xlsx-svelte-viewer 0.4.4 → 0.5.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.
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { deferredHandle, eventOptions, mountEditor, pickEditorProps, type EditorBinding, type EditorEventHandlers, type EditorProps } from './runtime.js';
2
+ import { deferredHandle, eventOptions, mountEditor, pickEditorProps, type EditorBinding, type EditorEventHandlers, type EditorProps, type EditorHandle } from './runtime.js';
3
3
  type Props = EditorProps & {
4
4
  onworkbookchange?: EditorEventHandlers['workbook-change'];
5
5
  onworkbookerror?: EditorEventHandlers['workbook-error'];
@@ -7,27 +7,40 @@
7
7
  ondirtychange?: EditorEventHandlers['dirty-change'];
8
8
  onreadonlychange?: EditorEventHandlers['readonly-change'];
9
9
  onribboncustomize?: EditorEventHandlers['ribbon-customize'];
10
+ oncollaborationchange?: EditorEventHandlers['collaboration-change'];
10
11
  onready?: EditorEventHandlers['ready'];
11
12
  };
12
- let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], themeColors, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onready }: Props = $props();
13
+ let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], themeColors, collaboration, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, oncollaborationchange, onready }: Props = $props();
13
14
  let binding: EditorBinding | undefined;
14
15
  const handle = deferredHandle(() => binding);
16
+ // Live `element` and `dirty`, the same handle vocabulary as the other frameworks (`EDITOR_HANDLE_KEYS`).
17
+ let mountedElement = $state.raw<EditorHandle['element'] | undefined>();
18
+ let dirtyState = $state(false);
19
+ const element = $derived(mountedElement);
20
+ const dirty = $derived(dirtyState);
15
21
  function attach(host: HTMLElement, options: Props) {
16
22
  const normalized = (value: Props) => ({ ...pickEditorProps(value),
17
- ...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, ready: value.onready }) });
18
- binding = mountEditor(host, normalized(options));
19
- return { update(next: Props) { binding?.update(normalized(next)); }, destroy() { binding?.destroy(); binding = undefined; } };
23
+ ...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, 'collaboration-change': value.oncollaborationchange, ready: value.onready }) });
24
+ const tracked = (value: Props) => normalized({ ...value, ondirtychange: (next: boolean) => { dirtyState = next; value.ondirtychange?.(next); } });
25
+ binding = mountEditor(host, tracked(options));
26
+ mountedElement = binding.element;
27
+ dirtyState = binding.dirty;
28
+ return { update(next: Props) { binding?.update(tracked(next)); }, destroy() { binding?.destroy(); binding = undefined; mountedElement = undefined; dirtyState = false; } };
20
29
  }
21
30
  export function load(input: Uint8Array | ArrayBuffer, name?: string) { return handle.load(input, name); }
22
31
  export function newWorkbook() { handle.newWorkbook(); }
23
32
  export function save() { return handle.save(); }
24
33
  export function saveBytes(format?: 'xlsx' | 'csv') { return handle.saveBytes(format); }
25
34
  export function download(name?: string) { return handle.download(name); }
26
- export function markClean() { handle.markClean(); }
35
+ export function markClean() { handle.markClean(); dirtyState = handle.dirty; }
27
36
  export function select(ref: string) { handle.select(ref); }
28
37
  export function getSelection() { return handle.getSelection(); }
29
38
  export function setActiveSheet(index: number) { handle.setActiveSheet(index); }
39
+ export function share() { handle.share(); }
40
+ /** @deprecated Read the dirty property instead. */
30
41
  export function isDirty() { return handle.dirty; }
42
+ /** @deprecated Read the element property instead. */
31
43
  export function getElement() { return binding?.element; }
44
+ export { element, dirty };
32
45
  </script>
33
- <div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, themeColors, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onready }}></div>
46
+ <div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, themeColors, collaboration, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, oncollaborationchange, onready }}></div>
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Component } from 'svelte';
2
2
  import type { EditorEventHandlers, EditorProps, XlsxEditorElement } from './runtime';
3
3
  type Props = EditorProps & { onworkbookchange?: EditorEventHandlers['workbook-change']; onworkbookerror?: EditorEventHandlers['workbook-error']; onselectionchange?: EditorEventHandlers['selection-change']; ondirtychange?: EditorEventHandlers['dirty-change']; onready?: EditorEventHandlers['ready'] };
4
- type Exports = { load(input: Uint8Array | ArrayBuffer, fileName?: string): Promise<void>; newWorkbook(): void; save(): Promise<Blob>; saveBytes(format?: 'xlsx' | 'csv'): Promise<Uint8Array>; download(fileName?: string): Promise<void>; markClean(): void; select(ref: string): void; getSelection(): string; setActiveSheet(index: number): void; isDirty(): boolean; getElement(): XlsxEditorElement | undefined };
4
+ type Exports = { load(input: Uint8Array | ArrayBuffer, fileName?: string): Promise<void>; newWorkbook(): void; save(): Promise<Blob>; saveBytes(format?: 'xlsx' | 'csv'): Promise<Uint8Array>; download(fileName?: string): Promise<void>; markClean(): void; select(ref: string): void; getSelection(): string; setActiveSheet(index: number): void; /** @deprecated Use dirty. */ isDirty(): boolean; /** @deprecated Use element. */ getElement(): XlsxEditorElement | undefined; readonly element: XlsxEditorElement | undefined; readonly dirty: boolean };
5
5
  declare const XlsxEditor: Component<Props, Exports>;
6
6
  export default XlsxEditor;
package/dist/runtime.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { XlsxEditorElement, EditorLocaleInput, EditorThemeMode, XlsxThemeColors, SelectionChangeDetail } from 'ooxml-ui/xlsx';
1
+ import { XlsxEditorElement, EditorLocaleInput, EditorThemeMode, XlsxThemeColors, XlsxCollaborationOptions, SelectionChangeDetail, XlsxCollaborationState } from 'ooxml-ui/xlsx';
2
2
  export * from 'ooxml-ui/xlsx';
3
3
  import { Workbook } from '@christophervr/xlsx-core';
4
4
  export * from '@christophervr/xlsx-core';
@@ -29,6 +29,11 @@ interface EditorProps {
29
29
  hiddenActions?: readonly string[] | undefined;
30
30
  /** Theme token overrides, applied as `--xve-*` custom properties. */
31
31
  themeColors?: XlsxThemeColors | undefined;
32
+ /**
33
+ * Shares the open workbook in a room while set (room id, server URL or provider, user name and
34
+ * colour); forwarded when a new object is passed, and `undefined` or `null` leaves the room.
35
+ */
36
+ collaboration?: XlsxCollaborationOptions | null | undefined;
32
37
  }
33
38
  /** Editor callbacks; each is the framework-neutral form of one entry in `EDITOR_EVENT_NAMES`. */
34
39
  interface EditorEventOptions {
@@ -40,16 +45,18 @@ interface EditorEventOptions {
40
45
  onReadOnlyChange?: ((readOnly: boolean) => void) | undefined;
41
46
  /** The user changed the shown ribbon commands (File > Options > Customize Ribbon). */
42
47
  onRibbonCustomize?: ((hiddenActions: string[]) => void) | undefined;
48
+ /** Sharing started or stopped, the connection changed, or someone joined or left. */
49
+ onCollaborationChange?: ((state: XlsxCollaborationState) => void) | undefined;
43
50
  /** Called once, after the element is created and attached. */
44
51
  onReady?: ((element: XlsxEditorElement) => void) | undefined;
45
52
  }
46
53
  interface EditorOptions extends EditorProps, EditorEventOptions {
47
54
  }
48
55
  /** Single source of truth for the prop keys every adapter forwards. */
49
- declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "themeColors"];
56
+ declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "themeColors", "collaboration"];
50
57
  type EditorPropKey = (typeof EDITOR_PROP_KEYS)[number];
51
58
  /** Single source of truth for the element events every adapter surfaces. */
52
- declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "ribbon-customize"];
59
+ declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "ribbon-customize", "collaboration-change"];
53
60
  type EditorEventName = (typeof EDITOR_EVENT_NAMES)[number];
54
61
  /** One handler per bound event (unwrapped payload); a missing key is a compile error in every adapter. */
55
62
  interface EditorEventHandlers {
@@ -59,6 +66,7 @@ interface EditorEventHandlers {
59
66
  'dirty-change': EditorEventOptions['onDirtyChange'];
60
67
  'readonly-change': EditorEventOptions['onReadOnlyChange'];
61
68
  'ribbon-customize': EditorEventOptions['onRibbonCustomize'];
69
+ 'collaboration-change': EditorEventOptions['onCollaborationChange'];
62
70
  ready?: EditorEventOptions['onReady'];
63
71
  }
64
72
  /** Copies exactly the shared props out of a framework's props/instance object. */
@@ -78,6 +86,8 @@ interface EditorHandle {
78
86
  select(ref: string): void;
79
87
  getSelection(): string;
80
88
  setActiveSheet(index: number): void;
89
+ /** Opens File > Share, where the user starts or stops sharing the workbook. */
90
+ share(): void;
81
91
  readonly dirty: boolean;
82
92
  }
83
93
  interface EditorBinding extends EditorHandle {
@@ -91,6 +101,12 @@ interface EditorBinding extends EditorHandle {
91
101
  declare function deferredHandle(current: () => EditorBinding | null | undefined): EditorHandle;
92
102
  /** All framework adapters share property, event and lifecycle semantics here. */
93
103
  declare function mountEditor(host: HTMLElement, initial?: EditorOptions): EditorBinding;
104
+ /**
105
+ * The imperative handle every framework exposes (React ref, Vue template ref, Angular component
106
+ * instance, Solid `editorRef`, Svelte component instance). `handle-keys.test.ts` checks each one.
107
+ */
108
+ declare const EDITOR_HANDLE_KEYS: readonly ["element", "load", "newWorkbook", "save", "saveBytes", "download", "markClean", "select", "getSelection", "setActiveSheet", "share", "dirty"];
109
+ type EditorHandleKey = (typeof EDITOR_HANDLE_KEYS)[number];
94
110
 
95
- export { EDITOR_EVENT_NAMES, EDITOR_PROP_KEYS, deferredHandle, eventOptions, mountEditor, pickEditorProps };
96
- export type { EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorOptions, EditorPropKey, EditorProps };
111
+ export { EDITOR_EVENT_NAMES, EDITOR_HANDLE_KEYS, EDITOR_PROP_KEYS, deferredHandle, eventOptions, mountEditor, pickEditorProps };
112
+ export type { EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorHandleKey, EditorOptions, EditorPropKey, EditorProps };
package/dist/runtime.js CHANGED
@@ -78,14 +78,16 @@ var S = [
78
78
  "showToolbar",
79
79
  "showFormulaBar",
80
80
  "hiddenActions",
81
- "themeColors"
81
+ "themeColors",
82
+ "collaboration"
82
83
  ], C = [
83
84
  "workbook-change",
84
85
  "workbook-error",
85
86
  "selection-change",
86
87
  "dirty-change",
87
88
  "readonly-change",
88
- "ribbon-customize"
89
+ "ribbon-customize",
90
+ "collaboration-change"
89
91
  ];
90
92
  function w(e, t, n) {
91
93
  e[n] = t[n];
@@ -103,6 +105,7 @@ function E(e) {
103
105
  onDirtyChange: e["dirty-change"],
104
106
  onReadOnlyChange: e["readonly-change"],
105
107
  onRibbonCustomize: e["ribbon-customize"],
108
+ onCollaborationChange: e["collaboration-change"],
106
109
  onReady: e.ready
107
110
  };
108
111
  }
@@ -125,6 +128,7 @@ function D(e) {
125
128
  select: (e) => t().select(e),
126
129
  getSelection: () => t().getSelection(),
127
130
  setActiveSheet: (e) => t().setActiveSheet(e),
131
+ share: () => t().share(),
128
132
  get dirty() {
129
133
  return e()?.dirty ?? !1;
130
134
  }
@@ -142,7 +146,8 @@ function O(e, t = {}) {
142
146
  "selection-change": (e) => r.onSelectionChange?.(e.detail),
143
147
  "dirty-change": (e) => r.onDirtyChange?.(e.detail.dirty),
144
148
  "readonly-change": (e) => r.onReadOnlyChange?.(e.detail.readOnly),
145
- "ribbon-customize": (e) => r.onRibbonCustomize?.([...e.detail.hiddenActions])
149
+ "ribbon-customize": (e) => r.onRibbonCustomize?.([...e.detail.hiddenActions]),
150
+ "collaboration-change": (e) => r.onCollaborationChange?.(e.detail)
146
151
  }, m = (e) => {
147
152
  for (let t of C) {
148
153
  let r = p[t];
@@ -153,7 +158,7 @@ function O(e, t = {}) {
153
158
  let g = {
154
159
  element: n,
155
160
  update(e) {
156
- 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("themeColors", e.themeColors, v) && (n.themeColors = { ...e.themeColors }), l("fileName", e.fileName) && e.fileName !== void 0 && (n.fileName = e.fileName), 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);
161
+ 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("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);
157
162
  },
158
163
  load: (e, t) => (f.cancel(), n.load(e, t)),
159
164
  newWorkbook: () => n.newWorkbook(),
@@ -164,18 +169,30 @@ function O(e, t = {}) {
164
169
  select: (e) => n.select(e),
165
170
  getSelection: () => n.getSelection(),
166
171
  setActiveSheet: (e) => n.setActiveSheet(e),
172
+ share: () => n.share(),
167
173
  get dirty() {
168
174
  return n.dirty;
169
175
  },
170
176
  destroy() {
171
- c || (c = !0, f.cancel(), m(!1), n.remove());
177
+ c || (c = !0, f.cancel(), typeof n.stopCollaboration == "function" && n.stopCollaboration(), m(!1), n.remove());
172
178
  }
173
179
  };
174
180
  return g.update(t), e.append(n), r.onReady?.(n), g;
175
181
  }
176
- //#endregion
177
- //#region packages/bindings/src/common.ts
178
- var k = /* @__PURE__ */ f({
182
+ var k = [
183
+ "element",
184
+ "load",
185
+ "newWorkbook",
186
+ "save",
187
+ "saveBytes",
188
+ "download",
189
+ "markClean",
190
+ "select",
191
+ "getSelection",
192
+ "setActiveSheet",
193
+ "share",
194
+ "dirty"
195
+ ], A = /* @__PURE__ */ f({
179
196
  LegacyXlsError: () => e,
180
197
  csvToWorkbook: () => t,
181
198
  detectWorkbookFormat: () => n,
@@ -185,8 +202,9 @@ var k = /* @__PURE__ */ f({
185
202
  saveWorkbook: () => o,
186
203
  sheetToCsv: () => s
187
204
  });
188
- m(k, h), m(/* @__PURE__ */ f({
205
+ m(A, h), m(/* @__PURE__ */ f({
189
206
  EDITOR_EVENT_NAMES: () => C,
207
+ EDITOR_HANDLE_KEYS: () => k,
190
208
  EDITOR_PROP_KEYS: () => S,
191
209
  LegacyXlsError: () => e,
192
210
  csvToWorkbook: () => t,
@@ -200,6 +218,6 @@ m(k, h), m(/* @__PURE__ */ f({
200
218
  pickEditorProps: () => T,
201
219
  saveWorkbook: () => o,
202
220
  sheetToCsv: () => s
203
- }), k);
221
+ }), A);
204
222
  //#endregion
205
- export { C as EDITOR_EVENT_NAMES, 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 };
223
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xlsx-svelte-viewer",
3
- "version": "0.4.4",
3
+ "version": "0.5.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",
@@ -46,9 +46,9 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@christophervr/xlsx-core": "^0.2.7",
50
- "ooxml-core": "^0.24.0",
51
- "ooxml-ui": "^0.31.0"
49
+ "@christophervr/xlsx-core": "^0.2.9",
50
+ "ooxml-core": "^1.2.0",
51
+ "ooxml-ui": "^1.2.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "svelte": "^5.0.0"