@affino/diagram-vue 0.10.0 → 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
CHANGED
|
@@ -28,6 +28,8 @@ selection.setSelection(["bay-a"], "bay-a")
|
|
|
28
28
|
|
|
29
29
|
Render static diagram text as SVG `<text>`/`<tspan>` elements in world space. Use DOM only for the single active text editor overlay and floating UI such as context menus, toolbars, popovers, and form-like controls. The adapter returns render lists from `engine.queryVisible()`, so Vue code does not scan the whole scene on pan.
|
|
30
30
|
|
|
31
|
+
Core `flipEntities` commands are reflected by `getSvgEntityProps()` and `getDomEntityStyle()` through the geometry's `flipX`/`flipY` flags. The built-in table view mirrors its cell layout and keeps toolbar and active input controls readable.
|
|
32
|
+
|
|
31
33
|
```vue
|
|
32
34
|
<script setup lang="ts">
|
|
33
35
|
import { getSvgEntityProps, useDiagramEngine, useDiagramPointerController, useDiagramTextEditor, useDiagramVisibleEntities } from "@affino/diagram-vue"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagramTableView.d.ts","sourceRoot":"","sources":["../src/DiagramTableView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,KAAK,CAAA;AAE/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"DiagramTableView.d.ts","sourceRoot":"","sources":["../src/DiagramTableView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,KAAK,CAAA;AAE/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAA;AAIhF,qGAAqG;AACrG,eAAO,MAAM,gBAAgB;;cAGK,QAAQ,CAAC,uBAAuB,CAAC;;;IAC/D,0FAA0F;;cAC/D,QAAQ,CAAC,wBAAwB,CAAC;;;IAC7D,uEAAuE;;;;;;;;;;;;;cAHzC,QAAQ,CAAC,uBAAuB,CAAC;;;IAC/D,0FAA0F;;cAC/D,QAAQ,CAAC,wBAAwB,CAAC;;;IAC7D,uEAAuE;;;;;;;;;;;MAmIzE,CAAA"}
|
package/dist/DiagramTableView.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { computed, defineComponent, h, nextTick, ref, watch } from "vue";
|
|
2
|
+
import { svgTransform } from "./useDiagramRenderer.js";
|
|
2
3
|
import { useDiagramTable } from "./useDiagramTable.js";
|
|
3
4
|
/** SVG-native table renderer with one accessible foreignObject editor and toolbar while selected. */
|
|
4
5
|
export const DiagramTableView = defineComponent({
|
|
@@ -117,12 +118,17 @@ export const DiagramTableView = defineComponent({
|
|
|
117
118
|
}
|
|
118
119
|
if (style.border.visible)
|
|
119
120
|
children.push(h("rect", { x: table.x + style.border.stroke.width / 2, y: table.y + style.border.stroke.width / 2, width: Math.max(0, table.width - style.border.stroke.width), height: Math.max(0, table.height - style.border.stroke.width), rx: style.border.radius, fill: "none", stroke: style.border.stroke.color, "stroke-width": style.border.stroke.width, "stroke-dasharray": dash(style.border.stroke.style), "vector-effect": "non-scaling-stroke", "pointer-events": "none" }));
|
|
121
|
+
const tableTransform = svgTransform(0, table.flipX === true, table.flipY === true, table);
|
|
122
|
+
const visualChildren = children.splice(0, children.length);
|
|
123
|
+
children.push(h("g", { transform: tableTransform }, visualChildren));
|
|
120
124
|
const activeEdit = editing.value;
|
|
121
125
|
if (activeEdit) {
|
|
122
|
-
const
|
|
123
|
-
const
|
|
126
|
+
const cellX = columnOffsets[activeEdit.column];
|
|
127
|
+
const cellY = rowOffsets[activeEdit.row];
|
|
124
128
|
const width = table.columnWidths[activeEdit.column];
|
|
125
129
|
const height = table.rowHeights[activeEdit.row];
|
|
130
|
+
const x = table.flipX ? table.x + table.width - (cellX - table.x) - width : cellX;
|
|
131
|
+
const y = table.flipY ? table.y + table.height - (cellY - table.y) - height : cellY;
|
|
126
132
|
children.push(h("foreignObject", { x, y, width, height }, [h("input", {
|
|
127
133
|
ref: input, value: activeEdit.text, "aria-label": `Edit row ${activeEdit.row + 1}, column ${activeEdit.column + 1}`,
|
|
128
134
|
onPointerdown: stopToolbarEvent, onClick: stopToolbarEvent,
|
|
@@ -3,4 +3,10 @@ import type { DiagramViewport } from "@affino/diagram-core";
|
|
|
3
3
|
export type SvgEntityProps = Readonly<Record<string, string | number | boolean | undefined>>;
|
|
4
4
|
export declare function getSvgEntityProps(entity: DiagramRenderEntity): SvgEntityProps;
|
|
5
5
|
export declare function getDomEntityStyle(entity: DiagramRenderEntity, viewport?: DiagramViewport): Readonly<Record<string, string>>;
|
|
6
|
+
export declare function svgTransform(rotation: number, flipX: boolean, flipY: boolean, bounds: Readonly<{
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}>): string | undefined;
|
|
6
12
|
//# 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;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,
|
|
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,CA2C7E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgB3H;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,GAAG,SAAS,CAO5K"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export function getSvgEntityProps(entity) {
|
|
2
|
-
var _a, _b, _c, _d;
|
|
2
|
+
var _a, _b, _c, _d, _e;
|
|
3
3
|
const { geometry } = entity;
|
|
4
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;
|
|
5
|
+
const transform = svgTransform((_b = geometry.rotation) !== null && _b !== void 0 ? _b : 0, geometry.flipX === true, geometry.flipY === true, bounds);
|
|
8
6
|
const common = {
|
|
9
7
|
"data-diagram-id": entity.id,
|
|
10
8
|
"data-diagram-kind": entity.kind,
|
|
@@ -13,11 +11,11 @@ export function getSvgEntityProps(entity) {
|
|
|
13
11
|
if (entity.kind === "edge") {
|
|
14
12
|
return {
|
|
15
13
|
...common,
|
|
16
|
-
points: (
|
|
14
|
+
points: (_d = (_c = geometry.path) === null || _c === void 0 ? void 0 : _c.map((point) => `${point.x},${point.y}`).join(" ")) !== null && _d !== void 0 ? _d : "",
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
17
|
if (entity.kind === "port") {
|
|
20
|
-
const point = (
|
|
18
|
+
const point = (_e = geometry.point) !== null && _e !== void 0 ? _e : { x: geometry.bounds.x, y: geometry.bounds.y };
|
|
21
19
|
return {
|
|
22
20
|
...common,
|
|
23
21
|
cx: point.x,
|
|
@@ -52,11 +50,24 @@ export function getDomEntityStyle(entity, viewport) {
|
|
|
52
50
|
const left = viewport ? (bounds.x - viewport.x) * zoom : bounds.x;
|
|
53
51
|
const top = viewport ? (bounds.y - viewport.y) * zoom : bounds.y;
|
|
54
52
|
const rotation = entity.geometry.rotation ? " rotate(" + entity.geometry.rotation + "deg)" : "";
|
|
53
|
+
const flip = entity.geometry.flipX || entity.geometry.flipY
|
|
54
|
+
? " scale(" + (entity.geometry.flipX ? -1 : 1) + ", " + (entity.geometry.flipY ? -1 : 1) + ")"
|
|
55
|
+
: "";
|
|
55
56
|
return Object.freeze({
|
|
56
57
|
position: "absolute",
|
|
57
|
-
transform: "translate(" + left + "px, " + top + "px)" + rotation,
|
|
58
|
+
transform: "translate(" + left + "px, " + top + "px)" + rotation + flip,
|
|
58
59
|
width: bounds.width * zoom + "px",
|
|
59
60
|
height: bounds.height * zoom + "px",
|
|
60
|
-
...(rotation ? { transformOrigin: "center center" } : {}),
|
|
61
|
+
...(rotation || flip ? { transformOrigin: "center center" } : {}),
|
|
61
62
|
});
|
|
62
63
|
}
|
|
64
|
+
export function svgTransform(rotation, flipX, flipY, bounds) {
|
|
65
|
+
const centerX = bounds.x + bounds.width / 2;
|
|
66
|
+
const centerY = bounds.y + bounds.height / 2;
|
|
67
|
+
const transforms = [];
|
|
68
|
+
if (rotation)
|
|
69
|
+
transforms.push(`rotate(${rotation} ${centerX} ${centerY})`);
|
|
70
|
+
if (flipX || flipY)
|
|
71
|
+
transforms.push(`translate(${centerX} ${centerY}) scale(${flipX ? -1 : 1} ${flipY ? -1 : 1}) translate(${-centerX} ${-centerY})`);
|
|
72
|
+
return transforms.length ? transforms.join(" ") : undefined;
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@affino/diagram-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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.12.0"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"devDependencies": {
|