@affino/diagram-vue 0.11.0 → 0.13.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
@@ -30,6 +30,8 @@ Render static diagram text as SVG `<text>`/`<tspan>` elements in world space. Us
30
30
 
31
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
32
 
33
+ Core group rotation publishes updated member geometry and selection bounds through the existing scene controller. `getSvgEntityProps()` and `DiagramTableView` apply the resulting rotation, so Vue toolbar capability checks based on `engine.canRotate(selection.ids)` and group selection overlays react to the command.
34
+
33
35
  ```vue
34
36
  <script setup lang="ts">
35
37
  import { getSvgEntityProps, useDiagramEngine, useDiagramPointerController, useDiagramTextEditor, useDiagramVisibleEntities } from "@affino/diagram-vue"
@@ -78,7 +80,7 @@ const pointer = useDiagramPointerController(diagram)
78
80
  </template>
79
81
  ```
80
82
 
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.
83
+ 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.
82
84
 
83
85
  ## Viewport resize
84
86
 
@@ -90,11 +92,14 @@ import { useDiagramEngine, useDiagramViewport } from "@affino/diagram-vue"
90
92
 
91
93
  const stage = shallowRef<HTMLElement | null>(null)
92
94
  const diagram = useDiagramEngine(initialScene)
93
- const viewport = useDiagramViewport(diagram, { element: stage })
95
+ const pageConstraints = { bounds: { x: 0, y: 0, width: 794, height: 1123 }, margin: 80 }
96
+ const viewport = useDiagramViewport(diagram, { element: stage, viewportConstraints: pageConstraints })
94
97
 
95
98
  viewport.setViewport({ x: 120, y: 40, zoom: 1.25 })
96
99
  ```
97
100
 
101
+ Pass the same `viewportConstraints` to `useDiagramPointerController()` to constrain pan gesture preview and commit. `useDiagramViewport()` clamps restored state, programmatic `setViewport()` calls, and resize updates only when this option is provided; without it, the existing unbounded behavior is preserved. Bounds and margin use world units, and a visible world area larger than the page plus margin centers the page on that axis.
102
+
98
103
  ## Projection contract
99
104
 
100
105
  `useDiagramVisibleEntities()` exposes:
@@ -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;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
+ {"version":3,"file":"DiagramTableView.d.ts","sourceRoot":"","sources":["../src/DiagramTableView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,KAAK,CAAA;AAG/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;;;;;;;;;;;MAkIzE,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { computed, defineComponent, h, nextTick, ref, watch } from "vue";
2
+ import { rectFromPoints, rotatePoint } from "@affino/diagram-core";
2
3
  import { svgTransform } from "./useDiagramRenderer.js";
3
4
  import { useDiagramTable } from "./useDiagramTable.js";
4
5
  /** SVG-native table renderer with one accessible foreignObject editor and toolbar while selected. */
@@ -59,9 +60,9 @@ export const DiagramTableView = defineComponent({
59
60
  };
60
61
  const cancelEdit = () => { const edit = editing.value; editing.value = null; if (edit)
61
62
  focusCell(edit.row, edit.column); };
62
- const beginEdit = (table, row, column) => {
63
+ const beginEdit = (table, row, column, initialText) => {
63
64
  selectedCell.value = { row, column };
64
- editing.value = { row, column, text: currentCell(table, row, column).text };
65
+ editing.value = { row, column, text: initialText !== null && initialText !== void 0 ? initialText : currentCell(table, row, column).text };
65
66
  };
66
67
  const navigateEdit = (table, rowDelta, columnDelta, expected) => {
67
68
  commitEdit(expected);
@@ -82,7 +83,7 @@ export const DiagramTableView = defineComponent({
82
83
  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 }),
83
84
  ]);
84
85
  return () => {
85
- var _a, _b, _c, _d, _e, _f;
86
+ var _a, _b, _c, _d, _e, _f, _g;
86
87
  const table = projectedTable.value;
87
88
  if (!table)
88
89
  return null;
@@ -111,25 +112,24 @@ export const DiagramTableView = defineComponent({
111
112
  const anchor = cell.horizontalAlign === "center" ? "middle" : cell.horizontalAlign === "right" ? "end" : "start";
112
113
  const textX = anchor === "start" ? x + padding : anchor === "end" ? x + width - padding : x + width / 2;
113
114
  const textY = cell.verticalAlign === "top" ? y + padding : cell.verticalAlign === "bottom" ? y + height - padding : y + height / 2;
114
- 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) }));
115
+ 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) }));
115
116
  if (!isEditing)
116
117
  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));
117
118
  }
118
119
  }
119
120
  if (style.border.visible)
120
121
  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 tableTransform = svgTransform((_g = table.rotation) !== null && _g !== void 0 ? _g : 0, table.flipX === true, table.flipY === true, table);
122
123
  const visualChildren = children.splice(0, children.length);
123
- children.push(h("g", { transform: tableTransform }, visualChildren));
124
+ children.push(h("style", tableCellFocusStyles), h("g", { transform: tableTransform }, visualChildren));
124
125
  const activeEdit = editing.value;
125
126
  if (activeEdit) {
126
127
  const cellX = columnOffsets[activeEdit.column];
127
128
  const cellY = rowOffsets[activeEdit.row];
128
129
  const width = table.columnWidths[activeEdit.column];
129
130
  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;
132
- children.push(h("foreignObject", { x, y, width, height }, [h("input", {
131
+ const editorBounds = projectTableCellBounds(table, { x: cellX, y: cellY, width, height });
132
+ children.push(h("foreignObject", editorBounds, [h("input", {
133
133
  ref: input, value: activeEdit.text, "aria-label": `Edit row ${activeEdit.row + 1}, column ${activeEdit.column + 1}`,
134
134
  onPointerdown: stopToolbarEvent, onClick: stopToolbarEvent,
135
135
  onInput: (event) => { if (editing.value)
@@ -209,14 +209,43 @@ function onCellKey(event, table, row, column, beginEdit, selectedCell) {
209
209
  if (event.key === "Enter" || event.key === "F2") {
210
210
  event.preventDefault();
211
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);
212
218
  }
213
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
+ }
214
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: "" }; }
229
+ function projectTableCellBounds(table, cell) {
230
+ const center = { x: table.x + table.width / 2, y: table.y + table.height / 2 };
231
+ const project = (point) => {
232
+ var _a;
233
+ const local = { x: center.x + (point.x - center.x) * (table.flipX ? -1 : 1), y: center.y + (point.y - center.y) * (table.flipY ? -1 : 1) };
234
+ return rotatePoint(local, center, (_a = table.rotation) !== null && _a !== void 0 ? _a : 0);
235
+ };
236
+ return rectFromPoints([
237
+ project({ x: cell.x, y: cell.y }),
238
+ project({ x: cell.x + cell.width, y: cell.y }),
239
+ project({ x: cell.x + cell.width, y: cell.y + cell.height }),
240
+ project({ x: cell.x, y: cell.y + cell.height }),
241
+ ]);
242
+ }
215
243
  function offsets(sizes, start) { const result = [start]; for (const size of sizes)
216
244
  result.push(result[result.length - 1] + size); return result; }
217
245
  function dash(style) { return style === "dashed" ? "6 4" : style === "dotted" ? "1 3" : undefined; }
218
246
  function colorInputValue(color) { return /^#[0-9a-f]{6}$/i.test(color) ? color : "#64748b"; }
219
247
  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 };
248
+ 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}`;
220
249
  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" };
221
250
  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" };
222
251
  const fieldStyle = { display: "inline-flex", alignItems: "center", gap: "3px", fontSize: "11px", whiteSpace: "nowrap" };
@@ -1,5 +1,5 @@
1
1
  import type { ShallowRef } from "vue";
2
- import { type DiagramInteractionController, type DiagramInteractionSnapOptions, type DiagramInteractionSnapshot, type DiagramInteractionTool, type DiagramPoint } from "@affino/diagram-core";
2
+ import { type DiagramInteractionController, type DiagramInteractionSnapOptions, type DiagramInteractionSnapshot, type DiagramInteractionTool, type DiagramPoint, type DiagramViewportConstraints } from "@affino/diagram-core";
3
3
  import type { DiagramEngineController } from "./useDiagramEngine.js";
4
4
  export type DiagramPointerController = Readonly<{
5
5
  interaction: DiagramInteractionController;
@@ -18,6 +18,7 @@ export type DiagramPointerControllerOptions = Readonly<{
18
18
  setPointerCapture?: (event: PointerEvent) => void;
19
19
  releasePointerCapture?: (event: PointerEvent) => void;
20
20
  snap?: DiagramInteractionSnapOptions;
21
+ viewportConstraints?: DiagramViewportConstraints;
21
22
  }>;
22
23
  export declare function useDiagramPointerController(controller: DiagramEngineController, options?: DiagramPointerControllerOptions): DiagramPointerController;
23
24
  //# sourceMappingURL=useDiagramPointerController.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDiagramPointerController.d.ts","sourceRoot":"","sources":["../src/useDiagramPointerController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,EAAsC,KAAK,4BAA4B,EAAE,KAAK,6BAA6B,EAAE,KAAK,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACjO,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,WAAW,EAAE,4BAA4B,CAAA;IACzC,KAAK,EAAE,UAAU,CAAC,0BAA0B,CAAC,CAAA;IAC7C,OAAO,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAA;IAC/C,kBAAkB,EAAE,MAAM;QACxB,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC5C,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC5C,WAAW,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;QAC1C,eAAe,EAAE,MAAM,IAAI,CAAA;KAC5B,CAAA;IACD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC;IACrD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,YAAY,CAAA;IACpD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACjD,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CA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E,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACrD,IAAI,CAAC,EAAE,6BAA6B,CAAA;IACpC,mBAAmB,CAAC,EAAE,0BAA0B,CAAA;CACjD,CAAC,CAAA;AAEF,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,+BAAoC,GAAG,wBAAwB,CAsExJ"}
@@ -4,6 +4,7 @@ export function useDiagramPointerController(controller, options = {}) {
4
4
  let refresh = () => { };
5
5
  const interaction = createDiagramInteractionController(controller.engine, {
6
6
  snap: options.snap,
7
+ viewportConstraints: options.viewportConstraints,
7
8
  scheduleFrame: (callback) => {
8
9
  const schedule = typeof globalThis.requestAnimationFrame === "function"
9
10
  ? globalThis.requestAnimationFrame.bind(globalThis)
@@ -1,6 +1,6 @@
1
1
  import type { Ref, ShallowRef } from "vue";
2
2
  import type { DiagramEngineController } from "./useDiagramEngine.js";
3
- import type { DiagramViewport } from "@affino/diagram-core";
3
+ import type { DiagramViewport, DiagramViewportConstraints } from "@affino/diagram-core";
4
4
  export type DiagramViewportController = Readonly<{
5
5
  viewport: ShallowRef<DiagramViewport>;
6
6
  setViewport: (viewport: Partial<DiagramViewport>) => void;
@@ -20,6 +20,7 @@ type ResizeObserverCtor = new (callback: (entries: ReadonlyArray<{
20
20
  export type DiagramViewportOptions = Readonly<{
21
21
  element?: Ref<Element | null> | Element | null;
22
22
  resizeObserver?: ResizeObserverCtor;
23
+ viewportConstraints?: DiagramViewportConstraints;
23
24
  }>;
24
25
  export declare function useDiagramViewport(controller: DiagramEngineController, options?: DiagramViewportOptions): DiagramViewportController;
25
26
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"useDiagramViewport.d.ts","sourceRoot":"","sources":["../src/useDiagramViewport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,C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AK,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AAEvF,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,QAAQ,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IACzD,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IACxD,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAC,CAAA;AAEF,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACnC,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB,CAAA;AAED,KAAK,kBAAkB,GAAG,KAAK,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC;IAAE,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,KAAK,IAAI,KAAK,kBAAkB,CAAA;AAEpJ,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAA;IAC9C,cAAc,CAAC,EAAE,kBAAkB,CAAA;IACnC,mBAAmB,CAAC,EAAE,0BAA0B,CAAA;CACjD,CAAC,CAAA;AAEF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,uBAAuB,EAAE,OAAO,GAAE,sBAA2B,GAAG,yBAAyB,CA0EvI"}
@@ -1,4 +1,5 @@
1
1
  import { getCurrentScope, isRef, onScopeDispose, shallowRef, watch } from "vue";
2
+ import { clampViewportToBounds } from "@affino/diagram-core";
2
3
  export function useDiagramViewport(controller, options = {}) {
3
4
  const viewport = shallowRef(controller.scene.value.viewport);
4
5
  let observer = null;
@@ -12,6 +13,11 @@ export function useDiagramViewport(controller, options = {}) {
12
13
  if (disposed) {
13
14
  return;
14
15
  }
16
+ if (options.viewportConstraints) {
17
+ const constrained = clampViewportToBounds({ ...controller.scene.value.viewport, ...next }, options.viewportConstraints);
18
+ controller.dispatch({ type: "setViewport", viewport: constrained });
19
+ return;
20
+ }
15
21
  controller.dispatch({ type: "setViewport", viewport: next });
16
22
  };
17
23
  const attachViewportElement = (element) => {
@@ -62,6 +68,8 @@ export function useDiagramViewport(controller, options = {}) {
62
68
  attachViewportElement(initialElement);
63
69
  }
64
70
  }
71
+ if (options.viewportConstraints)
72
+ setViewport(controller.scene.value.viewport);
65
73
  return { viewport, setViewport, attachViewportElement, dispose };
66
74
  }
67
75
  function unwrapElement(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affino/diagram-vue",
3
- "version": "0.11.0",
3
+ "version": "0.13.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.12.0"
24
+ "@affino/diagram-core": "^0.14.0"
25
25
  },
26
26
  "license": "MIT",
27
27
  "devDependencies": {