@galaxy-io/dls 2.12.3 → 2.13.1
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/inputs/ToggleInput.js +11 -3
- package/dist/styles.css +1 -1
- package/dist/table/InfiniteTable.d.ts +3 -1
- package/dist/table/InfiniteTable.js +6 -3
- package/dist/table/TableCore.d.ts +2 -0
- package/dist/table/TableCore.js +29 -4
- package/dist/table/VirtualizedInfiniteTable.js +1 -0
- package/dist/table/useTableRowSelection.d.ts +8 -4
- package/dist/table/useTableRowSelection.js +25 -16
- package/package.json +1 -1
|
@@ -40,7 +40,7 @@ interface InfiniteTableBaseProps<TData> extends AriaAttributes {
|
|
|
40
40
|
emptyState?: ReactNode;
|
|
41
41
|
/** Called when the last row comes within 500px of view, for loading the next page; called again only after `data` grows. Setting it also makes sorting server-side. */
|
|
42
42
|
onEndReached?: () => void;
|
|
43
|
-
/** Called when a row is clicked or Enter is pressed on it. Not called for clicks on a control inside the row. */
|
|
43
|
+
/** Called when a row is clicked or Enter is pressed on it. Not called for clicks on a control inside the row: a native control or an element with an interactive role (`combobox`, `switch`, `menuitem`, …). */
|
|
44
44
|
onRowClick?: (row: TData, event: MouseEvent<HTMLTableRowElement> | KeyboardEvent<HTMLTableRowElement>) => void;
|
|
45
45
|
/** Id of the row shown as current, such as the one open in a side panel. Display only: set it from `onRowClick`. */
|
|
46
46
|
activeRowId?: string | null;
|
|
@@ -60,6 +60,8 @@ interface InfiniteTableBaseProps<TData> extends AriaAttributes {
|
|
|
60
60
|
defaultValue?: string[];
|
|
61
61
|
/** Called with the new list of selected row ids, in row order. */
|
|
62
62
|
onChange?: (value: string[]) => void;
|
|
63
|
+
/** Return `false` for a row whose selection cannot change: its checkbox is disabled and select-all, Space and Shift ranges skip it. Every row can change when unset. */
|
|
64
|
+
canSelectRow?: (row: TData) => boolean;
|
|
63
65
|
/** Content of a row's expanded panel, shown under it. Adds a leading caret column. Return `null` for rows that cannot expand. Called for every rendered row, so keep it cheap. */
|
|
64
66
|
renderExpandedRow?: (row: TData) => ReactNode | null;
|
|
65
67
|
/** Controlled expanded row ids. */
|
|
@@ -52,7 +52,7 @@ function splitPassthrough(rest) {
|
|
|
52
52
|
}
|
|
53
53
|
/** The read-only data table. */
|
|
54
54
|
var InfiniteTableInner = forwardRef(function InfiniteTable(props, ref) {
|
|
55
|
-
const { columns, data, getRowId, size: sizeProp, isLoading: isLoadingProp, error: errorProp, emptyState, onEndReached, onRowClick, activeRowId, rowActions, sort, defaultSort, onSortChange, isSelectable: isSelectableProp, value, defaultValue, onChange, renderExpandedRow, expandedIds, defaultExpandedIds, onExpandedIdsChange, columnLayout, defaultColumnLayout, onColumnLayoutChange, canResizeColumns: canResizeColumnsProp, canCustomizeColumns: canCustomizeColumnsProp, hasHeader = true, inset: insetProp, ariaLabel, id, className, style, ...rest } = props;
|
|
55
|
+
const { columns, data, getRowId, size: sizeProp, isLoading: isLoadingProp, error: errorProp, emptyState, onEndReached, onRowClick, activeRowId, rowActions, sort, defaultSort, onSortChange, isSelectable: isSelectableProp, value, defaultValue, onChange, canSelectRow, renderExpandedRow, expandedIds, defaultExpandedIds, onExpandedIdsChange, columnLayout, defaultColumnLayout, onColumnLayoutChange, canResizeColumns: canResizeColumnsProp, canCustomizeColumns: canCustomizeColumnsProp, hasHeader = true, inset: insetProp, ariaLabel, id, className, style, ...rest } = props;
|
|
56
56
|
const error = errorProp === "" ? void 0 : errorProp;
|
|
57
57
|
const size = sizeProp ?? "MEDIUM";
|
|
58
58
|
const isLoading = isLoadingProp ?? false;
|
|
@@ -113,11 +113,13 @@ var InfiniteTableInner = forwardRef(function InfiniteTable(props, ref) {
|
|
|
113
113
|
});
|
|
114
114
|
else setSort(null);
|
|
115
115
|
}, [currentSort, setSort]);
|
|
116
|
+
const lockedIds = useMemo(() => new Set(canSelectRow === void 0 ? [] : displayRows.filter((entry) => !canSelectRow(entry.row)).map((entry) => entry.id)), [displayRows, canSelectRow]);
|
|
116
117
|
const selection = useTableRowSelection({
|
|
117
118
|
value,
|
|
118
119
|
defaultValue: defaultValue ?? [],
|
|
119
120
|
onChange,
|
|
120
|
-
rowIds
|
|
121
|
+
rowIds,
|
|
122
|
+
lockedIds
|
|
121
123
|
});
|
|
122
124
|
const [expanded, setExpanded] = useControlledState({
|
|
123
125
|
value: expandedIds,
|
|
@@ -229,7 +231,7 @@ var InfiniteTableInner = forwardRef(function InfiniteTable(props, ref) {
|
|
|
229
231
|
metrics,
|
|
230
232
|
isChecked: selection.isAllSelected,
|
|
231
233
|
isIndeterminate: selection.isSomeSelected,
|
|
232
|
-
isDisabled:
|
|
234
|
+
isDisabled: selection.isAllLocked,
|
|
233
235
|
onToggle: selection.toggleAll
|
|
234
236
|
}));
|
|
235
237
|
if (hasExpandColumn) leadingHeaders.push(null);
|
|
@@ -283,6 +285,7 @@ var InfiniteTableInner = forwardRef(function InfiniteTable(props, ref) {
|
|
|
283
285
|
isBorderless: isLastRow && !hasStatusAfter || isExpanded,
|
|
284
286
|
isActive: activeRowId !== void 0 && activeRowId !== null && activeRowId === entry.id,
|
|
285
287
|
isSelected: isSelectable ? selection.selectedIds.has(entry.id) : void 0,
|
|
288
|
+
isSelectionLocked: lockedIds.has(entry.id),
|
|
286
289
|
hasExpandColumn,
|
|
287
290
|
isExpanded: canExpand ? isExpanded : void 0,
|
|
288
291
|
panelId: canExpand ? panelId : void 0,
|
|
@@ -156,6 +156,8 @@ export interface TableBodyRowProps {
|
|
|
156
156
|
isActive: boolean;
|
|
157
157
|
/** `undefined`: the table has no select column. */
|
|
158
158
|
isSelected: boolean | undefined;
|
|
159
|
+
/** The row's checkbox is disabled: its selection cannot change. */
|
|
160
|
+
isSelectionLocked: boolean;
|
|
159
161
|
/** The table has an expand column. */
|
|
160
162
|
hasExpandColumn: boolean;
|
|
161
163
|
/** `undefined`: this row cannot expand. */
|
package/dist/table/TableCore.js
CHANGED
|
@@ -293,7 +293,12 @@ var PIN_TO_EDGE_CSS_MAP = {
|
|
|
293
293
|
var PINNED_HEADER_CSS = "gx-TableCore-PINNED_HEADER_CSS-p1nurjwh";
|
|
294
294
|
/** The row does something: pointer and a hover fill. */
|
|
295
295
|
var ROW_INTERACTIVE_CSS = "gx-TableCore-ROW_INTERACTIVE_CSS-r1g7lrfg";
|
|
296
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* A checked row: a faint `opacity.fg4` wash over whatever fill the row has, so it is the same small
|
|
298
|
+
* step on every surface and hover still shows through. The checkbox carries the state; the wash only
|
|
299
|
+
* groups the checked rows. Painted as an image over each cell's inherited color, so a pinned cell
|
|
300
|
+
* stays opaque.
|
|
301
|
+
*/
|
|
297
302
|
var ROW_SELECTED_CSS = "gx-TableCore-ROW_SELECTED_CSS-r10dstoh";
|
|
298
303
|
/** The current row (`activeRowId`): a fill and the `text.primary` bar of active navigation. */
|
|
299
304
|
var ROW_ACTIVE_CSS = "gx-TableCore-ROW_ACTIVE_CSS-rpsswqs";
|
|
@@ -508,10 +513,29 @@ function TableColumnsMenu({ entries, metrics, onToggle, onReset }) {
|
|
|
508
513
|
}
|
|
509
514
|
/** Spread on a built-in control outside the roving row: reachable by pointer, not by Tab. */
|
|
510
515
|
var UNTABBABLE = { tabIndex: -1 };
|
|
511
|
-
/**
|
|
512
|
-
|
|
516
|
+
/**
|
|
517
|
+
* Clicks on these, inside a row, never activate the row: native controls and the interactive
|
|
518
|
+
* ARIA roles a cell can hold (a `SelectInput` trigger is a `div` with `role="combobox"`).
|
|
519
|
+
*/
|
|
520
|
+
var INTERACTIVE_SELECTOR = [
|
|
521
|
+
"a[href]",
|
|
522
|
+
"button",
|
|
523
|
+
"input",
|
|
524
|
+
"select",
|
|
525
|
+
"textarea",
|
|
526
|
+
"[role=\"button\"]",
|
|
527
|
+
"[role=\"link\"]",
|
|
528
|
+
"[role=\"checkbox\"]",
|
|
529
|
+
"[role=\"combobox\"]",
|
|
530
|
+
"[role=\"switch\"]",
|
|
531
|
+
"[role=\"radio\"]",
|
|
532
|
+
"[role=\"tab\"]",
|
|
533
|
+
"[role=\"slider\"]",
|
|
534
|
+
"[role=\"spinbutton\"]",
|
|
535
|
+
"[role=\"menuitem\"]"
|
|
536
|
+
].join(", ");
|
|
513
537
|
/** @internal One body row with its synthetic and data cells. Memoized: every prop is stable or primitive. */
|
|
514
|
-
var TableBodyRow = memo(function TableBodyRow({ row, rowIndex, rowId, columns, metrics, callbacks, cellRole, isFocusable, isTabStop, isClickable, isBorderless, isActive, isSelected, hasExpandColumn, isExpanded, panelId, hasTrailingColumn, isActionsOpen, ariaRowIndex, hasColIndex, className, style }) {
|
|
538
|
+
var TableBodyRow = memo(function TableBodyRow({ row, rowIndex, rowId, columns, metrics, callbacks, cellRole, isFocusable, isTabStop, isClickable, isBorderless, isActive, isSelected, isSelectionLocked, hasExpandColumn, isExpanded, panelId, hasTrailingColumn, isActionsOpen, ariaRowIndex, hasColIndex, className, style }) {
|
|
515
539
|
const shiftRef = useRef(false);
|
|
516
540
|
const rowRef = useCallback((element) => callbacks.registerRow(rowIndex, element), [callbacks, rowIndex]);
|
|
517
541
|
const isSelectable = isSelected !== void 0;
|
|
@@ -565,6 +589,7 @@ var TableBodyRow = memo(function TableBodyRow({ row, rowIndex, rowId, columns, m
|
|
|
565
589
|
children: /* @__PURE__ */ jsx(CheckboxInput, {
|
|
566
590
|
size: metrics.checkboxSize,
|
|
567
591
|
isChecked: isSelected,
|
|
592
|
+
isDisabled: isSelectionLocked,
|
|
568
593
|
onChange: () => {
|
|
569
594
|
callbacks.onToggleSelect(rowId, shiftRef.current);
|
|
570
595
|
shiftRef.current = false;
|
|
@@ -277,6 +277,7 @@ var VirtualizedInfiniteTableInner = forwardRef(function VirtualizedInfiniteTable
|
|
|
277
277
|
isBorderless,
|
|
278
278
|
isActive: activeRowId !== void 0 && activeRowId !== null && activeRowId === rowId,
|
|
279
279
|
isSelected: void 0,
|
|
280
|
+
isSelectionLocked: false,
|
|
280
281
|
hasExpandColumn: false,
|
|
281
282
|
isExpanded: void 0,
|
|
282
283
|
panelId: void 0,
|
|
@@ -8,19 +8,23 @@ export interface UseTableRowSelectionOptions {
|
|
|
8
8
|
onChange: ((value: string[]) => void) | undefined;
|
|
9
9
|
/** Ids of the loaded rows in display order. */
|
|
10
10
|
rowIds: string[];
|
|
11
|
+
/** Ids of rows whose selection cannot change. */
|
|
12
|
+
lockedIds: ReadonlySet<string>;
|
|
11
13
|
}
|
|
12
14
|
/** @internal What `useTableRowSelection` returns. */
|
|
13
15
|
export interface TableRowSelection {
|
|
14
16
|
/** The selected ids. */
|
|
15
17
|
selectedIds: ReadonlySet<string>;
|
|
16
|
-
/** Every loaded row is selected (and there is at least one). */
|
|
18
|
+
/** Every loaded row that can change is selected (and there is at least one). */
|
|
17
19
|
isAllSelected: boolean;
|
|
18
|
-
/** Some, not
|
|
20
|
+
/** Some loaded rows are selected, but not every row that can change. */
|
|
19
21
|
isSomeSelected: boolean;
|
|
22
|
+
/** No loaded row can change. */
|
|
23
|
+
isAllLocked: boolean;
|
|
20
24
|
/** Toggles one row; with `isRange`, selects every row from the last toggled one to it. */
|
|
21
25
|
toggleRow: (rowId: string, isRange: boolean) => void;
|
|
22
|
-
/** Selects every loaded row, or clears
|
|
26
|
+
/** Selects every loaded row that can change, or clears them when all are selected. */
|
|
23
27
|
toggleAll: () => void;
|
|
24
28
|
}
|
|
25
29
|
/** @internal Selection state for a table's rows. */
|
|
26
|
-
export declare function useTableRowSelection({ value, defaultValue, onChange, rowIds, }: UseTableRowSelectionOptions): TableRowSelection;
|
|
30
|
+
export declare function useTableRowSelection({ value, defaultValue, onChange, rowIds, lockedIds, }: UseTableRowSelectionOptions): TableRowSelection;
|
|
@@ -7,10 +7,11 @@ import { useCallback, useMemo, useRef } from "react";
|
|
|
7
7
|
*
|
|
8
8
|
* Row selection over string ids: the `value` / `defaultValue` / `onChange` triple, the
|
|
9
9
|
* shift-range anchor (the last toggled row) and select-all over the loaded rows. Reported ids
|
|
10
|
-
* are in row order.
|
|
10
|
+
* are in row order. Rows in `lockedIds` keep their state: toggles, ranges and select-all skip
|
|
11
|
+
* them. Only InfiniteTable selects rows.
|
|
11
12
|
*/
|
|
12
13
|
/** @internal Selection state for a table's rows. */
|
|
13
|
-
function useTableRowSelection({ value, defaultValue, onChange, rowIds }) {
|
|
14
|
+
function useTableRowSelection({ value, defaultValue, onChange, rowIds, lockedIds }) {
|
|
14
15
|
const [selected, setSelected] = useControlledState({
|
|
15
16
|
value,
|
|
16
17
|
defaultValue,
|
|
@@ -20,11 +21,13 @@ function useTableRowSelection({ value, defaultValue, onChange, rowIds }) {
|
|
|
20
21
|
const anchorRef = useRef(null);
|
|
21
22
|
const stateRef = useRef({
|
|
22
23
|
selectedIds,
|
|
23
|
-
rowIds
|
|
24
|
+
rowIds,
|
|
25
|
+
lockedIds
|
|
24
26
|
});
|
|
25
27
|
stateRef.current = {
|
|
26
28
|
selectedIds,
|
|
27
|
-
rowIds
|
|
29
|
+
rowIds,
|
|
30
|
+
lockedIds
|
|
28
31
|
};
|
|
29
32
|
/** Ids in row order; ids no longer loaded keep their place at the end. */
|
|
30
33
|
const ordered = useCallback((ids) => {
|
|
@@ -34,33 +37,39 @@ function useTableRowSelection({ value, defaultValue, onChange, rowIds }) {
|
|
|
34
37
|
return [...inRows, ...[...ids].filter((id) => !rowSet.has(id))];
|
|
35
38
|
}, []);
|
|
36
39
|
const toggleRow = useCallback((rowId, isRange) => {
|
|
37
|
-
const { selectedIds: current, rowIds: rows } = stateRef.current;
|
|
40
|
+
const { selectedIds: current, rowIds: rows, lockedIds: locked } = stateRef.current;
|
|
41
|
+
if (locked.has(rowId)) return;
|
|
38
42
|
const next = new Set(current);
|
|
39
43
|
const anchor = anchorRef.current;
|
|
40
44
|
const from = anchor === null ? -1 : rows.indexOf(anchor);
|
|
41
45
|
const to = rows.indexOf(rowId);
|
|
42
46
|
if (isRange && from !== -1 && to !== -1) {
|
|
43
47
|
const [start, end] = from < to ? [from, to] : [to, from];
|
|
44
|
-
for (const id of rows.slice(start, end + 1)) next.add(id);
|
|
48
|
+
for (const id of rows.slice(start, end + 1)) if (!locked.has(id)) next.add(id);
|
|
45
49
|
} else if (next.has(rowId)) next.delete(rowId);
|
|
46
50
|
else next.add(rowId);
|
|
47
51
|
anchorRef.current = rowId;
|
|
48
52
|
setSelected(ordered(next));
|
|
49
53
|
}, [ordered, setSelected]);
|
|
50
|
-
const
|
|
54
|
+
const unlockedIds = rowIds.filter((id) => !lockedIds.has(id));
|
|
55
|
+
const isAllSelected = unlockedIds.length > 0 && unlockedIds.every((id) => selectedIds.has(id));
|
|
56
|
+
const isSomeSelected = !isAllSelected && rowIds.some((id) => selectedIds.has(id));
|
|
57
|
+
const toggleAll = useCallback(() => {
|
|
58
|
+
const { selectedIds: current, rowIds: allRows, lockedIds: locked } = stateRef.current;
|
|
59
|
+
const rows = allRows.filter((id) => !locked.has(id));
|
|
60
|
+
const isAll = rows.length > 0 && rows.every((id) => current.has(id));
|
|
61
|
+
const next = new Set(current);
|
|
62
|
+
for (const id of rows) if (isAll) next.delete(id);
|
|
63
|
+
else next.add(id);
|
|
64
|
+
setSelected(ordered(next));
|
|
65
|
+
}, [ordered, setSelected]);
|
|
51
66
|
return {
|
|
52
67
|
selectedIds,
|
|
53
68
|
isAllSelected,
|
|
54
|
-
isSomeSelected
|
|
69
|
+
isSomeSelected,
|
|
70
|
+
isAllLocked: unlockedIds.length === 0,
|
|
55
71
|
toggleRow,
|
|
56
|
-
toggleAll
|
|
57
|
-
const { selectedIds: current, rowIds: rows } = stateRef.current;
|
|
58
|
-
const isAll = rows.length > 0 && rows.every((id) => current.has(id));
|
|
59
|
-
const next = new Set(current);
|
|
60
|
-
for (const id of rows) if (isAll) next.delete(id);
|
|
61
|
-
else next.add(id);
|
|
62
|
-
setSelected(ordered(next));
|
|
63
|
-
}, [ordered, setSelected])
|
|
72
|
+
toggleAll
|
|
64
73
|
};
|
|
65
74
|
}
|
|
66
75
|
//#endregion
|