@x12i/data 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +549 -3
- package/dist/chunk-ASP4ABDG.js +1987 -0
- package/dist/chunk-ASP4ABDG.js.map +1 -0
- package/dist/index.d.ts +394 -0
- package/dist/index.js +219 -0
- package/dist/index.js.map +1 -0
- package/dist/messages-BF20Mq97.d.ts +508 -0
- package/dist/react.d.ts +328 -0
- package/dist/react.js +3078 -0
- package/dist/react.js.map +1 -0
- package/dist/styles.css +1169 -0
- package/package.json +87 -3
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, Ref, MouseEvent } from 'react';
|
|
3
|
+
import { DensityName } from '@x12i/tokens';
|
|
4
|
+
import { C as ColumnDef, r as DataGridMessages, i as ServerDataSource, x as GridViewState, D as DataGridMessageOverrides, S as SortModelItem, f as FilterModelItem, G as GroupModelItem, I as SelectionState, B as SavedViewStore, z as SavedView } from './messages-BF20Mq97.js';
|
|
5
|
+
import { DelimitedOptions, ColumnPinning, SavedViewSummary } from './index.js';
|
|
6
|
+
export { a as CellType, b as ColumnAlign, n as ColumnOption, o as ColumnPin, e as FilterOperator, M as StatusTone, Z as defaultMessages, _ as defineColumns, ag as resolveMessages } from './messages-BF20Mq97.js';
|
|
7
|
+
|
|
8
|
+
/** What a custom cell renderer receives. */
|
|
9
|
+
interface CellContext<Row> {
|
|
10
|
+
row: Row;
|
|
11
|
+
/** The id from `getRowId`. */
|
|
12
|
+
rowId: string;
|
|
13
|
+
/** Index into the `rows` array (client mode) or the server row index. */
|
|
14
|
+
rowIndex: number;
|
|
15
|
+
column: DataGridColumn<Row>;
|
|
16
|
+
/** The raw value, including a pending edit. */
|
|
17
|
+
value: unknown;
|
|
18
|
+
/** The formatted text: what export, copy and quick search see. */
|
|
19
|
+
text: string;
|
|
20
|
+
selected: boolean;
|
|
21
|
+
/** The grid's messages, already merged with the overrides. */
|
|
22
|
+
messages: DataGridMessages;
|
|
23
|
+
locale: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
/** What a custom header renderer receives. */
|
|
26
|
+
interface HeaderContext<Row> {
|
|
27
|
+
column: DataGridColumn<Row>;
|
|
28
|
+
sortDirection: "asc" | "desc" | null;
|
|
29
|
+
messages: DataGridMessages;
|
|
30
|
+
}
|
|
31
|
+
/** What a custom footer (totals) renderer receives. */
|
|
32
|
+
interface FooterContext<Row> {
|
|
33
|
+
column: DataGridColumn<Row>;
|
|
34
|
+
/** The column's aggregate over the filtered rows, or `undefined` when it has none. */
|
|
35
|
+
value: unknown;
|
|
36
|
+
/** `value` formatted for display. */
|
|
37
|
+
text: string;
|
|
38
|
+
messages: DataGridMessages;
|
|
39
|
+
}
|
|
40
|
+
/** One entry of a row-actions menu. */
|
|
41
|
+
interface RowAction<Row> {
|
|
42
|
+
id: string;
|
|
43
|
+
/** Pass a translated string. */
|
|
44
|
+
label: string;
|
|
45
|
+
onSelect: (row: Row) => void;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
tone?: "default" | "danger";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A grid column: everything in `ColumnDef` plus the renderers that only make
|
|
51
|
+
* sense in React. A `DataGridColumn` is a `ColumnDef`, so it works with the
|
|
52
|
+
* headless functions of `@x12i/data` too.
|
|
53
|
+
*/
|
|
54
|
+
interface DataGridColumn<Row> extends ColumnDef<Row> {
|
|
55
|
+
/** Replaces the default cell. Runs for every rendered cell, so keep it cheap. */
|
|
56
|
+
cell?: (context: CellContext<Row>) => ReactNode;
|
|
57
|
+
/** Replaces the header label. The sort, filter and menu buttons stay. */
|
|
58
|
+
headerCell?: (context: HeaderContext<Row>) => ReactNode;
|
|
59
|
+
/** Replaces the totals-row content of this column. */
|
|
60
|
+
footerCell?: (context: FooterContext<Row>) => ReactNode;
|
|
61
|
+
/** Menu entries for `actions` cells. Return an empty list to show no menu for a row. */
|
|
62
|
+
actions?: (row: Row) => RowAction<Row>[];
|
|
63
|
+
/** Target of `link` cells. Without it a string value that looks like a URL is linked. */
|
|
64
|
+
href?: (row: Row) => string | undefined;
|
|
65
|
+
}
|
|
66
|
+
interface PaginationState {
|
|
67
|
+
/** Zero-based page index. */
|
|
68
|
+
page: number;
|
|
69
|
+
pageSize: number;
|
|
70
|
+
}
|
|
71
|
+
/** What `onCellEdit` receives. Throw or reject to roll the edit back. */
|
|
72
|
+
interface CellEdit<Row> {
|
|
73
|
+
row: Row;
|
|
74
|
+
rowId: string;
|
|
75
|
+
column: DataGridColumn<Row>;
|
|
76
|
+
/** The parsed new value. */
|
|
77
|
+
value: unknown;
|
|
78
|
+
previousValue: unknown;
|
|
79
|
+
}
|
|
80
|
+
type ToolbarOptions = {
|
|
81
|
+
search?: boolean;
|
|
82
|
+
columns?: boolean;
|
|
83
|
+
export?: boolean;
|
|
84
|
+
copy?: boolean;
|
|
85
|
+
};
|
|
86
|
+
interface DataGridSlots {
|
|
87
|
+
/** Replaces the "no rows" content. */
|
|
88
|
+
empty?: ReactNode;
|
|
89
|
+
/** Replaces the first-load content. */
|
|
90
|
+
loading?: ReactNode;
|
|
91
|
+
/** Replaces the error content. Receives the error and a retry function. */
|
|
92
|
+
error?: (error: unknown, retry: () => void) => ReactNode;
|
|
93
|
+
}
|
|
94
|
+
interface DataGridHandle<Row> {
|
|
95
|
+
/** Scrolls so the row at a display index is visible. */
|
|
96
|
+
scrollToIndex(index: number): void;
|
|
97
|
+
/** Scrolls to a data row by id, when it is in the current view. */
|
|
98
|
+
scrollToRow(rowId: string): void;
|
|
99
|
+
/** Moves the cursor and focus. Row 0 is the header, column 0 the first column. */
|
|
100
|
+
focusCell(row: number, column: number): void;
|
|
101
|
+
/** CSV of the current view: filtered and sorted rows, visible columns. Server mode fetches every page. */
|
|
102
|
+
exportCsv(options?: DelimitedOptions): Promise<string>;
|
|
103
|
+
/** Copies the selected rows, or the focused cell, as tab-separated text. */
|
|
104
|
+
copySelection(): Promise<boolean>;
|
|
105
|
+
/** The selected rows that are loaded. */
|
|
106
|
+
getSelectedRows(): Row[];
|
|
107
|
+
/** Server mode: drops loaded rows and fetches again. */
|
|
108
|
+
reload(): void;
|
|
109
|
+
getViewState(): GridViewState;
|
|
110
|
+
}
|
|
111
|
+
interface DataGridProps<Row> {
|
|
112
|
+
columns: readonly DataGridColumn<Row>[];
|
|
113
|
+
/** Client mode: all the rows. The grid sorts, filters, groups and pages them. */
|
|
114
|
+
rows?: readonly Row[];
|
|
115
|
+
/** Server mode: the grid asks this for blocks of rows. Give `rows` or `dataSource`, not both. */
|
|
116
|
+
dataSource?: ServerDataSource<Row>;
|
|
117
|
+
/** A stable id per row. Used for selection, expansion, editing and React keys. */
|
|
118
|
+
getRowId: (row: Row, index: number) => string;
|
|
119
|
+
/** Names the grid for assistive technology. Give one of the two. */
|
|
120
|
+
"aria-label"?: string;
|
|
121
|
+
"aria-labelledby"?: string;
|
|
122
|
+
className?: string;
|
|
123
|
+
ref?: Ref<DataGridHandle<Row>>;
|
|
124
|
+
/** Block size of the grid. A number is in pixels. Without it the grid grows up to `maxHeight`. */
|
|
125
|
+
height?: number | string;
|
|
126
|
+
maxHeight?: number | string;
|
|
127
|
+
density?: DensityName;
|
|
128
|
+
dir?: "ltr" | "rtl";
|
|
129
|
+
/** Row height to assume until the `--kit-grid-row-height` token can be measured. */
|
|
130
|
+
estimateRowHeight?: number;
|
|
131
|
+
/** `auto` virtualizes rows above 100 and columns above 24. */
|
|
132
|
+
virtualize?: "auto" | boolean;
|
|
133
|
+
overscan?: number;
|
|
134
|
+
columnOverscan?: number;
|
|
135
|
+
locale?: string;
|
|
136
|
+
timeZone?: string;
|
|
137
|
+
messages?: DataGridMessageOverrides;
|
|
138
|
+
sort?: SortModelItem[];
|
|
139
|
+
defaultSort?: SortModelItem[];
|
|
140
|
+
onSortChange?: (sort: SortModelItem[]) => void;
|
|
141
|
+
/** Shift+click adds columns to the sort. Default `true`. */
|
|
142
|
+
multiSort?: boolean;
|
|
143
|
+
filter?: FilterModelItem[];
|
|
144
|
+
defaultFilter?: FilterModelItem[];
|
|
145
|
+
onFilterChange?: (filter: FilterModelItem[]) => void;
|
|
146
|
+
quickFilter?: string;
|
|
147
|
+
defaultQuickFilter?: string;
|
|
148
|
+
onQuickFilterChange?: (text: string) => void;
|
|
149
|
+
/** Server mode: wait this long (ms) after the last keystroke before asking the server. Default 250. */
|
|
150
|
+
quickFilterDelay?: number;
|
|
151
|
+
group?: GroupModelItem[];
|
|
152
|
+
defaultGroup?: GroupModelItem[];
|
|
153
|
+
onGroupChange?: (group: GroupModelItem[]) => void;
|
|
154
|
+
/** Expanded state per group id. Groups without an entry follow `groupsExpandedByDefault`. */
|
|
155
|
+
groupExpansion?: Record<string, boolean>;
|
|
156
|
+
defaultGroupExpansion?: Record<string, boolean>;
|
|
157
|
+
onGroupExpansionChange?: (expansion: Record<string, boolean>) => void;
|
|
158
|
+
groupsExpandedByDefault?: boolean;
|
|
159
|
+
columnVisibility?: Record<string, boolean>;
|
|
160
|
+
defaultColumnVisibility?: Record<string, boolean>;
|
|
161
|
+
onColumnVisibilityChange?: (visibility: Record<string, boolean>) => void;
|
|
162
|
+
columnOrder?: string[];
|
|
163
|
+
defaultColumnOrder?: string[];
|
|
164
|
+
onColumnOrderChange?: (order: string[]) => void;
|
|
165
|
+
columnSizing?: Record<string, number>;
|
|
166
|
+
defaultColumnSizing?: Record<string, number>;
|
|
167
|
+
onColumnSizingChange?: (sizing: Record<string, number>) => void;
|
|
168
|
+
columnPinning?: ColumnPinning;
|
|
169
|
+
defaultColumnPinning?: ColumnPinning;
|
|
170
|
+
onColumnPinningChange?: (pinning: ColumnPinning) => void;
|
|
171
|
+
selectionMode?: "none" | "single" | "multiple";
|
|
172
|
+
selection?: SelectionState;
|
|
173
|
+
defaultSelection?: SelectionState;
|
|
174
|
+
onSelectionChange?: (selection: SelectionState) => void;
|
|
175
|
+
/** Rows that cannot be selected get no checkbox. */
|
|
176
|
+
isRowSelectable?: (row: Row) => boolean;
|
|
177
|
+
/** Renders a detail panel under an expanded row and adds the expander column. */
|
|
178
|
+
renderDetail?: (row: Row) => ReactNode;
|
|
179
|
+
/** Height to assume for a detail panel until it is measured. */
|
|
180
|
+
detailHeight?: number;
|
|
181
|
+
isRowExpandable?: (row: Row) => boolean;
|
|
182
|
+
/** Ids of rows whose detail is open. */
|
|
183
|
+
expanded?: Record<string, boolean>;
|
|
184
|
+
defaultExpanded?: Record<string, boolean>;
|
|
185
|
+
onExpandedChange?: (expanded: Record<string, boolean>) => void;
|
|
186
|
+
/** Called when a data row is clicked, except for clicks on a control inside it (checkbox, button, link, input). */
|
|
187
|
+
onRowClick?: (row: Row, event: MouseEvent<HTMLElement>) => void;
|
|
188
|
+
/** Page the rows and show the pagination footer. Without it the grid scrolls. */
|
|
189
|
+
paginated?: boolean;
|
|
190
|
+
pagination?: PaginationState;
|
|
191
|
+
defaultPagination?: PaginationState;
|
|
192
|
+
onPaginationChange?: (pagination: PaginationState) => void;
|
|
193
|
+
pageSizeOptions?: number[];
|
|
194
|
+
/** Server mode without pagination: rows per request. Default 100. */
|
|
195
|
+
blockSize?: number;
|
|
196
|
+
/** Called when a cell edit is committed. Reject to roll the edit back. */
|
|
197
|
+
onCellEdit?: (edit: CellEdit<Row>) => void | Promise<void>;
|
|
198
|
+
toolbar?: boolean | ToolbarOptions;
|
|
199
|
+
toolbarStart?: ReactNode;
|
|
200
|
+
toolbarEnd?: ReactNode;
|
|
201
|
+
/** Show a totals row from the columns' `aggregate`. */
|
|
202
|
+
showTotals?: boolean;
|
|
203
|
+
/** Server mode: totals computed by the server, keyed by column id. */
|
|
204
|
+
totals?: Record<string, unknown>;
|
|
205
|
+
/** Client-mode loading flag, for rows that are still being fetched. */
|
|
206
|
+
loading?: boolean;
|
|
207
|
+
/** Client-mode error, shown with a retry button when `onRetry` is given. */
|
|
208
|
+
error?: unknown;
|
|
209
|
+
onRetry?: () => void;
|
|
210
|
+
slots?: DataGridSlots;
|
|
211
|
+
/** Called with the CSV text when the user presses Export, instead of a download. */
|
|
212
|
+
onExport?: (csv: string) => void;
|
|
213
|
+
exportFileName?: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* An accessible, virtualized data grid. See the package README for the full
|
|
218
|
+
* prop reference; this component owns the layout, the keyboard model and the
|
|
219
|
+
* state, and delegates the data work to the headless engine of `@x12i/data`.
|
|
220
|
+
*/
|
|
221
|
+
declare function DataGrid<Row>(props: DataGridProps<Row>): react.JSX.Element;
|
|
222
|
+
|
|
223
|
+
interface PaginationProps {
|
|
224
|
+
/** Zero-based page index. */
|
|
225
|
+
page: number;
|
|
226
|
+
pageSize: number;
|
|
227
|
+
/** Total rows, or `null` when the server has not said yet. */
|
|
228
|
+
total: number | null;
|
|
229
|
+
pageSizeOptions?: number[];
|
|
230
|
+
onPageChange: (page: number) => void;
|
|
231
|
+
/** Shows the page-size select when given. */
|
|
232
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
233
|
+
messages?: DataGridMessageOverrides;
|
|
234
|
+
locale?: string;
|
|
235
|
+
disabled?: boolean;
|
|
236
|
+
className?: string;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Page controls for a grid or any list: the visible range, a page-size select,
|
|
240
|
+
* and first, previous, next and last buttons. Pages are zero-based. Use it with
|
|
241
|
+
* `DataGrid` (which shows it for `paginated`) or on its own.
|
|
242
|
+
*/
|
|
243
|
+
declare function Pagination({ page, pageSize, total, pageSizeOptions, onPageChange, onPageSizeChange, messages: overrides, locale, disabled, className, }: PaginationProps): react.JSX.Element;
|
|
244
|
+
|
|
245
|
+
interface UseGridStateOptions<Row> {
|
|
246
|
+
columns: readonly ColumnDef<Row>[];
|
|
247
|
+
/** Starting values for any part of the view. Columns' `hidden` and `pinned` apply for the rest. */
|
|
248
|
+
initial?: Partial<GridViewState>;
|
|
249
|
+
/** Starting page size. Default 25. */
|
|
250
|
+
initialPageSize?: number;
|
|
251
|
+
}
|
|
252
|
+
/** The controlled props of `DataGrid` that `useGridState` fills in. Spread them: `<DataGrid {...grid.props} />`. */
|
|
253
|
+
interface GridStateProps {
|
|
254
|
+
sort: SortModelItem[];
|
|
255
|
+
onSortChange: (sort: SortModelItem[]) => void;
|
|
256
|
+
filter: FilterModelItem[];
|
|
257
|
+
onFilterChange: (filter: FilterModelItem[]) => void;
|
|
258
|
+
quickFilter: string;
|
|
259
|
+
onQuickFilterChange: (text: string) => void;
|
|
260
|
+
group: GroupModelItem[];
|
|
261
|
+
onGroupChange: (group: GroupModelItem[]) => void;
|
|
262
|
+
columnOrder: string[];
|
|
263
|
+
onColumnOrderChange: (order: string[]) => void;
|
|
264
|
+
columnVisibility: Record<string, boolean>;
|
|
265
|
+
onColumnVisibilityChange: (visibility: Record<string, boolean>) => void;
|
|
266
|
+
columnSizing: Record<string, number>;
|
|
267
|
+
onColumnSizingChange: (sizing: Record<string, number>) => void;
|
|
268
|
+
columnPinning: ColumnPinning;
|
|
269
|
+
onColumnPinningChange: (pinning: ColumnPinning) => void;
|
|
270
|
+
selection: SelectionState;
|
|
271
|
+
onSelectionChange: (selection: SelectionState) => void;
|
|
272
|
+
pagination: PaginationState;
|
|
273
|
+
onPaginationChange: (pagination: PaginationState) => void;
|
|
274
|
+
}
|
|
275
|
+
interface UseGridStateResult {
|
|
276
|
+
/** Spread onto `DataGrid` to control it from outside. */
|
|
277
|
+
props: GridStateProps;
|
|
278
|
+
/** The part of the state a saved view keeps. */
|
|
279
|
+
view: GridViewState;
|
|
280
|
+
/** Replaces the whole view, for example with the result of `applySavedView`. */
|
|
281
|
+
setView: (view: GridViewState) => void;
|
|
282
|
+
/** Back to what the column definitions say. Clears quick search and selection too. */
|
|
283
|
+
reset: () => void;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* All of the grid's state in one hook, so an app can read it, persist it, put
|
|
287
|
+
* it in the URL, or reset it. `DataGrid` works without it; use it when you need
|
|
288
|
+
* to see the sort, filters or selection outside the grid.
|
|
289
|
+
*/
|
|
290
|
+
declare function useGridState<Row>({ columns, initial, initialPageSize }: UseGridStateOptions<Row>): UseGridStateResult;
|
|
291
|
+
|
|
292
|
+
/** Anything that holds a grid view: the result of `useGridState` fits. */
|
|
293
|
+
interface GridViewController {
|
|
294
|
+
view: GridViewState;
|
|
295
|
+
setView: (view: GridViewState) => void;
|
|
296
|
+
}
|
|
297
|
+
interface UseSavedViewsOptions<Row> {
|
|
298
|
+
store: SavedViewStore;
|
|
299
|
+
columns: readonly ColumnDef<Row>[];
|
|
300
|
+
grid: GridViewController;
|
|
301
|
+
}
|
|
302
|
+
interface UseSavedViewsResult {
|
|
303
|
+
/** The views in the store, from the last refresh. */
|
|
304
|
+
views: SavedViewSummary[];
|
|
305
|
+
loading: boolean;
|
|
306
|
+
/** The error of the last failed store call, or `null`. */
|
|
307
|
+
error: unknown;
|
|
308
|
+
/** The id of the view last applied or saved, or `null`. */
|
|
309
|
+
activeId: string | null;
|
|
310
|
+
refresh: () => Promise<void>;
|
|
311
|
+
/** Saves the grid's current view under an id and refreshes the list. */
|
|
312
|
+
save: (id: string, name?: string) => Promise<void>;
|
|
313
|
+
/** Loads a view and applies it to the grid. Resolves to `false` when the id has no valid view. */
|
|
314
|
+
apply: (id: string) => Promise<boolean>;
|
|
315
|
+
remove: (id: string) => Promise<void>;
|
|
316
|
+
/** The grid's current view as a `SavedView`, without saving it. */
|
|
317
|
+
capture: (name?: string) => SavedView;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Saved views for a grid: list, save the current view, apply one, delete one.
|
|
321
|
+
* The store is any `SavedViewStore` (`createLocalStorageSavedViewStore`, your
|
|
322
|
+
* API, the Flowix adapter). A view saved against other columns still applies;
|
|
323
|
+
* ids the grid does not have are ignored.
|
|
324
|
+
*/
|
|
325
|
+
declare function useSavedViews<Row>({ store, columns, grid }: UseSavedViewsOptions<Row>): UseSavedViewsResult;
|
|
326
|
+
|
|
327
|
+
export { ColumnDef, DataGrid, DataGridMessageOverrides, DataGridMessages, FilterModelItem, GridViewState, GroupModelItem, Pagination, SavedView, SavedViewStore, SelectionState, ServerDataSource, SortModelItem, useGridState, useSavedViews };
|
|
328
|
+
export type { CellContext, CellEdit, DataGridColumn, DataGridHandle, DataGridProps, DataGridSlots, FooterContext, GridStateProps, GridViewController, HeaderContext, PaginationProps, PaginationState, RowAction, ToolbarOptions, UseGridStateOptions, UseGridStateResult, UseSavedViewsOptions, UseSavedViewsResult };
|