@hitachivantara/uikit-react-lab 5.16.5 → 5.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Flow/Node/BaseNode.cjs +29 -22
- package/dist/cjs/components/Flow/Node/BaseNode.cjs.map +1 -1
- package/dist/cjs/components/Flow/Node/Node.cjs +1 -3
- package/dist/cjs/components/Flow/Node/Node.cjs.map +1 -1
- package/dist/cjs/components/Flow/hooks/useFlowNode.cjs +26 -18
- package/dist/cjs/components/Flow/hooks/useFlowNode.cjs.map +1 -1
- package/dist/cjs/components/Flow/hooks/useFlowNodeMeta.cjs +11 -0
- package/dist/cjs/components/Flow/hooks/useFlowNodeMeta.cjs.map +1 -0
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/components/Flow/Node/BaseNode.js +30 -23
- package/dist/esm/components/Flow/Node/BaseNode.js.map +1 -1
- package/dist/esm/components/Flow/Node/Node.js +1 -3
- package/dist/esm/components/Flow/Node/Node.js.map +1 -1
- package/dist/esm/components/Flow/hooks/useFlowNode.js +28 -20
- package/dist/esm/components/Flow/hooks/useFlowNode.js.map +1 -1
- package/dist/esm/components/Flow/hooks/useFlowNodeMeta.js +11 -0
- package/dist/esm/components/Flow/hooks/useFlowNodeMeta.js.map +1 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +13 -4
- package/package.json +3 -3
|
@@ -7,14 +7,15 @@ const uid = require("uid");
|
|
|
7
7
|
const uikitReactCore = require("@hitachivantara/uikit-react-core");
|
|
8
8
|
const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
|
|
9
9
|
const uikitStyles = require("@hitachivantara/uikit-styles");
|
|
10
|
+
const useFlowNode = require("../hooks/useFlowNode.cjs");
|
|
10
11
|
const NodeMetaContext = require("../FlowContext/NodeMetaContext.cjs");
|
|
11
12
|
const BaseNode_styles = require("./BaseNode.styles.cjs");
|
|
12
|
-
const isInputConnected = (id, type,
|
|
13
|
+
const isInputConnected = (id, type, handleId, edges) => {
|
|
13
14
|
if (type === "target") {
|
|
14
|
-
return edges.some((e) => e.target === id && e.targetHandle ===
|
|
15
|
+
return edges.some((e) => e.target === id && e.targetHandle === handleId);
|
|
15
16
|
}
|
|
16
17
|
if (type === "source") {
|
|
17
|
-
return edges.some((e) => e.source === id && e.sourceHandle ===
|
|
18
|
+
return edges.some((e) => e.source === id && e.sourceHandle === handleId);
|
|
18
19
|
}
|
|
19
20
|
return false;
|
|
20
21
|
};
|
|
@@ -60,9 +61,9 @@ const HvFlowBaseNode = ({
|
|
|
60
61
|
cx,
|
|
61
62
|
css
|
|
62
63
|
} = BaseNode_styles.useClasses(classesProp);
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
64
|
+
const node = useFlowNode.useFlowNode(id);
|
|
65
|
+
const inputEdges = useFlowNode.useFlowNodeInputEdges(id);
|
|
66
|
+
const outputEdges = useFlowNode.useFlowNodeOutputEdges(id);
|
|
66
67
|
const handleDefaultAction = React.useCallback((action) => {
|
|
67
68
|
if (!node)
|
|
68
69
|
return;
|
|
@@ -122,25 +123,31 @@ const HvFlowBaseNode = ({
|
|
|
122
123
|
children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.contentContainer, children }),
|
|
123
124
|
inputs && inputs.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
124
125
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.inputsTitleContainer, children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: "Inputs" }) }),
|
|
125
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.inputsContainer, children: inputs?.map((input, idx) =>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.inputsContainer, children: inputs?.map((input, idx) => {
|
|
127
|
+
const handleId = input.id ?? idx.toString();
|
|
128
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.inputContainer, children: [
|
|
129
|
+
/* @__PURE__ */ jsxRuntime.jsx(ReactFlow.Handle, { type: "target", isConnectableStart: false, id: handleId, position: ReactFlow.Position.Left, style: {
|
|
130
|
+
top: "auto",
|
|
131
|
+
bottom: (outputs?.length ? 80 : 18) + (outputs?.length || 0) * 29 + 29 * idx
|
|
132
|
+
} }),
|
|
133
|
+
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: input.label }),
|
|
134
|
+
input.isMandatory && !isInputConnected(id, "target", handleId, inputEdges) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.mandatory })
|
|
135
|
+
] }, idx);
|
|
136
|
+
}) })
|
|
133
137
|
] }),
|
|
134
138
|
outputs && outputs.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
135
139
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.outputsTitleContainer, children: /* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: "Outputs" }) }),
|
|
136
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.outputsContainer, children: outputs?.map((output, idx) =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.outputsContainer, children: outputs?.map((output, idx) => {
|
|
141
|
+
const handleId = output.id ?? idx.toString();
|
|
142
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.outputContainer, children: [
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx(ReactFlow.Handle, { type: "source", isConnectableEnd: false, id: handleId, position: ReactFlow.Position.Right, style: {
|
|
144
|
+
bottom: -10 + 29 * (outputs.length - idx),
|
|
145
|
+
top: "auto"
|
|
146
|
+
} }),
|
|
147
|
+
output.isMandatory && !isInputConnected(id, "source", handleId, outputEdges) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.mandatory }),
|
|
148
|
+
/* @__PURE__ */ jsxRuntime.jsx(uikitReactCore.HvTypography, { children: output.label })
|
|
149
|
+
] }, idx);
|
|
150
|
+
}) })
|
|
144
151
|
] })
|
|
145
152
|
] });
|
|
146
153
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseNode.cjs","sources":["../../../../../src/components/Flow/Node/BaseNode.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\nimport {\n Edge,\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useEdges,\n useNodes,\n useReactFlow,\n} from \"reactflow\";\nimport { uid } from \"uid\";\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\";\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 = any>\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 = useEdges();\n const nodes = useNodes();\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: uid(),\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 const iconColor = isValidElement(icon)\n ? getColor(icon.props.color || \"base_dark\")\n : getColor(\"base_dark\");\n\n return (\n <div\n className={cx(\n \"nowheel\", // Disables the default canvas pan behaviour when scrolling inside the node\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\n className={cx(\n classes.titleContainer,\n css({ \"& svg *.color0\": { fill: iconColor } })\n )}\n >\n {icon}\n <HvTypography\n component=\"p\"\n variant=\"title4\"\n className={classes.title}\n >\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","Delete","Duplicate","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","useEdges","nodes","useNodes","node","find","n","handleDefaultAction","useCallback","action","callback","deleteElements","addNodes","uid","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","getColor","iconColor","props","jsxs","border","root","jsx","NodeToolbar","map","HvButton","backgroundColor","headerContainer","titleContainer","fill","HvTypography","display","contentContainer","length","Fragment","inputsTitleContainer","inputsContainer","input","inputContainer","Handle","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;;AAwDA,MAAMA,mBAAmBA,CACvBC,IACAC,MACAC,KACAC,UACG;AACH,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;AAEO,SAAA;AACT;AAEA,MAAMG,iBAAyC,CAC7C;AAAA,EAAEX,IAAI;AAAA,EAAUY,OAAO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A,cAAcO,EAAAA,UAAAA,MAAM3E,MAAM,CAAA;AAAA,QAC1B2E,MAAMO,eACL,CAAC/F,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxCqE,2BAAAA,IAAC,OAAI,EAAA,WAAW7C,QAAQoE,UACzB,CAAA;AAAA,MAAA,KAlBwC7F,GAmB7C,CACD,GACH;AAAA,IAAA,GACF;AAAA,IAEDuB,WAAWA,QAAQ0D,SAAS,KAEzBd,2BAAAA,KAAAe,WAAAA,UAAA,EAAA,UAAA;AAAA,MAAAZ,2BAAAA,IAAC,SAAI,WAAW7C,QAAQqE,uBACtB,UAACxB,2BAAA,IAAAQ,eAAA,cAAA,EAAa,qBAAO,EACvB,CAAA;AAAA,MACCR,2BAAA,IAAA,OAAA,EAAI,WAAW7C,QAAQsE,kBACrBxE,UAASiD,SAAAA,IAAI,CAACwB,QAAQhG,QACrBmE,2BAAAA,KAAC,OAAI,EAAA,WAAW1C,QAAQwE,iBACtB,UAAA;AAAA,QAAA3B,2BAAA,IAACiB,UACC,QAAA,EAAA,MAAK,UACL,kBAAkB,OAClB,IAAK,GAAEvF,GAAI,IACX,UAAUwF,UAAAA,SAASU,OACnB,OAAO;AAAA,UACLP,QAAQ,MAAM,MAAMpE,QAAQ0D,SAASjF;AAAAA,UACrC0F,KAAK;AAAA,QAAA,GACL;AAAA,QAEHM,OAAOJ,eACN,CAAC/F,iBAAiBC,IAAI,UAAUE,KAAKC,KAAK,KACxCqE,2BAAAA,IAAC,OAAI,EAAA,WAAW7C,QAAQoE,UACzB,CAAA;AAAA,QACHvB,2BAAAA,IAACQ,eAAAA,cAAckB,EAAAA,UAAAA,OAAOtF,MAAM,CAAA;AAAA,MAAA,KAfgBV,GAgB9C,CACD,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
1
|
+
{"version":3,"file":"BaseNode.cjs","sources":["../../../../../src/components/Flow/Node/BaseNode.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\nimport {\n Edge,\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useReactFlow,\n} from \"reactflow\";\nimport { uid } from \"uid\";\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\";\nimport {\n useFlowNode,\n useFlowNodeInputEdges,\n useFlowNodeOutputEdges,\n} from \"../hooks/useFlowNode\";\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 = any>\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 handleId: string,\n edges: Edge[]\n) => {\n if (type === \"target\") {\n return edges.some((e) => e.target === id && e.targetHandle === handleId);\n }\n if (type === \"source\") {\n return edges.some((e) => e.source === id && e.sourceHandle === handleId);\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 node = useFlowNode(id);\n const inputEdges = useFlowNodeInputEdges(id);\n const outputEdges = useFlowNodeOutputEdges(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: uid(),\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 const iconColor = isValidElement(icon)\n ? getColor(icon.props.color || \"base_dark\")\n : getColor(\"base_dark\");\n\n return (\n <div\n className={cx(\n \"nowheel\", // Disables the default canvas pan behaviour when scrolling inside the node\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\n className={cx(\n classes.titleContainer,\n css({ \"& svg *.color0\": { fill: iconColor } })\n )}\n >\n {icon}\n <HvTypography\n component=\"p\"\n variant=\"title4\"\n className={classes.title}\n >\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 const handleId = input.id ?? idx.toString();\n return (\n <div className={classes.inputContainer} key={idx}>\n <Handle\n type=\"target\"\n isConnectableStart={false}\n id={handleId}\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\", handleId, inputEdges) && (\n <div className={classes.mandatory} />\n )}\n </div>\n );\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 const handleId = output.id ?? idx.toString();\n return (\n <div className={classes.outputContainer} key={idx}>\n <Handle\n type=\"source\"\n isConnectableEnd={false}\n id={handleId}\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\", handleId, outputEdges) && (\n <div className={classes.mandatory} />\n )}\n <HvTypography>{output.label}</HvTypography>\n </div>\n );\n })}\n </div>\n </>\n )}\n </div>\n );\n};\n"],"names":["isInputConnected","id","type","handleId","edges","some","e","target","targetHandle","source","sourceHandle","defaultActions","label","icon","Delete","Duplicate","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","node","useFlowNode","inputEdges","useFlowNodeInputEdges","outputEdges","useFlowNodeOutputEdges","handleDefaultAction","useCallback","action","callback","deleteElements","nodes","addNodes","uid","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","getColor","iconColor","props","jsxs","border","root","jsx","NodeToolbar","map","HvButton","backgroundColor","headerContainer","titleContainer","fill","HvTypography","display","contentContainer","length","Fragment","inputsTitleContainer","inputsContainer","input","idx","toString","inputContainer","Handle","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;;;AA2DA,MAAMA,mBAAmBA,CACvBC,IACAC,MACAC,UACAC,UACG;AACH,MAAIF,SAAS,UAAU;AACdE,WAAAA,MAAMC,KAAMC,CAAMA,MAAAA,EAAEC,WAAWN,MAAMK,EAAEE,iBAAiBL,QAAQ;AAAA,EACzE;AACA,MAAID,SAAS,UAAU;AACdE,WAAAA,MAAMC,KAAMC,CAAMA,MAAAA,EAAEG,WAAWR,MAAMK,EAAEI,iBAAiBP,QAAQ;AAAA,EACzE;AAEO,SAAA;AACT;AAEA,MAAMQ,iBAAyC,CAC7C;AAAA,EAAEV,IAAI;AAAA,EAAUW,OAAO;AAAA,EAAUC,qCAAOC,gBAAM,QAAA,EAAA;AAAI,GAClD;AAAA,EAAEb,IAAI;AAAA,EAAaW,OAAO;AAAA,EAAaC,qCAAOE,gBAAS,WAAA,EAAA;AAAI,CAAC;AAG9D,MAAMC,eAAeA,CAACC,eACpBC,qBAAeD,UAAU,IAAIA,aAAcA;AAEtC,MAAME,iBAAiBA,CAAC;AAAA,EAC7BlB;AAAAA,EACAmB;A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CAAA,GACH;AAAA,IAAA,GACF;AAAA,IAEDhE,WAAWA,QAAQ2D,SAAS,KAEzBd,2BAAAA,KAAAe,WAAAA,UAAA,EAAA,UAAA;AAAA,MAAAZ,2BAAAA,IAAC,SAAI,WAAW9C,QAAQwE,uBACtB,UAAC1B,2BAAA,IAAAQ,eAAA,cAAA,EAAa,qBAAO,EACvB,CAAA;AAAA,MACAR,2BAAAA,IAAC,SAAI,WAAW9C,QAAQyE,kBACrB3E,UAASkD,SAAAA,IAAI,CAAC0B,QAAQZ,QAAQ;AAC7B,cAAMtF,WAAWkG,OAAOpG,MAAMwF,IAAIC,SAAS;AAC3C,eACGpB,2BAAAA,KAAA,OAAA,EAAI,WAAW3C,QAAQ2E,iBACtB,UAAA;AAAA,UAAC7B,2BAAAA,IAAAmB,UAAAA,QAAA,EACC,MAAK,UACL,kBAAkB,OAClB,IAAIzF,UACJ,UAAU0F,mBAASU,OACnB,OAAO;AAAA,YACLP,QAAQ,MAAM,MAAMvE,QAAQ2D,SAASK;AAAAA,YACrCM,KAAK;AAAA,UAAA,GACL;AAAA,UAEHM,OAAOJ,eACN,CAACjG,iBAAiBC,IAAI,UAAUE,UAAU4C,WAAW,KACnD0B,2BAAAA,IAAC,OAAI,EAAA,WAAW9C,QAAQuE,UACzB,CAAA;AAAA,UACHzB,2BAAAA,IAACQ,eAAAA,cAAcoB,EAAAA,UAAAA,OAAOzF,MAAM,CAAA;AAAA,QAAA,EAAA,GAfgB6E,GAgB9C;AAAA,MAEH,CAAA,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
@@ -31,9 +31,7 @@ const HvFlowNode = ({
|
|
|
31
31
|
classes
|
|
32
32
|
} = Node_styles.useClasses(classesProp);
|
|
33
33
|
const [showParams, setShowParams] = React.useState(expanded);
|
|
34
|
-
const
|
|
35
|
-
node
|
|
36
|
-
} = useFlowNode.useFlowNode(id);
|
|
34
|
+
const node = useFlowNode.useFlowNode(id);
|
|
37
35
|
const {
|
|
38
36
|
nodeGroups,
|
|
39
37
|
nodeTypes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.cjs","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import React, { isValidElement, useState } from \"react\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvButton,\n HvButtonProps,\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 type HvFlowNodeDefaults = {\n title?: string;\n subTitle?: string;\n color?: string;\n icon?: React.ReactNode;\n};\n\nexport interface HvFlowNodeProps<T = any>\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 set of node default values for when there are no groups to fetch this data from. */\n nodeDefaults?: HvFlowNodeDefaults;\n /** Props to be passed to the expand parameters button. */\n expandParamsButtonProps?: HvButtonProps;\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 nodeDefaults,\n classes: classesProp,\n children,\n expandParamsButtonProps,\n ...props\n}: HvFlowNodeProps<unknown>) => {\n const { classes } = useClasses(classesProp as HvFlowNodeClasses);\n const [showParams, setShowParams] = useState(expanded);\n const
|
|
1
|
+
{"version":3,"file":"Node.cjs","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import React, { isValidElement, useState } from \"react\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvButton,\n HvButtonProps,\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 type HvFlowNodeDefaults = {\n title?: string;\n subTitle?: string;\n color?: string;\n icon?: React.ReactNode;\n};\n\nexport interface HvFlowNodeProps<T = any>\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 set of node default values for when there are no groups to fetch this data from. */\n nodeDefaults?: HvFlowNodeDefaults;\n /** Props to be passed to the expand parameters button. */\n expandParamsButtonProps?: HvButtonProps;\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 nodeDefaults,\n classes: classesProp,\n children,\n expandParamsButtonProps,\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 || nodeDefaults?.subTitle;\n const groupLabel =\n (groupId && nodeGroups && nodeGroups[groupId].label) || nodeDefaults?.title;\n\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon =\n (groupId && nodeGroups && nodeGroups[groupId].icon) || nodeDefaults?.icon;\n const colorProp =\n (groupId && nodeGroups && nodeGroups[groupId].color) || nodeDefaults?.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 color=\"base_dark\" />\n </div>\n </HvTooltip>\n )}\n {hasParams && (\n <HvButton\n icon\n overrideIconColors={false}\n onClick={() => setShowParams((p) => !p)}\n aria-label={showParams ? \"Collapse\" : \"Expand\"}\n {...expandParamsButtonProps}\n >\n {showParams ? (\n <Up role=\"none\" color=\"base_dark\" />\n ) : (\n <Down role=\"none\" color=\"base_dark\" />\n )}\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 key={action.id} title={action.label}>\n <HvButton\n icon\n onClick={(event) => {\n actionCallback?.(event, id, action);\n }}\n aria-label={action.label}\n >\n {renderedIcon(action.icon)}\n </HvButton>\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","nodeDefaults","classes","classesProp","children","expandParamsButtonProps","props","useClasses","showParams","setShowParams","useState","node","useFlowNode","nodeGroups","nodeTypes","defaultActions","useFlowContext","groupId","meta","subtitle","label","subTitle","groupLabel","title","inputs","outputs","icon","colorProp","color","getColor","actsVisible","slice","actsDropdown","hasParams","length","jsxs","HvFlowBaseNode","jsx","HvTooltip","HvTypography","Info","HvButton","p","Up","Down","subtitleContainer","map","action","event","HvDropD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,UAAA;AACDA,2BAAAA,OAAOxD,IAAIuD,MAAM;AAAA,QACpC,GACA,cAAYA,OAAO3B,OAElBhC,UAAAA,aAAa2D,OAAOrB,IAAI,EAC3B,CAAA,EAAA,GATcqB,OAAOvD,EAUvB,CACD;AAAA,QAEAwC,gBAAgBA,aAAaE,SAAS,KACrCG,2BAAA,IAACY,eACC,gBAAA,EAAA,YAAY,OACZ,UAAUjB,cAAcc,IAAKC,CAAY,YAAA;AAAA,UACvCvD,IAAIuD,OAAOvD;AAAAA,UACX4B,OAAO2B,OAAO3B;AAAAA,QACd,EAAA,GACF,SAAS,CAAC4B,OAAOD,WAAW;AACTC,2BAAAA,OAAOxD,IAAIuD,MAA0B;AAAA,QAAA,GAG3D;AAAA,MAAA,EAAA,CACH,EAEJ,CAAA;AAAA,IAAA,GACF;AAAA,IAED3C;AAAAA,IACAI,cAAcR,UACZqC,2BAAAA,IAAA,OAAA,EAAI,WAAWnC,QAAQgD,iBACtB,UAACb,2BAAAA,IAAAc,cAAAA,SAAA,EAAc,QAAQ3D,IAAI,QAAgB,MAAMmB,MAAMyC,KAAK,CAAA,GAC9D;AAAA,EAEJ,EAAA,CAAA;AAEJ;;;"}
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
3
4
|
const ReactFlow = require("reactflow");
|
|
4
5
|
function useFlowNode(id) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
const nodeSelector = React.useCallback((state) => state.getNodes().find((n) => n.id === id), [id]);
|
|
7
|
+
return ReactFlow.useStore(nodeSelector);
|
|
8
|
+
}
|
|
9
|
+
function useFlowNodeInputEdges(id) {
|
|
10
|
+
const inputEdgesSelector = React.useCallback((state) => state.edges.filter((e) => e.target === id), [id]);
|
|
11
|
+
return ReactFlow.useStore(inputEdgesSelector);
|
|
12
|
+
}
|
|
13
|
+
function useFlowNodeOutputEdges(id) {
|
|
14
|
+
const outputEdgesSelector = React.useCallback((state) => state.edges.filter((e) => e.source === id), [id]);
|
|
15
|
+
return ReactFlow.useStore(outputEdgesSelector);
|
|
16
|
+
}
|
|
17
|
+
function useFlowNodeEdges(id) {
|
|
18
|
+
const edgesSelector = React.useCallback((state) => state.edges.filter((e) => e.source === id || e.target === id), [id]);
|
|
19
|
+
return ReactFlow.useStore(edgesSelector);
|
|
20
|
+
}
|
|
21
|
+
function useFlowNodeParents(id) {
|
|
22
|
+
const inputEdges = useFlowNodeInputEdges(id);
|
|
23
|
+
const parentNodesSelector = React.useCallback((state) => {
|
|
24
|
+
return inputEdges.map((e) => state.getNodes().find((n) => n.id === e.source)).filter((n) => n !== null);
|
|
25
|
+
}, [inputEdges]);
|
|
26
|
+
return ReactFlow.useStore(parentNodesSelector);
|
|
23
27
|
}
|
|
24
28
|
exports.useFlowNode = useFlowNode;
|
|
29
|
+
exports.useFlowNodeEdges = useFlowNodeEdges;
|
|
30
|
+
exports.useFlowNodeInputEdges = useFlowNodeInputEdges;
|
|
31
|
+
exports.useFlowNodeOutputEdges = useFlowNodeOutputEdges;
|
|
32
|
+
exports.useFlowNodeParents = useFlowNodeParents;
|
|
25
33
|
//# sourceMappingURL=useFlowNode.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFlowNode.cjs","sources":["../../../../../src/components/Flow/hooks/useFlowNode.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useFlowNode.cjs","sources":["../../../../../src/components/Flow/hooks/useFlowNode.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { Node, Edge, ReactFlowState, useStore } from \"reactflow\";\n\nexport function useFlowNode<T extends Node = Node>(id: string) {\n const nodeSelector = useCallback(\n (state: ReactFlowState) =>\n state.getNodes().find((n: Node): n is T => n.id === id),\n [id]\n );\n return useStore<T | undefined>(nodeSelector);\n}\n\nexport function useFlowNodeInputEdges(id: string) {\n const inputEdgesSelector = useCallback(\n (state: ReactFlowState) => state.edges.filter((e: Edge) => e.target === id),\n [id]\n );\n return useStore(inputEdgesSelector);\n}\n\nexport function useFlowNodeOutputEdges(id: string) {\n const outputEdgesSelector = useCallback(\n (state: ReactFlowState) => state.edges.filter((e: Edge) => e.source === id),\n [id]\n );\n return useStore(outputEdgesSelector);\n}\n\nexport function useFlowNodeEdges(id: string) {\n const edgesSelector = useCallback(\n (state: ReactFlowState) =>\n state.edges.filter((e: Edge) => e.source === id || e.target === id),\n [id]\n );\n return useStore(edgesSelector);\n}\n\nexport function useFlowNodeParents(id: string) {\n const inputEdges = useFlowNodeInputEdges(id);\n const parentNodesSelector = useCallback(\n (state: ReactFlowState) => {\n return inputEdges\n .map((e) => state.getNodes().find((n: Node) => n.id === e.source))\n .filter((n): n is Node => n !== null);\n },\n [inputEdges]\n );\n return useStore(parentNodesSelector);\n}\n"],"names":["useFlowNode","id","nodeSelector","useCallback","state","getNodes","find","n","useStore","useFlowNodeInputEdges","inputEdgesSelector","edges","filter","e","target","useFlowNodeOutputEdges","outputEdgesSelector","source","useFlowNodeEdges","edgesSelector","useFlowNodeParents","inputEdges","parentNodesSelector","map"],"mappings":";;;;AAGO,SAASA,YAAmCC,IAAY;AAC7D,QAAMC,eAAeC,MAAAA,YACnB,CAACC,UACCA,MAAMC,WAAWC,KAAK,CAACC,MAAoBA,EAAEN,OAAOA,EAAE,GACxD,CAACA,EAAE,CACL;AACA,SAAOO,UAAAA,SAAwBN,YAAY;AAC7C;AAEO,SAASO,sBAAsBR,IAAY;AAChD,QAAMS,qBAAqBP,MAAAA,YACzB,CAACC,UAA0BA,MAAMO,MAAMC,OAAO,CAACC,MAAYA,EAAEC,WAAWb,EAAE,GAC1E,CAACA,EAAE,CACL;AACA,SAAOO,UAAAA,SAASE,kBAAkB;AACpC;AAEO,SAASK,uBAAuBd,IAAY;AACjD,QAAMe,sBAAsBb,MAAAA,YAC1B,CAACC,UAA0BA,MAAMO,MAAMC,OAAO,CAACC,MAAYA,EAAEI,WAAWhB,EAAE,GAC1E,CAACA,EAAE,CACL;AACA,SAAOO,UAAAA,SAASQ,mBAAmB;AACrC;AAEO,SAASE,iBAAiBjB,IAAY;AAC3C,QAAMkB,gBAAgBhB,MAAAA,YACpB,CAACC,UACCA,MAAMO,MAAMC,OAAO,CAACC,MAAYA,EAAEI,WAAWhB,MAAMY,EAAEC,WAAWb,EAAE,GACpE,CAACA,EAAE,CACL;AACA,SAAOO,UAAAA,SAASW,aAAa;AAC/B;AAEO,SAASC,mBAAmBnB,IAAY;AACvCoB,QAAAA,aAAaZ,sBAAsBR,EAAE;AACrCqB,QAAAA,sBAAsBnB,kBAC1B,CAACC,UAA0B;AACzB,WAAOiB,WACJE,IAAKV,CAAAA,MAAMT,MAAMC,SAAS,EAAEC,KAAK,CAACC,MAAYA,EAAEN,OAAOY,EAAEI,MAAM,CAAC,EAChEL,OAAO,CAACL,MAAiBA,MAAM,IAAI;AAAA,EAAA,GAExC,CAACc,UAAU,CACb;AACA,SAAOb,UAAAA,SAASc,mBAAmB;AACrC;;;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const NodeMetaContext = require("../FlowContext/NodeMetaContext.cjs");
|
|
4
|
+
function useFlowNodeMeta(id) {
|
|
5
|
+
const {
|
|
6
|
+
registry
|
|
7
|
+
} = NodeMetaContext.useNodeMetaRegistry();
|
|
8
|
+
return registry[id];
|
|
9
|
+
}
|
|
10
|
+
exports.useFlowNodeMeta = useFlowNodeMeta;
|
|
11
|
+
//# sourceMappingURL=useFlowNodeMeta.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFlowNodeMeta.cjs","sources":["../../../../../src/components/Flow/hooks/useFlowNodeMeta.ts"],"sourcesContent":["import { useNodeMetaRegistry } from \"../FlowContext/NodeMetaContext\";\n\nexport function useFlowNodeMeta(id: string) {\n const { registry } = useNodeMetaRegistry();\n\n return registry[id];\n}\n"],"names":["useFlowNodeMeta","id","registry","useNodeMetaRegistry"],"mappings":";;;AAEO,SAASA,gBAAgBC,IAAY;AACpC,QAAA;AAAA,IAAEC;AAAAA,MAAaC,gBAAoB,oBAAA;AAEzC,SAAOD,SAASD,EAAE;AACpB;;"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ const Node_styles = require("./components/Flow/Node/Node.styles.cjs");
|
|
|
28
28
|
const Node = require("./components/Flow/Node/Node.cjs");
|
|
29
29
|
const useFlowNode = require("./components/Flow/hooks/useFlowNode.cjs");
|
|
30
30
|
const useFlowContext = require("./components/Flow/hooks/useFlowContext.cjs");
|
|
31
|
+
const useFlowNodeMeta = require("./components/Flow/hooks/useFlowNodeMeta.cjs");
|
|
31
32
|
exports.stepNavigationClasses = StepNavigation_styles.staticClasses;
|
|
32
33
|
exports.HvStepNavigation = StepNavigation.HvStepNavigation;
|
|
33
34
|
exports.wizardClasses = Wizard_styles.staticClasses;
|
|
@@ -55,5 +56,10 @@ exports.HvFlowBaseNode = BaseNode.HvFlowBaseNode;
|
|
|
55
56
|
exports.flowNodeClasses = Node_styles.staticClasses;
|
|
56
57
|
exports.HvFlowNode = Node.HvFlowNode;
|
|
57
58
|
exports.useFlowNode = useFlowNode.useFlowNode;
|
|
59
|
+
exports.useFlowNodeEdges = useFlowNode.useFlowNodeEdges;
|
|
60
|
+
exports.useFlowNodeInputEdges = useFlowNode.useFlowNodeInputEdges;
|
|
61
|
+
exports.useFlowNodeOutputEdges = useFlowNode.useFlowNodeOutputEdges;
|
|
62
|
+
exports.useFlowNodeParents = useFlowNode.useFlowNodeParents;
|
|
58
63
|
exports.useFlowContext = useFlowContext.useFlowContext;
|
|
64
|
+
exports.useFlowNodeMeta = useFlowNodeMeta.useFlowNodeMeta;
|
|
59
65
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState, useCallback, isValidElement } from "react";
|
|
3
|
-
import { useReactFlow,
|
|
3
|
+
import { useReactFlow, NodeToolbar, Handle, Position } from "reactflow";
|
|
4
4
|
import { uid } from "uid";
|
|
5
5
|
import { HvButton, HvTypography } from "@hitachivantara/uikit-react-core";
|
|
6
6
|
import { Delete, Duplicate } from "@hitachivantara/uikit-react-icons";
|
|
7
7
|
import { theme, getColor } from "@hitachivantara/uikit-styles";
|
|
8
|
+
import { useFlowNode, useFlowNodeInputEdges, useFlowNodeOutputEdges } from "../hooks/useFlowNode.js";
|
|
8
9
|
import { useNodeMetaRegistry } from "../FlowContext/NodeMetaContext.js";
|
|
9
10
|
import { useClasses } from "./BaseNode.styles.js";
|
|
10
11
|
import { staticClasses } from "./BaseNode.styles.js";
|
|
11
|
-
const isInputConnected = (id, type,
|
|
12
|
+
const isInputConnected = (id, type, handleId, edges) => {
|
|
12
13
|
if (type === "target") {
|
|
13
|
-
return edges.some((e) => e.target === id && e.targetHandle ===
|
|
14
|
+
return edges.some((e) => e.target === id && e.targetHandle === handleId);
|
|
14
15
|
}
|
|
15
16
|
if (type === "source") {
|
|
16
|
-
return edges.some((e) => e.source === id && e.sourceHandle ===
|
|
17
|
+
return edges.some((e) => e.source === id && e.sourceHandle === handleId);
|
|
17
18
|
}
|
|
18
19
|
return false;
|
|
19
20
|
};
|
|
@@ -59,9 +60,9 @@ const HvFlowBaseNode = ({
|
|
|
59
60
|
cx,
|
|
60
61
|
css
|
|
61
62
|
} = useClasses(classesProp);
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
63
|
+
const node = useFlowNode(id);
|
|
64
|
+
const inputEdges = useFlowNodeInputEdges(id);
|
|
65
|
+
const outputEdges = useFlowNodeOutputEdges(id);
|
|
65
66
|
const handleDefaultAction = useCallback((action) => {
|
|
66
67
|
if (!node)
|
|
67
68
|
return;
|
|
@@ -121,25 +122,31 @@ const HvFlowBaseNode = ({
|
|
|
121
122
|
children && /* @__PURE__ */ jsx("div", { className: classes.contentContainer, children }),
|
|
122
123
|
inputs && inputs.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
123
124
|
/* @__PURE__ */ jsx("div", { className: classes.inputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Inputs" }) }),
|
|
124
|
-
/* @__PURE__ */ jsx("div", { className: classes.inputsContainer, children: inputs?.map((input, idx) =>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
/* @__PURE__ */ jsx("div", { className: classes.inputsContainer, children: inputs?.map((input, idx) => {
|
|
126
|
+
const handleId = input.id ?? idx.toString();
|
|
127
|
+
return /* @__PURE__ */ jsxs("div", { className: classes.inputContainer, children: [
|
|
128
|
+
/* @__PURE__ */ jsx(Handle, { type: "target", isConnectableStart: false, id: handleId, position: Position.Left, style: {
|
|
129
|
+
top: "auto",
|
|
130
|
+
bottom: (outputs?.length ? 80 : 18) + (outputs?.length || 0) * 29 + 29 * idx
|
|
131
|
+
} }),
|
|
132
|
+
/* @__PURE__ */ jsx(HvTypography, { children: input.label }),
|
|
133
|
+
input.isMandatory && !isInputConnected(id, "target", handleId, inputEdges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory })
|
|
134
|
+
] }, idx);
|
|
135
|
+
}) })
|
|
132
136
|
] }),
|
|
133
137
|
outputs && outputs.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
134
138
|
/* @__PURE__ */ jsx("div", { className: classes.outputsTitleContainer, children: /* @__PURE__ */ jsx(HvTypography, { children: "Outputs" }) }),
|
|
135
|
-
/* @__PURE__ */ jsx("div", { className: classes.outputsContainer, children: outputs?.map((output, idx) =>
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
/* @__PURE__ */ jsx("div", { className: classes.outputsContainer, children: outputs?.map((output, idx) => {
|
|
140
|
+
const handleId = output.id ?? idx.toString();
|
|
141
|
+
return /* @__PURE__ */ jsxs("div", { className: classes.outputContainer, children: [
|
|
142
|
+
/* @__PURE__ */ jsx(Handle, { type: "source", isConnectableEnd: false, id: handleId, position: Position.Right, style: {
|
|
143
|
+
bottom: -10 + 29 * (outputs.length - idx),
|
|
144
|
+
top: "auto"
|
|
145
|
+
} }),
|
|
146
|
+
output.isMandatory && !isInputConnected(id, "source", handleId, outputEdges) && /* @__PURE__ */ jsx("div", { className: classes.mandatory }),
|
|
147
|
+
/* @__PURE__ */ jsx(HvTypography, { children: output.label })
|
|
148
|
+
] }, idx);
|
|
149
|
+
}) })
|
|
143
150
|
] })
|
|
144
151
|
] });
|
|
145
152
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseNode.js","sources":["../../../../../src/components/Flow/Node/BaseNode.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\nimport {\n Edge,\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useEdges,\n useNodes,\n useReactFlow,\n} from \"reactflow\";\nimport { uid } from \"uid\";\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\";\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 = any>\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 = useEdges();\n const nodes = useNodes();\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: uid(),\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 const iconColor = isValidElement(icon)\n ? getColor(icon.props.color || \"base_dark\")\n : getColor(\"base_dark\");\n\n return (\n <div\n className={cx(\n \"nowheel\", // Disables the default canvas pan behaviour when scrolling inside the node\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\n className={cx(\n classes.titleContainer,\n css({ \"& svg *.color0\": { fill: iconColor } })\n )}\n >\n {icon}\n <HvTypography\n component=\"p\"\n variant=\"title4\"\n className={classes.title}\n >\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","useEdges","nodes","useNodes","node","find","n","handleDefaultAction","useCallback","action","callback","deleteElements","addNodes","uid","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","getColor","iconColor","props","border","root","map","backgroundColor","headerContainer","titleContainer","fill","display","contentContainer","length","inputsTitleContainer","inputsContainer","input","inputContainer","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;AAwDA,MAAMA,mBAAmBA,CACvBC,IACAC,MACAC,KACAC,UACG;AACH,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;AAEO,SAAA;AACT;AAEA,MAAMG,iBAAyC,CAC7C;AAAA,EAAEX,IAAI;AAAA,EAAUY,OAAO;AAAA,EAAUC,0BAAO,QAAM,EAAA;AAAI,GAClD;AAAA,EAAEb,IAAI;AAAA,EAAaY,OAAO;AAAA,EAAaC,0BAAO,WAAS,EAAA;AAAI,CAAC;AAG9D,MAAMC,eAAeA,CAACC,eACpBC,eAAeD,UAAU,IAAIA,aAAcA;AAEtC,MAAME,iBAAiBA,CAAC;AAAA,EAC7BjB;AAAAA,EACAkB;AAAAA,EACAC;AAAAA,EACAN;AAAAA,EACAO,OAAOC;AAAAA,EACPC;AAAAA,EACAC;AAAAA,EACAC,cAAcb;AAAAA,EACdc,SAASC;AAAAA,EACTC;AAAAA,EACAC;AAC4B,MAAM;AAC5B,QAAA;AAAA,IAAEC;AAAAA,IAAcC;AAAAA,MAAmBC,oBAAoB;AAC7DC,YAAU,MAAM;AACdH,iBAAa7B,IAAI;AAAA,MAAEY,OAAOM,SAAS;AAAA,MAAII;AAAAA,MAAQC;AAAAA,IAAAA,CAAS;AACjD,WAAA,MAAMO,eAAe9B,EAAE;AAAA,EAAA,GAC7B,CAACA,IAAIk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AA,MAAA,KAfgBV,GAgB9C,CACD,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"BaseNode.js","sources":["../../../../../src/components/Flow/Node/BaseNode.tsx"],"sourcesContent":["import { isValidElement, useCallback, useEffect, useState } from \"react\";\nimport {\n Edge,\n Handle,\n NodeProps,\n NodeToolbar,\n Position,\n useReactFlow,\n} from \"reactflow\";\nimport { uid } from \"uid\";\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\";\nimport {\n useFlowNode,\n useFlowNodeInputEdges,\n useFlowNodeOutputEdges,\n} from \"../hooks/useFlowNode\";\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 = any>\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 handleId: string,\n edges: Edge[]\n) => {\n if (type === \"target\") {\n return edges.some((e) => e.target === id && e.targetHandle === handleId);\n }\n if (type === \"source\") {\n return edges.some((e) => e.source === id && e.sourceHandle === handleId);\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 node = useFlowNode(id);\n const inputEdges = useFlowNodeInputEdges(id);\n const outputEdges = useFlowNodeOutputEdges(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: uid(),\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 const iconColor = isValidElement(icon)\n ? getColor(icon.props.color || \"base_dark\")\n : getColor(\"base_dark\");\n\n return (\n <div\n className={cx(\n \"nowheel\", // Disables the default canvas pan behaviour when scrolling inside the node\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\n className={cx(\n classes.titleContainer,\n css({ \"& svg *.color0\": { fill: iconColor } })\n )}\n >\n {icon}\n <HvTypography\n component=\"p\"\n variant=\"title4\"\n className={classes.title}\n >\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 const handleId = input.id ?? idx.toString();\n return (\n <div className={classes.inputContainer} key={idx}>\n <Handle\n type=\"target\"\n isConnectableStart={false}\n id={handleId}\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\", handleId, inputEdges) && (\n <div className={classes.mandatory} />\n )}\n </div>\n );\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 const handleId = output.id ?? idx.toString();\n return (\n <div className={classes.outputContainer} key={idx}>\n <Handle\n type=\"source\"\n isConnectableEnd={false}\n id={handleId}\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\", handleId, outputEdges) && (\n <div className={classes.mandatory} />\n )}\n <HvTypography>{output.label}</HvTypography>\n </div>\n );\n })}\n </div>\n </>\n )}\n </div>\n );\n};\n"],"names":["isInputConnected","id","type","handleId","edges","some","e","target","targetHandle","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","node","useFlowNode","inputEdges","useFlowNodeInputEdges","outputEdges","useFlowNodeOutputEdges","handleDefaultAction","useCallback","action","callback","deleteElements","nodes","addNodes","uid","position","x","y","height","selected","zIndex","Number","theme","zIndices","overlay","getColor","iconColor","props","border","root","map","backgroundColor","headerContainer","titleContainer","fill","display","contentContainer","length","inputsTitleContainer","inputsContainer","input","idx","toString","inputContainer","Position","Left","top","bottom","isMandatory","mandatory","outputsTitleContainer","outputsContainer","output","outputContainer","Right"],"mappings":";;;;;;;;;;;AA2DA,MAAMA,mBAAmBA,CACvBC,IACAC,MACAC,UACAC,UACG;AACH,MAAIF,SAAS,UAAU;AACdE,WAAAA,MAAMC,KAAMC,CAAMA,MAAAA,EAAEC,WAAWN,MAAMK,EAAEE,iBAAiBL,QAAQ;AAAA,EACzE;AACA,MAAID,SAAS,UAAU;AACdE,WAAAA,MAAMC,KAAMC,CAAMA,MAAAA,EAAEG,WAAWR,MAAMK,EAAEI,iBAAiBP,QAAQ;AAAA,EACzE;AAEO,SAAA;AACT;AAEA,MAAMQ,iBAAyC,CAC7C;AAAA,EAAEV,IAAI;AAAA,EAAUW,OAAO;AAAA,EAAUC,0BAAO,QAAM,EAAA;AAAI,GAClD;AAAA,EAAEZ,IAAI;AAAA,EAAaW,OAAO;AAAA,EAAaC,0BAAO,WAAS,EAAA;AAAI,CAAC;AAG9D,MAAMC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AAC,oBAAA,cAAA,EAAa,qBAAO,EACvB,CAAA;AAAA,MACA,oBAAC,SAAI,WAAWjE,QAAQkE,kBACrBpE,UAAS+C,SAAAA,IAAI,CAACsB,QAAQX,QAAQ;AAC7B,cAAM9E,WAAWyF,OAAO3F,MAAMgF,IAAIC,SAAS;AAC3C,eACG,qBAAA,OAAA,EAAI,WAAWzD,QAAQoE,iBACtB,UAAA;AAAA,UAAC,oBAAA,QAAA,EACC,MAAK,UACL,kBAAkB,OAClB,IAAI1F,UACJ,UAAUiF,SAASU,OACnB,OAAO;AAAA,YACLP,QAAQ,MAAM,MAAMhE,QAAQsD,SAASI;AAAAA,YACrCK,KAAK;AAAA,UAAA,GACL;AAAA,UAEHM,OAAOJ,eACN,CAACxF,iBAAiBC,IAAI,UAAUE,UAAU0C,WAAW,KACnD,oBAAC,OAAI,EAAA,WAAWpB,QAAQgE,UACzB,CAAA;AAAA,UACH,oBAAC,cAAcG,EAAAA,UAAAA,OAAOhF,MAAM,CAAA;AAAA,QAAA,EAAA,GAfgBqE,GAgB9C;AAAA,MAEH,CAAA,GACH;AAAA,IAAA,GACF;AAAA,EAEJ,EAAA,CAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.js","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import React, { isValidElement, useState } from \"react\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvButton,\n HvButtonProps,\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 type HvFlowNodeDefaults = {\n title?: string;\n subTitle?: string;\n color?: string;\n icon?: React.ReactNode;\n};\n\nexport interface HvFlowNodeProps<T = any>\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 set of node default values for when there are no groups to fetch this data from. */\n nodeDefaults?: HvFlowNodeDefaults;\n /** Props to be passed to the expand parameters button. */\n expandParamsButtonProps?: HvButtonProps;\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 nodeDefaults,\n classes: classesProp,\n children,\n expandParamsButtonProps,\n ...props\n}: HvFlowNodeProps<unknown>) => {\n const { classes } = useClasses(classesProp as HvFlowNodeClasses);\n const [showParams, setShowParams] = useState(expanded);\n const
|
|
1
|
+
{"version":3,"file":"Node.js","sources":["../../../../../src/components/Flow/Node/Node.tsx"],"sourcesContent":["import React, { isValidElement, useState } from \"react\";\n\nimport {\n ExtractNames,\n HvActionGeneric,\n HvActionsGenericProps,\n HvButton,\n HvButtonProps,\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 type HvFlowNodeDefaults = {\n title?: string;\n subTitle?: string;\n color?: string;\n icon?: React.ReactNode;\n};\n\nexport interface HvFlowNodeProps<T = any>\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 set of node default values for when there are no groups to fetch this data from. */\n nodeDefaults?: HvFlowNodeDefaults;\n /** Props to be passed to the expand parameters button. */\n expandParamsButtonProps?: HvButtonProps;\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 nodeDefaults,\n classes: classesProp,\n children,\n expandParamsButtonProps,\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 || nodeDefaults?.subTitle;\n const groupLabel =\n (groupId && nodeGroups && nodeGroups[groupId].label) || nodeDefaults?.title;\n\n const inputs = nodeTypes?.[type]?.meta?.inputs;\n const outputs = nodeTypes?.[type]?.meta?.outputs;\n const icon =\n (groupId && nodeGroups && nodeGroups[groupId].icon) || nodeDefaults?.icon;\n const colorProp =\n (groupId && nodeGroups && nodeGroups[groupId].color) || nodeDefaults?.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 color=\"base_dark\" />\n </div>\n </HvTooltip>\n )}\n {hasParams && (\n <HvButton\n icon\n overrideIconColors={false}\n onClick={() => setShowParams((p) => !p)}\n aria-label={showParams ? \"Collapse\" : \"Expand\"}\n {...expandParamsButtonProps}\n >\n {showParams ? (\n <Up role=\"none\" color=\"base_dark\" />\n ) : (\n <Down role=\"none\" color=\"base_dark\" />\n )}\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 key={action.id} title={action.label}>\n <HvButton\n icon\n onClick={(event) => {\n actionCallback?.(event, id, action);\n }}\n aria-label={action.label}\n >\n {renderedIcon(action.icon)}\n </HvButton>\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","nodeDefaults","classes","classesProp","children","expandParamsButtonProps","props","useClasses","showParams","setShowParams","useState","node","useFlowNode","nodeGroups","nodeTypes","defaultActions","useFlowContext","groupId","meta","subtitle","label","subTitle","groupLabel","title","inputs","outputs","icon","colorProp","color","getColor","actsVisible","slice","actsDropdown","hasParams","length","p","subtitleContainer","map","action","event","paramsContainer","data"],"mappings":";;;;;;;;;;;AAsDA,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;AAAAA,EACAC,SAASC;AAAAA,EACTC;AAAAA,EACAC;AAAAA,EACA,GAAGC;AACqB,MAAM;AACxB,QAAA;AAAA,IAAEJ;AAAAA,EAAAA,IAAYK,WAAWJ,WAAiC;AAChE,QAAM,CAACK,YAAYC,aAAa,IAAIC,SAASX,QAAQ;AAC/CY,QAAAA,OAAOC,YAAYpB,EAAE;AAErB,QAAA;AAAA,IAAEqB;AAAAA,IAAYC;AAAAA,IAAWC;AAAAA,MAAmBC,eAAe;AACjE,QAAMC,UAAUH,YAAYrB,IAAI,EAAEyB,MAAMD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|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const nodeSelector = useCallback((state) => state.getNodes().find((n) => n.id === id), [id]);
|
|
5
|
+
return useStore(nodeSelector);
|
|
6
|
+
}
|
|
7
|
+
function useFlowNodeInputEdges(id) {
|
|
8
|
+
const inputEdgesSelector = useCallback((state) => state.edges.filter((e) => e.target === id), [id]);
|
|
9
|
+
return useStore(inputEdgesSelector);
|
|
10
|
+
}
|
|
11
|
+
function useFlowNodeOutputEdges(id) {
|
|
12
|
+
const outputEdgesSelector = useCallback((state) => state.edges.filter((e) => e.source === id), [id]);
|
|
13
|
+
return useStore(outputEdgesSelector);
|
|
14
|
+
}
|
|
15
|
+
function useFlowNodeEdges(id) {
|
|
16
|
+
const edgesSelector = useCallback((state) => state.edges.filter((e) => e.source === id || e.target === id), [id]);
|
|
17
|
+
return useStore(edgesSelector);
|
|
18
|
+
}
|
|
19
|
+
function useFlowNodeParents(id) {
|
|
20
|
+
const inputEdges = useFlowNodeInputEdges(id);
|
|
21
|
+
const parentNodesSelector = useCallback((state) => {
|
|
22
|
+
return inputEdges.map((e) => state.getNodes().find((n) => n.id === e.source)).filter((n) => n !== null);
|
|
23
|
+
}, [inputEdges]);
|
|
24
|
+
return useStore(parentNodesSelector);
|
|
21
25
|
}
|
|
22
26
|
export {
|
|
23
|
-
useFlowNode
|
|
27
|
+
useFlowNode,
|
|
28
|
+
useFlowNodeEdges,
|
|
29
|
+
useFlowNodeInputEdges,
|
|
30
|
+
useFlowNodeOutputEdges,
|
|
31
|
+
useFlowNodeParents
|
|
24
32
|
};
|
|
25
33
|
//# sourceMappingURL=useFlowNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFlowNode.js","sources":["../../../../../src/components/Flow/hooks/useFlowNode.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useFlowNode.js","sources":["../../../../../src/components/Flow/hooks/useFlowNode.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { Node, Edge, ReactFlowState, useStore } from \"reactflow\";\n\nexport function useFlowNode<T extends Node = Node>(id: string) {\n const nodeSelector = useCallback(\n (state: ReactFlowState) =>\n state.getNodes().find((n: Node): n is T => n.id === id),\n [id]\n );\n return useStore<T | undefined>(nodeSelector);\n}\n\nexport function useFlowNodeInputEdges(id: string) {\n const inputEdgesSelector = useCallback(\n (state: ReactFlowState) => state.edges.filter((e: Edge) => e.target === id),\n [id]\n );\n return useStore(inputEdgesSelector);\n}\n\nexport function useFlowNodeOutputEdges(id: string) {\n const outputEdgesSelector = useCallback(\n (state: ReactFlowState) => state.edges.filter((e: Edge) => e.source === id),\n [id]\n );\n return useStore(outputEdgesSelector);\n}\n\nexport function useFlowNodeEdges(id: string) {\n const edgesSelector = useCallback(\n (state: ReactFlowState) =>\n state.edges.filter((e: Edge) => e.source === id || e.target === id),\n [id]\n );\n return useStore(edgesSelector);\n}\n\nexport function useFlowNodeParents(id: string) {\n const inputEdges = useFlowNodeInputEdges(id);\n const parentNodesSelector = useCallback(\n (state: ReactFlowState) => {\n return inputEdges\n .map((e) => state.getNodes().find((n: Node) => n.id === e.source))\n .filter((n): n is Node => n !== null);\n },\n [inputEdges]\n );\n return useStore(parentNodesSelector);\n}\n"],"names":["useFlowNode","id","nodeSelector","useCallback","state","getNodes","find","n","useStore","useFlowNodeInputEdges","inputEdgesSelector","edges","filter","e","target","useFlowNodeOutputEdges","outputEdgesSelector","source","useFlowNodeEdges","edgesSelector","useFlowNodeParents","inputEdges","parentNodesSelector","map"],"mappings":";;AAGO,SAASA,YAAmCC,IAAY;AAC7D,QAAMC,eAAeC,YACnB,CAACC,UACCA,MAAMC,WAAWC,KAAK,CAACC,MAAoBA,EAAEN,OAAOA,EAAE,GACxD,CAACA,EAAE,CACL;AACA,SAAOO,SAAwBN,YAAY;AAC7C;AAEO,SAASO,sBAAsBR,IAAY;AAChD,QAAMS,qBAAqBP,YACzB,CAACC,UAA0BA,MAAMO,MAAMC,OAAO,CAACC,MAAYA,EAAEC,WAAWb,EAAE,GAC1E,CAACA,EAAE,CACL;AACA,SAAOO,SAASE,kBAAkB;AACpC;AAEO,SAASK,uBAAuBd,IAAY;AACjD,QAAMe,sBAAsBb,YAC1B,CAACC,UAA0BA,MAAMO,MAAMC,OAAO,CAACC,MAAYA,EAAEI,WAAWhB,EAAE,GAC1E,CAACA,EAAE,CACL;AACA,SAAOO,SAASQ,mBAAmB;AACrC;AAEO,SAASE,iBAAiBjB,IAAY;AAC3C,QAAMkB,gBAAgBhB,YACpB,CAACC,UACCA,MAAMO,MAAMC,OAAO,CAACC,MAAYA,EAAEI,WAAWhB,MAAMY,EAAEC,WAAWb,EAAE,GACpE,CAACA,EAAE,CACL;AACA,SAAOO,SAASW,aAAa;AAC/B;AAEO,SAASC,mBAAmBnB,IAAY;AACvCoB,QAAAA,aAAaZ,sBAAsBR,EAAE;AACrCqB,QAAAA,sBAAsBnB,YAC1B,CAACC,UAA0B;AACzB,WAAOiB,WACJE,IAAKV,CAAAA,MAAMT,MAAMC,SAAS,EAAEC,KAAK,CAACC,MAAYA,EAAEN,OAAOY,EAAEI,MAAM,CAAC,EAChEL,OAAO,CAACL,MAAiBA,MAAM,IAAI;AAAA,EAAA,GAExC,CAACc,UAAU,CACb;AACA,SAAOb,SAASc,mBAAmB;AACrC;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useNodeMetaRegistry } from "../FlowContext/NodeMetaContext.js";
|
|
2
|
+
function useFlowNodeMeta(id) {
|
|
3
|
+
const {
|
|
4
|
+
registry
|
|
5
|
+
} = useNodeMetaRegistry();
|
|
6
|
+
return registry[id];
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
useFlowNodeMeta
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useFlowNodeMeta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFlowNodeMeta.js","sources":["../../../../../src/components/Flow/hooks/useFlowNodeMeta.ts"],"sourcesContent":["import { useNodeMetaRegistry } from \"../FlowContext/NodeMetaContext\";\n\nexport function useFlowNodeMeta(id: string) {\n const { registry } = useNodeMetaRegistry();\n\n return registry[id];\n}\n"],"names":["useFlowNodeMeta","id","registry","useNodeMetaRegistry"],"mappings":";AAEO,SAASA,gBAAgBC,IAAY;AACpC,QAAA;AAAA,IAAEC;AAAAA,MAAaC,oBAAoB;AAEzC,SAAOD,SAASD,EAAE;AACpB;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -24,8 +24,9 @@ import { staticClasses as staticClasses10 } from "./components/Flow/Node/BaseNod
|
|
|
24
24
|
import { HvFlowBaseNode } from "./components/Flow/Node/BaseNode.js";
|
|
25
25
|
import { staticClasses as staticClasses11 } from "./components/Flow/Node/Node.styles.js";
|
|
26
26
|
import { HvFlowNode } from "./components/Flow/Node/Node.js";
|
|
27
|
-
import { useFlowNode } from "./components/Flow/hooks/useFlowNode.js";
|
|
27
|
+
import { useFlowNode, useFlowNodeEdges, useFlowNodeInputEdges, useFlowNodeOutputEdges, useFlowNodeParents } from "./components/Flow/hooks/useFlowNode.js";
|
|
28
28
|
import { useFlowContext } from "./components/Flow/hooks/useFlowContext.js";
|
|
29
|
+
import { useFlowNodeMeta } from "./components/Flow/hooks/useFlowNodeMeta.js";
|
|
29
30
|
export {
|
|
30
31
|
HvFlow,
|
|
31
32
|
HvFlowBackground,
|
|
@@ -50,6 +51,11 @@ export {
|
|
|
50
51
|
staticClasses as stepNavigationClasses,
|
|
51
52
|
useFlowContext,
|
|
52
53
|
useFlowNode,
|
|
54
|
+
useFlowNodeEdges,
|
|
55
|
+
useFlowNodeInputEdges,
|
|
56
|
+
useFlowNodeMeta,
|
|
57
|
+
useFlowNodeOutputEdges,
|
|
58
|
+
useFlowNodeParents,
|
|
53
59
|
staticClasses3 as wizardActionsClasses,
|
|
54
60
|
staticClasses2 as wizardClasses,
|
|
55
61
|
staticClasses4 as wizardContainerClasses,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -236,6 +236,7 @@ export declare interface HvFlowNodeGroup {
|
|
|
236
236
|
export declare type HvFlowNodeGroups<GroupId extends keyof any = string> = Record<GroupId, HvFlowNodeGroup>;
|
|
237
237
|
|
|
238
238
|
export declare type HvFlowNodeInput = {
|
|
239
|
+
id?: string;
|
|
239
240
|
label: string;
|
|
240
241
|
isMandatory?: boolean;
|
|
241
242
|
accepts?: string[];
|
|
@@ -251,6 +252,7 @@ export declare interface HvFlowNodeMeta {
|
|
|
251
252
|
export declare type HvFlowNodeMetaRegistry = Record<string, HvFlowNodeMeta>;
|
|
252
253
|
|
|
253
254
|
export declare type HvFlowNodeOutput = {
|
|
255
|
+
id?: string;
|
|
254
256
|
label: string;
|
|
255
257
|
isMandatory?: boolean;
|
|
256
258
|
provides?: string;
|
|
@@ -744,10 +746,17 @@ declare const useClasses_9: (classesProp?: Partial<Record<"root", string>>, addS
|
|
|
744
746
|
|
|
745
747
|
export declare const useFlowContext: () => HvFlowContextValue<string>;
|
|
746
748
|
|
|
747
|
-
export declare function useFlowNode<T =
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
749
|
+
export declare function useFlowNode<T extends Node_2 = Node_2>(id: string): T | undefined;
|
|
750
|
+
|
|
751
|
+
export declare function useFlowNodeEdges(id: string): Edge<any>[];
|
|
752
|
+
|
|
753
|
+
export declare function useFlowNodeInputEdges(id: string): Edge<any>[];
|
|
754
|
+
|
|
755
|
+
export declare function useFlowNodeMeta(id: string): HvFlowNodeMeta;
|
|
756
|
+
|
|
757
|
+
export declare function useFlowNodeOutputEdges(id: string): Edge<any>[];
|
|
758
|
+
|
|
759
|
+
export declare function useFlowNodeParents(id: string): Node_2<any, string | undefined>[];
|
|
751
760
|
|
|
752
761
|
export declare const wizardActionsClasses: {
|
|
753
762
|
actionsContainer: "HvWizardActions-actionsContainer";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/uikit-react-lab",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.17.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Hitachi Vantara UI Kit Team",
|
|
6
6
|
"description": "Contributed React components for the NEXT UI Kit.",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@dnd-kit/core": "^6.0.8",
|
|
33
33
|
"@dnd-kit/modifiers": "^6.0.1",
|
|
34
34
|
"@emotion/css": "^11.11.0",
|
|
35
|
-
"@hitachivantara/uikit-react-core": "^5.36.
|
|
35
|
+
"@hitachivantara/uikit-react-core": "^5.36.10",
|
|
36
36
|
"@hitachivantara/uikit-react-icons": "^5.7.4",
|
|
37
37
|
"@hitachivantara/uikit-styles": "^5.16.2",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"access": "public",
|
|
49
49
|
"directory": "package"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "51d5aaf46b3f007d313ead5ce8bfd5d3b248bc80",
|
|
52
52
|
"main": "dist/cjs/index.cjs",
|
|
53
53
|
"exports": {
|
|
54
54
|
".": {
|