@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,369 @@
|
|
|
1
|
+
// src/document/document-schema.ts
|
|
2
|
+
/** A point in flow coordinates. */
|
|
3
|
+
const xySchema = {
|
|
4
|
+
type: "object",
|
|
5
|
+
description: "a point in flow coordinates: x grows to the right, y grows down",
|
|
6
|
+
properties: {
|
|
7
|
+
x: {
|
|
8
|
+
type: "number",
|
|
9
|
+
description: "the horizontal coordinate"
|
|
10
|
+
},
|
|
11
|
+
y: {
|
|
12
|
+
type: "number",
|
|
13
|
+
description: "the vertical coordinate"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
required: ["x", "y"],
|
|
17
|
+
additionalProperties: false
|
|
18
|
+
};
|
|
19
|
+
/** A rectangle in flow coordinates: a node's `extent`. */
|
|
20
|
+
const rectSchema = {
|
|
21
|
+
type: "object",
|
|
22
|
+
description: "a rectangle in flow coordinates: its top-left corner and its size",
|
|
23
|
+
properties: {
|
|
24
|
+
x: {
|
|
25
|
+
type: "number",
|
|
26
|
+
description: "its left edge"
|
|
27
|
+
},
|
|
28
|
+
y: {
|
|
29
|
+
type: "number",
|
|
30
|
+
description: "its top edge"
|
|
31
|
+
},
|
|
32
|
+
width: {
|
|
33
|
+
type: "number",
|
|
34
|
+
minimum: 0,
|
|
35
|
+
description: "its width"
|
|
36
|
+
},
|
|
37
|
+
height: {
|
|
38
|
+
type: "number",
|
|
39
|
+
minimum: 0,
|
|
40
|
+
description: "its height"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
required: [
|
|
44
|
+
"x",
|
|
45
|
+
"y",
|
|
46
|
+
"width",
|
|
47
|
+
"height"
|
|
48
|
+
],
|
|
49
|
+
additionalProperties: false
|
|
50
|
+
};
|
|
51
|
+
/** A node's `extent`: its parent's box, or a rectangle. */
|
|
52
|
+
const extentSchema = {
|
|
53
|
+
anyOf: [{ const: "parent" }, rectSchema],
|
|
54
|
+
description: "\"parent\": it stays inside its parent's box; a rectangle (x, y, width, height): it stays inside it, in the coordinates of its position (requires the subflows feature)"
|
|
55
|
+
};
|
|
56
|
+
/** A node's or an edge's place in its layer's stacking order. */
|
|
57
|
+
const zIndexSchema = {
|
|
58
|
+
type: "integer",
|
|
59
|
+
description: "its place in the stacking order of its layer (nodes among nodes, edges among edges): a greater one is drawn above; default 0"
|
|
60
|
+
};
|
|
61
|
+
/** A JSON object: a node's or an edge's data. */
|
|
62
|
+
const dataSchema = {
|
|
63
|
+
type: "object",
|
|
64
|
+
description: "the app's data, a JSON object typed by the node or edge type"
|
|
65
|
+
};
|
|
66
|
+
/** A node's flags, each optional (an absent flag is its default). */
|
|
67
|
+
const nodeFlagProperties = {
|
|
68
|
+
draggable: {
|
|
69
|
+
type: "boolean",
|
|
70
|
+
description: "it may be moved (`node.move`); default true"
|
|
71
|
+
},
|
|
72
|
+
selectable: {
|
|
73
|
+
type: "boolean",
|
|
74
|
+
description: "it may be selected (`selection.set`); default true"
|
|
75
|
+
},
|
|
76
|
+
connectable: {
|
|
77
|
+
type: "boolean",
|
|
78
|
+
description: "edges may start or end at it (`edge.add`, `edge.reconnect`); default true"
|
|
79
|
+
},
|
|
80
|
+
deletable: {
|
|
81
|
+
type: "boolean",
|
|
82
|
+
description: "it may be removed (`node.remove`, `selection.remove`); default true"
|
|
83
|
+
},
|
|
84
|
+
hidden: {
|
|
85
|
+
type: "boolean",
|
|
86
|
+
description: "it is not shown; default false"
|
|
87
|
+
},
|
|
88
|
+
focusable: {
|
|
89
|
+
type: "boolean",
|
|
90
|
+
description: "it takes DOM focus (with the keyboard feature); default true"
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/** An edge's flags, each optional (an absent flag is its default). */
|
|
94
|
+
const edgeFlagProperties = {
|
|
95
|
+
selectable: {
|
|
96
|
+
type: "boolean",
|
|
97
|
+
description: "it may be selected (`selection.set`); default true"
|
|
98
|
+
},
|
|
99
|
+
deletable: {
|
|
100
|
+
type: "boolean",
|
|
101
|
+
description: "it may be removed (`edge.remove`, `selection.remove`); default true"
|
|
102
|
+
},
|
|
103
|
+
hidden: {
|
|
104
|
+
type: "boolean",
|
|
105
|
+
description: "it is not shown; default false"
|
|
106
|
+
},
|
|
107
|
+
reconnectable: {
|
|
108
|
+
anyOf: [
|
|
109
|
+
{ type: "boolean" },
|
|
110
|
+
{ const: "source" },
|
|
111
|
+
{ const: "target" }
|
|
112
|
+
],
|
|
113
|
+
description: "its ends may be moved to other nodes or handles (`edge.reconnect`): both (true), none (false), or only its \"source\" or its \"target\" end; default true"
|
|
114
|
+
},
|
|
115
|
+
focusable: {
|
|
116
|
+
type: "boolean",
|
|
117
|
+
description: "it takes DOM focus (with the keyboard feature); default true"
|
|
118
|
+
},
|
|
119
|
+
animated: {
|
|
120
|
+
type: "boolean",
|
|
121
|
+
description: "it is drawn animated (the app's CSS animates its data-animated parts); default false"
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
/** An edge's `pathOptions`: the shape of its path, each built-in type reading its own keys. */
|
|
125
|
+
const edgePathOptionsSchema = {
|
|
126
|
+
type: "object",
|
|
127
|
+
description: "the shape of its path, over the engine's path options: each built-in type reads its own keys (bezier: curvature; smoothstep: borderRadius, offset, stepPosition, centerX, centerY; step: the same but borderRadius)",
|
|
128
|
+
properties: {
|
|
129
|
+
curvature: {
|
|
130
|
+
type: "number",
|
|
131
|
+
description: "bezier: the share of the distance a control point stands out by"
|
|
132
|
+
},
|
|
133
|
+
borderRadius: {
|
|
134
|
+
type: "number",
|
|
135
|
+
minimum: 0,
|
|
136
|
+
description: "smoothstep: the corners' radius, in flow units"
|
|
137
|
+
},
|
|
138
|
+
offset: {
|
|
139
|
+
type: "number",
|
|
140
|
+
description: "smoothstep and step: how far an end stands out before turning, in flow units"
|
|
141
|
+
},
|
|
142
|
+
stepPosition: {
|
|
143
|
+
type: "number",
|
|
144
|
+
minimum: 0,
|
|
145
|
+
description: "smoothstep and step: where the turn sits between the source (0) and the target (1); above 1 counts as 1"
|
|
146
|
+
},
|
|
147
|
+
centerX: {
|
|
148
|
+
type: "number",
|
|
149
|
+
description: "smoothstep and step: the x of a vertical turn, in flow coordinates"
|
|
150
|
+
},
|
|
151
|
+
centerY: {
|
|
152
|
+
type: "number",
|
|
153
|
+
description: "smoothstep and step: the y of a horizontal turn, in flow coordinates"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
additionalProperties: false
|
|
157
|
+
};
|
|
158
|
+
/** A side of a node: a handle's, or the side an edge leaves or enters by. */
|
|
159
|
+
const handleSideSchema = {
|
|
160
|
+
enum: [
|
|
161
|
+
"top",
|
|
162
|
+
"right",
|
|
163
|
+
"bottom",
|
|
164
|
+
"left"
|
|
165
|
+
],
|
|
166
|
+
description: "a side of the node: top, right, bottom or left"
|
|
167
|
+
};
|
|
168
|
+
/** A handle a node declares, for its edges to be drawn before it is measured. */
|
|
169
|
+
const declaredHandleSchema = {
|
|
170
|
+
type: "object",
|
|
171
|
+
description: "a handle the node declares, used until a handle of that type and id is measured",
|
|
172
|
+
properties: {
|
|
173
|
+
id: {
|
|
174
|
+
type: "string",
|
|
175
|
+
minLength: 1,
|
|
176
|
+
description: "its id among the node's handles of its type; none: the default handle"
|
|
177
|
+
},
|
|
178
|
+
type: {
|
|
179
|
+
enum: ["source", "target"],
|
|
180
|
+
description: "edges start (source) or end (target) at it"
|
|
181
|
+
},
|
|
182
|
+
position: {
|
|
183
|
+
...handleSideSchema,
|
|
184
|
+
description: "the side of the node it sits on"
|
|
185
|
+
},
|
|
186
|
+
x: {
|
|
187
|
+
type: "number",
|
|
188
|
+
description: "its box's left edge, relative to the node box's left edge"
|
|
189
|
+
},
|
|
190
|
+
y: {
|
|
191
|
+
type: "number",
|
|
192
|
+
description: "its box's top edge, relative to the node box's top edge"
|
|
193
|
+
},
|
|
194
|
+
width: {
|
|
195
|
+
type: "number",
|
|
196
|
+
minimum: 0,
|
|
197
|
+
description: "its box's width; default 0"
|
|
198
|
+
},
|
|
199
|
+
height: {
|
|
200
|
+
type: "number",
|
|
201
|
+
minimum: 0,
|
|
202
|
+
description: "its box's height; default 0"
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
required: [
|
|
206
|
+
"type",
|
|
207
|
+
"position",
|
|
208
|
+
"x",
|
|
209
|
+
"y"
|
|
210
|
+
],
|
|
211
|
+
additionalProperties: false
|
|
212
|
+
};
|
|
213
|
+
const selected = {
|
|
214
|
+
type: "boolean",
|
|
215
|
+
description: "it is selected (requires the selection feature)"
|
|
216
|
+
};
|
|
217
|
+
/** A node, as a document or `node.add` gives it. */
|
|
218
|
+
const nodeSchema = {
|
|
219
|
+
type: "object",
|
|
220
|
+
description: "a node",
|
|
221
|
+
properties: {
|
|
222
|
+
id: {
|
|
223
|
+
type: "string",
|
|
224
|
+
minLength: 1,
|
|
225
|
+
description: "its id; generated when missing"
|
|
226
|
+
},
|
|
227
|
+
type: {
|
|
228
|
+
type: "string",
|
|
229
|
+
minLength: 1,
|
|
230
|
+
description: "its type, from the app's registry"
|
|
231
|
+
},
|
|
232
|
+
position: {
|
|
233
|
+
...xySchema,
|
|
234
|
+
description: "its top-left corner, in flow coordinates (relative to its parent with sub-flows)"
|
|
235
|
+
},
|
|
236
|
+
data: dataSchema,
|
|
237
|
+
width: {
|
|
238
|
+
type: "number",
|
|
239
|
+
minimum: 0,
|
|
240
|
+
description: "its width, when the document gives one"
|
|
241
|
+
},
|
|
242
|
+
height: {
|
|
243
|
+
type: "number",
|
|
244
|
+
minimum: 0,
|
|
245
|
+
description: "its height, when the document gives one"
|
|
246
|
+
},
|
|
247
|
+
initialWidth: {
|
|
248
|
+
type: "number",
|
|
249
|
+
minimum: 0,
|
|
250
|
+
description: "its width until it is measured; width wins"
|
|
251
|
+
},
|
|
252
|
+
initialHeight: {
|
|
253
|
+
type: "number",
|
|
254
|
+
minimum: 0,
|
|
255
|
+
description: "its height until it is measured; height wins"
|
|
256
|
+
},
|
|
257
|
+
handles: {
|
|
258
|
+
type: "array",
|
|
259
|
+
items: declaredHandleSchema,
|
|
260
|
+
description: "its handles, declared for its edges to be drawn before it is measured"
|
|
261
|
+
},
|
|
262
|
+
sourcePosition: {
|
|
263
|
+
...handleSideSchema,
|
|
264
|
+
description: "the side its edges leave by when no handle gives one; default bottom"
|
|
265
|
+
},
|
|
266
|
+
targetPosition: {
|
|
267
|
+
...handleSideSchema,
|
|
268
|
+
description: "the side its edges enter by when no handle gives one; default top"
|
|
269
|
+
},
|
|
270
|
+
origin: {
|
|
271
|
+
...xySchema,
|
|
272
|
+
description: "the point of its box its position stands at, as shares of its size, over the engine's nodeOrigin"
|
|
273
|
+
},
|
|
274
|
+
zIndex: zIndexSchema,
|
|
275
|
+
...nodeFlagProperties,
|
|
276
|
+
selected,
|
|
277
|
+
parentId: {
|
|
278
|
+
type: "string",
|
|
279
|
+
minLength: 1,
|
|
280
|
+
description: "the node it lives in, its position relative to it (requires the subflows feature)"
|
|
281
|
+
},
|
|
282
|
+
extent: extentSchema,
|
|
283
|
+
expandParent: {
|
|
284
|
+
type: "boolean",
|
|
285
|
+
description: "its parent grows to keep it inside (requires the subflows feature)"
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
required: [
|
|
289
|
+
"type",
|
|
290
|
+
"position",
|
|
291
|
+
"data"
|
|
292
|
+
],
|
|
293
|
+
additionalProperties: false
|
|
294
|
+
};
|
|
295
|
+
/** An edge, as a document or `edge.add` gives it. */
|
|
296
|
+
const edgeSchema = {
|
|
297
|
+
type: "object",
|
|
298
|
+
description: "an edge between two nodes",
|
|
299
|
+
properties: {
|
|
300
|
+
id: {
|
|
301
|
+
type: "string",
|
|
302
|
+
minLength: 1,
|
|
303
|
+
description: "its id; generated when missing"
|
|
304
|
+
},
|
|
305
|
+
source: {
|
|
306
|
+
type: "string",
|
|
307
|
+
minLength: 1,
|
|
308
|
+
description: "the id of the node it starts at"
|
|
309
|
+
},
|
|
310
|
+
target: {
|
|
311
|
+
type: "string",
|
|
312
|
+
minLength: 1,
|
|
313
|
+
description: "the id of the node it ends at"
|
|
314
|
+
},
|
|
315
|
+
sourceHandle: {
|
|
316
|
+
type: "string",
|
|
317
|
+
minLength: 1,
|
|
318
|
+
description: "the source node's handle it starts at; none: the node's default source handle"
|
|
319
|
+
},
|
|
320
|
+
targetHandle: {
|
|
321
|
+
type: "string",
|
|
322
|
+
minLength: 1,
|
|
323
|
+
description: "the target node's handle it ends at; none: the node's default target handle"
|
|
324
|
+
},
|
|
325
|
+
type: {
|
|
326
|
+
type: "string",
|
|
327
|
+
minLength: 1,
|
|
328
|
+
description: "how it is drawn: \"bezier\" (the default), \"simplebezier\", \"smoothstep\", \"step\", \"straight\" or an app type"
|
|
329
|
+
},
|
|
330
|
+
data: dataSchema,
|
|
331
|
+
zIndex: zIndexSchema,
|
|
332
|
+
pathOptions: edgePathOptionsSchema,
|
|
333
|
+
...edgeFlagProperties,
|
|
334
|
+
selected
|
|
335
|
+
},
|
|
336
|
+
required: ["source", "target"],
|
|
337
|
+
additionalProperties: false
|
|
338
|
+
};
|
|
339
|
+
/** A flow document, version 1. */
|
|
340
|
+
const flowDocumentSchema = {
|
|
341
|
+
type: "object",
|
|
342
|
+
title: "Flow document",
|
|
343
|
+
description: "a flow: its nodes and the edges between them",
|
|
344
|
+
properties: {
|
|
345
|
+
version: {
|
|
346
|
+
const: 1,
|
|
347
|
+
description: "the document format's version"
|
|
348
|
+
},
|
|
349
|
+
nodes: {
|
|
350
|
+
type: "array",
|
|
351
|
+
items: nodeSchema,
|
|
352
|
+
description: "the nodes, in drawing order"
|
|
353
|
+
},
|
|
354
|
+
edges: {
|
|
355
|
+
type: "array",
|
|
356
|
+
items: edgeSchema,
|
|
357
|
+
description: "the edges, in drawing order"
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
required: [
|
|
361
|
+
"version",
|
|
362
|
+
"nodes",
|
|
363
|
+
"edges"
|
|
364
|
+
],
|
|
365
|
+
additionalProperties: false
|
|
366
|
+
};
|
|
367
|
+
export { nodeSchema as a, zIndexSchema as c, nodeFlagProperties as i, edgeSchema as n, rectSchema as o, flowDocumentSchema as r, xySchema as s, edgeFlagProperties as t };
|
|
368
|
+
|
|
369
|
+
//# sourceMappingURL=document-schema-CPK5xkyO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-schema-CPK5xkyO.js","names":[],"sources":["../src/document/document-schema.ts"],"sourcesContent":["// The JSON Schema of a flow document (D3), written by hand in the subset the validator checks, and\n// tested equal to the document's types (`tests/types/schemas.ts`). Every schema here is\n// self-contained (no `$ref`): `node.add` and `edge.add` take a node and an edge as their payloads,\n// so their schemas are these, as `model.get(\"commands\")` hands them to an assistant.\n\n/** A point in flow coordinates. */\nexport const xySchema = {\n type: \"object\",\n description:\n \"a point in flow coordinates: x grows to the right, y grows down\",\n properties: {\n x: { type: \"number\", description: \"the horizontal coordinate\" },\n y: { type: \"number\", description: \"the vertical coordinate\" },\n },\n required: [\"x\", \"y\"],\n additionalProperties: false,\n} as const;\n\n/** A rectangle in flow coordinates: a node's `extent`. */\nexport const rectSchema = {\n type: \"object\",\n description:\n \"a rectangle in flow coordinates: its top-left corner and its size\",\n properties: {\n x: { type: \"number\", description: \"its left edge\" },\n y: { type: \"number\", description: \"its top edge\" },\n width: { type: \"number\", minimum: 0, description: \"its width\" },\n height: { type: \"number\", minimum: 0, description: \"its height\" },\n },\n required: [\"x\", \"y\", \"width\", \"height\"],\n additionalProperties: false,\n} as const;\n\n/** A node's `extent`: its parent's box, or a rectangle. */\nexport const extentSchema = {\n anyOf: [{ const: \"parent\" }, rectSchema],\n description:\n '\"parent\": it stays inside its parent\\'s box; a rectangle (x, y, width, height): it stays inside it, in the coordinates of its position (requires the subflows feature)',\n} as const;\n\n/** A node's or an edge's place in its layer's stacking order. */\nexport const zIndexSchema = {\n type: \"integer\",\n description:\n \"its place in the stacking order of its layer (nodes among nodes, edges among edges): a greater one is drawn above; default 0\",\n} as const;\n\n/** A JSON object: a node's or an edge's data. */\nexport const dataSchema = {\n type: \"object\",\n description: \"the app's data, a JSON object typed by the node or edge type\",\n} as const;\n\n/** A node's flags, each optional (an absent flag is its default). */\nexport const nodeFlagProperties = {\n draggable: {\n type: \"boolean\",\n description: \"it may be moved (`node.move`); default true\",\n },\n selectable: {\n type: \"boolean\",\n description: \"it may be selected (`selection.set`); default true\",\n },\n connectable: {\n type: \"boolean\",\n description:\n \"edges may start or end at it (`edge.add`, `edge.reconnect`); default true\",\n },\n deletable: {\n type: \"boolean\",\n description:\n \"it may be removed (`node.remove`, `selection.remove`); default true\",\n },\n hidden: { type: \"boolean\", description: \"it is not shown; default false\" },\n focusable: {\n type: \"boolean\",\n description:\n \"it takes DOM focus (with the keyboard feature); default true\",\n },\n} as const;\n\n/** An edge's flags, each optional (an absent flag is its default). */\nexport const edgeFlagProperties = {\n selectable: {\n type: \"boolean\",\n description: \"it may be selected (`selection.set`); default true\",\n },\n deletable: {\n type: \"boolean\",\n description:\n \"it may be removed (`edge.remove`, `selection.remove`); default true\",\n },\n hidden: { type: \"boolean\", description: \"it is not shown; default false\" },\n reconnectable: {\n anyOf: [{ type: \"boolean\" }, { const: \"source\" }, { const: \"target\" }],\n description:\n 'its ends may be moved to other nodes or handles (`edge.reconnect`): both (true), none (false), or only its \"source\" or its \"target\" end; default true',\n },\n focusable: {\n type: \"boolean\",\n description:\n \"it takes DOM focus (with the keyboard feature); default true\",\n },\n animated: {\n type: \"boolean\",\n description:\n \"it is drawn animated (the app's CSS animates its data-animated parts); default false\",\n },\n} as const;\n\n/** An edge's `pathOptions`: the shape of its path, each built-in type reading its own keys. */\nexport const edgePathOptionsSchema = {\n type: \"object\",\n description:\n \"the shape of its path, over the engine's path options: each built-in type reads its own keys (bezier: curvature; smoothstep: borderRadius, offset, stepPosition, centerX, centerY; step: the same but borderRadius)\",\n properties: {\n curvature: {\n type: \"number\",\n description:\n \"bezier: the share of the distance a control point stands out by\",\n },\n borderRadius: {\n type: \"number\",\n minimum: 0,\n description: \"smoothstep: the corners' radius, in flow units\",\n },\n offset: {\n type: \"number\",\n description:\n \"smoothstep and step: how far an end stands out before turning, in flow units\",\n },\n stepPosition: {\n type: \"number\",\n minimum: 0,\n description:\n \"smoothstep and step: where the turn sits between the source (0) and the target (1); above 1 counts as 1\",\n },\n centerX: {\n type: \"number\",\n description:\n \"smoothstep and step: the x of a vertical turn, in flow coordinates\",\n },\n centerY: {\n type: \"number\",\n description:\n \"smoothstep and step: the y of a horizontal turn, in flow coordinates\",\n },\n },\n additionalProperties: false,\n} as const;\n\n/** A side of a node: a handle's, or the side an edge leaves or enters by. */\nexport const handleSideSchema = {\n enum: [\"top\", \"right\", \"bottom\", \"left\"],\n description: \"a side of the node: top, right, bottom or left\",\n} as const;\n\n/** A handle a node declares, for its edges to be drawn before it is measured. */\nexport const declaredHandleSchema = {\n type: \"object\",\n description:\n \"a handle the node declares, used until a handle of that type and id is measured\",\n properties: {\n id: {\n type: \"string\",\n minLength: 1,\n description:\n \"its id among the node's handles of its type; none: the default handle\",\n },\n type: {\n enum: [\"source\", \"target\"],\n description: \"edges start (source) or end (target) at it\",\n },\n position: {\n ...handleSideSchema,\n description: \"the side of the node it sits on\",\n },\n x: {\n type: \"number\",\n description:\n \"its box's left edge, relative to the node box's left edge\",\n },\n y: {\n type: \"number\",\n description:\n \"its box's top edge, relative to the node box's top edge\",\n },\n width: {\n type: \"number\",\n minimum: 0,\n description: \"its box's width; default 0\",\n },\n height: {\n type: \"number\",\n minimum: 0,\n description: \"its box's height; default 0\",\n },\n },\n required: [\"type\", \"position\", \"x\", \"y\"],\n additionalProperties: false,\n} as const;\n\nconst selected = {\n type: \"boolean\",\n description: \"it is selected (requires the selection feature)\",\n} as const;\n\n/** A node, as a document or `node.add` gives it. */\nexport const nodeSchema = {\n type: \"object\",\n description: \"a node\",\n properties: {\n id: {\n type: \"string\",\n minLength: 1,\n description: \"its id; generated when missing\",\n },\n type: {\n type: \"string\",\n minLength: 1,\n description: \"its type, from the app's registry\",\n },\n position: {\n ...xySchema,\n description:\n \"its top-left corner, in flow coordinates (relative to its parent with sub-flows)\",\n },\n data: dataSchema,\n width: {\n type: \"number\",\n minimum: 0,\n description: \"its width, when the document gives one\",\n },\n height: {\n type: \"number\",\n minimum: 0,\n description: \"its height, when the document gives one\",\n },\n initialWidth: {\n type: \"number\",\n minimum: 0,\n description: \"its width until it is measured; width wins\",\n },\n initialHeight: {\n type: \"number\",\n minimum: 0,\n description: \"its height until it is measured; height wins\",\n },\n handles: {\n type: \"array\",\n items: declaredHandleSchema,\n description:\n \"its handles, declared for its edges to be drawn before it is measured\",\n },\n sourcePosition: {\n ...handleSideSchema,\n description:\n \"the side its edges leave by when no handle gives one; default bottom\",\n },\n targetPosition: {\n ...handleSideSchema,\n description:\n \"the side its edges enter by when no handle gives one; default top\",\n },\n origin: {\n ...xySchema,\n description:\n \"the point of its box its position stands at, as shares of its size, over the engine's nodeOrigin\",\n },\n zIndex: zIndexSchema,\n ...nodeFlagProperties,\n selected,\n parentId: {\n type: \"string\",\n minLength: 1,\n description:\n \"the node it lives in, its position relative to it (requires the subflows feature)\",\n },\n extent: extentSchema,\n expandParent: {\n type: \"boolean\",\n description:\n \"its parent grows to keep it inside (requires the subflows feature)\",\n },\n },\n required: [\"type\", \"position\", \"data\"],\n additionalProperties: false,\n} as const;\n\n/** An edge, as a document or `edge.add` gives it. */\nexport const edgeSchema = {\n type: \"object\",\n description: \"an edge between two nodes\",\n properties: {\n id: {\n type: \"string\",\n minLength: 1,\n description: \"its id; generated when missing\",\n },\n source: {\n type: \"string\",\n minLength: 1,\n description: \"the id of the node it starts at\",\n },\n target: {\n type: \"string\",\n minLength: 1,\n description: \"the id of the node it ends at\",\n },\n sourceHandle: {\n type: \"string\",\n minLength: 1,\n description:\n \"the source node's handle it starts at; none: the node's default source handle\",\n },\n targetHandle: {\n type: \"string\",\n minLength: 1,\n description:\n \"the target node's handle it ends at; none: the node's default target handle\",\n },\n type: {\n type: \"string\",\n minLength: 1,\n description:\n 'how it is drawn: \"bezier\" (the default), \"simplebezier\", \"smoothstep\", \"step\", \"straight\" or an app type',\n },\n data: dataSchema,\n zIndex: zIndexSchema,\n pathOptions: edgePathOptionsSchema,\n ...edgeFlagProperties,\n selected,\n },\n required: [\"source\", \"target\"],\n additionalProperties: false,\n} as const;\n\n/** A flow document, version 1. */\nexport const flowDocumentSchema = {\n type: \"object\",\n title: \"Flow document\",\n description: \"a flow: its nodes and the edges between them\",\n properties: {\n version: { const: 1, description: \"the document format's version\" },\n nodes: {\n type: \"array\",\n items: nodeSchema,\n description: \"the nodes, in drawing order\",\n },\n edges: {\n type: \"array\",\n items: edgeSchema,\n description: \"the edges, in drawing order\",\n },\n },\n required: [\"version\", \"nodes\", \"edges\"],\n additionalProperties: false,\n} as const;\n"],"mappings":";;AAMA,MAAa,WAAW;CACpB,MAAM;CACN,aACI;CACJ,YAAY;EACR,GAAG;GAAE,MAAM;GAAU,aAAa;EAA4B;EAC9D,GAAG;GAAE,MAAM;GAAU,aAAa;EAA0B;CAChE;CACA,UAAU,CAAC,KAAK,GAAG;CACnB,sBAAsB;AAC1B;;AAGA,MAAa,aAAa;CACtB,MAAM;CACN,aACI;CACJ,YAAY;EACR,GAAG;GAAE,MAAM;GAAU,aAAa;EAAgB;EAClD,GAAG;GAAE,MAAM;GAAU,aAAa;EAAe;EACjD,OAAO;GAAE,MAAM;GAAU,SAAS;GAAG,aAAa;EAAY;EAC9D,QAAQ;GAAE,MAAM;GAAU,SAAS;GAAG,aAAa;EAAa;CACpE;CACA,UAAU;EAAC;EAAK;EAAK;EAAS;CAAQ;CACtC,sBAAsB;AAC1B;;AAGA,MAAa,eAAe;CACxB,OAAO,CAAC,EAAE,OAAO,SAAS,GAAG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M;GACF,MAAM,CAAC,UAAU,QAAQ;GACzB,aAAa;EACjB;EACA,UAAU;GACN,GAAG;GACH,aAAa;EACjB;EACA,GAAG;GACC,MAAM;GACN,aACI;EACR;EACA,GAAG;GACC,MAAM;GACN,aACI;EACR;EACA,OAAO;GACH,MAAM;GACN,SAAS;GACT,aAAa;EACjB;EACA,QAAQ;GACJ,MAAM;GACN,SAAS;GACT,aAAa;EACjB;CACJ;CACA,UAAU;EAAC;EAAQ;EAAY;EAAK;CAAG;CACvC,sBAAsB;AAC1B;AAEA,MAAM,WAAW;CACb,MAAM;CACN,aAAa;AACjB;;AAGA,MAAa,aAAa;CACtB,MAAM;CACN,aAAa;CACb,YAAY;EACR,IAAI;GACA,MAAM;GACN,WAAW;GACX,aAAa;EACjB;EACA,MAAM;GACF,MAAM;GACN,WAAW;GACX,aAAa;EACjB;EACA,UAAU;GACN,GAAG;GACH,aACI;EACR;EACA,MAAM;EACN,OAAO;GACH,MAAM;GACN,SAAS;GACT,aAAa;EACjB;EACA,QAAQ;GACJ,MAAM;GACN,SAAS;GACT,aAAa;EACjB;EACA,cAAc;GACV,MAAM;GACN,SAAS;GACT,aAAa;EACjB;EACA,eAAe;GACX,MAAM;GACN,SAAS;GACT,aAAa;EACjB;EACA,SAAS;GACL,MAAM;GACN,OAAO;GACP,aACI;EACR;EACA,gBAAgB;GACZ,GAAG;GACH,aACI;EACR;EACA,gBAAgB;GACZ,GAAG;GACH,aACI;EACR;EACA,QAAQ;GACJ,GAAG;GACH,aACI;EACR;EACA,QAAQ;EACR,GAAG;EACH;EACA,UAAU;GACN,MAAM;GACN,WAAW;GACX,aACI;EACR;EACA,QAAQ;EACR,cAAc;GACV,MAAM;GACN,aACI;EACR;CACJ;CACA,UAAU;EAAC;EAAQ;EAAY;CAAM;CACrC,sBAAsB;AAC1B;;AAGA,MAAa,aAAa;CACtB,MAAM;CACN,aAAa;CACb,YAAY;EACR,IAAI;GACA,MAAM;GACN,WAAW;GACX,aAAa;EACjB;EACA,QAAQ;GACJ,MAAM;GACN,WAAW;GACX,aAAa;EACjB;EACA,QAAQ;GACJ,MAAM;GACN,WAAW;GACX,aAAa;EACjB;EACA,cAAc;GACV,MAAM;GACN,WAAW;GACX,aACI;EACR;EACA,cAAc;GACV,MAAM;GACN,WAAW;GACX,aACI;EACR;EACA,MAAM;GACF,MAAM;GACN,WAAW;GACX,aACI;EACR;EACA,MAAM;EACN,QAAQ;EACR,aAAa;EACb,GAAG;EACH;CACJ;CACA,UAAU,CAAC,UAAU,QAAQ;CAC7B,sBAAsB;AAC1B;;AAGA,MAAa,qBAAqB;CAC9B,MAAM;CACN,OAAO;CACP,aAAa;CACb,YAAY;EACR,SAAS;GAAE,OAAO;GAAG,aAAa;EAAgC;EAClE,OAAO;GACH,MAAM;GACN,OAAO;GACP,aAAa;EACjB;EACA,OAAO;GACH,MAAM;GACN,OAAO;GACP,aAAa;EACjB;CACJ;CACA,UAAU;EAAC;EAAW;EAAS;CAAO;CACtC,sBAAsB;AAC1B"}
|
package/dist/drag.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { f as FlowFeature } from "./types-CLHcZVCb.js";
|
|
2
|
+
/** Options of {@link drag}: read by its engine side. */
|
|
3
|
+
interface DragOptions {
|
|
4
|
+
/** the grid a dragged node's position snaps to, `[x, y]` in flow units; none: no snap */
|
|
5
|
+
readonly snapGrid: readonly [number, number] | undefined;
|
|
6
|
+
/** how far (in pixels) a press moves before it is a drag; default 1 */
|
|
7
|
+
readonly threshold: number;
|
|
8
|
+
/**
|
|
9
|
+
* a drag of a node that is not selected selects it first (it is then dragged alone); false
|
|
10
|
+
* drags it unselected, the selection kept; default true
|
|
11
|
+
*/
|
|
12
|
+
readonly selectOnDrag: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** The drag feature, as `drag()` makes it. */
|
|
15
|
+
type DragFeature = FlowFeature<"drag", DragOptions>;
|
|
16
|
+
/** Dragging nodes: `features: [drag()]` (`@fragiola/flow/drag`). */
|
|
17
|
+
export declare function drag(options?: Partial<DragOptions>): DragFeature;
|
|
18
|
+
export type { DragFeature, DragOptions };
|
|
19
|
+
//# sourceMappingURL=drag.d.ts.map
|
package/dist/drag.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { f as flag } from "./part-attributes-DuBltA__.js";
|
|
2
|
+
import { r as runMoves, t as carriedBy } from "./node-moves-DyWe-4dj.js";
|
|
3
|
+
// src/drag/drag-engine.ts
|
|
4
|
+
/** The engine side of `drag()`. */
|
|
5
|
+
function dragEngine(host, options) {
|
|
6
|
+
const { model } = host;
|
|
7
|
+
let drag;
|
|
8
|
+
const snap = (value, grid) => grid > 0 ? Math.round(value / grid) * grid : value;
|
|
9
|
+
const begin = (nodeId, fromRect) => {
|
|
10
|
+
if (options.selectOnDrag && host.allows("select") && !model.is("node-selected", { nodeId })) model.run("selection.set", { nodeIds: [nodeId] });
|
|
11
|
+
const nodeIds = carriedBy(model, nodeId);
|
|
12
|
+
const starts = /* @__PURE__ */ new Map();
|
|
13
|
+
const relatives = /* @__PURE__ */ new Map();
|
|
14
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const id of nodeIds) {
|
|
16
|
+
const absolute = host.absolutePosition(id);
|
|
17
|
+
const box = host.nodeRect(id);
|
|
18
|
+
const node = model.get("node-by", { id });
|
|
19
|
+
if (absolute && box && node) {
|
|
20
|
+
starts.set(id, absolute);
|
|
21
|
+
relatives.set(id, node.position);
|
|
22
|
+
boxes.set(id, box);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
nodeIds: [...starts.keys()],
|
|
27
|
+
fromRect,
|
|
28
|
+
starts,
|
|
29
|
+
relatives,
|
|
30
|
+
boxes
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** Tells a step of a drag from the rectangle (none for a node's own drag). */
|
|
34
|
+
const step = (type, current, client) => {
|
|
35
|
+
if (!current.fromRect) return;
|
|
36
|
+
host.emit({
|
|
37
|
+
type,
|
|
38
|
+
nodeIds: current.nodeIds,
|
|
39
|
+
client,
|
|
40
|
+
point: host.toFlow(client)
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const gestureFor = (nodeId, start, fromRect = false) => {
|
|
44
|
+
let active = false;
|
|
45
|
+
const anchor = host.toFlow(start);
|
|
46
|
+
/** The moves that put the dragged nodes under the pointer at `client`. */
|
|
47
|
+
const movesAt = (current, client) => {
|
|
48
|
+
const pointer = host.toFlow(client);
|
|
49
|
+
const delta = {
|
|
50
|
+
x: pointer.x - anchor.x,
|
|
51
|
+
y: pointer.y - anchor.y
|
|
52
|
+
};
|
|
53
|
+
const lead = current.starts.get(nodeId) ?? current.starts.values().next().value;
|
|
54
|
+
if (lead && options.snapGrid) {
|
|
55
|
+
const [gridX, gridY] = options.snapGrid;
|
|
56
|
+
delta.x = snap(lead.x + delta.x, gridX) - lead.x;
|
|
57
|
+
delta.y = snap(lead.y + delta.y, gridY) - lead.y;
|
|
58
|
+
}
|
|
59
|
+
return current.nodeIds.map((id) => {
|
|
60
|
+
const box = current.boxes.get(id);
|
|
61
|
+
return {
|
|
62
|
+
nodeId: id,
|
|
63
|
+
position: host.keepInExtent(id, host.positionFor(id, {
|
|
64
|
+
x: box.x + delta.x,
|
|
65
|
+
y: box.y + delta.y
|
|
66
|
+
}, box))
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
autoPan: "node",
|
|
72
|
+
kind: "drag",
|
|
73
|
+
move: (event) => {
|
|
74
|
+
const client = {
|
|
75
|
+
x: event.clientX,
|
|
76
|
+
y: event.clientY
|
|
77
|
+
};
|
|
78
|
+
if (!active) {
|
|
79
|
+
if (Math.hypot(client.x - start.x, client.y - start.y) < options.threshold) return;
|
|
80
|
+
active = true;
|
|
81
|
+
drag = begin(nodeId, fromRect);
|
|
82
|
+
if (fromRect) step("selection-drag-start", drag, client);
|
|
83
|
+
else host.emit({
|
|
84
|
+
type: "drag-start",
|
|
85
|
+
nodeIds: drag.nodeIds
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const current = drag;
|
|
89
|
+
if (!current) return;
|
|
90
|
+
runMoves(model, movesAt(current, client), true);
|
|
91
|
+
host.changed();
|
|
92
|
+
step("selection-drag", current, client);
|
|
93
|
+
},
|
|
94
|
+
end: (event) => {
|
|
95
|
+
const current = drag;
|
|
96
|
+
drag = void 0;
|
|
97
|
+
if (!active || !current) return;
|
|
98
|
+
const client = {
|
|
99
|
+
x: event.clientX,
|
|
100
|
+
y: event.clientY
|
|
101
|
+
};
|
|
102
|
+
runMoves(model, movesAt(current, client), false);
|
|
103
|
+
host.changed();
|
|
104
|
+
host.emit({
|
|
105
|
+
type: "nodes-move",
|
|
106
|
+
nodeIds: current.nodeIds,
|
|
107
|
+
source: "pointer"
|
|
108
|
+
});
|
|
109
|
+
step("selection-drag-end", current, client);
|
|
110
|
+
},
|
|
111
|
+
cancel: () => {
|
|
112
|
+
const current = drag;
|
|
113
|
+
drag = void 0;
|
|
114
|
+
if (!active || !current) return;
|
|
115
|
+
runMoves(model, current.nodeIds.map((id) => ({
|
|
116
|
+
nodeId: id,
|
|
117
|
+
position: current.relatives.get(id)
|
|
118
|
+
})), false);
|
|
119
|
+
host.changed();
|
|
120
|
+
host.emit({
|
|
121
|
+
type: "drag-cancel",
|
|
122
|
+
nodeIds: current.nodeIds
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
active: () => active
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
get: { "dragging-node-ids": () => drag?.nodeIds ?? [] },
|
|
130
|
+
is: {
|
|
131
|
+
dragging: () => drag !== void 0,
|
|
132
|
+
"node-dragging": (payload) => drag?.nodeIds.includes(String(payload.nodeId)) ?? false
|
|
133
|
+
},
|
|
134
|
+
pointerdown: (event, target) => {
|
|
135
|
+
if (target.kind === "nodes-selection") {
|
|
136
|
+
const lead = (model.get("selected-nodes") ?? []).find((node) => model.is("node-draggable", { nodeId: node.id }));
|
|
137
|
+
if (!lead || drag !== void 0 || !host.allows("drag")) return void 0;
|
|
138
|
+
return gestureFor(lead.id, {
|
|
139
|
+
x: event.clientX,
|
|
140
|
+
y: event.clientY
|
|
141
|
+
}, true);
|
|
142
|
+
}
|
|
143
|
+
if (target.kind !== "node" || target.nodeId === void 0 || target.outsideDragHandle === true || drag !== void 0 || !host.allows("drag") || !model.is("node-draggable", { nodeId: target.nodeId })) return;
|
|
144
|
+
return gestureFor(target.nodeId, {
|
|
145
|
+
x: event.clientX,
|
|
146
|
+
y: event.clientY
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
attributes: (part, payload, into) => {
|
|
150
|
+
if (part === "root") into["data-dragging"] = flag(drag !== void 0);
|
|
151
|
+
if (part === "nodes-selection") into["data-dragging"] = flag(drag?.fromRect === true);
|
|
152
|
+
if (part === "node") into["data-dragging"] = flag(drag?.nodeIds.includes(String(payload.nodeId)) ?? false);
|
|
153
|
+
},
|
|
154
|
+
detached: () => {
|
|
155
|
+
drag = void 0;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// src/drag/drag.ts
|
|
160
|
+
/** Dragging nodes: `features: [drag()]` (`@fragiola/flow/drag`). */
|
|
161
|
+
function drag(options = {}) {
|
|
162
|
+
const resolved = Object.freeze({
|
|
163
|
+
snapGrid: options.snapGrid ? Object.freeze([...options.snapGrid]) : void 0,
|
|
164
|
+
threshold: options.threshold ?? 1,
|
|
165
|
+
selectOnDrag: options.selectOnDrag ?? true
|
|
166
|
+
});
|
|
167
|
+
return Object.freeze({
|
|
168
|
+
name: "drag",
|
|
169
|
+
options: resolved,
|
|
170
|
+
engine: (host) => dragEngine(host, resolved)
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export { drag };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=drag.js.map
|
package/dist/drag.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drag.js","names":[],"sources":["../src/drag/drag-engine.ts","../src/drag/drag.ts"],"sourcesContent":["// The drag feature's engine side (D9, D10): a press on a node that moves past the threshold drags\n// it, with the selection when it is selected (and, `selectOnDrag`, selects it first when it is not;\n// a node dragged unselected is dragged alone); every pointer\n// move is a transient step (`node.move`, a `batch` for several), the drop the final one. Positions\n// snap to the grid (the pressed node snaps, the others keep their offsets), and a node with\n// an extent (`extent: \"parent\"`, a rectangle `extent`, the engine's `nodeExtent`) stays inside it\n// with the measured sizes. A node holding a drag handle drags only from it. Escape,\n// `pointercancel` or a lost capture puts the nodes back. A press on the rectangle around the\n// selection (the `nodes-selection` part) is the same drag, of the selection, led by its first\n// draggable node, told as `selection-drag-start`, `selection-drag` (each step) and\n// `selection-drag-end`.\nimport { flag } from \"../attributes/part-attributes\";\nimport type { XY } from \"../document/types\";\nimport { carriedBy, runMoves } from \"../engine/node-moves\";\nimport type {\n FeatureEngine,\n FeatureEngineHost,\n FeatureGesture,\n} from \"../features/types\";\nimport type { Rect } from \"../geometry/types\";\nimport type { DragOptions } from \"./drag\";\n\ninterface Drag {\n readonly nodeIds: readonly string[];\n /** dragged from the rectangle around the selection (`nodes-selection`) */\n readonly fromRect: boolean;\n /** each node's absolute position at the start (the snap's reference) */\n readonly starts: ReadonlyMap<string, XY>;\n /** each node's relative position at the start (a cancel puts it back) */\n readonly relatives: ReadonlyMap<string, XY>;\n /**\n * each node's absolute box at the start: a step puts it at its corner plus the pointer's\n * travel, relative to its parent's corner as it is then (a parent that grew, `expandParent`,\n * moved it)\n */\n readonly boxes: ReadonlyMap<string, Rect>;\n}\n\n/** The engine side of `drag()`. */\nexport function dragEngine(\n host: FeatureEngineHost,\n options: DragOptions,\n): FeatureEngine {\n const { model } = host;\n let drag: Drag | undefined;\n\n const snap = (value: number, grid: number) =>\n grid > 0 ? Math.round(value / grid) * grid : value;\n\n const begin = (nodeId: string, fromRect: boolean): Drag => {\n if (\n options.selectOnDrag &&\n host.allows(\"select\") &&\n !model.is(\"node-selected\", { nodeId })\n ) {\n // a node dragged alone becomes the selection (refused without `selection()`)\n model.run(\"selection.set\", { nodeIds: [nodeId] });\n }\n const nodeIds = carriedBy(model, nodeId);\n const starts = new Map<string, XY>();\n const relatives = new Map<string, XY>();\n const boxes = new Map<string, Rect>();\n for (const id of nodeIds) {\n const absolute = host.absolutePosition(id);\n const box = host.nodeRect(id);\n const node = model.get(\"node-by\", { id }) as\n | { position: XY }\n | undefined;\n if (absolute && box && node) {\n starts.set(id, absolute);\n relatives.set(id, node.position);\n boxes.set(id, box);\n }\n }\n return {\n nodeIds: [...starts.keys()],\n fromRect,\n starts,\n relatives,\n boxes,\n };\n };\n\n /** Tells a step of a drag from the rectangle (none for a node's own drag). */\n const step = (\n type: \"selection-drag-start\" | \"selection-drag\" | \"selection-drag-end\",\n current: Drag,\n client: XY,\n ) => {\n if (!current.fromRect) return;\n host.emit({\n type,\n nodeIds: current.nodeIds,\n client,\n point: host.toFlow(client),\n });\n };\n\n const gestureFor = (\n nodeId: string,\n start: XY,\n fromRect = false,\n ): FeatureGesture => {\n let active = false;\n // the flow point pressed: an auto-pan moves the flow under a still pointer\n const anchor = host.toFlow(start);\n /** The moves that put the dragged nodes under the pointer at `client`. */\n const movesAt = (current: Drag, client: XY) => {\n const pointer = host.toFlow(client);\n const delta = {\n x: pointer.x - anchor.x,\n y: pointer.y - anchor.y,\n };\n const lead =\n current.starts.get(nodeId) ??\n current.starts.values().next().value;\n if (lead && options.snapGrid) {\n const [gridX, gridY] = options.snapGrid;\n delta.x = snap(lead.x + delta.x, gridX) - lead.x;\n delta.y = snap(lead.y + delta.y, gridY) - lead.y;\n }\n return current.nodeIds.map((id) => {\n const box = current.boxes.get(id) as Rect;\n return {\n nodeId: id,\n position: host.keepInExtent(\n id,\n host.positionFor(\n id,\n { x: box.x + delta.x, y: box.y + delta.y },\n box,\n ),\n ),\n };\n });\n };\n return {\n autoPan: \"node\",\n kind: \"drag\",\n move: (event) => {\n const client = { x: event.clientX, y: event.clientY };\n if (!active) {\n if (\n Math.hypot(client.x - start.x, client.y - start.y) <\n options.threshold\n ) {\n return;\n }\n active = true;\n drag = begin(nodeId, fromRect);\n if (fromRect) step(\"selection-drag-start\", drag, client);\n else\n host.emit({\n type: \"drag-start\",\n nodeIds: drag.nodeIds,\n });\n }\n const current = drag;\n if (!current) return;\n runMoves(model, movesAt(current, client), true);\n host.changed();\n step(\"selection-drag\", current, client);\n },\n end: (event) => {\n const current = drag;\n drag = undefined;\n if (!active || !current) return;\n // the drop, from where the pointer is now (never a stored step: a parent that grew\n // since moved what the step was relative to)\n const client = { x: event.clientX, y: event.clientY };\n runMoves(model, movesAt(current, client), false);\n host.changed();\n host.emit({\n type: \"nodes-move\",\n nodeIds: current.nodeIds,\n source: \"pointer\",\n });\n step(\"selection-drag-end\", current, client);\n },\n cancel: () => {\n const current = drag;\n drag = undefined;\n if (!active || !current) return;\n runMoves(\n model,\n current.nodeIds.map((id) => ({\n nodeId: id,\n position: current.relatives.get(id) as XY,\n })),\n false,\n );\n host.changed();\n host.emit({ type: \"drag-cancel\", nodeIds: current.nodeIds });\n },\n active: () => active,\n };\n };\n\n return {\n get: {\n \"dragging-node-ids\": () => drag?.nodeIds ?? [],\n },\n is: {\n dragging: () => drag !== undefined,\n \"node-dragging\": (payload) =>\n drag?.nodeIds.includes(\n String((payload as { nodeId?: unknown }).nodeId),\n ) ?? false,\n },\n pointerdown: (event, target) => {\n if (target.kind === \"nodes-selection\") {\n // the selection's drag, led by its first draggable node\n const lead = (\n (model.get(\"selected-nodes\") as\n | readonly { id: string }[]\n | undefined) ?? []\n ).find((node) =>\n model.is(\"node-draggable\", { nodeId: node.id }),\n );\n if (!lead || drag !== undefined || !host.allows(\"drag\"))\n return undefined;\n return gestureFor(\n lead.id,\n { x: event.clientX, y: event.clientY },\n true,\n );\n }\n if (\n target.kind !== \"node\" ||\n target.nodeId === undefined ||\n target.outsideDragHandle === true ||\n drag !== undefined ||\n !host.allows(\"drag\") ||\n !model.is(\"node-draggable\", { nodeId: target.nodeId })\n ) {\n return undefined;\n }\n return gestureFor(target.nodeId, {\n x: event.clientX,\n y: event.clientY,\n });\n },\n attributes: (part, payload, into) => {\n if (part === \"root\")\n into[\"data-dragging\"] = flag(drag !== undefined);\n if (part === \"nodes-selection\")\n into[\"data-dragging\"] = flag(drag?.fromRect === true);\n if (part === \"node\") {\n into[\"data-dragging\"] = flag(\n drag?.nodeIds.includes(String(payload.nodeId)) ?? false,\n );\n }\n },\n detached: () => {\n drag = undefined;\n },\n };\n}\n","// The drag feature (D2, `@fragiola/flow/drag`): node dragging, snap to a grid, multi-node drag,\n// extent. Its model side is the core's `node.move` (refused for a node that is not draggable),\n// which a drag runs as `transient` steps, then once more for the drop (D9); its engine side\n// (`drag-engine.ts`: Pointer Events, the threshold, the snap, moving every selected node) reads\n// `options`.\nimport type { FlowFeature } from \"../features/types\";\nimport { dragEngine } from \"./drag-engine\";\n\n/** Options of {@link drag}: read by its engine side. */\nexport interface DragOptions {\n /** the grid a dragged node's position snaps to, `[x, y]` in flow units; none: no snap */\n readonly snapGrid: readonly [number, number] | undefined;\n /** how far (in pixels) a press moves before it is a drag; default 1 */\n readonly threshold: number;\n /**\n * a drag of a node that is not selected selects it first (it is then dragged alone); false\n * drags it unselected, the selection kept; default true\n */\n readonly selectOnDrag: boolean;\n}\n\n/** The drag feature, as `drag()` makes it. */\nexport type DragFeature = FlowFeature<\"drag\", DragOptions>;\n\n/** Dragging nodes: `features: [drag()]` (`@fragiola/flow/drag`). */\nexport function drag(options: Partial<DragOptions> = {}): DragFeature {\n const resolved: DragOptions = Object.freeze({\n snapGrid: options.snapGrid\n ? (Object.freeze([...options.snapGrid]) as readonly [\n number,\n number,\n ])\n : undefined,\n threshold: options.threshold ?? 1,\n selectOnDrag: options.selectOnDrag ?? true,\n });\n return Object.freeze({\n name: \"drag\",\n options: resolved,\n engine: (host) => dragEngine(host, resolved),\n } satisfies DragFeature);\n}\n"],"m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