@bmsuisse/datagrid 0.25.3 → 0.27.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/dist/index.d.ts +352 -3
- package/dist/index.js +674 -186
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -161,6 +161,54 @@ interface BaseColumn<TRow> {
|
|
|
161
161
|
* any, since `<DataGrid>` has no way to tell your content lacks one.
|
|
162
162
|
*/
|
|
163
163
|
renderHeader?: (column: BaseColumn<TRow>) => ReactNode;
|
|
164
|
+
/**
|
|
165
|
+
* Opt-in: defaults to false — must be explicitly set (or return true) for
|
|
166
|
+
* `<DataGrid>` to render this column's cells as inline editors. A function
|
|
167
|
+
* makes it conditional per row (e.g. a "locked" row that can't be
|
|
168
|
+
* edited). See `DataGridProps.editing` for the accumulate-then-save
|
|
169
|
+
* workflow this feeds into — editable cells with no `editing` prop
|
|
170
|
+
* supplied just render as static text, same as if `editable` were unset.
|
|
171
|
+
*
|
|
172
|
+
* A cell doesn't become an editor just because this is true, though:
|
|
173
|
+
* clicking (or Enter/Space-ing) any editable cell in a row is what
|
|
174
|
+
* activates editors for every editable column in THAT row at once — the
|
|
175
|
+
* rest of the grid's rows stay static until clicked into themselves. At
|
|
176
|
+
* most one row is active at a time: activating a row deactivates whatever
|
|
177
|
+
* row was active before it (edit row by row, not several open at once) —
|
|
178
|
+
* this does NOT discard the row you switch away from, its own pending
|
|
179
|
+
* edits stay exactly as they were, just no longer shown as editors.
|
|
180
|
+
*
|
|
181
|
+
* Until a cell is activated, its content renders inside a clickable
|
|
182
|
+
* `<span role="button">` (this is what makes clicking it activate the
|
|
183
|
+
* row) — a column that's both `editable` and has a custom `cell`
|
|
184
|
+
* returning its own focusable content (a link, a button) produces nested
|
|
185
|
+
* interactive elements once wrapped this way. Prefer a non-focusable
|
|
186
|
+
* element (styled to look like a link, e.g.) in `cell` for a column
|
|
187
|
+
* that's also `editable`, the same caution `renderHeader` needs under
|
|
188
|
+
* `sortable`.
|
|
189
|
+
*/
|
|
190
|
+
editable?: boolean | ((row: TRow) => boolean);
|
|
191
|
+
/**
|
|
192
|
+
* Overrides the default type-based editor (see `renderDefaultEditWidget`)
|
|
193
|
+
* for this column's cells. Receives the cell's current value (the row's
|
|
194
|
+
* original value, or a still-pending edit if the user already changed it
|
|
195
|
+
* this session), the row itself, an `onChange` to record a new pending
|
|
196
|
+
* value, this cell's current validation error message (from
|
|
197
|
+
* `validateEdit` below) if any, and whether this specific cell is the one
|
|
198
|
+
* whose click just activated the row (see `editable`'s own doc) — forward
|
|
199
|
+
* it to your control's native `autoFocus` so the row-activating click also
|
|
200
|
+
* focuses the field the user actually clicked, not just some other cell
|
|
201
|
+
* in the same row.
|
|
202
|
+
*/
|
|
203
|
+
renderEditCell?: (value: unknown, row: TRow, onChange: (next: unknown) => void, error: string | undefined, autoFocus: boolean) => ReactNode;
|
|
204
|
+
/**
|
|
205
|
+
* Validates a pending edit before it's allowed into `editing.onSave`'s
|
|
206
|
+
* payload. Returning a message string blocks the Save button (and shows
|
|
207
|
+
* the message under the cell) until the value is fixed or reverted to its
|
|
208
|
+
* original; returning `undefined` means valid. Runs on every change to
|
|
209
|
+
* this cell, including the default editors' own `onChange`.
|
|
210
|
+
*/
|
|
211
|
+
validateEdit?: (value: unknown, row: TRow) => string | undefined;
|
|
164
212
|
}
|
|
165
213
|
type StringColumn<TRow> = BaseColumn<TRow> & {
|
|
166
214
|
type: "string";
|
|
@@ -191,6 +239,8 @@ declare function getColumnValue<TRow>(column: ColumnDef<TRow>, row: TRow): unkno
|
|
|
191
239
|
declare function isSortable<TRow>(column: ColumnDef<TRow>): boolean;
|
|
192
240
|
/** True only if a column explicitly opts in (`filterable: true`) — the default is false. */
|
|
193
241
|
declare function isFilterable<TRow>(column: ColumnDef<TRow>): boolean;
|
|
242
|
+
/** True only if a column explicitly opts in to `editable` — for this specific row, when `editable` is a predicate. Default is false. */
|
|
243
|
+
declare function isEditable<TRow>(column: ColumnDef<TRow>, row: TRow): boolean;
|
|
194
244
|
|
|
195
245
|
/**
|
|
196
246
|
* Default filter widget for `type: "boolean"` columns: a 3-way All/Yes/No
|
|
@@ -450,6 +500,14 @@ declare function renderDefaultFilterWidget<TRow>(column: ColumnDef<TRow>, value:
|
|
|
450
500
|
declare function defaultAlign<TRow>(column: ColumnDef<TRow>): ColumnAlign;
|
|
451
501
|
/** The literal Tailwind class for a column's default alignment; see `defaultAlign`. */
|
|
452
502
|
declare function alignClassName<TRow>(column: ColumnDef<TRow>): string;
|
|
503
|
+
/**
|
|
504
|
+
* Parses an arbitrary raw cell value into a `Date`, or `null` if it isn't
|
|
505
|
+
* one. Exported (unlike `toNumber` below, which stays internal) because
|
|
506
|
+
* `edit/DateEditor.tsx` needs the exact same date-only-vs-datetime parsing
|
|
507
|
+
* this module already uses for display — a second copy would risk drifting
|
|
508
|
+
* from the UTC-midnight fix documented below.
|
|
509
|
+
*/
|
|
510
|
+
declare function toDate(value: unknown): Date | null;
|
|
453
511
|
/**
|
|
454
512
|
* Renders a raw cell value as a display string, using the type-appropriate
|
|
455
513
|
* default formatter for `column.type`. Columns with a custom `cell` render
|
|
@@ -457,6 +515,275 @@ declare function alignClassName<TRow>(column: ColumnDef<TRow>): string;
|
|
|
457
515
|
*/
|
|
458
516
|
declare function defaultFormat<TRow>(column: ColumnDef<TRow>, value: unknown): string;
|
|
459
517
|
|
|
518
|
+
/**
|
|
519
|
+
* One row carrying at least one pending edit, as handed to
|
|
520
|
+
* `EditingOptions.onSave`. `values` is keyed by column id and holds
|
|
521
|
+
* only the columns that actually changed — not a full patched `TRow` — so
|
|
522
|
+
* this works uniformly for `accessorKey` columns (which have one obvious
|
|
523
|
+
* field to write back into) and `accessorFn` columns (which may not: a
|
|
524
|
+
* derived/computed column has no single field of `TRow` an edit could patch
|
|
525
|
+
* back onto).
|
|
526
|
+
*/
|
|
527
|
+
interface EditedRow<TRow> {
|
|
528
|
+
rowId: string;
|
|
529
|
+
/** The row as it looked when its first still-pending edit was made — not necessarily the row's current on-screen data if it was refetched since. */
|
|
530
|
+
row: TRow;
|
|
531
|
+
values: Record<string, unknown>;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Drives the built-in inline-editing workflow shared by `<DataGrid>` and
|
|
535
|
+
* `<TreeDataGrid>`: cells in a column with `editable` set become
|
|
536
|
+
* interactive editors, and every change accumulates locally (never written
|
|
537
|
+
* back onto the caller's `data`, never sent anywhere on its own) until the
|
|
538
|
+
* user clicks the Save button this renders in a bar above the grid — or
|
|
539
|
+
* Discard, to drop everything back to unedited. There is no partial/per-cell
|
|
540
|
+
* autosave; see `onSave` below for the all-or-nothing commit point.
|
|
541
|
+
*
|
|
542
|
+
* This package has no translation/i18n layer anywhere — `saveLabel`/
|
|
543
|
+
* `discardLabel` are plain strings (or a count-aware function) you supply
|
|
544
|
+
* directly, the same convention every other caller-facing string in this
|
|
545
|
+
* package already follows (`header`, menu item labels, etc.).
|
|
546
|
+
*/
|
|
547
|
+
interface EditingOptions<TRow> {
|
|
548
|
+
/**
|
|
549
|
+
* Called once, when the user clicks Save, with every row currently
|
|
550
|
+
* holding at least one pending edit and no validation error
|
|
551
|
+
* (`validateEdit`-failing rows are excluded — Save itself stays disabled
|
|
552
|
+
* while ANY row has one, so in practice this only ever fires once none
|
|
553
|
+
* do). Pending-edit state stays exactly as it was until this resolves:
|
|
554
|
+
* **throw or reject to leave every pending edit in place** (e.g. your own
|
|
555
|
+
* save request failed) rather than losing the user's in-progress edits —
|
|
556
|
+
* nothing of this package's own surfaces for that case, so show your own
|
|
557
|
+
* error UI. Resolve (or return) normally to clear every pending edit that
|
|
558
|
+
* was included in this call — and only those; an edit made to a different
|
|
559
|
+
* cell while this was still in flight is never touched by this call's own
|
|
560
|
+
* resolution, whenever it lands.
|
|
561
|
+
*/
|
|
562
|
+
onSave: (edits: EditedRow<TRow>[]) => void | Promise<void>;
|
|
563
|
+
/** Called after the built-in Discard button clears every pending edit. Omit for no extra behavior beyond that clear. */
|
|
564
|
+
onDiscard?: () => void;
|
|
565
|
+
/**
|
|
566
|
+
* Label for the Save button. A plain string renders as-is — no
|
|
567
|
+
* placeholder substitution, since there's no templating/i18n layer here.
|
|
568
|
+
* Pass a function instead for a count-aware label, e.g. `(count) =>
|
|
569
|
+
* `Apply ${count} change${count === 1 ? "" : "s"}``. Defaults to that
|
|
570
|
+
* exact "Save N change(s)" function.
|
|
571
|
+
*/
|
|
572
|
+
saveLabel?: string | ((changedRowCount: number) => ReactNode);
|
|
573
|
+
/** Label for the Discard button. Same convention as `saveLabel`. Defaults to `"Discard"`. */
|
|
574
|
+
discardLabel?: string | ((changedRowCount: number) => ReactNode);
|
|
575
|
+
/**
|
|
576
|
+
* Disables the Save and Discard buttons and shows Save in a pending
|
|
577
|
+
* state — set this while your own `onSave` promise is in flight (a
|
|
578
|
+
* caller-driven flag, not something this package infers on its own, since
|
|
579
|
+
* `onSave` may resolve without the grid ever finding out your own server
|
|
580
|
+
* call afterward e.g. still triggered a background refetch). Defaults to
|
|
581
|
+
* false.
|
|
582
|
+
*/
|
|
583
|
+
saving?: boolean;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Contract every built-in edit widget implements — the `renderEditCell`
|
|
588
|
+
* equivalent of `filter/widget-types.ts`'s `FilterWidgetProps`. `TColumn` is
|
|
589
|
+
* narrowed to the specific column shape the widget knows how to render (e.g.
|
|
590
|
+
* `EnumColumn` for `EnumEditor`) — `renderDefaultEditWidget` picks the right
|
|
591
|
+
* widget by `column.type` before handing it a column, so the widget itself
|
|
592
|
+
* never has to branch on `type`.
|
|
593
|
+
*
|
|
594
|
+
* `value` is the cell's current value: the row's original value, or a
|
|
595
|
+
* still-pending edit if the user already changed it this session.
|
|
596
|
+
* `onChange` records a new pending value — it does not itself validate or
|
|
597
|
+
* persist anything. `error`, when set, is this cell's current
|
|
598
|
+
* `column.validateEdit` message; every built-in widget shows it as small
|
|
599
|
+
* text under its control and marks the control `aria-invalid`.
|
|
600
|
+
*
|
|
601
|
+
* `rowId` exists purely so each built-in widget's own `data-testid` (`edit-
|
|
602
|
+
* ${rowId}-${column.id}`) stays unique per cell — unlike a filter widget,
|
|
603
|
+
* which renders exactly once per column (in the header), an edit widget
|
|
604
|
+
* renders once per (row, column) pair, so a column-id-only testid would
|
|
605
|
+
* collide across every row the moment a grid has more than one.
|
|
606
|
+
*
|
|
607
|
+
* `autoFocus` is true for exactly one cell per row-activation: the specific
|
|
608
|
+
* column whose static cell the user clicked (or Enter/Space'd) to turn the
|
|
609
|
+
* whole row into editors — every other cell in that same row gets `false`.
|
|
610
|
+
* Every built-in widget forwards it straight to its underlying control's own
|
|
611
|
+
* native `autoFocus` prop, so the browser focuses that one control the
|
|
612
|
+
* moment it mounts, without an extra click to actually start typing.
|
|
613
|
+
*/
|
|
614
|
+
interface EditWidgetProps<TColumn> {
|
|
615
|
+
column: TColumn;
|
|
616
|
+
rowId: string;
|
|
617
|
+
value: unknown;
|
|
618
|
+
onChange: (next: unknown) => void;
|
|
619
|
+
error?: string;
|
|
620
|
+
autoFocus?: boolean;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* The `id` every built-in widget gives its own error `<span>`, so its
|
|
624
|
+
* control's `aria-describedby` can point at it — a screen reader announces
|
|
625
|
+
* `aria-invalid` alone with no indication of *why*, so the association
|
|
626
|
+
* matters, not just the flag. Exported for a custom `renderEditCell` that
|
|
627
|
+
* wants the same convention instead of inventing its own id scheme.
|
|
628
|
+
*/
|
|
629
|
+
declare function editErrorId(rowId: string, columnId: string): string;
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* The error text every built-in editor shows under its control, associated
|
|
633
|
+
* with it via `id` + the control's own `aria-describedby={editErrorId(...)}`
|
|
634
|
+
* — pulled out to one place so the a11y wiring/styling convention can't
|
|
635
|
+
* drift between the 5 editors the way five independent copies of the same
|
|
636
|
+
* `<span>` inevitably would.
|
|
637
|
+
*/
|
|
638
|
+
declare function EditFieldError({ id, message }: {
|
|
639
|
+
id: string;
|
|
640
|
+
message: string;
|
|
641
|
+
}): ReactElement;
|
|
642
|
+
|
|
643
|
+
/** Default inline editor for `type: "boolean"` columns: a single checkbox. */
|
|
644
|
+
declare function BooleanEditor<TRow>({ column, rowId, value, onChange, error, autoFocus, }: EditWidgetProps<BooleanColumn<TRow>>): ReactElement;
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Default inline editor for `type: "date"` / `type: "datetime"` columns: a
|
|
648
|
+
* native `<input type="date">`/`<input type="datetime-local">`. Emits a
|
|
649
|
+
* `Date` (or `null` for an emptied field), via `parseISO` rather than the
|
|
650
|
+
* bare `new Date(...)` constructor — same convention `DateRangeFilter`'s
|
|
651
|
+
* `parseBound` and `format.ts`'s `toDate` already use, since a native date
|
|
652
|
+
* input's value is a date-only `"YYYY-MM-DD"` string for `type: "date"`,
|
|
653
|
+
* which the JS spec would otherwise parse as UTC midnight instead of local
|
|
654
|
+
* midnight.
|
|
655
|
+
*/
|
|
656
|
+
declare function DateEditor<TRow>({ column, rowId, value, onChange, error, autoFocus, }: EditWidgetProps<DateColumn<TRow>>): ReactElement;
|
|
657
|
+
|
|
658
|
+
/** Default inline editor for `type: "enum"` columns: a single-value select over `column.options`. */
|
|
659
|
+
declare function EnumEditor<TRow>({ column, rowId, value, onChange, error, autoFocus, }: EditWidgetProps<EnumColumn<TRow>>): ReactElement;
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Default inline editor for `type: "number"` / `type: "currency"` columns: a
|
|
663
|
+
* native number input. Emits `null` for an emptied field (not `NaN` or `""`)
|
|
664
|
+
* so `validateEdit`/`onSave` see an explicit "cleared" value; otherwise emits
|
|
665
|
+
* a real `number`, never the input's raw string.
|
|
666
|
+
*
|
|
667
|
+
* Keeps its own local `text` state instead of deriving the input's `value`
|
|
668
|
+
* straight from the `value` prop on every render — a native
|
|
669
|
+
* `type="number"` input's own `.value` getter reads back as `""` while the
|
|
670
|
+
* user is mid-typing a string that isn't yet a complete valid float ("12.",
|
|
671
|
+
* "-", "1e"), even though the field still visually shows what they typed.
|
|
672
|
+
* Deriving the controlled `value` prop straight from a re-parsed number
|
|
673
|
+
* would feed that `""` back in on every such keystroke, wiping the decimal
|
|
674
|
+
* point/minus sign before the user can finish typing it. `lastEmittedRef` +
|
|
675
|
+
* the effect below only resync `text` from an EXTERNAL change to `value`
|
|
676
|
+
* (Escape-revert, switching rows and back, a row's data refetched) — the
|
|
677
|
+
* same pattern `NumberComparisonFilter` already uses for the identical
|
|
678
|
+
* reason; see that component's own doc.
|
|
679
|
+
*/
|
|
680
|
+
declare function NumberEditor<TRow>({ column, rowId, value, onChange, error, autoFocus, }: EditWidgetProps<NumberColumn<TRow>>): ReactElement;
|
|
681
|
+
|
|
682
|
+
/** Default inline editor for `type: "string"` columns: a plain text input. */
|
|
683
|
+
declare function StringEditor<TRow>({ column, rowId, value, onChange, error, autoFocus, }: EditWidgetProps<StringColumn<TRow>>): ReactElement;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Picks and renders the default inline-edit widget for a column, based
|
|
687
|
+
* purely on `column.type` — the `renderEditCell` equivalent of
|
|
688
|
+
* `filter/registry.tsx`'s `renderDefaultFilterWidget`. `<DataGrid>` calls
|
|
689
|
+
* this itself for any editable column that doesn't set its own
|
|
690
|
+
* `renderEditCell`; a consuming app only reaches for it directly to wrap or
|
|
691
|
+
* extend one of these defaults rather than writing an editor from scratch.
|
|
692
|
+
*/
|
|
693
|
+
declare function renderDefaultEditWidget<TRow>(column: ColumnDef<TRow>, rowId: string, value: unknown, onChange: (next: unknown) => void, error?: string, autoFocus?: boolean): ReactElement;
|
|
694
|
+
|
|
695
|
+
/** One row's accumulated pending edits. */
|
|
696
|
+
interface PendingRowEdit<TRow> {
|
|
697
|
+
/** The row as it looked when its first still-pending edit was made this session. */
|
|
698
|
+
row: TRow;
|
|
699
|
+
values: Map<string, unknown>;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Everything a cell-rendering path (`renderEditableCell`) needs to decide
|
|
703
|
+
* whether/how to render a given cell as an editor. Bundled into one object
|
|
704
|
+
* so `<DataGrid>` can hand it through a `useRef` (see that component's own
|
|
705
|
+
* doc on why — TanStack's `flexRender` treats `columnDef.cell` as a
|
|
706
|
+
* component type, so a closure that changes identity on every edit would
|
|
707
|
+
* remount the whole table body) while `<TreeDataGrid>`, which has no such
|
|
708
|
+
* memoized column-def layer, can just read the hook's plain `ctx` value
|
|
709
|
+
* directly every render.
|
|
710
|
+
*/
|
|
711
|
+
interface EditingCellContext<TRow> {
|
|
712
|
+
pendingEdits: Map<string, PendingRowEdit<TRow>>;
|
|
713
|
+
editErrors: Map<string, Map<string, string>>;
|
|
714
|
+
/**
|
|
715
|
+
* The one row currently showing editors, or `null`. Deliberately NOT the
|
|
716
|
+
* same thing as "has a pending edit": a row can be active with nothing
|
|
717
|
+
* changed yet (just clicked into). At most one at a time — activating a
|
|
718
|
+
* row deactivates whatever was active before it (edit row by row, not
|
|
719
|
+
* several open at once). This does NOT discard the row you switch away
|
|
720
|
+
* from: its own pending edits stay exactly as they were in `pendingEdits`,
|
|
721
|
+
* just no longer shown as editors.
|
|
722
|
+
*/
|
|
723
|
+
activeRowId: string | null;
|
|
724
|
+
/** Set only by the click that activated a row — see `EditWidgetProps.autoFocus`'s own doc for why this exists. */
|
|
725
|
+
autoFocusTarget: {
|
|
726
|
+
rowId: string;
|
|
727
|
+
columnId: string;
|
|
728
|
+
} | null;
|
|
729
|
+
getRowId: (row: TRow) => string;
|
|
730
|
+
onEdit: (column: ColumnDef<TRow>, row: TRow, value: unknown) => void;
|
|
731
|
+
/** Activates `rowId` (deactivating whatever row was active before it) and requests autofocus on `columnId`'s editor specifically — the column whose static cell was actually clicked. */
|
|
732
|
+
onActivateRow: (rowId: string, columnId: string) => void;
|
|
733
|
+
}
|
|
734
|
+
interface EditingState<TRow> {
|
|
735
|
+
pendingEdits: Map<string, PendingRowEdit<TRow>>;
|
|
736
|
+
editErrors: Map<string, Map<string, string>>;
|
|
737
|
+
hasEditErrors: boolean;
|
|
738
|
+
/** The live editing context — read directly during a render body that has no remount-avoidance concerns of its own (e.g. `<TreeDataGrid>`'s plain per-row render). */
|
|
739
|
+
ctx: EditingCellContext<TRow> | undefined;
|
|
740
|
+
/** Same context, mirrored into a ref every render — for a caller (`<DataGrid>`) whose cell-rendering closures must stay referentially stable and so can't close over `ctx` directly. */
|
|
741
|
+
ctxRef: {
|
|
742
|
+
current: EditingCellContext<TRow> | undefined;
|
|
743
|
+
};
|
|
744
|
+
handleSaveEdits: () => Promise<void>;
|
|
745
|
+
handleDiscardEdits: () => void;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Owns the full accumulate-then-save inline-editing state machine: pending
|
|
749
|
+
* edits, validation errors, which row is active, autofocus targeting, and
|
|
750
|
+
* the Save/Discard commit logic — shared by `<DataGrid>` and
|
|
751
|
+
* `<TreeDataGrid>` so the tricky parts (the async-save race around edits
|
|
752
|
+
* made while `onSave` is in flight, the one-shot autoFocus consumption) only
|
|
753
|
+
* exist, and only need fixing, in one place.
|
|
754
|
+
*/
|
|
755
|
+
declare function useEditingState<TRow>(editing: EditingOptions<TRow> | undefined, getRowId: (row: TRow) => string): EditingState<TRow>;
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Renders one cell for a column that may or may not be `editable`, given the
|
|
759
|
+
* live editing context (or `undefined` when no `editing` prop was supplied
|
|
760
|
+
* at all). Shared by `<DataGrid>` and `<TreeDataGrid>` so the click-to-
|
|
761
|
+
* activate/Escape-to-revert/autoFocus behavior — and its bug fixes — only
|
|
762
|
+
* exist in one place; see `useEditingState`'s own module doc.
|
|
763
|
+
*
|
|
764
|
+
* Not itself responsible for choosing WHICH raw value to start from
|
|
765
|
+
* (`<DataGrid>` reads it off TanStack's `CellContext.getValue()`,
|
|
766
|
+
* `<TreeDataGrid>` off a plain accessor) — callers pass `rawValue` in.
|
|
767
|
+
*/
|
|
768
|
+
declare function renderEditableCell<TRow>(column: ColumnDef<TRow>, row: TRow, rawValue: unknown, ctx: EditingCellContext<TRow> | undefined): ReactNode;
|
|
769
|
+
|
|
770
|
+
interface EditingBarProps<TRow> {
|
|
771
|
+
editing: EditingOptions<TRow>;
|
|
772
|
+
pendingRowCount: number;
|
|
773
|
+
editErrors: Map<string, Map<string, string>>;
|
|
774
|
+
onSave: () => void;
|
|
775
|
+
onDiscard: () => void;
|
|
776
|
+
/** `data-testid` for the outer bar element. Defaults to `"datagrid-edit-bar"` (also the default for the Save/Discard buttons' own testids, unless overridden below). */
|
|
777
|
+
testIdPrefix?: string;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* The Save/Discard bar `<DataGrid>` and `<TreeDataGrid>` both render above
|
|
781
|
+
* themselves once at least one pending edit exists — shared so the two
|
|
782
|
+
* grids' editing UI (and its `aria-live`/row-naming behavior) can't drift
|
|
783
|
+
* apart from each other.
|
|
784
|
+
*/
|
|
785
|
+
declare function EditingBar<TRow>({ editing, pendingRowCount, editErrors, onSave, onDiscard, testIdPrefix, }: EditingBarProps<TRow>): ReactElement;
|
|
786
|
+
|
|
460
787
|
/**
|
|
461
788
|
* Column visibility keyed by `ColumnDef.id`. A missing key means visible —
|
|
462
789
|
* this matches TanStack Table's own `VisibilityState` convention, so a
|
|
@@ -795,6 +1122,16 @@ interface DataGridProps<TRow> {
|
|
|
795
1122
|
onExpandedGroupsChange?: (expanded: Record<string, boolean>) => void;
|
|
796
1123
|
/** Alternates body row backgrounds for readability on wide/dense tables. Defaults to true. */
|
|
797
1124
|
zebra?: boolean;
|
|
1125
|
+
/**
|
|
1126
|
+
* Enables the built-in inline-editing workflow: any column with
|
|
1127
|
+
* `editable` set renders as an interactive editor, edits accumulate
|
|
1128
|
+
* locally, and a Save/Discard bar appears above the grid once at least
|
|
1129
|
+
* one exists. Omit entirely to disable — every `editable` column then
|
|
1130
|
+
* just falls back to its normal static `cell`/`defaultFormat` rendering,
|
|
1131
|
+
* same as if `editable` were never set. See `EditingOptions` for the full
|
|
1132
|
+
* contract — shared with `<TreeDataGrid>`'s own `editing` prop.
|
|
1133
|
+
*/
|
|
1134
|
+
editing?: EditingOptions<TRow>;
|
|
798
1135
|
}
|
|
799
1136
|
|
|
800
1137
|
/**
|
|
@@ -805,7 +1142,7 @@ interface DataGridProps<TRow> {
|
|
|
805
1142
|
* (`"server"`). Column filter UI defaults to the type-appropriate widget
|
|
806
1143
|
* from `src/filter` unless a column supplies its own `cell` renderer.
|
|
807
1144
|
*/
|
|
808
|
-
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, }: DataGridProps<TRow>): ReactElement;
|
|
1145
|
+
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, editing, }: DataGridProps<TRow>): ReactElement;
|
|
809
1146
|
|
|
810
1147
|
interface GridStateController {
|
|
811
1148
|
state: GridState;
|
|
@@ -1054,6 +1391,18 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1054
1391
|
isRowSelectionDisabled?: (row: TRow) => boolean;
|
|
1055
1392
|
/** Alternates body row backgrounds for readability on wide/dense tables. Defaults to true. */
|
|
1056
1393
|
zebra?: boolean;
|
|
1394
|
+
/**
|
|
1395
|
+
* Enables the same built-in inline-editing workflow `<DataGrid>` has:
|
|
1396
|
+
* any column with `editable` set renders as an interactive editor
|
|
1397
|
+
* (clicking one editable cell activates every editable column in that
|
|
1398
|
+
* row, one row active at a time), edits accumulate locally, and a
|
|
1399
|
+
* Save/Discard bar appears above the tree once at least one exists. Omit
|
|
1400
|
+
* entirely to disable — every `editable` column then just falls back to
|
|
1401
|
+
* its normal static `cell`/`defaultFormat` rendering, same as if
|
|
1402
|
+
* `editable` were never set. See `EditingOptions` (shared with
|
|
1403
|
+
* `<DataGrid>`) for the full contract.
|
|
1404
|
+
*/
|
|
1405
|
+
editing?: EditingOptions<TRow>;
|
|
1057
1406
|
}
|
|
1058
1407
|
|
|
1059
1408
|
/**
|
|
@@ -1070,7 +1419,7 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1070
1419
|
* column's cell matches `treeColumnId` (defaults to `columns[0]`); every
|
|
1071
1420
|
* other column renders exactly like it would in `<DataGrid>`.
|
|
1072
1421
|
*/
|
|
1073
|
-
declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, zebra, }: TreeDataGridProps<TRow>): ReactElement;
|
|
1422
|
+
declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, zebra, editing, }: TreeDataGridProps<TRow>): ReactElement;
|
|
1074
1423
|
|
|
1075
1424
|
interface FlatTreeRow<TRow> {
|
|
1076
1425
|
row: TRow;
|
|
@@ -1126,4 +1475,4 @@ interface UseTreeStateOptions<TRow> extends TreeAccessors<TRow> {
|
|
|
1126
1475
|
*/
|
|
1127
1476
|
declare function useTreeState<TRow>({ data, getRowId, getChildren, hasChildren, onLoadChildren, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, }: UseTreeStateOptions<TRow>): TreeStateController<TRow>;
|
|
1128
1477
|
|
|
1129
|
-
export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanFilter, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateRangeFilter, type DebouncedCallback, type EnumColumn, EnumFilter, type EnumOption, type FilterDescriptor, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type MenuItem, type MenuItemContext, type NumberColumn, NumberComparisonFilter, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type ResolvedMenuItem, type SortDescriptor, type StringColumn, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, canHideColumn, canHideGroup, countVisible, defaultAlign, defaultFormat, evaluateFilter, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isColumnVisible, isCompositeFilterDescriptor, isFilterDescriptor, isFilterable, isSortable, processClientData, renderDefaultFilterWidget, resolveMenuItems, storageKeyFor, useDebouncedCallback, useGridState, useTreeState };
|
|
1478
|
+
export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanEditor, BooleanFilter, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateEditor, DateRangeFilter, type DebouncedCallback, EditFieldError, type EditWidgetProps, type EditedRow, EditingBar, type EditingBarProps, type EditingCellContext, type EditingOptions, type EditingState, type EnumColumn, EnumEditor, EnumFilter, type EnumOption, type FilterDescriptor, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type MenuItem, type MenuItemContext, type NumberColumn, NumberComparisonFilter, NumberEditor, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type PendingRowEdit, type ResolvedMenuItem, type SortDescriptor, type StringColumn, StringEditor, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, canHideColumn, canHideGroup, countVisible, defaultAlign, defaultFormat, editErrorId, evaluateFilter, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isColumnVisible, isCompositeFilterDescriptor, isEditable, isFilterDescriptor, isFilterable, isSortable, processClientData, renderDefaultEditWidget, renderDefaultFilterWidget, renderEditableCell, resolveMenuItems, storageKeyFor, toDate, useDebouncedCallback, useEditingState, useGridState, useTreeState };
|