datatable-tree 0.0.0-stage → 0.1.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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +251 -2
  3. package/dist/DataTable.d.ts +583 -0
  4. package/dist/DataTable.js +620 -0
  5. package/dist/Draggable.d.ts +35 -0
  6. package/dist/Draggable.js +91 -0
  7. package/dist/ListBox.d.ts +132 -0
  8. package/dist/ListBox.js +243 -0
  9. package/dist/ListVirtualizer.d.ts +59 -0
  10. package/dist/ListVirtualizer.js +180 -0
  11. package/dist/TreeList.d.ts +196 -0
  12. package/dist/TreeList.js +300 -0
  13. package/dist/config.d.ts +55 -0
  14. package/dist/config.js +33 -0
  15. package/dist/datatable.css +161 -0
  16. package/dist/hooks.d.ts +27 -0
  17. package/dist/hooks.js +115 -0
  18. package/dist/index.d.ts +12 -0
  19. package/dist/index.js +15 -0
  20. package/dist/interfaces.d.ts +269 -0
  21. package/dist/interfaces.js +3 -0
  22. package/dist/mobx-adapter.d.ts +12 -0
  23. package/dist/mobx-adapter.js +21 -0
  24. package/dist/reactivity.d.ts +112 -0
  25. package/dist/reactivity.js +155 -0
  26. package/dist/styles.d.ts +64 -0
  27. package/dist/styles.js +86 -0
  28. package/dist/theme.d.ts +160 -0
  29. package/dist/theme.js +239 -0
  30. package/dist/util.d.ts +28 -0
  31. package/dist/util.js +45 -0
  32. package/package.json +143 -4
  33. package/src/DataTable.tsx +1332 -0
  34. package/src/Draggable.tsx +133 -0
  35. package/src/ListBox.tsx +423 -0
  36. package/src/ListVirtualizer.ts +234 -0
  37. package/src/TreeList.tsx +590 -0
  38. package/src/config.tsx +96 -0
  39. package/src/css.d.ts +1 -0
  40. package/src/datatable.css +161 -0
  41. package/src/hooks.ts +138 -0
  42. package/src/index.ts +15 -0
  43. package/src/interfaces.ts +309 -0
  44. package/src/mobx-adapter.ts +24 -0
  45. package/src/reactivity.ts +222 -0
  46. package/src/styles.tsx +102 -0
  47. package/src/theme.ts +346 -0
  48. package/src/util.ts +60 -0
@@ -0,0 +1,583 @@
1
+ import { ReactNode } from 'react';
2
+ import { Holder } from 'holders';
3
+ import { IMapSource } from './interfaces.js';
4
+ import { VirtualizationSettings } from './ListVirtualizer.js';
5
+ import { WatchableArrayLike } from './reactivity.js';
6
+ import { Styles } from './styles.js';
7
+ import { TableTheme } from './theme.js';
8
+ import { TreeItem, TreeItemProps, TreeListAuxProps, TreeListMainProps } from './TreeList.js';
9
+ import { nully, Optionalize } from './util.js';
10
+ /**
11
+ * `DataTable` overview
12
+ * --------------------
13
+ *
14
+ * `DataTable` and `DataTableCore` are based on `TreeListCore`, so please have a look at
15
+ * the simpler `TreeList`/`TreeListCore` components first. The difference is that while
16
+ * `TreeList` is a tree of "items", `DataTable` is a tree of "rows" and therefore adds
17
+ * a set of columns and column headers. If you want a plain table rather than a tree,
18
+ * simply don't provide properties that would make it a tree.
19
+ *
20
+ * - The only required props are `columns` and `list` (or `tree`). `list` is an array of any
21
+ * type `T`, while `columns` is typically an array of `DataTableColumn<T>`.
22
+ * - `DataTable` is the usual choice. `DataTableCore` is the same, but omits the outer
23
+ * `<div>` and `<table>` elements (which is useful if you want to change the rendering
24
+ * method, e.g. to avoid `table` in favor of flexbox).
25
+ * - The table uses `table-layout: fixed`, so the widths of the columns are determined by
26
+ * the header row alone. If you provide a numeric/Holder `width` for a column, the user
27
+ * can resize it by dragging the right edge of the column header.
28
+ * - To make a tree, provide a `getChildren` or `getParents` prop and set `isTreeCol: true`
29
+ * on exactly one of the columns.
30
+ * - If you want to mix different kinds of rows on a single table (often parents and
31
+ * children are different things, for example), the `getRowConfig` prop lets you
32
+ * configure behavior for each row type individually (see example below).
33
+ *
34
+ * Most important types
35
+ * --------------------
36
+ *
37
+ * - `DataTableProps`: props of `DataTable`. Inherits `DataTableCoreProps`, `TreeListMainProps`
38
+ * `TreeListAuxProps` and most of `ListCoreProps`.
39
+ * - `DataTableColumn<T,...>`: settings for a single column. Inherits from
40
+ * `DataTableCellConfig<T,T,...>`.
41
+ *
42
+ * Support for multiple row types
43
+ * ------------------------------
44
+ *
45
+ * A table has a single set of columns, but the way values are chosen for a column can be
46
+ * specified separately for each row type. Here is a simple example of a "file browser" to
47
+ * explain the principle:
48
+ *
49
+ * class FileInfo {
50
+ * constructor(public name: string, public folderPath: string, public size: number, public modified: Date) {}
51
+ * }
52
+ *
53
+ * const files = [
54
+ * new FileInfo('README.md', '', 1345, new Date(2024,0,2)),
55
+ * new FileInfo('index.html', 'Documents', 1345, new Date(2024,0,2)),
56
+ * new FileInfo('Life 3.0.pdf', 'Documents/Books/Nonfiction', 5235091, new Date(2022,2,3)),
57
+ * new FileInfo('Rules for Radicals.pdf', 'Documents/Books/Nonfiction', 583020, new Date(2022,0,1)),
58
+ * new FileInfo('IMG_20240106_101958_861.jpg', 'Documents/Photos', 5830220, new Date(2024,0,6)),
59
+ * new FileInfo('IMG_20240107_141614_680.jpg', 'Documents/Photos', 5731990, new Date(2024,0,7)),
60
+ * new FileInfo('test.pdf', 'Books/Nonfiction', 5235091, new Date(2022,2,3)),
61
+ * ];
62
+ *
63
+ * export function FileTree() {
64
+ * // You don't have to memoize the column configuration, but hey, why not?
65
+ * const { columns, folderConfig } = useMemo(getColumnsAndRowConfigs, []);
66
+ *
67
+ * return (
68
+ * // TypeScript can infer the type argument(s), but in case of a type error, the
69
+ * // error message tends to be easier to understand if the type argument is explicit.
70
+ * <DataTable<FileInfo|string>
71
+ * columns={columns}
72
+ * list={files}
73
+ * // `getParents` is only called for items in `list`, all of which are `FileInfo`.
74
+ * getParents={item => getParentPathsOf((item as FileInfo).folderPath, '/', true)}
75
+ * getRowConfig={item => {
76
+ * if (typeof item.item === 'string') {
77
+ * return folderConfig;
78
+ * }
79
+ * }}
80
+ * // Note: if your folders close, or the selection is lost, whenever the outer
81
+ * // component is re-rendered, it means you need to add a `getSelKey` prop.
82
+ * // But in this example the folders are just strings, which serve as
83
+ * // their own keys.
84
+ * />);
85
+ *
86
+ * function getColumnsAndRowConfigs() {
87
+ * // Basic column configuration
88
+ * let columns: DataTableColumn<string|FileInfo>[] = [
89
+ * {
90
+ * name: 'name',
91
+ * heading: 'Name',
92
+ * width: 300,
93
+ * isTreeCol: true,
94
+ * },
95
+ * {
96
+ * name: 'size',
97
+ * heading: 'Size',
98
+ * width: 100,
99
+ * renderCell(node, props) {
100
+ * let size = props.value as number;
101
+ * if (size > 1024 * 1024) {
102
+ * return `${(size / (1 << 20)).toFixed(1)} MiB`;
103
+ * } else {
104
+ * return size > 1024 ? `${(size / 1024).toFixed(1)} KiB` : `${size} bytes`;
105
+ * }
106
+ * }
107
+ * },
108
+ * {
109
+ * name: 'modified',
110
+ * heading: 'Modified',
111
+ * width: 220,
112
+ * renderCell(node, props) {
113
+ * return (props.value as unknown as Date).toLocaleString();
114
+ * }
115
+ * },
116
+ * ];
117
+ *
118
+ * // Configures "folder" (parent) rows
119
+ * let folder = new Map<string, DataTableCellConfig<string|FileInfo, string>>([
120
+ * ['name', {
121
+ * getValue: path => path.substring(path.lastIndexOf('/') + 1),
122
+ * getColSpan: _ => 3,
123
+ * }],
124
+ * ]);
125
+ *
126
+ * return { columns, folderConfig: { columns: folder } };
127
+ * }
128
+ * }
129
+ *
130
+ * In this example, files are `FileInfo` while folders are simply strings. The main `columns`
131
+ * list contains default settings, and configuration for a specific row type is specified with
132
+ * an object of type `ItemAndColumns` (`{ columns: Map<string, DataTableCellConfig<...>>, ... }`).
133
+ * In this example we only need a single `Map<string, DataTableCellConfig>` for folders, but
134
+ * often it's more convenient to define one for every row type.
135
+ *
136
+ * Note that the folders are derived on-the-fly from the files using `getParentPathsOf`
137
+ * (e.g. 'Books/Nonfiction' => ['Books', 'Books/Nonfiction']). You cannot simply use
138
+ * `folderPath.split('/')` because if a folder such as 'Nonfiction' appears as part of multiple
139
+ * paths, as it does in this example, `DataTable` will treat it like the "same" item, which can
140
+ * cause problems, e.g. if you click one of the 'Nonfiction' folders, the other one will be
141
+ * selected too. `getParentPathsOf` ensures that the two 'Nonfiction' folders are different
142
+ * strings, and a `getValue` method is also required so that 'Books/Nonfiction' shows up as
143
+ * 'Nonfiction'.
144
+ **/
145
+ export type DefaultRowProps = React.ComponentProps<'td'> & React.ComponentProps<'tr'> & {
146
+ highlightChildrenOfSelectedParents?: boolean;
147
+ noPadding?: boolean | nully;
148
+ };
149
+ /** Settings for rendering cells in a specific column, either for a specific type of row (if
150
+ * this object is in the map returned by the table's `getRowConfig` prop), or for all rows.
151
+ * This type is a subset of `DataTableColumn`. The most important properties are `getValue`
152
+ * and `renderCell`.
153
+ *
154
+ * @template T is the union type of all rows in the DataTable or DataTableCore.
155
+ * @template TRow is the type of row that the the current object is designed for.
156
+ * @template ColName is the type of `name` and of `ColName` in the `this` passed to some functions
157
+ * @template ItemProps is the type of the `cellProps` property.
158
+ */
159
+ export interface DataTableCellConfig<T, TRow = T, ColName = string, ItemProps = DefaultRowProps> {
160
+ /** Contains props to apply to each cell in this column (except to the standard header cell),
161
+ * or a function to get a set of props that depends on the current row. */
162
+ cellProps?: ItemProps | ((item: TreeItem<T, TRow>) => ItemProps);
163
+ /** Provide this to customize the way that the value of this column is obtained
164
+ * from a row. If this is not provided, `node.item[this.name.toString()]` is used. The
165
+ * value obtained from this function is passed to the renderer via `TableCellProps`.
166
+ *
167
+ * The return type should be `ReactNode` if you don't provide `renderCell` or `RenderCell`,
168
+ * and `string|number|boolean` if you don't provide sorting properties such as
169
+ * `getSortableValue` or `compare`.
170
+ *
171
+ * If the table has a `getRowConfig` prop, it is called before `getValue`, both to
172
+ * determine what value of `item` will be passed to `getValue`, and also _which `getValue`
173
+ * function_ will be called, in case you provide different `getValue` functions for
174
+ * different row types.
175
+ *
176
+ * As a case study, let's consider `Date`. Here are the main ways you might handle
177
+ * rendering and sorting for them:
178
+ *
179
+ * 1. Convert the `Date` to a string in `getValue`, then provide a separate
180
+ * `getSortableValue` function that just returns the `Date` so that the column can be
181
+ * sorted correctly. In this case, you don't need to provide `renderCell`.
182
+ * 2. Return the `Date` from `getValue`, then check in `renderCell` whether `props.value`
183
+ * is actually a `Date` and, if so, format it as a string or JSX there.
184
+ * 3. Don't provide a `getValue` function at all, only a `renderCell`. In this case,
185
+ * `name` must refer to the property that contains the `Date`, and `renderCell` must
186
+ * convert the `Date` to a string or JSX.
187
+ **/
188
+ getValue?(this: DataTableColumn<T, TRow, ColName, ItemProps>, item: TRow, node: TreeItem<T>): any;
189
+ /** This function is called to render a column value to a ReactNode, not including the
190
+ * outer `<td>` element. If not provided, `defaultRenderCell` is used.
191
+ *
192
+ * You must provide `renderCell` or `RenderCell` if the cell's value (determined by `name`
193
+ * or `getValue`) is not always a `ReactNode` (string, number, boolean or JSX).
194
+ *
195
+ * You can think of rendering customizations as a three-level hierarchy:
196
+ *
197
+ * 1. `getValue` prop: in charge of selecting low-level cell content, such as a
198
+ * string, number, boolean or `<span>`. `DefaultDataTableRow` calls this function
199
+ * and stores the result in `TableCellProps.value`.
200
+ * 2. `renderCell` prop: in charge of selecting the "main" cell content, such as a
201
+ * `<div>` element to control padding.
202
+ * 3. `RenderCell` prop: the top level, in charge of rendering the entire cell
203
+ * including `<td>` and the tree indent (if any).
204
+ *
205
+ * In the simplest cases (e.g. string or boolean columns) you may not need to
206
+ * customize any of these, and in simple cases you only need to provide `getValue`.
207
+ * On the other end of the scale, you can provide `RenderCell` for maximum control.
208
+ * It is recommended that each level use the output of the previous level, i.e.
209
+ * `RenderCell` should get the "main" cell content by calling the function
210
+ * `column.renderCell ?? defaultRenderCell`, while `renderCell` should include
211
+ * `props.value` in its output.
212
+ ***/
213
+ renderCell?(node: TreeItem<T, TRow>, props: DataTableCellProps<T, TRow, ColName, ItemProps>): React.ReactNode;
214
+ /** This component is used to render a data cell. Usually it should be left undefined
215
+ * so that the `DefaultDataTableCell` component will be used. If you just want to add
216
+ * attributes to the `<td>` element, you can set `cellProps` instead.
217
+ *
218
+ * If you provide this prop, you are responsible for rendering the outer `<td>` element,
219
+ * and for using other relevant attributes of the column and the cell to produce output,
220
+ * such as:
221
+ * - Including `cellProps` and `colSpan` in your output, if applicable
222
+ * - Including the value of the cell (`props.value`) into the output
223
+ * - Rendering the tree indent if `isTreeCol` may be true, e.g. by calling
224
+ * `props.renderTreeIndent?.()` and including its output at the left edge of the cell.
225
+ **/
226
+ RenderCell?: React.ComponentType<DataTableCellProps<T, TRow, ColName, ItemProps>>;
227
+ /** This function allows you to cause this column to span multiple columns sometimes.
228
+ * If this function returns a value greater than one, the default row rendering code
229
+ * will skip rendering the spanned columns after this column (e.g. if it returns 3,
230
+ * the row renderer skips rendering two columns afterward) and the default cell
231
+ * renderer will set the `colSpan` prop on the `td`. If this function returns a value
232
+ * less than one, it's treated the same as one. */
233
+ getColSpan?(node: TreeItem<T, TRow>, props: DataTableCellProps<T, TRow, ColName, ItemProps>): number | undefined;
234
+ }
235
+ /** Properties of a single column of a `<DataTable>`. The most important properties are
236
+ * `name`, `heading`, `getValue`, `width` and `renderCell`.
237
+ *
238
+ * @template T is the union type of all row types in the DataTable or DataTableCore.
239
+ * @template TRow is normally just `T`, but when the table has a `getRowConfig` prop, the
240
+ * configuration returned by that prop is combined with the information in the
241
+ * original `DataTableColumn<T,T>` objects to produce a set of objects of type
242
+ * `DataTableColumn<T,TRow>`.
243
+ * @template ColName is the type of the `name` property.
244
+ * @template ItemProps is the type of the `headingProps` and `cellProps` properties.
245
+ */
246
+ export interface DataTableColumn<T, TRow = T, ColName = string, ItemProps = DefaultRowProps> extends DataTableCellConfig<T, TRow, ColName, ItemProps> {
247
+ /** The `name` property is used in the following ways.
248
+ * - If no `heading` or `RenderHeading` is provided, it is shown as the column heading
249
+ * - If no `getValue` is provided, `name.toString()` is treated as a property name
250
+ * and used to get the value for this column on each data row.
251
+ * - `name.toString()` is also used as the React `key` on the column heading
252
+ *
253
+ * IMPORTANT: `name` (if given) must be unique among columns in a table, because it is
254
+ * used as a React key. If it isn't unique, columns with that name may glitch out by, for
255
+ * example, being duplicated by React.
256
+ **/
257
+ name: ColName;
258
+ /** The label to show on the table heater. If this is missing, `name` is displayed. */
259
+ heading?: ReactNode;
260
+ /** True if this column is the "tree column" which is indented and has buttons to expand
261
+ * and collapse items that have children. If and only if this property is truthy, a prop
262
+ * called `renderTreeIndent` is provided to the cell renderer. */
263
+ isTreeCol?: boolean;
264
+ /** Default or current column width. Columns require a numeric `width` to allow users to
265
+ * resize (see also: `noResize`), but this prop is optional since the browser can choose a
266
+ * width based on the headings row of the table. Providing a `Holder` allows you to get
267
+ * the current width (in case the user resized it) or set the width dynamically. */
268
+ width?: number | Holder<number>;
269
+ /** When a user sorts a column by clicking it, normally the column is sorted by "value" of
270
+ * the column (based on `getValue` or `name`). If you need sorting to be based on something
271
+ * else, this property is the most convenient way to do it. See also: `getComparer`.
272
+ *
273
+ * Note: this prop doesn't have a row-type-specific version, so if you provide it,
274
+ * `getRowConfig` is not called as part of the sorting process.
275
+ **/
276
+ getSortableValue?(this: DataTableColumn<T, T, ColName, ItemProps>, node: TreeItem<T>): any;
277
+ /** A function to compare two values that were selected based on two rows of the table. The
278
+ * `a` and `b` values passed to the comparer are the values returned by `getSortableValue`,
279
+ * or by `getValue` if `getSortableValue` is not provided, or by using `name` to look up
280
+ * the value of the column. If no `compare` function is provided, `DataTableCore` will
281
+ * compare values using `>` and `<` operators instead.
282
+ *
283
+ * For text columns, you should typically use `compare: compareByLocale`.
284
+ **/
285
+ compare?: (a: any, b: any) => number;
286
+ /** This rarely-used prop provides full control over comparisons between items when sorting
287
+ * this column. If you provide this, then `getValue`, `getSortableValue` and `getComparer`
288
+ * are not called during the sorting process for this column. */
289
+ getNodeComparer?(this: DataTableColumn<T, T, ColName, ItemProps>, descending: boolean): (a: TreeItem<T, T>, b: TreeItem<T, T>) => number;
290
+ /** Contains a `style` and/or `className` to apply to the heading cell.
291
+ * See also `DataTableCoreProps.headingRowProps`.
292
+ *
293
+ * Note: if you provide your own `RenderHeading` then this prop is only used if
294
+ * your custom renderer uses it. */
295
+ headingProps?: ItemProps;
296
+ /** This function is called to render a column header to a ReactNode. Your custom
297
+ * component must include the outer `<th>` element, and is recommended to use
298
+ * `headingProps`. **/
299
+ RenderHeading?: React.ComponentType<DataTableHeadingProps<T, ColName, ItemProps>>;
300
+ /** If true, users cannot sort the column by clicking on the column heading and the
301
+ * sort-direction icon (if any) is hidden. Sorting based on `sortComparer` and
302
+ * `columnsToSortBy` still works. */
303
+ noSort?: boolean;
304
+ /** If true, the resize cursor is not shown and the user cannot resize the column.
305
+ * Note: columns also cannot be resized if they don't have a `width` value. */
306
+ noResize?: boolean;
307
+ /** Maximum width when user is resizing (default: unlimited) */
308
+ maxWidth?: number;
309
+ /** A function to modify a proposed column width when user is resizing. If this is
310
+ * not provided, a default minimum column width of 30 (or `width`, if less than 30) is
311
+ * enforced. This function is called before enforcing `maxWidth`. */
312
+ clampWidth?(proposedWidth: number, column: DataTableColumn<T, T, ColName, ItemProps>): number;
313
+ }
314
+ /** Props passed to the renderer for the heading row of a `<DataTable>`.
315
+ * Note: if you need access to other props that were passed to `DataTable`,
316
+ * use `const tableProps = useContext(DataTableContext);`. */
317
+ export interface DataTableHeadingRowProps<ColName = string, ItemProps = DefaultRowProps> {
318
+ headingRowProps?: ItemProps;
319
+ /** A function to get which sort icon (ascending or descending) to show */
320
+ getColumnSortIndicator(colName: ColName): SortDirection | undefined;
321
+ /** A function to gets the current width of column width, if set. */
322
+ getColumnWidth(colName: ColName): number | undefined;
323
+ /** A function to save a column width. Called as the resize handle is dragged by the user. */
324
+ setColumnWidth(colName: ColName, width: number): void;
325
+ /** A function to change the table's sort order. */
326
+ onHeadingClick(colName: ColName): void;
327
+ }
328
+ /** Props passed to the renderer for an entire row of data in a DataTable. */
329
+ export interface DataTableRowProps<T, K = T, ItemProps = DefaultRowProps> extends Omit<TreeItemProps<T, K, ItemProps>, 'renderItem'> {
330
+ }
331
+ /** Props passed when rendering a single heading in a DataTable. */
332
+ export interface DataTableHeadingProps<T, ColName = string, ItemProps = DefaultRowProps> extends DataTableHeadingRowProps<ColName, ItemProps> {
333
+ /** Information about the column being rendered */
334
+ column: DataTableColumn<T, T, ColName, ItemProps>;
335
+ }
336
+ /** Props passed when rendering one cell of a DataTable. */
337
+ export interface DataTableCellProps<T, TRow = T, ColName = string, ItemProps = DefaultRowProps> extends Optionalize<Omit<DataTableRowProps<T, unknown, ItemProps>, 'item'>, 'renderTreeIndent'> {
338
+ /** Settings of the column being rendered. If the table has a `getRowConfig` prop, the
339
+ * settings it returns are included in this object. */
340
+ column: DataTableColumn<T, TRow, ColName, ItemProps>;
341
+ /** The current row (overridden by `getRowConfig(...).item`, if applicable). */
342
+ item: TreeItem<T, TRow>;
343
+ /** Value of the cell (obtained from `this.column.getValue(this.item)` or
344
+ * `this.item[this.column.name]`.) */
345
+ value: React.ReactNode;
346
+ /** Whether the current row is selected. */
347
+ isSelected: boolean | null;
348
+ /** Number of columns spanned by cell, if provided by `DataTableColumn.getColSpan()`. */
349
+ colSpan?: number;
350
+ }
351
+ /** Sort order of the column, used in `DataTableCoreProps.columnsToSortBy` */
352
+ export declare enum SortDirection {
353
+ Ascending = 1,
354
+ Descending = -1
355
+ }
356
+ /** Tells `DataTableCoreProps.getRowConfig` what section of the row is being rendered. */
357
+ export declare enum RowType {
358
+ Header = -1,
359
+ Normal = 0,
360
+ Footer = 1
361
+ }
362
+ /** Main properties of a `DataTable` or `DataTableCore`. The only required properties are
363
+ * `list` (or `tree`) and `columns`, but if you are showing a tree, it is recommended to
364
+ * also provide `getKey` to identify rows to React. */
365
+ export type DataTableCoreProps<T, K = T, ColName = string, ItemProps = DefaultRowProps> = Omit<TreeListAuxProps<T, K, ItemProps>, 'RenderItem' | 'renderItem'> & TreeListMainProps<T> & {
366
+ /** Describes each of the columns in this data table. */
367
+ columns: DataTableColumn<T, T, ColName, ItemProps>[];
368
+ /** Component type used to render the heading cells (including `<th>` element).
369
+ * If not provided, headers are rendered with `DefaultDataTableHeading`.
370
+ * This property can be overridden for specific columns in `DataTableColumn`. */
371
+ RenderHeading?: React.ComponentType<DataTableHeadingProps<T, ColName, ItemProps>>;
372
+ /** Component type used to render the data cells (including `<td>` element).
373
+ * It is recommended to leave this undefined in order to use `DefaultDataTableCell`.
374
+ * This property can be overridden for specific columns in `DataTableColumn`.
375
+ * If you're using any tree columns, be sure to render the tree indent
376
+ * using `props.renderTreeIndent?.()` and include its output.
377
+ **/
378
+ RenderCell?: React.ComponentType<DataTableCellProps<T, T, ColName, ItemProps>>;
379
+ /** Component type used to render the header row. The result must include the outer
380
+ * `tr` or `div` but the `<thead>` is added by `DataTableCore` unless `noTHeadBody`.
381
+ * If not provided, the headings are rendered with `DefaultDataTableHeadingRow`. */
382
+ RenderHeadingRow?: React.ComponentType<DataTableHeadingRowProps<ColName, ItemProps>>;
383
+ /** Component type used to render an entire row. The result must include the outer
384
+ * `tr` or `div`. If not provided, rows are rendered with `DefaultDataTableRow`. */
385
+ RenderDataRow?: React.ComponentType<DataTableRowProps<T, K, ItemProps>>;
386
+ /** Optional props to send to the renderer for the heading row (if there is one).
387
+ * BTW: the inherited `itemProps` prop specifies props to use for each data row. */
388
+ headingRowProps?: ItemProps;
389
+ /** Optional props to add to `<thead>` element. Ignored if `noStructureWrap` is true. */
390
+ theadProps?: React.HTMLProps<HTMLTableSectionElement>;
391
+ /** Optional props to add to `<thead>` element. Ignored if `noStructureWrap` is true. */
392
+ tbodyProps?: React.HTMLProps<HTMLTableSectionElement>;
393
+ /** Optional props to add to `<tfoot>` element. Ignored if `noStructureWrap` is true. */
394
+ tfootProps?: React.HTMLProps<HTMLTableSectionElement>;
395
+ /** If this is true, then no header row is included in the output. This allows you
396
+ * either to make a table without a header, or to provide a header manually, e.g.
397
+ *
398
+ * <table>
399
+ * <tr>
400
+ * <th colSpan={2}>Custom</th>
401
+ * <th colSpan={2}>Headings</th>
402
+ * </tr>
403
+ * <DataTableCore noHeader noTHeadBody list={L} columns={C}/>
404
+ * </table>
405
+ *
406
+ * NOTE: Column widths are controller by the header row, and don't work when using
407
+ * `noHeader` mode.
408
+ */
409
+ noHeader?: boolean;
410
+ /** If this is true, the rows are not wrapped in `<thead>`, `<tbody>`, or `<tfoot>` elements. */
411
+ noStructureWrap?: boolean;
412
+ /** Optional list of columns to sort by, where the first item of the list is the primary
413
+ * sort key. This is treated as mutable by `DataTableCore`, so by providing an observable
414
+ * array here, you can find out (as well as change) what sort order the user has chosen.
415
+ * So that changes (including the user clicking headings) cause a re-render of the table,
416
+ * this should be an array the reactivity adapter can track: a `WatchableArray` (from
417
+ * this package) with the default adapter, or a MobX `observable.array` with the MobX
418
+ * adapter.
419
+ *
420
+ * Example in function-style component:
421
+ *
422
+ * const [columnsToSortBy] = useState(() => WatchableArray.from(
423
+ * [['myColumn', SortDirection.Descending]]) as WatchableArray<[string, SortDirection]>);
424
+ *
425
+ * return <DataTable list={...} columns={...} columnsToSortBy={columnsToSortBy}/>
426
+ **/
427
+ columnsToSortBy?: WatchableArrayLike<[ColName, SortDirection]>;
428
+ /** If provided, this is called on each row to find out how that row should be rendered.
429
+ * @param item Row being rendered.
430
+ * @param rowType Section of the table that is being rendered
431
+ * @returns The item to render (normally `item.item`) and the configuration of each column
432
+ * whose behavior you want to customize, or null/undefined to use the default
433
+ * configuration specified by `columns`. *The return type is incorrect.* The return type
434
+ * should actually be `ItemAndColumns<T,TRow,ColName,ItemProps> | nully` for some specific
435
+ * type `TRow`, but we could not find any way to express this in TypeScript.
436
+ **/
437
+ getRowConfig?(item: TreeItem<T>, rowType: RowType): ItemAndColumns<T, any, ColName, ItemProps> | nully;
438
+ /** Optional additional header rows that will be rendered underneath the normal header row. */
439
+ headerRows?: T[];
440
+ /** Optional footer rows that will be rendered underneath all other rows. */
441
+ footerRows?: T[];
442
+ /** These settings enable virtualization, which speeds up table rendering by not rendering
443
+ * off-screen items. */
444
+ virtualize?: VirtualizationSettings<T>;
445
+ };
446
+ /** Return type of `DataTableCoreProps.getRowConfig` */
447
+ export interface ItemAndColumns<T, TRow = T, ColName = string, ItemProps = DefaultRowProps> {
448
+ readonly columns: IMapSource<ColName, DataTableCellConfig<T, TRow, ColName, ItemProps>>;
449
+ /** If provided, `DefaultDataTableRow` renders this item instead of the original row
450
+ * value. If the original item has type `TRow`, you can omit this prop to render
451
+ * the original item. If the original item is not a `TRow`, this prop is required
452
+ * to avoid runtime type errors. */
453
+ item?: TRow;
454
+ }
455
+ /** A table of data with columns and rows rendered based on user-specified objects. This
456
+ * is the core functionality of a `<DataTable>`, without the actual `<table>` element.
457
+ * It can be used the same way as `<DataTable>` except that you wrap it in a `<table>`.
458
+ * See `<DataTable>` for a usage example. By not including `<table>`, this component
459
+ * gives you additional ways to format the table, e.g. you can use `<caption>`, `<tfoot>`
460
+ * or an extra header row. Also, it is possible to construct a non-table grid (e.g. CSS
461
+ * grid) using this component and custom renderers. */
462
+ export declare const DataTableCore: <T, K = T, ColName extends {
463
+ toString(): string;
464
+ } = string, ItemProps extends Styles = DefaultRowProps>(p: DataTableCoreProps<T, K, ColName, ItemProps>) => import("react").JSX.Element;
465
+ export interface DataTableContext<T, K = T, ColName = string, ItemProps = DefaultRowProps> {
466
+ rowConfigCache: Map<DataTableCellConfig<T, any, ColName, ItemProps>, DataTableColumn<T, any, ColName, ItemProps>>;
467
+ tableProps: DataTableCoreProps<T, K, ColName, ItemProps>;
468
+ }
469
+ /** This context can be used in a custom component used inside DataTable (e.g.
470
+ * a custom `RenderCell` component) to get the props that were passed to the
471
+ * data table. */
472
+ export declare const DataTableContext: import("react").Context<DataTableContext<any, any, any, any>>;
473
+ export declare const DataTableSectionContext: import("react").Context<RowType>;
474
+ /** Properties of a `DataTable`. The only required properties are `columns` and `list` (or
475
+ * `tree`), which are defined in the base interfaces `DataTableCoreProps` and `TreeListMainProps`.
476
+ * If you are using a tree view, it is recommended to also provide `getKey` (from the base
477
+ * interface `ListCoreProps`) to identify rows to React. */
478
+ export type DataTableProps<T, K = T, ColName = string, ItemProps = DefaultRowProps> = DataTableCoreProps<T, K, ColName, ItemProps> & Styles & {
479
+ /** Styles on the `<table>` element (the `style` and `className` on `DataTableProps`
480
+ * itelf are applied to an outer scrollable `<div>` that contains the `<table>`.) */
481
+ tableProps?: Styles & React.ComponentProps<'table'>;
482
+ /** Attributes to add to the outer `<div>` element that contains the `<table>` */
483
+ outerProps?: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
484
+ /** Theme for this table; overrides the ambient `TableConfig` theme. */
485
+ theme?: TableTheme | string | nully;
486
+ };
487
+ /** A table of data with columns and rows rendered based on user-specified objects.
488
+ * Also supports tree grids via the `getChildren` or `getParents` prop.
489
+ *
490
+ * By default, DataTable is rendered as a `<table>` element (with style `width: 100%`)
491
+ * wrapped in a `<div>` whose class includes `overflow: auto` so that a scroll bar
492
+ * appears automatically when appropriate. Other than that, the table size is not
493
+ * constrained and will automatically choose its own size. One simple way to limit
494
+ * min/max table size is to add `style={{ minHeight: N, maxHeight: M }}`. If the table
495
+ * is within a container that has its own min/max height, it might be better to set
496
+ * `display: flex; flex-direction: column` on that container and also set
497
+ * `style={{ flex: 1 }}` on the DataTable. This way, the table fills available space
498
+ * while also allowing space for other widgets.
499
+ *
500
+ * The table class includes `table-layout: fixed` and each `<th>` has an inline width
501
+ * controlled by the `DataTableColumn.width` value if you provided one. This is a
502
+ * minimum width; if the table is wider than the total widths of all columns, your
503
+ * browser will distribute excess available space among the columns automatically. If
504
+ * the table is less wide than the total widths of all columns, a horizontal scroll bar
505
+ * will appear. Drag handles appear by default so the user can change column widths (but
506
+ * the user's custom widths are forgotten when the component is unmounted.)
507
+ *
508
+ * Here's an example that shows a bunch of columns based on some simple `{ n: number }`
509
+ * objects, and shows certain items in tree form. In this example, `getParents`
510
+ * regenerates a parent object every time it is called, and the result is that the user
511
+ * can't expand parent rows unless a `getSelKey` prop is provided. This is because when
512
+ * the user expands a parent, the table is re-rendered and the originally-expanded
513
+ * parent object is no longer in the table! `getSelKey` fixes the problem causing the sets
514
+ * of selected and expanded items to be sets of numbers rather than objects. However,
515
+ * TypeScript can't infer that the type returned by `getSelKey` is correct, so type
516
+ * parameters are needed on `DataTable<{n: number}, number>`.
517
+ *
518
+ * <DataTable<{n: number}, number>
519
+ * list={[ { n:1 }, { n:3 }, { n:5 }, { n:36 }, { n:100 } ]}
520
+ * selMode="multi"
521
+ * columns={[
522
+ * {
523
+ * name: 'n',
524
+ * heading: 'Number',
525
+ * isTreeCol: true,
526
+ * },
527
+ * {
528
+ * name: 'Square', // Shown as the heading because `heading` is missing
529
+ * getValue(item: {n: number}) { return item.n * item.n; }
530
+ * },
531
+ * {
532
+ * name: 'Square root',
533
+ * getValue(item: {n: number}) { return Math.sqrt(item.n); }
534
+ * },
535
+ * {
536
+ * name: 'Odd?',
537
+ * getValue(item: {n: number}) { return (item.n & 1) !== 0; }
538
+ * },
539
+ * ]}
540
+ * getParents={item => {
541
+ * let root = Math.sqrt(item.n);
542
+ * return root === Math.round(root) ? [ { n: root } ] : undefined;
543
+ * }}
544
+ * getSelKey={item => item.n}
545
+ * />
546
+ */
547
+ export declare function DataTable<T, K = T, ColName extends {
548
+ toString(): string;
549
+ } = string, ItemProps extends Styles = DefaultRowProps>(p: DataTableProps<T, K, ColName, ItemProps>): import("react").JSX.Element;
550
+ export declare function DefaultDataTableHeadingRow(p: DataTableHeadingRowProps<any, any>): import("react").JSX.Element;
551
+ export declare let defaultClampWidth: {
552
+ current(w: number, c: DataTableColumn<any, any, any, any>): number;
553
+ };
554
+ export declare function DefaultDataTableHeading(p: DataTableHeadingProps<any, any, any>): import("react").JSX.Element;
555
+ export declare function ResizableColumn(p: {
556
+ children: React.ReactNode;
557
+ width: Holder<number>;
558
+ forDraggable?: Styles;
559
+ onStartDrag: () => void;
560
+ onStopDrag: () => void;
561
+ }): import("react").JSX.Element;
562
+ export declare const DefaultDataTableRow: (p: DataTableRowProps<any, any, any>) => import("react").JSX.Element;
563
+ export declare function DefaultDataTableCell(p: DataTableCellProps<any, any, any, any>): import("react").JSX.Element;
564
+ export declare function defaultRenderCell(node: TreeItem<any>, props: DataTableCellProps<any, any, any>): React.ReactNode;
565
+ /** The class names used to render tables (defined in datatable.css). These are stable, but
566
+ * exposed as an object so that code written against the earlier makeStyles-based API keeps
567
+ * working. Colors and spacing come from CSS variables; see `TableTheme`. */
568
+ export declare const dataTableClasses: Record<'outerDiv' | 'table' | 'rowPadded' | 'row' | 'sortIcon' | 'draggableColumn', string>;
569
+ export declare function useDataTableStyles(): Record<"table" | "row" | "outerDiv" | "rowPadded" | "sortIcon" | "draggableColumn", string>;
570
+ /** Returns a function that sorts with two or more comparison functions for the same type T.
571
+ * For example, if T is `{ x: number, y: string }` and you have two comparers `cmpX` and `cmpY`
572
+ * that projects and compares the two fields, then `combineComparers(cmpX, cmpY)` returns a
573
+ * function that compares by field X, and when those are equal (so `cmpX` returns 0), compares
574
+ * by field Y. */
575
+ export declare function combineComparers<T>(comparator: (a: T, b: T) => number, ...comparators: Array<(a: T, b: T) => number>): (a: T, b: T) => number;
576
+ export declare function compareByLocale<T>(a: nully | {
577
+ toString(): string;
578
+ }, b: nully | {
579
+ toString(): string;
580
+ }): number;
581
+ /** Compares any pair of numbers, strings, booleans, Dates, or (to the extent supported by the
582
+ * `>` and `<` operators) arrays. String comparisons are case-sensitive. */
583
+ export declare function heterogeneousCompare(a: any, b: any): number;