react-glide-table 2.3.5 → 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 +1246 -357
- package/dist/compound.d.cts +13 -4
- package/dist/compound.d.ts +13 -4
- package/dist/compound.js +1262 -369
- package/dist/core.cjs +1628 -999
- package/dist/core.d.cts +100 -15
- package/dist/core.d.ts +100 -15
- package/dist/core.js +1649 -1021
- package/dist/index.cjs +2060 -1170
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2074 -1181
- 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");
|
|
2657
|
-
}
|
|
2658
|
-
function registerCellSelectionOwner(owner, clearSelection) {
|
|
2659
|
-
clearByOwner.set(owner, clearSelection);
|
|
2660
|
-
return () => {
|
|
2661
|
-
clearByOwner.delete(owner);
|
|
2662
|
-
if (activeOwner === owner) {
|
|
2663
|
-
activeOwner = null;
|
|
2664
|
-
}
|
|
2665
|
-
};
|
|
2666
|
-
}
|
|
2667
|
-
function claimCellSelectionOwner(owner) {
|
|
2668
|
-
if (activeOwner === owner) return;
|
|
2669
|
-
activeOwner = owner;
|
|
2670
|
-
for (const [id, clearSelection] of clearByOwner) {
|
|
2671
|
-
if (id !== owner) {
|
|
2672
|
-
clearSelection();
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
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+$/, "");
|
|
2675
2936
|
}
|
|
2676
|
-
function
|
|
2677
|
-
|
|
2937
|
+
function rememberSubtreeCopy(text) {
|
|
2938
|
+
lastSubtreeCopy = normalize(text);
|
|
2678
2939
|
}
|
|
2679
|
-
function
|
|
2680
|
-
|
|
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");
|
|
@@ -3054,6 +3304,7 @@ function writeTextWithExecCommand(text) {
|
|
|
3054
3304
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
3055
3305
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
3056
3306
|
if (!text) return false;
|
|
3307
|
+
if (mode === "subtree") rememberSubtreeCopy(text);
|
|
3057
3308
|
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
3058
3309
|
return writeTextWithExecCommand(text);
|
|
3059
3310
|
}
|
|
@@ -3065,6 +3316,42 @@ async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible",
|
|
|
3065
3316
|
}
|
|
3066
3317
|
}
|
|
3067
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
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3068
3355
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
3069
3356
|
function getColumnAccessorKey2(columnDef) {
|
|
3070
3357
|
if ("accessorKey" in columnDef && columnDef.accessorKey) {
|
|
@@ -3087,6 +3374,8 @@ function collectFillTargets(rows, sourceBounds, fillBounds) {
|
|
|
3087
3374
|
const targetCell = targetRow?.getVisibleCells()[colIndex];
|
|
3088
3375
|
const sourceCell = rows[sourceRowIndex]?.getVisibleCells()[sourceColIndex];
|
|
3089
3376
|
if (!targetRow || !targetCell || !sourceCell) continue;
|
|
3377
|
+
if (!isColumnEditable(targetCell.column.columnDef)) continue;
|
|
3378
|
+
if (isProtectedColumn(sourceCell.column.columnDef)) continue;
|
|
3090
3379
|
const accessorKey = getColumnAccessorKey2(
|
|
3091
3380
|
targetCell.column.columnDef
|
|
3092
3381
|
);
|
|
@@ -3108,13 +3397,22 @@ function collectFillChanges(rows, sourceBounds, fillBounds) {
|
|
|
3108
3397
|
);
|
|
3109
3398
|
}
|
|
3110
3399
|
function applyFillData(data, rows, sourceBounds, fillBounds) {
|
|
3111
|
-
const newData = data.map((row) => ({ ...row }));
|
|
3112
3400
|
const targets = collectFillTargets(rows, sourceBounds, fillBounds);
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
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
|
+
);
|
|
3118
3416
|
}
|
|
3119
3417
|
function hasFillExtension(sourceBounds, fillBounds) {
|
|
3120
3418
|
if (!sourceBounds) return false;
|
|
@@ -3135,14 +3433,59 @@ function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
|
3135
3433
|
if (firstDepth !== 0) return false;
|
|
3136
3434
|
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
3137
3435
|
}
|
|
3138
|
-
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) {
|
|
3139
3482
|
if (!text) return { values: [], depths: [] };
|
|
3140
3483
|
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
3141
3484
|
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
3142
3485
|
if (!withoutTrailing) return { values: [], depths: [] };
|
|
3143
|
-
const rows = withoutTrailing
|
|
3486
|
+
const rows = splitTSV(withoutTrailing);
|
|
3144
3487
|
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
3145
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3488
|
+
const treatAsDepth = options?.treeDepth !== "none" && looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3146
3489
|
const values = [];
|
|
3147
3490
|
const depths = [];
|
|
3148
3491
|
for (let index = 0; index < rows.length; index += 1) {
|
|
@@ -3169,8 +3512,8 @@ function resolvePasteColumnIds(rows, startCol, width) {
|
|
|
3169
3512
|
}
|
|
3170
3513
|
return columnIds;
|
|
3171
3514
|
}
|
|
3172
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
3173
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
3515
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow, options) {
|
|
3516
|
+
const { values, depths } = parseClipboardTSVWithDepths(text, options);
|
|
3174
3517
|
if (values.length === 0) return null;
|
|
3175
3518
|
const width = Math.max(...values.map((row) => row.length), 0);
|
|
3176
3519
|
if (width === 0) return null;
|
|
@@ -3203,6 +3546,19 @@ function isEditablePasteTarget(target) {
|
|
|
3203
3546
|
}
|
|
3204
3547
|
|
|
3205
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
|
+
}
|
|
3206
3562
|
function isFocusOutsideRoot(rootRef) {
|
|
3207
3563
|
const root = rootRef?.current;
|
|
3208
3564
|
if (!root) return false;
|
|
@@ -3215,29 +3571,50 @@ function useCellSelection({
|
|
|
3215
3571
|
rows,
|
|
3216
3572
|
enabled = true,
|
|
3217
3573
|
columnCount = 0,
|
|
3574
|
+
columnSignature,
|
|
3218
3575
|
enableSubtreeCopy = false,
|
|
3576
|
+
escapeCopyFormulas = false,
|
|
3219
3577
|
enableInsertPaste = true,
|
|
3220
3578
|
onDataChange,
|
|
3221
3579
|
onBatchChange,
|
|
3222
3580
|
onRowsPaste,
|
|
3223
3581
|
onCellNavigate,
|
|
3224
3582
|
cellRendererRegistry,
|
|
3225
|
-
rootRef
|
|
3583
|
+
rootRef,
|
|
3584
|
+
enableWasdNavigation = true,
|
|
3585
|
+
onEditKey,
|
|
3586
|
+
onClearKey
|
|
3226
3587
|
}) {
|
|
3227
3588
|
const ownerRef = useRef5(createCellSelectionOwner());
|
|
3228
3589
|
const [dragState, setDragState] = useState3(INITIAL_DRAG_STATE);
|
|
3229
3590
|
const pendingPasteModeRef = useRef5(null);
|
|
3230
3591
|
const dragStateRef = useRef5(dragState);
|
|
3231
3592
|
const onCellNavigateRef = useRef5(onCellNavigate);
|
|
3593
|
+
const onEditKeyRef = useRef5(onEditKey);
|
|
3594
|
+
const onClearKeyRef = useRef5(onClearKey);
|
|
3232
3595
|
dragStateRef.current = dragState;
|
|
3233
3596
|
onCellNavigateRef.current = onCellNavigate;
|
|
3234
|
-
|
|
3235
|
-
|
|
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]);
|
|
3236
3613
|
const handleCellMouseDown = useCallback3(
|
|
3237
3614
|
(rowIndex, colIndex, options) => {
|
|
3238
3615
|
if (!enabled) return;
|
|
3239
3616
|
claimCellSelectionOwner(ownerRef.current);
|
|
3240
|
-
|
|
3617
|
+
updateDragState((prev) => {
|
|
3241
3618
|
if (options?.shiftKey && prev.start) {
|
|
3242
3619
|
return {
|
|
3243
3620
|
...prev,
|
|
@@ -3258,28 +3635,30 @@ function useCellSelection({
|
|
|
3258
3635
|
};
|
|
3259
3636
|
});
|
|
3260
3637
|
},
|
|
3261
|
-
[enabled]
|
|
3638
|
+
[enabled, updateDragState]
|
|
3262
3639
|
);
|
|
3263
3640
|
const handleCellMouseEnter = useCallback3(
|
|
3264
3641
|
(rowIndex, colIndex) => {
|
|
3265
3642
|
if (!enabled) return;
|
|
3266
|
-
|
|
3643
|
+
updateDragState((prev) => {
|
|
3267
3644
|
if (prev.isSelecting) {
|
|
3645
|
+
if (prev.end?.row === rowIndex && prev.end.col === colIndex) return prev;
|
|
3268
3646
|
return { ...prev, end: { row: rowIndex, col: colIndex } };
|
|
3269
3647
|
}
|
|
3270
3648
|
if (prev.isFillDragging) {
|
|
3649
|
+
if (prev.fillEnd?.row === rowIndex && prev.fillEnd.col === colIndex) return prev;
|
|
3271
3650
|
return { ...prev, fillEnd: { row: rowIndex, col: colIndex } };
|
|
3272
3651
|
}
|
|
3273
3652
|
return prev;
|
|
3274
3653
|
});
|
|
3275
3654
|
},
|
|
3276
|
-
[enabled]
|
|
3655
|
+
[enabled, updateDragState]
|
|
3277
3656
|
);
|
|
3278
3657
|
const handleFillHandleMouseDown = useCallback3(
|
|
3279
3658
|
(rowIndex, colIndex) => {
|
|
3280
3659
|
if (!enabled) return;
|
|
3281
3660
|
claimCellSelectionOwner(ownerRef.current);
|
|
3282
|
-
|
|
3661
|
+
updateDragState((prev) => {
|
|
3283
3662
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
3284
3663
|
if (!bounds) return prev;
|
|
3285
3664
|
return {
|
|
@@ -3291,7 +3670,7 @@ function useCellSelection({
|
|
|
3291
3670
|
};
|
|
3292
3671
|
});
|
|
3293
3672
|
},
|
|
3294
|
-
[enabled]
|
|
3673
|
+
[enabled, updateDragState]
|
|
3295
3674
|
);
|
|
3296
3675
|
const clearSelection = useCallback3(() => {
|
|
3297
3676
|
const prev = dragStateRef.current;
|
|
@@ -3310,6 +3689,130 @@ function useCellSelection({
|
|
|
3310
3689
|
useEffect5(() => {
|
|
3311
3690
|
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
3312
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]);
|
|
3313
3816
|
useEffect5(() => {
|
|
3314
3817
|
if (!enabled) return;
|
|
3315
3818
|
const handleKeyDown = (e) => {
|
|
@@ -3319,6 +3822,7 @@ function useCellSelection({
|
|
|
3319
3822
|
return;
|
|
3320
3823
|
}
|
|
3321
3824
|
if (isFocusOutsideRoot(rootRef)) return;
|
|
3825
|
+
if (!enableWasdNavigation && e.key.length === 1) return;
|
|
3322
3826
|
const delta = getCellNavigationDelta(e.key);
|
|
3323
3827
|
if (!delta) return;
|
|
3324
3828
|
const prev = dragStateRef.current;
|
|
@@ -3358,14 +3862,15 @@ function useCellSelection({
|
|
|
3358
3862
|
};
|
|
3359
3863
|
window.addEventListener("keydown", handleKeyDown);
|
|
3360
3864
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3361
|
-
}, [columnCount, enabled, rows]);
|
|
3865
|
+
}, [columnCount, enableWasdNavigation, enabled, rows]);
|
|
3362
3866
|
const copySelection = useCallback3(
|
|
3363
3867
|
async (options) => {
|
|
3364
3868
|
if (!enabled || !activeSelectionBounds) return false;
|
|
3365
3869
|
const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
|
|
3366
3870
|
return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
|
|
3367
3871
|
registry: cellRendererRegistry,
|
|
3368
|
-
root: rootRef?.current
|
|
3872
|
+
root: rootRef?.current,
|
|
3873
|
+
escapeFormulas: escapeCopyFormulas
|
|
3369
3874
|
});
|
|
3370
3875
|
},
|
|
3371
3876
|
[
|
|
@@ -3373,6 +3878,7 @@ function useCellSelection({
|
|
|
3373
3878
|
cellRendererRegistry,
|
|
3374
3879
|
enableSubtreeCopy,
|
|
3375
3880
|
enabled,
|
|
3881
|
+
escapeCopyFormulas,
|
|
3376
3882
|
rootRef,
|
|
3377
3883
|
rows
|
|
3378
3884
|
]
|
|
@@ -3390,6 +3896,7 @@ function useCellSelection({
|
|
|
3390
3896
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
3391
3897
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
3392
3898
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
3899
|
+
if (hasPageTextSelectionOutside(rootRef?.current)) return;
|
|
3393
3900
|
e.preventDefault();
|
|
3394
3901
|
void copySelection({ includeDescendants: isSubtreeShortcut });
|
|
3395
3902
|
};
|
|
@@ -3405,9 +3912,17 @@ function useCellSelection({
|
|
|
3405
3912
|
activeSelectionBounds.startCol,
|
|
3406
3913
|
text,
|
|
3407
3914
|
mode,
|
|
3408
|
-
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" }
|
|
3409
3919
|
);
|
|
3410
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
|
+
});
|
|
3411
3926
|
onRowsPaste(payload);
|
|
3412
3927
|
return true;
|
|
3413
3928
|
},
|
|
@@ -3438,7 +3953,10 @@ function useCellSelection({
|
|
|
3438
3953
|
void (async () => {
|
|
3439
3954
|
try {
|
|
3440
3955
|
const text = await navigator.clipboard.readText();
|
|
3441
|
-
if (pasteHandledRef.current)
|
|
3956
|
+
if (pasteHandledRef.current) {
|
|
3957
|
+
pasteHandledRef.current = false;
|
|
3958
|
+
return;
|
|
3959
|
+
}
|
|
3442
3960
|
if (pendingPasteModeRef.current !== mode) return;
|
|
3443
3961
|
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3444
3962
|
if (!text) return;
|
|
@@ -3463,6 +3981,7 @@ function useCellSelection({
|
|
|
3463
3981
|
}
|
|
3464
3982
|
const mode = pendingPasteModeRef.current ?? "overwrite";
|
|
3465
3983
|
if (pasteHandledRef.current) {
|
|
3984
|
+
pasteHandledRef.current = false;
|
|
3466
3985
|
e.preventDefault();
|
|
3467
3986
|
return;
|
|
3468
3987
|
}
|
|
@@ -3489,39 +4008,41 @@ function useCellSelection({
|
|
|
3489
4008
|
useEffect5(() => {
|
|
3490
4009
|
if (!enabled) return;
|
|
3491
4010
|
const handleMouseUp = () => {
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
} else if (onDataChange) {
|
|
3504
|
-
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);
|
|
3505
4022
|
}
|
|
4023
|
+
} else if (onDataChange) {
|
|
4024
|
+
onDataChange(applyFillData(data, rows, sourceBounds, newBounds));
|
|
3506
4025
|
}
|
|
3507
|
-
return {
|
|
3508
|
-
isSelecting: false,
|
|
3509
|
-
isFillDragging: false,
|
|
3510
|
-
start: { row: newBounds.startRow, col: newBounds.startCol },
|
|
3511
|
-
end: { row: newBounds.endRow, col: newBounds.endCol },
|
|
3512
|
-
fillAnchor: null,
|
|
3513
|
-
fillEnd: null
|
|
3514
|
-
};
|
|
3515
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 };
|
|
3516
4037
|
}
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
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);
|
|
3525
4046
|
};
|
|
3526
4047
|
window.addEventListener("mouseup", handleMouseUp);
|
|
3527
4048
|
return () => window.removeEventListener("mouseup", handleMouseUp);
|
|
@@ -3533,7 +4054,9 @@ function useCellSelection({
|
|
|
3533
4054
|
handleCellMouseEnter,
|
|
3534
4055
|
handleFillHandleMouseDown,
|
|
3535
4056
|
clearSelection,
|
|
3536
|
-
copySelection
|
|
4057
|
+
copySelection,
|
|
4058
|
+
selectCell,
|
|
4059
|
+
focusSelection
|
|
3537
4060
|
};
|
|
3538
4061
|
}
|
|
3539
4062
|
|
|
@@ -3596,16 +4119,35 @@ import {
|
|
|
3596
4119
|
useCallback as useCallback4,
|
|
3597
4120
|
useEffect as useEffect6,
|
|
3598
4121
|
useId,
|
|
3599
|
-
useMemo as
|
|
4122
|
+
useMemo as useMemo4,
|
|
3600
4123
|
useRef as useRef6,
|
|
3601
4124
|
useState as useState4
|
|
3602
4125
|
} from "react";
|
|
3603
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
|
+
}
|
|
3604
4145
|
function useInlineSearch({
|
|
3605
4146
|
enabled = false,
|
|
3606
4147
|
rowCount,
|
|
3607
4148
|
columnCount,
|
|
3608
4149
|
getCellValue,
|
|
4150
|
+
contentKey,
|
|
3609
4151
|
initialStartRow = 0,
|
|
3610
4152
|
showSearch: controlledShowSearch,
|
|
3611
4153
|
searchValue: controlledSearchValue,
|
|
@@ -3814,6 +4356,7 @@ function useInlineSearch({
|
|
|
3814
4356
|
}
|
|
3815
4357
|
beginSearch(searchValue);
|
|
3816
4358
|
}, [
|
|
4359
|
+
contentKey,
|
|
3817
4360
|
beginSearch,
|
|
3818
4361
|
cancelSearch,
|
|
3819
4362
|
controlledSearchResults,
|
|
@@ -3834,6 +4377,9 @@ function useInlineSearch({
|
|
|
3834
4377
|
if (!focusInside && active !== document.body) {
|
|
3835
4378
|
return;
|
|
3836
4379
|
}
|
|
4380
|
+
if (!focusInside && !(lastPointerTarget instanceof Node && root.contains(lastPointerTarget))) {
|
|
4381
|
+
return;
|
|
4382
|
+
}
|
|
3837
4383
|
}
|
|
3838
4384
|
event.preventDefault();
|
|
3839
4385
|
event.stopPropagation();
|
|
@@ -3847,14 +4393,18 @@ function useInlineSearch({
|
|
|
3847
4393
|
}
|
|
3848
4394
|
};
|
|
3849
4395
|
window.addEventListener("keydown", handleKeyDown, true);
|
|
3850
|
-
|
|
4396
|
+
const releaseInstance = registerSearchInstance();
|
|
4397
|
+
return () => {
|
|
4398
|
+
window.removeEventListener("keydown", handleKeyDown, true);
|
|
4399
|
+
releaseInstance();
|
|
4400
|
+
};
|
|
3851
4401
|
}, [controlledShowSearch, enabled, rootRef, showSearch]);
|
|
3852
4402
|
useEffect6(() => () => cancelSearch(), [cancelSearch]);
|
|
3853
|
-
const searchMatchKeys =
|
|
4403
|
+
const searchMatchKeys = useMemo4(
|
|
3854
4404
|
() => buildSearchMatchKeys(searchResults),
|
|
3855
4405
|
[searchResults]
|
|
3856
4406
|
);
|
|
3857
|
-
const activeMatch =
|
|
4407
|
+
const activeMatch = useMemo4(() => {
|
|
3858
4408
|
if (!searchStatus || searchStatus.selectedIndex < 0) return null;
|
|
3859
4409
|
return searchResults[searchStatus.selectedIndex] ?? null;
|
|
3860
4410
|
}, [searchResults, searchStatus]);
|
|
@@ -3924,7 +4474,11 @@ var DEFAULT_DATA_TABLE_LABELS = {
|
|
|
3924
4474
|
searchResultHint: "Type to search",
|
|
3925
4475
|
searchPrevious: "Previous result",
|
|
3926
4476
|
searchNext: "Next result",
|
|
3927
|
-
searchClose: "Close search"
|
|
4477
|
+
searchClose: "Close search",
|
|
4478
|
+
searchResultCount: formatSearchResultLabel,
|
|
4479
|
+
protectedCell: "protected",
|
|
4480
|
+
paginationPrevious: "Previous page",
|
|
4481
|
+
paginationNext: "Next page"
|
|
3928
4482
|
};
|
|
3929
4483
|
function resolveDataTableLabels(partial) {
|
|
3930
4484
|
return {
|
|
@@ -3934,6 +4488,9 @@ function resolveDataTableLabels(partial) {
|
|
|
3934
4488
|
}
|
|
3935
4489
|
|
|
3936
4490
|
// src/core/useGlideTable.ts
|
|
4491
|
+
function isProductionBuild() {
|
|
4492
|
+
return typeof process !== "undefined" && process?.env?.NODE_ENV === "production";
|
|
4493
|
+
}
|
|
3937
4494
|
var EMPTY_COLUMN_FREEZE_OFFSETS = /* @__PURE__ */ new Map();
|
|
3938
4495
|
var EMPTY_SEARCH_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
3939
4496
|
function useGlideTable(options) {
|
|
@@ -3955,18 +4512,24 @@ function useGlideTable(options) {
|
|
|
3955
4512
|
selectOnRowClick = true,
|
|
3956
4513
|
enableCellSelection = true,
|
|
3957
4514
|
onDataChange,
|
|
3958
|
-
onCellChange,
|
|
3959
|
-
onBatchChange,
|
|
4515
|
+
onCellChange: onCellChangeProp,
|
|
4516
|
+
onBatchChange: onBatchChangeProp,
|
|
3960
4517
|
cellRenderers,
|
|
3961
4518
|
preserveRowSelection = false,
|
|
3962
|
-
toggleField,
|
|
3963
|
-
|
|
3964
|
-
|
|
4519
|
+
toggleField: toggleFieldProp,
|
|
4520
|
+
idField,
|
|
4521
|
+
childField: childFieldProp,
|
|
4522
|
+
parentIdField,
|
|
4523
|
+
flattenField: flattenFieldProp,
|
|
4524
|
+
childrenField,
|
|
3965
4525
|
qtyField,
|
|
4526
|
+
expandColumn,
|
|
3966
4527
|
expandedRows: controlledExpandedRows,
|
|
3967
4528
|
onExpandedRowsChange,
|
|
3968
4529
|
preventExpand = false,
|
|
4530
|
+
autoExpandOnLoad = true,
|
|
3969
4531
|
enableSubtreeCopy,
|
|
4532
|
+
escapeCopyFormulas = false,
|
|
3970
4533
|
onCopyActionsReady,
|
|
3971
4534
|
onRowsPaste,
|
|
3972
4535
|
enableInsertPaste,
|
|
@@ -3987,9 +4550,28 @@ function useGlideTable(options) {
|
|
|
3987
4550
|
onSearchValueChange,
|
|
3988
4551
|
onSearchClose,
|
|
3989
4552
|
searchResults,
|
|
3990
|
-
onSearchResultsChanged
|
|
4553
|
+
onSearchResultsChanged,
|
|
4554
|
+
enableWasdNavigation = true
|
|
3991
4555
|
} = options;
|
|
3992
|
-
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(() => {
|
|
3993
4575
|
const resolved = resolveDataTableLabels(labelsProp);
|
|
3994
4576
|
return {
|
|
3995
4577
|
...resolved,
|
|
@@ -4006,11 +4588,11 @@ function useGlideTable(options) {
|
|
|
4006
4588
|
const [internalExpandedRows, setInternalExpandedRows] = useState5(
|
|
4007
4589
|
() => /* @__PURE__ */ new Set()
|
|
4008
4590
|
);
|
|
4009
|
-
const [
|
|
4591
|
+
const [hoverStore] = useState5(createRowHoverStore);
|
|
4010
4592
|
const scrollRef = useRef7(null);
|
|
4011
4593
|
const rootRef = useRef7(null);
|
|
4012
4594
|
const escapeDismissOwnerRef = useRef7(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
4013
|
-
const cellRendererRegistry =
|
|
4595
|
+
const cellRendererRegistry = useMemo5(
|
|
4014
4596
|
() => createCellRendererRegistry(cellRenderers),
|
|
4015
4597
|
[cellRenderers]
|
|
4016
4598
|
);
|
|
@@ -4029,7 +4611,7 @@ function useGlideTable(options) {
|
|
|
4029
4611
|
);
|
|
4030
4612
|
const columnSizing = controlledColumnSizing ?? internalColumnSizing;
|
|
4031
4613
|
const columnOrder = controlledColumnOrder ?? internalColumnOrder;
|
|
4032
|
-
const tableColumns =
|
|
4614
|
+
const tableColumns = useMemo5(() => {
|
|
4033
4615
|
if (!enableColumnReorder) return columns;
|
|
4034
4616
|
return applyLeafColumnOrder(columns, columnOrder);
|
|
4035
4617
|
}, [columnOrder, columns, enableColumnReorder]);
|
|
@@ -4063,8 +4645,10 @@ function useGlideTable(options) {
|
|
|
4063
4645
|
qtyField,
|
|
4064
4646
|
expandedRows,
|
|
4065
4647
|
onExpandedRowsChange: enableExpand ? handleExpandedRowsChange : void 0,
|
|
4066
|
-
preventExpand
|
|
4648
|
+
preventExpand,
|
|
4649
|
+
autoExpandOnLoad
|
|
4067
4650
|
});
|
|
4651
|
+
const sourceData = useMemo5(() => data ?? [], [data]);
|
|
4068
4652
|
const table = useReactTable({
|
|
4069
4653
|
data: tableData,
|
|
4070
4654
|
columns: tableColumns,
|
|
@@ -4103,15 +4687,19 @@ function useGlideTable(options) {
|
|
|
4103
4687
|
);
|
|
4104
4688
|
},
|
|
4105
4689
|
getCoreRowModel: getCoreRowModel(),
|
|
4106
|
-
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
|
+
)
|
|
4107
4695
|
});
|
|
4108
|
-
const rowSpanColumnKeys =
|
|
4696
|
+
const rowSpanColumnKeys = useMemo5(() => {
|
|
4109
4697
|
if (!enableRowSpan) return [];
|
|
4110
4698
|
return collectRowSpanColumns(columns);
|
|
4111
4699
|
}, [enableRowSpan, columns]);
|
|
4112
4700
|
const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
|
|
4113
4701
|
const primaryRowSpanColumnId = rowSpanColumnKeys[0]?.columnId;
|
|
4114
|
-
const columnRowSpanMap =
|
|
4702
|
+
const columnRowSpanMap = useMemo5(
|
|
4115
4703
|
() => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
|
|
4116
4704
|
[tableData, rowSpanColumnKeys]
|
|
4117
4705
|
);
|
|
@@ -4120,7 +4708,21 @@ function useGlideTable(options) {
|
|
|
4120
4708
|
const rows = table.getRowModel().rows;
|
|
4121
4709
|
const columnCount = table.getAllLeafColumns().length || 1;
|
|
4122
4710
|
const visibleLeafColumns = table.getVisibleLeafColumns();
|
|
4123
|
-
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(() => {
|
|
4124
4726
|
if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
|
|
4125
4727
|
return buildColumnFreezeOffsets(
|
|
4126
4728
|
visibleLeafColumns.map((column) => ({
|
|
@@ -4140,7 +4742,7 @@ function useGlideTable(options) {
|
|
|
4140
4742
|
const totalSize = rowVirtualizer.getTotalSize();
|
|
4141
4743
|
const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
|
|
4142
4744
|
const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
|
|
4143
|
-
const selectedRowIndices =
|
|
4745
|
+
const selectedRowIndices = useMemo5(() => {
|
|
4144
4746
|
const indices = /* @__PURE__ */ new Set();
|
|
4145
4747
|
for (const selectedRow of selectedRows) {
|
|
4146
4748
|
indices.add(selectedRow.index);
|
|
@@ -4162,7 +4764,7 @@ function useGlideTable(options) {
|
|
|
4162
4764
|
const cell = scrollElement.querySelector(
|
|
4163
4765
|
`[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
|
|
4164
4766
|
);
|
|
4165
|
-
if (cell instanceof HTMLElement) {
|
|
4767
|
+
if (cell instanceof HTMLElement && typeof cell.scrollIntoView === "function") {
|
|
4166
4768
|
cell.scrollIntoView({ block: blockAlign, inline: "nearest" });
|
|
4167
4769
|
}
|
|
4168
4770
|
};
|
|
@@ -4180,6 +4782,10 @@ function useGlideTable(options) {
|
|
|
4180
4782
|
},
|
|
4181
4783
|
[scrollCellIntoView]
|
|
4182
4784
|
);
|
|
4785
|
+
const editKeyRef = useRef7(() => {
|
|
4786
|
+
});
|
|
4787
|
+
const clearKeyRef = useRef7(() => {
|
|
4788
|
+
});
|
|
4183
4789
|
const {
|
|
4184
4790
|
dragState,
|
|
4185
4791
|
activeSelectionBounds,
|
|
@@ -4187,20 +4793,27 @@ function useGlideTable(options) {
|
|
|
4187
4793
|
handleCellMouseEnter,
|
|
4188
4794
|
handleFillHandleMouseDown,
|
|
4189
4795
|
clearSelection: clearCellSelection,
|
|
4190
|
-
copySelection
|
|
4796
|
+
copySelection,
|
|
4797
|
+
selectCell,
|
|
4798
|
+
focusSelection
|
|
4191
4799
|
} = useCellSelection({
|
|
4192
|
-
data:
|
|
4800
|
+
data: sourceData,
|
|
4193
4801
|
rows,
|
|
4194
4802
|
enabled: enableCellSelection,
|
|
4195
4803
|
columnCount: visibleLeafColumns.length,
|
|
4804
|
+
columnSignature: visibleLeafColumns.map((column) => column.id).join("\0"),
|
|
4196
4805
|
enableSubtreeCopy: resolvedEnableSubtreeCopy,
|
|
4806
|
+
escapeCopyFormulas,
|
|
4197
4807
|
enableInsertPaste: enableInsertPaste ?? true,
|
|
4198
4808
|
onDataChange,
|
|
4199
4809
|
onBatchChange,
|
|
4200
4810
|
onRowsPaste,
|
|
4201
4811
|
onCellNavigate: handleCellNavigate,
|
|
4202
4812
|
cellRendererRegistry,
|
|
4203
|
-
rootRef
|
|
4813
|
+
rootRef,
|
|
4814
|
+
enableWasdNavigation,
|
|
4815
|
+
onEditKey: (position) => editKeyRef.current(position),
|
|
4816
|
+
onClearKey: (bounds) => clearKeyRef.current(bounds)
|
|
4204
4817
|
});
|
|
4205
4818
|
const clearRowSelection = useCallback5(() => {
|
|
4206
4819
|
if (rowSelectionMode === "none") return;
|
|
@@ -4221,22 +4834,79 @@ function useGlideTable(options) {
|
|
|
4221
4834
|
const {
|
|
4222
4835
|
editingCell,
|
|
4223
4836
|
draftValue,
|
|
4837
|
+
draftInvalid,
|
|
4838
|
+
setDraftInvalid,
|
|
4224
4839
|
setDraftValue,
|
|
4225
4840
|
startEdit,
|
|
4226
4841
|
commitEdit,
|
|
4227
4842
|
cancelEdit
|
|
4228
|
-
} = 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]);
|
|
4229
4893
|
const commitRenderedCellValue = useCallback5(
|
|
4230
|
-
(rowId, columnId, value) =>
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
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]
|
|
4240
4910
|
);
|
|
4241
4911
|
const getCellContext = useCallback5(
|
|
4242
4912
|
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
@@ -4264,27 +4934,14 @@ function useGlideTable(options) {
|
|
|
4264
4934
|
(row, index) => {
|
|
4265
4935
|
if (getRowId) return getRowId(row, index);
|
|
4266
4936
|
if (enableExpand) {
|
|
4267
|
-
const
|
|
4268
|
-
|
|
4269
|
-
if (idValue != null && String(idValue).length > 0) {
|
|
4270
|
-
return String(idValue);
|
|
4271
|
-
}
|
|
4272
|
-
const uniqueId = record.uniqueId;
|
|
4273
|
-
if (uniqueId != null && String(uniqueId).length > 0) {
|
|
4274
|
-
return String(uniqueId);
|
|
4275
|
-
}
|
|
4276
|
-
if (toggleField) {
|
|
4277
|
-
const toggleValue = record[toggleField];
|
|
4278
|
-
if (toggleValue != null && String(toggleValue).length > 0) {
|
|
4279
|
-
return String(toggleValue);
|
|
4280
|
-
}
|
|
4281
|
-
}
|
|
4937
|
+
const treeKey = getTreeRowKey(row);
|
|
4938
|
+
if (treeKey) return treeKey;
|
|
4282
4939
|
}
|
|
4283
4940
|
return String(index);
|
|
4284
4941
|
},
|
|
4285
|
-
[enableExpand, getRowId
|
|
4942
|
+
[enableExpand, getRowId]
|
|
4286
4943
|
);
|
|
4287
|
-
const searchCorpus =
|
|
4944
|
+
const searchCorpus = useMemo5(() => {
|
|
4288
4945
|
if (!enableInlineSearch) return [];
|
|
4289
4946
|
if (enableExpand && toggleField) {
|
|
4290
4947
|
return buildTreeSearchCorpus(tableData, {
|
|
@@ -4302,35 +4959,66 @@ function useGlideTable(options) {
|
|
|
4302
4959
|
]);
|
|
4303
4960
|
const searchCorpusRef = useRef7(searchCorpus);
|
|
4304
4961
|
searchCorpusRef.current = searchCorpus;
|
|
4305
|
-
const visibleRowIndexById =
|
|
4962
|
+
const visibleRowIndexById = useMemo5(() => {
|
|
4306
4963
|
const map = /* @__PURE__ */ new Map();
|
|
4307
4964
|
for (const row of rows) {
|
|
4308
4965
|
map.set(resolveSearchRowId(row.original, row.index), row.index);
|
|
4309
4966
|
}
|
|
4310
4967
|
return map;
|
|
4311
4968
|
}, [resolveSearchRowId, rows]);
|
|
4312
|
-
const
|
|
4313
|
-
(rowIndex,
|
|
4314
|
-
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
4315
|
-
const column = visibleLeafColumns[colIndex];
|
|
4316
|
-
if (!corpusRow || !column) return void 0;
|
|
4969
|
+
const readSearchRawValue = useCallback5(
|
|
4970
|
+
(corpusRow, rowIndex, column) => {
|
|
4317
4971
|
const visibleIndex = visibleRowIndexById.get(corpusRow.id);
|
|
4318
4972
|
if (visibleIndex !== void 0) {
|
|
4319
4973
|
const visibleRow = rows[visibleIndex];
|
|
4320
4974
|
if (visibleRow) {
|
|
4321
|
-
return visibleRow.getValue(column.id);
|
|
4975
|
+
return { value: visibleRow.getValue(column.id), row: visibleRow };
|
|
4322
4976
|
}
|
|
4323
4977
|
}
|
|
4324
4978
|
const columnDef = column.columnDef;
|
|
4325
4979
|
if ("accessorFn" in columnDef && typeof columnDef.accessorFn === "function") {
|
|
4326
|
-
return columnDef.accessorFn(corpusRow.data, rowIndex);
|
|
4980
|
+
return { value: columnDef.accessorFn(corpusRow.data, rowIndex), row: void 0 };
|
|
4327
4981
|
}
|
|
4328
4982
|
if ("accessorKey" in columnDef && columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
4329
|
-
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;
|
|
4330
5018
|
}
|
|
4331
|
-
return
|
|
5019
|
+
return value;
|
|
4332
5020
|
},
|
|
4333
|
-
[
|
|
5021
|
+
[cellRendererRegistry, readSearchRawValue, visibleLeafColumns]
|
|
4334
5022
|
);
|
|
4335
5023
|
const pendingSearchNavRef = useRef7(null);
|
|
4336
5024
|
const focusSearchResult = useCallback5(
|
|
@@ -4381,11 +5069,19 @@ function useGlideTable(options) {
|
|
|
4381
5069
|
focusSearchResult(pending.colIndex, visibleRowIndex);
|
|
4382
5070
|
}, [focusSearchResult, rows, visibleRowIndexById]);
|
|
4383
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
|
+
);
|
|
4384
5077
|
const inlineSearch = useInlineSearch({
|
|
4385
5078
|
enabled: enableInlineSearch,
|
|
4386
5079
|
rowCount: searchCorpus.length,
|
|
4387
5080
|
columnCount: visibleLeafColumns.length,
|
|
4388
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,
|
|
4389
5085
|
initialStartRow: initialSearchStartRow,
|
|
4390
5086
|
showSearch,
|
|
4391
5087
|
searchValue,
|
|
@@ -4396,7 +5092,7 @@ function useGlideTable(options) {
|
|
|
4396
5092
|
onNavigateToResult: navigateToCorpusSearchResult,
|
|
4397
5093
|
rootRef
|
|
4398
5094
|
});
|
|
4399
|
-
const visibleSearchMatchKeys =
|
|
5095
|
+
const visibleSearchMatchKeys = useMemo5(() => {
|
|
4400
5096
|
if (!enableInlineSearch) return EMPTY_SEARCH_MATCH_KEYS;
|
|
4401
5097
|
return mapSearchResultsToVisibleKeys(
|
|
4402
5098
|
inlineSearch.searchResults,
|
|
@@ -4409,7 +5105,7 @@ function useGlideTable(options) {
|
|
|
4409
5105
|
searchCorpus,
|
|
4410
5106
|
visibleRowIndexById
|
|
4411
5107
|
]);
|
|
4412
|
-
const visibleActiveMatch =
|
|
5108
|
+
const visibleActiveMatch = useMemo5(() => {
|
|
4413
5109
|
if (!enableInlineSearch || !inlineSearch.activeMatch) return null;
|
|
4414
5110
|
return mapSearchResultToVisibleItem(
|
|
4415
5111
|
inlineSearch.activeMatch,
|
|
@@ -4423,11 +5119,14 @@ function useGlideTable(options) {
|
|
|
4423
5119
|
visibleRowIndexById
|
|
4424
5120
|
]);
|
|
4425
5121
|
const clearHover = useCallback5(() => {
|
|
4426
|
-
setHoveredRowIndex(null);
|
|
4427
|
-
}, []);
|
|
4428
|
-
const handleRowHover = useCallback5(
|
|
4429
|
-
|
|
4430
|
-
|
|
5122
|
+
hoverStore.setHoveredRowIndex(null);
|
|
5123
|
+
}, [hoverStore]);
|
|
5124
|
+
const handleRowHover = useCallback5(
|
|
5125
|
+
(rowIndex, _rowData) => {
|
|
5126
|
+
hoverStore.setHoveredRowIndex(rowIndex);
|
|
5127
|
+
},
|
|
5128
|
+
[hoverStore]
|
|
5129
|
+
);
|
|
4431
5130
|
const handleToggleSelect = useCallback5(
|
|
4432
5131
|
(row) => {
|
|
4433
5132
|
if (!row.getCanSelect()) return;
|
|
@@ -4445,14 +5144,14 @@ function useGlideTable(options) {
|
|
|
4445
5144
|
},
|
|
4446
5145
|
[preventExpand, handleExpandedRowsChange, expandedRows]
|
|
4447
5146
|
);
|
|
4448
|
-
const rowContextValue =
|
|
5147
|
+
const rowContextValue = useMemo5(() => {
|
|
4449
5148
|
return {
|
|
4450
5149
|
rowSpan: {
|
|
4451
5150
|
enableRowSpan,
|
|
4452
5151
|
primaryRowSpanKey,
|
|
4453
5152
|
primaryRowSpanColumnId,
|
|
4454
5153
|
columnRowSpanMap,
|
|
4455
|
-
|
|
5154
|
+
hoverStore,
|
|
4456
5155
|
selectedRowIndices,
|
|
4457
5156
|
onRowHover: handleRowHover
|
|
4458
5157
|
},
|
|
@@ -4466,6 +5165,7 @@ function useGlideTable(options) {
|
|
|
4466
5165
|
enableCellSelection,
|
|
4467
5166
|
activeSelectionBounds,
|
|
4468
5167
|
dragState,
|
|
5168
|
+
canFill,
|
|
4469
5169
|
onCellMouseDown: handleCellMouseDownWithCommit,
|
|
4470
5170
|
onCellMouseEnter: handleCellMouseEnter,
|
|
4471
5171
|
onFillHandleMouseDown: handleFillHandleMouseDown
|
|
@@ -4473,18 +5173,23 @@ function useGlideTable(options) {
|
|
|
4473
5173
|
cellEdit: {
|
|
4474
5174
|
editingCell,
|
|
4475
5175
|
draftValue,
|
|
5176
|
+
draftInvalid,
|
|
5177
|
+
onDraftInvalidChange: setDraftInvalid,
|
|
4476
5178
|
onDraftValueChange: setDraftValue,
|
|
4477
5179
|
onStartEdit: startEdit,
|
|
4478
5180
|
onCommitEdit: commitEdit,
|
|
4479
|
-
|
|
5181
|
+
onCommitEditAndMove: commitEditAndMove,
|
|
5182
|
+
onCancelEdit: cancelEditAndRefocus
|
|
4480
5183
|
},
|
|
4481
5184
|
cellRender: {
|
|
4482
5185
|
registry: cellRendererRegistry,
|
|
4483
|
-
commitValue: commitRenderedCellValue
|
|
5186
|
+
commitValue: commitRenderedCellValue,
|
|
5187
|
+
protectedLabel: labels.protectedCell
|
|
4484
5188
|
},
|
|
4485
5189
|
expand: {
|
|
4486
5190
|
enableExpand,
|
|
4487
5191
|
toggleField,
|
|
5192
|
+
expandColumn,
|
|
4488
5193
|
expandedRows,
|
|
4489
5194
|
preventExpand,
|
|
4490
5195
|
onToggleExpand: handleToggleExpand,
|
|
@@ -4509,7 +5214,7 @@ function useGlideTable(options) {
|
|
|
4509
5214
|
primaryRowSpanKey,
|
|
4510
5215
|
primaryRowSpanColumnId,
|
|
4511
5216
|
columnRowSpanMap,
|
|
4512
|
-
|
|
5217
|
+
hoverStore,
|
|
4513
5218
|
selectedRowIndices,
|
|
4514
5219
|
handleRowHover,
|
|
4515
5220
|
rowSelectionMode,
|
|
@@ -4519,19 +5224,25 @@ function useGlideTable(options) {
|
|
|
4519
5224
|
enableCellSelection,
|
|
4520
5225
|
activeSelectionBounds,
|
|
4521
5226
|
dragState,
|
|
5227
|
+
canFill,
|
|
4522
5228
|
handleCellMouseDownWithCommit,
|
|
4523
5229
|
handleCellMouseEnter,
|
|
4524
5230
|
handleFillHandleMouseDown,
|
|
4525
5231
|
editingCell,
|
|
4526
5232
|
draftValue,
|
|
5233
|
+
draftInvalid,
|
|
5234
|
+
setDraftInvalid,
|
|
4527
5235
|
setDraftValue,
|
|
4528
5236
|
startEdit,
|
|
4529
5237
|
commitEdit,
|
|
4530
|
-
|
|
5238
|
+
commitEditAndMove,
|
|
5239
|
+
cancelEditAndRefocus,
|
|
4531
5240
|
cellRendererRegistry,
|
|
4532
5241
|
commitRenderedCellValue,
|
|
5242
|
+
labels.protectedCell,
|
|
4533
5243
|
enableExpand,
|
|
4534
5244
|
toggleField,
|
|
5245
|
+
expandColumn,
|
|
4535
5246
|
expandedRows,
|
|
4536
5247
|
preventExpand,
|
|
4537
5248
|
handleToggleExpand,
|
|
@@ -4579,6 +5290,7 @@ function useGlideTable(options) {
|
|
|
4579
5290
|
handleToggleSelect,
|
|
4580
5291
|
clearHover,
|
|
4581
5292
|
setColumnOrder,
|
|
5293
|
+
handleRootFocus: focusSelection,
|
|
4582
5294
|
copySelection: stableCopySelection,
|
|
4583
5295
|
inlineSearch: {
|
|
4584
5296
|
showSearch: inlineSearch.showSearch,
|
|
@@ -4676,7 +5388,8 @@ function DataTable({
|
|
|
4676
5388
|
handleToggleSelect,
|
|
4677
5389
|
clearHover,
|
|
4678
5390
|
setColumnOrder,
|
|
4679
|
-
inlineSearch
|
|
5391
|
+
inlineSearch,
|
|
5392
|
+
handleRootFocus
|
|
4680
5393
|
} = useGlideTable(glideOptions);
|
|
4681
5394
|
const ToolbarSlot = slots?.Toolbar ?? DataTableToolbar;
|
|
4682
5395
|
const ScrollSlot = slots?.Scroll ?? DefaultScroll;
|
|
@@ -4710,7 +5423,7 @@ function DataTable({
|
|
|
4710
5423
|
observer.observe(element);
|
|
4711
5424
|
return () => observer.disconnect();
|
|
4712
5425
|
}, [enableColumnResize, isPending, scrollRef, rows.length, leafColumnIds.join("|")]);
|
|
4713
|
-
const layoutWidths =
|
|
5426
|
+
const layoutWidths = useMemo6(() => {
|
|
4714
5427
|
if (enableColumnResize) return void 0;
|
|
4715
5428
|
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4716
5429
|
id: column.id,
|
|
@@ -4720,13 +5433,33 @@ function DataTable({
|
|
|
4720
5433
|
}));
|
|
4721
5434
|
return resolveColumnLayoutWidths(containerWidth, columns);
|
|
4722
5435
|
}, [enableColumnResize, containerWidth, table, columnLayoutMetaSignature]);
|
|
4723
|
-
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(() => {
|
|
4724
5457
|
if (!enableColumnFreeze || enableColumnResize || !layoutWidths) {
|
|
4725
5458
|
return rowContextValue.columnFreeze.offsets;
|
|
4726
5459
|
}
|
|
4727
5460
|
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4728
5461
|
id: column.id,
|
|
4729
|
-
size: layoutWidths.get(column.id) ?? column.getSize(),
|
|
5462
|
+
size: measuredWidths.get(column.id) ?? layoutWidths.get(column.id) ?? column.getSize(),
|
|
4730
5463
|
side: resolveColumnFreezeSide(column.columnDef.meta?.frozen)
|
|
4731
5464
|
}));
|
|
4732
5465
|
return buildColumnFreezeOffsets(columns);
|
|
@@ -4734,10 +5467,11 @@ function DataTable({
|
|
|
4734
5467
|
enableColumnFreeze,
|
|
4735
5468
|
enableColumnResize,
|
|
4736
5469
|
layoutWidths,
|
|
5470
|
+
measuredWidths,
|
|
4737
5471
|
rowContextValue.columnFreeze.offsets,
|
|
4738
5472
|
table
|
|
4739
5473
|
]);
|
|
4740
|
-
const contextValue =
|
|
5474
|
+
const contextValue = useMemo6(
|
|
4741
5475
|
() => ({
|
|
4742
5476
|
...rowContextValue,
|
|
4743
5477
|
classNames,
|
|
@@ -4766,6 +5500,10 @@ function DataTable({
|
|
|
4766
5500
|
"div",
|
|
4767
5501
|
{
|
|
4768
5502
|
ref: rootRef,
|
|
5503
|
+
tabIndex: enableCellSelection ? 0 : void 0,
|
|
5504
|
+
onFocus: enableCellSelection ? (event) => {
|
|
5505
|
+
if (event.target === event.currentTarget) handleRootFocus();
|
|
5506
|
+
} : void 0,
|
|
4769
5507
|
className: cn(
|
|
4770
5508
|
"DataTableJSX",
|
|
4771
5509
|
!enableCellSelection && "DataTableJSX--no-cell-selection",
|
|
@@ -4786,6 +5524,7 @@ function DataTable({
|
|
|
4786
5524
|
summary,
|
|
4787
5525
|
selectedCount,
|
|
4788
5526
|
selectionLabel,
|
|
5527
|
+
countLabel: labels.count,
|
|
4789
5528
|
toolbar,
|
|
4790
5529
|
classNames
|
|
4791
5530
|
}
|
|
@@ -4804,6 +5543,7 @@ function DataTable({
|
|
|
4804
5543
|
previousLabel: labels.searchPrevious,
|
|
4805
5544
|
nextLabel: labels.searchNext,
|
|
4806
5545
|
closeLabel: labels.searchClose,
|
|
5546
|
+
formatResult: labels.searchResultCount,
|
|
4807
5547
|
rowsTotal: inlineSearch.searchRowCount,
|
|
4808
5548
|
classNames,
|
|
4809
5549
|
onSearchValueChange: inlineSearch.setSearchValue,
|
|
@@ -4853,6 +5593,8 @@ function DataTable({
|
|
|
4853
5593
|
(leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
|
|
4854
5594
|
);
|
|
4855
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";
|
|
4856
5598
|
const dropEdge = !isPlaceholder && dropTarget?.columnId === header.column.id ? dropTarget.edge : void 0;
|
|
4857
5599
|
return /* @__PURE__ */ jsxs6(
|
|
4858
5600
|
"th",
|
|
@@ -4868,7 +5610,8 @@ function DataTable({
|
|
|
4868
5610
|
"data-resizing": header.column.getIsResizing() ? "" : void 0,
|
|
4869
5611
|
"data-frozen": freezeOffset?.side,
|
|
4870
5612
|
"data-freeze-edge": getColumnFreezeEdgeAttr(freezeOffset),
|
|
4871
|
-
"
|
|
5613
|
+
"data-leaf-column-id": isLeafHeader ? header.column.id : void 0,
|
|
5614
|
+
"aria-sort": ariaSort,
|
|
4872
5615
|
title: canDrag ? labels.reorderColumn : void 0,
|
|
4873
5616
|
onPointerDown: enableColumnReorder ? (event) => onHeaderPointerDown(event, {
|
|
4874
5617
|
columnId: header.column.id,
|
|
@@ -4895,7 +5638,31 @@ function DataTable({
|
|
|
4895
5638
|
role: "separator",
|
|
4896
5639
|
"aria-orientation": "vertical",
|
|
4897
5640
|
"aria-label": labels.resizeColumn,
|
|
5641
|
+
"aria-valuenow": header.getSize(),
|
|
5642
|
+
tabIndex: 0,
|
|
4898
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
|
+
},
|
|
4899
5666
|
className: cn(
|
|
4900
5667
|
"data-table-resize-handle",
|
|
4901
5668
|
classNames?.resizeHandle
|
|
@@ -5003,7 +5770,10 @@ function DataTable({
|
|
|
5003
5770
|
}
|
|
5004
5771
|
|
|
5005
5772
|
// src/components/ui/table/components/Table/Table.tsx
|
|
5006
|
-
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";
|
|
5007
5777
|
|
|
5008
5778
|
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
5009
5779
|
import { useCallback as useCallback6 } from "react";
|
|
@@ -5021,12 +5791,16 @@ function ResolvedTableCell({
|
|
|
5021
5791
|
},
|
|
5022
5792
|
[cellRender, columnId, row.id]
|
|
5023
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
|
+
}
|
|
5024
5798
|
const ctx = {
|
|
5025
5799
|
value,
|
|
5026
5800
|
row,
|
|
5027
5801
|
index: row.index,
|
|
5028
5802
|
columnId,
|
|
5029
|
-
cellProps
|
|
5803
|
+
cellProps,
|
|
5030
5804
|
update
|
|
5031
5805
|
};
|
|
5032
5806
|
if (meta?.cellRender) {
|
|
@@ -5041,12 +5815,16 @@ function ResolvedTableCell({
|
|
|
5041
5815
|
|
|
5042
5816
|
// src/components/ui/table/components/Table/buildColumnDef.tsx
|
|
5043
5817
|
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
5818
|
+
var TableSortContext = createContext2(null);
|
|
5044
5819
|
function SortableHeader({
|
|
5045
5820
|
label,
|
|
5046
5821
|
field,
|
|
5047
|
-
sort,
|
|
5048
|
-
onSort
|
|
5822
|
+
sort: sortProp,
|
|
5823
|
+
onSort: onSortProp
|
|
5049
5824
|
}) {
|
|
5825
|
+
const context = use2(TableSortContext);
|
|
5826
|
+
const sort = context ? context.sort : sortProp;
|
|
5827
|
+
const onSort = context ? context.onSort : onSortProp;
|
|
5050
5828
|
const isActive = sort?.field === field;
|
|
5051
5829
|
const Icon = isActive ? sort.direction === "asc" ? ArrowUp : ArrowDown : ArrowUpDown;
|
|
5052
5830
|
return /* @__PURE__ */ jsxs7(
|
|
@@ -5065,7 +5843,7 @@ function SortableHeader({
|
|
|
5065
5843
|
}
|
|
5066
5844
|
);
|
|
5067
5845
|
}
|
|
5068
|
-
function buildColumnDef(props, sort, onSort) {
|
|
5846
|
+
function buildColumnDef(props, sort, onSort, headerCache) {
|
|
5069
5847
|
const {
|
|
5070
5848
|
field,
|
|
5071
5849
|
virtual = false,
|
|
@@ -5091,8 +5869,29 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5091
5869
|
className,
|
|
5092
5870
|
headerClassName,
|
|
5093
5871
|
render,
|
|
5094
|
-
copyValue
|
|
5872
|
+
copyValue,
|
|
5873
|
+
searchValue
|
|
5095
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
|
+
}
|
|
5096
5895
|
return {
|
|
5097
5896
|
id: field,
|
|
5098
5897
|
...!virtual ? { accessorKey: field } : {},
|
|
@@ -5100,18 +5899,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5100
5899
|
...minResizeWidth != null ? { minSize: minResizeWidth } : {},
|
|
5101
5900
|
...maxResizeWidth != null ? { maxSize: maxResizeWidth } : {},
|
|
5102
5901
|
...resizable === false ? { enableResizing: false } : {},
|
|
5103
|
-
header
|
|
5104
|
-
SortableHeader,
|
|
5105
|
-
{
|
|
5106
|
-
label: children,
|
|
5107
|
-
field,
|
|
5108
|
-
sort,
|
|
5109
|
-
onSort
|
|
5110
|
-
}
|
|
5111
|
-
) : (
|
|
5112
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
5113
|
-
() => children
|
|
5114
|
-
),
|
|
5902
|
+
header,
|
|
5115
5903
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
5116
5904
|
cell: (info) => /* @__PURE__ */ jsx8(ResolvedTableCell, { info }),
|
|
5117
5905
|
meta: {
|
|
@@ -5126,6 +5914,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5126
5914
|
cellProps,
|
|
5127
5915
|
cellRender: render,
|
|
5128
5916
|
copyValue,
|
|
5917
|
+
searchValue,
|
|
5918
|
+
sortDirection: sortable ? sort?.field === field ? sort.direction : false : void 0,
|
|
5129
5919
|
frozen,
|
|
5130
5920
|
reorderable,
|
|
5131
5921
|
width,
|
|
@@ -5143,12 +5933,12 @@ function resolveGroupId(props, index) {
|
|
|
5143
5933
|
}
|
|
5144
5934
|
return `group:${index}`;
|
|
5145
5935
|
}
|
|
5146
|
-
function buildColumnDefsFromTree(nodes, sort, onSort) {
|
|
5936
|
+
function buildColumnDefsFromTree(nodes, sort, onSort, headerCache) {
|
|
5147
5937
|
return nodes.map((node, index) => {
|
|
5148
5938
|
if (node.type === "leaf") {
|
|
5149
|
-
return buildColumnDef(node.props, sort, onSort);
|
|
5939
|
+
return buildColumnDef(node.props, sort, onSort, headerCache);
|
|
5150
5940
|
}
|
|
5151
|
-
const childDefs = buildColumnDefsFromTree(node.columns, sort, onSort);
|
|
5941
|
+
const childDefs = buildColumnDefsFromTree(node.columns, sort, onSort, headerCache);
|
|
5152
5942
|
const { header, align, headerClassName } = node.props;
|
|
5153
5943
|
return {
|
|
5154
5944
|
id: resolveGroupId(node.props, index),
|
|
@@ -5284,13 +6074,22 @@ function TableColumnGroup(props) {
|
|
|
5284
6074
|
TableColumnGroup.displayName = TABLE_COLUMN_GROUP_DISPLAY_NAME;
|
|
5285
6075
|
|
|
5286
6076
|
// src/components/ui/table/components/Table/tableDataPipeline.ts
|
|
5287
|
-
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") {
|
|
5288
6087
|
if (!sort) return data;
|
|
5289
6088
|
const { field, direction } = sort;
|
|
5290
6089
|
const multiplier = direction === "asc" ? 1 : -1;
|
|
5291
6090
|
return [...data].sort((left, right) => {
|
|
5292
|
-
const leftValue = left
|
|
5293
|
-
const rightValue = right
|
|
6091
|
+
const leftValue = readField(left, field);
|
|
6092
|
+
const rightValue = readField(right, field);
|
|
5294
6093
|
if ((leftValue === null || leftValue === void 0) && (rightValue === null || rightValue === void 0)) {
|
|
5295
6094
|
return 0;
|
|
5296
6095
|
}
|
|
@@ -5299,11 +6098,12 @@ function sortTableData(data, sort) {
|
|
|
5299
6098
|
if (typeof leftValue === "number" && typeof rightValue === "number") {
|
|
5300
6099
|
return (leftValue - rightValue) * multiplier;
|
|
5301
6100
|
}
|
|
5302
|
-
return String(leftValue).localeCompare(String(rightValue),
|
|
6101
|
+
return String(leftValue).localeCompare(String(rightValue), locale, { numeric: true }) * multiplier;
|
|
5303
6102
|
});
|
|
5304
6103
|
}
|
|
5305
6104
|
function paginateTableData(data, page, pageSize) {
|
|
5306
|
-
const
|
|
6105
|
+
const lastPage = getTotalPages(data.length, pageSize);
|
|
6106
|
+
const safePage = Math.min(Math.max(1, page), lastPage);
|
|
5307
6107
|
const start = (safePage - 1) * pageSize;
|
|
5308
6108
|
return data.slice(start, start + pageSize);
|
|
5309
6109
|
}
|
|
@@ -5311,6 +6111,36 @@ function getTotalPages(totalCount, pageSize) {
|
|
|
5311
6111
|
if (pageSize <= 0) return 1;
|
|
5312
6112
|
return Math.max(1, Math.ceil(totalCount / pageSize));
|
|
5313
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
|
+
}
|
|
5314
6144
|
|
|
5315
6145
|
// src/components/ui/table/components/Table/TableHeader.tsx
|
|
5316
6146
|
function TableHeader(props) {
|
|
@@ -5326,7 +6156,9 @@ function TablePagination({
|
|
|
5326
6156
|
pageSize = 10,
|
|
5327
6157
|
totalCount = 0,
|
|
5328
6158
|
onChange,
|
|
5329
|
-
className
|
|
6159
|
+
className,
|
|
6160
|
+
previousLabel = "Previous page",
|
|
6161
|
+
nextLabel = "Next page"
|
|
5330
6162
|
}) {
|
|
5331
6163
|
const totalPages = getTotalPages(totalCount, pageSize);
|
|
5332
6164
|
const safePage = Math.min(Math.max(1, page), totalPages);
|
|
@@ -5340,7 +6172,7 @@ function TablePagination({
|
|
|
5340
6172
|
className: "pagination-button",
|
|
5341
6173
|
disabled: !canGoPrev,
|
|
5342
6174
|
onClick: () => onChange(safePage - 1),
|
|
5343
|
-
"aria-label":
|
|
6175
|
+
"aria-label": previousLabel,
|
|
5344
6176
|
children: /* @__PURE__ */ jsx9(ChevronLeft, { className: "pagination-button-icon" })
|
|
5345
6177
|
}
|
|
5346
6178
|
),
|
|
@@ -5356,7 +6188,7 @@ function TablePagination({
|
|
|
5356
6188
|
className: "pagination-button",
|
|
5357
6189
|
disabled: !canGoNext,
|
|
5358
6190
|
onClick: () => onChange(safePage + 1),
|
|
5359
|
-
"aria-label":
|
|
6191
|
+
"aria-label": nextLabel,
|
|
5360
6192
|
children: /* @__PURE__ */ jsx9(ChevronRight, { className: "pagination-button-icon" })
|
|
5361
6193
|
}
|
|
5362
6194
|
)
|
|
@@ -5370,63 +6202,124 @@ function TableRoot({
|
|
|
5370
6202
|
data,
|
|
5371
6203
|
children,
|
|
5372
6204
|
className,
|
|
6205
|
+
classNames,
|
|
5373
6206
|
totalCount,
|
|
5374
6207
|
filteredCount,
|
|
6208
|
+
onDataChange,
|
|
6209
|
+
getRowId,
|
|
6210
|
+
sort: controlledSort,
|
|
6211
|
+
defaultSort = null,
|
|
6212
|
+
onSortChange,
|
|
6213
|
+
sortLocale,
|
|
5375
6214
|
...dataTableProps
|
|
5376
6215
|
}) {
|
|
5377
|
-
const { header, pagination: paginationElement } =
|
|
6216
|
+
const { header, pagination: paginationElement } = useMemo7(
|
|
5378
6217
|
() => parseTableChildren(children),
|
|
5379
6218
|
[children]
|
|
5380
6219
|
);
|
|
5381
|
-
const [
|
|
5382
|
-
const
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
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;
|
|
5389
6231
|
}
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
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),
|
|
5396
6241
|
[columnTree, sort, handleSort]
|
|
5397
6242
|
);
|
|
6243
|
+
const sortContextValue = useMemo7(() => ({ sort, onSort: handleSort }), [sort, handleSort]);
|
|
5398
6244
|
const paginationProps = paginationElement?.props;
|
|
5399
6245
|
const pageSize = paginationProps?.pageSize ?? 10;
|
|
5400
6246
|
const page = paginationProps?.page ?? 1;
|
|
5401
6247
|
const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
|
|
5402
|
-
const
|
|
5403
|
-
|
|
5404
|
-
|
|
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;
|
|
5405
6270
|
return paginateTableData(sortedData, page, pageSize);
|
|
5406
|
-
}, [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]);
|
|
5407
6295
|
if (countLeafColumns(columnTree) === 0) {
|
|
5408
6296
|
console.warn("[Table] Declare at least one Table.Column inside Table.Header.");
|
|
5409
6297
|
}
|
|
5410
|
-
return /* @__PURE__ */ jsxs9("div", { className: "TableJSX", children: [
|
|
5411
|
-
/* @__PURE__ */ jsx10(
|
|
6298
|
+
return /* @__PURE__ */ jsxs9("div", { className: cn("TableJSX", classNames?.tableRoot), children: [
|
|
6299
|
+
/* @__PURE__ */ jsx10(TableSortContext, { value: sortContextValue, children: /* @__PURE__ */ jsx10(
|
|
5412
6300
|
DataTable,
|
|
5413
6301
|
{
|
|
5414
6302
|
...dataTableProps,
|
|
6303
|
+
classNames,
|
|
6304
|
+
getRowId: resolvedGetRowId,
|
|
6305
|
+
onDataChange: handleDataChange,
|
|
5415
6306
|
data: tableData,
|
|
5416
6307
|
columns,
|
|
5417
6308
|
totalCount: paginationProps ? resolvedTotalCount : totalCount,
|
|
5418
6309
|
filteredCount: filteredCount ?? data.length,
|
|
5419
6310
|
className: cn(className, paginationProps && "DataTableJSX--with-pagination")
|
|
5420
6311
|
}
|
|
5421
|
-
),
|
|
6312
|
+
) }),
|
|
5422
6313
|
paginationProps && /* @__PURE__ */ jsx10(
|
|
5423
6314
|
TablePagination,
|
|
5424
6315
|
{
|
|
5425
6316
|
page,
|
|
5426
6317
|
pageSize,
|
|
5427
|
-
totalCount:
|
|
6318
|
+
totalCount: pageTotalCount,
|
|
5428
6319
|
onChange: paginationProps.onChange,
|
|
5429
|
-
className: paginationProps.className
|
|
6320
|
+
className: cn(classNames?.pagination, paginationProps.className),
|
|
6321
|
+
previousLabel: paginationProps.previousLabel ?? dataTableProps.labels?.paginationPrevious,
|
|
6322
|
+
nextLabel: paginationProps.nextLabel ?? dataTableProps.labels?.paginationNext
|
|
5430
6323
|
}
|
|
5431
6324
|
)
|
|
5432
6325
|
] });
|