@primer/react 38.41.0 → 38.42.0-rc.23d625bd0
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/CHANGELOG.md +8 -0
- package/dist/DataTable/DataTable.d.ts +27 -2
- package/dist/DataTable/DataTable.js +119 -72
- package/dist/DataTable/{Table-50e68700.css → Table-6ee6a868.css} +2 -2
- package/dist/DataTable/Table-6ee6a868.css.map +1 -0
- package/dist/DataTable/Table.d.ts +76 -1
- package/dist/DataTable/Table.js +214 -15
- package/dist/DataTable/Table.module.css.js +3 -1
- package/dist/DataTable/index.d.ts +5 -3
- package/dist/DataTable/index.js +3 -1
- package/dist/DataTable/row.d.ts +3 -2
- package/dist/DataTable/useTable.js +185 -61
- package/dist/Overlay/Overlay.d.ts +2 -0
- package/dist/Overlay/Overlay.js +4 -2
- package/dist/experimental/index.d.ts +3 -3
- package/dist/hooks/useOpenAndCloseFocus.d.ts +3 -1
- package/dist/hooks/useOpenAndCloseFocus.js +28 -16
- package/dist/hooks/useOverlay.d.ts +3 -1
- package/dist/hooks/useOverlay.js +24 -22
- package/generated/components.json +138 -2
- package/generated/hooks.json +12 -0
- package/package.json +2 -2
- package/dist/DataTable/Table-50e68700.css.map +0 -1
package/dist/DataTable/Table.js
CHANGED
|
@@ -2,6 +2,7 @@ import { c } from "../utils/react-compiler-runtime.js";
|
|
|
2
2
|
import Text_default from "../Text/Text.js";
|
|
3
3
|
import VisuallyHidden from "../_VisuallyHidden.js";
|
|
4
4
|
import { ScrollableRegion } from "../ScrollableRegion/ScrollableRegion.js";
|
|
5
|
+
import Checkbox from "../Checkbox/Checkbox.js";
|
|
5
6
|
import { SkeletonText } from "../SkeletonText/SkeletonText.js";
|
|
6
7
|
import { SortDirection } from "./sorting.js";
|
|
7
8
|
import { useTableLayout } from "./useTable.js";
|
|
@@ -142,28 +143,32 @@ function TableBody(t0) {
|
|
|
142
143
|
return t2;
|
|
143
144
|
}
|
|
144
145
|
function TableHeader(t0) {
|
|
145
|
-
const $ = c(
|
|
146
|
+
const $ = c(12);
|
|
146
147
|
let align;
|
|
147
148
|
let children;
|
|
149
|
+
let className;
|
|
148
150
|
let rest;
|
|
149
151
|
if ($[0] !== t0) {
|
|
150
|
-
({align, children, ...rest} = t0);
|
|
152
|
+
({align, className, children, ...rest} = t0);
|
|
151
153
|
$[0] = t0;
|
|
152
154
|
$[1] = align;
|
|
153
155
|
$[2] = children;
|
|
154
|
-
$[3] =
|
|
156
|
+
$[3] = className;
|
|
157
|
+
$[4] = rest;
|
|
155
158
|
} else {
|
|
156
159
|
align = $[1];
|
|
157
160
|
children = $[2];
|
|
158
|
-
|
|
161
|
+
className = $[3];
|
|
162
|
+
rest = $[4];
|
|
159
163
|
}
|
|
160
164
|
let t1;
|
|
161
|
-
if ($[
|
|
162
|
-
t1 = clsx("TableHeader", Table_module_css_default.TableHeader);
|
|
163
|
-
$[
|
|
164
|
-
|
|
165
|
+
if ($[5] !== className) {
|
|
166
|
+
t1 = clsx("TableHeader", className, Table_module_css_default.TableHeader);
|
|
167
|
+
$[5] = className;
|
|
168
|
+
$[6] = t1;
|
|
169
|
+
} else t1 = $[6];
|
|
165
170
|
let t2;
|
|
166
|
-
if ($[
|
|
171
|
+
if ($[7] !== align || $[8] !== children || $[9] !== rest || $[10] !== t1) {
|
|
167
172
|
t2 = /* @__PURE__ */ jsx("th", {
|
|
168
173
|
"data-component": "Table.Header",
|
|
169
174
|
...rest,
|
|
@@ -173,11 +178,12 @@ function TableHeader(t0) {
|
|
|
173
178
|
"data-cell-align": align,
|
|
174
179
|
children
|
|
175
180
|
});
|
|
176
|
-
$[
|
|
177
|
-
$[
|
|
178
|
-
$[
|
|
179
|
-
$[
|
|
180
|
-
|
|
181
|
+
$[7] = align;
|
|
182
|
+
$[8] = children;
|
|
183
|
+
$[9] = rest;
|
|
184
|
+
$[10] = t1;
|
|
185
|
+
$[11] = t2;
|
|
186
|
+
} else t2 = $[11];
|
|
181
187
|
return t2;
|
|
182
188
|
}
|
|
183
189
|
function TableSortHeader(t0) {
|
|
@@ -267,6 +273,90 @@ function TableSortHeader(t0) {
|
|
|
267
273
|
} else t6 = $[23];
|
|
268
274
|
return t6;
|
|
269
275
|
}
|
|
276
|
+
function TableSelectionHeader(t0) {
|
|
277
|
+
const $ = c(25);
|
|
278
|
+
let ariaDescription;
|
|
279
|
+
let checkboxRef;
|
|
280
|
+
let className;
|
|
281
|
+
let disabled;
|
|
282
|
+
let onToggleSelect;
|
|
283
|
+
let rest;
|
|
284
|
+
let selection;
|
|
285
|
+
let t1;
|
|
286
|
+
if ($[0] !== t0) {
|
|
287
|
+
({selection, checkboxRef, className, disabled, onToggleSelect, "aria-label": t1, "aria-description": ariaDescription, ...rest} = t0);
|
|
288
|
+
$[0] = t0;
|
|
289
|
+
$[1] = ariaDescription;
|
|
290
|
+
$[2] = checkboxRef;
|
|
291
|
+
$[3] = className;
|
|
292
|
+
$[4] = disabled;
|
|
293
|
+
$[5] = onToggleSelect;
|
|
294
|
+
$[6] = rest;
|
|
295
|
+
$[7] = selection;
|
|
296
|
+
$[8] = t1;
|
|
297
|
+
} else {
|
|
298
|
+
ariaDescription = $[1];
|
|
299
|
+
checkboxRef = $[2];
|
|
300
|
+
className = $[3];
|
|
301
|
+
disabled = $[4];
|
|
302
|
+
onToggleSelect = $[5];
|
|
303
|
+
rest = $[6];
|
|
304
|
+
selection = $[7];
|
|
305
|
+
t1 = $[8];
|
|
306
|
+
}
|
|
307
|
+
const ariaLabel = t1 === void 0 ? "Select rows" : t1;
|
|
308
|
+
let t2;
|
|
309
|
+
if ($[9] !== className) {
|
|
310
|
+
t2 = clsx(className, Table_module_css_default.TableSelectionHeader);
|
|
311
|
+
$[9] = className;
|
|
312
|
+
$[10] = t2;
|
|
313
|
+
} else t2 = $[10];
|
|
314
|
+
const t3 = selection === "all";
|
|
315
|
+
const t4 = selection === "some";
|
|
316
|
+
let t5;
|
|
317
|
+
if ($[11] !== onToggleSelect) {
|
|
318
|
+
t5 = () => {
|
|
319
|
+
var _onToggleSelect;
|
|
320
|
+
return (_onToggleSelect = onToggleSelect) === null || _onToggleSelect === void 0 ? void 0 : _onToggleSelect();
|
|
321
|
+
};
|
|
322
|
+
$[11] = onToggleSelect;
|
|
323
|
+
$[12] = t5;
|
|
324
|
+
} else t5 = $[12];
|
|
325
|
+
let t6;
|
|
326
|
+
if ($[13] !== ariaDescription || $[14] !== ariaLabel || $[15] !== checkboxRef || $[16] !== disabled || $[17] !== t3 || $[18] !== t4 || $[19] !== t5) {
|
|
327
|
+
t6 = /* @__PURE__ */ jsx(Checkbox, {
|
|
328
|
+
ref: checkboxRef,
|
|
329
|
+
checked: t3,
|
|
330
|
+
indeterminate: t4,
|
|
331
|
+
disabled,
|
|
332
|
+
onChange: t5,
|
|
333
|
+
"aria-label": ariaLabel,
|
|
334
|
+
"aria-description": ariaDescription
|
|
335
|
+
});
|
|
336
|
+
$[13] = ariaDescription;
|
|
337
|
+
$[14] = ariaLabel;
|
|
338
|
+
$[15] = checkboxRef;
|
|
339
|
+
$[16] = disabled;
|
|
340
|
+
$[17] = t3;
|
|
341
|
+
$[18] = t4;
|
|
342
|
+
$[19] = t5;
|
|
343
|
+
$[20] = t6;
|
|
344
|
+
} else t6 = $[20];
|
|
345
|
+
let t7;
|
|
346
|
+
if ($[21] !== rest || $[22] !== t2 || $[23] !== t6) {
|
|
347
|
+
t7 = /* @__PURE__ */ jsx(TableHeader, {
|
|
348
|
+
...rest,
|
|
349
|
+
className: t2,
|
|
350
|
+
"data-component": "Table.SelectionHeader",
|
|
351
|
+
children: t6
|
|
352
|
+
});
|
|
353
|
+
$[21] = rest;
|
|
354
|
+
$[22] = t2;
|
|
355
|
+
$[23] = t6;
|
|
356
|
+
$[24] = t7;
|
|
357
|
+
} else t7 = $[24];
|
|
358
|
+
return t7;
|
|
359
|
+
}
|
|
270
360
|
function TableRow(t0) {
|
|
271
361
|
const $ = c(7);
|
|
272
362
|
let children;
|
|
@@ -366,6 +456,115 @@ function TableCell(t0) {
|
|
|
366
456
|
} else t3 = $[20];
|
|
367
457
|
return t3;
|
|
368
458
|
}
|
|
459
|
+
function TableRowSelection(t0) {
|
|
460
|
+
const $ = c(33);
|
|
461
|
+
let ariaLabelledBy;
|
|
462
|
+
let checkboxRef;
|
|
463
|
+
let className;
|
|
464
|
+
let disabled;
|
|
465
|
+
let headers;
|
|
466
|
+
let onToggleSelect;
|
|
467
|
+
let rest;
|
|
468
|
+
let selected;
|
|
469
|
+
let t1;
|
|
470
|
+
if ($[0] !== t0) {
|
|
471
|
+
({selected, checkboxRef, className, disabled, headers, onToggleSelect, "aria-label": t1, "aria-labelledby": ariaLabelledBy, ...rest} = t0);
|
|
472
|
+
$[0] = t0;
|
|
473
|
+
$[1] = ariaLabelledBy;
|
|
474
|
+
$[2] = checkboxRef;
|
|
475
|
+
$[3] = className;
|
|
476
|
+
$[4] = disabled;
|
|
477
|
+
$[5] = headers;
|
|
478
|
+
$[6] = onToggleSelect;
|
|
479
|
+
$[7] = rest;
|
|
480
|
+
$[8] = selected;
|
|
481
|
+
$[9] = t1;
|
|
482
|
+
} else {
|
|
483
|
+
ariaLabelledBy = $[1];
|
|
484
|
+
checkboxRef = $[2];
|
|
485
|
+
className = $[3];
|
|
486
|
+
disabled = $[4];
|
|
487
|
+
headers = $[5];
|
|
488
|
+
onToggleSelect = $[6];
|
|
489
|
+
rest = $[7];
|
|
490
|
+
selected = $[8];
|
|
491
|
+
t1 = $[9];
|
|
492
|
+
}
|
|
493
|
+
const ariaLabel = t1 === void 0 ? "Select row" : t1;
|
|
494
|
+
const actionLabelId = React.useId();
|
|
495
|
+
const group = useContext(TableGroupContext);
|
|
496
|
+
let t2;
|
|
497
|
+
if ($[10] !== (group === null || group === void 0 ? void 0 : group.headerId) || $[11] !== headers) {
|
|
498
|
+
t2 = [group === null || group === void 0 ? void 0 : group.headerId, headers].filter(Boolean).join(" ") || void 0;
|
|
499
|
+
$[10] = group === null || group === void 0 ? void 0 : group.headerId;
|
|
500
|
+
$[11] = headers;
|
|
501
|
+
$[12] = t2;
|
|
502
|
+
} else t2 = $[12];
|
|
503
|
+
const resolvedHeaders = t2;
|
|
504
|
+
let t3;
|
|
505
|
+
if ($[13] !== className) {
|
|
506
|
+
t3 = clsx(className, Table_module_css_default.TableCell, Table_module_css_default.TableRowSelection);
|
|
507
|
+
$[13] = className;
|
|
508
|
+
$[14] = t3;
|
|
509
|
+
} else t3 = $[14];
|
|
510
|
+
let t4;
|
|
511
|
+
if ($[15] !== actionLabelId || $[16] !== ariaLabelledBy) {
|
|
512
|
+
t4 = ariaLabelledBy ? /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
513
|
+
id: actionLabelId,
|
|
514
|
+
children: "Select"
|
|
515
|
+
}) : null;
|
|
516
|
+
$[15] = actionLabelId;
|
|
517
|
+
$[16] = ariaLabelledBy;
|
|
518
|
+
$[17] = t4;
|
|
519
|
+
} else t4 = $[17];
|
|
520
|
+
let t5;
|
|
521
|
+
if ($[18] !== onToggleSelect) {
|
|
522
|
+
t5 = () => {
|
|
523
|
+
var _onToggleSelect2;
|
|
524
|
+
return (_onToggleSelect2 = onToggleSelect) === null || _onToggleSelect2 === void 0 ? void 0 : _onToggleSelect2();
|
|
525
|
+
};
|
|
526
|
+
$[18] = onToggleSelect;
|
|
527
|
+
$[19] = t5;
|
|
528
|
+
} else t5 = $[19];
|
|
529
|
+
const t6 = ariaLabelledBy ? void 0 : ariaLabel;
|
|
530
|
+
const t7 = ariaLabelledBy ? `${actionLabelId} ${ariaLabelledBy}` : void 0;
|
|
531
|
+
let t8;
|
|
532
|
+
if ($[20] !== checkboxRef || $[21] !== disabled || $[22] !== selected || $[23] !== t5 || $[24] !== t6 || $[25] !== t7) {
|
|
533
|
+
t8 = /* @__PURE__ */ jsx(Checkbox, {
|
|
534
|
+
ref: checkboxRef,
|
|
535
|
+
checked: selected,
|
|
536
|
+
disabled,
|
|
537
|
+
onChange: t5,
|
|
538
|
+
"aria-label": t6,
|
|
539
|
+
"aria-labelledby": t7
|
|
540
|
+
});
|
|
541
|
+
$[20] = checkboxRef;
|
|
542
|
+
$[21] = disabled;
|
|
543
|
+
$[22] = selected;
|
|
544
|
+
$[23] = t5;
|
|
545
|
+
$[24] = t6;
|
|
546
|
+
$[25] = t7;
|
|
547
|
+
$[26] = t8;
|
|
548
|
+
} else t8 = $[26];
|
|
549
|
+
let t9;
|
|
550
|
+
if ($[27] !== resolvedHeaders || $[28] !== rest || $[29] !== t3 || $[30] !== t4 || $[31] !== t8) {
|
|
551
|
+
t9 = /* @__PURE__ */ jsxs("td", {
|
|
552
|
+
...rest,
|
|
553
|
+
className: t3,
|
|
554
|
+
role: "cell",
|
|
555
|
+
headers: resolvedHeaders,
|
|
556
|
+
"data-component": "Table.RowSelection",
|
|
557
|
+
children: [t4, t8]
|
|
558
|
+
});
|
|
559
|
+
$[27] = resolvedHeaders;
|
|
560
|
+
$[28] = rest;
|
|
561
|
+
$[29] = t3;
|
|
562
|
+
$[30] = t4;
|
|
563
|
+
$[31] = t8;
|
|
564
|
+
$[32] = t9;
|
|
565
|
+
} else t9 = $[32];
|
|
566
|
+
return t9;
|
|
567
|
+
}
|
|
369
568
|
function TableCellPlaceholder(t0) {
|
|
370
569
|
const $ = c(2);
|
|
371
570
|
const { children } = t0;
|
|
@@ -585,4 +784,4 @@ function _temp(column, i) {
|
|
|
585
784
|
return /* @__PURE__ */ jsx(TableHeader, { children: typeof column.header === "string" ? column.header : column.header() }, i);
|
|
586
785
|
}
|
|
587
786
|
//#endregion
|
|
588
|
-
export { Table, TableActions, TableBody, TableCell, TableCellPlaceholder, TableContainer, TableDivider, TableHead, TableHeader, TableRow, TableSkeleton, TableSortHeader, TableSubtitle, TableTitle };
|
|
787
|
+
export { Table, TableActions, TableBody, TableCell, TableCellPlaceholder, TableContainer, TableDivider, TableHead, TableHeader, TableRow, TableRowSelection, TableSelectionHeader, TableSkeleton, TableSortHeader, TableSubtitle, TableTitle };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./Table-
|
|
1
|
+
import "./Table-6ee6a868.css";
|
|
2
2
|
//#region src/DataTable/Table.module.css.js
|
|
3
3
|
var Table_module_css_default = {
|
|
4
4
|
"TableContainer": "prc-DataTable-TableContainer-hn0p3",
|
|
@@ -16,6 +16,8 @@ var Table_module_css_default = {
|
|
|
16
16
|
"TableBody": "prc-DataTable-TableBody-QKQy2",
|
|
17
17
|
"TableCellSkeletonItem": "prc-DataTable-TableCellSkeletonItem-bGhwZ",
|
|
18
18
|
"TableCellSkeleton": "prc-DataTable-TableCellSkeleton-DMdM5",
|
|
19
|
+
"TableRowSelection": "prc-DataTable-TableRowSelection-HwyDU",
|
|
20
|
+
"TableSelectionHeader": "prc-DataTable-TableSelectionHeader-Op0cK",
|
|
19
21
|
"TableSortIcon": "prc-DataTable-TableSortIcon-wHvJw",
|
|
20
22
|
"TableSortIcon--ascending": "prc-DataTable-TableSortIcon--ascending-Lpx6z",
|
|
21
23
|
"TableSortIcon--descending": "prc-DataTable-TableSortIcon--descending-hHJGo",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SlotMarker } from "../utils/types/Slots.js";
|
|
2
2
|
import { ObjectPaths } from "./utils.js";
|
|
3
|
-
import { DataTableData, DataTableRowGroup, UniqueRow } from "./row.js";
|
|
3
|
+
import { DataTableData, DataTableRowGroup, DataTableRowId, UniqueRow } from "./row.js";
|
|
4
4
|
import { CellAlignment, Column, ColumnWidth, createColumnHelper } from "./column.js";
|
|
5
5
|
import { DataTable, DataTableProps } from "./DataTable.js";
|
|
6
6
|
import { ErrorDialog } from "./ErrorDialog.js";
|
|
7
|
-
import { Table as Table$1, TableActions, TableActionsProps, TableBody, TableBodyProps, TableCell, TableCellPlaceholder, TableCellProps, TableContainer, TableContainerProps, TableDivider, TableHead, TableHeadProps, TableHeader, TableHeaderProps, TableProps, TableRow, TableRowProps, TableSkeleton, TableSkeletonProps, TableSubtitle, TableSubtitleProps, TableTitle, TableTitleProps } from "./Table.js";
|
|
7
|
+
import { Table as Table$1, TableActions, TableActionsProps, TableBody, TableBodyProps, TableCell, TableCellPlaceholder, TableCellProps, TableContainer, TableContainerProps, TableDivider, TableHead, TableHeadProps, TableHeader, TableHeaderProps, TableProps, TableRow, TableRowProps, TableRowSelection, TableRowSelectionProps, TableSelectionHeader, TableSelectionHeaderProps, TableSkeleton, TableSkeletonProps, TableSubtitle, TableSubtitleProps, TableTitle, TableTitleProps } from "./Table.js";
|
|
8
8
|
import { TableGroup, TableGroupProps } from "./TableGroup.js";
|
|
9
9
|
import { Pagination } from "./Pagination.js";
|
|
10
10
|
|
|
@@ -20,11 +20,13 @@ declare const Table: typeof Table$1 & SlotMarker & {
|
|
|
20
20
|
Body: typeof TableBody;
|
|
21
21
|
Group: typeof TableGroup;
|
|
22
22
|
Header: typeof TableHeader;
|
|
23
|
+
SelectionHeader: typeof TableSelectionHeader;
|
|
23
24
|
Row: typeof TableRow;
|
|
25
|
+
RowSelection: typeof TableRowSelection;
|
|
24
26
|
Cell: typeof TableCell;
|
|
25
27
|
CellPlaceholder: typeof TableCellPlaceholder;
|
|
26
28
|
Pagination: typeof Pagination;
|
|
27
29
|
ErrorDialog: typeof ErrorDialog;
|
|
28
30
|
};
|
|
29
31
|
//#endregion
|
|
30
|
-
export { type CellAlignment, type Column, type ColumnWidth, DataTable, type DataTableData, type DataTableProps, type DataTableRowGroup, type ObjectPaths, Table, type TableActionsProps, type TableBodyProps, type TableCellProps, type TableContainerProps, type TableGroupProps, type TableHeadProps, type TableHeaderProps, type TableProps, type TableRowProps, type TableSubtitleProps, type TableTitleProps, type UniqueRow, createColumnHelper };
|
|
32
|
+
export { type CellAlignment, type Column, type ColumnWidth, DataTable, type DataTableData, type DataTableProps, type DataTableRowGroup, type DataTableRowId, type ObjectPaths, Table, type TableActionsProps, type TableBodyProps, type TableCellProps, type TableContainerProps, type TableGroupProps, type TableHeadProps, type TableHeaderProps, type TableProps, type TableRowProps, type TableRowSelectionProps, type TableSelectionHeaderProps, type TableSubtitleProps, type TableTitleProps, type UniqueRow, createColumnHelper };
|
package/dist/DataTable/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Table as Table$1, TableActions, TableBody, TableCell, TableCellPlaceholder, TableContainer, TableDivider, TableHead, TableHeader, TableRow, TableSkeleton, TableSubtitle, TableTitle } from "./Table.js";
|
|
1
|
+
import { Table as Table$1, TableActions, TableBody, TableCell, TableCellPlaceholder, TableContainer, TableDivider, TableHead, TableHeader, TableRow, TableRowSelection, TableSelectionHeader, TableSkeleton, TableSubtitle, TableTitle } from "./Table.js";
|
|
2
2
|
import { TableGroup } from "./TableGroup.js";
|
|
3
3
|
import { DataTable } from "./DataTable.js";
|
|
4
4
|
import { ErrorDialog } from "./ErrorDialog.js";
|
|
@@ -16,7 +16,9 @@ const Table = Object.assign(Table$1, {
|
|
|
16
16
|
Body: TableBody,
|
|
17
17
|
Group: TableGroup,
|
|
18
18
|
Header: TableHeader,
|
|
19
|
+
SelectionHeader: TableSelectionHeader,
|
|
19
20
|
Row: TableRow,
|
|
21
|
+
RowSelection: TableRowSelection,
|
|
20
22
|
Cell: TableCell,
|
|
21
23
|
CellPlaceholder: TableCellPlaceholder,
|
|
22
24
|
Pagination,
|
package/dist/DataTable/row.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/DataTable/row.d.ts
|
|
2
|
+
type DataTableRowId = string | number;
|
|
2
3
|
interface UniqueRow {
|
|
3
|
-
id:
|
|
4
|
+
id: DataTableRowId;
|
|
4
5
|
}
|
|
5
6
|
interface DataTableRowGroup<Data extends UniqueRow> {
|
|
6
7
|
/**
|
|
@@ -26,4 +27,4 @@ interface DataTableRowGroup<Data extends UniqueRow> {
|
|
|
26
27
|
*/
|
|
27
28
|
type DataTableData<Data extends UniqueRow> = Array<Data | DataTableRowGroup<Data>>;
|
|
28
29
|
//#endregion
|
|
29
|
-
export { DataTableData, DataTableRowGroup, UniqueRow };
|
|
30
|
+
export { DataTableData, DataTableRowGroup, DataTableRowId, UniqueRow };
|
|
@@ -1,24 +1,54 @@
|
|
|
1
1
|
import { c } from "../utils/react-compiler-runtime.js";
|
|
2
|
+
import { useControllableState } from "../hooks/useControllableState.js";
|
|
2
3
|
import { DEFAULT_SORT_DIRECTION, SortDirection, strategies, transition } from "./sorting.js";
|
|
3
4
|
import { useId, useState } from "react";
|
|
4
5
|
//#region src/DataTable/useTable.ts
|
|
5
6
|
function useTable(t0) {
|
|
6
|
-
const $ = c(
|
|
7
|
-
const { columns, data, initialSortColumn, initialSortDirection, externalSorting, getRowId } = t0;
|
|
7
|
+
const $ = c(61);
|
|
8
|
+
const { columns, data, initialSortColumn, initialSortDirection, externalSorting, getRowId, rowSelection: t1, selectedRows: controlledSelectedRows, defaultSelectedRows, onSelectionChange, isRowSelectable } = t0;
|
|
9
|
+
const rowSelection = t1 === void 0 ? false : t1;
|
|
8
10
|
const tableId = useId();
|
|
9
11
|
const [rowOrder, setRowOrder] = useState(data);
|
|
10
12
|
const [prevData, setPrevData] = useState(data);
|
|
11
13
|
const [prevColumns, setPrevColumns] = useState(columns);
|
|
12
|
-
let
|
|
14
|
+
let t2;
|
|
13
15
|
if ($[0] !== columns || $[1] !== initialSortColumn || $[2] !== initialSortDirection) {
|
|
14
|
-
|
|
16
|
+
t2 = () => getInitialSortState(columns, initialSortColumn, initialSortDirection);
|
|
15
17
|
$[0] = columns;
|
|
16
18
|
$[1] = initialSortColumn;
|
|
17
19
|
$[2] = initialSortDirection;
|
|
18
|
-
$[3] =
|
|
19
|
-
} else
|
|
20
|
-
const [sortByColumn, setSortByColumn] = useState(
|
|
21
|
-
|
|
20
|
+
$[3] = t2;
|
|
21
|
+
} else t2 = $[3];
|
|
22
|
+
const [sortByColumn, setSortByColumn] = useState(t2);
|
|
23
|
+
let t3;
|
|
24
|
+
if ($[4] !== defaultSelectedRows) {
|
|
25
|
+
t3 = () => defaultSelectedRows !== null && defaultSelectedRows !== void 0 ? defaultSelectedRows : /* @__PURE__ */ new Set();
|
|
26
|
+
$[4] = defaultSelectedRows;
|
|
27
|
+
$[5] = t3;
|
|
28
|
+
} else t3 = $[5];
|
|
29
|
+
let t4;
|
|
30
|
+
if ($[6] !== onSelectionChange) {
|
|
31
|
+
t4 = (nextSelectedRows) => {
|
|
32
|
+
onSelectionChange === null || onSelectionChange === void 0 || onSelectionChange({ selectedRows: new Set(nextSelectedRows) });
|
|
33
|
+
};
|
|
34
|
+
$[6] = onSelectionChange;
|
|
35
|
+
$[7] = t4;
|
|
36
|
+
} else t4 = $[7];
|
|
37
|
+
let t5;
|
|
38
|
+
if ($[8] !== controlledSelectedRows || $[9] !== t3 || $[10] !== t4) {
|
|
39
|
+
t5 = {
|
|
40
|
+
name: "DataTable selectedRows",
|
|
41
|
+
value: controlledSelectedRows,
|
|
42
|
+
defaultValue: t3,
|
|
43
|
+
onChange: t4
|
|
44
|
+
};
|
|
45
|
+
$[8] = controlledSelectedRows;
|
|
46
|
+
$[9] = t3;
|
|
47
|
+
$[10] = t4;
|
|
48
|
+
$[11] = t5;
|
|
49
|
+
} else t5 = $[11];
|
|
50
|
+
const [selectedRows, setSelectedRows] = useControllableState(t5);
|
|
51
|
+
const { gridTemplateColumns } = useTableLayout(columns, rowSelection);
|
|
22
52
|
if (columns !== prevColumns) {
|
|
23
53
|
setPrevColumns(columns);
|
|
24
54
|
if (sortByColumn) {
|
|
@@ -29,20 +59,21 @@ function useTable(t0) {
|
|
|
29
59
|
})) setSortByColumn(null);
|
|
30
60
|
}
|
|
31
61
|
}
|
|
32
|
-
let
|
|
33
|
-
if ($[
|
|
34
|
-
|
|
35
|
-
$[
|
|
36
|
-
$[
|
|
37
|
-
} else
|
|
38
|
-
const hasGroups =
|
|
62
|
+
let t6;
|
|
63
|
+
if ($[12] !== rowOrder) {
|
|
64
|
+
t6 = rowOrder.some(isDataTableRowGroup);
|
|
65
|
+
$[12] = rowOrder;
|
|
66
|
+
$[13] = t6;
|
|
67
|
+
} else t6 = $[13];
|
|
68
|
+
const hasGroups = t6;
|
|
39
69
|
let bodies;
|
|
40
70
|
let headers;
|
|
41
71
|
let sortBy;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
72
|
+
let t7;
|
|
73
|
+
if ($[14] !== columns || $[15] !== data || $[16] !== externalSorting || $[17] !== getRowId || $[18] !== hasGroups || $[19] !== isRowSelectable || $[20] !== prevData || $[21] !== rowOrder || $[22] !== rowSelection || $[23] !== selectedRows || $[24] !== sortByColumn || $[25] !== tableId) {
|
|
74
|
+
let t8;
|
|
75
|
+
if ($[30] !== hasGroups || $[31] !== sortByColumn || $[32] !== tableId) {
|
|
76
|
+
t8 = (column_1, index) => {
|
|
46
77
|
var _column_1$id;
|
|
47
78
|
const id_0 = (_column_1$id = column_1.id) !== null && _column_1$id !== void 0 ? _column_1$id : column_1.field;
|
|
48
79
|
if (id_0 === void 0) throw new Error("Expected either an `id` or `field` to be defined for a Column");
|
|
@@ -60,12 +91,12 @@ function useTable(t0) {
|
|
|
60
91
|
}
|
|
61
92
|
};
|
|
62
93
|
};
|
|
63
|
-
$[
|
|
64
|
-
$[
|
|
65
|
-
$[
|
|
66
|
-
$[
|
|
67
|
-
} else
|
|
68
|
-
headers = columns.map(
|
|
94
|
+
$[30] = hasGroups;
|
|
95
|
+
$[31] = sortByColumn;
|
|
96
|
+
$[32] = tableId;
|
|
97
|
+
$[33] = t8;
|
|
98
|
+
} else t8 = $[33];
|
|
99
|
+
headers = columns.map(t8);
|
|
69
100
|
if (data !== prevData) {
|
|
70
101
|
setPrevData(data);
|
|
71
102
|
updateRowOrder(data, sortByColumn);
|
|
@@ -128,11 +159,17 @@ function useTable(t0) {
|
|
|
128
159
|
return sorted;
|
|
129
160
|
}
|
|
130
161
|
const createRow = function createRow(row_0, rowIndex) {
|
|
162
|
+
var _isRowSelectable;
|
|
131
163
|
const rowId = getRowId(row_0);
|
|
132
|
-
const rowHeaderIds = hasGroups ? headers.flatMap((header_2, index_0) => header_2.column.rowHeader ? [`${tableId}-row-${rowIndex}-header-${index_0}`] : []) : [];
|
|
164
|
+
const rowHeaderIds = hasGroups || rowSelection ? headers.flatMap((header_2, index_0) => header_2.column.rowHeader ? [`${tableId}-row-${rowIndex}-header-${index_0}`] : []) : [];
|
|
165
|
+
const selectable = rowSelection && ((_isRowSelectable = isRowSelectable === null || isRowSelectable === void 0 ? void 0 : isRowSelectable(row_0)) !== null && _isRowSelectable !== void 0 ? _isRowSelectable : true);
|
|
133
166
|
return {
|
|
134
167
|
type: "row",
|
|
135
168
|
id: `${rowId}`,
|
|
169
|
+
selectionId: rowId,
|
|
170
|
+
selectionLabelledBy: rowHeaderIds.length > 0 ? rowHeaderIds.join(" ") : void 0,
|
|
171
|
+
selected: selectable && selectedRows.has(rowId),
|
|
172
|
+
selectable,
|
|
136
173
|
getValue() {
|
|
137
174
|
return row_0;
|
|
138
175
|
},
|
|
@@ -142,7 +179,7 @@ function useTable(t0) {
|
|
|
142
179
|
const rowHeader = (_header_3$column$rowH = header_3.column.rowHeader) !== null && _header_3$column$rowH !== void 0 ? _header_3$column$rowH : false;
|
|
143
180
|
return {
|
|
144
181
|
id: `${rowId}:${header_3.id}`,
|
|
145
|
-
domId: hasGroups && rowHeader ? `${tableId}-row-${rowIndex}-header-${index_1}` : void 0,
|
|
182
|
+
domId: (hasGroups || rowSelection) && rowHeader ? `${tableId}-row-${rowIndex}-header-${index_1}` : void 0,
|
|
146
183
|
headers: hasGroups ? (rowHeader ? [header_3.domId] : [...rowHeaderIds, header_3.domId]).join(" ") : void 0,
|
|
147
184
|
column: header_3.column,
|
|
148
185
|
rowHeader,
|
|
@@ -184,44 +221,131 @@ function useTable(t0) {
|
|
|
184
221
|
rowIndex_0 = rowIndex_0 + 1;
|
|
185
222
|
}
|
|
186
223
|
if (body.rows.length > 0 || bodies.length === 0) bodies.push(body);
|
|
187
|
-
|
|
188
|
-
$[
|
|
189
|
-
$[
|
|
190
|
-
$[
|
|
191
|
-
$[
|
|
192
|
-
$[
|
|
193
|
-
$[
|
|
194
|
-
$[
|
|
195
|
-
$[
|
|
196
|
-
$[
|
|
197
|
-
$[
|
|
198
|
-
$[
|
|
224
|
+
t7 = bodies.flatMap(_temp).filter(_temp2);
|
|
225
|
+
$[14] = columns;
|
|
226
|
+
$[15] = data;
|
|
227
|
+
$[16] = externalSorting;
|
|
228
|
+
$[17] = getRowId;
|
|
229
|
+
$[18] = hasGroups;
|
|
230
|
+
$[19] = isRowSelectable;
|
|
231
|
+
$[20] = prevData;
|
|
232
|
+
$[21] = rowOrder;
|
|
233
|
+
$[22] = rowSelection;
|
|
234
|
+
$[23] = selectedRows;
|
|
235
|
+
$[24] = sortByColumn;
|
|
236
|
+
$[25] = tableId;
|
|
237
|
+
$[26] = bodies;
|
|
238
|
+
$[27] = headers;
|
|
239
|
+
$[28] = sortBy;
|
|
240
|
+
$[29] = t7;
|
|
199
241
|
} else {
|
|
200
|
-
bodies = $[
|
|
201
|
-
headers = $[
|
|
202
|
-
sortBy = $[
|
|
242
|
+
bodies = $[26];
|
|
243
|
+
headers = $[27];
|
|
244
|
+
sortBy = $[28];
|
|
245
|
+
t7 = $[29];
|
|
203
246
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
$[
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
247
|
+
const selectableRows = t7;
|
|
248
|
+
let t8;
|
|
249
|
+
if ($[34] !== selectableRows) {
|
|
250
|
+
t8 = new Set(selectableRows.filter(_temp3).map(_temp4));
|
|
251
|
+
$[34] = selectableRows;
|
|
252
|
+
$[35] = t8;
|
|
253
|
+
} else t8 = $[35];
|
|
254
|
+
const effectiveSelectedRows = t8;
|
|
255
|
+
const selectedCount = effectiveSelectedRows.size;
|
|
256
|
+
const selectableCount = selectableRows.length;
|
|
257
|
+
const allSelected = selectableCount > 0 && selectedCount === selectableCount;
|
|
258
|
+
const someSelected = selectedCount > 0 && !allSelected;
|
|
259
|
+
let t9;
|
|
260
|
+
if ($[36] !== selectedRows || $[37] !== setSelectedRows) {
|
|
261
|
+
t9 = function toggleRowSelection(row_5) {
|
|
262
|
+
if (!row_5.selectable) return;
|
|
263
|
+
const nextSelectedRows_0 = new Set(selectedRows);
|
|
264
|
+
if (nextSelectedRows_0.has(row_5.selectionId)) nextSelectedRows_0.delete(row_5.selectionId);
|
|
265
|
+
else nextSelectedRows_0.add(row_5.selectionId);
|
|
266
|
+
setSelectedRows(nextSelectedRows_0);
|
|
267
|
+
};
|
|
268
|
+
$[36] = selectedRows;
|
|
269
|
+
$[37] = setSelectedRows;
|
|
270
|
+
$[38] = t9;
|
|
271
|
+
} else t9 = $[38];
|
|
272
|
+
const toggleRowSelection = t9;
|
|
273
|
+
let t10;
|
|
274
|
+
if ($[39] !== allSelected || $[40] !== selectableRows || $[41] !== selectedRows || $[42] !== setSelectedRows) {
|
|
275
|
+
t10 = function toggleAllRows() {
|
|
276
|
+
if (selectableRows.length === 0) return;
|
|
277
|
+
const nextSelectedRows_1 = new Set(selectedRows);
|
|
278
|
+
for (const row_6 of selectableRows) if (allSelected) nextSelectedRows_1.delete(row_6.selectionId);
|
|
279
|
+
else nextSelectedRows_1.add(row_6.selectionId);
|
|
280
|
+
setSelectedRows(nextSelectedRows_1);
|
|
281
|
+
};
|
|
282
|
+
$[39] = allSelected;
|
|
283
|
+
$[40] = selectableRows;
|
|
284
|
+
$[41] = selectedRows;
|
|
285
|
+
$[42] = setSelectedRows;
|
|
286
|
+
$[43] = t10;
|
|
287
|
+
} else t10 = $[43];
|
|
288
|
+
const toggleAllRows = t10;
|
|
289
|
+
let t11;
|
|
290
|
+
if ($[44] !== sortBy || $[45] !== toggleAllRows || $[46] !== toggleRowSelection) {
|
|
291
|
+
t11 = {
|
|
292
|
+
sortBy,
|
|
293
|
+
toggleRowSelection,
|
|
294
|
+
toggleAllRows
|
|
295
|
+
};
|
|
296
|
+
$[44] = sortBy;
|
|
297
|
+
$[45] = toggleAllRows;
|
|
298
|
+
$[46] = toggleRowSelection;
|
|
299
|
+
$[47] = t11;
|
|
300
|
+
} else t11 = $[47];
|
|
301
|
+
const t12 = `${tableId}-selection-column`;
|
|
302
|
+
let t13;
|
|
303
|
+
if ($[48] !== allSelected || $[49] !== effectiveSelectedRows || $[50] !== selectableCount || $[51] !== selectedCount || $[52] !== someSelected || $[53] !== t12) {
|
|
304
|
+
t13 = {
|
|
305
|
+
headerId: t12,
|
|
306
|
+
selectedRows: effectiveSelectedRows,
|
|
307
|
+
allSelected,
|
|
308
|
+
someSelected,
|
|
309
|
+
selectableCount,
|
|
310
|
+
selectedCount
|
|
311
|
+
};
|
|
312
|
+
$[48] = allSelected;
|
|
313
|
+
$[49] = effectiveSelectedRows;
|
|
314
|
+
$[50] = selectableCount;
|
|
315
|
+
$[51] = selectedCount;
|
|
316
|
+
$[52] = someSelected;
|
|
317
|
+
$[53] = t12;
|
|
318
|
+
$[54] = t13;
|
|
319
|
+
} else t13 = $[54];
|
|
320
|
+
let t14;
|
|
321
|
+
if ($[55] !== bodies || $[56] !== gridTemplateColumns || $[57] !== headers || $[58] !== t11 || $[59] !== t13) {
|
|
322
|
+
t14 = {
|
|
213
323
|
headers,
|
|
214
|
-
actions:
|
|
324
|
+
actions: t11,
|
|
325
|
+
selection: t13,
|
|
215
326
|
gridTemplateColumns,
|
|
216
327
|
bodies
|
|
217
328
|
};
|
|
218
|
-
$[
|
|
219
|
-
$[
|
|
220
|
-
$[
|
|
221
|
-
$[
|
|
222
|
-
$[
|
|
223
|
-
|
|
224
|
-
|
|
329
|
+
$[55] = bodies;
|
|
330
|
+
$[56] = gridTemplateColumns;
|
|
331
|
+
$[57] = headers;
|
|
332
|
+
$[58] = t11;
|
|
333
|
+
$[59] = t13;
|
|
334
|
+
$[60] = t14;
|
|
335
|
+
} else t14 = $[60];
|
|
336
|
+
return t14;
|
|
337
|
+
}
|
|
338
|
+
function _temp4(row_4) {
|
|
339
|
+
return row_4.selectionId;
|
|
340
|
+
}
|
|
341
|
+
function _temp3(row_3) {
|
|
342
|
+
return row_3.selected;
|
|
343
|
+
}
|
|
344
|
+
function _temp2(row_2) {
|
|
345
|
+
return row_2.selectable;
|
|
346
|
+
}
|
|
347
|
+
function _temp(body_0) {
|
|
348
|
+
return body_0.rows;
|
|
225
349
|
}
|
|
226
350
|
function isDataTableRowGroup(item) {
|
|
227
351
|
return "groupId" in item && "rows" in item && Array.isArray(item.rows);
|
|
@@ -265,8 +389,8 @@ function getInitialSortState(columns, initialSortColumn, initialSortDirection) {
|
|
|
265
389
|
}
|
|
266
390
|
return null;
|
|
267
391
|
}
|
|
268
|
-
function useTableLayout(columns) {
|
|
269
|
-
return { gridTemplateColumns: getGridTemplateFromColumns(columns).join(" ") };
|
|
392
|
+
function useTableLayout(columns, rowSelection = false) {
|
|
393
|
+
return { gridTemplateColumns: [...rowSelection ? ["min-content"] : [], ...getGridTemplateFromColumns(columns)].join(" ") };
|
|
270
394
|
}
|
|
271
395
|
function getGridTemplateFromColumns(columns) {
|
|
272
396
|
return columns.map((column) => {
|