@extend-ai/react-xlsx 0.16.5 → 0.17.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 +74 -0
- package/dist/index.cjs +369 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +368 -80
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +5 -1
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -344,6 +344,58 @@ Notes:
|
|
|
344
344
|
- Thumbnails preserve worksheet aspect ratio and paint into your supplied `<canvas>`.
|
|
345
345
|
- The current implementation renders a bounded top-left worksheet preview, including loaded embedded worksheet images, shapes, and form controls, but does not include charts.
|
|
346
346
|
|
|
347
|
+
## Range Highlighting
|
|
348
|
+
|
|
349
|
+
Pass an A1 reference or an array of references to `highlightedRanges` to draw blue bounding boxes with a thin border matching the selection outline and a subtle fill. The highlights are separate from the current selection and do not change workbook formatting. It works in both canvas and DOM rendering, including frozen panes, hidden rows/columns, merged cells, and zoom.
|
|
350
|
+
|
|
351
|
+
```tsx
|
|
352
|
+
<XlsxViewer
|
|
353
|
+
file={file}
|
|
354
|
+
highlightedRanges={["'Sheet 1'!$B$3:$E$8", "'Sheet 1'!G3:J8", "'Sheet 2'!B10:D14"]}
|
|
355
|
+
autoScrollToHighlightedRanges={true}
|
|
356
|
+
highlightClassName="my-range-highlight"
|
|
357
|
+
/>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
`autoScrollToHighlightedRanges` defaults to `true`: a new set of ranges reveals the first range and switches to its worksheet. Other ranges remain highlighted on their respective sheets. Set it to `false` to leave both the current scroll position and active sheet unchanged. Navigation happens once per set of ranges or auto-scroll option change, so manual scrolling remains free afterward. A range larger than the viewport reveals its top-left portion; whole-row and whole-column references scroll only the relevant axis.
|
|
361
|
+
|
|
362
|
+
Set `highlightedRanges={null}` or `highlightedRanges={[]}` to clear all highlights. Omit the prop to manage highlighting through the controller instead. If any prop reference is invalid or unresolved, the previous highlights are cleared. Equivalent arrays do not repeat navigation on parent re-renders. An unqualified reference is bound to the active worksheet when applied, and stays on that worksheet when the user switches tabs.
|
|
363
|
+
|
|
364
|
+
### Controller API
|
|
365
|
+
|
|
366
|
+
The same API is available through `useXlsxViewer()` and `useXlsxViewerController()`:
|
|
367
|
+
|
|
368
|
+
```tsx
|
|
369
|
+
const accepted = controller.highlightRanges(["B3:E8", "G3:J8"], { autoScroll: false });
|
|
370
|
+
controller.highlightRanges("'Sheet 1'!A40:D48");
|
|
371
|
+
controller.highlightRanges("B3:E8", { sheetIndex: 1 });
|
|
372
|
+
controller.clearHighlightedRanges();
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
`highlightRanges(references, options?)` accepts a string or a readonly array of strings and returns `true` when every reference resolves to a loaded, visible worksheet. It returns `false` for invalid references, unavailable worksheets, or a workbook that is still loading, leaving all current highlights and navigation unchanged. Validation is atomic; a partially valid array is never applied. `autoScroll` defaults to `true`; `sheetIndex` is a zero-based index into `controller.sheets` and applies only to unqualified references. Each successful call replaces all previous highlights; an empty array clears them. Calling again can reveal the same first range again. `controller.highlightedRanges` is an array of parsed references with their resolved sheet names and workbook sheet indexes. Only its first entry can have `autoScroll: true`. Loading another workbook clears the array.
|
|
376
|
+
|
|
377
|
+
### CSS Customization
|
|
378
|
+
|
|
379
|
+
Style `.react-xlsx-range-highlight` globally, or use `highlightClassName` for a scoped override. Appearance is CSS in both renderers, so ordinary CSS properties work without `!important`:
|
|
380
|
+
|
|
381
|
+
```css
|
|
382
|
+
.my-range-highlight {
|
|
383
|
+
border: 1px solid #0284c7;
|
|
384
|
+
background: rgb(2 132 199 / 10%);
|
|
385
|
+
border-radius: 3px;
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
The defaults also accept inherited `--xlsx-highlight-border`, `--xlsx-highlight-fill`, and `--xlsx-highlight-radius` custom properties on the viewer or any ancestor. Position and dimensions are managed by the viewer; the overlay ignores pointer events. Use `[data-xlsx-range-highlight="1"]` to style a particular range by its zero-based index in the input array. A range crossing frozen panes may have several clipped overlay elements, each carrying the same class and index.
|
|
390
|
+
|
|
391
|
+
### Parsing References
|
|
392
|
+
|
|
393
|
+
`parseXlsxRange(reference)` validates a reference without loading a workbook. It returns `{ kind, range: { start, end }, sheetName }` with normalized, zero-based coordinates, or `null` for invalid input. `kind` is `"cells"`, `"rows"`, or `"columns"`; `sheetName` is `null` for an unqualified reference.
|
|
394
|
+
|
|
395
|
+
Supported references include single cells (`A1`), rectangles (`B2:E8`), absolute or mixed references (`$B2:E$8`), entire rows (`2:8`), entire columns (`B:E`), and optional worksheet prefixes. Sheet names with spaces or punctuation must be single-quoted; embedded apostrophes are doubled (`'Owner''s Data'!A1`). Letter case, reversed endpoints, surrounding whitespace, and an optional leading `=` are accepted. Coordinates are checked against [Excel's worksheet limits](https://support.microsoft.com/en-us/excel/excel-specifications-and-limits).
|
|
396
|
+
|
|
397
|
+
Each string must contain one rectangular A1 reference, not named ranges, structured table references, unions, R1C1 notation, external workbooks, or references spanning multiple worksheets. Whole-row/column highlights cover the displayed grid and extend as it grows.
|
|
398
|
+
|
|
347
399
|
## Custom Rendering
|
|
348
400
|
|
|
349
401
|
The viewer exposes render props for common UI integration points.
|
|
@@ -385,6 +437,22 @@ export function CustomWorkbook({ file }: { file: ArrayBuffer }) {
|
|
|
385
437
|
|
|
386
438
|
Apply `triggerProps` to the table-header trigger button so clicks do not leak into grid selection.
|
|
387
439
|
|
|
440
|
+
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.
|
|
441
|
+
|
|
442
|
+
```tsx
|
|
443
|
+
<XlsxViewer
|
|
444
|
+
file={file}
|
|
445
|
+
renderActiveCellOverlay={({ cell }) => (
|
|
446
|
+
<div
|
|
447
|
+
ref={activeCellRef}
|
|
448
|
+
className="active-cell-anchor"
|
|
449
|
+
data-active-cell={`${cell.row}:${cell.col}`}
|
|
450
|
+
style={{ height: "100%", width: "100%" }}
|
|
451
|
+
/>
|
|
452
|
+
)}
|
|
453
|
+
/>
|
|
454
|
+
```
|
|
455
|
+
|
|
388
456
|
Use `renderFormControl` to replace the built-in worksheet widgets. The callback receives the parsed `control`, resolved `items` and `label`, calculated `style`, read-only state, and `activate`, `setState`, `setSelected`, and `setValue` helpers. Apply `style` to the custom root and call `stopPropagation` from pointer/click handlers. The helpers keep Duke mutations, linked cells, undo/redo, export, and `onFormControlChange` in sync.
|
|
389
457
|
|
|
390
458
|
```tsx
|
|
@@ -477,6 +545,9 @@ Common rendering props:
|
|
|
477
545
|
- `enableGestureZoom?: boolean`
|
|
478
546
|
- `enableCanvasSelectionAnimation?: boolean`
|
|
479
547
|
- `allowResizeInReadOnly?: boolean`
|
|
548
|
+
- `highlightedRanges?: string | readonly string[] | null`
|
|
549
|
+
- `autoScrollToHighlightedRanges?: boolean`
|
|
550
|
+
- `highlightClassName?: string`
|
|
480
551
|
- `selectionColor?: string`
|
|
481
552
|
- `selectionFillColor?: string`
|
|
482
553
|
- `selectionHeaderColor?: string`
|
|
@@ -491,6 +562,7 @@ Common rendering props:
|
|
|
491
562
|
- `renderChartLoading?: (props: XlsxChartLoadingRenderProps) => React.ReactNode`
|
|
492
563
|
- `renderFormControl?: (props: XlsxFormControlRenderProps) => React.ReactNode`
|
|
493
564
|
- `renderTableHeaderMenu?: (props: XlsxTableHeaderMenuRenderProps) => React.ReactNode`
|
|
565
|
+
- `renderActiveCellOverlay?: (props: XlsxActiveCellOverlayRenderProps) => React.ReactNode`
|
|
494
566
|
- `renderScroller?: (props: XlsxScrollerRenderProps) => React.ReactNode`
|
|
495
567
|
|
|
496
568
|
### Persisted Cell Styling
|
|
@@ -662,7 +734,9 @@ The package exports the main types you are likely to use for custom integrations
|
|
|
662
734
|
- `XlsxImage`, `XlsxImageRect`, `XlsxImageRenderProps`, `XlsxImageSelectionRenderProps`
|
|
663
735
|
- `XlsxFormControl`, `XlsxFormControlInput`, `XlsxFormControlCaption`, `XlsxFormControlCaptionInput`, `XlsxFormControlCaptionRun`, `XlsxFormControlRenderProps`
|
|
664
736
|
- `XlsxTable`, `XlsxTableColumn`, `XlsxTableHeaderMenuRenderProps`
|
|
737
|
+
- `XlsxActiveCellOverlayRenderProps`
|
|
665
738
|
- `XlsxWorkbookTab`, `XlsxCellAddress`, `XlsxCellRange`
|
|
739
|
+
- `XlsxParsedRange`, `XlsxRangeHighlight`, `XlsxHighlightRangeOptions`
|
|
666
740
|
|
|
667
741
|
## License
|
|
668
742
|
|