@hitachivantara/uikit-react-lab 6.1.9 → 6.1.10

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 (68) hide show
  1. package/dist/Blade/Blade.js +134 -173
  2. package/dist/Blade/Blade.styles.js +54 -69
  3. package/dist/Blades/Blades.js +70 -101
  4. package/dist/Blades/Blades.styles.js +7 -10
  5. package/dist/Dashboard/Dashboard.js +57 -60
  6. package/dist/Dashboard/Dashboard.styles.js +6 -10
  7. package/dist/Flow/Background/Background.js +10 -16
  8. package/dist/Flow/Controls/Controls.js +77 -91
  9. package/dist/Flow/DroppableFlow.js +135 -200
  10. package/dist/Flow/Empty/Empty.js +12 -9
  11. package/dist/Flow/Empty/Empty.styles.js +12 -15
  12. package/dist/Flow/Flow.js +28 -30
  13. package/dist/Flow/Flow.styles.js +12 -18
  14. package/dist/Flow/FlowContext/FlowContext.js +22 -23
  15. package/dist/Flow/FlowContext/NodeMetaContext.js +36 -39
  16. package/dist/Flow/Minimap/Minimap.js +15 -28
  17. package/dist/Flow/Minimap/Minimap.styles.js +4 -9
  18. package/dist/Flow/Node/BaseNode.js +144 -190
  19. package/dist/Flow/Node/BaseNode.styles.js +122 -133
  20. package/dist/Flow/Node/Node.js +90 -108
  21. package/dist/Flow/Node/Node.styles.js +30 -40
  22. package/dist/Flow/Node/Parameters/ParamRenderer.js +17 -14
  23. package/dist/Flow/Node/Parameters/Select.js +33 -38
  24. package/dist/Flow/Node/Parameters/Slider.js +27 -29
  25. package/dist/Flow/Node/Parameters/Text.js +17 -17
  26. package/dist/Flow/Node/utils.js +44 -49
  27. package/dist/Flow/Sidebar/Sidebar.js +115 -137
  28. package/dist/Flow/Sidebar/Sidebar.styles.js +21 -22
  29. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroup.js +57 -60
  30. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroup.styles.js +27 -33
  31. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.js +27 -47
  32. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.js +14 -32
  33. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.styles.js +17 -23
  34. package/dist/Flow/base.js +5 -5
  35. package/dist/Flow/hooks/useFlowContext.js +5 -5
  36. package/dist/Flow/hooks/useFlowInstance.js +5 -4
  37. package/dist/Flow/hooks/useFlowNode.js +92 -113
  38. package/dist/Flow/hooks/useFlowNodeMeta.js +7 -7
  39. package/dist/Flow/hooks/useNode.js +136 -154
  40. package/dist/Flow/hooks/useNodeId.js +8 -7
  41. package/dist/Flow/nodes/DashboardNode.js +64 -86
  42. package/dist/Flow/nodes/DashboardNode.styles.js +8 -14
  43. package/dist/Flow/nodes/StickyNode.js +370 -435
  44. package/dist/StepNavigation/DefaultNavigation/DefaultNavigation.js +36 -52
  45. package/dist/StepNavigation/DefaultNavigation/Step/Step.js +40 -51
  46. package/dist/StepNavigation/DefaultNavigation/Step/Step.styles.js +22 -33
  47. package/dist/StepNavigation/DefaultNavigation/utils.js +38 -30
  48. package/dist/StepNavigation/SimpleNavigation/Dot/Dot.js +24 -41
  49. package/dist/StepNavigation/SimpleNavigation/Dot/Dot.styles.js +13 -16
  50. package/dist/StepNavigation/SimpleNavigation/SimpleNavigation.js +35 -47
  51. package/dist/StepNavigation/SimpleNavigation/utils.js +10 -11
  52. package/dist/StepNavigation/StepNavigation.js +136 -179
  53. package/dist/StepNavigation/StepNavigation.styles.js +29 -32
  54. package/dist/Wizard/Wizard.js +81 -104
  55. package/dist/Wizard/Wizard.styles.js +4 -7
  56. package/dist/Wizard/WizardActions/WizardActions.js +111 -131
  57. package/dist/Wizard/WizardActions/WizardActions.styles.js +19 -20
  58. package/dist/Wizard/WizardContainer/WizardContainer.js +19 -28
  59. package/dist/Wizard/WizardContainer/WizardContainer.styles.js +8 -14
  60. package/dist/Wizard/WizardContent/WizardContent.js +103 -120
  61. package/dist/Wizard/WizardContent/WizardContent.styles.js +33 -36
  62. package/dist/Wizard/WizardContext/WizardContext.js +10 -13
  63. package/dist/Wizard/WizardTitle/WizardTitle.js +74 -79
  64. package/dist/Wizard/WizardTitle/WizardTitle.styles.js +12 -15
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +30 -81
  67. package/package.json +6 -6
  68. package/dist/StepNavigation/utils.js +0 -8
package/dist/Flow/base.js CHANGED
@@ -1,6 +1,7 @@
1
- import { css } from "@emotion/react";
2
1
  import { theme } from "@hitachivantara/uikit-react-core";
3
- const flowStyles = css`
2
+ import { css } from "@emotion/react";
3
+ //#region src/Flow/base.ts
4
+ var flowStyles = css`
4
5
  /* this gets exported as style.css and can be used for the default theming */
5
6
  /* these are the necessary styles for React Flow, they get used by base.css and style.css */
6
7
  .react-flow__container {
@@ -406,6 +407,5 @@ const flowStyles = css`
406
407
  top: 100%;
407
408
  }
408
409
  `;
409
- export {
410
- flowStyles
411
- };
410
+ //#endregion
411
+ export { flowStyles };
@@ -1,6 +1,6 @@
1
- import { useContext } from "react";
2
1
  import { HvFlowContext } from "../FlowContext/FlowContext.js";
3
- const useFlowContext = () => useContext(HvFlowContext);
4
- export {
5
- useFlowContext
6
- };
2
+ import { useContext } from "react";
3
+ //#region src/Flow/hooks/useFlowContext.ts
4
+ var useFlowContext = () => useContext(HvFlowContext);
5
+ //#endregion
6
+ export { useFlowContext };
@@ -1,7 +1,8 @@
1
1
  import { useReactFlow } from "reactflow";
2
+ //#region src/Flow/hooks/useFlowInstance.ts
3
+ /** Retrieves the React Flow instance */
2
4
  function useFlowInstance() {
3
- return useReactFlow();
5
+ return useReactFlow();
4
6
  }
5
- export {
6
- useFlowInstance
7
- };
7
+ //#endregion
8
+ export { useFlowInstance };
@@ -1,134 +1,113 @@
1
- import { useMemo, useCallback } from "react";
2
- import { useNodes, useEdges, useStore } from "reactflow";
3
- import { shallow } from "zustand/shallow";
4
1
  import { useFlowInstance } from "./useFlowInstance.js";
5
- import { useNodeId } from "./useNodeId.js";
2
+ import { useNodeId as useNodeId$1 } from "./useNodeId.js";
3
+ import { useCallback, useMemo } from "react";
4
+ import { useEdges, useNodes, useStore } from "reactflow";
5
+ import { shallow } from "zustand/shallow";
6
+ //#region src/Flow/hooks/useFlowNode.ts
7
+ /** Uses coordinates to create the relative position vector */
6
8
  function relativePosition(positionA, positionB) {
7
- if (positionA && positionB)
8
- return {
9
- x: positionB.x - positionA.x,
10
- y: positionB.y - positionA.y
11
- };
12
- return { x: 0, y: 0 };
9
+ if (positionA && positionB) return {
10
+ x: positionB.x - positionA.x,
11
+ y: positionB.y - positionA.y
12
+ };
13
+ return {
14
+ x: 0,
15
+ y: 0
16
+ };
13
17
  }
18
+ /** Retrieves the node instance */
14
19
  function useFlowNode(id) {
15
- const nodeId = useNodeId(id);
16
- const nodeSelector = useCallback(
17
- (state) => state.getNodes().find((n) => n.id === nodeId),
18
- [nodeId]
19
- );
20
- return useStore(nodeSelector, shallow);
20
+ const nodeId = useNodeId$1(id);
21
+ return useStore(useCallback((state) => state.getNodes().find((n) => n.id === nodeId), [nodeId]), shallow);
21
22
  }
23
+ /** Provides the input edges connected to the node */
22
24
  function useFlowNodeInputEdges(id) {
23
- const nodeId = useNodeId(id);
24
- const inputEdgesSelector = useCallback(
25
- (state) => state.edges.filter((e) => e.target === nodeId),
26
- [nodeId]
27
- );
28
- return useStore(inputEdgesSelector, shallow);
25
+ const nodeId = useNodeId$1(id);
26
+ return useStore(useCallback((state) => state.edges.filter((e) => e.target === nodeId), [nodeId]), shallow);
29
27
  }
28
+ /** Gives the output edges connected from the node */
30
29
  function useFlowNodeOutputEdges(id) {
31
- const nodeId = useNodeId(id);
32
- const outputEdgesSelector = useCallback(
33
- (state) => state.edges.filter((e) => e.source === nodeId),
34
- [nodeId]
35
- );
36
- return useStore(outputEdgesSelector, shallow);
30
+ const nodeId = useNodeId$1(id);
31
+ return useStore(useCallback((state) => state.edges.filter((e) => e.source === nodeId), [nodeId]), shallow);
37
32
  }
33
+ /** Offers both input and output edges of the node */
38
34
  function useFlowNodeEdges(id) {
39
- const nodeId = useNodeId(id);
40
- const edgesSelector = useCallback(
41
- (state) => state.edges.filter(
42
- (e) => e.source === nodeId || e.target === nodeId
43
- ),
44
- [nodeId]
45
- );
46
- return useStore(edgesSelector, shallow);
35
+ const nodeId = useNodeId$1(id);
36
+ return useStore(useCallback((state) => state.edges.filter((e) => e.source === nodeId || e.target === nodeId), [nodeId]), shallow);
47
37
  }
38
+ /** Gets the parent nodes of a specified node (nodes that have an output connected to one of the inputs of the node) */
48
39
  function useFlowNodeParents(id) {
49
- const inputEdges = useFlowNodeInputEdges(id);
50
- const parentNodesSelector = useCallback(
51
- (state) => {
52
- return inputEdges.map((e) => state.getNodes().find((n) => n.id === e.source)).filter((n) => n !== null);
53
- },
54
- [inputEdges]
55
- );
56
- return useStore(parentNodesSelector, shallow);
40
+ const inputEdges = useFlowNodeInputEdges(id);
41
+ return useStore(useCallback((state) => {
42
+ return inputEdges.map((e) => state.getNodes().find((n) => n.id === e.source)).filter((n) => n !== null);
43
+ }, [inputEdges]), shallow);
57
44
  }
45
+ /** Retrieves the nodes connected to the inputs of the node */
58
46
  function useFlowInputNodes(id) {
59
- const nodeId = useNodeId(id);
60
- const nodes = useNodes();
61
- const edges = useEdges();
62
- return useMemo(() => {
63
- return edges.filter((e) => e.target === nodeId).map((e) => nodes.find((n) => n.id === e.source)).filter((n) => n !== null);
64
- }, [edges, nodeId, nodes]);
47
+ const nodeId = useNodeId$1(id);
48
+ const nodes = useNodes();
49
+ const edges = useEdges();
50
+ return useMemo(() => {
51
+ return edges.filter((e) => e.target === nodeId).map((e) => nodes.find((n) => n.id === e.source)).filter((n) => n !== null);
52
+ }, [
53
+ edges,
54
+ nodeId,
55
+ nodes
56
+ ]);
65
57
  }
58
+ /** Retrieves the nodes connected to the outputs of the node */
66
59
  function useFlowOutputNodes(id) {
67
- const nodeId = useNodeId(id);
68
- const nodes = useNodes();
69
- const edges = useEdges();
70
- return useMemo(() => {
71
- return edges.filter((e) => e.source === nodeId).map((e) => nodes.find((n) => n.id === e.target)).filter((n) => n !== null);
72
- }, [edges, nodeId, nodes]);
60
+ const nodeId = useNodeId$1(id);
61
+ const nodes = useNodes();
62
+ const edges = useEdges();
63
+ return useMemo(() => {
64
+ return edges.filter((e) => e.source === nodeId).map((e) => nodes.find((n) => n.id === e.target)).filter((n) => n !== null);
65
+ }, [
66
+ edges,
67
+ nodeId,
68
+ nodes
69
+ ]);
73
70
  }
71
+ /** Utilities to manipulate a node in the flow */
74
72
  function useFlowNodeUtils(id) {
75
- const nodeId = useNodeId(id);
76
- const reactFlowInstance = useFlowInstance();
77
- const setNodeData = useCallback(
78
- (setNewData) => {
79
- if (!nodeId) return;
80
- reactFlowInstance.setNodes((nodes) => {
81
- return nodes.map((n) => {
82
- if (n.id === nodeId) {
83
- return { ...n, data: setNewData(n.data) };
84
- }
85
- return n;
86
- });
87
- });
88
- },
89
- [nodeId, reactFlowInstance]
90
- );
91
- const setNodeParent = useCallback(
92
- (node, extent) => {
93
- if (!nodeId) return;
94
- reactFlowInstance.setNodes((nodes) => {
95
- return nodes.map((n) => {
96
- if (n.id === nodeId) {
97
- return {
98
- ...n,
99
- parentId: node ? node.id : void 0,
100
- extent,
101
- position: node ? relativePosition(node.position, n.position) : n.positionAbsolute ?? n.position
102
- };
103
- }
104
- return n;
105
- });
106
- });
107
- },
108
- [nodeId, reactFlowInstance]
109
- );
110
- return useMemo(
111
- () => ({
112
- setNodeData,
113
- setNodeParent
114
- }),
115
- [setNodeData, setNodeParent]
116
- );
73
+ const nodeId = useNodeId$1(id);
74
+ const reactFlowInstance = useFlowInstance();
75
+ /** Mutate the node's `.data` object */
76
+ const setNodeData = useCallback((setNewData) => {
77
+ if (!nodeId) return;
78
+ reactFlowInstance.setNodes((nodes) => {
79
+ return nodes.map((n) => {
80
+ if (n.id === nodeId) return {
81
+ ...n,
82
+ data: setNewData(n.data)
83
+ };
84
+ return n;
85
+ });
86
+ });
87
+ }, [nodeId, reactFlowInstance]);
88
+ const setNodeParent = useCallback((node, extent) => {
89
+ if (!nodeId) return;
90
+ reactFlowInstance.setNodes((nodes) => {
91
+ return nodes.map((n) => {
92
+ if (n.id === nodeId) return {
93
+ ...n,
94
+ parentId: node ? node.id : void 0,
95
+ extent,
96
+ position: node ? relativePosition(node.position, n.position) : n.positionAbsolute ?? n.position
97
+ };
98
+ return n;
99
+ });
100
+ });
101
+ }, [nodeId, reactFlowInstance]);
102
+ return useMemo(() => ({
103
+ setNodeData,
104
+ setNodeParent
105
+ }), [setNodeData, setNodeParent]);
117
106
  }
118
107
  function useFlowNodeIntersections(id) {
119
- const nodeId = useNodeId(id);
120
- const node = useFlowNode(nodeId ?? "");
121
- const reactFlowInstance = useFlowInstance();
122
- return node ? reactFlowInstance.getIntersectingNodes(node, false) : [];
108
+ const node = useFlowNode(useNodeId$1(id) ?? "");
109
+ const reactFlowInstance = useFlowInstance();
110
+ return node ? reactFlowInstance.getIntersectingNodes(node, false) : [];
123
111
  }
124
- export {
125
- useFlowInputNodes,
126
- useFlowNode,
127
- useFlowNodeEdges,
128
- useFlowNodeInputEdges,
129
- useFlowNodeIntersections,
130
- useFlowNodeOutputEdges,
131
- useFlowNodeParents,
132
- useFlowNodeUtils,
133
- useFlowOutputNodes
134
- };
112
+ //#endregion
113
+ export { useFlowInputNodes, useFlowNode, useFlowNodeEdges, useFlowNodeInputEdges, useFlowNodeIntersections, useFlowNodeOutputEdges, useFlowNodeParents, useFlowNodeUtils, useFlowOutputNodes };
@@ -1,10 +1,10 @@
1
- import { useNodeMetaRegistry } from "../FlowContext/NodeMetaContext.js";
2
1
  import { useNodeId } from "./useNodeId.js";
2
+ import { useNodeMetaRegistry } from "../FlowContext/NodeMetaContext.js";
3
+ //#region src/Flow/hooks/useFlowNodeMeta.ts
3
4
  function useFlowNodeMeta(id) {
4
- const nodeId = useNodeId(id);
5
- const { registry } = useNodeMetaRegistry();
6
- return registry[nodeId];
5
+ const nodeId = useNodeId(id);
6
+ const { registry } = useNodeMetaRegistry();
7
+ return registry[nodeId];
7
8
  }
8
- export {
9
- useFlowNodeMeta
10
- };
9
+ //#endregion
10
+ export { useFlowNodeMeta };
@@ -1,159 +1,141 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { useMemo, isValidElement, useState, useCallback, useEffect } from "react";
3
- import { uid } from "uid";
4
- import { useLabels } from "@hitachivantara/uikit-react-core";
5
- import { Delete, Duplicate } from "@hitachivantara/uikit-react-icons";
6
- import { getColor, theme } from "@hitachivantara/uikit-styles";
1
+ import { useFlowInstance } from "./useFlowInstance.js";
2
+ import { useFlowNode, useFlowNodeInputEdges, useFlowNodeIntersections, useFlowNodeOutputEdges, useFlowNodeUtils } from "./useFlowNode.js";
7
3
  import { useNodeMetaRegistry } from "../FlowContext/NodeMetaContext.js";
8
- import { identifyHandles } from "../Node/utils.js";
9
4
  import { useFlowContext } from "./useFlowContext.js";
10
- import { useFlowInstance } from "./useFlowInstance.js";
11
- import { useFlowNodeInputEdges, useFlowNodeOutputEdges, useFlowNodeIntersections, useFlowNodeUtils, useFlowNode } from "./useFlowNode.js";
12
- const DEFAULT_LABELS = {
13
- deleteActionLabel: "Delete",
14
- duplicateActionLabel: "Duplicate"
5
+ import { identifyHandles } from "../Node/utils.js";
6
+ import { isValidElement, useCallback, useEffect, useMemo, useState } from "react";
7
+ import { useLabels } from "@hitachivantara/uikit-react-core";
8
+ import { getColor, theme as theme$1 } from "@hitachivantara/uikit-styles";
9
+ import { jsx } from "react/jsx-runtime";
10
+ import { Delete, Duplicate } from "@hitachivantara/uikit-react-icons";
11
+ import { uid } from "uid";
12
+ //#region src/Flow/hooks/useNode.tsx
13
+ var DEFAULT_LABELS = {
14
+ deleteActionLabel: "Delete",
15
+ duplicateActionLabel: "Duplicate"
15
16
  };
16
17
  function useHvNode(props) {
17
- const {
18
- id,
19
- title: titleProp,
20
- icon: iconProp,
21
- color: colorProp,
22
- subtitle: subtitleProp,
23
- nodeActions: nodeActionsProp,
24
- inputs: inputsProp,
25
- outputs: outputsProp,
26
- groupId,
27
- labels: labelsProps,
28
- nodeToolbarProps
29
- } = props;
30
- const { registerNode, unregisterNode } = useNodeMetaRegistry();
31
- const labels = useLabels(DEFAULT_LABELS, labelsProps);
32
- const inputs = useMemo(() => identifyHandles(inputsProp), [inputsProp]);
33
- const inputEdges = useFlowNodeInputEdges();
34
- const outputs = useMemo(() => identifyHandles(outputsProp), [outputsProp]);
35
- const outputEdges = useFlowNodeOutputEdges();
36
- const { nodeGroups } = useFlowContext();
37
- const intersections = useFlowNodeIntersections();
38
- const { setNodeParent, setNodeData } = useFlowNodeUtils();
39
- const node = useFlowNode();
40
- const reactFlowInstance = useFlowInstance();
41
- const nodeGroup = groupId && nodeGroups && nodeGroups[groupId] || void 0;
42
- const title = titleProp || nodeGroup?.label;
43
- const icon = iconProp || nodeGroup?.icon;
44
- const color = getColor(colorProp || nodeGroup?.color);
45
- const iconColor = getColor(
46
- isValidElement(icon) && icon.props.color || "textDark"
47
- );
48
- const subtitle = subtitleProp || node?.data.nodeLabel;
49
- const [showActions, setShowActions] = useState(false);
50
- const toggleShowActions = useCallback(() => {
51
- setShowActions(!showActions);
52
- }, [showActions]);
53
- const getNodeToolbarProps = useCallback(
54
- () => ({
55
- offset: 0,
56
- isVisible: showActions,
57
- ...nodeToolbarProps
58
- }),
59
- [nodeToolbarProps, showActions]
60
- );
61
- const nodeActions = useMemo(
62
- () => nodeActionsProp || [
63
- { id: "delete", label: labels?.deleteActionLabel, icon: /* @__PURE__ */ jsx(Delete, {}) },
64
- {
65
- id: "duplicate",
66
- label: labels?.duplicateActionLabel,
67
- icon: /* @__PURE__ */ jsx(Duplicate, {})
68
- }
69
- ],
70
- [labels?.deleteActionLabel, labels?.duplicateActionLabel, nodeActionsProp]
71
- );
72
- useEffect(() => {
73
- registerNode(id, {
74
- label: title || "",
75
- inputs,
76
- outputs
77
- });
78
- return () => unregisterNode(id);
79
- }, [id, title, inputs, outputs, registerNode, unregisterNode]);
80
- const handleDefaultAction = useCallback(
81
- (action) => {
82
- if (!node) return;
83
- if (action.callback) {
84
- action.callback(node);
85
- return;
86
- }
87
- switch (action.id) {
88
- case "delete":
89
- reactFlowInstance.deleteElements({ nodes: [node] });
90
- break;
91
- case "duplicate":
92
- reactFlowInstance.addNodes([
93
- {
94
- ...node,
95
- id: uid(),
96
- position: {
97
- x: node.position.x,
98
- y: node.position.y + (node.height || 0) + 20
99
- },
100
- selected: false,
101
- zIndex: Number(theme.zIndices.overlay)
102
- }
103
- ]);
104
- break;
105
- }
106
- },
107
- [node, reactFlowInstance]
108
- );
109
- return useMemo(
110
- () => ({
111
- // state
112
- id,
113
- title,
114
- icon,
115
- color,
116
- iconColor,
117
- subtitle,
118
- inputs,
119
- inputEdges,
120
- outputs,
121
- outputEdges,
122
- node,
123
- nodeActions,
124
- showActions,
125
- intersections,
126
- // prop getters
127
- getNodeToolbarProps,
128
- // actions
129
- toggleShowActions,
130
- handleDefaultAction,
131
- setNodeData,
132
- setNodeParent
133
- }),
134
- [
135
- id,
136
- title,
137
- icon,
138
- color,
139
- iconColor,
140
- subtitle,
141
- inputs,
142
- inputEdges,
143
- outputs,
144
- outputEdges,
145
- node,
146
- nodeActions,
147
- showActions,
148
- intersections,
149
- getNodeToolbarProps,
150
- toggleShowActions,
151
- handleDefaultAction,
152
- setNodeData,
153
- setNodeParent
154
- ]
155
- );
18
+ const { id, title: titleProp, icon: iconProp, color: colorProp, subtitle: subtitleProp, nodeActions: nodeActionsProp, inputs: inputsProp, outputs: outputsProp, groupId, labels: labelsProps, nodeToolbarProps } = props;
19
+ const { registerNode, unregisterNode } = useNodeMetaRegistry();
20
+ const labels = useLabels(DEFAULT_LABELS, labelsProps);
21
+ const inputs = useMemo(() => identifyHandles(inputsProp), [inputsProp]);
22
+ const inputEdges = useFlowNodeInputEdges();
23
+ const outputs = useMemo(() => identifyHandles(outputsProp), [outputsProp]);
24
+ const outputEdges = useFlowNodeOutputEdges();
25
+ const { nodeGroups } = useFlowContext();
26
+ const intersections = useFlowNodeIntersections();
27
+ const { setNodeParent, setNodeData } = useFlowNodeUtils();
28
+ const node = useFlowNode();
29
+ const reactFlowInstance = useFlowInstance();
30
+ const nodeGroup = groupId && nodeGroups && nodeGroups[groupId] || void 0;
31
+ const title = titleProp || nodeGroup?.label;
32
+ const icon = iconProp || nodeGroup?.icon;
33
+ const color = getColor(colorProp || nodeGroup?.color);
34
+ const iconColor = getColor(isValidElement(icon) && icon.props.color || "textDark");
35
+ const subtitle = subtitleProp || node?.data.nodeLabel;
36
+ const [showActions, setShowActions] = useState(false);
37
+ const toggleShowActions = useCallback(() => {
38
+ setShowActions(!showActions);
39
+ }, [showActions]);
40
+ const getNodeToolbarProps = useCallback(() => ({
41
+ offset: 0,
42
+ isVisible: showActions,
43
+ ...nodeToolbarProps
44
+ }), [nodeToolbarProps, showActions]);
45
+ const nodeActions = useMemo(() => nodeActionsProp || [{
46
+ id: "delete",
47
+ label: labels?.deleteActionLabel,
48
+ icon: /* @__PURE__ */ jsx(Delete, {})
49
+ }, {
50
+ id: "duplicate",
51
+ label: labels?.duplicateActionLabel,
52
+ icon: /* @__PURE__ */ jsx(Duplicate, {})
53
+ }], [
54
+ labels?.deleteActionLabel,
55
+ labels?.duplicateActionLabel,
56
+ nodeActionsProp
57
+ ]);
58
+ useEffect(() => {
59
+ registerNode(id, {
60
+ label: title || "",
61
+ inputs,
62
+ outputs
63
+ });
64
+ return () => unregisterNode(id);
65
+ }, [
66
+ id,
67
+ title,
68
+ inputs,
69
+ outputs,
70
+ registerNode,
71
+ unregisterNode
72
+ ]);
73
+ const handleDefaultAction = useCallback((action) => {
74
+ if (!node) return;
75
+ if (action.callback) {
76
+ action.callback(node);
77
+ return;
78
+ }
79
+ switch (action.id) {
80
+ case "delete":
81
+ reactFlowInstance.deleteElements({ nodes: [node] });
82
+ break;
83
+ case "duplicate":
84
+ reactFlowInstance.addNodes([{
85
+ ...node,
86
+ id: uid(),
87
+ position: {
88
+ x: node.position.x,
89
+ y: node.position.y + (node.height || 0) + 20
90
+ },
91
+ selected: false,
92
+ zIndex: Number(theme$1.zIndices.overlay)
93
+ }]);
94
+ break;
95
+ default: break;
96
+ }
97
+ }, [node, reactFlowInstance]);
98
+ return useMemo(() => ({
99
+ id,
100
+ title,
101
+ icon,
102
+ color,
103
+ iconColor,
104
+ subtitle,
105
+ inputs,
106
+ inputEdges,
107
+ outputs,
108
+ outputEdges,
109
+ node,
110
+ nodeActions,
111
+ showActions,
112
+ intersections,
113
+ getNodeToolbarProps,
114
+ toggleShowActions,
115
+ handleDefaultAction,
116
+ setNodeData,
117
+ setNodeParent
118
+ }), [
119
+ id,
120
+ title,
121
+ icon,
122
+ color,
123
+ iconColor,
124
+ subtitle,
125
+ inputs,
126
+ inputEdges,
127
+ outputs,
128
+ outputEdges,
129
+ node,
130
+ nodeActions,
131
+ showActions,
132
+ intersections,
133
+ getNodeToolbarProps,
134
+ toggleShowActions,
135
+ handleDefaultAction,
136
+ setNodeData,
137
+ setNodeParent
138
+ ]);
156
139
  }
157
- export {
158
- useHvNode
159
- };
140
+ //#endregion
141
+ export { useHvNode };
@@ -1,8 +1,9 @@
1
- import { useNodeId as useNodeId$1 } from "reactflow";
2
- function useNodeId(id) {
3
- const currentNodeId = useNodeId$1();
4
- return id ?? currentNodeId;
1
+ import { useNodeId } from "reactflow";
2
+ //#region src/Flow/hooks/useNodeId.ts
3
+ /** Retrieves the node id. INTERNAL USE ONLY */
4
+ function useNodeId$1(id) {
5
+ const currentNodeId = useNodeId();
6
+ return id ?? currentNodeId;
5
7
  }
6
- export {
7
- useNodeId
8
- };
8
+ //#endregion
9
+ export { useNodeId$1 as useNodeId };