@trama-ui/react-native 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +198 -2
- package/dist/accordion.d.ts +29 -0
- package/dist/accordion.js +137 -0
- package/dist/alert.d.ts +30 -0
- package/dist/alert.js +95 -0
- package/dist/avatar.d.ts +36 -0
- package/dist/avatar.js +91 -0
- package/dist/bars.d.ts +44 -0
- package/dist/bars.js +74 -0
- package/dist/button.d.ts +30 -0
- package/dist/button.js +90 -0
- package/dist/calendar.d.ts +71 -0
- package/dist/calendar.js +276 -0
- package/dist/card.d.ts +41 -0
- package/dist/card.js +139 -0
- package/dist/choices.d.ts +87 -0
- package/dist/choices.js +228 -0
- package/dist/collections.d.ts +131 -0
- package/dist/collections.js +230 -0
- package/dist/color-code.d.ts +37 -0
- package/dist/color-code.js +158 -0
- package/dist/compositions.d.ts +110 -0
- package/dist/compositions.js +190 -0
- package/dist/controls.d.ts +85 -0
- package/dist/controls.js +221 -0
- package/dist/drag-drop.d.ts +65 -0
- package/dist/drag-drop.js +482 -0
- package/dist/feedback.d.ts +30 -0
- package/dist/feedback.js +81 -0
- package/dist/file-upload.d.ts +67 -0
- package/dist/file-upload.js +251 -0
- package/dist/generated/icons.d.ts +1037 -0
- package/dist/generated/icons.js +3 -0
- package/dist/generated/tokens.d.ts +64 -0
- package/dist/generated/tokens.js +65 -0
- package/dist/icon.d.ts +31 -0
- package/dist/icon.js +28 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +43 -0
- package/dist/input.d.ts +43 -0
- package/dist/input.js +115 -0
- package/dist/interactive-layout.d.ts +26 -0
- package/dist/interactive-layout.js +117 -0
- package/dist/internal/content.d.ts +17 -0
- package/dist/internal/content.js +24 -0
- package/dist/internal/drag-geometry.d.ts +16 -0
- package/dist/internal/drag-geometry.js +25 -0
- package/dist/internal/keyboard.d.ts +20 -0
- package/dist/internal/keyboard.js +101 -0
- package/dist/internal/motion.d.ts +1 -0
- package/dist/internal/motion.js +24 -0
- package/dist/internal/number-format.d.ts +4 -0
- package/dist/internal/number-format.js +25 -0
- package/dist/internal/pointer-capture.d.ts +1 -0
- package/dist/internal/pointer-capture.js +16 -0
- package/dist/internal/state.d.ts +6 -0
- package/dist/internal/state.js +28 -0
- package/dist/internal/system-drag.d.ts +48 -0
- package/dist/internal/system-drag.js +93 -0
- package/dist/internal/table-drag.d.ts +56 -0
- package/dist/internal/table-drag.js +237 -0
- package/dist/internal/table-editing.d.ts +49 -0
- package/dist/internal/table-editing.js +278 -0
- package/dist/internal/table-editor.d.ts +11 -0
- package/dist/internal/table-editor.js +31 -0
- package/dist/internal/table-grid.d.ts +44 -0
- package/dist/internal/table-grid.js +153 -0
- package/dist/internal/table-model.d.ts +132 -0
- package/dist/internal/table-model.js +231 -0
- package/dist/internal/table-source.d.ts +9 -0
- package/dist/internal/table-source.js +80 -0
- package/dist/internal/tour-target.d.ts +23 -0
- package/dist/internal/tour-target.js +81 -0
- package/dist/keyboard.d.ts +14 -0
- package/dist/keyboard.js +27 -0
- package/dist/layout.d.ts +35 -0
- package/dist/layout.js +77 -0
- package/dist/loader.d.ts +18 -0
- package/dist/loader.js +79 -0
- package/dist/localization.d.ts +106 -0
- package/dist/localization.js +310 -0
- package/dist/media.d.ts +35 -0
- package/dist/media.js +96 -0
- package/dist/menus.d.ts +103 -0
- package/dist/menus.js +422 -0
- package/dist/navigation.d.ts +111 -0
- package/dist/navigation.js +255 -0
- package/dist/overlays.d.ts +97 -0
- package/dist/overlays.js +364 -0
- package/dist/pill.d.ts +33 -0
- package/dist/pill.js +90 -0
- package/dist/progress.d.ts +27 -0
- package/dist/progress.js +154 -0
- package/dist/responsive.d.ts +15 -0
- package/dist/responsive.js +27 -0
- package/dist/select.d.ts +74 -0
- package/dist/select.js +181 -0
- package/dist/separator.d.ts +13 -0
- package/dist/separator.js +34 -0
- package/dist/switch.d.ts +26 -0
- package/dist/switch.js +69 -0
- package/dist/table.d.ts +122 -0
- package/dist/table.js +928 -0
- package/dist/text-fields.d.ts +39 -0
- package/dist/text-fields.js +134 -0
- package/dist/theme.d.ts +47 -0
- package/dist/theme.js +71 -0
- package/dist/transient.d.ts +80 -0
- package/dist/transient.js +273 -0
- package/package.json +50 -4
package/dist/table.js
ADDED
|
@@ -0,0 +1,928 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Children, isValidElement, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { Animated, FlatList, PanResponder, Platform, Pressable, ScrollView, Text, View, } from 'react-native';
|
|
4
|
+
import { Button } from './button.js';
|
|
5
|
+
import { Checkbox } from './choices.js';
|
|
6
|
+
import { Input } from './input.js';
|
|
7
|
+
import { FieldMessage, splitContent, TextContent } from './internal/content.js';
|
|
8
|
+
import { useControllableValue } from './internal/state.js';
|
|
9
|
+
import { useTableDrag } from './internal/table-drag.js';
|
|
10
|
+
import { useTableEditing } from './internal/table-editing.js';
|
|
11
|
+
import { TableEditor } from './internal/table-editor.js';
|
|
12
|
+
import { gridSpanIntersects, gridTravel, tableGridSpans, } from './internal/table-grid.js';
|
|
13
|
+
import { useTableSource } from './internal/table-source.js';
|
|
14
|
+
import { formatTableFields, getTableValue, sameTableCell, tableColumnOffsets, tableColumnSlots, tableColumnWindow, tableSpanningSlots, tableVisibleColumns, } from './internal/table-model.js';
|
|
15
|
+
import { Cluster } from './layout.js';
|
|
16
|
+
import { useTramaLocale, useTramaMessages } from './localization.js';
|
|
17
|
+
import { Pagination } from './navigation.js';
|
|
18
|
+
import { useTramaAppearance, useTramaTheme } from './theme.js';
|
|
19
|
+
function modelKey(id) {
|
|
20
|
+
return typeof id + '-' + id;
|
|
21
|
+
}
|
|
22
|
+
const cellKey = ({ rowId, columnId }) => JSON.stringify([rowId, columnId]);
|
|
23
|
+
function DefaultKeyboardCell({ focusRef, handleKey, children, ...props }) {
|
|
24
|
+
const keyboardEvents = {
|
|
25
|
+
onKeyDown: (event) => {
|
|
26
|
+
if (Platform.OS === 'web' && event.target !== event.currentTarget)
|
|
27
|
+
return;
|
|
28
|
+
if (handleKey(event.nativeEvent)) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return (_jsx(Pressable, { ...props, ...keyboardEvents, ref: focusRef, children: children }));
|
|
35
|
+
}
|
|
36
|
+
function ResizeGrip({ width, min, max, label, onResize, }) {
|
|
37
|
+
const { direction, theme } = useTramaAppearance();
|
|
38
|
+
const start = useRef(width);
|
|
39
|
+
const current = useRef({ width, min, max, direction, onResize });
|
|
40
|
+
current.current = { width, min, max, direction, onResize };
|
|
41
|
+
const resize = (next) => current.current.onResize(Math.max(current.current.min, Math.min(current.current.max, Math.round(next))));
|
|
42
|
+
const responder = useRef(PanResponder.create({
|
|
43
|
+
onMoveShouldSetPanResponder: (_event, gesture) => Math.abs(gesture.dx) > 4 && Math.abs(gesture.dx) > Math.abs(gesture.dy),
|
|
44
|
+
onPanResponderGrant: () => {
|
|
45
|
+
start.current = current.current.width;
|
|
46
|
+
},
|
|
47
|
+
onPanResponderMove: (_event, gesture) => resize(start.current + gesture.dx * (current.current.direction === 'rtl' ? -1 : 1)),
|
|
48
|
+
})).current;
|
|
49
|
+
return (_jsx(View, { ...responder.panHandlers, accessible: true, accessibilityRole: "adjustable", accessibilityLabel: label, accessibilityValue: { min, max, now: width }, accessibilityActions: [{ name: 'increment' }, { name: 'decrement' }], onAccessibilityAction: (event) => resize(width + (event.nativeEvent.actionName === 'increment' ? 16 : -16)), style: { alignSelf: 'stretch', width: 24, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: { width: 2, minHeight: 18, backgroundColor: theme.colors.border } }) }));
|
|
50
|
+
}
|
|
51
|
+
export function Table({ ref, rows: controlledRows, defaultRows, onRowsChange, columns, rowId, variant, density, height, stickyHeader = true, virtualized, rowHeight, columnVirtualized, columnOverscan = 1, selectable, selectedKeys, defaultSelectedKeys, onSelectionChange, activeKeys, sort, defaultSort, onSortChange, multiSort, sorting: controlledSorting, defaultSorting, onSortingChange, filterable, filter, defaultFilter, onFilterChange, filterRow, page, defaultPage, pageSize, onPageChange, manual, dataSource, cacheDataSource = false, onDataError, totalItems, groupBy, pinnedRows, expandedKeys, defaultExpandedKeys, onExpandedChange, renderRowActions, renderRowDetail, renderSelectionActions, onColumnResize, columnWidths, defaultColumnWidths, onColumnWidthsChange, columnOrder, defaultColumnOrder, onColumnOrderChange, hiddenColumns, defaultHiddenColumns, onHiddenColumnsChange, renderColumnGroup, cellSelection = 'none', dragSelection = false, cellRange, defaultCellRange, onCellRangeChange, clipboard, keyboardNavigation = false, keyboardCell: KeyboardCell = DefaultKeyboardCell, showCellActions = true, empty, children, style, ...props }) {
|
|
52
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
53
|
+
const messages = useTramaMessages();
|
|
54
|
+
const locale = useTramaLocale();
|
|
55
|
+
const sections = splitContent(children, {
|
|
56
|
+
toolbar: TableToolbar,
|
|
57
|
+
selection: TableSelectionActions,
|
|
58
|
+
summary: TableSummary,
|
|
59
|
+
});
|
|
60
|
+
const columnParts = Children.toArray(sections.body).flatMap((node) => isValidElement(node) && node.type === TableColumn ? [node.props] : []);
|
|
61
|
+
const definitions = columns ?? columnParts;
|
|
62
|
+
const [order, setOrder] = useControllableValue(columnOrder, defaultColumnOrder ?? []);
|
|
63
|
+
const [hidden, setHidden] = useControllableValue(hiddenColumns, defaultHiddenColumns ?? []);
|
|
64
|
+
const ordered = useMemo(() => tableVisibleColumns(definitions, order, hidden), [definitions, order, hidden]);
|
|
65
|
+
const [localRows, setRows] = useControllableValue(controlledRows, defaultRows ?? []);
|
|
66
|
+
const [query, changeQuery] = useControllableValue(filter, defaultFilter ?? '', onFilterChange);
|
|
67
|
+
const [singleSort, changeSort] = useControllableValue(sort, defaultSort ?? null);
|
|
68
|
+
const [sortModel, setSortModel] = useControllableValue(controlledSorting, defaultSorting ?? (defaultSort ? [defaultSort] : []));
|
|
69
|
+
const multiple = controlledSorting !== undefined || defaultSorting !== undefined || Boolean(multiSort);
|
|
70
|
+
const sorting = useMemo(() => (multiple ? sortModel : singleSort ? [singleSort] : []), [multiple, sortModel, singleSort]);
|
|
71
|
+
const [current, changePage] = useControllableValue(page, defaultPage ?? 1);
|
|
72
|
+
const [selection, changeSelection] = useControllableValue(selectedKeys, defaultSelectedKeys ?? []);
|
|
73
|
+
const [expanded, changeExpanded] = useControllableValue(expandedKeys, defaultExpandedKeys ?? []);
|
|
74
|
+
const [widths, setWidths] = useControllableValue(columnWidths, defaultColumnWidths ?? {});
|
|
75
|
+
const [viewport, setViewport] = useState(0);
|
|
76
|
+
const scrollX = useRef(new Animated.Value(0)).current;
|
|
77
|
+
const collator = useMemo(() => new Intl.Collator(locale, { numeric: true, sensitivity: 'base' }), [locale]);
|
|
78
|
+
const bordered = resolve(variant, 'bordered') === 'bordered';
|
|
79
|
+
const striped = resolve(variant, 'bordered') === 'striped';
|
|
80
|
+
const spacing = theme.space * { compact: 1.5, comfortable: 2.5, spacious: 4 }[resolve(density, 'comfortable')];
|
|
81
|
+
const pageLength = pageSize && Number.isFinite(pageSize) ? Math.max(1, Math.floor(pageSize)) : dataSource ? 25 : undefined;
|
|
82
|
+
const server = Boolean(manual || dataSource);
|
|
83
|
+
const requestedPage = Number.isFinite(current) ? Math.max(1, Math.floor(current)) : 1;
|
|
84
|
+
const remote = useTableSource(dataSource, { page: requestedPage, pageSize: pageLength ?? 25, filter: query, sorting }, cacheDataSource, onDataError);
|
|
85
|
+
const rows = dataSource ? remote.rows : localRows;
|
|
86
|
+
const lowerQuery = query.trim().toLocaleLowerCase(locale);
|
|
87
|
+
const matching = useMemo(() => server || !lowerQuery
|
|
88
|
+
? rows
|
|
89
|
+
: rows.filter((row) => filterRow?.(row, query) ??
|
|
90
|
+
definitions.some((column) => String(getTableValue(row, column) ?? '')
|
|
91
|
+
.toLocaleLowerCase(locale)
|
|
92
|
+
.includes(lowerQuery))), [server, lowerQuery, rows, filterRow, query, definitions, locale]);
|
|
93
|
+
const sorted = useMemo(() => {
|
|
94
|
+
if (server || !sorting.length)
|
|
95
|
+
return matching;
|
|
96
|
+
const selectors = sorting.flatMap((rule) => {
|
|
97
|
+
const column = definitions.find((column) => column.id === rule.key);
|
|
98
|
+
return column ? [{ column, rule }] : [];
|
|
99
|
+
});
|
|
100
|
+
return [...matching].sort((a, b) => {
|
|
101
|
+
for (const { column, rule } of selectors) {
|
|
102
|
+
const first = getTableValue(a, column);
|
|
103
|
+
const second = getTableValue(b, column);
|
|
104
|
+
const order = column.compare?.(first, second) ??
|
|
105
|
+
(typeof first === 'number' && typeof second === 'number'
|
|
106
|
+
? first - second
|
|
107
|
+
: collator.compare(String(first ?? ''), String(second ?? '')));
|
|
108
|
+
if (order)
|
|
109
|
+
return rule.direction === 'descending' ? -order : order;
|
|
110
|
+
}
|
|
111
|
+
return 0;
|
|
112
|
+
});
|
|
113
|
+
}, [server, sorting, matching, definitions, collator]);
|
|
114
|
+
const { start, middle, end } = useMemo(() => {
|
|
115
|
+
const start = [];
|
|
116
|
+
const middle = [];
|
|
117
|
+
const end = [];
|
|
118
|
+
const first = new Set(pinnedRows?.start);
|
|
119
|
+
const last = new Set(pinnedRows?.end);
|
|
120
|
+
for (const row of sorted) {
|
|
121
|
+
const id = rowId(row);
|
|
122
|
+
if (first.has(id))
|
|
123
|
+
start.push(row);
|
|
124
|
+
else if (last.has(id))
|
|
125
|
+
end.push(row);
|
|
126
|
+
else
|
|
127
|
+
middle.push(row);
|
|
128
|
+
}
|
|
129
|
+
return { start, middle, end };
|
|
130
|
+
}, [sorted, rowId, pinnedRows?.start, pinnedRows?.end]);
|
|
131
|
+
const count = totalItems ?? remote.totalItems ?? middle.length;
|
|
132
|
+
const pageCount = Math.max(1, pageLength ? Math.ceil(count / pageLength) : 1, remote.loading ? requestedPage : 1);
|
|
133
|
+
const effectivePage = Math.min(pageCount, requestedPage);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (dataSource && !remote.loading && !remote.failed && requestedPage > pageCount && page === undefined)
|
|
136
|
+
changePage(pageCount);
|
|
137
|
+
}, [dataSource, remote.loading, remote.failed, requestedPage, pageCount, page, changePage]);
|
|
138
|
+
const { entries, pinnedStartEntries, pinnedEndEntries, ids, displayed, displayedIds, displayRowIndex } = useMemo(() => {
|
|
139
|
+
const visible = server || !pageLength ? middle : middle.slice((effectivePage - 1) * pageLength, effectivePage * pageLength);
|
|
140
|
+
const entries = [];
|
|
141
|
+
const rowEntry = (row, index) => ({
|
|
142
|
+
kind: 'row',
|
|
143
|
+
id: 'row-' + modelKey(rowId(row)),
|
|
144
|
+
row,
|
|
145
|
+
index,
|
|
146
|
+
});
|
|
147
|
+
if (groupBy) {
|
|
148
|
+
const groups = new Map();
|
|
149
|
+
for (const row of visible) {
|
|
150
|
+
const label = groupBy(row);
|
|
151
|
+
const group = groups.get(label);
|
|
152
|
+
if (group)
|
|
153
|
+
group.push(row);
|
|
154
|
+
else
|
|
155
|
+
groups.set(label, [row]);
|
|
156
|
+
}
|
|
157
|
+
let index = 0;
|
|
158
|
+
for (const [label, group] of groups) {
|
|
159
|
+
entries.push({ kind: 'group', id: 'group-' + label, label });
|
|
160
|
+
for (const row of group)
|
|
161
|
+
entries.push(rowEntry(row, index++));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else
|
|
165
|
+
visible.forEach((row, index) => entries.push(rowEntry(row, index)));
|
|
166
|
+
const pinnedStartEntries = start.map((row) => rowEntry(row, 0));
|
|
167
|
+
const pinnedEndEntries = end.map((row) => rowEntry(row, 0));
|
|
168
|
+
const displayed = [
|
|
169
|
+
...pinnedStartEntries,
|
|
170
|
+
...entries.filter((entry) => entry.kind === 'row'),
|
|
171
|
+
...pinnedEndEntries,
|
|
172
|
+
];
|
|
173
|
+
const displayedIds = displayed.map((entry) => rowId(entry.row));
|
|
174
|
+
return {
|
|
175
|
+
entries,
|
|
176
|
+
pinnedStartEntries,
|
|
177
|
+
pinnedEndEntries,
|
|
178
|
+
displayed,
|
|
179
|
+
displayedIds,
|
|
180
|
+
ids: [...start, ...visible, ...end].map(rowId),
|
|
181
|
+
displayRowIndex: new Map(displayedIds.map((id, index) => [id, index])),
|
|
182
|
+
};
|
|
183
|
+
}, [server, pageLength, effectivePage, start, middle, end, rowId, groupBy]);
|
|
184
|
+
const editBlocked = Boolean((dataSource || controlledRows !== undefined) && !onRowsChange);
|
|
185
|
+
const hasEditableColumns = !editBlocked && ordered.some((column) => column.editor || column.editable);
|
|
186
|
+
const canSpan = ordered.some((column) => column.rowSpan || column.colSpan);
|
|
187
|
+
const hasVerticalSpans = canSpan && ordered.some((column) => column.rowSpan);
|
|
188
|
+
const spans = useMemo(() => {
|
|
189
|
+
if (!canSpan)
|
|
190
|
+
return undefined;
|
|
191
|
+
const rowEnds = [];
|
|
192
|
+
let index = 0;
|
|
193
|
+
let boundary = 0;
|
|
194
|
+
function finishSegment() {
|
|
195
|
+
while (boundary < index)
|
|
196
|
+
rowEnds[boundary++] = index;
|
|
197
|
+
}
|
|
198
|
+
for (const lane of [pinnedStartEntries, entries, pinnedEndEntries]) {
|
|
199
|
+
for (const entry of lane) {
|
|
200
|
+
if (entry.kind === 'group')
|
|
201
|
+
finishSegment();
|
|
202
|
+
else {
|
|
203
|
+
index++;
|
|
204
|
+
if (renderRowDetail && expanded.includes(rowId(entry.row)))
|
|
205
|
+
finishSegment();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
finishSegment();
|
|
209
|
+
}
|
|
210
|
+
return tableGridSpans(displayed.length, ordered.map((column) => column.pinned), rowEnds, ({ row, column }) => ({
|
|
211
|
+
rows: ordered[column].rowSpan?.(displayed[row].row),
|
|
212
|
+
columns: ordered[column].colSpan?.(displayed[row].row),
|
|
213
|
+
}));
|
|
214
|
+
}, [canSpan, pinnedStartEntries, entries, pinnedEndEntries, renderRowDetail, expanded, rowId, displayed, ordered]);
|
|
215
|
+
const ownerAt = (point) => spans?.owner(point) ?? { ...point, rows: 1, columns: 1 };
|
|
216
|
+
function isCovered(row, column) {
|
|
217
|
+
const owner = ownerAt({ row, column });
|
|
218
|
+
return owner.row !== row || owner.column !== column;
|
|
219
|
+
}
|
|
220
|
+
function visibleOwner(cell) {
|
|
221
|
+
if (!spans)
|
|
222
|
+
return cell;
|
|
223
|
+
const point = locatePoint(cell);
|
|
224
|
+
return point ? pointAddress(ownerAt(point)) : cell;
|
|
225
|
+
}
|
|
226
|
+
const { bodyBlocks, bodyIndex, pinnedStartBlocks, pinnedEndBlocks } = useMemo(() => {
|
|
227
|
+
function blocksFor(group) {
|
|
228
|
+
const blocks = [];
|
|
229
|
+
let limit = -1;
|
|
230
|
+
for (const entry of group) {
|
|
231
|
+
if (entry.kind === 'group') {
|
|
232
|
+
blocks.push(entry);
|
|
233
|
+
limit = -1;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const position = displayRowIndex.get(rowId(entry.row)) ?? -1;
|
|
237
|
+
const previous = blocks.at(-1);
|
|
238
|
+
if (position < limit && previous?.kind === 'rows')
|
|
239
|
+
previous.rows.push(entry);
|
|
240
|
+
else
|
|
241
|
+
blocks.push({ kind: 'rows', id: entry.id, rows: [entry] });
|
|
242
|
+
limit = Math.max(limit, spans?.rowEnd(position) ?? position + 1);
|
|
243
|
+
}
|
|
244
|
+
return blocks;
|
|
245
|
+
}
|
|
246
|
+
const bodyBlocks = blocksFor(entries);
|
|
247
|
+
const bodyIndex = new Map();
|
|
248
|
+
bodyBlocks.forEach((block, index) => {
|
|
249
|
+
if (block.kind === 'rows')
|
|
250
|
+
for (const entry of block.rows)
|
|
251
|
+
bodyIndex.set(rowId(entry.row), index);
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
bodyBlocks,
|
|
255
|
+
bodyIndex,
|
|
256
|
+
pinnedStartBlocks: blocksFor(pinnedStartEntries),
|
|
257
|
+
pinnedEndBlocks: blocksFor(pinnedEndEntries),
|
|
258
|
+
};
|
|
259
|
+
}, [entries, pinnedStartEntries, pinnedEndEntries, displayRowIndex, rowId, spans]);
|
|
260
|
+
const spanRowHeight = hasVerticalSpans
|
|
261
|
+
? Math.max(44, rowHeight && Number.isFinite(rowHeight) ? rowHeight : 64)
|
|
262
|
+
: undefined;
|
|
263
|
+
const editing = useTableEditing({
|
|
264
|
+
rows,
|
|
265
|
+
rowId,
|
|
266
|
+
columns: ordered,
|
|
267
|
+
displayedIds,
|
|
268
|
+
cellSelection,
|
|
269
|
+
cellRange,
|
|
270
|
+
defaultCellRange,
|
|
271
|
+
onCellRangeChange,
|
|
272
|
+
clipboard,
|
|
273
|
+
isCovered,
|
|
274
|
+
owner: visibleOwner,
|
|
275
|
+
expandBounds: spans?.close,
|
|
276
|
+
spanModel: spans,
|
|
277
|
+
writeRows(next, detail) {
|
|
278
|
+
if (editBlocked)
|
|
279
|
+
return false;
|
|
280
|
+
if (onRowsChange?.(next, detail) === false)
|
|
281
|
+
return false;
|
|
282
|
+
if (dataSource)
|
|
283
|
+
return remote.updateRows(next);
|
|
284
|
+
setRows(next);
|
|
285
|
+
return true;
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
const utilityCells = Number(Boolean(selectable)) + Number(Boolean(renderRowDetail));
|
|
289
|
+
const fixedRowHeight = stickyHeader &&
|
|
290
|
+
!groupBy &&
|
|
291
|
+
!renderRowDetail &&
|
|
292
|
+
(spanRowHeight !== undefined || !hasEditableColumns) &&
|
|
293
|
+
(spanRowHeight !== undefined || (rowHeight !== undefined && Number.isFinite(rowHeight)))
|
|
294
|
+
? (spanRowHeight ?? Math.max(44, rowHeight ?? 64))
|
|
295
|
+
: undefined;
|
|
296
|
+
const blockOffsets = [0];
|
|
297
|
+
if (fixedRowHeight)
|
|
298
|
+
for (const block of bodyBlocks)
|
|
299
|
+
blockOffsets.push(blockOffsets[blockOffsets.length - 1] + (block.kind === 'rows' ? block.rows.length : 1) * fixedRowHeight);
|
|
300
|
+
const cells = useMemo(() => [
|
|
301
|
+
...(selectable ? [{ key: 'select', width: 58, pin: 'start' }] : []),
|
|
302
|
+
...(renderRowDetail ? [{ key: 'detail', width: 52, pin: 'start' }] : []),
|
|
303
|
+
...ordered.map((column) => {
|
|
304
|
+
const min = typeof column.minWidth === 'number' && Number.isFinite(column.minWidth) ? Math.max(44, column.minWidth) : 64;
|
|
305
|
+
const max = typeof column.maxWidth === 'number' && Number.isFinite(column.maxWidth)
|
|
306
|
+
? Math.max(min, column.maxWidth)
|
|
307
|
+
: Math.max(min, 640);
|
|
308
|
+
const supplied = widths[column.id] ?? column.width ?? 160;
|
|
309
|
+
return {
|
|
310
|
+
key: 'column-' + column.id,
|
|
311
|
+
width: Math.min(max, Math.max(min, Number.isFinite(supplied) ? supplied : 160)),
|
|
312
|
+
pin: column.pinned,
|
|
313
|
+
};
|
|
314
|
+
}),
|
|
315
|
+
...(renderRowActions ? [{ key: 'actions', width: 128, pin: 'end' }] : []),
|
|
316
|
+
], [selectable, renderRowDetail, ordered, widths, renderRowActions]);
|
|
317
|
+
const offsets = useMemo(() => tableColumnOffsets(cells), [cells]);
|
|
318
|
+
const contentWidth = offsets[offsets.length - 1];
|
|
319
|
+
const pinnedEnd = cells.filter((cell) => cell.pin === 'end').reduce((width, cell) => width + cell.width, 0);
|
|
320
|
+
const pinnedStart = cells.filter((cell) => cell.pin === 'start').reduce((width, cell) => width + cell.width, 0);
|
|
321
|
+
const maxScroll = Math.max(0, contentWidth - viewport);
|
|
322
|
+
const canPin = viewport > pinnedStart + pinnedEnd + 24 && maxScroll > 0;
|
|
323
|
+
const rtl = direction === 'rtl';
|
|
324
|
+
const windowColumns = resolve(columnVirtualized, false);
|
|
325
|
+
const overscan = Number.isFinite(columnOverscan) ? Math.min(20, Math.max(0, Math.floor(columnOverscan))) : 1;
|
|
326
|
+
const physicalX = useRef(0);
|
|
327
|
+
const physicalY = useRef(0);
|
|
328
|
+
const bodyHeight = useRef(0);
|
|
329
|
+
const bodyContentHeight = useRef(0);
|
|
330
|
+
const horizontal = useRef(null);
|
|
331
|
+
const vertical = useRef(null);
|
|
332
|
+
const virtualRows = useRef(null);
|
|
333
|
+
const focusHosts = useRef(new Map());
|
|
334
|
+
const pendingFocus = useRef(null);
|
|
335
|
+
const focusFrame = useRef(null);
|
|
336
|
+
const [cursor, setCursor] = useState(null);
|
|
337
|
+
const [focused, setFocused] = useState(null);
|
|
338
|
+
const [window, setWindow] = useState({ start: 0, end: 1 });
|
|
339
|
+
useEffect(() => {
|
|
340
|
+
if (windowColumns) {
|
|
341
|
+
const next = tableColumnWindow(offsets, Math.max(0, Math.min(maxScroll, physicalX.current)), viewport || 360, overscan);
|
|
342
|
+
setWindow((before) => (before.start === next.start && before.end === next.end ? before : next));
|
|
343
|
+
}
|
|
344
|
+
}, [viewport, maxScroll, windowColumns, offsets, overscan]);
|
|
345
|
+
const activeColumn = editing.draft ? ordered.findIndex((column) => column.id === editing.draft?.cell.columnId) : -1;
|
|
346
|
+
const retained = activeColumn < 0 ? -1 : activeColumn + utilityCells;
|
|
347
|
+
const slots = useMemo(() => tableColumnSlots(cells, offsets, windowColumns ? window.start : 0, windowColumns ? window.end : cells.length, retained), [cells, offsets, windowColumns, window.start, window.end, retained]);
|
|
348
|
+
function scrollColumns(event) {
|
|
349
|
+
syncColumnWindow(event.nativeEvent.contentOffset.x);
|
|
350
|
+
}
|
|
351
|
+
function syncColumnWindow(left) {
|
|
352
|
+
physicalX.current = left;
|
|
353
|
+
if (!windowColumns)
|
|
354
|
+
return;
|
|
355
|
+
const next = tableColumnWindow(offsets, Math.max(0, Math.min(maxScroll, physicalX.current)), viewport || 360, overscan);
|
|
356
|
+
setWindow((before) => (before.start === next.start && before.end === next.end ? before : next));
|
|
357
|
+
}
|
|
358
|
+
function locatePoint(cell) {
|
|
359
|
+
const row = cell ? (displayRowIndex.get(cell.rowId) ?? -1) : -1;
|
|
360
|
+
const column = cell ? ordered.findIndex((entry) => entry.id === cell.columnId) : -1;
|
|
361
|
+
return row >= 0 && column >= 0 ? { row, column } : null;
|
|
362
|
+
}
|
|
363
|
+
function pointAddress(point) {
|
|
364
|
+
return { rowId: displayedIds[point.row], columnId: ordered[point.column].id };
|
|
365
|
+
}
|
|
366
|
+
const currentPoint = locatePoint(cursor) ?? (displayed.length && ordered.length ? { row: 0, column: 0 } : null);
|
|
367
|
+
const currentKey = currentPoint ? cellKey(pointAddress(ownerAt(currentPoint))) : undefined;
|
|
368
|
+
const dragLayout = useMemo(() => ({}), [displayed, ordered, offsets, rtl, spans]);
|
|
369
|
+
const drag = useTableDrag({
|
|
370
|
+
enabled: dragSelection && cellSelection === 'range' && !editing.draft && displayed.length > 0 && ordered.length > 0,
|
|
371
|
+
layout: dragLayout,
|
|
372
|
+
rtl,
|
|
373
|
+
offsets,
|
|
374
|
+
utility: utilityCells,
|
|
375
|
+
columns: ordered.length,
|
|
376
|
+
rowCount: displayed.length,
|
|
377
|
+
pinnedRowsStart: start.length,
|
|
378
|
+
pinnedRowsEnd: end.length,
|
|
379
|
+
pinnedColumnsStart: canPin ? pinnedStart : 0,
|
|
380
|
+
pinnedColumnsEnd: canPin ? pinnedEnd : 0,
|
|
381
|
+
cell: (row, column) => pointAddress(ownerAt({ row, column })),
|
|
382
|
+
position: () => ({ x: physicalX.current, y: physicalY.current }),
|
|
383
|
+
scroll(delta) {
|
|
384
|
+
const x = Math.max(0, Math.min(maxScroll, physicalX.current + delta.x));
|
|
385
|
+
const y = Math.max(0, Math.min(bodyContentHeight.current - bodyHeight.current, physicalY.current + delta.y));
|
|
386
|
+
if (x !== physicalX.current) {
|
|
387
|
+
const target = horizontal.current;
|
|
388
|
+
if (target && typeof target === 'object' && 'scrollTo' in target)
|
|
389
|
+
target.scrollTo({ x, animated: false });
|
|
390
|
+
syncColumnWindow(x);
|
|
391
|
+
}
|
|
392
|
+
if (height && y !== physicalY.current) {
|
|
393
|
+
virtualRows.current?.scrollToOffset({ offset: y, animated: false });
|
|
394
|
+
vertical.current?.scrollTo({ y, animated: false });
|
|
395
|
+
physicalY.current = y;
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
onSelect(range) {
|
|
399
|
+
if (editing.select(range)) {
|
|
400
|
+
editing.setExtending(false);
|
|
401
|
+
if (keyboardNavigation) {
|
|
402
|
+
setCursor(range.focus);
|
|
403
|
+
applyFocus(cellKey(range.focus));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
const previewBounds = drag.preview ? editing.boundsFor(drag.preview) : undefined;
|
|
409
|
+
useEffect(() => () => {
|
|
410
|
+
if (focusFrame.current !== null)
|
|
411
|
+
cancelAnimationFrame(focusFrame.current);
|
|
412
|
+
}, []);
|
|
413
|
+
function applyFocus(key) {
|
|
414
|
+
if (focusFrame.current !== null)
|
|
415
|
+
cancelAnimationFrame(focusFrame.current);
|
|
416
|
+
pendingFocus.current = key;
|
|
417
|
+
focusFrame.current = requestAnimationFrame(() => {
|
|
418
|
+
focusFrame.current = null;
|
|
419
|
+
if (pendingFocus.current !== key)
|
|
420
|
+
return;
|
|
421
|
+
const host = focusHosts.current.get(key);
|
|
422
|
+
if (host) {
|
|
423
|
+
pendingFocus.current = null;
|
|
424
|
+
host.focus();
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
function registerFocus(key, host) {
|
|
429
|
+
if (host) {
|
|
430
|
+
focusHosts.current.set(key, host);
|
|
431
|
+
if (pendingFocus.current === key)
|
|
432
|
+
applyFocus(key);
|
|
433
|
+
}
|
|
434
|
+
else
|
|
435
|
+
focusHosts.current.delete(key);
|
|
436
|
+
}
|
|
437
|
+
function focusPoint(point) {
|
|
438
|
+
const anchor = ownerAt(point);
|
|
439
|
+
const address = pointAddress(anchor);
|
|
440
|
+
const key = cellKey(address);
|
|
441
|
+
setCursor(pointAddress(point));
|
|
442
|
+
const layout = cells[anchor.column + utilityCells];
|
|
443
|
+
if (!canPin || !layout.pin) {
|
|
444
|
+
const start = offsets[anchor.column + utilityCells];
|
|
445
|
+
const end = offsets[anchor.column + utilityCells + anchor.columns];
|
|
446
|
+
const insetStart = canPin ? pinnedStart : 0;
|
|
447
|
+
const insetEnd = canPin ? pinnedEnd : 0;
|
|
448
|
+
const currentX = physicalX.current;
|
|
449
|
+
const room = viewport - insetStart - insetEnd;
|
|
450
|
+
if (room > 0) {
|
|
451
|
+
const x = Math.max(0, Math.min(maxScroll, start < currentX + insetStart || end - start > room
|
|
452
|
+
? start - insetStart
|
|
453
|
+
: end > currentX + viewport - insetEnd
|
|
454
|
+
? end - viewport + insetEnd
|
|
455
|
+
: currentX));
|
|
456
|
+
if (x !== currentX) {
|
|
457
|
+
const target = horizontal.current;
|
|
458
|
+
if (target && typeof target === 'object' && 'scrollTo' in target)
|
|
459
|
+
target.scrollTo({ x, animated: false });
|
|
460
|
+
syncColumnWindow(x);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const block = bodyIndex.get(address.rowId);
|
|
465
|
+
if (height && block !== undefined) {
|
|
466
|
+
if (fixedRowHeight) {
|
|
467
|
+
const y = (anchor.row - pinnedStartEntries.length) * fixedRowHeight;
|
|
468
|
+
const edge = physicalY.current;
|
|
469
|
+
const room = Math.max(fixedRowHeight, height - fixedRowHeight * (1 + start.length + end.length));
|
|
470
|
+
if (y < edge || y + fixedRowHeight > edge + room) {
|
|
471
|
+
const offset = y < edge ? y : y + fixedRowHeight - room;
|
|
472
|
+
virtualRows.current?.scrollToOffset({ offset, animated: false });
|
|
473
|
+
vertical.current?.scrollTo({ y: offset, animated: false });
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
else if (virtualRows.current && !focusHosts.current.has(key)) {
|
|
477
|
+
virtualRows.current.scrollToIndex({ index: block, animated: false, viewPosition: 0.5 });
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
applyFocus(key);
|
|
481
|
+
}
|
|
482
|
+
function focusCell(cell) {
|
|
483
|
+
const point = locatePoint(cell);
|
|
484
|
+
if (!keyboardNavigation || !point || editing.draft)
|
|
485
|
+
return false;
|
|
486
|
+
focusPoint(point);
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
function recordFocus(cell) {
|
|
490
|
+
const key = cellKey(cell);
|
|
491
|
+
setFocused(key);
|
|
492
|
+
if (currentKey !== key)
|
|
493
|
+
setCursor(cell);
|
|
494
|
+
}
|
|
495
|
+
function handleCellKey(event, origin) {
|
|
496
|
+
if (!keyboardNavigation || event.isComposing || event.altKey || !currentPoint)
|
|
497
|
+
return false;
|
|
498
|
+
if (editing.draft) {
|
|
499
|
+
if (event.key !== 'Escape')
|
|
500
|
+
return false;
|
|
501
|
+
return finishEditing(false);
|
|
502
|
+
}
|
|
503
|
+
const source = origin && cellKey(origin) !== currentKey ? (locatePoint(origin) ?? currentPoint) : currentPoint;
|
|
504
|
+
const owner = ownerAt(source);
|
|
505
|
+
const cell = pointAddress(owner);
|
|
506
|
+
const next = gridTravel(event, source, owner, {
|
|
507
|
+
rows: displayed.length,
|
|
508
|
+
columns: ordered.length,
|
|
509
|
+
rtl,
|
|
510
|
+
pageRows: Math.max(1, Math.floor((height ?? 420) / (fixedRowHeight ?? 56)) - 1),
|
|
511
|
+
});
|
|
512
|
+
if (next) {
|
|
513
|
+
if (event.shiftKey && cellSelection === 'range') {
|
|
514
|
+
const anchor = editing.range && sameTableCell(editing.range.focus, cell) ? editing.range.anchor : cell;
|
|
515
|
+
editing.select({ anchor, focus: pointAddress(ownerAt(next)) });
|
|
516
|
+
}
|
|
517
|
+
focusPoint(next);
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
const key = event.key.toLowerCase();
|
|
521
|
+
if (key === 'escape' && drag.cancel())
|
|
522
|
+
return true;
|
|
523
|
+
if (event.ctrlKey || event.metaKey) {
|
|
524
|
+
if (key === 'c' && clipboard?.writeText && editing.bounds) {
|
|
525
|
+
void editing.copySelection();
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
if (key === 'v' && clipboard?.readText && editing.bounds && !editBlocked) {
|
|
529
|
+
void editing.pasteSelection();
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
if (key === 'z')
|
|
533
|
+
return event.shiftKey ? editing.redo() : editing.undo();
|
|
534
|
+
if (key === 'y')
|
|
535
|
+
return editing.redo();
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
if (key === 'f2' || key === 'enter') {
|
|
539
|
+
if (!editBlocked && editing.editable(cell)) {
|
|
540
|
+
if (!event.repeat)
|
|
541
|
+
editing.begin(cell);
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
if (key === 'f2')
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
if (key === 'enter' || key === ' ' || key === 'spacebar')
|
|
548
|
+
return editing.select({ anchor: cell, focus: cell });
|
|
549
|
+
if (key === 'escape' && editing.bounds)
|
|
550
|
+
return editing.select(null);
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
function finishEditing(save) {
|
|
554
|
+
const current = editing.draft?.cell;
|
|
555
|
+
if (save && !editing.commit())
|
|
556
|
+
return false;
|
|
557
|
+
if (!save)
|
|
558
|
+
editing.cancel();
|
|
559
|
+
if (keyboardNavigation && current) {
|
|
560
|
+
const point = locatePoint(current);
|
|
561
|
+
if (point)
|
|
562
|
+
focusPoint(point);
|
|
563
|
+
}
|
|
564
|
+
return true;
|
|
565
|
+
}
|
|
566
|
+
function renderCells(render, background, header = false, windowSlots = slots, row) {
|
|
567
|
+
return windowSlots.map((slot) => {
|
|
568
|
+
if ('width' in slot)
|
|
569
|
+
return (_jsx(View, { accessible: false, importantForAccessibility: "no", style: { width: slot.width, flexShrink: 0 } }, slot.key));
|
|
570
|
+
const cell = cells[slot.index];
|
|
571
|
+
const span = row === undefined ? undefined : spans?.row(row)?.get(slot.index - utilityCells);
|
|
572
|
+
const width = offsets[slot.index + (slot.span ?? 1)] - offsets[slot.index];
|
|
573
|
+
if (span && span.row !== row)
|
|
574
|
+
return _jsx(View, { style: { width }, importantForAccessibility: "no" }, cell.key);
|
|
575
|
+
const tall = spanRowHeight && span && span.rows > 1 ? spanRowHeight * span.rows : undefined;
|
|
576
|
+
const dataCell = row !== undefined && slot.index >= utilityCells && slot.index < ordered.length + utilityCells;
|
|
577
|
+
const boundedEditor = spanRowHeight &&
|
|
578
|
+
row !== undefined &&
|
|
579
|
+
editing.draft &&
|
|
580
|
+
displayedIds[row] === editing.draft.cell.rowId &&
|
|
581
|
+
ordered[slot.index - utilityCells]?.id === editing.draft.cell.columnId;
|
|
582
|
+
const semantic = Platform.OS === 'web' && !header
|
|
583
|
+
? {
|
|
584
|
+
role: (keyboardNavigation ? 'gridcell' : 'cell'),
|
|
585
|
+
'aria-rowspan': span && span.rows > 1 ? span.rows : undefined,
|
|
586
|
+
'aria-colspan': span && span.columns > 1 ? span.columns : undefined,
|
|
587
|
+
}
|
|
588
|
+
: {};
|
|
589
|
+
const pinnedRight = cell.pin === 'end';
|
|
590
|
+
const translate = canPin && cell.pin
|
|
591
|
+
? scrollX.interpolate({
|
|
592
|
+
inputRange: [0, maxScroll],
|
|
593
|
+
outputRange: pinnedRight ? [-maxScroll, 0] : [0, maxScroll],
|
|
594
|
+
extrapolate: 'clamp',
|
|
595
|
+
})
|
|
596
|
+
: undefined;
|
|
597
|
+
return (_jsx(Animated.View, { role: header ? 'columnheader' : 'cell', ...semantic, ...(dataCell ? drag.cellEvents(pointAddress({ row, column: slot.index - utilityCells })) : {}), style: {
|
|
598
|
+
width,
|
|
599
|
+
...(Platform.OS === 'web' && drag.armed && dataCell ? { touchAction: 'none' } : {}),
|
|
600
|
+
...(tall ? { height: tall, alignSelf: 'flex-start', borderBottomWidth: 1 } : {}),
|
|
601
|
+
flexShrink: 0,
|
|
602
|
+
backgroundColor: background,
|
|
603
|
+
paddingVertical: boundedEditor ? 0 : header ? spacing / 2 : spacing,
|
|
604
|
+
paddingHorizontal: spacing,
|
|
605
|
+
justifyContent: 'center',
|
|
606
|
+
borderEndWidth: bordered ? 1 : 0,
|
|
607
|
+
borderColor: theme.colors.border,
|
|
608
|
+
zIndex: (translate ? 2 : 0) + (tall ? 1 : 0),
|
|
609
|
+
direction,
|
|
610
|
+
transform: [...(translate ? [{ translateX: translate }] : []), ...(rtl ? [{ scaleX: -1 }] : [])],
|
|
611
|
+
}, children: render(slot.index) }, cell.key));
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
function select(next) {
|
|
615
|
+
if (onSelectionChange?.(next) !== false)
|
|
616
|
+
changeSelection(next);
|
|
617
|
+
}
|
|
618
|
+
function setColumnOrder(next) {
|
|
619
|
+
const known = new Set(definitions.map((column) => column.id));
|
|
620
|
+
const cleaned = [...new Set(next.filter((id) => known.has(id)))];
|
|
621
|
+
if (onColumnOrderChange?.(cleaned) === false)
|
|
622
|
+
return false;
|
|
623
|
+
setOrder(cleaned);
|
|
624
|
+
return true;
|
|
625
|
+
}
|
|
626
|
+
function setHiddenColumns(next) {
|
|
627
|
+
const known = new Set(definitions.map((column) => column.id));
|
|
628
|
+
const cleaned = [...new Set(next.filter((id) => known.has(id)))];
|
|
629
|
+
if (onHiddenColumnsChange?.(cleaned) === false)
|
|
630
|
+
return false;
|
|
631
|
+
setHidden(cleaned);
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
634
|
+
function setPage(next) {
|
|
635
|
+
if (onPageChange?.(next) !== false)
|
|
636
|
+
changePage(next);
|
|
637
|
+
}
|
|
638
|
+
function toggleSort(column) {
|
|
639
|
+
const active = sorting.find((entry) => entry.key === column);
|
|
640
|
+
const next = !active
|
|
641
|
+
? { key: column, direction: 'ascending' }
|
|
642
|
+
: active.direction === 'ascending'
|
|
643
|
+
? { key: column, direction: 'descending' }
|
|
644
|
+
: null;
|
|
645
|
+
if (multiple) {
|
|
646
|
+
const model = active
|
|
647
|
+
? sorting.flatMap((entry) => (entry.key === column ? (next ? [next] : []) : [entry]))
|
|
648
|
+
: next
|
|
649
|
+
? [...sorting, next]
|
|
650
|
+
: sorting;
|
|
651
|
+
if (onSortingChange?.(model) === false)
|
|
652
|
+
return;
|
|
653
|
+
setSortModel(model);
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
if (onSortChange?.(next) === false)
|
|
657
|
+
return;
|
|
658
|
+
changeSort(next);
|
|
659
|
+
}
|
|
660
|
+
if (effectivePage !== 1)
|
|
661
|
+
setPage(1);
|
|
662
|
+
}
|
|
663
|
+
function toggleExpand(id) {
|
|
664
|
+
const next = expanded.includes(id) ? expanded.filter((key) => key !== id) : [...expanded, id];
|
|
665
|
+
if (onExpandedChange?.(next) !== false)
|
|
666
|
+
changeExpanded(next);
|
|
667
|
+
}
|
|
668
|
+
const allSelected = ids.length > 0 && ids.every((id) => selection.includes(id));
|
|
669
|
+
const someSelected = ids.some((id) => selection.includes(id));
|
|
670
|
+
function renderHeaderCell(index) {
|
|
671
|
+
if (selectable && index === 0)
|
|
672
|
+
return (_jsx(Checkbox, { size: "sm", accessibilityLabel: messages.selectAll, checked: allSelected, indeterminate: !allSelected && someSelected, disabled: !ids.length, onCheckedChange: () => select(allSelected ? selection.filter((id) => !ids.includes(id)) : [...new Set([...selection, ...ids])]) }));
|
|
673
|
+
if (index < utilityCells)
|
|
674
|
+
return null;
|
|
675
|
+
const column = ordered[index - utilityCells];
|
|
676
|
+
if (!column)
|
|
677
|
+
return _jsx(TableHeader, { children: messages.actions });
|
|
678
|
+
const label = column.renderHeader?.({ sort: sorting[0] ?? null, sorting, column }) ?? column.heading;
|
|
679
|
+
const priority = sorting.findIndex((entry) => entry.key === column.id);
|
|
680
|
+
const sortedDirection = sorting[priority]?.direction;
|
|
681
|
+
const minimum = Number.isFinite(column.minWidth) ? Math.max(44, column.minWidth ?? 64) : 64;
|
|
682
|
+
const maximum = Number.isFinite(column.maxWidth)
|
|
683
|
+
? Math.max(minimum, column.maxWidth ?? 640)
|
|
684
|
+
: Math.max(minimum, 640);
|
|
685
|
+
return (_jsxs(View, { style: { flexDirection: 'row', flex: 1, alignItems: 'center' }, children: [column.sortable ? (_jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: sortedDirection
|
|
686
|
+
? messages.sortedColumn(column.heading, sortedDirection) +
|
|
687
|
+
(sorting.length > 1 ? ', ' + messages.tableSortPriority(priority + 1) : '')
|
|
688
|
+
: column.heading, onPress: () => toggleSort(column.id), style: { flex: 1, minHeight: 44, justifyContent: 'center' }, children: [_jsx(TextContent, { style: { fontWeight: '700', color: theme.colors.text }, children: label }), sortedDirection && (_jsxs(Text, { accessible: false, style: { color: theme.colors.accent }, children: [sortedDirection === 'ascending' ? '↑' : '↓', sorting.length > 1 ? priority + 1 : ''] }))] })) : (_jsx(View, { style: { flex: 1 }, children: _jsx(TableHeader, { children: label }) })), column.resizable && (_jsx(ResizeGrip, { label: messages.resizeColumn(column.heading), width: cells[index].width, min: minimum, max: maximum, onResize: (width) => {
|
|
689
|
+
if (width === cells[index].width)
|
|
690
|
+
return;
|
|
691
|
+
const next = { ...widths, [column.id]: width };
|
|
692
|
+
if (onColumnWidthsChange?.(next) === false)
|
|
693
|
+
return;
|
|
694
|
+
setWidths(next);
|
|
695
|
+
onColumnResize?.(column.id, width);
|
|
696
|
+
} }))] }));
|
|
697
|
+
}
|
|
698
|
+
const groupedSlots = [];
|
|
699
|
+
for (const slot of slots) {
|
|
700
|
+
const previous = groupedSlots.at(-1);
|
|
701
|
+
if ('index' in slot && previous && 'index' in previous) {
|
|
702
|
+
const currentGroup = ordered[slot.index - utilityCells]?.group;
|
|
703
|
+
const previousGroup = ordered[previous.index - utilityCells]?.group;
|
|
704
|
+
const span = previous.span ?? 1;
|
|
705
|
+
if (currentGroup &&
|
|
706
|
+
currentGroup === previousGroup &&
|
|
707
|
+
cells[slot.index].pin === cells[previous.index].pin &&
|
|
708
|
+
previous.index + span === slot.index) {
|
|
709
|
+
groupedSlots[groupedSlots.length - 1] = { index: previous.index, span: span + 1 };
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
groupedSlots.push(slot);
|
|
714
|
+
}
|
|
715
|
+
const headerStyle = { flexDirection: 'row', borderBottomWidth: 1, borderColor: theme.colors.border };
|
|
716
|
+
const header = (_jsxs(_Fragment, { children: [ordered.some((column) => column.group) && (_jsx(View, { role: "row", style: headerStyle, children: renderCells((index) => {
|
|
717
|
+
const group = ordered[index - utilityCells]?.group;
|
|
718
|
+
return group ? _jsx(TableHeader, { children: renderColumnGroup?.(group) ?? group }) : null;
|
|
719
|
+
}, theme.colors.subtle, true, groupedSlots) })), _jsx(View, { role: "row", style: headerStyle, children: renderCells(renderHeaderCell, theme.colors.subtle, true) })] }));
|
|
720
|
+
function rowSlots(index) {
|
|
721
|
+
const sizes = new Map();
|
|
722
|
+
for (const [column, span] of spans?.row(index) ?? []) {
|
|
723
|
+
if (span.column === column && span.columns > 1)
|
|
724
|
+
sizes.set(column + utilityCells, span.columns);
|
|
725
|
+
}
|
|
726
|
+
return sizes.size ? tableSpanningSlots(slots, cells, offsets, sizes) : slots;
|
|
727
|
+
}
|
|
728
|
+
function renderDataCell(row, columnIndex) {
|
|
729
|
+
const column = ordered[columnIndex];
|
|
730
|
+
const id = rowId(row);
|
|
731
|
+
const cell = { rowId: id, columnId: column.id };
|
|
732
|
+
const label = messages.tableCellLabel(column.heading, id);
|
|
733
|
+
if (editing.draft && sameTableCell(cell, editing.draft.cell)) {
|
|
734
|
+
const editor = (_jsx(TableEditor, { column: column, row: row, value: editing.draft.value, label: label, error: editing.draft.error, onChange: editing.updateDraft, onSubmit: () => finishEditing(true), onCancel: keyboardNavigation ? () => finishEditing(false) : undefined }));
|
|
735
|
+
return spanRowHeight ? (_jsx(ScrollView, { nestedScrollEnabled: true, keyboardShouldPersistTaps: "handled", style: { maxHeight: '100%', flexGrow: 0 }, children: editor })) : (editor);
|
|
736
|
+
}
|
|
737
|
+
const value = getTableValue(row, column);
|
|
738
|
+
const name = column.editor?.type === 'select'
|
|
739
|
+
? column.editor.options?.find((option) => option.value === value)?.label
|
|
740
|
+
: undefined;
|
|
741
|
+
const text = name ?? String(value ?? '');
|
|
742
|
+
const content = _jsx(TableCell, { children: column.renderCell?.(row) ?? text });
|
|
743
|
+
const canEdit = editing.editable(cell) && !editBlocked;
|
|
744
|
+
if (!keyboardNavigation && cellSelection === 'none' && !canEdit)
|
|
745
|
+
return content;
|
|
746
|
+
const display = displayRowIndex.get(id) ?? -1;
|
|
747
|
+
const bounds = previewBounds ?? editing.bounds;
|
|
748
|
+
const selected = Boolean(bounds && gridSpanIntersects(ownerAt({ row: display, column: columnIndex }), bounds));
|
|
749
|
+
const key = cellKey(cell);
|
|
750
|
+
const press = {
|
|
751
|
+
accessibilityRole: 'button',
|
|
752
|
+
'aria-selected': cellSelection !== 'none' ? selected : undefined,
|
|
753
|
+
accessibilityState: { selected },
|
|
754
|
+
accessibilityLabel: text ? label + ', ' + text : label,
|
|
755
|
+
accessibilityHint: cellSelection === 'none' && canEdit ? messages.editValue : undefined,
|
|
756
|
+
onPress() {
|
|
757
|
+
if (drag.suppressPress())
|
|
758
|
+
return;
|
|
759
|
+
if (keyboardNavigation)
|
|
760
|
+
setCursor(cell);
|
|
761
|
+
if (cellSelection !== 'none' || canEdit)
|
|
762
|
+
editing.choose(cell);
|
|
763
|
+
},
|
|
764
|
+
style: ({ pressed }) => ({
|
|
765
|
+
flex: 1,
|
|
766
|
+
minHeight: 44,
|
|
767
|
+
userSelect: dragSelection ? 'none' : undefined,
|
|
768
|
+
padding: theme.space,
|
|
769
|
+
justifyContent: 'center',
|
|
770
|
+
borderRadius: theme.radius / 2,
|
|
771
|
+
borderWidth: 1,
|
|
772
|
+
borderColor: focused === key || selected ? theme.colors.accent : 'transparent',
|
|
773
|
+
backgroundColor: selected || pressed ? theme.colors.subtle : 'transparent',
|
|
774
|
+
}),
|
|
775
|
+
};
|
|
776
|
+
return keyboardNavigation ? (_jsx(KeyboardCell, { ...press, tabIndex: key === currentKey && !editing.draft ? 0 : -1, onFocus: () => recordFocus(cell), onBlur: () => setFocused((previous) => (previous === key ? null : previous)), focusRef: (host) => registerFocus(key, host), handleKey: (event) => handleCellKey(event, cell), children: content })) : (_jsx(Pressable, { ...press, children: content }));
|
|
777
|
+
}
|
|
778
|
+
function renderRow(row, index, layer) {
|
|
779
|
+
const id = rowId(row);
|
|
780
|
+
const checked = selection.includes(id);
|
|
781
|
+
const isExpanded = expanded.includes(id);
|
|
782
|
+
const position = displayRowIndex.get(id) ?? -1;
|
|
783
|
+
const background = checked || activeKeys?.includes(id) || (striped && index % 2 !== 0) ? theme.colors.subtle : theme.colors.surface;
|
|
784
|
+
return (_jsxs(View, { style: layer > 1 ? { zIndex: layer } : undefined, children: [_jsx(View, { ref: dragSelection ? (view) => drag.row(position, view) : undefined, collapsable: !dragSelection, role: "row", style: [
|
|
785
|
+
headerStyle,
|
|
786
|
+
spanRowHeight
|
|
787
|
+
? { height: spanRowHeight, overflow: 'visible' }
|
|
788
|
+
: fixedRowHeight
|
|
789
|
+
? { height: fixedRowHeight, overflow: 'hidden' }
|
|
790
|
+
: undefined,
|
|
791
|
+
], children: renderCells((cell) => {
|
|
792
|
+
if (selectable && cell === 0)
|
|
793
|
+
return (_jsx(Checkbox, { size: "sm", accessibilityLabel: messages.selectRow(id), checked: checked, onCheckedChange: () => select(checked ? selection.filter((key) => key !== id) : [...selection, id]) }));
|
|
794
|
+
if (cell < utilityCells)
|
|
795
|
+
return (_jsx(Button, { size: "sm", variant: "text", accessibilityLabel: isExpanded ? messages.collapseItem(String(id)) : messages.expandItem(String(id)), accessibilityState: { expanded: isExpanded }, onPress: () => toggleExpand(id), children: isExpanded ? '−' : '+' }));
|
|
796
|
+
const column = cell - utilityCells;
|
|
797
|
+
return column < ordered.length ? (renderDataCell(row, column)) : (_jsx(TableRowActions, { children: renderRowActions?.(row) }));
|
|
798
|
+
}, background, false, rowSlots(position), position) }), renderRowDetail && isExpanded && (_jsx(TableRowDetail, { style: { direction, transform: rtl ? [{ scaleX: -1 }] : undefined }, children: renderRowDetail(row) }))] }, modelKey(id)));
|
|
799
|
+
}
|
|
800
|
+
function renderEntry(entry) {
|
|
801
|
+
return entry.kind === 'rows' ? (_jsx(View, { children: entry.rows.map(({ row, index }, layer) => renderRow(row, index, entry.rows.length - layer)) })) : (_jsx(Text, { accessibilityRole: "header", style: {
|
|
802
|
+
backgroundColor: theme.colors.subtle,
|
|
803
|
+
color: theme.colors.text,
|
|
804
|
+
fontWeight: '700',
|
|
805
|
+
padding: spacing,
|
|
806
|
+
direction,
|
|
807
|
+
transform: rtl ? [{ scaleX: -1 }] : undefined,
|
|
808
|
+
}, children: entry.label }));
|
|
809
|
+
}
|
|
810
|
+
const bodyEmpty = ids.length === 0 && !remote.loading && !remote.failed ? (_jsx(View, { style: { direction, transform: rtl ? [{ scaleX: -1 }] : undefined }, children: _jsx(TextContent, { style: { color: theme.colors.muted, padding: spacing }, children: empty ?? messages.noResults }) })) : null;
|
|
811
|
+
function exportData({ format = 'csv', rows: scope = 'filtered', includeHeaders = true, escapeFormulas = true, } = {}) {
|
|
812
|
+
const byId = new Map(rows.map((row) => [rowId(row), row]));
|
|
813
|
+
const chosen = scope === 'all'
|
|
814
|
+
? rows
|
|
815
|
+
: scope === 'page'
|
|
816
|
+
? displayedIds.flatMap((id) => {
|
|
817
|
+
const row = byId.get(id);
|
|
818
|
+
return row === undefined ? [] : [row];
|
|
819
|
+
})
|
|
820
|
+
: scope === 'selected'
|
|
821
|
+
? sorted.filter((row) => selection.includes(rowId(row)))
|
|
822
|
+
: sorted;
|
|
823
|
+
if (format === 'json')
|
|
824
|
+
return JSON.stringify(chosen.map((row) => Object.fromEntries(ordered.map((column) => [column.id, getTableValue(row, column) ?? null]))), null, 2);
|
|
825
|
+
return formatTableFields([
|
|
826
|
+
...(includeHeaders ? [ordered.map((column) => column.heading)] : []),
|
|
827
|
+
...chosen.map((row) => ordered.map((column) => getTableValue(row, column))),
|
|
828
|
+
], format === 'csv' ? ',' : '\t', escapeFormulas);
|
|
829
|
+
}
|
|
830
|
+
const beginEdit = (cell) => displayedIds.includes(cell.rowId) && !editBlocked && editing.begin(cell);
|
|
831
|
+
useImperativeHandle(ref, () => ({
|
|
832
|
+
selectRange: editing.select,
|
|
833
|
+
beginEdit,
|
|
834
|
+
saveEdit: () => finishEditing(true),
|
|
835
|
+
cancelEdit: () => {
|
|
836
|
+
finishEditing(false);
|
|
837
|
+
},
|
|
838
|
+
copySelection: editing.copySelection,
|
|
839
|
+
pasteSelection: editing.pasteSelection,
|
|
840
|
+
fillSelection: editing.fillSelection,
|
|
841
|
+
undo: editing.undo,
|
|
842
|
+
redo: editing.redo,
|
|
843
|
+
exportData,
|
|
844
|
+
setColumnOrder,
|
|
845
|
+
setHiddenColumns,
|
|
846
|
+
focusCell,
|
|
847
|
+
handleKey: handleCellKey,
|
|
848
|
+
refresh: remote.refresh,
|
|
849
|
+
}));
|
|
850
|
+
const cellActions = cellSelection !== 'none' && (editing.bounds || editing.canUndo || editing.canRedo);
|
|
851
|
+
return (_jsxs(View, { ...props, style: [{ gap: theme.space * 2, direction }, style], children: [sections.named.toolbar, filterable && (_jsx(Input, { label: messages.search, value: query, onChangeText: (text) => {
|
|
852
|
+
changeQuery(text);
|
|
853
|
+
if (effectivePage !== 1)
|
|
854
|
+
setPage(1);
|
|
855
|
+
} })), selection.length > 0 && (renderSelectionActions?.(selection) ?? sections.named.selection), dragSelection && cellSelection === 'range' && !editing.draft && displayed.length > 0 && (_jsx(TableToolbar, { children: _jsx(Button, { size: "sm", variant: "outlined", pressed: drag.armed, onPress: drag.toggle, children: messages.tableDragSelection }) })), editing.draft ? (_jsxs(TableToolbar, { children: [_jsx(Button, { size: "sm", onPress: () => finishEditing(true), children: messages.saveValue }), _jsx(Button, { size: "sm", variant: "text", onPress: () => finishEditing(false), children: messages.cancel })] })) : (showCellActions &&
|
|
856
|
+
cellActions && (_jsxs(TableToolbar, { children: [editing.bounds && editing.range && (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", variant: "outlined", disabled: editBlocked || !editing.editable(editing.range.focus), onPress: () => editing.range && beginEdit(editing.range.focus), children: messages.editValue }), cellSelection === 'range' && (_jsx(Button, { size: "sm", variant: editing.extending ? 'outlined' : 'text', accessibilityState: { selected: editing.extending }, onPress: () => editing.setExtending((active) => !active), children: messages.tableExtendSelection })), clipboard?.writeText && (_jsx(Button, { size: "sm", variant: "text", onPress: () => {
|
|
857
|
+
void editing.copySelection();
|
|
858
|
+
}, children: messages.tableCopyCells })), clipboard?.readText && (_jsx(Button, { size: "sm", variant: "text", disabled: editBlocked, onPress: () => {
|
|
859
|
+
void editing.pasteSelection();
|
|
860
|
+
}, children: messages.tablePasteCells })), cellSelection === 'range' &&
|
|
861
|
+
(editing.bounds.top !== editing.bounds.bottom || editing.bounds.start !== editing.bounds.end) && (_jsx(Button, { size: "sm", variant: "text", disabled: editBlocked, onPress: editing.fillSelection, children: messages.tableFillCells })), _jsx(Button, { size: "sm", variant: "text", onPress: () => {
|
|
862
|
+
editing.select(null);
|
|
863
|
+
editing.setExtending(false);
|
|
864
|
+
}, children: messages.clearSelection })] })), editing.canUndo && (_jsx(Button, { size: "sm", variant: "text", onPress: editing.undo, children: messages.tableUndo })), editing.canRedo && (_jsx(Button, { size: "sm", variant: "text", onPress: editing.redo, children: messages.tableRedo }))] }))), !editing.draft && cellSelection === 'none' && showCellActions && (editing.canUndo || editing.canRedo) && (_jsxs(TableToolbar, { children: [editing.canUndo && (_jsx(Button, { size: "sm", variant: "text", onPress: editing.undo, children: messages.tableUndo })), editing.canRedo && (_jsx(Button, { size: "sm", variant: "text", onPress: editing.redo, children: messages.tableRedo }))] })), _jsx(FieldMessage, { message: editing.error, invalid: Boolean(editing.error), theme: theme }), remote.loading && (_jsx(Text, { accessibilityLiveRegion: "polite", style: { color: theme.colors.muted }, children: messages.loading })), remote.failed && (_jsxs(TableToolbar, { children: [_jsx(FieldMessage, { message: messages.tableDataError, invalid: true, theme: theme }), _jsx(Button, { size: "sm", variant: "outlined", onPress: remote.refresh, children: messages.retry })] })), _jsx(View, { ...drag.events, ref: drag.viewportRef, collapsable: false, style: {
|
|
865
|
+
height,
|
|
866
|
+
minWidth: 0,
|
|
867
|
+
borderWidth: bordered ? 1 : 0,
|
|
868
|
+
borderColor: theme.colors.border,
|
|
869
|
+
borderRadius: theme.radius,
|
|
870
|
+
overflow: 'hidden',
|
|
871
|
+
...(Platform.OS === 'web' && drag.armed ? { touchAction: 'none' } : {}),
|
|
872
|
+
}, children: _jsx(Animated.ScrollView, { ref: horizontal, horizontal: true, scrollEnabled: !drag.armed, nestedScrollEnabled: true, keyboardShouldPersistTaps: "handled", scrollEventThrottle: 16, style: { direction: 'ltr', transform: rtl ? [{ scaleX: -1 }] : undefined }, onLayout: (event) => setViewport(event.nativeEvent.layout.width), onScroll: Animated.event([{ nativeEvent: { contentOffset: { x: scrollX } } }], {
|
|
873
|
+
useNativeDriver: true,
|
|
874
|
+
listener: scrollColumns,
|
|
875
|
+
}), children: _jsxs(View, { role: keyboardNavigation ? 'grid' : 'table', style: {
|
|
876
|
+
width: contentWidth || undefined,
|
|
877
|
+
flexDirection: 'column',
|
|
878
|
+
direction: 'ltr',
|
|
879
|
+
...(height ? { height: '100%', minHeight: 0 } : {}),
|
|
880
|
+
}, children: [stickyHeader && header, pinnedStartBlocks.map((block) => (_jsx(View, { children: renderEntry(block) }, block.id))), _jsx(View, { ref: drag.bodyRef, collapsable: false, style: height ? { flex: 1, minHeight: 0 } : undefined, onLayout: ({ nativeEvent }) => {
|
|
881
|
+
bodyHeight.current = nativeEvent.layout.height;
|
|
882
|
+
}, children: virtualized && height ? (_jsx(FlatList, { ref: virtualRows, data: bodyBlocks, nestedScrollEnabled: true, scrollEnabled: !drag.armed, keyboardShouldPersistTaps: "handled", keyExtractor: (entry) => entry.id, renderItem: ({ item }) => renderEntry(item), getItemLayout: fixedRowHeight
|
|
883
|
+
? (_, index) => ({
|
|
884
|
+
index,
|
|
885
|
+
length: blockOffsets[index + 1] - blockOffsets[index],
|
|
886
|
+
offset: blockOffsets[index],
|
|
887
|
+
})
|
|
888
|
+
: undefined, ListHeaderComponent: stickyHeader ? undefined : header, ListEmptyComponent: bodyEmpty, onScroll: (event) => {
|
|
889
|
+
physicalY.current = event.nativeEvent.contentOffset.y;
|
|
890
|
+
}, onContentSizeChange: (_width, height) => {
|
|
891
|
+
bodyContentHeight.current = height;
|
|
892
|
+
}, scrollEventThrottle: 16, onScrollToIndexFailed: ({ index, averageItemLength }) => virtualRows.current?.scrollToOffset({
|
|
893
|
+
offset: index * Math.max(averageItemLength, 56),
|
|
894
|
+
animated: false,
|
|
895
|
+
}) })) : (_jsxs(ScrollView, { ref: vertical, nestedScrollEnabled: true, keyboardShouldPersistTaps: "handled", scrollEnabled: Boolean(height) && !drag.armed, onScroll: (event) => {
|
|
896
|
+
physicalY.current = event.nativeEvent.contentOffset.y;
|
|
897
|
+
}, onContentSizeChange: (_width, height) => {
|
|
898
|
+
bodyContentHeight.current = height;
|
|
899
|
+
}, scrollEventThrottle: 16, children: [!stickyHeader && header, bodyBlocks.map((entry) => (_jsx(View, { children: renderEntry(entry) }, entry.id))), bodyEmpty] })) }), pinnedEndBlocks.map((block) => (_jsx(View, { children: renderEntry(block) }, block.id)))] }) }) }), pageLength !== undefined && !remote.failed && (_jsx(Pagination, { variant: "compact", pageSize: pageLength, totalPages: pageCount, page: effectivePage, disabled: remote.loading, onPageChange: setPage })), sections.named.summary] }));
|
|
900
|
+
}
|
|
901
|
+
export const DataGrid = Table;
|
|
902
|
+
export function TableColumn({ children }) {
|
|
903
|
+
return _jsx(_Fragment, { children: children });
|
|
904
|
+
}
|
|
905
|
+
export function TableCell({ children, style, ...props }) {
|
|
906
|
+
const theme = useTramaTheme();
|
|
907
|
+
return (_jsx(View, { ...props, style: style, children: _jsx(TextContent, { style: { color: theme.colors.text, fontSize: theme.fontSize }, children: children }) }));
|
|
908
|
+
}
|
|
909
|
+
export function TableHeader({ children, style, ...props }) {
|
|
910
|
+
const theme = useTramaTheme();
|
|
911
|
+
return (_jsx(View, { ...props, style: style, children: _jsx(TextContent, { style: { color: theme.colors.text, fontWeight: '700' }, children: children }) }));
|
|
912
|
+
}
|
|
913
|
+
export function TableRowActions(props) {
|
|
914
|
+
return _jsx(Cluster, { gap: "xs", ...props });
|
|
915
|
+
}
|
|
916
|
+
export function TableRowDetail(props) {
|
|
917
|
+
const theme = useTramaTheme();
|
|
918
|
+
return _jsx(View, { ...props, style: [{ padding: theme.space * 3, backgroundColor: theme.colors.subtle }, props.style] });
|
|
919
|
+
}
|
|
920
|
+
export function TableSelectionActions(props) {
|
|
921
|
+
return _jsx(Cluster, { gap: "xs", ...props });
|
|
922
|
+
}
|
|
923
|
+
export function TableSummary(props) {
|
|
924
|
+
return _jsx(TableCell, { ...props });
|
|
925
|
+
}
|
|
926
|
+
export function TableToolbar(props) {
|
|
927
|
+
return _jsx(Cluster, { ...props });
|
|
928
|
+
}
|