@gridkitjs/react 0.0.0-dev-20261119135354 → 0.0.0-dev-20261119142904

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
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';
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, DataMode, 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 {
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  useId as useId2,
7
7
  useImperativeHandle as useImperativeHandle3,
8
8
  useMemo as useMemo5,
9
- useRef as useRef23,
9
+ useRef as useRef24,
10
10
  useState as useState19
11
11
  } from "react";
12
12
  import {
@@ -2844,7 +2844,7 @@ function useGridOverlay({
2844
2844
  }
2845
2845
 
2846
2846
  // src/DataGrid/panels/GridPanels.tsx
2847
- import { useRef as useRef15 } from "react";
2847
+ import { useRef as useRef16 } from "react";
2848
2848
 
2849
2849
  // src/DataGrid/columnChooser/ColumnChooser.tsx
2850
2850
  import { useLayoutEffect as useLayoutEffect7, useRef as useRef9, useState as useState6 } from "react";
@@ -3882,25 +3882,47 @@ function FilterMenu({
3882
3882
  }
3883
3883
 
3884
3884
  // src/DataGrid/useAnnounceWhenDrawn.ts
3885
- import { useEffect as useEffect5, useState as useState10 } from "react";
3886
- function useAnnounceWhenDrawn(announce) {
3885
+ import { useEffect as useEffect5, useRef as useRef15, useState as useState10 } from "react";
3886
+ function useAnnounceWhenDrawn(announce, controller) {
3887
3887
  const [requested, setRequested] = useState10(null);
3888
+ const settled = useRef15(null);
3889
+ const { dataMode, dataSource, loading = false } = controller.getOptions();
3888
3890
  useEffect5(() => {
3889
- if (requested?.drawn() === true) {
3890
- announce(requested.text());
3891
+ if (requested === null || settled.current === requested) {
3892
+ return;
3893
+ }
3894
+ const { announcement, rowsAsked } = requested;
3895
+ const awaitingRows = dataMode === "server" && (loading || dataSource === rowsAsked);
3896
+ const drawn = announcement.drawn();
3897
+ if (drawn && awaitingRows) {
3898
+ return;
3899
+ }
3900
+ settled.current = requested;
3901
+ if (drawn) {
3902
+ announce(announcement.text());
3891
3903
  }
3892
- }, [requested, announce]);
3893
- return setRequested;
3904
+ }, [requested, dataMode, dataSource, loading, announce]);
3905
+ return (announcement) => {
3906
+ setRequested({
3907
+ announcement,
3908
+ rowsAsked: controller.getOptions().dataSource
3909
+ });
3910
+ };
3911
+ }
3912
+ function resultCount(controller) {
3913
+ const { dataMode, rowCount } = controller.getOptions();
3914
+ const held = controller.getView().rows.length;
3915
+ return dataMode === "server" ? rowCount ?? held : held;
3894
3916
  }
3895
3917
 
3896
3918
  // src/DataGrid/filterMenu/useApplyFilter.ts
3897
3919
  function useApplyFilter(controller, messages, announce) {
3898
- const announceWhenDrawn = useAnnounceWhenDrawn(announce);
3920
+ const announceWhenDrawn = useAnnounceWhenDrawn(announce, controller);
3899
3921
  return (filter) => {
3900
3922
  announceWhenDrawn({
3901
3923
  drawn: () => controller.getState().filter === filter,
3902
- text: () => messages.filterResults(
3903
- controller.getView().rows.length,
3924
+ text: () => controller.getOptions().dataMode === "server" ? messages.searchResults(resultCount(controller)) : messages.filterResults(
3925
+ resultCount(controller),
3904
3926
  controller.getOptions().dataSource?.length ?? 0
3905
3927
  )
3906
3928
  });
@@ -3940,7 +3962,7 @@ function GridPanels({
3940
3962
  commands,
3941
3963
  messages
3942
3964
  }) {
3943
- const initialFocus = useRef15(null);
3965
+ const initialFocus = useRef16(null);
3944
3966
  const applyFilter = useApplyFilter(
3945
3967
  controller,
3946
3968
  messages,
@@ -4009,7 +4031,7 @@ function panelApi(panels, controller) {
4009
4031
  }
4010
4032
 
4011
4033
  // src/DataGrid/panels/useGridPanels.ts
4012
- import { useRef as useRef16 } from "react";
4034
+ import { useRef as useRef17 } from "react";
4013
4035
  import {
4014
4036
  writingDirection as writingDirection6
4015
4037
  } from "@gridkitjs/dom";
@@ -4038,7 +4060,7 @@ function useGridPanels({
4038
4060
  headerTableRef,
4039
4061
  overlay
4040
4062
  }) {
4041
- const openings = useRef16(0);
4063
+ const openings = useRef17(0);
4042
4064
  function placeFor(root, target) {
4043
4065
  const element = target.area === "toolbar" ? toolbarItem(root, target.itemId) : target.area === "header" ? headerCell2(headerTableRef.current, target.columnId) : null;
4044
4066
  if (element !== null) {
@@ -4084,7 +4106,7 @@ function useGridPanels({
4084
4106
  }
4085
4107
 
4086
4108
  // src/DataGrid/toolbar/GridToolbar.tsx
4087
- import { useLayoutEffect as useLayoutEffect13, useRef as useRef19 } from "react";
4109
+ import { useLayoutEffect as useLayoutEffect13, useRef as useRef20 } from "react";
4088
4110
  import {
4089
4111
  resolveToolbar,
4090
4112
  toolbarEntries
@@ -4156,7 +4178,7 @@ function ToolbarMenuButton({
4156
4178
  }
4157
4179
 
4158
4180
  // src/DataGrid/toolbar/ToolbarSearch.tsx
4159
- import { useEffect as useEffect6, useRef as useRef17, useState as useState12 } from "react";
4181
+ import { useEffect as useEffect6, useRef as useRef18, useState as useState12 } from "react";
4160
4182
  import { searchTextOf, setSearchText } from "@gridkitjs/core/renderer";
4161
4183
  import { jsx as jsx26 } from "react/jsx-runtime";
4162
4184
  var SEARCH_DELAY_MS = 250;
@@ -4169,8 +4191,8 @@ function ToolbarSearch({
4169
4191
  }) {
4170
4192
  const applied = searchTextOf(controller.getState().filter);
4171
4193
  const [draft, setDraft] = useState12(null);
4172
- const timer = useRef17(void 0);
4173
- const announceWhenDrawn = useAnnounceWhenDrawn(announce);
4194
+ const timer = useRef18(void 0);
4195
+ const announceWhenDrawn = useAnnounceWhenDrawn(announce, controller);
4174
4196
  const text = draft !== null && draft.over === applied ? draft.text : applied;
4175
4197
  function apply(next, over) {
4176
4198
  clearTimeout(timer.current);
@@ -4183,7 +4205,7 @@ function ToolbarSearch({
4183
4205
  if (searched !== filter) {
4184
4206
  announceWhenDrawn({
4185
4207
  drawn: () => searchTextOf(controller.getState().filter) === next,
4186
- text: () => messages.searchResults(controller.getView().rows.length)
4208
+ text: () => messages.searchResults(resultCount(controller))
4187
4209
  });
4188
4210
  controller.setFilter(searched);
4189
4211
  }
@@ -4225,12 +4247,12 @@ function ToolbarSearch({
4225
4247
  }
4226
4248
 
4227
4249
  // src/DataGrid/toolbar/useToolbarOverflow.ts
4228
- import { useLayoutEffect as useLayoutEffect12, useRef as useRef18, useState as useState13 } from "react";
4250
+ import { useLayoutEffect as useLayoutEffect12, useRef as useRef19, useState as useState13 } from "react";
4229
4251
  import { observeToolbarOverflow } from "@gridkitjs/dom";
4230
4252
  function useToolbarOverflow(toolbarRef, items) {
4231
4253
  const [fit, setFit] = useState13(items.length);
4232
- const overflow = useRef18(null);
4233
- const measuredLayout = useRef18("");
4254
+ const overflow = useRef19(null);
4255
+ const measuredLayout = useRef19("");
4234
4256
  const layout = JSON.stringify(
4235
4257
  items.map((item) => [
4236
4258
  item.type,
@@ -4337,7 +4359,7 @@ function Toolbar({
4337
4359
  messages,
4338
4360
  announce
4339
4361
  }) {
4340
- const toolbarRef = useRef19(null);
4362
+ const toolbarRef = useRef20(null);
4341
4363
  const items = resolveToolbar(entries, {
4342
4364
  commands: commands.commands,
4343
4365
  contextFor: commands.contextFor,
@@ -4657,14 +4679,14 @@ function useGridController(options) {
4657
4679
  }
4658
4680
 
4659
4681
  // src/DataGrid/useInfiniteScroll.ts
4660
- import { useEffect as useEffect7, useRef as useRef20 } from "react";
4682
+ import { useEffect as useEffect7, useRef as useRef21 } from "react";
4661
4683
  import { attachInfiniteScroll } from "@gridkitjs/dom";
4662
4684
  function useInfiniteScroll({
4663
4685
  rootRef,
4664
4686
  sentinelRef,
4665
4687
  config
4666
4688
  }) {
4667
- const scroll = useRef20(null);
4689
+ const scroll = useRef21(null);
4668
4690
  useEffect7(() => {
4669
4691
  const root = rootRef.current;
4670
4692
  if (root === null) {
@@ -4692,10 +4714,10 @@ function useInfiniteScroll({
4692
4714
  }
4693
4715
 
4694
4716
  // src/DataGrid/useLiveAnnouncer.ts
4695
- import { useCallback as useCallback3, useLayoutEffect as useLayoutEffect16, useRef as useRef21 } from "react";
4717
+ import { useCallback as useCallback3, useLayoutEffect as useLayoutEffect16, useRef as useRef22 } from "react";
4696
4718
  import { createLiveAnnouncer } from "@gridkitjs/dom";
4697
4719
  function useLiveAnnouncer(containerRef) {
4698
- const announcer = useRef21(null);
4720
+ const announcer = useRef22(null);
4699
4721
  useLayoutEffect16(() => {
4700
4722
  const container = containerRef.current;
4701
4723
  if (container === null) {
@@ -4714,7 +4736,7 @@ function useLiveAnnouncer(containerRef) {
4714
4736
  }
4715
4737
 
4716
4738
  // src/DataGrid/useRowVirtualizer.ts
4717
- import { useLayoutEffect as useLayoutEffect17, useRef as useRef22, useState as useState18 } from "react";
4739
+ import { useLayoutEffect as useLayoutEffect17, useRef as useRef23, useState as useState18 } from "react";
4718
4740
  import {
4719
4741
  bodyRowFrom as bodyRowFrom3,
4720
4742
  createRowVirtualizer as createRowVirtualizer2
@@ -4755,8 +4777,8 @@ function useRowVirtualizer({
4755
4777
  overscan
4756
4778
  }) {
4757
4779
  const [virtualizer, setVirtualizer] = useState18(null);
4758
- const instance = useRef22(null);
4759
- const rowCount = useRef22(rows.length);
4780
+ const instance = useRef23(null);
4781
+ const rowCount = useRef23(rows.length);
4760
4782
  const [rowWindow, setRowWindow] = useState18(enabled ? NO_ROWS3 : ALL_ROWS);
4761
4783
  if (!enabled && rowWindow.kind !== "allRows") {
4762
4784
  setRowWindow(ALL_ROWS);
@@ -4877,15 +4899,15 @@ function DataGrid(props) {
4877
4899
  const hoverRows = hoverable?.rows ?? true;
4878
4900
  const hoverColumns = hoverable?.columns ?? true;
4879
4901
  const hoverCells = hoverable?.cells ?? true;
4880
- const viewportRef = useRef23(null);
4881
- const gridRef = useRef23(null);
4882
- const headerTableRef = useRef23(null);
4883
- const bodyTableRef = useRef23(null);
4884
- const bodyRef = useRef23(null);
4885
- const footerTableRef = useRef23(null);
4886
- const sentinelRef = useRef23(null);
4902
+ const viewportRef = useRef24(null);
4903
+ const gridRef = useRef24(null);
4904
+ const headerTableRef = useRef24(null);
4905
+ const bodyTableRef = useRef24(null);
4906
+ const bodyRef = useRef24(null);
4907
+ const footerTableRef = useRef24(null);
4908
+ const sentinelRef = useRef24(null);
4887
4909
  const viewportWidth = useElementWidth(gridRef, resizeMode === "fit");
4888
- const subscribersRef = useRef23(/* @__PURE__ */ new Set());
4910
+ const subscribersRef = useRef24(/* @__PURE__ */ new Set());
4889
4911
  const gridId = useId2();
4890
4912
  const announce = useLiveAnnouncer(viewportRef);
4891
4913
  const messages = useMemo5(
@@ -4928,6 +4950,14 @@ function DataGrid(props) {
4928
4950
  );
4929
4951
  }
4930
4952
  }, [paginated, hasInfiniteScroll]);
4953
+ const serverPagesUncounted = props.dataMode === "server" && paginated && props.rowCount === void 0;
4954
+ useEffect8(() => {
4955
+ if (serverPagesUncounted) {
4956
+ console.error(
4957
+ 'DataGrid: a `paginated` grid under `dataMode: "server"` needs `rowCount` \u2014 without it the pager counts only the rows given, one page. Pass `0` until the first response.'
4958
+ );
4959
+ }
4960
+ }, [serverPagesUncounted]);
4931
4961
  useInfiniteScroll({
4932
4962
  rootRef: gridRef,
4933
4963
  sentinelRef,
@@ -5256,7 +5286,7 @@ function DataGrid(props) {
5256
5286
  id: gridId,
5257
5287
  className: "gridkit-data-grid-tables",
5258
5288
  role: state.groupBy.length > 0 ? "treegrid" : "grid",
5259
- "aria-rowcount": view.displayRows.length + (hasFooter ? 2 : 1),
5289
+ "aria-rowcount": view.rowCount + (hasFooter ? 2 : 1),
5260
5290
  "aria-colcount": view.columns.length,
5261
5291
  tabIndex: -1,
5262
5292
  style: tablesStyle(
@@ -5397,7 +5427,7 @@ function DataGrid(props) {
5397
5427
  results: view.grandTotal,
5398
5428
  rows: view.rows.map((entry) => entry.row),
5399
5429
  locale,
5400
- ariaRowIndex: view.displayRows.length + 2
5430
+ ariaRowIndex: view.rowCount + 2
5401
5431
  }
5402
5432
  )
5403
5433
  ]
@@ -5432,7 +5462,7 @@ import { useCallback as useCallback5 } from "react";
5432
5462
  import {
5433
5463
  useCallback as useCallback4,
5434
5464
  useEffect as useEffect9,
5435
- useRef as useRef24,
5465
+ useRef as useRef25,
5436
5466
  useSyncExternalStore as useSyncExternalStore3
5437
5467
  } from "react";
5438
5468
  function subscribeTo(api, listener) {
@@ -5449,7 +5479,7 @@ function unsubscribe(subscription) {
5449
5479
  }
5450
5480
  }
5451
5481
  function useGridSnapshot(gridRef, getSnapshot, fallback) {
5452
- const subscription = useRef24(null);
5482
+ const subscription = useRef25(null);
5453
5483
  const subscribe = useCallback4(
5454
5484
  (listener) => {
5455
5485
  subscription.current = subscribeTo(gridRef.current, listener);