File size: 1,033 Bytes
7ed5764
 
 
7fda361
f835633
 
483664b
 
7fda361
f835633
7ed5764
 
 
 
7fda361
483664b
7fda361
 
 
7ed5764
7fda361
 
 
 
 
7ed5764
 
 
7fda361
7ed5764
d5f09ce
7ed5764
7fda361
 
 
 
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
34
35
36
37
import { useReactFlow } from "@xyflow/react";
import LynxKiteNode from "./LynxKiteNode";
import NodeParameter from "./NodeParameter";

export type UpdateOptions = { delay?: number };

function NodeWithParams(props: any) {
  const reactFlow = useReactFlow();
  const metaParams = props.data.meta?.params;
  function setParam(name: string, newValue: any, opts: UpdateOptions) {
    reactFlow.updateNodeData(props.id, {
      params: { ...props.data.params, [name]: newValue },
      __execution_delay: opts.delay || 0,
    });
  }
  const params = 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: any, opts?: UpdateOptions) =>
            setParam(name, value, opts || {})
          }
        />
      ))}
      {props.children}
    </LynxKiteNode>
  );
}

export default NodeWithParams;