@gridkitjs/react 0.0.0-dev-20261118204728 → 0.0.0-dev-20261118223155

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.js CHANGED
@@ -11,12 +11,16 @@ import {
11
11
  } from "react";
12
12
  import {
13
13
  headerFocus as headerFocus3,
14
- moveColumnBefore,
15
14
  resolveColumnHeaderText as resolveColumnHeaderText2,
15
+ resolveColumnPin as resolveColumnPin2,
16
16
  resolveMessages,
17
17
  resolveRows
18
18
  } from "@gridkitjs/core";
19
- import { pinnedWidths, totalColumnWidth } from "@gridkitjs/core/renderer";
19
+ import {
20
+ moveColumnInPinGroup,
21
+ pinnedWidths as pinnedWidths2,
22
+ totalColumnWidth
23
+ } from "@gridkitjs/core/renderer";
20
24
 
21
25
  // src/DataGrid/components/GridColgroup.tsx
22
26
  import { jsx } from "react/jsx-runtime";
@@ -203,8 +207,10 @@ function GridHeader({
203
207
  const { column } = entry;
204
208
  const resizing = resize.activeColumnId === entry.id;
205
209
  const dragging = drag.draggedColumnId === entry.id;
206
- const dropBefore = beforeId !== void 0 && beforeId === entry.id;
207
- const dropAfter = beforeId === null && index === columns.length - 1;
210
+ const dragBlocked = draggedEntry !== null && entry.pinned !== draggedEntry.pinned;
211
+ const next = columns[index + 1];
212
+ const dropBefore = beforeId === entry.id && !dragBlocked;
213
+ const dropAfter = !dragBlocked && (next === void 0 ? beforeId === null : beforeId === next.id && next.pinned !== entry.pinned);
208
214
  const selected = selection.selectedColumnIds.has(entry.id);
209
215
  const sortable = column.sortable ?? sortableColumns;
210
216
  const sortDirection = sortDirectionFor(columnSort, entry.id);
@@ -309,6 +315,7 @@ function GridHeader({
309
315
  dragging ? "is-dragging" : "",
310
316
  dropBefore ? "is-drop-before" : "",
311
317
  dropAfter ? "is-drop-after" : "",
318
+ dragBlocked ? "is-drag-blocked" : "",
312
319
  column.wrap?.header ? "is-wrapped" : "",
313
320
  pinnedCellClassNames(entry),
314
321
  column.headerClassName ?? ""
@@ -2417,7 +2424,7 @@ import {
2417
2424
  isSameCell,
2418
2425
  resolveMenu
2419
2426
  } from "@gridkitjs/core";
2420
- import { hasContextMenu } from "@gridkitjs/core/renderer";
2427
+ import { hasContextMenu, pinnedWidths } from "@gridkitjs/core/renderer";
2421
2428
  import {
2422
2429
  attachContextMenuTrigger
2423
2430
  } from "@gridkitjs/dom";
@@ -2442,12 +2449,16 @@ function bodyCell(parts, rowIndex, columnIndex) {
2442
2449
  const element = findBodyRow2(parts.bodyTable, rowIndex)?.cells[columnIndex];
2443
2450
  return element === void 0 ? null : { element, focus: bodyFocus2(rowIndex, columnIndex) };
2444
2451
  }
2452
+ function underPinnedColumns(element, parts) {
2453
+ return parts.pinnedWidths.start + parts.pinnedWidths.end > 0 && element instanceof HTMLTableCellElement && !element.matches(".is-pinned-start, .is-pinned-end");
2454
+ }
2445
2455
  function viewOf(element, parts) {
2446
- const view = parts.scroller?.getBoundingClientRect();
2447
- if (view === void 0) {
2456
+ const { scroller } = parts;
2457
+ if (scroller === null) {
2448
2458
  return null;
2449
2459
  }
2450
- let { top, bottom } = view;
2460
+ const view = scroller.getBoundingClientRect();
2461
+ let { top, bottom, left, right } = view;
2451
2462
  if (parts.body?.contains(element) === true) {
2452
2463
  top = Math.max(
2453
2464
  top,
@@ -2458,7 +2469,19 @@ function viewOf(element, parts) {
2458
2469
  parts.footerTable?.getBoundingClientRect().top ?? bottom
2459
2470
  );
2460
2471
  }
2461
- return new DOMRect(view.left, top, view.width, Math.max(0, bottom - top));
2472
+ if (underPinnedColumns(element, parts)) {
2473
+ const { start, end } = parts.pinnedWidths;
2474
+ const rtl = writingDirection5(element) === "rtl";
2475
+ const portLeft = view.left + scroller.clientLeft;
2476
+ left = portLeft + (rtl ? end : start);
2477
+ right = portLeft + scroller.clientWidth - (rtl ? start : end);
2478
+ }
2479
+ return new DOMRect(
2480
+ left,
2481
+ top,
2482
+ Math.max(0, right - left),
2483
+ Math.max(0, bottom - top)
2484
+ );
2462
2485
  }
2463
2486
  function clamp(value, min, max) {
2464
2487
  return Math.min(Math.max(value, min), max);
@@ -2597,6 +2620,7 @@ function useContextMenu({
2597
2620
  body: bodyRef.current,
2598
2621
  footerTable: footerTableRef.current,
2599
2622
  columns,
2623
+ pinnedWidths: pinnedWidths(columns),
2600
2624
  pageRows
2601
2625
  };
2602
2626
  }
@@ -4389,13 +4413,15 @@ function useColumnDrag({
4389
4413
  order,
4390
4414
  groupBy,
4391
4415
  groupByDraggableIds,
4416
+ pinOf,
4392
4417
  onDrop
4393
4418
  }) {
4394
4419
  const drag = useDragReorder({
4395
4420
  resolveTarget: (clientX, clientY, movedId) => resolveColumnDropTarget(clientX, clientY, movedId, {
4396
4421
  order,
4397
4422
  groupBy,
4398
- groupByDraggableIds
4423
+ groupByDraggableIds,
4424
+ pinOf
4399
4425
  }),
4400
4426
  onDrop
4401
4427
  });
@@ -4912,20 +4938,36 @@ function DataGrid(props) {
4912
4938
  ),
4913
4939
  [view.columns]
4914
4940
  );
4941
+ function pinOf(columnId) {
4942
+ const column = definitions.get(columnId);
4943
+ return column === void 0 ? "none" : resolveColumnPin2(column, state.columnPinning);
4944
+ }
4915
4945
  function handleDrop(target, movedId) {
4916
4946
  if (target.kind === "group-by") {
4917
4947
  controller.moveGroupBy(movedId, target.beforeColumnId);
4918
4948
  return;
4919
4949
  }
4920
- const next = moveColumnBefore(orderedIds, movedId, target.beforeId);
4950
+ const next = moveColumnInPinGroup(
4951
+ orderedIds,
4952
+ pinOf,
4953
+ movedId,
4954
+ target.beforeId
4955
+ );
4921
4956
  if (next === orderedIds) {
4922
4957
  return;
4923
4958
  }
4924
4959
  controller.moveColumn(movedId, target.beforeId);
4925
- const shown = next.filter((id) => displayedIds.includes(id));
4926
- const position = shown.indexOf(movedId);
4960
+ const pin = pinOf(movedId);
4961
+ const group = next.filter(
4962
+ (id) => pinOf(id) === pin && displayedIds.includes(id)
4963
+ );
4964
+ const position = displayedIds.findIndex((id) => pinOf(id) === pin) + group.indexOf(movedId);
4927
4965
  announce(
4928
- messages.columnMoved(columnName(movedId), position + 1, shown.length)
4966
+ messages.columnMoved(
4967
+ columnName(movedId),
4968
+ position + 1,
4969
+ displayedIds.length
4970
+ )
4929
4971
  );
4930
4972
  nav.focusCell(headerFocus3(position));
4931
4973
  }
@@ -4933,6 +4975,7 @@ function DataGrid(props) {
4933
4975
  order: displayedIds,
4934
4976
  groupBy: state.groupBy,
4935
4977
  groupByDraggableIds,
4978
+ pinOf,
4936
4979
  onDrop: handleDrop
4937
4980
  });
4938
4981
  const draggedColumnAlreadyGrouped = drag.draggedColumnId !== null && state.groupBy.some((entry) => entry.columnId === drag.draggedColumnId);
@@ -5137,7 +5180,7 @@ function DataGrid(props) {
5137
5180
  height,
5138
5181
  headerHeight,
5139
5182
  footerHeight,
5140
- pinnedWidths(view.columns)
5183
+ pinnedWidths2(view.columns)
5141
5184
  ),
5142
5185
  ...ariaAttr(multiselectable, "aria-multiselectable", true),
5143
5186
  ...ariaAttr(labelledBy !== void 0, "aria-labelledby", labelledBy),