@fragiola/flow 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/connect-session-nyEp02_P.js +375 -0
- package/dist/connect-session-nyEp02_P.js.map +1 -0
- package/dist/connection.d.ts +31 -0
- package/dist/connection.js +60 -0
- package/dist/connection.js.map +1 -0
- package/dist/core-queries-BPNbcM6k.js +452 -0
- package/dist/core-queries-BPNbcM6k.js.map +1 -0
- package/dist/document-schema-CPK5xkyO.js +369 -0
- package/dist/document-schema-CPK5xkyO.js.map +1 -0
- package/dist/drag.d.ts +19 -0
- package/dist/drag.js +175 -0
- package/dist/drag.js.map +1 -0
- package/dist/index.d.ts +876 -0
- package/dist/index.js +5711 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard-links-CVaTtlZg.js +8 -0
- package/dist/keyboard-links-CVaTtlZg.js.map +1 -0
- package/dist/keyboard.d.ts +40 -0
- package/dist/keyboard.js +342 -0
- package/dist/keyboard.js.map +1 -0
- package/dist/minimap.d.ts +26 -0
- package/dist/minimap.js +206 -0
- package/dist/minimap.js.map +1 -0
- package/dist/node-moves-DyWe-4dj.js +36 -0
- package/dist/node-moves-DyWe-4dj.js.map +1 -0
- package/dist/part-attributes-DuBltA__.js +71 -0
- package/dist/part-attributes-DuBltA__.js.map +1 -0
- package/dist/path-format-2OU7Eiyy.js +43 -0
- package/dist/path-format-2OU7Eiyy.js.map +1 -0
- package/dist/reconnection.d.ts +15 -0
- package/dist/reconnection.js +138 -0
- package/dist/reconnection.js.map +1 -0
- package/dist/rect-CmoREaR6.js +92 -0
- package/dist/rect-CmoREaR6.js.map +1 -0
- package/dist/resize.d.ts +33 -0
- package/dist/resize.js +316 -0
- package/dist/resize.js.map +1 -0
- package/dist/rules-DLOMrPBG.js +102 -0
- package/dist/rules-DLOMrPBG.js.map +1 -0
- package/dist/selection.d.ts +38 -0
- package/dist/selection.js +392 -0
- package/dist/selection.js.map +1 -0
- package/dist/subflows.d.ts +9 -0
- package/dist/subflows.js +237 -0
- package/dist/subflows.js.map +1 -0
- package/dist/types-CLHcZVCb.d.ts +2660 -0
- package/dist/viewport-math-B-9Pn2kN.js +69 -0
- package/dist/viewport-math-B-9Pn2kN.js.map +1 -0
- package/package.json +94 -3
|
@@ -0,0 +1,2660 @@
|
|
|
1
|
+
/** An axis-aligned rectangle: its top-left corner and its size. */
|
|
2
|
+
interface Rect {
|
|
3
|
+
readonly x: number;
|
|
4
|
+
readonly y: number;
|
|
5
|
+
readonly width: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
}
|
|
8
|
+
/** The side of a node a handle sits on, and the direction an edge leaves it in (physical, D8). */
|
|
9
|
+
type HandleSide = "top" | "right" | "bottom" | "left";
|
|
10
|
+
/**
|
|
11
|
+
* What the flow shows (D4, view state): the screen offset of the flow's origin from the root's
|
|
12
|
+
* top-left corner, in pixels, and the scale. A flow point `p` is drawn at `p * zoom + (x, y)`.
|
|
13
|
+
*/
|
|
14
|
+
interface Viewport {
|
|
15
|
+
readonly x: number;
|
|
16
|
+
readonly y: number;
|
|
17
|
+
readonly zoom: number;
|
|
18
|
+
}
|
|
19
|
+
/** Where an edge starts and ends, and the side it leaves and enters by. */
|
|
20
|
+
interface PathEnds {
|
|
21
|
+
/** where it starts, in flow coordinates */
|
|
22
|
+
readonly source: XY;
|
|
23
|
+
/** the side of the source node it leaves by */
|
|
24
|
+
readonly sourceSide: HandleSide;
|
|
25
|
+
/** where it ends, in flow coordinates */
|
|
26
|
+
readonly target: XY;
|
|
27
|
+
/** the side of the target node it enters by */
|
|
28
|
+
readonly targetSide: HandleSide;
|
|
29
|
+
}
|
|
30
|
+
/** An SVG path and the point its label goes at (halfway along it). */
|
|
31
|
+
interface PathResult {
|
|
32
|
+
/** the SVG path data (`d`) */
|
|
33
|
+
readonly path: string;
|
|
34
|
+
/** where a label goes: halfway along the path, in flow coordinates */
|
|
35
|
+
readonly label: XY;
|
|
36
|
+
}
|
|
37
|
+
/** An edge as the engine draws it (`engine.get("edge-path-by", { edgeId })`). */
|
|
38
|
+
interface EdgePath extends PathResult, PathEnds {}
|
|
39
|
+
/** A point or an offset in flow coordinates: x grows to the right, y grows down. */
|
|
40
|
+
interface XY {
|
|
41
|
+
readonly x: number;
|
|
42
|
+
readonly y: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The app's registry of node and edge types and their data:
|
|
46
|
+
* `{ nodes: { task: { title: string } }; edges: { dependency: { weight: number } } }`.
|
|
47
|
+
*/
|
|
48
|
+
interface FlowTypes {
|
|
49
|
+
/** each node type and the shape of its `data` */
|
|
50
|
+
readonly nodes?: object;
|
|
51
|
+
/** each app edge type and the shape of its `data` (the built-in types may be given too) */
|
|
52
|
+
readonly edges?: object;
|
|
53
|
+
}
|
|
54
|
+
/** A registry that types nothing: any node type, any edge type, any JSON object as data. */
|
|
55
|
+
interface AnyTypes extends FlowTypes {
|
|
56
|
+
readonly nodes: {
|
|
57
|
+
readonly [type: string]: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
readonly edges: {
|
|
60
|
+
readonly [type: string]: Record<string, unknown>;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** The edge types the core draws (its own path math): any other type is the app's. */
|
|
64
|
+
type BuiltInEdgeType = "bezier" | "simplebezier" | "smoothstep" | "step" | "straight";
|
|
65
|
+
/** The node types of a registry. */
|
|
66
|
+
type NodeTypeOf<T extends FlowTypes> = T extends {
|
|
67
|
+
readonly nodes: infer N extends object;
|
|
68
|
+
} ? keyof N & string : string;
|
|
69
|
+
/** The data of a node type. */
|
|
70
|
+
type NodeDataOf<T extends FlowTypes, K extends string> = T extends {
|
|
71
|
+
readonly nodes: infer N extends object;
|
|
72
|
+
} ? K extends keyof N ? N[K] : Record<string, unknown> : Record<string, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* The edge types of a registry: the built-in ones and the app's. An `any` registry (what Angular's
|
|
75
|
+
* template type-check gives a generic directive) takes every type, as `AnyTypes` does.
|
|
76
|
+
*/
|
|
77
|
+
type EdgeTypeOf<T extends FlowTypes> = 0 extends 1 & T ? string : BuiltInEdgeType | (T extends {
|
|
78
|
+
readonly edges: infer E extends object;
|
|
79
|
+
} ? keyof E & string : never);
|
|
80
|
+
/** The data of an edge type (a built-in type the registry does not name: any JSON object). */
|
|
81
|
+
type EdgeDataOf<T extends FlowTypes, K extends string> = T extends {
|
|
82
|
+
readonly edges: infer E extends object;
|
|
83
|
+
} ? K extends keyof E ? E[K] : Record<string, unknown> : Record<string, unknown>;
|
|
84
|
+
/** A node's permission flags; an absent flag is its default (`hidden` false, the others true). */
|
|
85
|
+
interface NodeFlags {
|
|
86
|
+
/** it may be moved (`node.move`); default true */
|
|
87
|
+
readonly draggable?: boolean;
|
|
88
|
+
/** it may be selected (`selection.set`); default true */
|
|
89
|
+
readonly selectable?: boolean;
|
|
90
|
+
/** edges may start or end at it (`edge.add`, `edge.reconnect`); default true */
|
|
91
|
+
readonly connectable?: boolean;
|
|
92
|
+
/** it may be removed (`node.remove`, `selection.remove`); default true */
|
|
93
|
+
readonly deletable?: boolean;
|
|
94
|
+
/** it is not shown; default false */
|
|
95
|
+
readonly hidden?: boolean;
|
|
96
|
+
/** it takes DOM focus (with `keyboard()`); default true */
|
|
97
|
+
readonly focusable?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* An edge's permission and display flags; an absent flag is its default (`hidden` and `animated`
|
|
101
|
+
* false, the others true).
|
|
102
|
+
*/
|
|
103
|
+
interface EdgeFlags {
|
|
104
|
+
/** it may be selected (`selection.set`); default true */
|
|
105
|
+
readonly selectable?: boolean;
|
|
106
|
+
/** it may be removed (`edge.remove`, `selection.remove`); default true */
|
|
107
|
+
readonly deletable?: boolean;
|
|
108
|
+
/** it is not shown; default false */
|
|
109
|
+
readonly hidden?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* its ends may be moved to other nodes or handles (`edge.reconnect`): both (`true`), none
|
|
112
|
+
* (`false`), or only its `"source"` or its `"target"` end; default true
|
|
113
|
+
*/
|
|
114
|
+
readonly reconnectable?: boolean | "source" | "target";
|
|
115
|
+
/** it takes DOM focus (with `keyboard()`); default true */
|
|
116
|
+
readonly focusable?: boolean;
|
|
117
|
+
/** it is drawn animated (`data-animated` on its parts: the app's CSS animates it); default false */
|
|
118
|
+
readonly animated?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/** The fields the `selection()` feature owns on a node and on an edge. */
|
|
121
|
+
interface SelectionFields {
|
|
122
|
+
/** it is selected (`@fragiola/flow/selection`) */
|
|
123
|
+
readonly selected?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/** The fields the `subflows()` feature owns on a node. */
|
|
126
|
+
interface SubflowFields {
|
|
127
|
+
/** the node it lives in (`@fragiola/flow/subflows`): its `position` is relative to it */
|
|
128
|
+
readonly parentId?: string;
|
|
129
|
+
/**
|
|
130
|
+
* where it stays (`@fragiola/flow/subflows`): `"parent"`, inside its parent's box; a `Rect`,
|
|
131
|
+
* inside that rectangle, in the coordinates of its `position` (relative to its parent for a
|
|
132
|
+
* child)
|
|
133
|
+
*/
|
|
134
|
+
readonly extent?: "parent" | Rect;
|
|
135
|
+
/** its parent grows to keep it inside when it moves or grows past it (`@fragiola/flow/subflows`) */
|
|
136
|
+
readonly expandParent?: boolean;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A handle a node declares in the document, for its edges to be drawn before it is rendered and
|
|
140
|
+
* measured (a server render): used only until a handle of that node, type and id is measured.
|
|
141
|
+
*/
|
|
142
|
+
interface DeclaredHandle {
|
|
143
|
+
/** its id among the node's handles of its type (none: the node's default handle) */
|
|
144
|
+
readonly id?: string;
|
|
145
|
+
/** whether edges start (`source`) or end (`target`) at it */
|
|
146
|
+
readonly type: "source" | "target";
|
|
147
|
+
/** the side of the node it sits on: the direction an edge leaves or enters by */
|
|
148
|
+
readonly position: HandleSide;
|
|
149
|
+
/** its box's left edge, relative to the node box's left edge, in flow units */
|
|
150
|
+
readonly x: number;
|
|
151
|
+
/** its box's top edge, relative to the node box's top edge, in flow units */
|
|
152
|
+
readonly y: number;
|
|
153
|
+
/** its box's width; default 0 (an edge's end is the box's centre) */
|
|
154
|
+
readonly width?: number;
|
|
155
|
+
/** its box's height; default 0 */
|
|
156
|
+
readonly height?: number;
|
|
157
|
+
}
|
|
158
|
+
/** What every node has, whatever its type. */
|
|
159
|
+
interface NodeFields extends NodeFlags, SelectionFields, SubflowFields {
|
|
160
|
+
/** its top-left corner, in flow coordinates (relative to its parent with sub-flows) */
|
|
161
|
+
readonly position: XY;
|
|
162
|
+
/** its width, when the document gives one (the engine measures the rendered one) */
|
|
163
|
+
readonly width?: number;
|
|
164
|
+
/** its height, when the document gives one (the engine measures the rendered one) */
|
|
165
|
+
readonly height?: number;
|
|
166
|
+
/** its width until it is measured (a server render, `fit-view` on init); `width` wins */
|
|
167
|
+
readonly initialWidth?: number;
|
|
168
|
+
/** its height until it is measured (a server render, `fit-view` on init); `height` wins */
|
|
169
|
+
readonly initialHeight?: number;
|
|
170
|
+
/**
|
|
171
|
+
* its handles, declared for its edges to be drawn before it is measured; a measured handle of
|
|
172
|
+
* the same type and id always wins
|
|
173
|
+
*/
|
|
174
|
+
readonly handles?: DeclaredHandle[];
|
|
175
|
+
/** the side its edges leave by when no handle gives one; default `"bottom"` */
|
|
176
|
+
readonly sourcePosition?: HandleSide;
|
|
177
|
+
/** the side its edges enter by when no handle gives one; default `"top"` */
|
|
178
|
+
readonly targetPosition?: HandleSide;
|
|
179
|
+
/**
|
|
180
|
+
* the point of its box its `position` stands at, as shares of its size, over the engine's
|
|
181
|
+
* `nodeOrigin` (a child's position stays its box's top-left corner)
|
|
182
|
+
*/
|
|
183
|
+
readonly origin?: XY;
|
|
184
|
+
/** its place in the nodes' stacking order (an integer): a greater one is drawn above; default 0 */
|
|
185
|
+
readonly zIndex?: number;
|
|
186
|
+
}
|
|
187
|
+
/** A node of type `K` and data `D`. */
|
|
188
|
+
interface NodeOf<K extends string, D> extends NodeFields {
|
|
189
|
+
readonly id: string;
|
|
190
|
+
readonly type: K;
|
|
191
|
+
readonly data: D;
|
|
192
|
+
}
|
|
193
|
+
/** A node of the registry `T`: a union over its node types, so `type` narrows `data`. */
|
|
194
|
+
type FlowNode<T extends FlowTypes = AnyTypes> = { [K in NodeTypeOf<T>]: NodeOf<K, NodeDataOf<T, K>>; }[NodeTypeOf<T>];
|
|
195
|
+
/**
|
|
196
|
+
* The shape of one edge's path, over the engine's `pathOptions`: each built-in type reads its own
|
|
197
|
+
* (bezier `curvature`; smooth step `borderRadius`, `offset`, `stepPosition`, `centerX`,
|
|
198
|
+
* `centerY`; step the same but `borderRadius`), the others are ignored.
|
|
199
|
+
*/
|
|
200
|
+
interface EdgePathOptions {
|
|
201
|
+
/** bezier: the share of the distance a control point stands out by */
|
|
202
|
+
readonly curvature?: number;
|
|
203
|
+
/** smooth step: the corners' radius, in flow units */
|
|
204
|
+
readonly borderRadius?: number;
|
|
205
|
+
/** smooth step and step: how far an end stands out before turning, in flow units */
|
|
206
|
+
readonly offset?: number;
|
|
207
|
+
/** smooth step and step: where the turn sits between the source (0) and the target (1) */
|
|
208
|
+
readonly stepPosition?: number;
|
|
209
|
+
/** smooth step and step: the x of a vertical turn, in flow coordinates */
|
|
210
|
+
readonly centerX?: number;
|
|
211
|
+
/** smooth step and step: the y of a horizontal turn, in flow coordinates */
|
|
212
|
+
readonly centerY?: number;
|
|
213
|
+
}
|
|
214
|
+
/** What every edge has, whatever its type. */
|
|
215
|
+
interface EdgeFields extends EdgeFlags, SelectionFields {
|
|
216
|
+
/** the node it starts at */
|
|
217
|
+
readonly source: string;
|
|
218
|
+
/** the node it ends at */
|
|
219
|
+
readonly target: string;
|
|
220
|
+
/** the source node's handle it starts at (none: the node's only, or default, source handle) */
|
|
221
|
+
readonly sourceHandle?: string;
|
|
222
|
+
/** the target node's handle it ends at (none: the node's only, or default, target handle) */
|
|
223
|
+
readonly targetHandle?: string;
|
|
224
|
+
/** its place in the edges' drawing order (an integer): a greater one is drawn above; default 0 */
|
|
225
|
+
readonly zIndex?: number;
|
|
226
|
+
/** the shape of its path, over the engine's `pathOptions` (its type's keys) */
|
|
227
|
+
readonly pathOptions?: EdgePathOptions;
|
|
228
|
+
}
|
|
229
|
+
/** An edge of type `K` and data `D`. */
|
|
230
|
+
interface EdgeOf<K extends string, D> extends EdgeFields {
|
|
231
|
+
readonly id: string;
|
|
232
|
+
/** how it is drawn: a built-in path or the app's type; none is `"bezier"` */
|
|
233
|
+
readonly type?: K;
|
|
234
|
+
readonly data?: D;
|
|
235
|
+
}
|
|
236
|
+
/** An edge of the registry `T`: a union over its edge types, so `type` narrows `data`. */
|
|
237
|
+
type FlowEdge<T extends FlowTypes = AnyTypes> = { [K in EdgeTypeOf<T>]: EdgeOf<K, EdgeDataOf<T, K>>; }[EdgeTypeOf<T>];
|
|
238
|
+
/** The document as the model holds it: frozen, every id present. */
|
|
239
|
+
interface FlowDocument<T extends FlowTypes = AnyTypes> {
|
|
240
|
+
readonly version: 1;
|
|
241
|
+
readonly nodes: readonly FlowNode<T>[];
|
|
242
|
+
readonly edges: readonly FlowEdge<T>[];
|
|
243
|
+
}
|
|
244
|
+
/** A node as a document or `node.add` gives it: its `id` may be left out (one is generated). */
|
|
245
|
+
type FlowNodeInput<T extends FlowTypes = AnyTypes> = { [K in NodeTypeOf<T>]: Omit<NodeOf<K, NodeDataOf<T, K>>, "id"> & {
|
|
246
|
+
/** its id; generated (`createId`) when missing */
|
|
247
|
+
readonly id?: string;
|
|
248
|
+
}; }[NodeTypeOf<T>];
|
|
249
|
+
/** An edge as a document or `edge.add` gives it: its `id` may be left out (one is generated). */
|
|
250
|
+
type FlowEdgeInput<T extends FlowTypes = AnyTypes> = { [K in EdgeTypeOf<T>]: Omit<EdgeOf<K, EdgeDataOf<T, K>>, "id"> & {
|
|
251
|
+
/** its id; generated (`createId`) when missing */
|
|
252
|
+
readonly id?: string;
|
|
253
|
+
}; }[EdgeTypeOf<T>];
|
|
254
|
+
/** A flow document as JSON, as `createFlowModel` and `validateFlow` take it (version 1). */
|
|
255
|
+
interface FlowJson<T extends FlowTypes = AnyTypes> {
|
|
256
|
+
version: 1;
|
|
257
|
+
nodes: FlowNodeInput<T>[];
|
|
258
|
+
edges: FlowEdgeInput<T>[];
|
|
259
|
+
}
|
|
260
|
+
/** A writable copy of the document, every id present: what `get("flow-json")` returns. */
|
|
261
|
+
interface FlowDocumentJson<T extends FlowTypes = AnyTypes> {
|
|
262
|
+
version: 1;
|
|
263
|
+
nodes: FlowNode<T>[];
|
|
264
|
+
edges: FlowEdge<T>[];
|
|
265
|
+
}
|
|
266
|
+
/** The attribute naming an element's part. */
|
|
267
|
+
declare const PART_ATTRIBUTE = "data-flow-part";
|
|
268
|
+
/** The attribute holding the id of the entity a part stands for. */
|
|
269
|
+
declare const ID_ATTRIBUTE = "data-flow-id";
|
|
270
|
+
/** The attribute a resize handle carries: which corner or side of its node it moves. */
|
|
271
|
+
declare const POSITION_ATTRIBUTE = "data-position";
|
|
272
|
+
/**
|
|
273
|
+
* The attribute a resize handle given its own direction carries (`horizontal`, `vertical`): the
|
|
274
|
+
* sides it moves, over its resizer's `direction`, read when a press or a key on it starts.
|
|
275
|
+
*/
|
|
276
|
+
declare const DIRECTION_ATTRIBUTE = "data-direction";
|
|
277
|
+
/** The attribute a resize handle carries: how it is drawn (`handle`, `line`), for the app's styles. */
|
|
278
|
+
declare const VARIANT_ATTRIBUTE = "data-variant";
|
|
279
|
+
/** The attribute a reconnect anchor carries: which end of its edge it moves (`source`, `target`). */
|
|
280
|
+
declare const END_ATTRIBUTE = "data-end";
|
|
281
|
+
/** The attribute an edges layer carries: its render level (`render-layers`), 0 the lowest. */
|
|
282
|
+
declare const LEVEL_ATTRIBUTE = "data-level";
|
|
283
|
+
/** A subtree inside a node that starts no gesture when pressed (a slider, a text field). */
|
|
284
|
+
declare const NO_GESTURE_ATTRIBUTE = "data-flow-no-gesture";
|
|
285
|
+
/**
|
|
286
|
+
* An element inside a node that is its drag handle: a node holding one is dragged only from it (a
|
|
287
|
+
* press elsewhere on it still selects it).
|
|
288
|
+
*/
|
|
289
|
+
declare const DRAG_HANDLE_ATTRIBUTE = "data-flow-drag-handle";
|
|
290
|
+
/** A subtree inside the flow where the wheel scrolls its content instead of zooming the flow. */
|
|
291
|
+
declare const NO_WHEEL_ATTRIBUTE = "data-flow-no-wheel";
|
|
292
|
+
/** The parts of the flow's primitives (an adapter may use others: `toolbar`, `panel`, …). */
|
|
293
|
+
type FlowPart = "root" | "viewport" | "nodes" | "node" | "edges" | "edges-layer" | "edge" | "edge-path" | "edge-label" | "reconnect-anchor" | "handle" | "connection-line" | "selection-box" | "nodes-selection" | "background" | "controls" | "minimap" | "minimap-node" | "minimap-mask" | "resizer" | "resize-handle" | "toolbar" | "panel";
|
|
294
|
+
/** A part's attributes: names to values, `undefined` for an attribute the element does not have. */
|
|
295
|
+
type PartAttributes = Readonly<Record<string, string | undefined>>;
|
|
296
|
+
/** A writable attribute record, as the engine and its features fill it. */
|
|
297
|
+
type MutablePartAttributes = Record<string, string | undefined>;
|
|
298
|
+
/** A boolean state attribute's value: present (`""`) or absent. */
|
|
299
|
+
declare function flag(on: boolean): string | undefined;
|
|
300
|
+
/** The static attributes of a part: its name and, for an entity, its id. */
|
|
301
|
+
declare function partAttributes(part: string, id?: string): PartAttributes;
|
|
302
|
+
/**
|
|
303
|
+
* The attributes of one render level's edges layer (`edges-layer`, with several levels): its part
|
|
304
|
+
* and its `data-level`. Static: the same with or without an engine.
|
|
305
|
+
*/
|
|
306
|
+
declare function edgesLayerAttributes(level: number): PartAttributes;
|
|
307
|
+
/** The sides a resize handle moves, over its resizer's direction. */
|
|
308
|
+
type ResizeHandleDirection = "horizontal" | "vertical";
|
|
309
|
+
/**
|
|
310
|
+
* How a resize handle is drawn: `handle` (a grab area on its corner or side) or `line` (a side's
|
|
311
|
+
* whole length, a marker the app styles thin); a corner is always a `handle`.
|
|
312
|
+
*/
|
|
313
|
+
type ResizeHandleVariant = "handle" | "line";
|
|
314
|
+
/** What a resize handle's attributes are made of (`resizeHandleAttributes`). */
|
|
315
|
+
interface ResizeHandleAttributeOptions {
|
|
316
|
+
/** the sides it moves, over its resizer's; anything else: the resizer's */
|
|
317
|
+
readonly direction?: string | undefined;
|
|
318
|
+
/** how it is drawn; default `handle`, and a corner's `line` is ignored */
|
|
319
|
+
readonly variant?: string | undefined;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The static attributes of a resize handle (the engine's record adds its state): its part,
|
|
323
|
+
* `data-position`, `data-variant` (`line` only on a side, else `handle`) and `data-direction` when
|
|
324
|
+
* it has a valid one of its own.
|
|
325
|
+
*/
|
|
326
|
+
declare function resizeHandleAttributes(position: string | undefined, options?: ResizeHandleAttributeOptions): PartAttributes;
|
|
327
|
+
/** Every feature's keys and fields. */
|
|
328
|
+
declare const FEATURE_KEYS: Readonly<{
|
|
329
|
+
readonly selection: {
|
|
330
|
+
readonly commands: readonly ["selection.set", "selection.clear", "selection.remove"];
|
|
331
|
+
readonly get: readonly ["selected-nodes", "selected-edges"];
|
|
332
|
+
readonly is: readonly ["node-selected", "edge-selected"];
|
|
333
|
+
readonly engineRun: readonly [];
|
|
334
|
+
readonly engineGet: readonly ["selection-box", "selection-rect"];
|
|
335
|
+
readonly engineIs: readonly ["box-selecting"];
|
|
336
|
+
readonly nodeFields: readonly ["selected"];
|
|
337
|
+
readonly edgeFields: readonly ["selected"];
|
|
338
|
+
};
|
|
339
|
+
readonly subflows: {
|
|
340
|
+
readonly commands: readonly ["node.set-parent"];
|
|
341
|
+
readonly get: readonly ["node-children-by", "node-parent-by"];
|
|
342
|
+
readonly is: readonly [];
|
|
343
|
+
readonly engineRun: readonly [];
|
|
344
|
+
readonly engineGet: readonly [];
|
|
345
|
+
readonly engineIs: readonly [];
|
|
346
|
+
readonly nodeFields: readonly ["parentId", "extent", "expandParent"];
|
|
347
|
+
readonly edgeFields: readonly [];
|
|
348
|
+
};
|
|
349
|
+
readonly drag: {
|
|
350
|
+
readonly commands: readonly [];
|
|
351
|
+
readonly get: readonly [];
|
|
352
|
+
readonly is: readonly [];
|
|
353
|
+
readonly engineRun: readonly [];
|
|
354
|
+
readonly engineGet: readonly ["dragging-node-ids"];
|
|
355
|
+
readonly engineIs: readonly ["node-dragging", "dragging"];
|
|
356
|
+
readonly nodeFields: readonly [];
|
|
357
|
+
readonly edgeFields: readonly [];
|
|
358
|
+
};
|
|
359
|
+
readonly resize: {
|
|
360
|
+
readonly commands: readonly [];
|
|
361
|
+
readonly get: readonly [];
|
|
362
|
+
readonly is: readonly [];
|
|
363
|
+
readonly engineRun: readonly [];
|
|
364
|
+
readonly engineGet: readonly [];
|
|
365
|
+
readonly engineIs: readonly ["node-resizing", "resizing"];
|
|
366
|
+
readonly nodeFields: readonly [];
|
|
367
|
+
readonly edgeFields: readonly [];
|
|
368
|
+
};
|
|
369
|
+
readonly connection: {
|
|
370
|
+
readonly commands: readonly [];
|
|
371
|
+
readonly get: readonly [];
|
|
372
|
+
readonly is: readonly [];
|
|
373
|
+
readonly engineRun: readonly [];
|
|
374
|
+
readonly engineGet: readonly ["connection"];
|
|
375
|
+
readonly engineIs: readonly ["connecting"];
|
|
376
|
+
readonly nodeFields: readonly [];
|
|
377
|
+
readonly edgeFields: readonly [];
|
|
378
|
+
};
|
|
379
|
+
readonly reconnection: {
|
|
380
|
+
readonly commands: readonly ["edge.reconnect"];
|
|
381
|
+
readonly get: readonly [];
|
|
382
|
+
readonly is: readonly [];
|
|
383
|
+
readonly engineRun: readonly [];
|
|
384
|
+
readonly engineGet: readonly [];
|
|
385
|
+
readonly engineIs: readonly ["edge-reconnecting"];
|
|
386
|
+
readonly nodeFields: readonly [];
|
|
387
|
+
readonly edgeFields: readonly [];
|
|
388
|
+
};
|
|
389
|
+
readonly keyboard: {
|
|
390
|
+
readonly commands: readonly [];
|
|
391
|
+
readonly get: readonly [];
|
|
392
|
+
readonly is: readonly [];
|
|
393
|
+
readonly engineRun: readonly [];
|
|
394
|
+
readonly engineGet: readonly [];
|
|
395
|
+
readonly engineIs: readonly ["node-focusable", "edge-focusable"];
|
|
396
|
+
readonly nodeFields: readonly [];
|
|
397
|
+
readonly edgeFields: readonly [];
|
|
398
|
+
};
|
|
399
|
+
readonly minimap: {
|
|
400
|
+
readonly commands: readonly [];
|
|
401
|
+
readonly get: readonly [];
|
|
402
|
+
readonly is: readonly [];
|
|
403
|
+
readonly engineRun: readonly [];
|
|
404
|
+
readonly engineGet: readonly ["minimap-view", "minimap-point-to-flow"];
|
|
405
|
+
readonly engineIs: readonly [];
|
|
406
|
+
readonly nodeFields: readonly [];
|
|
407
|
+
readonly edgeFields: readonly [];
|
|
408
|
+
};
|
|
409
|
+
}>;
|
|
410
|
+
/** The name of an opt-in feature (`@fragiola/flow/<name>`). */
|
|
411
|
+
type FeatureName = keyof typeof FEATURE_KEYS;
|
|
412
|
+
/** The kinds of names a feature owns. */
|
|
413
|
+
type FeatureKeyKind = keyof (typeof FEATURE_KEYS)[FeatureName];
|
|
414
|
+
/** The names of kind `K` the features `N` own. */
|
|
415
|
+
type OwnedBy<K extends FeatureKeyKind, N extends FeatureName = FeatureName> = N extends FeatureName ? (typeof FEATURE_KEYS)[N][K][number] : never;
|
|
416
|
+
/** A JSON value. */
|
|
417
|
+
type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
|
|
418
|
+
readonly [key: string]: JsonValue;
|
|
419
|
+
};
|
|
420
|
+
/** The JSON Schema types the validator knows. */
|
|
421
|
+
type JsonSchemaType = "object" | "array" | "string" | "number" | "integer" | "boolean" | "null";
|
|
422
|
+
/**
|
|
423
|
+
* The subset of JSON Schema (2020-12) that the flow schemas use and its validator checks. Other
|
|
424
|
+
* keywords may be present (a consumer's data schema can carry them); they are ignored.
|
|
425
|
+
*/
|
|
426
|
+
interface JsonSchema {
|
|
427
|
+
readonly $ref?: string;
|
|
428
|
+
readonly $defs?: {
|
|
429
|
+
readonly [name: string]: JsonSchema;
|
|
430
|
+
};
|
|
431
|
+
readonly title?: string;
|
|
432
|
+
readonly description?: string;
|
|
433
|
+
readonly type?: JsonSchemaType;
|
|
434
|
+
readonly properties?: {
|
|
435
|
+
readonly [name: string]: JsonSchema;
|
|
436
|
+
};
|
|
437
|
+
readonly required?: readonly string[];
|
|
438
|
+
readonly additionalProperties?: boolean;
|
|
439
|
+
readonly enum?: readonly JsonValue[];
|
|
440
|
+
readonly const?: JsonValue;
|
|
441
|
+
readonly items?: JsonSchema;
|
|
442
|
+
readonly oneOf?: readonly JsonSchema[];
|
|
443
|
+
readonly anyOf?: readonly JsonSchema[];
|
|
444
|
+
readonly minimum?: number;
|
|
445
|
+
readonly exclusiveMinimum?: number;
|
|
446
|
+
readonly minLength?: number;
|
|
447
|
+
readonly minItems?: number;
|
|
448
|
+
}
|
|
449
|
+
/** A problem found in a document: where (a JSON pointer, RFC 6901) and what. */
|
|
450
|
+
interface ValidationIssue {
|
|
451
|
+
readonly path: string;
|
|
452
|
+
readonly message: string;
|
|
453
|
+
}
|
|
454
|
+
/** A shallow patch of data `D`: some of its top-level keys (any keys when `D` is not typed). */
|
|
455
|
+
type PatchOf<D> = unknown extends D ? Record<string, unknown> : D extends object ? Partial<D> : never;
|
|
456
|
+
/** A shallow patch of a node's data in the registry `T`: some top-level keys of one type's data. */
|
|
457
|
+
type NodeDataPatchOf<T extends FlowTypes> = { [K in NodeTypeOf<T>]: PatchOf<NodeDataOf<T, K>>; }[NodeTypeOf<T>];
|
|
458
|
+
/** A shallow patch of an edge's data in the registry `T`: some top-level keys of one type's data. */
|
|
459
|
+
type EdgeDataPatchOf<T extends FlowTypes> = { [K in EdgeTypeOf<T>]: PatchOf<EdgeDataOf<T, K>>; }[EdgeTypeOf<T>];
|
|
460
|
+
/** The flags `node.set-flags` sets: each one given is written, the others stay. */
|
|
461
|
+
interface NodeFlagsPayload {
|
|
462
|
+
nodeId: string;
|
|
463
|
+
draggable?: boolean;
|
|
464
|
+
selectable?: boolean;
|
|
465
|
+
connectable?: boolean;
|
|
466
|
+
deletable?: boolean;
|
|
467
|
+
hidden?: boolean;
|
|
468
|
+
focusable?: boolean;
|
|
469
|
+
}
|
|
470
|
+
/** The flags `edge.set-flags` sets: each one given is written, the others stay. */
|
|
471
|
+
interface EdgeFlagsPayload {
|
|
472
|
+
edgeId: string;
|
|
473
|
+
selectable?: boolean;
|
|
474
|
+
deletable?: boolean;
|
|
475
|
+
hidden?: boolean;
|
|
476
|
+
reconnectable?: boolean | "source" | "target";
|
|
477
|
+
focusable?: boolean;
|
|
478
|
+
animated?: boolean;
|
|
479
|
+
}
|
|
480
|
+
/** Where an edge goes: its nodes and, optionally, their handles. */
|
|
481
|
+
interface ConnectionPayload {
|
|
482
|
+
source: string;
|
|
483
|
+
target: string;
|
|
484
|
+
sourceHandle?: string;
|
|
485
|
+
targetHandle?: string;
|
|
486
|
+
}
|
|
487
|
+
/** How `selection.set` combines its ids with the selection: replace it (default), add, toggle. */
|
|
488
|
+
type SelectionMode = "replace" | "add" | "toggle";
|
|
489
|
+
/** What a removal took away: the nodes, and every edge that touched them or was removed itself. */
|
|
490
|
+
interface RemovedResult {
|
|
491
|
+
removedNodeIds: string[];
|
|
492
|
+
removedEdgeIds: string[];
|
|
493
|
+
}
|
|
494
|
+
/** The ids selected (or deselected) by a selection command. */
|
|
495
|
+
interface SelectionResult {
|
|
496
|
+
nodeIds: string[];
|
|
497
|
+
edgeIds: string[];
|
|
498
|
+
}
|
|
499
|
+
/** One command of a batch. */
|
|
500
|
+
type BatchEntry<T extends FlowTypes = AnyTypes> = { [C in CommandName]: {
|
|
501
|
+
command: C;
|
|
502
|
+
payload: PayloadOf<T, C>;
|
|
503
|
+
}; }[CommandName];
|
|
504
|
+
/** Every command, the core's and the features': its payload and its result, typed by `T`. */
|
|
505
|
+
interface CommandMap<T extends FlowTypes = AnyTypes> {
|
|
506
|
+
"node.add": {
|
|
507
|
+
payload: FlowNodeInput<T>;
|
|
508
|
+
result: {
|
|
509
|
+
nodeId: string;
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
"node.remove": {
|
|
513
|
+
payload: {
|
|
514
|
+
nodeId: string;
|
|
515
|
+
};
|
|
516
|
+
result: RemovedResult;
|
|
517
|
+
};
|
|
518
|
+
"node.move": {
|
|
519
|
+
payload: {
|
|
520
|
+
nodeId: string;
|
|
521
|
+
position: XY;
|
|
522
|
+
};
|
|
523
|
+
result: {
|
|
524
|
+
nodeId: string;
|
|
525
|
+
position: XY;
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
"node.resize": {
|
|
529
|
+
payload: {
|
|
530
|
+
nodeId: string;
|
|
531
|
+
width: number;
|
|
532
|
+
height: number;
|
|
533
|
+
position?: XY;
|
|
534
|
+
};
|
|
535
|
+
result: {
|
|
536
|
+
nodeId: string;
|
|
537
|
+
width: number;
|
|
538
|
+
height: number;
|
|
539
|
+
position: XY;
|
|
540
|
+
};
|
|
541
|
+
};
|
|
542
|
+
"node.set-data": {
|
|
543
|
+
payload: {
|
|
544
|
+
nodeId: string;
|
|
545
|
+
data: NodeDataPatchOf<T>;
|
|
546
|
+
};
|
|
547
|
+
result: {
|
|
548
|
+
nodeId: string;
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
"node.set-flags": {
|
|
552
|
+
payload: NodeFlagsPayload;
|
|
553
|
+
result: {
|
|
554
|
+
nodeId: string;
|
|
555
|
+
};
|
|
556
|
+
};
|
|
557
|
+
"node.set-z-index": {
|
|
558
|
+
payload: {
|
|
559
|
+
nodeId: string;
|
|
560
|
+
zIndex: number | null;
|
|
561
|
+
};
|
|
562
|
+
result: {
|
|
563
|
+
nodeId: string;
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
"node.set-parent": {
|
|
567
|
+
payload: {
|
|
568
|
+
nodeId: string;
|
|
569
|
+
parentId: string | null;
|
|
570
|
+
extent?: "parent" | Rect | null;
|
|
571
|
+
expandParent?: boolean;
|
|
572
|
+
};
|
|
573
|
+
result: {
|
|
574
|
+
nodeId: string;
|
|
575
|
+
position: XY;
|
|
576
|
+
};
|
|
577
|
+
};
|
|
578
|
+
"edge.add": {
|
|
579
|
+
payload: FlowEdgeInput<T>;
|
|
580
|
+
result: {
|
|
581
|
+
edgeId: string;
|
|
582
|
+
};
|
|
583
|
+
};
|
|
584
|
+
"edge.remove": {
|
|
585
|
+
payload: {
|
|
586
|
+
edgeId: string;
|
|
587
|
+
};
|
|
588
|
+
result: {
|
|
589
|
+
edgeId: string;
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
"edge.reconnect": {
|
|
593
|
+
payload: {
|
|
594
|
+
edgeId: string;
|
|
595
|
+
} & ConnectionPayload;
|
|
596
|
+
result: {
|
|
597
|
+
edgeId: string;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
"edge.set-data": {
|
|
601
|
+
payload: {
|
|
602
|
+
edgeId: string;
|
|
603
|
+
data: EdgeDataPatchOf<T>;
|
|
604
|
+
};
|
|
605
|
+
result: {
|
|
606
|
+
edgeId: string;
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
"edge.set-flags": {
|
|
610
|
+
payload: EdgeFlagsPayload;
|
|
611
|
+
result: {
|
|
612
|
+
edgeId: string;
|
|
613
|
+
};
|
|
614
|
+
};
|
|
615
|
+
"edge.set-z-index": {
|
|
616
|
+
payload: {
|
|
617
|
+
edgeId: string;
|
|
618
|
+
zIndex: number | null;
|
|
619
|
+
};
|
|
620
|
+
result: {
|
|
621
|
+
edgeId: string;
|
|
622
|
+
};
|
|
623
|
+
};
|
|
624
|
+
"selection.set": {
|
|
625
|
+
payload: {
|
|
626
|
+
nodeIds?: string[];
|
|
627
|
+
edgeIds?: string[];
|
|
628
|
+
mode?: SelectionMode;
|
|
629
|
+
};
|
|
630
|
+
result: SelectionResult;
|
|
631
|
+
};
|
|
632
|
+
"selection.clear": {
|
|
633
|
+
payload: Record<never, never>;
|
|
634
|
+
result: SelectionResult;
|
|
635
|
+
};
|
|
636
|
+
"selection.remove": {
|
|
637
|
+
payload: Record<never, never>;
|
|
638
|
+
result: RemovedResult;
|
|
639
|
+
};
|
|
640
|
+
batch: {
|
|
641
|
+
payload: {
|
|
642
|
+
commands: BatchEntry<T>[];
|
|
643
|
+
};
|
|
644
|
+
result: {
|
|
645
|
+
results: unknown[];
|
|
646
|
+
};
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
/** The name of a command, the core's or a feature's. */
|
|
650
|
+
type CommandName = keyof CommandMap;
|
|
651
|
+
/** The payload of command `C`. */
|
|
652
|
+
type PayloadOf<T extends FlowTypes, C extends CommandName> = CommandMap<T>[C]["payload"];
|
|
653
|
+
/** The result of command `C`. */
|
|
654
|
+
type ResultOf<T extends FlowTypes, C extends CommandName> = CommandMap<T>[C]["result"];
|
|
655
|
+
/** Why a command did not apply. */
|
|
656
|
+
type CommandErrorCode =
|
|
657
|
+
/** no command has this name */
|
|
658
|
+
"unknown_command" |
|
|
659
|
+
/** the payload does not match the command's schema, or names a field of a feature not installed */
|
|
660
|
+
"invalid_payload" |
|
|
661
|
+
/** a node or edge the payload names does not exist, or the command's feature is not installed */
|
|
662
|
+
"not_found" |
|
|
663
|
+
/** a rule of the flow forbids it (a permission flag, a duplicate edge, a parent cycle, …) */
|
|
664
|
+
"refused" |
|
|
665
|
+
/** a middleware vetoed it */
|
|
666
|
+
"vetoed" |
|
|
667
|
+
/** it was issued from a middleware and will run after the current command */
|
|
668
|
+
"queued" |
|
|
669
|
+
/** a middleware threw */
|
|
670
|
+
"middleware_error";
|
|
671
|
+
/** Why a command did not apply: a code, a message, and where (a JSON pointer into the payload). */
|
|
672
|
+
interface CommandError {
|
|
673
|
+
readonly code: CommandErrorCode;
|
|
674
|
+
readonly message: string;
|
|
675
|
+
/** a JSON pointer into the payload (or the dispatched input) */
|
|
676
|
+
readonly path?: string;
|
|
677
|
+
/** every schema problem, for `invalid_payload` */
|
|
678
|
+
readonly issues?: readonly ValidationIssue[];
|
|
679
|
+
}
|
|
680
|
+
/** What a command returns: its value, or why it did not apply. It never throws on bad input. */
|
|
681
|
+
type CommandResult<R> = {
|
|
682
|
+
readonly ok: true;
|
|
683
|
+
readonly value: R;
|
|
684
|
+
} | {
|
|
685
|
+
readonly ok: false;
|
|
686
|
+
readonly error: CommandError;
|
|
687
|
+
};
|
|
688
|
+
/** Options of `run`, `can` and `check`. */
|
|
689
|
+
interface RunOptions {
|
|
690
|
+
/** a step of a continuous gesture (a drag): the event is marked so undo can merge it */
|
|
691
|
+
transient?: boolean;
|
|
692
|
+
/** free-form information for middleware and listeners */
|
|
693
|
+
meta?: Readonly<Record<string, unknown>>;
|
|
694
|
+
}
|
|
695
|
+
/** What a middleware's `ctx.get` reads: each key's payload and result, as on `model.get`. */
|
|
696
|
+
interface CommandContextGetMap<T extends FlowTypes = AnyTypes> {
|
|
697
|
+
/** a node by its id */
|
|
698
|
+
"node-by": {
|
|
699
|
+
payload: {
|
|
700
|
+
id: string;
|
|
701
|
+
};
|
|
702
|
+
result: FlowDocument<T>["nodes"][number] | undefined;
|
|
703
|
+
};
|
|
704
|
+
/** an edge by its id */
|
|
705
|
+
"edge-by": {
|
|
706
|
+
payload: {
|
|
707
|
+
id: string;
|
|
708
|
+
};
|
|
709
|
+
result: FlowDocument<T>["edges"][number] | undefined;
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
/** What a middleware's `ctx.get` reads. */
|
|
713
|
+
type CommandContextGetKey = keyof CommandContextGetMap;
|
|
714
|
+
/** What a middleware sees of any command. */
|
|
715
|
+
interface CommandContextBase<T extends FlowTypes = AnyTypes> {
|
|
716
|
+
/** `model.can`/`model.check` (and a drag's hover): nothing will be committed; cause no side effects */
|
|
717
|
+
readonly dryRun: boolean;
|
|
718
|
+
readonly transient: boolean;
|
|
719
|
+
/** true for a command running inside a batch (the batch itself also passes the chain) */
|
|
720
|
+
readonly inBatch: boolean;
|
|
721
|
+
readonly meta: Readonly<Record<string, unknown>> | undefined;
|
|
722
|
+
/** the committed document the command applies to */
|
|
723
|
+
readonly state: FlowDocument<T>;
|
|
724
|
+
/** reads a node or an edge as the command sees it: inside a batch, after its earlier commands */
|
|
725
|
+
get<K extends CommandContextGetKey>(key: K, payload: CommandContextGetMap<T>[K]["payload"]): CommandContextGetMap<T>[K]["result"];
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* What a middleware sees: a union discriminated by `command`, so checking the command narrows the
|
|
729
|
+
* payload (`if (ctx.command === "edge.add") ctx.payload.source`). Only the commands of the
|
|
730
|
+
* installed features `F` are in it.
|
|
731
|
+
*/
|
|
732
|
+
type CommandContext<T extends FlowTypes = AnyTypes, F extends FlowFeatures = FlowFeatures> = ContextOf<T, CommandNameOf<F>>;
|
|
733
|
+
/**
|
|
734
|
+
* The context of each command of `C` (a distributive conditional, not a mapped type over the
|
|
735
|
+
* names: a model with features then stays assignable to a model of any features).
|
|
736
|
+
*/
|
|
737
|
+
type ContextOf<T extends FlowTypes, C extends CommandName> = C extends CommandName ? CommandContextBase<T> & {
|
|
738
|
+
readonly command: C;
|
|
739
|
+
/** the validated payload; assign a new object to rewrite it (it is validated again) */
|
|
740
|
+
payload: PayloadOf<T, C>;
|
|
741
|
+
} : never;
|
|
742
|
+
/**
|
|
743
|
+
* Runs around every command, engine-issued or not: veto (return an error without calling
|
|
744
|
+
* `next`), rewrite (assign `ctx.payload`, then call `next`) or observe (call `next` and look at its
|
|
745
|
+
* result). Returning `undefined` passes on `next`'s result when it was called. (Spelled as a
|
|
746
|
+
* method: its parameters compare both ways, so a model with features is a model.)
|
|
747
|
+
*/
|
|
748
|
+
type Middleware<T extends FlowTypes = AnyTypes, F extends FlowFeatures = FlowFeatures> = {
|
|
749
|
+
middleware(ctx: CommandContext<T, F>, next: () => CommandResult<unknown>): CommandResult<unknown> | undefined;
|
|
750
|
+
}["middleware"];
|
|
751
|
+
/** One command of a batch, as its event reports it. */
|
|
752
|
+
interface BatchStep {
|
|
753
|
+
readonly command: CommandName;
|
|
754
|
+
readonly payload: unknown;
|
|
755
|
+
readonly result: unknown;
|
|
756
|
+
}
|
|
757
|
+
/** What a listener receives: one event per commit. */
|
|
758
|
+
interface CommandEvent<T extends FlowTypes = AnyTypes> {
|
|
759
|
+
readonly command: CommandName;
|
|
760
|
+
/** the payload the command ran with (after the middleware rewrote it) */
|
|
761
|
+
readonly payload: unknown;
|
|
762
|
+
/** the command's value */
|
|
763
|
+
readonly result: unknown;
|
|
764
|
+
readonly before: FlowDocument<T>;
|
|
765
|
+
readonly after: FlowDocument<T>;
|
|
766
|
+
readonly transient: boolean;
|
|
767
|
+
readonly meta: Readonly<Record<string, unknown>> | undefined;
|
|
768
|
+
/** for a batch: the commands it ran, flattened */
|
|
769
|
+
readonly commands?: readonly BatchStep[];
|
|
770
|
+
}
|
|
771
|
+
/** Listens to every commit (`model.subscribe`). */
|
|
772
|
+
type CommandListener<T extends FlowTypes = AnyTypes> = (event: CommandEvent<T>) => void;
|
|
773
|
+
/** A command as `model.get("commands")` describes it: ready to become an AI tool definition. */
|
|
774
|
+
interface CommandInfo {
|
|
775
|
+
readonly name: CommandName;
|
|
776
|
+
readonly description: string;
|
|
777
|
+
readonly payloadSchema: JsonSchema;
|
|
778
|
+
readonly resultSchema: JsonSchema;
|
|
779
|
+
/** whether it may run as a step of a continuous gesture */
|
|
780
|
+
readonly transient: boolean;
|
|
781
|
+
/** the feature it comes with (`@fragiola/flow/<feature>`), none for the core's */
|
|
782
|
+
readonly feature?: FeatureName;
|
|
783
|
+
}
|
|
784
|
+
/** What an id is generated for. */
|
|
785
|
+
type IdKind = "node" | "edge";
|
|
786
|
+
/**
|
|
787
|
+
* Generates the id of a node or an edge given without one (the `createId` option). The model skips
|
|
788
|
+
* an id already in use and asks again; no global `crypto` is ever used.
|
|
789
|
+
*/
|
|
790
|
+
type CreateId = (kind: IdKind) => string;
|
|
791
|
+
/**
|
|
792
|
+
* The ids of one model. The default generator is deterministic: `` `${kind}-${n}` `` with one
|
|
793
|
+
* counter per kind.
|
|
794
|
+
*/
|
|
795
|
+
declare class IdSource {
|
|
796
|
+
private readonly counters;
|
|
797
|
+
private readonly custom;
|
|
798
|
+
constructor(createId?: CreateId);
|
|
799
|
+
/**
|
|
800
|
+
* A copy with the same counters and no custom generator: a dry run draws ids from it, leaving
|
|
801
|
+
* this one as it was and never asking the app's `createId` (so `check`'s id is only indicative).
|
|
802
|
+
*/
|
|
803
|
+
dryClone(): IdSource;
|
|
804
|
+
/** A fresh id for `kind`, for which `isUsed` is false. */
|
|
805
|
+
next(kind: IdKind, isUsed: (id: string) => boolean): string;
|
|
806
|
+
}
|
|
807
|
+
/** The payload of a key that takes none. */
|
|
808
|
+
type NoPayload = Record<never, never>;
|
|
809
|
+
/**
|
|
810
|
+
* The payload argument of a key: optional when the payload has no required field
|
|
811
|
+
* (`model.get("all-nodes")`), required otherwise (`model.get("node-by", { id })`).
|
|
812
|
+
*/
|
|
813
|
+
type QueryArgs<P> = NoPayload extends P ? [payload?: P] : [payload: P];
|
|
814
|
+
/** Which end of an edge a handle is: where it starts (`source`) or ends (`target`). */
|
|
815
|
+
type HandleType = "source" | "target";
|
|
816
|
+
/**
|
|
817
|
+
* An edge at a node, as the connection it makes: its id and its two ends (`node-connections-by`,
|
|
818
|
+
* what `useNodeConnections` gives).
|
|
819
|
+
*/
|
|
820
|
+
interface NodeConnection {
|
|
821
|
+
readonly edgeId: string;
|
|
822
|
+
readonly source: string;
|
|
823
|
+
readonly sourceHandle: string | undefined;
|
|
824
|
+
readonly target: string;
|
|
825
|
+
readonly targetHandle: string | undefined;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* A node's id, type and data (`nodes-data-by`, what `useNodesData` gives): a union over the
|
|
829
|
+
* registry's node types, so `type` narrows `data`.
|
|
830
|
+
*/
|
|
831
|
+
type NodeData<T extends FlowTypes = AnyTypes> = { [K in NodeTypeOf<T>]: {
|
|
832
|
+
readonly id: string;
|
|
833
|
+
readonly type: K;
|
|
834
|
+
readonly data: NodeDataOf<T, K>;
|
|
835
|
+
}; }[NodeTypeOf<T>];
|
|
836
|
+
/** What `model.get(key, payload)` reads: each key's payload and result. */
|
|
837
|
+
interface ModelGetMap<T extends FlowTypes = AnyTypes> {
|
|
838
|
+
/** a node by its id (O(1)) */
|
|
839
|
+
"node-by": {
|
|
840
|
+
payload: {
|
|
841
|
+
id: string;
|
|
842
|
+
};
|
|
843
|
+
result: FlowNode<T> | undefined;
|
|
844
|
+
};
|
|
845
|
+
/** an edge by its id (O(1)) */
|
|
846
|
+
"edge-by": {
|
|
847
|
+
payload: {
|
|
848
|
+
id: string;
|
|
849
|
+
};
|
|
850
|
+
result: FlowEdge<T> | undefined;
|
|
851
|
+
};
|
|
852
|
+
/** every node, in drawing order (the document's own frozen list) */
|
|
853
|
+
"all-nodes": {
|
|
854
|
+
payload: NoPayload;
|
|
855
|
+
result: readonly FlowNode<T>[];
|
|
856
|
+
};
|
|
857
|
+
/** every edge, in drawing order (the document's own frozen list) */
|
|
858
|
+
"all-edges": {
|
|
859
|
+
payload: NoPayload;
|
|
860
|
+
result: readonly FlowEdge<T>[];
|
|
861
|
+
};
|
|
862
|
+
/**
|
|
863
|
+
* the edges that start or end at a node; with `handleType`, only those that start
|
|
864
|
+
* (`"source"`) or end (`"target"`) there; with `handleId`, only those at that handle
|
|
865
|
+
*/
|
|
866
|
+
"node-edges-by": {
|
|
867
|
+
payload: {
|
|
868
|
+
nodeId: string;
|
|
869
|
+
handleType?: HandleType | undefined;
|
|
870
|
+
handleId?: string | undefined;
|
|
871
|
+
};
|
|
872
|
+
result: readonly FlowEdge<T>[];
|
|
873
|
+
};
|
|
874
|
+
/**
|
|
875
|
+
* the connections at a node: `node-edges-by`'s edges (with the same `handleType` and
|
|
876
|
+
* `handleId`), each as its id and its ends, in the document's order
|
|
877
|
+
*/
|
|
878
|
+
"node-connections-by": {
|
|
879
|
+
payload: {
|
|
880
|
+
nodeId: string;
|
|
881
|
+
handleType?: HandleType | undefined;
|
|
882
|
+
handleId?: string | undefined;
|
|
883
|
+
};
|
|
884
|
+
result: readonly NodeConnection[];
|
|
885
|
+
};
|
|
886
|
+
/** the id, type and data of each of the nodes, in the order asked; an unknown id is left out */
|
|
887
|
+
"nodes-data-by": {
|
|
888
|
+
payload: {
|
|
889
|
+
nodeIds: readonly string[];
|
|
890
|
+
};
|
|
891
|
+
result: readonly NodeData<T>[];
|
|
892
|
+
};
|
|
893
|
+
/** the edges that touch any of the nodes (an edge between two of them once) */
|
|
894
|
+
"connected-edges-by": {
|
|
895
|
+
payload: {
|
|
896
|
+
nodeIds: readonly string[];
|
|
897
|
+
};
|
|
898
|
+
result: readonly FlowEdge<T>[];
|
|
899
|
+
};
|
|
900
|
+
/**
|
|
901
|
+
* the nodes edges come from into a node (the sources of the edges that end at it), in the
|
|
902
|
+
* document's order, each once; a self loop makes it its own
|
|
903
|
+
*/
|
|
904
|
+
"incomers-by": {
|
|
905
|
+
payload: {
|
|
906
|
+
nodeId: string;
|
|
907
|
+
};
|
|
908
|
+
result: readonly FlowNode<T>[];
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* the nodes a node's edges go to (the targets of the edges that start at it), in the
|
|
912
|
+
* document's order, each once; a self loop makes it its own
|
|
913
|
+
*/
|
|
914
|
+
"outgoers-by": {
|
|
915
|
+
payload: {
|
|
916
|
+
nodeId: string;
|
|
917
|
+
};
|
|
918
|
+
result: readonly FlowNode<T>[];
|
|
919
|
+
};
|
|
920
|
+
/** a node's position in flow coordinates (with sub-flows: its parents' positions added) */
|
|
921
|
+
"absolute-position-by": {
|
|
922
|
+
payload: {
|
|
923
|
+
nodeId: string;
|
|
924
|
+
};
|
|
925
|
+
result: XY | undefined;
|
|
926
|
+
};
|
|
927
|
+
/** the selected nodes, in drawing order (`selection()`) */
|
|
928
|
+
"selected-nodes": {
|
|
929
|
+
payload: NoPayload;
|
|
930
|
+
result: readonly FlowNode<T>[];
|
|
931
|
+
};
|
|
932
|
+
/** the selected edges, in drawing order (`selection()`) */
|
|
933
|
+
"selected-edges": {
|
|
934
|
+
payload: NoPayload;
|
|
935
|
+
result: readonly FlowEdge<T>[];
|
|
936
|
+
};
|
|
937
|
+
/** a node's children, in drawing order (`subflows()`) */
|
|
938
|
+
"node-children-by": {
|
|
939
|
+
payload: {
|
|
940
|
+
nodeId: string;
|
|
941
|
+
};
|
|
942
|
+
result: readonly FlowNode<T>[];
|
|
943
|
+
};
|
|
944
|
+
/** a node's parent (`subflows()`) */
|
|
945
|
+
"node-parent-by": {
|
|
946
|
+
payload: {
|
|
947
|
+
nodeId: string;
|
|
948
|
+
};
|
|
949
|
+
result: FlowNode<T> | undefined;
|
|
950
|
+
};
|
|
951
|
+
/** the flow as a JSON v1 document: a writable copy, every id present (what `createFlowModel` takes) */
|
|
952
|
+
"flow-json": {
|
|
953
|
+
payload: NoPayload;
|
|
954
|
+
result: FlowDocumentJson<T>;
|
|
955
|
+
};
|
|
956
|
+
/** every installed command with its description and JSON Schemas */
|
|
957
|
+
commands: {
|
|
958
|
+
payload: NoPayload;
|
|
959
|
+
result: readonly CommandInfo[];
|
|
960
|
+
};
|
|
961
|
+
/**
|
|
962
|
+
* the commands that turn the document into one with these nodes and edges (a list left out
|
|
963
|
+
* stays as it is), for `batch`: what an adapter runs for its controlled `nodes` / `edges`
|
|
964
|
+
* props. Each difference is the command a user would have run (`node.move`, `edge.add`,
|
|
965
|
+
* `selection.set`, …), a flag that stops a user (`draggable`, `deletable`, `connectable`)
|
|
966
|
+
* unlocked for its step only; what no command expresses (a node's type, a removed data key)
|
|
967
|
+
* removes and adds the entity again with its id. Entities without an id are added; the
|
|
968
|
+
* drawing order is not synced
|
|
969
|
+
*/
|
|
970
|
+
"commands-to": {
|
|
971
|
+
payload: {
|
|
972
|
+
nodes?: readonly FlowNodeInput<T>[] | undefined;
|
|
973
|
+
edges?: readonly FlowEdgeInput<T>[] | undefined;
|
|
974
|
+
};
|
|
975
|
+
result: readonly BatchEntry<T>[];
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
/** A key of `model.get`. */
|
|
979
|
+
type ModelGetKey = keyof ModelGetMap;
|
|
980
|
+
/** The payload of `model.get(K)`. */
|
|
981
|
+
type ModelGetPayload<T extends FlowTypes, K extends ModelGetKey> = ModelGetMap<T>[K]["payload"];
|
|
982
|
+
/** The result of `model.get(K)`. */
|
|
983
|
+
type ModelGetResult<T extends FlowTypes, K extends ModelGetKey> = ModelGetMap<T>[K]["result"];
|
|
984
|
+
/** What `model.is(key, payload)` asks: each question's payload. */
|
|
985
|
+
interface ModelIsMap {
|
|
986
|
+
/** a node may be moved (`draggable`, default true) */
|
|
987
|
+
"node-draggable": {
|
|
988
|
+
nodeId: string;
|
|
989
|
+
};
|
|
990
|
+
/** a node may be selected (`selectable`, default true) */
|
|
991
|
+
"node-selectable": {
|
|
992
|
+
nodeId: string;
|
|
993
|
+
};
|
|
994
|
+
/** edges may start or end at a node (`connectable`, default true) */
|
|
995
|
+
"node-connectable": {
|
|
996
|
+
nodeId: string;
|
|
997
|
+
};
|
|
998
|
+
/** a node may be removed (`deletable`, default true) */
|
|
999
|
+
"node-deletable": {
|
|
1000
|
+
nodeId: string;
|
|
1001
|
+
};
|
|
1002
|
+
/** a node is hidden (`hidden`, default false) */
|
|
1003
|
+
"node-hidden": {
|
|
1004
|
+
nodeId: string;
|
|
1005
|
+
};
|
|
1006
|
+
/** an edge may be selected (`selectable`, default true) */
|
|
1007
|
+
"edge-selectable": {
|
|
1008
|
+
edgeId: string;
|
|
1009
|
+
};
|
|
1010
|
+
/** an edge may be removed (`deletable`, default true) */
|
|
1011
|
+
"edge-deletable": {
|
|
1012
|
+
edgeId: string;
|
|
1013
|
+
};
|
|
1014
|
+
/** an edge is hidden (`hidden`, default false) */
|
|
1015
|
+
"edge-hidden": {
|
|
1016
|
+
edgeId: string;
|
|
1017
|
+
};
|
|
1018
|
+
/**
|
|
1019
|
+
* an edge's ends may be moved (`reconnectable`, default true): one of them at least, or the
|
|
1020
|
+
* `end` given (`reconnectable: "source"` moves the source end only)
|
|
1021
|
+
*/
|
|
1022
|
+
"edge-reconnectable": {
|
|
1023
|
+
edgeId: string;
|
|
1024
|
+
end?: "source" | "target" | undefined;
|
|
1025
|
+
};
|
|
1026
|
+
/** a node is selected (`selection()`) */
|
|
1027
|
+
"node-selected": {
|
|
1028
|
+
nodeId: string;
|
|
1029
|
+
};
|
|
1030
|
+
/** an edge is selected (`selection()`) */
|
|
1031
|
+
"edge-selected": {
|
|
1032
|
+
edgeId: string;
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
/** A key of `model.is`. */
|
|
1036
|
+
type ModelIsKey = keyof ModelIsMap;
|
|
1037
|
+
/** The payload of `model.is(K)`. */
|
|
1038
|
+
type ModelIsPayload<K extends ModelIsKey> = ModelIsMap[K];
|
|
1039
|
+
/** Each entity's index in its list, by id. */
|
|
1040
|
+
type EntityIndex = ReadonlyMap<string, number>;
|
|
1041
|
+
/** A document and the indexes of its nodes and edges: what the model holds and queries read. */
|
|
1042
|
+
interface IndexedDocument {
|
|
1043
|
+
readonly document: FlowDocument;
|
|
1044
|
+
readonly nodeIndex: EntityIndex;
|
|
1045
|
+
readonly edgeIndex: EntityIndex;
|
|
1046
|
+
}
|
|
1047
|
+
/** A copy-on-write document: what a command reads and changes. */
|
|
1048
|
+
declare class Draft implements FlowReader {
|
|
1049
|
+
readonly ids: IdSource;
|
|
1050
|
+
private readonly base;
|
|
1051
|
+
private nodeList;
|
|
1052
|
+
private edgeList;
|
|
1053
|
+
private nodeIds;
|
|
1054
|
+
private edgeIds;
|
|
1055
|
+
/** the ids replaced in place; none once an item was added or removed */
|
|
1056
|
+
private replacedNodes;
|
|
1057
|
+
private replacedEdges;
|
|
1058
|
+
constructor(base: IndexedDocument, ids: IdSource);
|
|
1059
|
+
/** Whether a command changed anything. */
|
|
1060
|
+
get changed(): boolean;
|
|
1061
|
+
/** The nodes, in order. */
|
|
1062
|
+
nodes(): readonly FlowNode[];
|
|
1063
|
+
/** The edges, in order. */
|
|
1064
|
+
edges(): readonly FlowEdge[];
|
|
1065
|
+
/** A node by its id. */
|
|
1066
|
+
node(id: string): FlowNode | undefined;
|
|
1067
|
+
/** An edge by its id. */
|
|
1068
|
+
edge(id: string): FlowEdge | undefined;
|
|
1069
|
+
/** A fresh node id (`createId`). */
|
|
1070
|
+
nextNodeId(): string;
|
|
1071
|
+
/** A fresh edge id (`createId`). */
|
|
1072
|
+
nextEdgeId(): string;
|
|
1073
|
+
/** Appends a node (its id unused) or replaces the node of its id, in place. */
|
|
1074
|
+
putNode(node: FlowNode): void;
|
|
1075
|
+
/** Appends an edge (its id unused) or replaces the edge of its id, in place. */
|
|
1076
|
+
putEdge(edge: FlowEdge): void;
|
|
1077
|
+
/** Removes the nodes of these ids (their edges are the caller's to remove). */
|
|
1078
|
+
removeNodes(ids: ReadonlySet<string>): void;
|
|
1079
|
+
/** Removes the edges of these ids. */
|
|
1080
|
+
removeEdges(ids: ReadonlySet<string>): void;
|
|
1081
|
+
/** The document the draft holds now, frozen (or the base itself when nothing changed). */
|
|
1082
|
+
commit(freeze: boolean): IndexedDocument;
|
|
1083
|
+
private ownNodes;
|
|
1084
|
+
private ownEdges;
|
|
1085
|
+
}
|
|
1086
|
+
/** What the app adds to a dispatched command: never read from the untrusted input. */
|
|
1087
|
+
interface DispatchOptions {
|
|
1088
|
+
/** free-form information for middleware and listeners (`{ source: "assistant" }`) */
|
|
1089
|
+
meta?: Readonly<Record<string, unknown>> | undefined;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* The arguments after a command's name: its payload (optional when it has no required field:
|
|
1093
|
+
* `model.run("selection.clear")`) and the run options.
|
|
1094
|
+
*/
|
|
1095
|
+
type CommandArgs<P> = NoPayload extends P ? [payload?: P, options?: RunOptions] : [payload: P, options?: RunOptions];
|
|
1096
|
+
/**
|
|
1097
|
+
* The flow model. Every member is one verb, and bound (`const { run } = model` works):
|
|
1098
|
+
*
|
|
1099
|
+
* - `run` changes the flow (a command, through the middleware chain); `dispatch` is `run` for
|
|
1100
|
+
* untrusted JSON;
|
|
1101
|
+
* - `can` answers whether `run` would succeed; `check` returns what it would return;
|
|
1102
|
+
* - `get` reads (`model.get("node-by", { id })`); `is` asks a yes/no question
|
|
1103
|
+
* (`model.is("node-draggable", { nodeId })`);
|
|
1104
|
+
* - `use` adds a middleware around every command; `subscribe` listens to every commit.
|
|
1105
|
+
*
|
|
1106
|
+
* `F` is the installed features; the default, any features, is what every model is assignable to.
|
|
1107
|
+
*/
|
|
1108
|
+
interface FlowModel<T extends FlowTypes = AnyTypes, F extends FlowFeatures = FlowFeatures> {
|
|
1109
|
+
/**
|
|
1110
|
+
* changes the flow: runs a command (typed) through the middleware chain; never throws on bad
|
|
1111
|
+
* input. A command of a feature that is not installed returns `not_found`
|
|
1112
|
+
*/
|
|
1113
|
+
run<C extends CommandNameOf<F>>(command: C, ...args: CommandArgs<PayloadOf<T, C>>): CommandResult<ResultOf<T, C>>;
|
|
1114
|
+
/**
|
|
1115
|
+
* `run` for a command given as untrusted JSON `{ command, payload, transient? }`, validated
|
|
1116
|
+
* first; `options.meta` (the app's, never the input's) reaches middleware and listeners
|
|
1117
|
+
*/
|
|
1118
|
+
dispatch(input: unknown, options?: DispatchOptions): CommandResult<unknown>;
|
|
1119
|
+
/** whether `run` would succeed now (a dry run: nothing is committed or emitted) */
|
|
1120
|
+
can<C extends CommandNameOf<F>>(command: C, ...args: CommandArgs<PayloadOf<T, C>>): boolean;
|
|
1121
|
+
/** what `run` would return (its value, or why it is refused), without committing or emitting */
|
|
1122
|
+
check<C extends CommandNameOf<F>>(command: C, ...args: CommandArgs<PayloadOf<T, C>>): CommandResult<ResultOf<T, C>>;
|
|
1123
|
+
/** reads from the committed document: a node, the edges of a node, the JSON, the commands, … */
|
|
1124
|
+
get<K extends ModelGetKeyOf<F>>(key: K, ...payload: QueryArgs<ModelGetPayload<T, K>>): ModelGetResult<T, K>;
|
|
1125
|
+
/** asks a yes/no question about the committed document */
|
|
1126
|
+
is<K extends ModelIsKeyOf<F>>(key: K, payload: ModelIsPayload<K>): boolean;
|
|
1127
|
+
/** adds a middleware around every command (the first added runs outermost); returns its remover */
|
|
1128
|
+
use(middleware: {
|
|
1129
|
+
middleware(ctx: CommandContext<T, F>, next: () => CommandResult<unknown>): CommandResult<unknown> | undefined;
|
|
1130
|
+
}["middleware"]): () => void;
|
|
1131
|
+
/** listens to every committed command (one event per commit); returns its remover */
|
|
1132
|
+
subscribe(listener: CommandListener<T>): () => void;
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* The fields `edge.add` fills in when its payload leaves them out (the `defaultEdgeOptions` model
|
|
1136
|
+
* option): an edge's type, data, `zIndex` and flags, never its id or its ends.
|
|
1137
|
+
*/
|
|
1138
|
+
type DefaultEdgeOptions<T extends FlowTypes = AnyTypes> = Partial<Omit<FlowEdgeInput<T>, "id" | "source" | "target" | "sourceHandle" | "targetHandle">>;
|
|
1139
|
+
/** Options of {@link createFlowModel}. */
|
|
1140
|
+
interface FlowModelOptions<F extends FlowFeatures = readonly [], T extends FlowTypes = AnyTypes> {
|
|
1141
|
+
/**
|
|
1142
|
+
* the opt-in features (`[selection(), subflows()]`), each from its own entry
|
|
1143
|
+
* (`@fragiola/flow/<feature>`): fixed for the model's life. Without them, a bare flow
|
|
1144
|
+
*/
|
|
1145
|
+
features?: F | undefined;
|
|
1146
|
+
/** generates the id of a node or edge given without one; default `` `${kind}-${n}` `` */
|
|
1147
|
+
createId?: CreateId | undefined;
|
|
1148
|
+
/** freeze the document (default true) */
|
|
1149
|
+
freeze?: boolean | undefined;
|
|
1150
|
+
/**
|
|
1151
|
+
* the fields every `edge.add` fills in where its payload leaves them out, before the
|
|
1152
|
+
* middleware sees it (`{ type: "smoothstep" }`: a connection's new edges are smooth steps);
|
|
1153
|
+
* the document's edges are loaded as they are. An invalid one throws a `TypeError`
|
|
1154
|
+
*/
|
|
1155
|
+
defaultEdgeOptions?: DefaultEdgeOptions<T> | undefined;
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Creates a flow model from a JSON v1 document (an empty flow without one), with the features it
|
|
1159
|
+
* installs (`createFlowModel<Types, typeof features>(json, { features })`). The document is
|
|
1160
|
+
* validated: an invalid one throws a {@link FlowValidationError} listing every problem with its
|
|
1161
|
+
* JSON path. A feature installed twice, or missing one it requires, throws a `TypeError` naming
|
|
1162
|
+
* both.
|
|
1163
|
+
*/
|
|
1164
|
+
declare function createFlowModel<T extends FlowTypes = AnyTypes, const F extends FlowFeatures = readonly []>(json?: FlowJson<T>, options?: FlowModelOptions<F, T>): FlowModel<T, F>;
|
|
1165
|
+
/** The shape options of the built-in paths (the engine's `pathOptions`). */
|
|
1166
|
+
interface PathOptions {
|
|
1167
|
+
/** bezier: the share of the distance a control point stands out by; default 0.5 */
|
|
1168
|
+
readonly curvature?: number | undefined;
|
|
1169
|
+
/** smooth step: the corners' radius; default 5 */
|
|
1170
|
+
readonly borderRadius?: number | undefined;
|
|
1171
|
+
/** smooth step and step: how far an end stands out before turning; default 20 */
|
|
1172
|
+
readonly offset?: number | undefined;
|
|
1173
|
+
/** smooth step and step: where the turn sits between the source (0) and the target (1); default 0.5 */
|
|
1174
|
+
readonly stepPosition?: number | undefined;
|
|
1175
|
+
/** smooth step and step: the x of a vertical turn, in flow coordinates; default none */
|
|
1176
|
+
readonly centerX?: number | undefined;
|
|
1177
|
+
/** smooth step and step: the y of a horizontal turn, in flow coordinates; default none */
|
|
1178
|
+
readonly centerY?: number | undefined;
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* How the stack values are worked out:
|
|
1182
|
+
* - `"basic"`: nodes by `zIndex` (a selected one raised with `elevateNodesOnSelect`, a child above
|
|
1183
|
+
* its parent), edges by `zIndex` (a selected one raised with `elevateEdgesOnSelect`), edges
|
|
1184
|
+
* always below the nodes;
|
|
1185
|
+
* - `"auto"` (the default): the same for nodes; an edge stands at least as high as its ends when
|
|
1186
|
+
* one of them is a child, and a selected one is raised (`elevateEdgesOnSelect` defaults to true),
|
|
1187
|
+
* so it may be drawn above nodes;
|
|
1188
|
+
* - `"manual"`: only the given `zIndex` values count.
|
|
1189
|
+
*/
|
|
1190
|
+
type ZIndexMode = "basic" | "auto" | "manual";
|
|
1191
|
+
/**
|
|
1192
|
+
* One level of the drawing (`render-layers`): its edges, drawn above the nodes of the levels
|
|
1193
|
+
* below it and below its own nodes.
|
|
1194
|
+
*/
|
|
1195
|
+
interface RenderLayer {
|
|
1196
|
+
/** its place, 0 the lowest */
|
|
1197
|
+
readonly level: number;
|
|
1198
|
+
/**
|
|
1199
|
+
* the structural `z-index` of its edges' layer, in the viewport's stacking context; none with
|
|
1200
|
+
* a single level (today's DOM: the edges below the nodes)
|
|
1201
|
+
*/
|
|
1202
|
+
readonly zIndex: number | undefined;
|
|
1203
|
+
/** the shown nodes of this level, in the document's order */
|
|
1204
|
+
readonly nodeIds: readonly string[];
|
|
1205
|
+
/** the edges of this level, in drawing order */
|
|
1206
|
+
readonly edgeIds: readonly string[];
|
|
1207
|
+
}
|
|
1208
|
+
/** The gestures auto-pan follows, each of which may be turned off alone. */
|
|
1209
|
+
type AutoPanGesture = "node" | "connect" | "selection" | "resize";
|
|
1210
|
+
/**
|
|
1211
|
+
* How auto-pan pans (`autoPan: { speed, margin }`), and which gestures it follows (each one left
|
|
1212
|
+
* out does: `{ connect: false }` keeps the view still while drawing an edge).
|
|
1213
|
+
*/
|
|
1214
|
+
interface AutoPanOptions {
|
|
1215
|
+
/** a node drag; default true */
|
|
1216
|
+
node?: boolean | undefined;
|
|
1217
|
+
/** a connection or a reconnection; default true */
|
|
1218
|
+
connect?: boolean | undefined;
|
|
1219
|
+
/** a selection box; default true */
|
|
1220
|
+
selection?: boolean | undefined;
|
|
1221
|
+
/** a resize; default true */
|
|
1222
|
+
resize?: boolean | undefined;
|
|
1223
|
+
/** the pixels a frame it pans with the pointer at the edge (or past it); default 10 */
|
|
1224
|
+
speed?: number | undefined;
|
|
1225
|
+
/** how near the edge (in pixels) the pointer starts it; default 30 */
|
|
1226
|
+
margin?: number | undefined;
|
|
1227
|
+
}
|
|
1228
|
+
/** How a move, a connection or a resize was made: with the pointer or with the keyboard. */
|
|
1229
|
+
type MoveSource = "pointer" | "keyboard";
|
|
1230
|
+
/** A handle a connection's events name: its node, its id and its type. */
|
|
1231
|
+
interface ConnectionEnd {
|
|
1232
|
+
readonly nodeId: string;
|
|
1233
|
+
readonly handleId: string | undefined;
|
|
1234
|
+
readonly type: HandleType;
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Where a connection or a reconnection ended without an edge: the handle it came from (`from`;
|
|
1238
|
+
* for a reconnection, the edge's fixed end), the handle it was over (`to`, none when it was over
|
|
1239
|
+
* nothing), and the drop point as a client point (`clientX`, `clientY`: a new node goes there) and
|
|
1240
|
+
* as a flow point. A keyboard connection's points are its target's (or its start's) centre.
|
|
1241
|
+
* `dropped` tells a release (or a keyboard confirm) from a cancel (Escape, the lock turning
|
|
1242
|
+
* `connect` off, a `pointercancel`): only a drop should add a node where it ended.
|
|
1243
|
+
*/
|
|
1244
|
+
interface ConnectionDrop {
|
|
1245
|
+
readonly dropped: boolean;
|
|
1246
|
+
readonly from: ConnectionEnd;
|
|
1247
|
+
readonly to: ConnectionEnd | undefined;
|
|
1248
|
+
readonly client: XY;
|
|
1249
|
+
readonly point: XY;
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Where a tap, a double click or a context menu happened: the flow point and the client point,
|
|
1253
|
+
* and the DOM event (an app prevents a context menu's default with it).
|
|
1254
|
+
*/
|
|
1255
|
+
interface FlowPointerInfo {
|
|
1256
|
+
/** the flow point */
|
|
1257
|
+
readonly point: XY;
|
|
1258
|
+
/** the client point (`clientX`, `clientY`) */
|
|
1259
|
+
readonly client: XY;
|
|
1260
|
+
/** the event that ended it: the tap's `pointerup`, the `dblclick`, the `contextmenu` */
|
|
1261
|
+
readonly event: MouseEvent;
|
|
1262
|
+
}
|
|
1263
|
+
/** A step of a drag of the rectangle around the selection: the dragged nodes and the pointer. */
|
|
1264
|
+
interface SelectionDragStep {
|
|
1265
|
+
/** the nodes it drags (the selection's draggable ones) */
|
|
1266
|
+
readonly nodeIds: readonly string[];
|
|
1267
|
+
/** the pointer's client point (`clientX`, `clientY`) */
|
|
1268
|
+
readonly client: XY;
|
|
1269
|
+
/** the pointer's flow point */
|
|
1270
|
+
readonly point: XY;
|
|
1271
|
+
}
|
|
1272
|
+
/** A viewport change of a gesture or an animation, at its start or its end. */
|
|
1273
|
+
interface ViewportMove {
|
|
1274
|
+
readonly viewport: Viewport;
|
|
1275
|
+
/** a pan, a zoom, a pinch or auto-pan (`true`), or an action (`false`) */
|
|
1276
|
+
readonly gesture: boolean;
|
|
1277
|
+
}
|
|
1278
|
+
/** An event of `engine.subscribe`. */
|
|
1279
|
+
type FlowEngineEvent = {
|
|
1280
|
+
/** the viewport changed (`gesture`: by a pan, a zoom or a pinch, not by an action) */
|
|
1281
|
+
readonly type: "viewport-change";
|
|
1282
|
+
readonly viewport: Viewport;
|
|
1283
|
+
readonly gesture: boolean;
|
|
1284
|
+
} | ({
|
|
1285
|
+
/**
|
|
1286
|
+
* the viewport starts changing: the first change of a pan, a wheel, a pinch, an
|
|
1287
|
+
* animation or an action (an action that does not animate starts and ends at once)
|
|
1288
|
+
*/
|
|
1289
|
+
readonly type: "viewport-change-start";
|
|
1290
|
+
} & ViewportMove) | ({
|
|
1291
|
+
/**
|
|
1292
|
+
* the viewport stopped changing: the pan or pinch was released, the animation ended or
|
|
1293
|
+
* stopped, the wheel rested for 150 ms
|
|
1294
|
+
*/
|
|
1295
|
+
readonly type: "viewport-change-end";
|
|
1296
|
+
} & ViewportMove) | {
|
|
1297
|
+
/** the root has a size and the fit on init (`fitView`) is done, once per engine */
|
|
1298
|
+
readonly type: "ready";
|
|
1299
|
+
} | ({
|
|
1300
|
+
/** a tap (a press released within the tap distance, no gesture started) on a node */
|
|
1301
|
+
readonly type: "node-click";
|
|
1302
|
+
readonly nodeId: string;
|
|
1303
|
+
} & FlowPointerInfo) | ({
|
|
1304
|
+
/** a tap on an edge */
|
|
1305
|
+
readonly type: "edge-click";
|
|
1306
|
+
readonly edgeId: string;
|
|
1307
|
+
} & FlowPointerInfo) | ({
|
|
1308
|
+
/** a tap on the pane */
|
|
1309
|
+
readonly type: "pane-click";
|
|
1310
|
+
} & FlowPointerInfo) | ({
|
|
1311
|
+
/**
|
|
1312
|
+
* a tap on a minimap (`minimap()`): `point` is the flow point under it on the minimap
|
|
1313
|
+
* (`minimap-point-to-flow`), not the one behind it in the root; `element` is the
|
|
1314
|
+
* tapped minimap (its `data-flow-part="minimap"` element), as an app may draw several
|
|
1315
|
+
*/
|
|
1316
|
+
readonly type: "minimap-click";
|
|
1317
|
+
readonly element: Element;
|
|
1318
|
+
} & FlowPointerInfo) | ({
|
|
1319
|
+
/** a double click whose two presses were taps on a node */
|
|
1320
|
+
readonly type: "node-double-click";
|
|
1321
|
+
readonly nodeId: string;
|
|
1322
|
+
} & FlowPointerInfo) | ({
|
|
1323
|
+
/** a double click whose two presses were taps on an edge */
|
|
1324
|
+
readonly type: "edge-double-click";
|
|
1325
|
+
readonly edgeId: string;
|
|
1326
|
+
} & FlowPointerInfo) | ({
|
|
1327
|
+
/** a double click whose two presses were taps on the pane */
|
|
1328
|
+
readonly type: "pane-double-click";
|
|
1329
|
+
} & FlowPointerInfo) | ({
|
|
1330
|
+
/** a context menu on a node (not one of several selected nodes) */
|
|
1331
|
+
readonly type: "node-context-menu";
|
|
1332
|
+
readonly nodeId: string;
|
|
1333
|
+
} & FlowPointerInfo) | ({
|
|
1334
|
+
/** a context menu on an edge */
|
|
1335
|
+
readonly type: "edge-context-menu";
|
|
1336
|
+
readonly edgeId: string;
|
|
1337
|
+
} & FlowPointerInfo) | ({
|
|
1338
|
+
/** a context menu on the pane */
|
|
1339
|
+
readonly type: "pane-context-menu";
|
|
1340
|
+
} & FlowPointerInfo) | ({
|
|
1341
|
+
/**
|
|
1342
|
+
* a context menu on a selected node while several nodes are selected, or on the
|
|
1343
|
+
* rectangle around the selection (the `nodes-selection` part): the selection's
|
|
1344
|
+
*/
|
|
1345
|
+
readonly type: "selection-context-menu";
|
|
1346
|
+
readonly nodeIds: readonly string[];
|
|
1347
|
+
readonly edgeIds: readonly string[];
|
|
1348
|
+
} & FlowPointerInfo) | {
|
|
1349
|
+
/** a drag of these nodes started (`drag()`) */
|
|
1350
|
+
readonly type: "drag-start";
|
|
1351
|
+
readonly nodeIds: readonly string[];
|
|
1352
|
+
} | {
|
|
1353
|
+
/** nodes were moved and dropped (a drag) or moved by the arrows (`keyboard()`) */
|
|
1354
|
+
readonly type: "nodes-move";
|
|
1355
|
+
readonly nodeIds: readonly string[];
|
|
1356
|
+
readonly source: MoveSource;
|
|
1357
|
+
} | ({
|
|
1358
|
+
/**
|
|
1359
|
+
* a drag of the rectangle around the selection (the `nodes-selection` part, `drag()`)
|
|
1360
|
+
* started (instead of `drag-start`): its nodes, where the pointer is
|
|
1361
|
+
*/
|
|
1362
|
+
readonly type: "selection-drag-start";
|
|
1363
|
+
} & SelectionDragStep) | ({
|
|
1364
|
+
/** the rectangle's drag moved its nodes (each step, auto-pan's included) */
|
|
1365
|
+
readonly type: "selection-drag";
|
|
1366
|
+
} & SelectionDragStep) | ({
|
|
1367
|
+
/** the rectangle's drag dropped its nodes (after their `nodes-move`) */
|
|
1368
|
+
readonly type: "selection-drag-end";
|
|
1369
|
+
} & SelectionDragStep) | {
|
|
1370
|
+
/** a drag was cancelled: its nodes went back */
|
|
1371
|
+
readonly type: "drag-cancel";
|
|
1372
|
+
readonly nodeIds: readonly string[];
|
|
1373
|
+
} | {
|
|
1374
|
+
/**
|
|
1375
|
+
* a connection started from a handle (`connection()`): dragged or tapped (`input:
|
|
1376
|
+
* "pointer"`), or Enter on a focused handle (`"keyboard"`, with `keyboard()`)
|
|
1377
|
+
*/
|
|
1378
|
+
readonly type: "connect-start";
|
|
1379
|
+
readonly nodeId: string;
|
|
1380
|
+
readonly handleId: string | undefined;
|
|
1381
|
+
readonly handleType: HandleType;
|
|
1382
|
+
readonly input: MoveSource;
|
|
1383
|
+
} | {
|
|
1384
|
+
/**
|
|
1385
|
+
* a keyboard connection points at another target handle (the arrows, Tab): the
|
|
1386
|
+
* `index`-th of the `count` handles the model accepts, nearest first (`index` -1 and no
|
|
1387
|
+
* handle when it accepts none), for the app's live region
|
|
1388
|
+
*/
|
|
1389
|
+
readonly type: "connect-target";
|
|
1390
|
+
readonly nodeId: string | undefined;
|
|
1391
|
+
readonly handleId: string | undefined;
|
|
1392
|
+
readonly handleType: HandleType | undefined;
|
|
1393
|
+
readonly index: number;
|
|
1394
|
+
readonly count: number;
|
|
1395
|
+
} | {
|
|
1396
|
+
/** a connection was dropped on a handle (or Enter chose it): an edge was added (`edge.add`) */
|
|
1397
|
+
readonly type: "connect";
|
|
1398
|
+
readonly edgeId: string;
|
|
1399
|
+
readonly source: string;
|
|
1400
|
+
readonly target: string;
|
|
1401
|
+
readonly input: MoveSource;
|
|
1402
|
+
} | ({
|
|
1403
|
+
/**
|
|
1404
|
+
* a connection ended without an edge: dropped nowhere, cancelled, or (`refused`) on a
|
|
1405
|
+
* handle `model.can("edge.add", …)` refused; where it ended (`ConnectionDrop`)
|
|
1406
|
+
*/
|
|
1407
|
+
readonly type: "connect-cancel";
|
|
1408
|
+
readonly refused: boolean;
|
|
1409
|
+
readonly input: MoveSource;
|
|
1410
|
+
} & ConnectionDrop) | {
|
|
1411
|
+
/** an edge's end was dragged (`reconnection()`) */
|
|
1412
|
+
readonly type: "reconnect-start";
|
|
1413
|
+
readonly edgeId: string;
|
|
1414
|
+
readonly end: "source" | "target";
|
|
1415
|
+
} | {
|
|
1416
|
+
/** an edge was reconnected (`edge.reconnect`) */
|
|
1417
|
+
readonly type: "reconnect";
|
|
1418
|
+
readonly edgeId: string;
|
|
1419
|
+
readonly source: string;
|
|
1420
|
+
readonly target: string;
|
|
1421
|
+
} | ({
|
|
1422
|
+
/**
|
|
1423
|
+
* a reconnection ended with the edge as it was (`refused`: dropped on a refused handle);
|
|
1424
|
+
* `from` is the edge's fixed end, `to` the handle it was over
|
|
1425
|
+
*/
|
|
1426
|
+
readonly type: "reconnect-cancel";
|
|
1427
|
+
readonly edgeId: string;
|
|
1428
|
+
readonly end: "source" | "target";
|
|
1429
|
+
readonly refused: boolean;
|
|
1430
|
+
} & ConnectionDrop) | {
|
|
1431
|
+
/** a resize of a node started (`resize()`, a drag of a resize handle past its press) */
|
|
1432
|
+
readonly type: "resize-start";
|
|
1433
|
+
readonly nodeId: string;
|
|
1434
|
+
readonly width: number;
|
|
1435
|
+
readonly height: number;
|
|
1436
|
+
} | {
|
|
1437
|
+
/** a resize was cancelled: the node is back at its size */
|
|
1438
|
+
readonly type: "resize-cancel";
|
|
1439
|
+
readonly nodeId: string;
|
|
1440
|
+
} | {
|
|
1441
|
+
/** a node was resized (`resize()`): by a drag, or by the arrows on a focused resize handle */
|
|
1442
|
+
readonly type: "resize";
|
|
1443
|
+
readonly nodeId: string;
|
|
1444
|
+
readonly width: number;
|
|
1445
|
+
readonly height: number;
|
|
1446
|
+
readonly source: MoveSource;
|
|
1447
|
+
} | {
|
|
1448
|
+
/** a selection box started (`selection()`): the pointer moved past its press */
|
|
1449
|
+
readonly type: "box-select-start";
|
|
1450
|
+
/** where it started, as a client point and as a flow point */
|
|
1451
|
+
readonly client: XY;
|
|
1452
|
+
readonly point: XY;
|
|
1453
|
+
} | {
|
|
1454
|
+
/** a box selection ended with these selected (`selection()`) */
|
|
1455
|
+
readonly type: "box-select";
|
|
1456
|
+
readonly nodeIds: readonly string[];
|
|
1457
|
+
readonly edgeIds: readonly string[];
|
|
1458
|
+
} | {
|
|
1459
|
+
/** a delete key removed these (`keyboard()`, after its `beforeDelete`) */
|
|
1460
|
+
readonly type: "remove";
|
|
1461
|
+
readonly nodeIds: readonly string[];
|
|
1462
|
+
readonly edgeIds: readonly string[];
|
|
1463
|
+
};
|
|
1464
|
+
/** The type of an engine event. */
|
|
1465
|
+
type FlowEngineEventType = FlowEngineEvent["type"];
|
|
1466
|
+
/** The event of a type. */
|
|
1467
|
+
type FlowEngineEventOf<K extends FlowEngineEventType> = Extract<FlowEngineEvent, {
|
|
1468
|
+
readonly type: K;
|
|
1469
|
+
}>;
|
|
1470
|
+
/**
|
|
1471
|
+
* One side's padding: a number is a share of the root's size along it (its width for the left and
|
|
1472
|
+
* right, its height for the top and bottom), a `"<n>px"` string pixels.
|
|
1473
|
+
*/
|
|
1474
|
+
type PaddingValue = number | `${number}px`;
|
|
1475
|
+
/**
|
|
1476
|
+
* The room kept free around framed bounds: one value for every side, or each side's (a side left
|
|
1477
|
+
* out keeps none).
|
|
1478
|
+
*/
|
|
1479
|
+
type FitPadding = PaddingValue | {
|
|
1480
|
+
readonly top?: PaddingValue | undefined;
|
|
1481
|
+
readonly right?: PaddingValue | undefined;
|
|
1482
|
+
readonly bottom?: PaddingValue | undefined;
|
|
1483
|
+
readonly left?: PaddingValue | undefined;
|
|
1484
|
+
};
|
|
1485
|
+
/** Options of {@link viewportForBounds}. */
|
|
1486
|
+
interface ViewportForBoundsOptions {
|
|
1487
|
+
/**
|
|
1488
|
+
* the room kept free on every side (a number: a share of the root's size), or each side's
|
|
1489
|
+
* (`{ top, right, bottom, left }`, a `"<n>px"` string in pixels); default 0.1
|
|
1490
|
+
*/
|
|
1491
|
+
readonly padding?: FitPadding | undefined;
|
|
1492
|
+
/** the least zoom it may pick; default 0.5 */
|
|
1493
|
+
readonly minZoom?: number | undefined;
|
|
1494
|
+
/** the greatest zoom it may pick; default 2 */
|
|
1495
|
+
readonly maxZoom?: number | undefined;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* The viewport that shows `bounds` (flow coordinates) whole and centred in a root of `width` ×
|
|
1499
|
+
* `height` pixels, `padding` kept free on every side (or each side's: the bounds are centred in
|
|
1500
|
+
* what is left), its zoom between `minZoom` and `maxZoom` (a rectangle without a size gets the
|
|
1501
|
+
* greatest zoom, centred on it; a `maxZoom` below `minZoom` wins).
|
|
1502
|
+
*/
|
|
1503
|
+
declare function viewportForBounds(bounds: Rect, width: number, height: number, options?: ViewportForBoundsOptions): Viewport;
|
|
1504
|
+
/** A kind of gesture and key `set-interactive` turns on or off on its own. */
|
|
1505
|
+
type InteractionKind = "drag" | "connect" | "select" | "reconnect";
|
|
1506
|
+
/**
|
|
1507
|
+
* The switches of `set-interactive`: `interactive` (every gesture and key that changes the flow)
|
|
1508
|
+
* and each kind (`drag`: dragging nodes and moving them with the arrows; `connect`: drawing edges;
|
|
1509
|
+
* `select`: taps, the selection box, Enter and Space; `reconnect`: moving an edge's ends).
|
|
1510
|
+
*/
|
|
1511
|
+
interface Interactivity {
|
|
1512
|
+
readonly interactive: boolean;
|
|
1513
|
+
readonly drag: boolean;
|
|
1514
|
+
readonly connect: boolean;
|
|
1515
|
+
readonly select: boolean;
|
|
1516
|
+
readonly reconnect: boolean;
|
|
1517
|
+
}
|
|
1518
|
+
/** What `set-interactive` takes: the switches it changes (at least one), the others kept. */
|
|
1519
|
+
type InteractivityPayload = Partial<Interactivity>;
|
|
1520
|
+
/** Options of `fit-view` (and of the `fitView` engine option). */
|
|
1521
|
+
interface FitViewPayload {
|
|
1522
|
+
/**
|
|
1523
|
+
* the room kept free on every side (a number: a share of the root's size), or each side's
|
|
1524
|
+
* (`{ top, right, bottom, left }`, a `"<n>px"` string in pixels); default 0.1
|
|
1525
|
+
*/
|
|
1526
|
+
padding?: FitPadding | undefined;
|
|
1527
|
+
/** only these nodes; default every node that is not hidden */
|
|
1528
|
+
nodeIds?: string[] | undefined;
|
|
1529
|
+
/** without `nodeIds`, the hidden nodes of known size too; default false */
|
|
1530
|
+
includeHidden?: boolean | undefined;
|
|
1531
|
+
/** the least zoom it may pick (within the engine's limits); default the engine's `minZoom` */
|
|
1532
|
+
minZoom?: number | undefined;
|
|
1533
|
+
/** the greatest zoom it may pick (within the engine's limits); default the engine's `maxZoom` */
|
|
1534
|
+
maxZoom?: number | undefined;
|
|
1535
|
+
/** how long it animates, in milliseconds (the engine's `easing`); default 0: at once */
|
|
1536
|
+
duration?: number | undefined;
|
|
1537
|
+
}
|
|
1538
|
+
/** What `viewport-for-bounds` takes: a flow rectangle and `fit-view`'s framing options. */
|
|
1539
|
+
interface ViewportForBoundsPayload {
|
|
1540
|
+
/** the flow rectangle to frame */
|
|
1541
|
+
bounds: Rect;
|
|
1542
|
+
/** the room kept free on every side, or each side's, as `fit-view`'s; default 0.1 */
|
|
1543
|
+
padding?: FitPadding | undefined;
|
|
1544
|
+
/** the least zoom it may pick (within the engine's limits); default the engine's `minZoom` */
|
|
1545
|
+
minZoom?: number | undefined;
|
|
1546
|
+
/** the greatest zoom it may pick (within the engine's limits); default the engine's `maxZoom` */
|
|
1547
|
+
maxZoom?: number | undefined;
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* What `intersecting-nodes` takes: a node (its box) or a flow rectangle, and whether a node that
|
|
1551
|
+
* only overlaps it counts.
|
|
1552
|
+
*/
|
|
1553
|
+
interface IntersectingNodesPayload {
|
|
1554
|
+
/** the node whose box the others are compared with (it is left out); wins over `rect` */
|
|
1555
|
+
nodeId?: string | undefined;
|
|
1556
|
+
/** a rectangle in absolute flow coordinates, without `nodeId` */
|
|
1557
|
+
rect?: Rect | undefined;
|
|
1558
|
+
/** any shared area counts (`true`, the default); `false`: only a node wholly inside */
|
|
1559
|
+
partial?: boolean | undefined;
|
|
1560
|
+
}
|
|
1561
|
+
/** A zoom by a step around a point (`zoom-in`, `zoom-out`). */
|
|
1562
|
+
interface ZoomStepPayload {
|
|
1563
|
+
/** the factor; default the engine's `zoomStep` (1.2) */
|
|
1564
|
+
step?: number | undefined;
|
|
1565
|
+
/** the screen point (relative to the root) that stays put; default the root's centre */
|
|
1566
|
+
around?: XY | undefined;
|
|
1567
|
+
/** how long it animates, in milliseconds (the engine's `easing`); default 0: at once */
|
|
1568
|
+
duration?: number | undefined;
|
|
1569
|
+
}
|
|
1570
|
+
/** The pattern a `Background` draws (`background-pattern`). */
|
|
1571
|
+
type BackgroundVariant = "dots" | "lines" | "cross";
|
|
1572
|
+
/** What `background-pattern` takes. */
|
|
1573
|
+
interface BackgroundPatternPayload {
|
|
1574
|
+
/** default `"dots"` */
|
|
1575
|
+
variant?: BackgroundVariant | undefined;
|
|
1576
|
+
/** the distance between two marks, in flow units; default 20 (`[x, y]` for two) */
|
|
1577
|
+
gap?: number | readonly [number, number] | undefined;
|
|
1578
|
+
/**
|
|
1579
|
+
* dots: a dot's diameter, in flow units (default 1); lines: the stroke width, in screen pixels
|
|
1580
|
+
* (default 1); cross: the length of each bar, in flow units (default 6)
|
|
1581
|
+
*/
|
|
1582
|
+
size?: number | undefined;
|
|
1583
|
+
/** the pattern's shift from the flow's origin, in flow units; default 0 */
|
|
1584
|
+
offset?: number | readonly [number, number] | undefined;
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* One tile of a background pattern, on the screen: an SVG `<pattern>` with
|
|
1588
|
+
* `patternUnits="userSpaceOnUse"` at `x`, `y` of `width` × `height`, drawing a dot (`dot`) or a
|
|
1589
|
+
* path (`path`, for lines and crosses, stroked `strokeWidth`).
|
|
1590
|
+
*/
|
|
1591
|
+
interface BackgroundPattern {
|
|
1592
|
+
readonly variant: BackgroundVariant;
|
|
1593
|
+
readonly x: number;
|
|
1594
|
+
readonly y: number;
|
|
1595
|
+
readonly width: number;
|
|
1596
|
+
readonly height: number;
|
|
1597
|
+
/** the dot (`dots`), inside the tile */
|
|
1598
|
+
readonly dot: {
|
|
1599
|
+
readonly cx: number;
|
|
1600
|
+
readonly cy: number;
|
|
1601
|
+
readonly r: number;
|
|
1602
|
+
} | undefined;
|
|
1603
|
+
/** the lines' or the cross's path data (`lines`, `cross`), inside the tile */
|
|
1604
|
+
readonly path: string | undefined;
|
|
1605
|
+
/** the stroke width of `path`, in pixels */
|
|
1606
|
+
readonly strokeWidth: number;
|
|
1607
|
+
}
|
|
1608
|
+
/** Where a node's toolbar goes (`node-toolbar-by`): beside one node, or beside several nodes' bounds. */
|
|
1609
|
+
interface NodeToolbarPayload {
|
|
1610
|
+
/** the node it stands beside (without `nodeIds`) */
|
|
1611
|
+
nodeId?: string | undefined;
|
|
1612
|
+
/** the nodes whose bounds it stands beside (their measured boxes); wins over `nodeId` when not empty */
|
|
1613
|
+
nodeIds?: readonly string[] | undefined;
|
|
1614
|
+
/** the node's side it stands on; default `"top"` */
|
|
1615
|
+
side?: HandleSide | undefined;
|
|
1616
|
+
/** where along that side; default `"center"` */
|
|
1617
|
+
align?: "start" | "center" | "end" | undefined;
|
|
1618
|
+
/** the gap between the node and the toolbar, in pixels; default 10 */
|
|
1619
|
+
offset?: number | undefined;
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* A toolbar's anchor point on the screen (relative to the root, outside the zoom), and which point
|
|
1623
|
+
* of the toolbar goes there: `anchorX`, `anchorY` are shares of its own size (`0.5, 1`: its
|
|
1624
|
+
* bottom centre), for a `translate(-50%, -100%)`.
|
|
1625
|
+
*/
|
|
1626
|
+
interface NodeToolbarPosition {
|
|
1627
|
+
readonly x: number;
|
|
1628
|
+
readonly y: number;
|
|
1629
|
+
readonly anchorX: number;
|
|
1630
|
+
readonly anchorY: number;
|
|
1631
|
+
}
|
|
1632
|
+
/** Where an edge's toolbar goes (`edge-toolbar-by`). */
|
|
1633
|
+
interface EdgeToolbarPayload {
|
|
1634
|
+
edgeId: string;
|
|
1635
|
+
/** the point of the edge it stands at: its label point (default), its source or its target end */
|
|
1636
|
+
position?: "label" | "source" | "target" | undefined;
|
|
1637
|
+
/** a flow point it stands at instead (absolute flow coordinates); wins over `position` */
|
|
1638
|
+
point?: XY | undefined;
|
|
1639
|
+
/** a screen offset from that point, in pixels; default `{ x: 0, y: 0 }` */
|
|
1640
|
+
offset?: XY | undefined;
|
|
1641
|
+
/** which of the toolbar's edges goes at the point across: its left (`start`), centre (default) or right */
|
|
1642
|
+
alignX?: "start" | "center" | "end" | undefined;
|
|
1643
|
+
/** which of the toolbar's edges goes at the point down: its top (`start`), centre (default) or bottom */
|
|
1644
|
+
alignY?: "start" | "center" | "end" | undefined;
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* An edge toolbar's anchor on the screen (relative to the root, outside the zoom): the toolbar's
|
|
1648
|
+
* point at `anchorX`, `anchorY` (shares of its size, 0.5 by default: its centre) goes there.
|
|
1649
|
+
*/
|
|
1650
|
+
type EdgeToolbarPosition = NodeToolbarPosition;
|
|
1651
|
+
/** The selection box (`selection-box`, `selection()`): on the screen, relative to the root. */
|
|
1652
|
+
type SelectionBox = Rect;
|
|
1653
|
+
/** A connection being drawn (`connection`, `connection()`). */
|
|
1654
|
+
interface Connection {
|
|
1655
|
+
/** the handle it started from */
|
|
1656
|
+
readonly from: FlowHandle;
|
|
1657
|
+
/** where it starts, in flow coordinates (the handle's centre) */
|
|
1658
|
+
readonly fromPoint: XY;
|
|
1659
|
+
/** where the pointer is, or the centre of the handle it snapped to, in flow coordinates */
|
|
1660
|
+
readonly toPoint: XY;
|
|
1661
|
+
/** the side it enters by: the snapped handle's, or the one facing its start */
|
|
1662
|
+
readonly toSide: HandleSide;
|
|
1663
|
+
/** the handle within the radius it would end at, if any */
|
|
1664
|
+
readonly to: FlowHandle | undefined;
|
|
1665
|
+
/** `valid`: the drop adds an edge; `invalid`: `model.can` refuses it; null: no handle near */
|
|
1666
|
+
readonly status: "valid" | "invalid" | null;
|
|
1667
|
+
/** the connection line's path (bezier) and its middle */
|
|
1668
|
+
readonly path: string;
|
|
1669
|
+
/** the edge whose end is being moved (`reconnection()`), with the end */
|
|
1670
|
+
readonly reconnecting: {
|
|
1671
|
+
readonly edgeId: string;
|
|
1672
|
+
readonly end: "source" | "target";
|
|
1673
|
+
} | undefined;
|
|
1674
|
+
}
|
|
1675
|
+
/** What the minimap draws (`minimap-view`, `minimap()`), in flow coordinates. */
|
|
1676
|
+
interface MinimapView {
|
|
1677
|
+
/** the SVG `viewBox`: the nodes and the view, fitted to the minimap's aspect */
|
|
1678
|
+
readonly viewBox: Rect;
|
|
1679
|
+
/** `viewBox` as the attribute writes it */
|
|
1680
|
+
readonly viewBoxAttribute: string;
|
|
1681
|
+
/** the flow units one minimap pixel stands for */
|
|
1682
|
+
readonly scale: number;
|
|
1683
|
+
/** each visible node's box */
|
|
1684
|
+
readonly nodes: readonly {
|
|
1685
|
+
readonly nodeId: string;
|
|
1686
|
+
readonly x: number;
|
|
1687
|
+
readonly y: number;
|
|
1688
|
+
readonly width: number;
|
|
1689
|
+
readonly height: number;
|
|
1690
|
+
}[];
|
|
1691
|
+
/** what the root shows */
|
|
1692
|
+
readonly view: Rect;
|
|
1693
|
+
/** the mask: the view box with the view cut out (`fill-rule="evenodd"`) */
|
|
1694
|
+
readonly maskPath: string;
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* What `engine.run(action, payload)` does: each screen action's payload and result. A viewport
|
|
1698
|
+
* action with a `duration` returns the viewport it animates to (zoom limits and extent kept) and
|
|
1699
|
+
* gets there frame by frame (`viewport-change` with `gesture: false` each frame); another viewport
|
|
1700
|
+
* action, a pan or zoom gesture, `cancel-gesture` or `destroy` stops it where it is.
|
|
1701
|
+
*/
|
|
1702
|
+
interface EngineActionMap {
|
|
1703
|
+
/** sets the viewport (what it leaves out stays), its zoom and extent kept */
|
|
1704
|
+
"set-viewport": {
|
|
1705
|
+
payload: {
|
|
1706
|
+
x?: number;
|
|
1707
|
+
y?: number;
|
|
1708
|
+
zoom?: number;
|
|
1709
|
+
/** how long it animates, in milliseconds; default 0: at once */
|
|
1710
|
+
duration?: number | undefined;
|
|
1711
|
+
};
|
|
1712
|
+
result: Viewport;
|
|
1713
|
+
};
|
|
1714
|
+
/** pans by a screen offset, in pixels */
|
|
1715
|
+
"pan-by": {
|
|
1716
|
+
payload: {
|
|
1717
|
+
x: number;
|
|
1718
|
+
y: number;
|
|
1719
|
+
};
|
|
1720
|
+
result: Viewport;
|
|
1721
|
+
};
|
|
1722
|
+
/** zooms in by a step around a point; refused at the greatest zoom */
|
|
1723
|
+
"zoom-in": {
|
|
1724
|
+
payload: ZoomStepPayload;
|
|
1725
|
+
result: Viewport;
|
|
1726
|
+
};
|
|
1727
|
+
/** zooms out by a step around a point; refused at the least zoom */
|
|
1728
|
+
"zoom-out": {
|
|
1729
|
+
payload: ZoomStepPayload;
|
|
1730
|
+
result: Viewport;
|
|
1731
|
+
};
|
|
1732
|
+
/** zooms to a zoom around a point (default the root's centre) */
|
|
1733
|
+
"zoom-to": {
|
|
1734
|
+
payload: {
|
|
1735
|
+
zoom: number;
|
|
1736
|
+
around?: XY | undefined;
|
|
1737
|
+
/** how long it animates, in milliseconds; default 0: at once */
|
|
1738
|
+
duration?: number | undefined;
|
|
1739
|
+
};
|
|
1740
|
+
result: Viewport;
|
|
1741
|
+
};
|
|
1742
|
+
/** fits the nodes (or some) in the root; refused while none is measured or the root has no size */
|
|
1743
|
+
"fit-view": {
|
|
1744
|
+
payload: FitViewPayload;
|
|
1745
|
+
result: Viewport;
|
|
1746
|
+
};
|
|
1747
|
+
/** centres a flow point in the root (at a zoom) */
|
|
1748
|
+
"center-on": {
|
|
1749
|
+
payload: {
|
|
1750
|
+
x: number;
|
|
1751
|
+
y: number;
|
|
1752
|
+
zoom?: number | undefined;
|
|
1753
|
+
/** how long it animates, in milliseconds; default 0: at once */
|
|
1754
|
+
duration?: number | undefined;
|
|
1755
|
+
};
|
|
1756
|
+
result: Viewport;
|
|
1757
|
+
};
|
|
1758
|
+
/** gives DOM focus to a node's element, panning it into view */
|
|
1759
|
+
"focus-node": {
|
|
1760
|
+
payload: {
|
|
1761
|
+
nodeId: string;
|
|
1762
|
+
};
|
|
1763
|
+
result: {
|
|
1764
|
+
nodeId: string;
|
|
1765
|
+
};
|
|
1766
|
+
};
|
|
1767
|
+
/**
|
|
1768
|
+
* lets the gestures and keys change the flow, or not: all of them (`interactive`) or one kind
|
|
1769
|
+
* (`drag`, `connect`, `select`, `reconnect`), the switches left out kept (the Controls' lock);
|
|
1770
|
+
* pan and zoom stay. A switch turned off cancels the gesture under way. Its result is every
|
|
1771
|
+
* switch
|
|
1772
|
+
*/
|
|
1773
|
+
"set-interactive": {
|
|
1774
|
+
payload: InteractivityPayload;
|
|
1775
|
+
result: Interactivity;
|
|
1776
|
+
};
|
|
1777
|
+
/**
|
|
1778
|
+
* cancels the gesture under way (what Escape does) and stops a viewport animation where it is;
|
|
1779
|
+
* refused when there is neither
|
|
1780
|
+
*/
|
|
1781
|
+
"cancel-gesture": {
|
|
1782
|
+
payload: NoPayload;
|
|
1783
|
+
result: NoPayload;
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
type EngineActionKey = keyof EngineActionMap;
|
|
1787
|
+
type EngineActionPayload<K extends EngineActionKey> = EngineActionMap[K]["payload"];
|
|
1788
|
+
type EngineActionResult<K extends EngineActionKey> = EngineActionMap[K]["result"];
|
|
1789
|
+
/**
|
|
1790
|
+
* A node as the engine knows it on screen (`internal-node-by`, what `useInternalNode` gives): the
|
|
1791
|
+
* document's node, its absolute place and box, whether its size is known, its z-index and its
|
|
1792
|
+
* registered handles.
|
|
1793
|
+
*/
|
|
1794
|
+
interface InternalNode<T extends FlowTypes = AnyTypes> {
|
|
1795
|
+
readonly id: string;
|
|
1796
|
+
/** the document's node */
|
|
1797
|
+
readonly node: FlowNode<T>;
|
|
1798
|
+
/** its position in absolute flow coordinates: its parent's box's top-left corner plus its own (each origin applied) */
|
|
1799
|
+
readonly absolutePosition: XY;
|
|
1800
|
+
/** its box in absolute flow coordinates, `nodeOrigin` applied, size 0 until known (`node-rect-by`) */
|
|
1801
|
+
readonly rect: Rect;
|
|
1802
|
+
/** its size is measured, or given by the document (`node-measured`; an initial size is not) */
|
|
1803
|
+
readonly measured: boolean;
|
|
1804
|
+
/** its structural `z-index` (`node-z-index-by`) */
|
|
1805
|
+
readonly zIndex: number;
|
|
1806
|
+
/** its registered handles, with their centres and bounds (`handles-by`) */
|
|
1807
|
+
readonly handles: readonly FlowHandle[];
|
|
1808
|
+
}
|
|
1809
|
+
/** What `engine.get(key, payload)` reads: facts of this flow on screen. */
|
|
1810
|
+
interface EngineGetMap<T extends FlowTypes = AnyTypes> {
|
|
1811
|
+
/** the viewport */
|
|
1812
|
+
viewport: {
|
|
1813
|
+
payload: NoPayload;
|
|
1814
|
+
result: Viewport;
|
|
1815
|
+
};
|
|
1816
|
+
/** the root's size, in pixels */
|
|
1817
|
+
"root-size": {
|
|
1818
|
+
payload: NoPayload;
|
|
1819
|
+
result: {
|
|
1820
|
+
readonly width: number;
|
|
1821
|
+
readonly height: number;
|
|
1822
|
+
};
|
|
1823
|
+
};
|
|
1824
|
+
/**
|
|
1825
|
+
* an edge's path, label point and ends (D9), once both its nodes have a size; a type that is
|
|
1826
|
+
* not built in gets the bezier path (its own primitive may draw another from the ends)
|
|
1827
|
+
*/
|
|
1828
|
+
"edge-path-by": {
|
|
1829
|
+
payload: {
|
|
1830
|
+
edgeId: string;
|
|
1831
|
+
};
|
|
1832
|
+
result: EdgePath | undefined;
|
|
1833
|
+
};
|
|
1834
|
+
/** a node's box in absolute flow coordinates (size 0 until measured or given) */
|
|
1835
|
+
"node-rect-by": {
|
|
1836
|
+
payload: {
|
|
1837
|
+
nodeId: string;
|
|
1838
|
+
};
|
|
1839
|
+
result: Rect | undefined;
|
|
1840
|
+
};
|
|
1841
|
+
/** the box of the nodes (or some), with their measured sizes; none without a node */
|
|
1842
|
+
"nodes-bounds": {
|
|
1843
|
+
payload: {
|
|
1844
|
+
nodeIds?: string[] | undefined;
|
|
1845
|
+
};
|
|
1846
|
+
result: Rect | undefined;
|
|
1847
|
+
};
|
|
1848
|
+
/**
|
|
1849
|
+
* the viewport that frames a flow rectangle in the root, as `fit-view` would set it (padding,
|
|
1850
|
+
* zoom limits and translate extent kept); undefined while the root has no size
|
|
1851
|
+
*/
|
|
1852
|
+
"viewport-for-bounds": {
|
|
1853
|
+
payload: ViewportForBoundsPayload;
|
|
1854
|
+
result: Viewport | undefined;
|
|
1855
|
+
};
|
|
1856
|
+
/**
|
|
1857
|
+
* the nodes whose box (measured or given) shares some area with a node's box or a rectangle
|
|
1858
|
+
* (`partial: false`: lies wholly inside it), in the document's order; hidden nodes, nodes of
|
|
1859
|
+
* unknown size and the node itself are left out
|
|
1860
|
+
*/
|
|
1861
|
+
"intersecting-nodes": {
|
|
1862
|
+
payload: IntersectingNodesPayload;
|
|
1863
|
+
result: readonly FlowNode<T>[];
|
|
1864
|
+
};
|
|
1865
|
+
/** a client point (a pointer's `clientX`, `clientY`) as a flow point */
|
|
1866
|
+
"screen-to-flow": {
|
|
1867
|
+
payload: XY;
|
|
1868
|
+
result: XY;
|
|
1869
|
+
};
|
|
1870
|
+
/** a flow point as a client point */
|
|
1871
|
+
"flow-to-screen": {
|
|
1872
|
+
payload: XY;
|
|
1873
|
+
result: XY;
|
|
1874
|
+
};
|
|
1875
|
+
/** the nodes in view, and those not measured yet (so they render and get measured) */
|
|
1876
|
+
"visible-nodes": {
|
|
1877
|
+
payload: NoPayload;
|
|
1878
|
+
result: readonly FlowNode<T>[];
|
|
1879
|
+
};
|
|
1880
|
+
/** the edges whose ends' box is in view */
|
|
1881
|
+
"visible-edges": {
|
|
1882
|
+
payload: NoPayload;
|
|
1883
|
+
result: readonly FlowEdge<T>[];
|
|
1884
|
+
};
|
|
1885
|
+
/**
|
|
1886
|
+
* the edges to draw, in drawing order: those shown whose nodes have a size (with
|
|
1887
|
+
* `onlyRenderVisible`, those in view), by their stack value (`zIndexMode`: `zIndex`, a selected
|
|
1888
|
+
* one raised with `elevateEdgesOnSelect`, in `"auto"` at least its ends' when one is a child),
|
|
1889
|
+
* the document's order among equals
|
|
1890
|
+
*/
|
|
1891
|
+
"drawn-edges": {
|
|
1892
|
+
payload: NoPayload;
|
|
1893
|
+
result: readonly FlowEdge<T>[];
|
|
1894
|
+
};
|
|
1895
|
+
/**
|
|
1896
|
+
* the levels to draw, lowest first: one (today's DOM, the edges below the nodes) unless an
|
|
1897
|
+
* edge's stack value (`zIndexMode`) is above the lowest shown node's; then each level's edges
|
|
1898
|
+
* go in their own layer at its `zIndex`, between the nodes below and above them
|
|
1899
|
+
*/
|
|
1900
|
+
"render-layers": {
|
|
1901
|
+
payload: NoPayload;
|
|
1902
|
+
result: readonly RenderLayer[];
|
|
1903
|
+
};
|
|
1904
|
+
/**
|
|
1905
|
+
* a node's structural `z-index`: its stack value (`zIndexMode`: its `zIndex`, a selected one
|
|
1906
|
+
* raised with `elevateNodesOnSelect`, always above its parent's) with one render level; with
|
|
1907
|
+
* several, its rank among the layers (negative), below what the app draws after them
|
|
1908
|
+
*/
|
|
1909
|
+
"node-z-index-by": {
|
|
1910
|
+
payload: {
|
|
1911
|
+
nodeId: string;
|
|
1912
|
+
};
|
|
1913
|
+
result: number;
|
|
1914
|
+
};
|
|
1915
|
+
/** a node on screen: its node, absolute place and box, size known, z-index and handles */
|
|
1916
|
+
"internal-node-by": {
|
|
1917
|
+
payload: {
|
|
1918
|
+
nodeId: string;
|
|
1919
|
+
};
|
|
1920
|
+
result: InternalNode<T> | undefined;
|
|
1921
|
+
};
|
|
1922
|
+
/** a node's registered handles, with their centres */
|
|
1923
|
+
"handles-by": {
|
|
1924
|
+
payload: {
|
|
1925
|
+
nodeId: string;
|
|
1926
|
+
};
|
|
1927
|
+
result: readonly FlowHandle[];
|
|
1928
|
+
};
|
|
1929
|
+
/** one tile of a background pattern at the current viewport */
|
|
1930
|
+
"background-pattern": {
|
|
1931
|
+
payload: BackgroundPatternPayload;
|
|
1932
|
+
result: BackgroundPattern;
|
|
1933
|
+
};
|
|
1934
|
+
/**
|
|
1935
|
+
* where a node's toolbar goes, outside the zoom: beside a node, or beside several nodes'
|
|
1936
|
+
* bounds (`nodeIds`); undefined until one of them has a size
|
|
1937
|
+
*/
|
|
1938
|
+
"node-toolbar-by": {
|
|
1939
|
+
payload: NodeToolbarPayload;
|
|
1940
|
+
result: NodeToolbarPosition | undefined;
|
|
1941
|
+
};
|
|
1942
|
+
/**
|
|
1943
|
+
* where an edge's toolbar goes, outside the zoom: at its label point or one of its ends, until
|
|
1944
|
+
* its path is drawn (undefined before)
|
|
1945
|
+
*/
|
|
1946
|
+
"edge-toolbar-by": {
|
|
1947
|
+
payload: EdgeToolbarPayload;
|
|
1948
|
+
result: EdgeToolbarPosition | undefined;
|
|
1949
|
+
};
|
|
1950
|
+
/** the selection box being drawn, or null (`selection()`) */
|
|
1951
|
+
"selection-box": {
|
|
1952
|
+
payload: NoPayload;
|
|
1953
|
+
result: SelectionBox | null;
|
|
1954
|
+
};
|
|
1955
|
+
/**
|
|
1956
|
+
* the flow-space bounds of the selected nodes, for the rectangle around them (the
|
|
1957
|
+
* `nodes-selection` part, placed in the viewport): while two or more are selected by a box
|
|
1958
|
+
* (`selection({ rect: "always" })`: by anything), until the selection changes otherwise; null
|
|
1959
|
+
* otherwise (and while a box is drawn) (`selection()`)
|
|
1960
|
+
*/
|
|
1961
|
+
"selection-rect": {
|
|
1962
|
+
payload: NoPayload;
|
|
1963
|
+
result: Rect | null;
|
|
1964
|
+
};
|
|
1965
|
+
/** the nodes being dragged (`drag()`) */
|
|
1966
|
+
"dragging-node-ids": {
|
|
1967
|
+
payload: NoPayload;
|
|
1968
|
+
result: readonly string[];
|
|
1969
|
+
};
|
|
1970
|
+
/** the connection being drawn, or null (`connection()`) */
|
|
1971
|
+
connection: {
|
|
1972
|
+
payload: NoPayload;
|
|
1973
|
+
result: Connection | null;
|
|
1974
|
+
};
|
|
1975
|
+
/** what a minimap of `width` × `height` pixels draws (`minimap()`) */
|
|
1976
|
+
"minimap-view": {
|
|
1977
|
+
payload: {
|
|
1978
|
+
width: number;
|
|
1979
|
+
height: number;
|
|
1980
|
+
};
|
|
1981
|
+
result: MinimapView;
|
|
1982
|
+
};
|
|
1983
|
+
/**
|
|
1984
|
+
* a client point on the minimap (the one under it, else the first) as a flow point; undefined
|
|
1985
|
+
* while no minimap has a size (`minimap()`)
|
|
1986
|
+
*/
|
|
1987
|
+
"minimap-point-to-flow": {
|
|
1988
|
+
payload: {
|
|
1989
|
+
client: XY;
|
|
1990
|
+
};
|
|
1991
|
+
result: XY | undefined;
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
type EngineGetKey = keyof EngineGetMap;
|
|
1995
|
+
type EngineGetPayload<K extends EngineGetKey> = EngineGetMap[K]["payload"];
|
|
1996
|
+
type EngineGetResult<T extends FlowTypes, K extends EngineGetKey> = EngineGetMap<T>[K]["result"];
|
|
1997
|
+
/** What `engine.is(key, payload)` asks: each question's payload. */
|
|
1998
|
+
interface EngineIsMap {
|
|
1999
|
+
/** the gestures and keys may change the flow (`set-interactive`) */
|
|
2000
|
+
interactive: NoPayload;
|
|
2001
|
+
/** the gestures and keys of a kind may change the flow (`interactive` and that kind's switch) */
|
|
2002
|
+
"interactive-by": {
|
|
2003
|
+
kind: InteractionKind;
|
|
2004
|
+
};
|
|
2005
|
+
/** the root has a size and the fit on init is done (the `ready` event came) */
|
|
2006
|
+
ready: NoPayload;
|
|
2007
|
+
/** the viewport is being panned by a drag or a pinch */
|
|
2008
|
+
panning: NoPayload;
|
|
2009
|
+
/** a node's size is measured, or given by the document (`width` and `height`; an initial one is not) */
|
|
2010
|
+
"node-measured": {
|
|
2011
|
+
nodeId: string;
|
|
2012
|
+
};
|
|
2013
|
+
/** a box selection is being drawn (`selection()`) */
|
|
2014
|
+
"box-selecting": NoPayload;
|
|
2015
|
+
/** nodes are being dragged (`drag()`) */
|
|
2016
|
+
dragging: NoPayload;
|
|
2017
|
+
/** a node is being dragged (`drag()`) */
|
|
2018
|
+
"node-dragging": {
|
|
2019
|
+
nodeId: string;
|
|
2020
|
+
};
|
|
2021
|
+
/** a node is being resized (`resize()`) */
|
|
2022
|
+
"node-resizing": {
|
|
2023
|
+
nodeId: string;
|
|
2024
|
+
};
|
|
2025
|
+
/** a node is being resized (`resize()`) */
|
|
2026
|
+
resizing: NoPayload;
|
|
2027
|
+
/** a connection is being drawn (`connection()`) */
|
|
2028
|
+
connecting: NoPayload;
|
|
2029
|
+
/** an edge's end is being moved (`reconnection()`) */
|
|
2030
|
+
"edge-reconnecting": {
|
|
2031
|
+
edgeId: string;
|
|
2032
|
+
};
|
|
2033
|
+
/**
|
|
2034
|
+
* a node takes DOM focus (`tabindex="0"`, `keyboard()`): shown, its `focusable` not false and
|
|
2035
|
+
* the `nodesFocusable` option on
|
|
2036
|
+
*/
|
|
2037
|
+
"node-focusable": {
|
|
2038
|
+
nodeId: string;
|
|
2039
|
+
};
|
|
2040
|
+
/**
|
|
2041
|
+
* an edge takes DOM focus (`tabindex="0"`, `keyboard()`): shown, its `focusable` not false and
|
|
2042
|
+
* the `edgesFocusable` option on
|
|
2043
|
+
*/
|
|
2044
|
+
"edge-focusable": {
|
|
2045
|
+
edgeId: string;
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
type EngineIsKey = keyof EngineIsMap;
|
|
2049
|
+
type EngineIsPayload<K extends EngineIsKey> = EngineIsMap[K];
|
|
2050
|
+
/** How an animation's share of time becomes its share of the way (0 → 0, 1 → 1). */
|
|
2051
|
+
type ViewportEasing = (t: number) => number;
|
|
2052
|
+
/** Which way the wheel pans with `panOnScroll`: both ways, or one axis only. */
|
|
2053
|
+
type PanOnScrollMode = "free" | "horizontal" | "vertical";
|
|
2054
|
+
/** Options of {@link createFlowEngine}. */
|
|
2055
|
+
interface FlowEngineOptions {
|
|
2056
|
+
/** the root element; an adapter may attach it later (`engine.adapter.attachRoot`) */
|
|
2057
|
+
root?: HTMLElement | undefined;
|
|
2058
|
+
/** the viewport it starts at; default `{ x: 0, y: 0, zoom: 1 }` */
|
|
2059
|
+
defaultViewport?: Viewport | undefined;
|
|
2060
|
+
/** the least zoom; default 0.5 */
|
|
2061
|
+
minZoom?: number | undefined;
|
|
2062
|
+
/** the greatest zoom; default 2 */
|
|
2063
|
+
maxZoom?: number | undefined;
|
|
2064
|
+
/** the flow rectangle the view stays inside; default none */
|
|
2065
|
+
translateExtent?: Rect | undefined;
|
|
2066
|
+
/**
|
|
2067
|
+
* a drag on the pane pans: `true` with the primary button (and a touch or a pen), or the mouse
|
|
2068
|
+
* buttons that pan (`[0]` primary, `[1]` middle, `[2]` right); default true
|
|
2069
|
+
*/
|
|
2070
|
+
panOnDrag?: boolean | readonly number[] | undefined;
|
|
2071
|
+
/**
|
|
2072
|
+
* the key that, held, makes a primary drag pan from anywhere (nodes included) and start no
|
|
2073
|
+
* other gesture (`KeyboardEvent.key`, or `.code`); null for none; default `" "` (Space)
|
|
2074
|
+
*/
|
|
2075
|
+
panActivationKey?: string | null | undefined;
|
|
2076
|
+
/** the wheel pans (Ctrl + wheel zooms); default false: the wheel zooms */
|
|
2077
|
+
panOnScroll?: boolean | undefined;
|
|
2078
|
+
/** which way the wheel pans with `panOnScroll`; default `"free"` */
|
|
2079
|
+
panOnScrollMode?: PanOnScrollMode | undefined;
|
|
2080
|
+
/** the factor of the wheel's pixels when it pans (`panOnScroll`); default 1 */
|
|
2081
|
+
panOnScrollSpeed?: number | undefined;
|
|
2082
|
+
/**
|
|
2083
|
+
* the key that, held, makes the wheel zoom while `panOnScroll` is on (`KeyboardEvent.key`;
|
|
2084
|
+
* `Meta`, `Control`, `Alt` and `Shift` read from the wheel event); null for none; default
|
|
2085
|
+
* `Meta` on Apple platforms and `Control` elsewhere (the root window's `navigator`)
|
|
2086
|
+
*/
|
|
2087
|
+
zoomActivationKey?: string | null | undefined;
|
|
2088
|
+
/** the wheel zooms around the pointer; default true */
|
|
2089
|
+
zoomOnScroll?: boolean | undefined;
|
|
2090
|
+
/** a two-finger pinch (and a trackpad's) zooms; default true */
|
|
2091
|
+
zoomOnPinch?: boolean | undefined;
|
|
2092
|
+
/** a double click on the pane zooms in; default true */
|
|
2093
|
+
zoomOnDoubleClick?: boolean | undefined;
|
|
2094
|
+
/** the factor of `zoom-in` and `zoom-out`; default 1.2 */
|
|
2095
|
+
zoomStep?: number | undefined;
|
|
2096
|
+
/** fits the nodes once their sizes are known, again once measured (`fit-view`'s options); default false */
|
|
2097
|
+
fitView?: boolean | FitViewPayload | undefined;
|
|
2098
|
+
/** whether gestures and keys may change the flow (`set-interactive`); default true */
|
|
2099
|
+
interactive?: boolean | undefined;
|
|
2100
|
+
/** adapters render only the nodes and edges in view; default false */
|
|
2101
|
+
onlyRenderVisible?: boolean | undefined;
|
|
2102
|
+
/** the shape of the built-in edge paths */
|
|
2103
|
+
pathOptions?: PathOptions | undefined;
|
|
2104
|
+
/**
|
|
2105
|
+
* the viewport pans while a drag, a connection, a reconnection, a selection box or a resize
|
|
2106
|
+
* has its pointer near the root's edge (`{ speed, margin }` tunes it; `{ node, connect,
|
|
2107
|
+
* selection, resize }` turn it off for one gesture); default true
|
|
2108
|
+
*/
|
|
2109
|
+
autoPan?: boolean | AutoPanOptions | undefined;
|
|
2110
|
+
/**
|
|
2111
|
+
* how far (in pixels) a press on the pane may move and still be a tap (a click: it clears the
|
|
2112
|
+
* selection, `pane-click`); default 3
|
|
2113
|
+
*/
|
|
2114
|
+
paneClickDistance?: number | undefined;
|
|
2115
|
+
/**
|
|
2116
|
+
* how far (in pixels) a press on a node, an edge or a handle may move and still be a tap (it
|
|
2117
|
+
* selects, `node-click`; with click-to-connect a handle's drag starts past it); default 3
|
|
2118
|
+
*/
|
|
2119
|
+
nodeClickDistance?: number | undefined;
|
|
2120
|
+
/**
|
|
2121
|
+
* the wheel over the flow never scrolls the page, even when neither `zoomOnScroll` nor
|
|
2122
|
+
* `panOnScroll` uses it (a `data-flow-no-wheel` element and the controls keep theirs);
|
|
2123
|
+
* default true
|
|
2124
|
+
*/
|
|
2125
|
+
preventScrolling?: boolean | undefined;
|
|
2126
|
+
/** nodes take focus (with `keyboard()`; a node's `focusable: false` still wins); default true */
|
|
2127
|
+
nodesFocusable?: boolean | undefined;
|
|
2128
|
+
/** edges take focus (with `keyboard()`; an edge's `focusable: false` still wins); default true */
|
|
2129
|
+
edgesFocusable?: boolean | undefined;
|
|
2130
|
+
/** how an animated viewport action (its `duration`) eases; default a smooth ease in and out */
|
|
2131
|
+
easing?: ViewportEasing | undefined;
|
|
2132
|
+
/**
|
|
2133
|
+
* the point of a node's box its `position` stands at, as shares of its size (`{ x: 0.5, y: 0.5 }`:
|
|
2134
|
+
* its centre), for the nodes on the flow (a child's position is its box's top-left corner in its
|
|
2135
|
+
* parent's); default `{ x: 0, y: 0 }`: the top-left corner
|
|
2136
|
+
*/
|
|
2137
|
+
nodeOrigin?: XY | undefined;
|
|
2138
|
+
/** the flow rectangle every node's box stays inside when dragged, moved by keys or resized */
|
|
2139
|
+
nodeExtent?: Rect | undefined;
|
|
2140
|
+
/** a selected node, and its children with it, is drawn above the others; default true */
|
|
2141
|
+
elevateNodesOnSelect?: boolean | undefined;
|
|
2142
|
+
/**
|
|
2143
|
+
* a selected edge is drawn above the other edges (in `"auto"`, above the nodes too); default
|
|
2144
|
+
* false in `"basic"`, true in `"auto"`
|
|
2145
|
+
*/
|
|
2146
|
+
elevateEdgesOnSelect?: boolean | undefined;
|
|
2147
|
+
/**
|
|
2148
|
+
* how nodes and edges stack (`render-layers`): `"basic"` edges always below the nodes, `"auto"`
|
|
2149
|
+
* an edge may stand above nodes (a selected one, one of a child, a higher `zIndex`), `"manual"`
|
|
2150
|
+
* only the `zIndex` values; default `"auto"`
|
|
2151
|
+
*/
|
|
2152
|
+
zIndexMode?: ZIndexMode | undefined;
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* One flow on screen. Every member is one verb, as on the model, and bound: `run` a screen
|
|
2156
|
+
* action, `can` / `check` it, `get` a fact of the screen, `is` a yes/no question; `subscribe`
|
|
2157
|
+
* listens to what happens on screen (D12: the events an app announces); `destroy` releases it.
|
|
2158
|
+
* `adapter` is what only an adapter calls.
|
|
2159
|
+
*/
|
|
2160
|
+
interface FlowEngine<T extends FlowTypes = AnyTypes, F extends FlowFeatures = readonly []> {
|
|
2161
|
+
run<K extends EngineActionKeyOf<F>>(action: K, ...payload: QueryArgs<EngineActionPayload<K>>): CommandResult<EngineActionResult<K>>;
|
|
2162
|
+
can<K extends EngineActionKeyOf<F>>(action: K, ...payload: QueryArgs<EngineActionPayload<K>>): boolean;
|
|
2163
|
+
check<K extends EngineActionKeyOf<F>>(action: K, ...payload: QueryArgs<EngineActionPayload<K>>): CommandResult<EngineActionResult<K>>;
|
|
2164
|
+
get<K extends EngineGetKeyOf<F>>(key: K, ...payload: QueryArgs<EngineGetPayload<K>>): EngineGetResult<T, K>;
|
|
2165
|
+
is<K extends EngineIsKeyOf<F>>(key: K, ...payload: QueryArgs<EngineIsPayload<K>>): boolean;
|
|
2166
|
+
/** listens to what happens on screen (a drag's drop, a connection, the viewport); returns its remover */
|
|
2167
|
+
subscribe(listener: (event: FlowEngineEvent) => void): () => void;
|
|
2168
|
+
/** releases every listener and element; no command runs afterwards */
|
|
2169
|
+
destroy(): void;
|
|
2170
|
+
/** what only an adapter calls */
|
|
2171
|
+
readonly adapter: FlowEngineAdapter;
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Creates the engine of one flow on screen, over its model
|
|
2175
|
+
* (`createFlowEngine<Types, typeof features>(model, options)`). Give it the root element now or
|
|
2176
|
+
* attach it later (`engine.adapter.attachRoot`, what an adapter does); call `destroy()` when the
|
|
2177
|
+
* flow leaves the screen.
|
|
2178
|
+
*/
|
|
2179
|
+
declare function createFlowEngine<T extends FlowTypes = AnyTypes, const F extends FlowFeatures = readonly []>(model: FlowModel<T, F>, options?: FlowEngineOptions): FlowEngine<T, F>;
|
|
2180
|
+
/** A handle as its primitive registers it (D8). */
|
|
2181
|
+
interface HandleRegistration {
|
|
2182
|
+
/** the node it belongs to */
|
|
2183
|
+
readonly nodeId: string;
|
|
2184
|
+
/** its id among the node's handles of its type (none: the node's default handle) */
|
|
2185
|
+
readonly handleId?: string | undefined;
|
|
2186
|
+
/** whether edges start (`source`) or end (`target`) at it */
|
|
2187
|
+
readonly type: HandleType;
|
|
2188
|
+
/** the side of the node it sits on: the direction an edge leaves or enters by */
|
|
2189
|
+
readonly side: HandleSide;
|
|
2190
|
+
/** whether a connection may start or end at it; default true */
|
|
2191
|
+
readonly connectable?: boolean | undefined;
|
|
2192
|
+
/** whether a connection may start at it (a drag, a tap, a key); default true */
|
|
2193
|
+
readonly connectableStart?: boolean | undefined;
|
|
2194
|
+
/** whether a connection may end at it (be its target); default true */
|
|
2195
|
+
readonly connectableEnd?: boolean | undefined;
|
|
2196
|
+
}
|
|
2197
|
+
/** A registered handle and where it is. */
|
|
2198
|
+
interface FlowHandle {
|
|
2199
|
+
readonly nodeId: string;
|
|
2200
|
+
readonly handleId: string | undefined;
|
|
2201
|
+
readonly type: HandleType;
|
|
2202
|
+
readonly side: HandleSide;
|
|
2203
|
+
readonly connectable: boolean;
|
|
2204
|
+
/** a connection may start at it (and it is `connectable`) */
|
|
2205
|
+
readonly connectableStart: boolean;
|
|
2206
|
+
/** a connection may end at it (and it is `connectable`) */
|
|
2207
|
+
readonly connectableEnd: boolean;
|
|
2208
|
+
/** its centre in absolute flow coordinates, once it and its node are measured */
|
|
2209
|
+
readonly center: XY | undefined;
|
|
2210
|
+
/** its box relative to its node's top-left corner, in flow units, once measured */
|
|
2211
|
+
readonly bounds: Rect | undefined;
|
|
2212
|
+
}
|
|
2213
|
+
/** What a press, a key, the wheel or focus hit in the flow, read from the part attributes. */
|
|
2214
|
+
interface PressTarget {
|
|
2215
|
+
/**
|
|
2216
|
+
* - `pane`: the flow's background (the root, the viewport, the background, the nodes' and
|
|
2217
|
+
* edges' layers);
|
|
2218
|
+
* - `node`, `edge`, `handle`, `resize-handle`, `minimap`: that part (or an element inside it);
|
|
2219
|
+
* a reconnect anchor is its edge's, with its `end`;
|
|
2220
|
+
* - `nodes-selection`: the rectangle around the selected nodes (`selection-rect`): a press
|
|
2221
|
+
* drags the selection, a context menu is the selection's;
|
|
2222
|
+
* - `other`: a part with its own behaviour (the controls, a toolbar, a panel) or a control
|
|
2223
|
+
* inside a node (a field, a button, `data-flow-no-gesture`): the flow leaves it alone
|
|
2224
|
+
*/
|
|
2225
|
+
readonly kind: "pane" | "node" | "edge" | "handle" | "resize-handle" | "minimap" | "nodes-selection" | "other";
|
|
2226
|
+
/** the part's element */
|
|
2227
|
+
readonly element: Element | undefined;
|
|
2228
|
+
/** the node it is in (a node, a handle, a resize handle) */
|
|
2229
|
+
readonly nodeId?: string | undefined;
|
|
2230
|
+
/** the edge (an edge, its path or its label) */
|
|
2231
|
+
readonly edgeId?: string | undefined;
|
|
2232
|
+
/** the handle */
|
|
2233
|
+
readonly handle?: FlowHandle | undefined;
|
|
2234
|
+
/** a resize handle's corner or side (`data-position`: `top-left`, `top`, …) */
|
|
2235
|
+
readonly position?: string | undefined;
|
|
2236
|
+
/** a resize handle's own direction (`data-direction`), over its resizer's */
|
|
2237
|
+
readonly direction?: ResizeHandleDirection | undefined;
|
|
2238
|
+
/** a reconnect anchor's end of its edge (`data-end`) */
|
|
2239
|
+
readonly end?: "source" | "target" | undefined;
|
|
2240
|
+
/**
|
|
2241
|
+
* a press on a node that holds a drag handle (`data-flow-drag-handle`), outside it: the node
|
|
2242
|
+
* is not dragged from there
|
|
2243
|
+
*/
|
|
2244
|
+
readonly outsideDragHandle?: boolean | undefined;
|
|
2245
|
+
}
|
|
2246
|
+
/** What changed in the view, for an adapter to re-render only what depends on it. */
|
|
2247
|
+
interface ViewChange {
|
|
2248
|
+
/** the viewport moved or zoomed (the background, the minimap, toolbars) */
|
|
2249
|
+
readonly viewport: boolean;
|
|
2250
|
+
/** a node or handle was measured (edges, the minimap, toolbars) */
|
|
2251
|
+
readonly measured: boolean;
|
|
2252
|
+
/** a gesture's state changed (the connection line, the selection box, state attributes) */
|
|
2253
|
+
readonly gesture: boolean;
|
|
2254
|
+
}
|
|
2255
|
+
/** The payload each part's attributes take (`engine.adapter.attributes(part, payload)`). */
|
|
2256
|
+
interface PartPayloadMap {
|
|
2257
|
+
node: {
|
|
2258
|
+
nodeId: string;
|
|
2259
|
+
};
|
|
2260
|
+
edge: {
|
|
2261
|
+
edgeId: string;
|
|
2262
|
+
};
|
|
2263
|
+
"edge-path": {
|
|
2264
|
+
edgeId: string;
|
|
2265
|
+
};
|
|
2266
|
+
"edge-label": {
|
|
2267
|
+
edgeId: string;
|
|
2268
|
+
};
|
|
2269
|
+
"reconnect-anchor": {
|
|
2270
|
+
edgeId: string;
|
|
2271
|
+
end: "source" | "target";
|
|
2272
|
+
};
|
|
2273
|
+
handle: HandleRegistration;
|
|
2274
|
+
/**
|
|
2275
|
+
* a resize handle: its corner or side, its own direction over its resizer's (#40,
|
|
2276
|
+
* `data-direction`), how it is drawn (#40, `data-variant`: `line` on a side only)
|
|
2277
|
+
*/
|
|
2278
|
+
"resize-handle": {
|
|
2279
|
+
nodeId: string;
|
|
2280
|
+
position: string;
|
|
2281
|
+
direction?: ResizeHandleDirection | undefined;
|
|
2282
|
+
variant?: ResizeHandleVariant | undefined;
|
|
2283
|
+
};
|
|
2284
|
+
resizer: {
|
|
2285
|
+
nodeId: string;
|
|
2286
|
+
};
|
|
2287
|
+
"minimap-node": {
|
|
2288
|
+
nodeId: string;
|
|
2289
|
+
};
|
|
2290
|
+
/** one render level's edges layer (`render-layers`) */
|
|
2291
|
+
"edges-layer": {
|
|
2292
|
+
level: number;
|
|
2293
|
+
};
|
|
2294
|
+
/** a node's toolbar (`nodeId`), several nodes' (neither: no id) or an edge's (`edgeId`) */
|
|
2295
|
+
toolbar: {
|
|
2296
|
+
nodeId?: string | undefined;
|
|
2297
|
+
edgeId?: string | undefined;
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
/** What only an adapter calls on an engine. */
|
|
2301
|
+
interface FlowEngineAdapter {
|
|
2302
|
+
/** the model this engine draws */
|
|
2303
|
+
readonly model: FlowModel;
|
|
2304
|
+
/** the adapter's rendering settings, from the engine's options */
|
|
2305
|
+
readonly settings: {
|
|
2306
|
+
/** render only the nodes and edges in view (`visible-nodes`, `visible-edges`) */
|
|
2307
|
+
readonly onlyRenderVisible: boolean;
|
|
2308
|
+
};
|
|
2309
|
+
/**
|
|
2310
|
+
* the engine's options changed (a root prop: `minZoom`, `panOnDrag`, `translateExtent`,
|
|
2311
|
+
* `pathOptions`, `interactive`, `autoPan`, `panActivationKey`, `zoomActivationKey`, `easing`,
|
|
2312
|
+
* …): they apply from now on, a gesture under way included;
|
|
2313
|
+
* `root`, `defaultViewport` and `fitView` are creation options and are ignored here
|
|
2314
|
+
*/
|
|
2315
|
+
setOptions(options: Partial<FlowEngineOptions>): void;
|
|
2316
|
+
/**
|
|
2317
|
+
* attaches the root element (`Flow.Root`): the engine listens to its events and sets its
|
|
2318
|
+
* `touch-action: none`; another replaces it
|
|
2319
|
+
*/
|
|
2320
|
+
attachRoot(element: HTMLElement): void;
|
|
2321
|
+
/** detaches the root, cancelling a gesture under way */
|
|
2322
|
+
detachRoot(): void;
|
|
2323
|
+
/**
|
|
2324
|
+
* attaches (or, with `null`, detaches) the viewport element: the engine writes its transform
|
|
2325
|
+
* (`transform`, `transform-origin`) directly, and the framework never renders it (D4)
|
|
2326
|
+
*/
|
|
2327
|
+
attachViewport(element: HTMLElement | SVGElement | null): void;
|
|
2328
|
+
/** registers (or unregisters) a node's element: the engine measures it (`ResizeObserver`) */
|
|
2329
|
+
registerNode(nodeId: string, element: HTMLElement | null): void;
|
|
2330
|
+
/** registers (or, with `null`, unregisters) a handle's element (D8): the engine measures its centre */
|
|
2331
|
+
registerHandle(handle: HandleRegistration, element: Element | null): void;
|
|
2332
|
+
/** options a part's primitive takes (`resizer`: `minWidth`, …); `null` drops them */
|
|
2333
|
+
setPartOptions(part: string, id: string, options: Readonly<Record<string, unknown>> | null): void;
|
|
2334
|
+
/** a part's attributes (D11): `data-flow-part`, `data-flow-id` and its state */
|
|
2335
|
+
attributes<P extends string>(part: P, ...payload: P extends keyof PartPayloadMap ? [payload: PartPayloadMap[P]] : [payload?: Readonly<Record<string, unknown>>]): PartAttributes;
|
|
2336
|
+
/**
|
|
2337
|
+
* gives focus back to a part that was remounted (an edge moved to another render level's
|
|
2338
|
+
* layer): when `element` is the part (`data-flow-part` and `data-flow-id`) that last had focus
|
|
2339
|
+
* in the flow and focus was lost (its document's active element is its body, or none), it is
|
|
2340
|
+
* focused again, without scrolling
|
|
2341
|
+
*/
|
|
2342
|
+
refocus(element: Element): void;
|
|
2343
|
+
/** calls `listener` when the view changed (not the model: adapters subscribe to it); returns its remover */
|
|
2344
|
+
subscribe(listener: (change: ViewChange) => void): () => void;
|
|
2345
|
+
/** a number that changes whenever the view changes */
|
|
2346
|
+
getSnapshot(): number;
|
|
2347
|
+
}
|
|
2348
|
+
/** A model's features, composed: what the model, its commands and its engines call. */
|
|
2349
|
+
interface ComposedFeatures {
|
|
2350
|
+
/** the features, as installed (fixed: the app's array changing later changes nothing) */
|
|
2351
|
+
readonly list: readonly AnyFlowFeature[];
|
|
2352
|
+
/** the installed features' names */
|
|
2353
|
+
readonly names: ReadonlySet<FeatureName>;
|
|
2354
|
+
/** their commands, by name */
|
|
2355
|
+
readonly commands: ReadonlyMap<string, CommandDefinition>;
|
|
2356
|
+
/** their `get` keys */
|
|
2357
|
+
readonly get: ReadonlyMap<string, (reader: FlowReader, payload: unknown) => unknown>;
|
|
2358
|
+
/** their `is` keys */
|
|
2359
|
+
readonly is: ReadonlyMap<string, (reader: FlowReader, payload: unknown) => boolean>;
|
|
2360
|
+
/** the feature that owns `key` of kind `kind` when it is not installed */
|
|
2361
|
+
missing(kind: FeatureKeyKind, key: string): FeatureName | undefined;
|
|
2362
|
+
/** the fields of `object` that belong to a feature not installed, as issues at `path` */
|
|
2363
|
+
missingFields(kind: "nodeFields" | "edgeFields", object: object, path: string): ValidationIssue[];
|
|
2364
|
+
documentIssues(reader: FlowReader): ValidationIssue[];
|
|
2365
|
+
checkNode(draft: Draft, node: FlowNode, path: string): Failure | undefined;
|
|
2366
|
+
checkEdge(draft: Draft, edge: FlowEdge, path: string): Failure | undefined;
|
|
2367
|
+
removing(draft: Draft, nodeIds: Set<string>): void;
|
|
2368
|
+
constrainPosition(draft: Draft, node: FlowNode, position: XY): XY;
|
|
2369
|
+
nodeChanged(draft: Draft, nodeId: string): void;
|
|
2370
|
+
flagsChanged(draft: Draft, kind: "node" | "edge", id: string): void;
|
|
2371
|
+
absolutePosition(reader: FlowReader, node: FlowNode): XY;
|
|
2372
|
+
}
|
|
2373
|
+
/** What a reducer can use besides the draft. */
|
|
2374
|
+
interface ReduceContext {
|
|
2375
|
+
readonly draft: Draft;
|
|
2376
|
+
/** the model's installed features, composed: the contribution points a reducer calls */
|
|
2377
|
+
readonly features: ComposedFeatures;
|
|
2378
|
+
/** runs one command of a batch on the same draft, through the middleware chain */
|
|
2379
|
+
runInBatch(command: string, payload: unknown, path: string): CommandResult<unknown>;
|
|
2380
|
+
}
|
|
2381
|
+
/** A command: its description, schemas and reducer. */
|
|
2382
|
+
interface CommandDefinition<C extends CommandName = CommandName> {
|
|
2383
|
+
readonly name: C;
|
|
2384
|
+
readonly description: string;
|
|
2385
|
+
readonly payloadSchema: JsonSchema;
|
|
2386
|
+
readonly resultSchema: JsonSchema;
|
|
2387
|
+
/** whether it may run as a transient step of a continuous gesture */
|
|
2388
|
+
readonly transient: boolean;
|
|
2389
|
+
/**
|
|
2390
|
+
* applies the command to the draft, or returns why it cannot (a method: a list of commands
|
|
2391
|
+
* holds each one's own payload type)
|
|
2392
|
+
*/
|
|
2393
|
+
reduce(payload: PayloadOf<AnyTypes, C>, context: ReduceContext): CommandResult<ResultOf<AnyTypes, C>>;
|
|
2394
|
+
}
|
|
2395
|
+
/** Why a command did not apply. */
|
|
2396
|
+
type Failure = {
|
|
2397
|
+
readonly ok: false;
|
|
2398
|
+
readonly error: CommandError;
|
|
2399
|
+
};
|
|
2400
|
+
/** What a feature reads of a document: its nodes and edges, in order and by id. */
|
|
2401
|
+
interface FlowReader {
|
|
2402
|
+
nodes(): readonly FlowNode[];
|
|
2403
|
+
edges(): readonly FlowEdge[];
|
|
2404
|
+
node(id: string): FlowNode | undefined;
|
|
2405
|
+
edge(id: string): FlowEdge | undefined;
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* The model as a feature's engine side uses it (fragiola/flow#3): the verbs, typed loosely, since
|
|
2409
|
+
* a feature works on a model of any registry.
|
|
2410
|
+
*/
|
|
2411
|
+
interface FeatureModel {
|
|
2412
|
+
run(command: CommandName, payload: object, options?: RunOptions): CommandResult<unknown>;
|
|
2413
|
+
can(command: CommandName, payload: object, options?: RunOptions): boolean;
|
|
2414
|
+
check(command: CommandName, payload: object, options?: RunOptions): CommandResult<unknown>;
|
|
2415
|
+
get(key: ModelGetKey, payload?: object): unknown;
|
|
2416
|
+
is(key: ModelIsKey, payload: object): boolean;
|
|
2417
|
+
subscribe(listener: CommandListener): () => void;
|
|
2418
|
+
}
|
|
2419
|
+
/** What the engine tells a gesture: the pointer moved, was released, or the gesture ends. */
|
|
2420
|
+
interface FeatureGesture {
|
|
2421
|
+
/** the pointer moved (its coalesced moves arrive one by one) */
|
|
2422
|
+
move(event: PointerEvent): void;
|
|
2423
|
+
/** the pointer was released: the gesture commits what it did */
|
|
2424
|
+
end(event: PointerEvent): void;
|
|
2425
|
+
/** the gesture ends without committing (Escape, `pointercancel`, a lost capture, a detach) */
|
|
2426
|
+
cancel(): void;
|
|
2427
|
+
/**
|
|
2428
|
+
* whether the gesture has started doing something (a drag past its threshold): a press whose
|
|
2429
|
+
* gesture is not active and that barely moved is a tap (`FeatureEngine.tap`)
|
|
2430
|
+
*/
|
|
2431
|
+
active?(): boolean;
|
|
2432
|
+
/**
|
|
2433
|
+
* a key while the gesture goes on without a press (one a tap or a key started): `true` takes
|
|
2434
|
+
* it (its default is prevented, no feature sees it); the gesture is over once `active()`
|
|
2435
|
+
* answers false (a key connected it)
|
|
2436
|
+
*/
|
|
2437
|
+
keydown?(event: KeyboardEvent): boolean;
|
|
2438
|
+
/**
|
|
2439
|
+
* the gesture follows the pointer in the flow (a drag, a connection, a box, a resize): while it
|
|
2440
|
+
* is active and its pointer nears the root's edge, the engine pans the viewport every frame
|
|
2441
|
+
* (the `autoPan` option) and calls `move` again with the pointer's last event, so `move` must
|
|
2442
|
+
* read the flow point from the client point each time (`host.toFlow`), never from a delta
|
|
2443
|
+
* divided by the zoom; its kind (`"node"`, `"connect"`, `"selection"`, `"resize"`) lets the
|
|
2444
|
+
* app turn it off for that gesture alone (`autoPan: { connect: false }`)
|
|
2445
|
+
*/
|
|
2446
|
+
readonly autoPan?: boolean | AutoPanGesture | undefined;
|
|
2447
|
+
/**
|
|
2448
|
+
* the `set-interactive` switch the gesture belongs to (`"drag"`, `"connect"`, `"select"`,
|
|
2449
|
+
* `"reconnect"`): turning it off cancels the gesture; one without a kind (a pan, a resize)
|
|
2450
|
+
* stops only with `interactive`
|
|
2451
|
+
*/
|
|
2452
|
+
readonly kind?: InteractionKind | undefined;
|
|
2453
|
+
}
|
|
2454
|
+
/**
|
|
2455
|
+
* What the engine gives the features of one view: the model, the view's means (the root, the
|
|
2456
|
+
* viewport, measured rects and handles, point conversion), its notifications and a shared slot.
|
|
2457
|
+
* Every member reads the engine at the call, never a snapshot.
|
|
2458
|
+
*/
|
|
2459
|
+
interface FeatureEngineHost {
|
|
2460
|
+
readonly model: FeatureModel;
|
|
2461
|
+
/**
|
|
2462
|
+
* a value the features of this engine share, made by the first one that asks (a gesture
|
|
2463
|
+
* session): features share state through it without importing each other
|
|
2464
|
+
*/
|
|
2465
|
+
shared<V>(key: string, create: () => V): V;
|
|
2466
|
+
/** the root element, when attached */
|
|
2467
|
+
root(): HTMLElement | undefined;
|
|
2468
|
+
/** the viewport */
|
|
2469
|
+
viewport(): Viewport;
|
|
2470
|
+
/** the least and the greatest zoom */
|
|
2471
|
+
zoomLimits(): {
|
|
2472
|
+
readonly min: number;
|
|
2473
|
+
readonly max: number;
|
|
2474
|
+
};
|
|
2475
|
+
/** sets the viewport (zoom and translate extent kept); returns the viewport it got */
|
|
2476
|
+
setViewport(viewport: Viewport): Viewport;
|
|
2477
|
+
/** the root's size, in pixels (zero before it is attached and laid out) */
|
|
2478
|
+
rootSize(): {
|
|
2479
|
+
readonly width: number;
|
|
2480
|
+
readonly height: number;
|
|
2481
|
+
};
|
|
2482
|
+
/** a pointer's client point (`clientX`, `clientY`) relative to the root's top-left corner */
|
|
2483
|
+
toRoot(client: XY): XY;
|
|
2484
|
+
/** a pointer's client point as a flow point */
|
|
2485
|
+
toFlow(client: XY): XY;
|
|
2486
|
+
/** a node's box in absolute flow coordinates with its measured (or given) size */
|
|
2487
|
+
nodeRect(nodeId: string): Rect | undefined;
|
|
2488
|
+
/** whether a node's size is known (measured, or given by the document) */
|
|
2489
|
+
measured(nodeId: string): boolean;
|
|
2490
|
+
/** every registered handle with its centre (absolute flow coordinates, once measured) */
|
|
2491
|
+
handles(): readonly FlowHandle[];
|
|
2492
|
+
/** an edge's drawn ends, once both its nodes are measured */
|
|
2493
|
+
edgePath(edgeId: string): EdgePath | undefined;
|
|
2494
|
+
/**
|
|
2495
|
+
* a node's position in absolute flow coordinates: its parent's box's top-left corner plus its
|
|
2496
|
+
* own position (with the `nodeOrigin`, the point of its box at that origin)
|
|
2497
|
+
*/
|
|
2498
|
+
absolutePosition(nodeId: string): XY | undefined;
|
|
2499
|
+
/**
|
|
2500
|
+
* the position (relative to its parent) that puts a node's box of `size` with its top-left
|
|
2501
|
+
* corner at the absolute flow point `corner` (the `nodeOrigin` applied)
|
|
2502
|
+
*/
|
|
2503
|
+
positionFor(nodeId: string, corner: XY, size: {
|
|
2504
|
+
readonly width: number;
|
|
2505
|
+
readonly height: number;
|
|
2506
|
+
}): XY;
|
|
2507
|
+
/**
|
|
2508
|
+
* the absolute rectangle a node's box stays inside: its parent's box with `extent: "parent"`
|
|
2509
|
+
* (measured), its rectangle `extent`, the engine's `nodeExtent`, together; none when unbound
|
|
2510
|
+
*/
|
|
2511
|
+
extentOf(nodeId: string): Rect | undefined;
|
|
2512
|
+
/**
|
|
2513
|
+
* a node's position (relative to its parent) kept inside its extent (`extentOf`) with the
|
|
2514
|
+
* measured sizes; `size` overrides the node's own (a resize under way)
|
|
2515
|
+
*/
|
|
2516
|
+
keepInExtent(nodeId: string, position: XY, size?: {
|
|
2517
|
+
readonly width: number;
|
|
2518
|
+
readonly height: number;
|
|
2519
|
+
}): XY;
|
|
2520
|
+
/**
|
|
2521
|
+
* whether a key is held during `event`: `Meta`, `Control`, `Alt` and `Shift` from the event's
|
|
2522
|
+
* flags, any other (`KeyboardEvent.key` or `.code`) from the keys held in the root's document
|
|
2523
|
+
*/
|
|
2524
|
+
held(key: string, event: MouseEvent | KeyboardEvent): boolean;
|
|
2525
|
+
/** a node's element, as the adapter registered it */
|
|
2526
|
+
nodeElement(nodeId: string): HTMLElement | undefined;
|
|
2527
|
+
/** whether the flow's gestures and keys may change it (the Controls' interactivity toggle) */
|
|
2528
|
+
interactive(): boolean;
|
|
2529
|
+
/**
|
|
2530
|
+
* whether the gestures and keys of one kind may change the flow (`set-interactive`'s per-kind
|
|
2531
|
+
* switches: `drag`, `connect`, `select`, `reconnect`), `interactive()` included
|
|
2532
|
+
*/
|
|
2533
|
+
allows(kind: InteractionKind): boolean;
|
|
2534
|
+
/**
|
|
2535
|
+
* how far (in pixels) a press may move and still be a tap: on the pane (`paneClickDistance`)
|
|
2536
|
+
* or on anything else (`nodeClickDistance`)
|
|
2537
|
+
*/
|
|
2538
|
+
tapDistance(on: "pane" | "node"): number;
|
|
2539
|
+
/** whether nodes (`nodesFocusable`) or edges (`edgesFocusable`) take focus at all */
|
|
2540
|
+
focusable(kind: "node" | "edge"): boolean;
|
|
2541
|
+
/** a flow point as a client point (the inverse of `toFlow`) */
|
|
2542
|
+
toClient(point: XY): XY;
|
|
2543
|
+
/** the path of a built-in edge type (an app type: the bezier) between two ends, with the engine's `pathOptions` */
|
|
2544
|
+
path(type: string | undefined, ends: PathEnds): EdgePath;
|
|
2545
|
+
/** options an adapter gave a part (`engine.adapter.setPartOptions`: a resizer's limits) */
|
|
2546
|
+
partOptions(part: string, id: string): Readonly<Record<string, unknown>> | undefined;
|
|
2547
|
+
/** the view changed (a gesture's state): adapters re-render */
|
|
2548
|
+
changed(): void;
|
|
2549
|
+
/** tells the app something happened (D12: an announcement's event) */
|
|
2550
|
+
emit(event: FlowEngineEvent): void;
|
|
2551
|
+
}
|
|
2552
|
+
/**
|
|
2553
|
+
* What a feature adds to one engine (each engine on a model gets its own). The engine walks the
|
|
2554
|
+
* hooks in install order, the first taking the event ending the walk, and merges the keys into its
|
|
2555
|
+
* verbs (a key two features add throws).
|
|
2556
|
+
*/
|
|
2557
|
+
interface FeatureEngine {
|
|
2558
|
+
/** engine actions (`engine.run`), each with its dry run */
|
|
2559
|
+
readonly run?: Readonly<Record<string, (payload: unknown, dryRun: boolean) => CommandResult<unknown>>> | undefined;
|
|
2560
|
+
/** engine reads (`engine.get`) */
|
|
2561
|
+
readonly get?: Readonly<Record<string, (payload: unknown) => unknown>> | undefined;
|
|
2562
|
+
/** engine questions (`engine.is`) */
|
|
2563
|
+
readonly is?: Readonly<Record<string, (payload: unknown) => boolean>> | undefined;
|
|
2564
|
+
/**
|
|
2565
|
+
* a primary press in the flow (`target` says on what): a gesture takes it (a drag, a
|
|
2566
|
+
* connection, a box selection starts), `undefined` leaves it to the next feature and the core
|
|
2567
|
+
*/
|
|
2568
|
+
pointerdown?(event: PointerEvent, target: PressTarget): FeatureGesture | undefined;
|
|
2569
|
+
/**
|
|
2570
|
+
* a press released where it was pressed (no active gesture): `true` takes it (a click
|
|
2571
|
+
* selects); a gesture takes it and goes on without a press (a click-to-connect connection):
|
|
2572
|
+
* the engine moves it with the pointer, and the next press is its own (its release is the
|
|
2573
|
+
* gesture's `end`), as Escape, `cancel-gesture` and a detach are
|
|
2574
|
+
*/
|
|
2575
|
+
tap?(event: PointerEvent, target: PressTarget): boolean | FeatureGesture | undefined;
|
|
2576
|
+
/** the wheel in the flow: `true` takes it (the minimap zooms) */
|
|
2577
|
+
wheel?(event: WheelEvent, target: PressTarget): boolean | undefined;
|
|
2578
|
+
/**
|
|
2579
|
+
* a key in the flow: `true` takes it (its default is prevented); a gesture takes it and goes
|
|
2580
|
+
* on without a press (a keyboard connection), as a tap's does: the engine gives it the next
|
|
2581
|
+
* keys first (`FeatureGesture.keydown`), and Escape, `cancel-gesture`, a press and a detach
|
|
2582
|
+
* end it
|
|
2583
|
+
*/
|
|
2584
|
+
keydown?(event: KeyboardEvent, target: PressTarget): boolean | FeatureGesture | undefined;
|
|
2585
|
+
/** DOM focus entered a part of the flow (a node, an edge) */
|
|
2586
|
+
focus?(target: PressTarget): void;
|
|
2587
|
+
/** adds its state attributes to a part's record (`data-dragging` on a dragged node) */
|
|
2588
|
+
attributes?(part: string, payload: Readonly<Record<string, unknown>>, into: MutablePartAttributes): void;
|
|
2589
|
+
/** the root element was attached */
|
|
2590
|
+
attached?(root: Element): void;
|
|
2591
|
+
/** the root goes away: what is under way (a gesture) ends */
|
|
2592
|
+
detached?(): void;
|
|
2593
|
+
/** the engine is destroyed */
|
|
2594
|
+
destroy?(): void;
|
|
2595
|
+
}
|
|
2596
|
+
/**
|
|
2597
|
+
* An opt-in feature: its options, commands, keys, document rules and engine side. `N` is its name
|
|
2598
|
+
* (`FEATURE_KEYS`), `O` its options as its factory resolved them (read by its engine side).
|
|
2599
|
+
*/
|
|
2600
|
+
interface FlowFeature<N extends FeatureName = FeatureName, O extends object = object> {
|
|
2601
|
+
readonly name: N;
|
|
2602
|
+
/** features it needs installed too; a missing one fails `createFlowModel`, naming both */
|
|
2603
|
+
readonly requires?: readonly FeatureName[] | undefined;
|
|
2604
|
+
/** its options, with their defaults, frozen */
|
|
2605
|
+
readonly options: Readonly<O>;
|
|
2606
|
+
/** its commands, on the same bus as the core's */
|
|
2607
|
+
readonly commands?: readonly CommandDefinition[] | undefined;
|
|
2608
|
+
/** its `model.get` keys */
|
|
2609
|
+
readonly get?: {
|
|
2610
|
+
readonly [key: string]: (reader: FlowReader, payload: never) => unknown;
|
|
2611
|
+
} | undefined;
|
|
2612
|
+
/** its `model.is` keys */
|
|
2613
|
+
readonly is?: {
|
|
2614
|
+
readonly [key: string]: (reader: FlowReader, payload: never) => boolean;
|
|
2615
|
+
} | undefined;
|
|
2616
|
+
/** the rules of its document fields past the JSON Schema (references, cycles), with their paths */
|
|
2617
|
+
documentIssues?(reader: FlowReader): ValidationIssue[];
|
|
2618
|
+
/** a node `node.add` is about to add: why it cannot be (at `path`), or `undefined` */
|
|
2619
|
+
checkNode?(draft: Draft, node: FlowNode, path: string): Failure | undefined;
|
|
2620
|
+
/** an edge `edge.add` is about to add: why it cannot be (at `path`), or `undefined` */
|
|
2621
|
+
checkEdge?(draft: Draft, edge: FlowEdge, path: string): Failure | undefined;
|
|
2622
|
+
/** nodes are about to be removed: adds the nodes that go with them (a parent's children) */
|
|
2623
|
+
removing?(draft: Draft, nodeIds: Set<string>): void;
|
|
2624
|
+
/** where a node may be put (`node.add`, `node.move`, `node.resize`): the position kept to its rules */
|
|
2625
|
+
constrainPosition?(draft: Draft, node: FlowNode, position: XY): XY;
|
|
2626
|
+
/** a node was added, moved or resized: what follows it (a parent that grows) */
|
|
2627
|
+
nodeChanged?(draft: Draft, nodeId: string): void;
|
|
2628
|
+
/** a node's or an edge's flags changed (`node.set-flags`, `edge.set-flags`) */
|
|
2629
|
+
flagsChanged?(draft: Draft, kind: "node" | "edge", id: string): void;
|
|
2630
|
+
/** a node's position in flow coordinates, whatever it is relative to (a parent's) */
|
|
2631
|
+
absolutePosition?(reader: FlowReader, node: FlowNode): XY;
|
|
2632
|
+
/** its part of each engine (fragiola/flow#3) */
|
|
2633
|
+
engine?(host: FeatureEngineHost): FeatureEngine;
|
|
2634
|
+
}
|
|
2635
|
+
/** Any feature. */
|
|
2636
|
+
type AnyFlowFeature = FlowFeature<FeatureName, object>;
|
|
2637
|
+
/**
|
|
2638
|
+
* A list of installed features (`createFlowModel`'s `features`). As a type argument, this wide
|
|
2639
|
+
* form means "any features": every feature's keys are allowed, and a model with features is
|
|
2640
|
+
* assignable to it, so a function taking `FlowModel<T>` takes any model.
|
|
2641
|
+
*/
|
|
2642
|
+
type FlowFeatures = readonly AnyFlowFeature[];
|
|
2643
|
+
/** The names of the features of a list. */
|
|
2644
|
+
type FeatureNamesOf<F extends FlowFeatures> = F[number]["name"];
|
|
2645
|
+
/** The names of kind `Kind` among `All` that a model with the features `F` has: the core's and theirs. */
|
|
2646
|
+
type AllowedKeys<Kind extends FeatureKeyKind, All extends string, F extends FlowFeatures> = Exclude<All, OwnedBy<Kind>> | Extract<All, OwnedBy<Kind, FeatureNamesOf<F>>>;
|
|
2647
|
+
/** The commands a model with the features `F` runs. */
|
|
2648
|
+
type CommandNameOf<F extends FlowFeatures> = AllowedKeys<"commands", CommandName, F>;
|
|
2649
|
+
/** The `model.get` keys of a model with the features `F`. */
|
|
2650
|
+
type ModelGetKeyOf<F extends FlowFeatures> = AllowedKeys<"get", ModelGetKey, F>;
|
|
2651
|
+
/** The `model.is` keys of a model with the features `F`. */
|
|
2652
|
+
type ModelIsKeyOf<F extends FlowFeatures> = AllowedKeys<"is", ModelIsKey, F>;
|
|
2653
|
+
/** The `engine.run` actions of an engine whose model has the features `F`. */
|
|
2654
|
+
type EngineActionKeyOf<F extends FlowFeatures> = AllowedKeys<"engineRun", EngineActionKey, F>;
|
|
2655
|
+
/** The `engine.get` keys of an engine whose model has the features `F`. */
|
|
2656
|
+
type EngineGetKeyOf<F extends FlowFeatures> = AllowedKeys<"engineGet", EngineGetKey, F>;
|
|
2657
|
+
/** The `engine.is` keys of an engine whose model has the features `F`. */
|
|
2658
|
+
type EngineIsKeyOf<F extends FlowFeatures> = AllowedKeys<"engineIs", EngineIsKey, F>;
|
|
2659
|
+
export { NodeToolbarPosition as $, FlowDocumentJson as $n, CommandListener as $t, ViewportEasing as A, NO_GESTURE_ATTRIBUTE as An, ModelGetKey as At, EngineActionResult as B, flag as Bn, QueryArgs as Bt, PartPayloadMap as C, DIRECTION_ATTRIBUTE as Cn, CommandArgs as Ct, FlowEngineOptions as D, ID_ATTRIBUTE as Dn, createFlowModel as Dt, FlowEngine as E, FlowPart as En, FlowModelOptions as Et, EdgeToolbarPayload as F, ResizeHandleAttributeOptions as Fn, ModelIsMap as Ft, EngineIsKey as G, DeclaredHandle as Gn, CommandContext as Gt, EngineGetMap as H, resizeHandleAttributes as Hn, IdKind as Ht, EdgeToolbarPosition as I, ResizeHandleDirection as In, ModelIsPayload as It, FitViewPayload as J, EdgeFlags as Jn, CommandContextGetMap as Jt, EngineIsMap as K, EdgeDataOf as Kn, CommandContextBase as Kt, EngineActionKey as L, ResizeHandleVariant as Ln, NoPayload as Lt, BackgroundPatternPayload as M, PART_ATTRIBUTE as Mn, ModelGetPayload as Mt, BackgroundVariant as N, POSITION_ATTRIBUTE as Nn, ModelGetResult as Nt, PanOnScrollMode as O, LEVEL_ATTRIBUTE as On, DispatchOptions as Ot, Connection as P, PartAttributes as Pn, ModelIsKey as Pt, NodeToolbarPayload as Q, FlowDocument as Qn, CommandInfo as Qt, EngineActionMap as R, VARIANT_ATTRIBUTE as Rn, NodeConnection as Rt, HandleRegistration as S, OwnedBy as Sn, PathOptions as St, ViewChange as T, END_ATTRIBUTE as Tn, FlowModel as Tt, EngineGetPayload as U, AnyTypes as Un, BatchEntry as Ut, EngineGetKey as V, partAttributes as Vn, CreateId as Vt, EngineGetResult as W, BuiltInEdgeType as Wn, BatchStep as Wt, IntersectingNodesPayload as X, EdgePathOptions as Xn, CommandErrorCode as Xt, InternalNode as Y, EdgeOf as Yn, CommandError as Yt, MinimapView as Z, EdgeTypeOf as Zn, CommandEvent as Zt, CommandDefinition as _, JsonValue as _n, PathResult as _r, SelectionDragStep as _t, EngineGetKeyOf as a, EdgeFlagsPayload as an, FlowTypes as ar, InteractivityPayload as at, FlowEngineAdapter as b, FeatureKeyKind as bn, RenderLayer as bt, FeatureEngineHost as c, NodeFlagsPayload as cn, NodeFlags as cr, ViewportForBoundsOptions as ct, FeatureNamesOf as d, ResultOf as dn, SelectionFields as dr, ConnectionEnd as dt, CommandMap as en, FlowEdge as er, SelectionBox as et, FlowFeature as f, RunOptions as fn, SubflowFields as fr, FlowEngineEvent as ft, ModelIsKeyOf as g, JsonSchemaType as gn, PathEnds as gr, MoveSource as gt, ModelGetKeyOf as h, JsonSchema as hn, HandleSide as hr, FlowPointerInfo as ht, EngineActionKeyOf as i, EdgeDataPatchOf as in, FlowNodeInput as ir, Interactivity as it, BackgroundPattern as j, NO_WHEEL_ATTRIBUTE as jn, ModelGetMap as jt, createFlowEngine as k, MutablePartAttributes as kn, HandleType as kt, FeatureGesture as l, PayloadOf as ln, NodeOf as lr, viewportForBounds as lt, FlowReader as m, SelectionResult as mn, EdgePath as mr, FlowEngineEventType as mt, AnyFlowFeature as n, CommandResult as nn, FlowJson as nr, ZoomStepPayload as nt, EngineIsKeyOf as o, Middleware as on, NodeDataOf as or, FitPadding as ot, FlowFeatures as p, SelectionMode as pn, XY as pr, FlowEngineEventOf as pt, EngineIsPayload as q, EdgeFields as qn, CommandContextGetKey as qt, CommandNameOf as r, ConnectionPayload as rn, FlowNode as rr, InteractionKind as rt, FeatureEngine as s, NodeDataPatchOf as sn, NodeFields as sr, PaddingValue as st, AllowedKeys as t, CommandName as tn, FlowEdgeInput as tr, ViewportForBoundsPayload as tt, FeatureModel as u, RemovedResult as un, NodeTypeOf as ur, ConnectionDrop as ut, Failure as v, ValidationIssue as vn, Rect as vr, AutoPanGesture as vt, PressTarget as w, DRAG_HANDLE_ATTRIBUTE as wn, DefaultEdgeOptions as wt, FlowHandle as x, FeatureName as xn, ZIndexMode as xt, ReduceContext as y, FEATURE_KEYS as yn, Viewport as yr, AutoPanOptions as yt, EngineActionPayload as z, edgesLayerAttributes as zn, NodeData as zt };
|
|
2660
|
+
//# sourceMappingURL=types-CLHcZVCb.d.ts.map
|