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

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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, Ref, RefObject } from 'react';
3
- import { ExportWriter, GridExportOptions, PrintOptions, CellSelectEvent as CellSelectEvent$1, CellSelectionChangeEvent as CellSelectionChangeEvent$1, ColumnDefinition as ColumnDefinition$1, ColumnSelectEvent as ColumnSelectEvent$1, ColumnSelectionChangeEvent as ColumnSelectionChangeEvent$1, ColumnsSelectEvent as ColumnsSelectEvent$1, DataColumn as DataColumn$1, GridOptions, PaginationState, SelectionCallbacks as SelectionCallbacks$1, ResolvedRow, DisplayRow, ResolvedColumn as ResolvedColumn$1, ColumnSizingState, ColumnOrderState, ColumnVisibilityState, ColumnSortState, FilterState, GroupByState, GroupExpansionState, AggregateResults, SelectionState, CellSelectionState, GridFocus, GridState, SerializedGridState, GridContextMenuTarget, GridCommandTarget, SelectedCell as SelectedCell$1, SelectedColumn as SelectedColumn$1 } from '@gridkitjs/core';
4
- export { AggregateFn, AggregateResults, AggregateSpec, AggregateState, Borders, BuiltInAggregate, CellSelectionMode, CellSelectionState, CellTemplateContext, ColumnAlignment, ColumnFilterMenuOptions, ColumnOrderEvent, ColumnOrderState, ColumnResizeEvent, ColumnSizeDefaults, ColumnSizingState, ColumnSortEntry, ColumnSortEvent, ColumnSortState, ColumnType, ColumnVisibilityEvent, ColumnVisibilityState, ColumnWrapConfig, ContextMenuOpenChangeEvent, DisplayRow, ExportFile, ExportOptions, ExportScalar, ExportWriter, FieldPath, FilterChangeEvent, FilterEntry, FilterState, FooterTemplateContext, FormatLocale, GridCommand, GridCommandEvent, GridCommandTarget, GridContextMenuOptions, GridContextMenuRequest, GridContextMenuTarget, GridExportOptions, GridFilterMenuOptions, GridFocus, GridMessages, GridOptions, GridState, GridToolbarOptions, GroupAggregateDisplay, GroupByBarVisibility, GroupByEntry, GroupByEvent, GroupByState, GroupExpansionEvent, GroupExpansionState, HoverableConfig, MenuEntry, PaginationChangeEvent, PaginationState, PaginationUnit, PrintOptions, ResizeMode, ResolvedGroupRow, ResolvedGroupSummaryRow, ResolvedRow, RowGroupPosition, RowPointerEvent, RowProps, RowSelectEvent, RowSelectionChangeEvent, RowsSelectEvent, SelectableConfig, SelectedCellRef, SelectionMode, SelectionState, SerializedGridState, SortDirection, ToolbarEntry, ToolbarItemAttributes, excelFilter, serializeGridState } from '@gridkitjs/core';
3
+ import { ExportWriter, GridExportOptions, PrintOptions, CellSelectEvent as CellSelectEvent$1, CellSelectionChangeEvent as CellSelectionChangeEvent$1, ColumnDefinition as ColumnDefinition$1, ColumnSelectEvent as ColumnSelectEvent$1, ColumnSelectionChangeEvent as ColumnSelectionChangeEvent$1, ColumnsSelectEvent as ColumnsSelectEvent$1, DataColumn as DataColumn$1, GridOptions, PaginationState, SelectionCallbacks as SelectionCallbacks$1, ResolvedRow, DisplayRow, ResolvedColumn as ResolvedColumn$1, ColumnSizingState, ColumnOrderState, ColumnVisibilityState, ColumnPinningState, ColumnSortState, FilterState, GroupByState, GroupExpansionState, AggregateResults, SelectionState, CellSelectionState, GridFocus, GridState, SerializedGridState, ColumnPin, GridContextMenuTarget, GridCommandTarget, SelectedCell as SelectedCell$1, SelectedColumn as SelectedColumn$1 } from '@gridkitjs/core';
4
+ export { AggregateFn, AggregateResults, AggregateSpec, AggregateState, Borders, BuiltInAggregate, CellSelectionMode, CellSelectionState, CellTemplateContext, ColumnAlignment, ColumnFilterMenuOptions, ColumnOrderEvent, ColumnOrderState, ColumnPin, ColumnPinningEvent, ColumnPinningState, ColumnResizeEvent, ColumnSizeDefaults, ColumnSizingState, ColumnSortEntry, ColumnSortEvent, ColumnSortState, ColumnType, ColumnVisibilityEvent, ColumnVisibilityState, ColumnWrapConfig, ContextMenuOpenChangeEvent, DisplayRow, ExportFile, ExportOptions, ExportScalar, ExportWriter, FieldPath, FilterChangeEvent, FilterEntry, FilterState, FooterTemplateContext, FormatLocale, GridCommand, GridCommandEvent, GridCommandTarget, GridContextMenuOptions, GridContextMenuRequest, GridContextMenuTarget, GridExportOptions, GridFilterMenuOptions, GridFocus, GridMessages, GridOptions, GridState, GridToolbarOptions, GroupAggregateDisplay, GroupByBarVisibility, GroupByEntry, GroupByEvent, GroupByState, GroupExpansionEvent, GroupExpansionState, HoverableConfig, MenuEntry, PaginationChangeEvent, PaginationState, PaginationUnit, PrintOptions, ResizeMode, ResolvedGroupRow, ResolvedGroupSummaryRow, ResolvedRow, RowGroupPosition, RowPointerEvent, RowProps, RowSelectEvent, RowSelectionChangeEvent, RowsSelectEvent, SelectableConfig, SelectedCellRef, SelectionMode, SelectionState, SerializedGridState, SortDirection, ToolbarEntry, ToolbarItemAttributes, excelFilter, serializeGridState } from '@gridkitjs/core';
5
5
 
6
6
  /** What `DataGridApi` carries for exporting. */
7
7
  interface GridExportApi {
@@ -122,6 +122,8 @@ interface DataGridApi<Row> extends GridExportApi, GridPrintApi, GridPanelApi {
122
122
  getColumnOrder(): ColumnOrderState;
123
123
  /** Columns shown or hidden since the grid mounted. A column absent from it follows its definition's `hidden`. */
124
124
  getColumnVisibility(): ColumnVisibilityState;
125
+ /** Columns pinned or unpinned since the grid mounted. A column absent from it follows its definition's `pinned`. */
126
+ getColumnPinning(): ColumnPinningState;
125
127
  getColumnSort(): ColumnSortState;
126
128
  /** The filter the rows are shown through — every entry, ANDed together. */
127
129
  getFilter(): FilterState<Row>;
@@ -205,6 +207,13 @@ interface DataGridApi<Row> extends GridExportApi, GridPrintApi, GridPanelApi {
205
207
  * filters and groups, and keeps its place in the column order.
206
208
  */
207
209
  hideColumns(columnIds: readonly string[]): void;
210
+ /**
211
+ * Pins a column to the `"start"` or `"end"` edge, or unpins it with
212
+ * `"none"`, leaving the column order as it is: an unpinned column goes
213
+ * back to its place among the others. Reports one
214
+ * `onColumnPinningChange`, and none when the column is already there.
215
+ */
216
+ pinColumn(columnId: string, pin: ColumnPin): void;
208
217
  /**
209
218
  * Replaces the filter, the way a filter UI would, and sends an uncontrolled
210
219
  * grid back to its first page. Reports one `onFilterChange`, and none when
@@ -230,6 +239,8 @@ interface DataGridApi<Row> extends GridExportApi, GridPrintApi, GridPanelApi {
230
239
  setColumnOrder(order: ColumnOrderState): void;
231
240
  /** Replaces the column visibility state. Reports through `onColumnVisibilityChange`. */
232
241
  setColumnVisibility(visibility: ColumnVisibilityState): void;
242
+ /** Replaces the column pinning state. Reports through `onColumnPinningChange`. */
243
+ setColumnPinning(pinning: ColumnPinningState): void;
233
244
  /** Replaces the selected row ids as given, whatever `selectable` allows. Fires the row selection callbacks. */
234
245
  setRowSelection(selection: SelectionState): void;
235
246
  /** Replaces the selected column ids as given. Fires the column selection callbacks. */
@@ -490,6 +501,16 @@ declare function useColumnOrderState<Row>(gridRef: RefObject<DataGridApi<Row> |
490
501
  */
491
502
  declare function useColumnVisibilityState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnVisibilityState;
492
503
 
504
+ /**
505
+ * Reactive column-pinning state read off a mounted `DataGrid`'s `ref` — the
506
+ * columns pinned or unpinned since it mounted, keyed by id. Read-only:
507
+ * change it through the ref's `pinColumn`/`setColumnPinning`. A column
508
+ * absent from it follows its definition's `pinned`.
509
+ *
510
+ * Before the grid mounts, reads as an empty object.
511
+ */
512
+ declare function useColumnPinningState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): ColumnPinningState;
513
+
493
514
  interface FilterStateApi<Row> {
494
515
  filter: FilterState<Row>;
495
516
  setFilter: (filter: FilterState<Row>) => void;
@@ -505,4 +526,4 @@ interface FilterStateApi<Row> {
505
526
  */
506
527
  declare function useFilterState<Row>(gridRef: RefObject<DataGridApi<Row> | null>): FilterStateApi<Row>;
507
528
 
508
- export { type CellSelectEvent, type CellSelectionChangeEvent, type ColumnDefinition, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnsSelectEvent, type DataColumn, DataGrid, type DataGridApi, type DataGridProps, type FilterStateApi, type GroupByStateApi, type InfiniteScrollConfig, type PagerConfig, type PagerTemplateContext, type PaginationStateApi, type ReactRenderSlots, type ResolvedColumn, type SelectedCell, type SelectedColumn, type SelectionStateApi, useAggregateState, useColumnOrderState, useColumnSizingState, useColumnSortState, useColumnVisibilityState, useFilterState, useGroupByState, usePaginationState, useSelectionState };
529
+ export { type CellSelectEvent, type CellSelectionChangeEvent, type ColumnDefinition, type ColumnSelectEvent, type ColumnSelectionChangeEvent, type ColumnsSelectEvent, type DataColumn, DataGrid, type DataGridApi, type DataGridProps, type FilterStateApi, type GroupByStateApi, type InfiniteScrollConfig, type PagerConfig, type PagerTemplateContext, type PaginationStateApi, type ReactRenderSlots, type ResolvedColumn, type SelectedCell, type SelectedColumn, type SelectionStateApi, useAggregateState, useColumnOrderState, useColumnPinningState, useColumnSizingState, useColumnSortState, useColumnVisibilityState, useFilterState, useGroupByState, usePaginationState, useSelectionState };
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  resolveMessages,
17
17
  resolveRows
18
18
  } from "@gridkitjs/core";
19
- import { totalColumnWidth } from "@gridkitjs/core/renderer";
19
+ import { pinnedWidths, totalColumnWidth } from "@gridkitjs/core/renderer";
20
20
 
21
21
  // src/DataGrid/components/GridColgroup.tsx
22
22
  import { jsx } from "react/jsx-runtime";
@@ -111,6 +111,27 @@ function isOwnEvent(event) {
111
111
  return event.target instanceof Node && event.currentTarget.contains(event.target);
112
112
  }
113
113
 
114
+ // src/DataGrid/pinnedCell.ts
115
+ function pinnedCellClassNames({
116
+ pinned,
117
+ pinEdge
118
+ }) {
119
+ if (pinned === "none") return "";
120
+ return classNames(
121
+ pinned === "start" ? "is-pinned-start" : "is-pinned-end",
122
+ pinEdge && "is-pinned-edge"
123
+ );
124
+ }
125
+ function pinnedCellStyle({
126
+ pinned,
127
+ pinOffset
128
+ }) {
129
+ if (pinned === "none") return void 0;
130
+ return {
131
+ "--gridkit-pin-offset": `${String(pinOffset)}px`
132
+ };
133
+ }
134
+
114
135
  // src/DataGrid/useGridSelection.ts
115
136
  import { useMemo } from "react";
116
137
  function keyboardSelectIntent(event) {
@@ -289,8 +310,10 @@ function GridHeader({
289
310
  dropBefore ? "is-drop-before" : "",
290
311
  dropAfter ? "is-drop-after" : "",
291
312
  column.wrap?.header ? "is-wrapped" : "",
313
+ pinnedCellClassNames(entry),
292
314
  column.headerClassName ?? ""
293
315
  ),
316
+ style: pinnedCellStyle(entry),
294
317
  ...ariaAttr(shortcuts !== "", "aria-keyshortcuts", shortcuts),
295
318
  ...ariaAttr(
296
319
  filtered,
@@ -738,9 +761,13 @@ function GridGroupSummaryRowComponent({
738
761
  {
739
762
  role: "gridcell",
740
763
  "data-gridkit-column": entry.id,
741
- className: "gridkit-grid-group-summary-cell",
764
+ className: classNames(
765
+ "gridkit-grid-group-summary-cell",
766
+ pinnedCellClassNames(entry)
767
+ ),
742
768
  style: {
743
- textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment)
769
+ textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),
770
+ ...pinnedCellStyle(entry)
744
771
  },
745
772
  children: [
746
773
  entry.id === columns[0]?.id && /* @__PURE__ */ jsx5(
@@ -827,7 +854,8 @@ function GridRowComponent({
827
854
  selected ? "is-selected" : "",
828
855
  rowClassName
829
856
  ),
830
- children: columns.map(({ id, column, alignment }, columnIndex) => {
857
+ children: columns.map((entry, columnIndex) => {
858
+ const { id, column, alignment } = entry;
831
859
  const value = accessDotted(row, column.field);
832
860
  const cellSelected = id === selectedColumnId;
833
861
  return /* @__PURE__ */ jsx6(
@@ -844,9 +872,13 @@ function GridRowComponent({
844
872
  id === activeColumnId ? "is-resizing" : "",
845
873
  cellSelected || selectedColumnIds.has(id) ? "is-selected" : "",
846
874
  column.wrap?.cells ? "is-wrapped" : "",
875
+ pinnedCellClassNames(entry),
847
876
  column.cellClassName ?? ""
848
877
  ),
849
- style: { textAlign: textAlignFor(alignment) },
878
+ style: {
879
+ textAlign: textAlignFor(alignment),
880
+ ...pinnedCellStyle(entry)
881
+ },
850
882
  children: column.cellTemplate ? column.cellTemplate({
851
883
  value,
852
884
  row,
@@ -1167,9 +1199,13 @@ function GridFooter({
1167
1199
  {
1168
1200
  role: "gridcell",
1169
1201
  "data-gridkit-column": entry.id,
1170
- className: "gridkit-grid-footer-cell",
1202
+ className: classNames(
1203
+ "gridkit-grid-footer-cell",
1204
+ pinnedCellClassNames(entry)
1205
+ ),
1171
1206
  style: {
1172
- textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment)
1207
+ textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),
1208
+ ...pinnedCellStyle(entry)
1173
1209
  },
1174
1210
  children: specs.map(
1175
1211
  (spec) => renderAggregate(
@@ -1590,7 +1626,8 @@ function GroupByBar({
1590
1626
  // src/DataGrid/announcedCallbacks.ts
1591
1627
  import {
1592
1628
  isColumnVisible,
1593
- isGroupExpanded
1629
+ isGroupExpanded,
1630
+ resolveColumnPin
1594
1631
  } from "@gridkitjs/core";
1595
1632
  function announcedCallbacks({
1596
1633
  callbacks,
@@ -1644,6 +1681,26 @@ function announcedCallbacks({
1644
1681
  shown ? messages.columnShown(columnName(columnId)) : messages.columnHidden(columnName(columnId))
1645
1682
  );
1646
1683
  },
1684
+ /**
1685
+ * Naming the one column pinned or unpinned and the edge it went to. A
1686
+ * change touching several columns, as `setColumnPinning` or restoring a
1687
+ * layout can, may pin some and unpin others, and says nothing.
1688
+ */
1689
+ onColumnPinningChange: (event) => {
1690
+ callbacks.onColumnPinningChange?.(event);
1691
+ const [columnId, ...others] = event.columnIds;
1692
+ if (columnId === void 0 || others.length > 0) {
1693
+ return;
1694
+ }
1695
+ const column = columnOf(columnId);
1696
+ if (column === void 0) {
1697
+ return;
1698
+ }
1699
+ const pin = resolveColumnPin(column, event.pinning);
1700
+ announce(
1701
+ pin === "none" ? messages.columnUnpinned(columnName(columnId)) : messages.columnPinned(columnName(columnId), pin)
1702
+ );
1703
+ },
1647
1704
  /** A toggle, a stack, or a clear back to "none" each get their own. */
1648
1705
  onColumnSortChange: (event) => {
1649
1706
  callbacks.onColumnSortChange?.(event);
@@ -4677,6 +4734,19 @@ function selectedRowsReader(controller) {
4677
4734
  return last.selected;
4678
4735
  };
4679
4736
  }
4737
+ function tablesStyle(height, headerHeight, footerHeight, pinned) {
4738
+ const heights = height === void 0 ? {} : {
4739
+ "--gridkit-body-height": typeof height === "number" ? `${String(height)}px` : height,
4740
+ ...headerHeight === null ? {} : { "--gridkit-header-height": `${String(headerHeight)}px` },
4741
+ ...footerHeight === null ? {} : { "--gridkit-footer-height": `${String(footerHeight)}px` }
4742
+ };
4743
+ const widths = pinned.start === 0 && pinned.end === 0 ? {} : {
4744
+ "--gridkit-pinned-start-width": `${String(pinned.start)}px`,
4745
+ "--gridkit-pinned-end-width": `${String(pinned.end)}px`
4746
+ };
4747
+ const style = { ...heights, ...widths };
4748
+ return Object.keys(style).length === 0 ? void 0 : style;
4749
+ }
4680
4750
  function DataGrid(props) {
4681
4751
  const {
4682
4752
  borders,
@@ -4920,6 +4990,7 @@ function DataGrid(props) {
4920
4990
  getColumnSizing: () => controller.getState().columnSizing,
4921
4991
  getColumnOrder: () => controller.getState().columnOrder,
4922
4992
  getColumnVisibility: () => controller.getState().columnVisibility,
4993
+ getColumnPinning: () => controller.getState().columnPinning,
4923
4994
  getColumnSort: () => controller.getState().columnSort,
4924
4995
  getFilter: () => controller.getState().filter,
4925
4996
  getGroupBy: () => controller.getState().groupBy,
@@ -4946,6 +5017,7 @@ function DataGrid(props) {
4946
5017
  setPageSize: controller.setPageSize,
4947
5018
  showColumns: controller.showColumns,
4948
5019
  hideColumns: controller.hideColumns,
5020
+ pinColumn: controller.pinColumn,
4949
5021
  setFilter: controller.setFilter,
4950
5022
  setColumnSort: controller.setColumnSort,
4951
5023
  setGroupBy: controller.setGroupBy,
@@ -4954,6 +5026,7 @@ function DataGrid(props) {
4954
5026
  setColumnSizing: controller.setColumnSizing,
4955
5027
  setColumnOrder: controller.setColumnOrder,
4956
5028
  setColumnVisibility: controller.setColumnVisibility,
5029
+ setColumnPinning: controller.setColumnPinning,
4957
5030
  setRowSelection: controller.setRowSelection,
4958
5031
  setColumnSelection: controller.setColumnSelection,
4959
5032
  setCellSelection: controller.setCellSelection,
@@ -5060,11 +5133,12 @@ function DataGrid(props) {
5060
5133
  "aria-rowcount": view.displayRows.length + (hasFooter ? 2 : 1),
5061
5134
  "aria-colcount": view.columns.length,
5062
5135
  tabIndex: -1,
5063
- style: height === void 0 ? void 0 : {
5064
- "--gridkit-body-height": typeof height === "number" ? `${String(height)}px` : height,
5065
- ...headerHeight === null ? {} : { "--gridkit-header-height": `${String(headerHeight)}px` },
5066
- ...footerHeight === null ? {} : { "--gridkit-footer-height": `${String(footerHeight)}px` }
5067
- },
5136
+ style: tablesStyle(
5137
+ height,
5138
+ headerHeight,
5139
+ footerHeight,
5140
+ pinnedWidths(view.columns)
5141
+ ),
5068
5142
  ...ariaAttr(multiselectable, "aria-multiselectable", true),
5069
5143
  ...ariaAttr(labelledBy !== void 0, "aria-labelledby", labelledBy),
5070
5144
  ...ariaAttr(
@@ -5419,13 +5493,24 @@ function useColumnVisibilityState(gridRef) {
5419
5493
  );
5420
5494
  }
5421
5495
 
5496
+ // src/DataGrid/hooks/useColumnPinningState.ts
5497
+ import { useCallback as useCallback13 } from "react";
5498
+ var FALLBACK_PINNING = {};
5499
+ function useColumnPinningState(gridRef) {
5500
+ return useGridSnapshot(
5501
+ gridRef,
5502
+ useCallback13((api) => api.getColumnPinning(), []),
5503
+ FALLBACK_PINNING
5504
+ );
5505
+ }
5506
+
5422
5507
  // src/DataGrid/hooks/useFilterState.ts
5423
- import { useCallback as useCallback13, useState as useState20 } from "react";
5508
+ import { useCallback as useCallback14, useState as useState20 } from "react";
5424
5509
  function useFilterState(gridRef) {
5425
5510
  const [fallback] = useState20(() => []);
5426
5511
  const filter = useGridSnapshot(
5427
5512
  gridRef,
5428
- useCallback13((api) => api.getFilter(), []),
5513
+ useCallback14((api) => api.getFilter(), []),
5429
5514
  fallback
5430
5515
  );
5431
5516
  return {
@@ -5444,6 +5529,7 @@ export {
5444
5529
  serializeGridState,
5445
5530
  useAggregateState,
5446
5531
  useColumnOrderState,
5532
+ useColumnPinningState,
5447
5533
  useColumnSizingState,
5448
5534
  useColumnSortState,
5449
5535
  useColumnVisibilityState,