@sheetxl/react 0.7.28-beta.4 → 0.8.0-beta.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sheetxl/react",
3
3
  "description": "React - React components needed to build advanced grid and spreadsheet UIs.",
4
- "version": "0.7.28-beta.4",
4
+ "version": "0.8.0-beta.1",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -48,11 +48,11 @@
48
48
  "@dnd-kit/modifiers": "^9.0.0",
49
49
  "@dnd-kit/sortable": "^10.0.0",
50
50
  "@dnd-kit/utilities": "^3.2.2",
51
- "@sheetxl/grid-react": "^0.7.28-beta.4",
52
- "@sheetxl/io": "^0.7.28-beta.4",
53
- "@sheetxl/sdk": "^0.7.28-beta.4",
54
- "@sheetxl/utils": "^0.7.28-beta.4",
55
- "@sheetxl/utils-react": "^0.7.28-beta.4",
51
+ "@sheetxl/grid-react": "^0.8.0-beta.1",
52
+ "@sheetxl/io": "^0.8.0-beta.1",
53
+ "@sheetxl/sdk": "^0.8.0-beta.1",
54
+ "@sheetxl/utils": "^0.8.0-beta.1",
55
+ "@sheetxl/utils-react": "^0.8.0-beta.1",
56
56
  "clsx": "^2.1.1",
57
57
  "react-merge-refs": "^3.0.2",
58
58
  "react-moveable": "^0.56.0",
@@ -10,6 +10,21 @@ export interface SheetCellRendererProps extends CellRendererProps<ICell> {
10
10
  * If true, show zero values
11
11
  */
12
12
  showZeros?: boolean;
13
+ /**
14
+ * Allow text that does not fit to paint over its empty neighbors, as it does in a sheet.
15
+ *
16
+ * @defaultValue true
17
+ *
18
+ * @remarks
19
+ * Set `false` when the cell is being drawn somewhere its own sheet's geometry does not apply — a
20
+ * list or menu built from real cells. The extrusion the SDK reports (`ICell.getTextOverflow`) is
21
+ * measured against the SOURCE column's width and ITS neighbors, so away from the sheet it places
22
+ * text against a geometry the surrounding pixels do not have. With this off the renderer lays out
23
+ * purely in the bounds it is given, and text that does not fit is clipped.
24
+ *
25
+ * Only text can extrude — a number or date that does not fit is replaced by `#` either way.
26
+ */
27
+ allowTextOverflow?: boolean;
13
28
  /**
14
29
  * Ability to query the theme colors.
15
30
  * Note - There are also css variables that can be used to style using doc theme colors
@@ -2,6 +2,7 @@ export { LicenseManager, type LicenseDetails } from '@sheetxl/sdk';
2
2
  export * from './context';
3
3
  export * from './cell';
4
4
  export * from './editor';
5
+ export * from './list';
5
6
  export * from './selection';
6
7
  export * from './border';
7
8
  export * from './sheet';
@@ -0,0 +1,51 @@
1
+ import { default as React } from 'react';
2
+ import { CellCoords } from '@sheetxl/utils';
3
+ import { ISheet, IDataValidation, IRange } from '@sheetxl/sdk';
4
+ import { LayerProps } from '@sheetxl/grid-react';
5
+ /** What the probe hands the button: the validation to open, and the cell it belongs to. */
6
+ export interface ValidationDropdown {
7
+ /** The list validation the button opens a picker for. */
8
+ dataValidation: IDataValidation;
9
+ /** The cell holding it — the anchor cell when the validation sits on a merge. */
10
+ cell: CellCoords;
11
+ /** The merge that cell anchors, when it anchors one. */
12
+ merge?: IRange.Coords;
13
+ }
14
+ export interface ValidationDropdownLayerProps extends Omit<LayerProps, 'children'> {
15
+ /** Class for the floated button container. */
16
+ className?: string;
17
+ /** Style for the floated button container. */
18
+ style?: React.CSSProperties;
19
+ /** The sheet whose selection is followed. */
20
+ sheet: ISheet;
21
+ /** Width (px, unzoomed) of the button. @defaultValue 17 */
22
+ dropdownWidth?: number;
23
+ /**
24
+ * Intercept the press instead of opening the built-in picker.
25
+ *
26
+ * @remarks
27
+ * By default the button opens the shared list picker ({@link useValidationPicker}). Supply this to
28
+ * take the press over entirely — the built-in picker is then never opened, and presenting the list
29
+ * is yours.
30
+ */
31
+ onOpenDropdown?: (cell: CellCoords, dataValidation: IDataValidation) => void;
32
+ }
33
+ /**
34
+ * The **list-validation dropdown** on the selected cell — a {@link RangeFloatLayer} activated by the
35
+ * selection.
36
+ *
37
+ * @remarks
38
+ * Deliberately a separate layer from `ValidationIndicatorLayer`, because the two marks answer
39
+ * different questions and so are drawn by different mechanisms. The invalid-value mark is a property
40
+ * of a cell's VALUE: it belongs wherever one is in view, as cached tile snapshots that survive scroll.
41
+ * The dropdown appears on the ACTIVE CELL ALONE — which is the expensive predicate, since it would
42
+ * dirty a tile on every selection move — and it hugs the OUTSIDE of the cell's right edge (covering
43
+ * the neighbor, as Excel does) so it has to escape the pane clip. Tile and float; they share a sheet
44
+ * and nothing else.
45
+ *
46
+ * On a **merge** the affordance belongs to the merge, not to its anchor corner cell: the button hugs
47
+ * the MERGE's right edge, but keeps the ANCHOR ROW's height pinned to the top — stretching it to fit
48
+ * would turn a tall merge into a full-height bar.
49
+ */
50
+ export declare const ValidationDropdownLayer: React.MemoExoticComponent<(props: ValidationDropdownLayerProps) => React.JSX.Element>;
51
+ //# sourceMappingURL=ValidationDropdownLayer.d.ts.map
@@ -1,6 +1,5 @@
1
1
  import { default as React } from 'react';
2
- import { CellCoords } from '@sheetxl/utils';
3
- import { ISheet, IDataValidation } from '@sheetxl/sdk';
2
+ import { ISheet } from '@sheetxl/sdk';
4
3
  import { LayerProps } from '@sheetxl/grid-react';
5
4
  export interface ValidationIndicatorLayerProps extends LayerProps {
6
5
  /** Class for the layer (devtools identification). */
@@ -11,31 +10,19 @@ export interface ValidationIndicatorLayerProps extends LayerProps {
11
10
  sheet: ISheet;
12
11
  /** Size (px, unzoomed) of the invalid-value corner mark. @defaultValue 7 */
13
12
  markSize?: number;
14
- /** Width (px, unzoomed) of the list dropdown button. @defaultValue 17 */
15
- dropdownWidth?: number;
16
- /**
17
- * Called when the selected cell's list dropdown is pressed.
18
- *
19
- * @remarks
20
- * The layer draws the affordance but owns no picker — the list UI is a host concern (it needs
21
- * the float stack and the editor). Omit and the button is inert.
22
- */
23
- onOpenDropdown?: (cell: CellCoords, dataValidation: IDataValidation) => void;
24
13
  }
25
14
  /**
26
- * The sheet's **data-validation indicators** — the mark on a cell holding a value its rule rejects,
27
- * and the dropdown on a selected list cell.
15
+ * The sheet's **invalid-value marks** — the corner mark on every in-view cell holding a value its
16
+ * validation rule rejects.
28
17
  *
29
18
  * @remarks
30
19
  * A layer of its own rather than part of the cell renderer, so the cells layer never probes the
31
20
  * validation model and a sheet with no validations costs one index lookup per frame.
32
21
  *
33
- * The two marks answer different questions and so are drawn differently. The invalid mark is a
34
- * property of a cell's VALUE: it is drawn wherever one is in view, as {@link CellTileDiv}
35
- * snapshots that survive scroll. The dropdown is an affordance for editing, so — as in Excel — it
36
- * appears on the selected cell alone (a column of list cells would otherwise be a column of
37
- * buttons), and it follows the selection as a live {@link VirtualDiv} peer of the tiles, so an
38
- * arrow key never invalidates a tile.
22
+ * The mark is a property of a cell's VALUE, so it belongs wherever one is in view and is drawn as
23
+ * {@link CellTileDiv} snapshots that survive scroll — nothing here depends on the selection, which is
24
+ * what keeps the tile cache alive across cursor movement. The list DROPDOWN is the opposite predicate
25
+ * ("the active cell alone") and lives in `ValidationDropdownLayer`; they share a sheet and nothing else.
39
26
  */
40
27
  export declare const ValidationIndicatorLayer: React.MemoExoticComponent<(props: ValidationIndicatorLayerProps) => React.JSX.Element | null>;
41
28
  //# sourceMappingURL=ValidationIndicatorLayer.d.ts.map
@@ -18,6 +18,9 @@ export * from './ConditionalIcons';
18
18
  export * from './ConditionalBarLayer';
19
19
  export * from './ConditionalIconsLayer';
20
20
  export * from './ValidationIndicatorLayer';
21
+ export * from './ValidationDropdownLayer';
22
+ export * from './useValidationPicker';
23
+ export * from './validationList';
21
24
  export * from './CircularIndicatorLayer';
22
25
  export * from './HeaderSelectionLayer';
23
26
  export * from './HeaderResizerLayer';
@@ -0,0 +1,54 @@
1
+ import { default as React } from 'react';
2
+ import { CellCoords } from '@sheetxl/utils';
3
+ import { ISheet, IDataValidation } from '@sheetxl/sdk';
4
+ /**
5
+ * What the picker needs. Deliberately only an anchor + a validation + where to write: the picker does
6
+ * **not** care who opened it, so the Excel-mode float button and the Sheets-mode in-cell triangle open
7
+ * the identical component.
8
+ */
9
+ export interface ValidationPickerOptions {
10
+ /** The sheet the chosen value is written to. */
11
+ sheet: ISheet;
12
+ /** The validation whose list is offered (`null` closes / offers nothing). */
13
+ dataValidation: IDataValidation | null;
14
+ /** The cell that receives the chosen value. */
15
+ cell: CellCoords | null;
16
+ /**
17
+ * What the menu drops under — the **cell / merge** rect, not the button. Excel anchors the list to
18
+ * the cell, and it is what both modes can supply (the Sheets-mode triangle has no float to anchor
19
+ * to). A Floating UI virtual element; `StickyState.reference` is one.
20
+ */
21
+ anchor: unknown;
22
+ /**
23
+ * The anchored cell / merge width (px). Excel makes the list **at least** as wide as the cell — a
24
+ * floor, not a cap: a long value still widens it past the column.
25
+ */
26
+ minWidth?: number;
27
+ }
28
+ /** The picker, ready to drop into JSX and drive. */
29
+ export interface ValidationPicker {
30
+ /** Render this. */
31
+ component: React.ReactNode;
32
+ /** Open the menu. */
33
+ open: () => void;
34
+ /** Close it. */
35
+ close: () => void;
36
+ /** Whether it is currently open (reactive). */
37
+ isOpen: boolean;
38
+ }
39
+ /**
40
+ * The **list-validation picker** — a `FloatPopper` menu (through the shared float stack, so it gets
41
+ * the portal, stacking, light-dismiss and Escape every other popup in the app has) anchored to the
42
+ * cell it edits.
43
+ *
44
+ * @remarks
45
+ * The split is deliberate: `RangeFloatLayer` places the *button* against the grid (pane ownership,
46
+ * freeze, boundary fit); the float stack owns the *menu*. Neither does the other's job.
47
+ *
48
+ * The offered values come from {@link resolveListRange} as a RANGE of real cells, and are drawn by
49
+ * `SheetValueList` — so a date reads as a date and a currency as currency, because the rows are
50
+ * cells. A reference-backed source is not resolvable yet; the menu shows clearly-marked placeholders
51
+ * in that case and refuses to write one back.
52
+ */
53
+ export declare const useValidationPicker: (options: ValidationPickerOptions) => ValidationPicker;
54
+ //# sourceMappingURL=useValidationPicker.d.ts.map
@@ -0,0 +1,84 @@
1
+ import { ICellRange, IDataValidation, ISheet, Scalar } from '@sheetxl/sdk';
2
+ /**
3
+ * The values a list validation offers, plus whether they are real.
4
+ */
5
+ export interface ResolvedList {
6
+ /** The offered values. */
7
+ items: readonly Scalar[];
8
+ /**
9
+ * `true` when {@link items} is **placeholder data** — the source exists but this build cannot
10
+ * resolve it (see {@link resolveListItems}). Never let placeholder values reach the model or read
11
+ * as real in the UI.
12
+ */
13
+ placeholder: boolean;
14
+ }
15
+ /**
16
+ * The values a list validation offers.
17
+ *
18
+ * @remarks
19
+ * A list source is stored as **formula text**, verbatim, so the round-trip is lossless — see
20
+ * `io-xlsx`'s `toCondition`, which sets `param` to the raw `<formula1>`. Three forms reach here:
21
+ *
22
+ * - a `Scalar[]` under `param.items` — the programmatic form, used directly;
23
+ * - a quoted literal (`"a,b,c"`) — parsed here;
24
+ * - a reference or formula (`$A$1:$A$5`, a name, a cross-sheet ref) — **not resolvable in this
25
+ * build**. `ICondition.IContext.resolveFormula` returns a single `Scalar`, not an array, and
26
+ * `InSetOperator` carries the matching TODO: resolving a source to a list needs a formula→array
27
+ * evaluation that does not exist yet. Until it does, this returns PLACEHOLDER values with
28
+ * `placeholder: true` so the picker UI can be exercised — the caller must surface that, and must
29
+ * never write one back to the model.
30
+ *
31
+ * Note the same gap makes such a validation inert as a *predicate* too (`InSetOperator` drops a
32
+ * non-array `items`), so this is one missing capability, not a picker-only problem.
33
+ */
34
+ export declare const resolveListItems: (dataValidation: IDataValidation | null | undefined) => ResolvedList;
35
+ /**
36
+ * Options for {@link resolveListRange}.
37
+ */
38
+ export interface ResolveListRangeOptions {
39
+ /**
40
+ * The sheet the validation belongs to.
41
+ *
42
+ * @remarks
43
+ * Its {@link IStyleCollection} is SHARED with the scratch sheet, so the offered values render in
44
+ * the document's theme and `Normal` style instead of the defaults. Sharing is safe only because
45
+ * the scratch sheet sets values and never a style — writing one would reach the host's collection.
46
+ */
47
+ host?: ISheet;
48
+ }
49
+ /**
50
+ * A list validation's values, as a **range**.
51
+ */
52
+ export interface ResolvedListRange {
53
+ /** The values to offer, or `null` when the validation offers none. */
54
+ range: ICellRange | null;
55
+ /**
56
+ * The width (px) the values need — already measured, so a caller sizing a menu does not measure
57
+ * again. `0` when there is no range.
58
+ */
59
+ contentWidth: number;
60
+ /**
61
+ * `true` when {@link range} holds **placeholder data** — the source exists but this build cannot
62
+ * resolve it. Never let a placeholder reach the model or read as real in the UI.
63
+ */
64
+ placeholder: boolean;
65
+ /**
66
+ * Release the scratch sheet this materialized. A no-op for a source that was already a real range,
67
+ * which is never ours to close.
68
+ */
69
+ close: () => void;
70
+ }
71
+ /**
72
+ * The values a list validation offers, as a **range of real cells** — which is what a UI needs, since
73
+ * only a cell knows how its value becomes text (a date is a date, a currency is a currency).
74
+ *
75
+ * @remarks
76
+ * A literal source (`"a,b,c"`) is materialized onto a scratch sheet. A reference source
77
+ * (`$A$1:$A$5`) will one day return that range directly, live, with no copy — the consumer does not
78
+ * change when it does, which is the point of taking a range. Until the SDK can resolve a formula to
79
+ * an array it returns marked placeholders; see {@link resolveListItems}.
80
+ *
81
+ * The caller MUST {@link ResolvedListRange.close} the result when it is done with it.
82
+ */
83
+ export declare const resolveListRange: (dataValidation: IDataValidation | null | undefined, options?: ResolveListRangeOptions) => ResolvedListRange;
84
+ //# sourceMappingURL=validationList.d.ts.map
@@ -0,0 +1,93 @@
1
+ import { default as React } from 'react';
2
+ import { ICell, ICellRange } from '@sheetxl/sdk';
3
+ import { ISelection } from '@sheetxl/grid-react';
4
+ export interface SheetValueListAttributes {
5
+ isSheetValueList: () => true;
6
+ }
7
+ export interface ISheetValueListElement extends HTMLDivElement, SheetValueListAttributes {
8
+ }
9
+ /**
10
+ * Props for {@link SheetValueList}.
11
+ */
12
+ export interface SheetValueListProps extends React.HTMLAttributes<HTMLDivElement> {
13
+ /**
14
+ * The values to offer — **the** input. A single column of a real sheet; only its first column is
15
+ * read (a wider range is not an error, it is just narrowed).
16
+ *
17
+ * @remarks
18
+ * A caller holding raw values makes itself a scratch sheet and hands over the resulting range —
19
+ * see the component remarks. The list never writes to it: it is a **view**, so a *live* range (a
20
+ * list validation's `$A$1:$A$5`, a table column) can be passed straight through with no copy and
21
+ * no staleness.
22
+ *
23
+ * The range is never resized to render it. Ask `getBestFit()` how wide the values are and pass that
24
+ * as {@link SheetValueListProps.contentWidth}; the range itself is left exactly as it was.
25
+ */
26
+ range: ICellRange;
27
+ /**
28
+ * The selection model — the highlighted row + Arrow-key navigation, in **list** coordinates (row 0
29
+ * is the range's first row, whatever its sheet address). Owned by the caller so it can read what is
30
+ * highlighted; a private one is created when omitted.
31
+ */
32
+ selection?: ISelection;
33
+ /**
34
+ * A row was chosen — clicked, or Enter/Space on the highlighted row. The cell is the real sheet
35
+ * cell, so the caller can take its value, its text or its format.
36
+ */
37
+ onChoose?: (cell: ICell, index: number) => void;
38
+ /**
39
+ * Uniform row height in px. @defaultValue the range's first row height.
40
+ *
41
+ * @remarks
42
+ * Uniform, deliberately: a dropdown wants even rows, and a source range brings heights that were
43
+ * chosen for a sheet, not for a menu.
44
+ */
45
+ rowHeight?: number;
46
+ /**
47
+ * Width the **values** need, in px — normally `range.getBestFit({ axes: Column }).width`. The list
48
+ * sizes itself to this plus its own scrollbar gutter, so the column really is this wide.
49
+ *
50
+ * @remarks
51
+ * Pass this rather than a `style.width`: `getBestFit` describes the COLUMN, and a box of that width
52
+ * hands the gutter back out of it — content that fits exactly then doesn't, and the renderer
53
+ * replaces the values it can no longer fit with `#`. Cap the result with `style.maxWidth`.
54
+ */
55
+ contentWidth?: number;
56
+ /** Take focus on mount, so the Arrow keys work without a click first. @defaultValue false */
57
+ autoFocus?: boolean;
58
+ /** Ref for the Element. */
59
+ ref?: React.Ref<ISheetValueListElement>;
60
+ }
61
+ /**
62
+ * A single-column list whose rows are **real cells on a real sheet** — so a date reads as a date, a
63
+ * currency as currency, and a number stays right-aligned, because the values are drawn by the same
64
+ * {@link SheetCellRenderer} the grid uses.
65
+ *
66
+ * @remarks
67
+ * The input is a {@link SheetValueListProps.range | range}, and only a range. A caller holding raw
68
+ * `Scalar[]` materializes a scratch sheet and passes the resulting range — which is what this
69
+ * component would otherwise have had to do internally, so pushing it out costs nothing and makes the
70
+ * reference-backed case (a list validation sourced from `$A$1:$A$5`) stop being special: same code
71
+ * path, pointed at the live range.
72
+ *
73
+ * It is a **dropdown**, not a little spreadsheet: no headers, no gridlines, no fills or borders, and
74
+ * a list-shaped highlight (see `ListSurface`, whose chrome it wears). It also adds **no padding of
75
+ * its own** — a row's text sits exactly where the cell's own insets put it, which is what lets a
76
+ * caller align the first row with the cell the menu drops out of. A border belongs OUTSIDE the
77
+ * component (an outset on the panel), or every value shifts right by the border width.
78
+ *
79
+ * Sizing is split: pass {@link SheetValueListProps.contentWidth} (what the values need) and the list
80
+ * adds its own chrome, but the width RULE — at least the anchored cell, at most a cap — stays the
81
+ * caller's, since only the caller knows the anchor. Height is `style`'s.
82
+ *
83
+ * Rows are drawn with `allowTextOverflow={false}`: in a sheet, text too wide for its column spills
84
+ * over its empty neighbors, and the SDK reports that spill in the SOURCE sheet's geometry — which the
85
+ * list does not have. A dropdown row should not spill anyway, so the renderer lays out purely in the
86
+ * bounds the list gives it and clips what does not fit.
87
+ *
88
+ * Note the font scale: a sheet's `Normal` font is in POINTS and paints at `points * 96/72` (11pt
89
+ * Calibri renders at 14.667px), which is the scale every width here — `getBestFit` included — is
90
+ * measured in. A width that looks too small next to a point size is usually this.
91
+ */
92
+ export declare const SheetValueList: React.ForwardRefExoticComponent<Omit<SheetValueListProps, "ref"> & React.RefAttributes<ISheetValueListElement>>;
93
+ //# sourceMappingURL=SheetValueList.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './SheetValueList';
2
+ //# sourceMappingURL=index.d.ts.map