@affino/diagram-core 0.10.1 → 0.11.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/README.md +33 -1
- package/dist/DiagramEngine.d.ts +1 -0
- package/dist/DiagramEngine.d.ts.map +1 -1
- package/dist/DiagramEngine.js +625 -49
- package/dist/geometry.d.ts +3 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +44 -0
- package/dist/interaction.d.ts +7 -0
- package/dist/interaction.d.ts.map +1 -1
- package/dist/interaction.js +193 -25
- package/dist/internal/DiagramClipboardService.d.ts.map +1 -1
- package/dist/internal/DiagramClipboardService.js +43 -6
- package/dist/internal/DiagramSceneStore.d.ts.map +1 -1
- package/dist/internal/DiagramSceneStore.js +12 -2
- package/dist/internal/model.d.ts +5 -1
- package/dist/internal/model.d.ts.map +1 -1
- package/dist/types.d.ts +123 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/geometry.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { DiagramEdge, DiagramEdgeEndpoint, DiagramEntities, DiagramGeometry, DiagramId, DiagramPoint, DiagramPort, DiagramRect } from "./types.js";
|
|
1
|
+
import type { DiagramEdge, DiagramEdgeEndpoint, DiagramEntities, DiagramGeometry, DiagramId, DiagramPoint, DiagramPort, DiagramRect, DiagramTable, DiagramTableCellPosition } from "./types.js";
|
|
2
2
|
export declare function rectIntersects(a: DiagramRect, b: DiagramRect): boolean;
|
|
3
3
|
export declare function rectContainsPoint(rect: DiagramRect, point: DiagramPoint, radius?: number): boolean;
|
|
4
4
|
export declare function rectFromPoints(points: ReadonlyArray<DiagramPoint>): DiagramRect;
|
|
5
5
|
export declare function inflateRect(rect: DiagramRect, amount: number): DiagramRect;
|
|
6
6
|
export declare function rectCenter(rect: DiagramRect): DiagramPoint;
|
|
7
7
|
export declare function distance(a: DiagramPoint, b: DiagramPoint): number;
|
|
8
|
+
/** Returns the zero-based table cell at a world-space point, or null when outside the table. */
|
|
9
|
+
export declare function getDiagramTableCellAt(table: DiagramTable, point: DiagramPoint): DiagramTableCellPosition | null;
|
|
8
10
|
export declare function createEntityGeometry(id: DiagramId, entities: DiagramEntities): DiagramGeometry | null;
|
|
9
11
|
export declare function resolveEdgePath(edge: DiagramEdge, entities: DiagramEntities): ReadonlyArray<DiagramPoint>;
|
|
10
12
|
export declare function resolveEndpoint(endpoint: DiagramEdgeEndpoint, entities: DiagramEntities): DiagramPoint;
|
package/dist/geometry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE/L,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAEtE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAI,GAAG,OAAO,CAK7F;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,GAAG,WAAW,CAe/E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAO1E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,CAE1D;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAEjE;AAED,gGAAgG;AAChG,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,wBAAwB,GAAG,IAAI,CAO/G;AAYD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,GAAG,eAAe,GAAG,IAAI,CAwCrG;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,GAAG,aAAa,CAAC,YAAY,CAAC,CAMzG;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,EAAE,eAAe,GAAG,YAAY,CAUtG;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,GAAG,YAAY,CAO3F;AAYD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC,CAQnG;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CASrG"}
|
package/dist/geometry.js
CHANGED
|
@@ -37,6 +37,28 @@ export function rectCenter(rect) {
|
|
|
37
37
|
export function distance(a, b) {
|
|
38
38
|
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
39
39
|
}
|
|
40
|
+
/** Returns the zero-based table cell at a world-space point, or null when outside the table. */
|
|
41
|
+
export function getDiagramTableCellAt(table, point) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
if (point.x < table.x || point.y < table.y || point.x > table.x + table.width || point.y > table.y + table.height)
|
|
44
|
+
return null;
|
|
45
|
+
const columnWidths = (_a = table.columnWidths) !== null && _a !== void 0 ? _a : Array(table.columnCount).fill(table.width / table.columnCount);
|
|
46
|
+
const rowHeights = (_b = table.rowHeights) !== null && _b !== void 0 ? _b : Array(table.rowCount).fill(table.height / table.rowCount);
|
|
47
|
+
const column = findCellIndex(point.x - table.x, columnWidths, table.width);
|
|
48
|
+
const row = findCellIndex(point.y - table.y, rowHeights, table.height);
|
|
49
|
+
return { row, column };
|
|
50
|
+
}
|
|
51
|
+
function findCellIndex(offset, sizes, total) {
|
|
52
|
+
if (offset >= total)
|
|
53
|
+
return sizes.length - 1;
|
|
54
|
+
let edge = 0;
|
|
55
|
+
for (let index = 0; index < sizes.length; index += 1) {
|
|
56
|
+
edge += sizes[index];
|
|
57
|
+
if (offset < edge)
|
|
58
|
+
return index;
|
|
59
|
+
}
|
|
60
|
+
return Math.max(0, sizes.length - 1);
|
|
61
|
+
}
|
|
40
62
|
export function createEntityGeometry(id, entities) {
|
|
41
63
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
42
64
|
const node = entities.nodesById.get(id);
|
|
@@ -66,6 +88,19 @@ export function createEntityGeometry(id, entities) {
|
|
|
66
88
|
if (shape) {
|
|
67
89
|
return rectGeometry(id, "shape", { x: shape.x, y: shape.y, width: shape.width, height: shape.height }, (_h = shape.rotation) !== null && _h !== void 0 ? _h : 0, 3);
|
|
68
90
|
}
|
|
91
|
+
const group = entities.groupsById.get(id);
|
|
92
|
+
if (group) {
|
|
93
|
+
const bounds = unionRects(group.childIds
|
|
94
|
+
.filter((childId) => childId !== id)
|
|
95
|
+
.map((childId) => { var _a; return (_a = createEntityGeometry(childId, entities)) === null || _a === void 0 ? void 0 : _a.bounds; })
|
|
96
|
+
.filter((rect) => Boolean(rect)));
|
|
97
|
+
if (!bounds)
|
|
98
|
+
return null;
|
|
99
|
+
return { id, kind: "group", bounds, unrotatedBounds: bounds, rotation: 0, hitBounds: inflateRect(bounds, 6) };
|
|
100
|
+
}
|
|
101
|
+
const table = entities.tablesById.get(id);
|
|
102
|
+
if (table)
|
|
103
|
+
return rectGeometry(id, "table", { x: table.x, y: table.y, width: table.width, height: table.height }, 0, 3);
|
|
69
104
|
return null;
|
|
70
105
|
}
|
|
71
106
|
export function resolveEdgePath(edge, entities) {
|
|
@@ -129,3 +164,12 @@ function normalizeRotation(rotation) {
|
|
|
129
164
|
const normalized = rotation % 360;
|
|
130
165
|
return normalized < 0 ? normalized + 360 : normalized;
|
|
131
166
|
}
|
|
167
|
+
function unionRects(rects) {
|
|
168
|
+
if (!rects.length)
|
|
169
|
+
return null;
|
|
170
|
+
const minX = Math.min(...rects.map((rect) => rect.x));
|
|
171
|
+
const minY = Math.min(...rects.map((rect) => rect.y));
|
|
172
|
+
const maxX = Math.max(...rects.map((rect) => rect.x + rect.width));
|
|
173
|
+
const maxY = Math.max(...rects.map((rect) => rect.y + rect.height));
|
|
174
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
175
|
+
}
|
package/dist/interaction.d.ts
CHANGED
|
@@ -26,7 +26,10 @@ export declare class DiagramInteractionController {
|
|
|
26
26
|
private edgeEndpointId;
|
|
27
27
|
private edgeEndpointKind;
|
|
28
28
|
private edgeEndpointStart;
|
|
29
|
+
private edgeEndpointOppositeStart;
|
|
30
|
+
private edgeEndpointCardinalAngle;
|
|
29
31
|
private edgeEndpointPreview;
|
|
32
|
+
private edgeWaypointPreview;
|
|
30
33
|
private dragSelectionIds;
|
|
31
34
|
private snapGuides;
|
|
32
35
|
private framePending;
|
|
@@ -56,7 +59,11 @@ export declare class DiagramInteractionController {
|
|
|
56
59
|
private createSelectionResizePreviewEntries;
|
|
57
60
|
private createResizePreview;
|
|
58
61
|
private resizeGridSize;
|
|
62
|
+
private expandedDragSelectionIds;
|
|
63
|
+
private isDraggedEntity;
|
|
59
64
|
private updateShiftAxis;
|
|
65
|
+
private isPastAxisActivation;
|
|
66
|
+
private createOrthogonalWaypointPreview;
|
|
60
67
|
private getMarqueeSelectionIds;
|
|
61
68
|
private clearGesture;
|
|
62
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interaction.d.ts","sourceRoot":"","sources":["../src/interaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"interaction.d.ts","sourceRoot":"","sources":["../src/interaction.ts"],"names":[],"mappings":"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"}
|
package/dist/interaction.js
CHANGED
|
@@ -117,12 +117,30 @@ export class DiagramInteractionController {
|
|
|
117
117
|
writable: true,
|
|
118
118
|
value: null
|
|
119
119
|
});
|
|
120
|
+
Object.defineProperty(this, "edgeEndpointOppositeStart", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
value: null
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(this, "edgeEndpointCardinalAngle", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true,
|
|
129
|
+
writable: true,
|
|
130
|
+
value: null
|
|
131
|
+
});
|
|
120
132
|
Object.defineProperty(this, "edgeEndpointPreview", {
|
|
121
133
|
enumerable: true,
|
|
122
134
|
configurable: true,
|
|
123
135
|
writable: true,
|
|
124
136
|
value: null
|
|
125
137
|
});
|
|
138
|
+
Object.defineProperty(this, "edgeWaypointPreview", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
configurable: true,
|
|
141
|
+
writable: true,
|
|
142
|
+
value: null
|
|
143
|
+
});
|
|
126
144
|
Object.defineProperty(this, "dragSelectionIds", {
|
|
127
145
|
enumerable: true,
|
|
128
146
|
configurable: true,
|
|
@@ -214,6 +232,9 @@ export class DiagramInteractionController {
|
|
|
214
232
|
return;
|
|
215
233
|
}
|
|
216
234
|
}
|
|
235
|
+
const ownerGroup = [...this.engine.getScene().entities.groupsById.values()].find((group) => group.childIds.includes(targetId));
|
|
236
|
+
if (ownerGroup)
|
|
237
|
+
targetId = ownerGroup.id;
|
|
217
238
|
const selection = this.engine.getScene().selection;
|
|
218
239
|
if (event.shiftKey) {
|
|
219
240
|
this.engine.dispatch({ type: "setSelection", selection: { ids: [targetId], primaryId: targetId }, mode: "toggle" });
|
|
@@ -259,6 +280,7 @@ export class DiagramInteractionController {
|
|
|
259
280
|
if (!geometry || geometry.kind !== "edge" || !((_a = geometry.path) === null || _a === void 0 ? void 0 : _a.length))
|
|
260
281
|
return false;
|
|
261
282
|
const point = endpoint === "source" ? geometry.path[0] : geometry.path[geometry.path.length - 1];
|
|
283
|
+
const oppositePoint = endpoint === "source" ? geometry.path[geometry.path.length - 1] : geometry.path[0];
|
|
262
284
|
this.cancel();
|
|
263
285
|
this.tool = "drag-edge-endpoint";
|
|
264
286
|
this.activePointer = event;
|
|
@@ -269,6 +291,7 @@ export class DiagramInteractionController {
|
|
|
269
291
|
this.edgeEndpointId = ownerId;
|
|
270
292
|
this.edgeEndpointKind = endpoint;
|
|
271
293
|
this.edgeEndpointStart = point;
|
|
294
|
+
this.edgeEndpointOppositeStart = oppositePoint;
|
|
272
295
|
return true;
|
|
273
296
|
}
|
|
274
297
|
beginResizeSelectionHandle(handle, event) {
|
|
@@ -314,7 +337,7 @@ export class DiagramInteractionController {
|
|
|
314
337
|
}
|
|
315
338
|
}
|
|
316
339
|
pointerUp(event) {
|
|
317
|
-
var _a, _b, _c, _d, _e, _f;
|
|
340
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
318
341
|
if (!this.activePointer || this.activePointer.id !== event.id) {
|
|
319
342
|
return;
|
|
320
343
|
}
|
|
@@ -337,12 +360,26 @@ export class DiagramInteractionController {
|
|
|
337
360
|
}
|
|
338
361
|
if (this.tool === "drag-edge-endpoint" && this.edgeEndpointId && this.edgeEndpointKind && this.edgeEndpointPreview
|
|
339
362
|
&& (this.edgeEndpointPreview.x !== ((_d = this.edgeEndpointStart) === null || _d === void 0 ? void 0 : _d.x) || this.edgeEndpointPreview.y !== ((_e = this.edgeEndpointStart) === null || _e === void 0 ? void 0 : _e.y))) {
|
|
340
|
-
this.engine.
|
|
363
|
+
const edge = this.engine.getScene().entities.edgesById.get(this.edgeEndpointId);
|
|
364
|
+
const commands = [{ type: "moveEdgeEndpoint", id: this.edgeEndpointId, endpoint: this.edgeEndpointKind, point: this.edgeEndpointPreview }];
|
|
365
|
+
if (edge && this.edgeWaypointPreview) {
|
|
366
|
+
for (let index = 0; index < this.edgeWaypointPreview.length; index += 1) {
|
|
367
|
+
const point = this.edgeWaypointPreview[index];
|
|
368
|
+
const previous = (_f = edge.points) === null || _f === void 0 ? void 0 : _f[index];
|
|
369
|
+
if (!previous || previous.x !== point.x || previous.y !== point.y) {
|
|
370
|
+
commands.push({ type: "moveEdgeWaypoint", id: this.edgeEndpointId, index, point });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (commands.length > 1)
|
|
375
|
+
this.engine.dispatchBatch(commands);
|
|
376
|
+
else
|
|
377
|
+
this.engine.dispatch(commands[0]);
|
|
341
378
|
this.commitCount += 1;
|
|
342
379
|
}
|
|
343
380
|
if (this.tool === "marquee" && this.marquee) {
|
|
344
381
|
const ids = this.getMarqueeSelectionIds(this.marquee);
|
|
345
|
-
this.engine.dispatch({ type: "setSelection", selection: { ids, primaryId: (
|
|
382
|
+
this.engine.dispatch({ type: "setSelection", selection: { ids, primaryId: (_g = ids[0]) !== null && _g !== void 0 ? _g : null }, mode: this.activePointer.shiftKey ? "add" : "replace" });
|
|
346
383
|
this.commitCount += 1;
|
|
347
384
|
}
|
|
348
385
|
this.clearGesture();
|
|
@@ -356,13 +393,14 @@ export class DiagramInteractionController {
|
|
|
356
393
|
}
|
|
357
394
|
/** Returns the renderer-ready geometry for the active move preview. */
|
|
358
395
|
getPreviewGeometry(id) {
|
|
359
|
-
var _a, _b, _c, _d;
|
|
396
|
+
var _a, _b, _c, _d, _e;
|
|
360
397
|
const geometry = this.engine.getGeometrySnapshot(id);
|
|
361
398
|
if ((geometry === null || geometry === void 0 ? void 0 : geometry.kind) === "edge" && ((_a = geometry.path) === null || _a === void 0 ? void 0 : _a.length) && this.edgeEndpointId === id && this.edgeEndpointKind && this.edgeEndpointPreview) {
|
|
362
|
-
const path =
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
399
|
+
const path = [
|
|
400
|
+
this.edgeEndpointKind === "source" ? this.edgeEndpointPreview : geometry.path[0],
|
|
401
|
+
...((_b = this.edgeWaypointPreview) !== null && _b !== void 0 ? _b : geometry.path.slice(1, -1)),
|
|
402
|
+
this.edgeEndpointKind === "target" ? this.edgeEndpointPreview : geometry.path[geometry.path.length - 1],
|
|
403
|
+
];
|
|
366
404
|
const bounds = boundsFromPoints(path);
|
|
367
405
|
return Object.freeze({ ...geometry, path: Object.freeze(path), bounds, hitBounds: inflateRect(bounds, 6) });
|
|
368
406
|
}
|
|
@@ -372,7 +410,7 @@ export class DiagramInteractionController {
|
|
|
372
410
|
const edge = scene.entities.edgesById.get(id);
|
|
373
411
|
if (geometry.kind === "edge" && edge) {
|
|
374
412
|
const delta = this.previewDelta;
|
|
375
|
-
const moved = new Set(this.
|
|
413
|
+
const moved = new Set(this.expandedDragSelectionIds());
|
|
376
414
|
const endpointMoves = (endpoint) => {
|
|
377
415
|
var _a, _b;
|
|
378
416
|
return endpoint.kind === "point"
|
|
@@ -381,7 +419,7 @@ export class DiagramInteractionController {
|
|
|
381
419
|
? moved.has(endpoint.nodeId)
|
|
382
420
|
: moved.has((_b = (_a = scene.entities.portsById.get(endpoint.portId)) === null || _a === void 0 ? void 0 : _a.nodeId) !== null && _b !== void 0 ? _b : "");
|
|
383
421
|
};
|
|
384
|
-
const path = (
|
|
422
|
+
const path = (_c = geometry.path) === null || _c === void 0 ? void 0 : _c.map((point, index) => {
|
|
385
423
|
var _a, _b;
|
|
386
424
|
const isSource = index === 0;
|
|
387
425
|
const isTarget = index === ((_b = (_a = geometry.path) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1;
|
|
@@ -396,7 +434,7 @@ export class DiagramInteractionController {
|
|
|
396
434
|
return Object.freeze({ ...geometry, path: Object.freeze(path), bounds, hitBounds: inflateRect(bounds, 6) });
|
|
397
435
|
}
|
|
398
436
|
}
|
|
399
|
-
if (!this.
|
|
437
|
+
if (!this.isDraggedEntity(id))
|
|
400
438
|
return geometry;
|
|
401
439
|
const move = (point) => ({ x: point.x + this.previewDelta.x, y: point.y + this.previewDelta.y });
|
|
402
440
|
return Object.freeze({
|
|
@@ -404,8 +442,8 @@ export class DiagramInteractionController {
|
|
|
404
442
|
bounds: { ...geometry.bounds, x: geometry.bounds.x + this.previewDelta.x, y: geometry.bounds.y + this.previewDelta.y },
|
|
405
443
|
hitBounds: { ...geometry.hitBounds, x: geometry.hitBounds.x + this.previewDelta.x, y: geometry.hitBounds.y + this.previewDelta.y },
|
|
406
444
|
unrotatedBounds: geometry.unrotatedBounds ? { ...geometry.unrotatedBounds, x: geometry.unrotatedBounds.x + this.previewDelta.x, y: geometry.unrotatedBounds.y + this.previewDelta.y } : undefined,
|
|
407
|
-
corners: (
|
|
408
|
-
path: (
|
|
445
|
+
corners: (_d = geometry.corners) === null || _d === void 0 ? void 0 : _d.map(move),
|
|
446
|
+
path: (_e = geometry.path) === null || _e === void 0 ? void 0 : _e.map(move),
|
|
409
447
|
point: geometry.point ? move(geometry.point) : undefined,
|
|
410
448
|
});
|
|
411
449
|
}
|
|
@@ -447,7 +485,8 @@ export class DiagramInteractionController {
|
|
|
447
485
|
const viewport = this.engine.getScene().viewport;
|
|
448
486
|
const zoom = viewport.zoom > 0 ? viewport.zoom : 1;
|
|
449
487
|
const selection = this.engine.getScene().selection;
|
|
450
|
-
const
|
|
488
|
+
const snapIds = [...new Set([...this.dragSelectionIds, ...this.expandedDragSelectionIds()])];
|
|
489
|
+
const snapped = this.engine.snapTranslation({ ...selection, ids: snapIds, primaryId: this.dragSelectionIds.includes((_b = selection.primaryId) !== null && _b !== void 0 ? _b : "") ? selection.primaryId : (_c = this.dragSelectionIds[0]) !== null && _c !== void 0 ? _c : null }, constrainedDelta, {
|
|
451
490
|
radius: ((_d = this.snapOptions.tolerancePx) !== null && _d !== void 0 ? _d : 6) / zoom,
|
|
452
491
|
gridSize: this.snapOptions.gridSize,
|
|
453
492
|
axisConstraint,
|
|
@@ -473,18 +512,18 @@ export class DiagramInteractionController {
|
|
|
473
512
|
if (!this.edgeEndpointStart)
|
|
474
513
|
return;
|
|
475
514
|
const origin = this.edgeEndpointStart;
|
|
476
|
-
const
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
515
|
+
const angle = this.latestShiftKey ? this.edgeEndpointCardinalAngle : null;
|
|
516
|
+
const axisConstraint = angle === null ? undefined : angle === 0 || angle === 180 ? "x" : "y";
|
|
517
|
+
let desiredPoint = angle === null
|
|
518
|
+
? this.latestPoint
|
|
519
|
+
: projectToCardinal((_g = this.edgeEndpointOppositeStart) !== null && _g !== void 0 ? _g : origin, this.latestPoint, angle);
|
|
481
520
|
if (this.snapOptions.enabled === false) {
|
|
482
521
|
this.edgeEndpointPreview = desiredPoint;
|
|
483
522
|
}
|
|
484
523
|
else {
|
|
485
524
|
const viewport = this.engine.getScene().viewport;
|
|
486
525
|
const zoom = viewport.zoom > 0 ? viewport.zoom : 1;
|
|
487
|
-
|
|
526
|
+
const snapped = this.engine.snapPoint(desiredPoint, {
|
|
488
527
|
radius: ((_h = this.snapOptions.tolerancePx) !== null && _h !== void 0 ? _h : 6) / zoom,
|
|
489
528
|
gridSize: this.snapOptions.gridSize,
|
|
490
529
|
axisConstraint,
|
|
@@ -492,7 +531,11 @@ export class DiagramInteractionController {
|
|
|
492
531
|
snapToAlignment: this.snapOptions.snapToAlignment,
|
|
493
532
|
excludeIds: new Set(this.edgeEndpointId ? [this.edgeEndpointId] : []),
|
|
494
533
|
}).point;
|
|
534
|
+
this.edgeEndpointPreview = angle === null || !this.edgeEndpointOppositeStart
|
|
535
|
+
? snapped
|
|
536
|
+
: projectToCardinal(this.edgeEndpointOppositeStart, snapped, angle);
|
|
495
537
|
}
|
|
538
|
+
this.edgeWaypointPreview = this.createOrthogonalWaypointPreview(this.edgeEndpointPreview);
|
|
496
539
|
return;
|
|
497
540
|
}
|
|
498
541
|
if (this.tool === "marquee") {
|
|
@@ -554,33 +597,104 @@ export class DiagramInteractionController {
|
|
|
554
597
|
resizeGridSize() {
|
|
555
598
|
return !this.latestShiftKey || this.snapOptions.enabled === false ? undefined : this.snapOptions.gridSize;
|
|
556
599
|
}
|
|
600
|
+
expandedDragSelectionIds() {
|
|
601
|
+
var _a, _b;
|
|
602
|
+
const groups = this.engine.getScene().entities.groupsById;
|
|
603
|
+
const ids = new Set(this.dragSelectionIds);
|
|
604
|
+
for (const id of this.dragSelectionIds) {
|
|
605
|
+
for (const childId of (_b = (_a = groups.get(id)) === null || _a === void 0 ? void 0 : _a.childIds) !== null && _b !== void 0 ? _b : [])
|
|
606
|
+
ids.add(childId);
|
|
607
|
+
}
|
|
608
|
+
return [...ids];
|
|
609
|
+
}
|
|
610
|
+
isDraggedEntity(id) {
|
|
611
|
+
if (this.dragSelectionIds.includes(id))
|
|
612
|
+
return true;
|
|
613
|
+
const groups = this.engine.getScene().entities.groupsById;
|
|
614
|
+
return this.dragSelectionIds.some((groupId) => { var _a; return ((_a = groups.get(groupId)) === null || _a === void 0 ? void 0 : _a.childIds.includes(id)) === true; });
|
|
615
|
+
}
|
|
557
616
|
updateShiftAxis(shiftKey, point) {
|
|
558
617
|
const wasShifted = this.latestShiftKey;
|
|
559
618
|
this.latestShiftKey = shiftKey;
|
|
560
619
|
if (!shiftKey) {
|
|
561
620
|
this.shiftAxis = null;
|
|
621
|
+
this.edgeEndpointCardinalAngle = null;
|
|
562
622
|
return;
|
|
563
623
|
}
|
|
564
|
-
if (!wasShifted)
|
|
624
|
+
if (!wasShifted) {
|
|
565
625
|
this.shiftAxis = null;
|
|
566
|
-
|
|
626
|
+
this.edgeEndpointCardinalAngle = null;
|
|
627
|
+
}
|
|
628
|
+
if (this.tool === "drag-edge-endpoint") {
|
|
629
|
+
if (this.edgeEndpointCardinalAngle === null && this.edgeEndpointOppositeStart && this.startPoint && this.isPastAxisActivation(point, this.startPoint)) {
|
|
630
|
+
this.edgeEndpointCardinalAngle = nearestCardinalAngle(point, this.edgeEndpointOppositeStart);
|
|
631
|
+
}
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (this.shiftAxis || !this.startPoint || this.tool !== "drag-selection")
|
|
567
635
|
return;
|
|
568
636
|
const delta = { x: point.x - this.startPoint.x, y: point.y - this.startPoint.y };
|
|
569
|
-
|
|
570
|
-
const zoom = viewport.zoom > 0 ? viewport.zoom : 1;
|
|
571
|
-
if (Math.hypot(delta.x, delta.y) * zoom < AXIS_LOCK_ACTIVATION_TOLERANCE_PX)
|
|
637
|
+
if (!this.isPastAxisActivation(point, this.startPoint))
|
|
572
638
|
return;
|
|
573
639
|
this.shiftAxis = Math.abs(delta.x) >= Math.abs(delta.y) ? "x" : "y";
|
|
574
640
|
}
|
|
641
|
+
isPastAxisActivation(point, origin) {
|
|
642
|
+
const viewport = this.engine.getScene().viewport;
|
|
643
|
+
const zoom = viewport.zoom > 0 ? viewport.zoom : 1;
|
|
644
|
+
return Math.hypot(point.x - origin.x, point.y - origin.y) * zoom >= AXIS_LOCK_ACTIVATION_TOLERANCE_PX;
|
|
645
|
+
}
|
|
646
|
+
createOrthogonalWaypointPreview(endpoint) {
|
|
647
|
+
if (!endpoint || !this.edgeEndpointId || !this.edgeEndpointKind)
|
|
648
|
+
return null;
|
|
649
|
+
const edge = this.engine.getScene().entities.edgesById.get(this.edgeEndpointId);
|
|
650
|
+
const points = edge === null || edge === void 0 ? void 0 : edge.points;
|
|
651
|
+
if (!edge || !(points === null || points === void 0 ? void 0 : points.length))
|
|
652
|
+
return points !== null && points !== void 0 ? points : null;
|
|
653
|
+
const geometry = this.engine.getGeometrySnapshot(this.edgeEndpointId);
|
|
654
|
+
const path = geometry === null || geometry === void 0 ? void 0 : geometry.path;
|
|
655
|
+
if (!(path === null || path === void 0 ? void 0 : path.length) || !isOrthogonalPath(path))
|
|
656
|
+
return points;
|
|
657
|
+
const nextPoints = points.map((point) => ({ x: point.x, y: point.y }));
|
|
658
|
+
if (this.edgeEndpointKind === "source") {
|
|
659
|
+
const waypointIndex = 0;
|
|
660
|
+
const routeIndex = 1;
|
|
661
|
+
const inward = findDistinctPoint(path, routeIndex, 1);
|
|
662
|
+
if (!inward)
|
|
663
|
+
return nextPoints;
|
|
664
|
+
const segment = segmentAxis(path[routeIndex], inward);
|
|
665
|
+
if (segment === "horizontal")
|
|
666
|
+
nextPoints[waypointIndex] = { x: endpoint.x, y: inward.y };
|
|
667
|
+
else if (segment === "vertical")
|
|
668
|
+
nextPoints[waypointIndex] = { x: inward.x, y: endpoint.y };
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
const waypointIndex = points.length - 1;
|
|
672
|
+
const routeIndex = path.length - 2;
|
|
673
|
+
const inward = findDistinctPoint(path, routeIndex, -1);
|
|
674
|
+
if (!inward)
|
|
675
|
+
return nextPoints;
|
|
676
|
+
const segment = segmentAxis(inward, path[routeIndex]);
|
|
677
|
+
if (segment === "horizontal")
|
|
678
|
+
nextPoints[waypointIndex] = { x: endpoint.x, y: inward.y };
|
|
679
|
+
else if (segment === "vertical")
|
|
680
|
+
nextPoints[waypointIndex] = { x: inward.x, y: endpoint.y };
|
|
681
|
+
}
|
|
682
|
+
return nextPoints;
|
|
683
|
+
}
|
|
575
684
|
getMarqueeSelectionIds(rect) {
|
|
576
685
|
const visible = new Set(this.engine.queryVisible(rect));
|
|
577
686
|
const scene = this.engine.getScene();
|
|
687
|
+
const groupedChildren = new Set([...scene.entities.groupsById.values()].flatMap((group) => group.childIds));
|
|
578
688
|
return [
|
|
689
|
+
...scene.order.groupIds,
|
|
579
690
|
...scene.order.nodeIds,
|
|
580
691
|
...scene.order.shapeIds,
|
|
692
|
+
...scene.order.tableIds,
|
|
581
693
|
...scene.order.textIds,
|
|
582
694
|
...scene.order.edgeIds,
|
|
583
695
|
].filter((id) => {
|
|
696
|
+
if (groupedChildren.has(id))
|
|
697
|
+
return false;
|
|
584
698
|
if (!visible.has(id))
|
|
585
699
|
return false;
|
|
586
700
|
if (this.marqueeMode === "intersect")
|
|
@@ -610,7 +724,10 @@ export class DiagramInteractionController {
|
|
|
610
724
|
this.edgeEndpointId = null;
|
|
611
725
|
this.edgeEndpointKind = null;
|
|
612
726
|
this.edgeEndpointStart = null;
|
|
727
|
+
this.edgeEndpointOppositeStart = null;
|
|
728
|
+
this.edgeEndpointCardinalAngle = null;
|
|
613
729
|
this.edgeEndpointPreview = null;
|
|
730
|
+
this.edgeWaypointPreview = null;
|
|
614
731
|
this.framePending = false;
|
|
615
732
|
this.pendingMoveCount = 0;
|
|
616
733
|
}
|
|
@@ -631,6 +748,57 @@ function rotateDelta(delta, rotation) {
|
|
|
631
748
|
const sin = Math.sin(angle);
|
|
632
749
|
return { x: delta.x * cos - delta.y * sin, y: delta.x * sin + delta.y * cos };
|
|
633
750
|
}
|
|
751
|
+
function nearestCardinalAngle(point, origin) {
|
|
752
|
+
const degrees = (Math.atan2(point.y - origin.y, point.x - origin.x) * 180 / Math.PI + 360) % 360;
|
|
753
|
+
const candidates = [0, 180, 90, 270];
|
|
754
|
+
let nearest = candidates[0];
|
|
755
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
756
|
+
for (const candidate of candidates) {
|
|
757
|
+
const difference = Math.abs(degrees - candidate);
|
|
758
|
+
const distance = Math.min(difference, 360 - difference);
|
|
759
|
+
if (distance < nearestDistance) {
|
|
760
|
+
nearest = candidate;
|
|
761
|
+
nearestDistance = distance;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return nearest;
|
|
765
|
+
}
|
|
766
|
+
function projectToCardinal(origin, point, angle) {
|
|
767
|
+
const distance = Math.hypot(point.x - origin.x, point.y - origin.y);
|
|
768
|
+
switch (angle) {
|
|
769
|
+
case 0: return { x: origin.x + distance, y: origin.y };
|
|
770
|
+
case 90: return { x: origin.x, y: origin.y + distance };
|
|
771
|
+
case 180: return { x: origin.x - distance, y: origin.y };
|
|
772
|
+
case 270: return { x: origin.x, y: origin.y - distance };
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function segmentAxis(start, end) {
|
|
776
|
+
if (Math.abs(start.y - end.y) <= 1e-6)
|
|
777
|
+
return "horizontal";
|
|
778
|
+
if (Math.abs(start.x - end.x) <= 1e-6)
|
|
779
|
+
return "vertical";
|
|
780
|
+
return null;
|
|
781
|
+
}
|
|
782
|
+
function isOrthogonalPath(path) {
|
|
783
|
+
for (let index = 1; index < path.length; index += 1) {
|
|
784
|
+
if (!segmentAxis(path[index - 1], path[index]))
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
789
|
+
function findDistinctPoint(path, index, step) {
|
|
790
|
+
const origin = path[index];
|
|
791
|
+
if (!origin)
|
|
792
|
+
return null;
|
|
793
|
+
for (let nextIndex = index + step; nextIndex >= 0 && nextIndex < path.length; nextIndex += step) {
|
|
794
|
+
const next = path[nextIndex];
|
|
795
|
+
if (Math.abs(origin.x - next.x) <= 1e-6 && Math.abs(origin.y - next.y) <= 1e-6)
|
|
796
|
+
continue;
|
|
797
|
+
if (segmentAxis(origin, next))
|
|
798
|
+
return next;
|
|
799
|
+
}
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
634
802
|
function resizeBoundsByHandle(bounds, handle, delta, minSize, preserveAspectRatio = false, gridSize) {
|
|
635
803
|
let x = bounds.x;
|
|
636
804
|
let y = bounds.y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagramClipboardService.d.ts","sourceRoot":"","sources":["../../src/internal/DiagramClipboardService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"DiagramClipboardService.d.ts","sourceRoot":"","sources":["../../src/internal/DiagramClipboardService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAkD,SAAS,EAAe,YAAY,EAAE,gBAAgB,EAA2C,MAAM,aAAa,CAAA;AACpM,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEtD,KAAK,kBAAkB,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,KAAK,CAAA;AAClE,KAAK,kBAAkB,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,SAAS,KAAK,gBAAgB,CAAA;AAEhG,qBAAa,uBAAuB;IAClC,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,kBAAkB,EAAE,kBAAkB,GAAG,gBAAgB;IA2C7H,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,GAAG,KAAK,GAAG,IAAI;CAkCvL"}
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
export class DiagramClipboardService {
|
|
2
2
|
exportSubgraph(state, ids, normalizeSelection) {
|
|
3
|
-
const selected = new Set(
|
|
3
|
+
const selected = new Set();
|
|
4
|
+
for (const id of ids) {
|
|
5
|
+
const group = state.entities.groupsById.get(id);
|
|
6
|
+
if (group) {
|
|
7
|
+
selected.add(id);
|
|
8
|
+
for (const childId of group.childIds)
|
|
9
|
+
selected.add(childId);
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const owner = [...state.entities.groupsById.values()].find((candidate) => candidate.childIds.includes(id));
|
|
13
|
+
if (owner) {
|
|
14
|
+
selected.add(owner.id);
|
|
15
|
+
for (const childId of owner.childIds)
|
|
16
|
+
selected.add(childId);
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
selected.add(id);
|
|
20
|
+
}
|
|
21
|
+
const groups = state.order.groupIds
|
|
22
|
+
.map((id) => state.entities.groupsById.get(id))
|
|
23
|
+
.filter((group) => group !== undefined && selected.has(group.id));
|
|
4
24
|
const nodes = state.order.nodeIds
|
|
5
25
|
.map((id) => state.entities.nodesById.get(id))
|
|
6
26
|
.filter((entity) => entity !== undefined && selected.has(entity.id));
|
|
@@ -19,30 +39,36 @@ export class DiagramClipboardService {
|
|
|
19
39
|
shapes: state.order.shapeIds
|
|
20
40
|
.map((id) => state.entities.shapesById.get(id))
|
|
21
41
|
.filter((entity) => entity !== undefined && selected.has(entity.id)),
|
|
42
|
+
tables: state.order.tableIds.map((id) => state.entities.tablesById.get(id)).filter((entity) => entity !== undefined && selected.has(entity.id)),
|
|
43
|
+
groups,
|
|
22
44
|
selection: normalizeSelection({ ids: [...selected], primaryId: state.selection.primaryId }),
|
|
23
45
|
viewport: state.viewport,
|
|
24
46
|
};
|
|
25
47
|
}
|
|
26
48
|
createPastePatch(state, clipboard, offset, createDeletePatch, normalizeSelection) {
|
|
49
|
+
var _a, _b, _c, _d;
|
|
27
50
|
const remap = new Map();
|
|
28
51
|
const reserve = (id) => {
|
|
29
52
|
const next = uniqueId(state, `${id}-copy`, remap.size + 1);
|
|
30
53
|
remap.set(id, next);
|
|
31
54
|
return next;
|
|
32
55
|
};
|
|
33
|
-
for (const entity of [...clipboard.nodes, ...clipboard.ports, ...clipboard.edges, ...clipboard.texts, ...clipboard.shapes])
|
|
56
|
+
for (const entity of [...clipboard.nodes, ...clipboard.ports, ...clipboard.edges, ...clipboard.texts, ...clipboard.shapes, ...((_a = clipboard.groups) !== null && _a !== void 0 ? _a : []), ...((_b = clipboard.tables) !== null && _b !== void 0 ? _b : [])])
|
|
34
57
|
reserve(entity.id);
|
|
35
58
|
const nodes = clipboard.nodes.map((node) => { var _a; return ({ ...node, id: remap.get(node.id), x: node.x + offset.x, y: node.y + offset.y, portIds: (_a = node.portIds) === null || _a === void 0 ? void 0 : _a.map((id) => { var _a; return (_a = remap.get(id)) !== null && _a !== void 0 ? _a : id; }) }); });
|
|
36
59
|
const ports = clipboard.ports.map((port) => { var _a; return ({ ...port, id: remap.get(port.id), nodeId: (_a = remap.get(port.nodeId)) !== null && _a !== void 0 ? _a : port.nodeId }); });
|
|
37
60
|
const edges = clipboard.edges.map((edge) => { var _a; return ({ ...edge, id: remap.get(edge.id), source: remapEndpoint(edge.source, remap), target: remapEndpoint(edge.target, remap), points: (_a = edge.points) === null || _a === void 0 ? void 0 : _a.map((point) => ({ x: point.x + offset.x, y: point.y + offset.y })) }); });
|
|
38
61
|
const texts = clipboard.texts.map((text) => ({ ...text, id: remap.get(text.id), x: text.x + offset.x, y: text.y + offset.y }));
|
|
39
62
|
const shapes = clipboard.shapes.map((shape) => ({ ...shape, id: remap.get(shape.id), x: shape.x + offset.x, y: shape.y + offset.y }));
|
|
40
|
-
const
|
|
63
|
+
const groups = ((_c = clipboard.groups) !== null && _c !== void 0 ? _c : []).map((group) => ({ ...group, id: remap.get(group.id), childIds: group.childIds.map((id) => { var _a; return (_a = remap.get(id)) !== null && _a !== void 0 ? _a : id; }) }));
|
|
64
|
+
const tables = ((_d = clipboard.tables) !== null && _d !== void 0 ? _d : []).map((table) => ({ ...table, id: remap.get(table.id), x: table.x + offset.x, y: table.y + offset.y }));
|
|
65
|
+
const pastedIds = [...nodes, ...ports, ...edges, ...texts, ...shapes, ...groups, ...tables].map((entity) => entity.id);
|
|
41
66
|
if (!pastedIds.length)
|
|
42
67
|
return null;
|
|
43
68
|
return {
|
|
69
|
+
orderChanged: true,
|
|
44
70
|
apply: (next) => {
|
|
45
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
71
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
46
72
|
for (const node of nodes) {
|
|
47
73
|
next.entities.nodesById.set(node.id, node);
|
|
48
74
|
next.order.nodeIds.push(node.id);
|
|
@@ -67,7 +93,18 @@ export class DiagramClipboardService {
|
|
|
67
93
|
next.order.shapeIds.push(shape.id);
|
|
68
94
|
next.versions.set(shape.id, 0);
|
|
69
95
|
}
|
|
70
|
-
|
|
96
|
+
for (const group of groups) {
|
|
97
|
+
next.entities.groupsById.set(group.id, group);
|
|
98
|
+
next.order.groupIds.push(group.id);
|
|
99
|
+
next.versions.set(group.id, 0);
|
|
100
|
+
}
|
|
101
|
+
for (const table of tables) {
|
|
102
|
+
next.entities.tablesById.set(table.id, table);
|
|
103
|
+
next.order.tableIds.push(table.id);
|
|
104
|
+
next.versions.set(table.id, 0);
|
|
105
|
+
}
|
|
106
|
+
const selectedIds = groups.length ? groups.map((group) => group.id) : pastedIds.filter((id) => !next.entities.portsById.has(id));
|
|
107
|
+
next.selection = normalizeSelection({ ids: selectedIds, primaryId: (_k = (_h = (_f = (_d = (_b = (_a = groups[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : (_c = nodes[0]) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : (_e = texts[0]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : (_g = shapes[0]) === null || _g === void 0 ? void 0 : _g.id) !== null && _h !== void 0 ? _h : (_j = edges[0]) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : null });
|
|
71
108
|
return new Set([...pastedIds, "selection"]);
|
|
72
109
|
},
|
|
73
110
|
inverse: createDeletePatch(pastedIds),
|
|
@@ -99,5 +136,5 @@ function uniqueId(state, base, seed) {
|
|
|
99
136
|
return id;
|
|
100
137
|
}
|
|
101
138
|
function hasEntity(state, id) {
|
|
102
|
-
return state.entities.nodesById.has(id) || state.entities.edgesById.has(id) || state.entities.textsById.has(id) || state.entities.shapesById.has(id) || state.entities.portsById.has(id);
|
|
139
|
+
return state.entities.nodesById.has(id) || state.entities.edgesById.has(id) || state.entities.textsById.has(id) || state.entities.shapesById.has(id) || state.entities.portsById.has(id) || state.entities.groupsById.has(id) || state.entities.tablesById.has(id);
|
|
103
140
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagramSceneStore.d.ts","sourceRoot":"","sources":["../../src/internal/DiagramSceneStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,iBAAiB,EAAoB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEjI,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAA;AAIhE,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAiC;IACnE,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,UAAU,CAKjB;gBAEW,YAAY,GAAE,iBAAsB;IAKhD,WAAW,IAAI,YAAY;IAI3B,aAAa,IAAI,aAAa;IAI9B,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI;IAazF,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE;IAUnE,OAAO,CAAC,cAAc;
|
|
1
|
+
{"version":3,"file":"DiagramSceneStore.d.ts","sourceRoot":"","sources":["../../src/internal/DiagramSceneStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,iBAAiB,EAAoB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEjI,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAA;AAIhE,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAiC;IACnE,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,UAAU,CAKjB;gBAEW,YAAY,GAAE,iBAAsB;IAKhD,WAAW,IAAI,YAAY;IAI3B,aAAa,IAAI,aAAa;IAI9B,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI;IAazF,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE;IAUnE,OAAO,CAAC,cAAc;IA4BtB,OAAO,CAAC,iBAAiB;CAO1B;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAoC3E"}
|