@hitachivantara/uikit-react-lab 5.5.5 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Flow/DroppableFlow.cjs +73 -1
- package/dist/cjs/components/Flow/DroppableFlow.cjs.map +1 -1
- package/dist/cjs/components/Flow/Flow.styles.cjs +40 -1
- package/dist/cjs/components/Flow/Flow.styles.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/Node.cjs +106 -0
- package/dist/cjs/components/Flow/Node/Node.cjs.map +1 -0
- package/dist/cjs/components/Flow/Node/Node.styles.cjs +89 -0
- package/dist/cjs/components/Flow/Node/Node.styles.cjs.map +1 -0
- package/dist/cjs/components/Flow/Node/Parameters/ParamRenderer.cjs +28 -0
- package/dist/cjs/components/Flow/Node/Parameters/ParamRenderer.cjs.map +1 -0
- package/dist/cjs/components/Flow/Node/Parameters/Select.cjs +39 -0
- package/dist/cjs/components/Flow/Node/Parameters/Select.cjs.map +1 -0
- package/dist/cjs/components/Flow/Node/Parameters/Text.cjs +32 -0
- package/dist/cjs/components/Flow/Node/Parameters/Text.cjs.map +1 -0
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/components/Flow/DroppableFlow.js +75 -3
- package/dist/esm/components/Flow/DroppableFlow.js.map +1 -1
- package/dist/esm/components/Flow/Flow.styles.js +41 -2
- package/dist/esm/components/Flow/Flow.styles.js.map +1 -1
- package/dist/esm/components/Flow/Node/Node.js +107 -0
- package/dist/esm/components/Flow/Node/Node.js.map +1 -0
- package/dist/esm/components/Flow/Node/Node.styles.js +89 -0
- package/dist/esm/components/Flow/Node/Node.styles.js.map +1 -0
- package/dist/esm/components/Flow/Node/Parameters/ParamRenderer.js +28 -0
- package/dist/esm/components/Flow/Node/Parameters/ParamRenderer.js.map +1 -0
- package/dist/esm/components/Flow/Node/Parameters/Select.js +39 -0
- package/dist/esm/components/Flow/Node/Parameters/Select.js.map +1 -0
- package/dist/esm/components/Flow/Node/Parameters/Text.js +32 -0
- package/dist/esm/components/Flow/Node/Parameters/Text.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +94 -19
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { useState, useCallback } from "react";
|
|
3
|
-
import ReactFlow, { useReactFlow, addEdge, applyNodeChanges, applyEdgeChanges } from "reactflow";
|
|
3
|
+
import ReactFlow, { useReactFlow, addEdge, applyNodeChanges, applyEdgeChanges, MarkerType } from "reactflow";
|
|
4
4
|
import "reactflow/dist/style.css";
|
|
5
5
|
import { useDroppable, useDndMonitor } from "@dnd-kit/core";
|
|
6
6
|
import { uid } from "uid";
|
|
@@ -8,6 +8,44 @@ import { useUniqueId } from "@hitachivantara/uikit-react-core";
|
|
|
8
8
|
import { useClasses } from "./Flow.styles.js";
|
|
9
9
|
import { staticClasses } from "./Flow.styles.js";
|
|
10
10
|
import { useFlowContext } from "./FlowContext/FlowContext.js";
|
|
11
|
+
const getNode = (nodes, nodeId) => {
|
|
12
|
+
return nodes.find((n) => n.id === nodeId);
|
|
13
|
+
};
|
|
14
|
+
const validateEdges = (edges, nodes, nodeTypes) => {
|
|
15
|
+
if (edges) {
|
|
16
|
+
const validEdges = [];
|
|
17
|
+
edges.forEach((edge) => {
|
|
18
|
+
var _a, _b, _c, _d, _e, _f;
|
|
19
|
+
if (!edge.sourceHandle || !edge.targetHandle)
|
|
20
|
+
return [];
|
|
21
|
+
const sourceNode = getNode(nodes, edge.source);
|
|
22
|
+
const targetNode = getNode(nodes, edge.target);
|
|
23
|
+
if (!sourceNode || !targetNode)
|
|
24
|
+
return [];
|
|
25
|
+
const sourceType = sourceNode.type;
|
|
26
|
+
const targetType = targetNode.type;
|
|
27
|
+
if (!sourceType || !targetType)
|
|
28
|
+
return [];
|
|
29
|
+
const output = (_c = (_b = (_a = nodeTypes == null ? void 0 : nodeTypes[sourceType]) == null ? void 0 : _a.meta) == null ? void 0 : _b.outputs) == null ? void 0 : _c[edge.sourceHandle];
|
|
30
|
+
const input = (_f = (_e = (_d = nodeTypes == null ? void 0 : nodeTypes[targetType]) == null ? void 0 : _d.meta) == null ? void 0 : _e.inputs) == null ? void 0 : _f[edge.targetHandle];
|
|
31
|
+
const sourceProvides = (output == null ? void 0 : output.provides) || [];
|
|
32
|
+
const targetAccepts = (input == null ? void 0 : input.accepts) || [];
|
|
33
|
+
let isValid = false;
|
|
34
|
+
sourceProvides.forEach((s) => {
|
|
35
|
+
targetAccepts.forEach((t) => {
|
|
36
|
+
if (s === t) {
|
|
37
|
+
isValid = true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
if (isValid) {
|
|
42
|
+
validEdges.push(edge);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return validEdges;
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
48
|
+
};
|
|
11
49
|
const HvDroppableFlow = ({
|
|
12
50
|
id,
|
|
13
51
|
className,
|
|
@@ -81,10 +119,44 @@ const HvDroppableFlow = ({
|
|
|
81
119
|
handleFlowChange(nodes, eds);
|
|
82
120
|
onEdgesChangeProp == null ? void 0 : onEdgesChangeProp(changes);
|
|
83
121
|
}, [edges, handleFlowChange, nodes, onEdgesChangeProp]);
|
|
84
|
-
|
|
122
|
+
const isValidConnection = (connection) => {
|
|
123
|
+
var _a, _b, _c, _d, _e, _f;
|
|
124
|
+
const sourceNode = getNode(nodes, connection.source);
|
|
125
|
+
const targetNode = getNode(nodes, connection.target);
|
|
126
|
+
if (!sourceNode || !targetNode) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
const sourceType = sourceNode.type;
|
|
130
|
+
const targetType = targetNode.type;
|
|
131
|
+
if (!sourceType || !targetType) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const inputs = ((_b = (_a = nodeTypes == null ? void 0 : nodeTypes[targetType]) == null ? void 0 : _a.meta) == null ? void 0 : _b.inputs) || [];
|
|
135
|
+
const outputs = ((_d = (_c = nodeTypes == null ? void 0 : nodeTypes[sourceType]) == null ? void 0 : _c.meta) == null ? void 0 : _d.outputs) || [];
|
|
136
|
+
const sourceProvides = ((_e = outputs[connection.sourceHandle]) == null ? void 0 : _e.provides) || [];
|
|
137
|
+
const targetAccepts = ((_f = inputs[connection.targetHandle]) == null ? void 0 : _f.accepts) || [];
|
|
138
|
+
let isValid = false;
|
|
139
|
+
sourceProvides.forEach((s) => {
|
|
140
|
+
targetAccepts.forEach((t) => {
|
|
141
|
+
if (s === t) {
|
|
142
|
+
isValid = true;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
return isValid;
|
|
147
|
+
};
|
|
148
|
+
const validEdges = validateEdges(edges, nodes, nodeTypes);
|
|
149
|
+
return /* @__PURE__ */ jsx("div", { id: elementId, ref: setNodeRef, className: cx(classes.root, className), children: /* @__PURE__ */ jsx(ReactFlow, { nodes, edges: validEdges, nodeTypes, onNodesChange: handleNodesChange, onEdgesChange: handleEdgesChange, onConnect: handleConnect, isValidConnection, defaultEdgeOptions: {
|
|
150
|
+
markerEnd: {
|
|
151
|
+
type: MarkerType.ArrowClosed,
|
|
152
|
+
height: 20,
|
|
153
|
+
width: 20
|
|
154
|
+
}
|
|
155
|
+
}, ...others, children }) });
|
|
85
156
|
};
|
|
86
157
|
export {
|
|
87
158
|
HvDroppableFlow,
|
|
88
|
-
staticClasses as flowClasses
|
|
159
|
+
staticClasses as flowClasses,
|
|
160
|
+
getNode
|
|
89
161
|
};
|
|
90
162
|
//# sourceMappingURL=DroppableFlow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DroppableFlow.js","sources":["../../../../src/components/Flow/DroppableFlow.tsx"],"sourcesContent":["import { useCallback, useState } from \"react\";\n\nimport ReactFlow, {\n Connection,\n EdgeChange,\n NodeChange,\n ReactFlowProps,\n addEdge,\n applyEdgeChanges,\n applyNodeChanges,\n useReactFlow,\n} from \"reactflow\";\nimport \"reactflow/dist/style.css\";\n\nimport { DragEndEvent, useDndMonitor, useDroppable } from \"@dnd-kit/core\";\n\nimport { uid } from \"uid\";\n\nimport { ExtractNames, useUniqueId } from \"@hitachivantara/uikit-react-core\";\n\nimport { HvFlowEdge, HvFlowNode } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./FlowContext\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeData = any,\n NodeType extends string | undefined = string | undefined\n> extends Omit<ReactFlowProps, \"nodes\" | \"edges\" | \"nodeTypes\"> {\n /** Flow content: background, controls, and minimap. */\n children?: React.ReactNode;\n /** Flow nodes. */\n nodes?: HvFlowNode<NodeData, NodeType>[];\n /** Flow edges. */\n edges?: HvFlowEdge[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowClasses;\n /** Function called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (\n nodes: HvFlowNode<NodeData, NodeType>[],\n edges: HvFlowEdge[]\n ) => void;\n}\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n ...others\n}: HvDroppableFlowProps) => {\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvFlow\");\n\n const reactFlowInstance = useReactFlow();\n\n const { nodeTypes } = useFlowContext();\n\n const [nodes, setNodes] = useState(initialNodes);\n const [edges, setEdges] = useState(initialEdges);\n\n const { setNodeRef } = useDroppable({\n id: elementId,\n });\n\n const handleDragEnd = useCallback(\n (event: DragEndEvent) => {\n if (event.over && event.over.id === elementId) {\n const type = event.active.id.toString();\n\n // Converts the coordinates to the react flow coordinate system\n const position = reactFlowInstance.project({\n x: (event.active.data.current?.hvFlow?.x || 0) - event.over.rect.left,\n y: (event.active.data.current?.hvFlow?.y || 0) - event.over.rect.top,\n });\n\n const newNode: HvFlowNode = {\n id: uid(),\n position,\n data: {},\n type,\n };\n\n setNodes((nds) => nds.concat(newNode));\n }\n },\n [elementId, reactFlowInstance, setNodes]\n );\n\n useDndMonitor({\n onDragEnd: handleDragEnd,\n });\n\n const handleFlowChange = useCallback(\n (\n nds: NonNullable<HvDroppableFlowProps[\"nodes\"]>,\n eds: NonNullable<HvDroppableFlowProps[\"edges\"]>\n ) => {\n // The new flow is returned if the user is not dragging nodes\n // This avoids triggering this handler too many times\n const isDragging = nds.find((node) => node.dragging);\n if (!isDragging) {\n onFlowChange?.(nds, eds);\n }\n },\n [onFlowChange]\n );\n\n const handleConnect = useCallback(\n (connection: Connection) => {\n const eds = addEdge(connection, edges);\n setEdges(eds);\n\n handleFlowChange(nodes, eds);\n onConnectProp?.(connection);\n },\n [edges, handleFlowChange, nodes, onConnectProp]\n );\n\n const handleNodesChange = useCallback(\n (changes: NodeChange[]) => {\n const nds = applyNodeChanges(changes, nodes);\n setNodes(nds);\n\n handleFlowChange(nds, edges);\n onNodesChangeProp?.(changes);\n },\n [edges, handleFlowChange, nodes, onNodesChangeProp]\n );\n\n const handleEdgesChange = useCallback(\n (changes: EdgeChange[]) => {\n const eds = applyEdgeChanges(changes, edges);\n setEdges(eds);\n\n handleFlowChange(nodes, eds);\n onEdgesChangeProp?.(changes);\n },\n [edges, handleFlowChange, nodes, onEdgesChangeProp]\n );\n\n return (\n <div\n id={elementId}\n ref={setNodeRef}\n className={cx(classes.root, className)}\n >\n <ReactFlow\n nodes={nodes}\n edges={edges}\n nodeTypes={nodeTypes}\n onNodesChange={handleNodesChange}\n onEdgesChange={handleEdgesChange}\n onConnect={handleConnect}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n );\n};\n"],"names":["HvDroppableFlow","id","className","children","onFlowChange","classes","classesProp","nodes","initialNodes","edges","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","nodeTypes","useFlowContext","setNodes","useState","setEdges","setNodeRef","useDroppable","handleDragEnd","useCallback","event","over","type","active","toString","position","project","x","data","current","hvFlow","rect","left","y","top","newNode","uid","nds","concat","onDragEnd","handleFlowChange","eds","isDragging","find","node","dragging","handleConnect","connection","addEdge","handleNodesChange","changes","applyNodeChanges","handleEdgesChange","applyEdgeChanges","root"],"mappings":";;;;;;;;;;AA+CO,MAAMA,kBAAkBA,CAAC;AAAA,EAC9BC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC,SAASC;AAAAA,EACTC,OAAOC,eAAe,CAAE;AAAA,EACxBC,OAAOC,eAAe,CAAE;AAAA,EACxBC,WAAWC;AAAAA,EACXC,eAAeC;AAAAA,EACfC,eAAeC;AAAAA,EACf,GAAGC;AACiB,MAAM;AACpB,QAAA;AAAA,IAAEZ;AAAAA,IAASa;AAAAA,EAAAA,IAAOC,WAAWb,WAAW;AAExCc,QAAAA,YAAYC,YAAYpB,IAAI,QAAQ;AAE1C,QAAMqB,oBAAoBC;AAEpB,QAAA;AAAA,IAAEC;AAAAA,MAAcC,eAAe;AAErC,QAAM,CAAClB,OAAOmB,QAAQ,IAAIC,SAASnB,YAAY;AAC/C,QAAM,CAACC,OAAOmB,QAAQ,IAAID,SAASjB,YAAY;AAEzC,QAAA;AAAA,IAAEmB;AAAAA,MAAeC,aAAa;AAAA,IAClC7B,IAAImB;AAAAA,EAAAA,CACL;AAEKW,QAAAA,gBAAgBC,YACpB,CAACC,UAAwB;;AACvB,QAAIA,MAAMC,QAAQD,MAAMC,KAAKjC,OAAOmB,WAAW;AAC7C,YAAMe,OAAOF,MAAMG,OAAOnC,GAAGoC,SAAS;AAGhCC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AiB,CACpD;AAEMmD,QAAAA,oBAAoBjC,YACxB,CAAC+B,YAA0B;AACnBT,UAAAA,MAAMY,iBAAiBH,SAAStD,KAAK;AAC3CmB,aAAS0B,GAAG;AAEZD,qBAAiB9C,OAAO+C,GAAG;AAC3BtC,2DAAoB+C;AAAAA,KAEtB,CAACtD,OAAO4C,kBAAkB9C,OAAOS,iBAAiB,CACpD;AAGE,SAAA,oBAAC,OACC,EAAA,IAAII,WACJ,KAAKS,YACL,WAAWX,GAAGb,QAAQ8D,MAAMjE,SAAS,GAErC,UAAA,oBAAC,aACC,OACA,OACA,WACA,eAAe4D,mBACf,eAAeG,mBACf,WAAWN,eACX,GAAI1C,QAEHd,SACH,CAAA,EACF,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"DroppableFlow.js","sources":["../../../../src/components/Flow/DroppableFlow.tsx"],"sourcesContent":["import { useCallback, useState } from \"react\";\n\nimport ReactFlow, {\n Connection,\n EdgeChange,\n NodeChange,\n ReactFlowProps,\n addEdge,\n applyEdgeChanges,\n applyNodeChanges,\n useReactFlow,\n MarkerType,\n Edge,\n Node,\n} from \"reactflow\";\nimport \"reactflow/dist/style.css\";\n\nimport { DragEndEvent, useDndMonitor, useDroppable } from \"@dnd-kit/core\";\n\nimport { uid } from \"uid\";\n\nimport { ExtractNames, useUniqueId } from \"@hitachivantara/uikit-react-core\";\n\nimport { HvFlowNodeTypes } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./FlowContext\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeData = any,\n NodeType extends string | undefined = string | undefined\n> extends Omit<ReactFlowProps, \"nodes\" | \"edges\" | \"nodeTypes\"> {\n /** Flow content: background, controls, and minimap. */\n children?: React.ReactNode;\n /** Flow nodes. */\n nodes?: Node<NodeData, NodeType>[];\n /** Flow edges. */\n edges?: Edge[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowClasses;\n /** Function called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdges = (\n edges: Edge[],\n nodes: Node[],\n nodeTypes: HvFlowNodeTypes<string> | undefined\n) => {\n if (edges) {\n const validEdges: Edge[] = [];\n\n edges.forEach((edge) => {\n if (!edge.sourceHandle || !edge.targetHandle) return [];\n\n const sourceNode = getNode(nodes, edge.source);\n const targetNode = getNode(nodes, edge.target);\n\n if (!sourceNode || !targetNode) return [];\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) return [];\n\n const output =\n nodeTypes?.[sourceType]?.meta?.outputs?.[edge.sourceHandle];\n const input = nodeTypes?.[targetType]?.meta?.inputs?.[edge.targetHandle];\n\n const sourceProvides = output?.provides || [];\n const targetAccepts = input?.accepts || [];\n\n let isValid = false;\n sourceProvides.forEach((s) => {\n targetAccepts.forEach((t) => {\n if (s === t) {\n isValid = true;\n }\n });\n });\n\n if (isValid) {\n validEdges.push(edge);\n }\n });\n\n return validEdges;\n }\n return [];\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n ...others\n}: HvDroppableFlowProps) => {\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id, \"hvFlow\");\n\n const reactFlowInstance = useReactFlow();\n\n const { nodeTypes } = useFlowContext();\n\n const [nodes, setNodes] = useState(initialNodes);\n const [edges, setEdges] = useState(initialEdges);\n\n const { setNodeRef } = useDroppable({\n id: elementId,\n });\n\n const handleDragEnd = useCallback(\n (event: DragEndEvent) => {\n if (event.over && event.over.id === elementId) {\n const type = event.active.id.toString();\n\n // Converts the coordinates to the react flow coordinate system\n const position = reactFlowInstance.project({\n x: (event.active.data.current?.hvFlow?.x || 0) - event.over.rect.left,\n y: (event.active.data.current?.hvFlow?.y || 0) - event.over.rect.top,\n });\n\n const newNode: Node = {\n id: uid(),\n position,\n data: {},\n type,\n };\n\n setNodes((nds) => nds.concat(newNode));\n }\n },\n [elementId, reactFlowInstance, setNodes]\n );\n\n useDndMonitor({\n onDragEnd: handleDragEnd,\n });\n\n const handleFlowChange = useCallback(\n (\n nds: NonNullable<HvDroppableFlowProps[\"nodes\"]>,\n eds: NonNullable<HvDroppableFlowProps[\"edges\"]>\n ) => {\n // The new flow is returned if the user is not dragging nodes\n // This avoids triggering this handler too many times\n const isDragging = nds.find((node) => node.dragging);\n if (!isDragging) {\n onFlowChange?.(nds, eds);\n }\n },\n [onFlowChange]\n );\n\n const handleConnect = useCallback(\n (connection: Connection) => {\n const eds = addEdge(connection, edges);\n setEdges(eds);\n\n handleFlowChange(nodes, eds);\n onConnectProp?.(connection);\n },\n [edges, handleFlowChange, nodes, onConnectProp]\n );\n\n const handleNodesChange = useCallback(\n (changes: NodeChange[]) => {\n const nds = applyNodeChanges(changes, nodes);\n setNodes(nds);\n\n handleFlowChange(nds, edges);\n onNodesChangeProp?.(changes);\n },\n [edges, handleFlowChange, nodes, onNodesChangeProp]\n );\n\n const handleEdgesChange = useCallback(\n (changes: EdgeChange[]) => {\n const eds = applyEdgeChanges(changes, edges);\n setEdges(eds);\n\n handleFlowChange(nodes, eds);\n onEdgesChangeProp?.(changes);\n },\n [edges, handleFlowChange, nodes, onEdgesChangeProp]\n );\n\n const isValidConnection = (connection) => {\n const sourceNode = getNode(nodes, connection.source);\n const targetNode = getNode(nodes, connection.target);\n\n if (!sourceNode || !targetNode) {\n return false;\n }\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) {\n return false;\n }\n\n const inputs = nodeTypes?.[targetType]?.meta?.inputs || [];\n const outputs = nodeTypes?.[sourceType]?.meta?.outputs || [];\n\n const sourceProvides = outputs[connection.sourceHandle]?.provides || [];\n const targetAccepts = inputs[connection.targetHandle]?.accepts || [];\n\n let isValid = false;\n sourceProvides.forEach((s) => {\n targetAccepts.forEach((t) => {\n if (s === t) {\n isValid = true;\n }\n });\n });\n\n return isValid;\n };\n\n const validEdges = validateEdges(edges, nodes, nodeTypes);\n\n return (\n <div\n id={elementId}\n ref={setNodeRef}\n className={cx(classes.root, className)}\n >\n <ReactFlow\n nodes={nodes}\n edges={validEdges}\n nodeTypes={nodeTypes}\n onNodesChange={handleNodesChange}\n onEdgesChange={handleEdgesChange}\n onConnect={handleConnect}\n isValidConnection={isValidConnection}\n defaultEdgeOptions={{\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n }}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n );\n};\n"],"names":["getNode","nodes","nodeId","find","n","id","validateEdges","edges","nodeTypes","validEdges","forEach","edge","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","output","meta","outputs","input","inputs","sourceProvides","provides","targetAccepts","accepts","isValid","s","t","push","HvDroppableFlow","className","children","onFlowChange","classes","classesProp","initialNodes","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","useFlowContext","setNodes","useState","setEdges","setNodeRef","useDroppable","handleDragEnd","useCallback","event","over","active","toString","position","project","x","data","current","hvFlow","rect","left","y","top","newNode","uid","nds","concat","onDragEnd","handleFlowChange","eds","isDragging","node","dragging","handleConnect","connection","addEdge","handleNodesChange","changes","applyNodeChanges","handleEdgesChange","applyEdgeChanges","isValidConnection","root","markerEnd","MarkerType","ArrowClosed","height","width"],"mappings":";;;;;;;;;;AA+CaA,MAAAA,UAAUA,CAACC,OAAeC,WAAmB;AACxD,SAAOD,MAAME,KAAMC,CAAMA,M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AA+BiB,WAAU;AACxD,UAAMF,YAAUf,kDAAYU,gBAAZV,mBAAyBc,SAAzBd,mBAA+Be,YAAW;AAE1D,UAAMG,mBAAiBH,aAAQiE,WAAW5E,YAAY,MAA/BW,mBAAkCI,aAAY;AACrE,UAAMC,kBAAgBH,YAAO+D,WAAW3E,YAAY,MAA9BY,mBAAiCI,YAAW;AAElE,QAAIC,UAAU;AACdJ,mBAAehB,QAASqB,CAAM,MAAA;AAC5BH,oBAAclB,QAASsB,CAAM,MAAA;AAC3B,YAAID,MAAMC,GAAG;AACD,oBAAA;AAAA,QACZ;AAAA,MAAA,CACD;AAAA,IAAA,CACF;AAEMF,WAAAA;AAAAA,EAAAA;AAGT,QAAMrB,aAAaH,cAAcC,OAAON,OAAOO,SAAS;AAGtD,SAAA,oBAAC,OACC,EAAA,IAAI2C,WACJ,KAAKQ,YACL,WAAWV,GAAGX,QAAQ0D,MAAM7D,SAAS,GAErC,8BAAC,WACC,EAAA,OACA,OAAO1B,YACP,WACA,eAAeiF,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBAAoB;AAAA,IAClBU,WAAW;AAAA,MACT9E,MAAM+E,WAAWC;AAAAA,MACjBC,QAAQ;AAAA,MACRC,OAAO;AAAA,IACT;AAAA,EAEErD,GAAAA,GAAAA,QAEHZ,SACH,CAAA,EACF,CAAA;AAEJ;"}
|
|
@@ -1,10 +1,49 @@
|
|
|
1
|
-
import { createClasses } from "@hitachivantara/uikit-react-core";
|
|
1
|
+
import { createClasses, theme } from "@hitachivantara/uikit-react-core";
|
|
2
|
+
import { staticClasses as staticClasses$1 } from "./Node/Node.styles.js";
|
|
3
|
+
import "@emotion/react/jsx-runtime";
|
|
4
|
+
import "@hitachivantara/uikit-react-icons";
|
|
5
|
+
import "@hitachivantara/uikit-styles";
|
|
6
|
+
import "react";
|
|
7
|
+
import "reactflow";
|
|
2
8
|
const {
|
|
3
9
|
staticClasses,
|
|
4
10
|
useClasses
|
|
5
11
|
} = createClasses("HvFlow", {
|
|
6
12
|
root: {
|
|
7
|
-
height: "100%"
|
|
13
|
+
height: "100%",
|
|
14
|
+
"& .react-flow__handle": {
|
|
15
|
+
backgroundColor: theme.colors.secondary_60,
|
|
16
|
+
width: 8,
|
|
17
|
+
height: 8,
|
|
18
|
+
zIndex: theme.zIndices.overlay
|
|
19
|
+
},
|
|
20
|
+
"& .react-flow__handle-connecting": {
|
|
21
|
+
backgroundColor: theme.colors.negative_20,
|
|
22
|
+
width: 12,
|
|
23
|
+
height: 12,
|
|
24
|
+
"&.react-flow__handle-top": {
|
|
25
|
+
top: -6
|
|
26
|
+
},
|
|
27
|
+
"&.react-flow__handle-bottom": {
|
|
28
|
+
bottom: -6
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"& .react-flow__handle-valid": {
|
|
32
|
+
backgroundColor: theme.colors.positive_20,
|
|
33
|
+
width: 12,
|
|
34
|
+
height: 12,
|
|
35
|
+
"&.react-flow__handle-top": {
|
|
36
|
+
top: -6
|
|
37
|
+
},
|
|
38
|
+
"&.react-flow__handle-bottom": {
|
|
39
|
+
bottom: -6
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
[`& .selected > .${staticClasses$1.root}`]: {
|
|
43
|
+
border: `1px solid ${theme.colors.secondary_60}`,
|
|
44
|
+
borderRadius: theme.radii.round,
|
|
45
|
+
boxSizing: "border-box"
|
|
46
|
+
}
|
|
8
47
|
}
|
|
9
48
|
});
|
|
10
49
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flow.styles.js","sources":["../../../../src/components/Flow/Flow.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-core\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFlow\", {\n root: {
|
|
1
|
+
{"version":3,"file":"Flow.styles.js","sources":["../../../../src/components/Flow/Flow.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\nimport { flowNodeClasses } from \"./Node\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFlow\", {\n root: {\n height: \"100%\",\n \"& .react-flow__handle\": {\n backgroundColor: theme.colors.secondary_60,\n width: 8,\n height: 8,\n zIndex: theme.zIndices.overlay,\n },\n \"& .react-flow__handle-connecting\": {\n backgroundColor: theme.colors.negative_20,\n width: 12,\n height: 12,\n \"&.react-flow__handle-top\": {\n top: -6,\n },\n \"&.react-flow__handle-bottom\": {\n bottom: -6,\n },\n },\n \"& .react-flow__handle-valid\": {\n backgroundColor: theme.colors.positive_20,\n width: 12,\n height: 12,\n \"&.react-flow__handle-top\": {\n top: -6,\n },\n \"&.react-flow__handle-bottom\": {\n bottom: -6,\n },\n },\n [`& .selected > .${flowNodeClasses.root}`]: {\n border: `1px solid ${theme.colors.secondary_60}`,\n borderRadius: theme.radii.round,\n boxSizing: \"border-box\",\n },\n },\n});\n"],"names":["staticClasses","useClasses","createClasses","root","height","backgroundColor","theme","colors","secondary_60","width","zIndex","zIndices","overlay","negative_20","top","bottom","positive_20","flowNodeClasses","border","borderRadius","radii","round","boxSizing"],"mappings":";;;;;;;AAGa,MAAA;AAAA,EAAEA;AAAAA,EAAeC;AAAW,IAAIC,cAAc,UAAU;AAAA,EACnEC,MAAM;AAAA,IACJC,QAAQ;AAAA,IACR,yBAAyB;AAAA,MACvBC,iBAAiBC,MAAMC,OAAOC;AAAAA,MAC9BC,OAAO;AAAA,MACPL,QAAQ;AAAA,MACRM,QAAQJ,MAAMK,SAASC;AAAAA,IACzB;AAAA,IACA,oCAAoC;AAAA,MAClCP,iBAAiBC,MAAMC,OAAOM;AAAAA,MAC9BJ,OAAO;AAAA,MACPL,QAAQ;AAAA,MACR,4BAA4B;AAAA,QAC1BU,KAAK;AAAA,MACP;AAAA,MACA,+BAA+B;AAAA,QAC7BC,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,IACA,+BAA+B;AAAA,MAC7BV,iBAAiBC,MAAMC,OAAOS;AAAAA,MAC9BP,OAAO;AAAA,MACPL,QAAQ;AAAA,MACR,4BAA4B;AAAA,QAC1BU,KAAK;AAAA,MACP;AAAA,MACA,+BAA+B;AAAA,QAC7BC,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,IACA,CAAE,kBAAiBE,gBAAgBd,IAAK,EAAC,GAAG;AAAA,MAC1Ce,QAAS,aAAYZ,MAAMC,OAAOC,YAAa;AAAA,MAC/CW,cAAcb,MAAMc,MAAMC;AAAAA,MAC1BC,WAAW;AAAA,IACb;AAAA,EACF;AACF,CAAC;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { jsxs, jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { HvTypography, HvTooltip, HvButton } from "@hitachivantara/uikit-react-core";
|
|
3
|
+
import { Info, Up, Down } from "@hitachivantara/uikit-react-icons";
|
|
4
|
+
import { getColor } from "@hitachivantara/uikit-styles";
|
|
5
|
+
import { useState, useEffect } from "react";
|
|
6
|
+
import { useReactFlow, useStore, Handle, Position } from "reactflow";
|
|
7
|
+
import { useFlowContext } from "../FlowContext/FlowContext.js";
|
|
8
|
+
import { useClasses } from "./Node.styles.js";
|
|
9
|
+
import { staticClasses } from "./Node.styles.js";
|
|
10
|
+
import ParamRenderer from "./Parameters/ParamRenderer.js";
|
|
11
|
+
const isInputConnected = (id, type, idx, edges) => {
|
|
12
|
+
if (type === "target") {
|
|
13
|
+
return edges.some((e) => e.target === id && e.targetHandle === idx.toString());
|
|
14
|
+
}
|
|
15
|
+
if (type === "source") {
|
|
16
|
+
return edges.some((e) => e.source === id && e.sourceHandle === idx.toString());
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const HvFlowNode = ({
|
|
20
|
+
id,
|
|
21
|
+
type,
|
|
22
|
+
title,
|
|
23
|
+
description,
|
|
24
|
+
expanded = false,
|
|
25
|
+
params,
|
|
26
|
+
classes: classesProp,
|
|
27
|
+
className
|
|
28
|
+
}) => {
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
30
|
+
const [showParams, setShowParams] = useState(expanded);
|
|
31
|
+
const reactFlowInstance = useReactFlow();
|
|
32
|
+
const {
|
|
33
|
+
classes,
|
|
34
|
+
cx,
|
|
35
|
+
css
|
|
36
|
+
} = useClasses(classesProp);
|
|
37
|
+
const {
|
|
38
|
+
nodeGroups,
|
|
39
|
+
nodeTypes
|
|
40
|
+
} = useFlowContext();
|
|
41
|
+
const edges = useStore((s) => s.edges);
|
|
42
|
+
const nodes = useStore((s) => s.getNodes());
|
|
43
|
+
const node = nodes.find((n) => n.id === id);
|
|
44
|
+
const groupId = (_a = nodeTypes == null ? void 0 : nodeTypes[type].meta) == null ? void 0 : _a.groupId;
|
|
45
|
+
const groupLabel = groupId && nodeGroups && nodeGroups[groupId].label;
|
|
46
|
+
const inputs = (_c = (_b = nodeTypes == null ? void 0 : nodeTypes[type]) == null ? void 0 : _b.meta) == null ? void 0 : _c.inputs;
|
|
47
|
+
const outputs = (_e = (_d = nodeTypes == null ? void 0 : nodeTypes[type]) == null ? void 0 : _d.meta) == null ? void 0 : _e.outputs;
|
|
48
|
+
const icon = groupId && nodeGroups && nodeGroups[groupId].icon;
|
|
49
|
+
const colorProp = groupId && nodeGroups && nodeGroups[groupId].color;
|
|
50
|
+
const color = getColor(colorProp);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const newNodes = nodes.map((n) => {
|
|
53
|
+
if (n.id === id) {
|
|
54
|
+
if (Object.keys(n.data).length === 0) {
|
|
55
|
+
params == null ? void 0 : params.forEach((param) => {
|
|
56
|
+
n.data[param.label] = param.value;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return n;
|
|
61
|
+
});
|
|
62
|
+
reactFlowInstance.setNodes(newNodes);
|
|
63
|
+
}, []);
|
|
64
|
+
const hasParams = !!(params && params.length > 0);
|
|
65
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(css({
|
|
66
|
+
border: `1px solid ${color}`
|
|
67
|
+
}), classes.root, className), children: [
|
|
68
|
+
/* @__PURE__ */ jsxs("div", { className: cx(css({
|
|
69
|
+
backgroundColor: color
|
|
70
|
+
}), classes.headerContainer), children: [
|
|
71
|
+
/* @__PURE__ */ jsxs("div", { className: classes.groupContainer, children: [
|
|
72
|
+
icon,
|
|
73
|
+
/* @__PURE__ */ jsx(HvTypography, { variant: "title4", className: classes.group, children: groupLabel })
|
|
74
|
+
] }),
|
|
75
|
+
/* @__PURE__ */ jsxs("div", { style: {
|
|
76
|
+
display: "flex"
|
|
77
|
+
}, children: [
|
|
78
|
+
/* @__PURE__ */ jsx(HvTooltip, { title: /* @__PURE__ */ jsx(HvTypography, { children: description }), children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Info, {}) }) }),
|
|
79
|
+
/* @__PURE__ */ jsx(HvButton, { icon: true, disabled: !hasParams, onClick: () => setShowParams((p) => !p), children: showParams ? /* @__PURE__ */ jsx(Up, {}) : /* @__PURE__ */ jsx(Down, {}) })
|
|
80
|
+
] })
|
|
81
|
+
] }),
|
|
82
|
+
/* @__PURE__ */ jsx("div", { className: classes.titleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: title }) }),
|
|
83
|
+
/* @__PURE__ */ jsx("div", { className: classes.inputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Inputs" }) }),
|
|
84
|
+
/* @__PURE__ */ jsx("div", { className: classes.inputsContainer, children: inputs == null ? void 0 : inputs.map((input, idx) => /* @__PURE__ */ jsxs("div", { className: classes.inputContainer, children: [
|
|
85
|
+
/* @__PURE__ */ jsx(Handle, { type: "target", isConnectableStart: false, id: `${idx}`, position: Position.Left, style: {
|
|
86
|
+
top: 160 + 29 * idx
|
|
87
|
+
} }),
|
|
88
|
+
/* @__PURE__ */ jsx(HvTypography, { children: input.label }),
|
|
89
|
+
input.isMandatory && !isInputConnected(id, "target", idx, edges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory })
|
|
90
|
+
] }, idx)) }),
|
|
91
|
+
showParams && params && /* @__PURE__ */ jsx("div", { className: classes.paramsContainer, children: /* @__PURE__ */ jsx(ParamRenderer, { nodeId: id, params, data: node == null ? void 0 : node.data }) }),
|
|
92
|
+
/* @__PURE__ */ jsx("div", { className: classes.outputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Outputs" }) }),
|
|
93
|
+
/* @__PURE__ */ jsx("div", { className: classes.outputsContainer, children: outputs == null ? void 0 : outputs.map((output, idx) => /* @__PURE__ */ jsxs("div", { className: classes.outputContainer, children: [
|
|
94
|
+
/* @__PURE__ */ jsx(Handle, { type: "source", isConnectableEnd: false, id: `${idx}`, position: Position.Right, style: {
|
|
95
|
+
bottom: -8 + 29 * (outputs.length - idx),
|
|
96
|
+
top: "auto"
|
|
97
|
+
} }),
|
|
98
|
+
output.isMandatory && !isInputConnected(id, "source", idx, edges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory }),
|
|
99
|
+
/* @__PURE__ */ jsx(HvTypography, { children: output.label })
|
|
100
|
+
] }, idx)) })
|
|
101
|
+
] });
|
|
102
|
+
};
|
|
103
|
+
export {
|
|
104
|
+
HvFlowNode,
|
|
105
|
+
staticClasses as flowNodeClasses
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=Node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Node.js","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import {\n ExtractNames,\n HvBaseProps,\n HvButton,\n HvTooltip,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Down, Info, Up } from \"@hitachivantara/uikit-react-icons\";\nimport { getColor } from \"@hitachivantara/uikit-styles\";\nimport { useEffect, useState } from \"react\";\nimport { Handle, NodeProps, Position, useReactFlow, useStore } from \"reactflow\";\nimport { useFlowContext } from \"../FlowContext/FlowContext\";\n\nimport { HvFlowNodeInput, HvFlowNodeOutput, HvFlowNodeParam } from \"../types\";\nimport { staticClasses, useClasses } from \"./Node.styles\";\nimport ParamRenderer from \"./Parameters/ParamRenderer\";\n\nexport { staticClasses as flowNodeClasses };\n\nexport type HvFlowNodeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFlowNodeProps extends Omit<HvBaseProps, \"id\">, NodeProps {\n /** Node title */\n title: string;\n /** Node description */\n description: string;\n /** Node expanded */\n expanded?: boolean;\n /** Node inputs */\n inputs?: HvFlowNodeInput[];\n /** Node outputs */\n outputs?: HvFlowNodeOutput[];\n /** Node parameters */\n params?: HvFlowNodeParam[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowNodeClasses;\n}\n\nconst isInputConnected = (id, type, idx, edges) => {\n if (type === \"target\") {\n return edges.some(\n (e) => e.target === id && e.targetHandle === idx.toString()\n );\n }\n if (type === \"source\") {\n return edges.some(\n (e) => e.source === id && e.sourceHandle === idx.toString()\n );\n }\n};\n\nexport const HvFlowNode = ({\n id,\n type,\n title,\n description,\n expanded = false,\n params,\n classes: classesProp,\n className,\n}: HvFlowNodeProps) => {\n const [showParams, setShowParams] = useState(expanded);\n const reactFlowInstance = useReactFlow();\n\n const { classes, cx, css } = useClasses(classesProp);\n\n const { nodeGroups, nodeTypes } = useFlowContext();\n const edges = useStore((s) => s.edges);\n const nodes = useStore((s) => s.getNodes());\n\n const node = nodes.find((n) => n.id === id);\n\n const groupId = nodeTypes?.[type].meta?.groupId;\n const groupLabel = groupId && nodeGroups && nodeGroups[groupId].label;\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon = groupId && nodeGroups && nodeGroups[groupId].icon;\n const colorProp = groupId && nodeGroups && nodeGroups[groupId].color;\n const color = getColor(colorProp);\n\n useEffect(() => {\n const newNodes = nodes.map((n) => {\n if (n.id === id) {\n if (Object.keys(n.data).length === 0) {\n params?.forEach((param) => {\n n.data[param.label] = param.value;\n });\n }\n }\n return n;\n });\n reactFlowInstance.setNodes(newNodes);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const hasParams = !!(params && params.length > 0);\n\n return (\n <div\n className={cx(\n css({ border: `1px solid ${color}` }),\n classes.root,\n className\n )}\n >\n <div\n className={cx(css({ backgroundColor: color }), classes.headerContainer)}\n >\n <div className={classes.groupContainer}>\n {icon}\n <HvTypography variant=\"title4\" className={classes.group}>\n {groupLabel}\n </HvTypography>\n </div>\n <div style={{ display: \"flex\" }}>\n <HvTooltip title={<HvTypography>{description}</HvTypography>}>\n <div>\n <Info />\n </div>\n </HvTooltip>\n <HvButton\n icon\n disabled={!hasParams}\n onClick={() => setShowParams((p) => !p)}\n >\n {showParams ? <Up /> : <Down />}\n </HvButton>\n </div>\n </div>\n <div className={classes.titleContainer}>\n <HvTypography>{title}</HvTypography>\n </div>\n <div className={classes.inputsTitleContainer}>\n <HvTypography>Inputs</HvTypography>\n </div>\n <div className={classes.inputsContainer}>\n {inputs?.map((input, idx) => (\n <div className={classes.inputContainer} key={idx}>\n <Handle\n type=\"target\"\n isConnectableStart={false}\n id={`${idx}`}\n position={Position.Left}\n style={{\n top: 160 + 29 * idx,\n }}\n />\n <HvTypography>{input.label}</HvTypography>\n {input.isMandatory &&\n !isInputConnected(id, \"target\", idx, edges) && (\n <div className={classes.mandatory} />\n )}\n </div>\n ))}\n </div>\n {showParams && params && (\n <div className={classes.paramsContainer}>\n <ParamRenderer nodeId={id} params={params} data={node?.data} />\n </div>\n )}\n <div className={classes.outputsTitleContainer}>\n <HvTypography>Outputs</HvTypography>\n </div>\n <div className={classes.outputsContainer}>\n {outputs?.map((output, idx) => (\n <div className={classes.outputContainer} key={idx}>\n <Handle\n type=\"source\"\n isConnectableEnd={false}\n id={`${idx}`}\n position={Position.Right}\n style={{\n bottom: -8 + 29 * (outputs.length - idx),\n top: \"auto\",\n }}\n />\n {output.isMandatory &&\n !isInputConnected(id, \"source\", idx, edges) && (\n <div className={classes.mandatory} />\n )}\n <HvTypography>{output.label}</HvTypography>\n </div>\n ))}\n </div>\n </div>\n );\n};\n"],"names":["isInputConnected","id","type","idx","edges","some","e","target","targetHandle","toString","source","sourceHandle","HvFlowNode","title","description","expanded","params","classes","classesProp","className","showParams","setShowParams","useState","reactFlowInstance","useReactFlow","cx","css","useClasses","nodeGroups","nodeTypes","useFlowContext","useStore","s","nodes","getNodes","node","find","n","groupId","meta","groupLabel","label","inputs","outputs","icon","colorProp","color","getColor","useEffect","newNodes","map","Object","keys","data","length","forEach","param","value","setNodes","hasParams","border","root","backgroundColor","headerContainer","groupContainer","group","display","p","titleContainer","inputsTitleContainer","inputsContainer","input","inputContainer","Position","Left","top","isMandatory","mandatory","paramsContainer","outputsTitleContainer","outputsContainer","output","outputContainer","Right","bottom"],"mappings":";;;;;;;;;;AAsCA,MAAMA,mBAAmBA,CAACC,IAAIC,MAAMC,KAAKC,UAAU;AACjD,MAAIF,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEC,WAAWN,MAAMK,EAAEE,iBAAiBL,IAAIM,SACnD,CAAA;AAAA,EACF;AACA,MAAIP,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEI,WAAWT,MAAMK,EAAEK,iBAAiBR,IAAIM,SACnD,CAAA;AAAA,EACF;AACF;AAEO,MAAMG,aAAaA,CAAC;AAAA,EACzBX;AAAAA,EACAC;AAAAA,EACAW;AAAAA,EACAC;AAAAA,EACAC,WAAW;AAAA,EACXC;AAAAA,EACAC,SAASC;AAAAA,EACTC;AACe,MAAM;;AACrB,QAAM,CAACC,YAAYC,aAAa,IAAIC,SAASP,QAAQ;AACrD,QAAMQ,oBAAoBC;AAEpB,QAAA;AAAA,IAAEP;AAAAA,IAASQ;AAAAA,IAAIC;AAAAA,EAAAA,IAAQC,WAAWT,WAAW;AAE7C,QAAA;AAAA,IAAEU;AAAAA,IAAYC;AAAAA,MAAcC,eAAe;AACjD,QAAM1B,QAAQ2B,SAAUC,CAAMA,MAAAA,EAAE5B,KAAK;AACrC,QAAM6B,QAAQF,SAAUC,CAAMA,M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Q4D,UACzB,CAAA;AAAA,IAAA,KAdwC1E,GAe7C,IAEJ;AAAA,IACCiB,cAAcJ,UACZ,oBAAA,OAAA,EAAI,WAAWC,QAAQ6D,iBACtB,UAAC,oBAAA,eAAA,EAAc,QAAQ7E,IAAI,QAAgB,MAAMkC,6BAAMkB,KAAK,CAAA,GAC9D;AAAA,IAEF,oBAAC,SAAI,WAAWpC,QAAQ8D,uBACtB,UAAC,oBAAA,cAAA,EAAa,qBAAO,EACvB,CAAA;AAAA,IACC,oBAAA,OAAA,EAAI,WAAW9D,QAAQ+D,kBACrBrC,UAASO,mCAAAA,IAAI,CAAC+B,QAAQ9E,QACrB,qBAAC,OAAI,EAAA,WAAWc,QAAQiE,iBACtB,UAAA;AAAA,MAAA,oBAAC,QACC,EAAA,MAAK,UACL,kBAAkB,OAClB,IAAK,GAAE/E,GAAI,IACX,UAAUsE,SAASU,OACnB,OAAO;AAAA,QACLC,QAAQ,KAAK,MAAMzC,QAAQW,SAASnD;AAAAA,QACpCwE,KAAK;AAAA,MAAA,GACL;AAAA,MAEHM,OAAOL,eACN,CAAC5E,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxC,oBAAC,OAAI,EAAA,WAAWa,QAAQ4D,UACzB,CAAA;AAAA,MACH,oBAAC,cAAcI,EAAAA,UAAAA,OAAOxC,MAAM,CAAA;AAAA,IAAA,KAfgBtC,GAgB9C,IAEJ;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createClasses, theme } from "@hitachivantara/uikit-react-core";
|
|
2
|
+
const {
|
|
3
|
+
staticClasses,
|
|
4
|
+
useClasses
|
|
5
|
+
} = createClasses("HvFlowNode", {
|
|
6
|
+
root: {
|
|
7
|
+
borderRadius: theme.radii.round,
|
|
8
|
+
backgroundColor: theme.colors.atmo1,
|
|
9
|
+
boxShadow: theme.colors.shadow,
|
|
10
|
+
minWidth: "250px"
|
|
11
|
+
},
|
|
12
|
+
headerContainer: {
|
|
13
|
+
padding: theme.spacing(0.5, 1),
|
|
14
|
+
display: "flex",
|
|
15
|
+
flexDirection: "row",
|
|
16
|
+
justifyContent: "space-between",
|
|
17
|
+
alignItems: "center"
|
|
18
|
+
},
|
|
19
|
+
groupContainer: {
|
|
20
|
+
display: "flex",
|
|
21
|
+
flexDirection: "row",
|
|
22
|
+
alignItems: "center"
|
|
23
|
+
},
|
|
24
|
+
group: {
|
|
25
|
+
color: theme.colors.base_dark
|
|
26
|
+
},
|
|
27
|
+
titleContainer: {
|
|
28
|
+
padding: theme.space.sm
|
|
29
|
+
},
|
|
30
|
+
inputsTitleContainer: {
|
|
31
|
+
display: "flex",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
padding: theme.space.xs,
|
|
34
|
+
backgroundColor: theme.colors.atmo2,
|
|
35
|
+
borderTop: `1px solid ${theme.colors.atmo4}`,
|
|
36
|
+
borderBottom: `1px solid ${theme.colors.atmo4}`
|
|
37
|
+
},
|
|
38
|
+
outputsTitleContainer: {
|
|
39
|
+
display: "flex",
|
|
40
|
+
justifyContent: "center",
|
|
41
|
+
padding: theme.space.xs,
|
|
42
|
+
backgroundColor: theme.colors.atmo2,
|
|
43
|
+
borderTop: `1px solid ${theme.colors.atmo4}`,
|
|
44
|
+
borderBottom: `1px solid ${theme.colors.atmo4}`
|
|
45
|
+
},
|
|
46
|
+
inputsContainer: {
|
|
47
|
+
display: "flex",
|
|
48
|
+
flexDirection: "column",
|
|
49
|
+
padding: theme.space.sm,
|
|
50
|
+
gap: theme.space.xs,
|
|
51
|
+
alignItems: "flex-start"
|
|
52
|
+
},
|
|
53
|
+
outputsContainer: {
|
|
54
|
+
display: "flex",
|
|
55
|
+
flexDirection: "column",
|
|
56
|
+
padding: theme.space.sm,
|
|
57
|
+
gap: theme.space.xs,
|
|
58
|
+
alignItems: "flex-end"
|
|
59
|
+
},
|
|
60
|
+
paramsContainer: {
|
|
61
|
+
borderTop: `1px solid ${theme.colors.atmo4}`,
|
|
62
|
+
display: "flex",
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
gap: theme.space.xs,
|
|
65
|
+
padding: theme.space.sm
|
|
66
|
+
},
|
|
67
|
+
inputContainer: {
|
|
68
|
+
display: "flex",
|
|
69
|
+
flexDirection: "row",
|
|
70
|
+
alignItems: "center"
|
|
71
|
+
},
|
|
72
|
+
outputContainer: {
|
|
73
|
+
display: "flex",
|
|
74
|
+
flexDirection: "row",
|
|
75
|
+
alignItems: "center"
|
|
76
|
+
},
|
|
77
|
+
mandatory: {
|
|
78
|
+
width: 10,
|
|
79
|
+
height: 10,
|
|
80
|
+
margin: theme.spacing(0, theme.space.xs),
|
|
81
|
+
borderRadius: theme.radii.circle,
|
|
82
|
+
backgroundColor: theme.colors.negative_20
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
export {
|
|
86
|
+
staticClasses,
|
|
87
|
+
useClasses
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=Node.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Node.styles.js","sources":["../../../../../src/components/Flow/Node/Node.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFlowNode\", {\n root: {\n borderRadius: theme.radii.round,\n backgroundColor: theme.colors.atmo1,\n boxShadow: theme.colors.shadow,\n minWidth: \"250px\",\n },\n headerContainer: {\n padding: theme.spacing(0.5, 1),\n display: \"flex\",\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n },\n groupContainer: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n },\n group: {\n color: theme.colors.base_dark,\n },\n titleContainer: { padding: theme.space.sm },\n inputsTitleContainer: {\n display: \"flex\",\n justifyContent: \"center\",\n padding: theme.space.xs,\n backgroundColor: theme.colors.atmo2,\n borderTop: `1px solid ${theme.colors.atmo4}`,\n borderBottom: `1px solid ${theme.colors.atmo4}`,\n },\n outputsTitleContainer: {\n display: \"flex\",\n justifyContent: \"center\",\n padding: theme.space.xs,\n backgroundColor: theme.colors.atmo2,\n borderTop: `1px solid ${theme.colors.atmo4}`,\n borderBottom: `1px solid ${theme.colors.atmo4}`,\n },\n inputsContainer: {\n display: \"flex\",\n flexDirection: \"column\",\n padding: theme.space.sm,\n gap: theme.space.xs,\n alignItems: \"flex-start\",\n },\n outputsContainer: {\n display: \"flex\",\n flexDirection: \"column\",\n padding: theme.space.sm,\n gap: theme.space.xs,\n alignItems: \"flex-end\",\n },\n paramsContainer: {\n borderTop: `1px solid ${theme.colors.atmo4}`,\n display: \"flex\",\n flexDirection: \"column\",\n gap: theme.space.xs,\n padding: theme.space.sm,\n },\n inputContainer: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n },\n outputContainer: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n },\n mandatory: {\n width: 10,\n height: 10,\n margin: theme.spacing(0, theme.space.xs),\n borderRadius: theme.radii.circle,\n backgroundColor: theme.colors.negative_20,\n },\n});\n"],"names":["staticClasses","useClasses","createClasses","root","borderRadius","theme","radii","round","backgroundColor","colors","atmo1","boxShadow","shadow","minWidth","headerContainer","padding","spacing","display","flexDirection","justifyContent","alignItems","groupContainer","group","color","base_dark","titleContainer","space","sm","inputsTitleContainer","xs","atmo2","borderTop","atmo4","borderBottom","outputsTitleContainer","inputsContainer","gap","outputsContainer","paramsContainer","inputContainer","outputContainer","mandatory","width","height","margin","circle","negative_20"],"mappings":";AAEa,MAAA;AAAA,EAAEA;AAAAA,EAAeC;AAAW,IAAIC,cAAc,cAAc;AAAA,EACvEC,MAAM;AAAA,IACJC,cAAcC,MAAMC,MAAMC;AAAAA,IAC1BC,iBAAiBH,MAAMI,OAAOC;AAAAA,IAC9BC,WAAWN,MAAMI,OAAOG;AAAAA,IACxBC,UAAU;AAAA,EACZ;AAAA,EACAC,iBAAiB;AAAA,IACfC,SAASV,MAAMW,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AA,IAC3Cf,SAAS;AAAA,IACTC,eAAe;AAAA,IACfkB,KAAK/B,MAAMqB,MAAMG;AAAAA,IACjBd,SAASV,MAAMqB,MAAMC;AAAAA,EACvB;AAAA,EACAY,gBAAgB;AAAA,IACdtB,SAAS;AAAA,IACTC,eAAe;AAAA,IACfE,YAAY;AAAA,EACd;AAAA,EACAoB,iBAAiB;AAAA,IACfvB,SAAS;AAAA,IACTC,eAAe;AAAA,IACfE,YAAY;AAAA,EACd;AAAA,EACAqB,WAAW;AAAA,IACTC,OAAO;AAAA,IACPC,QAAQ;AAAA,IACRC,QAAQvC,MAAMW,QAAQ,GAAGX,MAAMqB,MAAMG,EAAE;AAAA,IACvCzB,cAAcC,MAAMC,MAAMuC;AAAAA,IAC1BrC,iBAAiBH,MAAMI,OAAOqC;AAAAA,EAChC;AACF,CAAC;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx, Fragment, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import Text from "./Text.js";
|
|
3
|
+
import Select from "./Select.js";
|
|
4
|
+
const renderers = {
|
|
5
|
+
text: Text,
|
|
6
|
+
select: Select
|
|
7
|
+
};
|
|
8
|
+
const ParamRenderer = ({
|
|
9
|
+
nodeId,
|
|
10
|
+
params,
|
|
11
|
+
data
|
|
12
|
+
}) => {
|
|
13
|
+
return /* @__PURE__ */ jsx(Fragment, { children: params.map((param, idx) => {
|
|
14
|
+
const Renderer = renderers[param.type];
|
|
15
|
+
if (Renderer) {
|
|
16
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
17
|
+
/* @__PURE__ */ jsx("span", { children: param.label }),
|
|
18
|
+
/* @__PURE__ */ jsx(Renderer, { nodeId, param, data })
|
|
19
|
+
] }, idx);
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}) });
|
|
23
|
+
};
|
|
24
|
+
const ParamRenderer$1 = ParamRenderer;
|
|
25
|
+
export {
|
|
26
|
+
ParamRenderer$1 as default
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=ParamRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParamRenderer.js","sources":["../../../../../../src/components/Flow/Node/Parameters/ParamRenderer.tsx"],"sourcesContent":["import { HvFlowNodeParam } from \"../../types\";\nimport Text from \"./Text\";\nimport Select from \"./Select\";\n\nexport type ParamRendererProps = {\n nodeId: string;\n params: HvFlowNodeParam[];\n data: any;\n};\n\nconst renderers = {\n text: Text,\n select: Select,\n};\n\nconst ParamRenderer = ({ nodeId, params, data }: ParamRendererProps) => {\n return (\n <>\n {params.map((param, idx) => {\n const Renderer = renderers[param.type];\n if (Renderer) {\n return (\n <div key={idx}>\n <span>{param.label}</span>\n <Renderer nodeId={nodeId} param={param} data={data} />\n </div>\n );\n }\n return null;\n })}\n </>\n );\n};\n\nexport default ParamRenderer;\n"],"names":["renderers","text","Text","select","Select","ParamRenderer","nodeId","params","data","map","param","idx","Renderer","type","label"],"mappings":";;;AAUA,MAAMA,YAAY;AAAA,EAChBC,MAAMC;AAAAA,EACNC,QAAQC;AACV;AAEA,MAAMC,gBAAgBA,CAAC;AAAA,EAAEC;AAAAA,EAAQC;AAAAA,EAAQC;AAAyB,MAAM;AACtE,SAEKD,oBAAAA,UAAAA,EAAAA,UAAAA,OAAOE,IAAI,CAACC,OAAOC,QAAQ;AACpBC,UAAAA,WAAWZ,UAAUU,MAAMG,IAAI;AACrC,QAAID,UAAU;AACZ,kCACG,OACC,EAAA,UAAA;AAAA,QAAC,oBAAA,QAAA,EAAMF,gBAAMI,MAAM,CAAA;AAAA,QAClB,oBAAA,UAAA,EAAS,QAAgB,OAAc,KAAW,CAAA;AAAA,MAAA,EAAA,GAF3CH,GAGV;AAAA,IAEJ;AACO,WAAA;AAAA,EACR,CAAA,EACH,CAAA;AAEJ;AAEA,MAAA,kBAAeN;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { HvDropdown } from "@hitachivantara/uikit-react-core";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useReactFlow } from "reactflow";
|
|
5
|
+
const Select = ({
|
|
6
|
+
nodeId,
|
|
7
|
+
param,
|
|
8
|
+
data
|
|
9
|
+
}) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const reactFlowInstance = useReactFlow();
|
|
12
|
+
const [option, setOption] = useState(data[param.id]);
|
|
13
|
+
const onSelectChange = (item) => {
|
|
14
|
+
const nodes = reactFlowInstance.getNodes();
|
|
15
|
+
const newNodes = nodes.map((node) => {
|
|
16
|
+
if (node.id === nodeId) {
|
|
17
|
+
node.data = {
|
|
18
|
+
...node.data,
|
|
19
|
+
[param.id]: item.label
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return node;
|
|
23
|
+
});
|
|
24
|
+
reactFlowInstance.setNodes(newNodes);
|
|
25
|
+
setOption(item.label);
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ jsx(HvDropdown, { values: (_a = param.options) == null ? void 0 : _a.map((o) => {
|
|
28
|
+
return {
|
|
29
|
+
id: o,
|
|
30
|
+
label: o,
|
|
31
|
+
selected: o === option
|
|
32
|
+
};
|
|
33
|
+
}), onChange: (item) => onSelectChange(item) });
|
|
34
|
+
};
|
|
35
|
+
const Select$1 = Select;
|
|
36
|
+
export {
|
|
37
|
+
Select$1 as default
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=Select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.js","sources":["../../../../../../src/components/Flow/Node/Parameters/Select.tsx"],"sourcesContent":["import { HvDropdown } from \"@hitachivantara/uikit-react-core\";\nimport { useState } from \"react\";\nimport { useReactFlow } from \"reactflow\";\n\nconst Select = ({ nodeId, param, data }) => {\n const reactFlowInstance = useReactFlow();\n const [option, setOption] = useState(data[param.id]);\n\n const onSelectChange = (item) => {\n const nodes = reactFlowInstance.getNodes();\n const newNodes = nodes.map((node) => {\n if (node.id === nodeId) {\n node.data = { ...node.data, [param.id]: item.label };\n }\n return node;\n });\n reactFlowInstance.setNodes(newNodes);\n setOption(item.label);\n };\n\n return (\n <HvDropdown\n values={param.options?.map((o) => {\n return { id: o, label: o, selected: o === option };\n })}\n onChange={(item) => onSelectChange(item)}\n />\n );\n};\n\nexport default Select;\n"],"names":["Select","nodeId","param","data","reactFlowInstance","useReactFlow","option","setOption","useState","id","onSelectChange","item","nodes","getNodes","newNodes","map","node","label","setNodes","options","o","selected"],"mappings":";;;;AAIA,MAAMA,SAASA,CAAC;AAAA,EAAEC;AAAAA,EAAQC;AAAAA,EAAOC;AAAK,MAAM;;AAC1C,QAAMC,oBAAoBC;AACpB,QAAA,CAACC,QAAQC,SAAS,IAAIC,SAASL,KAAKD,MAAMO,EAAE,CAAC;AAEnD,QAAMC,iBAAkBC,CAAS,SAAA;AACzBC,UAAAA,QAAQR,kBAAkBS;AAC1BC,UAAAA,WAAWF,MAAMG,IAAKC,CAAS,SAAA;AAC/BA,UAAAA,KAAKP,OAAOR,QAAQ;AACtBe,aAAKb,OAAO;AAAA,UAAE,GAAGa,KAAKb;AAAAA,UAAM,CAACD,MAAMO,EAAE,GAAGE,KAAKM;AAAAA,QAAAA;AAAAA,MAC/C;AACOD,aAAAA;AAAAA,IAAAA,CACR;AACDZ,sBAAkBc,SAASJ,QAAQ;AACnCP,cAAUI,KAAKM,KAAK;AAAA,EAAA;AAGtB,6BACG,YACC,EAAA,SAAQf,WAAMiB,YAANjB,mBAAea,IAAKK,CAAM,MAAA;AACzB,WAAA;AAAA,MAAEX,IAAIW;AAAAA,MAAGH,OAAOG;AAAAA,MAAGC,UAAUD,MAAMd;AAAAA,IAAAA;AAAAA,EAAO,IAEnD,UAAWK,CAASD,SAAAA,eAAeC,IAAI,EACvC,CAAA;AAEN;AAEA,MAAA,WAAeX;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { HvInput } from "@hitachivantara/uikit-react-core";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useReactFlow } from "reactflow";
|
|
5
|
+
const Text = ({
|
|
6
|
+
nodeId,
|
|
7
|
+
param,
|
|
8
|
+
data
|
|
9
|
+
}) => {
|
|
10
|
+
const reactFlowInstance = useReactFlow();
|
|
11
|
+
const [text, setText] = useState(data[param.id]);
|
|
12
|
+
const onTextChange = (val) => {
|
|
13
|
+
const nodes = reactFlowInstance.getNodes();
|
|
14
|
+
const newNodes = nodes.map((node) => {
|
|
15
|
+
if (node.id === nodeId) {
|
|
16
|
+
node.data = {
|
|
17
|
+
...node.data,
|
|
18
|
+
[param.id]: val
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return node;
|
|
22
|
+
});
|
|
23
|
+
reactFlowInstance.setNodes(newNodes);
|
|
24
|
+
setText(val);
|
|
25
|
+
};
|
|
26
|
+
return /* @__PURE__ */ jsx(HvInput, { value: text, onChange: (evt, val) => onTextChange(val) });
|
|
27
|
+
};
|
|
28
|
+
const Text$1 = Text;
|
|
29
|
+
export {
|
|
30
|
+
Text$1 as default
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=Text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Text.js","sources":["../../../../../../src/components/Flow/Node/Parameters/Text.tsx"],"sourcesContent":["import { HvInput } from \"@hitachivantara/uikit-react-core\";\nimport { useState } from \"react\";\nimport { useReactFlow } from \"reactflow\";\n\nconst Text = ({ nodeId, param, data }) => {\n const reactFlowInstance = useReactFlow();\n const [text, setText] = useState(data[param.id]);\n\n const onTextChange = (val) => {\n const nodes = reactFlowInstance.getNodes();\n const newNodes = nodes.map((node) => {\n if (node.id === nodeId) {\n node.data = { ...node.data, [param.id]: val };\n }\n return node;\n });\n reactFlowInstance.setNodes(newNodes);\n setText(val);\n };\n\n return <HvInput value={text} onChange={(evt, val) => onTextChange(val)} />;\n};\n\nexport default Text;\n"],"names":["Text","nodeId","param","data","reactFlowInstance","useReactFlow","text","setText","useState","id","onTextChange","val","nodes","getNodes","newNodes","map","node","setNodes","evt"],"mappings":";;;;AAIA,MAAMA,OAAOA,CAAC;AAAA,EAAEC;AAAAA,EAAQC;AAAAA,EAAOC;AAAK,MAAM;AACxC,QAAMC,oBAAoBC;AACpB,QAAA,CAACC,MAAMC,OAAO,IAAIC,SAASL,KAAKD,MAAMO,EAAE,CAAC;AAE/C,QAAMC,eAAgBC,CAAQ,QAAA;AACtBC,UAAAA,QAAQR,kBAAkBS;AAC1BC,UAAAA,WAAWF,MAAMG,IAAKC,CAAS,SAAA;AAC/BA,UAAAA,KAAKP,OAAOR,QAAQ;AACtBe,aAAKb,OAAO;AAAA,UAAE,GAAGa,KAAKb;AAAAA,UAAM,CAACD,MAAMO,EAAE,GAAGE;AAAAA,QAAAA;AAAAA,MAC1C;AACOK,aAAAA;AAAAA,IAAAA,CACR;AACDZ,sBAAkBa,SAASH,QAAQ;AACnCP,YAAQI,GAAG;AAAA,EAAA;AAGN,SAAA,oBAAC,SAAQ,EAAA,OAAOL,MAAM,UAAU,CAACY,KAAKP,QAAQD,aAAaC,GAAG,EAAK,CAAA;AAC5E;AAEA,MAAA,SAAeX;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -19,11 +19,14 @@ import { HvFlowMinimap } from "./components/Flow/Minimap/Minimap.js";
|
|
|
19
19
|
import { staticClasses as staticClasses9 } from "./components/Flow/Sidebar/Sidebar.styles.js";
|
|
20
20
|
import { HvFlowSidebar } from "./components/Flow/Sidebar/Sidebar.js";
|
|
21
21
|
import { HvFlow } from "./components/Flow/Flow.js";
|
|
22
|
+
import { staticClasses as staticClasses10 } from "./components/Flow/Node/Node.styles.js";
|
|
23
|
+
import { HvFlowNode } from "./components/Flow/Node/Node.js";
|
|
22
24
|
export {
|
|
23
25
|
HvFlow,
|
|
24
26
|
HvFlowBackground,
|
|
25
27
|
HvFlowControls,
|
|
26
28
|
HvFlowMinimap,
|
|
29
|
+
HvFlowNode,
|
|
27
30
|
HvFlowSidebar,
|
|
28
31
|
HvStepNavigation,
|
|
29
32
|
HvWizard,
|
|
@@ -34,6 +37,7 @@ export {
|
|
|
34
37
|
HvWizardTitle,
|
|
35
38
|
staticClasses7 as flowClasses,
|
|
36
39
|
staticClasses8 as flowMinimapClasses,
|
|
40
|
+
staticClasses10 as flowNodeClasses,
|
|
37
41
|
staticClasses9 as flowSidebarClasses,
|
|
38
42
|
staticClasses as stepNavigationClasses,
|
|
39
43
|
staticClasses3 as wizardActionsClasses,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
|