react-glide-table 2.2.1 → 2.3.1

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/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 import_react5 = require("react");
140
+ var import_react6 = require("react");
140
141
 
141
142
  // src/components/ui/table/constants.ts
142
143
  var CELL_ALIGN_CLASS = {
@@ -537,8 +538,92 @@ function withCellUpdate(context, commitValue) {
537
538
  };
538
539
  }
539
540
 
541
+ // src/components/ui/table/features/cell-selection/pasteData.ts
542
+ function countLeadingEmptyCells(cells) {
543
+ let depth = 0;
544
+ while (depth < cells.length && cells[depth] === "") {
545
+ depth += 1;
546
+ }
547
+ return depth;
548
+ }
549
+ function looksLikeSubtreeIndentation(leadingEmptyCounts) {
550
+ if (leadingEmptyCounts.length === 0) return false;
551
+ const firstDepth = leadingEmptyCounts[0] ?? 0;
552
+ if (firstDepth !== 0) return false;
553
+ return leadingEmptyCounts.some((depth) => depth > 0);
554
+ }
555
+ function parseClipboardTSV(text) {
556
+ return parseClipboardTSVWithDepths(text).values;
557
+ }
558
+ function parseClipboardTSVWithDepths(text) {
559
+ if (!text) return { values: [], depths: [] };
560
+ const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
561
+ const withoutTrailing = normalized.replace(/\n+$/, "");
562
+ if (!withoutTrailing) return { values: [], depths: [] };
563
+ const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
564
+ const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
565
+ const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
566
+ const values = [];
567
+ const depths = [];
568
+ for (let index = 0; index < rows.length; index += 1) {
569
+ const cells = rows[index] ?? [];
570
+ const depth = leadingEmptyCounts[index] ?? 0;
571
+ if (treatAsDepth) {
572
+ values.push(cells.slice(depth));
573
+ depths.push(depth);
574
+ } else {
575
+ values.push(cells);
576
+ depths.push(0);
577
+ }
578
+ }
579
+ return { values, depths };
580
+ }
581
+ function resolvePasteColumnIds(rows, startCol, width) {
582
+ if (width <= 0) return [];
583
+ const cells = rows[0]?.getVisibleCells() ?? [];
584
+ const columnIds = [];
585
+ for (let offset = 0; offset < width; offset += 1) {
586
+ const cell = cells[startCol + offset];
587
+ if (!cell) break;
588
+ columnIds.push(cell.column.id);
589
+ }
590
+ return columnIds;
591
+ }
592
+ function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
593
+ const { values, depths } = parseClipboardTSVWithDepths(text);
594
+ if (values.length === 0) return null;
595
+ const width = Math.max(...values.map((row) => row.length), 0);
596
+ if (width === 0) return null;
597
+ const columnIds = resolvePasteColumnIds(rows, startCol, width);
598
+ if (columnIds.length === 0) return null;
599
+ const rowIds = [];
600
+ for (let offset = 0; offset < values.length; offset += 1) {
601
+ const row = rows[startRow + offset];
602
+ if (!row) break;
603
+ rowIds.push(row.id);
604
+ }
605
+ const anchorRow = rows[endRow] ?? rows[startRow];
606
+ return {
607
+ mode,
608
+ startRow,
609
+ startCol,
610
+ endRow,
611
+ rowIds,
612
+ anchorRowId: anchorRow?.id ?? "",
613
+ columnIds,
614
+ values,
615
+ depths
616
+ };
617
+ }
618
+ function isEditablePasteTarget(target) {
619
+ if (!(target instanceof HTMLElement)) return false;
620
+ const tag = target.tagName;
621
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
622
+ return Boolean(target.isContentEditable);
623
+ }
624
+
540
625
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
541
- var import_react2 = require("react");
626
+ var import_react3 = require("react");
542
627
 
543
628
  // src/components/ui/table/features/cell-selection/cellSelection.ts
544
629
  var INITIAL_DRAG_STATE = {
@@ -846,6 +931,219 @@ function hasCellSelectionEdges(style) {
846
931
  }
847
932
 
848
933
  // src/components/ui/table/features/cell-selection/copyData.ts
934
+ var import_react2 = require("react");
935
+ function isReactNodeIterable(node) {
936
+ return typeof node === "object" && node !== null && !(0, import_react2.isValidElement)(node) && Symbol.iterator in node;
937
+ }
938
+ function getElementTypeName(type) {
939
+ if (typeof type === "string") return type;
940
+ if (typeof type === "function") {
941
+ const fn = type;
942
+ return fn.displayName || fn.name || "";
943
+ }
944
+ if (typeof type === "object" && type !== null) {
945
+ const component = type;
946
+ return component.displayName || component.render?.displayName || component.render?.name || "";
947
+ }
948
+ return "";
949
+ }
950
+ function isButtonReactElement(node) {
951
+ const typeName = getElementTypeName(node.type);
952
+ if (typeName === "button" || /button/i.test(typeName)) return true;
953
+ const props = node.props;
954
+ if (props.role === "button") return true;
955
+ if (typeName === "input" && props.type === "button") return true;
956
+ return false;
957
+ }
958
+ function isImageReactElement(node) {
959
+ const typeName = getElementTypeName(node.type);
960
+ return typeName === "img" || typeName === "image" || /image/i.test(typeName);
961
+ }
962
+ var IMAGE_URL_PROP_KEYS = ["src", "url", "href", "imageUrl", "srcUrl"];
963
+ function isLikelyUrl(value) {
964
+ const trimmed = value.trim();
965
+ if (!trimmed) return false;
966
+ if (/^(https?:|blob:|data:|\/\/)/i.test(trimmed)) return true;
967
+ if (trimmed.startsWith("/") && trimmed.includes("/")) return true;
968
+ return false;
969
+ }
970
+ function pickUrlFromUnknown(value) {
971
+ if (typeof value === "string") {
972
+ return isLikelyUrl(value) ? value.trim() : "";
973
+ }
974
+ if (Array.isArray(value)) {
975
+ return value.map((item) => pickUrlFromUnknown(item)).filter((item) => item.length > 0).join(", ");
976
+ }
977
+ if (value && typeof value === "object") {
978
+ const record = value;
979
+ for (const key of IMAGE_URL_PROP_KEYS) {
980
+ const candidate = record[key];
981
+ if (typeof candidate === "string" && candidate.trim()) {
982
+ return candidate.trim();
983
+ }
984
+ }
985
+ }
986
+ return "";
987
+ }
988
+ function imageElementText(node) {
989
+ const props = node.props;
990
+ for (const key of IMAGE_URL_PROP_KEYS) {
991
+ const candidate = props[key];
992
+ if (typeof candidate === "string" && candidate.trim()) {
993
+ return candidate.trim();
994
+ }
995
+ }
996
+ return "";
997
+ }
998
+ function reactNodeContainsImage(node) {
999
+ if ((0, import_react2.isValidElement)(node)) {
1000
+ if (isImageReactElement(node)) return true;
1001
+ return reactNodeContainsImage(node.props.children);
1002
+ }
1003
+ if (isReactNodeIterable(node)) {
1004
+ for (const child of node) {
1005
+ if (reactNodeContainsImage(child)) return true;
1006
+ }
1007
+ }
1008
+ return false;
1009
+ }
1010
+ function readImgUrl(img) {
1011
+ const attr = img.getAttribute("src")?.trim() ?? "";
1012
+ if (attr) return attr;
1013
+ if (img instanceof HTMLImageElement) {
1014
+ const current = img.currentSrc?.trim() ?? "";
1015
+ if (current && current !== img.baseURI) return current;
1016
+ }
1017
+ return "";
1018
+ }
1019
+ function readDomImageUrls(rowIndex, colIndex, root) {
1020
+ const scope = root ?? (typeof document === "undefined" ? null : document);
1021
+ if (!scope) return "";
1022
+ const cells = scope.querySelectorAll(
1023
+ `[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
1024
+ );
1025
+ for (const cell of cells) {
1026
+ const urls = Array.from(cell.querySelectorAll("img")).flatMap((img) => {
1027
+ const url = readImgUrl(img);
1028
+ return url ? [url] : [];
1029
+ });
1030
+ if (urls.length > 0) return urls.join(", ");
1031
+ }
1032
+ return "";
1033
+ }
1034
+ function reactNodeToText(node) {
1035
+ if (node == null || typeof node === "boolean") return "";
1036
+ if (typeof node === "string" || typeof node === "number" || typeof node === "bigint") {
1037
+ return String(node);
1038
+ }
1039
+ if (isReactNodeIterable(node)) {
1040
+ let text = "";
1041
+ for (const child of node) {
1042
+ text += reactNodeToText(child);
1043
+ }
1044
+ return text;
1045
+ }
1046
+ if ((0, import_react2.isValidElement)(node)) {
1047
+ if (isButtonReactElement(node)) return "";
1048
+ const props = node.props;
1049
+ const childText = reactNodeToText(props.children);
1050
+ if (childText) return childText;
1051
+ const fromImage = imageElementText(node);
1052
+ if (fromImage) return fromImage;
1053
+ if (isImageReactElement(node)) return "";
1054
+ if (typeof props.alt === "string" && props.alt) return props.alt;
1055
+ if (typeof props.title === "string" && props.title) return props.title;
1056
+ return "";
1057
+ }
1058
+ return "";
1059
+ }
1060
+ function sanitizeClipboardCell(text) {
1061
+ return text.replace(/\s+/g, " ").trim();
1062
+ }
1063
+ function createCopyRenderRow(rowData, index) {
1064
+ return {
1065
+ id: getOriginalRowId(rowData) || String(index),
1066
+ index,
1067
+ original: rowData,
1068
+ getIsCellDragSelected: () => false
1069
+ };
1070
+ }
1071
+ function buildVisibleRowLookup(visibleRows) {
1072
+ const lookup = /* @__PURE__ */ new Map();
1073
+ for (const row of visibleRows) {
1074
+ lookup.set(row.original, row);
1075
+ }
1076
+ return lookup;
1077
+ }
1078
+ function resolveCopyColumnId(cell) {
1079
+ if (cell.column.id) return cell.column.id;
1080
+ const columnDef = cell.column.columnDef;
1081
+ if (columnDef.id) return columnDef.id;
1082
+ if (columnDef.accessorKey != null && columnDef.accessorKey !== "") {
1083
+ return String(columnDef.accessorKey);
1084
+ }
1085
+ return "";
1086
+ }
1087
+ function isPrimitiveCopyValue(value) {
1088
+ return value == null || typeof value !== "object";
1089
+ }
1090
+ function extractRenderedCopyText(node, value, cellPosition, root) {
1091
+ const rendered = sanitizeClipboardCell(reactNodeToText(node));
1092
+ if (reactNodeContainsImage(node)) {
1093
+ const fromDom = cellPosition != null ? sanitizeClipboardCell(
1094
+ readDomImageUrls(cellPosition.rowIndex, cellPosition.colIndex, root)
1095
+ ) : "";
1096
+ if (fromDom) return fromDom;
1097
+ if (rendered && isLikelyUrl(rendered)) return rendered;
1098
+ return sanitizeClipboardCell(pickUrlFromUnknown(value));
1099
+ }
1100
+ return rendered;
1101
+ }
1102
+ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
1103
+ const meta = columnDef.meta;
1104
+ const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
1105
+ const cellRender = meta?.cellRender;
1106
+ if (typeof cellRender === "function") {
1107
+ try {
1108
+ const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1109
+ const node = cellRender({
1110
+ value,
1111
+ row,
1112
+ index: row.index,
1113
+ columnId,
1114
+ cellProps: meta?.cellProps,
1115
+ update: () => {
1116
+ }
1117
+ });
1118
+ return extractRenderedCopyText(node, value, cellPosition, options?.root);
1119
+ } catch {
1120
+ return formatCellValue(value);
1121
+ }
1122
+ }
1123
+ if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
1124
+ try {
1125
+ const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1126
+ const ctx = {
1127
+ value,
1128
+ row,
1129
+ index: row.index,
1130
+ columnId,
1131
+ cellProps: meta.cellProps,
1132
+ update: () => {
1133
+ }
1134
+ };
1135
+ const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
1136
+ if (renderer) {
1137
+ const node = renderer.render(ctx);
1138
+ const rendered = extractRenderedCopyText(node, value, cellPosition, options.root);
1139
+ if (rendered) return rendered;
1140
+ }
1141
+ } catch {
1142
+ return formatCellValue(value);
1143
+ }
1144
+ }
1145
+ return formatCellValue(value);
1146
+ }
849
1147
  function formatPrimitive(value) {
850
1148
  if (value === null || value === void 0) return "";
851
1149
  if (typeof value === "string") return value;
@@ -951,37 +1249,47 @@ function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
951
1249
  function collectCopyRows(visibleRows, bounds, mode = "visible") {
952
1250
  return collectCopyRowEntries(visibleRows, bounds, mode).map((entry) => entry.row);
953
1251
  }
954
- function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths) {
1252
+ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options) {
955
1253
  if (copyRows.length === 0) return "";
956
1254
  const { startCol, endCol } = bounds;
957
1255
  const columnCells = visibleRows[0]?.getVisibleCells().slice(startCol, endCol + 1) ?? [];
958
1256
  if (columnCells.length === 0) return "";
959
1257
  const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
960
1258
  const minDepth = Math.min(...resolvedDepths);
1259
+ const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
961
1260
  return copyRows.map((rowData, index) => {
962
1261
  const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
963
- const line = columnCells.map(
964
- (cell) => formatCellValue(
965
- readRowColumnValue(
966
- rowData,
967
- cell.column.columnDef
968
- )
969
- )
970
- ).join(" ");
1262
+ const visibleRow = visibleRowByOriginal.get(rowData);
1263
+ const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
1264
+ const line = columnCells.map((templateCell, colOffset) => {
1265
+ const sourceCell = matchingCells?.[colOffset];
1266
+ const column = sourceCell?.column ?? templateCell.column;
1267
+ return formatCopyCellText(
1268
+ rowData,
1269
+ column.columnDef,
1270
+ resolveCopyColumnId(sourceCell ?? templateCell),
1271
+ visibleRow,
1272
+ visibleRow?.index ?? index,
1273
+ sourceCell,
1274
+ visibleRow != null ? { rowIndex: visibleRow.index, colIndex: startCol + colOffset } : void 0,
1275
+ options
1276
+ );
1277
+ }).join(" ");
971
1278
  return `${" ".repeat(relativeDepth)}${line}`;
972
1279
  }).join("\n");
973
1280
  }
974
- function serializeSelectionToTSV(visibleRows, bounds, mode = "visible") {
1281
+ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options) {
975
1282
  const entries = collectCopyRowEntries(visibleRows, bounds, mode);
976
1283
  return serializeCopyRowsToTSV(
977
1284
  entries.map((entry) => entry.row),
978
1285
  visibleRows,
979
1286
  bounds,
980
- entries.map((entry) => entry.depth)
1287
+ entries.map((entry) => entry.depth),
1288
+ options
981
1289
  );
982
1290
  }
983
- async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible") {
984
- const text = serializeSelectionToTSV(visibleRows, bounds, mode);
1291
+ async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
1292
+ const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
985
1293
  if (!text) return false;
986
1294
  try {
987
1295
  await navigator.clipboard.writeText(text);
@@ -1047,90 +1355,6 @@ function hasFillExtension(sourceBounds, fillBounds) {
1047
1355
  return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
1048
1356
  }
1049
1357
 
1050
- // src/components/ui/table/features/cell-selection/pasteData.ts
1051
- function countLeadingEmptyCells(cells) {
1052
- let depth = 0;
1053
- while (depth < cells.length && cells[depth] === "") {
1054
- depth += 1;
1055
- }
1056
- return depth;
1057
- }
1058
- function looksLikeSubtreeIndentation(leadingEmptyCounts) {
1059
- if (leadingEmptyCounts.length === 0) return false;
1060
- const firstDepth = leadingEmptyCounts[0] ?? 0;
1061
- if (firstDepth !== 0) return false;
1062
- return leadingEmptyCounts.some((depth) => depth > 0);
1063
- }
1064
- function parseClipboardTSV(text) {
1065
- return parseClipboardTSVWithDepths(text).values;
1066
- }
1067
- function parseClipboardTSVWithDepths(text) {
1068
- if (!text) return { values: [], depths: [] };
1069
- const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
1070
- const withoutTrailing = normalized.replace(/\n+$/, "");
1071
- if (!withoutTrailing) return { values: [], depths: [] };
1072
- const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
1073
- const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
1074
- const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
1075
- const values = [];
1076
- const depths = [];
1077
- for (let index = 0; index < rows.length; index += 1) {
1078
- const cells = rows[index] ?? [];
1079
- const depth = leadingEmptyCounts[index] ?? 0;
1080
- if (treatAsDepth) {
1081
- values.push(cells.slice(depth));
1082
- depths.push(depth);
1083
- } else {
1084
- values.push(cells);
1085
- depths.push(0);
1086
- }
1087
- }
1088
- return { values, depths };
1089
- }
1090
- function resolvePasteColumnIds(rows, startCol, width) {
1091
- if (width <= 0) return [];
1092
- const cells = rows[0]?.getVisibleCells() ?? [];
1093
- const columnIds = [];
1094
- for (let offset = 0; offset < width; offset += 1) {
1095
- const cell = cells[startCol + offset];
1096
- if (!cell) break;
1097
- columnIds.push(cell.column.id);
1098
- }
1099
- return columnIds;
1100
- }
1101
- function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
1102
- const { values, depths } = parseClipboardTSVWithDepths(text);
1103
- if (values.length === 0) return null;
1104
- const width = Math.max(...values.map((row) => row.length), 0);
1105
- if (width === 0) return null;
1106
- const columnIds = resolvePasteColumnIds(rows, startCol, width);
1107
- if (columnIds.length === 0) return null;
1108
- const rowIds = [];
1109
- for (let offset = 0; offset < values.length; offset += 1) {
1110
- const row = rows[startRow + offset];
1111
- if (!row) break;
1112
- rowIds.push(row.id);
1113
- }
1114
- const anchorRow = rows[endRow] ?? rows[startRow];
1115
- return {
1116
- mode,
1117
- startRow,
1118
- startCol,
1119
- endRow,
1120
- rowIds,
1121
- anchorRowId: anchorRow?.id ?? "",
1122
- columnIds,
1123
- values,
1124
- depths
1125
- };
1126
- }
1127
- function isEditablePasteTarget(target) {
1128
- if (!(target instanceof HTMLElement)) return false;
1129
- const tag = target.tagName;
1130
- if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
1131
- return Boolean(target.isContentEditable);
1132
- }
1133
-
1134
1358
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
1135
1359
  function useCellSelection({
1136
1360
  data,
@@ -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, import_react2.useState)(INITIAL_DRAG_STATE);
1148
- const pendingPasteModeRef = (0, import_react2.useRef)(null);
1149
- const dragStateRef = (0, import_react2.useRef)(dragState);
1150
- const onCellNavigateRef = (0, import_react2.useRef)(onCellNavigate);
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, import_react2.useCallback)(
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, import_react2.useCallback)(
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, import_react2.useCallback)(
1422
+ const handleFillHandleMouseDown = (0, import_react3.useCallback)(
1197
1423
  (rowIndex, colIndex) => {
1198
1424
  if (!enabled) return;
1199
1425
  setDragState((prev) => {
@@ -1210,12 +1436,20 @@ function useCellSelection({
1210
1436
  },
1211
1437
  [enabled]
1212
1438
  );
1213
- (0, import_react2.useEffect)(() => {
1439
+ const clearSelection = (0, import_react3.useCallback)(() => {
1440
+ const prev = dragStateRef.current;
1441
+ if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
1442
+ return;
1443
+ }
1444
+ dragStateRef.current = INITIAL_DRAG_STATE;
1445
+ setDragState(INITIAL_DRAG_STATE);
1446
+ }, []);
1447
+ (0, import_react3.useEffect)(() => {
1214
1448
  if (!enabled) {
1215
- setDragState(INITIAL_DRAG_STATE);
1449
+ clearSelection();
1216
1450
  }
1217
- }, [enabled]);
1218
- (0, import_react2.useEffect)(() => {
1451
+ }, [clearSelection, enabled]);
1452
+ (0, import_react3.useEffect)(() => {
1219
1453
  if (!enabled) return;
1220
1454
  const handleKeyDown = (e) => {
1221
1455
  if (e.ctrlKey || e.metaKey || e.altKey) return;
@@ -1262,19 +1496,32 @@ function useCellSelection({
1262
1496
  window.addEventListener("keydown", handleKeyDown);
1263
1497
  return () => window.removeEventListener("keydown", handleKeyDown);
1264
1498
  }, [columnCount, enabled, rows]);
1265
- const copySelection = (0, import_react2.useCallback)(
1499
+ const copySelection = (0, import_react3.useCallback)(
1266
1500
  async (options) => {
1267
1501
  if (!enabled || !activeSelectionBounds) return false;
1268
1502
  const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
1269
- return writeSelectionToClipboard(rows, activeSelectionBounds, mode);
1503
+ return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
1504
+ registry: cellRendererRegistry,
1505
+ root: rootRef?.current
1506
+ });
1270
1507
  },
1271
- [activeSelectionBounds, enableSubtreeCopy, enabled, rows]
1508
+ [
1509
+ activeSelectionBounds,
1510
+ cellRendererRegistry,
1511
+ enableSubtreeCopy,
1512
+ enabled,
1513
+ rootRef,
1514
+ rows
1515
+ ]
1272
1516
  );
1273
- (0, import_react2.useEffect)(() => {
1517
+ (0, import_react3.useEffect)(() => {
1274
1518
  if (!enabled) return;
1275
1519
  const handleKeyDown = (e) => {
1276
1520
  if (!activeSelectionBounds) return;
1277
1521
  if (!(e.ctrlKey || e.metaKey)) return;
1522
+ if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1523
+ return;
1524
+ }
1278
1525
  const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
1279
1526
  const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
1280
1527
  if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
@@ -1284,7 +1531,7 @@ function useCellSelection({
1284
1531
  window.addEventListener("keydown", handleKeyDown);
1285
1532
  return () => window.removeEventListener("keydown", handleKeyDown);
1286
1533
  }, [activeSelectionBounds, copySelection, enableSubtreeCopy, enabled]);
1287
- const emitRowsPaste = (0, import_react2.useCallback)(
1534
+ const emitRowsPaste = (0, import_react3.useCallback)(
1288
1535
  (text, mode) => {
1289
1536
  if (!onRowsPaste || !activeSelectionBounds) return false;
1290
1537
  const payload = buildRowsPastePayload(
@@ -1301,7 +1548,7 @@ function useCellSelection({
1301
1548
  },
1302
1549
  [activeSelectionBounds, onRowsPaste, rows]
1303
1550
  );
1304
- (0, import_react2.useEffect)(() => {
1551
+ (0, import_react3.useEffect)(() => {
1305
1552
  if (!enabled || !onRowsPaste) return;
1306
1553
  const pasteHandledRef = { current: false };
1307
1554
  const ignoreNextPasteRef = { current: false };
@@ -1369,7 +1616,7 @@ function useCellSelection({
1369
1616
  enabled,
1370
1617
  onRowsPaste
1371
1618
  ]);
1372
- (0, import_react2.useEffect)(() => {
1619
+ (0, import_react3.useEffect)(() => {
1373
1620
  if (!enabled) return;
1374
1621
  const handleMouseUp = () => {
1375
1622
  setDragState((prev) => {
@@ -1415,6 +1662,7 @@ function useCellSelection({
1415
1662
  handleCellMouseDown,
1416
1663
  handleCellMouseEnter,
1417
1664
  handleFillHandleMouseDown,
1665
+ clearSelection,
1418
1666
  copySelection
1419
1667
  };
1420
1668
  }
@@ -1818,7 +2066,7 @@ function collectAncestorKeysToExpand(corpusRow, expandedRows) {
1818
2066
  }
1819
2067
 
1820
2068
  // src/components/ui/table/features/inline-search/useInlineSearch.ts
1821
- var import_react3 = require("react");
2069
+ var import_react4 = require("react");
1822
2070
  var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
1823
2071
  function useInlineSearch({
1824
2072
  enabled = false,
@@ -1835,46 +2083,46 @@ function useInlineSearch({
1835
2083
  onNavigateToResult,
1836
2084
  rootRef
1837
2085
  }) {
1838
- const searchInputId = (0, import_react3.useId)();
1839
- const searchInputRef = (0, import_react3.useRef)(null);
1840
- const [internalShowSearch, setInternalShowSearch] = (0, import_react3.useState)(false);
1841
- const [internalSearchValue, setInternalSearchValue] = (0, import_react3.useState)("");
1842
- const [internalResults, setInternalResults] = (0, import_react3.useState)(
2086
+ const searchInputId = (0, import_react4.useId)();
2087
+ const searchInputRef = (0, import_react4.useRef)(null);
2088
+ const [internalShowSearch, setInternalShowSearch] = (0, import_react4.useState)(false);
2089
+ const [internalSearchValue, setInternalSearchValue] = (0, import_react4.useState)("");
2090
+ const [internalResults, setInternalResults] = (0, import_react4.useState)(
1843
2091
  []
1844
2092
  );
1845
- const [searchStatus, setSearchStatus] = (0, import_react3.useState)();
1846
- const searchStatusRef = (0, import_react3.useRef)(searchStatus);
2093
+ const [searchStatus, setSearchStatus] = (0, import_react4.useState)();
2094
+ const searchStatusRef = (0, import_react4.useRef)(searchStatus);
1847
2095
  searchStatusRef.current = searchStatus;
1848
- const abortControllerRef = (0, import_react3.useRef)(null);
1849
- const searchHandleRef = (0, import_react3.useRef)(void 0);
1850
- const initialStartRowRef = (0, import_react3.useRef)(initialStartRow);
2096
+ const abortControllerRef = (0, import_react4.useRef)(null);
2097
+ const searchHandleRef = (0, import_react4.useRef)(void 0);
2098
+ const initialStartRowRef = (0, import_react4.useRef)(initialStartRow);
1851
2099
  initialStartRowRef.current = initialStartRow;
1852
- const getCellValueRef = (0, import_react3.useRef)(getCellValue);
2100
+ const getCellValueRef = (0, import_react4.useRef)(getCellValue);
1853
2101
  getCellValueRef.current = getCellValue;
1854
2102
  const showSearch = controlledShowSearch ?? internalShowSearch;
1855
2103
  const searchValue = controlledSearchValue ?? internalSearchValue;
1856
2104
  const searchResults = controlledSearchResults ?? internalResults;
1857
- const setSearchValue = (0, import_react3.useCallback)(
2105
+ const setSearchValue = (0, import_react4.useCallback)(
1858
2106
  (value) => {
1859
2107
  setInternalSearchValue(value);
1860
2108
  onSearchValueChange?.(value);
1861
2109
  },
1862
2110
  [onSearchValueChange]
1863
2111
  );
1864
- const cancelSearch = (0, import_react3.useCallback)(() => {
2112
+ const cancelSearch = (0, import_react4.useCallback)(() => {
1865
2113
  if (searchHandleRef.current !== void 0) {
1866
2114
  window.cancelAnimationFrame(searchHandleRef.current);
1867
2115
  searchHandleRef.current = void 0;
1868
2116
  }
1869
2117
  abortControllerRef.current?.abort();
1870
2118
  }, []);
1871
- const emitResultsChanged = (0, import_react3.useCallback)(
2119
+ const emitResultsChanged = (0, import_react4.useCallback)(
1872
2120
  (results, navIndex) => {
1873
2121
  onSearchResultsChanged?.(results, navIndex);
1874
2122
  },
1875
2123
  [onSearchResultsChanged]
1876
2124
  );
1877
- const navigateToIndex = (0, import_react3.useCallback)(
2125
+ const navigateToIndex = (0, import_react4.useCallback)(
1878
2126
  (results, navIndex) => {
1879
2127
  if (onSearchResultsChanged) return;
1880
2128
  if (navIndex < 0 || navIndex >= results.length) return;
@@ -1884,7 +2132,7 @@ function useInlineSearch({
1884
2132
  },
1885
2133
  [onNavigateToResult, onSearchResultsChanged]
1886
2134
  );
1887
- const beginSearch = (0, import_react3.useCallback)(
2135
+ const beginSearch = (0, import_react4.useCallback)(
1888
2136
  (query) => {
1889
2137
  if (controlledSearchResults !== void 0) return;
1890
2138
  const totalRows = rowCount;
@@ -1956,12 +2204,12 @@ function useInlineSearch({
1956
2204
  rowCount
1957
2205
  ]
1958
2206
  );
1959
- const openSearch = (0, import_react3.useCallback)(() => {
2207
+ const openSearch = (0, import_react4.useCallback)(() => {
1960
2208
  if (controlledShowSearch === void 0) {
1961
2209
  setInternalShowSearch(true);
1962
2210
  }
1963
2211
  }, [controlledShowSearch]);
1964
- const closeSearch = (0, import_react3.useCallback)(() => {
2212
+ const closeSearch = (0, import_react4.useCallback)(() => {
1965
2213
  if (controlledShowSearch === void 0) {
1966
2214
  setInternalShowSearch(false);
1967
2215
  }
@@ -1976,7 +2224,7 @@ function useInlineSearch({
1976
2224
  emitResultsChanged,
1977
2225
  onSearchClose
1978
2226
  ]);
1979
- const goToNext = (0, import_react3.useCallback)(() => {
2227
+ const goToNext = (0, import_react4.useCallback)(() => {
1980
2228
  if (!searchStatus || searchStatus.results === 0) return;
1981
2229
  const newIndex = nextSearchIndex(
1982
2230
  searchStatus.selectedIndex,
@@ -1986,7 +2234,7 @@ function useInlineSearch({
1986
2234
  emitResultsChanged(searchResults, newIndex);
1987
2235
  navigateToIndex(searchResults, newIndex);
1988
2236
  }, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
1989
- const goToPrevious = (0, import_react3.useCallback)(() => {
2237
+ const goToPrevious = (0, import_react4.useCallback)(() => {
1990
2238
  if (!searchStatus || searchStatus.results === 0) return;
1991
2239
  const newIndex = previousSearchIndex(
1992
2240
  searchStatus.selectedIndex,
@@ -1996,7 +2244,7 @@ function useInlineSearch({
1996
2244
  emitResultsChanged(searchResults, newIndex);
1997
2245
  navigateToIndex(searchResults, newIndex);
1998
2246
  }, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
1999
- (0, import_react3.useEffect)(() => {
2247
+ (0, import_react4.useEffect)(() => {
2000
2248
  if (controlledSearchResults === void 0) return;
2001
2249
  if (controlledSearchResults.length > 0) {
2002
2250
  setSearchStatus((current) => ({
@@ -2008,7 +2256,7 @@ function useInlineSearch({
2008
2256
  setSearchStatus(void 0);
2009
2257
  }
2010
2258
  }, [controlledSearchResults, rowCount]);
2011
- (0, import_react3.useEffect)(() => {
2259
+ (0, import_react4.useEffect)(() => {
2012
2260
  if (!enabled) return;
2013
2261
  setSearchStatus(void 0);
2014
2262
  setInternalResults([]);
@@ -2021,7 +2269,7 @@ function useInlineSearch({
2021
2269
  cancelSearch();
2022
2270
  }
2023
2271
  }, [enabled, showSearch]);
2024
- (0, import_react3.useEffect)(() => {
2272
+ (0, import_react4.useEffect)(() => {
2025
2273
  if (!enabled || !showSearch) return;
2026
2274
  if (controlledSearchResults !== void 0) return;
2027
2275
  if (searchValue.trim() === "") {
@@ -2041,7 +2289,7 @@ function useInlineSearch({
2041
2289
  searchValue,
2042
2290
  showSearch
2043
2291
  ]);
2044
- (0, import_react3.useEffect)(() => {
2292
+ (0, import_react4.useEffect)(() => {
2045
2293
  if (!enabled) return;
2046
2294
  const handleKeyDown = (event) => {
2047
2295
  if (!(event.ctrlKey || event.metaKey)) return;
@@ -2068,12 +2316,12 @@ function useInlineSearch({
2068
2316
  window.addEventListener("keydown", handleKeyDown, true);
2069
2317
  return () => window.removeEventListener("keydown", handleKeyDown, true);
2070
2318
  }, [controlledShowSearch, enabled, rootRef, showSearch]);
2071
- (0, import_react3.useEffect)(() => () => cancelSearch(), [cancelSearch]);
2072
- const searchMatchKeys = (0, import_react3.useMemo)(
2319
+ (0, import_react4.useEffect)(() => () => cancelSearch(), [cancelSearch]);
2320
+ const searchMatchKeys = (0, import_react4.useMemo)(
2073
2321
  () => buildSearchMatchKeys(searchResults),
2074
2322
  [searchResults]
2075
2323
  );
2076
- const activeMatch = (0, import_react3.useMemo)(() => {
2324
+ const activeMatch = (0, import_react4.useMemo)(() => {
2077
2325
  if (!searchStatus || searchStatus.selectedIndex < 0) return null;
2078
2326
  return searchResults[searchStatus.selectedIndex] ?? null;
2079
2327
  }, [searchResults, searchStatus]);
@@ -2116,7 +2364,7 @@ function useInlineSearch({
2116
2364
  }
2117
2365
 
2118
2366
  // src/components/ui/table/features/row-expand/row-expand.ts
2119
- var import_react4 = require("react");
2367
+ var import_react5 = require("react");
2120
2368
  function getFieldValue(row, key) {
2121
2369
  return row[key];
2122
2370
  }
@@ -2146,12 +2394,12 @@ var useConvertTreeData = ({
2146
2394
  expandedRows,
2147
2395
  onExpandedRowsChange
2148
2396
  }) => {
2149
- const onExpandedRowsChangeRef = (0, import_react4.useRef)(onExpandedRowsChange);
2150
- const hasInitializedRef = (0, import_react4.useRef)(false);
2151
- (0, import_react4.useEffect)(() => {
2397
+ const onExpandedRowsChangeRef = (0, import_react5.useRef)(onExpandedRowsChange);
2398
+ const hasInitializedRef = (0, import_react5.useRef)(false);
2399
+ (0, import_react5.useEffect)(() => {
2152
2400
  onExpandedRowsChangeRef.current = onExpandedRowsChange;
2153
2401
  }, [onExpandedRowsChange]);
2154
- (0, import_react4.useEffect)(() => {
2402
+ (0, import_react5.useEffect)(() => {
2155
2403
  if (!data || data.length === 0) {
2156
2404
  hasInitializedRef.current = false;
2157
2405
  return;
@@ -2161,7 +2409,7 @@ var useConvertTreeData = ({
2161
2409
  onExpandedRowsChangeRef.current?.(new Set(ids));
2162
2410
  hasInitializedRef.current = true;
2163
2411
  }, [enabled, data, toggleField]);
2164
- const processedData = (0, import_react4.useMemo)(() => {
2412
+ const processedData = (0, import_react5.useMemo)(() => {
2165
2413
  if (!enabled || !data || data.length === 0) return [];
2166
2414
  const flattenedData = [];
2167
2415
  const flattenItems = (items) => {
@@ -2225,7 +2473,7 @@ var useConvertTreeData = ({
2225
2473
  });
2226
2474
  return rootItems;
2227
2475
  }, [enabled, data, toggleField, childField, flattenField]);
2228
- const flattenTree = (0, import_react4.useMemo)(() => {
2476
+ const flattenTree = (0, import_react5.useMemo)(() => {
2229
2477
  if (!enabled) return [];
2230
2478
  const flatten = (nodes, result = [], level = 0) => {
2231
2479
  nodes.forEach((node, index) => {
@@ -2275,7 +2523,7 @@ var useConvertTreeData = ({
2275
2523
  preventExpand,
2276
2524
  expandedRows
2277
2525
  ]);
2278
- const sortedData = (0, import_react4.useMemo)(() => {
2526
+ const sortedData = (0, import_react5.useMemo)(() => {
2279
2527
  if (!enabled) {
2280
2528
  return data ?? [];
2281
2529
  }
@@ -2502,7 +2750,7 @@ function useGlideTable(options) {
2502
2750
  searchResults,
2503
2751
  onSearchResultsChanged
2504
2752
  } = options;
2505
- const labels = (0, import_react5.useMemo)(() => {
2753
+ const labels = (0, import_react6.useMemo)(() => {
2506
2754
  const resolved = resolveDataTableLabels(labelsProp);
2507
2755
  return {
2508
2756
  ...resolved,
@@ -2513,17 +2761,21 @@ function useGlideTable(options) {
2513
2761
  }, [labelsProp, emptyText, loadingText, selectionLabel]);
2514
2762
  const enableExpand = Boolean(toggleField);
2515
2763
  const resolvedEnableSubtreeCopy = enableSubtreeCopy ?? enableExpand;
2516
- const [internalRowSelection, setInternalRowSelection] = (0, import_react5.useState)({});
2517
- const [internalColumnSizing, setInternalColumnSizing] = (0, import_react5.useState)({});
2518
- const [internalColumnOrder, setInternalColumnOrder] = (0, import_react5.useState)([]);
2519
- const [internalExpandedRows, setInternalExpandedRows] = (0, import_react5.useState)(
2764
+ const [internalRowSelection, setInternalRowSelection] = (0, import_react6.useState)({});
2765
+ const [internalColumnSizing, setInternalColumnSizing] = (0, import_react6.useState)({});
2766
+ const [internalColumnOrder, setInternalColumnOrder] = (0, import_react6.useState)([]);
2767
+ const [internalExpandedRows, setInternalExpandedRows] = (0, import_react6.useState)(
2520
2768
  () => /* @__PURE__ */ new Set()
2521
2769
  );
2522
- const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react5.useState)(null);
2523
- const scrollRef = (0, import_react5.useRef)(null);
2524
- const rootRef = (0, import_react5.useRef)(null);
2770
+ const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
2771
+ const scrollRef = (0, import_react6.useRef)(null);
2772
+ const rootRef = (0, import_react6.useRef)(null);
2773
+ const cellRendererRegistry = (0, import_react6.useMemo)(
2774
+ () => createCellRendererRegistry(cellRenderers),
2775
+ [cellRenderers]
2776
+ );
2525
2777
  const shouldVirtualize = enableVirtualization && !enableRowSpan;
2526
- (0, import_react5.useEffect)(() => {
2778
+ (0, import_react6.useEffect)(() => {
2527
2779
  if (enableVirtualization && enableRowSpan) {
2528
2780
  console.warn(
2529
2781
  "[useGlideTable] enableRowSpan is on; virtualization is disabled to preserve cell merges."
@@ -2537,11 +2789,11 @@ function useGlideTable(options) {
2537
2789
  );
2538
2790
  const columnSizing = controlledColumnSizing ?? internalColumnSizing;
2539
2791
  const columnOrder = controlledColumnOrder ?? internalColumnOrder;
2540
- const tableColumns = (0, import_react5.useMemo)(() => {
2792
+ const tableColumns = (0, import_react6.useMemo)(() => {
2541
2793
  if (!enableColumnReorder) return columns;
2542
2794
  return applyLeafColumnOrder(columns, columnOrder);
2543
2795
  }, [columnOrder, columns, enableColumnReorder]);
2544
- const setColumnOrder = (0, import_react5.useCallback)(
2796
+ const setColumnOrder = (0, import_react6.useCallback)(
2545
2797
  (next) => {
2546
2798
  if (onColumnOrderChange) {
2547
2799
  onColumnOrderChange(next);
@@ -2552,7 +2804,7 @@ function useGlideTable(options) {
2552
2804
  [onColumnOrderChange]
2553
2805
  );
2554
2806
  const expandedRows = controlledExpandedRows ?? internalExpandedRows;
2555
- const handleExpandedRowsChange = (0, import_react5.useCallback)(
2807
+ const handleExpandedRowsChange = (0, import_react6.useCallback)(
2556
2808
  (next) => {
2557
2809
  if (onExpandedRowsChange) {
2558
2810
  onExpandedRowsChange(next);
@@ -2613,13 +2865,13 @@ function useGlideTable(options) {
2613
2865
  getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
2614
2866
  getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (_originalRow, index) => String(index)
2615
2867
  });
2616
- const rowSpanColumnKeys = (0, import_react5.useMemo)(() => {
2868
+ const rowSpanColumnKeys = (0, import_react6.useMemo)(() => {
2617
2869
  if (!enableRowSpan) return [];
2618
2870
  return collectRowSpanColumns(columns);
2619
2871
  }, [enableRowSpan, columns]);
2620
2872
  const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
2621
2873
  const primaryRowSpanColumnId = rowSpanColumnKeys[0]?.columnId;
2622
- const columnRowSpanMap = (0, import_react5.useMemo)(
2874
+ const columnRowSpanMap = (0, import_react6.useMemo)(
2623
2875
  () => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
2624
2876
  [tableData, rowSpanColumnKeys]
2625
2877
  );
@@ -2628,7 +2880,7 @@ function useGlideTable(options) {
2628
2880
  const rows = table.getRowModel().rows;
2629
2881
  const columnCount = table.getAllLeafColumns().length || 1;
2630
2882
  const visibleLeafColumns = table.getVisibleLeafColumns();
2631
- const columnFreezeOffsets = (0, import_react5.useMemo)(() => {
2883
+ const columnFreezeOffsets = (0, import_react6.useMemo)(() => {
2632
2884
  if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
2633
2885
  return buildColumnFreezeOffsets(
2634
2886
  visibleLeafColumns.map((column) => ({
@@ -2648,14 +2900,14 @@ function useGlideTable(options) {
2648
2900
  const totalSize = rowVirtualizer.getTotalSize();
2649
2901
  const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
2650
2902
  const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
2651
- const selectedRowIndices = (0, import_react5.useMemo)(() => {
2903
+ const selectedRowIndices = (0, import_react6.useMemo)(() => {
2652
2904
  const indices = /* @__PURE__ */ new Set();
2653
2905
  for (const selectedRow of selectedRows) {
2654
2906
  indices.add(selectedRow.index);
2655
2907
  }
2656
2908
  return indices;
2657
2909
  }, [selectedRows]);
2658
- const scrollCellIntoView = (0, import_react5.useCallback)(
2910
+ const scrollCellIntoView = (0, import_react6.useCallback)(
2659
2911
  (rowIndex, colIndex, options2) => {
2660
2912
  const align = options2?.align ?? "nearest";
2661
2913
  const blockAlign = align === "center" ? "center" : "nearest";
@@ -2682,7 +2934,7 @@ function useGlideTable(options) {
2682
2934
  },
2683
2935
  [rowVirtualizer, shouldVirtualize]
2684
2936
  );
2685
- const handleCellNavigate = (0, import_react5.useCallback)(
2937
+ const handleCellNavigate = (0, import_react6.useCallback)(
2686
2938
  (position) => {
2687
2939
  scrollCellIntoView(position.row, position.col, { align: "nearest" });
2688
2940
  },
@@ -2694,6 +2946,7 @@ function useGlideTable(options) {
2694
2946
  handleCellMouseDown,
2695
2947
  handleCellMouseEnter,
2696
2948
  handleFillHandleMouseDown,
2949
+ clearSelection: clearCellSelection,
2697
2950
  copySelection
2698
2951
  } = useCellSelection({
2699
2952
  data: tableData,
@@ -2705,8 +2958,46 @@ function useGlideTable(options) {
2705
2958
  onDataChange,
2706
2959
  onBatchChange,
2707
2960
  onRowsPaste,
2708
- onCellNavigate: handleCellNavigate
2961
+ onCellNavigate: handleCellNavigate,
2962
+ cellRendererRegistry,
2963
+ rootRef
2709
2964
  });
2965
+ const clearRowSelection = (0, import_react6.useCallback)(() => {
2966
+ if (rowSelectionMode === "none") return;
2967
+ const hasSelection = Object.values(rowSelection).some(Boolean);
2968
+ if (!hasSelection) return;
2969
+ if (onRowSelectionChange) {
2970
+ onRowSelectionChange(() => ({}));
2971
+ return;
2972
+ }
2973
+ setInternalRowSelection({});
2974
+ }, [onRowSelectionChange, rowSelection, rowSelectionMode]);
2975
+ (0, import_react6.useEffect)(() => {
2976
+ const clearAllSelections = () => {
2977
+ clearCellSelection();
2978
+ clearRowSelection();
2979
+ };
2980
+ const handleKeyDown = (event) => {
2981
+ if (event.key !== "Escape") return;
2982
+ if (event.defaultPrevented) return;
2983
+ if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
2984
+ return;
2985
+ }
2986
+ clearAllSelections();
2987
+ };
2988
+ const handleMouseDown = (event) => {
2989
+ const root = rootRef.current;
2990
+ if (!root) return;
2991
+ if (event.target instanceof Node && root.contains(event.target)) return;
2992
+ clearAllSelections();
2993
+ };
2994
+ window.addEventListener("keydown", handleKeyDown);
2995
+ document.addEventListener("mousedown", handleMouseDown);
2996
+ return () => {
2997
+ window.removeEventListener("keydown", handleKeyDown);
2998
+ document.removeEventListener("mousedown", handleMouseDown);
2999
+ };
3000
+ }, [clearCellSelection, clearRowSelection]);
2710
3001
  const {
2711
3002
  editingCell,
2712
3003
  draftValue,
@@ -2715,11 +3006,7 @@ function useGlideTable(options) {
2715
3006
  commitEdit,
2716
3007
  cancelEdit
2717
3008
  } = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
2718
- const cellRendererRegistry = (0, import_react5.useMemo)(
2719
- () => createCellRendererRegistry(cellRenderers),
2720
- [cellRenderers]
2721
- );
2722
- const commitRenderedCellValue = (0, import_react5.useCallback)(
3009
+ const commitRenderedCellValue = (0, import_react6.useCallback)(
2723
3010
  (rowId, columnId, value) => commitCellValue({
2724
3011
  data: tableData,
2725
3012
  rows,
@@ -2731,11 +3018,11 @@ function useGlideTable(options) {
2731
3018
  }),
2732
3019
  [onCellChange, onDataChange, rows, tableData]
2733
3020
  );
2734
- const getCellContext = (0, import_react5.useCallback)(
3021
+ const getCellContext = (0, import_react6.useCallback)(
2735
3022
  (cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
2736
3023
  [commitRenderedCellValue]
2737
3024
  );
2738
- const handleCellMouseDownWithCommit = (0, import_react5.useCallback)(
3025
+ const handleCellMouseDownWithCommit = (0, import_react6.useCallback)(
2739
3026
  (rowIndex, colIndex, options2) => {
2740
3027
  const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
2741
3028
  if (editingCell && !isSameEditingCell && !commitEdit()) {
@@ -2745,7 +3032,7 @@ function useGlideTable(options) {
2745
3032
  },
2746
3033
  [commitEdit, editingCell, handleCellMouseDown]
2747
3034
  );
2748
- const navigateToSearchResult = (0, import_react5.useCallback)(
3035
+ const navigateToSearchResult = (0, import_react6.useCallback)(
2749
3036
  (item) => {
2750
3037
  const [colIndex, rowIndex] = item;
2751
3038
  handleCellMouseDownWithCommit(rowIndex, colIndex);
@@ -2753,7 +3040,7 @@ function useGlideTable(options) {
2753
3040
  },
2754
3041
  [handleCellMouseDownWithCommit, scrollCellIntoView]
2755
3042
  );
2756
- const resolveSearchRowId = (0, import_react5.useCallback)(
3043
+ const resolveSearchRowId = (0, import_react6.useCallback)(
2757
3044
  (row, index) => {
2758
3045
  if (getRowId) return getRowId(row, index);
2759
3046
  if (enableExpand) {
@@ -2777,7 +3064,7 @@ function useGlideTable(options) {
2777
3064
  },
2778
3065
  [enableExpand, getRowId, toggleField]
2779
3066
  );
2780
- const searchCorpus = (0, import_react5.useMemo)(() => {
3067
+ const searchCorpus = (0, import_react6.useMemo)(() => {
2781
3068
  if (!enableInlineSearch) return [];
2782
3069
  if (enableExpand && toggleField) {
2783
3070
  return buildTreeSearchCorpus(tableData, {
@@ -2793,16 +3080,16 @@ function useGlideTable(options) {
2793
3080
  tableData,
2794
3081
  toggleField
2795
3082
  ]);
2796
- const searchCorpusRef = (0, import_react5.useRef)(searchCorpus);
3083
+ const searchCorpusRef = (0, import_react6.useRef)(searchCorpus);
2797
3084
  searchCorpusRef.current = searchCorpus;
2798
- const visibleRowIndexById = (0, import_react5.useMemo)(() => {
3085
+ const visibleRowIndexById = (0, import_react6.useMemo)(() => {
2799
3086
  const map = /* @__PURE__ */ new Map();
2800
3087
  for (const row of rows) {
2801
3088
  map.set(resolveSearchRowId(row.original, row.index), row.index);
2802
3089
  }
2803
3090
  return map;
2804
3091
  }, [resolveSearchRowId, rows]);
2805
- const getSearchCellValue = (0, import_react5.useCallback)(
3092
+ const getSearchCellValue = (0, import_react6.useCallback)(
2806
3093
  (rowIndex, colIndex) => {
2807
3094
  const corpusRow = searchCorpusRef.current[rowIndex];
2808
3095
  const column = visibleLeafColumns[colIndex];
@@ -2825,14 +3112,14 @@ function useGlideTable(options) {
2825
3112
  },
2826
3113
  [rows, visibleLeafColumns, visibleRowIndexById]
2827
3114
  );
2828
- const pendingSearchNavRef = (0, import_react5.useRef)(null);
2829
- const focusSearchResult = (0, import_react5.useCallback)(
3115
+ const pendingSearchNavRef = (0, import_react6.useRef)(null);
3116
+ const focusSearchResult = (0, import_react6.useCallback)(
2830
3117
  (colIndex, visibleRowIndex) => {
2831
3118
  navigateToSearchResult([colIndex, visibleRowIndex]);
2832
3119
  },
2833
3120
  [navigateToSearchResult]
2834
3121
  );
2835
- const navigateToCorpusSearchResult = (0, import_react5.useCallback)(
3122
+ const navigateToCorpusSearchResult = (0, import_react6.useCallback)(
2836
3123
  (item) => {
2837
3124
  const [colIndex, corpusRowIndex] = item;
2838
3125
  const corpusRow = searchCorpusRef.current[corpusRowIndex];
@@ -2865,7 +3152,7 @@ function useGlideTable(options) {
2865
3152
  visibleRowIndexById
2866
3153
  ]
2867
3154
  );
2868
- (0, import_react5.useEffect)(() => {
3155
+ (0, import_react6.useEffect)(() => {
2869
3156
  const pending = pendingSearchNavRef.current;
2870
3157
  if (!pending) return;
2871
3158
  const visibleRowIndex = visibleRowIndexById.get(pending.rowId);
@@ -2889,7 +3176,7 @@ function useGlideTable(options) {
2889
3176
  onNavigateToResult: navigateToCorpusSearchResult,
2890
3177
  rootRef
2891
3178
  });
2892
- const visibleSearchMatchKeys = (0, import_react5.useMemo)(() => {
3179
+ const visibleSearchMatchKeys = (0, import_react6.useMemo)(() => {
2893
3180
  if (!enableInlineSearch) return EMPTY_SEARCH_MATCH_KEYS;
2894
3181
  return mapSearchResultsToVisibleKeys(
2895
3182
  inlineSearch.searchResults,
@@ -2902,7 +3189,7 @@ function useGlideTable(options) {
2902
3189
  searchCorpus,
2903
3190
  visibleRowIndexById
2904
3191
  ]);
2905
- const visibleActiveMatch = (0, import_react5.useMemo)(() => {
3192
+ const visibleActiveMatch = (0, import_react6.useMemo)(() => {
2906
3193
  if (!enableInlineSearch || !inlineSearch.activeMatch) return null;
2907
3194
  return mapSearchResultToVisibleItem(
2908
3195
  inlineSearch.activeMatch,
@@ -2915,13 +3202,13 @@ function useGlideTable(options) {
2915
3202
  searchCorpus,
2916
3203
  visibleRowIndexById
2917
3204
  ]);
2918
- const clearHover = (0, import_react5.useCallback)(() => {
3205
+ const clearHover = (0, import_react6.useCallback)(() => {
2919
3206
  setHoveredRowIndex(null);
2920
3207
  }, []);
2921
- const handleRowHover = (0, import_react5.useCallback)((rowIndex, _rowData) => {
3208
+ const handleRowHover = (0, import_react6.useCallback)((rowIndex, _rowData) => {
2922
3209
  setHoveredRowIndex(rowIndex);
2923
3210
  }, []);
2924
- const handleToggleSelect = (0, import_react5.useCallback)(
3211
+ const handleToggleSelect = (0, import_react6.useCallback)(
2925
3212
  (row) => {
2926
3213
  if (!row.getCanSelect()) return;
2927
3214
  if (preserveRowSelection && row.getIsSelected()) {
@@ -2931,14 +3218,14 @@ function useGlideTable(options) {
2931
3218
  },
2932
3219
  [preserveRowSelection]
2933
3220
  );
2934
- const handleToggleExpand = (0, import_react5.useCallback)(
3221
+ const handleToggleExpand = (0, import_react6.useCallback)(
2935
3222
  (rowKey) => {
2936
3223
  if (preventExpand) return;
2937
3224
  handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
2938
3225
  },
2939
3226
  [preventExpand, handleExpandedRowsChange, expandedRows]
2940
3227
  );
2941
- const rowContextValue = (0, import_react5.useMemo)(() => {
3228
+ const rowContextValue = (0, import_react6.useMemo)(() => {
2942
3229
  return {
2943
3230
  rowSpan: {
2944
3231
  enableRowSpan,
@@ -3037,12 +3324,12 @@ function useGlideTable(options) {
3037
3324
  visibleSearchMatchKeys,
3038
3325
  visibleActiveMatch
3039
3326
  ]);
3040
- const copySelectionRef = (0, import_react5.useRef)(copySelection);
3041
- (0, import_react5.useEffect)(() => {
3327
+ const copySelectionRef = (0, import_react6.useRef)(copySelection);
3328
+ (0, import_react6.useEffect)(() => {
3042
3329
  copySelectionRef.current = copySelection;
3043
3330
  }, [copySelection]);
3044
- const stableCopySelection = (0, import_react5.useCallback)((options2) => copySelectionRef.current(options2), []);
3045
- (0, import_react5.useEffect)(() => {
3331
+ const stableCopySelection = (0, import_react6.useCallback)((options2) => copySelectionRef.current(options2), []);
3332
+ (0, import_react6.useEffect)(() => {
3046
3333
  onCopyActionsReady?.({ copySelection: stableCopySelection });
3047
3334
  }, [onCopyActionsReady, stableCopySelection]);
3048
3335
  return {
@@ -3091,16 +3378,18 @@ function useGlideTable(options) {
3091
3378
  }
3092
3379
 
3093
3380
  // src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
3094
- var import_react7 = require("react");
3381
+ var import_react8 = require("react");
3095
3382
 
3096
3383
  // src/components/ui/table/DataTableContext.tsx
3097
- var import_react6 = require("react");
3384
+ var import_react7 = require("react");
3098
3385
  var import_jsx_runtime2 = require("react/jsx-runtime");
3099
- var DataTableContext = (0, import_react6.createContext)(null);
3386
+ var DataTableContext = (0, import_react7.createContext)(null);
3100
3387
  function useDataTableRowContext() {
3101
- const context = (0, import_react6.use)(DataTableContext);
3388
+ const context = (0, import_react7.use)(DataTableContext);
3102
3389
  if (!context) {
3103
- throw new Error("useDataTableRowContext must be used within a DataTableContextProvider");
3390
+ throw new Error(
3391
+ "useDataTableRowContext must be used within a DataTableContextProvider"
3392
+ );
3104
3393
  }
3105
3394
  return context;
3106
3395
  }
@@ -3120,7 +3409,7 @@ function ResolvedTableCell({
3120
3409
  const meta = column.columnDef.meta;
3121
3410
  const value = getValue();
3122
3411
  const columnId = column.id;
3123
- const update = (0, import_react7.useCallback)(
3412
+ const update = (0, import_react8.useCallback)(
3124
3413
  (next) => {
3125
3414
  cellRender.commitValue(row.id, columnId, next);
3126
3415
  },
@@ -3145,8 +3434,105 @@ function ResolvedTableCell({
3145
3434
  }
3146
3435
 
3147
3436
  // src/components/ui/table/features/column-resize/columnResize.ts
3437
+ function clamp(value, min, max) {
3438
+ return Math.min(Math.max(value, min), max);
3439
+ }
3440
+ function floorOf(column) {
3441
+ return column.minWidth ?? 0;
3442
+ }
3443
+ function ceilOf(column) {
3444
+ return column.maxWidth ?? Number.POSITIVE_INFINITY;
3445
+ }
3446
+ function preferOf(column) {
3447
+ const floor = floorOf(column);
3448
+ const ceil = ceilOf(column);
3449
+ const preferred = column.maxWidth ?? column.minWidth ?? 0;
3450
+ return clamp(preferred, floor, Number.isFinite(ceil) ? ceil : preferred);
3451
+ }
3452
+ function resolveColumnLayoutWidths(containerWidth, columns) {
3453
+ const widths = /* @__PURE__ */ new Map();
3454
+ const fixed = [];
3455
+ const bounded = [];
3456
+ let flexCount = 0;
3457
+ for (const column of columns) {
3458
+ if (column.width != null) {
3459
+ fixed.push(column);
3460
+ } else if (column.minWidth != null || column.maxWidth != null) {
3461
+ bounded.push(column);
3462
+ } else {
3463
+ flexCount += 1;
3464
+ }
3465
+ }
3466
+ let used = 0;
3467
+ for (const column of fixed) {
3468
+ let size = column.width;
3469
+ if (column.minWidth != null) size = Math.max(size, column.minWidth);
3470
+ if (column.maxWidth != null) size = Math.min(size, column.maxWidth);
3471
+ widths.set(column.id, size);
3472
+ used += size;
3473
+ }
3474
+ if (bounded.length === 0) {
3475
+ return widths;
3476
+ }
3477
+ const boundedSizes = /* @__PURE__ */ new Map();
3478
+ let preferredSum = 0;
3479
+ let floorSum = 0;
3480
+ for (const column of bounded) {
3481
+ const preferred = preferOf(column);
3482
+ boundedSizes.set(column.id, preferred);
3483
+ preferredSum += preferred;
3484
+ floorSum += floorOf(column);
3485
+ }
3486
+ if (containerWidth > 0) {
3487
+ const remaining = Math.max(0, containerWidth - used);
3488
+ if (remaining >= preferredSum) {
3489
+ } else if (remaining >= floorSum) {
3490
+ let deficit = preferredSum - remaining;
3491
+ const open = bounded.map((column) => ({
3492
+ id: column.id,
3493
+ current: boundedSizes.get(column.id),
3494
+ floor: floorOf(column)
3495
+ }));
3496
+ while (deficit >= 1) {
3497
+ const shrinkable = open.filter((entry) => entry.current > entry.floor);
3498
+ if (shrinkable.length === 0) break;
3499
+ const portion = Math.floor(deficit / shrinkable.length);
3500
+ const rem = deficit % shrinkable.length;
3501
+ let consumed = 0;
3502
+ for (let index = 0; index < shrinkable.length; index += 1) {
3503
+ const entry = shrinkable[index];
3504
+ const reduce = Math.min(
3505
+ entry.current - entry.floor,
3506
+ portion + (index < rem ? 1 : 0)
3507
+ );
3508
+ entry.current -= reduce;
3509
+ consumed += reduce;
3510
+ }
3511
+ if (consumed === 0) break;
3512
+ deficit -= consumed;
3513
+ }
3514
+ for (const entry of open) {
3515
+ boundedSizes.set(entry.id, entry.current);
3516
+ }
3517
+ } else {
3518
+ for (const column of bounded) {
3519
+ boundedSizes.set(column.id, floorOf(column));
3520
+ }
3521
+ }
3522
+ }
3523
+ for (const [id, size] of boundedSizes) {
3524
+ widths.set(id, Math.round(size));
3525
+ }
3526
+ return widths;
3527
+ }
3148
3528
  function getColumnSizeStyle(size, options) {
3149
- const { force = false, lockMax = false, minWidth, maxWidth } = options ?? {};
3529
+ const {
3530
+ force = false,
3531
+ lockMax = false,
3532
+ minWidth,
3533
+ maxWidth,
3534
+ layoutWidth
3535
+ } = options ?? {};
3150
3536
  if (lockMax) {
3151
3537
  return {
3152
3538
  width: size,
@@ -3154,14 +3540,27 @@ function getColumnSizeStyle(size, options) {
3154
3540
  maxWidth: size
3155
3541
  };
3156
3542
  }
3543
+ if (layoutWidth != null) {
3544
+ return {
3545
+ width: layoutWidth,
3546
+ minWidth: layoutWidth,
3547
+ maxWidth: layoutWidth
3548
+ };
3549
+ }
3550
+ const resolvedSize = size;
3157
3551
  const hasExplicitSize = force || size !== DATA_TABLE_COLUMN_SIZE;
3158
3552
  if (!hasExplicitSize && minWidth == null && maxWidth == null) {
3159
3553
  return void 0;
3160
3554
  }
3161
3555
  const style = {};
3162
3556
  if (hasExplicitSize) {
3163
- style.width = size;
3164
- style.minWidth = minWidth ?? size;
3557
+ const used = minWidth != null || maxWidth != null ? clamp(
3558
+ resolvedSize,
3559
+ minWidth ?? Number.NEGATIVE_INFINITY,
3560
+ maxWidth ?? Number.POSITIVE_INFINITY
3561
+ ) : resolvedSize;
3562
+ style.width = used;
3563
+ style.minWidth = minWidth ?? used;
3165
3564
  } else if (minWidth != null) {
3166
3565
  style.minWidth = minWidth;
3167
3566
  }
@@ -3172,7 +3571,7 @@ function getColumnSizeStyle(size, options) {
3172
3571
  }
3173
3572
 
3174
3573
  // src/components/ui/table/features/column-reorder/useColumnReorder.ts
3175
- var import_react8 = require("react");
3574
+ var import_react9 = require("react");
3176
3575
  function hitTestReorderHeader(table, clientX, clientY) {
3177
3576
  const headers = Array.from(
3178
3577
  table.querySelectorAll(
@@ -3220,19 +3619,19 @@ function readTargetIds(table, columnId) {
3220
3619
  }
3221
3620
  function useColumnReorder(options) {
3222
3621
  const { enabled, columnOrder, onColumnOrderChange } = options;
3223
- const sessionRef = (0, import_react8.useRef)(null);
3224
- const columnOrderRef = (0, import_react8.useRef)(columnOrder);
3225
- const onColumnOrderChangeRef = (0, import_react8.useRef)(onColumnOrderChange);
3226
- const [draggingColumnId, setDraggingColumnId] = (0, import_react8.useState)(null);
3227
- const [dropTarget, setDropTarget] = (0, import_react8.useState)(
3622
+ const sessionRef = (0, import_react9.useRef)(null);
3623
+ const columnOrderRef = (0, import_react9.useRef)(columnOrder);
3624
+ const onColumnOrderChangeRef = (0, import_react9.useRef)(onColumnOrderChange);
3625
+ const [draggingColumnId, setDraggingColumnId] = (0, import_react9.useState)(null);
3626
+ const [dropTarget, setDropTarget] = (0, import_react9.useState)(
3228
3627
  null
3229
3628
  );
3230
- const dropTargetRef = (0, import_react8.useRef)(dropTarget);
3231
- const previousUserSelectRef = (0, import_react8.useRef)(null);
3629
+ const dropTargetRef = (0, import_react9.useRef)(dropTarget);
3630
+ const previousUserSelectRef = (0, import_react9.useRef)(null);
3232
3631
  columnOrderRef.current = columnOrder;
3233
3632
  onColumnOrderChangeRef.current = onColumnOrderChange;
3234
3633
  dropTargetRef.current = dropTarget;
3235
- const resetDrag = (0, import_react8.useCallback)(() => {
3634
+ const resetDrag = (0, import_react9.useCallback)(() => {
3236
3635
  sessionRef.current = null;
3237
3636
  setDraggingColumnId(null);
3238
3637
  setDropTarget(null);
@@ -3248,15 +3647,15 @@ function useColumnReorder(options) {
3248
3647
  }
3249
3648
  document.body.style.removeProperty("user-select");
3250
3649
  }, []);
3251
- (0, import_react8.useEffect)(() => {
3650
+ (0, import_react9.useEffect)(() => {
3252
3651
  if (!enabled) resetDrag();
3253
3652
  }, [enabled, resetDrag]);
3254
- (0, import_react8.useEffect)(() => {
3653
+ (0, import_react9.useEffect)(() => {
3255
3654
  return () => {
3256
3655
  resetDrag();
3257
3656
  };
3258
3657
  }, [resetDrag]);
3259
- const onHeaderPointerDown = (0, import_react8.useCallback)(
3658
+ const onHeaderPointerDown = (0, import_react9.useCallback)(
3260
3659
  (event, meta) => {
3261
3660
  if (!enabled || !meta.canDrag) return;
3262
3661
  if (event.button !== 0) return;
@@ -3279,7 +3678,7 @@ function useColumnReorder(options) {
3279
3678
  },
3280
3679
  [enabled]
3281
3680
  );
3282
- (0, import_react8.useEffect)(() => {
3681
+ (0, import_react9.useEffect)(() => {
3283
3682
  if (!enabled) return;
3284
3683
  const onPointerMove = (event) => {
3285
3684
  const session = sessionRef.current;
@@ -3381,11 +3780,11 @@ function useColumnReorder(options) {
3381
3780
 
3382
3781
  // src/components/ui/table/components/DataTable/DataTable.tsx
3383
3782
  var import_react_table3 = require("@tanstack/react-table");
3384
- var import_react10 = require("react");
3783
+ var import_react11 = require("react");
3385
3784
 
3386
3785
  // src/components/ui/table/components/DataTable/DataTableRow.tsx
3387
3786
  var import_react_table2 = require("@tanstack/react-table");
3388
- var import_react9 = require("react");
3787
+ var import_react10 = require("react");
3389
3788
 
3390
3789
  // src/components/ui/table/components/icons.tsx
3391
3790
  var import_jsx_runtime3 = require("react/jsx-runtime");
@@ -3547,6 +3946,12 @@ function isInteractiveMouseTarget(target) {
3547
3946
  ].join(",");
3548
3947
  return target.closest(interactiveSelector) !== null;
3549
3948
  }
3949
+ function blurActiveElementOutside(container) {
3950
+ const active = document.activeElement;
3951
+ if (!(active instanceof HTMLElement) || active === document.body) return;
3952
+ if (container instanceof Node && container.contains(active)) return;
3953
+ active.blur();
3954
+ }
3550
3955
  function resolveExpandCellIndex(cells, toggleField) {
3551
3956
  if (!toggleField) return 0;
3552
3957
  const matchedIndex = cells.findIndex(
@@ -3579,7 +3984,7 @@ function DataTableRow({
3579
3984
  columnFreeze,
3580
3985
  inlineSearch
3581
3986
  } = useDataTableRowContext();
3582
- const { enableColumnResize } = columnResize;
3987
+ const { enableColumnResize, layoutWidths } = columnResize;
3583
3988
  const { enableColumnFreeze, offsets: freezeOffsets } = columnFreeze;
3584
3989
  const {
3585
3990
  enabled: enableInlineSearch,
@@ -3683,9 +4088,9 @@ function DataTableRow({
3683
4088
  const expandKey = toggleField && rowData[toggleField] !== null && rowData[toggleField] !== void 0 ? String(rowData[toggleField]) : null;
3684
4089
  const isExpanded = expandKey !== null && Boolean(expandedRows?.has(expandKey));
3685
4090
  const rowLevel = typeof rowData.level === "number" ? rowData.level : 0;
3686
- const editInputRef = (0, import_react9.useRef)(null);
4091
+ const editInputRef = (0, import_react10.useRef)(null);
3687
4092
  const isRowEditing = editingCell?.rowIndex === rowIndex;
3688
- (0, import_react9.useEffect)(() => {
4093
+ (0, import_react10.useEffect)(() => {
3689
4094
  if (!isRowEditing) return;
3690
4095
  editInputRef.current?.focus();
3691
4096
  editInputRef.current?.select();
@@ -3774,7 +4179,8 @@ function DataTableRow({
3774
4179
  force: enableColumnResize,
3775
4180
  lockMax: enableColumnResize,
3776
4181
  minWidth: meta?.minWidth,
3777
- maxWidth: meta?.maxWidth
4182
+ maxWidth: meta?.maxWidth,
4183
+ layoutWidth: layoutWidths?.get(columnId)
3778
4184
  });
3779
4185
  const freezeOffset = enableColumnFreeze ? freezeOffsets.get(columnId) : void 0;
3780
4186
  const freezeStyle = getColumnFreezeStyle(freezeOffset);
@@ -3814,6 +4220,7 @@ function DataTableRow({
3814
4220
  if (!enableCellSelection) return;
3815
4221
  if (isInteractiveMouseTarget(event.target)) return;
3816
4222
  event.preventDefault();
4223
+ blurActiveElementOutside(event.currentTarget);
3817
4224
  onCellMouseDown(
3818
4225
  resolveCellRowIndex(event.clientY, event.currentTarget),
3819
4226
  cellIndex,
@@ -3977,6 +4384,7 @@ function DataTableRow({
3977
4384
  onMouseDown: (event) => {
3978
4385
  event.stopPropagation();
3979
4386
  event.preventDefault();
4387
+ blurActiveElementOutside(event.currentTarget);
3980
4388
  onFillHandleMouseDown(rowIndex, cellIndex);
3981
4389
  }
3982
4390
  }
@@ -4306,17 +4714,74 @@ function DataTable({
4306
4714
  const RowSlot = slots?.Row ?? DataTableRow;
4307
4715
  const PendingSlot = slots?.Pending ?? DefaultPending;
4308
4716
  const EmptySlot = slots?.Empty ?? DefaultEmpty;
4309
- const freezeOffsets = rowContextValue.columnFreeze.offsets;
4310
4717
  const headerGroups = getMergedHeaderGroups(table.getHeaderGroups());
4311
4718
  const leafColumnIds = table.getVisibleLeafColumns().map((column) => column.id);
4719
+ const columnLayoutMetaSignature = table.getVisibleLeafColumns().map((column) => {
4720
+ const meta = column.columnDef.meta;
4721
+ return `${column.id}:${meta?.width ?? ""}:${meta?.minWidth ?? ""}:${meta?.maxWidth ?? ""}`;
4722
+ }).join("|");
4312
4723
  const { isReordering, draggingColumnId, dropTarget, onHeaderPointerDown } = useColumnReorder({
4313
4724
  enabled: enableColumnReorder,
4314
4725
  columnOrder: leafColumnIds,
4315
4726
  onColumnOrderChange: setColumnOrder
4316
4727
  });
4317
- const contextValue = (0, import_react10.useMemo)(
4318
- () => ({ ...rowContextValue, classNames }),
4319
- [rowContextValue, classNames]
4728
+ const [containerWidth, setContainerWidth] = (0, import_react11.useState)(0);
4729
+ (0, import_react11.useEffect)(() => {
4730
+ if (enableColumnResize || isPending) return;
4731
+ const element = scrollRef.current;
4732
+ if (!element) return;
4733
+ const updateWidth = () => {
4734
+ setContainerWidth(Math.floor(element.clientWidth));
4735
+ };
4736
+ updateWidth();
4737
+ if (typeof ResizeObserver === "undefined") return;
4738
+ const observer = new ResizeObserver(() => {
4739
+ updateWidth();
4740
+ });
4741
+ observer.observe(element);
4742
+ return () => observer.disconnect();
4743
+ }, [enableColumnResize, isPending, scrollRef, rows.length, leafColumnIds.join("|")]);
4744
+ const layoutWidths = (0, import_react11.useMemo)(() => {
4745
+ if (enableColumnResize) return void 0;
4746
+ const columns = table.getVisibleLeafColumns().map((column) => ({
4747
+ id: column.id,
4748
+ width: column.columnDef.meta?.width,
4749
+ minWidth: column.columnDef.meta?.minWidth,
4750
+ maxWidth: column.columnDef.meta?.maxWidth
4751
+ }));
4752
+ return resolveColumnLayoutWidths(containerWidth, columns);
4753
+ }, [enableColumnResize, containerWidth, table, columnLayoutMetaSignature]);
4754
+ const freezeOffsets = (0, import_react11.useMemo)(() => {
4755
+ if (!enableColumnFreeze || enableColumnResize || !layoutWidths) {
4756
+ return rowContextValue.columnFreeze.offsets;
4757
+ }
4758
+ const columns = table.getVisibleLeafColumns().map((column) => ({
4759
+ id: column.id,
4760
+ size: layoutWidths.get(column.id) ?? column.getSize(),
4761
+ side: resolveColumnFreezeSide(column.columnDef.meta?.frozen)
4762
+ }));
4763
+ return buildColumnFreezeOffsets(columns);
4764
+ }, [
4765
+ enableColumnFreeze,
4766
+ enableColumnResize,
4767
+ layoutWidths,
4768
+ rowContextValue.columnFreeze.offsets,
4769
+ table
4770
+ ]);
4771
+ const contextValue = (0, import_react11.useMemo)(
4772
+ () => ({
4773
+ ...rowContextValue,
4774
+ classNames,
4775
+ columnFreeze: {
4776
+ ...rowContextValue.columnFreeze,
4777
+ offsets: freezeOffsets
4778
+ },
4779
+ columnResize: {
4780
+ ...rowContextValue.columnResize,
4781
+ layoutWidths
4782
+ }
4783
+ }),
4784
+ [rowContextValue, classNames, freezeOffsets, layoutWidths]
4320
4785
  );
4321
4786
  if (isPending) {
4322
4787
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
@@ -4397,7 +4862,8 @@ function DataTable({
4397
4862
  force: enableColumnResize,
4398
4863
  lockMax: enableColumnResize,
4399
4864
  minWidth: header.column.columnDef.meta?.minWidth,
4400
- maxWidth: header.column.columnDef.meta?.maxWidth
4865
+ maxWidth: header.column.columnDef.meta?.maxWidth,
4866
+ layoutWidth: layoutWidths?.get(header.column.id)
4401
4867
  });
4402
4868
  const freezeOffset = enableColumnFreeze ? resolveHeaderFreezeOffset(header.column, freezeOffsets) : void 0;
4403
4869
  const freezeStyle = getColumnFreezeStyle(freezeOffset, {
@@ -4410,7 +4876,9 @@ function DataTable({
4410
4876
  };
4411
4877
  const isPlaceholder = header.isPlaceholder;
4412
4878
  const leafColumns = header.column.getLeafColumns();
4413
- const leafIds = leafColumns.map((leafColumn) => leafColumn.id);
4879
+ const leafIds = leafColumns.map(
4880
+ (leafColumn) => leafColumn.id
4881
+ );
4414
4882
  const isLeafHeader = !isPlaceholder && header.subHeaders.length === 0;
4415
4883
  const canDrag = enableColumnReorder && !isPlaceholder && leafIds.length > 0 && leafColumns.every(
4416
4884
  (leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
@@ -4566,7 +5034,7 @@ function DataTable({
4566
5034
  }
4567
5035
 
4568
5036
  // src/components/ui/table/components/Table/Table.tsx
4569
- var import_react13 = require("react");
5037
+ var import_react14 = require("react");
4570
5038
 
4571
5039
  // src/components/ui/table/components/Table/buildColumnDef.tsx
4572
5040
  var import_jsx_runtime8 = require("react/jsx-runtime");
@@ -4655,6 +5123,7 @@ function buildColumnDef(props, sort, onSort) {
4655
5123
  cellRender: render,
4656
5124
  frozen,
4657
5125
  reorderable,
5126
+ width,
4658
5127
  minWidth,
4659
5128
  maxWidth,
4660
5129
  className,
@@ -4702,10 +5171,10 @@ function countLeafColumns(nodes) {
4702
5171
  }
4703
5172
 
4704
5173
  // src/components/ui/table/components/Table/parseTableChildren.ts
4705
- var import_react12 = require("react");
5174
+ var import_react13 = require("react");
4706
5175
 
4707
5176
  // src/components/ui/table/components/Table/tableChildTypes.ts
4708
- var import_react11 = require("react");
5177
+ var import_react12 = require("react");
4709
5178
  var TABLE_HEADER_DISPLAY_NAME = "Table.Header";
4710
5179
  var TABLE_BODY_DISPLAY_NAME = "Table.Body";
4711
5180
  var TABLE_COLUMN_DISPLAY_NAME = "Table.Column";
@@ -4718,19 +5187,19 @@ function getComponentDisplayName(type) {
4718
5187
  return void 0;
4719
5188
  }
4720
5189
  function isTableHeaderElement(child) {
4721
- return (0, import_react11.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
5190
+ return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
4722
5191
  }
4723
5192
  function isTableBodyElement(child) {
4724
- return (0, import_react11.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
5193
+ return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
4725
5194
  }
4726
5195
  function isTableColumnElement(child) {
4727
- return (0, import_react11.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
5196
+ return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
4728
5197
  }
4729
5198
  function isTableColumnGroupElement(child) {
4730
- return (0, import_react11.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_GROUP_DISPLAY_NAME;
5199
+ return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_GROUP_DISPLAY_NAME;
4731
5200
  }
4732
5201
  function isTablePaginationElement(child) {
4733
- return (0, import_react11.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
5202
+ return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
4734
5203
  }
4735
5204
 
4736
5205
  // src/components/ui/table/components/Table/parseTableChildren.ts
@@ -4740,7 +5209,7 @@ function parseTableChildren(children) {
4740
5209
  body: null,
4741
5210
  pagination: null
4742
5211
  };
4743
- for (const child of import_react12.Children.toArray(children)) {
5212
+ for (const child of import_react13.Children.toArray(children)) {
4744
5213
  if (isTableHeaderElement(child)) {
4745
5214
  slots.header = child;
4746
5215
  continue;
@@ -4757,7 +5226,7 @@ function parseTableChildren(children) {
4757
5226
  }
4758
5227
  function walkColumnTreeNodes(children) {
4759
5228
  const result = [];
4760
- for (const child of import_react12.Children.toArray(children)) {
5229
+ for (const child of import_react13.Children.toArray(children)) {
4761
5230
  if (isTableColumnElement(child)) {
4762
5231
  result.push({
4763
5232
  type: "leaf",
@@ -4774,7 +5243,7 @@ function walkColumnTreeNodes(children) {
4774
5243
  });
4775
5244
  continue;
4776
5245
  }
4777
- if ((0, import_react12.isValidElement)(child)) {
5246
+ if ((0, import_react13.isValidElement)(child)) {
4778
5247
  const nested = child.props.children;
4779
5248
  if (nested != null) {
4780
5249
  result.push(...walkColumnTreeNodes(nested));
@@ -4900,12 +5369,12 @@ function TableRoot({
4900
5369
  filteredCount,
4901
5370
  ...dataTableProps
4902
5371
  }) {
4903
- const { header, pagination: paginationElement } = (0, import_react13.useMemo)(
5372
+ const { header, pagination: paginationElement } = (0, import_react14.useMemo)(
4904
5373
  () => parseTableChildren(children),
4905
5374
  [children]
4906
5375
  );
4907
- const [sort, setSort] = (0, import_react13.useState)(null);
4908
- const handleSort = (0, import_react13.useCallback)((field) => {
5376
+ const [sort, setSort] = (0, import_react14.useState)(null);
5377
+ const handleSort = (0, import_react14.useCallback)((field) => {
4909
5378
  setSort((previous) => {
4910
5379
  if (previous?.field !== field) {
4911
5380
  return { field, direction: "asc" };
@@ -4916,8 +5385,8 @@ function TableRoot({
4916
5385
  return null;
4917
5386
  });
4918
5387
  }, []);
4919
- const columnTree = (0, import_react13.useMemo)(() => extractColumnTree(header), [header]);
4920
- const columns = (0, import_react13.useMemo)(
5388
+ const columnTree = (0, import_react14.useMemo)(() => extractColumnTree(header), [header]);
5389
+ const columns = (0, import_react14.useMemo)(
4921
5390
  () => buildColumnDefsFromTree(columnTree, sort, handleSort),
4922
5391
  [columnTree, sort, handleSort]
4923
5392
  );
@@ -4925,7 +5394,7 @@ function TableRoot({
4925
5394
  const pageSize = paginationProps?.pageSize ?? 10;
4926
5395
  const page = paginationProps?.page ?? 1;
4927
5396
  const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
4928
- const tableData = (0, import_react13.useMemo)(() => {
5397
+ const tableData = (0, import_react14.useMemo)(() => {
4929
5398
  const sortedData = sortTableData(data, sort);
4930
5399
  if (!paginationProps) return sortedData;
4931
5400
  return paginateTableData(sortedData, page, pageSize);
@@ -5053,6 +5522,7 @@ var Table = Object.assign(TableRoot, {
5053
5522
  previousSearchIndex,
5054
5523
  resolveCellRenderer,
5055
5524
  resolveColumnFreezeSide,
5525
+ resolveColumnLayoutWidths,
5056
5526
  resolveDataTableLabels,
5057
5527
  resolveDropEdge,
5058
5528
  resolveHeaderFreezeOffset,