UNPKG

@yworks/yfiles-layout-reactflow

Version:

yFiles Layouts for React Flow - A layout library for React Flow providing powerful yFiles layout algorithms and supporting components

68 lines (66 loc) 1.81 kB
/** * Sets the license to be used for initializing web workers. */ declare function setWebWorkerLicense(licensePar: Record<string, unknown>): void; /** * Waits for the Web Worker to ready up and sends the license to it. * Returns a promise that resolves to the worker once the worker has sent * a 'licensed' message. * * Every worker should therefore include the following or similar code * at the beginning of its message handler: * * ```tsx * if (e.data.license) { * License.value = e.data.license * postMessage('licensed') * return * } * ``` * */ declare function registerWebWorker(worker: Worker): Promise<Worker>; /** * Initializes a Web Worker for the layout calculation. * * For example, this function can be used in a Web Worker for asynchronous layout calculation. * * ```tsx * // LayoutWorker.ts * import { initializeWebWorker } from '@yworks/yfiles-layout-reactflow/WebWorkerSupport' * initializeWebWorker(self) * ``` * * ```tsx * // index.tsx * const layoutWorker = new Worker(new URL('./LayoutWorker', import.meta.url), { * type: 'module' * }) * * const LayoutFlow = () => { * const [nodes] = useNodesState(initialNodes) * const [edges] = useEdgesState(initialEdges) * * const { runLayout } = useLayout({ layoutWorker }) * * return ( * <ReactFlow> * <Panel position="top-left"> * <button onClick={() => runLayout('HierarchicalLayout')}>Layout</button> * </Panel> * </ReactFlow> * ) * } * * export default function Flow() { * return ( * <ReactFlowProvider> * <LayoutFlow /> * </ReactFlowProvider> * ) * } * ``` * @param self - The current worker */ declare function initializeWebWorker(self: Window): void; export { initializeWebWorker, registerWebWorker, setWebWorkerLicense };