xlsx-svelte-viewer 1.5.0 → 2.1.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/README.md CHANGED
@@ -1,85 +1,142 @@
1
1
  # xlsx-svelte-viewer
2
2
 
3
+ **The Excel spreadsheet editor as a Svelte 5 component: open, edit, calculate and save `.xlsx`, `.xlsm`, `.xltx`, legacy `.xls` and `.csv` files in the browser.**
4
+
3
5
  [![npm version](https://img.shields.io/npm/v/xlsx-svelte-viewer.svg)](https://www.npmjs.com/package/xlsx-svelte-viewer)
4
6
  [![license](https://img.shields.io/npm/l/xlsx-svelte-viewer.svg)](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/LICENSE)
5
7
  [![types](https://img.shields.io/npm/types/xlsx-svelte-viewer.svg)](https://www.npmjs.com/package/xlsx-svelte-viewer)
6
8
 
7
- > A browser Excel spreadsheet editor for Svelte 5, using one shared editor and the canonical OOXML document engine.
8
-
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)
9
+ [Live demo](https://christophervr.github.io/ooxml/xlsx/demo-svelte/) · [Documentation](https://christophervr.github.io/ooxml/xlsx/) · [Svelte guide](https://christophervr.github.io/ooxml/xlsx/frameworks/svelte) · [Changelog](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/packages/svelte/CHANGELOG.md) · [Report a bug](https://github.com/ChristopherVR/ooxml/issues)
10
10
 
11
- Part of [ooxml](https://github.com/ChristopherVR/ooxml#readme): [Office](https://github.com/ChristopherVR/ooxml#ooxml-office-the-whole-suite-in-one-app) · [Word](https://github.com/ChristopherVR/ooxml/tree/main/viewers/docx#readme) · **[Excel](https://github.com/ChristopherVR/ooxml/tree/main/viewers/xlsx#readme)** · [PowerPoint](https://github.com/ChristopherVR/ooxml/tree/main/viewers/pptx#readme) · [Visio](https://github.com/ChristopherVR/ooxml/tree/main/viewers/visio#readme) · [OpenTeams](https://github.com/ChristopherVR/ooxml/tree/main/viewers/teams#readme) · [Core](https://github.com/ChristopherVR/ooxml/tree/main/src/core#readme)
11
+ ![The Excel editor with its ribbon, formula bar, grid and sheet tabs](https://raw.githubusercontent.com/ChristopherVR/ooxml/main/viewers/xlsx/docs/public/hero-editor.webp)
12
12
 
13
13
  ## Install
14
14
 
15
15
  ```bash
16
- npm install xlsx-svelte-viewer
16
+ npm install xlsx-svelte-viewer svelte
17
17
  ```
18
18
 
19
- Use the framework peers declared by this package: `svelte` (`^5.0.0`). Existing framework apps normally already provide them.
20
-
21
- The package bundles its editor UI and adapter. The core model and shared controls
22
- are installed as regular registry dependencies and the model API is re-exported.
23
- One viewer package is enough; no separate core install is required.
19
+ - Peer dependency: `svelte` `^5.0.0`.
20
+ - Bundled: the `<xlsx-editor>` web component and the Svelte adapter. Installed with it: `@christophervr/xlsx-core` (the workbook model, re-exported from this package), `ooxml-core` and `ooxml-ui`.
21
+ - Use one Excel editor package per application: each registers the same `<xlsx-editor>` element.
24
22
 
25
23
  ## Quick start
26
24
 
27
25
  ```svelte
28
26
  <script>
29
- import XlsxEditor from 'xlsx-svelte-viewer';
30
- import { createWorkbook } from 'xlsx-svelte-viewer/runtime';
31
- let workbook = $state.raw(createWorkbook());
27
+ import XlsxEditor from 'xlsx-svelte-viewer';
28
+
29
+ let editor;
32
30
  </script>
33
- <XlsxEditor {workbook} onworkbookchange={(next) => (workbook = next)} />
31
+
32
+ <button onclick={() => editor.download('Budget.xlsx')}>Download</button>
33
+ <XlsxEditor
34
+ bind:this={editor}
35
+ class="sheet"
36
+ src="/files/budget.xlsx"
37
+ fileName="Budget.xlsx"
38
+ ondirtychange={(dirty) => console.log('unsaved edits:', dirty)}
39
+ />
40
+
41
+ <style>
42
+ :global(.sheet) { height: 80vh; }
43
+ </style>
34
44
  ```
35
45
 
36
- Mount in the browser and give the host a height. Use one editor package per
37
- application: each registers the same editor custom element.
46
+ The component renders one host `<div>`, which `class` and `style` style: give it a height and the editor fills it and scrolls inside it. The package root is the component (default export); `createWorkbook`, `loadWorkbook`, `mountEditor` and the types are in `xlsx-svelte-viewer/runtime`. Hold a `workbook` prop in `$state.raw`. There is no stylesheet to import: the element carries its own styles. Without `src`, `bytes` or `workbook` the editor starts with a blank workbook.
47
+
48
+ ## Props
49
+
50
+ | Prop | What it does |
51
+ | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
52
+ | `workbook`, `bytes`, `src`, `fileName` | What to show: a workbook model, file bytes or a URL, and the name used by the title bar, Save and Download (default `Book1.xlsx`). |
53
+ | `readOnly` | Opens in Viewing mode (default `false`). |
54
+ | `locale` | Interface language (see [Localisation](#localisation)). |
55
+ | `theme`, `themeColors` | `light`, `dark` or `auto` (default), and `--xve-*` token overrides (see [Theming](#theming)). |
56
+ | `showToolbar`, `showFormulaBar` | Show or hide the ribbon and the formula bar (both default `true`). |
57
+ | `hiddenActions`, `ribbonAddIns` | Hide ribbon commands by stable id, or add your own tabs after Excel's. |
58
+ | `customization` | Capabilities, hidden ribbon tabs (File included), extra File pages and context-menu commands. |
59
+ | `storage`, `fileProviders` | Send File > Save and Open to your own storage, and add OneDrive or your own cloud places to File > Open. |
60
+ | `collaboration` | Join a shared room while set; `null` leaves it. |
61
+ | `imageProvider` | Opt in to `IMAGE` formulas with your own fetcher (without one they show `#BLOCKED!`). |
62
+ | `googleFonts` | Turn font downloads off (`false`) or point them at Google Fonts or your mirror (`{ baseUrl }`); unset leaves it to the reader (off by default). |
63
+ | `authorName`, `validateReplace` | The author of new comments (default `Author`), and whether Replace applies data validation (default `false`). |
64
+ | `class`, `style` | Class and inline style of the host `<div>` the editor fills. |
65
+
66
+ Props are forwarded only when their value changes, so a re-render never undoes what the user changed inside the editor (Editing or Viewing, theme, language, Customize Ribbon). Keep `customization`, `fileProviders` and `ribbonAddIns` stable between renders.
67
+
68
+ `bind:this` gives the component, whose exports are the editor handle, with live `element` and `dirty` properties (`isDirty()` and `getElement()` are deprecated). The handle has `load(bytes, fileName?)`, `newWorkbook()`, `save()`, `saveBytes('xlsx' | 'csv')`, `download(fileName?)`, `markClean()`, `openCloudFile(file)`, `select(ref)`, `getSelection()`, `setActiveSheet(index)`, `share()`, and the `dirty` and `element` properties. A method called before the editor has mounted throws `Editor is not mounted`.
69
+
70
+ Full reference: [framework bindings](https://christophervr.github.io/ooxml/xlsx/bindings) and the [element API](https://christophervr.github.io/ooxml/xlsx/api).
38
71
 
39
- ## Features
72
+ ## Events
40
73
 
41
- | Feature | Description |
42
- | ---------- | ----------------------------------------------------------------------------------- |
43
- | Editing | Shared grid, ribbon, formula bar, sheet tabs and workbook change events. |
44
- | Files | XLSX, XLSM, XLTX, legacy XLS and CSV loading through core. |
45
- | Model | `createWorkbook`, `loadWorkbook`, `saveXlsx` and core types from the package entry. |
46
- | Frameworks | The same `<xlsx-editor>` UI behind six thin adapters. |
74
+ | Callback prop | Receives |
75
+ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------- |
76
+ | `onworkbookchange` | The edited `Workbook`. |
77
+ | `ondirtychange` | `true` while there are unsaved edits. |
78
+ | `onworkbookerror` | An `Error` when a file or a `src` fetch fails to open. |
79
+ | `onfilecommand` | The cancelable `file-command` event: call `event.preventDefault()` to run New, Open, Save, Print and the rest yourself. |
80
+ | `onselectionchange` | `{ sheet, ref, active }`. |
81
+ | `onsheetchange` | `{ index, name }` of the new active sheet. |
82
+ | `onreadonlychange` | `(readOnly, { readOnly, locked, hostReadOnly })`; a controlled parent stores `hostReadOnly`. |
83
+ | `onworkbookwarning` | The loader's notes about content it could not read. |
84
+ | `onribbonaction` | `{ id }` of a command that ran. |
85
+ | `onribboncustomize` | The new hidden-action list after Customize Ribbon. |
86
+ | `onribbonaddin` | `{ tab, command }` of a host tab command. |
87
+ | `oncollaborationchange` | The sharing state. |
88
+ | `onready` | The `<xlsx-editor>` element, once mounted. |
47
89
 
48
- ## API
90
+ See [callbacks and events](https://christophervr.github.io/ooxml/xlsx/bindings#callbacks-and-events).
49
91
 
50
- Shared option types, `loadWorkbook` and `detectWorkbookFormat` helpers are exported
51
- from the package. `mountEditor(container, options)` returns an imperative binding
52
- with `load`, `save` and `destroy`. `ooxml-core` and `ooxml-ui` are regular
53
- dependencies. Parsing, formulas, editing and grid calculations live in core.
92
+ ## Open and save files
54
93
 
55
- The root exports the Svelte component; JavaScript helpers and model exports are
56
- under `xlsx-svelte-viewer/runtime`.
94
+ The editor opens `.xlsx`, `.xlsm` (macros never run), `.xltx`, password-protected workbooks, legacy `.xls` and `.csv`; `.xls` and `.csv` are saved as `.xlsx`. `save()` resolves to an `.xlsx` Blob and does not clear `dirty`: call `markClean()` once you have stored it, or use `download()`, which does both. `saveBytes('csv')` exports the active sheet. The model API (`createWorkbook`, `loadWorkbook`, `saveWorkbook`, `detectWorkbookFormat` and the rest of `@christophervr/xlsx-core`) is re-exported from `xlsx-svelte-viewer/runtime`, so headless work needs no second install. The editor mounts in an action, so the component is safe in server-rendered apps.
57
95
 
58
- ## Limitations
96
+ ## Theming
59
97
 
60
- This is an early editor, without Microsoft Excel parity or guaranteed lossless
61
- saving for unsupported features. Legacy XLS input saves as XLSX. Pivot tables,
62
- slicers and sparklines are supported for the cases the feature guide lists, but sparkline style galleries are not available; macros never execute. Review core
63
- diagnostics and the feature guide before relying on preservation.
98
+ `theme` picks `light`, `dark` or `auto`, and `themeColors` sets `--xve-*` tokens on the editor (for example `{ primary: '#1f9d63', radius: '6px' }`). The chrome also follows the shared `--office-*` tokens and a `data-office-theme` attribute on any ancestor; install them once with `installOfficeUiTheme()` from `ooxml-ui/theme`. Theme changes never alter workbook colours. See [theming](https://christophervr.github.io/ooxml/xlsx/theming).
64
99
 
65
- ## Documentation
100
+ ## Localisation
66
101
 
67
- [Framework guide](https://christophervr.github.io/ooxml/xlsx/frameworks/svelte) |
68
- [Bindings](https://christophervr.github.io/ooxml/xlsx/bindings)
102
+ The interface is available in English (`en`, the default, built in), French (`fr`), German (`de`), Spanish (`es`) and Simplified Chinese (`zh-CN`), set with `locale`. A tag that maps to one (`de-DE`, `zh-Hans`) works; any other falls back to English. Other languages load on demand. Workbook content and function names are never translated. See [localization](https://christophervr.github.io/ooxml/xlsx/localization).
103
+
104
+ ## Status and limits
105
+
106
+ Excel is **Stable** under the [stability policy](https://github.com/ChristopherVR/ooxml/blob/main/docs/stability.md): a frozen API under semver, a [preservation guarantee](https://christophervr.github.io/ooxml/xlsx/preservation) and native Excel save and reopen checks. It does not match Microsoft Excel feature for feature.
107
+
108
+ - `.xlsb` and `.ods` do not open.
109
+ - Macros never run (a `.xlsm` keeps its VBA project). External links, data connections and Power Query are kept with their cached values and never refreshed.
110
+ - PivotTables from external or OLAP sources and advanced pivot filters are kept but not editable; the sparkline style gallery is missing.
111
+ - Ink is drawn, erased and saved as Excel ink from the Draw tab, with the Ruler, and shared in a shared workbook (Ink to Math needs a handwriting recognizer the host supplies with `setInkMathRecognizer`; none is built in). Older OLE objects show as placeholders; form controls cannot be moved or resized, and buttons run no macro.
112
+ - In a shared room, pictures, ink, other drawings, page setup and PivotTables are not shared.
113
+
114
+ See [features and limitations](https://christophervr.github.io/ooxml/xlsx/features) and the [parity checklist](https://github.com/ChristopherVR/ooxml/blob/main/docs/parity-checklist.md).
69
115
 
70
116
  ## Privacy and network use
71
117
 
72
- The Excel packages make no network request when opening, rendering, editing or saving a document: linked pictures are not fetched, linked data is not refreshed, and fonts come from the device only, unless a reader turns on the Trust Center font download (off by default) or the host sets `googleFonts`. Hyperlinks open only when the reader follows them. Nothing collects analytics or telemetry. See [PRIVACY.md](https://github.com/ChristopherVR/ooxml/blob/main/PRIVACY.md).
118
+ Workbooks open, calculate, render, edit and save on the device. Nothing is uploaded, and nothing collects analytics or telemetry.
73
119
 
74
- ## License
120
+ - **Same-origin assets.** Workers, the selected non-English language, and chart, PivotTable, picture and shape tool code load on demand from your app's origin, carrying only the asset URL. Keep `locale` at `en` to skip language requests.
121
+ - **Fonts.** Off by default. Fonts the device lacks are downloaded from `fonts.googleapis.com` and `fonts.gstatic.com` only when the reader turns on File > Options > Trust Center "Download fonts that are not installed or embedded", or the host sets the `googleFonts` prop: `false` turns downloads off and locks the toggle, `{ baseUrl }` points at Google Fonts or your own mirror. Only public font family names are sent.
122
+ - **Linked content.** Linked pictures are not fetched, external links and linked data are not refreshed, and `WEBSERVICE` is not evaluated. `IMAGE` formulas fetch only through an `imageProvider` you pass.
123
+ - **Destinations you choose.** `src` fetches the URL you pass; sharing (`collaboration`, or a server URL the reader types in File > Share) talks only to that server, and without one connects tabs of the same browser only; OneDrive and other `fileProviders` only when you add them. Hyperlinks and the Forms link open only when the reader follows them.
124
+ - **On the device.** Small preferences, such as the font-download choice (`ooxml.xlsx.allowFontDownloads`), stay in localStorage.
75
125
 
76
- Apache-2.0.
126
+ See [PRIVACY.md](https://github.com/ChristopherVR/ooxml/blob/main/PRIVACY.md#word-excel-and-visio).
77
127
 
78
- ## OneDrive integration
128
+ ## Browser support
129
+
130
+ The last two major versions of Chrome, Edge, Firefox and Safari, and Safari 16.4 at least ([browser support](https://github.com/ChristopherVR/ooxml/blob/main/docs/browser-support.md)). Svelte 5. Node.js 22.3 or newer for builds, tests and server rendering. A slow calculation on open runs in a module worker from your origin, so a Content Security Policy must allow `worker-src 'self'`; without workers it runs on the page under the same time limit.
131
+
132
+ ## Documentation and demos
133
+
134
+ - [Documentation](https://christophervr.github.io/ooxml/xlsx/), the [Svelte guide](https://christophervr.github.io/ooxml/xlsx/frameworks/svelte) and the [live demo](https://christophervr.github.io/ooxml/xlsx/demo-svelte/).
135
+ - Your own interface around the grid: `createViewerBuildingBlocks` from `xlsx-svelte-viewer/runtime` with `xlsx-svelte-viewer/SpreadsheetCanvas.svelte`, `/Toolbar.svelte`, `/FormulaBar.svelte` and `/SheetTabs.svelte` ([building blocks](https://christophervr.github.io/ooxml/xlsx/building-blocks)).
136
+ - Other frameworks: [`@christophervr/xlsx-react-viewer`](https://www.npmjs.com/package/@christophervr/xlsx-react-viewer) · [`xlsx-vue-viewer`](https://www.npmjs.com/package/xlsx-vue-viewer) · [`xlsx-angular-viewer`](https://www.npmjs.com/package/xlsx-angular-viewer) · [`xlsx-solid-viewer`](https://www.npmjs.com/package/xlsx-solid-viewer) · [`xlsx-vanilla-viewer`](https://www.npmjs.com/package/xlsx-vanilla-viewer).
137
+ - Headless and agents: [`@christophervr/xlsx-core`](https://www.npmjs.com/package/@christophervr/xlsx-core) (the workbook model) and [`xlsx-viewer-mcp`](https://www.npmjs.com/package/xlsx-viewer-mcp) (MCP tools).
138
+ - Source: the [ooxml repository](https://github.com/ChristopherVR/ooxml).
139
+
140
+ ## License
79
141
 
80
- Use the optional shared `ooxml-core/embedding/onedrive` connection with host-supplied Microsoft
81
- sign-in. See the [Office package and integration reference](https://github.com/ChristopherVR/ooxml/blob/main/docs/onedrive-integration.md#excel-xlsx)
82
- for this product's load/save API, native storage wiring, sharing permissions and conflict recovery.
83
- The [testing guide](https://github.com/ChristopherVR/ooxml/blob/main/docs/onedrive-testing.md)
84
- separates test-local transports from live Microsoft acceptance. No simulation service is shipped;
85
- OneDrive storage does not provide Microsoft Office coauthoring or automatic document merging.
142
+ [Apache-2.0](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/LICENSE). See [NOTICE](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/NOTICE) for attributions.
@@ -15,8 +15,11 @@
15
15
  onribbonaddin?: EditorEventHandlers['office-ribbon-add-in'];
16
16
  oncollaborationchange?: EditorEventHandlers['collaboration-change'];
17
17
  onready?: EditorEventHandlers['ready'];
18
+ /** Class and inline style of the host `<div>`, as `className`/`class` on the other bindings. */
19
+ class?: string;
20
+ style?: string;
18
21
  };
19
- let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', validateReplace = false, showToolbar = true, showFormulaBar = true, hiddenActions = [], ribbonAddIns, themeColors, collaboration, customization, storage, fileProviders, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready }: Props = $props();
22
+ let { workbook, bytes, src, fileName, readOnly = false, locale = 'en', theme = 'auto', authorName = 'Author', validateReplace = false, showToolbar = true, showFormulaBar = true, hiddenActions = [], ribbonAddIns, themeColors, collaboration, customization, storage, fileProviders, imageProvider, googleFonts, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready, class: className, style }: Props = $props();
20
23
  let binding: EditorBinding | undefined;
21
24
  const handle = deferredHandle(() => binding);
22
25
  // Live `element` and `dirty`, the same handle vocabulary as the other frameworks (`EDITOR_HANDLE_KEYS`).
@@ -49,4 +52,4 @@
49
52
  export function getElement() { return binding?.element; }
50
53
  export { element, dirty };
51
54
  </script>
52
- <div use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, validateReplace, showToolbar, showFormulaBar, hiddenActions, ribbonAddIns, themeColors, collaboration, customization, storage, fileProviders, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready }}></div>
55
+ <div class={className} {style} use:attach={{ workbook, bytes, src, fileName, readOnly, locale, theme, authorName, validateReplace, showToolbar, showFormulaBar, hiddenActions, ribbonAddIns, themeColors, collaboration, customization, storage, fileProviders, imageProvider, googleFonts, onworkbookchange, onworkbookerror, onselectionchange, ondirtychange, onreadonlychange, onfilecommand, onworkbookwarning, onribbonaction, onribboncustomize, onsheetchange, onribbonaddin, oncollaborationchange, onready }}></div>
package/dist/runtime.d.ts CHANGED
@@ -4,9 +4,10 @@ import * as ooxml_core_collab from 'ooxml-core/collab';
4
4
  import { EditorLocaleInput, EditorThemeMode, RibbonAddInTab, XlsxThemeColors, XlsxCollaborationOptions, ExcelCustomization, SelectionChangeDetail, FileCommandDetail, RibbonAddInCommandDetail, XlsxCollaborationState, XlsxEditorElement, SurfaceHostActions, ValidationErrorDetail, FormatCellsOperations, FindOperations, InsertFunctionOperations, ContextMenuKind, ContextMenuModel, SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
5
5
  export * from 'ooxml-ui/xlsx';
6
6
  export { SpreadsheetToolbarProps } from 'ooxml-ui/xlsx';
7
- import { Workbook } from '@christophervr/xlsx-core';
7
+ import { Workbook, ImageProvider } from '@christophervr/xlsx-core';
8
8
  export * from '@christophervr/xlsx-core';
9
9
  import { DocumentStorage, CloudFileProvider, CloudOpenedFile } from 'ooxml-core/embedding';
10
+ import { GoogleFontsOption } from 'ooxml-core/text';
10
11
  import { BindingContract } from 'ooxml-ui/bindings';
11
12
  export { LegacyXlsError, WorkbookFormat, csvToWorkbook, detectWorkbookFormat, loadLegacyXls, loadWorkbook, parseCsv, saveWorkbook, sheetToCsv } from '@christophervr/xlsx-core/load';
12
13
  import * as svelte_store from 'svelte/store';
@@ -53,12 +54,20 @@ interface EditorProps {
53
54
  * File > Open to `storage.open()` when it has one. `file-command` still fires first.
54
55
  */
55
56
  storage?: DocumentStorage | null | undefined;
57
+ /** Host opt-in for IMAGE formulas. */
58
+ imageProvider?: ImageProvider | undefined;
56
59
  /**
57
60
  * Cloud places (OneDrive, or a host's own `CloudFileProvider`) File > Open offers next to "This
58
61
  * device". A workbook opened from one saves back to that file; empty or omitted keeps Open as it
59
62
  * was. Forwarded when the array changes, so keep it stable.
60
63
  */
61
64
  fileProviders?: readonly CloudFileProvider[] | null | undefined;
65
+ /**
66
+ * Webfont fallback for fonts the reader has neither installed nor embedded: `false` is off,
67
+ * `{ baseUrl }` downloads them from that CSS2 endpoint. Unset (or `null`), the reader's File >
68
+ * Options > Trust Center choice applies, which is off by default.
69
+ */
70
+ googleFonts?: GoogleFontsOption | null | undefined;
62
71
  /**
63
72
  * Host customisation (`ExcelCustomization`): `capabilities`, `backstage.extraPages` and
64
73
  * `contextMenu.extraCommands`. Forwarded when the object changes, so keep it stable (memoise
@@ -111,7 +120,7 @@ interface EditorEventOptions {
111
120
  interface EditorOptions extends EditorProps, EditorEventOptions {
112
121
  }
113
122
  /** Single source of truth for the prop keys every adapter forwards. */
114
- declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "validateReplace", "showToolbar", "showFormulaBar", "hiddenActions", "ribbonAddIns", "themeColors", "collaboration", "storage", "fileProviders", "customization"];
123
+ declare const EDITOR_PROP_KEYS: readonly ["workbook", "bytes", "src", "fileName", "readOnly", "locale", "theme", "authorName", "validateReplace", "showToolbar", "showFormulaBar", "hiddenActions", "ribbonAddIns", "themeColors", "collaboration", "storage", "fileProviders", "imageProvider", "googleFonts", "customization"];
115
124
  type EditorPropKey = (typeof EDITOR_PROP_KEYS)[number];
116
125
  /** Single source of truth for the element events every adapter surfaces. */
117
126
  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"];
package/dist/runtime.js CHANGED
@@ -41,6 +41,8 @@ var j = [
41
41
  "collaboration",
42
42
  "storage",
43
43
  "fileProviders",
44
+ "imageProvider",
45
+ "googleFonts",
44
46
  "customization"
45
47
  ], M = [
46
48
  "workbook-change",
@@ -55,7 +57,11 @@ var j = [
55
57
  "sheet-change",
56
58
  "office-ribbon-add-in",
57
59
  "collaboration-change"
58
- ], N = {
60
+ ];
61
+ function N(e, t) {
62
+ return (e ?? void 0) === (t ?? void 0) || typeof e == "object" && typeof t == "object" && e?.baseUrl === t?.baseUrl;
63
+ }
64
+ var P = {
59
65
  props: {
60
66
  locale: {
61
67
  forward: "changed",
@@ -98,10 +104,15 @@ var j = [
98
104
  forward: "changed",
99
105
  apply: (e, t) => e.storage = t ?? void 0
100
106
  },
107
+ imageProvider: { forward: "changed" },
101
108
  fileProviders: {
102
109
  forward: "changed",
103
110
  apply: (e, t) => e.fileProviders = t ?? []
104
111
  },
112
+ googleFonts: {
113
+ forward: "changed",
114
+ same: N
115
+ },
105
116
  themeColors: {
106
117
  forward: "changed",
107
118
  same: l,
@@ -167,23 +178,23 @@ var j = [
167
178
  share: "call",
168
179
  dirty: { fallback: !1 }
169
180
  }
170
- }, P = ["onReady"];
171
- function F(e) {
172
- return o(N, e);
173
- }
181
+ }, F = ["onReady"];
174
182
  function I(e) {
183
+ return o(P, e);
184
+ }
185
+ function L(e) {
175
186
  return {
176
- ...a(N, e),
187
+ ...a(P, e),
177
188
  onReady: e.ready
178
189
  };
179
190
  }
180
- function L(e) {
181
- return t(N, e, u, P);
182
- }
183
191
  function R(e) {
184
- return r(N.handle, e);
192
+ return t(P, e, u, F);
185
193
  }
186
- var z = [
194
+ function z(e) {
195
+ return r(P.handle, e);
196
+ }
197
+ var B = [
187
198
  "element",
188
199
  "load",
189
200
  "newWorkbook",
@@ -199,14 +210,14 @@ var z = [
199
210
  "dirty"
200
211
  ];
201
212
  // packages/bindings/src/index.ts
202
- function B(t, r = {}, i = !1) {
213
+ function V(t, r = {}, i = !1) {
203
214
  (0, k.defineXlsxEditor)();
204
215
  let a = t.ownerDocument.createElement("xlsx-editor");
205
216
  if (i && typeof a.getToolbarProps != "function") throw Error("Update ooxml-ui to use editor building blocks.");
206
217
  a.surfaceOnly = i;
207
218
  let o = {}, s, c, l, u, d = !1, f = (e) => {
208
219
  d || o.onWorkbookError?.(e instanceof Error ? e : Error(String(e)));
209
- }, p = (e, t) => a.load(e, t).catch(() => void 0), m = n(p, f), h = e(a, N, () => o, { onEvent: (e, t) => {
220
+ }, p = (e, t) => a.load(e, t).catch(() => void 0), m = n(p, f), h = e(a, P, () => o, { onEvent: (e, t) => {
210
221
  e === "workbook-change" && (c = t.detail.workbook);
211
222
  } }), g = {
212
223
  element: a,
@@ -233,7 +244,7 @@ function B(t, r = {}, i = !1) {
233
244
  };
234
245
  return g.update(r), t.append(a), o.onReady?.(a), g;
235
246
  }
236
- var V = [
247
+ var H = [
237
248
  "onOpenShareDialog",
238
249
  "onOpenSettings",
239
250
  "onOpenFormatCells",
@@ -243,14 +254,14 @@ var V = [
243
254
  "onContextMenu",
244
255
  "onContextMenuItems"
245
256
  ];
246
- function H(e, t = {}) {
257
+ function U(e, t = {}) {
247
258
  let n = t, r = (e) => ({
248
259
  ...e,
249
260
  readOnly: e.canEdit !== !0 || e.readOnly === !0
250
- }), i = B(e, r(t), !0), { element: a } = i, o = i.update, s = i.destroy, c = {}, l = (e) => {
251
- if (V.every((t) => c[t] === e[t])) return;
261
+ }), i = V(e, r(t), !0), { element: a } = i, o = i.update, s = i.destroy, c = {}, l = (e) => {
262
+ if (H.every((t) => c[t] === e[t])) return;
252
263
  let t = {};
253
- for (let n of V) t[n] = e[n];
264
+ for (let n of H) t[n] = e[n];
254
265
  c = t, a.surfaceActions = t;
255
266
  }, u = (e) => n.onValidationError?.(e.detail);
256
267
  return a.addEventListener("validation-error", u), l(t), Object.assign(i, {
@@ -265,35 +276,35 @@ function H(e, t = {}) {
265
276
  });
266
277
  }
267
278
  // packages/bindings/src/common.ts
268
- var U = /* @__PURE__ */ E({
279
+ var W = /* @__PURE__ */ E({
269
280
  LegacyXlsError: () => d,
270
281
  csvToWorkbook: () => f,
271
282
  detectWorkbookFormat: () => p,
272
283
  loadLegacyXls: () => m,
273
284
  loadWorkbook: () => h,
274
- mountEditorSurface: () => H,
285
+ mountEditorSurface: () => U,
275
286
  parseCsv: () => g,
276
287
  saveWorkbook: () => _,
277
288
  sheetToCsv: () => v
278
289
  });
279
- O(U, k);
290
+ O(W, k);
280
291
  // packages/bindings/src/building-blocks.ts
281
- var W = Object.freeze({
292
+ var G = Object.freeze({
282
293
  active: !1,
283
294
  roomId: void 0,
284
295
  status: "off",
285
296
  synced: !1,
286
297
  people: []
287
298
  });
288
- function G(e) {
299
+ function K(e) {
289
300
  return {
290
301
  dirty: e?.dirty ?? !1,
291
302
  selection: e?.selection ?? "",
292
- collaboration: e?.collaboration ?? W,
303
+ collaboration: e?.collaboration ?? G,
293
304
  editError: e?.editError ?? null
294
305
  };
295
306
  }
296
- function K(e) {
307
+ function q(e) {
297
308
  let t = null, n, r, i = {}, a = null, o = !1, s = () => {
298
309
  let t = n?.element.loading ?? !1;
299
310
  t && !o && (a = null), o = t;
@@ -303,7 +314,7 @@ function K(e) {
303
314
  loading: n?.element.loading ?? !1,
304
315
  error: a,
305
316
  mode: i.canEdit !== !0 || i.readOnly ? "view" : "edit",
306
- ...G(r)
317
+ ...K(r)
307
318
  });
308
319
  }, c = () => ({
309
320
  ...i,
@@ -314,9 +325,9 @@ function K(e) {
314
325
  t = null, r?.(), r = void 0, n?.destroy(), n = void 0, s();
315
326
  };
316
327
  return {
317
- handle: R(() => n),
328
+ handle: z(() => n),
318
329
  mount(e) {
319
- e && e === t || (l(), e && (a = null, n = H(e, c()), t = e, r = n.subscribe(s), s()));
330
+ e && e === t || (l(), e && (a = null, n = U(e, c()), t = e, r = n.subscribe(s), s()));
320
331
  },
321
332
  update(e) {
322
333
  (e.workbook !== i.workbook || e.bytes !== i.bytes || e.src !== i.src) && (a = null), i = e, n?.update(c()), s();
@@ -324,20 +335,20 @@ function K(e) {
324
335
  destroy: l
325
336
  };
326
337
  }
327
- var q = () => ({
338
+ var J = () => ({
328
339
  toolbarProps: null,
329
340
  loading: !1,
330
341
  error: null,
331
342
  mode: "view",
332
- ...G(null)
333
- }), J = (e, t) => t === null ? [{
343
+ ...K(null)
344
+ }), Y = (e, t) => t === null ? [{
334
345
  value: "",
335
346
  label: ""
336
347
  }, ...e] : e.some((e) => e.value === t) ? e : [{
337
348
  value: t,
338
349
  label: t
339
350
  }, ...e];
340
- function Y(e) {
351
+ function X(e) {
341
352
  let t = (t) => e.labels[t] ?? t, n = (t) => !e.canEdit || !t, r = (e, t, n, r, i) => ({
342
353
  kind: "button",
343
354
  id: e,
@@ -355,7 +366,7 @@ function Y(e) {
355
366
  label: t("Font"),
356
367
  value: e.fontFamily ?? "",
357
368
  disabled: n(e.enabled.fontFamily),
358
- options: J(e.options.fontFamilies.map((e) => ({
369
+ options: Y(e.options.fontFamilies.map((e) => ({
359
370
  value: e,
360
371
  label: e
361
372
  })), e.fontFamily),
@@ -367,7 +378,7 @@ function Y(e) {
367
378
  label: t("Font Size"),
368
379
  value: e.fontSize === null ? "" : String(e.fontSize),
369
380
  disabled: n(e.enabled.fontSize),
370
- options: J(e.options.fontSizes.map((e) => ({
381
+ options: Y(e.options.fontSizes.map((e) => ({
371
382
  value: String(e),
372
383
  label: String(e)
373
384
  })), e.fontSize === null ? null : String(e.fontSize)),
@@ -383,12 +394,12 @@ function Y(e) {
383
394
  label: t("Number Format"),
384
395
  value: e.numberFormat ?? "",
385
396
  disabled: n(e.enabled.numberFormat),
386
- options: J(e.options.numberFormats, e.numberFormat),
397
+ options: Y(e.options.numberFormats, e.numberFormat),
387
398
  change: (t) => e.onNumberFormatChange(t)
388
399
  }
389
400
  ];
390
401
  }
391
- function X(e, t) {
402
+ function Z(e, t) {
392
403
  try {
393
404
  return e.onSelect(t);
394
405
  } catch {
@@ -396,14 +407,14 @@ function X(e, t) {
396
407
  }
397
408
  }
398
409
  // packages/bindings/src/block-theme.ts
399
- function Z(e, t) {
410
+ function Q(e, t) {
400
411
  if (!e || typeof e != "object" || !("ownerDocument" in e)) return;
401
412
  let n = e, r = Reflect.get(x, "prepareOfficeUiBlock");
402
413
  typeof r == "function" ? r(n, t, "xlsx") : (x.installOfficeUiTheme(n.ownerDocument), n.setAttribute("data-office-block", t), n.setAttribute("data-office-product", "xlsx"));
403
414
  }
404
415
  // packages/svelte/src/building-blocks.ts
405
- function Q(e = {}) {
406
- let t = b(q()), n = K(t.set);
416
+ function $(e = {}) {
417
+ let t = b(J()), n = q(t.set);
407
418
  return n.update(e), y(n.destroy), {
408
419
  subscribe: t.subscribe,
409
420
  update: n.update,
@@ -413,28 +424,28 @@ function Q(e = {}) {
413
424
  };
414
425
  }
415
426
  O(/* @__PURE__ */ E({
416
- EDITOR_CALLBACKS: () => P,
417
- EDITOR_CONTRACT: () => N,
427
+ EDITOR_CALLBACKS: () => F,
428
+ EDITOR_CONTRACT: () => P,
418
429
  EDITOR_EVENT_NAMES: () => M,
419
- EDITOR_HANDLE_KEYS: () => z,
430
+ EDITOR_HANDLE_KEYS: () => B,
420
431
  EDITOR_PROP_KEYS: () => j,
421
432
  LegacyXlsError: () => d,
422
- createViewerBuildingBlocks: () => Q,
433
+ createViewerBuildingBlocks: () => $,
423
434
  csvToWorkbook: () => f,
424
- deferredHandle: () => R,
435
+ deferredHandle: () => z,
425
436
  detectWorkbookFormat: () => p,
426
- eventOptions: () => I,
437
+ eventOptions: () => L,
427
438
  loadLegacyXls: () => m,
428
439
  loadWorkbook: () => h,
429
- mountEditor: () => B,
430
- mountEditorSurface: () => H,
440
+ mountEditor: () => V,
441
+ mountEditorSurface: () => U,
431
442
  parseCsv: () => g,
432
- pickEditorProps: () => F,
433
- prepareBlock: () => Z,
443
+ pickEditorProps: () => I,
444
+ prepareBlock: () => Q,
434
445
  saveWorkbook: () => _,
435
- selectReference: () => X,
446
+ selectReference: () => Z,
436
447
  sheetToCsv: () => v,
437
- svelteEditorOptions: () => L,
438
- toolbarModel: () => Y
439
- }), U);
440
- export { P as EDITOR_CALLBACKS, N as EDITOR_CONTRACT, M as EDITOR_EVENT_NAMES, z as EDITOR_HANDLE_KEYS, j as EDITOR_PROP_KEYS, d as LegacyXlsError, Q as createViewerBuildingBlocks, f as csvToWorkbook, R as deferredHandle, p as detectWorkbookFormat, I as eventOptions, m as loadLegacyXls, h as loadWorkbook, B as mountEditor, H as mountEditorSurface, g as parseCsv, F as pickEditorProps, Z as prepareBlock, _ as saveWorkbook, X as selectReference, v as sheetToCsv, L as svelteEditorOptions, Y as toolbarModel };
448
+ svelteEditorOptions: () => R,
449
+ toolbarModel: () => X
450
+ }), W);
451
+ export { F as EDITOR_CALLBACKS, P as EDITOR_CONTRACT, M as EDITOR_EVENT_NAMES, B as EDITOR_HANDLE_KEYS, j as EDITOR_PROP_KEYS, d as LegacyXlsError, $ as createViewerBuildingBlocks, f as csvToWorkbook, z as deferredHandle, p as detectWorkbookFormat, L as eventOptions, m as loadLegacyXls, h as loadWorkbook, V as mountEditor, U as mountEditorSurface, g as parseCsv, I as pickEditorProps, Q as prepareBlock, _ as saveWorkbook, Z as selectReference, v as sheetToCsv, R as svelteEditorOptions, X as toolbarModel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xlsx-svelte-viewer",
3
- "version": "1.5.0",
3
+ "version": "2.1.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",
@@ -66,11 +66,14 @@
66
66
  "access": "public"
67
67
  },
68
68
  "dependencies": {
69
- "@christophervr/xlsx-core": "^1.1.2",
70
- "ooxml-core": "^1.50.0",
71
- "ooxml-ui": "^1.50.0"
69
+ "@christophervr/xlsx-core": "^2.0.1",
70
+ "ooxml-core": "^2.5.0",
71
+ "ooxml-ui": "^2.5.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "svelte": "^5.0.0"
75
+ },
76
+ "engines": {
77
+ "node": ">=22.3"
75
78
  }
76
79
  }