react-glide-table 2.2.0 → 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/dist/core.cjs CHANGED
@@ -80,6 +80,7 @@ __export(core_exports, {
80
80
  previousSearchIndex: () => previousSearchIndex,
81
81
  resolveCellRenderer: () => resolveCellRenderer,
82
82
  resolveColumnFreezeSide: () => resolveColumnFreezeSide,
83
+ resolveColumnLayoutWidths: () => resolveColumnLayoutWidths,
83
84
  resolveDataTableLabels: () => resolveDataTableLabels,
84
85
  resolveDropEdge: () => resolveDropEdge,
85
86
  resolveHeaderFreezeOffset: () => resolveHeaderFreezeOffset,
@@ -133,7 +134,7 @@ var DEFAULT_TREE_QTY_FIELD = "qty";
133
134
  // src/core/useGlideTable.ts
134
135
  var import_react_table = require("@tanstack/react-table");
135
136
  var import_react_virtual = require("@tanstack/react-virtual");
136
- var import_react5 = require("react");
137
+ var import_react6 = require("react");
137
138
 
138
139
  // src/components/ui/table/constants.ts
139
140
  var DATA_TABLE_ROW_HEIGHT = 44;
@@ -526,7 +527,7 @@ function withCellUpdate(context, commitValue) {
526
527
  }
527
528
 
528
529
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
529
- var import_react2 = require("react");
530
+ var import_react3 = require("react");
530
531
 
531
532
  // src/components/ui/table/features/cell-selection/cellSelection.ts
532
533
  var INITIAL_DRAG_STATE = {
@@ -834,6 +835,219 @@ function hasCellSelectionEdges(style) {
834
835
  }
835
836
 
836
837
  // src/components/ui/table/features/cell-selection/copyData.ts
838
+ var import_react2 = require("react");
839
+ function isReactNodeIterable(node) {
840
+ return typeof node === "object" && node !== null && !(0, import_react2.isValidElement)(node) && Symbol.iterator in node;
841
+ }
842
+ function getElementTypeName(type) {
843
+ if (typeof type === "string") return type;
844
+ if (typeof type === "function") {
845
+ const fn = type;
846
+ return fn.displayName || fn.name || "";
847
+ }
848
+ if (typeof type === "object" && type !== null) {
849
+ const component = type;
850
+ return component.displayName || component.render?.displayName || component.render?.name || "";
851
+ }
852
+ return "";
853
+ }
854
+ function isButtonReactElement(node) {
855
+ const typeName = getElementTypeName(node.type);
856
+ if (typeName === "button" || /button/i.test(typeName)) return true;
857
+ const props = node.props;
858
+ if (props.role === "button") return true;
859
+ if (typeName === "input" && props.type === "button") return true;
860
+ return false;
861
+ }
862
+ function isImageReactElement(node) {
863
+ const typeName = getElementTypeName(node.type);
864
+ return typeName === "img" || typeName === "image" || /image/i.test(typeName);
865
+ }
866
+ var IMAGE_URL_PROP_KEYS = ["src", "url", "href", "imageUrl", "srcUrl"];
867
+ function isLikelyUrl(value) {
868
+ const trimmed = value.trim();
869
+ if (!trimmed) return false;
870
+ if (/^(https?:|blob:|data:|\/\/)/i.test(trimmed)) return true;
871
+ if (trimmed.startsWith("/") && trimmed.includes("/")) return true;
872
+ return false;
873
+ }
874
+ function pickUrlFromUnknown(value) {
875
+ if (typeof value === "string") {
876
+ return isLikelyUrl(value) ? value.trim() : "";
877
+ }
878
+ if (Array.isArray(value)) {
879
+ return value.map((item) => pickUrlFromUnknown(item)).filter((item) => item.length > 0).join(", ");
880
+ }
881
+ if (value && typeof value === "object") {
882
+ const record = value;
883
+ for (const key of IMAGE_URL_PROP_KEYS) {
884
+ const candidate = record[key];
885
+ if (typeof candidate === "string" && candidate.trim()) {
886
+ return candidate.trim();
887
+ }
888
+ }
889
+ }
890
+ return "";
891
+ }
892
+ function imageElementText(node) {
893
+ const props = node.props;
894
+ for (const key of IMAGE_URL_PROP_KEYS) {
895
+ const candidate = props[key];
896
+ if (typeof candidate === "string" && candidate.trim()) {
897
+ return candidate.trim();
898
+ }
899
+ }
900
+ return "";
901
+ }
902
+ function reactNodeContainsImage(node) {
903
+ if ((0, import_react2.isValidElement)(node)) {
904
+ if (isImageReactElement(node)) return true;
905
+ return reactNodeContainsImage(node.props.children);
906
+ }
907
+ if (isReactNodeIterable(node)) {
908
+ for (const child of node) {
909
+ if (reactNodeContainsImage(child)) return true;
910
+ }
911
+ }
912
+ return false;
913
+ }
914
+ function readImgUrl(img) {
915
+ const attr = img.getAttribute("src")?.trim() ?? "";
916
+ if (attr) return attr;
917
+ if (img instanceof HTMLImageElement) {
918
+ const current = img.currentSrc?.trim() ?? "";
919
+ if (current && current !== img.baseURI) return current;
920
+ }
921
+ return "";
922
+ }
923
+ function readDomImageUrls(rowIndex, colIndex, root) {
924
+ const scope = root ?? (typeof document === "undefined" ? null : document);
925
+ if (!scope) return "";
926
+ const cells = scope.querySelectorAll(
927
+ `[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
928
+ );
929
+ for (const cell of cells) {
930
+ const urls = Array.from(cell.querySelectorAll("img")).flatMap((img) => {
931
+ const url = readImgUrl(img);
932
+ return url ? [url] : [];
933
+ });
934
+ if (urls.length > 0) return urls.join(", ");
935
+ }
936
+ return "";
937
+ }
938
+ function reactNodeToText(node) {
939
+ if (node == null || typeof node === "boolean") return "";
940
+ if (typeof node === "string" || typeof node === "number" || typeof node === "bigint") {
941
+ return String(node);
942
+ }
943
+ if (isReactNodeIterable(node)) {
944
+ let text = "";
945
+ for (const child of node) {
946
+ text += reactNodeToText(child);
947
+ }
948
+ return text;
949
+ }
950
+ if ((0, import_react2.isValidElement)(node)) {
951
+ if (isButtonReactElement(node)) return "";
952
+ const props = node.props;
953
+ const childText = reactNodeToText(props.children);
954
+ if (childText) return childText;
955
+ const fromImage = imageElementText(node);
956
+ if (fromImage) return fromImage;
957
+ if (isImageReactElement(node)) return "";
958
+ if (typeof props.alt === "string" && props.alt) return props.alt;
959
+ if (typeof props.title === "string" && props.title) return props.title;
960
+ return "";
961
+ }
962
+ return "";
963
+ }
964
+ function sanitizeClipboardCell(text) {
965
+ return text.replace(/\s+/g, " ").trim();
966
+ }
967
+ function createCopyRenderRow(rowData, index) {
968
+ return {
969
+ id: getOriginalRowId(rowData) || String(index),
970
+ index,
971
+ original: rowData,
972
+ getIsCellDragSelected: () => false
973
+ };
974
+ }
975
+ function buildVisibleRowLookup(visibleRows) {
976
+ const lookup = /* @__PURE__ */ new Map();
977
+ for (const row of visibleRows) {
978
+ lookup.set(row.original, row);
979
+ }
980
+ return lookup;
981
+ }
982
+ function resolveCopyColumnId(cell) {
983
+ if (cell.column.id) return cell.column.id;
984
+ const columnDef = cell.column.columnDef;
985
+ if (columnDef.id) return columnDef.id;
986
+ if (columnDef.accessorKey != null && columnDef.accessorKey !== "") {
987
+ return String(columnDef.accessorKey);
988
+ }
989
+ return "";
990
+ }
991
+ function isPrimitiveCopyValue(value) {
992
+ return value == null || typeof value !== "object";
993
+ }
994
+ function extractRenderedCopyText(node, value, cellPosition, root) {
995
+ const rendered = sanitizeClipboardCell(reactNodeToText(node));
996
+ if (reactNodeContainsImage(node)) {
997
+ const fromDom = cellPosition != null ? sanitizeClipboardCell(
998
+ readDomImageUrls(cellPosition.rowIndex, cellPosition.colIndex, root)
999
+ ) : "";
1000
+ if (fromDom) return fromDom;
1001
+ if (rendered && isLikelyUrl(rendered)) return rendered;
1002
+ return sanitizeClipboardCell(pickUrlFromUnknown(value));
1003
+ }
1004
+ return rendered;
1005
+ }
1006
+ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
1007
+ const meta = columnDef.meta;
1008
+ const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
1009
+ const cellRender = meta?.cellRender;
1010
+ if (typeof cellRender === "function") {
1011
+ try {
1012
+ const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1013
+ const node = cellRender({
1014
+ value,
1015
+ row,
1016
+ index: row.index,
1017
+ columnId,
1018
+ cellProps: meta?.cellProps,
1019
+ update: () => {
1020
+ }
1021
+ });
1022
+ return extractRenderedCopyText(node, value, cellPosition, options?.root);
1023
+ } catch {
1024
+ return formatCellValue(value);
1025
+ }
1026
+ }
1027
+ if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
1028
+ try {
1029
+ const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1030
+ const ctx = {
1031
+ value,
1032
+ row,
1033
+ index: row.index,
1034
+ columnId,
1035
+ cellProps: meta.cellProps,
1036
+ update: () => {
1037
+ }
1038
+ };
1039
+ const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
1040
+ if (renderer) {
1041
+ const node = renderer.render(ctx);
1042
+ const rendered = extractRenderedCopyText(node, value, cellPosition, options.root);
1043
+ if (rendered) return rendered;
1044
+ }
1045
+ } catch {
1046
+ return formatCellValue(value);
1047
+ }
1048
+ }
1049
+ return formatCellValue(value);
1050
+ }
837
1051
  function formatPrimitive(value) {
838
1052
  if (value === null || value === void 0) return "";
839
1053
  if (typeof value === "string") return value;
@@ -939,37 +1153,47 @@ function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
939
1153
  function collectCopyRows(visibleRows, bounds, mode = "visible") {
940
1154
  return collectCopyRowEntries(visibleRows, bounds, mode).map((entry) => entry.row);
941
1155
  }
942
- function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths) {
1156
+ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options) {
943
1157
  if (copyRows.length === 0) return "";
944
1158
  const { startCol, endCol } = bounds;
945
1159
  const columnCells = visibleRows[0]?.getVisibleCells().slice(startCol, endCol + 1) ?? [];
946
1160
  if (columnCells.length === 0) return "";
947
1161
  const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
948
1162
  const minDepth = Math.min(...resolvedDepths);
1163
+ const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
949
1164
  return copyRows.map((rowData, index) => {
950
1165
  const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
951
- const line = columnCells.map(
952
- (cell) => formatCellValue(
953
- readRowColumnValue(
954
- rowData,
955
- cell.column.columnDef
956
- )
957
- )
958
- ).join(" ");
1166
+ const visibleRow = visibleRowByOriginal.get(rowData);
1167
+ const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
1168
+ const line = columnCells.map((templateCell, colOffset) => {
1169
+ const sourceCell = matchingCells?.[colOffset];
1170
+ const column = sourceCell?.column ?? templateCell.column;
1171
+ return formatCopyCellText(
1172
+ rowData,
1173
+ column.columnDef,
1174
+ resolveCopyColumnId(sourceCell ?? templateCell),
1175
+ visibleRow,
1176
+ visibleRow?.index ?? index,
1177
+ sourceCell,
1178
+ visibleRow != null ? { rowIndex: visibleRow.index, colIndex: startCol + colOffset } : void 0,
1179
+ options
1180
+ );
1181
+ }).join(" ");
959
1182
  return `${" ".repeat(relativeDepth)}${line}`;
960
1183
  }).join("\n");
961
1184
  }
962
- function serializeSelectionToTSV(visibleRows, bounds, mode = "visible") {
1185
+ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options) {
963
1186
  const entries = collectCopyRowEntries(visibleRows, bounds, mode);
964
1187
  return serializeCopyRowsToTSV(
965
1188
  entries.map((entry) => entry.row),
966
1189
  visibleRows,
967
1190
  bounds,
968
- entries.map((entry) => entry.depth)
1191
+ entries.map((entry) => entry.depth),
1192
+ options
969
1193
  );
970
1194
  }
971
- async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible") {
972
- const text = serializeSelectionToTSV(visibleRows, bounds, mode);
1195
+ async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
1196
+ const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
973
1197
  if (!text) return false;
974
1198
  try {
975
1199
  await navigator.clipboard.writeText(text);
@@ -1130,17 +1354,19 @@ function useCellSelection({
1130
1354
  onDataChange,
1131
1355
  onBatchChange,
1132
1356
  onRowsPaste,
1133
- onCellNavigate
1357
+ onCellNavigate,
1358
+ cellRendererRegistry,
1359
+ rootRef
1134
1360
  }) {
1135
- const [dragState, setDragState] = (0, import_react2.useState)(INITIAL_DRAG_STATE);
1136
- const pendingPasteModeRef = (0, import_react2.useRef)(null);
1137
- const dragStateRef = (0, import_react2.useRef)(dragState);
1138
- const onCellNavigateRef = (0, import_react2.useRef)(onCellNavigate);
1361
+ const [dragState, setDragState] = (0, import_react3.useState)(INITIAL_DRAG_STATE);
1362
+ const pendingPasteModeRef = (0, import_react3.useRef)(null);
1363
+ const dragStateRef = (0, import_react3.useRef)(dragState);
1364
+ const onCellNavigateRef = (0, import_react3.useRef)(onCellNavigate);
1139
1365
  dragStateRef.current = dragState;
1140
1366
  onCellNavigateRef.current = onCellNavigate;
1141
1367
  const cellSelectionBounds = getCellSelectionBounds(dragState.start, dragState.end);
1142
1368
  const activeSelectionBounds = enabled ? getActiveSelectionBounds(dragState, cellSelectionBounds) : null;
1143
- const handleCellMouseDown = (0, import_react2.useCallback)(
1369
+ const handleCellMouseDown = (0, import_react3.useCallback)(
1144
1370
  (rowIndex, colIndex, options) => {
1145
1371
  if (!enabled) return;
1146
1372
  setDragState((prev) => {
@@ -1166,7 +1392,7 @@ function useCellSelection({
1166
1392
  },
1167
1393
  [enabled]
1168
1394
  );
1169
- const handleCellMouseEnter = (0, import_react2.useCallback)(
1395
+ const handleCellMouseEnter = (0, import_react3.useCallback)(
1170
1396
  (rowIndex, colIndex) => {
1171
1397
  if (!enabled) return;
1172
1398
  setDragState((prev) => {
@@ -1181,7 +1407,7 @@ function useCellSelection({
1181
1407
  },
1182
1408
  [enabled]
1183
1409
  );
1184
- const handleFillHandleMouseDown = (0, import_react2.useCallback)(
1410
+ const handleFillHandleMouseDown = (0, import_react3.useCallback)(
1185
1411
  (rowIndex, colIndex) => {
1186
1412
  if (!enabled) return;
1187
1413
  setDragState((prev) => {
@@ -1198,12 +1424,12 @@ function useCellSelection({
1198
1424
  },
1199
1425
  [enabled]
1200
1426
  );
1201
- (0, import_react2.useEffect)(() => {
1427
+ (0, import_react3.useEffect)(() => {
1202
1428
  if (!enabled) {
1203
1429
  setDragState(INITIAL_DRAG_STATE);
1204
1430
  }
1205
1431
  }, [enabled]);
1206
- (0, import_react2.useEffect)(() => {
1432
+ (0, import_react3.useEffect)(() => {
1207
1433
  if (!enabled) return;
1208
1434
  const handleKeyDown = (e) => {
1209
1435
  if (e.ctrlKey || e.metaKey || e.altKey) return;
@@ -1250,19 +1476,32 @@ function useCellSelection({
1250
1476
  window.addEventListener("keydown", handleKeyDown);
1251
1477
  return () => window.removeEventListener("keydown", handleKeyDown);
1252
1478
  }, [columnCount, enabled, rows]);
1253
- const copySelection = (0, import_react2.useCallback)(
1479
+ const copySelection = (0, import_react3.useCallback)(
1254
1480
  async (options) => {
1255
1481
  if (!enabled || !activeSelectionBounds) return false;
1256
1482
  const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
1257
- return writeSelectionToClipboard(rows, activeSelectionBounds, mode);
1483
+ return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
1484
+ registry: cellRendererRegistry,
1485
+ root: rootRef?.current
1486
+ });
1258
1487
  },
1259
- [activeSelectionBounds, enableSubtreeCopy, enabled, rows]
1488
+ [
1489
+ activeSelectionBounds,
1490
+ cellRendererRegistry,
1491
+ enableSubtreeCopy,
1492
+ enabled,
1493
+ rootRef,
1494
+ rows
1495
+ ]
1260
1496
  );
1261
- (0, import_react2.useEffect)(() => {
1497
+ (0, import_react3.useEffect)(() => {
1262
1498
  if (!enabled) return;
1263
1499
  const handleKeyDown = (e) => {
1264
1500
  if (!activeSelectionBounds) return;
1265
1501
  if (!(e.ctrlKey || e.metaKey)) return;
1502
+ if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1503
+ return;
1504
+ }
1266
1505
  const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
1267
1506
  const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
1268
1507
  if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
@@ -1272,7 +1511,7 @@ function useCellSelection({
1272
1511
  window.addEventListener("keydown", handleKeyDown);
1273
1512
  return () => window.removeEventListener("keydown", handleKeyDown);
1274
1513
  }, [activeSelectionBounds, copySelection, enableSubtreeCopy, enabled]);
1275
- const emitRowsPaste = (0, import_react2.useCallback)(
1514
+ const emitRowsPaste = (0, import_react3.useCallback)(
1276
1515
  (text, mode) => {
1277
1516
  if (!onRowsPaste || !activeSelectionBounds) return false;
1278
1517
  const payload = buildRowsPastePayload(
@@ -1289,7 +1528,7 @@ function useCellSelection({
1289
1528
  },
1290
1529
  [activeSelectionBounds, onRowsPaste, rows]
1291
1530
  );
1292
- (0, import_react2.useEffect)(() => {
1531
+ (0, import_react3.useEffect)(() => {
1293
1532
  if (!enabled || !onRowsPaste) return;
1294
1533
  const pasteHandledRef = { current: false };
1295
1534
  const ignoreNextPasteRef = { current: false };
@@ -1357,7 +1596,7 @@ function useCellSelection({
1357
1596
  enabled,
1358
1597
  onRowsPaste
1359
1598
  ]);
1360
- (0, import_react2.useEffect)(() => {
1599
+ (0, import_react3.useEffect)(() => {
1361
1600
  if (!enabled) return;
1362
1601
  const handleMouseUp = () => {
1363
1602
  setDragState((prev) => {
@@ -1800,7 +2039,7 @@ function collectAncestorKeysToExpand(corpusRow, expandedRows) {
1800
2039
  }
1801
2040
 
1802
2041
  // src/components/ui/table/features/inline-search/useInlineSearch.ts
1803
- var import_react3 = require("react");
2042
+ var import_react4 = require("react");
1804
2043
  var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
1805
2044
  function useInlineSearch({
1806
2045
  enabled = false,
@@ -1817,46 +2056,46 @@ function useInlineSearch({
1817
2056
  onNavigateToResult,
1818
2057
  rootRef
1819
2058
  }) {
1820
- const searchInputId = (0, import_react3.useId)();
1821
- const searchInputRef = (0, import_react3.useRef)(null);
1822
- const [internalShowSearch, setInternalShowSearch] = (0, import_react3.useState)(false);
1823
- const [internalSearchValue, setInternalSearchValue] = (0, import_react3.useState)("");
1824
- const [internalResults, setInternalResults] = (0, import_react3.useState)(
2059
+ const searchInputId = (0, import_react4.useId)();
2060
+ const searchInputRef = (0, import_react4.useRef)(null);
2061
+ const [internalShowSearch, setInternalShowSearch] = (0, import_react4.useState)(false);
2062
+ const [internalSearchValue, setInternalSearchValue] = (0, import_react4.useState)("");
2063
+ const [internalResults, setInternalResults] = (0, import_react4.useState)(
1825
2064
  []
1826
2065
  );
1827
- const [searchStatus, setSearchStatus] = (0, import_react3.useState)();
1828
- const searchStatusRef = (0, import_react3.useRef)(searchStatus);
2066
+ const [searchStatus, setSearchStatus] = (0, import_react4.useState)();
2067
+ const searchStatusRef = (0, import_react4.useRef)(searchStatus);
1829
2068
  searchStatusRef.current = searchStatus;
1830
- const abortControllerRef = (0, import_react3.useRef)(null);
1831
- const searchHandleRef = (0, import_react3.useRef)(void 0);
1832
- const initialStartRowRef = (0, import_react3.useRef)(initialStartRow);
2069
+ const abortControllerRef = (0, import_react4.useRef)(null);
2070
+ const searchHandleRef = (0, import_react4.useRef)(void 0);
2071
+ const initialStartRowRef = (0, import_react4.useRef)(initialStartRow);
1833
2072
  initialStartRowRef.current = initialStartRow;
1834
- const getCellValueRef = (0, import_react3.useRef)(getCellValue);
2073
+ const getCellValueRef = (0, import_react4.useRef)(getCellValue);
1835
2074
  getCellValueRef.current = getCellValue;
1836
2075
  const showSearch = controlledShowSearch ?? internalShowSearch;
1837
2076
  const searchValue = controlledSearchValue ?? internalSearchValue;
1838
2077
  const searchResults = controlledSearchResults ?? internalResults;
1839
- const setSearchValue = (0, import_react3.useCallback)(
2078
+ const setSearchValue = (0, import_react4.useCallback)(
1840
2079
  (value) => {
1841
2080
  setInternalSearchValue(value);
1842
2081
  onSearchValueChange?.(value);
1843
2082
  },
1844
2083
  [onSearchValueChange]
1845
2084
  );
1846
- const cancelSearch = (0, import_react3.useCallback)(() => {
2085
+ const cancelSearch = (0, import_react4.useCallback)(() => {
1847
2086
  if (searchHandleRef.current !== void 0) {
1848
2087
  window.cancelAnimationFrame(searchHandleRef.current);
1849
2088
  searchHandleRef.current = void 0;
1850
2089
  }
1851
2090
  abortControllerRef.current?.abort();
1852
2091
  }, []);
1853
- const emitResultsChanged = (0, import_react3.useCallback)(
2092
+ const emitResultsChanged = (0, import_react4.useCallback)(
1854
2093
  (results, navIndex) => {
1855
2094
  onSearchResultsChanged?.(results, navIndex);
1856
2095
  },
1857
2096
  [onSearchResultsChanged]
1858
2097
  );
1859
- const navigateToIndex = (0, import_react3.useCallback)(
2098
+ const navigateToIndex = (0, import_react4.useCallback)(
1860
2099
  (results, navIndex) => {
1861
2100
  if (onSearchResultsChanged) return;
1862
2101
  if (navIndex < 0 || navIndex >= results.length) return;
@@ -1866,7 +2105,7 @@ function useInlineSearch({
1866
2105
  },
1867
2106
  [onNavigateToResult, onSearchResultsChanged]
1868
2107
  );
1869
- const beginSearch = (0, import_react3.useCallback)(
2108
+ const beginSearch = (0, import_react4.useCallback)(
1870
2109
  (query) => {
1871
2110
  if (controlledSearchResults !== void 0) return;
1872
2111
  const totalRows = rowCount;
@@ -1938,12 +2177,12 @@ function useInlineSearch({
1938
2177
  rowCount
1939
2178
  ]
1940
2179
  );
1941
- const openSearch = (0, import_react3.useCallback)(() => {
2180
+ const openSearch = (0, import_react4.useCallback)(() => {
1942
2181
  if (controlledShowSearch === void 0) {
1943
2182
  setInternalShowSearch(true);
1944
2183
  }
1945
2184
  }, [controlledShowSearch]);
1946
- const closeSearch = (0, import_react3.useCallback)(() => {
2185
+ const closeSearch = (0, import_react4.useCallback)(() => {
1947
2186
  if (controlledShowSearch === void 0) {
1948
2187
  setInternalShowSearch(false);
1949
2188
  }
@@ -1958,7 +2197,7 @@ function useInlineSearch({
1958
2197
  emitResultsChanged,
1959
2198
  onSearchClose
1960
2199
  ]);
1961
- const goToNext = (0, import_react3.useCallback)(() => {
2200
+ const goToNext = (0, import_react4.useCallback)(() => {
1962
2201
  if (!searchStatus || searchStatus.results === 0) return;
1963
2202
  const newIndex = nextSearchIndex(
1964
2203
  searchStatus.selectedIndex,
@@ -1968,7 +2207,7 @@ function useInlineSearch({
1968
2207
  emitResultsChanged(searchResults, newIndex);
1969
2208
  navigateToIndex(searchResults, newIndex);
1970
2209
  }, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
1971
- const goToPrevious = (0, import_react3.useCallback)(() => {
2210
+ const goToPrevious = (0, import_react4.useCallback)(() => {
1972
2211
  if (!searchStatus || searchStatus.results === 0) return;
1973
2212
  const newIndex = previousSearchIndex(
1974
2213
  searchStatus.selectedIndex,
@@ -1978,7 +2217,7 @@ function useInlineSearch({
1978
2217
  emitResultsChanged(searchResults, newIndex);
1979
2218
  navigateToIndex(searchResults, newIndex);
1980
2219
  }, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
1981
- (0, import_react3.useEffect)(() => {
2220
+ (0, import_react4.useEffect)(() => {
1982
2221
  if (controlledSearchResults === void 0) return;
1983
2222
  if (controlledSearchResults.length > 0) {
1984
2223
  setSearchStatus((current) => ({
@@ -1990,7 +2229,7 @@ function useInlineSearch({
1990
2229
  setSearchStatus(void 0);
1991
2230
  }
1992
2231
  }, [controlledSearchResults, rowCount]);
1993
- (0, import_react3.useEffect)(() => {
2232
+ (0, import_react4.useEffect)(() => {
1994
2233
  if (!enabled) return;
1995
2234
  setSearchStatus(void 0);
1996
2235
  setInternalResults([]);
@@ -2003,7 +2242,7 @@ function useInlineSearch({
2003
2242
  cancelSearch();
2004
2243
  }
2005
2244
  }, [enabled, showSearch]);
2006
- (0, import_react3.useEffect)(() => {
2245
+ (0, import_react4.useEffect)(() => {
2007
2246
  if (!enabled || !showSearch) return;
2008
2247
  if (controlledSearchResults !== void 0) return;
2009
2248
  if (searchValue.trim() === "") {
@@ -2023,7 +2262,7 @@ function useInlineSearch({
2023
2262
  searchValue,
2024
2263
  showSearch
2025
2264
  ]);
2026
- (0, import_react3.useEffect)(() => {
2265
+ (0, import_react4.useEffect)(() => {
2027
2266
  if (!enabled) return;
2028
2267
  const handleKeyDown = (event) => {
2029
2268
  if (!(event.ctrlKey || event.metaKey)) return;
@@ -2050,12 +2289,12 @@ function useInlineSearch({
2050
2289
  window.addEventListener("keydown", handleKeyDown, true);
2051
2290
  return () => window.removeEventListener("keydown", handleKeyDown, true);
2052
2291
  }, [controlledShowSearch, enabled, rootRef, showSearch]);
2053
- (0, import_react3.useEffect)(() => () => cancelSearch(), [cancelSearch]);
2054
- const searchMatchKeys = (0, import_react3.useMemo)(
2292
+ (0, import_react4.useEffect)(() => () => cancelSearch(), [cancelSearch]);
2293
+ const searchMatchKeys = (0, import_react4.useMemo)(
2055
2294
  () => buildSearchMatchKeys(searchResults),
2056
2295
  [searchResults]
2057
2296
  );
2058
- const activeMatch = (0, import_react3.useMemo)(() => {
2297
+ const activeMatch = (0, import_react4.useMemo)(() => {
2059
2298
  if (!searchStatus || searchStatus.selectedIndex < 0) return null;
2060
2299
  return searchResults[searchStatus.selectedIndex] ?? null;
2061
2300
  }, [searchResults, searchStatus]);
@@ -2098,7 +2337,7 @@ function useInlineSearch({
2098
2337
  }
2099
2338
 
2100
2339
  // src/components/ui/table/features/row-expand/row-expand.ts
2101
- var import_react4 = require("react");
2340
+ var import_react5 = require("react");
2102
2341
  function getFieldValue(row, key) {
2103
2342
  return row[key];
2104
2343
  }
@@ -2128,12 +2367,12 @@ var useConvertTreeData = ({
2128
2367
  expandedRows,
2129
2368
  onExpandedRowsChange
2130
2369
  }) => {
2131
- const onExpandedRowsChangeRef = (0, import_react4.useRef)(onExpandedRowsChange);
2132
- const hasInitializedRef = (0, import_react4.useRef)(false);
2133
- (0, import_react4.useEffect)(() => {
2370
+ const onExpandedRowsChangeRef = (0, import_react5.useRef)(onExpandedRowsChange);
2371
+ const hasInitializedRef = (0, import_react5.useRef)(false);
2372
+ (0, import_react5.useEffect)(() => {
2134
2373
  onExpandedRowsChangeRef.current = onExpandedRowsChange;
2135
2374
  }, [onExpandedRowsChange]);
2136
- (0, import_react4.useEffect)(() => {
2375
+ (0, import_react5.useEffect)(() => {
2137
2376
  if (!data || data.length === 0) {
2138
2377
  hasInitializedRef.current = false;
2139
2378
  return;
@@ -2143,7 +2382,7 @@ var useConvertTreeData = ({
2143
2382
  onExpandedRowsChangeRef.current?.(new Set(ids));
2144
2383
  hasInitializedRef.current = true;
2145
2384
  }, [enabled, data, toggleField]);
2146
- const processedData = (0, import_react4.useMemo)(() => {
2385
+ const processedData = (0, import_react5.useMemo)(() => {
2147
2386
  if (!enabled || !data || data.length === 0) return [];
2148
2387
  const flattenedData = [];
2149
2388
  const flattenItems = (items) => {
@@ -2207,7 +2446,7 @@ var useConvertTreeData = ({
2207
2446
  });
2208
2447
  return rootItems;
2209
2448
  }, [enabled, data, toggleField, childField, flattenField]);
2210
- const flattenTree = (0, import_react4.useMemo)(() => {
2449
+ const flattenTree = (0, import_react5.useMemo)(() => {
2211
2450
  if (!enabled) return [];
2212
2451
  const flatten = (nodes, result = [], level = 0) => {
2213
2452
  nodes.forEach((node, index) => {
@@ -2257,7 +2496,7 @@ var useConvertTreeData = ({
2257
2496
  preventExpand,
2258
2497
  expandedRows
2259
2498
  ]);
2260
- const sortedData = (0, import_react4.useMemo)(() => {
2499
+ const sortedData = (0, import_react5.useMemo)(() => {
2261
2500
  if (!enabled) {
2262
2501
  return data ?? [];
2263
2502
  }
@@ -2484,7 +2723,7 @@ function useGlideTable(options) {
2484
2723
  searchResults,
2485
2724
  onSearchResultsChanged
2486
2725
  } = options;
2487
- const labels = (0, import_react5.useMemo)(() => {
2726
+ const labels = (0, import_react6.useMemo)(() => {
2488
2727
  const resolved = resolveDataTableLabels(labelsProp);
2489
2728
  return {
2490
2729
  ...resolved,
@@ -2495,17 +2734,21 @@ function useGlideTable(options) {
2495
2734
  }, [labelsProp, emptyText, loadingText, selectionLabel]);
2496
2735
  const enableExpand = Boolean(toggleField);
2497
2736
  const resolvedEnableSubtreeCopy = enableSubtreeCopy ?? enableExpand;
2498
- const [internalRowSelection, setInternalRowSelection] = (0, import_react5.useState)({});
2499
- const [internalColumnSizing, setInternalColumnSizing] = (0, import_react5.useState)({});
2500
- const [internalColumnOrder, setInternalColumnOrder] = (0, import_react5.useState)([]);
2501
- const [internalExpandedRows, setInternalExpandedRows] = (0, import_react5.useState)(
2737
+ const [internalRowSelection, setInternalRowSelection] = (0, import_react6.useState)({});
2738
+ const [internalColumnSizing, setInternalColumnSizing] = (0, import_react6.useState)({});
2739
+ const [internalColumnOrder, setInternalColumnOrder] = (0, import_react6.useState)([]);
2740
+ const [internalExpandedRows, setInternalExpandedRows] = (0, import_react6.useState)(
2502
2741
  () => /* @__PURE__ */ new Set()
2503
2742
  );
2504
- const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react5.useState)(null);
2505
- const scrollRef = (0, import_react5.useRef)(null);
2506
- const rootRef = (0, import_react5.useRef)(null);
2743
+ const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
2744
+ const scrollRef = (0, import_react6.useRef)(null);
2745
+ const rootRef = (0, import_react6.useRef)(null);
2746
+ const cellRendererRegistry = (0, import_react6.useMemo)(
2747
+ () => createCellRendererRegistry(cellRenderers),
2748
+ [cellRenderers]
2749
+ );
2507
2750
  const shouldVirtualize = enableVirtualization && !enableRowSpan;
2508
- (0, import_react5.useEffect)(() => {
2751
+ (0, import_react6.useEffect)(() => {
2509
2752
  if (enableVirtualization && enableRowSpan) {
2510
2753
  console.warn(
2511
2754
  "[useGlideTable] enableRowSpan is on; virtualization is disabled to preserve cell merges."
@@ -2519,11 +2762,11 @@ function useGlideTable(options) {
2519
2762
  );
2520
2763
  const columnSizing = controlledColumnSizing ?? internalColumnSizing;
2521
2764
  const columnOrder = controlledColumnOrder ?? internalColumnOrder;
2522
- const tableColumns = (0, import_react5.useMemo)(() => {
2765
+ const tableColumns = (0, import_react6.useMemo)(() => {
2523
2766
  if (!enableColumnReorder) return columns;
2524
2767
  return applyLeafColumnOrder(columns, columnOrder);
2525
2768
  }, [columnOrder, columns, enableColumnReorder]);
2526
- const setColumnOrder = (0, import_react5.useCallback)(
2769
+ const setColumnOrder = (0, import_react6.useCallback)(
2527
2770
  (next) => {
2528
2771
  if (onColumnOrderChange) {
2529
2772
  onColumnOrderChange(next);
@@ -2534,7 +2777,7 @@ function useGlideTable(options) {
2534
2777
  [onColumnOrderChange]
2535
2778
  );
2536
2779
  const expandedRows = controlledExpandedRows ?? internalExpandedRows;
2537
- const handleExpandedRowsChange = (0, import_react5.useCallback)(
2780
+ const handleExpandedRowsChange = (0, import_react6.useCallback)(
2538
2781
  (next) => {
2539
2782
  if (onExpandedRowsChange) {
2540
2783
  onExpandedRowsChange(next);
@@ -2595,13 +2838,13 @@ function useGlideTable(options) {
2595
2838
  getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
2596
2839
  getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (_originalRow, index) => String(index)
2597
2840
  });
2598
- const rowSpanColumnKeys = (0, import_react5.useMemo)(() => {
2841
+ const rowSpanColumnKeys = (0, import_react6.useMemo)(() => {
2599
2842
  if (!enableRowSpan) return [];
2600
2843
  return collectRowSpanColumns(columns);
2601
2844
  }, [enableRowSpan, columns]);
2602
2845
  const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
2603
2846
  const primaryRowSpanColumnId = rowSpanColumnKeys[0]?.columnId;
2604
- const columnRowSpanMap = (0, import_react5.useMemo)(
2847
+ const columnRowSpanMap = (0, import_react6.useMemo)(
2605
2848
  () => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
2606
2849
  [tableData, rowSpanColumnKeys]
2607
2850
  );
@@ -2610,7 +2853,7 @@ function useGlideTable(options) {
2610
2853
  const rows = table.getRowModel().rows;
2611
2854
  const columnCount = table.getAllLeafColumns().length || 1;
2612
2855
  const visibleLeafColumns = table.getVisibleLeafColumns();
2613
- const columnFreezeOffsets = (0, import_react5.useMemo)(() => {
2856
+ const columnFreezeOffsets = (0, import_react6.useMemo)(() => {
2614
2857
  if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
2615
2858
  return buildColumnFreezeOffsets(
2616
2859
  visibleLeafColumns.map((column) => ({
@@ -2630,14 +2873,14 @@ function useGlideTable(options) {
2630
2873
  const totalSize = rowVirtualizer.getTotalSize();
2631
2874
  const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
2632
2875
  const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
2633
- const selectedRowIndices = (0, import_react5.useMemo)(() => {
2876
+ const selectedRowIndices = (0, import_react6.useMemo)(() => {
2634
2877
  const indices = /* @__PURE__ */ new Set();
2635
2878
  for (const selectedRow of selectedRows) {
2636
2879
  indices.add(selectedRow.index);
2637
2880
  }
2638
2881
  return indices;
2639
2882
  }, [selectedRows]);
2640
- const scrollCellIntoView = (0, import_react5.useCallback)(
2883
+ const scrollCellIntoView = (0, import_react6.useCallback)(
2641
2884
  (rowIndex, colIndex, options2) => {
2642
2885
  const align = options2?.align ?? "nearest";
2643
2886
  const blockAlign = align === "center" ? "center" : "nearest";
@@ -2664,7 +2907,7 @@ function useGlideTable(options) {
2664
2907
  },
2665
2908
  [rowVirtualizer, shouldVirtualize]
2666
2909
  );
2667
- const handleCellNavigate = (0, import_react5.useCallback)(
2910
+ const handleCellNavigate = (0, import_react6.useCallback)(
2668
2911
  (position) => {
2669
2912
  scrollCellIntoView(position.row, position.col, { align: "nearest" });
2670
2913
  },
@@ -2687,7 +2930,9 @@ function useGlideTable(options) {
2687
2930
  onDataChange,
2688
2931
  onBatchChange,
2689
2932
  onRowsPaste,
2690
- onCellNavigate: handleCellNavigate
2933
+ onCellNavigate: handleCellNavigate,
2934
+ cellRendererRegistry,
2935
+ rootRef
2691
2936
  });
2692
2937
  const {
2693
2938
  editingCell,
@@ -2697,11 +2942,7 @@ function useGlideTable(options) {
2697
2942
  commitEdit,
2698
2943
  cancelEdit
2699
2944
  } = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
2700
- const cellRendererRegistry = (0, import_react5.useMemo)(
2701
- () => createCellRendererRegistry(cellRenderers),
2702
- [cellRenderers]
2703
- );
2704
- const commitRenderedCellValue = (0, import_react5.useCallback)(
2945
+ const commitRenderedCellValue = (0, import_react6.useCallback)(
2705
2946
  (rowId, columnId, value) => commitCellValue({
2706
2947
  data: tableData,
2707
2948
  rows,
@@ -2713,11 +2954,11 @@ function useGlideTable(options) {
2713
2954
  }),
2714
2955
  [onCellChange, onDataChange, rows, tableData]
2715
2956
  );
2716
- const getCellContext = (0, import_react5.useCallback)(
2957
+ const getCellContext = (0, import_react6.useCallback)(
2717
2958
  (cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
2718
2959
  [commitRenderedCellValue]
2719
2960
  );
2720
- const handleCellMouseDownWithCommit = (0, import_react5.useCallback)(
2961
+ const handleCellMouseDownWithCommit = (0, import_react6.useCallback)(
2721
2962
  (rowIndex, colIndex, options2) => {
2722
2963
  const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
2723
2964
  if (editingCell && !isSameEditingCell && !commitEdit()) {
@@ -2727,7 +2968,7 @@ function useGlideTable(options) {
2727
2968
  },
2728
2969
  [commitEdit, editingCell, handleCellMouseDown]
2729
2970
  );
2730
- const navigateToSearchResult = (0, import_react5.useCallback)(
2971
+ const navigateToSearchResult = (0, import_react6.useCallback)(
2731
2972
  (item) => {
2732
2973
  const [colIndex, rowIndex] = item;
2733
2974
  handleCellMouseDownWithCommit(rowIndex, colIndex);
@@ -2735,7 +2976,7 @@ function useGlideTable(options) {
2735
2976
  },
2736
2977
  [handleCellMouseDownWithCommit, scrollCellIntoView]
2737
2978
  );
2738
- const resolveSearchRowId = (0, import_react5.useCallback)(
2979
+ const resolveSearchRowId = (0, import_react6.useCallback)(
2739
2980
  (row, index) => {
2740
2981
  if (getRowId) return getRowId(row, index);
2741
2982
  if (enableExpand) {
@@ -2759,7 +3000,7 @@ function useGlideTable(options) {
2759
3000
  },
2760
3001
  [enableExpand, getRowId, toggleField]
2761
3002
  );
2762
- const searchCorpus = (0, import_react5.useMemo)(() => {
3003
+ const searchCorpus = (0, import_react6.useMemo)(() => {
2763
3004
  if (!enableInlineSearch) return [];
2764
3005
  if (enableExpand && toggleField) {
2765
3006
  return buildTreeSearchCorpus(tableData, {
@@ -2775,16 +3016,16 @@ function useGlideTable(options) {
2775
3016
  tableData,
2776
3017
  toggleField
2777
3018
  ]);
2778
- const searchCorpusRef = (0, import_react5.useRef)(searchCorpus);
3019
+ const searchCorpusRef = (0, import_react6.useRef)(searchCorpus);
2779
3020
  searchCorpusRef.current = searchCorpus;
2780
- const visibleRowIndexById = (0, import_react5.useMemo)(() => {
3021
+ const visibleRowIndexById = (0, import_react6.useMemo)(() => {
2781
3022
  const map = /* @__PURE__ */ new Map();
2782
3023
  for (const row of rows) {
2783
3024
  map.set(resolveSearchRowId(row.original, row.index), row.index);
2784
3025
  }
2785
3026
  return map;
2786
3027
  }, [resolveSearchRowId, rows]);
2787
- const getSearchCellValue = (0, import_react5.useCallback)(
3028
+ const getSearchCellValue = (0, import_react6.useCallback)(
2788
3029
  (rowIndex, colIndex) => {
2789
3030
  const corpusRow = searchCorpusRef.current[rowIndex];
2790
3031
  const column = visibleLeafColumns[colIndex];
@@ -2807,14 +3048,14 @@ function useGlideTable(options) {
2807
3048
  },
2808
3049
  [rows, visibleLeafColumns, visibleRowIndexById]
2809
3050
  );
2810
- const pendingSearchNavRef = (0, import_react5.useRef)(null);
2811
- const focusSearchResult = (0, import_react5.useCallback)(
3051
+ const pendingSearchNavRef = (0, import_react6.useRef)(null);
3052
+ const focusSearchResult = (0, import_react6.useCallback)(
2812
3053
  (colIndex, visibleRowIndex) => {
2813
3054
  navigateToSearchResult([colIndex, visibleRowIndex]);
2814
3055
  },
2815
3056
  [navigateToSearchResult]
2816
3057
  );
2817
- const navigateToCorpusSearchResult = (0, import_react5.useCallback)(
3058
+ const navigateToCorpusSearchResult = (0, import_react6.useCallback)(
2818
3059
  (item) => {
2819
3060
  const [colIndex, corpusRowIndex] = item;
2820
3061
  const corpusRow = searchCorpusRef.current[corpusRowIndex];
@@ -2847,7 +3088,7 @@ function useGlideTable(options) {
2847
3088
  visibleRowIndexById
2848
3089
  ]
2849
3090
  );
2850
- (0, import_react5.useEffect)(() => {
3091
+ (0, import_react6.useEffect)(() => {
2851
3092
  const pending = pendingSearchNavRef.current;
2852
3093
  if (!pending) return;
2853
3094
  const visibleRowIndex = visibleRowIndexById.get(pending.rowId);
@@ -2871,7 +3112,7 @@ function useGlideTable(options) {
2871
3112
  onNavigateToResult: navigateToCorpusSearchResult,
2872
3113
  rootRef
2873
3114
  });
2874
- const visibleSearchMatchKeys = (0, import_react5.useMemo)(() => {
3115
+ const visibleSearchMatchKeys = (0, import_react6.useMemo)(() => {
2875
3116
  if (!enableInlineSearch) return EMPTY_SEARCH_MATCH_KEYS;
2876
3117
  return mapSearchResultsToVisibleKeys(
2877
3118
  inlineSearch.searchResults,
@@ -2884,7 +3125,7 @@ function useGlideTable(options) {
2884
3125
  searchCorpus,
2885
3126
  visibleRowIndexById
2886
3127
  ]);
2887
- const visibleActiveMatch = (0, import_react5.useMemo)(() => {
3128
+ const visibleActiveMatch = (0, import_react6.useMemo)(() => {
2888
3129
  if (!enableInlineSearch || !inlineSearch.activeMatch) return null;
2889
3130
  return mapSearchResultToVisibleItem(
2890
3131
  inlineSearch.activeMatch,
@@ -2897,13 +3138,13 @@ function useGlideTable(options) {
2897
3138
  searchCorpus,
2898
3139
  visibleRowIndexById
2899
3140
  ]);
2900
- const clearHover = (0, import_react5.useCallback)(() => {
3141
+ const clearHover = (0, import_react6.useCallback)(() => {
2901
3142
  setHoveredRowIndex(null);
2902
3143
  }, []);
2903
- const handleRowHover = (0, import_react5.useCallback)((rowIndex, _rowData) => {
3144
+ const handleRowHover = (0, import_react6.useCallback)((rowIndex, _rowData) => {
2904
3145
  setHoveredRowIndex(rowIndex);
2905
3146
  }, []);
2906
- const handleToggleSelect = (0, import_react5.useCallback)(
3147
+ const handleToggleSelect = (0, import_react6.useCallback)(
2907
3148
  (row) => {
2908
3149
  if (!row.getCanSelect()) return;
2909
3150
  if (preserveRowSelection && row.getIsSelected()) {
@@ -2913,14 +3154,14 @@ function useGlideTable(options) {
2913
3154
  },
2914
3155
  [preserveRowSelection]
2915
3156
  );
2916
- const handleToggleExpand = (0, import_react5.useCallback)(
3157
+ const handleToggleExpand = (0, import_react6.useCallback)(
2917
3158
  (rowKey) => {
2918
3159
  if (preventExpand) return;
2919
3160
  handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
2920
3161
  },
2921
3162
  [preventExpand, handleExpandedRowsChange, expandedRows]
2922
3163
  );
2923
- const rowContextValue = (0, import_react5.useMemo)(() => {
3164
+ const rowContextValue = (0, import_react6.useMemo)(() => {
2924
3165
  return {
2925
3166
  rowSpan: {
2926
3167
  enableRowSpan,
@@ -3019,12 +3260,12 @@ function useGlideTable(options) {
3019
3260
  visibleSearchMatchKeys,
3020
3261
  visibleActiveMatch
3021
3262
  ]);
3022
- const copySelectionRef = (0, import_react5.useRef)(copySelection);
3023
- (0, import_react5.useEffect)(() => {
3263
+ const copySelectionRef = (0, import_react6.useRef)(copySelection);
3264
+ (0, import_react6.useEffect)(() => {
3024
3265
  copySelectionRef.current = copySelection;
3025
3266
  }, [copySelection]);
3026
- const stableCopySelection = (0, import_react5.useCallback)((options2) => copySelectionRef.current(options2), []);
3027
- (0, import_react5.useEffect)(() => {
3267
+ const stableCopySelection = (0, import_react6.useCallback)((options2) => copySelectionRef.current(options2), []);
3268
+ (0, import_react6.useEffect)(() => {
3028
3269
  onCopyActionsReady?.({ copySelection: stableCopySelection });
3029
3270
  }, [onCopyActionsReady, stableCopySelection]);
3030
3271
  return {
@@ -3073,16 +3314,18 @@ function useGlideTable(options) {
3073
3314
  }
3074
3315
 
3075
3316
  // src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
3076
- var import_react7 = require("react");
3317
+ var import_react8 = require("react");
3077
3318
 
3078
3319
  // src/components/ui/table/DataTableContext.tsx
3079
- var import_react6 = require("react");
3320
+ var import_react7 = require("react");
3080
3321
  var import_jsx_runtime2 = require("react/jsx-runtime");
3081
- var DataTableContext = (0, import_react6.createContext)(null);
3322
+ var DataTableContext = (0, import_react7.createContext)(null);
3082
3323
  function useDataTableRowContext() {
3083
- const context = (0, import_react6.use)(DataTableContext);
3324
+ const context = (0, import_react7.use)(DataTableContext);
3084
3325
  if (!context) {
3085
- throw new Error("useDataTableRowContext must be used within a DataTableContextProvider");
3326
+ throw new Error(
3327
+ "useDataTableRowContext must be used within a DataTableContextProvider"
3328
+ );
3086
3329
  }
3087
3330
  return context;
3088
3331
  }
@@ -3096,7 +3339,7 @@ function ResolvedTableCell({
3096
3339
  const meta = column.columnDef.meta;
3097
3340
  const value = getValue();
3098
3341
  const columnId = column.id;
3099
- const update = (0, import_react7.useCallback)(
3342
+ const update = (0, import_react8.useCallback)(
3100
3343
  (next) => {
3101
3344
  cellRender.commitValue(row.id, columnId, next);
3102
3345
  },
@@ -3121,20 +3364,144 @@ function ResolvedTableCell({
3121
3364
  }
3122
3365
 
3123
3366
  // src/components/ui/table/features/column-resize/columnResize.ts
3367
+ function clamp(value, min, max) {
3368
+ return Math.min(Math.max(value, min), max);
3369
+ }
3370
+ function floorOf(column) {
3371
+ return column.minWidth ?? 0;
3372
+ }
3373
+ function ceilOf(column) {
3374
+ return column.maxWidth ?? Number.POSITIVE_INFINITY;
3375
+ }
3376
+ function preferOf(column) {
3377
+ const floor = floorOf(column);
3378
+ const ceil = ceilOf(column);
3379
+ const preferred = column.maxWidth ?? column.minWidth ?? 0;
3380
+ return clamp(preferred, floor, Number.isFinite(ceil) ? ceil : preferred);
3381
+ }
3382
+ function resolveColumnLayoutWidths(containerWidth, columns) {
3383
+ const widths = /* @__PURE__ */ new Map();
3384
+ const fixed = [];
3385
+ const bounded = [];
3386
+ let flexCount = 0;
3387
+ for (const column of columns) {
3388
+ if (column.width != null) {
3389
+ fixed.push(column);
3390
+ } else if (column.minWidth != null || column.maxWidth != null) {
3391
+ bounded.push(column);
3392
+ } else {
3393
+ flexCount += 1;
3394
+ }
3395
+ }
3396
+ let used = 0;
3397
+ for (const column of fixed) {
3398
+ let size = column.width;
3399
+ if (column.minWidth != null) size = Math.max(size, column.minWidth);
3400
+ if (column.maxWidth != null) size = Math.min(size, column.maxWidth);
3401
+ widths.set(column.id, size);
3402
+ used += size;
3403
+ }
3404
+ if (bounded.length === 0) {
3405
+ return widths;
3406
+ }
3407
+ const boundedSizes = /* @__PURE__ */ new Map();
3408
+ let preferredSum = 0;
3409
+ let floorSum = 0;
3410
+ for (const column of bounded) {
3411
+ const preferred = preferOf(column);
3412
+ boundedSizes.set(column.id, preferred);
3413
+ preferredSum += preferred;
3414
+ floorSum += floorOf(column);
3415
+ }
3416
+ if (containerWidth > 0) {
3417
+ const remaining = Math.max(0, containerWidth - used);
3418
+ if (remaining >= preferredSum) {
3419
+ } else if (remaining >= floorSum) {
3420
+ let deficit = preferredSum - remaining;
3421
+ const open = bounded.map((column) => ({
3422
+ id: column.id,
3423
+ current: boundedSizes.get(column.id),
3424
+ floor: floorOf(column)
3425
+ }));
3426
+ while (deficit >= 1) {
3427
+ const shrinkable = open.filter((entry) => entry.current > entry.floor);
3428
+ if (shrinkable.length === 0) break;
3429
+ const portion = Math.floor(deficit / shrinkable.length);
3430
+ const rem = deficit % shrinkable.length;
3431
+ let consumed = 0;
3432
+ for (let index = 0; index < shrinkable.length; index += 1) {
3433
+ const entry = shrinkable[index];
3434
+ const reduce = Math.min(
3435
+ entry.current - entry.floor,
3436
+ portion + (index < rem ? 1 : 0)
3437
+ );
3438
+ entry.current -= reduce;
3439
+ consumed += reduce;
3440
+ }
3441
+ if (consumed === 0) break;
3442
+ deficit -= consumed;
3443
+ }
3444
+ for (const entry of open) {
3445
+ boundedSizes.set(entry.id, entry.current);
3446
+ }
3447
+ } else {
3448
+ for (const column of bounded) {
3449
+ boundedSizes.set(column.id, floorOf(column));
3450
+ }
3451
+ }
3452
+ }
3453
+ for (const [id, size] of boundedSizes) {
3454
+ widths.set(id, Math.round(size));
3455
+ }
3456
+ return widths;
3457
+ }
3124
3458
  function getColumnSizeStyle(size, options) {
3125
- const { force = false, lockMax = false } = options ?? {};
3126
- if (!force && size === DATA_TABLE_COLUMN_SIZE) {
3459
+ const {
3460
+ force = false,
3461
+ lockMax = false,
3462
+ minWidth,
3463
+ maxWidth,
3464
+ layoutWidth
3465
+ } = options ?? {};
3466
+ if (lockMax) {
3467
+ return {
3468
+ width: size,
3469
+ minWidth: size,
3470
+ maxWidth: size
3471
+ };
3472
+ }
3473
+ if (layoutWidth != null) {
3474
+ return {
3475
+ width: layoutWidth,
3476
+ minWidth: layoutWidth,
3477
+ maxWidth: layoutWidth
3478
+ };
3479
+ }
3480
+ const resolvedSize = size;
3481
+ const hasExplicitSize = force || size !== DATA_TABLE_COLUMN_SIZE;
3482
+ if (!hasExplicitSize && minWidth == null && maxWidth == null) {
3127
3483
  return void 0;
3128
3484
  }
3129
- return {
3130
- width: size,
3131
- minWidth: size,
3132
- ...lockMax ? { maxWidth: size } : {}
3133
- };
3485
+ const style = {};
3486
+ if (hasExplicitSize) {
3487
+ const used = minWidth != null || maxWidth != null ? clamp(
3488
+ resolvedSize,
3489
+ minWidth ?? Number.NEGATIVE_INFINITY,
3490
+ maxWidth ?? Number.POSITIVE_INFINITY
3491
+ ) : resolvedSize;
3492
+ style.width = used;
3493
+ style.minWidth = minWidth ?? used;
3494
+ } else if (minWidth != null) {
3495
+ style.minWidth = minWidth;
3496
+ }
3497
+ if (maxWidth != null) {
3498
+ style.maxWidth = maxWidth;
3499
+ }
3500
+ return style;
3134
3501
  }
3135
3502
 
3136
3503
  // src/components/ui/table/features/column-reorder/useColumnReorder.ts
3137
- var import_react8 = require("react");
3504
+ var import_react9 = require("react");
3138
3505
  function hitTestReorderHeader(table, clientX, clientY) {
3139
3506
  const headers = Array.from(
3140
3507
  table.querySelectorAll(
@@ -3182,19 +3549,19 @@ function readTargetIds(table, columnId) {
3182
3549
  }
3183
3550
  function useColumnReorder(options) {
3184
3551
  const { enabled, columnOrder, onColumnOrderChange } = options;
3185
- const sessionRef = (0, import_react8.useRef)(null);
3186
- const columnOrderRef = (0, import_react8.useRef)(columnOrder);
3187
- const onColumnOrderChangeRef = (0, import_react8.useRef)(onColumnOrderChange);
3188
- const [draggingColumnId, setDraggingColumnId] = (0, import_react8.useState)(null);
3189
- const [dropTarget, setDropTarget] = (0, import_react8.useState)(
3552
+ const sessionRef = (0, import_react9.useRef)(null);
3553
+ const columnOrderRef = (0, import_react9.useRef)(columnOrder);
3554
+ const onColumnOrderChangeRef = (0, import_react9.useRef)(onColumnOrderChange);
3555
+ const [draggingColumnId, setDraggingColumnId] = (0, import_react9.useState)(null);
3556
+ const [dropTarget, setDropTarget] = (0, import_react9.useState)(
3190
3557
  null
3191
3558
  );
3192
- const dropTargetRef = (0, import_react8.useRef)(dropTarget);
3193
- const previousUserSelectRef = (0, import_react8.useRef)(null);
3559
+ const dropTargetRef = (0, import_react9.useRef)(dropTarget);
3560
+ const previousUserSelectRef = (0, import_react9.useRef)(null);
3194
3561
  columnOrderRef.current = columnOrder;
3195
3562
  onColumnOrderChangeRef.current = onColumnOrderChange;
3196
3563
  dropTargetRef.current = dropTarget;
3197
- const resetDrag = (0, import_react8.useCallback)(() => {
3564
+ const resetDrag = (0, import_react9.useCallback)(() => {
3198
3565
  sessionRef.current = null;
3199
3566
  setDraggingColumnId(null);
3200
3567
  setDropTarget(null);
@@ -3210,15 +3577,15 @@ function useColumnReorder(options) {
3210
3577
  }
3211
3578
  document.body.style.removeProperty("user-select");
3212
3579
  }, []);
3213
- (0, import_react8.useEffect)(() => {
3580
+ (0, import_react9.useEffect)(() => {
3214
3581
  if (!enabled) resetDrag();
3215
3582
  }, [enabled, resetDrag]);
3216
- (0, import_react8.useEffect)(() => {
3583
+ (0, import_react9.useEffect)(() => {
3217
3584
  return () => {
3218
3585
  resetDrag();
3219
3586
  };
3220
3587
  }, [resetDrag]);
3221
- const onHeaderPointerDown = (0, import_react8.useCallback)(
3588
+ const onHeaderPointerDown = (0, import_react9.useCallback)(
3222
3589
  (event, meta) => {
3223
3590
  if (!enabled || !meta.canDrag) return;
3224
3591
  if (event.button !== 0) return;
@@ -3241,7 +3608,7 @@ function useColumnReorder(options) {
3241
3608
  },
3242
3609
  [enabled]
3243
3610
  );
3244
- (0, import_react8.useEffect)(() => {
3611
+ (0, import_react9.useEffect)(() => {
3245
3612
  if (!enabled) return;
3246
3613
  const onPointerMove = (event) => {
3247
3614
  const session = sessionRef.current;
@@ -3402,6 +3769,7 @@ function useColumnReorder(options) {
3402
3769
  previousSearchIndex,
3403
3770
  resolveCellRenderer,
3404
3771
  resolveColumnFreezeSide,
3772
+ resolveColumnLayoutWidths,
3405
3773
  resolveDataTableLabels,
3406
3774
  resolveDropEdge,
3407
3775
  resolveHeaderFreezeOffset,