xlsx-svelte-viewer 0.4.0 → 0.4.2
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/README.md +4 -4
- package/dist/runtime.d.ts +5 -529
- package/dist/runtime.js +201 -19847
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# xlsx-svelte-viewer
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/xlsx-svelte-viewer)
|
|
4
|
-
[](https://github.com/ChristopherVR/
|
|
4
|
+
[](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/LICENSE)
|
|
5
5
|
[](https://www.npmjs.com/package/xlsx-svelte-viewer)
|
|
6
6
|
|
|
7
7
|
> A browser Excel spreadsheet editor for Svelte 5, using one shared editor and the canonical OOXML document engine.
|
|
8
8
|
|
|
9
|
-
[Live demo](https://christophervr.github.io/xlsx
|
|
9
|
+
[Live demo](https://christophervr.github.io/ooxml/xlsx/demo/) | [npm](https://www.npmjs.com/package/xlsx-svelte-viewer) | [Full docs](https://christophervr.github.io/ooxml/xlsx/) | [Source](https://github.com/ChristopherVR/ooxml/tree/main/viewers/xlsx)
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -62,8 +62,8 @@ diagnostics and the feature guide before relying on preservation.
|
|
|
62
62
|
|
|
63
63
|
## Documentation
|
|
64
64
|
|
|
65
|
-
[Framework guide](https://christophervr.github.io/xlsx
|
|
66
|
-
[Bindings](https://christophervr.github.io/xlsx
|
|
65
|
+
[Framework guide](https://christophervr.github.io/ooxml/xlsx/frameworks/svelte) |
|
|
66
|
+
[Bindings](https://christophervr.github.io/ooxml/xlsx/bindings)
|
|
67
67
|
|
|
68
68
|
## License
|
|
69
69
|
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,533 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { XlsxEditorElement, EditorLocaleInput, EditorThemeMode, XlsxThemeColors, SelectionChangeDetail } from 'ooxml-ui/xlsx';
|
|
2
|
+
export * from 'ooxml-ui/xlsx';
|
|
3
|
+
import { Workbook } from '@christophervr/xlsx-core';
|
|
2
4
|
export * from '@christophervr/xlsx-core';
|
|
3
5
|
export { LegacyXlsError, WorkbookFormat, csvToWorkbook, detectWorkbookFormat, loadLegacyXls, loadWorkbook, parseCsv, saveWorkbook, sheetToCsv } from '@christophervr/xlsx-core/load';
|
|
4
6
|
|
|
5
|
-
type DialogOpener = (ctx: EditorContext, props?: unknown) => Promise<unknown>;
|
|
6
|
-
interface DialogRegistry {
|
|
7
|
-
register(name: string, open: DialogOpener): void;
|
|
8
|
-
/** Resolves undefined when cancelled or when no dialog has that name. */
|
|
9
|
-
open<T = unknown>(name: string, props?: unknown): Promise<T | undefined>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface Selection {
|
|
13
|
-
sheet: number;
|
|
14
|
-
active: CellAddress;
|
|
15
|
-
anchor: CellAddress;
|
|
16
|
-
ranges: CellRange[];
|
|
17
|
-
/**
|
|
18
|
-
* Index in the sheet's drawings of the selected picture or chart. While set, the drawing (not
|
|
19
|
-
* the cells) is the selection: the Chart Design tab follows it and Delete removes it. Any
|
|
20
|
-
* cell selection change clears it.
|
|
21
|
-
*/
|
|
22
|
-
drawing?: number | undefined;
|
|
23
|
-
}
|
|
24
|
-
interface SelectionModel {
|
|
25
|
-
get(): Selection;
|
|
26
|
-
set(next: Partial<Selection> & {
|
|
27
|
-
ranges?: CellRange[];
|
|
28
|
-
}): void;
|
|
29
|
-
onChange(listener: (selection: Selection) => void): () => void;
|
|
30
|
-
}
|
|
31
|
-
/** Implemented by the grid module and attached through `ctx.attachGrid`. */
|
|
32
|
-
interface GridController {
|
|
33
|
-
focus(): void;
|
|
34
|
-
scrollTo(address: CellAddress): void;
|
|
35
|
-
/** Repaints after a model change. */
|
|
36
|
-
invalidate(): void;
|
|
37
|
-
/** Starts the in-cell editor (F2 or typing). */
|
|
38
|
-
beginEdit(initialText?: string): void;
|
|
39
|
-
commitEdit(): boolean;
|
|
40
|
-
cancelEdit(): void;
|
|
41
|
-
isEditing(): boolean;
|
|
42
|
-
/** Width in CSS pixels of `text` drawn with a CSS font shorthand. */
|
|
43
|
-
measureText(text: string, font: string): number;
|
|
44
|
-
zoom(): number;
|
|
45
|
-
setZoom(percent: number): void;
|
|
46
|
-
}
|
|
47
|
-
interface EditorContext {
|
|
48
|
-
readonly host: HTMLElement;
|
|
49
|
-
readonly root: ShadowRoot;
|
|
50
|
-
/** Undefined until a workbook is loaded. */
|
|
51
|
-
session(): EditSession | undefined;
|
|
52
|
-
workbook(): Workbook | undefined;
|
|
53
|
-
activeSheet(): number;
|
|
54
|
-
setActiveSheet(index: number): void;
|
|
55
|
-
readonly selection: SelectionModel;
|
|
56
|
-
readOnly(): boolean;
|
|
57
|
-
/** English text is the key, like the Word editor. */
|
|
58
|
-
t(key: string, vars?: Record<string, string | number>): string;
|
|
59
|
-
readonly commands: CommandRegistry;
|
|
60
|
-
readonly dialogs: DialogRegistry;
|
|
61
|
-
grid(): GridController | undefined;
|
|
62
|
-
attachGrid(grid: GridController): void;
|
|
63
|
-
/** Fires after every session change, load and sheet switch. */
|
|
64
|
-
onModelChange(listener: (change: unknown) => void): () => void;
|
|
65
|
-
/** Refreshes ribbon and status bar state (debounced). */
|
|
66
|
-
requestRender(): void;
|
|
67
|
-
toast(message: string, kind?: 'info' | 'warning' | 'error'): void;
|
|
68
|
-
/** Dispatches a public CustomEvent on the host; returns `!defaultPrevented`. */
|
|
69
|
-
emit(type: string, detail: unknown): boolean;
|
|
70
|
-
authorName(): string;
|
|
71
|
-
locale(): string;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
interface Command {
|
|
75
|
-
/** Stable kebab id: 'home.bold', 'home.merge-center', 'view.freeze-panes'. */
|
|
76
|
-
id: string;
|
|
77
|
-
/** English text (translation key). */
|
|
78
|
-
label: string;
|
|
79
|
-
/** An ooxml-ui icon name or a local icon registered with `registerIcon`. */
|
|
80
|
-
icon?: string;
|
|
81
|
-
/** Display text, for example 'Ctrl+B'. */
|
|
82
|
-
shortcut?: string;
|
|
83
|
-
/** True: disabled in read-only mode. */
|
|
84
|
-
editing?: boolean;
|
|
85
|
-
enabled?(ctx: EditorContext): boolean;
|
|
86
|
-
/** Toggle state (bold of the active cell, ...). */
|
|
87
|
-
checked?(ctx: EditorContext): boolean;
|
|
88
|
-
/** Value for select-like controls (font name, size, number format). */
|
|
89
|
-
value?(ctx: EditorContext): string;
|
|
90
|
-
run(ctx: EditorContext, arg?: unknown): void | Promise<void>;
|
|
91
|
-
}
|
|
92
|
-
interface CommandRegistry {
|
|
93
|
-
register(command: Command): void;
|
|
94
|
-
registerAll(commands: Command[]): void;
|
|
95
|
-
get(id: string): Command | undefined;
|
|
96
|
-
list(): Command[];
|
|
97
|
-
/** False when the command is missing or disabled; emits 'ribbon-action'. */
|
|
98
|
-
run(id: string, arg?: unknown): Promise<boolean>;
|
|
99
|
-
isEnabled(id: string): boolean;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Unsaved-changes flag behind `element.dirty`; reports only real transitions. */
|
|
103
|
-
declare class DirtyState {
|
|
104
|
-
private readonly changed;
|
|
105
|
-
private value;
|
|
106
|
-
constructor(changed: (dirty: boolean) => void);
|
|
107
|
-
get dirty(): boolean;
|
|
108
|
-
set(dirty: boolean): void;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
type EditorLocale = 'en' | 'fr' | 'de' | 'es' | 'zh-CN';
|
|
112
|
-
/** A supported locale or any BCP 47 tag that maps onto one (`de-DE`, `zh-Hans`). */
|
|
113
|
-
type EditorLocaleInput = EditorLocale | (string & {});
|
|
114
|
-
declare const EDITOR_LOCALES: readonly EditorLocale[];
|
|
115
|
-
/**
|
|
116
|
-
* Maps any BCP 47 tag to a supported display locale, falling back to English. Region variants
|
|
117
|
-
* resolve to their language (`fr-CA`, `de-DE`, `es-MX`); `zh`, `zh-CN`, `zh-Hans` and `zh-SG` use
|
|
118
|
-
* Simplified Chinese, while Traditional tags (`zh-TW`, `zh-HK`, `zh-Hant`) fall back to English.
|
|
119
|
-
*/
|
|
120
|
-
declare function normalizeEditorLocale(value: string | null | undefined): EditorLocale;
|
|
121
|
-
|
|
122
|
-
type FileCommand = 'new' | 'open' | 'save' | 'saveAs' | 'export' | 'exportCsv' | 'print';
|
|
123
|
-
interface FileCommandDetail {
|
|
124
|
-
command: FileCommand;
|
|
125
|
-
/** Save As: the name the user chose. */
|
|
126
|
-
fileName?: string;
|
|
127
|
-
}
|
|
128
|
-
interface SelectionChangeDetail {
|
|
129
|
-
sheet: number;
|
|
130
|
-
/** The selection as A1 text (`B2:C5`, or `A1:B2,D4` for several ranges). */
|
|
131
|
-
ref: string;
|
|
132
|
-
/** The active cell (`B2`). */
|
|
133
|
-
active: string;
|
|
134
|
-
}
|
|
135
|
-
/** Every public event of `<xlsx-editor>` and its detail. All bubble and are composed. */
|
|
136
|
-
interface XlsxEditorEventMap {
|
|
137
|
-
/** The workbook was loaded, created or edited. */
|
|
138
|
-
'workbook-change': {
|
|
139
|
-
workbook: Workbook;
|
|
140
|
-
};
|
|
141
|
-
/** Loading, saving, printing or a command failed. */
|
|
142
|
-
'workbook-error': {
|
|
143
|
-
error: Error;
|
|
144
|
-
message: string;
|
|
145
|
-
};
|
|
146
|
-
/** Non-fatal notes from the loader (unsupported features, compatibility). */
|
|
147
|
-
'workbook-warning': {
|
|
148
|
-
warnings: string[];
|
|
149
|
-
};
|
|
150
|
-
/** The user toggled Editing / Viewing, or the host changed `readOnly`. */
|
|
151
|
-
'readonly-change': {
|
|
152
|
-
readOnly: boolean;
|
|
153
|
-
};
|
|
154
|
-
/** A command ran from the ribbon, a menu, Tell me or a shortcut. */
|
|
155
|
-
'ribbon-action': {
|
|
156
|
-
id: string;
|
|
157
|
-
};
|
|
158
|
-
/** The user changed which ribbon commands are shown (File > Options > Customize Ribbon). */
|
|
159
|
-
'ribbon-customize': {
|
|
160
|
-
hiddenActions: string[];
|
|
161
|
-
};
|
|
162
|
-
/** Cancelable: call `preventDefault()` to handle a File command yourself. */
|
|
163
|
-
'file-command': FileCommandDetail;
|
|
164
|
-
'selection-change': SelectionChangeDetail;
|
|
165
|
-
'sheet-change': {
|
|
166
|
-
index: number;
|
|
167
|
-
name: string;
|
|
168
|
-
};
|
|
169
|
-
/** Unsaved-changes state flipped: true after an edit, false after save, load or `markClean()`. */
|
|
170
|
-
'dirty-change': {
|
|
171
|
-
dirty: boolean;
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
type XlsxEditorEventName = keyof XlsxEditorEventMap;
|
|
175
|
-
type XlsxEditorEventDetail<K extends XlsxEditorEventName> = XlsxEditorEventMap[K];
|
|
176
|
-
/** Runtime list of every event name; the `satisfies` check keeps it a subset of the map. */
|
|
177
|
-
declare const XLSX_EDITOR_EVENTS: readonly ["workbook-change", "workbook-error", "workbook-warning", "readonly-change", "ribbon-action", "ribbon-customize", "file-command", "selection-change", "sheet-change", "dirty-change"];
|
|
178
|
-
|
|
179
|
-
type SaveState = 'saved' | 'dirty' | 'saving' | 'saved-local';
|
|
180
|
-
|
|
181
|
-
/** Shared building blocks and the host interface of the File backstage pages. */
|
|
182
|
-
|
|
183
|
-
type CalculationMode = 'automatic' | 'manual';
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Editor theme tokens.
|
|
187
|
-
*
|
|
188
|
-
* Provenance: the semantic key set mirrors docx-viewer's theme (packages/web-component/src/theme,
|
|
189
|
-
* itself following pptx-viewer's shared `ViewerThemeColors` and the shadcn/ui naming), with the
|
|
190
|
-
* `--xve-*` prefix, plus grid tokens for the spreadsheet surface. Keys are camelCase here and
|
|
191
|
-
* become kebab-case custom properties. Values accept any CSS colour. Cells stay white like Excel's
|
|
192
|
-
* sheet in every theme; only the chrome (and the row and column headers) follow dark mode.
|
|
193
|
-
*/
|
|
194
|
-
interface XlsxTheme {
|
|
195
|
-
/** Application chrome background (title bar, status bar). */
|
|
196
|
-
background: string;
|
|
197
|
-
foreground: string;
|
|
198
|
-
/** Ribbon, panel and backstage surface. */
|
|
199
|
-
card: string;
|
|
200
|
-
cardForeground: string;
|
|
201
|
-
/** Menus, dialogs and other floating surfaces. */
|
|
202
|
-
popover: string;
|
|
203
|
-
popoverForeground: string;
|
|
204
|
-
/** Brand and primary action colour (Excel green). */
|
|
205
|
-
primary: string;
|
|
206
|
-
primaryForeground: string;
|
|
207
|
-
secondary: string;
|
|
208
|
-
secondaryForeground: string;
|
|
209
|
-
muted: string;
|
|
210
|
-
mutedForeground: string;
|
|
211
|
-
/** Hover and selected highlight. */
|
|
212
|
-
accent: string;
|
|
213
|
-
accentForeground: string;
|
|
214
|
-
destructive: string;
|
|
215
|
-
destructiveForeground: string;
|
|
216
|
-
border: string;
|
|
217
|
-
input: string;
|
|
218
|
-
/** Focus ring. */
|
|
219
|
-
ring: string;
|
|
220
|
-
/** Base corner radius, e.g. `4px`. */
|
|
221
|
-
radius: string;
|
|
222
|
-
/** Cell gridlines. */
|
|
223
|
-
gridLine: string;
|
|
224
|
-
/** Row and column header background and text. */
|
|
225
|
-
headerBg: string;
|
|
226
|
-
headerFg: string;
|
|
227
|
-
/** Header of a selected row or column. */
|
|
228
|
-
headerActiveBg: string;
|
|
229
|
-
/** Fill over selected cells. */
|
|
230
|
-
selection: string;
|
|
231
|
-
/** Outline of the selection and the active cell. */
|
|
232
|
-
selectionBorder: string;
|
|
233
|
-
/** The sheet behind the cells (white like Excel's paper). */
|
|
234
|
-
sheetBg: string;
|
|
235
|
-
}
|
|
236
|
-
type EditorThemeMode = 'light' | 'dark' | 'auto';
|
|
237
|
-
|
|
238
|
-
/** Light preset: the Word editor's neutral chrome with Excel green as primary. */
|
|
239
|
-
declare const lightTheme: XlsxTheme;
|
|
240
|
-
/** Dark preset: the Word editor's dark gray scale with a lighter Excel green. */
|
|
241
|
-
declare const darkTheme: XlsxTheme;
|
|
242
|
-
|
|
243
|
-
/** Every token key; each becomes the kebab-case `--xve-*` custom property. */
|
|
244
|
-
declare const THEME_KEYS: readonly ["background", "foreground", "card", "cardForeground", "popover", "popoverForeground", "primary", "primaryForeground", "secondary", "secondaryForeground", "muted", "mutedForeground", "accent", "accentForeground", "destructive", "destructiveForeground", "border", "input", "ring", "radius", "gridLine", "headerBg", "headerFg", "headerActiveBg", "selection", "selectionBorder", "sheetBg"];
|
|
245
|
-
/** Converts a (partial) theme to `--xve-*` custom properties; unknown or empty values are skipped. */
|
|
246
|
-
declare function themeToCssVars(theme: Partial<XlsxTheme> | undefined): Record<string, string>;
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* The editor's state and the `EditorContext` every UI module receives: the workbook and its edit
|
|
250
|
-
* session, the active sheet and selection, the command and dialog registries, and the public
|
|
251
|
-
* event plumbing. The element (component.ts) owns one EditorCore; the shell (editor-shell.ts)
|
|
252
|
-
* builds the DOM around it.
|
|
253
|
-
*/
|
|
254
|
-
|
|
255
|
-
/** What the shell exposes back to the core (filled in when the element connects). */
|
|
256
|
-
interface ShellHooks {
|
|
257
|
-
render(): void;
|
|
258
|
-
toast(message: string, kind?: 'info' | 'warning' | 'error'): void;
|
|
259
|
-
relocalize(): void;
|
|
260
|
-
}
|
|
261
|
-
declare class EditorCore {
|
|
262
|
-
readonly host: HTMLElement;
|
|
263
|
-
workbook: Workbook | undefined;
|
|
264
|
-
session: EditSession | undefined;
|
|
265
|
-
activeSheet: number;
|
|
266
|
-
readOnly: boolean;
|
|
267
|
-
locale: EditorLocale;
|
|
268
|
-
authorName: string;
|
|
269
|
-
fileName: string;
|
|
270
|
-
theme: EditorThemeMode;
|
|
271
|
-
showToolbar: boolean;
|
|
272
|
-
showFormulaBar: boolean;
|
|
273
|
-
themeColors: Partial<XlsxTheme>;
|
|
274
|
-
appliedThemeVars: string[];
|
|
275
|
-
hiddenActions: string[];
|
|
276
|
-
loadGeneration: number;
|
|
277
|
-
savePassword: string | undefined;
|
|
278
|
-
shell: ShellHooks | undefined;
|
|
279
|
-
readonly selection: SelectionModel;
|
|
280
|
-
readonly commands: CommandRegistry;
|
|
281
|
-
readonly dialogs: DialogRegistry;
|
|
282
|
-
readonly dirty: DirtyState;
|
|
283
|
-
readonly ctx: EditorContext;
|
|
284
|
-
private gridController;
|
|
285
|
-
private readonly modelListeners;
|
|
286
|
-
private stopSession;
|
|
287
|
-
private renderQueued;
|
|
288
|
-
private lastSelection;
|
|
289
|
-
private readonly sheetSelections;
|
|
290
|
-
/** The worksheet object on screen, to notice sheets inserted, moved or deleted around it. */
|
|
291
|
-
private shownSheet;
|
|
292
|
-
/** Automatic or manual calculation: the workbook's own mode (`calcPr calcMode`). */
|
|
293
|
-
get calculation(): CalculationMode;
|
|
294
|
-
constructor(host: HTMLElement);
|
|
295
|
-
private createContext;
|
|
296
|
-
/** Debounced refresh of the ribbon, title bar and status bar. */
|
|
297
|
-
requestRender(): void;
|
|
298
|
-
notifyModel(change: unknown): void;
|
|
299
|
-
/** Replaces the workbook (load, new, template, property), with a fresh edit session. */
|
|
300
|
-
setWorkbook(workbook: Workbook | undefined): void;
|
|
301
|
-
private createSession;
|
|
302
|
-
private onSessionChange;
|
|
303
|
-
setActiveSheet(index: number, force?: boolean): void;
|
|
304
|
-
/**
|
|
305
|
-
* After an edit that inserted, moved or deleted sheets: keep showing the same worksheet at its
|
|
306
|
-
* new index, or, when it was deleted, switch to the nearest visible sheet (always announcing
|
|
307
|
-
* `sheet-change` and restoring that sheet's selection, even when the index is unchanged).
|
|
308
|
-
*/
|
|
309
|
-
private followShownSheet;
|
|
310
|
-
/** Text width for the core's automatic row heights, from the grid's canvas measurer. */
|
|
311
|
-
private measureText;
|
|
312
|
-
/** Iterative calculation as the workbook stores it (`calcPr iterate`); undefined when off. */
|
|
313
|
-
get iteration(): {
|
|
314
|
-
count: number;
|
|
315
|
-
delta: number;
|
|
316
|
-
} | undefined;
|
|
317
|
-
/**
|
|
318
|
-
* Turns iterative calculation on (with its maximum iterations and maximum change) or off
|
|
319
|
-
* (`undefined`) and recalculates, so circular references settle or are reported again. The core
|
|
320
|
-
* session has no undoable setter for this yet, so it is not an undo step; it marks the workbook
|
|
321
|
-
* as changed so it is saved.
|
|
322
|
-
*/
|
|
323
|
-
setIterativeCalculation(next: {
|
|
324
|
-
count: number;
|
|
325
|
-
delta: number;
|
|
326
|
-
} | undefined): void;
|
|
327
|
-
/** Switches automatic or manual calculation on the live session (one undo step, saved). */
|
|
328
|
-
setCalculation(mode: CalculationMode): void;
|
|
329
|
-
setLocale(value: string): void;
|
|
330
|
-
setReadOnly(readOnly: boolean): boolean;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Workbook I/O for the element: load (xlsx, xlsm, xls, csv through the core's `loadWorkbook`),
|
|
335
|
-
* new, save, download, and the default handlers of the File commands.
|
|
336
|
-
*/
|
|
337
|
-
|
|
338
|
-
/** Chrome callbacks the file actions report to (title bar save state, backstage). */
|
|
339
|
-
interface FileChrome {
|
|
340
|
-
setSaveState(state: SaveState): void;
|
|
341
|
-
fileNameChanged(): void;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* The public methods of `<xlsx-editor>` (load, newWorkbook, save, saveBytes, download, markClean,
|
|
346
|
-
* select, getSelection, setActiveSheet, undo, redo, focusGrid). The properties and lifecycle are
|
|
347
|
-
* in component.ts; the state is the EditorCore.
|
|
348
|
-
*/
|
|
349
|
-
|
|
350
|
-
/** Server rendering has no HTMLElement; the class still has to be definable there. */
|
|
351
|
-
declare const HTMLElementBase: typeof HTMLElement;
|
|
352
|
-
declare class XlsxEditorApi extends HTMLElementBase {
|
|
353
|
-
protected readonly core: EditorCore;
|
|
354
|
-
/** Set by the shell once connected. */
|
|
355
|
-
protected chrome: FileChrome | undefined;
|
|
356
|
-
/** Opens .xlsx, .xlsm, .xltx, .xls or .csv bytes; `fileName` helps detection and names the file. */
|
|
357
|
-
load(bytes: Uint8Array | ArrayBuffer, fileName?: string): Promise<void>;
|
|
358
|
-
/** Starts a blank workbook named Book1.xlsx. */
|
|
359
|
-
newWorkbook(): void;
|
|
360
|
-
/** The workbook as .xlsx bytes (or the active sheet as CSV). Does not clear `dirty`. */
|
|
361
|
-
saveBytes(format?: 'xlsx' | 'csv'): Promise<Uint8Array>;
|
|
362
|
-
/** The workbook as an .xlsx Blob. Does not clear `dirty`; call `markClean()` after persisting. */
|
|
363
|
-
save(): Promise<Blob>;
|
|
364
|
-
/** Saves and downloads in the browser, then marks the workbook clean. */
|
|
365
|
-
download(name?: string): Promise<void>;
|
|
366
|
-
/** Clears the unsaved-changes flag (after the host persisted the bytes). */
|
|
367
|
-
markClean(): void;
|
|
368
|
-
/** Selects `B2`, `B2:C5`, `A:A`, `B2:C5,E1` or `'Sheet 2'!A1` and scrolls it into view. */
|
|
369
|
-
select(ref: string): void;
|
|
370
|
-
/** The selection as A1 text (`B2:C5`, several ranges joined by commas). */
|
|
371
|
-
getSelection(): string;
|
|
372
|
-
setActiveSheet(index: number): void;
|
|
373
|
-
undo(): void;
|
|
374
|
-
redo(): void;
|
|
375
|
-
focusGrid(): void;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* `<xlsx-editor>`: the properties, attributes and lifecycle. Methods are in element-api.ts, state
|
|
380
|
-
* in editor-core.ts and the DOM in editor-shell.ts.
|
|
381
|
-
*/
|
|
382
|
-
|
|
383
|
-
/** Theme tokens, applied to the host as `--xve-<kebab-key>` custom properties. */
|
|
384
|
-
type XlsxThemeColors = Partial<XlsxTheme>;
|
|
385
|
-
type Listener<K extends keyof XlsxEditorEventMap> = (this: XlsxEditorElement, event: CustomEvent<XlsxEditorEventMap[K]>) => unknown;
|
|
386
|
-
/** Typed event overloads (redeclaring hides the inherited ones, so the DOM map is repeated). */
|
|
387
|
-
interface XlsxEditorElement {
|
|
388
|
-
addEventListener<K extends keyof XlsxEditorEventMap>(type: K, listener: Listener<K>, options?: boolean | AddEventListenerOptions): void;
|
|
389
|
-
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: XlsxEditorElement, event: HTMLElementEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
|
|
390
|
-
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
391
|
-
removeEventListener<K extends keyof XlsxEditorEventMap>(type: K, listener: Listener<K>, options?: boolean | EventListenerOptions): void;
|
|
392
|
-
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: XlsxEditorElement, event: HTMLElementEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
|
|
393
|
-
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
394
|
-
}
|
|
395
|
-
declare class XlsxEditorElement extends XlsxEditorApi {
|
|
396
|
-
static get observedAttributes(): readonly string[];
|
|
397
|
-
private shell;
|
|
398
|
-
connectedCallback(): void;
|
|
399
|
-
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
400
|
-
/** Interface language: `en`, `fr`, `de`, `es`, `zh-CN` (any tag mapping to one). */
|
|
401
|
-
get locale(): EditorLocale;
|
|
402
|
-
set locale(value: EditorLocaleInput);
|
|
403
|
-
get readOnly(): boolean;
|
|
404
|
-
set readOnly(value: boolean);
|
|
405
|
-
/** Shown in the title bar and used by Save and Download. Default `Book1.xlsx`. */
|
|
406
|
-
get fileName(): string;
|
|
407
|
-
set fileName(value: string);
|
|
408
|
-
/** Author recorded on new comments. Default `Author`. */
|
|
409
|
-
get authorName(): string;
|
|
410
|
-
set authorName(value: string);
|
|
411
|
-
/** `light`, `dark` or `auto` (default, follows the OS). */
|
|
412
|
-
get theme(): EditorThemeMode;
|
|
413
|
-
set theme(value: EditorThemeMode);
|
|
414
|
-
get showToolbar(): boolean;
|
|
415
|
-
set showToolbar(value: boolean);
|
|
416
|
-
get showFormulaBar(): boolean;
|
|
417
|
-
set showFormulaBar(value: boolean);
|
|
418
|
-
/** Token overrides applied inline as `--xve-*` custom properties. */
|
|
419
|
-
get themeColors(): XlsxThemeColors;
|
|
420
|
-
set themeColors(value: XlsxThemeColors | undefined);
|
|
421
|
-
/** Command ids the ribbon, menus, Tell me and shortcuts leave out. */
|
|
422
|
-
get hiddenActions(): string[];
|
|
423
|
-
set hiddenActions(value: readonly string[]);
|
|
424
|
-
/** The open workbook model, or null. Assigning one shows it with a fresh undo history. */
|
|
425
|
-
get workbook(): Workbook | null;
|
|
426
|
-
set workbook(value: Workbook | null);
|
|
427
|
-
/** Unsaved changes since the last load, save or `markClean()`. */
|
|
428
|
-
get dirty(): boolean;
|
|
429
|
-
get activeSheet(): number;
|
|
430
|
-
set activeSheet(index: number);
|
|
431
|
-
}
|
|
432
|
-
declare global {
|
|
433
|
-
interface HTMLElementTagNameMap {
|
|
434
|
-
'xlsx-editor': XlsxEditorElement;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
/** Registers `<xlsx-editor>` once; a no-op without `customElements` (server rendering). */
|
|
438
|
-
declare function defineXlsxEditor(): void;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Attribute <-> property mapping for `<xlsx-editor>`. Properties are the source of truth: an
|
|
442
|
-
* attribute change goes through the property setter only when it would change the value, and a
|
|
443
|
-
* property change is written back only when the attribute would differ, so the two directions
|
|
444
|
-
* cannot ping-pong (the docx editor's scheme).
|
|
445
|
-
*/
|
|
446
|
-
declare const XLSX_EDITOR_ATTRIBUTES: readonly ["locale", "read-only", "file-name", "author-name", "theme", "show-toolbar", "show-formula-bar"];
|
|
447
|
-
declare const DEFAULT_FILE_NAME = "Book1.xlsx";
|
|
448
|
-
declare const DEFAULT_AUTHOR_NAME = "Author";
|
|
449
|
-
|
|
450
|
-
interface RibbonOption {
|
|
451
|
-
value: string;
|
|
452
|
-
label: string;
|
|
453
|
-
}
|
|
454
|
-
type RibbonControl = {
|
|
455
|
-
kind: 'button';
|
|
456
|
-
command: string;
|
|
457
|
-
size?: 'large' | 'small';
|
|
458
|
-
showLabel?: boolean;
|
|
459
|
-
} | {
|
|
460
|
-
kind: 'toggle';
|
|
461
|
-
command: string;
|
|
462
|
-
size?: 'large' | 'small';
|
|
463
|
-
showLabel?: boolean;
|
|
464
|
-
} | {
|
|
465
|
-
kind: 'split';
|
|
466
|
-
command: string;
|
|
467
|
-
menu: RibbonMenuItem[];
|
|
468
|
-
size?: 'large' | 'small';
|
|
469
|
-
} | {
|
|
470
|
-
kind: 'menu';
|
|
471
|
-
label: string;
|
|
472
|
-
icon?: string;
|
|
473
|
-
items: RibbonMenuItem[];
|
|
474
|
-
size?: 'large' | 'small';
|
|
475
|
-
} | {
|
|
476
|
-
kind: 'select';
|
|
477
|
-
command: string;
|
|
478
|
-
options: RibbonOption[] | ((ctx: EditorContext) => RibbonOption[]);
|
|
479
|
-
width?: number;
|
|
480
|
-
editable?: boolean;
|
|
481
|
-
}
|
|
482
|
-
/** Split with a theme and standard colour grid; the command arg is a `Color` or undefined. */
|
|
483
|
-
| {
|
|
484
|
-
kind: 'color';
|
|
485
|
-
command: string;
|
|
486
|
-
label: string;
|
|
487
|
-
icon: string;
|
|
488
|
-
} | {
|
|
489
|
-
kind: 'gallery';
|
|
490
|
-
command: string;
|
|
491
|
-
items: (ctx: EditorContext) => {
|
|
492
|
-
id: string;
|
|
493
|
-
label: string;
|
|
494
|
-
preview?: string;
|
|
495
|
-
}[];
|
|
496
|
-
}
|
|
497
|
-
/** Vertical stack of small controls. */
|
|
498
|
-
| {
|
|
499
|
-
kind: 'stack';
|
|
500
|
-
controls: RibbonControl[];
|
|
501
|
-
} | {
|
|
502
|
-
kind: 'separator';
|
|
503
|
-
};
|
|
504
|
-
type RibbonMenuItem = {
|
|
505
|
-
command: string;
|
|
506
|
-
arg?: unknown;
|
|
507
|
-
label?: string;
|
|
508
|
-
} | {
|
|
509
|
-
separator: true;
|
|
510
|
-
};
|
|
511
|
-
interface RibbonGroup {
|
|
512
|
-
id: string;
|
|
513
|
-
label: string;
|
|
514
|
-
controls: RibbonControl[];
|
|
515
|
-
/** Command id of the dialog launcher in the group corner. */
|
|
516
|
-
launcher?: string;
|
|
517
|
-
}
|
|
518
|
-
interface RibbonTab {
|
|
519
|
-
id: string;
|
|
520
|
-
label: string;
|
|
521
|
-
groups: RibbonGroup[];
|
|
522
|
-
/** Contextual tabs (Table Design, Chart Design) show only while this returns true. */
|
|
523
|
-
contextual?: (ctx: EditorContext) => boolean;
|
|
524
|
-
}
|
|
525
|
-
/** Adds or replaces tabs (by id). UI-COMMANDS calls this from `commands/index.ts`. */
|
|
526
|
-
declare function registerRibbonTabs(tabs: RibbonTab[]): void;
|
|
527
|
-
|
|
528
|
-
/** Adds or replaces a 24x24 line icon for ribbon commands. Returns false for an empty name or path. */
|
|
529
|
-
declare function registerRibbonIcon(name: string, path: string): boolean;
|
|
530
|
-
|
|
531
7
|
/** Editor state a framework passes down as props. */
|
|
532
8
|
interface EditorProps {
|
|
533
9
|
/** A workbook model to show. Re-assigned only when a new object is passed (never echoed back). */
|
|
@@ -616,5 +92,5 @@ declare function deferredHandle(current: () => EditorBinding | null | undefined)
|
|
|
616
92
|
/** All framework adapters share property, event and lifecycle semantics here. */
|
|
617
93
|
declare function mountEditor(host: HTMLElement, initial?: EditorOptions): EditorBinding;
|
|
618
94
|
|
|
619
|
-
export {
|
|
620
|
-
export type {
|
|
95
|
+
export { EDITOR_EVENT_NAMES, EDITOR_PROP_KEYS, deferredHandle, eventOptions, mountEditor, pickEditorProps };
|
|
96
|
+
export type { EditorBinding, EditorEventHandlers, EditorEventName, EditorEventOptions, EditorHandle, EditorOptions, EditorPropKey, EditorProps };
|