@gridkitjs/react 0.18.0 → 0.19.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/index.js CHANGED
@@ -7,16 +7,20 @@ import {
7
7
  useImperativeHandle as useImperativeHandle3,
8
8
  useMemo as useMemo5,
9
9
  useRef as useRef23,
10
- useState as useState18
10
+ useState as useState19
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 { 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";
@@ -34,10 +38,12 @@ import {
34
38
  } from "@gridkitjs/core";
35
39
  import {
36
40
  buildKeyShortcuts,
41
+ inlineStep,
37
42
  intentOf,
38
43
  KEYBOARD_STEP,
39
44
  resolveColumnFilterMenu
40
45
  } from "@gridkitjs/core/renderer";
46
+ import { writingDirection } from "@gridkitjs/dom";
41
47
 
42
48
  // src/DataGrid/ariaAttr.ts
43
49
  function ariaAttr(condition, key, value) {
@@ -109,6 +115,27 @@ function isOwnEvent(event) {
109
115
  return event.target instanceof Node && event.currentTarget.contains(event.target);
110
116
  }
111
117
 
118
+ // src/DataGrid/pinnedCell.ts
119
+ function pinnedCellClassNames({
120
+ pinned,
121
+ pinEdge
122
+ }) {
123
+ if (pinned === "none") return "";
124
+ return classNames(
125
+ pinned === "start" ? "is-pinned-start" : "is-pinned-end",
126
+ pinEdge && "is-pinned-edge"
127
+ );
128
+ }
129
+ function pinnedCellStyle({
130
+ pinned,
131
+ pinOffset
132
+ }) {
133
+ if (pinned === "none") return void 0;
134
+ return {
135
+ "--gridkit-pin-offset": `${String(pinOffset)}px`
136
+ };
137
+ }
138
+
112
139
  // src/DataGrid/useGridSelection.ts
113
140
  import { useMemo } from "react";
114
141
  function keyboardSelectIntent(event) {
@@ -180,8 +207,10 @@ function GridHeader({
180
207
  const { column } = entry;
181
208
  const resizing = resize.activeColumnId === entry.id;
182
209
  const dragging = drag.draggedColumnId === entry.id;
183
- const dropBefore = beforeId !== void 0 && beforeId === entry.id;
184
- 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);
185
214
  const selected = selection.selectedColumnIds.has(entry.id);
186
215
  const sortable = column.sortable ?? sortableColumns;
187
216
  const sortDirection = sortDirectionFor(columnSort, entry.id);
@@ -228,16 +257,18 @@ function GridHeader({
228
257
  },
229
258
  onKeyDown: (event) => {
230
259
  if (!isOwnEvent(event)) return;
231
- const horizontal = event.key === "ArrowLeft" || event.key === "ArrowRight";
232
- const direction = event.key === "ArrowLeft" ? -1 : 1;
233
- if (horizontal && event.ctrlKey && entry.reorderable) {
260
+ const step = inlineStep(
261
+ event.key,
262
+ writingDirection(event.currentTarget)
263
+ );
264
+ if (step !== null && event.ctrlKey && entry.reorderable) {
234
265
  event.preventDefault();
235
- drag.moveByKeyboard(entry, direction);
266
+ drag.moveByKeyboard(entry, step);
236
267
  return;
237
268
  }
238
- if (horizontal && event.altKey && entry.resizable) {
269
+ if (step !== null && event.altKey && entry.resizable) {
239
270
  event.preventDefault();
240
- resize.nudge(entry, direction * KEYBOARD_STEP);
271
+ resize.nudge(entry, step * KEYBOARD_STEP);
241
272
  return;
242
273
  }
243
274
  if (event.key === "Enter" && event.altKey && entry.resizable) {
@@ -284,9 +315,12 @@ function GridHeader({
284
315
  dragging ? "is-dragging" : "",
285
316
  dropBefore ? "is-drop-before" : "",
286
317
  dropAfter ? "is-drop-after" : "",
318
+ dragBlocked ? "is-drag-blocked" : "",
287
319
  column.wrap?.header ? "is-wrapped" : "",
320
+ pinnedCellClassNames(entry),
288
321
  column.headerClassName ?? ""
289
322
  ),
323
+ style: pinnedCellStyle(entry),
290
324
  ...ariaAttr(shortcuts !== "", "aria-keyshortcuts", shortcuts),
291
325
  ...ariaAttr(
292
326
  filtered,
@@ -435,8 +469,7 @@ import {
435
469
  useState as useState2
436
470
  } from "react";
437
471
  import {
438
- bodyFocus,
439
- groupRowId
472
+ bodyFocus
440
473
  } from "@gridkitjs/core";
441
474
  import { intentOf as intentOf2 } from "@gridkitjs/core/renderer";
442
475
  import {
@@ -455,7 +488,8 @@ import {
455
488
  import {
456
489
  createGridFocus,
457
490
  findBodyRow,
458
- measurePageSize
491
+ measurePageSize,
492
+ writingDirection as writingDirection2
459
493
  } from "@gridkitjs/dom";
460
494
  function tabIndexFor(columnIndex, focusedColumnIndex) {
461
495
  return columnIndex === focusedColumnIndex ? 0 : -1;
@@ -519,7 +553,8 @@ function useGridNavigation({
519
553
  if (gridFocus.handleKey(
520
554
  event.key,
521
555
  event,
522
- measurePageSize(bodyTableRef.current)
556
+ measurePageSize(bodyTableRef.current, gridRef.current),
557
+ writingDirection2(event.currentTarget)
523
558
  )) {
524
559
  event.preventDefault();
525
560
  }
@@ -686,6 +721,20 @@ var GridGroupRow_default = GridGroupRow;
686
721
 
687
722
  // src/DataGrid/components/GridGroupSummaryRow.tsx
688
723
  import { memo as memo2 } from "react";
724
+
725
+ // src/DataGrid/textAlign.ts
726
+ function textAlignFor(alignment) {
727
+ switch (alignment) {
728
+ case "left":
729
+ return "start";
730
+ case "right":
731
+ return "end";
732
+ case "center":
733
+ return "center";
734
+ }
735
+ }
736
+
737
+ // src/DataGrid/components/GridGroupSummaryRow.tsx
689
738
  import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
690
739
  function GridGroupSummaryRowComponent({
691
740
  groupId,
@@ -719,8 +768,14 @@ function GridGroupSummaryRowComponent({
719
768
  {
720
769
  role: "gridcell",
721
770
  "data-gridkit-column": entry.id,
722
- className: "gridkit-grid-group-summary-cell",
723
- style: { textAlign: specs[0]?.alignment ?? entry.alignment },
771
+ className: classNames(
772
+ "gridkit-grid-group-summary-cell",
773
+ pinnedCellClassNames(entry)
774
+ ),
775
+ style: {
776
+ textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),
777
+ ...pinnedCellStyle(entry)
778
+ },
724
779
  children: [
725
780
  entry.id === columns[0]?.id && /* @__PURE__ */ jsx5(
726
781
  "span",
@@ -767,6 +822,9 @@ function GridRowComponent({
767
822
  row,
768
823
  rowIndex,
769
824
  datasetIndex,
825
+ groupLevel,
826
+ groupPosition,
827
+ groupSetSize,
770
828
  activeColumnId,
771
829
  selectedColumnIds,
772
830
  selected,
@@ -794,13 +852,17 @@ function GridRowComponent({
794
852
  "aria-rowindex": datasetIndex + 2,
795
853
  "data-gridkit-row-index": rowIndex,
796
854
  "data-gridkit-row-id": rowId,
855
+ "aria-level": groupLevel === void 0 ? void 0 : groupLevel + 1,
856
+ "aria-posinset": groupPosition,
857
+ "aria-setsize": groupSetSize,
797
858
  ...ariaAttr(rowsSelectable, "aria-selected", selected),
798
859
  className: classNames(
799
860
  "gridkit-grid-row",
800
861
  selected ? "is-selected" : "",
801
862
  rowClassName
802
863
  ),
803
- children: columns.map(({ id, column, alignment }, columnIndex) => {
864
+ children: columns.map((entry, columnIndex) => {
865
+ const { id, column, alignment } = entry;
804
866
  const value = accessDotted(row, column.field);
805
867
  const cellSelected = id === selectedColumnId;
806
868
  return /* @__PURE__ */ jsx6(
@@ -817,9 +879,13 @@ function GridRowComponent({
817
879
  id === activeColumnId ? "is-resizing" : "",
818
880
  cellSelected || selectedColumnIds.has(id) ? "is-selected" : "",
819
881
  column.wrap?.cells ? "is-wrapped" : "",
882
+ pinnedCellClassNames(entry),
820
883
  column.cellClassName ?? ""
821
884
  ),
822
- style: { textAlign: alignment },
885
+ style: {
886
+ textAlign: textAlignFor(alignment),
887
+ ...pinnedCellStyle(entry)
888
+ },
823
889
  children: column.cellTemplate ? column.cellTemplate({
824
890
  value,
825
891
  row,
@@ -840,27 +906,6 @@ var GridRow_default = GridRow;
840
906
 
841
907
  // src/DataGrid/components/GridBody.tsx
842
908
  import { Fragment, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
843
- function groupAriaMeta(rows) {
844
- const totals = /* @__PURE__ */ new Map();
845
- for (const entry of rows) {
846
- if (entry.kind !== "group") continue;
847
- const parentKey = groupRowId(entry.path.slice(0, -1));
848
- totals.set(parentKey, (totals.get(parentKey) ?? 0) + 1);
849
- }
850
- const seen = /* @__PURE__ */ new Map();
851
- const meta = /* @__PURE__ */ new Map();
852
- for (const entry of rows) {
853
- if (entry.kind !== "group") continue;
854
- const parentKey = groupRowId(entry.path.slice(0, -1));
855
- const posinset = (seen.get(parentKey) ?? 0) + 1;
856
- seen.set(parentKey, posinset);
857
- meta.set(entry.groupId, {
858
- posinset,
859
- setsize: totals.get(parentKey) ?? posinset
860
- });
861
- }
862
- return meta;
863
- }
864
909
  function GridBody({
865
910
  columns,
866
911
  definitions,
@@ -883,7 +928,6 @@ function GridBody({
883
928
  groupMenu
884
929
  }) {
885
930
  const { selectedCell, rowMode, cellMode, toggleOnClick } = selection;
886
- const ariaMeta = useMemo2(() => groupAriaMeta(rows), [rows]);
887
931
  const visibleRows = virtualRange === null ? rows : rows.slice(virtualRange.startIndex, virtualRange.endIndex + 1);
888
932
  const { booleanTrue, booleanFalse, blankGroupValue } = messages;
889
933
  const cellMessages = useMemo2(
@@ -941,7 +985,7 @@ function GridBody({
941
985
  return /* @__PURE__ */ jsxs5(
942
986
  "tbody",
943
987
  {
944
- role: "rowgroup",
988
+ role: "presentation",
945
989
  className: "gridkit-grid-body",
946
990
  onFocus: (event) => {
947
991
  const group = groupRowFrom(event.target);
@@ -1029,6 +1073,9 @@ function GridBody({
1029
1073
  row: entry.row,
1030
1074
  rowIndex: entry.rowIndex,
1031
1075
  datasetIndex: entry.datasetIndex,
1076
+ groupLevel: entry.groupPosition?.level,
1077
+ groupPosition: entry.groupPosition?.position,
1078
+ groupSetSize: entry.groupPosition?.setSize,
1032
1079
  activeColumnId,
1033
1080
  selectedColumnIds: selection.selectedColumnIds,
1034
1081
  selected: selection.selectedRowIds.has(entry.rowId),
@@ -1078,8 +1125,8 @@ function GridBody({
1078
1125
  count: entry.count,
1079
1126
  rowIndex: entry.rowIndex,
1080
1127
  datasetIndex: entry.datasetIndex,
1081
- posinset: ariaMeta.get(entry.groupId)?.posinset ?? 1,
1082
- setsize: ariaMeta.get(entry.groupId)?.setsize ?? 1,
1128
+ posinset: entry.position,
1129
+ setsize: entry.setSize,
1083
1130
  aggregates: groupAggregateDisplay === "inline" ? aggregates : [],
1084
1131
  results: entry.aggregates,
1085
1132
  definitions,
@@ -1159,8 +1206,14 @@ function GridFooter({
1159
1206
  {
1160
1207
  role: "gridcell",
1161
1208
  "data-gridkit-column": entry.id,
1162
- className: "gridkit-grid-footer-cell",
1163
- style: { textAlign: specs[0]?.alignment ?? entry.alignment },
1209
+ className: classNames(
1210
+ "gridkit-grid-footer-cell",
1211
+ pinnedCellClassNames(entry)
1212
+ ),
1213
+ style: {
1214
+ textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),
1215
+ ...pinnedCellStyle(entry)
1216
+ },
1164
1217
  children: specs.map(
1165
1218
  (spec) => renderAggregate(
1166
1219
  results.get(spec.id ?? spec.columnId),
@@ -1334,7 +1387,11 @@ import { createPortal as createPortal2 } from "react-dom";
1334
1387
  import {
1335
1388
  resolveColumnLabel as resolveColumnLabel2
1336
1389
  } from "@gridkitjs/core";
1337
- import { resolveKeyboardDropTarget } from "@gridkitjs/core/renderer";
1390
+ import {
1391
+ inlineStep as inlineStep2,
1392
+ resolveKeyboardDropTarget
1393
+ } from "@gridkitjs/core/renderer";
1394
+ import { writingDirection as writingDirection3 } from "@gridkitjs/dom";
1338
1395
 
1339
1396
  // src/DataGrid/useGroupByDrag.ts
1340
1397
  import {
@@ -1525,13 +1582,13 @@ function GroupByBar({
1525
1582
  chipDrag.startDrag(entry.columnId, event);
1526
1583
  },
1527
1584
  onKeyDown: (event) => {
1528
- const horizontal = event.key === "ArrowLeft" || event.key === "ArrowRight";
1529
- if (horizontal && event.ctrlKey) {
1585
+ const step = inlineStep2(
1586
+ event.key,
1587
+ writingDirection3(event.currentTarget)
1588
+ );
1589
+ if (step !== null && event.ctrlKey) {
1530
1590
  event.preventDefault();
1531
- moveByKeyboard(
1532
- entry.columnId,
1533
- event.key === "ArrowLeft" ? -1 : 1
1534
- );
1591
+ moveByKeyboard(entry.columnId, step);
1535
1592
  }
1536
1593
  },
1537
1594
  children: [
@@ -1576,7 +1633,8 @@ function GroupByBar({
1576
1633
  // src/DataGrid/announcedCallbacks.ts
1577
1634
  import {
1578
1635
  isColumnVisible,
1579
- isGroupExpanded
1636
+ isGroupExpanded,
1637
+ resolveColumnPin
1580
1638
  } from "@gridkitjs/core";
1581
1639
  function announcedCallbacks({
1582
1640
  callbacks,
@@ -1630,6 +1688,26 @@ function announcedCallbacks({
1630
1688
  shown ? messages.columnShown(columnName(columnId)) : messages.columnHidden(columnName(columnId))
1631
1689
  );
1632
1690
  },
1691
+ /**
1692
+ * Naming the one column pinned or unpinned and the edge it went to. A
1693
+ * change touching several columns, as `setColumnPinning` or restoring a
1694
+ * layout can, may pin some and unpin others, and says nothing.
1695
+ */
1696
+ onColumnPinningChange: (event) => {
1697
+ callbacks.onColumnPinningChange?.(event);
1698
+ const [columnId, ...others] = event.columnIds;
1699
+ if (columnId === void 0 || others.length > 0) {
1700
+ return;
1701
+ }
1702
+ const column = columnOf(columnId);
1703
+ if (column === void 0) {
1704
+ return;
1705
+ }
1706
+ const pin = resolveColumnPin(column, event.pinning);
1707
+ announce(
1708
+ pin === "none" ? messages.columnUnpinned(columnName(columnId)) : messages.columnPinned(columnName(columnId), pin)
1709
+ );
1710
+ },
1633
1711
  /** A toggle, a stack, or a clear back to "none" each get their own. */
1634
1712
  onColumnSortChange: (event) => {
1635
1713
  callbacks.onColumnSortChange?.(event);
@@ -1977,20 +2055,27 @@ import {
1977
2055
  import { useLayoutEffect as useLayoutEffect3, useRef as useRef5 } from "react";
1978
2056
  import { createPortal as createPortal3 } from "react-dom";
1979
2057
  import {
1980
- attachOverlay
2058
+ attachOverlay,
2059
+ writingDirection as writingDirection4
1981
2060
  } from "@gridkitjs/dom";
1982
2061
  import { jsx as jsx11 } from "react/jsx-runtime";
1983
2062
  var ANCHOR_GAP = 4;
1984
2063
  function attachedFocus(focus) {
1985
2064
  return typeof focus === "object" && !(focus instanceof HTMLElement) ? focus.current ?? "first" : focus;
1986
2065
  }
1987
- function overlayThemeClassName(element) {
2066
+ function themeClassNameOf(element) {
1988
2067
  const scope = element?.closest(".gridkit-light, .gridkit-dark");
1989
2068
  if (scope === null || scope === void 0) {
1990
2069
  return "";
1991
2070
  }
1992
2071
  return scope.classList.contains("gridkit-dark") ? "gridkit-dark" : "gridkit-light";
1993
2072
  }
2073
+ function overlayScope(element) {
2074
+ return {
2075
+ themeClassName: themeClassNameOf(element),
2076
+ direction: writingDirection4(element ?? document.documentElement)
2077
+ };
2078
+ }
1994
2079
  function Overlay({
1995
2080
  anchor,
1996
2081
  placement,
@@ -2001,7 +2086,7 @@ function Overlay({
2001
2086
  returnFocusFallback,
2002
2087
  ignoreScrollAfterInput,
2003
2088
  trapFocus,
2004
- themeClassName,
2089
+ scope,
2005
2090
  onDismiss,
2006
2091
  children
2007
2092
  }) {
@@ -2045,7 +2130,8 @@ function Overlay({
2045
2130
  "div",
2046
2131
  {
2047
2132
  ref: panelRef,
2048
- className: classNames("gridkit-overlay", themeClassName),
2133
+ className: classNames("gridkit-overlay", scope.themeClassName),
2134
+ dir: scope.direction,
2049
2135
  children
2050
2136
  }
2051
2137
  ),
@@ -2153,7 +2239,7 @@ function MenuItem({
2153
2239
  function GridMenu({
2154
2240
  entries,
2155
2241
  label,
2156
- themeClassName,
2242
+ scope,
2157
2243
  onRun,
2158
2244
  onClose,
2159
2245
  onCloseSubmenu,
@@ -2273,14 +2359,14 @@ function GridMenu({
2273
2359
  placement: "right-start",
2274
2360
  offset: submenu.offset,
2275
2361
  initialFocus: submenu.focus,
2276
- themeClassName,
2362
+ scope,
2277
2363
  onDismiss: closeSubmenu,
2278
2364
  children: /* @__PURE__ */ jsx13(
2279
2365
  GridMenu,
2280
2366
  {
2281
2367
  entries: openEntry.items,
2282
2368
  label: openEntry.label,
2283
- themeClassName,
2369
+ scope,
2284
2370
  onRun,
2285
2371
  onClose,
2286
2372
  onCloseSubmenu: closeSubmenu,
@@ -2309,14 +2395,14 @@ function GridContextMenu({
2309
2395
  gap: menu.anchor instanceof Element ? ANCHOR_GAP : 0,
2310
2396
  returnFocusTo: menu.cell ?? void 0,
2311
2397
  returnFocusFallback,
2312
- themeClassName: menu.themeClassName,
2398
+ scope: menu.scope,
2313
2399
  onDismiss: close,
2314
2400
  children: /* @__PURE__ */ jsx14(
2315
2401
  GridMenu,
2316
2402
  {
2317
2403
  entries: menu.entries,
2318
2404
  label: menu.label,
2319
- themeClassName: menu.themeClassName,
2405
+ scope: menu.scope,
2320
2406
  onRun: run,
2321
2407
  onClose: close
2322
2408
  }
@@ -2338,7 +2424,7 @@ import {
2338
2424
  isSameCell,
2339
2425
  resolveMenu
2340
2426
  } from "@gridkitjs/core";
2341
- import { hasContextMenu } from "@gridkitjs/core/renderer";
2427
+ import { hasContextMenu, pinnedWidths } from "@gridkitjs/core/renderer";
2342
2428
  import {
2343
2429
  attachContextMenuTrigger
2344
2430
  } from "@gridkitjs/dom";
@@ -2352,7 +2438,8 @@ import {
2352
2438
  bodyCellFrom as bodyCellFrom2,
2353
2439
  bodyRowFrom as bodyRowFrom2,
2354
2440
  findBodyRow as findBodyRow2,
2355
- groupRowFrom as groupRowFrom2
2441
+ groupRowFrom as groupRowFrom2,
2442
+ writingDirection as writingDirection5
2356
2443
  } from "@gridkitjs/dom";
2357
2444
  function headerCell(parts, columnIndex) {
2358
2445
  const element = parts.headerTable?.tHead?.rows[0]?.cells[columnIndex];
@@ -2362,24 +2449,46 @@ function bodyCell(parts, rowIndex, columnIndex) {
2362
2449
  const element = findBodyRow2(parts.bodyTable, rowIndex)?.cells[columnIndex];
2363
2450
  return element === void 0 ? null : { element, focus: bodyFocus2(rowIndex, columnIndex) };
2364
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
+ }
2365
2455
  function viewOf(element, parts) {
2366
- const root = parts.root?.getBoundingClientRect();
2367
- if (root === void 0) {
2456
+ const { scroller } = parts;
2457
+ if (scroller === null) {
2368
2458
  return null;
2369
2459
  }
2370
- const body = parts.body?.contains(element) === true ? parts.body.getBoundingClientRect() : root;
2371
- const left = Math.max(root.left, body.left);
2372
- const top = Math.max(root.top, body.top);
2460
+ const view = scroller.getBoundingClientRect();
2461
+ let { top, bottom, left, right } = view;
2462
+ if (parts.body?.contains(element) === true) {
2463
+ top = Math.max(
2464
+ top,
2465
+ parts.headerTable?.getBoundingClientRect().bottom ?? top
2466
+ );
2467
+ bottom = Math.min(
2468
+ bottom,
2469
+ parts.footerTable?.getBoundingClientRect().top ?? bottom
2470
+ );
2471
+ }
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
+ }
2373
2479
  return new DOMRect(
2374
2480
  left,
2375
2481
  top,
2376
- Math.max(0, Math.min(root.right, body.right) - left),
2377
- Math.max(0, Math.min(root.bottom, body.bottom) - top)
2482
+ Math.max(0, right - left),
2483
+ Math.max(0, bottom - top)
2378
2484
  );
2379
2485
  }
2380
2486
  function clamp(value, min, max) {
2381
2487
  return Math.min(Math.max(value, min), max);
2382
2488
  }
2489
+ function inlineStartOf(element, box) {
2490
+ return writingDirection5(element) === "rtl" ? box.right : box.left;
2491
+ }
2383
2492
  function onCell(target, cell, parts) {
2384
2493
  if (cell === null) {
2385
2494
  return null;
@@ -2393,14 +2502,22 @@ function onCell(target, cell, parts) {
2393
2502
  target,
2394
2503
  cell,
2395
2504
  anchor: {
2396
- x: clamp(box.left, view.left, view.right),
2505
+ x: clamp(inlineStartOf(cell.element, box), view.left, view.right),
2397
2506
  y: clamp(box.bottom, view.top, view.bottom)
2398
2507
  }
2399
2508
  };
2400
2509
  }
2401
- function onBody(body) {
2402
- const { left, top } = body.getBoundingClientRect();
2403
- return { target: { area: "body" }, cell: null, anchor: { x: left, y: top } };
2510
+ function onBody(body, parts) {
2511
+ const box = body.getBoundingClientRect();
2512
+ const view = viewOf(body, parts) ?? box;
2513
+ return {
2514
+ target: { area: "body" },
2515
+ cell: null,
2516
+ anchor: {
2517
+ x: inlineStartOf(body, view),
2518
+ y: clamp(box.top, view.top, view.bottom)
2519
+ }
2520
+ };
2404
2521
  }
2405
2522
  function headerPlaceAt(element, parts) {
2406
2523
  const cell = element.closest("th[data-gridkit-column]");
@@ -2439,7 +2556,7 @@ function bodyPlaceAt(element, parts) {
2439
2556
  parts
2440
2557
  ) : null;
2441
2558
  }
2442
- return bodyRowFrom2(element) === null ? onBody(body) : null;
2559
+ return bodyRowFrom2(element) === null ? onBody(body, parts) : null;
2443
2560
  }
2444
2561
  function placeAt(element, parts) {
2445
2562
  return headerPlaceAt(element, parts) ?? bodyPlaceAt(element, parts);
@@ -2470,16 +2587,18 @@ function placeOf(target, parts) {
2470
2587
  return onCell(target, bodyCell(parts, rowIndex, 0), parts);
2471
2588
  }
2472
2589
  case "body":
2473
- return parts.body === null ? null : onBody(parts.body);
2590
+ return parts.body === null ? null : onBody(parts.body, parts);
2474
2591
  }
2475
2592
  }
2476
2593
 
2477
2594
  // src/DataGrid/contextMenu/useContextMenu.ts
2478
2595
  function useContextMenu({
2479
2596
  rootRef,
2597
+ scrollRef,
2480
2598
  headerTableRef,
2481
2599
  bodyTableRef,
2482
- bodyScrollRef,
2600
+ bodyRef,
2601
+ footerTableRef,
2483
2602
  contextMenu,
2484
2603
  overlay,
2485
2604
  controller,
@@ -2495,11 +2614,13 @@ function useContextMenu({
2495
2614
  function parts() {
2496
2615
  const { columns, pageRows } = controller.getView();
2497
2616
  return {
2498
- root: rootRef.current,
2617
+ scroller: scrollRef.current,
2499
2618
  headerTable: headerTableRef.current,
2500
2619
  bodyTable: bodyTableRef.current,
2501
- body: bodyScrollRef.current,
2620
+ body: bodyRef.current,
2621
+ footerTable: footerTableRef.current,
2502
2622
  columns,
2623
+ pinnedWidths: pinnedWidths(columns),
2503
2624
  pageRows
2504
2625
  };
2505
2626
  }
@@ -2571,7 +2692,7 @@ function useContextMenu({
2571
2692
  label: labelOf(target),
2572
2693
  anchor: point ?? anchor,
2573
2694
  cell: cell?.element ?? null,
2574
- themeClassName: overlayThemeClassName(rootRef.current)
2695
+ scope: overlayScope(rootRef.current)
2575
2696
  }
2576
2697
  });
2577
2698
  return true;
@@ -2823,7 +2944,7 @@ function useMenuButton({
2823
2944
  setState({
2824
2945
  kind: "open",
2825
2946
  anchor: button,
2826
- themeClassName: overlayThemeClassName(button),
2947
+ scope: overlayScope(button),
2827
2948
  gap: gap(button),
2828
2949
  focusItem: onLast ? itemCount - 1 : 0
2829
2950
  });
@@ -2914,14 +3035,14 @@ function OperatorMenuButton({
2914
3035
  placement: "right-start",
2915
3036
  gap: state.gap,
2916
3037
  returnFocusTo: state.anchor,
2917
- themeClassName: state.themeClassName,
3038
+ scope: state.scope,
2918
3039
  onDismiss: close,
2919
3040
  children: /* @__PURE__ */ jsx16(
2920
3041
  GridMenu,
2921
3042
  {
2922
3043
  entries,
2923
3044
  label,
2924
- themeClassName: state.themeClassName,
3045
+ scope: state.scope,
2925
3046
  behaviourRef,
2926
3047
  onRun: (item) => {
2927
3048
  item.run();
@@ -3777,7 +3898,7 @@ function GridPanels({
3777
3898
  returnFocusFallback,
3778
3899
  ignoreScrollAfterInput: true,
3779
3900
  trapFocus,
3780
- themeClassName: panel.themeClassName,
3901
+ scope: panel.scope,
3781
3902
  onDismiss: close,
3782
3903
  children: /* @__PURE__ */ jsx22(
3783
3904
  Panel,
@@ -3824,6 +3945,9 @@ function panelApi(panels, controller) {
3824
3945
 
3825
3946
  // src/DataGrid/panels/useGridPanels.ts
3826
3947
  import { useRef as useRef16 } from "react";
3948
+ import {
3949
+ writingDirection as writingDirection6
3950
+ } from "@gridkitjs/dom";
3827
3951
  function toolbarItem(root, itemId) {
3828
3952
  const items = root.querySelectorAll(
3829
3953
  ":scope > .gridkit-toolbar > [data-gridkit-toolbar-item]"
@@ -3860,9 +3984,9 @@ function useGridPanels({
3860
3984
  returnFocusTo: element
3861
3985
  };
3862
3986
  }
3863
- const { right, top } = root.getBoundingClientRect();
3987
+ const { left, right, top } = root.getBoundingClientRect();
3864
3988
  return {
3865
- anchor: { x: right, y: top },
3989
+ anchor: { x: writingDirection6(root) === "rtl" ? left : right, y: top },
3866
3990
  placement: "bottom-end",
3867
3991
  returnFocusTo: void 0
3868
3992
  };
@@ -3883,7 +4007,7 @@ function useGridPanels({
3883
4007
  kind,
3884
4008
  target,
3885
4009
  ...placeFor(root, target),
3886
- themeClassName: overlayThemeClassName(root)
4010
+ scope: overlayScope(root)
3887
4011
  }
3888
4012
  });
3889
4013
  },
@@ -3945,14 +4069,14 @@ function ToolbarMenuButton({
3945
4069
  gap: state.gap,
3946
4070
  returnFocusTo: state.anchor,
3947
4071
  returnFocusFallback,
3948
- themeClassName: state.themeClassName,
4072
+ scope: state.scope,
3949
4073
  onDismiss: close,
3950
4074
  children: /* @__PURE__ */ jsx23(
3951
4075
  GridMenu,
3952
4076
  {
3953
4077
  entries,
3954
4078
  label,
3955
- themeClassName: state.themeClassName,
4079
+ scope: state.scope,
3956
4080
  behaviourRef,
3957
4081
  onRun: (item) => {
3958
4082
  item.run();
@@ -4289,13 +4413,15 @@ function useColumnDrag({
4289
4413
  order,
4290
4414
  groupBy,
4291
4415
  groupByDraggableIds,
4416
+ pinOf,
4292
4417
  onDrop
4293
4418
  }) {
4294
4419
  const drag = useDragReorder({
4295
4420
  resolveTarget: (clientX, clientY, movedId) => resolveColumnDropTarget(clientX, clientY, movedId, {
4296
4421
  order,
4297
4422
  groupBy,
4298
- groupByDraggableIds
4423
+ groupByDraggableIds,
4424
+ pinOf
4299
4425
  }),
4300
4426
  onDrop
4301
4427
  });
@@ -4413,12 +4539,31 @@ function useColumnResize({
4413
4539
  return { activeColumnId, startResize, sizeToContent, nudge };
4414
4540
  }
4415
4541
 
4416
- // src/DataGrid/useElementWidth.ts
4542
+ // src/DataGrid/useElementHeight.ts
4417
4543
  import { useLayoutEffect as useLayoutEffect14, useState as useState15 } from "react";
4544
+ import { observeElementHeight } from "@gridkitjs/dom";
4545
+ function useElementHeight(ref, enabled) {
4546
+ const [height, setHeight] = useState15(null);
4547
+ useLayoutEffect14(() => {
4548
+ const element = ref.current;
4549
+ if (element === null || !enabled) {
4550
+ return void 0;
4551
+ }
4552
+ const disconnect = observeElementHeight(element, setHeight);
4553
+ return () => {
4554
+ disconnect();
4555
+ setHeight(null);
4556
+ };
4557
+ }, [ref, enabled]);
4558
+ return enabled ? height : null;
4559
+ }
4560
+
4561
+ // src/DataGrid/useElementWidth.ts
4562
+ import { useLayoutEffect as useLayoutEffect15, useState as useState16 } from "react";
4418
4563
  import { observeElementWidth } from "@gridkitjs/dom";
4419
4564
  function useElementWidth(ref, enabled) {
4420
- const [width, setWidth] = useState15(null);
4421
- useLayoutEffect14(() => {
4565
+ const [width, setWidth] = useState16(null);
4566
+ useLayoutEffect15(() => {
4422
4567
  const element = ref.current;
4423
4568
  if (element === null || !enabled) {
4424
4569
  return void 0;
@@ -4429,12 +4574,12 @@ function useElementWidth(ref, enabled) {
4429
4574
  }
4430
4575
 
4431
4576
  // src/DataGrid/useGridController.ts
4432
- import { useState as useState16, useSyncExternalStore as useSyncExternalStore2 } from "react";
4577
+ import { useState as useState17, useSyncExternalStore as useSyncExternalStore2 } from "react";
4433
4578
  import {
4434
4579
  createGridController
4435
4580
  } from "@gridkitjs/core";
4436
4581
  function useGridController(options) {
4437
- const [controller] = useState16(
4582
+ const [controller] = useState17(
4438
4583
  () => createGridController(options)
4439
4584
  );
4440
4585
  controller.setOptions(options);
@@ -4482,11 +4627,11 @@ function useInfiniteScroll({
4482
4627
  }
4483
4628
 
4484
4629
  // src/DataGrid/useLiveAnnouncer.ts
4485
- import { useCallback as useCallback3, useLayoutEffect as useLayoutEffect15, useRef as useRef21 } from "react";
4630
+ import { useCallback as useCallback3, useLayoutEffect as useLayoutEffect16, useRef as useRef21 } from "react";
4486
4631
  import { createLiveAnnouncer } from "@gridkitjs/dom";
4487
4632
  function useLiveAnnouncer(containerRef) {
4488
4633
  const announcer = useRef21(null);
4489
- useLayoutEffect15(() => {
4634
+ useLayoutEffect16(() => {
4490
4635
  const container = containerRef.current;
4491
4636
  if (container === null) {
4492
4637
  return void 0;
@@ -4504,7 +4649,7 @@ function useLiveAnnouncer(containerRef) {
4504
4649
  }
4505
4650
 
4506
4651
  // src/DataGrid/useRowVirtualizer.ts
4507
- import { useLayoutEffect as useLayoutEffect16, useRef as useRef22, useState as useState17 } from "react";
4652
+ import { useLayoutEffect as useLayoutEffect17, useRef as useRef22, useState as useState18 } from "react";
4508
4653
  import {
4509
4654
  bodyRowFrom as bodyRowFrom3,
4510
4655
  createRowVirtualizer as createRowVirtualizer2
@@ -4539,25 +4684,25 @@ function ignoreRow() {
4539
4684
  function useRowVirtualizer({
4540
4685
  enabled,
4541
4686
  rows,
4542
- bodyScrollRef,
4687
+ scrollRef,
4543
4688
  bodyTableRef,
4544
4689
  estimatedRowHeight,
4545
4690
  overscan
4546
4691
  }) {
4547
- const [virtualizer, setVirtualizer] = useState17(null);
4692
+ const [virtualizer, setVirtualizer] = useState18(null);
4548
4693
  const instance = useRef22(null);
4549
4694
  const rowCount = useRef22(rows.length);
4550
- const [rowWindow, setRowWindow] = useState17(enabled ? NO_ROWS3 : ALL_ROWS);
4695
+ const [rowWindow, setRowWindow] = useState18(enabled ? NO_ROWS3 : ALL_ROWS);
4551
4696
  if (!enabled && rowWindow.kind !== "allRows") {
4552
4697
  setRowWindow(ALL_ROWS);
4553
4698
  }
4554
- useLayoutEffect16(() => {
4699
+ useLayoutEffect17(() => {
4555
4700
  rowCount.current = rows.length;
4556
4701
  instance.current?.setRowCount(rows.length);
4557
4702
  instance.current?.resetHeights();
4558
4703
  }, [rows]);
4559
- useLayoutEffect16(() => {
4560
- const element = bodyScrollRef.current;
4704
+ useLayoutEffect17(() => {
4705
+ const element = scrollRef.current;
4561
4706
  if (!enabled || element === null) {
4562
4707
  return void 0;
4563
4708
  }
@@ -4575,7 +4720,7 @@ function useRowVirtualizer({
4575
4720
  return () => {
4576
4721
  created.destroy();
4577
4722
  };
4578
- }, [enabled, bodyScrollRef, bodyTableRef, estimatedRowHeight, overscan]);
4723
+ }, [enabled, scrollRef, bodyTableRef, estimatedRowHeight, overscan]);
4579
4724
  const range = rangeOf(rowWindow, rows.length);
4580
4725
  return {
4581
4726
  startIndex: range.startIndex,
@@ -4615,6 +4760,19 @@ function selectedRowsReader(controller) {
4615
4760
  return last.selected;
4616
4761
  };
4617
4762
  }
4763
+ function tablesStyle(height, headerHeight, footerHeight, pinned) {
4764
+ const heights = height === void 0 ? {} : {
4765
+ "--gridkit-body-height": typeof height === "number" ? `${String(height)}px` : height,
4766
+ ...headerHeight === null ? {} : { "--gridkit-header-height": `${String(headerHeight)}px` },
4767
+ ...footerHeight === null ? {} : { "--gridkit-footer-height": `${String(footerHeight)}px` }
4768
+ };
4769
+ const widths = pinned.start === 0 && pinned.end === 0 ? {} : {
4770
+ "--gridkit-pinned-start-width": `${String(pinned.start)}px`,
4771
+ "--gridkit-pinned-end-width": `${String(pinned.end)}px`
4772
+ };
4773
+ const style = { ...heights, ...widths };
4774
+ return Object.keys(style).length === 0 ? void 0 : style;
4775
+ }
4618
4776
  function DataGrid(props) {
4619
4777
  const {
4620
4778
  borders,
@@ -4651,9 +4809,10 @@ function DataGrid(props) {
4651
4809
  const gridRef = useRef23(null);
4652
4810
  const headerTableRef = useRef23(null);
4653
4811
  const bodyTableRef = useRef23(null);
4654
- const bodyScrollRef = useRef23(null);
4812
+ const bodyRef = useRef23(null);
4813
+ const footerTableRef = useRef23(null);
4655
4814
  const sentinelRef = useRef23(null);
4656
- const viewportWidth = useElementWidth(viewportRef, resizeMode === "fit");
4815
+ const viewportWidth = useElementWidth(gridRef, resizeMode === "fit");
4657
4816
  const subscribersRef = useRef23(/* @__PURE__ */ new Set());
4658
4817
  const gridId = useId2();
4659
4818
  const announce = useLiveAnnouncer(viewportRef);
@@ -4672,12 +4831,12 @@ function DataGrid(props) {
4672
4831
  columnOf
4673
4832
  })
4674
4833
  });
4675
- const [readPagination] = useState18(() => paginationReader(controller));
4676
- const [readSelectedRows] = useState18(() => selectedRowsReader(controller));
4834
+ const [readPagination] = useState19(() => paginationReader(controller));
4835
+ const [readSelectedRows] = useState19(() => selectedRowsReader(controller));
4677
4836
  const virtualizer = useRowVirtualizer({
4678
4837
  enabled: virtualized,
4679
4838
  rows: view.pageRows,
4680
- bodyScrollRef,
4839
+ scrollRef: gridRef,
4681
4840
  bodyTableRef,
4682
4841
  estimatedRowHeight,
4683
4842
  overscan
@@ -4698,7 +4857,7 @@ function DataGrid(props) {
4698
4857
  }
4699
4858
  }, [paginated, hasInfiniteScroll]);
4700
4859
  useInfiniteScroll({
4701
- rootRef: bodyScrollRef,
4860
+ rootRef: gridRef,
4702
4861
  sentinelRef,
4703
4862
  config: infiniteScroll
4704
4863
  });
@@ -4779,20 +4938,36 @@ function DataGrid(props) {
4779
4938
  ),
4780
4939
  [view.columns]
4781
4940
  );
4941
+ function pinOf(columnId) {
4942
+ const column = definitions.get(columnId);
4943
+ return column === void 0 ? "none" : resolveColumnPin2(column, state.columnPinning);
4944
+ }
4782
4945
  function handleDrop(target, movedId) {
4783
4946
  if (target.kind === "group-by") {
4784
4947
  controller.moveGroupBy(movedId, target.beforeColumnId);
4785
4948
  return;
4786
4949
  }
4787
- const next = moveColumnBefore(orderedIds, movedId, target.beforeId);
4950
+ const next = moveColumnInPinGroup(
4951
+ orderedIds,
4952
+ pinOf,
4953
+ movedId,
4954
+ target.beforeId
4955
+ );
4788
4956
  if (next === orderedIds) {
4789
4957
  return;
4790
4958
  }
4791
4959
  controller.moveColumn(movedId, target.beforeId);
4792
- const shown = next.filter((id) => displayedIds.includes(id));
4793
- 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);
4794
4965
  announce(
4795
- messages.columnMoved(columnName(movedId), position + 1, shown.length)
4966
+ messages.columnMoved(
4967
+ columnName(movedId),
4968
+ position + 1,
4969
+ displayedIds.length
4970
+ )
4796
4971
  );
4797
4972
  nav.focusCell(headerFocus3(position));
4798
4973
  }
@@ -4800,6 +4975,7 @@ function DataGrid(props) {
4800
4975
  order: displayedIds,
4801
4976
  groupBy: state.groupBy,
4802
4977
  groupByDraggableIds,
4978
+ pinOf,
4803
4979
  onDrop: handleDrop
4804
4980
  });
4805
4981
  const draggedColumnAlreadyGrouped = drag.draggedColumnId !== null && state.groupBy.some((entry) => entry.columnId === drag.draggedColumnId);
@@ -4820,9 +4996,11 @@ function DataGrid(props) {
4820
4996
  const multiselectable = selection.rowMode === "multiple" || selection.columnMode === "multiple";
4821
4997
  const contextMenu = useContextMenu({
4822
4998
  rootRef: viewportRef,
4999
+ scrollRef: gridRef,
4823
5000
  headerTableRef,
4824
5001
  bodyTableRef,
4825
- bodyScrollRef,
5002
+ bodyRef,
5003
+ footerTableRef,
4826
5004
  contextMenu: props.contextMenu,
4827
5005
  overlay,
4828
5006
  controller,
@@ -4855,6 +5033,7 @@ function DataGrid(props) {
4855
5033
  getColumnSizing: () => controller.getState().columnSizing,
4856
5034
  getColumnOrder: () => controller.getState().columnOrder,
4857
5035
  getColumnVisibility: () => controller.getState().columnVisibility,
5036
+ getColumnPinning: () => controller.getState().columnPinning,
4858
5037
  getColumnSort: () => controller.getState().columnSort,
4859
5038
  getFilter: () => controller.getState().filter,
4860
5039
  getGroupBy: () => controller.getState().groupBy,
@@ -4881,6 +5060,7 @@ function DataGrid(props) {
4881
5060
  setPageSize: controller.setPageSize,
4882
5061
  showColumns: controller.showColumns,
4883
5062
  hideColumns: controller.hideColumns,
5063
+ pinColumn: controller.pinColumn,
4884
5064
  setFilter: controller.setFilter,
4885
5065
  setColumnSort: controller.setColumnSort,
4886
5066
  setGroupBy: controller.setGroupBy,
@@ -4889,6 +5069,7 @@ function DataGrid(props) {
4889
5069
  setColumnSizing: controller.setColumnSizing,
4890
5070
  setColumnOrder: controller.setColumnOrder,
4891
5071
  setColumnVisibility: controller.setColumnVisibility,
5072
+ setColumnPinning: controller.setColumnPinning,
4892
5073
  setRowSelection: controller.setRowSelection,
4893
5074
  setColumnSelection: controller.setColumnSelection,
4894
5075
  setCellSelection: controller.setCellSelection,
@@ -4947,181 +5128,201 @@ function DataGrid(props) {
4947
5128
  selection.cellMode === false ? "" : "gridkit-selectable-cells"
4948
5129
  );
4949
5130
  const hasFooter = aggregates.length > 0;
4950
- return /* @__PURE__ */ jsxs19("div", { className: "gridkit-data-grid-viewport", ref: viewportRef, children: [
4951
- /* @__PURE__ */ jsx26(
4952
- GridToolbar,
4953
- {
4954
- toolbar: props.toolbar,
4955
- renderItem: props.renderToolbarItem,
4956
- gridId,
4957
- controller,
4958
- commands,
4959
- messages,
4960
- announce
4961
- }
4962
- ),
4963
- showGroupByBar && /* @__PURE__ */ jsx26(
4964
- GroupByBar,
4965
- {
4966
- columns: view.columns,
4967
- definitions,
4968
- groupBy: state.groupBy,
4969
- controller,
4970
- columnName,
4971
- headerDragEligible: dragEligibleForGroupBy,
4972
- headerDragBlocked: draggedColumnAlreadyGrouped,
4973
- headerDropTarget: headerGroupByDropTarget,
4974
- messages
4975
- }
4976
- ),
4977
- /* @__PURE__ */ jsxs19(
4978
- "div",
4979
- {
4980
- ref: gridRef,
4981
- id: gridId,
4982
- className: "gridkit-data-grid-tables",
4983
- role: state.groupBy.length > 0 ? "treegrid" : "grid",
4984
- "aria-rowcount": view.displayRows.length + (hasFooter ? 2 : 1),
4985
- "aria-colcount": view.columns.length,
4986
- ...ariaAttr(multiselectable, "aria-multiselectable", true),
4987
- ...ariaAttr(labelledBy !== void 0, "aria-labelledby", labelledBy),
4988
- ...ariaAttr(
4989
- labelledBy === void 0 && label !== void 0,
4990
- "aria-label",
4991
- label
4992
- ),
4993
- onKeyDown: (event) => {
4994
- if (!isOwnEvent(event)) return;
4995
- handleCopyKey(event);
4996
- if (event.key === "Escape") {
4997
- if (drag.draggedColumnId !== null || resize.activeColumnId !== null)
4998
- return;
4999
- selection.clear();
5000
- return;
5131
+ const headerHeight = useElementHeight(headerTableRef, height !== void 0);
5132
+ const footerHeight = useElementHeight(
5133
+ footerTableRef,
5134
+ height !== void 0 && hasFooter
5135
+ );
5136
+ return /* @__PURE__ */ jsxs19(
5137
+ "div",
5138
+ {
5139
+ className: "gridkit-data-grid-viewport",
5140
+ ref: viewportRef,
5141
+ tabIndex: -1,
5142
+ children: [
5143
+ /* @__PURE__ */ jsx26(
5144
+ GridToolbar,
5145
+ {
5146
+ toolbar: props.toolbar,
5147
+ renderItem: props.renderToolbarItem,
5148
+ gridId,
5149
+ controller,
5150
+ commands,
5151
+ messages,
5152
+ announce
5001
5153
  }
5002
- if ((event.ctrlKey || event.metaKey) && (event.key === "a" || event.key === "A")) {
5003
- if (selection.rowMode !== "multiple") return;
5004
- event.preventDefault();
5005
- selection.selectAllRows();
5154
+ ),
5155
+ showGroupByBar && /* @__PURE__ */ jsx26(
5156
+ GroupByBar,
5157
+ {
5158
+ columns: view.columns,
5159
+ definitions,
5160
+ groupBy: state.groupBy,
5161
+ controller,
5162
+ columnName,
5163
+ headerDragEligible: dragEligibleForGroupBy,
5164
+ headerDragBlocked: draggedColumnAlreadyGrouped,
5165
+ headerDropTarget: headerGroupByDropTarget,
5166
+ messages
5006
5167
  }
5007
- },
5008
- children: [
5009
- /* @__PURE__ */ jsxs19(
5010
- "table",
5011
- {
5012
- ref: headerTableRef,
5013
- role: "presentation",
5014
- style: { width: totalColumnWidth(view.columns) },
5015
- className: classNames(gridTableClassName, "gridkit-data-grid-header"),
5016
- children: [
5017
- /* @__PURE__ */ jsx26(GridColgroup, { columns: view.columns }),
5018
- /* @__PURE__ */ jsx26(
5019
- GridHeader,
5020
- {
5021
- columns: view.columns,
5022
- resize,
5023
- drag,
5024
- controller,
5025
- state,
5026
- sortableColumns,
5027
- groupableColumns,
5028
- groupToggleIconColumns,
5029
- headerMenu: contextMenu.opens("header"),
5030
- panels,
5031
- messages,
5032
- nav,
5033
- selection
5034
- }
5035
- )
5036
- ]
5037
- }
5038
- ),
5039
- /* @__PURE__ */ jsx26(
5040
- "div",
5041
- {
5042
- className: "gridkit-data-grid-body",
5043
- ref: bodyScrollRef,
5044
- style: height === void 0 ? void 0 : {
5045
- "--gridkit-body-height": typeof height === "number" ? `${String(height)}px` : height
5046
- },
5047
- children: /* @__PURE__ */ jsxs19(
5168
+ ),
5169
+ /* @__PURE__ */ jsxs19(
5170
+ "div",
5171
+ {
5172
+ ref: gridRef,
5173
+ id: gridId,
5174
+ className: "gridkit-data-grid-tables",
5175
+ role: state.groupBy.length > 0 ? "treegrid" : "grid",
5176
+ "aria-rowcount": view.displayRows.length + (hasFooter ? 2 : 1),
5177
+ "aria-colcount": view.columns.length,
5178
+ tabIndex: -1,
5179
+ style: tablesStyle(
5180
+ height,
5181
+ headerHeight,
5182
+ footerHeight,
5183
+ pinnedWidths2(view.columns)
5184
+ ),
5185
+ ...ariaAttr(multiselectable, "aria-multiselectable", true),
5186
+ ...ariaAttr(labelledBy !== void 0, "aria-labelledby", labelledBy),
5187
+ ...ariaAttr(
5188
+ labelledBy === void 0 && label !== void 0,
5189
+ "aria-label",
5190
+ label
5191
+ ),
5192
+ onKeyDown: (event) => {
5193
+ if (!isOwnEvent(event)) return;
5194
+ handleCopyKey(event);
5195
+ if (event.key === "Escape") {
5196
+ if (drag.draggedColumnId !== null || resize.activeColumnId !== null)
5197
+ return;
5198
+ selection.clear();
5199
+ return;
5200
+ }
5201
+ if ((event.ctrlKey || event.metaKey) && (event.key === "a" || event.key === "A")) {
5202
+ if (selection.rowMode !== "multiple") return;
5203
+ event.preventDefault();
5204
+ selection.selectAllRows();
5205
+ }
5206
+ },
5207
+ children: [
5208
+ /* @__PURE__ */ jsxs19(
5048
5209
  "table",
5049
5210
  {
5050
- ref: bodyTableRef,
5211
+ ref: headerTableRef,
5051
5212
  role: "presentation",
5052
5213
  style: { width: totalColumnWidth(view.columns) },
5053
- className: gridTableClassName,
5214
+ className: classNames(gridTableClassName, "gridkit-data-grid-header"),
5054
5215
  children: [
5055
5216
  /* @__PURE__ */ jsx26(GridColgroup, { columns: view.columns }),
5056
5217
  /* @__PURE__ */ jsx26(
5057
- GridBody,
5218
+ GridHeader,
5058
5219
  {
5059
5220
  columns: view.columns,
5060
- definitions,
5061
- rows: view.pageRows,
5062
- activeColumnId: resize.activeColumnId,
5063
- nav,
5064
- selection,
5221
+ resize,
5222
+ drag,
5065
5223
  controller,
5224
+ state,
5225
+ sortableColumns,
5226
+ groupableColumns,
5227
+ groupToggleIconColumns,
5228
+ headerMenu: contextMenu.opens("header"),
5229
+ panels,
5230
+ messages,
5231
+ nav,
5232
+ selection
5233
+ }
5234
+ )
5235
+ ]
5236
+ }
5237
+ ),
5238
+ /* @__PURE__ */ jsx26(
5239
+ "div",
5240
+ {
5241
+ className: "gridkit-data-grid-body",
5242
+ ref: bodyRef,
5243
+ role: "rowgroup",
5244
+ tabIndex: -1,
5245
+ children: /* @__PURE__ */ jsxs19(
5246
+ "table",
5247
+ {
5248
+ ref: bodyTableRef,
5249
+ role: "presentation",
5250
+ style: { width: totalColumnWidth(view.columns) },
5251
+ className: gridTableClassName,
5252
+ children: [
5253
+ /* @__PURE__ */ jsx26(GridColgroup, { columns: view.columns }),
5254
+ /* @__PURE__ */ jsx26(
5255
+ GridBody,
5256
+ {
5257
+ columns: view.columns,
5258
+ definitions,
5259
+ rows: view.pageRows,
5260
+ activeColumnId: resize.activeColumnId,
5261
+ nav,
5262
+ selection,
5263
+ controller,
5264
+ aggregates,
5265
+ groupAggregateDisplay,
5266
+ virtualRange: virtualized ? virtualizer : null,
5267
+ infiniteScroll,
5268
+ sentinelRef,
5269
+ locale,
5270
+ getRowProps,
5271
+ onRowClick,
5272
+ onRowDoubleClick,
5273
+ messages,
5274
+ cellMenu: contextMenu.opens("cell"),
5275
+ groupMenu: contextMenu.opens("group")
5276
+ }
5277
+ )
5278
+ ]
5279
+ }
5280
+ )
5281
+ }
5282
+ ),
5283
+ hasFooter && /* @__PURE__ */ jsxs19(
5284
+ "table",
5285
+ {
5286
+ ref: footerTableRef,
5287
+ role: "presentation",
5288
+ style: { width: totalColumnWidth(view.columns) },
5289
+ className: classNames(
5290
+ gridTableClassName,
5291
+ "gridkit-data-grid-footer"
5292
+ ),
5293
+ children: [
5294
+ /* @__PURE__ */ jsx26(GridColgroup, { columns: view.columns }),
5295
+ /* @__PURE__ */ jsx26(
5296
+ GridFooter,
5297
+ {
5298
+ columns: view.columns,
5066
5299
  aggregates,
5067
- groupAggregateDisplay,
5068
- virtualRange: virtualized ? virtualizer : null,
5069
- infiniteScroll,
5070
- sentinelRef,
5300
+ results: view.grandTotal,
5301
+ rows: view.rows.map((entry) => entry.row),
5071
5302
  locale,
5072
- getRowProps,
5073
- onRowClick,
5074
- onRowDoubleClick,
5075
- messages,
5076
- cellMenu: contextMenu.opens("cell"),
5077
- groupMenu: contextMenu.opens("group")
5303
+ ariaRowIndex: view.displayRows.length + 2
5078
5304
  }
5079
5305
  )
5080
5306
  ]
5081
5307
  }
5082
5308
  )
5083
- }
5084
- ),
5085
- hasFooter && /* @__PURE__ */ jsxs19(
5086
- "table",
5087
- {
5088
- role: "presentation",
5089
- style: { width: totalColumnWidth(view.columns) },
5090
- className: classNames(
5091
- gridTableClassName,
5092
- "gridkit-data-grid-footer"
5093
- ),
5094
- children: [
5095
- /* @__PURE__ */ jsx26(GridColgroup, { columns: view.columns }),
5096
- /* @__PURE__ */ jsx26(
5097
- GridFooter,
5098
- {
5099
- columns: view.columns,
5100
- aggregates,
5101
- results: view.grandTotal,
5102
- rows: view.rows.map((entry) => entry.row),
5103
- locale,
5104
- ariaRowIndex: view.displayRows.length + 2
5105
- }
5106
- )
5107
- ]
5108
- }
5109
- )
5110
- ]
5111
- }
5112
- ),
5113
- /* @__PURE__ */ jsx26(GridContextMenu, { contextMenu }),
5114
- /* @__PURE__ */ jsx26(
5115
- GridPanels,
5116
- {
5117
- panels,
5118
- controller,
5119
- commands,
5120
- messages
5121
- }
5122
- ),
5123
- paginated && (pager?.template ? pager.template(pagerContext) : /* @__PURE__ */ jsx26(GridPager, { pager: pagerContext, config: pager, messages }))
5124
- ] });
5309
+ ]
5310
+ }
5311
+ ),
5312
+ /* @__PURE__ */ jsx26(GridContextMenu, { contextMenu }),
5313
+ /* @__PURE__ */ jsx26(
5314
+ GridPanels,
5315
+ {
5316
+ panels,
5317
+ controller,
5318
+ commands,
5319
+ messages
5320
+ }
5321
+ ),
5322
+ paginated && (pager?.template ? pager.template(pagerContext) : /* @__PURE__ */ jsx26(GridPager, { pager: pagerContext, config: pager, messages }))
5323
+ ]
5324
+ }
5325
+ );
5125
5326
  }
5126
5327
 
5127
5328
  // src/index.ts
@@ -5335,13 +5536,24 @@ function useColumnVisibilityState(gridRef) {
5335
5536
  );
5336
5537
  }
5337
5538
 
5539
+ // src/DataGrid/hooks/useColumnPinningState.ts
5540
+ import { useCallback as useCallback13 } from "react";
5541
+ var FALLBACK_PINNING = {};
5542
+ function useColumnPinningState(gridRef) {
5543
+ return useGridSnapshot(
5544
+ gridRef,
5545
+ useCallback13((api) => api.getColumnPinning(), []),
5546
+ FALLBACK_PINNING
5547
+ );
5548
+ }
5549
+
5338
5550
  // src/DataGrid/hooks/useFilterState.ts
5339
- import { useCallback as useCallback13, useState as useState19 } from "react";
5551
+ import { useCallback as useCallback14, useState as useState20 } from "react";
5340
5552
  function useFilterState(gridRef) {
5341
- const [fallback] = useState19(() => []);
5553
+ const [fallback] = useState20(() => []);
5342
5554
  const filter = useGridSnapshot(
5343
5555
  gridRef,
5344
- useCallback13((api) => api.getFilter(), []),
5556
+ useCallback14((api) => api.getFilter(), []),
5345
5557
  fallback
5346
5558
  );
5347
5559
  return {
@@ -5360,6 +5572,7 @@ export {
5360
5572
  serializeGridState,
5361
5573
  useAggregateState,
5362
5574
  useColumnOrderState,
5575
+ useColumnPinningState,
5363
5576
  useColumnSizingState,
5364
5577
  useColumnSortState,
5365
5578
  useColumnVisibilityState,