@tradalab/lyra 3.15.0 → 3.16.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.
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ReactNode, HTMLAttributes } from 'react';
3
- import { ColumnDef, Row, Cell, Column, Table, Header, HeaderGroup } from '@tanstack/react-table';
4
- export { ColumnDef } from '@tanstack/react-table';
3
+ import { VisibilityState, ColumnOrderState, ColumnSizingState, RowData, ColumnDef, Row, Cell, Column, Table, Header, HeaderGroup } from '@tanstack/react-table';
4
+ export { ColumnDef, ColumnSizingState, VisibilityState } from '@tanstack/react-table';
5
5
 
6
6
  /**
7
7
  * Case-insensitive search over chosen fields, for a list the server does NOT page.
@@ -17,6 +17,38 @@ export { ColumnDef } from '@tanstack/react-table';
17
17
  */
18
18
  declare function filterRows<T>(rows: T[], q: string, fields: (r: T) => (string | undefined | null)[]): T[];
19
19
 
20
+ /** What `useTableState` keeps for one table. */
21
+ type TableState = {
22
+ sorts?: TableSort[];
23
+ columnVisibility?: VisibilityState;
24
+ columnOrder?: ColumnOrderState;
25
+ groupBy?: string | null;
26
+ columnSizing?: ColumnSizingState;
27
+ columnFilters?: ColumnFilters;
28
+ };
29
+ /**
30
+ * A table's sort keys, column order, hidden columns, widths, filters and grouping, kept per device.
31
+ * Spread `props` into `DataTable`. A browser that refuses storage keeps them for the session.
32
+ */
33
+ declare function useTableState(key: string, defaults?: TableState): {
34
+ props: {
35
+ sorts: TableSort[];
36
+ onSortsChange: (sorts: TableSort[]) => void;
37
+ columnOrder: ColumnOrderState;
38
+ onColumnOrderChange: (columnOrder: ColumnOrderState) => void;
39
+ groupBy: string | null;
40
+ onGroupByChange: (groupBy: string | null) => void;
41
+ columnVisibility: VisibilityState;
42
+ onColumnVisibilityChange: (columnVisibility: VisibilityState) => void;
43
+ columnSizing: ColumnSizingState;
44
+ onColumnSizingChange: (columnSizing: ColumnSizingState) => void;
45
+ columnFilters: ColumnFilters;
46
+ onColumnFiltersChange: (columnFilters: ColumnFilters) => void;
47
+ };
48
+ state: TableState;
49
+ reset: () => void;
50
+ };
51
+
20
52
  /**
21
53
  * The row above a table: narrowing on the left, actions on the right.
22
54
  *
@@ -146,6 +178,53 @@ declare function usePager(options?: UsePagerOptions): {
146
178
  };
147
179
  };
148
180
 
181
+ declare module "@tanstack/react-table" {
182
+ interface ColumnMeta<TData extends RowData, TValue> {
183
+ /** Header and cell alignment. `right` also sets tabular figures, for columns of numbers. */
184
+ align?: "left" | "center" | "right";
185
+ /** The column's name in the column menu, when its header is not a plain string. */
186
+ label?: string;
187
+ /** Classes on the header and on every cell of the column. */
188
+ className?: string;
189
+ /** Keep the column in view while the table scrolls sideways. Its width is fixed at `size`. */
190
+ pin?: "left" | "right";
191
+ /** The value written to CSV for this column, when the cell value is not it (or there is none). */
192
+ exportValue?: (row: TData) => unknown;
193
+ /**
194
+ * A filter for the column in a row under the header. Text matches without accents; a select
195
+ * lists `options`, or the values of a table that holds every row, and is left out otherwise.
196
+ */
197
+ filter?: "text" | "select" | {
198
+ options: readonly {
199
+ value: string;
200
+ label?: string;
201
+ }[];
202
+ };
203
+ /** Offered in the "Group by" select. Subtotals come from TanStack's `aggregationFn`/`aggregatedCell`. */
204
+ groupable?: boolean;
205
+ }
206
+ }
207
+ /** Per-column filter values by column id; an empty string is no filter. */
208
+ type ColumnFilters = Record<string, string>;
209
+ /** One-column sort, as `DataTable` reads and reports it. */
210
+ type TableSort = {
211
+ id: string;
212
+ desc: boolean;
213
+ };
214
+ /** The sort keys after a shift-click on column `id`: added ascending, then descending, then removed. */
215
+ declare function nextSorts(current: readonly TableSort[], id: string): TableSort[];
216
+ /** The column order after moving `id` to where `target` is. */
217
+ declare function moveColumn(order: readonly string[], id: string, target: string): string[];
218
+ /** The sort after a click on column `id`: ascending, then descending, then none. */
219
+ declare function nextSort(current: TableSort | null, id: string): TableSort | null;
220
+ /**
221
+ * RFC 4180 CSV with CRLF rows. A string that a spreadsheet would run as a formula gets a leading
222
+ * `'`; numbers are written as they are, so `-5` stays a number.
223
+ */
224
+ declare function toCsv(header: readonly string[], rows: readonly (readonly unknown[])[]): string;
225
+ /** The name a column goes by in the column menu: `meta.label`, a string header, or its id. */
226
+ declare function columnLabel<TData, TValue>(column: Column<TData, TValue>): string;
227
+
149
228
  declare const TableContext: React.Context<{
150
229
  data: unknown[];
151
230
  columns: ColumnDef<unknown, unknown>[];
@@ -279,10 +358,108 @@ interface TableProps<TData, TValue> {
279
358
  };
280
359
  /** Open a row: the whole row clicks, and Enter or Space opens it from the keyboard. */
281
360
  onRowClick?: (row: TData) => void;
282
- /** Accessible labels for the selection checkboxes. */
361
+ /** Labels for selection: the two checkboxes, the clear button and the count in the action bar. */
283
362
  selectLabels?: {
284
363
  rows?: string;
285
364
  row?: string;
365
+ clear?: string;
366
+ count?: (n: number) => ReactNode;
367
+ };
368
+ /** Bar above the table while rows are selected, e.g. bulk buttons. Gets every selected id. */
369
+ selectionActions?: (ids: string[]) => ReactNode;
370
+ /**
371
+ * Sort by clicking a header. Tables that hold every row sort here; paged-by-server and infinite
372
+ * tables sort only through `onSortChange`, since sorting one page would mislead.
373
+ */
374
+ sortable?: boolean;
375
+ /** Controlled sort, e.g. read from the URL. `null` is unsorted; omit to keep it inside the table. */
376
+ sort?: TableSort | null;
377
+ /** Called with the next sort. A server-paged table must refetch with it. */
378
+ onSortChange?: (sort: TableSort | null) => void;
379
+ /** A "Columns" menu in the control bar to hide and show columns; the last visible one stays. */
380
+ columnToggle?: boolean;
381
+ /** Label of the column menu button. */
382
+ columnsLabel?: string;
383
+ /** Controlled visibility by column id, e.g. kept in local storage; omit to keep it inside. */
384
+ columnVisibility?: VisibilityState;
385
+ /** Called with the next visibility map. */
386
+ onColumnVisibilityChange?: (visibility: VisibilityState) => void;
387
+ /** Keep the header row in view; bound the height with `className`, e.g. `max-h-[60vh]`. */
388
+ stickyHeader?: boolean;
389
+ /** Placeholder rows drawn on the first load instead of the `loadingText` line. */
390
+ loadingRows?: number;
391
+ /**
392
+ * Drag a header edge (or use the arrow keys on it) to resize. Widths start at each column's
393
+ * `size`, and the table becomes exactly as wide as its columns.
394
+ */
395
+ resizableColumns?: boolean;
396
+ /** Controlled widths by column id, e.g. kept in local storage. */
397
+ columnSizing?: ColumnSizingState;
398
+ /** Called with the next widths. */
399
+ onColumnSizingChange?: (sizing: ColumnSizingState) => void;
400
+ /** Accessible label prefix of a resize handle; the column name follows. */
401
+ resizeLabel?: string;
402
+ /** A panel under a row, opened by a chevron. Without `getRowId` open panels close when `data` changes. */
403
+ renderDetail?: (row: TData) => ReactNode;
404
+ /** Rows with no detail get no chevron. Default: every row has one. */
405
+ rowHasDetail?: (row: TData) => boolean;
406
+ /** Accessible labels of the detail chevron. */
407
+ detailLabels?: {
408
+ expand?: string;
409
+ collapse?: string;
410
+ };
411
+ /**
412
+ * A button in the control bar that downloads the rows as CSV: every row the table holds, as
413
+ * filtered and sorted, with the visible columns. Not offered on server-paged or infinite tables.
414
+ */
415
+ exportCsv?: {
416
+ filename: string;
417
+ label?: string;
418
+ };
419
+ /**
420
+ * Controlled column filters (see `meta.filter`). Tables that hold every row filter here; a
421
+ * server-paged or infinite table only reports them and must refetch.
422
+ */
423
+ columnFilters?: ColumnFilters;
424
+ /** Called with the next filters. */
425
+ onColumnFiltersChange?: (filters: ColumnFilters) => void;
426
+ /** Labels of the filter row: the text box placeholder and the "any value" choice of a select. */
427
+ filterLabels?: {
428
+ placeholder?: string;
429
+ all?: string;
430
+ };
431
+ /** Shift-click a header to add it as a further sort key; a plain click sorts by that column alone. */
432
+ multiSort?: boolean;
433
+ /** Controlled sort keys in order, e.g. from `useTableState`. Wins over `sort`. */
434
+ sorts?: TableSort[];
435
+ /** Called with the next sort keys; `onSortChange` still gets the first one. */
436
+ onSortsChange?: (sorts: TableSort[]) => void;
437
+ /**
438
+ * Group rows by this column under a header row with a count and subtotals. Only tables that hold
439
+ * every row group; a "Group by" select lists the columns marked `meta.groupable`.
440
+ */
441
+ groupBy?: string | null;
442
+ /** Called with the next grouping column, or `null` for none. */
443
+ onGroupByChange?: (column: string | null) => void;
444
+ /** Labels of grouping: the select, its "none" choice and the row count of a group. */
445
+ groupLabels?: {
446
+ groupBy?: string;
447
+ none?: string;
448
+ count?: (n: number) => string;
449
+ };
450
+ /** Drag a header, or press Alt+Arrow on it, to move the column. Pinned columns stay put. */
451
+ reorderableColumns?: boolean;
452
+ /** Controlled column order by id, e.g. from `useTableState`. */
453
+ columnOrder?: string[];
454
+ /** Called with the next column order. */
455
+ onColumnOrderChange?: (order: string[]) => void;
456
+ /**
457
+ * Render only the rows in view, for a long unpaged or infinite list. Bound the height with
458
+ * `className` (e.g. `max-h-[70vh]`); rows may differ in height, they are measured.
459
+ */
460
+ virtualize?: boolean | {
461
+ estimateRowHeight?: number;
462
+ overscan?: number;
286
463
  };
287
464
  }
288
465
  type RowSelection<TData> = {
@@ -305,6 +482,6 @@ type DataTableProps<TData, TValue> = TableProps<TData, TValue> & RowSelection<TD
305
482
  * reader opened it with.
306
483
  */
307
484
  declare function pageWindow(index: number, count: number, radius?: number): (number | null)[];
308
- declare function DataTable<TData, TValue>({ columns, data, loading, emptyText, empty, loadingText, previousLabel, nextLabel, pageSize, unpaged, className, searchable, searchPlaceholder, onReload, reloadLabel, toolbar, onLoadMore, hasMore, loadingMore, loadingMoreText, pageIndex, pageCount, onPageChange, pageSizeOptions, onPageSizeChange, rangeLabel, pageLabels, onRowClick, getRowId, selected, onSelectedChange, selectLabels, }: DataTableProps<TData, TValue>): React.JSX.Element;
485
+ declare function DataTable<TData, TValue>({ columns, data, loading, emptyText, empty, loadingText, previousLabel, nextLabel, pageSize, unpaged, className, searchable, searchPlaceholder, onReload, reloadLabel, toolbar, onLoadMore, hasMore, loadingMore, loadingMoreText, pageIndex, pageCount, onPageChange, pageSizeOptions, onPageSizeChange, rangeLabel, pageLabels, onRowClick, getRowId, selected, onSelectedChange, selectLabels, selectionActions, sortable, sort, onSortChange, columnToggle, columnsLabel, columnVisibility, onColumnVisibilityChange, stickyHeader, loadingRows, resizableColumns, columnSizing, onColumnSizingChange, resizeLabel, renderDetail, rowHasDetail, detailLabels, exportCsv, columnFilters, onColumnFiltersChange, filterLabels, multiSort, sorts, onSortsChange, groupBy, onGroupByChange, groupLabels, reorderableColumns, columnOrder, onColumnOrderChange, virtualize, }: DataTableProps<TData, TValue>): React.JSX.Element;
309
486
 
310
- export { DEFAULT_PAGE_SIZE, DataTable, type DataTableProps, PAGE_SIZE_OPTIONS, type PagerLabels, type PagerProps, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableColumnHeader, type TableColumnHeaderProps, TableContext, TableFilterBar, type TableFilterChip, TableFilterChips, TableHead, type TableHeadProps, TableHeader, TableHeaderGroup, type TableHeaderGroupProps, type TableHeaderProps, TableProvider, type TableProviderProps, TableReload, TableRow, type TableRowProps, TableSearch, type UsePagerOptions, filterRows, pageWindow, usePager };
487
+ export { type ColumnFilters, DEFAULT_PAGE_SIZE, DataTable, type DataTableProps, PAGE_SIZE_OPTIONS, type PagerLabels, type PagerProps, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableColumnHeader, type TableColumnHeaderProps, TableContext, TableFilterBar, type TableFilterChip, TableFilterChips, TableHead, type TableHeadProps, TableHeader, TableHeaderGroup, type TableHeaderGroupProps, type TableHeaderProps, TableProvider, type TableProviderProps, TableReload, TableRow, type TableRowProps, TableSearch, type TableSort, type TableState, type UsePagerOptions, columnLabel, filterRows, moveColumn, nextSort, nextSorts, pageWindow, toCsv, usePager, useTableState };