xlsx-svelte-viewer 2.0.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 +93 -85
- package/dist/XlsxEditor.svelte +5 -2
- package/dist/runtime.d.ts +11 -2
- package/dist/runtime.js +65 -54
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# xlsx-svelte-viewer
|
|
2
2
|
|
|
3
|
-
**The Excel editor
|
|
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
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/xlsx-svelte-viewer)
|
|
6
6
|
[](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/LICENSE)
|
|
7
|
-
[](https://www.npmjs.com/package/xlsx-svelte-viewer)
|
|
8
8
|
|
|
9
|
-
[Live demo](https://christophervr.github.io/ooxml/xlsx/demo-svelte/) · [Documentation](https://christophervr.github.io/ooxml/xlsx/) · [Changelog](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/packages/svelte/CHANGELOG.md) · [Report a bug](https://github.com/ChristopherVR/ooxml/issues)
|
|
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
11
|

|
|
12
12
|
|
|
@@ -16,29 +16,12 @@
|
|
|
16
16
|
npm install xlsx-svelte-viewer svelte
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
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.
|
|
20
22
|
|
|
21
23
|
## Quick start
|
|
22
24
|
|
|
23
|
-
```svelte
|
|
24
|
-
<script>
|
|
25
|
-
import XlsxEditor from 'xlsx-svelte-viewer';
|
|
26
|
-
import { createWorkbook } from 'xlsx-svelte-viewer/runtime';
|
|
27
|
-
|
|
28
|
-
let workbook = $state.raw(createWorkbook());
|
|
29
|
-
</script>
|
|
30
|
-
|
|
31
|
-
<div style="height: 100vh">
|
|
32
|
-
<XlsxEditor {workbook} onworkbookchange={(next) => (workbook = next)} />
|
|
33
|
-
</div>
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Give the editor a height: the grid fills its container and scrolls inside it. Use one Excel editor package per application, since each registers the same `<xlsx-editor>` element.
|
|
37
|
-
|
|
38
|
-
## Open and save files
|
|
39
|
-
|
|
40
|
-
Pass `bytes` (with `fileName`) or a `src` URL to open a file, and use the handle to save:
|
|
41
|
-
|
|
42
25
|
```svelte
|
|
43
26
|
<script>
|
|
44
27
|
import XlsxEditor from 'xlsx-svelte-viewer';
|
|
@@ -47,88 +30,113 @@ Pass `bytes` (with `fileName`) or a `src` URL to open a file, and use the handle
|
|
|
47
30
|
</script>
|
|
48
31
|
|
|
49
32
|
<button onclick={() => editor.download('Budget.xlsx')}>Download</button>
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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>
|
|
58
44
|
```
|
|
59
45
|
|
|
60
|
-
The
|
|
61
|
-
|
|
62
|
-
##
|
|
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).
|
|
71
|
+
|
|
72
|
+
## Events
|
|
73
|
+
|
|
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. |
|
|
89
|
+
|
|
90
|
+
See [callbacks and events](https://christophervr.github.io/ooxml/xlsx/bindings#callbacks-and-events).
|
|
63
91
|
|
|
64
|
-
|
|
65
|
-
- **A calculation engine.** More than 500 functions, dynamic arrays, `LET` and `LAMBDA`, automatic or manual calculation and iterative calculation. Each formula has a work budget, and a slow calculation on open runs in a worker, so a workbook cannot freeze the page.
|
|
66
|
-
- **Formatting.** Fonts, fills, borders, number formats, merged cells, tables, outline groups, data validation and conditional formatting with colour scales, data bars and icon sets.
|
|
67
|
-
- **Objects.** Charts drawn from live values and edited from the Chart Design tab and Format pane, SmartArt, shapes, pictures, sparklines, worksheet PivotTables and slicers, and form controls linked to cells.
|
|
68
|
-
- **Collaboration.** Optional real-time co-editing between tabs of one browser, or across machines through a y-websocket compatible server you run.
|
|
69
|
-
- **Five interface languages.** English, French, German, Spanish and Simplified Chinese through `locale`. Workbook content is never translated.
|
|
70
|
-
- **Keyboard and screen reader support.** F6 regions, Excel's shortcuts, a grid that reads as a table, and forced-colours support.
|
|
71
|
-
|
|
72
|
-
## Svelte notes
|
|
92
|
+
## Open and save files
|
|
73
93
|
|
|
74
|
-
-
|
|
75
|
-
- Callbacks are lower-case props: `onworkbookchange`, `onselectionchange`, `ondirtychange`, `onfilecommand` and the others in the [bindings guide](https://christophervr.github.io/ooxml/xlsx/bindings#callbacks-and-events).
|
|
76
|
-
- `bind:this` gives the component, whose exports are the [handle](#the-handle): `load`, `save`, `download` and the rest, plus live `element` and `dirty` properties.
|
|
77
|
-
- Hold the workbook in `$state.raw`: it is a large plain object, and deep reactivity adds nothing but cost.
|
|
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.
|
|
78
95
|
|
|
79
|
-
##
|
|
96
|
+
## Theming
|
|
80
97
|
|
|
81
|
-
|
|
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).
|
|
82
99
|
|
|
83
|
-
|
|
84
|
-
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
85
|
-
| `workbook`, `bytes`, `src`, `fileName` | What to show: a model, file bytes or a URL, and the name used by the title bar, Save and Download. |
|
|
86
|
-
| `readOnly` | Opens in Viewing mode. |
|
|
87
|
-
| `locale` | `en`, `fr`, `de`, `es` or `zh-CN` (tags such as `de-DE` map to one). |
|
|
88
|
-
| `theme`, `themeColors` | `light`, `dark` or `auto`, and `--xve-*` token overrides. See [theming](https://christophervr.github.io/ooxml/xlsx/theming). |
|
|
89
|
-
| `showToolbar`, `showFormulaBar` | Show or hide the ribbon and the formula bar. |
|
|
90
|
-
| `hiddenActions`, `ribbonAddIns` | Hide ribbon commands by id, or add your own tabs after Excel's. |
|
|
91
|
-
| `customization` | Capabilities, hidden ribbon tabs (`ribbon.hiddenTabs`, including File), extra backstage pages and menu items. |
|
|
92
|
-
| `storage`, `fileProviders` | Send Save and Open to your own storage, and offer OneDrive or your own cloud places in File > Open. |
|
|
93
|
-
| `collaboration` | Join a shared room. See [collaboration](https://christophervr.github.io/ooxml/xlsx/collaboration). |
|
|
94
|
-
| `authorName`, `validateReplace` | The author of new comments, and whether Replace applies data validation. |
|
|
100
|
+
## Localisation
|
|
95
101
|
|
|
96
|
-
|
|
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).
|
|
97
103
|
|
|
98
|
-
|
|
104
|
+
## Status and limits
|
|
99
105
|
|
|
100
|
-
|
|
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.
|
|
101
107
|
|
|
102
|
-
|
|
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.
|
|
103
113
|
|
|
104
|
-
|
|
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).
|
|
105
115
|
|
|
106
|
-
|
|
107
|
-
- **Node.js:** 22.3 or newer for builds, tests and server rendering. The package imports without a DOM; the editor itself runs in the browser.
|
|
108
|
-
- **Workers:** a workbook that needs a long calculation on open is calculated in a module worker that bundlers pick up from `new Worker(new URL(..., import.meta.url))`. A Content Security Policy must allow `worker-src 'self'`; without workers the calculation runs on the page under the same time limit.
|
|
116
|
+
## Privacy and network use
|
|
109
117
|
|
|
110
|
-
|
|
118
|
+
Workbooks open, calculate, render, edit and save on the device. Nothing is uploaded, and nothing collects analytics or telemetry.
|
|
111
119
|
|
|
112
|
-
|
|
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.
|
|
113
125
|
|
|
114
|
-
-
|
|
115
|
-
- Macros never run; a `.xlsm` keeps its VBA project on save.
|
|
116
|
-
- External links, Power Query, OLAP and external-source PivotTables are kept but never refreshed, and `WEBSERVICE` is not evaluated.
|
|
117
|
-
- A few functions are not implemented (`ASC`, `DBCS`, `JIS`, `PHONETIC`, `INFO`, `WEBSERVICE`) and show `#NAME?`.
|
|
118
|
-
- Ink and OLE objects show as placeholders. In a shared room, pictures, other drawings and page setup stay local.
|
|
126
|
+
See [PRIVACY.md](https://github.com/ChristopherVR/ooxml/blob/main/PRIVACY.md#word-excel-and-visio).
|
|
119
127
|
|
|
120
|
-
##
|
|
128
|
+
## Browser support
|
|
121
129
|
|
|
122
|
-
The
|
|
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.
|
|
123
131
|
|
|
124
|
-
##
|
|
132
|
+
## Documentation and demos
|
|
125
133
|
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
- [`xlsx-viewer-
|
|
129
|
-
- [
|
|
130
|
-
-
|
|
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).
|
|
131
139
|
|
|
132
140
|
## License
|
|
133
141
|
|
|
134
|
-
[Apache-2.0](https://github.com/ChristopherVR/ooxml/blob/main/viewers/xlsx/LICENSE)
|
|
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.
|
package/dist/XlsxEditor.svelte
CHANGED
|
@@ -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
|
-
]
|
|
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
|
-
},
|
|
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(
|
|
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
|
|
192
|
+
return t(P, e, u, F);
|
|
185
193
|
}
|
|
186
|
-
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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 =
|
|
251
|
-
if (
|
|
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
|
|
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
|
|
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: () =>
|
|
285
|
+
mountEditorSurface: () => U,
|
|
275
286
|
parseCsv: () => g,
|
|
276
287
|
saveWorkbook: () => _,
|
|
277
288
|
sheetToCsv: () => v
|
|
278
289
|
});
|
|
279
|
-
O(
|
|
290
|
+
O(W, k);
|
|
280
291
|
// packages/bindings/src/building-blocks.ts
|
|
281
|
-
var
|
|
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
|
|
299
|
+
function K(e) {
|
|
289
300
|
return {
|
|
290
301
|
dirty: e?.dirty ?? !1,
|
|
291
302
|
selection: e?.selection ?? "",
|
|
292
|
-
collaboration: e?.collaboration ??
|
|
303
|
+
collaboration: e?.collaboration ?? G,
|
|
293
304
|
editError: e?.editError ?? null
|
|
294
305
|
};
|
|
295
306
|
}
|
|
296
|
-
function
|
|
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
|
-
...
|
|
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:
|
|
328
|
+
handle: z(() => n),
|
|
318
329
|
mount(e) {
|
|
319
|
-
e && e === t || (l(), e && (a = null, n =
|
|
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
|
|
338
|
+
var J = () => ({
|
|
328
339
|
toolbarProps: null,
|
|
329
340
|
loading: !1,
|
|
330
341
|
error: null,
|
|
331
342
|
mode: "view",
|
|
332
|
-
...
|
|
333
|
-
}),
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
397
|
+
options: Y(e.options.numberFormats, e.numberFormat),
|
|
387
398
|
change: (t) => e.onNumberFormatChange(t)
|
|
388
399
|
}
|
|
389
400
|
];
|
|
390
401
|
}
|
|
391
|
-
function
|
|
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
|
|
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
|
|
406
|
-
let t = b(
|
|
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: () =>
|
|
417
|
-
EDITOR_CONTRACT: () =>
|
|
427
|
+
EDITOR_CALLBACKS: () => F,
|
|
428
|
+
EDITOR_CONTRACT: () => P,
|
|
418
429
|
EDITOR_EVENT_NAMES: () => M,
|
|
419
|
-
EDITOR_HANDLE_KEYS: () =>
|
|
430
|
+
EDITOR_HANDLE_KEYS: () => B,
|
|
420
431
|
EDITOR_PROP_KEYS: () => j,
|
|
421
432
|
LegacyXlsError: () => d,
|
|
422
|
-
createViewerBuildingBlocks: () =>
|
|
433
|
+
createViewerBuildingBlocks: () => $,
|
|
423
434
|
csvToWorkbook: () => f,
|
|
424
|
-
deferredHandle: () =>
|
|
435
|
+
deferredHandle: () => z,
|
|
425
436
|
detectWorkbookFormat: () => p,
|
|
426
|
-
eventOptions: () =>
|
|
437
|
+
eventOptions: () => L,
|
|
427
438
|
loadLegacyXls: () => m,
|
|
428
439
|
loadWorkbook: () => h,
|
|
429
|
-
mountEditor: () =>
|
|
430
|
-
mountEditorSurface: () =>
|
|
440
|
+
mountEditor: () => V,
|
|
441
|
+
mountEditorSurface: () => U,
|
|
431
442
|
parseCsv: () => g,
|
|
432
|
-
pickEditorProps: () =>
|
|
433
|
-
prepareBlock: () =>
|
|
443
|
+
pickEditorProps: () => I,
|
|
444
|
+
prepareBlock: () => Q,
|
|
434
445
|
saveWorkbook: () => _,
|
|
435
|
-
selectReference: () =>
|
|
446
|
+
selectReference: () => Z,
|
|
436
447
|
sheetToCsv: () => v,
|
|
437
|
-
svelteEditorOptions: () =>
|
|
438
|
-
toolbarModel: () =>
|
|
439
|
-
}),
|
|
440
|
-
export {
|
|
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": "2.
|
|
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,9 +66,9 @@
|
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@christophervr/xlsx-core": "^2.0.
|
|
70
|
-
"ooxml-core": "^2.
|
|
71
|
-
"ooxml-ui": "^2.
|
|
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"
|