feat(devtools/grf): fix undefined error

This commit is contained in:
neoapps-dev
2026-04-28 12:53:01 +03:00
parent 972a5958c6
commit 74d2b71084
+17 -8
View File
@@ -70,14 +70,23 @@ export default function GrfEditorView() {
const handleUpdateParameter = (nodePath: string[], paramIndex: number, value: string) => { const handleUpdateParameter = (nodePath: string[], paramIndex: number, value: string) => {
if (!grf) return; if (!grf) return;
const newGrf = { ...grf }; const updateNode = (node: GrfNode, path: string[]): GrfNode => {
let current = newGrf.root; if (path.length === 0) {
for (const part of nodePath) { if (!node.parameters[paramIndex]) return node;
const found = current.children.find(c => c.name === part); const newParams = [...node.parameters];
if (found) current = found; newParams[paramIndex] = { ...newParams[paramIndex], value };
return { ...node, parameters: newParams };
} }
current.parameters[paramIndex].value = value; const [next, ...rest] = path;
setGrf(newGrf); return {
...node,
children: node.children.map(child => child.name === next ? updateNode(child, rest) : child)
};
};
setGrf({
...grf,
root: updateNode(grf.root, nodePath)
});
}; };
const handleSaveGrf = () => { const handleSaveGrf = () => {
@@ -282,7 +291,7 @@ function GrfNodeView({ node, level, path, onUpdate }: { node: GrfNode, level: nu
<input <input
type="text" type="text"
value={p.value} value={p.value}
onChange={(e) => onUpdate(path, i, e.target.value)} onChange={(e) => onUpdate(currentPath, i, e.target.value)}
className="flex-1 bg-white/5 border border-white/10 px-2 py-1 text-white outline-none focus:border-[#FFFF55]/50 font-mono transition-colors" className="flex-1 bg-white/5 border border-white/10 px-2 py-1 text-white outline-none focus:border-[#FFFF55]/50 font-mono transition-colors"
/> />
</div> </div>