UNPKG

@hitachivantara/uikit-react-lab

Version:

Contributed React components for the NEXT UI Kit.

55 lines (54 loc) 1.49 kB
import { isValidElement } from "react"; const isInputGroup = (input) => { return "inputs" in input; }; const isOutputGroup = (output) => { return "outputs" in output; }; const isConnected = (id, type, handleId, edges) => { if (type === "target") { return edges.some((e) => e.target === id && e.targetHandle === handleId); } if (type === "source") { return edges.some((e) => e.source === id && e.sourceHandle === handleId); } return false; }; const renderedIcon = (actionIcon) => isValidElement(actionIcon) ? actionIcon : actionIcon?.(); const identifyHandles = (handles) => { let idx = 0; return handles?.map( (handle) => { if (isInputGroup(handle)) { return { ...handle, inputs: handle.inputs.map((x) => { const identifiedHandle2 = x.id != null ? x : { ...x, id: String(idx) }; idx += 1; return identifiedHandle2; }) }; } if (isOutputGroup(handle)) { return { ...handle, outputs: handle.outputs.map((x) => { const identifiedHandle2 = x.id != null ? x : { ...x, id: String(idx) }; idx += 1; return identifiedHandle2; }) }; } const identifiedHandle = handle.id != null ? handle : { ...handle, id: String(idx) }; idx += 1; return identifiedHandle; } ); }; export { identifyHandles, isConnected, isInputGroup, isOutputGroup, renderedIcon };