@calcifer-design/ui 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Alert/Alert.d.ts +5 -2
- package/dist/components/Alert/Alert.js +1 -0
- package/dist/components/Alert/Alert.module.js +5 -5
- package/dist/components/Alert/Alert_module.css +20 -17
- package/dist/components/Avatar/Avatar.d.ts +16 -2
- package/dist/components/Avatar/Avatar.js +23 -7
- package/dist/components/Avatar/Avatar.module.js +3 -3
- package/dist/components/Avatar/Avatar_module.css +58 -17
- package/dist/components/Avatar/avatarColor.d.ts +12 -0
- package/dist/components/Avatar/avatarColor.js +12 -0
- package/dist/components/AvatarGroup/AvatarGroup.d.ts +37 -0
- package/dist/components/AvatarGroup/AvatarGroup.js +52 -0
- package/dist/components/AvatarGroup/AvatarGroup.module.js +8 -0
- package/dist/components/AvatarGroup/AvatarGroup_module.css +67 -0
- package/dist/components/Breadcrumb/Breadcrumb.module.js +6 -6
- package/dist/components/Breadcrumb/Breadcrumb_module.css +7 -7
- package/dist/components/Button/Button.d.ts +40 -4
- package/dist/components/Button/Button.js +48 -11
- package/dist/components/Button/Button.module.js +6 -2
- package/dist/components/Button/Button_module.css +143 -17
- package/dist/components/Button/LinkButton.d.ts +10 -3
- package/dist/components/Button/LinkButton.js +16 -5
- package/dist/components/Card/Card.module.js +5 -5
- package/dist/components/Card/Card_module.css +15 -9
- package/dist/components/CardList/CardList.module.js +3 -3
- package/dist/components/CardList/CardList_module.css +5 -3
- package/dist/components/Checkbox/Checkbox.module.js +2 -2
- package/dist/components/Checkbox/Checkbox_module.css +3 -3
- package/dist/components/ChoiceCard/ChoiceCard.d.ts +34 -0
- package/dist/components/ChoiceCard/ChoiceCard.js +81 -0
- package/dist/components/ChoiceCard/ChoiceCard.module.js +12 -0
- package/dist/components/ChoiceCard/ChoiceCard_module.css +161 -0
- package/dist/components/Collapsible/Collapsible.d.ts +39 -0
- package/dist/components/Collapsible/Collapsible.js +63 -0
- package/dist/components/Collapsible/Collapsible.module.js +10 -0
- package/dist/components/Collapsible/Collapsible_module.css +80 -0
- package/dist/components/DataGrid/DataGrid.d.ts +3 -0
- package/dist/components/DataGrid/DataGrid.js +436 -0
- package/dist/components/DataGrid/DataGrid.module.js +36 -0
- package/dist/components/DataGrid/DataGrid_module.css +372 -0
- package/dist/components/DataGrid/GridCardHeader.d.ts +16 -0
- package/dist/components/DataGrid/GridCardHeader.js +40 -0
- package/dist/components/DataGrid/GridCheckbox.d.ts +15 -0
- package/dist/components/DataGrid/GridCheckbox.js +25 -0
- package/dist/components/DataGrid/GridHeaderCell.d.ts +14 -0
- package/dist/components/DataGrid/GridHeaderCell.js +29 -0
- package/dist/components/DataGrid/GridHeaderRow.d.ts +35 -0
- package/dist/components/DataGrid/GridHeaderRow.js +56 -0
- package/dist/components/DataGrid/GridRow.d.ts +69 -0
- package/dist/components/DataGrid/GridRow.js +139 -0
- package/dist/components/DataGrid/GridStateRows.d.ts +24 -0
- package/dist/components/DataGrid/GridStateRows.js +59 -0
- package/dist/components/DataGrid/columns.d.ts +40 -0
- package/dist/components/DataGrid/columns.js +37 -0
- package/dist/components/DataGrid/labels.d.ts +20 -0
- package/dist/components/DataGrid/labels.js +25 -0
- package/dist/components/DataGrid/types.d.ts +88 -0
- package/dist/components/DataGrid/types.js +0 -0
- package/dist/components/DataGrid/useGridEntries.d.ts +17 -0
- package/dist/components/DataGrid/useGridEntries.js +40 -0
- package/dist/components/DataGrid/useGridHighlight.d.ts +16 -0
- package/dist/components/DataGrid/useGridHighlight.js +24 -0
- package/dist/components/DataGrid/useGridKeyboard.d.ts +50 -0
- package/dist/components/DataGrid/useGridKeyboard.js +242 -0
- package/dist/components/DataGrid/useGridMetrics.d.ts +13 -0
- package/dist/components/DataGrid/useGridMetrics.js +35 -0
- package/dist/components/DataGrid/useLatest.d.ts +7 -0
- package/dist/components/DataGrid/useLatest.js +9 -0
- package/dist/components/DataGrid/useLoadMore.d.ts +30 -0
- package/dist/components/DataGrid/useLoadMore.js +39 -0
- package/dist/components/DataGrid/useRowExpansion.d.ts +14 -0
- package/dist/components/DataGrid/useRowExpansion.js +21 -0
- package/dist/components/DataGrid/useRowSelection.d.ts +43 -0
- package/dist/components/DataGrid/useRowSelection.js +107 -0
- package/dist/components/DataTable/DataTable.module.js +9 -9
- package/dist/components/DataTable/DataTable_module.css +24 -21
- package/dist/components/DatePicker/DatePicker.d.ts +15 -1
- package/dist/components/DatePicker/DatePicker.js +30 -5
- package/dist/components/DatePicker/DatePicker.module.js +10 -10
- package/dist/components/DatePicker/DatePicker_module.css +22 -21
- package/dist/components/Descriptions/Descriptions.module.js +4 -4
- package/dist/components/Descriptions/Descriptions_module.css +12 -8
- package/dist/components/Dialog/Dialog.d.ts +30 -2
- package/dist/components/Dialog/Dialog.js +52 -11
- package/dist/components/Dialog/Dialog.module.js +8 -6
- package/dist/components/Dialog/Dialog_module.css +60 -13
- package/dist/components/EmptyState/EmptyState.d.ts +41 -0
- package/dist/components/EmptyState/EmptyState.js +39 -0
- package/dist/components/EmptyState/EmptyState.module.js +9 -0
- package/dist/components/EmptyState/EmptyState_module.css +65 -0
- package/dist/components/ErrorBoundary/ErrorBoundary.d.ts +5 -2
- package/dist/components/ErrorBoundary/ErrorBoundary.module.js +1 -1
- package/dist/components/ErrorBoundary/ErrorBoundary_module.css +1 -1
- package/dist/components/Field/AffixInput.d.ts +28 -0
- package/dist/components/Field/AffixInput.js +50 -0
- package/dist/components/Field/GroupFrame.d.ts +19 -0
- package/dist/components/Field/GroupFrame.js +31 -0
- package/dist/components/Field/PickerField.d.ts +8 -2
- package/dist/components/Field/PickerField.js +12 -8
- package/dist/components/Field/PickerField.module.js +4 -4
- package/dist/components/Field/PickerField_module.css +11 -6
- package/dist/components/FilterBar/FilterBar.module.js +9 -9
- package/dist/components/FilterBar/FilterBar_module.css +13 -13
- package/dist/components/Form/Form.d.ts +9 -7
- package/dist/components/Form/Form.module.js +1 -1
- package/dist/components/Form/Form_module.css +1 -1
- package/dist/components/IconButton/IconButton.d.ts +1 -1
- package/dist/components/IconButton/IconButton.module.js +2 -2
- package/dist/components/IconButton/IconButton_module.css +28 -17
- package/dist/components/Menu/Menu.js +3 -0
- package/dist/components/Menu/Menu.module.js +2 -2
- package/dist/components/Menu/Menu_module.css +5 -4
- package/dist/components/NavMenu/NavMenu.d.ts +27 -4
- package/dist/components/NavMenu/NavMenu.js +10 -8
- package/dist/components/NavMenu/NavMenu.module.js +6 -6
- package/dist/components/NavMenu/NavMenu_module.css +37 -19
- package/dist/components/NavMenu/currentPath.d.ts +9 -0
- package/dist/components/NavMenu/currentPath.js +5 -0
- package/dist/components/PageHeading/PageHeading.module.js +3 -3
- package/dist/components/PageHeading/PageHeading_module.css +12 -9
- package/dist/components/PageShell/PageShell.module.js +5 -5
- package/dist/components/PageShell/PageShell_module.css +9 -9
- package/dist/components/Popover/Popover.js +3 -0
- package/dist/components/Popover/Popover.module.js +2 -2
- package/dist/components/Popover/Popover_module.css +6 -3
- package/dist/components/ProgressBar/ProgressBar.d.ts +55 -0
- package/dist/components/ProgressBar/ProgressBar.js +76 -0
- package/dist/components/ProgressBar/ProgressBar.module.js +12 -0
- package/dist/components/ProgressBar/ProgressBar_module.css +120 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +1 -1
- package/dist/components/RadioGroup/RadioGroup.js +35 -49
- package/dist/components/RadioGroup/RadioGroup.module.js +2 -2
- package/dist/components/RadioGroup/RadioGroup_module.css +2 -2
- package/dist/components/SearchField/SearchField.d.ts +32 -0
- package/dist/components/SearchField/SearchField.js +100 -0
- package/dist/components/SearchField/SearchField.module.js +8 -0
- package/dist/components/SearchField/SearchField_module.css +34 -0
- package/dist/components/Segmented/Segmented.d.ts +23 -6
- package/dist/components/Segmented/Segmented.js +37 -20
- package/dist/components/Segmented/Segmented.module.js +4 -3
- package/dist/components/Segmented/Segmented_module.css +46 -20
- package/dist/components/Select/Select.js +3 -0
- package/dist/components/Select/Select.module.js +5 -5
- package/dist/components/Select/Select_module.css +12 -11
- package/dist/components/Skeleton/Skeleton.module.js +3 -3
- package/dist/components/Skeleton/Skeleton_module.css +9 -9
- package/dist/components/SkipLink/SkipLink.module.js +1 -1
- package/dist/components/SkipLink/SkipLink_module.css +4 -4
- package/dist/components/Spinner/Spinner.module.js +3 -3
- package/dist/components/Spinner/Spinner_module.css +7 -7
- package/dist/components/StatusDot/StatusDot.module.js +5 -5
- package/dist/components/StatusDot/StatusDot_module.css +11 -11
- package/dist/components/Steps/Steps.module.js +6 -6
- package/dist/components/Steps/Steps_module.css +19 -19
- package/dist/components/Switch/Switch.module.js +2 -2
- package/dist/components/Switch/Switch_module.css +5 -5
- package/dist/components/TabBar/TabBar.d.ts +26 -0
- package/dist/components/TabBar/TabBar.js +52 -0
- package/dist/components/TabBar/TabBar.module.js +11 -0
- package/dist/components/TabBar/TabBar_module.css +100 -0
- package/dist/components/Tabs/Tabs.module.js +4 -4
- package/dist/components/Tabs/Tabs_module.css +9 -8
- package/dist/components/Tag/Tag.module.js +1 -1
- package/dist/components/Tag/Tag_module.css +3 -2
- package/dist/components/TextArea/TextArea.module.js +1 -1
- package/dist/components/TextArea/TextArea_module.css +6 -2
- package/dist/components/TextInput/TextInput.d.ts +14 -2
- package/dist/components/TextInput/TextInput.js +4 -5
- package/dist/components/ThemeScope/PortalContainerContext.d.ts +17 -0
- package/dist/components/ThemeScope/PortalContainerContext.js +6 -0
- package/dist/components/ThemeScope/ThemeScope.d.ts +23 -0
- package/dist/components/ThemeScope/ThemeScope.js +29 -0
- package/dist/components/ThemeScope/ThemeScope.module.js +6 -0
- package/dist/components/ThemeScope/ThemeScope_module.css +10 -0
- package/dist/components/TimePicker/TimePicker.d.ts +15 -2
- package/dist/components/TimePicker/TimePicker.js +5 -5
- package/dist/components/Timeline/Timeline.module.js +8 -8
- package/dist/components/Timeline/Timeline_module.css +15 -13
- package/dist/components/ToastRegion/ToastRegion.js +3 -0
- package/dist/components/ToastRegion/ToastRegion.module.js +6 -6
- package/dist/components/ToastRegion/ToastRegion_module.css +23 -19
- package/dist/components/ToggleChip/ToggleChip.d.ts +49 -0
- package/dist/components/ToggleChip/ToggleChip.js +45 -0
- package/dist/components/ToggleChip/ToggleChip.module.js +9 -0
- package/dist/components/ToggleChip/ToggleChipGroup.d.ts +57 -0
- package/dist/components/ToggleChip/ToggleChipGroup.js +93 -0
- package/dist/components/ToggleChip/ToggleChip_module.css +97 -0
- package/dist/components/Toolbar/Toolbar.module.js +3 -3
- package/dist/components/Toolbar/Toolbar_module.css +5 -5
- package/dist/components/Tooltip/Tooltip.js +3 -0
- package/dist/components/Tree/Tree.module.js +8 -8
- package/dist/components/Tree/Tree_module.css +20 -20
- package/dist/components/TreeSelect/TreeSelect.js +3 -0
- package/dist/components/TreeSelect/TreeSelect.module.js +3 -3
- package/dist/components/TreeSelect/TreeSelect_module.css +4 -4
- package/dist/components/Upload/Upload.module.js +8 -8
- package/dist/components/Upload/Upload_module.css +16 -16
- package/dist/components/ViewField/ViewField.module.js +2 -2
- package/dist/components/ViewField/ViewField_module.css +3 -3
- package/dist/hooks/useControllable.d.ts +11 -0
- package/dist/hooks/useControllable.js +13 -0
- package/dist/hooks/useIndexedToggleGroup.d.ts +30 -0
- package/dist/hooks/useIndexedToggleGroup.js +26 -0
- package/dist/hooks/useOverflowFocusable.d.ts +17 -0
- package/dist/hooks/useOverflowFocusable.js +36 -0
- package/dist/icons/ChevronRightIcon.d.ts +6 -0
- package/dist/icons/ChevronRightIcon.js +17 -0
- package/dist/icons/RefreshIcon.d.ts +6 -0
- package/dist/icons/RefreshIcon.js +22 -0
- package/dist/icons/SearchIcon.d.ts +9 -0
- package/dist/icons/SearchIcon.js +23 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +14 -0
- package/dist/styles/a11y.module.js +1 -1
- package/dist/styles/a11y_module.css +1 -1
- package/dist/styles/base.css +17 -0
- package/dist/styles/closeCircle.module.js +5 -0
- package/dist/styles/closeCircle_module.css +12 -0
- package/dist/styles/field.module.js +14 -11
- package/dist/styles/field_module.css +92 -23
- package/dist/styles/pair.module.js +2 -2
- package/dist/styles/pair_module.css +5 -3
- package/dist/styles/popup.module.js +5 -5
- package/dist/styles/popup_module.css +35 -28
- package/dist/utils/focusInputFromPill.d.ts +12 -0
- package/dist/utils/focusInputFromPill.js +7 -0
- package/dist/utils/hasContent.d.ts +8 -0
- package/dist/utils/hasContent.js +4 -0
- package/package.json +4 -3
|
@@ -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 };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "./DataGrid_module.css";
|
|
2
|
+
const DataGrid_module = {
|
|
3
|
+
card: "ui0-7-0-card-sKuGs",
|
|
4
|
+
header: "ui0-7-0-header-FnSmG",
|
|
5
|
+
heading: "ui0-7-0-heading-cO1_Q",
|
|
6
|
+
cluster: "ui0-7-0-cluster-FC5NS",
|
|
7
|
+
actions: "ui0-7-0-actions-_1Hpt",
|
|
8
|
+
scroll: "ui0-7-0-scroll-FzUQa",
|
|
9
|
+
fill: "ui0-7-0-fill-gnSOL",
|
|
10
|
+
scrollFill: "ui0-7-0-scrollFill-ouKju",
|
|
11
|
+
table: "ui0-7-0-table-sZLxO",
|
|
12
|
+
head: "ui0-7-0-head-z5Rnq",
|
|
13
|
+
headerCell: "ui0-7-0-headerCell-CgaE0",
|
|
14
|
+
sortIcon: "ui0-7-0-sortIcon-aw3qW",
|
|
15
|
+
row: "ui0-7-0-row-OLZkz",
|
|
16
|
+
cell: "ui0-7-0-cell-TYnuY",
|
|
17
|
+
pinnedHeader: "ui0-7-0-pinnedHeader-b7R5T",
|
|
18
|
+
pinnedCell: "ui0-7-0-pinnedCell-hktdQ",
|
|
19
|
+
selectHeader: "ui0-7-0-selectHeader-ysJFY",
|
|
20
|
+
selectCell: "ui0-7-0-selectCell-WkrzU",
|
|
21
|
+
expandHeader: "ui0-7-0-expandHeader-xZuaw",
|
|
22
|
+
expandCell: "ui0-7-0-expandCell-nB87K",
|
|
23
|
+
expandButton: "ui0-7-0-expandButton-gnwRu",
|
|
24
|
+
actionsHeader: "ui0-7-0-actionsHeader-DXNJS",
|
|
25
|
+
actionsCell: "ui0-7-0-actionsCell-XmWDR",
|
|
26
|
+
detailRow: "ui0-7-0-detailRow-WsOl1",
|
|
27
|
+
detailCell: "ui0-7-0-detailCell-y4qyE",
|
|
28
|
+
errorCell: "ui0-7-0-errorCell-m9Gxy",
|
|
29
|
+
errorContent: "ui0-7-0-errorContent-_tmon",
|
|
30
|
+
stateCell: "ui0-7-0-stateCell-_44Lv",
|
|
31
|
+
state: "ui0-7-0-state-WLbKa",
|
|
32
|
+
spacerCell: "ui0-7-0-spacerCell-IoOYY",
|
|
33
|
+
footer: "ui0-7-0-footer-pI1Q7",
|
|
34
|
+
rowCount: "ui0-7-0-rowCount-M_Nba"
|
|
35
|
+
};
|
|
36
|
+
export default DataGrid_module;
|