@hitachivantara/uikit-react-lab 5.14.0 → 5.16.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 +1 -1
- package/dist/cjs/components/Flow/DroppableFlow.cjs.map +1 -1
- package/dist/cjs/components/Flow/Empty/Empty.cjs +1 -1
- package/dist/cjs/components/Flow/Empty/Empty.cjs.map +1 -1
- package/dist/cjs/components/Flow/Flow.styles.cjs +1 -0
- package/dist/cjs/components/Flow/Flow.styles.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/BaseNode.cjs +19 -7
- package/dist/cjs/components/Flow/Node/BaseNode.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/Node.cjs +2 -2
- package/dist/cjs/components/Flow/Node/Node.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/Parameters/Select.cjs +28 -10
- package/dist/cjs/components/Flow/Node/Parameters/Select.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/Parameters/Text.cjs +16 -4
- package/dist/cjs/components/Flow/Node/Parameters/Text.cjs.map +1 -1
- package/dist/cjs/components/Flow/hooks/useFlowNode.cjs +4 -4
- package/dist/cjs/components/Flow/hooks/useFlowNode.cjs.map +1 -1
- package/dist/esm/components/Flow/DroppableFlow.js +1 -1
- package/dist/esm/components/Flow/DroppableFlow.js.map +1 -1
- package/dist/esm/components/Flow/Empty/Empty.js +2 -2
- package/dist/esm/components/Flow/Empty/Empty.js.map +1 -1
- package/dist/esm/components/Flow/Flow.styles.js +1 -0
- package/dist/esm/components/Flow/Flow.styles.js.map +1 -1
- package/dist/esm/components/Flow/Node/BaseNode.js +20 -8
- package/dist/esm/components/Flow/Node/BaseNode.js.map +1 -1
- package/dist/esm/components/Flow/Node/Node.js +2 -2
- package/dist/esm/components/Flow/Node/Node.js.map +1 -1
- package/dist/esm/components/Flow/Node/Parameters/Select.js +28 -10
- package/dist/esm/components/Flow/Node/Parameters/Select.js.map +1 -1
- package/dist/esm/components/Flow/Node/Parameters/Text.js +16 -4
- package/dist/esm/components/Flow/Node/Parameters/Text.js.map +1 -1
- package/dist/esm/components/Flow/hooks/useFlowNode.js +5 -5
- package/dist/esm/components/Flow/hooks/useFlowNode.js.map +1 -1
- package/dist/types/index.d.ts +47 -38
- package/package.json +5 -5
|
@@ -33,7 +33,7 @@ const validateEdge = (nodes, edges, edge, nodeMetaRegistry) => {
|
|
|
33
33
|
const targetAccepts = inputs[edge.targetHandle]?.accepts || [];
|
|
34
34
|
const sourceMaxConnections = outputs[edge.sourceHandle]?.maxConnections;
|
|
35
35
|
const targetMaxConnections = inputs[edge.targetHandle]?.maxConnections;
|
|
36
|
-
let isValid = targetAccepts.includes(sourceProvides);
|
|
36
|
+
let isValid = targetAccepts.length === 0 || targetAccepts.includes(sourceProvides);
|
|
37
37
|
if (isValid && targetMaxConnections != null) {
|
|
38
38
|
const targetConnections = edges.filter((edg) => edg.target === edge.target && edg.targetHandle === edge.targetHandle).length;
|
|
39
39
|
isValid = targetConnections < targetMaxConnections;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DroppableFlow.cjs","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\";\n\nimport { Global } from \"@emotion/react\";\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 { HvFlowNodeMetaRegistry } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./hooks\";\nimport { flowStyles } from \"./base\";\nimport { useNodeMetaRegistry } from \"./FlowContext/NodeMetaContext\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeType extends string | undefined = string | undefined,\n NodeData = any\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 /** Callback called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n /**\n * Callback called when a node is dropped in the flow.\n *\n * This callback should be used to override the custom UI Kit drop event.\n * Thus, when defined, the user is responsible for adding nodes to the flow.\n *\n * This callback is called when `HvFlowSidebar` is used or a custom sidebar was created using Dnd Kit.\n * When a custom sidebar was created using the native HTML drag and drop API, refer to the `onDrop` callback.\n *\n * Returns the event and the node to be added to the flow.\n */\n onDndDrop?: (event: DragEndEvent, node: Node) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdge = (\n nodes: Node[],\n edges: Edge[],\n edge: Edge,\n nodeMetaRegistry: HvFlowNodeMetaRegistry\n) => {\n if (!edge.sourceHandle || !edge.targetHandle) return false;\n\n const sourceNode = getNode(nodes, edge.source);\n const targetNode = getNode(nodes, edge.target);\n\n if (!sourceNode || !targetNode) return false;\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) return false;\n\n const inputs = nodeMetaRegistry[edge.target]?.inputs || [];\n const outputs = nodeMetaRegistry[edge.source]?.outputs || [];\n\n const sourceProvides = outputs[edge.sourceHandle]?.provides || \"\";\n const targetAccepts = inputs[edge.targetHandle]?.accepts || [];\n const sourceMaxConnections = outputs[edge.sourceHandle]?.maxConnections;\n const targetMaxConnections = inputs[edge.targetHandle]?.maxConnections;\n\n let isValid = targetAccepts.includes(sourceProvides);\n\n if (isValid && targetMaxConnections != null) {\n const targetConnections = edges.filter(\n (edg) =>\n edg.target === edge.target && edg.targetHandle === edge.targetHandle\n ).length;\n\n isValid = targetConnections < targetMaxConnections;\n }\n\n if (isValid && sourceMaxConnections != null) {\n const sourceConnections = edges.filter(\n (edg) =>\n edg.source === edge.source && edg.sourceHandle === edge.sourceHandle\n ).length;\n\n isValid = sourceConnections < sourceMaxConnections;\n }\n\n return isValid;\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n onDndDrop,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n defaultEdgeOptions: defaultEdgeOptionsProp,\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.data.current?.hvFlow?.type;\n\n // Only known node types can be dropped in the canvas\n if (type && nodeTypes?.[type]) {\n // Converts the coordinates to the react flow coordinate system\n const position = reactFlowInstance.project({\n x:\n (event.active.data.current?.hvFlow?.x || 0) -\n event.over.rect.left,\n y:\n (event.active.data.current?.hvFlow?.y || 0) - event.over.rect.top,\n });\n\n // Node data\n const data = event.active.data.current?.hvFlow?.data || {};\n\n // Node to add\n const newNode: Node = {\n id: uid(),\n position,\n data,\n type,\n };\n\n // Drop override\n if (onDndDrop) {\n onDndDrop(event, newNode);\n return;\n }\n\n setNodes((nds) => nds.concat(newNode));\n } else {\n // eslint-disable-next-line no-console\n console.error(\n `Could not add node to the flow because of unknown type ${type}. Use nodeTypes to define all the node types.`\n );\n }\n }\n },\n [elementId, nodeTypes, onDndDrop, reactFlowInstance]\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 { registry } = useNodeMetaRegistry();\n const isValidConnection = (connection) =>\n validateEdge(nodes, edges, connection, registry);\n\n const defaultEdgeOptions = {\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n ...defaultEdgeOptionsProp,\n };\n\n return (\n <>\n <Global styles={flowStyles} />\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 isValidConnection={isValidConnection}\n defaultEdgeOptions={defaultEdgeOptions}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n </>\n );\n};\n"],"names":["getNode","nodes","nodeId","find","n","id","validateEdge","edges","edge","nodeMetaRegistry","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","inputs","outputs","sourceProvides","provides","targetAccepts","accepts","sourceMaxConnections","maxConnections","targetMaxConnections","isValid","includes","targetConnections","filter","edg","length","sourceConnections","HvDroppableFlow","className","children","onFlowChange","onDndDrop","classes","classesProp","initialNodes","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","defaultEdgeOptions","defaultEdgeOptionsProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","nodeTypes","useFlowContext","setNodes","useState","setEdges","setNodeRef","useDroppable","handleDragEnd","useCallback","event","over","active","data","current","hvFlow","position","project","x","rect","left","y","top","newNode","uid","nds","concat","error","useDndMonitor","onDragEnd","handleFlowChange","eds","isDragging","node","dragging","handleConnect","connection","addEdge","handleNodesChange","changes","applyNodeChanges","handleEdgesChange","applyEdgeChanges","registry","useNodeMetaRegistry","isValidConnection","markerEnd","MarkerType","ArrowClosed","height","width","jsxs","Fragment","jsx","Global","flowStyles","root","ReactFlow"],"mappings":";;;;;;;;;;;;;;;AA8DaA,MAAAA,UAAUA,CAACC,OAAeC,WAAmB;AACxD,SAAOD,MAAME,KAAMC,CAAMA,MAAAA,EAAEC,OAAOH,MAAM;AAC1C;AAEA,MAAMI,eAAeA,CACnBL,OACAM,OACAC,MACAC,qBACG;AACH,MAAI,CAACD,KAAKE,gBAAgB,CAACF,KAAKG;AAAqB,WAAA;AAErD,QAAMC,aAAaZ,QAAQC,OAAOO,KAAKK,MAAM;AAC7C,QAAMC,aAAad,QAAQC,OAAOO,KAAKO,MAAM;AAEzC,MAAA,CAACH,cAAc,CAACE;AAAmB,WAAA;AAEvC,QAAME,aAAaJ,WAAWK;AAC9B,QAAMC,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AA;AAAAA,MACjBC,QAAQ;AAAA,MACRC,OAAO;AAAA,IACT;AAAA,IACA,GAAGzD;AAAAA,EAAAA;AAGL,SAEI0D,2BAAA,KAAAC,qBAAA,EAAA,UAAA;AAAA,IAACC,2BAAAA,IAAAC,MAAA,QAAA,EAAO,QAAQC,KAAW,WAAA,CAAA;AAAA,IAC1BF,2BAAA,IAAA,OAAA,EACC,IAAIxD,WACJ,KAAKS,YACL,WAAWX,GAAGb,QAAQ0E,MAAM9E,SAAS,GAErC,UAAC2E,2BAAA,IAAAI,mBAAA,SAAA,EACC,OACA,OACA,WACA,eAAenB,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBACIzC,GAAAA,QAEHf,SAAAA,CACH,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"DroppableFlow.cjs","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\";\n\nimport { Global } from \"@emotion/react\";\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 { HvFlowNodeMetaRegistry } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./hooks\";\nimport { flowStyles } from \"./base\";\nimport { useNodeMetaRegistry } from \"./FlowContext/NodeMetaContext\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeType extends string | undefined = string | undefined,\n NodeData = any\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 /** Callback called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n /**\n * Callback called when a node is dropped in the flow.\n *\n * This callback should be used to override the custom UI Kit drop event.\n * Thus, when defined, the user is responsible for adding nodes to the flow.\n *\n * This callback is called when `HvFlowSidebar` is used or a custom sidebar was created using Dnd Kit.\n * When a custom sidebar was created using the native HTML drag and drop API, refer to the `onDrop` callback.\n *\n * Returns the event and the node to be added to the flow.\n */\n onDndDrop?: (event: DragEndEvent, node: Node) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdge = (\n nodes: Node[],\n edges: Edge[],\n edge: Edge,\n nodeMetaRegistry: HvFlowNodeMetaRegistry\n) => {\n if (!edge.sourceHandle || !edge.targetHandle) return false;\n\n const sourceNode = getNode(nodes, edge.source);\n const targetNode = getNode(nodes, edge.target);\n\n if (!sourceNode || !targetNode) return false;\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) return false;\n\n const inputs = nodeMetaRegistry[edge.target]?.inputs || [];\n const outputs = nodeMetaRegistry[edge.source]?.outputs || [];\n\n const sourceProvides = outputs[edge.sourceHandle]?.provides || \"\";\n const targetAccepts = inputs[edge.targetHandle]?.accepts || [];\n const sourceMaxConnections = outputs[edge.sourceHandle]?.maxConnections;\n const targetMaxConnections = inputs[edge.targetHandle]?.maxConnections;\n\n let isValid =\n targetAccepts.length === 0 || targetAccepts.includes(sourceProvides);\n\n if (isValid && targetMaxConnections != null) {\n const targetConnections = edges.filter(\n (edg) =>\n edg.target === edge.target && edg.targetHandle === edge.targetHandle\n ).length;\n\n isValid = targetConnections < targetMaxConnections;\n }\n\n if (isValid && sourceMaxConnections != null) {\n const sourceConnections = edges.filter(\n (edg) =>\n edg.source === edge.source && edg.sourceHandle === edge.sourceHandle\n ).length;\n\n isValid = sourceConnections < sourceMaxConnections;\n }\n\n return isValid;\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n onDndDrop,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n defaultEdgeOptions: defaultEdgeOptionsProp,\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.data.current?.hvFlow?.type;\n\n // Only known node types can be dropped in the canvas\n if (type && nodeTypes?.[type]) {\n // Converts the coordinates to the react flow coordinate system\n const position = reactFlowInstance.project({\n x:\n (event.active.data.current?.hvFlow?.x || 0) -\n event.over.rect.left,\n y:\n (event.active.data.current?.hvFlow?.y || 0) - event.over.rect.top,\n });\n\n // Node data\n const data = event.active.data.current?.hvFlow?.data || {};\n\n // Node to add\n const newNode: Node = {\n id: uid(),\n position,\n data,\n type,\n };\n\n // Drop override\n if (onDndDrop) {\n onDndDrop(event, newNode);\n return;\n }\n\n setNodes((nds) => nds.concat(newNode));\n } else {\n // eslint-disable-next-line no-console\n console.error(\n `Could not add node to the flow because of unknown type ${type}. Use nodeTypes to define all the node types.`\n );\n }\n }\n },\n [elementId, nodeTypes, onDndDrop, reactFlowInstance]\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 { registry } = useNodeMetaRegistry();\n const isValidConnection = (connection) =>\n validateEdge(nodes, edges, connection, registry);\n\n const defaultEdgeOptions = {\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n ...defaultEdgeOptionsProp,\n };\n\n return (\n <>\n <Global styles={flowStyles} />\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 isValidConnection={isValidConnection}\n defaultEdgeOptions={defaultEdgeOptions}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n </>\n );\n};\n"],"names":["getNode","nodes","nodeId","find","n","id","validateEdge","edges","edge","nodeMetaRegistry","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","inputs","outputs","sourceProvides","provides","targetAccepts","accepts","sourceMaxConnections","maxConnections","targetMaxConnections","isValid","length","includes","targetConnections","filter","edg","sourceConnections","HvDroppableFlow","className","children","onFlowChange","onDndDrop","classes","classesProp","initialNodes","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","defaultEdgeOptions","defaultEdgeOptionsProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","nodeTypes","useFlowContext","setNodes","useState","setEdges","setNodeRef","useDroppable","handleDragEnd","useCallback","event","over","active","data","current","hvFlow","position","project","x","rect","left","y","top","newNode","uid","nds","concat","error","useDndMonitor","onDragEnd","handleFlowChange","eds","isDragging","node","dragging","handleConnect","connection","addEdge","handleNodesChange","changes","applyNodeChanges","handleEdgesChange","applyEdgeChanges","registry","useNodeMetaRegistry","isValidConnection","markerEnd","MarkerType","ArrowClosed","height","width","jsxs","Fragment","jsx","Global","flowStyles","root","ReactFlow"],"mappings":";;;;;;;;;;;;;;;AA8DaA,MAAAA,UAAUA,CAACC,OAAeC,WAAmB;AACxD,SAAOD,MAAME,KAAMC,CAAMA,MAAAA,EAAEC,OAAOH,MAAM;AAC1C;AAEA,MAAMI,eAAeA,CACnBL,OACAM,OACAC,MACAC,qBACG;AACH,MAAI,CAACD,KAAKE,gBAAgB,CAACF,KAAKG;AAAqB,WAAA;AAErD,QAAMC,aAAaZ,QAAQC,OAAOO,KAAKK,MAAM;AAC7C,QAAMC,aAAad,QAAQC,OAAOO,KAAKO,MAAM;AAEzC,MAAA,CAACH,cAAc,CAACE;AAAmB,WAAA;AAEvC,QAAME,aAAaJ,WAAWK;AAC9B,QAAMC,aAAaJ,WAAWG;AAE1B,MAAA,CAACD,cAAc,CAACE;AAAmB,WAAA;AAEvC,QAAMC,SAASV,iBAAiBD,KAAKO,MAAM,GAAGI,UAAU;AACxD,QAAMC,UAAUX,iBAAiBD,KAAKK,MAAM,GAAGO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,2BAAAA,IAAAC,MAAA,QAAA,EAAO,QAAQC,KAAW,WAAA,CAAA;AAAA,IAC1BF,2BAAA,IAAA,OAAA,EACC,IAAIxD,WACJ,KAAKS,YACL,WAAWX,GAAGb,QAAQ0E,MAAM9E,SAAS,GAErC,UAAC2E,2BAAA,IAAAI,mBAAA,SAAA,EACC,OACA,OACA,WACA,eAAenB,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBACIzC,GAAAA,QAEHf,SAAAA,CACH,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;;;;"}
|
|
@@ -12,7 +12,7 @@ const HvFlowEmpty = ({
|
|
|
12
12
|
classes,
|
|
13
13
|
cx
|
|
14
14
|
} = Empty_styles.useClasses();
|
|
15
|
-
const nodes = ReactFlow.
|
|
15
|
+
const nodes = ReactFlow.useNodes();
|
|
16
16
|
return !nodes || (nodes.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvEmptyState, { className: cx(classes.root, className), ...others }) : null);
|
|
17
17
|
};
|
|
18
18
|
exports.HvFlowEmpty = HvFlowEmpty;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Empty.cjs","sources":["../../../../../src/components/Flow/Empty/Empty.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Empty.cjs","sources":["../../../../../src/components/Flow/Empty/Empty.tsx"],"sourcesContent":["import { useNodes } from \"reactflow\";\nimport {\n HvEmptyState,\n HvEmptyStateProps,\n} from \"@hitachivantara/uikit-react-core\";\n\nimport { useClasses } from \"./Empty.styles\";\n\nexport interface HvFlowEmptyProps extends HvEmptyStateProps {}\n\nexport const HvFlowEmpty = ({ className, ...others }: HvFlowEmptyProps) => {\n const { classes, cx } = useClasses();\n const nodes = useNodes();\n return (\n !nodes ||\n (nodes.length === 0 ? (\n <HvEmptyState className={cx(classes.root, className)} {...others} />\n ) : null)\n );\n};\n"],"names":["HvFlowEmpty","className","others","classes","cx","useClasses","nodes","useNodes","length","jsx","HvEmptyState","root"],"mappings":";;;;;;AAUO,MAAMA,cAAcA,CAAC;AAAA,EAAEC;AAAAA,EAAW,GAAGC;AAAyB,MAAM;AACnE,QAAA;AAAA,IAAEC;AAAAA,IAASC;AAAAA,MAAOC,aAAW,WAAA;AACnC,QAAMC,QAAQC,UAAAA;AACd,SACE,CAACD,UACAA,MAAME,WAAW,IACfC,2BAAAA,IAAAC,eAAAA,cAAA,EAAa,WAAWN,GAAGD,QAAQQ,MAAMV,SAAS,GAAG,GAAIC,OAAU,CAAA,IAClE;AAER;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flow.styles.cjs","sources":["../../../../src/components/Flow/Flow.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nimport { flowBaseNodeClasses } 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-left\": {\n translate: \"0 4px\",\n },\n },\n \"& .react-flow__handle-valid\": {\n backgroundColor: theme.colors.positive_20,\n width: 12,\n height: 12,\n \"&.react-flow__handle-left\": {\n translate: \"0 4px\",\n },\n },\n [`& .selected > .${flowBaseNodeClasses.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","translate","positive_20","flowBaseNodeClasses","border","borderRadius","radii","round","boxSizing"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Flow.styles.cjs","sources":["../../../../src/components/Flow/Flow.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nimport { flowBaseNodeClasses } 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-left\": {\n translate: \"0 4px\",\n },\n },\n \"& .react-flow__handle-valid\": {\n backgroundColor: theme.colors.positive_20,\n width: 12,\n height: 12,\n \"&.react-flow__handle-left\": {\n translate: \"0 4px\",\n },\n },\n [`& .selected > .${flowBaseNodeClasses.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","translate","positive_20","flowBaseNodeClasses","border","borderRadius","radii","round","boxSizing"],"mappings":";;;;;;;;;;AAIa,MAAA;AAAA,EAAEA;AAAAA,EAAeC;AAAW,IAAIC,eAAAA,cAAc,UAAU;AAAA,EACnEC,MAAM;AAAA,IACJC,QAAQ;AAAA,IACR,yBAAyB;AAAA,MACvBC,iBAAiBC,eAAAA,MAAMC,OAAOC;AAAAA,MAC9BC,OAAO;AAAA,MACPL,QAAQ;AAAA,MACRM,QAAQJ,eAAAA,MAAMK,SAASC;AAAAA,IACzB;AAAA,IACA,oCAAoC;AAAA,MAClCP,iBAAiBC,eAAAA,MAAMC,OAAOM;AAAAA,MAC9BJ,OAAO;AAAA,MACPL,QAAQ;AAAA,MACR,6BAA6B;AAAA,QAC3BU,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,+BAA+B;AAAA,MAC7BT,iBAAiBC,eAAAA,MAAMC,OAAOQ;AAAAA,MAC9BN,OAAO;AAAA,MACPL,QAAQ;AAAA,MACR,6BAA6B;AAAA,QAC3BU,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,CAAE,kBAAiBE,8BAAoBb,IAAK,EAAC,GAAG;AAAA,MAC9Cc,QAAS,aAAYX,eAAMC,MAAAA,OAAOC,YAAa;AAAA,MAC/CU,cAAcZ,eAAAA,MAAMa,MAAMC;AAAAA,MAC1BC,WAAW;AAAA,IACb;AAAA,EACF;AACF,CAAC;;;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const ReactFlow = require("reactflow");
|
|
6
|
+
const uid = require("uid");
|
|
6
7
|
const uikitReactCore = require("@hitachivantara/uikit-react-core");
|
|
7
8
|
const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
|
|
8
9
|
const uikitStyles = require("@hitachivantara/uikit-styles");
|
|
@@ -59,8 +60,8 @@ const HvFlowBaseNode = ({
|
|
|
59
60
|
cx,
|
|
60
61
|
css
|
|
61
62
|
} = BaseNode_styles.useClasses(classesProp);
|
|
62
|
-
const edges = ReactFlow.
|
|
63
|
-
const nodes = ReactFlow.
|
|
63
|
+
const edges = ReactFlow.useEdges();
|
|
64
|
+
const nodes = ReactFlow.useNodes();
|
|
64
65
|
const node = nodes.find((n) => n.id === id);
|
|
65
66
|
const handleDefaultAction = React.useCallback((action) => {
|
|
66
67
|
if (!node)
|
|
@@ -78,7 +79,7 @@ const HvFlowBaseNode = ({
|
|
|
78
79
|
case "duplicate":
|
|
79
80
|
reactFlowInstance.addNodes([{
|
|
80
81
|
...node,
|
|
81
|
-
id:
|
|
82
|
+
id: uid.uid(),
|
|
82
83
|
position: {
|
|
83
84
|
x: node.position.x,
|
|
84
85
|
y: node.position.y + (node.height || 0) + 20
|
|
@@ -92,14 +93,25 @@ const HvFlowBaseNode = ({
|
|
|
92
93
|
if (!node)
|
|
93
94
|
return null;
|
|
94
95
|
const color = uikitStyles.getColor(colorProp);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
const iconColor = React.isValidElement(icon) ? uikitStyles.getColor(icon.props.color || "base_dark") : uikitStyles.getColor("base_dark");
|
|
97
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(
|
|
98
|
+
"nowheel",
|
|
99
|
+
// Disables the default canvas pan behaviour when scrolling inside the node
|
|
100
|
+
css({
|
|
101
|
+
border: `1px solid ${color}`
|
|
102
|
+
}),
|
|
103
|
+
classes.root,
|
|
104
|
+
className
|
|
105
|
+
), onMouseEnter: () => setShowActions(true), onMouseLeave: () => setShowActions(false), children: [
|
|
98
106
|
/* @__PURE__ */ jsxRuntime.jsx(ReactFlow.NodeToolbar, { isVisible: showActions, offset: 0, children: nodeActions?.map((action) => /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvButton, { icon: true, onClick: () => handleDefaultAction(action), children: renderedIcon(action.icon) }, action.id)) }),
|
|
99
107
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(css({
|
|
100
108
|
backgroundColor: color
|
|
101
109
|
}), classes.headerContainer), children: [
|
|
102
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.titleContainer,
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(classes.titleContainer, css({
|
|
111
|
+
"& svg *.color0": {
|
|
112
|
+
fill: iconColor
|
|
113
|
+
}
|
|
114
|
+
})), children: [
|
|
103
115
|
icon,
|
|
104
116
|
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { variant: "title4", className: classes.title, children: title })
|
|
105
117
|
] }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseNode.cjs","sources":["../../../../../src/components/Flow/Node/BaseNode.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\n\nimport {\n Edge,\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useReactFlow,\n useStore,\n} from \"reactflow\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvBaseProps,\n HvButton,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Delete, Duplicate } from \"@hitachivantara/uikit-react-icons\";\nimport { HvColorAny, getColor, theme } from \"@hitachivantara/uikit-styles\";\n\nimport {\n HvFlowNodeAction,\n HvFlowBuiltInActions,\n HvFlowNodeInput,\n HvFlowNodeOutput,\n} from \"../types/index\";\nimport { useNodeMetaRegistry } from \"../FlowContext/NodeMetaContext\";\nimport { staticClasses, useClasses } from \"./BaseNode.styles\";\n\nexport { staticClasses as flowBaseNodeClasses };\n\nexport type HvFlowBaseNodeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFlowBaseNodeProps<T = any>\n extends Omit<HvBaseProps, \"id\">,\n NodeProps<T> {\n /** Header title */\n title?: string;\n /** Header icon */\n icon?: React.ReactNode;\n /** Header color */\n color?: HvColorAny;\n /** Header items */\n headerItems?: React.ReactNode;\n /** Node inputs */\n inputs?: HvFlowNodeInput[];\n /** Node outputs */\n outputs?: HvFlowNodeOutput[];\n /** Node actions */\n nodeActions?: HvFlowNodeAction[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowBaseNodeClasses;\n}\n\nconst isInputConnected = (\n id: string,\n type: \"target\" | \"source\",\n idx: number,\n edges: Edge[]\n) => {\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 return false;\n};\n\nconst defaultActions: HvFlowBuiltInActions[] = [\n { id: \"delete\", label: \"Delete\", icon: <Delete /> },\n { id: \"duplicate\", label: \"Duplicate\", icon: <Duplicate /> },\n];\n\nconst renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\n\nexport const HvFlowBaseNode = ({\n id,\n title,\n headerItems,\n icon,\n color: colorProp,\n inputs,\n outputs,\n nodeActions = defaultActions,\n classes: classesProp,\n className,\n children,\n}: HvFlowBaseNodeProps<unknown>) => {\n const { registerNode, unregisterNode } = useNodeMetaRegistry();\n useEffect(() => {\n registerNode(id, { label: title || \"\", inputs, outputs });\n return () => unregisterNode(id);\n }, [id, title, inputs, outputs, registerNode, unregisterNode]);\n\n const [showActions, setShowActions] = useState(false);\n const reactFlowInstance = useReactFlow();\n\n const { classes, cx, css } = useClasses(classesProp);\n\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 handleDefaultAction = useCallback(\n (action: HvFlowNodeAction) => {\n if (!node) return;\n\n if (action.callback) {\n action.callback(node);\n return;\n }\n\n // built-in actions\n switch (action.id) {\n case \"delete\":\n reactFlowInstance.deleteElements({ nodes: [node] });\n break;\n case \"duplicate\":\n reactFlowInstance.addNodes([\n {\n ...node,\n id: `${reactFlowInstance.getNodes().length + 1}`,\n position: {\n x: node.position.x,\n y: node.position.y + (node.height || 0) + 20,\n },\n selected: false,\n zIndex: Number(theme.zIndices.overlay),\n },\n ]);\n break;\n default:\n break;\n }\n },\n [node, reactFlowInstance]\n );\n\n if (!node) return null;\n\n const color = getColor(colorProp);\n\n return (\n <div\n className={cx(\n css({ border: `1px solid ${color}` }),\n classes.root,\n className\n )}\n onMouseEnter={() => setShowActions(true)}\n onMouseLeave={() => setShowActions(false)}\n >\n <NodeToolbar isVisible={showActions} offset={0}>\n {nodeActions?.map((action) => (\n <HvButton\n key={action.id}\n icon\n onClick={() => handleDefaultAction(action)}\n >\n {renderedIcon(action.icon)}\n </HvButton>\n ))}\n </NodeToolbar>\n <div\n className={cx(css({ backgroundColor: color }), classes.headerContainer)}\n >\n <div className={classes.titleContainer}>\n {icon}\n <HvTypography variant=\"title4\" className={classes.title}>\n {title}\n </HvTypography>\n </div>\n {headerItems && <div style={{ display: \"flex\" }}>{headerItems}</div>}\n </div>\n {children && <div className={classes.contentContainer}>{children}</div>}\n {inputs && inputs.length > 0 && (\n <>\n <div className={classes.inputsTitleContainer}>\n <HvTypography>Inputs</HvTypography>\n </div>\n\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: \"auto\",\n bottom:\n (outputs?.length ? 80 : 18) +\n (outputs?.length || 0) * 29 +\n 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 </>\n )}\n {outputs && outputs.length > 0 && (\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: -10 + 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 </>\n )}\n </div>\n );\n};\n"],"names":["isInputConnected","id","type","idx","edges","some","e","target","targetHandle","toString","source","sourceHandle","defaultActions","label","icon","Delete","Duplicate","renderedIcon","actionIcon","isValidElement","HvFlowBaseNode","title","headerItems","color","colorProp","inputs","outputs","nodeActions","classes","classesProp","className","children","registerNode","unregisterNode","useNodeMetaRegistry","useEffect","showActions","setShowActions","useState","reactFlowInstance","useReactFlow","cx","css","useClasses","useStore","s","nodes","getNodes","node","find","n","handleDefaultAction","useCallback","action","callback","deleteElements","addNodes","length","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","getColor","jsxs","border","root","jsx","NodeToolbar","map","HvButton","backgroundColor","headerContainer","titleContainer","HvTypography","display","contentContainer","Fragment","inputsTitleContainer","inputsContainer","input","inputContainer","Handle","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;AAwDA,MAAMA,mBAAmBA,CACvBC,IACAC,MACAC,KACAC,UACG;AACH,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;AAEO,SAAA;AACT;AAEA,MAAMG,iBAAyC,CAC7C;AAAA,EAAEX,IAAI;AAAA,EAAUY,OAAO;AAAA,EAAUC,qCAAOC,gBAAM,QAAA,EAAA;AAAI,GAClD;AAAA,EAAEd,IAAI;AAAA,EAAaY,OAAO;AAAA,EAAaC,qCAAOE,gBAAS,WAAA,EAAA;AAAI,CAAC;AAG9D,MAAMC,eAAeA,CAACC,eACpBC,qBAAeD,UAAU,IAAIA,aAAcA;AAEtC,MAAME,iBAAiBA,CAAC;AAAA,EAC7BnB;AAAAA,EACAoB;AAAAA,EACAC;AAAAA,EACAR;AAAAA,EACAS,OAAOC;AAAAA,EACPC;AAAAA,EACAC;AAAAA,EACAC,cAAcf;AAAAA,EACdgB,SAASC;AAAAA,EACTC;AAAAA,EACAC;AAC4B,MAAM;AAC5B,QAAA;AAAA,IAAEC;AAAAA,IAAcC;AAAAA,MAAmBC,gBAAoB,oBAAA;AAC7DC,QAAAA,UAAU,MAAM;AACdH,iBAAa/B,IAAI;AAAA,MAAEY,OAAOQ,SAAS;AAAA,MAAII;AAAAA,MAAQC;AAAAA,IAAAA,CAAS;AACjD,WAAA,MAAMO,eAAehC,EAA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;AAAA,QAEHM,OAAOJ,eACN,CAAC5F,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxCoE,2BAAAA,IAAC,OAAI,EAAA,WAAW5C,QAAQiE,UACzB,CAAA;AAAA,QACHrB,2BAAAA,IAACO,eAAAA,cAAciB,EAAAA,UAAAA,OAAOnF,MAAM,CAAA;AAAA,MAAA,KAfgBV,GAgB9C,CACD,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
1
|
+
{"version":3,"file":"BaseNode.cjs","sources":["../../../../../src/components/Flow/Node/BaseNode.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\nimport {\n Edge,\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useEdges,\n useNodes,\n useReactFlow,\n} from \"reactflow\";\nimport { uid } from \"uid\";\nimport {\n ExtractNames,\n HvActionGeneric,\n HvBaseProps,\n HvButton,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Delete, Duplicate } from \"@hitachivantara/uikit-react-icons\";\nimport { HvColorAny, getColor, theme } from \"@hitachivantara/uikit-styles\";\n\nimport {\n HvFlowNodeAction,\n HvFlowBuiltInActions,\n HvFlowNodeInput,\n HvFlowNodeOutput,\n} from \"../types\";\nimport { useNodeMetaRegistry } from \"../FlowContext/NodeMetaContext\";\nimport { staticClasses, useClasses } from \"./BaseNode.styles\";\n\nexport { staticClasses as flowBaseNodeClasses };\n\nexport type HvFlowBaseNodeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFlowBaseNodeProps<T = any>\n extends Omit<HvBaseProps, \"id\">,\n NodeProps<T> {\n /** Header title */\n title?: string;\n /** Header icon */\n icon?: React.ReactNode;\n /** Header color */\n color?: HvColorAny;\n /** Header items */\n headerItems?: React.ReactNode;\n /** Node inputs */\n inputs?: HvFlowNodeInput[];\n /** Node outputs */\n outputs?: HvFlowNodeOutput[];\n /** Node actions */\n nodeActions?: HvFlowNodeAction[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowBaseNodeClasses;\n}\n\nconst isInputConnected = (\n id: string,\n type: \"target\" | \"source\",\n idx: number,\n edges: Edge[]\n) => {\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 return false;\n};\n\nconst defaultActions: HvFlowBuiltInActions[] = [\n { id: \"delete\", label: \"Delete\", icon: <Delete /> },\n { id: \"duplicate\", label: \"Duplicate\", icon: <Duplicate /> },\n];\n\nconst renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\n\nexport const HvFlowBaseNode = ({\n id,\n title,\n headerItems,\n icon,\n color: colorProp,\n inputs,\n outputs,\n nodeActions = defaultActions,\n classes: classesProp,\n className,\n children,\n}: HvFlowBaseNodeProps<unknown>) => {\n const { registerNode, unregisterNode } = useNodeMetaRegistry();\n useEffect(() => {\n registerNode(id, { label: title || \"\", inputs, outputs });\n return () => unregisterNode(id);\n }, [id, title, inputs, outputs, registerNode, unregisterNode]);\n\n const [showActions, setShowActions] = useState(false);\n const reactFlowInstance = useReactFlow();\n\n const { classes, cx, css } = useClasses(classesProp);\n\n const edges = useEdges();\n const nodes = useNodes();\n\n const node = nodes.find((n) => n.id === id);\n\n const handleDefaultAction = useCallback(\n (action: HvFlowNodeAction) => {\n if (!node) return;\n\n if (action.callback) {\n action.callback(node);\n return;\n }\n\n // built-in actions\n switch (action.id) {\n case \"delete\":\n reactFlowInstance.deleteElements({ nodes: [node] });\n break;\n case \"duplicate\":\n reactFlowInstance.addNodes([\n {\n ...node,\n id: uid(),\n position: {\n x: node.position.x,\n y: node.position.y + (node.height || 0) + 20,\n },\n selected: false,\n zIndex: Number(theme.zIndices.overlay),\n },\n ]);\n break;\n default:\n break;\n }\n },\n [node, reactFlowInstance]\n );\n\n if (!node) return null;\n\n const color = getColor(colorProp);\n const iconColor = isValidElement(icon)\n ? getColor(icon.props.color || \"base_dark\")\n : getColor(\"base_dark\");\n\n return (\n <div\n className={cx(\n \"nowheel\", // Disables the default canvas pan behaviour when scrolling inside the node\n css({ border: `1px solid ${color}` }),\n classes.root,\n className\n )}\n onMouseEnter={() => setShowActions(true)}\n onMouseLeave={() => setShowActions(false)}\n >\n <NodeToolbar isVisible={showActions} offset={0}>\n {nodeActions?.map((action) => (\n <HvButton\n key={action.id}\n icon\n onClick={() => handleDefaultAction(action)}\n >\n {renderedIcon(action.icon)}\n </HvButton>\n ))}\n </NodeToolbar>\n <div\n className={cx(css({ backgroundColor: color }), classes.headerContainer)}\n >\n <div\n className={cx(\n classes.titleContainer,\n css({ \"& svg *.color0\": { fill: iconColor } })\n )}\n >\n {icon}\n <HvTypography variant=\"title4\" className={classes.title}>\n {title}\n </HvTypography>\n </div>\n {headerItems && <div style={{ display: \"flex\" }}>{headerItems}</div>}\n </div>\n {children && <div className={classes.contentContainer}>{children}</div>}\n {inputs && inputs.length > 0 && (\n <>\n <div className={classes.inputsTitleContainer}>\n <HvTypography>Inputs</HvTypography>\n </div>\n\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: \"auto\",\n bottom:\n (outputs?.length ? 80 : 18) +\n (outputs?.length || 0) * 29 +\n 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 </>\n )}\n {outputs && outputs.length > 0 && (\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: -10 + 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 </>\n )}\n </div>\n );\n};\n"],"names":["isInputConnected","id","type","idx","edges","some","e","target","targetHandle","toString","source","sourceHandle","defaultActions","label","icon","Delete","Duplicate","renderedIcon","actionIcon","isValidElement","HvFlowBaseNode","title","headerItems","color","colorProp","inputs","outputs","nodeActions","classes","classesProp","className","children","registerNode","unregisterNode","useNodeMetaRegistry","useEffect","showActions","setShowActions","useState","reactFlowInstance","useReactFlow","cx","css","useClasses","useEdges","nodes","useNodes","node","find","n","handleDefaultAction","useCallback","action","callback","deleteElements","addNodes","uid","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","getColor","iconColor","props","jsxs","border","root","jsx","NodeToolbar","map","HvButton","backgroundColor","headerContainer","titleContainer","fill","HvTypography","display","contentContainer","length","Fragment","inputsTitleContainer","inputsContainer","input","inputContainer","Handle","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;;AAwDA,MAAMA,mBAAmBA,CACvBC,IACAC,MACAC,KACAC,UACG;AACH,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;AAEO,SAAA;AACT;AAEA,MAAMG,iBAAyC,CAC7C;AAAA,EAAEX,IAAI;AAAA,EAAUY,OAAO;AAAA,EAAUC,qCAAOC,gBAAM,QAAA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QAC1B2E,MAAMO,eACL,CAAC/F,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxCqE,2BAAAA,IAAC,OAAI,EAAA,WAAW7C,QAAQoE,UACzB,CAAA;AAAA,MAAA,KAlBwC7F,GAmB7C,CACD,GACH;AAAA,IAAA,GACF;AAAA,IAEDuB,WAAWA,QAAQ0D,SAAS,KAEzBd,2BAAAA,KAAAe,WAAAA,UAAA,EAAA,UAAA;AAAA,MAAAZ,2BAAAA,IAAC,SAAI,WAAW7C,QAAQqE,uBACtB,UAACxB,2BAAA,IAAAQ,eAAA,cAAA,EAAa,qBAAO,EACvB,CAAA;AAAA,MACCR,2BAAA,IAAA,OAAA,EAAI,WAAW7C,QAAQsE,kBACrBxE,UAASiD,SAAAA,IAAI,CAACwB,QAAQhG,QACrBmE,2BAAAA,KAAC,OAAI,EAAA,WAAW1C,QAAQwE,iBACtB,UAAA;AAAA,QAAA3B,2BAAA,IAACiB,UACC,QAAA,EAAA,MAAK,UACL,kBAAkB,OAClB,IAAK,GAAEvF,GAAI,IACX,UAAUwF,UAAAA,SAASU,OACnB,OAAO;AAAA,UACLP,QAAQ,MAAM,MAAMpE,QAAQ0D,SAASjF;AAAAA,UACrC0F,KAAK;AAAA,QAAA,GACL;AAAA,QAEHM,OAAOJ,eACN,CAAC/F,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxCqE,2BAAAA,IAAC,OAAI,EAAA,WAAW7C,QAAQoE,UACzB,CAAA;AAAA,QACHvB,2BAAAA,IAACQ,eAAAA,cAAckB,EAAAA,UAAAA,OAAOtF,MAAM,CAAA;AAAA,MAAA,KAfgBV,GAgB9C,CACD,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
@@ -51,8 +51,8 @@ const HvFlowNode = ({
|
|
|
51
51
|
const hasParams = !!(params && params.length > 0);
|
|
52
52
|
return /* @__PURE__ */ jsxRuntime.jsxs(BaseNode.HvFlowBaseNode, { id, type, title: groupLabel, icon, color, inputs, outputs, nodeActions: defaultActions, classes: classesProp, headerItems: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
53
53
|
headerItems,
|
|
54
|
-
description && /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTooltip, { title: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: description }), children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Info, {}) }) }),
|
|
55
|
-
hasParams && /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvButton, { icon: true, onClick: () => setShowParams((p) => !p), children: showParams ? /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Up, {}) : /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Down, {}) })
|
|
54
|
+
description && /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTooltip, { title: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: description }), children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Info, { color: "base_dark" }) }) }),
|
|
55
|
+
hasParams && /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvButton, { icon: true, overrideIconColors: false, onClick: () => setShowParams((p) => !p), children: showParams ? /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Up, { color: "base_dark" }) : /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Down, { color: "base_dark" }) })
|
|
56
56
|
] }), ...props, children: [
|
|
57
57
|
(subtitle || actsVisible?.length || actsDropdown?.length) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.subtitleContainer, children: [
|
|
58
58
|
subtitle && /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: subtitle }) }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.cjs","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import React, { SyntheticEvent, isValidElement, useState } from \"react\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvButton,\n HvDropDownMenu,\n HvTooltip,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { getColor } from \"@hitachivantara/uikit-styles\";\nimport { Down, Info, Up } from \"@hitachivantara/uikit-react-icons\";\n\nimport { useFlowContext, useFlowNode } from \"../hooks/index\";\nimport { HvFlowNodeParam } from \"../types/index\";\nimport { staticClasses, useClasses } from \"./Node.styles\";\nimport ParamRenderer from \"./Parameters/ParamRenderer\";\nimport { HvFlowBaseNode, HvFlowBaseNodeProps } from \"./BaseNode\";\n\nexport { staticClasses as flowNodeClasses };\n// TODO How to include here the types from the parent component?\nexport type HvFlowNodeClasses = ExtractNames<typeof useClasses>;\n\nexport type HvFlowNodeDefaults = {\n title?: string;\n subTitle?: string;\n color?: string;\n icon?: React.ReactNode;\n};\n\nexport interface HvFlowNodeProps<T = any>\n extends Omit<HvFlowBaseNodeProps<T>, \"classes\"> {\n /** Node description */\n description?: string;\n /** Node actions */\n actions?: HvActionGeneric[]; // HvFlowNodeActions[];\n /** Node action callback */\n actionCallback?: HvActionsGenericProps[\"actionsCallback\"];\n /** Node maximum number of actions visible */\n maxVisibleActions?: number;\n /** Node expanded */\n expanded?: boolean;\n /** Node parameters */\n params?: HvFlowNodeParam[];\n /** A set of node default values for when there are no groups to fetch this data from. */\n nodeDefaults?: HvFlowNodeDefaults;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowNodeClasses | HvFlowBaseNodeProps<T>[\"classes\"];\n}\n\nconst renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\n\nexport const HvFlowNode = ({\n id,\n type,\n headerItems,\n description,\n actions,\n actionCallback,\n maxVisibleActions = 1,\n expanded = false,\n params,\n nodeDefaults,\n classes: classesProp,\n children,\n ...props\n}: HvFlowNodeProps<unknown>) => {\n const { classes } = useClasses(classesProp as HvFlowNodeClasses);\n const [showParams, setShowParams] = useState(expanded);\n const { node } = useFlowNode(id);\n\n const { nodeGroups, nodeTypes, defaultActions } = useFlowContext();\n const groupId = nodeTypes?.[type].meta?.groupId;\n const subtitle = nodeTypes?.[type].meta?.label || nodeDefaults?.subTitle;\n const groupLabel =\n (groupId && nodeGroups && nodeGroups[groupId].label) || nodeDefaults?.title;\n\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon =\n (groupId && nodeGroups && nodeGroups[groupId].icon) || nodeDefaults?.icon;\n const colorProp =\n (groupId && nodeGroups && nodeGroups[groupId].color) || nodeDefaults?.color;\n const color = getColor(colorProp);\n\n const actsVisible = actions?.slice(0, maxVisibleActions);\n const actsDropdown = actions?.slice(maxVisibleActions);\n\n const hasParams = !!(params && params.length > 0);\n\n return (\n <HvFlowBaseNode\n id={id}\n type={type}\n title={groupLabel}\n icon={icon}\n color={color}\n inputs={inputs}\n outputs={outputs}\n nodeActions={defaultActions}\n classes={classesProp as HvFlowBaseNodeProps<unknown>[\"classes\"]}\n headerItems={\n <>\n {headerItems}\n {description && (\n <HvTooltip title={<HvTypography>{description}</HvTypography>}>\n <div>\n <Info />\n </div>\n </HvTooltip>\n )}\n {hasParams && (\n <HvButton
|
|
1
|
+
{"version":3,"file":"Node.cjs","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import React, { SyntheticEvent, isValidElement, useState } from \"react\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvButton,\n HvDropDownMenu,\n HvTooltip,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { getColor } from \"@hitachivantara/uikit-styles\";\nimport { Down, Info, Up } from \"@hitachivantara/uikit-react-icons\";\n\nimport { useFlowContext, useFlowNode } from \"../hooks/index\";\nimport { HvFlowNodeParam } from \"../types/index\";\nimport { staticClasses, useClasses } from \"./Node.styles\";\nimport ParamRenderer from \"./Parameters/ParamRenderer\";\nimport { HvFlowBaseNode, HvFlowBaseNodeProps } from \"./BaseNode\";\n\nexport { staticClasses as flowNodeClasses };\n// TODO How to include here the types from the parent component?\nexport type HvFlowNodeClasses = ExtractNames<typeof useClasses>;\n\nexport type HvFlowNodeDefaults = {\n title?: string;\n subTitle?: string;\n color?: string;\n icon?: React.ReactNode;\n};\n\nexport interface HvFlowNodeProps<T = any>\n extends Omit<HvFlowBaseNodeProps<T>, \"classes\"> {\n /** Node description */\n description?: string;\n /** Node actions */\n actions?: HvActionGeneric[]; // HvFlowNodeActions[];\n /** Node action callback */\n actionCallback?: HvActionsGenericProps[\"actionsCallback\"];\n /** Node maximum number of actions visible */\n maxVisibleActions?: number;\n /** Node expanded */\n expanded?: boolean;\n /** Node parameters */\n params?: HvFlowNodeParam[];\n /** A set of node default values for when there are no groups to fetch this data from. */\n nodeDefaults?: HvFlowNodeDefaults;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowNodeClasses | HvFlowBaseNodeProps<T>[\"classes\"];\n}\n\nconst renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\n\nexport const HvFlowNode = ({\n id,\n type,\n headerItems,\n description,\n actions,\n actionCallback,\n maxVisibleActions = 1,\n expanded = false,\n params,\n nodeDefaults,\n classes: classesProp,\n children,\n ...props\n}: HvFlowNodeProps<unknown>) => {\n const { classes } = useClasses(classesProp as HvFlowNodeClasses);\n const [showParams, setShowParams] = useState(expanded);\n const { node } = useFlowNode(id);\n\n const { nodeGroups, nodeTypes, defaultActions } = useFlowContext();\n const groupId = nodeTypes?.[type].meta?.groupId;\n const subtitle = nodeTypes?.[type].meta?.label || nodeDefaults?.subTitle;\n const groupLabel =\n (groupId && nodeGroups && nodeGroups[groupId].label) || nodeDefaults?.title;\n\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon =\n (groupId && nodeGroups && nodeGroups[groupId].icon) || nodeDefaults?.icon;\n const colorProp =\n (groupId && nodeGroups && nodeGroups[groupId].color) || nodeDefaults?.color;\n const color = getColor(colorProp);\n\n const actsVisible = actions?.slice(0, maxVisibleActions);\n const actsDropdown = actions?.slice(maxVisibleActions);\n\n const hasParams = !!(params && params.length > 0);\n\n return (\n <HvFlowBaseNode\n id={id}\n type={type}\n title={groupLabel}\n icon={icon}\n color={color}\n inputs={inputs}\n outputs={outputs}\n nodeActions={defaultActions}\n classes={classesProp as HvFlowBaseNodeProps<unknown>[\"classes\"]}\n headerItems={\n <>\n {headerItems}\n {description && (\n <HvTooltip title={<HvTypography>{description}</HvTypography>}>\n <div>\n <Info color=\"base_dark\" />\n </div>\n </HvTooltip>\n )}\n {hasParams && (\n <HvButton\n icon\n overrideIconColors={false}\n onClick={() => setShowParams((p) => !p)}\n >\n {showParams ? (\n <Up color=\"base_dark\" />\n ) : (\n <Down color=\"base_dark\" />\n )}\n </HvButton>\n )}\n </>\n }\n {...props}\n >\n {(subtitle || actsVisible?.length || actsDropdown?.length) && (\n <div className={classes.subtitleContainer}>\n {subtitle && (\n <div>\n <HvTypography>{subtitle}</HvTypography>\n </div>\n )}\n <div className={classes.actions}>\n {actions?.length && actions?.length > 0 && (\n <>\n {actsVisible?.map((action) => (\n <HvTooltip\n key={action.id}\n title={<HvTypography>{action.label}</HvTypography>}\n >\n <div>\n <HvButton\n icon\n onClick={(event: SyntheticEvent<Element, Event>) => {\n actionCallback?.(event, id, action);\n }}\n aria-label={action.label}\n >\n {renderedIcon(action.icon)}\n </HvButton>\n </div>\n </HvTooltip>\n ))}\n\n {actsDropdown && actsDropdown.length > 0 && (\n <HvDropDownMenu\n keepOpened={false}\n dataList={actsDropdown?.map((action) => ({\n id: action.id,\n label: action.label,\n }))}\n onClick={(event, action) => {\n actionCallback?.(event, id, action as HvActionGeneric);\n }}\n />\n )}\n </>\n )}\n </div>\n </div>\n )}\n {children}\n {showParams && params && (\n <div className={classes.paramsContainer}>\n <ParamRenderer nodeId={id} params={params} data={node?.data} />\n </div>\n )}\n </HvFlowBaseNode>\n );\n};\n"],"names":["renderedIcon","actionIcon","isValidElement","HvFlowNode","id","type","headerItems","description","actions","actionCallback","maxVisibleActions","expanded","params","nodeDefaults","classes","classesProp","children","props","useClasses","showParams","setShowParams","useState","node","useFlowNode","nodeGroups","nodeTypes","defaultActions","useFlowContext","groupId","meta","subtitle","label","subTitle","groupLabel","title","inputs","outputs","icon","colorProp","color","getColor","actsVisible","slice","actsDropdown","hasParams","length","jsxs","HvFlowBaseNode","jsx","HvTooltip","HvTypography","Info","HvButton","p","Up","Down","subtitleContainer","map","action","event","HvDropDownMenu","paramsContainer","ParamRenderer","data"],"mappings":";;;;;;;;;;;;AAmDA,MAAMA,eAAeA,CAACC,eACpBC,qBAAeD,UAAU,IAAIA,aAAcA;AAEtC,MAAME,aAAaA,CAAC;AAAA,EACzBC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC,oBAAoB;AAAA,EACpBC,WAAW;AAAA,EACXC;AAAAA,EACAC;AAAAA,EACAC,SAASC;AAAAA,EACTC;AAAAA,EACA,GAAGC;AACqB,MAAM;AACxB,QAAA;AAAA,IAAEH;AAAAA,EAAAA,IAAYI,YAAAA,WAAWH,WAAiC;AAChE,QAAM,CAACI,YAAYC,aAAa,IAAIC,eAASV,QAAQ;AAC/C,QAAA;AAAA,IAAEW;AAAAA,EAAAA,IAASC,YAAAA,YAAYnB,EAAE;AAEzB,QAAA;AAAA,IAAEoB;AAAAA,IAAYC;AAAAA,IAAWC;AAAAA,MAAmBC,eAAe,eAAA;AACjE,QAAMC,UAAUH,YAAYpB,IAAI,EAAEwB,MAAMD;AACxC,QAAME,WAAWL,YAAYpB,IAAI,EAAEwB,MAAME,SAASlB,cA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C,KAAK,CAAA,GAC9D;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
@@ -9,29 +9,47 @@ const Select = ({
|
|
|
9
9
|
param,
|
|
10
10
|
data
|
|
11
11
|
}) => {
|
|
12
|
+
const {
|
|
13
|
+
id,
|
|
14
|
+
label,
|
|
15
|
+
multiple = false,
|
|
16
|
+
options
|
|
17
|
+
} = param;
|
|
12
18
|
const reactFlowInstance = ReactFlow.useReactFlow();
|
|
13
|
-
const [
|
|
19
|
+
const [opts, setOpts] = React.useState(data[id] ? Array.isArray(data[id]) ? data[id] : [data[id]] : void 0);
|
|
14
20
|
const onSelectChange = (item) => {
|
|
15
21
|
const nodes = reactFlowInstance.getNodes();
|
|
22
|
+
const newOpts = Array.isArray(item) ? item.map((x) => x.label) : item?.label ? [item.label] : void 0;
|
|
16
23
|
const newNodes = nodes.map((node) => {
|
|
17
24
|
if (node.id === nodeId) {
|
|
18
25
|
node.data = {
|
|
19
26
|
...node.data,
|
|
20
|
-
[
|
|
27
|
+
[id]: newOpts
|
|
21
28
|
};
|
|
22
29
|
}
|
|
23
30
|
return node;
|
|
24
31
|
});
|
|
25
32
|
reactFlowInstance.setNodes(newNodes);
|
|
26
|
-
|
|
33
|
+
setOpts(newOpts);
|
|
27
34
|
};
|
|
28
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
36
|
+
uikitReactCore.HvDropdown,
|
|
37
|
+
{
|
|
38
|
+
className: "nodrag",
|
|
39
|
+
disablePortal: true,
|
|
40
|
+
label,
|
|
41
|
+
values: options?.map((o) => {
|
|
42
|
+
return {
|
|
43
|
+
id: o,
|
|
44
|
+
label: o,
|
|
45
|
+
selected: !!opts?.find((opt) => opt === o)
|
|
46
|
+
};
|
|
47
|
+
}),
|
|
48
|
+
onChange: onSelectChange,
|
|
49
|
+
maxHeight: 100,
|
|
50
|
+
multiSelect: multiple
|
|
51
|
+
}
|
|
52
|
+
);
|
|
35
53
|
};
|
|
36
54
|
const Select$1 = Select;
|
|
37
55
|
exports.default = Select$1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.cjs","sources":["../../../../../../src/components/Flow/Node/Parameters/Select.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { HvDropdown } from \"@hitachivantara/uikit-react-core\";\nimport { useReactFlow } from \"reactflow\";\n\nconst Select = ({ nodeId, param, data }) => {\n const reactFlowInstance = useReactFlow();\n const [
|
|
1
|
+
{"version":3,"file":"Select.cjs","sources":["../../../../../../src/components/Flow/Node/Parameters/Select.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { HvDropdown, HvDropdownProps } from \"@hitachivantara/uikit-react-core\";\nimport { useReactFlow } from \"reactflow\";\n\nimport { HvFlowNodeSelectParam } from \"../../types\";\n\ninterface SelectProps {\n nodeId: string;\n param: Omit<HvFlowNodeSelectParam, \"type\">;\n data: any;\n}\n\nconst Select = ({ nodeId, param, data }: SelectProps) => {\n const { id, label, multiple = false, options } = param;\n\n const reactFlowInstance = useReactFlow();\n\n const [opts, setOpts] = useState<string[] | undefined>(\n data[id] ? (Array.isArray(data[id]) ? data[id] : [data[id]]) : undefined\n );\n\n const onSelectChange: HvDropdownProps[\"onChange\"] = (item) => {\n const nodes = reactFlowInstance.getNodes();\n\n const newOpts = Array.isArray(item)\n ? item.map((x) => x.label as string)\n : item?.label\n ? [item.label as string]\n : undefined;\n\n const newNodes = nodes.map((node) => {\n if (node.id === nodeId) {\n node.data = {\n ...node.data,\n [id]: newOpts,\n };\n }\n return node;\n });\n\n reactFlowInstance.setNodes(newNodes);\n setOpts(newOpts);\n };\n\n return (\n <HvDropdown\n className=\"nodrag\" // Prevents dragging within the select field\n disablePortal\n label={label}\n values={options?.map((o) => {\n return { id: o, label: o, selected: !!opts?.find((opt) => opt === o) };\n })}\n onChange={onSelectChange}\n maxHeight={100}\n multiSelect={multiple}\n />\n );\n};\n\nexport default Select;\n"],"names":["Select","nodeId","param","data","id","label","multiple","options","reactFlowInstance","useReactFlow","opts","setOpts","useState","Array","isArray","undefined","onSelectChange","item","nodes","getNodes","newOpts","map","x","newNodes","node","setNodes","jsx","HvDropdown","o","selected","find","opt"],"mappings":";;;;;;AAYA,MAAMA,SAASA,CAAC;AAAA,EAAEC;AAAAA,EAAQC;AAAAA,EAAOC;AAAkB,MAAM;AACjD,QAAA;AAAA,IAAEC;AAAAA,IAAIC;AAAAA,IAAOC,WAAW;AAAA,IAAOC;AAAAA,EAAYL,IAAAA;AAEjD,QAAMM,oBAAoBC,UAAAA;AAEpB,QAAA,CAACC,MAAMC,OAAO,IAAIC,MAAAA,SACtBT,KAAKC,EAAE,IAAKS,MAAMC,QAAQX,KAAKC,EAAE,CAAC,IAAID,KAAKC,EAAE,IAAI,CAACD,KAAKC,EAAE,CAAC,IAAKW,MACjE;AAEA,QAAMC,iBAA+CC,CAAS,SAAA;AACtDC,UAAAA,QAAQV,kBAAkBW;AAEhC,UAAMC,UAAUP,MAAMC,QAAQG,IAAI,IAC9BA,KAAKI,IAAKC,CAAAA,MAAMA,EAAEjB,KAAe,IACjCY,MAAMZ,QACN,CAACY,KAAKZ,KAAe,IACrBU;AAEEQ,UAAAA,WAAWL,MAAMG,IAAKG,CAAS,SAAA;AAC/BA,UAAAA,KAAKpB,OAAOH,QAAQ;AACtBuB,aAAKrB,OAAO;AAAA,UACV,GAAGqB,KAAKrB;AAAAA,UACR,CAACC,EAAE,GAAGgB;AAAAA,QAAAA;AAAAA,MAEV;AACOI,aAAAA;AAAAA,IAAAA,CACR;AAEDhB,sBAAkBiB,SAASF,QAAQ;AACnCZ,YAAQS,OAAO;AAAA,EAAA;AAIf,SAAAM,2BAAA;AAAA,IAACC,eAAA;AAAA,IAAA;AAAA,MACC,WAAU;AAAA,MACV,eAAa;AAAA,MACb;AAAA,MACA,QAAQpB,SAASc,IAAKO,CAAM,MAAA;AACnB,eAAA;AAAA,UAAExB,IAAIwB;AAAAA,UAAGvB,OAAOuB;AAAAA,UAAGC,UAAU,CAAC,CAACnB,MAAMoB,KAAMC,CAAAA,QAAQA,QAAQH,CAAC;AAAA,QAAA;AAAA,MAAE,CACtE;AAAA,MACD,UAAUZ;AAAAA,MACV,WAAW;AAAA,MACX,aAAaV;AAAAA,IAAAA;AAAAA,EAAAA;AAGnB;AAEA,MAAA,WAAeN;;"}
|
|
@@ -9,15 +9,19 @@ const Text = ({
|
|
|
9
9
|
param,
|
|
10
10
|
data
|
|
11
11
|
}) => {
|
|
12
|
+
const {
|
|
13
|
+
id,
|
|
14
|
+
label
|
|
15
|
+
} = param;
|
|
12
16
|
const reactFlowInstance = ReactFlow.useReactFlow();
|
|
13
|
-
const [text, setText] = React.useState(data[
|
|
14
|
-
const onTextChange = (val) => {
|
|
17
|
+
const [text, setText] = React.useState(data[id]);
|
|
18
|
+
const onTextChange = (event, val) => {
|
|
15
19
|
const nodes = reactFlowInstance.getNodes();
|
|
16
20
|
const newNodes = nodes.map((node) => {
|
|
17
21
|
if (node.id === nodeId) {
|
|
18
22
|
node.data = {
|
|
19
23
|
...node.data,
|
|
20
|
-
[
|
|
24
|
+
[id]: val
|
|
21
25
|
};
|
|
22
26
|
}
|
|
23
27
|
return node;
|
|
@@ -25,7 +29,15 @@ const Text = ({
|
|
|
25
29
|
reactFlowInstance.setNodes(newNodes);
|
|
26
30
|
setText(val);
|
|
27
31
|
};
|
|
28
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
33
|
+
uikitReactCore.HvInput,
|
|
34
|
+
{
|
|
35
|
+
className: "nodrag",
|
|
36
|
+
label,
|
|
37
|
+
value: text,
|
|
38
|
+
onChange: onTextChange
|
|
39
|
+
}
|
|
40
|
+
);
|
|
29
41
|
};
|
|
30
42
|
const Text$1 = Text;
|
|
31
43
|
exports.default = Text$1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.cjs","sources":["../../../../../../src/components/Flow/Node/Parameters/Text.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { HvInput } from \"@hitachivantara/uikit-react-core\";\nimport { useReactFlow } from \"reactflow\";\n\nconst Text = ({ nodeId, param, data }) => {\n const reactFlowInstance = useReactFlow();\n const [text, setText] = useState(data[
|
|
1
|
+
{"version":3,"file":"Text.cjs","sources":["../../../../../../src/components/Flow/Node/Parameters/Text.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { HvInput, HvInputProps } from \"@hitachivantara/uikit-react-core\";\nimport { useReactFlow } from \"reactflow\";\n\nimport { HvFlowNodeTextParam } from \"../../types\";\n\ninterface TextProps {\n nodeId: string;\n param: Omit<HvFlowNodeTextParam, \"type\">;\n data: any;\n}\n\nconst Text = ({ nodeId, param, data }: TextProps) => {\n const { id, label } = param;\n\n const reactFlowInstance = useReactFlow();\n\n const [text, setText] = useState(data[id]);\n\n const onTextChange: HvInputProps[\"onChange\"] = (event, val) => {\n const nodes = reactFlowInstance.getNodes();\n\n const newNodes = nodes.map((node) => {\n if (node.id === nodeId) {\n node.data = { ...node.data, [id]: val };\n }\n return node;\n });\n\n reactFlowInstance.setNodes(newNodes);\n setText(val);\n };\n\n return (\n <HvInput\n className=\"nodrag\" // Prevents dragging within the input field\n label={label}\n value={text}\n onChange={onTextChange}\n />\n );\n};\n\nexport default Text;\n"],"names":["Text","nodeId","param","data","id","label","reactFlowInstance","useReactFlow","text","setText","useState","onTextChange","event","val","nodes","getNodes","newNodes","map","node","setNodes","jsx","HvInput"],"mappings":";;;;;;AAYA,MAAMA,OAAOA,CAAC;AAAA,EAAEC;AAAAA,EAAQC;AAAAA,EAAOC;AAAgB,MAAM;AAC7C,QAAA;AAAA,IAAEC;AAAAA,IAAIC;AAAAA,EAAUH,IAAAA;AAEtB,QAAMI,oBAAoBC,UAAAA;AAE1B,QAAM,CAACC,MAAMC,OAAO,IAAIC,MAASP,SAAAA,KAAKC,EAAE,CAAC;AAEnCO,QAAAA,eAAyCA,CAACC,OAAOC,QAAQ;AACvDC,UAAAA,QAAQR,kBAAkBS;AAE1BC,UAAAA,WAAWF,MAAMG,IAAKC,CAAS,SAAA;AAC/BA,UAAAA,KAAKd,OAAOH,QAAQ;AACtBiB,aAAKf,OAAO;AAAA,UAAE,GAAGe,KAAKf;AAAAA,UAAM,CAACC,EAAE,GAAGS;AAAAA,QAAAA;AAAAA,MACpC;AACOK,aAAAA;AAAAA,IAAAA,CACR;AAEDZ,sBAAkBa,SAASH,QAAQ;AACnCP,YAAQI,GAAG;AAAA,EAAA;AAIX,SAAAO,2BAAA;AAAA,IAACC,eAAA;AAAA,IAAA;AAAA,MACC,WAAU;AAAA,MACV;AAAA,MACA,OAAOb;AAAAA,MACP,UAAUG;AAAAA,IAAAA;AAAAA,EAAAA;AAGhB;AAEA,MAAA,SAAeX;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const ReactFlow = require("reactflow");
|
|
4
|
-
|
|
5
|
-
const nodes = ReactFlow.
|
|
6
|
-
const edges = ReactFlow.
|
|
4
|
+
function useFlowNode(id) {
|
|
5
|
+
const nodes = ReactFlow.useNodes();
|
|
6
|
+
const edges = ReactFlow.useEdges();
|
|
7
7
|
return {
|
|
8
8
|
// self node
|
|
9
9
|
get node() {
|
|
@@ -20,6 +20,6 @@ const useFlowNode = (id) => {
|
|
|
20
20
|
return parentNodeArray;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
24
|
exports.useFlowNode = useFlowNode;
|
|
25
25
|
//# sourceMappingURL=useFlowNode.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFlowNode.cjs","sources":["../../../../../src/components/Flow/hooks/useFlowNode.ts"],"sourcesContent":["import { Edge, Node,
|
|
1
|
+
{"version":3,"file":"useFlowNode.cjs","sources":["../../../../../src/components/Flow/hooks/useFlowNode.ts"],"sourcesContent":["import { Edge, Node, useEdges, useNodes } from \"reactflow\";\n\nexport function useFlowNode<T = any>(id: string) {\n const nodes = useNodes<T>();\n const edges = useEdges();\n\n return {\n // self node\n get node() {\n const self = nodes.find((n: Node) => n.id === id);\n return self;\n },\n\n // parent nodes\n get parentNodes() {\n const connectedEdges = edges.filter((e: Edge) => e.target === id);\n const parentNodeArray = connectedEdges.map((e) => {\n const parentNode = nodes.find((n: Node) => n.id === e.source) as Node;\n return parentNode;\n });\n return parentNodeArray;\n },\n };\n}\n"],"names":["useFlowNode","id","nodes","useNodes","edges","useEdges","node","self","find","n","parentNodes","connectedEdges","filter","e","target","parentNodeArray","map","parentNode","source"],"mappings":";;;AAEO,SAASA,YAAqBC,IAAY;AAC/C,QAAMC,QAAQC,UAAAA;AACd,QAAMC,QAAQC,UAAAA;AAEP,SAAA;AAAA;AAAA,IAEL,IAAIC,OAAO;AACT,YAAMC,OAAOL,MAAMM,KAAK,CAACC,MAAYA,EAAER,OAAOA,EAAE;AACzCM,aAAAA;AAAAA,IACT;AAAA;AAAA,IAGA,IAAIG,cAAc;AAChB,YAAMC,iBAAiBP,MAAMQ,OAAO,CAACC,MAAYA,EAAEC,WAAWb,EAAE;AAC1Dc,YAAAA,kBAAkBJ,eAAeK,IAAKH,CAAM,MAAA;AAC1CI,cAAAA,aAAaf,MAAMM,KAAK,CAACC,MAAYA,EAAER,OAAOY,EAAEK,MAAM;AACrDD,eAAAA;AAAAA,MAAAA,CACR;AACMF,aAAAA;AAAAA,IACT;AAAA,EAAA;AAEJ;;"}
|
|
@@ -30,7 +30,7 @@ const validateEdge = (nodes, edges, edge, nodeMetaRegistry) => {
|
|
|
30
30
|
const targetAccepts = inputs[edge.targetHandle]?.accepts || [];
|
|
31
31
|
const sourceMaxConnections = outputs[edge.sourceHandle]?.maxConnections;
|
|
32
32
|
const targetMaxConnections = inputs[edge.targetHandle]?.maxConnections;
|
|
33
|
-
let isValid = targetAccepts.includes(sourceProvides);
|
|
33
|
+
let isValid = targetAccepts.length === 0 || targetAccepts.includes(sourceProvides);
|
|
34
34
|
if (isValid && targetMaxConnections != null) {
|
|
35
35
|
const targetConnections = edges.filter((edg) => edg.target === edge.target && edg.targetHandle === edge.targetHandle).length;
|
|
36
36
|
isValid = targetConnections < targetMaxConnections;
|
|
@@ -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 MarkerType,\n Edge,\n Node,\n} from \"reactflow\";\n\nimport { Global } from \"@emotion/react\";\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 { HvFlowNodeMetaRegistry } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./hooks\";\nimport { flowStyles } from \"./base\";\nimport { useNodeMetaRegistry } from \"./FlowContext/NodeMetaContext\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeType extends string | undefined = string | undefined,\n NodeData = any\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 /** Callback called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n /**\n * Callback called when a node is dropped in the flow.\n *\n * This callback should be used to override the custom UI Kit drop event.\n * Thus, when defined, the user is responsible for adding nodes to the flow.\n *\n * This callback is called when `HvFlowSidebar` is used or a custom sidebar was created using Dnd Kit.\n * When a custom sidebar was created using the native HTML drag and drop API, refer to the `onDrop` callback.\n *\n * Returns the event and the node to be added to the flow.\n */\n onDndDrop?: (event: DragEndEvent, node: Node) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdge = (\n nodes: Node[],\n edges: Edge[],\n edge: Edge,\n nodeMetaRegistry: HvFlowNodeMetaRegistry\n) => {\n if (!edge.sourceHandle || !edge.targetHandle) return false;\n\n const sourceNode = getNode(nodes, edge.source);\n const targetNode = getNode(nodes, edge.target);\n\n if (!sourceNode || !targetNode) return false;\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) return false;\n\n const inputs = nodeMetaRegistry[edge.target]?.inputs || [];\n const outputs = nodeMetaRegistry[edge.source]?.outputs || [];\n\n const sourceProvides = outputs[edge.sourceHandle]?.provides || \"\";\n const targetAccepts = inputs[edge.targetHandle]?.accepts || [];\n const sourceMaxConnections = outputs[edge.sourceHandle]?.maxConnections;\n const targetMaxConnections = inputs[edge.targetHandle]?.maxConnections;\n\n let isValid = targetAccepts.includes(sourceProvides);\n\n if (isValid && targetMaxConnections != null) {\n const targetConnections = edges.filter(\n (edg) =>\n edg.target === edge.target && edg.targetHandle === edge.targetHandle\n ).length;\n\n isValid = targetConnections < targetMaxConnections;\n }\n\n if (isValid && sourceMaxConnections != null) {\n const sourceConnections = edges.filter(\n (edg) =>\n edg.source === edge.source && edg.sourceHandle === edge.sourceHandle\n ).length;\n\n isValid = sourceConnections < sourceMaxConnections;\n }\n\n return isValid;\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n onDndDrop,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n defaultEdgeOptions: defaultEdgeOptionsProp,\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.data.current?.hvFlow?.type;\n\n // Only known node types can be dropped in the canvas\n if (type && nodeTypes?.[type]) {\n // Converts the coordinates to the react flow coordinate system\n const position = reactFlowInstance.project({\n x:\n (event.active.data.current?.hvFlow?.x || 0) -\n event.over.rect.left,\n y:\n (event.active.data.current?.hvFlow?.y || 0) - event.over.rect.top,\n });\n\n // Node data\n const data = event.active.data.current?.hvFlow?.data || {};\n\n // Node to add\n const newNode: Node = {\n id: uid(),\n position,\n data,\n type,\n };\n\n // Drop override\n if (onDndDrop) {\n onDndDrop(event, newNode);\n return;\n }\n\n setNodes((nds) => nds.concat(newNode));\n } else {\n // eslint-disable-next-line no-console\n console.error(\n `Could not add node to the flow because of unknown type ${type}. Use nodeTypes to define all the node types.`\n );\n }\n }\n },\n [elementId, nodeTypes, onDndDrop, reactFlowInstance]\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 { registry } = useNodeMetaRegistry();\n const isValidConnection = (connection) =>\n validateEdge(nodes, edges, connection, registry);\n\n const defaultEdgeOptions = {\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n ...defaultEdgeOptionsProp,\n };\n\n return (\n <>\n <Global styles={flowStyles} />\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 isValidConnection={isValidConnection}\n defaultEdgeOptions={defaultEdgeOptions}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n </>\n );\n};\n"],"names":["getNode","nodes","nodeId","find","n","id","validateEdge","edges","edge","nodeMetaRegistry","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","inputs","outputs","sourceProvides","provides","targetAccepts","accepts","sourceMaxConnections","maxConnections","targetMaxConnections","isValid","includes","targetConnections","filter","edg","length","sourceConnections","HvDroppableFlow","className","children","onFlowChange","onDndDrop","classes","classesProp","initialNodes","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","defaultEdgeOptions","defaultEdgeOptionsProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","nodeTypes","useFlowContext","setNodes","useState","setEdges","setNodeRef","useDroppable","handleDragEnd","useCallback","event","over","active","data","current","hvFlow","position","project","x","rect","left","y","top","newNode","uid","nds","concat","error","onDragEnd","handleFlowChange","eds","isDragging","node","dragging","handleConnect","connection","addEdge","handleNodesChange","changes","applyNodeChanges","handleEdgesChange","applyEdgeChanges","registry","useNodeMetaRegistry","isValidConnection","markerEnd","MarkerType","ArrowClosed","height","width","flowStyles","root"],"mappings":";;;;;;;;;;;;AA8DaA,MAAAA,UAAUA,CAACC,OAAeC,WAAmB;AACxD,SAAOD,MAAME,KAAMC,CAAMA,MAAAA,EAAEC,OAAOH,MAAM;AAC1C;AAEA,MAAMI,eAAeA,CACnBL,OACAM,OACAC,MACAC,qBACG;AACH,MAAI,CAACD,KAAKE,gBAAgB,CAACF,KAAKG;AAAqB,WAAA;AAErD,QAAMC,aAAaZ,QAAQC,OAAOO,KAAKK,MAAM;AAC7C,QAAMC,aAAad,QAAQC,OAAOO,KAAKO,MAAM;AAEzC,MAAA,CAACH,cAAc,CAACE;AAAmB,WAAA;AAEvC,QAAME,aAAaJ,WAAWK;AAC9B,QAAMC,aAAaJ,WAAWG;AAE1B,MAAA,CAACD,cAAc,CAACE;AAAmB,WAAA;AAEvC,QAAMC,SAASV,iBAAiBD,KAAKO,MAAM,GAAGI,UAAU;AACxD,QAAMC,UAAUX,iBAAiBD,KAAKK,MAAM,GAAGO,WAAW;AAE1D,QAAMC,iBAAiBD,QAAQZ,KAAKE,YAAY,GAAGY,YAAY;AAC/D,QAAMC,gBAAgBJ,OAAOX,KAAKG,YAAY,GAAGa,WAAW;AAC5D,QAAMC,uBAAuBL,QAAQZ,KAAKE,YAAY,GAAGgB;AACzD,QAAMC,uBAAuBR,OAAOX,KAAKG,YAAY,GAAGe;AAEpDE,MAAAA,UAAUL,cAAcM,SAASR,cAAc;AAE/CO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AAkBtF,OAAO4C,aAAa,CAChD;AAEMkD,QAAAA,oBAAoB5B,YACxB,CAAC6B,YAA0B;AACnBb,UAAAA,MAAMc,iBAAiBD,SAAS/F,KAAK;AAC3C4D,aAASsB,GAAG;AAEZI,qBAAiBJ,KAAK5E,KAAK;AAC3BwC,wBAAoBiD,OAAO;AAAA,KAE7B,CAACzF,OAAOgF,kBAAkBtF,OAAO8C,iBAAiB,CACpD;AAEMmD,QAAAA,oBAAoB/B,YACxB,CAAC6B,YAA0B;AACnBR,UAAAA,MAAMW,iBAAiBH,SAASzF,KAAK;AAC3CwD,aAASyB,GAAG;AAEZD,qBAAiBtF,OAAOuF,GAAG;AAC3BvC,wBAAoB+C,OAAO;AAAA,KAE7B,CAACzF,OAAOgF,kBAAkBtF,OAAOgD,iBAAiB,CACpD;AAEM,QAAA;AAAA,IAAEmD;AAAAA,MAAaC,oBAAoB;AACzC,QAAMC,oBAAqBT,CACzBvF,eAAAA,aAAaL,OAAOM,OAAOsF,YAAYO,QAAQ;AAEjD,QAAMlD,qBAAqB;AAAA,IACzBqD,WAAW;AAAA,MACTtF,MAAMuF,WAAWC;AAAAA,MACjBC,QAAQ;AAAA,MACRC,OAAO;AAAA,IACT;AAAA,IACA,GAAGxD;AAAAA,EAAAA;AAGL,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAC,oBAAA,QAAA,EAAO,QAAQyD,WAAW,CAAA;AAAA,IAC1B,oBAAA,OAAA,EACC,IAAIrD,WACJ,KAAKS,YACL,WAAWX,GAAGb,QAAQqE,MAAMzE,SAAS,GAErC,UAAC,oBAAA,WAAA,EACC,OACA,OACA,WACA,eAAe2D,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBACIxC,GAAAA,QAEHf,SAAAA,CACH,EACF,CAAA;AAAA,EACF,EAAA,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\";\n\nimport { Global } from \"@emotion/react\";\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 { HvFlowNodeMetaRegistry } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./hooks\";\nimport { flowStyles } from \"./base\";\nimport { useNodeMetaRegistry } from \"./FlowContext/NodeMetaContext\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeType extends string | undefined = string | undefined,\n NodeData = any\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 /** Callback called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n /**\n * Callback called when a node is dropped in the flow.\n *\n * This callback should be used to override the custom UI Kit drop event.\n * Thus, when defined, the user is responsible for adding nodes to the flow.\n *\n * This callback is called when `HvFlowSidebar` is used or a custom sidebar was created using Dnd Kit.\n * When a custom sidebar was created using the native HTML drag and drop API, refer to the `onDrop` callback.\n *\n * Returns the event and the node to be added to the flow.\n */\n onDndDrop?: (event: DragEndEvent, node: Node) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdge = (\n nodes: Node[],\n edges: Edge[],\n edge: Edge,\n nodeMetaRegistry: HvFlowNodeMetaRegistry\n) => {\n if (!edge.sourceHandle || !edge.targetHandle) return false;\n\n const sourceNode = getNode(nodes, edge.source);\n const targetNode = getNode(nodes, edge.target);\n\n if (!sourceNode || !targetNode) return false;\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) return false;\n\n const inputs = nodeMetaRegistry[edge.target]?.inputs || [];\n const outputs = nodeMetaRegistry[edge.source]?.outputs || [];\n\n const sourceProvides = outputs[edge.sourceHandle]?.provides || \"\";\n const targetAccepts = inputs[edge.targetHandle]?.accepts || [];\n const sourceMaxConnections = outputs[edge.sourceHandle]?.maxConnections;\n const targetMaxConnections = inputs[edge.targetHandle]?.maxConnections;\n\n let isValid =\n targetAccepts.length === 0 || targetAccepts.includes(sourceProvides);\n\n if (isValid && targetMaxConnections != null) {\n const targetConnections = edges.filter(\n (edg) =>\n edg.target === edge.target && edg.targetHandle === edge.targetHandle\n ).length;\n\n isValid = targetConnections < targetMaxConnections;\n }\n\n if (isValid && sourceMaxConnections != null) {\n const sourceConnections = edges.filter(\n (edg) =>\n edg.source === edge.source && edg.sourceHandle === edge.sourceHandle\n ).length;\n\n isValid = sourceConnections < sourceMaxConnections;\n }\n\n return isValid;\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n onDndDrop,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n defaultEdgeOptions: defaultEdgeOptionsProp,\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.data.current?.hvFlow?.type;\n\n // Only known node types can be dropped in the canvas\n if (type && nodeTypes?.[type]) {\n // Converts the coordinates to the react flow coordinate system\n const position = reactFlowInstance.project({\n x:\n (event.active.data.current?.hvFlow?.x || 0) -\n event.over.rect.left,\n y:\n (event.active.data.current?.hvFlow?.y || 0) - event.over.rect.top,\n });\n\n // Node data\n const data = event.active.data.current?.hvFlow?.data || {};\n\n // Node to add\n const newNode: Node = {\n id: uid(),\n position,\n data,\n type,\n };\n\n // Drop override\n if (onDndDrop) {\n onDndDrop(event, newNode);\n return;\n }\n\n setNodes((nds) => nds.concat(newNode));\n } else {\n // eslint-disable-next-line no-console\n console.error(\n `Could not add node to the flow because of unknown type ${type}. Use nodeTypes to define all the node types.`\n );\n }\n }\n },\n [elementId, nodeTypes, onDndDrop, reactFlowInstance]\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 { registry } = useNodeMetaRegistry();\n const isValidConnection = (connection) =>\n validateEdge(nodes, edges, connection, registry);\n\n const defaultEdgeOptions = {\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n ...defaultEdgeOptionsProp,\n };\n\n return (\n <>\n <Global styles={flowStyles} />\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 isValidConnection={isValidConnection}\n defaultEdgeOptions={defaultEdgeOptions}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n </>\n );\n};\n"],"names":["getNode","nodes","nodeId","find","n","id","validateEdge","edges","edge","nodeMetaRegistry","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","inputs","outputs","sourceProvides","provides","targetAccepts","accepts","sourceMaxConnections","maxConnections","targetMaxConnections","isValid","length","includes","targetConnections","filter","edg","sourceConnections","HvDroppableFlow","className","children","onFlowChange","onDndDrop","classes","classesProp","initialNodes","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","defaultEdgeOptions","defaultEdgeOptionsProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","nodeTypes","useFlowContext","setNodes","useState","setEdges","setNodeRef","useDroppable","handleDragEnd","useCallback","event","over","active","data","current","hvFlow","position","project","x","rect","left","y","top","newNode","uid","nds","concat","error","onDragEnd","handleFlowChange","eds","isDragging","node","dragging","handleConnect","connection","addEdge","handleNodesChange","changes","applyNodeChanges","handleEdgesChange","applyEdgeChanges","registry","useNodeMetaRegistry","isValidConnection","markerEnd","MarkerType","ArrowClosed","height","width","flowStyles","root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iBAAiBH,SAASzF,KAAK;AAC3CwD,aAASyB,GAAG;AAEZD,qBAAiBtF,OAAOuF,GAAG;AAC3BvC,wBAAoB+C,OAAO;AAAA,KAE7B,CAACzF,OAAOgF,kBAAkBtF,OAAOgD,iBAAiB,CACpD;AAEM,QAAA;AAAA,IAAEmD;AAAAA,MAAaC,oBAAoB;AACzC,QAAMC,oBAAqBT,CACzBvF,eAAAA,aAAaL,OAAOM,OAAOsF,YAAYO,QAAQ;AAEjD,QAAMlD,qBAAqB;AAAA,IACzBqD,WAAW;AAAA,MACTtF,MAAMuF,WAAWC;AAAAA,MACjBC,QAAQ;AAAA,MACRC,OAAO;AAAA,IACT;AAAA,IACA,GAAGxD;AAAAA,EAAAA;AAGL,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAC,oBAAA,QAAA,EAAO,QAAQyD,WAAW,CAAA;AAAA,IAC1B,oBAAA,OAAA,EACC,IAAIrD,WACJ,KAAKS,YACL,WAAWX,GAAGb,QAAQqE,MAAMzE,SAAS,GAErC,UAAC,oBAAA,WAAA,EACC,OACA,OACA,WACA,eAAe2D,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBACIxC,GAAAA,QAEHf,SAAAA,CACH,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useNodes } from "reactflow";
|
|
3
3
|
import { HvEmptyState } from "@hitachivantara/uikit-react-core";
|
|
4
4
|
import { useClasses } from "./Empty.styles.js";
|
|
5
5
|
const HvFlowEmpty = ({
|
|
@@ -10,7 +10,7 @@ const HvFlowEmpty = ({
|
|
|
10
10
|
classes,
|
|
11
11
|
cx
|
|
12
12
|
} = useClasses();
|
|
13
|
-
const nodes =
|
|
13
|
+
const nodes = useNodes();
|
|
14
14
|
return !nodes || (nodes.length === 0 ? /* @__PURE__ */ jsx(HvEmptyState, { className: cx(classes.root, className), ...others }) : null);
|
|
15
15
|
};
|
|
16
16
|
export {
|