visio-solid-viewer 1.0.1 → 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
@@ -59,7 +59,7 @@ export function Diagram() {
59
59
  The shared properties are `document` (a parsed `VisioDocument`, or `null` to clear),
60
60
  `pageIndex` (zero-based), `zoom` (`1` means 100%), `showToolbar`, `ribbonAddIns` (tabs the host adds
61
61
  after Help), `canEdit` (editing permission; the viewer is editable unless you pass `false`),
62
- `collaboration` (shares the open drawing in a room while set; `null` leaves it) and `events`.
62
+ `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`.
63
63
  The callback map uses `document-load`, `document-change` (`{ document, dirty, kind }` with kind
64
64
  `edit`, `undo`, `redo`, `remote` or `save`), `document-error`, `page-change`, `zoom-change`,
65
65
  `shape-select`, `selection-change`, `office-ribbon-add-in` and `collaboration-change`. File loading uses the imperative
package/dist/index.js CHANGED
@@ -2,18 +2,52 @@ import * as ui from "ooxml-ui/visio";
2
2
  import { ViewerController, createWorkerParser, mountViewer, propertyKeys } from "ooxml-ui/visio";
3
3
  import { className, createComponent, delegateEvents, effect, insert, setAttribute, style, template, use } from "solid-js/web";
4
4
  import { For, Index, Match, Switch, createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js";
5
+ import { deferredHandle, pickProps } from "ooxml-ui/bindings";
5
6
  import * as officeTheme from "ooxml-ui/theme";
6
7
  export * from "ooxml-ui/visio";
7
8
  export * from "visio-core";
8
9
  //#region packages/bindings/src/common.ts
10
+ /**
11
+ * The Visio binding contract. `mountViewer` (ooxml-ui/visio) forwards properties and events itself,
12
+ * so every property is `manual` here: `mountFrameworkViewer` sends them as revision-aware patches.
13
+ * Events reach native outputs through the `events` callback map (`withEventEmitter`).
14
+ */
15
+ var VIEWER_CONTRACT = {
16
+ props: Object.fromEntries(propertyKeys.map((key) => [key, { forward: "manual" }])),
17
+ events: {},
18
+ handle: {
19
+ element: "get",
20
+ controller: "get",
21
+ load: "async",
22
+ createBlankDrawing: "async",
23
+ applyEdits: "async",
24
+ selectShapes: "call",
25
+ selectAll: "call",
26
+ clearSelection: "call",
27
+ duplicateSelection: "async",
28
+ copySelection: "async",
29
+ cutSelection: "async",
30
+ pasteSelection: "async",
31
+ replacePlainText: "async",
32
+ undo: "async",
33
+ redo: "async",
34
+ cancelEdit: "call",
35
+ exportVsdx: "call",
36
+ fit: "call",
37
+ setLayerVisibility: "call",
38
+ resetLayerVisibility: "call",
39
+ exportSvg: "call",
40
+ createPrintSnapshot: "call"
41
+ }
42
+ };
43
+ /** The error every lazy handle member throws before mount and after unmount. */
44
+ var VIEWER_HANDLE_OPTIONS = { message: "The viewer is not mounted." };
9
45
  /** One mapping for every property and event, shared by every framework adapter. */
10
46
  function viewerOptions(props) {
11
- const result = { events: props.events ?? {} };
12
- for (const key of propertyKeys) {
13
- const value = props[key];
14
- if (value !== void 0) Object.assign(result, { [key]: value });
15
- }
16
- return result;
47
+ return {
48
+ events: props.events ?? {},
49
+ ...pickProps(VIEWER_CONTRACT, props, true)
50
+ };
17
51
  }
18
52
  /**
19
53
  * Native props are snapshots, while the browser binding accepts explicit patches. Forward only
@@ -36,6 +70,7 @@ function mountFrameworkViewer(container, initial) {
36
70
  const touchedByOlderCall = [...activePatches].some((active) => key in active);
37
71
  if (snapshot[key] !== void 0 && (snapshot[key] !== previous[key] || touchedByOlderCall)) Object.assign(patch, { [key]: snapshot[key] });
38
72
  }
73
+ if (snapshot.readOnly === void 0 && previous.readOnly !== void 0) Object.assign(patch, { readOnly: false });
39
74
  activePatches.add(patch);
40
75
  try {
41
76
  binding.update(patch);
@@ -54,79 +89,7 @@ function mountFrameworkViewer(container, initial) {
54
89
  }
55
90
  /** Lazy imperative methods reject both before mount and after unmount. */
56
91
  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
- };
92
+ return deferredHandle(VIEWER_CONTRACT.handle, current, VIEWER_HANDLE_OPTIONS);
130
93
  }
131
94
  function viewerStateSource(current) {
132
95
  const controller = () => {
@@ -2,18 +2,52 @@ import * as ui from "ooxml-ui/visio";
2
2
  import { ViewerController, createWorkerParser, mountViewer, propertyKeys } from "ooxml-ui/visio";
3
3
  import { createComponent, escape, ssr, ssrAttribute, ssrHydrationKey, ssrStyle } from "solid-js/web";
4
4
  import { For, Index, Match, Switch, createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js";
5
+ import { deferredHandle, pickProps } from "ooxml-ui/bindings";
5
6
  import "ooxml-ui/theme";
6
7
  export * from "ooxml-ui/visio";
7
8
  export * from "visio-core";
8
9
  //#region packages/bindings/src/common.ts
10
+ /**
11
+ * The Visio binding contract. `mountViewer` (ooxml-ui/visio) forwards properties and events itself,
12
+ * so every property is `manual` here: `mountFrameworkViewer` sends them as revision-aware patches.
13
+ * Events reach native outputs through the `events` callback map (`withEventEmitter`).
14
+ */
15
+ var VIEWER_CONTRACT = {
16
+ props: Object.fromEntries(propertyKeys.map((key) => [key, { forward: "manual" }])),
17
+ events: {},
18
+ handle: {
19
+ element: "get",
20
+ controller: "get",
21
+ load: "async",
22
+ createBlankDrawing: "async",
23
+ applyEdits: "async",
24
+ selectShapes: "call",
25
+ selectAll: "call",
26
+ clearSelection: "call",
27
+ duplicateSelection: "async",
28
+ copySelection: "async",
29
+ cutSelection: "async",
30
+ pasteSelection: "async",
31
+ replacePlainText: "async",
32
+ undo: "async",
33
+ redo: "async",
34
+ cancelEdit: "call",
35
+ exportVsdx: "call",
36
+ fit: "call",
37
+ setLayerVisibility: "call",
38
+ resetLayerVisibility: "call",
39
+ exportSvg: "call",
40
+ createPrintSnapshot: "call"
41
+ }
42
+ };
43
+ /** The error every lazy handle member throws before mount and after unmount. */
44
+ var VIEWER_HANDLE_OPTIONS = { message: "The viewer is not mounted." };
9
45
  /** One mapping for every property and event, shared by every framework adapter. */
10
46
  function viewerOptions(props) {
11
- const result = { events: props.events ?? {} };
12
- for (const key of propertyKeys) {
13
- const value = props[key];
14
- if (value !== void 0) Object.assign(result, { [key]: value });
15
- }
16
- return result;
47
+ return {
48
+ events: props.events ?? {},
49
+ ...pickProps(VIEWER_CONTRACT, props, true)
50
+ };
17
51
  }
18
52
  /**
19
53
  * Native props are snapshots, while the browser binding accepts explicit patches. Forward only
@@ -36,6 +70,7 @@ function mountFrameworkViewer(container, initial) {
36
70
  const touchedByOlderCall = [...activePatches].some((active) => key in active);
37
71
  if (snapshot[key] !== void 0 && (snapshot[key] !== previous[key] || touchedByOlderCall)) Object.assign(patch, { [key]: snapshot[key] });
38
72
  }
73
+ if (snapshot.readOnly === void 0 && previous.readOnly !== void 0) Object.assign(patch, { readOnly: false });
39
74
  activePatches.add(patch);
40
75
  try {
41
76
  binding.update(patch);
@@ -54,79 +89,7 @@ function mountFrameworkViewer(container, initial) {
54
89
  }
55
90
  /** Lazy imperative methods reject both before mount and after unmount. */
56
91
  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
- };
92
+ return deferredHandle(VIEWER_CONTRACT.handle, current, VIEWER_HANDLE_OPTIONS);
130
93
  }
131
94
  function viewerStateSource(current) {
132
95
  const controller = () => {
@@ -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-solid-viewer",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Local-first Visio viewer for solid",
5
5
  "homepage": "https://christophervr.github.io/ooxml/visio/",
6
6
  "bugs": {
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "emf-converter": "4.21.0",
35
- "ooxml-core": "^1.23.0",
36
- "ooxml-ui": "^1.22.0",
35
+ "ooxml-core": "^1.25.0",
36
+ "ooxml-ui": "^1.26.0",
37
37
  "visio-core": "^1.0.1"
38
38
  },
39
39
  "peerDependencies": {