@affino/diagram-vue 0.10.0 → 0.11.1
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"
|
|
@@ -76,7 +78,7 @@ const pointer = useDiagramPointerController(diagram)
|
|
|
76
78
|
</template>
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
Double-click a cell or focus it and press Enter/F2 to edit. Enter commits and returns focus to the cell; Escape discards; blur commits; Up/Down move to the adjacent cell, and Left/Right move when the text caret is at the corresponding edge. While selected, the accessible table toolbar exposes row/column insertion and deletion, row/column sizes, cell alignment, grid visibility/color/width/style, and outer border visibility/color/width/style/radius. Set `showToolbar` to `false` to hide only that built-in toolbar and expose commands in an external inspector through `useDiagramTable(diagram, id)`; cell editing and diagram interactions remain enabled. Toolbar/editor pointer events stop at the controls; the table surface continues to bubble pointer gestures to the diagram controller.
|
|
81
|
+
Double-click a cell or focus it and press Enter/F2 to edit. Typing a printable key starts editing with that character replacing the previous cell text; IME composition and Ctrl/Meta/Alt shortcuts do not trigger replacement. Enter commits and returns focus to the cell; Escape discards; blur commits; Up/Down move to the adjacent cell, and Left/Right move when the text caret is at the corresponding edge. Keyboard-focused cells use a subtle `--affino-focus-ring-color`/`--affino-accent` ring that adapts to the active theme and does not alter grid strokes. While selected, the accessible table toolbar exposes row/column insertion and deletion, row/column sizes, cell alignment, grid visibility/color/width/style, and outer border visibility/color/width/style/radius. Set `showToolbar` to `false` to hide only that built-in toolbar and expose commands in an external inspector through `useDiagramTable(diagram, id)`; cell editing and diagram interactions remain enabled. Toolbar/editor pointer events stop at the controls; the table surface continues to bubble pointer gestures to the diagram controller.
|
|
80
82
|
|
|
81
83
|
## Viewport resize
|
|
82
84
|
|
|
@@ -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({
|
|
@@ -58,9 +59,9 @@ export const DiagramTableView = defineComponent({
|
|
|
58
59
|
};
|
|
59
60
|
const cancelEdit = () => { const edit = editing.value; editing.value = null; if (edit)
|
|
60
61
|
focusCell(edit.row, edit.column); };
|
|
61
|
-
const beginEdit = (table, row, column) => {
|
|
62
|
+
const beginEdit = (table, row, column, initialText) => {
|
|
62
63
|
selectedCell.value = { row, column };
|
|
63
|
-
editing.value = { row, column, text: currentCell(table, row, column).text };
|
|
64
|
+
editing.value = { row, column, text: initialText !== null && initialText !== void 0 ? initialText : currentCell(table, row, column).text };
|
|
64
65
|
};
|
|
65
66
|
const navigateEdit = (table, rowDelta, columnDelta, expected) => {
|
|
66
67
|
commitEdit(expected);
|
|
@@ -110,19 +111,24 @@ export const DiagramTableView = defineComponent({
|
|
|
110
111
|
const anchor = cell.horizontalAlign === "center" ? "middle" : cell.horizontalAlign === "right" ? "end" : "start";
|
|
111
112
|
const textX = anchor === "start" ? x + padding : anchor === "end" ? x + width - padding : x + width / 2;
|
|
112
113
|
const textY = cell.verticalAlign === "top" ? y + padding : cell.verticalAlign === "bottom" ? y + height - padding : y + height / 2;
|
|
113
|
-
children.push(h("rect", { x, y, width, height, fill: active && selected.value ? "var(--affino-diagram-table-cell-active, rgba(59, 130, 246, 0.08))" : "transparent", stroke: active && selected.value ? "var(--affino-accent, #3b82f6)" : "transparent", "stroke-width": active && selected.value ? 1 : 0, role: "gridcell", tabindex: selected.value && active ? 0 : -1, "data-table-row": row, "data-table-column": column, "aria-label": `Row ${row + 1}, column ${column + 1}: ${cell.text}`, onClick: (event) => { event.stopPropagation(); selectedCell.value = { row, column }; }, onDblclick: (event) => { event.stopPropagation(); beginEdit(table, row, column); }, onKeydown: (event) => onCellKey(event, table, row, column, beginEdit, selectedCell) }));
|
|
114
|
+
children.push(h("rect", { class: "affino-diagram-table-cell", x, y, width, height, fill: active && selected.value ? "var(--affino-diagram-table-cell-active, rgba(59, 130, 246, 0.08))" : "transparent", stroke: active && selected.value ? "var(--affino-accent, #3b82f6)" : "transparent", "stroke-width": active && selected.value ? 1 : 0, role: "gridcell", tabindex: selected.value && active ? 0 : -1, "data-table-row": row, "data-table-column": column, "aria-label": `Row ${row + 1}, column ${column + 1}: ${cell.text}`, onClick: (event) => { event.stopPropagation(); selectedCell.value = { row, column }; }, onDblclick: (event) => { event.stopPropagation(); beginEdit(table, row, column); }, onKeydown: (event) => onCellKey(event, table, row, column, beginEdit, selectedCell) }));
|
|
114
115
|
if (!isEditing)
|
|
115
116
|
children.push(h("text", { x: textX, y: textY, "text-anchor": anchor, "dominant-baseline": cell.verticalAlign === "top" ? "hanging" : cell.verticalAlign === "bottom" ? "auto" : "middle", fill: "var(--affino-diagram-table-text, currentColor)", "font-size": 14, "pointer-events": "none" }, cell.text));
|
|
116
117
|
}
|
|
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("style", tableCellFocusStyles), 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,
|
|
@@ -203,14 +209,29 @@ function onCellKey(event, table, row, column, beginEdit, selectedCell) {
|
|
|
203
209
|
if (event.key === "Enter" || event.key === "F2") {
|
|
204
210
|
event.preventDefault();
|
|
205
211
|
beginEdit(table, row, column);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (isPrintableCellInput(event)) {
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
event.stopPropagation();
|
|
217
|
+
beginEdit(table, row, column, event.key);
|
|
206
218
|
}
|
|
207
219
|
}
|
|
220
|
+
function isPrintableCellInput(event) {
|
|
221
|
+
return !event.isComposing
|
|
222
|
+
&& event.keyCode !== 229
|
|
223
|
+
&& !event.ctrlKey
|
|
224
|
+
&& !event.metaKey
|
|
225
|
+
&& !event.altKey
|
|
226
|
+
&& Array.from(event.key).length === 1;
|
|
227
|
+
}
|
|
208
228
|
function currentCellValue(table, cell) { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = table.cells) === null || _a === void 0 ? void 0 : _a[cell.row]) === null || _b === void 0 ? void 0 : _b[cell.column]) !== null && _c !== void 0 ? _c : table.defaultCell) !== null && _d !== void 0 ? _d : { text: "" }; }
|
|
209
229
|
function offsets(sizes, start) { const result = [start]; for (const size of sizes)
|
|
210
230
|
result.push(result[result.length - 1] + size); return result; }
|
|
211
231
|
function dash(style) { return style === "dashed" ? "6 4" : style === "dotted" ? "1 3" : undefined; }
|
|
212
232
|
function colorInputValue(color) { return /^#[0-9a-f]{6}$/i.test(color) ? color : "#64748b"; }
|
|
213
233
|
const defaultStyle = { grid: { visible: true, stroke: { color: "#d1d5db", width: 1, style: "solid" } }, border: { visible: true, stroke: { color: "#9ca3af", width: 1, style: "solid" }, radius: 8 }, cellPadding: 8 };
|
|
234
|
+
const tableCellFocusStyles = `.affino-diagram-table-cell:focus{outline:none}.affino-diagram-table-cell:focus-visible{stroke:var(--affino-focus-ring-color,var(--affino-accent,#3b82f6));stroke-width:2;vector-effect:non-scaling-stroke}`;
|
|
214
235
|
const buttonStyle = { border: "1px solid var(--affino-border, #d1d5db)", borderRadius: "5px", background: "var(--affino-surface, #fff)", color: "var(--affino-text, #111827)", fontSize: "12px", padding: "3px 6px", whiteSpace: "nowrap" };
|
|
215
236
|
const inputStyle = { boxSizing: "border-box", maxWidth: "72px", border: "1px solid var(--affino-border, #d1d5db)", borderRadius: "4px", background: "var(--affino-surface, #fff)", color: "var(--affino-text, #111827)", fontSize: "12px", padding: "3px" };
|
|
216
237
|
const fieldStyle = { display: "inline-flex", alignItems: "center", gap: "3px", fontSize: "11px", whiteSpace: "nowrap" };
|
|
@@ -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.1",
|
|
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": {
|