File size: 1,006 Bytes
be095f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useContext } from 'react';
import { LynxKiteState } from '../LynxKiteState';
import LynxKiteNode from './LynxKiteNode';
import { useNodesState } from '@xyflow/react';
import NodeParameter from './NodeParameter';

function NodeWithParams(props) {
  const metaParams = props.data.meta?.params;
  const state = useContext(LynxKiteState);
  function setParam(name, newValue) {
    const i = state.workspace.nodes.findIndex((n) => n.id === props.id);
    state.workspace.nodes[i].data.params[name] = newValue;
  }
  const [nodes, setNodes, onNodesChange] = useNodesState([]);
  const params = nodes && props.data?.params ? Object.entries(props.data.params) : [];

  return (
    <LynxKiteNode {...props}>
      {params.map(([name, value]) =>
        <NodeParameter
          name={name}
          key={name}
          value={value}
          meta={metaParams?.[name]}
          onChange={(value) => setParam(name, value)}
        />
      )}
    </LynxKiteNode >
  );
}

export default NodeWithParams;