xlsx-svelte-viewer 0.4.3 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/XlsxEditor.svelte +15 -4
- package/dist/index.d.ts +1 -1
- package/dist/runtime.d.ts +8 -2
- package/dist/runtime.js +17 -6
- package/package.json +4 -4
package/dist/XlsxEditor.svelte
CHANGED
|
@@ -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'];
|
|
@@ -12,22 +12,33 @@
|
|
|
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
13
|
let binding: EditorBinding | undefined;
|
|
14
14
|
const handle = deferredHandle(() => binding);
|
|
15
|
+
// Live `element` and `dirty`, the same handle vocabulary as the other frameworks (`EDITOR_HANDLE_KEYS`).
|
|
16
|
+
let mountedElement = $state.raw<EditorHandle['element'] | undefined>();
|
|
17
|
+
let dirtyState = $state(false);
|
|
18
|
+
const element = $derived(mountedElement);
|
|
19
|
+
const dirty = $derived(dirtyState);
|
|
15
20
|
function attach(host: HTMLElement, options: Props) {
|
|
16
21
|
const normalized = (value: Props) => ({ ...pickEditorProps(value),
|
|
17
22
|
...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
|
-
|
|
19
|
-
|
|
23
|
+
const tracked = (value: Props) => normalized({ ...value, ondirtychange: (next: boolean) => { dirtyState = next; value.ondirtychange?.(next); } });
|
|
24
|
+
binding = mountEditor(host, tracked(options));
|
|
25
|
+
mountedElement = binding.element;
|
|
26
|
+
dirtyState = binding.dirty;
|
|
27
|
+
return { update(next: Props) { binding?.update(tracked(next)); }, destroy() { binding?.destroy(); binding = undefined; mountedElement = undefined; dirtyState = false; } };
|
|
20
28
|
}
|
|
21
29
|
export function load(input: Uint8Array | ArrayBuffer, name?: string) { return handle.load(input, name); }
|
|
22
30
|
export function newWorkbook() { handle.newWorkbook(); }
|
|
23
31
|
export function save() { return handle.save(); }
|
|
24
32
|
export function saveBytes(format?: 'xlsx' | 'csv') { return handle.saveBytes(format); }
|
|
25
33
|
export function download(name?: string) { return handle.download(name); }
|
|
26
|
-
export function markClean() { handle.markClean(); }
|
|
34
|
+
export function markClean() { handle.markClean(); dirtyState = handle.dirty; }
|
|
27
35
|
export function select(ref: string) { handle.select(ref); }
|
|
28
36
|
export function getSelection() { return handle.getSelection(); }
|
|
29
37
|
export function setActiveSheet(index: number) { handle.setActiveSheet(index); }
|
|
38
|
+
/** @deprecated Read the dirty property instead. */
|
|
30
39
|
export function isDirty() { return handle.dirty; }
|
|
40
|
+
/** @deprecated Read the element property instead. */
|
|
31
41
|
export function getElement() { return binding?.element; }
|
|
42
|
+
export { element, dirty };
|
|
32
43
|
</script>
|
|
33
44
|
<div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, themeColors, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, 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
|
@@ -91,6 +91,12 @@ interface EditorBinding extends EditorHandle {
|
|
|
91
91
|
declare function deferredHandle(current: () => EditorBinding | null | undefined): EditorHandle;
|
|
92
92
|
/** All framework adapters share property, event and lifecycle semantics here. */
|
|
93
93
|
declare function mountEditor(host: HTMLElement, initial?: EditorOptions): EditorBinding;
|
|
94
|
+
/**
|
|
95
|
+
* The imperative handle every framework exposes (React ref, Vue template ref, Angular component
|
|
96
|
+
* instance, Solid `editorRef`, Svelte component instance). `handle-keys.test.ts` checks each one.
|
|
97
|
+
*/
|
|
98
|
+
declare const EDITOR_HANDLE_KEYS: readonly ["element", "load", "newWorkbook", "save", "saveBytes", "download", "markClean", "select", "getSelection", "setActiveSheet", "dirty"];
|
|
99
|
+
type EditorHandleKey = (typeof EDITOR_HANDLE_KEYS)[number];
|
|
94
100
|
|
|
95
|
-
export { EDITOR_EVENT_NAMES, EDITOR_PROP_KEYS, deferredHandle, eventOptions, mountEditor, pickEditorProps };
|
|
96
|
-
export type { EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorOptions, EditorPropKey, EditorProps };
|
|
101
|
+
export { EDITOR_EVENT_NAMES, EDITOR_HANDLE_KEYS, EDITOR_PROP_KEYS, deferredHandle, eventOptions, mountEditor, pickEditorProps };
|
|
102
|
+
export type { EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorHandleKey, EditorOptions, EditorPropKey, EditorProps };
|
package/dist/runtime.js
CHANGED
|
@@ -173,9 +173,19 @@ function O(e, t = {}) {
|
|
|
173
173
|
};
|
|
174
174
|
return g.update(t), e.append(n), r.onReady?.(n), g;
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
var k = [
|
|
177
|
+
"element",
|
|
178
|
+
"load",
|
|
179
|
+
"newWorkbook",
|
|
180
|
+
"save",
|
|
181
|
+
"saveBytes",
|
|
182
|
+
"download",
|
|
183
|
+
"markClean",
|
|
184
|
+
"select",
|
|
185
|
+
"getSelection",
|
|
186
|
+
"setActiveSheet",
|
|
187
|
+
"dirty"
|
|
188
|
+
], A = /* @__PURE__ */ f({
|
|
179
189
|
LegacyXlsError: () => e,
|
|
180
190
|
csvToWorkbook: () => t,
|
|
181
191
|
detectWorkbookFormat: () => n,
|
|
@@ -185,8 +195,9 @@ var k = /* @__PURE__ */ f({
|
|
|
185
195
|
saveWorkbook: () => o,
|
|
186
196
|
sheetToCsv: () => s
|
|
187
197
|
});
|
|
188
|
-
m(
|
|
198
|
+
m(A, h), m(/* @__PURE__ */ f({
|
|
189
199
|
EDITOR_EVENT_NAMES: () => C,
|
|
200
|
+
EDITOR_HANDLE_KEYS: () => k,
|
|
190
201
|
EDITOR_PROP_KEYS: () => S,
|
|
191
202
|
LegacyXlsError: () => e,
|
|
192
203
|
csvToWorkbook: () => t,
|
|
@@ -200,6 +211,6 @@ m(k, h), m(/* @__PURE__ */ f({
|
|
|
200
211
|
pickEditorProps: () => T,
|
|
201
212
|
saveWorkbook: () => o,
|
|
202
213
|
sheetToCsv: () => s
|
|
203
|
-
}),
|
|
214
|
+
}), A);
|
|
204
215
|
//#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 };
|
|
216
|
+
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.
|
|
3
|
+
"version": "0.4.6",
|
|
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.
|
|
50
|
-
"ooxml-core": "^
|
|
51
|
-
"ooxml-ui": "^
|
|
49
|
+
"@christophervr/xlsx-core": "^0.2.9",
|
|
50
|
+
"ooxml-core": "^1.1.0",
|
|
51
|
+
"ooxml-ui": "^1.1.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"svelte": "^5.0.0"
|