react-glide-table 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -30
- package/dist/compound.cjs +561 -139
- package/dist/compound.d.cts +2 -2
- package/dist/compound.d.ts +2 -2
- package/dist/compound.js +465 -43
- package/dist/core.cjs +491 -137
- package/dist/core.d.cts +46 -7
- package/dist/core.d.ts +46 -7
- package/dist/core.js +378 -25
- package/dist/index.cjs +590 -166
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +466 -43
- package/dist/{types-CnsQ8GZb.d.cts → types-DdeVn-9s.d.cts} +23 -6
- package/dist/{types-CnsQ8GZb.d.ts → types-DdeVn-9s.d.ts} +23 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -83,6 +83,7 @@ __export(src_exports, {
|
|
|
83
83
|
previousSearchIndex: () => previousSearchIndex,
|
|
84
84
|
resolveCellRenderer: () => resolveCellRenderer,
|
|
85
85
|
resolveColumnFreezeSide: () => resolveColumnFreezeSide,
|
|
86
|
+
resolveColumnLayoutWidths: () => resolveColumnLayoutWidths,
|
|
86
87
|
resolveDataTableLabels: () => resolveDataTableLabels,
|
|
87
88
|
resolveDropEdge: () => resolveDropEdge,
|
|
88
89
|
resolveHeaderFreezeOffset: () => resolveHeaderFreezeOffset,
|
|
@@ -136,7 +137,7 @@ var DEFAULT_TREE_QTY_FIELD = "qty";
|
|
|
136
137
|
// src/core/useGlideTable.ts
|
|
137
138
|
var import_react_table = require("@tanstack/react-table");
|
|
138
139
|
var import_react_virtual = require("@tanstack/react-virtual");
|
|
139
|
-
var
|
|
140
|
+
var import_react6 = require("react");
|
|
140
141
|
|
|
141
142
|
// src/components/ui/table/constants.ts
|
|
142
143
|
var CELL_ALIGN_CLASS = {
|
|
@@ -538,7 +539,7 @@ function withCellUpdate(context, commitValue) {
|
|
|
538
539
|
}
|
|
539
540
|
|
|
540
541
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
541
|
-
var
|
|
542
|
+
var import_react3 = require("react");
|
|
542
543
|
|
|
543
544
|
// src/components/ui/table/features/cell-selection/cellSelection.ts
|
|
544
545
|
var INITIAL_DRAG_STATE = {
|
|
@@ -846,6 +847,219 @@ function hasCellSelectionEdges(style) {
|
|
|
846
847
|
}
|
|
847
848
|
|
|
848
849
|
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
850
|
+
var import_react2 = require("react");
|
|
851
|
+
function isReactNodeIterable(node) {
|
|
852
|
+
return typeof node === "object" && node !== null && !(0, import_react2.isValidElement)(node) && Symbol.iterator in node;
|
|
853
|
+
}
|
|
854
|
+
function getElementTypeName(type) {
|
|
855
|
+
if (typeof type === "string") return type;
|
|
856
|
+
if (typeof type === "function") {
|
|
857
|
+
const fn = type;
|
|
858
|
+
return fn.displayName || fn.name || "";
|
|
859
|
+
}
|
|
860
|
+
if (typeof type === "object" && type !== null) {
|
|
861
|
+
const component = type;
|
|
862
|
+
return component.displayName || component.render?.displayName || component.render?.name || "";
|
|
863
|
+
}
|
|
864
|
+
return "";
|
|
865
|
+
}
|
|
866
|
+
function isButtonReactElement(node) {
|
|
867
|
+
const typeName = getElementTypeName(node.type);
|
|
868
|
+
if (typeName === "button" || /button/i.test(typeName)) return true;
|
|
869
|
+
const props = node.props;
|
|
870
|
+
if (props.role === "button") return true;
|
|
871
|
+
if (typeName === "input" && props.type === "button") return true;
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
874
|
+
function isImageReactElement(node) {
|
|
875
|
+
const typeName = getElementTypeName(node.type);
|
|
876
|
+
return typeName === "img" || typeName === "image" || /image/i.test(typeName);
|
|
877
|
+
}
|
|
878
|
+
var IMAGE_URL_PROP_KEYS = ["src", "url", "href", "imageUrl", "srcUrl"];
|
|
879
|
+
function isLikelyUrl(value) {
|
|
880
|
+
const trimmed = value.trim();
|
|
881
|
+
if (!trimmed) return false;
|
|
882
|
+
if (/^(https?:|blob:|data:|\/\/)/i.test(trimmed)) return true;
|
|
883
|
+
if (trimmed.startsWith("/") && trimmed.includes("/")) return true;
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
function pickUrlFromUnknown(value) {
|
|
887
|
+
if (typeof value === "string") {
|
|
888
|
+
return isLikelyUrl(value) ? value.trim() : "";
|
|
889
|
+
}
|
|
890
|
+
if (Array.isArray(value)) {
|
|
891
|
+
return value.map((item) => pickUrlFromUnknown(item)).filter((item) => item.length > 0).join(", ");
|
|
892
|
+
}
|
|
893
|
+
if (value && typeof value === "object") {
|
|
894
|
+
const record = value;
|
|
895
|
+
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
896
|
+
const candidate = record[key];
|
|
897
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
898
|
+
return candidate.trim();
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
return "";
|
|
903
|
+
}
|
|
904
|
+
function imageElementText(node) {
|
|
905
|
+
const props = node.props;
|
|
906
|
+
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
907
|
+
const candidate = props[key];
|
|
908
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
909
|
+
return candidate.trim();
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return "";
|
|
913
|
+
}
|
|
914
|
+
function reactNodeContainsImage(node) {
|
|
915
|
+
if ((0, import_react2.isValidElement)(node)) {
|
|
916
|
+
if (isImageReactElement(node)) return true;
|
|
917
|
+
return reactNodeContainsImage(node.props.children);
|
|
918
|
+
}
|
|
919
|
+
if (isReactNodeIterable(node)) {
|
|
920
|
+
for (const child of node) {
|
|
921
|
+
if (reactNodeContainsImage(child)) return true;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
function readImgUrl(img) {
|
|
927
|
+
const attr = img.getAttribute("src")?.trim() ?? "";
|
|
928
|
+
if (attr) return attr;
|
|
929
|
+
if (img instanceof HTMLImageElement) {
|
|
930
|
+
const current = img.currentSrc?.trim() ?? "";
|
|
931
|
+
if (current && current !== img.baseURI) return current;
|
|
932
|
+
}
|
|
933
|
+
return "";
|
|
934
|
+
}
|
|
935
|
+
function readDomImageUrls(rowIndex, colIndex, root) {
|
|
936
|
+
const scope = root ?? (typeof document === "undefined" ? null : document);
|
|
937
|
+
if (!scope) return "";
|
|
938
|
+
const cells = scope.querySelectorAll(
|
|
939
|
+
`[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
|
|
940
|
+
);
|
|
941
|
+
for (const cell of cells) {
|
|
942
|
+
const urls = Array.from(cell.querySelectorAll("img")).flatMap((img) => {
|
|
943
|
+
const url = readImgUrl(img);
|
|
944
|
+
return url ? [url] : [];
|
|
945
|
+
});
|
|
946
|
+
if (urls.length > 0) return urls.join(", ");
|
|
947
|
+
}
|
|
948
|
+
return "";
|
|
949
|
+
}
|
|
950
|
+
function reactNodeToText(node) {
|
|
951
|
+
if (node == null || typeof node === "boolean") return "";
|
|
952
|
+
if (typeof node === "string" || typeof node === "number" || typeof node === "bigint") {
|
|
953
|
+
return String(node);
|
|
954
|
+
}
|
|
955
|
+
if (isReactNodeIterable(node)) {
|
|
956
|
+
let text = "";
|
|
957
|
+
for (const child of node) {
|
|
958
|
+
text += reactNodeToText(child);
|
|
959
|
+
}
|
|
960
|
+
return text;
|
|
961
|
+
}
|
|
962
|
+
if ((0, import_react2.isValidElement)(node)) {
|
|
963
|
+
if (isButtonReactElement(node)) return "";
|
|
964
|
+
const props = node.props;
|
|
965
|
+
const childText = reactNodeToText(props.children);
|
|
966
|
+
if (childText) return childText;
|
|
967
|
+
const fromImage = imageElementText(node);
|
|
968
|
+
if (fromImage) return fromImage;
|
|
969
|
+
if (isImageReactElement(node)) return "";
|
|
970
|
+
if (typeof props.alt === "string" && props.alt) return props.alt;
|
|
971
|
+
if (typeof props.title === "string" && props.title) return props.title;
|
|
972
|
+
return "";
|
|
973
|
+
}
|
|
974
|
+
return "";
|
|
975
|
+
}
|
|
976
|
+
function sanitizeClipboardCell(text) {
|
|
977
|
+
return text.replace(/\s+/g, " ").trim();
|
|
978
|
+
}
|
|
979
|
+
function createCopyRenderRow(rowData, index) {
|
|
980
|
+
return {
|
|
981
|
+
id: getOriginalRowId(rowData) || String(index),
|
|
982
|
+
index,
|
|
983
|
+
original: rowData,
|
|
984
|
+
getIsCellDragSelected: () => false
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
function buildVisibleRowLookup(visibleRows) {
|
|
988
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
989
|
+
for (const row of visibleRows) {
|
|
990
|
+
lookup.set(row.original, row);
|
|
991
|
+
}
|
|
992
|
+
return lookup;
|
|
993
|
+
}
|
|
994
|
+
function resolveCopyColumnId(cell) {
|
|
995
|
+
if (cell.column.id) return cell.column.id;
|
|
996
|
+
const columnDef = cell.column.columnDef;
|
|
997
|
+
if (columnDef.id) return columnDef.id;
|
|
998
|
+
if (columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
999
|
+
return String(columnDef.accessorKey);
|
|
1000
|
+
}
|
|
1001
|
+
return "";
|
|
1002
|
+
}
|
|
1003
|
+
function isPrimitiveCopyValue(value) {
|
|
1004
|
+
return value == null || typeof value !== "object";
|
|
1005
|
+
}
|
|
1006
|
+
function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
1007
|
+
const rendered = sanitizeClipboardCell(reactNodeToText(node));
|
|
1008
|
+
if (reactNodeContainsImage(node)) {
|
|
1009
|
+
const fromDom = cellPosition != null ? sanitizeClipboardCell(
|
|
1010
|
+
readDomImageUrls(cellPosition.rowIndex, cellPosition.colIndex, root)
|
|
1011
|
+
) : "";
|
|
1012
|
+
if (fromDom) return fromDom;
|
|
1013
|
+
if (rendered && isLikelyUrl(rendered)) return rendered;
|
|
1014
|
+
return sanitizeClipboardCell(pickUrlFromUnknown(value));
|
|
1015
|
+
}
|
|
1016
|
+
return rendered;
|
|
1017
|
+
}
|
|
1018
|
+
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
1019
|
+
const meta = columnDef.meta;
|
|
1020
|
+
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
1021
|
+
const cellRender = meta?.cellRender;
|
|
1022
|
+
if (typeof cellRender === "function") {
|
|
1023
|
+
try {
|
|
1024
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1025
|
+
const node = cellRender({
|
|
1026
|
+
value,
|
|
1027
|
+
row,
|
|
1028
|
+
index: row.index,
|
|
1029
|
+
columnId,
|
|
1030
|
+
cellProps: meta?.cellProps,
|
|
1031
|
+
update: () => {
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
1035
|
+
} catch {
|
|
1036
|
+
return formatCellValue(value);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
1040
|
+
try {
|
|
1041
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1042
|
+
const ctx = {
|
|
1043
|
+
value,
|
|
1044
|
+
row,
|
|
1045
|
+
index: row.index,
|
|
1046
|
+
columnId,
|
|
1047
|
+
cellProps: meta.cellProps,
|
|
1048
|
+
update: () => {
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
1052
|
+
if (renderer) {
|
|
1053
|
+
const node = renderer.render(ctx);
|
|
1054
|
+
const rendered = extractRenderedCopyText(node, value, cellPosition, options.root);
|
|
1055
|
+
if (rendered) return rendered;
|
|
1056
|
+
}
|
|
1057
|
+
} catch {
|
|
1058
|
+
return formatCellValue(value);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return formatCellValue(value);
|
|
1062
|
+
}
|
|
849
1063
|
function formatPrimitive(value) {
|
|
850
1064
|
if (value === null || value === void 0) return "";
|
|
851
1065
|
if (typeof value === "string") return value;
|
|
@@ -951,37 +1165,47 @@ function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
|
|
|
951
1165
|
function collectCopyRows(visibleRows, bounds, mode = "visible") {
|
|
952
1166
|
return collectCopyRowEntries(visibleRows, bounds, mode).map((entry) => entry.row);
|
|
953
1167
|
}
|
|
954
|
-
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths) {
|
|
1168
|
+
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options) {
|
|
955
1169
|
if (copyRows.length === 0) return "";
|
|
956
1170
|
const { startCol, endCol } = bounds;
|
|
957
1171
|
const columnCells = visibleRows[0]?.getVisibleCells().slice(startCol, endCol + 1) ?? [];
|
|
958
1172
|
if (columnCells.length === 0) return "";
|
|
959
1173
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
960
1174
|
const minDepth = Math.min(...resolvedDepths);
|
|
1175
|
+
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
961
1176
|
return copyRows.map((rowData, index) => {
|
|
962
1177
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1178
|
+
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
1179
|
+
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
1180
|
+
const line = columnCells.map((templateCell, colOffset) => {
|
|
1181
|
+
const sourceCell = matchingCells?.[colOffset];
|
|
1182
|
+
const column = sourceCell?.column ?? templateCell.column;
|
|
1183
|
+
return formatCopyCellText(
|
|
1184
|
+
rowData,
|
|
1185
|
+
column.columnDef,
|
|
1186
|
+
resolveCopyColumnId(sourceCell ?? templateCell),
|
|
1187
|
+
visibleRow,
|
|
1188
|
+
visibleRow?.index ?? index,
|
|
1189
|
+
sourceCell,
|
|
1190
|
+
visibleRow != null ? { rowIndex: visibleRow.index, colIndex: startCol + colOffset } : void 0,
|
|
1191
|
+
options
|
|
1192
|
+
);
|
|
1193
|
+
}).join(" ");
|
|
971
1194
|
return `${" ".repeat(relativeDepth)}${line}`;
|
|
972
1195
|
}).join("\n");
|
|
973
1196
|
}
|
|
974
|
-
function serializeSelectionToTSV(visibleRows, bounds, mode = "visible") {
|
|
1197
|
+
function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options) {
|
|
975
1198
|
const entries = collectCopyRowEntries(visibleRows, bounds, mode);
|
|
976
1199
|
return serializeCopyRowsToTSV(
|
|
977
1200
|
entries.map((entry) => entry.row),
|
|
978
1201
|
visibleRows,
|
|
979
1202
|
bounds,
|
|
980
|
-
entries.map((entry) => entry.depth)
|
|
1203
|
+
entries.map((entry) => entry.depth),
|
|
1204
|
+
options
|
|
981
1205
|
);
|
|
982
1206
|
}
|
|
983
|
-
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible") {
|
|
984
|
-
const text = serializeSelectionToTSV(visibleRows, bounds, mode);
|
|
1207
|
+
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
1208
|
+
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
985
1209
|
if (!text) return false;
|
|
986
1210
|
try {
|
|
987
1211
|
await navigator.clipboard.writeText(text);
|
|
@@ -1142,17 +1366,19 @@ function useCellSelection({
|
|
|
1142
1366
|
onDataChange,
|
|
1143
1367
|
onBatchChange,
|
|
1144
1368
|
onRowsPaste,
|
|
1145
|
-
onCellNavigate
|
|
1369
|
+
onCellNavigate,
|
|
1370
|
+
cellRendererRegistry,
|
|
1371
|
+
rootRef
|
|
1146
1372
|
}) {
|
|
1147
|
-
const [dragState, setDragState] = (0,
|
|
1148
|
-
const pendingPasteModeRef = (0,
|
|
1149
|
-
const dragStateRef = (0,
|
|
1150
|
-
const onCellNavigateRef = (0,
|
|
1373
|
+
const [dragState, setDragState] = (0, import_react3.useState)(INITIAL_DRAG_STATE);
|
|
1374
|
+
const pendingPasteModeRef = (0, import_react3.useRef)(null);
|
|
1375
|
+
const dragStateRef = (0, import_react3.useRef)(dragState);
|
|
1376
|
+
const onCellNavigateRef = (0, import_react3.useRef)(onCellNavigate);
|
|
1151
1377
|
dragStateRef.current = dragState;
|
|
1152
1378
|
onCellNavigateRef.current = onCellNavigate;
|
|
1153
1379
|
const cellSelectionBounds = getCellSelectionBounds(dragState.start, dragState.end);
|
|
1154
1380
|
const activeSelectionBounds = enabled ? getActiveSelectionBounds(dragState, cellSelectionBounds) : null;
|
|
1155
|
-
const handleCellMouseDown = (0,
|
|
1381
|
+
const handleCellMouseDown = (0, import_react3.useCallback)(
|
|
1156
1382
|
(rowIndex, colIndex, options) => {
|
|
1157
1383
|
if (!enabled) return;
|
|
1158
1384
|
setDragState((prev) => {
|
|
@@ -1178,7 +1404,7 @@ function useCellSelection({
|
|
|
1178
1404
|
},
|
|
1179
1405
|
[enabled]
|
|
1180
1406
|
);
|
|
1181
|
-
const handleCellMouseEnter = (0,
|
|
1407
|
+
const handleCellMouseEnter = (0, import_react3.useCallback)(
|
|
1182
1408
|
(rowIndex, colIndex) => {
|
|
1183
1409
|
if (!enabled) return;
|
|
1184
1410
|
setDragState((prev) => {
|
|
@@ -1193,7 +1419,7 @@ function useCellSelection({
|
|
|
1193
1419
|
},
|
|
1194
1420
|
[enabled]
|
|
1195
1421
|
);
|
|
1196
|
-
const handleFillHandleMouseDown = (0,
|
|
1422
|
+
const handleFillHandleMouseDown = (0, import_react3.useCallback)(
|
|
1197
1423
|
(rowIndex, colIndex) => {
|
|
1198
1424
|
if (!enabled) return;
|
|
1199
1425
|
setDragState((prev) => {
|
|
@@ -1210,12 +1436,12 @@ function useCellSelection({
|
|
|
1210
1436
|
},
|
|
1211
1437
|
[enabled]
|
|
1212
1438
|
);
|
|
1213
|
-
(0,
|
|
1439
|
+
(0, import_react3.useEffect)(() => {
|
|
1214
1440
|
if (!enabled) {
|
|
1215
1441
|
setDragState(INITIAL_DRAG_STATE);
|
|
1216
1442
|
}
|
|
1217
1443
|
}, [enabled]);
|
|
1218
|
-
(0,
|
|
1444
|
+
(0, import_react3.useEffect)(() => {
|
|
1219
1445
|
if (!enabled) return;
|
|
1220
1446
|
const handleKeyDown = (e) => {
|
|
1221
1447
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
@@ -1262,19 +1488,32 @@ function useCellSelection({
|
|
|
1262
1488
|
window.addEventListener("keydown", handleKeyDown);
|
|
1263
1489
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
1264
1490
|
}, [columnCount, enabled, rows]);
|
|
1265
|
-
const copySelection = (0,
|
|
1491
|
+
const copySelection = (0, import_react3.useCallback)(
|
|
1266
1492
|
async (options) => {
|
|
1267
1493
|
if (!enabled || !activeSelectionBounds) return false;
|
|
1268
1494
|
const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
|
|
1269
|
-
return writeSelectionToClipboard(rows, activeSelectionBounds, mode
|
|
1495
|
+
return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
|
|
1496
|
+
registry: cellRendererRegistry,
|
|
1497
|
+
root: rootRef?.current
|
|
1498
|
+
});
|
|
1270
1499
|
},
|
|
1271
|
-
[
|
|
1500
|
+
[
|
|
1501
|
+
activeSelectionBounds,
|
|
1502
|
+
cellRendererRegistry,
|
|
1503
|
+
enableSubtreeCopy,
|
|
1504
|
+
enabled,
|
|
1505
|
+
rootRef,
|
|
1506
|
+
rows
|
|
1507
|
+
]
|
|
1272
1508
|
);
|
|
1273
|
-
(0,
|
|
1509
|
+
(0, import_react3.useEffect)(() => {
|
|
1274
1510
|
if (!enabled) return;
|
|
1275
1511
|
const handleKeyDown = (e) => {
|
|
1276
1512
|
if (!activeSelectionBounds) return;
|
|
1277
1513
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
1514
|
+
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1278
1517
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
1279
1518
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
1280
1519
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -1284,7 +1523,7 @@ function useCellSelection({
|
|
|
1284
1523
|
window.addEventListener("keydown", handleKeyDown);
|
|
1285
1524
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
1286
1525
|
}, [activeSelectionBounds, copySelection, enableSubtreeCopy, enabled]);
|
|
1287
|
-
const emitRowsPaste = (0,
|
|
1526
|
+
const emitRowsPaste = (0, import_react3.useCallback)(
|
|
1288
1527
|
(text, mode) => {
|
|
1289
1528
|
if (!onRowsPaste || !activeSelectionBounds) return false;
|
|
1290
1529
|
const payload = buildRowsPastePayload(
|
|
@@ -1301,7 +1540,7 @@ function useCellSelection({
|
|
|
1301
1540
|
},
|
|
1302
1541
|
[activeSelectionBounds, onRowsPaste, rows]
|
|
1303
1542
|
);
|
|
1304
|
-
(0,
|
|
1543
|
+
(0, import_react3.useEffect)(() => {
|
|
1305
1544
|
if (!enabled || !onRowsPaste) return;
|
|
1306
1545
|
const pasteHandledRef = { current: false };
|
|
1307
1546
|
const ignoreNextPasteRef = { current: false };
|
|
@@ -1369,7 +1608,7 @@ function useCellSelection({
|
|
|
1369
1608
|
enabled,
|
|
1370
1609
|
onRowsPaste
|
|
1371
1610
|
]);
|
|
1372
|
-
(0,
|
|
1611
|
+
(0, import_react3.useEffect)(() => {
|
|
1373
1612
|
if (!enabled) return;
|
|
1374
1613
|
const handleMouseUp = () => {
|
|
1375
1614
|
setDragState((prev) => {
|
|
@@ -1818,7 +2057,7 @@ function collectAncestorKeysToExpand(corpusRow, expandedRows) {
|
|
|
1818
2057
|
}
|
|
1819
2058
|
|
|
1820
2059
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
1821
|
-
var
|
|
2060
|
+
var import_react4 = require("react");
|
|
1822
2061
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
1823
2062
|
function useInlineSearch({
|
|
1824
2063
|
enabled = false,
|
|
@@ -1835,46 +2074,46 @@ function useInlineSearch({
|
|
|
1835
2074
|
onNavigateToResult,
|
|
1836
2075
|
rootRef
|
|
1837
2076
|
}) {
|
|
1838
|
-
const searchInputId = (0,
|
|
1839
|
-
const searchInputRef = (0,
|
|
1840
|
-
const [internalShowSearch, setInternalShowSearch] = (0,
|
|
1841
|
-
const [internalSearchValue, setInternalSearchValue] = (0,
|
|
1842
|
-
const [internalResults, setInternalResults] = (0,
|
|
2077
|
+
const searchInputId = (0, import_react4.useId)();
|
|
2078
|
+
const searchInputRef = (0, import_react4.useRef)(null);
|
|
2079
|
+
const [internalShowSearch, setInternalShowSearch] = (0, import_react4.useState)(false);
|
|
2080
|
+
const [internalSearchValue, setInternalSearchValue] = (0, import_react4.useState)("");
|
|
2081
|
+
const [internalResults, setInternalResults] = (0, import_react4.useState)(
|
|
1843
2082
|
[]
|
|
1844
2083
|
);
|
|
1845
|
-
const [searchStatus, setSearchStatus] = (0,
|
|
1846
|
-
const searchStatusRef = (0,
|
|
2084
|
+
const [searchStatus, setSearchStatus] = (0, import_react4.useState)();
|
|
2085
|
+
const searchStatusRef = (0, import_react4.useRef)(searchStatus);
|
|
1847
2086
|
searchStatusRef.current = searchStatus;
|
|
1848
|
-
const abortControllerRef = (0,
|
|
1849
|
-
const searchHandleRef = (0,
|
|
1850
|
-
const initialStartRowRef = (0,
|
|
2087
|
+
const abortControllerRef = (0, import_react4.useRef)(null);
|
|
2088
|
+
const searchHandleRef = (0, import_react4.useRef)(void 0);
|
|
2089
|
+
const initialStartRowRef = (0, import_react4.useRef)(initialStartRow);
|
|
1851
2090
|
initialStartRowRef.current = initialStartRow;
|
|
1852
|
-
const getCellValueRef = (0,
|
|
2091
|
+
const getCellValueRef = (0, import_react4.useRef)(getCellValue);
|
|
1853
2092
|
getCellValueRef.current = getCellValue;
|
|
1854
2093
|
const showSearch = controlledShowSearch ?? internalShowSearch;
|
|
1855
2094
|
const searchValue = controlledSearchValue ?? internalSearchValue;
|
|
1856
2095
|
const searchResults = controlledSearchResults ?? internalResults;
|
|
1857
|
-
const setSearchValue = (0,
|
|
2096
|
+
const setSearchValue = (0, import_react4.useCallback)(
|
|
1858
2097
|
(value) => {
|
|
1859
2098
|
setInternalSearchValue(value);
|
|
1860
2099
|
onSearchValueChange?.(value);
|
|
1861
2100
|
},
|
|
1862
2101
|
[onSearchValueChange]
|
|
1863
2102
|
);
|
|
1864
|
-
const cancelSearch = (0,
|
|
2103
|
+
const cancelSearch = (0, import_react4.useCallback)(() => {
|
|
1865
2104
|
if (searchHandleRef.current !== void 0) {
|
|
1866
2105
|
window.cancelAnimationFrame(searchHandleRef.current);
|
|
1867
2106
|
searchHandleRef.current = void 0;
|
|
1868
2107
|
}
|
|
1869
2108
|
abortControllerRef.current?.abort();
|
|
1870
2109
|
}, []);
|
|
1871
|
-
const emitResultsChanged = (0,
|
|
2110
|
+
const emitResultsChanged = (0, import_react4.useCallback)(
|
|
1872
2111
|
(results, navIndex) => {
|
|
1873
2112
|
onSearchResultsChanged?.(results, navIndex);
|
|
1874
2113
|
},
|
|
1875
2114
|
[onSearchResultsChanged]
|
|
1876
2115
|
);
|
|
1877
|
-
const navigateToIndex = (0,
|
|
2116
|
+
const navigateToIndex = (0, import_react4.useCallback)(
|
|
1878
2117
|
(results, navIndex) => {
|
|
1879
2118
|
if (onSearchResultsChanged) return;
|
|
1880
2119
|
if (navIndex < 0 || navIndex >= results.length) return;
|
|
@@ -1884,7 +2123,7 @@ function useInlineSearch({
|
|
|
1884
2123
|
},
|
|
1885
2124
|
[onNavigateToResult, onSearchResultsChanged]
|
|
1886
2125
|
);
|
|
1887
|
-
const beginSearch = (0,
|
|
2126
|
+
const beginSearch = (0, import_react4.useCallback)(
|
|
1888
2127
|
(query) => {
|
|
1889
2128
|
if (controlledSearchResults !== void 0) return;
|
|
1890
2129
|
const totalRows = rowCount;
|
|
@@ -1956,12 +2195,12 @@ function useInlineSearch({
|
|
|
1956
2195
|
rowCount
|
|
1957
2196
|
]
|
|
1958
2197
|
);
|
|
1959
|
-
const openSearch = (0,
|
|
2198
|
+
const openSearch = (0, import_react4.useCallback)(() => {
|
|
1960
2199
|
if (controlledShowSearch === void 0) {
|
|
1961
2200
|
setInternalShowSearch(true);
|
|
1962
2201
|
}
|
|
1963
2202
|
}, [controlledShowSearch]);
|
|
1964
|
-
const closeSearch = (0,
|
|
2203
|
+
const closeSearch = (0, import_react4.useCallback)(() => {
|
|
1965
2204
|
if (controlledShowSearch === void 0) {
|
|
1966
2205
|
setInternalShowSearch(false);
|
|
1967
2206
|
}
|
|
@@ -1976,7 +2215,7 @@ function useInlineSearch({
|
|
|
1976
2215
|
emitResultsChanged,
|
|
1977
2216
|
onSearchClose
|
|
1978
2217
|
]);
|
|
1979
|
-
const goToNext = (0,
|
|
2218
|
+
const goToNext = (0, import_react4.useCallback)(() => {
|
|
1980
2219
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
1981
2220
|
const newIndex = nextSearchIndex(
|
|
1982
2221
|
searchStatus.selectedIndex,
|
|
@@ -1986,7 +2225,7 @@ function useInlineSearch({
|
|
|
1986
2225
|
emitResultsChanged(searchResults, newIndex);
|
|
1987
2226
|
navigateToIndex(searchResults, newIndex);
|
|
1988
2227
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
1989
|
-
const goToPrevious = (0,
|
|
2228
|
+
const goToPrevious = (0, import_react4.useCallback)(() => {
|
|
1990
2229
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
1991
2230
|
const newIndex = previousSearchIndex(
|
|
1992
2231
|
searchStatus.selectedIndex,
|
|
@@ -1996,7 +2235,7 @@ function useInlineSearch({
|
|
|
1996
2235
|
emitResultsChanged(searchResults, newIndex);
|
|
1997
2236
|
navigateToIndex(searchResults, newIndex);
|
|
1998
2237
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
1999
|
-
(0,
|
|
2238
|
+
(0, import_react4.useEffect)(() => {
|
|
2000
2239
|
if (controlledSearchResults === void 0) return;
|
|
2001
2240
|
if (controlledSearchResults.length > 0) {
|
|
2002
2241
|
setSearchStatus((current) => ({
|
|
@@ -2008,7 +2247,7 @@ function useInlineSearch({
|
|
|
2008
2247
|
setSearchStatus(void 0);
|
|
2009
2248
|
}
|
|
2010
2249
|
}, [controlledSearchResults, rowCount]);
|
|
2011
|
-
(0,
|
|
2250
|
+
(0, import_react4.useEffect)(() => {
|
|
2012
2251
|
if (!enabled) return;
|
|
2013
2252
|
setSearchStatus(void 0);
|
|
2014
2253
|
setInternalResults([]);
|
|
@@ -2021,7 +2260,7 @@ function useInlineSearch({
|
|
|
2021
2260
|
cancelSearch();
|
|
2022
2261
|
}
|
|
2023
2262
|
}, [enabled, showSearch]);
|
|
2024
|
-
(0,
|
|
2263
|
+
(0, import_react4.useEffect)(() => {
|
|
2025
2264
|
if (!enabled || !showSearch) return;
|
|
2026
2265
|
if (controlledSearchResults !== void 0) return;
|
|
2027
2266
|
if (searchValue.trim() === "") {
|
|
@@ -2041,7 +2280,7 @@ function useInlineSearch({
|
|
|
2041
2280
|
searchValue,
|
|
2042
2281
|
showSearch
|
|
2043
2282
|
]);
|
|
2044
|
-
(0,
|
|
2283
|
+
(0, import_react4.useEffect)(() => {
|
|
2045
2284
|
if (!enabled) return;
|
|
2046
2285
|
const handleKeyDown = (event) => {
|
|
2047
2286
|
if (!(event.ctrlKey || event.metaKey)) return;
|
|
@@ -2068,12 +2307,12 @@ function useInlineSearch({
|
|
|
2068
2307
|
window.addEventListener("keydown", handleKeyDown, true);
|
|
2069
2308
|
return () => window.removeEventListener("keydown", handleKeyDown, true);
|
|
2070
2309
|
}, [controlledShowSearch, enabled, rootRef, showSearch]);
|
|
2071
|
-
(0,
|
|
2072
|
-
const searchMatchKeys = (0,
|
|
2310
|
+
(0, import_react4.useEffect)(() => () => cancelSearch(), [cancelSearch]);
|
|
2311
|
+
const searchMatchKeys = (0, import_react4.useMemo)(
|
|
2073
2312
|
() => buildSearchMatchKeys(searchResults),
|
|
2074
2313
|
[searchResults]
|
|
2075
2314
|
);
|
|
2076
|
-
const activeMatch = (0,
|
|
2315
|
+
const activeMatch = (0, import_react4.useMemo)(() => {
|
|
2077
2316
|
if (!searchStatus || searchStatus.selectedIndex < 0) return null;
|
|
2078
2317
|
return searchResults[searchStatus.selectedIndex] ?? null;
|
|
2079
2318
|
}, [searchResults, searchStatus]);
|
|
@@ -2116,7 +2355,7 @@ function useInlineSearch({
|
|
|
2116
2355
|
}
|
|
2117
2356
|
|
|
2118
2357
|
// src/components/ui/table/features/row-expand/row-expand.ts
|
|
2119
|
-
var
|
|
2358
|
+
var import_react5 = require("react");
|
|
2120
2359
|
function getFieldValue(row, key) {
|
|
2121
2360
|
return row[key];
|
|
2122
2361
|
}
|
|
@@ -2146,12 +2385,12 @@ var useConvertTreeData = ({
|
|
|
2146
2385
|
expandedRows,
|
|
2147
2386
|
onExpandedRowsChange
|
|
2148
2387
|
}) => {
|
|
2149
|
-
const onExpandedRowsChangeRef = (0,
|
|
2150
|
-
const hasInitializedRef = (0,
|
|
2151
|
-
(0,
|
|
2388
|
+
const onExpandedRowsChangeRef = (0, import_react5.useRef)(onExpandedRowsChange);
|
|
2389
|
+
const hasInitializedRef = (0, import_react5.useRef)(false);
|
|
2390
|
+
(0, import_react5.useEffect)(() => {
|
|
2152
2391
|
onExpandedRowsChangeRef.current = onExpandedRowsChange;
|
|
2153
2392
|
}, [onExpandedRowsChange]);
|
|
2154
|
-
(0,
|
|
2393
|
+
(0, import_react5.useEffect)(() => {
|
|
2155
2394
|
if (!data || data.length === 0) {
|
|
2156
2395
|
hasInitializedRef.current = false;
|
|
2157
2396
|
return;
|
|
@@ -2161,7 +2400,7 @@ var useConvertTreeData = ({
|
|
|
2161
2400
|
onExpandedRowsChangeRef.current?.(new Set(ids));
|
|
2162
2401
|
hasInitializedRef.current = true;
|
|
2163
2402
|
}, [enabled, data, toggleField]);
|
|
2164
|
-
const processedData = (0,
|
|
2403
|
+
const processedData = (0, import_react5.useMemo)(() => {
|
|
2165
2404
|
if (!enabled || !data || data.length === 0) return [];
|
|
2166
2405
|
const flattenedData = [];
|
|
2167
2406
|
const flattenItems = (items) => {
|
|
@@ -2225,7 +2464,7 @@ var useConvertTreeData = ({
|
|
|
2225
2464
|
});
|
|
2226
2465
|
return rootItems;
|
|
2227
2466
|
}, [enabled, data, toggleField, childField, flattenField]);
|
|
2228
|
-
const flattenTree = (0,
|
|
2467
|
+
const flattenTree = (0, import_react5.useMemo)(() => {
|
|
2229
2468
|
if (!enabled) return [];
|
|
2230
2469
|
const flatten = (nodes, result = [], level = 0) => {
|
|
2231
2470
|
nodes.forEach((node, index) => {
|
|
@@ -2275,7 +2514,7 @@ var useConvertTreeData = ({
|
|
|
2275
2514
|
preventExpand,
|
|
2276
2515
|
expandedRows
|
|
2277
2516
|
]);
|
|
2278
|
-
const sortedData = (0,
|
|
2517
|
+
const sortedData = (0, import_react5.useMemo)(() => {
|
|
2279
2518
|
if (!enabled) {
|
|
2280
2519
|
return data ?? [];
|
|
2281
2520
|
}
|
|
@@ -2502,7 +2741,7 @@ function useGlideTable(options) {
|
|
|
2502
2741
|
searchResults,
|
|
2503
2742
|
onSearchResultsChanged
|
|
2504
2743
|
} = options;
|
|
2505
|
-
const labels = (0,
|
|
2744
|
+
const labels = (0, import_react6.useMemo)(() => {
|
|
2506
2745
|
const resolved = resolveDataTableLabels(labelsProp);
|
|
2507
2746
|
return {
|
|
2508
2747
|
...resolved,
|
|
@@ -2513,17 +2752,21 @@ function useGlideTable(options) {
|
|
|
2513
2752
|
}, [labelsProp, emptyText, loadingText, selectionLabel]);
|
|
2514
2753
|
const enableExpand = Boolean(toggleField);
|
|
2515
2754
|
const resolvedEnableSubtreeCopy = enableSubtreeCopy ?? enableExpand;
|
|
2516
|
-
const [internalRowSelection, setInternalRowSelection] = (0,
|
|
2517
|
-
const [internalColumnSizing, setInternalColumnSizing] = (0,
|
|
2518
|
-
const [internalColumnOrder, setInternalColumnOrder] = (0,
|
|
2519
|
-
const [internalExpandedRows, setInternalExpandedRows] = (0,
|
|
2755
|
+
const [internalRowSelection, setInternalRowSelection] = (0, import_react6.useState)({});
|
|
2756
|
+
const [internalColumnSizing, setInternalColumnSizing] = (0, import_react6.useState)({});
|
|
2757
|
+
const [internalColumnOrder, setInternalColumnOrder] = (0, import_react6.useState)([]);
|
|
2758
|
+
const [internalExpandedRows, setInternalExpandedRows] = (0, import_react6.useState)(
|
|
2520
2759
|
() => /* @__PURE__ */ new Set()
|
|
2521
2760
|
);
|
|
2522
|
-
const [hoveredRowIndex, setHoveredRowIndex] = (0,
|
|
2523
|
-
const scrollRef = (0,
|
|
2524
|
-
const rootRef = (0,
|
|
2761
|
+
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
|
|
2762
|
+
const scrollRef = (0, import_react6.useRef)(null);
|
|
2763
|
+
const rootRef = (0, import_react6.useRef)(null);
|
|
2764
|
+
const cellRendererRegistry = (0, import_react6.useMemo)(
|
|
2765
|
+
() => createCellRendererRegistry(cellRenderers),
|
|
2766
|
+
[cellRenderers]
|
|
2767
|
+
);
|
|
2525
2768
|
const shouldVirtualize = enableVirtualization && !enableRowSpan;
|
|
2526
|
-
(0,
|
|
2769
|
+
(0, import_react6.useEffect)(() => {
|
|
2527
2770
|
if (enableVirtualization && enableRowSpan) {
|
|
2528
2771
|
console.warn(
|
|
2529
2772
|
"[useGlideTable] enableRowSpan is on; virtualization is disabled to preserve cell merges."
|
|
@@ -2537,11 +2780,11 @@ function useGlideTable(options) {
|
|
|
2537
2780
|
);
|
|
2538
2781
|
const columnSizing = controlledColumnSizing ?? internalColumnSizing;
|
|
2539
2782
|
const columnOrder = controlledColumnOrder ?? internalColumnOrder;
|
|
2540
|
-
const tableColumns = (0,
|
|
2783
|
+
const tableColumns = (0, import_react6.useMemo)(() => {
|
|
2541
2784
|
if (!enableColumnReorder) return columns;
|
|
2542
2785
|
return applyLeafColumnOrder(columns, columnOrder);
|
|
2543
2786
|
}, [columnOrder, columns, enableColumnReorder]);
|
|
2544
|
-
const setColumnOrder = (0,
|
|
2787
|
+
const setColumnOrder = (0, import_react6.useCallback)(
|
|
2545
2788
|
(next) => {
|
|
2546
2789
|
if (onColumnOrderChange) {
|
|
2547
2790
|
onColumnOrderChange(next);
|
|
@@ -2552,7 +2795,7 @@ function useGlideTable(options) {
|
|
|
2552
2795
|
[onColumnOrderChange]
|
|
2553
2796
|
);
|
|
2554
2797
|
const expandedRows = controlledExpandedRows ?? internalExpandedRows;
|
|
2555
|
-
const handleExpandedRowsChange = (0,
|
|
2798
|
+
const handleExpandedRowsChange = (0, import_react6.useCallback)(
|
|
2556
2799
|
(next) => {
|
|
2557
2800
|
if (onExpandedRowsChange) {
|
|
2558
2801
|
onExpandedRowsChange(next);
|
|
@@ -2613,13 +2856,13 @@ function useGlideTable(options) {
|
|
|
2613
2856
|
getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
|
|
2614
2857
|
getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (_originalRow, index) => String(index)
|
|
2615
2858
|
});
|
|
2616
|
-
const rowSpanColumnKeys = (0,
|
|
2859
|
+
const rowSpanColumnKeys = (0, import_react6.useMemo)(() => {
|
|
2617
2860
|
if (!enableRowSpan) return [];
|
|
2618
2861
|
return collectRowSpanColumns(columns);
|
|
2619
2862
|
}, [enableRowSpan, columns]);
|
|
2620
2863
|
const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
|
|
2621
2864
|
const primaryRowSpanColumnId = rowSpanColumnKeys[0]?.columnId;
|
|
2622
|
-
const columnRowSpanMap = (0,
|
|
2865
|
+
const columnRowSpanMap = (0, import_react6.useMemo)(
|
|
2623
2866
|
() => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
|
|
2624
2867
|
[tableData, rowSpanColumnKeys]
|
|
2625
2868
|
);
|
|
@@ -2628,7 +2871,7 @@ function useGlideTable(options) {
|
|
|
2628
2871
|
const rows = table.getRowModel().rows;
|
|
2629
2872
|
const columnCount = table.getAllLeafColumns().length || 1;
|
|
2630
2873
|
const visibleLeafColumns = table.getVisibleLeafColumns();
|
|
2631
|
-
const columnFreezeOffsets = (0,
|
|
2874
|
+
const columnFreezeOffsets = (0, import_react6.useMemo)(() => {
|
|
2632
2875
|
if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
|
|
2633
2876
|
return buildColumnFreezeOffsets(
|
|
2634
2877
|
visibleLeafColumns.map((column) => ({
|
|
@@ -2648,14 +2891,14 @@ function useGlideTable(options) {
|
|
|
2648
2891
|
const totalSize = rowVirtualizer.getTotalSize();
|
|
2649
2892
|
const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
|
|
2650
2893
|
const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
|
|
2651
|
-
const selectedRowIndices = (0,
|
|
2894
|
+
const selectedRowIndices = (0, import_react6.useMemo)(() => {
|
|
2652
2895
|
const indices = /* @__PURE__ */ new Set();
|
|
2653
2896
|
for (const selectedRow of selectedRows) {
|
|
2654
2897
|
indices.add(selectedRow.index);
|
|
2655
2898
|
}
|
|
2656
2899
|
return indices;
|
|
2657
2900
|
}, [selectedRows]);
|
|
2658
|
-
const scrollCellIntoView = (0,
|
|
2901
|
+
const scrollCellIntoView = (0, import_react6.useCallback)(
|
|
2659
2902
|
(rowIndex, colIndex, options2) => {
|
|
2660
2903
|
const align = options2?.align ?? "nearest";
|
|
2661
2904
|
const blockAlign = align === "center" ? "center" : "nearest";
|
|
@@ -2682,7 +2925,7 @@ function useGlideTable(options) {
|
|
|
2682
2925
|
},
|
|
2683
2926
|
[rowVirtualizer, shouldVirtualize]
|
|
2684
2927
|
);
|
|
2685
|
-
const handleCellNavigate = (0,
|
|
2928
|
+
const handleCellNavigate = (0, import_react6.useCallback)(
|
|
2686
2929
|
(position) => {
|
|
2687
2930
|
scrollCellIntoView(position.row, position.col, { align: "nearest" });
|
|
2688
2931
|
},
|
|
@@ -2705,7 +2948,9 @@ function useGlideTable(options) {
|
|
|
2705
2948
|
onDataChange,
|
|
2706
2949
|
onBatchChange,
|
|
2707
2950
|
onRowsPaste,
|
|
2708
|
-
onCellNavigate: handleCellNavigate
|
|
2951
|
+
onCellNavigate: handleCellNavigate,
|
|
2952
|
+
cellRendererRegistry,
|
|
2953
|
+
rootRef
|
|
2709
2954
|
});
|
|
2710
2955
|
const {
|
|
2711
2956
|
editingCell,
|
|
@@ -2715,11 +2960,7 @@ function useGlideTable(options) {
|
|
|
2715
2960
|
commitEdit,
|
|
2716
2961
|
cancelEdit
|
|
2717
2962
|
} = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
|
|
2718
|
-
const
|
|
2719
|
-
() => createCellRendererRegistry(cellRenderers),
|
|
2720
|
-
[cellRenderers]
|
|
2721
|
-
);
|
|
2722
|
-
const commitRenderedCellValue = (0, import_react5.useCallback)(
|
|
2963
|
+
const commitRenderedCellValue = (0, import_react6.useCallback)(
|
|
2723
2964
|
(rowId, columnId, value) => commitCellValue({
|
|
2724
2965
|
data: tableData,
|
|
2725
2966
|
rows,
|
|
@@ -2731,11 +2972,11 @@ function useGlideTable(options) {
|
|
|
2731
2972
|
}),
|
|
2732
2973
|
[onCellChange, onDataChange, rows, tableData]
|
|
2733
2974
|
);
|
|
2734
|
-
const getCellContext = (0,
|
|
2975
|
+
const getCellContext = (0, import_react6.useCallback)(
|
|
2735
2976
|
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
2736
2977
|
[commitRenderedCellValue]
|
|
2737
2978
|
);
|
|
2738
|
-
const handleCellMouseDownWithCommit = (0,
|
|
2979
|
+
const handleCellMouseDownWithCommit = (0, import_react6.useCallback)(
|
|
2739
2980
|
(rowIndex, colIndex, options2) => {
|
|
2740
2981
|
const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
|
|
2741
2982
|
if (editingCell && !isSameEditingCell && !commitEdit()) {
|
|
@@ -2745,7 +2986,7 @@ function useGlideTable(options) {
|
|
|
2745
2986
|
},
|
|
2746
2987
|
[commitEdit, editingCell, handleCellMouseDown]
|
|
2747
2988
|
);
|
|
2748
|
-
const navigateToSearchResult = (0,
|
|
2989
|
+
const navigateToSearchResult = (0, import_react6.useCallback)(
|
|
2749
2990
|
(item) => {
|
|
2750
2991
|
const [colIndex, rowIndex] = item;
|
|
2751
2992
|
handleCellMouseDownWithCommit(rowIndex, colIndex);
|
|
@@ -2753,7 +2994,7 @@ function useGlideTable(options) {
|
|
|
2753
2994
|
},
|
|
2754
2995
|
[handleCellMouseDownWithCommit, scrollCellIntoView]
|
|
2755
2996
|
);
|
|
2756
|
-
const resolveSearchRowId = (0,
|
|
2997
|
+
const resolveSearchRowId = (0, import_react6.useCallback)(
|
|
2757
2998
|
(row, index) => {
|
|
2758
2999
|
if (getRowId) return getRowId(row, index);
|
|
2759
3000
|
if (enableExpand) {
|
|
@@ -2777,7 +3018,7 @@ function useGlideTable(options) {
|
|
|
2777
3018
|
},
|
|
2778
3019
|
[enableExpand, getRowId, toggleField]
|
|
2779
3020
|
);
|
|
2780
|
-
const searchCorpus = (0,
|
|
3021
|
+
const searchCorpus = (0, import_react6.useMemo)(() => {
|
|
2781
3022
|
if (!enableInlineSearch) return [];
|
|
2782
3023
|
if (enableExpand && toggleField) {
|
|
2783
3024
|
return buildTreeSearchCorpus(tableData, {
|
|
@@ -2793,16 +3034,16 @@ function useGlideTable(options) {
|
|
|
2793
3034
|
tableData,
|
|
2794
3035
|
toggleField
|
|
2795
3036
|
]);
|
|
2796
|
-
const searchCorpusRef = (0,
|
|
3037
|
+
const searchCorpusRef = (0, import_react6.useRef)(searchCorpus);
|
|
2797
3038
|
searchCorpusRef.current = searchCorpus;
|
|
2798
|
-
const visibleRowIndexById = (0,
|
|
3039
|
+
const visibleRowIndexById = (0, import_react6.useMemo)(() => {
|
|
2799
3040
|
const map = /* @__PURE__ */ new Map();
|
|
2800
3041
|
for (const row of rows) {
|
|
2801
3042
|
map.set(resolveSearchRowId(row.original, row.index), row.index);
|
|
2802
3043
|
}
|
|
2803
3044
|
return map;
|
|
2804
3045
|
}, [resolveSearchRowId, rows]);
|
|
2805
|
-
const getSearchCellValue = (0,
|
|
3046
|
+
const getSearchCellValue = (0, import_react6.useCallback)(
|
|
2806
3047
|
(rowIndex, colIndex) => {
|
|
2807
3048
|
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
2808
3049
|
const column = visibleLeafColumns[colIndex];
|
|
@@ -2825,14 +3066,14 @@ function useGlideTable(options) {
|
|
|
2825
3066
|
},
|
|
2826
3067
|
[rows, visibleLeafColumns, visibleRowIndexById]
|
|
2827
3068
|
);
|
|
2828
|
-
const pendingSearchNavRef = (0,
|
|
2829
|
-
const focusSearchResult = (0,
|
|
3069
|
+
const pendingSearchNavRef = (0, import_react6.useRef)(null);
|
|
3070
|
+
const focusSearchResult = (0, import_react6.useCallback)(
|
|
2830
3071
|
(colIndex, visibleRowIndex) => {
|
|
2831
3072
|
navigateToSearchResult([colIndex, visibleRowIndex]);
|
|
2832
3073
|
},
|
|
2833
3074
|
[navigateToSearchResult]
|
|
2834
3075
|
);
|
|
2835
|
-
const navigateToCorpusSearchResult = (0,
|
|
3076
|
+
const navigateToCorpusSearchResult = (0, import_react6.useCallback)(
|
|
2836
3077
|
(item) => {
|
|
2837
3078
|
const [colIndex, corpusRowIndex] = item;
|
|
2838
3079
|
const corpusRow = searchCorpusRef.current[corpusRowIndex];
|
|
@@ -2865,7 +3106,7 @@ function useGlideTable(options) {
|
|
|
2865
3106
|
visibleRowIndexById
|
|
2866
3107
|
]
|
|
2867
3108
|
);
|
|
2868
|
-
(0,
|
|
3109
|
+
(0, import_react6.useEffect)(() => {
|
|
2869
3110
|
const pending = pendingSearchNavRef.current;
|
|
2870
3111
|
if (!pending) return;
|
|
2871
3112
|
const visibleRowIndex = visibleRowIndexById.get(pending.rowId);
|
|
@@ -2889,7 +3130,7 @@ function useGlideTable(options) {
|
|
|
2889
3130
|
onNavigateToResult: navigateToCorpusSearchResult,
|
|
2890
3131
|
rootRef
|
|
2891
3132
|
});
|
|
2892
|
-
const visibleSearchMatchKeys = (0,
|
|
3133
|
+
const visibleSearchMatchKeys = (0, import_react6.useMemo)(() => {
|
|
2893
3134
|
if (!enableInlineSearch) return EMPTY_SEARCH_MATCH_KEYS;
|
|
2894
3135
|
return mapSearchResultsToVisibleKeys(
|
|
2895
3136
|
inlineSearch.searchResults,
|
|
@@ -2902,7 +3143,7 @@ function useGlideTable(options) {
|
|
|
2902
3143
|
searchCorpus,
|
|
2903
3144
|
visibleRowIndexById
|
|
2904
3145
|
]);
|
|
2905
|
-
const visibleActiveMatch = (0,
|
|
3146
|
+
const visibleActiveMatch = (0, import_react6.useMemo)(() => {
|
|
2906
3147
|
if (!enableInlineSearch || !inlineSearch.activeMatch) return null;
|
|
2907
3148
|
return mapSearchResultToVisibleItem(
|
|
2908
3149
|
inlineSearch.activeMatch,
|
|
@@ -2915,13 +3156,13 @@ function useGlideTable(options) {
|
|
|
2915
3156
|
searchCorpus,
|
|
2916
3157
|
visibleRowIndexById
|
|
2917
3158
|
]);
|
|
2918
|
-
const clearHover = (0,
|
|
3159
|
+
const clearHover = (0, import_react6.useCallback)(() => {
|
|
2919
3160
|
setHoveredRowIndex(null);
|
|
2920
3161
|
}, []);
|
|
2921
|
-
const handleRowHover = (0,
|
|
3162
|
+
const handleRowHover = (0, import_react6.useCallback)((rowIndex, _rowData) => {
|
|
2922
3163
|
setHoveredRowIndex(rowIndex);
|
|
2923
3164
|
}, []);
|
|
2924
|
-
const handleToggleSelect = (0,
|
|
3165
|
+
const handleToggleSelect = (0, import_react6.useCallback)(
|
|
2925
3166
|
(row) => {
|
|
2926
3167
|
if (!row.getCanSelect()) return;
|
|
2927
3168
|
if (preserveRowSelection && row.getIsSelected()) {
|
|
@@ -2931,14 +3172,14 @@ function useGlideTable(options) {
|
|
|
2931
3172
|
},
|
|
2932
3173
|
[preserveRowSelection]
|
|
2933
3174
|
);
|
|
2934
|
-
const handleToggleExpand = (0,
|
|
3175
|
+
const handleToggleExpand = (0, import_react6.useCallback)(
|
|
2935
3176
|
(rowKey) => {
|
|
2936
3177
|
if (preventExpand) return;
|
|
2937
3178
|
handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
|
|
2938
3179
|
},
|
|
2939
3180
|
[preventExpand, handleExpandedRowsChange, expandedRows]
|
|
2940
3181
|
);
|
|
2941
|
-
const rowContextValue = (0,
|
|
3182
|
+
const rowContextValue = (0, import_react6.useMemo)(() => {
|
|
2942
3183
|
return {
|
|
2943
3184
|
rowSpan: {
|
|
2944
3185
|
enableRowSpan,
|
|
@@ -3037,12 +3278,12 @@ function useGlideTable(options) {
|
|
|
3037
3278
|
visibleSearchMatchKeys,
|
|
3038
3279
|
visibleActiveMatch
|
|
3039
3280
|
]);
|
|
3040
|
-
const copySelectionRef = (0,
|
|
3041
|
-
(0,
|
|
3281
|
+
const copySelectionRef = (0, import_react6.useRef)(copySelection);
|
|
3282
|
+
(0, import_react6.useEffect)(() => {
|
|
3042
3283
|
copySelectionRef.current = copySelection;
|
|
3043
3284
|
}, [copySelection]);
|
|
3044
|
-
const stableCopySelection = (0,
|
|
3045
|
-
(0,
|
|
3285
|
+
const stableCopySelection = (0, import_react6.useCallback)((options2) => copySelectionRef.current(options2), []);
|
|
3286
|
+
(0, import_react6.useEffect)(() => {
|
|
3046
3287
|
onCopyActionsReady?.({ copySelection: stableCopySelection });
|
|
3047
3288
|
}, [onCopyActionsReady, stableCopySelection]);
|
|
3048
3289
|
return {
|
|
@@ -3091,16 +3332,18 @@ function useGlideTable(options) {
|
|
|
3091
3332
|
}
|
|
3092
3333
|
|
|
3093
3334
|
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
3094
|
-
var
|
|
3335
|
+
var import_react8 = require("react");
|
|
3095
3336
|
|
|
3096
3337
|
// src/components/ui/table/DataTableContext.tsx
|
|
3097
|
-
var
|
|
3338
|
+
var import_react7 = require("react");
|
|
3098
3339
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
3099
|
-
var DataTableContext = (0,
|
|
3340
|
+
var DataTableContext = (0, import_react7.createContext)(null);
|
|
3100
3341
|
function useDataTableRowContext() {
|
|
3101
|
-
const context = (0,
|
|
3342
|
+
const context = (0, import_react7.use)(DataTableContext);
|
|
3102
3343
|
if (!context) {
|
|
3103
|
-
throw new Error(
|
|
3344
|
+
throw new Error(
|
|
3345
|
+
"useDataTableRowContext must be used within a DataTableContextProvider"
|
|
3346
|
+
);
|
|
3104
3347
|
}
|
|
3105
3348
|
return context;
|
|
3106
3349
|
}
|
|
@@ -3120,7 +3363,7 @@ function ResolvedTableCell({
|
|
|
3120
3363
|
const meta = column.columnDef.meta;
|
|
3121
3364
|
const value = getValue();
|
|
3122
3365
|
const columnId = column.id;
|
|
3123
|
-
const update = (0,
|
|
3366
|
+
const update = (0, import_react8.useCallback)(
|
|
3124
3367
|
(next) => {
|
|
3125
3368
|
cellRender.commitValue(row.id, columnId, next);
|
|
3126
3369
|
},
|
|
@@ -3145,8 +3388,105 @@ function ResolvedTableCell({
|
|
|
3145
3388
|
}
|
|
3146
3389
|
|
|
3147
3390
|
// src/components/ui/table/features/column-resize/columnResize.ts
|
|
3391
|
+
function clamp(value, min, max) {
|
|
3392
|
+
return Math.min(Math.max(value, min), max);
|
|
3393
|
+
}
|
|
3394
|
+
function floorOf(column) {
|
|
3395
|
+
return column.minWidth ?? 0;
|
|
3396
|
+
}
|
|
3397
|
+
function ceilOf(column) {
|
|
3398
|
+
return column.maxWidth ?? Number.POSITIVE_INFINITY;
|
|
3399
|
+
}
|
|
3400
|
+
function preferOf(column) {
|
|
3401
|
+
const floor = floorOf(column);
|
|
3402
|
+
const ceil = ceilOf(column);
|
|
3403
|
+
const preferred = column.maxWidth ?? column.minWidth ?? 0;
|
|
3404
|
+
return clamp(preferred, floor, Number.isFinite(ceil) ? ceil : preferred);
|
|
3405
|
+
}
|
|
3406
|
+
function resolveColumnLayoutWidths(containerWidth, columns) {
|
|
3407
|
+
const widths = /* @__PURE__ */ new Map();
|
|
3408
|
+
const fixed = [];
|
|
3409
|
+
const bounded = [];
|
|
3410
|
+
let flexCount = 0;
|
|
3411
|
+
for (const column of columns) {
|
|
3412
|
+
if (column.width != null) {
|
|
3413
|
+
fixed.push(column);
|
|
3414
|
+
} else if (column.minWidth != null || column.maxWidth != null) {
|
|
3415
|
+
bounded.push(column);
|
|
3416
|
+
} else {
|
|
3417
|
+
flexCount += 1;
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
let used = 0;
|
|
3421
|
+
for (const column of fixed) {
|
|
3422
|
+
let size = column.width;
|
|
3423
|
+
if (column.minWidth != null) size = Math.max(size, column.minWidth);
|
|
3424
|
+
if (column.maxWidth != null) size = Math.min(size, column.maxWidth);
|
|
3425
|
+
widths.set(column.id, size);
|
|
3426
|
+
used += size;
|
|
3427
|
+
}
|
|
3428
|
+
if (bounded.length === 0) {
|
|
3429
|
+
return widths;
|
|
3430
|
+
}
|
|
3431
|
+
const boundedSizes = /* @__PURE__ */ new Map();
|
|
3432
|
+
let preferredSum = 0;
|
|
3433
|
+
let floorSum = 0;
|
|
3434
|
+
for (const column of bounded) {
|
|
3435
|
+
const preferred = preferOf(column);
|
|
3436
|
+
boundedSizes.set(column.id, preferred);
|
|
3437
|
+
preferredSum += preferred;
|
|
3438
|
+
floorSum += floorOf(column);
|
|
3439
|
+
}
|
|
3440
|
+
if (containerWidth > 0) {
|
|
3441
|
+
const remaining = Math.max(0, containerWidth - used);
|
|
3442
|
+
if (remaining >= preferredSum) {
|
|
3443
|
+
} else if (remaining >= floorSum) {
|
|
3444
|
+
let deficit = preferredSum - remaining;
|
|
3445
|
+
const open = bounded.map((column) => ({
|
|
3446
|
+
id: column.id,
|
|
3447
|
+
current: boundedSizes.get(column.id),
|
|
3448
|
+
floor: floorOf(column)
|
|
3449
|
+
}));
|
|
3450
|
+
while (deficit >= 1) {
|
|
3451
|
+
const shrinkable = open.filter((entry) => entry.current > entry.floor);
|
|
3452
|
+
if (shrinkable.length === 0) break;
|
|
3453
|
+
const portion = Math.floor(deficit / shrinkable.length);
|
|
3454
|
+
const rem = deficit % shrinkable.length;
|
|
3455
|
+
let consumed = 0;
|
|
3456
|
+
for (let index = 0; index < shrinkable.length; index += 1) {
|
|
3457
|
+
const entry = shrinkable[index];
|
|
3458
|
+
const reduce = Math.min(
|
|
3459
|
+
entry.current - entry.floor,
|
|
3460
|
+
portion + (index < rem ? 1 : 0)
|
|
3461
|
+
);
|
|
3462
|
+
entry.current -= reduce;
|
|
3463
|
+
consumed += reduce;
|
|
3464
|
+
}
|
|
3465
|
+
if (consumed === 0) break;
|
|
3466
|
+
deficit -= consumed;
|
|
3467
|
+
}
|
|
3468
|
+
for (const entry of open) {
|
|
3469
|
+
boundedSizes.set(entry.id, entry.current);
|
|
3470
|
+
}
|
|
3471
|
+
} else {
|
|
3472
|
+
for (const column of bounded) {
|
|
3473
|
+
boundedSizes.set(column.id, floorOf(column));
|
|
3474
|
+
}
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
for (const [id, size] of boundedSizes) {
|
|
3478
|
+
widths.set(id, Math.round(size));
|
|
3479
|
+
}
|
|
3480
|
+
return widths;
|
|
3481
|
+
}
|
|
3148
3482
|
function getColumnSizeStyle(size, options) {
|
|
3149
|
-
const {
|
|
3483
|
+
const {
|
|
3484
|
+
force = false,
|
|
3485
|
+
lockMax = false,
|
|
3486
|
+
minWidth,
|
|
3487
|
+
maxWidth,
|
|
3488
|
+
layoutWidth
|
|
3489
|
+
} = options ?? {};
|
|
3150
3490
|
if (lockMax) {
|
|
3151
3491
|
return {
|
|
3152
3492
|
width: size,
|
|
@@ -3154,14 +3494,27 @@ function getColumnSizeStyle(size, options) {
|
|
|
3154
3494
|
maxWidth: size
|
|
3155
3495
|
};
|
|
3156
3496
|
}
|
|
3497
|
+
if (layoutWidth != null) {
|
|
3498
|
+
return {
|
|
3499
|
+
width: layoutWidth,
|
|
3500
|
+
minWidth: layoutWidth,
|
|
3501
|
+
maxWidth: layoutWidth
|
|
3502
|
+
};
|
|
3503
|
+
}
|
|
3504
|
+
const resolvedSize = size;
|
|
3157
3505
|
const hasExplicitSize = force || size !== DATA_TABLE_COLUMN_SIZE;
|
|
3158
3506
|
if (!hasExplicitSize && minWidth == null && maxWidth == null) {
|
|
3159
3507
|
return void 0;
|
|
3160
3508
|
}
|
|
3161
3509
|
const style = {};
|
|
3162
3510
|
if (hasExplicitSize) {
|
|
3163
|
-
|
|
3164
|
-
|
|
3511
|
+
const used = minWidth != null || maxWidth != null ? clamp(
|
|
3512
|
+
resolvedSize,
|
|
3513
|
+
minWidth ?? Number.NEGATIVE_INFINITY,
|
|
3514
|
+
maxWidth ?? Number.POSITIVE_INFINITY
|
|
3515
|
+
) : resolvedSize;
|
|
3516
|
+
style.width = used;
|
|
3517
|
+
style.minWidth = minWidth ?? used;
|
|
3165
3518
|
} else if (minWidth != null) {
|
|
3166
3519
|
style.minWidth = minWidth;
|
|
3167
3520
|
}
|
|
@@ -3172,7 +3525,7 @@ function getColumnSizeStyle(size, options) {
|
|
|
3172
3525
|
}
|
|
3173
3526
|
|
|
3174
3527
|
// src/components/ui/table/features/column-reorder/useColumnReorder.ts
|
|
3175
|
-
var
|
|
3528
|
+
var import_react9 = require("react");
|
|
3176
3529
|
function hitTestReorderHeader(table, clientX, clientY) {
|
|
3177
3530
|
const headers = Array.from(
|
|
3178
3531
|
table.querySelectorAll(
|
|
@@ -3220,19 +3573,19 @@ function readTargetIds(table, columnId) {
|
|
|
3220
3573
|
}
|
|
3221
3574
|
function useColumnReorder(options) {
|
|
3222
3575
|
const { enabled, columnOrder, onColumnOrderChange } = options;
|
|
3223
|
-
const sessionRef = (0,
|
|
3224
|
-
const columnOrderRef = (0,
|
|
3225
|
-
const onColumnOrderChangeRef = (0,
|
|
3226
|
-
const [draggingColumnId, setDraggingColumnId] = (0,
|
|
3227
|
-
const [dropTarget, setDropTarget] = (0,
|
|
3576
|
+
const sessionRef = (0, import_react9.useRef)(null);
|
|
3577
|
+
const columnOrderRef = (0, import_react9.useRef)(columnOrder);
|
|
3578
|
+
const onColumnOrderChangeRef = (0, import_react9.useRef)(onColumnOrderChange);
|
|
3579
|
+
const [draggingColumnId, setDraggingColumnId] = (0, import_react9.useState)(null);
|
|
3580
|
+
const [dropTarget, setDropTarget] = (0, import_react9.useState)(
|
|
3228
3581
|
null
|
|
3229
3582
|
);
|
|
3230
|
-
const dropTargetRef = (0,
|
|
3231
|
-
const previousUserSelectRef = (0,
|
|
3583
|
+
const dropTargetRef = (0, import_react9.useRef)(dropTarget);
|
|
3584
|
+
const previousUserSelectRef = (0, import_react9.useRef)(null);
|
|
3232
3585
|
columnOrderRef.current = columnOrder;
|
|
3233
3586
|
onColumnOrderChangeRef.current = onColumnOrderChange;
|
|
3234
3587
|
dropTargetRef.current = dropTarget;
|
|
3235
|
-
const resetDrag = (0,
|
|
3588
|
+
const resetDrag = (0, import_react9.useCallback)(() => {
|
|
3236
3589
|
sessionRef.current = null;
|
|
3237
3590
|
setDraggingColumnId(null);
|
|
3238
3591
|
setDropTarget(null);
|
|
@@ -3248,15 +3601,15 @@ function useColumnReorder(options) {
|
|
|
3248
3601
|
}
|
|
3249
3602
|
document.body.style.removeProperty("user-select");
|
|
3250
3603
|
}, []);
|
|
3251
|
-
(0,
|
|
3604
|
+
(0, import_react9.useEffect)(() => {
|
|
3252
3605
|
if (!enabled) resetDrag();
|
|
3253
3606
|
}, [enabled, resetDrag]);
|
|
3254
|
-
(0,
|
|
3607
|
+
(0, import_react9.useEffect)(() => {
|
|
3255
3608
|
return () => {
|
|
3256
3609
|
resetDrag();
|
|
3257
3610
|
};
|
|
3258
3611
|
}, [resetDrag]);
|
|
3259
|
-
const onHeaderPointerDown = (0,
|
|
3612
|
+
const onHeaderPointerDown = (0, import_react9.useCallback)(
|
|
3260
3613
|
(event, meta) => {
|
|
3261
3614
|
if (!enabled || !meta.canDrag) return;
|
|
3262
3615
|
if (event.button !== 0) return;
|
|
@@ -3279,7 +3632,7 @@ function useColumnReorder(options) {
|
|
|
3279
3632
|
},
|
|
3280
3633
|
[enabled]
|
|
3281
3634
|
);
|
|
3282
|
-
(0,
|
|
3635
|
+
(0, import_react9.useEffect)(() => {
|
|
3283
3636
|
if (!enabled) return;
|
|
3284
3637
|
const onPointerMove = (event) => {
|
|
3285
3638
|
const session = sessionRef.current;
|
|
@@ -3381,11 +3734,11 @@ function useColumnReorder(options) {
|
|
|
3381
3734
|
|
|
3382
3735
|
// src/components/ui/table/components/DataTable/DataTable.tsx
|
|
3383
3736
|
var import_react_table3 = require("@tanstack/react-table");
|
|
3384
|
-
var
|
|
3737
|
+
var import_react11 = require("react");
|
|
3385
3738
|
|
|
3386
3739
|
// src/components/ui/table/components/DataTable/DataTableRow.tsx
|
|
3387
3740
|
var import_react_table2 = require("@tanstack/react-table");
|
|
3388
|
-
var
|
|
3741
|
+
var import_react10 = require("react");
|
|
3389
3742
|
|
|
3390
3743
|
// src/components/ui/table/components/icons.tsx
|
|
3391
3744
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -3547,6 +3900,12 @@ function isInteractiveMouseTarget(target) {
|
|
|
3547
3900
|
].join(",");
|
|
3548
3901
|
return target.closest(interactiveSelector) !== null;
|
|
3549
3902
|
}
|
|
3903
|
+
function blurActiveElementOutside(container) {
|
|
3904
|
+
const active = document.activeElement;
|
|
3905
|
+
if (!(active instanceof HTMLElement) || active === document.body) return;
|
|
3906
|
+
if (container instanceof Node && container.contains(active)) return;
|
|
3907
|
+
active.blur();
|
|
3908
|
+
}
|
|
3550
3909
|
function resolveExpandCellIndex(cells, toggleField) {
|
|
3551
3910
|
if (!toggleField) return 0;
|
|
3552
3911
|
const matchedIndex = cells.findIndex(
|
|
@@ -3579,7 +3938,7 @@ function DataTableRow({
|
|
|
3579
3938
|
columnFreeze,
|
|
3580
3939
|
inlineSearch
|
|
3581
3940
|
} = useDataTableRowContext();
|
|
3582
|
-
const { enableColumnResize } = columnResize;
|
|
3941
|
+
const { enableColumnResize, layoutWidths } = columnResize;
|
|
3583
3942
|
const { enableColumnFreeze, offsets: freezeOffsets } = columnFreeze;
|
|
3584
3943
|
const {
|
|
3585
3944
|
enabled: enableInlineSearch,
|
|
@@ -3683,9 +4042,9 @@ function DataTableRow({
|
|
|
3683
4042
|
const expandKey = toggleField && rowData[toggleField] !== null && rowData[toggleField] !== void 0 ? String(rowData[toggleField]) : null;
|
|
3684
4043
|
const isExpanded = expandKey !== null && Boolean(expandedRows?.has(expandKey));
|
|
3685
4044
|
const rowLevel = typeof rowData.level === "number" ? rowData.level : 0;
|
|
3686
|
-
const editInputRef = (0,
|
|
4045
|
+
const editInputRef = (0, import_react10.useRef)(null);
|
|
3687
4046
|
const isRowEditing = editingCell?.rowIndex === rowIndex;
|
|
3688
|
-
(0,
|
|
4047
|
+
(0, import_react10.useEffect)(() => {
|
|
3689
4048
|
if (!isRowEditing) return;
|
|
3690
4049
|
editInputRef.current?.focus();
|
|
3691
4050
|
editInputRef.current?.select();
|
|
@@ -3774,7 +4133,8 @@ function DataTableRow({
|
|
|
3774
4133
|
force: enableColumnResize,
|
|
3775
4134
|
lockMax: enableColumnResize,
|
|
3776
4135
|
minWidth: meta?.minWidth,
|
|
3777
|
-
maxWidth: meta?.maxWidth
|
|
4136
|
+
maxWidth: meta?.maxWidth,
|
|
4137
|
+
layoutWidth: layoutWidths?.get(columnId)
|
|
3778
4138
|
});
|
|
3779
4139
|
const freezeOffset = enableColumnFreeze ? freezeOffsets.get(columnId) : void 0;
|
|
3780
4140
|
const freezeStyle = getColumnFreezeStyle(freezeOffset);
|
|
@@ -3814,6 +4174,7 @@ function DataTableRow({
|
|
|
3814
4174
|
if (!enableCellSelection) return;
|
|
3815
4175
|
if (isInteractiveMouseTarget(event.target)) return;
|
|
3816
4176
|
event.preventDefault();
|
|
4177
|
+
blurActiveElementOutside(event.currentTarget);
|
|
3817
4178
|
onCellMouseDown(
|
|
3818
4179
|
resolveCellRowIndex(event.clientY, event.currentTarget),
|
|
3819
4180
|
cellIndex,
|
|
@@ -3977,6 +4338,7 @@ function DataTableRow({
|
|
|
3977
4338
|
onMouseDown: (event) => {
|
|
3978
4339
|
event.stopPropagation();
|
|
3979
4340
|
event.preventDefault();
|
|
4341
|
+
blurActiveElementOutside(event.currentTarget);
|
|
3980
4342
|
onFillHandleMouseDown(rowIndex, cellIndex);
|
|
3981
4343
|
}
|
|
3982
4344
|
}
|
|
@@ -4306,17 +4668,74 @@ function DataTable({
|
|
|
4306
4668
|
const RowSlot = slots?.Row ?? DataTableRow;
|
|
4307
4669
|
const PendingSlot = slots?.Pending ?? DefaultPending;
|
|
4308
4670
|
const EmptySlot = slots?.Empty ?? DefaultEmpty;
|
|
4309
|
-
const freezeOffsets = rowContextValue.columnFreeze.offsets;
|
|
4310
4671
|
const headerGroups = getMergedHeaderGroups(table.getHeaderGroups());
|
|
4311
4672
|
const leafColumnIds = table.getVisibleLeafColumns().map((column) => column.id);
|
|
4673
|
+
const columnLayoutMetaSignature = table.getVisibleLeafColumns().map((column) => {
|
|
4674
|
+
const meta = column.columnDef.meta;
|
|
4675
|
+
return `${column.id}:${meta?.width ?? ""}:${meta?.minWidth ?? ""}:${meta?.maxWidth ?? ""}`;
|
|
4676
|
+
}).join("|");
|
|
4312
4677
|
const { isReordering, draggingColumnId, dropTarget, onHeaderPointerDown } = useColumnReorder({
|
|
4313
4678
|
enabled: enableColumnReorder,
|
|
4314
4679
|
columnOrder: leafColumnIds,
|
|
4315
4680
|
onColumnOrderChange: setColumnOrder
|
|
4316
4681
|
});
|
|
4317
|
-
const
|
|
4318
|
-
|
|
4319
|
-
|
|
4682
|
+
const [containerWidth, setContainerWidth] = (0, import_react11.useState)(0);
|
|
4683
|
+
(0, import_react11.useEffect)(() => {
|
|
4684
|
+
if (enableColumnResize || isPending) return;
|
|
4685
|
+
const element = scrollRef.current;
|
|
4686
|
+
if (!element) return;
|
|
4687
|
+
const updateWidth = () => {
|
|
4688
|
+
setContainerWidth(Math.floor(element.clientWidth));
|
|
4689
|
+
};
|
|
4690
|
+
updateWidth();
|
|
4691
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
4692
|
+
const observer = new ResizeObserver(() => {
|
|
4693
|
+
updateWidth();
|
|
4694
|
+
});
|
|
4695
|
+
observer.observe(element);
|
|
4696
|
+
return () => observer.disconnect();
|
|
4697
|
+
}, [enableColumnResize, isPending, scrollRef, rows.length, leafColumnIds.join("|")]);
|
|
4698
|
+
const layoutWidths = (0, import_react11.useMemo)(() => {
|
|
4699
|
+
if (enableColumnResize) return void 0;
|
|
4700
|
+
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4701
|
+
id: column.id,
|
|
4702
|
+
width: column.columnDef.meta?.width,
|
|
4703
|
+
minWidth: column.columnDef.meta?.minWidth,
|
|
4704
|
+
maxWidth: column.columnDef.meta?.maxWidth
|
|
4705
|
+
}));
|
|
4706
|
+
return resolveColumnLayoutWidths(containerWidth, columns);
|
|
4707
|
+
}, [enableColumnResize, containerWidth, table, columnLayoutMetaSignature]);
|
|
4708
|
+
const freezeOffsets = (0, import_react11.useMemo)(() => {
|
|
4709
|
+
if (!enableColumnFreeze || enableColumnResize || !layoutWidths) {
|
|
4710
|
+
return rowContextValue.columnFreeze.offsets;
|
|
4711
|
+
}
|
|
4712
|
+
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4713
|
+
id: column.id,
|
|
4714
|
+
size: layoutWidths.get(column.id) ?? column.getSize(),
|
|
4715
|
+
side: resolveColumnFreezeSide(column.columnDef.meta?.frozen)
|
|
4716
|
+
}));
|
|
4717
|
+
return buildColumnFreezeOffsets(columns);
|
|
4718
|
+
}, [
|
|
4719
|
+
enableColumnFreeze,
|
|
4720
|
+
enableColumnResize,
|
|
4721
|
+
layoutWidths,
|
|
4722
|
+
rowContextValue.columnFreeze.offsets,
|
|
4723
|
+
table
|
|
4724
|
+
]);
|
|
4725
|
+
const contextValue = (0, import_react11.useMemo)(
|
|
4726
|
+
() => ({
|
|
4727
|
+
...rowContextValue,
|
|
4728
|
+
classNames,
|
|
4729
|
+
columnFreeze: {
|
|
4730
|
+
...rowContextValue.columnFreeze,
|
|
4731
|
+
offsets: freezeOffsets
|
|
4732
|
+
},
|
|
4733
|
+
columnResize: {
|
|
4734
|
+
...rowContextValue.columnResize,
|
|
4735
|
+
layoutWidths
|
|
4736
|
+
}
|
|
4737
|
+
}),
|
|
4738
|
+
[rowContextValue, classNames, freezeOffsets, layoutWidths]
|
|
4320
4739
|
);
|
|
4321
4740
|
if (isPending) {
|
|
4322
4741
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
@@ -4397,7 +4816,8 @@ function DataTable({
|
|
|
4397
4816
|
force: enableColumnResize,
|
|
4398
4817
|
lockMax: enableColumnResize,
|
|
4399
4818
|
minWidth: header.column.columnDef.meta?.minWidth,
|
|
4400
|
-
maxWidth: header.column.columnDef.meta?.maxWidth
|
|
4819
|
+
maxWidth: header.column.columnDef.meta?.maxWidth,
|
|
4820
|
+
layoutWidth: layoutWidths?.get(header.column.id)
|
|
4401
4821
|
});
|
|
4402
4822
|
const freezeOffset = enableColumnFreeze ? resolveHeaderFreezeOffset(header.column, freezeOffsets) : void 0;
|
|
4403
4823
|
const freezeStyle = getColumnFreezeStyle(freezeOffset, {
|
|
@@ -4410,7 +4830,9 @@ function DataTable({
|
|
|
4410
4830
|
};
|
|
4411
4831
|
const isPlaceholder = header.isPlaceholder;
|
|
4412
4832
|
const leafColumns = header.column.getLeafColumns();
|
|
4413
|
-
const leafIds = leafColumns.map(
|
|
4833
|
+
const leafIds = leafColumns.map(
|
|
4834
|
+
(leafColumn) => leafColumn.id
|
|
4835
|
+
);
|
|
4414
4836
|
const isLeafHeader = !isPlaceholder && header.subHeaders.length === 0;
|
|
4415
4837
|
const canDrag = enableColumnReorder && !isPlaceholder && leafIds.length > 0 && leafColumns.every(
|
|
4416
4838
|
(leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
|
|
@@ -4566,7 +4988,7 @@ function DataTable({
|
|
|
4566
4988
|
}
|
|
4567
4989
|
|
|
4568
4990
|
// src/components/ui/table/components/Table/Table.tsx
|
|
4569
|
-
var
|
|
4991
|
+
var import_react14 = require("react");
|
|
4570
4992
|
|
|
4571
4993
|
// src/components/ui/table/components/Table/buildColumnDef.tsx
|
|
4572
4994
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
@@ -4655,6 +5077,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4655
5077
|
cellRender: render,
|
|
4656
5078
|
frozen,
|
|
4657
5079
|
reorderable,
|
|
5080
|
+
width,
|
|
4658
5081
|
minWidth,
|
|
4659
5082
|
maxWidth,
|
|
4660
5083
|
className,
|
|
@@ -4702,10 +5125,10 @@ function countLeafColumns(nodes) {
|
|
|
4702
5125
|
}
|
|
4703
5126
|
|
|
4704
5127
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
4705
|
-
var
|
|
5128
|
+
var import_react13 = require("react");
|
|
4706
5129
|
|
|
4707
5130
|
// src/components/ui/table/components/Table/tableChildTypes.ts
|
|
4708
|
-
var
|
|
5131
|
+
var import_react12 = require("react");
|
|
4709
5132
|
var TABLE_HEADER_DISPLAY_NAME = "Table.Header";
|
|
4710
5133
|
var TABLE_BODY_DISPLAY_NAME = "Table.Body";
|
|
4711
5134
|
var TABLE_COLUMN_DISPLAY_NAME = "Table.Column";
|
|
@@ -4718,19 +5141,19 @@ function getComponentDisplayName(type) {
|
|
|
4718
5141
|
return void 0;
|
|
4719
5142
|
}
|
|
4720
5143
|
function isTableHeaderElement(child) {
|
|
4721
|
-
return (0,
|
|
5144
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
|
|
4722
5145
|
}
|
|
4723
5146
|
function isTableBodyElement(child) {
|
|
4724
|
-
return (0,
|
|
5147
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
|
|
4725
5148
|
}
|
|
4726
5149
|
function isTableColumnElement(child) {
|
|
4727
|
-
return (0,
|
|
5150
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
|
|
4728
5151
|
}
|
|
4729
5152
|
function isTableColumnGroupElement(child) {
|
|
4730
|
-
return (0,
|
|
5153
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_GROUP_DISPLAY_NAME;
|
|
4731
5154
|
}
|
|
4732
5155
|
function isTablePaginationElement(child) {
|
|
4733
|
-
return (0,
|
|
5156
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
|
|
4734
5157
|
}
|
|
4735
5158
|
|
|
4736
5159
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
@@ -4740,7 +5163,7 @@ function parseTableChildren(children) {
|
|
|
4740
5163
|
body: null,
|
|
4741
5164
|
pagination: null
|
|
4742
5165
|
};
|
|
4743
|
-
for (const child of
|
|
5166
|
+
for (const child of import_react13.Children.toArray(children)) {
|
|
4744
5167
|
if (isTableHeaderElement(child)) {
|
|
4745
5168
|
slots.header = child;
|
|
4746
5169
|
continue;
|
|
@@ -4757,7 +5180,7 @@ function parseTableChildren(children) {
|
|
|
4757
5180
|
}
|
|
4758
5181
|
function walkColumnTreeNodes(children) {
|
|
4759
5182
|
const result = [];
|
|
4760
|
-
for (const child of
|
|
5183
|
+
for (const child of import_react13.Children.toArray(children)) {
|
|
4761
5184
|
if (isTableColumnElement(child)) {
|
|
4762
5185
|
result.push({
|
|
4763
5186
|
type: "leaf",
|
|
@@ -4774,7 +5197,7 @@ function walkColumnTreeNodes(children) {
|
|
|
4774
5197
|
});
|
|
4775
5198
|
continue;
|
|
4776
5199
|
}
|
|
4777
|
-
if ((0,
|
|
5200
|
+
if ((0, import_react13.isValidElement)(child)) {
|
|
4778
5201
|
const nested = child.props.children;
|
|
4779
5202
|
if (nested != null) {
|
|
4780
5203
|
result.push(...walkColumnTreeNodes(nested));
|
|
@@ -4900,12 +5323,12 @@ function TableRoot({
|
|
|
4900
5323
|
filteredCount,
|
|
4901
5324
|
...dataTableProps
|
|
4902
5325
|
}) {
|
|
4903
|
-
const { header, pagination: paginationElement } = (0,
|
|
5326
|
+
const { header, pagination: paginationElement } = (0, import_react14.useMemo)(
|
|
4904
5327
|
() => parseTableChildren(children),
|
|
4905
5328
|
[children]
|
|
4906
5329
|
);
|
|
4907
|
-
const [sort, setSort] = (0,
|
|
4908
|
-
const handleSort = (0,
|
|
5330
|
+
const [sort, setSort] = (0, import_react14.useState)(null);
|
|
5331
|
+
const handleSort = (0, import_react14.useCallback)((field) => {
|
|
4909
5332
|
setSort((previous) => {
|
|
4910
5333
|
if (previous?.field !== field) {
|
|
4911
5334
|
return { field, direction: "asc" };
|
|
@@ -4916,8 +5339,8 @@ function TableRoot({
|
|
|
4916
5339
|
return null;
|
|
4917
5340
|
});
|
|
4918
5341
|
}, []);
|
|
4919
|
-
const columnTree = (0,
|
|
4920
|
-
const columns = (0,
|
|
5342
|
+
const columnTree = (0, import_react14.useMemo)(() => extractColumnTree(header), [header]);
|
|
5343
|
+
const columns = (0, import_react14.useMemo)(
|
|
4921
5344
|
() => buildColumnDefsFromTree(columnTree, sort, handleSort),
|
|
4922
5345
|
[columnTree, sort, handleSort]
|
|
4923
5346
|
);
|
|
@@ -4925,7 +5348,7 @@ function TableRoot({
|
|
|
4925
5348
|
const pageSize = paginationProps?.pageSize ?? 10;
|
|
4926
5349
|
const page = paginationProps?.page ?? 1;
|
|
4927
5350
|
const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
|
|
4928
|
-
const tableData = (0,
|
|
5351
|
+
const tableData = (0, import_react14.useMemo)(() => {
|
|
4929
5352
|
const sortedData = sortTableData(data, sort);
|
|
4930
5353
|
if (!paginationProps) return sortedData;
|
|
4931
5354
|
return paginateTableData(sortedData, page, pageSize);
|
|
@@ -5053,6 +5476,7 @@ var Table = Object.assign(TableRoot, {
|
|
|
5053
5476
|
previousSearchIndex,
|
|
5054
5477
|
resolveCellRenderer,
|
|
5055
5478
|
resolveColumnFreezeSide,
|
|
5479
|
+
resolveColumnLayoutWidths,
|
|
5056
5480
|
resolveDataTableLabels,
|
|
5057
5481
|
resolveDropEdge,
|
|
5058
5482
|
resolveHeaderFreezeOffset,
|