@extend-ai/react-xlsx 0.20.11 → 0.21.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 +171 -4
- package/dist/{chunk-VSM7WKLM.js → chunk-2UFSVI5Z.js} +565 -142
- package/dist/chunk-2UFSVI5Z.js.map +1 -0
- package/dist/{chunk-SXHHFUXA.cjs → chunk-7IL4KLCD.cjs} +1729 -1306
- package/dist/chunk-7IL4KLCD.cjs.map +1 -0
- package/dist/{chunk-OGZ6ROZC.cjs → chunk-A3S3QKJN.cjs} +445 -3
- package/dist/chunk-A3S3QKJN.cjs.map +1 -0
- package/dist/chunk-IRC7BQ6E.js +538 -0
- package/dist/chunk-IRC7BQ6E.js.map +1 -0
- package/dist/{chunk-CVMHJO5H.js → chunk-WHTV6N6S.js} +443 -1
- package/dist/chunk-WHTV6N6S.js.map +1 -0
- package/dist/chunk-ZPDHTVL6.cjs +538 -0
- package/dist/chunk-ZPDHTVL6.cjs.map +1 -0
- package/dist/index.cjs +245 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -2
- package/dist/index.d.ts +135 -2
- package/dist/index.js +203 -117
- package/dist/index.js.map +1 -1
- package/dist/{internal-BBaC9yCh.d.cts → internal-BO70EPFy.d.cts} +130 -2
- package/dist/{internal-BBaC9yCh.d.ts → internal-BO70EPFy.d.ts} +130 -2
- package/dist/internal.cjs +3 -3
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +2 -2
- package/dist/{shared-chart-XOCTF7KQ.js → shared-chart-7RUN5IKZ.js} +6 -4
- package/dist/shared-chart-7RUN5IKZ.js.map +1 -0
- package/dist/{shared-chart-CIRSCWTO.cjs → shared-chart-P3KU6TQR.cjs} +15 -13
- package/dist/shared-chart-P3KU6TQR.cjs.map +1 -0
- package/dist/{shared-chart-BLOOGI7S.js → shared-chart-UTUK46E4.js} +6 -4
- package/dist/shared-chart-UTUK46E4.js.map +1 -0
- package/dist/{shared-chart-4LUQQI2B.cjs → shared-chart-VRXD57MU.cjs} +6 -4
- package/dist/shared-chart-VRXD57MU.cjs.map +1 -0
- package/dist/vanilla.cjs +3 -3
- package/dist/vanilla.d.cts +2 -2
- package/dist/vanilla.d.ts +2 -2
- package/dist/vanilla.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-7GBCRNGO.js +0 -94
- package/dist/chunk-7GBCRNGO.js.map +0 -1
- package/dist/chunk-CVMHJO5H.js.map +0 -1
- package/dist/chunk-MFOGLSFJ.cjs +0 -94
- package/dist/chunk-MFOGLSFJ.cjs.map +0 -1
- package/dist/chunk-OGZ6ROZC.cjs.map +0 -1
- package/dist/chunk-SXHHFUXA.cjs.map +0 -1
- package/dist/chunk-VSM7WKLM.js.map +0 -1
- package/dist/shared-chart-4LUQQI2B.cjs.map +0 -1
- package/dist/shared-chart-BLOOGI7S.js.map +0 -1
- package/dist/shared-chart-CIRSCWTO.cjs.map +0 -1
- package/dist/shared-chart-XOCTF7KQ.js.map +0 -1
package/README.md
CHANGED
|
@@ -266,7 +266,7 @@ viewer.destroy();
|
|
|
266
266
|
|
|
267
267
|
`subscribe` also exposes `isLoadDeferred` and `continueDeferredLoad()` for deferred workbooks.
|
|
268
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.
|
|
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`, `renderCellEditorOverlay`, `renderSelectionPopover`, `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
270
|
|
|
271
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
272
|
|
|
@@ -635,6 +635,147 @@ The hook receives `context` (target kind, cell, selection, sheet index/name, and
|
|
|
635
635
|
|
|
636
636
|
Default styling follows the document theme. Override `.react-xlsx-context-menu`, `.react-xlsx-context-menu-item`, `.react-xlsx-context-menu-separator`, and `.react-xlsx-context-menu-shortcut`, or set `--xlsx-context-menu-background`, `--xlsx-context-menu-color`, `--xlsx-context-menu-border`, `--xlsx-context-menu-hover`, `--xlsx-context-menu-muted`, and `--xlsx-context-menu-danger` through `contextMenuStyle`. The menu is portaled to the document body, so use its class rather than a viewer-descendant selector. Set `enableContextMenu={false}` to retain the browser's native context menu.
|
|
637
637
|
|
|
638
|
+
## Custom Cell Editor Overlays
|
|
639
|
+
|
|
640
|
+
`renderCellEditorOverlay` adds your own decoration and actions around the live cell editor. It runs only while editing, never when merely selecting a cell. The library supplies no default menu, AI client, or animation. The separate `renderSelectionPopover` callback handles selections outside editing. React callbacks return React content; vanilla callbacks return DOM nodes. `cellEditorStyle` customizes the built-in editor's appearance without replacing its input or text measurement.
|
|
641
|
+
|
|
642
|
+
```tsx
|
|
643
|
+
import type { XlsxCellEditorContext, XlsxCellEditorOverlayRenderProps } from "@extend-ai/react-xlsx";
|
|
644
|
+
|
|
645
|
+
function FormulaActions({ editor, generateFormula }: {
|
|
646
|
+
editor: XlsxCellEditorOverlayRenderProps;
|
|
647
|
+
generateFormula: (request: { prompt: string; context: XlsxCellEditorContext; signal: AbortSignal }) => Promise<string>;
|
|
648
|
+
}) {
|
|
649
|
+
const [busy, setBusy] = React.useState(false);
|
|
650
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
651
|
+
|
|
652
|
+
async function generate() {
|
|
653
|
+
const prompt = editor.getValue();
|
|
654
|
+
if (prompt === null) return;
|
|
655
|
+
setBusy(true);
|
|
656
|
+
setError(null);
|
|
657
|
+
try {
|
|
658
|
+
const formula = await generateFormula({
|
|
659
|
+
prompt,
|
|
660
|
+
context: editor.context,
|
|
661
|
+
signal: editor.signal,
|
|
662
|
+
});
|
|
663
|
+
if (editor.getValue() === prompt) editor.preview(formula);
|
|
664
|
+
} catch (cause) {
|
|
665
|
+
if (!editor.signal.aborted) setError(String(cause));
|
|
666
|
+
} finally {
|
|
667
|
+
if (!editor.signal.aborted) setBusy(false);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return (
|
|
672
|
+
<div style={{ position: "absolute", top: "calc(100% + 8px)", pointerEvents: "auto" }}>
|
|
673
|
+
{editor.isPreview ? (
|
|
674
|
+
<>
|
|
675
|
+
<button onClick={() => editor.commit()}>Keep</button>
|
|
676
|
+
<button onClick={() => editor.discardPreview()}>Discard</button>
|
|
677
|
+
</>
|
|
678
|
+
) : (
|
|
679
|
+
<button disabled={busy} onClick={generate}>Write formula</button>
|
|
680
|
+
)}
|
|
681
|
+
{error && <div role="alert">{error}</div>}
|
|
682
|
+
</div>
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
<XlsxViewer
|
|
687
|
+
file={file}
|
|
688
|
+
cellEditorStyle={{ borderRadius: 4, boxShadow: "inset 0 0 0 2px #64748b" }}
|
|
689
|
+
renderCellEditorOverlay={(editor) => (
|
|
690
|
+
<FormulaActions editor={editor} generateFormula={callYourBackend} />
|
|
691
|
+
)}
|
|
692
|
+
/>
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
`context` contains the zero-based `cell`, `sheetIndex` (an index in `controller.sheets`), `sheetName`, the saved `originalValue`, and the editing `trigger`: `"double-click"`, `"typing"`, `"keyboard"`, or `"context-menu"`. For assistance only after double-clicking and changing the text, check `context.trigger === "double-click" && value !== context.originalValue`. `value` is the current draft. `editorElement` is the native editor element, available for anchoring and scoped styles or effects; undo DOM changes when your component unmounts. `rect` is the expanded editor's rectangle in viewport pixels, updated as the input grows, the worksheet scrolls, or zoom changes.
|
|
696
|
+
|
|
697
|
+
| Member | Behavior |
|
|
698
|
+
| --- | --- |
|
|
699
|
+
| `getValue()` | Reads the latest draft, or `null` after the session ends. |
|
|
700
|
+
| `setValue(text)` | Replaces the draft without saving it. Ordinary editing commit behavior still applies. |
|
|
701
|
+
| `preview(text)` | Shows a proposed replacement and marks it for review, retaining the previous draft. |
|
|
702
|
+
| `isPreview` | Indicates that the draft is an unconfirmed preview. |
|
|
703
|
+
| `discardPreview()` | Restores the draft from before the preview and focuses the input. |
|
|
704
|
+
| `commit(text?)` | Saves the supplied input, or the current draft, and ends editing. Uses normal formula parsing and undo history. |
|
|
705
|
+
| `cancel()` | Ends editing without saving any draft or preview. |
|
|
706
|
+
| `focus()` | Returns focus to the native editor. |
|
|
707
|
+
| `signal` | An `AbortSignal` cancelled when the editing session ends or changes target. |
|
|
708
|
+
|
|
709
|
+
Commands return `false` after their session ends, so a delayed response cannot write to a different cell. For requests that depend on the draft, also compare `getValue()` with the submitted text before applying a result. Pass `signal` to your backend request. Use `commit(formula)` for direct application, or `preview(formula)` for a review flow. Previewing does not write to the workbook: Enter or `commit()` accepts it; Escape or leaving the editor cancels it. Tab/arrow navigation also leaves an unconfirmed preview unsaved. Repeated `preview()` calls preserve the draft from before the first preview.
|
|
710
|
+
|
|
711
|
+
The overlay is an unstyled portal positioned over the actual expanded input in both canvas and DOM rendering. Its container ignores pointer events: set `pointerEvents: "auto"` on interactive content. Place actions below it with `top: "calc(100% + 8px)"`; render a full-size decorative wrapper to draw a custom border around it. Your wrapper may use CSS, a canvas shader, or an animation component. The native input remains underneath, preserving caret behavior and formula highlighting. `rect` lets your UI choose an alternate placement near window edges. Apply sizing and scrolling to your own panels as needed.
|
|
712
|
+
|
|
713
|
+
Interactions inside the overlay keep the edit session open. Alt+ArrowDown from the editor focuses its first control. The overlay isolates keyboard events from grid navigation; your components own their roles and navigation. Return `null` to render no decoration or controls. Without `renderCellEditorOverlay`, no overlay is mounted.
|
|
714
|
+
|
|
715
|
+
Your menu items and their callbacks belong entirely to your renderer. A callback can call `setValue(formula)` to replace the editor text and update your component's state or the `renderCellEditorOverlay` prop to display different controls. Use `preview(formula)` when you also want the library to retain the previous draft for Discard and prevent unconfirmed changes from saving on blur. To apply immediately, call `commit(formula)`; it saves the cell and closes the editor. There is no required menu model, review screen, or confirmation step. When using a UI component that creates its own portal, mount it into an element inside your overlay so focus and pointer interactions remain within the edit session.
|
|
716
|
+
|
|
717
|
+
All animation belongs to your rendered component, including its origin, easing, duration, and exit behavior. The library does not animate the overlay container. Anchor a popover to an element that fills the overlay, animate its opacity and scale from that anchor, and disable position transitions on its positioning element to avoid movement from an initial unpositioned location. Retain the current menu content throughout an exit animation instead of switching back to suggestions while closing. Respect reduced-motion preferences in your renderer.
|
|
718
|
+
|
|
719
|
+
Vanilla JavaScript uses the same session commands:
|
|
720
|
+
|
|
721
|
+
```js
|
|
722
|
+
const viewer = createXlsxViewer(container, {
|
|
723
|
+
file: workbookBytes,
|
|
724
|
+
renderCellEditorOverlay(editor) {
|
|
725
|
+
const button = document.createElement("button");
|
|
726
|
+
button.textContent = editor.isPreview ? "Keep" : "Write formula";
|
|
727
|
+
Object.assign(button.style, {
|
|
728
|
+
position: "absolute", top: "calc(100% + 8px)", pointerEvents: "auto",
|
|
729
|
+
});
|
|
730
|
+
button.onclick = async () => {
|
|
731
|
+
if (editor.isPreview) { editor.commit(); return; }
|
|
732
|
+
const prompt = editor.getValue();
|
|
733
|
+
if (prompt === null) return;
|
|
734
|
+
button.disabled = true;
|
|
735
|
+
try {
|
|
736
|
+
const formula = await callYourBackend({ prompt, context: editor.context, signal: editor.signal });
|
|
737
|
+
if (editor.getValue() === prompt) editor.preview(formula);
|
|
738
|
+
} catch (error) {
|
|
739
|
+
if (!editor.signal.aborted) showError(error);
|
|
740
|
+
} finally {
|
|
741
|
+
if (!editor.signal.aborted) button.disabled = false;
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
return button;
|
|
745
|
+
},
|
|
746
|
+
});
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
The render callback is called as the draft and editor geometry change. Return a stable DOM node when preserving state in custom vanilla controls. The playground opts into this API while typing in the cell editor, using animated Coss UI popovers and a text shimmer during preview. Its “Write formula (Demo formula)” callback immediately previews a deterministic formula referencing multiple ranges and switches the actions to Keep and Discard. In the starter workbook it averages the three curve columns, excluding the target cell to avoid a circular reference. Other worksheets use a deterministic three-range formula that excludes the target column. It does not call an AI backend. The effects and controls live entirely in the playground renderer.
|
|
750
|
+
|
|
751
|
+
The playground also demonstrates a Coss UI “Generate formula” context-menu submenu through `renderContextMenu`. Its instruction input supports formula previews and a “heatmap” demo that previews numeric-cell colors through `getCellStyle`, then saves them through `setCellStyles` only on Keep. Discard removes the temporary styles. Context-menu render props expose `signal` and `commit(callback)` so custom backend actions can reject stale menus and apply arbitrary synchronous controller changes. Mount nested menu portals inside your custom renderer and stop keyboard propagation when your UI handles navigation.
|
|
752
|
+
|
|
753
|
+
## Custom Selection Popovers
|
|
754
|
+
|
|
755
|
+
`renderSelectionPopover` is independently opt-in and works for a cell or range selection in React and vanilla JavaScript. It is hidden during editing and supplies no default controls, styles, or animations. The callback receives `context` (`cell`, normalized `selection`, `sheetIndex`, `sheetName`, `readOnly`), the visible selection `rect` in viewport pixels, `signal`, `close()`, `applyFormula(formula)`, and `commit(callback)` for other synchronous mutations.
|
|
756
|
+
|
|
757
|
+
`applyFormula` writes to the active cell with normal undo history, closes the popover, and returns `false` if the selection has expired or is read-only. `signal` aborts when the popover closes, the selection changes, or editing starts. Preview a backend result in your own component state before applying it; Discard can simply call `close()`. To update a range or perform another action, use `commit(() => controller.setCellStyles(updates))` or another synchronous controller mutation. `setCellStyles([{ cell, style }, ...])` applies individually styled cells as one undoable edit and preserves them in XLSX exports. Check the signal before applying async results.
|
|
758
|
+
|
|
759
|
+
```tsx
|
|
760
|
+
<XlsxViewer
|
|
761
|
+
controller={controller}
|
|
762
|
+
renderSelectionPopover={(selection) => (
|
|
763
|
+
<YourFormulaPopover
|
|
764
|
+
selection={selection.context.selection}
|
|
765
|
+
onGenerate={(instructions) => callYourBackend({
|
|
766
|
+
prompt: instructions,
|
|
767
|
+
context: selection.context,
|
|
768
|
+
signal: selection.signal,
|
|
769
|
+
})}
|
|
770
|
+
onKeep={selection.applyFormula}
|
|
771
|
+
onDiscard={selection.close}
|
|
772
|
+
/>
|
|
773
|
+
)}
|
|
774
|
+
/>
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
The unstyled portal fills the visible selection bounds. Set `pointerEvents: "auto"` on interactive content and position it below with `top: "calc(100% + 8px)"`, or use your own anchored popover. Mount nested UI portals into a host inside this container. Input focus and keyboard events are isolated from the worksheet. Vanilla renderers receive the same props and return DOM nodes. Both selection and editor renderers can be configured together or used separately.
|
|
778
|
+
|
|
638
779
|
## Custom Rendering
|
|
639
780
|
|
|
640
781
|
The viewer exposes render props for common UI integration points.
|
|
@@ -661,10 +802,10 @@ export function CustomWorkbook({ file }: { file: ArrayBuffer }) {
|
|
|
661
802
|
{triggerIcon}
|
|
662
803
|
</button>
|
|
663
804
|
<button type="button" onClick={sortAscending}>
|
|
664
|
-
Sort
|
|
805
|
+
Sort ascending{direction === "ascending" ? " selected" : ""}
|
|
665
806
|
</button>
|
|
666
807
|
<button type="button" onClick={sortDescending}>
|
|
667
|
-
Sort
|
|
808
|
+
Sort descending{direction === "descending" ? " selected" : ""}
|
|
668
809
|
</button>
|
|
669
810
|
<span>{column.name}</span>
|
|
670
811
|
</span>
|
|
@@ -676,6 +817,29 @@ export function CustomWorkbook({ file }: { file: ArrayBuffer }) {
|
|
|
676
817
|
|
|
677
818
|
Apply `triggerProps` to the table-header trigger button so clicks do not leak into grid selection.
|
|
678
819
|
|
|
820
|
+
### Locale and UI text
|
|
821
|
+
|
|
822
|
+
The built-in header and context menus use **Sort ascending** / **Sort descending** in English, with translations selected by `locale`. The toolbar, sheet and grid accessibility labels, cell editor, form-control fallback labels, loading/empty/error states, and chart fallbacks use the same locale. Changing `locale` or `messages` updates the UI without reloading the workbook.
|
|
823
|
+
|
|
824
|
+
Bundled UI languages are English (`en`), French (`fr`), German (`de`), Spanish (`es`), Italian (`it`), Portuguese (`pt`), Japanese (`ja`), and Simplified Chinese (`zh`). Regional tags use their language catalog, so `fr-CA` uses French. Unsupported languages fall back to English for UI text; number formatting still uses the requested locale. Supply `messages` to add another language or change any wording.
|
|
825
|
+
|
|
826
|
+
```tsx
|
|
827
|
+
<XlsxViewer
|
|
828
|
+
file={file}
|
|
829
|
+
locale="fr-FR"
|
|
830
|
+
messages={{
|
|
831
|
+
sortAscending: "Ordre croissant",
|
|
832
|
+
sortDescending: "Ordre décroissant",
|
|
833
|
+
openMenuForColumn: "Options de {column}",
|
|
834
|
+
}}
|
|
835
|
+
/>
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
`messages` is also accepted by `useXlsxViewerController`, `XlsxViewerProvider`, and the vanilla viewer options. With a supplied controller or provider, configure `locale` there so formatting and UI use the same locale. A viewer's `messages` prop overrides its controller's messages for that viewer. Resolved text is available as `controller.messages` for custom UI.
|
|
839
|
+
|
|
840
|
+
Message values are plain strings. Keep `{column}` in `openMenuForColumn`, `{sheet}` in `worksheetGrid`, `hiddenSheet`, and `veryHiddenSheet`, `{size}` and `{limit}` in `fileTooLarge`, and `{size}` in `deferredLoadDescription` wherever those values should appear. Values are inserted as text. Workbook content and custom render callbacks keep the text supplied by the workbook or application. Default errors use localized messages; the original error is available through `controller.error` and `errorState`.
|
|
841
|
+
|
|
842
|
+
|
|
679
843
|
Use `renderActiveCellOverlay` to render your own content over the active cell. The returned node sits in a container that exactly covers the cell (the full merge for merged cells) and moves with scrolling and zoom, so you can attach classes, data attributes, or a ref and measure it with `getBoundingClientRect()`. The container ignores pointer events; set `pointerEvents: "auto"` on your own elements to make them interactive.
|
|
680
844
|
|
|
681
845
|
```tsx
|
|
@@ -763,7 +927,8 @@ Common source and loading props:
|
|
|
763
927
|
- `fileName?: string`
|
|
764
928
|
- `controller?: XlsxViewerController`
|
|
765
929
|
- `useWorker?: boolean`
|
|
766
|
-
- `locale?: string` — BCP 47 locale for numeric decimal and grouping separators, defaulting to `"en-US"`. Pass `"fr-FR"` for French or `navigator.language` for the browser locale. Dates retain their workbook format.
|
|
930
|
+
- `locale?: string` — BCP 47 locale for numeric decimal and grouping separators and built-in UI text, defaulting to `"en-US"`. Pass `"fr-FR"` for French or `navigator.language` for the browser locale. Dates retain their workbook format.
|
|
931
|
+
- `messages?: Partial<XlsxViewerMessages>` — Override individual localized labels, accessibility text, and state messages. Unspecified or `undefined` entries retain their locale defaults.
|
|
767
932
|
- `maxFileSizeBytes?: number`
|
|
768
933
|
- `readOnly?: boolean`
|
|
769
934
|
- `readOnlyAboveBytes?: number`
|
|
@@ -803,6 +968,8 @@ Common rendering props:
|
|
|
803
968
|
- `renderFormControl?: (props: XlsxFormControlRenderProps) => React.ReactNode`
|
|
804
969
|
- `renderTableHeaderMenu?: (props: XlsxTableHeaderMenuRenderProps) => React.ReactNode`
|
|
805
970
|
- `renderActiveCellOverlay?: (props: XlsxActiveCellOverlayRenderProps) => React.ReactNode`
|
|
971
|
+
- `renderCellEditorOverlay?: (props: XlsxCellEditorOverlayRenderProps) => React.ReactNode`
|
|
972
|
+
- `cellEditorStyle?: React.CSSProperties`
|
|
806
973
|
- `renderScroller?: (props: XlsxScrollerRenderProps) => React.ReactNode`
|
|
807
974
|
|
|
808
975
|
### Persisted Cell Styling
|