xlsx-svelte-viewer 0.5.1 → 0.7.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/FormulaBar.svelte +14 -0
- package/dist/FormulaBar.svelte.d.ts +4 -0
- package/dist/SheetTabs.svelte +11 -0
- package/dist/SheetTabs.svelte.d.ts +4 -0
- package/dist/SpreadsheetCanvas.svelte +6 -0
- package/dist/SpreadsheetCanvas.svelte.d.ts +4 -0
- package/dist/Toolbar.svelte +12 -0
- package/dist/Toolbar.svelte.d.ts +4 -0
- package/dist/XlsxEditor.svelte +4 -3
- package/dist/runtime.d.ts +104 -6
- package/dist/runtime.js +194 -67
- package/package.json +25 -5
|
@@ -0,0 +1,14 @@
|
|
|
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}
|
|
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
|
+
</div>
|
|
@@ -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,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,12 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { prepareBlock } from './runtime.js';
|
|
3
|
+
const themeBlock = (host: HTMLElement) => prepareBlock(host, 'toolbar');
|
|
4
|
+
import { toolbarButtons, type SpreadsheetToolbarProps } from './runtime.js';
|
|
5
|
+
let { toolbarProps }: { toolbarProps: SpreadsheetToolbarProps } = $props();
|
|
6
|
+
</script>
|
|
7
|
+
<div use:themeBlock role="toolbar">
|
|
8
|
+
{#each toolbarButtons(toolbarProps) as button (button.label)}
|
|
9
|
+
<button type="button" disabled={button.disabled} aria-pressed={button.pressed === null ? 'mixed' : button.pressed}
|
|
10
|
+
onmousedown={(e) => e.preventDefault()} onclick={() => { void button.run(); }}>{button.label}</button>
|
|
11
|
+
{/each}
|
|
12
|
+
</div>
|
package/dist/XlsxEditor.svelte
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
ondirtychange?: EditorEventHandlers['dirty-change'];
|
|
8
8
|
onreadonlychange?: EditorEventHandlers['readonly-change'];
|
|
9
9
|
onribboncustomize?: EditorEventHandlers['ribbon-customize'];
|
|
10
|
+
onribbonaddin?: EditorEventHandlers['office-ribbon-add-in'];
|
|
10
11
|
oncollaborationchange?: EditorEventHandlers['collaboration-change'];
|
|
11
12
|
onready?: EditorEventHandlers['ready'];
|
|
12
13
|
};
|
|
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();
|
|
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();
|
|
14
15
|
let binding: EditorBinding | undefined;
|
|
15
16
|
const handle = deferredHandle(() => binding);
|
|
16
17
|
// Live `element` and `dirty`, the same handle vocabulary as the other frameworks (`EDITOR_HANDLE_KEYS`).
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
const dirty = $derived(dirtyState);
|
|
21
22
|
function attach(host: HTMLElement, options: Props) {
|
|
22
23
|
const normalized = (value: Props) => ({ ...pickEditorProps(value),
|
|
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
|
+
...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 }) });
|
|
24
25
|
const tracked = (value: Props) => normalized({ ...value, ondirtychange: (next: boolean) => { dirtyState = next; value.ondirtychange?.(next); } });
|
|
25
26
|
binding = mountEditor(host, tracked(options));
|
|
26
27
|
mountedElement = binding.element;
|
|
@@ -43,4 +44,4 @@
|
|
|
43
44
|
export function getElement() { return binding?.element; }
|
|
44
45
|
export { element, dirty };
|
|
45
46
|
</script>
|
|
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>
|
|
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>
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as ooxml_core_xlsx from 'ooxml-core/xlsx';
|
|
2
|
+
import * as ooxml_core_xlsx_ui from 'ooxml-core/xlsx/ui';
|
|
3
|
+
import { EditorLocaleInput, EditorThemeMode, RibbonAddInTab, XlsxThemeColors, XlsxCollaborationOptions, SelectionChangeDetail, RibbonAddInCommandDetail, XlsxCollaborationState, XlsxEditorElement, SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
|
|
2
4
|
export * from 'ooxml-ui/xlsx';
|
|
5
|
+
export { SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
|
|
3
6
|
import { Workbook } from '@christophervr/xlsx-core';
|
|
4
7
|
export * from '@christophervr/xlsx-core';
|
|
5
8
|
export { LegacyXlsError, WorkbookFormat, csvToWorkbook, detectWorkbookFormat, loadLegacyXls, loadWorkbook, parseCsv, saveWorkbook, sheetToCsv } from '@christophervr/xlsx-core/load';
|
|
9
|
+
import * as svelte_store from 'svelte/store';
|
|
6
10
|
|
|
7
11
|
/** Editor state a framework passes down as props. */
|
|
8
12
|
interface EditorProps {
|
|
@@ -27,6 +31,8 @@ interface EditorProps {
|
|
|
27
31
|
showFormulaBar?: boolean | undefined;
|
|
28
32
|
/** Ribbon controls to hide, by stable id. */
|
|
29
33
|
hiddenActions?: readonly string[] | undefined;
|
|
34
|
+
/** Tabs the host adds after Excel's own, as an Office add-in does. */
|
|
35
|
+
ribbonAddIns?: readonly RibbonAddInTab[] | undefined;
|
|
30
36
|
/** Theme token overrides, applied as `--xve-*` custom properties. */
|
|
31
37
|
themeColors?: XlsxThemeColors | undefined;
|
|
32
38
|
/**
|
|
@@ -45,6 +51,8 @@ interface EditorEventOptions {
|
|
|
45
51
|
onReadOnlyChange?: ((readOnly: boolean) => void) | undefined;
|
|
46
52
|
/** The user changed the shown ribbon commands (File > Options > Customize Ribbon). */
|
|
47
53
|
onRibbonCustomize?: ((hiddenActions: string[]) => void) | undefined;
|
|
54
|
+
/** A command of a host tab (`ribbonAddIns`) was chosen. */
|
|
55
|
+
onRibbonAddIn?: ((detail: RibbonAddInCommandDetail) => void) | undefined;
|
|
48
56
|
/** Sharing started or stopped, the connection changed, or someone joined or left. */
|
|
49
57
|
onCollaborationChange?: ((state: XlsxCollaborationState) => void) | undefined;
|
|
50
58
|
/** Called once, after the element is created and attached. */
|
|
@@ -53,10 +61,10 @@ interface EditorEventOptions {
|
|
|
53
61
|
interface EditorOptions extends EditorProps, EditorEventOptions {
|
|
54
62
|
}
|
|
55
63
|
/** Single source of truth for the prop keys every adapter forwards. */
|
|
56
|
-
declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "themeColors", "collaboration"];
|
|
64
|
+
declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "showToolbar", "showFormulaBar", "hiddenActions", "ribbonAddIns", "themeColors", "collaboration"];
|
|
57
65
|
type EditorPropKey = (typeof EDITOR_PROP_KEYS)[number];
|
|
58
66
|
/** Single source of truth for the element events every adapter surfaces. */
|
|
59
|
-
declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "ribbon-customize", "collaboration-change"];
|
|
67
|
+
declare const EDITOR_EVENT_NAMES: readonly ["workbook-change", "workbook-error", "selection-change", "dirty-change", "readonly-change", "ribbon-customize", "office-ribbon-add-in", "collaboration-change"];
|
|
60
68
|
type EditorEventName = (typeof EDITOR_EVENT_NAMES)[number];
|
|
61
69
|
/** One handler per bound event (unwrapped payload); a missing key is a compile error in every adapter. */
|
|
62
70
|
interface EditorEventHandlers {
|
|
@@ -66,6 +74,7 @@ interface EditorEventHandlers {
|
|
|
66
74
|
'dirty-change': EditorEventOptions['onDirtyChange'];
|
|
67
75
|
'readonly-change': EditorEventOptions['onReadOnlyChange'];
|
|
68
76
|
'ribbon-customize': EditorEventOptions['onRibbonCustomize'];
|
|
77
|
+
'office-ribbon-add-in': EditorEventOptions['onRibbonAddIn'];
|
|
69
78
|
'collaboration-change': EditorEventOptions['onCollaborationChange'];
|
|
70
79
|
ready?: EditorEventOptions['onReady'];
|
|
71
80
|
}
|
|
@@ -100,13 +109,102 @@ interface EditorBinding extends EditorHandle {
|
|
|
100
109
|
*/
|
|
101
110
|
declare function deferredHandle(current: () => EditorBinding | null | undefined): EditorHandle;
|
|
102
111
|
/** All framework adapters share property, event and lifecycle semantics here. */
|
|
103
|
-
declare function mountEditor(host: HTMLElement, initial?: EditorOptions): EditorBinding;
|
|
112
|
+
declare function mountEditor(host: HTMLElement, initial?: EditorOptions, surfaceOnly?: boolean): EditorBinding;
|
|
104
113
|
/**
|
|
105
114
|
* The imperative handle every framework exposes (React ref, Vue template ref, Angular component
|
|
106
115
|
* instance, Solid `editorRef`, Svelte component instance). `handle-keys.test.ts` checks each one.
|
|
107
116
|
*/
|
|
108
117
|
declare const EDITOR_HANDLE_KEYS: readonly ["element", "load", "newWorkbook", "save", "saveBytes", "download", "markClean", "select", "getSelection", "setActiveSheet", "share", "dirty"];
|
|
109
118
|
type EditorHandleKey = (typeof EDITOR_HANDLE_KEYS)[number];
|
|
119
|
+
/** Framework-neutral composition API, shared by every adapter. Choose before mount. */
|
|
120
|
+
interface SurfaceOptions extends EditorOptions {
|
|
121
|
+
canEdit?: boolean | undefined;
|
|
122
|
+
}
|
|
123
|
+
declare function mountEditorSurface(host: HTMLElement, initial?: SurfaceOptions): EditorBinding & {
|
|
124
|
+
update: (options: SurfaceOptions) => void;
|
|
125
|
+
getToolbarProps: () => {
|
|
126
|
+
bold: boolean | null;
|
|
127
|
+
italic: boolean | null;
|
|
128
|
+
underline: boolean | null;
|
|
129
|
+
fontFamily: string | null;
|
|
130
|
+
fontSize: number | null;
|
|
131
|
+
alignment: string | null;
|
|
132
|
+
numberFormat: string | null;
|
|
133
|
+
formattingComplete: boolean;
|
|
134
|
+
enabled: {
|
|
135
|
+
bold: boolean;
|
|
136
|
+
italic: boolean;
|
|
137
|
+
underline: boolean;
|
|
138
|
+
fontFamily: boolean;
|
|
139
|
+
fontSize: boolean;
|
|
140
|
+
numberFormat: boolean;
|
|
141
|
+
};
|
|
142
|
+
labels: {
|
|
143
|
+
[k: string]: string;
|
|
144
|
+
};
|
|
145
|
+
canEdit: boolean;
|
|
146
|
+
selection: string;
|
|
147
|
+
activeCell: string;
|
|
148
|
+
activeSheet: number;
|
|
149
|
+
editing: boolean;
|
|
150
|
+
editMode: ooxml_core_xlsx_ui.EditMode;
|
|
151
|
+
formulaCaret: number;
|
|
152
|
+
sheets: {
|
|
153
|
+
name: string;
|
|
154
|
+
index: number;
|
|
155
|
+
state: ooxml_core_xlsx.SheetState;
|
|
156
|
+
}[];
|
|
157
|
+
canUndo: boolean;
|
|
158
|
+
canRedo: boolean;
|
|
159
|
+
formula: string;
|
|
160
|
+
onBold: () => Promise<boolean>;
|
|
161
|
+
onItalic: () => Promise<boolean>;
|
|
162
|
+
onUnderline: () => Promise<boolean>;
|
|
163
|
+
onFontFamilyChange: (family: string) => Promise<boolean>;
|
|
164
|
+
onFontSizeChange: (size: number) => Promise<boolean>;
|
|
165
|
+
onNumberFormatChange: (format: string) => Promise<boolean>;
|
|
166
|
+
onAlignmentChange: (alignment: ooxml_core_xlsx.HorizontalAlignment) => Promise<boolean>;
|
|
167
|
+
onUndo: () => Promise<boolean>;
|
|
168
|
+
onRedo: () => Promise<boolean>;
|
|
169
|
+
onSelect: (ref: string) => boolean;
|
|
170
|
+
onSheetChange: (index: number) => boolean;
|
|
171
|
+
onFormulaInput: (text: string, caret?: number) => boolean;
|
|
172
|
+
onFormulaChange: (text: string) => boolean;
|
|
173
|
+
onCancelEdit: () => void;
|
|
174
|
+
commitEdit: () => boolean;
|
|
175
|
+
};
|
|
176
|
+
subscribe: (listener: () => void) => () => void;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
type BuildingBlockOptions = SurfaceOptions;
|
|
180
|
+
interface BuildingBlockState {
|
|
181
|
+
toolbarProps: SpreadsheetToolbarProps | null;
|
|
182
|
+
loading: boolean;
|
|
183
|
+
error: Error | null;
|
|
184
|
+
mode: 'view' | 'edit';
|
|
185
|
+
}
|
|
186
|
+
declare function toolbarButtons(p: SpreadsheetToolbarProps): {
|
|
187
|
+
label: string;
|
|
188
|
+
pressed: boolean | null;
|
|
189
|
+
disabled: boolean;
|
|
190
|
+
run: () => Promise<boolean>;
|
|
191
|
+
}[];
|
|
192
|
+
declare function selectReference(p: SpreadsheetToolbarProps, value: string): boolean;
|
|
193
|
+
|
|
194
|
+
type BuildingBlockKind = 'toolbar' | 'formula-bar' | 'tabs';
|
|
195
|
+
/** Lazy lookup keeps existing viewer imports compatible with an older Office UI runtime. */
|
|
196
|
+
declare function prepareBlock(value: unknown, kind: BuildingBlockKind): void;
|
|
197
|
+
|
|
198
|
+
/** Create during component initialization; use $blocks for state and $effect(() => blocks.update(options)). */
|
|
199
|
+
declare function createViewerBuildingBlocks(initial?: BuildingBlockOptions): {
|
|
200
|
+
subscribe: (this: void, run: svelte_store.Subscriber<BuildingBlockState>, invalidate?: () => void) => svelte_store.Unsubscriber;
|
|
201
|
+
update: (next: BuildingBlockOptions) => void;
|
|
202
|
+
handle: EditorHandle;
|
|
203
|
+
canvasProps: {
|
|
204
|
+
mount: (host: HTMLElement | null) => void;
|
|
205
|
+
};
|
|
206
|
+
destroy: () => void;
|
|
207
|
+
};
|
|
110
208
|
|
|
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 };
|
|
209
|
+
export { EDITOR_EVENT_NAMES, EDITOR_HANDLE_KEYS, EDITOR_PROP_KEYS, createViewerBuildingBlocks, deferredHandle, eventOptions, mountEditor, mountEditorSurface, pickEditorProps, prepareBlock, selectReference, toolbarButtons };
|
|
210
|
+
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
|
|
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)
|
|
10
|
+
for (var r in e) d(n, r, {
|
|
8
11
|
get: e[r],
|
|
9
12
|
enumerable: !0
|
|
10
13
|
});
|
|
11
|
-
return t ||
|
|
12
|
-
},
|
|
13
|
-
if (t && typeof t == "object" || typeof t == "function") for (var i =
|
|
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 =
|
|
18
|
+
enumerable: !(r = f(t, s)) || r.enumerable
|
|
16
19
|
});
|
|
17
20
|
return e;
|
|
18
|
-
},
|
|
19
|
-
import * as
|
|
20
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 ??
|
|
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
|
|
72
|
+
var T = [
|
|
70
73
|
"workbook",
|
|
71
74
|
"bytes",
|
|
72
75
|
"src",
|
|
@@ -78,26 +81,28 @@ var S = [
|
|
|
78
81
|
"showToolbar",
|
|
79
82
|
"showFormulaBar",
|
|
80
83
|
"hiddenActions",
|
|
84
|
+
"ribbonAddIns",
|
|
81
85
|
"themeColors",
|
|
82
86
|
"collaboration"
|
|
83
|
-
],
|
|
87
|
+
], E = [
|
|
84
88
|
"workbook-change",
|
|
85
89
|
"workbook-error",
|
|
86
90
|
"selection-change",
|
|
87
91
|
"dirty-change",
|
|
88
92
|
"readonly-change",
|
|
89
93
|
"ribbon-customize",
|
|
94
|
+
"office-ribbon-add-in",
|
|
90
95
|
"collaboration-change"
|
|
91
96
|
];
|
|
92
|
-
function
|
|
97
|
+
function D(e, t, n) {
|
|
93
98
|
e[n] = t[n];
|
|
94
99
|
}
|
|
95
|
-
function
|
|
100
|
+
function O(e) {
|
|
96
101
|
let t = {};
|
|
97
|
-
for (let n of
|
|
102
|
+
for (let n of T) D(t, e, n);
|
|
98
103
|
return t;
|
|
99
104
|
}
|
|
100
|
-
function
|
|
105
|
+
function k(e) {
|
|
101
106
|
return {
|
|
102
107
|
onWorkbookChange: e["workbook-change"],
|
|
103
108
|
onWorkbookError: e["workbook-error"],
|
|
@@ -105,11 +110,12 @@ function E(e) {
|
|
|
105
110
|
onDirtyChange: e["dirty-change"],
|
|
106
111
|
onReadOnlyChange: e["readonly-change"],
|
|
107
112
|
onRibbonCustomize: e["ribbon-customize"],
|
|
113
|
+
onRibbonAddIn: e["office-ribbon-add-in"],
|
|
108
114
|
onCollaborationChange: e["collaboration-change"],
|
|
109
115
|
onReady: e.ready
|
|
110
116
|
};
|
|
111
117
|
}
|
|
112
|
-
function
|
|
118
|
+
function A(e) {
|
|
113
119
|
let t = () => {
|
|
114
120
|
let t = e();
|
|
115
121
|
if (!t) throw Error("Editor is not mounted");
|
|
@@ -134,52 +140,56 @@ function D(e) {
|
|
|
134
140
|
}
|
|
135
141
|
};
|
|
136
142
|
}
|
|
137
|
-
function
|
|
138
|
-
(0,
|
|
139
|
-
let
|
|
140
|
-
|
|
141
|
-
|
|
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 = {
|
|
142
151
|
"workbook-change": (e) => {
|
|
143
|
-
|
|
152
|
+
o = e.detail.workbook, i.onWorkbookChange?.(o);
|
|
144
153
|
},
|
|
145
|
-
"workbook-error": (e) =>
|
|
146
|
-
"selection-change": (e) =>
|
|
147
|
-
"dirty-change": (e) =>
|
|
148
|
-
"readonly-change": (e) =>
|
|
149
|
-
"ribbon-customize": (e) =>
|
|
150
|
-
"
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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);
|
|
155
165
|
}
|
|
156
166
|
};
|
|
157
|
-
|
|
167
|
+
h(!0);
|
|
158
168
|
let g = {
|
|
159
|
-
element:
|
|
169
|
+
element: r,
|
|
160
170
|
update(e) {
|
|
161
|
-
|
|
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);
|
|
162
172
|
},
|
|
163
|
-
load: (e, t) => (
|
|
164
|
-
newWorkbook: () =>
|
|
165
|
-
save: () =>
|
|
166
|
-
saveBytes: (e) =>
|
|
167
|
-
download: (e) =>
|
|
168
|
-
markClean: () =>
|
|
169
|
-
select: (e) =>
|
|
170
|
-
getSelection: () =>
|
|
171
|
-
setActiveSheet: (e) =>
|
|
172
|
-
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(),
|
|
173
183
|
get dirty() {
|
|
174
|
-
return
|
|
184
|
+
return r.dirty;
|
|
175
185
|
},
|
|
176
186
|
destroy() {
|
|
177
|
-
|
|
187
|
+
l || (l = !0, p.cancel(), typeof r.stopCollaboration == "function" && r.stopCollaboration(), h(!1), r.remove());
|
|
178
188
|
}
|
|
179
189
|
};
|
|
180
|
-
return g.update(t), e.append(
|
|
190
|
+
return g.update(t), e.append(r), i.onReady?.(r), g;
|
|
181
191
|
}
|
|
182
|
-
var
|
|
192
|
+
var M = [
|
|
183
193
|
"element",
|
|
184
194
|
"load",
|
|
185
195
|
"newWorkbook",
|
|
@@ -192,32 +202,149 @@ var k = [
|
|
|
192
202
|
"setActiveSheet",
|
|
193
203
|
"share",
|
|
194
204
|
"dirty"
|
|
195
|
-
]
|
|
205
|
+
];
|
|
206
|
+
function N(e, t = {}) {
|
|
207
|
+
let n = (e) => ({
|
|
208
|
+
...e,
|
|
209
|
+
readOnly: e.canEdit === !1 || e.readOnly === !0
|
|
210
|
+
}), r = j(e, n(t), !0), i = r.update;
|
|
211
|
+
return Object.assign(r, {
|
|
212
|
+
update: (e) => i(n(e)),
|
|
213
|
+
getToolbarProps: () => r.element.getToolbarProps(),
|
|
214
|
+
subscribe: (e) => r.element.subscribeEditorState(e)
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region packages/bindings/src/common.ts
|
|
219
|
+
var P = /* @__PURE__ */ h({
|
|
196
220
|
LegacyXlsError: () => e,
|
|
197
221
|
csvToWorkbook: () => t,
|
|
198
222
|
detectWorkbookFormat: () => n,
|
|
199
223
|
loadLegacyXls: () => r,
|
|
200
224
|
loadWorkbook: () => i,
|
|
225
|
+
mountEditorSurface: () => N,
|
|
201
226
|
parseCsv: () => a,
|
|
202
227
|
saveWorkbook: () => o,
|
|
203
228
|
sheetToCsv: () => s
|
|
204
229
|
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
230
|
+
_(P, v);
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region packages/bindings/src/building-blocks.ts
|
|
233
|
+
function F(e) {
|
|
234
|
+
let t = null, n, r, i = {}, a = null, o = !1, s = () => {
|
|
235
|
+
let t = n?.element.loading ?? !1;
|
|
236
|
+
t && !o && (a = null), o = t, e({
|
|
237
|
+
toolbarProps: n?.getToolbarProps() ?? null,
|
|
238
|
+
loading: n?.element.loading ?? !1,
|
|
239
|
+
error: a,
|
|
240
|
+
mode: i.canEdit === !1 || i.readOnly ? "view" : "edit"
|
|
241
|
+
});
|
|
242
|
+
}, c = () => ({
|
|
243
|
+
...i,
|
|
244
|
+
onWorkbookError: (e) => {
|
|
245
|
+
a = e, o = n?.element.loading ?? !1, s(), i.onWorkbookError?.(e);
|
|
246
|
+
}
|
|
247
|
+
}), l = () => {
|
|
248
|
+
t = null, r?.(), r = void 0, n?.destroy(), n = void 0, s();
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
handle: A(() => n),
|
|
252
|
+
mount(e) {
|
|
253
|
+
e && e === t || (l(), e && (a = null, n = N(e, c()), t = e, r = n.subscribe(s), s()));
|
|
254
|
+
},
|
|
255
|
+
update(e) {
|
|
256
|
+
(e.workbook !== i.workbook || e.bytes !== i.bytes || e.src !== i.src) && (a = null), i = e, n?.update(c()), s();
|
|
257
|
+
},
|
|
258
|
+
destroy: l
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
var I = () => ({
|
|
262
|
+
toolbarProps: null,
|
|
263
|
+
loading: !1,
|
|
264
|
+
error: null,
|
|
265
|
+
mode: "edit"
|
|
266
|
+
});
|
|
267
|
+
function L(e) {
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
label: e.labels.Bold ?? "Bold",
|
|
271
|
+
pressed: e.bold,
|
|
272
|
+
disabled: !e.canEdit || !e.enabled.bold,
|
|
273
|
+
run: e.onBold
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
label: e.labels.Italic ?? "Italic",
|
|
277
|
+
pressed: e.italic,
|
|
278
|
+
disabled: !e.canEdit || !e.enabled.italic,
|
|
279
|
+
run: e.onItalic
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
label: e.labels.Underline ?? "Underline",
|
|
283
|
+
pressed: e.underline,
|
|
284
|
+
disabled: !e.canEdit || !e.enabled.underline,
|
|
285
|
+
run: e.onUnderline
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
label: e.labels.Undo ?? "Undo",
|
|
289
|
+
pressed: !1,
|
|
290
|
+
disabled: !e.canUndo,
|
|
291
|
+
run: e.onUndo
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
label: e.labels.Redo ?? "Redo",
|
|
295
|
+
pressed: !1,
|
|
296
|
+
disabled: !e.canRedo,
|
|
297
|
+
run: e.onRedo
|
|
298
|
+
}
|
|
299
|
+
];
|
|
300
|
+
}
|
|
301
|
+
function R(e, t) {
|
|
302
|
+
try {
|
|
303
|
+
return e.onSelect(t);
|
|
304
|
+
} catch {
|
|
305
|
+
return !1;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region packages/bindings/src/block-theme.ts
|
|
310
|
+
function z(e, t) {
|
|
311
|
+
if (!e || typeof e != "object" || !("ownerDocument" in e)) return;
|
|
312
|
+
let n = e, r = Reflect.get(u, "prepareOfficeUiBlock");
|
|
313
|
+
typeof r == "function" ? r(n, t, "xlsx") : (u.installOfficeUiTheme(n.ownerDocument), n.setAttribute("data-office-block", t), n.setAttribute("data-office-product", "xlsx"));
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region packages/svelte/src/building-blocks.ts
|
|
317
|
+
function B(e = {}) {
|
|
318
|
+
let t = l(I()), n = F(t.set);
|
|
319
|
+
return n.update(e), c(n.destroy), {
|
|
320
|
+
subscribe: t.subscribe,
|
|
321
|
+
update: n.update,
|
|
322
|
+
handle: n.handle,
|
|
323
|
+
canvasProps: { mount: n.mount },
|
|
324
|
+
destroy: n.destroy
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
_(/* @__PURE__ */ h({
|
|
328
|
+
EDITOR_EVENT_NAMES: () => E,
|
|
329
|
+
EDITOR_HANDLE_KEYS: () => M,
|
|
330
|
+
EDITOR_PROP_KEYS: () => T,
|
|
209
331
|
LegacyXlsError: () => e,
|
|
332
|
+
createViewerBuildingBlocks: () => B,
|
|
210
333
|
csvToWorkbook: () => t,
|
|
211
|
-
deferredHandle: () =>
|
|
334
|
+
deferredHandle: () => A,
|
|
212
335
|
detectWorkbookFormat: () => n,
|
|
213
|
-
eventOptions: () =>
|
|
336
|
+
eventOptions: () => k,
|
|
214
337
|
loadLegacyXls: () => r,
|
|
215
338
|
loadWorkbook: () => i,
|
|
216
|
-
mountEditor: () =>
|
|
339
|
+
mountEditor: () => j,
|
|
340
|
+
mountEditorSurface: () => N,
|
|
217
341
|
parseCsv: () => a,
|
|
218
|
-
pickEditorProps: () =>
|
|
342
|
+
pickEditorProps: () => O,
|
|
343
|
+
prepareBlock: () => z,
|
|
219
344
|
saveWorkbook: () => o,
|
|
220
|
-
|
|
221
|
-
|
|
345
|
+
selectReference: () => R,
|
|
346
|
+
sheetToCsv: () => s,
|
|
347
|
+
toolbarButtons: () => L
|
|
348
|
+
}), P);
|
|
222
349
|
//#endregion
|
|
223
|
-
export {
|
|
350
|
+
export { E as EDITOR_EVENT_NAMES, M as EDITOR_HANDLE_KEYS, T as EDITOR_PROP_KEYS, e as LegacyXlsError, B as createViewerBuildingBlocks, t as csvToWorkbook, A as deferredHandle, n as detectWorkbookFormat, k as eventOptions, r as loadLegacyXls, i as loadWorkbook, j as mountEditor, N as mountEditorSurface, a as parseCsv, O as pickEditorProps, z as prepareBlock, o as saveWorkbook, R as selectReference, s as sheetToCsv, L as toolbarButtons };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xlsx-svelte-viewer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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.
|
|
50
|
-
"ooxml-core": "^1.
|
|
51
|
-
"ooxml-ui": "^1.
|
|
69
|
+
"@christophervr/xlsx-core": "^0.3.0",
|
|
70
|
+
"ooxml-core": "^1.20.0",
|
|
71
|
+
"ooxml-ui": "^1.19.0"
|
|
52
72
|
},
|
|
53
73
|
"peerDependencies": {
|
|
54
74
|
"svelte": "^5.0.0"
|