@affino/diagram-vue 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 +15 -0
- package/dist/useDiagramPointerController.d.ts.map +1 -1
- package/dist/useDiagramPointerController.js +23 -3
- package/dist/useDiagramRenderer.d.ts +2 -1
- package/dist/useDiagramRenderer.d.ts.map +1 -1
- package/dist/useDiagramRenderer.js +26 -14
- package/dist/useDiagramTextEditor.d.ts.map +1 -1
- package/dist/useDiagramTextEditor.js +3 -1
- package/dist/useDiagramViewport.d.ts.map +1 -1
- package/dist/useDiagramViewport.js +6 -2
- package/dist/useDiagramVisibleEntities.d.ts.map +1 -1
- package/dist/useDiagramVisibleEntities.js +17 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -81,3 +81,18 @@ Selected entities are included even when outside the viewport, which keeps handl
|
|
|
81
81
|
## What belongs in core
|
|
82
82
|
|
|
83
83
|
Do not put domain rules, snapping decisions, hit testing, undo/redo, or geometry math in Vue components. Route those through `@affino/diagram-core` commands and queries, then render the projection here.
|
|
84
|
+
|
|
85
|
+
## Viewport and camera migration
|
|
86
|
+
|
|
87
|
+
`ResizeObserver.contentRect` is CSS pixels. `useDiagramViewport()` converts them to world extent by dividing by the current zoom and ignores `0×0` measurements, so a restored camera is not overwritten by a hidden tab. The SVG viewBox should be `x y width height` from the core viewport—do not divide width or height by zoom again.
|
|
88
|
+
|
|
89
|
+
For DOM overlays call `getDomEntityStyle(entity, viewport.viewport.value)`; text editor positioning already applies the same transform. Use core `zoomViewportAt()` for cursor focus and `zoomViewportCentered()` for toolbar zoom. Minimap dimensions use the world scene bounds and the same camera transform.
|
|
90
|
+
|
|
91
|
+
Preview geometry remains transient until pointerup. Render the interaction preview and its handles from core state; entity IDs are opaque strings and may contain `:`. Use `handle.ownerId`, never parse `handle.id`. Escape/pointercancel cancels without history; pointerup commits one undo operation.
|
|
92
|
+
|
|
93
|
+
### Migration from 0.1.0
|
|
94
|
+
|
|
95
|
+
- Replace `viewBox.width = viewport.width / viewport.zoom` and the corresponding height formula with raw world `viewport.width` and `viewport.height`.
|
|
96
|
+
- Remove application-side ResizeObserver writes of CSS width/height into core; use `useDiagramViewport()`.
|
|
97
|
+
- Replace custom cursor zoom/focus and resize camera math with the exported core helpers.
|
|
98
|
+
- Run initial Fit only for a new document without a persisted viewport; never Fit on every resize or scene restore.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiagramPointerController.d.ts","sourceRoot":"","sources":["../src/useDiagramPointerController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAAsC,KAAK,4BAA4B,EAAE,KAAK,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC7L,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,WAAW,EAAE,4BAA4B,CAAA;IACzC,KAAK,EAAE,UAAU,CAAC,0BAA0B,CAAC,CAAA;IAC7C,OAAO,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAA;IAC/C,kBAAkB,EAAE,MAAM;QACxB,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC5C,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC5C,WAAW,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC1C,eAAe,EAAE,MAAM,IAAI,CAAA;KAC5B,CAAA;IACD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC;IACrD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,YAAY,CAAA;IACpD,iB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,KAAK,IAAI,CAAA;IACjD,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;CACtD,CAAC,CAAA;AAEF,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,+BAAoC,GAAG,wBAAwB,CAoExJ"}
|
|
@@ -4,16 +4,28 @@ export function useDiagramPointerController(controller, options = {}) {
|
|
|
4
4
|
let refresh = () => { };
|
|
5
5
|
const interaction = createDiagramInteractionController(controller.engine, {
|
|
6
6
|
scheduleFrame: (callback) => {
|
|
7
|
-
requestAnimationFrame
|
|
7
|
+
const schedule = typeof globalThis.requestAnimationFrame === "function"
|
|
8
|
+
? globalThis.requestAnimationFrame.bind(globalThis)
|
|
9
|
+
: (next) => globalThis.setTimeout(next, 0);
|
|
10
|
+
schedule(() => {
|
|
11
|
+
if (disposed) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
8
14
|
callback();
|
|
9
15
|
refresh();
|
|
10
16
|
});
|
|
11
17
|
},
|
|
12
18
|
});
|
|
13
|
-
|
|
19
|
+
let lastSnapshot = interaction.getSnapshot();
|
|
20
|
+
const state = shallowRef(lastSnapshot);
|
|
14
21
|
let disposed = false;
|
|
15
22
|
refresh = () => {
|
|
16
|
-
|
|
23
|
+
const next = interaction.getSnapshot();
|
|
24
|
+
if (sameSnapshot(lastSnapshot, next)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
lastSnapshot = next;
|
|
28
|
+
state.value = next;
|
|
17
29
|
};
|
|
18
30
|
const toEvent = (event) => ({ id: event.pointerId, point: toWorldPoint(event, options.toWorldPoint), shiftKey: event.shiftKey });
|
|
19
31
|
const api = {
|
|
@@ -59,6 +71,14 @@ export function useDiagramPointerController(controller, options = {}) {
|
|
|
59
71
|
}
|
|
60
72
|
return api;
|
|
61
73
|
}
|
|
74
|
+
function sameSnapshot(previous, next) {
|
|
75
|
+
return previous.tool === next.tool
|
|
76
|
+
&& previous.active === next.active
|
|
77
|
+
&& previous.previewDelta === next.previewDelta
|
|
78
|
+
&& previous.resizePreview === next.resizePreview
|
|
79
|
+
&& previous.resizePreviewEntries === next.resizePreviewEntries
|
|
80
|
+
&& previous.marquee === next.marquee;
|
|
81
|
+
}
|
|
62
82
|
function toWorldPoint(event, mapper) {
|
|
63
83
|
if (mapper) {
|
|
64
84
|
return mapper(event);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DiagramRenderEntity } from "./types.js";
|
|
2
|
+
import type { DiagramViewport } from "@affino/diagram-core";
|
|
2
3
|
export type SvgEntityProps = Readonly<Record<string, string | number | boolean | undefined>>;
|
|
3
4
|
export declare function getSvgEntityProps(entity: DiagramRenderEntity): SvgEntityProps;
|
|
4
|
-
export declare function getDomEntityStyle(entity: DiagramRenderEntity): Readonly<Record<string, string>>;
|
|
5
|
+
export declare function getDomEntityStyle(entity: DiagramRenderEntity, viewport?: DiagramViewport): Readonly<Record<string, string>>;
|
|
5
6
|
//# sourceMappingURL=useDiagramRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiagramRenderer.d.ts","sourceRoot":"","sources":["../src/useDiagramRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"useDiagramRenderer.d.ts","sourceRoot":"","sources":["../src/useDiagramRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,CAAA;AAE5F,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,cAAc,CA6C7E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAa3H"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export function getSvgEntityProps(entity) {
|
|
2
|
-
var _a, _b, _c;
|
|
2
|
+
var _a, _b, _c, _d;
|
|
3
3
|
const { geometry } = entity;
|
|
4
|
+
const bounds = (_a = geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : geometry.bounds;
|
|
5
|
+
const transform = geometry.rotation
|
|
6
|
+
? "rotate(" + geometry.rotation + " " + (bounds.x + bounds.width / 2) + " " + (bounds.y + bounds.height / 2) + ")"
|
|
7
|
+
: undefined;
|
|
4
8
|
const common = {
|
|
5
9
|
"data-diagram-id": entity.id,
|
|
6
10
|
"data-diagram-kind": entity.kind,
|
|
@@ -9,11 +13,11 @@ export function getSvgEntityProps(entity) {
|
|
|
9
13
|
if (entity.kind === "edge") {
|
|
10
14
|
return {
|
|
11
15
|
...common,
|
|
12
|
-
points: (
|
|
16
|
+
points: (_c = (_b = geometry.path) === null || _b === void 0 ? void 0 : _b.map((point) => `${point.x},${point.y}`).join(" ")) !== null && _c !== void 0 ? _c : "",
|
|
13
17
|
};
|
|
14
18
|
}
|
|
15
19
|
if (entity.kind === "port") {
|
|
16
|
-
const point = (
|
|
20
|
+
const point = (_d = geometry.point) !== null && _d !== void 0 ? _d : { x: geometry.bounds.x, y: geometry.bounds.y };
|
|
17
21
|
return {
|
|
18
22
|
...common,
|
|
19
23
|
cx: point.x,
|
|
@@ -24,27 +28,35 @@ export function getSvgEntityProps(entity) {
|
|
|
24
28
|
if (entity.kind === "shape" || entity.kind === "node") {
|
|
25
29
|
return {
|
|
26
30
|
...common,
|
|
27
|
-
x:
|
|
28
|
-
y:
|
|
29
|
-
width:
|
|
30
|
-
height:
|
|
31
|
+
x: bounds.x,
|
|
32
|
+
y: bounds.y,
|
|
33
|
+
width: bounds.width,
|
|
34
|
+
height: bounds.height,
|
|
35
|
+
transform,
|
|
31
36
|
};
|
|
32
37
|
}
|
|
33
38
|
if (entity.kind === "text") {
|
|
34
39
|
return {
|
|
35
40
|
...common,
|
|
36
|
-
x:
|
|
37
|
-
y:
|
|
41
|
+
x: bounds.x,
|
|
42
|
+
y: bounds.y,
|
|
43
|
+
transform,
|
|
38
44
|
};
|
|
39
45
|
}
|
|
40
46
|
return common;
|
|
41
47
|
}
|
|
42
|
-
export function getDomEntityStyle(entity) {
|
|
43
|
-
|
|
48
|
+
export function getDomEntityStyle(entity, viewport) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const bounds = (_a = entity.geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : entity.geometry.bounds;
|
|
51
|
+
const zoom = (_b = viewport === null || viewport === void 0 ? void 0 : viewport.zoom) !== null && _b !== void 0 ? _b : 1;
|
|
52
|
+
const left = viewport ? (bounds.x - viewport.x) * zoom : bounds.x;
|
|
53
|
+
const top = viewport ? (bounds.y - viewport.y) * zoom : bounds.y;
|
|
54
|
+
const rotation = entity.geometry.rotation ? " rotate(" + entity.geometry.rotation + "deg)" : "";
|
|
44
55
|
return Object.freeze({
|
|
45
56
|
position: "absolute",
|
|
46
|
-
transform:
|
|
47
|
-
width:
|
|
48
|
-
height:
|
|
57
|
+
transform: "translate(" + left + "px, " + top + "px)" + rotation,
|
|
58
|
+
width: bounds.width * zoom + "px",
|
|
59
|
+
height: bounds.height * zoom + "px",
|
|
60
|
+
...(rotation ? { transformOrigin: "center center" } : {}),
|
|
49
61
|
});
|
|
50
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiagramTextEditor.d.ts","sourceRoot":"","sources":["../src/useDiagramTextEditor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAAwB,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,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uB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,EAAE,EAAE,SAAS,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,WAAW,CAAA;IACnB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACxC,CAAC,CAAA;AAEF,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,YAAY,EAAE,UAAU,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAAA;IACzD,aAAa,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAA;IACzC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;IAC1C,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,QAAQ,CAAC,EAAE,QAAQ,CAAC;QAAE,KAAK,EAAE,eAAe,CAAA;KAAE,CAAC,CAAA;CAChD,CAAC,CAAA;AAEF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,wBAA6B,GAAG,2BAA2B,CAgF7I"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCurrentScope, onScopeDispose, shallowRef } from "vue";
|
|
1
|
+
import { getCurrentScope, onScopeDispose, shallowRef, watch } from "vue";
|
|
2
2
|
import { createEntityGeometry } from "@affino/diagram-core";
|
|
3
3
|
export function useDiagramTextEditor(controller, options = {}) {
|
|
4
4
|
const activeEditor = shallowRef(null);
|
|
@@ -29,6 +29,7 @@ export function useDiagramTextEditor(controller, options = {}) {
|
|
|
29
29
|
activeEditor.value = buildOverlay(current.id, current.text);
|
|
30
30
|
};
|
|
31
31
|
const subscription = controller.engine.subscribe(() => refreshActive());
|
|
32
|
+
const stopViewportWatch = options.viewport ? watch(() => { var _a; return (_a = options.viewport) === null || _a === void 0 ? void 0 : _a.value; }, refreshActive) : null;
|
|
32
33
|
const beginTextEdit = (id) => {
|
|
33
34
|
const overlay = buildOverlay(id);
|
|
34
35
|
if (!overlay) {
|
|
@@ -64,6 +65,7 @@ export function useDiagramTextEditor(controller, options = {}) {
|
|
|
64
65
|
disposed = true;
|
|
65
66
|
activeEditor.value = null;
|
|
66
67
|
subscription.unsubscribe();
|
|
68
|
+
stopViewportWatch === null || stopViewportWatch === void 0 ? void 0 : stopViewportWatch();
|
|
67
69
|
};
|
|
68
70
|
if (getCurrentScope()) {
|
|
69
71
|
onScopeDispose(dispose);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiagramViewport.d.ts","sourceRoot":"","sources":["../src/useDiagramViewport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,QAAQ,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IACzD,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IACxD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACnC,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB,CAA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AAG,KAAK,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC;IAAE,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,KAAK,IAAI,KAAK,kBAAkB,CAAA;AAEpJ,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAA;IAC9C,cAAc,CAAC,EAAE,kBAAkB,CAAA;CACpC,CAAC,CAAA;AAEF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,sBAA2B,GAAG,yBAAyB,CAmEvI"}
|
|
@@ -9,6 +9,9 @@ export function useDiagramViewport(controller, options = {}) {
|
|
|
9
9
|
viewport.value = scene.viewport;
|
|
10
10
|
});
|
|
11
11
|
const setViewport = (next) => {
|
|
12
|
+
if (disposed) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
12
15
|
controller.dispatch({ type: "setViewport", viewport: next });
|
|
13
16
|
};
|
|
14
17
|
const attachViewportElement = (element) => {
|
|
@@ -28,8 +31,9 @@ export function useDiagramViewport(controller, options = {}) {
|
|
|
28
31
|
observer = new ResizeObserverImpl((entries) => {
|
|
29
32
|
var _a;
|
|
30
33
|
const rect = (_a = entries[0]) === null || _a === void 0 ? void 0 : _a.contentRect;
|
|
31
|
-
if (rect) {
|
|
32
|
-
|
|
34
|
+
if (rect && rect.width > 0 && rect.height > 0) {
|
|
35
|
+
const current = controller.scene.value.viewport;
|
|
36
|
+
setViewport({ width: rect.width / current.zoom, height: rect.height / current.zoom });
|
|
33
37
|
}
|
|
34
38
|
});
|
|
35
39
|
observer.observe(element);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDiagramVisibleEntities.d.ts","sourceRoot":"","sources":["../src/useDiagramVisibleEntities.ts"],"names":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wBAAwB,CAAC,CAAA;IAChD,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAaF,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,6BAAkC,GAAG,gCAAgC,CAyB5J"}
|
|
@@ -12,10 +12,11 @@ const EMPTY_PROJECTION = Object.freeze({
|
|
|
12
12
|
});
|
|
13
13
|
export function useDiagramVisibleEntities(controller, options = {}) {
|
|
14
14
|
const projection = shallowRef(EMPTY_PROJECTION);
|
|
15
|
+
const entityCache = new Map();
|
|
15
16
|
const refreshVisible = (bounds) => {
|
|
16
17
|
var _a, _b;
|
|
17
18
|
const viewportBounds = bounds !== null && bounds !== void 0 ? bounds : controller.scene.value.viewport;
|
|
18
|
-
projection.value = buildProjection(controller, inflate(viewportBounds, (_a = options.overscan) !== null && _a !== void 0 ? _a : 0), (_b = options.includeSelection) !== null && _b !== void 0 ? _b : true);
|
|
19
|
+
projection.value = buildProjection(controller, inflate(viewportBounds, (_a = options.overscan) !== null && _a !== void 0 ? _a : 0), (_b = options.includeSelection) !== null && _b !== void 0 ? _b : true, entityCache);
|
|
19
20
|
};
|
|
20
21
|
const subscription = controller.engine.subscribe(() => refreshVisible());
|
|
21
22
|
let disposed = false;
|
|
@@ -26,13 +27,12 @@ export function useDiagramVisibleEntities(controller, options = {}) {
|
|
|
26
27
|
disposed = true;
|
|
27
28
|
subscription.unsubscribe();
|
|
28
29
|
};
|
|
29
|
-
refreshVisible();
|
|
30
30
|
if (getCurrentScope()) {
|
|
31
31
|
onScopeDispose(dispose);
|
|
32
32
|
}
|
|
33
33
|
return { projection, refreshVisible, dispose };
|
|
34
34
|
}
|
|
35
|
-
function buildProjection(controller, bounds, includeSelection) {
|
|
35
|
+
function buildProjection(controller, bounds, includeSelection, entityCache) {
|
|
36
36
|
const scene = controller.scene.value;
|
|
37
37
|
const ids = new Set(controller.engine.queryVisible(bounds));
|
|
38
38
|
if (includeSelection) {
|
|
@@ -43,11 +43,23 @@ function buildProjection(controller, bounds, includeSelection) {
|
|
|
43
43
|
const selected = new Set(scene.selection.ids);
|
|
44
44
|
const entities = [];
|
|
45
45
|
for (const id of ids) {
|
|
46
|
-
const geometry =
|
|
46
|
+
const geometry = controller.engine.getGeometrySnapshot(id);
|
|
47
47
|
if (!geometry) {
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
const isSelected = selected.has(id);
|
|
51
|
+
const cached = entityCache.get(id);
|
|
52
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.geometry) === geometry && cached.selected === isSelected) {
|
|
53
|
+
entities.push(cached.entity);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const entity = Object.freeze({ id, kind: geometry.kind, layer: "svg", geometry, selected: isSelected });
|
|
57
|
+
entityCache.set(id, { geometry, selected: isSelected, entity });
|
|
58
|
+
entities.push(entity);
|
|
59
|
+
}
|
|
60
|
+
for (const id of entityCache.keys()) {
|
|
61
|
+
if (!ids.has(id))
|
|
62
|
+
entityCache.delete(id);
|
|
51
63
|
}
|
|
52
64
|
const activeGeometries = entities.filter((entity) => entity.selected).map((entity) => entity.geometry);
|
|
53
65
|
const anchorGeometries = activeGeometries.filter((geometry) => geometry.kind !== "edge");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@affino/diagram-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "Anton Pavlov <a.pavlov@affino.dev>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Vue adapter for @affino/diagram-core",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"vue": "^3.3.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@affino/diagram-core": "^0.
|
|
24
|
+
"@affino/diagram-core": "^0.3.0"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"devDependencies": {
|