xlsx-svelte-viewer 1.1.0 → 1.2.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.
@@ -1,17 +1,21 @@
1
1
  <script lang="ts">
2
- import { deferredHandle, eventOptions, mountEditor, pickEditorProps, type EditorBinding, type EditorEventHandlers, type EditorProps, type EditorHandle } from './runtime.js';
2
+ import { deferredHandle, mountEditor, svelteEditorOptions, type EditorBinding, type EditorEventHandlers, type EditorOptions, type EditorProps, type EditorHandle } from './runtime.js';
3
3
  type Props = EditorProps & {
4
4
  onworkbookchange?: EditorEventHandlers['workbook-change'];
5
5
  onworkbookerror?: EditorEventHandlers['workbook-error'];
6
6
  onselectionchange?: EditorEventHandlers['selection-change'];
7
7
  ondirtychange?: EditorEventHandlers['dirty-change'];
8
8
  onreadonlychange?: EditorEventHandlers['readonly-change'];
9
+ onfilecommand?: EditorEventHandlers['file-command'];
10
+ onworkbookwarning?: EditorEventHandlers['workbook-warning'];
11
+ onribbonaction?: EditorEventHandlers['ribbon-action'];
9
12
  onribboncustomize?: EditorEventHandlers['ribbon-customize'];
13
+ onsheetchange?: EditorEventHandlers['sheet-change'];
10
14
  onribbonaddin?: EditorEventHandlers['office-ribbon-add-in'];
11
15
  oncollaborationchange?: EditorEventHandlers['collaboration-change'];
12
16
  onready?: EditorEventHandlers['ready'];
13
17
  };
14
- let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], ribbonAddIns, themeColors, collaboration, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onribbonaddin, oncollaborationchange, onready }: Props = $props();
18
+ let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], ribbonAddIns, themeColors, collaboration, customization, storage, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready }: Props = $props();
15
19
  let binding: EditorBinding | undefined;
16
20
  const handle = deferredHandle(() => binding);
17
21
  // Live `element` and `dirty`, the same handle vocabulary as the other frameworks (`EDITOR_HANDLE_KEYS`).
@@ -20,9 +24,8 @@
20
24
  const element = $derived(mountedElement);
21
25
  const dirty = $derived(dirtyState);
22
26
  function attach(host: HTMLElement, options: Props) {
23
- const normalized = (value: Props) => ({ ...pickEditorProps(value),
24
- ...eventOptions({ 'workbook-change': value.onworkbookchange, 'workbook-error': value.onworkbookerror, 'selection-change': value.onselectionchange, 'dirty-change': value.ondirtychange, 'readonly-change': value.onreadonlychange, 'ribbon-customize': value.onribboncustomize, 'office-ribbon-add-in': value.onribbonaddin, 'collaboration-change': value.oncollaborationchange, ready: value.onready }) });
25
- const tracked = (value: Props) => normalized({ ...value, ondirtychange: (next: boolean) => { dirtyState = next; value.ondirtychange?.(next); } });
27
+ // Callback props are the lower-case options (`onworkbookchange`); `dirty` is tracked on the way.
28
+ const tracked = (value: Props): EditorOptions => ({ ...svelteEditorOptions(value), onDirtyChange: (next: boolean) => { dirtyState = next; value.ondirtychange?.(next); } });
26
29
  binding = mountEditor(host, tracked(options));
27
30
  mountedElement = binding.element;
28
31
  dirtyState = binding.dirty;
@@ -44,4 +47,4 @@
44
47
  export function getElement() { return binding?.element; }
45
48
  export { element, dirty };
46
49
  </script>
47
- <div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, ribbonAddIns, themeColors, collaboration, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onribbonaddin, oncollaborationchange, onready }}></div>
50
+ <div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, ribbonAddIns, themeColors, collaboration, customization, storage, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready }}></div>
package/dist/runtime.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import * as ooxml_core_xlsx from 'ooxml-core/xlsx';
2
2
  import * as ooxml_core_xlsx_ui from 'ooxml-core/xlsx/ui';
3
3
  import * as ooxml_core_collab from 'ooxml-core/collab';
4
- import { EditorLocaleInput, EditorThemeMode, RibbonAddInTab, XlsxThemeColors, XlsxCollaborationOptions, SelectionChangeDetail, RibbonAddInCommandDetail, XlsxCollaborationState, XlsxEditorElement, SurfaceHostActions, ValidationErrorDetail, SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
4
+ import { EditorLocaleInput, EditorThemeMode, RibbonAddInTab, XlsxThemeColors, XlsxCollaborationOptions, ExcelCustomization, SelectionChangeDetail, FileCommandDetail, RibbonAddInCommandDetail, XlsxCollaborationState, XlsxEditorElement, SurfaceHostActions, ValidationErrorDetail, SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
5
5
  export * from 'ooxml-ui/xlsx';
6
6
  export { SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
7
7
  import { Workbook } from '@christophervr/xlsx-core';
8
8
  export * from '@christophervr/xlsx-core';
9
+ import { DocumentStorage } from 'ooxml-core/embedding';
10
+ import { BindingContract } from 'ooxml-ui/bindings';
9
11
  export { LegacyXlsError, WorkbookFormat, csvToWorkbook, detectWorkbookFormat, loadLegacyXls, loadWorkbook, parseCsv, saveWorkbook, sheetToCsv } from '@christophervr/xlsx-core/load';
10
12
  import * as svelte_store from 'svelte/store';
11
13
 
@@ -41,6 +43,17 @@ interface EditorProps {
41
43
  * colour); forwarded when a new object is passed, and `undefined` or `null` leaves the room.
42
44
  */
43
45
  collaboration?: XlsxCollaborationOptions | null | undefined;
46
+ /**
47
+ * Host-owned storage: File > Save and Save As go to `storage.save()` instead of a download, and
48
+ * File > Open to `storage.open()` when it has one. `file-command` still fires first.
49
+ */
50
+ storage?: DocumentStorage | null | undefined;
51
+ /**
52
+ * Host customisation (`ExcelCustomization`): `capabilities`, `backstage.extraPages` and
53
+ * `contextMenu.extraCommands`. Forwarded when the object changes, so keep it stable (memoise
54
+ * it); `null` or omitted restores the defaults.
55
+ */
56
+ customization?: ExcelCustomization | null | undefined;
44
57
  }
45
58
  /** Editor callbacks; each is the framework-neutral form of one entry in `EDITOR_EVENT_NAMES`. */
46
59
  interface EditorEventOptions {
@@ -48,10 +61,35 @@ interface EditorEventOptions {
48
61
  onWorkbookError?: ((error: Error) => void) | undefined;
49
62
  onSelectionChange?: ((detail: SelectionChangeDetail) => void) | undefined;
50
63
  onDirtyChange?: ((dirty: boolean) => void) | undefined;
51
- /** The user toggled Editing / Viewing (or `readOnly` changed); lets a controlled parent sync. */
52
- onReadOnlyChange?: ((readOnly: boolean) => void) | undefined;
64
+ /**
65
+ * The user toggled Editing / Viewing, `readOnly` changed or a collaboration role changed.
66
+ * `readOnly` is the effective value. A controlled parent that mirrors the switch must store
67
+ * `detail.hostReadOnly`, never `readOnly`, or a `viewer` role lock would be written into the
68
+ * host's setting.
69
+ */
70
+ onReadOnlyChange?: ((readOnly: boolean, detail: {
71
+ readOnly: boolean;
72
+ locked: boolean;
73
+ hostReadOnly: boolean;
74
+ }) => void) | undefined;
75
+ /**
76
+ * A File command (new, open, save, saveAs, export, exportCsv, print) is about to run. The event is
77
+ * cancelable: call `event.preventDefault()` to take the command over yourself.
78
+ */
79
+ onFileCommand?: ((event: CustomEvent<FileCommandDetail>) => void) | undefined;
80
+ /** Non-fatal notes from the loader (unsupported features, compatibility). */
81
+ onWorkbookWarning?: ((warnings: string[]) => void) | undefined;
82
+ /** A command ran from the ribbon, a menu, Tell me or a shortcut. */
83
+ onRibbonAction?: ((detail: {
84
+ id: string;
85
+ }) => void) | undefined;
53
86
  /** The user changed the shown ribbon commands (File > Options > Customize Ribbon). */
54
87
  onRibbonCustomize?: ((hiddenActions: string[]) => void) | undefined;
88
+ /** The active sheet changed. */
89
+ onSheetChange?: ((detail: {
90
+ index: number;
91
+ name: string;
92
+ }) => void) | undefined;
55
93
  /** A command of a host tab (`ribbonAddIns`) was chosen. */
56
94
  onRibbonAddIn?: ((detail: RibbonAddInCommandDetail) => void) | undefined;
57
95
  /** Sharing started or stopped, the connection changed, or someone joined or left. */
@@ -62,10 +100,10 @@ interface EditorEventOptions {
62
100
  interface EditorOptions extends EditorProps, EditorEventOptions {
63
101
  }
64
102
  /** Single source of truth for the prop keys every adapter forwards. */
65
- declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "ribbonAddIns", "themeColors", "collaboration"];
103
+ declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "ribbonAddIns", "themeColors", "collaboration", "storage", "customization"];
66
104
  type EditorPropKey = (typeof EDITOR_PROP_KEYS)[number];
67
105
  /** Single source of truth for the element events every adapter surfaces. */
68
- declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "ribbon-customize", "office-ribbon-add-in", "collaboration-change"];
106
+ declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "file-command", "workbook-warning", "ribbon-action", "ribbon-customize", "sheet-change", "office-ribbon-add-in", "collaboration-change"];
69
107
  type EditorEventName = (typeof EDITOR_EVENT_NAMES)[number];
70
108
  /** One handler per bound event (unwrapped payload); a missing key is a compile error in every adapter. */
71
109
  interface EditorEventHandlers {
@@ -74,15 +112,15 @@ interface EditorEventHandlers {
74
112
  'selection-change': EditorEventOptions['onSelectionChange'];
75
113
  'dirty-change': EditorEventOptions['onDirtyChange'];
76
114
  'readonly-change': EditorEventOptions['onReadOnlyChange'];
115
+ 'file-command': EditorEventOptions['onFileCommand'];
116
+ 'workbook-warning': EditorEventOptions['onWorkbookWarning'];
117
+ 'ribbon-action': EditorEventOptions['onRibbonAction'];
77
118
  'ribbon-customize': EditorEventOptions['onRibbonCustomize'];
119
+ 'sheet-change': EditorEventOptions['onSheetChange'];
78
120
  'office-ribbon-add-in': EditorEventOptions['onRibbonAddIn'];
79
121
  'collaboration-change': EditorEventOptions['onCollaborationChange'];
80
122
  ready?: EditorEventOptions['onReady'];
81
123
  }
82
- /** Copies exactly the shared props out of a framework's props/instance object. */
83
- declare function pickEditorProps(source: EditorProps): EditorProps;
84
- /** Maps per-event handlers (keyed by DOM event name) onto the shared option callbacks. */
85
- declare function eventOptions(handlers: EditorEventHandlers): EditorEventOptions;
86
124
  interface EditorHandle {
87
125
  readonly element: XlsxEditorElement;
88
126
  load(input: Uint8Array | ArrayBuffer, fileName?: string): Promise<void>;
@@ -104,19 +142,35 @@ interface EditorBinding extends EditorHandle {
104
142
  update(options: EditorOptions): void;
105
143
  destroy(): void;
106
144
  }
145
+ /**
146
+ * Props in forwarding order; each is written only when the prop itself changed since it was last
147
+ * written, so a re-render never undoes what the user changed inside the editor. `fileName` and
148
+ * collaboration precede the workbook, bytes and `src` (forwarded by `mountEditor`), so a workbook
149
+ * opened in the same update is named and joins the room.
150
+ */
151
+ declare const EDITOR_CONTRACT: BindingContract<XlsxEditorElement, EditorProps, EditorHandle, EditorEventName, keyof EditorEventOptions>;
152
+ /** `onReady` is a callback of the binding, not an element event. */
153
+ declare const EDITOR_CALLBACKS: readonly ["onReady"];
154
+ /** Copies exactly the shared props out of a framework's props/instance object. */
155
+ declare function pickEditorProps(source: EditorProps): EditorProps;
156
+ /** Maps per-event handlers (keyed by DOM event name) onto the shared option callbacks. */
157
+ declare function eventOptions(handlers: EditorEventHandlers): EditorEventOptions;
158
+ /** Options from Svelte's props, whose callbacks are the lower-case options (`onworkbookchange`). */
159
+ declare function svelteEditorOptions(props: object): EditorOptions;
107
160
  /**
108
161
  * A handle for adapters that hold a binding which may not be mounted yet: every call reads the
109
162
  * current binding and throws a clear error before mount.
110
163
  */
111
164
  declare function deferredHandle(current: () => EditorBinding | null | undefined): EditorHandle;
112
- /** All framework adapters share property, event and lifecycle semantics here. */
113
- declare function mountEditor(host: HTMLElement, initial?: EditorOptions, surfaceOnly?: boolean): EditorBinding;
114
165
  /**
115
166
  * The imperative handle every framework exposes (React ref, Vue template ref, Angular component
116
- * instance, Solid `editorRef`, Svelte component instance). `handle-keys.test.ts` checks each one.
167
+ * instance, Solid `editorRef`, Svelte component instance). `contract-parity.test.ts` checks each.
117
168
  */
118
169
  declare const EDITOR_HANDLE_KEYS: readonly ["element", "load", "newWorkbook", "save", "saveBytes", "download", "markClean", "select", "getSelection", "setActiveSheet", "share", "dirty"];
119
170
  type EditorHandleKey = (typeof EDITOR_HANDLE_KEYS)[number];
171
+
172
+ /** All framework adapters share property, event and lifecycle semantics here. */
173
+ declare function mountEditor(host: HTMLElement, initial?: EditorOptions, surfaceOnly?: boolean): EditorBinding;
120
174
  /** Framework-neutral composition API, shared by every adapter. Choose before mount. */
121
175
  interface SurfaceOptions extends EditorOptions, SurfaceHostActions {
122
176
  canEdit?: boolean | undefined;
@@ -266,5 +320,5 @@ declare function createViewerBuildingBlocks(initial?: BuildingBlockOptions): {
266
320
  destroy: () => void;
267
321
  };
268
322
 
269
- export { EDITOR_EVENT_NAMES, EDITOR_HANDLE_KEYS, EDITOR_PROP_KEYS, createViewerBuildingBlocks, deferredHandle, eventOptions, mountEditor, mountEditorSurface, pickEditorProps, prepareBlock, selectReference, toolbarModel };
323
+ export { EDITOR_CALLBACKS, EDITOR_CONTRACT, EDITOR_EVENT_NAMES, EDITOR_HANDLE_KEYS, EDITOR_PROP_KEYS, createViewerBuildingBlocks, deferredHandle, eventOptions, mountEditor, mountEditorSurface, pickEditorProps, prepareBlock, selectReference, svelteEditorOptions, toolbarModel };
270
324
  export type { BuildingBlockOptions, BuildingBlockState, EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorHandleKey, EditorOptions, EditorPropKey, EditorProps, SurfaceOptions };
package/dist/runtime.js CHANGED
@@ -1,75 +1,30 @@
1
- import { LegacyXlsError as e, csvToWorkbook as t, detectWorkbookFormat as n, loadLegacyXls as r, loadWorkbook as i, parseCsv as a, saveWorkbook as o, sheetToCsv as s } from "@christophervr/xlsx-core/load";
2
- import { onDestroy as c } from "svelte";
3
- import { writable as l } from "svelte/store";
4
- import * as u from "ooxml-ui/theme";
1
+ import { bindElement as e, contractOptions as t, createSrcLoader as n, deferredHandle as r, eventArgs as i, eventOptions as a, pickProps as o, readOnlyChange as s, sameList as c, shallowEqual as l, svelteHandlerName as u } from "ooxml-ui/bindings";
2
+ import { LegacyXlsError as d, csvToWorkbook as f, detectWorkbookFormat as p, loadLegacyXls as m, loadWorkbook as h, parseCsv as g, saveWorkbook as _, sheetToCsv as v } from "@christophervr/xlsx-core/load";
3
+ import { onDestroy as y } from "svelte";
4
+ import { writable as b } from "svelte/store";
5
+ import * as x from "ooxml-ui/theme";
5
6
  export * from "ooxml-ui/xlsx";
6
7
  export * from "@christophervr/xlsx-core";
7
8
  //#region \0rolldown/runtime.js
8
- var d = Object.defineProperty, f = Object.getOwnPropertyDescriptor, p = Object.getOwnPropertyNames, m = Object.prototype.hasOwnProperty, h = (e, t) => {
9
+ var S = Object.defineProperty, C = Object.getOwnPropertyDescriptor, w = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, E = (e, t) => {
9
10
  let n = {};
10
- for (var r in e) d(n, r, {
11
+ for (var r in e) S(n, r, {
11
12
  get: e[r],
12
13
  enumerable: !0
13
14
  });
14
- return t || d(n, Symbol.toStringTag, { value: "Module" }), n;
15
- }, g = (e, t, n, r) => {
16
- if (t && typeof t == "object" || typeof t == "function") for (var i = p(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !m.call(e, s) && s !== n && d(e, s, {
15
+ return t || S(n, Symbol.toStringTag, { value: "Module" }), n;
16
+ }, D = (e, t, n, r) => {
17
+ if (t && typeof t == "object" || typeof t == "function") for (var i = w(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !T.call(e, s) && s !== n && S(e, s, {
17
18
  get: ((e) => t[e]).bind(null, s),
18
- enumerable: !(r = f(t, s)) || r.enumerable
19
+ enumerable: !(r = C(t, s)) || r.enumerable
19
20
  });
20
21
  return e;
21
- }, _ = (e, t, n) => (g(e, t, "default"), n && g(n, t, "default")), v = /* @__PURE__ */ h({});
22
- import * as y from "ooxml-ui/xlsx";
23
- _(v, y);
22
+ }, O = (e, t, n) => (D(e, t, "default"), n && D(n, t, "default")), k = /* @__PURE__ */ E({});
23
+ import * as A from "ooxml-ui/xlsx";
24
+ O(k, A);
24
25
  //#endregion
25
- //#region packages/bindings/src/forwarding.ts
26
- function b(e, t) {
27
- if (e === t) return !0;
28
- let n = e ?? [], r = t ?? [];
29
- return n.length === r.length && n.every((e, t) => e === r[t]);
30
- }
31
- function x(e, t) {
32
- if (e === t) return !0;
33
- let n = { ...e }, r = { ...t }, i = Object.keys(n);
34
- return i.length === Object.keys(r).length && i.every((e) => n[e] === r[e]);
35
- }
36
- function S() {
37
- let e = /* @__PURE__ */ new Map();
38
- return function(t, n, r = Object.is) {
39
- return e.has(t) && r(e.get(t), n) ? !1 : (e.set(t, n), !0);
40
- };
41
- }
42
- function C(e) {
43
- let t = e.split(/[?#]/u)[0]?.split("/").pop();
44
- if (t) try {
45
- return decodeURIComponent(t);
46
- } catch {
47
- return t;
48
- }
49
- }
50
- function w(e, t) {
51
- let n = 0, r, i = () => {
52
- n++, r?.abort(), r = void 0;
53
- };
54
- return {
55
- cancel: i,
56
- fetch(a, o) {
57
- i();
58
- let s = n, c = typeof AbortController > "u" ? void 0 : new AbortController();
59
- r = c;
60
- let l = () => s === n;
61
- Promise.resolve().then(() => fetch(a, c ? { signal: c.signal } : void 0)).then(async (e) => {
62
- if (!e.ok) throw Error(`Could not fetch ${a}: HTTP ${e.status}`);
63
- return new Uint8Array(await e.arrayBuffer());
64
- }).then((t) => l() ? e(t, o ?? C(a)) : void 0).catch((e) => {
65
- l() && t(e);
66
- });
67
- }
68
- };
69
- }
70
- //#endregion
71
- //#region packages/bindings/src/index.ts
72
- var T = [
26
+ //#region packages/bindings/src/contract.ts
27
+ var j = [
73
28
  "workbook",
74
29
  "bytes",
75
30
  "src",
@@ -83,113 +38,142 @@ var T = [
83
38
  "hiddenActions",
84
39
  "ribbonAddIns",
85
40
  "themeColors",
86
- "collaboration"
87
- ], E = [
41
+ "collaboration",
42
+ "storage",
43
+ "customization"
44
+ ], M = [
88
45
  "workbook-change",
89
46
  "workbook-error",
90
47
  "selection-change",
91
48
  "dirty-change",
92
49
  "readonly-change",
50
+ "file-command",
51
+ "workbook-warning",
52
+ "ribbon-action",
93
53
  "ribbon-customize",
54
+ "sheet-change",
94
55
  "office-ribbon-add-in",
95
56
  "collaboration-change"
96
- ];
97
- function D(e, t, n) {
98
- e[n] = t[n];
99
- }
100
- function O(e) {
101
- let t = {};
102
- for (let n of T) D(t, e, n);
103
- return t;
57
+ ], N = {
58
+ props: {
59
+ locale: {
60
+ forward: "changed",
61
+ fallback: "en"
62
+ },
63
+ readOnly: {
64
+ forward: "changed",
65
+ fallback: !1
66
+ },
67
+ theme: {
68
+ forward: "changed",
69
+ fallback: "auto"
70
+ },
71
+ authorName: {
72
+ forward: "changed",
73
+ fallback: "Author"
74
+ },
75
+ showToolbar: {
76
+ forward: "changed",
77
+ fallback: !0
78
+ },
79
+ showFormulaBar: {
80
+ forward: "changed",
81
+ fallback: !0
82
+ },
83
+ hiddenActions: {
84
+ forward: "changed",
85
+ same: c,
86
+ apply: (e, t) => e.hiddenActions = [...t ?? []]
87
+ },
88
+ ribbonAddIns: {
89
+ forward: "changed",
90
+ apply: (e, t) => e.ribbonAddIns = t ?? []
91
+ },
92
+ storage: {
93
+ forward: "changed",
94
+ apply: (e, t) => e.storage = t ?? void 0
95
+ },
96
+ themeColors: {
97
+ forward: "changed",
98
+ same: l,
99
+ apply: (e, t) => e.themeColors = { ...t }
100
+ },
101
+ fileName: { forward: "defined" },
102
+ collaboration: {
103
+ forward: "changed",
104
+ fallback: null
105
+ },
106
+ customization: {
107
+ forward: "changed",
108
+ fallback: null
109
+ },
110
+ workbook: { forward: "manual" },
111
+ bytes: { forward: "manual" },
112
+ src: { forward: "manual" }
113
+ },
114
+ events: {
115
+ "workbook-change": {
116
+ option: "onWorkbookChange",
117
+ args: i.field("workbook")
118
+ },
119
+ "workbook-error": {
120
+ option: "onWorkbookError",
121
+ args: i.field("error")
122
+ },
123
+ "selection-change": { option: "onSelectionChange" },
124
+ "dirty-change": {
125
+ option: "onDirtyChange",
126
+ args: i.field("dirty")
127
+ },
128
+ "readonly-change": s,
129
+ "file-command": {
130
+ option: "onFileCommand",
131
+ args: i.event
132
+ },
133
+ "workbook-warning": {
134
+ option: "onWorkbookWarning",
135
+ args: (e) => [[...e.detail.warnings]]
136
+ },
137
+ "ribbon-action": { option: "onRibbonAction" },
138
+ "ribbon-customize": {
139
+ option: "onRibbonCustomize",
140
+ args: (e) => [[...e.detail.hiddenActions]]
141
+ },
142
+ "sheet-change": { option: "onSheetChange" },
143
+ "office-ribbon-add-in": { option: "onRibbonAddIn" },
144
+ "collaboration-change": { option: "onCollaborationChange" }
145
+ },
146
+ handle: {
147
+ element: "get",
148
+ load: "async",
149
+ newWorkbook: "call",
150
+ save: "async",
151
+ saveBytes: "async",
152
+ download: "async",
153
+ markClean: "optional-call",
154
+ select: "call",
155
+ getSelection: "call",
156
+ setActiveSheet: "call",
157
+ share: "call",
158
+ dirty: { fallback: !1 }
159
+ }
160
+ }, P = ["onReady"];
161
+ function F(e) {
162
+ return o(N, e);
104
163
  }
105
- function k(e) {
164
+ function I(e) {
106
165
  return {
107
- onWorkbookChange: e["workbook-change"],
108
- onWorkbookError: e["workbook-error"],
109
- onSelectionChange: e["selection-change"],
110
- onDirtyChange: e["dirty-change"],
111
- onReadOnlyChange: e["readonly-change"],
112
- onRibbonCustomize: e["ribbon-customize"],
113
- onRibbonAddIn: e["office-ribbon-add-in"],
114
- onCollaborationChange: e["collaboration-change"],
166
+ ...a(N, e),
115
167
  onReady: e.ready
116
168
  };
117
169
  }
118
- function A(e) {
119
- let t = () => {
120
- let t = e();
121
- if (!t) throw Error("Editor is not mounted");
122
- return t;
123
- };
124
- return {
125
- get element() {
126
- return t().element;
127
- },
128
- load: async (e, n) => t().load(e, n),
129
- newWorkbook: () => t().newWorkbook(),
130
- save: async () => t().save(),
131
- saveBytes: async (e) => t().saveBytes(e),
132
- download: async (e) => t().download(e),
133
- markClean: () => e()?.markClean(),
134
- select: (e) => t().select(e),
135
- getSelection: () => t().getSelection(),
136
- setActiveSheet: (e) => t().setActiveSheet(e),
137
- share: () => t().share(),
138
- get dirty() {
139
- return e()?.dirty ?? !1;
140
- }
141
- };
170
+ function L(e) {
171
+ return t(N, e, u, P);
142
172
  }
143
- function j(e, t = {}, n = !1) {
144
- (0, v.defineXlsxEditor)();
145
- let r = e.ownerDocument.createElement("xlsx-editor");
146
- if (n && typeof r.getToolbarProps != "function") throw Error("Update ooxml-ui to use editor building blocks.");
147
- r.surfaceOnly = n;
148
- let i = {}, a, o, s, c, l = !1, u = S(), d = (e) => {
149
- l || i.onWorkbookError?.(e instanceof Error ? e : Error(String(e)));
150
- }, f = (e, t) => r.load(e, t).catch(() => void 0), p = w(f, d), m = {
151
- "workbook-change": (e) => {
152
- o = e.detail.workbook, i.onWorkbookChange?.(o);
153
- },
154
- "workbook-error": (e) => i.onWorkbookError?.(e.detail.error),
155
- "selection-change": (e) => i.onSelectionChange?.(e.detail),
156
- "dirty-change": (e) => i.onDirtyChange?.(e.detail.dirty),
157
- "readonly-change": (e) => i.onReadOnlyChange?.(e.detail.readOnly),
158
- "ribbon-customize": (e) => i.onRibbonCustomize?.([...e.detail.hiddenActions]),
159
- "office-ribbon-add-in": (e) => i.onRibbonAddIn?.(e.detail),
160
- "collaboration-change": (e) => i.onCollaborationChange?.(e.detail)
161
- }, h = (e) => {
162
- for (let t of E) {
163
- let n = m[t];
164
- e ? r.addEventListener(t, n) : r.removeEventListener(t, n);
165
- }
166
- };
167
- h(!0);
168
- let g = {
169
- element: r,
170
- update(e) {
171
- l || (i = e, u("locale", e.locale) && (r.locale = e.locale ?? "en"), u("readOnly", e.readOnly) && (r.readOnly = e.readOnly ?? !1), u("theme", e.theme) && (r.theme = e.theme ?? "auto"), u("authorName", e.authorName) && (r.authorName = e.authorName ?? "Author"), u("showToolbar", e.showToolbar) && (r.showToolbar = e.showToolbar ?? !0), u("showFormulaBar", e.showFormulaBar) && (r.showFormulaBar = e.showFormulaBar ?? !0), u("hiddenActions", e.hiddenActions, b) && (r.hiddenActions = [...e.hiddenActions ?? []]), u("ribbonAddIns", e.ribbonAddIns) && (r.ribbonAddIns = e.ribbonAddIns ?? []), u("themeColors", e.themeColors, x) && (r.themeColors = { ...e.themeColors }), u("fileName", e.fileName) && e.fileName !== void 0 && (r.fileName = e.fileName), u("collaboration", e.collaboration ?? null) && (r.collaboration = e.collaboration ?? null), e.workbook && e.workbook !== a && e.workbook !== o && (p.cancel(), r.workbook = e.workbook), a = e.workbook, e.bytes && e.bytes !== s && (p.cancel(), f(e.bytes, e.fileName)), s = e.bytes, e.src && e.src !== c ? p.fetch(e.src, e.fileName) : !e.src && c && p.cancel(), c = e.src);
172
- },
173
- load: (e, t) => (p.cancel(), r.load(e, t)),
174
- newWorkbook: () => r.newWorkbook(),
175
- save: () => r.save(),
176
- saveBytes: (e) => r.saveBytes(e),
177
- download: (e) => r.download(e),
178
- markClean: () => r.markClean(),
179
- select: (e) => r.select(e),
180
- getSelection: () => r.getSelection(),
181
- setActiveSheet: (e) => r.setActiveSheet(e),
182
- share: () => r.share(),
183
- get dirty() {
184
- return r.dirty;
185
- },
186
- destroy() {
187
- l || (l = !0, p.cancel(), typeof r.stopCollaboration == "function" && r.stopCollaboration(), h(!1), r.remove());
188
- }
189
- };
190
- return g.update(t), e.append(r), i.onReady?.(r), g;
173
+ function R(e) {
174
+ return r(N.handle, e);
191
175
  }
192
- var M = [
176
+ var z = [
193
177
  "element",
194
178
  "load",
195
179
  "newWorkbook",
@@ -202,7 +186,43 @@ var M = [
202
186
  "setActiveSheet",
203
187
  "share",
204
188
  "dirty"
205
- ], N = [
189
+ ];
190
+ //#endregion
191
+ //#region packages/bindings/src/index.ts
192
+ function B(t, r = {}, i = !1) {
193
+ (0, k.defineXlsxEditor)();
194
+ let a = t.ownerDocument.createElement("xlsx-editor");
195
+ if (i && typeof a.getToolbarProps != "function") throw Error("Update ooxml-ui to use editor building blocks.");
196
+ a.surfaceOnly = i;
197
+ let o = {}, s, c, l, u, d = !1, f = (e) => {
198
+ d || o.onWorkbookError?.(e instanceof Error ? e : Error(String(e)));
199
+ }, p = (e, t) => a.load(e, t).catch(() => void 0), m = n(p, f), h = e(a, N, () => o, { onEvent: (e, t) => {
200
+ e === "workbook-change" && (c = t.detail.workbook);
201
+ } }), g = {
202
+ element: a,
203
+ update(e) {
204
+ d || (o = e, h.update(e), e.workbook && e.workbook !== s && e.workbook !== c && (m.cancel(), a.workbook = e.workbook), s = e.workbook, e.bytes && e.bytes !== l && (m.cancel(), p(e.bytes, e.fileName)), l = e.bytes, e.src && e.src !== u ? m.fetch(e.src, e.fileName) : !e.src && u && m.cancel(), u = e.src);
205
+ },
206
+ load: (e, t) => (m.cancel(), a.load(e, t)),
207
+ newWorkbook: () => a.newWorkbook(),
208
+ save: () => a.save(),
209
+ saveBytes: (e) => a.saveBytes(e),
210
+ download: (e) => a.download(e),
211
+ markClean: () => a.markClean(),
212
+ select: (e) => a.select(e),
213
+ getSelection: () => a.getSelection(),
214
+ setActiveSheet: (e) => a.setActiveSheet(e),
215
+ share: () => a.share(),
216
+ get dirty() {
217
+ return a.dirty;
218
+ },
219
+ destroy() {
220
+ d || (d = !0, m.cancel(), typeof a.stopCollaboration == "function" && a.stopCollaboration(), h.unlisten(), a.remove());
221
+ }
222
+ };
223
+ return g.update(r), t.append(a), o.onReady?.(a), g;
224
+ }
225
+ var V = [
206
226
  "onOpenShareDialog",
207
227
  "onOpenSettings",
208
228
  "onOpenFormatCells",
@@ -210,14 +230,14 @@ var M = [
210
230
  "onOpenInsertFunction",
211
231
  "onOpenValidationAlert"
212
232
  ];
213
- function P(e, t = {}) {
233
+ function H(e, t = {}) {
214
234
  let n = t, r = (e) => ({
215
235
  ...e,
216
236
  readOnly: e.canEdit !== !0 || e.readOnly === !0
217
- }), i = j(e, r(t), !0), { element: a } = i, o = i.update, s = i.destroy, c = {}, l = (e) => {
218
- if (N.every((t) => c[t] === e[t])) return;
237
+ }), i = B(e, r(t), !0), { element: a } = i, o = i.update, s = i.destroy, c = {}, l = (e) => {
238
+ if (V.every((t) => c[t] === e[t])) return;
219
239
  let t = {};
220
- for (let n of N) t[n] = e[n];
240
+ for (let n of V) t[n] = e[n];
221
241
  c = t, a.surfaceActions = t;
222
242
  }, u = (e) => n.onValidationError?.(e.detail);
223
243
  return a.addEventListener("validation-error", u), l(t), Object.assign(i, {
@@ -233,36 +253,36 @@ function P(e, t = {}) {
233
253
  }
234
254
  //#endregion
235
255
  //#region packages/bindings/src/common.ts
236
- var F = /* @__PURE__ */ h({
237
- LegacyXlsError: () => e,
238
- csvToWorkbook: () => t,
239
- detectWorkbookFormat: () => n,
240
- loadLegacyXls: () => r,
241
- loadWorkbook: () => i,
242
- mountEditorSurface: () => P,
243
- parseCsv: () => a,
244
- saveWorkbook: () => o,
245
- sheetToCsv: () => s
256
+ var U = /* @__PURE__ */ E({
257
+ LegacyXlsError: () => d,
258
+ csvToWorkbook: () => f,
259
+ detectWorkbookFormat: () => p,
260
+ loadLegacyXls: () => m,
261
+ loadWorkbook: () => h,
262
+ mountEditorSurface: () => H,
263
+ parseCsv: () => g,
264
+ saveWorkbook: () => _,
265
+ sheetToCsv: () => v
246
266
  });
247
- _(F, v);
267
+ O(U, k);
248
268
  //#endregion
249
269
  //#region packages/bindings/src/building-blocks.ts
250
- var I = Object.freeze({
270
+ var W = Object.freeze({
251
271
  active: !1,
252
272
  roomId: void 0,
253
273
  status: "off",
254
274
  synced: !1,
255
275
  people: []
256
276
  });
257
- function L(e) {
277
+ function G(e) {
258
278
  return {
259
279
  dirty: e?.dirty ?? !1,
260
280
  selection: e?.selection ?? "",
261
- collaboration: e?.collaboration ?? I,
281
+ collaboration: e?.collaboration ?? W,
262
282
  editError: e?.editError ?? null
263
283
  };
264
284
  }
265
- function R(e) {
285
+ function K(e) {
266
286
  let t = null, n, r, i = {}, a = null, o = !1, s = () => {
267
287
  let t = n?.element.loading ?? !1;
268
288
  t && !o && (a = null), o = t;
@@ -272,7 +292,7 @@ function R(e) {
272
292
  loading: n?.element.loading ?? !1,
273
293
  error: a,
274
294
  mode: i.canEdit !== !0 || i.readOnly ? "view" : "edit",
275
- ...L(r)
295
+ ...G(r)
276
296
  });
277
297
  }, c = () => ({
278
298
  ...i,
@@ -283,9 +303,9 @@ function R(e) {
283
303
  t = null, r?.(), r = void 0, n?.destroy(), n = void 0, s();
284
304
  };
285
305
  return {
286
- handle: A(() => n),
306
+ handle: R(() => n),
287
307
  mount(e) {
288
- e && e === t || (l(), e && (a = null, n = P(e, c()), t = e, r = n.subscribe(s), s()));
308
+ e && e === t || (l(), e && (a = null, n = H(e, c()), t = e, r = n.subscribe(s), s()));
289
309
  },
290
310
  update(e) {
291
311
  (e.workbook !== i.workbook || e.bytes !== i.bytes || e.src !== i.src) && (a = null), i = e, n?.update(c()), s();
@@ -293,20 +313,20 @@ function R(e) {
293
313
  destroy: l
294
314
  };
295
315
  }
296
- var z = () => ({
316
+ var q = () => ({
297
317
  toolbarProps: null,
298
318
  loading: !1,
299
319
  error: null,
300
320
  mode: "view",
301
- ...L(null)
302
- }), B = (e, t) => t === null ? [{
321
+ ...G(null)
322
+ }), J = (e, t) => t === null ? [{
303
323
  value: "",
304
324
  label: ""
305
325
  }, ...e] : e.some((e) => e.value === t) ? e : [{
306
326
  value: t,
307
327
  label: t
308
328
  }, ...e];
309
- function V(e) {
329
+ function Y(e) {
310
330
  let t = (t) => e.labels[t] ?? t, n = (t) => !e.canEdit || !t, r = (e, t, n, r, i) => ({
311
331
  kind: "button",
312
332
  id: e,
@@ -324,7 +344,7 @@ function V(e) {
324
344
  label: t("Font"),
325
345
  value: e.fontFamily ?? "",
326
346
  disabled: n(e.enabled.fontFamily),
327
- options: B(e.options.fontFamilies.map((e) => ({
347
+ options: J(e.options.fontFamilies.map((e) => ({
328
348
  value: e,
329
349
  label: e
330
350
  })), e.fontFamily),
@@ -336,7 +356,7 @@ function V(e) {
336
356
  label: t("Font Size"),
337
357
  value: e.fontSize === null ? "" : String(e.fontSize),
338
358
  disabled: n(e.enabled.fontSize),
339
- options: B(e.options.fontSizes.map((e) => ({
359
+ options: J(e.options.fontSizes.map((e) => ({
340
360
  value: String(e),
341
361
  label: String(e)
342
362
  })), e.fontSize === null ? null : String(e.fontSize)),
@@ -352,12 +372,12 @@ function V(e) {
352
372
  label: t("Number Format"),
353
373
  value: e.numberFormat ?? "",
354
374
  disabled: n(e.enabled.numberFormat),
355
- options: B(e.options.numberFormats, e.numberFormat),
375
+ options: J(e.options.numberFormats, e.numberFormat),
356
376
  change: (t) => e.onNumberFormatChange(t)
357
377
  }
358
378
  ];
359
379
  }
360
- function H(e, t) {
380
+ function X(e, t) {
361
381
  try {
362
382
  return e.onSelect(t);
363
383
  } catch {
@@ -366,16 +386,16 @@ function H(e, t) {
366
386
  }
367
387
  //#endregion
368
388
  //#region packages/bindings/src/block-theme.ts
369
- function U(e, t) {
389
+ function Z(e, t) {
370
390
  if (!e || typeof e != "object" || !("ownerDocument" in e)) return;
371
- let n = e, r = Reflect.get(u, "prepareOfficeUiBlock");
372
- typeof r == "function" ? r(n, t, "xlsx") : (u.installOfficeUiTheme(n.ownerDocument), n.setAttribute("data-office-block", t), n.setAttribute("data-office-product", "xlsx"));
391
+ let n = e, r = Reflect.get(x, "prepareOfficeUiBlock");
392
+ typeof r == "function" ? r(n, t, "xlsx") : (x.installOfficeUiTheme(n.ownerDocument), n.setAttribute("data-office-block", t), n.setAttribute("data-office-product", "xlsx"));
373
393
  }
374
394
  //#endregion
375
395
  //#region packages/svelte/src/building-blocks.ts
376
- function W(e = {}) {
377
- let t = l(z()), n = R(t.set);
378
- return n.update(e), c(n.destroy), {
396
+ function Q(e = {}) {
397
+ let t = b(q()), n = K(t.set);
398
+ return n.update(e), y(n.destroy), {
379
399
  subscribe: t.subscribe,
380
400
  update: n.update,
381
401
  handle: n.handle,
@@ -383,27 +403,30 @@ function W(e = {}) {
383
403
  destroy: n.destroy
384
404
  };
385
405
  }
386
- _(/* @__PURE__ */ h({
387
- EDITOR_EVENT_NAMES: () => E,
388
- EDITOR_HANDLE_KEYS: () => M,
389
- EDITOR_PROP_KEYS: () => T,
390
- LegacyXlsError: () => e,
391
- createViewerBuildingBlocks: () => W,
392
- csvToWorkbook: () => t,
393
- deferredHandle: () => A,
394
- detectWorkbookFormat: () => n,
395
- eventOptions: () => k,
396
- loadLegacyXls: () => r,
397
- loadWorkbook: () => i,
398
- mountEditor: () => j,
399
- mountEditorSurface: () => P,
400
- parseCsv: () => a,
401
- pickEditorProps: () => O,
402
- prepareBlock: () => U,
403
- saveWorkbook: () => o,
404
- selectReference: () => H,
405
- sheetToCsv: () => s,
406
- toolbarModel: () => V
407
- }), F);
406
+ O(/* @__PURE__ */ E({
407
+ EDITOR_CALLBACKS: () => P,
408
+ EDITOR_CONTRACT: () => N,
409
+ EDITOR_EVENT_NAMES: () => M,
410
+ EDITOR_HANDLE_KEYS: () => z,
411
+ EDITOR_PROP_KEYS: () => j,
412
+ LegacyXlsError: () => d,
413
+ createViewerBuildingBlocks: () => Q,
414
+ csvToWorkbook: () => f,
415
+ deferredHandle: () => R,
416
+ detectWorkbookFormat: () => p,
417
+ eventOptions: () => I,
418
+ loadLegacyXls: () => m,
419
+ loadWorkbook: () => h,
420
+ mountEditor: () => B,
421
+ mountEditorSurface: () => H,
422
+ parseCsv: () => g,
423
+ pickEditorProps: () => F,
424
+ prepareBlock: () => Z,
425
+ saveWorkbook: () => _,
426
+ selectReference: () => X,
427
+ sheetToCsv: () => v,
428
+ svelteEditorOptions: () => L,
429
+ toolbarModel: () => Y
430
+ }), U);
408
431
  //#endregion
409
- export { E as EDITOR_EVENT_NAMES, M as EDITOR_HANDLE_KEYS, T as EDITOR_PROP_KEYS, e as LegacyXlsError, W as createViewerBuildingBlocks, t as csvToWorkbook, A as deferredHandle, n as detectWorkbookFormat, k as eventOptions, r as loadLegacyXls, i as loadWorkbook, j as mountEditor, P as mountEditorSurface, a as parseCsv, O as pickEditorProps, U as prepareBlock, o as saveWorkbook, H as selectReference, s as sheetToCsv, V as toolbarModel };
432
+ export { P as EDITOR_CALLBACKS, N as EDITOR_CONTRACT, M as EDITOR_EVENT_NAMES, z as EDITOR_HANDLE_KEYS, j as EDITOR_PROP_KEYS, d as LegacyXlsError, Q as createViewerBuildingBlocks, f as csvToWorkbook, R as deferredHandle, p as detectWorkbookFormat, I as eventOptions, m as loadLegacyXls, h as loadWorkbook, B as mountEditor, H as mountEditorSurface, g as parseCsv, F as pickEditorProps, Z as prepareBlock, _ as saveWorkbook, X as selectReference, v as sheetToCsv, L as svelteEditorOptions, Y as toolbarModel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xlsx-svelte-viewer",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Svelte 5 component for the Excel spreadsheet editor. Self-contained: includes the editor, the formula engine and the legacy .xls reader.",
5
5
  "keywords": [
6
6
  "editor",
@@ -66,9 +66,9 @@
66
66
  "access": "public"
67
67
  },
68
68
  "dependencies": {
69
- "@christophervr/xlsx-core": "^0.3.0",
70
- "ooxml-core": "^1.23.0",
71
- "ooxml-ui": "^1.22.0"
69
+ "@christophervr/xlsx-core": "^0.3.1",
70
+ "ooxml-core": "^1.25.0",
71
+ "ooxml-ui": "^1.26.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "svelte": "^5.0.0"