@optimum-intelligence/opti-ui 0.2.0 → 0.3.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.
Files changed (34) hide show
  1. package/README.md +86 -3
  2. package/dist/components/card/Card.d.ts +1 -1
  3. package/dist/components/card/Card.js.map +1 -1
  4. package/dist/components/data-table/DataTable.d.ts +58 -96
  5. package/dist/components/data-table/DataTable.js +452 -418
  6. package/dist/components/data-table/DataTable.js.map +1 -1
  7. package/dist/components/data-table/DataTableContent.d.ts +35 -0
  8. package/dist/components/data-table/DataTableContent.js +550 -0
  9. package/dist/components/data-table/DataTableContent.js.map +1 -0
  10. package/dist/components/data-table/DataTableFilters.d.ts +15 -0
  11. package/dist/components/data-table/DataTableFilters.js +284 -0
  12. package/dist/components/data-table/DataTableFilters.js.map +1 -0
  13. package/dist/components/data-table/DataTableRow.d.ts +33 -0
  14. package/dist/components/data-table/DataTableRow.js +552 -0
  15. package/dist/components/data-table/DataTableRow.js.map +1 -0
  16. package/dist/components/data-table/context.d.ts +5 -0
  17. package/dist/components/data-table/context.js +14 -0
  18. package/dist/components/data-table/context.js.map +1 -0
  19. package/dist/components/data-table/layout.d.ts +60 -0
  20. package/dist/components/data-table/layout.js +272 -0
  21. package/dist/components/data-table/layout.js.map +1 -0
  22. package/dist/components/data-table/types.d.ts +319 -0
  23. package/dist/components/data-table/useDataTable.d.ts +9 -0
  24. package/dist/components/data-table/useDataTable.js +666 -0
  25. package/dist/components/data-table/useDataTable.js.map +1 -0
  26. package/dist/components/stat-card/StatCard.d.ts +1 -1
  27. package/dist/components/stat-card/StatCard.js.map +1 -1
  28. package/dist/icons/index.d.ts +8 -0
  29. package/dist/icons/index.js +9 -1
  30. package/dist/icons/index.js.map +1 -1
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.js +4 -2
  33. package/dist/opti-ui.css +494 -167
  34. package/package.json +1 -1
@@ -1,444 +1,478 @@
1
1
  "use client";
2
2
  import { cx } from "../../utils/cx.js";
3
- import { Skeleton } from "../skeleton/Skeleton.js";
3
+ import { createPrimitive } from "../../utils/primitive.js";
4
4
  import { Spinner } from "../spinner/Spinner.js";
5
- import { Button } from "../button/Button.js";
6
- import { Checkbox } from "../choice/Choice.js";
7
5
  import { SearchInput } from "../search-input/SearchInput.js";
8
- import { matchesQuery } from "../../utils/search.js";
9
6
  import { Pagination } from "../pagination/Pagination.js";
10
- import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../table/Table.js";
11
- import { EmptyState } from "../empty-state/EmptyState.js";
7
+ import { DataTableContext, useDataTableContext } from "./context.js";
8
+ import { useDataTable } from "./useDataTable.js";
9
+ import { DataTableContent } from "./DataTableContent.js";
10
+ import { DataTableFilter, DataTableFilters } from "./DataTableFilters.js";
12
11
  import { c } from "react/compiler-runtime";
13
12
  import * as React from "react";
14
- import { jsx, jsxs } from "react/jsx-runtime";
13
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
14
  //#region src/components/data-table/DataTable.tsx
16
- var defaultLabels = {
17
- search: "Search…",
18
- clearSearch: "Clear search",
19
- selectAll: "Select all",
20
- selectRow: (label) => `Select ${label}`,
21
- count: (count) => `${count} ${count === 1 ? "record" : "records"}`,
22
- selected: (count) => `${count} selected`,
23
- emptyTitle: "No records yet",
24
- emptyDescription: "Records will appear here once added.",
25
- noMatchTitle: "No matching records",
26
- noMatchDescription: "Try a different search.",
27
- loading: "Loading",
28
- errorTitle: "Could not load records",
29
- retry: "Try again"
30
- };
31
- function useControlled(value, initial, onChange) {
32
- const $ = c(5);
33
- const [inner, setInner] = React.useState(initial);
34
- let t0;
35
- if ($[0] !== onChange) {
36
- t0 = (next) => {
37
- setInner(next);
38
- onChange?.(next);
15
+ /** Provides a table to the parts inside it. */
16
+ function DataTableRoot(t0) {
17
+ const $ = c(15);
18
+ let className;
19
+ let props;
20
+ let ref;
21
+ let table;
22
+ if ($[0] !== t0) {
23
+ ({table, className, ref, ...props} = t0);
24
+ $[0] = t0;
25
+ $[1] = className;
26
+ $[2] = props;
27
+ $[3] = ref;
28
+ $[4] = table;
29
+ } else {
30
+ className = $[1];
31
+ props = $[2];
32
+ ref = $[3];
33
+ table = $[4];
34
+ }
35
+ let t1;
36
+ if ($[5] !== className) {
37
+ t1 = cx("oui-data-table", className);
38
+ $[5] = className;
39
+ $[6] = t1;
40
+ } else t1 = $[6];
41
+ const t2 = table.loading ? table.rows.length ? "refresh" : "initial" : void 0;
42
+ let t3;
43
+ if ($[7] !== props || $[8] !== ref || $[9] !== t1 || $[10] !== t2) {
44
+ t3 = /* @__PURE__ */ jsx("div", {
45
+ ref,
46
+ className: t1,
47
+ "data-loading": t2,
48
+ ...props
49
+ });
50
+ $[7] = props;
51
+ $[8] = ref;
52
+ $[9] = t1;
53
+ $[10] = t2;
54
+ $[11] = t3;
55
+ } else t3 = $[11];
56
+ let t4;
57
+ if ($[12] !== t3 || $[13] !== table) {
58
+ t4 = /* @__PURE__ */ jsx(DataTableContext.Provider, {
59
+ value: table,
60
+ children: t3
61
+ });
62
+ $[12] = t3;
63
+ $[13] = table;
64
+ $[14] = t4;
65
+ } else t4 = $[14];
66
+ return t4;
67
+ }
68
+ var DataTableToolbar = createPrimitive("div", "oui-data-table__toolbar", "DataTableToolbar");
69
+ var DataTableActions = createPrimitive("div", "oui-data-table__actions", "DataTableActions");
70
+ /** Search box of the table. Typing applies after the table's `searchDebounce`; clearing applies at once. */
71
+ function DataTableSearch(t0) {
72
+ const $ = c(26);
73
+ let className;
74
+ let props;
75
+ if ($[0] !== t0) {
76
+ ({className, ...props} = t0);
77
+ $[0] = t0;
78
+ $[1] = className;
79
+ $[2] = props;
80
+ } else {
81
+ className = $[1];
82
+ props = $[2];
83
+ }
84
+ const table = useDataTableContext();
85
+ const { search, searchDebounce, labels: text } = table;
86
+ const [draft, setDraft] = React.useState(search);
87
+ const [seen, setSeen] = React.useState(search);
88
+ const [sent, setSent] = React.useState(search);
89
+ if (seen !== search) {
90
+ setSeen(search);
91
+ if (search !== sent) {
92
+ setSent(search);
93
+ setDraft(search);
94
+ }
95
+ }
96
+ let t1;
97
+ if ($[3] !== table) {
98
+ t1 = (next) => {
99
+ setSent(next);
100
+ table.setSearch(next);
39
101
  };
40
- $[0] = onChange;
41
- $[1] = t0;
42
- } else t0 = $[1];
43
- const set = t0;
44
- const t1 = value === void 0 ? inner : value;
102
+ $[3] = table;
103
+ $[4] = t1;
104
+ } else t1 = $[4];
105
+ const commit = t1;
45
106
  let t2;
46
- if ($[2] !== set || $[3] !== t1) {
47
- t2 = [t1, set];
48
- $[2] = set;
49
- $[3] = t1;
50
- $[4] = t2;
51
- } else t2 = $[4];
52
- return t2;
53
- }
54
- function valueOf(column, row) {
55
- return column.accessor ? column.accessor(row) : row[column.id];
56
- }
57
- function isEmpty(value) {
58
- return value === null || value === void 0 || value === "";
59
- }
60
- function compareValues(a, b) {
61
- if (typeof a === "number" && typeof b === "number") return a - b;
62
- if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();
63
- if (typeof a === "boolean" && typeof b === "boolean") return Number(a) - Number(b);
64
- return String(a).localeCompare(String(b), void 0, {
65
- numeric: true,
66
- sensitivity: "base"
67
- });
107
+ if ($[5] !== commit || $[6] !== draft || $[7] !== searchDebounce || $[8] !== sent) {
108
+ t2 = () => {
109
+ if (draft === sent) return;
110
+ const timer = window.setTimeout(() => commit(draft), searchDebounce);
111
+ return () => window.clearTimeout(timer);
112
+ };
113
+ $[5] = commit;
114
+ $[6] = draft;
115
+ $[7] = searchDebounce;
116
+ $[8] = sent;
117
+ $[9] = t2;
118
+ } else t2 = $[9];
119
+ let t3;
120
+ if ($[10] !== draft || $[11] !== searchDebounce || $[12] !== sent) {
121
+ t3 = [
122
+ draft,
123
+ sent,
124
+ searchDebounce
125
+ ];
126
+ $[10] = draft;
127
+ $[11] = searchDebounce;
128
+ $[12] = sent;
129
+ $[13] = t3;
130
+ } else t3 = $[13];
131
+ React.useEffect(t2, t3);
132
+ let t4;
133
+ if ($[14] !== commit || $[15] !== searchDebounce) {
134
+ t4 = (next_0) => {
135
+ setDraft(next_0);
136
+ if (!searchDebounce || !next_0) commit(next_0);
137
+ };
138
+ $[14] = commit;
139
+ $[15] = searchDebounce;
140
+ $[16] = t4;
141
+ } else t4 = $[16];
142
+ const change = t4;
143
+ let t5;
144
+ if ($[17] !== className) {
145
+ t5 = cx("oui-data-table__search", className);
146
+ $[17] = className;
147
+ $[18] = t5;
148
+ } else t5 = $[18];
149
+ let t6;
150
+ if ($[19] !== change || $[20] !== draft || $[21] !== props || $[22] !== t5 || $[23] !== text.clearSearch || $[24] !== text.search) {
151
+ t6 = /* @__PURE__ */ jsx(SearchInput, {
152
+ className: t5,
153
+ "aria-label": text.search,
154
+ placeholder: text.search,
155
+ clearLabel: text.clearSearch,
156
+ ...props,
157
+ value: draft,
158
+ onValueChange: change
159
+ });
160
+ $[19] = change;
161
+ $[20] = draft;
162
+ $[21] = props;
163
+ $[22] = t5;
164
+ $[23] = text.clearSearch;
165
+ $[24] = text.search;
166
+ $[25] = t6;
167
+ } else t6 = $[25];
168
+ return t6;
68
169
  }
69
- var INTERACTIVE = "a, button, input, select, textarea, label, [role=\"checkbox\"], [role=\"button\"]";
70
- /**
71
- * Table with built-in search, sorting, pagination and row selection. Every
72
- * piece of state works uncontrolled or controlled (`search` / `sort` / `page` /
73
- * `selection`), e.g. to persist it in the URL. With `mode="server"` the same
74
- * state drives an API instead: pass the fetched page as `data`, plus `total`
75
- * and `loading`. For custom layouts compose `Table` and `Pagination`.
76
- */
77
- function DataTable(t0) {
78
- const $ = c(66);
79
- const { data, columns, mode: t1, total, loading, error, onRetry, getRowId, searchable: t2, search: searchProp, defaultSearch: t3, onSearchChange, filter, sort: sortProp, defaultSort: t4, onSortChange, paginated: t5, page: pageProp, onPageChange, pageSize: pageSizeProp, defaultPageSize: t6, onPageSizeChange, pageSizeOptions, selection, onSelectionChange, onRowClick, rowLabel, toolbar, empty, labels, density, striped, stickyHeader, className, tableProps } = t0;
80
- const mode = t1 === void 0 ? "client" : t1;
81
- const searchable = t2 === void 0 ? true : t2;
82
- const defaultSearch = t3 === void 0 ? "" : t3;
83
- const defaultSort = t4 === void 0 ? null : t4;
84
- const paginated = t5 === void 0 ? true : t5;
85
- const defaultPageSize = t6 === void 0 ? 10 : t6;
86
- const text = {
87
- ...defaultLabels,
88
- ...labels
89
- };
90
- const [search, setSearch] = useControlled(searchProp, defaultSearch, onSearchChange);
91
- const [sort, setSort] = useControlled(sortProp, defaultSort, onSortChange);
92
- const [page, setPage] = useControlled(pageProp, 1, onPageChange);
93
- const [pageSize, setPageSize] = useControlled(pageSizeProp, defaultPageSize, onPageSizeChange);
94
- const server = mode === "server";
95
- const selectable = Boolean(onSelectionChange);
96
- let t7;
97
- if ($[0] !== selection) {
98
- t7 = new Set(selection);
99
- $[0] = selection;
100
- $[1] = t7;
101
- } else t7 = $[1];
102
- const selected = t7;
103
- const sortable = _temp;
104
- let t8;
105
- if ($[2] !== getRowId) {
106
- t8 = (row, index) => getRowId?.(row, index) ?? String(row.id ?? index);
107
- $[2] = getRowId;
108
- $[3] = t8;
109
- } else t8 = $[3];
110
- const idOf = t8;
111
- let t9;
112
- if ($[4] !== idOf) {
113
- t9 = (row_0, index_0) => ({
114
- row: row_0,
115
- id: idOf(row_0, index_0)
170
+ /** Row count, or the number of selected rows, with a spinner while loading. */
171
+ function DataTableSummary(t0) {
172
+ const $ = c(24);
173
+ let className;
174
+ let props;
175
+ if ($[0] !== t0) {
176
+ ({className, ...props} = t0);
177
+ $[0] = t0;
178
+ $[1] = className;
179
+ $[2] = props;
180
+ } else {
181
+ className = $[1];
182
+ props = $[2];
183
+ }
184
+ const table = useDataTableContext();
185
+ const text = table.labels;
186
+ let t1;
187
+ if ($[3] !== table.selection) {
188
+ t1 = new Set(table.selection);
189
+ $[3] = table.selection;
190
+ $[4] = t1;
191
+ } else t1 = $[4];
192
+ const selected = t1.size;
193
+ let t2;
194
+ if ($[5] !== table.loading || $[6] !== text) {
195
+ t2 = table.loading && /* @__PURE__ */ jsx(Spinner, {
196
+ className: "oui-data-table__spinner",
197
+ label: text.loading
116
198
  });
117
- $[4] = idOf;
118
- $[5] = t9;
119
- } else t9 = $[5];
120
- let rows = data.map(t9);
121
- if (!server && search.trim()) {
122
- const searchColumns = columns.filter(_temp2);
123
- rows = rows.filter((t10) => {
124
- const { row: row_1 } = t10;
125
- return filter ? filter(row_1, search) : matchesQuery(searchColumns.map((column_1) => valueOf(column_1, row_1) ?? "").join(" "), search);
199
+ $[5] = table.loading;
200
+ $[6] = text;
201
+ $[7] = t2;
202
+ } else t2 = $[7];
203
+ let t3;
204
+ if ($[8] !== className) {
205
+ t3 = cx("oui-data-table__summary", className);
206
+ $[8] = className;
207
+ $[9] = t3;
208
+ } else t3 = $[9];
209
+ let t4;
210
+ if ($[10] !== selected || $[11] !== table.count || $[12] !== table.pending || $[13] !== table.selectable || $[14] !== table.totalCount || $[15] !== text) {
211
+ t4 = table.selectable && selected ? text.selected(selected) : table.pending ? null : table.count !== table.totalCount ? text.filteredCount(table.count, table.totalCount) : text.count(table.count);
212
+ $[10] = selected;
213
+ $[11] = table.count;
214
+ $[12] = table.pending;
215
+ $[13] = table.selectable;
216
+ $[14] = table.totalCount;
217
+ $[15] = text;
218
+ $[16] = t4;
219
+ } else t4 = $[16];
220
+ let t5;
221
+ if ($[17] !== props || $[18] !== t3 || $[19] !== t4) {
222
+ t5 = /* @__PURE__ */ jsx("span", {
223
+ className: t3,
224
+ "aria-live": "polite",
225
+ ...props,
226
+ children: t4
126
227
  });
228
+ $[17] = props;
229
+ $[18] = t3;
230
+ $[19] = t4;
231
+ $[20] = t5;
232
+ } else t5 = $[20];
233
+ let t6;
234
+ if ($[21] !== t2 || $[22] !== t5) {
235
+ t6 = /* @__PURE__ */ jsxs(Fragment, { children: [t2, t5] });
236
+ $[21] = t2;
237
+ $[22] = t5;
238
+ $[23] = t6;
239
+ } else t6 = $[23];
240
+ return t6;
241
+ }
242
+ /** Page navigation of the table. Renders nothing when there are no rows, or the table is not paginated. */
243
+ function DataTablePagination(t0) {
244
+ const $ = c(14);
245
+ let className;
246
+ let props;
247
+ if ($[0] !== t0) {
248
+ ({className, ...props} = t0);
249
+ $[0] = t0;
250
+ $[1] = className;
251
+ $[2] = props;
252
+ } else {
253
+ className = $[1];
254
+ props = $[2];
127
255
  }
128
- let t10;
129
- if ($[6] !== columns || $[7] !== sort) {
130
- t10 = sort && columns.find((candidate) => candidate.id === sort.id);
131
- $[6] = columns;
132
- $[7] = sort;
133
- $[8] = t10;
134
- } else t10 = $[8];
135
- const sortColumn = t10;
136
- if (!server && sort && sortColumn) {
137
- const direction = sort.direction === "asc" ? 1 : -1;
138
- let t11;
139
- if ($[9] !== direction || $[10] !== sortColumn) {
140
- t11 = (a, b) => {
141
- if (sortColumn.compare) return direction * sortColumn.compare(a.row, b.row);
142
- const [av, bv] = [valueOf(sortColumn, a.row), valueOf(sortColumn, b.row)];
143
- if (isEmpty(av) || isEmpty(bv)) return Number(isEmpty(av)) - Number(isEmpty(bv));
144
- return direction * compareValues(av, bv);
145
- };
146
- $[9] = direction;
147
- $[10] = sortColumn;
148
- $[11] = t11;
149
- } else t11 = $[11];
150
- rows = [...rows].sort(t11);
256
+ const table = useDataTableContext();
257
+ if (!table.paginated || table.count <= 0 || table.error) return null;
258
+ let t1;
259
+ if ($[3] !== className) {
260
+ t1 = cx("oui-data-table__pagination", className);
261
+ $[3] = className;
262
+ $[4] = t1;
263
+ } else t1 = $[4];
264
+ let t2;
265
+ if ($[5] !== props || $[6] !== t1 || $[7] !== table.count || $[8] !== table.labels || $[9] !== table.page || $[10] !== table.pageSize || $[11] !== table.setPage || $[12] !== table.setPageSize) {
266
+ t2 = /* @__PURE__ */ jsx(Pagination, {
267
+ className: t1,
268
+ variant: "simple",
269
+ labels: table.labels,
270
+ ...props,
271
+ page: table.page,
272
+ pageSize: table.pageSize,
273
+ total: table.count,
274
+ onPageChange: table.setPage,
275
+ onPageSizeChange: table.setPageSize
276
+ });
277
+ $[5] = props;
278
+ $[6] = t1;
279
+ $[7] = table.count;
280
+ $[8] = table.labels;
281
+ $[9] = table.page;
282
+ $[10] = table.pageSize;
283
+ $[11] = table.setPage;
284
+ $[12] = table.setPageSize;
285
+ $[13] = t2;
286
+ } else t2 = $[13];
287
+ return t2;
288
+ }
289
+ function DataTableComponent(t0) {
290
+ const $ = c(51);
291
+ let className;
292
+ let controlSize;
293
+ let density;
294
+ let empty;
295
+ let layout;
296
+ let maxHeight;
297
+ let onEndReached;
298
+ let options;
299
+ let pageSizeOptions;
300
+ let stickyHeader;
301
+ let striped;
302
+ let tableProps;
303
+ let toolbar;
304
+ let virtualized;
305
+ if ($[0] !== t0) {
306
+ ({density, striped, stickyHeader, layout, maxHeight, virtualized, onEndReached, empty, tableProps, pageSizeOptions, controlSize, toolbar, className, ...options} = t0);
307
+ $[0] = t0;
308
+ $[1] = className;
309
+ $[2] = controlSize;
310
+ $[3] = density;
311
+ $[4] = empty;
312
+ $[5] = layout;
313
+ $[6] = maxHeight;
314
+ $[7] = onEndReached;
315
+ $[8] = options;
316
+ $[9] = pageSizeOptions;
317
+ $[10] = stickyHeader;
318
+ $[11] = striped;
319
+ $[12] = tableProps;
320
+ $[13] = toolbar;
321
+ $[14] = virtualized;
322
+ } else {
323
+ className = $[1];
324
+ controlSize = $[2];
325
+ density = $[3];
326
+ empty = $[4];
327
+ layout = $[5];
328
+ maxHeight = $[6];
329
+ onEndReached = $[7];
330
+ options = $[8];
331
+ pageSizeOptions = $[9];
332
+ stickyHeader = $[10];
333
+ striped = $[11];
334
+ tableProps = $[12];
335
+ toolbar = $[13];
336
+ virtualized = $[14];
151
337
  }
152
- const count = server ? total ?? rows.length : rows.length;
153
- const pageCount = Math.max(1, Math.ceil(count / pageSize));
154
- const currentPage = Math.min(Math.max(1, page), pageCount);
155
- const visible = paginated && !server ? rows.slice((currentPage - 1) * pageSize, currentPage * pageSize) : rows;
156
- let t11;
157
- if ($[12] !== data.length || $[13] !== search || $[14] !== server) {
158
- t11 = server ? Boolean(search.trim()) : data.length > 0;
159
- $[12] = data.length;
160
- $[13] = search;
161
- $[14] = server;
162
- $[15] = t11;
163
- } else t11 = $[15];
164
- const filtered = t11;
165
- const placeholders = loading && !rows.length && !error ? Math.min(paginated ? pageSize : 5, 10) : 0;
166
- let t12;
167
- if ($[16] !== selected) {
168
- t12 = (t13) => {
169
- const { id } = t13;
170
- return selected.has(id);
171
- };
172
- $[16] = selected;
173
- $[17] = t12;
174
- } else t12 = $[17];
175
- const selectedInView = rows.filter(t12).length;
176
- const allSelected = rows.length > 0 && selectedInView === rows.length;
177
- const toggleAll = (checked) => {
178
- const ids = new Set(rows.map(_temp3));
179
- const kept = (selection ?? []).filter((id_1) => !ids.has(id_1));
180
- onSelectionChange?.(checked ? [...kept, ...ids] : kept);
181
- };
182
- let t13;
183
- if ($[18] !== setSort || $[19] !== sort) {
184
- t13 = (id_2) => setSort(sort?.id !== id_2 ? {
185
- id: id_2,
186
- direction: "asc"
187
- } : sort.direction === "asc" ? {
188
- id: id_2,
189
- direction: "desc"
190
- } : null);
191
- $[18] = setSort;
192
- $[19] = sort;
193
- $[20] = t13;
194
- } else t13 = $[20];
195
- const toggleSort = t13;
196
- let t14;
197
- if ($[21] !== setPage || $[22] !== setSearch) {
198
- t14 = (next) => {
199
- setSearch(next);
200
- setPage(1);
338
+ const t1 = options.paginated ?? !virtualized;
339
+ let t2;
340
+ if ($[15] !== options || $[16] !== t1) {
341
+ t2 = {
342
+ ...options,
343
+ paginated: t1
201
344
  };
202
- $[21] = setPage;
203
- $[22] = setSearch;
204
- $[23] = t14;
205
- } else t14 = $[23];
206
- const changeSearch = t14;
207
- const extra = typeof toolbar === "function" ? toolbar({
208
- rows: rows.map(_temp4),
209
- selection: selection ?? []
210
- }) : toolbar;
211
- let t15;
212
- if ($[24] !== className) {
213
- t15 = cx("oui-data-table", className);
214
- $[24] = className;
215
- $[25] = t15;
216
- } else t15 = $[25];
217
- const T0 = Table;
218
- const t16 = loading || void 0;
219
- const t17 = selectable && /* @__PURE__ */ jsx(TableHead, {
220
- className: "oui-data-table__check",
221
- children: /* @__PURE__ */ jsx(Checkbox, {
222
- size: "sm",
223
- "aria-label": text.selectAll,
224
- checked: allSelected,
225
- indeterminate: selectedInView > 0 && !allSelected,
226
- disabled: !rows.length,
227
- onCheckedChange: (checked_0) => toggleAll(checked_0)
228
- })
229
- });
230
- let t18;
231
- if ($[26] !== columns || $[27] !== sort || $[28] !== toggleSort) {
232
- let t19;
233
- if ($[30] !== sort || $[31] !== toggleSort) {
234
- t19 = (column_2) => /* @__PURE__ */ jsx(TableHead, {
235
- align: column_2.align ?? (column_2.numeric ? "end" : "start"),
236
- style: column_2.width !== void 0 ? { width: column_2.width } : void 0,
237
- sort: sortable(column_2) ? sort?.id === column_2.id ? sort.direction : false : void 0,
238
- onSort: () => toggleSort(column_2.id),
239
- children: column_2.header
240
- }, column_2.id);
241
- $[30] = sort;
242
- $[31] = toggleSort;
243
- $[32] = t19;
244
- } else t19 = $[32];
245
- t18 = columns.map(t19);
246
- $[26] = columns;
247
- $[27] = sort;
248
- $[28] = toggleSort;
249
- $[29] = t18;
250
- } else t18 = $[29];
251
- let t19;
252
- if ($[33] !== t17 || $[34] !== t18) {
253
- t19 = /* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [t17, t18] }) });
254
- $[33] = t17;
255
- $[34] = t18;
256
- $[35] = t19;
257
- } else t19 = $[35];
258
- const T1 = TableBody;
259
- let t20;
260
- if ($[36] !== columns || $[37] !== placeholders || $[38] !== selectable) {
261
- let t21;
262
- if ($[40] !== columns || $[41] !== selectable) {
263
- t21 = (_, index_1) => /* @__PURE__ */ jsxs(TableRow, {
264
- "aria-hidden": true,
265
- children: [selectable && /* @__PURE__ */ jsx(TableCell, { className: "oui-data-table__check" }), columns.map((column_3, position) => /* @__PURE__ */ jsx(TableCell, {
266
- align: column_3.align,
267
- numeric: column_3.numeric,
268
- children: /* @__PURE__ */ jsx(Skeleton, {
269
- className: "oui-data-table__skeleton",
270
- width: `${45 + (index_1 * 3 + position * 5) % 7 * 8}%`
271
- })
272
- }, column_3.id))]
273
- }, index_1);
274
- $[40] = columns;
275
- $[41] = selectable;
276
- $[42] = t21;
277
- } else t21 = $[42];
278
- t20 = Array.from({ length: placeholders }, t21);
279
- $[36] = columns;
280
- $[37] = placeholders;
281
- $[38] = selectable;
282
- $[39] = t20;
283
- } else t20 = $[39];
284
- const t21 = !error && visible.map((t22) => {
285
- const { row: row_3, id: id_3 } = t22;
286
- const isSelected = selected.has(id_3);
287
- return /* @__PURE__ */ jsxs(TableRow, {
288
- "data-selected": isSelected || void 0,
289
- "data-clickable": onRowClick ? "" : void 0,
290
- tabIndex: onRowClick ? 0 : void 0,
291
- "aria-label": onRowClick ? rowLabel?.(row_3) : void 0,
292
- onClick: (event) => {
293
- if (!onRowClick || event.ctrlKey || event.metaKey) return;
294
- if (event.target.closest(INTERACTIVE)) return;
295
- onRowClick(row_3);
296
- },
297
- onKeyDown: (event_0) => {
298
- if (onRowClick && event_0.target === event_0.currentTarget && event_0.key === "Enter") onRowClick(row_3);
299
- },
300
- children: [selectable && /* @__PURE__ */ jsx(TableCell, {
301
- className: "oui-data-table__check",
302
- children: /* @__PURE__ */ jsx(Checkbox, {
303
- size: "sm",
304
- "aria-label": text.selectRow(rowLabel?.(row_3) ?? id_3),
305
- checked: isSelected,
306
- onCheckedChange: (checked_1) => onSelectionChange?.(checked_1 ? [...selection ?? [], id_3] : (selection ?? []).filter((item) => item !== id_3))
307
- })
308
- }), columns.map((column_4) => {
309
- const value = column_4.cell ? column_4.cell(row_3) : valueOf(column_4, row_3);
310
- return /* @__PURE__ */ jsx(TableCell, {
311
- align: column_4.align,
312
- numeric: column_4.numeric,
313
- children: column_4.cell || React.isValidElement(value) ? value : isEmpty(value) ? "—" : String(value)
314
- }, column_4.id);
315
- })]
316
- }, id_3);
317
- });
318
- let t23;
319
- if ($[43] !== T1 || $[44] !== t20 || $[45] !== t21) {
320
- t23 = /* @__PURE__ */ jsxs(T1, { children: [t20, t21] });
321
- $[43] = T1;
322
- $[44] = t20;
323
- $[45] = t21;
324
- $[46] = t23;
325
- } else t23 = $[46];
326
- let t24;
327
- if ($[47] !== T0 || $[48] !== density || $[49] !== stickyHeader || $[50] !== striped || $[51] !== t16 || $[52] !== t19 || $[53] !== t23 || $[54] !== tableProps) {
328
- t24 = /* @__PURE__ */ jsxs(T0, {
345
+ $[15] = options;
346
+ $[16] = t1;
347
+ $[17] = t2;
348
+ } else t2 = $[17];
349
+ const table = useDataTable(t2);
350
+ let t3;
351
+ if ($[18] !== table || $[19] !== toolbar) {
352
+ t3 = typeof toolbar === "function" ? toolbar({
353
+ rows: table.rows.map(_temp),
354
+ selection: table.selection,
355
+ table
356
+ }) : toolbar;
357
+ $[18] = table;
358
+ $[19] = toolbar;
359
+ $[20] = t3;
360
+ } else t3 = $[20];
361
+ const extra = t3;
362
+ let t4;
363
+ if ($[21] !== controlSize || $[22] !== table.searchable) {
364
+ t4 = table.searchable && /* @__PURE__ */ jsx(DataTableSearch, { size: controlSize });
365
+ $[21] = controlSize;
366
+ $[22] = table.searchable;
367
+ $[23] = t4;
368
+ } else t4 = $[23];
369
+ let t5;
370
+ if ($[24] !== controlSize) {
371
+ t5 = /* @__PURE__ */ jsx(DataTableFilters, { size: controlSize });
372
+ $[24] = controlSize;
373
+ $[25] = t5;
374
+ } else t5 = $[25];
375
+ let t6;
376
+ if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
377
+ t6 = /* @__PURE__ */ jsx(DataTableSummary, {});
378
+ $[26] = t6;
379
+ } else t6 = $[26];
380
+ let t7;
381
+ if ($[27] !== extra) {
382
+ t7 = /* @__PURE__ */ jsxs(DataTableActions, { children: [t6, extra] });
383
+ $[27] = extra;
384
+ $[28] = t7;
385
+ } else t7 = $[28];
386
+ let t8;
387
+ if ($[29] !== t4 || $[30] !== t5 || $[31] !== t7) {
388
+ t8 = /* @__PURE__ */ jsxs(DataTableToolbar, { children: [
389
+ t4,
390
+ t5,
391
+ t7
392
+ ] });
393
+ $[29] = t4;
394
+ $[30] = t5;
395
+ $[31] = t7;
396
+ $[32] = t8;
397
+ } else t8 = $[32];
398
+ let t9;
399
+ if ($[33] !== density || $[34] !== empty || $[35] !== layout || $[36] !== maxHeight || $[37] !== onEndReached || $[38] !== stickyHeader || $[39] !== striped || $[40] !== tableProps || $[41] !== virtualized) {
400
+ t9 = /* @__PURE__ */ jsx(DataTableContent, {
329
401
  density,
330
402
  striped,
331
403
  stickyHeader,
332
- "aria-busy": t16,
333
- ...tableProps,
334
- children: [t19, t23]
404
+ layout,
405
+ maxHeight,
406
+ virtualized,
407
+ onEndReached,
408
+ empty,
409
+ tableProps
335
410
  });
336
- $[47] = T0;
337
- $[48] = density;
338
- $[49] = stickyHeader;
339
- $[50] = striped;
340
- $[51] = t16;
341
- $[52] = t19;
342
- $[53] = t23;
343
- $[54] = tableProps;
344
- $[55] = t24;
345
- } else t24 = $[55];
346
- let t25;
347
- if ($[56] !== count || $[57] !== currentPage || $[58] !== error || $[59] !== labels || $[60] !== pageSize || $[61] !== pageSizeOptions || $[62] !== paginated || $[63] !== setPage || $[64] !== setPageSize) {
348
- t25 = paginated && count > 0 && !error && /* @__PURE__ */ jsx(Pagination, {
349
- className: "oui-data-table__pagination",
350
- variant: "simple",
351
- page: currentPage,
352
- pageSize,
353
- total: count,
354
- onPageChange: setPage,
355
- onPageSizeChange: (size) => {
356
- setPageSize(size);
357
- setPage(1);
358
- },
359
- pageSizeOptions,
360
- labels
411
+ $[33] = density;
412
+ $[34] = empty;
413
+ $[35] = layout;
414
+ $[36] = maxHeight;
415
+ $[37] = onEndReached;
416
+ $[38] = stickyHeader;
417
+ $[39] = striped;
418
+ $[40] = tableProps;
419
+ $[41] = virtualized;
420
+ $[42] = t9;
421
+ } else t9 = $[42];
422
+ let t10;
423
+ if ($[43] !== pageSizeOptions) {
424
+ t10 = /* @__PURE__ */ jsx(DataTablePagination, { pageSizeOptions });
425
+ $[43] = pageSizeOptions;
426
+ $[44] = t10;
427
+ } else t10 = $[44];
428
+ let t11;
429
+ if ($[45] !== className || $[46] !== t10 || $[47] !== t8 || $[48] !== t9 || $[49] !== table) {
430
+ t11 = /* @__PURE__ */ jsxs(DataTableRoot, {
431
+ table,
432
+ className,
433
+ children: [
434
+ t8,
435
+ t9,
436
+ t10
437
+ ]
361
438
  });
362
- $[56] = count;
363
- $[57] = currentPage;
364
- $[58] = error;
365
- $[59] = labels;
366
- $[60] = pageSize;
367
- $[61] = pageSizeOptions;
368
- $[62] = paginated;
369
- $[63] = setPage;
370
- $[64] = setPageSize;
371
- $[65] = t25;
372
- } else t25 = $[65];
373
- return /* @__PURE__ */ jsxs("div", {
374
- className: t15,
375
- "data-loading": loading ? rows.length ? "refresh" : "initial" : void 0,
376
- children: [
377
- /* @__PURE__ */ jsxs("div", {
378
- className: "oui-data-table__toolbar",
379
- children: [searchable && /* @__PURE__ */ jsx(SearchInput, {
380
- className: "oui-data-table__search",
381
- "aria-label": text.search,
382
- placeholder: text.search,
383
- clearLabel: text.clearSearch,
384
- value: search,
385
- onValueChange: changeSearch
386
- }), /* @__PURE__ */ jsxs("div", {
387
- className: "oui-data-table__actions",
388
- children: [
389
- loading && /* @__PURE__ */ jsx(Spinner, {
390
- className: "oui-data-table__spinner",
391
- label: text.loading
392
- }),
393
- /* @__PURE__ */ jsx("span", {
394
- className: "oui-data-table__summary",
395
- "aria-live": "polite",
396
- children: selectable && selected.size ? text.selected(selected.size) : placeholders ? null : text.count(count)
397
- }),
398
- extra
399
- ]
400
- })]
401
- }),
402
- t24,
403
- error ? /* @__PURE__ */ jsx(EmptyState, {
404
- role: "alert",
405
- title: text.errorTitle,
406
- description: error,
407
- actions: onRetry ? /* @__PURE__ */ jsx(Button, {
408
- size: "sm",
409
- variant: "secondary",
410
- onClick: onRetry,
411
- children: text.retry
412
- }) : void 0
413
- }) : !rows.length && !loading && (empty ?? /* @__PURE__ */ jsx(EmptyState, {
414
- title: filtered ? text.noMatchTitle : text.emptyTitle,
415
- description: filtered ? text.noMatchDescription : text.emptyDescription,
416
- actions: search ? /* @__PURE__ */ jsx(Button, {
417
- size: "sm",
418
- variant: "secondary",
419
- onClick: () => changeSearch(""),
420
- children: text.clearSearch
421
- }) : void 0
422
- })),
423
- t25
424
- ]
425
- });
439
+ $[45] = className;
440
+ $[46] = t10;
441
+ $[47] = t8;
442
+ $[48] = t9;
443
+ $[49] = table;
444
+ $[50] = t11;
445
+ } else t11 = $[50];
446
+ return t11;
426
447
  }
427
- function _temp4(t0) {
428
- const { row: row_2 } = t0;
429
- return row_2;
430
- }
431
- function _temp3(t0) {
432
- const { id: id_0 } = t0;
433
- return id_0;
434
- }
435
- function _temp2(column_0) {
436
- return column_0.searchable ?? (column_0.accessor !== void 0 || column_0.cell === void 0);
437
- }
438
- function _temp(column) {
439
- return column.sortable ?? (column.accessor !== void 0 || column.cell === void 0);
448
+ /**
449
+ * `<DataTable data={…} columns={…} />` renders a complete table with search,
450
+ * filters, sorting, pagination, row selection, row actions and inline editing;
451
+ * columns declare what they take part in. Every piece of state works
452
+ * uncontrolled or controlled (`search` / `filterValues` / `sort` / `page` /
453
+ * `selection`), and with `mode="server"` the same state drives an API.
454
+ *
455
+ * For another layout, create the table with `useDataTable` and compose the
456
+ * parts: `DataTable.Root`, `DataTable.Toolbar`, `DataTable.Search`,
457
+ * `DataTable.Filters`, `DataTable.Filter`, `DataTable.Actions`,
458
+ * `DataTable.Summary`, `DataTable.Content`, `DataTable.Pagination`.
459
+ */
460
+ function _temp(t0) {
461
+ const { row } = t0;
462
+ return row;
440
463
  }
464
+ var DataTable = Object.assign(DataTableComponent, {
465
+ Root: DataTableRoot,
466
+ Toolbar: DataTableToolbar,
467
+ Search: DataTableSearch,
468
+ Filters: DataTableFilters,
469
+ Filter: DataTableFilter,
470
+ Actions: DataTableActions,
471
+ Summary: DataTableSummary,
472
+ Content: DataTableContent,
473
+ Pagination: DataTablePagination
474
+ });
441
475
  //#endregion
442
- export { DataTable };
476
+ export { DataTable, useDataTableContext };
443
477
 
444
478
  //# sourceMappingURL=DataTable.js.map