@hitachivantara/uikit-react-lab 5.34.2 → 5.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/Flow/DroppableFlow.cjs +7 -5
  2. package/dist/cjs/Flow/Flow.cjs +10 -19
  3. package/dist/cjs/Flow/FlowContext/FlowContext.cjs +1 -3
  4. package/dist/cjs/Flow/Node/Node.cjs +17 -17
  5. package/dist/cjs/Flow/Sidebar/Sidebar.cjs +41 -61
  6. package/dist/cjs/Flow/Sidebar/Sidebar.styles.cjs +0 -3
  7. package/dist/cjs/Flow/Sidebar/SidebarGroup/SidebarGroup.cjs +8 -8
  8. package/dist/cjs/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.cjs +5 -5
  9. package/dist/cjs/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.cjs +21 -22
  10. package/dist/esm/Flow/DroppableFlow.js +7 -5
  11. package/dist/esm/Flow/DroppableFlow.js.map +1 -1
  12. package/dist/esm/Flow/Flow.js +10 -19
  13. package/dist/esm/Flow/Flow.js.map +1 -1
  14. package/dist/esm/Flow/FlowContext/FlowContext.js +1 -3
  15. package/dist/esm/Flow/FlowContext/FlowContext.js.map +1 -1
  16. package/dist/esm/Flow/Node/Node.js +17 -17
  17. package/dist/esm/Flow/Node/Node.js.map +1 -1
  18. package/dist/esm/Flow/Sidebar/Sidebar.js +42 -62
  19. package/dist/esm/Flow/Sidebar/Sidebar.js.map +1 -1
  20. package/dist/esm/Flow/Sidebar/Sidebar.styles.js +0 -3
  21. package/dist/esm/Flow/Sidebar/Sidebar.styles.js.map +1 -1
  22. package/dist/esm/Flow/Sidebar/SidebarGroup/SidebarGroup.js +8 -8
  23. package/dist/esm/Flow/Sidebar/SidebarGroup/SidebarGroup.js.map +1 -1
  24. package/dist/esm/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.js +5 -5
  25. package/dist/esm/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.js.map +1 -1
  26. package/dist/esm/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.js +21 -22
  27. package/dist/esm/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.js.map +1 -1
  28. package/dist/types/index.d.ts +33 -52
  29. package/package.json +3 -3
  30. package/dist/cjs/Flow/Sidebar/utils.cjs +0 -43
  31. package/dist/esm/Flow/Sidebar/utils.js +0 -43
  32. package/dist/esm/Flow/Sidebar/utils.js.map +0 -1
@@ -11,7 +11,6 @@ const base = require("./base.cjs");
11
11
  const Flow_styles = require("./Flow.styles.cjs");
12
12
  const NodeMetaContext = require("./FlowContext/NodeMetaContext.cjs");
13
13
  const useFlowInstance = require("./hooks/useFlowInstance.cjs");
14
- const useFlowContext = require("./hooks/useFlowContext.cjs");
15
14
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
16
15
  const ReactFlow__default = /* @__PURE__ */ _interopDefault(ReactFlow);
17
16
  const getNode = (nodes, nodeId) => {
@@ -36,8 +35,8 @@ const validateEdge = (nodes, edges, connection, nodeMetaRegistry) => {
36
35
  return false;
37
36
  const inputs = nodeMetaRegistry[targetId]?.inputs || [];
38
37
  const outputs = nodeMetaRegistry[sourceId]?.outputs || [];
39
- const source = outputs.map((out) => out.outputs || out).flat().find((out) => out.id === sourceHandle);
40
- const target = inputs.map((inp) => inp.inputs || inp).flat().find((inp) => inp.id === targetHandle);
38
+ const source = outputs.flatMap((out) => out.outputs || out).find((out) => out.id === sourceHandle);
39
+ const target = inputs.flatMap((inp) => inp.inputs || inp).find((inp) => inp.id === targetHandle);
41
40
  const sourceProvides = source?.provides || "";
42
41
  const targetAccepts = target?.accepts || [];
43
42
  const sourceMaxConnections = source?.maxConnections;
@@ -70,12 +69,12 @@ const HvDroppableFlow = ({
70
69
  onNodesChange: onNodesChangeProp,
71
70
  onEdgesChange: onEdgesChangeProp,
72
71
  defaultEdgeOptions: defaultEdgeOptionsProp,
72
+ nodeTypes,
73
73
  ...others
74
74
  }) => {
75
75
  const { classes, cx } = Flow_styles.useClasses(classesProp);
76
76
  const elementId = uikitReactCore.useUniqueId(id);
77
77
  const reactFlowInstance = useFlowInstance.useFlowInstance();
78
- const { nodeTypes } = useFlowContext.useFlowContext();
79
78
  const [nodes, setNodes] = React.useState(initialNodes);
80
79
  const [edges, setEdges] = React.useState(initialEdges);
81
80
  const nodesRef = React.useRef(initialNodes);
@@ -104,7 +103,10 @@ const HvDroppableFlow = ({
104
103
  x: hvFlow?.x || 0,
105
104
  y: hvFlow?.y || 0
106
105
  });
107
- const data = hvFlow?.data || {};
106
+ const data = {
107
+ nodeLabel: hvFlow?.label,
108
+ ...hvFlow?.data
109
+ };
108
110
  const newNode = {
109
111
  id: uid.uid(),
110
112
  position,
@@ -7,7 +7,6 @@ const ReactFlow = require("reactflow");
7
7
  const DroppableFlow = require("./DroppableFlow.cjs");
8
8
  const FlowContext = require("./FlowContext/FlowContext.cjs");
9
9
  const HvFlow = ({
10
- nodeTypes,
11
10
  nodeGroups,
12
11
  sidebar,
13
12
  defaultActions,
@@ -18,25 +17,17 @@ const HvFlow = ({
18
17
  core.useSensor(core.PointerSensor),
19
18
  core.useSensor(core.KeyboardSensor)
20
19
  );
21
- return /* @__PURE__ */ jsxRuntime.jsx(ReactFlow.ReactFlowProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(
22
- FlowContext.HvFlowProvider,
20
+ return /* @__PURE__ */ jsxRuntime.jsx(ReactFlow.ReactFlowProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(FlowContext.HvFlowProvider, { nodeGroups, defaultActions, children: /* @__PURE__ */ jsxRuntime.jsxs(
21
+ core.DndContext,
23
22
  {
24
- nodeGroups,
25
- nodeTypes,
26
- defaultActions,
27
- children: /* @__PURE__ */ jsxRuntime.jsxs(
28
- core.DndContext,
29
- {
30
- sensors,
31
- modifiers: [modifiers.restrictToWindowEdges],
32
- ...dndContextProps,
33
- children: [
34
- /* @__PURE__ */ jsxRuntime.jsx(DroppableFlow.HvDroppableFlow, { ...others }),
35
- sidebar
36
- ]
37
- }
38
- )
23
+ sensors,
24
+ modifiers: [modifiers.restrictToWindowEdges],
25
+ ...dndContextProps,
26
+ children: [
27
+ /* @__PURE__ */ jsxRuntime.jsx(DroppableFlow.HvDroppableFlow, { ...others }),
28
+ sidebar
29
+ ]
39
30
  }
40
- ) });
31
+ ) }) });
41
32
  };
42
33
  exports.HvFlow = HvFlow;
@@ -6,20 +6,18 @@ const NodeMetaContext = require("./NodeMetaContext.cjs");
6
6
  const HvFlowContext = React.createContext({});
7
7
  const HvFlowProvider = ({
8
8
  nodeGroups,
9
- nodeTypes,
10
9
  defaultActions,
11
10
  children
12
11
  }) => {
13
12
  const [expandedNodeGroups, setExpandedNodeGroups] = React.useState([]);
14
13
  const value = React.useMemo(
15
14
  () => ({
16
- nodeTypes,
17
15
  nodeGroups,
18
16
  defaultActions,
19
17
  expandedNodeGroups,
20
18
  setExpandedNodeGroups
21
19
  }),
22
- [nodeTypes, nodeGroups, defaultActions, expandedNodeGroups]
20
+ [nodeGroups, defaultActions, expandedNodeGroups]
23
21
  );
24
22
  return /* @__PURE__ */ jsxRuntime.jsx(NodeMetaContext.HvFlowNodeMetaProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(HvFlowContext.Provider, { value, children }) });
25
23
  };
@@ -2,7 +2,6 @@
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 css = require("@emotion/css");
6
5
  const uikitReactCore = require("@hitachivantara/uikit-react-core");
7
6
  const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
8
7
  const BaseNode = require("./BaseNode.cjs");
@@ -18,7 +17,6 @@ const HvFlowNode = ({
18
17
  id,
19
18
  type,
20
19
  headerItems,
21
- description,
22
20
  actions,
23
21
  actionCallback,
24
22
  // TODO - remove in v6
@@ -27,34 +25,38 @@ const HvFlowNode = ({
27
25
  expanded = false,
28
26
  actionsIconOnly = true,
29
27
  params,
30
- nodeDefaults,
31
28
  classes: classesProp,
32
29
  labels: labelsProps,
33
30
  children,
34
31
  expandParamsButtonProps,
35
32
  disableInlineEdit,
33
+ title: titleProp,
34
+ subtitle: subtitleProp,
35
+ description,
36
+ groupId,
37
+ color: colorProp,
38
+ icon: iconProp,
36
39
  ...props
37
40
  }) => {
38
41
  const { classes } = Node_styles.useClasses(classesProp);
39
- const labels = uikitReactCore.useLabels(DEFAULT_LABELS, labelsProps);
40
42
  const [showParams, setShowParams] = React.useState(expanded);
43
+ const { nodeGroups, defaultActions } = useFlowContext.useFlowContext();
44
+ const labels = uikitReactCore.useLabels(DEFAULT_LABELS, labelsProps);
41
45
  const node = useFlowNode.useFlowNode();
42
46
  const { setNodeData } = useFlowNode.useFlowNodeUtils();
43
- const { nodeGroups, nodeTypes, defaultActions } = useFlowContext.useFlowContext();
44
- const subtitle = node?.data.customNodeLabel || nodeTypes?.[type].meta?.label || nodeDefaults?.subTitle;
45
- const groupId = nodeTypes?.[type].meta?.groupId;
46
47
  const inlineEditorWidth = actions === void 0 || Array.isArray(actions) && actions.length === 0 || maxVisibleActions === 0 ? "100%" : `calc(200px - calc(${maxVisibleActions} * 32px + ${uikitReactCore.theme.spacing(2)}))`;
47
- const group = groupId && nodeGroups && nodeGroups[groupId] || void 0;
48
- const groupLabel = group?.label || nodeDefaults?.title;
49
- const icon = group?.icon || nodeDefaults?.icon;
50
- const color = group?.color || nodeDefaults?.color;
48
+ const nodeGroup = groupId && nodeGroups && nodeGroups[groupId] || void 0;
49
+ const title = titleProp || nodeGroup?.label;
50
+ const icon = iconProp || nodeGroup?.icon;
51
+ const color = colorProp || nodeGroup?.color;
52
+ const subtitle = subtitleProp || node?.data.nodeLabel;
51
53
  const hasParams = !!(params && params.length > 0);
52
54
  return /* @__PURE__ */ jsxRuntime.jsxs(
53
55
  BaseNode.HvFlowBaseNode,
54
56
  {
55
57
  id,
56
58
  type,
57
- title: groupLabel,
59
+ title,
58
60
  icon,
59
61
  color,
60
62
  nodeActions: defaultActions,
@@ -83,14 +85,12 @@ const HvFlowNode = ({
83
85
  {
84
86
  defaultValue: subtitle,
85
87
  showIcon: true,
88
+ style: { width: inlineEditorWidth },
86
89
  classes: {
87
90
  root: classes.inlineEditRoot,
88
- button: classes.inlineEditButton,
89
- inputRoot: css.css({
90
- width: inlineEditorWidth
91
- })
91
+ button: classes.inlineEditButton
92
92
  },
93
- onBlur: (evt, value) => setNodeData((prev) => ({ ...prev, customNodeLabel: value }))
93
+ onBlur: (evt, value) => setNodeData((prev) => ({ ...prev, nodeLabel: value }))
94
94
  }
95
95
  )),
96
96
  actions && /* @__PURE__ */ jsxRuntime.jsx(
@@ -4,11 +4,9 @@ const jsxRuntime = require("@emotion/react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const core = require("@dnd-kit/core");
6
6
  const modifiers = require("@dnd-kit/modifiers");
7
- const usehooksTs = require("usehooks-ts");
8
7
  const uikitReactCore = require("@hitachivantara/uikit-react-core");
9
8
  const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
10
9
  const Sidebar_styles = require("./Sidebar.styles.cjs");
11
- const utils = require("./utils.cjs");
12
10
  const SidebarGroup = require("./SidebarGroup/SidebarGroup.cjs");
13
11
  const SidebarGroupItem = require("./SidebarGroup/SidebarGroupItem/SidebarGroupItem.cjs");
14
12
  const useFlowContext = require("../hooks/useFlowContext.cjs");
@@ -25,30 +23,20 @@ const HvFlowSidebar = ({
25
23
  description,
26
24
  anchor = "right",
27
25
  buttonTitle = "Close",
26
+ flatten = false,
28
27
  classes: classesProp,
29
28
  labels: labelsProps,
30
29
  dragOverlayProps,
31
- defaultGroupProps,
32
30
  ...others
33
31
  }) => {
34
32
  const { classes } = Sidebar_styles.useClasses(classesProp);
35
- const { nodeGroups, nodeTypes, setExpandedNodeGroups } = useFlowContext.useFlowContext();
36
- const unfilteredGroups = React.useMemo(
37
- () => utils.buildGroups(nodeGroups, nodeTypes, defaultGroupProps),
38
- [nodeGroups, nodeTypes, defaultGroupProps]
39
- );
40
- const [groups, setGroups] = React.useState(unfilteredGroups);
41
- const [ndTypes, setNdTypes] = React.useState(nodeTypes);
42
- const [draggingLabel, setDraggingLabel] = React.useState(void 0);
43
- React.useEffect(() => {
44
- setGroups(unfilteredGroups);
45
- }, [unfilteredGroups]);
33
+ const { nodeGroups, setExpandedNodeGroups } = useFlowContext.useFlowContext();
34
+ const [filterValue, setFilterValue] = React.useState("");
35
+ const [draggingLabel, setDraggingLabel] = React.useState();
46
36
  const labels = uikitReactCore.useLabels(DEFAULT_LABELS, labelsProps);
47
37
  const drawerElementId = uikitReactCore.useUniqueId(id);
48
- const groupsElementId = uikitReactCore.useUniqueId(id);
49
- const { setNodeRef } = core.useDroppable({
50
- id: drawerElementId
51
- });
38
+ const groupsElementId = uikitReactCore.useUniqueId();
39
+ const { setNodeRef } = core.useDroppable({ id: drawerElementId });
52
40
  const handleDragStart = (event) => {
53
41
  if (event.active.data.current?.hvFlow) {
54
42
  setDraggingLabel(event.active.data.current.hvFlow?.label);
@@ -61,34 +49,29 @@ const HvFlowSidebar = ({
61
49
  onDragEnd: handleDragEnd,
62
50
  onDragStart: handleDragStart
63
51
  });
64
- const handleSearch = (event, value) => {
65
- if (nodeGroups) {
66
- const gps = value ? Object.entries(unfilteredGroups).reduce((acc, curr) => {
67
- const filteredNodes = curr[1].nodes.filter(
68
- (obj) => obj.label.toLocaleLowerCase().includes(value.toLocaleLowerCase())
52
+ const filteredGroups = React.useMemo(() => {
53
+ if (!filterValue || !nodeGroups)
54
+ return nodeGroups || {};
55
+ return filterValue ? Object.entries(nodeGroups).reduce(
56
+ (acc, [groupId, group]) => {
57
+ const filteredItems = (group.items || []).filter(
58
+ (item) => item.label.toLowerCase().includes(filterValue.toLowerCase())
69
59
  );
70
- const nodesCount = filteredNodes.length;
71
- if (nodesCount > 0) {
72
- acc[curr[0]] = {
73
- ...curr[1],
74
- nodes: filteredNodes
60
+ const itemsCount = Object.keys(filteredItems).length;
61
+ if (itemsCount > 0) {
62
+ acc[groupId] = {
63
+ ...group,
64
+ items: filteredItems
75
65
  };
76
66
  }
77
67
  return acc;
78
- }, {}) : unfilteredGroups;
79
- setGroups(gps);
80
- setExpandedNodeGroups?.(value ? Object.keys(gps) : []);
81
- } else if (nodeTypes) {
82
- const filteredNodeTypes = {};
83
- for (const [key, node] of Object.entries(nodeTypes)) {
84
- if (node.meta?.label.toLocaleLowerCase().includes(value.toLocaleLowerCase())) {
85
- filteredNodeTypes[key] = node;
86
- }
87
- }
88
- setNdTypes(value ? filteredNodeTypes : nodeTypes);
89
- }
90
- };
91
- const handleDebouncedSearch = usehooksTs.useDebounceCallback(handleSearch, 500);
68
+ },
69
+ {}
70
+ ) : nodeGroups;
71
+ }, [filterValue, nodeGroups]);
72
+ React.useEffect(() => {
73
+ setExpandedNodeGroups?.(filterValue ? Object.keys(filteredGroups) : []);
74
+ }, [filterValue, filteredGroups, setExpandedNodeGroups]);
92
75
  return /* @__PURE__ */ jsxRuntime.jsxs(
93
76
  uikitReactCore.HvDrawer,
94
77
  {
@@ -118,39 +101,36 @@ const HvFlowSidebar = ({
118
101
  "aria-label": labels?.searchAriaLabel,
119
102
  "aria-controls": groupsElementId,
120
103
  "aria-owns": groupsElementId,
121
- onChange: handleDebouncedSearch,
104
+ onChange: (evt, val) => setFilterValue(val.trim()),
122
105
  inputProps: { autoComplete: "off" }
123
106
  }
124
107
  ),
125
- nodeGroups ? /* @__PURE__ */ jsxRuntime.jsx("ul", { id: groupsElementId, className: classes.groupsContainer, children: Object.entries(groups).map((obj) => {
108
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { id: groupsElementId, className: classes.groupsContainer, children: Object.entries(filteredGroups).map(([groupId, group]) => {
109
+ if (flatten) {
110
+ return (group.items || []).map((item, i) => /* @__PURE__ */ jsxRuntime.jsx(
111
+ DraggableSidebarGroupItem.HvFlowDraggableSidebarGroupItem,
112
+ {
113
+ "aria-roledescription": labels?.itemAriaRoleDescription,
114
+ ...item
115
+ },
116
+ `${item.nodeType}-${i}`
117
+ ));
118
+ }
126
119
  return /* @__PURE__ */ jsxRuntime.jsx(
127
120
  SidebarGroup.HvFlowSidebarGroup,
128
121
  {
129
- id: obj[0],
122
+ id: groupId,
130
123
  expandButtonProps: {
131
124
  "aria-label": labels?.expandGroupButtonAriaLabel
132
125
  },
133
126
  itemProps: {
134
127
  "aria-roledescription": labels?.itemAriaRoleDescription
135
128
  },
136
- ...obj[1]
137
- },
138
- obj[0]
139
- );
140
- }) }) : ndTypes && Object.entries(ndTypes).map((obj) => {
141
- return /* @__PURE__ */ jsxRuntime.jsx(
142
- DraggableSidebarGroupItem.HvFlowDraggableSidebarGroupItem,
143
- {
144
- id: obj[0],
145
- type: obj[0],
146
- label: obj[1]?.meta?.label || "",
147
- data: obj[1]?.meta?.data,
148
- "aria-roledescription": labels?.itemAriaRoleDescription,
149
- className: classes.nodeType
129
+ ...group
150
130
  },
151
- obj[0]
131
+ groupId
152
132
  );
153
- })
133
+ }) })
154
134
  ] })
155
135
  ] }),
156
136
  /* @__PURE__ */ jsxRuntime.jsx(core.DragOverlay, { modifiers: [modifiers.restrictToWindowEdges], ...dragOverlayProps, children: draggingLabel ? /* @__PURE__ */ jsxRuntime.jsx(SidebarGroupItem.HvFlowSidebarGroupItem, { label: draggingLabel, isDragging: true }) : null })
@@ -18,9 +18,6 @@ const { staticClasses, useClasses } = uikitReactCore.createClasses("HvFlowSideba
18
18
  flexDirection: "column",
19
19
  gap: uikitReactCore.theme.space.sm,
20
20
  listStyleType: "none"
21
- },
22
- nodeType: {
23
- marginBottom: uikitReactCore.theme.space.xs
24
21
  }
25
22
  });
26
23
  exports.staticClasses = staticClasses;
@@ -11,7 +11,7 @@ const DraggableSidebarGroupItem = require("./SidebarGroupItem/DraggableSidebarGr
11
11
  const HvFlowSidebarGroup = ({
12
12
  id,
13
13
  label,
14
- nodes,
14
+ items = [],
15
15
  color,
16
16
  description,
17
17
  icon,
@@ -22,19 +22,19 @@ const HvFlowSidebarGroup = ({
22
22
  const { classes, cx, css } = SidebarGroup_styles.useClasses(classesProp);
23
23
  const { expandedNodeGroups, setExpandedNodeGroups } = useFlowContext.useFlowContext();
24
24
  const opened = React.useMemo(
25
- () => !!expandedNodeGroups?.find((groupId) => groupId === id),
25
+ () => !!expandedNodeGroups?.find((group) => group === id),
26
26
  [expandedNodeGroups, id]
27
27
  );
28
28
  const handleClick = React.useCallback(() => {
29
29
  setExpandedNodeGroups?.(
30
- (prev) => opened ? prev.filter((groupId) => id !== groupId) : [...prev, id]
30
+ (prev) => opened ? prev.filter((group) => id !== group) : [...prev, id]
31
31
  );
32
32
  }, [id, opened, setExpandedNodeGroups]);
33
33
  return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: cx(css({ borderColor: uikitStyles.getColor(color) }), classes.root), children: [
34
34
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.titleContainer, children: [
35
35
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.labelContainer, children: [
36
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.icon, children: icon }),
37
- /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { component: "p", variant: "title4", children: nodes.length > 1 ? `${label} (${nodes.length})` : label })
36
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.icon, role: "presentation", children: icon }),
37
+ /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { component: "p", variant: "title4", children: Object.keys(items).length > 1 ? `${label} (${Object.keys(items).length})` : label })
38
38
  ] }),
39
39
  /* @__PURE__ */ jsxRuntime.jsx(
40
40
  uikitReactCore.HvButton,
@@ -48,13 +48,13 @@ const HvFlowSidebarGroup = ({
48
48
  )
49
49
  ] }),
50
50
  description && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.descriptionContainer, children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: description }) }),
51
- opened && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.itemsContainer, children: nodes.map((obj) => /* @__PURE__ */ jsxRuntime.jsx(
51
+ opened && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.itemsContainer, children: Object.entries(items).map(([itemId, item]) => /* @__PURE__ */ jsxRuntime.jsx(
52
52
  DraggableSidebarGroupItem.HvFlowDraggableSidebarGroupItem,
53
53
  {
54
54
  ...itemProps,
55
- ...obj
55
+ ...item
56
56
  },
57
- obj.type
57
+ itemId
58
58
  )) })
59
59
  ] });
60
60
  };
@@ -7,20 +7,20 @@ const utils = require("@mui/material/utils");
7
7
  const uikitReactCore = require("@hitachivantara/uikit-react-core");
8
8
  const SidebarGroupItem = require("./SidebarGroupItem.cjs");
9
9
  const HvFlowDraggableSidebarGroupItem = ({
10
- id,
10
+ id: idProp,
11
11
  label,
12
- type,
12
+ nodeType,
13
13
  data,
14
14
  ...others
15
15
  }) => {
16
16
  const itemRef = React.useRef(null);
17
- const elementId = uikitReactCore.useUniqueId(id);
17
+ const id = uikitReactCore.useUniqueId(idProp);
18
18
  const { attributes, listeners, setNodeRef, isDragging, transform } = core.useDraggable({
19
- id: elementId,
19
+ id,
20
20
  data: {
21
21
  hvFlow: {
22
22
  // Needed to know which item is being dragged and dropped
23
- type,
23
+ type: nodeType,
24
24
  // Needed for the drag overlay: otherwise the item is cut by the drawer because of overflow
25
25
  label,
26
26
  // Item position: used to position the item when dropped
@@ -5,32 +5,31 @@ const React = require("react");
5
5
  const uikitReactCore = require("@hitachivantara/uikit-react-core");
6
6
  const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
7
7
  const SidebarGroupItem_styles = require("./SidebarGroupItem.styles.cjs");
8
- const HvFlowSidebarGroupItem = React.forwardRef(
9
- ({
8
+ const HvFlowSidebarGroupItem = React.forwardRef((props, ref) => {
9
+ const {
10
10
  label,
11
11
  isDragging,
12
12
  classes: classesProp,
13
13
  className,
14
14
  ...others
15
- }, ref) => {
16
- const { classes, cx } = SidebarGroupItem_styles.useClasses(classesProp);
17
- return /* @__PURE__ */ jsxRuntime.jsxs(
18
- "div",
19
- {
20
- ref,
21
- className: cx(
22
- classes.root,
23
- { [classes.dragging]: isDragging },
24
- className
25
- ),
26
- ...others,
27
- children: [
28
- /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: label }),
29
- /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Drag, {})
30
- ]
31
- }
32
- );
33
- }
34
- );
15
+ } = props;
16
+ const { classes, cx } = SidebarGroupItem_styles.useClasses(classesProp);
17
+ return /* @__PURE__ */ jsxRuntime.jsxs(
18
+ "div",
19
+ {
20
+ ref,
21
+ className: cx(
22
+ classes.root,
23
+ { [classes.dragging]: isDragging },
24
+ className
25
+ ),
26
+ ...others,
27
+ children: [
28
+ /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: label }),
29
+ /* @__PURE__ */ jsxRuntime.jsx(uikitReactIcons.Drag, {})
30
+ ]
31
+ }
32
+ );
33
+ });
35
34
  exports.flowSidebarGroupItemClasses = SidebarGroupItem_styles.staticClasses;
36
35
  exports.HvFlowSidebarGroupItem = HvFlowSidebarGroupItem;
@@ -10,7 +10,6 @@ import { useClasses } from "./Flow.styles.js";
10
10
  import { staticClasses } from "./Flow.styles.js";
11
11
  import { useNodeMetaRegistry } from "./FlowContext/NodeMetaContext.js";
12
12
  import { useFlowInstance } from "./hooks/useFlowInstance.js";
13
- import { useFlowContext } from "./hooks/useFlowContext.js";
14
13
  const getNode = (nodes, nodeId) => {
15
14
  return nodes.find((n) => n.id === nodeId);
16
15
  };
@@ -33,8 +32,8 @@ const validateEdge = (nodes, edges, connection, nodeMetaRegistry) => {
33
32
  return false;
34
33
  const inputs = nodeMetaRegistry[targetId]?.inputs || [];
35
34
  const outputs = nodeMetaRegistry[sourceId]?.outputs || [];
36
- const source = outputs.map((out) => out.outputs || out).flat().find((out) => out.id === sourceHandle);
37
- const target = inputs.map((inp) => inp.inputs || inp).flat().find((inp) => inp.id === targetHandle);
35
+ const source = outputs.flatMap((out) => out.outputs || out).find((out) => out.id === sourceHandle);
36
+ const target = inputs.flatMap((inp) => inp.inputs || inp).find((inp) => inp.id === targetHandle);
38
37
  const sourceProvides = source?.provides || "";
39
38
  const targetAccepts = target?.accepts || [];
40
39
  const sourceMaxConnections = source?.maxConnections;
@@ -67,12 +66,12 @@ const HvDroppableFlow = ({
67
66
  onNodesChange: onNodesChangeProp,
68
67
  onEdgesChange: onEdgesChangeProp,
69
68
  defaultEdgeOptions: defaultEdgeOptionsProp,
69
+ nodeTypes,
70
70
  ...others
71
71
  }) => {
72
72
  const { classes, cx } = useClasses(classesProp);
73
73
  const elementId = useUniqueId(id);
74
74
  const reactFlowInstance = useFlowInstance();
75
- const { nodeTypes } = useFlowContext();
76
75
  const [nodes, setNodes] = useState(initialNodes);
77
76
  const [edges, setEdges] = useState(initialEdges);
78
77
  const nodesRef = useRef(initialNodes);
@@ -101,7 +100,10 @@ const HvDroppableFlow = ({
101
100
  x: hvFlow?.x || 0,
102
101
  y: hvFlow?.y || 0
103
102
  });
104
- const data = hvFlow?.data || {};
103
+ const data = {
104
+ nodeLabel: hvFlow?.label,
105
+ ...hvFlow?.data
106
+ };
105
107
  const newNode = {
106
108
  id: uid(),
107
109
  position,
@@ -1 +1 @@
1
- {"version":3,"file":"DroppableFlow.js","sources":["../../../src/Flow/DroppableFlow.tsx"],"sourcesContent":["import { useCallback, useRef, useState } from \"react\";\nimport { DragEndEvent, useDndMonitor, useDroppable } from \"@dnd-kit/core\";\nimport { Global } from \"@emotion/react\";\nimport ReactFlow, {\n addEdge,\n applyEdgeChanges,\n applyNodeChanges,\n Connection,\n Edge,\n EdgeChange,\n MarkerType,\n Node,\n NodeChange,\n ReactFlowProps,\n} from \"reactflow\";\nimport { uid } from \"uid\";\nimport { ExtractNames, useUniqueId } from \"@hitachivantara/uikit-react-core\";\n\nimport { flowStyles } from \"./base\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useNodeMetaRegistry } from \"./FlowContext/NodeMetaContext\";\nimport { useFlowContext, useFlowInstance } from \"./hooks\";\nimport {\n HvFlowNodeInputGroup,\n HvFlowNodeMetaRegistry,\n HvFlowNodeOutputGroup,\n} from \"./types\";\n\nexport { staticClasses as flowClasses };\n\nexport type HvFlowClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvDroppableFlowProps<\n NodeType extends string | undefined = string | undefined,\n NodeData = any,\n> extends Omit<ReactFlowProps, \"nodes\" | \"edges\" | \"nodeTypes\"> {\n /** Flow content: background, controls, and minimap. */\n children?: React.ReactNode;\n /** Flow nodes. */\n nodes?: Node<NodeData, NodeType>[];\n /** Flow edges. */\n edges?: Edge[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowClasses;\n /** Callback called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n /**\n * Callback called when a node is dropped in the flow.\n *\n * This callback should be used to override the custom UI Kit drop event.\n * Thus, when defined, the user is responsible for adding nodes to the flow.\n *\n * This callback is called when `HvFlowSidebar` is used or a custom sidebar was created using Dnd Kit.\n * When a custom sidebar was created using the native HTML drag and drop API, refer to the `onDrop` callback.\n *\n * Returns the event and the node to be added to the flow.\n */\n onDndDrop?: (event: DragEndEvent, node: Node) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdge = (\n nodes: Node[],\n edges: Edge[],\n connection: Connection,\n nodeMetaRegistry: HvFlowNodeMetaRegistry,\n) => {\n const {\n source: sourceId,\n sourceHandle,\n target: targetId,\n targetHandle,\n } = connection;\n\n if (!sourceHandle || !targetHandle || !sourceId || !targetId) return false;\n\n const sourceNode = getNode(nodes, sourceId);\n const targetNode = getNode(nodes, targetId);\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[targetId]?.inputs || [];\n const outputs = nodeMetaRegistry[sourceId]?.outputs || [];\n\n const source = outputs\n .map((out) => (out as HvFlowNodeOutputGroup).outputs || out)\n .flat()\n .find((out) => out.id === sourceHandle);\n const target = inputs\n .map((inp) => (inp as HvFlowNodeInputGroup).inputs || inp)\n .flat()\n .find((inp) => inp.id === targetHandle);\n\n const sourceProvides = source?.provides || \"\";\n const targetAccepts = target?.accepts || [];\n const sourceMaxConnections = source?.maxConnections;\n const targetMaxConnections = target?.maxConnections;\n\n let isValid =\n targetAccepts.length === 0 || targetAccepts.includes(sourceProvides);\n\n if (isValid && targetMaxConnections != null) {\n const targetConnections = edges.filter(\n (edg) => edg.target === targetId && edg.targetHandle === targetHandle,\n ).length;\n\n isValid = targetConnections < targetMaxConnections;\n }\n\n if (isValid && sourceMaxConnections != null) {\n const sourceConnections = edges.filter(\n (edg) => edg.source === sourceId && edg.sourceHandle === sourceHandle,\n ).length;\n\n isValid = sourceConnections < sourceMaxConnections;\n }\n\n return isValid;\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n onDndDrop,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n defaultEdgeOptions: defaultEdgeOptionsProp,\n ...others\n}: HvDroppableFlowProps) => {\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id);\n\n const reactFlowInstance = useFlowInstance();\n\n const { nodeTypes } = useFlowContext();\n\n const [nodes, setNodes] = useState(initialNodes);\n const [edges, setEdges] = useState(initialEdges);\n // Keeping track of nodes and edges for onFlowChange since useState is async\n const nodesRef = useRef(initialNodes);\n const edgesRef = useRef(initialEdges);\n\n const updateNodes = (nds: Node[]) => {\n setNodes(nds);\n nodesRef.current = nds;\n };\n\n const updateEdges = (eds: Edge[]) => {\n setEdges(eds);\n edgesRef.current = eds;\n };\n\n const { setNodeRef } = useDroppable({\n id: elementId,\n });\n\n const handleDragEnd = useCallback(\n (event: DragEndEvent) => {\n if (event.over?.id !== elementId) return;\n\n const hvFlow = event.active.data.current?.hvFlow;\n const type = hvFlow?.type;\n\n // Only known node types can be dropped in the canvas\n if (!type || !nodeTypes?.[type]) {\n if (import.meta.env.DEV) {\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 return;\n }\n\n // Position node in the flow\n const position = reactFlowInstance.screenToFlowPosition({\n x: hvFlow?.x || 0,\n y: hvFlow?.y || 0,\n });\n\n // Node data\n const data = 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 updateNodes(nodes.concat(newNode));\n },\n [elementId, nodeTypes, nodes, onDndDrop, reactFlowInstance],\n );\n\n useDndMonitor({\n onDragEnd: handleDragEnd,\n });\n\n const handleFlowChange = useCallback(\n (nds: Node[], eds: Edge[]) => {\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, edgesRef.current);\n updateEdges(eds);\n\n handleFlowChange(nodesRef.current, eds);\n onConnectProp?.(connection);\n },\n [handleFlowChange, onConnectProp],\n );\n\n const handleNodesChange = useCallback(\n (changes: NodeChange[]) => {\n const nds = applyNodeChanges(changes, nodesRef.current);\n updateNodes(nds);\n\n handleFlowChange(nds, edgesRef.current);\n onNodesChangeProp?.(changes);\n },\n [handleFlowChange, onNodesChangeProp],\n );\n\n const handleEdgesChange = useCallback(\n (changes: EdgeChange[]) => {\n const eds = applyEdgeChanges(changes, edgesRef.current);\n updateEdges(eds);\n\n handleFlowChange(nodesRef.current, eds);\n onEdgesChangeProp?.(changes);\n },\n [handleFlowChange, onEdgesChangeProp],\n );\n\n const { registry } = useNodeMetaRegistry();\n\n const isValidConnection: ReactFlowProps[\"isValidConnection\"] = (connection) =>\n validateEdge(nodes, edges, connection, registry);\n\n const defaultEdgeOptions = {\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n type: \"smoothstep\",\n pathOptions: {\n borderRadius: 40,\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 snapGrid={[1, 1]}\n snapToGrid\n onError={(code, message) => {\n if (import.meta.env.DEV) {\n // eslint-disable-next-line no-console\n console.error(message);\n }\n }}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AA4Da,MAAA,UAAU,CAAC,OAAe,WAAmB;AACxD,SAAO,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM;AAC1C;AAEA,MAAM,eAAe,CACnB,OACA,OACA,YACA,qBACG;AACG,QAAA;AAAA,IACJ,QAAQ;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,EACE,IAAA;AAEJ,MAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,YAAY,CAAC;AAAiB,WAAA;AAE/D,QAAA,aAAa,QAAQ,OAAO,QAAQ;AACpC,QAAA,aAAa,QAAQ,OAAO,QAAQ;AAEtC,MAAA,CAAC,cAAc,CAAC;AAAmB,WAAA;AAEvC,QAAM,aAAa,WAAW;AAC9B,QAAM,aA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J,KAAK;AAAA,QACL,WAAW,GAAG,QAAQ,MAAM,SAAS;AAAA,QAErC,UAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC;AAAA,YACA;AAAA,YACA;AAAA,YACA,eAAe;AAAA,YACf,eAAe;AAAA,YACf,WAAW;AAAA,YACX;AAAA,YACA;AAAA,YACA,UAAU,CAAC,GAAG,CAAC;AAAA,YACf,YAAU;AAAA,YACV,SAAS,CAAC,MAAM,YAAY;AAAA,YAK5B;AAAA,YACC,GAAG;AAAA,YAEH;AAAA,UAAA;AAAA,QACH;AAAA,MAAA;AAAA,IACF;AAAA,EACF,EAAA,CAAA;AAEJ;"}
1
+ {"version":3,"file":"DroppableFlow.js","sources":["../../../src/Flow/DroppableFlow.tsx"],"sourcesContent":["import { useCallback, useRef, useState } from \"react\";\nimport { DragEndEvent, useDndMonitor, useDroppable } from \"@dnd-kit/core\";\nimport { Global } from \"@emotion/react\";\nimport ReactFlow, {\n addEdge,\n applyEdgeChanges,\n applyNodeChanges,\n Connection,\n Edge,\n EdgeChange,\n MarkerType,\n Node,\n NodeChange,\n ReactFlowProps,\n} from \"reactflow\";\nimport { uid } from \"uid\";\nimport { ExtractNames, useUniqueId } from \"@hitachivantara/uikit-react-core\";\n\nimport { flowStyles } from \"./base\";\nimport { staticClasses, useClasses } from \"./Flow.styles\";\nimport { useNodeMetaRegistry } from \"./FlowContext/NodeMetaContext\";\nimport { useFlowInstance } from \"./hooks\";\nimport {\n HvFlowNodeInputGroup,\n HvFlowNodeMetaRegistry,\n HvFlowNodeOutputGroup,\n HvFlowNodeTypes,\n} from \"./types\";\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 types. */\n nodeTypes?: HvFlowNodeTypes<NodeData>;\n /** Flow nodes. */\n nodes?: Node<NodeData, NodeType>[];\n /** Flow edges. */\n edges?: Edge[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowClasses;\n /** Callback called when the flow changes. Returns the updated nodes and edges. */\n onFlowChange?: (nodes: Node<NodeData, NodeType>[], edges: Edge[]) => void;\n /**\n * Callback called when a node is dropped in the flow.\n *\n * This callback should be used to override the custom UI Kit drop event.\n * Thus, when defined, the user is responsible for adding nodes to the flow.\n *\n * This callback is called when `HvFlowSidebar` is used or a custom sidebar was created using Dnd Kit.\n * When a custom sidebar was created using the native HTML drag and drop API, refer to the `onDrop` callback.\n *\n * Returns the event and the node to be added to the flow.\n */\n onDndDrop?: (event: DragEndEvent, node: Node) => void;\n}\n\nexport const getNode = (nodes: Node[], nodeId: string) => {\n return nodes.find((n) => n.id === nodeId);\n};\n\nconst validateEdge = (\n nodes: Node[],\n edges: Edge[],\n connection: Connection,\n nodeMetaRegistry: HvFlowNodeMetaRegistry,\n) => {\n const {\n source: sourceId,\n sourceHandle,\n target: targetId,\n targetHandle,\n } = connection;\n\n if (!sourceHandle || !targetHandle || !sourceId || !targetId) return false;\n\n const sourceNode = getNode(nodes, sourceId);\n const targetNode = getNode(nodes, targetId);\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[targetId]?.inputs || [];\n const outputs = nodeMetaRegistry[sourceId]?.outputs || [];\n\n const source = outputs\n .flatMap((out) => (out as HvFlowNodeOutputGroup).outputs || out)\n .find((out) => out.id === sourceHandle);\n const target = inputs\n .flatMap((inp) => (inp as HvFlowNodeInputGroup).inputs || inp)\n .find((inp) => inp.id === targetHandle);\n\n const sourceProvides = source?.provides || \"\";\n const targetAccepts = target?.accepts || [];\n const sourceMaxConnections = source?.maxConnections;\n const targetMaxConnections = target?.maxConnections;\n\n let isValid =\n targetAccepts.length === 0 || targetAccepts.includes(sourceProvides);\n\n if (isValid && targetMaxConnections != null) {\n const targetConnections = edges.filter(\n (edg) => edg.target === targetId && edg.targetHandle === targetHandle,\n ).length;\n\n isValid = targetConnections < targetMaxConnections;\n }\n\n if (isValid && sourceMaxConnections != null) {\n const sourceConnections = edges.filter(\n (edg) => edg.source === sourceId && edg.sourceHandle === sourceHandle,\n ).length;\n\n isValid = sourceConnections < sourceMaxConnections;\n }\n\n return isValid;\n};\n\nexport const HvDroppableFlow = ({\n id,\n className,\n children,\n onFlowChange,\n onDndDrop,\n classes: classesProp,\n nodes: initialNodes = [],\n edges: initialEdges = [],\n onConnect: onConnectProp,\n onNodesChange: onNodesChangeProp,\n onEdgesChange: onEdgesChangeProp,\n defaultEdgeOptions: defaultEdgeOptionsProp,\n nodeTypes,\n ...others\n}: HvDroppableFlowProps) => {\n const { classes, cx } = useClasses(classesProp);\n\n const elementId = useUniqueId(id);\n\n const reactFlowInstance = useFlowInstance();\n\n const [nodes, setNodes] = useState(initialNodes);\n const [edges, setEdges] = useState(initialEdges);\n // Keeping track of nodes and edges for onFlowChange since useState is async\n const nodesRef = useRef(initialNodes);\n const edgesRef = useRef(initialEdges);\n\n const updateNodes = (nds: Node[]) => {\n setNodes(nds);\n nodesRef.current = nds;\n };\n\n const updateEdges = (eds: Edge[]) => {\n setEdges(eds);\n edgesRef.current = eds;\n };\n\n const { setNodeRef } = useDroppable({\n id: elementId,\n });\n\n const handleDragEnd = useCallback(\n (event: DragEndEvent) => {\n if (event.over?.id !== elementId) return;\n\n const hvFlow = event.active.data.current?.hvFlow;\n const type = hvFlow?.type;\n\n // Only known node types can be dropped in the canvas\n if (!type || !nodeTypes?.[type]) {\n if (import.meta.env.DEV) {\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 return;\n }\n\n // Position node in the flow\n const position = reactFlowInstance.screenToFlowPosition({\n x: hvFlow?.x || 0,\n y: hvFlow?.y || 0,\n });\n\n // Node data\n const data = {\n nodeLabel: hvFlow?.label,\n ...hvFlow?.data,\n };\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 updateNodes(nodes.concat(newNode));\n },\n [elementId, nodeTypes, nodes, onDndDrop, reactFlowInstance],\n );\n\n useDndMonitor({\n onDragEnd: handleDragEnd,\n });\n\n const handleFlowChange = useCallback(\n (nds: Node[], eds: Edge[]) => {\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, edgesRef.current);\n updateEdges(eds);\n\n handleFlowChange(nodesRef.current, eds);\n onConnectProp?.(connection);\n },\n [handleFlowChange, onConnectProp],\n );\n\n const handleNodesChange = useCallback(\n (changes: NodeChange[]) => {\n const nds = applyNodeChanges(changes, nodesRef.current);\n updateNodes(nds);\n\n handleFlowChange(nds, edgesRef.current);\n onNodesChangeProp?.(changes);\n },\n [handleFlowChange, onNodesChangeProp],\n );\n\n const handleEdgesChange = useCallback(\n (changes: EdgeChange[]) => {\n const eds = applyEdgeChanges(changes, edgesRef.current);\n updateEdges(eds);\n\n handleFlowChange(nodesRef.current, eds);\n onEdgesChangeProp?.(changes);\n },\n [handleFlowChange, onEdgesChangeProp],\n );\n\n const { registry } = useNodeMetaRegistry();\n\n const isValidConnection: ReactFlowProps[\"isValidConnection\"] = (connection) =>\n validateEdge(nodes, edges, connection, registry);\n\n const defaultEdgeOptions = {\n markerEnd: {\n type: MarkerType.ArrowClosed,\n height: 20,\n width: 20,\n },\n type: \"smoothstep\",\n pathOptions: {\n borderRadius: 40,\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 snapGrid={[1, 1]}\n snapToGrid\n onError={(code, message) => {\n if (import.meta.env.DEV) {\n // eslint-disable-next-line no-console\n console.error(message);\n }\n }}\n {...others}\n >\n {children}\n </ReactFlow>\n </div>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA+Da,MAAA,UAAU,CAAC,OAAe,WAAmB;AACxD,SAAO,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM;AAC1C;AAEA,MAAM,eAAe,CACnB,OACA,OACA,YACA,qBACG;AACG,QAAA;AAAA,IACJ,QAAQ;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,EACE,IAAA;AAEJ,MAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,YAAY,CAAC;AAAiB,WAAA;AAE/D,QAAA,aAAa,QAAQ,OAAO,QAAQ;AACpC,QAAA,aAAa,QAAQ,OAAO,QAAQ;AAEtC,MAAA,CAAC,cAAc,CAAC;AAAmB,WAAA;AAEvC,QAAM,aAAa,WAAW;AAC9B,QAAM,aAAa,WAAW;AAE1B,MAAA,CAAC,cAAc,CAAC;AAAmB,WAAA;AAEvC,QAAM,SAAS,iBAAiB,QAAQ,GAAG,UAAU,CAAA;AACrD,QAAM,UAAU,iBAAiB,QAAQ,GAAG,WAAW,CAAA;AAEvD,QAAM,SAAS,QACZ,QAAQ,CAAC,QAAS,IAA8B,WAAW,GAAG,EAC9D,KAAK,CAAC,QAAQ,IAAI,OAAO,YAAY;AACxC,QAAM,SAAS,OACZ,QAAQ,CAAC,QAAS,IAA6B,UAAU,GAAG,EAC5D,KAAK,CAAC,QAAQ,IAAI,OAAO,YAAY;AAElC,QAAA,iBA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A,EACF,EAAA,CAAA;AAEJ;"}
@@ -5,7 +5,6 @@ import { ReactFlowProvider } from "reactflow";
5
5
  import { HvDroppableFlow } from "./DroppableFlow.js";
6
6
  import { HvFlowProvider } from "./FlowContext/FlowContext.js";
7
7
  const HvFlow = ({
8
- nodeTypes,
9
8
  nodeGroups,
10
9
  sidebar,
11
10
  defaultActions,
@@ -16,26 +15,18 @@ const HvFlow = ({
16
15
  useSensor(PointerSensor),
17
16
  useSensor(KeyboardSensor)
18
17
  );
19
- return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(
20
- HvFlowProvider,
18
+ return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(HvFlowProvider, { nodeGroups, defaultActions, children: /* @__PURE__ */ jsxs(
19
+ DndContext,
21
20
  {
22
- nodeGroups,
23
- nodeTypes,
24
- defaultActions,
25
- children: /* @__PURE__ */ jsxs(
26
- DndContext,
27
- {
28
- sensors,
29
- modifiers: [restrictToWindowEdges],
30
- ...dndContextProps,
31
- children: [
32
- /* @__PURE__ */ jsx(HvDroppableFlow, { ...others }),
33
- sidebar
34
- ]
35
- }
36
- )
21
+ sensors,
22
+ modifiers: [restrictToWindowEdges],
23
+ ...dndContextProps,
24
+ children: [
25
+ /* @__PURE__ */ jsx(HvDroppableFlow, { ...others }),
26
+ sidebar
27
+ ]
37
28
  }
38
- ) });
29
+ ) }) });
39
30
  };
40
31
  export {
41
32
  HvFlow