@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,713 @@
1
+ import { a as PrimitiveProps, c as SvgPrimitiveProps, i as DivPrimitiveProps, n as ButtonPrimitiveProps, o as RenderProp, r as DataAttributes, s as RenderedProps, t as AttributeProps } from "./use-render-BoW0zIae.js";
2
+ import { AnyTypes, BackgroundPattern, BackgroundVariant, Connection, CreateId, DefaultEdgeOptions, ENGINE_EVENT_CALLBACKS, EdgePath, EdgeToolbarPosition, FitPadding, FitViewPayload, FlowEdge, FlowEdgeInput, FlowEngine, FlowEngineEventOf, FlowEngineOptions, FlowFeatures, FlowModel, FlowNode, FlowNodeInput, FlowTypes, HandleSide, HandleType, InternalNode, KeyPressKeys, KeyPressTarget, NodeConnection, NodeData, NodeToolbarPosition, PartAttributes, Rect, Viewport, XY } from "@fragiola/flow";
3
+ import * as React from "react";
4
+ export * from "@fragiola/flow";
5
+ interface BackgroundState {
6
+ /** the pattern's tile on the screen, at the current viewport */
7
+ readonly pattern: BackgroundPattern;
8
+ }
9
+ interface BackgroundProps extends Omit<SvgPrimitiveProps<BackgroundState, SVGSVGElement>, "children" | "offset"> {
10
+ /** the marks: `dots` (default), `lines` or `cross` */
11
+ variant?: BackgroundVariant | undefined;
12
+ /** the distance between two marks, in flow units; default 20 (`[x, y]` for two) */
13
+ gap?: number | readonly [number, number] | undefined;
14
+ /** dots: a dot's diameter (flow units); lines: the stroke width (screen pixels); cross: a bar's length */
15
+ size?: number | undefined;
16
+ /** the pattern's shift from the flow's origin, in flow units */
17
+ offset?: number | readonly [number, number] | undefined;
18
+ }
19
+ /**
20
+ * The flow's background (`data-flow-part="background"`): an SVG pattern of dots, lines or crosses
21
+ * that pans and zooms with the viewport (`background-pattern`), inside `Flow.Root` before
22
+ * `Flow.Viewport`. The marks are drawn in `currentColor`: set the `color` (and the background
23
+ * itself) in your style.
24
+ */
25
+ declare function Background(props: BackgroundProps): React.JSX.Element;
26
+ interface ConnectionLineState {
27
+ /** the connection being drawn */
28
+ readonly connection: Connection;
29
+ /** the drop would add the edge: `data-valid` */
30
+ readonly valid: boolean;
31
+ /** the drop would be refused (`model.can("edge.add")`, a middleware's veto): `data-invalid` */
32
+ readonly invalid: boolean;
33
+ }
34
+ interface ConnectionLineProps extends Omit<SvgPrimitiveProps<ConnectionLineState, SVGSVGElement>, "children"> {
35
+ /**
36
+ * draws the line, in flow coordinates; default an unfilled `<path>` of the connection's path
37
+ * (`data-flow-part="connection-path"`)
38
+ */
39
+ children?: ((connection: Connection) => React.ReactNode) | undefined;
40
+ }
41
+ /**
42
+ * The connection being drawn (`data-flow-part="connection-line"`, `data-valid` / `data-invalid`,
43
+ * `connection()`): an SVG inside `Flow.Viewport`, rendered only while a connection is under way.
44
+ */
45
+ declare function ConnectionLine(props: ConnectionLineProps): React.JSX.Element | null;
46
+ /** The state of `Flow.Controls` (none: its buttons have their own). */
47
+ type ControlsState = Record<never, never>;
48
+ interface ControlsProps extends DivPrimitiveProps<ControlsState> {
49
+ children?: React.ReactNode;
50
+ }
51
+ /**
52
+ * A group of the viewport's buttons (`data-flow-part="controls"`): `Flow.ZoomIn`, `Flow.ZoomOut`,
53
+ * `Flow.FitView`, `Flow.ToggleInteractive`, or your own. Inside `Flow.Root`, outside
54
+ * `Flow.Viewport`; presses and the wheel over it are left to it. Place it with your style.
55
+ */
56
+ declare function Controls(props: ControlsProps): React.JSX.Element;
57
+ /** What an edge shows: its state on screen. */
58
+ interface EdgeState<T extends FlowTypes = AnyTypes> {
59
+ readonly edgeId: string;
60
+ /** the edge, as the model holds it */
61
+ readonly edge: FlowEdge<T>;
62
+ /**
63
+ * its path, label point and ends (`edge-path-by`), once both its nodes have a size; an app
64
+ * type gets the bezier path, and its ends to draw its own
65
+ */
66
+ readonly path: EdgePath | undefined;
67
+ /** `data-selected` (`selection()`) */
68
+ readonly selected: boolean;
69
+ /** one of its ends is being moved (`reconnection()`) */
70
+ readonly reconnecting: boolean;
71
+ /** it takes DOM focus (`keyboard()`): `tabindex="0"` */
72
+ readonly focusable: boolean;
73
+ readonly attributes: PartAttributes;
74
+ }
75
+ interface UseEdgeResult<T extends FlowTypes = AnyTypes> {
76
+ state: EdgeState<T>;
77
+ /** what goes on the edge's element (an SVG group): its attributes and `tabIndex` */
78
+ props: {
79
+ tabIndex: number | undefined;
80
+ } & DataAttributes;
81
+ }
82
+ /** An edge's state and the props of its element, for an edge drawn by hand (`Flow.Edge` uses it). */
83
+ export declare function useEdge<T extends FlowTypes = AnyTypes>(edge: FlowEdge<T>): UseEdgeResult<T>;
84
+ interface EdgeProps<T extends FlowTypes = AnyTypes> extends SvgPrimitiveProps<EdgeState<T>, SVGGElement> {
85
+ /** the edge it draws: the one `Flow.Edges` gives its children function */
86
+ edge: FlowEdge<T>;
87
+ /** its parts: default a `Flow.EdgePath` */
88
+ children?: React.ReactNode;
89
+ }
90
+ /**
91
+ * One edge (`data-flow-part="edge"`, `data-flow-id`): an SVG group inside `Flow.Edges`, drawn once
92
+ * both its nodes have a size. It renders its children (`Flow.EdgePath` by default,
93
+ * `Flow.EdgeLabel`, `Flow.ReconnectAnchor`); a press on its stroke selects it (`selection()`).
94
+ */
95
+ declare function Edge<T extends FlowTypes = AnyTypes>(props: EdgeProps<T>): React.JSX.Element | null;
96
+ interface EdgeLabelState {
97
+ readonly edgeId: string;
98
+ /** the edge's path, label point and ends */
99
+ readonly path: EdgePath;
100
+ /** `data-selected` (`selection()`) */
101
+ readonly selected: boolean;
102
+ }
103
+ interface EdgeLabelProps extends DivPrimitiveProps<EdgeLabelState> {
104
+ /** the edge; default the enclosing `Flow.Edge`'s */
105
+ edgeId?: string | undefined;
106
+ children?: React.ReactNode;
107
+ }
108
+ /**
109
+ * An edge's label (`data-flow-part="edge-label"`): HTML, centred on the path's label point in
110
+ * flow coordinates, in the HTML layer of `Flow.Edges` (a portal: SVG holds no HTML). It renders
111
+ * only its children; a press on it selects its edge.
112
+ */
113
+ declare function EdgeLabel(props: EdgeLabelProps): React.ReactPortal | null;
114
+ interface EdgePathState {
115
+ readonly edgeId: string;
116
+ /** the edge's path, label point and ends */
117
+ readonly path: EdgePath;
118
+ /** `data-selected` (`selection()`) */
119
+ readonly selected: boolean;
120
+ }
121
+ interface EdgePathProps extends SvgPrimitiveProps<EdgePathState, SVGPathElement> {
122
+ /** the edge; default the enclosing `Flow.Edge`'s */
123
+ edgeId?: string | undefined;
124
+ }
125
+ /**
126
+ * An edge's path (`data-flow-part="edge-path"`): an SVG `<path>` whose `d` is the engine's
127
+ * (`edge-path-by`, D9), unfilled. A `d` of your own draws an app type (from `state.path`'s ends).
128
+ * Several may share an edge: a wide transparent one is a bigger press target.
129
+ */
130
+ declare function EdgePath$1(props: EdgePathProps): import("react").JSX.Element | null;
131
+ interface EdgeToolbarState {
132
+ readonly edgeId: string;
133
+ /** the point of the edge it stands at */
134
+ readonly position: "label" | "source" | "target";
135
+ /** where it is anchored (its `alignX` / `alignY` point), in pixels relative to the root */
136
+ readonly anchor: EdgeToolbarPosition;
137
+ }
138
+ interface EdgeToolbarProps extends DivPrimitiveProps<EdgeToolbarState> {
139
+ /** its edge; default the enclosing `Flow.Edge`'s */
140
+ edgeId?: string | undefined;
141
+ /** the point of the edge it stands at: its label point, its source or its target end; default `"label"` */
142
+ position?: "label" | "source" | "target" | undefined;
143
+ /** a flow point it stands at instead (absolute flow coordinates); wins over `position` */
144
+ point?: XY | undefined;
145
+ /** a screen offset from that point, in pixels; default `{ x: 0, y: 0 }` */
146
+ offset?: XY | undefined;
147
+ /** which of its edges goes at the point across: its left (`"start"`), centre (default) or right */
148
+ alignX?: "start" | "center" | "end" | undefined;
149
+ /** which of its edges goes at the point down: its top (`"start"`), centre (default) or bottom */
150
+ alignY?: "start" | "center" | "end" | undefined;
151
+ /** whether it is shown; default while its edge is selected (`selection()`) */
152
+ open?: boolean | undefined;
153
+ children?: React.ReactNode;
154
+ }
155
+ /**
156
+ * A toolbar on an edge (`data-flow-part="toolbar"`, `data-flow-id` its edge's id), outside the
157
+ * zoom: rendered in `Flow.Root` (a portal), centred at the point `edge-toolbar-by` gives (the
158
+ * edge's label point or one of its ends), so it keeps its size at any zoom. Presses and the wheel
159
+ * over it are left to it. It renders only its children (your buttons).
160
+ */
161
+ declare function EdgeToolbar(props: EdgeToolbarProps): React.ReactPortal | null;
162
+ interface EdgesState {
163
+ /** how many edges are drawn */
164
+ count: number;
165
+ }
166
+ interface EdgesProps<T extends FlowTypes = AnyTypes> extends Omit<DivPrimitiveProps<EdgesState>, "children"> {
167
+ /**
168
+ * draws one edge: usually a `Flow.Edge` (an SVG group) with its path and label. A new function re-renders every
169
+ * one: keep it stable (a module function, `useCallback`) when the app re-renders on each
170
+ * change (controlled `nodes` / `edges`)
171
+ */
172
+ children: (edge: FlowEdge<T>) => React.ReactNode;
173
+ }
174
+ /**
175
+ * The layer of the edges (`data-flow-part="edges"`), inside `Flow.Viewport`, before `Flow.Nodes`:
176
+ * an SVG (`data-flow-part="edges"` too) where `children` draws each edge, once both its nodes have
177
+ * a size, in the engine's drawing order (`drawn-edges`: by `zIndex`), and the HTML layer edge
178
+ * labels go to. When an edge stands above some node (`render-layers`: a selected edge with
179
+ * `zIndexMode` `"auto"`, a high `zIndex`), each render level gets a wrapper of its own
180
+ * (`data-flow-part="edges-layer"`, `data-level`, the level's `z-index`) holding its SVG and its
181
+ * labels. Before the engine (the server render, the first client render) it draws the document's
182
+ * static geometry (with `onlyRenderVisible`, no edge: the view is not known yet). It lets presses
183
+ * through to the pane; the edges' own parts take them.
184
+ */
185
+ declare function Edges<T extends FlowTypes = AnyTypes>(props: EdgesProps<T>): React.JSX.Element;
186
+ /** What a control button shows. */
187
+ interface ControlButtonState {
188
+ /** the engine refuses its action now (a zoom at its limit, `fit-view` before a size) */
189
+ readonly disabled: boolean;
190
+ }
191
+ interface FitViewProps extends ButtonPrimitiveProps<ControlButtonState> {
192
+ /** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */
193
+ duration?: number | undefined;
194
+ /**
195
+ * the room kept free on every side: a share of the root's size, `"<n>px"`, or each side's
196
+ * (`{ top, right, bottom, left }`); default the engine's 0.1
197
+ */
198
+ padding?: FitPadding | undefined;
199
+ /** only these nodes; default every node that is not hidden */
200
+ nodeIds?: string[] | undefined;
201
+ /** without `nodeIds`, the hidden nodes of known size too; default false */
202
+ includeHidden?: boolean | undefined;
203
+ /** the least zoom it may pick (within the root's limits); default the root's `minZoom` */
204
+ minZoom?: number | undefined;
205
+ /** the greatest zoom it may pick (within the root's limits); default the root's `maxZoom` */
206
+ maxZoom?: number | undefined;
207
+ children?: React.ReactNode;
208
+ }
209
+ /**
210
+ * 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
211
+ * children (an icon, a label).
212
+ */
213
+ declare function FitView(props: FitViewProps): React.JSX.Element;
214
+ interface UseHandleOptions {
215
+ /** whether edges start (`source`) or end (`target`) here */
216
+ type: HandleType;
217
+ /** the side of the node it sits on: the direction its edges leave or enter by */
218
+ side: HandleSide;
219
+ /** its id among the node's handles of its type (none: the node's default handle) */
220
+ handleId?: string | undefined;
221
+ /** whether a connection may start or end here; default true */
222
+ connectable?: boolean | undefined;
223
+ /** whether a connection may start here (a drag, a tap, a key); default true */
224
+ connectableStart?: boolean | undefined;
225
+ /** whether a connection may end here (be its target); default true */
226
+ connectableEnd?: boolean | undefined;
227
+ /** its node; default the enclosing `Flow.Node`'s */
228
+ nodeId?: string | undefined;
229
+ }
230
+ /** What a handle shows. */
231
+ interface HandleState {
232
+ readonly nodeId: string;
233
+ readonly handleId: string | undefined;
234
+ readonly type: HandleType;
235
+ readonly side: HandleSide;
236
+ /** a connection may start or end here (its flag and its node's): `data-connectable` */
237
+ readonly connectable: boolean;
238
+ /** a connection may start here: `data-connectable-start` */
239
+ readonly connectableStart: boolean;
240
+ /** a connection may end here: `data-connectable-end` */
241
+ readonly connectableEnd: boolean;
242
+ /** the connection under way starts here (`connection()`): `data-connecting` */
243
+ readonly connecting: boolean;
244
+ /** the connection under way would end here and be accepted: `data-valid` */
245
+ readonly valid: boolean;
246
+ /** the connection under way would end here and be refused: `data-invalid` */
247
+ readonly invalid: boolean;
248
+ readonly attributes: PartAttributes;
249
+ }
250
+ interface UseHandleResult {
251
+ state: HandleState;
252
+ /**
253
+ * what goes on the handle's element: its attributes (`tabIndex` with `keyboard()` and
254
+ * `connection()`) and the ref that registers it (D8)
255
+ */
256
+ props: {
257
+ ref: React.RefCallback<Element>;
258
+ } & AttributeProps;
259
+ }
260
+ /**
261
+ * A handle's state and the props of its element, for a handle rendered by hand (`Flow.Handle`
262
+ * uses it): registered with the engine, which measures its centre relative to its node.
263
+ */
264
+ export declare function useHandle(options: UseHandleOptions): UseHandleResult;
265
+ interface HandleProps extends DivPrimitiveProps<HandleState>, UseHandleOptions {
266
+ children?: React.ReactNode;
267
+ }
268
+ /**
269
+ * A node's connection point (`data-flow-part="handle"`, `data-handle-type`, `data-side`), inside
270
+ * `Flow.Node`: registered with the engine (D8), which measures its centre; with `connection()`, a
271
+ * press on it draws a connection. Absolutely positioned at the middle of its `side` by default;
272
+ * your `style` may place it elsewhere on the node. Give it its size and look.
273
+ */
274
+ declare function Handle(props: HandleProps): React.JSX.Element;
275
+ /** What a node shows: its state on screen. */
276
+ interface NodeState<T extends FlowTypes = AnyTypes> {
277
+ readonly nodeId: string;
278
+ /** the node, as the model holds it */
279
+ readonly node: FlowNode<T>;
280
+ /** its top-left corner in absolute flow coordinates (its parents' positions added) */
281
+ readonly x: number;
282
+ readonly y: number;
283
+ /** `data-selected` (`selection()`) */
284
+ readonly selected: boolean;
285
+ /** `data-dragging` (`drag()`) */
286
+ readonly dragging: boolean;
287
+ /** `data-resizing` (`resize()`) */
288
+ readonly resizing: boolean;
289
+ /** its size is known (measured or given): `data-measured` */
290
+ readonly measured: boolean;
291
+ /** it takes DOM focus (`keyboard()`): `tabindex="0"` */
292
+ readonly focusable: boolean;
293
+ /** the attributes its element carries (`data-flow-part`, `data-flow-id`, the state) */
294
+ readonly attributes: PartAttributes;
295
+ }
296
+ interface UseNodeResult<T extends FlowTypes = AnyTypes> {
297
+ state: NodeState<T>;
298
+ /**
299
+ * what goes on the node's element: its attributes, `tabIndex`, its structural style (absolute,
300
+ * at its position, its `z-index` among the nodes, with the document's size when given) and the ref that registers it with the
301
+ * engine (measured)
302
+ */
303
+ props: {
304
+ ref: React.RefCallback<HTMLElement>;
305
+ tabIndex: number | undefined;
306
+ style: React.CSSProperties;
307
+ } & DataAttributes;
308
+ }
309
+ /**
310
+ * A node's state and the props of its element, for a node rendered by hand (`Flow.Node` uses it).
311
+ * Spread `props` on the element (the engine resolves presses from its attributes).
312
+ */
313
+ export declare function useNode<T extends FlowTypes = AnyTypes>(node: FlowNode<T>): UseNodeResult<T>;
314
+ interface NodeProps<T extends FlowTypes = AnyTypes> extends DivPrimitiveProps<NodeState<T>> {
315
+ /** the node it renders: the one `Flow.Nodes` gives its children function */
316
+ node: FlowNode<T>;
317
+ children?: React.ReactNode;
318
+ }
319
+ /**
320
+ * One node (`data-flow-part="node"`, `data-flow-id`), absolutely positioned at its place in the
321
+ * viewport (a structural `transform`), registered with the engine, which measures it and resolves
322
+ * presses on it (drag, select, connect from its handles). It renders only its children: the
323
+ * content, `Flow.Handle`s, a resizer, a toolbar.
324
+ */
325
+ declare function Node<T extends FlowTypes = AnyTypes>(props: NodeProps<T>): React.JSX.Element;
326
+ interface NodeToolbarState {
327
+ /** its node (undefined for several nodes' toolbar) */
328
+ readonly nodeId: string | undefined;
329
+ /** the nodes it stands beside: `nodeIds`, or its one node */
330
+ readonly nodeIds: readonly string[];
331
+ /** where it is anchored, in pixels relative to the root */
332
+ readonly position: NodeToolbarPosition;
333
+ readonly side: HandleSide;
334
+ }
335
+ interface NodeToolbarProps extends DivPrimitiveProps<NodeToolbarState> {
336
+ /** its node; default the enclosing `Flow.Node`'s */
337
+ nodeId?: string | undefined;
338
+ /**
339
+ * several nodes it stands beside (their bounds), instead of one; when not empty it wins over
340
+ * `nodeId`, and the toolbar is shown by default while every one of them is selected
341
+ */
342
+ nodeIds?: readonly string[] | undefined;
343
+ /** the node's side it stands on; default `"top"` */
344
+ side?: HandleSide | undefined;
345
+ /** where along that side; default `"center"` */
346
+ align?: "start" | "center" | "end" | undefined;
347
+ /** the gap between the node and the toolbar, in pixels; default 10 */
348
+ offset?: number | undefined;
349
+ /** whether it is shown; default while its node (every node of `nodeIds`) is selected (`selection()`) */
350
+ open?: boolean | undefined;
351
+ children?: React.ReactNode;
352
+ }
353
+ /**
354
+ * A toolbar next to a node, or beside several nodes' bounds (`nodeIds`; `data-flow-part="toolbar"`),
355
+ * outside the zoom: rendered in
356
+ * `Flow.Root` (a portal), at the anchor `node-toolbar-by` gives, so it keeps its size at any zoom.
357
+ * Presses and the wheel over it are left to it. It renders only its children (your buttons).
358
+ */
359
+ declare function NodeToolbar(props: NodeToolbarProps): React.ReactPortal | null;
360
+ interface NodesState {
361
+ /** how many nodes are rendered */
362
+ count: number;
363
+ }
364
+ interface NodesProps<T extends FlowTypes = AnyTypes> extends Omit<DivPrimitiveProps<NodesState>, "children"> {
365
+ /**
366
+ * renders one node: usually a `Flow.Node` with its content and handles. A new function re-renders every
367
+ * one: keep it stable (a module function, `useCallback`) when the app re-renders on each
368
+ * change (controlled `nodes` / `edges`)
369
+ */
370
+ children: (node: FlowNode<T>) => React.ReactNode;
371
+ }
372
+ /**
373
+ * The layer of the nodes (`data-flow-part="nodes"`), inside `Flow.Viewport`: calls `children` for
374
+ * each node that is not hidden (with `onlyRenderVisible`, each one in view, `visible-nodes`), in
375
+ * drawing order, keyed by its id (a node keeps its element when it moves, and never leaves this
376
+ * layer: with several render levels its `z-index` places it among the edge levels). You render each
377
+ * node. With `onlyRenderVisible`, the server render and the first client render (before the
378
+ * engine knows the view) render none.
379
+ */
380
+ declare function Nodes<T extends FlowTypes = AnyTypes>(props: NodesProps<T>): React.JSX.Element;
381
+ interface NodesSelectionState {
382
+ /** the rectangle around the selected nodes, in flow coordinates */
383
+ readonly rect: Rect;
384
+ /** the selection is being dragged by it: `data-dragging` */
385
+ readonly dragging: boolean;
386
+ }
387
+ interface NodesSelectionProps extends DivPrimitiveProps<NodesSelectionState> {
388
+ children?: React.ReactNode;
389
+ }
390
+ /**
391
+ * The rectangle around the selected nodes (`data-flow-part="nodes-selection"`, `selection()`),
392
+ * inside `Flow.Viewport` next to `Flow.Nodes` (it is in flow coordinates): rendered at
393
+ * `selection-rect`, while two or more nodes are selected by a box (or always, with
394
+ * `selection({ rect: "always" })`). A press on it drags the selection (`drag()`), its context
395
+ * menu is the selection's. With `keyboard()` it takes focus, and its keys are a focused selected
396
+ * node's: the arrows move the selection, the delete keys remove it, Escape clears it. Give it its
397
+ * look.
398
+ */
399
+ declare function NodesSelection(props: NodesSelectionProps): React.JSX.Element | null;
400
+ interface ReconnectAnchorState {
401
+ readonly edgeId: string;
402
+ /** which end of the edge it moves */
403
+ readonly end: "source" | "target";
404
+ /** the edge's path and ends */
405
+ readonly path: EdgePath;
406
+ /** this edge's end is being moved */
407
+ readonly reconnecting: boolean;
408
+ }
409
+ interface ReconnectAnchorProps extends SvgPrimitiveProps<ReconnectAnchorState, SVGCircleElement> {
410
+ /** which end of the edge it moves */
411
+ end: "source" | "target";
412
+ /** the edge; default the enclosing `Flow.Edge`'s */
413
+ edgeId?: string | undefined;
414
+ }
415
+ /**
416
+ * An edge end's grab area (`data-flow-part="reconnect-anchor"`, `data-end`): an SVG circle at the
417
+ * end, inside `Flow.Edge`. With `reconnection()`, a press on it moves that end to another handle;
418
+ * an end its edge's `reconnectable` keeps fixed (`false`, or the other end's name) draws none.
419
+ * Transparent by default; give it its radius (`r`, default 10) and look.
420
+ */
421
+ declare function ReconnectAnchor(props: ReconnectAnchorProps): import("react").JSX.Element | null;
422
+ /** What a flow ref gives once its `Flow.Root` is mounted: the root's model and engine. */
423
+ interface FlowRefValue<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> {
424
+ readonly model: FlowModel<T, F>;
425
+ readonly engine: FlowEngine<T, F>;
426
+ }
427
+ /**
428
+ * Access to a `Flow.Root` from outside it (a toolbar, a menu, a test): pass it as the root's
429
+ * `flowRef`; `current` is the root's model and engine while it is mounted, `null` otherwise.
430
+ */
431
+ interface FlowRef<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> {
432
+ readonly current: FlowRefValue<T, F> | null;
433
+ }
434
+ /**
435
+ * Creates a flow ref outside React (a module, a test). In a component, `useFlowRef` keeps one and
436
+ * re-renders when it attaches.
437
+ *
438
+ * ```tsx
439
+ * const flow = createFlowRef<Types, typeof features>();
440
+ * <Flow.Root flowRef={flow} features={features} defaultNodes={nodes}>…</Flow.Root>;
441
+ * flow.current?.engine.run("fit-view");
442
+ * ```
443
+ */
444
+ export declare function createFlowRef<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(): FlowRef<T, F>;
445
+ interface RootState {
446
+ /** the gestures and keys may change the flow (`set-interactive`, `data-interactive`) */
447
+ interactive: boolean;
448
+ /** the viewport is being panned (`data-panning`) */
449
+ panning: boolean;
450
+ /** nodes are being dragged (`drag()`, `data-dragging`) */
451
+ dragging: boolean;
452
+ /** a connection is being drawn (`connection()`, `data-connecting`) */
453
+ connecting: boolean;
454
+ /** a box selection is being drawn (`selection()`, `data-selecting`) */
455
+ selecting: boolean;
456
+ }
457
+ /** The engine's options a root takes as props: each one that changes applies at once. */
458
+ type RootEngineProps = Pick<FlowEngineOptions, "minZoom" | "maxZoom" | "translateExtent" | "panOnDrag" | "panOnScroll" | "zoomOnScroll" | "zoomOnPinch" | "zoomOnDoubleClick" | "zoomStep" | "interactive" | "onlyRenderVisible" | "pathOptions" | "autoPan" | "panActivationKey" | "panOnScrollMode" | "panOnScrollSpeed" | "zoomActivationKey" | "easing" | "nodeOrigin" | "nodeExtent" | "elevateNodesOnSelect" | "elevateEdgesOnSelect" | "paneClickDistance" | "nodeClickDistance" | "preventScrolling" | "nodesFocusable" | "edgesFocusable" | "zIndexMode">;
459
+ type Callbacks = typeof ENGINE_EVENT_CALLBACKS;
460
+ /**
461
+ * The root's event callbacks, one per engine event (`ENGINE_EVENT_CALLBACKS`): `onNodeClick`,
462
+ * `onMoveStart`, `onConnectCancel`, … each called with the event.
463
+ */
464
+ type RootEventProps = { [K in keyof Callbacks as `on${Callbacks[K]}`]?: ((event: FlowEngineEventOf<K>) => void) | undefined; };
465
+ interface RootProps<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> extends DivPrimitiveProps<RootState>, RootEngineProps, RootEventProps {
466
+ /**
467
+ * the flow model. Its middleware (`model.use`) sees every command the flow runs, and its
468
+ * listeners (`model.subscribe`) every change. Give it, or let the root create one from
469
+ * `nodes` / `defaultNodes` and `edges` / `defaultEdges`
470
+ */
471
+ model?: FlowModel<T, F> | undefined;
472
+ /** the nodes of the model the root creates (read once, at mount) */
473
+ defaultNodes?: readonly FlowNodeInput<T>[] | undefined;
474
+ /** the edges of the model the root creates (read once, at mount) */
475
+ defaultEdges?: readonly FlowEdgeInput<T>[] | undefined;
476
+ /**
477
+ * controlled nodes: each render brings the model to them with the commands a user would run
478
+ * (`model.get("commands-to")`, one `batch`); every change of the model's nodes calls
479
+ * `onNodesChange`. Give every node its id
480
+ */
481
+ nodes?: readonly FlowNode<T>[] | undefined;
482
+ /** called with the model's nodes after every command that changes them (a drag step too) */
483
+ onNodesChange?: ((nodes: readonly FlowNode<T>[]) => void) | undefined;
484
+ /** controlled edges, as `nodes` */
485
+ edges?: readonly FlowEdge<T>[] | undefined;
486
+ /** called with the model's edges after every command that changes them */
487
+ onEdgesChange?: ((edges: readonly FlowEdge<T>[]) => void) | undefined;
488
+ /**
489
+ * the opt-in features of the model the root creates (read once, at mount):
490
+ * `[selection(), drag(), connection()]`, each from its entry (`@fragiola/flow-react/drag`). A
491
+ * `model` has its own
492
+ */
493
+ features?: F | undefined;
494
+ /** the id generator of the model the root creates (read once, at mount) */
495
+ createId?: CreateId | undefined;
496
+ /**
497
+ * the fields every `edge.add` of the model the root creates fills in where it leaves them out
498
+ * (read once, at mount: the model option `defaultEdgeOptions`)
499
+ */
500
+ defaultEdgeOptions?: DefaultEdgeOptions<T> | undefined;
501
+ /** controlled viewport: a new value is set on the engine (`set-viewport`) */
502
+ viewport?: Viewport | undefined;
503
+ /** the viewport the flow starts at (read once, at mount); default `{ x: 0, y: 0, zoom: 1 }` */
504
+ defaultViewport?: Viewport | undefined;
505
+ /** called on every viewport change, by a gesture (`gesture: true`) or an action */
506
+ onViewportChange?: ((viewport: Viewport, gesture: boolean) => void) | undefined;
507
+ /** fits the nodes once their sizes are known, again once measured (read once, at mount) */
508
+ fitView?: boolean | FitViewPayload | undefined;
509
+ /** access to the model and the engine from outside the root (`useFlowRef`, `createFlowRef`) */
510
+ flowRef?: FlowRef<T, F> | undefined;
511
+ children?: React.ReactNode;
512
+ }
513
+ /**
514
+ * The flow (`data-flow-part="root"`): owns the model (unless given) and the engine, attaches the
515
+ * engine to its element (the engine listens to it: pointer, wheel, keys, focus) and re-renders
516
+ * when the flow changes. It renders only its children; no Provider is needed above it. Give it a
517
+ * size (the flow fills it).
518
+ */
519
+ declare function Root<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(allProps: RootProps<T, F>): React.JSX.Element;
520
+ interface SelectionBoxState {
521
+ /** the box, in pixels relative to the root */
522
+ readonly box: Rect;
523
+ }
524
+ interface SelectionBoxProps extends DivPrimitiveProps<SelectionBoxState> {
525
+ children?: React.ReactNode;
526
+ }
527
+ /**
528
+ * The box selection being drawn (`data-flow-part="selection-box"`, `selection()`): absolutely
529
+ * positioned in `Flow.Root` (outside `Flow.Viewport`: it is in screen pixels), rendered only
530
+ * while a box is drawn. Give it its look.
531
+ */
532
+ declare function SelectionBox(props: SelectionBoxProps): React.JSX.Element | null;
533
+ interface ToggleInteractiveState {
534
+ /**
535
+ * the flow is not locked: it is interactive and one of dragging, connecting and selecting at
536
+ * least is on (`interactive-by`)
537
+ */
538
+ readonly interactive: boolean;
539
+ }
540
+ interface ToggleInteractiveProps extends ButtonPrimitiveProps<ToggleInteractiveState> {
541
+ children?: React.ReactNode;
542
+ }
543
+ /**
544
+ * A toggle button (`data-flow-part="toggle-interactive"`, `aria-pressed` while the flow is locked,
545
+ * `data-interactive`): locks and unlocks the flow, React Flow's interactive button: locking turns
546
+ * dragging, connecting and selecting off (`set-interactive { drag, connect, select }`), unlocking
547
+ * turns them and `interactive` on; pan and zoom stay. It renders only its children.
548
+ */
549
+ declare function ToggleInteractive(props: ToggleInteractiveProps): React.JSX.Element;
550
+ interface ViewportState {
551
+ /** the viewport: the pan (`x`, `y`, pixels) and the zoom */
552
+ viewport: Viewport;
553
+ }
554
+ interface ViewportProps extends DivPrimitiveProps<ViewportState> {
555
+ children?: React.ReactNode;
556
+ }
557
+ /**
558
+ * The pannable, zoomable layer (`data-flow-part="viewport"`): what is inside is in flow
559
+ * coordinates (`Flow.Edges`, `Flow.Nodes`, `Flow.ConnectionLine`). The engine writes its
560
+ * `transform` itself (D4), never React: a pan or a zoom re-renders nothing inside it.
561
+ */
562
+ declare function Viewport$1(props: ViewportProps): React.JSX.Element;
563
+ interface ZoomInProps extends ButtonPrimitiveProps<ControlButtonState> {
564
+ /** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */
565
+ duration?: number | undefined;
566
+ children?: React.ReactNode;
567
+ }
568
+ /**
569
+ * 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
570
+ * children (an icon, a label).
571
+ */
572
+ declare function ZoomIn(props: ZoomInProps): React.JSX.Element;
573
+ interface ZoomOutProps extends ButtonPrimitiveProps<ControlButtonState> {
574
+ /** how long its viewport change animates, in milliseconds (the root's `easing`); default 0: at once */
575
+ duration?: number | undefined;
576
+ children?: React.ReactNode;
577
+ }
578
+ /**
579
+ * 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
580
+ * children (an icon, a label).
581
+ */
582
+ declare function ZoomOut(props: ZoomOutProps): React.JSX.Element;
583
+ /**
584
+ * The connection being drawn from a handle (`connection()`), or null, re-rendering the component
585
+ * when it changes: where it starts and ends, the handle it would end at and whether the drop
586
+ * would be accepted (`status`).
587
+ */
588
+ export declare function useConnection(): Connection | null;
589
+ /** Every edge of the enclosing `Flow.Root`, in drawing order, re-rendering on every change of one. */
590
+ export declare function useEdges<T extends FlowTypes = AnyTypes>(): readonly FlowEdge<T>[];
591
+ interface UseFlowResult<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> {
592
+ /**
593
+ * the model of the enclosing `Flow.Root`: the flow's document and its rules. Change it with
594
+ * `model.run("node.move", { nodeId, position })`, read it with `model.get` / `model.is`
595
+ */
596
+ model: FlowModel<T, F>;
597
+ /**
598
+ * the engine of the flow on screen: screen actions (`engine.run("fit-view")`), screen facts
599
+ * (`engine.get("viewport")`) and its events (`engine.subscribe`). It is there from the first
600
+ * render; before the root is mounted (and on the server) an action is refused and a read is
601
+ * empty
602
+ */
603
+ engine: FlowEngine<T, F>;
604
+ }
605
+ /**
606
+ * The model and the engine of the enclosing `Flow.Root`. Pass the registry and the features as the
607
+ * type arguments (`useFlow<Types, typeof features>()`): a child cannot infer them through context.
608
+ */
609
+ export declare function useFlow<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(): UseFlowResult<T, F>;
610
+ /**
611
+ * A flow ref kept by this component, which re-renders when the `Flow.Root` it is given to mounts
612
+ * or unmounts: read `flow.current` in render (a toolbar next to the flow) or in handlers.
613
+ *
614
+ * ```tsx
615
+ * const flow = useFlowRef<Types>();
616
+ * <button type="button" onClick={() => flow.current?.engine.run("fit-view")}>Fit</button>
617
+ * <Flow.Root flowRef={flow} defaultNodes={nodes}>…</Flow.Root>
618
+ * ```
619
+ */
620
+ export declare function useFlowRef<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(): FlowRef<T, F>;
621
+ /**
622
+ * A value selected from the model and the engine of the enclosing `Flow.Root`, re-rendering the
623
+ * component only when it changes (`equal`, default `Object.is`): `selector` runs again on every
624
+ * change of the model and every view change of the engine (a measurement, the viewport, a
625
+ * gesture), and on every render. Pass the registry and the features as the type arguments after
626
+ * the selected value's (`useFlowStore<number, Types, typeof features>(…)`). Keep a selector that
627
+ * builds an object or an array with an `equal` that compares it (`sameFlowValue`), or it
628
+ * re-renders on every change.
629
+ */
630
+ export declare function useFlowStore<S, T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []>(selector: (flow: UseFlowResult<T, F>) => S, equal?: (a: S, b: S) => boolean): S;
631
+ /**
632
+ * A node as the engine knows it on screen (`internal-node-by`): the document's node, its absolute
633
+ * position and box (`nodeOrigin` applied), whether its size is known, its z-index and its handles
634
+ * with their centres; undefined while it does not exist or before the root is mounted. It
635
+ * re-renders the component only when one of them changes (compared by value): a pan does not.
636
+ */
637
+ export declare function useInternalNode<T extends FlowTypes = AnyTypes>(nodeId: string): InternalNode<T> | undefined;
638
+ interface UseKeyPressOptions {
639
+ /** where the keys are read: a window, a document or an element; default the root's window */
640
+ target?: KeyPressTarget | null | undefined;
641
+ }
642
+ /**
643
+ * Whether a key, or a combo of keys, is held, re-rendering the component when that changes.
644
+ * `keys` is a combo or several (any of them): key names joined by `+`, held at once (`"Shift"`,
645
+ * `"Meta+s"`, `["Meta+z", "Control+z"]`); a name is a `KeyboardEvent.key` or `.code`, without case
646
+ * (`watchKeyPress`). The keys are read on `target`, by default the window of the enclosing
647
+ * `Flow.Root`'s element (never the global one): false before the root is mounted, or outside a
648
+ * root without a `target`.
649
+ */
650
+ export declare function useKeyPress(keys: KeyPressKeys, options?: UseKeyPressOptions): boolean;
651
+ interface UseNodeConnectionsOptions {
652
+ /** the node; default the enclosing `Flow.Node`'s */
653
+ id?: string | undefined;
654
+ /** only the connections at this handle of it */
655
+ handleId?: string | undefined;
656
+ /** only those that start (`"source"`) or end (`"target"`) at it */
657
+ type?: HandleType | undefined;
658
+ }
659
+ /**
660
+ * The connections at a node (`node-connections-by`): each edge that starts or ends at it, as its
661
+ * `edgeId`, `source`, `sourceHandle`, `target` and `targetHandle`, in the document's order. It
662
+ * re-renders the component only when they change (an edge added, removed or reconnected there),
663
+ * not when a node moves or an edge's data changes.
664
+ */
665
+ export declare function useNodeConnections(options?: UseNodeConnectionsOptions): readonly NodeConnection[];
666
+ /**
667
+ * The id of the node the component renders inside (`Flow.Node`), or null outside one: a custom
668
+ * node's piece reads its own node without being given its id.
669
+ */
670
+ export declare function useNodeId(): string | null;
671
+ /** Every node of the enclosing `Flow.Root`, in drawing order, re-rendering on every change of one. */
672
+ export declare function useNodes<T extends FlowTypes = AnyTypes>(): readonly FlowNode<T>[];
673
+ /**
674
+ * A node's id, type and data (`nodes-data-by`), or null while it does not exist; given several
675
+ * ids, each existing one's in the order given. It re-renders the component only when one of them
676
+ * changes (its type or its data, compared by value), not when a node moves or another changes.
677
+ */
678
+ export declare function useNodesData<T extends FlowTypes = AnyTypes>(nodeId: string): NodeData<T> | null;
679
+ export declare function useNodesData<T extends FlowTypes = AnyTypes>(nodeIds: readonly string[]): readonly NodeData<T>[];
680
+ interface UseOnViewportChangeOptions {
681
+ /** the viewport starts changing (`viewport-change-start`): a pan, a zoom, an animation */
682
+ onStart?: ((viewport: Viewport, gesture: boolean) => void) | undefined;
683
+ /** each change of the viewport (`viewport-change`) */
684
+ onChange?: ((viewport: Viewport, gesture: boolean) => void) | undefined;
685
+ /** the viewport stopped changing (`viewport-change-end`) */
686
+ onEnd?: ((viewport: Viewport, gesture: boolean) => void) | undefined;
687
+ }
688
+ /**
689
+ * Calls back on the viewport's changes of the enclosing `Flow.Root` (the engine's events),
690
+ * without re-rendering the component: `gesture` is true for a pan, the wheel, a pinch or auto-pan,
691
+ * false for an action. The latest callbacks are called.
692
+ */
693
+ export declare function useOnViewportChange(options: UseOnViewportChangeOptions): void;
694
+ /** What is selected. */
695
+ interface FlowSelection<T extends FlowTypes = AnyTypes> {
696
+ readonly nodes: readonly FlowNode<T>[];
697
+ readonly edges: readonly FlowEdge<T>[];
698
+ }
699
+ /**
700
+ * The selected nodes and edges of the enclosing `Flow.Root` (`selection()`; none without it),
701
+ * re-rendering the component when they change: a panel showing the selection, a Delete button.
702
+ */
703
+ export declare function useSelection<T extends FlowTypes = AnyTypes>(): FlowSelection<T>;
704
+ /**
705
+ * The viewport of the enclosing `Flow.Root` (`{ x, y, zoom }`), re-rendering the component when it
706
+ * changes: a zoom level readout, a control's state. Change it with `engine.run("set-viewport")`.
707
+ */
708
+ export declare function useViewport(): Viewport;
709
+ declare namespace parts_d_exports {
710
+ export { Background, ConnectionLine, Controls, Edge, EdgeLabel, EdgePath$1 as EdgePath, EdgeToolbar, Edges, FitView, Handle, Node, NodeToolbar, Nodes, NodesSelection, ReconnectAnchor, Root, SelectionBox, ToggleInteractive, Viewport$1 as Viewport, ZoomIn, ZoomOut };
711
+ }
712
+ export { type BackgroundProps, type BackgroundState, type ButtonPrimitiveProps, type ConnectionLineProps, type ConnectionLineState, type ControlButtonState, type ControlsProps, type ControlsState, type DivPrimitiveProps, type EdgeLabelProps, type EdgeLabelState, type EdgePathProps, type EdgePathState, type EdgeProps, type EdgeState, type EdgeToolbarProps, type EdgeToolbarState, type EdgesProps, type EdgesState, type FitViewProps, parts_d_exports as Flow, type FlowRef, type FlowRefValue, type FlowSelection, type HandleProps, type HandleState, type NodeProps, type NodeState, type NodeToolbarProps, type NodeToolbarState, type NodesProps, type NodesSelectionProps, type NodesSelectionState, type NodesState, type PrimitiveProps, type ReconnectAnchorProps, type ReconnectAnchorState, type RenderProp, type RenderedProps, type RootEngineProps, type RootEventProps, type RootProps, type RootState, type SelectionBoxProps, type SelectionBoxState, type SvgPrimitiveProps, type ToggleInteractiveProps, type ToggleInteractiveState, type UseEdgeResult, type UseFlowResult, type UseHandleOptions, type UseHandleResult, type UseKeyPressOptions, type UseNodeConnectionsOptions, type UseNodeResult, type UseOnViewportChangeOptions, type ViewportProps, type ViewportState, type ZoomInProps, type ZoomOutProps };
713
+ //# sourceMappingURL=index.d.ts.map