@affino/diagram-vue 0.4.0 → 0.6.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
CHANGED
|
@@ -73,7 +73,7 @@ viewport.setViewport({ x: 120, y: 40, zoom: 1.25 })
|
|
|
73
73
|
`useDiagramVisibleEntities()` exposes:
|
|
74
74
|
|
|
75
75
|
- `nodes`, `edges`, `ports`, `shapes`, and `texts` for SVG rendering;
|
|
76
|
-
- `activeHandles` for selected resize/port handles;
|
|
76
|
+
- `activeHandles` for selected resize/port handles and source/target handles on selected edges;
|
|
77
77
|
- `overlayAnchors` for context menus and toolbars.
|
|
78
78
|
|
|
79
79
|
Selected entities are included even when outside the viewport, which keeps handles and overlays stable during keyboard or programmatic selection changes. `useDiagramTextEditor()` owns one shared DOM editor overlay for the active text entity; it reads bounds from core, positions through the viewport transform, and commits through the `editText` command.
|
|
@@ -88,7 +88,9 @@ Do not put domain rules, snapping decisions, hit testing, undo/redo, or geometry
|
|
|
88
88
|
|
|
89
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
90
|
|
|
91
|
-
Preview geometry remains transient until pointerup.
|
|
91
|
+
Preview geometry remains transient until pointerup. Start endpoint gestures with `interaction.beginEdgeEndpointHandle(handle.ownerId, "source" | "target", event)` and render `interaction.getPreviewGeometry(edgeId)` while the gesture is active. 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
|
+
`useDiagramPointerController()` accepts `snap` options for grid spacing, port snapping, alignment, equal spacing, and screen pixel tolerance. Its `state.value.snapGuides` contains world-space line segments for currently active alignment and equal-spacing matches and clears when the gesture ends.
|
|
92
94
|
|
|
93
95
|
### Migration from 0.1.0
|
|
94
96
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ShallowRef } from "vue";
|
|
2
|
-
import { type DiagramInteractionController, type DiagramInteractionSnapshot, type DiagramInteractionTool, type DiagramPoint } from "@affino/diagram-core";
|
|
2
|
+
import { type DiagramInteractionController, type DiagramInteractionSnapOptions, type DiagramInteractionSnapshot, type DiagramInteractionTool, type DiagramPoint } from "@affino/diagram-core";
|
|
3
3
|
import type { DiagramEngineController } from "./useDiagramEngine.js";
|
|
4
4
|
export type DiagramPointerController = Readonly<{
|
|
5
5
|
interaction: DiagramInteractionController;
|
|
@@ -17,6 +17,7 @@ export type DiagramPointerControllerOptions = Readonly<{
|
|
|
17
17
|
toWorldPoint?: (event: PointerEvent) => DiagramPoint;
|
|
18
18
|
setPointerCapture?: (event: PointerEvent) => void;
|
|
19
19
|
releasePointerCapture?: (event: PointerEvent) => void;
|
|
20
|
+
snap?: DiagramInteractionSnapOptions;
|
|
20
21
|
}>;
|
|
21
22
|
export declare function useDiagramPointerController(controller: DiagramEngineController, options?: DiagramPointerControllerOptions): DiagramPointerController;
|
|
22
23
|
//# sourceMappingURL=useDiagramPointerController.d.ts.map
|
|
@@ -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;
|
|
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,6BAA6B,EAAE,KAAK,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACjO,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,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACjD,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACrD,IAAI,CAAC,EAAE,6BAA6B,CAAA;CACrC,CAAC,CAAA;AAEF,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,+BAAoC,GAAG,wBAAwB,CAqExJ"}
|
|
@@ -3,6 +3,7 @@ import { createDiagramInteractionController } from "@affino/diagram-core";
|
|
|
3
3
|
export function useDiagramPointerController(controller, options = {}) {
|
|
4
4
|
let refresh = () => { };
|
|
5
5
|
const interaction = createDiagramInteractionController(controller.engine, {
|
|
6
|
+
snap: options.snap,
|
|
6
7
|
scheduleFrame: (callback) => {
|
|
7
8
|
const schedule = typeof globalThis.requestAnimationFrame === "function"
|
|
8
9
|
? globalThis.requestAnimationFrame.bind(globalThis)
|
|
@@ -77,6 +78,8 @@ function sameSnapshot(previous, next) {
|
|
|
77
78
|
&& previous.previewDelta === next.previewDelta
|
|
78
79
|
&& previous.resizePreview === next.resizePreview
|
|
79
80
|
&& previous.resizePreviewEntries === next.resizePreviewEntries
|
|
81
|
+
&& previous.edgeEndpointPreview === next.edgeEndpointPreview
|
|
82
|
+
&& previous.snapGuides === next.snapGuides
|
|
80
83
|
&& previous.marquee === next.marquee;
|
|
81
84
|
}
|
|
82
85
|
function toWorldPoint(event, mapper) {
|
|
@@ -63,7 +63,10 @@ function buildProjection(controller, bounds, includeSelection, entityCache) {
|
|
|
63
63
|
}
|
|
64
64
|
const activeGeometries = entities.filter((entity) => entity.selected).map((entity) => entity.geometry);
|
|
65
65
|
const anchorGeometries = activeGeometries.filter((geometry) => geometry.kind !== "edge");
|
|
66
|
-
const activeHandles =
|
|
66
|
+
const activeHandles = [
|
|
67
|
+
...(anchorGeometries.length > 1 ? createGroupHandles(anchorGeometries) : activeGeometries.flatMap(createHandles)),
|
|
68
|
+
...activeGeometries.filter((geometry) => geometry.kind === "edge").flatMap(createEdgeEndpointHandles),
|
|
69
|
+
];
|
|
67
70
|
return Object.freeze({
|
|
68
71
|
ids: Object.freeze(entities.map((entity) => entity.id)),
|
|
69
72
|
nodes: freezeKind(entities, "node"),
|
|
@@ -81,9 +84,8 @@ function freezeKind(entities, kind) {
|
|
|
81
84
|
}
|
|
82
85
|
function createHandles(geometry) {
|
|
83
86
|
var _a, _b, _c;
|
|
84
|
-
if (geometry.kind === "edge")
|
|
87
|
+
if (geometry.kind === "edge")
|
|
85
88
|
return [];
|
|
86
|
-
}
|
|
87
89
|
const rect = (_a = geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : geometry.bounds;
|
|
88
90
|
if (geometry.kind === "port") {
|
|
89
91
|
return [{ id: `${geometry.id}:port`, ownerId: geometry.id, kind: "port", point: (_b = geometry.point) !== null && _b !== void 0 ? _b : { x: rect.x, y: rect.y } }];
|
|
@@ -101,6 +103,15 @@ function createHandles(geometry) {
|
|
|
101
103
|
{ id: `${geometry.id}:sw`, ownerId: geometry.id, kind: "resize", point: corners[3] },
|
|
102
104
|
];
|
|
103
105
|
}
|
|
106
|
+
function createEdgeEndpointHandles(geometry) {
|
|
107
|
+
var _a;
|
|
108
|
+
if (geometry.kind !== "edge" || !((_a = geometry.path) === null || _a === void 0 ? void 0 : _a.length))
|
|
109
|
+
return [];
|
|
110
|
+
return [
|
|
111
|
+
{ id: `${geometry.id}:source`, ownerId: geometry.id, kind: "edge-endpoint", point: geometry.path[0] },
|
|
112
|
+
{ id: `${geometry.id}:target`, ownerId: geometry.id, kind: "edge-endpoint", point: geometry.path[geometry.path.length - 1] },
|
|
113
|
+
];
|
|
114
|
+
}
|
|
104
115
|
function createGroupHandles(geometries) {
|
|
105
116
|
const rect = unionRects(geometries.map((geometry) => geometry.bounds));
|
|
106
117
|
if (!rect)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@affino/diagram-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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.8.1"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"devDependencies": {
|