@affino/diagram-vue 0.9.0 → 0.10.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 +5 -4
- package/dist/DiagramTableView.d.ts +24 -1
- package/dist/DiagramTableView.d.ts.map +1 -1
- package/dist/DiagramTableView.js +30 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -55,27 +55,28 @@ const textEditor = useDiagramTextEditor(diagram)
|
|
|
55
55
|
|
|
56
56
|
### Visual table component
|
|
57
57
|
|
|
58
|
-
Create table data through Core, then render `DiagramTableView` inside the diagram SVG. The component reads the same reactive scene as other projections and sends cell/style/row/column changes through undoable Core commands; it has no duplicate application-owned table model.
|
|
58
|
+
Create table data through Core, then render `DiagramTableView` inside the diagram SVG. The component reads the same reactive scene as other projections and sends cell/style/row/column changes through undoable Core commands; it has no duplicate application-owned table model. Pass the optional pointer controller to project frame-batched drag and resize previews, including multi-selection and grouped-table resize. Preview geometry is transient: serialization, revision, and history remain unchanged until pointer-up, while pointer cancel returns to the committed scene.
|
|
59
59
|
|
|
60
60
|
```vue
|
|
61
61
|
<script setup lang="ts">
|
|
62
|
-
import { DiagramTableView, useDiagramEngine } from "@affino/diagram-vue"
|
|
62
|
+
import { DiagramTableView, useDiagramEngine, useDiagramPointerController } from "@affino/diagram-vue"
|
|
63
63
|
|
|
64
64
|
const diagram = useDiagramEngine({
|
|
65
65
|
tables: [{ id: "notes", kind: "table", x: 40, y: 40, width: 320, height: 120, rowCount: 2, columnCount: 2,
|
|
66
66
|
cells: [[{ text: "Item", horizontalAlign: "center" }, { text: "Value" }], [{ text: "Relay" }, { text: "R1" }]] }],
|
|
67
67
|
viewport: { x: 0, y: 0, width: 900, height: 600, zoom: 1 },
|
|
68
68
|
})
|
|
69
|
+
const pointer = useDiagramPointerController(diagram)
|
|
69
70
|
</script>
|
|
70
71
|
|
|
71
72
|
<template>
|
|
72
73
|
<svg :viewBox="`${diagram.scene.value.viewport.x} ${diagram.scene.value.viewport.y} ${diagram.scene.value.viewport.width} ${diagram.scene.value.viewport.height}`">
|
|
73
|
-
<DiagramTableView :controller="diagram" id="notes" />
|
|
74
|
+
<DiagramTableView :controller="diagram" :pointer="pointer" id="notes" :show-toolbar="false" />
|
|
74
75
|
</svg>
|
|
75
76
|
</template>
|
|
76
77
|
```
|
|
77
78
|
|
|
78
|
-
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. Toolbar/editor pointer events stop at the controls; the table surface continues to bubble pointer gestures to the diagram controller.
|
|
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.
|
|
79
80
|
|
|
80
81
|
## Viewport resize
|
|
81
82
|
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import type { PropType } from "vue";
|
|
2
2
|
import type { DiagramEngineController } from "./useDiagramEngine.js";
|
|
3
|
+
import type { DiagramPointerController } from "./useDiagramPointerController.js";
|
|
3
4
|
/** SVG-native table renderer with one accessible foreignObject editor and toolbar while selected. */
|
|
4
5
|
export declare const DiagramTableView: import("vue").DefineComponent<{
|
|
5
6
|
controller: {
|
|
6
7
|
type: PropType<DiagramEngineController>;
|
|
7
8
|
required: true;
|
|
8
9
|
};
|
|
10
|
+
/** Optional pointer controller used to project transient movement and resize previews. */
|
|
11
|
+
pointer: {
|
|
12
|
+
type: PropType<DiagramPointerController>;
|
|
13
|
+
required: false;
|
|
14
|
+
};
|
|
15
|
+
/** Hides only the built-in formatting toolbar; defaults to visible. */
|
|
16
|
+
showToolbar: {
|
|
17
|
+
type: BooleanConstructor;
|
|
18
|
+
default: boolean;
|
|
19
|
+
};
|
|
9
20
|
id: {
|
|
10
21
|
type: StringConstructor;
|
|
11
22
|
required: true;
|
|
@@ -17,9 +28,21 @@ export declare const DiagramTableView: import("vue").DefineComponent<{
|
|
|
17
28
|
type: PropType<DiagramEngineController>;
|
|
18
29
|
required: true;
|
|
19
30
|
};
|
|
31
|
+
/** Optional pointer controller used to project transient movement and resize previews. */
|
|
32
|
+
pointer: {
|
|
33
|
+
type: PropType<DiagramPointerController>;
|
|
34
|
+
required: false;
|
|
35
|
+
};
|
|
36
|
+
/** Hides only the built-in formatting toolbar; defaults to visible. */
|
|
37
|
+
showToolbar: {
|
|
38
|
+
type: BooleanConstructor;
|
|
39
|
+
default: boolean;
|
|
40
|
+
};
|
|
20
41
|
id: {
|
|
21
42
|
type: StringConstructor;
|
|
22
43
|
required: true;
|
|
23
44
|
};
|
|
24
|
-
}>>, {
|
|
45
|
+
}>>, {
|
|
46
|
+
showToolbar: boolean;
|
|
47
|
+
}, {}>;
|
|
25
48
|
//# sourceMappingURL=DiagramTableView.d.ts.map
|
|
@@ -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;
|
|
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;AAGhF,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;;;;;;;;;;;MA8HzE,CAAA"}
|
package/dist/DiagramTableView.js
CHANGED
|
@@ -5,11 +5,39 @@ export const DiagramTableView = defineComponent({
|
|
|
5
5
|
name: "DiagramTableView",
|
|
6
6
|
props: {
|
|
7
7
|
controller: { type: Object, required: true },
|
|
8
|
+
/** Optional pointer controller used to project transient movement and resize previews. */
|
|
9
|
+
pointer: { type: Object, required: false },
|
|
10
|
+
/** Hides only the built-in formatting toolbar; defaults to visible. */
|
|
11
|
+
showToolbar: { type: Boolean, default: true },
|
|
8
12
|
id: { type: String, required: true },
|
|
9
13
|
},
|
|
10
14
|
setup(props) {
|
|
11
15
|
const model = useDiagramTable(props.controller, props.id);
|
|
12
16
|
const selected = computed(() => props.controller.scene.value.selection.ids.includes(props.id));
|
|
17
|
+
const pointerSnapshot = computed(() => { var _a, _b; return (_b = (_a = props.pointer) === null || _a === void 0 ? void 0 : _a.state.value) !== null && _b !== void 0 ? _b : null; });
|
|
18
|
+
const projectedTable = computed(() => {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
const table = model.table.value;
|
|
21
|
+
const pointer = props.pointer;
|
|
22
|
+
const interaction = pointerSnapshot.value;
|
|
23
|
+
if (!table || !pointer || !(interaction === null || interaction === void 0 ? void 0 : interaction.active))
|
|
24
|
+
return table;
|
|
25
|
+
const geometry = pointer.interaction.getPreviewGeometry(props.id);
|
|
26
|
+
if (!geometry || geometry.kind !== "table")
|
|
27
|
+
return table;
|
|
28
|
+
const bounds = (_a = geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : geometry.bounds;
|
|
29
|
+
const scaleX = table.width === 0 ? 1 : bounds.width / table.width;
|
|
30
|
+
const scaleY = table.height === 0 ? 1 : bounds.height / table.height;
|
|
31
|
+
return {
|
|
32
|
+
...table,
|
|
33
|
+
x: bounds.x,
|
|
34
|
+
y: bounds.y,
|
|
35
|
+
width: bounds.width,
|
|
36
|
+
height: bounds.height,
|
|
37
|
+
columnWidths: (_b = table.columnWidths) === null || _b === void 0 ? void 0 : _b.map((size) => size * scaleX),
|
|
38
|
+
rowHeights: (_c = table.rowHeights) === null || _c === void 0 ? void 0 : _c.map((size) => size * scaleY),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
13
41
|
const selectedCell = ref({ row: 0, column: 0 });
|
|
14
42
|
const editing = ref(null);
|
|
15
43
|
const input = ref(null);
|
|
@@ -54,7 +82,7 @@ export const DiagramTableView = defineComponent({
|
|
|
54
82
|
]);
|
|
55
83
|
return () => {
|
|
56
84
|
var _a, _b, _c, _d, _e, _f;
|
|
57
|
-
const table =
|
|
85
|
+
const table = projectedTable.value;
|
|
58
86
|
if (!table)
|
|
59
87
|
return null;
|
|
60
88
|
const style = (_a = table.style) !== null && _a !== void 0 ? _a : defaultStyle;
|
|
@@ -131,7 +159,7 @@ export const DiagramTableView = defineComponent({
|
|
|
131
159
|
style: { boxSizing: "border-box", width: "100%", height: "100%", border: "2px solid var(--affino-accent, #3b82f6)", borderRadius: "2px", padding: `${padding}px`, background: "var(--affino-surface, #fff)", color: "var(--affino-text, #111827)", font: "inherit", outline: "none" },
|
|
132
160
|
})]));
|
|
133
161
|
}
|
|
134
|
-
if (selected.value)
|
|
162
|
+
if (selected.value && props.showToolbar)
|
|
135
163
|
children.push(toolbar(table, style, selectedCell.value, model, button, select, checkbox, numberInput, stopToolbarEvent));
|
|
136
164
|
return h("g", { ref: tableRoot, "data-diagram-id": table.id, "data-diagram-kind": "table", role: "grid", "aria-label": `Table ${table.id}`, "aria-rowcount": table.rowCount, "aria-colcount": table.columnCount, "data-selected": selected.value || undefined }, children);
|
|
137
165
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@affino/diagram-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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.11.
|
|
24
|
+
"@affino/diagram-core": "^0.11.1"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"devDependencies": {
|