@hitachivantara/uikit-react-lab 6.1.8 → 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.
- package/dist/Blade/Blade.js +134 -173
- package/dist/Blade/Blade.styles.js +54 -69
- package/dist/Blades/Blades.js +70 -101
- package/dist/Blades/Blades.styles.js +7 -10
- package/dist/Dashboard/Dashboard.js +57 -60
- package/dist/Dashboard/Dashboard.styles.js +6 -10
- package/dist/Flow/Background/Background.js +10 -16
- package/dist/Flow/Controls/Controls.js +77 -91
- package/dist/Flow/DroppableFlow.js +135 -200
- package/dist/Flow/Empty/Empty.js +12 -9
- package/dist/Flow/Empty/Empty.styles.js +12 -15
- package/dist/Flow/Flow.js +28 -30
- package/dist/Flow/Flow.styles.js +12 -18
- package/dist/Flow/FlowContext/FlowContext.js +22 -23
- package/dist/Flow/FlowContext/NodeMetaContext.js +36 -39
- package/dist/Flow/Minimap/Minimap.js +15 -28
- package/dist/Flow/Minimap/Minimap.styles.js +4 -9
- package/dist/Flow/Node/BaseNode.js +144 -190
- package/dist/Flow/Node/BaseNode.styles.js +122 -133
- package/dist/Flow/Node/Node.js +90 -108
- package/dist/Flow/Node/Node.styles.js +30 -40
- package/dist/Flow/Node/Parameters/ParamRenderer.js +17 -14
- package/dist/Flow/Node/Parameters/Select.js +33 -38
- package/dist/Flow/Node/Parameters/Slider.js +27 -29
- package/dist/Flow/Node/Parameters/Text.js +17 -17
- package/dist/Flow/Node/utils.js +44 -49
- package/dist/Flow/Sidebar/Sidebar.js +115 -137
- package/dist/Flow/Sidebar/Sidebar.styles.js +21 -22
- package/dist/Flow/Sidebar/SidebarGroup/SidebarGroup.js +57 -60
- package/dist/Flow/Sidebar/SidebarGroup/SidebarGroup.styles.js +27 -33
- package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.js +27 -47
- package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.js +14 -32
- package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.styles.js +17 -23
- package/dist/Flow/base.js +5 -5
- package/dist/Flow/hooks/useFlowContext.js +5 -5
- package/dist/Flow/hooks/useFlowInstance.js +5 -4
- package/dist/Flow/hooks/useFlowNode.js +92 -113
- package/dist/Flow/hooks/useFlowNodeMeta.js +7 -7
- package/dist/Flow/hooks/useNode.js +136 -154
- package/dist/Flow/hooks/useNodeId.js +8 -7
- package/dist/Flow/nodes/DashboardNode.js +64 -86
- package/dist/Flow/nodes/DashboardNode.styles.js +8 -14
- package/dist/Flow/nodes/StickyNode.js +370 -435
- package/dist/StepNavigation/DefaultNavigation/DefaultNavigation.js +36 -52
- package/dist/StepNavigation/DefaultNavigation/Step/Step.js +40 -51
- package/dist/StepNavigation/DefaultNavigation/Step/Step.styles.js +22 -33
- package/dist/StepNavigation/DefaultNavigation/utils.js +38 -30
- package/dist/StepNavigation/SimpleNavigation/Dot/Dot.js +24 -41
- package/dist/StepNavigation/SimpleNavigation/Dot/Dot.styles.js +13 -16
- package/dist/StepNavigation/SimpleNavigation/SimpleNavigation.js +35 -47
- package/dist/StepNavigation/SimpleNavigation/utils.js +10 -11
- package/dist/StepNavigation/StepNavigation.js +136 -179
- package/dist/StepNavigation/StepNavigation.styles.js +29 -32
- package/dist/Wizard/Wizard.js +81 -104
- package/dist/Wizard/Wizard.styles.js +4 -7
- package/dist/Wizard/WizardActions/WizardActions.js +111 -131
- package/dist/Wizard/WizardActions/WizardActions.styles.js +19 -20
- package/dist/Wizard/WizardContainer/WizardContainer.js +19 -28
- package/dist/Wizard/WizardContainer/WizardContainer.styles.js +8 -14
- package/dist/Wizard/WizardContent/WizardContent.js +103 -120
- package/dist/Wizard/WizardContent/WizardContent.styles.js +33 -36
- package/dist/Wizard/WizardContext/WizardContext.js +10 -13
- package/dist/Wizard/WizardTitle/WizardTitle.js +74 -79
- package/dist/Wizard/WizardTitle/WizardTitle.styles.js +12 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -81
- package/package.json +6 -6
- 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
|
-
|
|
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
|
-
|
|
410
|
-
|
|
411
|
-
};
|
|
410
|
+
//#endregion
|
|
411
|
+
export { flowStyles };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
1
|
import { HvFlowContext } from "../FlowContext/FlowContext.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
5
|
+
return useReactFlow();
|
|
4
6
|
}
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
125
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const nodeId = useNodeId(id);
|
|
6
|
+
const { registry } = useNodeMetaRegistry();
|
|
7
|
+
return registry[nodeId];
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useFlowNodeMeta };
|
|
@@ -1,159 +1,141 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
140
|
+
//#endregion
|
|
141
|
+
export { useHvNode };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useNodeId
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { useNodeId$1 as useNodeId };
|