UNPKG

@hitachivantara/uikit-react-lab

Version:

Contributed React components for the NEXT UI Kit.

44 lines (43 loc) 1.2 kB
import { jsx } from "react/jsx-runtime"; import { useContext, createContext, useRef, useCallback, useMemo } from "react"; const HvFlowNodeMetaContext = createContext(void 0); const HvFlowNodeMetaProvider = ({ children }) => { const registryRef = useRef({}); const registerNode = useCallback((id, nodeInfo) => { registryRef.current[id] = nodeInfo; }, []); const unregisterNode = useCallback((id) => { delete registryRef.current[id]; }, []); const getRegistry = useCallback(() => { return registryRef.current; }, []); const value = useMemo( () => ({ registerNode, unregisterNode, getRegistry }), [registerNode, unregisterNode, getRegistry] ); return /* @__PURE__ */ jsx(HvFlowNodeMetaContext.Provider, { value, children }); }; function useNodeMetaRegistry() { const context = useContext(HvFlowNodeMetaContext); if (context === void 0) { throw new Error( "useNodeRegistry must be used within a HvFlowNodeMetaProvider" ); } return { registerNode: context.registerNode, unregisterNode: context.unregisterNode, registry: context.getRegistry() }; } export { HvFlowNodeMetaProvider, useNodeMetaRegistry };