@extend-ai/react-xlsx 0.18.1 → 0.19.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 +154 -6
- package/dist/chart-renderer-3K2VKB5I.js +5042 -0
- package/dist/chart-renderer-3K2VKB5I.js.map +1 -0
- package/dist/{chart-renderer-ZUWRNNZT.cjs → chart-renderer-HVOEAQXK.cjs} +5 -5
- package/dist/{chart-renderer-ZUWRNNZT.cjs.map → chart-renderer-HVOEAQXK.cjs.map} +1 -1
- package/dist/chart-renderer-LHXMRBGR.cjs +5043 -0
- package/dist/chart-renderer-LHXMRBGR.cjs.map +1 -0
- package/dist/{chart-renderer-HQSQHDCB.js → chart-renderer-R2B4I2HL.js} +2 -2
- package/dist/chunk-3O2QY6LA.js +50 -0
- package/dist/{chunk-OZLJPZUX.js.map → chunk-3O2QY6LA.js.map} +1 -1
- package/dist/chunk-4VX5HTCF.cjs +50 -0
- package/dist/chunk-4VX5HTCF.cjs.map +1 -0
- package/dist/chunk-CJBI5F6V.cjs +816 -0
- package/dist/chunk-CJBI5F6V.cjs.map +1 -0
- package/dist/chunk-NBH72POD.js +816 -0
- package/dist/chunk-NBH72POD.js.map +1 -0
- package/dist/{chunk-OZLJPZUX.js → chunk-O7S3Y6II.js} +10 -6
- package/dist/chunk-O7S3Y6II.js.map +1 -0
- package/dist/{chunk-FO6MIHX4.cjs → chunk-T5WZHPIN.cjs} +2 -2
- package/dist/{chunk-FO6MIHX4.cjs.map → chunk-T5WZHPIN.cjs.map} +1 -1
- package/dist/chunk-TYJLNPNE.cjs +26972 -0
- package/dist/chunk-TYJLNPNE.cjs.map +1 -0
- package/dist/chunk-Y737JKUG.js +26969 -0
- package/dist/chunk-Y737JKUG.js.map +1 -0
- package/dist/{chunk-WFQGZI2Z.cjs → chunk-ZIO47YMT.cjs} +12 -8
- package/dist/chunk-ZIO47YMT.cjs.map +1 -0
- package/dist/index.cjs +588 -11267
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -14
- package/dist/index.d.ts +3 -14
- package/dist/index.js +474 -11153
- package/dist/index.js.map +1 -1
- package/dist/internal-DSz8QMhK.d.cts +1496 -0
- package/dist/internal-DSz8QMhK.d.ts +1496 -0
- package/dist/internal.cjs +24 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +3 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +23 -0
- package/dist/internal.js.map +1 -0
- package/dist/{region-map-geography-5E5SVPGS.cjs → region-map-geography-6TGXBY3V.cjs} +2 -2
- package/dist/{region-map-geography-5E5SVPGS.cjs.map → region-map-geography-6TGXBY3V.cjs.map} +1 -1
- package/dist/{spreadsheet-font-assets-7QMV43XD.cjs → spreadsheet-font-assets-4AHYDTAQ.cjs} +2 -2
- package/dist/{spreadsheet-font-assets-7QMV43XD.cjs.map → spreadsheet-font-assets-4AHYDTAQ.cjs.map} +1 -1
- package/dist/surface-regl-KW4JL325.js +723 -0
- package/dist/surface-regl-KW4JL325.js.map +1 -0
- package/dist/surface-regl-MAPCPD7W.cjs +724 -0
- package/dist/surface-regl-MAPCPD7W.cjs.map +1 -0
- package/dist/{surface-regl-WVLW3SEA.cjs → surface-regl-PWTZWQQS.cjs} +2 -2
- package/dist/{surface-regl-WVLW3SEA.cjs.map → surface-regl-PWTZWQQS.cjs.map} +1 -1
- package/dist/vanilla.cjs +20 -0
- package/dist/vanilla.cjs.map +1 -0
- package/dist/vanilla.d.cts +9 -0
- package/dist/vanilla.d.ts +9 -0
- package/dist/vanilla.js +19 -0
- package/dist/vanilla.js.map +1 -0
- package/dist/xlsx-worker.js +2888 -34
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +23 -3
- package/dist/chunk-WFQGZI2Z.cjs.map +0 -1
- /package/dist/{chart-renderer-HQSQHDCB.js.map → chart-renderer-R2B4I2HL.js.map} +0 -0
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# @extend-ai/react-xlsx
|
|
2
2
|
|
|
3
|
-
React components and
|
|
3
|
+
React components, hooks, and a vanilla JavaScript API for rendering `.xlsx` workbooks in the browser.
|
|
4
4
|
|
|
5
5
|
`@extend-ai/react-xlsx` gives you:
|
|
6
6
|
|
|
7
7
|
- A drop-in `XlsxViewer` for workbook previews
|
|
8
|
+
- A `createXlsxViewer` API for mounting the viewer from plain JavaScript
|
|
8
9
|
- A provider/controller API for custom spreadsheet experiences
|
|
9
10
|
- Worksheet rendering with frozen panes, tables, merged cells, conditional formatting, sparklines, selection, resizing, copy/paste, and zoom
|
|
10
11
|
- Embedded worksheet images, shapes, form controls, charts, and chartsheet tabs
|
|
@@ -15,14 +16,14 @@ React components and hooks for rendering `.xlsx` workbooks in the browser.
|
|
|
15
16
|
## Install
|
|
16
17
|
|
|
17
18
|
```bash
|
|
18
|
-
npm install @extend-ai/react-xlsx
|
|
19
|
+
npm install @extend-ai/react-xlsx
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
```bash
|
|
22
|
-
pnpm add @extend-ai/react-xlsx
|
|
23
|
+
pnpm add @extend-ai/react-xlsx
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
`react` and `react-dom` are peer dependencies.
|
|
26
|
+
For the React entry, install `react` and `react-dom` as well. They are optional peer dependencies and are not needed by the vanilla entry.
|
|
26
27
|
|
|
27
28
|
## Automatic Chart Loading
|
|
28
29
|
|
|
@@ -105,11 +106,38 @@ If several routes use the viewer, import the same setup module from a shared cli
|
|
|
105
106
|
|
|
106
107
|
Configured string, URL, Request URL, bytes, and `WebAssembly.Module` sources are forwarded into the XLSX worker. `Response` sources are supported on the main thread; worker-backed parsing is skipped for that source type.
|
|
107
108
|
|
|
108
|
-
|
|
109
|
+
In Vite development, exclude the vanilla entry from dependency optimization so Vite can resolve the worker asset. Production builds do not need this setting:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { defineConfig } from "vite";
|
|
113
|
+
|
|
114
|
+
export default defineConfig({
|
|
115
|
+
optimizeDeps: { exclude: ["@extend-ai/react-xlsx/vanilla"] }
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
For the React entry, exclude the shared entries and let Vite optimize React separately:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { defineConfig } from "vite";
|
|
123
|
+
|
|
124
|
+
export default defineConfig({
|
|
125
|
+
optimizeDeps: {
|
|
126
|
+
exclude: ["@extend-ai/react-xlsx", "@extend-ai/react-xlsx/vanilla", "@extend-ai/react-xlsx/internal"],
|
|
127
|
+
include: ["react", "react-dom", "react-dom/client", "react/jsx-runtime"]
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
You can also call `initWasm()` (optionally with a source) ahead of time to warm the module before the first workbook is opened. Vanilla applications can import these functions from `@extend-ai/react-xlsx/vanilla`.
|
|
109
133
|
|
|
110
134
|
## Main Entry Points
|
|
111
135
|
|
|
112
|
-
The package
|
|
136
|
+
The package provides a vanilla JavaScript entry point and three levels of React API:
|
|
137
|
+
|
|
138
|
+
- `@extend-ai/react-xlsx/vanilla` exports `createXlsxViewer`, the `XlsxViewer` instance class, and utilities for JavaScript applications.
|
|
139
|
+
|
|
140
|
+
`@extend-ai/react-xlsx` exports:
|
|
113
141
|
|
|
114
142
|
1. `XlsxViewer`
|
|
115
143
|
A ready-to-render workbook viewer with built-in toolbar, sheet tabs, grid rendering, charts, images, and selection state.
|
|
@@ -122,6 +150,126 @@ The package exports three useful levels of API:
|
|
|
122
150
|
|
|
123
151
|
## Quick Start
|
|
124
152
|
|
|
153
|
+
### Vanilla JavaScript
|
|
154
|
+
|
|
155
|
+
Use the vanilla entry point to mount the viewer in an existing DOM element. The viewer uses a bundled Preact renderer and does not require React or JSX. The React component wraps the same viewer implementation. The instance creates a `div` in the regular DOM, so application styles and focus behavior continue to apply.
|
|
156
|
+
|
|
157
|
+
The examples below use a browser bundler such as Vite to resolve the package import. For Vite development, use the [worker configuration above](#webassembly-asset).
|
|
158
|
+
|
|
159
|
+
#### Open a workbook from a URL
|
|
160
|
+
|
|
161
|
+
```html
|
|
162
|
+
<div id="viewer"></div>
|
|
163
|
+
<script type="module" src="/main.js"></script>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
import { createXlsxViewer } from "@extend-ai/react-xlsx/vanilla";
|
|
168
|
+
|
|
169
|
+
const viewer = createXlsxViewer(document.getElementById("viewer"), {
|
|
170
|
+
src: "/workbook.xlsx",
|
|
171
|
+
height: 600,
|
|
172
|
+
readOnly: true,
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The URL must be accessible to the browser. A workbook on another origin needs the appropriate CORS headers. Omit `readOnly` to allow editing.
|
|
177
|
+
|
|
178
|
+
You can also construct an instance directly:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
import { XlsxViewer } from "@extend-ai/react-xlsx/vanilla";
|
|
182
|
+
|
|
183
|
+
const viewer = new XlsxViewer(document.getElementById("viewer"), {
|
|
184
|
+
src: "/workbook.xlsx",
|
|
185
|
+
height: 600,
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### Open a local workbook
|
|
190
|
+
|
|
191
|
+
The `file` option accepts workbook bytes as an `ArrayBuffer`. This standalone example starts with an empty viewer and loads the file selected by the user:
|
|
192
|
+
|
|
193
|
+
```html
|
|
194
|
+
<input id="workbook" type="file" accept=".xlsx,.xlsm,.xls" />
|
|
195
|
+
<div id="viewer"></div>
|
|
196
|
+
<script type="module" src="/main.js"></script>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
import { createXlsxViewer } from "@extend-ai/react-xlsx/vanilla";
|
|
201
|
+
|
|
202
|
+
const viewer = createXlsxViewer(document.getElementById("viewer"), {
|
|
203
|
+
height: 600,
|
|
204
|
+
emptyState: "Choose a workbook to preview.",
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
document.getElementById("workbook").addEventListener("change", async (event) => {
|
|
208
|
+
const file = event.currentTarget.files?.[0];
|
|
209
|
+
if (!file) return;
|
|
210
|
+
|
|
211
|
+
viewer.setOptions({ file: await file.arrayBuffer(), fileName: file.name });
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### Read state and control the viewer
|
|
216
|
+
|
|
217
|
+
Subscribe to loading, errors, sheet changes, selection, and other controller updates:
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
const unsubscribe = viewer.subscribe((controller) => {
|
|
221
|
+
if (controller.error) {
|
|
222
|
+
console.error(controller.error);
|
|
223
|
+
} else if (controller.isLoading) {
|
|
224
|
+
console.log("Loading workbook…");
|
|
225
|
+
} else if (controller.sheets.length > 0) {
|
|
226
|
+
console.log(controller.activeSheet?.name, controller.selectedRangeAddress);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Read the latest controller when invoking a command. These commands should run after the workbook has loaded:
|
|
232
|
+
|
|
233
|
+
```js
|
|
234
|
+
const controller = viewer.getController();
|
|
235
|
+
|
|
236
|
+
if (controller && !controller.isLoading && controller.sheets.length > 0) {
|
|
237
|
+
controller.highlightRanges("A1:C5");
|
|
238
|
+
if (!controller.readOnly) controller.setCellValue({ row: 0, col: 0 }, "42");
|
|
239
|
+
if (controller.canExport) controller.exportXlsx();
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`setCellValue` requires an editable workbook. `exportXlsx()` downloads the current workbook in the browser.
|
|
244
|
+
|
|
245
|
+
Change options or load another workbook with `setOptions`:
|
|
246
|
+
|
|
247
|
+
```js
|
|
248
|
+
viewer.setOptions({ isDark: true, readOnly: true });
|
|
249
|
+
viewer.setOptions({ src: "/another-workbook.xlsx", fileName: undefined });
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Supplying `file` clears the previous `src`, and supplying `src` clears the previous `file`. To release the viewer when it is no longer needed:
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
unsubscribe();
|
|
256
|
+
viewer.destroy();
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
`createXlsxViewer` returns an object with these methods:
|
|
260
|
+
|
|
261
|
+
- `getController()` returns the latest `XlsxViewerController`, or `null` when no controller is available or after destruction. Read it again when invoking commands so you have the current state and methods.
|
|
262
|
+
- `subscribe(listener)` reports controller updates, including loading, errors, sheets, selection, zoom, edits, and the existing controller commands. If a controller is already available, the listener is called immediately. Updates can be coalesced. The return value unsubscribes the listener.
|
|
263
|
+
- `setOptions(options)` merges new options into the current ones. Supplying `file` clears `src`, and supplying `src` clears `file`. `file` accepts an `ArrayBuffer`; convert a browser `File` with `await file.arrayBuffer()`.
|
|
264
|
+
- `reload()` discards the current viewer state and reloads the current source.
|
|
265
|
+
- `destroy()` unmounts the viewer, releases its resources, and removes listeners. It is safe to call more than once.
|
|
266
|
+
|
|
267
|
+
`subscribe` also exposes `isLoadDeferred` and `continueDeferredLoad()` for deferred workbooks.
|
|
268
|
+
|
|
269
|
+
`XlsxVanillaViewerOptions` supports the non-React viewer options, including `getCellStyle`, form-control events, themes, worker settings, and highlighting. `toolbar`, loading/empty/error states, and the `renderActiveCellOverlay`, `renderChartLoading`, `renderContextMenu`, `renderFormControl`, and `renderImage` callbacks accept text or DOM nodes. Their vanilla callback props omit React's `defaultNode`. React-specific custom scroller, image-selection, and table-header render callbacks are not available through this entry point.
|
|
270
|
+
|
|
271
|
+
The vanilla entry also exports `setWasmSource`, `initWasm`, `parseXlsxRange`, and workbook types. The same WASM, worker, font, and chart assets need to be served as in the React integration.
|
|
272
|
+
|
|
125
273
|
### Basic viewer
|
|
126
274
|
|
|
127
275
|
Use `XlsxViewer` when you want the smallest integration surface.
|