@affino/diagram-vue 0.9.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"
@@ -55,27 +57,28 @@ const textEditor = useDiagramTextEditor(diagram)
55
57
 
56
58
  ### Visual table component
57
59
 
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.
60
+ 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
61
 
60
62
  ```vue
61
63
  <script setup lang="ts">
62
- import { DiagramTableView, useDiagramEngine } from "@affino/diagram-vue"
64
+ import { DiagramTableView, useDiagramEngine, useDiagramPointerController } from "@affino/diagram-vue"
63
65
 
64
66
  const diagram = useDiagramEngine({
65
67
  tables: [{ id: "notes", kind: "table", x: 40, y: 40, width: 320, height: 120, rowCount: 2, columnCount: 2,
66
68
  cells: [[{ text: "Item", horizontalAlign: "center" }, { text: "Value" }], [{ text: "Relay" }, { text: "R1" }]] }],
67
69
  viewport: { x: 0, y: 0, width: 900, height: 600, zoom: 1 },
68
70
  })
71
+ const pointer = useDiagramPointerController(diagram)
69
72
  </script>
70
73
 
71
74
  <template>
72
75
  <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" />
76
+ <DiagramTableView :controller="diagram" :pointer="pointer" id="notes" :show-toolbar="false" />
74
77
  </svg>
75
78
  </template>
76
79
  ```
77
80
 
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.
81
+ 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
82
 
80
83
  ## Viewport resize
81
84
 
@@ -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;AAGpE,qGAAqG;AACrG,eAAO,MAAM,gBAAgB;;cAGK,QAAQ,CAAC,uBAAuB,CAAC;;;;;;;;;;;cAAjC,QAAQ,CAAC,uBAAuB,CAAC;;;;;;;YAwGjE,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"}
@@ -1,15 +1,44 @@
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({
5
6
  name: "DiagramTableView",
6
7
  props: {
7
8
  controller: { type: Object, required: true },
9
+ /** Optional pointer controller used to project transient movement and resize previews. */
10
+ pointer: { type: Object, required: false },
11
+ /** Hides only the built-in formatting toolbar; defaults to visible. */
12
+ showToolbar: { type: Boolean, default: true },
8
13
  id: { type: String, required: true },
9
14
  },
10
15
  setup(props) {
11
16
  const model = useDiagramTable(props.controller, props.id);
12
17
  const selected = computed(() => props.controller.scene.value.selection.ids.includes(props.id));
18
+ 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; });
19
+ const projectedTable = computed(() => {
20
+ var _a, _b, _c;
21
+ const table = model.table.value;
22
+ const pointer = props.pointer;
23
+ const interaction = pointerSnapshot.value;
24
+ if (!table || !pointer || !(interaction === null || interaction === void 0 ? void 0 : interaction.active))
25
+ return table;
26
+ const geometry = pointer.interaction.getPreviewGeometry(props.id);
27
+ if (!geometry || geometry.kind !== "table")
28
+ return table;
29
+ const bounds = (_a = geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : geometry.bounds;
30
+ const scaleX = table.width === 0 ? 1 : bounds.width / table.width;
31
+ const scaleY = table.height === 0 ? 1 : bounds.height / table.height;
32
+ return {
33
+ ...table,
34
+ x: bounds.x,
35
+ y: bounds.y,
36
+ width: bounds.width,
37
+ height: bounds.height,
38
+ columnWidths: (_b = table.columnWidths) === null || _b === void 0 ? void 0 : _b.map((size) => size * scaleX),
39
+ rowHeights: (_c = table.rowHeights) === null || _c === void 0 ? void 0 : _c.map((size) => size * scaleY),
40
+ };
41
+ });
13
42
  const selectedCell = ref({ row: 0, column: 0 });
14
43
  const editing = ref(null);
15
44
  const input = ref(null);
@@ -54,7 +83,7 @@ export const DiagramTableView = defineComponent({
54
83
  ]);
55
84
  return () => {
56
85
  var _a, _b, _c, _d, _e, _f;
57
- const table = model.table.value;
86
+ const table = projectedTable.value;
58
87
  if (!table)
59
88
  return null;
60
89
  const style = (_a = table.style) !== null && _a !== void 0 ? _a : defaultStyle;
@@ -89,12 +118,17 @@ export const DiagramTableView = defineComponent({
89
118
  }
90
119
  if (style.border.visible)
91
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));
92
124
  const activeEdit = editing.value;
93
125
  if (activeEdit) {
94
- const x = columnOffsets[activeEdit.column];
95
- const y = rowOffsets[activeEdit.row];
126
+ const cellX = columnOffsets[activeEdit.column];
127
+ const cellY = rowOffsets[activeEdit.row];
96
128
  const width = table.columnWidths[activeEdit.column];
97
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;
98
132
  children.push(h("foreignObject", { x, y, width, height }, [h("input", {
99
133
  ref: input, value: activeEdit.text, "aria-label": `Edit row ${activeEdit.row + 1}, column ${activeEdit.column + 1}`,
100
134
  onPointerdown: stopToolbarEvent, onClick: stopToolbarEvent,
@@ -131,7 +165,7 @@ export const DiagramTableView = defineComponent({
131
165
  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
166
  })]));
133
167
  }
134
- if (selected.value)
168
+ if (selected.value && props.showToolbar)
135
169
  children.push(toolbar(table, style, selectedCell.value, model, button, select, checkbox, numberInput, stopToolbarEvent));
136
170
  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
171
  };
@@ -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,MA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AAM,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: (_c = (_b = geometry.path) === null || _b === void 0 ? void 0 : _b.map((point) => `${point.x},${point.y}`).join(" ")) !== null && _c !== void 0 ? _c : "",
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 = (_d = geometry.point) !== null && _d !== void 0 ? _d : { x: geometry.bounds.x, y: geometry.bounds.y };
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.9.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.11.0"
24
+ "@affino/diagram-core": "^0.12.0"
25
25
  },
26
26
  "license": "MIT",
27
27
  "devDependencies": {