@hitachivantara/uikit-react-lab 5.13.1 → 5.13.3
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 +9 -22
- package/dist/cjs/components/Flow/DroppableFlow.cjs.map +1 -1
- 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/Flow.styles.cjs.map +1 -1
- package/dist/cjs/components/Flow/FlowContext/FlowContext.cjs +2 -1
- package/dist/cjs/components/Flow/FlowContext/FlowContext.cjs.map +1 -1
- package/dist/cjs/components/Flow/FlowContext/NodeMetaContext.cjs +39 -0
- package/dist/cjs/components/Flow/FlowContext/NodeMetaContext.cjs.map +1 -0
- package/dist/cjs/components/Flow/Node/BaseNode.cjs +137 -0
- package/dist/cjs/components/Flow/Node/BaseNode.cjs.map +1 -0
- package/dist/cjs/components/Flow/Node/BaseNode.styles.cjs +82 -0
- package/dist/cjs/components/Flow/Node/BaseNode.styles.cjs.map +1 -0
- package/dist/cjs/components/Flow/Node/Node.cjs +27 -110
- package/dist/cjs/components/Flow/Node/Node.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/Node.styles.cjs +1 -74
- package/dist/cjs/components/Flow/Node/Node.styles.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/components/Flow/DroppableFlow.js +9 -22
- package/dist/esm/components/Flow/DroppableFlow.js.map +1 -1
- package/dist/esm/components/Flow/Flow.js.map +1 -1
- package/dist/esm/components/Flow/Flow.styles.js +1 -1
- package/dist/esm/components/Flow/Flow.styles.js.map +1 -1
- package/dist/esm/components/Flow/FlowContext/FlowContext.js +2 -1
- package/dist/esm/components/Flow/FlowContext/FlowContext.js.map +1 -1
- package/dist/esm/components/Flow/FlowContext/NodeMetaContext.js +39 -0
- package/dist/esm/components/Flow/FlowContext/NodeMetaContext.js.map +1 -0
- package/dist/esm/components/Flow/Node/BaseNode.js +138 -0
- package/dist/esm/components/Flow/Node/BaseNode.js.map +1 -0
- package/dist/esm/components/Flow/Node/BaseNode.styles.js +82 -0
- package/dist/esm/components/Flow/Node/BaseNode.styles.js.map +1 -0
- package/dist/esm/components/Flow/Node/Node.js +30 -113
- package/dist/esm/components/Flow/Node/Node.js.map +1 -1
- package/dist/esm/components/Flow/Node/Node.styles.js +1 -74
- package/dist/esm/components/Flow/Node/Node.styles.js.map +1 -1
- package/dist/esm/index.js +6 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +89 -41
- package/package.json +4 -4
|
@@ -2,156 +2,73 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
|
-
const ReactFlow = require("reactflow");
|
|
6
5
|
const uikitReactCore = require("@hitachivantara/uikit-react-core");
|
|
7
|
-
const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
|
|
8
6
|
const uikitStyles = require("@hitachivantara/uikit-styles");
|
|
7
|
+
const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
|
|
9
8
|
const Node_styles = require("./Node.styles.cjs");
|
|
10
9
|
const ParamRenderer = require("./Parameters/ParamRenderer.cjs");
|
|
10
|
+
const BaseNode = require("./BaseNode.cjs");
|
|
11
|
+
const useFlowNode = require("../hooks/useFlowNode.cjs");
|
|
11
12
|
const useFlowContext = require("../hooks/useFlowContext.cjs");
|
|
12
|
-
const
|
|
13
|
-
if (type === "target") {
|
|
14
|
-
return edges.some((e) => e.target === id && e.targetHandle === idx.toString());
|
|
15
|
-
}
|
|
16
|
-
if (type === "source") {
|
|
17
|
-
return edges.some((e) => e.source === id && e.sourceHandle === idx.toString());
|
|
18
|
-
}
|
|
19
|
-
};
|
|
13
|
+
const renderedIcon = (actionIcon) => React.isValidElement(actionIcon) ? actionIcon : actionIcon?.();
|
|
20
14
|
const HvFlowNode = ({
|
|
21
15
|
id,
|
|
22
16
|
type,
|
|
17
|
+
headerItems,
|
|
23
18
|
description,
|
|
24
|
-
expanded = false,
|
|
25
|
-
params,
|
|
26
19
|
actions,
|
|
27
20
|
actionCallback,
|
|
28
21
|
maxVisibleActions = 1,
|
|
22
|
+
expanded = false,
|
|
23
|
+
params,
|
|
29
24
|
classes: classesProp,
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
children,
|
|
26
|
+
...props
|
|
32
27
|
}) => {
|
|
33
|
-
const [showParams, setShowParams] = React.useState(expanded);
|
|
34
|
-
const [showActions, setShowActions] = React.useState(false);
|
|
35
|
-
const reactFlowInstance = ReactFlow.useReactFlow();
|
|
36
28
|
const {
|
|
37
|
-
classes
|
|
38
|
-
cx,
|
|
39
|
-
css
|
|
29
|
+
classes
|
|
40
30
|
} = Node_styles.useClasses(classesProp);
|
|
31
|
+
const [showParams, setShowParams] = React.useState(expanded);
|
|
32
|
+
const {
|
|
33
|
+
node
|
|
34
|
+
} = useFlowNode.useFlowNode(id);
|
|
41
35
|
const {
|
|
42
36
|
nodeGroups,
|
|
43
37
|
nodeTypes,
|
|
44
38
|
defaultActions
|
|
45
39
|
} = useFlowContext.useFlowContext();
|
|
46
|
-
const edges = ReactFlow.useStore((s) => s.edges);
|
|
47
|
-
const nodes = ReactFlow.useStore((s) => s.getNodes());
|
|
48
|
-
const node = nodes.find((n) => n.id === id);
|
|
49
40
|
const groupId = nodeTypes?.[type].meta?.groupId;
|
|
50
|
-
const
|
|
41
|
+
const subtitle = nodeTypes?.[type].meta?.label;
|
|
51
42
|
const groupLabel = groupId && nodeGroups && nodeGroups[groupId].label;
|
|
52
43
|
const inputs = nodeTypes?.[type]?.meta?.inputs;
|
|
53
44
|
const outputs = nodeTypes?.[type]?.meta?.outputs;
|
|
54
45
|
const icon = groupId && nodeGroups && nodeGroups[groupId].icon;
|
|
55
46
|
const colorProp = groupId && nodeGroups && nodeGroups[groupId].color;
|
|
56
47
|
const color = uikitStyles.getColor(colorProp);
|
|
57
|
-
React.useEffect(() => {
|
|
58
|
-
const newNodes = nodes.map((n) => {
|
|
59
|
-
if (n.id === id) {
|
|
60
|
-
if (Object.keys(n.data).length === 0) {
|
|
61
|
-
params?.forEach((param) => {
|
|
62
|
-
n.data[param.id] = param.value;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return n;
|
|
67
|
-
});
|
|
68
|
-
reactFlowInstance.setNodes(newNodes);
|
|
69
|
-
}, []);
|
|
70
|
-
const handleDefaultAction = React.useCallback((action) => {
|
|
71
|
-
if (!node)
|
|
72
|
-
return;
|
|
73
|
-
switch (action) {
|
|
74
|
-
case "delete":
|
|
75
|
-
reactFlowInstance.deleteElements({
|
|
76
|
-
nodes: [node]
|
|
77
|
-
});
|
|
78
|
-
break;
|
|
79
|
-
case "duplicate":
|
|
80
|
-
reactFlowInstance.addNodes([{
|
|
81
|
-
...node,
|
|
82
|
-
id: `${reactFlowInstance.getNodes().length + 1}`,
|
|
83
|
-
position: {
|
|
84
|
-
x: node.position.x,
|
|
85
|
-
y: node.position.y + (node.height || 0) + 20
|
|
86
|
-
},
|
|
87
|
-
selected: false,
|
|
88
|
-
zIndex: Number(uikitStyles.theme.zIndices.overlay)
|
|
89
|
-
}]);
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}, [node, reactFlowInstance]);
|
|
93
|
-
const hasParams = !!(params && params.length > 0);
|
|
94
|
-
if (!node)
|
|
95
|
-
return null;
|
|
96
48
|
const actsVisible = actions?.slice(0, maxVisibleActions);
|
|
97
49
|
const actsDropdown = actions?.slice(maxVisibleActions);
|
|
98
|
-
const
|
|
99
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.groupContainer, children: [
|
|
107
|
-
icon,
|
|
108
|
-
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { variant: "title4", className: classes.group, children: groupLabel })
|
|
109
|
-
] }),
|
|
110
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
|
|
111
|
-
display: "flex"
|
|
112
|
-
}, children: [
|
|
113
|
-
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTooltip, { title: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: description }), children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Info, {}) }) }),
|
|
114
|
-
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvButton, { icon: true, disabled: !hasParams, onClick: () => setShowParams((p) => !p), children: showParams ? /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Up, {}) : /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Down, {}) })
|
|
115
|
-
] })
|
|
116
|
-
] }),
|
|
117
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.titleContainer, children: [
|
|
118
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: title }) }),
|
|
50
|
+
const hasParams = !!(params && params.length > 0);
|
|
51
|
+
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: [
|
|
52
|
+
headerItems,
|
|
53
|
+
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, {}) }) }),
|
|
54
|
+
hasParams && /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvButton, { icon: true, onClick: () => setShowParams((p) => !p), children: showParams ? /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Up, {}) : /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Down, {}) })
|
|
55
|
+
] }), ...props, children: [
|
|
56
|
+
(subtitle || actsVisible?.length || actsDropdown?.length) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.subtitleContainer, children: [
|
|
57
|
+
subtitle && /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: subtitle }) }),
|
|
119
58
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.actions, children: actions?.length && actions?.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
120
59
|
actsVisible?.map((action) => /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTooltip, { title: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: action.label }), children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvButton, { icon: true, onClick: (event) => {
|
|
121
|
-
actionCallback?.(event,
|
|
60
|
+
actionCallback?.(event, id, action);
|
|
122
61
|
}, "aria-label": action.label, children: renderedIcon(action.icon) }) }) }, action.id)),
|
|
123
62
|
actsDropdown && actsDropdown.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvDropDownMenu, { keepOpened: false, dataList: actsDropdown?.map((action) => ({
|
|
124
63
|
id: action.id,
|
|
125
64
|
label: action.label
|
|
126
65
|
})), onClick: (event, action) => {
|
|
127
|
-
actionCallback?.(event,
|
|
66
|
+
actionCallback?.(event, id, action);
|
|
128
67
|
} })
|
|
129
68
|
] }) })
|
|
130
69
|
] }),
|
|
131
|
-
children
|
|
132
|
-
showParams && params && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.paramsContainer, children: /* @__PURE__ */ jsxRuntime.jsx(ParamRenderer.default, { nodeId: id, params, data: node?.data }) })
|
|
133
|
-
inputs && inputs.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
134
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.inputsTitleContainer, children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: "Inputs" }) }),
|
|
135
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.inputsContainer, children: inputs?.map((input, idx) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.inputContainer, children: [
|
|
136
|
-
/* @__PURE__ */ jsxRuntime.jsx(ReactFlow.Handle, { type: "target", isConnectableStart: false, id: `${idx}`, position: ReactFlow.Position.Left, style: {
|
|
137
|
-
top: "auto",
|
|
138
|
-
bottom: (outputs?.length ? 80 : 18) + (outputs?.length || 0) * 29 + 29 * idx
|
|
139
|
-
} }),
|
|
140
|
-
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: input.label }),
|
|
141
|
-
input.isMandatory && !isInputConnected(id, "target", idx, edges) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.mandatory })
|
|
142
|
-
] }, idx)) })
|
|
143
|
-
] }),
|
|
144
|
-
outputs && outputs.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
145
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.outputsTitleContainer, children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: "Outputs" }) }),
|
|
146
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.outputsContainer, children: outputs?.map((output, idx) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.outputContainer, children: [
|
|
147
|
-
/* @__PURE__ */ jsxRuntime.jsx(ReactFlow.Handle, { type: "source", isConnectableEnd: false, id: `${idx}`, position: ReactFlow.Position.Right, style: {
|
|
148
|
-
bottom: -10 + 29 * (outputs.length - idx),
|
|
149
|
-
top: "auto"
|
|
150
|
-
} }),
|
|
151
|
-
output.isMandatory && !isInputConnected(id, "source", idx, edges) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.mandatory }),
|
|
152
|
-
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: output.label })
|
|
153
|
-
] }, idx)) })
|
|
154
|
-
] })
|
|
70
|
+
children,
|
|
71
|
+
showParams && params && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.paramsContainer, children: /* @__PURE__ */ jsxRuntime.jsx(ParamRenderer.default, { nodeId: id, params, data: node?.data }) })
|
|
155
72
|
] });
|
|
156
73
|
};
|
|
157
74
|
exports.flowNodeClasses = Node_styles.staticClasses;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.cjs","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","jsxs","border","root","jsx","NodeToolbar","HvButton","backgroundColor","headerContainer","groupContainer","HvTypography","group","display","HvTooltip","Info","p","Up","Down","titleContainer","event","HvDropDownMenu","contentContainer","paramsContainer","ParamRenderer","Fragment","inputsTitleContainer","inputsContainer","input","inputContainer","Handle","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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QAAAnC,2BAAA,IAACyB,UACC,QAAA,EAAA,MAAK,UACL,kBAAkB,OAClB,IAAK,GAAEjH,GAAI,IACX,UAAUkH,UAAAA,SAASU,OACnB,OAAO;AAAA,UACLP,QAAQ,MAAM,MAAMtE,QAAQW,SAAS1D;AAAAA,UACrCoH,KAAK;AAAA,QAAA,GACL;AAAA,QAEHM,OAAOJ,eACN,CAACzH,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxCuF,2BAAAA,IAAC,OAAI,EAAA,WAAWxE,QAAQuG,UACzB,CAAA;AAAA,QACH/B,2BAAAA,IAACM,eAAAA,cAAc4B,EAAAA,UAAAA,OAAO9E,MAAM,CAAA;AAAA,MAAA,KAfgB5C,GAgB9C,CACD,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
1
|
+
{"version":3,"file":"Node.cjs","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import { 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 interface HvFlowNodeProps<T>\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 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 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;\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 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 icon onClick={() => setShowParams((p) => !p)}>\n {showParams ? <Up /> : <Down />}\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","classes","classesProp","children","props","useClasses","showParams","setShowParams","useState","node","useFlowNode","nodeGroups","nodeTypes","defaultActions","useFlowContext","groupId","meta","subtitle","label","groupLabel","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":";;;;;;;;;;;;AA0CA,MAAMA,eAAeA,CAACC,eACpBC,qBAAeD,UAAU,IAAIA,aAAcA;AAEtC,MAAME,aAAaA,CAAC;AAAA,EACzBC;AAAAA,EACAC;AAAAA,EACAC;A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,CAAY,YAAA;AAAA,UACvCnD,IAAImD,OAAOnD;AAAAA,UACX0B,OAAOyB,OAAOzB;AAAAA,QACd,EAAA,GACF,SAAS,CAAC0B,OAAOD,WAAW;AACTC,2BAAAA,OAAOpD,IAAImD,MAA0B;AAAA,QAAA,GAG3D;AAAA,MAAA,EAAA,CACH,EAEJ,CAAA;AAAA,IAAA,GACF;AAAA,IAEDxC;AAAAA,IACAG,cAAcN,UACZiC,2BAAAA,IAAA,OAAA,EAAI,WAAWhC,QAAQ6C,iBACtB,UAACb,2BAAAA,IAAAc,cAAAA,SAAA,EAAc,QAAQvD,IAAI,QAAgB,MAAMiB,MAAMuC,KAAK,CAAA,GAC9D;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
@@ -5,30 +5,7 @@ const {
|
|
|
5
5
|
staticClasses,
|
|
6
6
|
useClasses
|
|
7
7
|
} = uikitReactCore.createClasses("HvFlowNode", {
|
|
8
|
-
|
|
9
|
-
borderRadius: uikitReactCore.theme.radii.round,
|
|
10
|
-
backgroundColor: uikitReactCore.theme.colors.atmo1,
|
|
11
|
-
boxShadow: uikitReactCore.theme.colors.shadow,
|
|
12
|
-
minWidth: "250px"
|
|
13
|
-
},
|
|
14
|
-
headerContainer: {
|
|
15
|
-
padding: uikitReactCore.theme.spacing(0.5, 1),
|
|
16
|
-
display: "flex",
|
|
17
|
-
flexDirection: "row",
|
|
18
|
-
justifyContent: "space-between",
|
|
19
|
-
alignItems: "center",
|
|
20
|
-
borderTopLeftRadius: uikitReactCore.theme.radii.round,
|
|
21
|
-
borderTopRightRadius: uikitReactCore.theme.radii.round
|
|
22
|
-
},
|
|
23
|
-
groupContainer: {
|
|
24
|
-
display: "flex",
|
|
25
|
-
flexDirection: "row",
|
|
26
|
-
alignItems: "center"
|
|
27
|
-
},
|
|
28
|
-
group: {
|
|
29
|
-
color: uikitReactCore.theme.colors.base_dark
|
|
30
|
-
},
|
|
31
|
-
titleContainer: {
|
|
8
|
+
subtitleContainer: {
|
|
32
9
|
minHeight: 48,
|
|
33
10
|
padding: uikitReactCore.theme.spacing(uikitReactCore.theme.space.xs, uikitReactCore.theme.space.xs, uikitReactCore.theme.space.xs, uikitReactCore.theme.space.sm),
|
|
34
11
|
display: "flex",
|
|
@@ -40,62 +17,12 @@ const {
|
|
|
40
17
|
display: "flex",
|
|
41
18
|
alignItems: "center"
|
|
42
19
|
},
|
|
43
|
-
inputsTitleContainer: {
|
|
44
|
-
display: "flex",
|
|
45
|
-
justifyContent: "center",
|
|
46
|
-
padding: uikitReactCore.theme.space.xs,
|
|
47
|
-
backgroundColor: uikitReactCore.theme.colors.atmo2,
|
|
48
|
-
borderTop: `1px solid ${uikitReactCore.theme.colors.atmo4}`,
|
|
49
|
-
borderBottom: `1px solid ${uikitReactCore.theme.colors.atmo4}`
|
|
50
|
-
},
|
|
51
|
-
outputsTitleContainer: {
|
|
52
|
-
display: "flex",
|
|
53
|
-
justifyContent: "center",
|
|
54
|
-
padding: uikitReactCore.theme.space.xs,
|
|
55
|
-
backgroundColor: uikitReactCore.theme.colors.atmo2,
|
|
56
|
-
borderTop: `1px solid ${uikitReactCore.theme.colors.atmo4}`,
|
|
57
|
-
borderBottom: `1px solid ${uikitReactCore.theme.colors.atmo4}`
|
|
58
|
-
},
|
|
59
|
-
contentContainer: {
|
|
60
|
-
padding: uikitReactCore.theme.space.sm
|
|
61
|
-
},
|
|
62
|
-
inputsContainer: {
|
|
63
|
-
display: "flex",
|
|
64
|
-
flexDirection: "column",
|
|
65
|
-
padding: uikitReactCore.theme.space.sm,
|
|
66
|
-
gap: uikitReactCore.theme.space.xs,
|
|
67
|
-
alignItems: "flex-start"
|
|
68
|
-
},
|
|
69
|
-
outputsContainer: {
|
|
70
|
-
display: "flex",
|
|
71
|
-
flexDirection: "column",
|
|
72
|
-
padding: uikitReactCore.theme.space.sm,
|
|
73
|
-
gap: uikitReactCore.theme.space.xs,
|
|
74
|
-
alignItems: "flex-end"
|
|
75
|
-
},
|
|
76
20
|
paramsContainer: {
|
|
77
21
|
borderTop: `1px solid ${uikitReactCore.theme.colors.atmo4}`,
|
|
78
22
|
display: "flex",
|
|
79
23
|
flexDirection: "column",
|
|
80
24
|
gap: uikitReactCore.theme.space.xs,
|
|
81
25
|
padding: uikitReactCore.theme.space.sm
|
|
82
|
-
},
|
|
83
|
-
inputContainer: {
|
|
84
|
-
display: "flex",
|
|
85
|
-
flexDirection: "row",
|
|
86
|
-
alignItems: "center"
|
|
87
|
-
},
|
|
88
|
-
outputContainer: {
|
|
89
|
-
display: "flex",
|
|
90
|
-
flexDirection: "row",
|
|
91
|
-
alignItems: "center"
|
|
92
|
-
},
|
|
93
|
-
mandatory: {
|
|
94
|
-
width: 10,
|
|
95
|
-
height: 10,
|
|
96
|
-
margin: uikitReactCore.theme.spacing(0, uikitReactCore.theme.space.xs),
|
|
97
|
-
borderRadius: uikitReactCore.theme.radii.circle,
|
|
98
|
-
backgroundColor: uikitReactCore.theme.colors.negative_20
|
|
99
26
|
}
|
|
100
27
|
});
|
|
101
28
|
exports.staticClasses = staticClasses;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.styles.cjs","sources":["../../../../../src/components/Flow/Node/Node.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFlowNode\", {\n
|
|
1
|
+
{"version":3,"file":"Node.styles.cjs","sources":["../../../../../src/components/Flow/Node/Node.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFlowNode\", {\n subtitleContainer: {\n minHeight: 48,\n padding: theme.spacing(\n theme.space.xs,\n theme.space.xs,\n theme.space.xs,\n theme.space.sm\n ),\n display: \"flex\",\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n },\n actions: {\n display: \"flex\",\n alignItems: \"center\",\n },\n paramsContainer: {\n borderTop: `1px solid ${theme.colors.atmo4}`,\n display: \"flex\",\n flexDirection: \"column\",\n gap: theme.space.xs,\n padding: theme.space.sm,\n },\n});\n"],"names":["staticClasses","useClasses","createClasses","subtitleContainer","minHeight","padding","theme","spacing","space","xs","sm","display","flexDirection","justifyContent","alignItems","actions","paramsContainer","borderTop","colors","atmo4","gap"],"mappings":";;;AAEa,MAAA;AAAA,EAAEA;AAAAA,EAAeC;AAAW,IAAIC,eAAAA,cAAc,cAAc;AAAA,EACvEC,mBAAmB;AAAA,IACjBC,WAAW;AAAA,IACXC,SAASC,eAAAA,MAAMC,QACbD,eAAAA,MAAME,MAAMC,IACZH,eAAAA,MAAME,MAAMC,IACZH,eAAME,MAAAA,MAAMC,IACZH,eAAAA,MAAME,MAAME,EACd;AAAA,IACAC,SAAS;AAAA,IACTC,eAAe;AAAA,IACfC,gBAAgB;AAAA,IAChBC,YAAY;AAAA,EACd;AAAA,EACAC,SAAS;AAAA,IACPJ,SAAS;AAAA,IACTG,YAAY;AAAA,EACd;AAAA,EACAE,iBAAiB;AAAA,IACfC,WAAY,aAAYX,eAAMY,MAAAA,OAAOC,KAAM;AAAA,IAC3CR,SAAS;AAAA,IACTC,eAAe;AAAA,IACfQ,KAAKd,eAAAA,MAAME,MAAMC;AAAAA,IACjBJ,SAASC,eAAAA,MAAME,MAAME;AAAAA,EACvB;AACF,CAAC;;;"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -22,6 +22,8 @@ const Sidebar_styles = require("./components/Flow/Sidebar/Sidebar.styles.cjs");
|
|
|
22
22
|
const Sidebar = require("./components/Flow/Sidebar/Sidebar.cjs");
|
|
23
23
|
const Empty = require("./components/Flow/Empty/Empty.cjs");
|
|
24
24
|
const Flow = require("./components/Flow/Flow.cjs");
|
|
25
|
+
const BaseNode_styles = require("./components/Flow/Node/BaseNode.styles.cjs");
|
|
26
|
+
const BaseNode = require("./components/Flow/Node/BaseNode.cjs");
|
|
25
27
|
const Node_styles = require("./components/Flow/Node/Node.styles.cjs");
|
|
26
28
|
const Node = require("./components/Flow/Node/Node.cjs");
|
|
27
29
|
const useFlowNode = require("./components/Flow/hooks/useFlowNode.cjs");
|
|
@@ -48,6 +50,8 @@ exports.flowSidebarClasses = Sidebar_styles.staticClasses;
|
|
|
48
50
|
exports.HvFlowSidebar = Sidebar.HvFlowSidebar;
|
|
49
51
|
exports.HvFlowEmpty = Empty.HvFlowEmpty;
|
|
50
52
|
exports.HvFlow = Flow.HvFlow;
|
|
53
|
+
exports.flowBaseNodeClasses = BaseNode_styles.staticClasses;
|
|
54
|
+
exports.HvFlowBaseNode = BaseNode.HvFlowBaseNode;
|
|
51
55
|
exports.flowNodeClasses = Node_styles.staticClasses;
|
|
52
56
|
exports.HvFlowNode = Node.HvFlowNode;
|
|
53
57
|
exports.useFlowNode = useFlowNode.useFlowNode;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -8,11 +8,12 @@ import { useUniqueId } from "@hitachivantara/uikit-react-core";
|
|
|
8
8
|
import { useClasses } from "./Flow.styles.js";
|
|
9
9
|
import { staticClasses } from "./Flow.styles.js";
|
|
10
10
|
import { flowStyles } from "./base.js";
|
|
11
|
+
import { useNodeMetaRegistry } from "./FlowContext/NodeMetaContext.js";
|
|
11
12
|
import { useFlowContext } from "./hooks/useFlowContext.js";
|
|
12
13
|
const getNode = (nodes, nodeId) => {
|
|
13
14
|
return nodes.find((n) => n.id === nodeId);
|
|
14
15
|
};
|
|
15
|
-
const validateEdge = (nodes, edge,
|
|
16
|
+
const validateEdge = (nodes, edge, nodeMetaRegistry) => {
|
|
16
17
|
if (!edge.sourceHandle || !edge.targetHandle)
|
|
17
18
|
return false;
|
|
18
19
|
const sourceNode = getNode(nodes, edge.source);
|
|
@@ -23,26 +24,13 @@ const validateEdge = (nodes, edge, nodeTypes) => {
|
|
|
23
24
|
const targetType = targetNode.type;
|
|
24
25
|
if (!sourceType || !targetType)
|
|
25
26
|
return false;
|
|
26
|
-
const inputs =
|
|
27
|
-
const outputs =
|
|
27
|
+
const inputs = nodeMetaRegistry[edge.target]?.inputs || [];
|
|
28
|
+
const outputs = nodeMetaRegistry[edge.source]?.outputs || [];
|
|
28
29
|
const sourceProvides = outputs[edge.sourceHandle]?.provides || "";
|
|
29
30
|
const targetAccepts = inputs[edge.targetHandle]?.accepts || [];
|
|
30
31
|
const isValid = targetAccepts.includes(sourceProvides);
|
|
31
32
|
return isValid;
|
|
32
33
|
};
|
|
33
|
-
const validateEdges = (edges, nodes, nodeTypes) => {
|
|
34
|
-
if (edges) {
|
|
35
|
-
const validEdges = [];
|
|
36
|
-
edges.forEach((edge) => {
|
|
37
|
-
const isValidEdge = validateEdge(nodes, edge, nodeTypes);
|
|
38
|
-
if (isValidEdge) {
|
|
39
|
-
validEdges.push(edge);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return validEdges;
|
|
43
|
-
}
|
|
44
|
-
return [];
|
|
45
|
-
};
|
|
46
34
|
const HvDroppableFlow = ({
|
|
47
35
|
id,
|
|
48
36
|
className,
|
|
@@ -126,11 +114,10 @@ const HvDroppableFlow = ({
|
|
|
126
114
|
handleFlowChange(nodes, eds);
|
|
127
115
|
onEdgesChangeProp?.(changes);
|
|
128
116
|
}, [edges, handleFlowChange, nodes, onEdgesChangeProp]);
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const validEdges = validateEdges(edges, nodes, nodeTypes);
|
|
117
|
+
const {
|
|
118
|
+
registry
|
|
119
|
+
} = useNodeMetaRegistry();
|
|
120
|
+
const isValidConnection = (connection) => validateEdge(nodes, connection, registry);
|
|
134
121
|
const defaultEdgeOptions = {
|
|
135
122
|
markerEnd: {
|
|
136
123
|
type: MarkerType.ArrowClosed,
|
|
@@ -141,7 +128,7 @@ const HvDroppableFlow = ({
|
|
|
141
128
|
};
|
|
142
129
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
143
130
|
/* @__PURE__ */ jsx(Global, { styles: flowStyles }),
|
|
144
|
-
/* @__PURE__ */ jsx("div", { id: elementId, ref: setNodeRef, className: cx(classes.root, className), children: /* @__PURE__ */ jsx(ReactFlow, { nodes, edges
|
|
131
|
+
/* @__PURE__ */ jsx("div", { id: elementId, ref: setNodeRef, className: cx(classes.root, className), children: /* @__PURE__ */ jsx(ReactFlow, { nodes, edges, nodeTypes, onNodesChange: handleNodesChange, onEdgesChange: handleEdgesChange, onConnect: handleConnect, isValidConnection, defaultEdgeOptions, ...others, children }) })
|
|
145
132
|
] });
|
|
146
133
|
};
|
|
147
134
|
export {
|
|
@@ -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 { 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 /** 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 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 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 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","onDndDrop","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":";;;;;;;;;;;AA6DaA,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,SAASV,YAAYS,UAAU,GAAGE,MAAMD,UAAU;AACxD,QAAME,UAAUZ,YAAYO,UAAU,GAAGI,MAAMC,WAAW;AAE1D,QAAMC,iBAAiBD,QAAQb,KAAKE,YAAY,GAAGa,YAAY;AAC/D,QAAMC,gBAAgBL,OAAOX,KAAKG,YAAY,GAAGc,WAAW;AAEtDC,QAAAA,UAAUF,cAAcG,SAASL,cAAc;AAC9CI,SAAAA;AACT;AAEA,MAAME,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,aAASsB,GAAG;AAEZI,qBAAiBJ,KAAKpD,KAAK;AAC3BiB,wBAAoBgD,OAAO;AAAA,KAE7B,CAACjE,OAAOwD,kBAAkBnF,OAAO4C,iBAAiB,CACpD;AAEMkD,QAAAA,oBAAoB/B,YACxB,CAAC6B,YAA0B;AACnBR,UAAAA,MAAMW,iBAAiBH,SAASjE,KAAK;AAC3CgC,aAASyB,GAAG;AAEZD,qBAAiBnF,OAAOoF,GAAG;AAC3BtC,wBAAoB8C,OAAO;AAAA,KAE7B,CAACjE,OAAOwD,kBAAkBnF,OAAO8C,iBAAiB,CACpD;AAEA,QAAMkD,oBAAqBP,CAAe,eAAA;AACxC,UAAMjE,UAAUnB,aAAaL,OAAOyF,YAAYlF,SAAS;AAClDiB,WAAAA;AAAAA,EAAAA;AAGT,QAAMI,aAAaF,cAAcC,OAAO3B,OAAOO,SAAS;AAExD,QAAMwC,qBAAqB;AAAA,IACzBkD,WAAW;AAAA,MACTlF,MAAMmF,WAAWC;AAAAA,MACjBC,QAAQ;AAAA,MACRC,OAAO;AAAA,IACT;AAAA,IACA,GAAGrD;AAAAA,EAAAA;AAGL,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAC,oBAAA,QAAA,EAAO,QAAQsD,WAAW,CAAA;AAAA,IAC1B,oBAAA,OAAA,EACC,IAAIlD,WACJ,KAAKQ,YACL,WAAWV,GAAGb,QAAQkE,MAAMtE,SAAS,GAErC,UAAC,oBAAA,WAAA,EACC,OACA,OAAOL,YACP,WACA,eAAe+D,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBACIvC,GAAAA,QAEHf,SACH,CAAA,GACF;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 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\n const isValid = targetAccepts.includes(sourceProvides);\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, 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","edge","nodeMetaRegistry","sourceHandle","targetHandle","sourceNode","source","targetNode","target","sourceType","type","targetType","inputs","outputs","sourceProvides","provides","targetAccepts","accepts","isValid","includes","HvDroppableFlow","className","children","onFlowChange","onDndDrop","classes","classesProp","initialNodes","edges","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,MACAC,qBACG;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,SAASV,iBAAiBD,KAAKO,MA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KzC,KAAK;AAC3BK,wBAAoBiD,OAAO;AAAA,KAE7B,CAACtD,OAAO6C,kBAAkB9E,OAAOsC,iBAAiB,CACpD;AAEMmD,QAAAA,oBAAoB/B,YACxB,CAAC6B,YAA0B;AACnBR,UAAAA,MAAMW,iBAAiBH,SAAStD,KAAK;AAC3CqB,aAASyB,GAAG;AAEZD,qBAAiB9E,OAAO+E,GAAG;AAC3BvC,wBAAoB+C,OAAO;AAAA,KAE7B,CAACtD,OAAO6C,kBAAkB9E,OAAOwC,iBAAiB,CACpD;AAEM,QAAA;AAAA,IAAEmD;AAAAA,MAAaC,oBAAoB;AACzC,QAAMC,oBAAqBT,CAAAA,eACzB/E,aAAaL,OAAOoF,YAAYO,QAAQ;AAE1C,QAAMlD,qBAAqB;AAAA,IACzBqD,WAAW;AAAA,MACT/E,MAAMgF,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,GAAGd,QAAQsE,MAAM1E,SAAS,GAErC,UAAC,oBAAA,WAAA,EACC,OACA,OACA,WACA,eAAe4D,mBACf,eAAeG,mBACf,WAAWN,eACX,mBACA,oBACIxC,GAAAA,QAEHhB,SAAAA,CACH,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 { HvFlowNodeAction, HvFlowNodeGroups, HvFlowNodeTypes } 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?: HvFlowNodeAction[];\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":";;;;;;AA6CO,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,5 +1,5 @@
|
|
|
1
1
|
import { createClasses, theme } from "@hitachivantara/uikit-react-core";
|
|
2
|
-
import { staticClasses as staticClasses$1 } from "./Node/
|
|
2
|
+
import { staticClasses as staticClasses$1 } from "./Node/BaseNode.styles.js";
|
|
3
3
|
import "@emotion/react/jsx-runtime";
|
|
4
4
|
import "react";
|
|
5
5
|
import "reactflow";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flow.styles.js","sources":["../../../../src/components/Flow/Flow.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"Flow.styles.js","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,cAAc,UAAU;AAAA,EACnEC,MAAM;AAAA,IACJC,QAAQ;AAAA,IACR,yBAAyB;AAAA,MACvBC,iBAAiBC,MAAMC,OAAOC;AAAAA,MAC9BC,OAAO;AAAA,MACPL,QAAQ;AAAA,MACRM,QAAQJ,MAAMK,SAASC;AAAAA,IACzB;AAAA,IACA,oCAAoC;AAAA,MAClCP,iBAAiBC,MAAMC,OAAOM;AAAAA,MAC9BJ,OAAO;AAAA,MACPL,QAAQ;AAAA,MACR,6BAA6B;AAAA,QAC3BU,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,+BAA+B;AAAA,MAC7BT,iBAAiBC,MAAMC,OAAOQ;AAAAA,MAC9BN,OAAO;AAAA,MACPL,QAAQ;AAAA,MACR,6BAA6B;AAAA,QAC3BU,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,CAAE,kBAAiBE,gBAAoBb,IAAK,EAAC,GAAG;AAAA,MAC9Cc,QAAS,aAAYX,MAAMC,OAAOC,YAAa;AAAA,MAC/CU,cAAcZ,MAAMa,MAAMC;AAAAA,MAC1BC,WAAW;AAAA,IACb;AAAA,EACF;AACF,CAAC;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { createContext, useState, useMemo } from "react";
|
|
3
|
+
import { HvFlowNodeMetaProvider } from "./NodeMetaContext.js";
|
|
3
4
|
const HvFlowContext = createContext({});
|
|
4
5
|
const HvFlowProvider = ({
|
|
5
6
|
nodeGroups,
|
|
@@ -15,7 +16,7 @@ const HvFlowProvider = ({
|
|
|
15
16
|
expandedNodeGroups,
|
|
16
17
|
setExpandedNodeGroups
|
|
17
18
|
}), [nodeTypes, nodeGroups, defaultActions, expandedNodeGroups]);
|
|
18
|
-
return /* @__PURE__ */ jsx(HvFlowContext.Provider, { value, children });
|
|
19
|
+
return /* @__PURE__ */ jsx(HvFlowNodeMetaProvider, { children: /* @__PURE__ */ jsx(HvFlowContext.Provider, { value, children }) });
|
|
19
20
|
};
|
|
20
21
|
export {
|
|
21
22
|
HvFlowContext,
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 { HvFlowNodeAction, HvFlowNodeGroups, HvFlowNodeTypes } from \"../types\";\nimport { HvFlowNodeMetaProvider } from \"./NodeMetaContext\";\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?: HvFlowNodeAction[];\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?: HvFlowNodeAction[];\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 <HvFlowNodeMetaProvider>\n <HvFlowContext.Provider value={value}>{children}</HvFlowContext.Provider>\n </HvFlowNodeMetaProvider>\n );\n};\n"],"names":["HvFlowContext","createContext","HvFlowProvider","nodeGroups","nodeTypes","defaultActions","children","expandedNodeGroups","setExpandedNodeGroups","useState","value","useMemo"],"mappings":";;;AAwBaA,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;AAGE,SAAA,oBAAC,0BACC,UAAC,oBAAA,cAAc,UAAd,EAAuB,OAAeD,SAAS,CAAA,EAClD,CAAA;AAEJ;"}
|