xlsx-svelte-viewer 1.2.0 → 1.2.2

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,5 +1,5 @@
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'];
@@ -24,9 +24,8 @@
24
24
  const element = $derived(mountedElement);
25
25
  const dirty = $derived(dirtyState);
26
26
  function attach(host: HTMLElement, options: Props) {
27
- const normalized = (value: Props) => ({ ...pickEditorProps(value),
28
- ...eventOptions({ 'workbook-change': value.onworkbookchange, 'workbook-error': value.onworkbookerror, 'selection-change': value.onselectionchange, 'dirty-change': value.ondirtychange, 'readonly-change': value.onreadonlychange, 'file-command': value.onfilecommand, 'workbook-warning': value.onworkbookwarning, 'ribbon-action': value.onribbonaction, 'ribbon-customize': value.onribboncustomize, 'sheet-change': value.onsheetchange, 'office-ribbon-add-in': value.onribbonaddin, 'collaboration-change': value.oncollaborationchange, ready: value.onready }) });
29
- 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); } });
30
29
  binding = mountEditor(host, tracked(options));
31
30
  mountedElement = binding.element;
32
31
  dirtyState = binding.dirty;
package/dist/runtime.d.ts CHANGED
@@ -7,6 +7,7 @@ export { SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
7
7
  import { Workbook } from '@christophervr/xlsx-core';
8
8
  export * from '@christophervr/xlsx-core';
9
9
  import { DocumentStorage } from 'ooxml-core/embedding';
10
+ import { BindingContract } from 'ooxml-ui/bindings';
10
11
  export { LegacyXlsError, WorkbookFormat, csvToWorkbook, detectWorkbookFormat, loadLegacyXls, loadWorkbook, parseCsv, saveWorkbook, sheetToCsv } from '@christophervr/xlsx-core/load';
11
12
  import * as svelte_store from 'svelte/store';
12
13
 
@@ -120,10 +121,6 @@ interface EditorEventHandlers {
120
121
  'collaboration-change': EditorEventOptions['onCollaborationChange'];
121
122
  ready?: EditorEventOptions['onReady'];
122
123
  }
123
- /** Copies exactly the shared props out of a framework's props/instance object. */
124
- declare function pickEditorProps(source: EditorProps): EditorProps;
125
- /** Maps per-event handlers (keyed by DOM event name) onto the shared option callbacks. */
126
- declare function eventOptions(handlers: EditorEventHandlers): EditorEventOptions;
127
124
  interface EditorHandle {
128
125
  readonly element: XlsxEditorElement;
129
126
  load(input: Uint8Array | ArrayBuffer, fileName?: string): Promise<void>;
@@ -145,19 +142,35 @@ interface EditorBinding extends EditorHandle {
145
142
  update(options: EditorOptions): void;
146
143
  destroy(): void;
147
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;
148
160
  /**
149
161
  * A handle for adapters that hold a binding which may not be mounted yet: every call reads the
150
162
  * current binding and throws a clear error before mount.
151
163
  */
152
164
  declare function deferredHandle(current: () => EditorBinding | null | undefined): EditorHandle;
153
- /** All framework adapters share property, event and lifecycle semantics here. */
154
- declare function mountEditor(host: HTMLElement, initial?: EditorOptions, surfaceOnly?: boolean): EditorBinding;
155
165
  /**
156
166
  * The imperative handle every framework exposes (React ref, Vue template ref, Angular component
157
- * 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.
158
168
  */
159
169
  declare const EDITOR_HANDLE_KEYS: readonly ["element", "load", "newWorkbook", "save", "saveBytes", "download", "markClean", "select", "getSelection", "setActiveSheet", "share", "dirty"];
160
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;
161
174
  /** Framework-neutral composition API, shared by every adapter. Choose before mount. */
162
175
  interface SurfaceOptions extends EditorOptions, SurfaceHostActions {
163
176
  canEdit?: boolean | undefined;
@@ -307,5 +320,5 @@ declare function createViewerBuildingBlocks(initial?: BuildingBlockOptions): {
307
320
  destroy: () => void;
308
321
  };
309
322
 
310
- 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 };
311
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",
@@ -86,7 +41,7 @@ var T = [
86
41
  "collaboration",
87
42
  "storage",
88
43
  "customization"
89
- ], E = [
44
+ ], M = [
90
45
  "workbook-change",
91
46
  "workbook-error",
92
47
  "selection-change",
@@ -99,111 +54,126 @@ var T = [
99
54
  "sheet-change",
100
55
  "office-ribbon-add-in",
101
56
  "collaboration-change"
102
- ];
103
- function D(e, t, n) {
104
- e[n] = t[n];
105
- }
106
- function O(e) {
107
- let t = {};
108
- for (let n of T) D(t, e, n);
109
- 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);
110
163
  }
111
- function k(e) {
164
+ function I(e) {
112
165
  return {
113
- onWorkbookChange: e["workbook-change"],
114
- onWorkbookError: e["workbook-error"],
115
- onSelectionChange: e["selection-change"],
116
- onDirtyChange: e["dirty-change"],
117
- onReadOnlyChange: e["readonly-change"],
118
- onFileCommand: e["file-command"],
119
- onWorkbookWarning: e["workbook-warning"],
120
- onRibbonAction: e["ribbon-action"],
121
- onRibbonCustomize: e["ribbon-customize"],
122
- onSheetChange: e["sheet-change"],
123
- onRibbonAddIn: e["office-ribbon-add-in"],
124
- onCollaborationChange: e["collaboration-change"],
166
+ ...a(N, e),
125
167
  onReady: e.ready
126
168
  };
127
169
  }
128
- function A(e) {
129
- let t = () => {
130
- let t = e();
131
- if (!t) throw Error("Editor is not mounted");
132
- return t;
133
- };
134
- return {
135
- get element() {
136
- return t().element;
137
- },
138
- load: async (e, n) => t().load(e, n),
139
- newWorkbook: () => t().newWorkbook(),
140
- save: async () => t().save(),
141
- saveBytes: async (e) => t().saveBytes(e),
142
- download: async (e) => t().download(e),
143
- markClean: () => e()?.markClean(),
144
- select: (e) => t().select(e),
145
- getSelection: () => t().getSelection(),
146
- setActiveSheet: (e) => t().setActiveSheet(e),
147
- share: () => t().share(),
148
- get dirty() {
149
- return e()?.dirty ?? !1;
150
- }
151
- };
170
+ function L(e) {
171
+ return t(N, e, u, P);
152
172
  }
153
- function j(e, t = {}, n = !1) {
154
- (0, v.defineXlsxEditor)();
155
- let r = e.ownerDocument.createElement("xlsx-editor");
156
- if (n && typeof r.getToolbarProps != "function") throw Error("Update ooxml-ui to use editor building blocks.");
157
- r.surfaceOnly = n;
158
- let i = {}, a, o, s, c, l = !1, u = S(), d = (e) => {
159
- l || i.onWorkbookError?.(e instanceof Error ? e : Error(String(e)));
160
- }, f = (e, t) => r.load(e, t).catch(() => void 0), p = w(f, d), m = {
161
- "workbook-change": (e) => {
162
- o = e.detail.workbook, i.onWorkbookChange?.(o);
163
- },
164
- "workbook-error": (e) => i.onWorkbookError?.(e.detail.error),
165
- "selection-change": (e) => i.onSelectionChange?.(e.detail),
166
- "dirty-change": (e) => i.onDirtyChange?.(e.detail.dirty),
167
- "readonly-change": (e) => i.onReadOnlyChange?.(e.detail.readOnly, e.detail),
168
- "file-command": (e) => i.onFileCommand?.(e),
169
- "workbook-warning": (e) => i.onWorkbookWarning?.([...e.detail.warnings]),
170
- "ribbon-action": (e) => i.onRibbonAction?.(e.detail),
171
- "ribbon-customize": (e) => i.onRibbonCustomize?.([...e.detail.hiddenActions]),
172
- "sheet-change": (e) => i.onSheetChange?.(e.detail),
173
- "office-ribbon-add-in": (e) => i.onRibbonAddIn?.(e.detail),
174
- "collaboration-change": (e) => i.onCollaborationChange?.(e.detail)
175
- }, h = (e) => {
176
- for (let t of E) {
177
- let n = m[t];
178
- e ? r.addEventListener(t, n) : r.removeEventListener(t, n);
179
- }
180
- };
181
- h(!0);
182
- let g = {
183
- element: r,
184
- update(e) {
185
- 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("storage", e.storage ?? void 0) && (r.storage = e.storage ?? void 0), 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), u("customization", e.customization ?? null) && (r.customization = e.customization ?? 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);
186
- },
187
- load: (e, t) => (p.cancel(), r.load(e, t)),
188
- newWorkbook: () => r.newWorkbook(),
189
- save: () => r.save(),
190
- saveBytes: (e) => r.saveBytes(e),
191
- download: (e) => r.download(e),
192
- markClean: () => r.markClean(),
193
- select: (e) => r.select(e),
194
- getSelection: () => r.getSelection(),
195
- setActiveSheet: (e) => r.setActiveSheet(e),
196
- share: () => r.share(),
197
- get dirty() {
198
- return r.dirty;
199
- },
200
- destroy() {
201
- l || (l = !0, p.cancel(), typeof r.stopCollaboration == "function" && r.stopCollaboration(), h(!1), r.remove());
202
- }
203
- };
204
- return g.update(t), e.append(r), i.onReady?.(r), g;
173
+ function R(e) {
174
+ return r(N.handle, e);
205
175
  }
206
- var M = [
176
+ var z = [
207
177
  "element",
208
178
  "load",
209
179
  "newWorkbook",
@@ -216,7 +186,43 @@ var M = [
216
186
  "setActiveSheet",
217
187
  "share",
218
188
  "dirty"
219
- ], 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 = [
220
226
  "onOpenShareDialog",
221
227
  "onOpenSettings",
222
228
  "onOpenFormatCells",
@@ -224,14 +230,14 @@ var M = [
224
230
  "onOpenInsertFunction",
225
231
  "onOpenValidationAlert"
226
232
  ];
227
- function P(e, t = {}) {
233
+ function H(e, t = {}) {
228
234
  let n = t, r = (e) => ({
229
235
  ...e,
230
236
  readOnly: e.canEdit !== !0 || e.readOnly === !0
231
- }), i = j(e, r(t), !0), { element: a } = i, o = i.update, s = i.destroy, c = {}, l = (e) => {
232
- 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;
233
239
  let t = {};
234
- for (let n of N) t[n] = e[n];
240
+ for (let n of V) t[n] = e[n];
235
241
  c = t, a.surfaceActions = t;
236
242
  }, u = (e) => n.onValidationError?.(e.detail);
237
243
  return a.addEventListener("validation-error", u), l(t), Object.assign(i, {
@@ -247,36 +253,36 @@ function P(e, t = {}) {
247
253
  }
248
254
  //#endregion
249
255
  //#region packages/bindings/src/common.ts
250
- var F = /* @__PURE__ */ h({
251
- LegacyXlsError: () => e,
252
- csvToWorkbook: () => t,
253
- detectWorkbookFormat: () => n,
254
- loadLegacyXls: () => r,
255
- loadWorkbook: () => i,
256
- mountEditorSurface: () => P,
257
- parseCsv: () => a,
258
- saveWorkbook: () => o,
259
- 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
260
266
  });
261
- _(F, v);
267
+ O(U, k);
262
268
  //#endregion
263
269
  //#region packages/bindings/src/building-blocks.ts
264
- var I = Object.freeze({
270
+ var W = Object.freeze({
265
271
  active: !1,
266
272
  roomId: void 0,
267
273
  status: "off",
268
274
  synced: !1,
269
275
  people: []
270
276
  });
271
- function L(e) {
277
+ function G(e) {
272
278
  return {
273
279
  dirty: e?.dirty ?? !1,
274
280
  selection: e?.selection ?? "",
275
- collaboration: e?.collaboration ?? I,
281
+ collaboration: e?.collaboration ?? W,
276
282
  editError: e?.editError ?? null
277
283
  };
278
284
  }
279
- function R(e) {
285
+ function K(e) {
280
286
  let t = null, n, r, i = {}, a = null, o = !1, s = () => {
281
287
  let t = n?.element.loading ?? !1;
282
288
  t && !o && (a = null), o = t;
@@ -286,7 +292,7 @@ function R(e) {
286
292
  loading: n?.element.loading ?? !1,
287
293
  error: a,
288
294
  mode: i.canEdit !== !0 || i.readOnly ? "view" : "edit",
289
- ...L(r)
295
+ ...G(r)
290
296
  });
291
297
  }, c = () => ({
292
298
  ...i,
@@ -297,9 +303,9 @@ function R(e) {
297
303
  t = null, r?.(), r = void 0, n?.destroy(), n = void 0, s();
298
304
  };
299
305
  return {
300
- handle: A(() => n),
306
+ handle: R(() => n),
301
307
  mount(e) {
302
- 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()));
303
309
  },
304
310
  update(e) {
305
311
  (e.workbook !== i.workbook || e.bytes !== i.bytes || e.src !== i.src) && (a = null), i = e, n?.update(c()), s();
@@ -307,20 +313,20 @@ function R(e) {
307
313
  destroy: l
308
314
  };
309
315
  }
310
- var z = () => ({
316
+ var q = () => ({
311
317
  toolbarProps: null,
312
318
  loading: !1,
313
319
  error: null,
314
320
  mode: "view",
315
- ...L(null)
316
- }), B = (e, t) => t === null ? [{
321
+ ...G(null)
322
+ }), J = (e, t) => t === null ? [{
317
323
  value: "",
318
324
  label: ""
319
325
  }, ...e] : e.some((e) => e.value === t) ? e : [{
320
326
  value: t,
321
327
  label: t
322
328
  }, ...e];
323
- function V(e) {
329
+ function Y(e) {
324
330
  let t = (t) => e.labels[t] ?? t, n = (t) => !e.canEdit || !t, r = (e, t, n, r, i) => ({
325
331
  kind: "button",
326
332
  id: e,
@@ -338,7 +344,7 @@ function V(e) {
338
344
  label: t("Font"),
339
345
  value: e.fontFamily ?? "",
340
346
  disabled: n(e.enabled.fontFamily),
341
- options: B(e.options.fontFamilies.map((e) => ({
347
+ options: J(e.options.fontFamilies.map((e) => ({
342
348
  value: e,
343
349
  label: e
344
350
  })), e.fontFamily),
@@ -350,7 +356,7 @@ function V(e) {
350
356
  label: t("Font Size"),
351
357
  value: e.fontSize === null ? "" : String(e.fontSize),
352
358
  disabled: n(e.enabled.fontSize),
353
- options: B(e.options.fontSizes.map((e) => ({
359
+ options: J(e.options.fontSizes.map((e) => ({
354
360
  value: String(e),
355
361
  label: String(e)
356
362
  })), e.fontSize === null ? null : String(e.fontSize)),
@@ -366,12 +372,12 @@ function V(e) {
366
372
  label: t("Number Format"),
367
373
  value: e.numberFormat ?? "",
368
374
  disabled: n(e.enabled.numberFormat),
369
- options: B(e.options.numberFormats, e.numberFormat),
375
+ options: J(e.options.numberFormats, e.numberFormat),
370
376
  change: (t) => e.onNumberFormatChange(t)
371
377
  }
372
378
  ];
373
379
  }
374
- function H(e, t) {
380
+ function X(e, t) {
375
381
  try {
376
382
  return e.onSelect(t);
377
383
  } catch {
@@ -380,16 +386,16 @@ function H(e, t) {
380
386
  }
381
387
  //#endregion
382
388
  //#region packages/bindings/src/block-theme.ts
383
- function U(e, t) {
389
+ function Z(e, t) {
384
390
  if (!e || typeof e != "object" || !("ownerDocument" in e)) return;
385
- let n = e, r = Reflect.get(u, "prepareOfficeUiBlock");
386
- 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"));
387
393
  }
388
394
  //#endregion
389
395
  //#region packages/svelte/src/building-blocks.ts
390
- function W(e = {}) {
391
- let t = l(z()), n = R(t.set);
392
- 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), {
393
399
  subscribe: t.subscribe,
394
400
  update: n.update,
395
401
  handle: n.handle,
@@ -397,27 +403,30 @@ function W(e = {}) {
397
403
  destroy: n.destroy
398
404
  };
399
405
  }
400
- _(/* @__PURE__ */ h({
401
- EDITOR_EVENT_NAMES: () => E,
402
- EDITOR_HANDLE_KEYS: () => M,
403
- EDITOR_PROP_KEYS: () => T,
404
- LegacyXlsError: () => e,
405
- createViewerBuildingBlocks: () => W,
406
- csvToWorkbook: () => t,
407
- deferredHandle: () => A,
408
- detectWorkbookFormat: () => n,
409
- eventOptions: () => k,
410
- loadLegacyXls: () => r,
411
- loadWorkbook: () => i,
412
- mountEditor: () => j,
413
- mountEditorSurface: () => P,
414
- parseCsv: () => a,
415
- pickEditorProps: () => O,
416
- prepareBlock: () => U,
417
- saveWorkbook: () => o,
418
- selectReference: () => H,
419
- sheetToCsv: () => s,
420
- toolbarModel: () => V
421
- }), 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);
422
431
  //#endregion
423
- 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.2.0",
3
+ "version": "1.2.2",
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.24.0",
71
- "ooxml-ui": "^1.23.0"
69
+ "@christophervr/xlsx-core": "^1.0.0",
70
+ "ooxml-core": "^1.31.0",
71
+ "ooxml-ui": "^1.33.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "svelte": "^5.0.0"