@gridkitjs/react 0.19.0 → 0.20.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.d.ts +26 -4
- package/dist/index.js +382 -255
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/DataGrid/DataGrid.tsx","../src/DataGrid/components/GridColgroup.tsx","../src/DataGrid/components/GridHeader.tsx","../src/DataGrid/ariaAttr.ts","../src/DataGrid/classNames.ts","../src/DataGrid/icons.tsx","../src/DataGrid/isOwnEvent.ts","../src/DataGrid/pinnedCell.ts","../src/DataGrid/useGridSelection.ts","../src/DataGrid/components/GridBody.tsx","../src/DataGrid/useGridNavigation.ts","../src/DataGrid/rowProps.ts","../src/DataGrid/components/GridGroupRow.tsx","../src/DataGrid/components/renderAggregate.ts","../src/DataGrid/components/GridGroupSummaryRow.tsx","../src/DataGrid/textAlign.ts","../src/DataGrid/components/GridRow.tsx","../src/DataGrid/components/GridFooter.tsx","../src/DataGrid/components/GridPager.tsx","../src/DataGrid/components/GroupByBar.tsx","../src/DataGrid/useGroupByDrag.ts","../src/DataGrid/useDragReorder.ts","../src/DataGrid/useGestureSignal.ts","../src/DataGrid/announcedCallbacks.ts","../src/DataGrid/clipboard/useGridCopy.ts","../src/DataGrid/commands/useGridCommands.ts","../src/DataGrid/clipboard/useCopyToClipboard.ts","../src/DataGrid/export/useSaveFile.ts","../src/DataGrid/export/exportApi.ts","../src/DataGrid/print/printApi.ts","../src/DataGrid/menu/GridMenu.tsx","../src/DataGrid/overlay/Overlay.tsx","../src/DataGrid/menu/menuIcons.tsx","../src/DataGrid/contextMenu/GridContextMenu.tsx","../src/DataGrid/contextMenu/useContextMenu.ts","../src/DataGrid/contextMenu/contextMenuPlaces.ts","../src/DataGrid/overlay/useGridOverlay.ts","../src/DataGrid/panels/GridPanels.tsx","../src/DataGrid/columnChooser/ColumnChooser.tsx","../src/DataGrid/filterMenu/FilterMenu.tsx","../src/DataGrid/filterMenu/ExcelFilterEditor.tsx","../src/DataGrid/filterMenu/excelEditorState.ts","../src/DataGrid/menu/useMenuButton.ts","../src/DataGrid/filterMenu/OperatorMenuButton.tsx","../src/DataGrid/filterMenu/SimpleFilterEditor.tsx","../src/DataGrid/filterMenu/ConditionRow.tsx","../src/DataGrid/filterMenu/simpleEditorState.ts","../src/DataGrid/filterMenu/ValueChecklist.tsx","../src/DataGrid/useAnnounceWhenDrawn.ts","../src/DataGrid/filterMenu/useApplyFilter.ts","../src/DataGrid/filterMenu/useFilterValueCache.ts","../src/DataGrid/panels/panelApi.ts","../src/DataGrid/panels/useGridPanels.ts","../src/DataGrid/toolbar/GridToolbar.tsx","../src/DataGrid/toolbar/ToolbarMenuButton.tsx","../src/DataGrid/toolbar/ToolbarSearch.tsx","../src/DataGrid/toolbar/useToolbarOverflow.ts","../src/DataGrid/useColumnDrag.ts","../src/DataGrid/useColumnResize.ts","../src/DataGrid/useElementHeight.ts","../src/DataGrid/useElementWidth.ts","../src/DataGrid/useGridController.ts","../src/DataGrid/useInfiniteScroll.ts","../src/DataGrid/useLiveAnnouncer.ts","../src/DataGrid/useRowVirtualizer.ts","../src/index.ts","../src/DataGrid/hooks/usePaginationState.ts","../src/DataGrid/hooks/useGridSnapshot.ts","../src/DataGrid/hooks/useGroupByState.ts","../src/DataGrid/hooks/useColumnSortState.ts","../src/DataGrid/hooks/useSelectionState.ts","../src/DataGrid/hooks/useAggregateState.ts","../src/DataGrid/hooks/useColumnSizingState.ts","../src/DataGrid/hooks/useColumnOrderState.ts","../src/DataGrid/hooks/useColumnVisibilityState.ts","../src/DataGrid/hooks/useColumnPinningState.ts","../src/DataGrid/hooks/useFilterState.ts"],"sourcesContent":["import {\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport {\n headerFocus,\n resolveColumnHeaderText,\n resolveColumnPin,\n resolveMessages,\n resolveRows,\n type ColumnDefinition as CoreColumnDefinition,\n type DataColumn as CoreDataColumn,\n type ResolvedColumn as CoreResolvedColumn,\n type AggregateResults,\n type AggregateState,\n type Borders,\n type ColumnOrderState,\n type ColumnPin,\n type ColumnPinningState,\n type ColumnSizingState,\n type ColumnSortState,\n type ColumnVisibilityState,\n type DisplayRow,\n type FilterState,\n type GridCommandTarget,\n type GridContextMenuTarget,\n type GridOptions,\n type GridState,\n type GroupByBarVisibility,\n type GroupByState,\n type GroupExpansionState,\n type HoverableConfig,\n type PaginationState,\n type PaginationUnit,\n type ResizeMode,\n type ResolvedRow,\n type CellSelectionState,\n type SelectedCell as CoreSelectedCell,\n type SelectedColumn as CoreSelectedColumn,\n type SelectionState,\n type CellSelectEvent as CoreCellSelectEvent,\n type CellSelectionChangeEvent as CoreCellSelectionChangeEvent,\n type ColumnSelectEvent as CoreColumnSelectEvent,\n type ColumnSelectionChangeEvent as CoreColumnSelectionChangeEvent,\n type ColumnsSelectEvent as CoreColumnsSelectEvent,\n type SelectionCallbacks as CoreSelectionCallbacks,\n type SerializedGridState,\n type GridFocus,\n} from \"@gridkitjs/core\";\nimport {\n moveColumnInPinGroup,\n pinnedWidths,\n totalColumnWidth,\n} from \"@gridkitjs/core/renderer\";\nimport type { ColumnDropTarget } from \"@gridkitjs/dom\";\nimport GridColgroup from \"./components/GridColgroup\";\nimport GridHeader from \"./components/GridHeader\";\nimport GridBody from \"./components/GridBody\";\nimport GridFooter from \"./components/GridFooter\";\nimport GridPager from \"./components/GridPager\";\nimport GroupByBar from \"./components/GroupByBar\";\nimport { announcedCallbacks } from \"./announcedCallbacks\";\nimport { ariaAttr } from \"./ariaAttr\";\nimport { classNames } from \"./classNames\";\nimport useGridCopy from \"./clipboard/useGridCopy\";\nimport useGridCommands from \"./commands/useGridCommands\";\nimport GridContextMenu from \"./contextMenu/GridContextMenu\";\nimport useContextMenu from \"./contextMenu/useContextMenu\";\nimport { exportApi, type GridExportApi } from \"./export/exportApi\";\nimport { isOwnEvent } from \"./isOwnEvent\";\nimport useGridOverlay from \"./overlay/useGridOverlay\";\nimport GridPanels from \"./panels/GridPanels\";\nimport { panelApi, type GridPanelApi } from \"./panels/panelApi\";\nimport { printApi, type GridPrintApi } from \"./print/printApi\";\nimport useGridPanels from \"./panels/useGridPanels\";\nimport GridToolbar from \"./toolbar/GridToolbar\";\nimport useColumnDrag from \"./useColumnDrag\";\nimport useColumnResize from \"./useColumnResize\";\nimport useElementHeight from \"./useElementHeight\";\nimport useElementWidth from \"./useElementWidth\";\nimport useGridController, {\n type DataGridController,\n} from \"./useGridController\";\nimport useGridNavigation from \"./useGridNavigation\";\nimport useGridSelection from \"./useGridSelection\";\nimport useInfiniteScroll from \"./useInfiniteScroll\";\nimport useLiveAnnouncer from \"./useLiveAnnouncer\";\nimport useRowVirtualizer from \"./useRowVirtualizer\";\n\n/**\n * A column whose header and cells may render arbitrary React content.\n * @gridkitjs/core stays framework-agnostic and so leaves that output type open;\n * this is the binding React consumers want, and the one they should import.\n */\nexport type ColumnDefinition<Row> = CoreColumnDefinition<Row, ReactNode>;\n\n/** A column paired with the width it renders at. */\nexport type ResolvedColumn<Row> = CoreResolvedColumn<Row, ReactNode>;\n\n/** A column paired with its id, hidden or not — what `getDataColumns()` lists. */\nexport type DataColumn<Row> = CoreDataColumn<Row, ReactNode>;\n\n/**\n * The selection payloads, bound to React's node type for the same reason\n * `ColumnDefinition` is: they carry a resolved column, whose label is whatever\n * a `headerTemplate` returned.\n *\n * The row payloads name no node type at all and so are re-exported from\n * `@gridkitjs/core` as they are.\n */\nexport type SelectedColumn<Row> = CoreSelectedColumn<Row, ReactNode>;\nexport type SelectedCell<Row> = CoreSelectedCell<Row, ReactNode>;\nexport type ColumnSelectEvent<Row> = CoreColumnSelectEvent<Row, ReactNode>;\nexport type ColumnsSelectEvent<Row> = CoreColumnsSelectEvent<Row, ReactNode>;\nexport type ColumnSelectionChangeEvent<Row> = CoreColumnSelectionChangeEvent<\n Row,\n ReactNode\n>;\nexport type CellSelectEvent<Row> = CoreCellSelectEvent<Row, ReactNode>;\nexport type CellSelectionChangeEvent<Row> = CoreCellSelectionChangeEvent<\n Row,\n ReactNode\n>;\nexport type SelectionCallbacks<Row> = CoreSelectionCallbacks<Row, ReactNode>;\n\n/**\n * Imperative handle for a mounted `DataGrid`, reached via its `ref` prop:\n * the grid's DOM nodes, getters for its live state, the actions every grid\n * ref carries (focus, select all, scroll-to), and a setter for every slice of\n * state, for a toolbar, a saved layout or a test to drive it from outside.\n *\n * Every getter reads the grid's state at call time, so a read straight after\n * an action sees its result. Every setter changes the grid as the user's own\n * interaction would: it fires the slice's `on*Change` callback, and, for a\n * slice held through a controlled prop, only asks. `subscribe` is the\n * notify channel for state that changes; see\n * `packages/react/src/DataGrid/hooks/` for the public hooks built on it.\n */\nexport interface DataGridApi<Row>\n extends GridExportApi, GridPrintApi, GridPanelApi {\n /**\n * The grid's root element, `.gridkit-data-grid-viewport`. The tables\n * scroll inside it, in `.gridkit-data-grid-tables`, not on it.\n */\n readonly element: HTMLDivElement | null;\n /**\n * The grid's row-area `<table>` element — the one holding `<tbody>`. The\n * header and, when aggregates are active, footer render as their own\n * sibling `<table>`s outside this one; use `element` to reach the whole\n * grid instead.\n */\n readonly table: HTMLTableElement | null;\n\n /** Rows as currently filtered and sorted — what's rendered, ungrouped. */\n getRows(): readonly ResolvedRow<Row>[];\n /**\n * `getRows()` regrouped into the active `groupBy` — group headers\n * interleaved with data rows, in render order. Identical to `getRows()`\n * when `groupBy` is empty.\n */\n getDisplayRows(): readonly DisplayRow<Row>[];\n /**\n * The current page of `getDisplayRows()` — exactly the rows the body\n * renders. All of `getDisplayRows()` when `paginated` is off.\n */\n getPageRows(): readonly DisplayRow<Row>[];\n /** Columns as currently sized and ordered — what's rendered, so hidden columns are left out. */\n getColumns(): readonly ResolvedColumn<Row>[];\n /** Every column in its current order, hidden ones included — what sorting, filtering and grouping read. */\n getDataColumns(): readonly DataColumn<Row>[];\n\n getColumnSizing(): ColumnSizingState;\n getColumnOrder(): ColumnOrderState;\n /** Columns shown or hidden since the grid mounted. A column absent from it follows its definition's `hidden`. */\n getColumnVisibility(): ColumnVisibilityState;\n /** Columns pinned or unpinned since the grid mounted. A column absent from it follows its definition's `pinned`. */\n getColumnPinning(): ColumnPinningState;\n getColumnSort(): ColumnSortState;\n /** The filter the rows are shown through — every entry, ANDed together. */\n getFilter(): FilterState<Row>;\n getGroupBy(): GroupByState;\n getGroupExpansion(): GroupExpansionState;\n /** The active page and page size. Meaningful even when `paginated` is off — it stays at page 0 over the grid's whole (single) page. */\n getPagination(): PaginationState;\n /** How many pages the current `pagination.pageSize` splits the grid's rows into — `1` whenever `paginated` is off. */\n getPageCount(): number;\n /**\n * The grand-total aggregate results — every active aggregate computed over\n * the whole filtered/sorted dataset, ungrouped and unpaginated. A specific\n * group's own results are read off `getDisplayRows()` instead, on that\n * group header's `aggregates` field.\n */\n getAggregates(): AggregateResults;\n getRowSelection(): SelectionState;\n /**\n * The selected rows themselves, in the order they were selected — among\n * every row the filter lets through, on any page or in any group, so a row\n * filtered out while selected is left out until it is back.\n */\n getSelectedRows(): readonly ResolvedRow<Row>[];\n getColumnSelection(): SelectionState;\n getCellSelection(): CellSelectionState;\n /**\n * The cell currently holding the grid's single tab stop, in the shape\n * `focusCell` takes. Returns the same object until the focus moves.\n */\n getFocusedCell(): GridFocus;\n /**\n * Every slice of state as the grid applies it, in one object — what\n * `restoreState` takes back. Pass it through `serializeGridState` before\n * saving it as JSON.\n */\n getState(): GridState<Row>;\n /**\n * Puts back state saved earlier, whole or in part — from `getState()`, or\n * from `serializeGridState` and back through JSON. Each slice given is set\n * as its setter would set it, firing its callback when it changes; the\n * grid re-renders once. Saved state is read by its `version`; one without\n * a version, saved by an earlier release, still restores, and one newer\n * than this release reads throws.\n */\n restoreState(\n saved: Partial<GridState<Row>> | Partial<SerializedGridState<Row>>,\n ): void;\n\n /**\n * Moves the grid's tab stop, and the browser's focus, to a cell:\n * `{ area: \"body\", rowIndex, columnIndex }` or\n * `{ area: \"header\", columnIndex }`. Either index is held inside the grid.\n */\n focusCell(focus: GridFocus): void;\n clearSelection(): void;\n selectAllRows(): void;\n /**\n * Selects rows by id, as far as `selectable.rows` allows: `\"replace\"` (the\n * default) selects exactly these — only the last of them under\n * `\"single\"` — and `\"toggle\"` flips each one. Fires the row selection\n * callbacks once for the whole call, and none when nothing changed.\n */\n selectRows(rowIds: readonly string[], intent?: \"replace\" | \"toggle\"): void;\n /** Expands every group at once, as the `group.expandAll` command does. */\n expandAllGroups(): void;\n /** Collapses every group at once, as the `group.collapseAll` command does — one nested under a collapsed group, and one that appears later, too. */\n collapseAllGroups(): void;\n /** Moves to the given page, clamped into range. */\n goToPage(pageIndex: number): void;\n /** Moves to the next page. A no-op on the last page. */\n nextPage(): void;\n /** Moves to the previous page. A no-op on the first page. */\n previousPage(): void;\n /** Changes the page size, resetting to the first page. */\n setPageSize(pageSize: number): void;\n /**\n * Shows the columns with the given ids, each in the place it held when\n * hidden. Reports one `onColumnVisibilityChange` for the whole call, and\n * none if every column was already showing.\n */\n showColumns(columnIds: readonly string[]): void;\n /**\n * Hides the columns with the given ids. A hidden column still sorts,\n * filters and groups, and keeps its place in the column order.\n */\n hideColumns(columnIds: readonly string[]): void;\n /**\n * Pins a column to the `\"start\"` or `\"end\"` edge, or unpins it with\n * `\"none\"`, leaving the column order as it is: an unpinned column goes\n * back to its place among the others. Reports one\n * `onColumnPinningChange`, and none when the column is already there.\n */\n pinColumn(columnId: string, pin: ColumnPin): void;\n /**\n * Replaces the filter, the way a filter UI would, and sends an uncontrolled\n * grid back to its first page. Reports one `onFilterChange`, and none when\n * `filter` is equal to the current one. With a controlled `filter` prop it\n * only asks, as any change does.\n */\n setFilter(filter: FilterState<Row>): void;\n /**\n * Replaces the sort. Reports one `onColumnSortChange`, naming the first\n * column whose place or direction changed, and none for an equal sort —\n * the rule every setter below follows for its own slice and callback.\n */\n setColumnSort(sort: ColumnSortState): void;\n /** Replaces the group-by stack. Reports through `onGroupByChange`. */\n setGroupBy(groupBy: GroupByState): void;\n /** Replaces the group expansion. Reports through `onGroupExpansionChange` with `groupId: null`, and nothing for an equal expansion. */\n setGroupExpansion(expansion: GroupExpansionState): void;\n /** Replaces the page and page size as given. Reports through `onPaginationChange`. */\n setPagination(pagination: PaginationState): void;\n /** Replaces the column widths. Reports through `onColumnSizingChange`, as the `\"end\"` of a resize. */\n setColumnSizing(sizing: ColumnSizingState): void;\n /** Replaces the column order. Reports through `onColumnOrderChange`. */\n setColumnOrder(order: ColumnOrderState): void;\n /** Replaces the column visibility state. Reports through `onColumnVisibilityChange`. */\n setColumnVisibility(visibility: ColumnVisibilityState): void;\n /** Replaces the column pinning state. Reports through `onColumnPinningChange`. */\n setColumnPinning(pinning: ColumnPinningState): void;\n /** Replaces the selected row ids as given, whatever `selectable` allows. Fires the row selection callbacks. */\n setRowSelection(selection: SelectionState): void;\n /** Replaces the selected column ids as given. Fires the column selection callbacks. */\n setColumnSelection(selection: SelectionState): void;\n /** Replaces the cell selection as given, `{ kind: \"none\" }` for none. Fires the cell selection callbacks. */\n setCellSelection(selection: CellSelectionState): void;\n /**\n * Sizes a shown column to fit its content, as double-clicking its resize\n * handle does, reporting through `onColumnSizingChange`. A hidden column, or one\n * with no rows to measure, is left as it is.\n */\n autoFitColumn(columnId: string): void;\n /**\n * `autoFitColumn` for each of the given columns, or for every column shown\n * when given none.\n */\n autoFitColumns(columnIds?: readonly string[]): void;\n /**\n * Opens the context menu `target` has, as a right-click there would —\n * selecting it and focusing its cell first — beside `anchor`, a point in\n * viewport coordinates or an element, or else below its cell, in place of\n * any panel open. Says whether it opened: not for a target not on screen,\n * nor where `contextMenu` gives no menu.\n */\n openContextMenu(\n target: GridContextMenuTarget,\n anchor?: { readonly x: number; readonly y: number } | Element,\n ): boolean;\n /** Closes the context menu, if one is open. */\n closeContextMenu(): void;\n /**\n * Runs a command by id — a built-in or one of `commands` — on `target`,\n * `{ area: \"grid\" }` when left out, when it is visible and enabled there.\n * Reports it through `onCommand` with `source: \"api\"`, and says whether it\n * ran.\n */\n runCommand(commandId: string, target?: GridCommandTarget): boolean;\n /** Scrolls the row with the given id into view, if it is currently shown. */\n scrollToRow(rowId: string, options?: ScrollIntoViewOptions): void;\n /** Scrolls the column with the given id into view. */\n scrollToColumn(columnId: string, options?: ScrollIntoViewOptions): void;\n\n /**\n * Registers `listener` to be called after any render in which the grid's\n * internal state may have changed — every getter above may return a\n * different value once `listener` fires, not just one. Returns an\n * unsubscribe function. The primitive the `use*State` hooks under\n * `packages/react/src/DataGrid/hooks/` build on; most consumers should\n * reach for one of those instead of calling `subscribe` directly.\n */\n subscribe(listener: () => void): () => void;\n}\n\n/**\n * Defined in `@gridkitjs/core` with the rest of `GridOptions`, and exported\n * from here too so a React consumer needs one import.\n */\nexport type {\n Borders,\n GroupByBarVisibility,\n HoverableConfig,\n PaginationUnit,\n ResizeMode,\n};\n\n/**\n * A stable empty fallback for an omitted `aggregates` prop, for the parts of\n * the grid that draw aggregate cells — a fresh `[]` every render would hand\n * them a new array each time.\n */\nconst NO_AGGREGATES: AggregateState<never> = [];\n\n/**\n * `DataGridApi.getPagination`, read off `controller` at call time: the page\n * shown — clamped, unlike the stored index — and the page size. The same\n * object while both stay the same, since a `useSyncExternalStore` snapshot\n * built fresh on every read makes React warn and re-render forever.\n */\nfunction paginationReader<Row>(\n controller: DataGridController<Row>,\n): () => PaginationState {\n let last: PaginationState | undefined;\n return () => {\n const { pageIndex } = controller.getView();\n const { pageSize } = controller.getState().pagination;\n if (last?.pageIndex !== pageIndex || last.pageSize !== pageSize) {\n last = { pageIndex, pageSize };\n }\n return last;\n };\n}\n\n/**\n * Everything a `pager.template` render prop needs to rebuild the built-in\n * pager's UI itself. Passed fresh on every render where pagination-relevant\n * state changed, so it's current by construction — unlike `DataGridApi`'s\n * imperative methods and snapshot getters, which carry no \"something\n * changed, re-render\" signal of their own.\n */\nexport interface PagerTemplateContext {\n /** Same shape as `DataGridApi.getPagination()` — 0-based `pageIndex`. */\n pagination: PaginationState;\n /** `pagination.pageIndex + 1`, clamped — the display-ready page number. */\n currentPage: number;\n pageCount: number;\n /** Passthrough of `pager.sizeOptions`, undefined when not given. */\n pageSizeOptions: readonly number[] | undefined;\n /** 0-based, same as `DataGridApi.goToPage` — not `currentPage`'s numbering. */\n goToPage: (pageIndex: number) => void;\n nextPage: () => void;\n previousPage: () => void;\n setPageSize: (pageSize: number) => void;\n}\n\n/** Presentation options for the grid's built-in pager. */\nexport interface PagerConfig {\n /** Page sizes offered by the built-in pager's page-size control. */\n sizeOptions?: readonly number[] | undefined;\n /** Defaults to `\"compact\"` — today's Prev/status/Next. */\n variant?: \"compact\" | \"numbered\" | undefined;\n /** Numbered variant only. How many pages to always show at each end. Defaults to 1. */\n boundaryCount?: number | undefined;\n /** Numbered variant only. How many pages to show on each side of the current page. Defaults to 1. */\n siblingCount?: number | undefined;\n /** Replaces the built-in pager entirely when given. `variant` is ignored. */\n template?: ((context: PagerTemplateContext) => ReactNode) | undefined;\n}\n\n/**\n * Loads more rows as the user scrolls near the bottom, in place of paging.\n * Appends only — there is no equivalent of `paginated`'s reset-to-page-0 for\n * a result set that shrinks out from under the current position.\n */\nexport interface InfiniteScrollConfig {\n /** Whether a further `onLoadMore` could still return more rows. `false` removes the sentinel entirely, so no further scrolling can trigger a load. */\n readonly hasMore: boolean;\n /**\n * Called when the sentinel comes within `rootMargin` of the body's\n * viewport, then not again until one of these says the request was\n * answered: `isLoadingMore` goes back to `false`, `hasMore` changes, the\n * sentinel leaves range and comes back, or rows appended while\n * `isLoadingMore` never read `true` move the sentinel down.\n */\n readonly onLoadMore: () => void;\n /** Whether a load triggered by `onLoadMore` is still in flight. Suppresses further calls to it until this goes back to `false`. */\n readonly isLoadingMore?: boolean | undefined;\n /**\n * How far from the bottom of the scrollable body `onLoadMore` fires, ahead\n * of the sentinel actually scrolling into view, as CSS margins — an\n * intersection observer's `rootMargin`. Defaults to `\"200px\"`.\n */\n readonly rootMargin?: string | undefined;\n /** Replaces the built-in \"Loading more…\" row (`messages.loadingMore`). */\n readonly loadingTemplate?: (() => ReactNode) | undefined;\n}\n\n/**\n * The props that name a React type, and so have no place in the\n * framework-free `GridOptions`: columns whose templates return `ReactNode`,\n * the pager and infinite-scroll configs whose templates do too, and the\n * toolbar's custom entries.\n */\nexport interface ReactRenderSlots<Row> {\n columns?: readonly ColumnDefinition<Row>[] | undefined;\n /** Presentation options for the built-in pager. */\n pager?: PagerConfig | undefined;\n /**\n * Loads more rows as the user scrolls near the bottom, instead of paging.\n * Mutually exclusive with `paginated` — setting both logs a dev-time\n * `console.error` and only `paginated` takes effect. Recommended (not\n * required) alongside `virtualized` for a dataset that grows without\n * bound, so the mounted row count never grows with it either.\n */\n infiniteScroll?: InfiniteScrollConfig | undefined;\n /** Draws the toolbar's custom entries — `{ type: \"custom\", id }` — by id. */\n renderToolbarItem?: ((id: string) => ReactNode) | undefined;\n}\n\n/**\n * Every grid setting in `@gridkitjs/core`'s `GridOptions`, plus what only\n * React can express: render slots, selection callbacks carrying React-bound\n * columns, and the `ref`.\n */\nexport interface DataGridProps<Row>\n extends GridOptions<Row>, ReactRenderSlots<Row>, SelectionCallbacks<Row> {\n /** Imperative handle for reading live grid state and triggering actions. */\n ref?: Ref<DataGridApi<Row>> | undefined;\n}\n\n/**\n * `DataGridApi.getSelectedRows`, read off `controller` at call time: the\n * selected ids resolved against every filtered row. Recomputed only when the\n * rows or the selection change, so repeated reads are cheap and return the\n * same array.\n */\nfunction selectedRowsReader<Row>(\n controller: DataGridController<Row>,\n): () => readonly ResolvedRow<Row>[] {\n let last:\n | {\n readonly rows: readonly ResolvedRow<Row>[];\n readonly selection: SelectionState;\n readonly selected: readonly ResolvedRow<Row>[];\n }\n | undefined;\n return () => {\n const { rows } = controller.getView();\n const selection = controller.getState().rowSelection;\n if (last?.rows !== rows || last.selection !== selection) {\n const rowsById = new Map(rows.map((entry) => [entry.rowId, entry]));\n last = { rows, selection, selected: resolveRows(rowsById, selection) };\n }\n return last.selected;\n };\n}\n\n/**\n * The custom properties the scroll area's rules read, each set only when it\n * applies, so a grid with no `height` and no pinned column gets no `style`:\n * the rows' height and what the header and footer add to it, under\n * `height`, and the width pinned to each edge, while a column is pinned.\n */\nfunction tablesStyle(\n height: number | string | undefined,\n headerHeight: number | null,\n footerHeight: number | null,\n pinned: { readonly start: number; readonly end: number },\n): CSSProperties | undefined {\n const heights =\n height === undefined\n ? {}\n : {\n \"--gridkit-body-height\":\n typeof height === \"number\" ? `${String(height)}px` : height,\n ...(headerHeight === null\n ? {}\n : { \"--gridkit-header-height\": `${String(headerHeight)}px` }),\n ...(footerHeight === null\n ? {}\n : { \"--gridkit-footer-height\": `${String(footerHeight)}px` }),\n };\n const widths =\n pinned.start === 0 && pinned.end === 0\n ? {}\n : {\n \"--gridkit-pinned-start-width\": `${String(pinned.start)}px`,\n \"--gridkit-pinned-end-width\": `${String(pinned.end)}px`,\n };\n const style = { ...heights, ...widths };\n return Object.keys(style).length === 0 ? undefined : (style as CSSProperties);\n}\n\nexport function DataGrid<Row>(props: DataGridProps<Row>) {\n const {\n borders,\n hoverable,\n selectable,\n resizeMode = \"fit\",\n columnSizeDefaults,\n sortableColumns = false,\n groupableColumns = false,\n groupToggleIconColumns = true,\n groupByBarVisibility = \"auto\",\n paginated = false,\n pager,\n infiniteScroll,\n aggregates = NO_AGGREGATES as AggregateState<Row>,\n groupAggregateDisplay = \"inline\",\n height,\n virtualized = false,\n overscan = 4,\n estimatedRowHeight = 40,\n label,\n labelledBy,\n locale,\n getRowProps,\n onRowClick,\n onRowDoubleClick,\n messages: messageOverrides,\n ref,\n } = props;\n const hoverRows = hoverable?.rows ?? true;\n const hoverColumns = hoverable?.columns ?? true;\n const hoverCells = hoverable?.cells ?? true;\n\n const viewportRef = useRef<HTMLDivElement>(null);\n const gridRef = useRef<HTMLDivElement>(null);\n const headerTableRef = useRef<HTMLTableElement>(null);\n const bodyTableRef = useRef<HTMLTableElement>(null);\n const bodyRef = useRef<HTMLDivElement>(null);\n const footerTableRef = useRef<HTMLTableElement>(null);\n const sentinelRef = useRef<HTMLTableRowElement>(null);\n // The tables' scroll area rather than the viewport: a vertical scrollbar\n // takes its width from the scroll area, and columns filling the viewport\n // would then overflow it by that much.\n const viewportWidth = useElementWidth(gridRef, resizeMode === \"fit\");\n const subscribersRef = useRef(new Set<() => void>());\n /** The grid element's id, for the toolbar's `aria-controls`. */\n const gridId = useId();\n /** Reports a change no visual cue can carry to a screen reader. */\n const announce = useLiveAnnouncer(viewportRef);\n /** Every string the grid shows or announces, `messages` over the English defaults. */\n const messages = useMemo(\n () => resolveMessages(messageOverrides, locale),\n [messageOverrides, locale],\n );\n\n /**\n * Every slice of grid state, and everything the grid draws, comes from\n * here. The change callbacks go in wrapped, so each change is announced\n * where the controller reports it — see `announcedCallbacks`.\n */\n const { controller, state, view } = useGridController<Row>({\n ...props,\n viewportWidth,\n ...announcedCallbacks({\n callbacks: props,\n announce,\n messages,\n columnName,\n columnOf,\n }),\n });\n\n /**\n * `getPagination()`'s value: the page shown — clamped, unlike the stored\n * index — and the page size, kept as one object while both stay the same.\n * Read live off the controller rather than this render, so a read straight\n * after an action sees it.\n */\n const [readPagination] = useState(() => paginationReader(controller));\n const [readSelectedRows] = useState(() => selectedRowsReader(controller));\n\n /**\n * `enabled` is `virtualized` alone, independent of `height`: an `auto`\n * height body has no `overflow`, so its measured `clientHeight` covers\n * the whole content and the computed range naturally comes out as\n * everything anyway — the dev-time warning below is what tells a consumer\n * that combination does nothing useful, not a behavioral gate here.\n */\n const virtualizer = useRowVirtualizer({\n enabled: virtualized,\n rows: view.pageRows,\n scrollRef: gridRef,\n bodyTableRef,\n estimatedRowHeight,\n overscan,\n });\n\n useEffect(() => {\n if (virtualized && height === undefined) {\n console.error(\n \"DataGrid: `virtualized` has no effect without `height` — a body with no bounded height has no viewport to window rows against.\",\n );\n }\n }, [virtualized, height]);\n\n const hasInfiniteScroll = infiniteScroll !== undefined;\n useEffect(() => {\n if (paginated && hasInfiniteScroll) {\n console.error(\n \"DataGrid: `paginated` and `infiniteScroll` are mutually exclusive — only `paginated` takes effect while both are set.\",\n );\n }\n }, [paginated, hasInfiniteScroll]);\n\n useInfiniteScroll({\n rootRef: gridRef,\n sentinelRef,\n config: infiniteScroll,\n });\n\n /** A column's definition by id, hidden ones included. */\n function columnOf(columnId: string): ColumnDefinition<Row> | undefined {\n return view.dataColumns.find((candidate) => candidate.id === columnId)\n ?.column;\n }\n\n /** What a column is called in an announcement — see `resolveColumnHeaderText`. */\n function columnName(columnId: string): string {\n const column = columnOf(columnId);\n return column === undefined ? columnId : resolveColumnHeaderText(column);\n }\n\n const resize = useColumnResize<Row>({\n // `@gridkitjs/dom`'s `measureColumnContent` only ever matches\n // `td[data-gridkit-column]` (never `th`), so the header table has nothing\n // for it to find — the body table alone was already the effective scope\n // before this split.\n tableRef: bodyTableRef,\n controller,\n columnSizeDefaults,\n });\n const nav = useGridNavigation({\n gridRef,\n headerTableRef,\n bodyTableRef,\n // `null` when virtualization is off, in which case behavior is\n // byte-for-byte unchanged from before this feature existed.\n virtualRange: virtualized ? virtualizer : null,\n // Group headers are addressable rows too — the whole point of the flat\n // `DisplayRow[]` shape is that they share one position space with data\n // rows, so navigation counts them the same way. Page-relative\n // (`view.pageRows`, not `view.displayRows`): arrow keys operate on what's\n // actually in the DOM, which is the current page — a different \"page\"\n // concept than `useGridNavigation`'s own Page Up/Down viewport scrolling.\n rowCount: view.pageRows.length,\n columnCount: view.columns.length,\n // A group's own summary row (`groupAggregateDisplay: \"row\"`) occupies a\n // real slot in `rowCount` above — its DOM position has to line up with\n // everything else — but is presentational, never a tab stop: arrow-key\n // vertical movement steps over it rather than landing there.\n isSkippableRow: (rowIndex) => {\n const entry = view.pageRows[rowIndex];\n return entry?.kind === \"group-summary\";\n },\n });\n\n const overlay = useGridOverlay({\n nav,\n onContextMenuOpenChange: props.onContextMenuOpenChange,\n });\n const panels = useGridPanels({\n rootRef: viewportRef,\n headerTableRef,\n overlay,\n });\n const commands = useGridCommands({\n controller,\n commands: props.commands,\n onCommand: props.onCommand,\n messages,\n announce,\n resize,\n openPanel: panels.open,\n });\n const handleCopyKey = useGridCopy({ controller, commands, nav });\n\n /**\n * Every id in display order, hidden ones included — the list a column\n * move is made among, so a hidden column keeps its slot through a move\n * made around it.\n */\n const orderedIds = useMemo(\n () => view.dataColumns.map((entry) => entry.id),\n [view.dataColumns],\n );\n\n /**\n * The ids of the columns on screen, which a drag or a keyboard move is\n * resolved against: a move one place left has to pass the next visible\n * column, not stop in front of a hidden one and appear to do nothing.\n */\n const displayedIds = useMemo(\n () => view.columns.map((entry) => entry.id),\n [view.columns],\n );\n\n /** Every column's definition by id, hidden ones included, for a group header naming a hidden column. */\n const definitions = useMemo(\n () => new Map(view.dataColumns.map((entry) => [entry.id, entry.column])),\n [view.dataColumns],\n );\n\n /** Column ids whose header may be dragged into the group-by bar at all. */\n const groupByDraggableIds = useMemo(\n () =>\n new Set(\n view.columns\n .filter((entry) => entry.groupByDraggable)\n .map((entry) => entry.id),\n ),\n [view.columns],\n );\n\n /** The edge a column is pinned to, hidden ones included. */\n function pinOf(columnId: string): ColumnPin {\n const column = definitions.get(columnId);\n return column === undefined\n ? \"none\"\n : resolveColumnPin(column, state.columnPinning);\n }\n\n /**\n * The one place a drop is applied — the two-armed switch on `target.kind`\n * the group-by bar's own second drop zone was always going to need.\n */\n function handleDrop(target: ColumnDropTarget, movedId: string): void {\n if (target.kind === \"group-by\") {\n // Already announced: `moveGroupBy` reports through the same\n // `onGroupByChange` pipeline the header toggle and the bar's own chip\n // drag do, so this needs no announcement or focus-follow of its own —\n // unlike a column-order drop, the moved thing leaves the grid's single\n // tab-stop system entirely for the bar's own independently-focusable\n // chips, which have no shared index to update.\n controller.moveGroupBy(movedId, target.beforeColumnId);\n return;\n }\n\n // The order the controller will arrive at, worked out here as well for\n // where the column lands on screen. `moveColumnInPinGroup` hands back\n // the same reference for a move that changes nothing, a move past the\n // edge of the column's pin group included, so a drop in place neither\n // renders nor reports.\n const next = moveColumnInPinGroup(\n orderedIds,\n pinOf,\n movedId,\n target.beforeId,\n );\n if (next === orderedIds) {\n return;\n }\n controller.moveColumn(movedId, target.beforeId);\n // Counted among the columns on screen, which is what the user can see\n // and what the tab stop indexes. The move stays inside the column's pin\n // group, which starts where it did and keeps the new order within it.\n const pin = pinOf(movedId);\n const group = next.filter(\n (id) => pinOf(id) === pin && displayedIds.includes(id),\n );\n const position =\n displayedIds.findIndex((id) => pinOf(id) === pin) +\n group.indexOf(movedId);\n announce(\n messages.columnMoved(\n columnName(movedId),\n position + 1,\n displayedIds.length,\n ),\n );\n /**\n * The tab stop travels with the column. React reorders the headers by key,\n * so the browser's focus stays on the moved one by itself — without this\n * the stop would be left on whichever column took its index, and the next\n * arrow key would appear to do nothing.\n */\n nav.focusCell(headerFocus(position));\n }\n\n const drag = useColumnDrag<Row>({\n order: displayedIds,\n groupBy: state.groupBy,\n groupByDraggableIds,\n pinOf,\n onDrop: handleDrop,\n });\n\n /** Whether the header drag currently open (if any) is for a column already in the group-by stack — reordering it is the chip's job, so dragging it back in is never a valid target. */\n const draggedColumnAlreadyGrouped =\n drag.draggedColumnId !== null &&\n state.groupBy.some((entry) => entry.columnId === drag.draggedColumnId);\n\n /**\n * Whether the drag currently open (if any) could land on the group-by bar\n * — the signal `groupByBarVisibility=\"auto\"` needs to show the bar as a\n * drop target even while `groupBy` is still empty. Depends only on\n * `draggedColumnId` (set once the drag opens), the static\n * `groupByDraggableIds`, and whether that column is already grouped, never\n * the pointer's current position, so the bar mounts for the drag's whole\n * duration rather than flickering in only while directly hovering it.\n */\n const dragEligibleForGroupBy =\n drag.draggedColumnId !== null &&\n groupByDraggableIds.has(drag.draggedColumnId) &&\n !draggedColumnAlreadyGrouped;\n\n const showGroupByBar =\n groupByBarVisibility === \"always\" ||\n (groupByBarVisibility === \"auto\" &&\n (state.groupBy.length > 0 || dragEligibleForGroupBy));\n\n const headerGroupByDropTarget =\n drag.dropTarget?.kind === \"group-by\" ? drag.dropTarget : null;\n\n /** What the built-in pager draws, and what a `pager.template` is handed. */\n const pagerContext: PagerTemplateContext = {\n pagination: state.pagination,\n currentPage: Math.min(state.pagination.pageIndex + 1, view.pageCount),\n pageCount: view.pageCount,\n pageSizeOptions: pager?.sizeOptions,\n goToPage: controller.goToPage,\n nextPage: controller.nextPage,\n previousPage: controller.previousPage,\n setPageSize: controller.setPageSize,\n };\n\n const selection = useGridSelection<Row>({ controller, state, selectable });\n\n const multiselectable =\n selection.rowMode === \"multiple\" || selection.columnMode === \"multiple\";\n\n const contextMenu = useContextMenu({\n rootRef: viewportRef,\n scrollRef: gridRef,\n headerTableRef,\n bodyTableRef,\n bodyRef,\n footerTableRef,\n contextMenu: props.contextMenu,\n overlay,\n controller,\n commands,\n nav,\n selection,\n messages,\n columnName,\n });\n\n /**\n * Tells `subscribe`'s listeners once a render has drawn a change: to the\n * controller's state or view — whether an action or a prop made it — or to\n * the focused cell, which `@gridkitjs/dom`'s grid focus keeps apart from\n * the controller.\n *\n * Gated on those values, not run after every render: `useSyncExternalStore`\n * re-renders a subscriber that is notified, and a subscriber that renders\n * this grid as a plain (non-memoized) child would re-render it in turn and\n * be notified again, forever, though nothing ever changed. The state and\n * view objects keep their identity until something in them changes, which\n * is what breaks that cycle.\n */\n useEffect(() => {\n for (const listener of subscribersRef.current) {\n listener();\n }\n }, [view, state, nav.focus]);\n\n /**\n * No deps array: `nav`, `resize` and `virtualizer` are freshly\n * constructed every render (none of those hooks memoize their returned\n * API), so the handle has to be rebuilt every render too or its closures\n * would go stale. Grid state is read off the controller at call time.\n */\n useImperativeHandle(ref, () => ({\n get element() {\n return viewportRef.current;\n },\n get table() {\n return bodyTableRef.current;\n },\n getRows: () => controller.getView().rows,\n // Every group header's own `aggregates` field is populated here — the\n // whole reason `getDisplayRows()` is where a consumer reads a specific\n // group's computed results from.\n getDisplayRows: () => controller.getView().displayRows,\n getPageRows: () => controller.getView().pageRows,\n getColumns: () => controller.getView().columns,\n getDataColumns: () => controller.getView().dataColumns,\n getColumnSizing: () => controller.getState().columnSizing,\n getColumnOrder: () => controller.getState().columnOrder,\n getColumnVisibility: () => controller.getState().columnVisibility,\n getColumnPinning: () => controller.getState().columnPinning,\n getColumnSort: () => controller.getState().columnSort,\n getFilter: () => controller.getState().filter,\n getGroupBy: () => controller.getState().groupBy,\n getGroupExpansion: () => controller.getState().groupExpansion,\n getPagination: readPagination,\n getPageCount: () => controller.getView().pageCount,\n getAggregates: () => controller.getView().grandTotal,\n getRowSelection: () => controller.getState().rowSelection,\n getSelectedRows: readSelectedRows,\n getColumnSelection: () => controller.getState().columnSelection,\n getCellSelection: () => controller.getState().cellSelection,\n getFocusedCell: () => nav.focus,\n getState: controller.getState,\n restoreState: controller.restoreState,\n focusCell: nav.focusCell,\n clearSelection: controller.clearSelection,\n selectAllRows: controller.selectAllRows,\n selectRows: controller.selectRows,\n expandAllGroups: controller.expandAllGroups,\n collapseAllGroups: controller.collapseAllGroups,\n goToPage: controller.goToPage,\n nextPage: controller.nextPage,\n previousPage: controller.previousPage,\n setPageSize: controller.setPageSize,\n showColumns: controller.showColumns,\n hideColumns: controller.hideColumns,\n pinColumn: controller.pinColumn,\n setFilter: controller.setFilter,\n setColumnSort: controller.setColumnSort,\n setGroupBy: controller.setGroupBy,\n setGroupExpansion: controller.setGroupExpansion,\n setPagination: controller.setPagination,\n setColumnSizing: controller.setColumnSizing,\n setColumnOrder: controller.setColumnOrder,\n setColumnVisibility: controller.setColumnVisibility,\n setColumnPinning: controller.setColumnPinning,\n setRowSelection: controller.setRowSelection,\n setColumnSelection: controller.setColumnSelection,\n setCellSelection: controller.setCellSelection,\n autoFitColumn: (columnId) => {\n commands.host.autoFitColumns([columnId]);\n },\n autoFitColumns: (columnIds) => {\n commands.host.autoFitColumns(\n columnIds ?? controller.getView().columns.map((entry) => entry.id),\n );\n },\n openContextMenu: contextMenu.open,\n closeContextMenu: contextMenu.close,\n ...exportApi(commands),\n ...printApi(commands),\n ...panelApi(panels, controller),\n runCommand: (commandId, target = { area: \"grid\" }) =>\n commands.run(commandId, target, \"api\"),\n scrollToRow: (rowId, options) => {\n // `pageRows`, not `displayRows`: a data row's DOM position is its place\n // in the currently rendered page — with grouping active, that's its\n // place in the grouped, flattened output; with pagination also active,\n // that's the page's own slice of it. A row on a different page isn't\n // in the DOM at all, so there is nothing to scroll to.\n const index = controller\n .getView()\n .pageRows.findIndex(\n (entry) => entry.kind === \"data\" && entry.rowId === rowId,\n );\n if (index === -1) return;\n // Under virtualization the target row may not be mounted at all —\n // `virtualizer.scrollToIndex` estimates, scrolls, and self-corrects\n // once it mounts and is measured, rather than reaching for a DOM row\n // that may not exist.\n if (virtualized) {\n virtualizer.scrollToIndex(index, options);\n return;\n }\n bodyTableRef.current?.tBodies[0]?.rows[index]?.scrollIntoView(options);\n },\n scrollToColumn: (columnId, options) => {\n // The whole viewport, not just one table: a column's cells with\n // `data-gridkit-column` now live across three sibling tables\n // (header/body/footer) rather than one, and the header's `<th>` is\n // the one guaranteed to exist even when the body has no rows.\n const cells = viewportRef.current?.querySelectorAll(\n \"[data-gridkit-column]\",\n );\n const cell = cells\n ? Array.from(cells).find(\n (entry) => entry.getAttribute(\"data-gridkit-column\") === columnId,\n )\n : undefined;\n cell?.scrollIntoView(options);\n },\n subscribe: (listener) => {\n subscribersRef.current.add(listener);\n return () => {\n subscribersRef.current.delete(listener);\n };\n },\n }));\n\n // Shared by all three tables below, so borders/hover/selectable styling —\n // every `.gridkit-data-grid.<modifier>` rule in `theme-tailwind` — applies\n // identically to each rather than only to whichever one happened to carry\n // it. Each rule's own descendant selector (e.g. `.gridkit-borders-horizontal\n // .gridkit-grid-cell`) still needs the modifier class on that cell's own table\n // ancestor, which is exactly what splitting into one table per section\n // would otherwise lose.\n const gridTableClassName = classNames(\n \"gridkit-data-grid\",\n borders ? `gridkit-borders-${borders}` : \"\",\n // Hover is on by default and selection off, so one set of classes\n // turns styling off and the other turns it on. The polarity differs\n // because the defaults do.\n hoverRows ? \"\" : \"gridkit-no-hover-rows\",\n hoverColumns ? \"\" : \"gridkit-no-hover-columns\",\n hoverCells ? \"\" : \"gridkit-no-hover-cells\",\n selection.rowMode === false ? \"\" : \"gridkit-selectable-rows\",\n selection.columnMode === false ? \"\" : \"gridkit-selectable-columns\",\n selection.cellMode === false ? \"\" : \"gridkit-selectable-cells\",\n );\n const hasFooter = aggregates.length > 0;\n // What the header and footer, sticking to the scroll area's top and\n // bottom, cover of it: the area grows by both, so `height` is the rows'\n // alone, and keyboard focus scrolls a cell clear of both.\n const headerHeight = useElementHeight(headerTableRef, height !== undefined);\n const footerHeight = useElementHeight(\n footerTableRef,\n height !== undefined && hasFooter,\n );\n\n return (\n <div\n className=\"gridkit-data-grid-viewport\"\n ref={viewportRef}\n // Chromium and Firefox make an element that scrolls a Tab stop of its\n // own; the grid's one stop is its roving cell, so no scroller takes a\n // place in the Tab order: not the tables below, nor this one, which\n // scrolls only when something beside them is wider than it.\n tabIndex={-1}\n >\n <GridToolbar<Row>\n toolbar={props.toolbar}\n renderItem={props.renderToolbarItem}\n gridId={gridId}\n controller={controller}\n commands={commands}\n messages={messages}\n announce={announce}\n />\n {showGroupByBar && (\n <GroupByBar<Row>\n columns={view.columns}\n definitions={definitions}\n groupBy={state.groupBy}\n controller={controller}\n columnName={columnName}\n headerDragEligible={dragEligibleForGroupBy}\n headerDragBlocked={draggedColumnAlreadyGrouped}\n headerDropTarget={headerGroupByDropTarget}\n messages={messages}\n />\n )}\n <div\n ref={gridRef}\n id={gridId}\n className=\"gridkit-data-grid-tables\"\n /*\n * `role=\"grid\"` sits on this wrapper rather than any one of the\n * three `<table>`s below: the WAI-ARIA grid pattern needs a single\n * ancestor holding every row — header, body, and (when aggregates\n * are active) footer alike — and no one table is an ancestor of the\n * other two's rows now that they're split. It obliges the single\n * tab stop `useGridNavigation` keeps.\n *\n * So each `<table>` is `role=\"presentation\"`, and the header and\n * footer sections, the body's wrapper, and every row and cell carry\n * `rowgroup`, `row`, `columnheader` and `gridcell` explicitly: a native table inside a grid would own those rows\n * itself, with its own implicit roles, leaving the grid none, and\n * would make a group row's `aria-level`/`aria-expanded` invalid on\n * what is then a plain table row. The tables stay for layout alone.\n *\n * Switches to `\"treegrid\"` — the WAI-ARIA pattern for expandable,\n * collapsible rows — whenever `groupBy` is non-empty, rather than\n * committing to it unconditionally. The alternative (always\n * `treegrid`) would change what every existing, ungrouped consumer\n * announces to assistive technology the moment this feature shipped;\n * that regression is certain, while the edge case this trades away —\n * the role flipping mid-session if a consumer removes its last\n * group-by level — is rare and, per the WAI-ARIA grid pattern, still\n * a valid `role` change to make when the row structure itself\n * changes shape. See the \"Scope note\" this mirrors: grouping stays\n * an internal detail for an ungrouped grid, ARIA role included.\n */\n role={state.groupBy.length > 0 ? \"treegrid\" : \"grid\"}\n // The header is a row too, and counted from one; group headers (and,\n // under `groupAggregateDisplay: \"row\"`, each group's own summary\n // row) count as rows here too, the same way they do in `nav`'s\n // `rowCount`, and so does the grand-total footer. `view.displayRows`,\n // not `view.pageRows`: the total dataset count, not the current\n // page's, so this stays the true row count per the WAI-ARIA grid\n // pattern even while paged.\n aria-rowcount={view.displayRows.length + (hasFooter ? 2 : 1)}\n aria-colcount={view.columns.length}\n // The one element that scrolls the rows, both ways, with the header\n // and footer sticking to its top and bottom: a Tab stop of its own\n // in Chromium and Firefox otherwise, as the viewport's note says.\n tabIndex={-1}\n style={tablesStyle(\n height,\n headerHeight,\n footerHeight,\n pinnedWidths(view.columns),\n )}\n {...ariaAttr(multiselectable, \"aria-multiselectable\", true)}\n {...ariaAttr(labelledBy !== undefined, \"aria-labelledby\", labelledBy)}\n {...ariaAttr(\n labelledBy === undefined && label !== undefined,\n \"aria-label\",\n label,\n )}\n onKeyDown={(event) => {\n // The keys that address the grid rather than a cell, caught here\n // where everything bubbles to rather than in each of them.\n if (!isOwnEvent(event)) return;\n handleCopyKey(event);\n if (event.key === \"Escape\") {\n // A gesture in flight has its own use for Escape — cancelling —\n // and gets it first.\n if (drag.draggedColumnId !== null || resize.activeColumnId !== null)\n return;\n selection.clear();\n return;\n }\n if (\n (event.ctrlKey || event.metaKey) &&\n (event.key === \"a\" || event.key === \"A\")\n ) {\n // Left to the browser unless the grid has something to do with it,\n // so a grid without multiple rows does not swallow select-all.\n if (selection.rowMode !== \"multiple\") return;\n event.preventDefault();\n selection.selectAllRows();\n }\n }}\n >\n <table\n ref={headerTableRef}\n role=\"presentation\"\n // Widths are only honoured exactly when the table is as wide as its\n // columns; at `100%` the fixed layout redistributes the difference.\n style={{ width: totalColumnWidth(view.columns) }}\n className={classNames(gridTableClassName, \"gridkit-data-grid-header\")}\n >\n <GridColgroup columns={view.columns} />\n <GridHeader<Row>\n columns={view.columns}\n resize={resize}\n drag={drag}\n controller={controller}\n state={state}\n sortableColumns={sortableColumns}\n groupableColumns={groupableColumns}\n groupToggleIconColumns={groupToggleIconColumns}\n headerMenu={contextMenu.opens(\"header\")}\n panels={panels}\n messages={messages}\n nav={nav}\n selection={selection}\n />\n </table>\n\n <div\n className=\"gridkit-data-grid-body\"\n ref={bodyRef}\n // The body's rowgroup, rather than its `<tbody>`: an element that\n // can take focus, as `tabIndex` makes this one, must have a role\n // the grid allows among its children, and a rowgroup may not hold\n // another, so the `<tbody>` inside is presentational. Focusable\n // from script and by a click on the rows' empty space, never by\n // Tab.\n role=\"rowgroup\"\n tabIndex={-1}\n >\n <table\n ref={bodyTableRef}\n role=\"presentation\"\n style={{ width: totalColumnWidth(view.columns) }}\n className={gridTableClassName}\n >\n <GridColgroup columns={view.columns} />\n <GridBody<Row>\n columns={view.columns}\n definitions={definitions}\n rows={view.pageRows}\n activeColumnId={resize.activeColumnId}\n nav={nav}\n selection={selection}\n controller={controller}\n aggregates={aggregates}\n groupAggregateDisplay={groupAggregateDisplay}\n virtualRange={virtualized ? virtualizer : null}\n infiniteScroll={infiniteScroll}\n sentinelRef={sentinelRef}\n locale={locale}\n getRowProps={getRowProps}\n onRowClick={onRowClick}\n onRowDoubleClick={onRowDoubleClick}\n messages={messages}\n cellMenu={contextMenu.opens(\"cell\")}\n groupMenu={contextMenu.opens(\"group\")}\n />\n </table>\n </div>\n\n {hasFooter && (\n <table\n ref={footerTableRef}\n role=\"presentation\"\n style={{ width: totalColumnWidth(view.columns) }}\n className={classNames(\n gridTableClassName,\n \"gridkit-data-grid-footer\",\n )}\n >\n <GridColgroup columns={view.columns} />\n <GridFooter<Row>\n columns={view.columns}\n aggregates={aggregates}\n results={view.grandTotal}\n rows={view.rows.map((entry) => entry.row)}\n locale={locale}\n ariaRowIndex={view.displayRows.length + 2}\n />\n </table>\n )}\n </div>\n <GridContextMenu contextMenu={contextMenu} />\n <GridPanels\n panels={panels}\n controller={controller}\n commands={commands}\n messages={messages}\n />\n {paginated &&\n (pager?.template ? (\n pager.template(pagerContext)\n ) : (\n <GridPager pager={pagerContext} config={pager} messages={messages} />\n ))}\n </div>\n );\n}\n","import type { ResolvedColumn } from \"../DataGrid\";\n\ninterface GridColgroupProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n}\n\n/**\n * One `<colgroup>`, shared verbatim by the header, body, and footer\n * `<table>`s so all three render identical column widths from one source\n * rather than three independent copies of the same `.map()`.\n */\nexport default function GridColgroup<Row>({ columns }: GridColgroupProps<Row>) {\n return (\n <colgroup>\n {columns.map((entry) => (\n <col key={entry.id} style={{ width: entry.width }} />\n ))}\n </colgroup>\n );\n}\n","import { createPortal } from \"react-dom\";\nimport {\n headerFocus,\n isColumnFiltered,\n sortDirectionFor,\n sortPriorityFor,\n type GridMessages,\n type GridState,\n} from \"@gridkitjs/core\";\nimport {\n buildKeyShortcuts,\n inlineStep,\n intentOf,\n KEYBOARD_STEP,\n resolveColumnFilterMenu,\n} from \"@gridkitjs/core/renderer\";\nimport { writingDirection } from \"@gridkitjs/dom\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport {\n ChevronsUpDownIcon,\n ChevronUpIcon,\n FilterIcon,\n GroupIcon,\n} from \"../icons\";\nimport { isOwnEvent } from \"../isOwnEvent\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport type { GridPanelsApi } from \"../panels/useGridPanels\";\nimport type { ColumnDragApi } from \"../useColumnDrag\";\nimport type { ColumnResizeApi } from \"../useColumnResize\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\nimport {\n keyboardSelectIntent,\n type GridSelectionApi,\n} from \"../useGridSelection\";\nimport type { DataGridController } from \"../useGridController\";\n\ninterface GridHeaderProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n resize: ColumnResizeApi<Row>;\n drag: ColumnDragApi<Row>;\n /** What a header toggle changes — the sort and the group-by stack. */\n controller: DataGridController<Row>;\n /** The state this render draws: the sort, grouping and filter the headers show. */\n state: GridState<Row>;\n sortableColumns: boolean;\n groupableColumns: boolean;\n groupToggleIconColumns: boolean;\n /** Whether a header opens the grid's context menu, which its `aria-keyshortcuts` says. */\n headerMenu: boolean;\n /** Where a header opens its column's filter menu. */\n panels: GridPanelsApi;\n messages: GridMessages;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n}\n\nexport default function GridHeader<Row>({\n columns,\n resize,\n drag,\n controller,\n state,\n sortableColumns,\n groupableColumns,\n groupToggleIconColumns,\n headerMenu,\n panels,\n messages,\n nav,\n selection,\n}: GridHeaderProps<Row>) {\n const { columnSort, groupBy, filter } = state;\n // Only meaningful for the \"column-order\" branch — a drop headed for the\n // group-by bar instead (`kind: \"group-by\"`) draws no indicator here at\n // all; `GroupByBar` draws its own from the same `drag.dropTarget`.\n const beforeId =\n drag.dropTarget?.kind === \"column-order\"\n ? drag.dropTarget.beforeId\n : undefined;\n const draggedEntry =\n columns.find((entry) => entry.id === drag.draggedColumnId) ?? null;\n\n /**\n * Opens the column's filter menu, or closes it when it is the one open: a\n * press on the header it opened from leaves it open, so pressing its\n * button again is the way back out.\n */\n function toggleFilterMenu(columnId: string): void {\n const panel = panels.current();\n if (\n panel?.kind === \"filter\" &&\n panel.target.area === \"header\" &&\n panel.target.columnId === columnId\n ) {\n panels.close();\n } else {\n panels.open(\"filter\", { area: \"header\", columnId });\n }\n }\n\n return (\n <thead role=\"rowgroup\">\n <tr className=\"gridkit-grid-header\" role=\"row\" aria-rowindex={1}>\n {columns.map((entry, index) => {\n const { column } = entry;\n const resizing = resize.activeColumnId === entry.id;\n const dragging = drag.draggedColumnId === entry.id;\n\n // A drag keeps its column in its pin group, so the other groups'\n // headers say they won't take it for as long as it lasts.\n const dragBlocked =\n draggedEntry !== null && entry.pinned !== draggedEntry.pinned;\n /**\n * Drawn on the gap's own edge, so the one gap between two columns is\n * marked once, and inside the dragged column's pin group: the gap\n * at a group's end is drawn after its last column, not before the\n * next group's first. No guard against the dragged column: the hook\n * reports only gaps that would move it.\n */\n const next = columns[index + 1];\n const dropBefore = beforeId === entry.id && !dragBlocked;\n const dropAfter =\n !dragBlocked &&\n (next === undefined\n ? beforeId === null\n : beforeId === next.id && next.pinned !== entry.pinned);\n const selected = selection.selectedColumnIds.has(entry.id);\n const sortable = column.sortable ?? sortableColumns;\n const sortDirection = sortDirectionFor(columnSort, entry.id);\n // Only meaningful once two or more columns are stacked.\n const sortPriority = sortPriorityFor(columnSort, entry.id);\n const groupable = column.groupable ?? groupableColumns;\n // Purely a rendering choice — see the prop's own doc comment. Never\n // gates `groupable` itself, `aria-keyshortcuts`, or `Alt+ArrowDown`.\n const showGroupToggleIcon =\n column.groupToggleIcon ?? groupToggleIconColumns;\n const isGrouped = groupBy.some(\n (level) => level.columnId === entry.id,\n );\n const filterable =\n resolveColumnFilterMenu(controller.getOptions(), column) !== null;\n // Shown, and described, only where the header opens the menu that\n // changes it: a grid filtering a column in code alone keeps its\n // headers as they were.\n const filtered = filterable && isColumnFiltered(filter, entry.id);\n\n const shortcuts = buildKeyShortcuts({\n reorderable: entry.reorderable,\n resizable: entry.resizable,\n sortable,\n groupable,\n filterable,\n contextMenu: headerMenu,\n });\n\n return (\n <th\n key={entry.id}\n scope=\"col\"\n // Explicit, like every structural role in the grid: each\n // `<table>` is `role=\"presentation\"`, so the rows and cells\n // belong to the `grid`/`treegrid` wrapper rather than to a\n // native table, and only an explicit role survives that.\n role=\"columnheader\"\n data-gridkit-column={entry.id}\n aria-colindex={index + 1}\n tabIndex={nav.tabIndexFor(headerFocus(index))}\n {...ariaAttr(\n selection.columnMode !== false,\n \"aria-selected\",\n selected,\n )}\n onFocus={() => {\n nav.focusCell(headerFocus(index));\n }}\n onClick={(event) => {\n /*\n * A drag ends in a click on the header it started from, and a\n * resize in one on the handle inside it. Neither is the press\n * that selects a column, so both are shown the door here —\n * the drag by the distance it travelled, the resize by where\n * it began.\n */\n if (drag.justDragged(entry.id)) {\n return;\n }\n if (\n event.target instanceof Element &&\n (event.target.closest(\".gridkit-header-resize-handle\") !==\n null ||\n event.target.closest(\".gridkit-header-sort-toggle\") !==\n null ||\n event.target.closest(\".gridkit-header-group-toggle\") !==\n null ||\n event.target.closest(\".gridkit-header-filter-toggle\") !==\n null)\n ) {\n return;\n }\n selection.selectColumn(entry.id, intentOf(event));\n }}\n onKeyDown={(event) => {\n if (!isOwnEvent(event)) return;\n // Toward the next column moves it later and grows it, its\n // resize handle being on that side.\n const step = inlineStep(\n event.key,\n writingDirection(event.currentTarget),\n );\n\n if (step !== null && event.ctrlKey && entry.reorderable) {\n event.preventDefault();\n drag.moveByKeyboard(entry, step);\n return;\n }\n if (step !== null && event.altKey && entry.resizable) {\n event.preventDefault();\n resize.nudge(entry, step * KEYBOARD_STEP);\n return;\n }\n // The keyboard equivalent of double-clicking the resize\n // handle, which auto-fits the column to its content.\n if (event.key === \"Enter\" && event.altKey && entry.resizable) {\n event.preventDefault();\n resize.sizeToContent(entry);\n return;\n }\n if (event.key === \"ArrowUp\" && event.altKey && sortable) {\n event.preventDefault();\n controller.toggleColumnSort(entry.id, {\n stack: event.shiftKey,\n });\n return;\n }\n // Shift sets the filter menu apart from grouping, which\n // holds Alt+ArrowDown — the key Excel opens its filter with.\n if (\n event.key === \"ArrowDown\" &&\n event.altKey &&\n event.shiftKey &&\n filterable\n ) {\n event.preventDefault();\n toggleFilterMenu(entry.id);\n return;\n }\n if (\n event.key === \"ArrowDown\" &&\n event.altKey &&\n !event.shiftKey &&\n groupable\n ) {\n event.preventDefault();\n controller.toggleGroupBy(entry.id);\n return;\n }\n // Space builds a selection up and Enter replaces it, as in the\n // body. Taken either way, or Space scrolls the grid away.\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n selection.selectColumn(\n entry.id,\n intentOf(keyboardSelectIntent(event)),\n );\n return;\n }\n nav.onKeyDown(event);\n }}\n className={classNames(\n \"gridkit-header-cell\",\n // The grab affordance a header showing either drag\n // destination shares — a column dragged only for grouping\n // (`groupByDraggable` without `reorderable`) grabs the same\n // way one dragged only for reordering does.\n entry.reorderable || entry.groupByDraggable\n ? \"is-reorderable\"\n : \"\",\n selected ? \"is-selected\" : \"\",\n resizing ? \"is-resizing\" : \"\",\n dragging ? \"is-dragging\" : \"\",\n dropBefore ? \"is-drop-before\" : \"\",\n dropAfter ? \"is-drop-after\" : \"\",\n dragBlocked ? \"is-drag-blocked\" : \"\",\n column.wrap?.header ? \"is-wrapped\" : \"\",\n pinnedCellClassNames(entry),\n column.headerClassName ?? \"\",\n )}\n style={pinnedCellStyle(entry)}\n {...ariaAttr(shortcuts !== \"\", \"aria-keyshortcuts\", shortcuts)}\n {...ariaAttr(\n filtered,\n \"aria-description\",\n messages.columnFiltered,\n )}\n {...ariaAttr<\"aria-sort\", \"ascending\" | \"descending\">(\n sortable && sortDirection !== null,\n \"aria-sort\",\n sortDirection === \"asc\" ? \"ascending\" : \"descending\",\n )}\n {...((entry.reorderable || entry.groupByDraggable) && {\n onPointerDown: (event) => {\n drag.startDrag(entry, event);\n },\n })}\n >\n {groupable && showGroupToggleIcon && (\n /*\n * Inline, before the label, rather than absolutely\n * positioned like the sort toggle and resize handle: those\n * two already share the header's right edge, and a third\n * overlay there would need its own carve-out. Sitting in\n * normal flow costs nothing but a few pixels of label width.\n * A pointer affordance only, same as the other two — the\n * keyboard equivalent is Alt+ArrowDown on the header itself.\n */\n <span\n className={classNames(\n \"gridkit-header-group-toggle\",\n isGrouped ? \"is-grouped\" : \"\",\n )}\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n // See the sort toggle's own note: otherwise a\n // reorderable header's drag would swallow this click.\n event.stopPropagation();\n }}\n onClick={(event) => {\n event.stopPropagation();\n controller.toggleGroupBy(entry.id);\n }}\n >\n <GroupIcon />\n </span>\n )}\n {entry.label}\n {sortable && (\n /*\n * A pointer affordance only, and hidden from assistive\n * technology like the resize handle: the keyboard equivalent\n * lives on the header itself, under Alt+ArrowUp (plain) /\n * Alt+Shift+ArrowUp (stacking).\n */\n <span\n className={classNames(\n \"gridkit-header-sort-toggle\",\n sortDirection !== null ? `is-sorted-${sortDirection}` : \"\",\n )}\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n /*\n * Otherwise a reorderable header's own `onPointerDown`\n * sees this bubble up and starts a column drag, whose\n * pointer capture then redirects the click that\n * follows to the `th` — the same reason `startResize`\n * stops it for the resize handle.\n */\n event.stopPropagation();\n }}\n onClick={(event) => {\n controller.toggleColumnSort(entry.id, {\n stack: event.shiftKey,\n });\n }}\n >\n {sortDirection === null ? (\n <ChevronsUpDownIcon />\n ) : (\n <ChevronUpIcon />\n )}\n {sortPriority !== null && sortPriority > 1 && (\n <span className=\"gridkit-header-sort-priority\">\n {sortPriority}\n </span>\n )}\n </span>\n )}\n {filterable && (\n /*\n * A pointer affordance only, like the sort toggle: the\n * keyboard opens the menu from the header itself, under\n * Alt+Shift+ArrowDown, and a screen reader hears the\n * filtered state as the header's description.\n */\n <span\n className={classNames(\n \"gridkit-header-filter-toggle\",\n filtered ? \"is-filtered\" : \"\",\n )}\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n // See the sort toggle's own note.\n event.stopPropagation();\n }}\n onClick={() => {\n toggleFilterMenu(entry.id);\n }}\n >\n <FilterIcon />\n </span>\n )}\n {entry.resizable && (\n /*\n * A pointer affordance only, and hidden from assistive\n * technology accordingly: a focusable handle per column would\n * put N tab stops inside a widget that is meant to have one.\n * The keyboard resizes from the header itself, under Alt.\n */\n <span\n className=\"gridkit-header-resize-handle\"\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n resize.startResize(entry, event);\n }}\n onDoubleClick={() => {\n resize.sizeToContent(entry);\n }}\n />\n )}\n </th>\n );\n })}\n </tr>\n {/*\n * Portalled to the body, and not only because a `div` cannot sit in a\n * `tr`: inside the viewport the overflow that makes the grid scroll\n * would clip it.\n */}\n {draggedEntry !== null &&\n drag.ghostTransform !== null &&\n createPortal(\n <div\n className=\"gridkit-data-grid gridkit-header-cell gridkit-drag-ghost\"\n style={{\n width: draggedEntry.width,\n transform: drag.ghostTransform,\n }}\n aria-hidden=\"true\"\n >\n {draggedEntry.label}\n </div>,\n document.body,\n )}\n </thead>\n );\n}\n","/**\n * Collapses the `{...(condition && { \"aria-foo\": value })}` idiom for\n * conditionally including a single ARIA attribute in a JSX spread.\n */\nexport function ariaAttr<K extends string, V>(\n condition: boolean,\n key: K,\n value: V,\n): Record<K, V> | Record<string, never> {\n return condition ? ({ [key]: value } as Record<K, V>) : {};\n}\n","export function classNames(\n ...values: (string | false | null | undefined)[]\n): string {\n return values.filter(Boolean).join(\" \");\n}\n","import type { ReactNode } from \"react\";\n\n/** The common attributes behind every icon the grid draws — just the `<path>`s differ. */\nexport function Icon({ children }: { children: ReactNode }) {\n return (\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n {children}\n </svg>\n );\n}\n\n/**\n * The two glyphs a sort toggle shows: a neutral hint before a column has a\n * direction, and a single chevron reused for both directions once it does —\n * `theme-tailwind` rotates it 180° for `desc` rather than swapping icons.\n */\nexport function ChevronsUpDownIcon() {\n return (\n <Icon>\n <path d=\"m7 15 5 5 5-5\" />\n <path d=\"m7 9 5-5 5 5\" />\n </Icon>\n );\n}\n\nexport function ChevronUpIcon() {\n return (\n <Icon>\n <path d=\"m18 15-6-6-6 6\" />\n </Icon>\n );\n}\n\n/** Three stacked panes, standing in for \"group by this column\". */\nexport function GroupIcon() {\n return (\n <Icon>\n <rect x=\"3\" y=\"3\" width=\"7\" height=\"7\" rx=\"1\" />\n <rect x=\"14\" y=\"3\" width=\"7\" height=\"7\" rx=\"1\" />\n <rect x=\"8.5\" y=\"14\" width=\"7\" height=\"7\" rx=\"1\" />\n </Icon>\n );\n}\n\n/** A funnel, standing in for \"filter this column\". */\nexport function FilterIcon() {\n return (\n <Icon>\n <path d=\"M22 3H2l8 9.46V19l4 2v-8.54z\" />\n </Icon>\n );\n}\n\n/** The pager's previous-page chevron; `theme-tailwind` mirrors the pager's chevrons right-to-left. */\nexport function ChevronLeftIcon() {\n return (\n <Icon>\n <path d=\"m15 18-6-6 6-6\" />\n </Icon>\n );\n}\n\nexport function ChevronRightIcon() {\n return (\n <Icon>\n <path d=\"m9 18 6-6-6-6\" />\n </Icon>\n );\n}\n\n/** The pager's first-page double chevron. */\nexport function ChevronsLeftIcon() {\n return (\n <Icon>\n <path d=\"m11 17-5-5 5-5\" />\n <path d=\"m18 17-5-5 5-5\" />\n </Icon>\n );\n}\n\nexport function ChevronsRightIcon() {\n return (\n <Icon>\n <path d=\"m6 17 5-5-5-5\" />\n <path d=\"m13 17 5-5-5-5\" />\n </Icon>\n );\n}\n","/**\n * Whether `event` happened inside the element whose handler is running.\n * React bubbles a portal's events up the component tree rather than the DOM,\n * so a panel rendered into `document.body` from inside the grid still reaches\n * the grid's key handlers — and Escape or Ctrl+A pressed in it is the\n * panel's, not the grid's.\n */\nexport function isOwnEvent(event: {\n readonly currentTarget: Element;\n readonly target: EventTarget;\n}): boolean {\n return (\n event.target instanceof Node && event.currentTarget.contains(event.target)\n );\n}\n","import type { CSSProperties } from \"react\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport { classNames } from \"./classNames\";\n\n/** Where a column is pinned, as `core`'s view resolved it. */\ntype PinPlacement = Pick<\n ResolvedColumn<unknown>,\n \"pinned\" | \"pinOffset\" | \"pinEdge\"\n>;\n\n/**\n * The state classes of a pinned column's header, body, footer and summary\n * cells: its edge, and `is-pinned-edge` on the column beside the scrolling\n * ones. `\"\"` for an unpinned column.\n */\nexport function pinnedCellClassNames({\n pinned,\n pinEdge,\n}: PinPlacement): string {\n if (pinned === \"none\") return \"\";\n return classNames(\n pinned === \"start\" ? \"is-pinned-start\" : \"is-pinned-end\",\n pinEdge && \"is-pinned-edge\",\n );\n}\n\n/**\n * The one style a cell carries for pinning: its distance from its edge,\n * which the stylesheet's sticky inset reads. Per cell, so it cannot live in\n * the stylesheet. Nothing for an unpinned column.\n */\nexport function pinnedCellStyle({\n pinned,\n pinOffset,\n}: PinPlacement): CSSProperties | undefined {\n if (pinned === \"none\") return undefined;\n return {\n \"--gridkit-pin-offset\": `${String(pinOffset)}px`,\n } as CSSProperties;\n}\n","import { useMemo, type KeyboardEvent as ReactKeyboardEvent } from \"react\";\nimport type {\n CellSelectionMode,\n CellSelectionState,\n GridState,\n SelectableConfig,\n SelectedCellRef,\n SelectIntent,\n SelectionMode,\n} from \"@gridkitjs/core\";\nimport type { DataGridController } from \"./useGridController\";\n\n/**\n * The modifiers a Space or Enter keydown carries, for a caller that means to\n * hand them to `intentOf` as a click's modifiers would be. Space builds a\n * selection up and Enter replaces it, as in the body — so Space is mapped to\n * act like Ctrl, matching Ctrl-click and the plain click they stand in for.\n */\nexport function keyboardSelectIntent(event: ReactKeyboardEvent): {\n ctrlKey: boolean;\n metaKey: boolean;\n shiftKey: boolean;\n} {\n return {\n ctrlKey: event.key === \" \" || event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n };\n}\n\ninterface UseGridSelectionOptions<Row> {\n controller: DataGridController<Row>;\n state: GridState<Row>;\n selectable: SelectableConfig | undefined;\n}\n\nexport interface GridSelectionApi {\n rowMode: SelectionMode;\n columnMode: SelectionMode;\n cellMode: CellSelectionMode;\n /** Whether a plain click on a row toggles it — `selectable.toggleOnClick`. */\n toggleOnClick: boolean;\n /**\n * Lookups for the render pass. The state itself stays an ordered list, which\n * is what makes the most recent selection its last entry.\n */\n selectedRowIds: ReadonlySet<string>;\n selectedColumnIds: ReadonlySet<string>;\n selectedCell: CellSelectionState;\n selectRow: (rowId: string, intent: SelectIntent) => void;\n selectColumn: (columnId: string, intent: SelectIntent) => void;\n selectCell: (cell: SelectedCellRef, intent: SelectIntent) => void;\n selectAllRows: () => void;\n /** Lets go of every selection at once, as Escape does. */\n clear: () => void;\n}\n\n/**\n * The selection as the header and body draw and change it. The selections\n * themselves, the intent each click carries and the callbacks it fires all\n * live in the grid's controller; this hook only adds the lookups a render\n * pass wants and names the actions the components call.\n */\nexport default function useGridSelection<Row>({\n controller,\n state,\n selectable,\n}: UseGridSelectionOptions<Row>): GridSelectionApi {\n const selectedRowIds = useMemo(\n () => new Set(state.rowSelection),\n [state.rowSelection],\n );\n const selectedColumnIds = useMemo(\n () => new Set(state.columnSelection),\n [state.columnSelection],\n );\n\n // A new object each render, as the other hooks here return.\n return {\n rowMode: selectable?.rows ?? false,\n columnMode: selectable?.columns ?? false,\n cellMode: selectable?.cells ?? false,\n toggleOnClick: selectable?.toggleOnClick ?? false,\n selectedRowIds,\n selectedColumnIds,\n selectedCell: state.cellSelection,\n selectRow: controller.selectRow,\n selectColumn: controller.selectColumn,\n selectCell: controller.selectCell,\n selectAllRows: controller.selectAllRows,\n clear: controller.clearSelection,\n };\n}\n","import {\n useMemo,\n useState,\n type MouseEvent as ReactMouseEvent,\n type RefObject,\n} from \"react\";\nimport {\n bodyFocus,\n type AggregateState,\n type DisplayRow,\n type FormatLocale,\n type GridMessages,\n type GridOptions,\n type GroupAggregateDisplay,\n type ResolvedRow,\n type RowPointerEvent,\n} from \"@gridkitjs/core\";\nimport { intentOf } from \"@gridkitjs/core/renderer\";\nimport {\n bodyCellFrom,\n bodyRowFrom,\n groupRowFrom,\n type BodyCellTarget,\n} from \"@gridkitjs/dom\";\nimport type {\n ColumnDefinition,\n InfiniteScrollConfig,\n ResolvedColumn,\n} from \"../DataGrid\";\nimport {\n focusedColumnInRow,\n type GridNavigationApi,\n} from \"../useGridNavigation\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { RowVirtualizerApi } from \"../useRowVirtualizer\";\nimport { isOwnEvent } from \"../isOwnEvent\";\nimport { createRowPropsResolver } from \"../rowProps\";\nimport {\n keyboardSelectIntent,\n type GridSelectionApi,\n} from \"../useGridSelection\";\nimport GridGroupRow from \"./GridGroupRow\";\nimport GridGroupSummaryRow from \"./GridGroupSummaryRow\";\nimport GridRow from \"./GridRow\";\n\ninterface GridBodyProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n /** Every column's definition by id, hidden ones included — a grid may group or aggregate by a column it does not show. */\n definitions: ReadonlyMap<string, ColumnDefinition<Row>>;\n rows: readonly DisplayRow<Row>[];\n /** The column being resized, so its cells outline with its header. */\n activeColumnId: string | null;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n /** What a group header's click or key press expands or collapses. */\n controller: DataGridController<Row>;\n /** Active aggregates. Empty when none are active. */\n aggregates: AggregateState<Row>;\n /** Where a group's aggregates render — inline in its header, or as its own summary row. */\n groupAggregateDisplay: GroupAggregateDisplay;\n /** Windows `rows` down to the rows near the current scroll position. `null` when `virtualized` is off, in which case every row of `rows` renders exactly as it always has. */\n virtualRange: RowVirtualizerApi | null;\n /** Renders a sentinel row (and, while loading, a loading row) as the last child of `<tbody>` when set. `undefined` renders neither. */\n infiniteScroll: InfiniteScrollConfig | undefined;\n /** Ref the sentinel row attaches to — owned and observed by `DataGrid.tsx`'s `useInfiniteScroll`, not by this component. */\n sentinelRef: RefObject<HTMLTableRowElement | null>;\n /** The grid's `locale`, which every cell and aggregate without a template is formatted for. */\n locale: FormatLocale;\n getRowProps: GridOptions<Row>[\"getRowProps\"];\n onRowClick: GridOptions<Row>[\"onRowClick\"];\n onRowDoubleClick: GridOptions<Row>[\"onRowDoubleClick\"];\n messages: GridMessages;\n /** Whether a data cell, or a group row, opens the grid's context menu — for their `aria-keyshortcuts`. */\n cellMenu: boolean;\n groupMenu: boolean;\n}\n\n/**\n * Events are delegated to the body rather than bound per cell, which is what\n * lets `GridRow` be memoised: a handler rebuilt each render is a prop that\n * changes each render, and one reaching every row would defeat the boundary\n * entirely.\n */\nexport default function GridBody<Row>({\n columns,\n definitions,\n rows,\n activeColumnId,\n nav,\n selection,\n controller,\n aggregates,\n groupAggregateDisplay,\n virtualRange,\n infiniteScroll,\n sentinelRef,\n locale,\n getRowProps,\n onRowClick,\n onRowDoubleClick,\n messages,\n cellMenu,\n groupMenu,\n}: GridBodyProps<Row>) {\n const { selectedCell, rowMode, cellMode, toggleOnClick } = selection;\n // The full `rows` array otherwise — `virtualRange` is `null` whenever\n // `virtualized` is off, so this slice, and the spacer rows below, are a\n // no-op that reproduces today's output exactly.\n const visibleRows =\n virtualRange === null\n ? rows\n : rows.slice(virtualRange.startIndex, virtualRange.endIndex + 1);\n const { booleanTrue, booleanFalse, blankGroupValue } = messages;\n // Keyed on the strings rather than `messages`, so the memoised rows hold\n // still under a `messages` object rebuilt on every render.\n const cellMessages = useMemo(\n () => ({ booleanTrue, booleanFalse, blankGroupValue }),\n [booleanTrue, booleanFalse, blankGroupValue],\n );\n const [resolveRowProps] = useState(() => createRowPropsResolver<Row>());\n const rowPropsOf = resolveRowProps(\n visibleRows.filter(\n (entry): entry is ResolvedRow<Row> => entry.kind === \"data\",\n ),\n getRowProps,\n );\n\n /** The row and cell an event addresses, resolved once for every handler. */\n function targetOf(\n target: EventTarget,\n ): { position: BodyCellTarget; rowId: string } | null {\n const position = bodyCellFrom(target);\n const entry = position === null ? undefined : rows[position.rowIndex];\n if (position === null || entry?.kind !== \"data\") {\n return null;\n }\n return { position, rowId: entry.rowId };\n }\n\n function select(\n rowId: string,\n columnId: string,\n modifiers: { ctrlKey: boolean; metaKey: boolean; shiftKey: boolean },\n ): void {\n // Independent of each other: selecting a cell says nothing about its row,\n // so a grid with both on reports both. `toggleOnClick` is the rows' own.\n if (rowMode !== false) {\n selection.selectRow(rowId, intentOf(modifiers, { toggleOnClick }));\n }\n if (cellMode !== false) {\n selection.selectCell({ rowId, columnId }, intentOf(modifiers));\n }\n }\n\n /**\n * What `onRowClick`/`onRowDoubleClick` are told of a pointer event on a\n * data row — `null` off one, a group header included. Unlike `targetOf`\n * it needs no cell: the row alone is enough to report.\n */\n function rowPointerEventOf(\n event: ReactMouseEvent,\n ): RowPointerEvent<Row> | null {\n const target = bodyRowFrom(event.target);\n const entry = target === null ? undefined : rows[target.rowIndex];\n if (target === null || entry?.kind !== \"data\") {\n return null;\n }\n return {\n row: entry,\n columnId: target.columnId,\n native: {\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n altKey: event.altKey,\n button: event.button,\n },\n };\n }\n\n function reportRowPointer(\n event: ReactMouseEvent,\n callback: ((event: RowPointerEvent<Row>) => void) | undefined,\n ): void {\n if (callback === undefined) return;\n const pointer = rowPointerEventOf(event);\n if (pointer !== null) {\n callback(pointer);\n }\n }\n\n return (\n <tbody\n // The rowgroup is the scrolling element around the body's table.\n role=\"presentation\"\n className=\"gridkit-grid-body\"\n onFocus={(event) => {\n const group = groupRowFrom(event.target);\n if (group !== null) {\n // One cell for the whole row — see the note on `focused` below.\n nav.focusCell(bodyFocus(group.rowIndex, 0));\n return;\n }\n const found = targetOf(event.target);\n if (found === null) return;\n nav.focusCell(\n bodyFocus(found.position.rowIndex, found.position.columnIndex),\n );\n }}\n onClick={(event) => {\n const group = groupRowFrom(event.target);\n if (group !== null) {\n controller.toggleGroupExpansion(group.groupId);\n return;\n }\n const found = targetOf(event.target);\n if (found !== null) {\n select(found.rowId, found.position.columnId, event);\n }\n // After selecting, so a handler reading the selection sees this\n // click's.\n reportRowPointer(event, onRowClick);\n }}\n onDoubleClick={(event) => {\n reportRowPointer(event, onRowDoubleClick);\n }}\n onKeyDown={(event) => {\n if (!isOwnEvent(event)) return;\n const group = groupRowFrom(event.target);\n if (group !== null) {\n // One cell spans every column, so there is nothing to move within —\n // left/right stay a no-op rather than silently moving `nav`'s\n // stored column index off of a cell this row doesn't have.\n if (event.key === \"ArrowLeft\" || event.key === \"ArrowRight\") {\n event.preventDefault();\n return;\n }\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n controller.toggleGroupExpansion(group.groupId);\n return;\n }\n nav.onKeyDown(event);\n return;\n }\n\n // Space builds a selection up and Enter replaces it, matching the\n // Ctrl-click and the plain click they stand in for.\n if (event.key === \" \" || event.key === \"Enter\") {\n const found = targetOf(event.target);\n if (found === null) return;\n // Taken whether or not anything is selectable: Space would otherwise\n // scroll the grid out from under the focused cell.\n event.preventDefault();\n select(\n found.rowId,\n found.position.columnId,\n keyboardSelectIntent(event),\n );\n return;\n }\n nav.onKeyDown(event);\n }}\n >\n {virtualRange !== null && virtualRange.offsetBefore > 0 && (\n // `aria-hidden` and carrying neither `data-gridkit-column` nor\n // `data-gridkit-group`/`data-gridkit-row-index`, so `bodyCellFrom`/\n // `groupRowFrom` never mistake it for a real row — it exists purely\n // to give the browser's scrollbar the correct total height and thumb\n // position, the same way `GridFooter`'s `<tfoot>` isn't a \"row\" to\n // any of this grid's own row-counting logic.\n <tr aria-hidden=\"true\">\n <td\n style={{\n height: virtualRange.offsetBefore,\n padding: 0,\n border: \"none\",\n }}\n />\n </tr>\n )}\n {visibleRows.map((entry) => {\n switch (entry.kind) {\n case \"data\": {\n const rowProps = rowPropsOf(entry.rowId);\n return (\n <GridRow<Row>\n key={entry.rowId}\n ref={virtualRange?.measureRow(entry.rowIndex)}\n columns={columns}\n rowId={entry.rowId}\n row={entry.row}\n rowIndex={entry.rowIndex}\n datasetIndex={entry.datasetIndex}\n groupLevel={entry.groupPosition?.level}\n groupPosition={entry.groupPosition?.position}\n groupSetSize={entry.groupPosition?.setSize}\n activeColumnId={activeColumnId}\n selectedColumnIds={selection.selectedColumnIds}\n selected={selection.selectedRowIds.has(entry.rowId)}\n /*\n * Narrowed to this row before it crosses the boundary, so\n * that moving the selected cell re-renders the two rows it\n * moved between rather than all of them.\n */\n selectedColumnId={\n selectedCell.kind === \"cell\" &&\n selectedCell.rowId === entry.rowId\n ? selectedCell.columnId\n : null\n }\n focusedColumnIndex={focusedColumnInRow(\n nav.focus,\n entry.rowIndex,\n )}\n rowsSelectable={rowMode !== false}\n cellsSelectable={cellMode !== false}\n contextMenu={cellMenu}\n locale={locale}\n cellMessages={cellMessages}\n rowClassName={rowProps.className}\n rowAttributes={rowProps.attributes}\n />\n );\n }\n\n case \"group-summary\":\n return (\n <GridGroupSummaryRow<Row>\n key={`${entry.groupId}-summary`}\n ref={virtualRange?.measureRow(entry.rowIndex)}\n groupId={entry.groupId}\n level={entry.level}\n rowIndex={entry.rowIndex}\n datasetIndex={entry.datasetIndex}\n results={entry.aggregates}\n aggregates={aggregates}\n columns={columns}\n locale={locale}\n />\n );\n\n case \"group\":\n return (\n <GridGroupRow\n key={entry.groupId}\n ref={virtualRange?.measureRow(entry.rowIndex)}\n columnCount={columns.length}\n groupId={entry.groupId}\n level={entry.level}\n // A grouping by a column the grid does not have reads its value\n // by its kind alone.\n groupColumn={\n definitions.get(entry.columnId) ?? { field: entry.columnId }\n }\n value={entry.value}\n expanded={entry.expanded}\n count={entry.count}\n rowIndex={entry.rowIndex}\n datasetIndex={entry.datasetIndex}\n posinset={entry.position}\n setsize={entry.setSize}\n // Inline rendering only under \"inline\" display — under \"row\",\n // the group's own summary row (above) already shows these, and\n // showing them twice would be redundant.\n aggregates={\n groupAggregateDisplay === \"inline\" ? aggregates : []\n }\n results={entry.aggregates}\n definitions={definitions}\n locale={locale}\n cellMessages={cellMessages}\n // Ignores `nav.focus.columnIndex`: with only one cell in this\n // row, whether it holds the tab stop depends on `rowIndex`\n // alone.\n focused={focusedColumnInRow(nav.focus, entry.rowIndex) !== null}\n contextMenu={groupMenu}\n />\n );\n\n default:\n return entry satisfies never;\n }\n })}\n {virtualRange !== null && virtualRange.offsetAfter > 0 && (\n <tr aria-hidden=\"true\">\n <td\n style={{\n height: virtualRange.offsetAfter,\n padding: 0,\n border: \"none\",\n }}\n />\n </tr>\n )}\n {/*\n * Presentational, like the spacer rows above: neither carries\n * `data-gridkit-row-index`/`data-gridkit-column`, so `bodyCellFrom`/\n * `groupRowFrom` never match them, and neither is part of `rows` (the\n * array `aria-rowcount` and `useGridNavigation`'s `rowCount` are\n * computed from in `DataGrid.tsx`), so both are already excluded from\n * row counting and keyboard navigation without any extra check here.\n */}\n {infiniteScroll?.hasMore && (\n <>\n {infiniteScroll.isLoadingMore === true && (\n <tr aria-hidden=\"true\" className=\"gridkit-grid-loading-row\">\n <td\n colSpan={columns.length}\n className=\"gridkit-grid-loading-cell\"\n >\n {infiniteScroll.loadingTemplate\n ? infiniteScroll.loadingTemplate()\n : messages.loadingMore}\n </td>\n </tr>\n )}\n <tr\n aria-hidden=\"true\"\n ref={sentinelRef}\n className=\"gridkit-grid-sentinel-row\"\n >\n <td\n colSpan={columns.length}\n style={{ padding: 0, border: \"none\" }}\n />\n </tr>\n </>\n )}\n </tbody>\n );\n}\n","import {\n useEffect,\n useLayoutEffect,\n useState,\n useSyncExternalStore,\n type KeyboardEvent as ReactKeyboardEvent,\n type RefObject,\n} from \"react\";\nimport type { GridFocus } from \"@gridkitjs/core\";\nimport {\n createGridFocus,\n findBodyRow,\n measurePageSize,\n writingDirection,\n type FocusVirtualRange,\n type GridFocusOptions,\n type GridFocusRows,\n} from \"@gridkitjs/dom\";\n\ninterface UseGridNavigationOptions {\n /**\n * The `role=\"grid\"` element holding every row: focus leaving it, or a\n * wheel or press inside it, drops a move still waiting for its row.\n */\n gridRef: RefObject<HTMLElement | null>;\n headerTableRef: RefObject<HTMLTableElement | null>;\n bodyTableRef: RefObject<HTMLTableElement | null>;\n rowCount: number;\n columnCount: number;\n /**\n * Rows the vertical navigation keys step over rather than land a tab stop\n * on — a group's own summary row (`groupAggregateDisplay: \"row\"`), which\n * still occupies a real row slot for `rowCount` purposes but is\n * presentational, not a stop of its own. Left unset (skips nothing) for a\n * grid with no such rows.\n */\n isSkippableRow?: ((rowIndex: number) => boolean) | undefined;\n /**\n * The window `useRowVirtualizer` drew, present only when `virtualized` is\n * on, in which case behavior is otherwise unchanged. A focus move can\n * target a row index that isn't currently mounted — `ArrowDown` repeated\n * past the mounted window's end, or `End`/`Ctrl+End` jumping straight to\n * the last row.\n */\n virtualRange?: FocusVirtualRange | null | undefined;\n}\n\nexport interface GridNavigationApi {\n focus: GridFocus;\n /**\n * `0` for the focused cell and `-1` for every other. A grid is one tab stop:\n * tabbing reaches it, and the arrow keys move within it.\n */\n tabIndexFor: (cell: GridFocus) => 0 | -1;\n /** Moves the tab stop, and the browser's focus with it. */\n focusCell: (focus: GridFocus) => void;\n /**\n * `focusCell` for a cell on screen, whose browser focus moves now rather\n * than once the move is drawn — for something about to take focus from\n * it, such as a menu opened on it, which the drawing would pull focus back\n * out of. It renders nothing synchronously, so it is safe in an effect.\n */\n focusCellNow: (focus: GridFocus) => void;\n /**\n * The cell holding the tab stop, as drawn now, or `null` while its row is\n * not drawn — where focus goes when the element it was to go back to has\n * gone, as a header does when a menu opened on it hides its column.\n */\n tabStopCell: () => HTMLElement | null;\n /** Handles the navigation keys, leaving every other key to bubble. */\n onKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => void;\n}\n\n/**\n * `0` for the column holding the tab stop and `-1` for every other.\n * Standalone rather than reached only through the hook's own `tabIndexFor`,\n * because `GridRow` is `memo()`-wrapped and cannot take the whole `nav`\n * object as a prop without defeating that boundary. Takes the row's own\n * already-narrowed `focusedColumnIndex` (`null` when focus sits on a\n * different row) rather than a `GridFocus`, since that narrowing —\n * `focusedColumnInRow`, done once per row in `GridBody` — is what keeps a\n * focus move from re-rendering every row instead of the two it actually\n * touches.\n */\nexport function tabIndexFor(\n columnIndex: number,\n focusedColumnIndex: number | null,\n): 0 | -1 {\n return columnIndex === focusedColumnIndex ? 0 : -1;\n}\n\n/**\n * The column holding the tab stop when it sits in body row `rowIndex`, or\n * `null` when it sits in another row or in the header.\n */\nexport function focusedColumnInRow(\n focus: GridFocus,\n rowIndex: number,\n): number | null {\n return focus.area === \"body\" && focus.rowIndex === rowIndex\n ? focus.columnIndex\n : null;\n}\n\nfunction sameCell(a: GridFocus, b: GridFocus): boolean {\n if (a.columnIndex !== b.columnIndex) {\n return false;\n }\n return a.area === \"header\"\n ? b.area === \"header\"\n : focusedColumnInRow(b, a.rowIndex) !== null;\n}\n\n/**\n * The grid's single tab stop, kept by `@gridkitjs/dom`'s `createGridFocus`\n * and drawn from it: created once, handed the current counts and window on\n * every render, and subscribed to, so a move re-renders the grid. The\n * header row comes from the header table's own `.tHead`; a body row through\n * `findBodyRow`, by its `data-gridkit-row-index`.\n */\nexport default function useGridNavigation({\n gridRef,\n headerTableRef,\n bodyTableRef,\n rowCount,\n columnCount,\n isSkippableRow,\n virtualRange,\n}: UseGridNavigationOptions): GridNavigationApi {\n const options: GridFocusOptions = {\n rowCount,\n columnCount,\n isSkippableRow,\n virtualRange,\n };\n const [gridFocus] = useState(() => createGridFocus(options));\n // During render, like `useGridController`'s `setOptions`: the focus this\n // render draws is clamped to this render's row and column counts.\n gridFocus.setOptions(options);\n // `getFocus` serves the server too: nothing can move focus before the grid\n // hydrates, so both sides draw the same initial tab stop.\n const focus = useSyncExternalStore(\n gridFocus.subscribe,\n gridFocus.getFocus,\n gridFocus.getFocus,\n );\n\n const [rows] = useState<GridFocusRows>(() => ({\n getHeaderRow: () => headerTableRef.current?.tHead?.rows[0] ?? null,\n getBodyRow: (rowIndex) => findBodyRow(bodyTableRef.current, rowIndex),\n }));\n useLayoutEffect(\n () => gridFocus.attach(rows, gridRef.current),\n [gridFocus, rows, gridRef],\n );\n\n // After every commit rather than only when `focus` changes: under\n // virtualization the target row may mount only in a later drawing, once\n // the window has scrolled to it, and this is what retries.\n useEffect(() => {\n gridFocus.focusDrawnCell(focus);\n });\n\n // A new object each render, as the other hooks here return: `tabIndexFor`\n // closes over the focus it draws.\n return {\n focus,\n tabIndexFor: (cell) => (sameCell(cell, focus) ? 0 : -1),\n focusCell: gridFocus.focusCell,\n focusCellNow: (next) => {\n gridFocus.focusCell(next);\n // The cell is drawn already, all but its tab stop, so the move is\n // followed now, and the drawing that redraws the stop has none left.\n gridFocus.focusDrawnCell(gridFocus.getFocus());\n },\n tabStopCell: () => {\n // Read from the store rather than this render's `focus`: an overlay\n // asks while the drawing that moved the stop is being committed.\n const stop = gridFocus.getFocus();\n const cells = (\n stop.area === \"header\"\n ? rows.getHeaderRow()\n : rows.getBodyRow(stop.rowIndex)\n )?.cells;\n // A group header's row has one cell, whatever column the stop is in.\n return cells?.[Math.min(stop.columnIndex, cells.length - 1)] ?? null;\n },\n onKeyDown: (event) => {\n if (\n gridFocus.handleKey(\n event.key,\n event,\n measurePageSize(bodyTableRef.current, gridRef.current),\n writingDirection(event.currentTarget),\n )\n ) {\n event.preventDefault();\n }\n },\n };\n}\n","import type { ResolvedRow, RowProps } from \"@gridkitjs/core\";\n\nexport type RowAttributes = Readonly<Record<`data-${string}`, string>>;\n\n/** What `GridRow` is handed from `getRowProps`, both always present. */\nexport interface ResolvedRowProps {\n readonly className: string;\n readonly attributes: RowAttributes;\n}\n\n/** Shared by every row without attributes, so each compares equal to the last. */\nexport const NO_ATTRIBUTES: RowAttributes = {};\n\nconst NO_ROW_PROPS: ResolvedRowProps = {\n className: \"\",\n attributes: NO_ATTRIBUTES,\n};\n\nfunction sameAttributes(a: RowAttributes, b: RowAttributes): boolean {\n const keys = Object.keys(a) as (keyof RowAttributes)[];\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => a[key] === b[key])\n );\n}\n\n/**\n * Runs `getRowProps` over the rows about to render, keeping each row's\n * attributes the same object as last time while they read the same.\n *\n * `GridRow` is memoised, and `getRowProps` returns a fresh attributes object\n * on every call — often from an inline arrow that is itself new on every\n * render — so handing those objects straight through would redraw every row\n * on every render. The class is a string and compares by value already.\n *\n * Remembers only the rows of the latest call, so a virtualized grid scrolled\n * over many rows holds no more than the ones on screen.\n */\nexport function createRowPropsResolver<Row>(): (\n rows: readonly ResolvedRow<Row>[],\n getRowProps: ((row: ResolvedRow<Row>) => RowProps) | undefined,\n) => (rowId: string) => ResolvedRowProps {\n let previous = new Map<string, RowAttributes>();\n return (rows, getRowProps) => {\n if (getRowProps === undefined) {\n previous = new Map();\n return () => NO_ROW_PROPS;\n }\n const resolved = new Map<string, ResolvedRowProps>();\n const attributesById = new Map<string, RowAttributes>();\n for (const entry of rows) {\n const { className = \"\", attributes = NO_ATTRIBUTES } = getRowProps(entry);\n const last = previous.get(entry.rowId);\n const stable =\n last !== undefined && sameAttributes(last, attributes)\n ? last\n : attributes;\n attributesById.set(entry.rowId, stable);\n resolved.set(entry.rowId, { className, attributes: stable });\n }\n previous = attributesById;\n return (rowId) => resolved.get(rowId) ?? NO_ROW_PROPS;\n };\n}\n","import { memo, type Ref } from \"react\";\nimport {\n formatGroupValue,\n resolveColumnLabel,\n type AggregateResults,\n type AggregateState,\n type FormatLocale,\n type GridMessages,\n} from \"@gridkitjs/core\";\nimport type { ColumnDefinition } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport { renderAggregate } from \"./renderAggregate\";\n\ninterface GridGroupRowProps<Row> {\n /** How many columns this group's header spans, matching the grid's own count. */\n columnCount: number;\n groupId: string;\n /** Nesting depth, 0 for a top-level group — indents the header and feeds `aria-level`. */\n level: number;\n /** The column grouped by, whose label names the group and whose formatting its value reads in. */\n groupColumn: ColumnDefinition<Row>;\n /** This group's own value — the last entry of its `path`. */\n value: unknown;\n expanded: boolean;\n /** Leaf row count under this group, regardless of collapse state. */\n count: number;\n /** This row's position in the full (unsliced) display-rows array — see `ResolvedGroupRow.rowIndex`. */\n rowIndex: number;\n /** This header's absolute position in the whole dataset, unaffected by which page is showing — see `ResolvedGroupRow.datasetIndex`. */\n datasetIndex: number;\n /** This group's 1-based position among its own siblings, for `aria-posinset`. */\n posinset: number;\n /** How many siblings this group has, for `aria-setsize`. */\n setsize: number;\n /** Whether this row currently holds the grid's single tab stop. */\n focused: boolean;\n /** Whether this row opens the grid's context menu, which its `aria-keyshortcuts` says. */\n contextMenu: boolean;\n /** Active aggregates — empty when none are active, in which case no subtotal renders. */\n aggregates: AggregateState<Row>;\n /** This group's own computed results, keyed the same way `aggregates` resolves each spec's key. */\n results: AggregateResults;\n /** Every column's definition by id, hidden ones included — whose label and formatting each aggregate takes. */\n definitions: ReadonlyMap<string, ColumnDefinition<Row>>;\n /** The grid's `locale`, which values are formatted for. */\n locale: FormatLocale;\n /** The words for a boolean or missing group value, from `messages` — memoised by `GridBody`. */\n cellMessages: Pick<\n GridMessages,\n \"booleanTrue\" | \"booleanFalse\" | \"blankGroupValue\"\n >;\n ref?: Ref<HTMLTableRowElement> | undefined;\n}\n\nfunction GridGroupRowComponent<Row>({\n columnCount,\n groupId,\n level,\n groupColumn,\n value,\n expanded,\n count,\n rowIndex,\n datasetIndex,\n posinset,\n setsize,\n focused,\n contextMenu,\n aggregates,\n results,\n definitions,\n locale,\n cellMessages,\n ref,\n}: GridGroupRowProps<Row>) {\n return (\n <tr\n ref={ref}\n role=\"row\"\n // Two past the index: rows are counted from one, and the header is the\n // first of them — the same convention `GridRow` uses. Built from\n // `datasetIndex`, not the page-relative `rowIndex`, matching `GridRow`.\n aria-rowindex={datasetIndex + 2}\n // 1-based, per the WAI-ARIA treegrid pattern.\n aria-level={level + 1}\n aria-expanded={expanded}\n aria-setsize={setsize}\n aria-posinset={posinset}\n data-gridkit-group={groupId}\n // See `GridRow`'s own `data-gridkit-row-index` for why this reads off\n // the array position rather than the DOM's `sectionRowIndex`.\n data-gridkit-row-index={rowIndex}\n className={classNames(\n \"gridkit-grid-group-row\",\n `is-group-level-${String(level)}`,\n )}\n >\n <td\n role=\"gridcell\"\n colSpan={columnCount}\n tabIndex={focused ? 0 : -1}\n aria-keyshortcuts={\n contextMenu ? \"Space Enter Shift+F10\" : \"Space Enter\"\n }\n className=\"gridkit-grid-group-cell\"\n >\n {/*\n * The flex layout lives on this inner `div`, not the `<td>` itself:\n * a `display` other than `table-cell` on the cell element changes\n * its box type entirely, and the browser fixes that up by wrapping\n * it in an anonymous table-cell — which throws off the cell's own\n * hit-testing (a click landing where the row's bounding box says\n * the cell is can miss it and hit the table underneath instead).\n */}\n <div\n className=\"gridkit-grid-group-cell-content\"\n style={{ paddingInlineStart: `${String(level * 1.25 + 0.5)}rem` }}\n >\n <span\n className={classNames(\n \"gridkit-group-toggle\",\n expanded ? \"is-expanded\" : \"is-collapsed\",\n )}\n aria-hidden=\"true\"\n />\n <span className=\"gridkit-group-label\">\n {resolveColumnLabel(groupColumn)}:{\" \"}\n {formatGroupValue(value, groupColumn, locale, cellMessages)}\n </span>\n <span className=\"gridkit-group-count\">({count})</span>\n {aggregates.length > 0 && (\n <span className=\"gridkit-group-aggregates\">\n {aggregates.map((spec) => {\n const key = spec.id ?? spec.columnId;\n const aggregateValue = results.get(key);\n const column = definitions.get(spec.columnId);\n const rendered = renderAggregate(\n aggregateValue,\n spec,\n column,\n [],\n locale,\n );\n // An explicit `id` disambiguates two specs on the same\n // column (e.g. both `sum` and `avg` of Amount) — when given,\n // it's the caller's own label for this result, so it takes\n // priority over the column's shared label.\n const aggregateLabel =\n spec.id ??\n (column === undefined\n ? spec.columnId\n : resolveColumnLabel(column));\n return (\n <span key={key} className=\"gridkit-group-aggregate\">\n {aggregateLabel}: {rendered}\n </span>\n );\n })}\n </span>\n )}\n </div>\n </td>\n </tr>\n );\n}\n\n/**\n * `memo()`-wrapped for the same reason `GridRow` is: every prop here is a\n * scalar or an already-narrowed value, and no handler reaches this component\n * directly — `GridBody` delegates group-header clicks and keydowns the same\n * way it does for data rows.\n */\nconst GridGroupRow = memo(\n GridGroupRowComponent,\n) as typeof GridGroupRowComponent;\n\nexport default GridGroupRow;\n","import type { ReactNode } from \"react\";\nimport {\n formatAggregateValue,\n type AggregateSpec,\n type FormatLocale,\n} from \"@gridkitjs/core\";\nimport type { ColumnDefinition } from \"../DataGrid\";\n\n/**\n * One aggregate result as the grid shows it — in the grand-total footer, a\n * group's summary row, or inline in a group's header. The column's own\n * `footerTemplate` when it has one; otherwise the text\n * `formatAggregateValue` makes of it, with a dash standing in for an empty\n * result so a cell that has an aggregate never looks like one that has none.\n */\nexport function renderAggregate<Row>(\n value: unknown,\n spec: AggregateSpec<Row>,\n column: ColumnDefinition<Row> | undefined,\n rows: readonly Row[],\n locale: FormatLocale,\n): ReactNode {\n if (column?.footerTemplate) {\n return column.footerTemplate({ value, rows });\n }\n if (value === null || value === undefined) {\n return \"—\";\n }\n return formatAggregateValue(value, spec, column, locale);\n}\n","import { memo, type Ref } from \"react\";\nimport type {\n AggregateResults,\n AggregateState,\n FormatLocale,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport { textAlignFor } from \"../textAlign\";\nimport { renderAggregate } from \"./renderAggregate\";\n\ninterface GridGroupSummaryRowProps<Row> {\n groupId: string;\n /** Nesting depth, matching the group's own level — indents the row the same amount `GridGroupRow` does. */\n level: number;\n /** This row's position in the full (unsliced) display-rows array — see `ResolvedGroupSummaryRow.rowIndex`. */\n rowIndex: number;\n /** This row's absolute position in the whole dataset, unaffected by which page is showing — see `ResolvedGroupSummaryRow.datasetIndex`. */\n datasetIndex: number;\n /** The group's own computed results — identical to its header's `aggregates`. */\n results: AggregateResults;\n aggregates: AggregateState<Row>;\n columns: readonly ResolvedColumn<Row>[];\n /** The grid's `locale`, which values are formatted for. */\n locale: FormatLocale;\n ref?: Ref<HTMLTableRowElement> | undefined;\n}\n\n/**\n * A group's own aggregate results, one real `<td>` per column rather than\n * text inside the header's single spanning cell — the `groupAggregateDisplay:\n * \"row\"` alternative to `GridGroupRow`'s own inline rendering. Structurally\n * mirrors `GridFooter`'s grand-total row, scoped to one group's `results`\n * instead of the dataset-wide total, and indented the same amount its own\n * `GridGroupRow` is.\n *\n * Presentational: it occupies a real row slot (counted in `rowCount`/\n * `aria-rowindex`, since it is a genuine `<tr>` inside `<tbody>`) but is\n * never a keyboard tab stop — `DataGrid.tsx`'s `isSkippableRow` steps over\n * it during arrow-key navigation the same way this component itself takes\n * no `tabIndex`, `role=\"row\"`/`\"gridcell\"` only, no interactive attributes.\n *\n * Each cell's alignment follows the same rule `GridFooter`'s own cells do:\n * the first matching spec's `AggregateSpec.alignment` override, falling\n * back to the column's own `alignment` when neither is set.\n */\nfunction GridGroupSummaryRowComponent<Row>({\n groupId,\n level,\n rowIndex,\n datasetIndex,\n results,\n aggregates,\n columns,\n locale,\n ref,\n}: GridGroupSummaryRowProps<Row>) {\n return (\n <tr\n ref={ref}\n role=\"row\"\n aria-rowindex={datasetIndex + 2}\n data-gridkit-group-summary={groupId}\n // See `GridRow`'s own `data-gridkit-row-index` for why this reads off\n // the array position rather than the DOM's `sectionRowIndex`.\n data-gridkit-row-index={rowIndex}\n className={classNames(\n \"gridkit-grid-group-summary-row\",\n `is-group-level-${String(level)}`,\n )}\n >\n {columns.map((entry) => {\n const specs = aggregates.filter(\n (candidate) => candidate.columnId === entry.id,\n );\n\n return (\n <td\n key={entry.id}\n role=\"gridcell\"\n data-gridkit-column={entry.id}\n className={classNames(\n \"gridkit-grid-group-summary-cell\",\n pinnedCellClassNames(entry),\n )}\n style={{\n textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),\n ...pinnedCellStyle(entry),\n }}\n >\n {entry.id === columns[0]?.id && (\n <span\n className=\"gridkit-grid-group-summary-indent\"\n style={{ width: `${String(level * 1.25 + 0.5)}rem` }}\n aria-hidden=\"true\"\n />\n )}\n {specs\n .map((spec) =>\n renderAggregate(\n results.get(spec.id ?? spec.columnId),\n spec,\n entry.column,\n [],\n locale,\n ),\n )\n .flatMap((rendered, index) =>\n index === 0 ? [rendered] : [\", \", rendered],\n )}\n </td>\n );\n })}\n </tr>\n );\n}\n\n/**\n * `memo()`-wrapped for the same reason `GridGroupRow`/`GridRow` are: every\n * prop here is a scalar or an already-narrowed value.\n */\nconst GridGroupSummaryRow = memo(\n GridGroupSummaryRowComponent,\n) as typeof GridGroupSummaryRowComponent;\n\nexport default GridGroupSummaryRow;\n","import type { ColumnAlignment } from \"@gridkitjs/core\";\n\n/**\n * The `text-align` a column's `alignment` renders with. `\"left\"` and\n * `\"right\"` name the reading-start and reading-end sides, which `start` and\n * `end` follow: they render exactly as `left` and `right` in a left-to-right\n * page and mirror under `dir=\"rtl\"`.\n */\nexport function textAlignFor(\n alignment: ColumnAlignment,\n): \"start\" | \"center\" | \"end\" {\n switch (alignment) {\n case \"left\":\n return \"start\";\n case \"right\":\n return \"end\";\n case \"center\":\n return \"center\";\n }\n}\n","import {\n accessDotted,\n formatCellValue,\n type FormatLocale,\n type GridMessages,\n} from \"@gridkitjs/core\";\nimport { memo, type Ref } from \"react\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport type { RowAttributes } from \"../rowProps\";\nimport { textAlignFor } from \"../textAlign\";\nimport { tabIndexFor } from \"../useGridNavigation\";\n\ninterface GridRowProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n rowId: string;\n row: Row;\n rowIndex: number;\n /** This row's absolute position in the whole dataset, unaffected by which page is showing — see `CellTemplateContext.datasetIndex`. */\n datasetIndex: number;\n /**\n * The row's `groupPosition` fields, for `aria-level`, `aria-posinset` and\n * `aria-setsize`; `undefined` in an ungrouped grid. Scalars rather than the\n * object, which regrouping rebuilds for every row and would defeat `memo`.\n */\n groupLevel: number | undefined;\n groupPosition: number | undefined;\n groupSetSize: number | undefined;\n /** The column being resized, so its cells outline with its header. */\n activeColumnId: string | null;\n selectedColumnIds: ReadonlySet<string>;\n selected: boolean;\n /** Which of this row's cells is the selected one, if any. */\n selectedColumnId: string | null;\n /** Which of this row's cells holds the grid's tab stop, if any. */\n focusedColumnIndex: number | null;\n rowsSelectable: boolean;\n cellsSelectable: boolean;\n /** Whether a cell opens the grid's context menu, which its `aria-keyshortcuts` says. */\n contextMenu: boolean;\n /** The grid's `locale`, which a cell without a template is formatted for. */\n locale: FormatLocale;\n /** A boolean cell's words, from `messages` — memoised on the two strings by `GridBody`. */\n cellMessages: Pick<GridMessages, \"booleanTrue\" | \"booleanFalse\">;\n /** The class `getRowProps` gave this row, `\"\"` for none. */\n rowClassName: string;\n /** The `data-*` attributes `getRowProps` gave this row — the same object while they read the same, so they do not defeat `memo`. */\n rowAttributes: RowAttributes;\n ref?: Ref<HTMLTableRowElement> | undefined;\n}\n\nfunction GridRowComponent<Row>({\n columns,\n rowId,\n row,\n rowIndex,\n datasetIndex,\n groupLevel,\n groupPosition,\n groupSetSize,\n activeColumnId,\n selectedColumnIds,\n selected,\n selectedColumnId,\n focusedColumnIndex,\n rowsSelectable,\n cellsSelectable,\n contextMenu,\n locale,\n cellMessages,\n rowClassName,\n rowAttributes,\n ref,\n}: GridRowProps<Row>) {\n // The ContextMenu key needs no mention: it says what it does on its face.\n const shortcuts = [\n cellsSelectable ? \"Space Enter\" : \"\",\n contextMenu ? \"Shift+F10\" : \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n return (\n <tr\n // First, so the grid's own attributes below win over one of the same\n // name: `GridBody` finds rows by them.\n {...rowAttributes}\n ref={ref}\n role=\"row\"\n // Two past the index: rows are counted from one, and the header is the\n // first of them. Built from `datasetIndex` rather than the\n // page-relative `rowIndex`, so a paginated grid still reports each\n // row's true position in the whole dataset — the two only diverge once\n // pagination is on.\n aria-rowindex={datasetIndex + 2}\n // This row's position in the full (unsliced) rows array — read by\n // `GridBody`'s event delegation (`bodyCellFrom`) instead of the DOM's own\n // `sectionRowIndex`, which under virtualization no longer matches a\n // row's array position once a leading spacer `<tr>` shifts it.\n data-gridkit-row-index={rowIndex}\n // The row's identity, for a test or a script to find it by however it\n // has moved — the index above changes with every sort.\n data-gridkit-row-id={rowId}\n // One-based, where `groupLevel` counts from zero as a group row's does.\n aria-level={groupLevel === undefined ? undefined : groupLevel + 1}\n aria-posinset={groupPosition}\n aria-setsize={groupSetSize}\n // Omitted rather than `false` when rows cannot be selected, which would\n // otherwise have every row announce that it is not.\n {...ariaAttr(rowsSelectable, \"aria-selected\", selected)}\n className={classNames(\n \"gridkit-grid-row\",\n selected ? \"is-selected\" : \"\",\n rowClassName,\n )}\n >\n {columns.map((entry, columnIndex) => {\n const { id, column, alignment } = entry;\n // Resolved either way, so a template never has to walk the field path\n // a second time.\n const value = accessDotted(row, column.field);\n const cellSelected = id === selectedColumnId;\n\n return (\n <td\n key={id}\n role=\"gridcell\"\n data-gridkit-column={id}\n aria-colindex={columnIndex + 1}\n tabIndex={tabIndexFor(columnIndex, focusedColumnIndex)}\n {...ariaAttr(cellsSelectable, \"aria-selected\", cellSelected)}\n {...ariaAttr(shortcuts !== \"\", \"aria-keyshortcuts\", shortcuts)}\n className={classNames(\n \"gridkit-grid-cell\",\n id === activeColumnId ? \"is-resizing\" : \"\",\n cellSelected || selectedColumnIds.has(id) ? \"is-selected\" : \"\",\n column.wrap?.cells ? \"is-wrapped\" : \"\",\n pinnedCellClassNames(entry),\n column.cellClassName ?? \"\",\n )}\n style={{\n textAlign: textAlignFor(alignment),\n ...pinnedCellStyle(entry),\n }}\n >\n {column.cellTemplate\n ? column.cellTemplate({\n value,\n row,\n rowIndex,\n datasetIndex,\n rowId,\n selected,\n })\n : formatCellValue(value, column, locale, row, cellMessages)}\n </td>\n );\n })}\n </tr>\n );\n}\n\n/**\n * Selection lives at the top of the grid, so any change to it re-renders the\n * whole body — without this boundary a click would rebuild every cell of every\n * row rather than the one or two rows that changed.\n *\n * Every prop above is a scalar or already memoised for that reason, and no\n * handler reaches here at all: the body delegates its events, so a row has\n * nothing to compare that changes each render.\n *\n * `memo` erases the type parameter, and the cast puts it back — the standard\n * price of memoising a generic component.\n */\nconst GridRow = memo(GridRowComponent) as typeof GridRowComponent;\n\nexport default GridRow;\n","import type {\n AggregateResults,\n AggregateState,\n FormatLocale,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport { textAlignFor } from \"../textAlign\";\nimport { renderAggregate } from \"./renderAggregate\";\n\ninterface GridFooterProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n aggregates: AggregateState<Row>;\n results: AggregateResults;\n /** Every row the grand total was computed over — what a `footerTemplate` receives as `rows`. */\n rows: readonly Row[];\n /** The grid's `locale`, which values are formatted for. */\n locale: FormatLocale;\n /** This row's `aria-rowindex`: the last of the grid's `aria-rowcount`. */\n ariaRowIndex: number;\n}\n\n/**\n * The grand-total footer — one `<tfoot>` row, one cell per column, using\n * that column's own `footerTemplate` when it defines one, its own computed\n * value formatted like the column's values when it doesn't, and a blank cell for a column\n * with no aggregate at all. Structurally mirrors `GridHeader`, minus\n * everything interactive: a footer cell is not resizable, sortable, or\n * selectable.\n *\n * A column named by more than one spec (e.g. both `sum` and `avg` of the\n * same column, disambiguated by `id`) renders every matching spec's result\n * in its one cell, comma-separated — the cell grid stays one-per-column,\n * but no result is dropped the way picking only the first match would. The\n * cell's own alignment follows the first matching spec's `AggregateSpec.\n * alignment` override, falling back to the column's own `alignment` when\n * neither is set — one `<td>` can only take one `text-align`, so a second\n * spec's own override (if it disagrees) applies only to its value, not the\n * cell.\n *\n * A row of the grid like the header, so it is counted in `aria-rowcount`\n * and takes the index after the last body row, on any page. It is not a\n * stop for keyboard navigation, which moves among body rows only.\n */\nexport default function GridFooter<Row>({\n columns,\n aggregates,\n results,\n rows,\n locale,\n ariaRowIndex,\n}: GridFooterProps<Row>) {\n return (\n <tfoot role=\"rowgroup\">\n <tr\n className=\"gridkit-grid-footer\"\n role=\"row\"\n aria-rowindex={ariaRowIndex}\n >\n {columns.map((entry) => {\n const specs = aggregates.filter(\n (candidate) => candidate.columnId === entry.id,\n );\n\n return (\n <td\n key={entry.id}\n role=\"gridcell\"\n data-gridkit-column={entry.id}\n className={classNames(\n \"gridkit-grid-footer-cell\",\n pinnedCellClassNames(entry),\n )}\n style={{\n textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),\n ...pinnedCellStyle(entry),\n }}\n >\n {specs\n .map((spec) =>\n renderAggregate(\n results.get(spec.id ?? spec.columnId),\n spec,\n entry.column,\n rows,\n locale,\n ),\n )\n // Two values in one cell need a visible separator; a single\n // one (the common case) renders exactly as before.\n .flatMap((rendered, index) =>\n index === 0 ? [rendered] : [\", \", rendered],\n )}\n </td>\n );\n })}\n </tr>\n </tfoot>\n );\n}\n","import type { CSSProperties, ReactNode } from \"react\";\nimport type { GridMessages } from \"@gridkitjs/core\";\nimport { paginationWindow } from \"@gridkitjs/core/renderer\";\nimport type { PagerConfig, PagerTemplateContext } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport {\n ChevronLeftIcon,\n ChevronRightIcon,\n ChevronsLeftIcon,\n ChevronsRightIcon,\n} from \"../icons\";\n\ninterface GridPagerProps {\n /** The same context a `pager.template` is handed. */\n pager: PagerTemplateContext;\n /** Presentation options for the pager. `undefined` renders the `\"compact\"` default with no page-size control. */\n config: PagerConfig | undefined;\n messages: GridMessages;\n}\n\ninterface PagerNavButtonProps {\n /** The modifier class beside `gridkit-grid-pager-button gridkit-grid-pager-nav`. */\n className: string;\n label: string;\n disabled: boolean;\n onClick: () => void;\n children: ReactNode;\n}\n\n/**\n * One of the bar's four arrow segments: an icon, named by its message.\n *\n * Disabled with `aria-disabled` rather than the `disabled` attribute, the\n * way the toolbar's buttons are: the button that reaches an end is the one\n * that has focus, and a natively disabled button drops it to `<body>`. This\n * one keeps it, announced as unavailable, and pressing it again does nothing\n * rather than paging back the other way, as moving focus onto the opposite\n * arrow would.\n */\nfunction PagerNavButton({\n className,\n label,\n disabled,\n onClick,\n children,\n}: PagerNavButtonProps) {\n return (\n <button\n type=\"button\"\n className={`gridkit-grid-pager-button gridkit-grid-pager-nav ${className}`}\n aria-label={label}\n title={label}\n {...ariaAttr(disabled, \"aria-disabled\", true)}\n onClick={() => {\n if (!disabled) onClick();\n }}\n >\n {children}\n </button>\n );\n}\n\n/**\n * The built-in pager: one connected bar of first/previous, the page\n * numbers (or, under the default `\"compact\"` variant, a \"Page X of Y\"\n * status), and next/last, followed — when `config.sizeOptions` is given —\n * by a page-size `<select>`. Rendered as a sibling below the table, not a\n * row inside it, the same reasoning `GroupByBar` gives for its own\n * placement: a control surface, not grid content.\n *\n * The bar holds still as the user pages through it: `paginationWindow`\n * yields a constant number of slots, and `--gridkit-pager-digits` (the page\n * count's digit count) lets the theme give every number slot the same\n * width; the compact status reserves the width of its widest text.\n *\n * Whether this mounts at all is `DataGrid.tsx`'s call (`paginated`), not\n * this component's own.\n */\nexport default function GridPager({ pager, config, messages }: GridPagerProps) {\n const { pagination, pageCount, currentPage } = pager;\n const variant = config?.variant ?? \"compact\";\n const sizeOptions = config?.sizeOptions;\n const atFirst = pagination.pageIndex <= 0;\n const atLast = pagination.pageIndex >= pageCount - 1;\n const barStyle = {\n \"--gridkit-pager-digits\": String(String(Math.max(1, pageCount)).length),\n } as CSSProperties;\n\n return (\n <div\n className=\"gridkit-grid-pager\"\n role=\"group\"\n aria-label={messages.pagerLabel}\n >\n <div className=\"gridkit-grid-pager-bar\" style={barStyle}>\n <PagerNavButton\n className=\"gridkit-grid-pager-first\"\n label={messages.firstPage}\n disabled={atFirst}\n onClick={() => {\n pager.goToPage(0);\n }}\n >\n <ChevronsLeftIcon />\n </PagerNavButton>\n <PagerNavButton\n className=\"gridkit-grid-pager-previous\"\n label={messages.previousPage}\n disabled={atFirst}\n onClick={() => {\n pager.previousPage();\n }}\n >\n <ChevronLeftIcon />\n </PagerNavButton>\n {variant === \"numbered\" ? (\n paginationWindow(currentPage, pageCount, {\n boundaryCount: config?.boundaryCount,\n siblingCount: config?.siblingCount,\n }).map((entry, index) =>\n entry === \"ellipsis\" ? (\n <span\n key={`ellipsis-${String(index)}`}\n className=\"gridkit-grid-pager-ellipsis\"\n aria-hidden=\"true\"\n >\n …\n </span>\n ) : (\n <button\n key={entry}\n type=\"button\"\n className=\"gridkit-grid-pager-button gridkit-grid-pager-page\"\n aria-label={messages.pageButtonLabel(entry)}\n aria-current={entry === currentPage ? \"page\" : undefined}\n onClick={() => {\n pager.goToPage(entry - 1);\n }}\n >\n {entry}\n </button>\n ),\n )\n ) : (\n <span className=\"gridkit-grid-pager-status-slot\">\n <span className=\"gridkit-grid-pager-status\">\n {messages.pageStatus(\n pageCount === 0 ? 0 : currentPage,\n pageCount,\n )}\n </span>\n {/* The widest the status gets, invisible, so the slot never resizes as the page changes. */}\n <span\n className=\"gridkit-grid-pager-status-sizer\"\n aria-hidden=\"true\"\n >\n {messages.pageStatus(pageCount, pageCount)}\n </span>\n </span>\n )}\n <PagerNavButton\n className=\"gridkit-grid-pager-next\"\n label={messages.nextPage}\n disabled={atLast}\n onClick={() => {\n pager.nextPage();\n }}\n >\n <ChevronRightIcon />\n </PagerNavButton>\n <PagerNavButton\n className=\"gridkit-grid-pager-last\"\n label={messages.lastPage}\n disabled={atLast}\n onClick={() => {\n pager.goToPage(pageCount - 1);\n }}\n >\n <ChevronsRightIcon />\n </PagerNavButton>\n </div>\n {sizeOptions !== undefined && sizeOptions.length > 0 && (\n <label className=\"gridkit-grid-pager-page-size\">\n <select\n value={pagination.pageSize}\n onChange={(event) => {\n pager.setPageSize(Number(event.target.value));\n }}\n >\n {sizeOptions.map((size) => (\n <option key={size} value={size}>\n {size}\n </option>\n ))}\n </select>\n <span className=\"gridkit-grid-pager-page-size-label\">\n {messages.pageSizeLabel}\n </span>\n </label>\n )}\n </div>\n );\n}\n","import { createPortal } from \"react-dom\";\nimport {\n resolveColumnLabel,\n type GridMessages,\n type GroupByState,\n} from \"@gridkitjs/core\";\nimport {\n inlineStep,\n resolveKeyboardDropTarget,\n} from \"@gridkitjs/core/renderer\";\nimport { writingDirection, type GroupByDropTarget } from \"@gridkitjs/dom\";\nimport type { ColumnDefinition, ResolvedColumn } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport useGroupByDrag from \"../useGroupByDrag\";\nimport type { DataGridController } from \"../useGridController\";\n\ninterface GroupByBarProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n /** Every column's definition by id, hidden ones included, so a chip for a hidden column still carries its label. */\n definitions: ReadonlyMap<string, ColumnDefinition<Row>>;\n groupBy: GroupByState;\n /** What a chip's drag, move or remove button changes. */\n controller: DataGridController<Row>;\n /** A column's accessible name — see `DataGrid.tsx`'s own `columnName`. */\n columnName: (columnId: string) => string;\n /** Whether the header drag currently open (if any) could drop into this bar. */\n headerDragEligible: boolean;\n /**\n * Whether the header drag currently open (if any) is for a column already\n * in the group-by stack — a drag this bar rejects outright, since\n * repositioning a grouped column is the chip's job, not the header's.\n */\n headerDragBlocked: boolean;\n /** That header drag's own target within this bar, or `null`. */\n headerDropTarget: GroupByDropTarget | null;\n messages: GridMessages;\n}\n\n/**\n * The active group-by stack, outer to inner, as removable, reorderable\n * chips — and the drop target for a header dragged in from outside it.\n * Each column's own header already carries a group toggle (a pointer\n * affordance, plus `Alt+ArrowDown`) for adding or removing a level without\n * dragging at all; this bar shows the resulting stack, lets a level be\n * removed from it directly, lets a chip be dragged to reorder the stack (or\n * moved via `Ctrl+ArrowLeft`/`Ctrl+ArrowRight` on a focused one), and — for\n * a column whose header sets `groupByDraggable` and isn't grouped yet —\n * accepts a header dropped onto it, at whatever position among the existing\n * chips it's released. A header for a column already in the stack is\n * rejected outright (`is-drag-blocked`, `cursor: not-allowed`): the header\n * only ever adds, and repositioning an existing level is the chip's job.\n *\n * Whether this component mounts at all is `DataGrid.tsx`'s call\n * (`groupByBarVisibility`), not this component's own — it never bails out\n * on its own initiative once rendered.\n *\n * Chips sit outside the grid's own single-roving-tabstop model: there is no\n * shared index to keep in sync the way a row or a header cell has, so each\n * chip (and its own remove button) is simply, always `tabIndex={0}` — plain\n * DOM tab order, no roving-focus bookkeeping.\n */\nexport default function GroupByBar<Row>({\n columns,\n definitions,\n groupBy,\n controller,\n columnName,\n headerDragEligible,\n headerDragBlocked,\n headerDropTarget,\n messages,\n}: GroupByBarProps<Row>) {\n const groupByIds = groupBy.map((entry) => entry.columnId);\n\n const chipDrag = useGroupByDrag({\n groupBy,\n onDrop: (movedId, beforeColumnId) => {\n controller.moveGroupBy(movedId, beforeColumnId);\n },\n });\n\n // Mutually exclusive by construction — one pointer, so at most one of \"a\n // chip dragged within this bar\" and \"a header dragged in from outside it\"\n // is ever active at once.\n const activeDropTarget = chipDrag.dropTarget ?? headerDropTarget;\n const isDragTarget = chipDrag.draggedColumnId !== null || headerDragEligible;\n const showPlaceholder =\n groupBy.length === 0 && columns.some((entry) => entry.groupByDraggable);\n\n function labelFor(columnId: string) {\n const definition = definitions.get(columnId);\n return definition === undefined ? columnId : resolveColumnLabel(definition);\n }\n\n function moveByKeyboard(columnId: string, direction: -1 | 1): void {\n const beforeColumnId = resolveKeyboardDropTarget(\n groupByIds,\n columnId,\n direction,\n );\n if (beforeColumnId === undefined) {\n return;\n }\n controller.moveGroupBy(columnId, beforeColumnId);\n }\n\n return (\n <div\n className={classNames(\n \"gridkit-group-by-bar\",\n isDragTarget ? \"is-drag-target\" : \"\",\n headerDragBlocked ? \"is-drag-blocked\" : \"\",\n )}\n data-gridkit-group-by-bar=\"\"\n role=\"group\"\n aria-label={messages.groupByBarLabel}\n >\n {showPlaceholder && (\n <span className=\"gridkit-group-by-bar-placeholder\">\n {messages.groupByBarPlaceholder}\n </span>\n )}\n {groupBy.map((entry, index) => {\n const dropBefore = activeDropTarget?.beforeColumnId === entry.columnId;\n const dropAfter =\n activeDropTarget?.beforeColumnId === null &&\n index === groupBy.length - 1;\n const dragging = chipDrag.draggedColumnId === entry.columnId;\n\n return (\n <span\n key={entry.columnId}\n className={classNames(\n \"gridkit-group-by-chip\",\n dragging ? \"is-dragging\" : \"\",\n dropBefore ? \"is-drop-before\" : \"\",\n dropAfter ? \"is-drop-after\" : \"\",\n )}\n data-gridkit-group-chip={entry.columnId}\n tabIndex={0}\n aria-label={messages.groupByChipLabel(\n columnName(entry.columnId),\n index + 1,\n groupBy.length,\n )}\n aria-keyshortcuts=\"Control+ArrowLeft Control+ArrowRight\"\n onPointerDown={(event) => {\n chipDrag.startDrag(entry.columnId, event);\n }}\n onKeyDown={(event) => {\n const step = inlineStep(\n event.key,\n writingDirection(event.currentTarget),\n );\n if (step !== null && event.ctrlKey) {\n event.preventDefault();\n moveByKeyboard(entry.columnId, step);\n }\n }}\n >\n <span className=\"gridkit-group-by-chip-label\">\n {labelFor(entry.columnId)}\n </span>\n <button\n type=\"button\"\n className=\"gridkit-group-by-chip-remove\"\n aria-label={messages.removeGroupBy(columnName(entry.columnId))}\n onPointerDown={(event) => {\n // Otherwise the chip's own `onPointerDown` sees this bubble\n // up and starts a drag — the same reason the header's own\n // sort toggle stops it.\n event.stopPropagation();\n }}\n onClick={() => {\n controller.toggleGroupBy(entry.columnId);\n }}\n >\n ×\n </button>\n </span>\n );\n })}\n {/*\n * Portalled to the body, the same reason the header's own drag ghost\n * is: inside the viewport the overflow that makes the grid scroll\n * would clip it, and this bar sits right above that viewport.\n */}\n {chipDrag.draggedColumnId !== null &&\n chipDrag.ghostTransform !== null &&\n createPortal(\n <span\n className=\"gridkit-group-by-chip gridkit-drag-ghost\"\n style={{ transform: chipDrag.ghostTransform }}\n aria-hidden=\"true\"\n >\n {labelFor(chipDrag.draggedColumnId)}\n </span>,\n document.body,\n )}\n </div>\n );\n}\n","import type { PointerEvent as ReactPointerEvent } from \"react\";\nimport type { GroupByState } from \"@gridkitjs/core\";\nimport {\n resolveGroupByDropTarget,\n type GroupByDropTarget,\n} from \"@gridkitjs/dom\";\nimport useDragReorder from \"./useDragReorder\";\n\ninterface UseGroupByDragOptions {\n groupBy: GroupByState;\n onDrop: (movedColumnId: string, beforeColumnId: string | null) => void;\n}\n\nexport interface GroupByDragApi {\n /** The chip being dragged, for as long as the drag lasts. */\n draggedColumnId: string | null;\n /** Where it would land if released now. */\n dropTarget: GroupByDropTarget | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n ghostTransform: string | null;\n startDrag: (columnId: string, event: ReactPointerEvent<HTMLElement>) => void;\n}\n\n/**\n * Drag-to-reorder for chips inside the group-by bar, built on the same\n * `useDragReorder` mechanics `useColumnDrag` uses for headers — only the\n * hit-testing (`resolveGroupByDropTarget`, shared with a header dropped in\n * from outside the bar) differs.\n */\nexport default function useGroupByDrag({\n groupBy,\n onDrop,\n}: UseGroupByDragOptions): GroupByDragApi {\n const drag = useDragReorder<GroupByDropTarget>({\n resolveTarget: (clientX, clientY, movedId) =>\n resolveGroupByDropTarget(clientX, clientY, movedId, groupBy),\n onDrop: (target, movedId) => {\n onDrop(movedId, target.beforeColumnId);\n },\n });\n\n return {\n draggedColumnId: drag.draggedId,\n dropTarget: drag.dropTarget,\n ghostTransform: drag.ghostTransform,\n startDrag: (columnId, event) => {\n drag.startDrag(columnId, event.currentTarget, event);\n },\n };\n}\n","import {\n useLayoutEffect,\n useRef,\n useState,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport {\n NO_DRAG,\n startDragReorder,\n type DragReorderHandlers,\n type DragReorderState,\n} from \"@gridkitjs/dom\";\nimport useGestureSignal from \"./useGestureSignal\";\n\ntype UseDragReorderOptions<Target> = Pick<\n DragReorderHandlers<Target>,\n \"resolveTarget\" | \"onDrop\"\n>;\n\nexport interface DragReorderApi<Target> {\n /** The item being dragged, for as long as the drag lasts. */\n draggedId: string | null;\n /** Where it would land if released now, `null` for nowhere valid. */\n dropTarget: Target | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n ghostTransform: string | null;\n startDrag: (\n id: string,\n grabElement: HTMLElement,\n event: ReactPointerEvent<HTMLElement>,\n ) => void;\n /**\n * Whether `id`'s last press opened a drag, so the `click` that follows its\n * release is not a click, for a press that has something of its own to do\n * with one.\n *\n * Reading it clears it, and so does the next drag's press, so a press that\n * never opened a drag — on an item that cannot be dragged, or after a drag\n * cancelled with Escape and released elsewhere — does not see the last\n * one's answer.\n */\n justDragged: (id: string) => boolean;\n}\n\n/**\n * `@gridkitjs/dom`'s `startDragReorder`, the pointer mechanics behind every\n * drag-to-reorder gesture in the grid, with what it reports held as state\n * for the header and the group-by bar to draw. A column header drag and a\n * group-by chip drag (`useColumnDrag`, `useGroupByDrag`) share it, so they\n * can only ever differ in their own hit-testing (`resolveTarget`).\n *\n * The drag ends with the component, and with its grab element should a\n * render remove it (`useGestureSignal`).\n */\nexport default function useDragReorder<Target>({\n resolveTarget,\n onDrop,\n}: UseDragReorderOptions<Target>): DragReorderApi<Target> {\n const [drag, setDrag] = useState<DragReorderState<Target>>(NO_DRAG);\n /**\n * The item whose press opened a drag, held for the `click` that follows\n * the release: the only thing that can tell a drag apart from a press in\n * the same spot.\n */\n const openedDragId = useRef<string | null>(null);\n const startGesture = useGestureSignal();\n /**\n * What a drag under way resolves its targets and drops against: the\n * handlers of the latest render, so an order or grouping that changes\n * mid-drag counts from the next pointer move.\n */\n const handlers = useRef({ resolveTarget, onDrop });\n useLayoutEffect(() => {\n handlers.current = { resolveTarget, onDrop };\n });\n\n function justDragged(id: string): boolean {\n const answer = openedDragId.current === id;\n openedDragId.current = null;\n return answer;\n }\n\n function startDrag(\n id: string,\n grabElement: HTMLElement,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n const started = startGesture(grabElement, (signal) =>\n startDragReorder(id, grabElement, event, {\n resolveTarget: (clientX, clientY, movedId) =>\n handlers.current.resolveTarget(clientX, clientY, movedId),\n onState(state) {\n if (state.kind === \"dragging\") {\n openedDragId.current = state.draggedId;\n }\n setDrag(state);\n },\n onDrop: (target, movedId) => {\n handlers.current.onDrop(target, movedId);\n },\n signal,\n }),\n );\n // Only a press that began a drag clears it, so a second finger landing\n // mid-drag leaves the drag under way its answer. The new drag reports\n // nothing before its first move, so this never clears what it set.\n if (started) {\n openedDragId.current = null;\n }\n }\n\n const dragging = drag.kind === \"dragging\" ? drag : null;\n return {\n draggedId: dragging?.draggedId ?? null,\n dropTarget: dragging?.dropTarget ?? null,\n ghostTransform: dragging?.ghostTransform ?? null,\n startDrag,\n justDragged,\n };\n}\n","import { useEffect, useRef } from \"react\";\n\ninterface Gesture {\n /** The element the gesture listens on, which `@gridkitjs/dom` captured. */\n readonly element: HTMLElement;\n readonly controller: AbortController;\n}\n\n/**\n * Starts a gesture on `element` with `start`, handing it the `AbortSignal`\n * that ends it, and returns whatever `start` said about whether it began.\n */\nexport type StartGesture = (\n element: HTMLElement,\n start: (signal: AbortSignal) => boolean,\n) => boolean;\n\n/**\n * One `AbortSignal` per pointer gesture, for `@gridkitjs/dom`'s\n * `startDragReorder`/`startColumnResizeGesture`, whose `handlers.signal`\n * cancels the gesture as Escape does.\n *\n * A gesture that begins aborts the one before it; a press that begins none,\n * such as a second finger landing mid-drag, leaves it alone. The signal\n * aborts when the component unmounts, or after any render that has taken the\n * gesture's element out of the document: a header whose column is hidden\n * mid-drag goes with every listener the gesture had on it, so nothing else\n * would ever end what the grid draws for the gesture. Aborting a gesture that\n * has already ended does nothing.\n */\nexport default function useGestureSignal(): StartGesture {\n const gesture = useRef<Gesture | null>(null);\n\n useEffect(() => {\n const current = gesture.current;\n if (current !== null && !current.element.isConnected) {\n gesture.current = null;\n current.controller.abort();\n }\n });\n\n useEffect(\n () => () => {\n gesture.current?.controller.abort();\n },\n [],\n );\n\n return function startGesture(element, start) {\n const controller = new AbortController();\n if (!start(controller.signal)) {\n return false;\n }\n gesture.current?.controller.abort();\n gesture.current = { element, controller };\n return true;\n };\n}\n","import {\n isColumnVisible,\n isGroupExpanded,\n resolveColumnPin,\n type ColumnPinningEvent,\n type ColumnResizeEvent,\n type ColumnSortEvent,\n type ColumnVisibilityEvent,\n type GridMessages,\n type GroupByEvent,\n type GroupExpansionEvent,\n type PaginationChangeEvent,\n type SelectionDiffEvent,\n} from \"@gridkitjs/core\";\nimport type {\n CellSelectionChangeEvent,\n ColumnDefinition,\n DataGridProps,\n} from \"./DataGrid\";\n\n/** The change callbacks of a grid's props that announce what they report. */\ntype AnnouncedProps<Row> = Pick<\n DataGridProps<Row>,\n | \"onColumnSizingChange\"\n | \"onColumnVisibilityChange\"\n | \"onColumnPinningChange\"\n | \"onColumnSortChange\"\n | \"onGroupByChange\"\n | \"onGroupExpansionChange\"\n | \"onPaginationChange\"\n | \"onCellSelectionChange\"\n>;\n\ninterface AnnouncedCallbacksOptions<Row> {\n /** The grid's own callbacks, each called before its change is announced. */\n readonly callbacks: AnnouncedProps<Row>;\n readonly announce: (text: string) => void;\n readonly messages: GridMessages;\n /** What a column is called in an announcement. */\n readonly columnName: (columnId: string) => string;\n /** A column's definition by id, hidden or not. */\n readonly columnOf: (columnId: string) => ColumnDefinition<Row> | undefined;\n}\n\n/** What the grid hands its controller to hear each change through. */\nexport interface AnnouncedCallbacks<Row> {\n readonly onColumnSizingChange: (event: ColumnResizeEvent) => void;\n readonly onColumnVisibilityChange: (event: ColumnVisibilityEvent) => void;\n readonly onColumnPinningChange: (event: ColumnPinningEvent) => void;\n readonly onColumnSortChange: (event: ColumnSortEvent) => void;\n readonly onGroupByChange: (event: GroupByEvent) => void;\n readonly onGroupExpansionChange: (event: GroupExpansionEvent) => void;\n readonly onPaginationChange: (event: PaginationChangeEvent) => void;\n readonly onCellSelectionChange: (\n event: CellSelectionChangeEvent<Row>,\n ) => void;\n readonly onSelectionDiff: (event: SelectionDiffEvent) => void;\n}\n\n/**\n * The grid's change callbacks, each wrapped to announce its change in the\n * live region after calling the grid's own — so a change is announced where\n * the controller reports it, the same whether a click, a key, a menu or the\n * ref made it.\n */\nexport function announcedCallbacks<Row>({\n callbacks,\n announce,\n messages,\n columnName,\n columnOf,\n}: AnnouncedCallbacksOptions<Row>): AnnouncedCallbacks<Row> {\n return {\n /**\n * Announced only once the drag ends: the controller reports the\n * continuous `\"move\"` phase as well, and a live region given every frame\n * of a drag says nothing an assistive technology can keep up with.\n */\n onColumnSizingChange: (event) => {\n callbacks.onColumnSizingChange?.(event);\n if (event.phase === \"end\") {\n announce(\n messages.columnResized(\n columnName(event.columnId),\n Math.round(event.width),\n ),\n );\n }\n },\n\n /**\n * Naming a column shown or hidden alone, and counting several — \"Show\n * all\" in the column chooser, or `hideColumns` given a list. A change\n * that shows some and hides others, as restoring a layout can, has no\n * one thing to say, and says nothing.\n */\n onColumnVisibilityChange: (event) => {\n callbacks.onColumnVisibilityChange?.(event);\n const { columnIds, visibility } = event;\n const [columnId] = columnIds;\n const shownCount = columnIds.filter((id) => {\n const column = columnOf(id);\n return column !== undefined && isColumnVisible(column, visibility);\n }).length;\n if (\n columnId === undefined ||\n (shownCount !== 0 && shownCount !== columnIds.length)\n ) {\n return;\n }\n const shown = shownCount > 0;\n if (columnIds.length > 1) {\n announce(\n shown\n ? messages.columnsShown(columnIds.length)\n : messages.columnsHidden(columnIds.length),\n );\n return;\n }\n announce(\n shown\n ? messages.columnShown(columnName(columnId))\n : messages.columnHidden(columnName(columnId)),\n );\n },\n\n /**\n * Naming the one column pinned or unpinned and the edge it went to. A\n * change touching several columns, as `setColumnPinning` or restoring a\n * layout can, may pin some and unpin others, and says nothing.\n */\n onColumnPinningChange: (event) => {\n callbacks.onColumnPinningChange?.(event);\n const [columnId, ...others] = event.columnIds;\n if (columnId === undefined || others.length > 0) {\n return;\n }\n const column = columnOf(columnId);\n if (column === undefined) {\n return;\n }\n const pin = resolveColumnPin(column, event.pinning);\n announce(\n pin === \"none\"\n ? messages.columnUnpinned(columnName(columnId))\n : messages.columnPinned(columnName(columnId), pin),\n );\n },\n\n /** A toggle, a stack, or a clear back to \"none\" each get their own. */\n onColumnSortChange: (event) => {\n callbacks.onColumnSortChange?.(event);\n const entry = event.sort.find(\n (candidate) => candidate.columnId === event.columnId,\n );\n if (entry === undefined) {\n announce(messages.sortCleared(columnName(event.columnId)));\n return;\n }\n announce(\n messages.columnSorted(\n columnName(event.columnId),\n entry.direction,\n event.sort.indexOf(entry) + 1,\n event.sort.length,\n ),\n );\n },\n\n onGroupByChange: (event) => {\n callbacks.onGroupByChange?.(event);\n const entry = event.groupBy.find(\n (candidate) => candidate.columnId === event.columnId,\n );\n if (entry === undefined) {\n announce(messages.groupingRemoved(columnName(event.columnId)));\n return;\n }\n announce(\n messages.groupedBy(\n columnName(event.columnId),\n event.groupBy.indexOf(entry) + 1,\n event.groupBy.length,\n ),\n );\n },\n\n /**\n * `groupId: null` marks `expandAll`/`collapseAll` and\n * `setGroupExpansion`, which touch every group in one call rather than\n * one at a time — announced as a single summary of the mode the groups\n * now follow, instead of naming a group that doesn't apply.\n */\n onGroupExpansionChange: (event) => {\n callbacks.onGroupExpansionChange?.(event);\n if (event.groupId === null) {\n announce(\n event.expansion.mode === \"allExpanded\"\n ? messages.allGroupsExpanded\n : messages.allGroupsCollapsed,\n );\n return;\n }\n announce(\n isGroupExpanded(event.expansion, event.groupId)\n ? messages.groupExpanded\n : messages.groupCollapsed,\n );\n },\n\n onPaginationChange: (event) => {\n callbacks.onPaginationChange?.(event);\n announce(\n messages.pageStatus(event.pagination.pageIndex + 1, event.pageCount),\n );\n },\n\n /**\n * Unlike rows and columns, a cell selection is always exactly one cell —\n * there is no multi-cell range — so it never crosses the count's >1\n * threshold and the focused cell's own `aria-selected` is the only\n * feedback a screen-reader user would otherwise get. Announced on every\n * change that lands on a cell instead.\n */\n onCellSelectionChange: (event) => {\n callbacks.onCellSelectionChange?.(event);\n if (event.selected !== null) {\n announce(\n messages.cellSelected(\n columnName(event.selected.columnId),\n event.selected.rowIndex + 1,\n ),\n );\n }\n },\n\n /**\n * Announced only for a change touching more than one row or column. A\n * single selection is already carried by the focused member's own\n * `aria-selected`, and repeating it here would talk over that. Counted\n * by id, so rows the change touched off screen — on another page, in a\n * collapsed group — count too.\n */\n onSelectionDiff: (event) => {\n if (event.added.length + event.removed.length > 1) {\n announce(messages.selectedCount(event.selection.length, event.target));\n }\n },\n };\n}\n","import type { KeyboardEvent } from \"react\";\nimport { runCommand, type GridCommandTarget } from \"@gridkitjs/core\";\nimport { isNativeCopy } from \"@gridkitjs/dom\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\n\ninterface UseGridCopyOptions<Row> {\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n nav: GridNavigationApi;\n}\n\nfunction isCopyKey(event: KeyboardEvent): boolean {\n return (\n (event.ctrlKey || event.metaKey) &&\n !event.altKey &&\n (event.key === \"c\" || event.key === \"C\")\n );\n}\n\n/**\n * Ctrl+C (Cmd+C on a Mac) on the grid: copies the selection, else the\n * focused cell, through the same `copy.selection` and `copy.cell` commands\n * the context menu runs — so an app that overrides one changes both. The\n * returned handler belongs on the grid root's `onKeyDown`, for keys the\n * grid itself received.\n *\n * A press in a text field inside a cell, or with text highlighted on the\n * page, is the browser's, and so is one with nothing to copy: the default\n * is prevented only once a copy ran. Like the grid's other keys, it is not\n * reported to `onCommand`, which hears of menu and API runs.\n */\nexport default function useGridCopy<Row>({\n controller,\n commands,\n nav,\n}: UseGridCopyOptions<Row>): (event: KeyboardEvent) => void {\n function run(commandId: string, target: GridCommandTarget): boolean {\n const command = commands.commands.get(commandId);\n return (\n command !== undefined && runCommand(command, commands.contextFor(target))\n );\n }\n\n /** The focused data cell as a command target, or `null` on a header or a group row. */\n function focusedCell(): GridCommandTarget | null {\n const { focus } = nav;\n if (focus.area === \"header\") {\n return null;\n }\n const { pageRows, columns } = controller.getView();\n const entry = pageRows[focus.rowIndex];\n const column = columns[focus.columnIndex];\n return entry?.kind !== \"data\" || column === undefined\n ? null\n : { area: \"cell\", rowId: entry.rowId, columnId: column.id };\n }\n\n return (event) => {\n if (!isCopyKey(event) || isNativeCopy(event.target)) {\n return;\n }\n const cell = focusedCell();\n if (\n run(\"copy.selection\", { area: \"grid\" }) ||\n (cell !== null && run(\"copy.cell\", cell))\n ) {\n event.preventDefault();\n }\n };\n}\n","import { useMemo } from \"react\";\nimport {\n createCommandContext,\n resolveCommands,\n runCommand,\n type GridCommand,\n type GridCommandContext,\n type GridCommandHost,\n type GridCommandSource,\n type GridCommandTarget,\n type GridMessages,\n type GridOptions,\n} from \"@gridkitjs/core\";\nimport useCopyToClipboard from \"../clipboard/useCopyToClipboard\";\nimport useSaveFile from \"../export/useSaveFile\";\nimport { printGrid } from \"../print/printApi\";\nimport type { ColumnResizeApi } from \"../useColumnResize\";\nimport type { DataGridController } from \"../useGridController\";\n\ninterface UseGridCommandsOptions<Row> {\n controller: DataGridController<Row>;\n /** The app's commands, over the built-ins. */\n commands: GridOptions<Row>[\"commands\"];\n onCommand: GridOptions<Row>[\"onCommand\"];\n /** The grid's messages, over the defaults — what every built-in label reads. */\n messages: GridMessages;\n announce: (text: string) => void;\n resize: ColumnResizeApi<Row>;\n /** Opens one of the grid's panels — see `useGridPanels`. */\n openPanel: GridCommandHost[\"openPanel\"];\n}\n\nexport interface GridCommandsApi<Row> {\n /** Every command the grid knows, by id. */\n commands: ReadonlyMap<string, GridCommand<Row>>;\n /** What a command needs that only the grid has: its DOM, its live region. */\n host: GridCommandHost;\n /** A command context for `target`, over the grid as it is now. */\n contextFor: (target: GridCommandTarget) => GridCommandContext<Row>;\n /** Tells `onCommand` that a command, or an inline menu item, ran. */\n report: (\n commandId: string,\n target: GridCommandTarget,\n source: GridCommandSource,\n ) => void;\n /**\n * Runs the command `commandId` on `target` when it is visible and enabled\n * there, reports it, and says whether it ran.\n */\n run: (\n commandId: string,\n target: GridCommandTarget,\n source: GridCommandSource,\n ) => boolean;\n}\n\n/**\n * The commands behind the grid's menus — the built-ins and the app's own —\n * and the context they run in. Which command shows, is enabled or does what\n * is `@gridkitjs/core`'s; the grid lends them what needs a DOM — sizing a\n * column to its content, as double-clicking its resize handle does,\n * opening its panels, downloading an export, writing the clipboard and\n * printing — and its live region.\n */\nexport default function useGridCommands<Row>({\n controller,\n commands: appCommands,\n onCommand,\n messages,\n announce,\n resize,\n openPanel,\n}: UseGridCommandsOptions<Row>): GridCommandsApi<Row> {\n const commands = useMemo(() => resolveCommands(appCommands), [appCommands]);\n const { saveFile, canSave } = useSaveFile({ messages, announce });\n const writeClipboard = useCopyToClipboard({ messages, announce });\n\n const host: GridCommandHost = {\n autoFitColumns: (columnIds) => {\n const { columns } = controller.getView();\n let fitted = 0;\n for (const columnId of columnIds) {\n const entry = columns.find((candidate) => candidate.id === columnId);\n if (entry !== undefined && resize.sizeToContent(entry)) {\n fitted += 1;\n }\n }\n // Each resize announced itself, and the live region keeps only the\n // last; one message for them all replaces it before anything is read.\n if (fitted > 1) {\n announce(messages.columnsAutoFitted(fitted));\n }\n },\n openPanel,\n announce,\n saveFile,\n canSave,\n writeClipboard,\n print: (document, options) => {\n printGrid(document, options).catch((error: unknown) => {\n console.error(\"DataGrid: the print failed.\", error);\n announce(messages.printFailed);\n });\n },\n };\n\n function contextFor(target: GridCommandTarget): GridCommandContext<Row> {\n return createCommandContext({ controller, target, messages, host });\n }\n\n function report(\n commandId: string,\n target: GridCommandTarget,\n source: GridCommandSource,\n ): void {\n onCommand?.({ commandId, target, source });\n }\n\n // A new object each render, as the other hooks here return.\n return {\n commands,\n host,\n contextFor,\n report,\n run: (commandId, target, source) => {\n const command = commands.get(commandId);\n if (command === undefined) {\n console.error(`DataGrid: there is no command \\`${commandId}\\` to run.`);\n return false;\n }\n if (!runCommand(command, contextFor(target))) {\n return false;\n }\n report(commandId, target, source);\n return true;\n },\n };\n}\n","import { useRef } from \"react\";\nimport type { GridCommandHost, GridMessages } from \"@gridkitjs/core\";\nimport { writeClipboard } from \"@gridkitjs/dom\";\n\ninterface UseCopyToClipboardOptions {\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/**\n * The host's `writeClipboard`: puts a copy on the clipboard and says so, as\n * nothing on screen does. A copy the browser refuses is logged for the\n * developer and announced for the user, who would otherwise paste whatever\n * the clipboard held before.\n *\n * Only the latest copy is announced. A write cannot be called off, so one\n * finishing after a later copy began says nothing, rather than telling the\n * user they hold what they copied before.\n */\nexport default function useCopyToClipboard({\n messages,\n announce,\n}: UseCopyToClipboardOptions): GridCommandHost[\"writeClipboard\"] {\n /** How many copies have begun: the number of the latest. */\n const copies = useRef(0);\n\n return (content) => {\n copies.current += 1;\n const copy = copies.current;\n function announceIfLatest(text: string): void {\n if (copy === copies.current) {\n announce(text);\n }\n }\n writeClipboard(content).then(\n () => {\n announceIfLatest(messages.copied(content.count, content.unit));\n },\n (error: unknown) => {\n console.error(\"DataGrid: the clipboard could not be written.\", error);\n announceIfLatest(messages.copyFailed);\n },\n );\n };\n}\n","import { useRef } from \"react\";\nimport type {\n ExportFile,\n GridCommandHost,\n GridMessages,\n} from \"@gridkitjs/core\";\nimport { downloadBlob } from \"@gridkitjs/dom\";\nimport { exportBlob } from \"./exportApi\";\n\ninterface UseSaveFileOptions {\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/** Whether a writer is still writing the last export asked for. */\ntype SaveState = { readonly kind: \"idle\" } | { readonly kind: \"writing\" };\n\nconst IDLE: SaveState = { kind: \"idle\" };\nconst WRITING: SaveState = { kind: \"writing\" };\n\n/**\n * The host's `saveFile`, which downloads an export once its writer has\n * finished writing it, and its `canSave`.\n *\n * One at a time. An export asked for while a writer is still writing the\n * last is dropped and logged, and the export command that asked for it did\n * not run, so pressing a slow export twice saves one file, and reports one\n * command, rather than two. The export command asks `canSave` before it\n * builds its file, so a dropped export never runs its writer. A writer that\n * fails, or a download the browser refuses, is logged for the developer and\n * announced for the user, who asked for a file that will not come.\n */\nexport default function useSaveFile({\n messages,\n announce,\n}: UseSaveFileOptions): Pick<GridCommandHost, \"saveFile\" | \"canSave\"> {\n const state = useRef<SaveState>(IDLE);\n\n /**\n * Whether a file asked for now would be saved. An export asks just before\n * it would build its file, so a refusal is that export dropped, and logged.\n */\n function canSave(): boolean {\n if (state.current.kind === \"writing\") {\n console.error(\n \"DataGrid: an export is still being written, so this one was dropped.\",\n );\n return false;\n }\n return true;\n }\n\n function fail(reason: string, error: unknown): void {\n console.error(`DataGrid: ${reason}`, error);\n announce(messages.exportFailed);\n }\n\n function download(file: ExportFile): void {\n try {\n downloadBlob(exportBlob(file), file.fileName);\n } catch (error) {\n fail(\"the export could not be saved.\", error);\n }\n }\n\n function saveFile(file: ExportFile | Promise<ExportFile>): boolean {\n if (!canSave()) {\n return false;\n }\n if (!(file instanceof Promise)) {\n download(file);\n return true;\n }\n state.current = WRITING;\n file\n .then(download, (error: unknown) => {\n fail(\"the export's writer failed.\", error);\n })\n .finally(() => {\n state.current = IDLE;\n });\n return true;\n }\n\n return { saveFile, canSave };\n}\n","import {\n exportFile,\n resolveExportWriters,\n type ExportFile,\n type ExportWriter,\n type GridExportOptions,\n} from \"@gridkitjs/core\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\n\n/** What `DataGridApi` carries for exporting. */\nexport interface GridExportApi {\n /**\n * The grid's view exported as `format` — `\"csv\"`, `\"json\"`, a format\n * registered through `exportWriters`, or a writer passed as it is — and\n * handed back as a `Blob`, under the grid's `export` option with\n * `options` over it, field by field. Nothing is downloaded:\n * `runCommand(\"export.csv\")` downloads.\n *\n * Rejects for a format no writer is registered for, and when the writer\n * fails.\n */\n exportData(\n format: string | ExportWriter,\n options?: GridExportOptions,\n ): Promise<Blob>;\n}\n\n/**\n * An export's contents as a `Blob` of its media type. Text is stored as\n * UTF-8, a byte order mark the writer put first included, so a CSV opens in\n * a spreadsheet with its accents intact. Bytes are copied: a `Blob` takes\n * no view of shared memory, which a `Uint8Array` may be.\n */\nexport function exportBlob({ content, mimeType }: ExportFile): Blob {\n const part = typeof content === \"string\" ? content : content.slice();\n return new Blob([part], { type: mimeType });\n}\n\n/** `DataGridApi.exportData`, over the grid as it is when called. */\nexport function exportApi<Row>({\n contextFor,\n}: GridCommandsApi<Row>): GridExportApi {\n return {\n exportData: async (format, options) => {\n const context = contextFor({ area: \"grid\" });\n const { export: defaults, exportWriters } = context.options;\n const file = exportFile(\n context,\n format,\n { ...defaults, ...options },\n resolveExportWriters(exportWriters),\n );\n // `exportFile` has logged the format by name; the caller is told too.\n if (file === null) {\n throw new Error(\n \"DataGrid: there is no export writer for that format — register one through `exportWriters`.\",\n );\n }\n return exportBlob(await file);\n },\n };\n}\n","import {\n exportPrintDocument,\n type PrintDocument,\n type PrintOptions,\n} from \"@gridkitjs/core\";\nimport { printDocument, printStyles } from \"@gridkitjs/dom\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\n\n/** What `DataGridApi` carries for printing. */\nexport interface GridPrintApi {\n /**\n * Prints the grid's view through the browser's print dialog — every row\n * the filter leaves, across pages and collapsed groups, not only those\n * drawn — under the grid's `print` option with `options` over it, field\n * by field. Resolves once the dialog has closed, or at once while another\n * print is open.\n */\n print(options?: PrintOptions): Promise<void>;\n}\n\n/**\n * Puts a print document on paper through a hidden frame, under the print\n * stylesheet for its page with `options.styles` after it. The frame sees\n * none of the page's CSS, the theme's included.\n */\nexport function printGrid(\n document: PrintDocument,\n { styles = \"\" }: PrintOptions,\n): Promise<void> {\n return printDocument({\n title: document.title,\n bodyHtml: document.bodyHtml,\n styles: printStyles(document.page) + styles,\n });\n}\n\n/** `DataGridApi.print`, over the grid as it is when called. */\nexport function printApi<Row>({\n contextFor,\n}: GridCommandsApi<Row>): GridPrintApi {\n return {\n print: (options) => {\n const context = contextFor({ area: \"grid\" });\n const merged = { ...context.options.print, ...options };\n return printGrid(exportPrintDocument(context, merged), merged);\n },\n };\n}\n","import { useLayoutEffect, useRef, useState, type RefObject } from \"react\";\nimport type {\n ResolvedMenuEntry,\n ResolvedMenuItem,\n ResolvedMenuSubmenu,\n} from \"@gridkitjs/core\";\nimport {\n attachMenu,\n type AttachedMenu,\n type MenuSubmenuFocus,\n} from \"@gridkitjs/dom\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport Overlay, { type OverlayScope } from \"../overlay/Overlay\";\nimport { CheckIcon, ChevronRightIcon, MenuIcon } from \"./menuIcons\";\n\ninterface GridMenuProps {\n entries: readonly ResolvedMenuEntry[];\n /** The menu's accessible name. */\n label: string;\n /** The palette and direction its submenus take — the ones its own overlay took. */\n scope: OverlayScope;\n /** An enabled item was chosen: run it, and close every menu. */\n onRun: (item: ResolvedMenuItem) => void;\n /** Tab or Shift+Tab: close every menu. */\n onClose: () => void;\n /**\n * ArrowLeft, or ArrowRight in a right-to-left menu: close this menu, which\n * is a submenu, so focus goes back to\n * the item that opened it. Given only to a submenu; a menu without it has\n * nowhere to go back to.\n */\n onCloseSubmenu?: (() => void) | undefined;\n /**\n * Holds this menu's behaviour while it is attached, for the menu that\n * opened it to move focus in.\n */\n behaviourRef?: RefObject<AttachedMenu | null> | undefined;\n}\n\n/** Whether a submenu is open from a menu, and which. */\ntype SubmenuState =\n | { readonly kind: \"closed\" }\n | {\n readonly kind: \"open\";\n readonly id: string;\n /** The item it opened from, which it opens beside. */\n readonly anchor: HTMLElement;\n readonly focus: MenuSubmenuFocus;\n /** Lines its first item up with `anchor`. */\n readonly offset: number;\n }\n /**\n * Closed because its entry left the menu. The overlay hands focus back to\n * the entry's item as it detaches, before the same commit removes that\n * item, so focus that was in the submenu is left on the page's body.\n */\n | { readonly kind: \"entryGone\" };\n\nconst CLOSED: SubmenuState = { kind: \"closed\" };\nconst ENTRY_GONE: SubmenuState = { kind: \"entryGone\" };\n\n/** The item of `menu` whose id is `id`, read off the markup this drew. */\nfunction itemElement(menu: HTMLElement, id: string): HTMLElement | null {\n return (\n Array.from(\n menu.querySelectorAll<HTMLElement>(\"[data-gridkit-menu-item]\"),\n ).find((item) => item.getAttribute(\"data-gridkit-menu-item\") === id) ?? null\n );\n}\n\n/**\n * How far below a menu's top edge its first item starts: its top border and\n * padding. A submenu is styled the same, so opening it this far up lines its\n * first item up with the item that opened it, whatever the theme makes them.\n */\nfunction topInset(menu: HTMLElement): number {\n const style = getComputedStyle(menu);\n return parseFloat(style.borderTopWidth) + parseFloat(style.paddingTop);\n}\n\nfunction MenuItem({\n entry,\n expanded,\n}: {\n entry: ResolvedMenuItem | ResolvedMenuSubmenu;\n /** For a submenu item: whether its submenu is open. */\n expanded: boolean;\n}) {\n const isItem = entry.type === \"item\";\n const checked = isItem ? entry.checked : undefined;\n const shortcut = isItem ? entry.shortcut : undefined;\n return (\n <div\n role={checked === undefined ? \"menuitem\" : \"menuitemcheckbox\"}\n data-gridkit-menu-item={entry.id}\n className=\"gridkit-menu-item\"\n {...ariaAttr(isItem && entry.disabled, \"aria-disabled\", true)}\n {...ariaAttr(checked !== undefined, \"aria-checked\", checked)}\n {...ariaAttr(shortcut !== undefined, \"aria-keyshortcuts\", shortcut)}\n {...ariaAttr<\"aria-haspopup\", \"menu\">(!isItem, \"aria-haspopup\", \"menu\")}\n {...ariaAttr(!isItem, \"aria-expanded\", expanded)}\n >\n <span className=\"gridkit-menu-item-icon\" aria-hidden=\"true\">\n {checked === true ? <CheckIcon /> : <MenuIcon name={entry.icon} />}\n </span>\n <span className=\"gridkit-menu-item-label\">{entry.label}</span>\n {/* Read out through `aria-keyshortcuts`, not as part of the name. */}\n {shortcut !== undefined && (\n <span className=\"gridkit-menu-item-shortcut\" aria-hidden=\"true\">\n {shortcut}\n </span>\n )}\n {!isItem && (\n <span className=\"gridkit-menu-submenu-indicator\" aria-hidden=\"true\">\n <ChevronRightIcon />\n </span>\n )}\n </div>\n );\n}\n\n/**\n * A menu resolved by `@gridkitjs/core`'s `resolveMenu`, drawn as\n * `role=\"menu\"` and made to behave as one by `@gridkitjs/dom`'s\n * `attachMenu`, which decides what every key and hover does; this draws the\n * items and which submenu is open. Shown inside an `Overlay` — which attaches\n * after this, so its initial focus lands on the item `attachMenu` made the\n * tab stop.\n *\n * A submenu is a `GridMenu` of its own, in an `Overlay` of its own anchored\n * to the item that opened it.\n */\nexport default function GridMenu({\n entries,\n label,\n scope,\n onRun,\n onClose,\n onCloseSubmenu,\n behaviourRef,\n}: GridMenuProps) {\n const menuRef = useRef<HTMLDivElement>(null);\n const submenuBehaviourRef = useRef<AttachedMenu | null>(null);\n const [submenu, setSubmenu] = useState<SubmenuState>(CLOSED);\n const isSubmenu = onCloseSubmenu !== undefined;\n\n /**\n * What the behaviour's callbacks read. They are handed over once, when it\n * attaches, so they read the props and state of the latest render here.\n */\n const latest = useRef({ entries, submenu, onRun, onClose, onCloseSubmenu });\n useLayoutEffect(() => {\n latest.current = { entries, submenu, onRun, onClose, onCloseSubmenu };\n });\n\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (menu === null) {\n return undefined;\n }\n const behaviour = attachMenu(menu, {\n onActivate: (id) => {\n const item = latest.current.entries.find(\n (entry): entry is ResolvedMenuItem =>\n entry.type === \"item\" && entry.id === id,\n );\n if (item !== undefined) {\n latest.current.onRun(item);\n }\n },\n onOpenSubmenu: (id, { focus }) => {\n // Already open — the pointer opened it — so the keyboard only asks\n // for focus to move into it.\n const open = latest.current.submenu;\n if (open.kind === \"open\" && open.id === id) {\n if (focus === \"first\") {\n submenuBehaviourRef.current?.focusItem(0);\n }\n return;\n }\n const anchor = itemElement(menu, id);\n if (anchor !== null) {\n setSubmenu({\n kind: \"open\",\n id,\n anchor,\n focus,\n offset: -topInset(menu),\n });\n }\n },\n onCollapseSubmenu: () => {\n setSubmenu(CLOSED);\n },\n onCloseSubmenu: isSubmenu\n ? () => {\n latest.current.onCloseSubmenu?.();\n }\n : undefined,\n onClose: () => {\n latest.current.onClose();\n },\n });\n if (behaviourRef !== undefined) {\n behaviourRef.current = behaviour;\n }\n return () => {\n if (behaviourRef !== undefined) {\n behaviourRef.current = null;\n }\n behaviour.detach();\n };\n }, [isSubmenu, behaviourRef]);\n\n // Focus left on the body by a submenu whose entry went comes back to this\n // menu: its tab stop, or its first item once the tab stop was that entry.\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (\n submenu.kind !== \"entryGone\" ||\n menu === null ||\n document.activeElement !== document.body\n ) {\n return;\n }\n const item =\n menu.querySelector<HTMLElement>(\n '[data-gridkit-menu-item][tabindex=\"0\"]',\n ) ?? menu.querySelector<HTMLElement>(\"[data-gridkit-menu-item]\");\n item?.focus();\n }, [submenu]);\n\n function closeSubmenu(): void {\n setSubmenu(CLOSED);\n }\n\n const openEntry =\n submenu.kind === \"open\"\n ? entries.find(\n (entry): entry is ResolvedMenuSubmenu =>\n entry.type === \"submenu\" && entry.id === submenu.id,\n )\n : undefined;\n // Its entry has gone from `entries`: the submenu closes for good, rather\n // than coming back open with the entry.\n if (submenu.kind === \"open\" && openEntry === undefined) {\n setSubmenu(ENTRY_GONE);\n }\n\n return (\n <>\n <div\n ref={menuRef}\n role=\"menu\"\n aria-label={label}\n className=\"gridkit-menu\"\n >\n {entries.map((entry) =>\n entry.type === \"separator\" ? (\n <div\n key={entry.key}\n role=\"separator\"\n className=\"gridkit-menu-separator\"\n />\n ) : (\n <MenuItem\n key={entry.id}\n entry={entry}\n expanded={submenu.kind === \"open\" && entry.id === submenu.id}\n />\n ),\n )}\n </div>\n {submenu.kind === \"open\" && openEntry !== undefined && (\n <Overlay\n key={submenu.id}\n anchor={submenu.anchor}\n placement=\"right-start\"\n offset={submenu.offset}\n initialFocus={submenu.focus}\n scope={scope}\n onDismiss={closeSubmenu}\n >\n <GridMenu\n entries={openEntry.items}\n label={openEntry.label}\n scope={scope}\n onRun={onRun}\n onClose={onClose}\n onCloseSubmenu={closeSubmenu}\n behaviourRef={submenuBehaviourRef}\n />\n </Overlay>\n )}\n </>\n );\n}\n","import { useLayoutEffect, useRef, type ReactNode, type RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { WritingDirection } from \"@gridkitjs/core/renderer\";\nimport {\n attachOverlay,\n writingDirection,\n type OverlayAnchor,\n type OverlayDismissReason,\n type OverlayInitialFocus,\n type OverlayPlacement,\n} from \"@gridkitjs/dom\";\nimport { classNames } from \"../classNames\";\n\n/**\n * What an overlay copies from the element it opens from, rendering into\n * `document.body` out of reach of what that element inherits: the palette\n * class (`gridkit-light`, `gridkit-dark` or none, to follow the page) and\n * the writing direction, which lays out its content and places it.\n */\nexport interface OverlayScope {\n readonly themeClassName: string;\n readonly direction: WritingDirection;\n}\n\ninterface OverlayProps {\n /**\n * What the overlay opens beside: an element, or a point. It and the\n * options after it are read when the overlay attaches, and a change to any\n * of them attaches it afresh — moving focus back in — so each should stay\n * the same for as long as the overlay is open.\n */\n anchor: OverlayAnchor;\n placement?: OverlayPlacement | undefined;\n gap?: number | undefined;\n offset?: number | undefined;\n /**\n * Where focus goes on attaching — see `attachOverlay`'s option — or a ref\n * to the control it goes to, read as the overlay attaches, once its\n * children have mounted, so that it can be one of theirs. A ref holding\n * nothing sends it to the first control.\n */\n initialFocus?:\n OverlayInitialFocus | RefObject<HTMLElement | null> | undefined;\n returnFocusTo?: HTMLElement | null | undefined;\n /**\n * See `attachOverlay`'s option: where focus goes once `returnFocusTo` has\n * left the page. Read as the overlay detaches, so it need not stay the same.\n */\n returnFocusFallback?: (() => HTMLElement | null) | undefined;\n /** See `attachOverlay`'s option: a panel whose controls change the grid under it. */\n ignoreScrollAfterInput?: boolean | undefined;\n /** See `attachOverlay`'s option: Tab stays inside, as in a dialog. */\n trapFocus?: boolean | undefined;\n /** The palette and direction the overlay takes — see `overlayScope`. */\n scope: OverlayScope;\n /** The overlay asks to close; the caller unmounts it, or not. */\n onDismiss: (reason: OverlayDismissReason) => void;\n children: ReactNode;\n}\n\n/**\n * The space between a menu or panel and the element it opens below — a\n * toolbar button, a header — so its shadow does not run into that element's\n * border. Nothing opened at a point, or beside its own menu, as a submenu is,\n * takes it.\n */\nexport const ANCHOR_GAP = 4;\n\n/** `focus` as `attachOverlay` takes it, reading a ref's control now. */\nfunction attachedFocus(\n focus: OverlayProps[\"initialFocus\"],\n): OverlayInitialFocus | undefined {\n return typeof focus === \"object\" && !(focus instanceof HTMLElement)\n ? (focus.current ?? \"first\")\n : focus;\n}\n\n/**\n * The palette class an overlay opened from `element` copies:\n * `gridkit-light` or `gridkit-dark`, from the nearest ancestor carrying one,\n * or none to follow the page.\n */\nfunction themeClassNameOf(element: Element | null): string {\n const scope = element?.closest(\".gridkit-light, .gridkit-dark\");\n if (scope === null || scope === undefined) {\n return \"\";\n }\n return scope.classList.contains(\"gridkit-dark\")\n ? \"gridkit-dark\"\n : \"gridkit-light\";\n}\n\n/**\n * The scope an overlay opened from `element` takes, read as it opens. With\n * no element, it follows the page.\n */\nexport function overlayScope(element: Element | null): OverlayScope {\n return {\n themeClassName: themeClassNameOf(element),\n direction: writingDirection(element ?? document.documentElement),\n };\n}\n\n/**\n * `children` in a panel portalled into `document.body` — where no scrolling\n * ancestor of the grid clips it — shown beside `anchor` by\n * `@gridkitjs/dom`'s `attachOverlay` for as long as it is mounted.\n *\n * Attached in a layout effect, which React runs after its children's: a menu\n * inside attaches its own behaviour first, so the overlay's initial focus\n * finds the item that behaviour made the tab stop. A nested overlay — a\n * submenu — mounts on a later user action than the one it opens from, so it\n * attaches after it and sits above it in the overlay stack.\n */\nexport default function Overlay({\n anchor,\n placement,\n gap,\n offset,\n initialFocus,\n returnFocusTo,\n returnFocusFallback,\n ignoreScrollAfterInput,\n trapFocus,\n scope,\n onDismiss,\n children,\n}: OverlayProps) {\n const panelRef = useRef<HTMLDivElement>(null);\n // Read through refs, so new functions every render do not re-attach.\n const onDismissRef = useRef(onDismiss);\n const returnFocusFallbackRef = useRef(returnFocusFallback);\n useLayoutEffect(() => {\n onDismissRef.current = onDismiss;\n returnFocusFallbackRef.current = returnFocusFallback;\n });\n\n useLayoutEffect(() => {\n const panel = panelRef.current;\n if (panel === null) {\n return undefined;\n }\n return attachOverlay(anchor, panel, {\n placement,\n gap,\n offset,\n initialFocus: attachedFocus(initialFocus),\n returnFocusTo,\n returnFocusFallback: () => returnFocusFallbackRef.current?.() ?? null,\n ignoreScrollAfterInput,\n trapFocus,\n onDismiss: (reason) => {\n onDismissRef.current(reason);\n },\n });\n }, [\n anchor,\n placement,\n gap,\n offset,\n initialFocus,\n returnFocusTo,\n ignoreScrollAfterInput,\n trapFocus,\n ]);\n\n return createPortal(\n <div\n ref={panelRef}\n className={classNames(\"gridkit-overlay\", scope.themeClassName)}\n dir={scope.direction}\n >\n {children}\n </div>,\n document.body,\n );\n}\n","import type { ReactNode } from \"react\";\nimport type { BuiltInCommandIcon } from \"@gridkitjs/core\";\nimport { GroupIcon, Icon } from \"../icons\";\n\n/** A glyph for every icon key the built-in commands carry. */\nconst BUILT_IN_ICONS: Readonly<Record<BuiltInCommandIcon, () => ReactNode>> = {\n sortAscending: () => (\n <Icon>\n <path d=\"m3 8 4-4 4 4\" />\n <path d=\"M7 4v16\" />\n <path d=\"M11 12h4\" />\n <path d=\"M11 16h7\" />\n <path d=\"M11 20h10\" />\n </Icon>\n ),\n sortDescending: () => (\n <Icon>\n <path d=\"m3 16 4 4 4-4\" />\n <path d=\"M7 20V4\" />\n <path d=\"M11 4h10\" />\n <path d=\"M11 8h7\" />\n <path d=\"M11 12h4\" />\n </Icon>\n ),\n group: () => <GroupIcon />,\n hide: () => (\n <Icon>\n <path d=\"M9.88 9.88a3 3 0 1 0 4.24 4.24\" />\n <path d=\"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68\" />\n <path d=\"M6.61 6.61A13.53 13.53 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61\" />\n <path d=\"m2 2 20 20\" />\n </Icon>\n ),\n autoFit: () => (\n <Icon>\n <path d=\"m18 8 4 4-4 4\" />\n <path d=\"M2 12h20\" />\n <path d=\"m6 8-4 4 4 4\" />\n </Icon>\n ),\n copy: () => (\n <Icon>\n <rect x=\"8\" y=\"8\" width=\"14\" height=\"14\" rx=\"2\" />\n <path d=\"M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2\" />\n </Icon>\n ),\n print: () => (\n <Icon>\n <path d=\"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2\" />\n <path d=\"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6\" />\n <rect x=\"6\" y=\"14\" width=\"12\" height=\"8\" rx=\"1\" />\n </Icon>\n ),\n};\n\n/**\n * Looked up through a `Map`, since an item's key may be any string an app\n * chose, and one such as `\"toString\"` must find nothing rather than\n * something on `Object.prototype`.\n */\nconst ICONS = new Map(Object.entries(BUILT_IN_ICONS));\n\n/** The icon a key names, or nothing for a key the grid has no glyph for. */\nexport function MenuIcon({ name }: { name: string | undefined }) {\n const draw = name === undefined ? undefined : ICONS.get(name);\n return draw === undefined ? null : draw();\n}\n\n/** What a checked item shows in place of its icon. */\nexport function CheckIcon() {\n return (\n <Icon>\n <path d=\"M20 6 9 17l-5-5\" />\n </Icon>\n );\n}\n\n/** Marks a button that opens a menu below it. */\nexport function ChevronDownIcon() {\n return (\n <Icon>\n <path d=\"m6 9 6 6 6-6\" />\n </Icon>\n );\n}\n\n/** Marks a button going back to what a panel showed before. */\nexport function ChevronLeftIcon() {\n return (\n <Icon>\n <path d=\"m15 18-6-6 6-6\" />\n </Icon>\n );\n}\n\n/** Marks an item that opens a submenu. */\nexport function ChevronRightIcon() {\n return (\n <Icon>\n <path d=\"m9 18 6-6-6-6\" />\n </Icon>\n );\n}\n","import GridMenu from \"../menu/GridMenu\";\nimport Overlay, { ANCHOR_GAP } from \"../overlay/Overlay\";\nimport type { ContextMenuApi } from \"./useContextMenu\";\n\n/**\n * The open context menu, if any — beside the point it was asked for at, or\n * below its cell when asked for by a key — returning focus to that cell when\n * it closes, or, from the body's empty space, to wherever focus was before.\n * Rendered after the grid's tables, as every grid overlay is, so\n * the keys pressed in it reach no header or body handler on their way up\n * React's tree.\n */\nexport default function GridContextMenu({\n contextMenu,\n}: {\n contextMenu: ContextMenuApi;\n}) {\n const { menu, returnFocusFallback, run, close } = contextMenu;\n if (menu === null) {\n return null;\n }\n return (\n <Overlay\n key={menu.key}\n anchor={menu.anchor}\n gap={menu.anchor instanceof Element ? ANCHOR_GAP : 0}\n returnFocusTo={menu.cell ?? undefined}\n returnFocusFallback={returnFocusFallback}\n scope={menu.scope}\n onDismiss={close}\n >\n <GridMenu\n entries={menu.entries}\n label={menu.label}\n scope={menu.scope}\n onRun={run}\n onClose={close}\n />\n </Overlay>\n );\n}\n","import {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n type RefObject,\n} from \"react\";\nimport {\n contextMenuEntries,\n isSameCell,\n resolveMenu,\n type CellSelectionState,\n type GridContextMenuArea,\n type GridContextMenuTarget,\n type GridMessages,\n type GridOptions,\n type ResolvedMenuEntry,\n type ResolvedMenuItem,\n} from \"@gridkitjs/core\";\nimport { hasContextMenu, pinnedWidths } from \"@gridkitjs/core/renderer\";\nimport {\n attachContextMenuTrigger,\n type ContextMenuRequest,\n type OverlayAnchor,\n} from \"@gridkitjs/dom\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport { overlayScope, type OverlayScope } from \"../overlay/Overlay\";\nimport type { GridOverlayApi } from \"../overlay/useGridOverlay\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\nimport type { GridSelectionApi } from \"../useGridSelection\";\nimport {\n placeAt,\n placeOf,\n type ContextMenuPlace,\n type GridParts,\n} from \"./contextMenuPlaces\";\n\ninterface UseContextMenuOptions<Row> {\n /** The grid's root element: a menu is asked for on what is inside it. */\n rootRef: RefObject<HTMLElement | null>;\n /** The tables' scroll area, which a cell is seen through. */\n scrollRef: RefObject<HTMLElement | null>;\n headerTableRef: RefObject<HTMLTableElement | null>;\n bodyTableRef: RefObject<HTMLTableElement | null>;\n /** The body's rowgroup, whose empty space is the `body` area. */\n bodyRef: RefObject<HTMLElement | null>;\n footerTableRef: RefObject<HTMLTableElement | null>;\n contextMenu: GridOptions<Row>[\"contextMenu\"];\n /** The grid's one open overlay, the menu among them. */\n overlay: GridOverlayApi;\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n messages: GridMessages;\n /** What a column is called in a menu's name. */\n columnName: (columnId: string) => string;\n}\n\n/** The context menu open now. */\nexport interface OpenContextMenu {\n /** Counts the openings, so one opened over another replaces it. */\n readonly key: number;\n readonly target: GridContextMenuTarget;\n readonly entries: readonly ResolvedMenuEntry[];\n /** Its accessible name. */\n readonly label: string;\n /** The point it was asked for at, or its cell when asked for by a key. */\n readonly anchor: OverlayAnchor;\n /**\n * The cell it opened on, which has focus first and gets it back after —\n * `null` in the body's empty space, which leaves focus where it was.\n */\n readonly cell: HTMLElement | null;\n readonly scope: OverlayScope;\n}\n\nexport interface ContextMenuApi {\n menu: OpenContextMenu | null;\n /** Whether `area` opens a menu — for the `aria-keyshortcuts` of its cells. */\n opens: (area: GridContextMenuArea) => boolean;\n /**\n * Opens the menu `target` has, as a right-click there would, beside\n * `anchor` or below its cell, and says whether it did: not for a target\n * that is not on screen, or whose menu is empty.\n */\n open: (target: GridContextMenuTarget, anchor?: OverlayAnchor) => boolean;\n /** See `GridOverlayApi`. */\n returnFocusFallback: () => HTMLElement | null;\n /** Runs the item the user chose, reporting it if it ran, then closes the menu. */\n run: (item: ResolvedMenuItem) => void;\n close: () => void;\n}\n\n/**\n * The grid's context menu. `@gridkitjs/dom`'s trigger reports a right-click,\n * Shift+F10 or the ContextMenu key inside the grid, and the ref can ask for\n * one too; the `contextMenu` option and `@gridkitjs/core`'s `resolveMenu`\n * say what menu that place has; this opens it as the grid's one overlay\n * (see `useGridOverlay`, which tells `onContextMenuOpenChange`) and does\n * what opening it means in the grid.\n *\n * Opening one on a column, row or cell that is not selected selects it\n * first, where that kind is selectable, as a click on it would — opening one\n * inside the selection keeps it, so a menu can act on everything selected.\n * Focus moves to the cell first, so closing the menu returns it there. A\n * place whose menu resolves to nothing shows the browser's own.\n */\nexport default function useContextMenu<Row>({\n rootRef,\n scrollRef,\n headerTableRef,\n bodyTableRef,\n bodyRef,\n footerTableRef,\n contextMenu,\n overlay,\n controller,\n commands,\n nav,\n selection,\n messages,\n columnName,\n}: UseContextMenuOptions<Row>): ContextMenuApi {\n const { drawn, close: closeOverlay } = overlay;\n const openings = useRef(0);\n const enabled = contextMenu !== undefined && contextMenu !== false;\n\n function parts(): GridParts<Row> {\n const { columns, pageRows } = controller.getView();\n return {\n scroller: scrollRef.current,\n headerTable: headerTableRef.current,\n bodyTable: bodyTableRef.current,\n body: bodyRef.current,\n footerTable: footerTableRef.current,\n columns,\n pinnedWidths: pinnedWidths(columns),\n pageRows,\n };\n }\n\n function labelOf(target: GridContextMenuTarget): string {\n switch (target.area) {\n case \"header\":\n return messages.headerMenuLabel(columnName(target.columnId));\n case \"cell\":\n return messages.cellMenuLabel;\n case \"group\":\n return messages.groupMenuLabel;\n case \"body\":\n return messages.bodyMenuLabel;\n }\n }\n\n /**\n * Selects what the menu opens on unless it is selected already, and says\n * whether it did. Each kind follows its own `selectable` mode, as a click\n * does — a cell's row and the cell itself apart — and a kind a user cannot\n * select is left alone.\n */\n function selectTarget(target: GridContextMenuTarget): boolean {\n const state = controller.getState();\n if (target.area === \"header\") {\n if (\n selection.columnMode === false ||\n state.columnSelection.includes(target.columnId)\n ) {\n return false;\n }\n controller.selectColumn(target.columnId, \"replace\");\n return true;\n }\n if (target.area !== \"cell\") {\n return false;\n }\n const cell = {\n kind: \"cell\",\n rowId: target.rowId,\n columnId: target.columnId,\n } satisfies CellSelectionState;\n const selectRow =\n selection.rowMode !== false && !state.rowSelection.includes(target.rowId);\n const selectCell =\n selection.cellMode !== false && !isSameCell(state.cellSelection, cell);\n if (selectRow) {\n controller.selectRow(target.rowId, \"replace\");\n }\n if (selectCell) {\n controller.selectCell(cell, \"replace\");\n }\n return selectRow || selectCell;\n }\n\n /** The menu `target` has, over the grid as it is now. */\n function resolveFor(\n target: GridContextMenuTarget,\n ): readonly ResolvedMenuEntry[] {\n const context = commands.contextFor(target);\n return resolveMenu(contextMenuEntries(contextMenu, context), {\n commands: commands.commands,\n context,\n });\n }\n\n function openAt(\n { target, cell, anchor }: ContextMenuPlace,\n point: OverlayAnchor | null,\n ): boolean {\n let resolved = resolveFor(target);\n if (resolved.length === 0) {\n return false;\n }\n // Resolved again against the selection the menu now acts on.\n if (selectTarget(target)) {\n resolved = resolveFor(target);\n }\n if (cell !== null && document.activeElement !== cell.element) {\n // Focused without scrolling first: a scroll would close the menu about\n // to open beside it. Moving the tab stop after it then finds the cell\n // focused already.\n cell.element.focus({ preventScroll: true });\n nav.focusCellNow(cell.focus);\n }\n openings.current += 1;\n overlay.open({\n kind: \"contextMenu\",\n menu: {\n key: openings.current,\n target,\n entries: resolved,\n label: labelOf(target),\n anchor: point ?? anchor,\n cell: cell?.element ?? null,\n scope: overlayScope(rootRef.current),\n },\n });\n return true;\n }\n\n function handleRequest({ target, point }: ContextMenuRequest): boolean {\n const place = placeAt(target, parts());\n return place !== null && openAt(place, point);\n }\n\n // The trigger is attached once, and hears every request through this.\n const latestRequest = useRef(handleRequest);\n useLayoutEffect(() => {\n latestRequest.current = handleRequest;\n });\n\n useEffect(() => {\n const root = rootRef.current;\n if (!enabled || root === null) {\n return undefined;\n }\n return attachContextMenuTrigger(root, {\n onRequest: (request) => latestRequest.current(request),\n });\n }, [rootRef, enabled]);\n\n const close = useCallback(() => {\n closeOverlay(\"contextMenu\");\n }, [closeOverlay]);\n\n // A menu open as `contextMenu` turns off, or as the grid unmounts, closes\n // with it.\n useEffect(() => (enabled ? close : undefined), [enabled, close]);\n\n return {\n menu: drawn.kind === \"contextMenu\" ? drawn.menu : null,\n opens: (area) => hasContextMenu(contextMenu, area),\n open: (target, anchor) => {\n const place = placeOf(target, parts());\n return place !== null && openAt(place, anchor ?? null);\n },\n returnFocusFallback: overlay.returnFocusFallback,\n run: (item) => {\n const open = overlay.current();\n if (item.run() && open.kind === \"contextMenu\") {\n commands.report(item.id, open.menu.target, \"contextMenu\");\n }\n // A panel the item opened has replaced the menu already, and stays.\n close();\n },\n close,\n };\n}\n","import {\n bodyFocus,\n headerFocus,\n type DisplayRow,\n type GridContextMenuTarget,\n type GridFocus,\n} from \"@gridkitjs/core\";\nimport {\n bodyCellFrom,\n bodyRowFrom,\n findBodyRow,\n groupRowFrom,\n writingDirection,\n type OverlayAnchor,\n} from \"@gridkitjs/dom\";\n\n/** The cell a menu opens on, with its place in the grid's focus. */\nexport interface TargetCell {\n readonly element: HTMLTableCellElement;\n readonly focus: GridFocus;\n}\n\n/** Where a context menu opens: its target, and what it is drawn on. */\nexport interface ContextMenuPlace {\n readonly target: GridContextMenuTarget;\n /** The cell that has focus while it is open; `null` in the body's empty space. */\n readonly cell: TargetCell | null;\n /**\n * What it goes beside when asked for without a point: the cell — or, for a\n * cell scrolled out of the grid's view, the nearest point on that view's\n * edge — or the body's corner.\n */\n readonly anchor: OverlayAnchor;\n}\n\n/** The parts of the grid, as drawn now, that a place is found among. */\nexport interface GridParts<Row> {\n /** The tables' scroll area, which scrolls the rows both ways. */\n readonly scroller: HTMLElement | null;\n /** Sticks to the scroll area's top, over the rows scrolled under it. */\n readonly headerTable: HTMLTableElement | null;\n readonly bodyTable: HTMLTableElement | null;\n /** The body's rowgroup, whose empty space is the `body` area. */\n readonly body: HTMLElement | null;\n /** Sticks to the scroll area's bottom, over the rows scrolled under it. */\n readonly footerTable: HTMLTableElement | null;\n /** The columns shown, in order — what a cell's column index counts. */\n readonly columns: readonly { readonly id: string }[];\n /** How much of the view's width the pinned columns cover at each edge. */\n readonly pinnedWidths: { readonly start: number; readonly end: number };\n /** The rows of the page, as `data-gridkit-row-index` counts them. */\n readonly pageRows: readonly DisplayRow<Row>[];\n}\n\nfunction headerCell(\n parts: GridParts<unknown>,\n columnIndex: number,\n): TargetCell | null {\n const element = parts.headerTable?.tHead?.rows[0]?.cells[columnIndex];\n return element === undefined\n ? null\n : { element, focus: headerFocus(columnIndex) };\n}\n\nfunction bodyCell(\n parts: GridParts<unknown>,\n rowIndex: number,\n columnIndex: number,\n): TargetCell | null {\n const element = findBodyRow(parts.bodyTable, rowIndex)?.cells[columnIndex];\n return element === undefined\n ? null\n : { element, focus: bodyFocus(rowIndex, columnIndex) };\n}\n\n/**\n * Whether `element` is a cell that pinned columns can cover: one that\n * scrolls sideways in a grid with columns pinned.\n */\nfunction underPinnedColumns(\n element: Element,\n parts: GridParts<unknown>,\n): boolean {\n return (\n parts.pinnedWidths.start + parts.pinnedWidths.end > 0 &&\n element instanceof HTMLTableCellElement &&\n !element.matches(\".is-pinned-start, .is-pinned-end\")\n );\n}\n\n/**\n * The part of the viewport where `element` can be seen: its grid's scrolled\n * view; for a body cell only the part of it between the header and the\n * footer, and for a cell pinned columns can cover only the part of the\n * scrollport between them.\n */\nfunction viewOf(element: Element, parts: GridParts<unknown>): DOMRect | null {\n const { scroller } = parts;\n if (scroller === null) {\n return null;\n }\n const view = scroller.getBoundingClientRect();\n let { top, bottom, left, right } = view;\n if (parts.body?.contains(element) === true) {\n top = Math.max(\n top,\n parts.headerTable?.getBoundingClientRect().bottom ?? top,\n );\n bottom = Math.min(\n bottom,\n parts.footerTable?.getBoundingClientRect().top ?? bottom,\n );\n }\n if (underPinnedColumns(element, parts)) {\n // Pinned cells stick to the scrollport's edges, inside the scrollbar.\n const { start, end } = parts.pinnedWidths;\n const rtl = writingDirection(element) === \"rtl\";\n const portLeft = view.left + scroller.clientLeft;\n left = portLeft + (rtl ? end : start);\n right = portLeft + scroller.clientWidth - (rtl ? start : end);\n }\n return new DOMRect(\n left,\n top,\n Math.max(0, right - left),\n Math.max(0, bottom - top),\n );\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\n/** The x of `box`'s edge where `element`'s lines start: its left, or its right under `dir=\"rtl\"`. */\nfunction inlineStartOf(element: Element, box: DOMRect): number {\n return writingDirection(element) === \"rtl\" ? box.right : box.left;\n}\n\n/**\n * A cell's place, anchored to the cell itself while any of it is in the\n * grid's view (a group row's cell can be wider than the view). One scrolled\n * wholly out of it — the ref can ask for any cell drawn — is\n * anchored to the point of the view nearest its bottom corner at the inline\n * start (the left one, or the right under `dir=\"rtl\"`) instead, so the menu\n * opens at the grid's edge rather than off in the page, over whatever the\n * grid's scrolling hides it under.\n */\nfunction onCell(\n target: GridContextMenuTarget,\n cell: TargetCell | null,\n parts: GridParts<unknown>,\n): ContextMenuPlace | null {\n if (cell === null) {\n return null;\n }\n const box = cell.element.getBoundingClientRect();\n const view = viewOf(cell.element, parts);\n if (\n view === null ||\n (box.right > view.left &&\n box.left < view.right &&\n box.bottom > view.top &&\n box.top < view.bottom)\n ) {\n return { target, cell, anchor: cell.element };\n }\n return {\n target,\n cell,\n anchor: {\n x: clamp(inlineStartOf(cell.element, box), view.left, view.right),\n y: clamp(box.bottom, view.top, view.bottom),\n },\n };\n}\n\n/**\n * The body's empty space, anchored to the top corner of the part of it in\n * view, at the inline start.\n */\nfunction onBody(\n body: HTMLElement,\n parts: GridParts<unknown>,\n): ContextMenuPlace {\n const box = body.getBoundingClientRect();\n const view = viewOf(body, parts) ?? box;\n return {\n target: { area: \"body\" },\n cell: null,\n anchor: {\n x: inlineStartOf(body, view),\n y: clamp(box.top, view.top, view.bottom),\n },\n };\n}\n\nfunction headerPlaceAt<Row>(\n element: Element,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n const cell = element.closest<HTMLTableCellElement>(\"th[data-gridkit-column]\");\n const columnId = cell?.getAttribute(\"data-gridkit-column\");\n if (\n cell === null ||\n cell.parentElement !== parts.headerTable?.tHead?.rows[0] ||\n columnId === null ||\n columnId === undefined\n ) {\n return null;\n }\n return onCell(\n { area: \"header\", columnId },\n headerCell(parts, cell.cellIndex),\n parts,\n );\n}\n\n/**\n * A data cell or a group row of the body, read off the rows of the page, or\n * the body's empty space. A cell must be the one `element` is in, not one of\n * a table some cell template holds, which has rows of its own. A group's\n * summary row, with nothing of its own to act on, has no place.\n */\nfunction bodyPlaceAt<Row>(\n element: Element,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n const { body, pageRows } = parts;\n if (body === null || !body.contains(element)) {\n return null;\n }\n const group = groupRowFrom(element);\n if (group !== null) {\n const entry = pageRows[group.rowIndex];\n const cell = bodyCell(parts, group.rowIndex, 0);\n return entry !== undefined &&\n entry.kind === \"group\" &&\n cell?.element.contains(element) === true\n ? onCell(\n { area: \"group\", groupId: entry.groupId, columnId: entry.columnId },\n cell,\n parts,\n )\n : null;\n }\n const position = bodyCellFrom(element);\n if (position !== null) {\n const entry = pageRows[position.rowIndex];\n const cell = bodyCell(parts, position.rowIndex, position.columnIndex);\n return entry !== undefined &&\n entry.kind === \"data\" &&\n cell?.element.contains(element) === true\n ? onCell(\n { area: \"cell\", rowId: entry.rowId, columnId: position.columnId },\n cell,\n parts,\n )\n : null;\n }\n return bodyRowFrom(element) === null ? onBody(body, parts) : null;\n}\n\n/**\n * The place `element` is in — a header, a data cell, a group row or the\n * body's empty space — or `null` for anything else in the grid: the footer,\n * the pager, the group-by bar.\n */\nexport function placeAt<Row>(\n element: Element,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n return headerPlaceAt(element, parts) ?? bodyPlaceAt(element, parts);\n}\n\n/**\n * The place `target` names, among what is drawn now — `null` for a column,\n * row or group not on screen: hidden, on another page, in a collapsed group\n * or outside a virtualized window.\n */\nexport function placeOf<Row>(\n target: GridContextMenuTarget,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n const columnIndexOf = (columnId: string) =>\n parts.columns.findIndex((column) => column.id === columnId);\n switch (target.area) {\n case \"header\":\n return onCell(\n target,\n headerCell(parts, columnIndexOf(target.columnId)),\n parts,\n );\n case \"cell\": {\n const rowIndex = parts.pageRows.findIndex(\n (entry) => entry.kind === \"data\" && entry.rowId === target.rowId,\n );\n return onCell(\n target,\n bodyCell(parts, rowIndex, columnIndexOf(target.columnId)),\n parts,\n );\n }\n case \"group\": {\n const rowIndex = parts.pageRows.findIndex(\n (entry) => entry.kind === \"group\" && entry.groupId === target.groupId,\n );\n return onCell(target, bodyCell(parts, rowIndex, 0), parts);\n }\n case \"body\":\n return parts.body === null ? null : onBody(parts.body, parts);\n }\n}\n","import { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { GridOptions } from \"@gridkitjs/core\";\nimport type { OpenContextMenu } from \"../contextMenu/useContextMenu\";\nimport type { OpenPanel } from \"../panels/useGridPanels\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\n\n/** Which of the grid's top-level overlays is open: one at most. */\nexport type GridOverlayState =\n | { readonly kind: \"closed\" }\n | { readonly kind: \"contextMenu\"; readonly menu: OpenContextMenu }\n | { readonly kind: \"panel\"; readonly panel: OpenPanel };\n\nexport type OpenGridOverlay = Exclude<GridOverlayState, { kind: \"closed\" }>;\n\nconst CLOSED: GridOverlayState = { kind: \"closed\" };\n\ninterface UseGridOverlayOptions<Row> {\n nav: GridNavigationApi;\n onContextMenuOpenChange: GridOptions<Row>[\"onContextMenuOpenChange\"];\n}\n\nexport interface GridOverlayApi {\n /** The overlay as the last render drew it. */\n drawn: GridOverlayState;\n /**\n * The overlay open as of the last change, ahead of the render that draws\n * it: what a call acting on the open overlay reads.\n */\n current: () => GridOverlayState;\n /** Opens `next` in place of whatever is open. */\n open: (next: OpenGridOverlay) => void;\n /** Closes the overlay open if it is a `kind` one, and leaves any other. */\n close: (kind: OpenGridOverlay[\"kind\"]) => void;\n /**\n * Where focus goes when an overlay closes and the element it returns focus\n * to has gone with what it did, as a header goes with its hidden column:\n * the cell now holding the grid's tab stop.\n */\n returnFocusFallback: () => HTMLElement | null;\n}\n\n/**\n * The grid's top-level overlays — the context menu and the panels — held as\n * one state, so opening one closes the other, whether from the grid or the\n * ref. Every change goes through here, which tells `onContextMenuOpenChange`\n * when a context menu opens or closes: the one closing first.\n *\n * `open` and `close` keep their identity across renders, so an effect can\n * close an overlay on its way out.\n */\nexport default function useGridOverlay<Row>({\n nav,\n onContextMenuOpenChange,\n}: UseGridOverlayOptions<Row>): GridOverlayApi {\n const [drawn, setDrawn] = useState(CLOSED);\n const current = useRef(CLOSED);\n // Read through a ref, so a menu closing as the grid unmounts tells the\n // latest callback.\n const reportOpenChange = useRef(onContextMenuOpenChange);\n useLayoutEffect(() => {\n reportOpenChange.current = onContextMenuOpenChange;\n });\n\n const show = useCallback((next: GridOverlayState): void => {\n const previous = current.current;\n current.current = next;\n setDrawn(next);\n if (previous.kind === \"contextMenu\") {\n reportOpenChange.current?.({ open: false, target: previous.menu.target });\n }\n if (next.kind === \"contextMenu\") {\n reportOpenChange.current?.({ open: true, target: next.menu.target });\n }\n }, []);\n\n const close = useCallback(\n (kind: OpenGridOverlay[\"kind\"]): void => {\n if (current.current.kind === kind) {\n show(CLOSED);\n }\n },\n [show],\n );\n\n return {\n drawn,\n current: () => current.current,\n open: show,\n close,\n returnFocusFallback: nav.tabStopCell,\n };\n}\n","import { useRef, type ReactNode, type RefCallback } from \"react\";\nimport type {\n FilterState,\n GridCommandTarget,\n GridMessages,\n GridPanelKind,\n} from \"@gridkitjs/core\";\nimport type { ColumnValueOptions } from \"@gridkitjs/core/renderer\";\nimport ColumnChooser from \"../columnChooser/ColumnChooser\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport FilterMenu from \"../filterMenu/FilterMenu\";\nimport useApplyFilter from \"../filterMenu/useApplyFilter\";\nimport useFilterValueCache from \"../filterMenu/useFilterValueCache\";\nimport Overlay, { ANCHOR_GAP } from \"../overlay/Overlay\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridPanelsApi } from \"./useGridPanels\";\n\n/** What every panel is drawn with. */\nexport interface GridPanelProps<Row> {\n /** Where it was asked for — a header's names the column a panel acts on. */\n readonly target: GridCommandTarget;\n /** Read for the grid's state as each render draws it, and acted on. */\n readonly controller: DataGridController<Row>;\n /** The grid's commands, for a panel running one so `onCommand` hears it. */\n readonly commands: GridCommandsApi<Row>;\n readonly messages: GridMessages;\n /** Closes the panel, giving focus back to where it was opened from. */\n readonly close: () => void;\n /**\n * The `ref` of the control focus starts on as the panel opens — a filter\n * editor's value box. A panel giving it to none starts on its first\n * control.\n */\n readonly initialFocusRef: RefCallback<HTMLElement>;\n /**\n * Sets the grid's filter as a filter menu applies one, announcing the rows\n * it keeps once they are drawn — even when the menu has closed by then.\n */\n readonly applyFilter: (filter: FilterState<Row>) => void;\n /**\n * The values a filter checklist lists for a column, counted once and\n * handed back again while nothing they are counted from changes — kept\n * by the panel host, so reopening a column's menu reuses its list.\n */\n readonly columnValues: (columnId: string) => ColumnValueOptions;\n}\n\n/** How one kind of panel is drawn. */\ninterface PanelKind {\n readonly component: <Row>(props: GridPanelProps<Row>) => ReactNode;\n /**\n * Whether Tab stays inside the panel, as in a dialog. A panel holding a\n * draft keeps it, since tabbing out would close it and drop the draft; one\n * applying every change at once lets Tab leave.\n */\n readonly trapFocus: boolean;\n}\n\n/**\n * Each kind of panel. Keyed by `GridPanelKind`, so a kind added there fails\n * to compile until it has its entry here, and needs nothing else.\n */\nconst panelKinds: { readonly [Kind in GridPanelKind]: PanelKind } = {\n columnChooser: { component: ColumnChooser, trapFocus: false },\n filter: { component: FilterMenu, trapFocus: true },\n};\n\ninterface GridPanelsProps<Row> {\n panels: GridPanelsApi;\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n messages: GridMessages;\n}\n\n/**\n * The open panel, if any, beside where it was asked for. Rendered after the\n * grid's tables, as every grid overlay is, so the keys pressed in it reach\n * no header or body handler on their way up React's tree.\n */\nexport default function GridPanels<Row>({\n panels,\n controller,\n commands,\n messages,\n}: GridPanelsProps<Row>) {\n const initialFocus = useRef<HTMLElement>(null);\n const applyFilter = useApplyFilter(\n controller,\n messages,\n commands.host.announce,\n );\n const columnValues = useFilterValueCache(controller, messages);\n const { panel, close, returnFocusFallback } = panels;\n if (panel === null) {\n return null;\n }\n const { component: Panel, trapFocus } = panelKinds[panel.kind];\n return (\n <Overlay\n key={panel.key}\n anchor={panel.anchor}\n placement={panel.placement}\n gap={panel.anchor instanceof Element ? ANCHOR_GAP : 0}\n initialFocus={initialFocus}\n returnFocusTo={panel.returnFocusTo}\n returnFocusFallback={returnFocusFallback}\n // A column the chooser hides can scroll the grid back under it.\n ignoreScrollAfterInput\n trapFocus={trapFocus}\n scope={panel.scope}\n onDismiss={close}\n >\n <Panel<Row>\n target={panel.target}\n controller={controller}\n commands={commands}\n messages={messages}\n close={close}\n initialFocusRef={(element) => {\n initialFocus.current = element;\n }}\n applyFilter={applyFilter}\n columnValues={columnValues}\n />\n </Overlay>\n );\n}\n","import { useLayoutEffect, useRef, useState } from \"react\";\nimport { resolveColumnChooser } from \"@gridkitjs/core/renderer\";\nimport type { GridPanelProps } from \"../panels/GridPanels\";\n\n/**\n * The column chooser: a dialog listing every data column, hidden ones\n * included, with a native checkbox each, a search box narrowing the list and\n * a \"Show all\" checkbox over what the search shows. Which columns it lists,\n * which checkbox is disabled and what \"Show all\" does are\n * `@gridkitjs/core`'s `resolveColumnChooser`'s; this draws them.\n *\n * Every change applies at once, through `showColumns` and `hideColumns`, so\n * it reports and announces as any other change to the columns does. There\n * is nothing to confirm, so nothing to cancel: Escape or a click outside\n * just closes it.\n */\nexport default function ColumnChooser<Row>({\n controller,\n messages,\n}: GridPanelProps<Row>) {\n const [search, setSearch] = useState(\"\");\n const showAllRef = useRef<HTMLInputElement>(null);\n const { entries, selectAll, toggleAll } = resolveColumnChooser({\n columns: controller.getView().dataColumns,\n visibility: controller.getState().columnVisibility,\n search,\n });\n\n // A checkbox's mixed state has no attribute, only this property.\n useLayoutEffect(() => {\n if (showAllRef.current !== null) {\n showAllRef.current.indeterminate = selectAll === \"mixed\";\n }\n });\n\n function setVisible(columnIds: readonly string[], visible: boolean): void {\n if (visible) {\n controller.showColumns(columnIds);\n } else {\n controller.hideColumns(columnIds);\n }\n }\n\n return (\n <div\n role=\"dialog\"\n aria-label={messages.columnChooserLabel}\n className=\"gridkit-column-chooser\"\n >\n <input\n type=\"search\"\n className=\"gridkit-column-chooser-search\"\n aria-label={messages.columnChooserSearchLabel}\n placeholder={messages.searchPlaceholder}\n value={search}\n onChange={(event) => {\n setSearch(event.currentTarget.value);\n }}\n />\n {entries.length === 0 ? (\n <p role=\"status\" className=\"gridkit-column-chooser-empty\">\n {messages.noMatchingColumns}\n </p>\n ) : (\n <>\n <label className=\"gridkit-column-chooser-option gridkit-column-chooser-all\">\n <input\n ref={showAllRef}\n type=\"checkbox\"\n checked={selectAll === \"checked\"}\n disabled={toggleAll === null}\n onChange={() => {\n if (toggleAll !== null) {\n setVisible(toggleAll.columnIds, toggleAll.visible);\n }\n }}\n />\n {messages.showAllColumns}\n </label>\n <ul className=\"gridkit-column-chooser-list\">\n {entries.map((entry) => (\n <li key={entry.columnId}>\n <label className=\"gridkit-column-chooser-option\">\n <input\n type=\"checkbox\"\n checked={entry.visible}\n disabled={entry.disabled}\n onChange={() => {\n setVisible([entry.columnId], !entry.visible);\n }}\n />\n {entry.label}\n </label>\n </li>\n ))}\n </ul>\n </>\n )}\n </div>\n );\n}\n","import { useEffect, useRef, type SubmitEvent } from \"react\";\nimport {\n resolveColumnHeaderText,\n resolveMenu,\n type BuiltInCommandId,\n type ResolvedMenuEntry,\n type ResolvedMenuItem,\n} from \"@gridkitjs/core\";\nimport { resolveColumnFilterMenu } from \"@gridkitjs/core/renderer\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { MenuIcon } from \"../menu/menuIcons\";\nimport type { GridPanelProps } from \"../panels/GridPanels\";\nimport ExcelFilterEditor from \"./ExcelFilterEditor\";\nimport type { FilterEditorHandle, FilterEditorProps } from \"./filterEditor\";\nimport SimpleFilterEditor from \"./SimpleFilterEditor\";\n\n/** The sort commands offered above the editor, each hidden where its column cannot sort. */\nconst SORT_COMMANDS: readonly BuiltInCommandId[] = [\n \"sort.ascending\",\n \"sort.descending\",\n \"sort.clear\",\n];\n\nfunction isItem(entry: ResolvedMenuEntry): entry is ResolvedMenuItem {\n return entry.type === \"item\";\n}\n\n/**\n * A column's filter menu: a dialog below its header holding the column's\n * sort commands, its filter editor — the conditions, or the checklist where\n * its `ui` is `\"excel\"` — and buttons that clear the filter, cancel or\n * apply. Which sort entries show and whether \"Clear filter\" can\n * run are the commands' own, resolved by `@gridkitjs/core`'s `resolveMenu`;\n * each runs through the grid's commands, so `onCommand` hears it with the\n * source `\"filterMenu\"`, and closes the menu, as choosing a menu item does.\n *\n * The editor edits a draft, so nothing filters until it is applied: OK, or\n * Enter in a field, applies it; Cancel, Escape or a click outside drops it.\n * The menu closes once the editor has applied, and stays open while the\n * editor marks what keeps it from applying.\n */\nexport default function FilterMenu<Row>({\n target,\n controller,\n commands,\n messages,\n close,\n initialFocusRef,\n applyFilter,\n columnValues,\n}: GridPanelProps<Row>) {\n const editor = useRef<FilterEditorHandle>(null);\n const column =\n target.area === \"header\"\n ? controller\n .getView()\n .dataColumns.find((entry) => entry.id === target.columnId)\n : undefined;\n const menu =\n column === undefined\n ? null\n : resolveColumnFilterMenu(controller.getOptions(), column.column);\n\n // Opened by an app's own command on a column with no menu, or left open as\n // its column loses it: with nothing to show, nothing stays open.\n useEffect(() => {\n if (menu === null) {\n close();\n }\n });\n\n if (column === undefined || menu === null) {\n return null;\n }\n\n const resolveOptions = {\n commands: commands.commands,\n context: commands.contextFor(target),\n };\n const sortItems = resolveMenu(SORT_COMMANDS, resolveOptions).filter(isItem);\n const [clearItem] = resolveMenu([\"filter.clear\"], resolveOptions).filter(\n isItem,\n );\n\n function run(item: ResolvedMenuItem): void {\n commands.run(item.id, target, \"filterMenu\");\n close();\n }\n\n const editorProps: FilterEditorProps<Row> = {\n ref: editor,\n column,\n menu,\n controller,\n messages,\n initialFocusRef,\n applyFilter,\n };\n\n function apply(event: SubmitEvent<HTMLFormElement>): void {\n event.preventDefault();\n if (editor.current?.apply() ?? true) {\n close();\n }\n }\n\n return (\n <div\n role=\"dialog\"\n aria-label={messages.filterMenuLabel(\n resolveColumnHeaderText(column.column),\n )}\n className=\"gridkit-filter-menu\"\n >\n {/*\n * Not validated by the browser: core reads every operand an editor\n * holds, so a `type=\"number\"` input's whole-number step never blocks\n * an apply with a tooltip of the browser's own.\n */}\n <form\n className=\"gridkit-filter-menu-form\"\n noValidate\n onSubmit={apply}\n onKeyDown={(event) => {\n // Enter submits a form from its text boxes but not from a picker —\n // a select, or a checklist's list; here it applies from any.\n if (\n event.key === \"Enter\" &&\n event.target instanceof Element &&\n event.target.closest(\"select, [role=listbox]\") !== null\n ) {\n event.preventDefault();\n event.currentTarget.requestSubmit();\n }\n }}\n >\n {sortItems.length > 0 && (\n <div className=\"gridkit-filter-menu-sort\">\n {sortItems.map((item) => (\n <button\n key={item.id}\n type=\"button\"\n className=\"gridkit-filter-menu-sort-item\"\n disabled={item.disabled}\n {...ariaAttr(\n item.checked !== undefined,\n \"aria-pressed\",\n item.checked,\n )}\n onClick={() => {\n run(item);\n }}\n >\n <span\n className=\"gridkit-filter-menu-sort-icon\"\n aria-hidden=\"true\"\n >\n <MenuIcon name={item.icon} />\n </span>\n {item.label}\n </button>\n ))}\n </div>\n )}\n {menu.ui === \"excel\" ? (\n <ExcelFilterEditor {...editorProps} columnValues={columnValues} />\n ) : (\n <SimpleFilterEditor {...editorProps} />\n )}\n <div className=\"gridkit-filter-menu-actions\">\n {clearItem !== undefined && (\n <button\n type=\"button\"\n className=\"gridkit-filter-menu-clear\"\n disabled={clearItem.disabled}\n onClick={() => {\n run(clearItem);\n }}\n >\n {clearItem.label}\n </button>\n )}\n <button\n type=\"button\"\n className=\"gridkit-filter-menu-cancel\"\n onClick={close}\n >\n {messages.cancelFilter}\n </button>\n <button type=\"submit\" className=\"gridkit-filter-menu-apply\">\n {messages.applyFilter}\n </button>\n </div>\n </form>\n </div>\n );\n}\n","import {\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n} from \"react\";\nimport type { FilterOperator } from \"@gridkitjs/core\";\nimport {\n draftToFilter,\n filterChecklist,\n filterDraftChanged,\n selectAllState,\n type ColumnValueOptions,\n type FilterChecklistItem,\n} from \"@gridkitjs/core/renderer\";\nimport { ChevronLeftIcon } from \"../menu/menuIcons\";\nimport {\n excelEditorReducer,\n initialExcelEditorState,\n openValues,\n type ChecklistAction,\n} from \"./excelEditorState\";\nimport type { FilterEditorHandle, FilterEditorProps } from \"./filterEditor\";\nimport OperatorMenuButton from \"./OperatorMenuButton\";\nimport SimpleFilterEditor from \"./SimpleFilterEditor\";\nimport ValueChecklist from \"./ValueChecklist\";\n\nexport interface ExcelFilterEditorProps<Row> extends FilterEditorProps<Row> {\n /**\n * The values a column's checklist lists, counted over the rows the other\n * columns' filters keep — the same list again while nothing it is counted\n * from has changed.\n */\n readonly columnValues: (columnId: string) => ColumnValueOptions;\n}\n\n/**\n * What the editor shows: the checklist, or a condition at the operator\n * chosen from its menu, in place of the checklist. A condition takes focus\n * as it shows, being shown only once chosen; the checklist does when it\n * comes back from one, giving focus to the button whose menu chose it.\n */\ntype ExcelEditorMode =\n | { readonly kind: \"values\"; readonly focusOnMount: boolean }\n | { readonly kind: \"condition\"; readonly operator: FilterOperator };\n\nconst OPENED_ON_VALUES: ExcelEditorMode = {\n kind: \"values\",\n focusOnMount: false,\n};\n\n/** What a checklist item's toggle does to the draft. */\nfunction toggleOf<Row>(item: FilterChecklistItem): ChecklistAction<Row> {\n return item.kind === \"blanks\"\n ? { type: \"setIncludeBlanks\", includeBlanks: !item.checked }\n : { type: \"toggleValue\", value: item.value };\n}\n\n/**\n * A filter menu's excel editor: a search box, a \"Select all\" checkbox and a\n * checklist of the values the column holds, each checked while the filter\n * keeps it — the model being `@gridkitjs/core`'s `filterEditorReducer`,\n * over the column's values as `columnValues` counts them when the menu\n * opens. The values cascade: they are those of the rows the other columns'\n * filters keep.\n *\n * The search narrows the list, and \"Select all\" acts on what it shows, as\n * in Excel; past the menu's `valueLimit` values the list waits for a search\n * first, and a search matching more lists the first of them. OK applies the\n * draft through `draftToFilter`: everything checked is no filter, anything\n * less one `in` list, OR-ed with \"is blank\" while the blanks stay checked.\n *\n * Above the search, a \"Number filters\" button opens a menu of the column's\n * conditions. Choosing one shows the simple editor in place of the\n * checklist, its first condition at the operator chosen, until \"Back to\n * values\" brings the checklist back as it was left; OK there applies the\n * conditions, which replace the column's values, as Excel's do.\n *\n * Conditions or a custom filter open with every value checked, under a note\n * saying the column is filtered otherwise. OK leaves that filter be while\n * the checked values are those it opened with — `filterDraftChanged` —\n * as it leaves any filter whose values are as they opened.\n *\n * Set in code while it is open, the column's filter shows in place of what\n * was checked, as it would on reopening the menu.\n */\nexport default function ExcelFilterEditor<Row>({\n column,\n menu,\n controller,\n messages,\n initialFocusRef,\n applyFilter,\n columnValues,\n ref,\n}: ExcelFilterEditorProps<Row>) {\n const filter = controller.getState().filter;\n const open = (over: typeof filter) =>\n openValues(over, column.id, columnValues(column.id));\n const [{ opened, draft }, dispatch] = useReducer(\n excelEditorReducer<Row>,\n filter,\n (over) => initialExcelEditorState(open(over)),\n );\n // Set in code while the menu is open — `setFilter`, a controlled `filter`.\n if (filter !== opened.over) {\n dispatch({ type: \"filterChanged\", opened: open(filter) });\n }\n const [mode, setMode] = useState(OPENED_ON_VALUES);\n const conditions = useRef<FilterEditorHandle>(null);\n const conditionsFocus = useRef<HTMLElement | null>(null);\n const operatorButton = useRef<HTMLButtonElement>(null);\n const selectAllRef = useRef<HTMLInputElement>(null);\n // Each a pass over every value — tens of thousands of them on a large\n // column — so worked out as the draft changes, not again as the editor\n // switches to a condition and back.\n const selectAll = useMemo(() => selectAllState(draft), [draft]);\n const checklist = useMemo(\n () =>\n filterChecklist(draft, {\n valueLimit: menu.valueLimit,\n blanksLabel: messages.filterBlanks,\n }),\n [draft, menu.valueLimit, messages.filterBlanks],\n );\n\n // A checkbox's mixed state has no attribute, only this property.\n useLayoutEffect(() => {\n if (selectAllRef.current !== null) {\n selectAllRef.current.indeterminate = selectAll === \"mixed\";\n }\n });\n\n // Once the side switched to is drawn.\n useLayoutEffect(() => {\n if (mode.kind === \"condition\") {\n conditionsFocus.current?.focus();\n } else if (mode.focusOnMount) {\n operatorButton.current?.focus();\n }\n }, [mode]);\n\n useImperativeHandle(ref, () => ({\n apply: () => {\n if (mode.kind === \"condition\") {\n return conditions.current?.apply() ?? true;\n }\n if (filterDraftChanged(opened.draft, draft)) {\n applyFilter(\n draftToFilter(draft, column.id, controller.getState().filter),\n );\n }\n return true;\n },\n }));\n\n if (mode.kind === \"condition\") {\n return (\n <>\n <button\n type=\"button\"\n className=\"gridkit-filter-menu-back\"\n onClick={() => {\n setMode({ kind: \"values\", focusOnMount: true });\n }}\n >\n <span className=\"gridkit-filter-menu-back-icon\" aria-hidden=\"true\">\n <ChevronLeftIcon />\n </span>\n {messages.filterBackToValues}\n </button>\n <SimpleFilterEditor\n ref={conditions}\n column={column}\n menu={menu}\n controller={controller}\n messages={messages}\n initialFocusRef={(element) => {\n conditionsFocus.current = element;\n }}\n applyFilter={applyFilter}\n operator={mode.operator}\n />\n </>\n );\n }\n\n const { shape } = opened;\n return (\n <div className=\"gridkit-filter-menu-values\">\n {menu.operators.length > 0 && (\n <OperatorMenuButton\n ref={operatorButton}\n menu={menu}\n active={\n shape.kind === \"conditions\"\n ? shape.conditions.map((condition) => condition.operator)\n : undefined\n }\n messages={messages}\n onChoose={(operator) => {\n setMode({ kind: \"condition\", operator });\n }}\n />\n )}\n {(shape.kind === \"conditions\" || shape.kind === \"custom\") && (\n <p className=\"gridkit-filter-menu-custom\">\n {shape.kind === \"conditions\"\n ? messages.filterByCondition\n : messages.customFilter}\n </p>\n )}\n <input\n ref={initialFocusRef}\n type=\"search\"\n className=\"gridkit-filter-menu-search\"\n aria-label={messages.filterSearchLabel}\n placeholder={messages.searchPlaceholder}\n value={draft.search}\n onChange={(event) => {\n dispatch({ type: \"search\", search: event.currentTarget.value });\n }}\n />\n <label className=\"gridkit-filter-menu-select-all\">\n <input\n ref={selectAllRef}\n type=\"checkbox\"\n checked={selectAll === \"checked\"}\n // Nothing to act on: the search matches no value.\n disabled={!checklist.needsSearch && checklist.items.length === 0}\n onChange={() => {\n dispatch({ type: \"toggleAll\" });\n }}\n />\n {messages.filterSelectAll}\n </label>\n {checklist.needsSearch ? (\n <p className=\"gridkit-filter-menu-search-first\">\n {messages.filterSearchFirst(checklist.total)}\n </p>\n ) : (\n <ValueChecklist\n items={checklist.items}\n showCounts={menu.showCounts}\n label={messages.filterValuesLabel}\n onToggle={(item) => {\n dispatch(toggleOf<Row>(item));\n }}\n />\n )}\n {checklist.hiddenCount > 0 && (\n <p role=\"status\" className=\"gridkit-filter-menu-more\">\n {messages.filterMoreValues(checklist.hiddenCount)}\n </p>\n )}\n </div>\n );\n}\n","import type { FilterState } from \"@gridkitjs/core\";\nimport {\n describeColumnFilter,\n filterDraftChanged,\n filterEditorReducer,\n initialFilterEditorDraft,\n toValuesDraft,\n type ColumnFilterShape,\n type ColumnValueOptions,\n type FilterEditorAction,\n type FilterEditorDraft,\n type ValuesDraft,\n} from \"@gridkitjs/core/renderer\";\n\n/** What an excel editor opened with, read from the column's filter. */\nexport interface OpenedValues<Row> {\n /** The grid's filter it was read from. */\n readonly over: FilterState<Row>;\n readonly shape: ColumnFilterShape<Row>;\n /** On its conditions when the column's filter is conditions. */\n readonly draft: FilterEditorDraft<Row>;\n}\n\n/**\n * An excel editor's state: what it opened with, and the user's checklist.\n * Conditions are the simple editor's, shown in place of the checklist with\n * a state of its own, so the draft here stays on its checklist.\n */\nexport interface ExcelEditorState<Row> {\n readonly opened: OpenedValues<Row>;\n readonly draft: ValuesDraft<Row>;\n}\n\n/** What the checklist does to its draft: any draft action but conditions. */\nexport type ChecklistAction<Row> = Exclude<\n FilterEditorAction<Row>,\n { readonly type: \"setConditions\" }\n>;\n\nexport type ExcelEditorAction<Row> =\n | ChecklistAction<Row>\n /** The grid's filter changed while the editor is open: what it now reads. */\n | { readonly type: \"filterChanged\"; readonly opened: OpenedValues<Row> };\n\n/** What an excel editor opens with over `filter`, listing `values`. */\nexport function openValues<Row>(\n filter: FilterState<Row>,\n columnId: string,\n values: ColumnValueOptions,\n): OpenedValues<Row> {\n const shape = describeColumnFilter(filter, columnId);\n return {\n over: filter,\n shape,\n draft: initialFilterEditorDraft(shape, values),\n };\n}\n\n/** An excel editor's state as it opens on `opened`. */\nexport function initialExcelEditorState<Row>(\n opened: OpenedValues<Row>,\n): ExcelEditorState<Row> {\n return { opened, draft: toValuesDraft(opened.draft) };\n}\n\n/**\n * Whether the editor opens alike on what `a` and `b` read: the same note,\n * the same values listed, checked alike. The list is compared by identity:\n * the grid hands back the same one while nothing it is counted from changes.\n */\nfunction showsAlike<Row>(a: OpenedValues<Row>, b: OpenedValues<Row>): boolean {\n return (\n a.shape.kind === b.shape.kind &&\n a.draft.options === b.draft.options &&\n !filterDraftChanged(a.draft, b.draft)\n );\n}\n\n/**\n * The next state after `action`: the draft as `filterEditorReducer` changes\n * it. A change to the grid's filter that the editor would open on\n * differently starts it again on that, as reopening it would, dropping\n * what was checked; one it would open on alike leaves the draft be.\n */\nexport function excelEditorReducer<Row>(\n state: ExcelEditorState<Row>,\n action: ExcelEditorAction<Row>,\n): ExcelEditorState<Row> {\n if (action.type === \"filterChanged\") {\n return showsAlike(state.opened, action.opened)\n ? { ...state, opened: action.opened }\n : initialExcelEditorState(action.opened);\n }\n // Only narrows the type: a checklist action leaves the draft on its checklist.\n return {\n ...state,\n draft: toValuesDraft(filterEditorReducer(state.draft, action)),\n };\n}\n","import {\n useLayoutEffect,\n useRef,\n useState,\n type KeyboardEvent,\n type MouseEvent,\n type RefObject,\n} from \"react\";\nimport type { AttachedMenu } from \"@gridkitjs/dom\";\nimport {\n ANCHOR_GAP,\n overlayScope,\n type OverlayScope,\n} from \"../overlay/Overlay\";\n\n/** A menu button's menu: closed, or open from the button. */\nexport type MenuButtonState =\n | { readonly kind: \"closed\" }\n | {\n readonly kind: \"open\";\n /** The button, which the menu opens beside and returns focus to. */\n readonly anchor: HTMLElement;\n readonly scope: OverlayScope;\n /** How far from the button the menu opens. */\n readonly gap: number;\n /** The item it opens on: the first, or the last when ArrowUp opened it. */\n readonly focusItem: number;\n };\n\nconst CLOSED: MenuButtonState = { kind: \"closed\" };\n\ninterface UseMenuButtonOptions {\n /** How many items the menu holds, separators aside. */\n itemCount: number;\n /**\n * How far from the button its menu opens, measured as it opens. Defaults\n * to `ANCHOR_GAP`.\n */\n gap?: ((button: HTMLElement) => number) | undefined;\n}\n\nexport interface MenuButtonApi {\n state: MenuButtonState;\n close: () => void;\n /** Spread on the button. */\n buttonProps: {\n \"aria-haspopup\": \"menu\";\n \"aria-expanded\": boolean;\n onClick: (event: MouseEvent<HTMLElement>) => void;\n onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n };\n /** The menu's `behaviourRef`, for moving focus to `focusItem`. */\n behaviourRef: RefObject<AttachedMenu | null>;\n}\n\n/**\n * A button opening a menu, following the WAI-ARIA menu button pattern: a\n * click, Enter, Space or ArrowDown opens the menu with focus on its first\n * item, ArrowUp on its last, and a second click closes it. The caller draws\n * the menu in an `Overlay` while `state` is open, returning focus to its\n * `anchor`.\n */\nexport default function useMenuButton({\n itemCount,\n gap = () => ANCHOR_GAP,\n}: UseMenuButtonOptions): MenuButtonApi {\n const [state, setState] = useState(CLOSED);\n const behaviourRef = useRef<AttachedMenu | null>(null);\n\n // As the menu opens, after the overlay — a child, whose layout effect runs\n // first — has focused the first item.\n useLayoutEffect(() => {\n if (state.kind === \"open\" && state.focusItem > 0) {\n behaviourRef.current?.focusItem(state.focusItem);\n }\n }, [state]);\n\n function open(button: HTMLElement, onLast: boolean): void {\n setState({\n kind: \"open\",\n anchor: button,\n scope: overlayScope(button),\n gap: gap(button),\n focusItem: onLast ? itemCount - 1 : 0,\n });\n }\n\n function close(): void {\n setState(CLOSED);\n }\n\n return {\n state,\n close,\n buttonProps: {\n \"aria-haspopup\": \"menu\",\n \"aria-expanded\": state.kind === \"open\",\n onClick: (event) => {\n if (state.kind === \"closed\") {\n open(event.currentTarget, false);\n } else {\n close();\n }\n },\n onKeyDown: (event) => {\n if (\n (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") &&\n state.kind === \"closed\"\n ) {\n event.preventDefault();\n open(event.currentTarget, event.key === \"ArrowUp\");\n }\n },\n },\n behaviourRef,\n };\n}\n","import type { Ref } from \"react\";\nimport type {\n FilterOperator,\n GridMessages,\n ResolvedMenuItem,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumnFilterMenu } from \"@gridkitjs/core/renderer\";\nimport GridMenu from \"../menu/GridMenu\";\nimport { CheckIcon, ChevronRightIcon } from \"../menu/menuIcons\";\nimport useMenuButton from \"../menu/useMenuButton\";\nimport Overlay, { ANCHOR_GAP } from \"../overlay/Overlay\";\n\ninterface OperatorMenuButtonProps {\n /** The column's filter menu: the operators listed, in its family's words. */\n readonly menu: ResolvedColumnFilterMenu;\n /**\n * The operators the column's conditions use, each checked in the menu — or\n * `undefined` while the column is not filtered by conditions, when no item\n * is checkable.\n */\n readonly active: readonly FilterOperator[] | undefined;\n readonly messages: GridMessages;\n /** An operator was chosen, and the menu has closed. */\n readonly onChoose: (operator: FilterOperator) => void;\n readonly ref: Ref<HTMLButtonElement>;\n}\n\n/**\n * How far from the button's side its menu opens: past the edge of the filter\n * menu the button sits in, by the gap an overlay keeps from what it opens\n * beside — so it opens beside the filter menu rather than over its edge.\n * The filter menu's padding is the same either side, so the gap holds when\n * the menu flips to the left.\n */\nfunction gapBeside(button: HTMLElement): number {\n const dialog = button.closest('[role=\"dialog\"]') ?? button;\n return (\n dialog.getBoundingClientRect().right -\n button.getBoundingClientRect().right +\n ANCHOR_GAP\n );\n}\n\n/**\n * The excel editor's \"Number filters\" button, opening a menu of the\n * conditions the column offers — a `GridMenu` in an overlay of its own,\n * stacked above the filter menu, so Escape closes it alone and a click in\n * it leaves the filter menu open. It is a menu button as `useMenuButton`\n * describes, and closing its menu returns focus to it.\n *\n * While the column is filtered by conditions, its operators are checked in\n * the menu, and the button carries a tick, as Excel's does.\n */\nexport default function OperatorMenuButton({\n menu,\n active,\n messages,\n onChoose,\n ref,\n}: OperatorMenuButtonProps) {\n const { state, close, buttonProps, behaviourRef } = useMenuButton({\n itemCount: menu.operators.length,\n gap: gapBeside,\n });\n const label = messages.filterOperatorMenu(menu.family);\n\n const entries = menu.operators.map((operator): ResolvedMenuItem => ({\n type: \"item\",\n id: operator,\n label: messages.filterOperatorLabel(operator, menu.family),\n disabled: false,\n checked: active?.includes(operator),\n run: () => {\n close();\n onChoose(operator);\n return true;\n },\n }));\n\n return (\n <>\n <button\n ref={ref}\n type=\"button\"\n className=\"gridkit-filter-menu-submenu\"\n {...buttonProps}\n >\n <span className=\"gridkit-filter-menu-submenu-icon\" aria-hidden=\"true\">\n {active !== undefined && <CheckIcon />}\n </span>\n {label}\n <span\n className=\"gridkit-filter-menu-submenu-indicator\"\n aria-hidden=\"true\"\n >\n <ChevronRightIcon />\n </span>\n </button>\n {state.kind === \"open\" && (\n <Overlay\n anchor={state.anchor}\n placement=\"right-start\"\n gap={state.gap}\n returnFocusTo={state.anchor}\n scope={state.scope}\n onDismiss={close}\n >\n <GridMenu\n entries={entries}\n label={label}\n scope={state.scope}\n behaviourRef={behaviourRef}\n onRun={(item) => {\n item.run();\n }}\n onClose={close}\n />\n </Overlay>\n )}\n </>\n );\n}\n","import {\n Fragment,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useReducer,\n useRef,\n} from \"react\";\nimport type {\n FilterOperator,\n GridMessages,\n OperatorFilterEntry,\n} from \"@gridkitjs/core\";\nimport {\n conditionsFromRows,\n draftToFilter,\n filterDraftChanged,\n filterEditorReducer,\n} from \"@gridkitjs/core/renderer\";\nimport ConditionRow from \"./ConditionRow\";\nimport type { FilterEditorProps } from \"./filterEditor\";\nimport {\n initialSimpleEditorState,\n openConditions,\n sameConditionRows,\n simpleEditorReducer,\n type Combinator,\n} from \"./simpleEditorState\";\n\nconst COMBINATORS: readonly Combinator[] = [\"and\", \"or\"];\n\n/**\n * Whether a box in `row` holds what the browser can't read as a number or a\n * date — \"1e\", a date missing its year — which it reports as empty, so the\n * row would otherwise pass for one left blank.\n */\nfunction holdsUnreadable(row: HTMLElement | null | undefined): boolean {\n return Array.from(row?.querySelectorAll(\"input\") ?? []).some(\n (input) => input.validity.badInput,\n );\n}\n\ninterface CombinatorChoiceProps {\n /** The radio buttons' shared `name`, unique to the editor. */\n readonly name: string;\n readonly combinator: Combinator;\n readonly messages: GridMessages;\n readonly onChange: (combinator: Combinator) => void;\n}\n\n/** And or Or, between the two conditions: native radio buttons, one tab stop. */\nfunction CombinatorChoice({\n name,\n combinator,\n messages,\n onChange,\n}: CombinatorChoiceProps) {\n return (\n <div\n role=\"radiogroup\"\n aria-label={messages.filterCombinatorLabel}\n className=\"gridkit-filter-menu-combinator\"\n >\n {COMBINATORS.map((choice) => (\n <label key={choice} className=\"gridkit-filter-menu-combinator-option\">\n <input\n type=\"radio\"\n name={name}\n checked={choice === combinator}\n onChange={() => {\n onChange(choice);\n }}\n />\n {choice === \"and\" ? messages.filterAnd : messages.filterOr}\n </label>\n ))}\n </div>\n );\n}\n\nexport interface SimpleFilterEditorProps<Row> extends FilterEditorProps<Row> {\n /**\n * The operator its first condition starts at, chosen from the excel\n * editor's operator submenu — which shows this editor in place of its\n * checklist. A checklist's values are that editor's to show, so they are\n * not called a custom filter here then.\n */\n readonly operator?: FilterOperator | undefined;\n}\n\n/**\n * A filter menu's simple editor: one condition — an operator and its value —\n * and an optional second, joined to it by and/or. It opens on the column's\n * conditions, read by `@gridkitjs/core`'s `describeColumnFilter` and\n * `conditionRowsFrom`, its first at `operator` when given one. On a filter\n * it cannot show — a checklist's values, or a custom filter — it says so\n * above empty conditions, which replace it once applied.\n *\n * The conditions are text until applied, when `conditionsFromRows` reads\n * them as the column's type filters. A condition missing a value, or holding\n * one that doesn't read, keeps the menu open: its boxes are marked invalid,\n * described by a message, and the first takes focus — unless they are as it\n * opened them, as the empty ones on a column it shows no filter for: OK then\n * closes the menu as Cancel would, rather than asking for a value.\n *\n * Set in code while it is open, the column's filter shows in place of what\n * was typed, as it would on reopening the menu.\n */\nexport default function SimpleFilterEditor<Row>({\n column,\n menu,\n controller,\n messages,\n initialFocusRef,\n applyFilter,\n operator,\n ref,\n}: SimpleFilterEditorProps<Row>) {\n const type = column.column.type;\n const filter = controller.getState().filter;\n const open = (over: typeof filter) =>\n openConditions(over, column.id, menu.operators, type, operator);\n const [{ opened, draft, invalid }, dispatch] = useReducer(\n simpleEditorReducer<Row>,\n filter,\n (over) => initialSimpleEditorState(open(over)),\n );\n // Set in code while the menu is open — `setFilter`, a controlled `filter`.\n if (filter !== opened.over) {\n dispatch({ type: \"filterChanged\", opened: open(filter) });\n }\n const rowElements = useRef<(HTMLDivElement | null)[]>([]);\n const invalidMessageId = useId();\n const combinatorName = useId();\n\n /**\n * Puts `conditions` in place of every entry about the column — unless\n * they are the column's own, so a filter set in code stays as written.\n */\n function applyConditions(\n conditions: readonly OperatorFilterEntry<Row>[],\n ): void {\n const applied = filterEditorReducer(opened.filterDraft, {\n type: \"setConditions\",\n conditions,\n combinator: draft.combinator,\n });\n if (filterDraftChanged(opened.filterDraft, applied)) {\n applyFilter(\n draftToFilter(applied, column.id, controller.getState().filter),\n );\n }\n }\n\n useImperativeHandle(ref, () => ({\n apply: () => {\n const parsed = conditionsFromRows<Row>(draft.rows, column.id, type);\n const unreadable = draft.rows.map((_, index) =>\n holdsUnreadable(rowElements.current[index]),\n );\n const marked = draft.rows.flatMap((_, index) =>\n parsed.invalid.includes(index) || unreadable[index] === true\n ? [index]\n : [],\n );\n if (marked.length === 0) {\n applyConditions(parsed.conditions);\n return true;\n }\n // Nothing typed since it opened: OK closes it, as Cancel would, rather\n // than asking for a value.\n if (\n sameConditionRows(draft, opened.draft) &&\n !unreadable.includes(true)\n ) {\n return true;\n }\n dispatch({ type: \"markInvalid\", rows: marked });\n return false;\n },\n }));\n\n // After the render marking it, so the box is invalid as it takes focus.\n useLayoutEffect(() => {\n const [first] = invalid;\n if (first !== undefined) {\n rowElements.current[first]\n ?.querySelector<HTMLElement>('[aria-invalid=\"true\"]')\n ?.focus();\n }\n }, [invalid]);\n\n return (\n <div className=\"gridkit-filter-menu-conditions\">\n {opened.custom && (\n <p className=\"gridkit-filter-menu-custom\">{messages.customFilter}</p>\n )}\n {draft.rows.map((row, index) => (\n // A row is its place: the first condition, or the second.\n <Fragment key={index}>\n {index > 0 && (\n <CombinatorChoice\n name={combinatorName}\n combinator={draft.combinator}\n messages={messages}\n onChange={(combinator) => {\n dispatch({ type: \"setCombinator\", combinator });\n }}\n />\n )}\n <ConditionRow\n ref={(element) => {\n rowElements.current[index] = element;\n }}\n row={row}\n position={index + 1}\n menu={menu}\n type={type}\n messages={messages}\n invalidMessageId={\n invalid.includes(index) ? invalidMessageId : undefined\n }\n focusRef={index === 0 ? initialFocusRef : undefined}\n onChange={(next) => {\n dispatch({ type: \"editRow\", index, row: next });\n }}\n />\n </Fragment>\n ))}\n {invalid.length > 0 && (\n <p id={invalidMessageId} className=\"gridkit-filter-menu-invalid\">\n {messages.filterValueInvalid(menu.family)}\n </p>\n )}\n </div>\n );\n}\n","import type { ChangeEvent, Ref, RefCallback } from \"react\";\nimport type {\n ColumnType,\n FilterOperatorFamily,\n GridMessages,\n} from \"@gridkitjs/core\";\nimport {\n filterOperandArity,\n parseFilterOperand,\n type ConditionRowDraft,\n type ResolvedColumnFilterMenu,\n} from \"@gridkitjs/core/renderer\";\n\n/**\n * The input a column of `type` takes an operand in, each writing what\n * `@gridkitjs/core`'s `parseFilterOperand` reads: a day for a date column, a\n * day and a time for a date-time or time one.\n */\nfunction inputType(\n family: Exclude<FilterOperatorFamily, \"boolean\">,\n type: ColumnType | undefined,\n): \"text\" | \"number\" | \"date\" | \"datetime-local\" {\n switch (family) {\n case \"text\":\n return \"text\";\n case \"number\":\n return \"number\";\n case \"date\":\n return type === \"date\" ? \"date\" : \"datetime-local\";\n }\n}\n\ninterface OperandFieldProps {\n readonly family: FilterOperatorFamily;\n readonly type: ColumnType | undefined;\n readonly text: string;\n /** Its accessible name: \"Value\", or a `between`'s \"From\" or \"To\". */\n readonly label: string;\n /** The id of the message describing it while it is invalid. */\n readonly invalidMessageId: string | undefined;\n readonly fieldRef: RefCallback<HTMLElement> | undefined;\n readonly messages: GridMessages;\n readonly onChange: (text: string) => void;\n}\n\n/** One operand's box — a true/false choice on a boolean column. */\nfunction OperandField({\n family,\n type,\n text,\n label,\n invalidMessageId,\n fieldRef,\n messages,\n onChange,\n}: OperandFieldProps) {\n const field = {\n ref: fieldRef,\n className: \"gridkit-filter-menu-value\",\n \"aria-label\": label,\n \"aria-invalid\": invalidMessageId === undefined ? undefined : true,\n \"aria-describedby\": invalidMessageId,\n value: text,\n onChange: (event: ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {\n onChange(event.currentTarget.value);\n },\n };\n if (family === \"boolean\") {\n // Empty to start with, as a text box is, so a second condition left\n // alone is dropped rather than applied as \"Equals true\".\n return (\n <select {...field}>\n <option value=\"\" />\n <option value=\"true\">{messages.booleanTrue}</option>\n <option value=\"false\">{messages.booleanFalse}</option>\n </select>\n );\n }\n return <input {...field} type={inputType(family, type)} />;\n}\n\ninterface ConditionRowProps {\n readonly row: ConditionRowDraft;\n /** Its place among the editor's conditions, from one — what names it. */\n readonly position: number;\n readonly menu: ResolvedColumnFilterMenu;\n readonly type: ColumnType | undefined;\n readonly messages: GridMessages;\n /**\n * The id of the message saying its value is missing or doesn't read, while\n * it is marked so: each box whose text doesn't read is then invalid, and\n * described by it.\n */\n readonly invalidMessageId: string | undefined;\n /**\n * The `ref` of the control focus starts on: its first box, or its operator\n * picker when its operator takes no operand.\n */\n readonly focusRef: RefCallback<HTMLElement> | undefined;\n readonly onChange: (row: ConditionRowDraft) => void;\n readonly ref: Ref<HTMLDivElement>;\n}\n\n/**\n * One condition of a filter menu's editor, as typed: an operator picker,\n * then a box for each operand its operator takes — none for the blanks\n * operators, two for `between`'s ends.\n */\nexport default function ConditionRow({\n row,\n position,\n menu,\n type,\n messages,\n invalidMessageId,\n focusRef,\n onChange,\n ref,\n}: ConditionRowProps) {\n const arity = filterOperandArity(row.operator);\n // A condition set in code can use an operator the column doesn't offer; it\n // is listed too, so the row shows the condition as it is.\n const operators = menu.operators.includes(row.operator)\n ? menu.operators\n : [row.operator, ...menu.operators];\n const operand = { family: menu.family, type, messages };\n\n /**\n * The message id for a box holding `text`, while the row is marked: on the\n * box that is empty or doesn't read — a `between`'s missing end, not the\n * one filled in.\n */\n function messageIdFor(text: string): string | undefined {\n return parseFilterOperand(text, type) === undefined\n ? invalidMessageId\n : undefined;\n }\n\n return (\n <div\n ref={ref}\n role=\"group\"\n aria-label={messages.filterConditionLabel(position)}\n className=\"gridkit-filter-menu-condition\"\n >\n <select\n ref={arity === 0 ? focusRef : undefined}\n className=\"gridkit-filter-menu-operator\"\n aria-label={messages.filterOperatorFieldLabel}\n value={row.operator}\n onChange={(event) => {\n const operator = operators[event.currentTarget.selectedIndex];\n if (operator !== undefined) {\n onChange({ ...row, operator });\n }\n }}\n >\n {operators.map((operator) => (\n <option key={operator} value={operator}>\n {messages.filterOperatorLabel(operator, menu.family)}\n </option>\n ))}\n </select>\n {arity > 0 && (\n <OperandField\n {...operand}\n text={row.text}\n label={\n arity === 2 ? messages.filterFromLabel : messages.filterValueLabel\n }\n invalidMessageId={messageIdFor(row.text)}\n fieldRef={focusRef}\n onChange={(text) => {\n onChange({ ...row, text });\n }}\n />\n )}\n {arity === 2 && (\n <OperandField\n {...operand}\n text={row.textTo}\n label={messages.filterToLabel}\n invalidMessageId={messageIdFor(row.textTo)}\n fieldRef={undefined}\n onChange={(textTo) => {\n onChange({ ...row, textTo });\n }}\n />\n )}\n </div>\n );\n}\n","import type { ColumnType, FilterOperator, FilterState } from \"@gridkitjs/core\";\nimport {\n conditionRowsFrom,\n conditionsFromRows,\n describeColumnFilter,\n initialFilterEditorDraft,\n type ColumnFilterShape,\n type ColumnValueOptions,\n type ConditionRowDraft,\n type FilterEditorDraft,\n} from \"@gridkitjs/core/renderer\";\n\nexport type Combinator = \"and\" | \"or\";\n\n/** The conditions as typed, and how they join. */\nexport interface ConditionRowsDraft {\n readonly rows: readonly ConditionRowDraft[];\n readonly combinator: Combinator;\n}\n\n/** What a simple editor opened with, read from the column's filter. */\nexport interface OpenedConditions<Row> {\n /** The grid's filter it was read from. */\n readonly over: FilterState<Row>;\n /** Whether the editor can't show the column's filter: \"Custom filter\". */\n readonly custom: boolean;\n /** The boxes as they opened. */\n readonly draft: ConditionRowsDraft;\n /** The column's filter as a draft, for `filterDraftChanged`. */\n readonly filterDraft: FilterEditorDraft<Row>;\n}\n\n/** A simple editor's state: the draft, and what its last OK marked. */\nexport interface SimpleEditorState<Row> {\n readonly opened: OpenedConditions<Row>;\n readonly draft: ConditionRowsDraft;\n /** The rows the last OK marked invalid, until the draft next changes. */\n readonly invalid: readonly number[];\n}\n\nexport type SimpleEditorAction<Row> =\n | {\n readonly type: \"editRow\";\n readonly index: number;\n readonly row: ConditionRowDraft;\n }\n | { readonly type: \"setCombinator\"; readonly combinator: Combinator }\n | { readonly type: \"markInvalid\"; readonly rows: readonly number[] }\n /** The grid's filter changed while the editor is open: what it now reads. */\n | { readonly type: \"filterChanged\"; readonly opened: OpenedConditions<Row> };\n\n/** No condition marked invalid. */\nconst NO_ROWS: readonly number[] = [];\n\n/**\n * The values the column's filter is drafted over: the simple editor has no\n * checklist, so none.\n */\nconst NO_VALUES: ColumnValueOptions = {\n options: [],\n total: 0,\n truncated: false,\n blanks: 0,\n};\n\n/**\n * The draft standing for the column's filter `shape`, for\n * `filterDraftChanged` to tell an apply that changes nothing. Its conditions\n * are read back from the boxes showing them, `rows`, as the conditions\n * applied will be: a date set in code as a string, or a time to the second,\n * then compares equal to the day or minute its box shows.\n */\nfunction filterDraftShown<Row>(\n shape: ColumnFilterShape<Row>,\n rows: readonly ConditionRowDraft[],\n columnId: string,\n type: ColumnType | undefined,\n): FilterEditorDraft<Row> {\n const draft = initialFilterEditorDraft(shape, {\n ...NO_VALUES,\n columnType: type,\n });\n if (draft.kind !== \"conditions\") {\n return draft;\n }\n const shown = conditionsFromRows<Row>(rows, columnId, type);\n return shown.invalid.length > 0\n ? draft\n : { ...draft, conditions: shown.conditions };\n}\n\n/**\n * What a simple editor opens with over `filter`: the column's conditions,\n * the first at `operator` when given one, chosen from the excel editor's\n * operator menu. A checklist's values are that editor's to show, so with an\n * operator they are not called a custom filter.\n */\nexport function openConditions<Row>(\n filter: FilterState<Row>,\n columnId: string,\n operators: readonly FilterOperator[],\n type: ColumnType | undefined,\n operator: FilterOperator | undefined,\n): OpenedConditions<Row> {\n const shape = describeColumnFilter(filter, columnId);\n const rows = conditionRowsFrom(shape, operators, type);\n return {\n over: filter,\n custom:\n shape.kind === \"custom\" ||\n (shape.kind === \"values\" && operator === undefined),\n draft: {\n // Its typed values kept, as picking the operator in the row keeps them.\n rows:\n operator === undefined\n ? rows\n : rows.map((row, index) =>\n index === 0 ? { ...row, operator } : row,\n ),\n combinator: shape.kind === \"conditions\" ? shape.combinator : \"and\",\n },\n filterDraft: filterDraftShown(shape, rows, columnId, type),\n };\n}\n\n/** A simple editor's state as it opens on `opened`. */\nexport function initialSimpleEditorState<Row>(\n opened: OpenedConditions<Row>,\n): SimpleEditorState<Row> {\n return { opened, draft: opened.draft, invalid: NO_ROWS };\n}\n\n/** Whether two drafts hold the same text in every box, joined alike. */\nexport function sameConditionRows(\n a: ConditionRowsDraft,\n b: ConditionRowsDraft,\n): boolean {\n return (\n a.combinator === b.combinator &&\n a.rows.length === b.rows.length &&\n a.rows.every((row, index) => {\n const other = b.rows[index];\n return (\n other !== undefined &&\n row.operator === other.operator &&\n row.text === other.text &&\n row.textTo === other.textTo\n );\n })\n );\n}\n\n/** Whether the editor opens alike on what `a` and `b` read. */\nfunction showsAlike<Row>(\n a: OpenedConditions<Row>,\n b: OpenedConditions<Row>,\n): boolean {\n return a.custom === b.custom && sameConditionRows(a.draft, b.draft);\n}\n\n/**\n * The next state after `action`. An edit clears what OK marked. A change to\n * the grid's filter that the editor would open on differently starts it\n * again on that, as reopening it would, dropping what was typed; one it\n * would open on alike, such as another column's, leaves the draft be.\n */\nexport function simpleEditorReducer<Row>(\n state: SimpleEditorState<Row>,\n action: SimpleEditorAction<Row>,\n): SimpleEditorState<Row> {\n switch (action.type) {\n case \"editRow\":\n return {\n ...state,\n draft: {\n ...state.draft,\n rows: state.draft.rows.map((row, index) =>\n index === action.index ? action.row : row,\n ),\n },\n invalid: NO_ROWS,\n };\n case \"setCombinator\":\n return {\n ...state,\n draft: { ...state.draft, combinator: action.combinator },\n invalid: NO_ROWS,\n };\n case \"markInvalid\":\n return { ...state, invalid: action.rows };\n case \"filterChanged\":\n return showsAlike(state.opened, action.opened)\n ? { ...state, opened: action.opened }\n : initialSimpleEditorState(action.opened);\n }\n}\n","import { useLayoutEffect, useRef, useState } from \"react\";\nimport type {\n FilterChecklistItem,\n VisibleRange,\n} from \"@gridkitjs/core/renderer\";\nimport {\n attachChecklist,\n createRowVirtualizer,\n type AttachedChecklist,\n type RowVirtualizer,\n} from \"@gridkitjs/dom\";\nimport { CheckIcon } from \"../menu/menuIcons\";\n\n/**\n * The height assumed for an item not yet measured: the theme's, a line of\n * text and its padding. Every mounted item is measured, so it only places\n * those scrolled past.\n */\nconst ESTIMATED_ITEM_HEIGHT = 28;\n\n/** Items mounted beyond each edge of the list's visible part. */\nconst OVERSCAN = 4;\n\nconst NO_RANGE: VisibleRange = {\n startIndex: 0,\n endIndex: -1,\n offsetBefore: 0,\n offsetAfter: 0,\n};\n\ninterface ValueChecklistProps {\n /** Every item of the list, in order — only a window of them is mounted. */\n readonly items: readonly FilterChecklistItem[];\n readonly showCounts: boolean;\n /** The list's accessible name. */\n readonly label: string;\n /** An item asks to be checked or unchecked: Space on it, or a click. */\n readonly onToggle: (item: FilterChecklistItem) => void;\n}\n\n/**\n * A filter checklist's values: a `role=\"listbox\"` with one tab stop, each\n * value an option whose `aria-checked` says whether the filter keeps it.\n * A column can hold thousands of values, so the list is windowed by\n * `@gridkitjs/dom`'s `createRowVirtualizer` — the list is its own scroll\n * element, holding only the items near its scroll position between two\n * spacers — and made to behave by `attachChecklist`, which moves focus by\n * the arrow keys, Home, End, PageUp and PageDown and reports Space or a\n * click on an item by its place in the whole list.\n *\n * An item's key holds characters no DOM attribute may, so it keys React's\n * list only; the DOM knows an item by its place, `aria-posinset` one past it.\n */\nexport default function ValueChecklist({\n items,\n showCounts,\n label,\n onToggle,\n}: ValueChecklistProps) {\n const listRef = useRef<HTMLDivElement>(null);\n const checklistRef = useRef<AttachedChecklist | null>(null);\n const [virtualizer, setVirtualizer] = useState<RowVirtualizer | null>(null);\n const [range, setRange] = useState(NO_RANGE);\n\n /**\n * What the behaviour's callbacks read. They are handed over once, when it\n * attaches, so they read the props of the latest render here.\n */\n const latest = useRef({ items, onToggle });\n useLayoutEffect(() => {\n latest.current = { items, onToggle };\n });\n\n useLayoutEffect(() => {\n const list = listRef.current;\n if (list === null) {\n return undefined;\n }\n const rows = createRowVirtualizer(list, {\n estimatedRowHeight: ESTIMATED_ITEM_HEIGHT,\n overscan: OVERSCAN,\n onRange: setRange,\n });\n const checklist = attachChecklist(list, {\n onToggle: (index) => {\n const item = latest.current.items[index];\n if (item !== undefined) {\n latest.current.onToggle(item);\n }\n },\n scrollToIndex: (index) => {\n rows.scrollToIndex(index, { block: \"nearest\" });\n },\n });\n checklistRef.current = checklist;\n setVirtualizer(rows);\n return () => {\n checklistRef.current = null;\n checklist.detach();\n rows.destroy();\n };\n }, []);\n\n useLayoutEffect(() => {\n virtualizer?.setRowCount(items.length);\n checklistRef.current?.setCount(items.length);\n }, [virtualizer, items.length]);\n\n const shown = items.slice(range.startIndex, range.endIndex + 1);\n\n return (\n <div\n ref={listRef}\n role=\"listbox\"\n aria-multiselectable=\"true\"\n aria-label={label}\n className=\"gridkit-filter-menu-checklist\"\n >\n <div role=\"presentation\" style={{ height: range.offsetBefore }} />\n {shown.map((item, offset) => {\n const index = range.startIndex + offset;\n return (\n <div\n key={item.key}\n ref={virtualizer?.measureRow(index)}\n role=\"option\"\n data-gridkit-checklist-item=\"\"\n data-gridkit-checklist-index={index}\n aria-checked={item.checked}\n aria-setsize={items.length}\n aria-posinset={index + 1}\n className=\"gridkit-filter-menu-option\"\n >\n <span\n className=\"gridkit-filter-menu-option-check\"\n aria-hidden=\"true\"\n >\n <CheckIcon />\n </span>\n <span className=\"gridkit-filter-menu-option-label\">\n {item.label}\n </span>\n {/* Spaced, so the option's name reads \"Alice 3\", not \"Alice3\". */}\n {showCounts && (\n <>\n {\" \"}\n <span className=\"gridkit-filter-menu-option-count\">\n {String(item.count)}\n </span>\n </>\n )}\n </div>\n );\n })}\n <div role=\"presentation\" style={{ height: range.offsetAfter }} />\n </div>\n );\n}\n","import { useEffect, useState } from \"react\";\n\n/** An announcement of a change, waiting for the render that draws it. */\nexport interface DrawnAnnouncement {\n /** Whether the grid holds the change, which a controlled one may not. */\n readonly drawn: () => boolean;\n /** Its text, read once the rows are drawn, so the counts are theirs. */\n readonly text: () => string;\n}\n\n/**\n * Announces a change once the grid has drawn it. The returned function\n * takes the announcement as the change is asked for; the render that\n * follows announces it if the grid then holds the change, and drops it if\n * not — a controlled grid that didn't take it — so it never fires at a\n * later render that happens to hold the same thing.\n */\nexport default function useAnnounceWhenDrawn(\n announce: (text: string) => void,\n): (requested: DrawnAnnouncement) => void {\n const [requested, setRequested] = useState<DrawnAnnouncement | null>(null);\n\n useEffect(() => {\n if (requested?.drawn() === true) {\n announce(requested.text());\n }\n }, [requested, announce]);\n\n return setRequested;\n}\n","import type { FilterState, GridMessages } from \"@gridkitjs/core\";\nimport useAnnounceWhenDrawn from \"../useAnnounceWhenDrawn\";\nimport type { DataGridController } from \"../useGridController\";\n\n/**\n * How a filter menu applies a filter: it becomes the grid's filter, and once\n * the grid has drawn the rows it keeps, how many they are of all the rows is\n * announced — `filterResults`, \"3 of 10 rows\". Held by the panel host, which\n * outlives the menu: the menu closes as it applies, before the rows are\n * drawn.\n */\nexport default function useApplyFilter<Row>(\n controller: DataGridController<Row>,\n messages: GridMessages,\n announce: (text: string) => void,\n): (filter: FilterState<Row>) => void {\n const announceWhenDrawn = useAnnounceWhenDrawn(announce);\n\n return (filter) => {\n announceWhenDrawn({\n drawn: () => controller.getState().filter === filter,\n text: () =>\n messages.filterResults(\n controller.getView().rows.length,\n controller.getOptions().dataSource?.length ?? 0,\n ),\n });\n controller.setFilter(filter);\n };\n}\n","import { useState } from \"react\";\nimport type { GridMessages } from \"@gridkitjs/core\";\nimport {\n createColumnValueOptionsCache,\n type ColumnValueOptions,\n} from \"@gridkitjs/core/renderer\";\nimport type { DataGridController } from \"../useGridController\";\n\n/** Rows to count before the grid has any: one array, so the cache keeps its lists. */\nconst NO_ROWS: readonly never[] = [];\n\n/**\n * The values a column's filter checklist lists, counted over the rows the\n * other columns' filters keep. Held by the panel host for the grid's whole\n * life, so reopening a column's checklist hands back the list it counted\n * last time rather than counting every row again — until the rows, the\n * columns, the locale, `messages` or another column's filter change.\n *\n * `messages` is the grid's own resolved object, which keeps its identity\n * while the `messages` prop does: the cache compares it by identity.\n */\nexport default function useFilterValueCache<Row>(\n controller: DataGridController<Row>,\n messages: GridMessages,\n): (columnId: string) => ColumnValueOptions {\n const [cache] = useState(createColumnValueOptionsCache<Row>);\n\n return (columnId) => {\n const { dataSource = NO_ROWS, locale } = controller.getOptions();\n return cache.get(\n dataSource,\n controller.getView().dataColumns,\n controller.getState().filter,\n columnId,\n locale === undefined ? { messages } : { locale, messages },\n );\n };\n}\n","import { resolveColumnFilterMenu } from \"@gridkitjs/core/renderer\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridPanelsApi } from \"./useGridPanels\";\n\n/** What `DataGridApi` carries for the grid's panels. */\nexport interface GridPanelApi {\n /**\n * Opens the column chooser at the grid's top-end corner, in place of any\n * panel or context menu open; it gives focus back to what had it when it\n * closes.\n */\n openColumnChooser(): void;\n /**\n * Opens the filter menu of the column `columnId` below its header, in\n * place of any panel or context menu open, and says whether it opened:\n * not for a column with no filter menu, nor one not shown. It gives focus\n * back to the header when it closes.\n */\n openFilterMenu(columnId: string): boolean;\n /** Closes the filter menu, if one is open, leaving any other panel open. */\n closeFilterMenu(): void;\n}\n\n/** `DataGridApi`'s panel methods, over the grid as it is when called. */\nexport function panelApi<Row>(\n panels: GridPanelsApi,\n controller: DataGridController<Row>,\n): GridPanelApi {\n return {\n openColumnChooser: () => {\n panels.open(\"columnChooser\", { area: \"grid\" });\n },\n openFilterMenu: (columnId) => {\n const shown = controller\n .getView()\n .columns.find((entry) => entry.id === columnId);\n if (\n shown === undefined ||\n resolveColumnFilterMenu(controller.getOptions(), shown.column) === null\n ) {\n return false;\n }\n panels.open(\"filter\", { area: \"header\", columnId });\n return true;\n },\n closeFilterMenu: () => {\n if (panels.current()?.kind === \"filter\") {\n panels.close();\n }\n },\n };\n}\n","import { useRef, type RefObject } from \"react\";\nimport type { GridCommandTarget, GridPanelKind } from \"@gridkitjs/core\";\nimport {\n writingDirection,\n type OverlayAnchor,\n type OverlayPlacement,\n} from \"@gridkitjs/dom\";\nimport { overlayScope, type OverlayScope } from \"../overlay/Overlay\";\nimport type {\n GridOverlayApi,\n GridOverlayState,\n} from \"../overlay/useGridOverlay\";\n\ninterface UseGridPanelsOptions {\n /** The grid's root element, holding the toolbar; a panel asked for from nowhere opens at its corner. */\n rootRef: RefObject<HTMLElement | null>;\n headerTableRef: RefObject<HTMLTableElement | null>;\n /** The grid's one open overlay, the panels among them. */\n overlay: GridOverlayApi;\n}\n\n/** The panel open now. */\nexport interface OpenPanel {\n /** Counts the openings, so one opened over another replaces it. */\n readonly key: number;\n readonly kind: GridPanelKind;\n /** Where it was asked for. */\n readonly target: GridCommandTarget;\n readonly anchor: OverlayAnchor;\n readonly placement: OverlayPlacement;\n /**\n * What gets focus back when it closes: the toolbar button or the header it\n * opened from, or, for `undefined`, whatever had focus as it opened.\n */\n readonly returnFocusTo: HTMLElement | undefined;\n readonly scope: OverlayScope;\n}\n\nexport interface GridPanelsApi {\n /** The panel as the last render drew it. */\n panel: OpenPanel | null;\n /**\n * The panel open as of the last change, ahead of the render that draws it:\n * what a call acting on the open panel reads.\n */\n current: () => OpenPanel | null;\n /**\n * Opens the panel `kind` beside where `target` names, in place of any\n * panel or context menu open.\n */\n open: (kind: GridPanelKind, target: GridCommandTarget) => void;\n /** Closes the panel open, if any, and leaves a context menu open. */\n close: () => void;\n /** See `GridOverlayApi`. */\n returnFocusFallback: () => HTMLElement | null;\n}\n\n/** The element of the root's own toolbar whose `data-gridkit-toolbar-item` is `itemId`. */\nfunction toolbarItem(root: HTMLElement, itemId: string): HTMLElement | null {\n const items = root.querySelectorAll<HTMLElement>(\n \":scope > .gridkit-toolbar > [data-gridkit-toolbar-item]\",\n );\n return (\n Array.from(items).find(\n (item) => item.getAttribute(\"data-gridkit-toolbar-item\") === itemId,\n ) ??\n // In \"More\" while the toolbar is narrow: the button it is chosen from.\n Array.from(items).find((item) =>\n item.hasAttribute(\"data-gridkit-toolbar-more\"),\n ) ??\n null\n );\n}\n\nfunction panelOf(overlay: GridOverlayState): OpenPanel | null {\n return overlay.kind === \"panel\" ? overlay.panel : null;\n}\n\nfunction headerCell(\n headerTable: HTMLTableElement | null,\n columnId: string,\n): HTMLTableCellElement | null {\n const cells = headerTable?.tHead?.rows[0]?.cells;\n return cells === undefined\n ? null\n : (Array.from(cells).find(\n (cell) => cell.getAttribute(\"data-gridkit-column\") === columnId,\n ) ?? null);\n}\n\n/**\n * The grid's panels — the column chooser and a column's filter menu —\n * opened through the command host's `openPanel` as the grid's one overlay\n * (see `useGridOverlay`), so opening one closes a context menu. A panel\n * opens beside where it was asked for: below the toolbar button, below the\n * column header, or at the grid's top-end corner for a call from nowhere in\n * particular, as the ref's is.\n *\n * Opened from a menu, it opens as the menu closes, in the same render: the\n * menu hands focus back to where it was opened from, and the panel takes it\n * from there — and gives it back there when it closes.\n */\nexport default function useGridPanels({\n rootRef,\n headerTableRef,\n overlay,\n}: UseGridPanelsOptions): GridPanelsApi {\n const openings = useRef(0);\n\n function placeFor(\n root: HTMLElement,\n target: GridCommandTarget,\n ): Pick<OpenPanel, \"anchor\" | \"placement\" | \"returnFocusTo\"> {\n const element =\n target.area === \"toolbar\"\n ? toolbarItem(root, target.itemId)\n : target.area === \"header\"\n ? headerCell(headerTableRef.current, target.columnId)\n : null;\n if (element !== null) {\n return {\n anchor: element,\n // The toolbar's own button sits at its far end.\n placement: target.area === \"toolbar\" ? \"bottom-end\" : \"bottom-start\",\n returnFocusTo: element,\n };\n }\n // The grid's top corner at the inline end: its right, or its left under\n // `dir=\"rtl\"`, where the overlay mirrors `bottom-end` to match.\n const { left, right, top } = root.getBoundingClientRect();\n return {\n anchor: { x: writingDirection(root) === \"rtl\" ? left : right, y: top },\n placement: \"bottom-end\",\n returnFocusTo: undefined,\n };\n }\n\n return {\n panel: panelOf(overlay.drawn),\n current: () => panelOf(overlay.current()),\n open: (kind, target) => {\n const root = rootRef.current;\n if (root === null) {\n return;\n }\n openings.current += 1;\n overlay.open({\n kind: \"panel\",\n panel: {\n key: openings.current,\n kind,\n target,\n ...placeFor(root, target),\n scope: overlayScope(root),\n },\n });\n },\n close: () => {\n overlay.close(\"panel\");\n },\n returnFocusFallback: overlay.returnFocusFallback,\n };\n}\n","import { useLayoutEffect, useRef, type ReactNode } from \"react\";\nimport {\n resolveToolbar,\n toolbarEntries,\n type GridMessages,\n type GridOptions,\n type GridToolbarOptions,\n type ResolvedMenuEntry,\n type ResolvedToolbarItem,\n type ToolbarEntry,\n} from \"@gridkitjs/core\";\nimport { splitToolbarItems } from \"@gridkitjs/core/renderer\";\nimport { attachToolbar } from \"@gridkitjs/dom\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport { MenuIcon } from \"../menu/menuIcons\";\nimport type { DataGridController } from \"../useGridController\";\nimport ToolbarMenuButton from \"./ToolbarMenuButton\";\nimport ToolbarSearch from \"./ToolbarSearch\";\nimport useToolbarOverflow from \"./useToolbarOverflow\";\n\ninterface GridToolbarProps<Row> {\n toolbar: GridOptions<Row>[\"toolbar\"];\n /** Fills a custom entry, by its id. */\n renderItem: ((id: string) => ReactNode) | undefined;\n /** The id of the grid element the toolbar acts on. */\n gridId: string;\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/** `run`, also telling `onCommand` through `report` whenever it runs. */\nfunction reporting(run: () => boolean, report: () => void): () => boolean {\n return () => {\n const ran = run();\n if (ran) {\n report();\n }\n return ran;\n };\n}\n\n/** A menu's entries, each item reporting through `report` with its id when it runs. */\nfunction reportingEntries(\n entries: readonly ResolvedMenuEntry[],\n report: (commandId: string) => void,\n): readonly ResolvedMenuEntry[] {\n return entries.map((entry) => {\n switch (entry.type) {\n case \"item\":\n return {\n ...entry,\n run: reporting(entry.run, () => {\n report(entry.id);\n }),\n };\n case \"submenu\":\n return { ...entry, items: reportingEntries(entry.items, report) };\n default:\n return entry;\n }\n });\n}\n\n/**\n * A toolbar item whose `run` — or, for a dropdown, whose items' `run` —\n * also reports to `onCommand` as asked from that item, wherever it ends up\n * drawn: as itself, or in \"More\".\n */\nfunction reportingItem(\n item: ResolvedToolbarItem,\n report: (commandId: string, itemId: string) => void,\n): ResolvedToolbarItem {\n switch (item.type) {\n case \"button\":\n return {\n ...item,\n run: reporting(item.run, () => {\n report(item.id, item.id);\n }),\n };\n case \"menu\":\n return {\n ...item,\n items: reportingEntries(item.items, (commandId) => {\n report(commandId, item.id);\n }),\n };\n default:\n return item;\n }\n}\n\n/**\n * The grid's toolbar, when its `toolbar` option lists anything: the entries\n * resolved by `@gridkitjs/core`'s `resolveToolbar` and drawn as a\n * `role=\"toolbar\"`, which `@gridkitjs/dom`'s `attachToolbar` makes one tab\n * stop the arrow keys move within. Which item shows, is enabled, pressed or\n * does what is core's; this draws them, and resolves them again on every\n * render, so they follow the grid's state.\n *\n * What does not fit moves into a \"More\" menu at the end, as\n * `@gridkitjs/dom`'s `observeToolbarOverflow` measures it and core's\n * `splitToolbarItems` turns it into menu entries: a toggle a checkable item,\n * a dropdown a submenu. The search box and custom entries always stay.\n */\nexport default function GridToolbar<Row>(props: GridToolbarProps<Row>) {\n const entries = toolbarEntries(props.toolbar);\n if (entries.length === 0) {\n return null;\n }\n const options = typeof props.toolbar === \"object\" ? props.toolbar : undefined;\n return (\n <Toolbar\n {...props}\n entries={entries}\n label={options?.label ?? props.messages.toolbarLabel}\n itemAttributes={options?.itemAttributes}\n />\n );\n}\n\nfunction Toolbar<Row>({\n entries,\n label,\n itemAttributes,\n renderItem,\n gridId,\n controller,\n commands,\n messages,\n announce,\n}: GridToolbarProps<Row> & {\n entries: readonly ToolbarEntry<Row>[];\n label: string;\n itemAttributes: GridToolbarOptions<Row>[\"itemAttributes\"];\n}) {\n const toolbarRef = useRef<HTMLDivElement>(null);\n\n const items = resolveToolbar(entries, {\n commands: commands.commands,\n contextFor: commands.contextFor,\n itemAttributes,\n }).map((item) =>\n reportingItem(item, (commandId, itemId) => {\n commands.report(commandId, { area: \"toolbar\", itemId }, \"toolbar\");\n }),\n );\n const fit = useToolbarOverflow(toolbarRef, items);\n const { shown, overflow } = splitToolbarItems(items, fit);\n\n useLayoutEffect(() => {\n const toolbar = toolbarRef.current;\n return toolbar === null ? undefined : attachToolbar(toolbar);\n }, []);\n\n /**\n * Where a menu's focus comes back to when its button has gone: a dropdown\n * whose items all hid, or \"More\" as the toolbar widens with its menu open.\n */\n function toolbarTabStop(): HTMLElement | null {\n const toolbar = toolbarRef.current;\n return (\n toolbar?.querySelector<HTMLElement>('[tabindex=\"0\"]') ??\n toolbar?.querySelector<HTMLElement>(\"button, input\") ??\n null\n );\n }\n\n function draw(item: ResolvedToolbarItem): ReactNode {\n switch (item.type) {\n case \"button\":\n return (\n <button\n key={item.key}\n {...item.attributes}\n type=\"button\"\n className=\"gridkit-toolbar-button\"\n data-gridkit-toolbar-item={item.key}\n {...ariaAttr(item.disabled, \"aria-disabled\", true)}\n {...ariaAttr(\n item.pressed !== undefined,\n \"aria-pressed\",\n item.pressed,\n )}\n {...ariaAttr(\n item.shortcut !== undefined,\n \"aria-keyshortcuts\",\n item.shortcut,\n )}\n onClick={() => {\n item.run();\n }}\n >\n {item.icon !== undefined && (\n <span className=\"gridkit-toolbar-button-icon\" aria-hidden=\"true\">\n <MenuIcon name={item.icon} />\n </span>\n )}\n {item.label}\n </button>\n );\n case \"menu\":\n return (\n <ToolbarMenuButton\n key={item.key}\n itemKey={item.key}\n attributes={item.attributes}\n label={item.label}\n icon={item.icon}\n entries={item.items}\n returnFocusFallback={toolbarTabStop}\n />\n );\n case \"search\":\n return (\n <ToolbarSearch<Row>\n key={item.key}\n itemKey={item.key}\n attributes={item.attributes}\n controller={controller}\n messages={messages}\n announce={announce}\n />\n );\n case \"separator\":\n return (\n <div\n key={item.key}\n role=\"separator\"\n aria-orientation=\"vertical\"\n className=\"gridkit-toolbar-separator\"\n data-gridkit-toolbar-item={item.key}\n />\n );\n case \"spacer\":\n return (\n <div\n key={item.key}\n className=\"gridkit-toolbar-spacer\"\n data-gridkit-toolbar-item={item.key}\n />\n );\n case \"custom\":\n return (\n <div\n key={item.key}\n {...item.attributes}\n className=\"gridkit-toolbar-custom\"\n data-gridkit-toolbar-item={item.key}\n >\n {renderItem?.(item.id)}\n </div>\n );\n }\n }\n\n return (\n <div\n ref={toolbarRef}\n role=\"toolbar\"\n aria-label={label}\n aria-controls={gridId}\n className=\"gridkit-toolbar\"\n >\n {shown.map(draw)}\n {overflow.length > 0 && (\n <ToolbarMenuButton\n itemKey=\"more\"\n label={messages.moreToolbarItems}\n entries={overflow}\n more\n returnFocusFallback={toolbarTabStop}\n />\n )}\n </div>\n );\n}\n","import type { ResolvedMenuEntry, ToolbarItemAttributes } from \"@gridkitjs/core\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport GridMenu from \"../menu/GridMenu\";\nimport { ChevronDownIcon, MenuIcon } from \"../menu/menuIcons\";\nimport useMenuButton from \"../menu/useMenuButton\";\nimport Overlay from \"../overlay/Overlay\";\n\ninterface ToolbarMenuButtonProps {\n /** Its `data-gridkit-toolbar-item`. */\n itemKey: string;\n /** The app's attributes for the button, under the button's own. */\n attributes?: ToolbarItemAttributes | undefined;\n /** The button's label, and its menu's accessible name. */\n label: string;\n icon?: string | undefined;\n entries: readonly ResolvedMenuEntry[];\n /** The \"More\" button, holding the entries that do not fit, rather than a dropdown. */\n more?: boolean | undefined;\n /** Where focus goes when the menu closes with its button gone. */\n returnFocusFallback: () => HTMLElement | null;\n}\n\n/**\n * A toolbar button opening a menu below it, as `useMenuButton` describes.\n * Closing the menu returns focus to the button. What the items do, and\n * whether each runs, is in their `run`.\n */\nexport default function ToolbarMenuButton({\n itemKey,\n attributes,\n label,\n icon,\n entries,\n more = false,\n returnFocusFallback,\n}: ToolbarMenuButtonProps) {\n const { state, close, buttonProps, behaviourRef } = useMenuButton({\n itemCount: entries.filter((entry) => entry.type !== \"separator\").length,\n });\n\n return (\n <>\n <button\n {...attributes}\n type=\"button\"\n className={classNames(\n \"gridkit-toolbar-button\",\n more && \"gridkit-toolbar-more\",\n )}\n data-gridkit-toolbar-item={itemKey}\n {...ariaAttr(more, \"data-gridkit-toolbar-more\", \"\")}\n {...buttonProps}\n >\n {icon !== undefined && (\n <span className=\"gridkit-toolbar-button-icon\" aria-hidden=\"true\">\n <MenuIcon name={icon} />\n </span>\n )}\n {label}\n <span className=\"gridkit-toolbar-button-indicator\" aria-hidden=\"true\">\n <ChevronDownIcon />\n </span>\n </button>\n {state.kind === \"open\" && (\n <Overlay\n anchor={state.anchor}\n placement=\"bottom-start\"\n gap={state.gap}\n returnFocusTo={state.anchor}\n returnFocusFallback={returnFocusFallback}\n scope={state.scope}\n onDismiss={close}\n >\n <GridMenu\n entries={entries}\n label={label}\n scope={state.scope}\n behaviourRef={behaviourRef}\n onRun={(item) => {\n item.run();\n close();\n }}\n onClose={close}\n />\n </Overlay>\n )}\n </>\n );\n}\n","import { useEffect, useRef, useState } from \"react\";\nimport type { GridMessages, ToolbarItemAttributes } from \"@gridkitjs/core\";\nimport { searchTextOf, setSearchText } from \"@gridkitjs/core/renderer\";\nimport useAnnounceWhenDrawn from \"../useAnnounceWhenDrawn\";\nimport type { DataGridController } from \"../useGridController\";\n\n/** How long typing has to rest before the search applies. */\nconst SEARCH_DELAY_MS = 250;\n\n/** What the user has typed and the grid not yet applied. */\ninterface Draft {\n readonly text: string;\n /**\n * The search applied when it was typed. Once the search changes from\n * elsewhere — \"Clear filters\", a restored layout — the draft is dropped\n * and the box shows that instead.\n */\n readonly over: string;\n}\n\ninterface ToolbarSearchProps<Row> {\n /** Its `data-gridkit-toolbar-item`. */\n itemKey: string;\n /** The app's attributes for the box, under the box's own. */\n attributes: ToolbarItemAttributes | undefined;\n controller: DataGridController<Row>;\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/**\n * The toolbar's search box, over the filter's global text entry — the one\n * naming no column — through `@gridkitjs/core`'s `searchTextOf` and\n * `setSearchText`. It reads what it shows back from the filter, so anything\n * else that changes the search changes the box.\n *\n * Typing applies once it rests for a moment; Enter applies at once, and\n * Escape empties the box. A search the box applied is announced as the\n * number of rows it found, once the grid has drawn them.\n */\nexport default function ToolbarSearch<Row>({\n itemKey,\n attributes,\n controller,\n messages,\n announce,\n}: ToolbarSearchProps<Row>) {\n const applied = searchTextOf(controller.getState().filter);\n const [draft, setDraft] = useState<Draft | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const announceWhenDrawn = useAnnounceWhenDrawn(announce);\n const text = draft !== null && draft.over === applied ? draft.text : applied;\n\n /** Applies `next`, typed over the search `over`, unless that has changed since. */\n function apply(next: string, over: string): void {\n clearTimeout(timer.current);\n setDraft(null);\n const filter = controller.getState().filter;\n if (searchTextOf(filter) !== over) {\n return;\n }\n const searched = setSearchText(filter, next);\n if (searched !== filter) {\n announceWhenDrawn({\n drawn: () => searchTextOf(controller.getState().filter) === next,\n text: () => messages.searchResults(controller.getView().rows.length),\n });\n controller.setFilter(searched);\n }\n }\n\n useEffect(\n () => () => {\n clearTimeout(timer.current);\n },\n [],\n );\n\n return (\n <input\n {...attributes}\n type=\"search\"\n className=\"gridkit-toolbar-search\"\n data-gridkit-toolbar-item={itemKey}\n aria-label={messages.searchLabel}\n placeholder={messages.searchPlaceholder}\n value={text}\n onChange={(event) => {\n const typed = event.target.value;\n setDraft({ text: typed, over: applied });\n clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n apply(typed, applied);\n }, SEARCH_DELAY_MS);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n apply(text, applied);\n } else if (event.key === \"Escape\" && text !== \"\") {\n // Ahead of the browser's own clearing, which would wait out the delay.\n event.preventDefault();\n apply(\"\", applied);\n }\n }}\n />\n );\n}\n","import { useLayoutEffect, useRef, useState, type RefObject } from \"react\";\nimport type { ResolvedToolbarItem } from \"@gridkitjs/core\";\nimport { observeToolbarOverflow, type ToolbarOverflow } from \"@gridkitjs/dom\";\n\n/**\n * How many of a toolbar's items fit in it, from the start, as\n * `@gridkitjs/dom`'s `observeToolbarOverflow` measures them — every item\n * until it first reports, which it does before paint.\n *\n * Attached once, so the widths it remembers for items moved into \"More\"\n * survive, and told of new items only when the toolbar's layout — each\n * item's kind, key and label — changes, rather than on every render, which\n * resolves the items afresh. A label matters for an item in \"More\", whose\n * remembered width it makes stale.\n */\nexport default function useToolbarOverflow(\n toolbarRef: RefObject<HTMLElement | null>,\n items: readonly ResolvedToolbarItem[],\n): number {\n const [fit, setFit] = useState(items.length);\n const overflow = useRef<ToolbarOverflow | null>(null);\n const measuredLayout = useRef(\"\");\n const layout = JSON.stringify(\n items.map((item) => [\n item.type,\n item.key,\n \"label\" in item ? item.label : null,\n ]),\n );\n\n useLayoutEffect(() => {\n const toolbar = toolbarRef.current;\n if (toolbar === null || layout === measuredLayout.current) {\n return;\n }\n measuredLayout.current = layout;\n const options = { items, onChange: setFit };\n if (overflow.current === null) {\n overflow.current = observeToolbarOverflow(toolbar, options);\n } else {\n overflow.current.update(options);\n }\n }, [toolbarRef, layout, items]);\n\n useLayoutEffect(\n () => () => {\n overflow.current?.detach();\n overflow.current = null;\n measuredLayout.current = \"\";\n },\n [],\n );\n\n return fit;\n}\n","import type { PointerEvent as ReactPointerEvent } from \"react\";\nimport type {\n ColumnOrderState,\n ColumnPin,\n GroupByState,\n} from \"@gridkitjs/core\";\nimport { resolveKeyboardDropTarget } from \"@gridkitjs/core/renderer\";\nimport { resolveColumnDropTarget, type ColumnDropTarget } from \"@gridkitjs/dom\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport useDragReorder from \"./useDragReorder\";\n\ninterface UseColumnDragOptions {\n order: ColumnOrderState;\n /** What a drop onto the group-by bar is resolved against. */\n groupBy: GroupByState;\n /** Column ids whose header may be dragged into the group-by bar at all. */\n groupByDraggableIds: ReadonlySet<string>;\n /** The edge each column is pinned to, whose group a drag stays inside. */\n pinOf: (columnId: string) => ColumnPin;\n onDrop: (target: ColumnDropTarget, movedId: string) => void;\n}\n\nexport interface ColumnDragApi<Row> {\n /** The column being dragged, for as long as the drag lasts. */\n draggedColumnId: string | null;\n /** Where it would land if released now. */\n dropTarget: ColumnDropTarget | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n ghostTransform: string | null;\n startDrag: (\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ) => void;\n /** Moves a column one place left (`-1`) or right (`1`). */\n moveByKeyboard: (entry: ResolvedColumn<Row>, direction: -1 | 1) => void;\n /**\n * Whether the column's last press opened a drag, so the click that follows\n * its release is not a click, for a header that has something of its own to\n * do with one. Reading it clears it.\n */\n justDragged: (columnId: string) => boolean;\n}\n\n/**\n * Turns a pointer drag over the header into a drop target, leaving `onDrop` to\n * apply it. Built on `useDragReorder`'s shared pointer mechanics, with\n * `@gridkitjs/dom`'s `resolveColumnDropTarget` as the hit-testing: another\n * header (reorder among columns) or the group-by bar (add this column to the\n * grouping), tried in that order.\n */\nexport default function useColumnDrag<Row>({\n order,\n groupBy,\n groupByDraggableIds,\n pinOf,\n onDrop,\n}: UseColumnDragOptions): ColumnDragApi<Row> {\n const drag = useDragReorder<ColumnDropTarget>({\n resolveTarget: (clientX, clientY, movedId) =>\n resolveColumnDropTarget(clientX, clientY, movedId, {\n order,\n groupBy,\n groupByDraggableIds,\n pinOf,\n }),\n onDrop,\n });\n\n function startDrag(\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n drag.startDrag(entry.id, event.currentTarget, event);\n }\n\n function moveByKeyboard(entry: ResolvedColumn<Row>, direction: -1 | 1): void {\n const beforeId = resolveKeyboardDropTarget(order, entry.id, direction);\n if (beforeId === undefined) {\n return;\n }\n onDrop({ kind: \"column-order\", beforeId }, entry.id);\n }\n\n // A new object each render, as `useColumnResize` returns: the handlers close\n // over `order`/`groupBy`, and a stable identity would buy nothing.\n return {\n draggedColumnId: drag.draggedId,\n dropTarget: drag.dropTarget,\n ghostTransform: drag.ghostTransform,\n startDrag,\n moveByKeyboard,\n justDragged: drag.justDragged,\n };\n}\n","import {\n useState,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n} from \"react\";\nimport type { ColumnSizeDefaults } from \"@gridkitjs/core\";\nimport {\n beginColumnResize,\n clampColumnWidth,\n resolveColumnConstraints,\n sizeColumnToContent,\n} from \"@gridkitjs/core/renderer\";\nimport { measureColumnContent, startColumnResizeGesture } from \"@gridkitjs/dom\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport type { DataGridController } from \"./useGridController\";\nimport useGestureSignal from \"./useGestureSignal\";\n\ninterface UseColumnResizeOptions<Row> {\n tableRef: RefObject<HTMLTableElement | null>;\n controller: DataGridController<Row>;\n columnSizeDefaults?: Partial<ColumnSizeDefaults> | undefined;\n}\n\nexport interface ColumnResizeApi<Row> {\n /** The column being dragged, for as long as the drag lasts. */\n activeColumnId: string | null;\n startResize: (\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ) => void;\n /** Sizes a column to its content, and says whether it could: not without cells. */\n sizeToContent: (entry: ResolvedColumn<Row>) => boolean;\n nudge: (entry: ResolvedColumn<Row>, delta: number) => void;\n}\n\n/**\n * Turns pointer and keyboard input into column widths. The drag itself is\n * `@gridkitjs/dom`'s `startColumnResizeGesture`, every width comes from\n * `@gridkitjs/core`, and the grid's controller applies them; this hook holds\n * only which column is being dragged. The drag is cancelled with the\n * component, and with its handle should a render remove it\n * (`useGestureSignal`).\n */\nexport default function useColumnResize<Row>({\n tableRef,\n controller,\n columnSizeDefaults,\n}: UseColumnResizeOptions<Row>): ColumnResizeApi<Row> {\n const [activeColumnId, setActiveColumnId] = useState<string | null>(null);\n const startGesture = useGestureSignal();\n\n function startResize(\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n // A press on the handle is never the header's, whichever button made it:\n // a reorderable header's own drag must not see it.\n event.stopPropagation();\n\n const session = beginColumnResize(\n entry.column,\n entry.width,\n event.clientX,\n columnSizeDefaults,\n );\n /** The sizing as the drag found it, which Escape puts the column back to. */\n const base = controller.getState().columnSizing;\n\n const handle = event.currentTarget;\n const started = startGesture(handle, (signal) =>\n startColumnResizeGesture(handle, event, session, {\n onMove(width) {\n controller.resizeColumn(session.columnId, width, \"move\");\n },\n onEnd(width) {\n setActiveColumnId(null);\n if (width !== null) {\n controller.resizeColumn(session.columnId, width, \"end\");\n }\n },\n /**\n * Escape puts back only the dragged column's pre-drag width, merged\n * into whatever the sizing state is *now* — not the `base` snapshot\n * taken at drag-start — so a different column resized via keyboard\n * while this drag was still open keeps its change instead of being\n * clobbered by a stale restore.\n */\n onCancel() {\n setActiveColumnId(null);\n controller.cancelColumnResize(\n session.columnId,\n base,\n session.startWidth,\n );\n },\n signal,\n }),\n );\n if (started) {\n setActiveColumnId(session.columnId);\n }\n }\n\n function sizeToContent(entry: ResolvedColumn<Row>): boolean {\n const table = tableRef.current;\n if (table === null) {\n return false;\n }\n\n const measured = measureColumnContent(table, entry.id);\n if (measured === null) {\n return false;\n }\n\n controller.resizeColumn(\n entry.id,\n sizeColumnToContent(\n measured,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n return true;\n }\n\n function nudge(entry: ResolvedColumn<Row>, delta: number): void {\n controller.resizeColumn(\n entry.id,\n clampColumnWidth(\n entry.width + delta,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n }\n\n // A new object each render, as the other hooks here return.\n return { activeColumnId, startResize, sizeToContent, nudge };\n}\n","import { useLayoutEffect, useState, type RefObject } from \"react\";\nimport { observeElementHeight } from \"@gridkitjs/dom\";\n\n/**\n * The height of `ref`'s element, tracked as it changes by\n * `@gridkitjs/dom`'s `observeElementHeight`, or `null` while `enabled` is\n * off or the element is not mounted.\n *\n * A layout effect, as in `useElementWidth`, so the first measurement lands\n * before paint.\n */\nexport default function useElementHeight(\n ref: RefObject<HTMLElement | null>,\n enabled: boolean,\n): number | null {\n const [height, setHeight] = useState<number | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n if (element === null || !enabled) {\n return undefined;\n }\n const disconnect = observeElementHeight(element, setHeight);\n return () => {\n disconnect();\n setHeight(null);\n };\n }, [ref, enabled]);\n\n return enabled ? height : null;\n}\n","import { useLayoutEffect, useState, type RefObject } from \"react\";\nimport { observeElementWidth } from \"@gridkitjs/dom\";\n\n/**\n * The inner width of `ref`'s element, tracked as it changes by\n * `@gridkitjs/dom`'s `observeElementWidth`.\n *\n * A layout effect rather than an effect so the first measurement lands before\n * paint — otherwise columns show at their natural width for a frame and then\n * visibly jump once auto-fit runs. No isomorphic-layout-effect shim: React 19\n * skips layout effects on the server without a warning, and the width stays\n * `null` until the client measures.\n *\n * @param enabled Whether to observe at all. A caller that does not read the\n * width passes `false` rather than paying a re-render of the whole grid on\n * every frame of a window resize.\n */\nexport default function useElementWidth(\n ref: RefObject<HTMLElement | null>,\n enabled: boolean,\n): number | null {\n const [width, setWidth] = useState<number | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n if (element === null || !enabled) {\n return undefined;\n }\n return observeElementWidth(element, setWidth);\n }, [ref, enabled]);\n\n return width;\n}\n","import { useState, useSyncExternalStore, type ReactNode } from \"react\";\nimport {\n createGridController,\n type GridController,\n type GridControllerOptions,\n type GridState,\n type GridView,\n} from \"@gridkitjs/core\";\n\n/** The grid's controller, bound to React's node type for its columns. */\nexport type DataGridController<Row> = GridController<Row, ReactNode>;\n\nexport interface GridControllerBinding<Row> {\n controller: DataGridController<Row>;\n /** The state this render draws — re-read on every change the controller commits. */\n state: GridState<Row>;\n view: GridView<Row, ReactNode>;\n}\n\n/**\n * The grid's controller, created once and handed the current props on every\n * render. The controller holds every slice of state and derives the view, so\n * this hook only keeps React in step with it: `setOptions` runs during render,\n * so the view drawn always matches the props drawn, and the subscription\n * re-renders the grid when an action commits.\n *\n * `getState` is the snapshot: the controller hands back the same object until\n * a slice changes, which is exactly the stability `useSyncExternalStore`\n * needs, and a change the props made (a controlled slice) is already in it by\n * the time it is read here. It is the server snapshot too: on the server and\n * while hydrating, the controller has seen only the props, so both sides read\n * the same initial state.\n */\nexport default function useGridController<Row>(\n options: GridControllerOptions<Row, ReactNode>,\n): GridControllerBinding<Row> {\n const [controller] = useState(() =>\n createGridController<Row, ReactNode>(options),\n );\n controller.setOptions(options);\n const state = useSyncExternalStore(\n controller.subscribe,\n controller.getState,\n controller.getState,\n );\n return { controller, state, view: controller.getView() };\n}\n","import { useEffect, useRef, type RefObject } from \"react\";\nimport { attachInfiniteScroll, type InfiniteScroll } from \"@gridkitjs/dom\";\nimport type { InfiniteScrollConfig } from \"./DataGrid\";\n\ninterface UseInfiniteScrollOptions {\n /** The `.gridkit-data-grid-tables` scroll area the rows scroll in. */\n rootRef: RefObject<HTMLDivElement | null>;\n /** The always-last `<tr>` `GridBody` renders while `config?.hasMore` is true. */\n sentinelRef: RefObject<HTMLTableRowElement | null>;\n config: InfiniteScrollConfig | undefined;\n}\n\n/**\n * `@gridkitjs/dom`'s `attachInfiniteScroll` on the scroll area, idle until the\n * effect below hands it the props. That runs after every commit: the\n * sentinel row mounts and unmounts with `hasMore`, so only after a commit is\n * `sentinelRef` current, and an update that changes nothing does nothing.\n */\nexport default function useInfiniteScroll({\n rootRef,\n sentinelRef,\n config,\n}: UseInfiniteScrollOptions): void {\n const scroll = useRef<InfiniteScroll | null>(null);\n\n useEffect(() => {\n const root = rootRef.current;\n if (root === null) {\n return undefined;\n }\n const attached = attachInfiniteScroll(root, {\n sentinel: null,\n hasMore: false,\n });\n scroll.current = attached;\n return () => {\n attached.detach();\n scroll.current = null;\n };\n }, [rootRef]);\n\n useEffect(() => {\n scroll.current?.update({\n sentinel: sentinelRef.current,\n hasMore: config?.hasMore ?? false,\n onLoadMore: config?.onLoadMore,\n isLoadingMore: config?.isLoadingMore,\n rootMargin: config?.rootMargin,\n });\n });\n}\n","import { useCallback, useLayoutEffect, useRef, type RefObject } from \"react\";\nimport { createLiveAnnouncer, type LiveAnnouncer } from \"@gridkitjs/dom\";\n\n/**\n * The grid's live region, added as the last child of `containerRef`'s element\n * once it mounts. `@gridkitjs/dom` owns the element, so React never renders\n * it and an announcement re-renders nothing.\n *\n * A layout effect, so the region is in place from the first paint — where it\n * was when React rendered it. The returned `announce` keeps its identity for\n * the grid's whole life.\n */\nexport default function useLiveAnnouncer(\n containerRef: RefObject<HTMLElement | null>,\n): (text: string) => void {\n const announcer = useRef<LiveAnnouncer | null>(null);\n\n useLayoutEffect(() => {\n const container = containerRef.current;\n if (container === null) {\n return undefined;\n }\n const created = createLiveAnnouncer(container);\n announcer.current = created;\n return () => {\n created.destroy();\n announcer.current = null;\n };\n }, [containerRef]);\n\n return useCallback((text: string) => {\n announcer.current?.announce(text);\n }, []);\n}\n","import { useLayoutEffect, useRef, useState, type RefObject } from \"react\";\nimport type { VisibleRange } from \"@gridkitjs/core/renderer\";\nimport {\n bodyRowFrom,\n createRowVirtualizer,\n type RowVirtualizer,\n} from \"@gridkitjs/dom\";\n\nexport interface RowVirtualizerApi extends VisibleRange {\n /** Ref callback `GridBody` attaches to each rendered row's `<tr>`, keyed by that row's index in the full array. */\n measureRow: (index: number) => (element: HTMLTableRowElement | null) => void;\n /**\n * Scrolls so `index` is visible. Two-pass for a row not currently mounted:\n * jumps to an estimated offset immediately, then — once that row mounts and\n * its real height is measured — corrects the scroll position via the\n * mounted element's own `scrollIntoView`. A row already mounted is scrolled\n * to directly, in one pass. Works from a layout effect in the commit that\n * turns `enabled` on.\n */\n scrollToIndex: (index: number, options?: ScrollIntoViewOptions) => void;\n}\n\ninterface UseRowVirtualizerOptions {\n /** Whether virtualization is active at all. `false` attaches nothing — no behavioral or performance difference from not virtualizing. */\n enabled: boolean;\n /** The full row array — only its `.length` and reference identity matter here; a new reference resets the measured heights (see below). */\n rows: readonly unknown[];\n /**\n * The `.gridkit-data-grid-tables` scroll area. The rows follow the header,\n * which sticks to its top, so the area's scroll position is the rows' own.\n */\n scrollRef: RefObject<HTMLDivElement | null>;\n /** The body's `<table>`, whose mounted rows a new virtualizer measures before its first window. */\n bodyTableRef: RefObject<HTMLTableElement | null>;\n estimatedRowHeight: number;\n overscan: number;\n}\n\n/**\n * The rows the body draws: `allRows` while `enabled` is off, when the body\n * draws every row, and from the moment it turns on until the new virtualizer\n * reports; otherwise the `range` it reported last.\n */\ntype RowWindow =\n | { readonly kind: \"allRows\" }\n | { readonly kind: \"range\"; readonly range: VisibleRange };\n\nconst ALL_ROWS: RowWindow = { kind: \"allRows\" };\n\n/** A grid mounted with `enabled` on draws no rows until its virtualizer reports, which it does before paint. */\nconst NO_ROWS: RowWindow = {\n kind: \"range\",\n range: { startIndex: 0, endIndex: -1, offsetBefore: 0, offsetAfter: 0 },\n};\n\nfunction rangeOf(rowWindow: RowWindow, rowCount: number): VisibleRange {\n if (rowWindow.kind === \"range\") {\n return rowWindow.range;\n }\n return {\n startIndex: 0,\n endIndex: rowCount - 1,\n offsetBefore: 0,\n offsetAfter: 0,\n };\n}\n\n/** The body rows mounted in `table`, each with its index among all the rows; spacer and sentinel rows carry none. */\nfunction* mountedRows(\n table: HTMLTableElement | null,\n): Generator<readonly [number, HTMLTableRowElement]> {\n for (const row of table?.tBodies[0]?.rows ?? []) {\n const target = bodyRowFrom(row);\n if (target !== null) {\n yield [target.rowIndex, row];\n }\n }\n}\n\n/** What a row is measured with before the first virtualizer is created. */\nfunction ignoreRow(): () => void {\n return () => undefined;\n}\n\n/**\n * `@gridkitjs/dom`'s `createRowVirtualizer` on the scroll area, with the window of\n * rows it reports held as state for `GridBody` to render. The virtualizer is\n * state too, because `measureRow` is read while rendering: a new one —\n * `estimatedRowHeight` or `overscan` changed — re-renders every row with its\n * own ref callbacks, so the rows already mounted are measured anew. It is\n * also a ref, which `scrollToIndex` reads: in the commit that turns\n * `enabled` on, a parent's layout effect runs after the one here that\n * creates the virtualizer but before the render that puts it in state.\n *\n * Once `enabled` goes off, the destroyed virtualizer stays in state, where\n * it measures and scrolls nothing. The window goes back to every row, and\n * stays there when `enabled` comes back on until the new virtualizer\n * reports: the rows mounted then stay mounted, the focused one and the\n * browser's focus with it, and the body keeps its height, and so the scroll\n * area its position. An empty window, or the last one reported, would\n * unmount them for a pass, and could collapse the body and send the scroll\n * area to the top.\n * The new virtualizer measures every mounted row before it reports, so its\n * first window is the rows on screen: one placed by `estimatedRowHeight`\n * could miss them when real heights differ from it, unmounting the focused\n * row all the same.\n *\n * Layout effects, so the window settles before paint rather than showing the\n * previous one for a frame — the same reason `useElementWidth` measures in a\n * layout effect.\n *\n * The measured heights reset whenever `rows` becomes a new reference\n * (filter, sort, groupBy, or `dataSource` itself changing) rather than\n * tracking each of those individually — the simplest rule that stays\n * correct, at the cost of one remeasurement on those already-big operations.\n * Keying heights by row id instead, to survive a pure reorder, is a\n * considered, deliberately deferred enhancement.\n */\nexport default function useRowVirtualizer({\n enabled,\n rows,\n scrollRef,\n bodyTableRef,\n estimatedRowHeight,\n overscan,\n}: UseRowVirtualizerOptions): RowVirtualizerApi {\n const [virtualizer, setVirtualizer] = useState<RowVirtualizer | null>(null);\n const instance = useRef<RowVirtualizer | null>(null);\n const rowCount = useRef(rows.length);\n const [rowWindow, setRowWindow] = useState(enabled ? NO_ROWS : ALL_ROWS);\n\n // While rendering, as state that follows a prop is adjusted: the render\n // that turns `enabled` back on must already draw every row.\n if (!enabled && rowWindow.kind !== \"allRows\") {\n setRowWindow(ALL_ROWS);\n }\n\n useLayoutEffect(() => {\n rowCount.current = rows.length;\n instance.current?.setRowCount(rows.length);\n instance.current?.resetHeights();\n }, [rows]);\n\n useLayoutEffect(() => {\n const element = scrollRef.current;\n if (!enabled || element === null) {\n return undefined;\n }\n const created = createRowVirtualizer(element, {\n estimatedRowHeight,\n overscan,\n onRange: (range) => {\n setRowWindow({ kind: \"range\", range });\n },\n });\n // Before its first window is drawn, which would otherwise be empty, and\n // placed from the rows on screen rather than from estimated heights.\n created.setRowCount(rowCount.current);\n created.measureRows(mountedRows(bodyTableRef.current));\n instance.current = created;\n setVirtualizer(created);\n return () => {\n created.destroy();\n };\n }, [enabled, scrollRef, bodyTableRef, estimatedRowHeight, overscan]);\n\n const range = rangeOf(rowWindow, rows.length);\n return {\n startIndex: range.startIndex,\n endIndex: range.endIndex,\n offsetBefore: range.offsetBefore,\n offsetAfter: range.offsetAfter,\n measureRow: virtualizer?.measureRow ?? ignoreRow,\n scrollToIndex: (index, options) => {\n instance.current?.scrollToIndex(index, options);\n },\n };\n}\n","// React components will be exported from here. They consume the framework-agnostic logic in @gridkitjs/core.\nexport {\n DataGrid,\n type Borders,\n type CellSelectEvent,\n type CellSelectionChangeEvent,\n type ColumnDefinition,\n type ColumnSelectEvent,\n type ColumnSelectionChangeEvent,\n type ColumnsSelectEvent,\n type DataColumn,\n type DataGridApi,\n type DataGridProps,\n type GroupByBarVisibility,\n type HoverableConfig,\n type InfiniteScrollConfig,\n type PagerConfig,\n type PagerTemplateContext,\n type PaginationUnit,\n type ReactRenderSlots,\n type ResizeMode,\n type ResolvedColumn,\n type SelectedCell,\n type SelectedColumn,\n} from \"./DataGrid/DataGrid\";\n// Every core type a prop, a column definition, a callback or a `DataGridApi`\n// method names, and the entries those states are built from, so typing a grid,\n// its callbacks or a standalone template needs no import from core. The row\n// payloads name no node type of their own, so they come straight from core.\nexport type {\n AggregateFn,\n AggregateResults,\n AggregateSpec,\n AggregateState,\n BuiltInAggregate,\n CellSelectionMode,\n CellSelectionState,\n CellTemplateContext,\n ColumnAlignment,\n ColumnFilterMenuOptions,\n ColumnOrderEvent,\n ColumnOrderState,\n ColumnPin,\n ColumnPinningEvent,\n ColumnPinningState,\n ColumnResizeEvent,\n ColumnSizeDefaults,\n ColumnSizingState,\n ColumnSortEntry,\n ColumnSortEvent,\n ColumnSortState,\n ColumnType,\n ColumnVisibilityEvent,\n ColumnVisibilityState,\n ColumnWrapConfig,\n ContextMenuOpenChangeEvent,\n DisplayRow,\n ExportScalar,\n FieldPath,\n FilterChangeEvent,\n FilterEntry,\n FilterState,\n FooterTemplateContext,\n FormatLocale,\n GridCommand,\n GridCommandEvent,\n GridCommandTarget,\n GridContextMenuOptions,\n GridContextMenuRequest,\n GridContextMenuTarget,\n GridFilterMenuOptions,\n GridFocus,\n GridMessages,\n GridOptions,\n GridState,\n GridToolbarOptions,\n GroupAggregateDisplay,\n GroupByEntry,\n GroupByEvent,\n GroupByState,\n GroupExpansionEvent,\n GroupExpansionState,\n MenuEntry,\n PaginationChangeEvent,\n PaginationState,\n ResolvedGroupRow,\n ResolvedGroupSummaryRow,\n ResolvedRow,\n RowGroupPosition,\n RowPointerEvent,\n RowProps,\n RowSelectEvent,\n RowSelectionChangeEvent,\n RowsSelectEvent,\n SelectableConfig,\n SelectedCellRef,\n SelectionMode,\n SelectionState,\n SerializedGridState,\n SortDirection,\n ToolbarEntry,\n ToolbarItemAttributes,\n} from \"@gridkitjs/core\";\n\n// Re-exported for the same reason: saving `getState()` as JSON goes through it.\nexport { serializeGridState } from \"@gridkitjs/core\";\n\n// Reactive hooks for building custom UI outside the grid's own DOM, each\n// subscribing to `DataGridApi.subscribe` via `useSyncExternalStore`.\nexport { default as usePaginationState } from \"./DataGrid/hooks/usePaginationState\";\nexport type { PaginationStateApi } from \"./DataGrid/hooks/usePaginationState\";\nexport { default as useGroupByState } from \"./DataGrid/hooks/useGroupByState\";\nexport type { GroupByStateApi } from \"./DataGrid/hooks/useGroupByState\";\nexport { default as useColumnSortState } from \"./DataGrid/hooks/useColumnSortState\";\nexport { default as useSelectionState } from \"./DataGrid/hooks/useSelectionState\";\nexport type { SelectionStateApi } from \"./DataGrid/hooks/useSelectionState\";\nexport { default as useAggregateState } from \"./DataGrid/hooks/useAggregateState\";\nexport { default as useColumnSizingState } from \"./DataGrid/hooks/useColumnSizingState\";\nexport { default as useColumnOrderState } from \"./DataGrid/hooks/useColumnOrderState\";\nexport { default as useColumnVisibilityState } from \"./DataGrid/hooks/useColumnVisibilityState\";\nexport { default as useColumnPinningState } from \"./DataGrid/hooks/useColumnPinningState\";\nexport { default as useFilterState } from \"./DataGrid/hooks/useFilterState\";\nexport type { FilterStateApi } from \"./DataGrid/hooks/useFilterState\";\n\n// Re-exported so typing an export — its options, a writer of the app's own,\n// the file a writer gives — needs no import from core.\nexport type {\n ExportFile,\n ExportOptions,\n ExportWriter,\n GridExportOptions,\n} from \"@gridkitjs/core\";\n\n// Re-exported so typing the `print` option, or a call to `print`, needs no\n// import from core.\nexport type { PrintOptions } from \"@gridkitjs/core\";\n\n// The filter popup in its Excel-style form, spread into `DataGrid`:\n// `<DataGrid {...excelFilter} />`.\nexport { excelFilter } from \"@gridkitjs/core\";\n","import { useCallback, type RefObject } from \"react\";\nimport type { PaginationState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_PAGINATION: PaginationState = { pageIndex: 0, pageSize: 0 };\n\nexport interface PaginationStateApi {\n pagination: PaginationState;\n pageCount: number;\n goToPage: (pageIndex: number) => void;\n nextPage: () => void;\n previousPage: () => void;\n setPageSize: (pageSize: number) => void;\n}\n\n/**\n * Reactive pagination state read off a mounted `DataGrid`'s `ref`,\n * for building a pager entirely outside the grid's own DOM — a toolbar or\n * sidebar `pager.template` can't reach. Updates on every pagination change,\n * including the silent page-0 reset a filter/sort/group change triggers,\n * which carries no `onPaginationChange` of its own.\n *\n * Before the grid mounts, `pagination` reads `{ pageIndex: 0, pageSize: 0 }`\n * and `pageCount` reads `0`; the actions are no-ops until then.\n */\nexport default function usePaginationState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): PaginationStateApi {\n const pagination = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getPagination(), []),\n FALLBACK_PAGINATION,\n );\n const pageCount = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getPageCount(), []),\n 0,\n );\n\n return {\n pagination,\n pageCount,\n goToPage: (pageIndex) => {\n gridRef.current?.goToPage(pageIndex);\n },\n nextPage: () => {\n gridRef.current?.nextPage();\n },\n previousPage: () => {\n gridRef.current?.previousPage();\n },\n setPageSize: (pageSize) => {\n gridRef.current?.setPageSize(pageSize);\n },\n };\n}\n","import {\n useCallback,\n useEffect,\n useRef,\n useSyncExternalStore,\n type RefObject,\n} from \"react\";\nimport type { DataGridApi } from \"../DataGrid\";\n\n/**\n * `useSyncExternalStore`'s listener and the grid it is attached to: none\n * while the ref holds no grid, which can be long after the hook first\n * subscribes, a grid mounted once its data arrives.\n */\ntype Subscription<Row> =\n | { readonly kind: \"waiting\"; readonly listener: () => void }\n | {\n readonly kind: \"subscribed\";\n readonly listener: () => void;\n readonly api: DataGridApi<Row>;\n readonly unsubscribe: () => void;\n };\n\nfunction subscribeTo<Row>(\n api: DataGridApi<Row> | null,\n listener: () => void,\n): Subscription<Row> {\n return api === null\n ? { kind: \"waiting\", listener }\n : {\n kind: \"subscribed\",\n listener,\n api,\n unsubscribe: api.subscribe(listener),\n };\n}\n\nfunction unsubscribe<Row>(subscription: Subscription<Row> | null): void {\n if (subscription?.kind === \"subscribed\") {\n subscription.unsubscribe();\n }\n}\n\n/**\n * Shared `useSyncExternalStore` wiring behind every public `use*State` hook\n * in this folder. Not exported. `gridRef.current` is `null` until the grid\n * mounts, and a ref says nothing when it changes, so the grid it holds is\n * read again after every render of the hook's component: the listener moves\n * to a grid the ref has gained, lost or swapped since, and is called, as\n * that grid's state may differ from the last snapshot. Until there is one,\n * the hook returns `fallback`. The ref is `null` on the server and while\n * hydrating too, so `fallback` is the server snapshot.\n */\nexport default function useGridSnapshot<Row, T>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n getSnapshot: (api: DataGridApi<Row>) => T,\n fallback: T,\n): T {\n /** `null` while `useSyncExternalStore` has nothing subscribed. */\n const subscription = useRef<Subscription<Row> | null>(null);\n\n const subscribe = useCallback(\n (listener: () => void) => {\n subscription.current = subscribeTo(gridRef.current, listener);\n return () => {\n unsubscribe(subscription.current);\n subscription.current = null;\n };\n },\n [gridRef],\n );\n\n const snapshot = useSyncExternalStore(\n subscribe,\n () => {\n const api = gridRef.current;\n return api === null ? fallback : getSnapshot(api);\n },\n () => fallback,\n );\n\n // After `useSyncExternalStore`'s own effect, so its listener is held.\n useEffect(() => {\n const current = subscription.current;\n if (current === null) {\n return;\n }\n const api = gridRef.current;\n if (api === (current.kind === \"subscribed\" ? current.api : null)) {\n return;\n }\n unsubscribe(current);\n subscription.current = subscribeTo(api, current.listener);\n current.listener();\n });\n\n return snapshot;\n}\n","import { useCallback, type RefObject } from \"react\";\nimport {\n ALL_EXPANDED,\n type GroupByState,\n type GroupExpansionState,\n} from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_GROUP_BY: GroupByState = [];\nconst FALLBACK_EXPANSION: GroupExpansionState = ALL_EXPANDED;\n\nexport interface GroupByStateApi {\n groupBy: GroupByState;\n groupExpansion: GroupExpansionState;\n expandAllGroups: () => void;\n collapseAllGroups: () => void;\n}\n\n/**\n * Reactive group-by and group-expansion state read off a mounted\n * `DataGrid`'s `ref`, for a group-by bar or summary sidebar living\n * outside the grid's own DOM.\n *\n * The ref's `setGroupBy` and `setGroupExpansion` change the grouping and the\n * group expansion for a custom group-by UI; this hook carries only the\n * all-at-once expansion actions. A specific\n * group's own computed aggregates are read off `getDisplayRows()`'s\n * per-header `aggregates` field instead of a getter here — see\n * `useAggregateState` for the grand-total equivalent.\n *\n * Before the grid mounts, `groupBy` reads as empty, `groupExpansion` as\n * `ALL_EXPANDED`, and the actions are no-ops.\n */\nexport default function useGroupByState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): GroupByStateApi {\n const groupBy = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getGroupBy(), []),\n FALLBACK_GROUP_BY,\n );\n const groupExpansion = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getGroupExpansion(), []),\n FALLBACK_EXPANSION,\n );\n\n return {\n groupBy,\n groupExpansion,\n expandAllGroups: () => {\n gridRef.current?.expandAllGroups();\n },\n collapseAllGroups: () => {\n gridRef.current?.collapseAllGroups();\n },\n };\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnSortState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_SORT: ColumnSortState = [];\n\n/**\n * Reactive column-sort state read off a mounted `DataGrid`'s `ref`,\n * for a sort indicator living outside the grid's own DOM.\n *\n * Reads only; change the sort through the ref's `setColumnSort`, or hold it\n * yourself with the controlled `columnSort` prop.\n *\n * Before the grid mounts, reads as an empty array.\n */\nexport default function useColumnSortState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnSortState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnSort(), []),\n FALLBACK_SORT,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { CellSelectionState, SelectionState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_SELECTION: SelectionState = [];\nconst FALLBACK_CELL_SELECTION: CellSelectionState = { kind: \"none\" };\n\nexport interface SelectionStateApi {\n rowSelection: SelectionState;\n columnSelection: SelectionState;\n cellSelection: CellSelectionState;\n clearSelection: () => void;\n selectAllRows: () => void;\n}\n\n/**\n * Reactive row/column/cell selection state read off a mounted\n * `DataGrid`'s `ref`, for a \"N rows selected\" toolbar living\n * outside the grid's own DOM. One combined hook rather than three, matching\n * how `useGridSelection` already treats all three as one concern\n * internally.\n *\n * Before the grid mounts, the row/column fields read as empty arrays and\n * the cell field reads `{ kind: \"none\" }`; the actions are no-ops.\n */\nexport default function useSelectionState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): SelectionStateApi {\n const rowSelection = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getRowSelection(), []),\n FALLBACK_SELECTION,\n );\n const columnSelection = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnSelection(), []),\n FALLBACK_SELECTION,\n );\n const cellSelection = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getCellSelection(), []),\n FALLBACK_CELL_SELECTION,\n );\n\n return {\n rowSelection,\n columnSelection,\n cellSelection,\n clearSelection: () => {\n gridRef.current?.clearSelection();\n },\n selectAllRows: () => {\n gridRef.current?.selectAllRows();\n },\n };\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { AggregateResults } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_AGGREGATES: AggregateResults = new Map();\n\n/**\n * Reactive grand-total aggregate results read off a mounted\n * `DataGrid`'s `ref`, for a summary footer or bar living outside\n * the grid's own DOM — mirroring the built-in one the grid renders itself.\n *\n * Read-only: `getAggregates` is already read-only on `DataGridApi`, computed\n * over the whole filtered/sorted dataset rather than driven by any action.\n * A specific group's own subtotal is read off `getDisplayRows()`'s\n * per-header `aggregates` field instead — see `useGroupByState`.\n *\n * Before the grid mounts, reads as an empty map.\n */\nexport default function useAggregateState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): AggregateResults {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getAggregates(), []),\n FALLBACK_AGGREGATES,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnSizingState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_SIZING: ColumnSizingState = {};\n\n/**\n * Reactive column-sizing state read off a mounted `DataGrid`'s\n * `ref`. Reads only; change the widths through the ref's `setColumnSizing`,\n * or hold them yourself with the controlled `columnSizing` prop.\n *\n * Before the grid mounts, reads as an empty object.\n */\nexport default function useColumnSizingState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnSizingState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnSizing(), []),\n FALLBACK_SIZING,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnOrderState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_ORDER: ColumnOrderState = [];\n\n/**\n * Reactive column-order state read off a mounted `DataGrid`'s\n * `ref`. Reads only; change the order through the ref's `setColumnOrder`,\n * or hold it yourself with the controlled `columnOrder` prop.\n *\n * Before the grid mounts, reads as an empty array.\n */\nexport default function useColumnOrderState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnOrderState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnOrder(), []),\n FALLBACK_ORDER,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnVisibilityState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_VISIBILITY: ColumnVisibilityState = {};\n\n/**\n * Reactive column-visibility state read off a mounted `DataGrid`'s `ref` —\n * the columns shown or hidden since it mounted, keyed by id. Read-only:\n * change it through the ref's `showColumns`/`hideColumns`. A column absent\n * from it follows its definition's `hidden`.\n *\n * Before the grid mounts, reads as an empty object.\n */\nexport default function useColumnVisibilityState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnVisibilityState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnVisibility(), []),\n FALLBACK_VISIBILITY,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnPinningState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_PINNING: ColumnPinningState = {};\n\n/**\n * Reactive column-pinning state read off a mounted `DataGrid`'s `ref` — the\n * columns pinned or unpinned since it mounted, keyed by id. Read-only:\n * change it through the ref's `pinColumn`/`setColumnPinning`. A column\n * absent from it follows its definition's `pinned`.\n *\n * Before the grid mounts, reads as an empty object.\n */\nexport default function useColumnPinningState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnPinningState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnPinning(), []),\n FALLBACK_PINNING,\n );\n}\n","import { useCallback, useState, type RefObject } from \"react\";\nimport type { FilterState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nexport interface FilterStateApi<Row> {\n filter: FilterState<Row>;\n setFilter: (filter: FilterState<Row>) => void;\n}\n\n/**\n * Reactive filter state read off a mounted `DataGrid`'s `ref`, for a filter\n * bar or search box living outside the grid's own DOM, which sees every change\n * however it was made — the toolbar's search box included. `setFilter`\n * replaces the whole filter and sends the grid back to its first page.\n *\n * Before the grid mounts, `filter` reads as an empty array and `setFilter`\n * is a no-op.\n */\nexport default function useFilterState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): FilterStateApi<Row> {\n // Held per hook rather than as one module constant: a filter is typed by\n // its row, through a predicate's parameter, so one empty array cannot\n // stand in for every `Row`. Either way it must keep its identity.\n const [fallback] = useState<FilterState<Row>>(() => []);\n const filter = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getFilter(), []),\n fallback,\n );\n\n return {\n filter,\n setFilter: (next) => {\n gridRef.current?.setFilter(next);\n },\n };\n}\n"],"mappings":";;;AAAA;AAAA,EACE,aAAAA;AAAA,EACA,SAAAC;AAAA,EACA,uBAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,OAIK;AACP;AAAA,EACE,eAAAC;AAAA,EACA,2BAAAC;AAAA,EACA,oBAAAC;AAAA,EACA;AAAA,EACA;AAAA,OAuCK;AACP;AAAA,EACE;AAAA,EACA,gBAAAC;AAAA,EACA;AAAA,OACK;;;AC7CC;AAJO,SAAR,aAAmC,EAAE,QAAQ,GAA2B;AAC7E,SACE,oBAAC,cACE,kBAAQ,IAAI,CAAC,UACZ,oBAAC,SAAmB,OAAO,EAAE,OAAO,MAAM,MAAM,KAAtC,MAAM,EAAmC,CACpD,GACH;AAEJ;;;ACnBA,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;;;ACZ1B,SAAS,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IACA,WAAW,CAAC,SAAS;AACnB,cAAQ,SAAS,UAAU,IAAI;AAAA,IACjC;AAAA,EACF;AACF;;;AXqGA,SAAS,mBAAmB;","names":["useEffect","useId","useImperativeHandle","useMemo","useRef","useState","headerFocus","resolveColumnHeaderText","resolveColumnPin","pinnedWidths","jsx","jsx","jsxs","useMemo","useState","intentOf","writingDirection","jsx","jsxs","memo","jsx","jsxs","memo","memo","jsx","memo","jsx","jsxs","useMemo","useState","intentOf","jsx","jsx","jsxs","createPortal","resolveColumnLabel","inlineStep","writingDirection","useLayoutEffect","useRef","useState","useEffect","useState","useRef","useLayoutEffect","jsx","jsxs","resolveColumnLabel","inlineStep","writingDirection","createPortal","useMemo","runCommand","useRef","useRef","useRef","document","useMemo","writeClipboard","document","runCommand","useLayoutEffect","useRef","useState","useLayoutEffect","useRef","createPortal","writingDirection","jsx","writingDirection","useRef","useLayoutEffect","createPortal","jsx","jsxs","ChevronLeftIcon","ChevronRightIcon","Fragment","jsx","jsxs","isItem","ChevronRightIcon","useRef","useState","useLayoutEffect","jsx","useEffect","useLayoutEffect","useRef","bodyFocus","headerFocus","bodyCellFrom","bodyRowFrom","findBodyRow","groupRowFrom","writingDirection","useRef","useLayoutEffect","useEffect","useCallback","useLayoutEffect","useRef","useState","CLOSED","useRef","useLayoutEffect","useRef","useState","Fragment","jsx","jsxs","useEffect","useRef","resolveMenu","resolveColumnFilterMenu","useImperativeHandle","useLayoutEffect","useMemo","useReducer","useRef","useState","draftToFilter","filterDraftChanged","useLayoutEffect","useRef","useState","CLOSED","useState","useRef","useLayoutEffect","Fragment","jsx","jsxs","ChevronRightIcon","Fragment","useLayoutEffect","useRef","conditionsFromRows","filterDraftChanged","filterEditorReducer","jsx","jsxs","describeColumnFilter","initialFilterEditorDraft","showsAlike","jsx","jsxs","useRef","filterEditorReducer","filterDraftChanged","conditionsFromRows","useLayoutEffect","Fragment","useLayoutEffect","useRef","useState","Fragment","jsx","jsxs","useRef","useState","useLayoutEffect","Fragment","jsx","jsxs","useReducer","useState","useRef","useMemo","useLayoutEffect","useImperativeHandle","filterDraftChanged","draftToFilter","ChevronLeftIcon","jsx","jsxs","useRef","resolveColumnFilterMenu","useEffect","resolveMenu","useEffect","useState","useState","NO_ROWS","jsx","useRef","resolveColumnFilterMenu","useRef","writingDirection","headerCell","useRef","writingDirection","useLayoutEffect","useRef","Fragment","jsx","jsxs","useEffect","useRef","useState","jsx","useState","useRef","useEffect","useLayoutEffect","useRef","useState","jsx","jsxs","useRef","useLayoutEffect","resolveKeyboardDropTarget","resolveKeyboardDropTarget","useState","useState","useLayoutEffect","useState","useLayoutEffect","useState","useState","useSyncExternalStore","useEffect","useRef","useCallback","useLayoutEffect","useRef","useLayoutEffect","useRef","useState","bodyRowFrom","createRowVirtualizer","NO_ROWS","range","jsx","jsxs","useRef","useId","useMemo","useState","useEffect","resolveColumnHeaderText","resolveColumnPin","headerFocus","useImperativeHandle","pinnedWidths","useCallback","useCallback","useEffect","useRef","useSyncExternalStore","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useState","useState","useCallback"]}
|
|
1
|
+
{"version":3,"sources":["../src/DataGrid/DataGrid.tsx","../src/DataGrid/components/GridColgroup.tsx","../src/DataGrid/components/GridHeader.tsx","../src/DataGrid/ariaAttr.ts","../src/DataGrid/classNames.ts","../src/DataGrid/icons.tsx","../src/DataGrid/isOwnEvent.ts","../src/DataGrid/pinnedCell.ts","../src/DataGrid/useGridSelection.ts","../src/DataGrid/components/GridBody.tsx","../src/DataGrid/useGridNavigation.ts","../src/DataGrid/rowProps.ts","../src/DataGrid/components/GridEmptyRow.tsx","../src/DataGrid/components/GridGroupRow.tsx","../src/DataGrid/components/renderAggregate.ts","../src/DataGrid/components/GridGroupSummaryRow.tsx","../src/DataGrid/textAlign.ts","../src/DataGrid/components/GridRow.tsx","../src/DataGrid/components/GridFooter.tsx","../src/DataGrid/components/GridLoadingOverlay.tsx","../src/DataGrid/components/GridPager.tsx","../src/DataGrid/components/GroupByBar.tsx","../src/DataGrid/useGroupByDrag.ts","../src/DataGrid/useDragReorder.ts","../src/DataGrid/useGestureSignal.ts","../src/DataGrid/announcedCallbacks.ts","../src/DataGrid/clipboard/useGridCopy.ts","../src/DataGrid/commands/useGridCommands.ts","../src/DataGrid/clipboard/useCopyToClipboard.ts","../src/DataGrid/export/useSaveFile.ts","../src/DataGrid/export/exportApi.ts","../src/DataGrid/print/printApi.ts","../src/DataGrid/menu/GridMenu.tsx","../src/DataGrid/overlay/Overlay.tsx","../src/DataGrid/menu/menuIcons.tsx","../src/DataGrid/contextMenu/GridContextMenu.tsx","../src/DataGrid/contextMenu/useContextMenu.ts","../src/DataGrid/contextMenu/contextMenuPlaces.ts","../src/DataGrid/overlay/useGridOverlay.ts","../src/DataGrid/panels/GridPanels.tsx","../src/DataGrid/columnChooser/ColumnChooser.tsx","../src/DataGrid/filterMenu/FilterMenu.tsx","../src/DataGrid/filterMenu/ExcelFilterEditor.tsx","../src/DataGrid/filterMenu/excelEditorState.ts","../src/DataGrid/menu/useMenuButton.ts","../src/DataGrid/filterMenu/OperatorMenuButton.tsx","../src/DataGrid/filterMenu/SimpleFilterEditor.tsx","../src/DataGrid/filterMenu/ConditionRow.tsx","../src/DataGrid/filterMenu/simpleEditorState.ts","../src/DataGrid/filterMenu/ValueChecklist.tsx","../src/DataGrid/useAnnounceWhenDrawn.ts","../src/DataGrid/filterMenu/useApplyFilter.ts","../src/DataGrid/filterMenu/useFilterValueCache.ts","../src/DataGrid/panels/panelApi.ts","../src/DataGrid/panels/useGridPanels.ts","../src/DataGrid/toolbar/GridToolbar.tsx","../src/DataGrid/toolbar/ToolbarMenuButton.tsx","../src/DataGrid/toolbar/ToolbarSearch.tsx","../src/DataGrid/toolbar/useToolbarOverflow.ts","../src/DataGrid/useColumnDrag.ts","../src/DataGrid/useColumnResize.ts","../src/DataGrid/useElementHeight.ts","../src/DataGrid/useElementWidth.ts","../src/DataGrid/useGridController.ts","../src/DataGrid/useInfiniteScroll.ts","../src/DataGrid/useLiveAnnouncer.ts","../src/DataGrid/useRowVirtualizer.ts","../src/index.ts","../src/DataGrid/hooks/usePaginationState.ts","../src/DataGrid/hooks/useGridSnapshot.ts","../src/DataGrid/hooks/useGroupByState.ts","../src/DataGrid/hooks/useColumnSortState.ts","../src/DataGrid/hooks/useSelectionState.ts","../src/DataGrid/hooks/useAggregateState.ts","../src/DataGrid/hooks/useColumnSizingState.ts","../src/DataGrid/hooks/useColumnOrderState.ts","../src/DataGrid/hooks/useColumnVisibilityState.ts","../src/DataGrid/hooks/useColumnPinningState.ts","../src/DataGrid/hooks/useFilterState.ts"],"sourcesContent":["import {\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport {\n headerFocus,\n resolveColumnHeaderText,\n resolveColumnPin,\n resolveMessages,\n resolveRows,\n type ColumnDefinition as CoreColumnDefinition,\n type DataColumn as CoreDataColumn,\n type ResolvedColumn as CoreResolvedColumn,\n type AggregateResults,\n type AggregateState,\n type Borders,\n type ColumnOrderState,\n type ColumnPin,\n type ColumnPinningState,\n type ColumnSizingState,\n type ColumnSortState,\n type ColumnVisibilityState,\n type DataMode,\n type DisplayRow,\n type FilterState,\n type GridCommandTarget,\n type GridContextMenuTarget,\n type GridOptions,\n type GridState,\n type GridView,\n type GroupByBarVisibility,\n type GroupByState,\n type GroupExpansionState,\n type HoverableConfig,\n type PaginationState,\n type PaginationUnit,\n type ResizeMode,\n type ResolvedRow,\n type CellSelectionState,\n type SelectedCell as CoreSelectedCell,\n type SelectedColumn as CoreSelectedColumn,\n type SelectionState,\n type CellSelectEvent as CoreCellSelectEvent,\n type CellSelectionChangeEvent as CoreCellSelectionChangeEvent,\n type ColumnSelectEvent as CoreColumnSelectEvent,\n type ColumnSelectionChangeEvent as CoreColumnSelectionChangeEvent,\n type ColumnsSelectEvent as CoreColumnsSelectEvent,\n type SelectionCallbacks as CoreSelectionCallbacks,\n type SerializedGridState,\n type GridFocus,\n} from \"@gridkitjs/core\";\nimport {\n moveColumnInPinGroup,\n pinnedWidths,\n totalColumnWidth,\n} from \"@gridkitjs/core/renderer\";\nimport type { ColumnDropTarget } from \"@gridkitjs/dom\";\nimport GridColgroup from \"./components/GridColgroup\";\nimport GridHeader from \"./components/GridHeader\";\nimport GridBody from \"./components/GridBody\";\nimport GridFooter from \"./components/GridFooter\";\nimport GridLoadingOverlay from \"./components/GridLoadingOverlay\";\nimport GridPager from \"./components/GridPager\";\nimport GroupByBar from \"./components/GroupByBar\";\nimport { announcedCallbacks } from \"./announcedCallbacks\";\nimport { ariaAttr } from \"./ariaAttr\";\nimport { classNames } from \"./classNames\";\nimport useGridCopy from \"./clipboard/useGridCopy\";\nimport useGridCommands from \"./commands/useGridCommands\";\nimport GridContextMenu from \"./contextMenu/GridContextMenu\";\nimport useContextMenu from \"./contextMenu/useContextMenu\";\nimport { exportApi, type GridExportApi } from \"./export/exportApi\";\nimport { isOwnEvent } from \"./isOwnEvent\";\nimport useGridOverlay from \"./overlay/useGridOverlay\";\nimport GridPanels from \"./panels/GridPanels\";\nimport { panelApi, type GridPanelApi } from \"./panels/panelApi\";\nimport { printApi, type GridPrintApi } from \"./print/printApi\";\nimport useGridPanels from \"./panels/useGridPanels\";\nimport GridToolbar from \"./toolbar/GridToolbar\";\nimport useColumnDrag from \"./useColumnDrag\";\nimport useColumnResize from \"./useColumnResize\";\nimport useElementHeight from \"./useElementHeight\";\nimport useElementWidth from \"./useElementWidth\";\nimport useGridController, {\n type DataGridController,\n} from \"./useGridController\";\nimport useGridNavigation from \"./useGridNavigation\";\nimport useGridSelection from \"./useGridSelection\";\nimport useInfiniteScroll from \"./useInfiniteScroll\";\nimport useLiveAnnouncer from \"./useLiveAnnouncer\";\nimport useRowVirtualizer from \"./useRowVirtualizer\";\n\n/**\n * A column whose header and cells may render arbitrary React content.\n * @gridkitjs/core stays framework-agnostic and so leaves that output type open;\n * this is the binding React consumers want, and the one they should import.\n */\nexport type ColumnDefinition<Row> = CoreColumnDefinition<Row, ReactNode>;\n\n/** A column paired with the width it renders at. */\nexport type ResolvedColumn<Row> = CoreResolvedColumn<Row, ReactNode>;\n\n/** A column paired with its id, hidden or not — what `getDataColumns()` lists. */\nexport type DataColumn<Row> = CoreDataColumn<Row, ReactNode>;\n\n/**\n * The selection payloads, bound to React's node type for the same reason\n * `ColumnDefinition` is: they carry a resolved column, whose label is whatever\n * a `headerTemplate` returned.\n *\n * The row payloads name no node type at all and so are re-exported from\n * `@gridkitjs/core` as they are.\n */\nexport type SelectedColumn<Row> = CoreSelectedColumn<Row, ReactNode>;\nexport type SelectedCell<Row> = CoreSelectedCell<Row, ReactNode>;\nexport type ColumnSelectEvent<Row> = CoreColumnSelectEvent<Row, ReactNode>;\nexport type ColumnsSelectEvent<Row> = CoreColumnsSelectEvent<Row, ReactNode>;\nexport type ColumnSelectionChangeEvent<Row> = CoreColumnSelectionChangeEvent<\n Row,\n ReactNode\n>;\nexport type CellSelectEvent<Row> = CoreCellSelectEvent<Row, ReactNode>;\nexport type CellSelectionChangeEvent<Row> = CoreCellSelectionChangeEvent<\n Row,\n ReactNode\n>;\nexport type SelectionCallbacks<Row> = CoreSelectionCallbacks<Row, ReactNode>;\n\n/**\n * Imperative handle for a mounted `DataGrid`, reached via its `ref` prop:\n * the grid's DOM nodes, getters for its live state, the actions every grid\n * ref carries (focus, select all, scroll-to), and a setter for every slice of\n * state, for a toolbar, a saved layout or a test to drive it from outside.\n *\n * Every getter reads the grid's state at call time, so a read straight after\n * an action sees its result. Every setter changes the grid as the user's own\n * interaction would: it fires the slice's `on*Change` callback, and, for a\n * slice held through a controlled prop, only asks. `subscribe` is the\n * notify channel for state that changes; see\n * `packages/react/src/DataGrid/hooks/` for the public hooks built on it.\n */\nexport interface DataGridApi<Row>\n extends GridExportApi, GridPrintApi, GridPanelApi {\n /**\n * The grid's root element, `.gridkit-data-grid-viewport`. The tables\n * scroll inside it, in `.gridkit-data-grid-tables`, not on it.\n */\n readonly element: HTMLDivElement | null;\n /**\n * The grid's row-area `<table>` element — the one holding `<tbody>`. The\n * header and, when aggregates are active, footer render as their own\n * sibling `<table>`s outside this one; use `element` to reach the whole\n * grid instead.\n */\n readonly table: HTMLTableElement | null;\n\n /** Rows as currently filtered and sorted — what's rendered, ungrouped. */\n getRows(): readonly ResolvedRow<Row>[];\n /**\n * `getRows()` regrouped into the active `groupBy` — group headers\n * interleaved with data rows, in render order. Identical to `getRows()`\n * when `groupBy` is empty.\n */\n getDisplayRows(): readonly DisplayRow<Row>[];\n /**\n * The current page of `getDisplayRows()` — exactly the rows the body\n * renders. All of `getDisplayRows()` when `paginated` is off.\n */\n getPageRows(): readonly DisplayRow<Row>[];\n /** Columns as currently sized and ordered — what's rendered, so hidden columns are left out. */\n getColumns(): readonly ResolvedColumn<Row>[];\n /** Every column in its current order, hidden ones included — what sorting, filtering and grouping read. */\n getDataColumns(): readonly DataColumn<Row>[];\n\n getColumnSizing(): ColumnSizingState;\n getColumnOrder(): ColumnOrderState;\n /** Columns shown or hidden since the grid mounted. A column absent from it follows its definition's `hidden`. */\n getColumnVisibility(): ColumnVisibilityState;\n /** Columns pinned or unpinned since the grid mounted. A column absent from it follows its definition's `pinned`. */\n getColumnPinning(): ColumnPinningState;\n getColumnSort(): ColumnSortState;\n /** The filter the rows are shown through — every entry, ANDed together. */\n getFilter(): FilterState<Row>;\n getGroupBy(): GroupByState;\n getGroupExpansion(): GroupExpansionState;\n /** The active page and page size. Meaningful even when `paginated` is off — it stays at page 0 over the grid's whole (single) page. */\n getPagination(): PaginationState;\n /** How many pages the current `pagination.pageSize` splits the grid's rows into — `1` whenever `paginated` is off. */\n getPageCount(): number;\n /**\n * The grand-total aggregate results — every active aggregate computed over\n * the whole filtered/sorted dataset, ungrouped and unpaginated. A specific\n * group's own results are read off `getDisplayRows()` instead, on that\n * group header's `aggregates` field.\n */\n getAggregates(): AggregateResults;\n getRowSelection(): SelectionState;\n /**\n * The selected rows themselves, in the order they were selected — among\n * every row the filter lets through, on any page or in any group, so a row\n * filtered out while selected is left out until it is back.\n */\n getSelectedRows(): readonly ResolvedRow<Row>[];\n getColumnSelection(): SelectionState;\n getCellSelection(): CellSelectionState;\n /**\n * The cell currently holding the grid's single tab stop, in the shape\n * `focusCell` takes. Returns the same object until the focus moves.\n */\n getFocusedCell(): GridFocus;\n /**\n * Every slice of state as the grid applies it, in one object — what\n * `restoreState` takes back. Pass it through `serializeGridState` before\n * saving it as JSON.\n */\n getState(): GridState<Row>;\n /**\n * Puts back state saved earlier, whole or in part — from `getState()`, or\n * from `serializeGridState` and back through JSON. Each slice given is set\n * as its setter would set it, firing its callback when it changes; the\n * grid re-renders once. Saved state is read by its `version`; one without\n * a version, saved by an earlier release, still restores, and one newer\n * than this release reads throws.\n */\n restoreState(\n saved: Partial<GridState<Row>> | Partial<SerializedGridState<Row>>,\n ): void;\n\n /**\n * Moves the grid's tab stop, and the browser's focus, to a cell:\n * `{ area: \"body\", rowIndex, columnIndex }` or\n * `{ area: \"header\", columnIndex }`. Either index is held inside the grid.\n */\n focusCell(focus: GridFocus): void;\n clearSelection(): void;\n selectAllRows(): void;\n /**\n * Selects rows by id, as far as `selectable.rows` allows: `\"replace\"` (the\n * default) selects exactly these — only the last of them under\n * `\"single\"` — and `\"toggle\"` flips each one. Fires the row selection\n * callbacks once for the whole call, and none when nothing changed.\n */\n selectRows(rowIds: readonly string[], intent?: \"replace\" | \"toggle\"): void;\n /** Expands every group at once, as the `group.expandAll` command does. */\n expandAllGroups(): void;\n /** Collapses every group at once, as the `group.collapseAll` command does — one nested under a collapsed group, and one that appears later, too. */\n collapseAllGroups(): void;\n /** Moves to the given page, clamped into range. */\n goToPage(pageIndex: number): void;\n /** Moves to the next page. A no-op on the last page. */\n nextPage(): void;\n /** Moves to the previous page. A no-op on the first page. */\n previousPage(): void;\n /** Changes the page size, resetting to the first page. */\n setPageSize(pageSize: number): void;\n /**\n * Shows the columns with the given ids, each in the place it held when\n * hidden. Reports one `onColumnVisibilityChange` for the whole call, and\n * none if every column was already showing.\n */\n showColumns(columnIds: readonly string[]): void;\n /**\n * Hides the columns with the given ids. A hidden column still sorts,\n * filters and groups, and keeps its place in the column order.\n */\n hideColumns(columnIds: readonly string[]): void;\n /**\n * Pins a column to the `\"start\"` or `\"end\"` edge, or unpins it with\n * `\"none\"`, leaving the column order as it is: an unpinned column goes\n * back to its place among the others. Reports one\n * `onColumnPinningChange`, and none when the column is already there.\n */\n pinColumn(columnId: string, pin: ColumnPin): void;\n /**\n * Replaces the filter, the way a filter UI would, and sends an uncontrolled\n * grid back to its first page. Reports one `onFilterChange`, and none when\n * `filter` is equal to the current one. With a controlled `filter` prop it\n * only asks, as any change does.\n */\n setFilter(filter: FilterState<Row>): void;\n /**\n * Replaces the sort. Reports one `onColumnSortChange`, naming the first\n * column whose place or direction changed, and none for an equal sort —\n * the rule every setter below follows for its own slice and callback.\n */\n setColumnSort(sort: ColumnSortState): void;\n /** Replaces the group-by stack. Reports through `onGroupByChange`. */\n setGroupBy(groupBy: GroupByState): void;\n /** Replaces the group expansion. Reports through `onGroupExpansionChange` with `groupId: null`, and nothing for an equal expansion. */\n setGroupExpansion(expansion: GroupExpansionState): void;\n /** Replaces the page and page size as given. Reports through `onPaginationChange`. */\n setPagination(pagination: PaginationState): void;\n /** Replaces the column widths. Reports through `onColumnSizingChange`, as the `\"end\"` of a resize. */\n setColumnSizing(sizing: ColumnSizingState): void;\n /** Replaces the column order. Reports through `onColumnOrderChange`. */\n setColumnOrder(order: ColumnOrderState): void;\n /** Replaces the column visibility state. Reports through `onColumnVisibilityChange`. */\n setColumnVisibility(visibility: ColumnVisibilityState): void;\n /** Replaces the column pinning state. Reports through `onColumnPinningChange`. */\n setColumnPinning(pinning: ColumnPinningState): void;\n /** Replaces the selected row ids as given, whatever `selectable` allows. Fires the row selection callbacks. */\n setRowSelection(selection: SelectionState): void;\n /** Replaces the selected column ids as given. Fires the column selection callbacks. */\n setColumnSelection(selection: SelectionState): void;\n /** Replaces the cell selection as given, `{ kind: \"none\" }` for none. Fires the cell selection callbacks. */\n setCellSelection(selection: CellSelectionState): void;\n /**\n * Sizes a shown column to fit its content, as double-clicking its resize\n * handle does, reporting through `onColumnSizingChange`. A hidden column, or one\n * with no rows to measure, is left as it is.\n */\n autoFitColumn(columnId: string): void;\n /**\n * `autoFitColumn` for each of the given columns, or for every column shown\n * when given none.\n */\n autoFitColumns(columnIds?: readonly string[]): void;\n /**\n * Opens the context menu `target` has, as a right-click there would —\n * selecting it and focusing its cell first — beside `anchor`, a point in\n * viewport coordinates or an element, or else below its cell, in place of\n * any panel open. Says whether it opened: not for a target not on screen,\n * nor where `contextMenu` gives no menu.\n */\n openContextMenu(\n target: GridContextMenuTarget,\n anchor?: { readonly x: number; readonly y: number } | Element,\n ): boolean;\n /** Closes the context menu, if one is open. */\n closeContextMenu(): void;\n /**\n * Runs a command by id — a built-in or one of `commands` — on `target`,\n * `{ area: \"grid\" }` when left out, when it is visible and enabled there.\n * Reports it through `onCommand` with `source: \"api\"`, and says whether it\n * ran.\n */\n runCommand(commandId: string, target?: GridCommandTarget): boolean;\n /** Scrolls the row with the given id into view, if it is currently shown. */\n scrollToRow(rowId: string, options?: ScrollIntoViewOptions): void;\n /** Scrolls the column with the given id into view. */\n scrollToColumn(columnId: string, options?: ScrollIntoViewOptions): void;\n\n /**\n * Registers `listener` to be called after any render in which the grid's\n * internal state may have changed — every getter above may return a\n * different value once `listener` fires, not just one. Returns an\n * unsubscribe function. The primitive the `use*State` hooks under\n * `packages/react/src/DataGrid/hooks/` build on; most consumers should\n * reach for one of those instead of calling `subscribe` directly.\n */\n subscribe(listener: () => void): () => void;\n}\n\n/**\n * Defined in `@gridkitjs/core` with the rest of `GridOptions`, and exported\n * from here too so a React consumer needs one import.\n */\nexport type {\n Borders,\n DataMode,\n GroupByBarVisibility,\n HoverableConfig,\n PaginationUnit,\n ResizeMode,\n};\n\n/**\n * A stable empty fallback for an omitted `aggregates` prop, for the parts of\n * the grid that draw aggregate cells — a fresh `[]` every render would hand\n * them a new array each time.\n */\nconst NO_AGGREGATES: AggregateState<never> = [];\n\n/**\n * `DataGridApi.getPagination`, read off `controller` at call time: the page\n * shown — clamped, unlike the stored index — and the page size. The same\n * object while both stay the same, since a `useSyncExternalStore` snapshot\n * built fresh on every read makes React warn and re-render forever.\n */\nfunction paginationReader<Row>(\n controller: DataGridController<Row>,\n): () => PaginationState {\n let last: PaginationState | undefined;\n return () => {\n const { pageIndex } = controller.getView();\n const { pageSize } = controller.getState().pagination;\n if (last?.pageIndex !== pageIndex || last.pageSize !== pageSize) {\n last = { pageIndex, pageSize };\n }\n return last;\n };\n}\n\n/**\n * Everything a `pager.template` render prop needs to rebuild the built-in\n * pager's UI itself. Passed fresh on every render where pagination-relevant\n * state changed, so it's current by construction — unlike `DataGridApi`'s\n * imperative methods and snapshot getters, which carry no \"something\n * changed, re-render\" signal of their own.\n */\nexport interface PagerTemplateContext {\n /** Same shape as `DataGridApi.getPagination()` — 0-based `pageIndex`. */\n pagination: PaginationState;\n /** `pagination.pageIndex + 1`, clamped — the display-ready page number. */\n currentPage: number;\n pageCount: number;\n /** Passthrough of `pager.sizeOptions`, undefined when not given. */\n pageSizeOptions: readonly number[] | undefined;\n /** 0-based, same as `DataGridApi.goToPage` — not `currentPage`'s numbering. */\n goToPage: (pageIndex: number) => void;\n nextPage: () => void;\n previousPage: () => void;\n setPageSize: (pageSize: number) => void;\n}\n\n/** Presentation options for the grid's built-in pager. */\nexport interface PagerConfig {\n /** Page sizes offered by the built-in pager's page-size control. */\n sizeOptions?: readonly number[] | undefined;\n /** Defaults to `\"compact\"` — today's Prev/status/Next. */\n variant?: \"compact\" | \"numbered\" | undefined;\n /** Numbered variant only. How many pages to always show at each end. Defaults to 1. */\n boundaryCount?: number | undefined;\n /** Numbered variant only. How many pages to show on each side of the current page. Defaults to 1. */\n siblingCount?: number | undefined;\n /** Replaces the built-in pager entirely when given. `variant` is ignored. */\n template?: ((context: PagerTemplateContext) => ReactNode) | undefined;\n}\n\n/**\n * Loads more rows as the user scrolls near the bottom, in place of paging.\n * Appends only — there is no equivalent of `paginated`'s reset-to-page-0 for\n * a result set that shrinks out from under the current position.\n */\nexport interface InfiniteScrollConfig {\n /** Whether a further `onLoadMore` could still return more rows. `false` removes the sentinel entirely, so no further scrolling can trigger a load. */\n readonly hasMore: boolean;\n /**\n * Called when the sentinel comes within `rootMargin` of the body's\n * viewport, then not again until one of these says the request was\n * answered: `isLoadingMore` goes back to `false`, `hasMore` changes, the\n * sentinel leaves range and comes back, or rows appended while\n * `isLoadingMore` never read `true` move the sentinel down.\n */\n readonly onLoadMore: () => void;\n /** Whether a load triggered by `onLoadMore` is still in flight. Suppresses further calls to it until this goes back to `false`. */\n readonly isLoadingMore?: boolean | undefined;\n /**\n * How far from the bottom of the scrollable body `onLoadMore` fires, ahead\n * of the sentinel actually scrolling into view, as CSS margins — an\n * intersection observer's `rootMargin`. Defaults to `\"200px\"`.\n */\n readonly rootMargin?: string | undefined;\n /** Replaces the built-in \"Loading more…\" row (`messages.loadingMore`). */\n readonly loadingTemplate?: (() => ReactNode) | undefined;\n}\n\n/** What an `emptyTemplate` is handed when the grid has no rows to show. */\nexport interface EmptyTemplateContext {\n /**\n * Whether a filter or the toolbar's search is active: the rows may be\n * hidden by it rather than missing. It is how the built-in message picks\n * `messages.noMatchingRows` over `messages.noRows`.\n */\n readonly filtered: boolean;\n}\n\n/**\n * The props that name a React type, and so have no place in the\n * framework-free `GridOptions`: columns whose templates return `ReactNode`,\n * the pager and infinite-scroll configs whose templates do too, the empty\n * and loading templates and the toolbar's custom entries.\n */\nexport interface ReactRenderSlots<Row> {\n columns?: readonly ColumnDefinition<Row>[] | undefined;\n /** Presentation options for the built-in pager. */\n pager?: PagerConfig | undefined;\n /**\n * Loads more rows as the user scrolls near the bottom, instead of paging.\n * Mutually exclusive with `paginated` — setting both logs a dev-time\n * `console.error` and only `paginated` takes effect. Recommended (not\n * required) alongside `virtualized` for a dataset that grows without\n * bound, so the mounted row count never grows with it either.\n */\n infiniteScroll?: InfiniteScrollConfig | undefined;\n /**\n * Replaces the content of the message shown in place of the rows when\n * there are none to show (`messages.noRows`, or `messages.noMatchingRows`\n * while a filter hides every row). One that returns `null` leaves the\n * body blank.\n */\n emptyTemplate?: ((context: EmptyTemplateContext) => ReactNode) | undefined;\n /**\n * Replaces the content of the overlay shown over the body while `loading`\n * is on (`messages.loading`). Unrelated to `infiniteScroll.loadingTemplate`,\n * the row shown while infinite scroll loads more.\n */\n loadingTemplate?: (() => ReactNode) | undefined;\n /** Draws the toolbar's custom entries — `{ type: \"custom\", id }` — by id. */\n renderToolbarItem?: ((id: string) => ReactNode) | undefined;\n}\n\n/**\n * Every grid setting in `@gridkitjs/core`'s `GridOptions`, plus what only\n * React can express: render slots, selection callbacks carrying React-bound\n * columns, and the `ref`.\n */\nexport interface DataGridProps<Row>\n extends GridOptions<Row>, ReactRenderSlots<Row>, SelectionCallbacks<Row> {\n /** Imperative handle for reading live grid state and triggering actions. */\n ref?: Ref<DataGridApi<Row>> | undefined;\n}\n\n/**\n * `DataGridApi.getSelectedRows`, read off `controller` at call time: the\n * selected ids resolved against every filtered row. Recomputed only when the\n * rows or the selection change, so repeated reads are cheap and return the\n * same array.\n */\nfunction selectedRowsReader<Row>(\n controller: DataGridController<Row>,\n): () => readonly ResolvedRow<Row>[] {\n let last:\n | {\n readonly rows: readonly ResolvedRow<Row>[];\n readonly selection: SelectionState;\n readonly selected: readonly ResolvedRow<Row>[];\n }\n | undefined;\n return () => {\n const { rows } = controller.getView();\n const selection = controller.getState().rowSelection;\n if (last?.rows !== rows || last.selection !== selection) {\n const rowsById = new Map(rows.map((entry) => [entry.rowId, entry]));\n last = { rows, selection, selected: resolveRows(rowsById, selection) };\n }\n return last.selected;\n };\n}\n\n/**\n * The custom properties the scroll area's rules read, each set only when it\n * applies, so a grid with no `height` and no pinned column gets no `style`:\n * the rows' height and what the header and footer add to it, under\n * `height`, and the width pinned to each edge, while a column is pinned.\n */\nfunction tablesStyle(\n height: number | string | undefined,\n headerHeight: number | null,\n footerHeight: number | null,\n pinned: { readonly start: number; readonly end: number },\n): CSSProperties | undefined {\n const heights =\n height === undefined\n ? {}\n : {\n \"--gridkit-body-height\":\n typeof height === \"number\" ? `${String(height)}px` : height,\n ...(headerHeight === null\n ? {}\n : { \"--gridkit-header-height\": `${String(headerHeight)}px` }),\n ...(footerHeight === null\n ? {}\n : { \"--gridkit-footer-height\": `${String(footerHeight)}px` }),\n };\n const widths =\n pinned.start === 0 && pinned.end === 0\n ? {}\n : {\n \"--gridkit-pinned-start-width\": `${String(pinned.start)}px`,\n \"--gridkit-pinned-end-width\": `${String(pinned.end)}px`,\n };\n const style = { ...heights, ...widths };\n return Object.keys(style).length === 0 ? undefined : (style as CSSProperties);\n}\n\n/**\n * What the empty message is handed, or `null` while it does not show: while\n * there are rows, in a grid with no columns for it to span, while the app\n * says it is loading, and while infinite scroll can still load more. The\n * sentinel of an empty body is in view, so that load is already starting,\n * and its loading row is what the body shows meanwhile.\n */\nfunction emptyContext<Row>(\n view: GridView<Row, ReactNode>,\n filter: FilterState<Row>,\n loading: boolean,\n infiniteScroll: InfiniteScrollConfig | undefined,\n): EmptyTemplateContext | null {\n if (\n view.pageRows.length > 0 ||\n view.columns.length === 0 ||\n loading ||\n infiniteScroll?.hasMore === true\n ) {\n return null;\n }\n return { filtered: filter.length > 0 };\n}\n\nexport function DataGrid<Row>(props: DataGridProps<Row>) {\n const {\n borders,\n hoverable,\n selectable,\n resizeMode = \"fit\",\n columnSizeDefaults,\n sortableColumns = false,\n groupableColumns = false,\n groupToggleIconColumns = true,\n groupByBarVisibility = \"auto\",\n loading = false,\n paginated = false,\n pager,\n infiniteScroll,\n aggregates = NO_AGGREGATES as AggregateState<Row>,\n groupAggregateDisplay = \"inline\",\n height,\n virtualized = false,\n overscan = 4,\n estimatedRowHeight = 40,\n label,\n labelledBy,\n locale,\n getRowProps,\n onRowClick,\n onRowDoubleClick,\n messages: messageOverrides,\n ref,\n } = props;\n const hoverRows = hoverable?.rows ?? true;\n const hoverColumns = hoverable?.columns ?? true;\n const hoverCells = hoverable?.cells ?? true;\n\n const viewportRef = useRef<HTMLDivElement>(null);\n const gridRef = useRef<HTMLDivElement>(null);\n const headerTableRef = useRef<HTMLTableElement>(null);\n const bodyTableRef = useRef<HTMLTableElement>(null);\n const bodyRef = useRef<HTMLDivElement>(null);\n const footerTableRef = useRef<HTMLTableElement>(null);\n const sentinelRef = useRef<HTMLTableRowElement>(null);\n // The tables' scroll area rather than the viewport: a vertical scrollbar\n // takes its width from the scroll area, and columns filling the viewport\n // would then overflow it by that much.\n const viewportWidth = useElementWidth(gridRef, resizeMode === \"fit\");\n const subscribersRef = useRef(new Set<() => void>());\n /** The grid element's id, for the toolbar's `aria-controls`. */\n const gridId = useId();\n /** Reports a change no visual cue can carry to a screen reader. */\n const announce = useLiveAnnouncer(viewportRef);\n /** Every string the grid shows or announces, `messages` over the English defaults. */\n const messages = useMemo(\n () => resolveMessages(messageOverrides, locale),\n [messageOverrides, locale],\n );\n\n /**\n * Every slice of grid state, and everything the grid draws, comes from\n * here. The change callbacks go in wrapped, so each change is announced\n * where the controller reports it — see `announcedCallbacks`.\n */\n const { controller, state, view } = useGridController<Row>({\n ...props,\n viewportWidth,\n ...announcedCallbacks({\n callbacks: props,\n announce,\n messages,\n columnName,\n columnOf,\n }),\n });\n\n /**\n * `getPagination()`'s value: the page shown — clamped, unlike the stored\n * index — and the page size, kept as one object while both stay the same.\n * Read live off the controller rather than this render, so a read straight\n * after an action sees it.\n */\n const [readPagination] = useState(() => paginationReader(controller));\n const [readSelectedRows] = useState(() => selectedRowsReader(controller));\n\n /**\n * `enabled` is `virtualized` alone, independent of `height`: an `auto`\n * height body has no `overflow`, so its measured `clientHeight` covers\n * the whole content and the computed range naturally comes out as\n * everything anyway — the dev-time warning below is what tells a consumer\n * that combination does nothing useful, not a behavioral gate here.\n */\n const virtualizer = useRowVirtualizer({\n enabled: virtualized,\n rows: view.pageRows,\n scrollRef: gridRef,\n bodyTableRef,\n estimatedRowHeight,\n overscan,\n });\n\n useEffect(() => {\n if (virtualized && height === undefined) {\n console.error(\n \"DataGrid: `virtualized` has no effect without `height` — a body with no bounded height has no viewport to window rows against.\",\n );\n }\n }, [virtualized, height]);\n\n const hasInfiniteScroll = infiniteScroll !== undefined;\n useEffect(() => {\n if (paginated && hasInfiniteScroll) {\n console.error(\n \"DataGrid: `paginated` and `infiniteScroll` are mutually exclusive — only `paginated` takes effect while both are set.\",\n );\n }\n }, [paginated, hasInfiniteScroll]);\n\n const serverPagesUncounted =\n props.dataMode === \"server\" && paginated && props.rowCount === undefined;\n useEffect(() => {\n if (serverPagesUncounted) {\n console.error(\n 'DataGrid: a `paginated` grid under `dataMode: \"server\"` needs `rowCount` — without it the pager counts only the rows given, one page. Pass `0` until the first response.',\n );\n }\n }, [serverPagesUncounted]);\n\n useInfiniteScroll({\n rootRef: gridRef,\n sentinelRef,\n config: infiniteScroll,\n });\n\n const empty = emptyContext(view, state.filter, loading, infiniteScroll);\n // A `\"fit\"` grid measures the scroll area already; another measures it\n // only while the empty message or the loading overlay needs it.\n const messageWidth = useElementWidth(\n gridRef,\n (empty !== null || loading) && resizeMode !== \"fit\",\n );\n const bodyViewportWidth = viewportWidth ?? messageWidth;\n\n // Once per load, as it starts: the rows that arrive announce themselves\n // through the result announcements already in place.\n useEffect(() => {\n if (loading) {\n announce(messages.loading);\n }\n }, [loading, announce, messages.loading]);\n\n /** A column's definition by id, hidden ones included. */\n function columnOf(columnId: string): ColumnDefinition<Row> | undefined {\n return view.dataColumns.find((candidate) => candidate.id === columnId)\n ?.column;\n }\n\n /** What a column is called in an announcement — see `resolveColumnHeaderText`. */\n function columnName(columnId: string): string {\n const column = columnOf(columnId);\n return column === undefined ? columnId : resolveColumnHeaderText(column);\n }\n\n const resize = useColumnResize<Row>({\n // `@gridkitjs/dom`'s `measureColumnContent` only ever matches\n // `td[data-gridkit-column]` (never `th`), so the header table has nothing\n // for it to find — the body table alone was already the effective scope\n // before this split.\n tableRef: bodyTableRef,\n controller,\n columnSizeDefaults,\n });\n const nav = useGridNavigation({\n gridRef,\n headerTableRef,\n bodyTableRef,\n // `null` when virtualization is off, in which case behavior is\n // byte-for-byte unchanged from before this feature existed.\n virtualRange: virtualized ? virtualizer : null,\n // Group headers are addressable rows too — the whole point of the flat\n // `DisplayRow[]` shape is that they share one position space with data\n // rows, so navigation counts them the same way. Page-relative\n // (`view.pageRows`, not `view.displayRows`): arrow keys operate on what's\n // actually in the DOM, which is the current page — a different \"page\"\n // concept than `useGridNavigation`'s own Page Up/Down viewport scrolling.\n rowCount: view.pageRows.length,\n columnCount: view.columns.length,\n // A group's own summary row (`groupAggregateDisplay: \"row\"`) occupies a\n // real slot in `rowCount` above — its DOM position has to line up with\n // everything else — but is presentational, never a tab stop: arrow-key\n // vertical movement steps over it rather than landing there.\n isSkippableRow: (rowIndex) => {\n const entry = view.pageRows[rowIndex];\n return entry?.kind === \"group-summary\";\n },\n });\n\n const overlay = useGridOverlay({\n nav,\n onContextMenuOpenChange: props.onContextMenuOpenChange,\n });\n const panels = useGridPanels({\n rootRef: viewportRef,\n headerTableRef,\n overlay,\n });\n const commands = useGridCommands({\n controller,\n commands: props.commands,\n onCommand: props.onCommand,\n messages,\n announce,\n resize,\n openPanel: panels.open,\n });\n const handleCopyKey = useGridCopy({ controller, commands, nav });\n\n /**\n * Every id in display order, hidden ones included — the list a column\n * move is made among, so a hidden column keeps its slot through a move\n * made around it.\n */\n const orderedIds = useMemo(\n () => view.dataColumns.map((entry) => entry.id),\n [view.dataColumns],\n );\n\n /**\n * The ids of the columns on screen, which a drag or a keyboard move is\n * resolved against: a move one place left has to pass the next visible\n * column, not stop in front of a hidden one and appear to do nothing.\n */\n const displayedIds = useMemo(\n () => view.columns.map((entry) => entry.id),\n [view.columns],\n );\n\n /** Every column's definition by id, hidden ones included, for a group header naming a hidden column. */\n const definitions = useMemo(\n () => new Map(view.dataColumns.map((entry) => [entry.id, entry.column])),\n [view.dataColumns],\n );\n\n /** Column ids whose header may be dragged into the group-by bar at all. */\n const groupByDraggableIds = useMemo(\n () =>\n new Set(\n view.columns\n .filter((entry) => entry.groupByDraggable)\n .map((entry) => entry.id),\n ),\n [view.columns],\n );\n\n /** The edge a column is pinned to, hidden ones included. */\n function pinOf(columnId: string): ColumnPin {\n const column = definitions.get(columnId);\n return column === undefined\n ? \"none\"\n : resolveColumnPin(column, state.columnPinning);\n }\n\n /**\n * The one place a drop is applied — the two-armed switch on `target.kind`\n * the group-by bar's own second drop zone was always going to need.\n */\n function handleDrop(target: ColumnDropTarget, movedId: string): void {\n if (target.kind === \"group-by\") {\n // Already announced: `moveGroupBy` reports through the same\n // `onGroupByChange` pipeline the header toggle and the bar's own chip\n // drag do, so this needs no announcement or focus-follow of its own —\n // unlike a column-order drop, the moved thing leaves the grid's single\n // tab-stop system entirely for the bar's own independently-focusable\n // chips, which have no shared index to update.\n controller.moveGroupBy(movedId, target.beforeColumnId);\n return;\n }\n\n // The order the controller will arrive at, worked out here as well for\n // where the column lands on screen. `moveColumnInPinGroup` hands back\n // the same reference for a move that changes nothing, a move past the\n // edge of the column's pin group included, so a drop in place neither\n // renders nor reports.\n const next = moveColumnInPinGroup(\n orderedIds,\n pinOf,\n movedId,\n target.beforeId,\n );\n if (next === orderedIds) {\n return;\n }\n controller.moveColumn(movedId, target.beforeId);\n // Counted among the columns on screen, which is what the user can see\n // and what the tab stop indexes. The move stays inside the column's pin\n // group, which starts where it did and keeps the new order within it.\n const pin = pinOf(movedId);\n const group = next.filter(\n (id) => pinOf(id) === pin && displayedIds.includes(id),\n );\n const position =\n displayedIds.findIndex((id) => pinOf(id) === pin) +\n group.indexOf(movedId);\n announce(\n messages.columnMoved(\n columnName(movedId),\n position + 1,\n displayedIds.length,\n ),\n );\n /**\n * The tab stop travels with the column. React reorders the headers by key,\n * so the browser's focus stays on the moved one by itself — without this\n * the stop would be left on whichever column took its index, and the next\n * arrow key would appear to do nothing.\n */\n nav.focusCell(headerFocus(position));\n }\n\n const drag = useColumnDrag<Row>({\n order: displayedIds,\n groupBy: state.groupBy,\n groupByDraggableIds,\n pinOf,\n onDrop: handleDrop,\n });\n\n /** Whether the header drag currently open (if any) is for a column already in the group-by stack — reordering it is the chip's job, so dragging it back in is never a valid target. */\n const draggedColumnAlreadyGrouped =\n drag.draggedColumnId !== null &&\n state.groupBy.some((entry) => entry.columnId === drag.draggedColumnId);\n\n /**\n * Whether the drag currently open (if any) could land on the group-by bar\n * — the signal `groupByBarVisibility=\"auto\"` needs to show the bar as a\n * drop target even while `groupBy` is still empty. Depends only on\n * `draggedColumnId` (set once the drag opens), the static\n * `groupByDraggableIds`, and whether that column is already grouped, never\n * the pointer's current position, so the bar mounts for the drag's whole\n * duration rather than flickering in only while directly hovering it.\n */\n const dragEligibleForGroupBy =\n drag.draggedColumnId !== null &&\n groupByDraggableIds.has(drag.draggedColumnId) &&\n !draggedColumnAlreadyGrouped;\n\n const showGroupByBar =\n groupByBarVisibility === \"always\" ||\n (groupByBarVisibility === \"auto\" &&\n (state.groupBy.length > 0 || dragEligibleForGroupBy));\n\n const headerGroupByDropTarget =\n drag.dropTarget?.kind === \"group-by\" ? drag.dropTarget : null;\n\n /** What the built-in pager draws, and what a `pager.template` is handed. */\n const pagerContext: PagerTemplateContext = {\n pagination: state.pagination,\n currentPage: Math.min(state.pagination.pageIndex + 1, view.pageCount),\n pageCount: view.pageCount,\n pageSizeOptions: pager?.sizeOptions,\n goToPage: controller.goToPage,\n nextPage: controller.nextPage,\n previousPage: controller.previousPage,\n setPageSize: controller.setPageSize,\n };\n\n const selection = useGridSelection<Row>({ controller, state, selectable });\n\n const multiselectable =\n selection.rowMode === \"multiple\" || selection.columnMode === \"multiple\";\n\n const contextMenu = useContextMenu({\n rootRef: viewportRef,\n scrollRef: gridRef,\n headerTableRef,\n bodyTableRef,\n bodyRef,\n footerTableRef,\n contextMenu: props.contextMenu,\n overlay,\n controller,\n commands,\n nav,\n selection,\n messages,\n columnName,\n });\n\n /**\n * Tells `subscribe`'s listeners once a render has drawn a change: to the\n * controller's state or view — whether an action or a prop made it — or to\n * the focused cell, which `@gridkitjs/dom`'s grid focus keeps apart from\n * the controller.\n *\n * Gated on those values, not run after every render: `useSyncExternalStore`\n * re-renders a subscriber that is notified, and a subscriber that renders\n * this grid as a plain (non-memoized) child would re-render it in turn and\n * be notified again, forever, though nothing ever changed. The state and\n * view objects keep their identity until something in them changes, which\n * is what breaks that cycle.\n */\n useEffect(() => {\n for (const listener of subscribersRef.current) {\n listener();\n }\n }, [view, state, nav.focus]);\n\n /**\n * No deps array: `nav`, `resize` and `virtualizer` are freshly\n * constructed every render (none of those hooks memoize their returned\n * API), so the handle has to be rebuilt every render too or its closures\n * would go stale. Grid state is read off the controller at call time.\n */\n useImperativeHandle(ref, () => ({\n get element() {\n return viewportRef.current;\n },\n get table() {\n return bodyTableRef.current;\n },\n getRows: () => controller.getView().rows,\n // Every group header's own `aggregates` field is populated here — the\n // whole reason `getDisplayRows()` is where a consumer reads a specific\n // group's computed results from.\n getDisplayRows: () => controller.getView().displayRows,\n getPageRows: () => controller.getView().pageRows,\n getColumns: () => controller.getView().columns,\n getDataColumns: () => controller.getView().dataColumns,\n getColumnSizing: () => controller.getState().columnSizing,\n getColumnOrder: () => controller.getState().columnOrder,\n getColumnVisibility: () => controller.getState().columnVisibility,\n getColumnPinning: () => controller.getState().columnPinning,\n getColumnSort: () => controller.getState().columnSort,\n getFilter: () => controller.getState().filter,\n getGroupBy: () => controller.getState().groupBy,\n getGroupExpansion: () => controller.getState().groupExpansion,\n getPagination: readPagination,\n getPageCount: () => controller.getView().pageCount,\n getAggregates: () => controller.getView().grandTotal,\n getRowSelection: () => controller.getState().rowSelection,\n getSelectedRows: readSelectedRows,\n getColumnSelection: () => controller.getState().columnSelection,\n getCellSelection: () => controller.getState().cellSelection,\n getFocusedCell: () => nav.focus,\n getState: controller.getState,\n restoreState: controller.restoreState,\n focusCell: nav.focusCell,\n clearSelection: controller.clearSelection,\n selectAllRows: controller.selectAllRows,\n selectRows: controller.selectRows,\n expandAllGroups: controller.expandAllGroups,\n collapseAllGroups: controller.collapseAllGroups,\n goToPage: controller.goToPage,\n nextPage: controller.nextPage,\n previousPage: controller.previousPage,\n setPageSize: controller.setPageSize,\n showColumns: controller.showColumns,\n hideColumns: controller.hideColumns,\n pinColumn: controller.pinColumn,\n setFilter: controller.setFilter,\n setColumnSort: controller.setColumnSort,\n setGroupBy: controller.setGroupBy,\n setGroupExpansion: controller.setGroupExpansion,\n setPagination: controller.setPagination,\n setColumnSizing: controller.setColumnSizing,\n setColumnOrder: controller.setColumnOrder,\n setColumnVisibility: controller.setColumnVisibility,\n setColumnPinning: controller.setColumnPinning,\n setRowSelection: controller.setRowSelection,\n setColumnSelection: controller.setColumnSelection,\n setCellSelection: controller.setCellSelection,\n autoFitColumn: (columnId) => {\n commands.host.autoFitColumns([columnId]);\n },\n autoFitColumns: (columnIds) => {\n commands.host.autoFitColumns(\n columnIds ?? controller.getView().columns.map((entry) => entry.id),\n );\n },\n openContextMenu: contextMenu.open,\n closeContextMenu: contextMenu.close,\n ...exportApi(commands),\n ...printApi(commands),\n ...panelApi(panels, controller),\n runCommand: (commandId, target = { area: \"grid\" }) =>\n commands.run(commandId, target, \"api\"),\n scrollToRow: (rowId, options) => {\n // `pageRows`, not `displayRows`: a data row's DOM position is its place\n // in the currently rendered page — with grouping active, that's its\n // place in the grouped, flattened output; with pagination also active,\n // that's the page's own slice of it. A row on a different page isn't\n // in the DOM at all, so there is nothing to scroll to.\n const index = controller\n .getView()\n .pageRows.findIndex(\n (entry) => entry.kind === \"data\" && entry.rowId === rowId,\n );\n if (index === -1) return;\n // Under virtualization the target row may not be mounted at all —\n // `virtualizer.scrollToIndex` estimates, scrolls, and self-corrects\n // once it mounts and is measured, rather than reaching for a DOM row\n // that may not exist.\n if (virtualized) {\n virtualizer.scrollToIndex(index, options);\n return;\n }\n bodyTableRef.current?.tBodies[0]?.rows[index]?.scrollIntoView(options);\n },\n scrollToColumn: (columnId, options) => {\n // The whole viewport, not just one table: a column's cells with\n // `data-gridkit-column` now live across three sibling tables\n // (header/body/footer) rather than one, and the header's `<th>` is\n // the one guaranteed to exist even when the body has no rows.\n const cells = viewportRef.current?.querySelectorAll(\n \"[data-gridkit-column]\",\n );\n const cell = cells\n ? Array.from(cells).find(\n (entry) => entry.getAttribute(\"data-gridkit-column\") === columnId,\n )\n : undefined;\n cell?.scrollIntoView(options);\n },\n subscribe: (listener) => {\n subscribersRef.current.add(listener);\n return () => {\n subscribersRef.current.delete(listener);\n };\n },\n }));\n\n // Shared by all three tables below, so borders/hover/selectable styling —\n // every `.gridkit-data-grid.<modifier>` rule in `theme-tailwind` — applies\n // identically to each rather than only to whichever one happened to carry\n // it. Each rule's own descendant selector (e.g. `.gridkit-borders-horizontal\n // .gridkit-grid-cell`) still needs the modifier class on that cell's own table\n // ancestor, which is exactly what splitting into one table per section\n // would otherwise lose.\n const gridTableClassName = classNames(\n \"gridkit-data-grid\",\n borders ? `gridkit-borders-${borders}` : \"\",\n // Hover is on by default and selection off, so one set of classes\n // turns styling off and the other turns it on. The polarity differs\n // because the defaults do.\n hoverRows ? \"\" : \"gridkit-no-hover-rows\",\n hoverColumns ? \"\" : \"gridkit-no-hover-columns\",\n hoverCells ? \"\" : \"gridkit-no-hover-cells\",\n selection.rowMode === false ? \"\" : \"gridkit-selectable-rows\",\n selection.columnMode === false ? \"\" : \"gridkit-selectable-columns\",\n selection.cellMode === false ? \"\" : \"gridkit-selectable-cells\",\n );\n const hasFooter = aggregates.length > 0;\n // What the header and footer, sticking to the scroll area's top and\n // bottom, cover of it: the area grows by both, so `height` is the rows'\n // alone, and keyboard focus scrolls a cell clear of both.\n const headerHeight = useElementHeight(headerTableRef, height !== undefined);\n const footerHeight = useElementHeight(\n footerTableRef,\n height !== undefined && hasFooter,\n );\n\n return (\n <div\n className=\"gridkit-data-grid-viewport\"\n ref={viewportRef}\n // Chromium and Firefox make an element that scrolls a Tab stop of its\n // own; the grid's one stop is its roving cell, so no scroller takes a\n // place in the Tab order: not the tables below, nor this one, which\n // scrolls only when something beside them is wider than it.\n tabIndex={-1}\n >\n <GridToolbar<Row>\n toolbar={props.toolbar}\n renderItem={props.renderToolbarItem}\n gridId={gridId}\n controller={controller}\n commands={commands}\n messages={messages}\n announce={announce}\n />\n {showGroupByBar && (\n <GroupByBar<Row>\n columns={view.columns}\n definitions={definitions}\n groupBy={state.groupBy}\n controller={controller}\n columnName={columnName}\n headerDragEligible={dragEligibleForGroupBy}\n headerDragBlocked={draggedColumnAlreadyGrouped}\n headerDropTarget={headerGroupByDropTarget}\n messages={messages}\n />\n )}\n <div\n ref={gridRef}\n id={gridId}\n className=\"gridkit-data-grid-tables\"\n /*\n * `role=\"grid\"` sits on this wrapper rather than any one of the\n * three `<table>`s below: the WAI-ARIA grid pattern needs a single\n * ancestor holding every row — header, body, and (when aggregates\n * are active) footer alike — and no one table is an ancestor of the\n * other two's rows now that they're split. It obliges the single\n * tab stop `useGridNavigation` keeps.\n *\n * So each `<table>` is `role=\"presentation\"`, and the header and\n * footer sections, the body's wrapper, and every row and cell carry\n * `rowgroup`, `row`, `columnheader` and `gridcell` explicitly: a native table inside a grid would own those rows\n * itself, with its own implicit roles, leaving the grid none, and\n * would make a group row's `aria-level`/`aria-expanded` invalid on\n * what is then a plain table row. The tables stay for layout alone.\n *\n * Switches to `\"treegrid\"` — the WAI-ARIA pattern for expandable,\n * collapsible rows — whenever `groupBy` is non-empty, rather than\n * committing to it unconditionally. The alternative (always\n * `treegrid`) would change what every existing, ungrouped consumer\n * announces to assistive technology the moment this feature shipped;\n * that regression is certain, while the edge case this trades away —\n * the role flipping mid-session if a consumer removes its last\n * group-by level — is rare and, per the WAI-ARIA grid pattern, still\n * a valid `role` change to make when the row structure itself\n * changes shape. See the \"Scope note\" this mirrors: grouping stays\n * an internal detail for an ungrouped grid, ARIA role included.\n */\n role={state.groupBy.length > 0 ? \"treegrid\" : \"grid\"}\n // The header is a row too, and counted from one, and so is the\n // grand-total footer. `view.rowCount` counts every row on every page,\n // group headers and summary rows included, and under\n // `dataMode: \"server\"` the rows the server has, so this stays the\n // true row count per the WAI-ARIA grid pattern even while paged.\n aria-rowcount={view.rowCount + (hasFooter ? 2 : 1)}\n aria-colcount={view.columns.length}\n // The one element that scrolls the rows, both ways, with the header\n // and footer sticking to its top and bottom: a Tab stop of its own\n // in Chromium and Firefox otherwise, as the viewport's note says.\n tabIndex={-1}\n style={tablesStyle(\n height,\n headerHeight,\n footerHeight,\n pinnedWidths(view.columns),\n )}\n {...ariaAttr(multiselectable, \"aria-multiselectable\", true)}\n {...ariaAttr(loading, \"aria-busy\", true)}\n {...ariaAttr(labelledBy !== undefined, \"aria-labelledby\", labelledBy)}\n {...ariaAttr(\n labelledBy === undefined && label !== undefined,\n \"aria-label\",\n label,\n )}\n onKeyDown={(event) => {\n // The keys that address the grid rather than a cell, caught here\n // where everything bubbles to rather than in each of them.\n if (!isOwnEvent(event)) return;\n handleCopyKey(event);\n if (event.key === \"Escape\") {\n // A gesture in flight has its own use for Escape — cancelling —\n // and gets it first.\n if (drag.draggedColumnId !== null || resize.activeColumnId !== null)\n return;\n selection.clear();\n return;\n }\n if (\n (event.ctrlKey || event.metaKey) &&\n (event.key === \"a\" || event.key === \"A\")\n ) {\n // Left to the browser unless the grid has something to do with it,\n // so a grid without multiple rows does not swallow select-all.\n if (selection.rowMode !== \"multiple\") return;\n event.preventDefault();\n selection.selectAllRows();\n }\n }}\n >\n <table\n ref={headerTableRef}\n role=\"presentation\"\n // Widths are only honoured exactly when the table is as wide as its\n // columns; at `100%` the fixed layout redistributes the difference.\n style={{ width: totalColumnWidth(view.columns) }}\n className={classNames(gridTableClassName, \"gridkit-data-grid-header\")}\n >\n <GridColgroup columns={view.columns} />\n <GridHeader<Row>\n columns={view.columns}\n resize={resize}\n drag={drag}\n controller={controller}\n state={state}\n sortableColumns={sortableColumns}\n groupableColumns={groupableColumns}\n groupToggleIconColumns={groupToggleIconColumns}\n headerMenu={contextMenu.opens(\"header\")}\n panels={panels}\n messages={messages}\n nav={nav}\n selection={selection}\n />\n </table>\n\n <div\n className=\"gridkit-data-grid-body\"\n ref={bodyRef}\n // The body's rowgroup, rather than its `<tbody>`: an element that\n // can take focus, as `tabIndex` makes this one, must have a role\n // the grid allows among its children, and a rowgroup may not hold\n // another, so the `<tbody>` inside is presentational. Focusable\n // from script and by a click on the rows' empty space, never by\n // Tab.\n role=\"rowgroup\"\n tabIndex={-1}\n >\n <table\n ref={bodyTableRef}\n role=\"presentation\"\n style={{ width: totalColumnWidth(view.columns) }}\n className={gridTableClassName}\n >\n <GridColgroup columns={view.columns} />\n <GridBody<Row>\n columns={view.columns}\n definitions={definitions}\n rows={view.pageRows}\n activeColumnId={resize.activeColumnId}\n nav={nav}\n selection={selection}\n controller={controller}\n aggregates={aggregates}\n groupAggregateDisplay={groupAggregateDisplay}\n virtualRange={virtualized ? virtualizer : null}\n infiniteScroll={infiniteScroll}\n sentinelRef={sentinelRef}\n empty={empty}\n emptyTemplate={props.emptyTemplate}\n viewportWidth={bodyViewportWidth}\n locale={locale}\n getRowProps={getRowProps}\n onRowClick={onRowClick}\n onRowDoubleClick={onRowDoubleClick}\n messages={messages}\n cellMenu={contextMenu.opens(\"cell\")}\n groupMenu={contextMenu.opens(\"group\")}\n />\n </table>\n {loading && (\n <GridLoadingOverlay\n empty={view.pageRows.length === 0}\n viewportWidth={bodyViewportWidth}\n >\n {props.loadingTemplate\n ? props.loadingTemplate()\n : messages.loading}\n </GridLoadingOverlay>\n )}\n </div>\n\n {hasFooter && (\n <table\n ref={footerTableRef}\n role=\"presentation\"\n style={{ width: totalColumnWidth(view.columns) }}\n className={classNames(\n gridTableClassName,\n \"gridkit-data-grid-footer\",\n )}\n >\n <GridColgroup columns={view.columns} />\n <GridFooter<Row>\n columns={view.columns}\n aggregates={aggregates}\n results={view.grandTotal}\n rows={view.rows.map((entry) => entry.row)}\n locale={locale}\n ariaRowIndex={view.rowCount + 2}\n />\n </table>\n )}\n </div>\n <GridContextMenu contextMenu={contextMenu} />\n <GridPanels\n panels={panels}\n controller={controller}\n commands={commands}\n messages={messages}\n />\n {paginated &&\n (pager?.template ? (\n pager.template(pagerContext)\n ) : (\n <GridPager pager={pagerContext} config={pager} messages={messages} />\n ))}\n </div>\n );\n}\n","import type { ResolvedColumn } from \"../DataGrid\";\n\ninterface GridColgroupProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n}\n\n/**\n * One `<colgroup>`, shared verbatim by the header, body, and footer\n * `<table>`s so all three render identical column widths from one source\n * rather than three independent copies of the same `.map()`.\n */\nexport default function GridColgroup<Row>({ columns }: GridColgroupProps<Row>) {\n return (\n <colgroup>\n {columns.map((entry) => (\n <col key={entry.id} style={{ width: entry.width }} />\n ))}\n </colgroup>\n );\n}\n","import { createPortal } from \"react-dom\";\nimport {\n headerFocus,\n isColumnFiltered,\n sortDirectionFor,\n sortPriorityFor,\n type GridMessages,\n type GridState,\n} from \"@gridkitjs/core\";\nimport {\n buildKeyShortcuts,\n inlineStep,\n intentOf,\n KEYBOARD_STEP,\n resolveColumnFilterMenu,\n} from \"@gridkitjs/core/renderer\";\nimport { writingDirection } from \"@gridkitjs/dom\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport {\n ChevronsUpDownIcon,\n ChevronUpIcon,\n FilterIcon,\n GroupIcon,\n} from \"../icons\";\nimport { isOwnEvent } from \"../isOwnEvent\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport type { GridPanelsApi } from \"../panels/useGridPanels\";\nimport type { ColumnDragApi } from \"../useColumnDrag\";\nimport type { ColumnResizeApi } from \"../useColumnResize\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\nimport {\n keyboardSelectIntent,\n type GridSelectionApi,\n} from \"../useGridSelection\";\nimport type { DataGridController } from \"../useGridController\";\n\ninterface GridHeaderProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n resize: ColumnResizeApi<Row>;\n drag: ColumnDragApi<Row>;\n /** What a header toggle changes — the sort and the group-by stack. */\n controller: DataGridController<Row>;\n /** The state this render draws: the sort, grouping and filter the headers show. */\n state: GridState<Row>;\n sortableColumns: boolean;\n groupableColumns: boolean;\n groupToggleIconColumns: boolean;\n /** Whether a header opens the grid's context menu, which its `aria-keyshortcuts` says. */\n headerMenu: boolean;\n /** Where a header opens its column's filter menu. */\n panels: GridPanelsApi;\n messages: GridMessages;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n}\n\nexport default function GridHeader<Row>({\n columns,\n resize,\n drag,\n controller,\n state,\n sortableColumns,\n groupableColumns,\n groupToggleIconColumns,\n headerMenu,\n panels,\n messages,\n nav,\n selection,\n}: GridHeaderProps<Row>) {\n const { columnSort, groupBy, filter } = state;\n // Only meaningful for the \"column-order\" branch — a drop headed for the\n // group-by bar instead (`kind: \"group-by\"`) draws no indicator here at\n // all; `GroupByBar` draws its own from the same `drag.dropTarget`.\n const beforeId =\n drag.dropTarget?.kind === \"column-order\"\n ? drag.dropTarget.beforeId\n : undefined;\n const draggedEntry =\n columns.find((entry) => entry.id === drag.draggedColumnId) ?? null;\n\n /**\n * Opens the column's filter menu, or closes it when it is the one open: a\n * press on the header it opened from leaves it open, so pressing its\n * button again is the way back out.\n */\n function toggleFilterMenu(columnId: string): void {\n const panel = panels.current();\n if (\n panel?.kind === \"filter\" &&\n panel.target.area === \"header\" &&\n panel.target.columnId === columnId\n ) {\n panels.close();\n } else {\n panels.open(\"filter\", { area: \"header\", columnId });\n }\n }\n\n return (\n <thead role=\"rowgroup\">\n <tr className=\"gridkit-grid-header\" role=\"row\" aria-rowindex={1}>\n {columns.map((entry, index) => {\n const { column } = entry;\n const resizing = resize.activeColumnId === entry.id;\n const dragging = drag.draggedColumnId === entry.id;\n\n // A drag keeps its column in its pin group, so the other groups'\n // headers say they won't take it for as long as it lasts.\n const dragBlocked =\n draggedEntry !== null && entry.pinned !== draggedEntry.pinned;\n /**\n * Drawn on the gap's own edge, so the one gap between two columns is\n * marked once, and inside the dragged column's pin group: the gap\n * at a group's end is drawn after its last column, not before the\n * next group's first. No guard against the dragged column: the hook\n * reports only gaps that would move it.\n */\n const next = columns[index + 1];\n const dropBefore = beforeId === entry.id && !dragBlocked;\n const dropAfter =\n !dragBlocked &&\n (next === undefined\n ? beforeId === null\n : beforeId === next.id && next.pinned !== entry.pinned);\n const selected = selection.selectedColumnIds.has(entry.id);\n const sortable = column.sortable ?? sortableColumns;\n const sortDirection = sortDirectionFor(columnSort, entry.id);\n // Only meaningful once two or more columns are stacked.\n const sortPriority = sortPriorityFor(columnSort, entry.id);\n const groupable = column.groupable ?? groupableColumns;\n // Purely a rendering choice — see the prop's own doc comment. Never\n // gates `groupable` itself, `aria-keyshortcuts`, or `Alt+ArrowDown`.\n const showGroupToggleIcon =\n column.groupToggleIcon ?? groupToggleIconColumns;\n const isGrouped = groupBy.some(\n (level) => level.columnId === entry.id,\n );\n const filterable =\n resolveColumnFilterMenu(controller.getOptions(), column) !== null;\n // Shown, and described, only where the header opens the menu that\n // changes it: a grid filtering a column in code alone keeps its\n // headers as they were.\n const filtered = filterable && isColumnFiltered(filter, entry.id);\n\n const shortcuts = buildKeyShortcuts({\n reorderable: entry.reorderable,\n resizable: entry.resizable,\n sortable,\n groupable,\n filterable,\n contextMenu: headerMenu,\n });\n\n return (\n <th\n key={entry.id}\n scope=\"col\"\n // Explicit, like every structural role in the grid: each\n // `<table>` is `role=\"presentation\"`, so the rows and cells\n // belong to the `grid`/`treegrid` wrapper rather than to a\n // native table, and only an explicit role survives that.\n role=\"columnheader\"\n data-gridkit-column={entry.id}\n aria-colindex={index + 1}\n tabIndex={nav.tabIndexFor(headerFocus(index))}\n {...ariaAttr(\n selection.columnMode !== false,\n \"aria-selected\",\n selected,\n )}\n onFocus={() => {\n nav.focusCell(headerFocus(index));\n }}\n onClick={(event) => {\n /*\n * A drag ends in a click on the header it started from, and a\n * resize in one on the handle inside it. Neither is the press\n * that selects a column, so both are shown the door here —\n * the drag by the distance it travelled, the resize by where\n * it began.\n */\n if (drag.justDragged(entry.id)) {\n return;\n }\n if (\n event.target instanceof Element &&\n (event.target.closest(\".gridkit-header-resize-handle\") !==\n null ||\n event.target.closest(\".gridkit-header-sort-toggle\") !==\n null ||\n event.target.closest(\".gridkit-header-group-toggle\") !==\n null ||\n event.target.closest(\".gridkit-header-filter-toggle\") !==\n null)\n ) {\n return;\n }\n selection.selectColumn(entry.id, intentOf(event));\n }}\n onKeyDown={(event) => {\n if (!isOwnEvent(event)) return;\n // Toward the next column moves it later and grows it, its\n // resize handle being on that side.\n const step = inlineStep(\n event.key,\n writingDirection(event.currentTarget),\n );\n\n if (step !== null && event.ctrlKey && entry.reorderable) {\n event.preventDefault();\n drag.moveByKeyboard(entry, step);\n return;\n }\n if (step !== null && event.altKey && entry.resizable) {\n event.preventDefault();\n resize.nudge(entry, step * KEYBOARD_STEP);\n return;\n }\n // The keyboard equivalent of double-clicking the resize\n // handle, which auto-fits the column to its content.\n if (event.key === \"Enter\" && event.altKey && entry.resizable) {\n event.preventDefault();\n resize.sizeToContent(entry);\n return;\n }\n if (event.key === \"ArrowUp\" && event.altKey && sortable) {\n event.preventDefault();\n controller.toggleColumnSort(entry.id, {\n stack: event.shiftKey,\n });\n return;\n }\n // Shift sets the filter menu apart from grouping, which\n // holds Alt+ArrowDown — the key Excel opens its filter with.\n if (\n event.key === \"ArrowDown\" &&\n event.altKey &&\n event.shiftKey &&\n filterable\n ) {\n event.preventDefault();\n toggleFilterMenu(entry.id);\n return;\n }\n if (\n event.key === \"ArrowDown\" &&\n event.altKey &&\n !event.shiftKey &&\n groupable\n ) {\n event.preventDefault();\n controller.toggleGroupBy(entry.id);\n return;\n }\n // Space builds a selection up and Enter replaces it, as in the\n // body. Taken either way, or Space scrolls the grid away.\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n selection.selectColumn(\n entry.id,\n intentOf(keyboardSelectIntent(event)),\n );\n return;\n }\n nav.onKeyDown(event);\n }}\n className={classNames(\n \"gridkit-header-cell\",\n // The grab affordance a header showing either drag\n // destination shares — a column dragged only for grouping\n // (`groupByDraggable` without `reorderable`) grabs the same\n // way one dragged only for reordering does.\n entry.reorderable || entry.groupByDraggable\n ? \"is-reorderable\"\n : \"\",\n selected ? \"is-selected\" : \"\",\n resizing ? \"is-resizing\" : \"\",\n dragging ? \"is-dragging\" : \"\",\n dropBefore ? \"is-drop-before\" : \"\",\n dropAfter ? \"is-drop-after\" : \"\",\n dragBlocked ? \"is-drag-blocked\" : \"\",\n column.wrap?.header ? \"is-wrapped\" : \"\",\n pinnedCellClassNames(entry),\n column.headerClassName ?? \"\",\n )}\n style={pinnedCellStyle(entry)}\n {...ariaAttr(shortcuts !== \"\", \"aria-keyshortcuts\", shortcuts)}\n {...ariaAttr(\n filtered,\n \"aria-description\",\n messages.columnFiltered,\n )}\n {...ariaAttr<\"aria-sort\", \"ascending\" | \"descending\">(\n sortable && sortDirection !== null,\n \"aria-sort\",\n sortDirection === \"asc\" ? \"ascending\" : \"descending\",\n )}\n {...((entry.reorderable || entry.groupByDraggable) && {\n onPointerDown: (event) => {\n drag.startDrag(entry, event);\n },\n })}\n >\n {groupable && showGroupToggleIcon && (\n /*\n * Inline, before the label, rather than absolutely\n * positioned like the sort toggle and resize handle: those\n * two already share the header's right edge, and a third\n * overlay there would need its own carve-out. Sitting in\n * normal flow costs nothing but a few pixels of label width.\n * A pointer affordance only, same as the other two — the\n * keyboard equivalent is Alt+ArrowDown on the header itself.\n */\n <span\n className={classNames(\n \"gridkit-header-group-toggle\",\n isGrouped ? \"is-grouped\" : \"\",\n )}\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n // See the sort toggle's own note: otherwise a\n // reorderable header's drag would swallow this click.\n event.stopPropagation();\n }}\n onClick={(event) => {\n event.stopPropagation();\n controller.toggleGroupBy(entry.id);\n }}\n >\n <GroupIcon />\n </span>\n )}\n {entry.label}\n {sortable && (\n /*\n * A pointer affordance only, and hidden from assistive\n * technology like the resize handle: the keyboard equivalent\n * lives on the header itself, under Alt+ArrowUp (plain) /\n * Alt+Shift+ArrowUp (stacking).\n */\n <span\n className={classNames(\n \"gridkit-header-sort-toggle\",\n sortDirection !== null ? `is-sorted-${sortDirection}` : \"\",\n )}\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n /*\n * Otherwise a reorderable header's own `onPointerDown`\n * sees this bubble up and starts a column drag, whose\n * pointer capture then redirects the click that\n * follows to the `th` — the same reason `startResize`\n * stops it for the resize handle.\n */\n event.stopPropagation();\n }}\n onClick={(event) => {\n controller.toggleColumnSort(entry.id, {\n stack: event.shiftKey,\n });\n }}\n >\n {sortDirection === null ? (\n <ChevronsUpDownIcon />\n ) : (\n <ChevronUpIcon />\n )}\n {sortPriority !== null && sortPriority > 1 && (\n <span className=\"gridkit-header-sort-priority\">\n {sortPriority}\n </span>\n )}\n </span>\n )}\n {filterable && (\n /*\n * A pointer affordance only, like the sort toggle: the\n * keyboard opens the menu from the header itself, under\n * Alt+Shift+ArrowDown, and a screen reader hears the\n * filtered state as the header's description.\n */\n <span\n className={classNames(\n \"gridkit-header-filter-toggle\",\n filtered ? \"is-filtered\" : \"\",\n )}\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n // See the sort toggle's own note.\n event.stopPropagation();\n }}\n onClick={() => {\n toggleFilterMenu(entry.id);\n }}\n >\n <FilterIcon />\n </span>\n )}\n {entry.resizable && (\n /*\n * A pointer affordance only, and hidden from assistive\n * technology accordingly: a focusable handle per column would\n * put N tab stops inside a widget that is meant to have one.\n * The keyboard resizes from the header itself, under Alt.\n */\n <span\n className=\"gridkit-header-resize-handle\"\n aria-hidden=\"true\"\n tabIndex={-1}\n onPointerDown={(event) => {\n resize.startResize(entry, event);\n }}\n onDoubleClick={() => {\n resize.sizeToContent(entry);\n }}\n />\n )}\n </th>\n );\n })}\n </tr>\n {/*\n * Portalled to the body, and not only because a `div` cannot sit in a\n * `tr`: inside the viewport the overflow that makes the grid scroll\n * would clip it.\n */}\n {draggedEntry !== null &&\n drag.ghostTransform !== null &&\n createPortal(\n <div\n className=\"gridkit-data-grid gridkit-header-cell gridkit-drag-ghost\"\n style={{\n width: draggedEntry.width,\n transform: drag.ghostTransform,\n }}\n aria-hidden=\"true\"\n >\n {draggedEntry.label}\n </div>,\n document.body,\n )}\n </thead>\n );\n}\n","/**\n * Collapses the `{...(condition && { \"aria-foo\": value })}` idiom for\n * conditionally including a single ARIA attribute in a JSX spread.\n */\nexport function ariaAttr<K extends string, V>(\n condition: boolean,\n key: K,\n value: V,\n): Record<K, V> | Record<string, never> {\n return condition ? ({ [key]: value } as Record<K, V>) : {};\n}\n","export function classNames(\n ...values: (string | false | null | undefined)[]\n): string {\n return values.filter(Boolean).join(\" \");\n}\n","import type { ReactNode } from \"react\";\n\n/** The common attributes behind every icon the grid draws — just the `<path>`s differ. */\nexport function Icon({ children }: { children: ReactNode }) {\n return (\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n {children}\n </svg>\n );\n}\n\n/**\n * The two glyphs a sort toggle shows: a neutral hint before a column has a\n * direction, and a single chevron reused for both directions once it does —\n * `theme-tailwind` rotates it 180° for `desc` rather than swapping icons.\n */\nexport function ChevronsUpDownIcon() {\n return (\n <Icon>\n <path d=\"m7 15 5 5 5-5\" />\n <path d=\"m7 9 5-5 5 5\" />\n </Icon>\n );\n}\n\nexport function ChevronUpIcon() {\n return (\n <Icon>\n <path d=\"m18 15-6-6-6 6\" />\n </Icon>\n );\n}\n\n/** Three stacked panes, standing in for \"group by this column\". */\nexport function GroupIcon() {\n return (\n <Icon>\n <rect x=\"3\" y=\"3\" width=\"7\" height=\"7\" rx=\"1\" />\n <rect x=\"14\" y=\"3\" width=\"7\" height=\"7\" rx=\"1\" />\n <rect x=\"8.5\" y=\"14\" width=\"7\" height=\"7\" rx=\"1\" />\n </Icon>\n );\n}\n\n/** A funnel, standing in for \"filter this column\". */\nexport function FilterIcon() {\n return (\n <Icon>\n <path d=\"M22 3H2l8 9.46V19l4 2v-8.54z\" />\n </Icon>\n );\n}\n\n/** The pager's previous-page chevron; `theme-tailwind` mirrors the pager's chevrons right-to-left. */\nexport function ChevronLeftIcon() {\n return (\n <Icon>\n <path d=\"m15 18-6-6 6-6\" />\n </Icon>\n );\n}\n\nexport function ChevronRightIcon() {\n return (\n <Icon>\n <path d=\"m9 18 6-6-6-6\" />\n </Icon>\n );\n}\n\n/** The pager's first-page double chevron. */\nexport function ChevronsLeftIcon() {\n return (\n <Icon>\n <path d=\"m11 17-5-5 5-5\" />\n <path d=\"m18 17-5-5 5-5\" />\n </Icon>\n );\n}\n\nexport function ChevronsRightIcon() {\n return (\n <Icon>\n <path d=\"m6 17 5-5-5-5\" />\n <path d=\"m13 17 5-5-5-5\" />\n </Icon>\n );\n}\n","/**\n * Whether `event` happened inside the element whose handler is running.\n * React bubbles a portal's events up the component tree rather than the DOM,\n * so a panel rendered into `document.body` from inside the grid still reaches\n * the grid's key handlers — and Escape or Ctrl+A pressed in it is the\n * panel's, not the grid's.\n */\nexport function isOwnEvent(event: {\n readonly currentTarget: Element;\n readonly target: EventTarget;\n}): boolean {\n return (\n event.target instanceof Node && event.currentTarget.contains(event.target)\n );\n}\n","import type { CSSProperties } from \"react\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport { classNames } from \"./classNames\";\n\n/** Where a column is pinned, as `core`'s view resolved it. */\ntype PinPlacement = Pick<\n ResolvedColumn<unknown>,\n \"pinned\" | \"pinOffset\" | \"pinEdge\"\n>;\n\n/**\n * The state classes of a pinned column's header, body, footer and summary\n * cells: its edge, and `is-pinned-edge` on the column beside the scrolling\n * ones. `\"\"` for an unpinned column.\n */\nexport function pinnedCellClassNames({\n pinned,\n pinEdge,\n}: PinPlacement): string {\n if (pinned === \"none\") return \"\";\n return classNames(\n pinned === \"start\" ? \"is-pinned-start\" : \"is-pinned-end\",\n pinEdge && \"is-pinned-edge\",\n );\n}\n\n/**\n * The one style a cell carries for pinning: its distance from its edge,\n * which the stylesheet's sticky inset reads. Per cell, so it cannot live in\n * the stylesheet. Nothing for an unpinned column.\n */\nexport function pinnedCellStyle({\n pinned,\n pinOffset,\n}: PinPlacement): CSSProperties | undefined {\n if (pinned === \"none\") return undefined;\n return {\n \"--gridkit-pin-offset\": `${String(pinOffset)}px`,\n } as CSSProperties;\n}\n","import { useMemo, type KeyboardEvent as ReactKeyboardEvent } from \"react\";\nimport type {\n CellSelectionMode,\n CellSelectionState,\n GridState,\n SelectableConfig,\n SelectedCellRef,\n SelectIntent,\n SelectionMode,\n} from \"@gridkitjs/core\";\nimport type { DataGridController } from \"./useGridController\";\n\n/**\n * The modifiers a Space or Enter keydown carries, for a caller that means to\n * hand them to `intentOf` as a click's modifiers would be. Space builds a\n * selection up and Enter replaces it, as in the body — so Space is mapped to\n * act like Ctrl, matching Ctrl-click and the plain click they stand in for.\n */\nexport function keyboardSelectIntent(event: ReactKeyboardEvent): {\n ctrlKey: boolean;\n metaKey: boolean;\n shiftKey: boolean;\n} {\n return {\n ctrlKey: event.key === \" \" || event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n };\n}\n\ninterface UseGridSelectionOptions<Row> {\n controller: DataGridController<Row>;\n state: GridState<Row>;\n selectable: SelectableConfig | undefined;\n}\n\nexport interface GridSelectionApi {\n rowMode: SelectionMode;\n columnMode: SelectionMode;\n cellMode: CellSelectionMode;\n /** Whether a plain click on a row toggles it — `selectable.toggleOnClick`. */\n toggleOnClick: boolean;\n /**\n * Lookups for the render pass. The state itself stays an ordered list, which\n * is what makes the most recent selection its last entry.\n */\n selectedRowIds: ReadonlySet<string>;\n selectedColumnIds: ReadonlySet<string>;\n selectedCell: CellSelectionState;\n selectRow: (rowId: string, intent: SelectIntent) => void;\n selectColumn: (columnId: string, intent: SelectIntent) => void;\n selectCell: (cell: SelectedCellRef, intent: SelectIntent) => void;\n selectAllRows: () => void;\n /** Lets go of every selection at once, as Escape does. */\n clear: () => void;\n}\n\n/**\n * The selection as the header and body draw and change it. The selections\n * themselves, the intent each click carries and the callbacks it fires all\n * live in the grid's controller; this hook only adds the lookups a render\n * pass wants and names the actions the components call.\n */\nexport default function useGridSelection<Row>({\n controller,\n state,\n selectable,\n}: UseGridSelectionOptions<Row>): GridSelectionApi {\n const selectedRowIds = useMemo(\n () => new Set(state.rowSelection),\n [state.rowSelection],\n );\n const selectedColumnIds = useMemo(\n () => new Set(state.columnSelection),\n [state.columnSelection],\n );\n\n // A new object each render, as the other hooks here return.\n return {\n rowMode: selectable?.rows ?? false,\n columnMode: selectable?.columns ?? false,\n cellMode: selectable?.cells ?? false,\n toggleOnClick: selectable?.toggleOnClick ?? false,\n selectedRowIds,\n selectedColumnIds,\n selectedCell: state.cellSelection,\n selectRow: controller.selectRow,\n selectColumn: controller.selectColumn,\n selectCell: controller.selectCell,\n selectAllRows: controller.selectAllRows,\n clear: controller.clearSelection,\n };\n}\n","import {\n useMemo,\n useState,\n type MouseEvent as ReactMouseEvent,\n type RefObject,\n} from \"react\";\nimport {\n bodyFocus,\n type AggregateState,\n type DisplayRow,\n type FormatLocale,\n type GridMessages,\n type GridOptions,\n type GroupAggregateDisplay,\n type ResolvedRow,\n type RowPointerEvent,\n} from \"@gridkitjs/core\";\nimport { intentOf } from \"@gridkitjs/core/renderer\";\nimport {\n bodyCellFrom,\n bodyRowFrom,\n groupRowFrom,\n type BodyCellTarget,\n} from \"@gridkitjs/dom\";\nimport type {\n ColumnDefinition,\n EmptyTemplateContext,\n InfiniteScrollConfig,\n ReactRenderSlots,\n ResolvedColumn,\n} from \"../DataGrid\";\nimport {\n focusedColumnInRow,\n type GridNavigationApi,\n} from \"../useGridNavigation\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { RowVirtualizerApi } from \"../useRowVirtualizer\";\nimport { isOwnEvent } from \"../isOwnEvent\";\nimport { createRowPropsResolver } from \"../rowProps\";\nimport {\n keyboardSelectIntent,\n type GridSelectionApi,\n} from \"../useGridSelection\";\nimport GridEmptyRow from \"./GridEmptyRow\";\nimport GridGroupRow from \"./GridGroupRow\";\nimport GridGroupSummaryRow from \"./GridGroupSummaryRow\";\nimport GridRow from \"./GridRow\";\n\ninterface GridBodyProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n /** Every column's definition by id, hidden ones included — a grid may group or aggregate by a column it does not show. */\n definitions: ReadonlyMap<string, ColumnDefinition<Row>>;\n rows: readonly DisplayRow<Row>[];\n /** The column being resized, so its cells outline with its header. */\n activeColumnId: string | null;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n /** What a group header's click or key press expands or collapses. */\n controller: DataGridController<Row>;\n /** Active aggregates. Empty when none are active. */\n aggregates: AggregateState<Row>;\n /** Where a group's aggregates render — inline in its header, or as its own summary row. */\n groupAggregateDisplay: GroupAggregateDisplay;\n /** Windows `rows` down to the rows near the current scroll position. `null` when `virtualized` is off, in which case every row of `rows` renders exactly as it always has. */\n virtualRange: RowVirtualizerApi | null;\n /** Renders a sentinel row (and, while loading, a loading row) as the last child of `<tbody>` when set. `undefined` renders neither. */\n infiniteScroll: InfiniteScrollConfig | undefined;\n /** Ref the sentinel row attaches to — owned and observed by `DataGrid.tsx`'s `useInfiniteScroll`, not by this component. */\n sentinelRef: RefObject<HTMLTableRowElement | null>;\n /** Draws the empty message in place of the rows when set; `null` while there are rows to show, or infinite scroll can still load some. */\n empty: EmptyTemplateContext | null;\n emptyTemplate: ReactRenderSlots<Row>[\"emptyTemplate\"];\n /** The scroll area's inner width, for the empty message; `null` until measured. */\n viewportWidth: number | null;\n /** The grid's `locale`, which every cell and aggregate without a template is formatted for. */\n locale: FormatLocale;\n getRowProps: GridOptions<Row>[\"getRowProps\"];\n onRowClick: GridOptions<Row>[\"onRowClick\"];\n onRowDoubleClick: GridOptions<Row>[\"onRowDoubleClick\"];\n messages: GridMessages;\n /** Whether a data cell, or a group row, opens the grid's context menu — for their `aria-keyshortcuts`. */\n cellMenu: boolean;\n groupMenu: boolean;\n}\n\n/**\n * Events are delegated to the body rather than bound per cell, which is what\n * lets `GridRow` be memoised: a handler rebuilt each render is a prop that\n * changes each render, and one reaching every row would defeat the boundary\n * entirely.\n */\nexport default function GridBody<Row>({\n columns,\n definitions,\n rows,\n activeColumnId,\n nav,\n selection,\n controller,\n aggregates,\n groupAggregateDisplay,\n virtualRange,\n infiniteScroll,\n sentinelRef,\n empty,\n emptyTemplate,\n viewportWidth,\n locale,\n getRowProps,\n onRowClick,\n onRowDoubleClick,\n messages,\n cellMenu,\n groupMenu,\n}: GridBodyProps<Row>) {\n const { selectedCell, rowMode, cellMode, toggleOnClick } = selection;\n // The full `rows` array otherwise — `virtualRange` is `null` whenever\n // `virtualized` is off, so this slice, and the spacer rows below, are a\n // no-op that reproduces today's output exactly.\n const visibleRows =\n virtualRange === null\n ? rows\n : rows.slice(virtualRange.startIndex, virtualRange.endIndex + 1);\n const { booleanTrue, booleanFalse, blankGroupValue } = messages;\n // Keyed on the strings rather than `messages`, so the memoised rows hold\n // still under a `messages` object rebuilt on every render.\n const cellMessages = useMemo(\n () => ({ booleanTrue, booleanFalse, blankGroupValue }),\n [booleanTrue, booleanFalse, blankGroupValue],\n );\n const [resolveRowProps] = useState(() => createRowPropsResolver<Row>());\n const rowPropsOf = resolveRowProps(\n visibleRows.filter(\n (entry): entry is ResolvedRow<Row> => entry.kind === \"data\",\n ),\n getRowProps,\n );\n\n /** The row and cell an event addresses, resolved once for every handler. */\n function targetOf(\n target: EventTarget,\n ): { position: BodyCellTarget; rowId: string } | null {\n const position = bodyCellFrom(target);\n const entry = position === null ? undefined : rows[position.rowIndex];\n if (position === null || entry?.kind !== \"data\") {\n return null;\n }\n return { position, rowId: entry.rowId };\n }\n\n function select(\n rowId: string,\n columnId: string,\n modifiers: { ctrlKey: boolean; metaKey: boolean; shiftKey: boolean },\n ): void {\n // Independent of each other: selecting a cell says nothing about its row,\n // so a grid with both on reports both. `toggleOnClick` is the rows' own.\n if (rowMode !== false) {\n selection.selectRow(rowId, intentOf(modifiers, { toggleOnClick }));\n }\n if (cellMode !== false) {\n selection.selectCell({ rowId, columnId }, intentOf(modifiers));\n }\n }\n\n /**\n * What `onRowClick`/`onRowDoubleClick` are told of a pointer event on a\n * data row — `null` off one, a group header included. Unlike `targetOf`\n * it needs no cell: the row alone is enough to report.\n */\n function rowPointerEventOf(\n event: ReactMouseEvent,\n ): RowPointerEvent<Row> | null {\n const target = bodyRowFrom(event.target);\n const entry = target === null ? undefined : rows[target.rowIndex];\n if (target === null || entry?.kind !== \"data\") {\n return null;\n }\n return {\n row: entry,\n columnId: target.columnId,\n native: {\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n altKey: event.altKey,\n button: event.button,\n },\n };\n }\n\n function reportRowPointer(\n event: ReactMouseEvent,\n callback: ((event: RowPointerEvent<Row>) => void) | undefined,\n ): void {\n if (callback === undefined) return;\n const pointer = rowPointerEventOf(event);\n if (pointer !== null) {\n callback(pointer);\n }\n }\n\n return (\n <tbody\n // The rowgroup is the scrolling element around the body's table.\n role=\"presentation\"\n className=\"gridkit-grid-body\"\n onFocus={(event) => {\n const group = groupRowFrom(event.target);\n if (group !== null) {\n // One cell for the whole row — see the note on `focused` below.\n nav.focusCell(bodyFocus(group.rowIndex, 0));\n return;\n }\n const found = targetOf(event.target);\n if (found === null) return;\n nav.focusCell(\n bodyFocus(found.position.rowIndex, found.position.columnIndex),\n );\n }}\n onClick={(event) => {\n const group = groupRowFrom(event.target);\n if (group !== null) {\n controller.toggleGroupExpansion(group.groupId);\n return;\n }\n const found = targetOf(event.target);\n if (found !== null) {\n select(found.rowId, found.position.columnId, event);\n }\n // After selecting, so a handler reading the selection sees this\n // click's.\n reportRowPointer(event, onRowClick);\n }}\n onDoubleClick={(event) => {\n reportRowPointer(event, onRowDoubleClick);\n }}\n onKeyDown={(event) => {\n if (!isOwnEvent(event)) return;\n const group = groupRowFrom(event.target);\n if (group !== null) {\n // One cell spans every column, so there is nothing to move within —\n // left/right stay a no-op rather than silently moving `nav`'s\n // stored column index off of a cell this row doesn't have.\n if (event.key === \"ArrowLeft\" || event.key === \"ArrowRight\") {\n event.preventDefault();\n return;\n }\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n controller.toggleGroupExpansion(group.groupId);\n return;\n }\n nav.onKeyDown(event);\n return;\n }\n\n // Space builds a selection up and Enter replaces it, matching the\n // Ctrl-click and the plain click they stand in for.\n if (event.key === \" \" || event.key === \"Enter\") {\n const found = targetOf(event.target);\n if (found === null) return;\n // Taken whether or not anything is selectable: Space would otherwise\n // scroll the grid out from under the focused cell.\n event.preventDefault();\n select(\n found.rowId,\n found.position.columnId,\n keyboardSelectIntent(event),\n );\n return;\n }\n nav.onKeyDown(event);\n }}\n >\n {virtualRange !== null && virtualRange.offsetBefore > 0 && (\n // `aria-hidden` and carrying neither `data-gridkit-column` nor\n // `data-gridkit-group`/`data-gridkit-row-index`, so `bodyCellFrom`/\n // `groupRowFrom` never mistake it for a real row — it exists purely\n // to give the browser's scrollbar the correct total height and thumb\n // position, the same way `GridFooter`'s `<tfoot>` isn't a \"row\" to\n // any of this grid's own row-counting logic.\n <tr aria-hidden=\"true\">\n <td\n style={{\n height: virtualRange.offsetBefore,\n padding: 0,\n border: \"none\",\n }}\n />\n </tr>\n )}\n {visibleRows.map((entry) => {\n switch (entry.kind) {\n case \"data\": {\n const rowProps = rowPropsOf(entry.rowId);\n return (\n <GridRow<Row>\n key={entry.rowId}\n ref={virtualRange?.measureRow(entry.rowIndex)}\n columns={columns}\n rowId={entry.rowId}\n row={entry.row}\n rowIndex={entry.rowIndex}\n datasetIndex={entry.datasetIndex}\n groupLevel={entry.groupPosition?.level}\n groupPosition={entry.groupPosition?.position}\n groupSetSize={entry.groupPosition?.setSize}\n activeColumnId={activeColumnId}\n selectedColumnIds={selection.selectedColumnIds}\n selected={selection.selectedRowIds.has(entry.rowId)}\n /*\n * Narrowed to this row before it crosses the boundary, so\n * that moving the selected cell re-renders the two rows it\n * moved between rather than all of them.\n */\n selectedColumnId={\n selectedCell.kind === \"cell\" &&\n selectedCell.rowId === entry.rowId\n ? selectedCell.columnId\n : null\n }\n focusedColumnIndex={focusedColumnInRow(\n nav.focus,\n entry.rowIndex,\n )}\n rowsSelectable={rowMode !== false}\n cellsSelectable={cellMode !== false}\n contextMenu={cellMenu}\n locale={locale}\n cellMessages={cellMessages}\n rowClassName={rowProps.className}\n rowAttributes={rowProps.attributes}\n />\n );\n }\n\n case \"group-summary\":\n return (\n <GridGroupSummaryRow<Row>\n key={`${entry.groupId}-summary`}\n ref={virtualRange?.measureRow(entry.rowIndex)}\n groupId={entry.groupId}\n level={entry.level}\n rowIndex={entry.rowIndex}\n datasetIndex={entry.datasetIndex}\n results={entry.aggregates}\n aggregates={aggregates}\n columns={columns}\n locale={locale}\n />\n );\n\n case \"group\":\n return (\n <GridGroupRow\n key={entry.groupId}\n ref={virtualRange?.measureRow(entry.rowIndex)}\n columnCount={columns.length}\n groupId={entry.groupId}\n level={entry.level}\n // A grouping by a column the grid does not have reads its value\n // by its kind alone.\n groupColumn={\n definitions.get(entry.columnId) ?? { field: entry.columnId }\n }\n value={entry.value}\n expanded={entry.expanded}\n count={entry.count}\n rowIndex={entry.rowIndex}\n datasetIndex={entry.datasetIndex}\n posinset={entry.position}\n setsize={entry.setSize}\n // Inline rendering only under \"inline\" display — under \"row\",\n // the group's own summary row (above) already shows these, and\n // showing them twice would be redundant.\n aggregates={\n groupAggregateDisplay === \"inline\" ? aggregates : []\n }\n results={entry.aggregates}\n definitions={definitions}\n locale={locale}\n cellMessages={cellMessages}\n // Ignores `nav.focus.columnIndex`: with only one cell in this\n // row, whether it holds the tab stop depends on `rowIndex`\n // alone.\n focused={focusedColumnInRow(nav.focus, entry.rowIndex) !== null}\n contextMenu={groupMenu}\n />\n );\n\n default:\n return entry satisfies never;\n }\n })}\n {empty !== null && (\n <GridEmptyRow\n columnCount={columns.length}\n viewportWidth={viewportWidth}\n >\n {emptyTemplate\n ? emptyTemplate(empty)\n : empty.filtered\n ? messages.noMatchingRows\n : messages.noRows}\n </GridEmptyRow>\n )}\n {virtualRange !== null && virtualRange.offsetAfter > 0 && (\n <tr aria-hidden=\"true\">\n <td\n style={{\n height: virtualRange.offsetAfter,\n padding: 0,\n border: \"none\",\n }}\n />\n </tr>\n )}\n {/*\n * Presentational, like the spacer rows above: neither carries\n * `data-gridkit-row-index`/`data-gridkit-column`, so `bodyCellFrom`/\n * `groupRowFrom` never match them, and neither is part of `rows` (the\n * array `aria-rowcount` and `useGridNavigation`'s `rowCount` are\n * computed from in `DataGrid.tsx`), so both are already excluded from\n * row counting and keyboard navigation without any extra check here.\n */}\n {infiniteScroll?.hasMore && (\n <>\n {infiniteScroll.isLoadingMore === true && (\n <tr aria-hidden=\"true\" className=\"gridkit-grid-loading-row\">\n <td\n colSpan={columns.length}\n className=\"gridkit-grid-loading-cell\"\n >\n {infiniteScroll.loadingTemplate\n ? infiniteScroll.loadingTemplate()\n : messages.loadingMore}\n </td>\n </tr>\n )}\n <tr\n aria-hidden=\"true\"\n ref={sentinelRef}\n className=\"gridkit-grid-sentinel-row\"\n >\n <td\n colSpan={columns.length}\n style={{ padding: 0, border: \"none\" }}\n />\n </tr>\n </>\n )}\n </tbody>\n );\n}\n","import {\n useEffect,\n useLayoutEffect,\n useState,\n useSyncExternalStore,\n type KeyboardEvent as ReactKeyboardEvent,\n type RefObject,\n} from \"react\";\nimport type { GridFocus } from \"@gridkitjs/core\";\nimport {\n createGridFocus,\n findBodyRow,\n measurePageSize,\n writingDirection,\n type FocusVirtualRange,\n type GridFocusOptions,\n type GridFocusRows,\n} from \"@gridkitjs/dom\";\n\ninterface UseGridNavigationOptions {\n /**\n * The `role=\"grid\"` element holding every row: focus leaving it, or a\n * wheel or press inside it, drops a move still waiting for its row.\n */\n gridRef: RefObject<HTMLElement | null>;\n headerTableRef: RefObject<HTMLTableElement | null>;\n bodyTableRef: RefObject<HTMLTableElement | null>;\n rowCount: number;\n columnCount: number;\n /**\n * Rows the vertical navigation keys step over rather than land a tab stop\n * on — a group's own summary row (`groupAggregateDisplay: \"row\"`), which\n * still occupies a real row slot for `rowCount` purposes but is\n * presentational, not a stop of its own. Left unset (skips nothing) for a\n * grid with no such rows.\n */\n isSkippableRow?: ((rowIndex: number) => boolean) | undefined;\n /**\n * The window `useRowVirtualizer` drew, present only when `virtualized` is\n * on, in which case behavior is otherwise unchanged. A focus move can\n * target a row index that isn't currently mounted — `ArrowDown` repeated\n * past the mounted window's end, or `End`/`Ctrl+End` jumping straight to\n * the last row.\n */\n virtualRange?: FocusVirtualRange | null | undefined;\n}\n\nexport interface GridNavigationApi {\n focus: GridFocus;\n /**\n * `0` for the focused cell and `-1` for every other. A grid is one tab stop:\n * tabbing reaches it, and the arrow keys move within it.\n */\n tabIndexFor: (cell: GridFocus) => 0 | -1;\n /** Moves the tab stop, and the browser's focus with it. */\n focusCell: (focus: GridFocus) => void;\n /**\n * `focusCell` for a cell on screen, whose browser focus moves now rather\n * than once the move is drawn — for something about to take focus from\n * it, such as a menu opened on it, which the drawing would pull focus back\n * out of. It renders nothing synchronously, so it is safe in an effect.\n */\n focusCellNow: (focus: GridFocus) => void;\n /**\n * The cell holding the tab stop, as drawn now, or `null` while its row is\n * not drawn — where focus goes when the element it was to go back to has\n * gone, as a header does when a menu opened on it hides its column.\n */\n tabStopCell: () => HTMLElement | null;\n /** Handles the navigation keys, leaving every other key to bubble. */\n onKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => void;\n}\n\n/**\n * `0` for the column holding the tab stop and `-1` for every other.\n * Standalone rather than reached only through the hook's own `tabIndexFor`,\n * because `GridRow` is `memo()`-wrapped and cannot take the whole `nav`\n * object as a prop without defeating that boundary. Takes the row's own\n * already-narrowed `focusedColumnIndex` (`null` when focus sits on a\n * different row) rather than a `GridFocus`, since that narrowing —\n * `focusedColumnInRow`, done once per row in `GridBody` — is what keeps a\n * focus move from re-rendering every row instead of the two it actually\n * touches.\n */\nexport function tabIndexFor(\n columnIndex: number,\n focusedColumnIndex: number | null,\n): 0 | -1 {\n return columnIndex === focusedColumnIndex ? 0 : -1;\n}\n\n/**\n * The column holding the tab stop when it sits in body row `rowIndex`, or\n * `null` when it sits in another row or in the header.\n */\nexport function focusedColumnInRow(\n focus: GridFocus,\n rowIndex: number,\n): number | null {\n return focus.area === \"body\" && focus.rowIndex === rowIndex\n ? focus.columnIndex\n : null;\n}\n\nfunction sameCell(a: GridFocus, b: GridFocus): boolean {\n if (a.columnIndex !== b.columnIndex) {\n return false;\n }\n return a.area === \"header\"\n ? b.area === \"header\"\n : focusedColumnInRow(b, a.rowIndex) !== null;\n}\n\n/**\n * The grid's single tab stop, kept by `@gridkitjs/dom`'s `createGridFocus`\n * and drawn from it: created once, handed the current counts and window on\n * every render, and subscribed to, so a move re-renders the grid. The\n * header row comes from the header table's own `.tHead`; a body row through\n * `findBodyRow`, by its `data-gridkit-row-index`.\n */\nexport default function useGridNavigation({\n gridRef,\n headerTableRef,\n bodyTableRef,\n rowCount,\n columnCount,\n isSkippableRow,\n virtualRange,\n}: UseGridNavigationOptions): GridNavigationApi {\n const options: GridFocusOptions = {\n rowCount,\n columnCount,\n isSkippableRow,\n virtualRange,\n };\n const [gridFocus] = useState(() => createGridFocus(options));\n // During render, like `useGridController`'s `setOptions`: the focus this\n // render draws is clamped to this render's row and column counts.\n gridFocus.setOptions(options);\n // `getFocus` serves the server too: nothing can move focus before the grid\n // hydrates, so both sides draw the same initial tab stop.\n const focus = useSyncExternalStore(\n gridFocus.subscribe,\n gridFocus.getFocus,\n gridFocus.getFocus,\n );\n\n const [rows] = useState<GridFocusRows>(() => ({\n getHeaderRow: () => headerTableRef.current?.tHead?.rows[0] ?? null,\n getBodyRow: (rowIndex) => findBodyRow(bodyTableRef.current, rowIndex),\n }));\n useLayoutEffect(\n () => gridFocus.attach(rows, gridRef.current),\n [gridFocus, rows, gridRef],\n );\n\n // After every commit rather than only when `focus` changes: under\n // virtualization the target row may mount only in a later drawing, once\n // the window has scrolled to it, and this is what retries.\n useEffect(() => {\n gridFocus.focusDrawnCell(focus);\n });\n\n // A new object each render, as the other hooks here return: `tabIndexFor`\n // closes over the focus it draws.\n return {\n focus,\n tabIndexFor: (cell) => (sameCell(cell, focus) ? 0 : -1),\n focusCell: gridFocus.focusCell,\n focusCellNow: (next) => {\n gridFocus.focusCell(next);\n // The cell is drawn already, all but its tab stop, so the move is\n // followed now, and the drawing that redraws the stop has none left.\n gridFocus.focusDrawnCell(gridFocus.getFocus());\n },\n tabStopCell: () => {\n // Read from the store rather than this render's `focus`: an overlay\n // asks while the drawing that moved the stop is being committed.\n const stop = gridFocus.getFocus();\n const cells = (\n stop.area === \"header\"\n ? rows.getHeaderRow()\n : rows.getBodyRow(stop.rowIndex)\n )?.cells;\n // A group header's row has one cell, whatever column the stop is in.\n return cells?.[Math.min(stop.columnIndex, cells.length - 1)] ?? null;\n },\n onKeyDown: (event) => {\n if (\n gridFocus.handleKey(\n event.key,\n event,\n measurePageSize(bodyTableRef.current, gridRef.current),\n writingDirection(event.currentTarget),\n )\n ) {\n event.preventDefault();\n }\n },\n };\n}\n","import type { ResolvedRow, RowProps } from \"@gridkitjs/core\";\n\nexport type RowAttributes = Readonly<Record<`data-${string}`, string>>;\n\n/** What `GridRow` is handed from `getRowProps`, both always present. */\nexport interface ResolvedRowProps {\n readonly className: string;\n readonly attributes: RowAttributes;\n}\n\n/** Shared by every row without attributes, so each compares equal to the last. */\nexport const NO_ATTRIBUTES: RowAttributes = {};\n\nconst NO_ROW_PROPS: ResolvedRowProps = {\n className: \"\",\n attributes: NO_ATTRIBUTES,\n};\n\nfunction sameAttributes(a: RowAttributes, b: RowAttributes): boolean {\n const keys = Object.keys(a) as (keyof RowAttributes)[];\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => a[key] === b[key])\n );\n}\n\n/**\n * Runs `getRowProps` over the rows about to render, keeping each row's\n * attributes the same object as last time while they read the same.\n *\n * `GridRow` is memoised, and `getRowProps` returns a fresh attributes object\n * on every call — often from an inline arrow that is itself new on every\n * render — so handing those objects straight through would redraw every row\n * on every render. The class is a string and compares by value already.\n *\n * Remembers only the rows of the latest call, so a virtualized grid scrolled\n * over many rows holds no more than the ones on screen.\n */\nexport function createRowPropsResolver<Row>(): (\n rows: readonly ResolvedRow<Row>[],\n getRowProps: ((row: ResolvedRow<Row>) => RowProps) | undefined,\n) => (rowId: string) => ResolvedRowProps {\n let previous = new Map<string, RowAttributes>();\n return (rows, getRowProps) => {\n if (getRowProps === undefined) {\n previous = new Map();\n return () => NO_ROW_PROPS;\n }\n const resolved = new Map<string, ResolvedRowProps>();\n const attributesById = new Map<string, RowAttributes>();\n for (const entry of rows) {\n const { className = \"\", attributes = NO_ATTRIBUTES } = getRowProps(entry);\n const last = previous.get(entry.rowId);\n const stable =\n last !== undefined && sameAttributes(last, attributes)\n ? last\n : attributes;\n attributesById.set(entry.rowId, stable);\n resolved.set(entry.rowId, { className, attributes: stable });\n }\n previous = attributesById;\n return (rowId) => resolved.get(rowId) ?? NO_ROW_PROPS;\n };\n}\n","import type { CSSProperties, ReactNode } from \"react\";\n\ninterface GridEmptyRowProps {\n columnCount: number;\n /** The scroll area's inner width, so the content centres in the part of the row in view. `null` until measured. */\n viewportWidth: number | null;\n children: ReactNode;\n}\n\n/**\n * Stands in for the rows when there are none to show.\n *\n * A row the grid owns, so a screen reader reading the grid reaches it, but\n * not one of its rows: it has no `aria-rowindex`, `aria-rowcount` leaves it\n * out, and it carries neither `data-gridkit-row-index` nor\n * `data-gridkit-column`, so navigation, selection and the row events never\n * address it. Nothing in it takes focus unless the app's template puts it\n * there.\n */\nexport default function GridEmptyRow({\n columnCount,\n viewportWidth,\n children,\n}: GridEmptyRowProps) {\n const contentStyle =\n viewportWidth === null\n ? undefined\n : ({\n \"--gridkit-empty-width\": `${String(viewportWidth)}px`,\n } as CSSProperties);\n return (\n <tr role=\"row\" className=\"gridkit-grid-empty-row\">\n <td\n role=\"gridcell\"\n colSpan={columnCount}\n className=\"gridkit-grid-empty-cell\"\n >\n <div className=\"gridkit-grid-empty-content\" style={contentStyle}>\n {children}\n </div>\n </td>\n </tr>\n );\n}\n","import { memo, type Ref } from \"react\";\nimport {\n formatGroupValue,\n resolveColumnLabel,\n type AggregateResults,\n type AggregateState,\n type FormatLocale,\n type GridMessages,\n} from \"@gridkitjs/core\";\nimport type { ColumnDefinition } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport { renderAggregate } from \"./renderAggregate\";\n\ninterface GridGroupRowProps<Row> {\n /** How many columns this group's header spans, matching the grid's own count. */\n columnCount: number;\n groupId: string;\n /** Nesting depth, 0 for a top-level group — indents the header and feeds `aria-level`. */\n level: number;\n /** The column grouped by, whose label names the group and whose formatting its value reads in. */\n groupColumn: ColumnDefinition<Row>;\n /** This group's own value — the last entry of its `path`. */\n value: unknown;\n expanded: boolean;\n /** Leaf row count under this group, regardless of collapse state. */\n count: number;\n /** This row's position in the full (unsliced) display-rows array — see `ResolvedGroupRow.rowIndex`. */\n rowIndex: number;\n /** This header's absolute position in the whole dataset, unaffected by which page is showing — see `ResolvedGroupRow.datasetIndex`. */\n datasetIndex: number;\n /** This group's 1-based position among its own siblings, for `aria-posinset`. */\n posinset: number;\n /** How many siblings this group has, for `aria-setsize`. */\n setsize: number;\n /** Whether this row currently holds the grid's single tab stop. */\n focused: boolean;\n /** Whether this row opens the grid's context menu, which its `aria-keyshortcuts` says. */\n contextMenu: boolean;\n /** Active aggregates — empty when none are active, in which case no subtotal renders. */\n aggregates: AggregateState<Row>;\n /** This group's own computed results, keyed the same way `aggregates` resolves each spec's key. */\n results: AggregateResults;\n /** Every column's definition by id, hidden ones included — whose label and formatting each aggregate takes. */\n definitions: ReadonlyMap<string, ColumnDefinition<Row>>;\n /** The grid's `locale`, which values are formatted for. */\n locale: FormatLocale;\n /** The words for a boolean or missing group value, from `messages` — memoised by `GridBody`. */\n cellMessages: Pick<\n GridMessages,\n \"booleanTrue\" | \"booleanFalse\" | \"blankGroupValue\"\n >;\n ref?: Ref<HTMLTableRowElement> | undefined;\n}\n\nfunction GridGroupRowComponent<Row>({\n columnCount,\n groupId,\n level,\n groupColumn,\n value,\n expanded,\n count,\n rowIndex,\n datasetIndex,\n posinset,\n setsize,\n focused,\n contextMenu,\n aggregates,\n results,\n definitions,\n locale,\n cellMessages,\n ref,\n}: GridGroupRowProps<Row>) {\n return (\n <tr\n ref={ref}\n role=\"row\"\n // Two past the index: rows are counted from one, and the header is the\n // first of them — the same convention `GridRow` uses. Built from\n // `datasetIndex`, not the page-relative `rowIndex`, matching `GridRow`.\n aria-rowindex={datasetIndex + 2}\n // 1-based, per the WAI-ARIA treegrid pattern.\n aria-level={level + 1}\n aria-expanded={expanded}\n aria-setsize={setsize}\n aria-posinset={posinset}\n data-gridkit-group={groupId}\n // See `GridRow`'s own `data-gridkit-row-index` for why this reads off\n // the array position rather than the DOM's `sectionRowIndex`.\n data-gridkit-row-index={rowIndex}\n className={classNames(\n \"gridkit-grid-group-row\",\n `is-group-level-${String(level)}`,\n )}\n >\n <td\n role=\"gridcell\"\n colSpan={columnCount}\n tabIndex={focused ? 0 : -1}\n aria-keyshortcuts={\n contextMenu ? \"Space Enter Shift+F10\" : \"Space Enter\"\n }\n className=\"gridkit-grid-group-cell\"\n >\n {/*\n * The flex layout lives on this inner `div`, not the `<td>` itself:\n * a `display` other than `table-cell` on the cell element changes\n * its box type entirely, and the browser fixes that up by wrapping\n * it in an anonymous table-cell — which throws off the cell's own\n * hit-testing (a click landing where the row's bounding box says\n * the cell is can miss it and hit the table underneath instead).\n */}\n <div\n className=\"gridkit-grid-group-cell-content\"\n style={{ paddingInlineStart: `${String(level * 1.25 + 0.5)}rem` }}\n >\n <span\n className={classNames(\n \"gridkit-group-toggle\",\n expanded ? \"is-expanded\" : \"is-collapsed\",\n )}\n aria-hidden=\"true\"\n />\n <span className=\"gridkit-group-label\">\n {resolveColumnLabel(groupColumn)}:{\" \"}\n {formatGroupValue(value, groupColumn, locale, cellMessages)}\n </span>\n <span className=\"gridkit-group-count\">({count})</span>\n {aggregates.length > 0 && (\n <span className=\"gridkit-group-aggregates\">\n {aggregates.map((spec) => {\n const key = spec.id ?? spec.columnId;\n const aggregateValue = results.get(key);\n const column = definitions.get(spec.columnId);\n const rendered = renderAggregate(\n aggregateValue,\n spec,\n column,\n [],\n locale,\n );\n // An explicit `id` disambiguates two specs on the same\n // column (e.g. both `sum` and `avg` of Amount) — when given,\n // it's the caller's own label for this result, so it takes\n // priority over the column's shared label.\n const aggregateLabel =\n spec.id ??\n (column === undefined\n ? spec.columnId\n : resolveColumnLabel(column));\n return (\n <span key={key} className=\"gridkit-group-aggregate\">\n {aggregateLabel}: {rendered}\n </span>\n );\n })}\n </span>\n )}\n </div>\n </td>\n </tr>\n );\n}\n\n/**\n * `memo()`-wrapped for the same reason `GridRow` is: every prop here is a\n * scalar or an already-narrowed value, and no handler reaches this component\n * directly — `GridBody` delegates group-header clicks and keydowns the same\n * way it does for data rows.\n */\nconst GridGroupRow = memo(\n GridGroupRowComponent,\n) as typeof GridGroupRowComponent;\n\nexport default GridGroupRow;\n","import type { ReactNode } from \"react\";\nimport {\n formatAggregateValue,\n type AggregateSpec,\n type FormatLocale,\n} from \"@gridkitjs/core\";\nimport type { ColumnDefinition } from \"../DataGrid\";\n\n/**\n * One aggregate result as the grid shows it — in the grand-total footer, a\n * group's summary row, or inline in a group's header. The column's own\n * `footerTemplate` when it has one; otherwise the text\n * `formatAggregateValue` makes of it, with a dash standing in for an empty\n * result so a cell that has an aggregate never looks like one that has none.\n */\nexport function renderAggregate<Row>(\n value: unknown,\n spec: AggregateSpec<Row>,\n column: ColumnDefinition<Row> | undefined,\n rows: readonly Row[],\n locale: FormatLocale,\n): ReactNode {\n if (column?.footerTemplate) {\n return column.footerTemplate({ value, rows });\n }\n if (value === null || value === undefined) {\n return \"—\";\n }\n return formatAggregateValue(value, spec, column, locale);\n}\n","import { memo, type Ref } from \"react\";\nimport type {\n AggregateResults,\n AggregateState,\n FormatLocale,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport { textAlignFor } from \"../textAlign\";\nimport { renderAggregate } from \"./renderAggregate\";\n\ninterface GridGroupSummaryRowProps<Row> {\n groupId: string;\n /** Nesting depth, matching the group's own level — indents the row the same amount `GridGroupRow` does. */\n level: number;\n /** This row's position in the full (unsliced) display-rows array — see `ResolvedGroupSummaryRow.rowIndex`. */\n rowIndex: number;\n /** This row's absolute position in the whole dataset, unaffected by which page is showing — see `ResolvedGroupSummaryRow.datasetIndex`. */\n datasetIndex: number;\n /** The group's own computed results — identical to its header's `aggregates`. */\n results: AggregateResults;\n aggregates: AggregateState<Row>;\n columns: readonly ResolvedColumn<Row>[];\n /** The grid's `locale`, which values are formatted for. */\n locale: FormatLocale;\n ref?: Ref<HTMLTableRowElement> | undefined;\n}\n\n/**\n * A group's own aggregate results, one real `<td>` per column rather than\n * text inside the header's single spanning cell — the `groupAggregateDisplay:\n * \"row\"` alternative to `GridGroupRow`'s own inline rendering. Structurally\n * mirrors `GridFooter`'s grand-total row, scoped to one group's `results`\n * instead of the dataset-wide total, and indented the same amount its own\n * `GridGroupRow` is.\n *\n * Presentational: it occupies a real row slot (counted in `rowCount`/\n * `aria-rowindex`, since it is a genuine `<tr>` inside `<tbody>`) but is\n * never a keyboard tab stop — `DataGrid.tsx`'s `isSkippableRow` steps over\n * it during arrow-key navigation the same way this component itself takes\n * no `tabIndex`, `role=\"row\"`/`\"gridcell\"` only, no interactive attributes.\n *\n * Each cell's alignment follows the same rule `GridFooter`'s own cells do:\n * the first matching spec's `AggregateSpec.alignment` override, falling\n * back to the column's own `alignment` when neither is set.\n */\nfunction GridGroupSummaryRowComponent<Row>({\n groupId,\n level,\n rowIndex,\n datasetIndex,\n results,\n aggregates,\n columns,\n locale,\n ref,\n}: GridGroupSummaryRowProps<Row>) {\n return (\n <tr\n ref={ref}\n role=\"row\"\n aria-rowindex={datasetIndex + 2}\n data-gridkit-group-summary={groupId}\n // See `GridRow`'s own `data-gridkit-row-index` for why this reads off\n // the array position rather than the DOM's `sectionRowIndex`.\n data-gridkit-row-index={rowIndex}\n className={classNames(\n \"gridkit-grid-group-summary-row\",\n `is-group-level-${String(level)}`,\n )}\n >\n {columns.map((entry) => {\n const specs = aggregates.filter(\n (candidate) => candidate.columnId === entry.id,\n );\n\n return (\n <td\n key={entry.id}\n role=\"gridcell\"\n data-gridkit-column={entry.id}\n className={classNames(\n \"gridkit-grid-group-summary-cell\",\n pinnedCellClassNames(entry),\n )}\n style={{\n textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),\n ...pinnedCellStyle(entry),\n }}\n >\n {entry.id === columns[0]?.id && (\n <span\n className=\"gridkit-grid-group-summary-indent\"\n style={{ width: `${String(level * 1.25 + 0.5)}rem` }}\n aria-hidden=\"true\"\n />\n )}\n {specs\n .map((spec) =>\n renderAggregate(\n results.get(spec.id ?? spec.columnId),\n spec,\n entry.column,\n [],\n locale,\n ),\n )\n .flatMap((rendered, index) =>\n index === 0 ? [rendered] : [\", \", rendered],\n )}\n </td>\n );\n })}\n </tr>\n );\n}\n\n/**\n * `memo()`-wrapped for the same reason `GridGroupRow`/`GridRow` are: every\n * prop here is a scalar or an already-narrowed value.\n */\nconst GridGroupSummaryRow = memo(\n GridGroupSummaryRowComponent,\n) as typeof GridGroupSummaryRowComponent;\n\nexport default GridGroupSummaryRow;\n","import type { ColumnAlignment } from \"@gridkitjs/core\";\n\n/**\n * The `text-align` a column's `alignment` renders with. `\"left\"` and\n * `\"right\"` name the reading-start and reading-end sides, which `start` and\n * `end` follow: they render exactly as `left` and `right` in a left-to-right\n * page and mirror under `dir=\"rtl\"`.\n */\nexport function textAlignFor(\n alignment: ColumnAlignment,\n): \"start\" | \"center\" | \"end\" {\n switch (alignment) {\n case \"left\":\n return \"start\";\n case \"right\":\n return \"end\";\n case \"center\":\n return \"center\";\n }\n}\n","import {\n accessDotted,\n formatCellValue,\n type FormatLocale,\n type GridMessages,\n} from \"@gridkitjs/core\";\nimport { memo, type Ref } from \"react\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport type { RowAttributes } from \"../rowProps\";\nimport { textAlignFor } from \"../textAlign\";\nimport { tabIndexFor } from \"../useGridNavigation\";\n\ninterface GridRowProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n rowId: string;\n row: Row;\n rowIndex: number;\n /** This row's absolute position in the whole dataset, unaffected by which page is showing — see `CellTemplateContext.datasetIndex`. */\n datasetIndex: number;\n /**\n * The row's `groupPosition` fields, for `aria-level`, `aria-posinset` and\n * `aria-setsize`; `undefined` in an ungrouped grid. Scalars rather than the\n * object, which regrouping rebuilds for every row and would defeat `memo`.\n */\n groupLevel: number | undefined;\n groupPosition: number | undefined;\n groupSetSize: number | undefined;\n /** The column being resized, so its cells outline with its header. */\n activeColumnId: string | null;\n selectedColumnIds: ReadonlySet<string>;\n selected: boolean;\n /** Which of this row's cells is the selected one, if any. */\n selectedColumnId: string | null;\n /** Which of this row's cells holds the grid's tab stop, if any. */\n focusedColumnIndex: number | null;\n rowsSelectable: boolean;\n cellsSelectable: boolean;\n /** Whether a cell opens the grid's context menu, which its `aria-keyshortcuts` says. */\n contextMenu: boolean;\n /** The grid's `locale`, which a cell without a template is formatted for. */\n locale: FormatLocale;\n /** A boolean cell's words, from `messages` — memoised on the two strings by `GridBody`. */\n cellMessages: Pick<GridMessages, \"booleanTrue\" | \"booleanFalse\">;\n /** The class `getRowProps` gave this row, `\"\"` for none. */\n rowClassName: string;\n /** The `data-*` attributes `getRowProps` gave this row — the same object while they read the same, so they do not defeat `memo`. */\n rowAttributes: RowAttributes;\n ref?: Ref<HTMLTableRowElement> | undefined;\n}\n\nfunction GridRowComponent<Row>({\n columns,\n rowId,\n row,\n rowIndex,\n datasetIndex,\n groupLevel,\n groupPosition,\n groupSetSize,\n activeColumnId,\n selectedColumnIds,\n selected,\n selectedColumnId,\n focusedColumnIndex,\n rowsSelectable,\n cellsSelectable,\n contextMenu,\n locale,\n cellMessages,\n rowClassName,\n rowAttributes,\n ref,\n}: GridRowProps<Row>) {\n // The ContextMenu key needs no mention: it says what it does on its face.\n const shortcuts = [\n cellsSelectable ? \"Space Enter\" : \"\",\n contextMenu ? \"Shift+F10\" : \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n return (\n <tr\n // First, so the grid's own attributes below win over one of the same\n // name: `GridBody` finds rows by them.\n {...rowAttributes}\n ref={ref}\n role=\"row\"\n // Two past the index: rows are counted from one, and the header is the\n // first of them. Built from `datasetIndex` rather than the\n // page-relative `rowIndex`, so a paginated grid still reports each\n // row's true position in the whole dataset — the two only diverge once\n // pagination is on.\n aria-rowindex={datasetIndex + 2}\n // This row's position in the full (unsliced) rows array — read by\n // `GridBody`'s event delegation (`bodyCellFrom`) instead of the DOM's own\n // `sectionRowIndex`, which under virtualization no longer matches a\n // row's array position once a leading spacer `<tr>` shifts it.\n data-gridkit-row-index={rowIndex}\n // The row's identity, for a test or a script to find it by however it\n // has moved — the index above changes with every sort.\n data-gridkit-row-id={rowId}\n // One-based, where `groupLevel` counts from zero as a group row's does.\n aria-level={groupLevel === undefined ? undefined : groupLevel + 1}\n aria-posinset={groupPosition}\n aria-setsize={groupSetSize}\n // Omitted rather than `false` when rows cannot be selected, which would\n // otherwise have every row announce that it is not.\n {...ariaAttr(rowsSelectable, \"aria-selected\", selected)}\n className={classNames(\n \"gridkit-grid-row\",\n selected ? \"is-selected\" : \"\",\n rowClassName,\n )}\n >\n {columns.map((entry, columnIndex) => {\n const { id, column, alignment } = entry;\n // Resolved either way, so a template never has to walk the field path\n // a second time.\n const value = accessDotted(row, column.field);\n const cellSelected = id === selectedColumnId;\n\n return (\n <td\n key={id}\n role=\"gridcell\"\n data-gridkit-column={id}\n aria-colindex={columnIndex + 1}\n tabIndex={tabIndexFor(columnIndex, focusedColumnIndex)}\n {...ariaAttr(cellsSelectable, \"aria-selected\", cellSelected)}\n {...ariaAttr(shortcuts !== \"\", \"aria-keyshortcuts\", shortcuts)}\n className={classNames(\n \"gridkit-grid-cell\",\n id === activeColumnId ? \"is-resizing\" : \"\",\n cellSelected || selectedColumnIds.has(id) ? \"is-selected\" : \"\",\n column.wrap?.cells ? \"is-wrapped\" : \"\",\n pinnedCellClassNames(entry),\n column.cellClassName ?? \"\",\n )}\n style={{\n textAlign: textAlignFor(alignment),\n ...pinnedCellStyle(entry),\n }}\n >\n {column.cellTemplate\n ? column.cellTemplate({\n value,\n row,\n rowIndex,\n datasetIndex,\n rowId,\n selected,\n })\n : formatCellValue(value, column, locale, row, cellMessages)}\n </td>\n );\n })}\n </tr>\n );\n}\n\n/**\n * Selection lives at the top of the grid, so any change to it re-renders the\n * whole body — without this boundary a click would rebuild every cell of every\n * row rather than the one or two rows that changed.\n *\n * Every prop above is a scalar or already memoised for that reason, and no\n * handler reaches here at all: the body delegates its events, so a row has\n * nothing to compare that changes each render.\n *\n * `memo` erases the type parameter, and the cast puts it back — the standard\n * price of memoising a generic component.\n */\nconst GridRow = memo(GridRowComponent) as typeof GridRowComponent;\n\nexport default GridRow;\n","import type {\n AggregateResults,\n AggregateState,\n FormatLocale,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport { pinnedCellClassNames, pinnedCellStyle } from \"../pinnedCell\";\nimport { textAlignFor } from \"../textAlign\";\nimport { renderAggregate } from \"./renderAggregate\";\n\ninterface GridFooterProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n aggregates: AggregateState<Row>;\n results: AggregateResults;\n /** Every row the grand total was computed over — what a `footerTemplate` receives as `rows`. */\n rows: readonly Row[];\n /** The grid's `locale`, which values are formatted for. */\n locale: FormatLocale;\n /** This row's `aria-rowindex`: the last of the grid's `aria-rowcount`. */\n ariaRowIndex: number;\n}\n\n/**\n * The grand-total footer — one `<tfoot>` row, one cell per column, using\n * that column's own `footerTemplate` when it defines one, its own computed\n * value formatted like the column's values when it doesn't, and a blank cell for a column\n * with no aggregate at all. Structurally mirrors `GridHeader`, minus\n * everything interactive: a footer cell is not resizable, sortable, or\n * selectable.\n *\n * A column named by more than one spec (e.g. both `sum` and `avg` of the\n * same column, disambiguated by `id`) renders every matching spec's result\n * in its one cell, comma-separated — the cell grid stays one-per-column,\n * but no result is dropped the way picking only the first match would. The\n * cell's own alignment follows the first matching spec's `AggregateSpec.\n * alignment` override, falling back to the column's own `alignment` when\n * neither is set — one `<td>` can only take one `text-align`, so a second\n * spec's own override (if it disagrees) applies only to its value, not the\n * cell.\n *\n * A row of the grid like the header, so it is counted in `aria-rowcount`\n * and takes the index after the last body row, on any page. It is not a\n * stop for keyboard navigation, which moves among body rows only.\n */\nexport default function GridFooter<Row>({\n columns,\n aggregates,\n results,\n rows,\n locale,\n ariaRowIndex,\n}: GridFooterProps<Row>) {\n return (\n <tfoot role=\"rowgroup\">\n <tr\n className=\"gridkit-grid-footer\"\n role=\"row\"\n aria-rowindex={ariaRowIndex}\n >\n {columns.map((entry) => {\n const specs = aggregates.filter(\n (candidate) => candidate.columnId === entry.id,\n );\n\n return (\n <td\n key={entry.id}\n role=\"gridcell\"\n data-gridkit-column={entry.id}\n className={classNames(\n \"gridkit-grid-footer-cell\",\n pinnedCellClassNames(entry),\n )}\n style={{\n textAlign: textAlignFor(specs[0]?.alignment ?? entry.alignment),\n ...pinnedCellStyle(entry),\n }}\n >\n {specs\n .map((spec) =>\n renderAggregate(\n results.get(spec.id ?? spec.columnId),\n spec,\n entry.column,\n rows,\n locale,\n ),\n )\n // Two values in one cell need a visible separator; a single\n // one (the common case) renders exactly as before.\n .flatMap((rendered, index) =>\n index === 0 ? [rendered] : [\", \", rendered],\n )}\n </td>\n );\n })}\n </tr>\n </tfoot>\n );\n}\n","import type { CSSProperties, ReactNode } from \"react\";\nimport { classNames } from \"../classNames\";\n\ninterface GridLoadingOverlayProps {\n /** Whether the body has no rows beneath it, so the overlay sets the body's height rather than covering it. */\n empty: boolean;\n /** The scroll area's inner width, so the content centres in the part of the body in view. `null` until measured. */\n viewportWidth: number | null;\n children: ReactNode;\n}\n\n/**\n * Covers the body while the grid's `loading` option is on, over the rows\n * already drawn, which keep their places beneath it; pointer input on the\n * body lands on it rather than on them.\n *\n * Like the empty row, a row the grid owns, so a screen reader reading the\n * grid reaches its message, but not one of its rows: it has no\n * `aria-rowindex`, `aria-rowcount` leaves it out, and navigation, selection\n * and the row events never address it.\n */\nexport default function GridLoadingOverlay({\n empty,\n viewportWidth,\n children,\n}: GridLoadingOverlayProps) {\n const contentStyle =\n viewportWidth === null\n ? undefined\n : ({\n \"--gridkit-loading-width\": `${String(viewportWidth)}px`,\n } as CSSProperties);\n return (\n <div\n role=\"row\"\n className={classNames(\n \"gridkit-grid-loading-overlay\",\n empty && \"is-empty\",\n )}\n >\n <div\n role=\"gridcell\"\n className=\"gridkit-grid-loading-overlay-content\"\n style={contentStyle}\n >\n {children}\n </div>\n </div>\n );\n}\n","import type { CSSProperties, ReactNode } from \"react\";\nimport type { GridMessages } from \"@gridkitjs/core\";\nimport { paginationWindow } from \"@gridkitjs/core/renderer\";\nimport type { PagerConfig, PagerTemplateContext } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport {\n ChevronLeftIcon,\n ChevronRightIcon,\n ChevronsLeftIcon,\n ChevronsRightIcon,\n} from \"../icons\";\n\ninterface GridPagerProps {\n /** The same context a `pager.template` is handed. */\n pager: PagerTemplateContext;\n /** Presentation options for the pager. `undefined` renders the `\"compact\"` default with no page-size control. */\n config: PagerConfig | undefined;\n messages: GridMessages;\n}\n\ninterface PagerNavButtonProps {\n /** The modifier class beside `gridkit-grid-pager-button gridkit-grid-pager-nav`. */\n className: string;\n label: string;\n disabled: boolean;\n onClick: () => void;\n children: ReactNode;\n}\n\n/**\n * One of the bar's four arrow segments: an icon, named by its message.\n *\n * Disabled with `aria-disabled` rather than the `disabled` attribute, the\n * way the toolbar's buttons are: the button that reaches an end is the one\n * that has focus, and a natively disabled button drops it to `<body>`. This\n * one keeps it, announced as unavailable, and pressing it again does nothing\n * rather than paging back the other way, as moving focus onto the opposite\n * arrow would.\n */\nfunction PagerNavButton({\n className,\n label,\n disabled,\n onClick,\n children,\n}: PagerNavButtonProps) {\n return (\n <button\n type=\"button\"\n className={`gridkit-grid-pager-button gridkit-grid-pager-nav ${className}`}\n aria-label={label}\n title={label}\n {...ariaAttr(disabled, \"aria-disabled\", true)}\n onClick={() => {\n if (!disabled) onClick();\n }}\n >\n {children}\n </button>\n );\n}\n\n/**\n * The built-in pager: one connected bar of first/previous, the page\n * numbers (or, under the default `\"compact\"` variant, a \"Page X of Y\"\n * status), and next/last, followed — when `config.sizeOptions` is given —\n * by a page-size `<select>`. Rendered as a sibling below the table, not a\n * row inside it, the same reasoning `GroupByBar` gives for its own\n * placement: a control surface, not grid content.\n *\n * The bar holds still as the user pages through it: `paginationWindow`\n * yields a constant number of slots, and `--gridkit-pager-digits` (the page\n * count's digit count) lets the theme give every number slot the same\n * width; the compact status reserves the width of its widest text.\n *\n * Whether this mounts at all is `DataGrid.tsx`'s call (`paginated`), not\n * this component's own.\n */\nexport default function GridPager({ pager, config, messages }: GridPagerProps) {\n const { pagination } = pager;\n // A grid with no rows has no pages, but shows one, empty: page 1 of 1 with\n // nowhere to go.\n const pageCount = Math.max(1, pager.pageCount);\n const currentPage = Math.max(1, pager.currentPage);\n const variant = config?.variant ?? \"compact\";\n const sizeOptions = config?.sizeOptions;\n const atFirst = pagination.pageIndex <= 0;\n const atLast = pagination.pageIndex >= pageCount - 1;\n const barStyle = {\n \"--gridkit-pager-digits\": String(String(pageCount).length),\n } as CSSProperties;\n\n return (\n <div\n className=\"gridkit-grid-pager\"\n role=\"group\"\n aria-label={messages.pagerLabel}\n >\n <div className=\"gridkit-grid-pager-bar\" style={barStyle}>\n <PagerNavButton\n className=\"gridkit-grid-pager-first\"\n label={messages.firstPage}\n disabled={atFirst}\n onClick={() => {\n pager.goToPage(0);\n }}\n >\n <ChevronsLeftIcon />\n </PagerNavButton>\n <PagerNavButton\n className=\"gridkit-grid-pager-previous\"\n label={messages.previousPage}\n disabled={atFirst}\n onClick={() => {\n pager.previousPage();\n }}\n >\n <ChevronLeftIcon />\n </PagerNavButton>\n {variant === \"numbered\" ? (\n paginationWindow(currentPage, pageCount, {\n boundaryCount: config?.boundaryCount,\n siblingCount: config?.siblingCount,\n }).map((entry, index) =>\n entry === \"ellipsis\" ? (\n <span\n key={`ellipsis-${String(index)}`}\n className=\"gridkit-grid-pager-ellipsis\"\n aria-hidden=\"true\"\n >\n …\n </span>\n ) : (\n <button\n key={entry}\n type=\"button\"\n className=\"gridkit-grid-pager-button gridkit-grid-pager-page\"\n aria-label={messages.pageButtonLabel(entry)}\n aria-current={entry === currentPage ? \"page\" : undefined}\n onClick={() => {\n pager.goToPage(entry - 1);\n }}\n >\n {entry}\n </button>\n ),\n )\n ) : (\n <span className=\"gridkit-grid-pager-status-slot\">\n <span className=\"gridkit-grid-pager-status\">\n {messages.pageStatus(currentPage, pageCount)}\n </span>\n {/* The widest the status gets, invisible, so the slot never resizes as the page changes. */}\n <span\n className=\"gridkit-grid-pager-status-sizer\"\n aria-hidden=\"true\"\n >\n {messages.pageStatus(pageCount, pageCount)}\n </span>\n </span>\n )}\n <PagerNavButton\n className=\"gridkit-grid-pager-next\"\n label={messages.nextPage}\n disabled={atLast}\n onClick={() => {\n pager.nextPage();\n }}\n >\n <ChevronRightIcon />\n </PagerNavButton>\n <PagerNavButton\n className=\"gridkit-grid-pager-last\"\n label={messages.lastPage}\n disabled={atLast}\n onClick={() => {\n pager.goToPage(pageCount - 1);\n }}\n >\n <ChevronsRightIcon />\n </PagerNavButton>\n </div>\n {sizeOptions !== undefined && sizeOptions.length > 0 && (\n <label className=\"gridkit-grid-pager-page-size\">\n <select\n value={pagination.pageSize}\n onChange={(event) => {\n pager.setPageSize(Number(event.target.value));\n }}\n >\n {sizeOptions.map((size) => (\n <option key={size} value={size}>\n {size}\n </option>\n ))}\n </select>\n <span className=\"gridkit-grid-pager-page-size-label\">\n {messages.pageSizeLabel}\n </span>\n </label>\n )}\n </div>\n );\n}\n","import { createPortal } from \"react-dom\";\nimport {\n resolveColumnLabel,\n type GridMessages,\n type GroupByState,\n} from \"@gridkitjs/core\";\nimport {\n inlineStep,\n resolveKeyboardDropTarget,\n} from \"@gridkitjs/core/renderer\";\nimport { writingDirection, type GroupByDropTarget } from \"@gridkitjs/dom\";\nimport type { ColumnDefinition, ResolvedColumn } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport useGroupByDrag from \"../useGroupByDrag\";\nimport type { DataGridController } from \"../useGridController\";\n\ninterface GroupByBarProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n /** Every column's definition by id, hidden ones included, so a chip for a hidden column still carries its label. */\n definitions: ReadonlyMap<string, ColumnDefinition<Row>>;\n groupBy: GroupByState;\n /** What a chip's drag, move or remove button changes. */\n controller: DataGridController<Row>;\n /** A column's accessible name — see `DataGrid.tsx`'s own `columnName`. */\n columnName: (columnId: string) => string;\n /** Whether the header drag currently open (if any) could drop into this bar. */\n headerDragEligible: boolean;\n /**\n * Whether the header drag currently open (if any) is for a column already\n * in the group-by stack — a drag this bar rejects outright, since\n * repositioning a grouped column is the chip's job, not the header's.\n */\n headerDragBlocked: boolean;\n /** That header drag's own target within this bar, or `null`. */\n headerDropTarget: GroupByDropTarget | null;\n messages: GridMessages;\n}\n\n/**\n * The active group-by stack, outer to inner, as removable, reorderable\n * chips — and the drop target for a header dragged in from outside it.\n * Each column's own header already carries a group toggle (a pointer\n * affordance, plus `Alt+ArrowDown`) for adding or removing a level without\n * dragging at all; this bar shows the resulting stack, lets a level be\n * removed from it directly, lets a chip be dragged to reorder the stack (or\n * moved via `Ctrl+ArrowLeft`/`Ctrl+ArrowRight` on a focused one), and — for\n * a column whose header sets `groupByDraggable` and isn't grouped yet —\n * accepts a header dropped onto it, at whatever position among the existing\n * chips it's released. A header for a column already in the stack is\n * rejected outright (`is-drag-blocked`, `cursor: not-allowed`): the header\n * only ever adds, and repositioning an existing level is the chip's job.\n *\n * Whether this component mounts at all is `DataGrid.tsx`'s call\n * (`groupByBarVisibility`), not this component's own — it never bails out\n * on its own initiative once rendered.\n *\n * Chips sit outside the grid's own single-roving-tabstop model: there is no\n * shared index to keep in sync the way a row or a header cell has, so each\n * chip (and its own remove button) is simply, always `tabIndex={0}` — plain\n * DOM tab order, no roving-focus bookkeeping.\n */\nexport default function GroupByBar<Row>({\n columns,\n definitions,\n groupBy,\n controller,\n columnName,\n headerDragEligible,\n headerDragBlocked,\n headerDropTarget,\n messages,\n}: GroupByBarProps<Row>) {\n const groupByIds = groupBy.map((entry) => entry.columnId);\n\n const chipDrag = useGroupByDrag({\n groupBy,\n onDrop: (movedId, beforeColumnId) => {\n controller.moveGroupBy(movedId, beforeColumnId);\n },\n });\n\n // Mutually exclusive by construction — one pointer, so at most one of \"a\n // chip dragged within this bar\" and \"a header dragged in from outside it\"\n // is ever active at once.\n const activeDropTarget = chipDrag.dropTarget ?? headerDropTarget;\n const isDragTarget = chipDrag.draggedColumnId !== null || headerDragEligible;\n const showPlaceholder =\n groupBy.length === 0 && columns.some((entry) => entry.groupByDraggable);\n\n function labelFor(columnId: string) {\n const definition = definitions.get(columnId);\n return definition === undefined ? columnId : resolveColumnLabel(definition);\n }\n\n function moveByKeyboard(columnId: string, direction: -1 | 1): void {\n const beforeColumnId = resolveKeyboardDropTarget(\n groupByIds,\n columnId,\n direction,\n );\n if (beforeColumnId === undefined) {\n return;\n }\n controller.moveGroupBy(columnId, beforeColumnId);\n }\n\n return (\n <div\n className={classNames(\n \"gridkit-group-by-bar\",\n isDragTarget ? \"is-drag-target\" : \"\",\n headerDragBlocked ? \"is-drag-blocked\" : \"\",\n )}\n data-gridkit-group-by-bar=\"\"\n role=\"group\"\n aria-label={messages.groupByBarLabel}\n >\n {showPlaceholder && (\n <span className=\"gridkit-group-by-bar-placeholder\">\n {messages.groupByBarPlaceholder}\n </span>\n )}\n {groupBy.map((entry, index) => {\n const dropBefore = activeDropTarget?.beforeColumnId === entry.columnId;\n const dropAfter =\n activeDropTarget?.beforeColumnId === null &&\n index === groupBy.length - 1;\n const dragging = chipDrag.draggedColumnId === entry.columnId;\n\n return (\n <span\n key={entry.columnId}\n className={classNames(\n \"gridkit-group-by-chip\",\n dragging ? \"is-dragging\" : \"\",\n dropBefore ? \"is-drop-before\" : \"\",\n dropAfter ? \"is-drop-after\" : \"\",\n )}\n data-gridkit-group-chip={entry.columnId}\n tabIndex={0}\n aria-label={messages.groupByChipLabel(\n columnName(entry.columnId),\n index + 1,\n groupBy.length,\n )}\n aria-keyshortcuts=\"Control+ArrowLeft Control+ArrowRight\"\n onPointerDown={(event) => {\n chipDrag.startDrag(entry.columnId, event);\n }}\n onKeyDown={(event) => {\n const step = inlineStep(\n event.key,\n writingDirection(event.currentTarget),\n );\n if (step !== null && event.ctrlKey) {\n event.preventDefault();\n moveByKeyboard(entry.columnId, step);\n }\n }}\n >\n <span className=\"gridkit-group-by-chip-label\">\n {labelFor(entry.columnId)}\n </span>\n <button\n type=\"button\"\n className=\"gridkit-group-by-chip-remove\"\n aria-label={messages.removeGroupBy(columnName(entry.columnId))}\n onPointerDown={(event) => {\n // Otherwise the chip's own `onPointerDown` sees this bubble\n // up and starts a drag — the same reason the header's own\n // sort toggle stops it.\n event.stopPropagation();\n }}\n onClick={() => {\n controller.toggleGroupBy(entry.columnId);\n }}\n >\n ×\n </button>\n </span>\n );\n })}\n {/*\n * Portalled to the body, the same reason the header's own drag ghost\n * is: inside the viewport the overflow that makes the grid scroll\n * would clip it, and this bar sits right above that viewport.\n */}\n {chipDrag.draggedColumnId !== null &&\n chipDrag.ghostTransform !== null &&\n createPortal(\n <span\n className=\"gridkit-group-by-chip gridkit-drag-ghost\"\n style={{ transform: chipDrag.ghostTransform }}\n aria-hidden=\"true\"\n >\n {labelFor(chipDrag.draggedColumnId)}\n </span>,\n document.body,\n )}\n </div>\n );\n}\n","import type { PointerEvent as ReactPointerEvent } from \"react\";\nimport type { GroupByState } from \"@gridkitjs/core\";\nimport {\n resolveGroupByDropTarget,\n type GroupByDropTarget,\n} from \"@gridkitjs/dom\";\nimport useDragReorder from \"./useDragReorder\";\n\ninterface UseGroupByDragOptions {\n groupBy: GroupByState;\n onDrop: (movedColumnId: string, beforeColumnId: string | null) => void;\n}\n\nexport interface GroupByDragApi {\n /** The chip being dragged, for as long as the drag lasts. */\n draggedColumnId: string | null;\n /** Where it would land if released now. */\n dropTarget: GroupByDropTarget | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n ghostTransform: string | null;\n startDrag: (columnId: string, event: ReactPointerEvent<HTMLElement>) => void;\n}\n\n/**\n * Drag-to-reorder for chips inside the group-by bar, built on the same\n * `useDragReorder` mechanics `useColumnDrag` uses for headers — only the\n * hit-testing (`resolveGroupByDropTarget`, shared with a header dropped in\n * from outside the bar) differs.\n */\nexport default function useGroupByDrag({\n groupBy,\n onDrop,\n}: UseGroupByDragOptions): GroupByDragApi {\n const drag = useDragReorder<GroupByDropTarget>({\n resolveTarget: (clientX, clientY, movedId) =>\n resolveGroupByDropTarget(clientX, clientY, movedId, groupBy),\n onDrop: (target, movedId) => {\n onDrop(movedId, target.beforeColumnId);\n },\n });\n\n return {\n draggedColumnId: drag.draggedId,\n dropTarget: drag.dropTarget,\n ghostTransform: drag.ghostTransform,\n startDrag: (columnId, event) => {\n drag.startDrag(columnId, event.currentTarget, event);\n },\n };\n}\n","import {\n useLayoutEffect,\n useRef,\n useState,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport {\n NO_DRAG,\n startDragReorder,\n type DragReorderHandlers,\n type DragReorderState,\n} from \"@gridkitjs/dom\";\nimport useGestureSignal from \"./useGestureSignal\";\n\ntype UseDragReorderOptions<Target> = Pick<\n DragReorderHandlers<Target>,\n \"resolveTarget\" | \"onDrop\"\n>;\n\nexport interface DragReorderApi<Target> {\n /** The item being dragged, for as long as the drag lasts. */\n draggedId: string | null;\n /** Where it would land if released now, `null` for nowhere valid. */\n dropTarget: Target | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n ghostTransform: string | null;\n startDrag: (\n id: string,\n grabElement: HTMLElement,\n event: ReactPointerEvent<HTMLElement>,\n ) => void;\n /**\n * Whether `id`'s last press opened a drag, so the `click` that follows its\n * release is not a click, for a press that has something of its own to do\n * with one.\n *\n * Reading it clears it, and so does the next drag's press, so a press that\n * never opened a drag — on an item that cannot be dragged, or after a drag\n * cancelled with Escape and released elsewhere — does not see the last\n * one's answer.\n */\n justDragged: (id: string) => boolean;\n}\n\n/**\n * `@gridkitjs/dom`'s `startDragReorder`, the pointer mechanics behind every\n * drag-to-reorder gesture in the grid, with what it reports held as state\n * for the header and the group-by bar to draw. A column header drag and a\n * group-by chip drag (`useColumnDrag`, `useGroupByDrag`) share it, so they\n * can only ever differ in their own hit-testing (`resolveTarget`).\n *\n * The drag ends with the component, and with its grab element should a\n * render remove it (`useGestureSignal`).\n */\nexport default function useDragReorder<Target>({\n resolveTarget,\n onDrop,\n}: UseDragReorderOptions<Target>): DragReorderApi<Target> {\n const [drag, setDrag] = useState<DragReorderState<Target>>(NO_DRAG);\n /**\n * The item whose press opened a drag, held for the `click` that follows\n * the release: the only thing that can tell a drag apart from a press in\n * the same spot.\n */\n const openedDragId = useRef<string | null>(null);\n const startGesture = useGestureSignal();\n /**\n * What a drag under way resolves its targets and drops against: the\n * handlers of the latest render, so an order or grouping that changes\n * mid-drag counts from the next pointer move.\n */\n const handlers = useRef({ resolveTarget, onDrop });\n useLayoutEffect(() => {\n handlers.current = { resolveTarget, onDrop };\n });\n\n function justDragged(id: string): boolean {\n const answer = openedDragId.current === id;\n openedDragId.current = null;\n return answer;\n }\n\n function startDrag(\n id: string,\n grabElement: HTMLElement,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n const started = startGesture(grabElement, (signal) =>\n startDragReorder(id, grabElement, event, {\n resolveTarget: (clientX, clientY, movedId) =>\n handlers.current.resolveTarget(clientX, clientY, movedId),\n onState(state) {\n if (state.kind === \"dragging\") {\n openedDragId.current = state.draggedId;\n }\n setDrag(state);\n },\n onDrop: (target, movedId) => {\n handlers.current.onDrop(target, movedId);\n },\n signal,\n }),\n );\n // Only a press that began a drag clears it, so a second finger landing\n // mid-drag leaves the drag under way its answer. The new drag reports\n // nothing before its first move, so this never clears what it set.\n if (started) {\n openedDragId.current = null;\n }\n }\n\n const dragging = drag.kind === \"dragging\" ? drag : null;\n return {\n draggedId: dragging?.draggedId ?? null,\n dropTarget: dragging?.dropTarget ?? null,\n ghostTransform: dragging?.ghostTransform ?? null,\n startDrag,\n justDragged,\n };\n}\n","import { useEffect, useRef } from \"react\";\n\ninterface Gesture {\n /** The element the gesture listens on, which `@gridkitjs/dom` captured. */\n readonly element: HTMLElement;\n readonly controller: AbortController;\n}\n\n/**\n * Starts a gesture on `element` with `start`, handing it the `AbortSignal`\n * that ends it, and returns whatever `start` said about whether it began.\n */\nexport type StartGesture = (\n element: HTMLElement,\n start: (signal: AbortSignal) => boolean,\n) => boolean;\n\n/**\n * One `AbortSignal` per pointer gesture, for `@gridkitjs/dom`'s\n * `startDragReorder`/`startColumnResizeGesture`, whose `handlers.signal`\n * cancels the gesture as Escape does.\n *\n * A gesture that begins aborts the one before it; a press that begins none,\n * such as a second finger landing mid-drag, leaves it alone. The signal\n * aborts when the component unmounts, or after any render that has taken the\n * gesture's element out of the document: a header whose column is hidden\n * mid-drag goes with every listener the gesture had on it, so nothing else\n * would ever end what the grid draws for the gesture. Aborting a gesture that\n * has already ended does nothing.\n */\nexport default function useGestureSignal(): StartGesture {\n const gesture = useRef<Gesture | null>(null);\n\n useEffect(() => {\n const current = gesture.current;\n if (current !== null && !current.element.isConnected) {\n gesture.current = null;\n current.controller.abort();\n }\n });\n\n useEffect(\n () => () => {\n gesture.current?.controller.abort();\n },\n [],\n );\n\n return function startGesture(element, start) {\n const controller = new AbortController();\n if (!start(controller.signal)) {\n return false;\n }\n gesture.current?.controller.abort();\n gesture.current = { element, controller };\n return true;\n };\n}\n","import {\n isColumnVisible,\n isGroupExpanded,\n resolveColumnPin,\n type ColumnPinningEvent,\n type ColumnResizeEvent,\n type ColumnSortEvent,\n type ColumnVisibilityEvent,\n type GridMessages,\n type GroupByEvent,\n type GroupExpansionEvent,\n type PaginationChangeEvent,\n type SelectionDiffEvent,\n} from \"@gridkitjs/core\";\nimport type {\n CellSelectionChangeEvent,\n ColumnDefinition,\n DataGridProps,\n} from \"./DataGrid\";\n\n/** The change callbacks of a grid's props that announce what they report. */\ntype AnnouncedProps<Row> = Pick<\n DataGridProps<Row>,\n | \"onColumnSizingChange\"\n | \"onColumnVisibilityChange\"\n | \"onColumnPinningChange\"\n | \"onColumnSortChange\"\n | \"onGroupByChange\"\n | \"onGroupExpansionChange\"\n | \"onPaginationChange\"\n | \"onCellSelectionChange\"\n>;\n\ninterface AnnouncedCallbacksOptions<Row> {\n /** The grid's own callbacks, each called before its change is announced. */\n readonly callbacks: AnnouncedProps<Row>;\n readonly announce: (text: string) => void;\n readonly messages: GridMessages;\n /** What a column is called in an announcement. */\n readonly columnName: (columnId: string) => string;\n /** A column's definition by id, hidden or not. */\n readonly columnOf: (columnId: string) => ColumnDefinition<Row> | undefined;\n}\n\n/** What the grid hands its controller to hear each change through. */\nexport interface AnnouncedCallbacks<Row> {\n readonly onColumnSizingChange: (event: ColumnResizeEvent) => void;\n readonly onColumnVisibilityChange: (event: ColumnVisibilityEvent) => void;\n readonly onColumnPinningChange: (event: ColumnPinningEvent) => void;\n readonly onColumnSortChange: (event: ColumnSortEvent) => void;\n readonly onGroupByChange: (event: GroupByEvent) => void;\n readonly onGroupExpansionChange: (event: GroupExpansionEvent) => void;\n readonly onPaginationChange: (event: PaginationChangeEvent) => void;\n readonly onCellSelectionChange: (\n event: CellSelectionChangeEvent<Row>,\n ) => void;\n readonly onSelectionDiff: (event: SelectionDiffEvent) => void;\n}\n\n/**\n * The grid's change callbacks, each wrapped to announce its change in the\n * live region after calling the grid's own — so a change is announced where\n * the controller reports it, the same whether a click, a key, a menu or the\n * ref made it.\n */\nexport function announcedCallbacks<Row>({\n callbacks,\n announce,\n messages,\n columnName,\n columnOf,\n}: AnnouncedCallbacksOptions<Row>): AnnouncedCallbacks<Row> {\n return {\n /**\n * Announced only once the drag ends: the controller reports the\n * continuous `\"move\"` phase as well, and a live region given every frame\n * of a drag says nothing an assistive technology can keep up with.\n */\n onColumnSizingChange: (event) => {\n callbacks.onColumnSizingChange?.(event);\n if (event.phase === \"end\") {\n announce(\n messages.columnResized(\n columnName(event.columnId),\n Math.round(event.width),\n ),\n );\n }\n },\n\n /**\n * Naming a column shown or hidden alone, and counting several — \"Show\n * all\" in the column chooser, or `hideColumns` given a list. A change\n * that shows some and hides others, as restoring a layout can, has no\n * one thing to say, and says nothing.\n */\n onColumnVisibilityChange: (event) => {\n callbacks.onColumnVisibilityChange?.(event);\n const { columnIds, visibility } = event;\n const [columnId] = columnIds;\n const shownCount = columnIds.filter((id) => {\n const column = columnOf(id);\n return column !== undefined && isColumnVisible(column, visibility);\n }).length;\n if (\n columnId === undefined ||\n (shownCount !== 0 && shownCount !== columnIds.length)\n ) {\n return;\n }\n const shown = shownCount > 0;\n if (columnIds.length > 1) {\n announce(\n shown\n ? messages.columnsShown(columnIds.length)\n : messages.columnsHidden(columnIds.length),\n );\n return;\n }\n announce(\n shown\n ? messages.columnShown(columnName(columnId))\n : messages.columnHidden(columnName(columnId)),\n );\n },\n\n /**\n * Naming the one column pinned or unpinned and the edge it went to. A\n * change touching several columns, as `setColumnPinning` or restoring a\n * layout can, may pin some and unpin others, and says nothing.\n */\n onColumnPinningChange: (event) => {\n callbacks.onColumnPinningChange?.(event);\n const [columnId, ...others] = event.columnIds;\n if (columnId === undefined || others.length > 0) {\n return;\n }\n const column = columnOf(columnId);\n if (column === undefined) {\n return;\n }\n const pin = resolveColumnPin(column, event.pinning);\n announce(\n pin === \"none\"\n ? messages.columnUnpinned(columnName(columnId))\n : messages.columnPinned(columnName(columnId), pin),\n );\n },\n\n /** A toggle, a stack, or a clear back to \"none\" each get their own. */\n onColumnSortChange: (event) => {\n callbacks.onColumnSortChange?.(event);\n const entry = event.sort.find(\n (candidate) => candidate.columnId === event.columnId,\n );\n if (entry === undefined) {\n announce(messages.sortCleared(columnName(event.columnId)));\n return;\n }\n announce(\n messages.columnSorted(\n columnName(event.columnId),\n entry.direction,\n event.sort.indexOf(entry) + 1,\n event.sort.length,\n ),\n );\n },\n\n onGroupByChange: (event) => {\n callbacks.onGroupByChange?.(event);\n const entry = event.groupBy.find(\n (candidate) => candidate.columnId === event.columnId,\n );\n if (entry === undefined) {\n announce(messages.groupingRemoved(columnName(event.columnId)));\n return;\n }\n announce(\n messages.groupedBy(\n columnName(event.columnId),\n event.groupBy.indexOf(entry) + 1,\n event.groupBy.length,\n ),\n );\n },\n\n /**\n * `groupId: null` marks `expandAll`/`collapseAll` and\n * `setGroupExpansion`, which touch every group in one call rather than\n * one at a time — announced as a single summary of the mode the groups\n * now follow, instead of naming a group that doesn't apply.\n */\n onGroupExpansionChange: (event) => {\n callbacks.onGroupExpansionChange?.(event);\n if (event.groupId === null) {\n announce(\n event.expansion.mode === \"allExpanded\"\n ? messages.allGroupsExpanded\n : messages.allGroupsCollapsed,\n );\n return;\n }\n announce(\n isGroupExpanded(event.expansion, event.groupId)\n ? messages.groupExpanded\n : messages.groupCollapsed,\n );\n },\n\n onPaginationChange: (event) => {\n callbacks.onPaginationChange?.(event);\n // As the pager shows it: a grid with no rows reads page 1 of 1.\n announce(\n messages.pageStatus(\n event.pagination.pageIndex + 1,\n Math.max(1, event.pageCount),\n ),\n );\n },\n\n /**\n * Unlike rows and columns, a cell selection is always exactly one cell —\n * there is no multi-cell range — so it never crosses the count's >1\n * threshold and the focused cell's own `aria-selected` is the only\n * feedback a screen-reader user would otherwise get. Announced on every\n * change that lands on a cell instead.\n */\n onCellSelectionChange: (event) => {\n callbacks.onCellSelectionChange?.(event);\n if (event.selected !== null) {\n announce(\n messages.cellSelected(\n columnName(event.selected.columnId),\n event.selected.rowIndex + 1,\n ),\n );\n }\n },\n\n /**\n * Announced only for a change touching more than one row or column. A\n * single selection is already carried by the focused member's own\n * `aria-selected`, and repeating it here would talk over that. Counted\n * by id, so rows the change touched off screen — on another page, in a\n * collapsed group — count too.\n */\n onSelectionDiff: (event) => {\n if (event.added.length + event.removed.length > 1) {\n announce(messages.selectedCount(event.selection.length, event.target));\n }\n },\n };\n}\n","import type { KeyboardEvent } from \"react\";\nimport { runCommand, type GridCommandTarget } from \"@gridkitjs/core\";\nimport { isNativeCopy } from \"@gridkitjs/dom\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\n\ninterface UseGridCopyOptions<Row> {\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n nav: GridNavigationApi;\n}\n\nfunction isCopyKey(event: KeyboardEvent): boolean {\n return (\n (event.ctrlKey || event.metaKey) &&\n !event.altKey &&\n (event.key === \"c\" || event.key === \"C\")\n );\n}\n\n/**\n * Ctrl+C (Cmd+C on a Mac) on the grid: copies the selection, else the\n * focused cell, through the same `copy.selection` and `copy.cell` commands\n * the context menu runs — so an app that overrides one changes both. The\n * returned handler belongs on the grid root's `onKeyDown`, for keys the\n * grid itself received.\n *\n * A press in a text field inside a cell, or with text highlighted on the\n * page, is the browser's, and so is one with nothing to copy: the default\n * is prevented only once a copy ran. Like the grid's other keys, it is not\n * reported to `onCommand`, which hears of menu and API runs.\n */\nexport default function useGridCopy<Row>({\n controller,\n commands,\n nav,\n}: UseGridCopyOptions<Row>): (event: KeyboardEvent) => void {\n function run(commandId: string, target: GridCommandTarget): boolean {\n const command = commands.commands.get(commandId);\n return (\n command !== undefined && runCommand(command, commands.contextFor(target))\n );\n }\n\n /** The focused data cell as a command target, or `null` on a header or a group row. */\n function focusedCell(): GridCommandTarget | null {\n const { focus } = nav;\n if (focus.area === \"header\") {\n return null;\n }\n const { pageRows, columns } = controller.getView();\n const entry = pageRows[focus.rowIndex];\n const column = columns[focus.columnIndex];\n return entry?.kind !== \"data\" || column === undefined\n ? null\n : { area: \"cell\", rowId: entry.rowId, columnId: column.id };\n }\n\n return (event) => {\n if (!isCopyKey(event) || isNativeCopy(event.target)) {\n return;\n }\n const cell = focusedCell();\n if (\n run(\"copy.selection\", { area: \"grid\" }) ||\n (cell !== null && run(\"copy.cell\", cell))\n ) {\n event.preventDefault();\n }\n };\n}\n","import { useMemo } from \"react\";\nimport {\n createCommandContext,\n resolveCommands,\n runCommand,\n type GridCommand,\n type GridCommandContext,\n type GridCommandHost,\n type GridCommandSource,\n type GridCommandTarget,\n type GridMessages,\n type GridOptions,\n} from \"@gridkitjs/core\";\nimport useCopyToClipboard from \"../clipboard/useCopyToClipboard\";\nimport useSaveFile from \"../export/useSaveFile\";\nimport { printGrid } from \"../print/printApi\";\nimport type { ColumnResizeApi } from \"../useColumnResize\";\nimport type { DataGridController } from \"../useGridController\";\n\ninterface UseGridCommandsOptions<Row> {\n controller: DataGridController<Row>;\n /** The app's commands, over the built-ins. */\n commands: GridOptions<Row>[\"commands\"];\n onCommand: GridOptions<Row>[\"onCommand\"];\n /** The grid's messages, over the defaults — what every built-in label reads. */\n messages: GridMessages;\n announce: (text: string) => void;\n resize: ColumnResizeApi<Row>;\n /** Opens one of the grid's panels — see `useGridPanels`. */\n openPanel: GridCommandHost[\"openPanel\"];\n}\n\nexport interface GridCommandsApi<Row> {\n /** Every command the grid knows, by id. */\n commands: ReadonlyMap<string, GridCommand<Row>>;\n /** What a command needs that only the grid has: its DOM, its live region. */\n host: GridCommandHost;\n /** A command context for `target`, over the grid as it is now. */\n contextFor: (target: GridCommandTarget) => GridCommandContext<Row>;\n /** Tells `onCommand` that a command, or an inline menu item, ran. */\n report: (\n commandId: string,\n target: GridCommandTarget,\n source: GridCommandSource,\n ) => void;\n /**\n * Runs the command `commandId` on `target` when it is visible and enabled\n * there, reports it, and says whether it ran.\n */\n run: (\n commandId: string,\n target: GridCommandTarget,\n source: GridCommandSource,\n ) => boolean;\n}\n\n/**\n * The commands behind the grid's menus — the built-ins and the app's own —\n * and the context they run in. Which command shows, is enabled or does what\n * is `@gridkitjs/core`'s; the grid lends them what needs a DOM — sizing a\n * column to its content, as double-clicking its resize handle does,\n * opening its panels, downloading an export, writing the clipboard and\n * printing — and its live region.\n */\nexport default function useGridCommands<Row>({\n controller,\n commands: appCommands,\n onCommand,\n messages,\n announce,\n resize,\n openPanel,\n}: UseGridCommandsOptions<Row>): GridCommandsApi<Row> {\n const commands = useMemo(() => resolveCommands(appCommands), [appCommands]);\n const { saveFile, canSave } = useSaveFile({ messages, announce });\n const writeClipboard = useCopyToClipboard({ messages, announce });\n\n const host: GridCommandHost = {\n autoFitColumns: (columnIds) => {\n const { columns } = controller.getView();\n let fitted = 0;\n for (const columnId of columnIds) {\n const entry = columns.find((candidate) => candidate.id === columnId);\n if (entry !== undefined && resize.sizeToContent(entry)) {\n fitted += 1;\n }\n }\n // Each resize announced itself, and the live region keeps only the\n // last; one message for them all replaces it before anything is read.\n if (fitted > 1) {\n announce(messages.columnsAutoFitted(fitted));\n }\n },\n openPanel,\n announce,\n saveFile,\n canSave,\n writeClipboard,\n print: (document, options) => {\n printGrid(document, options).catch((error: unknown) => {\n console.error(\"DataGrid: the print failed.\", error);\n announce(messages.printFailed);\n });\n },\n };\n\n function contextFor(target: GridCommandTarget): GridCommandContext<Row> {\n return createCommandContext({ controller, target, messages, host });\n }\n\n function report(\n commandId: string,\n target: GridCommandTarget,\n source: GridCommandSource,\n ): void {\n onCommand?.({ commandId, target, source });\n }\n\n // A new object each render, as the other hooks here return.\n return {\n commands,\n host,\n contextFor,\n report,\n run: (commandId, target, source) => {\n const command = commands.get(commandId);\n if (command === undefined) {\n console.error(`DataGrid: there is no command \\`${commandId}\\` to run.`);\n return false;\n }\n if (!runCommand(command, contextFor(target))) {\n return false;\n }\n report(commandId, target, source);\n return true;\n },\n };\n}\n","import { useRef } from \"react\";\nimport type { GridCommandHost, GridMessages } from \"@gridkitjs/core\";\nimport { writeClipboard } from \"@gridkitjs/dom\";\n\ninterface UseCopyToClipboardOptions {\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/**\n * The host's `writeClipboard`: puts a copy on the clipboard and says so, as\n * nothing on screen does. A copy the browser refuses is logged for the\n * developer and announced for the user, who would otherwise paste whatever\n * the clipboard held before.\n *\n * Only the latest copy is announced. A write cannot be called off, so one\n * finishing after a later copy began says nothing, rather than telling the\n * user they hold what they copied before.\n */\nexport default function useCopyToClipboard({\n messages,\n announce,\n}: UseCopyToClipboardOptions): GridCommandHost[\"writeClipboard\"] {\n /** How many copies have begun: the number of the latest. */\n const copies = useRef(0);\n\n return (content) => {\n copies.current += 1;\n const copy = copies.current;\n function announceIfLatest(text: string): void {\n if (copy === copies.current) {\n announce(text);\n }\n }\n writeClipboard(content).then(\n () => {\n announceIfLatest(messages.copied(content.count, content.unit));\n },\n (error: unknown) => {\n console.error(\"DataGrid: the clipboard could not be written.\", error);\n announceIfLatest(messages.copyFailed);\n },\n );\n };\n}\n","import { useRef } from \"react\";\nimport type {\n ExportFile,\n GridCommandHost,\n GridMessages,\n} from \"@gridkitjs/core\";\nimport { downloadBlob } from \"@gridkitjs/dom\";\nimport { exportBlob } from \"./exportApi\";\n\ninterface UseSaveFileOptions {\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/** Whether a writer is still writing the last export asked for. */\ntype SaveState = { readonly kind: \"idle\" } | { readonly kind: \"writing\" };\n\nconst IDLE: SaveState = { kind: \"idle\" };\nconst WRITING: SaveState = { kind: \"writing\" };\n\n/**\n * The host's `saveFile`, which downloads an export once its writer has\n * finished writing it, and its `canSave`.\n *\n * One at a time. An export asked for while a writer is still writing the\n * last is dropped and logged, and the export command that asked for it did\n * not run, so pressing a slow export twice saves one file, and reports one\n * command, rather than two. The export command asks `canSave` before it\n * builds its file, so a dropped export never runs its writer. A writer that\n * fails, or a download the browser refuses, is logged for the developer and\n * announced for the user, who asked for a file that will not come.\n */\nexport default function useSaveFile({\n messages,\n announce,\n}: UseSaveFileOptions): Pick<GridCommandHost, \"saveFile\" | \"canSave\"> {\n const state = useRef<SaveState>(IDLE);\n\n /**\n * Whether a file asked for now would be saved. An export asks just before\n * it would build its file, so a refusal is that export dropped, and logged.\n */\n function canSave(): boolean {\n if (state.current.kind === \"writing\") {\n console.error(\n \"DataGrid: an export is still being written, so this one was dropped.\",\n );\n return false;\n }\n return true;\n }\n\n function fail(reason: string, error: unknown): void {\n console.error(`DataGrid: ${reason}`, error);\n announce(messages.exportFailed);\n }\n\n function download(file: ExportFile): void {\n try {\n downloadBlob(exportBlob(file), file.fileName);\n } catch (error) {\n fail(\"the export could not be saved.\", error);\n }\n }\n\n function saveFile(file: ExportFile | Promise<ExportFile>): boolean {\n if (!canSave()) {\n return false;\n }\n if (!(file instanceof Promise)) {\n download(file);\n return true;\n }\n state.current = WRITING;\n file\n .then(download, (error: unknown) => {\n fail(\"the export's writer failed.\", error);\n })\n .finally(() => {\n state.current = IDLE;\n });\n return true;\n }\n\n return { saveFile, canSave };\n}\n","import {\n exportFile,\n resolveExportWriters,\n type ExportFile,\n type ExportWriter,\n type GridExportOptions,\n} from \"@gridkitjs/core\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\n\n/** What `DataGridApi` carries for exporting. */\nexport interface GridExportApi {\n /**\n * The grid's view exported as `format` — `\"csv\"`, `\"json\"`, a format\n * registered through `exportWriters`, or a writer passed as it is — and\n * handed back as a `Blob`, under the grid's `export` option with\n * `options` over it, field by field. Nothing is downloaded:\n * `runCommand(\"export.csv\")` downloads.\n *\n * Rejects for a format no writer is registered for, and when the writer\n * fails.\n */\n exportData(\n format: string | ExportWriter,\n options?: GridExportOptions,\n ): Promise<Blob>;\n}\n\n/**\n * An export's contents as a `Blob` of its media type. Text is stored as\n * UTF-8, a byte order mark the writer put first included, so a CSV opens in\n * a spreadsheet with its accents intact. Bytes are copied: a `Blob` takes\n * no view of shared memory, which a `Uint8Array` may be.\n */\nexport function exportBlob({ content, mimeType }: ExportFile): Blob {\n const part = typeof content === \"string\" ? content : content.slice();\n return new Blob([part], { type: mimeType });\n}\n\n/** `DataGridApi.exportData`, over the grid as it is when called. */\nexport function exportApi<Row>({\n contextFor,\n}: GridCommandsApi<Row>): GridExportApi {\n return {\n exportData: async (format, options) => {\n const context = contextFor({ area: \"grid\" });\n const { export: defaults, exportWriters } = context.options;\n const file = exportFile(\n context,\n format,\n { ...defaults, ...options },\n resolveExportWriters(exportWriters),\n );\n // `exportFile` has logged the format by name; the caller is told too.\n if (file === null) {\n throw new Error(\n \"DataGrid: there is no export writer for that format — register one through `exportWriters`.\",\n );\n }\n return exportBlob(await file);\n },\n };\n}\n","import {\n exportPrintDocument,\n type PrintDocument,\n type PrintOptions,\n} from \"@gridkitjs/core\";\nimport { printDocument, printStyles } from \"@gridkitjs/dom\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\n\n/** What `DataGridApi` carries for printing. */\nexport interface GridPrintApi {\n /**\n * Prints the grid's view through the browser's print dialog — every row\n * the filter leaves, across pages and collapsed groups, not only those\n * drawn — under the grid's `print` option with `options` over it, field\n * by field. Resolves once the dialog has closed, or at once while another\n * print is open.\n */\n print(options?: PrintOptions): Promise<void>;\n}\n\n/**\n * Puts a print document on paper through a hidden frame, under the print\n * stylesheet for its page with `options.styles` after it. The frame sees\n * none of the page's CSS, the theme's included.\n */\nexport function printGrid(\n document: PrintDocument,\n { styles = \"\" }: PrintOptions,\n): Promise<void> {\n return printDocument({\n title: document.title,\n bodyHtml: document.bodyHtml,\n styles: printStyles(document.page) + styles,\n });\n}\n\n/** `DataGridApi.print`, over the grid as it is when called. */\nexport function printApi<Row>({\n contextFor,\n}: GridCommandsApi<Row>): GridPrintApi {\n return {\n print: (options) => {\n const context = contextFor({ area: \"grid\" });\n const merged = { ...context.options.print, ...options };\n return printGrid(exportPrintDocument(context, merged), merged);\n },\n };\n}\n","import { useLayoutEffect, useRef, useState, type RefObject } from \"react\";\nimport type {\n ResolvedMenuEntry,\n ResolvedMenuItem,\n ResolvedMenuSubmenu,\n} from \"@gridkitjs/core\";\nimport {\n attachMenu,\n type AttachedMenu,\n type MenuSubmenuFocus,\n} from \"@gridkitjs/dom\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport Overlay, { type OverlayScope } from \"../overlay/Overlay\";\nimport { CheckIcon, ChevronRightIcon, MenuIcon } from \"./menuIcons\";\n\ninterface GridMenuProps {\n entries: readonly ResolvedMenuEntry[];\n /** The menu's accessible name. */\n label: string;\n /** The palette and direction its submenus take — the ones its own overlay took. */\n scope: OverlayScope;\n /** An enabled item was chosen: run it, and close every menu. */\n onRun: (item: ResolvedMenuItem) => void;\n /** Tab or Shift+Tab: close every menu. */\n onClose: () => void;\n /**\n * ArrowLeft, or ArrowRight in a right-to-left menu: close this menu, which\n * is a submenu, so focus goes back to\n * the item that opened it. Given only to a submenu; a menu without it has\n * nowhere to go back to.\n */\n onCloseSubmenu?: (() => void) | undefined;\n /**\n * Holds this menu's behaviour while it is attached, for the menu that\n * opened it to move focus in.\n */\n behaviourRef?: RefObject<AttachedMenu | null> | undefined;\n}\n\n/** Whether a submenu is open from a menu, and which. */\ntype SubmenuState =\n | { readonly kind: \"closed\" }\n | {\n readonly kind: \"open\";\n readonly id: string;\n /** The item it opened from, which it opens beside. */\n readonly anchor: HTMLElement;\n readonly focus: MenuSubmenuFocus;\n /** Lines its first item up with `anchor`. */\n readonly offset: number;\n }\n /**\n * Closed because its entry left the menu. The overlay hands focus back to\n * the entry's item as it detaches, before the same commit removes that\n * item, so focus that was in the submenu is left on the page's body.\n */\n | { readonly kind: \"entryGone\" };\n\nconst CLOSED: SubmenuState = { kind: \"closed\" };\nconst ENTRY_GONE: SubmenuState = { kind: \"entryGone\" };\n\n/** The item of `menu` whose id is `id`, read off the markup this drew. */\nfunction itemElement(menu: HTMLElement, id: string): HTMLElement | null {\n return (\n Array.from(\n menu.querySelectorAll<HTMLElement>(\"[data-gridkit-menu-item]\"),\n ).find((item) => item.getAttribute(\"data-gridkit-menu-item\") === id) ?? null\n );\n}\n\n/**\n * How far below a menu's top edge its first item starts: its top border and\n * padding. A submenu is styled the same, so opening it this far up lines its\n * first item up with the item that opened it, whatever the theme makes them.\n */\nfunction topInset(menu: HTMLElement): number {\n const style = getComputedStyle(menu);\n return parseFloat(style.borderTopWidth) + parseFloat(style.paddingTop);\n}\n\nfunction MenuItem({\n entry,\n expanded,\n}: {\n entry: ResolvedMenuItem | ResolvedMenuSubmenu;\n /** For a submenu item: whether its submenu is open. */\n expanded: boolean;\n}) {\n const isItem = entry.type === \"item\";\n const checked = isItem ? entry.checked : undefined;\n const shortcut = isItem ? entry.shortcut : undefined;\n return (\n <div\n role={checked === undefined ? \"menuitem\" : \"menuitemcheckbox\"}\n data-gridkit-menu-item={entry.id}\n className=\"gridkit-menu-item\"\n {...ariaAttr(isItem && entry.disabled, \"aria-disabled\", true)}\n {...ariaAttr(checked !== undefined, \"aria-checked\", checked)}\n {...ariaAttr(shortcut !== undefined, \"aria-keyshortcuts\", shortcut)}\n {...ariaAttr<\"aria-haspopup\", \"menu\">(!isItem, \"aria-haspopup\", \"menu\")}\n {...ariaAttr(!isItem, \"aria-expanded\", expanded)}\n >\n <span className=\"gridkit-menu-item-icon\" aria-hidden=\"true\">\n {checked === true ? <CheckIcon /> : <MenuIcon name={entry.icon} />}\n </span>\n <span className=\"gridkit-menu-item-label\">{entry.label}</span>\n {/* Read out through `aria-keyshortcuts`, not as part of the name. */}\n {shortcut !== undefined && (\n <span className=\"gridkit-menu-item-shortcut\" aria-hidden=\"true\">\n {shortcut}\n </span>\n )}\n {!isItem && (\n <span className=\"gridkit-menu-submenu-indicator\" aria-hidden=\"true\">\n <ChevronRightIcon />\n </span>\n )}\n </div>\n );\n}\n\n/**\n * A menu resolved by `@gridkitjs/core`'s `resolveMenu`, drawn as\n * `role=\"menu\"` and made to behave as one by `@gridkitjs/dom`'s\n * `attachMenu`, which decides what every key and hover does; this draws the\n * items and which submenu is open. Shown inside an `Overlay` — which attaches\n * after this, so its initial focus lands on the item `attachMenu` made the\n * tab stop.\n *\n * A submenu is a `GridMenu` of its own, in an `Overlay` of its own anchored\n * to the item that opened it.\n */\nexport default function GridMenu({\n entries,\n label,\n scope,\n onRun,\n onClose,\n onCloseSubmenu,\n behaviourRef,\n}: GridMenuProps) {\n const menuRef = useRef<HTMLDivElement>(null);\n const submenuBehaviourRef = useRef<AttachedMenu | null>(null);\n const [submenu, setSubmenu] = useState<SubmenuState>(CLOSED);\n const isSubmenu = onCloseSubmenu !== undefined;\n\n /**\n * What the behaviour's callbacks read. They are handed over once, when it\n * attaches, so they read the props and state of the latest render here.\n */\n const latest = useRef({ entries, submenu, onRun, onClose, onCloseSubmenu });\n useLayoutEffect(() => {\n latest.current = { entries, submenu, onRun, onClose, onCloseSubmenu };\n });\n\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (menu === null) {\n return undefined;\n }\n const behaviour = attachMenu(menu, {\n onActivate: (id) => {\n const item = latest.current.entries.find(\n (entry): entry is ResolvedMenuItem =>\n entry.type === \"item\" && entry.id === id,\n );\n if (item !== undefined) {\n latest.current.onRun(item);\n }\n },\n onOpenSubmenu: (id, { focus }) => {\n // Already open — the pointer opened it — so the keyboard only asks\n // for focus to move into it.\n const open = latest.current.submenu;\n if (open.kind === \"open\" && open.id === id) {\n if (focus === \"first\") {\n submenuBehaviourRef.current?.focusItem(0);\n }\n return;\n }\n const anchor = itemElement(menu, id);\n if (anchor !== null) {\n setSubmenu({\n kind: \"open\",\n id,\n anchor,\n focus,\n offset: -topInset(menu),\n });\n }\n },\n onCollapseSubmenu: () => {\n setSubmenu(CLOSED);\n },\n onCloseSubmenu: isSubmenu\n ? () => {\n latest.current.onCloseSubmenu?.();\n }\n : undefined,\n onClose: () => {\n latest.current.onClose();\n },\n });\n if (behaviourRef !== undefined) {\n behaviourRef.current = behaviour;\n }\n return () => {\n if (behaviourRef !== undefined) {\n behaviourRef.current = null;\n }\n behaviour.detach();\n };\n }, [isSubmenu, behaviourRef]);\n\n // Focus left on the body by a submenu whose entry went comes back to this\n // menu: its tab stop, or its first item once the tab stop was that entry.\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (\n submenu.kind !== \"entryGone\" ||\n menu === null ||\n document.activeElement !== document.body\n ) {\n return;\n }\n const item =\n menu.querySelector<HTMLElement>(\n '[data-gridkit-menu-item][tabindex=\"0\"]',\n ) ?? menu.querySelector<HTMLElement>(\"[data-gridkit-menu-item]\");\n item?.focus();\n }, [submenu]);\n\n function closeSubmenu(): void {\n setSubmenu(CLOSED);\n }\n\n const openEntry =\n submenu.kind === \"open\"\n ? entries.find(\n (entry): entry is ResolvedMenuSubmenu =>\n entry.type === \"submenu\" && entry.id === submenu.id,\n )\n : undefined;\n // Its entry has gone from `entries`: the submenu closes for good, rather\n // than coming back open with the entry.\n if (submenu.kind === \"open\" && openEntry === undefined) {\n setSubmenu(ENTRY_GONE);\n }\n\n return (\n <>\n <div\n ref={menuRef}\n role=\"menu\"\n aria-label={label}\n className=\"gridkit-menu\"\n >\n {entries.map((entry) =>\n entry.type === \"separator\" ? (\n <div\n key={entry.key}\n role=\"separator\"\n className=\"gridkit-menu-separator\"\n />\n ) : (\n <MenuItem\n key={entry.id}\n entry={entry}\n expanded={submenu.kind === \"open\" && entry.id === submenu.id}\n />\n ),\n )}\n </div>\n {submenu.kind === \"open\" && openEntry !== undefined && (\n <Overlay\n key={submenu.id}\n anchor={submenu.anchor}\n placement=\"right-start\"\n offset={submenu.offset}\n initialFocus={submenu.focus}\n scope={scope}\n onDismiss={closeSubmenu}\n >\n <GridMenu\n entries={openEntry.items}\n label={openEntry.label}\n scope={scope}\n onRun={onRun}\n onClose={onClose}\n onCloseSubmenu={closeSubmenu}\n behaviourRef={submenuBehaviourRef}\n />\n </Overlay>\n )}\n </>\n );\n}\n","import { useLayoutEffect, useRef, type ReactNode, type RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport type { WritingDirection } from \"@gridkitjs/core/renderer\";\nimport {\n attachOverlay,\n writingDirection,\n type OverlayAnchor,\n type OverlayDismissReason,\n type OverlayInitialFocus,\n type OverlayPlacement,\n} from \"@gridkitjs/dom\";\nimport { classNames } from \"../classNames\";\n\n/**\n * What an overlay copies from the element it opens from, rendering into\n * `document.body` out of reach of what that element inherits: the palette\n * class (`gridkit-light`, `gridkit-dark` or none, to follow the page) and\n * the writing direction, which lays out its content and places it.\n */\nexport interface OverlayScope {\n readonly themeClassName: string;\n readonly direction: WritingDirection;\n}\n\ninterface OverlayProps {\n /**\n * What the overlay opens beside: an element, or a point. It and the\n * options after it are read when the overlay attaches, and a change to any\n * of them attaches it afresh — moving focus back in — so each should stay\n * the same for as long as the overlay is open.\n */\n anchor: OverlayAnchor;\n placement?: OverlayPlacement | undefined;\n gap?: number | undefined;\n offset?: number | undefined;\n /**\n * Where focus goes on attaching — see `attachOverlay`'s option — or a ref\n * to the control it goes to, read as the overlay attaches, once its\n * children have mounted, so that it can be one of theirs. A ref holding\n * nothing sends it to the first control.\n */\n initialFocus?:\n OverlayInitialFocus | RefObject<HTMLElement | null> | undefined;\n returnFocusTo?: HTMLElement | null | undefined;\n /**\n * See `attachOverlay`'s option: where focus goes once `returnFocusTo` has\n * left the page. Read as the overlay detaches, so it need not stay the same.\n */\n returnFocusFallback?: (() => HTMLElement | null) | undefined;\n /** See `attachOverlay`'s option: a panel whose controls change the grid under it. */\n ignoreScrollAfterInput?: boolean | undefined;\n /** See `attachOverlay`'s option: Tab stays inside, as in a dialog. */\n trapFocus?: boolean | undefined;\n /** The palette and direction the overlay takes — see `overlayScope`. */\n scope: OverlayScope;\n /** The overlay asks to close; the caller unmounts it, or not. */\n onDismiss: (reason: OverlayDismissReason) => void;\n children: ReactNode;\n}\n\n/**\n * The space between a menu or panel and the element it opens below — a\n * toolbar button, a header — so its shadow does not run into that element's\n * border. Nothing opened at a point, or beside its own menu, as a submenu is,\n * takes it.\n */\nexport const ANCHOR_GAP = 4;\n\n/** `focus` as `attachOverlay` takes it, reading a ref's control now. */\nfunction attachedFocus(\n focus: OverlayProps[\"initialFocus\"],\n): OverlayInitialFocus | undefined {\n return typeof focus === \"object\" && !(focus instanceof HTMLElement)\n ? (focus.current ?? \"first\")\n : focus;\n}\n\n/**\n * The palette class an overlay opened from `element` copies:\n * `gridkit-light` or `gridkit-dark`, from the nearest ancestor carrying one,\n * or none to follow the page.\n */\nfunction themeClassNameOf(element: Element | null): string {\n const scope = element?.closest(\".gridkit-light, .gridkit-dark\");\n if (scope === null || scope === undefined) {\n return \"\";\n }\n return scope.classList.contains(\"gridkit-dark\")\n ? \"gridkit-dark\"\n : \"gridkit-light\";\n}\n\n/**\n * The scope an overlay opened from `element` takes, read as it opens. With\n * no element, it follows the page.\n */\nexport function overlayScope(element: Element | null): OverlayScope {\n return {\n themeClassName: themeClassNameOf(element),\n direction: writingDirection(element ?? document.documentElement),\n };\n}\n\n/**\n * `children` in a panel portalled into `document.body` — where no scrolling\n * ancestor of the grid clips it — shown beside `anchor` by\n * `@gridkitjs/dom`'s `attachOverlay` for as long as it is mounted.\n *\n * Attached in a layout effect, which React runs after its children's: a menu\n * inside attaches its own behaviour first, so the overlay's initial focus\n * finds the item that behaviour made the tab stop. A nested overlay — a\n * submenu — mounts on a later user action than the one it opens from, so it\n * attaches after it and sits above it in the overlay stack.\n */\nexport default function Overlay({\n anchor,\n placement,\n gap,\n offset,\n initialFocus,\n returnFocusTo,\n returnFocusFallback,\n ignoreScrollAfterInput,\n trapFocus,\n scope,\n onDismiss,\n children,\n}: OverlayProps) {\n const panelRef = useRef<HTMLDivElement>(null);\n // Read through refs, so new functions every render do not re-attach.\n const onDismissRef = useRef(onDismiss);\n const returnFocusFallbackRef = useRef(returnFocusFallback);\n useLayoutEffect(() => {\n onDismissRef.current = onDismiss;\n returnFocusFallbackRef.current = returnFocusFallback;\n });\n\n useLayoutEffect(() => {\n const panel = panelRef.current;\n if (panel === null) {\n return undefined;\n }\n return attachOverlay(anchor, panel, {\n placement,\n gap,\n offset,\n initialFocus: attachedFocus(initialFocus),\n returnFocusTo,\n returnFocusFallback: () => returnFocusFallbackRef.current?.() ?? null,\n ignoreScrollAfterInput,\n trapFocus,\n onDismiss: (reason) => {\n onDismissRef.current(reason);\n },\n });\n }, [\n anchor,\n placement,\n gap,\n offset,\n initialFocus,\n returnFocusTo,\n ignoreScrollAfterInput,\n trapFocus,\n ]);\n\n return createPortal(\n <div\n ref={panelRef}\n className={classNames(\"gridkit-overlay\", scope.themeClassName)}\n dir={scope.direction}\n >\n {children}\n </div>,\n document.body,\n );\n}\n","import type { ReactNode } from \"react\";\nimport type { BuiltInCommandIcon } from \"@gridkitjs/core\";\nimport { GroupIcon, Icon } from \"../icons\";\n\n/** A glyph for every icon key the built-in commands carry. */\nconst BUILT_IN_ICONS: Readonly<Record<BuiltInCommandIcon, () => ReactNode>> = {\n sortAscending: () => (\n <Icon>\n <path d=\"m3 8 4-4 4 4\" />\n <path d=\"M7 4v16\" />\n <path d=\"M11 12h4\" />\n <path d=\"M11 16h7\" />\n <path d=\"M11 20h10\" />\n </Icon>\n ),\n sortDescending: () => (\n <Icon>\n <path d=\"m3 16 4 4 4-4\" />\n <path d=\"M7 20V4\" />\n <path d=\"M11 4h10\" />\n <path d=\"M11 8h7\" />\n <path d=\"M11 12h4\" />\n </Icon>\n ),\n group: () => <GroupIcon />,\n hide: () => (\n <Icon>\n <path d=\"M9.88 9.88a3 3 0 1 0 4.24 4.24\" />\n <path d=\"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68\" />\n <path d=\"M6.61 6.61A13.53 13.53 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61\" />\n <path d=\"m2 2 20 20\" />\n </Icon>\n ),\n autoFit: () => (\n <Icon>\n <path d=\"m18 8 4 4-4 4\" />\n <path d=\"M2 12h20\" />\n <path d=\"m6 8-4 4 4 4\" />\n </Icon>\n ),\n copy: () => (\n <Icon>\n <rect x=\"8\" y=\"8\" width=\"14\" height=\"14\" rx=\"2\" />\n <path d=\"M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2\" />\n </Icon>\n ),\n print: () => (\n <Icon>\n <path d=\"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2\" />\n <path d=\"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6\" />\n <rect x=\"6\" y=\"14\" width=\"12\" height=\"8\" rx=\"1\" />\n </Icon>\n ),\n};\n\n/**\n * Looked up through a `Map`, since an item's key may be any string an app\n * chose, and one such as `\"toString\"` must find nothing rather than\n * something on `Object.prototype`.\n */\nconst ICONS = new Map(Object.entries(BUILT_IN_ICONS));\n\n/** The icon a key names, or nothing for a key the grid has no glyph for. */\nexport function MenuIcon({ name }: { name: string | undefined }) {\n const draw = name === undefined ? undefined : ICONS.get(name);\n return draw === undefined ? null : draw();\n}\n\n/** What a checked item shows in place of its icon. */\nexport function CheckIcon() {\n return (\n <Icon>\n <path d=\"M20 6 9 17l-5-5\" />\n </Icon>\n );\n}\n\n/** Marks a button that opens a menu below it. */\nexport function ChevronDownIcon() {\n return (\n <Icon>\n <path d=\"m6 9 6 6 6-6\" />\n </Icon>\n );\n}\n\n/** Marks a button going back to what a panel showed before. */\nexport function ChevronLeftIcon() {\n return (\n <Icon>\n <path d=\"m15 18-6-6 6-6\" />\n </Icon>\n );\n}\n\n/** Marks an item that opens a submenu. */\nexport function ChevronRightIcon() {\n return (\n <Icon>\n <path d=\"m9 18 6-6-6-6\" />\n </Icon>\n );\n}\n","import GridMenu from \"../menu/GridMenu\";\nimport Overlay, { ANCHOR_GAP } from \"../overlay/Overlay\";\nimport type { ContextMenuApi } from \"./useContextMenu\";\n\n/**\n * The open context menu, if any — beside the point it was asked for at, or\n * below its cell when asked for by a key — returning focus to that cell when\n * it closes, or, from the body's empty space, to wherever focus was before.\n * Rendered after the grid's tables, as every grid overlay is, so\n * the keys pressed in it reach no header or body handler on their way up\n * React's tree.\n */\nexport default function GridContextMenu({\n contextMenu,\n}: {\n contextMenu: ContextMenuApi;\n}) {\n const { menu, returnFocusFallback, run, close } = contextMenu;\n if (menu === null) {\n return null;\n }\n return (\n <Overlay\n key={menu.key}\n anchor={menu.anchor}\n gap={menu.anchor instanceof Element ? ANCHOR_GAP : 0}\n returnFocusTo={menu.cell ?? undefined}\n returnFocusFallback={returnFocusFallback}\n scope={menu.scope}\n onDismiss={close}\n >\n <GridMenu\n entries={menu.entries}\n label={menu.label}\n scope={menu.scope}\n onRun={run}\n onClose={close}\n />\n </Overlay>\n );\n}\n","import {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n type RefObject,\n} from \"react\";\nimport {\n contextMenuEntries,\n isSameCell,\n resolveMenu,\n type CellSelectionState,\n type GridContextMenuArea,\n type GridContextMenuTarget,\n type GridMessages,\n type GridOptions,\n type ResolvedMenuEntry,\n type ResolvedMenuItem,\n} from \"@gridkitjs/core\";\nimport { hasContextMenu, pinnedWidths } from \"@gridkitjs/core/renderer\";\nimport {\n attachContextMenuTrigger,\n type ContextMenuRequest,\n type OverlayAnchor,\n} from \"@gridkitjs/dom\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport { overlayScope, type OverlayScope } from \"../overlay/Overlay\";\nimport type { GridOverlayApi } from \"../overlay/useGridOverlay\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\nimport type { GridSelectionApi } from \"../useGridSelection\";\nimport {\n placeAt,\n placeOf,\n type ContextMenuPlace,\n type GridParts,\n} from \"./contextMenuPlaces\";\n\ninterface UseContextMenuOptions<Row> {\n /** The grid's root element: a menu is asked for on what is inside it. */\n rootRef: RefObject<HTMLElement | null>;\n /** The tables' scroll area, which a cell is seen through. */\n scrollRef: RefObject<HTMLElement | null>;\n headerTableRef: RefObject<HTMLTableElement | null>;\n bodyTableRef: RefObject<HTMLTableElement | null>;\n /** The body's rowgroup, whose empty space is the `body` area. */\n bodyRef: RefObject<HTMLElement | null>;\n footerTableRef: RefObject<HTMLTableElement | null>;\n contextMenu: GridOptions<Row>[\"contextMenu\"];\n /** The grid's one open overlay, the menu among them. */\n overlay: GridOverlayApi;\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n messages: GridMessages;\n /** What a column is called in a menu's name. */\n columnName: (columnId: string) => string;\n}\n\n/** The context menu open now. */\nexport interface OpenContextMenu {\n /** Counts the openings, so one opened over another replaces it. */\n readonly key: number;\n readonly target: GridContextMenuTarget;\n readonly entries: readonly ResolvedMenuEntry[];\n /** Its accessible name. */\n readonly label: string;\n /** The point it was asked for at, or its cell when asked for by a key. */\n readonly anchor: OverlayAnchor;\n /**\n * The cell it opened on, which has focus first and gets it back after —\n * `null` in the body's empty space, which leaves focus where it was.\n */\n readonly cell: HTMLElement | null;\n readonly scope: OverlayScope;\n}\n\nexport interface ContextMenuApi {\n menu: OpenContextMenu | null;\n /** Whether `area` opens a menu — for the `aria-keyshortcuts` of its cells. */\n opens: (area: GridContextMenuArea) => boolean;\n /**\n * Opens the menu `target` has, as a right-click there would, beside\n * `anchor` or below its cell, and says whether it did: not for a target\n * that is not on screen, or whose menu is empty.\n */\n open: (target: GridContextMenuTarget, anchor?: OverlayAnchor) => boolean;\n /** See `GridOverlayApi`. */\n returnFocusFallback: () => HTMLElement | null;\n /** Runs the item the user chose, reporting it if it ran, then closes the menu. */\n run: (item: ResolvedMenuItem) => void;\n close: () => void;\n}\n\n/**\n * The grid's context menu. `@gridkitjs/dom`'s trigger reports a right-click,\n * Shift+F10 or the ContextMenu key inside the grid, and the ref can ask for\n * one too; the `contextMenu` option and `@gridkitjs/core`'s `resolveMenu`\n * say what menu that place has; this opens it as the grid's one overlay\n * (see `useGridOverlay`, which tells `onContextMenuOpenChange`) and does\n * what opening it means in the grid.\n *\n * Opening one on a column, row or cell that is not selected selects it\n * first, where that kind is selectable, as a click on it would — opening one\n * inside the selection keeps it, so a menu can act on everything selected.\n * Focus moves to the cell first, so closing the menu returns it there. A\n * place whose menu resolves to nothing shows the browser's own.\n */\nexport default function useContextMenu<Row>({\n rootRef,\n scrollRef,\n headerTableRef,\n bodyTableRef,\n bodyRef,\n footerTableRef,\n contextMenu,\n overlay,\n controller,\n commands,\n nav,\n selection,\n messages,\n columnName,\n}: UseContextMenuOptions<Row>): ContextMenuApi {\n const { drawn, close: closeOverlay } = overlay;\n const openings = useRef(0);\n const enabled = contextMenu !== undefined && contextMenu !== false;\n\n function parts(): GridParts<Row> {\n const { columns, pageRows } = controller.getView();\n return {\n scroller: scrollRef.current,\n headerTable: headerTableRef.current,\n bodyTable: bodyTableRef.current,\n body: bodyRef.current,\n footerTable: footerTableRef.current,\n columns,\n pinnedWidths: pinnedWidths(columns),\n pageRows,\n };\n }\n\n function labelOf(target: GridContextMenuTarget): string {\n switch (target.area) {\n case \"header\":\n return messages.headerMenuLabel(columnName(target.columnId));\n case \"cell\":\n return messages.cellMenuLabel;\n case \"group\":\n return messages.groupMenuLabel;\n case \"body\":\n return messages.bodyMenuLabel;\n }\n }\n\n /**\n * Selects what the menu opens on unless it is selected already, and says\n * whether it did. Each kind follows its own `selectable` mode, as a click\n * does — a cell's row and the cell itself apart — and a kind a user cannot\n * select is left alone.\n */\n function selectTarget(target: GridContextMenuTarget): boolean {\n const state = controller.getState();\n if (target.area === \"header\") {\n if (\n selection.columnMode === false ||\n state.columnSelection.includes(target.columnId)\n ) {\n return false;\n }\n controller.selectColumn(target.columnId, \"replace\");\n return true;\n }\n if (target.area !== \"cell\") {\n return false;\n }\n const cell = {\n kind: \"cell\",\n rowId: target.rowId,\n columnId: target.columnId,\n } satisfies CellSelectionState;\n const selectRow =\n selection.rowMode !== false && !state.rowSelection.includes(target.rowId);\n const selectCell =\n selection.cellMode !== false && !isSameCell(state.cellSelection, cell);\n if (selectRow) {\n controller.selectRow(target.rowId, \"replace\");\n }\n if (selectCell) {\n controller.selectCell(cell, \"replace\");\n }\n return selectRow || selectCell;\n }\n\n /** The menu `target` has, over the grid as it is now. */\n function resolveFor(\n target: GridContextMenuTarget,\n ): readonly ResolvedMenuEntry[] {\n const context = commands.contextFor(target);\n return resolveMenu(contextMenuEntries(contextMenu, context), {\n commands: commands.commands,\n context,\n });\n }\n\n function openAt(\n { target, cell, anchor }: ContextMenuPlace,\n point: OverlayAnchor | null,\n ): boolean {\n let resolved = resolveFor(target);\n if (resolved.length === 0) {\n return false;\n }\n // Resolved again against the selection the menu now acts on.\n if (selectTarget(target)) {\n resolved = resolveFor(target);\n }\n if (cell !== null && document.activeElement !== cell.element) {\n // Focused without scrolling first: a scroll would close the menu about\n // to open beside it. Moving the tab stop after it then finds the cell\n // focused already.\n cell.element.focus({ preventScroll: true });\n nav.focusCellNow(cell.focus);\n }\n openings.current += 1;\n overlay.open({\n kind: \"contextMenu\",\n menu: {\n key: openings.current,\n target,\n entries: resolved,\n label: labelOf(target),\n anchor: point ?? anchor,\n cell: cell?.element ?? null,\n scope: overlayScope(rootRef.current),\n },\n });\n return true;\n }\n\n function handleRequest({ target, point }: ContextMenuRequest): boolean {\n const place = placeAt(target, parts());\n return place !== null && openAt(place, point);\n }\n\n // The trigger is attached once, and hears every request through this.\n const latestRequest = useRef(handleRequest);\n useLayoutEffect(() => {\n latestRequest.current = handleRequest;\n });\n\n useEffect(() => {\n const root = rootRef.current;\n if (!enabled || root === null) {\n return undefined;\n }\n return attachContextMenuTrigger(root, {\n onRequest: (request) => latestRequest.current(request),\n });\n }, [rootRef, enabled]);\n\n const close = useCallback(() => {\n closeOverlay(\"contextMenu\");\n }, [closeOverlay]);\n\n // A menu open as `contextMenu` turns off, or as the grid unmounts, closes\n // with it.\n useEffect(() => (enabled ? close : undefined), [enabled, close]);\n\n return {\n menu: drawn.kind === \"contextMenu\" ? drawn.menu : null,\n opens: (area) => hasContextMenu(contextMenu, area),\n open: (target, anchor) => {\n const place = placeOf(target, parts());\n return place !== null && openAt(place, anchor ?? null);\n },\n returnFocusFallback: overlay.returnFocusFallback,\n run: (item) => {\n const open = overlay.current();\n if (item.run() && open.kind === \"contextMenu\") {\n commands.report(item.id, open.menu.target, \"contextMenu\");\n }\n // A panel the item opened has replaced the menu already, and stays.\n close();\n },\n close,\n };\n}\n","import {\n bodyFocus,\n headerFocus,\n type DisplayRow,\n type GridContextMenuTarget,\n type GridFocus,\n} from \"@gridkitjs/core\";\nimport {\n bodyCellFrom,\n bodyRowFrom,\n findBodyRow,\n groupRowFrom,\n writingDirection,\n type OverlayAnchor,\n} from \"@gridkitjs/dom\";\n\n/** The cell a menu opens on, with its place in the grid's focus. */\nexport interface TargetCell {\n readonly element: HTMLTableCellElement;\n readonly focus: GridFocus;\n}\n\n/** Where a context menu opens: its target, and what it is drawn on. */\nexport interface ContextMenuPlace {\n readonly target: GridContextMenuTarget;\n /** The cell that has focus while it is open; `null` in the body's empty space. */\n readonly cell: TargetCell | null;\n /**\n * What it goes beside when asked for without a point: the cell — or, for a\n * cell scrolled out of the grid's view, the nearest point on that view's\n * edge — or the body's corner.\n */\n readonly anchor: OverlayAnchor;\n}\n\n/** The parts of the grid, as drawn now, that a place is found among. */\nexport interface GridParts<Row> {\n /** The tables' scroll area, which scrolls the rows both ways. */\n readonly scroller: HTMLElement | null;\n /** Sticks to the scroll area's top, over the rows scrolled under it. */\n readonly headerTable: HTMLTableElement | null;\n readonly bodyTable: HTMLTableElement | null;\n /** The body's rowgroup, whose empty space is the `body` area. */\n readonly body: HTMLElement | null;\n /** Sticks to the scroll area's bottom, over the rows scrolled under it. */\n readonly footerTable: HTMLTableElement | null;\n /** The columns shown, in order — what a cell's column index counts. */\n readonly columns: readonly { readonly id: string }[];\n /** How much of the view's width the pinned columns cover at each edge. */\n readonly pinnedWidths: { readonly start: number; readonly end: number };\n /** The rows of the page, as `data-gridkit-row-index` counts them. */\n readonly pageRows: readonly DisplayRow<Row>[];\n}\n\nfunction headerCell(\n parts: GridParts<unknown>,\n columnIndex: number,\n): TargetCell | null {\n const element = parts.headerTable?.tHead?.rows[0]?.cells[columnIndex];\n return element === undefined\n ? null\n : { element, focus: headerFocus(columnIndex) };\n}\n\nfunction bodyCell(\n parts: GridParts<unknown>,\n rowIndex: number,\n columnIndex: number,\n): TargetCell | null {\n const element = findBodyRow(parts.bodyTable, rowIndex)?.cells[columnIndex];\n return element === undefined\n ? null\n : { element, focus: bodyFocus(rowIndex, columnIndex) };\n}\n\n/**\n * Whether `element` is a cell that pinned columns can cover: one that\n * scrolls sideways in a grid with columns pinned.\n */\nfunction underPinnedColumns(\n element: Element,\n parts: GridParts<unknown>,\n): boolean {\n return (\n parts.pinnedWidths.start + parts.pinnedWidths.end > 0 &&\n element instanceof HTMLTableCellElement &&\n !element.matches(\".is-pinned-start, .is-pinned-end\")\n );\n}\n\n/**\n * The part of the viewport where `element` can be seen: its grid's scrolled\n * view; for a body cell only the part of it between the header and the\n * footer, and for a cell pinned columns can cover only the part of the\n * scrollport between them.\n */\nfunction viewOf(element: Element, parts: GridParts<unknown>): DOMRect | null {\n const { scroller } = parts;\n if (scroller === null) {\n return null;\n }\n const view = scroller.getBoundingClientRect();\n let { top, bottom, left, right } = view;\n if (parts.body?.contains(element) === true) {\n top = Math.max(\n top,\n parts.headerTable?.getBoundingClientRect().bottom ?? top,\n );\n bottom = Math.min(\n bottom,\n parts.footerTable?.getBoundingClientRect().top ?? bottom,\n );\n }\n if (underPinnedColumns(element, parts)) {\n // Pinned cells stick to the scrollport's edges, inside the scrollbar.\n const { start, end } = parts.pinnedWidths;\n const rtl = writingDirection(element) === \"rtl\";\n const portLeft = view.left + scroller.clientLeft;\n left = portLeft + (rtl ? end : start);\n right = portLeft + scroller.clientWidth - (rtl ? start : end);\n }\n return new DOMRect(\n left,\n top,\n Math.max(0, right - left),\n Math.max(0, bottom - top),\n );\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\n/** The x of `box`'s edge where `element`'s lines start: its left, or its right under `dir=\"rtl\"`. */\nfunction inlineStartOf(element: Element, box: DOMRect): number {\n return writingDirection(element) === \"rtl\" ? box.right : box.left;\n}\n\n/**\n * A cell's place, anchored to the cell itself while any of it is in the\n * grid's view (a group row's cell can be wider than the view). One scrolled\n * wholly out of it — the ref can ask for any cell drawn — is\n * anchored to the point of the view nearest its bottom corner at the inline\n * start (the left one, or the right under `dir=\"rtl\"`) instead, so the menu\n * opens at the grid's edge rather than off in the page, over whatever the\n * grid's scrolling hides it under.\n */\nfunction onCell(\n target: GridContextMenuTarget,\n cell: TargetCell | null,\n parts: GridParts<unknown>,\n): ContextMenuPlace | null {\n if (cell === null) {\n return null;\n }\n const box = cell.element.getBoundingClientRect();\n const view = viewOf(cell.element, parts);\n if (\n view === null ||\n (box.right > view.left &&\n box.left < view.right &&\n box.bottom > view.top &&\n box.top < view.bottom)\n ) {\n return { target, cell, anchor: cell.element };\n }\n return {\n target,\n cell,\n anchor: {\n x: clamp(inlineStartOf(cell.element, box), view.left, view.right),\n y: clamp(box.bottom, view.top, view.bottom),\n },\n };\n}\n\n/**\n * The body's empty space, anchored to the top corner of the part of it in\n * view, at the inline start.\n */\nfunction onBody(\n body: HTMLElement,\n parts: GridParts<unknown>,\n): ContextMenuPlace {\n const box = body.getBoundingClientRect();\n const view = viewOf(body, parts) ?? box;\n return {\n target: { area: \"body\" },\n cell: null,\n anchor: {\n x: inlineStartOf(body, view),\n y: clamp(box.top, view.top, view.bottom),\n },\n };\n}\n\nfunction headerPlaceAt<Row>(\n element: Element,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n const cell = element.closest<HTMLTableCellElement>(\"th[data-gridkit-column]\");\n const columnId = cell?.getAttribute(\"data-gridkit-column\");\n if (\n cell === null ||\n cell.parentElement !== parts.headerTable?.tHead?.rows[0] ||\n columnId === null ||\n columnId === undefined\n ) {\n return null;\n }\n return onCell(\n { area: \"header\", columnId },\n headerCell(parts, cell.cellIndex),\n parts,\n );\n}\n\n/**\n * A data cell or a group row of the body, read off the rows of the page, or\n * the body's empty space. A cell must be the one `element` is in, not one of\n * a table some cell template holds, which has rows of its own. A group's\n * summary row, with nothing of its own to act on, has no place.\n */\nfunction bodyPlaceAt<Row>(\n element: Element,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n const { body, pageRows } = parts;\n if (body === null || !body.contains(element)) {\n return null;\n }\n const group = groupRowFrom(element);\n if (group !== null) {\n const entry = pageRows[group.rowIndex];\n const cell = bodyCell(parts, group.rowIndex, 0);\n return entry !== undefined &&\n entry.kind === \"group\" &&\n cell?.element.contains(element) === true\n ? onCell(\n { area: \"group\", groupId: entry.groupId, columnId: entry.columnId },\n cell,\n parts,\n )\n : null;\n }\n const position = bodyCellFrom(element);\n if (position !== null) {\n const entry = pageRows[position.rowIndex];\n const cell = bodyCell(parts, position.rowIndex, position.columnIndex);\n return entry !== undefined &&\n entry.kind === \"data\" &&\n cell?.element.contains(element) === true\n ? onCell(\n { area: \"cell\", rowId: entry.rowId, columnId: position.columnId },\n cell,\n parts,\n )\n : null;\n }\n return bodyRowFrom(element) === null ? onBody(body, parts) : null;\n}\n\n/**\n * The place `element` is in — a header, a data cell, a group row or the\n * body's empty space — or `null` for anything else in the grid: the footer,\n * the pager, the group-by bar.\n */\nexport function placeAt<Row>(\n element: Element,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n return headerPlaceAt(element, parts) ?? bodyPlaceAt(element, parts);\n}\n\n/**\n * The place `target` names, among what is drawn now — `null` for a column,\n * row or group not on screen: hidden, on another page, in a collapsed group\n * or outside a virtualized window.\n */\nexport function placeOf<Row>(\n target: GridContextMenuTarget,\n parts: GridParts<Row>,\n): ContextMenuPlace | null {\n const columnIndexOf = (columnId: string) =>\n parts.columns.findIndex((column) => column.id === columnId);\n switch (target.area) {\n case \"header\":\n return onCell(\n target,\n headerCell(parts, columnIndexOf(target.columnId)),\n parts,\n );\n case \"cell\": {\n const rowIndex = parts.pageRows.findIndex(\n (entry) => entry.kind === \"data\" && entry.rowId === target.rowId,\n );\n return onCell(\n target,\n bodyCell(parts, rowIndex, columnIndexOf(target.columnId)),\n parts,\n );\n }\n case \"group\": {\n const rowIndex = parts.pageRows.findIndex(\n (entry) => entry.kind === \"group\" && entry.groupId === target.groupId,\n );\n return onCell(target, bodyCell(parts, rowIndex, 0), parts);\n }\n case \"body\":\n return parts.body === null ? null : onBody(parts.body, parts);\n }\n}\n","import { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { GridOptions } from \"@gridkitjs/core\";\nimport type { OpenContextMenu } from \"../contextMenu/useContextMenu\";\nimport type { OpenPanel } from \"../panels/useGridPanels\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\n\n/** Which of the grid's top-level overlays is open: one at most. */\nexport type GridOverlayState =\n | { readonly kind: \"closed\" }\n | { readonly kind: \"contextMenu\"; readonly menu: OpenContextMenu }\n | { readonly kind: \"panel\"; readonly panel: OpenPanel };\n\nexport type OpenGridOverlay = Exclude<GridOverlayState, { kind: \"closed\" }>;\n\nconst CLOSED: GridOverlayState = { kind: \"closed\" };\n\ninterface UseGridOverlayOptions<Row> {\n nav: GridNavigationApi;\n onContextMenuOpenChange: GridOptions<Row>[\"onContextMenuOpenChange\"];\n}\n\nexport interface GridOverlayApi {\n /** The overlay as the last render drew it. */\n drawn: GridOverlayState;\n /**\n * The overlay open as of the last change, ahead of the render that draws\n * it: what a call acting on the open overlay reads.\n */\n current: () => GridOverlayState;\n /** Opens `next` in place of whatever is open. */\n open: (next: OpenGridOverlay) => void;\n /** Closes the overlay open if it is a `kind` one, and leaves any other. */\n close: (kind: OpenGridOverlay[\"kind\"]) => void;\n /**\n * Where focus goes when an overlay closes and the element it returns focus\n * to has gone with what it did, as a header goes with its hidden column:\n * the cell now holding the grid's tab stop.\n */\n returnFocusFallback: () => HTMLElement | null;\n}\n\n/**\n * The grid's top-level overlays — the context menu and the panels — held as\n * one state, so opening one closes the other, whether from the grid or the\n * ref. Every change goes through here, which tells `onContextMenuOpenChange`\n * when a context menu opens or closes: the one closing first.\n *\n * `open` and `close` keep their identity across renders, so an effect can\n * close an overlay on its way out.\n */\nexport default function useGridOverlay<Row>({\n nav,\n onContextMenuOpenChange,\n}: UseGridOverlayOptions<Row>): GridOverlayApi {\n const [drawn, setDrawn] = useState(CLOSED);\n const current = useRef(CLOSED);\n // Read through a ref, so a menu closing as the grid unmounts tells the\n // latest callback.\n const reportOpenChange = useRef(onContextMenuOpenChange);\n useLayoutEffect(() => {\n reportOpenChange.current = onContextMenuOpenChange;\n });\n\n const show = useCallback((next: GridOverlayState): void => {\n const previous = current.current;\n current.current = next;\n setDrawn(next);\n if (previous.kind === \"contextMenu\") {\n reportOpenChange.current?.({ open: false, target: previous.menu.target });\n }\n if (next.kind === \"contextMenu\") {\n reportOpenChange.current?.({ open: true, target: next.menu.target });\n }\n }, []);\n\n const close = useCallback(\n (kind: OpenGridOverlay[\"kind\"]): void => {\n if (current.current.kind === kind) {\n show(CLOSED);\n }\n },\n [show],\n );\n\n return {\n drawn,\n current: () => current.current,\n open: show,\n close,\n returnFocusFallback: nav.tabStopCell,\n };\n}\n","import { useRef, type ReactNode, type RefCallback } from \"react\";\nimport type {\n FilterState,\n GridCommandTarget,\n GridMessages,\n GridPanelKind,\n} from \"@gridkitjs/core\";\nimport type { ColumnValueOptions } from \"@gridkitjs/core/renderer\";\nimport ColumnChooser from \"../columnChooser/ColumnChooser\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport FilterMenu from \"../filterMenu/FilterMenu\";\nimport useApplyFilter from \"../filterMenu/useApplyFilter\";\nimport useFilterValueCache from \"../filterMenu/useFilterValueCache\";\nimport Overlay, { ANCHOR_GAP } from \"../overlay/Overlay\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridPanelsApi } from \"./useGridPanels\";\n\n/** What every panel is drawn with. */\nexport interface GridPanelProps<Row> {\n /** Where it was asked for — a header's names the column a panel acts on. */\n readonly target: GridCommandTarget;\n /** Read for the grid's state as each render draws it, and acted on. */\n readonly controller: DataGridController<Row>;\n /** The grid's commands, for a panel running one so `onCommand` hears it. */\n readonly commands: GridCommandsApi<Row>;\n readonly messages: GridMessages;\n /** Closes the panel, giving focus back to where it was opened from. */\n readonly close: () => void;\n /**\n * The `ref` of the control focus starts on as the panel opens — a filter\n * editor's value box. A panel giving it to none starts on its first\n * control.\n */\n readonly initialFocusRef: RefCallback<HTMLElement>;\n /**\n * Sets the grid's filter as a filter menu applies one, announcing the rows\n * it keeps once they are drawn — even when the menu has closed by then.\n */\n readonly applyFilter: (filter: FilterState<Row>) => void;\n /**\n * The values a filter checklist lists for a column, counted once and\n * handed back again while nothing they are counted from changes — kept\n * by the panel host, so reopening a column's menu reuses its list.\n */\n readonly columnValues: (columnId: string) => ColumnValueOptions;\n}\n\n/** How one kind of panel is drawn. */\ninterface PanelKind {\n readonly component: <Row>(props: GridPanelProps<Row>) => ReactNode;\n /**\n * Whether Tab stays inside the panel, as in a dialog. A panel holding a\n * draft keeps it, since tabbing out would close it and drop the draft; one\n * applying every change at once lets Tab leave.\n */\n readonly trapFocus: boolean;\n}\n\n/**\n * Each kind of panel. Keyed by `GridPanelKind`, so a kind added there fails\n * to compile until it has its entry here, and needs nothing else.\n */\nconst panelKinds: { readonly [Kind in GridPanelKind]: PanelKind } = {\n columnChooser: { component: ColumnChooser, trapFocus: false },\n filter: { component: FilterMenu, trapFocus: true },\n};\n\ninterface GridPanelsProps<Row> {\n panels: GridPanelsApi;\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n messages: GridMessages;\n}\n\n/**\n * The open panel, if any, beside where it was asked for. Rendered after the\n * grid's tables, as every grid overlay is, so the keys pressed in it reach\n * no header or body handler on their way up React's tree.\n */\nexport default function GridPanels<Row>({\n panels,\n controller,\n commands,\n messages,\n}: GridPanelsProps<Row>) {\n const initialFocus = useRef<HTMLElement>(null);\n const applyFilter = useApplyFilter(\n controller,\n messages,\n commands.host.announce,\n );\n const columnValues = useFilterValueCache(controller, messages);\n const { panel, close, returnFocusFallback } = panels;\n if (panel === null) {\n return null;\n }\n const { component: Panel, trapFocus } = panelKinds[panel.kind];\n return (\n <Overlay\n key={panel.key}\n anchor={panel.anchor}\n placement={panel.placement}\n gap={panel.anchor instanceof Element ? ANCHOR_GAP : 0}\n initialFocus={initialFocus}\n returnFocusTo={panel.returnFocusTo}\n returnFocusFallback={returnFocusFallback}\n // A column the chooser hides can scroll the grid back under it.\n ignoreScrollAfterInput\n trapFocus={trapFocus}\n scope={panel.scope}\n onDismiss={close}\n >\n <Panel<Row>\n target={panel.target}\n controller={controller}\n commands={commands}\n messages={messages}\n close={close}\n initialFocusRef={(element) => {\n initialFocus.current = element;\n }}\n applyFilter={applyFilter}\n columnValues={columnValues}\n />\n </Overlay>\n );\n}\n","import { useLayoutEffect, useRef, useState } from \"react\";\nimport { resolveColumnChooser } from \"@gridkitjs/core/renderer\";\nimport type { GridPanelProps } from \"../panels/GridPanels\";\n\n/**\n * The column chooser: a dialog listing every data column, hidden ones\n * included, with a native checkbox each, a search box narrowing the list and\n * a \"Show all\" checkbox over what the search shows. Which columns it lists,\n * which checkbox is disabled and what \"Show all\" does are\n * `@gridkitjs/core`'s `resolveColumnChooser`'s; this draws them.\n *\n * Every change applies at once, through `showColumns` and `hideColumns`, so\n * it reports and announces as any other change to the columns does. There\n * is nothing to confirm, so nothing to cancel: Escape or a click outside\n * just closes it.\n */\nexport default function ColumnChooser<Row>({\n controller,\n messages,\n}: GridPanelProps<Row>) {\n const [search, setSearch] = useState(\"\");\n const showAllRef = useRef<HTMLInputElement>(null);\n const { entries, selectAll, toggleAll } = resolveColumnChooser({\n columns: controller.getView().dataColumns,\n visibility: controller.getState().columnVisibility,\n search,\n });\n\n // A checkbox's mixed state has no attribute, only this property.\n useLayoutEffect(() => {\n if (showAllRef.current !== null) {\n showAllRef.current.indeterminate = selectAll === \"mixed\";\n }\n });\n\n function setVisible(columnIds: readonly string[], visible: boolean): void {\n if (visible) {\n controller.showColumns(columnIds);\n } else {\n controller.hideColumns(columnIds);\n }\n }\n\n return (\n <div\n role=\"dialog\"\n aria-label={messages.columnChooserLabel}\n className=\"gridkit-column-chooser\"\n >\n <input\n type=\"search\"\n className=\"gridkit-column-chooser-search\"\n aria-label={messages.columnChooserSearchLabel}\n placeholder={messages.searchPlaceholder}\n value={search}\n onChange={(event) => {\n setSearch(event.currentTarget.value);\n }}\n />\n {entries.length === 0 ? (\n <p role=\"status\" className=\"gridkit-column-chooser-empty\">\n {messages.noMatchingColumns}\n </p>\n ) : (\n <>\n <label className=\"gridkit-column-chooser-option gridkit-column-chooser-all\">\n <input\n ref={showAllRef}\n type=\"checkbox\"\n checked={selectAll === \"checked\"}\n disabled={toggleAll === null}\n onChange={() => {\n if (toggleAll !== null) {\n setVisible(toggleAll.columnIds, toggleAll.visible);\n }\n }}\n />\n {messages.showAllColumns}\n </label>\n <ul className=\"gridkit-column-chooser-list\">\n {entries.map((entry) => (\n <li key={entry.columnId}>\n <label className=\"gridkit-column-chooser-option\">\n <input\n type=\"checkbox\"\n checked={entry.visible}\n disabled={entry.disabled}\n onChange={() => {\n setVisible([entry.columnId], !entry.visible);\n }}\n />\n {entry.label}\n </label>\n </li>\n ))}\n </ul>\n </>\n )}\n </div>\n );\n}\n","import { useEffect, useRef, type SubmitEvent } from \"react\";\nimport {\n resolveColumnHeaderText,\n resolveMenu,\n type BuiltInCommandId,\n type ResolvedMenuEntry,\n type ResolvedMenuItem,\n} from \"@gridkitjs/core\";\nimport { resolveColumnFilterMenu } from \"@gridkitjs/core/renderer\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { MenuIcon } from \"../menu/menuIcons\";\nimport type { GridPanelProps } from \"../panels/GridPanels\";\nimport ExcelFilterEditor from \"./ExcelFilterEditor\";\nimport type { FilterEditorHandle, FilterEditorProps } from \"./filterEditor\";\nimport SimpleFilterEditor from \"./SimpleFilterEditor\";\n\n/** The sort commands offered above the editor, each hidden where its column cannot sort. */\nconst SORT_COMMANDS: readonly BuiltInCommandId[] = [\n \"sort.ascending\",\n \"sort.descending\",\n \"sort.clear\",\n];\n\nfunction isItem(entry: ResolvedMenuEntry): entry is ResolvedMenuItem {\n return entry.type === \"item\";\n}\n\n/**\n * A column's filter menu: a dialog below its header holding the column's\n * sort commands, its filter editor — the conditions, or the checklist where\n * its `ui` is `\"excel\"` — and buttons that clear the filter, cancel or\n * apply. Which sort entries show and whether \"Clear filter\" can\n * run are the commands' own, resolved by `@gridkitjs/core`'s `resolveMenu`;\n * each runs through the grid's commands, so `onCommand` hears it with the\n * source `\"filterMenu\"`, and closes the menu, as choosing a menu item does.\n *\n * The editor edits a draft, so nothing filters until it is applied: OK, or\n * Enter in a field, applies it; Cancel, Escape or a click outside drops it.\n * The menu closes once the editor has applied, and stays open while the\n * editor marks what keeps it from applying.\n */\nexport default function FilterMenu<Row>({\n target,\n controller,\n commands,\n messages,\n close,\n initialFocusRef,\n applyFilter,\n columnValues,\n}: GridPanelProps<Row>) {\n const editor = useRef<FilterEditorHandle>(null);\n const column =\n target.area === \"header\"\n ? controller\n .getView()\n .dataColumns.find((entry) => entry.id === target.columnId)\n : undefined;\n const menu =\n column === undefined\n ? null\n : resolveColumnFilterMenu(controller.getOptions(), column.column);\n\n // Opened by an app's own command on a column with no menu, or left open as\n // its column loses it: with nothing to show, nothing stays open.\n useEffect(() => {\n if (menu === null) {\n close();\n }\n });\n\n if (column === undefined || menu === null) {\n return null;\n }\n\n const resolveOptions = {\n commands: commands.commands,\n context: commands.contextFor(target),\n };\n const sortItems = resolveMenu(SORT_COMMANDS, resolveOptions).filter(isItem);\n const [clearItem] = resolveMenu([\"filter.clear\"], resolveOptions).filter(\n isItem,\n );\n\n function run(item: ResolvedMenuItem): void {\n commands.run(item.id, target, \"filterMenu\");\n close();\n }\n\n const editorProps: FilterEditorProps<Row> = {\n ref: editor,\n column,\n menu,\n controller,\n messages,\n initialFocusRef,\n applyFilter,\n };\n\n function apply(event: SubmitEvent<HTMLFormElement>): void {\n event.preventDefault();\n if (editor.current?.apply() ?? true) {\n close();\n }\n }\n\n return (\n <div\n role=\"dialog\"\n aria-label={messages.filterMenuLabel(\n resolveColumnHeaderText(column.column),\n )}\n className=\"gridkit-filter-menu\"\n >\n {/*\n * Not validated by the browser: core reads every operand an editor\n * holds, so a `type=\"number\"` input's whole-number step never blocks\n * an apply with a tooltip of the browser's own.\n */}\n <form\n className=\"gridkit-filter-menu-form\"\n noValidate\n onSubmit={apply}\n onKeyDown={(event) => {\n // Enter submits a form from its text boxes but not from a picker —\n // a select, or a checklist's list; here it applies from any.\n if (\n event.key === \"Enter\" &&\n event.target instanceof Element &&\n event.target.closest(\"select, [role=listbox]\") !== null\n ) {\n event.preventDefault();\n event.currentTarget.requestSubmit();\n }\n }}\n >\n {sortItems.length > 0 && (\n <div className=\"gridkit-filter-menu-sort\">\n {sortItems.map((item) => (\n <button\n key={item.id}\n type=\"button\"\n className=\"gridkit-filter-menu-sort-item\"\n disabled={item.disabled}\n {...ariaAttr(\n item.checked !== undefined,\n \"aria-pressed\",\n item.checked,\n )}\n onClick={() => {\n run(item);\n }}\n >\n <span\n className=\"gridkit-filter-menu-sort-icon\"\n aria-hidden=\"true\"\n >\n <MenuIcon name={item.icon} />\n </span>\n {item.label}\n </button>\n ))}\n </div>\n )}\n {menu.ui === \"excel\" ? (\n <ExcelFilterEditor {...editorProps} columnValues={columnValues} />\n ) : (\n <SimpleFilterEditor {...editorProps} />\n )}\n <div className=\"gridkit-filter-menu-actions\">\n {clearItem !== undefined && (\n <button\n type=\"button\"\n className=\"gridkit-filter-menu-clear\"\n disabled={clearItem.disabled}\n onClick={() => {\n run(clearItem);\n }}\n >\n {clearItem.label}\n </button>\n )}\n <button\n type=\"button\"\n className=\"gridkit-filter-menu-cancel\"\n onClick={close}\n >\n {messages.cancelFilter}\n </button>\n <button type=\"submit\" className=\"gridkit-filter-menu-apply\">\n {messages.applyFilter}\n </button>\n </div>\n </form>\n </div>\n );\n}\n","import {\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n} from \"react\";\nimport type { FilterOperator } from \"@gridkitjs/core\";\nimport {\n draftToFilter,\n filterChecklist,\n filterDraftChanged,\n selectAllState,\n type ColumnValueOptions,\n type FilterChecklistItem,\n} from \"@gridkitjs/core/renderer\";\nimport { ChevronLeftIcon } from \"../menu/menuIcons\";\nimport {\n excelEditorReducer,\n initialExcelEditorState,\n openValues,\n type ChecklistAction,\n} from \"./excelEditorState\";\nimport type { FilterEditorHandle, FilterEditorProps } from \"./filterEditor\";\nimport OperatorMenuButton from \"./OperatorMenuButton\";\nimport SimpleFilterEditor from \"./SimpleFilterEditor\";\nimport ValueChecklist from \"./ValueChecklist\";\n\nexport interface ExcelFilterEditorProps<Row> extends FilterEditorProps<Row> {\n /**\n * The values a column's checklist lists, counted over the rows the other\n * columns' filters keep — the same list again while nothing it is counted\n * from has changed.\n */\n readonly columnValues: (columnId: string) => ColumnValueOptions;\n}\n\n/**\n * What the editor shows: the checklist, or a condition at the operator\n * chosen from its menu, in place of the checklist. A condition takes focus\n * as it shows, being shown only once chosen; the checklist does when it\n * comes back from one, giving focus to the button whose menu chose it.\n */\ntype ExcelEditorMode =\n | { readonly kind: \"values\"; readonly focusOnMount: boolean }\n | { readonly kind: \"condition\"; readonly operator: FilterOperator };\n\nconst OPENED_ON_VALUES: ExcelEditorMode = {\n kind: \"values\",\n focusOnMount: false,\n};\n\n/** What a checklist item's toggle does to the draft. */\nfunction toggleOf<Row>(item: FilterChecklistItem): ChecklistAction<Row> {\n return item.kind === \"blanks\"\n ? { type: \"setIncludeBlanks\", includeBlanks: !item.checked }\n : { type: \"toggleValue\", value: item.value };\n}\n\n/**\n * A filter menu's excel editor: a search box, a \"Select all\" checkbox and a\n * checklist of the values the column holds, each checked while the filter\n * keeps it — the model being `@gridkitjs/core`'s `filterEditorReducer`,\n * over the column's values as `columnValues` counts them when the menu\n * opens. The values cascade: they are those of the rows the other columns'\n * filters keep.\n *\n * The search narrows the list, and \"Select all\" acts on what it shows, as\n * in Excel; past the menu's `valueLimit` values the list waits for a search\n * first, and a search matching more lists the first of them. OK applies the\n * draft through `draftToFilter`: everything checked is no filter, anything\n * less one `in` list, OR-ed with \"is blank\" while the blanks stay checked.\n *\n * Above the search, a \"Number filters\" button opens a menu of the column's\n * conditions. Choosing one shows the simple editor in place of the\n * checklist, its first condition at the operator chosen, until \"Back to\n * values\" brings the checklist back as it was left; OK there applies the\n * conditions, which replace the column's values, as Excel's do.\n *\n * Conditions or a custom filter open with every value checked, under a note\n * saying the column is filtered otherwise. OK leaves that filter be while\n * the checked values are those it opened with — `filterDraftChanged` —\n * as it leaves any filter whose values are as they opened.\n *\n * Set in code while it is open, the column's filter shows in place of what\n * was checked, as it would on reopening the menu.\n */\nexport default function ExcelFilterEditor<Row>({\n column,\n menu,\n controller,\n messages,\n initialFocusRef,\n applyFilter,\n columnValues,\n ref,\n}: ExcelFilterEditorProps<Row>) {\n const filter = controller.getState().filter;\n const open = (over: typeof filter) =>\n openValues(over, column.id, columnValues(column.id));\n const [{ opened, draft }, dispatch] = useReducer(\n excelEditorReducer<Row>,\n filter,\n (over) => initialExcelEditorState(open(over)),\n );\n // Set in code while the menu is open — `setFilter`, a controlled `filter`.\n if (filter !== opened.over) {\n dispatch({ type: \"filterChanged\", opened: open(filter) });\n }\n const [mode, setMode] = useState(OPENED_ON_VALUES);\n const conditions = useRef<FilterEditorHandle>(null);\n const conditionsFocus = useRef<HTMLElement | null>(null);\n const operatorButton = useRef<HTMLButtonElement>(null);\n const selectAllRef = useRef<HTMLInputElement>(null);\n // Each a pass over every value — tens of thousands of them on a large\n // column — so worked out as the draft changes, not again as the editor\n // switches to a condition and back.\n const selectAll = useMemo(() => selectAllState(draft), [draft]);\n const checklist = useMemo(\n () =>\n filterChecklist(draft, {\n valueLimit: menu.valueLimit,\n blanksLabel: messages.filterBlanks,\n }),\n [draft, menu.valueLimit, messages.filterBlanks],\n );\n\n // A checkbox's mixed state has no attribute, only this property.\n useLayoutEffect(() => {\n if (selectAllRef.current !== null) {\n selectAllRef.current.indeterminate = selectAll === \"mixed\";\n }\n });\n\n // Once the side switched to is drawn.\n useLayoutEffect(() => {\n if (mode.kind === \"condition\") {\n conditionsFocus.current?.focus();\n } else if (mode.focusOnMount) {\n operatorButton.current?.focus();\n }\n }, [mode]);\n\n useImperativeHandle(ref, () => ({\n apply: () => {\n if (mode.kind === \"condition\") {\n return conditions.current?.apply() ?? true;\n }\n if (filterDraftChanged(opened.draft, draft)) {\n applyFilter(\n draftToFilter(draft, column.id, controller.getState().filter),\n );\n }\n return true;\n },\n }));\n\n if (mode.kind === \"condition\") {\n return (\n <>\n <button\n type=\"button\"\n className=\"gridkit-filter-menu-back\"\n onClick={() => {\n setMode({ kind: \"values\", focusOnMount: true });\n }}\n >\n <span className=\"gridkit-filter-menu-back-icon\" aria-hidden=\"true\">\n <ChevronLeftIcon />\n </span>\n {messages.filterBackToValues}\n </button>\n <SimpleFilterEditor\n ref={conditions}\n column={column}\n menu={menu}\n controller={controller}\n messages={messages}\n initialFocusRef={(element) => {\n conditionsFocus.current = element;\n }}\n applyFilter={applyFilter}\n operator={mode.operator}\n />\n </>\n );\n }\n\n const { shape } = opened;\n return (\n <div className=\"gridkit-filter-menu-values\">\n {menu.operators.length > 0 && (\n <OperatorMenuButton\n ref={operatorButton}\n menu={menu}\n active={\n shape.kind === \"conditions\"\n ? shape.conditions.map((condition) => condition.operator)\n : undefined\n }\n messages={messages}\n onChoose={(operator) => {\n setMode({ kind: \"condition\", operator });\n }}\n />\n )}\n {(shape.kind === \"conditions\" || shape.kind === \"custom\") && (\n <p className=\"gridkit-filter-menu-custom\">\n {shape.kind === \"conditions\"\n ? messages.filterByCondition\n : messages.customFilter}\n </p>\n )}\n <input\n ref={initialFocusRef}\n type=\"search\"\n className=\"gridkit-filter-menu-search\"\n aria-label={messages.filterSearchLabel}\n placeholder={messages.searchPlaceholder}\n value={draft.search}\n onChange={(event) => {\n dispatch({ type: \"search\", search: event.currentTarget.value });\n }}\n />\n <label className=\"gridkit-filter-menu-select-all\">\n <input\n ref={selectAllRef}\n type=\"checkbox\"\n checked={selectAll === \"checked\"}\n // Nothing to act on: the search matches no value.\n disabled={!checklist.needsSearch && checklist.items.length === 0}\n onChange={() => {\n dispatch({ type: \"toggleAll\" });\n }}\n />\n {messages.filterSelectAll}\n </label>\n {checklist.needsSearch ? (\n <p className=\"gridkit-filter-menu-search-first\">\n {messages.filterSearchFirst(checklist.total)}\n </p>\n ) : (\n <ValueChecklist\n items={checklist.items}\n showCounts={menu.showCounts}\n label={messages.filterValuesLabel}\n onToggle={(item) => {\n dispatch(toggleOf<Row>(item));\n }}\n />\n )}\n {checklist.hiddenCount > 0 && (\n <p role=\"status\" className=\"gridkit-filter-menu-more\">\n {messages.filterMoreValues(checklist.hiddenCount)}\n </p>\n )}\n </div>\n );\n}\n","import type { FilterState } from \"@gridkitjs/core\";\nimport {\n describeColumnFilter,\n filterDraftChanged,\n filterEditorReducer,\n initialFilterEditorDraft,\n toValuesDraft,\n type ColumnFilterShape,\n type ColumnValueOptions,\n type FilterEditorAction,\n type FilterEditorDraft,\n type ValuesDraft,\n} from \"@gridkitjs/core/renderer\";\n\n/** What an excel editor opened with, read from the column's filter. */\nexport interface OpenedValues<Row> {\n /** The grid's filter it was read from. */\n readonly over: FilterState<Row>;\n readonly shape: ColumnFilterShape<Row>;\n /** On its conditions when the column's filter is conditions. */\n readonly draft: FilterEditorDraft<Row>;\n}\n\n/**\n * An excel editor's state: what it opened with, and the user's checklist.\n * Conditions are the simple editor's, shown in place of the checklist with\n * a state of its own, so the draft here stays on its checklist.\n */\nexport interface ExcelEditorState<Row> {\n readonly opened: OpenedValues<Row>;\n readonly draft: ValuesDraft<Row>;\n}\n\n/** What the checklist does to its draft: any draft action but conditions. */\nexport type ChecklistAction<Row> = Exclude<\n FilterEditorAction<Row>,\n { readonly type: \"setConditions\" }\n>;\n\nexport type ExcelEditorAction<Row> =\n | ChecklistAction<Row>\n /** The grid's filter changed while the editor is open: what it now reads. */\n | { readonly type: \"filterChanged\"; readonly opened: OpenedValues<Row> };\n\n/** What an excel editor opens with over `filter`, listing `values`. */\nexport function openValues<Row>(\n filter: FilterState<Row>,\n columnId: string,\n values: ColumnValueOptions,\n): OpenedValues<Row> {\n const shape = describeColumnFilter(filter, columnId);\n return {\n over: filter,\n shape,\n draft: initialFilterEditorDraft(shape, values),\n };\n}\n\n/** An excel editor's state as it opens on `opened`. */\nexport function initialExcelEditorState<Row>(\n opened: OpenedValues<Row>,\n): ExcelEditorState<Row> {\n return { opened, draft: toValuesDraft(opened.draft) };\n}\n\n/**\n * Whether the editor opens alike on what `a` and `b` read: the same note,\n * the same values listed, checked alike. The list is compared by identity:\n * the grid hands back the same one while nothing it is counted from changes.\n */\nfunction showsAlike<Row>(a: OpenedValues<Row>, b: OpenedValues<Row>): boolean {\n return (\n a.shape.kind === b.shape.kind &&\n a.draft.options === b.draft.options &&\n !filterDraftChanged(a.draft, b.draft)\n );\n}\n\n/**\n * The next state after `action`: the draft as `filterEditorReducer` changes\n * it. A change to the grid's filter that the editor would open on\n * differently starts it again on that, as reopening it would, dropping\n * what was checked; one it would open on alike leaves the draft be.\n */\nexport function excelEditorReducer<Row>(\n state: ExcelEditorState<Row>,\n action: ExcelEditorAction<Row>,\n): ExcelEditorState<Row> {\n if (action.type === \"filterChanged\") {\n return showsAlike(state.opened, action.opened)\n ? { ...state, opened: action.opened }\n : initialExcelEditorState(action.opened);\n }\n // Only narrows the type: a checklist action leaves the draft on its checklist.\n return {\n ...state,\n draft: toValuesDraft(filterEditorReducer(state.draft, action)),\n };\n}\n","import {\n useLayoutEffect,\n useRef,\n useState,\n type KeyboardEvent,\n type MouseEvent,\n type RefObject,\n} from \"react\";\nimport type { AttachedMenu } from \"@gridkitjs/dom\";\nimport {\n ANCHOR_GAP,\n overlayScope,\n type OverlayScope,\n} from \"../overlay/Overlay\";\n\n/** A menu button's menu: closed, or open from the button. */\nexport type MenuButtonState =\n | { readonly kind: \"closed\" }\n | {\n readonly kind: \"open\";\n /** The button, which the menu opens beside and returns focus to. */\n readonly anchor: HTMLElement;\n readonly scope: OverlayScope;\n /** How far from the button the menu opens. */\n readonly gap: number;\n /** The item it opens on: the first, or the last when ArrowUp opened it. */\n readonly focusItem: number;\n };\n\nconst CLOSED: MenuButtonState = { kind: \"closed\" };\n\ninterface UseMenuButtonOptions {\n /** How many items the menu holds, separators aside. */\n itemCount: number;\n /**\n * How far from the button its menu opens, measured as it opens. Defaults\n * to `ANCHOR_GAP`.\n */\n gap?: ((button: HTMLElement) => number) | undefined;\n}\n\nexport interface MenuButtonApi {\n state: MenuButtonState;\n close: () => void;\n /** Spread on the button. */\n buttonProps: {\n \"aria-haspopup\": \"menu\";\n \"aria-expanded\": boolean;\n onClick: (event: MouseEvent<HTMLElement>) => void;\n onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n };\n /** The menu's `behaviourRef`, for moving focus to `focusItem`. */\n behaviourRef: RefObject<AttachedMenu | null>;\n}\n\n/**\n * A button opening a menu, following the WAI-ARIA menu button pattern: a\n * click, Enter, Space or ArrowDown opens the menu with focus on its first\n * item, ArrowUp on its last, and a second click closes it. The caller draws\n * the menu in an `Overlay` while `state` is open, returning focus to its\n * `anchor`.\n */\nexport default function useMenuButton({\n itemCount,\n gap = () => ANCHOR_GAP,\n}: UseMenuButtonOptions): MenuButtonApi {\n const [state, setState] = useState(CLOSED);\n const behaviourRef = useRef<AttachedMenu | null>(null);\n\n // As the menu opens, after the overlay — a child, whose layout effect runs\n // first — has focused the first item.\n useLayoutEffect(() => {\n if (state.kind === \"open\" && state.focusItem > 0) {\n behaviourRef.current?.focusItem(state.focusItem);\n }\n }, [state]);\n\n function open(button: HTMLElement, onLast: boolean): void {\n setState({\n kind: \"open\",\n anchor: button,\n scope: overlayScope(button),\n gap: gap(button),\n focusItem: onLast ? itemCount - 1 : 0,\n });\n }\n\n function close(): void {\n setState(CLOSED);\n }\n\n return {\n state,\n close,\n buttonProps: {\n \"aria-haspopup\": \"menu\",\n \"aria-expanded\": state.kind === \"open\",\n onClick: (event) => {\n if (state.kind === \"closed\") {\n open(event.currentTarget, false);\n } else {\n close();\n }\n },\n onKeyDown: (event) => {\n if (\n (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") &&\n state.kind === \"closed\"\n ) {\n event.preventDefault();\n open(event.currentTarget, event.key === \"ArrowUp\");\n }\n },\n },\n behaviourRef,\n };\n}\n","import type { Ref } from \"react\";\nimport type {\n FilterOperator,\n GridMessages,\n ResolvedMenuItem,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumnFilterMenu } from \"@gridkitjs/core/renderer\";\nimport GridMenu from \"../menu/GridMenu\";\nimport { CheckIcon, ChevronRightIcon } from \"../menu/menuIcons\";\nimport useMenuButton from \"../menu/useMenuButton\";\nimport Overlay, { ANCHOR_GAP } from \"../overlay/Overlay\";\n\ninterface OperatorMenuButtonProps {\n /** The column's filter menu: the operators listed, in its family's words. */\n readonly menu: ResolvedColumnFilterMenu;\n /**\n * The operators the column's conditions use, each checked in the menu — or\n * `undefined` while the column is not filtered by conditions, when no item\n * is checkable.\n */\n readonly active: readonly FilterOperator[] | undefined;\n readonly messages: GridMessages;\n /** An operator was chosen, and the menu has closed. */\n readonly onChoose: (operator: FilterOperator) => void;\n readonly ref: Ref<HTMLButtonElement>;\n}\n\n/**\n * How far from the button's side its menu opens: past the edge of the filter\n * menu the button sits in, by the gap an overlay keeps from what it opens\n * beside — so it opens beside the filter menu rather than over its edge.\n * The filter menu's padding is the same either side, so the gap holds when\n * the menu flips to the left.\n */\nfunction gapBeside(button: HTMLElement): number {\n const dialog = button.closest('[role=\"dialog\"]') ?? button;\n return (\n dialog.getBoundingClientRect().right -\n button.getBoundingClientRect().right +\n ANCHOR_GAP\n );\n}\n\n/**\n * The excel editor's \"Number filters\" button, opening a menu of the\n * conditions the column offers — a `GridMenu` in an overlay of its own,\n * stacked above the filter menu, so Escape closes it alone and a click in\n * it leaves the filter menu open. It is a menu button as `useMenuButton`\n * describes, and closing its menu returns focus to it.\n *\n * While the column is filtered by conditions, its operators are checked in\n * the menu, and the button carries a tick, as Excel's does.\n */\nexport default function OperatorMenuButton({\n menu,\n active,\n messages,\n onChoose,\n ref,\n}: OperatorMenuButtonProps) {\n const { state, close, buttonProps, behaviourRef } = useMenuButton({\n itemCount: menu.operators.length,\n gap: gapBeside,\n });\n const label = messages.filterOperatorMenu(menu.family);\n\n const entries = menu.operators.map((operator): ResolvedMenuItem => ({\n type: \"item\",\n id: operator,\n label: messages.filterOperatorLabel(operator, menu.family),\n disabled: false,\n checked: active?.includes(operator),\n run: () => {\n close();\n onChoose(operator);\n return true;\n },\n }));\n\n return (\n <>\n <button\n ref={ref}\n type=\"button\"\n className=\"gridkit-filter-menu-submenu\"\n {...buttonProps}\n >\n <span className=\"gridkit-filter-menu-submenu-icon\" aria-hidden=\"true\">\n {active !== undefined && <CheckIcon />}\n </span>\n {label}\n <span\n className=\"gridkit-filter-menu-submenu-indicator\"\n aria-hidden=\"true\"\n >\n <ChevronRightIcon />\n </span>\n </button>\n {state.kind === \"open\" && (\n <Overlay\n anchor={state.anchor}\n placement=\"right-start\"\n gap={state.gap}\n returnFocusTo={state.anchor}\n scope={state.scope}\n onDismiss={close}\n >\n <GridMenu\n entries={entries}\n label={label}\n scope={state.scope}\n behaviourRef={behaviourRef}\n onRun={(item) => {\n item.run();\n }}\n onClose={close}\n />\n </Overlay>\n )}\n </>\n );\n}\n","import {\n Fragment,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useReducer,\n useRef,\n} from \"react\";\nimport type {\n FilterOperator,\n GridMessages,\n OperatorFilterEntry,\n} from \"@gridkitjs/core\";\nimport {\n conditionsFromRows,\n draftToFilter,\n filterDraftChanged,\n filterEditorReducer,\n} from \"@gridkitjs/core/renderer\";\nimport ConditionRow from \"./ConditionRow\";\nimport type { FilterEditorProps } from \"./filterEditor\";\nimport {\n initialSimpleEditorState,\n openConditions,\n sameConditionRows,\n simpleEditorReducer,\n type Combinator,\n} from \"./simpleEditorState\";\n\nconst COMBINATORS: readonly Combinator[] = [\"and\", \"or\"];\n\n/**\n * Whether a box in `row` holds what the browser can't read as a number or a\n * date — \"1e\", a date missing its year — which it reports as empty, so the\n * row would otherwise pass for one left blank.\n */\nfunction holdsUnreadable(row: HTMLElement | null | undefined): boolean {\n return Array.from(row?.querySelectorAll(\"input\") ?? []).some(\n (input) => input.validity.badInput,\n );\n}\n\ninterface CombinatorChoiceProps {\n /** The radio buttons' shared `name`, unique to the editor. */\n readonly name: string;\n readonly combinator: Combinator;\n readonly messages: GridMessages;\n readonly onChange: (combinator: Combinator) => void;\n}\n\n/** And or Or, between the two conditions: native radio buttons, one tab stop. */\nfunction CombinatorChoice({\n name,\n combinator,\n messages,\n onChange,\n}: CombinatorChoiceProps) {\n return (\n <div\n role=\"radiogroup\"\n aria-label={messages.filterCombinatorLabel}\n className=\"gridkit-filter-menu-combinator\"\n >\n {COMBINATORS.map((choice) => (\n <label key={choice} className=\"gridkit-filter-menu-combinator-option\">\n <input\n type=\"radio\"\n name={name}\n checked={choice === combinator}\n onChange={() => {\n onChange(choice);\n }}\n />\n {choice === \"and\" ? messages.filterAnd : messages.filterOr}\n </label>\n ))}\n </div>\n );\n}\n\nexport interface SimpleFilterEditorProps<Row> extends FilterEditorProps<Row> {\n /**\n * The operator its first condition starts at, chosen from the excel\n * editor's operator submenu — which shows this editor in place of its\n * checklist. A checklist's values are that editor's to show, so they are\n * not called a custom filter here then.\n */\n readonly operator?: FilterOperator | undefined;\n}\n\n/**\n * A filter menu's simple editor: one condition — an operator and its value —\n * and an optional second, joined to it by and/or. It opens on the column's\n * conditions, read by `@gridkitjs/core`'s `describeColumnFilter` and\n * `conditionRowsFrom`, its first at `operator` when given one. On a filter\n * it cannot show — a checklist's values, or a custom filter — it says so\n * above empty conditions, which replace it once applied.\n *\n * The conditions are text until applied, when `conditionsFromRows` reads\n * them as the column's type filters. A condition missing a value, or holding\n * one that doesn't read, keeps the menu open: its boxes are marked invalid,\n * described by a message, and the first takes focus — unless they are as it\n * opened them, as the empty ones on a column it shows no filter for: OK then\n * closes the menu as Cancel would, rather than asking for a value.\n *\n * Set in code while it is open, the column's filter shows in place of what\n * was typed, as it would on reopening the menu.\n */\nexport default function SimpleFilterEditor<Row>({\n column,\n menu,\n controller,\n messages,\n initialFocusRef,\n applyFilter,\n operator,\n ref,\n}: SimpleFilterEditorProps<Row>) {\n const type = column.column.type;\n const filter = controller.getState().filter;\n const open = (over: typeof filter) =>\n openConditions(over, column.id, menu.operators, type, operator);\n const [{ opened, draft, invalid }, dispatch] = useReducer(\n simpleEditorReducer<Row>,\n filter,\n (over) => initialSimpleEditorState(open(over)),\n );\n // Set in code while the menu is open — `setFilter`, a controlled `filter`.\n if (filter !== opened.over) {\n dispatch({ type: \"filterChanged\", opened: open(filter) });\n }\n const rowElements = useRef<(HTMLDivElement | null)[]>([]);\n const invalidMessageId = useId();\n const combinatorName = useId();\n\n /**\n * Puts `conditions` in place of every entry about the column — unless\n * they are the column's own, so a filter set in code stays as written.\n */\n function applyConditions(\n conditions: readonly OperatorFilterEntry<Row>[],\n ): void {\n const applied = filterEditorReducer(opened.filterDraft, {\n type: \"setConditions\",\n conditions,\n combinator: draft.combinator,\n });\n if (filterDraftChanged(opened.filterDraft, applied)) {\n applyFilter(\n draftToFilter(applied, column.id, controller.getState().filter),\n );\n }\n }\n\n useImperativeHandle(ref, () => ({\n apply: () => {\n const parsed = conditionsFromRows<Row>(draft.rows, column.id, type);\n const unreadable = draft.rows.map((_, index) =>\n holdsUnreadable(rowElements.current[index]),\n );\n const marked = draft.rows.flatMap((_, index) =>\n parsed.invalid.includes(index) || unreadable[index] === true\n ? [index]\n : [],\n );\n if (marked.length === 0) {\n applyConditions(parsed.conditions);\n return true;\n }\n // Nothing typed since it opened: OK closes it, as Cancel would, rather\n // than asking for a value.\n if (\n sameConditionRows(draft, opened.draft) &&\n !unreadable.includes(true)\n ) {\n return true;\n }\n dispatch({ type: \"markInvalid\", rows: marked });\n return false;\n },\n }));\n\n // After the render marking it, so the box is invalid as it takes focus.\n useLayoutEffect(() => {\n const [first] = invalid;\n if (first !== undefined) {\n rowElements.current[first]\n ?.querySelector<HTMLElement>('[aria-invalid=\"true\"]')\n ?.focus();\n }\n }, [invalid]);\n\n return (\n <div className=\"gridkit-filter-menu-conditions\">\n {opened.custom && (\n <p className=\"gridkit-filter-menu-custom\">{messages.customFilter}</p>\n )}\n {draft.rows.map((row, index) => (\n // A row is its place: the first condition, or the second.\n <Fragment key={index}>\n {index > 0 && (\n <CombinatorChoice\n name={combinatorName}\n combinator={draft.combinator}\n messages={messages}\n onChange={(combinator) => {\n dispatch({ type: \"setCombinator\", combinator });\n }}\n />\n )}\n <ConditionRow\n ref={(element) => {\n rowElements.current[index] = element;\n }}\n row={row}\n position={index + 1}\n menu={menu}\n type={type}\n messages={messages}\n invalidMessageId={\n invalid.includes(index) ? invalidMessageId : undefined\n }\n focusRef={index === 0 ? initialFocusRef : undefined}\n onChange={(next) => {\n dispatch({ type: \"editRow\", index, row: next });\n }}\n />\n </Fragment>\n ))}\n {invalid.length > 0 && (\n <p id={invalidMessageId} className=\"gridkit-filter-menu-invalid\">\n {messages.filterValueInvalid(menu.family)}\n </p>\n )}\n </div>\n );\n}\n","import type { ChangeEvent, Ref, RefCallback } from \"react\";\nimport type {\n ColumnType,\n FilterOperatorFamily,\n GridMessages,\n} from \"@gridkitjs/core\";\nimport {\n filterOperandArity,\n parseFilterOperand,\n type ConditionRowDraft,\n type ResolvedColumnFilterMenu,\n} from \"@gridkitjs/core/renderer\";\n\n/**\n * The input a column of `type` takes an operand in, each writing what\n * `@gridkitjs/core`'s `parseFilterOperand` reads: a day for a date column, a\n * day and a time for a date-time or time one.\n */\nfunction inputType(\n family: Exclude<FilterOperatorFamily, \"boolean\">,\n type: ColumnType | undefined,\n): \"text\" | \"number\" | \"date\" | \"datetime-local\" {\n switch (family) {\n case \"text\":\n return \"text\";\n case \"number\":\n return \"number\";\n case \"date\":\n return type === \"date\" ? \"date\" : \"datetime-local\";\n }\n}\n\ninterface OperandFieldProps {\n readonly family: FilterOperatorFamily;\n readonly type: ColumnType | undefined;\n readonly text: string;\n /** Its accessible name: \"Value\", or a `between`'s \"From\" or \"To\". */\n readonly label: string;\n /** The id of the message describing it while it is invalid. */\n readonly invalidMessageId: string | undefined;\n readonly fieldRef: RefCallback<HTMLElement> | undefined;\n readonly messages: GridMessages;\n readonly onChange: (text: string) => void;\n}\n\n/** One operand's box — a true/false choice on a boolean column. */\nfunction OperandField({\n family,\n type,\n text,\n label,\n invalidMessageId,\n fieldRef,\n messages,\n onChange,\n}: OperandFieldProps) {\n const field = {\n ref: fieldRef,\n className: \"gridkit-filter-menu-value\",\n \"aria-label\": label,\n \"aria-invalid\": invalidMessageId === undefined ? undefined : true,\n \"aria-describedby\": invalidMessageId,\n value: text,\n onChange: (event: ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {\n onChange(event.currentTarget.value);\n },\n };\n if (family === \"boolean\") {\n // Empty to start with, as a text box is, so a second condition left\n // alone is dropped rather than applied as \"Equals true\".\n return (\n <select {...field}>\n <option value=\"\" />\n <option value=\"true\">{messages.booleanTrue}</option>\n <option value=\"false\">{messages.booleanFalse}</option>\n </select>\n );\n }\n return <input {...field} type={inputType(family, type)} />;\n}\n\ninterface ConditionRowProps {\n readonly row: ConditionRowDraft;\n /** Its place among the editor's conditions, from one — what names it. */\n readonly position: number;\n readonly menu: ResolvedColumnFilterMenu;\n readonly type: ColumnType | undefined;\n readonly messages: GridMessages;\n /**\n * The id of the message saying its value is missing or doesn't read, while\n * it is marked so: each box whose text doesn't read is then invalid, and\n * described by it.\n */\n readonly invalidMessageId: string | undefined;\n /**\n * The `ref` of the control focus starts on: its first box, or its operator\n * picker when its operator takes no operand.\n */\n readonly focusRef: RefCallback<HTMLElement> | undefined;\n readonly onChange: (row: ConditionRowDraft) => void;\n readonly ref: Ref<HTMLDivElement>;\n}\n\n/**\n * One condition of a filter menu's editor, as typed: an operator picker,\n * then a box for each operand its operator takes — none for the blanks\n * operators, two for `between`'s ends.\n */\nexport default function ConditionRow({\n row,\n position,\n menu,\n type,\n messages,\n invalidMessageId,\n focusRef,\n onChange,\n ref,\n}: ConditionRowProps) {\n const arity = filterOperandArity(row.operator);\n // A condition set in code can use an operator the column doesn't offer; it\n // is listed too, so the row shows the condition as it is.\n const operators = menu.operators.includes(row.operator)\n ? menu.operators\n : [row.operator, ...menu.operators];\n const operand = { family: menu.family, type, messages };\n\n /**\n * The message id for a box holding `text`, while the row is marked: on the\n * box that is empty or doesn't read — a `between`'s missing end, not the\n * one filled in.\n */\n function messageIdFor(text: string): string | undefined {\n return parseFilterOperand(text, type) === undefined\n ? invalidMessageId\n : undefined;\n }\n\n return (\n <div\n ref={ref}\n role=\"group\"\n aria-label={messages.filterConditionLabel(position)}\n className=\"gridkit-filter-menu-condition\"\n >\n <select\n ref={arity === 0 ? focusRef : undefined}\n className=\"gridkit-filter-menu-operator\"\n aria-label={messages.filterOperatorFieldLabel}\n value={row.operator}\n onChange={(event) => {\n const operator = operators[event.currentTarget.selectedIndex];\n if (operator !== undefined) {\n onChange({ ...row, operator });\n }\n }}\n >\n {operators.map((operator) => (\n <option key={operator} value={operator}>\n {messages.filterOperatorLabel(operator, menu.family)}\n </option>\n ))}\n </select>\n {arity > 0 && (\n <OperandField\n {...operand}\n text={row.text}\n label={\n arity === 2 ? messages.filterFromLabel : messages.filterValueLabel\n }\n invalidMessageId={messageIdFor(row.text)}\n fieldRef={focusRef}\n onChange={(text) => {\n onChange({ ...row, text });\n }}\n />\n )}\n {arity === 2 && (\n <OperandField\n {...operand}\n text={row.textTo}\n label={messages.filterToLabel}\n invalidMessageId={messageIdFor(row.textTo)}\n fieldRef={undefined}\n onChange={(textTo) => {\n onChange({ ...row, textTo });\n }}\n />\n )}\n </div>\n );\n}\n","import type { ColumnType, FilterOperator, FilterState } from \"@gridkitjs/core\";\nimport {\n conditionRowsFrom,\n conditionsFromRows,\n describeColumnFilter,\n initialFilterEditorDraft,\n type ColumnFilterShape,\n type ColumnValueOptions,\n type ConditionRowDraft,\n type FilterEditorDraft,\n} from \"@gridkitjs/core/renderer\";\n\nexport type Combinator = \"and\" | \"or\";\n\n/** The conditions as typed, and how they join. */\nexport interface ConditionRowsDraft {\n readonly rows: readonly ConditionRowDraft[];\n readonly combinator: Combinator;\n}\n\n/** What a simple editor opened with, read from the column's filter. */\nexport interface OpenedConditions<Row> {\n /** The grid's filter it was read from. */\n readonly over: FilterState<Row>;\n /** Whether the editor can't show the column's filter: \"Custom filter\". */\n readonly custom: boolean;\n /** The boxes as they opened. */\n readonly draft: ConditionRowsDraft;\n /** The column's filter as a draft, for `filterDraftChanged`. */\n readonly filterDraft: FilterEditorDraft<Row>;\n}\n\n/** A simple editor's state: the draft, and what its last OK marked. */\nexport interface SimpleEditorState<Row> {\n readonly opened: OpenedConditions<Row>;\n readonly draft: ConditionRowsDraft;\n /** The rows the last OK marked invalid, until the draft next changes. */\n readonly invalid: readonly number[];\n}\n\nexport type SimpleEditorAction<Row> =\n | {\n readonly type: \"editRow\";\n readonly index: number;\n readonly row: ConditionRowDraft;\n }\n | { readonly type: \"setCombinator\"; readonly combinator: Combinator }\n | { readonly type: \"markInvalid\"; readonly rows: readonly number[] }\n /** The grid's filter changed while the editor is open: what it now reads. */\n | { readonly type: \"filterChanged\"; readonly opened: OpenedConditions<Row> };\n\n/** No condition marked invalid. */\nconst NO_ROWS: readonly number[] = [];\n\n/**\n * The values the column's filter is drafted over: the simple editor has no\n * checklist, so none.\n */\nconst NO_VALUES: ColumnValueOptions = {\n options: [],\n total: 0,\n truncated: false,\n blanks: 0,\n};\n\n/**\n * The draft standing for the column's filter `shape`, for\n * `filterDraftChanged` to tell an apply that changes nothing. Its conditions\n * are read back from the boxes showing them, `rows`, as the conditions\n * applied will be: a date set in code as a string, or a time to the second,\n * then compares equal to the day or minute its box shows.\n */\nfunction filterDraftShown<Row>(\n shape: ColumnFilterShape<Row>,\n rows: readonly ConditionRowDraft[],\n columnId: string,\n type: ColumnType | undefined,\n): FilterEditorDraft<Row> {\n const draft = initialFilterEditorDraft(shape, {\n ...NO_VALUES,\n columnType: type,\n });\n if (draft.kind !== \"conditions\") {\n return draft;\n }\n const shown = conditionsFromRows<Row>(rows, columnId, type);\n return shown.invalid.length > 0\n ? draft\n : { ...draft, conditions: shown.conditions };\n}\n\n/**\n * What a simple editor opens with over `filter`: the column's conditions,\n * the first at `operator` when given one, chosen from the excel editor's\n * operator menu. A checklist's values are that editor's to show, so with an\n * operator they are not called a custom filter.\n */\nexport function openConditions<Row>(\n filter: FilterState<Row>,\n columnId: string,\n operators: readonly FilterOperator[],\n type: ColumnType | undefined,\n operator: FilterOperator | undefined,\n): OpenedConditions<Row> {\n const shape = describeColumnFilter(filter, columnId);\n const rows = conditionRowsFrom(shape, operators, type);\n return {\n over: filter,\n custom:\n shape.kind === \"custom\" ||\n (shape.kind === \"values\" && operator === undefined),\n draft: {\n // Its typed values kept, as picking the operator in the row keeps them.\n rows:\n operator === undefined\n ? rows\n : rows.map((row, index) =>\n index === 0 ? { ...row, operator } : row,\n ),\n combinator: shape.kind === \"conditions\" ? shape.combinator : \"and\",\n },\n filterDraft: filterDraftShown(shape, rows, columnId, type),\n };\n}\n\n/** A simple editor's state as it opens on `opened`. */\nexport function initialSimpleEditorState<Row>(\n opened: OpenedConditions<Row>,\n): SimpleEditorState<Row> {\n return { opened, draft: opened.draft, invalid: NO_ROWS };\n}\n\n/** Whether two drafts hold the same text in every box, joined alike. */\nexport function sameConditionRows(\n a: ConditionRowsDraft,\n b: ConditionRowsDraft,\n): boolean {\n return (\n a.combinator === b.combinator &&\n a.rows.length === b.rows.length &&\n a.rows.every((row, index) => {\n const other = b.rows[index];\n return (\n other !== undefined &&\n row.operator === other.operator &&\n row.text === other.text &&\n row.textTo === other.textTo\n );\n })\n );\n}\n\n/** Whether the editor opens alike on what `a` and `b` read. */\nfunction showsAlike<Row>(\n a: OpenedConditions<Row>,\n b: OpenedConditions<Row>,\n): boolean {\n return a.custom === b.custom && sameConditionRows(a.draft, b.draft);\n}\n\n/**\n * The next state after `action`. An edit clears what OK marked. A change to\n * the grid's filter that the editor would open on differently starts it\n * again on that, as reopening it would, dropping what was typed; one it\n * would open on alike, such as another column's, leaves the draft be.\n */\nexport function simpleEditorReducer<Row>(\n state: SimpleEditorState<Row>,\n action: SimpleEditorAction<Row>,\n): SimpleEditorState<Row> {\n switch (action.type) {\n case \"editRow\":\n return {\n ...state,\n draft: {\n ...state.draft,\n rows: state.draft.rows.map((row, index) =>\n index === action.index ? action.row : row,\n ),\n },\n invalid: NO_ROWS,\n };\n case \"setCombinator\":\n return {\n ...state,\n draft: { ...state.draft, combinator: action.combinator },\n invalid: NO_ROWS,\n };\n case \"markInvalid\":\n return { ...state, invalid: action.rows };\n case \"filterChanged\":\n return showsAlike(state.opened, action.opened)\n ? { ...state, opened: action.opened }\n : initialSimpleEditorState(action.opened);\n }\n}\n","import { useLayoutEffect, useRef, useState } from \"react\";\nimport type {\n FilterChecklistItem,\n VisibleRange,\n} from \"@gridkitjs/core/renderer\";\nimport {\n attachChecklist,\n createRowVirtualizer,\n type AttachedChecklist,\n type RowVirtualizer,\n} from \"@gridkitjs/dom\";\nimport { CheckIcon } from \"../menu/menuIcons\";\n\n/**\n * The height assumed for an item not yet measured: the theme's, a line of\n * text and its padding. Every mounted item is measured, so it only places\n * those scrolled past.\n */\nconst ESTIMATED_ITEM_HEIGHT = 28;\n\n/** Items mounted beyond each edge of the list's visible part. */\nconst OVERSCAN = 4;\n\nconst NO_RANGE: VisibleRange = {\n startIndex: 0,\n endIndex: -1,\n offsetBefore: 0,\n offsetAfter: 0,\n};\n\ninterface ValueChecklistProps {\n /** Every item of the list, in order — only a window of them is mounted. */\n readonly items: readonly FilterChecklistItem[];\n readonly showCounts: boolean;\n /** The list's accessible name. */\n readonly label: string;\n /** An item asks to be checked or unchecked: Space on it, or a click. */\n readonly onToggle: (item: FilterChecklistItem) => void;\n}\n\n/**\n * A filter checklist's values: a `role=\"listbox\"` with one tab stop, each\n * value an option whose `aria-checked` says whether the filter keeps it.\n * A column can hold thousands of values, so the list is windowed by\n * `@gridkitjs/dom`'s `createRowVirtualizer` — the list is its own scroll\n * element, holding only the items near its scroll position between two\n * spacers — and made to behave by `attachChecklist`, which moves focus by\n * the arrow keys, Home, End, PageUp and PageDown and reports Space or a\n * click on an item by its place in the whole list.\n *\n * An item's key holds characters no DOM attribute may, so it keys React's\n * list only; the DOM knows an item by its place, `aria-posinset` one past it.\n */\nexport default function ValueChecklist({\n items,\n showCounts,\n label,\n onToggle,\n}: ValueChecklistProps) {\n const listRef = useRef<HTMLDivElement>(null);\n const checklistRef = useRef<AttachedChecklist | null>(null);\n const [virtualizer, setVirtualizer] = useState<RowVirtualizer | null>(null);\n const [range, setRange] = useState(NO_RANGE);\n\n /**\n * What the behaviour's callbacks read. They are handed over once, when it\n * attaches, so they read the props of the latest render here.\n */\n const latest = useRef({ items, onToggle });\n useLayoutEffect(() => {\n latest.current = { items, onToggle };\n });\n\n useLayoutEffect(() => {\n const list = listRef.current;\n if (list === null) {\n return undefined;\n }\n const rows = createRowVirtualizer(list, {\n estimatedRowHeight: ESTIMATED_ITEM_HEIGHT,\n overscan: OVERSCAN,\n onRange: setRange,\n });\n const checklist = attachChecklist(list, {\n onToggle: (index) => {\n const item = latest.current.items[index];\n if (item !== undefined) {\n latest.current.onToggle(item);\n }\n },\n scrollToIndex: (index) => {\n rows.scrollToIndex(index, { block: \"nearest\" });\n },\n });\n checklistRef.current = checklist;\n setVirtualizer(rows);\n return () => {\n checklistRef.current = null;\n checklist.detach();\n rows.destroy();\n };\n }, []);\n\n useLayoutEffect(() => {\n virtualizer?.setRowCount(items.length);\n checklistRef.current?.setCount(items.length);\n }, [virtualizer, items.length]);\n\n const shown = items.slice(range.startIndex, range.endIndex + 1);\n\n return (\n <div\n ref={listRef}\n role=\"listbox\"\n aria-multiselectable=\"true\"\n aria-label={label}\n className=\"gridkit-filter-menu-checklist\"\n >\n <div role=\"presentation\" style={{ height: range.offsetBefore }} />\n {shown.map((item, offset) => {\n const index = range.startIndex + offset;\n return (\n <div\n key={item.key}\n ref={virtualizer?.measureRow(index)}\n role=\"option\"\n data-gridkit-checklist-item=\"\"\n data-gridkit-checklist-index={index}\n aria-checked={item.checked}\n aria-setsize={items.length}\n aria-posinset={index + 1}\n className=\"gridkit-filter-menu-option\"\n >\n <span\n className=\"gridkit-filter-menu-option-check\"\n aria-hidden=\"true\"\n >\n <CheckIcon />\n </span>\n <span className=\"gridkit-filter-menu-option-label\">\n {item.label}\n </span>\n {/* Spaced, so the option's name reads \"Alice 3\", not \"Alice3\". */}\n {showCounts && (\n <>\n {\" \"}\n <span className=\"gridkit-filter-menu-option-count\">\n {String(item.count)}\n </span>\n </>\n )}\n </div>\n );\n })}\n <div role=\"presentation\" style={{ height: range.offsetAfter }} />\n </div>\n );\n}\n","import { useEffect, useRef, useState } from \"react\";\nimport type { DataGridController } from \"./useGridController\";\n\n/** An announcement of a change, waiting for the render that draws it. */\nexport interface DrawnAnnouncement {\n /** Whether the grid holds the change, which a controlled one may not. */\n readonly drawn: () => boolean;\n /** Its text, read once the rows are drawn, so the counts are theirs. */\n readonly text: () => string;\n}\n\n/** An announcement as it was asked for, with the rows the grid held then. */\ninterface Request<Row> {\n readonly announcement: DrawnAnnouncement;\n readonly rowsAsked: readonly Row[] | undefined;\n}\n\n/**\n * Announces a change once the grid has drawn it. The returned function\n * takes the announcement as the change is asked for; the render that\n * follows announces it if the grid then holds the change, and drops it if\n * not — a controlled grid that didn't take it — so it never fires at a\n * later render that happens to hold the same thing.\n *\n * Under `dataMode: \"server\"` the rows the change asks for are the server's\n * to send, so the announcement waits for them: for the first render after\n * the request whose `dataSource` is another array than the one held then,\n * while `loading` is off. It is dropped if the grid stops holding the\n * change meanwhile, and a newer request replaces it.\n */\nexport default function useAnnounceWhenDrawn<Row>(\n announce: (text: string) => void,\n controller: DataGridController<Row>,\n): (requested: DrawnAnnouncement) => void {\n const [requested, setRequested] = useState<Request<Row> | null>(null);\n /** The request already announced or dropped, which renders after it skip. */\n const settled = useRef<Request<Row> | null>(null);\n const { dataMode, dataSource, loading = false } = controller.getOptions();\n\n useEffect(() => {\n if (requested === null || settled.current === requested) {\n return;\n }\n const { announcement, rowsAsked } = requested;\n const awaitingRows =\n dataMode === \"server\" && (loading || dataSource === rowsAsked);\n const drawn = announcement.drawn();\n if (drawn && awaitingRows) {\n return;\n }\n settled.current = requested;\n if (drawn) {\n announce(announcement.text());\n }\n }, [requested, dataMode, dataSource, loading, announce]);\n\n return (announcement) => {\n setRequested({\n announcement,\n rowsAsked: controller.getOptions().dataSource,\n });\n };\n}\n\n/**\n * How many rows a search or filter found: the rows it keeps, or under\n * `dataMode: \"server\"` the server's `rowCount` for it.\n */\nexport function resultCount<Row>(controller: DataGridController<Row>): number {\n const { dataMode, rowCount } = controller.getOptions();\n const held = controller.getView().rows.length;\n return dataMode === \"server\" ? (rowCount ?? held) : held;\n}\n","import type { FilterState, GridMessages } from \"@gridkitjs/core\";\nimport useAnnounceWhenDrawn, { resultCount } from \"../useAnnounceWhenDrawn\";\nimport type { DataGridController } from \"../useGridController\";\n\n/**\n * How a filter menu applies a filter: it becomes the grid's filter, and once\n * the grid has drawn the rows it keeps, how many they are of all the rows is\n * announced — `filterResults`, \"3 of 10 rows\". Under `dataMode: \"server\"`\n * the grid holds one page and knows no total without the filter, so once\n * the server's rows arrive it announces their `rowCount` alone,\n * `searchResults` (\"3 rows found\"). Held by the panel host, which outlives\n * the menu: the menu closes as it applies, before the rows are drawn.\n */\nexport default function useApplyFilter<Row>(\n controller: DataGridController<Row>,\n messages: GridMessages,\n announce: (text: string) => void,\n): (filter: FilterState<Row>) => void {\n const announceWhenDrawn = useAnnounceWhenDrawn(announce, controller);\n\n return (filter) => {\n announceWhenDrawn({\n drawn: () => controller.getState().filter === filter,\n text: () =>\n controller.getOptions().dataMode === \"server\"\n ? messages.searchResults(resultCount(controller))\n : messages.filterResults(\n resultCount(controller),\n controller.getOptions().dataSource?.length ?? 0,\n ),\n });\n controller.setFilter(filter);\n };\n}\n","import { useState } from \"react\";\nimport type { GridMessages } from \"@gridkitjs/core\";\nimport {\n createColumnValueOptionsCache,\n type ColumnValueOptions,\n} from \"@gridkitjs/core/renderer\";\nimport type { DataGridController } from \"../useGridController\";\n\n/** Rows to count before the grid has any: one array, so the cache keeps its lists. */\nconst NO_ROWS: readonly never[] = [];\n\n/**\n * The values a column's filter checklist lists, counted over the rows the\n * other columns' filters keep. Held by the panel host for the grid's whole\n * life, so reopening a column's checklist hands back the list it counted\n * last time rather than counting every row again — until the rows, the\n * columns, the locale, `messages` or another column's filter change.\n *\n * `messages` is the grid's own resolved object, which keeps its identity\n * while the `messages` prop does: the cache compares it by identity.\n */\nexport default function useFilterValueCache<Row>(\n controller: DataGridController<Row>,\n messages: GridMessages,\n): (columnId: string) => ColumnValueOptions {\n const [cache] = useState(createColumnValueOptionsCache<Row>);\n\n return (columnId) => {\n const { dataSource = NO_ROWS, locale } = controller.getOptions();\n return cache.get(\n dataSource,\n controller.getView().dataColumns,\n controller.getState().filter,\n columnId,\n locale === undefined ? { messages } : { locale, messages },\n );\n };\n}\n","import { resolveColumnFilterMenu } from \"@gridkitjs/core/renderer\";\nimport type { DataGridController } from \"../useGridController\";\nimport type { GridPanelsApi } from \"./useGridPanels\";\n\n/** What `DataGridApi` carries for the grid's panels. */\nexport interface GridPanelApi {\n /**\n * Opens the column chooser at the grid's top-end corner, in place of any\n * panel or context menu open; it gives focus back to what had it when it\n * closes.\n */\n openColumnChooser(): void;\n /**\n * Opens the filter menu of the column `columnId` below its header, in\n * place of any panel or context menu open, and says whether it opened:\n * not for a column with no filter menu, nor one not shown. It gives focus\n * back to the header when it closes.\n */\n openFilterMenu(columnId: string): boolean;\n /** Closes the filter menu, if one is open, leaving any other panel open. */\n closeFilterMenu(): void;\n}\n\n/** `DataGridApi`'s panel methods, over the grid as it is when called. */\nexport function panelApi<Row>(\n panels: GridPanelsApi,\n controller: DataGridController<Row>,\n): GridPanelApi {\n return {\n openColumnChooser: () => {\n panels.open(\"columnChooser\", { area: \"grid\" });\n },\n openFilterMenu: (columnId) => {\n const shown = controller\n .getView()\n .columns.find((entry) => entry.id === columnId);\n if (\n shown === undefined ||\n resolveColumnFilterMenu(controller.getOptions(), shown.column) === null\n ) {\n return false;\n }\n panels.open(\"filter\", { area: \"header\", columnId });\n return true;\n },\n closeFilterMenu: () => {\n if (panels.current()?.kind === \"filter\") {\n panels.close();\n }\n },\n };\n}\n","import { useRef, type RefObject } from \"react\";\nimport type { GridCommandTarget, GridPanelKind } from \"@gridkitjs/core\";\nimport {\n writingDirection,\n type OverlayAnchor,\n type OverlayPlacement,\n} from \"@gridkitjs/dom\";\nimport { overlayScope, type OverlayScope } from \"../overlay/Overlay\";\nimport type {\n GridOverlayApi,\n GridOverlayState,\n} from \"../overlay/useGridOverlay\";\n\ninterface UseGridPanelsOptions {\n /** The grid's root element, holding the toolbar; a panel asked for from nowhere opens at its corner. */\n rootRef: RefObject<HTMLElement | null>;\n headerTableRef: RefObject<HTMLTableElement | null>;\n /** The grid's one open overlay, the panels among them. */\n overlay: GridOverlayApi;\n}\n\n/** The panel open now. */\nexport interface OpenPanel {\n /** Counts the openings, so one opened over another replaces it. */\n readonly key: number;\n readonly kind: GridPanelKind;\n /** Where it was asked for. */\n readonly target: GridCommandTarget;\n readonly anchor: OverlayAnchor;\n readonly placement: OverlayPlacement;\n /**\n * What gets focus back when it closes: the toolbar button or the header it\n * opened from, or, for `undefined`, whatever had focus as it opened.\n */\n readonly returnFocusTo: HTMLElement | undefined;\n readonly scope: OverlayScope;\n}\n\nexport interface GridPanelsApi {\n /** The panel as the last render drew it. */\n panel: OpenPanel | null;\n /**\n * The panel open as of the last change, ahead of the render that draws it:\n * what a call acting on the open panel reads.\n */\n current: () => OpenPanel | null;\n /**\n * Opens the panel `kind` beside where `target` names, in place of any\n * panel or context menu open.\n */\n open: (kind: GridPanelKind, target: GridCommandTarget) => void;\n /** Closes the panel open, if any, and leaves a context menu open. */\n close: () => void;\n /** See `GridOverlayApi`. */\n returnFocusFallback: () => HTMLElement | null;\n}\n\n/** The element of the root's own toolbar whose `data-gridkit-toolbar-item` is `itemId`. */\nfunction toolbarItem(root: HTMLElement, itemId: string): HTMLElement | null {\n const items = root.querySelectorAll<HTMLElement>(\n \":scope > .gridkit-toolbar > [data-gridkit-toolbar-item]\",\n );\n return (\n Array.from(items).find(\n (item) => item.getAttribute(\"data-gridkit-toolbar-item\") === itemId,\n ) ??\n // In \"More\" while the toolbar is narrow: the button it is chosen from.\n Array.from(items).find((item) =>\n item.hasAttribute(\"data-gridkit-toolbar-more\"),\n ) ??\n null\n );\n}\n\nfunction panelOf(overlay: GridOverlayState): OpenPanel | null {\n return overlay.kind === \"panel\" ? overlay.panel : null;\n}\n\nfunction headerCell(\n headerTable: HTMLTableElement | null,\n columnId: string,\n): HTMLTableCellElement | null {\n const cells = headerTable?.tHead?.rows[0]?.cells;\n return cells === undefined\n ? null\n : (Array.from(cells).find(\n (cell) => cell.getAttribute(\"data-gridkit-column\") === columnId,\n ) ?? null);\n}\n\n/**\n * The grid's panels — the column chooser and a column's filter menu —\n * opened through the command host's `openPanel` as the grid's one overlay\n * (see `useGridOverlay`), so opening one closes a context menu. A panel\n * opens beside where it was asked for: below the toolbar button, below the\n * column header, or at the grid's top-end corner for a call from nowhere in\n * particular, as the ref's is.\n *\n * Opened from a menu, it opens as the menu closes, in the same render: the\n * menu hands focus back to where it was opened from, and the panel takes it\n * from there — and gives it back there when it closes.\n */\nexport default function useGridPanels({\n rootRef,\n headerTableRef,\n overlay,\n}: UseGridPanelsOptions): GridPanelsApi {\n const openings = useRef(0);\n\n function placeFor(\n root: HTMLElement,\n target: GridCommandTarget,\n ): Pick<OpenPanel, \"anchor\" | \"placement\" | \"returnFocusTo\"> {\n const element =\n target.area === \"toolbar\"\n ? toolbarItem(root, target.itemId)\n : target.area === \"header\"\n ? headerCell(headerTableRef.current, target.columnId)\n : null;\n if (element !== null) {\n return {\n anchor: element,\n // The toolbar's own button sits at its far end.\n placement: target.area === \"toolbar\" ? \"bottom-end\" : \"bottom-start\",\n returnFocusTo: element,\n };\n }\n // The grid's top corner at the inline end: its right, or its left under\n // `dir=\"rtl\"`, where the overlay mirrors `bottom-end` to match.\n const { left, right, top } = root.getBoundingClientRect();\n return {\n anchor: { x: writingDirection(root) === \"rtl\" ? left : right, y: top },\n placement: \"bottom-end\",\n returnFocusTo: undefined,\n };\n }\n\n return {\n panel: panelOf(overlay.drawn),\n current: () => panelOf(overlay.current()),\n open: (kind, target) => {\n const root = rootRef.current;\n if (root === null) {\n return;\n }\n openings.current += 1;\n overlay.open({\n kind: \"panel\",\n panel: {\n key: openings.current,\n kind,\n target,\n ...placeFor(root, target),\n scope: overlayScope(root),\n },\n });\n },\n close: () => {\n overlay.close(\"panel\");\n },\n returnFocusFallback: overlay.returnFocusFallback,\n };\n}\n","import { useLayoutEffect, useRef, type ReactNode } from \"react\";\nimport {\n resolveToolbar,\n toolbarEntries,\n type GridMessages,\n type GridOptions,\n type GridToolbarOptions,\n type ResolvedMenuEntry,\n type ResolvedToolbarItem,\n type ToolbarEntry,\n} from \"@gridkitjs/core\";\nimport { splitToolbarItems } from \"@gridkitjs/core/renderer\";\nimport { attachToolbar } from \"@gridkitjs/dom\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport type { GridCommandsApi } from \"../commands/useGridCommands\";\nimport { MenuIcon } from \"../menu/menuIcons\";\nimport type { DataGridController } from \"../useGridController\";\nimport ToolbarMenuButton from \"./ToolbarMenuButton\";\nimport ToolbarSearch from \"./ToolbarSearch\";\nimport useToolbarOverflow from \"./useToolbarOverflow\";\n\ninterface GridToolbarProps<Row> {\n toolbar: GridOptions<Row>[\"toolbar\"];\n /** Fills a custom entry, by its id. */\n renderItem: ((id: string) => ReactNode) | undefined;\n /** The id of the grid element the toolbar acts on. */\n gridId: string;\n controller: DataGridController<Row>;\n commands: GridCommandsApi<Row>;\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/** `run`, also telling `onCommand` through `report` whenever it runs. */\nfunction reporting(run: () => boolean, report: () => void): () => boolean {\n return () => {\n const ran = run();\n if (ran) {\n report();\n }\n return ran;\n };\n}\n\n/** A menu's entries, each item reporting through `report` with its id when it runs. */\nfunction reportingEntries(\n entries: readonly ResolvedMenuEntry[],\n report: (commandId: string) => void,\n): readonly ResolvedMenuEntry[] {\n return entries.map((entry) => {\n switch (entry.type) {\n case \"item\":\n return {\n ...entry,\n run: reporting(entry.run, () => {\n report(entry.id);\n }),\n };\n case \"submenu\":\n return { ...entry, items: reportingEntries(entry.items, report) };\n default:\n return entry;\n }\n });\n}\n\n/**\n * A toolbar item whose `run` — or, for a dropdown, whose items' `run` —\n * also reports to `onCommand` as asked from that item, wherever it ends up\n * drawn: as itself, or in \"More\".\n */\nfunction reportingItem(\n item: ResolvedToolbarItem,\n report: (commandId: string, itemId: string) => void,\n): ResolvedToolbarItem {\n switch (item.type) {\n case \"button\":\n return {\n ...item,\n run: reporting(item.run, () => {\n report(item.id, item.id);\n }),\n };\n case \"menu\":\n return {\n ...item,\n items: reportingEntries(item.items, (commandId) => {\n report(commandId, item.id);\n }),\n };\n default:\n return item;\n }\n}\n\n/**\n * The grid's toolbar, when its `toolbar` option lists anything: the entries\n * resolved by `@gridkitjs/core`'s `resolveToolbar` and drawn as a\n * `role=\"toolbar\"`, which `@gridkitjs/dom`'s `attachToolbar` makes one tab\n * stop the arrow keys move within. Which item shows, is enabled, pressed or\n * does what is core's; this draws them, and resolves them again on every\n * render, so they follow the grid's state.\n *\n * What does not fit moves into a \"More\" menu at the end, as\n * `@gridkitjs/dom`'s `observeToolbarOverflow` measures it and core's\n * `splitToolbarItems` turns it into menu entries: a toggle a checkable item,\n * a dropdown a submenu. The search box and custom entries always stay.\n */\nexport default function GridToolbar<Row>(props: GridToolbarProps<Row>) {\n const entries = toolbarEntries(props.toolbar);\n if (entries.length === 0) {\n return null;\n }\n const options = typeof props.toolbar === \"object\" ? props.toolbar : undefined;\n return (\n <Toolbar\n {...props}\n entries={entries}\n label={options?.label ?? props.messages.toolbarLabel}\n itemAttributes={options?.itemAttributes}\n />\n );\n}\n\nfunction Toolbar<Row>({\n entries,\n label,\n itemAttributes,\n renderItem,\n gridId,\n controller,\n commands,\n messages,\n announce,\n}: GridToolbarProps<Row> & {\n entries: readonly ToolbarEntry<Row>[];\n label: string;\n itemAttributes: GridToolbarOptions<Row>[\"itemAttributes\"];\n}) {\n const toolbarRef = useRef<HTMLDivElement>(null);\n\n const items = resolveToolbar(entries, {\n commands: commands.commands,\n contextFor: commands.contextFor,\n itemAttributes,\n }).map((item) =>\n reportingItem(item, (commandId, itemId) => {\n commands.report(commandId, { area: \"toolbar\", itemId }, \"toolbar\");\n }),\n );\n const fit = useToolbarOverflow(toolbarRef, items);\n const { shown, overflow } = splitToolbarItems(items, fit);\n\n useLayoutEffect(() => {\n const toolbar = toolbarRef.current;\n return toolbar === null ? undefined : attachToolbar(toolbar);\n }, []);\n\n /**\n * Where a menu's focus comes back to when its button has gone: a dropdown\n * whose items all hid, or \"More\" as the toolbar widens with its menu open.\n */\n function toolbarTabStop(): HTMLElement | null {\n const toolbar = toolbarRef.current;\n return (\n toolbar?.querySelector<HTMLElement>('[tabindex=\"0\"]') ??\n toolbar?.querySelector<HTMLElement>(\"button, input\") ??\n null\n );\n }\n\n function draw(item: ResolvedToolbarItem): ReactNode {\n switch (item.type) {\n case \"button\":\n return (\n <button\n key={item.key}\n {...item.attributes}\n type=\"button\"\n className=\"gridkit-toolbar-button\"\n data-gridkit-toolbar-item={item.key}\n {...ariaAttr(item.disabled, \"aria-disabled\", true)}\n {...ariaAttr(\n item.pressed !== undefined,\n \"aria-pressed\",\n item.pressed,\n )}\n {...ariaAttr(\n item.shortcut !== undefined,\n \"aria-keyshortcuts\",\n item.shortcut,\n )}\n onClick={() => {\n item.run();\n }}\n >\n {item.icon !== undefined && (\n <span className=\"gridkit-toolbar-button-icon\" aria-hidden=\"true\">\n <MenuIcon name={item.icon} />\n </span>\n )}\n {item.label}\n </button>\n );\n case \"menu\":\n return (\n <ToolbarMenuButton\n key={item.key}\n itemKey={item.key}\n attributes={item.attributes}\n label={item.label}\n icon={item.icon}\n entries={item.items}\n returnFocusFallback={toolbarTabStop}\n />\n );\n case \"search\":\n return (\n <ToolbarSearch<Row>\n key={item.key}\n itemKey={item.key}\n attributes={item.attributes}\n controller={controller}\n messages={messages}\n announce={announce}\n />\n );\n case \"separator\":\n return (\n <div\n key={item.key}\n role=\"separator\"\n aria-orientation=\"vertical\"\n className=\"gridkit-toolbar-separator\"\n data-gridkit-toolbar-item={item.key}\n />\n );\n case \"spacer\":\n return (\n <div\n key={item.key}\n className=\"gridkit-toolbar-spacer\"\n data-gridkit-toolbar-item={item.key}\n />\n );\n case \"custom\":\n return (\n <div\n key={item.key}\n {...item.attributes}\n className=\"gridkit-toolbar-custom\"\n data-gridkit-toolbar-item={item.key}\n >\n {renderItem?.(item.id)}\n </div>\n );\n }\n }\n\n return (\n <div\n ref={toolbarRef}\n role=\"toolbar\"\n aria-label={label}\n aria-controls={gridId}\n className=\"gridkit-toolbar\"\n >\n {shown.map(draw)}\n {overflow.length > 0 && (\n <ToolbarMenuButton\n itemKey=\"more\"\n label={messages.moreToolbarItems}\n entries={overflow}\n more\n returnFocusFallback={toolbarTabStop}\n />\n )}\n </div>\n );\n}\n","import type { ResolvedMenuEntry, ToolbarItemAttributes } from \"@gridkitjs/core\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport GridMenu from \"../menu/GridMenu\";\nimport { ChevronDownIcon, MenuIcon } from \"../menu/menuIcons\";\nimport useMenuButton from \"../menu/useMenuButton\";\nimport Overlay from \"../overlay/Overlay\";\n\ninterface ToolbarMenuButtonProps {\n /** Its `data-gridkit-toolbar-item`. */\n itemKey: string;\n /** The app's attributes for the button, under the button's own. */\n attributes?: ToolbarItemAttributes | undefined;\n /** The button's label, and its menu's accessible name. */\n label: string;\n icon?: string | undefined;\n entries: readonly ResolvedMenuEntry[];\n /** The \"More\" button, holding the entries that do not fit, rather than a dropdown. */\n more?: boolean | undefined;\n /** Where focus goes when the menu closes with its button gone. */\n returnFocusFallback: () => HTMLElement | null;\n}\n\n/**\n * A toolbar button opening a menu below it, as `useMenuButton` describes.\n * Closing the menu returns focus to the button. What the items do, and\n * whether each runs, is in their `run`.\n */\nexport default function ToolbarMenuButton({\n itemKey,\n attributes,\n label,\n icon,\n entries,\n more = false,\n returnFocusFallback,\n}: ToolbarMenuButtonProps) {\n const { state, close, buttonProps, behaviourRef } = useMenuButton({\n itemCount: entries.filter((entry) => entry.type !== \"separator\").length,\n });\n\n return (\n <>\n <button\n {...attributes}\n type=\"button\"\n className={classNames(\n \"gridkit-toolbar-button\",\n more && \"gridkit-toolbar-more\",\n )}\n data-gridkit-toolbar-item={itemKey}\n {...ariaAttr(more, \"data-gridkit-toolbar-more\", \"\")}\n {...buttonProps}\n >\n {icon !== undefined && (\n <span className=\"gridkit-toolbar-button-icon\" aria-hidden=\"true\">\n <MenuIcon name={icon} />\n </span>\n )}\n {label}\n <span className=\"gridkit-toolbar-button-indicator\" aria-hidden=\"true\">\n <ChevronDownIcon />\n </span>\n </button>\n {state.kind === \"open\" && (\n <Overlay\n anchor={state.anchor}\n placement=\"bottom-start\"\n gap={state.gap}\n returnFocusTo={state.anchor}\n returnFocusFallback={returnFocusFallback}\n scope={state.scope}\n onDismiss={close}\n >\n <GridMenu\n entries={entries}\n label={label}\n scope={state.scope}\n behaviourRef={behaviourRef}\n onRun={(item) => {\n item.run();\n close();\n }}\n onClose={close}\n />\n </Overlay>\n )}\n </>\n );\n}\n","import { useEffect, useRef, useState } from \"react\";\nimport type { GridMessages, ToolbarItemAttributes } from \"@gridkitjs/core\";\nimport { searchTextOf, setSearchText } from \"@gridkitjs/core/renderer\";\nimport useAnnounceWhenDrawn, { resultCount } from \"../useAnnounceWhenDrawn\";\nimport type { DataGridController } from \"../useGridController\";\n\n/** How long typing has to rest before the search applies. */\nconst SEARCH_DELAY_MS = 250;\n\n/** What the user has typed and the grid not yet applied. */\ninterface Draft {\n readonly text: string;\n /**\n * The search applied when it was typed. Once the search changes from\n * elsewhere — \"Clear filters\", a restored layout — the draft is dropped\n * and the box shows that instead.\n */\n readonly over: string;\n}\n\ninterface ToolbarSearchProps<Row> {\n /** Its `data-gridkit-toolbar-item`. */\n itemKey: string;\n /** The app's attributes for the box, under the box's own. */\n attributes: ToolbarItemAttributes | undefined;\n controller: DataGridController<Row>;\n messages: GridMessages;\n announce: (text: string) => void;\n}\n\n/**\n * The toolbar's search box, over the filter's global text entry — the one\n * naming no column — through `@gridkitjs/core`'s `searchTextOf` and\n * `setSearchText`. It reads what it shows back from the filter, so anything\n * else that changes the search changes the box.\n *\n * Typing applies once it rests for a moment; Enter applies at once, and\n * Escape empties the box. A search the box applied is announced as the\n * number of rows it found, once the grid has drawn them; under\n * `dataMode: \"server\"`, the server's `rowCount`, once its rows arrive.\n */\nexport default function ToolbarSearch<Row>({\n itemKey,\n attributes,\n controller,\n messages,\n announce,\n}: ToolbarSearchProps<Row>) {\n const applied = searchTextOf(controller.getState().filter);\n const [draft, setDraft] = useState<Draft | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const announceWhenDrawn = useAnnounceWhenDrawn(announce, controller);\n const text = draft !== null && draft.over === applied ? draft.text : applied;\n\n /** Applies `next`, typed over the search `over`, unless that has changed since. */\n function apply(next: string, over: string): void {\n clearTimeout(timer.current);\n setDraft(null);\n const filter = controller.getState().filter;\n if (searchTextOf(filter) !== over) {\n return;\n }\n const searched = setSearchText(filter, next);\n if (searched !== filter) {\n announceWhenDrawn({\n drawn: () => searchTextOf(controller.getState().filter) === next,\n text: () => messages.searchResults(resultCount(controller)),\n });\n controller.setFilter(searched);\n }\n }\n\n useEffect(\n () => () => {\n clearTimeout(timer.current);\n },\n [],\n );\n\n return (\n <input\n {...attributes}\n type=\"search\"\n className=\"gridkit-toolbar-search\"\n data-gridkit-toolbar-item={itemKey}\n aria-label={messages.searchLabel}\n placeholder={messages.searchPlaceholder}\n value={text}\n onChange={(event) => {\n const typed = event.target.value;\n setDraft({ text: typed, over: applied });\n clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n apply(typed, applied);\n }, SEARCH_DELAY_MS);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n apply(text, applied);\n } else if (event.key === \"Escape\" && text !== \"\") {\n // Ahead of the browser's own clearing, which would wait out the delay.\n event.preventDefault();\n apply(\"\", applied);\n }\n }}\n />\n );\n}\n","import { useLayoutEffect, useRef, useState, type RefObject } from \"react\";\nimport type { ResolvedToolbarItem } from \"@gridkitjs/core\";\nimport { observeToolbarOverflow, type ToolbarOverflow } from \"@gridkitjs/dom\";\n\n/**\n * How many of a toolbar's items fit in it, from the start, as\n * `@gridkitjs/dom`'s `observeToolbarOverflow` measures them — every item\n * until it first reports, which it does before paint.\n *\n * Attached once, so the widths it remembers for items moved into \"More\"\n * survive, and told of new items only when the toolbar's layout — each\n * item's kind, key and label — changes, rather than on every render, which\n * resolves the items afresh. A label matters for an item in \"More\", whose\n * remembered width it makes stale.\n */\nexport default function useToolbarOverflow(\n toolbarRef: RefObject<HTMLElement | null>,\n items: readonly ResolvedToolbarItem[],\n): number {\n const [fit, setFit] = useState(items.length);\n const overflow = useRef<ToolbarOverflow | null>(null);\n const measuredLayout = useRef(\"\");\n const layout = JSON.stringify(\n items.map((item) => [\n item.type,\n item.key,\n \"label\" in item ? item.label : null,\n ]),\n );\n\n useLayoutEffect(() => {\n const toolbar = toolbarRef.current;\n if (toolbar === null || layout === measuredLayout.current) {\n return;\n }\n measuredLayout.current = layout;\n const options = { items, onChange: setFit };\n if (overflow.current === null) {\n overflow.current = observeToolbarOverflow(toolbar, options);\n } else {\n overflow.current.update(options);\n }\n }, [toolbarRef, layout, items]);\n\n useLayoutEffect(\n () => () => {\n overflow.current?.detach();\n overflow.current = null;\n measuredLayout.current = \"\";\n },\n [],\n );\n\n return fit;\n}\n","import type { PointerEvent as ReactPointerEvent } from \"react\";\nimport type {\n ColumnOrderState,\n ColumnPin,\n GroupByState,\n} from \"@gridkitjs/core\";\nimport { resolveKeyboardDropTarget } from \"@gridkitjs/core/renderer\";\nimport { resolveColumnDropTarget, type ColumnDropTarget } from \"@gridkitjs/dom\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport useDragReorder from \"./useDragReorder\";\n\ninterface UseColumnDragOptions {\n order: ColumnOrderState;\n /** What a drop onto the group-by bar is resolved against. */\n groupBy: GroupByState;\n /** Column ids whose header may be dragged into the group-by bar at all. */\n groupByDraggableIds: ReadonlySet<string>;\n /** The edge each column is pinned to, whose group a drag stays inside. */\n pinOf: (columnId: string) => ColumnPin;\n onDrop: (target: ColumnDropTarget, movedId: string) => void;\n}\n\nexport interface ColumnDragApi<Row> {\n /** The column being dragged, for as long as the drag lasts. */\n draggedColumnId: string | null;\n /** Where it would land if released now. */\n dropTarget: ColumnDropTarget | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n ghostTransform: string | null;\n startDrag: (\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ) => void;\n /** Moves a column one place left (`-1`) or right (`1`). */\n moveByKeyboard: (entry: ResolvedColumn<Row>, direction: -1 | 1) => void;\n /**\n * Whether the column's last press opened a drag, so the click that follows\n * its release is not a click, for a header that has something of its own to\n * do with one. Reading it clears it.\n */\n justDragged: (columnId: string) => boolean;\n}\n\n/**\n * Turns a pointer drag over the header into a drop target, leaving `onDrop` to\n * apply it. Built on `useDragReorder`'s shared pointer mechanics, with\n * `@gridkitjs/dom`'s `resolveColumnDropTarget` as the hit-testing: another\n * header (reorder among columns) or the group-by bar (add this column to the\n * grouping), tried in that order.\n */\nexport default function useColumnDrag<Row>({\n order,\n groupBy,\n groupByDraggableIds,\n pinOf,\n onDrop,\n}: UseColumnDragOptions): ColumnDragApi<Row> {\n const drag = useDragReorder<ColumnDropTarget>({\n resolveTarget: (clientX, clientY, movedId) =>\n resolveColumnDropTarget(clientX, clientY, movedId, {\n order,\n groupBy,\n groupByDraggableIds,\n pinOf,\n }),\n onDrop,\n });\n\n function startDrag(\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n drag.startDrag(entry.id, event.currentTarget, event);\n }\n\n function moveByKeyboard(entry: ResolvedColumn<Row>, direction: -1 | 1): void {\n const beforeId = resolveKeyboardDropTarget(order, entry.id, direction);\n if (beforeId === undefined) {\n return;\n }\n onDrop({ kind: \"column-order\", beforeId }, entry.id);\n }\n\n // A new object each render, as `useColumnResize` returns: the handlers close\n // over `order`/`groupBy`, and a stable identity would buy nothing.\n return {\n draggedColumnId: drag.draggedId,\n dropTarget: drag.dropTarget,\n ghostTransform: drag.ghostTransform,\n startDrag,\n moveByKeyboard,\n justDragged: drag.justDragged,\n };\n}\n","import {\n useState,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n} from \"react\";\nimport type { ColumnSizeDefaults } from \"@gridkitjs/core\";\nimport {\n beginColumnResize,\n clampColumnWidth,\n resolveColumnConstraints,\n sizeColumnToContent,\n} from \"@gridkitjs/core/renderer\";\nimport { measureColumnContent, startColumnResizeGesture } from \"@gridkitjs/dom\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport type { DataGridController } from \"./useGridController\";\nimport useGestureSignal from \"./useGestureSignal\";\n\ninterface UseColumnResizeOptions<Row> {\n tableRef: RefObject<HTMLTableElement | null>;\n controller: DataGridController<Row>;\n columnSizeDefaults?: Partial<ColumnSizeDefaults> | undefined;\n}\n\nexport interface ColumnResizeApi<Row> {\n /** The column being dragged, for as long as the drag lasts. */\n activeColumnId: string | null;\n startResize: (\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ) => void;\n /** Sizes a column to its content, and says whether it could: not without cells. */\n sizeToContent: (entry: ResolvedColumn<Row>) => boolean;\n nudge: (entry: ResolvedColumn<Row>, delta: number) => void;\n}\n\n/**\n * Turns pointer and keyboard input into column widths. The drag itself is\n * `@gridkitjs/dom`'s `startColumnResizeGesture`, every width comes from\n * `@gridkitjs/core`, and the grid's controller applies them; this hook holds\n * only which column is being dragged. The drag is cancelled with the\n * component, and with its handle should a render remove it\n * (`useGestureSignal`).\n */\nexport default function useColumnResize<Row>({\n tableRef,\n controller,\n columnSizeDefaults,\n}: UseColumnResizeOptions<Row>): ColumnResizeApi<Row> {\n const [activeColumnId, setActiveColumnId] = useState<string | null>(null);\n const startGesture = useGestureSignal();\n\n function startResize(\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n // A press on the handle is never the header's, whichever button made it:\n // a reorderable header's own drag must not see it.\n event.stopPropagation();\n\n const session = beginColumnResize(\n entry.column,\n entry.width,\n event.clientX,\n columnSizeDefaults,\n );\n /** The sizing as the drag found it, which Escape puts the column back to. */\n const base = controller.getState().columnSizing;\n\n const handle = event.currentTarget;\n const started = startGesture(handle, (signal) =>\n startColumnResizeGesture(handle, event, session, {\n onMove(width) {\n controller.resizeColumn(session.columnId, width, \"move\");\n },\n onEnd(width) {\n setActiveColumnId(null);\n if (width !== null) {\n controller.resizeColumn(session.columnId, width, \"end\");\n }\n },\n /**\n * Escape puts back only the dragged column's pre-drag width, merged\n * into whatever the sizing state is *now* — not the `base` snapshot\n * taken at drag-start — so a different column resized via keyboard\n * while this drag was still open keeps its change instead of being\n * clobbered by a stale restore.\n */\n onCancel() {\n setActiveColumnId(null);\n controller.cancelColumnResize(\n session.columnId,\n base,\n session.startWidth,\n );\n },\n signal,\n }),\n );\n if (started) {\n setActiveColumnId(session.columnId);\n }\n }\n\n function sizeToContent(entry: ResolvedColumn<Row>): boolean {\n const table = tableRef.current;\n if (table === null) {\n return false;\n }\n\n const measured = measureColumnContent(table, entry.id);\n if (measured === null) {\n return false;\n }\n\n controller.resizeColumn(\n entry.id,\n sizeColumnToContent(\n measured,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n return true;\n }\n\n function nudge(entry: ResolvedColumn<Row>, delta: number): void {\n controller.resizeColumn(\n entry.id,\n clampColumnWidth(\n entry.width + delta,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n }\n\n // A new object each render, as the other hooks here return.\n return { activeColumnId, startResize, sizeToContent, nudge };\n}\n","import { useLayoutEffect, useState, type RefObject } from \"react\";\nimport { observeElementHeight } from \"@gridkitjs/dom\";\n\n/**\n * The height of `ref`'s element, tracked as it changes by\n * `@gridkitjs/dom`'s `observeElementHeight`, or `null` while `enabled` is\n * off or the element is not mounted.\n *\n * A layout effect, as in `useElementWidth`, so the first measurement lands\n * before paint.\n */\nexport default function useElementHeight(\n ref: RefObject<HTMLElement | null>,\n enabled: boolean,\n): number | null {\n const [height, setHeight] = useState<number | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n if (element === null || !enabled) {\n return undefined;\n }\n const disconnect = observeElementHeight(element, setHeight);\n return () => {\n disconnect();\n setHeight(null);\n };\n }, [ref, enabled]);\n\n return enabled ? height : null;\n}\n","import { useLayoutEffect, useState, type RefObject } from \"react\";\nimport { observeElementWidth } from \"@gridkitjs/dom\";\n\n/**\n * The inner width of `ref`'s element, tracked as it changes by\n * `@gridkitjs/dom`'s `observeElementWidth`.\n *\n * A layout effect rather than an effect so the first measurement lands before\n * paint — otherwise columns show at their natural width for a frame and then\n * visibly jump once auto-fit runs. No isomorphic-layout-effect shim: React 19\n * skips layout effects on the server without a warning, and the width stays\n * `null` until the client measures.\n *\n * @param enabled Whether to observe at all. A caller that does not read the\n * width passes `false` rather than paying a re-render of the whole grid on\n * every frame of a window resize.\n */\nexport default function useElementWidth(\n ref: RefObject<HTMLElement | null>,\n enabled: boolean,\n): number | null {\n const [width, setWidth] = useState<number | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n if (element === null || !enabled) {\n return undefined;\n }\n return observeElementWidth(element, setWidth);\n }, [ref, enabled]);\n\n return width;\n}\n","import { useState, useSyncExternalStore, type ReactNode } from \"react\";\nimport {\n createGridController,\n type GridController,\n type GridControllerOptions,\n type GridState,\n type GridView,\n} from \"@gridkitjs/core\";\n\n/** The grid's controller, bound to React's node type for its columns. */\nexport type DataGridController<Row> = GridController<Row, ReactNode>;\n\nexport interface GridControllerBinding<Row> {\n controller: DataGridController<Row>;\n /** The state this render draws — re-read on every change the controller commits. */\n state: GridState<Row>;\n view: GridView<Row, ReactNode>;\n}\n\n/**\n * The grid's controller, created once and handed the current props on every\n * render. The controller holds every slice of state and derives the view, so\n * this hook only keeps React in step with it: `setOptions` runs during render,\n * so the view drawn always matches the props drawn, and the subscription\n * re-renders the grid when an action commits.\n *\n * `getState` is the snapshot: the controller hands back the same object until\n * a slice changes, which is exactly the stability `useSyncExternalStore`\n * needs, and a change the props made (a controlled slice) is already in it by\n * the time it is read here. It is the server snapshot too: on the server and\n * while hydrating, the controller has seen only the props, so both sides read\n * the same initial state.\n */\nexport default function useGridController<Row>(\n options: GridControllerOptions<Row, ReactNode>,\n): GridControllerBinding<Row> {\n const [controller] = useState(() =>\n createGridController<Row, ReactNode>(options),\n );\n controller.setOptions(options);\n const state = useSyncExternalStore(\n controller.subscribe,\n controller.getState,\n controller.getState,\n );\n return { controller, state, view: controller.getView() };\n}\n","import { useEffect, useRef, type RefObject } from \"react\";\nimport { attachInfiniteScroll, type InfiniteScroll } from \"@gridkitjs/dom\";\nimport type { InfiniteScrollConfig } from \"./DataGrid\";\n\ninterface UseInfiniteScrollOptions {\n /** The `.gridkit-data-grid-tables` scroll area the rows scroll in. */\n rootRef: RefObject<HTMLDivElement | null>;\n /** The always-last `<tr>` `GridBody` renders while `config?.hasMore` is true. */\n sentinelRef: RefObject<HTMLTableRowElement | null>;\n config: InfiniteScrollConfig | undefined;\n}\n\n/**\n * `@gridkitjs/dom`'s `attachInfiniteScroll` on the scroll area, idle until the\n * effect below hands it the props. That runs after every commit: the\n * sentinel row mounts and unmounts with `hasMore`, so only after a commit is\n * `sentinelRef` current, and an update that changes nothing does nothing.\n */\nexport default function useInfiniteScroll({\n rootRef,\n sentinelRef,\n config,\n}: UseInfiniteScrollOptions): void {\n const scroll = useRef<InfiniteScroll | null>(null);\n\n useEffect(() => {\n const root = rootRef.current;\n if (root === null) {\n return undefined;\n }\n const attached = attachInfiniteScroll(root, {\n sentinel: null,\n hasMore: false,\n });\n scroll.current = attached;\n return () => {\n attached.detach();\n scroll.current = null;\n };\n }, [rootRef]);\n\n useEffect(() => {\n scroll.current?.update({\n sentinel: sentinelRef.current,\n hasMore: config?.hasMore ?? false,\n onLoadMore: config?.onLoadMore,\n isLoadingMore: config?.isLoadingMore,\n rootMargin: config?.rootMargin,\n });\n });\n}\n","import { useCallback, useLayoutEffect, useRef, type RefObject } from \"react\";\nimport { createLiveAnnouncer, type LiveAnnouncer } from \"@gridkitjs/dom\";\n\n/**\n * The grid's live region, added as the last child of `containerRef`'s element\n * once it mounts. `@gridkitjs/dom` owns the element, so React never renders\n * it and an announcement re-renders nothing.\n *\n * A layout effect, so the region is in place from the first paint — where it\n * was when React rendered it. The returned `announce` keeps its identity for\n * the grid's whole life.\n */\nexport default function useLiveAnnouncer(\n containerRef: RefObject<HTMLElement | null>,\n): (text: string) => void {\n const announcer = useRef<LiveAnnouncer | null>(null);\n\n useLayoutEffect(() => {\n const container = containerRef.current;\n if (container === null) {\n return undefined;\n }\n const created = createLiveAnnouncer(container);\n announcer.current = created;\n return () => {\n created.destroy();\n announcer.current = null;\n };\n }, [containerRef]);\n\n return useCallback((text: string) => {\n announcer.current?.announce(text);\n }, []);\n}\n","import { useLayoutEffect, useRef, useState, type RefObject } from \"react\";\nimport type { VisibleRange } from \"@gridkitjs/core/renderer\";\nimport {\n bodyRowFrom,\n createRowVirtualizer,\n type RowVirtualizer,\n} from \"@gridkitjs/dom\";\n\nexport interface RowVirtualizerApi extends VisibleRange {\n /** Ref callback `GridBody` attaches to each rendered row's `<tr>`, keyed by that row's index in the full array. */\n measureRow: (index: number) => (element: HTMLTableRowElement | null) => void;\n /**\n * Scrolls so `index` is visible. Two-pass for a row not currently mounted:\n * jumps to an estimated offset immediately, then — once that row mounts and\n * its real height is measured — corrects the scroll position via the\n * mounted element's own `scrollIntoView`. A row already mounted is scrolled\n * to directly, in one pass. Works from a layout effect in the commit that\n * turns `enabled` on.\n */\n scrollToIndex: (index: number, options?: ScrollIntoViewOptions) => void;\n}\n\ninterface UseRowVirtualizerOptions {\n /** Whether virtualization is active at all. `false` attaches nothing — no behavioral or performance difference from not virtualizing. */\n enabled: boolean;\n /** The full row array — only its `.length` and reference identity matter here; a new reference resets the measured heights (see below). */\n rows: readonly unknown[];\n /**\n * The `.gridkit-data-grid-tables` scroll area. The rows follow the header,\n * which sticks to its top, so the area's scroll position is the rows' own.\n */\n scrollRef: RefObject<HTMLDivElement | null>;\n /** The body's `<table>`, whose mounted rows a new virtualizer measures before its first window. */\n bodyTableRef: RefObject<HTMLTableElement | null>;\n estimatedRowHeight: number;\n overscan: number;\n}\n\n/**\n * The rows the body draws: `allRows` while `enabled` is off, when the body\n * draws every row, and from the moment it turns on until the new virtualizer\n * reports; otherwise the `range` it reported last.\n */\ntype RowWindow =\n | { readonly kind: \"allRows\" }\n | { readonly kind: \"range\"; readonly range: VisibleRange };\n\nconst ALL_ROWS: RowWindow = { kind: \"allRows\" };\n\n/** A grid mounted with `enabled` on draws no rows until its virtualizer reports, which it does before paint. */\nconst NO_ROWS: RowWindow = {\n kind: \"range\",\n range: { startIndex: 0, endIndex: -1, offsetBefore: 0, offsetAfter: 0 },\n};\n\nfunction rangeOf(rowWindow: RowWindow, rowCount: number): VisibleRange {\n if (rowWindow.kind === \"range\") {\n return rowWindow.range;\n }\n return {\n startIndex: 0,\n endIndex: rowCount - 1,\n offsetBefore: 0,\n offsetAfter: 0,\n };\n}\n\n/** The body rows mounted in `table`, each with its index among all the rows; spacer and sentinel rows carry none. */\nfunction* mountedRows(\n table: HTMLTableElement | null,\n): Generator<readonly [number, HTMLTableRowElement]> {\n for (const row of table?.tBodies[0]?.rows ?? []) {\n const target = bodyRowFrom(row);\n if (target !== null) {\n yield [target.rowIndex, row];\n }\n }\n}\n\n/** What a row is measured with before the first virtualizer is created. */\nfunction ignoreRow(): () => void {\n return () => undefined;\n}\n\n/**\n * `@gridkitjs/dom`'s `createRowVirtualizer` on the scroll area, with the window of\n * rows it reports held as state for `GridBody` to render. The virtualizer is\n * state too, because `measureRow` is read while rendering: a new one —\n * `estimatedRowHeight` or `overscan` changed — re-renders every row with its\n * own ref callbacks, so the rows already mounted are measured anew. It is\n * also a ref, which `scrollToIndex` reads: in the commit that turns\n * `enabled` on, a parent's layout effect runs after the one here that\n * creates the virtualizer but before the render that puts it in state.\n *\n * Once `enabled` goes off, the destroyed virtualizer stays in state, where\n * it measures and scrolls nothing. The window goes back to every row, and\n * stays there when `enabled` comes back on until the new virtualizer\n * reports: the rows mounted then stay mounted, the focused one and the\n * browser's focus with it, and the body keeps its height, and so the scroll\n * area its position. An empty window, or the last one reported, would\n * unmount them for a pass, and could collapse the body and send the scroll\n * area to the top.\n * The new virtualizer measures every mounted row before it reports, so its\n * first window is the rows on screen: one placed by `estimatedRowHeight`\n * could miss them when real heights differ from it, unmounting the focused\n * row all the same.\n *\n * Layout effects, so the window settles before paint rather than showing the\n * previous one for a frame — the same reason `useElementWidth` measures in a\n * layout effect.\n *\n * The measured heights reset whenever `rows` becomes a new reference\n * (filter, sort, groupBy, or `dataSource` itself changing) rather than\n * tracking each of those individually — the simplest rule that stays\n * correct, at the cost of one remeasurement on those already-big operations.\n * Keying heights by row id instead, to survive a pure reorder, is a\n * considered, deliberately deferred enhancement.\n */\nexport default function useRowVirtualizer({\n enabled,\n rows,\n scrollRef,\n bodyTableRef,\n estimatedRowHeight,\n overscan,\n}: UseRowVirtualizerOptions): RowVirtualizerApi {\n const [virtualizer, setVirtualizer] = useState<RowVirtualizer | null>(null);\n const instance = useRef<RowVirtualizer | null>(null);\n const rowCount = useRef(rows.length);\n const [rowWindow, setRowWindow] = useState(enabled ? NO_ROWS : ALL_ROWS);\n\n // While rendering, as state that follows a prop is adjusted: the render\n // that turns `enabled` back on must already draw every row.\n if (!enabled && rowWindow.kind !== \"allRows\") {\n setRowWindow(ALL_ROWS);\n }\n\n useLayoutEffect(() => {\n rowCount.current = rows.length;\n instance.current?.setRowCount(rows.length);\n instance.current?.resetHeights();\n }, [rows]);\n\n useLayoutEffect(() => {\n const element = scrollRef.current;\n if (!enabled || element === null) {\n return undefined;\n }\n const created = createRowVirtualizer(element, {\n estimatedRowHeight,\n overscan,\n onRange: (range) => {\n setRowWindow({ kind: \"range\", range });\n },\n });\n // Before its first window is drawn, which would otherwise be empty, and\n // placed from the rows on screen rather than from estimated heights.\n created.setRowCount(rowCount.current);\n created.measureRows(mountedRows(bodyTableRef.current));\n instance.current = created;\n setVirtualizer(created);\n return () => {\n created.destroy();\n };\n }, [enabled, scrollRef, bodyTableRef, estimatedRowHeight, overscan]);\n\n const range = rangeOf(rowWindow, rows.length);\n return {\n startIndex: range.startIndex,\n endIndex: range.endIndex,\n offsetBefore: range.offsetBefore,\n offsetAfter: range.offsetAfter,\n measureRow: virtualizer?.measureRow ?? ignoreRow,\n scrollToIndex: (index, options) => {\n instance.current?.scrollToIndex(index, options);\n },\n };\n}\n","// React components will be exported from here. They consume the framework-agnostic logic in @gridkitjs/core.\nexport {\n DataGrid,\n type Borders,\n type CellSelectEvent,\n type CellSelectionChangeEvent,\n type ColumnDefinition,\n type ColumnSelectEvent,\n type ColumnSelectionChangeEvent,\n type ColumnsSelectEvent,\n type DataColumn,\n type DataGridApi,\n type DataGridProps,\n type DataMode,\n type EmptyTemplateContext,\n type GroupByBarVisibility,\n type HoverableConfig,\n type InfiniteScrollConfig,\n type PagerConfig,\n type PagerTemplateContext,\n type PaginationUnit,\n type ReactRenderSlots,\n type ResizeMode,\n type ResolvedColumn,\n type SelectedCell,\n type SelectedColumn,\n} from \"./DataGrid/DataGrid\";\n// Every core type a prop, a column definition, a callback or a `DataGridApi`\n// method names, and the entries those states are built from, so typing a grid,\n// its callbacks or a standalone template needs no import from core. The row\n// payloads name no node type of their own, so they come straight from core.\nexport type {\n AggregateFn,\n AggregateResults,\n AggregateSpec,\n AggregateState,\n BuiltInAggregate,\n CellSelectionMode,\n CellSelectionState,\n CellTemplateContext,\n ColumnAlignment,\n ColumnFilterMenuOptions,\n ColumnOrderEvent,\n ColumnOrderState,\n ColumnPin,\n ColumnPinningEvent,\n ColumnPinningState,\n ColumnResizeEvent,\n ColumnSizeDefaults,\n ColumnSizingState,\n ColumnSortEntry,\n ColumnSortEvent,\n ColumnSortState,\n ColumnType,\n ColumnVisibilityEvent,\n ColumnVisibilityState,\n ColumnWrapConfig,\n ContextMenuOpenChangeEvent,\n DisplayRow,\n ExportScalar,\n FieldPath,\n FilterChangeEvent,\n FilterEntry,\n FilterState,\n FooterTemplateContext,\n FormatLocale,\n GridCommand,\n GridCommandEvent,\n GridCommandTarget,\n GridContextMenuOptions,\n GridContextMenuRequest,\n GridContextMenuTarget,\n GridFilterMenuOptions,\n GridFocus,\n GridMessages,\n GridOptions,\n GridState,\n GridToolbarOptions,\n GroupAggregateDisplay,\n GroupByEntry,\n GroupByEvent,\n GroupByState,\n GroupExpansionEvent,\n GroupExpansionState,\n MenuEntry,\n PaginationChangeEvent,\n PaginationState,\n ResolvedGroupRow,\n ResolvedGroupSummaryRow,\n ResolvedRow,\n RowGroupPosition,\n RowPointerEvent,\n RowProps,\n RowSelectEvent,\n RowSelectionChangeEvent,\n RowsSelectEvent,\n SelectableConfig,\n SelectedCellRef,\n SelectionMode,\n SelectionState,\n SerializedGridState,\n SortDirection,\n ToolbarEntry,\n ToolbarItemAttributes,\n} from \"@gridkitjs/core\";\n\n// Re-exported for the same reason: saving `getState()` as JSON goes through it.\nexport { serializeGridState } from \"@gridkitjs/core\";\n\n// Reactive hooks for building custom UI outside the grid's own DOM, each\n// subscribing to `DataGridApi.subscribe` via `useSyncExternalStore`.\nexport { default as usePaginationState } from \"./DataGrid/hooks/usePaginationState\";\nexport type { PaginationStateApi } from \"./DataGrid/hooks/usePaginationState\";\nexport { default as useGroupByState } from \"./DataGrid/hooks/useGroupByState\";\nexport type { GroupByStateApi } from \"./DataGrid/hooks/useGroupByState\";\nexport { default as useColumnSortState } from \"./DataGrid/hooks/useColumnSortState\";\nexport { default as useSelectionState } from \"./DataGrid/hooks/useSelectionState\";\nexport type { SelectionStateApi } from \"./DataGrid/hooks/useSelectionState\";\nexport { default as useAggregateState } from \"./DataGrid/hooks/useAggregateState\";\nexport { default as useColumnSizingState } from \"./DataGrid/hooks/useColumnSizingState\";\nexport { default as useColumnOrderState } from \"./DataGrid/hooks/useColumnOrderState\";\nexport { default as useColumnVisibilityState } from \"./DataGrid/hooks/useColumnVisibilityState\";\nexport { default as useColumnPinningState } from \"./DataGrid/hooks/useColumnPinningState\";\nexport { default as useFilterState } from \"./DataGrid/hooks/useFilterState\";\nexport type { FilterStateApi } from \"./DataGrid/hooks/useFilterState\";\n\n// Re-exported so typing an export — its options, a writer of the app's own,\n// the file a writer gives — needs no import from core.\nexport type {\n ExportFile,\n ExportOptions,\n ExportWriter,\n GridExportOptions,\n} from \"@gridkitjs/core\";\n\n// Re-exported so typing the `print` option, or a call to `print`, needs no\n// import from core.\nexport type { PrintOptions } from \"@gridkitjs/core\";\n\n// The filter popup in its Excel-style form, spread into `DataGrid`:\n// `<DataGrid {...excelFilter} />`.\nexport { excelFilter } from \"@gridkitjs/core\";\n","import { useCallback, type RefObject } from \"react\";\nimport type { PaginationState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_PAGINATION: PaginationState = { pageIndex: 0, pageSize: 0 };\n\nexport interface PaginationStateApi {\n pagination: PaginationState;\n pageCount: number;\n goToPage: (pageIndex: number) => void;\n nextPage: () => void;\n previousPage: () => void;\n setPageSize: (pageSize: number) => void;\n}\n\n/**\n * Reactive pagination state read off a mounted `DataGrid`'s `ref`,\n * for building a pager entirely outside the grid's own DOM — a toolbar or\n * sidebar `pager.template` can't reach. Updates on every pagination change,\n * including the silent page-0 reset a filter/sort/group change triggers,\n * which carries no `onPaginationChange` of its own.\n *\n * Before the grid mounts, `pagination` reads `{ pageIndex: 0, pageSize: 0 }`\n * and `pageCount` reads `0`; the actions are no-ops until then.\n */\nexport default function usePaginationState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): PaginationStateApi {\n const pagination = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getPagination(), []),\n FALLBACK_PAGINATION,\n );\n const pageCount = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getPageCount(), []),\n 0,\n );\n\n return {\n pagination,\n pageCount,\n goToPage: (pageIndex) => {\n gridRef.current?.goToPage(pageIndex);\n },\n nextPage: () => {\n gridRef.current?.nextPage();\n },\n previousPage: () => {\n gridRef.current?.previousPage();\n },\n setPageSize: (pageSize) => {\n gridRef.current?.setPageSize(pageSize);\n },\n };\n}\n","import {\n useCallback,\n useEffect,\n useRef,\n useSyncExternalStore,\n type RefObject,\n} from \"react\";\nimport type { DataGridApi } from \"../DataGrid\";\n\n/**\n * `useSyncExternalStore`'s listener and the grid it is attached to: none\n * while the ref holds no grid, which can be long after the hook first\n * subscribes, a grid mounted once its data arrives.\n */\ntype Subscription<Row> =\n | { readonly kind: \"waiting\"; readonly listener: () => void }\n | {\n readonly kind: \"subscribed\";\n readonly listener: () => void;\n readonly api: DataGridApi<Row>;\n readonly unsubscribe: () => void;\n };\n\nfunction subscribeTo<Row>(\n api: DataGridApi<Row> | null,\n listener: () => void,\n): Subscription<Row> {\n return api === null\n ? { kind: \"waiting\", listener }\n : {\n kind: \"subscribed\",\n listener,\n api,\n unsubscribe: api.subscribe(listener),\n };\n}\n\nfunction unsubscribe<Row>(subscription: Subscription<Row> | null): void {\n if (subscription?.kind === \"subscribed\") {\n subscription.unsubscribe();\n }\n}\n\n/**\n * Shared `useSyncExternalStore` wiring behind every public `use*State` hook\n * in this folder. Not exported. `gridRef.current` is `null` until the grid\n * mounts, and a ref says nothing when it changes, so the grid it holds is\n * read again after every render of the hook's component: the listener moves\n * to a grid the ref has gained, lost or swapped since, and is called, as\n * that grid's state may differ from the last snapshot. Until there is one,\n * the hook returns `fallback`. The ref is `null` on the server and while\n * hydrating too, so `fallback` is the server snapshot.\n */\nexport default function useGridSnapshot<Row, T>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n getSnapshot: (api: DataGridApi<Row>) => T,\n fallback: T,\n): T {\n /** `null` while `useSyncExternalStore` has nothing subscribed. */\n const subscription = useRef<Subscription<Row> | null>(null);\n\n const subscribe = useCallback(\n (listener: () => void) => {\n subscription.current = subscribeTo(gridRef.current, listener);\n return () => {\n unsubscribe(subscription.current);\n subscription.current = null;\n };\n },\n [gridRef],\n );\n\n const snapshot = useSyncExternalStore(\n subscribe,\n () => {\n const api = gridRef.current;\n return api === null ? fallback : getSnapshot(api);\n },\n () => fallback,\n );\n\n // After `useSyncExternalStore`'s own effect, so its listener is held.\n useEffect(() => {\n const current = subscription.current;\n if (current === null) {\n return;\n }\n const api = gridRef.current;\n if (api === (current.kind === \"subscribed\" ? current.api : null)) {\n return;\n }\n unsubscribe(current);\n subscription.current = subscribeTo(api, current.listener);\n current.listener();\n });\n\n return snapshot;\n}\n","import { useCallback, type RefObject } from \"react\";\nimport {\n ALL_EXPANDED,\n type GroupByState,\n type GroupExpansionState,\n} from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_GROUP_BY: GroupByState = [];\nconst FALLBACK_EXPANSION: GroupExpansionState = ALL_EXPANDED;\n\nexport interface GroupByStateApi {\n groupBy: GroupByState;\n groupExpansion: GroupExpansionState;\n expandAllGroups: () => void;\n collapseAllGroups: () => void;\n}\n\n/**\n * Reactive group-by and group-expansion state read off a mounted\n * `DataGrid`'s `ref`, for a group-by bar or summary sidebar living\n * outside the grid's own DOM.\n *\n * The ref's `setGroupBy` and `setGroupExpansion` change the grouping and the\n * group expansion for a custom group-by UI; this hook carries only the\n * all-at-once expansion actions. A specific\n * group's own computed aggregates are read off `getDisplayRows()`'s\n * per-header `aggregates` field instead of a getter here — see\n * `useAggregateState` for the grand-total equivalent.\n *\n * Before the grid mounts, `groupBy` reads as empty, `groupExpansion` as\n * `ALL_EXPANDED`, and the actions are no-ops.\n */\nexport default function useGroupByState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): GroupByStateApi {\n const groupBy = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getGroupBy(), []),\n FALLBACK_GROUP_BY,\n );\n const groupExpansion = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getGroupExpansion(), []),\n FALLBACK_EXPANSION,\n );\n\n return {\n groupBy,\n groupExpansion,\n expandAllGroups: () => {\n gridRef.current?.expandAllGroups();\n },\n collapseAllGroups: () => {\n gridRef.current?.collapseAllGroups();\n },\n };\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnSortState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_SORT: ColumnSortState = [];\n\n/**\n * Reactive column-sort state read off a mounted `DataGrid`'s `ref`,\n * for a sort indicator living outside the grid's own DOM.\n *\n * Reads only; change the sort through the ref's `setColumnSort`, or hold it\n * yourself with the controlled `columnSort` prop.\n *\n * Before the grid mounts, reads as an empty array.\n */\nexport default function useColumnSortState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnSortState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnSort(), []),\n FALLBACK_SORT,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { CellSelectionState, SelectionState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_SELECTION: SelectionState = [];\nconst FALLBACK_CELL_SELECTION: CellSelectionState = { kind: \"none\" };\n\nexport interface SelectionStateApi {\n rowSelection: SelectionState;\n columnSelection: SelectionState;\n cellSelection: CellSelectionState;\n clearSelection: () => void;\n selectAllRows: () => void;\n}\n\n/**\n * Reactive row/column/cell selection state read off a mounted\n * `DataGrid`'s `ref`, for a \"N rows selected\" toolbar living\n * outside the grid's own DOM. One combined hook rather than three, matching\n * how `useGridSelection` already treats all three as one concern\n * internally.\n *\n * Before the grid mounts, the row/column fields read as empty arrays and\n * the cell field reads `{ kind: \"none\" }`; the actions are no-ops.\n */\nexport default function useSelectionState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): SelectionStateApi {\n const rowSelection = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getRowSelection(), []),\n FALLBACK_SELECTION,\n );\n const columnSelection = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnSelection(), []),\n FALLBACK_SELECTION,\n );\n const cellSelection = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getCellSelection(), []),\n FALLBACK_CELL_SELECTION,\n );\n\n return {\n rowSelection,\n columnSelection,\n cellSelection,\n clearSelection: () => {\n gridRef.current?.clearSelection();\n },\n selectAllRows: () => {\n gridRef.current?.selectAllRows();\n },\n };\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { AggregateResults } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_AGGREGATES: AggregateResults = new Map();\n\n/**\n * Reactive grand-total aggregate results read off a mounted\n * `DataGrid`'s `ref`, for a summary footer or bar living outside\n * the grid's own DOM — mirroring the built-in one the grid renders itself.\n *\n * Read-only: `getAggregates` is already read-only on `DataGridApi`, computed\n * over the whole filtered/sorted dataset rather than driven by any action.\n * A specific group's own subtotal is read off `getDisplayRows()`'s\n * per-header `aggregates` field instead — see `useGroupByState`.\n *\n * Before the grid mounts, reads as an empty map.\n */\nexport default function useAggregateState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): AggregateResults {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getAggregates(), []),\n FALLBACK_AGGREGATES,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnSizingState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_SIZING: ColumnSizingState = {};\n\n/**\n * Reactive column-sizing state read off a mounted `DataGrid`'s\n * `ref`. Reads only; change the widths through the ref's `setColumnSizing`,\n * or hold them yourself with the controlled `columnSizing` prop.\n *\n * Before the grid mounts, reads as an empty object.\n */\nexport default function useColumnSizingState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnSizingState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnSizing(), []),\n FALLBACK_SIZING,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnOrderState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_ORDER: ColumnOrderState = [];\n\n/**\n * Reactive column-order state read off a mounted `DataGrid`'s\n * `ref`. Reads only; change the order through the ref's `setColumnOrder`,\n * or hold it yourself with the controlled `columnOrder` prop.\n *\n * Before the grid mounts, reads as an empty array.\n */\nexport default function useColumnOrderState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnOrderState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnOrder(), []),\n FALLBACK_ORDER,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnVisibilityState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_VISIBILITY: ColumnVisibilityState = {};\n\n/**\n * Reactive column-visibility state read off a mounted `DataGrid`'s `ref` —\n * the columns shown or hidden since it mounted, keyed by id. Read-only:\n * change it through the ref's `showColumns`/`hideColumns`. A column absent\n * from it follows its definition's `hidden`.\n *\n * Before the grid mounts, reads as an empty object.\n */\nexport default function useColumnVisibilityState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnVisibilityState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnVisibility(), []),\n FALLBACK_VISIBILITY,\n );\n}\n","import { useCallback, type RefObject } from \"react\";\nimport type { ColumnPinningState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nconst FALLBACK_PINNING: ColumnPinningState = {};\n\n/**\n * Reactive column-pinning state read off a mounted `DataGrid`'s `ref` — the\n * columns pinned or unpinned since it mounted, keyed by id. Read-only:\n * change it through the ref's `pinColumn`/`setColumnPinning`. A column\n * absent from it follows its definition's `pinned`.\n *\n * Before the grid mounts, reads as an empty object.\n */\nexport default function useColumnPinningState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): ColumnPinningState {\n return useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getColumnPinning(), []),\n FALLBACK_PINNING,\n );\n}\n","import { useCallback, useState, type RefObject } from \"react\";\nimport type { FilterState } from \"@gridkitjs/core\";\nimport type { DataGridApi } from \"../DataGrid\";\nimport useGridSnapshot from \"./useGridSnapshot\";\n\nexport interface FilterStateApi<Row> {\n filter: FilterState<Row>;\n setFilter: (filter: FilterState<Row>) => void;\n}\n\n/**\n * Reactive filter state read off a mounted `DataGrid`'s `ref`, for a filter\n * bar or search box living outside the grid's own DOM, which sees every change\n * however it was made — the toolbar's search box included. `setFilter`\n * replaces the whole filter and sends the grid back to its first page.\n *\n * Before the grid mounts, `filter` reads as an empty array and `setFilter`\n * is a no-op.\n */\nexport default function useFilterState<Row>(\n gridRef: RefObject<DataGridApi<Row> | null>,\n): FilterStateApi<Row> {\n // Held per hook rather than as one module constant: a filter is typed by\n // its row, through a predicate's parameter, so one empty array cannot\n // stand in for every `Row`. Either way it must keep its identity.\n const [fallback] = useState<FilterState<Row>>(() => []);\n const filter = useGridSnapshot(\n gridRef,\n useCallback((api: DataGridApi<Row>) => api.getFilter(), []),\n fallback,\n );\n\n return {\n filter,\n setFilter: (next) => {\n gridRef.current?.setFilter(next);\n },\n };\n}\n"],"mappings":";;;AAAA;AAAA,EACE,aAAAA;AAAA,EACA,SAAAC;AAAA,EACA,uBAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,OAIK;AACP;AAAA,EACE,eAAAC;AAAA,EACA,2BAAAC;AAAA,EACA,oBAAAC;AAAA,EACA;AAAA,EACA;AAAA,OAyCK;AACP;AAAA,EACE;AAAA,EACA,gBAAAC;AAAA,EACA;AAAA,OACK;;;AC/CC;AAJO,SAAR,aAAmC,EAAE,QAAQ,GAA2B;AAC7E,SACE,oBAAC,cACE,kBAAQ,IAAI,CAAC,UACZ,oBAAC,SAAmB,OAAO,EAAE,OAAO,MAAM,MAAM,KAAtC,MAAM,EAAmC,CACpD,GACH;AAEJ;;;ACnBA,SAAS,oBAAoB;AAC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C,IAAM,mBAAuC,CAAC;AAU/B,SAAR,sBACL,SACoB;AACpB,SAAO;AAAA,IACL;AAAA,IACAC,cAAY,CAAC,QAA0B,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAAA,IACjE;AAAA,EACF;AACF;;;ACvBA,SAAS,eAAAC,eAAa,YAAAC,kBAAgC;AAmBvC,SAAR,eACL,SACqB;AAIrB,QAAM,CAAC,QAAQ,IAAIC,WAA2B,MAAM,CAAC,CAAC;AACtD,QAAM,SAAS;AAAA,IACb;AAAA,IACAC,cAAY,CAAC,QAA0B,IAAI,UAAU,GAAG,CAAC,CAAC;AAAA,IAC1D;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,WAAW,CAAC,SAAS;AACnB,cAAQ,SAAS,UAAU,IAAI;AAAA,IACjC;AAAA,EACF;AACF;;;AXuGA,SAAS,mBAAmB;","names":["useEffect","useId","useImperativeHandle","useMemo","useRef","useState","headerFocus","resolveColumnHeaderText","resolveColumnPin","pinnedWidths","jsx","jsx","jsxs","useMemo","useState","intentOf","writingDirection","jsx","jsx","jsxs","memo","jsx","jsxs","memo","memo","jsx","memo","jsx","jsxs","useMemo","useState","intentOf","jsx","jsx","jsx","jsxs","createPortal","resolveColumnLabel","inlineStep","writingDirection","useLayoutEffect","useRef","useState","useEffect","useState","useRef","useLayoutEffect","jsx","jsxs","resolveColumnLabel","inlineStep","writingDirection","createPortal","useMemo","runCommand","useRef","useRef","useRef","document","useMemo","writeClipboard","document","runCommand","useLayoutEffect","useRef","useState","useLayoutEffect","useRef","createPortal","writingDirection","jsx","writingDirection","useRef","useLayoutEffect","createPortal","jsx","jsxs","ChevronLeftIcon","ChevronRightIcon","Fragment","jsx","jsxs","isItem","ChevronRightIcon","useRef","useState","useLayoutEffect","jsx","useEffect","useLayoutEffect","useRef","bodyFocus","headerFocus","bodyCellFrom","bodyRowFrom","findBodyRow","groupRowFrom","writingDirection","useRef","useLayoutEffect","useEffect","useCallback","useLayoutEffect","useRef","useState","CLOSED","useRef","useLayoutEffect","useRef","useState","Fragment","jsx","jsxs","useEffect","useRef","resolveMenu","resolveColumnFilterMenu","useImperativeHandle","useLayoutEffect","useMemo","useReducer","useRef","useState","draftToFilter","filterDraftChanged","useLayoutEffect","useRef","useState","CLOSED","useState","useRef","useLayoutEffect","Fragment","jsx","jsxs","ChevronRightIcon","Fragment","useLayoutEffect","useRef","conditionsFromRows","filterDraftChanged","filterEditorReducer","jsx","jsxs","describeColumnFilter","initialFilterEditorDraft","showsAlike","jsx","jsxs","useRef","filterEditorReducer","filterDraftChanged","conditionsFromRows","useLayoutEffect","Fragment","useLayoutEffect","useRef","useState","Fragment","jsx","jsxs","useRef","useState","useLayoutEffect","Fragment","jsx","jsxs","useReducer","useState","useRef","useMemo","useLayoutEffect","useImperativeHandle","filterDraftChanged","draftToFilter","ChevronLeftIcon","jsx","jsxs","useRef","resolveColumnFilterMenu","useEffect","resolveMenu","useEffect","useRef","useState","useState","NO_ROWS","jsx","useRef","resolveColumnFilterMenu","useRef","writingDirection","headerCell","useRef","writingDirection","useLayoutEffect","useRef","Fragment","jsx","jsxs","useEffect","useRef","useState","jsx","useState","useRef","useEffect","useLayoutEffect","useRef","useState","jsx","jsxs","useRef","useLayoutEffect","resolveKeyboardDropTarget","resolveKeyboardDropTarget","useState","useState","useLayoutEffect","useState","useLayoutEffect","useState","useState","useSyncExternalStore","useEffect","useRef","useCallback","useLayoutEffect","useRef","useLayoutEffect","useRef","useState","bodyRowFrom","createRowVirtualizer","NO_ROWS","range","jsx","jsxs","useRef","useId","useMemo","useState","useEffect","resolveColumnHeaderText","resolveColumnPin","headerFocus","useImperativeHandle","pinnedWidths","useCallback","useCallback","useEffect","useRef","useSyncExternalStore","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useCallback","useState","useState","useCallback"]}
|