react-glide-table 2.0.2 → 2.2.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
@@ -31,6 +31,7 @@ __export(core_exports, {
31
31
  ResolvedTableCell: () => ResolvedTableCell,
32
32
  applyCellEdit: () => applyCellEdit,
33
33
  applyFillData: () => applyFillData,
34
+ applyLeafColumnOrder: () => applyLeafColumnOrder,
34
35
  applySelectionUpdater: () => applySelectionUpdater,
35
36
  buildColumnFreezeOffsets: () => buildColumnFreezeOffsets,
36
37
  buildColumnRowSpanMap: () => buildColumnRowSpanMap,
@@ -45,6 +46,7 @@ __export(core_exports, {
45
46
  collectCopyRowEntries: () => collectCopyRowEntries,
46
47
  collectCopyRows: () => collectCopyRows,
47
48
  collectFillChanges: () => collectFillChanges,
49
+ collectLeafColumnIds: () => collectLeafColumnIds,
48
50
  collectRowSpanColumns: () => collectRowSpanColumns,
49
51
  collectSearchMatchesInRange: () => collectSearchMatchesInRange,
50
52
  commitCellValue: () => commitCellValue,
@@ -69,6 +71,7 @@ __export(core_exports, {
69
71
  mapSearchResultToVisibleItem: () => mapSearchResultToVisibleItem,
70
72
  mapSearchResultsToVisibleKeys: () => mapSearchResultsToVisibleKeys,
71
73
  measureMergedSpanRowHeights: () => measureMergedSpanRowHeights,
74
+ moveColumnIds: () => moveColumnIds,
72
75
  nextSearchIndex: () => nextSearchIndex,
73
76
  nextSearchStride: () => nextSearchStride,
74
77
  parseCellEditValue: () => parseCellEditValue,
@@ -78,7 +81,9 @@ __export(core_exports, {
78
81
  resolveCellRenderer: () => resolveCellRenderer,
79
82
  resolveColumnFreezeSide: () => resolveColumnFreezeSide,
80
83
  resolveDataTableLabels: () => resolveDataTableLabels,
84
+ resolveDropEdge: () => resolveDropEdge,
81
85
  resolveHeaderFreezeOffset: () => resolveHeaderFreezeOffset,
86
+ resolveLeafColumnOrder: () => resolveLeafColumnOrder,
82
87
  resolvePasteColumnIds: () => resolvePasteColumnIds,
83
88
  resolveRowSelection: () => resolveRowSelection,
84
89
  resolveRowSpanAt: () => resolveRowSpanAt,
@@ -88,6 +93,7 @@ __export(core_exports, {
88
93
  toggleExpandedRowId: () => toggleExpandedRowId,
89
94
  useCellEdit: () => useCellEdit,
90
95
  useCellSelection: () => useCellSelection,
96
+ useColumnReorder: () => useColumnReorder,
91
97
  useConvertTreeData: () => useConvertTreeData,
92
98
  useGlideTable: () => useGlideTable,
93
99
  useInlineSearch: () => useInlineSearch,
@@ -104,6 +110,7 @@ var DEFAULT_DATA_TABLE_LABELS = {
104
110
  expandRow: "Expand row",
105
111
  collapseRow: "Collapse row",
106
112
  resizeColumn: "Resize column",
113
+ reorderColumn: "Reorder column",
107
114
  searchPlaceholder: "Search\u2026",
108
115
  searchResultHint: "Type to search",
109
116
  searchPrevious: "Previous result",
@@ -134,6 +141,7 @@ var DATA_TABLE_VIRTUAL_OVERSCAN = 8;
134
141
  var DATA_TABLE_COLUMN_SIZE = 150;
135
142
  var DATA_TABLE_COLUMN_MIN_SIZE = 40;
136
143
  var DATA_TABLE_COLUMN_MAX_SIZE = 800;
144
+ var DATA_TABLE_COLUMN_REORDER_THRESHOLD = 4;
137
145
 
138
146
  // src/components/ui/table/features/cell-edit/useCellEdit.ts
139
147
  var import_react = require("react");
@@ -1399,6 +1407,129 @@ function useCellSelection({
1399
1407
  };
1400
1408
  }
1401
1409
 
1410
+ // src/components/ui/table/features/column-reorder/columnReorder.ts
1411
+ function getColumnDefId(column) {
1412
+ if (column.id != null && column.id !== "") return column.id;
1413
+ if ("accessorKey" in column && column.accessorKey != null) {
1414
+ return String(column.accessorKey);
1415
+ }
1416
+ return void 0;
1417
+ }
1418
+ function getColumnDefChildren(column) {
1419
+ if (!("columns" in column) || !Array.isArray(column.columns)) return void 0;
1420
+ if (column.columns.length === 0) return void 0;
1421
+ return column.columns;
1422
+ }
1423
+ function collectLeafColumnIds(columns) {
1424
+ const ids = [];
1425
+ for (const column of columns) {
1426
+ const children = getColumnDefChildren(column);
1427
+ if (children) {
1428
+ ids.push(...collectLeafColumnIds(children));
1429
+ continue;
1430
+ }
1431
+ const id = getColumnDefId(column);
1432
+ if (id) ids.push(id);
1433
+ }
1434
+ return ids;
1435
+ }
1436
+ function areColumnOrdersEqual(left, right) {
1437
+ if (left.length !== right.length) return false;
1438
+ return left.every((id, index) => id === right[index]);
1439
+ }
1440
+ function resolveLeafColumnOrder(columns, order) {
1441
+ const leafIds = collectLeafColumnIds(columns);
1442
+ if (!order?.length) return leafIds;
1443
+ const leafSet = new Set(leafIds);
1444
+ const seen = /* @__PURE__ */ new Set();
1445
+ const next = order.filter((id) => {
1446
+ if (!leafSet.has(id) || seen.has(id)) return false;
1447
+ seen.add(id);
1448
+ return true;
1449
+ });
1450
+ for (const id of leafIds) {
1451
+ if (!seen.has(id)) next.push(id);
1452
+ }
1453
+ return next;
1454
+ }
1455
+ function flattenColumnSlots(columns, group) {
1456
+ const slots = [];
1457
+ for (const column of columns) {
1458
+ const id = getColumnDefId(column);
1459
+ const children = getColumnDefChildren(column);
1460
+ if (children) {
1461
+ const nestedGroup = id ? { id, def: column } : group;
1462
+ slots.push(...flattenColumnSlots(children, nestedGroup));
1463
+ continue;
1464
+ }
1465
+ if (!id) continue;
1466
+ slots.push({ id, def: column, group });
1467
+ }
1468
+ return slots;
1469
+ }
1470
+ function rebuildColumnTree(slots) {
1471
+ const result = [];
1472
+ let index = 0;
1473
+ while (index < slots.length) {
1474
+ const slot = slots[index];
1475
+ if (!slot.group) {
1476
+ result.push(slot.def);
1477
+ index += 1;
1478
+ continue;
1479
+ }
1480
+ const groupId = slot.group.id;
1481
+ const children = [];
1482
+ while (index < slots.length && slots[index]?.group?.id === groupId) {
1483
+ children.push(slots[index].def);
1484
+ index += 1;
1485
+ }
1486
+ const firstChildId = children[0] ? getColumnDefId(children[0]) : groupId;
1487
+ result.push({
1488
+ ...slot.group.def,
1489
+ id: `${groupId}::${firstChildId}`,
1490
+ columns: children
1491
+ });
1492
+ }
1493
+ return result;
1494
+ }
1495
+ function applyLeafColumnOrder(columns, order) {
1496
+ const resolved = resolveLeafColumnOrder(columns, order);
1497
+ const defaultOrder = collectLeafColumnIds(columns);
1498
+ if (areColumnOrdersEqual(resolved, defaultOrder)) {
1499
+ return columns;
1500
+ }
1501
+ const byId = new Map(
1502
+ flattenColumnSlots(columns).map((slot) => [
1503
+ slot.id,
1504
+ slot
1505
+ ])
1506
+ );
1507
+ const ordered = [];
1508
+ for (const id of resolved) {
1509
+ const slot = byId.get(id);
1510
+ if (slot) ordered.push(slot);
1511
+ }
1512
+ return rebuildColumnTree(ordered);
1513
+ }
1514
+ function moveColumnIds(order, fromIds, targetIds, edge) {
1515
+ if (fromIds.length === 0 || targetIds.length === 0) return [...order];
1516
+ const fromSet = new Set(fromIds);
1517
+ if (targetIds.some((id) => fromSet.has(id))) return [...order];
1518
+ const rest = order.filter((id) => !fromSet.has(id));
1519
+ const anchorId = edge === "before" ? targetIds[0] : targetIds[targetIds.length - 1];
1520
+ const anchorIndex = rest.indexOf(anchorId);
1521
+ if (anchorIndex < 0) return [...order];
1522
+ const insertAt = edge === "before" ? anchorIndex : anchorIndex + 1;
1523
+ return [...rest.slice(0, insertAt), ...fromIds, ...rest.slice(insertAt)];
1524
+ }
1525
+ function resolveDropEdge(clientX, rect) {
1526
+ return clientX < rect.left + rect.width / 2 ? "before" : "after";
1527
+ }
1528
+ function parseReorderIds(value) {
1529
+ if (!value) return [];
1530
+ return value.split(",").filter(Boolean);
1531
+ }
1532
+
1402
1533
  // src/components/ui/table/features/column-freeze/columnFreeze.ts
1403
1534
  var HEADER_Z_BASE = 30;
1404
1535
  var BODY_Z_BASE = 5;
@@ -2165,23 +2296,49 @@ function applySelectionUpdater(mode, updater, previous) {
2165
2296
  function getRowFieldValue(row, key) {
2166
2297
  return row[key];
2167
2298
  }
2168
- function computeRowSpans(data, rowSpanKey) {
2299
+ function normalizeRowSpanParent(value) {
2300
+ if (!value) return [];
2301
+ return typeof value === "string" ? [value] : [...value];
2302
+ }
2303
+ function toParentSpanList(parentSpans) {
2304
+ if (!parentSpans?.length) return [];
2305
+ const first = parentSpans[0];
2306
+ if (!Array.isArray(first)) {
2307
+ return [parentSpans];
2308
+ }
2309
+ return parentSpans;
2310
+ }
2311
+ function buildStartRowLookup(spans) {
2312
+ const startRows = new Array(spans.length);
2313
+ let origin = 0;
2314
+ for (let i = 0; i < spans.length; i++) {
2315
+ if ((spans[i]?.rowSpan ?? 1) > 0) origin = i;
2316
+ startRows[i] = origin;
2317
+ }
2318
+ return startRows;
2319
+ }
2320
+ function sharesParentGroup(parentStartRows, rowIndex) {
2321
+ if (parentStartRows.length === 0 || rowIndex <= 0) return true;
2322
+ return parentStartRows.every(
2323
+ (startRows) => startRows[rowIndex - 1] === startRows[rowIndex]
2324
+ );
2325
+ }
2326
+ function computeRowSpans(data, rowSpanKey, parentSpans) {
2169
2327
  if (data.length === 0) return [];
2328
+ const parentStartRows = toParentSpanList(parentSpans).map(buildStartRowLookup);
2170
2329
  const result = [];
2171
2330
  for (let index = 0; index < data.length; index++) {
2172
2331
  const currentValue = getRowFieldValue(data[index], rowSpanKey);
2173
2332
  const previousValue = index > 0 ? getRowFieldValue(data[index - 1], rowSpanKey) : void 0;
2174
- if (index > 0 && currentValue === previousValue) {
2333
+ if (index > 0 && currentValue === previousValue && sharesParentGroup(parentStartRows, index)) {
2175
2334
  result.push({ rowSpan: 0, isFirstInGroup: false });
2176
2335
  continue;
2177
2336
  }
2178
2337
  let span = 1;
2179
2338
  for (let nextIndex = index + 1; nextIndex < data.length; nextIndex++) {
2180
- if (getRowFieldValue(data[nextIndex], rowSpanKey) === currentValue) {
2181
- span++;
2182
- } else {
2183
- break;
2184
- }
2339
+ if (getRowFieldValue(data[nextIndex], rowSpanKey) !== currentValue) break;
2340
+ if (!sharesParentGroup(parentStartRows, nextIndex)) break;
2341
+ span++;
2185
2342
  }
2186
2343
  result.push({ rowSpan: span, isFirstInGroup: true });
2187
2344
  }
@@ -2203,10 +2360,50 @@ function resolveRowSpanAt(rowSpans, rowIndex) {
2203
2360
  }
2204
2361
  return { startRow: rowIndex, rowSpan: 1 };
2205
2362
  }
2363
+ function findRowSpanColumn(spec, ref) {
2364
+ return spec.find((column) => column.columnId === ref) ?? spec.find((column) => column.rowSpanKey === ref);
2365
+ }
2206
2366
  function buildColumnRowSpanMap(data, columnKeys) {
2207
2367
  const map = /* @__PURE__ */ new Map();
2208
- for (const { columnId, rowSpanKey } of columnKeys) {
2209
- map.set(columnId, computeRowSpans(data, rowSpanKey));
2368
+ const visiting = /* @__PURE__ */ new Set();
2369
+ const warnedCycles = /* @__PURE__ */ new Set();
2370
+ const virtualParents = /* @__PURE__ */ new Map();
2371
+ const spansForColumn = (columnId) => {
2372
+ const cached = map.get(columnId);
2373
+ if (cached !== void 0) return cached;
2374
+ const column = columnKeys.find((item) => item.columnId === columnId);
2375
+ if (!column) return void 0;
2376
+ if (visiting.has(columnId)) {
2377
+ if (!warnedCycles.has(columnId)) {
2378
+ warnedCycles.add(columnId);
2379
+ console.warn(
2380
+ `[rowSpan] rowSpanParent cycle detected at column "${columnId}"; dropping the cyclic parent reference.`
2381
+ );
2382
+ }
2383
+ return void 0;
2384
+ }
2385
+ visiting.add(columnId);
2386
+ const parentSpans = (column.rowSpanParent ?? []).map((ref) => spansForParentRef(ref)).filter((spans2) => Boolean(spans2));
2387
+ visiting.delete(columnId);
2388
+ const spans = computeRowSpans(
2389
+ data,
2390
+ column.rowSpanKey,
2391
+ parentSpans.length > 0 ? parentSpans : void 0
2392
+ );
2393
+ map.set(columnId, spans);
2394
+ return spans;
2395
+ };
2396
+ const spansForParentRef = (ref) => {
2397
+ const parentColumn = findRowSpanColumn(columnKeys, ref);
2398
+ if (parentColumn) return spansForColumn(parentColumn.columnId);
2399
+ const cached = virtualParents.get(ref);
2400
+ if (cached !== void 0) return cached;
2401
+ const spans = computeRowSpans(data, ref);
2402
+ virtualParents.set(ref, spans);
2403
+ return spans;
2404
+ };
2405
+ for (const column of columnKeys) {
2406
+ spansForColumn(column.columnId);
2210
2407
  }
2211
2408
  return map;
2212
2409
  }
@@ -2222,7 +2419,8 @@ function collectRowSpanColumns(columns) {
2222
2419
  if (!columnId || !columnDef.meta?.rowSpan) continue;
2223
2420
  result.push({
2224
2421
  columnId,
2225
- rowSpanKey: columnDef.meta.rowSpanKey ?? columnId
2422
+ rowSpanKey: columnDef.meta.rowSpanKey ?? columnId,
2423
+ rowSpanParent: normalizeRowSpanParent(columnDef.meta.rowSpanParent)
2226
2424
  });
2227
2425
  }
2228
2426
  };
@@ -2274,6 +2472,9 @@ function useGlideTable(options) {
2274
2472
  columnSizing: controlledColumnSizing,
2275
2473
  onColumnSizingChange,
2276
2474
  columnResizeMode = "onChange",
2475
+ enableColumnReorder = false,
2476
+ columnOrder: controlledColumnOrder,
2477
+ onColumnOrderChange,
2277
2478
  enableColumnFreeze = false,
2278
2479
  enableInlineSearch = false,
2279
2480
  showSearch,
@@ -2296,6 +2497,7 @@ function useGlideTable(options) {
2296
2497
  const resolvedEnableSubtreeCopy = enableSubtreeCopy ?? enableExpand;
2297
2498
  const [internalRowSelection, setInternalRowSelection] = (0, import_react5.useState)({});
2298
2499
  const [internalColumnSizing, setInternalColumnSizing] = (0, import_react5.useState)({});
2500
+ const [internalColumnOrder, setInternalColumnOrder] = (0, import_react5.useState)([]);
2299
2501
  const [internalExpandedRows, setInternalExpandedRows] = (0, import_react5.useState)(
2300
2502
  () => /* @__PURE__ */ new Set()
2301
2503
  );
@@ -2316,6 +2518,21 @@ function useGlideTable(options) {
2316
2518
  internalRowSelection
2317
2519
  );
2318
2520
  const columnSizing = controlledColumnSizing ?? internalColumnSizing;
2521
+ const columnOrder = controlledColumnOrder ?? internalColumnOrder;
2522
+ const tableColumns = (0, import_react5.useMemo)(() => {
2523
+ if (!enableColumnReorder) return columns;
2524
+ return applyLeafColumnOrder(columns, columnOrder);
2525
+ }, [columnOrder, columns, enableColumnReorder]);
2526
+ const setColumnOrder = (0, import_react5.useCallback)(
2527
+ (next) => {
2528
+ if (onColumnOrderChange) {
2529
+ onColumnOrderChange(next);
2530
+ return;
2531
+ }
2532
+ setInternalColumnOrder(next);
2533
+ },
2534
+ [onColumnOrderChange]
2535
+ );
2319
2536
  const expandedRows = controlledExpandedRows ?? internalExpandedRows;
2320
2537
  const handleExpandedRowsChange = (0, import_react5.useCallback)(
2321
2538
  (next) => {
@@ -2340,7 +2557,7 @@ function useGlideTable(options) {
2340
2557
  });
2341
2558
  const table = (0, import_react_table.useReactTable)({
2342
2559
  data: tableData,
2343
- columns,
2560
+ columns: tableColumns,
2344
2561
  ...enableColumnResize ? {
2345
2562
  defaultColumn: {
2346
2563
  minSize: DATA_TABLE_COLUMN_MIN_SIZE,
@@ -2822,6 +3039,7 @@ function useGlideTable(options) {
2822
3039
  selectionLabel: labels.selection,
2823
3040
  enableCellSelection,
2824
3041
  enableColumnResize,
3042
+ enableColumnReorder,
2825
3043
  enableColumnFreeze,
2826
3044
  enableInlineSearch,
2827
3045
  shouldVirtualize,
@@ -2835,6 +3053,7 @@ function useGlideTable(options) {
2835
3053
  getCellContext,
2836
3054
  handleToggleSelect,
2837
3055
  clearHover,
3056
+ setColumnOrder,
2838
3057
  copySelection: stableCopySelection,
2839
3058
  inlineSearch: {
2840
3059
  showSearch: inlineSearch.showSearch,
@@ -2913,6 +3132,214 @@ function getColumnSizeStyle(size, options) {
2913
3132
  ...lockMax ? { maxWidth: size } : {}
2914
3133
  };
2915
3134
  }
3135
+
3136
+ // src/components/ui/table/features/column-reorder/useColumnReorder.ts
3137
+ var import_react8 = require("react");
3138
+ function hitTestReorderHeader(table, clientX, clientY) {
3139
+ const headers = Array.from(
3140
+ table.querySelectorAll(
3141
+ "thead th[data-column-id][data-reorder-ids]"
3142
+ )
3143
+ );
3144
+ const containing = headers.find((element) => {
3145
+ const rect = element.getBoundingClientRect();
3146
+ return clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
3147
+ });
3148
+ if (containing) {
3149
+ return {
3150
+ columnId: containing.dataset.columnId ?? "",
3151
+ edge: resolveDropEdge(clientX, containing.getBoundingClientRect())
3152
+ };
3153
+ }
3154
+ const leaves = headers.filter(
3155
+ (element) => element.hasAttribute("data-reorder-leaf")
3156
+ );
3157
+ let match;
3158
+ for (const element of leaves) {
3159
+ const rect = element.getBoundingClientRect();
3160
+ if (clientX >= rect.left && clientX <= rect.right) {
3161
+ match = element;
3162
+ break;
3163
+ }
3164
+ }
3165
+ if (!match && leaves.length > 0) {
3166
+ const first = leaves[0].getBoundingClientRect();
3167
+ const last = leaves[leaves.length - 1].getBoundingClientRect();
3168
+ if (clientX < first.left) match = leaves[0];
3169
+ else if (clientX > last.right) match = leaves[leaves.length - 1];
3170
+ }
3171
+ if (!match) return null;
3172
+ return {
3173
+ columnId: match.dataset.columnId ?? "",
3174
+ edge: resolveDropEdge(clientX, match.getBoundingClientRect())
3175
+ };
3176
+ }
3177
+ function readTargetIds(table, columnId) {
3178
+ const element = table.querySelector(
3179
+ `thead th[data-column-id="${CSS.escape(columnId)}"]`
3180
+ );
3181
+ return parseReorderIds(element?.getAttribute("data-reorder-ids"));
3182
+ }
3183
+ function useColumnReorder(options) {
3184
+ 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)(
3190
+ null
3191
+ );
3192
+ const dropTargetRef = (0, import_react8.useRef)(dropTarget);
3193
+ const previousUserSelectRef = (0, import_react8.useRef)(null);
3194
+ columnOrderRef.current = columnOrder;
3195
+ onColumnOrderChangeRef.current = onColumnOrderChange;
3196
+ dropTargetRef.current = dropTarget;
3197
+ const resetDrag = (0, import_react8.useCallback)(() => {
3198
+ sessionRef.current = null;
3199
+ setDraggingColumnId(null);
3200
+ setDropTarget(null);
3201
+ const backup = previousUserSelectRef.current;
3202
+ previousUserSelectRef.current = null;
3203
+ if (backup) {
3204
+ if (backup.value) {
3205
+ document.body.style.setProperty("user-select", backup.value, backup.priority);
3206
+ } else {
3207
+ document.body.style.removeProperty("user-select");
3208
+ }
3209
+ return;
3210
+ }
3211
+ document.body.style.removeProperty("user-select");
3212
+ }, []);
3213
+ (0, import_react8.useEffect)(() => {
3214
+ if (!enabled) resetDrag();
3215
+ }, [enabled, resetDrag]);
3216
+ (0, import_react8.useEffect)(() => {
3217
+ return () => {
3218
+ resetDrag();
3219
+ };
3220
+ }, [resetDrag]);
3221
+ const onHeaderPointerDown = (0, import_react8.useCallback)(
3222
+ (event, meta) => {
3223
+ if (!enabled || !meta.canDrag) return;
3224
+ if (event.button !== 0) return;
3225
+ if (event.pointerType === "mouse" && event.ctrlKey) return;
3226
+ const target = event.target;
3227
+ if (target instanceof Element && target.closest("[data-table-disable-cell-selection]")) {
3228
+ return;
3229
+ }
3230
+ const table = event.currentTarget.closest("table");
3231
+ if (!(table instanceof HTMLTableElement)) return;
3232
+ sessionRef.current = {
3233
+ pointerId: event.pointerId,
3234
+ startX: event.clientX,
3235
+ startY: event.clientY,
3236
+ columnId: meta.columnId,
3237
+ fromIds: meta.leafIds,
3238
+ table,
3239
+ active: false
3240
+ };
3241
+ },
3242
+ [enabled]
3243
+ );
3244
+ (0, import_react8.useEffect)(() => {
3245
+ if (!enabled) return;
3246
+ const onPointerMove = (event) => {
3247
+ const session = sessionRef.current;
3248
+ if (!session || event.pointerId !== session.pointerId) return;
3249
+ const deltaX = event.clientX - session.startX;
3250
+ const deltaY = event.clientY - session.startY;
3251
+ const distance = Math.hypot(deltaX, deltaY);
3252
+ if (!session.active) {
3253
+ if (distance < DATA_TABLE_COLUMN_REORDER_THRESHOLD) return;
3254
+ session.active = true;
3255
+ if (!previousUserSelectRef.current) {
3256
+ previousUserSelectRef.current = {
3257
+ value: document.body.style.getPropertyValue("user-select"),
3258
+ priority: document.body.style.getPropertyPriority("user-select")
3259
+ };
3260
+ }
3261
+ document.body.style.setProperty("user-select", "none");
3262
+ setDraggingColumnId(session.columnId);
3263
+ }
3264
+ event.preventDefault();
3265
+ const nextTarget = hitTestReorderHeader(
3266
+ session.table,
3267
+ event.clientX,
3268
+ event.clientY
3269
+ );
3270
+ if (!nextTarget || !nextTarget.columnId) {
3271
+ setDropTarget(null);
3272
+ return;
3273
+ }
3274
+ const targetIds = readTargetIds(session.table, nextTarget.columnId);
3275
+ const fromSet = new Set(session.fromIds);
3276
+ if (targetIds.some((id) => fromSet.has(id))) {
3277
+ setDropTarget(null);
3278
+ return;
3279
+ }
3280
+ setDropTarget((previous) => {
3281
+ if (previous?.columnId === nextTarget.columnId && previous.edge === nextTarget.edge) {
3282
+ return previous;
3283
+ }
3284
+ return nextTarget;
3285
+ });
3286
+ };
3287
+ const onPointerUp = (event) => {
3288
+ const session = sessionRef.current;
3289
+ if (!session || event.pointerId !== session.pointerId) {
3290
+ return;
3291
+ }
3292
+ if (session.active) {
3293
+ event.preventDefault();
3294
+ const target = dropTargetRef.current;
3295
+ if (target) {
3296
+ const targetIds = readTargetIds(session.table, target.columnId);
3297
+ const next = moveColumnIds(
3298
+ columnOrderRef.current,
3299
+ session.fromIds,
3300
+ targetIds,
3301
+ target.edge
3302
+ );
3303
+ onColumnOrderChangeRef.current(next);
3304
+ }
3305
+ const suppressClick = (clickEvent) => {
3306
+ clickEvent.preventDefault();
3307
+ clickEvent.stopPropagation();
3308
+ document.removeEventListener("click", suppressClick, true);
3309
+ };
3310
+ document.addEventListener("click", suppressClick, true);
3311
+ window.setTimeout(() => {
3312
+ document.removeEventListener("click", suppressClick, true);
3313
+ }, 0);
3314
+ }
3315
+ resetDrag();
3316
+ };
3317
+ const onPointerCancel = (event) => {
3318
+ const session = sessionRef.current;
3319
+ if (!session || event.pointerId !== session.pointerId) {
3320
+ return;
3321
+ }
3322
+ if (session.active) {
3323
+ event.preventDefault();
3324
+ }
3325
+ resetDrag();
3326
+ };
3327
+ document.addEventListener("pointermove", onPointerMove);
3328
+ document.addEventListener("pointerup", onPointerUp);
3329
+ document.addEventListener("pointercancel", onPointerCancel);
3330
+ return () => {
3331
+ document.removeEventListener("pointermove", onPointerMove);
3332
+ document.removeEventListener("pointerup", onPointerUp);
3333
+ document.removeEventListener("pointercancel", onPointerCancel);
3334
+ };
3335
+ }, [enabled, resetDrag]);
3336
+ return {
3337
+ isReordering: draggingColumnId != null,
3338
+ draggingColumnId,
3339
+ dropTarget,
3340
+ onHeaderPointerDown
3341
+ };
3342
+ }
2916
3343
  // Annotate the CommonJS export names for ESM import in node:
2917
3344
  0 && (module.exports = {
2918
3345
  BUILTIN_CELL_RENDERERS,
@@ -2926,6 +3353,7 @@ function getColumnSizeStyle(size, options) {
2926
3353
  ResolvedTableCell,
2927
3354
  applyCellEdit,
2928
3355
  applyFillData,
3356
+ applyLeafColumnOrder,
2929
3357
  applySelectionUpdater,
2930
3358
  buildColumnFreezeOffsets,
2931
3359
  buildColumnRowSpanMap,
@@ -2940,6 +3368,7 @@ function getColumnSizeStyle(size, options) {
2940
3368
  collectCopyRowEntries,
2941
3369
  collectCopyRows,
2942
3370
  collectFillChanges,
3371
+ collectLeafColumnIds,
2943
3372
  collectRowSpanColumns,
2944
3373
  collectSearchMatchesInRange,
2945
3374
  commitCellValue,
@@ -2964,6 +3393,7 @@ function getColumnSizeStyle(size, options) {
2964
3393
  mapSearchResultToVisibleItem,
2965
3394
  mapSearchResultsToVisibleKeys,
2966
3395
  measureMergedSpanRowHeights,
3396
+ moveColumnIds,
2967
3397
  nextSearchIndex,
2968
3398
  nextSearchStride,
2969
3399
  parseCellEditValue,
@@ -2973,7 +3403,9 @@ function getColumnSizeStyle(size, options) {
2973
3403
  resolveCellRenderer,
2974
3404
  resolveColumnFreezeSide,
2975
3405
  resolveDataTableLabels,
3406
+ resolveDropEdge,
2976
3407
  resolveHeaderFreezeOffset,
3408
+ resolveLeafColumnOrder,
2977
3409
  resolvePasteColumnIds,
2978
3410
  resolveRowSelection,
2979
3411
  resolveRowSpanAt,
@@ -2983,6 +3415,7 @@ function getColumnSizeStyle(size, options) {
2983
3415
  toggleExpandedRowId,
2984
3416
  useCellEdit,
2985
3417
  useCellSelection,
3418
+ useColumnReorder,
2986
3419
  useConvertTreeData,
2987
3420
  useGlideTable,
2988
3421
  useInlineSearch,