visio-angular-viewer 1.1.0 → 1.1.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
@@ -53,7 +53,7 @@ export class DiagramComponent {
53
53
  The shared properties are `document` (a parsed `VisioDocument`, or `null` to clear),
54
54
  `pageIndex` (zero-based), `zoom` (`1` means 100%), `showToolbar`, `ribbonAddIns` (tabs the host adds
55
55
  after Help), `canEdit` (editing permission; the viewer is editable unless you pass `false`),
56
- `collaboration` (shares the open drawing in a room while set; `null` leaves it) and `events`.
56
+ `readOnly` (a restriction of its own), `storage` and `customization` (host-owned save and open), `collaboration` (shares the open drawing in a room while set; `null` leaves it) and `events`.
57
57
  The callback map uses `document-load`, `document-change` (`{ document, dirty, kind }` with kind
58
58
  `edit`, `undo`, `redo`, `remote` or `save`), `document-error`, `page-change`, `zoom-change`,
59
59
  `shape-select`, `selection-change`, `office-ribbon-add-in` and `collaboration-change`. File loading uses the imperative
package/dist/index.js CHANGED
@@ -1,18 +1,52 @@
1
1
  import * as ui from "ooxml-ui/visio";
2
2
  import { ViewerController, createWorkerParser, eventKeys, mountViewer, propertyKeys } from "ooxml-ui/visio";
3
3
  import { Component, DestroyRef, ElementRef, EventEmitter, Injectable, Input, Output, computed, effect, inject, signal, untracked } from "@angular/core";
4
+ import { deferredHandle, installHandle, pickProps } from "ooxml-ui/bindings";
4
5
  import * as officeTheme from "ooxml-ui/theme";
5
6
  export * from "ooxml-ui/visio";
6
7
  export * from "visio-core";
7
8
  //#region packages/bindings/src/common.ts
9
+ /**
10
+ * The Visio binding contract. `mountViewer` (ooxml-ui/visio) forwards properties and events itself,
11
+ * so every property is `manual` here: `mountFrameworkViewer` sends them as revision-aware patches.
12
+ * Events reach native outputs through the `events` callback map (`withEventEmitter`).
13
+ */
14
+ var VIEWER_CONTRACT = {
15
+ props: Object.fromEntries(propertyKeys.map((key) => [key, { forward: "manual" }])),
16
+ events: {},
17
+ handle: {
18
+ element: "get",
19
+ controller: "get",
20
+ load: "async",
21
+ createBlankDrawing: "async",
22
+ applyEdits: "async",
23
+ selectShapes: "call",
24
+ selectAll: "call",
25
+ clearSelection: "call",
26
+ duplicateSelection: "async",
27
+ copySelection: "async",
28
+ cutSelection: "async",
29
+ pasteSelection: "async",
30
+ replacePlainText: "async",
31
+ undo: "async",
32
+ redo: "async",
33
+ cancelEdit: "call",
34
+ exportVsdx: "call",
35
+ fit: "call",
36
+ setLayerVisibility: "call",
37
+ resetLayerVisibility: "call",
38
+ exportSvg: "call",
39
+ createPrintSnapshot: "call"
40
+ }
41
+ };
42
+ /** The error every lazy handle member throws before mount and after unmount. */
43
+ var VIEWER_HANDLE_OPTIONS = { message: "The viewer is not mounted." };
8
44
  /** One mapping for every property and event, shared by every framework adapter. */
9
45
  function viewerOptions(props) {
10
- const result = { events: props.events ?? {} };
11
- for (const key of propertyKeys) {
12
- const value = props[key];
13
- if (value !== void 0) Object.assign(result, { [key]: value });
14
- }
15
- return result;
46
+ return {
47
+ events: props.events ?? {},
48
+ ...pickProps(VIEWER_CONTRACT, props, true)
49
+ };
16
50
  }
17
51
  /**
18
52
  * Native props are snapshots, while the browser binding accepts explicit patches. Forward only
@@ -54,79 +88,7 @@ function mountFrameworkViewer(container, initial) {
54
88
  }
55
89
  /** Lazy imperative methods reject both before mount and after unmount. */
56
90
  function viewerHandle(current) {
57
- const requireViewer = () => {
58
- const binding = current();
59
- if (!binding) throw new Error("The viewer is not mounted.");
60
- return binding;
61
- };
62
- return {
63
- get element() {
64
- return requireViewer().element;
65
- },
66
- get controller() {
67
- return requireViewer().controller;
68
- },
69
- async load(source) {
70
- await requireViewer().load(source);
71
- },
72
- async createBlankDrawing(options) {
73
- await requireViewer().createBlankDrawing(options);
74
- },
75
- async applyEdits(edits) {
76
- await requireViewer().applyEdits(edits);
77
- },
78
- selectShapes(shapes) {
79
- requireViewer().selectShapes(shapes);
80
- },
81
- selectAll() {
82
- requireViewer().selectAll();
83
- },
84
- clearSelection() {
85
- requireViewer().clearSelection();
86
- },
87
- async replacePlainText(pageId, shapeId, text) {
88
- await requireViewer().replacePlainText(pageId, shapeId, text);
89
- },
90
- async duplicateSelection() {
91
- await requireViewer().duplicateSelection();
92
- },
93
- async copySelection() {
94
- await requireViewer().copySelection();
95
- },
96
- async cutSelection() {
97
- await requireViewer().cutSelection();
98
- },
99
- async pasteSelection() {
100
- await requireViewer().pasteSelection();
101
- },
102
- async undo() {
103
- await requireViewer().undo();
104
- },
105
- async redo() {
106
- await requireViewer().redo();
107
- },
108
- cancelEdit() {
109
- requireViewer().cancelEdit();
110
- },
111
- exportVsdx() {
112
- return requireViewer().exportVsdx();
113
- },
114
- fit() {
115
- requireViewer().fit();
116
- },
117
- setLayerVisibility(pageId, layerId, visible) {
118
- requireViewer().setLayerVisibility(pageId, layerId, visible);
119
- },
120
- resetLayerVisibility(pageId) {
121
- requireViewer().resetLayerVisibility(pageId);
122
- },
123
- exportSvg(options) {
124
- return requireViewer().exportSvg(options);
125
- },
126
- createPrintSnapshot(options) {
127
- return requireViewer().createPrintSnapshot(options);
128
- }
129
- };
91
+ return deferredHandle(VIEWER_CONTRACT.handle, current, VIEWER_HANDLE_OPTIONS);
130
92
  }
131
93
  function viewerStateSource(current) {
132
94
  const controller = () => {
@@ -201,6 +163,9 @@ var VisioViewerComponent = class VisioViewerComponent {
201
163
  "file-command": this.fileCommand
202
164
  };
203
165
  }
166
+ static {
167
+ installHandle(this.prototype, VIEWER_CONTRACT.handle, (self) => self.binding, VIEWER_HANDLE_OPTIONS);
168
+ }
204
169
  options() {
205
170
  return withEventEmitter(this, (name, value) => {
206
171
  this.outputs[name].emit(value);
@@ -223,72 +188,6 @@ var VisioViewerComponent = class VisioViewerComponent {
223
188
  this.binding = void 0;
224
189
  mounted?.destroy();
225
190
  }
226
- get element() {
227
- return this.handle.element;
228
- }
229
- get controller() {
230
- return this.handle.controller;
231
- }
232
- load(source) {
233
- return this.handle.load(source);
234
- }
235
- createBlankDrawing(options) {
236
- return this.handle.createBlankDrawing(options);
237
- }
238
- applyEdits(edits) {
239
- return this.handle.applyEdits(edits);
240
- }
241
- selectShapes(shapes) {
242
- this.handle.selectShapes(shapes);
243
- }
244
- selectAll() {
245
- this.handle.selectAll();
246
- }
247
- clearSelection() {
248
- this.handle.clearSelection();
249
- }
250
- duplicateSelection() {
251
- return this.handle.duplicateSelection();
252
- }
253
- copySelection() {
254
- return this.handle.copySelection();
255
- }
256
- cutSelection() {
257
- return this.handle.cutSelection();
258
- }
259
- pasteSelection() {
260
- return this.handle.pasteSelection();
261
- }
262
- replacePlainText(pageId, shapeId, text) {
263
- return this.handle.replacePlainText(pageId, shapeId, text);
264
- }
265
- undo() {
266
- return this.handle.undo();
267
- }
268
- redo() {
269
- return this.handle.redo();
270
- }
271
- cancelEdit() {
272
- this.handle.cancelEdit();
273
- }
274
- exportVsdx() {
275
- return this.handle.exportVsdx();
276
- }
277
- fit() {
278
- this.handle.fit();
279
- }
280
- setLayerVisibility(pageId, layerId, visible) {
281
- this.handle.setLayerVisibility(pageId, layerId, visible);
282
- }
283
- resetLayerVisibility(pageId) {
284
- this.handle.resetLayerVisibility(pageId);
285
- }
286
- exportSvg(options) {
287
- return this.handle.exportSvg(options);
288
- }
289
- createPrintSnapshot(options) {
290
- return this.handle.createPrintSnapshot(options);
291
- }
292
191
  };
293
192
  __decorate([Input()], VisioViewerComponent.prototype, "document", void 0);
294
193
  __decorate([Input()], VisioViewerComponent.prototype, "pageIndex", void 0);
@@ -1,5 +1,8 @@
1
1
  import { EventEmitter, type AfterViewInit, type OnChanges, type OnDestroy } from '@angular/core';
2
- import { type ViewerCallbacks, type ViewerProperties, type ViewerState, type VsdxSource, type VisioEdit, type CreateVsdxOptions, type VisioShapeSelection, type SvgExportOptions, type CurrentPagePrintSnapshotOptions } from './common.js';
2
+ import { type ViewerCallbacks, type ViewerHandle, type ViewerProperties, type ViewerState } from './common.js';
3
+ /** The handle members, defined on the prototype from `VIEWER_CONTRACT.handle`. */
4
+ export interface VisioViewerComponent extends ViewerHandle {
5
+ }
3
6
  /** Angular input/output and lifecycle wiring over the one shared browser binding. */
4
7
  export declare class VisioViewerComponent implements AfterViewInit, OnChanges, OnDestroy {
5
8
  document?: ViewerProperties['document'];
@@ -22,8 +25,8 @@ export declare class VisioViewerComponent implements AfterViewInit, OnChanges, O
22
25
  documentError: EventEmitter<Error>;
23
26
  pageChange: EventEmitter<number>;
24
27
  zoomChange: EventEmitter<number>;
25
- shapeSelect: EventEmitter<VisioShapeSelection | null>;
26
- selectionChange: EventEmitter<readonly VisioShapeSelection[]>;
28
+ shapeSelect: EventEmitter<import("ooxml-ui/visio").VisioShapeSelection | null>;
29
+ selectionChange: EventEmitter<readonly import("ooxml-ui/visio").VisioShapeSelection[]>;
27
30
  ribbonAddIn: EventEmitter<import("ooxml-core/ribbon").RibbonAddInCommandDetail>;
28
31
  collaborationChange: EventEmitter<import("ooxml-core/collab").CollaborationState>;
29
32
  /** Notification only: to cancel a File command, return false from `events['file-command']`. */
@@ -40,27 +43,5 @@ export declare class VisioViewerComponent implements AfterViewInit, OnChanges, O
40
43
  ngAfterViewInit(): void;
41
44
  ngOnChanges(): void;
42
45
  ngOnDestroy(): void;
43
- get element(): import("ooxml-ui/visio").VisioViewerElement;
44
- get controller(): import("ooxml-ui/visio").ViewerController;
45
- load(source: VsdxSource): Promise<void>;
46
- createBlankDrawing(options?: CreateVsdxOptions): Promise<void>;
47
- applyEdits(edits: readonly VisioEdit[]): Promise<void>;
48
- selectShapes(shapes: readonly VisioShapeSelection[]): void;
49
- selectAll(): void;
50
- clearSelection(): void;
51
- duplicateSelection(): Promise<void>;
52
- copySelection(): Promise<void>;
53
- cutSelection(): Promise<void>;
54
- pasteSelection(): Promise<void>;
55
- replacePlainText(pageId: string, shapeId: string, text: string): Promise<void>;
56
- undo(): Promise<void>;
57
- redo(): Promise<void>;
58
- cancelEdit(): void;
59
- exportVsdx(): import("ooxml-ui/visio").VsdxExportResult;
60
- fit(): void;
61
- setLayerVisibility(pageId: string, layerId: string, visible: boolean | null): void;
62
- resetLayerVisibility(pageId?: string): void;
63
- exportSvg(options?: SvgExportOptions): import("ooxml-ui/visio").SvgExportResult;
64
- createPrintSnapshot(options?: CurrentPagePrintSnapshotOptions): import("ooxml-ui/visio").PrintSnapshot;
65
46
  }
66
47
  export type { ViewerState, ViewerHandle, ViewerCallbacks, ViewerOptions, ViewerEvents, VisioShapeSelection, CreateVsdxOptions, ViewerEditState, VsdxExportResult, RibbonAddInCommand, RibbonAddInGroup, RibbonAddInTab, } from './common.js';
@@ -1,5 +1,6 @@
1
1
  import { mountViewer, type MountedViewer } from 'ooxml-ui/visio';
2
2
  import type { ViewerState } from 'ooxml-ui/visio';
3
+ import { type BindingContract } from 'ooxml-ui/bindings';
3
4
  import { eventKeys, propertyKeys, type ViewerCallbacks, type ViewerOptions, type ViewerProperties } from 'ooxml-ui/visio';
4
5
  /** Framework props permit undefined; omitted values preserve the shared binding's state. */
5
6
  export type ViewerProps = {
@@ -8,6 +9,16 @@ export type ViewerProps = {
8
9
  events?: ViewerCallbacks | undefined;
9
10
  };
10
11
  export type ViewerHandle = Pick<MountedViewer, 'element' | 'controller' | 'load' | 'createBlankDrawing' | 'applyEdits' | 'selectShapes' | 'selectAll' | 'clearSelection' | 'duplicateSelection' | 'copySelection' | 'cutSelection' | 'pasteSelection' | 'replacePlainText' | 'undo' | 'redo' | 'cancelEdit' | 'exportVsdx' | 'fit' | 'setLayerVisibility' | 'resetLayerVisibility' | 'exportSvg' | 'createPrintSnapshot'>;
12
+ /**
13
+ * The Visio binding contract. `mountViewer` (ooxml-ui/visio) forwards properties and events itself,
14
+ * so every property is `manual` here: `mountFrameworkViewer` sends them as revision-aware patches.
15
+ * Events reach native outputs through the `events` callback map (`withEventEmitter`).
16
+ */
17
+ export declare const VIEWER_CONTRACT: BindingContract<never, ViewerProperties, ViewerHandle>;
18
+ /** The error every lazy handle member throws before mount and after unmount. */
19
+ export declare const VIEWER_HANDLE_OPTIONS: {
20
+ readonly message: "The viewer is not mounted.";
21
+ };
11
22
  /** One mapping for every property and event, shared by every framework adapter. */
12
23
  export declare function viewerOptions(props: ViewerProps): ViewerOptions;
13
24
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visio-angular-viewer",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Local-first Visio viewer for angular",
5
5
  "homepage": "https://christophervr.github.io/ooxml/visio/",
6
6
  "bugs": {
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "emf-converter": "4.21.0",
34
- "ooxml-core": "^1.24.0",
35
- "ooxml-ui": "^1.23.0",
34
+ "ooxml-core": "^1.25.0",
35
+ "ooxml-ui": "^1.26.0",
36
36
  "visio-core": "^1.0.1"
37
37
  },
38
38
  "devDependencies": {