@fragiola/flow-react 0.0.0-stage → 0.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["EdgePath","EdgePath","Viewport"],"sources":["../src/hooks/create-flow-ref.ts","../src/hooks/use-connection.ts","../src/hooks/use-edge.ts","../src/hooks/use-edges.ts","../src/hooks/use-flow.ts","../src/hooks/use-flow-ref.ts","../src/hooks/use-flow-store.ts","../src/hooks/use-handle.ts","../src/hooks/use-internal-node.ts","../src/hooks/use-key-press.ts","../src/hooks/use-node.ts","../src/hooks/use-node-connections.ts","../src/hooks/use-node-id.ts","../src/hooks/use-nodes.ts","../src/hooks/use-nodes-data.ts","../src/hooks/use-on-viewport-change.ts","../src/hooks/use-selection.ts","../src/hooks/use-viewport.ts","../src/components/background.tsx","../src/components/connection-line.tsx","../src/components/controls.tsx","../src/components/edge-path.tsx","../src/components/edge.tsx","../src/components/edge-label.tsx","../src/components/edge-toolbar.tsx","../src/components/edges.tsx","../src/hooks/use-control-button.ts","../src/components/fit-view.tsx","../src/components/handle.tsx","../src/components/node.tsx","../src/components/node-toolbar.tsx","../src/components/nodes.tsx","../src/components/nodes-selection.tsx","../src/components/reconnect-anchor.tsx","../src/utils/engine-facade.ts","../src/components/root.tsx","../src/components/selection-box.tsx","../src/components/toggle-interactive.tsx","../src/components/viewport.tsx","../src/components/zoom-in.tsx","../src/components/zoom-out.tsx","../src/parts.ts"],"sourcesContent":["// From Tree (fragiola/tree, packages/react/src/hooks/create-tree-ref.ts), same author and licence.\nimport type {\n AnyTypes,\n FlowEngine,\n FlowFeatures,\n FlowModel,\n FlowTypes,\n} from \"@fragiola/flow\";\n\n/** What a flow ref gives once its `Flow.Root` is mounted: the root's model and engine. */\nexport interface FlowRefValue<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n> {\n readonly model: FlowModel<T, F>;\n readonly engine: FlowEngine<T, F>;\n}\n\n/**\n * Access to a `Flow.Root` from outside it (a toolbar, a menu, a test): pass it as the root's\n * `flowRef`; `current` is the root's model and engine while it is mounted, `null` otherwise.\n */\nexport interface FlowRef<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n> {\n readonly current: FlowRefValue<T, F> | null;\n}\n\ninterface RefSlot {\n value: FlowRefValue | null;\n readonly listeners: Set<() => void>;\n}\n\nconst slots = new WeakMap<object, RefSlot>();\n\nfunction slotOf(ref: object): RefSlot {\n const slot = slots.get(ref);\n if (!slot) throw new Error(\"not a flow ref: create it with createFlowRef\");\n return slot;\n}\n\n/**\n * Creates a flow ref outside React (a module, a test). In a component, `useFlowRef` keeps one and\n * re-renders when it attaches.\n *\n * ```tsx\n * const flow = createFlowRef<Types, typeof features>();\n * <Flow.Root flowRef={flow} features={features} defaultNodes={nodes}>…</Flow.Root>;\n * flow.current?.engine.run(\"fit-view\");\n * ```\n */\nexport function createFlowRef<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n>(): FlowRef<T, F> {\n const slot: RefSlot = { value: null, listeners: new Set() };\n const ref: FlowRef<T, F> = Object.freeze({\n get current() {\n return slot.value as unknown as FlowRefValue<T, F> | null;\n },\n });\n slots.set(ref, slot);\n return ref;\n}\n\n/** @internal what `Flow.Root` calls: attaches (or, with `null`, detaches) its model and engine */\nexport function setFlowRef(\n ref: FlowRef<FlowTypes, FlowFeatures>,\n value: FlowRefValue<FlowTypes, FlowFeatures> | null,\n): void {\n const slot = slotOf(ref);\n if ((slot.value as unknown) === value) return;\n slot.value = value as unknown as FlowRefValue | null;\n for (const listener of [...slot.listeners]) listener();\n}\n\n/** @internal calls `listener` when the ref attaches or detaches; returns its remover */\nexport function subscribeFlowRef(\n ref: FlowRef<FlowTypes, FlowFeatures>,\n listener: () => void,\n): () => void {\n const { listeners } = slotOf(ref);\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n","import type { Connection } from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/**\n * The connection being drawn from a handle (`connection()`), or null, re-rendering the component\n * when it changes: where it starts and ends, the handle it would end at and whether the drop\n * would be accepted (`status`).\n */\nexport function useConnection(): Connection | null {\n const { model, engine } = useFlowContext(\"useConnection\");\n return useFlowValue(\n model,\n engine,\n () => engine?.get(\"connection\") ?? null,\n (a, b) =>\n a === b ||\n (a !== null &&\n b !== null &&\n a.path === b.path &&\n a.status === b.status &&\n a.to === b.to &&\n a.from === b.from &&\n a.toSide === b.toSide),\n );\n}\n","import {\n type AnyTypes,\n type EdgePath,\n type FlowEdge,\n type FlowTypes,\n flag,\n type PartAttributes,\n partAttributes,\n} from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { shallowEqual } from \"../utils/shallow-equal\";\nimport type { DataAttributes } from \"../utils/use-render\";\nimport { useFlowValue } from \"./internal\";\n\n/** What an edge shows: its state on screen. */\nexport interface EdgeState<T extends FlowTypes = AnyTypes> {\n readonly edgeId: string;\n /** the edge, as the model holds it */\n readonly edge: FlowEdge<T>;\n /**\n * its path, label point and ends (`edge-path-by`), once both its nodes have a size; an app\n * type gets the bezier path, and its ends to draw its own\n */\n readonly path: EdgePath | undefined;\n /** `data-selected` (`selection()`) */\n readonly selected: boolean;\n /** one of its ends is being moved (`reconnection()`) */\n readonly reconnecting: boolean;\n /** it takes DOM focus (`keyboard()`): `tabindex=\"0\"` */\n readonly focusable: boolean;\n readonly attributes: PartAttributes;\n}\n\nexport interface UseEdgeResult<T extends FlowTypes = AnyTypes> {\n state: EdgeState<T>;\n /** what goes on the edge's element (an SVG group): its attributes and `tabIndex` */\n props: { tabIndex: number | undefined } & DataAttributes;\n}\n\n/** Two edge paths that draw the same (`edge-path-by` builds a new one at every read). */\nexport function sameEdgePath(\n a: EdgePath | undefined,\n b: EdgePath | undefined,\n): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n return (\n a.path === b.path &&\n a.sourceSide === b.sourceSide &&\n a.targetSide === b.targetSide &&\n a.label.x === b.label.x &&\n a.label.y === b.label.y &&\n a.source.x === b.source.x &&\n a.source.y === b.source.y &&\n a.target.x === b.target.x &&\n a.target.y === b.target.y\n );\n}\n\ninterface EdgeView {\n attributes: PartAttributes;\n path: EdgePath | undefined;\n reconnecting: boolean;\n focusable: boolean;\n}\n\n/** An edge's state and the props of its element, for an edge drawn by hand (`Flow.Edge` uses it). */\nexport function useEdge<T extends FlowTypes = AnyTypes>(\n edge: FlowEdge<T>,\n): UseEdgeResult<T> {\n const { model, engine, staticGeometry } = useFlowContext(\"useEdge\");\n const edgeId = edge.id;\n const view = useFlowValue<EdgeView>(\n model,\n engine,\n () =>\n engine\n ? {\n attributes: engine.adapter.attributes(\"edge\", { edgeId }),\n path: engine.get(\"edge-path-by\", { edgeId }),\n reconnecting: engine.is(\"edge-reconnecting\", { edgeId }),\n focusable: engine.is(\"edge-focusable\", { edgeId }),\n }\n : {\n attributes: staticEdgeAttributes(\"edge\", edge),\n path: staticGeometry?.edgePaths[edgeId],\n reconnecting: false,\n focusable: false,\n },\n (a, b) =>\n a.reconnecting === b.reconnecting &&\n a.focusable === b.focusable &&\n sameEdgePath(a.path, b.path) &&\n shallowEqual(a.attributes, b.attributes),\n \"entity\",\n { kind: \"edge\", id: edgeId },\n );\n const { attributes } = view;\n return {\n state: {\n edgeId,\n edge,\n path: view.path,\n selected: attributes[\"data-selected\"] !== undefined,\n reconnecting: view.reconnecting,\n focusable: view.focusable,\n attributes,\n },\n props: {\n ...(attributes as DataAttributes),\n tabIndex: view.focusable ? 0 : undefined,\n },\n };\n}\n\n/**\n * @internal an edge part's attributes before the engine (the server render, the first client\n * render): its part, its id, `data-selected` and `data-animated` from the document, as the\n * engine gives them\n */\nexport function staticEdgeAttributes(\n part: string,\n edge: {\n readonly id: string;\n readonly selected?: boolean | undefined;\n readonly animated?: boolean | undefined;\n },\n): PartAttributes {\n return {\n ...partAttributes(part, edge.id),\n \"data-selected\": flag(edge.selected === true),\n \"data-animated\": flag(edge.animated === true),\n };\n}\n\n/**\n * @internal an edge's path, re-rendering when it changes (`Flow.EdgePath`, `Flow.EdgeLabel`): the\n * engine's, or the static geometry's before the engine\n */\nexport function useEdgePath(edgeId: string): EdgePath | undefined {\n const { model, engine, staticGeometry } = useFlowContext(\"EdgePath\");\n return useFlowValue(\n model,\n engine,\n () =>\n engine\n ? engine.get(\"edge-path-by\", { edgeId })\n : staticGeometry?.edgePaths[edgeId],\n sameEdgePath,\n \"entity\",\n { kind: \"edge\", id: edgeId },\n );\n}\n","import type { AnyTypes, FlowEdge, FlowTypes } from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/** Every edge of the enclosing `Flow.Root`, in drawing order, re-rendering on every change of one. */\nexport function useEdges<\n T extends FlowTypes = AnyTypes,\n>(): readonly FlowEdge<T>[] {\n const { model } = useFlowContext(\"useEdges\");\n return useFlowValue(\n model,\n null,\n () => model.get(\"all-edges\") as readonly FlowEdge<T>[],\n Object.is,\n );\n}\n","import type {\n AnyTypes,\n FlowEngine,\n FlowFeatures,\n FlowModel,\n FlowTypes,\n} from \"@fragiola/flow\";\nimport { typedEngine, typedModel, useFlowContext } from \"../context\";\n\nexport interface UseFlowResult<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n> {\n /**\n * the model of the enclosing `Flow.Root`: the flow's document and its rules. Change it with\n * `model.run(\"node.move\", { nodeId, position })`, read it with `model.get` / `model.is`\n */\n model: FlowModel<T, F>;\n /**\n * the engine of the flow on screen: screen actions (`engine.run(\"fit-view\")`), screen facts\n * (`engine.get(\"viewport\")`) and its events (`engine.subscribe`). It is there from the first\n * render; before the root is mounted (and on the server) an action is refused and a read is\n * empty\n */\n engine: FlowEngine<T, F>;\n}\n\n/**\n * The model and the engine of the enclosing `Flow.Root`. Pass the registry and the features as the\n * type arguments (`useFlow<Types, typeof features>()`): a child cannot infer them through context.\n */\nexport function useFlow<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n>(): UseFlowResult<T, F> {\n const context = useFlowContext(\"useFlow\");\n return {\n model: typedModel<T, F>(context.model),\n engine: typedEngine<T, F>(context.publicEngine),\n };\n}\n","// From Tree (fragiola/tree, packages/react/src/hooks/use-tree-ref.ts), same author and licence.\nimport type { AnyTypes, FlowFeatures, FlowTypes } from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport {\n createFlowRef,\n type FlowRef,\n subscribeFlowRef,\n} from \"./create-flow-ref\";\n\n/**\n * A flow ref kept by this component, which re-renders when the `Flow.Root` it is given to mounts\n * or unmounts: read `flow.current` in render (a toolbar next to the flow) or in handlers.\n *\n * ```tsx\n * const flow = useFlowRef<Types>();\n * <button type=\"button\" onClick={() => flow.current?.engine.run(\"fit-view\")}>Fit</button>\n * <Flow.Root flowRef={flow} defaultNodes={nodes}>…</Flow.Root>\n * ```\n */\nexport function useFlowRef<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n>(): FlowRef<T, F> {\n const [ref] = React.useState(() => createFlowRef<T, F>());\n const subscribe = React.useCallback(\n (onChange: () => void) =>\n subscribeFlowRef(\n ref as unknown as FlowRef<FlowTypes, FlowFeatures>,\n onChange,\n ),\n [ref],\n );\n const snapshot = () => ref.current;\n React.useSyncExternalStore(subscribe, snapshot, () => null);\n return ref;\n}\n","import type { AnyTypes, FlowFeatures, FlowTypes } from \"@fragiola/flow\";\nimport { typedEngine, typedModel, useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\nimport type { UseFlowResult } from \"./use-flow\";\n\n/**\n * A value selected from the model and the engine of the enclosing `Flow.Root`, re-rendering the\n * component only when it changes (`equal`, default `Object.is`): `selector` runs again on every\n * change of the model and every view change of the engine (a measurement, the viewport, a\n * gesture), and on every render. Pass the registry and the features as the type arguments after\n * the selected value's (`useFlowStore<number, Types, typeof features>(…)`). Keep a selector that\n * builds an object or an array with an `equal` that compares it (`sameFlowValue`), or it\n * re-renders on every change.\n */\nexport function useFlowStore<\n S,\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n>(\n selector: (flow: UseFlowResult<T, F>) => S,\n equal: (a: S, b: S) => boolean = Object.is,\n): S {\n const { model, engine, publicEngine } = useFlowContext(\"useFlowStore\");\n return useFlowValue(\n model,\n engine,\n () =>\n selector({\n model: typedModel<T, F>(model),\n engine: typedEngine<T, F>(publicEngine),\n }),\n equal,\n );\n}\n","import {\n type HandleRegistration,\n type HandleSide,\n type HandleType,\n type PartAttributes,\n partAttributes,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { useFlowContext, usePartNodeId } from \"../context\";\nimport { type AttributeProps, attributeProps } from \"../utils/use-render\";\nimport { sameValue, useFlowValue } from \"./internal\";\n\nexport interface UseHandleOptions {\n /** whether edges start (`source`) or end (`target`) here */\n type: HandleType;\n /** the side of the node it sits on: the direction its edges leave or enter by */\n side: HandleSide;\n /** its id among the node's handles of its type (none: the node's default handle) */\n handleId?: string | undefined;\n /** whether a connection may start or end here; default true */\n connectable?: boolean | undefined;\n /** whether a connection may start here (a drag, a tap, a key); default true */\n connectableStart?: boolean | undefined;\n /** whether a connection may end here (be its target); default true */\n connectableEnd?: boolean | undefined;\n /** its node; default the enclosing `Flow.Node`'s */\n nodeId?: string | undefined;\n}\n\n/** What a handle shows. */\nexport interface HandleState {\n readonly nodeId: string;\n readonly handleId: string | undefined;\n readonly type: HandleType;\n readonly side: HandleSide;\n /** a connection may start or end here (its flag and its node's): `data-connectable` */\n readonly connectable: boolean;\n /** a connection may start here: `data-connectable-start` */\n readonly connectableStart: boolean;\n /** a connection may end here: `data-connectable-end` */\n readonly connectableEnd: boolean;\n /** the connection under way starts here (`connection()`): `data-connecting` */\n readonly connecting: boolean;\n /** the connection under way would end here and be accepted: `data-valid` */\n readonly valid: boolean;\n /** the connection under way would end here and be refused: `data-invalid` */\n readonly invalid: boolean;\n readonly attributes: PartAttributes;\n}\n\nexport interface UseHandleResult {\n state: HandleState;\n /**\n * what goes on the handle's element: its attributes (`tabIndex` with `keyboard()` and\n * `connection()`) and the ref that registers it (D8)\n */\n props: { ref: React.RefCallback<Element> } & AttributeProps;\n}\n\n/**\n * A handle's state and the props of its element, for a handle rendered by hand (`Flow.Handle`\n * uses it): registered with the engine, which measures its centre relative to its node.\n */\nexport function useHandle(options: UseHandleOptions): UseHandleResult {\n const { model, engine } = useFlowContext(\"useHandle\");\n const nodeId = usePartNodeId(\"Handle\", options.nodeId);\n const {\n type,\n side,\n handleId,\n connectable,\n connectableStart,\n connectableEnd,\n } = options;\n const registration = React.useMemo<HandleRegistration>(\n () => ({\n nodeId,\n handleId,\n type,\n side,\n connectable,\n connectableStart,\n connectableEnd,\n }),\n [\n nodeId,\n handleId,\n type,\n side,\n connectable,\n connectableStart,\n connectableEnd,\n ],\n );\n const attributes = useFlowValue(\n model,\n engine,\n () =>\n engine\n ? engine.adapter.attributes(\"handle\", registration)\n : {\n ...partAttributes(\"handle\", handleId),\n \"data-handle-type\": type,\n \"data-side\": side,\n },\n sameValue,\n \"entity\",\n );\n const ref = React.useCallback(\n (element: Element | null) => {\n if (!engine || !element) return;\n engine.adapter.registerHandle(registration, element);\n return () => engine.adapter.registerHandle(registration, null);\n },\n [engine, registration],\n );\n return {\n state: {\n nodeId,\n handleId,\n type,\n side,\n connectable: attributes[\"data-connectable\"] !== undefined,\n connectableStart:\n attributes[\"data-connectable-start\"] !== undefined,\n connectableEnd: attributes[\"data-connectable-end\"] !== undefined,\n connecting: attributes[\"data-connecting\"] !== undefined,\n valid: attributes[\"data-valid\"] !== undefined,\n invalid: attributes[\"data-invalid\"] !== undefined,\n attributes,\n },\n props: { ...attributeProps(attributes), ref },\n };\n}\n","import {\n type AnyTypes,\n type FlowTypes,\n type InternalNode,\n sameFlowValue,\n} from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/**\n * A node as the engine knows it on screen (`internal-node-by`): the document's node, its absolute\n * position and box (`nodeOrigin` applied), whether its size is known, its z-index and its handles\n * with their centres; undefined while it does not exist or before the root is mounted. It\n * re-renders the component only when one of them changes (compared by value): a pan does not.\n */\nexport function useInternalNode<T extends FlowTypes = AnyTypes>(\n nodeId: string,\n): InternalNode<T> | undefined {\n const { model, engine } = useFlowContext(\"useInternalNode\");\n return useFlowValue(\n model,\n engine,\n () =>\n engine?.get(\"internal-node-by\", { nodeId }) as\n | InternalNode<T>\n | undefined,\n sameFlowValue,\n );\n}\n","import {\n type KeyPressKeys,\n type KeyPressTarget,\n watchKeyPress,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { FlowContext } from \"../context\";\n\nexport interface UseKeyPressOptions {\n /** where the keys are read: a window, a document or an element; default the root's window */\n target?: KeyPressTarget | null | undefined;\n}\n\n/**\n * Whether a key, or a combo of keys, is held, re-rendering the component when that changes.\n * `keys` is a combo or several (any of them): key names joined by `+`, held at once (`\"Shift\"`,\n * `\"Meta+s\"`, `[\"Meta+z\", \"Control+z\"]`); a name is a `KeyboardEvent.key` or `.code`, without case\n * (`watchKeyPress`). The keys are read on `target`, by default the window of the enclosing\n * `Flow.Root`'s element (never the global one): false before the root is mounted, or outside a\n * root without a `target`.\n */\nexport function useKeyPress(\n keys: KeyPressKeys,\n options: UseKeyPressOptions = {},\n): boolean {\n const rootElement = React.useContext(FlowContext)?.rootElement ?? null;\n const target =\n options.target === undefined\n ? (rootElement?.ownerDocument.defaultView ?? null)\n : options.target;\n const [pressed, setPressed] = React.useState(false);\n // an equal list of keys on each render keeps the listener (and what it holds)\n const combos = JSON.stringify(typeof keys === \"string\" ? [keys] : keys);\n React.useEffect(() => {\n if (!target) return;\n const stop = watchKeyPress(\n target,\n JSON.parse(combos) as string[],\n setPressed,\n );\n return () => {\n stop();\n setPressed(false);\n };\n }, [target, combos]);\n return pressed;\n}\n","import {\n type AnyTypes,\n type FlowNode,\n type FlowTypes,\n flag,\n type PartAttributes,\n partAttributes,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport type { DataAttributes } from \"../utils/use-render\";\nimport { sameValue, useFlowValue } from \"./internal\";\n\n/** What a node shows: its state on screen. */\nexport interface NodeState<T extends FlowTypes = AnyTypes> {\n readonly nodeId: string;\n /** the node, as the model holds it */\n readonly node: FlowNode<T>;\n /** its top-left corner in absolute flow coordinates (its parents' positions added) */\n readonly x: number;\n readonly y: number;\n /** `data-selected` (`selection()`) */\n readonly selected: boolean;\n /** `data-dragging` (`drag()`) */\n readonly dragging: boolean;\n /** `data-resizing` (`resize()`) */\n readonly resizing: boolean;\n /** its size is known (measured or given): `data-measured` */\n readonly measured: boolean;\n /** it takes DOM focus (`keyboard()`): `tabindex=\"0\"` */\n readonly focusable: boolean;\n /** the attributes its element carries (`data-flow-part`, `data-flow-id`, the state) */\n readonly attributes: PartAttributes;\n}\n\nexport interface UseNodeResult<T extends FlowTypes = AnyTypes> {\n state: NodeState<T>;\n /**\n * what goes on the node's element: its attributes, `tabIndex`, its structural style (absolute,\n * at its position, its `z-index` among the nodes, with the document's size when given) and the ref that registers it with the\n * engine (measured)\n */\n props: {\n ref: React.RefCallback<HTMLElement>;\n tabIndex: number | undefined;\n style: React.CSSProperties;\n } & DataAttributes;\n}\n\ninterface NodeView {\n attributes: PartAttributes;\n x: number;\n y: number;\n /** its structural `z-index` (`node-z-index-by`, or the static geometry's before the engine) */\n zIndex: number | undefined;\n focusable: boolean;\n}\n\n/**\n * A node's state and the props of its element, for a node rendered by hand (`Flow.Node` uses it).\n * Spread `props` on the element (the engine resolves presses from its attributes).\n */\nexport function useNode<T extends FlowTypes = AnyTypes>(\n node: FlowNode<T>,\n): UseNodeResult<T> {\n const { model, engine, staticGeometry } = useFlowContext(\"useNode\");\n const nodeId = node.id;\n const view = useFlowValue<NodeView>(\n model,\n engine,\n () => {\n if (!engine) {\n // the static geometry (origin applied), as the engine places it before measuring\n const rect = staticGeometry?.nodeRects[nodeId];\n // no rect (no static geometry): its absolute position, its parents' added\n const at = rect\n ? undefined\n : model.get(\"absolute-position-by\", { nodeId });\n return {\n attributes: {\n ...partAttributes(\"node\", nodeId),\n \"data-selected\": flag(node.selected === true),\n },\n x: rect?.x ?? at?.x ?? node.position.x,\n y: rect?.y ?? at?.y ?? node.position.y,\n zIndex: staticGeometry?.nodeZIndexes[nodeId],\n focusable: false,\n };\n }\n const rect = engine.get(\"node-rect-by\", { nodeId });\n return {\n attributes: engine.adapter.attributes(\"node\", { nodeId }),\n x: rect?.x ?? node.position.x,\n y: rect?.y ?? node.position.y,\n zIndex: engine.get(\"node-z-index-by\", { nodeId }),\n focusable: engine.is(\"node-focusable\", { nodeId }),\n };\n },\n sameValue,\n \"entity\",\n { kind: \"node\", id: nodeId },\n );\n const ref = React.useCallback(\n (element: HTMLElement | null) => {\n if (!engine || !element) return;\n engine.adapter.registerNode(nodeId, element);\n return () => engine.adapter.registerNode(nodeId, null);\n },\n [engine, nodeId],\n );\n const { attributes } = view;\n const style: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n transform: `translate(${view.x}px, ${view.y}px)`,\n ...(view.zIndex === undefined ? {} : { zIndex: view.zIndex }),\n ...(node.width === undefined ? {} : { width: node.width }),\n ...(node.height === undefined ? {} : { height: node.height }),\n };\n return {\n state: {\n nodeId,\n node,\n x: view.x,\n y: view.y,\n selected: attributes[\"data-selected\"] !== undefined,\n dragging: attributes[\"data-dragging\"] !== undefined,\n resizing: attributes[\"data-resizing\"] !== undefined,\n measured: attributes[\"data-measured\"] !== undefined,\n focusable: view.focusable,\n attributes,\n },\n props: {\n ...(attributes as DataAttributes),\n ref,\n tabIndex: view.focusable ? 0 : undefined,\n style,\n },\n };\n}\n","import {\n type HandleType,\n type NodeConnection,\n sameFlowValue,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { NodeContext, useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\nexport interface UseNodeConnectionsOptions {\n /** the node; default the enclosing `Flow.Node`'s */\n id?: string | undefined;\n /** only the connections at this handle of it */\n handleId?: string | undefined;\n /** only those that start (`\"source\"`) or end (`\"target\"`) at it */\n type?: HandleType | undefined;\n}\n\n/**\n * The connections at a node (`node-connections-by`): each edge that starts or ends at it, as its\n * `edgeId`, `source`, `sourceHandle`, `target` and `targetHandle`, in the document's order. It\n * re-renders the component only when they change (an edge added, removed or reconnected there),\n * not when a node moves or an edge's data changes.\n */\nexport function useNodeConnections(\n options: UseNodeConnectionsOptions = {},\n): readonly NodeConnection[] {\n const { model } = useFlowContext(\"useNodeConnections\");\n const enclosing = React.useContext(NodeContext)?.nodeId;\n const nodeId = options.id ?? enclosing;\n if (nodeId === undefined) {\n throw new Error(\n \"useNodeConnections must be called inside Flow.Node (or be given an id)\",\n );\n }\n const { handleId, type } = options;\n return useFlowValue(\n model,\n null,\n () =>\n model.get(\"node-connections-by\", {\n nodeId,\n handleId,\n handleType: type,\n }),\n sameFlowValue,\n );\n}\n","import * as React from \"react\";\nimport { NodeContext } from \"../context\";\n\n/**\n * The id of the node the component renders inside (`Flow.Node`), or null outside one: a custom\n * node's piece reads its own node without being given its id.\n */\nexport function useNodeId(): string | null {\n return React.useContext(NodeContext)?.nodeId ?? null;\n}\n","import type { AnyTypes, FlowNode, FlowTypes } from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/** Every node of the enclosing `Flow.Root`, in drawing order, re-rendering on every change of one. */\nexport function useNodes<\n T extends FlowTypes = AnyTypes,\n>(): readonly FlowNode<T>[] {\n const { model } = useFlowContext(\"useNodes\");\n return useFlowValue(\n model,\n null,\n () => model.get(\"all-nodes\") as readonly FlowNode<T>[],\n Object.is,\n );\n}\n","import {\n type AnyTypes,\n type FlowTypes,\n type NodeData,\n sameFlowValue,\n} from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/**\n * A node's id, type and data (`nodes-data-by`), or null while it does not exist; given several\n * ids, each existing one's in the order given. It re-renders the component only when one of them\n * changes (its type or its data, compared by value), not when a node moves or another changes.\n */\nexport function useNodesData<T extends FlowTypes = AnyTypes>(\n nodeId: string,\n): NodeData<T> | null;\nexport function useNodesData<T extends FlowTypes = AnyTypes>(\n nodeIds: readonly string[],\n): readonly NodeData<T>[];\nexport function useNodesData<T extends FlowTypes = AnyTypes>(\n ids: string | readonly string[],\n): NodeData<T> | null | readonly NodeData<T>[] {\n const { model } = useFlowContext(\"useNodesData\");\n const one = typeof ids === \"string\";\n const list = useFlowValue(\n model,\n null,\n () =>\n model.get(\"nodes-data-by\", {\n nodeIds: one ? [ids] : ids,\n }) as readonly NodeData<T>[],\n sameFlowValue,\n );\n return one ? (list[0] ?? null) : list;\n}\n","import type { Viewport } from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { useFlowContext } from \"../context\";\n\nexport interface UseOnViewportChangeOptions {\n /** the viewport starts changing (`viewport-change-start`): a pan, a zoom, an animation */\n onStart?: ((viewport: Viewport, gesture: boolean) => void) | undefined;\n /** each change of the viewport (`viewport-change`) */\n onChange?: ((viewport: Viewport, gesture: boolean) => void) | undefined;\n /** the viewport stopped changing (`viewport-change-end`) */\n onEnd?: ((viewport: Viewport, gesture: boolean) => void) | undefined;\n}\n\n/**\n * Calls back on the viewport's changes of the enclosing `Flow.Root` (the engine's events),\n * without re-rendering the component: `gesture` is true for a pan, the wheel, a pinch or auto-pan,\n * false for an action. The latest callbacks are called.\n */\nexport function useOnViewportChange(options: UseOnViewportChangeOptions): void {\n const { engine } = useFlowContext(\"useOnViewportChange\");\n const latest = React.useRef(options);\n latest.current = options;\n React.useEffect(() => {\n if (!engine) return;\n return engine.subscribe((event) => {\n const { onStart, onChange, onEnd } = latest.current;\n if (event.type === \"viewport-change-start\") {\n onStart?.(event.viewport, event.gesture);\n } else if (event.type === \"viewport-change\") {\n onChange?.(event.viewport, event.gesture);\n } else if (event.type === \"viewport-change-end\") {\n onEnd?.(event.viewport, event.gesture);\n }\n });\n }, [engine]);\n}\n","import type { AnyTypes, FlowEdge, FlowNode, FlowTypes } from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/** What is selected. */\nexport interface FlowSelection<T extends FlowTypes = AnyTypes> {\n readonly nodes: readonly FlowNode<T>[];\n readonly edges: readonly FlowEdge<T>[];\n}\n\nconst NONE: readonly never[] = Object.freeze([]);\n\n/**\n * The selected nodes and edges of the enclosing `Flow.Root` (`selection()`; none without it),\n * re-rendering the component when they change: a panel showing the selection, a Delete button.\n */\nexport function useSelection<\n T extends FlowTypes = AnyTypes,\n>(): FlowSelection<T> {\n const { model } = useFlowContext(\"useSelection\");\n return useFlowValue(\n model,\n null,\n () => ({\n nodes: (model.get(\"selected-nodes\") ??\n NONE) as readonly FlowNode<T>[],\n edges: (model.get(\"selected-edges\") ??\n NONE) as readonly FlowEdge<T>[],\n }),\n (a, b) =>\n a.nodes.length === b.nodes.length &&\n a.edges.length === b.edges.length &&\n a.nodes.every((node, i) => node === b.nodes[i]) &&\n a.edges.every((edge, i) => edge === b.edges[i]),\n );\n}\n","import type { Viewport } from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/**\n * The viewport of the enclosing `Flow.Root` (`{ x, y, zoom }`), re-rendering the component when it\n * changes: a zoom level readout, a control's state. Change it with `engine.run(\"set-viewport\")`.\n */\nexport function useViewport(): Viewport {\n const { model, engine, publicEngine } = useFlowContext(\"useViewport\");\n return useFlowValue(model, engine, () => publicEngine.get(\"viewport\"));\n}\n","import {\n type BackgroundPattern,\n type BackgroundVariant,\n partAttributes,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface BackgroundState {\n /** the pattern's tile on the screen, at the current viewport */\n readonly pattern: BackgroundPattern;\n}\n\nexport interface BackgroundProps\n extends Omit<\n SvgPrimitiveProps<BackgroundState, SVGSVGElement>,\n \"children\" | \"offset\"\n > {\n /** the marks: `dots` (default), `lines` or `cross` */\n variant?: BackgroundVariant | undefined;\n /** the distance between two marks, in flow units; default 20 (`[x, y]` for two) */\n gap?: number | readonly [number, number] | undefined;\n /** dots: a dot's diameter (flow units); lines: the stroke width (screen pixels); cross: a bar's length */\n size?: number | undefined;\n /** the pattern's shift from the flow's origin, in flow units */\n offset?: number | readonly [number, number] | undefined;\n}\n\nconst BACKGROUND_STYLE: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n};\n\n/**\n * The flow's background (`data-flow-part=\"background\"`): an SVG pattern of dots, lines or crosses\n * that pans and zooms with the viewport (`background-pattern`), inside `Flow.Root` before\n * `Flow.Viewport`. The marks are drawn in `currentColor`: set the `color` (and the background\n * itself) in your style.\n */\nexport function Background(props: BackgroundProps) {\n const { variant, gap, size, offset, ...rest } = props;\n const { model, engine } = useFlowContext(\"Background\");\n const pattern = useFlowValue(model, engine, () =>\n engine\n ? engine.get(\"background-pattern\", { variant, gap, size, offset })\n : undefined,\n );\n const id = `flow-background-${React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n // drawn once the engine is there (a server render has the bare element)\n const tile = pattern;\n return useRenderElement(\"svg\", rest, {\n state: {\n pattern: tile ?? EMPTY_PATTERN,\n },\n props: {\n ...partAttributes(\"background\"),\n children: tile ? (\n <>\n <pattern\n data-flow-part=\"background-pattern\"\n id={id}\n patternUnits=\"userSpaceOnUse\"\n x={tile.x}\n y={tile.y}\n width={tile.width}\n height={tile.height}\n >\n {tile.dot ? (\n <circle\n data-flow-part=\"background-mark\"\n cx={tile.dot.cx}\n cy={tile.dot.cy}\n r={tile.dot.r}\n fill=\"currentColor\"\n />\n ) : (\n <path\n data-flow-part=\"background-mark\"\n d={tile.path}\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={tile.strokeWidth}\n />\n )}\n </pattern>\n <rect\n data-flow-part=\"background-fill\"\n width=\"100%\"\n height=\"100%\"\n fill={`url(#${id})`}\n />\n </>\n ) : null,\n },\n style: BACKGROUND_STYLE,\n });\n}\n\nconst EMPTY_PATTERN: BackgroundPattern = Object.freeze({\n variant: \"dots\",\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n dot: undefined,\n path: undefined,\n strokeWidth: 0,\n});\n","import type { Connection } from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport { useConnection } from \"../hooks/use-connection\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface ConnectionLineState {\n /** the connection being drawn */\n readonly connection: Connection;\n /** the drop would add the edge: `data-valid` */\n readonly valid: boolean;\n /** the drop would be refused (`model.can(\"edge.add\")`, a middleware's veto): `data-invalid` */\n readonly invalid: boolean;\n}\n\nexport interface ConnectionLineProps\n extends Omit<\n SvgPrimitiveProps<ConnectionLineState, SVGSVGElement>,\n \"children\"\n > {\n /**\n * draws the line, in flow coordinates; default an unfilled `<path>` of the connection's path\n * (`data-flow-part=\"connection-path\"`)\n */\n children?: ((connection: Connection) => React.ReactNode) | undefined;\n}\n\nconst LINE_STYLE: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: \"100%\",\n overflow: \"visible\",\n pointerEvents: \"none\",\n};\n\n/**\n * The connection being drawn (`data-flow-part=\"connection-line\"`, `data-valid` / `data-invalid`,\n * `connection()`): an SVG inside `Flow.Viewport`, rendered only while a connection is under way.\n */\nexport function ConnectionLine(props: ConnectionLineProps) {\n const connection = useConnection();\n if (!connection) return null;\n return <ConnectionLineElement {...props} connection={connection} />;\n}\n\nfunction ConnectionLineElement(\n props: ConnectionLineProps & { connection: Connection },\n) {\n const { connection, children, ...rest } = props;\n const { model, engine } = useFlowContext(\"ConnectionLine\");\n const attributes = useFlowValue(\n model,\n engine,\n () => engine?.adapter.attributes(\"connection-line\") ?? {},\n );\n const state: ConnectionLineState = {\n connection,\n valid: attributes[\"data-valid\"] !== undefined,\n invalid: attributes[\"data-invalid\"] !== undefined,\n };\n return useRenderElement(\"svg\", rest, {\n state,\n props: {\n ...attributes,\n \"data-flow-part\": \"connection-line\",\n children: children ? (\n children(connection)\n ) : (\n <path\n data-flow-part=\"connection-path\"\n d={connection.path}\n fill=\"none\"\n />\n ),\n },\n style: LINE_STYLE,\n });\n}\n","import { partAttributes } from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\n/** The state of `Flow.Controls` (none: its buttons have their own). */\nexport type ControlsState = Record<never, never>;\n\nexport interface ControlsProps extends DivPrimitiveProps<ControlsState> {\n children?: React.ReactNode;\n}\n\n/**\n * A group of the viewport's buttons (`data-flow-part=\"controls\"`): `Flow.ZoomIn`, `Flow.ZoomOut`,\n * `Flow.FitView`, `Flow.ToggleInteractive`, or your own. Inside `Flow.Root`, outside\n * `Flow.Viewport`; presses and the wheel over it are left to it. Place it with your style.\n */\nexport function Controls(props: ControlsProps) {\n const { children, ...rest } = props;\n return useRenderElement(\"div\", rest, {\n state: {},\n props: { ...partAttributes(\"controls\"), children },\n });\n}\n","import type { EdgePath as EdgePathValue } from \"@fragiola/flow\";\nimport { useEdgeId, useFlowContext } from \"../context\";\nimport { sameValue, useFlowValue } from \"../hooks/internal\";\nimport { staticEdgeAttributes, useEdgePath } from \"../hooks/use-edge\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface EdgePathState {\n readonly edgeId: string;\n /** the edge's path, label point and ends */\n readonly path: EdgePathValue;\n /** `data-selected` (`selection()`) */\n readonly selected: boolean;\n}\n\nexport interface EdgePathProps\n extends SvgPrimitiveProps<EdgePathState, SVGPathElement> {\n /** the edge; default the enclosing `Flow.Edge`'s */\n edgeId?: string | undefined;\n}\n\n/**\n * An edge's path (`data-flow-part=\"edge-path\"`): an SVG `<path>` whose `d` is the engine's\n * (`edge-path-by`, D9), unfilled. A `d` of your own draws an app type (from `state.path`'s ends).\n * Several may share an edge: a wide transparent one is a bigger press target.\n */\nexport function EdgePath(props: EdgePathProps) {\n const { edgeId: edgeIdProp, ...rest } = props;\n const edgeId = useEdgeId(\"EdgePath\", edgeIdProp);\n const { model, engine } = useFlowContext(\"EdgePath\");\n const path = useEdgePath(edgeId);\n const attributes = useFlowValue(\n model,\n engine,\n () =>\n engine\n ? engine.adapter.attributes(\"edge-path\", { edgeId })\n : staticEdgeAttributes(\n \"edge-path\",\n model.get(\"edge-by\", { id: edgeId }) ?? { id: edgeId },\n ),\n sameValue,\n \"entity\",\n { kind: \"edge\", id: edgeId },\n );\n if (!path || !attributes) return null;\n return (\n <EdgePathElement\n {...rest}\n state={{\n edgeId,\n path,\n selected: attributes[\"data-selected\"] !== undefined,\n }}\n attributes={attributes}\n />\n );\n}\n\nfunction EdgePathElement(\n props: Omit<EdgePathProps, \"edgeId\"> & {\n state: EdgePathState;\n attributes: Readonly<Record<string, string | undefined>>;\n },\n) {\n const { state, attributes, ...rest } = props;\n return useRenderElement(\"path\", rest, {\n state,\n props: { ...attributes, d: state.path.path, fill: \"none\" },\n });\n}\n","import type { AnyTypes, FlowEdge, FlowTypes } from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { EdgeContext, useFlowContext } from \"../context\";\nimport { type EdgeState, useEdge } from \"../hooks/use-edge\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\nimport { EdgePath } from \"./edge-path\";\n\nexport interface EdgeProps<T extends FlowTypes = AnyTypes>\n extends SvgPrimitiveProps<EdgeState<T>, SVGGElement> {\n /** the edge it draws: the one `Flow.Edges` gives its children function */\n edge: FlowEdge<T>;\n /** its parts: default a `Flow.EdgePath` */\n children?: React.ReactNode;\n}\n\nconst EDGE_STYLE: React.CSSProperties = { pointerEvents: \"visibleStroke\" };\n\n/**\n * One edge (`data-flow-part=\"edge\"`, `data-flow-id`): an SVG group inside `Flow.Edges`, drawn once\n * both its nodes have a size. It renders its children (`Flow.EdgePath` by default,\n * `Flow.EdgeLabel`, `Flow.ReconnectAnchor`); a press on its stroke selects it (`selection()`).\n */\nexport function Edge<T extends FlowTypes = AnyTypes>(props: EdgeProps<T>) {\n const { edge, children, ...rest } = props;\n const { state, props: own } = useEdge<T>(edge);\n const { engine } = useFlowContext(\"Edge\");\n const context = React.useMemo(() => ({ edgeId: edge.id }), [edge.id]);\n // an edge that moved to another render level's SVG is a new element: the one that had focus\n // takes it back (`adapter.refocus` does nothing otherwise)\n const ref = React.useCallback(\n (element: Element | null) => {\n if (engine && element) engine.adapter.refocus(element);\n },\n [engine],\n );\n const element = useRenderElement(\"g\", rest, {\n state,\n ref,\n props: { ...own, children: children ?? <EdgePath /> },\n style: EDGE_STYLE,\n });\n if (!state.path) return null;\n return (\n <EdgeContext.Provider value={context}>{element}</EdgeContext.Provider>\n );\n}\n","import type { EdgePath } from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { EdgeLabelLayerContext, useEdgeId, useFlowContext } from \"../context\";\nimport { sameValue, useFlowValue } from \"../hooks/internal\";\nimport { staticEdgeAttributes, useEdgePath } from \"../hooks/use-edge\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface EdgeLabelState {\n readonly edgeId: string;\n /** the edge's path, label point and ends */\n readonly path: EdgePath;\n /** `data-selected` (`selection()`) */\n readonly selected: boolean;\n}\n\nexport interface EdgeLabelProps extends DivPrimitiveProps<EdgeLabelState> {\n /** the edge; default the enclosing `Flow.Edge`'s */\n edgeId?: string | undefined;\n children?: React.ReactNode;\n}\n\n/**\n * An edge's label (`data-flow-part=\"edge-label\"`): HTML, centred on the path's label point in\n * flow coordinates, in the HTML layer of `Flow.Edges` (a portal: SVG holds no HTML). It renders\n * only its children; a press on it selects its edge.\n */\nexport function EdgeLabel(props: EdgeLabelProps) {\n const { edgeId: edgeIdProp, ...rest } = props;\n const edgeId = useEdgeId(\"EdgeLabel\", edgeIdProp);\n const layer = React.useContext(EdgeLabelLayerContext);\n const { model, engine } = useFlowContext(\"EdgeLabel\");\n const path = useEdgePath(edgeId);\n const attributes = useFlowValue(\n model,\n engine,\n () =>\n engine\n ? engine.adapter.attributes(\"edge-label\", { edgeId })\n : staticEdgeAttributes(\n \"edge-label\",\n model.get(\"edge-by\", { id: edgeId }) ?? { id: edgeId },\n ),\n sameValue,\n \"entity\",\n { kind: \"edge\", id: edgeId },\n );\n if (!path || !attributes || !layer) return null;\n return createPortal(\n <EdgeLabelElement\n {...rest}\n state={{\n edgeId,\n path,\n selected: attributes[\"data-selected\"] !== undefined,\n }}\n attributes={attributes}\n />,\n layer,\n );\n}\n\nfunction EdgeLabelElement(\n props: Omit<EdgeLabelProps, \"edgeId\"> & {\n state: EdgeLabelState;\n attributes: Readonly<Record<string, string | undefined>>;\n },\n) {\n const { state, attributes, children, ...rest } = props;\n const { x, y } = state.path.label;\n return useRenderElement(\"div\", rest, {\n state,\n props: { ...attributes, children },\n style: {\n position: \"absolute\",\n top: 0,\n left: 0,\n transform: `translate(${x}px, ${y}px) translate(-50%, -50%)`,\n pointerEvents: \"all\",\n },\n });\n}\n","import type { EdgeToolbarPosition, PartAttributes, XY } from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useEdgeId, useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface EdgeToolbarState {\n readonly edgeId: string;\n /** the point of the edge it stands at */\n readonly position: \"label\" | \"source\" | \"target\";\n /** where it is anchored (its `alignX` / `alignY` point), in pixels relative to the root */\n readonly anchor: EdgeToolbarPosition;\n}\n\nexport interface EdgeToolbarProps extends DivPrimitiveProps<EdgeToolbarState> {\n /** its edge; default the enclosing `Flow.Edge`'s */\n edgeId?: string | undefined;\n /** the point of the edge it stands at: its label point, its source or its target end; default `\"label\"` */\n position?: \"label\" | \"source\" | \"target\" | undefined;\n /** a flow point it stands at instead (absolute flow coordinates); wins over `position` */\n point?: XY | undefined;\n /** a screen offset from that point, in pixels; default `{ x: 0, y: 0 }` */\n offset?: XY | undefined;\n /** which of its edges goes at the point across: its left (`\"start\"`), centre (default) or right */\n alignX?: \"start\" | \"center\" | \"end\" | undefined;\n /** which of its edges goes at the point down: its top (`\"start\"`), centre (default) or bottom */\n alignY?: \"start\" | \"center\" | \"end\" | undefined;\n /** whether it is shown; default while its edge is selected (`selection()`) */\n open?: boolean | undefined;\n children?: React.ReactNode;\n}\n\n/**\n * A toolbar on an edge (`data-flow-part=\"toolbar\"`, `data-flow-id` its edge's id), outside the\n * zoom: rendered in `Flow.Root` (a portal), centred at the point `edge-toolbar-by` gives (the\n * edge's label point or one of its ends), so it keeps its size at any zoom. Presses and the wheel\n * over it are left to it. It renders only its children (your buttons).\n */\nexport function EdgeToolbar(props: EdgeToolbarProps) {\n const {\n edgeId: edgeIdProp,\n position = \"label\",\n point,\n offset,\n alignX,\n alignY,\n open,\n ...rest\n } = props;\n const edgeId = useEdgeId(\"EdgeToolbar\", edgeIdProp);\n const { model, engine, rootElement } = useFlowContext(\"EdgeToolbar\");\n // hidden, it reads nothing of the view: a pan or a zoom gives the same value (no re-render);\n // shown, an equal anchor keeps the last value (records compared by their fields)\n const view = useFlowValue(model, engine, () => {\n if (!engine) return undefined;\n if (!(open ?? model.is(\"edge-selected\", { edgeId }))) return undefined;\n const anchor = engine.get(\"edge-toolbar-by\", {\n edgeId,\n position,\n point,\n offset,\n alignX,\n alignY,\n });\n return anchor\n ? {\n anchor,\n attributes: engine.adapter.attributes(\"toolbar\", { edgeId }),\n }\n : undefined;\n });\n if (!view || !rootElement) return null;\n return createPortal(\n <EdgeToolbarElement\n {...rest}\n state={{ edgeId, position, anchor: view.anchor }}\n attributes={view.attributes}\n />,\n rootElement,\n );\n}\n\nfunction EdgeToolbarElement(\n props: Omit<\n EdgeToolbarProps,\n | \"edgeId\"\n | \"position\"\n | \"point\"\n | \"offset\"\n | \"alignX\"\n | \"alignY\"\n | \"open\"\n > & {\n state: EdgeToolbarState;\n attributes: PartAttributes;\n },\n) {\n const { state, attributes, children, ...rest } = props;\n const { x, y, anchorX, anchorY } = state.anchor;\n return useRenderElement(\"div\", rest, {\n state,\n props: { ...attributes, children },\n style: {\n position: \"absolute\",\n top: 0,\n left: 0,\n transform: `translate(${x}px, ${y}px) translate(${-anchorX * 100}%, ${-anchorY * 100}%)`,\n },\n });\n}\n","import {\n type AnyTypes,\n edgesLayerAttributes,\n type FlowEdge,\n type FlowTypes,\n type PartAttributes,\n partAttributes,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { EdgeLabelLayerContext, useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport { shallowEqual } from \"../utils/shallow-equal\";\nimport {\n type DataAttributes,\n type DivPrimitiveProps,\n useRenderElement,\n} from \"../utils/use-render\";\n\nexport interface EdgesState {\n /** how many edges are drawn */\n count: number;\n}\n\nexport interface EdgesProps<T extends FlowTypes = AnyTypes>\n extends Omit<DivPrimitiveProps<EdgesState>, \"children\"> {\n /**\n * draws one edge: usually a `Flow.Edge` (an SVG group) with its path and label. A new function re-renders every\n * one: keep it stable (a module function, `useCallback`) when the app re-renders on each\n * change (controlled `nodes` / `edges`)\n */\n children: (edge: FlowEdge<T>) => React.ReactNode;\n}\n\nconst LAYER_STYLE: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: \"100%\",\n overflow: \"visible\",\n pointerEvents: \"none\",\n};\n\nconst NO_EDGES: readonly FlowEdge[] = Object.freeze([]);\n\ninterface EdgeSlotProps {\n edge: FlowEdge;\n render: (edge: FlowEdge) => React.ReactNode;\n}\n\n// one edge's drawing, again only when its edge (or the children function) changes; its path\n// re-renders by itself (`Flow.EdgePath` follows `edge-path-by`)\nconst EdgeSlot = React.memo(function EdgeSlot({ edge, render }: EdgeSlotProps) {\n return render(edge);\n});\n\n/** One render level's edges, and the attributes of its wrapper (none with one level). */\ninterface EdgeLevel {\n readonly level: number;\n readonly zIndex: number | undefined;\n readonly attributes: PartAttributes | undefined;\n readonly edges: readonly FlowEdge[];\n}\n\nfunction sameLevels(a: readonly EdgeLevel[], b: readonly EdgeLevel[]): boolean {\n return (\n a.length === b.length &&\n a.every((level, i) => {\n const other = b[i] as EdgeLevel;\n return (\n level.level === other.level &&\n level.zIndex === other.zIndex &&\n (level.attributes === other.attributes ||\n (level.attributes !== undefined &&\n other.attributes !== undefined &&\n shallowEqual(level.attributes, other.attributes))) &&\n level.edges.length === other.edges.length &&\n level.edges.every((edge, j) => edge === other.edges[j])\n );\n })\n );\n}\n\ninterface EdgeListProps {\n edges: readonly FlowEdge[];\n render: (edge: FlowEdge) => React.ReactNode;\n}\n\n// the SVG of a level's edges (`data-flow-part=\"edges\"`)\nfunction EdgeList({ edges, render }: EdgeListProps) {\n return (\n // biome-ignore lint/a11y/noSvgWithoutTitle: a layer of edges, not an image: each edge is the consumer's to name\n <svg {...partAttributes(\"edges\")} style={LAYER_STYLE}>\n {edges.map((edge) => (\n <EdgeSlot key={edge.id} edge={edge} render={render} />\n ))}\n </svg>\n );\n}\n\ninterface LevelLayerProps {\n level: EdgeLevel;\n render: (edge: FlowEdge) => React.ReactNode;\n}\n\n// one render level, with several (`data-flow-part=\"edges-layer\"`, `data-level`): stacked at the\n// level's z-index among the nodes, holding its edges' SVG and its edges' labels\nfunction LevelLayer({ level, render }: LevelLayerProps) {\n const [layer, setLayer] = React.useState<HTMLElement | null>(null);\n return (\n <EdgeLabelLayerContext.Provider value={layer}>\n <div\n {...(level.attributes as DataAttributes)}\n ref={setLayer}\n style={{ ...LAYER_STYLE, zIndex: level.zIndex }}\n >\n <EdgeList edges={level.edges} render={render} />\n </div>\n </EdgeLabelLayerContext.Provider>\n );\n}\n\n/**\n * The layer of the edges (`data-flow-part=\"edges\"`), inside `Flow.Viewport`, before `Flow.Nodes`:\n * an SVG (`data-flow-part=\"edges\"` too) where `children` draws each edge, once both its nodes have\n * a size, in the engine's drawing order (`drawn-edges`: by `zIndex`), and the HTML layer edge\n * labels go to. When an edge stands above some node (`render-layers`: a selected edge with\n * `zIndexMode` `\"auto\"`, a high `zIndex`), each render level gets a wrapper of its own\n * (`data-flow-part=\"edges-layer\"`, `data-level`, the level's `z-index`) holding its SVG and its\n * labels. Before the engine (the server render, the first client render) it draws the document's\n * static geometry (with `onlyRenderVisible`, no edge: the view is not known yet). It lets presses\n * through to the pane; the edges' own parts take them.\n */\nexport function Edges<T extends FlowTypes = AnyTypes>(props: EdgesProps<T>) {\n const { children, ...rest } = props;\n const { model, engine, staticGeometry, onlyRenderVisible } =\n useFlowContext(\"Edges\");\n // the core's levels and drawing order: shown, measured, in view with `onlyRenderVisible`, by\n // z-order; the static geometry's before the engine\n const levels = useFlowValue<readonly EdgeLevel[]>(\n model,\n engine,\n () => {\n const layers = engine\n ? engine.get(\"render-layers\")\n : (staticGeometry?.layers ?? []);\n const layered = layers.length > 1;\n // before the engine, a culled flow draws none: the view is not known yet\n const none = !engine && onlyRenderVisible;\n return layers.map((layer) => ({\n level: layer.level,\n zIndex: layer.zIndex,\n attributes: !layered\n ? undefined\n : engine\n ? engine.adapter.attributes(\"edges-layer\", {\n level: layer.level,\n })\n : edgesLayerAttributes(layer.level),\n edges: none\n ? NO_EDGES\n : layer.edgeIds.flatMap((id) => {\n const edge = model.get(\"edge-by\", { id });\n return edge ? [edge] : [];\n }),\n }));\n },\n sameLevels,\n );\n const [layer, setLayer] = React.useState<HTMLElement | null>(null);\n const render = children as unknown as (edge: FlowEdge) => React.ReactNode;\n const count = levels.reduce((sum, level) => sum + level.edges.length, 0);\n const element = useRenderElement(\"div\", rest, {\n state: { count },\n ref: setLayer as React.Ref<Element>,\n props: {\n ...partAttributes(\"edges\"),\n children:\n levels.length > 1 ? (\n levels.map((level) => (\n <LevelLayer\n key={level.level}\n level={level}\n render={render}\n />\n ))\n ) : (\n <EdgeList edges={levels[0]?.edges ?? []} render={render} />\n ),\n },\n style: LAYER_STYLE,\n });\n return (\n <EdgeLabelLayerContext.Provider value={layer}>\n {element}\n </EdgeLabelLayerContext.Provider>\n );\n}\n","// The buttons of `Flow.Controls`: each runs one engine action, and is disabled while the engine\n// refuses it (`engine.can`), re-rendering when the view changes.\nimport type { EngineActionKey } from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"./internal\";\n\n/** What a control button shows. */\nexport interface ControlButtonState {\n /** the engine refuses its action now (a zoom at its limit, `fit-view` before a size) */\n readonly disabled: boolean;\n}\n\n/** @internal a control button's state and own props: it runs `action` when clicked */\nexport function useControlButton(\n part: string,\n action: EngineActionKey,\n payload: () => object,\n disabledProp: boolean | undefined,\n): { state: ControlButtonState; props: Record<string, unknown> } {\n const { model, engine } = useFlowContext(part);\n const allowed = useFlowValue(model, engine, () =>\n engine ? engine.can(action, payload() as never) : false,\n );\n const disabled = disabledProp === true || !allowed;\n return {\n state: { disabled },\n props: {\n type: \"button\",\n \"data-flow-part\": partName(part),\n \"data-disabled\": disabled ? \"\" : undefined,\n disabled,\n onClick: (_event: React.MouseEvent) => {\n engine?.run(action, payload() as never);\n },\n },\n };\n}\n\n/** @internal a control's payload: its `duration` when given (an absent one is the engine's default) */\nexport function durationPayload(duration: number | undefined): {\n duration?: number;\n} {\n return givenPayload({ duration });\n}\n\n/** @internal a control's payload: the fields its props give (an absent one is the engine's default) */\nexport function givenPayload<P extends object>(fields: P): Partial<P> {\n return Object.fromEntries(\n Object.entries(fields).filter(([, value]) => value !== undefined),\n ) as Partial<P>;\n}\n\n/** `ZoomIn` → `zoom-in`. */\nfunction partName(part: string): string {\n return part.replace(\n /[A-Z]/g,\n (letter, at: number) => `${at === 0 ? \"\" : \"-\"}${letter.toLowerCase()}`,\n );\n}\n","import type { FitPadding } from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport {\n type ControlButtonState,\n givenPayload,\n useControlButton,\n} from \"../hooks/use-control-button\";\nimport {\n type ButtonPrimitiveProps,\n useRenderElement,\n} from \"../utils/use-render\";\n\nexport interface FitViewProps extends ButtonPrimitiveProps<ControlButtonState> {\n /** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */\n duration?: number | undefined;\n /**\n * the room kept free on every side: a share of the root's size, `\"<n>px\"`, or each side's\n * (`{ top, right, bottom, left }`); default the engine's 0.1\n */\n padding?: FitPadding | undefined;\n /** only these nodes; default every node that is not hidden */\n nodeIds?: string[] | undefined;\n /** without `nodeIds`, the hidden nodes of known size too; default false */\n includeHidden?: boolean | undefined;\n /** the least zoom it may pick (within the root's limits); default the root's `minZoom` */\n minZoom?: number | undefined;\n /** the greatest zoom it may pick (within the root's limits); default the root's `maxZoom` */\n maxZoom?: number | undefined;\n children?: React.ReactNode;\n}\n\n/**\n * A button (`data-flow-part=\"fit-view\"`): Fits every node in the root, or its `nodeIds` (`fit-view`, with its props as the payload), disabled before a node is measured. It renders only its\n * children (an icon, a label).\n */\nexport function FitView(props: FitViewProps) {\n const {\n children,\n disabled,\n duration,\n padding,\n nodeIds,\n includeHidden,\n minZoom,\n maxZoom,\n ...rest\n } = props;\n const { state, props: own } = useControlButton(\n \"FitView\",\n \"fit-view\",\n () =>\n givenPayload({\n duration,\n padding,\n nodeIds,\n includeHidden,\n minZoom,\n maxZoom,\n }),\n disabled,\n );\n return useRenderElement(\"button\", rest, {\n state,\n props: { ...own, children },\n });\n}\n","import type * as React from \"react\";\nimport {\n type HandleState,\n type UseHandleOptions,\n useHandle,\n} from \"../hooks/use-handle\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface HandleProps\n extends DivPrimitiveProps<HandleState>,\n UseHandleOptions {\n children?: React.ReactNode;\n}\n\n/** Where a handle sits by default: centred on its side of the node (a style may move it). */\nconst SIDE_STYLE: Record<HandleProps[\"side\"], React.CSSProperties> = {\n top: { top: 0, left: \"50%\", transform: \"translate(-50%, -50%)\" },\n right: { top: \"50%\", left: \"100%\", transform: \"translate(-50%, -50%)\" },\n bottom: { top: \"100%\", left: \"50%\", transform: \"translate(-50%, -50%)\" },\n left: { top: \"50%\", left: 0, transform: \"translate(-50%, -50%)\" },\n};\n\nconst HANDLE_STYLE: React.CSSProperties = { position: \"absolute\" };\n\n/**\n * A node's connection point (`data-flow-part=\"handle\"`, `data-handle-type`, `data-side`), inside\n * `Flow.Node`: registered with the engine (D8), which measures its centre; with `connection()`, a\n * press on it draws a connection. Absolutely positioned at the middle of its `side` by default;\n * your `style` may place it elsewhere on the node. Give it its size and look.\n */\nexport function Handle(props: HandleProps) {\n const {\n type,\n side,\n handleId,\n connectable,\n connectableStart,\n connectableEnd,\n nodeId,\n children,\n ...rest\n } = props;\n const { state, props: own } = useHandle({\n type,\n side,\n handleId,\n connectable,\n connectableStart,\n connectableEnd,\n nodeId,\n });\n const { ref, ...attributes } = own;\n return useRenderElement(\"div\", rest, {\n state,\n ref: ref as React.Ref<Element>,\n props: { ...attributes, children },\n style: HANDLE_STYLE,\n baseStyle: SIDE_STYLE[side],\n });\n}\n","import type { AnyTypes, FlowNode, FlowTypes } from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { NodeContext } from \"../context\";\nimport { type NodeState, useNode } from \"../hooks/use-node\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface NodeProps<T extends FlowTypes = AnyTypes>\n extends DivPrimitiveProps<NodeState<T>> {\n /** the node it renders: the one `Flow.Nodes` gives its children function */\n node: FlowNode<T>;\n children?: React.ReactNode;\n}\n\n/**\n * One node (`data-flow-part=\"node\"`, `data-flow-id`), absolutely positioned at its place in the\n * viewport (a structural `transform`), registered with the engine, which measures it and resolves\n * presses on it (drag, select, connect from its handles). It renders only its children: the\n * content, `Flow.Handle`s, a resizer, a toolbar.\n */\nexport function Node<T extends FlowTypes = AnyTypes>(props: NodeProps<T>) {\n const { node, children, ...rest } = props;\n const { state, props: own } = useNode<T>(node);\n const { ref, style, ...attributes } = own;\n const context = React.useMemo(() => ({ nodeId: node.id }), [node.id]);\n const element = useRenderElement(\"div\", rest, {\n state,\n ref: ref as React.Ref<Element>,\n props: { ...attributes, children },\n style,\n });\n return (\n <NodeContext.Provider value={context}>{element}</NodeContext.Provider>\n );\n}\n","import type {\n HandleSide,\n NodeToolbarPosition,\n PartAttributes,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { NodeContext, useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface NodeToolbarState {\n /** its node (undefined for several nodes' toolbar) */\n readonly nodeId: string | undefined;\n /** the nodes it stands beside: `nodeIds`, or its one node */\n readonly nodeIds: readonly string[];\n /** where it is anchored, in pixels relative to the root */\n readonly position: NodeToolbarPosition;\n readonly side: HandleSide;\n}\n\nexport interface NodeToolbarProps extends DivPrimitiveProps<NodeToolbarState> {\n /** its node; default the enclosing `Flow.Node`'s */\n nodeId?: string | undefined;\n /**\n * several nodes it stands beside (their bounds), instead of one; when not empty it wins over\n * `nodeId`, and the toolbar is shown by default while every one of them is selected\n */\n nodeIds?: readonly string[] | undefined;\n /** the node's side it stands on; default `\"top\"` */\n side?: HandleSide | undefined;\n /** where along that side; default `\"center\"` */\n align?: \"start\" | \"center\" | \"end\" | undefined;\n /** the gap between the node and the toolbar, in pixels; default 10 */\n offset?: number | undefined;\n /** whether it is shown; default while its node (every node of `nodeIds`) is selected (`selection()`) */\n open?: boolean | undefined;\n children?: React.ReactNode;\n}\n\n/**\n * A toolbar next to a node, or beside several nodes' bounds (`nodeIds`; `data-flow-part=\"toolbar\"`),\n * outside the zoom: rendered in\n * `Flow.Root` (a portal), at the anchor `node-toolbar-by` gives, so it keeps its size at any zoom.\n * Presses and the wheel over it are left to it. It renders only its children (your buttons).\n */\nexport function NodeToolbar(props: NodeToolbarProps) {\n const {\n nodeId: nodeIdProp,\n nodeIds: nodeIdsProp,\n side = \"top\",\n align,\n offset,\n open,\n ...rest\n } = props;\n const around = React.useContext(NodeContext);\n const many = nodeIdsProp !== undefined && nodeIdsProp.length > 0;\n const nodeId = many ? undefined : (nodeIdProp ?? around?.nodeId);\n if (!many && nodeId === undefined) {\n throw new Error(\n \"Flow.NodeToolbar must be rendered inside Flow.Node (or be given a nodeId or nodeIds)\",\n );\n }\n const { model, engine, rootElement } = useFlowContext(\"NodeToolbar\");\n // hidden, it reads nothing of the view: a pan or a zoom gives the same value (no re-render);\n // shown, an equal anchor keeps the last value (records compared by their fields)\n const view = useFlowValue(model, engine, () => {\n if (!engine) return undefined;\n const nodeIds = many ? nodeIdsProp : [nodeId as string];\n const shown =\n open ??\n nodeIds.every((id) => model.is(\"node-selected\", { nodeId: id }));\n if (!shown) return undefined;\n const position = engine.get(\"node-toolbar-by\", {\n ...(many ? { nodeIds } : { nodeId }),\n side,\n align,\n offset,\n });\n return position\n ? {\n position,\n nodeIds,\n attributes: engine.adapter.attributes(\n \"toolbar\",\n many ? {} : { nodeId },\n ),\n }\n : undefined;\n });\n if (!view || !rootElement) return null;\n return createPortal(\n <NodeToolbarElement\n {...rest}\n state={{\n nodeId,\n nodeIds: view.nodeIds,\n position: view.position,\n side,\n }}\n attributes={view.attributes}\n />,\n rootElement,\n );\n}\n\nfunction NodeToolbarElement(\n props: Omit<\n NodeToolbarProps,\n \"nodeId\" | \"nodeIds\" | \"side\" | \"align\" | \"offset\" | \"open\"\n > & {\n state: NodeToolbarState;\n attributes: PartAttributes;\n },\n) {\n const { state, attributes, children, ...rest } = props;\n const { x, y, anchorX, anchorY } = state.position;\n return useRenderElement(\"div\", rest, {\n state,\n props: { ...attributes, children },\n style: {\n position: \"absolute\",\n top: 0,\n left: 0,\n transform: `translate(${x}px, ${y}px) translate(${-anchorX * 100}%, ${-anchorY * 100}%)`,\n },\n });\n}\n","import {\n type AnyTypes,\n type FlowNode,\n type FlowTypes,\n partAttributes,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface NodesState {\n /** how many nodes are rendered */\n count: number;\n}\n\nexport interface NodesProps<T extends FlowTypes = AnyTypes>\n extends Omit<DivPrimitiveProps<NodesState>, \"children\"> {\n /**\n * renders one node: usually a `Flow.Node` with its content and handles. A new function re-renders every\n * one: keep it stable (a module function, `useCallback`) when the app re-renders on each\n * change (controlled `nodes` / `edges`)\n */\n children: (node: FlowNode<T>) => React.ReactNode;\n}\n\n// with one render level, its own stacking context: the nodes' z-index (a selected one raised)\n// orders them among themselves, never above what follows the layer (the connection line)\nconst NODES_STYLE: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n isolation: \"isolate\",\n};\n\n// with several render levels, none: the nodes' (negative) z-indexes interleave with the edge\n// levels' wrappers in the viewport's stacking context\nconst LAYERED_NODES_STYLE: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n};\n\nconst NO_NODES: readonly FlowNode[] = Object.freeze([]);\n\nconst shownNodes = (nodes: readonly FlowNode[]) =>\n nodes.filter((node) => node.hidden !== true);\n\ninterface NodeSlotProps {\n node: FlowNode;\n render: (node: FlowNode) => React.ReactNode;\n}\n\n// one node's rendering, again only when its node (or the children function) changes: a drag step\n// re-renders the moved nodes only (the model shares the nodes it did not change)\nconst NodeSlot = React.memo(function NodeSlot({ node, render }: NodeSlotProps) {\n return render(node);\n});\n\n/**\n * The layer of the nodes (`data-flow-part=\"nodes\"`), inside `Flow.Viewport`: calls `children` for\n * each node that is not hidden (with `onlyRenderVisible`, each one in view, `visible-nodes`), in\n * drawing order, keyed by its id (a node keeps its element when it moves, and never leaves this\n * layer: with several render levels its `z-index` places it among the edge levels). You render each\n * node. With `onlyRenderVisible`, the server render and the first client render (before the\n * engine knows the view) render none.\n */\nexport function Nodes<T extends FlowTypes = AnyTypes>(props: NodesProps<T>) {\n const { children, ...rest } = props;\n const { model, engine, staticGeometry, onlyRenderVisible } =\n useFlowContext(\"Nodes\");\n const list = useFlowValue(model, engine, () =>\n engine\n ? engine.adapter.settings.onlyRenderVisible\n ? engine.get(\"visible-nodes\")\n : shownNodes(model.get(\"all-nodes\"))\n : // before the engine, a culled flow renders none: the view is not known yet\n onlyRenderVisible\n ? NO_NODES\n : shownNodes(model.get(\"all-nodes\")),\n );\n const layered = useFlowValue(\n model,\n engine,\n () =>\n (engine\n ? engine.get(\"render-layers\")\n : (staticGeometry?.layers ?? [])\n ).length > 1,\n );\n const render = children as unknown as (node: FlowNode) => React.ReactNode;\n return useRenderElement(\"div\", rest, {\n state: { count: list.length },\n props: {\n ...partAttributes(\"nodes\"),\n children: list.map((node) => (\n <NodeSlot key={node.id} node={node} render={render} />\n )),\n },\n style: layered ? LAYERED_NODES_STYLE : NODES_STYLE,\n });\n}\n","import type { Rect } from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport {\n attributeProps,\n type DivPrimitiveProps,\n useRenderElement,\n} from \"../utils/use-render\";\n\nexport interface NodesSelectionState {\n /** the rectangle around the selected nodes, in flow coordinates */\n readonly rect: Rect;\n /** the selection is being dragged by it: `data-dragging` */\n readonly dragging: boolean;\n}\n\nexport interface NodesSelectionProps\n extends DivPrimitiveProps<NodesSelectionState> {\n children?: React.ReactNode;\n}\n\n/**\n * The rectangle around the selected nodes (`data-flow-part=\"nodes-selection\"`, `selection()`),\n * inside `Flow.Viewport` next to `Flow.Nodes` (it is in flow coordinates): rendered at\n * `selection-rect`, while two or more nodes are selected by a box (or always, with\n * `selection({ rect: \"always\" })`). A press on it drags the selection (`drag()`), its context\n * menu is the selection's. With `keyboard()` it takes focus, and its keys are a focused selected\n * node's: the arrows move the selection, the delete keys remove it, Escape clears it. Give it its\n * look.\n */\nexport function NodesSelection(props: NodesSelectionProps) {\n const { model, engine } = useFlowContext(\"NodesSelection\");\n const rect = useFlowValue(model, engine, () =>\n engine ? (engine.get(\"selection-rect\") ?? null) : null,\n );\n if (!rect) return null;\n return <NodesSelectionElement {...props} rect={rect} />;\n}\n\nfunction NodesSelectionElement(props: NodesSelectionProps & { rect: Rect }) {\n const { rect, children, ...rest } = props;\n const { model, engine } = useFlowContext(\"NodesSelection\");\n const attributes = useFlowValue(\n model,\n engine,\n () => engine?.adapter.attributes(\"nodes-selection\") ?? {},\n );\n return useRenderElement(\"div\", rest, {\n state: { rect, dragging: attributes[\"data-dragging\"] !== undefined },\n // the engine's record: `data-dragging`, and `tabindex` with `keyboard()` (arrows move it)\n props: {\n ...attributeProps(attributes),\n \"data-flow-part\": \"nodes-selection\",\n children,\n },\n style: {\n position: \"absolute\",\n top: 0,\n left: 0,\n transform: `translate(${rect.x}px, ${rect.y}px)`,\n width: rect.width,\n height: rect.height,\n },\n });\n}\n","import type { EdgePath } from \"@fragiola/flow\";\nimport { useEdgeId, useFlowContext } from \"../context\";\nimport { sameValue, useFlowValue } from \"../hooks/internal\";\nimport { useEdgePath } from \"../hooks/use-edge\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface ReconnectAnchorState {\n readonly edgeId: string;\n /** which end of the edge it moves */\n readonly end: \"source\" | \"target\";\n /** the edge's path and ends */\n readonly path: EdgePath;\n /** this edge's end is being moved */\n readonly reconnecting: boolean;\n}\n\nexport interface ReconnectAnchorProps\n extends SvgPrimitiveProps<ReconnectAnchorState, SVGCircleElement> {\n /** which end of the edge it moves */\n end: \"source\" | \"target\";\n /** the edge; default the enclosing `Flow.Edge`'s */\n edgeId?: string | undefined;\n}\n\n/**\n * An edge end's grab area (`data-flow-part=\"reconnect-anchor\"`, `data-end`): an SVG circle at the\n * end, inside `Flow.Edge`. With `reconnection()`, a press on it moves that end to another handle;\n * an end its edge's `reconnectable` keeps fixed (`false`, or the other end's name) draws none.\n * Transparent by default; give it its radius (`r`, default 10) and look.\n */\nexport function ReconnectAnchor(props: ReconnectAnchorProps) {\n const { edgeId: edgeIdProp, end, ...rest } = props;\n const edgeId = useEdgeId(\"ReconnectAnchor\", edgeIdProp);\n const { model, engine } = useFlowContext(\"ReconnectAnchor\");\n const path = useEdgePath(edgeId);\n const view = useFlowValue(\n model,\n engine,\n () =>\n engine\n ? {\n attributes: engine.adapter.attributes(\n \"reconnect-anchor\",\n {\n edgeId,\n end,\n },\n ),\n reconnecting: engine.is(\"edge-reconnecting\", { edgeId }),\n // `reconnectable: \"source\"` (or `\"target\"`, or false): no anchor at the other end\n movable: model.is(\"edge-reconnectable\", { edgeId, end }),\n }\n : undefined,\n sameValue,\n \"entity\",\n { kind: \"edge\", id: edgeId },\n );\n if (!path || !view?.movable) return null;\n return (\n <ReconnectAnchorElement\n {...rest}\n state={{ edgeId, end, path, reconnecting: view.reconnecting }}\n attributes={view.attributes}\n />\n );\n}\n\nfunction ReconnectAnchorElement(\n props: Omit<ReconnectAnchorProps, \"edgeId\" | \"end\"> & {\n state: ReconnectAnchorState;\n attributes: Readonly<Record<string, string | undefined>>;\n },\n) {\n const { state, attributes, ...rest } = props;\n const point = state.path[state.end];\n return useRenderElement(\"circle\", rest, {\n state,\n props: {\n ...attributes,\n cx: point.x,\n cy: point.y,\n r: 10,\n fill: \"transparent\",\n },\n style: { pointerEvents: \"all\" },\n });\n}\n","// The engine an app sees through `useFlow()` and a flow ref: always there, even before the root\n// mounted (the first render, the server), and the same object when the root replaces its engine\n// (StrictMode's second mount, a new model). It forwards every verb to the root's current engine;\n// with none, an action is refused and a read gives the empty answer. From Tree (fragiola/tree,\n// packages/react/src/utils/engine-facade.ts), same author and licence.\nimport type {\n CommandResult,\n FlowEngine,\n FlowEngineAdapter,\n FlowEngineEvent,\n Viewport,\n} from \"@fragiola/flow\";\n\n/** The facade, and how the root points it at its current engine. */\nexport interface EngineFacade {\n readonly engine: FlowEngine;\n /** the root's current engine (null: not mounted) */\n readonly current: FlowEngine | null;\n /** points the facade at `engine` (null: the root unmounted) */\n set(engine: FlowEngine | null): void;\n}\n\nconst NOT_MOUNTED: CommandResult<never> = Object.freeze({\n ok: false,\n error: Object.freeze({\n code: \"refused\",\n message: \"the flow is not mounted\",\n }),\n});\n\ntype Verb = (key: string, payload?: unknown) => unknown;\n\n/** A facade whose reads before the mount answer `viewport` with `initial`. */\nexport function createEngineFacade(initial: Viewport): EngineFacade {\n let current: FlowEngine | null = null;\n const listeners = new Set<(event: FlowEngineEvent) => void>();\n let unsubscribe: () => void = () => {};\n const empty: Readonly<Record<string, unknown>> = {\n viewport: Object.freeze({ ...initial }),\n \"root-size\": Object.freeze({ width: 0, height: 0 }),\n \"handles-by\": Object.freeze([]),\n \"dragging-node-ids\": Object.freeze([]),\n \"selection-box\": null,\n connection: null,\n };\n const forward =\n (verb: \"run\" | \"can\" | \"check\" | \"get\" | \"is\", fallback: Verb) =>\n (key: string, payload?: unknown) =>\n current\n ? (current[verb] as unknown as Verb)(key, payload)\n : fallback(key, payload);\n const engine = Object.freeze({\n run: forward(\"run\", () => NOT_MOUNTED),\n can: forward(\"can\", () => false),\n check: forward(\"check\", () => NOT_MOUNTED),\n get: forward(\"get\", (key) =>\n Object.hasOwn(empty, key) ? empty[key] : undefined,\n ),\n is: forward(\"is\", () => false),\n // listens across engines: a listener added before the mount hears the mounted engine\n subscribe(listener: (event: FlowEngineEvent) => void) {\n const wrapper = (event: FlowEngineEvent) => listener(event);\n listeners.add(wrapper);\n return () => {\n listeners.delete(wrapper);\n };\n },\n // the root owns its engine and destroys it when it unmounts\n destroy() {},\n get adapter(): FlowEngineAdapter {\n if (!current) throw new Error(\"the flow is not mounted\");\n return current.adapter;\n },\n }) as unknown as FlowEngine;\n return {\n engine,\n get current() {\n return current;\n },\n set(next) {\n if (next === current) return;\n unsubscribe();\n current = next;\n unsubscribe = next\n ? next.subscribe((event) => {\n for (const listener of [...listeners]) listener(event);\n })\n : () => {};\n },\n };\n}\n","import {\n type AnyTypes,\n type CommandEvent,\n type CreateId,\n createFlowEngine,\n createFlowModel,\n type DefaultEdgeOptions,\n ENGINE_EVENT_CALLBACKS,\n type FitViewPayload,\n type FlowEdge,\n type FlowEdgeInput,\n type FlowEngine,\n type FlowEngineEventOf,\n type FlowEngineOptions,\n type FlowFeatures,\n type FlowModel,\n type FlowNode,\n type FlowNodeInput,\n type FlowTypes,\n partAttributes,\n type StaticGeometry,\n type StaticGeometryOptions,\n staticGeometry,\n type Viewport,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport {\n type AnyFlowEngine,\n eraseModel,\n FlowContext,\n type FlowContextValue,\n} from \"../context\";\nimport { type FlowRef, setFlowRef } from \"../hooks/create-flow-ref\";\nimport { useFlowValue, useIsomorphicLayoutEffect } from \"../hooks/internal\";\nimport { createEngineFacade } from \"../utils/engine-facade\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface RootState {\n /** the gestures and keys may change the flow (`set-interactive`, `data-interactive`) */\n interactive: boolean;\n /** the viewport is being panned (`data-panning`) */\n panning: boolean;\n /** nodes are being dragged (`drag()`, `data-dragging`) */\n dragging: boolean;\n /** a connection is being drawn (`connection()`, `data-connecting`) */\n connecting: boolean;\n /** a box selection is being drawn (`selection()`, `data-selecting`) */\n selecting: boolean;\n}\n\n/** The engine's options a root takes as props: each one that changes applies at once. */\nexport type RootEngineProps = Pick<\n FlowEngineOptions,\n | \"minZoom\"\n | \"maxZoom\"\n | \"translateExtent\"\n | \"panOnDrag\"\n | \"panOnScroll\"\n | \"zoomOnScroll\"\n | \"zoomOnPinch\"\n | \"zoomOnDoubleClick\"\n | \"zoomStep\"\n | \"interactive\"\n | \"onlyRenderVisible\"\n | \"pathOptions\"\n | \"autoPan\"\n | \"panActivationKey\"\n | \"panOnScrollMode\"\n | \"panOnScrollSpeed\"\n | \"zoomActivationKey\"\n | \"easing\"\n | \"nodeOrigin\"\n | \"nodeExtent\"\n | \"elevateNodesOnSelect\"\n | \"elevateEdgesOnSelect\"\n | \"paneClickDistance\"\n | \"nodeClickDistance\"\n | \"preventScrolling\"\n | \"nodesFocusable\"\n | \"edgesFocusable\"\n | \"zIndexMode\"\n>;\n\ntype Callbacks = typeof ENGINE_EVENT_CALLBACKS;\n\n/**\n * The root's event callbacks, one per engine event (`ENGINE_EVENT_CALLBACKS`): `onNodeClick`,\n * `onMoveStart`, `onConnectCancel`, … each called with the event.\n */\nexport type RootEventProps = {\n [K in keyof Callbacks as `on${Callbacks[K]}`]?:\n | ((event: FlowEngineEventOf<K>) => void)\n | undefined;\n};\n\n/** The callback props' names, from the core's table. */\nconst CALLBACK_PROPS = Object.entries(ENGINE_EVENT_CALLBACKS).map(\n ([type, name]) => [type, `on${name}`] as const,\n);\nconst CALLBACK_BY_TYPE: ReadonlyMap<string, string> = new Map(CALLBACK_PROPS);\n\n/** Splits the event callbacks off a root's other props. */\nfunction splitCallbacks<P extends object>(\n props: P,\n): [Record<string, unknown>, P] {\n const callbacks: Record<string, unknown> = {};\n const rest = { ...props } as Record<string, unknown>;\n for (const [, name] of CALLBACK_PROPS) {\n if (name in rest) {\n callbacks[name] = rest[name];\n delete rest[name];\n }\n }\n return [callbacks, rest as P];\n}\n\nexport interface RootProps<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n> extends DivPrimitiveProps<RootState>,\n RootEngineProps,\n RootEventProps {\n /**\n * the flow model. Its middleware (`model.use`) sees every command the flow runs, and its\n * listeners (`model.subscribe`) every change. Give it, or let the root create one from\n * `nodes` / `defaultNodes` and `edges` / `defaultEdges`\n */\n model?: FlowModel<T, F> | undefined;\n /** the nodes of the model the root creates (read once, at mount) */\n defaultNodes?: readonly FlowNodeInput<T>[] | undefined;\n /** the edges of the model the root creates (read once, at mount) */\n defaultEdges?: readonly FlowEdgeInput<T>[] | undefined;\n /**\n * controlled nodes: each render brings the model to them with the commands a user would run\n * (`model.get(\"commands-to\")`, one `batch`); every change of the model's nodes calls\n * `onNodesChange`. Give every node its id\n */\n nodes?: readonly FlowNode<T>[] | undefined;\n /** called with the model's nodes after every command that changes them (a drag step too) */\n onNodesChange?: ((nodes: readonly FlowNode<T>[]) => void) | undefined;\n /** controlled edges, as `nodes` */\n edges?: readonly FlowEdge<T>[] | undefined;\n /** called with the model's edges after every command that changes them */\n onEdgesChange?: ((edges: readonly FlowEdge<T>[]) => void) | undefined;\n /**\n * the opt-in features of the model the root creates (read once, at mount):\n * `[selection(), drag(), connection()]`, each from its entry (`@fragiola/flow-react/drag`). A\n * `model` has its own\n */\n features?: F | undefined;\n /** the id generator of the model the root creates (read once, at mount) */\n createId?: CreateId | undefined;\n /**\n * the fields every `edge.add` of the model the root creates fills in where it leaves them out\n * (read once, at mount: the model option `defaultEdgeOptions`)\n */\n defaultEdgeOptions?: DefaultEdgeOptions<T> | undefined;\n /** controlled viewport: a new value is set on the engine (`set-viewport`) */\n viewport?: Viewport | undefined;\n /** the viewport the flow starts at (read once, at mount); default `{ x: 0, y: 0, zoom: 1 }` */\n defaultViewport?: Viewport | undefined;\n /** called on every viewport change, by a gesture (`gesture: true`) or an action */\n onViewportChange?:\n | ((viewport: Viewport, gesture: boolean) => void)\n | undefined;\n /** fits the nodes once their sizes are known, again once measured (read once, at mount) */\n fitView?: boolean | FitViewPayload | undefined;\n /** access to the model and the engine from outside the root (`useFlowRef`, `createFlowRef`) */\n flowRef?: FlowRef<T, F> | undefined;\n children?: React.ReactNode;\n}\n\n/** The `meta` of the commands that bring the model to the controlled props. */\nconst CONTROLLED_META = Object.freeze({ source: \"controlled\" });\n\n/** A list of features by their names, in order: an equal new list (`features={[drag()]}`) is the same. */\nfunction featureNames(features: FlowFeatures | undefined): string {\n return (features ?? []).map((feature) => feature.name).join(\",\");\n}\n\n/** Warns once per message and root: misuse that the root ignores. */\nfunction useWarnOnce() {\n const warned = React.useRef(new Set<string>());\n return (message: string) => {\n if (warned.current.has(message)) return;\n warned.current.add(message);\n console.warn(`[@fragiola/flow-react] ${message}`);\n };\n}\n\n/**\n * Each engine option's value as a key: a new equal object (`pathOptions`) is the same, a function\n * (`easing`) is itself, and `null` (`panActivationKey={null}`: none) is not `undefined` (the\n * default).\n */\nfunction optionKeys(options: RootEngineProps): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(options).map(([key, value]) => [\n key,\n typeof value === \"function\" || value === undefined\n ? value\n : JSON.stringify(value),\n ]),\n );\n}\n\n/** A key that changes when an engine option's value does (but a function's: see `easing`). */\nfunction optionsKey(options: RootEngineProps): string {\n return JSON.stringify(optionKeys(options), (_key, value) =>\n value === undefined ? \"undefined\" : value,\n );\n}\n\nconst DEFAULT_VIEWPORT: Viewport = Object.freeze({ x: 0, y: 0, zoom: 1 });\n\nconst ROOT_STYLE: React.CSSProperties = {\n position: \"relative\",\n overflow: \"hidden\",\n};\n\n/**\n * The flow (`data-flow-part=\"root\"`): owns the model (unless given) and the engine, attaches the\n * engine to its element (the engine listens to it: pointer, wheel, keys, focus) and re-renders\n * when the flow changes. It renders only its children; no Provider is needed above it. Give it a\n * size (the flow fills it).\n */\nexport function Root<\n T extends FlowTypes = AnyTypes,\n F extends FlowFeatures = readonly [],\n>(allProps: RootProps<T, F>) {\n const [callbacks, props] = splitCallbacks(allProps);\n const {\n model: modelProp,\n defaultNodes,\n defaultEdges,\n nodes,\n onNodesChange,\n edges,\n onEdgesChange,\n features,\n createId,\n defaultEdgeOptions,\n viewport,\n defaultViewport,\n onViewportChange,\n fitView,\n flowRef,\n minZoom,\n maxZoom,\n translateExtent,\n panOnDrag,\n panOnScroll,\n zoomOnScroll,\n zoomOnPinch,\n zoomOnDoubleClick,\n zoomStep,\n interactive,\n onlyRenderVisible,\n pathOptions,\n autoPan,\n panActivationKey,\n panOnScrollMode,\n panOnScrollSpeed,\n zoomActivationKey,\n easing,\n nodeOrigin,\n nodeExtent,\n elevateNodesOnSelect,\n elevateEdgesOnSelect,\n paneClickDistance,\n nodeClickDistance,\n preventScrolling,\n nodesFocusable,\n edgesFocusable,\n zIndexMode,\n children,\n ...rest\n } = props;\n const [ownModel] = React.useState(() =>\n modelProp\n ? null\n : createFlowModel<T, F>(\n {\n version: 1,\n nodes: [...(nodes ?? defaultNodes ?? [])],\n edges: [...(edges ?? defaultEdges ?? [])],\n } as never,\n { features, createId, defaultEdgeOptions },\n ),\n );\n const typed = (modelProp ?? ownModel) as FlowModel<T, F>;\n // the parts below work on the erased registry; the typed surface is their props\n const model = eraseModel(typed);\n\n // the features are the model's, fixed when it is created: a later change is ignored\n const warn = useWarnOnce();\n const [firstFeatures] = React.useState(() => featureNames(features));\n if (!modelProp && featureNames(features) !== firstFeatures) {\n warn(\n \"the features prop changed after the root created its model: the change is ignored (the features are fixed when the model is created)\",\n );\n }\n\n const engineProps: RootEngineProps = {\n minZoom,\n maxZoom,\n translateExtent,\n panOnDrag,\n panOnScroll,\n zoomOnScroll,\n zoomOnPinch,\n zoomOnDoubleClick,\n zoomStep,\n interactive,\n onlyRenderVisible,\n pathOptions,\n autoPan,\n panActivationKey,\n panOnScrollMode,\n panOnScrollSpeed,\n zoomActivationKey,\n easing,\n nodeOrigin,\n nodeExtent,\n elevateNodesOnSelect,\n elevateEdgesOnSelect,\n paneClickDistance,\n nodeClickDistance,\n preventScrolling,\n nodesFocusable,\n edgesFocusable,\n zIndexMode,\n };\n const engineKey = optionsKey(engineProps);\n // the callbacks and the creation options are read when needed: a new function each render\n // recreates nothing\n const latest = React.useRef({\n onNodesChange,\n onEdgesChange,\n onViewportChange,\n callbacks,\n engineProps,\n start: viewport ?? defaultViewport ?? DEFAULT_VIEWPORT,\n fitView,\n });\n latest.current = {\n ...latest.current,\n onNodesChange,\n onEdgesChange,\n onViewportChange,\n callbacks,\n engineProps,\n };\n\n const [facade] = React.useState(() =>\n createEngineFacade(viewport ?? defaultViewport ?? DEFAULT_VIEWPORT),\n );\n const [engine, setEngine] = React.useState<AnyFlowEngine | null>(null);\n // the engine options last sent, by key: a change sends only the keys that changed (an\n // `interactive` that stays must not undo the lock of `Flow.ToggleInteractive`)\n const sentOptions = React.useRef<Record<string, unknown>>({});\n // the engine is created once mounted, in the commit (StrictMode's second mount creates a new\n // one), so that no render ever attaches or observes anything\n useIsomorphicLayoutEffect(() => {\n const { start, fitView: fit, engineProps: options } = latest.current;\n const created = createFlowEngine(model, {\n ...options,\n // a remount (StrictMode) starts where the last engine was\n defaultViewport: facade.current?.get(\"viewport\") ?? start,\n fitView: fit,\n }) as unknown as AnyFlowEngine;\n sentOptions.current = optionKeys(options);\n facade.set(created as unknown as FlowEngine);\n setEngine(created);\n const stop = created.subscribe((event) => {\n if (event.type === \"viewport-change\") {\n latest.current.start = event.viewport;\n latest.current.onViewportChange?.(\n event.viewport,\n event.gesture,\n );\n return;\n }\n // the event's callback (`onNodeClick`, `onMoveStart`, …), the latest one given\n const name = CALLBACK_BY_TYPE.get(event.type);\n const callback = name ? latest.current.callbacks[name] : undefined;\n if (typeof callback === \"function\") callback(event);\n });\n return () => {\n stop();\n facade.set(null);\n created.destroy();\n };\n }, [model, facade]);\n // a destroyed engine (StrictMode's first mount, a replaced model) is never used again\n const live = engine && engine.adapter.model === model ? engine : null;\n\n // the engine options that changed since they were sent\n useIsomorphicLayoutEffect(() => {\n if (!live) return;\n const next = optionKeys(latest.current.engineProps);\n const changed = Object.keys(next).filter(\n (key) => next[key] !== sentOptions.current[key],\n );\n sentOptions.current = next;\n if (changed.length === 0) return;\n const props = latest.current.engineProps as Record<string, unknown>;\n live.adapter.setOptions(\n Object.fromEntries(changed.map((key) => [key, props[key]])),\n );\n }, [live, engineKey, easing]);\n\n // a controlled viewport that differs from the engine's is set on it\n useIsomorphicLayoutEffect(() => {\n if (!live || !viewport) return;\n const current = live.get(\"viewport\");\n if (\n current.x !== viewport.x ||\n current.y !== viewport.y ||\n current.zoom !== viewport.zoom\n ) {\n live.run(\"set-viewport\", {\n x: viewport.x,\n y: viewport.y,\n zoom: viewport.zoom,\n });\n }\n }, [live, viewport?.x, viewport?.y, viewport?.zoom]);\n\n // onNodesChange / onEdgesChange on every commit that changes them, but the controlled props'\n useIsomorphicLayoutEffect(\n () =>\n model.subscribe((event: CommandEvent) => {\n if (event.meta?.source === CONTROLLED_META.source) return;\n const {\n onNodesChange: nodesChanged,\n onEdgesChange: edgesChanged,\n } = latest.current;\n if (event.before.nodes !== event.after.nodes) {\n nodesChanged?.(event.after.nodes as readonly FlowNode<T>[]);\n }\n if (event.before.edges !== event.after.edges) {\n edgesChanged?.(event.after.edges as readonly FlowEdge<T>[]);\n }\n }),\n [model],\n );\n\n // the controlled lists the model was last brought to (a model the root created starts at them)\n const sent = React.useRef<{\n model: unknown;\n nodes: unknown;\n edges: unknown;\n }>({ model: ownModel, nodes, edges });\n useIsomorphicLayoutEffect(() => {\n const previous = sent.current;\n const sameModel = previous.model === model;\n // only a list that changed is diffed (an edge list that stays is not walked on each step)\n const target = {\n nodes: (sameModel && previous.nodes === nodes\n ? undefined\n : nodes) as readonly FlowNode[] | undefined,\n edges: (sameModel && previous.edges === edges\n ? undefined\n : edges) as readonly FlowEdge[] | undefined,\n };\n sent.current = { model, nodes, edges };\n if (target.nodes === undefined && target.edges === undefined) return;\n const commands = model.get(\"commands-to\", target);\n if (commands.length === 0) return;\n const options = { meta: CONTROLLED_META };\n if (!model.run(\"batch\", { commands: [...commands] }, options).ok) {\n // refused as a whole (a middleware's veto): each change that may be made is, and the\n // app hears what the model holds instead\n const refused: string[] = [];\n for (const entry of commands) {\n const result = model.run(\n \"batch\",\n { commands: [entry] },\n options,\n );\n if (!result.ok)\n refused.push(`${entry.command}: ${result.error.message}`);\n }\n warn(\n `the controlled nodes / edges were not all applied (the model's are reported back):\\n${refused.join(\"\\n\")}`,\n );\n }\n // what the model holds when it differs from the props (a veto, a rule that kept a node\n // in its parent, a middleware that rewrote a payload): the app's state follows the model\n const { onNodesChange: nodesChanged, onEdgesChange: edgesChanged } =\n latest.current;\n if (\n target.nodes !== undefined &&\n model.get(\"commands-to\", { nodes: target.nodes }).length > 0\n ) {\n nodesChanged?.(model.get(\"all-nodes\") as readonly FlowNode<T>[]);\n }\n if (\n target.edges !== undefined &&\n model.get(\"commands-to\", { edges: target.edges }).length > 0\n ) {\n edgesChanged?.(model.get(\"all-edges\") as readonly FlowEdge<T>[]);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (!flowRef) return;\n const ref = flowRef as unknown as FlowRef<FlowTypes, FlowFeatures>;\n setFlowRef(ref, {\n model: typed as unknown as FlowModel<FlowTypes, FlowFeatures>,\n engine: facade.engine as unknown as FlowEngine<\n FlowTypes,\n FlowFeatures\n >,\n });\n return () => setFlowRef(ref, null);\n }, [flowRef, typed, facade]);\n\n const [rootElement, setRootElement] = React.useState<HTMLElement | null>(\n null,\n );\n const rootRef = React.useCallback(\n (element: HTMLElement | null) => {\n setRootElement(element);\n if (!element || !live) return;\n live.adapter.attachRoot(element);\n return () => live.adapter.detachRoot();\n },\n [live],\n );\n\n // before the engine (the server render, the first client render): the geometry of the\n // document with the options the engine gets, worked out once per document or options change,\n // so that the server's output and the first client render are the same\n const staticOptions: StaticGeometryOptions = {\n nodeOrigin,\n pathOptions,\n zIndexMode,\n elevateNodesOnSelect,\n elevateEdgesOnSelect,\n };\n const staticKey = JSON.stringify(staticOptions);\n const staticCache = React.useRef<\n | {\n nodes: unknown;\n edges: unknown;\n key: string;\n geometry: StaticGeometry;\n }\n | undefined\n >(undefined);\n const geometry = useFlowValue(model, live, () => {\n if (live) return null;\n const flow = {\n nodes: model.get(\"all-nodes\"),\n edges: model.get(\"all-edges\"),\n };\n const cached = staticCache.current;\n if (\n cached?.nodes === flow.nodes &&\n cached.edges === flow.edges &&\n cached.key === staticKey\n ) {\n return cached.geometry;\n }\n const computed = staticGeometry(flow, staticOptions);\n staticCache.current = { ...flow, key: staticKey, geometry: computed };\n return computed;\n });\n\n const attributes = useFlowValue(model, live, () =>\n live ? live.adapter.attributes(\"root\") : partAttributes(\"root\"),\n );\n const state: RootState = {\n interactive: live ? attributes[\"data-interactive\"] !== undefined : true,\n panning: attributes[\"data-panning\"] !== undefined,\n dragging: attributes[\"data-dragging\"] !== undefined,\n connecting: attributes[\"data-connecting\"] !== undefined,\n selecting: attributes[\"data-selecting\"] !== undefined,\n };\n const context = React.useMemo<FlowContextValue>(\n () => ({\n model,\n engine: live,\n publicEngine: facade.engine as unknown as AnyFlowEngine,\n rootElement,\n staticGeometry: geometry,\n onlyRenderVisible: onlyRenderVisible === true,\n }),\n [model, live, facade, rootElement, geometry, onlyRenderVisible],\n );\n const element = useRenderElement(\"div\", rest, {\n state,\n ref: rootRef as React.Ref<Element>,\n props: { ...attributes, children },\n style: ROOT_STYLE,\n });\n return (\n <FlowContext.Provider value={context}>{element}</FlowContext.Provider>\n );\n}\n","import type { Rect } from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface SelectionBoxState {\n /** the box, in pixels relative to the root */\n readonly box: Rect;\n}\n\nexport interface SelectionBoxProps\n extends DivPrimitiveProps<SelectionBoxState> {\n children?: React.ReactNode;\n}\n\n/**\n * The box selection being drawn (`data-flow-part=\"selection-box\"`, `selection()`): absolutely\n * positioned in `Flow.Root` (outside `Flow.Viewport`: it is in screen pixels), rendered only\n * while a box is drawn. Give it its look.\n */\nexport function SelectionBox(props: SelectionBoxProps) {\n const { model, engine } = useFlowContext(\"SelectionBox\");\n const box = useFlowValue(model, engine, () =>\n engine ? engine.get(\"selection-box\") : null,\n );\n if (!box) return null;\n return <SelectionBoxElement {...props} box={box} />;\n}\n\nfunction SelectionBoxElement(props: SelectionBoxProps & { box: Rect }) {\n const { box, children, ...rest } = props;\n const { model, engine } = useFlowContext(\"SelectionBox\");\n const attributes = useFlowValue(\n model,\n engine,\n () => engine?.adapter.attributes(\"selection-box\") ?? {},\n );\n return useRenderElement(\"div\", rest, {\n state: { box },\n props: {\n ...attributes,\n \"data-flow-part\": \"selection-box\",\n children,\n },\n style: {\n position: \"absolute\",\n left: box.x,\n top: box.y,\n width: box.width,\n height: box.height,\n pointerEvents: \"none\",\n },\n });\n}\n","import type * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue } from \"../hooks/internal\";\nimport {\n type ButtonPrimitiveProps,\n useRenderElement,\n} from \"../utils/use-render\";\n\n/** The switches the lock turns off and on (React Flow's: dragging, connecting, selecting). */\nconst LOCKED_KINDS = [\"drag\", \"connect\", \"select\"] as const;\n\nexport interface ToggleInteractiveState {\n /**\n * the flow is not locked: it is interactive and one of dragging, connecting and selecting at\n * least is on (`interactive-by`)\n */\n readonly interactive: boolean;\n}\n\nexport interface ToggleInteractiveProps\n extends ButtonPrimitiveProps<ToggleInteractiveState> {\n children?: React.ReactNode;\n}\n\n/**\n * A toggle button (`data-flow-part=\"toggle-interactive\"`, `aria-pressed` while the flow is locked,\n * `data-interactive`): locks and unlocks the flow, React Flow's interactive button: locking turns\n * dragging, connecting and selecting off (`set-interactive { drag, connect, select }`), unlocking\n * turns them and `interactive` on; pan and zoom stay. It renders only its children.\n */\nexport function ToggleInteractive(props: ToggleInteractiveProps) {\n const { children, ...rest } = props;\n const { model, engine } = useFlowContext(\"ToggleInteractive\");\n const interactive = useFlowValue(model, engine, () =>\n engine\n ? LOCKED_KINDS.some((kind) => engine.is(\"interactive-by\", { kind }))\n : true,\n );\n return useRenderElement(\"button\", rest, {\n state: { interactive },\n props: {\n type: \"button\",\n \"data-flow-part\": \"toggle-interactive\",\n \"data-interactive\": interactive ? \"\" : undefined,\n \"aria-pressed\": !interactive,\n disabled: engine === null,\n onClick: () => {\n engine?.run(\n \"set-interactive\",\n interactive\n ? { drag: false, connect: false, select: false }\n : {\n interactive: true,\n drag: true,\n connect: true,\n select: true,\n },\n );\n },\n children,\n },\n });\n}\n","import { partAttributes, type Viewport as ViewportValue } from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useViewport } from \"../hooks/use-viewport\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\n\nexport interface ViewportState {\n /** the viewport: the pan (`x`, `y`, pixels) and the zoom */\n viewport: ViewportValue;\n}\n\nexport interface ViewportProps extends DivPrimitiveProps<ViewportState> {\n children?: React.ReactNode;\n}\n\nconst VIEWPORT_STYLE: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: \"100%\",\n // a stacking context of its own before the engine writes its transform (the server's HTML):\n // with several render levels the nodes and edge layers have negative z-indexes\n isolation: \"isolate\",\n};\n\n/**\n * The pannable, zoomable layer (`data-flow-part=\"viewport\"`): what is inside is in flow\n * coordinates (`Flow.Edges`, `Flow.Nodes`, `Flow.ConnectionLine`). The engine writes its\n * `transform` itself (D4), never React: a pan or a zoom re-renders nothing inside it.\n */\nexport function Viewport(props: ViewportProps) {\n const { children, ...rest } = props;\n const { engine } = useFlowContext(\"Viewport\");\n const viewport = useViewport();\n const ref = React.useCallback(\n (element: HTMLElement | null) => {\n if (!engine) return;\n engine.adapter.attachViewport(element);\n return () => engine.adapter.attachViewport(null);\n },\n [engine],\n );\n return useRenderElement(\"div\", rest, {\n state: { viewport },\n ref: ref as React.Ref<Element>,\n props: { ...partAttributes(\"viewport\"), children },\n style: VIEWPORT_STYLE,\n });\n}\n","import type * as React from \"react\";\nimport {\n type ControlButtonState,\n durationPayload,\n useControlButton,\n} from \"../hooks/use-control-button\";\nimport {\n type ButtonPrimitiveProps,\n useRenderElement,\n} from \"../utils/use-render\";\n\nexport interface ZoomInProps extends ButtonPrimitiveProps<ControlButtonState> {\n /** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */\n duration?: number | undefined;\n children?: React.ReactNode;\n}\n\n/**\n * A button (`data-flow-part=\"zoom-in\"`): Zooms in by a step around the root's centre (`zoom-in`), disabled at the greatest zoom. It renders only its\n * children (an icon, a label).\n */\nexport function ZoomIn(props: ZoomInProps) {\n const { children, disabled, duration, ...rest } = props;\n const { state, props: own } = useControlButton(\n \"ZoomIn\",\n \"zoom-in\",\n () => durationPayload(duration),\n disabled,\n );\n return useRenderElement(\"button\", rest, {\n state,\n props: { ...own, children },\n });\n}\n","import type * as React from \"react\";\nimport {\n type ControlButtonState,\n durationPayload,\n useControlButton,\n} from \"../hooks/use-control-button\";\nimport {\n type ButtonPrimitiveProps,\n useRenderElement,\n} from \"../utils/use-render\";\n\nexport interface ZoomOutProps extends ButtonPrimitiveProps<ControlButtonState> {\n /** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */\n duration?: number | undefined;\n children?: React.ReactNode;\n}\n\n/**\n * A button (`data-flow-part=\"zoom-out\"`): Zooms out by a step around the root's centre (`zoom-out`), disabled at the least zoom. It renders only its\n * children (an icon, a label).\n */\nexport function ZoomOut(props: ZoomOutProps) {\n const { children, disabled, duration, ...rest } = props;\n const { state, props: own } = useControlButton(\n \"ZoomOut\",\n \"zoom-out\",\n () => durationPayload(duration),\n disabled,\n );\n return useRenderElement(\"button\", rest, {\n state,\n props: { ...own, children },\n });\n}\n","// The `Flow` namespace: `import { Flow } from \"@fragiola/flow-react\"`, then `Flow.Root`,\n// `Flow.Node`, … The features' primitives are on their entries (`MiniMap` on\n// `@fragiola/flow-react/minimap`, `NodeResizer` on `/resize`), so this one never imports them.\nexport { Background } from \"./components/background\";\nexport { ConnectionLine } from \"./components/connection-line\";\nexport { Controls } from \"./components/controls\";\nexport { Edge } from \"./components/edge\";\nexport { EdgeLabel } from \"./components/edge-label\";\nexport { EdgePath } from \"./components/edge-path\";\nexport { EdgeToolbar } from \"./components/edge-toolbar\";\nexport { Edges } from \"./components/edges\";\nexport { FitView } from \"./components/fit-view\";\nexport { Handle } from \"./components/handle\";\nexport { Node } from \"./components/node\";\nexport { NodeToolbar } from \"./components/node-toolbar\";\nexport { Nodes } from \"./components/nodes\";\nexport { NodesSelection } from \"./components/nodes-selection\";\nexport { ReconnectAnchor } from \"./components/reconnect-anchor\";\nexport { Root } from \"./components/root\";\nexport { SelectionBox } from \"./components/selection-box\";\nexport { ToggleInteractive } from \"./components/toggle-interactive\";\nexport { Viewport } from \"./components/viewport\";\nexport { ZoomIn } from \"./components/zoom-in\";\nexport { ZoomOut } from \"./components/zoom-out\";\n"],"mappings":";;;;;;;;AAkCA,MAAM,wBAAQ,IAAI,QAAyB;AAE3C,SAAS,OAAO,KAAsB;CAClC,MAAM,OAAO,MAAM,IAAI,GAAG;CAC1B,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,8CAA8C;CACzE,OAAO;AACX;;;;;;;;;;;AAYA,SAAgB,gBAGG;CACf,MAAM,OAAgB;EAAE,OAAO;EAAM,2BAAW,IAAI,IAAI;CAAE;CAC1D,MAAM,MAAqB,OAAO,OAAO,EACrC,IAAI,UAAU;EACV,OAAO,KAAK;CAChB,EACJ,CAAC;CACD,MAAM,IAAI,KAAK,IAAI;CACnB,OAAO;AACX;;AAGA,SAAgB,WACZ,KACA,OACI;CACJ,MAAM,OAAO,OAAO,GAAG;CACvB,IAAK,KAAK,UAAsB,OAAO;CACvC,KAAK,QAAQ;CACb,KAAK,MAAM,YAAY,CAAC,GAAG,KAAK,SAAS,GAAG,SAAS;AACzD;;AAGA,SAAgB,iBACZ,KACA,UACU;CACV,MAAM,EAAE,cAAc,OAAO,GAAG;CAChC,UAAU,IAAI,QAAQ;CACtB,aAAa;EACT,UAAU,OAAO,QAAQ;CAC7B;AACJ;;;;;;;AC9EA,SAAgB,gBAAmC;CAC/C,MAAM,EAAE,OAAO,WAAW,eAAe,eAAe;CACxD,OAAO,aACH,OACA,cACM,QAAQ,IAAI,YAAY,KAAK,OAClC,GAAG,MACA,MAAM,KACL,MAAM,QACH,MAAM,QACN,EAAE,SAAS,EAAE,QACb,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,EAAE,MACX,EAAE,SAAS,EAAE,QACb,EAAE,WAAW,EAAE,MAC3B;AACJ;;;ACeA,SAAgB,aACZ,GACA,GACO;CACP,IAAI,MAAM,GA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OAAO,OAAO,QAAQ,iBAC1B,UACA,iBACM,gBAAgB,QAAQ,GAC9B,QACJ;CACA,OAAO,iBAAiB,UAAU,MAAM;EACpC;EACA,OAAO;GAAE,GAAG;GAAK;EAAS;CAC9B,CAAC;AACL;;;;;;ACZA,SAAgB,QAAQ,OAAqB;CACzC,MAAM,EAAE,UAAU,UAAU,UAAU,GAAG,SAAS;CAClD,MAAM,EAAE,OAAO,OAAO,QAAQ,iBAC1B,WACA,kBACM,gBAAgB,QAAQ,GAC9B,QACJ;CACA,OAAO,iBAAiB,UAAU,MAAM;EACpC;EACA,OAAO;GAAE,GAAG;GAAK;EAAS;CAC9B,CAAC;AACL"}
@@ -0,0 +1 @@
1
+ export * from "@fragiola/flow/keyboard";
@@ -0,0 +1 @@
1
+ export * from "@fragiola/flow/keyboard";
@@ -0,0 +1,68 @@
1
+ import { c as SvgPrimitiveProps } from "./use-render-BoW0zIae.js";
2
+ import { MinimapView, XY } from "@fragiola/flow";
3
+ import * as React from "react";
4
+ export * from "@fragiola/flow/minimap";
5
+ interface MiniMapState {
6
+ /** what it draws: the nodes, the view and the mask, in flow coordinates */
7
+ readonly view: MinimapView;
8
+ }
9
+ interface MiniMapProps extends Omit<SvgPrimitiveProps<MiniMapState, SVGSVGElement>, "children" | "onClick"> {
10
+ /** its width, in pixels; default 200 */
11
+ width?: number | undefined;
12
+ /** its height, in pixels; default 150 */
13
+ height?: number | undefined;
14
+ /**
15
+ * a drag on it moves the view the other way (as grabbing the flow), and a press does not
16
+ * centre the view; default `minimap()`'s `inversePan`
17
+ */
18
+ inversePan?: boolean | undefined;
19
+ /** how fast its wheel zooms: 10 is the flow's own wheel, 20 twice as fast; default `minimap()`'s `zoomStep` */
20
+ zoomStep?: number | undefined;
21
+ /**
22
+ * a tap on it (`minimap-click`), with the flow point under the pointer on the minimap: center
23
+ * the view there, add a node there
24
+ */
25
+ onClick?: ((event: MouseEvent, point: XY) => void) | undefined;
26
+ /**
27
+ * what it draws, in flow coordinates; default a `MiniMapNode` per node, then the `MiniMapMask`
28
+ */
29
+ children?: React.ReactNode | ((view: MinimapView) => React.ReactNode);
30
+ }
31
+ /**
32
+ * A small map of the flow (`data-flow-part="minimap"`, `minimap()`): an SVG of `width` × `height`
33
+ * pixels showing every node and what the root shows. With `minimap()`'s options, a drag on it pans
34
+ * and its wheel zooms the flow. Inside `Flow.Root`, outside `Flow.Viewport`; place it with your
35
+ * style.
36
+ */
37
+ export declare function MiniMap(props: MiniMapProps): React.JSX.Element;
38
+ /** The state of `MiniMapMask`: the root's view, in flow coordinates. */
39
+ interface MiniMapMaskState {
40
+ readonly view: {
41
+ x: number;
42
+ y: number;
43
+ width: number;
44
+ height: number;
45
+ };
46
+ }
47
+ interface MiniMapMaskProps extends SvgPrimitiveProps<MiniMapMaskState, SVGPathElement> {}
48
+ /**
49
+ * The `MiniMap`'s mask (`data-flow-part="minimap-mask"`): an SVG path covering the map but what the
50
+ * root shows (`fill-rule="evenodd"`). Give it its fill.
51
+ */
52
+ export declare function MiniMapMask(props: MiniMapMaskProps): import("react").JSX.Element;
53
+ interface MiniMapNodeState {
54
+ readonly nodeId: string;
55
+ /** `data-selected` (`selection()`) */
56
+ readonly selected: boolean;
57
+ }
58
+ interface MiniMapNodeProps extends SvgPrimitiveProps<MiniMapNodeState, SVGRectElement> {
59
+ /** the node it stands for */
60
+ nodeId: string;
61
+ }
62
+ /**
63
+ * A node in the `MiniMap` (`data-flow-part="minimap-node"`, `data-flow-id`): an SVG rectangle of
64
+ * the node's box, in flow coordinates. Nothing when the node is not shown.
65
+ */
66
+ export declare function MiniMapNode(props: MiniMapNodeProps): import("react").JSX.Element | null;
67
+ export type { MiniMapMaskProps, MiniMapMaskState, MiniMapNodeProps, MiniMapNodeState, MiniMapProps, MiniMapState };
68
+ //# sourceMappingURL=minimap.d.ts.map
@@ -0,0 +1,137 @@
1
+ import { a as useIsomorphicLayoutEffect, h as useFlowContext, i as useFlowValue, n as useRenderElement, r as sameValue } from "./use-render-Dfsx9V4b.js";
2
+ import { partAttributes } from "@fragiola/flow";
3
+ import * as React from "react";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ export * from "@fragiola/flow/minimap";
6
+ // src/minimap/mini-map-context.ts
7
+ /** The view of the enclosing `MiniMap`, for its nodes and its mask. */
8
+ const MiniMapContext = React.createContext(null);
9
+ function useMiniMapView(part) {
10
+ const view = React.useContext(MiniMapContext);
11
+ if (!view) throw new Error(`${part} must be rendered inside MiniMap`);
12
+ return view;
13
+ }
14
+ // src/minimap/mini-map-mask.tsx
15
+ /**
16
+ * The `MiniMap`'s mask (`data-flow-part="minimap-mask"`): an SVG path covering the map but what the
17
+ * root shows (`fill-rule="evenodd"`). Give it its fill.
18
+ */
19
+ function MiniMapMask(props) {
20
+ const view = useMiniMapView("MiniMapMask");
21
+ return useRenderElement("path", props, {
22
+ state: { view: view.view },
23
+ props: {
24
+ ...partAttributes("minimap-mask"),
25
+ d: view.maskPath,
26
+ fillRule: "evenodd"
27
+ }
28
+ });
29
+ }
30
+ // src/minimap/mini-map-node.tsx
31
+ /**
32
+ * A node in the `MiniMap` (`data-flow-part="minimap-node"`, `data-flow-id`): an SVG rectangle of
33
+ * the node's box, in flow coordinates. Nothing when the node is not shown.
34
+ */
35
+ function MiniMapNode(props) {
36
+ const { nodeId, ...rest } = props;
37
+ const view = useMiniMapView("MiniMapNode");
38
+ const { model, engine } = useFlowContext("MiniMapNode");
39
+ const attributes = useFlowValue(model, engine, () => engine ? engine.adapter.attributes("minimap-node", { nodeId }) : partAttributes("minimap-node", nodeId), sameValue, "entity");
40
+ const box = view.nodes.find((node) => node.nodeId === nodeId);
41
+ const element = useRenderElement("rect", rest, {
42
+ state: {
43
+ nodeId,
44
+ selected: attributes["data-selected"] !== void 0
45
+ },
46
+ props: {
47
+ ...attributes,
48
+ x: box?.x,
49
+ y: box?.y,
50
+ width: box?.width,
51
+ height: box?.height
52
+ }
53
+ });
54
+ return box ? element : null;
55
+ }
56
+ // src/minimap/mini-map.tsx
57
+ const EMPTY_VIEW = Object.freeze({
58
+ viewBox: Object.freeze({
59
+ x: 0,
60
+ y: 0,
61
+ width: 0,
62
+ height: 0
63
+ }),
64
+ viewBoxAttribute: "0 0 0 0",
65
+ scale: 1,
66
+ nodes: Object.freeze([]),
67
+ view: Object.freeze({
68
+ x: 0,
69
+ y: 0,
70
+ width: 0,
71
+ height: 0
72
+ }),
73
+ maskPath: ""
74
+ });
75
+ /**
76
+ * A small map of the flow (`data-flow-part="minimap"`, `minimap()`): an SVG of `width` × `height`
77
+ * pixels showing every node and what the root shows. With `minimap()`'s options, a drag on it pans
78
+ * and its wheel zooms the flow. Inside `Flow.Root`, outside `Flow.Viewport`; place it with your
79
+ * style.
80
+ */
81
+ function MiniMap(props) {
82
+ const { width = 200, height = 150, inversePan, zoomStep, onClick, children, ...rest } = props;
83
+ const { model, engine } = useFlowContext("MiniMap");
84
+ useIsomorphicLayoutEffect(() => {
85
+ if (!engine) return;
86
+ const options = Object.fromEntries(Object.entries({
87
+ inversePan,
88
+ zoomStep
89
+ }).filter(([, value]) => value !== void 0));
90
+ engine.adapter.setPartOptions("minimap", "", options);
91
+ return () => engine.adapter.setPartOptions("minimap", "", null);
92
+ }, [
93
+ engine,
94
+ inversePan,
95
+ zoomStep
96
+ ]);
97
+ const latestClick = React.useRef(onClick);
98
+ latestClick.current = onClick;
99
+ const own = React.useRef(null);
100
+ React.useEffect(() => {
101
+ if (!engine) return;
102
+ return engine.subscribe((event) => {
103
+ if (event.type === "minimap-click" && event.element === own.current) latestClick.current?.(event.event, event.point);
104
+ });
105
+ }, [engine]);
106
+ const view = useFlowValue(model, engine, () => engine?.get("minimap-view", {
107
+ width,
108
+ height
109
+ }) ?? EMPTY_VIEW, (a, b) => a === b || a.viewBoxAttribute === b.viewBoxAttribute && a.maskPath === b.maskPath && a.nodes.length === b.nodes.length && a.nodes.every((node, i) => {
110
+ const other = b.nodes[i];
111
+ return other !== void 0 && node.nodeId === other.nodeId && node.x === other.x && node.y === other.y && node.width === other.width && node.height === other.height;
112
+ }));
113
+ const attributes = useFlowValue(model, engine, () => engine ? engine.adapter.attributes("minimap") : partAttributes("minimap"));
114
+ const content = typeof children === "function" ? children(view) : children ?? /* @__PURE__ */ jsxs(Fragment, { children: [view.nodes.map((node) => /* @__PURE__ */ jsx(MiniMapNode, { nodeId: node.nodeId }, node.nodeId)), /* @__PURE__ */ jsx(MiniMapMask, {})] });
115
+ const element = useRenderElement("svg", rest, {
116
+ ref: own,
117
+ state: { view },
118
+ props: {
119
+ ...attributes,
120
+ viewBox: view.viewBoxAttribute,
121
+ width,
122
+ height,
123
+ children: content
124
+ },
125
+ style: {
126
+ width,
127
+ height
128
+ }
129
+ });
130
+ return /* @__PURE__ */ jsx(MiniMapContext.Provider, {
131
+ value: view,
132
+ children: element
133
+ });
134
+ }
135
+ export { MiniMap, MiniMapMask, MiniMapNode };
136
+
137
+ //# sourceMappingURL=minimap.js.map