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/compound.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
// src/components/ui/table/components/DataTable/DataTable.tsx
|
|
2
2
|
import { flexRender as flexRender2 } from "@tanstack/react-table";
|
|
3
|
-
import { useEffect as useEffect8, useMemo as
|
|
3
|
+
import { useEffect as useEffect8, useLayoutEffect, useMemo as useMemo6, useState as useState6 } from "react";
|
|
4
4
|
|
|
5
5
|
// src/components/ui/table/components/DataTable/DataTableRow.tsx
|
|
6
6
|
import { flexRender } from "@tanstack/react-table";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
useEffect as useEffect2,
|
|
9
|
+
useRef as useRef2,
|
|
10
|
+
useSyncExternalStore
|
|
11
|
+
} from "react";
|
|
8
12
|
|
|
9
13
|
// src/components/ui/table/constants.ts
|
|
10
14
|
var CELL_ALIGN_CLASS = {
|
|
@@ -43,6 +47,61 @@ function DataTableContextProvider({
|
|
|
43
47
|
return /* @__PURE__ */ jsx(DataTableContext, { value, children });
|
|
44
48
|
}
|
|
45
49
|
|
|
50
|
+
// src/components/ui/table/features/data-patch/dataPatch.ts
|
|
51
|
+
var TREE_SOURCE = /* @__PURE__ */ Symbol("react-glide-table.treeSource");
|
|
52
|
+
function getTreeSource(row) {
|
|
53
|
+
if (!row || typeof row !== "object") return void 0;
|
|
54
|
+
return row[TREE_SOURCE];
|
|
55
|
+
}
|
|
56
|
+
function getTreeRowKey(row) {
|
|
57
|
+
const source = getTreeSource(row);
|
|
58
|
+
if (!source) return void 0;
|
|
59
|
+
return `tree:${source.path.join(".")}`;
|
|
60
|
+
}
|
|
61
|
+
function setValueAtAccessor(record, accessorKey, value) {
|
|
62
|
+
if (!accessorKey.includes(".") || accessorKey in record) {
|
|
63
|
+
return { ...record, [accessorKey]: value };
|
|
64
|
+
}
|
|
65
|
+
const [head, ...rest] = accessorKey.split(".");
|
|
66
|
+
const current = record[head];
|
|
67
|
+
const child = current && typeof current === "object" && !Array.isArray(current) ? current : {};
|
|
68
|
+
return {
|
|
69
|
+
...record,
|
|
70
|
+
[head]: setValueAtAccessor(child, rest.join("."), value)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function patchAtPath(nodes, path, childrenField, accessorKey, value) {
|
|
74
|
+
const [head, ...rest] = path;
|
|
75
|
+
if (head === void 0 || head < 0 || head >= nodes.length) return null;
|
|
76
|
+
const node = nodes[head];
|
|
77
|
+
if (!node || typeof node !== "object") return null;
|
|
78
|
+
const record = node;
|
|
79
|
+
let nextNode;
|
|
80
|
+
if (rest.length === 0) {
|
|
81
|
+
nextNode = setValueAtAccessor(record, accessorKey, value);
|
|
82
|
+
} else {
|
|
83
|
+
const children = record[childrenField];
|
|
84
|
+
if (!Array.isArray(children)) return null;
|
|
85
|
+
const nextChildren = patchAtPath(children, rest, childrenField, accessorKey, value);
|
|
86
|
+
if (!nextChildren) return null;
|
|
87
|
+
nextNode = { ...record, [childrenField]: nextChildren };
|
|
88
|
+
}
|
|
89
|
+
const next = nodes.slice();
|
|
90
|
+
next[head] = nextNode;
|
|
91
|
+
return next;
|
|
92
|
+
}
|
|
93
|
+
function applyCellChangesToData(data, changes) {
|
|
94
|
+
let next = data;
|
|
95
|
+
for (const change of changes) {
|
|
96
|
+
const source = getTreeSource(change.original);
|
|
97
|
+
const path = source ? source.path : [change.index];
|
|
98
|
+
const childrenField = source?.childrenField ?? "";
|
|
99
|
+
const patched = patchAtPath(next, path, childrenField, change.accessorKey, change.value);
|
|
100
|
+
if (patched) next = patched;
|
|
101
|
+
}
|
|
102
|
+
return next === data ? data.slice() : next;
|
|
103
|
+
}
|
|
104
|
+
|
|
46
105
|
// src/components/ui/table/features/cell-edit/cellEdit.ts
|
|
47
106
|
function getColumnAccessorKey(columnDef) {
|
|
48
107
|
if (columnDef.accessorKey !== void 0 && columnDef.accessorKey !== null) {
|
|
@@ -50,7 +109,11 @@ function getColumnAccessorKey(columnDef) {
|
|
|
50
109
|
}
|
|
51
110
|
return columnDef.id;
|
|
52
111
|
}
|
|
112
|
+
function isProtectedColumn(columnDef) {
|
|
113
|
+
return columnDef.meta?.kind === "protected";
|
|
114
|
+
}
|
|
53
115
|
function isColumnEditable(columnDef) {
|
|
116
|
+
if (isProtectedColumn(columnDef)) return false;
|
|
54
117
|
return Boolean(columnDef.meta?.editable);
|
|
55
118
|
}
|
|
56
119
|
function getColumnEditType(columnDef) {
|
|
@@ -175,9 +238,22 @@ function isCellInSelection(rowIndex, colIndex, bounds, rowSpan = 1) {
|
|
|
175
238
|
const cellEndRow = rowIndex + rowSpan - 1;
|
|
176
239
|
return cellEndRow >= bounds.startRow && rowIndex <= bounds.endRow && colIndex >= bounds.startCol && colIndex <= bounds.endCol;
|
|
177
240
|
}
|
|
241
|
+
function resolveFillBounds(source, pointer) {
|
|
242
|
+
const below = pointer.row - source.endRow;
|
|
243
|
+
const above = source.startRow - pointer.row;
|
|
244
|
+
const right = pointer.col - source.endCol;
|
|
245
|
+
const left = source.startCol - pointer.col;
|
|
246
|
+
const vertical = Math.max(below, above, 0);
|
|
247
|
+
const horizontal = Math.max(right, left, 0);
|
|
248
|
+
if (vertical === 0 && horizontal === 0) return { ...source };
|
|
249
|
+
if (vertical >= horizontal) {
|
|
250
|
+
return below > 0 ? { ...source, endRow: pointer.row } : { ...source, startRow: pointer.row };
|
|
251
|
+
}
|
|
252
|
+
return right > 0 ? { ...source, endCol: pointer.col } : { ...source, startCol: pointer.col };
|
|
253
|
+
}
|
|
178
254
|
function getActiveSelectionBounds(dragState, selectionBounds) {
|
|
179
|
-
if (dragState.isFillDragging && dragState.
|
|
180
|
-
return
|
|
255
|
+
if (dragState.isFillDragging && dragState.fillEnd && selectionBounds) {
|
|
256
|
+
return resolveFillBounds(selectionBounds, dragState.fillEnd);
|
|
181
257
|
}
|
|
182
258
|
return selectionBounds;
|
|
183
259
|
}
|
|
@@ -753,7 +829,8 @@ function buildTreeSearchCorpus(visibleRows, options) {
|
|
|
753
829
|
const children = node.children;
|
|
754
830
|
if (!Array.isArray(children) || children.length === 0) return;
|
|
755
831
|
const toggleValue = node[toggleField];
|
|
756
|
-
const
|
|
832
|
+
const toggleKey = toggleValue === null || toggleValue === void 0 ? "" : String(toggleValue);
|
|
833
|
+
const childAncestors = toggleKey.length > 0 ? [...ancestorToggleKeys, toggleKey] : ancestorToggleKeys;
|
|
757
834
|
for (const child of children) {
|
|
758
835
|
if (child && typeof child === "object") {
|
|
759
836
|
walk(child, childAncestors);
|
|
@@ -811,8 +888,12 @@ function getFieldValue(row, key) {
|
|
|
811
888
|
}
|
|
812
889
|
function canExpandRow(row) {
|
|
813
890
|
const children = row.children;
|
|
814
|
-
|
|
815
|
-
|
|
891
|
+
return Array.isArray(children) && children.length > 0;
|
|
892
|
+
}
|
|
893
|
+
function toTreeToggleKey(value) {
|
|
894
|
+
if (value === null || value === void 0) return null;
|
|
895
|
+
const key = String(value);
|
|
896
|
+
return key.length > 0 ? key : null;
|
|
816
897
|
}
|
|
817
898
|
function toggleExpandedRowId(rowId, previous) {
|
|
818
899
|
const next = new Set(previous);
|
|
@@ -833,7 +914,8 @@ var useConvertTreeData = ({
|
|
|
833
914
|
preventExpand = false,
|
|
834
915
|
startIndex = 1,
|
|
835
916
|
expandedRows,
|
|
836
|
-
onExpandedRowsChange
|
|
917
|
+
onExpandedRowsChange,
|
|
918
|
+
autoExpandOnLoad = true
|
|
837
919
|
}) => {
|
|
838
920
|
const onExpandedRowsChangeRef = useRef(onExpandedRowsChange);
|
|
839
921
|
const hasInitializedRef = useRef(false);
|
|
@@ -846,16 +928,33 @@ var useConvertTreeData = ({
|
|
|
846
928
|
return;
|
|
847
929
|
}
|
|
848
930
|
if (!enabled || hasInitializedRef.current) return;
|
|
849
|
-
const ids = data.map((item) => getFieldValue(item, toggleField)).filter((value) => typeof value === "string" && value.length > 0);
|
|
850
|
-
onExpandedRowsChangeRef.current?.(new Set(ids));
|
|
851
931
|
hasInitializedRef.current = true;
|
|
852
|
-
|
|
932
|
+
if (!autoExpandOnLoad) return;
|
|
933
|
+
const ids = /* @__PURE__ */ new Set();
|
|
934
|
+
const collect = (items) => {
|
|
935
|
+
for (const item of items) {
|
|
936
|
+
if (!item || typeof item !== "object") continue;
|
|
937
|
+
const record = item;
|
|
938
|
+
const key = toTreeToggleKey(getFieldValue(record, toggleField));
|
|
939
|
+
if (key) ids.add(key);
|
|
940
|
+
const nested = record[flattenField];
|
|
941
|
+
if (Array.isArray(nested)) collect(nested);
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
collect(data);
|
|
945
|
+
onExpandedRowsChangeRef.current?.(ids);
|
|
946
|
+
}, [enabled, data, toggleField, flattenField, autoExpandOnLoad]);
|
|
853
947
|
const processedData = useMemo(() => {
|
|
854
948
|
if (!enabled || !data || data.length === 0) return [];
|
|
855
949
|
const flattenedData = [];
|
|
856
|
-
const flattenItems = (items) => {
|
|
857
|
-
items.forEach((item) => {
|
|
858
|
-
|
|
950
|
+
const flattenItems = (items, parentPath) => {
|
|
951
|
+
items.forEach((item, itemIndex) => {
|
|
952
|
+
if (!item || typeof item !== "object") return;
|
|
953
|
+
const source = {
|
|
954
|
+
path: [...parentPath, itemIndex],
|
|
955
|
+
childrenField: flattenField
|
|
956
|
+
};
|
|
957
|
+
const newItem = { ...item, [TREE_SOURCE]: source };
|
|
859
958
|
const nested = newItem[flattenField];
|
|
860
959
|
if (Array.isArray(nested)) {
|
|
861
960
|
const children = nested.map(
|
|
@@ -869,89 +968,68 @@ var useConvertTreeData = ({
|
|
|
869
968
|
child[childField] = newItem[toggleField];
|
|
870
969
|
}
|
|
871
970
|
});
|
|
872
|
-
flattenItems(children);
|
|
971
|
+
flattenItems(children, source.path);
|
|
873
972
|
} else {
|
|
874
973
|
flattenedData.push(newItem);
|
|
875
974
|
}
|
|
876
975
|
});
|
|
877
976
|
};
|
|
878
|
-
flattenItems(data);
|
|
977
|
+
flattenItems(data, []);
|
|
879
978
|
const dataWithLevels = flattenedData.map((item) => ({
|
|
880
979
|
...item,
|
|
881
980
|
level: 0,
|
|
882
981
|
children: [],
|
|
883
982
|
processed: false
|
|
884
983
|
}));
|
|
885
|
-
const findNearestPrecedingParent = (index, parentKey) => {
|
|
886
|
-
for (let i = index - 1; i >= 0; i -= 1) {
|
|
887
|
-
const candidate = dataWithLevels[i];
|
|
888
|
-
if (!candidate) continue;
|
|
889
|
-
if (getFieldValue(candidate, toggleField) === parentKey) {
|
|
890
|
-
return candidate;
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
return void 0;
|
|
894
|
-
};
|
|
895
984
|
const rootItems = [];
|
|
985
|
+
const latestByKey = /* @__PURE__ */ new Map();
|
|
896
986
|
dataWithLevels.forEach((item) => {
|
|
897
|
-
if (!getFieldValue(item, childField)) {
|
|
898
|
-
rootItems.push(item);
|
|
899
|
-
item.processed = true;
|
|
900
|
-
}
|
|
901
|
-
});
|
|
902
|
-
dataWithLevels.forEach((item, index) => {
|
|
903
987
|
const parentKey = getFieldValue(item, childField);
|
|
904
|
-
|
|
905
|
-
const parent = findNearestPrecedingParent(index, parentKey);
|
|
988
|
+
const parent = parentKey ? latestByKey.get(parentKey) : void 0;
|
|
906
989
|
if (parent) {
|
|
907
990
|
item.level = parent.level + 1;
|
|
908
991
|
parent.children.push(item);
|
|
909
|
-
|
|
910
|
-
|
|
992
|
+
} else {
|
|
993
|
+
rootItems.push(item);
|
|
911
994
|
}
|
|
912
|
-
rootItems.push(item);
|
|
913
995
|
item.processed = true;
|
|
996
|
+
latestByKey.set(getFieldValue(item, toggleField), item);
|
|
914
997
|
});
|
|
915
998
|
return rootItems;
|
|
916
999
|
}, [enabled, data, toggleField, childField, flattenField]);
|
|
917
1000
|
const flattenTree = useMemo(() => {
|
|
918
1001
|
if (!enabled) return [];
|
|
919
|
-
const flatten = (nodes, result
|
|
1002
|
+
const flatten = (nodes, result, parentTreeNo) => {
|
|
920
1003
|
nodes.forEach((node, index) => {
|
|
921
|
-
const currentIndex =
|
|
1004
|
+
const currentIndex = parentTreeNo === null ? `${index + startIndex}` : `${parentTreeNo}-${index + 1}`;
|
|
922
1005
|
const toggleValue = getFieldValue(node, toggleField);
|
|
923
|
-
const uniqueId = `${
|
|
1006
|
+
const uniqueId = `${currentIndex}-${String(toggleValue ?? "")}`;
|
|
924
1007
|
result.push({
|
|
925
1008
|
...node,
|
|
926
1009
|
treeNo: currentIndex,
|
|
927
1010
|
uniqueId,
|
|
928
1011
|
processed: true
|
|
929
1012
|
});
|
|
930
|
-
const
|
|
1013
|
+
const toggleKey = toTreeToggleKey(toggleValue);
|
|
1014
|
+
const shouldExpandChildren = node.children.length > 0 && (preventExpand || toggleKey !== null && Boolean(expandedRows?.has(toggleKey)));
|
|
931
1015
|
if (shouldExpandChildren) {
|
|
932
|
-
flatten(node.children, result,
|
|
1016
|
+
flatten(node.children, result, currentIndex);
|
|
933
1017
|
}
|
|
934
1018
|
});
|
|
935
1019
|
return result;
|
|
936
1020
|
};
|
|
937
|
-
const flattenedData = flatten(processedData, [],
|
|
938
|
-
|
|
1021
|
+
const flattenedData = flatten(processedData, [], null);
|
|
1022
|
+
const latestByKey = /* @__PURE__ */ new Map();
|
|
1023
|
+
flattenedData.forEach((item) => {
|
|
939
1024
|
const parentKey = getFieldValue(item, childField);
|
|
940
1025
|
if (!parentKey) {
|
|
941
1026
|
item.parentCount = 1;
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
const candidate = flattenedData[i];
|
|
947
|
-
if (!candidate) continue;
|
|
948
|
-
if (getFieldValue(candidate, toggleField) === parentKey) {
|
|
949
|
-
parentItem = candidate;
|
|
950
|
-
break;
|
|
951
|
-
}
|
|
1027
|
+
} else {
|
|
1028
|
+
const parentItem = latestByKey.get(parentKey);
|
|
1029
|
+
const parentAmount = parentItem ? Number(getFieldValue(parentItem, qtyField) ?? 1) : 1;
|
|
1030
|
+
item.parentCount = parentAmount || 1;
|
|
952
1031
|
}
|
|
953
|
-
|
|
954
|
-
item.parentCount = parentAmount || 1;
|
|
1032
|
+
latestByKey.set(getFieldValue(item, toggleField), item);
|
|
955
1033
|
});
|
|
956
1034
|
return flattenedData;
|
|
957
1035
|
}, [
|
|
@@ -968,22 +1046,36 @@ var useConvertTreeData = ({
|
|
|
968
1046
|
if (!enabled) {
|
|
969
1047
|
return data ?? [];
|
|
970
1048
|
}
|
|
971
|
-
return
|
|
972
|
-
const aParts = String(a.treeNo ?? "").split("-").map(Number);
|
|
973
|
-
const bParts = String(b.treeNo ?? "").split("-").map(Number);
|
|
974
|
-
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
|
|
975
|
-
const aVal = aParts[i] || 0;
|
|
976
|
-
const bVal = bParts[i] || 0;
|
|
977
|
-
if (aVal !== bVal) {
|
|
978
|
-
return aVal - bVal;
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
return 0;
|
|
982
|
-
});
|
|
1049
|
+
return flattenTree;
|
|
983
1050
|
}, [enabled, data, flattenTree]);
|
|
984
1051
|
return sortedData;
|
|
985
1052
|
};
|
|
986
1053
|
|
|
1054
|
+
// src/components/ui/table/features/row-hover/rowHover.ts
|
|
1055
|
+
function createRowHoverStore() {
|
|
1056
|
+
let hoveredRowIndex = null;
|
|
1057
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1058
|
+
return {
|
|
1059
|
+
getHoveredRowIndex: () => hoveredRowIndex,
|
|
1060
|
+
setHoveredRowIndex: (nextRowIndex) => {
|
|
1061
|
+
if (nextRowIndex === hoveredRowIndex) return;
|
|
1062
|
+
hoveredRowIndex = nextRowIndex;
|
|
1063
|
+
listeners.forEach((listener) => listener());
|
|
1064
|
+
},
|
|
1065
|
+
subscribe: (listener) => {
|
|
1066
|
+
listeners.add(listener);
|
|
1067
|
+
return () => listeners.delete(listener);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
function isRowHovered(hoveredRowIndex, rowIndex) {
|
|
1072
|
+
return hoveredRowIndex === rowIndex;
|
|
1073
|
+
}
|
|
1074
|
+
function isRowGroupHovered(hoveredRowIndex, enableRowSpan, groupStart, groupSpan) {
|
|
1075
|
+
if (!enableRowSpan || hoveredRowIndex === null) return false;
|
|
1076
|
+
return hoveredRowIndex >= groupStart && hoveredRowIndex <= groupStart + groupSpan - 1;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
987
1079
|
// src/components/ui/table/features/row-span/rowSpan.ts
|
|
988
1080
|
function getRowFieldValue(row, key) {
|
|
989
1081
|
return row[key];
|
|
@@ -1022,13 +1114,13 @@ function computeRowSpans(data, rowSpanKey, parentSpans) {
|
|
|
1022
1114
|
for (let index = 0; index < data.length; index++) {
|
|
1023
1115
|
const currentValue = getRowFieldValue(data[index], rowSpanKey);
|
|
1024
1116
|
const previousValue = index > 0 ? getRowFieldValue(data[index - 1], rowSpanKey) : void 0;
|
|
1025
|
-
if (index > 0 && currentValue
|
|
1117
|
+
if (index > 0 && Object.is(currentValue, previousValue) && sharesParentGroup(parentStartRows, index)) {
|
|
1026
1118
|
result.push({ rowSpan: 0, isFirstInGroup: false });
|
|
1027
1119
|
continue;
|
|
1028
1120
|
}
|
|
1029
1121
|
let span = 1;
|
|
1030
1122
|
for (let nextIndex = index + 1; nextIndex < data.length; nextIndex++) {
|
|
1031
|
-
if (getRowFieldValue(data[nextIndex], rowSpanKey)
|
|
1123
|
+
if (!Object.is(getRowFieldValue(data[nextIndex], rowSpanKey), currentValue)) break;
|
|
1032
1124
|
if (!sharesParentGroup(parentStartRows, nextIndex)) break;
|
|
1033
1125
|
span++;
|
|
1034
1126
|
}
|
|
@@ -1286,7 +1378,11 @@ function blurActiveElementOutside(container) {
|
|
|
1286
1378
|
if (container instanceof Node && container.contains(active)) return;
|
|
1287
1379
|
active.blur();
|
|
1288
1380
|
}
|
|
1289
|
-
function resolveExpandCellIndex(cells, toggleField) {
|
|
1381
|
+
function resolveExpandCellIndex(cells, toggleField, expandColumn) {
|
|
1382
|
+
if (expandColumn) {
|
|
1383
|
+
const explicitIndex = cells.findIndex((cell) => cell.column.id === expandColumn);
|
|
1384
|
+
if (explicitIndex >= 0) return explicitIndex;
|
|
1385
|
+
}
|
|
1290
1386
|
if (!toggleField) return 0;
|
|
1291
1387
|
const matchedIndex = cells.findIndex(
|
|
1292
1388
|
(cell) => cell.column.id === toggleField
|
|
@@ -1329,7 +1425,7 @@ function DataTableRow({
|
|
|
1329
1425
|
enableRowSpan,
|
|
1330
1426
|
primaryRowSpanColumnId,
|
|
1331
1427
|
columnRowSpanMap,
|
|
1332
|
-
|
|
1428
|
+
hoverStore,
|
|
1333
1429
|
selectedRowIndices,
|
|
1334
1430
|
onRowHover
|
|
1335
1431
|
} = rowSpan;
|
|
@@ -1338,6 +1434,7 @@ function DataTableRow({
|
|
|
1338
1434
|
enableCellSelection,
|
|
1339
1435
|
activeSelectionBounds,
|
|
1340
1436
|
dragState,
|
|
1437
|
+
canFill = true,
|
|
1341
1438
|
onCellMouseDown,
|
|
1342
1439
|
onCellMouseEnter,
|
|
1343
1440
|
onFillHandleMouseDown
|
|
@@ -1345,9 +1442,12 @@ function DataTableRow({
|
|
|
1345
1442
|
const {
|
|
1346
1443
|
editingCell,
|
|
1347
1444
|
draftValue,
|
|
1445
|
+
draftInvalid = false,
|
|
1446
|
+
onDraftInvalidChange,
|
|
1348
1447
|
onDraftValueChange,
|
|
1349
1448
|
onStartEdit,
|
|
1350
1449
|
onCommitEdit,
|
|
1450
|
+
onCommitEditAndMove,
|
|
1351
1451
|
onCancelEdit
|
|
1352
1452
|
} = cellEdit;
|
|
1353
1453
|
const renderCell = (tableCell) => flexRender(
|
|
@@ -1357,6 +1457,7 @@ function DataTableRow({
|
|
|
1357
1457
|
const {
|
|
1358
1458
|
enableExpand,
|
|
1359
1459
|
toggleField,
|
|
1460
|
+
expandColumn,
|
|
1360
1461
|
expandedRows,
|
|
1361
1462
|
preventExpand,
|
|
1362
1463
|
onToggleExpand,
|
|
@@ -1365,13 +1466,50 @@ function DataTableRow({
|
|
|
1365
1466
|
} = expand;
|
|
1366
1467
|
const rowIndex = row.index;
|
|
1367
1468
|
const rowData = row.original;
|
|
1368
|
-
const isRowHovered = hoveredRowIndex === rowIndex;
|
|
1369
1469
|
const isRowSelected = row.getIsSelected();
|
|
1370
1470
|
const { startRow: primaryGroupStart, rowSpan: primaryGroupSpan } = resolveRowSpanAt(
|
|
1371
1471
|
primaryRowSpanColumnId ? columnRowSpanMap.get(primaryRowSpanColumnId) : void 0,
|
|
1372
1472
|
rowIndex
|
|
1373
1473
|
);
|
|
1374
|
-
const
|
|
1474
|
+
const isRowHovered2 = useSyncExternalStore(
|
|
1475
|
+
hoverStore.subscribe,
|
|
1476
|
+
() => isRowHovered(hoverStore.getHoveredRowIndex(), rowIndex),
|
|
1477
|
+
() => false
|
|
1478
|
+
);
|
|
1479
|
+
const isGroupHovered = useSyncExternalStore(
|
|
1480
|
+
hoverStore.subscribe,
|
|
1481
|
+
() => isRowGroupHovered(
|
|
1482
|
+
hoverStore.getHoveredRowIndex(),
|
|
1483
|
+
enableRowSpan,
|
|
1484
|
+
primaryGroupStart,
|
|
1485
|
+
primaryGroupSpan
|
|
1486
|
+
),
|
|
1487
|
+
() => false
|
|
1488
|
+
);
|
|
1489
|
+
const rowSpanColumnIds = enableRowSpan ? [...columnRowSpanMap.keys()].filter((id) => id !== primaryRowSpanColumnId) : [];
|
|
1490
|
+
const nestedRowSpanRanges = rowSpanColumnIds.map((columnId) => {
|
|
1491
|
+
const { startRow, rowSpan: span } = resolveRowSpanAt(
|
|
1492
|
+
columnRowSpanMap.get(columnId),
|
|
1493
|
+
rowIndex
|
|
1494
|
+
);
|
|
1495
|
+
return { columnId, startRow, span };
|
|
1496
|
+
});
|
|
1497
|
+
const nestedHoverSignature = useSyncExternalStore(
|
|
1498
|
+
hoverStore.subscribe,
|
|
1499
|
+
() => {
|
|
1500
|
+
const hovered = hoverStore.getHoveredRowIndex();
|
|
1501
|
+
return nestedRowSpanRanges.map(
|
|
1502
|
+
({ startRow, span }) => isRowGroupHovered(hovered, true, startRow, span) ? "1" : "0"
|
|
1503
|
+
).join("");
|
|
1504
|
+
},
|
|
1505
|
+
() => rowSpanColumnIds.map(() => "0").join("")
|
|
1506
|
+
);
|
|
1507
|
+
const nestedHoverByColumn = new Map(
|
|
1508
|
+
rowSpanColumnIds.map((columnId, index) => [
|
|
1509
|
+
columnId,
|
|
1510
|
+
nestedHoverSignature[index] === "1"
|
|
1511
|
+
])
|
|
1512
|
+
);
|
|
1375
1513
|
const visibleCells = row.getVisibleCells();
|
|
1376
1514
|
const columnIdsByIndex = visibleCells.map((cell) => cell.column.id);
|
|
1377
1515
|
row.getIsCellDragSelected = (columnId) => {
|
|
@@ -1417,12 +1555,13 @@ function DataTableRow({
|
|
|
1417
1555
|
span
|
|
1418
1556
|
);
|
|
1419
1557
|
} : void 0;
|
|
1420
|
-
const expandCellIndex = enableExpand ? resolveExpandCellIndex(visibleCells, toggleField) : -1;
|
|
1558
|
+
const expandCellIndex = enableExpand ? resolveExpandCellIndex(visibleCells, toggleField, expandColumn) : -1;
|
|
1421
1559
|
const canExpand = enableExpand && !preventExpand && canExpandRow(rowData);
|
|
1422
1560
|
const expandKey = toggleField && rowData[toggleField] !== null && rowData[toggleField] !== void 0 ? String(rowData[toggleField]) : null;
|
|
1423
1561
|
const isExpanded = expandKey !== null && Boolean(expandedRows?.has(expandKey));
|
|
1424
1562
|
const rowLevel = typeof rowData.level === "number" ? rowData.level : 0;
|
|
1425
1563
|
const editInputRef = useRef2(null);
|
|
1564
|
+
const cellPressRef = useRef2(false);
|
|
1426
1565
|
const isRowEditing = editingCell?.rowIndex === rowIndex;
|
|
1427
1566
|
useEffect2(() => {
|
|
1428
1567
|
if (!isRowEditing) return;
|
|
@@ -1435,23 +1574,29 @@ function DataTableRow({
|
|
|
1435
1574
|
ref: measureElement,
|
|
1436
1575
|
"data-index": virtualIndex,
|
|
1437
1576
|
"data-selected": isRowSelected ? "" : void 0,
|
|
1438
|
-
"data-hovered":
|
|
1577
|
+
"data-hovered": isRowHovered2 || isGroupHovered ? "" : void 0,
|
|
1439
1578
|
"data-expandable": enableExpand && canExpand ? "" : void 0,
|
|
1440
1579
|
"data-expanded": isExpanded ? "" : void 0,
|
|
1580
|
+
"data-level": enableExpand ? rowLevel : void 0,
|
|
1441
1581
|
className: cn(
|
|
1442
1582
|
"DataTableRowJSX",
|
|
1443
1583
|
!enableRowSpan && ROW_HOVER_CLASS,
|
|
1444
|
-
enableRowSpan &&
|
|
1584
|
+
enableRowSpan && isRowHovered2 && !isRowSelected && ROW_HOVERED_BG_CLASS,
|
|
1445
1585
|
isRowSelected && "is-selected",
|
|
1446
1586
|
enableExpand && canExpand && "is-expandable",
|
|
1447
1587
|
classNames?.row,
|
|
1448
1588
|
getRowClassName?.(rowData, rowIndex)
|
|
1449
1589
|
),
|
|
1450
1590
|
onMouseEnter: () => onRowHover(rowIndex, rowData),
|
|
1591
|
+
onMouseDownCapture: () => {
|
|
1592
|
+
cellPressRef.current = false;
|
|
1593
|
+
},
|
|
1451
1594
|
onClick: () => {
|
|
1595
|
+
const startedCellSelection = cellPressRef.current;
|
|
1596
|
+
cellPressRef.current = false;
|
|
1452
1597
|
if (isRowEditing) return;
|
|
1453
1598
|
onRowClick?.(rowData, rowIndex);
|
|
1454
|
-
if (rowSelectionMode !== "none" && selectOnRowClick) {
|
|
1599
|
+
if (rowSelectionMode !== "none" && selectOnRowClick && !startedCellSelection) {
|
|
1455
1600
|
onToggleSelect();
|
|
1456
1601
|
}
|
|
1457
1602
|
},
|
|
@@ -1474,8 +1619,8 @@ function DataTableRow({
|
|
|
1474
1619
|
}
|
|
1475
1620
|
const isEditing = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === cellIndex;
|
|
1476
1621
|
const cellRowSpan = rowSpanInfo?.rowSpan ?? 1;
|
|
1477
|
-
const isMergedCellHovered =
|
|
1478
|
-
const showCellHover = isRowSpanColumn ? isMergedCellHovered :
|
|
1622
|
+
const isMergedCellHovered = columnId === primaryRowSpanColumnId ? isGroupHovered : nestedHoverByColumn.get(columnId) ?? false;
|
|
1623
|
+
const showCellHover = isRowSpanColumn ? isMergedCellHovered : isRowHovered2;
|
|
1479
1624
|
let isMergedCellSelected = false;
|
|
1480
1625
|
if (isRowSpanColumn) {
|
|
1481
1626
|
for (let r = rowIndex; r < rowIndex + cellRowSpan; r += 1) {
|
|
@@ -1497,7 +1642,7 @@ function DataTableRow({
|
|
|
1497
1642
|
activeSelectionBounds,
|
|
1498
1643
|
cellRowSpan
|
|
1499
1644
|
);
|
|
1500
|
-
const isBottomRightCell = !isEditing && activeSelectionBounds && !dragState.isSelecting && activeSelectionBounds.endRow >= rowIndex && activeSelectionBounds.endRow <= rowIndex + cellRowSpan - 1 && cellIndex === activeSelectionBounds.endCol;
|
|
1645
|
+
const isBottomRightCell = canFill && !isEditing && activeSelectionBounds && !dragState.isSelecting && activeSelectionBounds.endRow >= rowIndex && activeSelectionBounds.endRow <= rowIndex + cellRowSpan - 1 && cellIndex === activeSelectionBounds.endCol;
|
|
1501
1646
|
const spanRowHeights = enableCellSelection && activeSelectionBounds && isCellDragSelected && cellRowSpan > 1 ? measureMergedSpanRowHeights(rowIndex, cellRowSpan) : void 0;
|
|
1502
1647
|
const selectionEdgeStyle = getCellSelectionEdgeStyle(
|
|
1503
1648
|
rowIndex,
|
|
@@ -1555,6 +1700,7 @@ function DataTableRow({
|
|
|
1555
1700
|
if (isInteractiveMouseTarget(event.target)) return;
|
|
1556
1701
|
event.preventDefault();
|
|
1557
1702
|
blurActiveElementOutside(event.currentTarget);
|
|
1703
|
+
cellPressRef.current = true;
|
|
1558
1704
|
onCellMouseDown(
|
|
1559
1705
|
resolveCellRowIndex(event.clientY, event.currentTarget),
|
|
1560
1706
|
cellIndex,
|
|
@@ -1608,6 +1754,8 @@ function DataTableRow({
|
|
|
1608
1754
|
ref: editInputRef,
|
|
1609
1755
|
type: editType === "number" ? "number" : "text",
|
|
1610
1756
|
defaultValue: draftValue,
|
|
1757
|
+
"aria-invalid": draftInvalid ? true : void 0,
|
|
1758
|
+
"data-invalid": draftInvalid ? "" : void 0,
|
|
1611
1759
|
className: cn(
|
|
1612
1760
|
"cell-edit-input",
|
|
1613
1761
|
CELL_ALIGN_CLASS[align],
|
|
@@ -1616,6 +1764,7 @@ function DataTableRow({
|
|
|
1616
1764
|
),
|
|
1617
1765
|
onChange: (event) => {
|
|
1618
1766
|
editInputProps?.onChange?.(event);
|
|
1767
|
+
onDraftInvalidChange?.(Boolean(event.target.validity?.badInput));
|
|
1619
1768
|
onDraftValueChange(event.target.value);
|
|
1620
1769
|
},
|
|
1621
1770
|
onMouseDown: (event) => {
|
|
@@ -1629,9 +1778,22 @@ function DataTableRow({
|
|
|
1629
1778
|
onKeyDown: (event) => {
|
|
1630
1779
|
editInputProps?.onKeyDown?.(event);
|
|
1631
1780
|
if (event.defaultPrevented) return;
|
|
1632
|
-
if (event.
|
|
1781
|
+
if (event.nativeEvent.isComposing || event.keyCode === 229) {
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
1633
1785
|
event.preventDefault();
|
|
1634
|
-
|
|
1786
|
+
if (event.currentTarget.validity?.badInput) {
|
|
1787
|
+
onDraftInvalidChange?.(true);
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
const delta = event.key === "Enter" ? { row: event.shiftKey ? -1 : 1, col: 0 } : { row: 0, col: event.shiftKey ? -1 : 1 };
|
|
1791
|
+
if (onCommitEditAndMove) {
|
|
1792
|
+
onCommitEditAndMove(event.currentTarget.value, delta);
|
|
1793
|
+
} else {
|
|
1794
|
+
onCommitEdit(event.currentTarget.value);
|
|
1795
|
+
}
|
|
1796
|
+
return;
|
|
1635
1797
|
}
|
|
1636
1798
|
if (event.key === "Escape") {
|
|
1637
1799
|
event.preventDefault();
|
|
@@ -1641,6 +1803,10 @@ function DataTableRow({
|
|
|
1641
1803
|
onBlur: (event) => {
|
|
1642
1804
|
editInputProps?.onBlur?.(event);
|
|
1643
1805
|
if (event.defaultPrevented) return;
|
|
1806
|
+
if (event.currentTarget.validity?.badInput) {
|
|
1807
|
+
onDraftInvalidChange?.(true);
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1644
1810
|
onCommitEdit(event.currentTarget.value);
|
|
1645
1811
|
}
|
|
1646
1812
|
}
|
|
@@ -1652,6 +1818,7 @@ function DataTableRow({
|
|
|
1652
1818
|
"expand-cell-content",
|
|
1653
1819
|
classNames?.expandCellContent
|
|
1654
1820
|
),
|
|
1821
|
+
style: { "--table-row-level": rowLevel },
|
|
1655
1822
|
children: [
|
|
1656
1823
|
rowLevel > 0 && /* @__PURE__ */ jsx3(
|
|
1657
1824
|
"span",
|
|
@@ -1681,6 +1848,7 @@ function DataTableRow({
|
|
|
1681
1848
|
{
|
|
1682
1849
|
type: "button",
|
|
1683
1850
|
"aria-label": isExpanded ? collapseRowLabel : expandRowLabel,
|
|
1851
|
+
"aria-expanded": isExpanded,
|
|
1684
1852
|
className: cn(
|
|
1685
1853
|
"expand-toggle-button",
|
|
1686
1854
|
classNames?.expandToggle
|
|
@@ -1767,6 +1935,7 @@ function DataTableSearch({
|
|
|
1767
1935
|
previousLabel,
|
|
1768
1936
|
nextLabel,
|
|
1769
1937
|
closeLabel,
|
|
1938
|
+
formatResult = formatSearchResultLabel,
|
|
1770
1939
|
rowsTotal,
|
|
1771
1940
|
classNames,
|
|
1772
1941
|
onSearchValueChange,
|
|
@@ -1775,9 +1944,10 @@ function DataTableSearch({
|
|
|
1775
1944
|
onPrevious
|
|
1776
1945
|
}) {
|
|
1777
1946
|
if (!showSearch) return null;
|
|
1778
|
-
const resultString = searchStatus ?
|
|
1947
|
+
const resultString = searchStatus ? formatResult(searchStatus) : resultHint;
|
|
1779
1948
|
const progress = rowsTotal > 0 ? Math.floor((searchStatus?.rowsSearched ?? 0) / rowsTotal * 100) : 0;
|
|
1780
1949
|
const handleKeyDown = (event) => {
|
|
1950
|
+
if (event.nativeEvent.isComposing || event.keyCode === 229) return;
|
|
1781
1951
|
if ((event.ctrlKey || event.metaKey) && event.code === "KeyF" || event.key === "Escape") {
|
|
1782
1952
|
event.preventDefault();
|
|
1783
1953
|
event.stopPropagation();
|
|
@@ -1901,6 +2071,7 @@ function DataTableToolbar({
|
|
|
1901
2071
|
summary,
|
|
1902
2072
|
selectedCount,
|
|
1903
2073
|
selectionLabel,
|
|
2074
|
+
countLabel,
|
|
1904
2075
|
toolbar,
|
|
1905
2076
|
className,
|
|
1906
2077
|
classNames
|
|
@@ -1914,7 +2085,7 @@ function DataTableToolbar({
|
|
|
1914
2085
|
if (!hasLeftContent && !hasToolbar && !hasSelectionContent) return null;
|
|
1915
2086
|
return /* @__PURE__ */ jsxs4("div", { className: cn("DataTableToolbarJSX", classNames?.toolbar, className), children: [
|
|
1916
2087
|
/* @__PURE__ */ jsxs4("div", { className: cn("toolbar-left", classNames?.toolbarLeft), children: [
|
|
1917
|
-
hasCount && /* @__PURE__ */ jsx5("span", { className: cn("toolbar-count", classNames?.toolbarCount), children: displayFiltered !== void 0 && totalCount !== void 0 ? /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
2088
|
+
hasCount && /* @__PURE__ */ jsx5("span", { className: cn("toolbar-count", classNames?.toolbarCount), children: countLabel ? countLabel(displayFiltered, totalCount) : displayFiltered !== void 0 && totalCount !== void 0 ? /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
1918
2089
|
/* @__PURE__ */ jsx5("span", { className: "toolbar-count-primary", children: displayFiltered }),
|
|
1919
2090
|
/* @__PURE__ */ jsxs4("span", { className: "toolbar-count-placeholder", children: [
|
|
1920
2091
|
" / ",
|
|
@@ -2315,13 +2486,13 @@ import {
|
|
|
2315
2486
|
import {
|
|
2316
2487
|
useCallback as useCallback5,
|
|
2317
2488
|
useEffect as useEffect7,
|
|
2318
|
-
useMemo as
|
|
2489
|
+
useMemo as useMemo5,
|
|
2319
2490
|
useRef as useRef7,
|
|
2320
2491
|
useState as useState5
|
|
2321
2492
|
} from "react";
|
|
2322
2493
|
|
|
2323
2494
|
// src/components/ui/table/features/cell-edit/useCellEdit.ts
|
|
2324
|
-
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef4, useState as useState2 } from "react";
|
|
2495
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef4, useState as useState2 } from "react";
|
|
2325
2496
|
|
|
2326
2497
|
// src/components/ui/table/features/cell-render/commitCellValue.ts
|
|
2327
2498
|
function commitCellValue({
|
|
@@ -2344,12 +2515,12 @@ function commitCellValue({
|
|
|
2344
2515
|
if (!cell) return false;
|
|
2345
2516
|
const accessorKey = getColumnAccessorKey(cell.column.columnDef);
|
|
2346
2517
|
if (!accessorKey) return false;
|
|
2347
|
-
const
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2518
|
+
const next = applyCellChangesToData(data, [
|
|
2519
|
+
{ original: row.original, index: row.index, accessorKey, value }
|
|
2520
|
+
]);
|
|
2521
|
+
if (next === data || next.every((item, index) => item === data[index])) {
|
|
2522
|
+
return false;
|
|
2523
|
+
}
|
|
2353
2524
|
onDataChange?.(next);
|
|
2354
2525
|
return true;
|
|
2355
2526
|
}
|
|
@@ -2361,19 +2532,36 @@ function useCellEdit({
|
|
|
2361
2532
|
onDataChange,
|
|
2362
2533
|
onCellChange
|
|
2363
2534
|
}) {
|
|
2364
|
-
const [
|
|
2535
|
+
const [editingKey, setEditingKey] = useState2(null);
|
|
2365
2536
|
const [draftValue, setDraftValue] = useState2("");
|
|
2366
2537
|
const draftValueRef = useRef4(draftValue);
|
|
2367
|
-
const
|
|
2538
|
+
const [draftInvalid, setDraftInvalidState] = useState2(false);
|
|
2539
|
+
const draftInvalidRef = useRef4(false);
|
|
2540
|
+
const setDraftInvalid = useCallback2((invalid) => {
|
|
2541
|
+
draftInvalidRef.current = invalid;
|
|
2542
|
+
setDraftInvalidState(invalid);
|
|
2543
|
+
}, []);
|
|
2368
2544
|
useEffect4(() => {
|
|
2369
2545
|
draftValueRef.current = draftValue;
|
|
2370
2546
|
}, [draftValue]);
|
|
2547
|
+
const editingCell = useMemo2(
|
|
2548
|
+
() => resolveEditingCell(rows, editingKey),
|
|
2549
|
+
[rows, editingKey]
|
|
2550
|
+
);
|
|
2551
|
+
const editingCellRef = useRef4(editingCell);
|
|
2552
|
+
editingCellRef.current = editingCell;
|
|
2371
2553
|
useEffect4(() => {
|
|
2372
|
-
|
|
2373
|
-
|
|
2554
|
+
if (editingKey && !editingCell) {
|
|
2555
|
+
setEditingKey(null);
|
|
2556
|
+
setDraftValue("");
|
|
2557
|
+
}
|
|
2558
|
+
}, [editingCell, editingKey]);
|
|
2374
2559
|
const cancelEdit = useCallback2(() => {
|
|
2375
|
-
|
|
2560
|
+
editingCellRef.current = null;
|
|
2561
|
+
setEditingKey(null);
|
|
2376
2562
|
setDraftValue("");
|
|
2563
|
+
draftInvalidRef.current = false;
|
|
2564
|
+
setDraftInvalidState(false);
|
|
2377
2565
|
}, []);
|
|
2378
2566
|
const commitEdit = useCallback2(
|
|
2379
2567
|
(raw) => {
|
|
@@ -2393,6 +2581,7 @@ function useCellEdit({
|
|
|
2393
2581
|
cancelEdit();
|
|
2394
2582
|
return true;
|
|
2395
2583
|
}
|
|
2584
|
+
if (draftInvalidRef.current) return false;
|
|
2396
2585
|
const value = raw ?? draftValueRef.current;
|
|
2397
2586
|
const parsed = parseCellEditValue(value, getColumnEditType(cell.column.columnDef));
|
|
2398
2587
|
if (!parsed.ok) return false;
|
|
@@ -2413,13 +2602,15 @@ function useCellEdit({
|
|
|
2413
2602
|
);
|
|
2414
2603
|
const startEdit = useCallback2(
|
|
2415
2604
|
(rowIndex, colIndex) => {
|
|
2416
|
-
const
|
|
2417
|
-
|
|
2605
|
+
const row = rows[rowIndex];
|
|
2606
|
+
const cell = row?.getVisibleCells()[colIndex];
|
|
2607
|
+
if (!row || !cell || !isColumnEditable(cell.column.columnDef)) return;
|
|
2608
|
+
if (!isTextEditableValue(cell.getValue())) return;
|
|
2418
2609
|
const current = editingCellRef.current;
|
|
2419
2610
|
if (current && (current.rowIndex !== rowIndex || current.colIndex !== colIndex) && !commitEdit()) {
|
|
2420
2611
|
return;
|
|
2421
2612
|
}
|
|
2422
|
-
|
|
2613
|
+
setEditingKey({ rowId: row.id, columnId: cell.column.id });
|
|
2423
2614
|
setDraftValue(getCellEditDraftValue(cell.getValue()));
|
|
2424
2615
|
},
|
|
2425
2616
|
[commitEdit, rows]
|
|
@@ -2427,12 +2618,55 @@ function useCellEdit({
|
|
|
2427
2618
|
return {
|
|
2428
2619
|
editingCell,
|
|
2429
2620
|
draftValue,
|
|
2621
|
+
draftInvalid,
|
|
2622
|
+
setDraftInvalid,
|
|
2430
2623
|
setDraftValue,
|
|
2431
2624
|
startEdit,
|
|
2432
2625
|
commitEdit,
|
|
2433
2626
|
cancelEdit
|
|
2434
2627
|
};
|
|
2435
2628
|
}
|
|
2629
|
+
function resolveEditingCell(rows, key) {
|
|
2630
|
+
if (!key) return null;
|
|
2631
|
+
const rowIndex = rows.findIndex((row) => row.id === key.rowId);
|
|
2632
|
+
if (rowIndex < 0) return null;
|
|
2633
|
+
const colIndex = rows[rowIndex].getVisibleCells().findIndex((cell) => cell.column.id === key.columnId);
|
|
2634
|
+
if (colIndex < 0) return null;
|
|
2635
|
+
return { rowIndex, colIndex };
|
|
2636
|
+
}
|
|
2637
|
+
function isTextEditableValue(value) {
|
|
2638
|
+
return value === null || value === void 0 || typeof value !== "object";
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
// src/components/ui/table/features/cell-selection/formatCellValue.ts
|
|
2642
|
+
function formatObjectValue(value) {
|
|
2643
|
+
const text = value.text ?? value.label ?? value.name ?? value.title;
|
|
2644
|
+
if (text != null && text !== "") {
|
|
2645
|
+
return formatCellValue(text);
|
|
2646
|
+
}
|
|
2647
|
+
try {
|
|
2648
|
+
return JSON.stringify(value);
|
|
2649
|
+
} catch {
|
|
2650
|
+
return "";
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
function formatCellValue(value) {
|
|
2654
|
+
if (value === null || value === void 0) return "";
|
|
2655
|
+
if (value instanceof Date) {
|
|
2656
|
+
return Number.isNaN(value.getTime()) ? "" : value.toISOString();
|
|
2657
|
+
}
|
|
2658
|
+
if (Array.isArray(value)) {
|
|
2659
|
+
return value.map((item) => formatCellValue(item)).filter((item) => item.length > 0).join(", ");
|
|
2660
|
+
}
|
|
2661
|
+
if (typeof value === "object") {
|
|
2662
|
+
return formatObjectValue(value);
|
|
2663
|
+
}
|
|
2664
|
+
if (typeof value === "string") return value;
|
|
2665
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
2666
|
+
return String(value);
|
|
2667
|
+
}
|
|
2668
|
+
return "";
|
|
2669
|
+
}
|
|
2436
2670
|
|
|
2437
2671
|
// src/components/ui/table/features/cell-render/builtins.tsx
|
|
2438
2672
|
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
@@ -2456,8 +2690,9 @@ function asDrilldownItems(value) {
|
|
|
2456
2690
|
const record = item;
|
|
2457
2691
|
const text = asString(record.text ?? record.label ?? "");
|
|
2458
2692
|
if (!text) return [];
|
|
2459
|
-
const
|
|
2460
|
-
|
|
2693
|
+
const rawImg = record.img ?? record.image;
|
|
2694
|
+
const img = typeof rawImg === "string" ? sanitizeImageSrc(rawImg) : null;
|
|
2695
|
+
return [{ text, ...img ? { img } : {} }];
|
|
2461
2696
|
}
|
|
2462
2697
|
return [{ text: asString(item) }];
|
|
2463
2698
|
});
|
|
@@ -2518,6 +2753,22 @@ function sanitizeUriHref(raw) {
|
|
|
2518
2753
|
return href;
|
|
2519
2754
|
}
|
|
2520
2755
|
}
|
|
2756
|
+
function sanitizeImageSrc(raw) {
|
|
2757
|
+
const src = raw.trim();
|
|
2758
|
+
if (!src) return null;
|
|
2759
|
+
try {
|
|
2760
|
+
const parsed = new URL(src);
|
|
2761
|
+
const protocol = parsed.protocol.toLowerCase();
|
|
2762
|
+
if (protocol === "http:" || protocol === "https:" || protocol === "blob:") {
|
|
2763
|
+
return src;
|
|
2764
|
+
}
|
|
2765
|
+
if (protocol === "data:" && /^data:image\//i.test(src)) return src;
|
|
2766
|
+
return null;
|
|
2767
|
+
} catch {
|
|
2768
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(src)) return null;
|
|
2769
|
+
return src;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2521
2772
|
function UriCell({ value }) {
|
|
2522
2773
|
const raw = asString(value);
|
|
2523
2774
|
if (!raw) return null;
|
|
@@ -2539,7 +2790,10 @@ function UriCell({ value }) {
|
|
|
2539
2790
|
);
|
|
2540
2791
|
}
|
|
2541
2792
|
function ImageCell({ value }) {
|
|
2542
|
-
const urls = asStringList(value)
|
|
2793
|
+
const urls = asStringList(value).flatMap((url) => {
|
|
2794
|
+
const src = sanitizeImageSrc(url);
|
|
2795
|
+
return src ? [src] : [];
|
|
2796
|
+
});
|
|
2543
2797
|
if (urls.length === 0) return null;
|
|
2544
2798
|
return /* @__PURE__ */ jsx6("span", { className: "data-table-cell-image", children: urls.map((url, index) => /* @__PURE__ */ jsx6(
|
|
2545
2799
|
"img",
|
|
@@ -2592,8 +2846,33 @@ function DrilldownCell({ value }) {
|
|
|
2592
2846
|
function LoadingCell() {
|
|
2593
2847
|
return /* @__PURE__ */ jsx6("span", { className: "data-table-cell-loading", "aria-busy": "true" });
|
|
2594
2848
|
}
|
|
2595
|
-
function ProtectedCell() {
|
|
2596
|
-
|
|
2849
|
+
function ProtectedCell({ cellProps }) {
|
|
2850
|
+
const label = typeof cellProps?.ariaLabel === "string" ? cellProps.ariaLabel : "protected";
|
|
2851
|
+
return /* @__PURE__ */ jsx6("span", { className: "data-table-cell-protected", "aria-label": label, children: "****" });
|
|
2852
|
+
}
|
|
2853
|
+
function RowSelectCell({ row, cellProps }) {
|
|
2854
|
+
const canSelect = typeof row.getCanSelect === "function" ? row.getCanSelect() : false;
|
|
2855
|
+
const checked = typeof row.getIsSelected === "function" ? row.getIsSelected() : false;
|
|
2856
|
+
const label = typeof cellProps?.ariaLabel === "string" ? cellProps.ariaLabel : "Select row";
|
|
2857
|
+
return /* @__PURE__ */ jsx6(
|
|
2858
|
+
"input",
|
|
2859
|
+
{
|
|
2860
|
+
type: "checkbox",
|
|
2861
|
+
className: "data-table-cell-row-select",
|
|
2862
|
+
checked,
|
|
2863
|
+
disabled: !canSelect,
|
|
2864
|
+
"aria-label": label,
|
|
2865
|
+
onChange: () => {
|
|
2866
|
+
if (canSelect) row.toggleSelected();
|
|
2867
|
+
},
|
|
2868
|
+
onClick: (event) => {
|
|
2869
|
+
event.stopPropagation();
|
|
2870
|
+
},
|
|
2871
|
+
onMouseDown: (event) => {
|
|
2872
|
+
event.stopPropagation();
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
);
|
|
2597
2876
|
}
|
|
2598
2877
|
function RowIdCell({ value }) {
|
|
2599
2878
|
return /* @__PURE__ */ jsx6("span", { className: "data-table-cell-row-id", children: asString(value) });
|
|
@@ -2609,7 +2888,8 @@ var BUILTIN_RENDER_MAP = {
|
|
|
2609
2888
|
drilldown: DrilldownCell,
|
|
2610
2889
|
loading: LoadingCell,
|
|
2611
2890
|
protected: ProtectedCell,
|
|
2612
|
-
"row-id": RowIdCell
|
|
2891
|
+
"row-id": RowIdCell,
|
|
2892
|
+
"row-select": RowSelectCell
|
|
2613
2893
|
};
|
|
2614
2894
|
var BUILTIN_CELL_RENDERERS = Object.keys(BUILTIN_RENDER_MAP).map((kind) => ({
|
|
2615
2895
|
kind,
|
|
@@ -2643,47 +2923,32 @@ function formatDefaultCellValue(value) {
|
|
|
2643
2923
|
return String(value);
|
|
2644
2924
|
}
|
|
2645
2925
|
if (typeof value === "bigint") return value.toString();
|
|
2646
|
-
return
|
|
2926
|
+
return formatCellValue(value);
|
|
2647
2927
|
}
|
|
2648
2928
|
|
|
2649
|
-
// src/components/ui/table/features/cell-selection/
|
|
2650
|
-
import {
|
|
2929
|
+
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
2930
|
+
import { isValidElement } from "react";
|
|
2651
2931
|
|
|
2652
|
-
// src/components/ui/table/features/cell-selection/
|
|
2653
|
-
var
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
2932
|
+
// src/components/ui/table/features/cell-selection/subtreeClipboard.ts
|
|
2933
|
+
var lastSubtreeCopy = null;
|
|
2934
|
+
function normalize(text) {
|
|
2935
|
+
return text.replace(/\r\n?/g, "\n").replace(/\n+$/, "");
|
|
2657
2936
|
}
|
|
2658
|
-
function
|
|
2659
|
-
|
|
2660
|
-
return () => {
|
|
2661
|
-
clearByOwner.delete(owner);
|
|
2662
|
-
if (activeOwner === owner) {
|
|
2663
|
-
activeOwner = null;
|
|
2664
|
-
}
|
|
2665
|
-
};
|
|
2937
|
+
function rememberSubtreeCopy(text) {
|
|
2938
|
+
lastSubtreeCopy = normalize(text);
|
|
2666
2939
|
}
|
|
2667
|
-
function
|
|
2668
|
-
|
|
2669
|
-
activeOwner = owner;
|
|
2670
|
-
for (const [id, clearSelection] of clearByOwner) {
|
|
2671
|
-
if (id !== owner) {
|
|
2672
|
-
clearSelection();
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
}
|
|
2676
|
-
function isActiveCellSelectionOwner(owner) {
|
|
2677
|
-
return activeOwner === owner;
|
|
2678
|
-
}
|
|
2679
|
-
function releaseCellSelectionOwner(owner) {
|
|
2680
|
-
if (activeOwner === owner) {
|
|
2681
|
-
activeOwner = null;
|
|
2682
|
-
}
|
|
2940
|
+
function isOwnSubtreeCopy(text) {
|
|
2941
|
+
return lastSubtreeCopy !== null && normalize(text) === lastSubtreeCopy;
|
|
2683
2942
|
}
|
|
2684
2943
|
|
|
2685
2944
|
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
2686
|
-
|
|
2945
|
+
var SPREADSHEET_FORMULA_PREFIX = /^[=+\-@\t\r]/;
|
|
2946
|
+
var PLAIN_SIGNED_NUMBER = /^[+-]\d+(?:\.\d+)?$/;
|
|
2947
|
+
function escapeSpreadsheetFormula(text) {
|
|
2948
|
+
if (!SPREADSHEET_FORMULA_PREFIX.test(text)) return text;
|
|
2949
|
+
if (PLAIN_SIGNED_NUMBER.test(text)) return text;
|
|
2950
|
+
return `'${text}`;
|
|
2951
|
+
}
|
|
2687
2952
|
function isReactNodeIterable(node) {
|
|
2688
2953
|
return typeof node === "object" && node !== null && !isValidElement(node) && Symbol.iterator in node;
|
|
2689
2954
|
}
|
|
@@ -2809,6 +3074,10 @@ function reactNodeToText(node) {
|
|
|
2809
3074
|
}
|
|
2810
3075
|
return "";
|
|
2811
3076
|
}
|
|
3077
|
+
function quoteTsvCell(text) {
|
|
3078
|
+
if (!/[\t\n\r]/.test(text) && !text.startsWith('"')) return text;
|
|
3079
|
+
return `"${text.replace(/"/g, '""')}"`;
|
|
3080
|
+
}
|
|
2812
3081
|
function sanitizeClipboardCell(text) {
|
|
2813
3082
|
return text.replace(/\s+/g, " ").trim();
|
|
2814
3083
|
}
|
|
@@ -2884,7 +3153,7 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
|
|
|
2884
3153
|
return formatCellValue(value);
|
|
2885
3154
|
}
|
|
2886
3155
|
}
|
|
2887
|
-
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
3156
|
+
if (options?.registry && meta?.kind && (isPrimitiveCopyValue(value) || meta.kind === "protected")) {
|
|
2888
3157
|
try {
|
|
2889
3158
|
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
2890
3159
|
if (renderer) {
|
|
@@ -2898,35 +3167,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
|
|
|
2898
3167
|
}
|
|
2899
3168
|
return formatCellValue(value);
|
|
2900
3169
|
}
|
|
2901
|
-
function formatPrimitive(value) {
|
|
2902
|
-
if (value === null || value === void 0) return "";
|
|
2903
|
-
if (typeof value === "string") return value;
|
|
2904
|
-
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
2905
|
-
return String(value);
|
|
2906
|
-
}
|
|
2907
|
-
return "";
|
|
2908
|
-
}
|
|
2909
|
-
function formatObjectValue(value) {
|
|
2910
|
-
const text = value.text ?? value.label ?? value.name ?? value.title;
|
|
2911
|
-
if (text != null && text !== "") {
|
|
2912
|
-
return formatCellValue(text);
|
|
2913
|
-
}
|
|
2914
|
-
try {
|
|
2915
|
-
return JSON.stringify(value);
|
|
2916
|
-
} catch {
|
|
2917
|
-
return "";
|
|
2918
|
-
}
|
|
2919
|
-
}
|
|
2920
|
-
function formatCellValue(value) {
|
|
2921
|
-
if (value === null || value === void 0) return "";
|
|
2922
|
-
if (Array.isArray(value)) {
|
|
2923
|
-
return value.map((item) => formatCellValue(item)).filter((item) => item.length > 0).join(", ");
|
|
2924
|
-
}
|
|
2925
|
-
if (typeof value === "object") {
|
|
2926
|
-
return formatObjectValue(value);
|
|
2927
|
-
}
|
|
2928
|
-
return formatPrimitive(value);
|
|
2929
|
-
}
|
|
2930
3170
|
function getNestedValue(row, path) {
|
|
2931
3171
|
if (!path.includes(".")) return row[path];
|
|
2932
3172
|
return path.split(".").reduce((current, key) => {
|
|
@@ -2958,15 +3198,23 @@ function getRowDepth(original) {
|
|
|
2958
3198
|
function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
|
|
2959
3199
|
const { startRow, endRow } = bounds;
|
|
2960
3200
|
const result = [];
|
|
2961
|
-
|
|
3201
|
+
if (mode !== "subtree") {
|
|
3202
|
+
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex += 1) {
|
|
3203
|
+
const row = visibleRows[rowIndex];
|
|
3204
|
+
if (row) result.push({ row: row.original, depth: 0 });
|
|
3205
|
+
}
|
|
3206
|
+
return result;
|
|
3207
|
+
}
|
|
3208
|
+
const included = /* @__PURE__ */ new Set();
|
|
3209
|
+
const keyOf = (node) => getTreeRowKey(node) ?? (getOriginalRowId(node) || node);
|
|
2962
3210
|
const appendSubtree = (node, depth) => {
|
|
2963
3211
|
const children = node.children;
|
|
2964
3212
|
if (!Array.isArray(children) || children.length === 0) return;
|
|
2965
3213
|
for (const child of children) {
|
|
2966
|
-
const
|
|
2967
|
-
if (!
|
|
3214
|
+
const key = keyOf(child);
|
|
3215
|
+
if (!included.has(key)) {
|
|
2968
3216
|
result.push({ row: child, depth });
|
|
2969
|
-
|
|
3217
|
+
included.add(key);
|
|
2970
3218
|
}
|
|
2971
3219
|
appendSubtree(child, depth + 1);
|
|
2972
3220
|
}
|
|
@@ -2974,12 +3222,12 @@ function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
|
|
|
2974
3222
|
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex += 1) {
|
|
2975
3223
|
const row = visibleRows[rowIndex];
|
|
2976
3224
|
if (!row) continue;
|
|
2977
|
-
const
|
|
2978
|
-
if (
|
|
3225
|
+
const key = keyOf(row.original);
|
|
3226
|
+
if (included.has(key)) continue;
|
|
2979
3227
|
const depth = getRowDepth(row.original);
|
|
2980
3228
|
result.push({ row: row.original, depth });
|
|
2981
|
-
|
|
2982
|
-
if (
|
|
3229
|
+
included.add(key);
|
|
3230
|
+
if (!hasSubtree(row.original)) continue;
|
|
2983
3231
|
appendSubtree(row.original, depth + 1);
|
|
2984
3232
|
}
|
|
2985
3233
|
return result;
|
|
@@ -3004,7 +3252,7 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
|
|
|
3004
3252
|
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
3005
3253
|
const sourceCell = matchingCells?.[colOffset];
|
|
3006
3254
|
const column = sourceCell?.column ?? templateCell.column;
|
|
3007
|
-
|
|
3255
|
+
const text = formatCopyCellText(
|
|
3008
3256
|
rowData,
|
|
3009
3257
|
column.columnDef,
|
|
3010
3258
|
resolveCopyColumnId(sourceCell ?? templateCell),
|
|
@@ -3014,6 +3262,8 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
|
|
|
3014
3262
|
visibleRow != null ? { rowIndex: visibleRow.index, colIndex: startCol + colOffset } : void 0,
|
|
3015
3263
|
options
|
|
3016
3264
|
);
|
|
3265
|
+
const escaped = options?.escapeFormulas ? escapeSpreadsheetFormula(text) : text;
|
|
3266
|
+
return quoteTsvCell(escaped);
|
|
3017
3267
|
}).join(" ");
|
|
3018
3268
|
return `${" ".repeat(relativeDepth)}${line}`;
|
|
3019
3269
|
}).join("\n");
|
|
@@ -3028,15 +3278,78 @@ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options)
|
|
|
3028
3278
|
options
|
|
3029
3279
|
);
|
|
3030
3280
|
}
|
|
3281
|
+
function writeTextWithExecCommand(text) {
|
|
3282
|
+
if (typeof document === "undefined") return false;
|
|
3283
|
+
const textarea = document.createElement("textarea");
|
|
3284
|
+
textarea.value = text;
|
|
3285
|
+
textarea.setAttribute("readonly", "");
|
|
3286
|
+
textarea.style.position = "fixed";
|
|
3287
|
+
textarea.style.top = "0";
|
|
3288
|
+
textarea.style.left = "0";
|
|
3289
|
+
textarea.style.opacity = "0";
|
|
3290
|
+
textarea.style.pointerEvents = "none";
|
|
3291
|
+
document.body.appendChild(textarea);
|
|
3292
|
+
const previouslyFocused = document.activeElement;
|
|
3293
|
+
try {
|
|
3294
|
+
textarea.focus();
|
|
3295
|
+
textarea.select();
|
|
3296
|
+
return document.execCommand("copy");
|
|
3297
|
+
} catch {
|
|
3298
|
+
return false;
|
|
3299
|
+
} finally {
|
|
3300
|
+
document.body.removeChild(textarea);
|
|
3301
|
+
previouslyFocused?.focus?.();
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3031
3304
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
3032
3305
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
3033
3306
|
if (!text) return false;
|
|
3307
|
+
if (mode === "subtree") rememberSubtreeCopy(text);
|
|
3308
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
3309
|
+
return writeTextWithExecCommand(text);
|
|
3310
|
+
}
|
|
3034
3311
|
try {
|
|
3035
3312
|
await navigator.clipboard.writeText(text);
|
|
3313
|
+
return true;
|
|
3036
3314
|
} catch {
|
|
3037
3315
|
return false;
|
|
3038
3316
|
}
|
|
3039
|
-
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3320
|
+
import { useCallback as useCallback3, useEffect as useEffect5, useMemo as useMemo3, useRef as useRef5, useState as useState3 } from "react";
|
|
3321
|
+
|
|
3322
|
+
// src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
|
|
3323
|
+
var activeOwner = null;
|
|
3324
|
+
var clearByOwner = /* @__PURE__ */ new Map();
|
|
3325
|
+
function createCellSelectionOwner() {
|
|
3326
|
+
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
3327
|
+
}
|
|
3328
|
+
function registerCellSelectionOwner(owner, clearSelection) {
|
|
3329
|
+
clearByOwner.set(owner, clearSelection);
|
|
3330
|
+
return () => {
|
|
3331
|
+
clearByOwner.delete(owner);
|
|
3332
|
+
if (activeOwner === owner) {
|
|
3333
|
+
activeOwner = null;
|
|
3334
|
+
}
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
3337
|
+
function claimCellSelectionOwner(owner) {
|
|
3338
|
+
if (activeOwner === owner) return;
|
|
3339
|
+
activeOwner = owner;
|
|
3340
|
+
for (const [id, clearSelection] of clearByOwner) {
|
|
3341
|
+
if (id !== owner) {
|
|
3342
|
+
clearSelection();
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
function isActiveCellSelectionOwner(owner) {
|
|
3347
|
+
return activeOwner === owner;
|
|
3348
|
+
}
|
|
3349
|
+
function releaseCellSelectionOwner(owner) {
|
|
3350
|
+
if (activeOwner === owner) {
|
|
3351
|
+
activeOwner = null;
|
|
3352
|
+
}
|
|
3040
3353
|
}
|
|
3041
3354
|
|
|
3042
3355
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
@@ -3061,6 +3374,8 @@ function collectFillTargets(rows, sourceBounds, fillBounds) {
|
|
|
3061
3374
|
const targetCell = targetRow?.getVisibleCells()[colIndex];
|
|
3062
3375
|
const sourceCell = rows[sourceRowIndex]?.getVisibleCells()[sourceColIndex];
|
|
3063
3376
|
if (!targetRow || !targetCell || !sourceCell) continue;
|
|
3377
|
+
if (!isColumnEditable(targetCell.column.columnDef)) continue;
|
|
3378
|
+
if (isProtectedColumn(sourceCell.column.columnDef)) continue;
|
|
3064
3379
|
const accessorKey = getColumnAccessorKey2(
|
|
3065
3380
|
targetCell.column.columnDef
|
|
3066
3381
|
);
|
|
@@ -3082,13 +3397,22 @@ function collectFillChanges(rows, sourceBounds, fillBounds) {
|
|
|
3082
3397
|
);
|
|
3083
3398
|
}
|
|
3084
3399
|
function applyFillData(data, rows, sourceBounds, fillBounds) {
|
|
3085
|
-
const newData = data.map((row) => ({ ...row }));
|
|
3086
3400
|
const targets = collectFillTargets(rows, sourceBounds, fillBounds);
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3401
|
+
return applyCellChangesToData(
|
|
3402
|
+
data,
|
|
3403
|
+
targets.flatMap((target) => {
|
|
3404
|
+
const row = rows[target.rowIndex];
|
|
3405
|
+
if (!row) return [];
|
|
3406
|
+
return [
|
|
3407
|
+
{
|
|
3408
|
+
original: row.original,
|
|
3409
|
+
index: row.index,
|
|
3410
|
+
accessorKey: target.accessorKey,
|
|
3411
|
+
value: target.value
|
|
3412
|
+
}
|
|
3413
|
+
];
|
|
3414
|
+
})
|
|
3415
|
+
);
|
|
3092
3416
|
}
|
|
3093
3417
|
function hasFillExtension(sourceBounds, fillBounds) {
|
|
3094
3418
|
if (!sourceBounds) return false;
|
|
@@ -3109,14 +3433,59 @@ function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
|
3109
3433
|
if (firstDepth !== 0) return false;
|
|
3110
3434
|
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
3111
3435
|
}
|
|
3112
|
-
function
|
|
3436
|
+
function splitTSV(text) {
|
|
3437
|
+
const rows = [];
|
|
3438
|
+
let row = [];
|
|
3439
|
+
let index = 0;
|
|
3440
|
+
while (index <= text.length) {
|
|
3441
|
+
let cell = "";
|
|
3442
|
+
if (text[index] === '"') {
|
|
3443
|
+
index += 1;
|
|
3444
|
+
while (index < text.length) {
|
|
3445
|
+
const char = text[index];
|
|
3446
|
+
if (char === '"') {
|
|
3447
|
+
if (text[index + 1] === '"') {
|
|
3448
|
+
cell += '"';
|
|
3449
|
+
index += 2;
|
|
3450
|
+
continue;
|
|
3451
|
+
}
|
|
3452
|
+
index += 1;
|
|
3453
|
+
break;
|
|
3454
|
+
}
|
|
3455
|
+
cell += char;
|
|
3456
|
+
index += 1;
|
|
3457
|
+
}
|
|
3458
|
+
while (index < text.length && text[index] !== " " && text[index] !== "\n") {
|
|
3459
|
+
cell += text[index];
|
|
3460
|
+
index += 1;
|
|
3461
|
+
}
|
|
3462
|
+
} else {
|
|
3463
|
+
while (index < text.length && text[index] !== " " && text[index] !== "\n") {
|
|
3464
|
+
cell += text[index];
|
|
3465
|
+
index += 1;
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
row.push(cell);
|
|
3469
|
+
if (index >= text.length) {
|
|
3470
|
+
rows.push(row);
|
|
3471
|
+
break;
|
|
3472
|
+
}
|
|
3473
|
+
if (text[index] === "\n") {
|
|
3474
|
+
rows.push(row);
|
|
3475
|
+
row = [];
|
|
3476
|
+
}
|
|
3477
|
+
index += 1;
|
|
3478
|
+
}
|
|
3479
|
+
return rows;
|
|
3480
|
+
}
|
|
3481
|
+
function parseClipboardTSVWithDepths(text, options) {
|
|
3113
3482
|
if (!text) return { values: [], depths: [] };
|
|
3114
3483
|
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
3115
3484
|
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
3116
3485
|
if (!withoutTrailing) return { values: [], depths: [] };
|
|
3117
|
-
const rows = withoutTrailing
|
|
3486
|
+
const rows = splitTSV(withoutTrailing);
|
|
3118
3487
|
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
3119
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3488
|
+
const treatAsDepth = options?.treeDepth !== "none" && looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3120
3489
|
const values = [];
|
|
3121
3490
|
const depths = [];
|
|
3122
3491
|
for (let index = 0; index < rows.length; index += 1) {
|
|
@@ -3143,8 +3512,8 @@ function resolvePasteColumnIds(rows, startCol, width) {
|
|
|
3143
3512
|
}
|
|
3144
3513
|
return columnIds;
|
|
3145
3514
|
}
|
|
3146
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
3147
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
3515
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow, options) {
|
|
3516
|
+
const { values, depths } = parseClipboardTSVWithDepths(text, options);
|
|
3148
3517
|
if (values.length === 0) return null;
|
|
3149
3518
|
const width = Math.max(...values.map((row) => row.length), 0);
|
|
3150
3519
|
if (width === 0) return null;
|
|
@@ -3177,6 +3546,19 @@ function isEditablePasteTarget(target) {
|
|
|
3177
3546
|
}
|
|
3178
3547
|
|
|
3179
3548
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3549
|
+
var INTERACTIVE_FOCUS_SELECTOR = "button, a[href], input, textarea, select, [contenteditable]:not([contenteditable='false'])";
|
|
3550
|
+
function isInteractiveFocus() {
|
|
3551
|
+
const active = document.activeElement;
|
|
3552
|
+
return active instanceof Element && active.matches(INTERACTIVE_FOCUS_SELECTOR);
|
|
3553
|
+
}
|
|
3554
|
+
function hasPageTextSelectionOutside(root) {
|
|
3555
|
+
if (typeof window.getSelection !== "function") return false;
|
|
3556
|
+
const selection = window.getSelection();
|
|
3557
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0) return false;
|
|
3558
|
+
if (!selection.toString()) return false;
|
|
3559
|
+
const anchor = selection.anchorNode;
|
|
3560
|
+
return !(root && anchor && root.contains(anchor));
|
|
3561
|
+
}
|
|
3180
3562
|
function isFocusOutsideRoot(rootRef) {
|
|
3181
3563
|
const root = rootRef?.current;
|
|
3182
3564
|
if (!root) return false;
|
|
@@ -3189,29 +3571,50 @@ function useCellSelection({
|
|
|
3189
3571
|
rows,
|
|
3190
3572
|
enabled = true,
|
|
3191
3573
|
columnCount = 0,
|
|
3574
|
+
columnSignature,
|
|
3192
3575
|
enableSubtreeCopy = false,
|
|
3576
|
+
escapeCopyFormulas = false,
|
|
3193
3577
|
enableInsertPaste = true,
|
|
3194
3578
|
onDataChange,
|
|
3195
3579
|
onBatchChange,
|
|
3196
3580
|
onRowsPaste,
|
|
3197
3581
|
onCellNavigate,
|
|
3198
3582
|
cellRendererRegistry,
|
|
3199
|
-
rootRef
|
|
3583
|
+
rootRef,
|
|
3584
|
+
enableWasdNavigation = true,
|
|
3585
|
+
onEditKey,
|
|
3586
|
+
onClearKey
|
|
3200
3587
|
}) {
|
|
3201
3588
|
const ownerRef = useRef5(createCellSelectionOwner());
|
|
3202
3589
|
const [dragState, setDragState] = useState3(INITIAL_DRAG_STATE);
|
|
3203
3590
|
const pendingPasteModeRef = useRef5(null);
|
|
3204
3591
|
const dragStateRef = useRef5(dragState);
|
|
3205
3592
|
const onCellNavigateRef = useRef5(onCellNavigate);
|
|
3593
|
+
const onEditKeyRef = useRef5(onEditKey);
|
|
3594
|
+
const onClearKeyRef = useRef5(onClearKey);
|
|
3206
3595
|
dragStateRef.current = dragState;
|
|
3207
3596
|
onCellNavigateRef.current = onCellNavigate;
|
|
3208
|
-
|
|
3209
|
-
|
|
3597
|
+
onEditKeyRef.current = onEditKey;
|
|
3598
|
+
onClearKeyRef.current = onClearKey;
|
|
3599
|
+
const updateDragState = useCallback3((update) => {
|
|
3600
|
+
const prev = dragStateRef.current;
|
|
3601
|
+
const next = update(prev);
|
|
3602
|
+
if (next === prev) return;
|
|
3603
|
+
dragStateRef.current = next;
|
|
3604
|
+
setDragState(next);
|
|
3605
|
+
}, []);
|
|
3606
|
+
const activeSelectionBounds = useMemo3(() => {
|
|
3607
|
+
if (!enabled) return null;
|
|
3608
|
+
return getActiveSelectionBounds(
|
|
3609
|
+
dragState,
|
|
3610
|
+
getCellSelectionBounds(dragState.start, dragState.end)
|
|
3611
|
+
);
|
|
3612
|
+
}, [dragState, enabled]);
|
|
3210
3613
|
const handleCellMouseDown = useCallback3(
|
|
3211
3614
|
(rowIndex, colIndex, options) => {
|
|
3212
3615
|
if (!enabled) return;
|
|
3213
3616
|
claimCellSelectionOwner(ownerRef.current);
|
|
3214
|
-
|
|
3617
|
+
updateDragState((prev) => {
|
|
3215
3618
|
if (options?.shiftKey && prev.start) {
|
|
3216
3619
|
return {
|
|
3217
3620
|
...prev,
|
|
@@ -3232,28 +3635,30 @@ function useCellSelection({
|
|
|
3232
3635
|
};
|
|
3233
3636
|
});
|
|
3234
3637
|
},
|
|
3235
|
-
[enabled]
|
|
3638
|
+
[enabled, updateDragState]
|
|
3236
3639
|
);
|
|
3237
3640
|
const handleCellMouseEnter = useCallback3(
|
|
3238
3641
|
(rowIndex, colIndex) => {
|
|
3239
3642
|
if (!enabled) return;
|
|
3240
|
-
|
|
3643
|
+
updateDragState((prev) => {
|
|
3241
3644
|
if (prev.isSelecting) {
|
|
3645
|
+
if (prev.end?.row === rowIndex && prev.end.col === colIndex) return prev;
|
|
3242
3646
|
return { ...prev, end: { row: rowIndex, col: colIndex } };
|
|
3243
3647
|
}
|
|
3244
3648
|
if (prev.isFillDragging) {
|
|
3649
|
+
if (prev.fillEnd?.row === rowIndex && prev.fillEnd.col === colIndex) return prev;
|
|
3245
3650
|
return { ...prev, fillEnd: { row: rowIndex, col: colIndex } };
|
|
3246
3651
|
}
|
|
3247
3652
|
return prev;
|
|
3248
3653
|
});
|
|
3249
3654
|
},
|
|
3250
|
-
[enabled]
|
|
3655
|
+
[enabled, updateDragState]
|
|
3251
3656
|
);
|
|
3252
3657
|
const handleFillHandleMouseDown = useCallback3(
|
|
3253
3658
|
(rowIndex, colIndex) => {
|
|
3254
3659
|
if (!enabled) return;
|
|
3255
3660
|
claimCellSelectionOwner(ownerRef.current);
|
|
3256
|
-
|
|
3661
|
+
updateDragState((prev) => {
|
|
3257
3662
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
3258
3663
|
if (!bounds) return prev;
|
|
3259
3664
|
return {
|
|
@@ -3265,7 +3670,7 @@ function useCellSelection({
|
|
|
3265
3670
|
};
|
|
3266
3671
|
});
|
|
3267
3672
|
},
|
|
3268
|
-
[enabled]
|
|
3673
|
+
[enabled, updateDragState]
|
|
3269
3674
|
);
|
|
3270
3675
|
const clearSelection = useCallback3(() => {
|
|
3271
3676
|
const prev = dragStateRef.current;
|
|
@@ -3284,6 +3689,130 @@ function useCellSelection({
|
|
|
3284
3689
|
useEffect5(() => {
|
|
3285
3690
|
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
3286
3691
|
}, [clearSelection]);
|
|
3692
|
+
const previousColumnSignatureRef = useRef5(columnSignature);
|
|
3693
|
+
useEffect5(() => {
|
|
3694
|
+
const columnsChanged = columnSignature !== void 0 && previousColumnSignatureRef.current !== void 0 && previousColumnSignatureRef.current !== columnSignature;
|
|
3695
|
+
previousColumnSignatureRef.current = columnSignature;
|
|
3696
|
+
const prev = dragStateRef.current;
|
|
3697
|
+
if (!prev.start || !prev.end) return;
|
|
3698
|
+
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
3699
|
+
const resolvedColumnCount = columnCount > 0 ? columnCount : rows[0]?.getVisibleCells().length ?? 0;
|
|
3700
|
+
const outOfRange = bounds !== null && (bounds.endRow >= rows.length || resolvedColumnCount > 0 && bounds.endCol >= resolvedColumnCount);
|
|
3701
|
+
if (columnsChanged || outOfRange) {
|
|
3702
|
+
clearSelection();
|
|
3703
|
+
}
|
|
3704
|
+
}, [clearSelection, columnCount, columnSignature, rows]);
|
|
3705
|
+
useEffect5(() => {
|
|
3706
|
+
if (!enabled) return;
|
|
3707
|
+
const handlePointerDown = (event) => {
|
|
3708
|
+
const root = rootRef?.current;
|
|
3709
|
+
if (!root || !isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3710
|
+
if (event.target instanceof Node && root.contains(event.target)) return;
|
|
3711
|
+
releaseCellSelectionOwner(ownerRef.current);
|
|
3712
|
+
};
|
|
3713
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
3714
|
+
document.addEventListener("mousedown", handlePointerDown, true);
|
|
3715
|
+
return () => {
|
|
3716
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
3717
|
+
document.removeEventListener("mousedown", handlePointerDown, true);
|
|
3718
|
+
};
|
|
3719
|
+
}, [enabled, rootRef]);
|
|
3720
|
+
const getColumnCount = useCallback3(
|
|
3721
|
+
() => columnCount > 0 ? columnCount : rows[0]?.getVisibleCells().length ?? 0,
|
|
3722
|
+
[columnCount, rows]
|
|
3723
|
+
);
|
|
3724
|
+
const selectCell = useCallback3(
|
|
3725
|
+
(row, col) => {
|
|
3726
|
+
if (!enabled) return;
|
|
3727
|
+
const resolvedColumnCount = getColumnCount();
|
|
3728
|
+
if (rows.length <= 0 || resolvedColumnCount <= 0) return;
|
|
3729
|
+
const position = clampCellPosition({ row, col }, rows.length, resolvedColumnCount);
|
|
3730
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
3731
|
+
const nextState = {
|
|
3732
|
+
isSelecting: false,
|
|
3733
|
+
isFillDragging: false,
|
|
3734
|
+
start: position,
|
|
3735
|
+
end: position,
|
|
3736
|
+
fillAnchor: null,
|
|
3737
|
+
fillEnd: null
|
|
3738
|
+
};
|
|
3739
|
+
dragStateRef.current = nextState;
|
|
3740
|
+
setDragState(nextState);
|
|
3741
|
+
onCellNavigateRef.current?.(position);
|
|
3742
|
+
},
|
|
3743
|
+
[enabled, getColumnCount, rows.length]
|
|
3744
|
+
);
|
|
3745
|
+
const focusSelection = useCallback3(() => {
|
|
3746
|
+
if (!enabled) return;
|
|
3747
|
+
const prev = dragStateRef.current;
|
|
3748
|
+
if (prev.start && prev.end) {
|
|
3749
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
3750
|
+
return;
|
|
3751
|
+
}
|
|
3752
|
+
selectCell(0, 0);
|
|
3753
|
+
}, [enabled, selectCell]);
|
|
3754
|
+
useEffect5(() => {
|
|
3755
|
+
if (!enabled) return;
|
|
3756
|
+
const handleKeyDown = (e) => {
|
|
3757
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3758
|
+
if (e.altKey) return;
|
|
3759
|
+
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3760
|
+
return;
|
|
3761
|
+
}
|
|
3762
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3763
|
+
const prev = dragStateRef.current;
|
|
3764
|
+
if (!prev.start || !prev.end) return;
|
|
3765
|
+
if (prev.isSelecting || prev.isFillDragging) return;
|
|
3766
|
+
const rowCount = rows.length;
|
|
3767
|
+
const resolvedColumnCount = getColumnCount();
|
|
3768
|
+
if (rowCount <= 0 || resolvedColumnCount <= 0) return;
|
|
3769
|
+
const withModifier = e.ctrlKey || e.metaKey;
|
|
3770
|
+
if (withModifier && !e.shiftKey && e.key.toLowerCase() === "a") {
|
|
3771
|
+
e.preventDefault();
|
|
3772
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
3773
|
+
const nextState = {
|
|
3774
|
+
isSelecting: false,
|
|
3775
|
+
isFillDragging: false,
|
|
3776
|
+
start: { row: 0, col: 0 },
|
|
3777
|
+
end: { row: rowCount - 1, col: resolvedColumnCount - 1 },
|
|
3778
|
+
fillAnchor: null,
|
|
3779
|
+
fillEnd: null
|
|
3780
|
+
};
|
|
3781
|
+
dragStateRef.current = nextState;
|
|
3782
|
+
setDragState(nextState);
|
|
3783
|
+
return;
|
|
3784
|
+
}
|
|
3785
|
+
if (e.key === "Home" || e.key === "End") {
|
|
3786
|
+
e.preventDefault();
|
|
3787
|
+
const toEnd = e.key === "End";
|
|
3788
|
+
const target = withModifier ? toEnd ? { row: rowCount - 1, col: resolvedColumnCount - 1 } : { row: 0, col: 0 } : { row: prev.end.row, col: toEnd ? resolvedColumnCount - 1 : 0 };
|
|
3789
|
+
if (e.shiftKey) {
|
|
3790
|
+
const nextState = { ...prev, end: target, fillAnchor: null, fillEnd: null };
|
|
3791
|
+
dragStateRef.current = nextState;
|
|
3792
|
+
setDragState(nextState);
|
|
3793
|
+
onCellNavigateRef.current?.(target);
|
|
3794
|
+
} else {
|
|
3795
|
+
selectCell(target.row, target.col);
|
|
3796
|
+
}
|
|
3797
|
+
return;
|
|
3798
|
+
}
|
|
3799
|
+
if (withModifier || isInteractiveFocus()) return;
|
|
3800
|
+
if (e.key === "Enter" || e.key === "F2") {
|
|
3801
|
+
if (!onEditKeyRef.current) return;
|
|
3802
|
+
e.preventDefault();
|
|
3803
|
+
onEditKeyRef.current(prev.end);
|
|
3804
|
+
return;
|
|
3805
|
+
}
|
|
3806
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
3807
|
+
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
3808
|
+
if (!bounds || !onClearKeyRef.current) return;
|
|
3809
|
+
e.preventDefault();
|
|
3810
|
+
onClearKeyRef.current(bounds);
|
|
3811
|
+
}
|
|
3812
|
+
};
|
|
3813
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
3814
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3815
|
+
}, [enabled, getColumnCount, rootRef, rows.length, selectCell]);
|
|
3287
3816
|
useEffect5(() => {
|
|
3288
3817
|
if (!enabled) return;
|
|
3289
3818
|
const handleKeyDown = (e) => {
|
|
@@ -3293,6 +3822,7 @@ function useCellSelection({
|
|
|
3293
3822
|
return;
|
|
3294
3823
|
}
|
|
3295
3824
|
if (isFocusOutsideRoot(rootRef)) return;
|
|
3825
|
+
if (!enableWasdNavigation && e.key.length === 1) return;
|
|
3296
3826
|
const delta = getCellNavigationDelta(e.key);
|
|
3297
3827
|
if (!delta) return;
|
|
3298
3828
|
const prev = dragStateRef.current;
|
|
@@ -3332,14 +3862,15 @@ function useCellSelection({
|
|
|
3332
3862
|
};
|
|
3333
3863
|
window.addEventListener("keydown", handleKeyDown);
|
|
3334
3864
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3335
|
-
}, [columnCount, enabled, rows]);
|
|
3865
|
+
}, [columnCount, enableWasdNavigation, enabled, rows]);
|
|
3336
3866
|
const copySelection = useCallback3(
|
|
3337
3867
|
async (options) => {
|
|
3338
3868
|
if (!enabled || !activeSelectionBounds) return false;
|
|
3339
3869
|
const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
|
|
3340
3870
|
return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
|
|
3341
3871
|
registry: cellRendererRegistry,
|
|
3342
|
-
root: rootRef?.current
|
|
3872
|
+
root: rootRef?.current,
|
|
3873
|
+
escapeFormulas: escapeCopyFormulas
|
|
3343
3874
|
});
|
|
3344
3875
|
},
|
|
3345
3876
|
[
|
|
@@ -3347,6 +3878,7 @@ function useCellSelection({
|
|
|
3347
3878
|
cellRendererRegistry,
|
|
3348
3879
|
enableSubtreeCopy,
|
|
3349
3880
|
enabled,
|
|
3881
|
+
escapeCopyFormulas,
|
|
3350
3882
|
rootRef,
|
|
3351
3883
|
rows
|
|
3352
3884
|
]
|
|
@@ -3364,6 +3896,7 @@ function useCellSelection({
|
|
|
3364
3896
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
3365
3897
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
3366
3898
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
3899
|
+
if (hasPageTextSelectionOutside(rootRef?.current)) return;
|
|
3367
3900
|
e.preventDefault();
|
|
3368
3901
|
void copySelection({ includeDescendants: isSubtreeShortcut });
|
|
3369
3902
|
};
|
|
@@ -3379,9 +3912,17 @@ function useCellSelection({
|
|
|
3379
3912
|
activeSelectionBounds.startCol,
|
|
3380
3913
|
text,
|
|
3381
3914
|
mode,
|
|
3382
|
-
activeSelectionBounds.endRow
|
|
3915
|
+
activeSelectionBounds.endRow,
|
|
3916
|
+
// Leading blank cells are tree depth only in this table's own subtree
|
|
3917
|
+
// copy; from a spreadsheet they are real (empty) cells.
|
|
3918
|
+
{ treeDepth: isOwnSubtreeCopy(text) ? "auto" : "none" }
|
|
3383
3919
|
);
|
|
3384
3920
|
if (!payload) return false;
|
|
3921
|
+
const cells = rows[activeSelectionBounds.startRow]?.getVisibleCells() ?? [];
|
|
3922
|
+
payload.editableColumnIds = payload.columnIds.filter((columnId) => {
|
|
3923
|
+
const cell = cells.find((item) => item.column.id === columnId);
|
|
3924
|
+
return cell ? isColumnEditable(cell.column.columnDef) : false;
|
|
3925
|
+
});
|
|
3385
3926
|
onRowsPaste(payload);
|
|
3386
3927
|
return true;
|
|
3387
3928
|
},
|
|
@@ -3412,7 +3953,10 @@ function useCellSelection({
|
|
|
3412
3953
|
void (async () => {
|
|
3413
3954
|
try {
|
|
3414
3955
|
const text = await navigator.clipboard.readText();
|
|
3415
|
-
if (pasteHandledRef.current)
|
|
3956
|
+
if (pasteHandledRef.current) {
|
|
3957
|
+
pasteHandledRef.current = false;
|
|
3958
|
+
return;
|
|
3959
|
+
}
|
|
3416
3960
|
if (pendingPasteModeRef.current !== mode) return;
|
|
3417
3961
|
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3418
3962
|
if (!text) return;
|
|
@@ -3437,6 +3981,7 @@ function useCellSelection({
|
|
|
3437
3981
|
}
|
|
3438
3982
|
const mode = pendingPasteModeRef.current ?? "overwrite";
|
|
3439
3983
|
if (pasteHandledRef.current) {
|
|
3984
|
+
pasteHandledRef.current = false;
|
|
3440
3985
|
e.preventDefault();
|
|
3441
3986
|
return;
|
|
3442
3987
|
}
|
|
@@ -3463,39 +4008,41 @@ function useCellSelection({
|
|
|
3463
4008
|
useEffect5(() => {
|
|
3464
4009
|
if (!enabled) return;
|
|
3465
4010
|
const handleMouseUp = () => {
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
} else if (onDataChange) {
|
|
3478
|
-
onDataChange(applyFillData(data, rows, sourceBounds, newBounds));
|
|
4011
|
+
const prev = dragStateRef.current;
|
|
4012
|
+
let next = prev;
|
|
4013
|
+
if (prev.isFillDragging && prev.fillEnd) {
|
|
4014
|
+
const sourceBounds = getCellSelectionBounds(prev.start, prev.end);
|
|
4015
|
+
if (sourceBounds) {
|
|
4016
|
+
const newBounds = resolveFillBounds(sourceBounds, prev.fillEnd);
|
|
4017
|
+
if (hasFillExtension(sourceBounds, newBounds)) {
|
|
4018
|
+
if (onBatchChange) {
|
|
4019
|
+
const changes = collectFillChanges(rows, sourceBounds, newBounds);
|
|
4020
|
+
if (changes.length > 0) {
|
|
4021
|
+
onBatchChange(changes);
|
|
3479
4022
|
}
|
|
4023
|
+
} else if (onDataChange) {
|
|
4024
|
+
onDataChange(applyFillData(data, rows, sourceBounds, newBounds));
|
|
3480
4025
|
}
|
|
3481
|
-
return {
|
|
3482
|
-
isSelecting: false,
|
|
3483
|
-
isFillDragging: false,
|
|
3484
|
-
start: { row: newBounds.startRow, col: newBounds.startCol },
|
|
3485
|
-
end: { row: newBounds.endRow, col: newBounds.endCol },
|
|
3486
|
-
fillAnchor: null,
|
|
3487
|
-
fillEnd: null
|
|
3488
|
-
};
|
|
3489
4026
|
}
|
|
4027
|
+
next = {
|
|
4028
|
+
isSelecting: false,
|
|
4029
|
+
isFillDragging: false,
|
|
4030
|
+
start: { row: newBounds.startRow, col: newBounds.startCol },
|
|
4031
|
+
end: { row: newBounds.endRow, col: newBounds.endCol },
|
|
4032
|
+
fillAnchor: null,
|
|
4033
|
+
fillEnd: null
|
|
4034
|
+
};
|
|
4035
|
+
} else {
|
|
4036
|
+
next = { ...prev, isFillDragging: false, fillAnchor: null, fillEnd: null };
|
|
3490
4037
|
}
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
4038
|
+
} else if (prev.isSelecting) {
|
|
4039
|
+
next = { ...prev, isSelecting: false };
|
|
4040
|
+
} else if (prev.isFillDragging) {
|
|
4041
|
+
next = { ...prev, isFillDragging: false, fillAnchor: null, fillEnd: null };
|
|
4042
|
+
}
|
|
4043
|
+
if (next === prev) return;
|
|
4044
|
+
dragStateRef.current = next;
|
|
4045
|
+
setDragState(next);
|
|
3499
4046
|
};
|
|
3500
4047
|
window.addEventListener("mouseup", handleMouseUp);
|
|
3501
4048
|
return () => window.removeEventListener("mouseup", handleMouseUp);
|
|
@@ -3507,7 +4054,9 @@ function useCellSelection({
|
|
|
3507
4054
|
handleCellMouseEnter,
|
|
3508
4055
|
handleFillHandleMouseDown,
|
|
3509
4056
|
clearSelection,
|
|
3510
|
-
copySelection
|
|
4057
|
+
copySelection,
|
|
4058
|
+
selectCell,
|
|
4059
|
+
focusSelection
|
|
3511
4060
|
};
|
|
3512
4061
|
}
|
|
3513
4062
|
|
|
@@ -3542,8 +4091,12 @@ function handleEscape(event) {
|
|
|
3542
4091
|
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3543
4092
|
return;
|
|
3544
4093
|
}
|
|
3545
|
-
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
3546
|
-
|
|
4094
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
4095
|
+
try {
|
|
4096
|
+
clearAllSelections();
|
|
4097
|
+
} catch (error) {
|
|
4098
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
4099
|
+
}
|
|
3547
4100
|
}
|
|
3548
4101
|
}
|
|
3549
4102
|
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
@@ -3566,16 +4119,35 @@ import {
|
|
|
3566
4119
|
useCallback as useCallback4,
|
|
3567
4120
|
useEffect as useEffect6,
|
|
3568
4121
|
useId,
|
|
3569
|
-
useMemo as
|
|
4122
|
+
useMemo as useMemo4,
|
|
3570
4123
|
useRef as useRef6,
|
|
3571
4124
|
useState as useState4
|
|
3572
4125
|
} from "react";
|
|
3573
4126
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
4127
|
+
var searchInstanceCount = 0;
|
|
4128
|
+
var lastPointerTarget = null;
|
|
4129
|
+
function trackPointerTarget(event) {
|
|
4130
|
+
lastPointerTarget = event.target;
|
|
4131
|
+
}
|
|
4132
|
+
function registerSearchInstance() {
|
|
4133
|
+
if (searchInstanceCount === 0) {
|
|
4134
|
+
document.addEventListener("pointerdown", trackPointerTarget, true);
|
|
4135
|
+
}
|
|
4136
|
+
searchInstanceCount += 1;
|
|
4137
|
+
return () => {
|
|
4138
|
+
searchInstanceCount -= 1;
|
|
4139
|
+
if (searchInstanceCount === 0) {
|
|
4140
|
+
document.removeEventListener("pointerdown", trackPointerTarget, true);
|
|
4141
|
+
lastPointerTarget = null;
|
|
4142
|
+
}
|
|
4143
|
+
};
|
|
4144
|
+
}
|
|
3574
4145
|
function useInlineSearch({
|
|
3575
4146
|
enabled = false,
|
|
3576
4147
|
rowCount,
|
|
3577
4148
|
columnCount,
|
|
3578
4149
|
getCellValue,
|
|
4150
|
+
contentKey,
|
|
3579
4151
|
initialStartRow = 0,
|
|
3580
4152
|
showSearch: controlledShowSearch,
|
|
3581
4153
|
searchValue: controlledSearchValue,
|
|
@@ -3784,6 +4356,7 @@ function useInlineSearch({
|
|
|
3784
4356
|
}
|
|
3785
4357
|
beginSearch(searchValue);
|
|
3786
4358
|
}, [
|
|
4359
|
+
contentKey,
|
|
3787
4360
|
beginSearch,
|
|
3788
4361
|
cancelSearch,
|
|
3789
4362
|
controlledSearchResults,
|
|
@@ -3804,6 +4377,9 @@ function useInlineSearch({
|
|
|
3804
4377
|
if (!focusInside && active !== document.body) {
|
|
3805
4378
|
return;
|
|
3806
4379
|
}
|
|
4380
|
+
if (!focusInside && !(lastPointerTarget instanceof Node && root.contains(lastPointerTarget))) {
|
|
4381
|
+
return;
|
|
4382
|
+
}
|
|
3807
4383
|
}
|
|
3808
4384
|
event.preventDefault();
|
|
3809
4385
|
event.stopPropagation();
|
|
@@ -3817,14 +4393,18 @@ function useInlineSearch({
|
|
|
3817
4393
|
}
|
|
3818
4394
|
};
|
|
3819
4395
|
window.addEventListener("keydown", handleKeyDown, true);
|
|
3820
|
-
|
|
4396
|
+
const releaseInstance = registerSearchInstance();
|
|
4397
|
+
return () => {
|
|
4398
|
+
window.removeEventListener("keydown", handleKeyDown, true);
|
|
4399
|
+
releaseInstance();
|
|
4400
|
+
};
|
|
3821
4401
|
}, [controlledShowSearch, enabled, rootRef, showSearch]);
|
|
3822
4402
|
useEffect6(() => () => cancelSearch(), [cancelSearch]);
|
|
3823
|
-
const searchMatchKeys =
|
|
4403
|
+
const searchMatchKeys = useMemo4(
|
|
3824
4404
|
() => buildSearchMatchKeys(searchResults),
|
|
3825
4405
|
[searchResults]
|
|
3826
4406
|
);
|
|
3827
|
-
const activeMatch =
|
|
4407
|
+
const activeMatch = useMemo4(() => {
|
|
3828
4408
|
if (!searchStatus || searchStatus.selectedIndex < 0) return null;
|
|
3829
4409
|
return searchResults[searchStatus.selectedIndex] ?? null;
|
|
3830
4410
|
}, [searchResults, searchStatus]);
|
|
@@ -3894,7 +4474,11 @@ var DEFAULT_DATA_TABLE_LABELS = {
|
|
|
3894
4474
|
searchResultHint: "Type to search",
|
|
3895
4475
|
searchPrevious: "Previous result",
|
|
3896
4476
|
searchNext: "Next result",
|
|
3897
|
-
searchClose: "Close search"
|
|
4477
|
+
searchClose: "Close search",
|
|
4478
|
+
searchResultCount: formatSearchResultLabel,
|
|
4479
|
+
protectedCell: "protected",
|
|
4480
|
+
paginationPrevious: "Previous page",
|
|
4481
|
+
paginationNext: "Next page"
|
|
3898
4482
|
};
|
|
3899
4483
|
function resolveDataTableLabels(partial) {
|
|
3900
4484
|
return {
|
|
@@ -3904,6 +4488,9 @@ function resolveDataTableLabels(partial) {
|
|
|
3904
4488
|
}
|
|
3905
4489
|
|
|
3906
4490
|
// src/core/useGlideTable.ts
|
|
4491
|
+
function isProductionBuild() {
|
|
4492
|
+
return typeof process !== "undefined" && process?.env?.NODE_ENV === "production";
|
|
4493
|
+
}
|
|
3907
4494
|
var EMPTY_COLUMN_FREEZE_OFFSETS = /* @__PURE__ */ new Map();
|
|
3908
4495
|
var EMPTY_SEARCH_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
3909
4496
|
function useGlideTable(options) {
|
|
@@ -3925,18 +4512,24 @@ function useGlideTable(options) {
|
|
|
3925
4512
|
selectOnRowClick = true,
|
|
3926
4513
|
enableCellSelection = true,
|
|
3927
4514
|
onDataChange,
|
|
3928
|
-
onCellChange,
|
|
3929
|
-
onBatchChange,
|
|
4515
|
+
onCellChange: onCellChangeProp,
|
|
4516
|
+
onBatchChange: onBatchChangeProp,
|
|
3930
4517
|
cellRenderers,
|
|
3931
4518
|
preserveRowSelection = false,
|
|
3932
|
-
toggleField,
|
|
3933
|
-
|
|
3934
|
-
|
|
4519
|
+
toggleField: toggleFieldProp,
|
|
4520
|
+
idField,
|
|
4521
|
+
childField: childFieldProp,
|
|
4522
|
+
parentIdField,
|
|
4523
|
+
flattenField: flattenFieldProp,
|
|
4524
|
+
childrenField,
|
|
3935
4525
|
qtyField,
|
|
4526
|
+
expandColumn,
|
|
3936
4527
|
expandedRows: controlledExpandedRows,
|
|
3937
4528
|
onExpandedRowsChange,
|
|
3938
4529
|
preventExpand = false,
|
|
4530
|
+
autoExpandOnLoad = true,
|
|
3939
4531
|
enableSubtreeCopy,
|
|
4532
|
+
escapeCopyFormulas = false,
|
|
3940
4533
|
onCopyActionsReady,
|
|
3941
4534
|
onRowsPaste,
|
|
3942
4535
|
enableInsertPaste,
|
|
@@ -3957,9 +4550,28 @@ function useGlideTable(options) {
|
|
|
3957
4550
|
onSearchValueChange,
|
|
3958
4551
|
onSearchClose,
|
|
3959
4552
|
searchResults,
|
|
3960
|
-
onSearchResultsChanged
|
|
4553
|
+
onSearchResultsChanged,
|
|
4554
|
+
enableWasdNavigation = true
|
|
3961
4555
|
} = options;
|
|
3962
|
-
const
|
|
4556
|
+
const toggleField = toggleFieldProp ?? idField;
|
|
4557
|
+
const childField = childFieldProp ?? parentIdField;
|
|
4558
|
+
const flattenField = flattenFieldProp ?? childrenField;
|
|
4559
|
+
const onCellChange = useMemo5(() => {
|
|
4560
|
+
if (onCellChangeProp) return onCellChangeProp;
|
|
4561
|
+
if (!onBatchChangeProp) return void 0;
|
|
4562
|
+
return (rowId, columnId, value) => onBatchChangeProp([{ rowId, columnId, value }]);
|
|
4563
|
+
}, [onBatchChangeProp, onCellChangeProp]);
|
|
4564
|
+
const onBatchChange = useMemo5(() => {
|
|
4565
|
+
if (onBatchChangeProp) return onBatchChangeProp;
|
|
4566
|
+
if (!onCellChangeProp) return void 0;
|
|
4567
|
+
return (changes) => {
|
|
4568
|
+
for (const change of changes) {
|
|
4569
|
+
onCellChangeProp(change.rowId, change.columnId, change.value);
|
|
4570
|
+
}
|
|
4571
|
+
};
|
|
4572
|
+
}, [onBatchChangeProp, onCellChangeProp]);
|
|
4573
|
+
const hasWriteCallback = Boolean(onCellChange || onBatchChange || onDataChange);
|
|
4574
|
+
const labels = useMemo5(() => {
|
|
3963
4575
|
const resolved = resolveDataTableLabels(labelsProp);
|
|
3964
4576
|
return {
|
|
3965
4577
|
...resolved,
|
|
@@ -3976,11 +4588,11 @@ function useGlideTable(options) {
|
|
|
3976
4588
|
const [internalExpandedRows, setInternalExpandedRows] = useState5(
|
|
3977
4589
|
() => /* @__PURE__ */ new Set()
|
|
3978
4590
|
);
|
|
3979
|
-
const [
|
|
4591
|
+
const [hoverStore] = useState5(createRowHoverStore);
|
|
3980
4592
|
const scrollRef = useRef7(null);
|
|
3981
4593
|
const rootRef = useRef7(null);
|
|
3982
4594
|
const escapeDismissOwnerRef = useRef7(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
3983
|
-
const cellRendererRegistry =
|
|
4595
|
+
const cellRendererRegistry = useMemo5(
|
|
3984
4596
|
() => createCellRendererRegistry(cellRenderers),
|
|
3985
4597
|
[cellRenderers]
|
|
3986
4598
|
);
|
|
@@ -3999,7 +4611,7 @@ function useGlideTable(options) {
|
|
|
3999
4611
|
);
|
|
4000
4612
|
const columnSizing = controlledColumnSizing ?? internalColumnSizing;
|
|
4001
4613
|
const columnOrder = controlledColumnOrder ?? internalColumnOrder;
|
|
4002
|
-
const tableColumns =
|
|
4614
|
+
const tableColumns = useMemo5(() => {
|
|
4003
4615
|
if (!enableColumnReorder) return columns;
|
|
4004
4616
|
return applyLeafColumnOrder(columns, columnOrder);
|
|
4005
4617
|
}, [columnOrder, columns, enableColumnReorder]);
|
|
@@ -4033,8 +4645,10 @@ function useGlideTable(options) {
|
|
|
4033
4645
|
qtyField,
|
|
4034
4646
|
expandedRows,
|
|
4035
4647
|
onExpandedRowsChange: enableExpand ? handleExpandedRowsChange : void 0,
|
|
4036
|
-
preventExpand
|
|
4648
|
+
preventExpand,
|
|
4649
|
+
autoExpandOnLoad
|
|
4037
4650
|
});
|
|
4651
|
+
const sourceData = useMemo5(() => data ?? [], [data]);
|
|
4038
4652
|
const table = useReactTable({
|
|
4039
4653
|
data: tableData,
|
|
4040
4654
|
columns: tableColumns,
|
|
@@ -4073,15 +4687,19 @@ function useGlideTable(options) {
|
|
|
4073
4687
|
);
|
|
4074
4688
|
},
|
|
4075
4689
|
getCoreRowModel: getCoreRowModel(),
|
|
4076
|
-
getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (
|
|
4690
|
+
getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (
|
|
4691
|
+
// Tree rows: their path in the original data, which (unlike the
|
|
4692
|
+
// flattened index) survives expanding/collapsing rows above.
|
|
4693
|
+
(originalRow, index) => getTreeRowKey(originalRow) ?? String(index)
|
|
4694
|
+
)
|
|
4077
4695
|
});
|
|
4078
|
-
const rowSpanColumnKeys =
|
|
4696
|
+
const rowSpanColumnKeys = useMemo5(() => {
|
|
4079
4697
|
if (!enableRowSpan) return [];
|
|
4080
4698
|
return collectRowSpanColumns(columns);
|
|
4081
4699
|
}, [enableRowSpan, columns]);
|
|
4082
4700
|
const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
|
|
4083
4701
|
const primaryRowSpanColumnId = rowSpanColumnKeys[0]?.columnId;
|
|
4084
|
-
const columnRowSpanMap =
|
|
4702
|
+
const columnRowSpanMap = useMemo5(
|
|
4085
4703
|
() => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
|
|
4086
4704
|
[tableData, rowSpanColumnKeys]
|
|
4087
4705
|
);
|
|
@@ -4090,7 +4708,21 @@ function useGlideTable(options) {
|
|
|
4090
4708
|
const rows = table.getRowModel().rows;
|
|
4091
4709
|
const columnCount = table.getAllLeafColumns().length || 1;
|
|
4092
4710
|
const visibleLeafColumns = table.getVisibleLeafColumns();
|
|
4093
|
-
const
|
|
4711
|
+
const canFill = enableCellSelection && hasWriteCallback && visibleLeafColumns.some((column) => isColumnEditable(column.columnDef));
|
|
4712
|
+
const warnedBooleanColumnsRef = useRef7(/* @__PURE__ */ new Set());
|
|
4713
|
+
useEffect7(() => {
|
|
4714
|
+
if (!hasWriteCallback || isProductionBuild()) return;
|
|
4715
|
+
for (const column of visibleLeafColumns) {
|
|
4716
|
+
const meta = column.columnDef.meta;
|
|
4717
|
+
if (meta?.kind !== "boolean" || meta.editable !== void 0 || meta.cellRender) continue;
|
|
4718
|
+
if (warnedBooleanColumnsRef.current.has(column.id)) continue;
|
|
4719
|
+
warnedBooleanColumnsRef.current.add(column.id);
|
|
4720
|
+
console.warn(
|
|
4721
|
+
`[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.`
|
|
4722
|
+
);
|
|
4723
|
+
}
|
|
4724
|
+
}, [hasWriteCallback, visibleLeafColumns]);
|
|
4725
|
+
const columnFreezeOffsets = useMemo5(() => {
|
|
4094
4726
|
if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
|
|
4095
4727
|
return buildColumnFreezeOffsets(
|
|
4096
4728
|
visibleLeafColumns.map((column) => ({
|
|
@@ -4110,7 +4742,7 @@ function useGlideTable(options) {
|
|
|
4110
4742
|
const totalSize = rowVirtualizer.getTotalSize();
|
|
4111
4743
|
const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
|
|
4112
4744
|
const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
|
|
4113
|
-
const selectedRowIndices =
|
|
4745
|
+
const selectedRowIndices = useMemo5(() => {
|
|
4114
4746
|
const indices = /* @__PURE__ */ new Set();
|
|
4115
4747
|
for (const selectedRow of selectedRows) {
|
|
4116
4748
|
indices.add(selectedRow.index);
|
|
@@ -4132,7 +4764,7 @@ function useGlideTable(options) {
|
|
|
4132
4764
|
const cell = scrollElement.querySelector(
|
|
4133
4765
|
`[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
|
|
4134
4766
|
);
|
|
4135
|
-
if (cell instanceof HTMLElement) {
|
|
4767
|
+
if (cell instanceof HTMLElement && typeof cell.scrollIntoView === "function") {
|
|
4136
4768
|
cell.scrollIntoView({ block: blockAlign, inline: "nearest" });
|
|
4137
4769
|
}
|
|
4138
4770
|
};
|
|
@@ -4150,6 +4782,10 @@ function useGlideTable(options) {
|
|
|
4150
4782
|
},
|
|
4151
4783
|
[scrollCellIntoView]
|
|
4152
4784
|
);
|
|
4785
|
+
const editKeyRef = useRef7(() => {
|
|
4786
|
+
});
|
|
4787
|
+
const clearKeyRef = useRef7(() => {
|
|
4788
|
+
});
|
|
4153
4789
|
const {
|
|
4154
4790
|
dragState,
|
|
4155
4791
|
activeSelectionBounds,
|
|
@@ -4157,20 +4793,27 @@ function useGlideTable(options) {
|
|
|
4157
4793
|
handleCellMouseEnter,
|
|
4158
4794
|
handleFillHandleMouseDown,
|
|
4159
4795
|
clearSelection: clearCellSelection,
|
|
4160
|
-
copySelection
|
|
4796
|
+
copySelection,
|
|
4797
|
+
selectCell,
|
|
4798
|
+
focusSelection
|
|
4161
4799
|
} = useCellSelection({
|
|
4162
|
-
data:
|
|
4800
|
+
data: sourceData,
|
|
4163
4801
|
rows,
|
|
4164
4802
|
enabled: enableCellSelection,
|
|
4165
4803
|
columnCount: visibleLeafColumns.length,
|
|
4804
|
+
columnSignature: visibleLeafColumns.map((column) => column.id).join("\0"),
|
|
4166
4805
|
enableSubtreeCopy: resolvedEnableSubtreeCopy,
|
|
4806
|
+
escapeCopyFormulas,
|
|
4167
4807
|
enableInsertPaste: enableInsertPaste ?? true,
|
|
4168
4808
|
onDataChange,
|
|
4169
4809
|
onBatchChange,
|
|
4170
4810
|
onRowsPaste,
|
|
4171
4811
|
onCellNavigate: handleCellNavigate,
|
|
4172
4812
|
cellRendererRegistry,
|
|
4173
|
-
rootRef
|
|
4813
|
+
rootRef,
|
|
4814
|
+
enableWasdNavigation,
|
|
4815
|
+
onEditKey: (position) => editKeyRef.current(position),
|
|
4816
|
+
onClearKey: (bounds) => clearKeyRef.current(bounds)
|
|
4174
4817
|
});
|
|
4175
4818
|
const clearRowSelection = useCallback5(() => {
|
|
4176
4819
|
if (rowSelectionMode === "none") return;
|
|
@@ -4191,22 +4834,79 @@ function useGlideTable(options) {
|
|
|
4191
4834
|
const {
|
|
4192
4835
|
editingCell,
|
|
4193
4836
|
draftValue,
|
|
4837
|
+
draftInvalid,
|
|
4838
|
+
setDraftInvalid,
|
|
4194
4839
|
setDraftValue,
|
|
4195
4840
|
startEdit,
|
|
4196
4841
|
commitEdit,
|
|
4197
4842
|
cancelEdit
|
|
4198
|
-
} = useCellEdit({ data:
|
|
4843
|
+
} = useCellEdit({ data: sourceData, rows, onDataChange, onCellChange });
|
|
4844
|
+
editKeyRef.current = (position) => {
|
|
4845
|
+
startEdit(position.row, position.col);
|
|
4846
|
+
};
|
|
4847
|
+
clearKeyRef.current = (bounds) => {
|
|
4848
|
+
const changes = [];
|
|
4849
|
+
for (let rowIndex = bounds.startRow; rowIndex <= bounds.endRow; rowIndex += 1) {
|
|
4850
|
+
const row = rows[rowIndex];
|
|
4851
|
+
if (!row) continue;
|
|
4852
|
+
const cells = row.getVisibleCells();
|
|
4853
|
+
for (let colIndex = bounds.startCol; colIndex <= bounds.endCol; colIndex += 1) {
|
|
4854
|
+
const cell = cells[colIndex];
|
|
4855
|
+
if (!cell || !isColumnEditable(cell.column.columnDef)) continue;
|
|
4856
|
+
changes.push({ rowId: row.id, columnId: cell.column.id, value: null });
|
|
4857
|
+
}
|
|
4858
|
+
}
|
|
4859
|
+
if (changes.length === 0) return;
|
|
4860
|
+
if (onBatchChange) {
|
|
4861
|
+
onBatchChange(changes);
|
|
4862
|
+
return;
|
|
4863
|
+
}
|
|
4864
|
+
if (!onDataChange) return;
|
|
4865
|
+
let next = sourceData;
|
|
4866
|
+
for (const change of changes) {
|
|
4867
|
+
const row = rows.find((item) => item.id === change.rowId);
|
|
4868
|
+
const cell = row?.getVisibleCells().find((item) => item.column.id === change.columnId);
|
|
4869
|
+
const accessorKey = cell ? getColumnAccessorKey(cell.column.columnDef) : void 0;
|
|
4870
|
+
if (!row || !accessorKey) continue;
|
|
4871
|
+
next = applyCellChangesToData(next, [
|
|
4872
|
+
{ original: row.original, index: row.index, accessorKey, value: null }
|
|
4873
|
+
]);
|
|
4874
|
+
}
|
|
4875
|
+
if (next !== sourceData) onDataChange(next);
|
|
4876
|
+
};
|
|
4877
|
+
const commitEditAndMove = useCallback5(
|
|
4878
|
+
(raw, delta) => {
|
|
4879
|
+
const current = editingCell;
|
|
4880
|
+
if (!commitEdit(raw)) return false;
|
|
4881
|
+
if (current) {
|
|
4882
|
+
selectCell(current.rowIndex + delta.row, current.colIndex + delta.col);
|
|
4883
|
+
}
|
|
4884
|
+
rootRef.current?.focus({ preventScroll: true });
|
|
4885
|
+
return true;
|
|
4886
|
+
},
|
|
4887
|
+
[commitEdit, editingCell, selectCell]
|
|
4888
|
+
);
|
|
4889
|
+
const cancelEditAndRefocus = useCallback5(() => {
|
|
4890
|
+
cancelEdit();
|
|
4891
|
+
rootRef.current?.focus({ preventScroll: true });
|
|
4892
|
+
}, [cancelEdit]);
|
|
4199
4893
|
const commitRenderedCellValue = useCallback5(
|
|
4200
|
-
(rowId, columnId, value) =>
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4894
|
+
(rowId, columnId, value) => {
|
|
4895
|
+
const columnDef = table.getColumn(columnId)?.columnDef;
|
|
4896
|
+
if (columnDef && (columnDef.meta?.editable === false || isProtectedColumn(columnDef))) {
|
|
4897
|
+
return false;
|
|
4898
|
+
}
|
|
4899
|
+
return commitCellValue({
|
|
4900
|
+
data: sourceData,
|
|
4901
|
+
rows,
|
|
4902
|
+
rowId,
|
|
4903
|
+
columnId,
|
|
4904
|
+
value,
|
|
4905
|
+
onCellChange,
|
|
4906
|
+
onDataChange
|
|
4907
|
+
});
|
|
4908
|
+
},
|
|
4909
|
+
[onCellChange, onDataChange, rows, sourceData, table]
|
|
4210
4910
|
);
|
|
4211
4911
|
const getCellContext = useCallback5(
|
|
4212
4912
|
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
@@ -4234,27 +4934,14 @@ function useGlideTable(options) {
|
|
|
4234
4934
|
(row, index) => {
|
|
4235
4935
|
if (getRowId) return getRowId(row, index);
|
|
4236
4936
|
if (enableExpand) {
|
|
4237
|
-
const
|
|
4238
|
-
|
|
4239
|
-
if (idValue != null && String(idValue).length > 0) {
|
|
4240
|
-
return String(idValue);
|
|
4241
|
-
}
|
|
4242
|
-
const uniqueId = record.uniqueId;
|
|
4243
|
-
if (uniqueId != null && String(uniqueId).length > 0) {
|
|
4244
|
-
return String(uniqueId);
|
|
4245
|
-
}
|
|
4246
|
-
if (toggleField) {
|
|
4247
|
-
const toggleValue = record[toggleField];
|
|
4248
|
-
if (toggleValue != null && String(toggleValue).length > 0) {
|
|
4249
|
-
return String(toggleValue);
|
|
4250
|
-
}
|
|
4251
|
-
}
|
|
4937
|
+
const treeKey = getTreeRowKey(row);
|
|
4938
|
+
if (treeKey) return treeKey;
|
|
4252
4939
|
}
|
|
4253
4940
|
return String(index);
|
|
4254
4941
|
},
|
|
4255
|
-
[enableExpand, getRowId
|
|
4942
|
+
[enableExpand, getRowId]
|
|
4256
4943
|
);
|
|
4257
|
-
const searchCorpus =
|
|
4944
|
+
const searchCorpus = useMemo5(() => {
|
|
4258
4945
|
if (!enableInlineSearch) return [];
|
|
4259
4946
|
if (enableExpand && toggleField) {
|
|
4260
4947
|
return buildTreeSearchCorpus(tableData, {
|
|
@@ -4272,35 +4959,66 @@ function useGlideTable(options) {
|
|
|
4272
4959
|
]);
|
|
4273
4960
|
const searchCorpusRef = useRef7(searchCorpus);
|
|
4274
4961
|
searchCorpusRef.current = searchCorpus;
|
|
4275
|
-
const visibleRowIndexById =
|
|
4962
|
+
const visibleRowIndexById = useMemo5(() => {
|
|
4276
4963
|
const map = /* @__PURE__ */ new Map();
|
|
4277
4964
|
for (const row of rows) {
|
|
4278
4965
|
map.set(resolveSearchRowId(row.original, row.index), row.index);
|
|
4279
4966
|
}
|
|
4280
4967
|
return map;
|
|
4281
4968
|
}, [resolveSearchRowId, rows]);
|
|
4282
|
-
const
|
|
4283
|
-
(rowIndex,
|
|
4284
|
-
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
4285
|
-
const column = visibleLeafColumns[colIndex];
|
|
4286
|
-
if (!corpusRow || !column) return void 0;
|
|
4969
|
+
const readSearchRawValue = useCallback5(
|
|
4970
|
+
(corpusRow, rowIndex, column) => {
|
|
4287
4971
|
const visibleIndex = visibleRowIndexById.get(corpusRow.id);
|
|
4288
4972
|
if (visibleIndex !== void 0) {
|
|
4289
4973
|
const visibleRow = rows[visibleIndex];
|
|
4290
4974
|
if (visibleRow) {
|
|
4291
|
-
return visibleRow.getValue(column.id);
|
|
4975
|
+
return { value: visibleRow.getValue(column.id), row: visibleRow };
|
|
4292
4976
|
}
|
|
4293
4977
|
}
|
|
4294
4978
|
const columnDef = column.columnDef;
|
|
4295
4979
|
if ("accessorFn" in columnDef && typeof columnDef.accessorFn === "function") {
|
|
4296
|
-
return columnDef.accessorFn(corpusRow.data, rowIndex);
|
|
4980
|
+
return { value: columnDef.accessorFn(corpusRow.data, rowIndex), row: void 0 };
|
|
4297
4981
|
}
|
|
4298
4982
|
if ("accessorKey" in columnDef && columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
4299
|
-
return
|
|
4983
|
+
return {
|
|
4984
|
+
value: corpusRow.data[String(columnDef.accessorKey)],
|
|
4985
|
+
row: void 0
|
|
4986
|
+
};
|
|
4987
|
+
}
|
|
4988
|
+
return { value: corpusRow.data[column.id], row: void 0 };
|
|
4989
|
+
},
|
|
4990
|
+
[rows, visibleRowIndexById]
|
|
4991
|
+
);
|
|
4992
|
+
const getSearchCellValue = useCallback5(
|
|
4993
|
+
(rowIndex, colIndex) => {
|
|
4994
|
+
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
4995
|
+
const column = visibleLeafColumns[colIndex];
|
|
4996
|
+
if (!corpusRow || !column) return void 0;
|
|
4997
|
+
if (isProtectedColumn(column.columnDef)) return void 0;
|
|
4998
|
+
const { value, row } = readSearchRawValue(corpusRow, rowIndex, column);
|
|
4999
|
+
const meta = column.columnDef.meta;
|
|
5000
|
+
const searchValue2 = meta?.searchValue;
|
|
5001
|
+
if (!searchValue2 || searchValue2 === "value") return value;
|
|
5002
|
+
const ctx = {
|
|
5003
|
+
value,
|
|
5004
|
+
row: row ?? { id: corpusRow.id, index: rowIndex, original: corpusRow.data },
|
|
5005
|
+
index: row?.index ?? rowIndex,
|
|
5006
|
+
columnId: column.id,
|
|
5007
|
+
cellProps: meta?.cellProps,
|
|
5008
|
+
update: () => {
|
|
5009
|
+
}
|
|
5010
|
+
};
|
|
5011
|
+
try {
|
|
5012
|
+
if (typeof searchValue2 === "function") return searchValue2(ctx);
|
|
5013
|
+
if (meta?.cellRender) return reactNodeToText(meta.cellRender(ctx));
|
|
5014
|
+
const renderer = resolveCellRenderer(cellRendererRegistry, meta?.kind, ctx);
|
|
5015
|
+
if (renderer) return reactNodeToText(renderer.render(ctx));
|
|
5016
|
+
} catch {
|
|
5017
|
+
return value;
|
|
4300
5018
|
}
|
|
4301
|
-
return
|
|
5019
|
+
return value;
|
|
4302
5020
|
},
|
|
4303
|
-
[
|
|
5021
|
+
[cellRendererRegistry, readSearchRawValue, visibleLeafColumns]
|
|
4304
5022
|
);
|
|
4305
5023
|
const pendingSearchNavRef = useRef7(null);
|
|
4306
5024
|
const focusSearchResult = useCallback5(
|
|
@@ -4351,11 +5069,19 @@ function useGlideTable(options) {
|
|
|
4351
5069
|
focusSearchResult(pending.colIndex, visibleRowIndex);
|
|
4352
5070
|
}, [focusSearchResult, rows, visibleRowIndexById]);
|
|
4353
5071
|
const initialSearchStartRow = virtualRows[0]?.index ?? 0;
|
|
5072
|
+
const searchColumnSignature = visibleLeafColumns.map((column) => column.id).join("\0");
|
|
5073
|
+
const searchContentKey = useMemo5(
|
|
5074
|
+
() => ({ data: sourceData, columns: searchColumnSignature }),
|
|
5075
|
+
[sourceData, searchColumnSignature]
|
|
5076
|
+
);
|
|
4354
5077
|
const inlineSearch = useInlineSearch({
|
|
4355
5078
|
enabled: enableInlineSearch,
|
|
4356
5079
|
rowCount: searchCorpus.length,
|
|
4357
5080
|
columnCount: visibleLeafColumns.length,
|
|
4358
5081
|
getCellValue: getSearchCellValue,
|
|
5082
|
+
// Re-scan when the rows' content/order or the column order changes
|
|
5083
|
+
// (edits, re-sorts, reorders) — not on tree expand/collapse.
|
|
5084
|
+
contentKey: searchContentKey,
|
|
4359
5085
|
initialStartRow: initialSearchStartRow,
|
|
4360
5086
|
showSearch,
|
|
4361
5087
|
searchValue,
|
|
@@ -4366,7 +5092,7 @@ function useGlideTable(options) {
|
|
|
4366
5092
|
onNavigateToResult: navigateToCorpusSearchResult,
|
|
4367
5093
|
rootRef
|
|
4368
5094
|
});
|
|
4369
|
-
const visibleSearchMatchKeys =
|
|
5095
|
+
const visibleSearchMatchKeys = useMemo5(() => {
|
|
4370
5096
|
if (!enableInlineSearch) return EMPTY_SEARCH_MATCH_KEYS;
|
|
4371
5097
|
return mapSearchResultsToVisibleKeys(
|
|
4372
5098
|
inlineSearch.searchResults,
|
|
@@ -4379,7 +5105,7 @@ function useGlideTable(options) {
|
|
|
4379
5105
|
searchCorpus,
|
|
4380
5106
|
visibleRowIndexById
|
|
4381
5107
|
]);
|
|
4382
|
-
const visibleActiveMatch =
|
|
5108
|
+
const visibleActiveMatch = useMemo5(() => {
|
|
4383
5109
|
if (!enableInlineSearch || !inlineSearch.activeMatch) return null;
|
|
4384
5110
|
return mapSearchResultToVisibleItem(
|
|
4385
5111
|
inlineSearch.activeMatch,
|
|
@@ -4393,11 +5119,14 @@ function useGlideTable(options) {
|
|
|
4393
5119
|
visibleRowIndexById
|
|
4394
5120
|
]);
|
|
4395
5121
|
const clearHover = useCallback5(() => {
|
|
4396
|
-
setHoveredRowIndex(null);
|
|
4397
|
-
}, []);
|
|
4398
|
-
const handleRowHover = useCallback5(
|
|
4399
|
-
|
|
4400
|
-
|
|
5122
|
+
hoverStore.setHoveredRowIndex(null);
|
|
5123
|
+
}, [hoverStore]);
|
|
5124
|
+
const handleRowHover = useCallback5(
|
|
5125
|
+
(rowIndex, _rowData) => {
|
|
5126
|
+
hoverStore.setHoveredRowIndex(rowIndex);
|
|
5127
|
+
},
|
|
5128
|
+
[hoverStore]
|
|
5129
|
+
);
|
|
4401
5130
|
const handleToggleSelect = useCallback5(
|
|
4402
5131
|
(row) => {
|
|
4403
5132
|
if (!row.getCanSelect()) return;
|
|
@@ -4415,14 +5144,14 @@ function useGlideTable(options) {
|
|
|
4415
5144
|
},
|
|
4416
5145
|
[preventExpand, handleExpandedRowsChange, expandedRows]
|
|
4417
5146
|
);
|
|
4418
|
-
const rowContextValue =
|
|
5147
|
+
const rowContextValue = useMemo5(() => {
|
|
4419
5148
|
return {
|
|
4420
5149
|
rowSpan: {
|
|
4421
5150
|
enableRowSpan,
|
|
4422
5151
|
primaryRowSpanKey,
|
|
4423
5152
|
primaryRowSpanColumnId,
|
|
4424
5153
|
columnRowSpanMap,
|
|
4425
|
-
|
|
5154
|
+
hoverStore,
|
|
4426
5155
|
selectedRowIndices,
|
|
4427
5156
|
onRowHover: handleRowHover
|
|
4428
5157
|
},
|
|
@@ -4436,6 +5165,7 @@ function useGlideTable(options) {
|
|
|
4436
5165
|
enableCellSelection,
|
|
4437
5166
|
activeSelectionBounds,
|
|
4438
5167
|
dragState,
|
|
5168
|
+
canFill,
|
|
4439
5169
|
onCellMouseDown: handleCellMouseDownWithCommit,
|
|
4440
5170
|
onCellMouseEnter: handleCellMouseEnter,
|
|
4441
5171
|
onFillHandleMouseDown: handleFillHandleMouseDown
|
|
@@ -4443,18 +5173,23 @@ function useGlideTable(options) {
|
|
|
4443
5173
|
cellEdit: {
|
|
4444
5174
|
editingCell,
|
|
4445
5175
|
draftValue,
|
|
5176
|
+
draftInvalid,
|
|
5177
|
+
onDraftInvalidChange: setDraftInvalid,
|
|
4446
5178
|
onDraftValueChange: setDraftValue,
|
|
4447
5179
|
onStartEdit: startEdit,
|
|
4448
5180
|
onCommitEdit: commitEdit,
|
|
4449
|
-
|
|
5181
|
+
onCommitEditAndMove: commitEditAndMove,
|
|
5182
|
+
onCancelEdit: cancelEditAndRefocus
|
|
4450
5183
|
},
|
|
4451
5184
|
cellRender: {
|
|
4452
5185
|
registry: cellRendererRegistry,
|
|
4453
|
-
commitValue: commitRenderedCellValue
|
|
5186
|
+
commitValue: commitRenderedCellValue,
|
|
5187
|
+
protectedLabel: labels.protectedCell
|
|
4454
5188
|
},
|
|
4455
5189
|
expand: {
|
|
4456
5190
|
enableExpand,
|
|
4457
5191
|
toggleField,
|
|
5192
|
+
expandColumn,
|
|
4458
5193
|
expandedRows,
|
|
4459
5194
|
preventExpand,
|
|
4460
5195
|
onToggleExpand: handleToggleExpand,
|
|
@@ -4479,7 +5214,7 @@ function useGlideTable(options) {
|
|
|
4479
5214
|
primaryRowSpanKey,
|
|
4480
5215
|
primaryRowSpanColumnId,
|
|
4481
5216
|
columnRowSpanMap,
|
|
4482
|
-
|
|
5217
|
+
hoverStore,
|
|
4483
5218
|
selectedRowIndices,
|
|
4484
5219
|
handleRowHover,
|
|
4485
5220
|
rowSelectionMode,
|
|
@@ -4489,19 +5224,25 @@ function useGlideTable(options) {
|
|
|
4489
5224
|
enableCellSelection,
|
|
4490
5225
|
activeSelectionBounds,
|
|
4491
5226
|
dragState,
|
|
5227
|
+
canFill,
|
|
4492
5228
|
handleCellMouseDownWithCommit,
|
|
4493
5229
|
handleCellMouseEnter,
|
|
4494
5230
|
handleFillHandleMouseDown,
|
|
4495
5231
|
editingCell,
|
|
4496
5232
|
draftValue,
|
|
5233
|
+
draftInvalid,
|
|
5234
|
+
setDraftInvalid,
|
|
4497
5235
|
setDraftValue,
|
|
4498
5236
|
startEdit,
|
|
4499
5237
|
commitEdit,
|
|
4500
|
-
|
|
5238
|
+
commitEditAndMove,
|
|
5239
|
+
cancelEditAndRefocus,
|
|
4501
5240
|
cellRendererRegistry,
|
|
4502
5241
|
commitRenderedCellValue,
|
|
5242
|
+
labels.protectedCell,
|
|
4503
5243
|
enableExpand,
|
|
4504
5244
|
toggleField,
|
|
5245
|
+
expandColumn,
|
|
4505
5246
|
expandedRows,
|
|
4506
5247
|
preventExpand,
|
|
4507
5248
|
handleToggleExpand,
|
|
@@ -4549,6 +5290,7 @@ function useGlideTable(options) {
|
|
|
4549
5290
|
handleToggleSelect,
|
|
4550
5291
|
clearHover,
|
|
4551
5292
|
setColumnOrder,
|
|
5293
|
+
handleRootFocus: focusSelection,
|
|
4552
5294
|
copySelection: stableCopySelection,
|
|
4553
5295
|
inlineSearch: {
|
|
4554
5296
|
showSearch: inlineSearch.showSearch,
|
|
@@ -4646,7 +5388,8 @@ function DataTable({
|
|
|
4646
5388
|
handleToggleSelect,
|
|
4647
5389
|
clearHover,
|
|
4648
5390
|
setColumnOrder,
|
|
4649
|
-
inlineSearch
|
|
5391
|
+
inlineSearch,
|
|
5392
|
+
handleRootFocus
|
|
4650
5393
|
} = useGlideTable(glideOptions);
|
|
4651
5394
|
const ToolbarSlot = slots?.Toolbar ?? DataTableToolbar;
|
|
4652
5395
|
const ScrollSlot = slots?.Scroll ?? DefaultScroll;
|
|
@@ -4680,7 +5423,7 @@ function DataTable({
|
|
|
4680
5423
|
observer.observe(element);
|
|
4681
5424
|
return () => observer.disconnect();
|
|
4682
5425
|
}, [enableColumnResize, isPending, scrollRef, rows.length, leafColumnIds.join("|")]);
|
|
4683
|
-
const layoutWidths =
|
|
5426
|
+
const layoutWidths = useMemo6(() => {
|
|
4684
5427
|
if (enableColumnResize) return void 0;
|
|
4685
5428
|
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4686
5429
|
id: column.id,
|
|
@@ -4690,13 +5433,33 @@ function DataTable({
|
|
|
4690
5433
|
}));
|
|
4691
5434
|
return resolveColumnLayoutWidths(containerWidth, columns);
|
|
4692
5435
|
}, [enableColumnResize, containerWidth, table, columnLayoutMetaSignature]);
|
|
4693
|
-
const
|
|
5436
|
+
const [measuredWidths, setMeasuredWidths] = useState6(
|
|
5437
|
+
() => /* @__PURE__ */ new Map()
|
|
5438
|
+
);
|
|
5439
|
+
useLayoutEffect(() => {
|
|
5440
|
+
if (!enableColumnFreeze || enableColumnResize) return;
|
|
5441
|
+
const element = scrollRef.current;
|
|
5442
|
+
if (!element) return;
|
|
5443
|
+
const next = /* @__PURE__ */ new Map();
|
|
5444
|
+
element.querySelectorAll("th[data-leaf-column-id]").forEach((th) => {
|
|
5445
|
+
const id = th.getAttribute("data-leaf-column-id");
|
|
5446
|
+
const width = th.getBoundingClientRect().width;
|
|
5447
|
+
if (id && width > 0) next.set(id, width);
|
|
5448
|
+
});
|
|
5449
|
+
setMeasuredWidths((previous) => {
|
|
5450
|
+
if (previous.size === next.size && [...next].every(([id, width]) => previous.get(id) === width)) {
|
|
5451
|
+
return previous;
|
|
5452
|
+
}
|
|
5453
|
+
return next;
|
|
5454
|
+
});
|
|
5455
|
+
});
|
|
5456
|
+
const freezeOffsets = useMemo6(() => {
|
|
4694
5457
|
if (!enableColumnFreeze || enableColumnResize || !layoutWidths) {
|
|
4695
5458
|
return rowContextValue.columnFreeze.offsets;
|
|
4696
5459
|
}
|
|
4697
5460
|
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4698
5461
|
id: column.id,
|
|
4699
|
-
size: layoutWidths.get(column.id) ?? column.getSize(),
|
|
5462
|
+
size: measuredWidths.get(column.id) ?? layoutWidths.get(column.id) ?? column.getSize(),
|
|
4700
5463
|
side: resolveColumnFreezeSide(column.columnDef.meta?.frozen)
|
|
4701
5464
|
}));
|
|
4702
5465
|
return buildColumnFreezeOffsets(columns);
|
|
@@ -4704,10 +5467,11 @@ function DataTable({
|
|
|
4704
5467
|
enableColumnFreeze,
|
|
4705
5468
|
enableColumnResize,
|
|
4706
5469
|
layoutWidths,
|
|
5470
|
+
measuredWidths,
|
|
4707
5471
|
rowContextValue.columnFreeze.offsets,
|
|
4708
5472
|
table
|
|
4709
5473
|
]);
|
|
4710
|
-
const contextValue =
|
|
5474
|
+
const contextValue = useMemo6(
|
|
4711
5475
|
() => ({
|
|
4712
5476
|
...rowContextValue,
|
|
4713
5477
|
classNames,
|
|
@@ -4736,6 +5500,10 @@ function DataTable({
|
|
|
4736
5500
|
"div",
|
|
4737
5501
|
{
|
|
4738
5502
|
ref: rootRef,
|
|
5503
|
+
tabIndex: enableCellSelection ? 0 : void 0,
|
|
5504
|
+
onFocus: enableCellSelection ? (event) => {
|
|
5505
|
+
if (event.target === event.currentTarget) handleRootFocus();
|
|
5506
|
+
} : void 0,
|
|
4739
5507
|
className: cn(
|
|
4740
5508
|
"DataTableJSX",
|
|
4741
5509
|
!enableCellSelection && "DataTableJSX--no-cell-selection",
|
|
@@ -4756,6 +5524,7 @@ function DataTable({
|
|
|
4756
5524
|
summary,
|
|
4757
5525
|
selectedCount,
|
|
4758
5526
|
selectionLabel,
|
|
5527
|
+
countLabel: labels.count,
|
|
4759
5528
|
toolbar,
|
|
4760
5529
|
classNames
|
|
4761
5530
|
}
|
|
@@ -4774,6 +5543,7 @@ function DataTable({
|
|
|
4774
5543
|
previousLabel: labels.searchPrevious,
|
|
4775
5544
|
nextLabel: labels.searchNext,
|
|
4776
5545
|
closeLabel: labels.searchClose,
|
|
5546
|
+
formatResult: labels.searchResultCount,
|
|
4777
5547
|
rowsTotal: inlineSearch.searchRowCount,
|
|
4778
5548
|
classNames,
|
|
4779
5549
|
onSearchValueChange: inlineSearch.setSearchValue,
|
|
@@ -4823,6 +5593,8 @@ function DataTable({
|
|
|
4823
5593
|
(leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
|
|
4824
5594
|
);
|
|
4825
5595
|
const isDragging = draggingColumnId === header.column.id;
|
|
5596
|
+
const sortDirection = isPlaceholder ? void 0 : header.column.columnDef.meta?.sortDirection;
|
|
5597
|
+
const ariaSort = sortDirection === void 0 ? void 0 : sortDirection === "asc" ? "ascending" : sortDirection === "desc" ? "descending" : "none";
|
|
4826
5598
|
const dropEdge = !isPlaceholder && dropTarget?.columnId === header.column.id ? dropTarget.edge : void 0;
|
|
4827
5599
|
return /* @__PURE__ */ jsxs6(
|
|
4828
5600
|
"th",
|
|
@@ -4838,7 +5610,8 @@ function DataTable({
|
|
|
4838
5610
|
"data-resizing": header.column.getIsResizing() ? "" : void 0,
|
|
4839
5611
|
"data-frozen": freezeOffset?.side,
|
|
4840
5612
|
"data-freeze-edge": getColumnFreezeEdgeAttr(freezeOffset),
|
|
4841
|
-
"
|
|
5613
|
+
"data-leaf-column-id": isLeafHeader ? header.column.id : void 0,
|
|
5614
|
+
"aria-sort": ariaSort,
|
|
4842
5615
|
title: canDrag ? labels.reorderColumn : void 0,
|
|
4843
5616
|
onPointerDown: enableColumnReorder ? (event) => onHeaderPointerDown(event, {
|
|
4844
5617
|
columnId: header.column.id,
|
|
@@ -4865,7 +5638,31 @@ function DataTable({
|
|
|
4865
5638
|
role: "separator",
|
|
4866
5639
|
"aria-orientation": "vertical",
|
|
4867
5640
|
"aria-label": labels.resizeColumn,
|
|
5641
|
+
"aria-valuenow": header.getSize(),
|
|
5642
|
+
tabIndex: 0,
|
|
4868
5643
|
"data-table-disable-cell-selection": "",
|
|
5644
|
+
onKeyDown: (event) => {
|
|
5645
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") {
|
|
5646
|
+
return;
|
|
5647
|
+
}
|
|
5648
|
+
event.preventDefault();
|
|
5649
|
+
event.stopPropagation();
|
|
5650
|
+
const step = event.shiftKey ? 50 : 10;
|
|
5651
|
+
const columnDef = header.column.columnDef;
|
|
5652
|
+
const min = columnDef.minSize ?? DATA_TABLE_COLUMN_MIN_SIZE;
|
|
5653
|
+
const max = columnDef.maxSize ?? DATA_TABLE_COLUMN_MAX_SIZE;
|
|
5654
|
+
const nextSize = Math.min(
|
|
5655
|
+
max,
|
|
5656
|
+
Math.max(
|
|
5657
|
+
min,
|
|
5658
|
+
header.getSize() + (event.key === "ArrowRight" ? step : -step)
|
|
5659
|
+
)
|
|
5660
|
+
);
|
|
5661
|
+
table.setColumnSizing((previous) => ({
|
|
5662
|
+
...previous,
|
|
5663
|
+
[header.column.id]: nextSize
|
|
5664
|
+
}));
|
|
5665
|
+
},
|
|
4869
5666
|
className: cn(
|
|
4870
5667
|
"data-table-resize-handle",
|
|
4871
5668
|
classNames?.resizeHandle
|
|
@@ -4973,7 +5770,10 @@ function DataTable({
|
|
|
4973
5770
|
}
|
|
4974
5771
|
|
|
4975
5772
|
// src/components/ui/table/components/Table/Table.tsx
|
|
4976
|
-
import { useCallback as useCallback7, useMemo as
|
|
5773
|
+
import { useCallback as useCallback7, useMemo as useMemo7, useRef as useRef8, useState as useState7 } from "react";
|
|
5774
|
+
|
|
5775
|
+
// src/components/ui/table/components/Table/buildColumnDef.tsx
|
|
5776
|
+
import { createContext as createContext2, use as use2 } from "react";
|
|
4977
5777
|
|
|
4978
5778
|
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
4979
5779
|
import { useCallback as useCallback6 } from "react";
|
|
@@ -4991,12 +5791,16 @@ function ResolvedTableCell({
|
|
|
4991
5791
|
},
|
|
4992
5792
|
[cellRender, columnId, row.id]
|
|
4993
5793
|
);
|
|
5794
|
+
let cellProps = meta?.editable === false ? { ...meta.cellProps, readonly: true } : meta?.cellProps;
|
|
5795
|
+
if (meta?.kind === "protected" && cellRender.protectedLabel && cellProps?.ariaLabel === void 0) {
|
|
5796
|
+
cellProps = { ...cellProps, ariaLabel: cellRender.protectedLabel };
|
|
5797
|
+
}
|
|
4994
5798
|
const ctx = {
|
|
4995
5799
|
value,
|
|
4996
5800
|
row,
|
|
4997
5801
|
index: row.index,
|
|
4998
5802
|
columnId,
|
|
4999
|
-
cellProps
|
|
5803
|
+
cellProps,
|
|
5000
5804
|
update
|
|
5001
5805
|
};
|
|
5002
5806
|
if (meta?.cellRender) {
|
|
@@ -5011,12 +5815,16 @@ function ResolvedTableCell({
|
|
|
5011
5815
|
|
|
5012
5816
|
// src/components/ui/table/components/Table/buildColumnDef.tsx
|
|
5013
5817
|
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
5818
|
+
var TableSortContext = createContext2(null);
|
|
5014
5819
|
function SortableHeader({
|
|
5015
5820
|
label,
|
|
5016
5821
|
field,
|
|
5017
|
-
sort,
|
|
5018
|
-
onSort
|
|
5822
|
+
sort: sortProp,
|
|
5823
|
+
onSort: onSortProp
|
|
5019
5824
|
}) {
|
|
5825
|
+
const context = use2(TableSortContext);
|
|
5826
|
+
const sort = context ? context.sort : sortProp;
|
|
5827
|
+
const onSort = context ? context.onSort : onSortProp;
|
|
5020
5828
|
const isActive = sort?.field === field;
|
|
5021
5829
|
const Icon = isActive ? sort.direction === "asc" ? ArrowUp : ArrowDown : ArrowUpDown;
|
|
5022
5830
|
return /* @__PURE__ */ jsxs7(
|
|
@@ -5035,7 +5843,7 @@ function SortableHeader({
|
|
|
5035
5843
|
}
|
|
5036
5844
|
);
|
|
5037
5845
|
}
|
|
5038
|
-
function buildColumnDef(props, sort, onSort) {
|
|
5846
|
+
function buildColumnDef(props, sort, onSort, headerCache) {
|
|
5039
5847
|
const {
|
|
5040
5848
|
field,
|
|
5041
5849
|
virtual = false,
|
|
@@ -5061,8 +5869,29 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5061
5869
|
className,
|
|
5062
5870
|
headerClassName,
|
|
5063
5871
|
render,
|
|
5064
|
-
copyValue
|
|
5872
|
+
copyValue,
|
|
5873
|
+
searchValue
|
|
5065
5874
|
} = props;
|
|
5875
|
+
const createHeader = () => sortable ? () => /* @__PURE__ */ jsx8(
|
|
5876
|
+
SortableHeader,
|
|
5877
|
+
{
|
|
5878
|
+
label: children,
|
|
5879
|
+
field,
|
|
5880
|
+
sort,
|
|
5881
|
+
onSort
|
|
5882
|
+
}
|
|
5883
|
+
) : (
|
|
5884
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
5885
|
+
() => children
|
|
5886
|
+
);
|
|
5887
|
+
const cached = headerCache?.get(field);
|
|
5888
|
+
let header;
|
|
5889
|
+
if (cached && cached.label === children && cached.sortable === sortable) {
|
|
5890
|
+
header = cached.render;
|
|
5891
|
+
} else {
|
|
5892
|
+
header = createHeader();
|
|
5893
|
+
headerCache?.set(field, { label: children, sortable, render: header });
|
|
5894
|
+
}
|
|
5066
5895
|
return {
|
|
5067
5896
|
id: field,
|
|
5068
5897
|
...!virtual ? { accessorKey: field } : {},
|
|
@@ -5070,18 +5899,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5070
5899
|
...minResizeWidth != null ? { minSize: minResizeWidth } : {},
|
|
5071
5900
|
...maxResizeWidth != null ? { maxSize: maxResizeWidth } : {},
|
|
5072
5901
|
...resizable === false ? { enableResizing: false } : {},
|
|
5073
|
-
header
|
|
5074
|
-
SortableHeader,
|
|
5075
|
-
{
|
|
5076
|
-
label: children,
|
|
5077
|
-
field,
|
|
5078
|
-
sort,
|
|
5079
|
-
onSort
|
|
5080
|
-
}
|
|
5081
|
-
) : (
|
|
5082
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
5083
|
-
() => children
|
|
5084
|
-
),
|
|
5902
|
+
header,
|
|
5085
5903
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
5086
5904
|
cell: (info) => /* @__PURE__ */ jsx8(ResolvedTableCell, { info }),
|
|
5087
5905
|
meta: {
|
|
@@ -5096,6 +5914,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5096
5914
|
cellProps,
|
|
5097
5915
|
cellRender: render,
|
|
5098
5916
|
copyValue,
|
|
5917
|
+
searchValue,
|
|
5918
|
+
sortDirection: sortable ? sort?.field === field ? sort.direction : false : void 0,
|
|
5099
5919
|
frozen,
|
|
5100
5920
|
reorderable,
|
|
5101
5921
|
width,
|
|
@@ -5113,12 +5933,12 @@ function resolveGroupId(props, index) {
|
|
|
5113
5933
|
}
|
|
5114
5934
|
return `group:${index}`;
|
|
5115
5935
|
}
|
|
5116
|
-
function buildColumnDefsFromTree(nodes, sort, onSort) {
|
|
5936
|
+
function buildColumnDefsFromTree(nodes, sort, onSort, headerCache) {
|
|
5117
5937
|
return nodes.map((node, index) => {
|
|
5118
5938
|
if (node.type === "leaf") {
|
|
5119
|
-
return buildColumnDef(node.props, sort, onSort);
|
|
5939
|
+
return buildColumnDef(node.props, sort, onSort, headerCache);
|
|
5120
5940
|
}
|
|
5121
|
-
const childDefs = buildColumnDefsFromTree(node.columns, sort, onSort);
|
|
5941
|
+
const childDefs = buildColumnDefsFromTree(node.columns, sort, onSort, headerCache);
|
|
5122
5942
|
const { header, align, headerClassName } = node.props;
|
|
5123
5943
|
return {
|
|
5124
5944
|
id: resolveGroupId(node.props, index),
|
|
@@ -5254,13 +6074,22 @@ function TableColumnGroup(props) {
|
|
|
5254
6074
|
TableColumnGroup.displayName = TABLE_COLUMN_GROUP_DISPLAY_NAME;
|
|
5255
6075
|
|
|
5256
6076
|
// src/components/ui/table/components/Table/tableDataPipeline.ts
|
|
5257
|
-
function
|
|
6077
|
+
function readField(row, field) {
|
|
6078
|
+
if (field in row || !field.includes(".")) return row[field];
|
|
6079
|
+
return field.split(".").reduce((current, key) => {
|
|
6080
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
6081
|
+
return void 0;
|
|
6082
|
+
}
|
|
6083
|
+
return current[key];
|
|
6084
|
+
}, row);
|
|
6085
|
+
}
|
|
6086
|
+
function sortTableData(data, sort, locale = "ko") {
|
|
5258
6087
|
if (!sort) return data;
|
|
5259
6088
|
const { field, direction } = sort;
|
|
5260
6089
|
const multiplier = direction === "asc" ? 1 : -1;
|
|
5261
6090
|
return [...data].sort((left, right) => {
|
|
5262
|
-
const leftValue = left
|
|
5263
|
-
const rightValue = right
|
|
6091
|
+
const leftValue = readField(left, field);
|
|
6092
|
+
const rightValue = readField(right, field);
|
|
5264
6093
|
if ((leftValue === null || leftValue === void 0) && (rightValue === null || rightValue === void 0)) {
|
|
5265
6094
|
return 0;
|
|
5266
6095
|
}
|
|
@@ -5269,11 +6098,12 @@ function sortTableData(data, sort) {
|
|
|
5269
6098
|
if (typeof leftValue === "number" && typeof rightValue === "number") {
|
|
5270
6099
|
return (leftValue - rightValue) * multiplier;
|
|
5271
6100
|
}
|
|
5272
|
-
return String(leftValue).localeCompare(String(rightValue),
|
|
6101
|
+
return String(leftValue).localeCompare(String(rightValue), locale, { numeric: true }) * multiplier;
|
|
5273
6102
|
});
|
|
5274
6103
|
}
|
|
5275
6104
|
function paginateTableData(data, page, pageSize) {
|
|
5276
|
-
const
|
|
6105
|
+
const lastPage = getTotalPages(data.length, pageSize);
|
|
6106
|
+
const safePage = Math.min(Math.max(1, page), lastPage);
|
|
5277
6107
|
const start = (safePage - 1) * pageSize;
|
|
5278
6108
|
return data.slice(start, start + pageSize);
|
|
5279
6109
|
}
|
|
@@ -5281,6 +6111,36 @@ function getTotalPages(totalCount, pageSize) {
|
|
|
5281
6111
|
if (pageSize <= 0) return 1;
|
|
5282
6112
|
return Math.max(1, Math.ceil(totalCount / pageSize));
|
|
5283
6113
|
}
|
|
6114
|
+
function buildTreeRootBlocks(data, fields, sort, locale) {
|
|
6115
|
+
const childrenByRow = /* @__PURE__ */ new Map();
|
|
6116
|
+
const roots = [];
|
|
6117
|
+
const latestById = /* @__PURE__ */ new Map();
|
|
6118
|
+
for (const row of data) {
|
|
6119
|
+
const parentKey = row[fields.parentIdField];
|
|
6120
|
+
const parent = parentKey !== null && parentKey !== void 0 && parentKey !== "" ? latestById.get(parentKey) : void 0;
|
|
6121
|
+
if (parent) {
|
|
6122
|
+
const siblings = childrenByRow.get(parent);
|
|
6123
|
+
if (siblings) siblings.push(row);
|
|
6124
|
+
else childrenByRow.set(parent, [row]);
|
|
6125
|
+
} else {
|
|
6126
|
+
roots.push(row);
|
|
6127
|
+
}
|
|
6128
|
+
latestById.set(row[fields.idField], row);
|
|
6129
|
+
}
|
|
6130
|
+
const appendSubtree = (row, out) => {
|
|
6131
|
+
out.push(row);
|
|
6132
|
+
const children = childrenByRow.get(row);
|
|
6133
|
+
if (!children) return;
|
|
6134
|
+
for (const child of sortTableData(children, sort, locale)) {
|
|
6135
|
+
appendSubtree(child, out);
|
|
6136
|
+
}
|
|
6137
|
+
};
|
|
6138
|
+
return sortTableData(roots, sort, locale).map((root) => {
|
|
6139
|
+
const block = [];
|
|
6140
|
+
appendSubtree(root, block);
|
|
6141
|
+
return block;
|
|
6142
|
+
});
|
|
6143
|
+
}
|
|
5284
6144
|
|
|
5285
6145
|
// src/components/ui/table/components/Table/TableHeader.tsx
|
|
5286
6146
|
function TableHeader(props) {
|
|
@@ -5296,7 +6156,9 @@ function TablePagination({
|
|
|
5296
6156
|
pageSize = 10,
|
|
5297
6157
|
totalCount = 0,
|
|
5298
6158
|
onChange,
|
|
5299
|
-
className
|
|
6159
|
+
className,
|
|
6160
|
+
previousLabel = "Previous page",
|
|
6161
|
+
nextLabel = "Next page"
|
|
5300
6162
|
}) {
|
|
5301
6163
|
const totalPages = getTotalPages(totalCount, pageSize);
|
|
5302
6164
|
const safePage = Math.min(Math.max(1, page), totalPages);
|
|
@@ -5310,7 +6172,7 @@ function TablePagination({
|
|
|
5310
6172
|
className: "pagination-button",
|
|
5311
6173
|
disabled: !canGoPrev,
|
|
5312
6174
|
onClick: () => onChange(safePage - 1),
|
|
5313
|
-
"aria-label":
|
|
6175
|
+
"aria-label": previousLabel,
|
|
5314
6176
|
children: /* @__PURE__ */ jsx9(ChevronLeft, { className: "pagination-button-icon" })
|
|
5315
6177
|
}
|
|
5316
6178
|
),
|
|
@@ -5326,7 +6188,7 @@ function TablePagination({
|
|
|
5326
6188
|
className: "pagination-button",
|
|
5327
6189
|
disabled: !canGoNext,
|
|
5328
6190
|
onClick: () => onChange(safePage + 1),
|
|
5329
|
-
"aria-label":
|
|
6191
|
+
"aria-label": nextLabel,
|
|
5330
6192
|
children: /* @__PURE__ */ jsx9(ChevronRight, { className: "pagination-button-icon" })
|
|
5331
6193
|
}
|
|
5332
6194
|
)
|
|
@@ -5340,63 +6202,124 @@ function TableRoot({
|
|
|
5340
6202
|
data,
|
|
5341
6203
|
children,
|
|
5342
6204
|
className,
|
|
6205
|
+
classNames,
|
|
5343
6206
|
totalCount,
|
|
5344
6207
|
filteredCount,
|
|
6208
|
+
onDataChange,
|
|
6209
|
+
getRowId,
|
|
6210
|
+
sort: controlledSort,
|
|
6211
|
+
defaultSort = null,
|
|
6212
|
+
onSortChange,
|
|
6213
|
+
sortLocale,
|
|
5345
6214
|
...dataTableProps
|
|
5346
6215
|
}) {
|
|
5347
|
-
const { header, pagination: paginationElement } =
|
|
6216
|
+
const { header, pagination: paginationElement } = useMemo7(
|
|
5348
6217
|
() => parseTableChildren(children),
|
|
5349
6218
|
[children]
|
|
5350
6219
|
);
|
|
5351
|
-
const [
|
|
5352
|
-
const
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
6220
|
+
const [internalSort, setInternalSort] = useState7(defaultSort);
|
|
6221
|
+
const sort = controlledSort !== void 0 ? controlledSort : internalSort;
|
|
6222
|
+
const handleSort = useCallback7(
|
|
6223
|
+
(field) => {
|
|
6224
|
+
let next;
|
|
6225
|
+
if (sort?.field !== field) {
|
|
6226
|
+
next = { field, direction: "asc" };
|
|
6227
|
+
} else if (sort.direction === "asc") {
|
|
6228
|
+
next = { field, direction: "desc" };
|
|
6229
|
+
} else {
|
|
6230
|
+
next = null;
|
|
5359
6231
|
}
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
6232
|
+
if (controlledSort === void 0) setInternalSort(next);
|
|
6233
|
+
onSortChange?.(next);
|
|
6234
|
+
},
|
|
6235
|
+
[controlledSort, onSortChange, sort]
|
|
6236
|
+
);
|
|
6237
|
+
const columnTree = useMemo7(() => extractColumnTree(header), [header]);
|
|
6238
|
+
const headerCacheRef = useRef8(/* @__PURE__ */ new Map());
|
|
6239
|
+
const columns = useMemo7(
|
|
6240
|
+
() => buildColumnDefsFromTree(columnTree, sort, handleSort, headerCacheRef.current),
|
|
5366
6241
|
[columnTree, sort, handleSort]
|
|
5367
6242
|
);
|
|
6243
|
+
const sortContextValue = useMemo7(() => ({ sort, onSort: handleSort }), [sort, handleSort]);
|
|
5368
6244
|
const paginationProps = paginationElement?.props;
|
|
5369
6245
|
const pageSize = paginationProps?.pageSize ?? 10;
|
|
5370
6246
|
const page = paginationProps?.page ?? 1;
|
|
5371
6247
|
const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
|
|
5372
|
-
const
|
|
5373
|
-
|
|
5374
|
-
|
|
6248
|
+
const isManualPagination = Boolean(paginationProps?.manual);
|
|
6249
|
+
const treeIdField = dataTableProps.toggleField ?? dataTableProps.idField;
|
|
6250
|
+
const isTree = Boolean(treeIdField);
|
|
6251
|
+
const treeParentIdField = dataTableProps.childField ?? dataTableProps.parentIdField ?? DEFAULT_TREE_PARENT_ID_FIELD;
|
|
6252
|
+
const treeBlocks = useMemo7(() => {
|
|
6253
|
+
if (!isTree || !treeIdField) return null;
|
|
6254
|
+
if (!sort && (!paginationProps || isManualPagination)) return null;
|
|
6255
|
+
return buildTreeRootBlocks(
|
|
6256
|
+
data,
|
|
6257
|
+
{ idField: treeIdField, parentIdField: treeParentIdField },
|
|
6258
|
+
sort,
|
|
6259
|
+
sortLocale
|
|
6260
|
+
);
|
|
6261
|
+
}, [data, isManualPagination, isTree, paginationProps, sort, sortLocale, treeIdField, treeParentIdField]);
|
|
6262
|
+
const pageTotalCount = paginationProps?.totalCount ?? totalCount ?? (treeBlocks ? treeBlocks.length : data.length);
|
|
6263
|
+
const tableData = useMemo7(() => {
|
|
6264
|
+
if (treeBlocks) {
|
|
6265
|
+
const blocks = !paginationProps || isManualPagination ? treeBlocks : paginateTableData(treeBlocks, page, pageSize);
|
|
6266
|
+
return blocks.flat();
|
|
6267
|
+
}
|
|
6268
|
+
const sortedData = sortTableData(data, sort, sortLocale);
|
|
6269
|
+
if (!paginationProps || isManualPagination) return sortedData;
|
|
5375
6270
|
return paginateTableData(sortedData, page, pageSize);
|
|
5376
|
-
}, [data, sort, paginationProps, page, pageSize]);
|
|
6271
|
+
}, [treeBlocks, data, sort, sortLocale, paginationProps, isManualPagination, page, pageSize]);
|
|
6272
|
+
const originalIndexByRow = useMemo7(() => {
|
|
6273
|
+
const map = /* @__PURE__ */ new Map();
|
|
6274
|
+
data.forEach((row, index) => map.set(row, index));
|
|
6275
|
+
return map;
|
|
6276
|
+
}, [data]);
|
|
6277
|
+
const resolvedGetRowId = useMemo7(() => {
|
|
6278
|
+
if (getRowId) return getRowId;
|
|
6279
|
+
if (isTree) return void 0;
|
|
6280
|
+
return (row, index) => String(originalIndexByRow.get(row) ?? index);
|
|
6281
|
+
}, [isTree, getRowId, originalIndexByRow]);
|
|
6282
|
+
const handleDataChange = useMemo7(() => {
|
|
6283
|
+
if (!onDataChange) return void 0;
|
|
6284
|
+
return (next) => {
|
|
6285
|
+
const merged = data.slice();
|
|
6286
|
+
tableData.forEach((row, index) => {
|
|
6287
|
+
const nextRow = next[index];
|
|
6288
|
+
if (nextRow === void 0 || nextRow === row) return;
|
|
6289
|
+
const originalIndex = originalIndexByRow.get(row);
|
|
6290
|
+
if (originalIndex !== void 0) merged[originalIndex] = nextRow;
|
|
6291
|
+
});
|
|
6292
|
+
onDataChange(merged);
|
|
6293
|
+
};
|
|
6294
|
+
}, [data, onDataChange, originalIndexByRow, tableData]);
|
|
5377
6295
|
if (countLeafColumns(columnTree) === 0) {
|
|
5378
6296
|
console.warn("[Table] Declare at least one Table.Column inside Table.Header.");
|
|
5379
6297
|
}
|
|
5380
|
-
return /* @__PURE__ */ jsxs9("div", { className: "TableJSX", children: [
|
|
5381
|
-
/* @__PURE__ */ jsx10(
|
|
6298
|
+
return /* @__PURE__ */ jsxs9("div", { className: cn("TableJSX", classNames?.tableRoot), children: [
|
|
6299
|
+
/* @__PURE__ */ jsx10(TableSortContext, { value: sortContextValue, children: /* @__PURE__ */ jsx10(
|
|
5382
6300
|
DataTable,
|
|
5383
6301
|
{
|
|
5384
6302
|
...dataTableProps,
|
|
6303
|
+
classNames,
|
|
6304
|
+
getRowId: resolvedGetRowId,
|
|
6305
|
+
onDataChange: handleDataChange,
|
|
5385
6306
|
data: tableData,
|
|
5386
6307
|
columns,
|
|
5387
6308
|
totalCount: paginationProps ? resolvedTotalCount : totalCount,
|
|
5388
6309
|
filteredCount: filteredCount ?? data.length,
|
|
5389
6310
|
className: cn(className, paginationProps && "DataTableJSX--with-pagination")
|
|
5390
6311
|
}
|
|
5391
|
-
),
|
|
6312
|
+
) }),
|
|
5392
6313
|
paginationProps && /* @__PURE__ */ jsx10(
|
|
5393
6314
|
TablePagination,
|
|
5394
6315
|
{
|
|
5395
6316
|
page,
|
|
5396
6317
|
pageSize,
|
|
5397
|
-
totalCount:
|
|
6318
|
+
totalCount: pageTotalCount,
|
|
5398
6319
|
onChange: paginationProps.onChange,
|
|
5399
|
-
className: paginationProps.className
|
|
6320
|
+
className: cn(classNames?.pagination, paginationProps.className),
|
|
6321
|
+
previousLabel: paginationProps.previousLabel ?? dataTableProps.labels?.paginationPrevious,
|
|
6322
|
+
nextLabel: paginationProps.nextLabel ?? dataTableProps.labels?.paginationNext
|
|
5400
6323
|
}
|
|
5401
6324
|
)
|
|
5402
6325
|
] });
|