@affino/diagram-core 0.1.0 → 0.3.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 +17 -3
- package/dist/DiagramEngine.d.ts +13 -3
- package/dist/DiagramEngine.d.ts.map +1 -1
- package/dist/DiagramEngine.js +161 -46
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/interaction.d.ts +5 -1
- package/dist/interaction.d.ts.map +1 -1
- package/dist/interaction.js +42 -4
- package/dist/internal/DiagramHistory.d.ts +4 -0
- package/dist/internal/DiagramHistory.d.ts.map +1 -1
- package/dist/internal/DiagramHistory.js +23 -1
- package/dist/internal/DiagramSceneStore.d.ts +2 -0
- package/dist/internal/DiagramSceneStore.d.ts.map +1 -1
- package/dist/internal/DiagramSceneStore.js +138 -15
- package/dist/internal/DiagramSpatialIndex.d.ts +1 -0
- package/dist/internal/DiagramSpatialIndex.d.ts.map +1 -1
- package/dist/internal/DiagramSpatialIndex.js +12 -0
- package/dist/internal/DiagramViewportService.js +15 -6
- package/dist/internal/model.d.ts +1 -0
- package/dist/internal/model.d.ts.map +1 -1
- package/dist/spatialIndex.d.ts +4 -0
- package/dist/spatialIndex.d.ts.map +1 -1
- package/dist/spatialIndex.js +67 -2
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/viewport.d.ts +7 -0
- package/dist/viewport.d.ts.map +1 -0
- package/dist/viewport.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,8 +24,13 @@ const engine = createDiagramEngine({
|
|
|
24
24
|
engine.dispatch({ type: "setSelection", selection: { ids: ["n1"], primaryId: "n1" } })
|
|
25
25
|
engine.dispatch({ type: "moveEntities", ids: ["n1"], delta: { x: 24, y: 0 } })
|
|
26
26
|
engine.dispatch({ type: "undo" })
|
|
27
|
+
|
|
28
|
+
// Bound retained undo memory for a long-lived editor session.
|
|
29
|
+
const boundedEngine = createDiagramEngine({}, { history: { maxEntries: 200 } })
|
|
27
30
|
```
|
|
28
31
|
|
|
32
|
+
`history.maxEntries` evicts the oldest undo entries first. It accepts a non-negative integer; `0` disables undo retention, while the default `Infinity` preserves the legacy unbounded behavior. An accepted edit clears redo, and `transact()` replaces the scene and resets history.
|
|
33
|
+
|
|
29
34
|
## Clipboard and duplication
|
|
30
35
|
|
|
31
36
|
Clipboard exports are scene-shaped and safe to persist or pass through app-level clipboard code. Import remaps all ids, offsets nodes/texts/shapes/edge waypoints, and remaps node port ids plus edge endpoints inside the selected subgraph.
|
|
@@ -44,9 +49,9 @@ Static text is data in core and should be rendered by adapters as SVG `<text>`/`
|
|
|
44
49
|
|
|
45
50
|
```ts
|
|
46
51
|
engine.dispatch({ type: "resizeEntities", entries: [{ id: "n1", width: 160, height: 80 }] }) // node-relative ports scale with the node
|
|
47
|
-
engine.dispatch({ type: "insertEdgeWaypoint",
|
|
48
|
-
engine.dispatch({ type: "moveEdgeWaypoint",
|
|
49
|
-
engine.dispatch({ type: "removeEdgeWaypoint",
|
|
52
|
+
engine.dispatch({ type: "insertEdgeWaypoint", id: "e1", index: 0, point: { x: 240, y: 120 } })
|
|
53
|
+
engine.dispatch({ type: "moveEdgeWaypoint", id: "e1", index: 0, point: { x: 260, y: 140 } })
|
|
54
|
+
engine.dispatch({ type: "removeEdgeWaypoint", id: "e1", index: 0 })
|
|
50
55
|
engine.dispatch({ type: "bringForward", ids: ["n1"] })
|
|
51
56
|
engine.dispatch({ type: "setLayer", ids: ["n1"], layer: "equipment", layerRole: "normal" })
|
|
52
57
|
engine.dispatch({ type: "rotateEntities", entries: [{ id: "n1", rotation: 90 }] }) // geometry exposes rotated bounds/corners
|
|
@@ -131,3 +136,12 @@ const diagnostics = engine.getDiagnostics()
|
|
|
131
136
|
```
|
|
132
137
|
|
|
133
138
|
Use `pnpm --filter @affino/diagram-core bench` after building to refresh `artifacts/performance/bench-diagram-core.json` and watch visible query, entity search/query, clipboard, routing, resize, fit, and command latency metrics.
|
|
139
|
+
|
|
140
|
+
## Viewport contract
|
|
141
|
+
|
|
142
|
+
- `x`/`y` are the world coordinate of the top-left visible point.
|
|
143
|
+
- `width`/`height` are visible world units, not CSS pixels. `zoom` is CSS pixels per world unit; the rendered stage size is `width * zoom` by `height * zoom`.
|
|
144
|
+
- Use `screenToWorld`, `worldToScreen`, `zoomViewportAt`, and `zoomViewportCentered` for camera math. Fit preserves the CSS stage-size invariant.
|
|
145
|
+
- Empty or degenerate bounds are clamped to finite values.
|
|
146
|
+
|
|
147
|
+
Persist `viewport` with the scene. Restore it before attaching the adapter; a resize only updates world extent and never changes `x`, `y`, or `zoom`.
|
package/dist/DiagramEngine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DiagramChange, DiagramClipboard, DiagramCommand, DiagramCommandResult, DiagramDiagnostics, DiagramGeometry, DiagramHit, DiagramHitTestOptions, DiagramId, DiagramPoint, DiagramQueryOptions, DiagramRect, DiagramRenderOrderOptions, DiagramScene, DiagramSceneInput, DiagramSelection, DiagramKeyboardCommand, DiagramKeyboardOptions, DiagramSnapContext, DiagramSnapResult, DiagramSubscriber, SerializedDiagramScene } from "./types.js";
|
|
1
|
+
import type { DiagramChange, DiagramClipboard, DiagramCommand, DiagramCommandResult, DiagramDiagnostics, DiagramGeometry, DiagramHit, DiagramHitTestOptions, DiagramId, DiagramPoint, DiagramQueryOptions, DiagramRect, DiagramRenderOrderOptions, DiagramScene, DiagramSceneInput, DiagramEngineOptions, DiagramSelection, DiagramKeyboardCommand, DiagramKeyboardOptions, DiagramSnapContext, DiagramSnapResult, DiagramSubscriber, SerializedDiagramScene } from "./types.js";
|
|
2
2
|
export declare class DiagramEngine {
|
|
3
3
|
private store;
|
|
4
4
|
private state;
|
|
@@ -11,7 +11,16 @@ export declare class DiagramEngine {
|
|
|
11
11
|
private entityQueryCount;
|
|
12
12
|
private hitTestCount;
|
|
13
13
|
private lastCommandMs;
|
|
14
|
-
|
|
14
|
+
private orderIndexRevision;
|
|
15
|
+
private orderIndexCache;
|
|
16
|
+
private orderedIdsRevision;
|
|
17
|
+
private orderedIdsCache;
|
|
18
|
+
private dependencyIndexReady;
|
|
19
|
+
private dependencyEntityIds;
|
|
20
|
+
private portIdsByNode;
|
|
21
|
+
private edgeIdsByNode;
|
|
22
|
+
private edgeIdsByPort;
|
|
23
|
+
constructor(initialScene?: DiagramSceneInput, options?: DiagramEngineOptions);
|
|
15
24
|
getScene(): DiagramScene;
|
|
16
25
|
getLastChange(): DiagramChange;
|
|
17
26
|
getEntityVersion(id: DiagramId): number;
|
|
@@ -53,6 +62,7 @@ export declare class DiagramEngine {
|
|
|
53
62
|
private redo;
|
|
54
63
|
private commitPatch;
|
|
55
64
|
private collectInvalidatedIds;
|
|
65
|
+
private ensureDependencyIndex;
|
|
56
66
|
private getGeometry;
|
|
57
67
|
private rebuildIndexGeometries;
|
|
58
68
|
private ensureIndexes;
|
|
@@ -66,7 +76,7 @@ export declare class DiagramEngine {
|
|
|
66
76
|
private isEntityLockedOrReadOnly;
|
|
67
77
|
private isEntityNonDeletable;
|
|
68
78
|
}
|
|
69
|
-
export declare function createDiagramEngine(initialScene?: DiagramSceneInput): DiagramEngine;
|
|
79
|
+
export declare function createDiagramEngine(initialScene?: DiagramSceneInput, options?: DiagramEngineOptions): DiagramEngine;
|
|
70
80
|
export declare function serializeScene(scene: DiagramScene): SerializedDiagramScene;
|
|
71
81
|
export declare function deserializeScene(scene: SerializedDiagramScene): DiagramSceneInput;
|
|
72
82
|
//# sourceMappingURL=DiagramEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagramEngine.d.ts","sourceRoot":"","sources":["../src/DiagramEngine.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAIlB,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,SAAS,EACT,YA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AO,CAAC,aAAa;IASrB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,wBAAwB;IAKhC,OAAO,CAAC,oBAAoB;CAG7B;AAsED,wBAAgB,mBAAmB,CAAC,YAAY,GAAE,iBAAsB,EAAE,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAE3H;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,GAAG,sBAAsB,CAU1E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,sBAAsB,GAAG,iBAAiB,CAEjF"}
|
package/dist/DiagramEngine.js
CHANGED
|
@@ -7,7 +7,7 @@ import { DiagramSpatialIndex } from "./internal/DiagramSpatialIndex.js";
|
|
|
7
7
|
import { DiagramViewportService } from "./internal/DiagramViewportService.js";
|
|
8
8
|
import { EMPTY_SELECTION } from "./internal/model.js";
|
|
9
9
|
export class DiagramEngine {
|
|
10
|
-
constructor(initialScene = {}) {
|
|
10
|
+
constructor(initialScene = {}, options = {}) {
|
|
11
11
|
Object.defineProperty(this, "store", {
|
|
12
12
|
enumerable: true,
|
|
13
13
|
configurable: true,
|
|
@@ -36,7 +36,7 @@ export class DiagramEngine {
|
|
|
36
36
|
enumerable: true,
|
|
37
37
|
configurable: true,
|
|
38
38
|
writable: true,
|
|
39
|
-
value:
|
|
39
|
+
value: void 0
|
|
40
40
|
});
|
|
41
41
|
Object.defineProperty(this, "viewportService", {
|
|
42
42
|
enumerable: true,
|
|
@@ -74,6 +74,61 @@ export class DiagramEngine {
|
|
|
74
74
|
writable: true,
|
|
75
75
|
value: 0
|
|
76
76
|
});
|
|
77
|
+
Object.defineProperty(this, "orderIndexRevision", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: -1
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(this, "orderIndexCache", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: new Map()
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "orderedIdsRevision", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: -1
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(this, "orderedIdsCache", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: []
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(this, "dependencyIndexReady", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true,
|
|
105
|
+
value: false
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(this, "dependencyEntityIds", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: new Set()
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "portIdsByNode", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: new Map()
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "edgeIdsByNode", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: new Map()
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(this, "edgeIdsByPort", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: new Map()
|
|
130
|
+
});
|
|
131
|
+
this.history = new DiagramHistory(options.history);
|
|
77
132
|
this.store = new DiagramSceneStore(initialScene);
|
|
78
133
|
this.state = this.store.state;
|
|
79
134
|
this.ensureIndexes();
|
|
@@ -121,6 +176,7 @@ export class DiagramEngine {
|
|
|
121
176
|
transact(mutator) {
|
|
122
177
|
const next = mutator(this.store.getSnapshot());
|
|
123
178
|
const patch = createReplaceScenePatch(next, serializeScene(this.store.getSnapshot()));
|
|
179
|
+
this.history.clear();
|
|
124
180
|
const result = this.commitPatch(patch, false, null);
|
|
125
181
|
return { changed: result.changedIds.size > 0, revision: this.state.revision };
|
|
126
182
|
}
|
|
@@ -141,6 +197,9 @@ export class DiagramEngine {
|
|
|
141
197
|
queryEntities(options = {}) {
|
|
142
198
|
var _a, _b;
|
|
143
199
|
this.entityQueryCount += 1;
|
|
200
|
+
if (options.limit !== undefined && options.limit <= 0) {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
144
203
|
this.ensureIndexes();
|
|
145
204
|
const kinds = options.kinds ? new Set(options.kinds) : null;
|
|
146
205
|
const includePorts = options.includePorts === true || (kinds === null || kinds === void 0 ? void 0 : kinds.has("port")) === true;
|
|
@@ -148,9 +207,12 @@ export class DiagramEngine {
|
|
|
148
207
|
const metadata = (_a = options.metadata) !== null && _a !== void 0 ? _a : null;
|
|
149
208
|
const order = this.createOrderIndex();
|
|
150
209
|
const sourceIds = options.bounds ? this.spatialIndex.queryVisible(options.bounds) : this.createOrderedIds();
|
|
210
|
+
const orderedSourceIds = options.bounds
|
|
211
|
+
? sourceIds.sort((a, b) => { var _a, _b; return ((_a = order.get(a)) !== null && _a !== void 0 ? _a : 0) - ((_b = order.get(b)) !== null && _b !== void 0 ? _b : 0); })
|
|
212
|
+
: sourceIds;
|
|
151
213
|
const result = [];
|
|
152
214
|
const seen = new Set();
|
|
153
|
-
for (const id of
|
|
215
|
+
for (const id of orderedSourceIds) {
|
|
154
216
|
if (seen.has(id)) {
|
|
155
217
|
continue;
|
|
156
218
|
}
|
|
@@ -256,7 +318,7 @@ export class DiagramEngine {
|
|
|
256
318
|
return { point: geometry.point, snapped: true, source: "port" };
|
|
257
319
|
}
|
|
258
320
|
}
|
|
259
|
-
const aligned = this.snapToAlignment(point, (_d = context.radius) !== null && _d !== void 0 ? _d : 6);
|
|
321
|
+
const aligned = this.snapToAlignment(point, (_d = context.radius) !== null && _d !== void 0 ? _d : 6, context.excludeIds);
|
|
260
322
|
if (aligned) {
|
|
261
323
|
return { point: aligned, snapped: true, source: "alignment" };
|
|
262
324
|
}
|
|
@@ -364,8 +426,8 @@ export class DiagramEngine {
|
|
|
364
426
|
if (!entry) {
|
|
365
427
|
return { changed: false, revision: this.state.revision };
|
|
366
428
|
}
|
|
367
|
-
const result = this.commitPatch(entry.inverse, false, null);
|
|
368
429
|
this.history.pushRedo(entry);
|
|
430
|
+
const result = this.commitPatch(entry.inverse, false, null);
|
|
369
431
|
return { changed: result.changedIds.size > 0, revision: this.state.revision };
|
|
370
432
|
}
|
|
371
433
|
redo() {
|
|
@@ -373,8 +435,8 @@ export class DiagramEngine {
|
|
|
373
435
|
if (!entry) {
|
|
374
436
|
return { changed: false, revision: this.state.revision };
|
|
375
437
|
}
|
|
376
|
-
const result = this.commitPatch(entry.patch, false, null);
|
|
377
438
|
this.history.pushUndo(entry);
|
|
439
|
+
const result = this.commitPatch(entry.patch, false, null);
|
|
378
440
|
return { changed: result.changedIds.size > 0, revision: this.state.revision };
|
|
379
441
|
}
|
|
380
442
|
commitPatch(patch, recordHistory, historyKey) {
|
|
@@ -383,46 +445,79 @@ export class DiagramEngine {
|
|
|
383
445
|
if (!changedIds.size) {
|
|
384
446
|
return { changedIds, invalidatedIds: new Set() };
|
|
385
447
|
}
|
|
448
|
+
this.ensureDependencyIndex(changedIds);
|
|
386
449
|
const invalidatedIds = this.collectInvalidatedIds(changedIds);
|
|
387
450
|
for (const id of invalidatedIds) {
|
|
388
451
|
this.state.versions.set(id, ((_a = this.state.versions.get(id)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
389
452
|
}
|
|
390
453
|
this.state.revision += 1;
|
|
391
454
|
this.geometryService.invalidate(invalidatedIds);
|
|
392
|
-
|
|
393
|
-
this.
|
|
455
|
+
const invalidatedGeometryIds = [...invalidatedIds];
|
|
456
|
+
this.spatialIndex.update(invalidatedGeometryIds
|
|
457
|
+
.map((id) => { var _a; return this.geometryService.get(id, this.state.entities, (_a = this.state.versions.get(id)) !== null && _a !== void 0 ? _a : 0); })
|
|
458
|
+
.filter((geometry) => geometry !== null), invalidatedGeometryIds.filter((id) => !this.hasEntity(id)));
|
|
394
459
|
if (recordHistory) {
|
|
395
460
|
this.history.record(patch, historyKey, composePatches);
|
|
396
461
|
}
|
|
462
|
+
this.store.publish(changedIds, invalidatedIds);
|
|
397
463
|
return { changedIds, invalidatedIds };
|
|
398
464
|
}
|
|
399
465
|
collectInvalidatedIds(changedIds) {
|
|
466
|
+
var _a, _b, _c;
|
|
400
467
|
const invalidated = new Set(changedIds);
|
|
401
468
|
for (const id of changedIds) {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
if (port.nodeId === id) {
|
|
405
|
-
invalidated.add(port.id);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
for (const edge of this.state.entities.edgesById.values()) {
|
|
409
|
-
if (edgeReferencesNode(edge, id, this.state.entities.portsById)) {
|
|
410
|
-
invalidated.add(edge.id);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
469
|
+
for (const portId of (_a = this.portIdsByNode.get(id)) !== null && _a !== void 0 ? _a : []) {
|
|
470
|
+
invalidated.add(portId);
|
|
413
471
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
472
|
+
for (const edgeId of (_b = this.edgeIdsByNode.get(id)) !== null && _b !== void 0 ? _b : []) {
|
|
473
|
+
invalidated.add(edgeId);
|
|
474
|
+
}
|
|
475
|
+
for (const edgeId of (_c = this.edgeIdsByPort.get(id)) !== null && _c !== void 0 ? _c : []) {
|
|
476
|
+
invalidated.add(edgeId);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return invalidated;
|
|
480
|
+
}
|
|
481
|
+
ensureDependencyIndex(changedIds) {
|
|
482
|
+
let rebuild = !this.dependencyIndexReady;
|
|
483
|
+
for (const id of changedIds) {
|
|
484
|
+
const exists = this.hasEntity(id);
|
|
485
|
+
if (this.dependencyEntityIds.has(id) !== exists || this.state.entities.edgesById.has(id) || this.state.entities.portsById.has(id)) {
|
|
486
|
+
rebuild = true;
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (!rebuild) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
this.dependencyEntityIds = new Set([
|
|
494
|
+
...this.state.entities.nodesById.keys(),
|
|
495
|
+
...this.state.entities.edgesById.keys(),
|
|
496
|
+
...this.state.entities.textsById.keys(),
|
|
497
|
+
...this.state.entities.shapesById.keys(),
|
|
498
|
+
...this.state.entities.portsById.keys(),
|
|
499
|
+
]);
|
|
500
|
+
this.portIdsByNode = new Map();
|
|
501
|
+
this.edgeIdsByNode = new Map();
|
|
502
|
+
this.edgeIdsByPort = new Map();
|
|
503
|
+
for (const port of this.state.entities.portsById.values()) {
|
|
504
|
+
addDependency(this.portIdsByNode, port.nodeId, port.id);
|
|
505
|
+
}
|
|
506
|
+
for (const edge of this.state.entities.edgesById.values()) {
|
|
507
|
+
for (const endpoint of [edge.source, edge.target]) {
|
|
508
|
+
if (endpoint.kind === "node") {
|
|
509
|
+
addDependency(this.edgeIdsByNode, endpoint.nodeId, edge.id);
|
|
510
|
+
}
|
|
511
|
+
else if (endpoint.kind === "port") {
|
|
512
|
+
addDependency(this.edgeIdsByPort, endpoint.portId, edge.id);
|
|
513
|
+
const port = this.state.entities.portsById.get(endpoint.portId);
|
|
514
|
+
if (port) {
|
|
515
|
+
addDependency(this.edgeIdsByNode, port.nodeId, edge.id);
|
|
421
516
|
}
|
|
422
517
|
}
|
|
423
518
|
}
|
|
424
519
|
}
|
|
425
|
-
|
|
520
|
+
this.dependencyIndexReady = true;
|
|
426
521
|
}
|
|
427
522
|
getGeometry(id) {
|
|
428
523
|
var _a;
|
|
@@ -480,13 +575,16 @@ export class DiagramEngine {
|
|
|
480
575
|
case "setSelection":
|
|
481
576
|
return createSelectionPatch(this.state.selection, command.selection, (_d = command.mode) !== null && _d !== void 0 ? _d : "replace");
|
|
482
577
|
case "editText":
|
|
483
|
-
return createEditTextPatch(this.state, command.id, command.text);
|
|
578
|
+
return this.canEditText(command.id) ? createEditTextPatch(this.state, command.id, command.text) : null;
|
|
484
579
|
case "setViewport":
|
|
485
580
|
return createViewportPatch(this.state.viewport, command.viewport);
|
|
486
581
|
}
|
|
487
582
|
}
|
|
488
|
-
snapToAlignment(point, radius) {
|
|
583
|
+
snapToAlignment(point, radius, excludeIds) {
|
|
489
584
|
for (const id of this.state.order.nodeIds) {
|
|
585
|
+
if (excludeIds === null || excludeIds === void 0 ? void 0 : excludeIds.has(id)) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
490
588
|
const geometry = this.getGeometry(id);
|
|
491
589
|
if (!geometry) {
|
|
492
590
|
continue;
|
|
@@ -502,6 +600,9 @@ export class DiagramEngine {
|
|
|
502
600
|
return null;
|
|
503
601
|
}
|
|
504
602
|
createOrderedIds() {
|
|
603
|
+
if (this.orderedIdsRevision === this.state.revision) {
|
|
604
|
+
return this.orderedIdsCache;
|
|
605
|
+
}
|
|
505
606
|
const ids = [
|
|
506
607
|
...this.state.order.edgeIds,
|
|
507
608
|
...this.state.order.shapeIds,
|
|
@@ -510,7 +611,7 @@ export class DiagramEngine {
|
|
|
510
611
|
...this.state.entities.portsById.keys(),
|
|
511
612
|
];
|
|
512
613
|
const baseOrder = new Map(ids.map((id, index) => [id, index]));
|
|
513
|
-
|
|
614
|
+
this.orderedIdsCache = ids.sort((a, b) => {
|
|
514
615
|
var _a, _b;
|
|
515
616
|
const layerDelta = layerRank(this.getEntityMetadata(a)) - layerRank(this.getEntityMetadata(b));
|
|
516
617
|
if (layerDelta) {
|
|
@@ -519,9 +620,15 @@ export class DiagramEngine {
|
|
|
519
620
|
const zDelta = zIndex(this.getEntityMetadata(a)) - zIndex(this.getEntityMetadata(b));
|
|
520
621
|
return zDelta || (((_a = baseOrder.get(a)) !== null && _a !== void 0 ? _a : 0) - ((_b = baseOrder.get(b)) !== null && _b !== void 0 ? _b : 0));
|
|
521
622
|
});
|
|
623
|
+
this.orderedIdsRevision = this.state.revision;
|
|
624
|
+
return this.orderedIdsCache;
|
|
522
625
|
}
|
|
523
626
|
createOrderIndex() {
|
|
524
|
-
|
|
627
|
+
if (this.orderIndexRevision !== this.state.revision) {
|
|
628
|
+
this.orderIndexCache = new Map(this.createOrderedIds().map((id, index) => [id, index]));
|
|
629
|
+
this.orderIndexRevision = this.state.revision;
|
|
630
|
+
}
|
|
631
|
+
return this.orderIndexCache;
|
|
525
632
|
}
|
|
526
633
|
hasEntity(id) {
|
|
527
634
|
return hasEntity(this.state, id);
|
|
@@ -614,8 +721,8 @@ function metadataValueMatches(actual, expected) {
|
|
|
614
721
|
}
|
|
615
722
|
return Object.is(actual, expected);
|
|
616
723
|
}
|
|
617
|
-
export function createDiagramEngine(initialScene = {}) {
|
|
618
|
-
return new DiagramEngine(initialScene);
|
|
724
|
+
export function createDiagramEngine(initialScene = {}, options = {}) {
|
|
725
|
+
return new DiagramEngine(initialScene, options);
|
|
619
726
|
}
|
|
620
727
|
export function serializeScene(scene) {
|
|
621
728
|
return {
|
|
@@ -1173,6 +1280,7 @@ function createViewportPatch(previous, viewport) {
|
|
|
1173
1280
|
function createReplaceScenePatch(next, previous) {
|
|
1174
1281
|
return {
|
|
1175
1282
|
apply: (state) => {
|
|
1283
|
+
const previousIds = allEntityIds(state);
|
|
1176
1284
|
const replacement = createInternalState(next);
|
|
1177
1285
|
state.entities = replacement.entities;
|
|
1178
1286
|
state.order = replacement.order;
|
|
@@ -1180,6 +1288,7 @@ function createReplaceScenePatch(next, previous) {
|
|
|
1180
1288
|
state.viewport = replacement.viewport;
|
|
1181
1289
|
state.versions = replacement.versions;
|
|
1182
1290
|
return new Set([
|
|
1291
|
+
...previousIds,
|
|
1183
1292
|
...replacement.order.nodeIds,
|
|
1184
1293
|
...replacement.order.edgeIds,
|
|
1185
1294
|
...replacement.order.textIds,
|
|
@@ -1189,6 +1298,7 @@ function createReplaceScenePatch(next, previous) {
|
|
|
1189
1298
|
},
|
|
1190
1299
|
inverse: {
|
|
1191
1300
|
apply: (state) => {
|
|
1301
|
+
const previousIds = allEntityIds(state);
|
|
1192
1302
|
const replacement = createInternalState(previous);
|
|
1193
1303
|
state.entities = replacement.entities;
|
|
1194
1304
|
state.order = replacement.order;
|
|
@@ -1196,6 +1306,7 @@ function createReplaceScenePatch(next, previous) {
|
|
|
1196
1306
|
state.viewport = replacement.viewport;
|
|
1197
1307
|
state.versions = replacement.versions;
|
|
1198
1308
|
return new Set([
|
|
1309
|
+
...previousIds,
|
|
1199
1310
|
...replacement.order.nodeIds,
|
|
1200
1311
|
...replacement.order.edgeIds,
|
|
1201
1312
|
...replacement.order.textIds,
|
|
@@ -1238,15 +1349,23 @@ function endpointDeleted(endpoint, deleted) {
|
|
|
1238
1349
|
return deleted.has(endpoint.portId);
|
|
1239
1350
|
}
|
|
1240
1351
|
function composePatches(first, second) {
|
|
1352
|
+
var _a, _b;
|
|
1353
|
+
const steps = [
|
|
1354
|
+
...((_a = first.steps) !== null && _a !== void 0 ? _a : [first]),
|
|
1355
|
+
...((_b = second.steps) !== null && _b !== void 0 ? _b : [second]),
|
|
1356
|
+
];
|
|
1241
1357
|
return {
|
|
1242
1358
|
apply: (state) => {
|
|
1243
|
-
const changed =
|
|
1244
|
-
for (const
|
|
1245
|
-
|
|
1359
|
+
const changed = new Set();
|
|
1360
|
+
for (const step of steps) {
|
|
1361
|
+
for (const id of step.apply(state)) {
|
|
1362
|
+
changed.add(id);
|
|
1363
|
+
}
|
|
1246
1364
|
}
|
|
1247
1365
|
return changed;
|
|
1248
1366
|
},
|
|
1249
1367
|
inverse: undefined,
|
|
1368
|
+
steps,
|
|
1250
1369
|
};
|
|
1251
1370
|
}
|
|
1252
1371
|
function cloneOrder(order) {
|
|
@@ -1414,17 +1533,13 @@ function deleteEntity(state, id) {
|
|
|
1414
1533
|
state.versions.delete(id);
|
|
1415
1534
|
return deleted;
|
|
1416
1535
|
}
|
|
1417
|
-
function
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
}
|
|
1423
|
-
if (endpoint.kind === "port" && ((_a = ports.get(endpoint.portId)) === null || _a === void 0 ? void 0 : _a.nodeId) === id) {
|
|
1424
|
-
return true;
|
|
1425
|
-
}
|
|
1536
|
+
function addDependency(index, ownerId, dependentId) {
|
|
1537
|
+
let dependents = index.get(ownerId);
|
|
1538
|
+
if (!dependents) {
|
|
1539
|
+
dependents = new Set();
|
|
1540
|
+
index.set(ownerId, dependents);
|
|
1426
1541
|
}
|
|
1427
|
-
|
|
1542
|
+
dependents.add(dependentId);
|
|
1428
1543
|
}
|
|
1429
1544
|
function hitDistanceForGeometry(geometry, point, radius) {
|
|
1430
1545
|
var _a, _b;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { DiagramEngine, createDiagramEngine, deserializeScene, serializeScene } from "./DiagramEngine.js";
|
|
2
2
|
export { DiagramInteractionController, createDiagramInteractionController } from "./interaction.js";
|
|
3
3
|
export { UniformGridIndex } from "./spatialIndex.js";
|
|
4
|
+
export { screenToWorld, worldToScreen, zoomViewportAt, zoomViewportCentered } from "./viewport.js";
|
|
4
5
|
export * from "./geometry.js";
|
|
5
6
|
export type * from "./types.js";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACzG,OAAO,EAAE,4BAA4B,EAAE,kCAAkC,EAAE,MAAM,kBAAkB,CAAA;AACnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,cAAc,eAAe,CAAA;AAC7B,mBAAmB,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACzG,OAAO,EAAE,4BAA4B,EAAE,kCAAkC,EAAE,MAAM,kBAAkB,CAAA;AACnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAClG,cAAc,eAAe,CAAA;AAC7B,mBAAmB,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { DiagramEngine, createDiagramEngine, deserializeScene, serializeScene } from "./DiagramEngine.js";
|
|
2
2
|
export { DiagramInteractionController, createDiagramInteractionController } from "./interaction.js";
|
|
3
3
|
export { UniformGridIndex } from "./spatialIndex.js";
|
|
4
|
+
export { screenToWorld, worldToScreen, zoomViewportAt, zoomViewportCentered } from "./viewport.js";
|
|
4
5
|
export * from "./geometry.js";
|
package/dist/interaction.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DiagramEngine } from "./DiagramEngine.js";
|
|
2
|
-
import type { DiagramId, DiagramInteractionSnapshot, DiagramInteractionTool, DiagramMarqueeMode, DiagramPointerEvent, DiagramResizeHandle } from "./types.js";
|
|
2
|
+
import type { DiagramId, DiagramGeometry, DiagramInteractionSnapshot, DiagramInteractionTool, DiagramMarqueeMode, DiagramPointerEvent, DiagramResizeHandle } from "./types.js";
|
|
3
3
|
type ScheduleFrame = (callback: () => void) => void;
|
|
4
4
|
export type DiagramInteractionOptions = Readonly<{
|
|
5
5
|
scheduleFrame?: ScheduleFrame;
|
|
@@ -23,6 +23,8 @@ export declare class DiagramInteractionController {
|
|
|
23
23
|
private framePending;
|
|
24
24
|
private pendingMoveCount;
|
|
25
25
|
private commitCount;
|
|
26
|
+
private gestureGeneration;
|
|
27
|
+
private gestureHistoryId;
|
|
26
28
|
private readonly scheduleFrame;
|
|
27
29
|
private readonly marqueeMode;
|
|
28
30
|
constructor(engine: DiagramEngine, options?: DiagramInteractionOptions);
|
|
@@ -33,6 +35,8 @@ export declare class DiagramInteractionController {
|
|
|
33
35
|
pointerMove(event: DiagramPointerEvent): void;
|
|
34
36
|
pointerUp(event: DiagramPointerEvent): void;
|
|
35
37
|
cancel(): void;
|
|
38
|
+
/** Returns the renderer-ready geometry for the active move preview. */
|
|
39
|
+
getPreviewGeometry(id: DiagramId): DiagramGeometry | null;
|
|
36
40
|
getSnapshot(): DiagramInteractionSnapshot;
|
|
37
41
|
getPendingMoveCount(): number;
|
|
38
42
|
getCommitCount(): number;
|
|
@@ -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,EAAE,SAAS,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,mBAAmB,EAAiD,mBAAmB,EAAE,MAAM,YAAY,CAAA;
|
|
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,EAAE,SAAS,EAAE,eAAe,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,mBAAmB,EAAiD,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAE7N,KAAK,aAAa,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;AAEnD,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,aAAa,CAAC,EAAE,aAAa,CAA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mB,GAAG,IAAI;IA+B3C,MAAM,IAAI,IAAI;IAKd,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,EAAE,SAAS,GAAG,eAAe,GAAG,IAAI;IAiBzD,WAAW,IAAI,0BAA0B;IAWzC,mBAAmB,IAAI,MAAM;IAI7B,cAAc,IAAI,MAAM;IAIxB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,mCAAmC;IAqB3C,OAAO,CAAC,mBAAmB;IAiC3B,OAAO,CAAC,sBAAsB;IAgB9B,OAAO,CAAC,YAAY;CAiBrB;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,yBAA8B,GAAG,4BAA4B,CAE/I"}
|
package/dist/interaction.js
CHANGED
|
@@ -104,6 +104,18 @@ export class DiagramInteractionController {
|
|
|
104
104
|
writable: true,
|
|
105
105
|
value: 0
|
|
106
106
|
});
|
|
107
|
+
Object.defineProperty(this, "gestureGeneration", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: 0
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "gestureHistoryId", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: 0
|
|
118
|
+
});
|
|
107
119
|
Object.defineProperty(this, "scheduleFrame", {
|
|
108
120
|
enumerable: true,
|
|
109
121
|
configurable: true,
|
|
@@ -124,6 +136,7 @@ export class DiagramInteractionController {
|
|
|
124
136
|
this.tool = tool;
|
|
125
137
|
}
|
|
126
138
|
pointerDown(event) {
|
|
139
|
+
this.gestureGeneration += 1;
|
|
127
140
|
this.activePointer = event;
|
|
128
141
|
this.startPoint = event.point;
|
|
129
142
|
this.latestPoint = event.point;
|
|
@@ -195,7 +208,12 @@ export class DiagramInteractionController {
|
|
|
195
208
|
this.pendingMoveCount += 1;
|
|
196
209
|
if (!this.framePending) {
|
|
197
210
|
this.framePending = true;
|
|
198
|
-
|
|
211
|
+
const generation = this.gestureGeneration;
|
|
212
|
+
this.scheduleFrame(() => {
|
|
213
|
+
if (generation !== this.gestureGeneration)
|
|
214
|
+
return;
|
|
215
|
+
this.flushPointerMove();
|
|
216
|
+
});
|
|
199
217
|
}
|
|
200
218
|
}
|
|
201
219
|
pointerUp(event) {
|
|
@@ -207,16 +225,16 @@ export class DiagramInteractionController {
|
|
|
207
225
|
this.flushPointerMove();
|
|
208
226
|
if (this.tool === "drag-selection" && this.previewDelta) {
|
|
209
227
|
const selection = this.engine.getScene().selection;
|
|
210
|
-
this.engine.dispatch({ type: "moveEntities", ids: selection.ids, delta: this.previewDelta, historyKey: `drag:${(_a = selection.primaryId) !== null && _a !== void 0 ? _a : "selection"}` });
|
|
228
|
+
this.engine.dispatch({ type: "moveEntities", ids: selection.ids, delta: this.previewDelta, historyKey: `drag:${(_a = selection.primaryId) !== null && _a !== void 0 ? _a : "selection"}:${++this.gestureHistoryId}` });
|
|
211
229
|
this.commitCount += 1;
|
|
212
230
|
}
|
|
213
231
|
if (this.tool === "pan" && this.previewDelta) {
|
|
214
232
|
const viewport = this.engine.getScene().viewport;
|
|
215
|
-
this.engine.dispatch({ type: "setViewport", viewport: { x: viewport.x - this.previewDelta.x, y: viewport.y - this.previewDelta.y }, historyKey:
|
|
233
|
+
this.engine.dispatch({ type: "setViewport", viewport: { x: viewport.x - this.previewDelta.x, y: viewport.y - this.previewDelta.y }, historyKey: `pan:${++this.gestureHistoryId}` });
|
|
216
234
|
this.commitCount += 1;
|
|
217
235
|
}
|
|
218
236
|
if (this.tool === "resize-selection" && this.resizePreviewEntries.length) {
|
|
219
|
-
this.engine.dispatch({ type: "resizeEntities", entries: this.resizePreviewEntries, historyKey: `resize:${(_c = (_b = this.resizePreview) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : "selection"}` });
|
|
237
|
+
this.engine.dispatch({ type: "resizeEntities", entries: this.resizePreviewEntries, historyKey: `resize:${(_c = (_b = this.resizePreview) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : "selection"}:${++this.gestureHistoryId}` });
|
|
220
238
|
this.commitCount += 1;
|
|
221
239
|
}
|
|
222
240
|
if (this.tool === "marquee" && this.marquee) {
|
|
@@ -231,6 +249,25 @@ export class DiagramInteractionController {
|
|
|
231
249
|
}
|
|
232
250
|
cancel() {
|
|
233
251
|
this.clearGesture();
|
|
252
|
+
this.tool = "select";
|
|
253
|
+
}
|
|
254
|
+
/** Returns the renderer-ready geometry for the active move preview. */
|
|
255
|
+
getPreviewGeometry(id) {
|
|
256
|
+
var _a, _b;
|
|
257
|
+
const geometry = this.engine.getGeometrySnapshot(id);
|
|
258
|
+
if (!geometry || this.tool !== "drag-selection" || !this.previewDelta || !this.engine.getScene().selection.ids.includes(id)) {
|
|
259
|
+
return geometry;
|
|
260
|
+
}
|
|
261
|
+
const move = (point) => ({ x: point.x + this.previewDelta.x, y: point.y + this.previewDelta.y });
|
|
262
|
+
return Object.freeze({
|
|
263
|
+
...geometry,
|
|
264
|
+
bounds: { ...geometry.bounds, x: geometry.bounds.x + this.previewDelta.x, y: geometry.bounds.y + this.previewDelta.y },
|
|
265
|
+
hitBounds: { ...geometry.hitBounds, x: geometry.hitBounds.x + this.previewDelta.x, y: geometry.hitBounds.y + this.previewDelta.y },
|
|
266
|
+
unrotatedBounds: geometry.unrotatedBounds ? { ...geometry.unrotatedBounds, x: geometry.unrotatedBounds.x + this.previewDelta.x, y: geometry.unrotatedBounds.y + this.previewDelta.y } : undefined,
|
|
267
|
+
corners: (_a = geometry.corners) === null || _a === void 0 ? void 0 : _a.map(move),
|
|
268
|
+
path: (_b = geometry.path) === null || _b === void 0 ? void 0 : _b.map(move),
|
|
269
|
+
point: geometry.point ? move(geometry.point) : undefined,
|
|
270
|
+
});
|
|
234
271
|
}
|
|
235
272
|
getSnapshot() {
|
|
236
273
|
return {
|
|
@@ -352,6 +389,7 @@ export class DiagramInteractionController {
|
|
|
352
389
|
});
|
|
353
390
|
}
|
|
354
391
|
clearGesture() {
|
|
392
|
+
this.gestureGeneration += 1;
|
|
355
393
|
this.activePointer = null;
|
|
356
394
|
this.startPoint = null;
|
|
357
395
|
this.latestPoint = null;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import type { DiagramHistoryOptions } from "../types.js";
|
|
1
2
|
import type { HistoryEntry, Patch } from "./model.js";
|
|
2
3
|
export declare class DiagramHistory {
|
|
3
4
|
private undoStack;
|
|
4
5
|
private redoStack;
|
|
6
|
+
private readonly maxEntries;
|
|
7
|
+
constructor(options?: DiagramHistoryOptions);
|
|
5
8
|
canUndo(): boolean;
|
|
6
9
|
canRedo(): boolean;
|
|
7
10
|
undoDepth(): number;
|
|
8
11
|
redoDepth(): number;
|
|
12
|
+
clear(): void;
|
|
9
13
|
popUndo(): HistoryEntry | null;
|
|
10
14
|
pushUndo(entry: HistoryEntry): void;
|
|
11
15
|
popRedo(): HistoryEntry | null;
|