xlsx-svelte-viewer 0.6.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ <script lang="ts">
2
+ import { prepareBlock } from './runtime.js';
3
+ const themeBlock = (host: HTMLElement) => prepareBlock(host, 'formula-bar');
4
+ import { selectReference, type SpreadsheetToolbarProps } from './runtime.js';
5
+ let { toolbarProps: toolbar }: { toolbarProps: SpreadsheetToolbarProps } = $props();
6
+ let invalid = $state(false); let invalidName = $state(false);
7
+ </script>
8
+ <div use:themeBlock>
9
+ <input aria-label={toolbar.labels['Name Box']} value={toolbar.selection} aria-invalid={invalidName}
10
+ oninput={() => { invalidName = false; }} onkeydown={(e) => { if (e.key === 'Enter') { e.preventDefault(); invalidName = !selectReference(toolbar, e.currentTarget.value); } }} />
11
+ <input aria-label={toolbar.labels['Formula Bar']} value={toolbar.formula} readonly={!toolbar.canEdit} aria-invalid={invalid || toolbar.editError !== null}
12
+ oninput={(e) => { invalid = false; toolbar.onFormulaInput(e.currentTarget.value, e.currentTarget.selectionEnd ?? undefined); }}
13
+ onkeydown={(e) => { if (e.key === 'Enter') { e.preventDefault(); invalid = !toolbar.onFormulaChange(e.currentTarget.value); } else if (e.key === 'Escape') { e.preventDefault(); toolbar.onCancelEdit(); invalid = false; } }} />
14
+ {#if toolbar.editError !== null}<span role="alert">{toolbar.editError}</span>{/if}
15
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { Component } from 'svelte';
2
+ import type { SpreadsheetToolbarProps } from './runtime';
3
+ declare const component: Component<{ toolbarProps: SpreadsheetToolbarProps }>;
4
+ export default component;
@@ -0,0 +1,11 @@
1
+ <script lang="ts">
2
+ import { prepareBlock } from './runtime.js';
3
+ const themeBlock = (host: HTMLElement) => prepareBlock(host, 'tabs');
4
+ import type { SpreadsheetToolbarProps } from './runtime.js';
5
+ let { toolbarProps }: { toolbarProps: SpreadsheetToolbarProps } = $props();
6
+ </script>
7
+ <div use:themeBlock role="tablist" aria-label={toolbarProps.labels['Sheet']}>
8
+ {#each toolbarProps.sheets.filter((s) => s.state === 'visible') as sheet (sheet.index)}
9
+ <button type="button" role="tab" aria-selected={sheet.index === toolbarProps.activeSheet} onclick={() => toolbarProps.onSheetChange(sheet.index)}>{sheet.name}</button>
10
+ {/each}
11
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { Component } from 'svelte';
2
+ import type { SpreadsheetToolbarProps } from './runtime';
3
+ declare const component: Component<{ toolbarProps: SpreadsheetToolbarProps }>;
4
+ export default component;
@@ -0,0 +1,6 @@
1
+ <script lang="ts">
2
+ let { mount, class: className }: { mount: (host: HTMLElement | null) => void; class?: string } = $props();
3
+ let host = $state<HTMLDivElement>();
4
+ $effect(() => { if (!host) return; const current = mount; current(host); return () => current(null); });
5
+ </script>
6
+ <div bind:this={host} class={className}></div>
@@ -0,0 +1,4 @@
1
+ import type { Component } from 'svelte';
2
+ import type { SpreadsheetToolbarProps } from './runtime';
3
+ declare const component: Component<{ mount: (host: HTMLElement | null) => void; class?: string }>;
4
+ export default component;
@@ -0,0 +1,21 @@
1
+ <script lang="ts">
2
+ import { prepareBlock } from './runtime.js';
3
+ const themeBlock = (host: HTMLElement) => prepareBlock(host, 'toolbar');
4
+ import { toolbarModel, type SpreadsheetToolbarProps } from './runtime.js';
5
+ let { toolbarProps }: { toolbarProps: SpreadsheetToolbarProps } = $props();
6
+ </script>
7
+ <div use:themeBlock role="toolbar">
8
+ {#each toolbarModel(toolbarProps) as item (item.id)}
9
+ {#if item.kind === 'select'}
10
+ <select aria-label={item.label} disabled={item.disabled} value={item.value}
11
+ onchange={(e) => { void item.change(e.currentTarget.value); }}>
12
+ {#each item.options as option (option.value)}
13
+ <option value={option.value} selected={option.value === item.value}>{option.label}</option>
14
+ {/each}
15
+ </select>
16
+ {:else}
17
+ <button type="button" disabled={item.disabled} aria-pressed={item.pressed === null ? 'mixed' : item.pressed}
18
+ onmousedown={(e) => e.preventDefault()} onclick={() => { void item.run(); }}>{item.label}</button>
19
+ {/if}
20
+ {/each}
21
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { Component } from 'svelte';
2
+ import type { SpreadsheetToolbarProps } from './runtime';
3
+ declare const component: Component<{ toolbarProps: SpreadsheetToolbarProps }>;
4
+ export default component;
package/dist/runtime.d.ts CHANGED
@@ -1,8 +1,13 @@
1
- import { XlsxEditorElement, EditorLocaleInput, EditorThemeMode, RibbonAddInTab, XlsxThemeColors, XlsxCollaborationOptions, SelectionChangeDetail, RibbonAddInCommandDetail, XlsxCollaborationState } from 'ooxml-ui/xlsx';
1
+ import * as ooxml_core_xlsx from 'ooxml-core/xlsx';
2
+ import * as ooxml_core_xlsx_ui from 'ooxml-core/xlsx/ui';
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';
2
5
  export * from 'ooxml-ui/xlsx';
6
+ export { SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
3
7
  import { Workbook } from '@christophervr/xlsx-core';
4
8
  export * from '@christophervr/xlsx-core';
5
9
  export { LegacyXlsError, WorkbookFormat, csvToWorkbook, detectWorkbookFormat, loadLegacyXls, loadWorkbook, parseCsv, saveWorkbook, sheetToCsv } from '@christophervr/xlsx-core/load';
10
+ import * as svelte_store from 'svelte/store';
6
11
 
7
12
  /** Editor state a framework passes down as props. */
8
13
  interface EditorProps {
@@ -105,13 +110,160 @@ interface EditorBinding extends EditorHandle {
105
110
  */
106
111
  declare function deferredHandle(current: () => EditorBinding | null | undefined): EditorHandle;
107
112
  /** All framework adapters share property, event and lifecycle semantics here. */
108
- declare function mountEditor(host: HTMLElement, initial?: EditorOptions): EditorBinding;
113
+ declare function mountEditor(host: HTMLElement, initial?: EditorOptions, surfaceOnly?: boolean): EditorBinding;
109
114
  /**
110
115
  * The imperative handle every framework exposes (React ref, Vue template ref, Angular component
111
116
  * instance, Solid `editorRef`, Svelte component instance). `handle-keys.test.ts` checks each one.
112
117
  */
113
118
  declare const EDITOR_HANDLE_KEYS: readonly ["element", "load", "newWorkbook", "save", "saveBytes", "download", "markClean", "select", "getSelection", "setActiveSheet", "share", "dirty"];
114
119
  type EditorHandleKey = (typeof EDITOR_HANDLE_KEYS)[number];
120
+ /** Framework-neutral composition API, shared by every adapter. Choose before mount. */
121
+ interface SurfaceOptions extends EditorOptions, SurfaceHostActions {
122
+ canEdit?: boolean | undefined;
123
+ /** A cell edit in progress failed validation before formatting, navigation or saving. */
124
+ onValidationError?: ((detail: ValidationErrorDetail) => void) | undefined;
125
+ }
126
+ declare function mountEditorSurface(host: HTMLElement, initial?: SurfaceOptions): EditorBinding & {
127
+ update: (options: SurfaceOptions) => void;
128
+ destroy: () => void;
129
+ getToolbarProps: () => {
130
+ bold: boolean | null;
131
+ italic: boolean | null;
132
+ underline: boolean | null;
133
+ fontFamily: string | null;
134
+ fontSize: number | null;
135
+ alignment: string | null;
136
+ numberFormat: string | null;
137
+ formattingComplete: boolean;
138
+ enabled: {
139
+ bold: boolean;
140
+ italic: boolean;
141
+ underline: boolean;
142
+ fontFamily: boolean;
143
+ fontSize: boolean;
144
+ alignment: boolean;
145
+ numberFormat: boolean;
146
+ undo: boolean;
147
+ redo: boolean;
148
+ openShareDialog: boolean;
149
+ settings: boolean;
150
+ formatCells: boolean;
151
+ findReplace: boolean;
152
+ insertFunction: boolean;
153
+ };
154
+ labels: {
155
+ [k: string]: string;
156
+ };
157
+ options: {
158
+ fontFamilies: string[];
159
+ fontSizes: number[];
160
+ alignments: {
161
+ value: "center" | "left" | "right";
162
+ label: string;
163
+ }[];
164
+ numberFormats: {
165
+ value: string;
166
+ label: string;
167
+ }[];
168
+ };
169
+ canEdit: boolean;
170
+ dirty: boolean;
171
+ collaboration: ooxml_core_collab.CollaborationState;
172
+ editError: string | null;
173
+ selection: string;
174
+ activeCell: string;
175
+ activeSheet: number;
176
+ editing: boolean;
177
+ editMode: ooxml_core_xlsx_ui.EditMode;
178
+ formulaCaret: number;
179
+ sheets: {
180
+ name: string;
181
+ index: number;
182
+ state: ooxml_core_xlsx.SheetState;
183
+ }[];
184
+ canUndo: boolean;
185
+ canRedo: boolean;
186
+ formula: string;
187
+ onBold: () => Promise<boolean>;
188
+ onItalic: () => Promise<boolean>;
189
+ onUnderline: () => Promise<boolean>;
190
+ onFontFamilyChange: (family: string) => Promise<boolean>;
191
+ onFontSizeChange: (size: number) => Promise<boolean>;
192
+ onNumberFormatChange: (format: string) => Promise<boolean>;
193
+ onAlignmentChange: (alignment: ooxml_core_xlsx.HorizontalAlignment) => Promise<boolean>;
194
+ onUndo: () => Promise<boolean>;
195
+ onRedo: () => Promise<boolean>;
196
+ onOpenShareDialog: () => Promise<boolean>;
197
+ onOpenSettings: () => Promise<boolean>;
198
+ onOpenFormatCells: () => Promise<boolean>;
199
+ onOpenFindReplace: () => Promise<boolean>;
200
+ onOpenInsertFunction: () => Promise<boolean>;
201
+ onSelect: (ref: string) => boolean;
202
+ onSheetChange: (index: number) => boolean;
203
+ onFormulaInput: (text: string, caret?: number) => boolean;
204
+ onFormulaChange: (text: string) => boolean;
205
+ onCancelEdit: () => void;
206
+ commitEdit: () => boolean;
207
+ };
208
+ subscribe: (listener: () => void) => () => void;
209
+ };
210
+
211
+ type BuildingBlockOptions = SurfaceOptions;
212
+ interface BuildingBlockState {
213
+ toolbarProps: SpreadsheetToolbarProps | null;
214
+ loading: boolean;
215
+ error: Error | null;
216
+ mode: 'view' | 'edit';
217
+ /** Unsaved changes since the last load, save or `markClean()`. */
218
+ dirty: boolean;
219
+ /** The selection as A1 text. */
220
+ selection: string;
221
+ /** Sharing state of the open workbook. */
222
+ collaboration: XlsxCollaborationState;
223
+ /** The validation message of the cell edit in progress, or null. */
224
+ editError: string | null;
225
+ }
226
+ interface ToolbarButtonModel {
227
+ kind: 'button';
228
+ id: string;
229
+ label: string;
230
+ /** true or false, or null for a mixed selection. */
231
+ pressed: boolean | null;
232
+ disabled: boolean;
233
+ run: () => Promise<boolean>;
234
+ }
235
+ interface ToolbarSelectModel {
236
+ kind: 'select';
237
+ id: string;
238
+ label: string;
239
+ /** The current value; '' when the selection is mixed. */
240
+ value: string;
241
+ disabled: boolean;
242
+ options: {
243
+ value: string;
244
+ label: string;
245
+ }[];
246
+ change: (value: string) => Promise<boolean>;
247
+ }
248
+ type ToolbarItemModel = ToolbarButtonModel | ToolbarSelectModel;
249
+ /** Every control the props support, in display order, for a framework to map onto its template. */
250
+ declare function toolbarModel(p: SpreadsheetToolbarProps): ToolbarItemModel[];
251
+ declare function selectReference(p: SpreadsheetToolbarProps, value: string): boolean;
252
+
253
+ type BuildingBlockKind = 'toolbar' | 'formula-bar' | 'tabs';
254
+ /** Lazy lookup keeps existing viewer imports compatible with an older Office UI runtime. */
255
+ declare function prepareBlock(value: unknown, kind: BuildingBlockKind): void;
256
+
257
+ /** Create during component initialization; use $blocks for state and $effect(() => blocks.update(options)). */
258
+ declare function createViewerBuildingBlocks(initial?: BuildingBlockOptions): {
259
+ subscribe: (this: void, run: svelte_store.Subscriber<BuildingBlockState>, invalidate?: () => void) => svelte_store.Unsubscriber;
260
+ update: (next: BuildingBlockOptions) => void;
261
+ handle: EditorHandle;
262
+ canvasProps: {
263
+ mount: (host: HTMLElement | null) => void;
264
+ };
265
+ destroy: () => void;
266
+ };
115
267
 
116
- export { EDITOR_EVENT_NAMES, EDITOR_HANDLE_KEYS, EDITOR_PROP_KEYS, deferredHandle, eventOptions, mountEditor, pickEditorProps };
117
- export type { EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorHandleKey, EditorOptions, EditorPropKey, EditorProps };
268
+ export { EDITOR_EVENT_NAMES, EDITOR_HANDLE_KEYS, EDITOR_PROP_KEYS, createViewerBuildingBlocks, deferredHandle, eventOptions, mountEditor, mountEditorSurface, pickEditorProps, prepareBlock, selectReference, toolbarModel };
269
+ export type { BuildingBlockOptions, BuildingBlockState, EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorHandleKey, EditorOptions, EditorPropKey, EditorProps, SurfaceOptions };
package/dist/runtime.js CHANGED
@@ -1,42 +1,45 @@
1
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";
2
5
  export * from "ooxml-ui/xlsx";
3
6
  export * from "@christophervr/xlsx-core";
4
7
  //#region \0rolldown/runtime.js
5
- var c = Object.defineProperty, l = Object.getOwnPropertyDescriptor, u = Object.getOwnPropertyNames, d = Object.prototype.hasOwnProperty, f = (e, t) => {
8
+ var d = Object.defineProperty, f = Object.getOwnPropertyDescriptor, p = Object.getOwnPropertyNames, m = Object.prototype.hasOwnProperty, h = (e, t) => {
6
9
  let n = {};
7
- for (var r in e) c(n, r, {
10
+ for (var r in e) d(n, r, {
8
11
  get: e[r],
9
12
  enumerable: !0
10
13
  });
11
- return t || c(n, Symbol.toStringTag, { value: "Module" }), n;
12
- }, p = (e, t, n, r) => {
13
- if (t && typeof t == "object" || typeof t == "function") for (var i = u(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !d.call(e, s) && s !== n && c(e, s, {
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, {
14
17
  get: ((e) => t[e]).bind(null, s),
15
- enumerable: !(r = l(t, s)) || r.enumerable
18
+ enumerable: !(r = f(t, s)) || r.enumerable
16
19
  });
17
20
  return e;
18
- }, m = (e, t, n) => (p(e, t, "default"), n && p(n, t, "default")), h = /* @__PURE__ */ f({});
19
- import * as g from "ooxml-ui/xlsx";
20
- m(h, g);
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);
21
24
  //#endregion
22
25
  //#region packages/bindings/src/forwarding.ts
23
- function _(e, t) {
26
+ function b(e, t) {
24
27
  if (e === t) return !0;
25
28
  let n = e ?? [], r = t ?? [];
26
29
  return n.length === r.length && n.every((e, t) => e === r[t]);
27
30
  }
28
- function v(e, t) {
31
+ function x(e, t) {
29
32
  if (e === t) return !0;
30
33
  let n = { ...e }, r = { ...t }, i = Object.keys(n);
31
34
  return i.length === Object.keys(r).length && i.every((e) => n[e] === r[e]);
32
35
  }
33
- function y() {
36
+ function S() {
34
37
  let e = /* @__PURE__ */ new Map();
35
38
  return function(t, n, r = Object.is) {
36
39
  return e.has(t) && r(e.get(t), n) ? !1 : (e.set(t, n), !0);
37
40
  };
38
41
  }
39
- function b(e) {
42
+ function C(e) {
40
43
  let t = e.split(/[?#]/u)[0]?.split("/").pop();
41
44
  if (t) try {
42
45
  return decodeURIComponent(t);
@@ -44,7 +47,7 @@ function b(e) {
44
47
  return t;
45
48
  }
46
49
  }
47
- function x(e, t) {
50
+ function w(e, t) {
48
51
  let n = 0, r, i = () => {
49
52
  n++, r?.abort(), r = void 0;
50
53
  };
@@ -58,7 +61,7 @@ function x(e, t) {
58
61
  Promise.resolve().then(() => fetch(a, c ? { signal: c.signal } : void 0)).then(async (e) => {
59
62
  if (!e.ok) throw Error(`Could not fetch ${a}: HTTP ${e.status}`);
60
63
  return new Uint8Array(await e.arrayBuffer());
61
- }).then((t) => l() ? e(t, o ?? b(a)) : void 0).catch((e) => {
64
+ }).then((t) => l() ? e(t, o ?? C(a)) : void 0).catch((e) => {
62
65
  l() && t(e);
63
66
  });
64
67
  }
@@ -66,7 +69,7 @@ function x(e, t) {
66
69
  }
67
70
  //#endregion
68
71
  //#region packages/bindings/src/index.ts
69
- var S = [
72
+ var T = [
70
73
  "workbook",
71
74
  "bytes",
72
75
  "src",
@@ -81,7 +84,7 @@ var S = [
81
84
  "ribbonAddIns",
82
85
  "themeColors",
83
86
  "collaboration"
84
- ], C = [
87
+ ], E = [
85
88
  "workbook-change",
86
89
  "workbook-error",
87
90
  "selection-change",
@@ -91,15 +94,15 @@ var S = [
91
94
  "office-ribbon-add-in",
92
95
  "collaboration-change"
93
96
  ];
94
- function w(e, t, n) {
97
+ function D(e, t, n) {
95
98
  e[n] = t[n];
96
99
  }
97
- function T(e) {
100
+ function O(e) {
98
101
  let t = {};
99
- for (let n of S) w(t, e, n);
102
+ for (let n of T) D(t, e, n);
100
103
  return t;
101
104
  }
102
- function E(e) {
105
+ function k(e) {
103
106
  return {
104
107
  onWorkbookChange: e["workbook-change"],
105
108
  onWorkbookError: e["workbook-error"],
@@ -112,7 +115,7 @@ function E(e) {
112
115
  onReady: e.ready
113
116
  };
114
117
  }
115
- function D(e) {
118
+ function A(e) {
116
119
  let t = () => {
117
120
  let t = e();
118
121
  if (!t) throw Error("Editor is not mounted");
@@ -137,53 +140,56 @@ function D(e) {
137
140
  }
138
141
  };
139
142
  }
140
- function O(e, t = {}) {
141
- (0, h.defineXlsxEditor)();
142
- let n = e.ownerDocument.createElement("xlsx-editor"), r = {}, i, a, o, s, c = !1, l = y(), u = (e) => {
143
- c || r.onWorkbookError?.(e instanceof Error ? e : Error(String(e)));
144
- }, d = (e, t) => n.load(e, t).catch(() => void 0), f = x(d, u), p = {
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 = {
145
151
  "workbook-change": (e) => {
146
- a = e.detail.workbook, r.onWorkbookChange?.(a);
152
+ o = e.detail.workbook, i.onWorkbookChange?.(o);
147
153
  },
148
- "workbook-error": (e) => r.onWorkbookError?.(e.detail.error),
149
- "selection-change": (e) => r.onSelectionChange?.(e.detail),
150
- "dirty-change": (e) => r.onDirtyChange?.(e.detail.dirty),
151
- "readonly-change": (e) => r.onReadOnlyChange?.(e.detail.readOnly),
152
- "ribbon-customize": (e) => r.onRibbonCustomize?.([...e.detail.hiddenActions]),
153
- "office-ribbon-add-in": (e) => r.onRibbonAddIn?.(e.detail),
154
- "collaboration-change": (e) => r.onCollaborationChange?.(e.detail)
155
- }, m = (e) => {
156
- for (let t of C) {
157
- let r = p[t];
158
- e ? n.addEventListener(t, r) : n.removeEventListener(t, r);
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);
159
165
  }
160
166
  };
161
- m(!0);
167
+ h(!0);
162
168
  let g = {
163
- element: n,
169
+ element: r,
164
170
  update(e) {
165
- c || (r = e, l("locale", e.locale) && (n.locale = e.locale ?? "en"), l("readOnly", e.readOnly) && (n.readOnly = e.readOnly ?? !1), l("theme", e.theme) && (n.theme = e.theme ?? "auto"), l("authorName", e.authorName) && (n.authorName = e.authorName ?? "Author"), l("showToolbar", e.showToolbar) && (n.showToolbar = e.showToolbar ?? !0), l("showFormulaBar", e.showFormulaBar) && (n.showFormulaBar = e.showFormulaBar ?? !0), l("hiddenActions", e.hiddenActions, _) && (n.hiddenActions = [...e.hiddenActions ?? []]), l("ribbonAddIns", e.ribbonAddIns) && (n.ribbonAddIns = e.ribbonAddIns ?? []), l("themeColors", e.themeColors, v) && (n.themeColors = { ...e.themeColors }), l("fileName", e.fileName) && e.fileName !== void 0 && (n.fileName = e.fileName), l("collaboration", e.collaboration ?? null) && (n.collaboration = e.collaboration ?? null), e.workbook && e.workbook !== i && e.workbook !== a && (f.cancel(), n.workbook = e.workbook), i = e.workbook, e.bytes && e.bytes !== o && (f.cancel(), d(e.bytes, e.fileName)), o = e.bytes, e.src && e.src !== s ? f.fetch(e.src, e.fileName) : !e.src && s && f.cancel(), s = e.src);
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);
166
172
  },
167
- load: (e, t) => (f.cancel(), n.load(e, t)),
168
- newWorkbook: () => n.newWorkbook(),
169
- save: () => n.save(),
170
- saveBytes: (e) => n.saveBytes(e),
171
- download: (e) => n.download(e),
172
- markClean: () => n.markClean(),
173
- select: (e) => n.select(e),
174
- getSelection: () => n.getSelection(),
175
- setActiveSheet: (e) => n.setActiveSheet(e),
176
- share: () => n.share(),
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(),
177
183
  get dirty() {
178
- return n.dirty;
184
+ return r.dirty;
179
185
  },
180
186
  destroy() {
181
- c || (c = !0, f.cancel(), typeof n.stopCollaboration == "function" && n.stopCollaboration(), m(!1), n.remove());
187
+ l || (l = !0, p.cancel(), typeof r.stopCollaboration == "function" && r.stopCollaboration(), h(!1), r.remove());
182
188
  }
183
189
  };
184
- return g.update(t), e.append(n), r.onReady?.(n), g;
190
+ return g.update(t), e.append(r), i.onReady?.(r), g;
185
191
  }
186
- var k = [
192
+ var M = [
187
193
  "element",
188
194
  "load",
189
195
  "newWorkbook",
@@ -196,32 +202,207 @@ var k = [
196
202
  "setActiveSheet",
197
203
  "share",
198
204
  "dirty"
199
- ], A = /* @__PURE__ */ f({
205
+ ], N = [
206
+ "onOpenShareDialog",
207
+ "onOpenSettings",
208
+ "onOpenFormatCells",
209
+ "onOpenFindReplace",
210
+ "onOpenInsertFunction"
211
+ ];
212
+ function P(e, t = {}) {
213
+ let n = t, r = (e) => ({
214
+ ...e,
215
+ readOnly: e.canEdit !== !0 || e.readOnly === !0
216
+ }), i = j(e, r(t), !0), { element: a } = i, o = i.update, s = i.destroy, c = {}, l = (e) => {
217
+ if (N.every((t) => c[t] === e[t])) return;
218
+ let t = {};
219
+ for (let n of N) t[n] = e[n];
220
+ c = t, a.surfaceActions = t;
221
+ }, u = (e) => n.onValidationError?.(e.detail);
222
+ return a.addEventListener("validation-error", u), l(t), Object.assign(i, {
223
+ update: (e) => {
224
+ n = e, l(e), o(r(e));
225
+ },
226
+ destroy: () => {
227
+ a.removeEventListener("validation-error", u), s();
228
+ },
229
+ getToolbarProps: () => a.getToolbarProps(),
230
+ subscribe: (e) => a.subscribeEditorState(e)
231
+ });
232
+ }
233
+ //#endregion
234
+ //#region packages/bindings/src/common.ts
235
+ var F = /* @__PURE__ */ h({
200
236
  LegacyXlsError: () => e,
201
237
  csvToWorkbook: () => t,
202
238
  detectWorkbookFormat: () => n,
203
239
  loadLegacyXls: () => r,
204
240
  loadWorkbook: () => i,
241
+ mountEditorSurface: () => P,
205
242
  parseCsv: () => a,
206
243
  saveWorkbook: () => o,
207
244
  sheetToCsv: () => s
208
245
  });
209
- m(A, h), m(/* @__PURE__ */ f({
210
- EDITOR_EVENT_NAMES: () => C,
211
- EDITOR_HANDLE_KEYS: () => k,
212
- EDITOR_PROP_KEYS: () => S,
246
+ _(F, v);
247
+ //#endregion
248
+ //#region packages/bindings/src/building-blocks.ts
249
+ var I = Object.freeze({
250
+ active: !1,
251
+ roomId: void 0,
252
+ status: "off",
253
+ synced: !1,
254
+ people: []
255
+ });
256
+ function L(e) {
257
+ return {
258
+ dirty: e?.dirty ?? !1,
259
+ selection: e?.selection ?? "",
260
+ collaboration: e?.collaboration ?? I,
261
+ editError: e?.editError ?? null
262
+ };
263
+ }
264
+ function R(e) {
265
+ let t = null, n, r, i = {}, a = null, o = !1, s = () => {
266
+ let t = n?.element.loading ?? !1;
267
+ t && !o && (a = null), o = t;
268
+ let r = n?.getToolbarProps() ?? null;
269
+ e({
270
+ toolbarProps: r,
271
+ loading: n?.element.loading ?? !1,
272
+ error: a,
273
+ mode: i.canEdit !== !0 || i.readOnly ? "view" : "edit",
274
+ ...L(r)
275
+ });
276
+ }, c = () => ({
277
+ ...i,
278
+ onWorkbookError: (e) => {
279
+ a = e, o = n?.element.loading ?? !1, s(), i.onWorkbookError?.(e);
280
+ }
281
+ }), l = () => {
282
+ t = null, r?.(), r = void 0, n?.destroy(), n = void 0, s();
283
+ };
284
+ return {
285
+ handle: A(() => n),
286
+ mount(e) {
287
+ e && e === t || (l(), e && (a = null, n = P(e, c()), t = e, r = n.subscribe(s), s()));
288
+ },
289
+ update(e) {
290
+ (e.workbook !== i.workbook || e.bytes !== i.bytes || e.src !== i.src) && (a = null), i = e, n?.update(c()), s();
291
+ },
292
+ destroy: l
293
+ };
294
+ }
295
+ var z = () => ({
296
+ toolbarProps: null,
297
+ loading: !1,
298
+ error: null,
299
+ mode: "view",
300
+ ...L(null)
301
+ }), B = (e, t) => t === null ? [{
302
+ value: "",
303
+ label: ""
304
+ }, ...e] : e.some((e) => e.value === t) ? e : [{
305
+ value: t,
306
+ label: t
307
+ }, ...e];
308
+ function V(e) {
309
+ let t = (t) => e.labels[t] ?? t, n = (t) => !e.canEdit || !t, r = (e, t, n, r, i) => ({
310
+ kind: "button",
311
+ id: e,
312
+ label: t,
313
+ pressed: n,
314
+ disabled: r,
315
+ run: i
316
+ });
317
+ return [
318
+ r("undo", t("Undo"), !1, !e.enabled.undo, e.onUndo),
319
+ r("redo", t("Redo"), !1, !e.enabled.redo, e.onRedo),
320
+ {
321
+ kind: "select",
322
+ id: "fontFamily",
323
+ label: t("Font"),
324
+ value: e.fontFamily ?? "",
325
+ disabled: n(e.enabled.fontFamily),
326
+ options: B(e.options.fontFamilies.map((e) => ({
327
+ value: e,
328
+ label: e
329
+ })), e.fontFamily),
330
+ change: (t) => e.onFontFamilyChange(t)
331
+ },
332
+ {
333
+ kind: "select",
334
+ id: "fontSize",
335
+ label: t("Font Size"),
336
+ value: e.fontSize === null ? "" : String(e.fontSize),
337
+ disabled: n(e.enabled.fontSize),
338
+ options: B(e.options.fontSizes.map((e) => ({
339
+ value: String(e),
340
+ label: String(e)
341
+ })), e.fontSize === null ? null : String(e.fontSize)),
342
+ change: (t) => e.onFontSizeChange(Number(t))
343
+ },
344
+ r("bold", t("Bold"), e.bold, n(e.enabled.bold), e.onBold),
345
+ r("italic", t("Italic"), e.italic, n(e.enabled.italic), e.onItalic),
346
+ r("underline", t("Underline"), e.underline, n(e.enabled.underline), e.onUnderline),
347
+ ...e.options.alignments.map((t) => r(`align-${t.value}`, t.label, e.alignment === null ? null : e.alignment === t.value, n(e.enabled.alignment), () => e.onAlignmentChange(t.value))),
348
+ {
349
+ kind: "select",
350
+ id: "numberFormat",
351
+ label: t("Number Format"),
352
+ value: e.numberFormat ?? "",
353
+ disabled: n(e.enabled.numberFormat),
354
+ options: B(e.options.numberFormats, e.numberFormat),
355
+ change: (t) => e.onNumberFormatChange(t)
356
+ }
357
+ ];
358
+ }
359
+ function H(e, t) {
360
+ try {
361
+ return e.onSelect(t);
362
+ } catch {
363
+ return !1;
364
+ }
365
+ }
366
+ //#endregion
367
+ //#region packages/bindings/src/block-theme.ts
368
+ function U(e, t) {
369
+ if (!e || typeof e != "object" || !("ownerDocument" in e)) return;
370
+ let n = e, r = Reflect.get(u, "prepareOfficeUiBlock");
371
+ typeof r == "function" ? r(n, t, "xlsx") : (u.installOfficeUiTheme(n.ownerDocument), n.setAttribute("data-office-block", t), n.setAttribute("data-office-product", "xlsx"));
372
+ }
373
+ //#endregion
374
+ //#region packages/svelte/src/building-blocks.ts
375
+ function W(e = {}) {
376
+ let t = l(z()), n = R(t.set);
377
+ return n.update(e), c(n.destroy), {
378
+ subscribe: t.subscribe,
379
+ update: n.update,
380
+ handle: n.handle,
381
+ canvasProps: { mount: n.mount },
382
+ destroy: n.destroy
383
+ };
384
+ }
385
+ _(/* @__PURE__ */ h({
386
+ EDITOR_EVENT_NAMES: () => E,
387
+ EDITOR_HANDLE_KEYS: () => M,
388
+ EDITOR_PROP_KEYS: () => T,
213
389
  LegacyXlsError: () => e,
390
+ createViewerBuildingBlocks: () => W,
214
391
  csvToWorkbook: () => t,
215
- deferredHandle: () => D,
392
+ deferredHandle: () => A,
216
393
  detectWorkbookFormat: () => n,
217
- eventOptions: () => E,
394
+ eventOptions: () => k,
218
395
  loadLegacyXls: () => r,
219
396
  loadWorkbook: () => i,
220
- mountEditor: () => O,
397
+ mountEditor: () => j,
398
+ mountEditorSurface: () => P,
221
399
  parseCsv: () => a,
222
- pickEditorProps: () => T,
400
+ pickEditorProps: () => O,
401
+ prepareBlock: () => U,
223
402
  saveWorkbook: () => o,
224
- sheetToCsv: () => s
225
- }), A);
403
+ selectReference: () => H,
404
+ sheetToCsv: () => s,
405
+ toolbarModel: () => V
406
+ }), F);
226
407
  //#endregion
227
- export { C as EDITOR_EVENT_NAMES, k as EDITOR_HANDLE_KEYS, S as EDITOR_PROP_KEYS, e as LegacyXlsError, t as csvToWorkbook, D as deferredHandle, n as detectWorkbookFormat, E as eventOptions, r as loadLegacyXls, i as loadWorkbook, O as mountEditor, a as parseCsv, T as pickEditorProps, o as saveWorkbook, s as sheetToCsv };
408
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xlsx-svelte-viewer",
3
- "version": "0.6.0",
3
+ "version": "1.0.0",
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",
@@ -40,15 +40,35 @@
40
40
  "types": "./dist/runtime.d.ts",
41
41
  "import": "./dist/runtime.js"
42
42
  },
43
- "./package.json": "./package.json"
43
+ "./package.json": "./package.json",
44
+ "./SpreadsheetCanvas.svelte": {
45
+ "types": "./dist/SpreadsheetCanvas.svelte.d.ts",
46
+ "svelte": "./dist/SpreadsheetCanvas.svelte",
47
+ "default": "./dist/SpreadsheetCanvas.svelte"
48
+ },
49
+ "./Toolbar.svelte": {
50
+ "types": "./dist/Toolbar.svelte.d.ts",
51
+ "svelte": "./dist/Toolbar.svelte",
52
+ "default": "./dist/Toolbar.svelte"
53
+ },
54
+ "./FormulaBar.svelte": {
55
+ "types": "./dist/FormulaBar.svelte.d.ts",
56
+ "svelte": "./dist/FormulaBar.svelte",
57
+ "default": "./dist/FormulaBar.svelte"
58
+ },
59
+ "./SheetTabs.svelte": {
60
+ "types": "./dist/SheetTabs.svelte.d.ts",
61
+ "svelte": "./dist/SheetTabs.svelte",
62
+ "default": "./dist/SheetTabs.svelte"
63
+ }
44
64
  },
45
65
  "publishConfig": {
46
66
  "access": "public"
47
67
  },
48
68
  "dependencies": {
49
- "@christophervr/xlsx-core": "^0.2.10",
50
- "ooxml-core": "^1.8.0",
51
- "ooxml-ui": "^1.8.0"
69
+ "@christophervr/xlsx-core": "^0.3.0",
70
+ "ooxml-core": "^1.22.0",
71
+ "ooxml-ui": "^1.21.0"
52
72
  },
53
73
  "peerDependencies": {
54
74
  "svelte": "^5.0.0"