@affino/diagram-vue 0.8.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 CHANGED
@@ -53,6 +53,31 @@ const textEditor = useDiagramTextEditor(diagram)
53
53
  </template>
54
54
  ```
55
55
 
56
+ ### Visual table component
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. 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
+
60
+ ```vue
61
+ <script setup lang="ts">
62
+ import { DiagramTableView, useDiagramEngine, useDiagramPointerController } from "@affino/diagram-vue"
63
+
64
+ const diagram = useDiagramEngine({
65
+ tables: [{ id: "notes", kind: "table", x: 40, y: 40, width: 320, height: 120, rowCount: 2, columnCount: 2,
66
+ cells: [[{ text: "Item", horizontalAlign: "center" }, { text: "Value" }], [{ text: "Relay" }, { text: "R1" }]] }],
67
+ viewport: { x: 0, y: 0, width: 900, height: 600, zoom: 1 },
68
+ })
69
+ const pointer = useDiagramPointerController(diagram)
70
+ </script>
71
+
72
+ <template>
73
+ <svg :viewBox="`${diagram.scene.value.viewport.x} ${diagram.scene.value.viewport.y} ${diagram.scene.value.viewport.width} ${diagram.scene.value.viewport.height}`">
74
+ <DiagramTableView :controller="diagram" :pointer="pointer" id="notes" :show-toolbar="false" />
75
+ </svg>
76
+ </template>
77
+ ```
78
+
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.
80
+
56
81
  ## Viewport resize
57
82
 
58
83
  `useDiagramViewport()` can attach a viewport element and write width/height changes into core through `setViewport` commands.
@@ -92,7 +117,7 @@ Preview geometry remains transient until pointerup. Start endpoint gestures with
92
117
 
93
118
  `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.
94
119
 
95
- During selection and edge endpoint drags, holding Shift constrains movement to the dominant axis from the gesture origin. During resize gestures it preserves the original aspect ratio. The Vue pointer adapter forwards `shiftKey` to core on pointer events, so pressing or releasing Shift updates the active preview.
120
+ During selection drags, holding Shift constrains movement to the dominant axis from the gesture origin. During edge endpoint drags, Shift projects the edge vector from its stationary endpoint to a latched cardinal angle. During resize gestures it preserves the original aspect ratio. The Vue pointer adapter forwards `shiftKey` to core on pointer events, so pressing or releasing Shift updates the active preview.
96
121
 
97
122
  ### Migration from 0.1.0
98
123
 
@@ -0,0 +1,48 @@
1
+ import type { PropType } from "vue";
2
+ import type { DiagramEngineController } from "./useDiagramEngine.js";
3
+ import type { DiagramPointerController } from "./useDiagramPointerController.js";
4
+ /** SVG-native table renderer with one accessible foreignObject editor and toolbar while selected. */
5
+ export declare const DiagramTableView: import("vue").DefineComponent<{
6
+ controller: {
7
+ type: PropType<DiagramEngineController>;
8
+ required: true;
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
+ };
20
+ id: {
21
+ type: StringConstructor;
22
+ required: true;
23
+ };
24
+ }, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
25
+ [key: string]: any;
26
+ }> | null, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
27
+ controller: {
28
+ type: PropType<DiagramEngineController>;
29
+ required: true;
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
+ };
41
+ id: {
42
+ type: StringConstructor;
43
+ required: true;
44
+ };
45
+ }>>, {
46
+ showToolbar: boolean;
47
+ }, {}>;
48
+ //# sourceMappingURL=DiagramTableView.d.ts.map
@@ -0,0 +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;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"}
@@ -0,0 +1,218 @@
1
+ import { computed, defineComponent, h, nextTick, ref, watch } from "vue";
2
+ import { useDiagramTable } from "./useDiagramTable.js";
3
+ /** SVG-native table renderer with one accessible foreignObject editor and toolbar while selected. */
4
+ export const DiagramTableView = defineComponent({
5
+ name: "DiagramTableView",
6
+ props: {
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 },
12
+ id: { type: String, required: true },
13
+ },
14
+ setup(props) {
15
+ const model = useDiagramTable(props.controller, props.id);
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
+ });
41
+ const selectedCell = ref({ row: 0, column: 0 });
42
+ const editing = ref(null);
43
+ const input = ref(null);
44
+ const tableRoot = ref(null);
45
+ watch(editing, (value) => { if (value)
46
+ void nextTick(() => { var _a; return (_a = input.value) === null || _a === void 0 ? void 0 : _a.focus(); }); });
47
+ const focusCell = (row, column) => { void nextTick(() => { var _a, _b; return (_b = (_a = tableRoot.value) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-table-row="${row}"][data-table-column="${column}"]`)) === null || _b === void 0 ? void 0 : _b.focus(); }); };
48
+ const currentCell = (table, row, column) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = table.cells) === null || _a === void 0 ? void 0 : _a[row]) === null || _b === void 0 ? void 0 : _b[column]) !== null && _c !== void 0 ? _c : table.defaultCell) !== null && _d !== void 0 ? _d : { text: "" }; };
49
+ const commitEdit = (expected, restoreFocus = false) => {
50
+ const edit = editing.value;
51
+ if (!edit || (expected && edit !== expected))
52
+ return false;
53
+ editing.value = null;
54
+ const changed = model.updateCell(edit.row, edit.column, { text: edit.text });
55
+ if (restoreFocus)
56
+ focusCell(edit.row, edit.column);
57
+ return changed;
58
+ };
59
+ const cancelEdit = () => { const edit = editing.value; editing.value = null; if (edit)
60
+ focusCell(edit.row, edit.column); };
61
+ const beginEdit = (table, row, column) => {
62
+ selectedCell.value = { row, column };
63
+ editing.value = { row, column, text: currentCell(table, row, column).text };
64
+ };
65
+ const navigateEdit = (table, rowDelta, columnDelta, expected) => {
66
+ commitEdit(expected);
67
+ const row = Math.max(0, Math.min(table.rowCount - 1, selectedCell.value.row + rowDelta));
68
+ const column = Math.max(0, Math.min(table.columnCount - 1, selectedCell.value.column + columnDelta));
69
+ beginEdit(table, row, column);
70
+ };
71
+ const stopToolbarEvent = (event) => event.stopPropagation();
72
+ const button = (label, action) => h("button", { type: "button", "aria-label": label, onPointerdown: stopToolbarEvent, onClick: (event) => { event.stopPropagation(); action(); }, style: buttonStyle }, label);
73
+ const select = (label, value, values, update) => h("label", { style: fieldStyle }, [
74
+ h("span", { style: visuallyHiddenStyle }, label),
75
+ h("select", { "aria-label": label, value, onPointerdown: stopToolbarEvent, onChange: (event) => { event.stopPropagation(); update(event.target.value); }, style: inputStyle }, values.map((entry) => h("option", { value: entry }, entry))),
76
+ ]);
77
+ const checkbox = (label, checked, update) => h("label", { style: fieldStyle }, [
78
+ h("input", { type: "checkbox", "aria-label": label, checked, onPointerdown: stopToolbarEvent, onChange: (event) => { event.stopPropagation(); update(event.target.checked); } }), label,
79
+ ]);
80
+ const numberInput = (label, value, update, min = 0) => h("label", { style: fieldStyle }, [
81
+ h("span", { style: visuallyHiddenStyle }, label), h("input", { type: "number", "aria-label": label, value, min, step: 1, onPointerdown: stopToolbarEvent, onChange: (event) => { event.stopPropagation(); update(Number(event.target.value)); }, style: inputStyle }),
82
+ ]);
83
+ return () => {
84
+ var _a, _b, _c, _d, _e, _f;
85
+ const table = projectedTable.value;
86
+ if (!table)
87
+ return null;
88
+ const style = (_a = table.style) !== null && _a !== void 0 ? _a : defaultStyle;
89
+ const columnOffsets = offsets((_b = table.columnWidths) !== null && _b !== void 0 ? _b : [], table.x);
90
+ const rowOffsets = offsets((_c = table.rowHeights) !== null && _c !== void 0 ? _c : [], table.y);
91
+ const padding = (_d = style.cellPadding) !== null && _d !== void 0 ? _d : 8;
92
+ const children = [
93
+ h("rect", { x: table.x, y: table.y, width: table.width, height: table.height, rx: style.border.radius, fill: "var(--affino-diagram-table-surface, var(--affino-surface, #ffffff))", stroke: "none" }),
94
+ ];
95
+ if (style.grid.visible) {
96
+ for (let column = 1; column < table.columnCount; column += 1)
97
+ children.push(h("line", { x1: columnOffsets[column], y1: table.y, x2: columnOffsets[column], y2: table.y + table.height, stroke: style.grid.stroke.color, "stroke-width": style.grid.stroke.width, "stroke-dasharray": dash(style.grid.stroke.style), "vector-effect": "non-scaling-stroke", "pointer-events": "none" }));
98
+ for (let row = 1; row < table.rowCount; row += 1)
99
+ children.push(h("line", { x1: table.x, y1: rowOffsets[row], x2: table.x + table.width, y2: rowOffsets[row], stroke: style.grid.stroke.color, "stroke-width": style.grid.stroke.width, "stroke-dasharray": dash(style.grid.stroke.style), "vector-effect": "non-scaling-stroke", "pointer-events": "none" }));
100
+ }
101
+ for (let row = 0; row < table.rowCount; row += 1) {
102
+ for (let column = 0; column < table.columnCount; column += 1) {
103
+ const cell = currentCell(table, row, column);
104
+ const x = columnOffsets[column];
105
+ const y = rowOffsets[row];
106
+ const width = table.columnWidths[column];
107
+ const height = table.rowHeights[row];
108
+ const active = selectedCell.value.row === row && selectedCell.value.column === column;
109
+ const isEditing = ((_e = editing.value) === null || _e === void 0 ? void 0 : _e.row) === row && ((_f = editing.value) === null || _f === void 0 ? void 0 : _f.column) === column;
110
+ const anchor = cell.horizontalAlign === "center" ? "middle" : cell.horizontalAlign === "right" ? "end" : "start";
111
+ const textX = anchor === "start" ? x + padding : anchor === "end" ? x + width - padding : x + width / 2;
112
+ 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
+ if (!isEditing)
115
+ 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
+ }
118
+ if (style.border.visible)
119
+ 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" }));
120
+ const activeEdit = editing.value;
121
+ if (activeEdit) {
122
+ const x = columnOffsets[activeEdit.column];
123
+ const y = rowOffsets[activeEdit.row];
124
+ const width = table.columnWidths[activeEdit.column];
125
+ const height = table.rowHeights[activeEdit.row];
126
+ children.push(h("foreignObject", { x, y, width, height }, [h("input", {
127
+ ref: input, value: activeEdit.text, "aria-label": `Edit row ${activeEdit.row + 1}, column ${activeEdit.column + 1}`,
128
+ onPointerdown: stopToolbarEvent, onClick: stopToolbarEvent,
129
+ onInput: (event) => { if (editing.value)
130
+ editing.value = { ...editing.value, text: event.target.value }; },
131
+ onBlur: () => commitEdit(activeEdit),
132
+ onKeydown: (event) => {
133
+ event.stopPropagation();
134
+ if (event.key === "Escape") {
135
+ event.preventDefault();
136
+ cancelEdit();
137
+ }
138
+ else if (event.key === "Enter") {
139
+ event.preventDefault();
140
+ commitEdit(activeEdit, true);
141
+ }
142
+ else if (event.key === "ArrowUp") {
143
+ event.preventDefault();
144
+ navigateEdit(table, -1, 0, activeEdit);
145
+ }
146
+ else if (event.key === "ArrowDown") {
147
+ event.preventDefault();
148
+ navigateEdit(table, 1, 0, activeEdit);
149
+ }
150
+ else if (event.key === "ArrowLeft" && event.target.selectionStart === 0) {
151
+ event.preventDefault();
152
+ navigateEdit(table, 0, -1, activeEdit);
153
+ }
154
+ else if (event.key === "ArrowRight" && event.target.selectionEnd === activeEdit.text.length) {
155
+ event.preventDefault();
156
+ navigateEdit(table, 0, 1, activeEdit);
157
+ }
158
+ },
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" },
160
+ })]));
161
+ }
162
+ if (selected.value && props.showToolbar)
163
+ children.push(toolbar(table, style, selectedCell.value, model, button, select, checkbox, numberInput, stopToolbarEvent));
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);
165
+ };
166
+ },
167
+ });
168
+ function toolbar(table, style, cell, model, button, select, checkbox, numberInput, stopToolbarEvent) {
169
+ var _a, _b, _c, _d, _e, _f;
170
+ const controls = [
171
+ button("Insert row", () => model.insertRow(cell.row + 1)),
172
+ button("Delete row", () => model.deleteRow(cell.row)),
173
+ button("Insert column", () => model.insertColumn(cell.column + 1)),
174
+ button("Delete column", () => model.deleteColumn(cell.column)),
175
+ numberInput("Row height", (_b = (_a = table.rowHeights) === null || _a === void 0 ? void 0 : _a[cell.row]) !== null && _b !== void 0 ? _b : table.height / table.rowCount, (height) => model.resizeRow(cell.row, height), 1),
176
+ numberInput("Column width", (_d = (_c = table.columnWidths) === null || _c === void 0 ? void 0 : _c[cell.column]) !== null && _d !== void 0 ? _d : table.width / table.columnCount, (width) => model.resizeColumn(cell.column, width), 1),
177
+ select("Horizontal text alignment", (_e = currentCellValue(table, cell).horizontalAlign) !== null && _e !== void 0 ? _e : "left", ["left", "center", "right"], (value) => model.updateCell(cell.row, cell.column, { horizontalAlign: value })),
178
+ select("Vertical text alignment", (_f = currentCellValue(table, cell).verticalAlign) !== null && _f !== void 0 ? _f : "middle", ["top", "middle", "bottom"], (value) => model.updateCell(cell.row, cell.column, { verticalAlign: value })),
179
+ checkbox("Show table grid", style.grid.visible, (visible) => model.updateStyle({ grid: { visible } })),
180
+ h("label", { style: fieldStyle }, [h("span", { style: visuallyHiddenStyle }, "Grid color"), h("input", { type: "color", "aria-label": "Grid color", value: colorInputValue(style.grid.stroke.color), onPointerdown: stopToolbarEvent, onClick: stopToolbarEvent, onChange: (event) => model.updateStyle({ grid: { stroke: { color: event.target.value } } }), style: inputStyle })]),
181
+ numberInput("Grid thickness", style.grid.stroke.width, (width) => model.updateStyle({ grid: { stroke: { width } } })),
182
+ select("Grid line style", style.grid.stroke.style, ["solid", "dashed", "dotted"], (value) => model.updateStyle({ grid: { stroke: { style: value } } })),
183
+ checkbox("Show outer border", style.border.visible, (visible) => model.updateStyle({ border: { visible } })),
184
+ h("label", { style: fieldStyle }, [h("span", { style: visuallyHiddenStyle }, "Border color"), h("input", { type: "color", "aria-label": "Border color", value: colorInputValue(style.border.stroke.color), onPointerdown: stopToolbarEvent, onClick: stopToolbarEvent, onChange: (event) => model.updateStyle({ border: { stroke: { color: event.target.value } } }), style: inputStyle })]),
185
+ numberInput("Border thickness", style.border.stroke.width, (width) => model.updateStyle({ border: { stroke: { width } } })),
186
+ select("Border line style", style.border.stroke.style, ["solid", "dashed", "dotted"], (value) => model.updateStyle({ border: { stroke: { style: value } } })),
187
+ numberInput("Border corner radius", style.border.radius, (radius) => model.updateStyle({ border: { radius } })),
188
+ ];
189
+ return h("foreignObject", { x: table.x, y: table.y - 42, width: 660, height: 40 }, [h("div", { role: "toolbar", "aria-label": "Table formatting", onPointerdown: (event) => event.stopPropagation(), onClick: (event) => event.stopPropagation(), style: toolbarStyle }, controls)]);
190
+ }
191
+ function onCellKey(event, table, row, column, beginEdit, selectedCell) {
192
+ var _a;
193
+ const delta = event.key === "ArrowUp" ? [-1, 0] : event.key === "ArrowDown" ? [1, 0] : event.key === "ArrowLeft" ? [0, -1] : event.key === "ArrowRight" ? [0, 1] : null;
194
+ if (delta) {
195
+ event.preventDefault();
196
+ const nextRow = Math.max(0, Math.min(table.rowCount - 1, row + delta[0]));
197
+ const nextColumn = Math.max(0, Math.min(table.columnCount - 1, column + delta[1]));
198
+ selectedCell.value = { row: nextRow, column: nextColumn };
199
+ const grid = (_a = event.currentTarget) === null || _a === void 0 ? void 0 : _a.closest("[role=grid]");
200
+ void nextTick(() => { var _a; return (_a = grid === null || grid === void 0 ? void 0 : grid.querySelector(`[data-table-row="${nextRow}"][data-table-column="${nextColumn}"]`)) === null || _a === void 0 ? void 0 : _a.focus(); });
201
+ return;
202
+ }
203
+ if (event.key === "Enter" || event.key === "F2") {
204
+ event.preventDefault();
205
+ beginEdit(table, row, column);
206
+ }
207
+ }
208
+ 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
+ function offsets(sizes, start) { const result = [start]; for (const size of sizes)
210
+ result.push(result[result.length - 1] + size); return result; }
211
+ function dash(style) { return style === "dashed" ? "6 4" : style === "dotted" ? "1 3" : undefined; }
212
+ function colorInputValue(color) { return /^#[0-9a-f]{6}$/i.test(color) ? color : "#64748b"; }
213
+ 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 };
214
+ 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
+ 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
+ const fieldStyle = { display: "inline-flex", alignItems: "center", gap: "3px", fontSize: "11px", whiteSpace: "nowrap" };
217
+ const toolbarStyle = { display: "flex", flexWrap: "nowrap", alignItems: "center", gap: "4px", overflowX: "auto", width: "100%", height: "100%", boxSizing: "border-box", padding: "3px", border: "1px solid var(--affino-border, #d1d5db)", borderRadius: "6px", background: "var(--affino-surface, #fff)", color: "var(--affino-text, #111827)", fontFamily: "inherit" };
218
+ const visuallyHiddenStyle = { position: "absolute", width: "1px", height: "1px", padding: 0, margin: "-1px", overflow: "hidden", clip: "rect(0, 0, 0, 0)", whiteSpace: "nowrap", border: 0 };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export { useDiagramSelection } from "./useDiagramSelection.js";
4
4
  export { useDiagramVisibleEntities } from "./useDiagramVisibleEntities.js";
5
5
  export { useDiagramPointerController } from "./useDiagramPointerController.js";
6
6
  export { useDiagramTextEditor } from "./useDiagramTextEditor.js";
7
+ export { useDiagramTable } from "./useDiagramTable.js";
8
+ export { DiagramTableView } from "./DiagramTableView.js";
7
9
  export { getDomEntityStyle, getSvgEntityProps } from "./useDiagramRenderer.js";
8
10
  export type * from "./types.js";
9
11
  export type * from "./useDiagramEngine.js";
@@ -12,5 +14,6 @@ export type * from "./useDiagramSelection.js";
12
14
  export type * from "./useDiagramVisibleEntities.js";
13
15
  export type * from "./useDiagramPointerController.js";
14
16
  export type * from "./useDiagramTextEditor.js";
17
+ export type * from "./useDiagramTable.js";
15
18
  export type * from "./useDiagramRenderer.js";
16
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC9E,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,yBAAyB,CAAA;AAC5C,mBAAmB,0BAA0B,CAAA;AAC7C,mBAAmB,gCAAgC,CAAA;AACnD,mBAAmB,kCAAkC,CAAA;AACrD,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,yBAAyB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC9E,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,yBAAyB,CAAA;AAC5C,mBAAmB,0BAA0B,CAAA;AAC7C,mBAAmB,gCAAgC,CAAA;AACnD,mBAAmB,kCAAkC,CAAA;AACrD,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,sBAAsB,CAAA;AACzC,mBAAmB,yBAAyB,CAAA"}
package/dist/index.js CHANGED
@@ -4,4 +4,6 @@ export { useDiagramSelection } from "./useDiagramSelection.js";
4
4
  export { useDiagramVisibleEntities } from "./useDiagramVisibleEntities.js";
5
5
  export { useDiagramPointerController } from "./useDiagramPointerController.js";
6
6
  export { useDiagramTextEditor } from "./useDiagramTextEditor.js";
7
+ export { useDiagramTable } from "./useDiagramTable.js";
8
+ export { DiagramTableView } from "./DiagramTableView.js";
7
9
  export { getDomEntityStyle, getSvgEntityProps } from "./useDiagramRenderer.js";
package/dist/types.d.ts CHANGED
@@ -24,6 +24,7 @@ export type DiagramVisibleProjection = Readonly<{
24
24
  edges: ReadonlyArray<DiagramRenderEntity>;
25
25
  texts: ReadonlyArray<DiagramRenderEntity>;
26
26
  shapes: ReadonlyArray<DiagramRenderEntity>;
27
+ tables: ReadonlyArray<DiagramRenderEntity>;
27
28
  ports: ReadonlyArray<DiagramRenderEntity>;
28
29
  activeHandles: ReadonlyArray<DiagramHandle>;
29
30
  overlayAnchors: ReadonlyArray<DiagramOverlayAnchor>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEpH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,KAAK,CAAA;AAE9C,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,EAAE,EAAE,SAAS,CAAA;IACb,IAAI,EAAE,iBAAiB,CAAA;IACvB,KAAK,EAAE,kBAAkB,CAAA;IACzB,QAAQ,EAAE,eAAe,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAC,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,SAAS,CAAA;IAClB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,eAAe,CAAA;IACzC,KAAK,EAAE,YAAY,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,EAAE,EAAE,SAAS,CAAA;IACb,IAAI,EAAE,iBAAiB,CAAA;IACvB,IAAI,EAAE,WAAW,CAAA;CAClB,CAAC,CAAA;AAEF,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;IAC7B,KAAK,EAAE,aAAa,CAAC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AC,SAAS,CAAC,CAAA;IAC7B,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,MAAM,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IAC1C,MAAM,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IAC1C,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzC,aAAa,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;IAC3C,cAAc,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAA;CACpD,CAAC,CAAA"}
@@ -25,7 +25,7 @@ export function getSvgEntityProps(entity) {
25
25
  r: geometry.bounds.width / 2,
26
26
  };
27
27
  }
28
- if (entity.kind === "shape" || entity.kind === "node") {
28
+ if (entity.kind === "shape" || entity.kind === "node" || entity.kind === "table") {
29
29
  return {
30
30
  ...common,
31
31
  x: bounds.x,
@@ -0,0 +1,16 @@
1
+ import type { ComputedRef } from "vue";
2
+ import type { DiagramId, DiagramTable, DiagramTableCell, DiagramTableStyleUpdate } from "@affino/diagram-core";
3
+ import type { DiagramEngineController } from "./useDiagramEngine.js";
4
+ export type DiagramTableController = Readonly<{
5
+ table: ComputedRef<DiagramTable | null>;
6
+ insertRow: (index: number, cells?: ReadonlyArray<DiagramTableCell>) => boolean;
7
+ deleteRow: (index: number) => boolean;
8
+ insertColumn: (index: number, cells?: ReadonlyArray<DiagramTableCell>) => boolean;
9
+ deleteColumn: (index: number) => boolean;
10
+ resizeRow: (index: number, height: number) => boolean;
11
+ resizeColumn: (index: number, width: number) => boolean;
12
+ updateCell: (row: number, column: number, cell: Partial<DiagramTableCell>) => boolean;
13
+ updateStyle: (style: DiagramTableStyleUpdate) => boolean;
14
+ }>;
15
+ export declare function useDiagramTable(controller: DiagramEngineController, id: DiagramId): DiagramTableController;
16
+ //# sourceM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AAG,sBAAsB,CAc1G"}
@@ -0,0 +1,16 @@
1
+ import { computed } from "vue";
2
+ export function useDiagramTable(controller, id) {
3
+ const table = computed(() => { var _a; return (_a = controller.scene.value.entities.tablesById.get(id)) !== null && _a !== void 0 ? _a : null; });
4
+ const dispatch = (command) => controller.dispatch(command).changed;
5
+ return {
6
+ table,
7
+ insertRow: (index, cells) => dispatch({ type: "insertTableRow", id, index, cells }),
8
+ deleteRow: (index) => dispatch({ type: "deleteTableRow", id, index }),
9
+ insertColumn: (index, cells) => dispatch({ type: "insertTableColumn", id, index, cells }),
10
+ deleteColumn: (index) => dispatch({ type: "deleteTableColumn", id, index }),
11
+ resizeRow: (index, height) => dispatch({ type: "resizeTableRow", id, index, height }),
12
+ resizeColumn: (index, width) => dispatch({ type: "resizeTableColumn", id, index, width }),
13
+ updateCell: (row, column, cell) => dispatch({ type: "updateTableCell", id, row, column, cell }),
14
+ updateStyle: (style) => dispatch({ type: "updateTableStyle", id, style }),
15
+ };
16
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"useDiagramVisibleEntities.d.ts","sourceRoot":"","sources":["../src/useDiagramVisibleEntities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAA8D,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACnH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAA4D,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAEpH,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,MAAM,gCAAgC,GAAG,QAAQ,CAAC;IACtD,UAAU,EAAE,UAAU,CAAC,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"}
1
+ {"version":3,"file":"useDiagramVisibleEntities.d.ts","sourceRoot":"","sources":["../src/useDiagramVisibleEntities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAA8D,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACnH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAA4D,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAEpH,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAC,CAAA;AAEF,MAAM,MAAM,gCAAgC,GAAG,QAAQ,CAAC;IACtD,UAAU,EAAE,UAAU,CAAC,wBAAwB,CAAC,CAAA;IAChD,cAAc,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAcF,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,6BAAkC,GAAG,gCAAgC,CAyB5J"}
@@ -6,6 +6,7 @@ const EMPTY_PROJECTION = Object.freeze({
6
6
  edges: Object.freeze([]),
7
7
  texts: Object.freeze([]),
8
8
  shapes: Object.freeze([]),
9
+ tables: Object.freeze([]),
9
10
  ports: Object.freeze([]),
10
11
  activeHandles: Object.freeze([]),
11
12
  overlayAnchors: Object.freeze([]),
@@ -73,6 +74,7 @@ function buildProjection(controller, bounds, includeSelection, entityCache) {
73
74
  edges: freezeKind(entities, "edge"),
74
75
  texts: freezeKind(entities, "text"),
75
76
  shapes: freezeKind(entities, "shape"),
77
+ tables: freezeKind(entities, "table"),
76
78
  ports: freezeKind(entities, "port"),
77
79
  activeHandles: Object.freeze(activeHandles),
78
80
  overlayAnchors: Object.freeze(anchorGeometries.map(createOverlayAnchor)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affino/diagram-vue",
3
- "version": "0.8.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.10.0"
24
+ "@affino/diagram-core": "^0.11.1"
25
25
  },
26
26
  "license": "MIT",
27
27
  "devDependencies": {