@hitachivantara/uikit-react-lab 5.13.2 → 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 +2 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useRef, useCallback, useMemo } from "react";
|
|
3
|
+
const HvFlowNodeMetaContext = createContext(void 0);
|
|
4
|
+
const HvFlowNodeMetaProvider = ({
|
|
5
|
+
children
|
|
6
|
+
}) => {
|
|
7
|
+
const registryRef = useRef({});
|
|
8
|
+
const registerNode = useCallback((id, nodeInfo) => {
|
|
9
|
+
registryRef.current[id] = nodeInfo;
|
|
10
|
+
}, []);
|
|
11
|
+
const unregisterNode = useCallback((id) => {
|
|
12
|
+
delete registryRef.current[id];
|
|
13
|
+
}, []);
|
|
14
|
+
const getRegistry = useCallback(() => {
|
|
15
|
+
return registryRef.current;
|
|
16
|
+
}, []);
|
|
17
|
+
const value = useMemo(() => ({
|
|
18
|
+
registerNode,
|
|
19
|
+
unregisterNode,
|
|
20
|
+
getRegistry
|
|
21
|
+
}), [registerNode, unregisterNode, getRegistry]);
|
|
22
|
+
return /* @__PURE__ */ jsx(HvFlowNodeMetaContext.Provider, { value, children });
|
|
23
|
+
};
|
|
24
|
+
function useNodeMetaRegistry() {
|
|
25
|
+
const context = useContext(HvFlowNodeMetaContext);
|
|
26
|
+
if (context === void 0) {
|
|
27
|
+
throw new Error("useNodeRegistry must be used within a HvFlowNodeMetaProvider");
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
registerNode: context.registerNode,
|
|
31
|
+
unregisterNode: context.unregisterNode,
|
|
32
|
+
registry: context.getRegistry()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
HvFlowNodeMetaProvider,
|
|
37
|
+
useNodeMetaRegistry
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=NodeMetaContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeMetaContext.js","sources":["../../../../../src/components/Flow/FlowContext/NodeMetaContext.tsx"],"sourcesContent":["import { createContext, useRef, useCallback, useContext, useMemo } from \"react\";\n\nimport { HvFlowNodeMeta } from \"../types\";\n\ninterface HvFlowNodeMetaContextType {\n registerNode: (id: string, nodeInfo: HvFlowNodeMeta) => void;\n unregisterNode: (id: string) => void;\n getRegistry: () => Record<string, HvFlowNodeMeta>;\n}\n\nconst HvFlowNodeMetaContext = createContext<\n HvFlowNodeMetaContextType | undefined\n>(undefined);\n\nexport const HvFlowNodeMetaProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const registryRef = useRef<Record<string, HvFlowNodeMeta>>({});\n\n const registerNode = useCallback((id: string, nodeInfo: HvFlowNodeMeta) => {\n registryRef.current[id] = nodeInfo;\n }, []);\n\n const unregisterNode = useCallback((id: string) => {\n delete registryRef.current[id];\n }, []);\n\n const getRegistry = useCallback(() => {\n return registryRef.current;\n }, []);\n\n const value = useMemo<HvFlowNodeMetaContextType>(\n () => ({\n registerNode,\n unregisterNode,\n getRegistry,\n }),\n [registerNode, unregisterNode, getRegistry]\n );\n\n return (\n <HvFlowNodeMetaContext.Provider value={value}>\n {children}\n </HvFlowNodeMetaContext.Provider>\n );\n};\n\nexport function useNodeMeta(nodeId: string): HvFlowNodeMeta | undefined {\n const context = useContext(HvFlowNodeMetaContext);\n\n if (context === undefined) {\n throw new Error(\"useNodeMeta must be used within a HvFlowNodeMetaProvider\");\n }\n\n const registry = context.getRegistry();\n return registry[nodeId];\n}\n\nexport function useNodeMetaRegistry() {\n const context = useContext(HvFlowNodeMetaContext);\n\n if (context === undefined) {\n throw new Error(\n \"useNodeRegistry must be used within a HvFlowNodeMetaProvider\"\n );\n }\n\n return {\n registerNode: context.registerNode,\n unregisterNode: context.unregisterNode,\n registry: context.getRegistry(),\n };\n}\n"],"names":["HvFlowNodeMetaContext","createContext","undefined","HvFlowNodeMetaProvider","children","registryRef","useRef","registerNode","useCallback","id","nodeInfo","current","unregisterNode","getRegistry","value","useMemo","useNodeMetaRegistry","context","useContext","Error","registry"],"mappings":";;AAUA,MAAMA,wBAAwBC,cAE5BC,MAAS;AAEJ,MAAMC,yBAAyBA,CAAC;AAAA,EACrCC;AAGF,MAAM;AACEC,QAAAA,cAAcC,OAAuC,CAAA,CAAE;AAE7D,QAAMC,eAAeC,YAAY,CAACC,IAAYC,aAA6B;AAC7DC,gBAAAA,QAAQF,EAAE,IAAIC;AAAAA,EAC5B,GAAG,CAAE,CAAA;AAECE,QAAAA,iBAAiBJ,YAAY,CAACC,OAAe;AAC1CJ,WAAAA,YAAYM,QAAQF,EAAE;AAAA,EAC/B,GAAG,CAAE,CAAA;AAECI,QAAAA,cAAcL,YAAY,MAAM;AACpC,WAAOH,YAAYM;AAAAA,EACrB,GAAG,CAAE,CAAA;AAECG,QAAAA,QAAQC,QACZ,OAAO;AAAA,IACLR;AAAAA,IACAK;AAAAA,IACAC;AAAAA,EAEF,IAAA,CAACN,cAAcK,gBAAgBC,WAAW,CAC5C;AAEA,SACG,oBAAA,sBAAsB,UAAtB,EAA+B,OAC7BT,SACH,CAAA;AAEJ;AAaO,SAASY,sBAAsB;AAC9BC,QAAAA,UAAUC,WAAWlB,qBAAqB;AAEhD,MAAIiB,YAAYf,QAAW;AACnB,UAAA,IAAIiB,MACR,8DACF;AAAA,EACF;AAEO,SAAA;AAAA,IACLZ,cAAcU,QAAQV;AAAAA,IACtBK,gBAAgBK,QAAQL;AAAAA,IACxBQ,UAAUH,QAAQJ,YAAY;AAAA,EAAA;AAElC;"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState, useCallback, isValidElement } from "react";
|
|
3
|
+
import { useReactFlow, useStore, NodeToolbar, Handle, Position } from "reactflow";
|
|
4
|
+
import { HvButton, HvTypography } from "@hitachivantara/uikit-react-core";
|
|
5
|
+
import { Delete, Duplicate } from "@hitachivantara/uikit-react-icons";
|
|
6
|
+
import { theme, getColor } from "@hitachivantara/uikit-styles";
|
|
7
|
+
import { useNodeMetaRegistry } from "../FlowContext/NodeMetaContext.js";
|
|
8
|
+
import { useClasses } from "./BaseNode.styles.js";
|
|
9
|
+
import { staticClasses } from "./BaseNode.styles.js";
|
|
10
|
+
const isInputConnected = (id, type, idx, edges) => {
|
|
11
|
+
if (type === "target") {
|
|
12
|
+
return edges.some((e) => e.target === id && e.targetHandle === idx.toString());
|
|
13
|
+
}
|
|
14
|
+
if (type === "source") {
|
|
15
|
+
return edges.some((e) => e.source === id && e.sourceHandle === idx.toString());
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
const defaultActions = [{
|
|
20
|
+
id: "delete",
|
|
21
|
+
label: "Delete",
|
|
22
|
+
icon: /* @__PURE__ */ jsx(Delete, {})
|
|
23
|
+
}, {
|
|
24
|
+
id: "duplicate",
|
|
25
|
+
label: "Duplicate",
|
|
26
|
+
icon: /* @__PURE__ */ jsx(Duplicate, {})
|
|
27
|
+
}];
|
|
28
|
+
const renderedIcon = (actionIcon) => isValidElement(actionIcon) ? actionIcon : actionIcon?.();
|
|
29
|
+
const HvFlowBaseNode = ({
|
|
30
|
+
id,
|
|
31
|
+
title,
|
|
32
|
+
headerItems,
|
|
33
|
+
icon,
|
|
34
|
+
color: colorProp,
|
|
35
|
+
inputs,
|
|
36
|
+
outputs,
|
|
37
|
+
nodeActions = defaultActions,
|
|
38
|
+
classes: classesProp,
|
|
39
|
+
className,
|
|
40
|
+
children
|
|
41
|
+
}) => {
|
|
42
|
+
const {
|
|
43
|
+
registerNode,
|
|
44
|
+
unregisterNode
|
|
45
|
+
} = useNodeMetaRegistry();
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
registerNode(id, {
|
|
48
|
+
label: title || "",
|
|
49
|
+
inputs,
|
|
50
|
+
outputs
|
|
51
|
+
});
|
|
52
|
+
return () => unregisterNode(id);
|
|
53
|
+
}, [id, title, inputs, outputs, registerNode, unregisterNode]);
|
|
54
|
+
const [showActions, setShowActions] = useState(false);
|
|
55
|
+
const reactFlowInstance = useReactFlow();
|
|
56
|
+
const {
|
|
57
|
+
classes,
|
|
58
|
+
cx,
|
|
59
|
+
css
|
|
60
|
+
} = useClasses(classesProp);
|
|
61
|
+
const edges = useStore((s) => s.edges);
|
|
62
|
+
const nodes = useStore((s) => s.getNodes());
|
|
63
|
+
const node = nodes.find((n) => n.id === id);
|
|
64
|
+
const handleDefaultAction = useCallback((action) => {
|
|
65
|
+
if (!node)
|
|
66
|
+
return;
|
|
67
|
+
if (action.callback) {
|
|
68
|
+
action.callback(node);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
switch (action.id) {
|
|
72
|
+
case "delete":
|
|
73
|
+
reactFlowInstance.deleteElements({
|
|
74
|
+
nodes: [node]
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
case "duplicate":
|
|
78
|
+
reactFlowInstance.addNodes([{
|
|
79
|
+
...node,
|
|
80
|
+
id: `${reactFlowInstance.getNodes().length + 1}`,
|
|
81
|
+
position: {
|
|
82
|
+
x: node.position.x,
|
|
83
|
+
y: node.position.y + (node.height || 0) + 20
|
|
84
|
+
},
|
|
85
|
+
selected: false,
|
|
86
|
+
zIndex: Number(theme.zIndices.overlay)
|
|
87
|
+
}]);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}, [node, reactFlowInstance]);
|
|
91
|
+
if (!node)
|
|
92
|
+
return null;
|
|
93
|
+
const color = getColor(colorProp);
|
|
94
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(css({
|
|
95
|
+
border: `1px solid ${color}`
|
|
96
|
+
}), classes.root, className), onMouseEnter: () => setShowActions(true), onMouseLeave: () => setShowActions(false), children: [
|
|
97
|
+
/* @__PURE__ */ jsx(NodeToolbar, { isVisible: showActions, offset: 0, children: nodeActions?.map((action) => /* @__PURE__ */ jsx(HvButton, { icon: true, onClick: () => handleDefaultAction(action), children: renderedIcon(action.icon) }, action.id)) }),
|
|
98
|
+
/* @__PURE__ */ jsxs("div", { className: cx(css({
|
|
99
|
+
backgroundColor: color
|
|
100
|
+
}), classes.headerContainer), children: [
|
|
101
|
+
/* @__PURE__ */ jsxs("div", { className: classes.titleContainer, children: [
|
|
102
|
+
icon,
|
|
103
|
+
/* @__PURE__ */ jsx(HvTypography, { variant: "title4", className: classes.title, children: title })
|
|
104
|
+
] }),
|
|
105
|
+
headerItems && /* @__PURE__ */ jsx("div", { style: {
|
|
106
|
+
display: "flex"
|
|
107
|
+
}, children: headerItems })
|
|
108
|
+
] }),
|
|
109
|
+
children && /* @__PURE__ */ jsx("div", { className: classes.contentContainer, children }),
|
|
110
|
+
inputs && inputs.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
111
|
+
/* @__PURE__ */ jsx("div", { className: classes.inputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Inputs" }) }),
|
|
112
|
+
/* @__PURE__ */ jsx("div", { className: classes.inputsContainer, children: inputs?.map((input, idx) => /* @__PURE__ */ jsxs("div", { className: classes.inputContainer, children: [
|
|
113
|
+
/* @__PURE__ */ jsx(Handle, { type: "target", isConnectableStart: false, id: `${idx}`, position: Position.Left, style: {
|
|
114
|
+
top: "auto",
|
|
115
|
+
bottom: (outputs?.length ? 80 : 18) + (outputs?.length || 0) * 29 + 29 * idx
|
|
116
|
+
} }),
|
|
117
|
+
/* @__PURE__ */ jsx(HvTypography, { children: input.label }),
|
|
118
|
+
input.isMandatory && !isInputConnected(id, "target", idx, edges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory })
|
|
119
|
+
] }, idx)) })
|
|
120
|
+
] }),
|
|
121
|
+
outputs && outputs.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
122
|
+
/* @__PURE__ */ jsx("div", { className: classes.outputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Outputs" }) }),
|
|
123
|
+
/* @__PURE__ */ jsx("div", { className: classes.outputsContainer, children: outputs?.map((output, idx) => /* @__PURE__ */ jsxs("div", { className: classes.outputContainer, children: [
|
|
124
|
+
/* @__PURE__ */ jsx(Handle, { type: "source", isConnectableEnd: false, id: `${idx}`, position: Position.Right, style: {
|
|
125
|
+
bottom: -10 + 29 * (outputs.length - idx),
|
|
126
|
+
top: "auto"
|
|
127
|
+
} }),
|
|
128
|
+
output.isMandatory && !isInputConnected(id, "source", idx, edges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory }),
|
|
129
|
+
/* @__PURE__ */ jsx(HvTypography, { children: output.label })
|
|
130
|
+
] }, idx)) })
|
|
131
|
+
] })
|
|
132
|
+
] });
|
|
133
|
+
};
|
|
134
|
+
export {
|
|
135
|
+
HvFlowBaseNode,
|
|
136
|
+
staticClasses as flowBaseNodeClasses
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=BaseNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseNode.js","sources":["../../../../../src/components/Flow/Node/BaseNode.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\n\nimport {\n Edge,\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useReactFlow,\n useStore,\n} from \"reactflow\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvBaseProps,\n HvButton,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Delete, Duplicate } from \"@hitachivantara/uikit-react-icons\";\nimport { HvColorAny, getColor, theme } from \"@hitachivantara/uikit-styles\";\n\nimport {\n HvFlowNodeAction,\n HvFlowBuiltInActions,\n HvFlowNodeInput,\n HvFlowNodeOutput,\n} from \"../types/index\";\nimport { useNodeMetaRegistry } from \"../FlowContext/NodeMetaContext\";\nimport { staticClasses, useClasses } from \"./BaseNode.styles\";\n\nexport { staticClasses as flowBaseNodeClasses };\n\nexport type HvFlowBaseNodeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFlowBaseNodeProps<T>\n extends Omit<HvBaseProps, \"id\">,\n NodeProps<T> {\n /** Header title */\n title?: string;\n /** Header icon */\n icon?: React.ReactNode;\n /** Header color */\n color?: HvColorAny;\n /** Header items */\n headerItems?: React.ReactNode;\n /** Node inputs */\n inputs?: HvFlowNodeInput[];\n /** Node outputs */\n outputs?: HvFlowNodeOutput[];\n /** Node actions */\n nodeActions?: HvFlowNodeAction[];\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowBaseNodeClasses;\n}\n\nconst isInputConnected = (\n id: string,\n type: \"target\" | \"source\",\n idx: number,\n edges: Edge[]\n) => {\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 return false;\n};\n\nconst defaultActions: HvFlowBuiltInActions[] = [\n { id: \"delete\", label: \"Delete\", icon: <Delete /> },\n { id: \"duplicate\", label: \"Duplicate\", icon: <Duplicate /> },\n];\n\nconst renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\n\nexport const HvFlowBaseNode = ({\n id,\n title,\n headerItems,\n icon,\n color: colorProp,\n inputs,\n outputs,\n nodeActions = defaultActions,\n classes: classesProp,\n className,\n children,\n}: HvFlowBaseNodeProps<unknown>) => {\n const { registerNode, unregisterNode } = useNodeMetaRegistry();\n useEffect(() => {\n registerNode(id, { label: title || \"\", inputs, outputs });\n return () => unregisterNode(id);\n }, [id, title, inputs, outputs, registerNode, unregisterNode]);\n\n const [showActions, setShowActions] = useState(false);\n const reactFlowInstance = useReactFlow();\n\n const { classes, cx, css } = useClasses(classesProp);\n\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 handleDefaultAction = useCallback(\n (action: HvFlowNodeAction) => {\n if (!node) return;\n\n if (action.callback) {\n action.callback(node);\n return;\n }\n\n // built-in actions\n switch (action.id) {\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 if (!node) return null;\n\n const color = getColor(colorProp);\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 {nodeActions?.map((action) => (\n <HvButton\n key={action.id}\n icon\n onClick={() => handleDefaultAction(action)}\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.titleContainer}>\n {icon}\n <HvTypography variant=\"title4\" className={classes.title}>\n {title}\n </HvTypography>\n </div>\n {headerItems && <div style={{ display: \"flex\" }}>{headerItems}</div>}\n </div>\n {children && <div className={classes.contentContainer}>{children}</div>}\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","defaultActions","label","icon","renderedIcon","actionIcon","isValidElement","HvFlowBaseNode","title","headerItems","color","colorProp","inputs","outputs","nodeActions","classes","classesProp","className","children","registerNode","unregisterNode","useNodeMetaRegistry","useEffect","showActions","setShowActions","useState","reactFlowInstance","useReactFlow","cx","css","useClasses","useStore","s","nodes","getNodes","node","find","n","handleDefaultAction","useCallback","action","callback","deleteElements","addNodes","length","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","getColor","border","root","map","backgroundColor","headerContainer","titleContainer","display","contentContainer","inputsTitleContainer","inputsContainer","input","inputContainer","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;AAwDA,MAAMA,mBAAmBA,C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CAAA;AAAA,QAC1BgE,MAAMM,eACL,CAACnF,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxC,oBAAC,OAAI,EAAA,WAAWsB,QAAQ0D,UACzB,CAAA;AAAA,MAAA,KAlBwCjF,GAmB7C,CACD,GACH;AAAA,IAAA,GACF;AAAA,IAEDqB,WAAWA,QAAQ+B,SAAS,KAEzB,qBAAA,UAAA,EAAA,UAAA;AAAA,MAAA,oBAAC,SAAI,WAAW7B,QAAQ2D,uBACtB,UAAC,oBAAA,cAAA,EAAa,qBAAO,EACvB,CAAA;AAAA,MACC,oBAAA,OAAA,EAAI,WAAW3D,QAAQ4D,kBACrB9D,UAAS6C,SAAAA,IAAI,CAACkB,QAAQpF,QACrB,qBAAC,OAAI,EAAA,WAAWuB,QAAQ8D,iBACtB,UAAA;AAAA,QAAA,oBAAC,QACC,EAAA,MAAK,UACL,kBAAkB,OAClB,IAAK,GAAErF,GAAI,IACX,UAAU4E,SAASU,OACnB,OAAO;AAAA,UACLP,QAAQ,MAAM,MAAM1D,QAAQ+B,SAASpD;AAAAA,UACrC8E,KAAK;AAAA,QAAA,GACL;AAAA,QAEHM,OAAOJ,eACN,CAACnF,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxC,oBAAC,OAAI,EAAA,WAAWsB,QAAQ0D,UACzB,CAAA;AAAA,QACH,oBAAC,cAAcG,EAAAA,UAAAA,OAAO1E,MAAM,CAAA;AAAA,MAAA,KAfgBV,GAgB9C,CACD,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createClasses, theme } from "@hitachivantara/uikit-react-core";
|
|
2
|
+
const {
|
|
3
|
+
staticClasses,
|
|
4
|
+
useClasses
|
|
5
|
+
} = createClasses("HvFlowBaseNode", {
|
|
6
|
+
root: {
|
|
7
|
+
borderRadius: theme.radii.round,
|
|
8
|
+
backgroundColor: theme.colors.atmo1,
|
|
9
|
+
boxShadow: theme.colors.shadow,
|
|
10
|
+
minWidth: "250px"
|
|
11
|
+
},
|
|
12
|
+
headerContainer: {
|
|
13
|
+
padding: theme.spacing(0.5, 1),
|
|
14
|
+
display: "flex",
|
|
15
|
+
flexDirection: "row",
|
|
16
|
+
justifyContent: "space-between",
|
|
17
|
+
alignItems: "center",
|
|
18
|
+
borderTopLeftRadius: theme.radii.round,
|
|
19
|
+
borderTopRightRadius: theme.radii.round
|
|
20
|
+
},
|
|
21
|
+
titleContainer: {
|
|
22
|
+
display: "flex",
|
|
23
|
+
flexDirection: "row",
|
|
24
|
+
alignItems: "center"
|
|
25
|
+
},
|
|
26
|
+
title: {
|
|
27
|
+
color: theme.colors.base_dark
|
|
28
|
+
},
|
|
29
|
+
inputsTitleContainer: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
justifyContent: "center",
|
|
32
|
+
padding: theme.space.xs,
|
|
33
|
+
backgroundColor: theme.colors.atmo2,
|
|
34
|
+
borderTop: `1px solid ${theme.colors.atmo4}`,
|
|
35
|
+
borderBottom: `1px solid ${theme.colors.atmo4}`
|
|
36
|
+
},
|
|
37
|
+
outputsTitleContainer: {
|
|
38
|
+
display: "flex",
|
|
39
|
+
justifyContent: "center",
|
|
40
|
+
padding: theme.space.xs,
|
|
41
|
+
backgroundColor: theme.colors.atmo2,
|
|
42
|
+
borderTop: `1px solid ${theme.colors.atmo4}`,
|
|
43
|
+
borderBottom: `1px solid ${theme.colors.atmo4}`
|
|
44
|
+
},
|
|
45
|
+
contentContainer: {},
|
|
46
|
+
inputsContainer: {
|
|
47
|
+
display: "flex",
|
|
48
|
+
flexDirection: "column",
|
|
49
|
+
padding: theme.space.sm,
|
|
50
|
+
gap: theme.space.xs,
|
|
51
|
+
alignItems: "flex-start"
|
|
52
|
+
},
|
|
53
|
+
outputsContainer: {
|
|
54
|
+
display: "flex",
|
|
55
|
+
flexDirection: "column",
|
|
56
|
+
padding: theme.space.sm,
|
|
57
|
+
gap: theme.space.xs,
|
|
58
|
+
alignItems: "flex-end"
|
|
59
|
+
},
|
|
60
|
+
inputContainer: {
|
|
61
|
+
display: "flex",
|
|
62
|
+
flexDirection: "row",
|
|
63
|
+
alignItems: "center"
|
|
64
|
+
},
|
|
65
|
+
outputContainer: {
|
|
66
|
+
display: "flex",
|
|
67
|
+
flexDirection: "row",
|
|
68
|
+
alignItems: "center"
|
|
69
|
+
},
|
|
70
|
+
mandatory: {
|
|
71
|
+
width: 10,
|
|
72
|
+
height: 10,
|
|
73
|
+
margin: theme.spacing(0, theme.space.xs),
|
|
74
|
+
borderRadius: theme.radii.circle,
|
|
75
|
+
backgroundColor: theme.colors.negative_20
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
export {
|
|
79
|
+
staticClasses,
|
|
80
|
+
useClasses
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=BaseNode.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseNode.styles.js","sources":["../../../../../src/components/Flow/Node/BaseNode.styles.tsx"],"sourcesContent":["import { createClasses, theme } from \"@hitachivantara/uikit-react-core\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFlowBaseNode\", {\n root: {\n borderRadius: theme.radii.round,\n backgroundColor: theme.colors.atmo1,\n boxShadow: theme.colors.shadow,\n minWidth: \"250px\",\n },\n headerContainer: {\n padding: theme.spacing(0.5, 1),\n display: \"flex\",\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n borderTopLeftRadius: theme.radii.round,\n borderTopRightRadius: theme.radii.round,\n },\n titleContainer: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n },\n title: {\n color: theme.colors.base_dark,\n },\n inputsTitleContainer: {\n display: \"flex\",\n justifyContent: \"center\",\n padding: theme.space.xs,\n backgroundColor: theme.colors.atmo2,\n borderTop: `1px solid ${theme.colors.atmo4}`,\n borderBottom: `1px solid ${theme.colors.atmo4}`,\n },\n outputsTitleContainer: {\n display: \"flex\",\n justifyContent: \"center\",\n padding: theme.space.xs,\n backgroundColor: theme.colors.atmo2,\n borderTop: `1px solid ${theme.colors.atmo4}`,\n borderBottom: `1px solid ${theme.colors.atmo4}`,\n },\n contentContainer: {},\n inputsContainer: {\n display: \"flex\",\n flexDirection: \"column\",\n padding: theme.space.sm,\n gap: theme.space.xs,\n alignItems: \"flex-start\",\n },\n outputsContainer: {\n display: \"flex\",\n flexDirection: \"column\",\n padding: theme.space.sm,\n gap: theme.space.xs,\n alignItems: \"flex-end\",\n },\n inputContainer: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n },\n outputContainer: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n },\n mandatory: {\n width: 10,\n height: 10,\n margin: theme.spacing(0, theme.space.xs),\n borderRadius: theme.radii.circle,\n backgroundColor: theme.colors.negative_20,\n },\n});\n"],"names":["staticClasses","useClasses","createClasses","root","borderRadius","theme","radii","round","backgroundColor","colors","atmo1","boxShadow","shadow","minWidth","headerContainer","padding","spacing","display","flexDirection","justifyContent","alignItems","borderTopLeftRadius","borderTopRightRadius","titleContainer","title","color","base_dark","inputsTitleContainer","space","xs","atmo2","borderTop","atmo4","borderBottom","outputsTitleContainer","contentContainer","inputsContainer","sm","gap","outputsContainer","inputContainer","outputContainer","mandatory","width","height","margin","circle","negative_20"],"mappings":";AAEa,MAAA;AAAA,EAAEA;AAAAA,EAAeC;AAAW,IAAIC,cAAc,kBAAkB;AAAA,EAC3EC,MAAM;AAAA,IACJC,cAAcC,MAAMC,MAAMC;AAAAA,IAC1BC,iBAAiBH,MAAMI,OAAOC;AAAAA,IAC9BC,WAAWN,MAAMI,OAAOG;AAAAA,IACxBC,UAAU;AAAA,EACZ;AAAA,EACAC,iBAAiB;AAAA,IACfC,SAASV,MAAMW,QAAQ,KAAK,CAAC;AAAA,IAC7BC,SAAS;AAAA,IACTC,eAAe;AAAA,IACfC,gBAAgB;AAAA,IAChBC,YAAY;AAAA,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TC,eAAe;AAAA,IACfE,YAAY;AAAA,EACd;AAAA,EACAsB,WAAW;AAAA,IACTC,OAAO;AAAA,IACPC,QAAQ;AAAA,IACRC,QAAQxC,MAAMW,QAAQ,GAAGX,MAAMuB,MAAMC,EAAE;AAAA,IACvCzB,cAAcC,MAAMC,MAAMwC;AAAAA,IAC1BtC,iBAAiBH,MAAMI,OAAOsC;AAAAA,EAChC;AACF,CAAC;"}
|
|
@@ -1,156 +1,73 @@
|
|
|
1
|
-
import { jsxs,
|
|
2
|
-
import { useState,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { jsxs, Fragment, jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useState, isValidElement } from "react";
|
|
3
|
+
import { HvTooltip, HvTypography, HvButton, HvDropDownMenu } from "@hitachivantara/uikit-react-core";
|
|
4
|
+
import { getColor } from "@hitachivantara/uikit-styles";
|
|
5
5
|
import { Info, Up, Down } from "@hitachivantara/uikit-react-icons";
|
|
6
|
-
import { getColor, theme } from "@hitachivantara/uikit-styles";
|
|
7
6
|
import { useClasses } from "./Node.styles.js";
|
|
8
7
|
import { staticClasses } from "./Node.styles.js";
|
|
9
8
|
import ParamRenderer from "./Parameters/ParamRenderer.js";
|
|
9
|
+
import { HvFlowBaseNode } from "./BaseNode.js";
|
|
10
|
+
import { useFlowNode } from "../hooks/useFlowNode.js";
|
|
10
11
|
import { useFlowContext } from "../hooks/useFlowContext.js";
|
|
11
|
-
const
|
|
12
|
-
if (type === "target") {
|
|
13
|
-
return edges.some((e) => e.target === id && e.targetHandle === idx.toString());
|
|
14
|
-
}
|
|
15
|
-
if (type === "source") {
|
|
16
|
-
return edges.some((e) => e.source === id && e.sourceHandle === idx.toString());
|
|
17
|
-
}
|
|
18
|
-
};
|
|
12
|
+
const renderedIcon = (actionIcon) => isValidElement(actionIcon) ? actionIcon : actionIcon?.();
|
|
19
13
|
const HvFlowNode = ({
|
|
20
14
|
id,
|
|
21
15
|
type,
|
|
16
|
+
headerItems,
|
|
22
17
|
description,
|
|
23
|
-
expanded = false,
|
|
24
|
-
params,
|
|
25
18
|
actions,
|
|
26
19
|
actionCallback,
|
|
27
20
|
maxVisibleActions = 1,
|
|
21
|
+
expanded = false,
|
|
22
|
+
params,
|
|
28
23
|
classes: classesProp,
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
children,
|
|
25
|
+
...props
|
|
31
26
|
}) => {
|
|
32
|
-
const [showParams, setShowParams] = useState(expanded);
|
|
33
|
-
const [showActions, setShowActions] = useState(false);
|
|
34
|
-
const reactFlowInstance = useReactFlow();
|
|
35
27
|
const {
|
|
36
|
-
classes
|
|
37
|
-
cx,
|
|
38
|
-
css
|
|
28
|
+
classes
|
|
39
29
|
} = useClasses(classesProp);
|
|
30
|
+
const [showParams, setShowParams] = useState(expanded);
|
|
31
|
+
const {
|
|
32
|
+
node
|
|
33
|
+
} = useFlowNode(id);
|
|
40
34
|
const {
|
|
41
35
|
nodeGroups,
|
|
42
36
|
nodeTypes,
|
|
43
37
|
defaultActions
|
|
44
38
|
} = useFlowContext();
|
|
45
|
-
const edges = useStore((s) => s.edges);
|
|
46
|
-
const nodes = useStore((s) => s.getNodes());
|
|
47
|
-
const node = nodes.find((n) => n.id === id);
|
|
48
39
|
const groupId = nodeTypes?.[type].meta?.groupId;
|
|
49
|
-
const
|
|
40
|
+
const subtitle = nodeTypes?.[type].meta?.label;
|
|
50
41
|
const groupLabel = groupId && nodeGroups && nodeGroups[groupId].label;
|
|
51
42
|
const inputs = nodeTypes?.[type]?.meta?.inputs;
|
|
52
43
|
const outputs = nodeTypes?.[type]?.meta?.outputs;
|
|
53
44
|
const icon = groupId && nodeGroups && nodeGroups[groupId].icon;
|
|
54
45
|
const colorProp = groupId && nodeGroups && nodeGroups[groupId].color;
|
|
55
46
|
const color = getColor(colorProp);
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
const newNodes = nodes.map((n) => {
|
|
58
|
-
if (n.id === id) {
|
|
59
|
-
if (Object.keys(n.data).length === 0) {
|
|
60
|
-
params?.forEach((param) => {
|
|
61
|
-
n.data[param.id] = param.value;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return n;
|
|
66
|
-
});
|
|
67
|
-
reactFlowInstance.setNodes(newNodes);
|
|
68
|
-
}, []);
|
|
69
|
-
const handleDefaultAction = useCallback((action) => {
|
|
70
|
-
if (!node)
|
|
71
|
-
return;
|
|
72
|
-
switch (action) {
|
|
73
|
-
case "delete":
|
|
74
|
-
reactFlowInstance.deleteElements({
|
|
75
|
-
nodes: [node]
|
|
76
|
-
});
|
|
77
|
-
break;
|
|
78
|
-
case "duplicate":
|
|
79
|
-
reactFlowInstance.addNodes([{
|
|
80
|
-
...node,
|
|
81
|
-
id: `${reactFlowInstance.getNodes().length + 1}`,
|
|
82
|
-
position: {
|
|
83
|
-
x: node.position.x,
|
|
84
|
-
y: node.position.y + (node.height || 0) + 20
|
|
85
|
-
},
|
|
86
|
-
selected: false,
|
|
87
|
-
zIndex: Number(theme.zIndices.overlay)
|
|
88
|
-
}]);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}, [node, reactFlowInstance]);
|
|
92
|
-
const hasParams = !!(params && params.length > 0);
|
|
93
|
-
if (!node)
|
|
94
|
-
return null;
|
|
95
47
|
const actsVisible = actions?.slice(0, maxVisibleActions);
|
|
96
48
|
const actsDropdown = actions?.slice(maxVisibleActions);
|
|
97
|
-
const
|
|
98
|
-
return /* @__PURE__ */ jsxs(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/* @__PURE__ */ jsx(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
/* @__PURE__ */ jsxs("div", { className: classes.groupContainer, children: [
|
|
106
|
-
icon,
|
|
107
|
-
/* @__PURE__ */ jsx(HvTypography, { variant: "title4", className: classes.group, children: groupLabel })
|
|
108
|
-
] }),
|
|
109
|
-
/* @__PURE__ */ jsxs("div", { style: {
|
|
110
|
-
display: "flex"
|
|
111
|
-
}, children: [
|
|
112
|
-
/* @__PURE__ */ jsx(HvTooltip, { title: /* @__PURE__ */ jsx(HvTypography, { children: description }), children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Info, {}) }) }),
|
|
113
|
-
/* @__PURE__ */ jsx(HvButton, { icon: true, disabled: !hasParams, onClick: () => setShowParams((p) => !p), children: showParams ? /* @__PURE__ */ jsx(Up, {}) : /* @__PURE__ */ jsx(Down, {}) })
|
|
114
|
-
] })
|
|
115
|
-
] }),
|
|
116
|
-
/* @__PURE__ */ jsxs("div", { className: classes.titleContainer, children: [
|
|
117
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(HvTypography, { children: title }) }),
|
|
49
|
+
const hasParams = !!(params && params.length > 0);
|
|
50
|
+
return /* @__PURE__ */ jsxs(HvFlowBaseNode, { id, type, title: groupLabel, icon, color, inputs, outputs, nodeActions: defaultActions, classes: classesProp, headerItems: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
51
|
+
headerItems,
|
|
52
|
+
description && /* @__PURE__ */ jsx(HvTooltip, { title: /* @__PURE__ */ jsx(HvTypography, { children: description }), children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Info, {}) }) }),
|
|
53
|
+
hasParams && /* @__PURE__ */ jsx(HvButton, { icon: true, onClick: () => setShowParams((p) => !p), children: showParams ? /* @__PURE__ */ jsx(Up, {}) : /* @__PURE__ */ jsx(Down, {}) })
|
|
54
|
+
] }), ...props, children: [
|
|
55
|
+
(subtitle || actsVisible?.length || actsDropdown?.length) && /* @__PURE__ */ jsxs("div", { className: classes.subtitleContainer, children: [
|
|
56
|
+
subtitle && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(HvTypography, { children: subtitle }) }),
|
|
118
57
|
/* @__PURE__ */ jsx("div", { className: classes.actions, children: actions?.length && actions?.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
119
58
|
actsVisible?.map((action) => /* @__PURE__ */ jsx(HvTooltip, { title: /* @__PURE__ */ jsx(HvTypography, { children: action.label }), children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(HvButton, { icon: true, onClick: (event) => {
|
|
120
|
-
actionCallback?.(event,
|
|
59
|
+
actionCallback?.(event, id, action);
|
|
121
60
|
}, "aria-label": action.label, children: renderedIcon(action.icon) }) }) }, action.id)),
|
|
122
61
|
actsDropdown && actsDropdown.length > 0 && /* @__PURE__ */ jsx(HvDropDownMenu, { keepOpened: false, dataList: actsDropdown?.map((action) => ({
|
|
123
62
|
id: action.id,
|
|
124
63
|
label: action.label
|
|
125
64
|
})), onClick: (event, action) => {
|
|
126
|
-
actionCallback?.(event,
|
|
65
|
+
actionCallback?.(event, id, action);
|
|
127
66
|
} })
|
|
128
67
|
] }) })
|
|
129
68
|
] }),
|
|
130
|
-
children
|
|
131
|
-
showParams && params && /* @__PURE__ */ jsx("div", { className: classes.paramsContainer, children: /* @__PURE__ */ jsx(ParamRenderer, { nodeId: id, params, data: node?.data }) })
|
|
132
|
-
inputs && inputs.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
133
|
-
/* @__PURE__ */ jsx("div", { className: classes.inputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Inputs" }) }),
|
|
134
|
-
/* @__PURE__ */ jsx("div", { className: classes.inputsContainer, children: inputs?.map((input, idx) => /* @__PURE__ */ jsxs("div", { className: classes.inputContainer, children: [
|
|
135
|
-
/* @__PURE__ */ jsx(Handle, { type: "target", isConnectableStart: false, id: `${idx}`, position: Position.Left, style: {
|
|
136
|
-
top: "auto",
|
|
137
|
-
bottom: (outputs?.length ? 80 : 18) + (outputs?.length || 0) * 29 + 29 * idx
|
|
138
|
-
} }),
|
|
139
|
-
/* @__PURE__ */ jsx(HvTypography, { children: input.label }),
|
|
140
|
-
input.isMandatory && !isInputConnected(id, "target", idx, edges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory })
|
|
141
|
-
] }, idx)) })
|
|
142
|
-
] }),
|
|
143
|
-
outputs && outputs.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
144
|
-
/* @__PURE__ */ jsx("div", { className: classes.outputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Outputs" }) }),
|
|
145
|
-
/* @__PURE__ */ jsx("div", { className: classes.outputsContainer, children: outputs?.map((output, idx) => /* @__PURE__ */ jsxs("div", { className: classes.outputContainer, children: [
|
|
146
|
-
/* @__PURE__ */ jsx(Handle, { type: "source", isConnectableEnd: false, id: `${idx}`, position: Position.Right, style: {
|
|
147
|
-
bottom: -10 + 29 * (outputs.length - idx),
|
|
148
|
-
top: "auto"
|
|
149
|
-
} }),
|
|
150
|
-
output.isMandatory && !isInputConnected(id, "source", idx, edges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory }),
|
|
151
|
-
/* @__PURE__ */ jsx(HvTypography, { children: output.label })
|
|
152
|
-
] }, idx)) })
|
|
153
|
-
] })
|
|
69
|
+
children,
|
|
70
|
+
showParams && params && /* @__PURE__ */ jsx("div", { className: classes.paramsContainer, children: /* @__PURE__ */ jsx(ParamRenderer, { nodeId: id, params, data: node?.data }) })
|
|
154
71
|
] });
|
|
155
72
|
};
|
|
156
73
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.js","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\n\nimport {\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useReactFlow,\n useStore,\n} from \"reactflow\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvBaseProps,\n HvButton,\n HvDropDownMenu,\n HvTooltip,\n HvTypography,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Down, Info, Up } from \"@hitachivantara/uikit-react-icons\";\nimport { getColor, theme } from \"@hitachivantara/uikit-styles\";\n\nimport { useFlowContext } from \"../hooks\";\nimport { HvFlowDefaultAction, HvFlowNodeParam } from \"../types\";\nimport { staticClasses, useClasses } from \"./Node.styles\";\nimport ParamRenderer from \"./Parameters/ParamRenderer\";\n\nexport { staticClasses as flowNodeClasses };\n\nexport type HvFlowNodeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvFlowNodeProps extends Omit<HvBaseProps, \"id\">, NodeProps {\n /** Node description */\n description: string;\n /** Node expanded */\n expanded?: boolean;\n /** Node parameters */\n params?: HvFlowNodeParam[];\n /** Node actions */\n actions?: HvActionGeneric[]; // HvFlowNodeActions[];\n /** Node action callback */\n actionCallback?: HvActionsGenericProps[\"actionsCallback\"];\n /** Node maximum number of actions visible */\n maxVisibleActions?: number;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFlowNodeClasses;\n}\n\nconst isInputConnected = (id, type, idx, edges) => {\n if (type === \"target\") {\n return edges.some(\n (e) => e.target === id && e.targetHandle === idx.toString()\n );\n }\n if (type === \"source\") {\n return edges.some(\n (e) => e.source === id && e.sourceHandle === idx.toString()\n );\n }\n};\n\nexport const HvFlowNode = ({\n id,\n type,\n description,\n expanded = false,\n params,\n actions,\n actionCallback,\n maxVisibleActions = 1,\n classes: classesProp,\n className,\n children,\n}: HvFlowNodeProps) => {\n const [showParams, setShowParams] = useState(expanded);\n const [showActions, setShowActions] = useState(false);\n const reactFlowInstance = useReactFlow();\n\n const { classes, cx, css } = useClasses(classesProp);\n\n const { nodeGroups, nodeTypes, defaultActions } = useFlowContext();\n const edges = useStore((s) => s.edges);\n const nodes = useStore((s) => s.getNodes());\n\n const node = nodes.find((n) => n.id === id);\n\n const groupId = nodeTypes?.[type].meta?.groupId;\n const title = nodeTypes?.[type].meta?.label;\n const groupLabel = groupId && nodeGroups && nodeGroups[groupId].label;\n\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon = groupId && nodeGroups && nodeGroups[groupId].icon;\n const colorProp = groupId && nodeGroups && nodeGroups[groupId].color;\n const color = getColor(colorProp);\n\n useEffect(() => {\n const newNodes = nodes.map((n) => {\n if (n.id === id) {\n if (Object.keys(n.data).length === 0) {\n params?.forEach((param) => {\n n.data[param.id] = param.value;\n });\n }\n }\n return n;\n });\n reactFlowInstance.setNodes(newNodes);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleDefaultAction = useCallback(\n (action: HvFlowDefaultAction) => {\n if (!node) return;\n\n switch (action) {\n case \"delete\":\n reactFlowInstance.deleteElements({ nodes: [node] });\n break;\n case \"duplicate\":\n reactFlowInstance.addNodes([\n {\n ...node,\n id: `${reactFlowInstance.getNodes().length + 1}`,\n position: {\n x: node.position.x,\n y: node.position.y + (node.height || 0) + 20,\n },\n selected: false,\n zIndex: Number(theme.zIndices.overlay),\n },\n ]);\n break;\n default:\n break;\n }\n },\n [node, reactFlowInstance]\n );\n\n const hasParams = !!(params && params.length > 0);\n\n if (!node) return null;\n\n const actsVisible = actions?.slice(0, maxVisibleActions);\n const actsDropdown = actions?.slice(maxVisibleActions);\n\n const renderedIcon = (actionIcon: HvActionGeneric[\"icon\"]) =>\n isValidElement(actionIcon) ? actionIcon : (actionIcon as Function)?.();\n\n return (\n <div\n className={cx(\n css({ border: `1px solid ${color}` }),\n classes.root,\n className\n )}\n onMouseEnter={() => setShowActions(true)}\n onMouseLeave={() => setShowActions(false)}\n >\n <NodeToolbar isVisible={showActions} offset={0}>\n {defaultActions?.map((action) => (\n <HvButton\n key={action.id}\n icon\n onClick={() => handleDefaultAction(action.id)}\n >\n {renderedIcon(action.icon)}\n </HvButton>\n ))}\n </NodeToolbar>\n <div\n className={cx(css({ backgroundColor: color }), classes.headerContainer)}\n >\n <div className={classes.groupContainer}>\n {icon}\n <HvTypography variant=\"title4\" className={classes.group}>\n {groupLabel}\n </HvTypography>\n </div>\n <div style={{ display: \"flex\" }}>\n <HvTooltip title={<HvTypography>{description}</HvTypography>}>\n <div>\n <Info />\n </div>\n </HvTooltip>\n <HvButton\n icon\n disabled={!hasParams}\n onClick={() => setShowParams((p) => !p)}\n >\n {showParams ? <Up /> : <Down />}\n </HvButton>\n </div>\n </div>\n <div className={classes.titleContainer}>\n <div>\n <HvTypography>{title}</HvTypography>\n </div>\n <div className={classes.actions}>\n {actions?.length && actions?.length > 0 && (\n <>\n {actsVisible?.map((action) => (\n <HvTooltip\n key={action.id}\n title={<HvTypography>{action.label}</HvTypography>}\n >\n <div>\n <HvButton\n icon\n onClick={(event) => {\n actionCallback?.(event, node.id, action);\n }}\n aria-label={action.label}\n >\n {renderedIcon(action.icon)}\n </HvButton>\n </div>\n </HvTooltip>\n ))}\n\n {actsDropdown && actsDropdown.length > 0 && (\n <HvDropDownMenu\n keepOpened={false}\n dataList={actsDropdown?.map((action) => ({\n id: action.id,\n label: action.label,\n }))}\n onClick={(event, action) => {\n actionCallback?.(event, node.id, action as HvActionGeneric);\n }}\n />\n )}\n </>\n )}\n </div>\n </div>\n {children && <div className={classes.contentContainer}>{children}</div>}\n {showParams && params && (\n <div className={classes.paramsContainer}>\n <ParamRenderer nodeId={id} params={params} data={node?.data} />\n </div>\n )}\n {inputs && inputs.length > 0 && (\n <>\n <div className={classes.inputsTitleContainer}>\n <HvTypography>Inputs</HvTypography>\n </div>\n\n <div className={classes.inputsContainer}>\n {inputs?.map((input, idx) => (\n <div className={classes.inputContainer} key={idx}>\n <Handle\n type=\"target\"\n isConnectableStart={false}\n id={`${idx}`}\n position={Position.Left}\n style={{\n top: \"auto\",\n bottom:\n (outputs?.length ? 80 : 18) +\n (outputs?.length || 0) * 29 +\n 29 * idx,\n }}\n />\n <HvTypography>{input.label}</HvTypography>\n {input.isMandatory &&\n !isInputConnected(id, \"target\", idx, edges) && (\n <div className={classes.mandatory} />\n )}\n </div>\n ))}\n </div>\n </>\n )}\n {outputs && outputs.length > 0 && (\n <>\n <div className={classes.outputsTitleContainer}>\n <HvTypography>Outputs</HvTypography>\n </div>\n <div className={classes.outputsContainer}>\n {outputs?.map((output, idx) => (\n <div className={classes.outputContainer} key={idx}>\n <Handle\n type=\"source\"\n isConnectableEnd={false}\n id={`${idx}`}\n position={Position.Right}\n style={{\n bottom: -10 + 29 * (outputs.length - idx),\n top: \"auto\",\n }}\n />\n {output.isMandatory &&\n !isInputConnected(id, \"source\", idx, edges) && (\n <div className={classes.mandatory} />\n )}\n <HvTypography>{output.label}</HvTypography>\n </div>\n ))}\n </div>\n </>\n )}\n </div>\n );\n};\n"],"names":["isInputConnected","id","type","idx","edges","some","e","target","targetHandle","toString","source","sourceHandle","HvFlowNode","description","expanded","params","actions","actionCallback","maxVisibleActions","classes","classesProp","className","children","showParams","setShowParams","useState","showActions","setShowActions","reactFlowInstance","useReactFlow","cx","css","useClasses","nodeGroups","nodeTypes","defaultActions","useFlowContext","useStore","s","nodes","getNodes","node","find","n","groupId","meta","title","label","groupLabel","inputs","outputs","icon","colorProp","color","getColor","useEffect","newNodes","map","Object","keys","data","length","forEach","param","value","setNodes","handleDefaultAction","useCallback","action","deleteElements","addNodes","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","hasParams","actsVisible","slice","actsDropdown","renderedIcon","actionIcon","isValidElement","border","root","backgroundColor","headerContainer","groupContainer","group","display","p","titleContainer","event","contentContainer","paramsContainer","inputsTitleContainer","inputsContainer","input","inputContainer","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;AAkDA,MAAMA,mBAAmBA,CAACC,IAAIC,MAAMC,KAAKC,UAAU;AACjD,MAAIF,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEC,WAAWN,MAAMK,EAAEE,iBAAiBL,IAAIM,SACnD,CAAA;AAAA,EACF;AACA,MAAIP,SAAS,UAAU;AACdE,WAAAA,MAAMC,KACVC,CAAAA,MAAMA,EAAEI,WAAWT,MAAMK,EAAEK,iBAAiBR,IAAIM,SACnD,CAAA;AAAA,EACF;AACF;AAEO,MAAMG,aAAa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AA,MAAA,KAfgB5C,GAgB9C,CACD,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Node.js","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","p","subtitleContainer","map","action","event","paramsContainer","data"],"mappings":";;;;;;;;;;;AA0CA,MAAMA,eAAeA,CAACC,eACpBC,eAAeD,UAAU,IAAIA,aAAcA;AAEtC,MAAME,aAAaA,CAAC;AAAA,EACzBC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC;AAAAA,EACAC,oBAAoB;AAAA,EACpBC,WAAW;AAAA,EACXC;AAAAA,EACAC,SAASC;AAAAA,EACTC;AAAAA,EACA,GAAGC;AACqB,MAAM;AACxB,QAAA;AAAA,IAAEH;AAAAA,EAAAA,IAAYI,WAAWH,WAAiC;AAChE,QAAM,CAACI,YAAYC,aAAa,IAAIC,SAAST,QAAQ;AAC/C,QAAA;AAAA,IAAEU;AAAAA,EAAAA,IAASC,YAAYlB,EAAE;AAEzB,QAAA;AAAA,IAAEmB;AAAAA,IAAYC;AAAAA,IAAWC;AAAAA,MAAmBC,eAAe;AACjE,QAAMC,UAAUH,YAAYnB,IAAI,EAAEuB,MAAMD;AACxC,QAAME,WAAWL,YAAYnB,IAAI,EAAEuB,MAAME;AACzC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