rift-ds 1.20.0 → 1.21.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import React, { useMemo, useState, useEffect, useRef, useId, useLayoutEffect, useCallback } from "react";
|
|
3
|
+
import React, { useMemo, useState, useEffect, useRef, useId, useLayoutEffect, useDeferredValue, useCallback } from "react";
|
|
4
4
|
import { useTable, tableFeatures, columnVisibilityFeature, columnPinningFeature, columnOrderingFeature, rowSelectionFeature, globalFilteringFeature, columnFilteringFeature, rowSortingFeature, createFilteredRowModel, createSortedRowModel } from "@tanstack/react-table";
|
|
5
5
|
import { DropdownMenu } from "../DropdownMenu/DropdownMenu.js";
|
|
6
6
|
import { Dropdown } from "../Dropdown/Dropdown.js";
|
|
@@ -125,6 +125,17 @@ const valueComparator = (collator) => (a, b) => {
|
|
|
125
125
|
if (typeof a === "boolean" && typeof b === "boolean") return Number(a) - Number(b);
|
|
126
126
|
return collator.compare(String(a), String(b));
|
|
127
127
|
};
|
|
128
|
+
const SEARCH_TEXT = /* @__PURE__ */ new WeakMap();
|
|
129
|
+
const searchTextOf = (rows, row) => {
|
|
130
|
+
let texts = SEARCH_TEXT.get(rows);
|
|
131
|
+
if (!texts) SEARCH_TEXT.set(rows, texts = /* @__PURE__ */ new WeakMap());
|
|
132
|
+
let text = texts.get(row);
|
|
133
|
+
if (text === void 0) {
|
|
134
|
+
text = Object.values(row.values).filter((cell) => cell != null).map(String).join("\0").toLowerCase();
|
|
135
|
+
texts.set(row, text);
|
|
136
|
+
}
|
|
137
|
+
return text;
|
|
138
|
+
};
|
|
128
139
|
const ENGINE_FEATURES = tableFeatures({
|
|
129
140
|
rowSortingFeature,
|
|
130
141
|
sortedRowModel: createSortedRowModel(),
|
|
@@ -503,7 +514,7 @@ function DataTable({
|
|
|
503
514
|
}),
|
|
504
515
|
[columnKeys, compareValues]
|
|
505
516
|
);
|
|
506
|
-
const needle = search.trim().toLowerCase();
|
|
517
|
+
const needle = useDeferredValue(search.trim().toLowerCase());
|
|
507
518
|
const sortingKey = JSON.stringify(
|
|
508
519
|
currentSorts.filter((entry) => byKey.has(entry.key)).map((entry) => ({ id: entry.key, desc: entry.direction === "desc" }))
|
|
509
520
|
);
|
|
@@ -540,18 +551,21 @@ function DataTable({
|
|
|
540
551
|
rowSelection: engineSelection
|
|
541
552
|
},
|
|
542
553
|
/* The search matches any raw value on the row, displayed or not, case
|
|
543
|
-
insensitively, as it always has:
|
|
544
|
-
|
|
545
|
-
|
|
554
|
+
insensitively, as it always has: the test reads the whole row, so it
|
|
555
|
+
runs once, from one column. The engine asks once per eligible column
|
|
556
|
+
until one passes, so with every column eligible a row that does not
|
|
557
|
+
match reads all its values once per column. */
|
|
558
|
+
getColumnCanGlobalFilter: (column) => column.id === columns[0]?.key,
|
|
546
559
|
globalFilterFn: (row, _columnId, value) => {
|
|
547
|
-
|
|
548
|
-
return
|
|
549
|
-
(cell) => cell != null && String(cell).toLowerCase().includes(term)
|
|
550
|
-
);
|
|
560
|
+
if (row.columnFilters && Object.values(row.columnFilters).includes(false)) return false;
|
|
561
|
+
return searchTextOf(rows, row.original).includes(String(value ?? ""));
|
|
551
562
|
}
|
|
552
563
|
});
|
|
553
564
|
const engineRows = table.getSortedRowModel().rows;
|
|
554
|
-
const sortedRows =
|
|
565
|
+
const sortedRows = useMemo(
|
|
566
|
+
() => manual ? orderedRows : engineRows.map((row) => row.original),
|
|
567
|
+
[manual, orderedRows, engineRows]
|
|
568
|
+
);
|
|
555
569
|
const matchCount = manual ? Math.max(rowCountProp ?? rows.length, rows.length) : sortedRows.length;
|
|
556
570
|
const groupKey = groupingState.find((key) => byKey.get(key)?.groupable);
|
|
557
571
|
const groupCol = groupKey ? byKey.get(groupKey) : void 0;
|
|
@@ -597,7 +611,7 @@ function DataTable({
|
|
|
597
611
|
return;
|
|
598
612
|
}
|
|
599
613
|
announce(resultsLabel(matchCount), true);
|
|
600
|
-
}, [
|
|
614
|
+
}, [needle]);
|
|
601
615
|
const filtered = useRef(false);
|
|
602
616
|
const filtersKey = JSON.stringify(filters);
|
|
603
617
|
useEffect(() => {
|
|
@@ -615,7 +629,8 @@ function DataTable({
|
|
|
615
629
|
announce(pageAnnouncement(next, pageCount, first, last, matchCount));
|
|
616
630
|
};
|
|
617
631
|
const visibleIds = visibleRows.map((row) => row.id);
|
|
618
|
-
const
|
|
632
|
+
const selectedSet = new Set(currentSelection);
|
|
633
|
+
const selectedVisible = visibleIds.filter((id) => selectedSet.has(id));
|
|
619
634
|
const allVisibleSelected = visibleIds.length > 0 && selectedVisible.length === visibleIds.length;
|
|
620
635
|
const someVisibleSelected = selectedVisible.length > 0 && !allVisibleSelected;
|
|
621
636
|
const toggleAllVisible = (checked) => {
|
|
@@ -979,14 +994,29 @@ function DataTable({
|
|
|
979
994
|
}
|
|
980
995
|
});
|
|
981
996
|
};
|
|
997
|
+
const columnScanKey = columns.map((col) => [col.key, col.type ?? "", col.options ? "1" : ""].join("")).join("\0");
|
|
998
|
+
const columnScans = useMemo(() => {
|
|
999
|
+
const scans = /* @__PURE__ */ new Map();
|
|
1000
|
+
for (const spec of columnScanKey.split("\0")) {
|
|
1001
|
+
const [key, type, hasOptions] = spec.split("");
|
|
1002
|
+
const typedKind = type ? TYPE_DEFAULTS[type].filter : void 0;
|
|
1003
|
+
if (typedKind && (hasOptions || typedKind !== "enum" && typedKind !== "tags")) {
|
|
1004
|
+
scans.set(key, { kind: typedKind, choices: [] });
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
const values = rows.map((row) => row.values[key]);
|
|
1008
|
+
const kind = typedKind ?? kindOf(values, Boolean(hasOptions));
|
|
1009
|
+
const choices = !hasOptions && (kind === "enum" || kind === "tags") ? [
|
|
1010
|
+
...new Set(
|
|
1011
|
+
values.flat().filter((value) => value != null && value !== "").map(String)
|
|
1012
|
+
)
|
|
1013
|
+
].sort((a, b) => collator.compare(a, b)).map((value) => ({ value, label: value })) : [];
|
|
1014
|
+
scans.set(key, { kind, choices });
|
|
1015
|
+
}
|
|
1016
|
+
return scans;
|
|
1017
|
+
}, [columnScanKey, rows, collator]);
|
|
982
1018
|
const toolbarColumns = columns.map((col) => {
|
|
983
|
-
const
|
|
984
|
-
const kind = col.type ? TYPE_DEFAULTS[col.type].filter : kindOf(values, Boolean(col.options));
|
|
985
|
-
const choices = col.options ?? (kind === "enum" || kind === "tags" ? [
|
|
986
|
-
...new Set(
|
|
987
|
-
values.flat().filter((value) => value != null && value !== "").map(String)
|
|
988
|
-
)
|
|
989
|
-
].sort((a, b) => collator.compare(a, b)).map((value) => ({ value, label: value })) : []);
|
|
1019
|
+
const { kind, choices } = columnScans.get(col.key);
|
|
990
1020
|
return {
|
|
991
1021
|
key: col.key,
|
|
992
1022
|
label: headerText(col),
|
|
@@ -997,12 +1027,13 @@ function DataTable({
|
|
|
997
1027
|
sortable: Boolean(col.sortable),
|
|
998
1028
|
groupable: Boolean(col.groupable),
|
|
999
1029
|
kind,
|
|
1000
|
-
options: choices
|
|
1030
|
+
options: col.options ?? choices
|
|
1001
1031
|
};
|
|
1002
1032
|
});
|
|
1003
1033
|
const [headerFilter, setHeaderFilter] = useState(null);
|
|
1004
1034
|
const [countClaimed, setCountClaimed] = useState(false);
|
|
1005
1035
|
const [selectionClaimed, setSelectionClaimed] = useState(false);
|
|
1036
|
+
const [commandLanding, setCommandLanding] = useState(false);
|
|
1006
1037
|
const openHeaderFilter = (key) => {
|
|
1007
1038
|
const existing = filters.find((filter2) => filter2.column === key);
|
|
1008
1039
|
if (existing) {
|
|
@@ -1089,6 +1120,7 @@ function DataTable({
|
|
|
1089
1120
|
reportedKey.current = currentKey;
|
|
1090
1121
|
viewCallback.current?.(JSON.parse(JSON.stringify(currentView)));
|
|
1091
1122
|
}, [currentKey]);
|
|
1123
|
+
const matchingIds = useMemo(() => sortedRows.map((row) => row.id), [sortedRows]);
|
|
1092
1124
|
const tableContext = {
|
|
1093
1125
|
columns: toolbarColumns,
|
|
1094
1126
|
filters,
|
|
@@ -1102,7 +1134,7 @@ function DataTable({
|
|
|
1102
1134
|
selectable,
|
|
1103
1135
|
selectedIds: currentSelection,
|
|
1104
1136
|
setSelectedIds: setSelection,
|
|
1105
|
-
matchingIds
|
|
1137
|
+
matchingIds,
|
|
1106
1138
|
size,
|
|
1107
1139
|
setSize,
|
|
1108
1140
|
shown: matchCount,
|
|
@@ -1122,7 +1154,8 @@ function DataTable({
|
|
|
1122
1154
|
setAllGroupsOpen: (open) => setCollapsedGroups(open ? [] : (groups ?? []).map((group) => group.key)),
|
|
1123
1155
|
view: currentView,
|
|
1124
1156
|
applyView,
|
|
1125
|
-
viewMatches: (view) => viewKey(fullView(view)) === currentKey
|
|
1157
|
+
viewMatches: (view) => viewKey(fullView(view)) === currentKey,
|
|
1158
|
+
setCommandLanding
|
|
1126
1159
|
};
|
|
1127
1160
|
const [menuKey, setMenuKey] = useState(null);
|
|
1128
1161
|
const menuItems = (key) => {
|
|
@@ -1727,6 +1760,7 @@ function DataTable({
|
|
|
1727
1760
|
loadMore.current = onLoadMore;
|
|
1728
1761
|
});
|
|
1729
1762
|
const rowCount = visibleRows.length;
|
|
1763
|
+
const pageRowSet = new Set(pageRows);
|
|
1730
1764
|
const scrollsInFrame = virtual || maxHeight !== void 0;
|
|
1731
1765
|
useEffect(() => {
|
|
1732
1766
|
const node = loadingRef.current;
|
|
@@ -1748,7 +1782,7 @@ function DataTable({
|
|
|
1748
1782
|
const expanded = !collapsedGroups.includes(group.key);
|
|
1749
1783
|
const label = groupLabel(group.key);
|
|
1750
1784
|
const ids = group.rows.map((row) => row.id);
|
|
1751
|
-
const chosen = ids.filter((id) =>
|
|
1785
|
+
const chosen = ids.filter((id) => selectedSet.has(id)).length;
|
|
1752
1786
|
const raw = group.rows[0]?.values[groupKey] ?? null;
|
|
1753
1787
|
return /* @__PURE__ */ jsxs("tr", { className: `ds-table__row ${baseClass}__group-row`, "data-group-row": "", children: [
|
|
1754
1788
|
utilityKeys.map((key) => {
|
|
@@ -1839,7 +1873,7 @@ function DataTable({
|
|
|
1839
1873
|
visibleKeys.map((key) => {
|
|
1840
1874
|
const col = byKey.get(key);
|
|
1841
1875
|
const pick = totalPick(col);
|
|
1842
|
-
const values = sortedRows.map((row) => row.values[key]);
|
|
1876
|
+
const values = pick === "none" ? [] : sortedRows.map((row) => row.values[key]);
|
|
1843
1877
|
const text = pick === "none" ? "" : typeof col.aggregate === "function" && !totalsState[key] ? col.aggregate(values, sortedRows) : resultText(col, calculate(pick, values));
|
|
1844
1878
|
const offered = TOTALS.filter((total) => !NUMERIC_TOTALS.has(total) || numericColumn(col));
|
|
1845
1879
|
return /* @__PURE__ */ jsx(
|
|
@@ -1887,7 +1921,7 @@ function DataTable({
|
|
|
1887
1921
|
] }) });
|
|
1888
1922
|
const columnCount = utilityKeys.length + visibleKeys.length + (layoutReady ? 1 : 0) + (showActions ? 1 : 0);
|
|
1889
1923
|
const bodyRow = (row, slot, part = "both") => {
|
|
1890
|
-
const isSelected = selectable &&
|
|
1924
|
+
const isSelected = selectable && selectedSet.has(row.id);
|
|
1891
1925
|
const name = rowName(row);
|
|
1892
1926
|
const expandedHere = Boolean(renderDetail) && expandedState.includes(row.id);
|
|
1893
1927
|
const detailId = `${tableId}-detail-${row.id}`;
|
|
@@ -2244,8 +2278,9 @@ function DataTable({
|
|
|
2244
2278
|
/* @__PURE__ */ jsx(Spinner, { size: "sm", tone: "neutral" }),
|
|
2245
2279
|
/* @__PURE__ */ jsx("span", { children: loadWords.loadingMore })
|
|
2246
2280
|
] }) }) });
|
|
2247
|
-
const firstLoad = loading && rows.length === 0 && !error;
|
|
2281
|
+
const firstLoad = (loading && rows.length === 0 || commandLanding) && !error;
|
|
2248
2282
|
const refreshing = loading && rows.length > 0;
|
|
2283
|
+
const searching = !manual && rows.length > 0 && search.trim().toLowerCase() !== needle;
|
|
2249
2284
|
const retryButton = onRetry && /* @__PURE__ */ jsx(Button, { variant: "secondary", tone: "neutral", size: "compact", iconLeft: "refresh", label: loadWords.retry, onClick: onRetry });
|
|
2250
2285
|
const skeletonRows = Array.from({ length: pageSize ?? 5 }, (_, index) => /* @__PURE__ */ jsxs("tr", { className: `ds-table__row ${baseClass}__skeleton-row`, "aria-hidden": "true", children: [
|
|
2251
2286
|
utilityKeys.map((key) => /* @__PURE__ */ jsx("td", { className: "ds-table__cell" }, key)),
|
|
@@ -2292,12 +2327,12 @@ function DataTable({
|
|
|
2292
2327
|
error && rows.length > 0 && /* @__PURE__ */ jsx(Banner, { variant: "error", title: loadWords.errorTitle, action: retryButton || void 0, className: `${baseClass}__banner`, children: error }),
|
|
2293
2328
|
firstLoad && /* @__PURE__ */ jsx("span", { className: "ds-visually-hidden", role: "status", children: loadWords.loading }),
|
|
2294
2329
|
visibleRows.length > 0 || firstLoad ? /* @__PURE__ */ jsxs(ScrollRegion, { className: `ds-table__wrapper ${baseClass}__frame`, style: frameStyle, onNode: setFrameEl, children: [
|
|
2295
|
-
refreshing && /* @__PURE__ */ jsx("div", { className: `${baseClass}__progress`, role: "progressbar", "aria-label": loadWords.loading }),
|
|
2330
|
+
(refreshing || searching) && /* @__PURE__ */ jsx("div", { className: `${baseClass}__progress`, role: "progressbar", "aria-label": loadWords.loading }),
|
|
2296
2331
|
/* @__PURE__ */ jsxs(
|
|
2297
2332
|
"table",
|
|
2298
2333
|
{
|
|
2299
2334
|
ref: setTableEl,
|
|
2300
|
-
"aria-busy": loading || void 0,
|
|
2335
|
+
"aria-busy": loading || commandLanding || searching || void 0,
|
|
2301
2336
|
className: tableClasses,
|
|
2302
2337
|
role: gridMode ? "grid" : stacked ? "table" : void 0,
|
|
2303
2338
|
"aria-rowcount": virtual ? virtualItems.length + 1 : void 0,
|
|
@@ -2332,7 +2367,7 @@ function DataTable({
|
|
|
2332
2367
|
}
|
|
2333
2368
|
)
|
|
2334
2369
|
] }) }),
|
|
2335
|
-
firstLoad ? /* @__PURE__ */ jsx("tbody", { className: "ds-table__body", children: skeletonRows }) : groups ? groups.map((group) => ({ group, onPage: group.rows.filter((row) =>
|
|
2370
|
+
firstLoad ? /* @__PURE__ */ jsx("tbody", { className: "ds-table__body", children: skeletonRows }) : groups ? groups.map((group) => ({ group, onPage: group.rows.filter((row) => pageRowSet.has(row)) })).filter(({ onPage }) => onPage.length > 0).map(({ group, onPage }) => /* @__PURE__ */ jsxs(
|
|
2336
2371
|
"tbody",
|
|
2337
2372
|
{
|
|
2338
2373
|
className: `ds-table__body ${baseClass}__group`,
|
|
@@ -76,6 +76,8 @@ export interface TableContextValue {
|
|
|
76
76
|
view: TableView;
|
|
77
77
|
applyView: (view: TableView) => void;
|
|
78
78
|
viewMatches: (view: TableView) => boolean;
|
|
79
|
+
/** Draws skeleton rows in the body while a toolbar command's answer lands. */
|
|
80
|
+
setCommandLanding: (landing: boolean) => void;
|
|
79
81
|
}
|
|
80
82
|
export declare const TableContext: import('react').Context<TableContextValue | null>;
|
|
81
83
|
/** The surrounding DataTable's state, or null outside one. */
|
|
@@ -24,7 +24,7 @@ import { parseDate, absoluteDate } from "../DataTable/columnTypes.js";
|
|
|
24
24
|
import "../../behaviors/visually-hidden.css";
|
|
25
25
|
import { DEFAULT_FILTER_LABELS, isComplete, VALUELESS, OPERATORS, valueText, newFilterId } from "../DataTable/filterModel.js";
|
|
26
26
|
import { useTableContext } from "../DataTable/tableContext.js";
|
|
27
|
-
import { MOTION_ACTION_DISMISS_MS } from "../../tokens/motion.js";
|
|
27
|
+
import { MOTION_TABLE_COMMAND_SKELETON_MS, MOTION_ACTION_DISMISS_MS } from "../../tokens/motion.js";
|
|
28
28
|
import { BREAKPOINT_PHONE_PX, BREAKPOINT_SHEET_PX, mediaBelow } from "../../tokens/breakpoints.js";
|
|
29
29
|
import "./TableToolbar.css";
|
|
30
30
|
import { mirrorClass } from "../../behaviors/direction.js";
|
|
@@ -183,7 +183,11 @@ function CommandRow({ command, table, labels, size, open, onClose, state, onStat
|
|
|
183
183
|
if (running.signal.aborted) return;
|
|
184
184
|
const changed = Boolean(result.view) && JSON.stringify(result.view) !== JSON.stringify(before);
|
|
185
185
|
if (changed) {
|
|
186
|
+
latestTable.current.setCommandLanding(true);
|
|
186
187
|
latestTable.current.applyView(result.view);
|
|
188
|
+
await new Promise((resolve) => setTimeout(resolve, MOTION_TABLE_COMMAND_SKELETON_MS));
|
|
189
|
+
latestTable.current.setCommandLanding(false);
|
|
190
|
+
if (running.signal.aborted) return;
|
|
187
191
|
const id = `table-command-${Date.now()}`;
|
|
188
192
|
report({
|
|
189
193
|
id,
|
|
@@ -639,7 +643,8 @@ const TableToolbar = React.forwardRef(
|
|
|
639
643
|
const commandTrigger = narrow ? /* @__PURE__ */ jsx(Tooltip, { content: labels.command, children: commandButtonDrawn }) : commandButtonDrawn;
|
|
640
644
|
const matching = table?.matchingIds ?? [];
|
|
641
645
|
const matchingCount = table?.matchingCount ?? matching.length;
|
|
642
|
-
const
|
|
646
|
+
const selectedSet = new Set(table?.selectedIds);
|
|
647
|
+
const allMatching = table?.allMatching ?? (matching.length > 0 && matching.every((id) => selectedSet.has(id)));
|
|
643
648
|
const selection = {
|
|
644
649
|
ids: table?.selectedIds ?? [],
|
|
645
650
|
allMatching,
|
package/package.json
CHANGED
package/tokens/motion.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export declare const MOTION_HOVER_HIDE_DELAY_MS = 150;
|
|
|
20
20
|
export declare const MOTION_AUTO_DISMISS_MS = 5000;
|
|
21
21
|
/** How long a notification carrying an action, such as an Undo, stays before dismissing itself: time to read it and decide. */
|
|
22
22
|
export declare const MOTION_ACTION_DISMISS_MS = 10000;
|
|
23
|
+
/** How long a table draws skeleton rows as an AI command's answer lands, so the change reads as a change before its result is reported. */
|
|
24
|
+
export declare const MOTION_TABLE_COMMAND_SKELETON_MS = 700;
|
|
23
25
|
/** How long an exiting element's unmount waits for its CSS exit animation — mirrors --motion-duration-base. */
|
|
24
26
|
export declare const MOTION_EXIT_SYNC_MS = 200;
|
|
25
27
|
/** Interval between automatic slide advances. */
|
package/tokens/motion.js
CHANGED
|
@@ -2,6 +2,7 @@ const MOTION_HOVER_SHOW_DELAY_MS = 300;
|
|
|
2
2
|
const MOTION_HOVER_HIDE_DELAY_MS = 150;
|
|
3
3
|
const MOTION_AUTO_DISMISS_MS = 5e3;
|
|
4
4
|
const MOTION_ACTION_DISMISS_MS = 1e4;
|
|
5
|
+
const MOTION_TABLE_COMMAND_SKELETON_MS = 700;
|
|
5
6
|
const MOTION_EXIT_SYNC_MS = 200;
|
|
6
7
|
const MOTION_AUTOPLAY_INTERVAL_MS = 5e3;
|
|
7
8
|
const MOTION_FEEDBACK_RESET_MS = 2e3;
|
|
@@ -49,6 +50,7 @@ export {
|
|
|
49
50
|
MOTION_SUGGESTIONS_THINK_MS,
|
|
50
51
|
MOTION_SUMMARY_REVEAL_MS,
|
|
51
52
|
MOTION_SUMMARY_THINK_MS,
|
|
53
|
+
MOTION_TABLE_COMMAND_SKELETON_MS,
|
|
52
54
|
MOTION_THREAD_NAMING_DELAY_MS,
|
|
53
55
|
MOTION_TOKEN_REREAD_MS
|
|
54
56
|
};
|