@calcifer-design/ui 0.4.0 → 0.6.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 (133) hide show
  1. package/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
  2. package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
  3. package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
  4. package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
  5. package/dist/components/CardList/CardList.d.ts +30 -0
  6. package/dist/components/CardList/CardList.js +35 -0
  7. package/dist/components/CardList/CardList.module.js +7 -0
  8. package/dist/components/CardList/CardList_module.css +20 -0
  9. package/dist/components/DataGrid/DataGrid.d.ts +3 -0
  10. package/dist/components/DataGrid/DataGrid.js +436 -0
  11. package/dist/components/DataGrid/DataGrid.module.js +36 -0
  12. package/dist/components/DataGrid/DataGrid_module.css +367 -0
  13. package/dist/components/DataGrid/GridCardHeader.d.ts +16 -0
  14. package/dist/components/DataGrid/GridCardHeader.js +40 -0
  15. package/dist/components/DataGrid/GridCheckbox.d.ts +15 -0
  16. package/dist/components/DataGrid/GridCheckbox.js +25 -0
  17. package/dist/components/DataGrid/GridHeaderCell.d.ts +14 -0
  18. package/dist/components/DataGrid/GridHeaderCell.js +29 -0
  19. package/dist/components/DataGrid/GridHeaderRow.d.ts +35 -0
  20. package/dist/components/DataGrid/GridHeaderRow.js +56 -0
  21. package/dist/components/DataGrid/GridRow.d.ts +69 -0
  22. package/dist/components/DataGrid/GridRow.js +139 -0
  23. package/dist/components/DataGrid/GridStateRows.d.ts +24 -0
  24. package/dist/components/DataGrid/GridStateRows.js +59 -0
  25. package/dist/components/DataGrid/columns.d.ts +40 -0
  26. package/dist/components/DataGrid/columns.js +37 -0
  27. package/dist/components/DataGrid/labels.d.ts +20 -0
  28. package/dist/components/DataGrid/labels.js +25 -0
  29. package/dist/components/DataGrid/types.d.ts +88 -0
  30. package/dist/components/DataGrid/types.js +0 -0
  31. package/dist/components/DataGrid/useGridEntries.d.ts +17 -0
  32. package/dist/components/DataGrid/useGridEntries.js +40 -0
  33. package/dist/components/DataGrid/useGridHighlight.d.ts +16 -0
  34. package/dist/components/DataGrid/useGridHighlight.js +24 -0
  35. package/dist/components/DataGrid/useGridKeyboard.d.ts +50 -0
  36. package/dist/components/DataGrid/useGridKeyboard.js +242 -0
  37. package/dist/components/DataGrid/useGridMetrics.d.ts +13 -0
  38. package/dist/components/DataGrid/useGridMetrics.js +35 -0
  39. package/dist/components/DataGrid/useLatest.d.ts +7 -0
  40. package/dist/components/DataGrid/useLatest.js +9 -0
  41. package/dist/components/DataGrid/useLoadMore.d.ts +30 -0
  42. package/dist/components/DataGrid/useLoadMore.js +39 -0
  43. package/dist/components/DataGrid/useRowExpansion.d.ts +14 -0
  44. package/dist/components/DataGrid/useRowExpansion.js +21 -0
  45. package/dist/components/DataGrid/useRowSelection.d.ts +43 -0
  46. package/dist/components/DataGrid/useRowSelection.js +107 -0
  47. package/dist/components/DatePicker/Calendar.d.ts +19 -0
  48. package/dist/components/DatePicker/Calendar.js +207 -0
  49. package/dist/components/DatePicker/DatePicker.d.ts +72 -0
  50. package/dist/components/DatePicker/DatePicker.js +116 -0
  51. package/dist/components/DatePicker/DatePicker.module.js +14 -0
  52. package/dist/components/DatePicker/DatePicker_module.css +112 -0
  53. package/dist/components/DatePicker/calendarDate.d.ts +46 -0
  54. package/dist/components/DatePicker/calendarDate.js +117 -0
  55. package/dist/components/Descriptions/Descriptions.d.ts +25 -0
  56. package/dist/components/Descriptions/Descriptions.js +44 -0
  57. package/dist/components/Descriptions/Descriptions.module.js +8 -0
  58. package/dist/components/Descriptions/Descriptions_module.css +47 -0
  59. package/dist/components/Field/Field.d.ts +1 -1
  60. package/dist/components/Field/Field.js +7 -1
  61. package/dist/components/Field/PickerField.d.ts +41 -0
  62. package/dist/components/Field/PickerField.js +115 -0
  63. package/dist/components/Field/PickerField.module.js +8 -0
  64. package/dist/components/Field/PickerField_module.css +36 -0
  65. package/dist/components/FilterBar/FilterBar.d.ts +55 -0
  66. package/dist/components/FilterBar/FilterBar.js +138 -0
  67. package/dist/components/FilterBar/FilterBar.module.js +13 -0
  68. package/dist/components/FilterBar/FilterBar_module.css +98 -0
  69. package/dist/components/Form/Form.d.ts +48 -0
  70. package/dist/components/Form/Form.js +38 -0
  71. package/dist/components/Form/Form.module.js +5 -0
  72. package/dist/components/Form/FormContext.d.ts +15 -0
  73. package/dist/components/Form/FormContext.js +20 -0
  74. package/dist/components/Form/Form_module.css +6 -0
  75. package/dist/components/PageShell/PageShell.d.ts +27 -0
  76. package/dist/components/PageShell/PageShell.js +35 -0
  77. package/dist/components/PageShell/PageShell.module.js +9 -0
  78. package/dist/components/PageShell/PageShell_module.css +56 -0
  79. package/dist/components/Segmented/Segmented.d.ts +49 -0
  80. package/dist/components/Segmented/Segmented.js +55 -0
  81. package/dist/components/Segmented/Segmented.module.js +7 -0
  82. package/dist/components/Segmented/Segmented_module.css +75 -0
  83. package/dist/components/Steps/Steps.d.ts +30 -0
  84. package/dist/components/Steps/Steps.js +63 -0
  85. package/dist/components/Steps/Steps.module.js +10 -0
  86. package/dist/components/Steps/Steps_module.css +126 -0
  87. package/dist/components/TextArea/TextArea.d.ts +16 -0
  88. package/dist/components/TextArea/TextArea.js +28 -0
  89. package/dist/components/TextArea/TextArea.module.js +5 -0
  90. package/dist/components/TextArea/TextArea_module.css +12 -0
  91. package/dist/components/TimePicker/TimePicker.d.ts +19 -0
  92. package/dist/components/TimePicker/TimePicker.js +17 -0
  93. package/dist/components/Timeline/Timeline.d.ts +39 -0
  94. package/dist/components/Timeline/Timeline.js +109 -0
  95. package/dist/components/Timeline/Timeline.module.js +12 -0
  96. package/dist/components/Timeline/Timeline_module.css +99 -0
  97. package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
  98. package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
  99. package/dist/components/Toolbar/Toolbar.d.ts +46 -0
  100. package/dist/components/Toolbar/Toolbar.js +43 -0
  101. package/dist/components/Toolbar/Toolbar.module.js +7 -0
  102. package/dist/components/Toolbar/Toolbar_module.css +26 -0
  103. package/dist/components/Tree/Tree.d.ts +81 -0
  104. package/dist/components/Tree/Tree.js +232 -0
  105. package/dist/components/Tree/Tree.module.js +12 -0
  106. package/dist/components/Tree/Tree_module.css +124 -0
  107. package/dist/components/Tree/treeIndex.d.ts +23 -0
  108. package/dist/components/Tree/treeIndex.js +33 -0
  109. package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
  110. package/dist/components/TreeSelect/TreeSelect.js +117 -0
  111. package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
  112. package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
  113. package/dist/components/Upload/Upload.d.ts +66 -0
  114. package/dist/components/Upload/Upload.js +287 -0
  115. package/dist/components/Upload/Upload.module.js +12 -0
  116. package/dist/components/Upload/Upload_module.css +96 -0
  117. package/dist/components/ViewField/ViewField.d.ts +26 -0
  118. package/dist/components/ViewField/ViewField.js +29 -0
  119. package/dist/components/ViewField/ViewField.module.js +6 -0
  120. package/dist/components/ViewField/ViewField_module.css +17 -0
  121. package/dist/hooks/useFormReset.d.ts +10 -0
  122. package/dist/hooks/useFormReset.js +34 -0
  123. package/dist/icons/CalendarIcon.d.ts +2 -0
  124. package/dist/icons/CalendarIcon.js +26 -0
  125. package/dist/icons/ChevronRightIcon.d.ts +6 -0
  126. package/dist/icons/ChevronRightIcon.js +17 -0
  127. package/dist/icons/RefreshIcon.d.ts +6 -0
  128. package/dist/icons/RefreshIcon.js +22 -0
  129. package/dist/index.d.ts +39 -0
  130. package/dist/index.js +19 -0
  131. package/dist/styles/pair.module.js +6 -0
  132. package/dist/styles/pair_module.css +18 -0
  133. package/package.json +4 -3
@@ -0,0 +1,24 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { LinkRenderProps } from '../NavMenu/NavMenu.js';
3
+ export interface BreadcrumbItem {
4
+ label: string;
5
+ /**
6
+ * Makes the item a link. Ignored on the last item, which is the page the reader is on, and
7
+ * optional before it for a level with no page of its own.
8
+ */
9
+ href?: string;
10
+ }
11
+ export interface BreadcrumbProps {
12
+ /** The trail, outermost first. The last item is the current page. */
13
+ items: BreadcrumbItem[];
14
+ /** The navigation landmark's name. */
15
+ 'aria-label'?: string;
16
+ /**
17
+ * Lets the app render router links; defaults to a plain anchor. Called only for an item that
18
+ * is a link, so `href` is always there.
19
+ */
20
+ renderLink?: (item: BreadcrumbItem & {
21
+ href: string;
22
+ }, props: LinkRenderProps) => ReactElement;
23
+ }
24
+ export declare function Breadcrumb({ items, 'aria-label': ariaLabel, renderLink, }: BreadcrumbProps): import("react").JSX.Element | null;
@@ -0,0 +1,48 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import Breadcrumb_module from "./Breadcrumb.module.js";
3
+ function defaultRenderLink(item, { children, ...linkProps }) {
4
+ return /*#__PURE__*/ jsx("a", {
5
+ href: item.href,
6
+ ...linkProps,
7
+ children: children
8
+ });
9
+ }
10
+ function renderItemContent(item, isLast, renderLink) {
11
+ if (isLast) return /*#__PURE__*/ jsx("span", {
12
+ className: Breadcrumb_module.current,
13
+ "aria-current": "page",
14
+ children: item.label
15
+ });
16
+ if (void 0 === item.href) return /*#__PURE__*/ jsx("span", {
17
+ className: Breadcrumb_module.text,
18
+ children: item.label
19
+ });
20
+ return renderLink({
21
+ ...item,
22
+ href: item.href
23
+ }, {
24
+ className: Breadcrumb_module.link,
25
+ children: item.label
26
+ });
27
+ }
28
+ function Breadcrumb({ items, 'aria-label': ariaLabel = 'Breadcrumb', renderLink = defaultRenderLink }) {
29
+ if (0 === items.length) return null;
30
+ return /*#__PURE__*/ jsx("nav", {
31
+ "aria-label": ariaLabel,
32
+ children: /*#__PURE__*/ jsx("ol", {
33
+ className: Breadcrumb_module.list,
34
+ children: items.map((item, index)=>/*#__PURE__*/ jsxs("li", {
35
+ className: Breadcrumb_module.item,
36
+ children: [
37
+ index > 0 ? /*#__PURE__*/ jsx("span", {
38
+ className: Breadcrumb_module.separator,
39
+ "aria-hidden": "true",
40
+ children: "/"
41
+ }) : null,
42
+ renderItemContent(item, index === items.length - 1, renderLink)
43
+ ]
44
+ }, index))
45
+ })
46
+ });
47
+ }
48
+ export { Breadcrumb };
@@ -0,0 +1,10 @@
1
+ import "./Breadcrumb_module.css";
2
+ const Breadcrumb_module = {
3
+ list: "list-eDbWY",
4
+ item: "item-yKtE5",
5
+ separator: "separator-pHrdE",
6
+ link: "link-l4Wbt",
7
+ text: "text-F4Upa",
8
+ current: "current-rfbM_"
9
+ };
10
+ export default Breadcrumb_module;
@@ -0,0 +1,49 @@
1
+ .list-eDbWY {
2
+ align-items: center;
3
+ gap: var(--space-1) var(--space-2);
4
+ font-size: var(--text-sm);
5
+ line-height: var(--leading-snug);
6
+ flex-wrap: wrap;
7
+ margin: 0;
8
+ padding: 0;
9
+ list-style: none;
10
+ display: flex;
11
+ }
12
+
13
+ .item-yKtE5 {
14
+ align-items: center;
15
+ gap: var(--space-2);
16
+ overflow-wrap: anywhere;
17
+ min-width: 0;
18
+ display: inline-flex;
19
+ }
20
+
21
+ .separator-pHrdE {
22
+ color: var(--color-text-subtle);
23
+ flex: none;
24
+ }
25
+
26
+ .link-l4Wbt {
27
+ border-radius: var(--radius-sm);
28
+ min-height: 1.5rem;
29
+ color: var(--color-link);
30
+ align-items: center;
31
+ text-decoration: underline;
32
+ display: inline-flex;
33
+ }
34
+
35
+ @media (hover: hover) {
36
+ .link-l4Wbt:hover {
37
+ text-decoration: none;
38
+ }
39
+ }
40
+
41
+ .text-F4Upa {
42
+ color: var(--color-text-muted);
43
+ }
44
+
45
+ .current-rfbM_ {
46
+ color: var(--color-text);
47
+ font-weight: 500;
48
+ }
49
+
@@ -0,0 +1,30 @@
1
+ import type { ReactNode } from 'react';
2
+ export interface CardListProps<Item> {
3
+ items: readonly Item[];
4
+ /** What tells one item from another across renders. */
5
+ getKey: (item: Item) => string | number;
6
+ /** One card. A `Card` is the usual answer, and any node will do. */
7
+ renderItem: (item: Item) => ReactNode;
8
+ /**
9
+ * The narrowest a column may get, as any CSS length, before the list drops to fewer columns.
10
+ * Defaults to `16rem`. A width greater than the list's own takes the list's own, so no value can
11
+ * overflow a phone.
12
+ */
13
+ minColumnWidth?: string;
14
+ /**
15
+ * Sets `aria-busy`. Items already here stay, so that a refresh loses nobody's focus or place, and
16
+ * skeletons stand in only for an empty list. To show skeletons, pass no items.
17
+ */
18
+ loading?: boolean;
19
+ /** How many skeletons stand in, up to 100. */
20
+ skeletonCount?: number;
21
+ /** Shown when there are no items and nothing is loading. Without it, nothing is drawn. */
22
+ emptyState?: ReactNode;
23
+ /** Names the list. */
24
+ 'aria-label': string;
25
+ }
26
+ /**
27
+ * A responsive list of cards: as many columns as fit, down to one. Each skeleton's item is hidden
28
+ * from assistive technology, so a list still loading reads as a busy list and not as blank rows.
29
+ */
30
+ export declare function CardList<Item>({ items, getKey, renderItem, minColumnWidth, loading, skeletonCount, emptyState, 'aria-label': ariaLabel, }: CardListProps<Item>): import("react").JSX.Element | null;
@@ -0,0 +1,35 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Skeleton } from "../Skeleton/Skeleton.js";
3
+ import CardList_module from "./CardList.module.js";
4
+ function CardList({ items, getKey, renderItem, minColumnWidth, loading = false, skeletonCount = 6, emptyState, 'aria-label': ariaLabel }) {
5
+ if (0 === items.length && !loading) return void 0 === emptyState ? null : /*#__PURE__*/ jsx("div", {
6
+ className: CardList_module.empty,
7
+ children: emptyState
8
+ });
9
+ const standIns = 0 === items.length && Number.isFinite(skeletonCount) ? Math.min(Math.max(0, Math.trunc(skeletonCount)), 100) : 0;
10
+ return /*#__PURE__*/ jsxs("ul", {
11
+ role: "list",
12
+ className: CardList_module.list,
13
+ style: void 0 === minColumnWidth ? void 0 : {
14
+ '--card-list-min-column': minColumnWidth
15
+ },
16
+ "aria-label": ariaLabel,
17
+ "aria-busy": loading ? true : void 0,
18
+ children: [
19
+ items.map((item)=>/*#__PURE__*/ jsx("li", {
20
+ className: CardList_module.item,
21
+ children: renderItem(item)
22
+ }, getKey(item))),
23
+ Array.from({
24
+ length: standIns
25
+ }, (_unused, position)=>/*#__PURE__*/ jsx("li", {
26
+ className: CardList_module.item,
27
+ "aria-hidden": "true",
28
+ children: /*#__PURE__*/ jsx(Skeleton, {
29
+ variant: "block"
30
+ })
31
+ }, position))
32
+ ]
33
+ });
34
+ }
35
+ export { CardList };
@@ -0,0 +1,7 @@
1
+ import "./CardList_module.css";
2
+ const CardList_module = {
3
+ list: "list-sqMJI",
4
+ item: "item-b8vTh",
5
+ empty: "empty-G1gXX"
6
+ };
7
+ export default CardList_module;
@@ -0,0 +1,20 @@
1
+ .list-sqMJI {
2
+ --card-list-track: minmax(min(var(--card-list-min-column, 16rem), 100%), 1fr);
3
+ grid-template-columns: repeat(auto-fill, var(--card-list-track));
4
+ gap: var(--space-4);
5
+ margin: 0;
6
+ padding: 0;
7
+ list-style: none;
8
+ display: grid;
9
+ }
10
+
11
+ .item-b8vTh {
12
+ min-width: 0;
13
+ }
14
+
15
+ .empty-G1gXX {
16
+ color: var(--color-text-muted);
17
+ font-size: var(--text-md);
18
+ line-height: var(--leading-prose);
19
+ }
20
+
@@ -0,0 +1,3 @@
1
+ import { type RowData } from '@tanstack/react-table';
2
+ import type { DataGridProps } from './types.js';
3
+ export declare function DataGrid<Row extends RowData>({ heading, headingLevel, rows, columns, getRowId, getRowLabel, actions, mode, totalRowCount, hasMore, loadingMore, loadError, onLoadMore, onQueryChange, initialSorting, enableSorting, multiSort, density, maxHeight, fill, hideFooter, loading, emptyState, onRefresh, refreshing, highlightOnClick, highlightedRowId, onHighlightChange, selectionMode, selectedRowIds, defaultSelectedRowIds, onSelectedRowIdsChange, isRowSelectable, onRowClick, onRowDoubleClick, onRowContextMenu, renderRowActions, rowActionsHeader, renderExpandedRow, isRowExpandable, expandedRowIds, defaultExpandedRowIds, onExpandedRowIdsChange, labels, }: DataGridProps<Row>): import("react").JSX.Element;
@@ -0,0 +1,436 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useTable } from "@tanstack/react-table";
3
+ import { useVirtualizer } from "@tanstack/react-virtual";
4
+ import { useCallback, useId, useMemo, useRef, useState } from "react";
5
+ import { LiveRegion } from "../LiveRegion/LiveRegion.js";
6
+ import { dataGridFeatures, textValueOf } from "./columns.js";
7
+ import DataGrid_module from "./DataGrid.module.js";
8
+ import { GridCardHeader } from "./GridCardHeader.js";
9
+ import { GridHeaderRow } from "./GridHeaderRow.js";
10
+ import { GridDetailRow, GridRow, GridSpacerRow } from "./GridRow.js";
11
+ import { GridErrorRow, GridStateRow } from "./GridStateRows.js";
12
+ import { resolveDataGridLabels } from "./labels.js";
13
+ import { useGridEntries } from "./useGridEntries.js";
14
+ import { useGridHighlight } from "./useGridHighlight.js";
15
+ import { useGridMetrics } from "./useGridMetrics.js";
16
+ import { cellControlSelector, useGridKeyboard } from "./useGridKeyboard.js";
17
+ import { useLoadMore } from "./useLoadMore.js";
18
+ import { useRowExpansion } from "./useRowExpansion.js";
19
+ import { useRowSelection } from "./useRowSelection.js";
20
+ const emptyCellText = '—';
21
+ const estimatedRowHeight = {
22
+ comfortable: 40,
23
+ compact: 34
24
+ };
25
+ const overscanRows = 8;
26
+ const loadAheadViewports = 2;
27
+ function extractRange(range, pinnedIndexes, entries) {
28
+ const start = Math.max(range.startIndex - range.overscan, 0);
29
+ const end = Math.min(range.endIndex + range.overscan, range.count - 1);
30
+ const indexes = new Set();
31
+ for(let index = start; index <= end; index += 1)indexes.add(index);
32
+ for (const pinnedIndex of pinnedIndexes)if (pinnedIndex >= 0 && pinnedIndex < range.count) indexes.add(pinnedIndex);
33
+ for (const index of [
34
+ ...indexes
35
+ ])if (entries[index]?.kind === 'row' && entries[index + 1]?.kind === 'detail') indexes.add(index + 1);
36
+ return [
37
+ ...indexes
38
+ ].sort((first, second)=>first - second);
39
+ }
40
+ function formatCellValue(value) {
41
+ if (null == value) return emptyCellText;
42
+ const text = 'string' == typeof value ? value : String(value);
43
+ return '' === text.trim() ? emptyCellText : text;
44
+ }
45
+ function DataGrid({ heading, headingLevel = 2, rows, columns, getRowId, getRowLabel, actions, mode = 'client', totalRowCount, hasMore = false, loadingMore = false, loadError, onLoadMore, onQueryChange, initialSorting = [], enableSorting = true, multiSort = false, density = 'comfortable', maxHeight, fill = false, hideFooter = false, loading = false, emptyState, onRefresh, refreshing = false, highlightOnClick = false, highlightedRowId, onHighlightChange, selectionMode = 'none', selectedRowIds, defaultSelectedRowIds, onSelectedRowIdsChange, isRowSelectable, onRowClick, onRowDoubleClick, onRowContextMenu, renderRowActions, rowActionsHeader, renderExpandedRow, isRowExpandable, expandedRowIds, defaultExpandedRowIds, onExpandedRowIdsChange, labels }) {
46
+ const serverMode = 'server' === mode;
47
+ const sortingEnabled = enableSorting && (!serverMode || void 0 !== onQueryChange);
48
+ const [sorting, setSorting] = useState(initialSorting);
49
+ const [rowsOfOldQuery, setRowsOfOldQuery] = useState(null);
50
+ const awaitingNewRows = rowsOfOldQuery === rows;
51
+ const { highlightedId, setHighlightedId } = useGridHighlight({
52
+ rows,
53
+ getRowId,
54
+ loading,
55
+ highlightedRowId,
56
+ onHighlightChange
57
+ });
58
+ const selecting = 'multiple' === selectionMode;
59
+ const expanding = void 0 !== renderExpandedRow;
60
+ const expandColumn = selecting ? 1 : 0;
61
+ const columnOffset = expandColumn + (expanding ? 1 : 0);
62
+ const expansion = useRowExpansion({
63
+ expandedRowIds,
64
+ defaultExpandedRowIds,
65
+ onExpandedRowIdsChange
66
+ });
67
+ const isExpandable = (row)=>expanding && (isRowExpandable?.(row) ?? true);
68
+ const selection = useRowSelection({
69
+ enabled: selecting,
70
+ rows,
71
+ getRowId,
72
+ isRowSelectable,
73
+ loading,
74
+ selectedRowIds,
75
+ defaultSelectedRowIds,
76
+ onSelectedRowIdsChange,
77
+ getDisplayedRowIds: ()=>entries.flatMap((entry)=>'row' === entry.kind ? [
78
+ entry.row.id
79
+ ] : [])
80
+ });
81
+ const headingId = useId();
82
+ const panelIdPrefix = useId();
83
+ const resolvedLabels = resolveDataGridLabels(labels);
84
+ const table = useTable({
85
+ features: dataGridFeatures,
86
+ data: rows,
87
+ columns,
88
+ getRowId,
89
+ state: {
90
+ sorting,
91
+ rowSelection: selection.rowSelection
92
+ },
93
+ manualSorting: serverMode,
94
+ onSortingChange: (updater)=>{
95
+ const nextSorting = 'function' == typeof updater ? updater(sorting) : updater;
96
+ setSorting(nextSorting);
97
+ selection.clear();
98
+ if (serverMode) {
99
+ setRowsOfOldQuery(rows);
100
+ loadMore.reset();
101
+ virtualizer.scrollToOffset(0);
102
+ onQueryChange?.({
103
+ sorting: nextSorting,
104
+ filters: {},
105
+ matchMode: 'all',
106
+ search: ''
107
+ });
108
+ }
109
+ },
110
+ enableRowSelection: (row)=>isRowSelectable?.(row.original) ?? true,
111
+ enableSorting: sortingEnabled,
112
+ enableMultiSort: multiSort,
113
+ defaultColumn: {
114
+ sortDescFirst: false,
115
+ cell: (context)=>context.column.accessorFn ? formatCellValue(context.getValue()) : null
116
+ }
117
+ });
118
+ const scrollRef = useRef(null);
119
+ const headRef = useRef(null);
120
+ const { viewportHeight, headerHeight, rightToLeft } = useGridMetrics(scrollRef, headRef);
121
+ const tableRows = table.getRowModel().rows;
122
+ const entries = useGridEntries(tableRows, expansion.expandedIds, (row)=>isExpandable(row.original));
123
+ const openPanelCount = useMemo(()=>entries.filter((entry)=>'detail' === entry.kind).length, [
124
+ entries
125
+ ]);
126
+ const leafHeaders = table.getHeaderGroups()[0]?.headers ?? [];
127
+ const leafColumns = table.getAllLeafColumns();
128
+ const columnCount = columnOffset + leafColumns.length + (renderRowActions ? 1 : 0);
129
+ const panelIdOf = (row)=>`${panelIdPrefix}-detail-${row.index}`;
130
+ const showsLoadError = serverMode && void 0 !== loadError && !loading;
131
+ let stateKind = null;
132
+ if (loading) stateKind = 'loading';
133
+ else if (0 === entries.length && !showsLoadError) stateKind = 'empty';
134
+ const rowHeight = estimatedRowHeight[density];
135
+ const rowsPerViewport = Math.max(1, Math.floor((viewportHeight - headerHeight) / rowHeight));
136
+ const rowsClickable = Boolean(onRowClick || highlightOnClick);
137
+ const clickRow = (row, event)=>{
138
+ onRowClick?.(row.original, event);
139
+ if (!highlightOnClick) return;
140
+ if (highlightedId === row.id && 'detail' in event && event.detail > 1) return;
141
+ setHighlightedId(highlightedId === row.id ? null : row.id);
142
+ };
143
+ const handleRowClick = (row, event)=>{
144
+ const selectsRow = event.shiftKey || event.ctrlKey || event.metaKey;
145
+ if (selecting && selectsRow) return void selection.toggleRow(row.id, {
146
+ range: event.shiftKey
147
+ });
148
+ clickRow(row, event);
149
+ };
150
+ const rowLabelOf = (row)=>{
151
+ if (getRowLabel) return getRowLabel(row.original);
152
+ const firstColumn = leafColumns[0];
153
+ const text = firstColumn ? textValueOf(firstColumn.columnDef, row.original) : void 0;
154
+ return text ?? row.id;
155
+ };
156
+ const handleActivate = (rowIndex, columnIndex, event)=>{
157
+ if (rowIndex > 0 && expanding && columnIndex === expandColumn) {
158
+ const entry = entries[rowIndex - 1];
159
+ if (entry?.kind === 'row' && isExpandable(entry.row.original)) {
160
+ event.preventDefault();
161
+ expansion.toggleRow(entry.row.id);
162
+ return;
163
+ }
164
+ }
165
+ if (' ' === event.key) {
166
+ if (!selecting) return;
167
+ if (0 === rowIndex) {
168
+ if (0 !== columnIndex || !selection.canSelectAny) return;
169
+ event.preventDefault();
170
+ selection.toggleAll();
171
+ return;
172
+ }
173
+ const entry = entries[rowIndex - 1];
174
+ if (entry?.kind !== 'row' || !selection.isSelectable(entry.row.id)) return;
175
+ event.preventDefault();
176
+ selection.toggleRow(entry.row.id, {
177
+ range: event.shiftKey
178
+ });
179
+ return;
180
+ }
181
+ if ('Enter' !== event.key) return;
182
+ if (0 === rowIndex) {
183
+ const column = leafHeaders[columnIndex - columnOffset]?.column;
184
+ if (column?.getCanSort()) {
185
+ event.preventDefault();
186
+ column.getToggleSortingHandler()?.(event);
187
+ }
188
+ return;
189
+ }
190
+ const entry = entries[rowIndex - 1];
191
+ if (entry?.kind !== 'row' || event.currentTarget.querySelector(cellControlSelector)) return;
192
+ if (rowsClickable) {
193
+ event.preventDefault();
194
+ clickRow(entry.row, event);
195
+ }
196
+ };
197
+ const keyboardContextMenuCellRef = useRef(null);
198
+ const forgetKeyboardContextMenu = ()=>{
199
+ keyboardContextMenuCellRef.current = null;
200
+ };
201
+ const handleContextMenuKey = (rowIndex, _columnIndex, event)=>{
202
+ const entry = entries[rowIndex - 1];
203
+ if (entry?.kind !== 'row' || !onRowContextMenu) return;
204
+ event.preventDefault();
205
+ keyboardContextMenuCellRef.current = event.currentTarget;
206
+ onRowContextMenu(entry.row.original, event);
207
+ };
208
+ const handleRowContextMenu = (row, event)=>{
209
+ event.preventDefault();
210
+ const pressedCell = keyboardContextMenuCellRef.current;
211
+ keyboardContextMenuCellRef.current = null;
212
+ if (null !== pressedCell && pressedCell === event.target.closest('td')) return;
213
+ onRowContextMenu?.(row.original, event);
214
+ };
215
+ const keyboard = useGridKeyboard({
216
+ rowCount: stateKind ? 1 : entries.length + 1 + (showsLoadError ? 1 : 0),
217
+ columnCount,
218
+ onActivate: handleActivate,
219
+ onContextMenu: handleContextMenuKey,
220
+ scrollToEntry: (entryIndex)=>virtualizer.scrollToIndex(entryIndex),
221
+ getPageSize: ()=>{
222
+ const range = virtualizer.range;
223
+ return range ? Math.max(1, range.endIndex - range.startIndex + 1) : rowsPerViewport;
224
+ }
225
+ });
226
+ const focusedEntryIndex = keyboard.focusedCell.rowIndex - 1;
227
+ const pinnedIndexes = useMemo(()=>new Set(focusedEntryIndex >= 0 ? [
228
+ focusedEntryIndex
229
+ ] : []), [
230
+ focusedEntryIndex
231
+ ]);
232
+ const getItemKey = useCallback((index)=>{
233
+ const entry = entries[index];
234
+ return entry ? `${entry.kind}:${entry.row.id}` : index;
235
+ }, [
236
+ entries
237
+ ]);
238
+ const virtualizer = useVirtualizer({
239
+ count: entries.length,
240
+ getScrollElement: ()=>scrollRef.current,
241
+ estimateSize: ()=>rowHeight,
242
+ measureElement: (element, entry)=>entry?.borderBoxSize?.[0]?.blockSize ?? element.getBoundingClientRect().height,
243
+ getItemKey,
244
+ overscan: overscanRows,
245
+ initialRect: {
246
+ width: scrollRef.current?.clientWidth ?? 0,
247
+ height: scrollRef.current?.clientHeight ?? 0
248
+ },
249
+ scrollMargin: headerHeight,
250
+ scrollPaddingStart: headerHeight,
251
+ rangeExtractor: (range)=>extractRange(range, pinnedIndexes, entries)
252
+ });
253
+ const virtualItems = stateKind ? [] : virtualizer.getVirtualItems();
254
+ const loadMore = useLoadMore({
255
+ enabled: serverMode && !awaitingNewRows,
256
+ loading,
257
+ loadedCount: rows.length,
258
+ lastRenderedIndex: (stateKind ? void 0 : entries[virtualizer.range?.endIndex ?? -1]?.rowIndex) ?? -1,
259
+ threshold: loadAheadViewports * rowsPerViewport,
260
+ hasMore,
261
+ loadingMore,
262
+ loadError,
263
+ onLoadMore
264
+ });
265
+ const bodyRows = [];
266
+ let renderedEnd = headerHeight;
267
+ for (const virtualItem of virtualItems){
268
+ const entry = entries[virtualItem.index];
269
+ if (!entry) continue;
270
+ if (virtualItem.start > renderedEnd) bodyRows.push(/*#__PURE__*/ jsx(GridSpacerRow, {
271
+ height: virtualItem.start - renderedEnd,
272
+ columnCount: columnCount
273
+ }, `gap-${virtualItem.index}`));
274
+ renderedEnd = virtualItem.end;
275
+ const { row } = entry;
276
+ if ('detail' === entry.kind) {
277
+ bodyRows.push(/*#__PURE__*/ jsx(GridDetailRow, {
278
+ entryIndex: virtualItem.index,
279
+ measureRef: virtualizer.measureElement,
280
+ columnCount: columnCount,
281
+ panelId: panelIdOf(row),
282
+ getCellProps: keyboard.getCellProps,
283
+ children: renderExpandedRow?.(row.original)
284
+ }, `detail:${row.id}`));
285
+ continue;
286
+ }
287
+ bodyRows.push(/*#__PURE__*/ jsx(GridRow, {
288
+ row: row,
289
+ entryIndex: virtualItem.index,
290
+ measureRef: virtualizer.measureElement,
291
+ density: density,
292
+ columnOffset: columnOffset,
293
+ highlighted: highlightedId === row.id,
294
+ clickable: rowsClickable,
295
+ checkbox: selecting ? {
296
+ label: resolvedLabels.selectRow(rowLabelOf(row)),
297
+ selected: row.getIsSelected(),
298
+ selectable: row.getCanSelect(),
299
+ onCheckedChange: ()=>selection.toggleRowFromCheckbox(row.id),
300
+ onClickCapture: selection.noteCheckboxClick,
301
+ onCellClick: (event)=>selection.toggleRow(row.id, {
302
+ range: event.shiftKey
303
+ })
304
+ } : void 0,
305
+ expander: expanding ? {
306
+ expandable: isExpandable(row.original),
307
+ expanded: entries[virtualItem.index + 1]?.kind === 'detail',
308
+ label: resolvedLabels.expandRow(rowLabelOf(row)),
309
+ panelId: panelIdOf(row),
310
+ onToggle: ()=>expansion.toggleRow(row.id)
311
+ } : void 0,
312
+ renderRowActions: renderRowActions,
313
+ getCellProps: keyboard.getCellProps,
314
+ onClick: (event)=>handleRowClick(row, event),
315
+ onDoubleClick: onRowDoubleClick ? (event)=>onRowDoubleClick(row.original, event) : void 0,
316
+ onContextMenu: onRowContextMenu ? (event)=>handleRowContextMenu(row, event) : void 0
317
+ }, row.id));
318
+ }
319
+ const bottomSpacerHeight = virtualItems.length ? virtualizer.getTotalSize() + headerHeight - renderedEnd : 0;
320
+ const scrollStyle = {
321
+ maxHeight: maxHeight && !fill ? maxHeight : void 0,
322
+ scrollPaddingBlockStart: headerHeight || void 0
323
+ };
324
+ const errorRowIndex = entries.length + 2;
325
+ const knownRowCount = serverMode && void 0 !== totalRowCount ? Math.max(totalRowCount, rows.length) : rows.length;
326
+ let ariaRowCount = Math.max(knownRowCount + openPanelCount + 1, showsLoadError ? errorRowIndex : 0);
327
+ if (serverMode && void 0 === totalRowCount && hasMore) ariaRowCount = -1;
328
+ if (stateKind) ariaRowCount = 2;
329
+ let stateLabel = '';
330
+ if ('loading' === stateKind) stateLabel = resolvedLabels.loading;
331
+ if ('empty' === stateKind) stateLabel = resolvedLabels.empty;
332
+ return /*#__PURE__*/ jsxs("section", {
333
+ className: fill ? `${DataGrid_module.card} ${DataGrid_module.fill}` : DataGrid_module.card,
334
+ "aria-labelledby": headingId,
335
+ children: [
336
+ /*#__PURE__*/ jsx(GridCardHeader, {
337
+ heading: heading,
338
+ headingLevel: headingLevel,
339
+ headingId: headingId,
340
+ actions: actions,
341
+ onRefresh: onRefresh,
342
+ refreshing: refreshing,
343
+ toolbarLabel: resolvedLabels.toolbar,
344
+ refreshLabel: resolvedLabels.refresh
345
+ }),
346
+ /*#__PURE__*/ jsx(LiveRegion, {
347
+ message: stateLabel,
348
+ politeness: "polite"
349
+ }),
350
+ /*#__PURE__*/ jsx("div", {
351
+ ref: scrollRef,
352
+ className: fill ? `${DataGrid_module.scroll} ${DataGrid_module.scrollFill}` : DataGrid_module.scroll,
353
+ style: scrollStyle,
354
+ "data-grid-scroll": "",
355
+ children: /*#__PURE__*/ jsxs("table", {
356
+ ref: keyboard.gridRef,
357
+ className: DataGrid_module.table,
358
+ role: "grid",
359
+ "aria-labelledby": headingId,
360
+ "aria-rowcount": ariaRowCount,
361
+ "aria-colcount": columnCount,
362
+ "aria-multiselectable": selecting || void 0,
363
+ "aria-busy": loading || void 0,
364
+ "data-density": density,
365
+ "data-rtl": rightToLeft ? '' : void 0,
366
+ onPointerDownCapture: forgetKeyboardContextMenu,
367
+ onKeyDownCapture: forgetKeyboardContextMenu,
368
+ onBlur: forgetKeyboardContextMenu,
369
+ children: [
370
+ /*#__PURE__*/ jsx("thead", {
371
+ ref: headRef,
372
+ className: DataGrid_module.head,
373
+ children: table.getHeaderGroups().map((headerGroup)=>/*#__PURE__*/ jsx(GridHeaderRow, {
374
+ headers: headerGroup.headers,
375
+ columnCount: columnCount,
376
+ columnOffset: columnOffset,
377
+ selectAll: selecting ? {
378
+ label: resolvedLabels.selectAll,
379
+ checked: selection.allSelected,
380
+ indeterminate: selection.someSelected,
381
+ disabled: !selection.canSelectAny,
382
+ onCheckedChange: selection.toggleAll
383
+ } : void 0,
384
+ expandLabel: expanding ? resolvedLabels.expandColumn : void 0,
385
+ rowActions: renderRowActions ? {
386
+ header: rowActionsHeader,
387
+ label: resolvedLabels.rowActions
388
+ } : void 0,
389
+ getCellProps: keyboard.getCellProps
390
+ }, headerGroup.id))
391
+ }),
392
+ /*#__PURE__*/ jsxs("tbody", {
393
+ children: [
394
+ stateKind ? /*#__PURE__*/ jsx(GridStateRow, {
395
+ kind: stateKind,
396
+ label: stateLabel,
397
+ emptyState: emptyState,
398
+ columnCount: columnCount
399
+ }) : null,
400
+ bodyRows,
401
+ bottomSpacerHeight > 0 ? /*#__PURE__*/ jsx(GridSpacerRow, {
402
+ height: bottomSpacerHeight,
403
+ columnCount: columnCount
404
+ }) : null,
405
+ showsLoadError ? /*#__PURE__*/ jsx(GridErrorRow, {
406
+ entryIndex: entries.length,
407
+ columnCount: columnCount,
408
+ message: loadError,
409
+ retryLabel: resolvedLabels.retry,
410
+ onRetry: loadMore.retry,
411
+ getCellProps: keyboard.getCellProps
412
+ }) : null
413
+ ]
414
+ })
415
+ ]
416
+ })
417
+ }),
418
+ hideFooter ? null : /*#__PURE__*/ jsxs("footer", {
419
+ className: DataGrid_module.footer,
420
+ children: [
421
+ selection.selectedIds.size > 0 ? /*#__PURE__*/ jsx("span", {
422
+ children: resolvedLabels.selectedCount(selection.selectedIds.size)
423
+ }) : null,
424
+ serverMode && loadingMore ? /*#__PURE__*/ jsx("span", {
425
+ children: resolvedLabels.loadingMore
426
+ }) : null,
427
+ /*#__PURE__*/ jsx("span", {
428
+ className: DataGrid_module.rowCount,
429
+ children: serverMode && void 0 !== totalRowCount ? resolvedLabels.loadedRowCount(rows.length, totalRowCount) : resolvedLabels.rowCount(rows.length)
430
+ })
431
+ ]
432
+ })
433
+ ]
434
+ });
435
+ }
436
+ export { DataGrid };