xlsx-svelte-viewer 1.0.0 → 1.2.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.
- package/dist/XlsxEditor.svelte +7 -3
- package/dist/runtime.d.ts +47 -5
- package/dist/runtime.js +19 -4
- package/package.json +3 -3
package/dist/XlsxEditor.svelte
CHANGED
|
@@ -6,12 +6,16 @@
|
|
|
6
6
|
onselectionchange?: EditorEventHandlers['selection-change'];
|
|
7
7
|
ondirtychange?: EditorEventHandlers['dirty-change'];
|
|
8
8
|
onreadonlychange?: EditorEventHandlers['readonly-change'];
|
|
9
|
+
onfilecommand?: EditorEventHandlers['file-command'];
|
|
10
|
+
onworkbookwarning?: EditorEventHandlers['workbook-warning'];
|
|
11
|
+
onribbonaction?: EditorEventHandlers['ribbon-action'];
|
|
9
12
|
onribboncustomize?: EditorEventHandlers['ribbon-customize'];
|
|
13
|
+
onsheetchange?: EditorEventHandlers['sheet-change'];
|
|
10
14
|
onribbonaddin?: EditorEventHandlers['office-ribbon-add-in'];
|
|
11
15
|
oncollaborationchange?: EditorEventHandlers['collaboration-change'];
|
|
12
16
|
onready?: EditorEventHandlers['ready'];
|
|
13
17
|
};
|
|
14
|
-
let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], ribbonAddIns, themeColors, collaboration, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onribbonaddin, oncollaborationchange, onready }: Props = $props();
|
|
18
|
+
let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', showToolbar = true, showFormulaBar = true, hiddenActions = [], ribbonAddIns, themeColors, collaboration, customization, storage, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready }: Props = $props();
|
|
15
19
|
let binding: EditorBinding | undefined;
|
|
16
20
|
const handle = deferredHandle(() => binding);
|
|
17
21
|
// Live `element` and `dirty`, the same handle vocabulary as the other frameworks (`EDITOR_HANDLE_KEYS`).
|
|
@@ -21,7 +25,7 @@
|
|
|
21
25
|
const dirty = $derived(dirtyState);
|
|
22
26
|
function attach(host: HTMLElement, options: Props) {
|
|
23
27
|
const normalized = (value: Props) => ({ ...pickEditorProps(value),
|
|
24
|
-
...eventOptions({ 'workbook-change': value.onworkbookchange, 'workbook-error': value.onworkbookerror, 'selection-change': value.onselectionchange, 'dirty-change': value.ondirtychange, 'readonly-change': value.onreadonlychange, 'ribbon-customize': value.onribboncustomize, 'office-ribbon-add-in': value.onribbonaddin, 'collaboration-change': value.oncollaborationchange, ready: value.onready }) });
|
|
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 }) });
|
|
25
29
|
const tracked = (value: Props) => normalized({ ...value, ondirtychange: (next: boolean) => { dirtyState = next; value.ondirtychange?.(next); } });
|
|
26
30
|
binding = mountEditor(host, tracked(options));
|
|
27
31
|
mountedElement = binding.element;
|
|
@@ -44,4 +48,4 @@
|
|
|
44
48
|
export function getElement() { return binding?.element; }
|
|
45
49
|
export { element, dirty };
|
|
46
50
|
</script>
|
|
47
|
-
<div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, ribbonAddIns, themeColors, collaboration, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onribboncustomize, onribbonaddin, oncollaborationchange, onready }}></div>
|
|
51
|
+
<div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, showToolbar, showFormulaBar, hiddenActions, ribbonAddIns, themeColors, collaboration, customization, storage, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready }}></div>
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as ooxml_core_xlsx from 'ooxml-core/xlsx';
|
|
2
2
|
import * as ooxml_core_xlsx_ui from 'ooxml-core/xlsx/ui';
|
|
3
3
|
import * as ooxml_core_collab from 'ooxml-core/collab';
|
|
4
|
-
import { EditorLocaleInput, EditorThemeMode, RibbonAddInTab, XlsxThemeColors, XlsxCollaborationOptions, SelectionChangeDetail, RibbonAddInCommandDetail, XlsxCollaborationState, XlsxEditorElement, SurfaceHostActions, ValidationErrorDetail, SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
|
|
4
|
+
import { EditorLocaleInput, EditorThemeMode, RibbonAddInTab, XlsxThemeColors, XlsxCollaborationOptions, ExcelCustomization, SelectionChangeDetail, FileCommandDetail, RibbonAddInCommandDetail, XlsxCollaborationState, XlsxEditorElement, SurfaceHostActions, ValidationErrorDetail, SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
|
|
5
5
|
export * from 'ooxml-ui/xlsx';
|
|
6
6
|
export { SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
|
|
7
7
|
import { Workbook } from '@christophervr/xlsx-core';
|
|
8
8
|
export * from '@christophervr/xlsx-core';
|
|
9
|
+
import { DocumentStorage } from 'ooxml-core/embedding';
|
|
9
10
|
export { LegacyXlsError, WorkbookFormat, csvToWorkbook, detectWorkbookFormat, loadLegacyXls, loadWorkbook, parseCsv, saveWorkbook, sheetToCsv } from '@christophervr/xlsx-core/load';
|
|
10
11
|
import * as svelte_store from 'svelte/store';
|
|
11
12
|
|
|
@@ -41,6 +42,17 @@ interface EditorProps {
|
|
|
41
42
|
* colour); forwarded when a new object is passed, and `undefined` or `null` leaves the room.
|
|
42
43
|
*/
|
|
43
44
|
collaboration?: XlsxCollaborationOptions | null | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Host-owned storage: File > Save and Save As go to `storage.save()` instead of a download, and
|
|
47
|
+
* File > Open to `storage.open()` when it has one. `file-command` still fires first.
|
|
48
|
+
*/
|
|
49
|
+
storage?: DocumentStorage | null | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Host customisation (`ExcelCustomization`): `capabilities`, `backstage.extraPages` and
|
|
52
|
+
* `contextMenu.extraCommands`. Forwarded when the object changes, so keep it stable (memoise
|
|
53
|
+
* it); `null` or omitted restores the defaults.
|
|
54
|
+
*/
|
|
55
|
+
customization?: ExcelCustomization | null | undefined;
|
|
44
56
|
}
|
|
45
57
|
/** Editor callbacks; each is the framework-neutral form of one entry in `EDITOR_EVENT_NAMES`. */
|
|
46
58
|
interface EditorEventOptions {
|
|
@@ -48,10 +60,35 @@ interface EditorEventOptions {
|
|
|
48
60
|
onWorkbookError?: ((error: Error) => void) | undefined;
|
|
49
61
|
onSelectionChange?: ((detail: SelectionChangeDetail) => void) | undefined;
|
|
50
62
|
onDirtyChange?: ((dirty: boolean) => void) | undefined;
|
|
51
|
-
/**
|
|
52
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The user toggled Editing / Viewing, `readOnly` changed or a collaboration role changed.
|
|
65
|
+
* `readOnly` is the effective value. A controlled parent that mirrors the switch must store
|
|
66
|
+
* `detail.hostReadOnly`, never `readOnly`, or a `viewer` role lock would be written into the
|
|
67
|
+
* host's setting.
|
|
68
|
+
*/
|
|
69
|
+
onReadOnlyChange?: ((readOnly: boolean, detail: {
|
|
70
|
+
readOnly: boolean;
|
|
71
|
+
locked: boolean;
|
|
72
|
+
hostReadOnly: boolean;
|
|
73
|
+
}) => void) | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* A File command (new, open, save, saveAs, export, exportCsv, print) is about to run. The event is
|
|
76
|
+
* cancelable: call `event.preventDefault()` to take the command over yourself.
|
|
77
|
+
*/
|
|
78
|
+
onFileCommand?: ((event: CustomEvent<FileCommandDetail>) => void) | undefined;
|
|
79
|
+
/** Non-fatal notes from the loader (unsupported features, compatibility). */
|
|
80
|
+
onWorkbookWarning?: ((warnings: string[]) => void) | undefined;
|
|
81
|
+
/** A command ran from the ribbon, a menu, Tell me or a shortcut. */
|
|
82
|
+
onRibbonAction?: ((detail: {
|
|
83
|
+
id: string;
|
|
84
|
+
}) => void) | undefined;
|
|
53
85
|
/** The user changed the shown ribbon commands (File > Options > Customize Ribbon). */
|
|
54
86
|
onRibbonCustomize?: ((hiddenActions: string[]) => void) | undefined;
|
|
87
|
+
/** The active sheet changed. */
|
|
88
|
+
onSheetChange?: ((detail: {
|
|
89
|
+
index: number;
|
|
90
|
+
name: string;
|
|
91
|
+
}) => void) | undefined;
|
|
55
92
|
/** A command of a host tab (`ribbonAddIns`) was chosen. */
|
|
56
93
|
onRibbonAddIn?: ((detail: RibbonAddInCommandDetail) => void) | undefined;
|
|
57
94
|
/** Sharing started or stopped, the connection changed, or someone joined or left. */
|
|
@@ -62,10 +99,10 @@ interface EditorEventOptions {
|
|
|
62
99
|
interface EditorOptions extends EditorProps, EditorEventOptions {
|
|
63
100
|
}
|
|
64
101
|
/** Single source of truth for the prop keys every adapter forwards. */
|
|
65
|
-
declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "ribbonAddIns", "themeColors", "collaboration"];
|
|
102
|
+
declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "ribbonAddIns", "themeColors", "collaboration", "storage", "customization"];
|
|
66
103
|
type EditorPropKey = (typeof EDITOR_PROP_KEYS)[number];
|
|
67
104
|
/** Single source of truth for the element events every adapter surfaces. */
|
|
68
|
-
declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "ribbon-customize", "office-ribbon-add-in", "collaboration-change"];
|
|
105
|
+
declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "file-command", "workbook-warning", "ribbon-action", "ribbon-customize", "sheet-change", "office-ribbon-add-in", "collaboration-change"];
|
|
69
106
|
type EditorEventName = (typeof EDITOR_EVENT_NAMES)[number];
|
|
70
107
|
/** One handler per bound event (unwrapped payload); a missing key is a compile error in every adapter. */
|
|
71
108
|
interface EditorEventHandlers {
|
|
@@ -74,7 +111,11 @@ interface EditorEventHandlers {
|
|
|
74
111
|
'selection-change': EditorEventOptions['onSelectionChange'];
|
|
75
112
|
'dirty-change': EditorEventOptions['onDirtyChange'];
|
|
76
113
|
'readonly-change': EditorEventOptions['onReadOnlyChange'];
|
|
114
|
+
'file-command': EditorEventOptions['onFileCommand'];
|
|
115
|
+
'workbook-warning': EditorEventOptions['onWorkbookWarning'];
|
|
116
|
+
'ribbon-action': EditorEventOptions['onRibbonAction'];
|
|
77
117
|
'ribbon-customize': EditorEventOptions['onRibbonCustomize'];
|
|
118
|
+
'sheet-change': EditorEventOptions['onSheetChange'];
|
|
78
119
|
'office-ribbon-add-in': EditorEventOptions['onRibbonAddIn'];
|
|
79
120
|
'collaboration-change': EditorEventOptions['onCollaborationChange'];
|
|
80
121
|
ready?: EditorEventOptions['onReady'];
|
|
@@ -150,6 +191,7 @@ declare function mountEditorSurface(host: HTMLElement, initial?: SurfaceOptions)
|
|
|
150
191
|
formatCells: boolean;
|
|
151
192
|
findReplace: boolean;
|
|
152
193
|
insertFunction: boolean;
|
|
194
|
+
validationAlert: boolean;
|
|
153
195
|
};
|
|
154
196
|
labels: {
|
|
155
197
|
[k: string]: string;
|
package/dist/runtime.js
CHANGED
|
@@ -83,14 +83,20 @@ var T = [
|
|
|
83
83
|
"hiddenActions",
|
|
84
84
|
"ribbonAddIns",
|
|
85
85
|
"themeColors",
|
|
86
|
-
"collaboration"
|
|
86
|
+
"collaboration",
|
|
87
|
+
"storage",
|
|
88
|
+
"customization"
|
|
87
89
|
], E = [
|
|
88
90
|
"workbook-change",
|
|
89
91
|
"workbook-error",
|
|
90
92
|
"selection-change",
|
|
91
93
|
"dirty-change",
|
|
92
94
|
"readonly-change",
|
|
95
|
+
"file-command",
|
|
96
|
+
"workbook-warning",
|
|
97
|
+
"ribbon-action",
|
|
93
98
|
"ribbon-customize",
|
|
99
|
+
"sheet-change",
|
|
94
100
|
"office-ribbon-add-in",
|
|
95
101
|
"collaboration-change"
|
|
96
102
|
];
|
|
@@ -109,7 +115,11 @@ function k(e) {
|
|
|
109
115
|
onSelectionChange: e["selection-change"],
|
|
110
116
|
onDirtyChange: e["dirty-change"],
|
|
111
117
|
onReadOnlyChange: e["readonly-change"],
|
|
118
|
+
onFileCommand: e["file-command"],
|
|
119
|
+
onWorkbookWarning: e["workbook-warning"],
|
|
120
|
+
onRibbonAction: e["ribbon-action"],
|
|
112
121
|
onRibbonCustomize: e["ribbon-customize"],
|
|
122
|
+
onSheetChange: e["sheet-change"],
|
|
113
123
|
onRibbonAddIn: e["office-ribbon-add-in"],
|
|
114
124
|
onCollaborationChange: e["collaboration-change"],
|
|
115
125
|
onReady: e.ready
|
|
@@ -154,8 +164,12 @@ function j(e, t = {}, n = !1) {
|
|
|
154
164
|
"workbook-error": (e) => i.onWorkbookError?.(e.detail.error),
|
|
155
165
|
"selection-change": (e) => i.onSelectionChange?.(e.detail),
|
|
156
166
|
"dirty-change": (e) => i.onDirtyChange?.(e.detail.dirty),
|
|
157
|
-
"readonly-change": (e) => i.onReadOnlyChange?.(e.detail.readOnly),
|
|
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),
|
|
158
171
|
"ribbon-customize": (e) => i.onRibbonCustomize?.([...e.detail.hiddenActions]),
|
|
172
|
+
"sheet-change": (e) => i.onSheetChange?.(e.detail),
|
|
159
173
|
"office-ribbon-add-in": (e) => i.onRibbonAddIn?.(e.detail),
|
|
160
174
|
"collaboration-change": (e) => i.onCollaborationChange?.(e.detail)
|
|
161
175
|
}, h = (e) => {
|
|
@@ -168,7 +182,7 @@ function j(e, t = {}, n = !1) {
|
|
|
168
182
|
let g = {
|
|
169
183
|
element: r,
|
|
170
184
|
update(e) {
|
|
171
|
-
l || (i = e, u("locale", e.locale) && (r.locale = e.locale ?? "en"), u("readOnly", e.readOnly) && (r.readOnly = e.readOnly ?? !1), u("theme", e.theme) && (r.theme = e.theme ?? "auto"), u("authorName", e.authorName) && (r.authorName = e.authorName ?? "Author"), u("showToolbar", e.showToolbar) && (r.showToolbar = e.showToolbar ?? !0), u("showFormulaBar", e.showFormulaBar) && (r.showFormulaBar = e.showFormulaBar ?? !0), u("hiddenActions", e.hiddenActions, b) && (r.hiddenActions = [...e.hiddenActions ?? []]), u("ribbonAddIns", e.ribbonAddIns) && (r.ribbonAddIns = e.ribbonAddIns ?? []), u("themeColors", e.themeColors, x) && (r.themeColors = { ...e.themeColors }), u("fileName", e.fileName) && e.fileName !== void 0 && (r.fileName = e.fileName), u("collaboration", e.collaboration ?? null) && (r.collaboration = e.collaboration ?? null), e.workbook && e.workbook !== a && e.workbook !== o && (p.cancel(), r.workbook = e.workbook), a = e.workbook, e.bytes && e.bytes !== s && (p.cancel(), f(e.bytes, e.fileName)), s = e.bytes, e.src && e.src !== c ? p.fetch(e.src, e.fileName) : !e.src && c && p.cancel(), c = e.src);
|
|
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);
|
|
172
186
|
},
|
|
173
187
|
load: (e, t) => (p.cancel(), r.load(e, t)),
|
|
174
188
|
newWorkbook: () => r.newWorkbook(),
|
|
@@ -207,7 +221,8 @@ var M = [
|
|
|
207
221
|
"onOpenSettings",
|
|
208
222
|
"onOpenFormatCells",
|
|
209
223
|
"onOpenFindReplace",
|
|
210
|
-
"onOpenInsertFunction"
|
|
224
|
+
"onOpenInsertFunction",
|
|
225
|
+
"onOpenValidationAlert"
|
|
211
226
|
];
|
|
212
227
|
function P(e, t = {}) {
|
|
213
228
|
let n = t, r = (e) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xlsx-svelte-viewer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@christophervr/xlsx-core": "^0.3.0",
|
|
70
|
-
"ooxml-core": "^1.
|
|
71
|
-
"ooxml-ui": "^1.
|
|
70
|
+
"ooxml-core": "^1.24.0",
|
|
71
|
+
"ooxml-ui": "^1.23.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"svelte": "^5.0.0"
|