@hitachivantara/uikit-react-lab 5.10.0 → 5.11.1
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 +49 -65
- package/dist/cjs/components/Flow/DroppableFlow.cjs.map +1 -1
- package/dist/cjs/components/Flow/Empty/Empty.cjs +19 -0
- package/dist/cjs/components/Flow/Empty/Empty.cjs.map +1 -0
- package/dist/cjs/components/Flow/Empty/Empty.styles.cjs +20 -0
- package/dist/cjs/components/Flow/Empty/Empty.styles.cjs.map +1 -0
- package/dist/cjs/components/Flow/Flow.cjs +2 -15
- package/dist/cjs/components/Flow/Flow.cjs.map +1 -1
- package/dist/cjs/components/Flow/Flow.styles.cjs +2 -2
- package/dist/cjs/components/Flow/FlowContext/FlowContext.cjs +0 -2
- package/dist/cjs/components/Flow/FlowContext/FlowContext.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/Node.cjs +6 -6
- package/dist/cjs/components/Flow/Node/Node.cjs.map +1 -1
- package/dist/cjs/components/Flow/Sidebar/Sidebar.cjs +40 -21
- package/dist/cjs/components/Flow/Sidebar/Sidebar.cjs.map +1 -1
- package/dist/cjs/components/Flow/Sidebar/SidebarGroup/SidebarGroup.cjs +3 -3
- package/dist/cjs/components/Flow/Sidebar/SidebarGroup/SidebarGroup.cjs.map +1 -1
- package/dist/cjs/components/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.cjs +12 -4
- package/dist/cjs/components/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.cjs.map +1 -1
- package/dist/cjs/components/Flow/Sidebar/utils.cjs +4 -3
- package/dist/cjs/components/Flow/Sidebar/utils.cjs.map +1 -1
- package/dist/cjs/components/Flow/base.cjs +16 -0
- package/dist/cjs/components/Flow/base.cjs.map +1 -0
- package/dist/cjs/components/Flow/hooks/useFlowContext.cjs +7 -0
- package/dist/cjs/components/Flow/hooks/useFlowContext.cjs.map +1 -0
- package/dist/cjs/components/Flow/hooks/useFlowNode.cjs +25 -0
- package/dist/cjs/components/Flow/hooks/useFlowNode.cjs.map +1 -0
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/components/Flow/DroppableFlow.js +49 -65
- package/dist/esm/components/Flow/DroppableFlow.js.map +1 -1
- package/dist/esm/components/Flow/Empty/Empty.js +19 -0
- package/dist/esm/components/Flow/Empty/Empty.js.map +1 -0
- package/dist/esm/components/Flow/Empty/Empty.styles.js +20 -0
- package/dist/esm/components/Flow/Empty/Empty.styles.js.map +1 -0
- package/dist/esm/components/Flow/Flow.js +3 -16
- package/dist/esm/components/Flow/Flow.js.map +1 -1
- package/dist/esm/components/Flow/Flow.styles.js +2 -2
- package/dist/esm/components/Flow/FlowContext/FlowContext.js +2 -4
- package/dist/esm/components/Flow/FlowContext/FlowContext.js.map +1 -1
- package/dist/esm/components/Flow/Node/Node.js +5 -5
- package/dist/esm/components/Flow/Node/Node.js.map +1 -1
- package/dist/esm/components/Flow/Sidebar/Sidebar.js +41 -22
- package/dist/esm/components/Flow/Sidebar/Sidebar.js.map +1 -1
- package/dist/esm/components/Flow/Sidebar/SidebarGroup/SidebarGroup.js +2 -2
- package/dist/esm/components/Flow/Sidebar/SidebarGroup/SidebarGroup.js.map +1 -1
- package/dist/esm/components/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.js +12 -4
- package/dist/esm/components/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.js.map +1 -1
- package/dist/esm/components/Flow/Sidebar/utils.js +4 -3
- package/dist/esm/components/Flow/Sidebar/utils.js.map +1 -1
- package/dist/esm/components/Flow/base.js +16 -0
- package/dist/esm/components/Flow/base.js.map +1 -0
- package/dist/esm/components/Flow/hooks/useFlowContext.js +7 -0
- package/dist/esm/components/Flow/hooks/useFlowContext.js.map +1 -0
- package/dist/esm/components/Flow/hooks/useFlowNode.js +25 -0
- package/dist/esm/components/Flow/hooks/useFlowNode.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +39 -16
- package/package.json +6 -6
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
import { jsx } from "@emotion/react/jsx-runtime";
|
|
1
|
+
import { jsxs, Fragment, jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { useState, useCallback } from "react";
|
|
3
3
|
import ReactFlow, { useReactFlow, addEdge, applyNodeChanges, applyEdgeChanges, MarkerType } from "reactflow";
|
|
4
|
-
import "
|
|
4
|
+
import { Global } from "@emotion/react";
|
|
5
5
|
import { useDroppable, useDndMonitor } from "@dnd-kit/core";
|
|
6
6
|
import { uid } from "uid";
|
|
7
7
|
import { useUniqueId } from "@hitachivantara/uikit-react-core";
|
|
8
8
|
import { useClasses } from "./Flow.styles.js";
|
|
9
9
|
import { staticClasses } from "./Flow.styles.js";
|
|
10
|
-
import {
|
|
10
|
+
import { flowStyles } from "./base.js";
|
|
11
|
+
import { useFlowContext } from "./hooks/useFlowContext.js";
|
|
11
12
|
const getNode = (nodes, nodeId) => {
|
|
12
13
|
return nodes.find((n) => n.id === nodeId);
|
|
13
14
|
};
|
|
15
|
+
const validateEdge = (nodes, edge, nodeTypes) => {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
if (!edge.sourceHandle || !edge.targetHandle)
|
|
18
|
+
return false;
|
|
19
|
+
const sourceNode = getNode(nodes, edge.source);
|
|
20
|
+
const targetNode = getNode(nodes, edge.target);
|
|
21
|
+
if (!sourceNode || !targetNode)
|
|
22
|
+
return false;
|
|
23
|
+
const sourceType = sourceNode.type;
|
|
24
|
+
const targetType = targetNode.type;
|
|
25
|
+
if (!sourceType || !targetType)
|
|
26
|
+
return false;
|
|
27
|
+
const inputs = ((_b = (_a = nodeTypes == null ? void 0 : nodeTypes[targetType]) == null ? void 0 : _a.meta) == null ? void 0 : _b.inputs) || [];
|
|
28
|
+
const outputs = ((_d = (_c = nodeTypes == null ? void 0 : nodeTypes[sourceType]) == null ? void 0 : _c.meta) == null ? void 0 : _d.outputs) || [];
|
|
29
|
+
const sourceProvides = ((_e = outputs[edge.sourceHandle]) == null ? void 0 : _e.provides) || "";
|
|
30
|
+
const targetAccepts = ((_f = inputs[edge.targetHandle]) == null ? void 0 : _f.accepts) || [];
|
|
31
|
+
const isValid = targetAccepts.includes(sourceProvides);
|
|
32
|
+
return isValid;
|
|
33
|
+
};
|
|
14
34
|
const validateEdges = (edges, nodes, nodeTypes) => {
|
|
15
35
|
if (edges) {
|
|
16
36
|
const validEdges = [];
|
|
17
37
|
edges.forEach((edge) => {
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
return [];
|
|
21
|
-
const sourceNode = getNode(nodes, edge.source);
|
|
22
|
-
const targetNode = getNode(nodes, edge.target);
|
|
23
|
-
if (!sourceNode || !targetNode)
|
|
24
|
-
return [];
|
|
25
|
-
const sourceType = sourceNode.type;
|
|
26
|
-
const targetType = targetNode.type;
|
|
27
|
-
if (!sourceType || !targetType)
|
|
28
|
-
return [];
|
|
29
|
-
const output = (_c = (_b = (_a = nodeTypes == null ? void 0 : nodeTypes[sourceType]) == null ? void 0 : _a.meta) == null ? void 0 : _b.outputs) == null ? void 0 : _c[edge.sourceHandle];
|
|
30
|
-
const input = (_f = (_e = (_d = nodeTypes == null ? void 0 : nodeTypes[targetType]) == null ? void 0 : _d.meta) == null ? void 0 : _e.inputs) == null ? void 0 : _f[edge.targetHandle];
|
|
31
|
-
const sourceProvides = (output == null ? void 0 : output.provides) || [];
|
|
32
|
-
const targetAccepts = (input == null ? void 0 : input.accepts) || [];
|
|
33
|
-
let isValid = false;
|
|
34
|
-
sourceProvides.forEach((s) => {
|
|
35
|
-
targetAccepts.forEach((t) => {
|
|
36
|
-
if (s === t) {
|
|
37
|
-
isValid = true;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
if (isValid) {
|
|
38
|
+
const isValidEdge = validateEdge(nodes, edge, nodeTypes);
|
|
39
|
+
if (isValidEdge) {
|
|
42
40
|
validEdges.push(edge);
|
|
43
41
|
}
|
|
44
42
|
});
|
|
@@ -77,22 +75,27 @@ const HvDroppableFlow = ({
|
|
|
77
75
|
id: elementId
|
|
78
76
|
});
|
|
79
77
|
const handleDragEnd = useCallback((event) => {
|
|
80
|
-
var _a, _b, _c, _d;
|
|
78
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
81
79
|
if (event.over && event.over.id === elementId) {
|
|
82
|
-
const type = event.active.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
const type = (_b = (_a = event.active.data.current) == null ? void 0 : _a.hvFlow) == null ? void 0 : _b.type;
|
|
81
|
+
if (type && (nodeTypes == null ? void 0 : nodeTypes[type])) {
|
|
82
|
+
const position = reactFlowInstance.project({
|
|
83
|
+
x: (((_d = (_c = event.active.data.current) == null ? void 0 : _c.hvFlow) == null ? void 0 : _d.x) || 0) - event.over.rect.left,
|
|
84
|
+
y: (((_f = (_e = event.active.data.current) == null ? void 0 : _e.hvFlow) == null ? void 0 : _f.y) || 0) - event.over.rect.top
|
|
85
|
+
});
|
|
86
|
+
const data = ((_h = (_g = event.active.data.current) == null ? void 0 : _g.hvFlow) == null ? void 0 : _h.data) || {};
|
|
87
|
+
const newNode = {
|
|
88
|
+
id: uid(),
|
|
89
|
+
position,
|
|
90
|
+
data,
|
|
91
|
+
type
|
|
92
|
+
};
|
|
93
|
+
setNodes((nds) => nds.concat(newNode));
|
|
94
|
+
} else {
|
|
95
|
+
console.error(`Could not add node to the flow because of unknown type ${type}. Use nodeTypes to define all the node types.`);
|
|
96
|
+
}
|
|
94
97
|
}
|
|
95
|
-
}, [elementId,
|
|
98
|
+
}, [elementId, nodeTypes, reactFlowInstance]);
|
|
96
99
|
useDndMonitor({
|
|
97
100
|
onDragEnd: handleDragEnd
|
|
98
101
|
});
|
|
@@ -121,29 +124,7 @@ const HvDroppableFlow = ({
|
|
|
121
124
|
onEdgesChangeProp == null ? void 0 : onEdgesChangeProp(changes);
|
|
122
125
|
}, [edges, handleFlowChange, nodes, onEdgesChangeProp]);
|
|
123
126
|
const isValidConnection = (connection) => {
|
|
124
|
-
|
|
125
|
-
const sourceNode = getNode(nodes, connection.source);
|
|
126
|
-
const targetNode = getNode(nodes, connection.target);
|
|
127
|
-
if (!sourceNode || !targetNode) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
const sourceType = sourceNode.type;
|
|
131
|
-
const targetType = targetNode.type;
|
|
132
|
-
if (!sourceType || !targetType) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
const inputs = ((_b = (_a = nodeTypes == null ? void 0 : nodeTypes[targetType]) == null ? void 0 : _a.meta) == null ? void 0 : _b.inputs) || [];
|
|
136
|
-
const outputs = ((_d = (_c = nodeTypes == null ? void 0 : nodeTypes[sourceType]) == null ? void 0 : _c.meta) == null ? void 0 : _d.outputs) || [];
|
|
137
|
-
const sourceProvides = ((_e = outputs[connection.sourceHandle]) == null ? void 0 : _e.provides) || [];
|
|
138
|
-
const targetAccepts = ((_f = inputs[connection.targetHandle]) == null ? void 0 : _f.accepts) || [];
|
|
139
|
-
let isValid = false;
|
|
140
|
-
sourceProvides.forEach((s) => {
|
|
141
|
-
targetAccepts.forEach((t) => {
|
|
142
|
-
if (s === t) {
|
|
143
|
-
isValid = true;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
});
|
|
127
|
+
const isValid = validateEdge(nodes, connection, nodeTypes);
|
|
147
128
|
return isValid;
|
|
148
129
|
};
|
|
149
130
|
const validEdges = validateEdges(edges, nodes, nodeTypes);
|
|
@@ -155,7 +136,10 @@ const HvDroppableFlow = ({
|
|
|
155
136
|
},
|
|
156
137
|
...defaultEdgeOptionsProp
|
|
157
138
|
};
|
|
158
|
-
return /* @__PURE__ */
|
|
139
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
140
|
+
/* @__PURE__ */ jsx(Global, { styles: flowStyles }),
|
|
141
|
+
/* @__PURE__ */ jsx("div", { id: elementId, ref: setNodeRef, className: cx(classes.root, className), children: /* @__PURE__ */ jsx(ReactFlow, { nodes, edges: validEdges, nodeTypes, onNodesChange: handleNodesChange, onEdgesChange: handleEdgesChange, onConnect: handleConnect, isValidConnection, defaultEdgeOptions, ...others, children }) })
|
|
142
|
+
] });
|
|
159
143
|
};
|
|
160
144
|
export {
|
|
161
145
|
HvDroppableFlow,
|
|
@@ -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\";\nimport \"reactflow/dist/style.css\";\n\nimport { DragEndEvent, useDndMonitor, useDroppable } from \"@dnd-kit/core\";\n\nimport { uid } from \"uid\";\n\nimport { ExtractNames, useUniqueId } from \"@hitachivantara/uikit-react-core\";\n\nimport { HvFlowNodeTypes } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./FlowContext\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeData = any,\n NodeType extends string | undefined = string | undefined\n> extends Omit<ReactFlowProps, \"nodes\" | \"edges\" | \"nodeTypes\"> {\n /** Flow content: background, controls, and minimap. */\n children?: React.ReactNode;\n /** Flow nodes. */\n nodes?: Node<NodeData, NodeType>[];\n /** Flow edges. */\n edges?: Edge[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowClasses;\n /** Function called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdges = (\n edges: Edge[],\n nodes: Node[],\n nodeTypes: HvFlowNodeTypes<string> | undefined\n) => {\n if (edges) {\n const validEdges: Edge[] = [];\n\n edges.forEach((edge) => {\n if (!edge.sourceHandle || !edge.targetHandle) return [];\n\n const sourceNode = getNode(nodes, edge.source);\n const targetNode = getNode(nodes, edge.target);\n\n if (!sourceNode || !targetNode) return [];\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) return [];\n\n const output =\n nodeTypes?.[sourceType]?.meta?.outputs?.[edge.sourceHandle];\n const input = nodeTypes?.[targetType]?.meta?.inputs?.[edge.targetHandle];\n\n const sourceProvides = output?.provides || [];\n const targetAccepts = input?.accepts || [];\n\n let isValid = false;\n sourceProvides.forEach((s) => {\n targetAccepts.forEach((t) => {\n if (s === t) {\n isValid = true;\n }\n });\n });\n\n if (isValid) {\n validEdges.push(edge);\n }\n });\n\n return validEdges;\n }\n return [];\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n 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.id.toString();\n\n // Converts the coordinates to the react flow coordinate system\n const position = reactFlowInstance.project({\n x: (event.active.data.current?.hvFlow?.x || 0) - event.over.rect.left,\n y: (event.active.data.current?.hvFlow?.y || 0) - event.over.rect.top,\n });\n\n const newNode: Node = {\n id: uid(),\n position,\n data: {},\n type,\n };\n\n setNodes((nds) => nds.concat(newNode));\n }\n },\n [elementId, reactFlowInstance, setNodes]\n );\n\n useDndMonitor({\n onDragEnd: handleDragEnd,\n });\n\n const handleFlowChange = useCallback(\n (\n nds: NonNullable<HvDroppableFlowProps[\"nodes\"]>,\n eds: NonNullable<HvDroppableFlowProps[\"edges\"]>\n ) => {\n // The new flow is returned if the user is not dragging nodes\n // This avoids triggering this handler too many times\n const isDragging = nds.find((node) => node.dragging);\n if (!isDragging) {\n onFlowChange?.(nds, eds);\n }\n },\n [onFlowChange]\n );\n\n const handleConnect = useCallback(\n (connection: Connection) => {\n const eds = addEdge(connection, edges);\n setEdges(eds);\n\n handleFlowChange(nodes, eds);\n onConnectProp?.(connection);\n },\n [edges, handleFlowChange, nodes, onConnectProp]\n );\n\n const handleNodesChange = useCallback(\n (changes: NodeChange[]) => {\n const nds = applyNodeChanges(changes, nodes);\n setNodes(nds);\n\n handleFlowChange(nds, edges);\n onNodesChangeProp?.(changes);\n },\n [edges, handleFlowChange, nodes, onNodesChangeProp]\n );\n\n const handleEdgesChange = useCallback(\n (changes: EdgeChange[]) => {\n const eds = applyEdgeChanges(changes, edges);\n setEdges(eds);\n\n handleFlowChange(nodes, eds);\n onEdgesChangeProp?.(changes);\n },\n [edges, handleFlowChange, nodes, onEdgesChangeProp]\n );\n\n const isValidConnection = (connection) => {\n const sourceNode = getNode(nodes, connection.source);\n const targetNode = getNode(nodes, connection.target);\n\n if (!sourceNode || !targetNode) {\n return false;\n }\n\n const sourceType = sourceNode.type;\n const targetType = targetNode.type;\n\n if (!sourceType || !targetType) {\n return false;\n }\n\n const inputs = nodeTypes?.[targetType]?.meta?.inputs || [];\n const outputs = nodeTypes?.[sourceType]?.meta?.outputs || [];\n\n const sourceProvides = outputs[connection.sourceHandle]?.provides || [];\n const targetAccepts = inputs[connection.targetHandle]?.accepts || [];\n\n let isValid = false;\n sourceProvides.forEach((s) => {\n targetAccepts.forEach((t) => {\n if (s === t) {\n isValid = true;\n }\n });\n });\n\n return isValid;\n };\n\n const validEdges = validateEdges(edges, nodes, nodeTypes);\n\n const defaultEdgeOptions = {\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n ...defaultEdgeOptionsProp,\n };\n\n return (\n <div\n id={elementId}\n ref={setNodeRef}\n className={cx(classes.root, className)}\n >\n <ReactFlow\n nodes={nodes}\n edges={validEdges}\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"],"names":["getNode","nodes","nodeId","find","n","id","validateEdges","edges","nodeTypes","validEdges","forEach","edge","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","output","meta","outputs","input","inputs","sourceProvides","provides","targetAccepts","accepts","isValid","s","t","push","HvDroppableFlow","className","children","onFlowChange","classes","classesProp","initialNodes","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","defaultEdgeOptions","defaultEdgeOptionsProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","useFlowContext","setNodes","useState","setEdges","setNodeRef","useDroppable","handleDragEnd","useCallback","event","over","active","toString","position","project","x","data","current","hvFlow","rect","left","y","top","newNode","uid","nds","concat","onDragEnd","handleFlowChange","eds","isDragging","node","dragging","handleConnect","connection","addEdge","handleNodesChange","changes","applyNodeChanges","handleEdgesChange","applyEdgeChanges","isValidConnection","markerEnd","MarkerType","Arrow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AaJ,WAAWG;AAE1B,QAAA,CAACD,cAAc,CAACE,YAAY;AACvB,aAAA;AAAA,IACT;AAEA,UAAMK,WAASjB,kDAAYY,gBAAZZ,mBAAyBc,SAAzBd,mBAA+BiB,WAAU;AACxD,UAAMF,YAAUf,kDAAYU,gBAAZV,mBAAyBc,SAAzBd,mBAA+Be,YAAW;AAE1D,UAAMG,mBAAiBH,aAAQmE,WAAW9E,YAAY,MAA/BW,mBAAkCI,aAAY;AACrE,UAAMC,kBAAgBH,YAAOiE,WAAW7E,YAAY,MAA9BY,mBAAiCI,YAAW;AAElE,QAAIC,UAAU;AACdJ,mBAAehB,QAASqB,CAAM,MAAA;AAC5BH,oBAAclB,QAASsB,CAAM,MAAA;AAC3B,YAAID,MAAMC,GAAG;AACD,oBAAA;AAAA,QACZ;AAAA,MAAA,CACD;AAAA,IAAA,CACF;AAEMF,WAAAA;AAAAA,EAAAA;AAGT,QAAMrB,aAAaH,cAAcC,OAAON,OAAOO,SAAS;AAExD,QAAMwC,qBAAqB;AAAA,IACzBkD,WAAW;AAAA,MACT/E,MAAMgF,WAAWC;AAAAA,MACjBC,QAAQ;AAAA,MACRC,OAAO;AAAA,IACT;AAAA,IACA,GAAGrD;AAAAA,EAAAA;AAGL,SACG,oBAAA,OAAA,EACC,IAAII,WACJ,KAAKQ,YACL,WAAWV,GAAGb,QAAQiE,MAAMpE,SAAS,GAErC,UAAC,oBAAA,WAAA,EACC,OACA,OAAO1B,YACP,WACA,eAAemF,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBACIvC,GAAAA,QAEHd,UACH,EACF,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"DroppableFlow.js","sources":["../../../../src/components/Flow/DroppableFlow.tsx"],"sourcesContent":["import { useCallback, useState } from \"react\";\n\nimport ReactFlow, {\n Connection,\n EdgeChange,\n NodeChange,\n ReactFlowProps,\n addEdge,\n applyEdgeChanges,\n applyNodeChanges,\n useReactFlow,\n MarkerType,\n Edge,\n Node,\n} from \"reactflow\";\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 { HvFlowNodeTypes } from \"./types\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useFlowContext } from \"./hooks\";\nimport { flowStyles } from \"./base\";\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 /** Function called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdge = (\n nodes: Node[],\n edge: Edge,\n nodeTypes: HvFlowNodeTypes<string> | undefined\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 = nodeTypes?.[targetType]?.meta?.inputs || [];\n const outputs = nodeTypes?.[sourceType]?.meta?.outputs || [];\n\n const sourceProvides = outputs[edge.sourceHandle]?.provides || \"\";\n const targetAccepts = inputs[edge.targetHandle]?.accepts || [];\n\n const isValid = targetAccepts.includes(sourceProvides);\n return isValid;\n};\n\nconst validateEdges = (\n edges: Edge[],\n nodes: Node[],\n nodeTypes: HvFlowNodeTypes<string> | undefined\n) => {\n if (edges) {\n const validEdges: Edge[] = [];\n\n edges.forEach((edge) => {\n const isValidEdge = validateEdge(nodes, edge, nodeTypes);\n if (isValidEdge) {\n validEdges.push(edge);\n }\n });\n\n return validEdges;\n }\n return [];\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n 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 const newNode: Node = {\n id: uid(),\n position,\n data,\n type,\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, 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 isValidConnection = (connection) => {\n const isValid = validateEdge(nodes, connection, nodeTypes);\n return isValid;\n };\n\n const validEdges = validateEdges(edges, nodes, nodeTypes);\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={validEdges}\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","edge","nodeTypes","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","inputs","meta","outputs","sourceProvides","provides","targetAccepts","accepts","isValid","includes","validateEdges","edges","validEdges","forEach","isValidEdge","push","HvDroppableFlow","className","children","onFlowChange","classes","classesProp","initialNodes","initialEdges","onConnect","onConnectProp","onNodesChange","onNodesChangeProp","onEdgesChange","onEdgesChangeProp","defaultEdgeOptions","defaultEdgeOptionsProp","others","cx","useClasses","elementId","useUniqueId","reactFlowInstance","useReactFlow","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","isValidConnection","markerEnd","MarkerType","ArrowClosed","height","width","flowStyles","root"],"mappings":";;;;;;;;;;;AAiDaA,MAAAA,UAAUA,CAACC,OAAeC,WAAmB;AACxD,SAAOD,MAAME,KAAMC,CAAMA,MAAAA,EAAEC,OAAOH,MAAM;AAC1C;AAEA,MAAMI,eAAeA,CACnBL,OACAM,MACAC,cACG;;AACH,MAAI,CAACD,KAAKE,gBAAgB,CAACF,KAAKG;AAAqB,WAAA;AAErD,QAAMC,aAAaX,QAAQC,OAAOM,KAAKK,MAAM;AAC7C,QAAMC,aAAab,QAAQC,OAAOM,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,WAASV,kDAAYS,gBAAZT,mBAAyBW,SAAzBX,mBAA+BU,WAAU;AACxD,QAAME,YAAUZ,kDAAYO,gBAAZP,mBAAyBW,SAAzBX,mBAA+BY,YAAW;AAE1D,QAAMC,mBAAiBD,aAAQb,KAAKE,YAAY,MAAzBW,mBAA4BE,aAAY;AAC/D,QA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"@emotion/react/jsx-runtime";
|
|
2
|
+
import { useStore } from "reactflow";
|
|
3
|
+
import { HvEmptyState } from "@hitachivantara/uikit-react-core";
|
|
4
|
+
import { useClasses } from "./Empty.styles.js";
|
|
5
|
+
const HvFlowEmpty = ({
|
|
6
|
+
className,
|
|
7
|
+
...others
|
|
8
|
+
}) => {
|
|
9
|
+
const {
|
|
10
|
+
classes,
|
|
11
|
+
cx
|
|
12
|
+
} = useClasses();
|
|
13
|
+
const nodes = useStore((state) => state.getNodes());
|
|
14
|
+
return !nodes || (nodes.length === 0 ? /* @__PURE__ */ jsx(HvEmptyState, { className: cx(classes.root, className), ...others }) : null);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
HvFlowEmpty
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=Empty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Empty.js","sources":["../../../../../src/components/Flow/Empty/Empty.tsx"],"sourcesContent":["import { useStore } from \"reactflow\";\nimport {\n HvEmptyState,\n HvEmptyStateProps,\n} from \"@hitachivantara/uikit-react-core\";\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 = useStore((state) => state.getNodes());\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","useStore","state","getNodes","length","root"],"mappings":";;;;AASO,MAAMA,cAAcA,CAAC;AAAA,EAAEC;AAAAA,EAAW,GAAGC;AAAyB,MAAM;AACnE,QAAA;AAAA,IAAEC;AAAAA,IAASC;AAAAA,MAAOC,WAAW;AACnC,QAAMC,QAAQC,SAAUC,CAAUA,UAAAA,MAAMC,UAAU;AAClD,SACE,CAACH,UACAA,MAAMI,WAAW,IACf,oBAAA,cAAA,EAAa,WAAWN,GAAGD,QAAQQ,MAAMV,SAAS,GAAG,GAAIC,OAAU,CAAA,IAClE;AAER;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createClasses, theme } from "@hitachivantara/uikit-react-core";
|
|
2
|
+
const {
|
|
3
|
+
staticClasses,
|
|
4
|
+
useClasses
|
|
5
|
+
} = createClasses("HvFlowEmpty", {
|
|
6
|
+
root: {
|
|
7
|
+
width: "100%",
|
|
8
|
+
height: "100%",
|
|
9
|
+
alignItems: "center",
|
|
10
|
+
justifyContent: "center",
|
|
11
|
+
backgroundColor: theme.colors.backgroundColor,
|
|
12
|
+
position: "absolute",
|
|
13
|
+
zIndex: theme.zIndices.popover
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export {
|
|
17
|
+
staticClasses,
|
|
18
|
+
useClasses
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=Empty.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Empty.styles.js","sources":["../../../../../src/components/Flow/Empty/Empty.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFlowEmpty\", {\n root: {\n width: \"100%\",\n height: \"100%\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: theme.colors.backgroundColor,\n position: \"absolute\",\n zIndex: theme.zIndices.popover,\n },\n});\n"],"names":["staticClasses","useClasses","createClasses","root","width","height","alignItems","justifyContent","backgroundColor","theme","colors","position","zIndex","zIndices","popover"],"mappings":";AAEa,MAAA;AAAA,EAAEA;AAAAA,EAAeC;AAAW,IAAIC,cAAc,eAAe;AAAA,EACxEC,MAAM;AAAA,IACJC,OAAO;AAAA,IACPC,QAAQ;AAAA,IACRC,YAAY;AAAA,IACZC,gBAAgB;AAAA,IAChBC,iBAAiBC,MAAMC,OAAOF;AAAAA,IAC9BG,UAAU;AAAA,IACVC,QAAQH,MAAMI,SAASC;AAAAA,EACzB;AACF,CAAC;"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, DragOverlay } from "@dnd-kit/core";
|
|
2
|
+
import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext } from "@dnd-kit/core";
|
|
4
3
|
import { restrictToWindowEdges } from "@dnd-kit/modifiers";
|
|
5
4
|
import { ReactFlowProvider } from "reactflow";
|
|
6
5
|
import { HvDroppableFlow } from "./DroppableFlow.js";
|
|
7
6
|
import { HvFlowProvider } from "./FlowContext/FlowContext.js";
|
|
8
|
-
import { HvFlowSidebarGroupItem } from "./Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.js";
|
|
9
7
|
const HvFlow = ({
|
|
10
8
|
nodeTypes,
|
|
11
9
|
nodeGroups,
|
|
@@ -14,21 +12,10 @@ const HvFlow = ({
|
|
|
14
12
|
dndContextProps,
|
|
15
13
|
...others
|
|
16
14
|
}) => {
|
|
17
|
-
const [draggingLabel, setDraggingLabel] = useState(void 0);
|
|
18
15
|
const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor));
|
|
19
|
-
|
|
20
|
-
var _a, _b;
|
|
21
|
-
if ((_a = event.active.data.current) == null ? void 0 : _a.hvFlow) {
|
|
22
|
-
setDraggingLabel((_b = event.active.data.current.hvFlow) == null ? void 0 : _b.label);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const handleDragEnd = () => {
|
|
26
|
-
setDraggingLabel(void 0);
|
|
27
|
-
};
|
|
28
|
-
return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(HvFlowProvider, { nodeGroups, nodeTypes, defaultActions, children: /* @__PURE__ */ jsxs(DndContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd, sensors, modifiers: [restrictToWindowEdges], ...dndContextProps, children: [
|
|
16
|
+
return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(HvFlowProvider, { nodeGroups, nodeTypes, defaultActions, children: /* @__PURE__ */ jsxs(DndContext, { sensors, modifiers: [restrictToWindowEdges], ...dndContextProps, children: [
|
|
29
17
|
/* @__PURE__ */ jsx(HvDroppableFlow, { ...others }),
|
|
30
|
-
sidebar
|
|
31
|
-
/* @__PURE__ */ jsx(DragOverlay, { modifiers: [restrictToWindowEdges], children: draggingLabel ? /* @__PURE__ */ jsx(HvFlowSidebarGroupItem, { label: draggingLabel, isDragging: true }) : null })
|
|
18
|
+
sidebar
|
|
32
19
|
] }) }) });
|
|
33
20
|
};
|
|
34
21
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flow.js","sources":["../../../../src/components/Flow/Flow.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Flow.js","sources":["../../../../src/components/Flow/Flow.tsx"],"sourcesContent":["import {\n DndContext,\n DndContextProps,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors,\n} from \"@dnd-kit/core\";\nimport { restrictToWindowEdges } from \"@dnd-kit/modifiers\";\n\nimport { ReactFlowProvider } from \"reactflow\";\n\nimport {\n HvFlowDefaultActions,\n HvFlowNodeGroups,\n HvFlowNodeTypes,\n} from \"./types\";\nimport { HvFlowProvider } from \"./FlowContext\";\nimport { HvDroppableFlow, HvDroppableFlowProps } from \"./DroppableFlow\";\n\nexport interface HvFlowProps<\n NodeGroups extends keyof any = string,\n NodeType extends string | undefined = string | undefined,\n NodeData = any\n> extends HvDroppableFlowProps<NodeType, NodeData> {\n /** Flow nodes groups. */\n nodeGroups?: HvFlowNodeGroups<NodeGroups>;\n /** Flow nodes types. */\n nodeTypes?: HvFlowNodeTypes<NodeGroups, NodeData>;\n /** Flow sidebar. */\n sidebar?: React.ReactNode;\n /** Flow default actions. */\n defaultActions?: HvFlowDefaultActions[];\n /**\n * Dnd Kit context props. This should be used for accessibility purposes.\n *\n * More information can be found on the [Dnd Kit documentation](https://docs.dndkit.com/guides/accessibility)\n */\n dndContextProps?: Pick<DndContextProps, \"accessibility\">;\n}\n\n/**\n * Flow component to build interactive node-based UIs.\n *\n * This implementation leverages [React Flow](https://reactflow.dev).\n * The drag and drop functionality leverages [Dnd Kit](https://docs.dndkit.com)\n *\n * DISCLAIMER: This component is a work in progress and there might be breaking changes.\n */\nexport const HvFlow = ({\n nodeTypes,\n nodeGroups,\n sidebar,\n defaultActions,\n dndContextProps,\n ...others\n}: HvFlowProps) => {\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor)\n );\n\n // We're wrapping the main Flow component with the ReactFlowProvider to access the react flow instance.\n // HvFlowContext is our custom internal context.\n return (\n <ReactFlowProvider>\n <HvFlowProvider\n nodeGroups={nodeGroups}\n nodeTypes={nodeTypes}\n defaultActions={defaultActions}\n >\n <DndContext\n sensors={sensors}\n modifiers={[restrictToWindowEdges]}\n {...dndContextProps}\n >\n <HvDroppableFlow {...others} />\n {sidebar}\n </DndContext>\n </HvFlowProvider>\n </ReactFlowProvider>\n );\n};\n"],"names":["HvFlow","nodeTypes","nodeGroups","sidebar","defaultActions","dndContextProps","others","sensors","useSensors","useSensor","PointerSensor","KeyboardSensor","restrictToWindowEdges"],"mappings":";;;;;;AAiDO,MAAMA,SAASA,CAAC;AAAA,EACrBC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACA,GAAGC;AACQ,MAAM;AACjB,QAAMC,UAAUC,WACdC,UAAUC,aAAa,GACvBD,UAAUE,cAAc,CAC1B;AAIA,SACG,oBAAA,mBAAA,EACC,UAAC,oBAAA,gBAAA,EACC,YACA,WACA,gBAEA,UAAC,qBAAA,YAAA,EACC,SACA,WAAW,CAACC,qBAAqB,GACjC,GAAIP,iBAEJ,UAAA;AAAA,IAAC,oBAAA,iBAAA,EAAgB,GAAIC,QAAO;AAAA,IAC3BH;AAAAA,EAAAA,GACH,GACF,EACF,CAAA;AAEJ;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createClasses, theme } from "@hitachivantara/uikit-react-core";
|
|
2
2
|
import { staticClasses as staticClasses$1 } from "./Node/Node.styles.js";
|
|
3
3
|
import "@emotion/react/jsx-runtime";
|
|
4
|
-
import "@hitachivantara/uikit-react-icons";
|
|
5
|
-
import "@hitachivantara/uikit-styles";
|
|
6
4
|
import "react";
|
|
7
5
|
import "reactflow";
|
|
6
|
+
import "@hitachivantara/uikit-react-icons";
|
|
7
|
+
import "@hitachivantara/uikit-styles";
|
|
8
8
|
const {
|
|
9
9
|
staticClasses,
|
|
10
10
|
useClasses
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { createContext, useState, useMemo
|
|
2
|
+
import { createContext, useState, useMemo } from "react";
|
|
3
3
|
const HvFlowContext = createContext({});
|
|
4
4
|
const HvFlowProvider = ({
|
|
5
5
|
nodeGroups,
|
|
@@ -17,10 +17,8 @@ const HvFlowProvider = ({
|
|
|
17
17
|
}), [nodeTypes, nodeGroups, defaultActions, expandedNodeGroups]);
|
|
18
18
|
return /* @__PURE__ */ jsx(HvFlowContext.Provider, { value, children });
|
|
19
19
|
};
|
|
20
|
-
const useFlowContext = () => useContext(HvFlowContext);
|
|
21
20
|
export {
|
|
22
21
|
HvFlowContext,
|
|
23
|
-
HvFlowProvider
|
|
24
|
-
useFlowContext
|
|
22
|
+
HvFlowProvider
|
|
25
23
|
};
|
|
26
24
|
//# sourceMappingURL=FlowContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowContext.js","sources":["../../../../../src/components/Flow/FlowContext/FlowContext.tsx"],"sourcesContent":["import {\n Dispatch,\n SetStateAction,\n createContext,\n
|
|
1
|
+
{"version":3,"file":"FlowContext.js","sources":["../../../../../src/components/Flow/FlowContext/FlowContext.tsx"],"sourcesContent":["import {\n Dispatch,\n SetStateAction,\n createContext,\n useMemo,\n useState,\n} from \"react\";\n\nimport {\n HvFlowDefaultActions,\n HvFlowNodeGroups,\n HvFlowNodeTypes,\n} from \"../types\";\n\nexport interface HvFlowContextValue<NodeGroups extends keyof any = string> {\n /** Flow nodes types. */\n nodeTypes?: HvFlowNodeTypes<NodeGroups>;\n /** Flow nodes groups. */\n nodeGroups?: HvFlowNodeGroups<NodeGroups>;\n /** Flow nodes groups expanded on sidebar. */\n expandedNodeGroups?: string[];\n /** Flow default actions. */\n defaultActions?: HvFlowDefaultActions[];\n /** Function to set `expandedNodeGroups`. */\n setExpandedNodeGroups?: Dispatch<SetStateAction<string[]>>;\n}\n\nexport const HvFlowContext = createContext<HvFlowContextValue>({});\n\nexport interface HvFlowProviderProps<NodeGroups extends keyof any = string> {\n /** Flow nodes types. */\n nodeTypes?: HvFlowContextValue<NodeGroups>[\"nodeTypes\"];\n /** Flow nodes groups. */\n nodeGroups?: HvFlowContextValue<NodeGroups>[\"nodeGroups\"];\n /** Flow default actions. */\n defaultActions?: HvFlowDefaultActions[];\n /** Children. */\n children?: React.ReactNode;\n}\n\nexport const HvFlowProvider = ({\n nodeGroups,\n nodeTypes,\n defaultActions,\n children,\n}: HvFlowProviderProps) => {\n const [expandedNodeGroups, setExpandedNodeGroups] = useState<string[]>([]);\n\n const value = useMemo(\n () => ({\n nodeTypes,\n nodeGroups,\n defaultActions,\n expandedNodeGroups,\n setExpandedNodeGroups,\n }),\n [nodeTypes, nodeGroups, defaultActions, expandedNodeGroups]\n );\n\n return (\n <HvFlowContext.Provider value={value}>{children}</HvFlowContext.Provider>\n );\n};\n"],"names":["HvFlowContext","createContext","HvFlowProvider","nodeGroups","nodeTypes","defaultActions","children","expandedNodeGroups","setExpandedNodeGroups","useState","value","useMemo"],"mappings":";;AA2BaA,MAAAA,gBAAgBC,cAAkC,EAAE;AAa1D,MAAMC,iBAAiBA,CAAC;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AACmB,MAAM;AACzB,QAAM,CAACC,oBAAoBC,qBAAqB,IAAIC,SAAmB,CAAE,CAAA;AAEnEC,QAAAA,QAAQC,QACZ,OAAO;AAAA,IACLP;AAAAA,IACAD;AAAAA,IACAE;AAAAA,IACAE;AAAAA,IACAC;AAAAA,EAAAA,IAEF,CAACJ,WAAWD,YAAYE,gBAAgBE,kBAAkB,CAC5D;AAEA,SACG,oBAAA,cAAc,UAAd,EAAuB,OAAeD,SAAS,CAAA;AAEpD;"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useCallback, isValidElement } from "react";
|
|
3
|
+
import { useReactFlow, useStore, NodeToolbar, Handle, Position } from "reactflow";
|
|
2
4
|
import { HvButton, HvTypography, HvTooltip, HvDropDownMenu } from "@hitachivantara/uikit-react-core";
|
|
3
5
|
import { Info, Up, Down } from "@hitachivantara/uikit-react-icons";
|
|
4
6
|
import { getColor, theme } from "@hitachivantara/uikit-styles";
|
|
5
|
-
import { useState, useEffect, useCallback, isValidElement } from "react";
|
|
6
|
-
import { useReactFlow, useStore, NodeToolbar, Handle, Position } from "reactflow";
|
|
7
|
-
import { useFlowContext } from "../FlowContext/FlowContext.js";
|
|
8
7
|
import { useClasses } from "./Node.styles.js";
|
|
9
8
|
import { staticClasses } from "./Node.styles.js";
|
|
10
9
|
import ParamRenderer from "./Parameters/ParamRenderer.js";
|
|
10
|
+
import { useFlowContext } from "../hooks/useFlowContext.js";
|
|
11
11
|
const isInputConnected = (id, type, idx, edges) => {
|
|
12
12
|
if (type === "target") {
|
|
13
13
|
return edges.some((e) => e.target === id && e.targetHandle === idx.toString());
|
|
@@ -99,7 +99,7 @@ const HvFlowNode = ({
|
|
|
99
99
|
return /* @__PURE__ */ jsxs("div", { className: cx(css({
|
|
100
100
|
border: `1px solid ${color}`
|
|
101
101
|
}), classes.root, className), onMouseEnter: () => setShowActions(true), onMouseLeave: () => setShowActions(false), children: [
|
|
102
|
-
/* @__PURE__ */ jsx(NodeToolbar, { isVisible: showActions, offset: 0, children: defaultActions == null ? void 0 : defaultActions.map((action) => /* @__PURE__ */ jsx(HvButton, { icon: true, onClick: () => handleDefaultAction(action.id), children: renderedIcon(action.icon) })) }),
|
|
102
|
+
/* @__PURE__ */ jsx(NodeToolbar, { isVisible: showActions, offset: 0, children: defaultActions == null ? void 0 : defaultActions.map((action) => /* @__PURE__ */ jsx(HvButton, { icon: true, onClick: () => handleDefaultAction(action.id), children: renderedIcon(action.icon) }, action.id)) }),
|
|
103
103
|
/* @__PURE__ */ jsxs("div", { className: cx(css({
|
|
104
104
|
backgroundColor: color
|
|
105
105
|
}), classes.headerContainer), children: [
|
|
@@ -119,7 +119,7 @@ const HvFlowNode = ({
|
|
|
119
119
|
/* @__PURE__ */ jsx("div", { className: classes.actions, children: (actions == null ? void 0 : actions.length) && (actions == null ? void 0 : actions.length) > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
120
120
|
actsVisible == null ? void 0 : actsVisible.map((action) => /* @__PURE__ */ jsx(HvTooltip, { title: /* @__PURE__ */ jsx(HvTypography, { children: action.label }), children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(HvButton, { icon: true, onClick: (event) => {
|
|
121
121
|
actionCallback == null ? void 0 : actionCallback(event, node.id, action);
|
|
122
|
-
}, "aria-label": action.label, children: renderedIcon(action.icon) }) }) })),
|
|
122
|
+
}, "aria-label": action.label, children: renderedIcon(action.icon) }) }) }, action.id)),
|
|
123
123
|
actsDropdown && actsDropdown.length > 0 && /* @__PURE__ */ jsx(HvDropDownMenu, { keepOpened: false, dataList: actsDropdown == null ? void 0 : actsDropdown.map((action) => ({
|
|
124
124
|
id: action.id,
|
|
125
125
|
label: action.label
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.js","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvBaseProps,\n HvButton,\n HvDropDownMenu,\n HvTooltip,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Down, Info, Up } from \"@hitachivantara/uikit-react-icons\";\nimport { getColor, theme } from \"@hitachivantara/uikit-styles\";\nimport { isValidElement, useCallback, useEffect, useState } from \"react\";\nimport {\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useReactFlow,\n useStore,\n} from \"reactflow\";\nimport { useFlowContext } from \"../FlowContext/FlowContext\";\n\nimport {\n HvFlowDefaultAction,\n HvFlowNodeInput,\n HvFlowNodeOutput,\n HvFlowNodeParam,\n} from \"../types\";\nimport { staticClasses, useClasses } from \"./Node.styles\";\nimport ParamRenderer from \"./Parameters/ParamRenderer\";\n\nexport { staticClasses as flowNodeClasses };\n\nexport type HvFlowNodeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFlowNodeProps extends Omit<HvBaseProps, \"id\">, NodeProps {\n /** Node description */\n description: string;\n /** Node expanded */\n expanded?: boolean;\n /** Node inputs */\n inputs?: HvFlowNodeInput[];\n /** Node outputs */\n outputs?: HvFlowNodeOutput[];\n /** Node parameters */\n params?: HvFlowNodeParam[];\n /** 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 /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowNodeClasses;\n}\n\nconst isInputConnected = (id, type, idx, edges) => {\n if (type === \"target\") {\n return edges.some(\n (e) => e.target === id && e.targetHandle === idx.toString()\n );\n }\n if (type === \"source\") {\n return edges.some(\n (e) => e.source === id && e.sourceHandle === idx.toString()\n );\n }\n};\n\nexport const HvFlowNode = ({\n id,\n type,\n description,\n expanded = false,\n params,\n actions,\n actionCallback,\n maxVisibleActions = 1,\n classes: classesProp,\n className,\n children,\n}: HvFlowNodeProps) => {\n const [showParams, setShowParams] = useState(expanded);\n const [showActions, setShowActions] = useState(false);\n const reactFlowInstance = useReactFlow();\n\n const { classes, cx, css } = useClasses(classesProp);\n\n const { nodeGroups, nodeTypes, defaultActions } = useFlowContext();\n const edges = useStore((s) => s.edges);\n const nodes = useStore((s) => s.getNodes());\n\n const node = nodes.find((n) => n.id === id);\n\n const groupId = nodeTypes?.[type].meta?.groupId;\n const title = nodeTypes?.[type].meta?.label;\n const groupLabel = groupId && nodeGroups && nodeGroups[groupId].label;\n\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon = groupId && nodeGroups && nodeGroups[groupId].icon;\n const colorProp = groupId && nodeGroups && nodeGroups[groupId].color;\n const color = getColor(colorProp);\n\n useEffect(() => {\n const newNodes = nodes.map((n) => {\n if (n.id === id) {\n if (Object.keys(n.data).length === 0) {\n params?.forEach((param) => {\n n.data[param.id] = param.value;\n });\n }\n }\n return n;\n });\n reactFlowInstance.setNodes(newNodes);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleDefaultAction = useCallback(\n (action: HvFlowDefaultAction) => {\n if (!node) return;\n\n switch (action) {\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 const hasParams = !!(params && params.length > 0);\n\n if (!node) return null;\n\n const actsVisible = actions?.slice(0, maxVisibleActions);\n const actsDropdown = actions?.slice(maxVisibleActions);\n\n const renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\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 {defaultActions?.map((action) => (\n <HvButton icon onClick={() => handleDefaultAction(action.id)}>\n {renderedIcon(action.icon)}\n </HvButton>\n ))}\n </NodeToolbar>\n <div\n className={cx(css({ backgroundColor: color }), classes.headerContainer)}\n >\n <div className={classes.groupContainer}>\n {icon}\n <HvTypography variant=\"title4\" className={classes.group}>\n {groupLabel}\n </HvTypography>\n </div>\n <div style={{ display: \"flex\" }}>\n <HvTooltip title={<HvTypography>{description}</HvTypography>}>\n <div>\n <Info />\n </div>\n </HvTooltip>\n <HvButton\n icon\n disabled={!hasParams}\n onClick={() => setShowParams((p) => !p)}\n >\n {showParams ? <Up /> : <Down />}\n </HvButton>\n </div>\n </div>\n <div className={classes.titleContainer}>\n <div>\n <HvTypography>{title}</HvTypography>\n </div>\n <div className={classes.actions}>\n {actions?.length && actions?.length > 0 && (\n <>\n {actsVisible?.map((action) => (\n <HvTooltip title={<HvTypography>{action.label}</HvTypography>}>\n <div>\n <HvButton\n icon\n onClick={(event) => {\n actionCallback?.(event, node.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, node.id, action as HvActionGeneric);\n }}\n />\n )}\n </>\n )}\n </div>\n </div>\n {children && <div className={classes.contentContainer}>{children}</div>}\n {showParams && params && (\n <div className={classes.paramsContainer}>\n <ParamRenderer nodeId={id} params={params} data={node?.data} />\n </div>\n )}\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","HvFlowNode","description","expanded","params","actions","actionCallback","maxVisibleActions","classes","classesProp","className","children","showParams","setShowParams","useState","showActions","setShowActions","reactFlowInstance","useReactFlow","cx","css","useClasses","nodeGroups","nodeTypes","defaultActions","useFlowContext","useStore","s","nodes","getNodes","node","find","n","groupId","meta","title","label","groupLabel","inputs","outputs","icon","colorProp","color","getColor","useEffect","newNodes","map","Object","keys","data","length","forEach","param","value","setNodes","handleDefaultAction","useCallback","action","deleteElements","addNodes","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","hasParams","actsVisible","slice","actsDropdown","renderedIcon","actionIcon","isValidElement","border","root","backgroundColor","headerContainer","groupContainer","group","display","p","titleContainer","event","contentContainer","paramsContainer","inputsTitleContainer","inputsContainer","input","inputContainer","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;AAyDA,MAAMA,mBAAmBA,CAACC,IAAIC,MAAMC,KAAKC,UAAU;AACjD,MAAIF,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEC,WAAWN,MAAMK,EAAEE,iBAAiBL,IAAIM,SACnD,CAAA;AAAA,EACF;AACA,MAAIP,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEI,WAAWT,MAAMK,EAAEK,iBAAiBR,IAAIM,SACnD,CAAA;AAAA,EACF;AACF;AAEO,MAAMG,aAAaA,CAAC;AAAA,EACzBX;AAAAA,EACAC;AAAAA,EACAW;AAAAA,EACAC,WAAW;AAAA,EACXC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC,oBAAoB;AAAA,EACpBC,SAASC;AAAAA,EACTC;AAAAA,EACAC;AACe,MAAM;;AACrB,QAAM,CAACC,YAAYC,aAAa,IAAIC,SAASX,QAAQ;AACrD,QAAM,CAACY,aAAaC,cAAc,IAAIF,SAAS,KAAK;AACpD,QAAMG,oBAAoBC;AAEpB,QAAA;AAAA,IAAEV;AAAAA,IAASW;AAAAA,IAAIC;AAAAA,EAAAA,IAAQC,WAAWZ,WAAW;AAE7C,QAAA;AAAA,IAAEa;AAAAA,IAAYC;AAAAA,IAAWC;AAAAA,MAAmBC,eAAe;AACjE,QAAMhC,QAAQiC,SAAUC,CAAMA,MAAAA,EAAElC,KAAK;AACrC,QAAMmC,QAAQF,SAAUC,CAAMA,MAAAA,EAAEE,UAAU;AAE1C,QAAMC,OAAOF,MAAMG,KAAMC,CAAMA,MAAAA,EAAE1C,OAAOA,EAAE;AAE1C,QAAM2C,WAAUV,4CAAYhC,MAAM2C,SAAlBX,mBAAwBU;AACxC,QAAME,SAAQZ,4CAAYhC,MAAM2C,SAAlBX,mBAAwBa;AACtC,QAAMC,a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AAWgB,QAAQ8F,iBACtB,UAAA;AAAA,QAAA,oBAAC,QACC,EAAA,MAAK,UACL,kBAAkB,OAClB,IAAK,GAAE9G,GAAI,IACX,UAAUqG,SAASU,OACnB,OAAO;AAAA,UACLP,QAAQ,MAAM,MAAMzD,QAAQW,SAAS1D;AAAAA,UACrCuG,KAAK;AAAA,QAAA,GACL;AAAA,QAEHM,OAAOJ,eACN,CAAC5G,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxC,oBAAC,OAAI,EAAA,WAAWe,QAAQ0F,UACzB,CAAA;AAAA,QACH,oBAAC,cAAcG,EAAAA,UAAAA,OAAOjE,MAAM,CAAA;AAAA,MAAA,KAfgB5C,GAgB9C,IAEJ;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Node.js","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\n\nimport {\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useReactFlow,\n useStore,\n} from \"reactflow\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvBaseProps,\n HvButton,\n HvDropDownMenu,\n HvTooltip,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Down, Info, Up } from \"@hitachivantara/uikit-react-icons\";\nimport { getColor, theme } from \"@hitachivantara/uikit-styles\";\n\nimport { useFlowContext } from \"../hooks\";\nimport { HvFlowDefaultAction, HvFlowNodeParam } from \"../types\";\nimport { staticClasses, useClasses } from \"./Node.styles\";\nimport ParamRenderer from \"./Parameters/ParamRenderer\";\n\nexport { staticClasses as flowNodeClasses };\n\nexport type HvFlowNodeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFlowNodeProps extends Omit<HvBaseProps, \"id\">, NodeProps {\n /** Node description */\n description: string;\n /** Node expanded */\n expanded?: boolean;\n /** Node parameters */\n params?: HvFlowNodeParam[];\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 /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowNodeClasses;\n}\n\nconst isInputConnected = (id, type, idx, edges) => {\n if (type === \"target\") {\n return edges.some(\n (e) => e.target === id && e.targetHandle === idx.toString()\n );\n }\n if (type === \"source\") {\n return edges.some(\n (e) => e.source === id && e.sourceHandle === idx.toString()\n );\n }\n};\n\nexport const HvFlowNode = ({\n id,\n type,\n description,\n expanded = false,\n params,\n actions,\n actionCallback,\n maxVisibleActions = 1,\n classes: classesProp,\n className,\n children,\n}: HvFlowNodeProps) => {\n const [showParams, setShowParams] = useState(expanded);\n const [showActions, setShowActions] = useState(false);\n const reactFlowInstance = useReactFlow();\n\n const { classes, cx, css } = useClasses(classesProp);\n\n const { nodeGroups, nodeTypes, defaultActions } = useFlowContext();\n const edges = useStore((s) => s.edges);\n const nodes = useStore((s) => s.getNodes());\n\n const node = nodes.find((n) => n.id === id);\n\n const groupId = nodeTypes?.[type].meta?.groupId;\n const title = nodeTypes?.[type].meta?.label;\n const groupLabel = groupId && nodeGroups && nodeGroups[groupId].label;\n\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon = groupId && nodeGroups && nodeGroups[groupId].icon;\n const colorProp = groupId && nodeGroups && nodeGroups[groupId].color;\n const color = getColor(colorProp);\n\n useEffect(() => {\n const newNodes = nodes.map((n) => {\n if (n.id === id) {\n if (Object.keys(n.data).length === 0) {\n params?.forEach((param) => {\n n.data[param.id] = param.value;\n });\n }\n }\n return n;\n });\n reactFlowInstance.setNodes(newNodes);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleDefaultAction = useCallback(\n (action: HvFlowDefaultAction) => {\n if (!node) return;\n\n switch (action) {\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 const hasParams = !!(params && params.length > 0);\n\n if (!node) return null;\n\n const actsVisible = actions?.slice(0, maxVisibleActions);\n const actsDropdown = actions?.slice(maxVisibleActions);\n\n const renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\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 {defaultActions?.map((action) => (\n <HvButton\n key={action.id}\n icon\n onClick={() => handleDefaultAction(action.id)}\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.groupContainer}>\n {icon}\n <HvTypography variant=\"title4\" className={classes.group}>\n {groupLabel}\n </HvTypography>\n </div>\n <div style={{ display: \"flex\" }}>\n <HvTooltip title={<HvTypography>{description}</HvTypography>}>\n <div>\n <Info />\n </div>\n </HvTooltip>\n <HvButton\n icon\n disabled={!hasParams}\n onClick={() => setShowParams((p) => !p)}\n >\n {showParams ? <Up /> : <Down />}\n </HvButton>\n </div>\n </div>\n <div className={classes.titleContainer}>\n <div>\n <HvTypography>{title}</HvTypography>\n </div>\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) => {\n actionCallback?.(event, node.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, node.id, action as HvActionGeneric);\n }}\n />\n )}\n </>\n )}\n </div>\n </div>\n {children && <div className={classes.contentContainer}>{children}</div>}\n {showParams && params && (\n <div className={classes.paramsContainer}>\n <ParamRenderer nodeId={id} params={params} data={node?.data} />\n </div>\n )}\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","HvFlowNode","description","expanded","params","actions","actionCallback","maxVisibleActions","classes","classesProp","className","children","showParams","setShowParams","useState","showActions","setShowActions","reactFlowInstance","useReactFlow","cx","css","useClasses","nodeGroups","nodeTypes","defaultActions","useFlowContext","useStore","s","nodes","getNodes","node","find","n","groupId","meta","title","label","groupLabel","inputs","outputs","icon","colorProp","color","getColor","useEffect","newNodes","map","Object","keys","data","length","forEach","param","value","setNodes","handleDefaultAction","useCallback","action","deleteElements","addNodes","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","hasParams","actsVisible","slice","actsDropdown","renderedIcon","actionIcon","isValidElement","border","root","backgroundColor","headerContainer","groupContainer","group","display","p","titleContainer","event","contentContainer","paramsContainer","inputsTitleContainer","inputsContainer","input","inputContainer","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;AAkDA,MAAMA,mBAAmBA,CAACC,IAAIC,MAAMC,KAAKC,UAAU;AACjD,MAAIF,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEC,WAAWN,MAAMK,EAAEE,iBAAiBL,IAAIM,SACnD,CAAA;AAAA,EACF;AACA,MAAIP,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEI,WAAWT,MAAMK,EAAEK,iBAAiBR,IAAIM,SACnD,CAAA;AAAA,EACF;AACF;AAEO,MAAMG,aAAaA,CAAC;AAAA,EACzBX;AAAAA,EACAC;AAAAA,EACAW;AAAAA,EACAC,WAAW;AAAA,EACXC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC,oBAAoB;AAAA,EACpBC,SAASC;AAAAA,EACTC;AAAAA,EACAC;AACe,MAAM;;AACrB,QAAM,CAACC,YAAYC,aAAa,IAAIC,SAASX,QAAQ;AACrD,QAAM,CAACY,aAAaC,cAAc,IAAIF,SAAS,KAAK;AACpD,QAAMG,oBAAoBC;A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QAEJ,oBAAC,cAAcmG,EAAAA,UAAAA,MAAMvD,MAAM,CAAA;AAAA,QAC1BuD,MAAMM,eACL,CAAC5G,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxC,oBAAC,OAAI,EAAA,WAAWe,QAAQ0F,UACzB,CAAA;AAAA,MAAA,KAlBwC1G,GAmB7C,IAEJ;AAAA,IAAA,GACF;AAAA,IAED+C,WAAWA,QAAQW,SAAS,KAEzB,qBAAA,UAAA,EAAA,UAAA;AAAA,MAAA,oBAAC,SAAI,WAAW1C,QAAQ2F,uBACtB,UAAC,oBAAA,cAAA,EAAa,qBAAO,EACvB,CAAA;AAAA,MACC,oBAAA,OAAA,EAAI,WAAW3F,QAAQ4F,kBACrB7D,UAASO,mCAAAA,IAAI,CAACuD,QAAQ7G,QACrB,qBAAC,OAAI,EAAA,WAAWgB,QAAQ8F,iBACtB,UAAA;AAAA,QAAA,oBAAC,QACC,EAAA,MAAK,UACL,kBAAkB,OAClB,IAAK,GAAE9G,GAAI,IACX,UAAUqG,SAASU,OACnB,OAAO;AAAA,UACLP,QAAQ,MAAM,MAAMzD,QAAQW,SAAS1D;AAAAA,UACrCuG,KAAK;AAAA,QAAA,GACL;AAAA,QAEHM,OAAOJ,eACN,CAAC5G,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxC,oBAAC,OAAI,EAAA,WAAWe,QAAQ0F,UACzB,CAAA;AAAA,QACH,oBAAC,cAAcG,EAAAA,UAAAA,OAAOjE,MAAM,CAAA;AAAA,MAAA,KAfgB5C,GAgB9C,IAEJ;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, Fragment, jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { useMemo, useState } from "react";
|
|
3
3
|
import debounce from "lodash/debounce";
|
|
4
|
-
import { useDroppable } from "@dnd-kit/core";
|
|
4
|
+
import { useDroppable, useDndMonitor, DragOverlay } from "@dnd-kit/core";
|
|
5
|
+
import { restrictToWindowEdges } from "@dnd-kit/modifiers";
|
|
5
6
|
import { useLabels, useUniqueId, HvDrawer, HvTypography, HvInput } from "@hitachivantara/uikit-react-core";
|
|
6
7
|
import { Add } from "@hitachivantara/uikit-react-icons";
|
|
7
8
|
import { useClasses } from "./Sidebar.styles.js";
|
|
8
9
|
import { staticClasses } from "./Sidebar.styles.js";
|
|
9
10
|
import { buildGroups } from "./utils.js";
|
|
10
11
|
import { HvFlowSidebarGroup } from "./SidebarGroup/SidebarGroup.js";
|
|
11
|
-
import {
|
|
12
|
+
import { HvFlowSidebarGroupItem } from "./SidebarGroup/SidebarGroupItem/SidebarGroupItem.js";
|
|
13
|
+
import { useFlowContext } from "../hooks/useFlowContext.js";
|
|
12
14
|
const DEFAULT_LABELS = {
|
|
13
15
|
itemAriaRoleDescription: "Draggable",
|
|
14
16
|
expandGroupButtonAriaLabel: "Expand group",
|
|
@@ -35,6 +37,7 @@ const HvFlowSidebar = ({
|
|
|
35
37
|
} = useFlowContext();
|
|
36
38
|
const unfilteredGroups = useMemo(() => buildGroups(nodeGroups, nodeTypes), [nodeGroups, nodeTypes]);
|
|
37
39
|
const [groups, setGroups] = useState(unfilteredGroups);
|
|
40
|
+
const [draggingLabel, setDraggingLabel] = useState(void 0);
|
|
38
41
|
const labels = useLabels(DEFAULT_LABELS, labelsProps);
|
|
39
42
|
const drawerElementId = useUniqueId(id, "hvFlowSidebarDrawer");
|
|
40
43
|
const groupsElementId = useUniqueId(id, "hvFlowSidebarGroups");
|
|
@@ -43,6 +46,19 @@ const HvFlowSidebar = ({
|
|
|
43
46
|
} = useDroppable({
|
|
44
47
|
id: drawerElementId
|
|
45
48
|
});
|
|
49
|
+
const handleDragStart = (event) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
if ((_a = event.active.data.current) == null ? void 0 : _a.hvFlow) {
|
|
52
|
+
setDraggingLabel((_b = event.active.data.current.hvFlow) == null ? void 0 : _b.label);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const handleDragEnd = () => {
|
|
56
|
+
setDraggingLabel(void 0);
|
|
57
|
+
};
|
|
58
|
+
useDndMonitor({
|
|
59
|
+
onDragEnd: handleDragEnd,
|
|
60
|
+
onDragStart: handleDragStart
|
|
61
|
+
});
|
|
46
62
|
const handleSearch = (event, value) => {
|
|
47
63
|
const gps = value ? Object.entries(unfilteredGroups).reduce((acc, curr) => {
|
|
48
64
|
const filteredNodes = curr[1].nodes.filter((obj) => obj.label.toLocaleLowerCase().includes(value.toLocaleLowerCase()));
|
|
@@ -59,25 +75,28 @@ const HvFlowSidebar = ({
|
|
|
59
75
|
setExpandedNodeGroups == null ? void 0 : setExpandedNodeGroups(value ? Object.keys(gps) : []);
|
|
60
76
|
};
|
|
61
77
|
const handleDebouncedSearch = debounce(handleSearch, 500);
|
|
62
|
-
return /* @__PURE__ */
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/* @__PURE__ */ jsxs("div", {
|
|
66
|
-
/* @__PURE__ */
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/* @__PURE__ */
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
79
|
+
/* @__PURE__ */ jsx(HvDrawer, { BackdropComponent: void 0, variant: "persistent", classes: {
|
|
80
|
+
paper: classes.drawerPaper
|
|
81
|
+
}, anchor, buttonTitle, ...others, children: /* @__PURE__ */ jsxs("div", { id: drawerElementId, ref: setNodeRef, children: [
|
|
82
|
+
/* @__PURE__ */ jsxs("div", { className: classes.titleContainer, children: [
|
|
83
|
+
/* @__PURE__ */ jsx(Add, { role: "none" }),
|
|
84
|
+
/* @__PURE__ */ jsx(HvTypography, { variant: "title3", children: title })
|
|
85
|
+
] }),
|
|
86
|
+
/* @__PURE__ */ jsxs("div", { className: classes.contentContainer, children: [
|
|
87
|
+
/* @__PURE__ */ jsx(HvTypography, { className: classes.description, children: description }),
|
|
88
|
+
/* @__PURE__ */ jsx(HvInput, { className: classes.searchRoot, type: "search", placeholder: labels == null ? void 0 : labels.searchPlaceholder, "aria-label": labels == null ? void 0 : labels.searchAriaLabel, "aria-controls": groupsElementId, "aria-owns": groupsElementId, onChange: handleDebouncedSearch, inputProps: {
|
|
89
|
+
autoComplete: "off"
|
|
90
|
+
} }),
|
|
91
|
+
/* @__PURE__ */ jsx("ul", { id: groupsElementId, className: classes.groupsContainer, children: Object.entries(groups).map((obj) => /* @__PURE__ */ jsx(HvFlowSidebarGroup, { id: obj[0], expandButtonProps: {
|
|
92
|
+
"aria-label": labels == null ? void 0 : labels.expandGroupButtonAriaLabel
|
|
93
|
+
}, itemProps: {
|
|
94
|
+
"aria-roledescription": labels == null ? void 0 : labels.itemAriaRoleDescription
|
|
95
|
+
}, ...obj[1] }, obj[0])) })
|
|
96
|
+
] })
|
|
97
|
+
] }) }),
|
|
98
|
+
/* @__PURE__ */ jsx(DragOverlay, { modifiers: [restrictToWindowEdges], children: draggingLabel ? /* @__PURE__ */ jsx(HvFlowSidebarGroupItem, { label: draggingLabel, isDragging: true }) : null })
|
|
99
|
+
] });
|
|
81
100
|
};
|
|
82
101
|
export {
|
|
83
102
|
HvFlowSidebar,
|