@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
package/dist/subflows.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { d as fail, i as isFailure, p as ok, r as findNode, u as defineCommand } from "./rules-DLOMrPBG.js";
|
|
2
|
+
import { r as stringOf } from "./core-queries-BPNbcM6k.js";
|
|
3
|
+
import { o as rectSchema, s as xySchema } from "./document-schema-CPK5xkyO.js";
|
|
4
|
+
// src/subflows/hierarchy.ts
|
|
5
|
+
/** A node's direct children, in drawing order. */
|
|
6
|
+
function childrenOf(reader, nodeId) {
|
|
7
|
+
return reader.nodes().filter((node) => node.parentId === nodeId);
|
|
8
|
+
}
|
|
9
|
+
/** Every node under a node (children, their children, …), in breadth-first order. */
|
|
10
|
+
function descendantsOf(reader, nodeId) {
|
|
11
|
+
const found = [];
|
|
12
|
+
const seen = /* @__PURE__ */ new Set([nodeId]);
|
|
13
|
+
for (let i = -1; i < found.length; i++) {
|
|
14
|
+
const parent = i < 0 ? nodeId : found[i];
|
|
15
|
+
for (const child of childrenOf(reader, parent)) if (!seen.has(child.id)) {
|
|
16
|
+
seen.add(child.id);
|
|
17
|
+
found.push(child.id);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return found;
|
|
21
|
+
}
|
|
22
|
+
/** A node's position in flow coordinates: its own, plus each of its parents'. */
|
|
23
|
+
function absolutePositionOf(reader, node) {
|
|
24
|
+
let x = node.position.x;
|
|
25
|
+
let y = node.position.y;
|
|
26
|
+
const seen = /* @__PURE__ */ new Set([node.id]);
|
|
27
|
+
for (let parent = node.parentId === void 0 ? void 0 : reader.node(node.parentId); parent !== void 0 && !seen.has(parent.id); parent = parent.parentId === void 0 ? void 0 : reader.node(parent.parentId)) {
|
|
28
|
+
seen.add(parent.id);
|
|
29
|
+
x += parent.position.x;
|
|
30
|
+
y += parent.position.y;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
x,
|
|
34
|
+
y
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Whether walking up from `nodeId` through its parents comes back to it. */
|
|
38
|
+
function inCycle(reader, nodeId) {
|
|
39
|
+
const seen = /* @__PURE__ */ new Set();
|
|
40
|
+
for (let id = reader.node(nodeId)?.parentId; id !== void 0; id = reader.node(id)?.parentId) {
|
|
41
|
+
if (id === nodeId) return true;
|
|
42
|
+
if (seen.has(id)) return false;
|
|
43
|
+
seen.add(id);
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// src/subflows/commands.ts
|
|
48
|
+
const nodeId = {
|
|
49
|
+
type: "string",
|
|
50
|
+
minLength: 1,
|
|
51
|
+
description: "the node's id"
|
|
52
|
+
};
|
|
53
|
+
const nodeSetParent = defineCommand({
|
|
54
|
+
name: "node.set-parent",
|
|
55
|
+
description: "Puts a node into a parent node (`parentId`), or back on the flow (`null`), keeping its place on screen: its position becomes relative to the new parent. `extent` and `expandParent` set how it stays in its parent. Refused when the parent is the node itself or one of its descendants.",
|
|
56
|
+
payloadSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
nodeId,
|
|
60
|
+
parentId: {
|
|
61
|
+
anyOf: [{
|
|
62
|
+
type: "string",
|
|
63
|
+
minLength: 1
|
|
64
|
+
}, { type: "null" }],
|
|
65
|
+
description: "the new parent's id, or null for none"
|
|
66
|
+
},
|
|
67
|
+
extent: {
|
|
68
|
+
anyOf: [
|
|
69
|
+
{ const: "parent" },
|
|
70
|
+
rectSchema,
|
|
71
|
+
{ type: "null" }
|
|
72
|
+
],
|
|
73
|
+
description: "\"parent\": it stays inside its parent; a rectangle: it stays inside it (in the coordinates of its position); null: no extent; none: as it was"
|
|
74
|
+
},
|
|
75
|
+
expandParent: {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
description: "its parent grows to keep it inside; none: as it was"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
required: ["nodeId", "parentId"],
|
|
81
|
+
additionalProperties: false
|
|
82
|
+
},
|
|
83
|
+
resultSchema: {
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: {
|
|
86
|
+
nodeId,
|
|
87
|
+
position: {
|
|
88
|
+
...xySchema,
|
|
89
|
+
description: "its position, relative to its new parent"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
required: ["nodeId", "position"],
|
|
93
|
+
additionalProperties: false
|
|
94
|
+
},
|
|
95
|
+
transient: false,
|
|
96
|
+
reduce: ({ nodeId, parentId, extent, expandParent }, { draft, features }) => {
|
|
97
|
+
const node = findNode(draft, nodeId, "/nodeId");
|
|
98
|
+
if (isFailure(node)) return node;
|
|
99
|
+
let parent;
|
|
100
|
+
if (parentId !== null) {
|
|
101
|
+
const found = findNode(draft, parentId, "/parentId");
|
|
102
|
+
if (isFailure(found)) return found;
|
|
103
|
+
if (parentId === nodeId || descendantsOf(draft, nodeId).includes(parentId)) return fail("refused", `node "${parentId}" cannot be the parent of node "${nodeId}": it is the node or one of its descendants`, "/parentId");
|
|
104
|
+
parent = found;
|
|
105
|
+
}
|
|
106
|
+
const absolute = absolutePositionOf(draft, node);
|
|
107
|
+
const origin = parent ? absolutePositionOf(draft, parent) : {
|
|
108
|
+
x: 0,
|
|
109
|
+
y: 0
|
|
110
|
+
};
|
|
111
|
+
const { parentId: _parent, extent: ownExtent, expandParent: ownExpand, ...rest } = node;
|
|
112
|
+
const keptExtent = extent === void 0 ? ownExtent : extent ?? void 0;
|
|
113
|
+
const keptExpand = expandParent ?? ownExpand;
|
|
114
|
+
const moved = {
|
|
115
|
+
...rest,
|
|
116
|
+
position: {
|
|
117
|
+
x: absolute.x - origin.x,
|
|
118
|
+
y: absolute.y - origin.y
|
|
119
|
+
},
|
|
120
|
+
...parent ? { parentId: parent.id } : {},
|
|
121
|
+
...keptExtent !== void 0 && (parent || keptExtent !== "parent") ? { extent: keptExtent } : {},
|
|
122
|
+
...parent && keptExpand !== void 0 ? { expandParent: keptExpand } : {}
|
|
123
|
+
};
|
|
124
|
+
const position = features.constrainPosition(draft, moved, moved.position);
|
|
125
|
+
draft.putNode({
|
|
126
|
+
...moved,
|
|
127
|
+
position
|
|
128
|
+
});
|
|
129
|
+
features.nodeChanged(draft, nodeId);
|
|
130
|
+
return ok({
|
|
131
|
+
nodeId,
|
|
132
|
+
position: draft.node(nodeId)?.position ?? position
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
// src/subflows/subflows.ts
|
|
137
|
+
function clamp(value, min, max) {
|
|
138
|
+
return Math.min(Math.max(value, min), Math.max(min, max));
|
|
139
|
+
}
|
|
140
|
+
/** A node's position kept inside its parent's box (`extent: "parent"`), as far as sizes are known. */
|
|
141
|
+
function keptInParent(draft, node, position) {
|
|
142
|
+
if (node.parentId === void 0 || node.extent !== "parent" || node.expandParent === true) return position;
|
|
143
|
+
const parent = draft.node(node.parentId);
|
|
144
|
+
if (!parent) return position;
|
|
145
|
+
return {
|
|
146
|
+
x: clamp(position.x, 0, (parent.width ?? Infinity) - (node.width ?? 0)),
|
|
147
|
+
y: clamp(position.y, 0, (parent.height ?? Infinity) - (node.height ?? 0))
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Grows a node's parent to hold it (`expandParent`): past its left or top edge, the parent moves
|
|
152
|
+
* there and grows, its children shifted back so nothing moves on screen; past its right or bottom
|
|
153
|
+
* edge, it grows (when it has a size). A parent that expands its own parent follows.
|
|
154
|
+
*/
|
|
155
|
+
function expandParentOf(draft, nodeId, seen = /* @__PURE__ */ new Set()) {
|
|
156
|
+
const node = draft.node(nodeId);
|
|
157
|
+
if (node?.expandParent !== true || node.parentId === void 0 || seen.has(nodeId)) return;
|
|
158
|
+
seen.add(nodeId);
|
|
159
|
+
const parent = draft.node(node.parentId);
|
|
160
|
+
if (!parent) return;
|
|
161
|
+
const dx = Math.min(0, node.position.x);
|
|
162
|
+
const dy = Math.min(0, node.position.y);
|
|
163
|
+
if (dx < 0 || dy < 0) for (const child of childrenOf(draft, parent.id)) draft.putNode({
|
|
164
|
+
...child,
|
|
165
|
+
position: {
|
|
166
|
+
x: child.position.x - dx,
|
|
167
|
+
y: child.position.y - dy
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
const moved = draft.node(nodeId) ?? node;
|
|
171
|
+
const right = moved.position.x + (moved.width ?? 0);
|
|
172
|
+
const bottom = moved.position.y + (moved.height ?? 0);
|
|
173
|
+
const width = parent.width === void 0 ? void 0 : Math.max(parent.width - dx, right);
|
|
174
|
+
const height = parent.height === void 0 ? void 0 : Math.max(parent.height - dy, bottom);
|
|
175
|
+
const grown = {
|
|
176
|
+
...parent,
|
|
177
|
+
position: {
|
|
178
|
+
x: parent.position.x + dx,
|
|
179
|
+
y: parent.position.y + dy
|
|
180
|
+
},
|
|
181
|
+
...width === void 0 ? {} : { width },
|
|
182
|
+
...height === void 0 ? {} : { height }
|
|
183
|
+
};
|
|
184
|
+
if (grown.position.x !== parent.position.x || grown.position.y !== parent.position.y || grown.width !== parent.width || grown.height !== parent.height) {
|
|
185
|
+
draft.putNode(grown);
|
|
186
|
+
expandParentOf(draft, parent.id, seen);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/** The document's sub-flow problems: a parent that does not exist, or a cycle of parents. */
|
|
190
|
+
function hierarchyIssues(reader) {
|
|
191
|
+
return reader.nodes().flatMap((node, i) => {
|
|
192
|
+
if (node.parentId === void 0) return [];
|
|
193
|
+
const path = `/nodes/${i}/parentId`;
|
|
194
|
+
if (!reader.node(node.parentId)) return [{
|
|
195
|
+
path,
|
|
196
|
+
message: `no node "${node.parentId}"`
|
|
197
|
+
}];
|
|
198
|
+
return inCycle(reader, node.id) ? [{
|
|
199
|
+
path,
|
|
200
|
+
message: `node "${node.id}" is its own ancestor`
|
|
201
|
+
}] : [];
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** Nodes inside nodes: `features: [subflows()]` (`@fragiola/flow/subflows`). */
|
|
205
|
+
function subflows() {
|
|
206
|
+
return Object.freeze({
|
|
207
|
+
name: "subflows",
|
|
208
|
+
options: Object.freeze({}),
|
|
209
|
+
commands: [nodeSetParent],
|
|
210
|
+
get: {
|
|
211
|
+
"node-children-by": (reader, payload) => {
|
|
212
|
+
const nodeId = stringOf(payload, "nodeId");
|
|
213
|
+
return nodeId === void 0 ? [] : childrenOf(reader, nodeId);
|
|
214
|
+
},
|
|
215
|
+
"node-parent-by": (reader, payload) => {
|
|
216
|
+
const nodeId = stringOf(payload, "nodeId");
|
|
217
|
+
const parentId = nodeId === void 0 ? void 0 : reader.node(nodeId)?.parentId;
|
|
218
|
+
return parentId === void 0 ? void 0 : reader.node(parentId);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
documentIssues: hierarchyIssues,
|
|
222
|
+
checkNode: (draft, node, path) => {
|
|
223
|
+
if (node.parentId === void 0) return;
|
|
224
|
+
if (node.parentId === node.id) return fail("refused", "a node cannot be its own parent", `${path}/parentId`);
|
|
225
|
+
return draft.node(node.parentId) ? void 0 : fail("not_found", `no node "${node.parentId}"`, `${path}/parentId`);
|
|
226
|
+
},
|
|
227
|
+
removing: (draft, nodeIds) => {
|
|
228
|
+
for (const id of [...nodeIds]) for (const descendant of descendantsOf(draft, id)) nodeIds.add(descendant);
|
|
229
|
+
},
|
|
230
|
+
constrainPosition: keptInParent,
|
|
231
|
+
nodeChanged: (draft, nodeId) => expandParentOf(draft, nodeId),
|
|
232
|
+
absolutePosition: absolutePositionOf
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
export { subflows };
|
|
236
|
+
|
|
237
|
+
//# sourceMappingURL=subflows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subflows.js","names":[],"sources":["../src/subflows/hierarchy.ts","../src/subflows/commands.ts","../src/subflows/subflows.ts"],"sourcesContent":["// A node's place among its parents and children (sub-flows): read from `parentId`, cycle-safe\n// (a document with a cycle is refused at load, but a reader never loops on one).\nimport type { FlowNode, XY } from \"../document/types\";\nimport type { FlowReader } from \"../features/types\";\n\n/** A node's direct children, in drawing order. */\nexport function childrenOf(\n reader: FlowReader,\n nodeId: string,\n): readonly FlowNode[] {\n return reader.nodes().filter((node) => node.parentId === nodeId);\n}\n\n/** Every node under a node (children, their children, …), in breadth-first order. */\nexport function descendantsOf(reader: FlowReader, nodeId: string): string[] {\n const found: string[] = [];\n const seen = new Set([nodeId]);\n for (let i = -1; i < found.length; i++) {\n const parent = i < 0 ? nodeId : (found[i] as string);\n for (const child of childrenOf(reader, parent)) {\n if (!seen.has(child.id)) {\n seen.add(child.id);\n found.push(child.id);\n }\n }\n }\n return found;\n}\n\n/** A node's position in flow coordinates: its own, plus each of its parents'. */\nexport function absolutePositionOf(reader: FlowReader, node: FlowNode): XY {\n let x = node.position.x;\n let y = node.position.y;\n const seen = new Set([node.id]);\n for (\n let parent =\n node.parentId === undefined\n ? undefined\n : reader.node(node.parentId);\n parent !== undefined && !seen.has(parent.id);\n parent =\n parent.parentId === undefined\n ? undefined\n : reader.node(parent.parentId)\n ) {\n seen.add(parent.id);\n x += parent.position.x;\n y += parent.position.y;\n }\n return { x, y };\n}\n\n/** Whether walking up from `nodeId` through its parents comes back to it. */\nexport function inCycle(reader: FlowReader, nodeId: string): boolean {\n const seen = new Set<string>();\n for (\n let id: string | undefined = reader.node(nodeId)?.parentId;\n id !== undefined;\n id = reader.node(id)?.parentId\n ) {\n if (id === nodeId) return true;\n if (seen.has(id)) return false;\n seen.add(id);\n }\n return false;\n}\n","// `node.set-parent` (D6, the subflows feature): puts a node into another, or back on the flow,\n// keeping where it is on screen (its position becomes relative to its new parent), and sets how it\n// stays in its parent (`extent`, `expandParent`). Refused when the parent would be the node itself\n// or one of its own descendants.\nimport { defineCommand, fail, ok } from \"../commands/define\";\nimport { findNode, isFailure } from \"../commands/rules\";\nimport { rectSchema, xySchema } from \"../document/document-schema\";\nimport type { FlowNode } from \"../document/types\";\nimport { absolutePositionOf, descendantsOf } from \"./hierarchy\";\n\nconst nodeId = {\n type: \"string\",\n minLength: 1,\n description: \"the node's id\",\n} as const;\n\nexport const nodeSetParent = defineCommand({\n name: \"node.set-parent\",\n description:\n \"Puts a node into a parent node (`parentId`), or back on the flow (`null`), keeping its place on screen: its position becomes relative to the new parent. `extent` and `expandParent` set how it stays in its parent. Refused when the parent is the node itself or one of its descendants.\",\n payloadSchema: {\n type: \"object\",\n properties: {\n nodeId,\n parentId: {\n anyOf: [{ type: \"string\", minLength: 1 }, { type: \"null\" }],\n description: \"the new parent's id, or null for none\",\n },\n extent: {\n anyOf: [{ const: \"parent\" }, rectSchema, { type: \"null\" }],\n description:\n '\"parent\": it stays inside its parent; a rectangle: it stays inside it (in the coordinates of its position); null: no extent; none: as it was',\n },\n expandParent: {\n type: \"boolean\",\n description:\n \"its parent grows to keep it inside; none: as it was\",\n },\n },\n required: [\"nodeId\", \"parentId\"],\n additionalProperties: false,\n },\n resultSchema: {\n type: \"object\",\n properties: {\n nodeId,\n position: {\n ...xySchema,\n description: \"its position, relative to its new parent\",\n },\n },\n required: [\"nodeId\", \"position\"],\n additionalProperties: false,\n },\n transient: false,\n reduce: (\n { nodeId, parentId, extent, expandParent },\n { draft, features },\n ) => {\n const node = findNode(draft, nodeId, \"/nodeId\");\n if (isFailure(node)) {\n return node;\n }\n let parent: FlowNode | undefined;\n if (parentId !== null) {\n const found = findNode(draft, parentId, \"/parentId\");\n if (isFailure(found)) {\n return found;\n }\n if (\n parentId === nodeId ||\n descendantsOf(draft, nodeId).includes(parentId)\n ) {\n return fail(\n \"refused\",\n `node \"${parentId}\" cannot be the parent of node \"${nodeId}\": it is the node or one of its descendants`,\n \"/parentId\",\n );\n }\n parent = found;\n }\n const absolute = absolutePositionOf(draft, node);\n const origin = parent\n ? absolutePositionOf(draft, parent)\n : { x: 0, y: 0 };\n const {\n parentId: _parent,\n extent: ownExtent,\n expandParent: ownExpand,\n ...rest\n } = node;\n const keptExtent =\n extent === undefined ? ownExtent : (extent ?? undefined);\n const keptExpand = expandParent ?? ownExpand;\n const moved = {\n ...rest,\n position: { x: absolute.x - origin.x, y: absolute.y - origin.y },\n ...(parent ? { parentId: parent.id } : {}),\n // `\"parent\"` only means something with a parent; a rectangle stays\n ...(keptExtent !== undefined && (parent || keptExtent !== \"parent\")\n ? { extent: keptExtent }\n : {}),\n ...(parent && keptExpand !== undefined\n ? { expandParent: keptExpand }\n : {}),\n } as FlowNode;\n const position = features.constrainPosition(\n draft,\n moved,\n moved.position,\n );\n draft.putNode({ ...moved, position });\n features.nodeChanged(draft, nodeId);\n return ok({\n nodeId,\n position: draft.node(nodeId)?.position ?? position,\n });\n },\n});\n","// The sub-flows feature (D2, `@fragiola/flow/subflows`): a node may live in another (`parentId`),\n// its position relative to its parent; with `extent: \"parent\"` it stays inside its parent's box,\n// and with `expandParent` its parent grows to keep it inside. Removing a parent removes its\n// children. The model keeps these rules with the sizes the document gives (`width`, `height`); the\n// engine (fragiola/flow#3) keeps them during a drag with the measured ones. A rectangle `extent`\n// (a field of this feature too, D3) is kept by the engine only, during drags, arrows and resizes.\nimport { fail } from \"../commands/define\";\nimport type { FlowNode, XY } from \"../document/types\";\nimport type { FlowFeature, FlowReader } from \"../features/types\";\nimport type { ValidationIssue } from \"../schema/types\";\nimport { stringOf } from \"../state/core-queries\";\nimport type { Draft } from \"../state/draft\";\nimport { nodeSetParent } from \"./commands\";\nimport {\n absolutePositionOf,\n childrenOf,\n descendantsOf,\n inCycle,\n} from \"./hierarchy\";\n\n/** Options of {@link subflows}: none yet. */\nexport type SubflowsOptions = Record<never, never>;\n\n/** The sub-flows feature, as `subflows()` makes it. */\nexport type SubflowsFeature = FlowFeature<\"subflows\", SubflowsOptions>;\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), Math.max(min, max));\n}\n\n/** A node's position kept inside its parent's box (`extent: \"parent\"`), as far as sizes are known. */\nfunction keptInParent(draft: Draft, node: FlowNode, position: XY): XY {\n if (\n node.parentId === undefined ||\n node.extent !== \"parent\" ||\n node.expandParent === true\n ) {\n return position;\n }\n const parent = draft.node(node.parentId);\n if (!parent) {\n return position;\n }\n return {\n x: clamp(position.x, 0, (parent.width ?? Infinity) - (node.width ?? 0)),\n y: clamp(\n position.y,\n 0,\n (parent.height ?? Infinity) - (node.height ?? 0),\n ),\n };\n}\n\n/**\n * Grows a node's parent to hold it (`expandParent`): past its left or top edge, the parent moves\n * there and grows, its children shifted back so nothing moves on screen; past its right or bottom\n * edge, it grows (when it has a size). A parent that expands its own parent follows.\n */\nfunction expandParentOf(\n draft: Draft,\n nodeId: string,\n seen = new Set<string>(),\n): void {\n const node = draft.node(nodeId);\n if (\n node?.expandParent !== true ||\n node.parentId === undefined ||\n seen.has(nodeId)\n ) {\n return;\n }\n seen.add(nodeId);\n const parent = draft.node(node.parentId);\n if (!parent) {\n return;\n }\n const dx = Math.min(0, node.position.x);\n const dy = Math.min(0, node.position.y);\n if (dx < 0 || dy < 0) {\n for (const child of childrenOf(draft, parent.id)) {\n draft.putNode({\n ...child,\n position: {\n x: child.position.x - dx,\n y: child.position.y - dy,\n },\n });\n }\n }\n const moved = draft.node(nodeId) ?? node;\n const right = moved.position.x + (moved.width ?? 0);\n const bottom = moved.position.y + (moved.height ?? 0);\n const width =\n parent.width === undefined\n ? undefined\n : Math.max(parent.width - dx, right);\n const height =\n parent.height === undefined\n ? undefined\n : Math.max(parent.height - dy, bottom);\n const grown: FlowNode = {\n ...parent,\n position: { x: parent.position.x + dx, y: parent.position.y + dy },\n ...(width === undefined ? {} : { width }),\n ...(height === undefined ? {} : { height }),\n };\n if (\n grown.position.x !== parent.position.x ||\n grown.position.y !== parent.position.y ||\n grown.width !== parent.width ||\n grown.height !== parent.height\n ) {\n draft.putNode(grown);\n expandParentOf(draft, parent.id, seen);\n }\n}\n\n/** The document's sub-flow problems: a parent that does not exist, or a cycle of parents. */\nfunction hierarchyIssues(reader: FlowReader): ValidationIssue[] {\n return reader.nodes().flatMap((node, i): ValidationIssue[] => {\n if (node.parentId === undefined) {\n return [];\n }\n const path = `/nodes/${i}/parentId`;\n if (!reader.node(node.parentId)) {\n return [{ path, message: `no node \"${node.parentId}\"` }];\n }\n return inCycle(reader, node.id)\n ? [{ path, message: `node \"${node.id}\" is its own ancestor` }]\n : [];\n });\n}\n\n/** Nodes inside nodes: `features: [subflows()]` (`@fragiola/flow/subflows`). */\nexport function subflows(): SubflowsFeature {\n return Object.freeze({\n name: \"subflows\",\n options: Object.freeze({}),\n commands: [nodeSetParent],\n get: {\n \"node-children-by\": (reader: FlowReader, payload: unknown) => {\n const nodeId = stringOf(payload, \"nodeId\");\n return nodeId === undefined ? [] : childrenOf(reader, nodeId);\n },\n \"node-parent-by\": (reader: FlowReader, payload: unknown) => {\n const nodeId = stringOf(payload, \"nodeId\");\n const parentId =\n nodeId === undefined\n ? undefined\n : reader.node(nodeId)?.parentId;\n return parentId === undefined\n ? undefined\n : reader.node(parentId);\n },\n },\n documentIssues: hierarchyIssues,\n checkNode: (draft, node, path) => {\n if (node.parentId === undefined) {\n return undefined;\n }\n if (node.parentId === node.id) {\n return fail(\n \"refused\",\n \"a node cannot be its own parent\",\n `${path}/parentId`,\n );\n }\n return draft.node(node.parentId)\n ? undefined\n : fail(\n \"not_found\",\n `no node \"${node.parentId}\"`,\n `${path}/parentId`,\n );\n },\n removing: (draft, nodeIds) => {\n for (const id of [...nodeIds]) {\n for (const descendant of descendantsOf(draft, id)) {\n nodeIds.add(descendant);\n }\n }\n },\n constrainPosition: keptInParent,\n nodeChanged: (draft, nodeId) => expandParentOf(draft, nodeId),\n absolutePosition: absolutePositionOf,\n } satisfies SubflowsFeature);\n}\n"],"mappings":";;;;;AAMA,SAAgB,WACZ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