react-glide-table 2.3.4 → 2.3.6
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/README.md +80 -4
- package/dist/compound.cjs +1279 -360
- package/dist/compound.d.cts +13 -4
- package/dist/compound.d.ts +13 -4
- package/dist/compound.js +1295 -372
- package/dist/core.cjs +1661 -1002
- package/dist/core.d.cts +100 -15
- package/dist/core.d.ts +100 -15
- package/dist/core.js +1682 -1024
- package/dist/index.cjs +1864 -944
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1883 -960
- package/dist/{types-hf2ruVdu.d.cts → types-CecIIMV1.d.cts} +101 -6
- package/dist/{types-hf2ruVdu.d.ts → types-CecIIMV1.d.ts} +101 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -56,6 +56,7 @@ __export(src_exports, {
|
|
|
56
56
|
createSearchRegex: () => createSearchRegex,
|
|
57
57
|
createTable: () => createTable,
|
|
58
58
|
escapeSearchRegex: () => escapeSearchRegex,
|
|
59
|
+
escapeSpreadsheetFormula: () => escapeSpreadsheetFormula,
|
|
59
60
|
flattenSubtreeRows: () => flattenSubtreeRows,
|
|
60
61
|
formatCellValue: () => formatCellValue,
|
|
61
62
|
formatDefaultCellValue: () => formatDefaultCellValue,
|
|
@@ -106,6 +107,163 @@ __export(src_exports, {
|
|
|
106
107
|
});
|
|
107
108
|
module.exports = __toCommonJS(src_exports);
|
|
108
109
|
|
|
110
|
+
// src/components/ui/table/features/inline-search/inlineSearch.ts
|
|
111
|
+
var INLINE_SEARCH_MAX_RESULTS = 1e3;
|
|
112
|
+
var INLINE_SEARCH_TARGET_TICK_MS = 10;
|
|
113
|
+
var INLINE_SEARCH_INITIAL_STRIDE = 10;
|
|
114
|
+
function escapeSearchRegex(value) {
|
|
115
|
+
return value.replace(/([$()*+.?[\\\]^{|}-])/g, "\\$1");
|
|
116
|
+
}
|
|
117
|
+
function createSearchRegex(query) {
|
|
118
|
+
const trimmed = query.trim();
|
|
119
|
+
if (!trimmed) return null;
|
|
120
|
+
return new RegExp(escapeSearchRegex(trimmed), "i");
|
|
121
|
+
}
|
|
122
|
+
function cellValueToSearchText(value) {
|
|
123
|
+
if (value == null) return void 0;
|
|
124
|
+
if (typeof value === "string") return value;
|
|
125
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
126
|
+
return String(value);
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
return value.map((item) => cellValueToSearchText(item) ?? "").join(" ");
|
|
130
|
+
}
|
|
131
|
+
if (typeof value === "object") {
|
|
132
|
+
try {
|
|
133
|
+
return JSON.stringify(value);
|
|
134
|
+
} catch {
|
|
135
|
+
return String(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return String(value);
|
|
139
|
+
}
|
|
140
|
+
function formatSearchResultLabel(status) {
|
|
141
|
+
const countLabel = status.results >= INLINE_SEARCH_MAX_RESULTS ? `over ${INLINE_SEARCH_MAX_RESULTS}` : `${status.results} result${status.results !== 1 ? "s" : ""}`;
|
|
142
|
+
if (status.selectedIndex >= 0 && status.results > 0) {
|
|
143
|
+
return `${status.selectedIndex + 1} of ${countLabel}`;
|
|
144
|
+
}
|
|
145
|
+
return countLabel;
|
|
146
|
+
}
|
|
147
|
+
function nextSearchIndex(selectedIndex, results) {
|
|
148
|
+
if (results <= 0) return -1;
|
|
149
|
+
if (selectedIndex < 0) return 0;
|
|
150
|
+
return (selectedIndex + 1) % results;
|
|
151
|
+
}
|
|
152
|
+
function previousSearchIndex(selectedIndex, results) {
|
|
153
|
+
if (results <= 0) return -1;
|
|
154
|
+
if (selectedIndex < 0) return results - 1;
|
|
155
|
+
let next = (selectedIndex - 1) % results;
|
|
156
|
+
if (next < 0) next += results;
|
|
157
|
+
return next;
|
|
158
|
+
}
|
|
159
|
+
function buildSearchMatchKey(colIndex, rowIndex) {
|
|
160
|
+
return `${colIndex}:${rowIndex}`;
|
|
161
|
+
}
|
|
162
|
+
function buildSearchMatchKeys(results) {
|
|
163
|
+
const keys = /* @__PURE__ */ new Set();
|
|
164
|
+
for (const [colIndex, rowIndex] of results) {
|
|
165
|
+
keys.add(buildSearchMatchKey(colIndex, rowIndex));
|
|
166
|
+
}
|
|
167
|
+
return keys;
|
|
168
|
+
}
|
|
169
|
+
function collectSearchMatchesInRange(options) {
|
|
170
|
+
const {
|
|
171
|
+
query,
|
|
172
|
+
startRow,
|
|
173
|
+
rowCount,
|
|
174
|
+
columnCount,
|
|
175
|
+
getCellValue,
|
|
176
|
+
maxResults = INLINE_SEARCH_MAX_RESULTS
|
|
177
|
+
} = options;
|
|
178
|
+
const regex = createSearchRegex(query);
|
|
179
|
+
if (!regex || rowCount <= 0 || columnCount <= 0) return [];
|
|
180
|
+
const matches = [];
|
|
181
|
+
for (let rowOffset = 0; rowOffset < rowCount; rowOffset += 1) {
|
|
182
|
+
const rowIndex = startRow + rowOffset;
|
|
183
|
+
for (let colIndex = 0; colIndex < columnCount; colIndex += 1) {
|
|
184
|
+
const text = cellValueToSearchText(getCellValue(rowIndex, colIndex));
|
|
185
|
+
if (text !== void 0 && regex.test(text)) {
|
|
186
|
+
matches.push([colIndex, rowIndex]);
|
|
187
|
+
if (matches.length >= maxResults) {
|
|
188
|
+
return matches;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return matches;
|
|
194
|
+
}
|
|
195
|
+
function nextSearchStride(currentStride, elapsedMs, targetMs = INLINE_SEARCH_TARGET_TICK_MS) {
|
|
196
|
+
const rounded = Math.max(elapsedMs, 1);
|
|
197
|
+
const scalar = targetMs / rounded;
|
|
198
|
+
return Math.max(1, Math.ceil(currentStride * scalar));
|
|
199
|
+
}
|
|
200
|
+
function buildFlatSearchCorpus(rows, getRowId) {
|
|
201
|
+
return rows.map((data, index) => ({
|
|
202
|
+
id: getRowId(data, index),
|
|
203
|
+
data,
|
|
204
|
+
ancestorToggleKeys: []
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
function buildTreeSearchCorpus(visibleRows, options) {
|
|
208
|
+
const { toggleField, getRowId } = options;
|
|
209
|
+
const corpus = [];
|
|
210
|
+
const seen = /* @__PURE__ */ new Set();
|
|
211
|
+
const walk = (node, ancestorToggleKeys) => {
|
|
212
|
+
const id = getRowId(node, corpus.length);
|
|
213
|
+
if (seen.has(id)) return;
|
|
214
|
+
seen.add(id);
|
|
215
|
+
corpus.push({
|
|
216
|
+
id,
|
|
217
|
+
data: node,
|
|
218
|
+
ancestorToggleKeys
|
|
219
|
+
});
|
|
220
|
+
const children = node.children;
|
|
221
|
+
if (!Array.isArray(children) || children.length === 0) return;
|
|
222
|
+
const toggleValue = node[toggleField];
|
|
223
|
+
const toggleKey = toggleValue === null || toggleValue === void 0 ? "" : String(toggleValue);
|
|
224
|
+
const childAncestors = toggleKey.length > 0 ? [...ancestorToggleKeys, toggleKey] : ancestorToggleKeys;
|
|
225
|
+
for (const child of children) {
|
|
226
|
+
if (child && typeof child === "object") {
|
|
227
|
+
walk(child, childAncestors);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
for (const row of visibleRows) {
|
|
232
|
+
const level = row.level;
|
|
233
|
+
if (level === 0 || level === void 0) {
|
|
234
|
+
walk(row, []);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
for (const row of visibleRows) {
|
|
238
|
+
const id = getRowId(row, corpus.length);
|
|
239
|
+
if (seen.has(id)) continue;
|
|
240
|
+
walk(row, []);
|
|
241
|
+
}
|
|
242
|
+
return corpus;
|
|
243
|
+
}
|
|
244
|
+
function mapSearchResultsToVisibleKeys(results, corpus, visibleRowIndexById) {
|
|
245
|
+
const keys = /* @__PURE__ */ new Set();
|
|
246
|
+
for (const [colIndex, corpusRowIndex] of results) {
|
|
247
|
+
const corpusRow = corpus[corpusRowIndex];
|
|
248
|
+
if (!corpusRow) continue;
|
|
249
|
+
const visibleRowIndex = visibleRowIndexById.get(corpusRow.id);
|
|
250
|
+
if (visibleRowIndex === void 0) continue;
|
|
251
|
+
keys.add(buildSearchMatchKey(colIndex, visibleRowIndex));
|
|
252
|
+
}
|
|
253
|
+
return keys;
|
|
254
|
+
}
|
|
255
|
+
function mapSearchResultToVisibleItem(item, corpus, visibleRowIndexById) {
|
|
256
|
+
const [colIndex, corpusRowIndex] = item;
|
|
257
|
+
const corpusRow = corpus[corpusRowIndex];
|
|
258
|
+
if (!corpusRow) return null;
|
|
259
|
+
const visibleRowIndex = visibleRowIndexById.get(corpusRow.id);
|
|
260
|
+
if (visibleRowIndex === void 0) return null;
|
|
261
|
+
return [colIndex, visibleRowIndex];
|
|
262
|
+
}
|
|
263
|
+
function collectAncestorKeysToExpand(corpusRow, expandedRows) {
|
|
264
|
+
return corpusRow.ancestorToggleKeys.filter((key) => !expandedRows.has(key));
|
|
265
|
+
}
|
|
266
|
+
|
|
109
267
|
// src/core/labels.ts
|
|
110
268
|
var DEFAULT_DATA_TABLE_LABELS = {
|
|
111
269
|
empty: "No data",
|
|
@@ -119,7 +277,11 @@ var DEFAULT_DATA_TABLE_LABELS = {
|
|
|
119
277
|
searchResultHint: "Type to search",
|
|
120
278
|
searchPrevious: "Previous result",
|
|
121
279
|
searchNext: "Next result",
|
|
122
|
-
searchClose: "Close search"
|
|
280
|
+
searchClose: "Close search",
|
|
281
|
+
searchResultCount: formatSearchResultLabel,
|
|
282
|
+
protectedCell: "protected",
|
|
283
|
+
paginationPrevious: "Previous page",
|
|
284
|
+
paginationNext: "Next page"
|
|
123
285
|
};
|
|
124
286
|
function resolveDataTableLabels(partial) {
|
|
125
287
|
return {
|
|
@@ -159,6 +321,61 @@ var DATA_TABLE_COLUMN_REORDER_THRESHOLD = 4;
|
|
|
159
321
|
// src/components/ui/table/features/cell-edit/useCellEdit.ts
|
|
160
322
|
var import_react = require("react");
|
|
161
323
|
|
|
324
|
+
// src/components/ui/table/features/data-patch/dataPatch.ts
|
|
325
|
+
var TREE_SOURCE = /* @__PURE__ */ Symbol("react-glide-table.treeSource");
|
|
326
|
+
function getTreeSource(row) {
|
|
327
|
+
if (!row || typeof row !== "object") return void 0;
|
|
328
|
+
return row[TREE_SOURCE];
|
|
329
|
+
}
|
|
330
|
+
function getTreeRowKey(row) {
|
|
331
|
+
const source = getTreeSource(row);
|
|
332
|
+
if (!source) return void 0;
|
|
333
|
+
return `tree:${source.path.join(".")}`;
|
|
334
|
+
}
|
|
335
|
+
function setValueAtAccessor(record, accessorKey, value) {
|
|
336
|
+
if (!accessorKey.includes(".") || accessorKey in record) {
|
|
337
|
+
return { ...record, [accessorKey]: value };
|
|
338
|
+
}
|
|
339
|
+
const [head, ...rest] = accessorKey.split(".");
|
|
340
|
+
const current = record[head];
|
|
341
|
+
const child = current && typeof current === "object" && !Array.isArray(current) ? current : {};
|
|
342
|
+
return {
|
|
343
|
+
...record,
|
|
344
|
+
[head]: setValueAtAccessor(child, rest.join("."), value)
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function patchAtPath(nodes, path, childrenField, accessorKey, value) {
|
|
348
|
+
const [head, ...rest] = path;
|
|
349
|
+
if (head === void 0 || head < 0 || head >= nodes.length) return null;
|
|
350
|
+
const node = nodes[head];
|
|
351
|
+
if (!node || typeof node !== "object") return null;
|
|
352
|
+
const record = node;
|
|
353
|
+
let nextNode;
|
|
354
|
+
if (rest.length === 0) {
|
|
355
|
+
nextNode = setValueAtAccessor(record, accessorKey, value);
|
|
356
|
+
} else {
|
|
357
|
+
const children = record[childrenField];
|
|
358
|
+
if (!Array.isArray(children)) return null;
|
|
359
|
+
const nextChildren = patchAtPath(children, rest, childrenField, accessorKey, value);
|
|
360
|
+
if (!nextChildren) return null;
|
|
361
|
+
nextNode = { ...record, [childrenField]: nextChildren };
|
|
362
|
+
}
|
|
363
|
+
const next = nodes.slice();
|
|
364
|
+
next[head] = nextNode;
|
|
365
|
+
return next;
|
|
366
|
+
}
|
|
367
|
+
function applyCellChangesToData(data, changes) {
|
|
368
|
+
let next = data;
|
|
369
|
+
for (const change of changes) {
|
|
370
|
+
const source = getTreeSource(change.original);
|
|
371
|
+
const path = source ? source.path : [change.index];
|
|
372
|
+
const childrenField = source?.childrenField ?? "";
|
|
373
|
+
const patched = patchAtPath(next, path, childrenField, change.accessorKey, change.value);
|
|
374
|
+
if (patched) next = patched;
|
|
375
|
+
}
|
|
376
|
+
return next === data ? data.slice() : next;
|
|
377
|
+
}
|
|
378
|
+
|
|
162
379
|
// src/components/ui/table/features/cell-edit/cellEdit.ts
|
|
163
380
|
function getColumnAccessorKey(columnDef) {
|
|
164
381
|
if (columnDef.accessorKey !== void 0 && columnDef.accessorKey !== null) {
|
|
@@ -166,7 +383,11 @@ function getColumnAccessorKey(columnDef) {
|
|
|
166
383
|
}
|
|
167
384
|
return columnDef.id;
|
|
168
385
|
}
|
|
386
|
+
function isProtectedColumn(columnDef) {
|
|
387
|
+
return columnDef.meta?.kind === "protected";
|
|
388
|
+
}
|
|
169
389
|
function isColumnEditable(columnDef) {
|
|
390
|
+
if (isProtectedColumn(columnDef)) return false;
|
|
170
391
|
return Boolean(columnDef.meta?.editable);
|
|
171
392
|
}
|
|
172
393
|
function getColumnEditType(columnDef) {
|
|
@@ -199,10 +420,11 @@ function applyCellEdit(data, rows, rowIndex, colIndex, raw) {
|
|
|
199
420
|
if (!accessorKey) return null;
|
|
200
421
|
const parsed = parseCellEditValue(raw, getColumnEditType(columnDef));
|
|
201
422
|
if (!parsed.ok) return null;
|
|
202
|
-
const
|
|
203
|
-
if (!
|
|
204
|
-
|
|
205
|
-
|
|
423
|
+
const row = rows[rowIndex];
|
|
424
|
+
if (!row) return null;
|
|
425
|
+
return applyCellChangesToData(data, [
|
|
426
|
+
{ original: row.original, index: row.index, accessorKey, value: parsed.value }
|
|
427
|
+
]);
|
|
206
428
|
}
|
|
207
429
|
|
|
208
430
|
// src/components/ui/table/features/cell-render/commitCellValue.ts
|
|
@@ -226,12 +448,12 @@ function commitCellValue({
|
|
|
226
448
|
if (!cell) return false;
|
|
227
449
|
const accessorKey = getColumnAccessorKey(cell.column.columnDef);
|
|
228
450
|
if (!accessorKey) return false;
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
451
|
+
const next = applyCellChangesToData(data, [
|
|
452
|
+
{ original: row.original, index: row.index, accessorKey, value }
|
|
453
|
+
]);
|
|
454
|
+
if (next === data || next.every((item, index) => item === data[index])) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
235
457
|
onDataChange?.(next);
|
|
236
458
|
return true;
|
|
237
459
|
}
|
|
@@ -243,19 +465,36 @@ function useCellEdit({
|
|
|
243
465
|
onDataChange,
|
|
244
466
|
onCellChange
|
|
245
467
|
}) {
|
|
246
|
-
const [
|
|
468
|
+
const [editingKey, setEditingKey] = (0, import_react.useState)(null);
|
|
247
469
|
const [draftValue, setDraftValue] = (0, import_react.useState)("");
|
|
248
470
|
const draftValueRef = (0, import_react.useRef)(draftValue);
|
|
249
|
-
const
|
|
471
|
+
const [draftInvalid, setDraftInvalidState] = (0, import_react.useState)(false);
|
|
472
|
+
const draftInvalidRef = (0, import_react.useRef)(false);
|
|
473
|
+
const setDraftInvalid = (0, import_react.useCallback)((invalid) => {
|
|
474
|
+
draftInvalidRef.current = invalid;
|
|
475
|
+
setDraftInvalidState(invalid);
|
|
476
|
+
}, []);
|
|
250
477
|
(0, import_react.useEffect)(() => {
|
|
251
478
|
draftValueRef.current = draftValue;
|
|
252
479
|
}, [draftValue]);
|
|
480
|
+
const editingCell = (0, import_react.useMemo)(
|
|
481
|
+
() => resolveEditingCell(rows, editingKey),
|
|
482
|
+
[rows, editingKey]
|
|
483
|
+
);
|
|
484
|
+
const editingCellRef = (0, import_react.useRef)(editingCell);
|
|
485
|
+
editingCellRef.current = editingCell;
|
|
253
486
|
(0, import_react.useEffect)(() => {
|
|
254
|
-
|
|
255
|
-
|
|
487
|
+
if (editingKey && !editingCell) {
|
|
488
|
+
setEditingKey(null);
|
|
489
|
+
setDraftValue("");
|
|
490
|
+
}
|
|
491
|
+
}, [editingCell, editingKey]);
|
|
256
492
|
const cancelEdit = (0, import_react.useCallback)(() => {
|
|
257
|
-
|
|
493
|
+
editingCellRef.current = null;
|
|
494
|
+
setEditingKey(null);
|
|
258
495
|
setDraftValue("");
|
|
496
|
+
draftInvalidRef.current = false;
|
|
497
|
+
setDraftInvalidState(false);
|
|
259
498
|
}, []);
|
|
260
499
|
const commitEdit = (0, import_react.useCallback)(
|
|
261
500
|
(raw) => {
|
|
@@ -275,6 +514,7 @@ function useCellEdit({
|
|
|
275
514
|
cancelEdit();
|
|
276
515
|
return true;
|
|
277
516
|
}
|
|
517
|
+
if (draftInvalidRef.current) return false;
|
|
278
518
|
const value = raw ?? draftValueRef.current;
|
|
279
519
|
const parsed = parseCellEditValue(value, getColumnEditType(cell.column.columnDef));
|
|
280
520
|
if (!parsed.ok) return false;
|
|
@@ -295,13 +535,15 @@ function useCellEdit({
|
|
|
295
535
|
);
|
|
296
536
|
const startEdit = (0, import_react.useCallback)(
|
|
297
537
|
(rowIndex, colIndex) => {
|
|
298
|
-
const
|
|
299
|
-
|
|
538
|
+
const row = rows[rowIndex];
|
|
539
|
+
const cell = row?.getVisibleCells()[colIndex];
|
|
540
|
+
if (!row || !cell || !isColumnEditable(cell.column.columnDef)) return;
|
|
541
|
+
if (!isTextEditableValue(cell.getValue())) return;
|
|
300
542
|
const current = editingCellRef.current;
|
|
301
543
|
if (current && (current.rowIndex !== rowIndex || current.colIndex !== colIndex) && !commitEdit()) {
|
|
302
544
|
return;
|
|
303
545
|
}
|
|
304
|
-
|
|
546
|
+
setEditingKey({ rowId: row.id, columnId: cell.column.id });
|
|
305
547
|
setDraftValue(getCellEditDraftValue(cell.getValue()));
|
|
306
548
|
},
|
|
307
549
|
[commitEdit, rows]
|
|
@@ -309,12 +551,55 @@ function useCellEdit({
|
|
|
309
551
|
return {
|
|
310
552
|
editingCell,
|
|
311
553
|
draftValue,
|
|
554
|
+
draftInvalid,
|
|
555
|
+
setDraftInvalid,
|
|
312
556
|
setDraftValue,
|
|
313
557
|
startEdit,
|
|
314
558
|
commitEdit,
|
|
315
559
|
cancelEdit
|
|
316
560
|
};
|
|
317
561
|
}
|
|
562
|
+
function resolveEditingCell(rows, key) {
|
|
563
|
+
if (!key) return null;
|
|
564
|
+
const rowIndex = rows.findIndex((row) => row.id === key.rowId);
|
|
565
|
+
if (rowIndex < 0) return null;
|
|
566
|
+
const colIndex = rows[rowIndex].getVisibleCells().findIndex((cell) => cell.column.id === key.columnId);
|
|
567
|
+
if (colIndex < 0) return null;
|
|
568
|
+
return { rowIndex, colIndex };
|
|
569
|
+
}
|
|
570
|
+
function isTextEditableValue(value) {
|
|
571
|
+
return value === null || value === void 0 || typeof value !== "object";
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/components/ui/table/features/cell-selection/formatCellValue.ts
|
|
575
|
+
function formatObjectValue(value) {
|
|
576
|
+
const text = value.text ?? value.label ?? value.name ?? value.title;
|
|
577
|
+
if (text != null && text !== "") {
|
|
578
|
+
return formatCellValue(text);
|
|
579
|
+
}
|
|
580
|
+
try {
|
|
581
|
+
return JSON.stringify(value);
|
|
582
|
+
} catch {
|
|
583
|
+
return "";
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function formatCellValue(value) {
|
|
587
|
+
if (value === null || value === void 0) return "";
|
|
588
|
+
if (value instanceof Date) {
|
|
589
|
+
return Number.isNaN(value.getTime()) ? "" : value.toISOString();
|
|
590
|
+
}
|
|
591
|
+
if (Array.isArray(value)) {
|
|
592
|
+
return value.map((item) => formatCellValue(item)).filter((item) => item.length > 0).join(", ");
|
|
593
|
+
}
|
|
594
|
+
if (typeof value === "object") {
|
|
595
|
+
return formatObjectValue(value);
|
|
596
|
+
}
|
|
597
|
+
if (typeof value === "string") return value;
|
|
598
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
599
|
+
return String(value);
|
|
600
|
+
}
|
|
601
|
+
return "";
|
|
602
|
+
}
|
|
318
603
|
|
|
319
604
|
// src/components/ui/table/features/cell-render/builtins.tsx
|
|
320
605
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -338,8 +623,9 @@ function asDrilldownItems(value) {
|
|
|
338
623
|
const record = item;
|
|
339
624
|
const text = asString(record.text ?? record.label ?? "");
|
|
340
625
|
if (!text) return [];
|
|
341
|
-
const
|
|
342
|
-
|
|
626
|
+
const rawImg = record.img ?? record.image;
|
|
627
|
+
const img = typeof rawImg === "string" ? sanitizeImageSrc(rawImg) : null;
|
|
628
|
+
return [{ text, ...img ? { img } : {} }];
|
|
343
629
|
}
|
|
344
630
|
return [{ text: asString(item) }];
|
|
345
631
|
});
|
|
@@ -400,6 +686,22 @@ function sanitizeUriHref(raw) {
|
|
|
400
686
|
return href;
|
|
401
687
|
}
|
|
402
688
|
}
|
|
689
|
+
function sanitizeImageSrc(raw) {
|
|
690
|
+
const src = raw.trim();
|
|
691
|
+
if (!src) return null;
|
|
692
|
+
try {
|
|
693
|
+
const parsed = new URL(src);
|
|
694
|
+
const protocol = parsed.protocol.toLowerCase();
|
|
695
|
+
if (protocol === "http:" || protocol === "https:" || protocol === "blob:") {
|
|
696
|
+
return src;
|
|
697
|
+
}
|
|
698
|
+
if (protocol === "data:" && /^data:image\//i.test(src)) return src;
|
|
699
|
+
return null;
|
|
700
|
+
} catch {
|
|
701
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(src)) return null;
|
|
702
|
+
return src;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
403
705
|
function UriCell({ value }) {
|
|
404
706
|
const raw = asString(value);
|
|
405
707
|
if (!raw) return null;
|
|
@@ -421,7 +723,10 @@ function UriCell({ value }) {
|
|
|
421
723
|
);
|
|
422
724
|
}
|
|
423
725
|
function ImageCell({ value }) {
|
|
424
|
-
const urls = asStringList(value)
|
|
726
|
+
const urls = asStringList(value).flatMap((url) => {
|
|
727
|
+
const src = sanitizeImageSrc(url);
|
|
728
|
+
return src ? [src] : [];
|
|
729
|
+
});
|
|
425
730
|
if (urls.length === 0) return null;
|
|
426
731
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-image", children: urls.map((url, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
427
732
|
"img",
|
|
@@ -474,8 +779,33 @@ function DrilldownCell({ value }) {
|
|
|
474
779
|
function LoadingCell() {
|
|
475
780
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-loading", "aria-busy": "true" });
|
|
476
781
|
}
|
|
477
|
-
function ProtectedCell() {
|
|
478
|
-
|
|
782
|
+
function ProtectedCell({ cellProps }) {
|
|
783
|
+
const label = typeof cellProps?.ariaLabel === "string" ? cellProps.ariaLabel : "protected";
|
|
784
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-protected", "aria-label": label, children: "****" });
|
|
785
|
+
}
|
|
786
|
+
function RowSelectCell({ row, cellProps }) {
|
|
787
|
+
const canSelect = typeof row.getCanSelect === "function" ? row.getCanSelect() : false;
|
|
788
|
+
const checked = typeof row.getIsSelected === "function" ? row.getIsSelected() : false;
|
|
789
|
+
const label = typeof cellProps?.ariaLabel === "string" ? cellProps.ariaLabel : "Select row";
|
|
790
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
791
|
+
"input",
|
|
792
|
+
{
|
|
793
|
+
type: "checkbox",
|
|
794
|
+
className: "data-table-cell-row-select",
|
|
795
|
+
checked,
|
|
796
|
+
disabled: !canSelect,
|
|
797
|
+
"aria-label": label,
|
|
798
|
+
onChange: () => {
|
|
799
|
+
if (canSelect) row.toggleSelected();
|
|
800
|
+
},
|
|
801
|
+
onClick: (event) => {
|
|
802
|
+
event.stopPropagation();
|
|
803
|
+
},
|
|
804
|
+
onMouseDown: (event) => {
|
|
805
|
+
event.stopPropagation();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
);
|
|
479
809
|
}
|
|
480
810
|
function RowIdCell({ value }) {
|
|
481
811
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-row-id", children: asString(value) });
|
|
@@ -491,7 +821,8 @@ var BUILTIN_RENDER_MAP = {
|
|
|
491
821
|
drilldown: DrilldownCell,
|
|
492
822
|
loading: LoadingCell,
|
|
493
823
|
protected: ProtectedCell,
|
|
494
|
-
"row-id": RowIdCell
|
|
824
|
+
"row-id": RowIdCell,
|
|
825
|
+
"row-select": RowSelectCell
|
|
495
826
|
};
|
|
496
827
|
var BUILTIN_CELL_RENDERERS = Object.keys(BUILTIN_RENDER_MAP).map((kind) => ({
|
|
497
828
|
kind,
|
|
@@ -525,38 +856,447 @@ function formatDefaultCellValue(value) {
|
|
|
525
856
|
return String(value);
|
|
526
857
|
}
|
|
527
858
|
if (typeof value === "bigint") return value.toString();
|
|
528
|
-
return
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// src/components/ui/table/features/cell-render/withCellUpdate.ts
|
|
532
|
-
function withCellUpdate(context, commitValue) {
|
|
533
|
-
return {
|
|
534
|
-
...context,
|
|
535
|
-
update: (next) => {
|
|
536
|
-
commitValue(context.row.id, context.column.id, next);
|
|
537
|
-
}
|
|
538
|
-
};
|
|
859
|
+
return formatCellValue(value);
|
|
539
860
|
}
|
|
540
861
|
|
|
541
|
-
// src/components/ui/table/features/cell-selection/
|
|
542
|
-
var
|
|
862
|
+
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
863
|
+
var import_react2 = require("react");
|
|
543
864
|
|
|
544
|
-
// src/components/ui/table/features/cell-selection/
|
|
545
|
-
var
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
865
|
+
// src/components/ui/table/features/cell-selection/subtreeClipboard.ts
|
|
866
|
+
var lastSubtreeCopy = null;
|
|
867
|
+
function normalize(text) {
|
|
868
|
+
return text.replace(/\r\n?/g, "\n").replace(/\n+$/, "");
|
|
549
869
|
}
|
|
550
|
-
function
|
|
551
|
-
|
|
552
|
-
return () => {
|
|
553
|
-
clearByOwner.delete(owner);
|
|
554
|
-
if (activeOwner === owner) {
|
|
555
|
-
activeOwner = null;
|
|
556
|
-
}
|
|
557
|
-
};
|
|
870
|
+
function rememberSubtreeCopy(text) {
|
|
871
|
+
lastSubtreeCopy = normalize(text);
|
|
558
872
|
}
|
|
559
|
-
function
|
|
873
|
+
function isOwnSubtreeCopy(text) {
|
|
874
|
+
return lastSubtreeCopy !== null && normalize(text) === lastSubtreeCopy;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
878
|
+
var SPREADSHEET_FORMULA_PREFIX = /^[=+\-@\t\r]/;
|
|
879
|
+
var PLAIN_SIGNED_NUMBER = /^[+-]\d+(?:\.\d+)?$/;
|
|
880
|
+
function escapeSpreadsheetFormula(text) {
|
|
881
|
+
if (!SPREADSHEET_FORMULA_PREFIX.test(text)) return text;
|
|
882
|
+
if (PLAIN_SIGNED_NUMBER.test(text)) return text;
|
|
883
|
+
return `'${text}`;
|
|
884
|
+
}
|
|
885
|
+
function isReactNodeIterable(node) {
|
|
886
|
+
return typeof node === "object" && node !== null && !(0, import_react2.isValidElement)(node) && Symbol.iterator in node;
|
|
887
|
+
}
|
|
888
|
+
function getElementTypeName(type) {
|
|
889
|
+
if (typeof type === "string") return type;
|
|
890
|
+
if (typeof type === "function") {
|
|
891
|
+
const fn = type;
|
|
892
|
+
return fn.displayName || fn.name || "";
|
|
893
|
+
}
|
|
894
|
+
if (typeof type === "object" && type !== null) {
|
|
895
|
+
const component = type;
|
|
896
|
+
return component.displayName || component.render?.displayName || component.render?.name || "";
|
|
897
|
+
}
|
|
898
|
+
return "";
|
|
899
|
+
}
|
|
900
|
+
function isButtonReactElement(node) {
|
|
901
|
+
const typeName = getElementTypeName(node.type);
|
|
902
|
+
if (typeName === "button" || /button/i.test(typeName)) return true;
|
|
903
|
+
const props = node.props;
|
|
904
|
+
if (props.role === "button") return true;
|
|
905
|
+
if (typeName === "input" && props.type === "button") return true;
|
|
906
|
+
return false;
|
|
907
|
+
}
|
|
908
|
+
function isImageReactElement(node) {
|
|
909
|
+
const typeName = getElementTypeName(node.type);
|
|
910
|
+
return typeName === "img" || typeName === "image" || /image/i.test(typeName);
|
|
911
|
+
}
|
|
912
|
+
var IMAGE_URL_PROP_KEYS = ["src", "url", "href", "imageUrl", "srcUrl"];
|
|
913
|
+
function isLikelyUrl(value) {
|
|
914
|
+
const trimmed = value.trim();
|
|
915
|
+
if (!trimmed) return false;
|
|
916
|
+
if (/^(https?:|blob:|data:|\/\/)/i.test(trimmed)) return true;
|
|
917
|
+
if (trimmed.startsWith("/") && trimmed.includes("/")) return true;
|
|
918
|
+
return false;
|
|
919
|
+
}
|
|
920
|
+
function pickUrlFromUnknown(value) {
|
|
921
|
+
if (typeof value === "string") {
|
|
922
|
+
return isLikelyUrl(value) ? value.trim() : "";
|
|
923
|
+
}
|
|
924
|
+
if (Array.isArray(value)) {
|
|
925
|
+
return value.map((item) => pickUrlFromUnknown(item)).filter((item) => item.length > 0).join(", ");
|
|
926
|
+
}
|
|
927
|
+
if (value && typeof value === "object") {
|
|
928
|
+
const record = value;
|
|
929
|
+
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
930
|
+
const candidate = record[key];
|
|
931
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
932
|
+
return candidate.trim();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return "";
|
|
937
|
+
}
|
|
938
|
+
function imageElementText(node) {
|
|
939
|
+
const props = node.props;
|
|
940
|
+
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
941
|
+
const candidate = props[key];
|
|
942
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
943
|
+
return candidate.trim();
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return "";
|
|
947
|
+
}
|
|
948
|
+
function reactNodeContainsImage(node) {
|
|
949
|
+
if ((0, import_react2.isValidElement)(node)) {
|
|
950
|
+
if (isImageReactElement(node)) return true;
|
|
951
|
+
return reactNodeContainsImage(node.props.children);
|
|
952
|
+
}
|
|
953
|
+
if (isReactNodeIterable(node)) {
|
|
954
|
+
for (const child of node) {
|
|
955
|
+
if (reactNodeContainsImage(child)) return true;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return false;
|
|
959
|
+
}
|
|
960
|
+
function readImgUrl(img) {
|
|
961
|
+
const attr = img.getAttribute("src")?.trim() ?? "";
|
|
962
|
+
if (attr) return attr;
|
|
963
|
+
if (img instanceof HTMLImageElement) {
|
|
964
|
+
const current = img.currentSrc?.trim() ?? "";
|
|
965
|
+
if (current && current !== img.baseURI) return current;
|
|
966
|
+
}
|
|
967
|
+
return "";
|
|
968
|
+
}
|
|
969
|
+
function readDomImageUrls(rowIndex, colIndex, root) {
|
|
970
|
+
const scope = root ?? (typeof document === "undefined" ? null : document);
|
|
971
|
+
if (!scope) return "";
|
|
972
|
+
const cells = scope.querySelectorAll(
|
|
973
|
+
`[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
|
|
974
|
+
);
|
|
975
|
+
for (const cell of cells) {
|
|
976
|
+
const urls = Array.from(cell.querySelectorAll("img")).flatMap((img) => {
|
|
977
|
+
const url = readImgUrl(img);
|
|
978
|
+
return url ? [url] : [];
|
|
979
|
+
});
|
|
980
|
+
if (urls.length > 0) return urls.join(", ");
|
|
981
|
+
}
|
|
982
|
+
return "";
|
|
983
|
+
}
|
|
984
|
+
function reactNodeToText(node) {
|
|
985
|
+
if (node == null || typeof node === "boolean") return "";
|
|
986
|
+
if (typeof node === "string" || typeof node === "number" || typeof node === "bigint") {
|
|
987
|
+
return String(node);
|
|
988
|
+
}
|
|
989
|
+
if (isReactNodeIterable(node)) {
|
|
990
|
+
let text = "";
|
|
991
|
+
for (const child of node) {
|
|
992
|
+
text += reactNodeToText(child);
|
|
993
|
+
}
|
|
994
|
+
return text;
|
|
995
|
+
}
|
|
996
|
+
if ((0, import_react2.isValidElement)(node)) {
|
|
997
|
+
if (isButtonReactElement(node)) return "";
|
|
998
|
+
const props = node.props;
|
|
999
|
+
const childText = reactNodeToText(props.children);
|
|
1000
|
+
if (childText) return childText;
|
|
1001
|
+
const fromImage = imageElementText(node);
|
|
1002
|
+
if (fromImage) return fromImage;
|
|
1003
|
+
if (isImageReactElement(node)) return "";
|
|
1004
|
+
if (typeof props.alt === "string" && props.alt) return props.alt;
|
|
1005
|
+
if (typeof props.title === "string" && props.title) return props.title;
|
|
1006
|
+
return "";
|
|
1007
|
+
}
|
|
1008
|
+
return "";
|
|
1009
|
+
}
|
|
1010
|
+
function quoteTsvCell(text) {
|
|
1011
|
+
if (!/[\t\n\r]/.test(text) && !text.startsWith('"')) return text;
|
|
1012
|
+
return `"${text.replace(/"/g, '""')}"`;
|
|
1013
|
+
}
|
|
1014
|
+
function sanitizeClipboardCell(text) {
|
|
1015
|
+
return text.replace(/\s+/g, " ").trim();
|
|
1016
|
+
}
|
|
1017
|
+
function createCopyRenderRow(rowData, index) {
|
|
1018
|
+
return {
|
|
1019
|
+
id: getOriginalRowId(rowData) || String(index),
|
|
1020
|
+
index,
|
|
1021
|
+
original: rowData,
|
|
1022
|
+
getIsCellDragSelected: () => false
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function buildVisibleRowLookup(visibleRows) {
|
|
1026
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
1027
|
+
for (const row of visibleRows) {
|
|
1028
|
+
lookup.set(row.original, row);
|
|
1029
|
+
}
|
|
1030
|
+
return lookup;
|
|
1031
|
+
}
|
|
1032
|
+
function resolveCopyColumnId(cell) {
|
|
1033
|
+
if (cell.column.id) return cell.column.id;
|
|
1034
|
+
const columnDef = cell.column.columnDef;
|
|
1035
|
+
if (columnDef.id) return columnDef.id;
|
|
1036
|
+
if (columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
1037
|
+
return String(columnDef.accessorKey);
|
|
1038
|
+
}
|
|
1039
|
+
return "";
|
|
1040
|
+
}
|
|
1041
|
+
function isPrimitiveCopyValue(value) {
|
|
1042
|
+
return value == null || typeof value !== "object";
|
|
1043
|
+
}
|
|
1044
|
+
function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
1045
|
+
const rendered = sanitizeClipboardCell(reactNodeToText(node));
|
|
1046
|
+
if (reactNodeContainsImage(node)) {
|
|
1047
|
+
const fromDom = cellPosition != null ? sanitizeClipboardCell(
|
|
1048
|
+
readDomImageUrls(cellPosition.rowIndex, cellPosition.colIndex, root)
|
|
1049
|
+
) : "";
|
|
1050
|
+
if (fromDom) return fromDom;
|
|
1051
|
+
if (rendered && isLikelyUrl(rendered)) return rendered;
|
|
1052
|
+
return sanitizeClipboardCell(pickUrlFromUnknown(value));
|
|
1053
|
+
}
|
|
1054
|
+
return rendered;
|
|
1055
|
+
}
|
|
1056
|
+
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
1057
|
+
const meta = columnDef.meta;
|
|
1058
|
+
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
1059
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1060
|
+
const ctx = {
|
|
1061
|
+
value,
|
|
1062
|
+
row,
|
|
1063
|
+
index: row.index,
|
|
1064
|
+
columnId,
|
|
1065
|
+
cellProps: meta?.cellProps,
|
|
1066
|
+
update: () => {
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
const copyValue = meta?.copyValue;
|
|
1070
|
+
if (typeof copyValue === "function") {
|
|
1071
|
+
try {
|
|
1072
|
+
return sanitizeClipboardCell(copyValue(ctx));
|
|
1073
|
+
} catch {
|
|
1074
|
+
return formatCellValue(value);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
if (copyValue === "value") {
|
|
1078
|
+
return formatCellValue(value);
|
|
1079
|
+
}
|
|
1080
|
+
const cellRender = meta?.cellRender;
|
|
1081
|
+
if (typeof cellRender === "function") {
|
|
1082
|
+
try {
|
|
1083
|
+
const node = cellRender(ctx);
|
|
1084
|
+
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
1085
|
+
} catch {
|
|
1086
|
+
return formatCellValue(value);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
if (options?.registry && meta?.kind && (isPrimitiveCopyValue(value) || meta.kind === "protected")) {
|
|
1090
|
+
try {
|
|
1091
|
+
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
1092
|
+
if (renderer) {
|
|
1093
|
+
const node = renderer.render(ctx);
|
|
1094
|
+
const rendered = extractRenderedCopyText(node, value, cellPosition, options.root);
|
|
1095
|
+
if (rendered) return rendered;
|
|
1096
|
+
}
|
|
1097
|
+
} catch {
|
|
1098
|
+
return formatCellValue(value);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return formatCellValue(value);
|
|
1102
|
+
}
|
|
1103
|
+
function getNestedValue(row, path) {
|
|
1104
|
+
if (!path.includes(".")) return row[path];
|
|
1105
|
+
return path.split(".").reduce((current, key) => {
|
|
1106
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
1107
|
+
return void 0;
|
|
1108
|
+
}
|
|
1109
|
+
return current[key];
|
|
1110
|
+
}, row);
|
|
1111
|
+
}
|
|
1112
|
+
function readRowColumnValue(rowData, columnDef) {
|
|
1113
|
+
if ("accessorFn" in columnDef && typeof columnDef.accessorFn === "function") {
|
|
1114
|
+
return columnDef.accessorFn(rowData, 0);
|
|
1115
|
+
}
|
|
1116
|
+
if ("accessorKey" in columnDef && columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
1117
|
+
return getNestedValue(rowData, String(columnDef.accessorKey));
|
|
1118
|
+
}
|
|
1119
|
+
return void 0;
|
|
1120
|
+
}
|
|
1121
|
+
function flattenSubtreeRows(row) {
|
|
1122
|
+
const children = row.children;
|
|
1123
|
+
if (!Array.isArray(children) || children.length === 0) return [];
|
|
1124
|
+
const result = [];
|
|
1125
|
+
const walk = (nodes) => {
|
|
1126
|
+
for (const node of nodes) {
|
|
1127
|
+
result.push(node);
|
|
1128
|
+
const nested = node.children;
|
|
1129
|
+
if (Array.isArray(nested) && nested.length > 0) {
|
|
1130
|
+
walk(nested);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
walk(children);
|
|
1135
|
+
return result;
|
|
1136
|
+
}
|
|
1137
|
+
function hasSubtree(row) {
|
|
1138
|
+
const children = row.children;
|
|
1139
|
+
return Array.isArray(children) && children.length > 0;
|
|
1140
|
+
}
|
|
1141
|
+
function getOriginalRowId(original) {
|
|
1142
|
+
return String(original.id ?? original.uniqueId ?? "");
|
|
1143
|
+
}
|
|
1144
|
+
function getRowDepth(original) {
|
|
1145
|
+
return typeof original.level === "number" ? original.level : 0;
|
|
1146
|
+
}
|
|
1147
|
+
function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
|
|
1148
|
+
const { startRow, endRow } = bounds;
|
|
1149
|
+
const result = [];
|
|
1150
|
+
if (mode !== "subtree") {
|
|
1151
|
+
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex += 1) {
|
|
1152
|
+
const row = visibleRows[rowIndex];
|
|
1153
|
+
if (row) result.push({ row: row.original, depth: 0 });
|
|
1154
|
+
}
|
|
1155
|
+
return result;
|
|
1156
|
+
}
|
|
1157
|
+
const included = /* @__PURE__ */ new Set();
|
|
1158
|
+
const keyOf = (node) => getTreeRowKey(node) ?? (getOriginalRowId(node) || node);
|
|
1159
|
+
const appendSubtree = (node, depth) => {
|
|
1160
|
+
const children = node.children;
|
|
1161
|
+
if (!Array.isArray(children) || children.length === 0) return;
|
|
1162
|
+
for (const child of children) {
|
|
1163
|
+
const key = keyOf(child);
|
|
1164
|
+
if (!included.has(key)) {
|
|
1165
|
+
result.push({ row: child, depth });
|
|
1166
|
+
included.add(key);
|
|
1167
|
+
}
|
|
1168
|
+
appendSubtree(child, depth + 1);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex += 1) {
|
|
1172
|
+
const row = visibleRows[rowIndex];
|
|
1173
|
+
if (!row) continue;
|
|
1174
|
+
const key = keyOf(row.original);
|
|
1175
|
+
if (included.has(key)) continue;
|
|
1176
|
+
const depth = getRowDepth(row.original);
|
|
1177
|
+
result.push({ row: row.original, depth });
|
|
1178
|
+
included.add(key);
|
|
1179
|
+
if (!hasSubtree(row.original)) continue;
|
|
1180
|
+
appendSubtree(row.original, depth + 1);
|
|
1181
|
+
}
|
|
1182
|
+
return result;
|
|
1183
|
+
}
|
|
1184
|
+
function collectCopyRows(visibleRows, bounds, mode = "visible") {
|
|
1185
|
+
return collectCopyRowEntries(visibleRows, bounds, mode).map((entry) => entry.row);
|
|
1186
|
+
}
|
|
1187
|
+
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options) {
|
|
1188
|
+
if (copyRows.length === 0) return "";
|
|
1189
|
+
const { startCol, endCol } = bounds;
|
|
1190
|
+
const columnCells = visibleRows[0]?.getVisibleCells().slice(startCol, endCol + 1) ?? [];
|
|
1191
|
+
if (columnCells.length === 0) return "";
|
|
1192
|
+
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
1193
|
+
const minDepth = Math.min(...resolvedDepths);
|
|
1194
|
+
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
1195
|
+
const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
|
|
1196
|
+
const meta = templateCell.column.columnDef.meta;
|
|
1197
|
+
if (meta?.copyValue === "omit") return [];
|
|
1198
|
+
return [{ templateCell, colOffset }];
|
|
1199
|
+
});
|
|
1200
|
+
return copyRows.map((rowData, index) => {
|
|
1201
|
+
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
1202
|
+
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
1203
|
+
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
1204
|
+
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
1205
|
+
const sourceCell = matchingCells?.[colOffset];
|
|
1206
|
+
const column = sourceCell?.column ?? templateCell.column;
|
|
1207
|
+
const text = formatCopyCellText(
|
|
1208
|
+
rowData,
|
|
1209
|
+
column.columnDef,
|
|
1210
|
+
resolveCopyColumnId(sourceCell ?? templateCell),
|
|
1211
|
+
visibleRow,
|
|
1212
|
+
visibleRow?.index ?? index,
|
|
1213
|
+
sourceCell,
|
|
1214
|
+
visibleRow != null ? { rowIndex: visibleRow.index, colIndex: startCol + colOffset } : void 0,
|
|
1215
|
+
options
|
|
1216
|
+
);
|
|
1217
|
+
const escaped = options?.escapeFormulas ? escapeSpreadsheetFormula(text) : text;
|
|
1218
|
+
return quoteTsvCell(escaped);
|
|
1219
|
+
}).join(" ");
|
|
1220
|
+
return `${" ".repeat(relativeDepth)}${line}`;
|
|
1221
|
+
}).join("\n");
|
|
1222
|
+
}
|
|
1223
|
+
function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options) {
|
|
1224
|
+
const entries = collectCopyRowEntries(visibleRows, bounds, mode);
|
|
1225
|
+
return serializeCopyRowsToTSV(
|
|
1226
|
+
entries.map((entry) => entry.row),
|
|
1227
|
+
visibleRows,
|
|
1228
|
+
bounds,
|
|
1229
|
+
entries.map((entry) => entry.depth),
|
|
1230
|
+
options
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
function writeTextWithExecCommand(text) {
|
|
1234
|
+
if (typeof document === "undefined") return false;
|
|
1235
|
+
const textarea = document.createElement("textarea");
|
|
1236
|
+
textarea.value = text;
|
|
1237
|
+
textarea.setAttribute("readonly", "");
|
|
1238
|
+
textarea.style.position = "fixed";
|
|
1239
|
+
textarea.style.top = "0";
|
|
1240
|
+
textarea.style.left = "0";
|
|
1241
|
+
textarea.style.opacity = "0";
|
|
1242
|
+
textarea.style.pointerEvents = "none";
|
|
1243
|
+
document.body.appendChild(textarea);
|
|
1244
|
+
const previouslyFocused = document.activeElement;
|
|
1245
|
+
try {
|
|
1246
|
+
textarea.focus();
|
|
1247
|
+
textarea.select();
|
|
1248
|
+
return document.execCommand("copy");
|
|
1249
|
+
} catch {
|
|
1250
|
+
return false;
|
|
1251
|
+
} finally {
|
|
1252
|
+
document.body.removeChild(textarea);
|
|
1253
|
+
previouslyFocused?.focus?.();
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
1257
|
+
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
1258
|
+
if (!text) return false;
|
|
1259
|
+
if (mode === "subtree") rememberSubtreeCopy(text);
|
|
1260
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
1261
|
+
return writeTextWithExecCommand(text);
|
|
1262
|
+
}
|
|
1263
|
+
try {
|
|
1264
|
+
await navigator.clipboard.writeText(text);
|
|
1265
|
+
return true;
|
|
1266
|
+
} catch {
|
|
1267
|
+
return false;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
// src/components/ui/table/features/cell-render/withCellUpdate.ts
|
|
1272
|
+
function withCellUpdate(context, commitValue) {
|
|
1273
|
+
return {
|
|
1274
|
+
...context,
|
|
1275
|
+
update: (next) => {
|
|
1276
|
+
commitValue(context.row.id, context.column.id, next);
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1282
|
+
var import_react3 = require("react");
|
|
1283
|
+
|
|
1284
|
+
// src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
|
|
1285
|
+
var activeOwner = null;
|
|
1286
|
+
var clearByOwner = /* @__PURE__ */ new Map();
|
|
1287
|
+
function createCellSelectionOwner() {
|
|
1288
|
+
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
1289
|
+
}
|
|
1290
|
+
function registerCellSelectionOwner(owner, clearSelection) {
|
|
1291
|
+
clearByOwner.set(owner, clearSelection);
|
|
1292
|
+
return () => {
|
|
1293
|
+
clearByOwner.delete(owner);
|
|
1294
|
+
if (activeOwner === owner) {
|
|
1295
|
+
activeOwner = null;
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
function claimCellSelectionOwner(owner) {
|
|
560
1300
|
if (activeOwner === owner) return;
|
|
561
1301
|
activeOwner = owner;
|
|
562
1302
|
for (const [id, clearSelection] of clearByOwner) {
|
|
@@ -664,9 +1404,22 @@ function isCellInSelection(rowIndex, colIndex, bounds, rowSpan = 1) {
|
|
|
664
1404
|
const cellEndRow = rowIndex + rowSpan - 1;
|
|
665
1405
|
return cellEndRow >= bounds.startRow && rowIndex <= bounds.endRow && colIndex >= bounds.startCol && colIndex <= bounds.endCol;
|
|
666
1406
|
}
|
|
1407
|
+
function resolveFillBounds(source, pointer) {
|
|
1408
|
+
const below = pointer.row - source.endRow;
|
|
1409
|
+
const above = source.startRow - pointer.row;
|
|
1410
|
+
const right = pointer.col - source.endCol;
|
|
1411
|
+
const left = source.startCol - pointer.col;
|
|
1412
|
+
const vertical = Math.max(below, above, 0);
|
|
1413
|
+
const horizontal = Math.max(right, left, 0);
|
|
1414
|
+
if (vertical === 0 && horizontal === 0) return { ...source };
|
|
1415
|
+
if (vertical >= horizontal) {
|
|
1416
|
+
return below > 0 ? { ...source, endRow: pointer.row } : { ...source, startRow: pointer.row };
|
|
1417
|
+
}
|
|
1418
|
+
return right > 0 ? { ...source, endCol: pointer.col } : { ...source, startCol: pointer.col };
|
|
1419
|
+
}
|
|
667
1420
|
function getActiveSelectionBounds(dragState, selectionBounds) {
|
|
668
|
-
if (dragState.isFillDragging && dragState.
|
|
669
|
-
return
|
|
1421
|
+
if (dragState.isFillDragging && dragState.fillEnd && selectionBounds) {
|
|
1422
|
+
return resolveFillBounds(selectionBounds, dragState.fillEnd);
|
|
670
1423
|
}
|
|
671
1424
|
return selectionBounds;
|
|
672
1425
|
}
|
|
@@ -833,427 +1586,51 @@ function getCellSelectionEdgeStyle(rowIndex, colIndex, bounds, rowSpan = 1, isVi
|
|
|
833
1586
|
if (isBottomEdge) {
|
|
834
1587
|
shadows.push(
|
|
835
1588
|
`inset 0 -${SELECTION_EDGE_WIDTH_PX}px 0 0 ${SELECTION_EDGE_COLOR}`
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
if (isLeftEdge) {
|
|
839
|
-
shadows.push(
|
|
840
|
-
`inset ${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
if (isRightEdge) {
|
|
844
|
-
shadows.push(
|
|
845
|
-
`inset -${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
const gradients = [];
|
|
850
|
-
const sizes = [];
|
|
851
|
-
const positions = [];
|
|
852
|
-
for (const edge of stepEdges) {
|
|
853
|
-
for (const partial of buildPartialEdgeGradient(edge)) {
|
|
854
|
-
gradients.push(partial.image);
|
|
855
|
-
sizes.push(partial.size);
|
|
856
|
-
positions.push(partial.position);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
if (shadows.length === 0 && gradients.length === 0 && !selectionContinuesBelow) {
|
|
860
|
-
return void 0;
|
|
861
|
-
}
|
|
862
|
-
const style = {};
|
|
863
|
-
if (shadows.length > 0) {
|
|
864
|
-
style["--selection-edge-shadows"] = shadows.join(", ");
|
|
865
|
-
}
|
|
866
|
-
if (gradients.length > 0) {
|
|
867
|
-
style["--selection-edge-gradients"] = gradients.join(", ");
|
|
868
|
-
style["--selection-edge-sizes"] = sizes.join(", ");
|
|
869
|
-
style["--selection-edge-positions"] = positions.join(", ");
|
|
870
|
-
}
|
|
871
|
-
if (selectionContinuesBelow) {
|
|
872
|
-
style.borderBottomColor = "var(--color-brand-surface)";
|
|
873
|
-
}
|
|
874
|
-
return style;
|
|
875
|
-
}
|
|
876
|
-
function hasCellSelectionEdges(style) {
|
|
877
|
-
return Boolean(
|
|
878
|
-
style?.["--selection-edge-shadows"] || style?.["--selection-edge-gradients"]
|
|
879
|
-
);
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
883
|
-
var import_react2 = require("react");
|
|
884
|
-
function isReactNodeIterable(node) {
|
|
885
|
-
return typeof node === "object" && node !== null && !(0, import_react2.isValidElement)(node) && Symbol.iterator in node;
|
|
886
|
-
}
|
|
887
|
-
function getElementTypeName(type) {
|
|
888
|
-
if (typeof type === "string") return type;
|
|
889
|
-
if (typeof type === "function") {
|
|
890
|
-
const fn = type;
|
|
891
|
-
return fn.displayName || fn.name || "";
|
|
892
|
-
}
|
|
893
|
-
if (typeof type === "object" && type !== null) {
|
|
894
|
-
const component = type;
|
|
895
|
-
return component.displayName || component.render?.displayName || component.render?.name || "";
|
|
896
|
-
}
|
|
897
|
-
return "";
|
|
898
|
-
}
|
|
899
|
-
function isButtonReactElement(node) {
|
|
900
|
-
const typeName = getElementTypeName(node.type);
|
|
901
|
-
if (typeName === "button" || /button/i.test(typeName)) return true;
|
|
902
|
-
const props = node.props;
|
|
903
|
-
if (props.role === "button") return true;
|
|
904
|
-
if (typeName === "input" && props.type === "button") return true;
|
|
905
|
-
return false;
|
|
906
|
-
}
|
|
907
|
-
function isImageReactElement(node) {
|
|
908
|
-
const typeName = getElementTypeName(node.type);
|
|
909
|
-
return typeName === "img" || typeName === "image" || /image/i.test(typeName);
|
|
910
|
-
}
|
|
911
|
-
var IMAGE_URL_PROP_KEYS = ["src", "url", "href", "imageUrl", "srcUrl"];
|
|
912
|
-
function isLikelyUrl(value) {
|
|
913
|
-
const trimmed = value.trim();
|
|
914
|
-
if (!trimmed) return false;
|
|
915
|
-
if (/^(https?:|blob:|data:|\/\/)/i.test(trimmed)) return true;
|
|
916
|
-
if (trimmed.startsWith("/") && trimmed.includes("/")) return true;
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
function pickUrlFromUnknown(value) {
|
|
920
|
-
if (typeof value === "string") {
|
|
921
|
-
return isLikelyUrl(value) ? value.trim() : "";
|
|
922
|
-
}
|
|
923
|
-
if (Array.isArray(value)) {
|
|
924
|
-
return value.map((item) => pickUrlFromUnknown(item)).filter((item) => item.length > 0).join(", ");
|
|
925
|
-
}
|
|
926
|
-
if (value && typeof value === "object") {
|
|
927
|
-
const record = value;
|
|
928
|
-
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
929
|
-
const candidate = record[key];
|
|
930
|
-
if (typeof candidate === "string" && candidate.trim()) {
|
|
931
|
-
return candidate.trim();
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
return "";
|
|
936
|
-
}
|
|
937
|
-
function imageElementText(node) {
|
|
938
|
-
const props = node.props;
|
|
939
|
-
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
940
|
-
const candidate = props[key];
|
|
941
|
-
if (typeof candidate === "string" && candidate.trim()) {
|
|
942
|
-
return candidate.trim();
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
return "";
|
|
946
|
-
}
|
|
947
|
-
function reactNodeContainsImage(node) {
|
|
948
|
-
if ((0, import_react2.isValidElement)(node)) {
|
|
949
|
-
if (isImageReactElement(node)) return true;
|
|
950
|
-
return reactNodeContainsImage(node.props.children);
|
|
951
|
-
}
|
|
952
|
-
if (isReactNodeIterable(node)) {
|
|
953
|
-
for (const child of node) {
|
|
954
|
-
if (reactNodeContainsImage(child)) return true;
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
return false;
|
|
958
|
-
}
|
|
959
|
-
function readImgUrl(img) {
|
|
960
|
-
const attr = img.getAttribute("src")?.trim() ?? "";
|
|
961
|
-
if (attr) return attr;
|
|
962
|
-
if (img instanceof HTMLImageElement) {
|
|
963
|
-
const current = img.currentSrc?.trim() ?? "";
|
|
964
|
-
if (current && current !== img.baseURI) return current;
|
|
965
|
-
}
|
|
966
|
-
return "";
|
|
967
|
-
}
|
|
968
|
-
function readDomImageUrls(rowIndex, colIndex, root) {
|
|
969
|
-
const scope = root ?? (typeof document === "undefined" ? null : document);
|
|
970
|
-
if (!scope) return "";
|
|
971
|
-
const cells = scope.querySelectorAll(
|
|
972
|
-
`[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
|
|
973
|
-
);
|
|
974
|
-
for (const cell of cells) {
|
|
975
|
-
const urls = Array.from(cell.querySelectorAll("img")).flatMap((img) => {
|
|
976
|
-
const url = readImgUrl(img);
|
|
977
|
-
return url ? [url] : [];
|
|
978
|
-
});
|
|
979
|
-
if (urls.length > 0) return urls.join(", ");
|
|
980
|
-
}
|
|
981
|
-
return "";
|
|
982
|
-
}
|
|
983
|
-
function reactNodeToText(node) {
|
|
984
|
-
if (node == null || typeof node === "boolean") return "";
|
|
985
|
-
if (typeof node === "string" || typeof node === "number" || typeof node === "bigint") {
|
|
986
|
-
return String(node);
|
|
987
|
-
}
|
|
988
|
-
if (isReactNodeIterable(node)) {
|
|
989
|
-
let text = "";
|
|
990
|
-
for (const child of node) {
|
|
991
|
-
text += reactNodeToText(child);
|
|
992
|
-
}
|
|
993
|
-
return text;
|
|
994
|
-
}
|
|
995
|
-
if ((0, import_react2.isValidElement)(node)) {
|
|
996
|
-
if (isButtonReactElement(node)) return "";
|
|
997
|
-
const props = node.props;
|
|
998
|
-
const childText = reactNodeToText(props.children);
|
|
999
|
-
if (childText) return childText;
|
|
1000
|
-
const fromImage = imageElementText(node);
|
|
1001
|
-
if (fromImage) return fromImage;
|
|
1002
|
-
if (isImageReactElement(node)) return "";
|
|
1003
|
-
if (typeof props.alt === "string" && props.alt) return props.alt;
|
|
1004
|
-
if (typeof props.title === "string" && props.title) return props.title;
|
|
1005
|
-
return "";
|
|
1006
|
-
}
|
|
1007
|
-
return "";
|
|
1008
|
-
}
|
|
1009
|
-
function sanitizeClipboardCell(text) {
|
|
1010
|
-
return text.replace(/\s+/g, " ").trim();
|
|
1011
|
-
}
|
|
1012
|
-
function createCopyRenderRow(rowData, index) {
|
|
1013
|
-
return {
|
|
1014
|
-
id: getOriginalRowId(rowData) || String(index),
|
|
1015
|
-
index,
|
|
1016
|
-
original: rowData,
|
|
1017
|
-
getIsCellDragSelected: () => false
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
function buildVisibleRowLookup(visibleRows) {
|
|
1021
|
-
const lookup = /* @__PURE__ */ new Map();
|
|
1022
|
-
for (const row of visibleRows) {
|
|
1023
|
-
lookup.set(row.original, row);
|
|
1024
|
-
}
|
|
1025
|
-
return lookup;
|
|
1026
|
-
}
|
|
1027
|
-
function resolveCopyColumnId(cell) {
|
|
1028
|
-
if (cell.column.id) return cell.column.id;
|
|
1029
|
-
const columnDef = cell.column.columnDef;
|
|
1030
|
-
if (columnDef.id) return columnDef.id;
|
|
1031
|
-
if (columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
1032
|
-
return String(columnDef.accessorKey);
|
|
1033
|
-
}
|
|
1034
|
-
return "";
|
|
1035
|
-
}
|
|
1036
|
-
function isPrimitiveCopyValue(value) {
|
|
1037
|
-
return value == null || typeof value !== "object";
|
|
1038
|
-
}
|
|
1039
|
-
function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
1040
|
-
const rendered = sanitizeClipboardCell(reactNodeToText(node));
|
|
1041
|
-
if (reactNodeContainsImage(node)) {
|
|
1042
|
-
const fromDom = cellPosition != null ? sanitizeClipboardCell(
|
|
1043
|
-
readDomImageUrls(cellPosition.rowIndex, cellPosition.colIndex, root)
|
|
1044
|
-
) : "";
|
|
1045
|
-
if (fromDom) return fromDom;
|
|
1046
|
-
if (rendered && isLikelyUrl(rendered)) return rendered;
|
|
1047
|
-
return sanitizeClipboardCell(pickUrlFromUnknown(value));
|
|
1048
|
-
}
|
|
1049
|
-
return rendered;
|
|
1050
|
-
}
|
|
1051
|
-
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
1052
|
-
const meta = columnDef.meta;
|
|
1053
|
-
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
1054
|
-
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1055
|
-
const ctx = {
|
|
1056
|
-
value,
|
|
1057
|
-
row,
|
|
1058
|
-
index: row.index,
|
|
1059
|
-
columnId,
|
|
1060
|
-
cellProps: meta?.cellProps,
|
|
1061
|
-
update: () => {
|
|
1062
|
-
}
|
|
1063
|
-
};
|
|
1064
|
-
const copyValue = meta?.copyValue;
|
|
1065
|
-
if (typeof copyValue === "function") {
|
|
1066
|
-
try {
|
|
1067
|
-
return sanitizeClipboardCell(copyValue(ctx));
|
|
1068
|
-
} catch {
|
|
1069
|
-
return formatCellValue(value);
|
|
1589
|
+
);
|
|
1070
1590
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
const cellRender = meta?.cellRender;
|
|
1076
|
-
if (typeof cellRender === "function") {
|
|
1077
|
-
try {
|
|
1078
|
-
const node = cellRender(ctx);
|
|
1079
|
-
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
1080
|
-
} catch {
|
|
1081
|
-
return formatCellValue(value);
|
|
1591
|
+
if (isLeftEdge) {
|
|
1592
|
+
shadows.push(
|
|
1593
|
+
`inset ${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`
|
|
1594
|
+
);
|
|
1082
1595
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
if (renderer) {
|
|
1088
|
-
const node = renderer.render(ctx);
|
|
1089
|
-
const rendered = extractRenderedCopyText(node, value, cellPosition, options.root);
|
|
1090
|
-
if (rendered) return rendered;
|
|
1091
|
-
}
|
|
1092
|
-
} catch {
|
|
1093
|
-
return formatCellValue(value);
|
|
1596
|
+
if (isRightEdge) {
|
|
1597
|
+
shadows.push(
|
|
1598
|
+
`inset -${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`
|
|
1599
|
+
);
|
|
1094
1600
|
}
|
|
1095
1601
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
function formatObjectValue(value) {
|
|
1107
|
-
const text = value.text ?? value.label ?? value.name ?? value.title;
|
|
1108
|
-
if (text != null && text !== "") {
|
|
1109
|
-
return formatCellValue(text);
|
|
1110
|
-
}
|
|
1111
|
-
try {
|
|
1112
|
-
return JSON.stringify(value);
|
|
1113
|
-
} catch {
|
|
1114
|
-
return "";
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
function formatCellValue(value) {
|
|
1118
|
-
if (value === null || value === void 0) return "";
|
|
1119
|
-
if (Array.isArray(value)) {
|
|
1120
|
-
return value.map((item) => formatCellValue(item)).filter((item) => item.length > 0).join(", ");
|
|
1602
|
+
const gradients = [];
|
|
1603
|
+
const sizes = [];
|
|
1604
|
+
const positions = [];
|
|
1605
|
+
for (const edge of stepEdges) {
|
|
1606
|
+
for (const partial of buildPartialEdgeGradient(edge)) {
|
|
1607
|
+
gradients.push(partial.image);
|
|
1608
|
+
sizes.push(partial.size);
|
|
1609
|
+
positions.push(partial.position);
|
|
1610
|
+
}
|
|
1121
1611
|
}
|
|
1122
|
-
if (
|
|
1123
|
-
return
|
|
1612
|
+
if (shadows.length === 0 && gradients.length === 0 && !selectionContinuesBelow) {
|
|
1613
|
+
return void 0;
|
|
1124
1614
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
if (!path.includes(".")) return row[path];
|
|
1129
|
-
return path.split(".").reduce((current, key) => {
|
|
1130
|
-
if (current === null || current === void 0 || typeof current !== "object") {
|
|
1131
|
-
return void 0;
|
|
1132
|
-
}
|
|
1133
|
-
return current[key];
|
|
1134
|
-
}, row);
|
|
1135
|
-
}
|
|
1136
|
-
function readRowColumnValue(rowData, columnDef) {
|
|
1137
|
-
if ("accessorFn" in columnDef && typeof columnDef.accessorFn === "function") {
|
|
1138
|
-
return columnDef.accessorFn(rowData, 0);
|
|
1615
|
+
const style = {};
|
|
1616
|
+
if (shadows.length > 0) {
|
|
1617
|
+
style["--selection-edge-shadows"] = shadows.join(", ");
|
|
1139
1618
|
}
|
|
1140
|
-
if (
|
|
1141
|
-
|
|
1619
|
+
if (gradients.length > 0) {
|
|
1620
|
+
style["--selection-edge-gradients"] = gradients.join(", ");
|
|
1621
|
+
style["--selection-edge-sizes"] = sizes.join(", ");
|
|
1622
|
+
style["--selection-edge-positions"] = positions.join(", ");
|
|
1142
1623
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
function flattenSubtreeRows(row) {
|
|
1146
|
-
const children = row.children;
|
|
1147
|
-
if (!Array.isArray(children) || children.length === 0) return [];
|
|
1148
|
-
const result = [];
|
|
1149
|
-
const walk = (nodes) => {
|
|
1150
|
-
for (const node of nodes) {
|
|
1151
|
-
result.push(node);
|
|
1152
|
-
const nested = node.children;
|
|
1153
|
-
if (Array.isArray(nested) && nested.length > 0) {
|
|
1154
|
-
walk(nested);
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
walk(children);
|
|
1159
|
-
return result;
|
|
1160
|
-
}
|
|
1161
|
-
function hasSubtree(row) {
|
|
1162
|
-
const children = row.children;
|
|
1163
|
-
return Array.isArray(children) && children.length > 0;
|
|
1164
|
-
}
|
|
1165
|
-
function getOriginalRowId(original) {
|
|
1166
|
-
return String(original.id ?? original.uniqueId ?? "");
|
|
1167
|
-
}
|
|
1168
|
-
function getRowDepth(original) {
|
|
1169
|
-
return typeof original.level === "number" ? original.level : 0;
|
|
1170
|
-
}
|
|
1171
|
-
function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
|
|
1172
|
-
const { startRow, endRow } = bounds;
|
|
1173
|
-
const result = [];
|
|
1174
|
-
const includedOriginalIds = /* @__PURE__ */ new Set();
|
|
1175
|
-
const appendSubtree = (node, depth) => {
|
|
1176
|
-
const children = node.children;
|
|
1177
|
-
if (!Array.isArray(children) || children.length === 0) return;
|
|
1178
|
-
for (const child of children) {
|
|
1179
|
-
const childId = getOriginalRowId(child);
|
|
1180
|
-
if (!(childId && includedOriginalIds.has(childId))) {
|
|
1181
|
-
result.push({ row: child, depth });
|
|
1182
|
-
if (childId) includedOriginalIds.add(childId);
|
|
1183
|
-
}
|
|
1184
|
-
appendSubtree(child, depth + 1);
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1187
|
-
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex += 1) {
|
|
1188
|
-
const row = visibleRows[rowIndex];
|
|
1189
|
-
if (!row) continue;
|
|
1190
|
-
const originalId = getOriginalRowId(row.original);
|
|
1191
|
-
if (originalId && includedOriginalIds.has(originalId)) continue;
|
|
1192
|
-
const depth = getRowDepth(row.original);
|
|
1193
|
-
result.push({ row: row.original, depth });
|
|
1194
|
-
if (originalId) includedOriginalIds.add(originalId);
|
|
1195
|
-
if (mode !== "subtree" || !hasSubtree(row.original)) continue;
|
|
1196
|
-
appendSubtree(row.original, depth + 1);
|
|
1624
|
+
if (selectionContinuesBelow) {
|
|
1625
|
+
style.borderBottomColor = "var(--color-brand-surface)";
|
|
1197
1626
|
}
|
|
1198
|
-
return
|
|
1199
|
-
}
|
|
1200
|
-
function collectCopyRows(visibleRows, bounds, mode = "visible") {
|
|
1201
|
-
return collectCopyRowEntries(visibleRows, bounds, mode).map((entry) => entry.row);
|
|
1202
|
-
}
|
|
1203
|
-
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options) {
|
|
1204
|
-
if (copyRows.length === 0) return "";
|
|
1205
|
-
const { startCol, endCol } = bounds;
|
|
1206
|
-
const columnCells = visibleRows[0]?.getVisibleCells().slice(startCol, endCol + 1) ?? [];
|
|
1207
|
-
if (columnCells.length === 0) return "";
|
|
1208
|
-
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
1209
|
-
const minDepth = Math.min(...resolvedDepths);
|
|
1210
|
-
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
1211
|
-
const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
|
|
1212
|
-
const meta = templateCell.column.columnDef.meta;
|
|
1213
|
-
if (meta?.copyValue === "omit") return [];
|
|
1214
|
-
return [{ templateCell, colOffset }];
|
|
1215
|
-
});
|
|
1216
|
-
return copyRows.map((rowData, index) => {
|
|
1217
|
-
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
1218
|
-
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
1219
|
-
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
1220
|
-
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
1221
|
-
const sourceCell = matchingCells?.[colOffset];
|
|
1222
|
-
const column = sourceCell?.column ?? templateCell.column;
|
|
1223
|
-
return formatCopyCellText(
|
|
1224
|
-
rowData,
|
|
1225
|
-
column.columnDef,
|
|
1226
|
-
resolveCopyColumnId(sourceCell ?? templateCell),
|
|
1227
|
-
visibleRow,
|
|
1228
|
-
visibleRow?.index ?? index,
|
|
1229
|
-
sourceCell,
|
|
1230
|
-
visibleRow != null ? { rowIndex: visibleRow.index, colIndex: startCol + colOffset } : void 0,
|
|
1231
|
-
options
|
|
1232
|
-
);
|
|
1233
|
-
}).join(" ");
|
|
1234
|
-
return `${" ".repeat(relativeDepth)}${line}`;
|
|
1235
|
-
}).join("\n");
|
|
1627
|
+
return style;
|
|
1236
1628
|
}
|
|
1237
|
-
function
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
entries.map((entry) => entry.row),
|
|
1241
|
-
visibleRows,
|
|
1242
|
-
bounds,
|
|
1243
|
-
entries.map((entry) => entry.depth),
|
|
1244
|
-
options
|
|
1629
|
+
function hasCellSelectionEdges(style) {
|
|
1630
|
+
return Boolean(
|
|
1631
|
+
style?.["--selection-edge-shadows"] || style?.["--selection-edge-gradients"]
|
|
1245
1632
|
);
|
|
1246
1633
|
}
|
|
1247
|
-
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
1248
|
-
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
1249
|
-
if (!text) return false;
|
|
1250
|
-
try {
|
|
1251
|
-
await navigator.clipboard.writeText(text);
|
|
1252
|
-
} catch {
|
|
1253
|
-
return false;
|
|
1254
|
-
}
|
|
1255
|
-
return true;
|
|
1256
|
-
}
|
|
1257
1634
|
|
|
1258
1635
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
1259
1636
|
function getColumnAccessorKey2(columnDef) {
|
|
@@ -1277,6 +1654,8 @@ function collectFillTargets(rows, sourceBounds, fillBounds) {
|
|
|
1277
1654
|
const targetCell = targetRow?.getVisibleCells()[colIndex];
|
|
1278
1655
|
const sourceCell = rows[sourceRowIndex]?.getVisibleCells()[sourceColIndex];
|
|
1279
1656
|
if (!targetRow || !targetCell || !sourceCell) continue;
|
|
1657
|
+
if (!isColumnEditable(targetCell.column.columnDef)) continue;
|
|
1658
|
+
if (isProtectedColumn(sourceCell.column.columnDef)) continue;
|
|
1280
1659
|
const accessorKey = getColumnAccessorKey2(
|
|
1281
1660
|
targetCell.column.columnDef
|
|
1282
1661
|
);
|
|
@@ -1298,13 +1677,22 @@ function collectFillChanges(rows, sourceBounds, fillBounds) {
|
|
|
1298
1677
|
);
|
|
1299
1678
|
}
|
|
1300
1679
|
function applyFillData(data, rows, sourceBounds, fillBounds) {
|
|
1301
|
-
const newData = data.map((row) => ({ ...row }));
|
|
1302
1680
|
const targets = collectFillTargets(rows, sourceBounds, fillBounds);
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1681
|
+
return applyCellChangesToData(
|
|
1682
|
+
data,
|
|
1683
|
+
targets.flatMap((target) => {
|
|
1684
|
+
const row = rows[target.rowIndex];
|
|
1685
|
+
if (!row) return [];
|
|
1686
|
+
return [
|
|
1687
|
+
{
|
|
1688
|
+
original: row.original,
|
|
1689
|
+
index: row.index,
|
|
1690
|
+
accessorKey: target.accessorKey,
|
|
1691
|
+
value: target.value
|
|
1692
|
+
}
|
|
1693
|
+
];
|
|
1694
|
+
})
|
|
1695
|
+
);
|
|
1308
1696
|
}
|
|
1309
1697
|
function hasFillExtension(sourceBounds, fillBounds) {
|
|
1310
1698
|
if (!sourceBounds) return false;
|
|
@@ -1325,17 +1713,62 @@ function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
|
1325
1713
|
if (firstDepth !== 0) return false;
|
|
1326
1714
|
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1327
1715
|
}
|
|
1716
|
+
function splitTSV(text) {
|
|
1717
|
+
const rows = [];
|
|
1718
|
+
let row = [];
|
|
1719
|
+
let index = 0;
|
|
1720
|
+
while (index <= text.length) {
|
|
1721
|
+
let cell = "";
|
|
1722
|
+
if (text[index] === '"') {
|
|
1723
|
+
index += 1;
|
|
1724
|
+
while (index < text.length) {
|
|
1725
|
+
const char = text[index];
|
|
1726
|
+
if (char === '"') {
|
|
1727
|
+
if (text[index + 1] === '"') {
|
|
1728
|
+
cell += '"';
|
|
1729
|
+
index += 2;
|
|
1730
|
+
continue;
|
|
1731
|
+
}
|
|
1732
|
+
index += 1;
|
|
1733
|
+
break;
|
|
1734
|
+
}
|
|
1735
|
+
cell += char;
|
|
1736
|
+
index += 1;
|
|
1737
|
+
}
|
|
1738
|
+
while (index < text.length && text[index] !== " " && text[index] !== "\n") {
|
|
1739
|
+
cell += text[index];
|
|
1740
|
+
index += 1;
|
|
1741
|
+
}
|
|
1742
|
+
} else {
|
|
1743
|
+
while (index < text.length && text[index] !== " " && text[index] !== "\n") {
|
|
1744
|
+
cell += text[index];
|
|
1745
|
+
index += 1;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
row.push(cell);
|
|
1749
|
+
if (index >= text.length) {
|
|
1750
|
+
rows.push(row);
|
|
1751
|
+
break;
|
|
1752
|
+
}
|
|
1753
|
+
if (text[index] === "\n") {
|
|
1754
|
+
rows.push(row);
|
|
1755
|
+
row = [];
|
|
1756
|
+
}
|
|
1757
|
+
index += 1;
|
|
1758
|
+
}
|
|
1759
|
+
return rows;
|
|
1760
|
+
}
|
|
1328
1761
|
function parseClipboardTSV(text) {
|
|
1329
1762
|
return parseClipboardTSVWithDepths(text).values;
|
|
1330
1763
|
}
|
|
1331
|
-
function parseClipboardTSVWithDepths(text) {
|
|
1764
|
+
function parseClipboardTSVWithDepths(text, options) {
|
|
1332
1765
|
if (!text) return { values: [], depths: [] };
|
|
1333
1766
|
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1334
1767
|
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1335
1768
|
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1336
|
-
const rows = withoutTrailing
|
|
1769
|
+
const rows = splitTSV(withoutTrailing);
|
|
1337
1770
|
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1338
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1771
|
+
const treatAsDepth = options?.treeDepth !== "none" && looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1339
1772
|
const values = [];
|
|
1340
1773
|
const depths = [];
|
|
1341
1774
|
for (let index = 0; index < rows.length; index += 1) {
|
|
@@ -1362,8 +1795,8 @@ function resolvePasteColumnIds(rows, startCol, width) {
|
|
|
1362
1795
|
}
|
|
1363
1796
|
return columnIds;
|
|
1364
1797
|
}
|
|
1365
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1366
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1798
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow, options) {
|
|
1799
|
+
const { values, depths } = parseClipboardTSVWithDepths(text, options);
|
|
1367
1800
|
if (values.length === 0) return null;
|
|
1368
1801
|
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1369
1802
|
if (width === 0) return null;
|
|
@@ -1396,6 +1829,19 @@ function isEditablePasteTarget(target) {
|
|
|
1396
1829
|
}
|
|
1397
1830
|
|
|
1398
1831
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1832
|
+
var INTERACTIVE_FOCUS_SELECTOR = "button, a[href], input, textarea, select, [contenteditable]:not([contenteditable='false'])";
|
|
1833
|
+
function isInteractiveFocus() {
|
|
1834
|
+
const active = document.activeElement;
|
|
1835
|
+
return active instanceof Element && active.matches(INTERACTIVE_FOCUS_SELECTOR);
|
|
1836
|
+
}
|
|
1837
|
+
function hasPageTextSelectionOutside(root) {
|
|
1838
|
+
if (typeof window.getSelection !== "function") return false;
|
|
1839
|
+
const selection = window.getSelection();
|
|
1840
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0) return false;
|
|
1841
|
+
if (!selection.toString()) return false;
|
|
1842
|
+
const anchor = selection.anchorNode;
|
|
1843
|
+
return !(root && anchor && root.contains(anchor));
|
|
1844
|
+
}
|
|
1399
1845
|
function isFocusOutsideRoot(rootRef) {
|
|
1400
1846
|
const root = rootRef?.current;
|
|
1401
1847
|
if (!root) return false;
|
|
@@ -1408,29 +1854,50 @@ function useCellSelection({
|
|
|
1408
1854
|
rows,
|
|
1409
1855
|
enabled = true,
|
|
1410
1856
|
columnCount = 0,
|
|
1857
|
+
columnSignature,
|
|
1411
1858
|
enableSubtreeCopy = false,
|
|
1859
|
+
escapeCopyFormulas = false,
|
|
1412
1860
|
enableInsertPaste = true,
|
|
1413
1861
|
onDataChange,
|
|
1414
1862
|
onBatchChange,
|
|
1415
1863
|
onRowsPaste,
|
|
1416
1864
|
onCellNavigate,
|
|
1417
1865
|
cellRendererRegistry,
|
|
1418
|
-
rootRef
|
|
1866
|
+
rootRef,
|
|
1867
|
+
enableWasdNavigation = true,
|
|
1868
|
+
onEditKey,
|
|
1869
|
+
onClearKey
|
|
1419
1870
|
}) {
|
|
1420
1871
|
const ownerRef = (0, import_react3.useRef)(createCellSelectionOwner());
|
|
1421
1872
|
const [dragState, setDragState] = (0, import_react3.useState)(INITIAL_DRAG_STATE);
|
|
1422
1873
|
const pendingPasteModeRef = (0, import_react3.useRef)(null);
|
|
1423
1874
|
const dragStateRef = (0, import_react3.useRef)(dragState);
|
|
1424
1875
|
const onCellNavigateRef = (0, import_react3.useRef)(onCellNavigate);
|
|
1876
|
+
const onEditKeyRef = (0, import_react3.useRef)(onEditKey);
|
|
1877
|
+
const onClearKeyRef = (0, import_react3.useRef)(onClearKey);
|
|
1425
1878
|
dragStateRef.current = dragState;
|
|
1426
1879
|
onCellNavigateRef.current = onCellNavigate;
|
|
1427
|
-
|
|
1428
|
-
|
|
1880
|
+
onEditKeyRef.current = onEditKey;
|
|
1881
|
+
onClearKeyRef.current = onClearKey;
|
|
1882
|
+
const updateDragState = (0, import_react3.useCallback)((update) => {
|
|
1883
|
+
const prev = dragStateRef.current;
|
|
1884
|
+
const next = update(prev);
|
|
1885
|
+
if (next === prev) return;
|
|
1886
|
+
dragStateRef.current = next;
|
|
1887
|
+
setDragState(next);
|
|
1888
|
+
}, []);
|
|
1889
|
+
const activeSelectionBounds = (0, import_react3.useMemo)(() => {
|
|
1890
|
+
if (!enabled) return null;
|
|
1891
|
+
return getActiveSelectionBounds(
|
|
1892
|
+
dragState,
|
|
1893
|
+
getCellSelectionBounds(dragState.start, dragState.end)
|
|
1894
|
+
);
|
|
1895
|
+
}, [dragState, enabled]);
|
|
1429
1896
|
const handleCellMouseDown = (0, import_react3.useCallback)(
|
|
1430
1897
|
(rowIndex, colIndex, options) => {
|
|
1431
1898
|
if (!enabled) return;
|
|
1432
1899
|
claimCellSelectionOwner(ownerRef.current);
|
|
1433
|
-
|
|
1900
|
+
updateDragState((prev) => {
|
|
1434
1901
|
if (options?.shiftKey && prev.start) {
|
|
1435
1902
|
return {
|
|
1436
1903
|
...prev,
|
|
@@ -1451,28 +1918,30 @@ function useCellSelection({
|
|
|
1451
1918
|
};
|
|
1452
1919
|
});
|
|
1453
1920
|
},
|
|
1454
|
-
[enabled]
|
|
1921
|
+
[enabled, updateDragState]
|
|
1455
1922
|
);
|
|
1456
1923
|
const handleCellMouseEnter = (0, import_react3.useCallback)(
|
|
1457
1924
|
(rowIndex, colIndex) => {
|
|
1458
1925
|
if (!enabled) return;
|
|
1459
|
-
|
|
1926
|
+
updateDragState((prev) => {
|
|
1460
1927
|
if (prev.isSelecting) {
|
|
1928
|
+
if (prev.end?.row === rowIndex && prev.end.col === colIndex) return prev;
|
|
1461
1929
|
return { ...prev, end: { row: rowIndex, col: colIndex } };
|
|
1462
1930
|
}
|
|
1463
1931
|
if (prev.isFillDragging) {
|
|
1932
|
+
if (prev.fillEnd?.row === rowIndex && prev.fillEnd.col === colIndex) return prev;
|
|
1464
1933
|
return { ...prev, fillEnd: { row: rowIndex, col: colIndex } };
|
|
1465
1934
|
}
|
|
1466
1935
|
return prev;
|
|
1467
1936
|
});
|
|
1468
1937
|
},
|
|
1469
|
-
[enabled]
|
|
1938
|
+
[enabled, updateDragState]
|
|
1470
1939
|
);
|
|
1471
1940
|
const handleFillHandleMouseDown = (0, import_react3.useCallback)(
|
|
1472
1941
|
(rowIndex, colIndex) => {
|
|
1473
1942
|
if (!enabled) return;
|
|
1474
1943
|
claimCellSelectionOwner(ownerRef.current);
|
|
1475
|
-
|
|
1944
|
+
updateDragState((prev) => {
|
|
1476
1945
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
1477
1946
|
if (!bounds) return prev;
|
|
1478
1947
|
return {
|
|
@@ -1484,7 +1953,7 @@ function useCellSelection({
|
|
|
1484
1953
|
};
|
|
1485
1954
|
});
|
|
1486
1955
|
},
|
|
1487
|
-
[enabled]
|
|
1956
|
+
[enabled, updateDragState]
|
|
1488
1957
|
);
|
|
1489
1958
|
const clearSelection = (0, import_react3.useCallback)(() => {
|
|
1490
1959
|
const prev = dragStateRef.current;
|
|
@@ -1503,6 +1972,130 @@ function useCellSelection({
|
|
|
1503
1972
|
(0, import_react3.useEffect)(() => {
|
|
1504
1973
|
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
1505
1974
|
}, [clearSelection]);
|
|
1975
|
+
const previousColumnSignatureRef = (0, import_react3.useRef)(columnSignature);
|
|
1976
|
+
(0, import_react3.useEffect)(() => {
|
|
1977
|
+
const columnsChanged = columnSignature !== void 0 && previousColumnSignatureRef.current !== void 0 && previousColumnSignatureRef.current !== columnSignature;
|
|
1978
|
+
previousColumnSignatureRef.current = columnSignature;
|
|
1979
|
+
const prev = dragStateRef.current;
|
|
1980
|
+
if (!prev.start || !prev.end) return;
|
|
1981
|
+
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
1982
|
+
const resolvedColumnCount = columnCount > 0 ? columnCount : rows[0]?.getVisibleCells().length ?? 0;
|
|
1983
|
+
const outOfRange = bounds !== null && (bounds.endRow >= rows.length || resolvedColumnCount > 0 && bounds.endCol >= resolvedColumnCount);
|
|
1984
|
+
if (columnsChanged || outOfRange) {
|
|
1985
|
+
clearSelection();
|
|
1986
|
+
}
|
|
1987
|
+
}, [clearSelection, columnCount, columnSignature, rows]);
|
|
1988
|
+
(0, import_react3.useEffect)(() => {
|
|
1989
|
+
if (!enabled) return;
|
|
1990
|
+
const handlePointerDown = (event) => {
|
|
1991
|
+
const root = rootRef?.current;
|
|
1992
|
+
if (!root || !isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1993
|
+
if (event.target instanceof Node && root.contains(event.target)) return;
|
|
1994
|
+
releaseCellSelectionOwner(ownerRef.current);
|
|
1995
|
+
};
|
|
1996
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
1997
|
+
document.addEventListener("mousedown", handlePointerDown, true);
|
|
1998
|
+
return () => {
|
|
1999
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
2000
|
+
document.removeEventListener("mousedown", handlePointerDown, true);
|
|
2001
|
+
};
|
|
2002
|
+
}, [enabled, rootRef]);
|
|
2003
|
+
const getColumnCount = (0, import_react3.useCallback)(
|
|
2004
|
+
() => columnCount > 0 ? columnCount : rows[0]?.getVisibleCells().length ?? 0,
|
|
2005
|
+
[columnCount, rows]
|
|
2006
|
+
);
|
|
2007
|
+
const selectCell = (0, import_react3.useCallback)(
|
|
2008
|
+
(row, col) => {
|
|
2009
|
+
if (!enabled) return;
|
|
2010
|
+
const resolvedColumnCount = getColumnCount();
|
|
2011
|
+
if (rows.length <= 0 || resolvedColumnCount <= 0) return;
|
|
2012
|
+
const position = clampCellPosition({ row, col }, rows.length, resolvedColumnCount);
|
|
2013
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
2014
|
+
const nextState = {
|
|
2015
|
+
isSelecting: false,
|
|
2016
|
+
isFillDragging: false,
|
|
2017
|
+
start: position,
|
|
2018
|
+
end: position,
|
|
2019
|
+
fillAnchor: null,
|
|
2020
|
+
fillEnd: null
|
|
2021
|
+
};
|
|
2022
|
+
dragStateRef.current = nextState;
|
|
2023
|
+
setDragState(nextState);
|
|
2024
|
+
onCellNavigateRef.current?.(position);
|
|
2025
|
+
},
|
|
2026
|
+
[enabled, getColumnCount, rows.length]
|
|
2027
|
+
);
|
|
2028
|
+
const focusSelection = (0, import_react3.useCallback)(() => {
|
|
2029
|
+
if (!enabled) return;
|
|
2030
|
+
const prev = dragStateRef.current;
|
|
2031
|
+
if (prev.start && prev.end) {
|
|
2032
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
2033
|
+
return;
|
|
2034
|
+
}
|
|
2035
|
+
selectCell(0, 0);
|
|
2036
|
+
}, [enabled, selectCell]);
|
|
2037
|
+
(0, import_react3.useEffect)(() => {
|
|
2038
|
+
if (!enabled) return;
|
|
2039
|
+
const handleKeyDown = (e) => {
|
|
2040
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
2041
|
+
if (e.altKey) return;
|
|
2042
|
+
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
2043
|
+
return;
|
|
2044
|
+
}
|
|
2045
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
2046
|
+
const prev = dragStateRef.current;
|
|
2047
|
+
if (!prev.start || !prev.end) return;
|
|
2048
|
+
if (prev.isSelecting || prev.isFillDragging) return;
|
|
2049
|
+
const rowCount = rows.length;
|
|
2050
|
+
const resolvedColumnCount = getColumnCount();
|
|
2051
|
+
if (rowCount <= 0 || resolvedColumnCount <= 0) return;
|
|
2052
|
+
const withModifier = e.ctrlKey || e.metaKey;
|
|
2053
|
+
if (withModifier && !e.shiftKey && e.key.toLowerCase() === "a") {
|
|
2054
|
+
e.preventDefault();
|
|
2055
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
2056
|
+
const nextState = {
|
|
2057
|
+
isSelecting: false,
|
|
2058
|
+
isFillDragging: false,
|
|
2059
|
+
start: { row: 0, col: 0 },
|
|
2060
|
+
end: { row: rowCount - 1, col: resolvedColumnCount - 1 },
|
|
2061
|
+
fillAnchor: null,
|
|
2062
|
+
fillEnd: null
|
|
2063
|
+
};
|
|
2064
|
+
dragStateRef.current = nextState;
|
|
2065
|
+
setDragState(nextState);
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
if (e.key === "Home" || e.key === "End") {
|
|
2069
|
+
e.preventDefault();
|
|
2070
|
+
const toEnd = e.key === "End";
|
|
2071
|
+
const target = withModifier ? toEnd ? { row: rowCount - 1, col: resolvedColumnCount - 1 } : { row: 0, col: 0 } : { row: prev.end.row, col: toEnd ? resolvedColumnCount - 1 : 0 };
|
|
2072
|
+
if (e.shiftKey) {
|
|
2073
|
+
const nextState = { ...prev, end: target, fillAnchor: null, fillEnd: null };
|
|
2074
|
+
dragStateRef.current = nextState;
|
|
2075
|
+
setDragState(nextState);
|
|
2076
|
+
onCellNavigateRef.current?.(target);
|
|
2077
|
+
} else {
|
|
2078
|
+
selectCell(target.row, target.col);
|
|
2079
|
+
}
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
if (withModifier || isInteractiveFocus()) return;
|
|
2083
|
+
if (e.key === "Enter" || e.key === "F2") {
|
|
2084
|
+
if (!onEditKeyRef.current) return;
|
|
2085
|
+
e.preventDefault();
|
|
2086
|
+
onEditKeyRef.current(prev.end);
|
|
2087
|
+
return;
|
|
2088
|
+
}
|
|
2089
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
2090
|
+
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
2091
|
+
if (!bounds || !onClearKeyRef.current) return;
|
|
2092
|
+
e.preventDefault();
|
|
2093
|
+
onClearKeyRef.current(bounds);
|
|
2094
|
+
}
|
|
2095
|
+
};
|
|
2096
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
2097
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2098
|
+
}, [enabled, getColumnCount, rootRef, rows.length, selectCell]);
|
|
1506
2099
|
(0, import_react3.useEffect)(() => {
|
|
1507
2100
|
if (!enabled) return;
|
|
1508
2101
|
const handleKeyDown = (e) => {
|
|
@@ -1512,6 +2105,7 @@ function useCellSelection({
|
|
|
1512
2105
|
return;
|
|
1513
2106
|
}
|
|
1514
2107
|
if (isFocusOutsideRoot(rootRef)) return;
|
|
2108
|
+
if (!enableWasdNavigation && e.key.length === 1) return;
|
|
1515
2109
|
const delta = getCellNavigationDelta(e.key);
|
|
1516
2110
|
if (!delta) return;
|
|
1517
2111
|
const prev = dragStateRef.current;
|
|
@@ -1551,14 +2145,15 @@ function useCellSelection({
|
|
|
1551
2145
|
};
|
|
1552
2146
|
window.addEventListener("keydown", handleKeyDown);
|
|
1553
2147
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
1554
|
-
}, [columnCount, enabled, rows]);
|
|
2148
|
+
}, [columnCount, enableWasdNavigation, enabled, rows]);
|
|
1555
2149
|
const copySelection = (0, import_react3.useCallback)(
|
|
1556
2150
|
async (options) => {
|
|
1557
2151
|
if (!enabled || !activeSelectionBounds) return false;
|
|
1558
2152
|
const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
|
|
1559
2153
|
return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
|
|
1560
2154
|
registry: cellRendererRegistry,
|
|
1561
|
-
root: rootRef?.current
|
|
2155
|
+
root: rootRef?.current,
|
|
2156
|
+
escapeFormulas: escapeCopyFormulas
|
|
1562
2157
|
});
|
|
1563
2158
|
},
|
|
1564
2159
|
[
|
|
@@ -1566,6 +2161,7 @@ function useCellSelection({
|
|
|
1566
2161
|
cellRendererRegistry,
|
|
1567
2162
|
enableSubtreeCopy,
|
|
1568
2163
|
enabled,
|
|
2164
|
+
escapeCopyFormulas,
|
|
1569
2165
|
rootRef,
|
|
1570
2166
|
rows
|
|
1571
2167
|
]
|
|
@@ -1583,6 +2179,7 @@ function useCellSelection({
|
|
|
1583
2179
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
1584
2180
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
1585
2181
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
2182
|
+
if (hasPageTextSelectionOutside(rootRef?.current)) return;
|
|
1586
2183
|
e.preventDefault();
|
|
1587
2184
|
void copySelection({ includeDescendants: isSubtreeShortcut });
|
|
1588
2185
|
};
|
|
@@ -1598,9 +2195,17 @@ function useCellSelection({
|
|
|
1598
2195
|
activeSelectionBounds.startCol,
|
|
1599
2196
|
text,
|
|
1600
2197
|
mode,
|
|
1601
|
-
activeSelectionBounds.endRow
|
|
2198
|
+
activeSelectionBounds.endRow,
|
|
2199
|
+
// Leading blank cells are tree depth only in this table's own subtree
|
|
2200
|
+
// copy; from a spreadsheet they are real (empty) cells.
|
|
2201
|
+
{ treeDepth: isOwnSubtreeCopy(text) ? "auto" : "none" }
|
|
1602
2202
|
);
|
|
1603
2203
|
if (!payload) return false;
|
|
2204
|
+
const cells = rows[activeSelectionBounds.startRow]?.getVisibleCells() ?? [];
|
|
2205
|
+
payload.editableColumnIds = payload.columnIds.filter((columnId) => {
|
|
2206
|
+
const cell = cells.find((item) => item.column.id === columnId);
|
|
2207
|
+
return cell ? isColumnEditable(cell.column.columnDef) : false;
|
|
2208
|
+
});
|
|
1604
2209
|
onRowsPaste(payload);
|
|
1605
2210
|
return true;
|
|
1606
2211
|
},
|
|
@@ -1631,7 +2236,10 @@ function useCellSelection({
|
|
|
1631
2236
|
void (async () => {
|
|
1632
2237
|
try {
|
|
1633
2238
|
const text = await navigator.clipboard.readText();
|
|
1634
|
-
if (pasteHandledRef.current)
|
|
2239
|
+
if (pasteHandledRef.current) {
|
|
2240
|
+
pasteHandledRef.current = false;
|
|
2241
|
+
return;
|
|
2242
|
+
}
|
|
1635
2243
|
if (pendingPasteModeRef.current !== mode) return;
|
|
1636
2244
|
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1637
2245
|
if (!text) return;
|
|
@@ -1656,6 +2264,7 @@ function useCellSelection({
|
|
|
1656
2264
|
}
|
|
1657
2265
|
const mode = pendingPasteModeRef.current ?? "overwrite";
|
|
1658
2266
|
if (pasteHandledRef.current) {
|
|
2267
|
+
pasteHandledRef.current = false;
|
|
1659
2268
|
e.preventDefault();
|
|
1660
2269
|
return;
|
|
1661
2270
|
}
|
|
@@ -1682,39 +2291,41 @@ function useCellSelection({
|
|
|
1682
2291
|
(0, import_react3.useEffect)(() => {
|
|
1683
2292
|
if (!enabled) return;
|
|
1684
2293
|
const handleMouseUp = () => {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
} else if (onDataChange) {
|
|
1697
|
-
onDataChange(applyFillData(data, rows, sourceBounds, newBounds));
|
|
2294
|
+
const prev = dragStateRef.current;
|
|
2295
|
+
let next = prev;
|
|
2296
|
+
if (prev.isFillDragging && prev.fillEnd) {
|
|
2297
|
+
const sourceBounds = getCellSelectionBounds(prev.start, prev.end);
|
|
2298
|
+
if (sourceBounds) {
|
|
2299
|
+
const newBounds = resolveFillBounds(sourceBounds, prev.fillEnd);
|
|
2300
|
+
if (hasFillExtension(sourceBounds, newBounds)) {
|
|
2301
|
+
if (onBatchChange) {
|
|
2302
|
+
const changes = collectFillChanges(rows, sourceBounds, newBounds);
|
|
2303
|
+
if (changes.length > 0) {
|
|
2304
|
+
onBatchChange(changes);
|
|
1698
2305
|
}
|
|
2306
|
+
} else if (onDataChange) {
|
|
2307
|
+
onDataChange(applyFillData(data, rows, sourceBounds, newBounds));
|
|
1699
2308
|
}
|
|
1700
|
-
return {
|
|
1701
|
-
isSelecting: false,
|
|
1702
|
-
isFillDragging: false,
|
|
1703
|
-
start: { row: newBounds.startRow, col: newBounds.startCol },
|
|
1704
|
-
end: { row: newBounds.endRow, col: newBounds.endCol },
|
|
1705
|
-
fillAnchor: null,
|
|
1706
|
-
fillEnd: null
|
|
1707
|
-
};
|
|
1708
2309
|
}
|
|
2310
|
+
next = {
|
|
2311
|
+
isSelecting: false,
|
|
2312
|
+
isFillDragging: false,
|
|
2313
|
+
start: { row: newBounds.startRow, col: newBounds.startCol },
|
|
2314
|
+
end: { row: newBounds.endRow, col: newBounds.endCol },
|
|
2315
|
+
fillAnchor: null,
|
|
2316
|
+
fillEnd: null
|
|
2317
|
+
};
|
|
2318
|
+
} else {
|
|
2319
|
+
next = { ...prev, isFillDragging: false, fillAnchor: null, fillEnd: null };
|
|
1709
2320
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
2321
|
+
} else if (prev.isSelecting) {
|
|
2322
|
+
next = { ...prev, isSelecting: false };
|
|
2323
|
+
} else if (prev.isFillDragging) {
|
|
2324
|
+
next = { ...prev, isFillDragging: false, fillAnchor: null, fillEnd: null };
|
|
2325
|
+
}
|
|
2326
|
+
if (next === prev) return;
|
|
2327
|
+
dragStateRef.current = next;
|
|
2328
|
+
setDragState(next);
|
|
1718
2329
|
};
|
|
1719
2330
|
window.addEventListener("mouseup", handleMouseUp);
|
|
1720
2331
|
return () => window.removeEventListener("mouseup", handleMouseUp);
|
|
@@ -1726,9 +2337,36 @@ function useCellSelection({
|
|
|
1726
2337
|
handleCellMouseEnter,
|
|
1727
2338
|
handleFillHandleMouseDown,
|
|
1728
2339
|
clearSelection,
|
|
1729
|
-
copySelection
|
|
2340
|
+
copySelection,
|
|
2341
|
+
selectCell,
|
|
2342
|
+
focusSelection
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
// src/components/ui/table/features/row-hover/rowHover.ts
|
|
2347
|
+
function createRowHoverStore() {
|
|
2348
|
+
let hoveredRowIndex = null;
|
|
2349
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2350
|
+
return {
|
|
2351
|
+
getHoveredRowIndex: () => hoveredRowIndex,
|
|
2352
|
+
setHoveredRowIndex: (nextRowIndex) => {
|
|
2353
|
+
if (nextRowIndex === hoveredRowIndex) return;
|
|
2354
|
+
hoveredRowIndex = nextRowIndex;
|
|
2355
|
+
listeners.forEach((listener) => listener());
|
|
2356
|
+
},
|
|
2357
|
+
subscribe: (listener) => {
|
|
2358
|
+
listeners.add(listener);
|
|
2359
|
+
return () => listeners.delete(listener);
|
|
2360
|
+
}
|
|
1730
2361
|
};
|
|
1731
2362
|
}
|
|
2363
|
+
function isRowHovered(hoveredRowIndex, rowIndex) {
|
|
2364
|
+
return hoveredRowIndex === rowIndex;
|
|
2365
|
+
}
|
|
2366
|
+
function isRowGroupHovered(hoveredRowIndex, enableRowSpan, groupStart, groupSpan) {
|
|
2367
|
+
if (!enableRowSpan || hoveredRowIndex === null) return false;
|
|
2368
|
+
return hoveredRowIndex >= groupStart && hoveredRowIndex <= groupStart + groupSpan - 1;
|
|
2369
|
+
}
|
|
1732
2370
|
|
|
1733
2371
|
// src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
|
|
1734
2372
|
var OVERLAY_DISMISS_IGNORE_SELECTOR = [
|
|
@@ -1761,8 +2399,12 @@ function handleEscape(event) {
|
|
|
1761
2399
|
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1762
2400
|
return;
|
|
1763
2401
|
}
|
|
1764
|
-
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
1765
|
-
|
|
2402
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
2403
|
+
try {
|
|
2404
|
+
clearAllSelections();
|
|
2405
|
+
} catch (error) {
|
|
2406
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
2407
|
+
}
|
|
1766
2408
|
}
|
|
1767
2409
|
}
|
|
1768
2410
|
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
@@ -1954,238 +2596,101 @@ function buildColumnFreezeOffsets(columns) {
|
|
|
1954
2596
|
rightIds.push(column.id);
|
|
1955
2597
|
result.set(column.id, {
|
|
1956
2598
|
side: "right",
|
|
1957
|
-
offset: rightOffset,
|
|
1958
|
-
isEdge: false,
|
|
1959
|
-
edgeLeft: false,
|
|
1960
|
-
edgeRight: false,
|
|
1961
|
-
stack: 0
|
|
1962
|
-
});
|
|
1963
|
-
rightOffset += column.size;
|
|
1964
|
-
}
|
|
1965
|
-
rightIds.forEach((id, index) => {
|
|
1966
|
-
const entry = result.get(id);
|
|
1967
|
-
if (!entry) return;
|
|
1968
|
-
entry.stack = rightIds.length - index;
|
|
1969
|
-
});
|
|
1970
|
-
columns.forEach((column, index) => {
|
|
1971
|
-
if (!column.side) return;
|
|
1972
|
-
const entry = result.get(column.id);
|
|
1973
|
-
if (!entry) return;
|
|
1974
|
-
const prevSide = index > 0 ? columns[index - 1]?.side : void 0;
|
|
1975
|
-
const nextSide = index < columns.length - 1 ? columns[index + 1]?.side : void 0;
|
|
1976
|
-
entry.edgeLeft = prevSide !== column.side;
|
|
1977
|
-
entry.edgeRight = nextSide !== column.side;
|
|
1978
|
-
if (index === 0) entry.edgeLeft = false;
|
|
1979
|
-
if (index === columns.length - 1) entry.edgeRight = false;
|
|
1980
|
-
entry.isEdge = entry.edgeLeft || entry.edgeRight;
|
|
1981
|
-
});
|
|
1982
|
-
return result;
|
|
1983
|
-
}
|
|
1984
|
-
function getColumnFreezeStyle(offset, options) {
|
|
1985
|
-
if (!offset) return void 0;
|
|
1986
|
-
const zBase = options?.isHeader ? HEADER_Z_BASE : BODY_Z_BASE;
|
|
1987
|
-
return {
|
|
1988
|
-
position: "sticky",
|
|
1989
|
-
...offset.side === "left" ? { left: offset.offset } : { right: offset.offset },
|
|
1990
|
-
zIndex: zBase + offset.stack
|
|
1991
|
-
};
|
|
1992
|
-
}
|
|
1993
|
-
function resolveHeaderFreezeOffset(column, freezeOffsets) {
|
|
1994
|
-
const direct = freezeOffsets.get(column.id);
|
|
1995
|
-
if (direct) return direct;
|
|
1996
|
-
const leaves = typeof column.getLeafColumns === "function" ? column.getLeafColumns() : column.columns && column.columns.length > 0 ? flattenHeaderLeaves(column) : [];
|
|
1997
|
-
if (leaves.length === 0) return void 0;
|
|
1998
|
-
const leafOffsets = [];
|
|
1999
|
-
for (const leaf of leaves) {
|
|
2000
|
-
const offset2 = freezeOffsets.get(leaf.id);
|
|
2001
|
-
if (!offset2) return void 0;
|
|
2002
|
-
leafOffsets.push(offset2);
|
|
2003
|
-
}
|
|
2004
|
-
const side = leafOffsets[0]?.side;
|
|
2005
|
-
if (!side || leafOffsets.some((offset2) => offset2.side !== side)) {
|
|
2006
|
-
return void 0;
|
|
2007
|
-
}
|
|
2008
|
-
const offset = Math.min(...leafOffsets.map((item) => item.offset));
|
|
2009
|
-
const leftmost = leafOffsets[0];
|
|
2010
|
-
const rightmost = leafOffsets[leafOffsets.length - 1];
|
|
2011
|
-
return {
|
|
2012
|
-
side,
|
|
2013
|
-
offset,
|
|
2014
|
-
edgeLeft: leftmost.edgeLeft,
|
|
2015
|
-
edgeRight: rightmost.edgeRight,
|
|
2016
|
-
isEdge: leftmost.edgeLeft || rightmost.edgeRight,
|
|
2017
|
-
stack: Math.max(...leafOffsets.map((item) => item.stack))
|
|
2018
|
-
};
|
|
2019
|
-
}
|
|
2020
|
-
function flattenHeaderLeaves(column) {
|
|
2021
|
-
if (!column.columns || column.columns.length === 0) return [column];
|
|
2022
|
-
return column.columns.flatMap((child) => flattenHeaderLeaves(child));
|
|
2023
|
-
}
|
|
2024
|
-
|
|
2025
|
-
// src/components/ui/table/features/inline-search/inlineSearch.ts
|
|
2026
|
-
var INLINE_SEARCH_MAX_RESULTS = 1e3;
|
|
2027
|
-
var INLINE_SEARCH_TARGET_TICK_MS = 10;
|
|
2028
|
-
var INLINE_SEARCH_INITIAL_STRIDE = 10;
|
|
2029
|
-
function escapeSearchRegex(value) {
|
|
2030
|
-
return value.replace(/([$()*+.?[\\\]^{|}-])/g, "\\$1");
|
|
2031
|
-
}
|
|
2032
|
-
function createSearchRegex(query) {
|
|
2033
|
-
const trimmed = query.trim();
|
|
2034
|
-
if (!trimmed) return null;
|
|
2035
|
-
return new RegExp(escapeSearchRegex(trimmed), "i");
|
|
2036
|
-
}
|
|
2037
|
-
function cellValueToSearchText(value) {
|
|
2038
|
-
if (value == null) return void 0;
|
|
2039
|
-
if (typeof value === "string") return value;
|
|
2040
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
2041
|
-
return String(value);
|
|
2042
|
-
}
|
|
2043
|
-
if (Array.isArray(value)) {
|
|
2044
|
-
return value.map((item) => cellValueToSearchText(item) ?? "").join(" ");
|
|
2045
|
-
}
|
|
2046
|
-
if (typeof value === "object") {
|
|
2047
|
-
try {
|
|
2048
|
-
return JSON.stringify(value);
|
|
2049
|
-
} catch {
|
|
2050
|
-
return String(value);
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
return String(value);
|
|
2054
|
-
}
|
|
2055
|
-
function formatSearchResultLabel(status) {
|
|
2056
|
-
const countLabel = status.results >= INLINE_SEARCH_MAX_RESULTS ? `over ${INLINE_SEARCH_MAX_RESULTS}` : `${status.results} result${status.results !== 1 ? "s" : ""}`;
|
|
2057
|
-
if (status.selectedIndex >= 0 && status.results > 0) {
|
|
2058
|
-
return `${status.selectedIndex + 1} of ${countLabel}`;
|
|
2059
|
-
}
|
|
2060
|
-
return countLabel;
|
|
2061
|
-
}
|
|
2062
|
-
function nextSearchIndex(selectedIndex, results) {
|
|
2063
|
-
if (results <= 0) return -1;
|
|
2064
|
-
if (selectedIndex < 0) return 0;
|
|
2065
|
-
return (selectedIndex + 1) % results;
|
|
2066
|
-
}
|
|
2067
|
-
function previousSearchIndex(selectedIndex, results) {
|
|
2068
|
-
if (results <= 0) return -1;
|
|
2069
|
-
if (selectedIndex < 0) return results - 1;
|
|
2070
|
-
let next = (selectedIndex - 1) % results;
|
|
2071
|
-
if (next < 0) next += results;
|
|
2072
|
-
return next;
|
|
2073
|
-
}
|
|
2074
|
-
function buildSearchMatchKey(colIndex, rowIndex) {
|
|
2075
|
-
return `${colIndex}:${rowIndex}`;
|
|
2076
|
-
}
|
|
2077
|
-
function buildSearchMatchKeys(results) {
|
|
2078
|
-
const keys = /* @__PURE__ */ new Set();
|
|
2079
|
-
for (const [colIndex, rowIndex] of results) {
|
|
2080
|
-
keys.add(buildSearchMatchKey(colIndex, rowIndex));
|
|
2081
|
-
}
|
|
2082
|
-
return keys;
|
|
2083
|
-
}
|
|
2084
|
-
function collectSearchMatchesInRange(options) {
|
|
2085
|
-
const {
|
|
2086
|
-
query,
|
|
2087
|
-
startRow,
|
|
2088
|
-
rowCount,
|
|
2089
|
-
columnCount,
|
|
2090
|
-
getCellValue,
|
|
2091
|
-
maxResults = INLINE_SEARCH_MAX_RESULTS
|
|
2092
|
-
} = options;
|
|
2093
|
-
const regex = createSearchRegex(query);
|
|
2094
|
-
if (!regex || rowCount <= 0 || columnCount <= 0) return [];
|
|
2095
|
-
const matches = [];
|
|
2096
|
-
for (let rowOffset = 0; rowOffset < rowCount; rowOffset += 1) {
|
|
2097
|
-
const rowIndex = startRow + rowOffset;
|
|
2098
|
-
for (let colIndex = 0; colIndex < columnCount; colIndex += 1) {
|
|
2099
|
-
const text = cellValueToSearchText(getCellValue(rowIndex, colIndex));
|
|
2100
|
-
if (text !== void 0 && regex.test(text)) {
|
|
2101
|
-
matches.push([colIndex, rowIndex]);
|
|
2102
|
-
if (matches.length >= maxResults) {
|
|
2103
|
-
return matches;
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
return matches;
|
|
2109
|
-
}
|
|
2110
|
-
function nextSearchStride(currentStride, elapsedMs, targetMs = INLINE_SEARCH_TARGET_TICK_MS) {
|
|
2111
|
-
const rounded = Math.max(elapsedMs, 1);
|
|
2112
|
-
const scalar = targetMs / rounded;
|
|
2113
|
-
return Math.max(1, Math.ceil(currentStride * scalar));
|
|
2114
|
-
}
|
|
2115
|
-
function buildFlatSearchCorpus(rows, getRowId) {
|
|
2116
|
-
return rows.map((data, index) => ({
|
|
2117
|
-
id: getRowId(data, index),
|
|
2118
|
-
data,
|
|
2119
|
-
ancestorToggleKeys: []
|
|
2120
|
-
}));
|
|
2121
|
-
}
|
|
2122
|
-
function buildTreeSearchCorpus(visibleRows, options) {
|
|
2123
|
-
const { toggleField, getRowId } = options;
|
|
2124
|
-
const corpus = [];
|
|
2125
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2126
|
-
const walk = (node, ancestorToggleKeys) => {
|
|
2127
|
-
const id = getRowId(node, corpus.length);
|
|
2128
|
-
if (seen.has(id)) return;
|
|
2129
|
-
seen.add(id);
|
|
2130
|
-
corpus.push({
|
|
2131
|
-
id,
|
|
2132
|
-
data: node,
|
|
2133
|
-
ancestorToggleKeys
|
|
2134
|
-
});
|
|
2135
|
-
const children = node.children;
|
|
2136
|
-
if (!Array.isArray(children) || children.length === 0) return;
|
|
2137
|
-
const toggleValue = node[toggleField];
|
|
2138
|
-
const childAncestors = typeof toggleValue === "string" && toggleValue.length > 0 ? [...ancestorToggleKeys, toggleValue] : ancestorToggleKeys;
|
|
2139
|
-
for (const child of children) {
|
|
2140
|
-
if (child && typeof child === "object") {
|
|
2141
|
-
walk(child, childAncestors);
|
|
2142
|
-
}
|
|
2143
|
-
}
|
|
2144
|
-
};
|
|
2145
|
-
for (const row of visibleRows) {
|
|
2146
|
-
const level = row.level;
|
|
2147
|
-
if (level === 0 || level === void 0) {
|
|
2148
|
-
walk(row, []);
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
for (const row of visibleRows) {
|
|
2152
|
-
const id = getRowId(row, corpus.length);
|
|
2153
|
-
if (seen.has(id)) continue;
|
|
2154
|
-
walk(row, []);
|
|
2599
|
+
offset: rightOffset,
|
|
2600
|
+
isEdge: false,
|
|
2601
|
+
edgeLeft: false,
|
|
2602
|
+
edgeRight: false,
|
|
2603
|
+
stack: 0
|
|
2604
|
+
});
|
|
2605
|
+
rightOffset += column.size;
|
|
2155
2606
|
}
|
|
2156
|
-
|
|
2607
|
+
rightIds.forEach((id, index) => {
|
|
2608
|
+
const entry = result.get(id);
|
|
2609
|
+
if (!entry) return;
|
|
2610
|
+
entry.stack = rightIds.length - index;
|
|
2611
|
+
});
|
|
2612
|
+
columns.forEach((column, index) => {
|
|
2613
|
+
if (!column.side) return;
|
|
2614
|
+
const entry = result.get(column.id);
|
|
2615
|
+
if (!entry) return;
|
|
2616
|
+
const prevSide = index > 0 ? columns[index - 1]?.side : void 0;
|
|
2617
|
+
const nextSide = index < columns.length - 1 ? columns[index + 1]?.side : void 0;
|
|
2618
|
+
entry.edgeLeft = prevSide !== column.side;
|
|
2619
|
+
entry.edgeRight = nextSide !== column.side;
|
|
2620
|
+
if (index === 0) entry.edgeLeft = false;
|
|
2621
|
+
if (index === columns.length - 1) entry.edgeRight = false;
|
|
2622
|
+
entry.isEdge = entry.edgeLeft || entry.edgeRight;
|
|
2623
|
+
});
|
|
2624
|
+
return result;
|
|
2157
2625
|
}
|
|
2158
|
-
function
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
}
|
|
2167
|
-
return keys;
|
|
2626
|
+
function getColumnFreezeStyle(offset, options) {
|
|
2627
|
+
if (!offset) return void 0;
|
|
2628
|
+
const zBase = options?.isHeader ? HEADER_Z_BASE : BODY_Z_BASE;
|
|
2629
|
+
return {
|
|
2630
|
+
position: "sticky",
|
|
2631
|
+
...offset.side === "left" ? { left: offset.offset } : { right: offset.offset },
|
|
2632
|
+
zIndex: zBase + offset.stack
|
|
2633
|
+
};
|
|
2168
2634
|
}
|
|
2169
|
-
function
|
|
2170
|
-
const
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2635
|
+
function resolveHeaderFreezeOffset(column, freezeOffsets) {
|
|
2636
|
+
const direct = freezeOffsets.get(column.id);
|
|
2637
|
+
if (direct) return direct;
|
|
2638
|
+
const leaves = typeof column.getLeafColumns === "function" ? column.getLeafColumns() : column.columns && column.columns.length > 0 ? flattenHeaderLeaves(column) : [];
|
|
2639
|
+
if (leaves.length === 0) return void 0;
|
|
2640
|
+
const leafOffsets = [];
|
|
2641
|
+
for (const leaf of leaves) {
|
|
2642
|
+
const offset2 = freezeOffsets.get(leaf.id);
|
|
2643
|
+
if (!offset2) return void 0;
|
|
2644
|
+
leafOffsets.push(offset2);
|
|
2645
|
+
}
|
|
2646
|
+
const side = leafOffsets[0]?.side;
|
|
2647
|
+
if (!side || leafOffsets.some((offset2) => offset2.side !== side)) {
|
|
2648
|
+
return void 0;
|
|
2649
|
+
}
|
|
2650
|
+
const offset = Math.min(...leafOffsets.map((item) => item.offset));
|
|
2651
|
+
const leftmost = leafOffsets[0];
|
|
2652
|
+
const rightmost = leafOffsets[leafOffsets.length - 1];
|
|
2653
|
+
return {
|
|
2654
|
+
side,
|
|
2655
|
+
offset,
|
|
2656
|
+
edgeLeft: leftmost.edgeLeft,
|
|
2657
|
+
edgeRight: rightmost.edgeRight,
|
|
2658
|
+
isEdge: leftmost.edgeLeft || rightmost.edgeRight,
|
|
2659
|
+
stack: Math.max(...leafOffsets.map((item) => item.stack))
|
|
2660
|
+
};
|
|
2176
2661
|
}
|
|
2177
|
-
function
|
|
2178
|
-
|
|
2662
|
+
function flattenHeaderLeaves(column) {
|
|
2663
|
+
if (!column.columns || column.columns.length === 0) return [column];
|
|
2664
|
+
return column.columns.flatMap((child) => flattenHeaderLeaves(child));
|
|
2179
2665
|
}
|
|
2180
2666
|
|
|
2181
2667
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
2182
2668
|
var import_react4 = require("react");
|
|
2183
2669
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
2670
|
+
var searchInstanceCount = 0;
|
|
2671
|
+
var lastPointerTarget = null;
|
|
2672
|
+
function trackPointerTarget(event) {
|
|
2673
|
+
lastPointerTarget = event.target;
|
|
2674
|
+
}
|
|
2675
|
+
function registerSearchInstance() {
|
|
2676
|
+
if (searchInstanceCount === 0) {
|
|
2677
|
+
document.addEventListener("pointerdown", trackPointerTarget, true);
|
|
2678
|
+
}
|
|
2679
|
+
searchInstanceCount += 1;
|
|
2680
|
+
return () => {
|
|
2681
|
+
searchInstanceCount -= 1;
|
|
2682
|
+
if (searchInstanceCount === 0) {
|
|
2683
|
+
document.removeEventListener("pointerdown", trackPointerTarget, true);
|
|
2684
|
+
lastPointerTarget = null;
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2184
2688
|
function useInlineSearch({
|
|
2185
2689
|
enabled = false,
|
|
2186
2690
|
rowCount,
|
|
2187
2691
|
columnCount,
|
|
2188
2692
|
getCellValue,
|
|
2693
|
+
contentKey,
|
|
2189
2694
|
initialStartRow = 0,
|
|
2190
2695
|
showSearch: controlledShowSearch,
|
|
2191
2696
|
searchValue: controlledSearchValue,
|
|
@@ -2394,6 +2899,7 @@ function useInlineSearch({
|
|
|
2394
2899
|
}
|
|
2395
2900
|
beginSearch(searchValue);
|
|
2396
2901
|
}, [
|
|
2902
|
+
contentKey,
|
|
2397
2903
|
beginSearch,
|
|
2398
2904
|
cancelSearch,
|
|
2399
2905
|
controlledSearchResults,
|
|
@@ -2414,6 +2920,9 @@ function useInlineSearch({
|
|
|
2414
2920
|
if (!focusInside && active !== document.body) {
|
|
2415
2921
|
return;
|
|
2416
2922
|
}
|
|
2923
|
+
if (!focusInside && !(lastPointerTarget instanceof Node && root.contains(lastPointerTarget))) {
|
|
2924
|
+
return;
|
|
2925
|
+
}
|
|
2417
2926
|
}
|
|
2418
2927
|
event.preventDefault();
|
|
2419
2928
|
event.stopPropagation();
|
|
@@ -2427,7 +2936,11 @@ function useInlineSearch({
|
|
|
2427
2936
|
}
|
|
2428
2937
|
};
|
|
2429
2938
|
window.addEventListener("keydown", handleKeyDown, true);
|
|
2430
|
-
|
|
2939
|
+
const releaseInstance = registerSearchInstance();
|
|
2940
|
+
return () => {
|
|
2941
|
+
window.removeEventListener("keydown", handleKeyDown, true);
|
|
2942
|
+
releaseInstance();
|
|
2943
|
+
};
|
|
2431
2944
|
}, [controlledShowSearch, enabled, rootRef, showSearch]);
|
|
2432
2945
|
(0, import_react4.useEffect)(() => () => cancelSearch(), [cancelSearch]);
|
|
2433
2946
|
const searchMatchKeys = (0, import_react4.useMemo)(
|
|
@@ -2483,8 +2996,12 @@ function getFieldValue(row, key) {
|
|
|
2483
2996
|
}
|
|
2484
2997
|
function canExpandRow(row) {
|
|
2485
2998
|
const children = row.children;
|
|
2486
|
-
|
|
2487
|
-
|
|
2999
|
+
return Array.isArray(children) && children.length > 0;
|
|
3000
|
+
}
|
|
3001
|
+
function toTreeToggleKey(value) {
|
|
3002
|
+
if (value === null || value === void 0) return null;
|
|
3003
|
+
const key = String(value);
|
|
3004
|
+
return key.length > 0 ? key : null;
|
|
2488
3005
|
}
|
|
2489
3006
|
function toggleExpandedRowId(rowId, previous) {
|
|
2490
3007
|
const next = new Set(previous);
|
|
@@ -2505,7 +3022,8 @@ var useConvertTreeData = ({
|
|
|
2505
3022
|
preventExpand = false,
|
|
2506
3023
|
startIndex = 1,
|
|
2507
3024
|
expandedRows,
|
|
2508
|
-
onExpandedRowsChange
|
|
3025
|
+
onExpandedRowsChange,
|
|
3026
|
+
autoExpandOnLoad = true
|
|
2509
3027
|
}) => {
|
|
2510
3028
|
const onExpandedRowsChangeRef = (0, import_react5.useRef)(onExpandedRowsChange);
|
|
2511
3029
|
const hasInitializedRef = (0, import_react5.useRef)(false);
|
|
@@ -2518,16 +3036,33 @@ var useConvertTreeData = ({
|
|
|
2518
3036
|
return;
|
|
2519
3037
|
}
|
|
2520
3038
|
if (!enabled || hasInitializedRef.current) return;
|
|
2521
|
-
const ids = data.map((item) => getFieldValue(item, toggleField)).filter((value) => typeof value === "string" && value.length > 0);
|
|
2522
|
-
onExpandedRowsChangeRef.current?.(new Set(ids));
|
|
2523
3039
|
hasInitializedRef.current = true;
|
|
2524
|
-
|
|
3040
|
+
if (!autoExpandOnLoad) return;
|
|
3041
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3042
|
+
const collect = (items) => {
|
|
3043
|
+
for (const item of items) {
|
|
3044
|
+
if (!item || typeof item !== "object") continue;
|
|
3045
|
+
const record = item;
|
|
3046
|
+
const key = toTreeToggleKey(getFieldValue(record, toggleField));
|
|
3047
|
+
if (key) ids.add(key);
|
|
3048
|
+
const nested = record[flattenField];
|
|
3049
|
+
if (Array.isArray(nested)) collect(nested);
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
collect(data);
|
|
3053
|
+
onExpandedRowsChangeRef.current?.(ids);
|
|
3054
|
+
}, [enabled, data, toggleField, flattenField, autoExpandOnLoad]);
|
|
2525
3055
|
const processedData = (0, import_react5.useMemo)(() => {
|
|
2526
3056
|
if (!enabled || !data || data.length === 0) return [];
|
|
2527
3057
|
const flattenedData = [];
|
|
2528
|
-
const flattenItems = (items) => {
|
|
2529
|
-
items.forEach((item) => {
|
|
2530
|
-
|
|
3058
|
+
const flattenItems = (items, parentPath) => {
|
|
3059
|
+
items.forEach((item, itemIndex) => {
|
|
3060
|
+
if (!item || typeof item !== "object") return;
|
|
3061
|
+
const source = {
|
|
3062
|
+
path: [...parentPath, itemIndex],
|
|
3063
|
+
childrenField: flattenField
|
|
3064
|
+
};
|
|
3065
|
+
const newItem = { ...item, [TREE_SOURCE]: source };
|
|
2531
3066
|
const nested = newItem[flattenField];
|
|
2532
3067
|
if (Array.isArray(nested)) {
|
|
2533
3068
|
const children = nested.map(
|
|
@@ -2541,89 +3076,68 @@ var useConvertTreeData = ({
|
|
|
2541
3076
|
child[childField] = newItem[toggleField];
|
|
2542
3077
|
}
|
|
2543
3078
|
});
|
|
2544
|
-
flattenItems(children);
|
|
3079
|
+
flattenItems(children, source.path);
|
|
2545
3080
|
} else {
|
|
2546
3081
|
flattenedData.push(newItem);
|
|
2547
3082
|
}
|
|
2548
3083
|
});
|
|
2549
3084
|
};
|
|
2550
|
-
flattenItems(data);
|
|
3085
|
+
flattenItems(data, []);
|
|
2551
3086
|
const dataWithLevels = flattenedData.map((item) => ({
|
|
2552
3087
|
...item,
|
|
2553
3088
|
level: 0,
|
|
2554
3089
|
children: [],
|
|
2555
3090
|
processed: false
|
|
2556
3091
|
}));
|
|
2557
|
-
const findNearestPrecedingParent = (index, parentKey) => {
|
|
2558
|
-
for (let i = index - 1; i >= 0; i -= 1) {
|
|
2559
|
-
const candidate = dataWithLevels[i];
|
|
2560
|
-
if (!candidate) continue;
|
|
2561
|
-
if (getFieldValue(candidate, toggleField) === parentKey) {
|
|
2562
|
-
return candidate;
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
return void 0;
|
|
2566
|
-
};
|
|
2567
3092
|
const rootItems = [];
|
|
3093
|
+
const latestByKey = /* @__PURE__ */ new Map();
|
|
2568
3094
|
dataWithLevels.forEach((item) => {
|
|
2569
|
-
if (!getFieldValue(item, childField)) {
|
|
2570
|
-
rootItems.push(item);
|
|
2571
|
-
item.processed = true;
|
|
2572
|
-
}
|
|
2573
|
-
});
|
|
2574
|
-
dataWithLevels.forEach((item, index) => {
|
|
2575
3095
|
const parentKey = getFieldValue(item, childField);
|
|
2576
|
-
|
|
2577
|
-
const parent = findNearestPrecedingParent(index, parentKey);
|
|
3096
|
+
const parent = parentKey ? latestByKey.get(parentKey) : void 0;
|
|
2578
3097
|
if (parent) {
|
|
2579
3098
|
item.level = parent.level + 1;
|
|
2580
3099
|
parent.children.push(item);
|
|
2581
|
-
|
|
2582
|
-
|
|
3100
|
+
} else {
|
|
3101
|
+
rootItems.push(item);
|
|
2583
3102
|
}
|
|
2584
|
-
rootItems.push(item);
|
|
2585
3103
|
item.processed = true;
|
|
3104
|
+
latestByKey.set(getFieldValue(item, toggleField), item);
|
|
2586
3105
|
});
|
|
2587
3106
|
return rootItems;
|
|
2588
3107
|
}, [enabled, data, toggleField, childField, flattenField]);
|
|
2589
3108
|
const flattenTree = (0, import_react5.useMemo)(() => {
|
|
2590
3109
|
if (!enabled) return [];
|
|
2591
|
-
const flatten = (nodes, result
|
|
3110
|
+
const flatten = (nodes, result, parentTreeNo) => {
|
|
2592
3111
|
nodes.forEach((node, index) => {
|
|
2593
|
-
const currentIndex =
|
|
3112
|
+
const currentIndex = parentTreeNo === null ? `${index + startIndex}` : `${parentTreeNo}-${index + 1}`;
|
|
2594
3113
|
const toggleValue = getFieldValue(node, toggleField);
|
|
2595
|
-
const uniqueId = `${
|
|
3114
|
+
const uniqueId = `${currentIndex}-${String(toggleValue ?? "")}`;
|
|
2596
3115
|
result.push({
|
|
2597
3116
|
...node,
|
|
2598
3117
|
treeNo: currentIndex,
|
|
2599
3118
|
uniqueId,
|
|
2600
3119
|
processed: true
|
|
2601
3120
|
});
|
|
2602
|
-
const
|
|
3121
|
+
const toggleKey = toTreeToggleKey(toggleValue);
|
|
3122
|
+
const shouldExpandChildren = node.children.length > 0 && (preventExpand || toggleKey !== null && Boolean(expandedRows?.has(toggleKey)));
|
|
2603
3123
|
if (shouldExpandChildren) {
|
|
2604
|
-
flatten(node.children, result,
|
|
3124
|
+
flatten(node.children, result, currentIndex);
|
|
2605
3125
|
}
|
|
2606
3126
|
});
|
|
2607
3127
|
return result;
|
|
2608
3128
|
};
|
|
2609
|
-
const flattenedData = flatten(processedData, [],
|
|
2610
|
-
|
|
3129
|
+
const flattenedData = flatten(processedData, [], null);
|
|
3130
|
+
const latestByKey = /* @__PURE__ */ new Map();
|
|
3131
|
+
flattenedData.forEach((item) => {
|
|
2611
3132
|
const parentKey = getFieldValue(item, childField);
|
|
2612
3133
|
if (!parentKey) {
|
|
2613
3134
|
item.parentCount = 1;
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
const candidate = flattenedData[i];
|
|
2619
|
-
if (!candidate) continue;
|
|
2620
|
-
if (getFieldValue(candidate, toggleField) === parentKey) {
|
|
2621
|
-
parentItem = candidate;
|
|
2622
|
-
break;
|
|
2623
|
-
}
|
|
3135
|
+
} else {
|
|
3136
|
+
const parentItem = latestByKey.get(parentKey);
|
|
3137
|
+
const parentAmount = parentItem ? Number(getFieldValue(parentItem, qtyField) ?? 1) : 1;
|
|
3138
|
+
item.parentCount = parentAmount || 1;
|
|
2624
3139
|
}
|
|
2625
|
-
|
|
2626
|
-
item.parentCount = parentAmount || 1;
|
|
3140
|
+
latestByKey.set(getFieldValue(item, toggleField), item);
|
|
2627
3141
|
});
|
|
2628
3142
|
return flattenedData;
|
|
2629
3143
|
}, [
|
|
@@ -2640,18 +3154,7 @@ var useConvertTreeData = ({
|
|
|
2640
3154
|
if (!enabled) {
|
|
2641
3155
|
return data ?? [];
|
|
2642
3156
|
}
|
|
2643
|
-
return
|
|
2644
|
-
const aParts = String(a.treeNo ?? "").split("-").map(Number);
|
|
2645
|
-
const bParts = String(b.treeNo ?? "").split("-").map(Number);
|
|
2646
|
-
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
|
|
2647
|
-
const aVal = aParts[i] || 0;
|
|
2648
|
-
const bVal = bParts[i] || 0;
|
|
2649
|
-
if (aVal !== bVal) {
|
|
2650
|
-
return aVal - bVal;
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
return 0;
|
|
2654
|
-
});
|
|
3157
|
+
return flattenTree;
|
|
2655
3158
|
}, [enabled, data, flattenTree]);
|
|
2656
3159
|
return sortedData;
|
|
2657
3160
|
};
|
|
@@ -2709,13 +3212,13 @@ function computeRowSpans(data, rowSpanKey, parentSpans) {
|
|
|
2709
3212
|
for (let index = 0; index < data.length; index++) {
|
|
2710
3213
|
const currentValue = getRowFieldValue(data[index], rowSpanKey);
|
|
2711
3214
|
const previousValue = index > 0 ? getRowFieldValue(data[index - 1], rowSpanKey) : void 0;
|
|
2712
|
-
if (index > 0 && currentValue
|
|
3215
|
+
if (index > 0 && Object.is(currentValue, previousValue) && sharesParentGroup(parentStartRows, index)) {
|
|
2713
3216
|
result.push({ rowSpan: 0, isFirstInGroup: false });
|
|
2714
3217
|
continue;
|
|
2715
3218
|
}
|
|
2716
3219
|
let span = 1;
|
|
2717
3220
|
for (let nextIndex = index + 1; nextIndex < data.length; nextIndex++) {
|
|
2718
|
-
if (getRowFieldValue(data[nextIndex], rowSpanKey)
|
|
3221
|
+
if (!Object.is(getRowFieldValue(data[nextIndex], rowSpanKey), currentValue)) break;
|
|
2719
3222
|
if (!sharesParentGroup(parentStartRows, nextIndex)) break;
|
|
2720
3223
|
span++;
|
|
2721
3224
|
}
|
|
@@ -2808,6 +3311,9 @@ function collectRowSpanColumns(columns) {
|
|
|
2808
3311
|
}
|
|
2809
3312
|
|
|
2810
3313
|
// src/core/useGlideTable.ts
|
|
3314
|
+
function isProductionBuild() {
|
|
3315
|
+
return typeof process !== "undefined" && process?.env?.NODE_ENV === "production";
|
|
3316
|
+
}
|
|
2811
3317
|
var EMPTY_COLUMN_FREEZE_OFFSETS = /* @__PURE__ */ new Map();
|
|
2812
3318
|
var EMPTY_SEARCH_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
2813
3319
|
function useGlideTable(options) {
|
|
@@ -2829,18 +3335,24 @@ function useGlideTable(options) {
|
|
|
2829
3335
|
selectOnRowClick = true,
|
|
2830
3336
|
enableCellSelection = true,
|
|
2831
3337
|
onDataChange,
|
|
2832
|
-
onCellChange,
|
|
2833
|
-
onBatchChange,
|
|
3338
|
+
onCellChange: onCellChangeProp,
|
|
3339
|
+
onBatchChange: onBatchChangeProp,
|
|
2834
3340
|
cellRenderers,
|
|
2835
3341
|
preserveRowSelection = false,
|
|
2836
|
-
toggleField,
|
|
2837
|
-
|
|
2838
|
-
|
|
3342
|
+
toggleField: toggleFieldProp,
|
|
3343
|
+
idField,
|
|
3344
|
+
childField: childFieldProp,
|
|
3345
|
+
parentIdField,
|
|
3346
|
+
flattenField: flattenFieldProp,
|
|
3347
|
+
childrenField,
|
|
2839
3348
|
qtyField,
|
|
3349
|
+
expandColumn,
|
|
2840
3350
|
expandedRows: controlledExpandedRows,
|
|
2841
3351
|
onExpandedRowsChange,
|
|
2842
3352
|
preventExpand = false,
|
|
3353
|
+
autoExpandOnLoad = true,
|
|
2843
3354
|
enableSubtreeCopy,
|
|
3355
|
+
escapeCopyFormulas = false,
|
|
2844
3356
|
onCopyActionsReady,
|
|
2845
3357
|
onRowsPaste,
|
|
2846
3358
|
enableInsertPaste,
|
|
@@ -2861,8 +3373,27 @@ function useGlideTable(options) {
|
|
|
2861
3373
|
onSearchValueChange,
|
|
2862
3374
|
onSearchClose,
|
|
2863
3375
|
searchResults,
|
|
2864
|
-
onSearchResultsChanged
|
|
3376
|
+
onSearchResultsChanged,
|
|
3377
|
+
enableWasdNavigation = true
|
|
2865
3378
|
} = options;
|
|
3379
|
+
const toggleField = toggleFieldProp ?? idField;
|
|
3380
|
+
const childField = childFieldProp ?? parentIdField;
|
|
3381
|
+
const flattenField = flattenFieldProp ?? childrenField;
|
|
3382
|
+
const onCellChange = (0, import_react6.useMemo)(() => {
|
|
3383
|
+
if (onCellChangeProp) return onCellChangeProp;
|
|
3384
|
+
if (!onBatchChangeProp) return void 0;
|
|
3385
|
+
return (rowId, columnId, value) => onBatchChangeProp([{ rowId, columnId, value }]);
|
|
3386
|
+
}, [onBatchChangeProp, onCellChangeProp]);
|
|
3387
|
+
const onBatchChange = (0, import_react6.useMemo)(() => {
|
|
3388
|
+
if (onBatchChangeProp) return onBatchChangeProp;
|
|
3389
|
+
if (!onCellChangeProp) return void 0;
|
|
3390
|
+
return (changes) => {
|
|
3391
|
+
for (const change of changes) {
|
|
3392
|
+
onCellChangeProp(change.rowId, change.columnId, change.value);
|
|
3393
|
+
}
|
|
3394
|
+
};
|
|
3395
|
+
}, [onBatchChangeProp, onCellChangeProp]);
|
|
3396
|
+
const hasWriteCallback = Boolean(onCellChange || onBatchChange || onDataChange);
|
|
2866
3397
|
const labels = (0, import_react6.useMemo)(() => {
|
|
2867
3398
|
const resolved = resolveDataTableLabels(labelsProp);
|
|
2868
3399
|
return {
|
|
@@ -2880,7 +3411,7 @@ function useGlideTable(options) {
|
|
|
2880
3411
|
const [internalExpandedRows, setInternalExpandedRows] = (0, import_react6.useState)(
|
|
2881
3412
|
() => /* @__PURE__ */ new Set()
|
|
2882
3413
|
);
|
|
2883
|
-
const [
|
|
3414
|
+
const [hoverStore] = (0, import_react6.useState)(createRowHoverStore);
|
|
2884
3415
|
const scrollRef = (0, import_react6.useRef)(null);
|
|
2885
3416
|
const rootRef = (0, import_react6.useRef)(null);
|
|
2886
3417
|
const escapeDismissOwnerRef = (0, import_react6.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
@@ -2937,8 +3468,10 @@ function useGlideTable(options) {
|
|
|
2937
3468
|
qtyField,
|
|
2938
3469
|
expandedRows,
|
|
2939
3470
|
onExpandedRowsChange: enableExpand ? handleExpandedRowsChange : void 0,
|
|
2940
|
-
preventExpand
|
|
3471
|
+
preventExpand,
|
|
3472
|
+
autoExpandOnLoad
|
|
2941
3473
|
});
|
|
3474
|
+
const sourceData = (0, import_react6.useMemo)(() => data ?? [], [data]);
|
|
2942
3475
|
const table = (0, import_react_table.useReactTable)({
|
|
2943
3476
|
data: tableData,
|
|
2944
3477
|
columns: tableColumns,
|
|
@@ -2977,7 +3510,11 @@ function useGlideTable(options) {
|
|
|
2977
3510
|
);
|
|
2978
3511
|
},
|
|
2979
3512
|
getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
|
|
2980
|
-
getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (
|
|
3513
|
+
getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (
|
|
3514
|
+
// Tree rows: their path in the original data, which (unlike the
|
|
3515
|
+
// flattened index) survives expanding/collapsing rows above.
|
|
3516
|
+
(originalRow, index) => getTreeRowKey(originalRow) ?? String(index)
|
|
3517
|
+
)
|
|
2981
3518
|
});
|
|
2982
3519
|
const rowSpanColumnKeys = (0, import_react6.useMemo)(() => {
|
|
2983
3520
|
if (!enableRowSpan) return [];
|
|
@@ -2994,6 +3531,20 @@ function useGlideTable(options) {
|
|
|
2994
3531
|
const rows = table.getRowModel().rows;
|
|
2995
3532
|
const columnCount = table.getAllLeafColumns().length || 1;
|
|
2996
3533
|
const visibleLeafColumns = table.getVisibleLeafColumns();
|
|
3534
|
+
const canFill = enableCellSelection && hasWriteCallback && visibleLeafColumns.some((column) => isColumnEditable(column.columnDef));
|
|
3535
|
+
const warnedBooleanColumnsRef = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
|
|
3536
|
+
(0, import_react6.useEffect)(() => {
|
|
3537
|
+
if (!hasWriteCallback || isProductionBuild()) return;
|
|
3538
|
+
for (const column of visibleLeafColumns) {
|
|
3539
|
+
const meta = column.columnDef.meta;
|
|
3540
|
+
if (meta?.kind !== "boolean" || meta.editable !== void 0 || meta.cellRender) continue;
|
|
3541
|
+
if (warnedBooleanColumnsRef.current.has(column.id)) continue;
|
|
3542
|
+
warnedBooleanColumnsRef.current.add(column.id);
|
|
3543
|
+
console.warn(
|
|
3544
|
+
`[react-glide-table] Column "${column.id}" (kind "boolean") has no \`editable\` prop, so its checkbox writes on click. Set editable={true} to keep that, or editable={false} for a read-only checkbox. A future major release will make boolean cells read-only unless editable is set, like other cells.`
|
|
3545
|
+
);
|
|
3546
|
+
}
|
|
3547
|
+
}, [hasWriteCallback, visibleLeafColumns]);
|
|
2997
3548
|
const columnFreezeOffsets = (0, import_react6.useMemo)(() => {
|
|
2998
3549
|
if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
|
|
2999
3550
|
return buildColumnFreezeOffsets(
|
|
@@ -3036,7 +3587,7 @@ function useGlideTable(options) {
|
|
|
3036
3587
|
const cell = scrollElement.querySelector(
|
|
3037
3588
|
`[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
|
|
3038
3589
|
);
|
|
3039
|
-
if (cell instanceof HTMLElement) {
|
|
3590
|
+
if (cell instanceof HTMLElement && typeof cell.scrollIntoView === "function") {
|
|
3040
3591
|
cell.scrollIntoView({ block: blockAlign, inline: "nearest" });
|
|
3041
3592
|
}
|
|
3042
3593
|
};
|
|
@@ -3054,6 +3605,10 @@ function useGlideTable(options) {
|
|
|
3054
3605
|
},
|
|
3055
3606
|
[scrollCellIntoView]
|
|
3056
3607
|
);
|
|
3608
|
+
const editKeyRef = (0, import_react6.useRef)(() => {
|
|
3609
|
+
});
|
|
3610
|
+
const clearKeyRef = (0, import_react6.useRef)(() => {
|
|
3611
|
+
});
|
|
3057
3612
|
const {
|
|
3058
3613
|
dragState,
|
|
3059
3614
|
activeSelectionBounds,
|
|
@@ -3061,20 +3616,27 @@ function useGlideTable(options) {
|
|
|
3061
3616
|
handleCellMouseEnter,
|
|
3062
3617
|
handleFillHandleMouseDown,
|
|
3063
3618
|
clearSelection: clearCellSelection,
|
|
3064
|
-
copySelection
|
|
3619
|
+
copySelection,
|
|
3620
|
+
selectCell,
|
|
3621
|
+
focusSelection
|
|
3065
3622
|
} = useCellSelection({
|
|
3066
|
-
data:
|
|
3623
|
+
data: sourceData,
|
|
3067
3624
|
rows,
|
|
3068
3625
|
enabled: enableCellSelection,
|
|
3069
3626
|
columnCount: visibleLeafColumns.length,
|
|
3627
|
+
columnSignature: visibleLeafColumns.map((column) => column.id).join("\0"),
|
|
3070
3628
|
enableSubtreeCopy: resolvedEnableSubtreeCopy,
|
|
3629
|
+
escapeCopyFormulas,
|
|
3071
3630
|
enableInsertPaste: enableInsertPaste ?? true,
|
|
3072
3631
|
onDataChange,
|
|
3073
3632
|
onBatchChange,
|
|
3074
3633
|
onRowsPaste,
|
|
3075
3634
|
onCellNavigate: handleCellNavigate,
|
|
3076
3635
|
cellRendererRegistry,
|
|
3077
|
-
rootRef
|
|
3636
|
+
rootRef,
|
|
3637
|
+
enableWasdNavigation,
|
|
3638
|
+
onEditKey: (position) => editKeyRef.current(position),
|
|
3639
|
+
onClearKey: (bounds) => clearKeyRef.current(bounds)
|
|
3078
3640
|
});
|
|
3079
3641
|
const clearRowSelection = (0, import_react6.useCallback)(() => {
|
|
3080
3642
|
if (rowSelectionMode === "none") return;
|
|
@@ -3095,22 +3657,79 @@ function useGlideTable(options) {
|
|
|
3095
3657
|
const {
|
|
3096
3658
|
editingCell,
|
|
3097
3659
|
draftValue,
|
|
3660
|
+
draftInvalid,
|
|
3661
|
+
setDraftInvalid,
|
|
3098
3662
|
setDraftValue,
|
|
3099
3663
|
startEdit,
|
|
3100
3664
|
commitEdit,
|
|
3101
3665
|
cancelEdit
|
|
3102
|
-
} = useCellEdit({ data:
|
|
3666
|
+
} = useCellEdit({ data: sourceData, rows, onDataChange, onCellChange });
|
|
3667
|
+
editKeyRef.current = (position) => {
|
|
3668
|
+
startEdit(position.row, position.col);
|
|
3669
|
+
};
|
|
3670
|
+
clearKeyRef.current = (bounds) => {
|
|
3671
|
+
const changes = [];
|
|
3672
|
+
for (let rowIndex = bounds.startRow; rowIndex <= bounds.endRow; rowIndex += 1) {
|
|
3673
|
+
const row = rows[rowIndex];
|
|
3674
|
+
if (!row) continue;
|
|
3675
|
+
const cells = row.getVisibleCells();
|
|
3676
|
+
for (let colIndex = bounds.startCol; colIndex <= bounds.endCol; colIndex += 1) {
|
|
3677
|
+
const cell = cells[colIndex];
|
|
3678
|
+
if (!cell || !isColumnEditable(cell.column.columnDef)) continue;
|
|
3679
|
+
changes.push({ rowId: row.id, columnId: cell.column.id, value: null });
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
if (changes.length === 0) return;
|
|
3683
|
+
if (onBatchChange) {
|
|
3684
|
+
onBatchChange(changes);
|
|
3685
|
+
return;
|
|
3686
|
+
}
|
|
3687
|
+
if (!onDataChange) return;
|
|
3688
|
+
let next = sourceData;
|
|
3689
|
+
for (const change of changes) {
|
|
3690
|
+
const row = rows.find((item) => item.id === change.rowId);
|
|
3691
|
+
const cell = row?.getVisibleCells().find((item) => item.column.id === change.columnId);
|
|
3692
|
+
const accessorKey = cell ? getColumnAccessorKey(cell.column.columnDef) : void 0;
|
|
3693
|
+
if (!row || !accessorKey) continue;
|
|
3694
|
+
next = applyCellChangesToData(next, [
|
|
3695
|
+
{ original: row.original, index: row.index, accessorKey, value: null }
|
|
3696
|
+
]);
|
|
3697
|
+
}
|
|
3698
|
+
if (next !== sourceData) onDataChange(next);
|
|
3699
|
+
};
|
|
3700
|
+
const commitEditAndMove = (0, import_react6.useCallback)(
|
|
3701
|
+
(raw, delta) => {
|
|
3702
|
+
const current = editingCell;
|
|
3703
|
+
if (!commitEdit(raw)) return false;
|
|
3704
|
+
if (current) {
|
|
3705
|
+
selectCell(current.rowIndex + delta.row, current.colIndex + delta.col);
|
|
3706
|
+
}
|
|
3707
|
+
rootRef.current?.focus({ preventScroll: true });
|
|
3708
|
+
return true;
|
|
3709
|
+
},
|
|
3710
|
+
[commitEdit, editingCell, selectCell]
|
|
3711
|
+
);
|
|
3712
|
+
const cancelEditAndRefocus = (0, import_react6.useCallback)(() => {
|
|
3713
|
+
cancelEdit();
|
|
3714
|
+
rootRef.current?.focus({ preventScroll: true });
|
|
3715
|
+
}, [cancelEdit]);
|
|
3103
3716
|
const commitRenderedCellValue = (0, import_react6.useCallback)(
|
|
3104
|
-
(rowId, columnId, value) =>
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3717
|
+
(rowId, columnId, value) => {
|
|
3718
|
+
const columnDef = table.getColumn(columnId)?.columnDef;
|
|
3719
|
+
if (columnDef && (columnDef.meta?.editable === false || isProtectedColumn(columnDef))) {
|
|
3720
|
+
return false;
|
|
3721
|
+
}
|
|
3722
|
+
return commitCellValue({
|
|
3723
|
+
data: sourceData,
|
|
3724
|
+
rows,
|
|
3725
|
+
rowId,
|
|
3726
|
+
columnId,
|
|
3727
|
+
value,
|
|
3728
|
+
onCellChange,
|
|
3729
|
+
onDataChange
|
|
3730
|
+
});
|
|
3731
|
+
},
|
|
3732
|
+
[onCellChange, onDataChange, rows, sourceData, table]
|
|
3114
3733
|
);
|
|
3115
3734
|
const getCellContext = (0, import_react6.useCallback)(
|
|
3116
3735
|
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
@@ -3138,25 +3757,12 @@ function useGlideTable(options) {
|
|
|
3138
3757
|
(row, index) => {
|
|
3139
3758
|
if (getRowId) return getRowId(row, index);
|
|
3140
3759
|
if (enableExpand) {
|
|
3141
|
-
const
|
|
3142
|
-
|
|
3143
|
-
if (idValue != null && String(idValue).length > 0) {
|
|
3144
|
-
return String(idValue);
|
|
3145
|
-
}
|
|
3146
|
-
const uniqueId = record.uniqueId;
|
|
3147
|
-
if (uniqueId != null && String(uniqueId).length > 0) {
|
|
3148
|
-
return String(uniqueId);
|
|
3149
|
-
}
|
|
3150
|
-
if (toggleField) {
|
|
3151
|
-
const toggleValue = record[toggleField];
|
|
3152
|
-
if (toggleValue != null && String(toggleValue).length > 0) {
|
|
3153
|
-
return String(toggleValue);
|
|
3154
|
-
}
|
|
3155
|
-
}
|
|
3760
|
+
const treeKey = getTreeRowKey(row);
|
|
3761
|
+
if (treeKey) return treeKey;
|
|
3156
3762
|
}
|
|
3157
3763
|
return String(index);
|
|
3158
3764
|
},
|
|
3159
|
-
[enableExpand, getRowId
|
|
3765
|
+
[enableExpand, getRowId]
|
|
3160
3766
|
);
|
|
3161
3767
|
const searchCorpus = (0, import_react6.useMemo)(() => {
|
|
3162
3768
|
if (!enableInlineSearch) return [];
|
|
@@ -3183,28 +3789,59 @@ function useGlideTable(options) {
|
|
|
3183
3789
|
}
|
|
3184
3790
|
return map;
|
|
3185
3791
|
}, [resolveSearchRowId, rows]);
|
|
3186
|
-
const
|
|
3187
|
-
(rowIndex,
|
|
3188
|
-
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
3189
|
-
const column = visibleLeafColumns[colIndex];
|
|
3190
|
-
if (!corpusRow || !column) return void 0;
|
|
3792
|
+
const readSearchRawValue = (0, import_react6.useCallback)(
|
|
3793
|
+
(corpusRow, rowIndex, column) => {
|
|
3191
3794
|
const visibleIndex = visibleRowIndexById.get(corpusRow.id);
|
|
3192
3795
|
if (visibleIndex !== void 0) {
|
|
3193
3796
|
const visibleRow = rows[visibleIndex];
|
|
3194
3797
|
if (visibleRow) {
|
|
3195
|
-
return visibleRow.getValue(column.id);
|
|
3798
|
+
return { value: visibleRow.getValue(column.id), row: visibleRow };
|
|
3196
3799
|
}
|
|
3197
3800
|
}
|
|
3198
3801
|
const columnDef = column.columnDef;
|
|
3199
3802
|
if ("accessorFn" in columnDef && typeof columnDef.accessorFn === "function") {
|
|
3200
|
-
return columnDef.accessorFn(corpusRow.data, rowIndex);
|
|
3803
|
+
return { value: columnDef.accessorFn(corpusRow.data, rowIndex), row: void 0 };
|
|
3201
3804
|
}
|
|
3202
3805
|
if ("accessorKey" in columnDef && columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
3203
|
-
return
|
|
3806
|
+
return {
|
|
3807
|
+
value: corpusRow.data[String(columnDef.accessorKey)],
|
|
3808
|
+
row: void 0
|
|
3809
|
+
};
|
|
3810
|
+
}
|
|
3811
|
+
return { value: corpusRow.data[column.id], row: void 0 };
|
|
3812
|
+
},
|
|
3813
|
+
[rows, visibleRowIndexById]
|
|
3814
|
+
);
|
|
3815
|
+
const getSearchCellValue = (0, import_react6.useCallback)(
|
|
3816
|
+
(rowIndex, colIndex) => {
|
|
3817
|
+
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
3818
|
+
const column = visibleLeafColumns[colIndex];
|
|
3819
|
+
if (!corpusRow || !column) return void 0;
|
|
3820
|
+
if (isProtectedColumn(column.columnDef)) return void 0;
|
|
3821
|
+
const { value, row } = readSearchRawValue(corpusRow, rowIndex, column);
|
|
3822
|
+
const meta = column.columnDef.meta;
|
|
3823
|
+
const searchValue2 = meta?.searchValue;
|
|
3824
|
+
if (!searchValue2 || searchValue2 === "value") return value;
|
|
3825
|
+
const ctx = {
|
|
3826
|
+
value,
|
|
3827
|
+
row: row ?? { id: corpusRow.id, index: rowIndex, original: corpusRow.data },
|
|
3828
|
+
index: row?.index ?? rowIndex,
|
|
3829
|
+
columnId: column.id,
|
|
3830
|
+
cellProps: meta?.cellProps,
|
|
3831
|
+
update: () => {
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
try {
|
|
3835
|
+
if (typeof searchValue2 === "function") return searchValue2(ctx);
|
|
3836
|
+
if (meta?.cellRender) return reactNodeToText(meta.cellRender(ctx));
|
|
3837
|
+
const renderer = resolveCellRenderer(cellRendererRegistry, meta?.kind, ctx);
|
|
3838
|
+
if (renderer) return reactNodeToText(renderer.render(ctx));
|
|
3839
|
+
} catch {
|
|
3840
|
+
return value;
|
|
3204
3841
|
}
|
|
3205
|
-
return
|
|
3842
|
+
return value;
|
|
3206
3843
|
},
|
|
3207
|
-
[
|
|
3844
|
+
[cellRendererRegistry, readSearchRawValue, visibleLeafColumns]
|
|
3208
3845
|
);
|
|
3209
3846
|
const pendingSearchNavRef = (0, import_react6.useRef)(null);
|
|
3210
3847
|
const focusSearchResult = (0, import_react6.useCallback)(
|
|
@@ -3255,11 +3892,19 @@ function useGlideTable(options) {
|
|
|
3255
3892
|
focusSearchResult(pending.colIndex, visibleRowIndex);
|
|
3256
3893
|
}, [focusSearchResult, rows, visibleRowIndexById]);
|
|
3257
3894
|
const initialSearchStartRow = virtualRows[0]?.index ?? 0;
|
|
3895
|
+
const searchColumnSignature = visibleLeafColumns.map((column) => column.id).join("\0");
|
|
3896
|
+
const searchContentKey = (0, import_react6.useMemo)(
|
|
3897
|
+
() => ({ data: sourceData, columns: searchColumnSignature }),
|
|
3898
|
+
[sourceData, searchColumnSignature]
|
|
3899
|
+
);
|
|
3258
3900
|
const inlineSearch = useInlineSearch({
|
|
3259
3901
|
enabled: enableInlineSearch,
|
|
3260
3902
|
rowCount: searchCorpus.length,
|
|
3261
3903
|
columnCount: visibleLeafColumns.length,
|
|
3262
3904
|
getCellValue: getSearchCellValue,
|
|
3905
|
+
// Re-scan when the rows' content/order or the column order changes
|
|
3906
|
+
// (edits, re-sorts, reorders) — not on tree expand/collapse.
|
|
3907
|
+
contentKey: searchContentKey,
|
|
3263
3908
|
initialStartRow: initialSearchStartRow,
|
|
3264
3909
|
showSearch,
|
|
3265
3910
|
searchValue,
|
|
@@ -3297,11 +3942,14 @@ function useGlideTable(options) {
|
|
|
3297
3942
|
visibleRowIndexById
|
|
3298
3943
|
]);
|
|
3299
3944
|
const clearHover = (0, import_react6.useCallback)(() => {
|
|
3300
|
-
setHoveredRowIndex(null);
|
|
3301
|
-
}, []);
|
|
3302
|
-
const handleRowHover = (0, import_react6.useCallback)(
|
|
3303
|
-
|
|
3304
|
-
|
|
3945
|
+
hoverStore.setHoveredRowIndex(null);
|
|
3946
|
+
}, [hoverStore]);
|
|
3947
|
+
const handleRowHover = (0, import_react6.useCallback)(
|
|
3948
|
+
(rowIndex, _rowData) => {
|
|
3949
|
+
hoverStore.setHoveredRowIndex(rowIndex);
|
|
3950
|
+
},
|
|
3951
|
+
[hoverStore]
|
|
3952
|
+
);
|
|
3305
3953
|
const handleToggleSelect = (0, import_react6.useCallback)(
|
|
3306
3954
|
(row) => {
|
|
3307
3955
|
if (!row.getCanSelect()) return;
|
|
@@ -3326,7 +3974,7 @@ function useGlideTable(options) {
|
|
|
3326
3974
|
primaryRowSpanKey,
|
|
3327
3975
|
primaryRowSpanColumnId,
|
|
3328
3976
|
columnRowSpanMap,
|
|
3329
|
-
|
|
3977
|
+
hoverStore,
|
|
3330
3978
|
selectedRowIndices,
|
|
3331
3979
|
onRowHover: handleRowHover
|
|
3332
3980
|
},
|
|
@@ -3340,6 +3988,7 @@ function useGlideTable(options) {
|
|
|
3340
3988
|
enableCellSelection,
|
|
3341
3989
|
activeSelectionBounds,
|
|
3342
3990
|
dragState,
|
|
3991
|
+
canFill,
|
|
3343
3992
|
onCellMouseDown: handleCellMouseDownWithCommit,
|
|
3344
3993
|
onCellMouseEnter: handleCellMouseEnter,
|
|
3345
3994
|
onFillHandleMouseDown: handleFillHandleMouseDown
|
|
@@ -3347,18 +3996,23 @@ function useGlideTable(options) {
|
|
|
3347
3996
|
cellEdit: {
|
|
3348
3997
|
editingCell,
|
|
3349
3998
|
draftValue,
|
|
3999
|
+
draftInvalid,
|
|
4000
|
+
onDraftInvalidChange: setDraftInvalid,
|
|
3350
4001
|
onDraftValueChange: setDraftValue,
|
|
3351
4002
|
onStartEdit: startEdit,
|
|
3352
4003
|
onCommitEdit: commitEdit,
|
|
3353
|
-
|
|
4004
|
+
onCommitEditAndMove: commitEditAndMove,
|
|
4005
|
+
onCancelEdit: cancelEditAndRefocus
|
|
3354
4006
|
},
|
|
3355
4007
|
cellRender: {
|
|
3356
4008
|
registry: cellRendererRegistry,
|
|
3357
|
-
commitValue: commitRenderedCellValue
|
|
4009
|
+
commitValue: commitRenderedCellValue,
|
|
4010
|
+
protectedLabel: labels.protectedCell
|
|
3358
4011
|
},
|
|
3359
4012
|
expand: {
|
|
3360
4013
|
enableExpand,
|
|
3361
4014
|
toggleField,
|
|
4015
|
+
expandColumn,
|
|
3362
4016
|
expandedRows,
|
|
3363
4017
|
preventExpand,
|
|
3364
4018
|
onToggleExpand: handleToggleExpand,
|
|
@@ -3383,7 +4037,7 @@ function useGlideTable(options) {
|
|
|
3383
4037
|
primaryRowSpanKey,
|
|
3384
4038
|
primaryRowSpanColumnId,
|
|
3385
4039
|
columnRowSpanMap,
|
|
3386
|
-
|
|
4040
|
+
hoverStore,
|
|
3387
4041
|
selectedRowIndices,
|
|
3388
4042
|
handleRowHover,
|
|
3389
4043
|
rowSelectionMode,
|
|
@@ -3393,19 +4047,25 @@ function useGlideTable(options) {
|
|
|
3393
4047
|
enableCellSelection,
|
|
3394
4048
|
activeSelectionBounds,
|
|
3395
4049
|
dragState,
|
|
4050
|
+
canFill,
|
|
3396
4051
|
handleCellMouseDownWithCommit,
|
|
3397
4052
|
handleCellMouseEnter,
|
|
3398
4053
|
handleFillHandleMouseDown,
|
|
3399
4054
|
editingCell,
|
|
3400
4055
|
draftValue,
|
|
4056
|
+
draftInvalid,
|
|
4057
|
+
setDraftInvalid,
|
|
3401
4058
|
setDraftValue,
|
|
3402
4059
|
startEdit,
|
|
3403
4060
|
commitEdit,
|
|
3404
|
-
|
|
4061
|
+
commitEditAndMove,
|
|
4062
|
+
cancelEditAndRefocus,
|
|
3405
4063
|
cellRendererRegistry,
|
|
3406
4064
|
commitRenderedCellValue,
|
|
4065
|
+
labels.protectedCell,
|
|
3407
4066
|
enableExpand,
|
|
3408
4067
|
toggleField,
|
|
4068
|
+
expandColumn,
|
|
3409
4069
|
expandedRows,
|
|
3410
4070
|
preventExpand,
|
|
3411
4071
|
handleToggleExpand,
|
|
@@ -3453,6 +4113,7 @@ function useGlideTable(options) {
|
|
|
3453
4113
|
handleToggleSelect,
|
|
3454
4114
|
clearHover,
|
|
3455
4115
|
setColumnOrder,
|
|
4116
|
+
handleRootFocus: focusSelection,
|
|
3456
4117
|
copySelection: stableCopySelection,
|
|
3457
4118
|
inlineSearch: {
|
|
3458
4119
|
showSearch: inlineSearch.showSearch,
|
|
@@ -3509,12 +4170,16 @@ function ResolvedTableCell({
|
|
|
3509
4170
|
},
|
|
3510
4171
|
[cellRender, columnId, row.id]
|
|
3511
4172
|
);
|
|
4173
|
+
let cellProps = meta?.editable === false ? { ...meta.cellProps, readonly: true } : meta?.cellProps;
|
|
4174
|
+
if (meta?.kind === "protected" && cellRender.protectedLabel && cellProps?.ariaLabel === void 0) {
|
|
4175
|
+
cellProps = { ...cellProps, ariaLabel: cellRender.protectedLabel };
|
|
4176
|
+
}
|
|
3512
4177
|
const ctx = {
|
|
3513
4178
|
value,
|
|
3514
4179
|
row,
|
|
3515
4180
|
index: row.index,
|
|
3516
4181
|
columnId,
|
|
3517
|
-
cellProps
|
|
4182
|
+
cellProps,
|
|
3518
4183
|
update
|
|
3519
4184
|
};
|
|
3520
4185
|
if (meta?.cellRender) {
|
|
@@ -4046,7 +4711,11 @@ function blurActiveElementOutside(container) {
|
|
|
4046
4711
|
if (container instanceof Node && container.contains(active)) return;
|
|
4047
4712
|
active.blur();
|
|
4048
4713
|
}
|
|
4049
|
-
function resolveExpandCellIndex(cells, toggleField) {
|
|
4714
|
+
function resolveExpandCellIndex(cells, toggleField, expandColumn) {
|
|
4715
|
+
if (expandColumn) {
|
|
4716
|
+
const explicitIndex = cells.findIndex((cell) => cell.column.id === expandColumn);
|
|
4717
|
+
if (explicitIndex >= 0) return explicitIndex;
|
|
4718
|
+
}
|
|
4050
4719
|
if (!toggleField) return 0;
|
|
4051
4720
|
const matchedIndex = cells.findIndex(
|
|
4052
4721
|
(cell) => cell.column.id === toggleField
|
|
@@ -4089,7 +4758,7 @@ function DataTableRow({
|
|
|
4089
4758
|
enableRowSpan,
|
|
4090
4759
|
primaryRowSpanColumnId,
|
|
4091
4760
|
columnRowSpanMap,
|
|
4092
|
-
|
|
4761
|
+
hoverStore,
|
|
4093
4762
|
selectedRowIndices,
|
|
4094
4763
|
onRowHover
|
|
4095
4764
|
} = rowSpan;
|
|
@@ -4098,6 +4767,7 @@ function DataTableRow({
|
|
|
4098
4767
|
enableCellSelection,
|
|
4099
4768
|
activeSelectionBounds,
|
|
4100
4769
|
dragState,
|
|
4770
|
+
canFill = true,
|
|
4101
4771
|
onCellMouseDown,
|
|
4102
4772
|
onCellMouseEnter,
|
|
4103
4773
|
onFillHandleMouseDown
|
|
@@ -4105,9 +4775,12 @@ function DataTableRow({
|
|
|
4105
4775
|
const {
|
|
4106
4776
|
editingCell,
|
|
4107
4777
|
draftValue,
|
|
4778
|
+
draftInvalid = false,
|
|
4779
|
+
onDraftInvalidChange,
|
|
4108
4780
|
onDraftValueChange,
|
|
4109
4781
|
onStartEdit,
|
|
4110
4782
|
onCommitEdit,
|
|
4783
|
+
onCommitEditAndMove,
|
|
4111
4784
|
onCancelEdit
|
|
4112
4785
|
} = cellEdit;
|
|
4113
4786
|
const renderCell = (tableCell) => (0, import_react_table2.flexRender)(
|
|
@@ -4117,6 +4790,7 @@ function DataTableRow({
|
|
|
4117
4790
|
const {
|
|
4118
4791
|
enableExpand,
|
|
4119
4792
|
toggleField,
|
|
4793
|
+
expandColumn,
|
|
4120
4794
|
expandedRows,
|
|
4121
4795
|
preventExpand,
|
|
4122
4796
|
onToggleExpand,
|
|
@@ -4125,13 +4799,50 @@ function DataTableRow({
|
|
|
4125
4799
|
} = expand;
|
|
4126
4800
|
const rowIndex = row.index;
|
|
4127
4801
|
const rowData = row.original;
|
|
4128
|
-
const isRowHovered = hoveredRowIndex === rowIndex;
|
|
4129
4802
|
const isRowSelected = row.getIsSelected();
|
|
4130
4803
|
const { startRow: primaryGroupStart, rowSpan: primaryGroupSpan } = resolveRowSpanAt(
|
|
4131
4804
|
primaryRowSpanColumnId ? columnRowSpanMap.get(primaryRowSpanColumnId) : void 0,
|
|
4132
4805
|
rowIndex
|
|
4133
4806
|
);
|
|
4134
|
-
const
|
|
4807
|
+
const isRowHovered2 = (0, import_react10.useSyncExternalStore)(
|
|
4808
|
+
hoverStore.subscribe,
|
|
4809
|
+
() => isRowHovered(hoverStore.getHoveredRowIndex(), rowIndex),
|
|
4810
|
+
() => false
|
|
4811
|
+
);
|
|
4812
|
+
const isGroupHovered = (0, import_react10.useSyncExternalStore)(
|
|
4813
|
+
hoverStore.subscribe,
|
|
4814
|
+
() => isRowGroupHovered(
|
|
4815
|
+
hoverStore.getHoveredRowIndex(),
|
|
4816
|
+
enableRowSpan,
|
|
4817
|
+
primaryGroupStart,
|
|
4818
|
+
primaryGroupSpan
|
|
4819
|
+
),
|
|
4820
|
+
() => false
|
|
4821
|
+
);
|
|
4822
|
+
const rowSpanColumnIds = enableRowSpan ? [...columnRowSpanMap.keys()].filter((id) => id !== primaryRowSpanColumnId) : [];
|
|
4823
|
+
const nestedRowSpanRanges = rowSpanColumnIds.map((columnId) => {
|
|
4824
|
+
const { startRow, rowSpan: span } = resolveRowSpanAt(
|
|
4825
|
+
columnRowSpanMap.get(columnId),
|
|
4826
|
+
rowIndex
|
|
4827
|
+
);
|
|
4828
|
+
return { columnId, startRow, span };
|
|
4829
|
+
});
|
|
4830
|
+
const nestedHoverSignature = (0, import_react10.useSyncExternalStore)(
|
|
4831
|
+
hoverStore.subscribe,
|
|
4832
|
+
() => {
|
|
4833
|
+
const hovered = hoverStore.getHoveredRowIndex();
|
|
4834
|
+
return nestedRowSpanRanges.map(
|
|
4835
|
+
({ startRow, span }) => isRowGroupHovered(hovered, true, startRow, span) ? "1" : "0"
|
|
4836
|
+
).join("");
|
|
4837
|
+
},
|
|
4838
|
+
() => rowSpanColumnIds.map(() => "0").join("")
|
|
4839
|
+
);
|
|
4840
|
+
const nestedHoverByColumn = new Map(
|
|
4841
|
+
rowSpanColumnIds.map((columnId, index) => [
|
|
4842
|
+
columnId,
|
|
4843
|
+
nestedHoverSignature[index] === "1"
|
|
4844
|
+
])
|
|
4845
|
+
);
|
|
4135
4846
|
const visibleCells = row.getVisibleCells();
|
|
4136
4847
|
const columnIdsByIndex = visibleCells.map((cell) => cell.column.id);
|
|
4137
4848
|
row.getIsCellDragSelected = (columnId) => {
|
|
@@ -4177,12 +4888,13 @@ function DataTableRow({
|
|
|
4177
4888
|
span
|
|
4178
4889
|
);
|
|
4179
4890
|
} : void 0;
|
|
4180
|
-
const expandCellIndex = enableExpand ? resolveExpandCellIndex(visibleCells, toggleField) : -1;
|
|
4891
|
+
const expandCellIndex = enableExpand ? resolveExpandCellIndex(visibleCells, toggleField, expandColumn) : -1;
|
|
4181
4892
|
const canExpand = enableExpand && !preventExpand && canExpandRow(rowData);
|
|
4182
4893
|
const expandKey = toggleField && rowData[toggleField] !== null && rowData[toggleField] !== void 0 ? String(rowData[toggleField]) : null;
|
|
4183
4894
|
const isExpanded = expandKey !== null && Boolean(expandedRows?.has(expandKey));
|
|
4184
4895
|
const rowLevel = typeof rowData.level === "number" ? rowData.level : 0;
|
|
4185
4896
|
const editInputRef = (0, import_react10.useRef)(null);
|
|
4897
|
+
const cellPressRef = (0, import_react10.useRef)(false);
|
|
4186
4898
|
const isRowEditing = editingCell?.rowIndex === rowIndex;
|
|
4187
4899
|
(0, import_react10.useEffect)(() => {
|
|
4188
4900
|
if (!isRowEditing) return;
|
|
@@ -4195,23 +4907,29 @@ function DataTableRow({
|
|
|
4195
4907
|
ref: measureElement,
|
|
4196
4908
|
"data-index": virtualIndex,
|
|
4197
4909
|
"data-selected": isRowSelected ? "" : void 0,
|
|
4198
|
-
"data-hovered":
|
|
4910
|
+
"data-hovered": isRowHovered2 || isGroupHovered ? "" : void 0,
|
|
4199
4911
|
"data-expandable": enableExpand && canExpand ? "" : void 0,
|
|
4200
4912
|
"data-expanded": isExpanded ? "" : void 0,
|
|
4913
|
+
"data-level": enableExpand ? rowLevel : void 0,
|
|
4201
4914
|
className: cn(
|
|
4202
4915
|
"DataTableRowJSX",
|
|
4203
4916
|
!enableRowSpan && ROW_HOVER_CLASS,
|
|
4204
|
-
enableRowSpan &&
|
|
4917
|
+
enableRowSpan && isRowHovered2 && !isRowSelected && ROW_HOVERED_BG_CLASS,
|
|
4205
4918
|
isRowSelected && "is-selected",
|
|
4206
4919
|
enableExpand && canExpand && "is-expandable",
|
|
4207
4920
|
classNames?.row,
|
|
4208
4921
|
getRowClassName?.(rowData, rowIndex)
|
|
4209
4922
|
),
|
|
4210
4923
|
onMouseEnter: () => onRowHover(rowIndex, rowData),
|
|
4924
|
+
onMouseDownCapture: () => {
|
|
4925
|
+
cellPressRef.current = false;
|
|
4926
|
+
},
|
|
4211
4927
|
onClick: () => {
|
|
4928
|
+
const startedCellSelection = cellPressRef.current;
|
|
4929
|
+
cellPressRef.current = false;
|
|
4212
4930
|
if (isRowEditing) return;
|
|
4213
4931
|
onRowClick?.(rowData, rowIndex);
|
|
4214
|
-
if (rowSelectionMode !== "none" && selectOnRowClick) {
|
|
4932
|
+
if (rowSelectionMode !== "none" && selectOnRowClick && !startedCellSelection) {
|
|
4215
4933
|
onToggleSelect();
|
|
4216
4934
|
}
|
|
4217
4935
|
},
|
|
@@ -4234,8 +4952,8 @@ function DataTableRow({
|
|
|
4234
4952
|
}
|
|
4235
4953
|
const isEditing = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === cellIndex;
|
|
4236
4954
|
const cellRowSpan = rowSpanInfo?.rowSpan ?? 1;
|
|
4237
|
-
const isMergedCellHovered =
|
|
4238
|
-
const showCellHover = isRowSpanColumn ? isMergedCellHovered :
|
|
4955
|
+
const isMergedCellHovered = columnId === primaryRowSpanColumnId ? isGroupHovered : nestedHoverByColumn.get(columnId) ?? false;
|
|
4956
|
+
const showCellHover = isRowSpanColumn ? isMergedCellHovered : isRowHovered2;
|
|
4239
4957
|
let isMergedCellSelected = false;
|
|
4240
4958
|
if (isRowSpanColumn) {
|
|
4241
4959
|
for (let r = rowIndex; r < rowIndex + cellRowSpan; r += 1) {
|
|
@@ -4257,7 +4975,7 @@ function DataTableRow({
|
|
|
4257
4975
|
activeSelectionBounds,
|
|
4258
4976
|
cellRowSpan
|
|
4259
4977
|
);
|
|
4260
|
-
const isBottomRightCell = !isEditing && activeSelectionBounds && !dragState.isSelecting && activeSelectionBounds.endRow >= rowIndex && activeSelectionBounds.endRow <= rowIndex + cellRowSpan - 1 && cellIndex === activeSelectionBounds.endCol;
|
|
4978
|
+
const isBottomRightCell = canFill && !isEditing && activeSelectionBounds && !dragState.isSelecting && activeSelectionBounds.endRow >= rowIndex && activeSelectionBounds.endRow <= rowIndex + cellRowSpan - 1 && cellIndex === activeSelectionBounds.endCol;
|
|
4261
4979
|
const spanRowHeights = enableCellSelection && activeSelectionBounds && isCellDragSelected && cellRowSpan > 1 ? measureMergedSpanRowHeights(rowIndex, cellRowSpan) : void 0;
|
|
4262
4980
|
const selectionEdgeStyle = getCellSelectionEdgeStyle(
|
|
4263
4981
|
rowIndex,
|
|
@@ -4315,6 +5033,7 @@ function DataTableRow({
|
|
|
4315
5033
|
if (isInteractiveMouseTarget(event.target)) return;
|
|
4316
5034
|
event.preventDefault();
|
|
4317
5035
|
blurActiveElementOutside(event.currentTarget);
|
|
5036
|
+
cellPressRef.current = true;
|
|
4318
5037
|
onCellMouseDown(
|
|
4319
5038
|
resolveCellRowIndex(event.clientY, event.currentTarget),
|
|
4320
5039
|
cellIndex,
|
|
@@ -4368,6 +5087,8 @@ function DataTableRow({
|
|
|
4368
5087
|
ref: editInputRef,
|
|
4369
5088
|
type: editType === "number" ? "number" : "text",
|
|
4370
5089
|
defaultValue: draftValue,
|
|
5090
|
+
"aria-invalid": draftInvalid ? true : void 0,
|
|
5091
|
+
"data-invalid": draftInvalid ? "" : void 0,
|
|
4371
5092
|
className: cn(
|
|
4372
5093
|
"cell-edit-input",
|
|
4373
5094
|
CELL_ALIGN_CLASS[align],
|
|
@@ -4376,6 +5097,7 @@ function DataTableRow({
|
|
|
4376
5097
|
),
|
|
4377
5098
|
onChange: (event) => {
|
|
4378
5099
|
editInputProps?.onChange?.(event);
|
|
5100
|
+
onDraftInvalidChange?.(Boolean(event.target.validity?.badInput));
|
|
4379
5101
|
onDraftValueChange(event.target.value);
|
|
4380
5102
|
},
|
|
4381
5103
|
onMouseDown: (event) => {
|
|
@@ -4389,9 +5111,22 @@ function DataTableRow({
|
|
|
4389
5111
|
onKeyDown: (event) => {
|
|
4390
5112
|
editInputProps?.onKeyDown?.(event);
|
|
4391
5113
|
if (event.defaultPrevented) return;
|
|
4392
|
-
if (event.
|
|
5114
|
+
if (event.nativeEvent.isComposing || event.keyCode === 229) {
|
|
5115
|
+
return;
|
|
5116
|
+
}
|
|
5117
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
4393
5118
|
event.preventDefault();
|
|
4394
|
-
|
|
5119
|
+
if (event.currentTarget.validity?.badInput) {
|
|
5120
|
+
onDraftInvalidChange?.(true);
|
|
5121
|
+
return;
|
|
5122
|
+
}
|
|
5123
|
+
const delta = event.key === "Enter" ? { row: event.shiftKey ? -1 : 1, col: 0 } : { row: 0, col: event.shiftKey ? -1 : 1 };
|
|
5124
|
+
if (onCommitEditAndMove) {
|
|
5125
|
+
onCommitEditAndMove(event.currentTarget.value, delta);
|
|
5126
|
+
} else {
|
|
5127
|
+
onCommitEdit(event.currentTarget.value);
|
|
5128
|
+
}
|
|
5129
|
+
return;
|
|
4395
5130
|
}
|
|
4396
5131
|
if (event.key === "Escape") {
|
|
4397
5132
|
event.preventDefault();
|
|
@@ -4401,6 +5136,10 @@ function DataTableRow({
|
|
|
4401
5136
|
onBlur: (event) => {
|
|
4402
5137
|
editInputProps?.onBlur?.(event);
|
|
4403
5138
|
if (event.defaultPrevented) return;
|
|
5139
|
+
if (event.currentTarget.validity?.badInput) {
|
|
5140
|
+
onDraftInvalidChange?.(true);
|
|
5141
|
+
return;
|
|
5142
|
+
}
|
|
4404
5143
|
onCommitEdit(event.currentTarget.value);
|
|
4405
5144
|
}
|
|
4406
5145
|
}
|
|
@@ -4412,6 +5151,7 @@ function DataTableRow({
|
|
|
4412
5151
|
"expand-cell-content",
|
|
4413
5152
|
classNames?.expandCellContent
|
|
4414
5153
|
),
|
|
5154
|
+
style: { "--table-row-level": rowLevel },
|
|
4415
5155
|
children: [
|
|
4416
5156
|
rowLevel > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
4417
5157
|
"span",
|
|
@@ -4441,6 +5181,7 @@ function DataTableRow({
|
|
|
4441
5181
|
{
|
|
4442
5182
|
type: "button",
|
|
4443
5183
|
"aria-label": isExpanded ? collapseRowLabel : expandRowLabel,
|
|
5184
|
+
"aria-expanded": isExpanded,
|
|
4444
5185
|
className: cn(
|
|
4445
5186
|
"expand-toggle-button",
|
|
4446
5187
|
classNames?.expandToggle
|
|
@@ -4527,6 +5268,7 @@ function DataTableSearch({
|
|
|
4527
5268
|
previousLabel,
|
|
4528
5269
|
nextLabel,
|
|
4529
5270
|
closeLabel,
|
|
5271
|
+
formatResult = formatSearchResultLabel,
|
|
4530
5272
|
rowsTotal,
|
|
4531
5273
|
classNames,
|
|
4532
5274
|
onSearchValueChange,
|
|
@@ -4535,9 +5277,10 @@ function DataTableSearch({
|
|
|
4535
5277
|
onPrevious
|
|
4536
5278
|
}) {
|
|
4537
5279
|
if (!showSearch) return null;
|
|
4538
|
-
const resultString = searchStatus ?
|
|
5280
|
+
const resultString = searchStatus ? formatResult(searchStatus) : resultHint;
|
|
4539
5281
|
const progress = rowsTotal > 0 ? Math.floor((searchStatus?.rowsSearched ?? 0) / rowsTotal * 100) : 0;
|
|
4540
5282
|
const handleKeyDown = (event) => {
|
|
5283
|
+
if (event.nativeEvent.isComposing || event.keyCode === 229) return;
|
|
4541
5284
|
if ((event.ctrlKey || event.metaKey) && event.code === "KeyF" || event.key === "Escape") {
|
|
4542
5285
|
event.preventDefault();
|
|
4543
5286
|
event.stopPropagation();
|
|
@@ -4661,6 +5404,7 @@ function DataTableToolbar({
|
|
|
4661
5404
|
summary,
|
|
4662
5405
|
selectedCount,
|
|
4663
5406
|
selectionLabel,
|
|
5407
|
+
countLabel,
|
|
4664
5408
|
toolbar,
|
|
4665
5409
|
className,
|
|
4666
5410
|
classNames
|
|
@@ -4674,7 +5418,7 @@ function DataTableToolbar({
|
|
|
4674
5418
|
if (!hasLeftContent && !hasToolbar && !hasSelectionContent) return null;
|
|
4675
5419
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: cn("DataTableToolbarJSX", classNames?.toolbar, className), children: [
|
|
4676
5420
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: cn("toolbar-left", classNames?.toolbarLeft), children: [
|
|
4677
|
-
hasCount && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: cn("toolbar-count", classNames?.toolbarCount), children: displayFiltered !== void 0 && totalCount !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
5421
|
+
hasCount && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: cn("toolbar-count", classNames?.toolbarCount), children: countLabel ? countLabel(displayFiltered, totalCount) : displayFiltered !== void 0 && totalCount !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
4678
5422
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "toolbar-count-primary", children: displayFiltered }),
|
|
4679
5423
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "toolbar-count-placeholder", children: [
|
|
4680
5424
|
" / ",
|
|
@@ -4801,7 +5545,8 @@ function DataTable({
|
|
|
4801
5545
|
handleToggleSelect,
|
|
4802
5546
|
clearHover,
|
|
4803
5547
|
setColumnOrder,
|
|
4804
|
-
inlineSearch
|
|
5548
|
+
inlineSearch,
|
|
5549
|
+
handleRootFocus
|
|
4805
5550
|
} = useGlideTable(glideOptions);
|
|
4806
5551
|
const ToolbarSlot = slots?.Toolbar ?? DataTableToolbar;
|
|
4807
5552
|
const ScrollSlot = slots?.Scroll ?? DefaultScroll;
|
|
@@ -4845,13 +5590,33 @@ function DataTable({
|
|
|
4845
5590
|
}));
|
|
4846
5591
|
return resolveColumnLayoutWidths(containerWidth, columns);
|
|
4847
5592
|
}, [enableColumnResize, containerWidth, table, columnLayoutMetaSignature]);
|
|
5593
|
+
const [measuredWidths, setMeasuredWidths] = (0, import_react11.useState)(
|
|
5594
|
+
() => /* @__PURE__ */ new Map()
|
|
5595
|
+
);
|
|
5596
|
+
(0, import_react11.useLayoutEffect)(() => {
|
|
5597
|
+
if (!enableColumnFreeze || enableColumnResize) return;
|
|
5598
|
+
const element = scrollRef.current;
|
|
5599
|
+
if (!element) return;
|
|
5600
|
+
const next = /* @__PURE__ */ new Map();
|
|
5601
|
+
element.querySelectorAll("th[data-leaf-column-id]").forEach((th) => {
|
|
5602
|
+
const id = th.getAttribute("data-leaf-column-id");
|
|
5603
|
+
const width = th.getBoundingClientRect().width;
|
|
5604
|
+
if (id && width > 0) next.set(id, width);
|
|
5605
|
+
});
|
|
5606
|
+
setMeasuredWidths((previous) => {
|
|
5607
|
+
if (previous.size === next.size && [...next].every(([id, width]) => previous.get(id) === width)) {
|
|
5608
|
+
return previous;
|
|
5609
|
+
}
|
|
5610
|
+
return next;
|
|
5611
|
+
});
|
|
5612
|
+
});
|
|
4848
5613
|
const freezeOffsets = (0, import_react11.useMemo)(() => {
|
|
4849
5614
|
if (!enableColumnFreeze || enableColumnResize || !layoutWidths) {
|
|
4850
5615
|
return rowContextValue.columnFreeze.offsets;
|
|
4851
5616
|
}
|
|
4852
5617
|
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4853
5618
|
id: column.id,
|
|
4854
|
-
size: layoutWidths.get(column.id) ?? column.getSize(),
|
|
5619
|
+
size: measuredWidths.get(column.id) ?? layoutWidths.get(column.id) ?? column.getSize(),
|
|
4855
5620
|
side: resolveColumnFreezeSide(column.columnDef.meta?.frozen)
|
|
4856
5621
|
}));
|
|
4857
5622
|
return buildColumnFreezeOffsets(columns);
|
|
@@ -4859,6 +5624,7 @@ function DataTable({
|
|
|
4859
5624
|
enableColumnFreeze,
|
|
4860
5625
|
enableColumnResize,
|
|
4861
5626
|
layoutWidths,
|
|
5627
|
+
measuredWidths,
|
|
4862
5628
|
rowContextValue.columnFreeze.offsets,
|
|
4863
5629
|
table
|
|
4864
5630
|
]);
|
|
@@ -4891,6 +5657,10 @@ function DataTable({
|
|
|
4891
5657
|
"div",
|
|
4892
5658
|
{
|
|
4893
5659
|
ref: rootRef,
|
|
5660
|
+
tabIndex: enableCellSelection ? 0 : void 0,
|
|
5661
|
+
onFocus: enableCellSelection ? (event) => {
|
|
5662
|
+
if (event.target === event.currentTarget) handleRootFocus();
|
|
5663
|
+
} : void 0,
|
|
4894
5664
|
className: cn(
|
|
4895
5665
|
"DataTableJSX",
|
|
4896
5666
|
!enableCellSelection && "DataTableJSX--no-cell-selection",
|
|
@@ -4911,6 +5681,7 @@ function DataTable({
|
|
|
4911
5681
|
summary,
|
|
4912
5682
|
selectedCount,
|
|
4913
5683
|
selectionLabel,
|
|
5684
|
+
countLabel: labels.count,
|
|
4914
5685
|
toolbar,
|
|
4915
5686
|
classNames
|
|
4916
5687
|
}
|
|
@@ -4929,6 +5700,7 @@ function DataTable({
|
|
|
4929
5700
|
previousLabel: labels.searchPrevious,
|
|
4930
5701
|
nextLabel: labels.searchNext,
|
|
4931
5702
|
closeLabel: labels.searchClose,
|
|
5703
|
+
formatResult: labels.searchResultCount,
|
|
4932
5704
|
rowsTotal: inlineSearch.searchRowCount,
|
|
4933
5705
|
classNames,
|
|
4934
5706
|
onSearchValueChange: inlineSearch.setSearchValue,
|
|
@@ -4978,6 +5750,8 @@ function DataTable({
|
|
|
4978
5750
|
(leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
|
|
4979
5751
|
);
|
|
4980
5752
|
const isDragging = draggingColumnId === header.column.id;
|
|
5753
|
+
const sortDirection = isPlaceholder ? void 0 : header.column.columnDef.meta?.sortDirection;
|
|
5754
|
+
const ariaSort = sortDirection === void 0 ? void 0 : sortDirection === "asc" ? "ascending" : sortDirection === "desc" ? "descending" : "none";
|
|
4981
5755
|
const dropEdge = !isPlaceholder && dropTarget?.columnId === header.column.id ? dropTarget.edge : void 0;
|
|
4982
5756
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
4983
5757
|
"th",
|
|
@@ -4993,7 +5767,8 @@ function DataTable({
|
|
|
4993
5767
|
"data-resizing": header.column.getIsResizing() ? "" : void 0,
|
|
4994
5768
|
"data-frozen": freezeOffset?.side,
|
|
4995
5769
|
"data-freeze-edge": getColumnFreezeEdgeAttr(freezeOffset),
|
|
4996
|
-
"
|
|
5770
|
+
"data-leaf-column-id": isLeafHeader ? header.column.id : void 0,
|
|
5771
|
+
"aria-sort": ariaSort,
|
|
4997
5772
|
title: canDrag ? labels.reorderColumn : void 0,
|
|
4998
5773
|
onPointerDown: enableColumnReorder ? (event) => onHeaderPointerDown(event, {
|
|
4999
5774
|
columnId: header.column.id,
|
|
@@ -5020,7 +5795,31 @@ function DataTable({
|
|
|
5020
5795
|
role: "separator",
|
|
5021
5796
|
"aria-orientation": "vertical",
|
|
5022
5797
|
"aria-label": labels.resizeColumn,
|
|
5798
|
+
"aria-valuenow": header.getSize(),
|
|
5799
|
+
tabIndex: 0,
|
|
5023
5800
|
"data-table-disable-cell-selection": "",
|
|
5801
|
+
onKeyDown: (event) => {
|
|
5802
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") {
|
|
5803
|
+
return;
|
|
5804
|
+
}
|
|
5805
|
+
event.preventDefault();
|
|
5806
|
+
event.stopPropagation();
|
|
5807
|
+
const step = event.shiftKey ? 50 : 10;
|
|
5808
|
+
const columnDef = header.column.columnDef;
|
|
5809
|
+
const min = columnDef.minSize ?? DATA_TABLE_COLUMN_MIN_SIZE;
|
|
5810
|
+
const max = columnDef.maxSize ?? DATA_TABLE_COLUMN_MAX_SIZE;
|
|
5811
|
+
const nextSize = Math.min(
|
|
5812
|
+
max,
|
|
5813
|
+
Math.max(
|
|
5814
|
+
min,
|
|
5815
|
+
header.getSize() + (event.key === "ArrowRight" ? step : -step)
|
|
5816
|
+
)
|
|
5817
|
+
);
|
|
5818
|
+
table.setColumnSizing((previous) => ({
|
|
5819
|
+
...previous,
|
|
5820
|
+
[header.column.id]: nextSize
|
|
5821
|
+
}));
|
|
5822
|
+
},
|
|
5024
5823
|
className: cn(
|
|
5025
5824
|
"data-table-resize-handle",
|
|
5026
5825
|
classNames?.resizeHandle
|
|
@@ -5128,16 +5927,21 @@ function DataTable({
|
|
|
5128
5927
|
}
|
|
5129
5928
|
|
|
5130
5929
|
// src/components/ui/table/components/Table/Table.tsx
|
|
5131
|
-
var
|
|
5930
|
+
var import_react15 = require("react");
|
|
5132
5931
|
|
|
5133
5932
|
// src/components/ui/table/components/Table/buildColumnDef.tsx
|
|
5933
|
+
var import_react12 = require("react");
|
|
5134
5934
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
5935
|
+
var TableSortContext = (0, import_react12.createContext)(null);
|
|
5135
5936
|
function SortableHeader({
|
|
5136
5937
|
label,
|
|
5137
5938
|
field,
|
|
5138
|
-
sort,
|
|
5139
|
-
onSort
|
|
5939
|
+
sort: sortProp,
|
|
5940
|
+
onSort: onSortProp
|
|
5140
5941
|
}) {
|
|
5942
|
+
const context = (0, import_react12.use)(TableSortContext);
|
|
5943
|
+
const sort = context ? context.sort : sortProp;
|
|
5944
|
+
const onSort = context ? context.onSort : onSortProp;
|
|
5141
5945
|
const isActive = sort?.field === field;
|
|
5142
5946
|
const Icon = isActive ? sort.direction === "asc" ? ArrowUp : ArrowDown : ArrowUpDown;
|
|
5143
5947
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
@@ -5156,7 +5960,7 @@ function SortableHeader({
|
|
|
5156
5960
|
}
|
|
5157
5961
|
);
|
|
5158
5962
|
}
|
|
5159
|
-
function buildColumnDef(props, sort, onSort) {
|
|
5963
|
+
function buildColumnDef(props, sort, onSort, headerCache) {
|
|
5160
5964
|
const {
|
|
5161
5965
|
field,
|
|
5162
5966
|
virtual = false,
|
|
@@ -5182,8 +5986,29 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5182
5986
|
className,
|
|
5183
5987
|
headerClassName,
|
|
5184
5988
|
render,
|
|
5185
|
-
copyValue
|
|
5989
|
+
copyValue,
|
|
5990
|
+
searchValue
|
|
5186
5991
|
} = props;
|
|
5992
|
+
const createHeader = () => sortable ? () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
5993
|
+
SortableHeader,
|
|
5994
|
+
{
|
|
5995
|
+
label: children,
|
|
5996
|
+
field,
|
|
5997
|
+
sort,
|
|
5998
|
+
onSort
|
|
5999
|
+
}
|
|
6000
|
+
) : (
|
|
6001
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
6002
|
+
() => children
|
|
6003
|
+
);
|
|
6004
|
+
const cached = headerCache?.get(field);
|
|
6005
|
+
let header;
|
|
6006
|
+
if (cached && cached.label === children && cached.sortable === sortable) {
|
|
6007
|
+
header = cached.render;
|
|
6008
|
+
} else {
|
|
6009
|
+
header = createHeader();
|
|
6010
|
+
headerCache?.set(field, { label: children, sortable, render: header });
|
|
6011
|
+
}
|
|
5187
6012
|
return {
|
|
5188
6013
|
id: field,
|
|
5189
6014
|
...!virtual ? { accessorKey: field } : {},
|
|
@@ -5191,18 +6016,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5191
6016
|
...minResizeWidth != null ? { minSize: minResizeWidth } : {},
|
|
5192
6017
|
...maxResizeWidth != null ? { maxSize: maxResizeWidth } : {},
|
|
5193
6018
|
...resizable === false ? { enableResizing: false } : {},
|
|
5194
|
-
header
|
|
5195
|
-
SortableHeader,
|
|
5196
|
-
{
|
|
5197
|
-
label: children,
|
|
5198
|
-
field,
|
|
5199
|
-
sort,
|
|
5200
|
-
onSort
|
|
5201
|
-
}
|
|
5202
|
-
) : (
|
|
5203
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
5204
|
-
() => children
|
|
5205
|
-
),
|
|
6019
|
+
header,
|
|
5206
6020
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
5207
6021
|
cell: (info) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ResolvedTableCell, { info }),
|
|
5208
6022
|
meta: {
|
|
@@ -5217,6 +6031,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5217
6031
|
cellProps,
|
|
5218
6032
|
cellRender: render,
|
|
5219
6033
|
copyValue,
|
|
6034
|
+
searchValue,
|
|
6035
|
+
sortDirection: sortable ? sort?.field === field ? sort.direction : false : void 0,
|
|
5220
6036
|
frozen,
|
|
5221
6037
|
reorderable,
|
|
5222
6038
|
width,
|
|
@@ -5234,12 +6050,12 @@ function resolveGroupId(props, index) {
|
|
|
5234
6050
|
}
|
|
5235
6051
|
return `group:${index}`;
|
|
5236
6052
|
}
|
|
5237
|
-
function buildColumnDefsFromTree(nodes, sort, onSort) {
|
|
6053
|
+
function buildColumnDefsFromTree(nodes, sort, onSort, headerCache) {
|
|
5238
6054
|
return nodes.map((node, index) => {
|
|
5239
6055
|
if (node.type === "leaf") {
|
|
5240
|
-
return buildColumnDef(node.props, sort, onSort);
|
|
6056
|
+
return buildColumnDef(node.props, sort, onSort, headerCache);
|
|
5241
6057
|
}
|
|
5242
|
-
const childDefs = buildColumnDefsFromTree(node.columns, sort, onSort);
|
|
6058
|
+
const childDefs = buildColumnDefsFromTree(node.columns, sort, onSort, headerCache);
|
|
5243
6059
|
const { header, align, headerClassName } = node.props;
|
|
5244
6060
|
return {
|
|
5245
6061
|
id: resolveGroupId(node.props, index),
|
|
@@ -5267,10 +6083,10 @@ function countLeafColumns(nodes) {
|
|
|
5267
6083
|
}
|
|
5268
6084
|
|
|
5269
6085
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
5270
|
-
var
|
|
6086
|
+
var import_react14 = require("react");
|
|
5271
6087
|
|
|
5272
6088
|
// src/components/ui/table/components/Table/tableChildTypes.ts
|
|
5273
|
-
var
|
|
6089
|
+
var import_react13 = require("react");
|
|
5274
6090
|
var TABLE_HEADER_DISPLAY_NAME = "Table.Header";
|
|
5275
6091
|
var TABLE_BODY_DISPLAY_NAME = "Table.Body";
|
|
5276
6092
|
var TABLE_COLUMN_DISPLAY_NAME = "Table.Column";
|
|
@@ -5283,19 +6099,19 @@ function getComponentDisplayName(type) {
|
|
|
5283
6099
|
return void 0;
|
|
5284
6100
|
}
|
|
5285
6101
|
function isTableHeaderElement(child) {
|
|
5286
|
-
return (0,
|
|
6102
|
+
return (0, import_react13.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
|
|
5287
6103
|
}
|
|
5288
6104
|
function isTableBodyElement(child) {
|
|
5289
|
-
return (0,
|
|
6105
|
+
return (0, import_react13.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
|
|
5290
6106
|
}
|
|
5291
6107
|
function isTableColumnElement(child) {
|
|
5292
|
-
return (0,
|
|
6108
|
+
return (0, import_react13.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
|
|
5293
6109
|
}
|
|
5294
6110
|
function isTableColumnGroupElement(child) {
|
|
5295
|
-
return (0,
|
|
6111
|
+
return (0, import_react13.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_GROUP_DISPLAY_NAME;
|
|
5296
6112
|
}
|
|
5297
6113
|
function isTablePaginationElement(child) {
|
|
5298
|
-
return (0,
|
|
6114
|
+
return (0, import_react13.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
|
|
5299
6115
|
}
|
|
5300
6116
|
|
|
5301
6117
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
@@ -5305,7 +6121,7 @@ function parseTableChildren(children) {
|
|
|
5305
6121
|
body: null,
|
|
5306
6122
|
pagination: null
|
|
5307
6123
|
};
|
|
5308
|
-
for (const child of
|
|
6124
|
+
for (const child of import_react14.Children.toArray(children)) {
|
|
5309
6125
|
if (isTableHeaderElement(child)) {
|
|
5310
6126
|
slots.header = child;
|
|
5311
6127
|
continue;
|
|
@@ -5322,7 +6138,7 @@ function parseTableChildren(children) {
|
|
|
5322
6138
|
}
|
|
5323
6139
|
function walkColumnTreeNodes(children) {
|
|
5324
6140
|
const result = [];
|
|
5325
|
-
for (const child of
|
|
6141
|
+
for (const child of import_react14.Children.toArray(children)) {
|
|
5326
6142
|
if (isTableColumnElement(child)) {
|
|
5327
6143
|
result.push({
|
|
5328
6144
|
type: "leaf",
|
|
@@ -5339,7 +6155,7 @@ function walkColumnTreeNodes(children) {
|
|
|
5339
6155
|
});
|
|
5340
6156
|
continue;
|
|
5341
6157
|
}
|
|
5342
|
-
if ((0,
|
|
6158
|
+
if ((0, import_react14.isValidElement)(child)) {
|
|
5343
6159
|
const nested = child.props.children;
|
|
5344
6160
|
if (nested != null) {
|
|
5345
6161
|
result.push(...walkColumnTreeNodes(nested));
|
|
@@ -5375,13 +6191,22 @@ function TableColumnGroup(props) {
|
|
|
5375
6191
|
TableColumnGroup.displayName = TABLE_COLUMN_GROUP_DISPLAY_NAME;
|
|
5376
6192
|
|
|
5377
6193
|
// src/components/ui/table/components/Table/tableDataPipeline.ts
|
|
5378
|
-
function
|
|
6194
|
+
function readField(row, field) {
|
|
6195
|
+
if (field in row || !field.includes(".")) return row[field];
|
|
6196
|
+
return field.split(".").reduce((current, key) => {
|
|
6197
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
6198
|
+
return void 0;
|
|
6199
|
+
}
|
|
6200
|
+
return current[key];
|
|
6201
|
+
}, row);
|
|
6202
|
+
}
|
|
6203
|
+
function sortTableData(data, sort, locale = "ko") {
|
|
5379
6204
|
if (!sort) return data;
|
|
5380
6205
|
const { field, direction } = sort;
|
|
5381
6206
|
const multiplier = direction === "asc" ? 1 : -1;
|
|
5382
6207
|
return [...data].sort((left, right) => {
|
|
5383
|
-
const leftValue = left
|
|
5384
|
-
const rightValue = right
|
|
6208
|
+
const leftValue = readField(left, field);
|
|
6209
|
+
const rightValue = readField(right, field);
|
|
5385
6210
|
if ((leftValue === null || leftValue === void 0) && (rightValue === null || rightValue === void 0)) {
|
|
5386
6211
|
return 0;
|
|
5387
6212
|
}
|
|
@@ -5390,11 +6215,12 @@ function sortTableData(data, sort) {
|
|
|
5390
6215
|
if (typeof leftValue === "number" && typeof rightValue === "number") {
|
|
5391
6216
|
return (leftValue - rightValue) * multiplier;
|
|
5392
6217
|
}
|
|
5393
|
-
return String(leftValue).localeCompare(String(rightValue),
|
|
6218
|
+
return String(leftValue).localeCompare(String(rightValue), locale, { numeric: true }) * multiplier;
|
|
5394
6219
|
});
|
|
5395
6220
|
}
|
|
5396
6221
|
function paginateTableData(data, page, pageSize) {
|
|
5397
|
-
const
|
|
6222
|
+
const lastPage = getTotalPages(data.length, pageSize);
|
|
6223
|
+
const safePage = Math.min(Math.max(1, page), lastPage);
|
|
5398
6224
|
const start = (safePage - 1) * pageSize;
|
|
5399
6225
|
return data.slice(start, start + pageSize);
|
|
5400
6226
|
}
|
|
@@ -5402,6 +6228,36 @@ function getTotalPages(totalCount, pageSize) {
|
|
|
5402
6228
|
if (pageSize <= 0) return 1;
|
|
5403
6229
|
return Math.max(1, Math.ceil(totalCount / pageSize));
|
|
5404
6230
|
}
|
|
6231
|
+
function buildTreeRootBlocks(data, fields, sort, locale) {
|
|
6232
|
+
const childrenByRow = /* @__PURE__ */ new Map();
|
|
6233
|
+
const roots = [];
|
|
6234
|
+
const latestById = /* @__PURE__ */ new Map();
|
|
6235
|
+
for (const row of data) {
|
|
6236
|
+
const parentKey = row[fields.parentIdField];
|
|
6237
|
+
const parent = parentKey !== null && parentKey !== void 0 && parentKey !== "" ? latestById.get(parentKey) : void 0;
|
|
6238
|
+
if (parent) {
|
|
6239
|
+
const siblings = childrenByRow.get(parent);
|
|
6240
|
+
if (siblings) siblings.push(row);
|
|
6241
|
+
else childrenByRow.set(parent, [row]);
|
|
6242
|
+
} else {
|
|
6243
|
+
roots.push(row);
|
|
6244
|
+
}
|
|
6245
|
+
latestById.set(row[fields.idField], row);
|
|
6246
|
+
}
|
|
6247
|
+
const appendSubtree = (row, out) => {
|
|
6248
|
+
out.push(row);
|
|
6249
|
+
const children = childrenByRow.get(row);
|
|
6250
|
+
if (!children) return;
|
|
6251
|
+
for (const child of sortTableData(children, sort, locale)) {
|
|
6252
|
+
appendSubtree(child, out);
|
|
6253
|
+
}
|
|
6254
|
+
};
|
|
6255
|
+
return sortTableData(roots, sort, locale).map((root) => {
|
|
6256
|
+
const block = [];
|
|
6257
|
+
appendSubtree(root, block);
|
|
6258
|
+
return block;
|
|
6259
|
+
});
|
|
6260
|
+
}
|
|
5405
6261
|
|
|
5406
6262
|
// src/components/ui/table/components/Table/TableHeader.tsx
|
|
5407
6263
|
function TableHeader(props) {
|
|
@@ -5417,7 +6273,9 @@ function TablePagination({
|
|
|
5417
6273
|
pageSize = 10,
|
|
5418
6274
|
totalCount = 0,
|
|
5419
6275
|
onChange,
|
|
5420
|
-
className
|
|
6276
|
+
className,
|
|
6277
|
+
previousLabel = "Previous page",
|
|
6278
|
+
nextLabel = "Next page"
|
|
5421
6279
|
}) {
|
|
5422
6280
|
const totalPages = getTotalPages(totalCount, pageSize);
|
|
5423
6281
|
const safePage = Math.min(Math.max(1, page), totalPages);
|
|
@@ -5431,7 +6289,7 @@ function TablePagination({
|
|
|
5431
6289
|
className: "pagination-button",
|
|
5432
6290
|
disabled: !canGoPrev,
|
|
5433
6291
|
onClick: () => onChange(safePage - 1),
|
|
5434
|
-
"aria-label":
|
|
6292
|
+
"aria-label": previousLabel,
|
|
5435
6293
|
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ChevronLeft, { className: "pagination-button-icon" })
|
|
5436
6294
|
}
|
|
5437
6295
|
),
|
|
@@ -5447,7 +6305,7 @@ function TablePagination({
|
|
|
5447
6305
|
className: "pagination-button",
|
|
5448
6306
|
disabled: !canGoNext,
|
|
5449
6307
|
onClick: () => onChange(safePage + 1),
|
|
5450
|
-
"aria-label":
|
|
6308
|
+
"aria-label": nextLabel,
|
|
5451
6309
|
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ChevronRight, { className: "pagination-button-icon" })
|
|
5452
6310
|
}
|
|
5453
6311
|
)
|
|
@@ -5461,63 +6319,124 @@ function TableRoot({
|
|
|
5461
6319
|
data,
|
|
5462
6320
|
children,
|
|
5463
6321
|
className,
|
|
6322
|
+
classNames,
|
|
5464
6323
|
totalCount,
|
|
5465
6324
|
filteredCount,
|
|
6325
|
+
onDataChange,
|
|
6326
|
+
getRowId,
|
|
6327
|
+
sort: controlledSort,
|
|
6328
|
+
defaultSort = null,
|
|
6329
|
+
onSortChange,
|
|
6330
|
+
sortLocale,
|
|
5466
6331
|
...dataTableProps
|
|
5467
6332
|
}) {
|
|
5468
|
-
const { header, pagination: paginationElement } = (0,
|
|
6333
|
+
const { header, pagination: paginationElement } = (0, import_react15.useMemo)(
|
|
5469
6334
|
() => parseTableChildren(children),
|
|
5470
6335
|
[children]
|
|
5471
6336
|
);
|
|
5472
|
-
const [
|
|
5473
|
-
const
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
6337
|
+
const [internalSort, setInternalSort] = (0, import_react15.useState)(defaultSort);
|
|
6338
|
+
const sort = controlledSort !== void 0 ? controlledSort : internalSort;
|
|
6339
|
+
const handleSort = (0, import_react15.useCallback)(
|
|
6340
|
+
(field) => {
|
|
6341
|
+
let next;
|
|
6342
|
+
if (sort?.field !== field) {
|
|
6343
|
+
next = { field, direction: "asc" };
|
|
6344
|
+
} else if (sort.direction === "asc") {
|
|
6345
|
+
next = { field, direction: "desc" };
|
|
6346
|
+
} else {
|
|
6347
|
+
next = null;
|
|
5480
6348
|
}
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
6349
|
+
if (controlledSort === void 0) setInternalSort(next);
|
|
6350
|
+
onSortChange?.(next);
|
|
6351
|
+
},
|
|
6352
|
+
[controlledSort, onSortChange, sort]
|
|
6353
|
+
);
|
|
6354
|
+
const columnTree = (0, import_react15.useMemo)(() => extractColumnTree(header), [header]);
|
|
6355
|
+
const headerCacheRef = (0, import_react15.useRef)(/* @__PURE__ */ new Map());
|
|
6356
|
+
const columns = (0, import_react15.useMemo)(
|
|
6357
|
+
() => buildColumnDefsFromTree(columnTree, sort, handleSort, headerCacheRef.current),
|
|
5487
6358
|
[columnTree, sort, handleSort]
|
|
5488
6359
|
);
|
|
6360
|
+
const sortContextValue = (0, import_react15.useMemo)(() => ({ sort, onSort: handleSort }), [sort, handleSort]);
|
|
5489
6361
|
const paginationProps = paginationElement?.props;
|
|
5490
6362
|
const pageSize = paginationProps?.pageSize ?? 10;
|
|
5491
6363
|
const page = paginationProps?.page ?? 1;
|
|
5492
6364
|
const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
|
|
5493
|
-
const
|
|
5494
|
-
|
|
5495
|
-
|
|
6365
|
+
const isManualPagination = Boolean(paginationProps?.manual);
|
|
6366
|
+
const treeIdField = dataTableProps.toggleField ?? dataTableProps.idField;
|
|
6367
|
+
const isTree = Boolean(treeIdField);
|
|
6368
|
+
const treeParentIdField = dataTableProps.childField ?? dataTableProps.parentIdField ?? DEFAULT_TREE_PARENT_ID_FIELD;
|
|
6369
|
+
const treeBlocks = (0, import_react15.useMemo)(() => {
|
|
6370
|
+
if (!isTree || !treeIdField) return null;
|
|
6371
|
+
if (!sort && (!paginationProps || isManualPagination)) return null;
|
|
6372
|
+
return buildTreeRootBlocks(
|
|
6373
|
+
data,
|
|
6374
|
+
{ idField: treeIdField, parentIdField: treeParentIdField },
|
|
6375
|
+
sort,
|
|
6376
|
+
sortLocale
|
|
6377
|
+
);
|
|
6378
|
+
}, [data, isManualPagination, isTree, paginationProps, sort, sortLocale, treeIdField, treeParentIdField]);
|
|
6379
|
+
const pageTotalCount = paginationProps?.totalCount ?? totalCount ?? (treeBlocks ? treeBlocks.length : data.length);
|
|
6380
|
+
const tableData = (0, import_react15.useMemo)(() => {
|
|
6381
|
+
if (treeBlocks) {
|
|
6382
|
+
const blocks = !paginationProps || isManualPagination ? treeBlocks : paginateTableData(treeBlocks, page, pageSize);
|
|
6383
|
+
return blocks.flat();
|
|
6384
|
+
}
|
|
6385
|
+
const sortedData = sortTableData(data, sort, sortLocale);
|
|
6386
|
+
if (!paginationProps || isManualPagination) return sortedData;
|
|
5496
6387
|
return paginateTableData(sortedData, page, pageSize);
|
|
5497
|
-
}, [data, sort, paginationProps, page, pageSize]);
|
|
6388
|
+
}, [treeBlocks, data, sort, sortLocale, paginationProps, isManualPagination, page, pageSize]);
|
|
6389
|
+
const originalIndexByRow = (0, import_react15.useMemo)(() => {
|
|
6390
|
+
const map = /* @__PURE__ */ new Map();
|
|
6391
|
+
data.forEach((row, index) => map.set(row, index));
|
|
6392
|
+
return map;
|
|
6393
|
+
}, [data]);
|
|
6394
|
+
const resolvedGetRowId = (0, import_react15.useMemo)(() => {
|
|
6395
|
+
if (getRowId) return getRowId;
|
|
6396
|
+
if (isTree) return void 0;
|
|
6397
|
+
return (row, index) => String(originalIndexByRow.get(row) ?? index);
|
|
6398
|
+
}, [isTree, getRowId, originalIndexByRow]);
|
|
6399
|
+
const handleDataChange = (0, import_react15.useMemo)(() => {
|
|
6400
|
+
if (!onDataChange) return void 0;
|
|
6401
|
+
return (next) => {
|
|
6402
|
+
const merged = data.slice();
|
|
6403
|
+
tableData.forEach((row, index) => {
|
|
6404
|
+
const nextRow = next[index];
|
|
6405
|
+
if (nextRow === void 0 || nextRow === row) return;
|
|
6406
|
+
const originalIndex = originalIndexByRow.get(row);
|
|
6407
|
+
if (originalIndex !== void 0) merged[originalIndex] = nextRow;
|
|
6408
|
+
});
|
|
6409
|
+
onDataChange(merged);
|
|
6410
|
+
};
|
|
6411
|
+
}, [data, onDataChange, originalIndexByRow, tableData]);
|
|
5498
6412
|
if (countLeafColumns(columnTree) === 0) {
|
|
5499
6413
|
console.warn("[Table] Declare at least one Table.Column inside Table.Header.");
|
|
5500
6414
|
}
|
|
5501
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "TableJSX", children: [
|
|
5502
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
6415
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: cn("TableJSX", classNames?.tableRoot), children: [
|
|
6416
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TableSortContext, { value: sortContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
5503
6417
|
DataTable,
|
|
5504
6418
|
{
|
|
5505
6419
|
...dataTableProps,
|
|
6420
|
+
classNames,
|
|
6421
|
+
getRowId: resolvedGetRowId,
|
|
6422
|
+
onDataChange: handleDataChange,
|
|
5506
6423
|
data: tableData,
|
|
5507
6424
|
columns,
|
|
5508
6425
|
totalCount: paginationProps ? resolvedTotalCount : totalCount,
|
|
5509
6426
|
filteredCount: filteredCount ?? data.length,
|
|
5510
6427
|
className: cn(className, paginationProps && "DataTableJSX--with-pagination")
|
|
5511
6428
|
}
|
|
5512
|
-
),
|
|
6429
|
+
) }),
|
|
5513
6430
|
paginationProps && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
5514
6431
|
TablePagination,
|
|
5515
6432
|
{
|
|
5516
6433
|
page,
|
|
5517
6434
|
pageSize,
|
|
5518
|
-
totalCount:
|
|
6435
|
+
totalCount: pageTotalCount,
|
|
5519
6436
|
onChange: paginationProps.onChange,
|
|
5520
|
-
className: paginationProps.className
|
|
6437
|
+
className: cn(classNames?.pagination, paginationProps.className),
|
|
6438
|
+
previousLabel: paginationProps.previousLabel ?? dataTableProps.labels?.paginationPrevious,
|
|
6439
|
+
nextLabel: paginationProps.nextLabel ?? dataTableProps.labels?.paginationNext
|
|
5521
6440
|
}
|
|
5522
6441
|
)
|
|
5523
6442
|
] });
|
|
@@ -5591,6 +6510,7 @@ var Table = Object.assign(TableRoot, {
|
|
|
5591
6510
|
createSearchRegex,
|
|
5592
6511
|
createTable,
|
|
5593
6512
|
escapeSearchRegex,
|
|
6513
|
+
escapeSpreadsheetFormula,
|
|
5594
6514
|
flattenSubtreeRows,
|
|
5595
6515
|
formatCellValue,
|
|
5596
6516
|
formatDefaultCellValue,
|