@gridkitjs/react 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/DataGrid/DataGrid.tsx","../src/DataGrid/components/GridHeader.tsx","../src/DataGrid/useGridNavigation.ts","../src/DataGrid/useGridSelection.ts","../src/DataGrid/components/GridRow.tsx","../src/DataGrid/components/GridBody.tsx","../src/DataGrid/useColumnDrag.ts","../src/DataGrid/useColumnResize.ts","../src/DataGrid/measureColumnContent.ts","../src/DataGrid/useColumnSort.ts","../src/DataGrid/useElementWidth.ts"],"sourcesContent":["import { useMemo, useRef, useState, type ReactNode } from \"react\";\nimport {\n applyColumnOrder,\n defineColumnsFromRows,\n fitColumnsToWidth,\n moveColumnBefore,\n resolveColumnWidths,\n resolveRowId,\n resolveShownRows,\n totalColumnWidth,\n type ColumnDefinition as CoreColumnDefinition,\n type ResolvedColumn as CoreResolvedColumn,\n type ColumnOrderEvent,\n type ColumnOrderState,\n type ColumnResizeEvent,\n type ColumnSizeDefaults,\n type ColumnSizingState,\n type ColumnSortEvent,\n type ColumnSortState,\n type FilterState,\n type ResolvedRow,\n type CellSelectionState,\n type SelectableConfig,\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} from \"@gridkitjs/core\";\nimport GridHeader from \"./components/GridHeader\";\nimport GridBody from \"./components/GridBody\";\nimport useColumnDrag, { type DropTarget } from \"./useColumnDrag\";\nimport useColumnResize from \"./useColumnResize\";\nimport useColumnSort from \"./useColumnSort\";\nimport useElementWidth from \"./useElementWidth\";\nimport useGridNavigation, { HEADER_ROW } from \"./useGridNavigation\";\nimport useGridSelection, { type SelectionCallbacks } from \"./useGridSelection\";\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/**\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>;\n\nexport type Borders = \"horizontal\" | \"vertical\" | \"all\" | \"none\";\n\n/**\n * How a column's width relates to the grid's.\n *\n * `\"fit\"` keeps the columns filling the grid: the space a column gives up is\n * handed to the others, and the space it takes comes out of them. `\"fixed\"`\n * lets every column keep its own width, so a resize moves one column and\n * nothing else, and the grid scrolls or leaves a gap accordingly.\n */\nexport type ResizeMode = \"fit\" | \"fixed\";\n\nexport interface HoverableConfig {\n rows?: boolean;\n columns?: boolean;\n cells?: boolean;\n}\n\nexport interface DataGridProps<Row> extends SelectionCallbacks<Row> {\n columns?: readonly ColumnDefinition<Row>[] | undefined;\n dataSource?: readonly Row[] | undefined;\n /**\n * A row's stable identity, for state keyed by it. Defaults to the row's\n * position, which is enough for a static grid but ties that state to where a\n * row sits rather than to the row — so anything sorting, filtering or paging\n * its data should give one.\n *\n * Called for every row on every change to `dataSource`, so it should be\n * cheap and stable; an inline arrow is fine, one that re-reads the data is\n * not.\n */\n getRowId?: ((row: Row, index: number) => string) | undefined;\n borders?: Borders | undefined;\n hoverable?: HoverableConfig | undefined;\n /**\n * Which parts of the grid the user may select, and how many of each —\n * `{ rows: \"multiple\", cells: \"single\" }`. A cell addresses one value, so it\n * has no `\"multiple\"`.\n *\n * Off by default, unlike `hoverable`: selection claims the click, which a\n * grid that only displays data should not do. Give `getRowId` alongside it\n * for data that sorts, filters or pages, or a selection follows the position\n * rather than the row.\n */\n selectable?: SelectableConfig | undefined;\n /** Row ids selected to start with, keyed as `getRowId` resolves them. Uncontrolled. */\n defaultRowSelection?: SelectionState | undefined;\n /** Column ids selected to start with. Uncontrolled. */\n defaultColumnSelection?: SelectionState | undefined;\n /** The cell selected to start with. Uncontrolled. */\n defaultCellSelection?: CellSelectionState | undefined;\n /** Whether columns can be dragged wider, unless a column says otherwise. */\n resizableColumns?: boolean | undefined;\n /**\n * Whether columns can be dragged into a new position, unless a column says\n * otherwise. Turning it off leaves an order the user already made in place.\n */\n reorderableColumns?: boolean | undefined;\n /**\n * Whether columns fill the grid's width or sit at their own. Defaults to\n * `\"fit\"`, under which columns the user has sized keep their width and the\n * rest share what is left.\n */\n resizeMode?: ResizeMode | undefined;\n /** Column widths to start from, keyed by column id. Uncontrolled. */\n defaultColumnSizing?: ColumnSizingState | undefined;\n /**\n * Column ids in the order to start in. Uncontrolled, and partial: ids it\n * omits keep their position among `columns` and follow those it lists.\n */\n defaultColumnOrder?: ColumnOrderState | undefined;\n /**\n * Sizes applied to columns that do not set their own — the width they start\n * at and the bounds they may be resized between. Distinct from\n * `defaultColumnSizing`, which sets specific columns' starting widths.\n */\n columnSizeDefaults?: Partial<ColumnSizeDefaults> | undefined;\n /**\n * Called as the user resizes a column. Fires continuously with\n * `phase: \"move\"` and once on release with `phase: \"end\"` — the latter being\n * the one to persist. Auto-fit does not call it; it reports user intent only.\n */\n onColumnResize?: ((event: ColumnResizeEvent) => void) | undefined;\n /**\n * Called once when the user drops a column somewhere new. A drop that leaves\n * the order as it was does not call it.\n */\n onColumnOrderChange?: ((event: ColumnOrderEvent) => void) | undefined;\n /**\n * Whether columns can be sorted by clicking their header toggle, unless a\n * column says otherwise. Shift-click stacks a column into the sort instead\n * of replacing it.\n */\n sortableColumns?: boolean | undefined;\n /** The sort to start with, in priority order. Uncontrolled. */\n defaultColumnSort?: ColumnSortState | undefined;\n /**\n * Called once when the user changes the sort — a toggle, a stack, or a\n * clear back to \"none\".\n */\n onColumnSortChange?: ((event: ColumnSortEvent) => void) | undefined;\n /** The filter to start with — every applied entry, ANDed together. Uncontrolled. */\n defaultFilter?: FilterState<Row> | undefined;\n /**\n * The grid's accessible name, announced when it takes focus. A grid without\n * one is read only as \"grid\", which says nothing about which grid.\n */\n label?: string | undefined;\n /**\n * The id of an element naming the grid, for a heading already on the page.\n * Takes precedence over `label`, as `aria-labelledby` does.\n */\n labelledBy?: string | undefined;\n}\n\nexport function DataGridComponent<Row>({\n dataSource,\n columns,\n getRowId,\n borders,\n hoverable,\n selectable,\n defaultRowSelection,\n defaultColumnSelection,\n defaultCellSelection,\n resizableColumns = false,\n reorderableColumns = false,\n resizeMode = \"fit\",\n defaultColumnSizing,\n defaultColumnOrder,\n columnSizeDefaults,\n onColumnResize,\n onColumnOrderChange,\n sortableColumns = false,\n defaultColumnSort,\n onColumnSortChange,\n defaultFilter,\n label,\n labelledBy,\n ...callbacks\n}: DataGridProps<Row>) {\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 tableRef = useRef<HTMLTableElement>(null);\n const viewportWidth = useElementWidth(viewportRef, resizeMode === \"fit\");\n const [sizing, setSizing] = useState<ColumnSizingState>(\n defaultColumnSizing ?? {},\n );\n const [order, setOrder] = useState<ColumnOrderState>(\n defaultColumnOrder ?? [],\n );\n const [sort, setSort] = useState<ColumnSortState>(defaultColumnSort ?? []);\n const [filter] = useState<FilterState<Row>>(defaultFilter ?? []);\n const [announcement, setAnnouncement] = useState(\"\");\n const [rowSelection, setRowSelection] = useState<SelectionState>(\n defaultRowSelection ?? [],\n );\n const [columnSelection, setColumnSelection] = useState<SelectionState>(\n defaultColumnSelection ?? [],\n );\n const [cellSelection, setCellSelection] = useState<CellSelectionState>(\n defaultCellSelection ?? null,\n );\n\n /**\n * The rows as rendered, each carrying the id everything downstream keys it\n * by. Resolved once here rather than per consumer so a row's id cannot come\n * out differently in two places — the same reason `resolveColumnWidths` runs\n * once ahead of the header and the body.\n *\n * An array rather than a map keyed by id: two rows given the same id is a\n * caller's mistake, and one that should render twice and look wrong rather\n * than silently lose a row.\n */\n const rows = useMemo<readonly ResolvedRow<Row>[]>(\n () =>\n dataSource?.map((row, rowIndex) => ({\n rowId: resolveRowId(row, rowIndex, getRowId),\n row,\n rowIndex,\n })) ?? [],\n [dataSource, getRowId],\n );\n\n const definedColumns = useMemo<readonly ColumnDefinition<Row>[]>(() => {\n if (columns && columns.length !== 0) return columns;\n if (dataSource && dataSource.length > 0)\n return defineColumnsFromRows(dataSource);\n return [];\n }, [columns, dataSource]);\n\n /**\n * Ahead of sizing, so everything downstream reads one already-ordered list\n * and no part of the grid has to know a reorder happened.\n */\n const orderedColumns = useMemo(\n () => applyColumnOrder(definedColumns, order),\n [definedColumns, order],\n );\n\n /**\n * Auto-fit is a derivation rather than a write back into `sizing`, so that a\n * `width` set in a column definition is never overwritten and the effect\n * cannot chase its own output. `\"fixed\"` is then simply the absence of it.\n */\n const resolved = useMemo(() => {\n const widths = resolveColumnWidths(orderedColumns, sizing, {\n sizes: columnSizeDefaults,\n resizable: resizableColumns,\n reorderable: reorderableColumns,\n });\n return resizeMode === \"fit\" && viewportWidth !== null\n ? fitColumnsToWidth(widths, viewportWidth, columnSizeDefaults)\n : widths;\n }, [\n orderedColumns,\n sizing,\n resizeMode,\n viewportWidth,\n columnSizeDefaults,\n resizableColumns,\n reorderableColumns,\n ]);\n\n /**\n * `rows`, filtered then sorted — needs `resolved` for each column's\n * `field` and `type`, so it runs after sizing rather than alongside\n * `rows` itself. Everything downstream that renders or interacts with row\n * order and membership reads this rather than `rows`, so what the user\n * sees, filters, sorts, and clicks all agree.\n */\n const shownRows = useMemo(\n () => resolveShownRows(rows, filter, sort, resolved),\n [rows, filter, sort, resolved],\n );\n\n /**\n * What a column is called in an announcement. `label` carries whatever a\n * `headerTemplate` returned, which need not be text at all, so the field\n * path stands in whenever it is not.\n */\n function columnName(columnId: string): string {\n const entry = resolved.find((candidate) => candidate.id === columnId);\n if (entry === undefined) {\n return columnId;\n }\n return typeof entry.label === \"string\" ? entry.label : entry.column.field;\n }\n\n /**\n * Reports a change no visual cue can carry to a screen reader. Held as state\n * rather than written to the DOM directly so React owns the one element the\n * live region watches.\n */\n function announce(message: string): void {\n setAnnouncement(message);\n }\n\n /**\n * Wrapped rather than announced from the resize hook, which reports the\n * continuous `\"move\"` phase as well — a live region given every frame of a\n * drag says nothing an assistive technology can keep up with.\n */\n function handleColumnResize(event: ColumnResizeEvent): void {\n onColumnResize?.(event);\n if (event.phase === \"end\") {\n announce(\n `${columnName(event.columnId)}, ${String(Math.round(event.width))} pixels wide`,\n );\n }\n }\n\n const resize = useColumnResize<Row>({\n tableRef,\n sizing,\n setSizing,\n columnSizeDefaults,\n onColumnResize: handleColumnResize,\n });\n\n const nav = useGridNavigation({\n tableRef,\n rowCount: shownRows.length,\n columnCount: resolved.length,\n });\n\n /**\n * The ids as displayed, which a drop is expressed against — the order state\n * starts empty and may name only some columns, so moving against it directly\n * would have nothing to rearrange.\n */\n const displayedIds = useMemo(\n () => orderedColumns.map((column) => column.id ?? column.field),\n [orderedColumns],\n );\n\n /**\n * The one place a drop is applied. A second drop zone — a grouping bar above\n * the header — turns this into a switch on `target.kind` and touches nothing\n * else.\n */\n function handleDrop(target: DropTarget, movedId: string): void {\n const next = moveColumnBefore(displayedIds, movedId, target.beforeId);\n // `moveColumnBefore` hands back the same reference for a move that changes\n // nothing, so a drop in place neither renders nor reports.\n if (next === displayedIds) {\n return;\n }\n const position = next.indexOf(movedId);\n setOrder(next);\n onColumnOrderChange?.({ columnId: movedId, order: next });\n announce(\n `${columnName(movedId)}, column ${String(position + 1)} of ${String(next.length)}`,\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(HEADER_ROW, position);\n }\n\n const drag = useColumnDrag<Row>({ order: displayedIds, onDrop: handleDrop });\n\n /**\n * Wrapped the same way `handleColumnResize`/`handleDrop` are, so a toggle,\n * a stack, or a clear back to \"none\" each get their own announcement.\n */\n function handleColumnSortChange(event: ColumnSortEvent): void {\n onColumnSortChange?.(event);\n const entry = event.sort.find(\n (candidate) => candidate.columnId === event.columnId,\n );\n if (entry === undefined) {\n announce(`${columnName(event.columnId)}, sort cleared`);\n return;\n }\n const direction = entry.direction === \"asc\" ? \"ascending\" : \"descending\";\n announce(\n event.sort.length > 1\n ? `${columnName(event.columnId)} sorted ${direction}, key ${String(event.sort.indexOf(entry) + 1)} of ${String(event.sort.length)}`\n : `${columnName(event.columnId)} sorted ${direction}`,\n );\n }\n\n const columnSort = useColumnSort<Row>({\n sort,\n setSort,\n onColumnSortChange: handleColumnSortChange,\n });\n\n const selection = useGridSelection<Row>({\n rows: shownRows,\n columns: resolved,\n selectable,\n rowSelection,\n setRowSelection,\n columnSelection,\n setColumnSelection,\n cellSelection,\n setCellSelection,\n callbacks,\n announce,\n });\n\n const multiselectable =\n selection.rowMode === \"multiple\" || selection.columnMode === \"multiple\";\n\n return (\n <div className=\"gridkit-data-grid-viewport\" ref={viewportRef}>\n <table\n ref={tableRef}\n /*\n * `role=\"grid\"` rather than the table's own semantics: it is what makes\n * the arrow keys a navigation the grid owns, and later what lets a row\n * report whether it is selected. It obliges the single tab stop\n * `useGridNavigation` keeps.\n */\n role=\"grid\"\n // The header is a row too, and counted from one.\n aria-rowcount={shownRows.length + 1}\n aria-colcount={resolved.length}\n {...(multiselectable && { \"aria-multiselectable\": true })}\n {...(labelledBy !== undefined && { \"aria-labelledby\": labelledBy })}\n {...(labelledBy === undefined &&\n label !== undefined && { \"aria-label\": label })}\n onKeyDown={(event) => {\n /*\n * The two keys that address the grid rather than a cell, and so are\n * caught here where everything bubbles to rather than in each of\n * them.\n */\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 // 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(resolved) }}\n className={[\n \"gridkit-data-grid\",\n borders ? `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 ? \"\" : \"no-hover-rows\",\n hoverColumns ? \"\" : \"no-hover-columns\",\n hoverCells ? \"\" : \"no-hover-cells\",\n selection.rowMode === false ? \"\" : \"selectable-rows\",\n selection.columnMode === false ? \"\" : \"selectable-columns\",\n selection.cellMode === false ? \"\" : \"selectable-cells\",\n ]\n .filter(Boolean)\n .join(\" \")}\n >\n <colgroup>\n {resolved.map((entry) => (\n <col key={entry.id} style={{ width: entry.width }} />\n ))}\n </colgroup>\n <GridHeader<Row>\n columns={resolved}\n resize={resize}\n drag={drag}\n sort={columnSort}\n sortableColumns={sortableColumns}\n nav={nav}\n selection={selection}\n />\n <GridBody<Row>\n columns={resolved}\n rows={shownRows}\n activeColumnId={resize.activeColumnId}\n nav={nav}\n selection={selection}\n />\n </table>\n {/*\n * Outside the table, which admits no `div`, and polite so it waits for a\n * pause rather than cutting across what the user is already hearing.\n */}\n <div className=\"gridkit-sr-only\" role=\"status\" aria-live=\"polite\">\n {announcement}\n </div>\n </div>\n );\n}\n","import { createPortal } from \"react-dom\";\nimport { KEYBOARD_STEP } from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport type { ColumnDragApi } from \"../useColumnDrag\";\nimport type { ColumnResizeApi } from \"../useColumnResize\";\nimport type { ColumnSortApi } from \"../useColumnSort\";\nimport { HEADER_ROW, type GridNavigationApi } from \"../useGridNavigation\";\nimport { intentOf, type GridSelectionApi } from \"../useGridSelection\";\n\ninterface GridHeaderProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n resize: ColumnResizeApi<Row>;\n drag: ColumnDragApi<Row>;\n sort: ColumnSortApi<Row>;\n sortableColumns: boolean;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\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 */\nfunction ChevronsUpDownIcon() {\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 <path d=\"m7 15 5 5 5-5\" />\n <path d=\"m7 9 5-5 5 5\" />\n </svg>\n );\n}\n\nfunction ChevronUpIcon() {\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 <path d=\"m18 15-6-6-6 6\" />\n </svg>\n );\n}\n\nexport default function GridHeader<Row>({\n columns,\n resize,\n drag,\n sort,\n sortableColumns,\n nav,\n selection,\n}: GridHeaderProps<Row>) {\n const { beforeId } = drag.dropTarget ?? {};\n const draggedEntry =\n columns.find((entry) => entry.id === drag.draggedColumnId) ?? null;\n\n return (\n <thead>\n <tr className=\"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 /**\n * Drawn on the gap's own edge, so the one gap between two columns is\n * marked once. No guard against the dragged column: the hook reports\n * only gaps that would move it.\n */\n const dropBefore = beforeId !== undefined && beforeId === entry.id;\n const dropAfter = beforeId === null && index === columns.length - 1;\n const selected = selection.selectedColumnIds.has(entry.id);\n const sortable = column.sortable ?? sortableColumns;\n const sortDirection = sort.directionFor(entry.id);\n const sortPriority = sort.priorityFor(entry.id);\n\n /**\n * Announced so the keys are discoverable, since neither is a\n * convention a user would try unprompted.\n */\n const shortcuts = [\n entry.reorderable ? \"Control+ArrowLeft Control+ArrowRight\" : \"\",\n entry.resizable ? \"Alt+ArrowLeft Alt+ArrowRight\" : \"\",\n sortable ? \"Alt+ArrowUp\" : \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n return (\n <th\n key={entry.id}\n scope=\"col\"\n data-gridkit-column={entry.id}\n aria-colindex={index + 1}\n tabIndex={nav.tabIndexFor(HEADER_ROW, index)}\n {...(selection.columnMode !== false && {\n \"aria-selected\": selected,\n })}\n onFocus={() => {\n nav.focusCell(HEADER_ROW, 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()) {\n return;\n }\n if (\n event.target instanceof Element &&\n (event.target.closest(\".header-resize-handle\") !== null ||\n event.target.closest(\".header-sort-toggle\") !== null)\n ) {\n return;\n }\n selection.selectColumn(entry.id, intentOf(event));\n }}\n onKeyDown={(event) => {\n const horizontal =\n event.key === \"ArrowLeft\" || event.key === \"ArrowRight\";\n const direction = event.key === \"ArrowLeft\" ? -1 : 1;\n\n if (horizontal && event.ctrlKey && entry.reorderable) {\n event.preventDefault();\n drag.moveByKeyboard(entry, direction);\n return;\n }\n if (horizontal && event.altKey && entry.resizable) {\n event.preventDefault();\n resize.nudge(entry, direction * KEYBOARD_STEP);\n return;\n }\n if (event.key === \"ArrowUp\" && event.altKey && sortable) {\n event.preventDefault();\n sort.toggle(entry, { shiftKey: event.shiftKey });\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({\n ctrlKey: event.key === \" \" || event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n }),\n );\n return;\n }\n nav.onKeyDown(event);\n }}\n className={[\n \"header-cell\",\n entry.reorderable ? \"is-reorderable\" : \"\",\n selected ? \"is-selected\" : \"\",\n resizing ? \"is-resizing\" : \"\",\n dragging ? \"is-dragging\" : \"\",\n dropBefore ? \"is-drop-before\" : \"\",\n dropAfter ? \"is-drop-after\" : \"\",\n column.wrap?.header ? \"is-wrapped\" : \"\",\n column.headerClassName ?? \"\",\n ]\n .filter(Boolean)\n .join(\" \")}\n {...(shortcuts !== \"\" && { \"aria-keyshortcuts\": shortcuts })}\n {...(sortable &&\n sortDirection !== null && {\n \"aria-sort\":\n sortDirection === \"asc\" ? \"ascending\" : \"descending\",\n })}\n {...(entry.reorderable && {\n onPointerDown: (event) => {\n drag.startDrag(entry, event);\n },\n })}\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={[\n \"header-sort-toggle\",\n sortDirection !== null ? `is-sorted-${sortDirection}` : \"\",\n ]\n .filter(Boolean)\n .join(\" \")}\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 * `setPointerCapture` 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 sort.toggle(entry, { shiftKey: event.shiftKey });\n }}\n >\n {sortDirection === null ? (\n <ChevronsUpDownIcon />\n ) : (\n <ChevronUpIcon />\n )}\n {sortPriority !== null && sortPriority > 1 && (\n <span className=\"header-sort-priority\">{sortPriority}</span>\n )}\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=\"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 header-cell 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","import {\n useEffect,\n useRef,\n useState,\n type KeyboardEvent as ReactKeyboardEvent,\n type RefObject,\n} from \"react\";\n\n/**\n * The header's row index. One coordinate space covers the header and the body\n * so that arrowing up out of the first row reaches the header without a case\n * of its own, and every other move is plain arithmetic.\n */\nexport const HEADER_ROW = -1;\n\n/** Rows a page key moves when the viewport cannot be measured. */\nconst FALLBACK_PAGE = 10;\n\n/** The cell the grid's single tab stop sits on. */\nexport interface GridFocus {\n readonly rowIndex: number;\n readonly columnIndex: number;\n}\n\ninterface UseGridNavigationOptions {\n tableRef: RefObject<HTMLTableElement | null>;\n rowCount: number;\n columnCount: number;\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: (rowIndex: number, columnIndex: number) => 0 | -1;\n /** Moves the tab stop, and the browser's focus with it. */\n focusCell: (rowIndex: number, columnIndex: number) => void;\n /** Handles the navigation keys, leaving every other key to bubble. */\n onKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => void;\n}\n\n/**\n * Holds a coordinate inside the grid, so that a focus surviving a column\n * removal or a shorter page never leaves the grid with no tab stop at all —\n * which is a grid a keyboard cannot reach.\n */\nfunction clampFocus(\n focus: GridFocus,\n rowCount: number,\n columnCount: number,\n): GridFocus {\n return {\n rowIndex: Math.min(Math.max(focus.rowIndex, HEADER_ROW), rowCount - 1),\n columnIndex: Math.min(\n Math.max(focus.columnIndex, 0),\n Math.max(columnCount - 1, 0),\n ),\n };\n}\n\n/**\n * The cell at a coordinate, found through the table's own row and cell\n * collections rather than a selector.\n *\n * Ids can hold anything a consumer's data holds, and an attribute selector\n * built from one would have to escape it; positions need no quoting.\n */\nfunction cellAt(table: HTMLTableElement, focus: GridFocus): HTMLElement | null {\n const row =\n focus.rowIndex === HEADER_ROW\n ? (table.tHead?.rows[0] ?? null)\n : (table.tBodies[0]?.rows[focus.rowIndex] ?? null);\n return row?.cells[focus.columnIndex] ?? null;\n}\n\n/**\n * Moves one tab stop around the grid, which is what `role=\"grid\"` obliges:\n * arrow keys travel cell to cell and Tab passes the whole grid by.\n *\n * Separate from selection because focus and selection are different states — a\n * cell is focused while travelling before anything is selected, and every cell\n * of a range is selected without being focused. Navigation also has to work\n * with selection turned off entirely, so it cannot depend on it.\n */\nexport default function useGridNavigation({\n tableRef,\n rowCount,\n columnCount,\n}: UseGridNavigationOptions): GridNavigationApi {\n const [stored, setStored] = useState<GridFocus>({\n rowIndex: HEADER_ROW,\n columnIndex: 0,\n });\n\n /**\n * Clamped on the way out rather than written back, so that a coordinate\n * pushed out of range by a change to the data is restored when the data\n * comes back — and so the effect below cannot chase its own output.\n */\n const focus = clampFocus(stored, rowCount, columnCount);\n\n /**\n * Whether the browser's focus still has to be moved to match. Without it\n * every render would pull focus into the grid, including the first.\n */\n const pending = useRef(false);\n\n useEffect(() => {\n if (!pending.current) {\n return;\n }\n pending.current = false;\n const table = tableRef.current;\n if (table === null) {\n return;\n }\n cellAt(table, { rowIndex: focus.rowIndex, columnIndex: focus.columnIndex })\n // Focusing the cell the browser already sits on is a no-op, which is what\n // makes one method serve both a key press and a cell reporting a click.\n ?.focus();\n }, [tableRef, focus.rowIndex, focus.columnIndex]);\n\n /** How many rows fit the viewport, which is what a page key should move. */\n function pageSize(): number {\n const table = tableRef.current;\n const firstRow = table?.tBodies[0]?.rows[0];\n const viewport = table?.parentElement;\n if (\n firstRow === undefined ||\n viewport === null ||\n viewport === undefined ||\n firstRow.offsetHeight === 0\n ) {\n return FALLBACK_PAGE;\n }\n return Math.max(\n 1,\n Math.floor(viewport.clientHeight / firstRow.offsetHeight),\n );\n }\n\n function focusCell(rowIndex: number, columnIndex: number): void {\n const next = clampFocus({ rowIndex, columnIndex }, rowCount, columnCount);\n if (\n next.rowIndex === focus.rowIndex &&\n next.columnIndex === focus.columnIndex\n ) {\n return;\n }\n pending.current = true;\n setStored(next);\n }\n\n function tabIndexFor(rowIndex: number, columnIndex: number): 0 | -1 {\n return rowIndex === focus.rowIndex && columnIndex === focus.columnIndex\n ? 0\n : -1;\n }\n\n function onKeyDown(event: ReactKeyboardEvent<HTMLElement>): void {\n // Alt on an arrow resizes and Ctrl on one reorders; the header claims both\n // before this runs, and elsewhere they belong to the browser.\n if (event.altKey) {\n return;\n }\n\n const { rowIndex, columnIndex } = focus;\n let next: GridFocus;\n\n switch (event.key) {\n case \"ArrowLeft\":\n if (event.ctrlKey) return;\n next = { rowIndex, columnIndex: columnIndex - 1 };\n break;\n case \"ArrowRight\":\n if (event.ctrlKey) return;\n next = { rowIndex, columnIndex: columnIndex + 1 };\n break;\n case \"ArrowUp\":\n next = { rowIndex: rowIndex - 1, columnIndex };\n break;\n case \"ArrowDown\":\n next = { rowIndex: rowIndex + 1, columnIndex };\n break;\n // Ctrl takes Home and End to the grid's ends rather than the row's, which\n // is the one place Ctrl is navigation rather than reorder.\n case \"Home\":\n next = event.ctrlKey\n ? { rowIndex: HEADER_ROW, columnIndex: 0 }\n : { rowIndex, columnIndex: 0 };\n break;\n case \"End\":\n next = event.ctrlKey\n ? { rowIndex: rowCount - 1, columnIndex: columnCount - 1 }\n : { rowIndex, columnIndex: columnCount - 1 };\n break;\n case \"PageUp\":\n next = { rowIndex: rowIndex - pageSize(), columnIndex };\n break;\n case \"PageDown\":\n next = { rowIndex: rowIndex + pageSize(), columnIndex };\n break;\n default:\n return;\n }\n\n // Taken even when the move lands nowhere: an arrow at the last row would\n // otherwise scroll the page out from under the grid.\n event.preventDefault();\n focusCell(next.rowIndex, next.columnIndex);\n }\n\n // A new object each render, as the other hooks here return: the handlers\n // close over the focus they move from.\n return { focus, tabIndexFor, focusCell, onKeyDown };\n}\n","import { useMemo, useRef, type Dispatch, type SetStateAction } from \"react\";\nimport {\n accessDotted,\n clearSelection,\n diffSelection,\n selectAll,\n selectCell,\n selectOnly,\n selectRange,\n toggleCellSelection,\n toggleSelection,\n type CellSelectionMode,\n type CellSelectionState,\n type ResolvedRow,\n type SelectableConfig,\n type SelectedCellRef,\n type SelectionMode,\n type SelectionState,\n type RowSelectEvent,\n type RowSelectionChangeEvent,\n type RowsSelectEvent,\n} from \"@gridkitjs/core\";\nimport type {\n CellSelectEvent,\n CellSelectionChangeEvent,\n ColumnSelectEvent,\n ColumnSelectionChangeEvent,\n ColumnsSelectEvent,\n ResolvedColumn,\n SelectedCell,\n SelectedColumn,\n} from \"./DataGrid\";\n\n/**\n * What an interaction means for the selection, read off its modifiers once at\n * the boundary so that nothing downstream handles a raw event.\n */\nexport type SelectIntent = \"replace\" | \"toggle\" | \"range\";\n\n/** The intent a click or key press carries, by the modifiers held with it. */\nexport function intentOf(event: {\n ctrlKey: boolean;\n metaKey: boolean;\n shiftKey: boolean;\n}): SelectIntent {\n if (event.shiftKey) {\n return \"range\";\n }\n // Cmd on a Mac is Ctrl everywhere else, and both mean the same thing here.\n return event.ctrlKey || event.metaKey ? \"toggle\" : \"replace\";\n}\n\n/**\n * Reported as the user selects. Every one of these is fanned out from a single\n * diff of the transition it describes, so no two can disagree about what one\n * interaction did.\n */\nexport interface SelectionCallbacks<Row> {\n /** Called once per row newly selected. The last call names the last row. */\n onRowSelect?: ((event: RowSelectEvent<Row>) => void) | undefined;\n /** Called once with every row one interaction selected. */\n onRowsSelect?: ((event: RowsSelectEvent<Row>) => void) | undefined;\n onRowDeselect?: ((event: RowSelectEvent<Row>) => void) | undefined;\n onRowsDeselect?: ((event: RowsSelectEvent<Row>) => void) | undefined;\n /**\n * Called once per change with what it added, what it removed and everything\n * selected after it — the one to persist from.\n */\n onRowSelectionChange?:\n ((event: RowSelectionChangeEvent<Row>) => void) | undefined;\n onColumnSelect?: ((event: ColumnSelectEvent<Row>) => void) | undefined;\n onColumnsSelect?: ((event: ColumnsSelectEvent<Row>) => void) | undefined;\n onColumnDeselect?: ((event: ColumnSelectEvent<Row>) => void) | undefined;\n onColumnsDeselect?: ((event: ColumnsSelectEvent<Row>) => void) | undefined;\n onColumnSelectionChange?:\n ((event: ColumnSelectionChangeEvent<Row>) => void) | undefined;\n onCellSelect?: ((event: CellSelectEvent<Row>) => void) | undefined;\n onCellDeselect?: ((event: CellSelectEvent<Row>) => void) | undefined;\n onCellSelectionChange?:\n ((event: CellSelectionChangeEvent<Row>) => void) | undefined;\n}\n\ninterface UseGridSelectionOptions<Row> {\n rows: readonly ResolvedRow<Row>[];\n columns: readonly ResolvedColumn<Row>[];\n selectable: SelectableConfig | undefined;\n rowSelection: SelectionState;\n setRowSelection: Dispatch<SetStateAction<SelectionState>>;\n columnSelection: SelectionState;\n setColumnSelection: Dispatch<SetStateAction<SelectionState>>;\n cellSelection: CellSelectionState;\n setCellSelection: Dispatch<SetStateAction<CellSelectionState>>;\n callbacks: SelectionCallbacks<Row>;\n announce: (message: string) => void;\n}\n\nexport interface GridSelectionApi {\n rowMode: SelectionMode;\n columnMode: SelectionMode;\n cellMode: CellSelectionMode;\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 transform an intent asks for. A function rather than a branch inside\n * each caller, so a row and a column cannot come to mean different things by\n * the same click.\n */\nfunction applyIntent(\n selection: SelectionState,\n orderedIds: readonly string[],\n anchorId: string | null,\n id: string,\n intent: SelectIntent,\n mode: SelectionMode,\n): SelectionState {\n switch (intent) {\n case \"toggle\":\n return toggleSelection(selection, id, mode);\n // A range with no anchor yet spans from the id to itself, which is the\n // plain click a first Shift-click may as well be.\n case \"range\":\n return selectRange(selection, orderedIds, anchorId ?? id, id, mode);\n default:\n return selectOnly(selection, id, mode);\n }\n}\n\nfunction countMessage(count: number, noun: string): string {\n if (count === 0) {\n return `No ${noun}s selected`;\n }\n return count === 1\n ? `1 ${noun} selected`\n : `${String(count)} ${noun}s selected`;\n}\n\n/**\n * Turns an intent against a row, column or cell into the selection it implies,\n * and reports what changed.\n *\n * Holds no state of its own: the three selections live in `DataGrid` beside\n * the sizing and the order, so that a ref exposing them later, or a feature\n * reading them, finds them in one place.\n */\nexport default function useGridSelection<Row>({\n rows,\n columns,\n selectable,\n rowSelection,\n setRowSelection,\n columnSelection,\n setColumnSelection,\n cellSelection,\n setCellSelection,\n callbacks,\n announce,\n}: UseGridSelectionOptions<Row>): GridSelectionApi {\n const rowMode = selectable?.rows ?? false;\n const columnMode = selectable?.columns ?? false;\n const cellMode = selectable?.cells ?? false;\n\n const rowsById = useMemo(\n () => new Map(rows.map((entry) => [entry.rowId, entry])),\n [rows],\n );\n const rowIds = useMemo(() => rows.map((entry) => entry.rowId), [rows]);\n const columnIds = useMemo(() => columns.map((entry) => entry.id), [columns]);\n\n const selectedRowIds = useMemo(() => new Set(rowSelection), [rowSelection]);\n const selectedColumnIds = useMemo(\n () => new Set(columnSelection),\n [columnSelection],\n );\n\n /**\n * Where a range is measured from: the last row or column selected by\n * anything but a range, so that repeated Shift-clicks re-draw one span\n * instead of walking the anchor along with them.\n */\n const rowAnchor = useRef<string | null>(null);\n const columnAnchor = useRef<string | null>(null);\n\n /**\n * Ids with no row behind them are dropped rather than reported: a selection\n * outlives a change to the data, so that filtering a row out and back leaves\n * it selected, and only what is on screen can be handed to a callback.\n */\n function resolveRows(ids: readonly string[]): readonly ResolvedRow<Row>[] {\n return ids.map((id) => rowsById.get(id)).filter((row) => row !== undefined);\n }\n\n function resolveColumns(\n ids: readonly string[],\n ): readonly SelectedColumn<Row>[] {\n return ids\n .map((id) => {\n const columnIndex = columns.findIndex((entry) => entry.id === id);\n const column = columns[columnIndex];\n return column === undefined\n ? undefined\n : { columnId: id, column, columnIndex };\n })\n .filter((column) => column !== undefined);\n }\n\n function resolveCell(ref: CellSelectionState): SelectedCell<Row> | null {\n if (ref === null) {\n return null;\n }\n const entry = rowsById.get(ref.rowId);\n const columnIndex = columns.findIndex(\n (candidate) => candidate.id === ref.columnId,\n );\n const column = columns[columnIndex];\n if (entry === undefined || column === undefined) {\n return null;\n }\n return {\n rowId: ref.rowId,\n columnId: ref.columnId,\n row: entry.row,\n column,\n rowIndex: entry.rowIndex,\n columnIndex,\n value: accessDotted(entry.row, column.column.field),\n };\n }\n\n /**\n * Announced only for a change touching more than one member. A single\n * selection is already carried by the focused row's own `aria-selected`, and\n * repeating it here would talk over that.\n */\n function announceCount(changed: number, total: number, noun: string): void {\n if (changed > 1) {\n announce(countMessage(total, noun));\n }\n }\n\n function commitRows(next: SelectionState): void {\n // The unchanged-reference contract the core transforms keep: a click that\n // selects what was already selected neither renders nor reports.\n if (next === rowSelection) {\n return;\n }\n setRowSelection(next);\n\n const { added, removed } = diffSelection(rowSelection, next);\n const addedRows = resolveRows(added);\n const removedRows = resolveRows(removed);\n\n for (const row of addedRows) {\n callbacks.onRowSelect?.({ row, selection: next });\n }\n if (addedRows.length > 0) {\n callbacks.onRowsSelect?.({ rows: addedRows, selection: next });\n }\n for (const row of removedRows) {\n callbacks.onRowDeselect?.({ row, selection: next });\n }\n if (removedRows.length > 0) {\n callbacks.onRowsDeselect?.({ rows: removedRows, selection: next });\n }\n callbacks.onRowSelectionChange?.({\n added: addedRows,\n removed: removedRows,\n selected: resolveRows(next),\n selection: next,\n });\n announceCount(added.length + removed.length, next.length, \"row\");\n }\n\n function commitColumns(next: SelectionState): void {\n if (next === columnSelection) {\n return;\n }\n setColumnSelection(next);\n\n const { added, removed } = diffSelection(columnSelection, next);\n const addedColumns = resolveColumns(added);\n const removedColumns = resolveColumns(removed);\n\n for (const column of addedColumns) {\n callbacks.onColumnSelect?.({ column, selection: next });\n }\n if (addedColumns.length > 0) {\n callbacks.onColumnsSelect?.({ columns: addedColumns, selection: next });\n }\n for (const column of removedColumns) {\n callbacks.onColumnDeselect?.({ column, selection: next });\n }\n if (removedColumns.length > 0) {\n callbacks.onColumnsDeselect?.({\n columns: removedColumns,\n selection: next,\n });\n }\n callbacks.onColumnSelectionChange?.({\n added: addedColumns,\n removed: removedColumns,\n selected: resolveColumns(next),\n selection: next,\n });\n announceCount(added.length + removed.length, next.length, \"column\");\n }\n\n function commitCell(next: CellSelectionState): void {\n if (next === cellSelection) {\n return;\n }\n setCellSelection(next);\n\n // Resolved before and after in one place, so that moving between two cells\n // reports the leaving and the arriving as one change.\n const selected = resolveCell(next);\n const deselected = resolveCell(cellSelection);\n\n if (deselected !== null) {\n callbacks.onCellDeselect?.({ cell: deselected, selection: next });\n }\n if (selected !== null) {\n callbacks.onCellSelect?.({ cell: selected, selection: next });\n }\n callbacks.onCellSelectionChange?.({\n selected,\n deselected,\n selection: next,\n });\n }\n\n function selectRow(rowId: string, intent: SelectIntent): void {\n const next = applyIntent(\n rowSelection,\n rowIds,\n rowAnchor.current,\n rowId,\n intent,\n rowMode,\n );\n if (intent !== \"range\") {\n rowAnchor.current = rowId;\n }\n commitRows(next);\n }\n\n function selectColumn(columnId: string, intent: SelectIntent): void {\n const next = applyIntent(\n columnSelection,\n columnIds,\n columnAnchor.current,\n columnId,\n intent,\n columnMode,\n );\n if (intent !== \"range\") {\n columnAnchor.current = columnId;\n }\n commitColumns(next);\n }\n\n function selectCellAt(cell: SelectedCellRef, intent: SelectIntent): void {\n // A cell holds one value, so a range over cells has nothing to span and\n // reads as the plain click it looks like.\n commitCell(\n intent === \"toggle\"\n ? toggleCellSelection(cellSelection, cell, cellMode)\n : selectCell(cellSelection, cell, cellMode),\n );\n }\n\n function selectAllRows(): void {\n commitRows(selectAll(rowSelection, rowIds, rowMode));\n }\n\n function clear(): void {\n commitRows(clearSelection(rowSelection));\n commitColumns(clearSelection(columnSelection));\n commitCell(null);\n }\n\n // A new object each render, as the other hooks here return: the handlers\n // close over the selections they transform.\n return {\n rowMode,\n columnMode,\n cellMode,\n selectedRowIds,\n selectedColumnIds,\n selectedCell: cellSelection,\n selectRow,\n selectColumn,\n selectCell: selectCellAt,\n selectAllRows,\n clear,\n };\n}\n","import { accessDotted } from \"@gridkitjs/core\";\nimport { memo, type ReactNode } from \"react\";\nimport type { ResolvedColumn } from \"../DataGrid\";\n\ninterface GridRowProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n rowId: string;\n row: Row;\n rowIndex: number;\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}\n\nfunction GridRowComponent<Row>({\n columns,\n rowId,\n row,\n rowIndex,\n activeColumnId,\n selectedColumnIds,\n selected,\n selectedColumnId,\n focusedColumnIndex,\n rowsSelectable,\n cellsSelectable,\n}: GridRowProps<Row>) {\n return (\n <tr\n role=\"row\"\n // Two past the index: rows are counted from one, and the header is the\n // first of them.\n aria-rowindex={rowIndex + 2}\n // Omitted rather than `false` when rows cannot be selected, which would\n // otherwise have every row announce that it is not.\n {...(rowsSelectable && { \"aria-selected\": selected })}\n className={[\"grid-row\", selected ? \"is-selected\" : \"\"]\n .filter(Boolean)\n .join(\" \")}\n >\n {columns.map(({ id, column, alignment }, columnIndex) => {\n // Resolved either way, so a template that only formats the value never\n // has to walk the field path 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={columnIndex === focusedColumnIndex ? 0 : -1}\n {...(cellsSelectable && { \"aria-selected\": cellSelected })}\n className={[\n \"grid-cell\",\n id === activeColumnId ? \"is-resizing\" : \"\",\n cellSelected || selectedColumnIds.has(id) ? \"is-selected\" : \"\",\n column.wrap?.cells ? \"is-wrapped\" : \"\",\n column.cellClassName ?? \"\",\n ]\n .filter(Boolean)\n .join(\" \")}\n style={{ textAlign: alignment }}\n >\n {column.cellTemplate\n ? column.cellTemplate({ value, row, rowIndex, rowId, selected })\n : (value as ReactNode)}\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 { ResolvedRow } from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\nimport { intentOf, type GridSelectionApi } from \"../useGridSelection\";\nimport GridRow from \"./GridRow\";\n\ninterface GridBodyProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n rows: readonly ResolvedRow<Row>[];\n /** The column being resized, so its cells outline with its header. */\n activeColumnId: string | null;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n}\n\n/** Where a cell sits, read off the table's own indices rather than an attribute. */\ninterface CellPosition {\n rowIndex: number;\n columnIndex: number;\n columnId: string;\n}\n\n/**\n * The cell an event happened in. `closest` is what makes the whole cell the\n * target: a click on a template's own markup resolves to the cell holding it.\n */\nfunction cellFrom(target: EventTarget): CellPosition | null {\n if (!(target instanceof Element)) {\n return null;\n }\n const cell = target.closest(\"td[data-gridkit-column]\");\n const row = cell?.parentElement;\n const columnId = cell?.getAttribute(\"data-gridkit-column\");\n if (\n !(cell instanceof HTMLTableCellElement) ||\n !(row instanceof HTMLTableRowElement) ||\n columnId === null ||\n columnId === undefined\n ) {\n return null;\n }\n return {\n rowIndex: row.sectionRowIndex,\n columnIndex: cell.cellIndex,\n columnId,\n };\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 rows,\n activeColumnId,\n nav,\n selection,\n}: GridBodyProps<Row>) {\n const { selectedCell, rowMode, cellMode } = selection;\n\n /** The row and cell an event addresses, resolved once for every handler. */\n function targetOf(\n target: EventTarget,\n ): { position: CellPosition; rowId: string } | null {\n const position = cellFrom(target);\n const entry = position === null ? undefined : rows[position.rowIndex];\n return position === null || entry === undefined\n ? null\n : { 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 const intent = intentOf(modifiers);\n // Independent of each other: selecting a cell says nothing about its row,\n // so a grid with both on reports both.\n if (rowMode !== false) {\n selection.selectRow(rowId, intent);\n }\n if (cellMode !== false) {\n selection.selectCell({ rowId, columnId }, intent);\n }\n }\n\n return (\n <tbody\n className=\"grid-body\"\n onFocus={(event) => {\n const found = targetOf(event.target);\n if (found === null) return;\n nav.focusCell(found.position.rowIndex, found.position.columnIndex);\n }}\n onClick={(event) => {\n const found = targetOf(event.target);\n if (found === null) return;\n select(found.rowId, found.position.columnId, event);\n }}\n onKeyDown={(event) => {\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(found.rowId, found.position.columnId, {\n ctrlKey: event.key === \" \" || event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n });\n return;\n }\n nav.onKeyDown(event);\n }}\n >\n {rows.map(({ rowId, row, rowIndex }) => (\n <GridRow<Row>\n key={rowId}\n columns={columns}\n rowId={rowId}\n row={row}\n rowIndex={rowIndex}\n activeColumnId={activeColumnId}\n selectedColumnIds={selection.selectedColumnIds}\n selected={selection.selectedRowIds.has(rowId)}\n /*\n * Narrowed to this row before it crosses the boundary, so that moving\n * the selected cell re-renders the two rows it moved between rather\n * than all of them.\n */\n selectedColumnId={\n selectedCell?.rowId === rowId ? selectedCell.columnId : null\n }\n focusedColumnIndex={\n nav.focus.rowIndex === rowIndex ? nav.focus.columnIndex : null\n }\n rowsSelectable={rowMode !== false}\n cellsSelectable={cellMode !== false}\n />\n ))}\n </tbody>\n );\n}\n","import {\n useRef,\n useState,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport {\n movesColumn,\n resolveDropBefore,\n type ColumnOrderState,\n type DropSide,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"./DataGrid\";\n\n/**\n * How far the pointer travels before a press becomes a drag. Below it the\n * gesture is still a click, which is what leaves the header free to take one.\n */\nconst DRAG_THRESHOLD = 4;\n\n/**\n * Where a drop would land. A union rather than the bare id it holds today, so\n * a second drop zone adds a member instead of reshaping this state.\n */\nexport type DropTarget = { kind: \"column-order\"; beforeId: string | null };\n\ninterface UseColumnDragOptions {\n order: ColumnOrderState;\n onDrop: (target: DropTarget, 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: DropTarget | 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 gesture that just ended was a drag rather than a click, for a\n * header that has something of its own to do with a click.\n *\n * Reading it clears it, so that a press which never opened a drag at all —\n * on a column that cannot be reordered — does not see the last one's answer.\n */\n justDragged: () => boolean;\n}\n\n/**\n * The header under `(x, y)`. `closest` is what makes the whole cell the drop\n * zone: a hit on the label or the resize handle resolves to its header.\n */\nfunction headerAt(x: number, y: number): Element | null {\n const element = document.elementFromPoint(x, y);\n return element?.closest(\"th[data-gridkit-column]\") ?? null;\n}\n\n/** Which half of `element` `x` falls in. */\nfunction sideOf(element: Element, x: number): DropSide {\n const rect = element.getBoundingClientRect();\n return x < rect.left + rect.width / 2 ? \"before\" : \"after\";\n}\n\n/**\n * Turns a pointer drag over the header into a drop target, leaving `onDrop` to\n * apply it.\n *\n * Pointer events rather than HTML5 drag-and-drop: `dragenter`/`dragleave` fire\n * per descendant, so the header's text and resize handle would each report the\n * target leaving and re-entering as the pointer crossed them.\n */\nexport default function useColumnDrag<Row>({\n order,\n onDrop,\n}: UseColumnDragOptions): ColumnDragApi<Row> {\n const [draggedColumnId, setDraggedColumnId] = useState<string | null>(null);\n const [dropTarget, setDropTarget] = useState<DropTarget | null>(null);\n const [ghostTransform, setGhostTransform] = useState<string | null>(null);\n const dragged = useRef(false);\n\n function justDragged(): boolean {\n const answer = dragged.current;\n dragged.current = false;\n return answer;\n }\n\n function startDrag(\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n const header = event.currentTarget;\n // Only the horizontal distance opens the drag: columns move along one\n // axis, so vertical travel says nothing about the user's intent.\n const { pointerId, clientX: startX } = event;\n const grabX = startX - header.getBoundingClientRect().left;\n let dragging = false;\n let target: DropTarget | null = null;\n\n /** Keeps the grab offset, so the pointer holds the spot it picked up. */\n function placeGhost(x: number, y: number): void {\n setGhostTransform(`translate(${String(x - grabX)}px, ${String(y)}px)`);\n }\n\n header.setPointerCapture(pointerId);\n\n function move(moveEvent: PointerEvent): void {\n const { clientX, clientY } = moveEvent;\n\n if (!dragging) {\n if (Math.abs(clientX - startX) < DRAG_THRESHOLD) {\n return;\n }\n dragging = true;\n // Latched for the `click` that follows the release, which is the only\n // thing that can tell a drag apart from a press in the same spot.\n dragged.current = true;\n setDraggedColumnId(entry.id);\n }\n\n placeGhost(clientX, clientY);\n\n // Hit-tested rather than read from the event's target, which pointer\n // capture pins to the header the drag opened on.\n const over = headerAt(clientX, clientY);\n const overId = over?.getAttribute(\"data-gridkit-column\");\n\n // The rect is read fresh each move, so a width changed mid-drag cannot\n // leave the midpoint stale.\n const beforeId =\n over && overId\n ? resolveDropBefore(order, overId, sideOf(over, clientX))\n : undefined;\n\n // A gap the column already sits in would promise a move that\n // `moveColumnBefore` then declines to make.\n target =\n beforeId !== undefined && movesColumn(order, entry.id, beforeId)\n ? { kind: \"column-order\", beforeId }\n : null;\n\n setDropTarget(target);\n }\n\n function stop(): void {\n header.removeEventListener(\"pointermove\", move);\n header.removeEventListener(\"pointerup\", end);\n header.removeEventListener(\"pointercancel\", cancel);\n window.removeEventListener(\"keydown\", onKeyDown);\n if (header.hasPointerCapture(pointerId)) {\n header.releasePointerCapture(pointerId);\n }\n setGhostTransform(null);\n setDraggedColumnId(null);\n setDropTarget(null);\n }\n\n function end(): void {\n const dropped = target;\n stop();\n if (dragging && dropped !== null) {\n onDrop(dropped, entry.id);\n }\n }\n\n /** Escape and a cancelled pointer both leave the order as it was. */\n function cancel(): void {\n target = null;\n stop();\n }\n\n function onKeyDown(keyEvent: KeyboardEvent): void {\n if (keyEvent.key === \"Escape\") {\n cancel();\n }\n }\n\n header.addEventListener(\"pointermove\", move);\n header.addEventListener(\"pointerup\", end);\n header.addEventListener(\"pointercancel\", cancel);\n window.addEventListener(\"keydown\", onKeyDown);\n }\n\n function moveByKeyboard(entry: ResolvedColumn<Row>, direction: -1 | 1): void {\n const index = order.indexOf(entry.id);\n if (index === -1) {\n return;\n }\n\n /**\n * Moving right lands in front of the id two along: the gap immediately\n * after a column is the one it already sits in.\n */\n const targetIndex = direction === -1 ? index - 1 : index + 2;\n if (targetIndex < 0) {\n return;\n }\n\n onDrop(\n { kind: \"column-order\", beforeId: order[targetIndex] ?? null },\n entry.id,\n );\n }\n\n // A new object each render, as `useColumnResize` returns: the handlers close\n // over `order`, and a stable identity would buy nothing.\n return {\n draggedColumnId,\n dropTarget,\n ghostTransform,\n startDrag,\n moveByKeyboard,\n justDragged,\n };\n}\n","import {\n useState,\n type Dispatch,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n type SetStateAction,\n} from \"react\";\nimport {\n applyColumnResize,\n beginColumnResize,\n clampColumnWidth,\n resolveColumnConstraints,\n sizeColumnToContent,\n type ColumnResizeEvent,\n type ColumnSizeDefaults,\n type ColumnSizingState,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport measureColumnContent from \"./measureColumnContent\";\n\ninterface UseColumnResizeOptions {\n tableRef: RefObject<HTMLTableElement | null>;\n sizing: ColumnSizingState;\n setSizing: Dispatch<SetStateAction<ColumnSizingState>>;\n columnSizeDefaults?: Partial<ColumnSizeDefaults> | undefined;\n onColumnResize?: ((event: ColumnResizeEvent) => void) | 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 sizeToContent: (entry: ResolvedColumn<Row>) => void;\n nudge: (entry: ResolvedColumn<Row>, delta: number) => void;\n}\n\n/**\n * Turns pointer and keyboard input into column widths. Every width it produces\n * comes from `@gridkitjs/core`; this hook only supplies the coordinates.\n */\nexport default function useColumnResize<Row>({\n tableRef,\n sizing,\n setSizing,\n columnSizeDefaults,\n onColumnResize,\n}: UseColumnResizeOptions): ColumnResizeApi<Row> {\n const [activeColumnId, setActiveColumnId] = useState<string | null>(null);\n\n function commit(\n base: ColumnSizingState,\n columnId: string,\n width: number,\n phase: \"move\" | \"end\",\n ): void {\n const next = { ...base, [columnId]: width };\n setSizing(next);\n onColumnResize?.({ columnId, width, sizing: next, phase });\n }\n\n function startResize(\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n const handle = event.currentTarget;\n const { pointerId } = event;\n const session = beginColumnResize(\n entry.column,\n entry.width,\n event.clientX,\n columnSizeDefaults,\n );\n /**\n * Only the dragged column can change while the drag lasts, so the state as\n * it was when the drag opened stays a correct base to merge into — no ref\n * mirror is needed to dodge a stale closure.\n */\n const base = sizing;\n let width = session.startWidth;\n\n // Otherwise the drag selects the header text it started on.\n event.preventDefault();\n event.stopPropagation();\n handle.setPointerCapture(pointerId);\n setActiveColumnId(session.columnId);\n\n function move(moveEvent: PointerEvent): void {\n width = applyColumnResize(session, moveEvent.clientX);\n commit(base, session.columnId, width, \"move\");\n }\n\n function stop(): void {\n handle.removeEventListener(\"pointermove\", move);\n handle.removeEventListener(\"pointerup\", end);\n handle.removeEventListener(\"pointercancel\", cancel);\n window.removeEventListener(\"keydown\", onKeyDown);\n if (handle.hasPointerCapture(pointerId)) {\n handle.releasePointerCapture(pointerId);\n }\n setActiveColumnId(null);\n }\n\n function end(): void {\n stop();\n // A click with no intervening `move` — as every double-click's two\n // constituent clicks are — leaves `width` at `startWidth`. Committing\n // that anyway would fire a spurious onColumnResize on every click.\n if (width !== session.startWidth) {\n commit(base, session.columnId, width, \"end\");\n }\n }\n\n /**\n * Escape puts back only the dragged column's pre-drag width, merged into\n * whatever the sizing state is *now* — not the `base` snapshot taken at\n * drag-start — so a different column resized via keyboard while this drag\n * was still open keeps its change instead of being clobbered by a stale\n * restore. A column that had no stored width at all is correctly omitted\n * by deleting the key rather than merging `startWidth` back in, which\n * would otherwise leave it pinned and hidden from auto-fit.\n */\n function cancel(): void {\n stop();\n setSizing((current) => {\n const next = Object.fromEntries(\n Object.entries(current).filter(\n ([columnId]) => columnId !== session.columnId,\n ),\n );\n if (session.columnId in base) {\n next[session.columnId] = base[session.columnId] as number;\n }\n onColumnResize?.({\n columnId: session.columnId,\n width: session.startWidth,\n sizing: next,\n phase: \"end\",\n });\n return next;\n });\n }\n\n function onKeyDown(keyEvent: KeyboardEvent): void {\n if (keyEvent.key === \"Escape\") {\n cancel();\n }\n }\n\n handle.addEventListener(\"pointermove\", move);\n handle.addEventListener(\"pointerup\", end);\n handle.addEventListener(\"pointercancel\", cancel);\n window.addEventListener(\"keydown\", onKeyDown);\n }\n\n function sizeToContent(entry: ResolvedColumn<Row>): void {\n const table = tableRef.current;\n if (table === null) {\n return;\n }\n\n const measured = measureColumnContent(table, entry.id);\n if (measured === null) {\n return;\n }\n\n commit(\n sizing,\n entry.id,\n sizeColumnToContent(\n measured,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n }\n\n function nudge(entry: ResolvedColumn<Row>, delta: number): void {\n commit(\n sizing,\n entry.id,\n clampColumnWidth(\n entry.width + delta,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n }\n\n // Deliberately a new object each render: the handlers close over `sizing` to\n // merge into, and a stable identity would need either `sizing` in a\n // `useCallback` dep list (no gain) or the ref mirror avoided above.\n return { activeColumnId, startResize, sizeToContent, nudge };\n}\n","/**\n * The width the widest cell in `columnId` needs to show its content in full,\n * or `null` when the column has no cells.\n *\n * Measured with a `Range` over each cell's contents rather than the cell's own\n * `scrollWidth`. A range shrink-wraps what is actually laid out, so a column\n * far wider than its content reports the content width and can be sized *down*;\n * `scrollWidth` never reports less than the cell it is read from and so can\n * only ever grow a column.\n *\n * Only rendered rows are measured — once paging or virtualisation lands, that\n * means the visible ones.\n */\nexport default function measureColumnContent(\n table: HTMLTableElement,\n columnId: string,\n): number | null {\n const cells = table.querySelectorAll<HTMLElement>(\n `td[data-gridkit-column=\"${CSS.escape(columnId)}\"]`,\n );\n const range = document.createRange();\n let widest: number | null = null;\n\n for (const cell of cells) {\n range.selectNodeContents(cell);\n const style = getComputedStyle(cell);\n // The range covers the content box only, so the cell's own spacing has to\n // be added back or the column would clip by exactly its padding.\n const width =\n range.getBoundingClientRect().width +\n parseFloat(style.paddingLeft) +\n parseFloat(style.paddingRight) +\n parseFloat(style.borderLeftWidth) +\n parseFloat(style.borderRightWidth);\n\n if (widest === null || width > widest) {\n widest = width;\n }\n }\n\n return widest;\n}\n","import type { Dispatch, SetStateAction } from \"react\";\nimport {\n sortDirectionFor,\n sortPriorityFor,\n toggleColumnSort,\n type ColumnSortEvent,\n type ColumnSortState,\n type SortDirection,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"./DataGrid\";\n\ninterface UseColumnSortOptions {\n sort: ColumnSortState;\n setSort: Dispatch<SetStateAction<ColumnSortState>>;\n onColumnSortChange?: ((event: ColumnSortEvent) => void) | undefined;\n}\n\nexport interface ColumnSortApi<Row> {\n sort: ColumnSortState;\n /** This column's direction, or `null` if it takes no part in the sort. */\n directionFor: (columnId: string) => SortDirection | null;\n /**\n * This column's 1-based place in the stack, or `null` outside it. Only\n * meaningful once two or more columns are stacked.\n */\n priorityFor: (columnId: string) => number | null;\n /** Cycles `entry`'s sort. A `shiftKey` stacks it; its absence replaces the stack. */\n toggle: (entry: ResolvedColumn<Row>, event: { shiftKey: boolean }) => void;\n}\n\n/**\n * Turns a click or keypress into a sort. Every transition it produces comes\n * from `@gridkitjs/core`; this hook only supplies the state to transform and\n * reports the result.\n */\nexport default function useColumnSort<Row>({\n sort,\n setSort,\n onColumnSortChange,\n}: UseColumnSortOptions): ColumnSortApi<Row> {\n function toggle(\n entry: ResolvedColumn<Row>,\n event: { shiftKey: boolean },\n ): void {\n const next = toggleColumnSort(sort, entry.id, { stack: event.shiftKey });\n if (next === sort) {\n return;\n }\n setSort(next);\n onColumnSortChange?.({ columnId: entry.id, sort: next });\n }\n\n // A new object each render, as the other hooks here return.\n return {\n sort,\n directionFor: (columnId) => sortDirectionFor(sort, columnId),\n priorityFor: (columnId) => sortPriorityFor(sort, columnId),\n toggle,\n };\n}\n","import { useLayoutEffect, useState, type RefObject } from \"react\";\n\n/**\n * The inner width of `ref`'s element, tracked as it changes.\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. Server rendering would want the usual\n * isomorphic-layout-effect shim here.\n *\n * Reads `clientWidth` rather than the observer entry's `contentRect` so the\n * first measurement and every later one come from the same, already-rounded,\n * source.\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\n setWidth(element.clientWidth);\n\n const observer = new ResizeObserver(() => {\n setWidth(element.clientWidth);\n });\n observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n }, [ref, enabled]);\n\n return width;\n}\n"],"mappings":";AAAA,SAAS,WAAAA,UAAS,UAAAC,SAAQ,YAAAC,iBAAgC;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAsBK;;;AC/BP,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;;;ACD9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAOA,IAAM,aAAa;AAG1B,IAAM,gBAAgB;AAgCtB,SAAS,WACP,OACA,UACA,aACW;AACX,SAAO;AAAA,IACL,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,UAAU,UAAU,GAAG,WAAW,CAAC;AAAA,IACrE,aAAa,KAAK;AAAA,MAChB,KAAK,IAAI,MAAM,aAAa,CAAC;AAAA,MAC7B,KAAK,IAAI,cAAc,GAAG,CAAC;AAAA,IAC7B;AAAA,EACF;AACF;AASA,SAAS,OAAO,OAAyB,OAAsC;AAC7E,QAAM,MACJ,MAAM,aAAa,aACd,MAAM,OAAO,KAAK,CAAC,KAAK,OACxB,MAAM,QAAQ,CAAC,GAAG,KAAK,MAAM,QAAQ,KAAK;AACjD,SAAO,KAAK,MAAM,MAAM,WAAW,KAAK;AAC1C;AAWe,SAAR,kBAAmC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAAgD;AAC9C,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAoB;AAAA,IAC9C,UAAU;AAAA,IACV,aAAa;AAAA,EACf,CAAC;AAOD,QAAM,QAAQ,WAAW,QAAQ,UAAU,WAAW;AAMtD,QAAM,UAAU,OAAO,KAAK;AAE5B,YAAU,MAAM;AACd,QAAI,C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;AAAA,QAEX;AAAA,0BAAAD,KAAC,cACE,mBAAS,IAAI,CAAC,UACb,gBAAAA,KAAC,SAAmB,OAAO,EAAE,OAAO,MAAM,MAAM,KAAtC,MAAM,EAAmC,CACpD,GACH;AAAA,UACA,gBAAAA;AAAA,YAAC;AAAA;AAAA,cACC,SAAS;AAAA,cACT;AAAA,cACA;AAAA,cACA,MAAM;AAAA,cACN;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACF;AAAA,UACA,gBAAAA;AAAA,YAAC;AAAA;AAAA,cACC,SAAS;AAAA,cACT,MAAM;AAAA,cACN,gBAAgB,OAAO;AAAA,cACvB;AAAA,cACA;AAAA;AAAA,UACF;AAAA;AAAA;AAAA,IACF;AAAA,IAKA,gBAAAA,KAAC,SAAI,WAAU,mBAAkB,MAAK,UAAS,aAAU,UACtD,wBACH;AAAA,KACF;AAEJ;","names":["useMemo","useRef","useState","useRef","accessDotted","jsx","jsx","useRef","useState","useState","useState","useState","jsx","jsxs","useRef","useState","useMemo"]}
1
+ {"version":3,"sources":["../src/DataGrid/DataGrid.tsx","../src/DataGrid/components/GridHeader.tsx","../src/DataGrid/ariaAttr.ts","../src/DataGrid/classNames.ts","../src/DataGrid/useGridNavigation.ts","../src/DataGrid/useGridSelection.ts","../src/DataGrid/commitIfChanged.ts","../src/DataGrid/components/GridBody.tsx","../src/DataGrid/components/GridGroupRow.tsx","../src/DataGrid/components/GridRow.tsx","../src/DataGrid/components/GroupByBar.tsx","../src/DataGrid/groupByDropTarget.ts","../src/DataGrid/useDragReorder.ts","../src/DataGrid/pointerGesture.ts","../src/DataGrid/useGroupByDrag.ts","../src/DataGrid/useColumnDrag.ts","../src/DataGrid/useColumnResize.ts","../src/DataGrid/measureColumnContent.ts","../src/DataGrid/useColumnSort.ts","../src/DataGrid/useElementWidth.ts","../src/DataGrid/useRowGrouping.ts"],"sourcesContent":["import {\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport {\n applyColumnOrder,\n defineColumnsFromRows,\n fitColumnsToWidth,\n groupRows,\n moveColumnBefore,\n resolveColumnWidths,\n resolveRowId,\n resolveShownRows,\n totalColumnWidth,\n type ColumnDefinition as CoreColumnDefinition,\n type ResolvedColumn as CoreResolvedColumn,\n type ColumnOrderEvent,\n type ColumnOrderState,\n type ColumnResizeEvent,\n type ColumnSizeDefaults,\n type ColumnSizingState,\n type ColumnSortEvent,\n type ColumnSortState,\n type DisplayRow,\n type FilterState,\n type GroupByEvent,\n type GroupByState,\n type GroupExpansionEvent,\n type GroupExpansionState,\n type ResolvedRow,\n type CellSelectionState,\n type SelectableConfig,\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} from \"@gridkitjs/core\";\nimport GridHeader from \"./components/GridHeader\";\nimport GridBody from \"./components/GridBody\";\nimport GroupByBar from \"./components/GroupByBar\";\nimport { ariaAttr } from \"./ariaAttr\";\nimport { classNames } from \"./classNames\";\nimport useColumnDrag, { type DropTarget } from \"./useColumnDrag\";\nimport useColumnResize from \"./useColumnResize\";\nimport useColumnSort from \"./useColumnSort\";\nimport useElementWidth from \"./useElementWidth\";\nimport useGridNavigation, { HEADER_ROW } from \"./useGridNavigation\";\nimport useGridSelection, { type SelectionCallbacks } from \"./useGridSelection\";\nimport useRowGrouping from \"./useRowGrouping\";\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/**\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>;\n\n/**\n * Imperative handle for a mounted `DataGridComponent`, reached via its `ref`\n * prop. Read-plus-standard-actions: getters mirror the grid's live state,\n * and the actions are the ones every grid ref carries (focus, clear/select\n * all, scroll-to). Sizing, order, sort, and selection stay uncontrolled via\n * their existing `default*` props — this is not a second, imperative-only\n * way to drive that same state.\n */\nexport interface DataGridApi<Row> {\n /** The grid's scrollable viewport element. */\n readonly element: HTMLDivElement | null;\n /** The grid's `<table>` element. */\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 /** Columns as currently sized and ordered — what's rendered. */\n getColumns(): readonly ResolvedColumn<Row>[];\n\n getColumnSizing(): ColumnSizingState;\n getColumnOrder(): ColumnOrderState;\n getColumnSort(): ColumnSortState;\n getGroupBy(): GroupByState;\n getGroupExpansion(): GroupExpansionState;\n getRowSelection(): SelectionState;\n getColumnSelection(): SelectionState;\n getCellSelection(): CellSelectionState;\n /** The cell currently holding the grid's single tab stop. */\n getFocusedCell(): { rowIndex: number; columnIndex: number };\n\n focusCell(rowIndex: number, columnIndex: number): void;\n clearSelection(): void;\n selectAllRows(): void;\n /** Expands every group at once — there is no dedicated UI control for it. */\n expandAllGroups(): void;\n /** Collapses every group currently shown at once — see `collapseAllGroups` in `@gridkitjs/core` for what \"currently shown\" means for a group already nested under a collapsed one. */\n collapseAllGroups(): void;\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\nexport type Borders = \"horizontal\" | \"vertical\" | \"all\" | \"none\";\n\n/**\n * How a column's width relates to the grid's.\n *\n * `\"fit\"` keeps the columns filling the grid: the space a column gives up is\n * handed to the others, and the space it takes comes out of them. `\"fixed\"`\n * lets every column keep its own width, so a resize moves one column and\n * nothing else, and the grid scrolls or leaves a gap accordingly.\n */\nexport type ResizeMode = \"fit\" | \"fixed\";\n\n/**\n * How the group-by bar's visibility follows the active grouping. `\"always\"`\n * renders it even with an empty `groupBy` — a fixed drop target and a\n * constant reminder grouping exists. `\"never\"` never renders it, for a grid\n * driving `groupBy` entirely by its own UI (a header toggle, `Alt+ArrowDown`)\n * or programmatically. `\"auto\"` renders it once `groupBy` is non-empty, or\n * while a header drag eligible to drop into it is in progress — so there is\n * always somewhere to drop the very first column, even from a fully empty\n * grouping.\n */\nexport type GroupByBarVisibility = \"always\" | \"auto\" | \"never\";\n\nexport interface HoverableConfig {\n rows?: boolean;\n columns?: boolean;\n cells?: boolean;\n}\n\nexport interface DataGridProps<Row> extends SelectionCallbacks<Row> {\n columns?: readonly ColumnDefinition<Row>[] | undefined;\n dataSource?: readonly Row[] | undefined;\n /**\n * A row's stable identity, for state keyed by it. Defaults to the row's\n * position, which is enough for a static grid but ties that state to where a\n * row sits rather than to the row — so anything sorting, filtering or paging\n * its data should give one.\n *\n * Called for every row on every change to `dataSource`, so it should be\n * cheap and stable; an inline arrow is fine, one that re-reads the data is\n * not.\n */\n getRowId?: ((row: Row, index: number) => string) | undefined;\n borders?: Borders | undefined;\n hoverable?: HoverableConfig | undefined;\n /**\n * Which parts of the grid the user may select, and how many of each —\n * `{ rows: \"multiple\", cells: \"single\" }`. A cell addresses one value, so it\n * has no `\"multiple\"`.\n *\n * Off by default, unlike `hoverable`: selection claims the click, which a\n * grid that only displays data should not do. Give `getRowId` alongside it\n * for data that sorts, filters or pages, or a selection follows the position\n * rather than the row.\n */\n selectable?: SelectableConfig | undefined;\n /** Row ids selected to start with, keyed as `getRowId` resolves them. Uncontrolled. */\n defaultRowSelection?: SelectionState | undefined;\n /** Column ids selected to start with. Uncontrolled. */\n defaultColumnSelection?: SelectionState | undefined;\n /** The cell selected to start with. Uncontrolled. */\n defaultCellSelection?: CellSelectionState | undefined;\n /** Whether columns can be dragged wider, unless a column says otherwise. */\n resizableColumns?: boolean | undefined;\n /**\n * Whether columns can be dragged into a new position, unless a column says\n * otherwise. Turning it off leaves an order the user already made in place.\n */\n reorderableColumns?: boolean | undefined;\n /**\n * Whether columns fill the grid's width or sit at their own. Defaults to\n * `\"fit\"`, under which columns the user has sized keep their width and the\n * rest share what is left.\n */\n resizeMode?: ResizeMode | undefined;\n /** Column widths to start from, keyed by column id. Uncontrolled. */\n defaultColumnSizing?: ColumnSizingState | undefined;\n /**\n * Column ids in the order to start in. Uncontrolled, and partial: ids it\n * omits keep their position among `columns` and follow those it lists.\n */\n defaultColumnOrder?: ColumnOrderState | undefined;\n /**\n * Sizes applied to columns that do not set their own — the width they start\n * at and the bounds they may be resized between. Distinct from\n * `defaultColumnSizing`, which sets specific columns' starting widths.\n */\n columnSizeDefaults?: Partial<ColumnSizeDefaults> | undefined;\n /**\n * Called as the user resizes a column. Fires continuously with\n * `phase: \"move\"` and once on release with `phase: \"end\"` — the latter being\n * the one to persist. Auto-fit does not call it; it reports user intent only.\n */\n onColumnResize?: ((event: ColumnResizeEvent) => void) | undefined;\n /**\n * Called once when the user drops a column somewhere new. A drop that leaves\n * the order as it was does not call it.\n */\n onColumnOrderChange?: ((event: ColumnOrderEvent) => void) | undefined;\n /**\n * Whether columns can be sorted by clicking their header toggle, unless a\n * column says otherwise. Shift-click stacks a column into the sort instead\n * of replacing it.\n */\n sortableColumns?: boolean | undefined;\n /** The sort to start with, in priority order. Uncontrolled. */\n defaultColumnSort?: ColumnSortState | undefined;\n /**\n * Called once when the user changes the sort — a toggle, a stack, or a\n * clear back to \"none\".\n */\n onColumnSortChange?: ((event: ColumnSortEvent) => void) | undefined;\n /**\n * Whether columns can be grouped by — a header's click/`Alt+ArrowDown`\n * toggle — unless a column says otherwise. The grouping itself still\n * applies when this is off, via `defaultGroupBy` or the imperative API;\n * this only gates that one interaction, the same way `sortableColumns`\n * gates the sort toggle without disabling `defaultColumnSort`. Independent\n * of `groupByBarVisibility` and `groupByDraggableColumns`, which gate the\n * bar and the drag-in gesture respectively.\n */\n groupableColumns?: boolean | undefined;\n /**\n * Whether a groupable header shows its group-toggle icon, unless a column\n * says otherwise. Purely a rendering choice: `Alt+ArrowDown` keeps working\n * on a groupable header with the icon hidden.\n */\n groupToggleIconColumns?: boolean | undefined;\n /**\n * Whether a column's header may be dragged into the group-by bar to add\n * it to the grouping, unless a column says otherwise. Independent of\n * `groupableColumns`: a column can be groupable via its header's\n * click/keyboard toggle, via this drag, both, or neither.\n */\n groupByDraggableColumns?: boolean | undefined;\n /** How the group-by bar's visibility follows the active grouping. */\n groupByBarVisibility?: GroupByBarVisibility | undefined;\n /** The group-by stack to start with, outer to inner. Uncontrolled. */\n defaultGroupBy?: GroupByState | undefined;\n /**\n * Called once when the user changes the group-by stack — adding, removing,\n * or reordering a level.\n */\n onGroupByChange?: ((event: GroupByEvent) => void) | undefined;\n /** Group keys collapsed to start with — every other group starts expanded. Uncontrolled. */\n defaultGroupExpansion?: GroupExpansionState | undefined;\n /** Called once when the user expands or collapses a group, or every group at once. */\n onGroupExpansionChange?: ((event: GroupExpansionEvent) => void) | undefined;\n /** The filter to start with — every applied entry, ANDed together. Uncontrolled. */\n defaultFilter?: FilterState<Row> | undefined;\n /**\n * The grid's accessible name, announced when it takes focus. A grid without\n * one is read only as \"grid\", which says nothing about which grid.\n */\n label?: string | undefined;\n /**\n * The id of an element naming the grid, for a heading already on the page.\n * Takes precedence over `label`, as `aria-labelledby` does.\n */\n labelledBy?: string | undefined;\n /** Imperative handle for reading live grid state and triggering actions. */\n ref?: Ref<DataGridApi<Row>> | undefined;\n}\n\nexport function DataGridComponent<Row>({\n dataSource,\n columns,\n getRowId,\n borders,\n hoverable,\n selectable,\n defaultRowSelection,\n defaultColumnSelection,\n defaultCellSelection,\n resizableColumns = false,\n reorderableColumns = false,\n resizeMode = \"fit\",\n defaultColumnSizing,\n defaultColumnOrder,\n columnSizeDefaults,\n onColumnResize,\n onColumnOrderChange,\n sortableColumns = false,\n defaultColumnSort,\n onColumnSortChange,\n groupableColumns = false,\n groupToggleIconColumns = true,\n groupByDraggableColumns = false,\n groupByBarVisibility = \"auto\",\n defaultGroupBy,\n onGroupByChange,\n defaultGroupExpansion,\n onGroupExpansionChange,\n defaultFilter,\n label,\n labelledBy,\n ref,\n ...callbacks\n}: DataGridProps<Row>) {\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 tableRef = useRef<HTMLTableElement>(null);\n const viewportWidth = useElementWidth(viewportRef, resizeMode === \"fit\");\n const [sizing, setSizing] = useState<ColumnSizingState>(\n defaultColumnSizing ?? {},\n );\n const [order, setOrder] = useState<ColumnOrderState>(\n defaultColumnOrder ?? [],\n );\n const [sort, setSort] = useState<ColumnSortState>(defaultColumnSort ?? []);\n const [groupBy, setGroupBy] = useState<GroupByState>(defaultGroupBy ?? []);\n const [expansion, setExpansion] = useState<GroupExpansionState>(\n defaultGroupExpansion ?? [],\n );\n const [filter] = useState<FilterState<Row>>(defaultFilter ?? []);\n const [announcement, setAnnouncement] = useState(\"\");\n const [rowSelection, setRowSelection] = useState<SelectionState>(\n defaultRowSelection ?? [],\n );\n const [columnSelection, setColumnSelection] = useState<SelectionState>(\n defaultColumnSelection ?? [],\n );\n const [cellSelection, setCellSelection] = useState<CellSelectionState>(\n defaultCellSelection ?? null,\n );\n\n /**\n * The rows as rendered, each carrying the id everything downstream keys it\n * by. Resolved once here rather than per consumer so a row's id cannot come\n * out differently in two places — the same reason `resolveColumnWidths` runs\n * once ahead of the header and the body.\n *\n * An array rather than a map keyed by id: two rows given the same id is a\n * caller's mistake, and one that should render twice and look wrong rather\n * than silently lose a row.\n */\n const rows = useMemo<readonly ResolvedRow<Row>[]>(\n () =>\n dataSource?.map((row, rowIndex) => ({\n rowId: resolveRowId(row, rowIndex, getRowId),\n row,\n rowIndex,\n })) ?? [],\n [dataSource, getRowId],\n );\n\n const definedColumns = useMemo<readonly ColumnDefinition<Row>[]>(() => {\n if (columns && columns.length !== 0) return columns;\n if (dataSource && dataSource.length > 0)\n return defineColumnsFromRows(dataSource);\n return [];\n }, [columns, dataSource]);\n\n /**\n * Ahead of sizing, so everything downstream reads one already-ordered list\n * and no part of the grid has to know a reorder happened.\n */\n const orderedColumns = useMemo(\n () => applyColumnOrder(definedColumns, order),\n [definedColumns, order],\n );\n\n /**\n * Auto-fit is a derivation rather than a write back into `sizing`, so that a\n * `width` set in a column definition is never overwritten and the effect\n * cannot chase its own output. `\"fixed\"` is then simply the absence of it.\n */\n const resolved = useMemo(() => {\n const widths = resolveColumnWidths(orderedColumns, sizing, {\n sizes: columnSizeDefaults,\n resizable: resizableColumns,\n reorderable: reorderableColumns,\n groupByDraggable: groupByDraggableColumns,\n });\n return resizeMode === \"fit\" && viewportWidth !== null\n ? fitColumnsToWidth(widths, viewportWidth, columnSizeDefaults)\n : widths;\n }, [\n orderedColumns,\n sizing,\n resizeMode,\n viewportWidth,\n columnSizeDefaults,\n resizableColumns,\n reorderableColumns,\n groupByDraggableColumns,\n ]);\n\n /**\n * `rows`, filtered then sorted — needs `resolved` for each column's\n * `field` and `type`, so it runs after sizing rather than alongside\n * `rows` itself. Everything downstream that renders or interacts with row\n * order and membership reads this rather than `rows`, so what the user\n * sees, filters, sorts, and clicks all agree.\n */\n const shownRows = useMemo(\n () => resolveShownRows(rows, filter, sort, resolved),\n [rows, filter, sort, resolved],\n );\n\n /**\n * `shownRows` regrouped into `groupBy` — group headers interleaved with\n * data rows, in render order. `GridBody` renders this rather than\n * `shownRows` directly, grouped or not: `groupRows` returns `shownRows`\n * itself, untouched, when `groupBy` is empty, so an ungrouped grid pays\n * only the cost of that check.\n */\n const displayRows = useMemo(\n () => groupRows(shownRows, groupBy, expansion, resolved),\n [shownRows, groupBy, expansion, resolved],\n );\n\n /**\n * `displayRows` narrowed back to its data rows, in the same (possibly\n * regrouped) order — what row/cell selection anchors its range-select\n * against, so that a Shift-click spans the rows actually adjacent on\n * screen rather than their pre-grouping order. A group collapsed at\n * selection time contributes no rows here at all, so a range spanning its\n * position includes only what was visible when the range was drawn, not\n * the rows hidden beneath it.\n */\n const displayDataRows = useMemo(\n () =>\n groupBy.length === 0\n ? shownRows\n : displayRows.filter(\n (entry): entry is ResolvedRow<Row> => !(\"kind\" in entry),\n ),\n [displayRows, groupBy.length, shownRows],\n );\n\n /**\n * What a column is called in an announcement. `label` carries whatever a\n * `headerTemplate` returned, which need not be text at all, so the field\n * path stands in whenever it is not.\n */\n function columnName(columnId: string): string {\n const entry = resolved.find((candidate) => candidate.id === columnId);\n if (entry === undefined) {\n return columnId;\n }\n return typeof entry.label === \"string\" ? entry.label : entry.column.field;\n }\n\n /**\n * Reports a change no visual cue can carry to a screen reader. Held as state\n * rather than written to the DOM directly so React owns the one element the\n * live region watches.\n */\n function announce(message: string): void {\n setAnnouncement(message);\n }\n\n /**\n * Wrapped rather than announced from the resize hook, which reports the\n * continuous `\"move\"` phase as well — a live region given every frame of a\n * drag says nothing an assistive technology can keep up with.\n */\n function handleColumnResize(event: ColumnResizeEvent): void {\n onColumnResize?.(event);\n if (event.phase === \"end\") {\n announce(\n `${columnName(event.columnId)}, ${String(Math.round(event.width))} pixels wide`,\n );\n }\n }\n\n const resize = useColumnResize<Row>({\n tableRef,\n sizing,\n setSizing,\n columnSizeDefaults,\n onColumnResize: handleColumnResize,\n });\n\n /** Wrapped the same way `handleColumnResize` is, for its own announcement. */\n function handleGroupByChange(event: GroupByEvent): void {\n onGroupByChange?.(event);\n const entry = event.groupBy.find(\n (candidate) => candidate.columnId === event.columnId,\n );\n if (entry === undefined) {\n announce(`${columnName(event.columnId)}, grouping removed`);\n return;\n }\n announce(\n event.groupBy.length > 1\n ? `Grouped by ${columnName(event.columnId)}, level ${String(event.groupBy.indexOf(entry) + 1)} of ${String(event.groupBy.length)}`\n : `Grouped by ${columnName(event.columnId)}`,\n );\n }\n\n /**\n * `groupId: null` marks `expandAll`/`collapseAll`, which touch every group\n * in one call rather than one at a time — announced as a single summary\n * instead of naming a group that doesn't apply.\n */\n function handleGroupExpansionChange(event: GroupExpansionEvent): void {\n onGroupExpansionChange?.(event);\n if (event.groupId === null) {\n announce(\n event.expansion.length === 0\n ? \"All groups expanded\"\n : \"All groups collapsed\",\n );\n return;\n }\n announce(\n event.expansion.includes(event.groupId)\n ? \"Group collapsed\"\n : \"Group expanded\",\n );\n }\n\n /**\n * Constructed ahead of `handleDrop`/`drag` below (rather than alongside\n * `columnSort`, its closest sibling) because `handleDrop`'s `\"group-by\"`\n * arm calls `grouping.moveGroupBy` directly.\n */\n const grouping = useRowGrouping<Row>({\n groupBy,\n setGroupBy,\n expansion,\n setExpansion,\n onGroupByChange: handleGroupByChange,\n onGroupExpansionChange: handleGroupExpansionChange,\n });\n\n const nav = useGridNavigation({\n tableRef,\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.\n rowCount: displayRows.length,\n columnCount: resolved.length,\n });\n\n /**\n * The ids as displayed, which a drop is expressed against — the order state\n * starts empty and may name only some columns, so moving against it directly\n * would have nothing to rearrange.\n */\n const displayedIds = useMemo(\n () => orderedColumns.map((column) => column.id ?? column.field),\n [orderedColumns],\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 resolved\n .filter((entry) => entry.groupByDraggable)\n .map((entry) => entry.id),\n ),\n [resolved],\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: DropTarget, movedId: string): void {\n if (target.kind === \"group-by\") {\n // Already announced: `grouping.moveGroupBy` commits 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 grouping.moveGroupBy(movedId, target.beforeColumnId);\n return;\n }\n\n const next = moveColumnBefore(displayedIds, movedId, target.beforeId);\n // `moveColumnBefore` hands back the same reference for a move that changes\n // nothing, so a drop in place neither renders nor reports.\n if (next === displayedIds) {\n return;\n }\n const position = next.indexOf(movedId);\n setOrder(next);\n onColumnOrderChange?.({ columnId: movedId, order: next });\n announce(\n `${columnName(movedId)}, column ${String(position + 1)} of ${String(next.length)}`,\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(HEADER_ROW, position);\n }\n\n const drag = useColumnDrag<Row>({\n order: displayedIds,\n groupBy,\n groupByDraggableIds,\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 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 (groupBy.length > 0 || dragEligibleForGroupBy));\n\n const headerGroupByDropTarget =\n drag.dropTarget?.kind === \"group-by\" ? drag.dropTarget : null;\n\n /**\n * Wrapped the same way `handleColumnResize`/`handleDrop` are, so a toggle,\n * a stack, or a clear back to \"none\" each get their own announcement.\n */\n function handleColumnSortChange(event: ColumnSortEvent): void {\n onColumnSortChange?.(event);\n const entry = event.sort.find(\n (candidate) => candidate.columnId === event.columnId,\n );\n if (entry === undefined) {\n announce(`${columnName(event.columnId)}, sort cleared`);\n return;\n }\n const direction = entry.direction === \"asc\" ? \"ascending\" : \"descending\";\n announce(\n event.sort.length > 1\n ? `${columnName(event.columnId)} sorted ${direction}, key ${String(event.sort.indexOf(entry) + 1)} of ${String(event.sort.length)}`\n : `${columnName(event.columnId)} sorted ${direction}`,\n );\n }\n\n const columnSort = useColumnSort<Row>({\n sort,\n setSort,\n onColumnSortChange: handleColumnSortChange,\n });\n\n const selection = useGridSelection<Row>({\n rows: displayDataRows,\n columns: resolved,\n selectable,\n rowSelection,\n setRowSelection,\n columnSelection,\n setColumnSelection,\n cellSelection,\n setCellSelection,\n callbacks,\n announce,\n columnName,\n });\n\n const multiselectable =\n selection.rowMode === \"multiple\" || selection.columnMode === \"multiple\";\n\n /**\n * No deps array: `nav`, `selection`, `resize`, and `drag` are all 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.\n */\n useImperativeHandle(ref, () => ({\n get element() {\n return viewportRef.current;\n },\n get table() {\n return tableRef.current;\n },\n getRows: () => shownRows,\n getDisplayRows: () => displayRows,\n getColumns: () => resolved,\n getColumnSizing: () => sizing,\n getColumnOrder: () => order,\n getColumnSort: () => sort,\n getGroupBy: () => groupBy,\n getGroupExpansion: () => expansion,\n getRowSelection: () => rowSelection,\n getColumnSelection: () => columnSelection,\n getCellSelection: () => cellSelection,\n getFocusedCell: () => nav.focus,\n focusCell: nav.focusCell,\n clearSelection: selection.clear,\n selectAllRows: selection.selectAllRows,\n expandAllGroups: grouping.expandAll,\n collapseAllGroups: () => {\n grouping.collapseAll(displayRows);\n },\n scrollToRow: (rowId, options) => {\n // `displayRows`, not `shownRows`: with grouping active a data row's DOM\n // position is its place in the grouped, flattened output, not its\n // pre-grouping index — group headers are siblings in the same `<tbody>`.\n const index = displayRows.findIndex(\n (entry) => !(\"kind\" in entry) && entry.rowId === rowId,\n );\n if (index === -1) return;\n tableRef.current?.tBodies[0]?.rows[index]?.scrollIntoView(options);\n },\n scrollToColumn: (columnId, options) => {\n const cells = tableRef.current?.querySelectorAll(\"[data-gridkit-column]\");\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 }));\n\n return (\n <div className=\"gridkit-data-grid-viewport\" ref={viewportRef}>\n {showGroupByBar && (\n <GroupByBar<Row>\n columns={resolved}\n grouping={grouping}\n columnName={columnName}\n headerDragEligible={dragEligibleForGroupBy}\n headerDragBlocked={draggedColumnAlreadyGrouped}\n headerDropTarget={headerGroupByDropTarget}\n />\n )}\n <table\n ref={tableRef}\n /*\n * `role=\"grid\"` rather than the table's own semantics: it is what makes\n * the arrow keys a navigation the grid owns, and later what lets a row\n * report whether it is selected. It obliges the single tab stop\n * `useGridNavigation` keeps.\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={groupBy.length > 0 ? \"treegrid\" : \"grid\"}\n // The header is a row too, and counted from one; group headers count\n // as rows here too, the same way they do in `nav`'s `rowCount`.\n aria-rowcount={displayRows.length + 1}\n aria-colcount={resolved.length}\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 /*\n * The two keys that address the grid rather than a cell, and so are\n * caught here where everything bubbles to rather than in each of\n * them.\n */\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 // 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(resolved) }}\n className={classNames(\n \"gridkit-data-grid\",\n borders ? `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 ? \"\" : \"no-hover-rows\",\n hoverColumns ? \"\" : \"no-hover-columns\",\n hoverCells ? \"\" : \"no-hover-cells\",\n selection.rowMode === false ? \"\" : \"selectable-rows\",\n selection.columnMode === false ? \"\" : \"selectable-columns\",\n selection.cellMode === false ? \"\" : \"selectable-cells\",\n )}\n >\n <colgroup>\n {resolved.map((entry) => (\n <col key={entry.id} style={{ width: entry.width }} />\n ))}\n </colgroup>\n <GridHeader<Row>\n columns={resolved}\n resize={resize}\n drag={drag}\n sort={columnSort}\n sortableColumns={sortableColumns}\n grouping={grouping}\n groupableColumns={groupableColumns}\n groupToggleIconColumns={groupToggleIconColumns}\n nav={nav}\n selection={selection}\n />\n <GridBody<Row>\n columns={resolved}\n rows={displayRows}\n activeColumnId={resize.activeColumnId}\n nav={nav}\n selection={selection}\n grouping={grouping}\n />\n </table>\n {/*\n * Outside the table, which admits no `div`, and polite so it waits for a\n * pause rather than cutting across what the user is already hearing.\n */}\n <div className=\"gridkit-sr-only\" role=\"status\" aria-live=\"polite\">\n {announcement}\n </div>\n </div>\n );\n}\n","import type { ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { buildKeyShortcuts, intentOf, KEYBOARD_STEP } from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport type { ColumnDragApi } from \"../useColumnDrag\";\nimport type { ColumnResizeApi } from \"../useColumnResize\";\nimport type { ColumnSortApi } from \"../useColumnSort\";\nimport { HEADER_ROW, type GridNavigationApi } from \"../useGridNavigation\";\nimport {\n keyboardSelectIntent,\n type GridSelectionApi,\n} from \"../useGridSelection\";\nimport type { RowGroupingApi } from \"../useRowGrouping\";\n\ninterface GridHeaderProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n resize: ColumnResizeApi<Row>;\n drag: ColumnDragApi<Row>;\n sort: ColumnSortApi<Row>;\n sortableColumns: boolean;\n grouping: RowGroupingApi<Row>;\n groupableColumns: boolean;\n groupToggleIconColumns: boolean;\n nav: GridNavigationApi;\n selection: GridSelectionApi;\n}\n\n/** The common attributes behind every icon here — just the `<path>`s differ. */\nfunction 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 */\nfunction 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\nfunction 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\". */\nfunction 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\nexport default function GridHeader<Row>({\n columns,\n resize,\n drag,\n sort,\n sortableColumns,\n grouping,\n groupableColumns,\n groupToggleIconColumns,\n nav,\n selection,\n}: GridHeaderProps<Row>) {\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 return (\n <thead>\n <tr className=\"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 /**\n * Drawn on the gap's own edge, so the one gap between two columns is\n * marked once. No guard against the dragged column: the hook reports\n * only gaps that would move it.\n */\n const dropBefore = beforeId !== undefined && beforeId === entry.id;\n const dropAfter = beforeId === null && index === columns.length - 1;\n const selected = selection.selectedColumnIds.has(entry.id);\n const sortable = column.sortable ?? sortableColumns;\n const sortDirection = sort.directionFor(entry.id);\n const sortPriority = sort.priorityFor(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 = grouping.groupBy.some(\n (level) => level.columnId === entry.id,\n );\n\n const shortcuts = buildKeyShortcuts({\n reorderable: entry.reorderable,\n resizable: entry.resizable,\n sortable,\n groupable,\n });\n\n return (\n <th\n key={entry.id}\n scope=\"col\"\n // Explicit, matching `GridRow.tsx`'s `role=\"gridcell\"` on the\n // body `<td>`: both sit inside a `<table role=\"grid\">`, and\n // mixing that non-native ancestor role with descendants that\n // rely on implicit native role mapping is inconsistently\n // resolved across browser/AT combinations.\n role=\"columnheader\"\n data-gridkit-column={entry.id}\n aria-colindex={index + 1}\n tabIndex={nav.tabIndexFor(HEADER_ROW, index)}\n {...ariaAttr(\n selection.columnMode !== false,\n \"aria-selected\",\n selected,\n )}\n onFocus={() => {\n nav.focusCell(HEADER_ROW, 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()) {\n return;\n }\n if (\n event.target instanceof Element &&\n (event.target.closest(\".header-resize-handle\") !== null ||\n event.target.closest(\".header-sort-toggle\") !== null ||\n event.target.closest(\".header-group-toggle\") !== null)\n ) {\n return;\n }\n selection.selectColumn(entry.id, intentOf(event));\n }}\n onKeyDown={(event) => {\n const horizontal =\n event.key === \"ArrowLeft\" || event.key === \"ArrowRight\";\n const direction = event.key === \"ArrowLeft\" ? -1 : 1;\n\n if (horizontal && event.ctrlKey && entry.reorderable) {\n event.preventDefault();\n drag.moveByKeyboard(entry, direction);\n return;\n }\n if (horizontal && event.altKey && entry.resizable) {\n event.preventDefault();\n resize.nudge(entry, direction * 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 sort.toggle(entry, { shiftKey: event.shiftKey });\n return;\n }\n if (event.key === \"ArrowDown\" && event.altKey && groupable) {\n event.preventDefault();\n grouping.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 \"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 column.wrap?.header ? \"is-wrapped\" : \"\",\n column.headerClassName ?? \"\",\n )}\n {...ariaAttr(shortcuts !== \"\", \"aria-keyshortcuts\", shortcuts)}\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 \"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 grouping.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 \"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 * `setPointerCapture` 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 sort.toggle(entry, { shiftKey: event.shiftKey });\n }}\n >\n {sortDirection === null ? (\n <ChevronsUpDownIcon />\n ) : (\n <ChevronUpIcon />\n )}\n {sortPriority !== null && sortPriority > 1 && (\n <span className=\"header-sort-priority\">{sortPriority}</span>\n )}\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=\"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 header-cell 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 {\n useEffect,\n useRef,\n useState,\n type KeyboardEvent as ReactKeyboardEvent,\n type RefObject,\n} from \"react\";\nimport {\n clampFocus,\n nextFocusForKey,\n HEADER_ROW,\n type GridFocus,\n} from \"@gridkitjs/core\";\n\nexport { HEADER_ROW, type GridFocus };\n\n/** Rows a page key moves when the viewport cannot be measured. */\nconst FALLBACK_PAGE = 10;\n\ninterface UseGridNavigationOptions {\n tableRef: RefObject<HTMLTableElement | null>;\n rowCount: number;\n columnCount: number;\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: (rowIndex: number, columnIndex: number) => 0 | -1;\n /** Moves the tab stop, and the browser's focus with it. */\n focusCell: (rowIndex: number, columnIndex: number) => void;\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 `rowIndex`/`GridFocus` pair, since that\n * narrowing — done once per row in `GridBody` — is what keeps a focus move\n * from re-rendering every row instead of the two it actually 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 cell at a coordinate, found through the table's own row and cell\n * collections rather than a selector.\n *\n * Ids can hold anything a consumer's data holds, and an attribute selector\n * built from one would have to escape it; positions need no quoting.\n *\n * `columnIndex` is clamped to the row's own last cell rather than read\n * directly: a group-header row renders one `<td colSpan>` regardless of\n * `columnCount`, so a focus arriving from a data row further right (or a\n * `columnIndex` a keyboard `End` left behind) would otherwise address a cell\n * that row doesn't have.\n */\nfunction cellAt(table: HTMLTableElement, focus: GridFocus): HTMLElement | null {\n const row =\n focus.rowIndex === HEADER_ROW\n ? (table.tHead?.rows[0] ?? null)\n : (table.tBodies[0]?.rows[focus.rowIndex] ?? null);\n if (row === null) {\n return null;\n }\n const columnIndex = Math.min(focus.columnIndex, row.cells.length - 1);\n return row.cells[columnIndex] ?? null;\n}\n\n/**\n * Moves one tab stop around the grid, which is what `role=\"grid\"` obliges:\n * arrow keys travel cell to cell and Tab passes the whole grid by.\n *\n * Separate from selection because focus and selection are different states — a\n * cell is focused while travelling before anything is selected, and every cell\n * of a range is selected without being focused. Navigation also has to work\n * with selection turned off entirely, so it cannot depend on it.\n */\nexport default function useGridNavigation({\n tableRef,\n rowCount,\n columnCount,\n}: UseGridNavigationOptions): GridNavigationApi {\n const [stored, setStored] = useState<GridFocus>({\n rowIndex: HEADER_ROW,\n columnIndex: 0,\n });\n\n /**\n * Clamped on the way out rather than written back, so that a coordinate\n * pushed out of range by a change to the data is restored when the data\n * comes back — and so the effect below cannot chase its own output.\n */\n const focus = clampFocus(stored, rowCount, columnCount);\n\n /**\n * Whether the browser's focus still has to be moved to match. Without it\n * every render would pull focus into the grid, including the first.\n */\n const pending = useRef(false);\n\n useEffect(() => {\n if (!pending.current) {\n return;\n }\n pending.current = false;\n const table = tableRef.current;\n if (table === null) {\n return;\n }\n cellAt(table, { rowIndex: focus.rowIndex, columnIndex: focus.columnIndex })\n // Focusing the cell the browser already sits on is a no-op, which is what\n // makes one method serve both a key press and a cell reporting a click.\n ?.focus();\n }, [tableRef, focus.rowIndex, focus.columnIndex]);\n\n /** How many rows fit the viewport, which is what a page key should move. */\n function pageSize(): number {\n const table = tableRef.current;\n const firstRow = table?.tBodies[0]?.rows[0];\n const viewport = table?.parentElement;\n if (\n firstRow === undefined ||\n viewport === null ||\n viewport === undefined ||\n firstRow.offsetHeight === 0\n ) {\n return FALLBACK_PAGE;\n }\n return Math.max(\n 1,\n Math.floor(viewport.clientHeight / firstRow.offsetHeight),\n );\n }\n\n function focusCell(rowIndex: number, columnIndex: number): void {\n const next = clampFocus({ rowIndex, columnIndex }, rowCount, columnCount);\n if (\n next.rowIndex === focus.rowIndex &&\n next.columnIndex === focus.columnIndex\n ) {\n return;\n }\n pending.current = true;\n setStored(next);\n }\n\n function onKeyDown(event: ReactKeyboardEvent<HTMLElement>): void {\n const next = nextFocusForKey(\n event.key,\n {\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n altKey: event.altKey,\n shiftKey: event.shiftKey,\n },\n focus,\n rowCount,\n columnCount,\n pageSize(),\n );\n if (next === null) {\n return;\n }\n\n // Taken even when the move lands nowhere: an arrow at the last row would\n // otherwise scroll the page out from under the grid.\n event.preventDefault();\n focusCell(next.rowIndex, next.columnIndex);\n }\n\n // A new object each render, as the other hooks here return: the handlers\n // close over the focus they move from.\n return {\n focus,\n tabIndexFor: (rowIndex, columnIndex) =>\n tabIndexFor(\n columnIndex,\n rowIndex === focus.rowIndex ? focus.columnIndex : null,\n ),\n focusCell,\n onKeyDown,\n };\n}\n","import {\n useMemo,\n useRef,\n type Dispatch,\n type KeyboardEvent as ReactKeyboardEvent,\n type SetStateAction,\n} from \"react\";\nimport {\n applySelectionIntent,\n clearSelection,\n diffSelection,\n resolveCell,\n resolveColumns,\n resolveRows,\n selectAll,\n selectCell,\n toggleCellSelection,\n type CellSelectionMode,\n type CellSelectionState,\n type ResolvedRow,\n type SelectableConfig,\n type SelectedCellRef,\n type SelectIntent,\n type SelectionMode,\n type SelectionState,\n type RowSelectEvent,\n type RowSelectionChangeEvent,\n type RowsSelectEvent,\n} from \"@gridkitjs/core\";\nimport type {\n CellSelectEvent,\n CellSelectionChangeEvent,\n ColumnSelectEvent,\n ColumnSelectionChangeEvent,\n ColumnsSelectEvent,\n ResolvedColumn,\n} from \"./DataGrid\";\nimport { commitIfChanged } from \"./commitIfChanged\";\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\n/**\n * Reported as the user selects. Every one of these is fanned out from a single\n * diff of the transition it describes, so no two can disagree about what one\n * interaction did.\n */\nexport interface SelectionCallbacks<Row> {\n /** Called once per row newly selected. The last call names the last row. */\n onRowSelect?: ((event: RowSelectEvent<Row>) => void) | undefined;\n /** Called once with every row one interaction selected. */\n onRowsSelect?: ((event: RowsSelectEvent<Row>) => void) | undefined;\n onRowDeselect?: ((event: RowSelectEvent<Row>) => void) | undefined;\n onRowsDeselect?: ((event: RowsSelectEvent<Row>) => void) | undefined;\n /**\n * Called once per change with what it added, what it removed and everything\n * selected after it — the one to persist from.\n */\n onRowSelectionChange?:\n ((event: RowSelectionChangeEvent<Row>) => void) | undefined;\n onColumnSelect?: ((event: ColumnSelectEvent<Row>) => void) | undefined;\n onColumnsSelect?: ((event: ColumnsSelectEvent<Row>) => void) | undefined;\n onColumnDeselect?: ((event: ColumnSelectEvent<Row>) => void) | undefined;\n onColumnsDeselect?: ((event: ColumnsSelectEvent<Row>) => void) | undefined;\n onColumnSelectionChange?:\n ((event: ColumnSelectionChangeEvent<Row>) => void) | undefined;\n onCellSelect?: ((event: CellSelectEvent<Row>) => void) | undefined;\n onCellDeselect?: ((event: CellSelectEvent<Row>) => void) | undefined;\n onCellSelectionChange?:\n ((event: CellSelectionChangeEvent<Row>) => void) | undefined;\n}\n\ninterface UseGridSelectionOptions<Row> {\n rows: readonly ResolvedRow<Row>[];\n columns: readonly ResolvedColumn<Row>[];\n selectable: SelectableConfig | undefined;\n rowSelection: SelectionState;\n setRowSelection: Dispatch<SetStateAction<SelectionState>>;\n columnSelection: SelectionState;\n setColumnSelection: Dispatch<SetStateAction<SelectionState>>;\n cellSelection: CellSelectionState;\n setCellSelection: Dispatch<SetStateAction<CellSelectionState>>;\n callbacks: SelectionCallbacks<Row>;\n announce: (message: string) => void;\n /** What a column is called in an announcement — see `DataGrid.tsx`. */\n columnName: (columnId: string) => string;\n}\n\nexport interface GridSelectionApi {\n rowMode: SelectionMode;\n columnMode: SelectionMode;\n cellMode: CellSelectionMode;\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\nfunction countMessage(count: number, noun: string): string {\n if (count === 0) {\n return `No ${noun}s selected`;\n }\n return count === 1\n ? `1 ${noun} selected`\n : `${String(count)} ${noun}s selected`;\n}\n\n/** A `Set` re-derived only when `values` changes. */\nfunction useAsSet<T>(values: readonly T[]): ReadonlySet<T> {\n return useMemo(() => new Set(values), [values]);\n}\n\n/**\n * A `Map` keying `values` by their `key` property, re-derived only when\n * `values` changes. Takes the key as a property name rather than an\n * extractor function so that it stays a stable dependency across\n * renders — an inline extractor handed in fresh each render would otherwise\n * force a recompute on every render regardless of whether `values` changed.\n */\nfunction useIndexedBy<T, K extends keyof T>(\n values: readonly T[],\n key: K,\n): ReadonlyMap<T[K], T> {\n return useMemo(\n () => new Map(values.map((value) => [value[key], value])),\n [values, key],\n );\n}\n\n/** `values.map((value) => value[key])`, re-derived only when `values` changes. */\nfunction useMappedArray<T, K extends keyof T>(\n values: readonly T[],\n key: K,\n): readonly T[K][] {\n return useMemo(() => values.map((value) => value[key]), [values, key]);\n}\n\n/**\n * Turns an intent against a row, column or cell into the selection it implies,\n * and reports what changed.\n *\n * Holds no state of its own: the three selections live in `DataGrid` beside\n * the sizing and the order, so that a ref exposing them later, or a feature\n * reading them, finds them in one place.\n */\nexport default function useGridSelection<Row>({\n rows,\n columns,\n selectable,\n rowSelection,\n setRowSelection,\n columnSelection,\n setColumnSelection,\n cellSelection,\n setCellSelection,\n callbacks,\n announce,\n columnName,\n}: UseGridSelectionOptions<Row>): GridSelectionApi {\n const rowMode = selectable?.rows ?? false;\n const columnMode = selectable?.columns ?? false;\n const cellMode = selectable?.cells ?? false;\n\n const rowsById = useIndexedBy(rows, \"rowId\");\n const rowIds = useMappedArray(rows, \"rowId\");\n const columnIds = useMappedArray(columns, \"id\");\n\n const selectedRowIds = useAsSet(rowSelection);\n const selectedColumnIds = useAsSet(columnSelection);\n\n /**\n * Where a range is measured from: the last row or column selected by\n * anything but a range, so that repeated Shift-clicks re-draw one span\n * instead of walking the anchor along with them.\n */\n const rowAnchor = useRef<string | null>(null);\n const columnAnchor = useRef<string | null>(null);\n\n /**\n * Announced only for a change touching more than one member. A single\n * selection is already carried by the focused row's own `aria-selected`, and\n * repeating it here would talk over that.\n */\n function announceCount(changed: number, total: number, noun: string): void {\n if (changed > 1) {\n announce(countMessage(total, noun));\n }\n }\n\n function commitRows(next: SelectionState): void {\n // The unchanged-reference contract the core transforms keep: a click that\n // selects what was already selected neither renders nor reports.\n commitIfChanged(rowSelection, next, setRowSelection, (committed) => {\n const { added, removed } = diffSelection(rowSelection, committed);\n const addedRows = resolveRows(rowsById, added);\n const removedRows = resolveRows(rowsById, removed);\n\n for (const row of addedRows) {\n callbacks.onRowSelect?.({ row, selection: committed });\n }\n if (addedRows.length > 0) {\n callbacks.onRowsSelect?.({ rows: addedRows, selection: committed });\n }\n for (const row of removedRows) {\n callbacks.onRowDeselect?.({ row, selection: committed });\n }\n if (removedRows.length > 0) {\n callbacks.onRowsDeselect?.({ rows: removedRows, selection: committed });\n }\n callbacks.onRowSelectionChange?.({\n added: addedRows,\n removed: removedRows,\n selected: resolveRows(rowsById, committed),\n selection: committed,\n });\n announceCount(added.length + removed.length, committed.length, \"row\");\n });\n }\n\n function commitColumns(next: SelectionState): void {\n commitIfChanged(columnSelection, next, setColumnSelection, (committed) => {\n const { added, removed } = diffSelection(columnSelection, committed);\n const addedColumns = resolveColumns(columns, added);\n const removedColumns = resolveColumns(columns, removed);\n\n for (const column of addedColumns) {\n callbacks.onColumnSelect?.({ column, selection: committed });\n }\n if (addedColumns.length > 0) {\n callbacks.onColumnsSelect?.({\n columns: addedColumns,\n selection: committed,\n });\n }\n for (const column of removedColumns) {\n callbacks.onColumnDeselect?.({ column, selection: committed });\n }\n if (removedColumns.length > 0) {\n callbacks.onColumnsDeselect?.({\n columns: removedColumns,\n selection: committed,\n });\n }\n callbacks.onColumnSelectionChange?.({\n added: addedColumns,\n removed: removedColumns,\n selected: resolveColumns(columns, committed),\n selection: committed,\n });\n announceCount(added.length + removed.length, committed.length, \"column\");\n });\n }\n\n function commitCell(next: CellSelectionState): void {\n commitIfChanged(cellSelection, next, setCellSelection, (committed) => {\n // Resolved before and after in one place, so that moving between two\n // cells reports the leaving and the arriving as one change.\n const selected = resolveCell(rowsById, columns, committed);\n const deselected = resolveCell(rowsById, columns, cellSelection);\n\n if (deselected !== null) {\n callbacks.onCellDeselect?.({ cell: deselected, selection: committed });\n }\n if (selected !== null) {\n callbacks.onCellSelect?.({ cell: selected, selection: committed });\n }\n callbacks.onCellSelectionChange?.({\n selected,\n deselected,\n selection: committed,\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\n // `announceCount`'s >1 threshold and the focused cell's own\n // `aria-selected` is the only feedback a screen-reader user would\n // otherwise get. Announced unconditionally here instead, on every\n // commit that lands on a cell.\n if (selected !== null) {\n announce(\n `${columnName(selected.columnId)}, row ${String(selected.rowIndex + 1)}, selected`,\n );\n }\n });\n }\n\n function selectRow(rowId: string, intent: SelectIntent): void {\n const next = applySelectionIntent(\n rowSelection,\n rowIds,\n rowAnchor.current,\n rowId,\n intent,\n rowMode,\n );\n if (intent !== \"range\") {\n rowAnchor.current = rowId;\n }\n commitRows(next);\n }\n\n function selectColumn(columnId: string, intent: SelectIntent): void {\n const next = applySelectionIntent(\n columnSelection,\n columnIds,\n columnAnchor.current,\n columnId,\n intent,\n columnMode,\n );\n if (intent !== \"range\") {\n columnAnchor.current = columnId;\n }\n commitColumns(next);\n }\n\n function selectCellAt(cell: SelectedCellRef, intent: SelectIntent): void {\n // A cell holds one value, so a range over cells has nothing to span and\n // reads as the plain click it looks like.\n commitCell(\n intent === \"toggle\"\n ? toggleCellSelection(cellSelection, cell, cellMode)\n : selectCell(cellSelection, cell, cellMode),\n );\n }\n\n function selectAllRows(): void {\n commitRows(selectAll(rowSelection, rowIds, rowMode));\n }\n\n function clear(): void {\n commitRows(clearSelection(rowSelection));\n commitColumns(clearSelection(columnSelection));\n commitCell(null);\n }\n\n // A new object each render, as the other hooks here return: the handlers\n // close over the selections they transform.\n return {\n rowMode,\n columnMode,\n cellMode,\n selectedRowIds,\n selectedColumnIds,\n selectedCell: cellSelection,\n selectRow,\n selectColumn,\n selectCell: selectCellAt,\n selectAllRows,\n clear,\n };\n}\n","/**\n * The shape behind a click or keypress that changes sort, resize, or\n * selection state: compute the next value, bail out if it's reference-equal\n * to the current one, persist it, then report it. Returns whether it\n * actually committed, for a caller with more to do only when it did.\n */\nexport function commitIfChanged<T>(\n current: T,\n next: T,\n setState: (value: T) => void,\n onCommit?: (next: T) => void,\n): boolean {\n if (next === current) {\n return false;\n }\n setState(next);\n onCommit?.(next);\n return true;\n}\n","import { useMemo } from \"react\";\nimport { groupRowId, intentOf, type DisplayRow } from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport type { GridNavigationApi } from \"../useGridNavigation\";\nimport type { RowGroupingApi } from \"../useRowGrouping\";\nimport {\n keyboardSelectIntent,\n type GridSelectionApi,\n} from \"../useGridSelection\";\nimport GridGroupRow from \"./GridGroupRow\";\nimport GridRow from \"./GridRow\";\n\ninterface GridBodyProps<Row> {\n columns: readonly ResolvedColumn<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 grouping: RowGroupingApi<Row>;\n}\n\n/** Where a cell sits, read off the table's own indices rather than an attribute. */\ninterface CellPosition {\n rowIndex: number;\n columnIndex: number;\n columnId: string;\n}\n\n/**\n * The cell an event happened in. `closest` is what makes the whole cell the\n * target: a click on a template's own markup resolves to the cell holding it.\n *\n * Never matches inside a group-header row: that row's single `<td>` carries\n * no `data-gridkit-column` (it spans every column at once, so no one column\n * id applies), which is what keeps this function — and everything built on\n * it — data-row-only without an explicit `\"kind\"` check of its own.\n */\nfunction cellFrom(target: EventTarget): CellPosition | null {\n if (!(target instanceof Element)) {\n return null;\n }\n const cell = target.closest(\"td[data-gridkit-column]\");\n const row = cell?.parentElement;\n const columnId = cell?.getAttribute(\"data-gridkit-column\");\n if (\n !(cell instanceof HTMLTableCellElement) ||\n !(row instanceof HTMLTableRowElement) ||\n columnId === null ||\n columnId === undefined\n ) {\n return null;\n }\n return {\n rowIndex: row.sectionRowIndex,\n columnIndex: cell.cellIndex,\n columnId,\n };\n}\n\n/** The group-header row an event happened in, if any. */\nfunction groupRowFrom(\n target: EventTarget,\n): { rowIndex: number; groupId: string } | null {\n if (!(target instanceof Element)) {\n return null;\n }\n const row = target.closest(\"tr[data-gridkit-group]\");\n const groupId = row?.getAttribute(\"data-gridkit-group\");\n if (\n !(row instanceof HTMLTableRowElement) ||\n groupId === null ||\n groupId === undefined\n ) {\n return null;\n }\n return { rowIndex: row.sectionRowIndex, groupId };\n}\n\ninterface GroupAriaMeta {\n posinset: number;\n setsize: number;\n}\n\n/**\n * `aria-posinset`/`aria-setsize` per group header: its 1-based position\n * among, and count of, the group headers sharing its level and immediate\n * parent. Depth-first order (see `groupRows`) keeps siblings contiguous, so\n * one pass tallies each parent's total and a second assigns each header's\n * position within it.\n */\nfunction groupAriaMeta<Row>(\n rows: readonly DisplayRow<Row>[],\n): ReadonlyMap<string, GroupAriaMeta> {\n const totals = new Map<string, number>();\n for (const entry of rows) {\n if (!(\"kind\" in entry)) continue;\n const parentKey = groupRowId(entry.path.slice(0, -1));\n totals.set(parentKey, (totals.get(parentKey) ?? 0) + 1);\n }\n\n const seen = new Map<string, number>();\n const meta = new Map<string, GroupAriaMeta>();\n for (const entry of rows) {\n if (!(\"kind\" in entry)) continue;\n const parentKey = groupRowId(entry.path.slice(0, -1));\n const posinset = (seen.get(parentKey) ?? 0) + 1;\n seen.set(parentKey, posinset);\n meta.set(entry.groupId, {\n posinset,\n setsize: totals.get(parentKey) ?? posinset,\n });\n }\n return meta;\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 rows,\n activeColumnId,\n nav,\n selection,\n grouping,\n}: GridBodyProps<Row>) {\n const { selectedCell, rowMode, cellMode } = selection;\n const ariaMeta = useMemo(() => groupAriaMeta(rows), [rows]);\n\n /** The row and cell an event addresses, resolved once for every handler. */\n function targetOf(\n target: EventTarget,\n ): { position: CellPosition; rowId: string } | null {\n const position = cellFrom(target);\n const entry = position === null ? undefined : rows[position.rowIndex];\n if (position === null || entry === undefined || \"kind\" in entry) {\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 const intent = intentOf(modifiers);\n // Independent of each other: selecting a cell says nothing about its row,\n // so a grid with both on reports both.\n if (rowMode !== false) {\n selection.selectRow(rowId, intent);\n }\n if (cellMode !== false) {\n selection.selectCell({ rowId, columnId }, intent);\n }\n }\n\n return (\n <tbody\n className=\"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(group.rowIndex, 0);\n return;\n }\n const found = targetOf(event.target);\n if (found === null) return;\n nav.focusCell(found.position.rowIndex, found.position.columnIndex);\n }}\n onClick={(event) => {\n const group = groupRowFrom(event.target);\n if (group !== null) {\n grouping.toggleExpansion(group.groupId);\n return;\n }\n const found = targetOf(event.target);\n if (found === null) return;\n select(found.rowId, found.position.columnId, event);\n }}\n onKeyDown={(event) => {\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 grouping.toggleExpansion(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 {rows.map((entry) =>\n \"kind\" in entry ? (\n <GridGroupRow\n key={entry.groupId}\n columnCount={columns.length}\n groupId={entry.groupId}\n level={entry.level}\n columnLabel={\n columns.find((column) => column.id === entry.columnId)?.label ??\n entry.columnId\n }\n value={entry.value}\n expanded={entry.expanded}\n count={entry.count}\n rowIndex={entry.rowIndex}\n posinset={ariaMeta.get(entry.groupId)?.posinset ?? 1}\n setsize={ariaMeta.get(entry.groupId)?.setsize ?? 1}\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={nav.focus.rowIndex === entry.rowIndex}\n />\n ) : (\n <GridRow<Row>\n key={entry.rowId}\n columns={columns}\n rowId={entry.rowId}\n row={entry.row}\n rowIndex={entry.rowIndex}\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 that\n * moving the selected cell re-renders the two rows it moved\n * between rather than all of them.\n */\n selectedColumnId={\n selectedCell?.rowId === entry.rowId ? selectedCell.columnId : null\n }\n focusedColumnIndex={\n nav.focus.rowIndex === entry.rowIndex\n ? nav.focus.columnIndex\n : null\n }\n rowsSelectable={rowMode !== false}\n cellsSelectable={cellMode !== false}\n />\n ),\n )}\n </tbody>\n );\n}\n","import { memo, type ReactNode } from \"react\";\nimport { classNames } from \"../classNames\";\n\ninterface GridGroupRowProps {\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 grouped column's own label, whatever its `headerTemplate` returns. */\n columnLabel: ReactNode;\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 /** Position among the display rows as rendered, matching `ResolvedGroupRow.rowIndex`. */\n rowIndex: 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}\n\n/**\n * How a group's own value renders in its header — blank rather than the\n * literal word \"null\"/\"undefined\", and never `Object`'s own\n * `[object Object]` for a value `String()` can't stringify meaningfully.\n */\nfunction formatGroupValue(value: unknown): string {\n if (value === null || value === undefined) {\n return \"(blank)\";\n }\n if (value instanceof Date) {\n return value.toLocaleString();\n }\n switch (typeof value) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"bigint\":\n case \"symbol\":\n return String(value);\n case \"function\":\n return \"(function)\";\n default:\n // Arrays, and anything else a grouped column's value could still be.\n return JSON.stringify(value);\n }\n}\n\nfunction GridGroupRowComponent({\n columnCount,\n groupId,\n level,\n columnLabel,\n value,\n expanded,\n count,\n rowIndex,\n posinset,\n setsize,\n focused,\n}: GridGroupRowProps) {\n return (\n <tr\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.\n aria-rowindex={rowIndex + 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 className={classNames(\n \"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=\"Space Enter\"\n className=\"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=\"grid-group-cell-content\"\n style={{ paddingInlineStart: `${String(level * 1.25 + 0.5)}rem` }}\n >\n <span\n className={classNames(\n \"group-toggle\",\n expanded ? \"is-expanded\" : \"is-collapsed\",\n )}\n aria-hidden=\"true\"\n />\n <span className=\"group-label\">\n {columnLabel}: {formatGroupValue(value)}\n </span>\n <span className=\"group-count\">({count})</span>\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(GridGroupRowComponent);\n\nexport default GridGroupRow;\n","import { accessDotted } from \"@gridkitjs/core\";\nimport { memo, type ReactNode } from \"react\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { ariaAttr } from \"../ariaAttr\";\nimport { classNames } from \"../classNames\";\nimport { tabIndexFor } from \"../useGridNavigation\";\n\ninterface GridRowProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n rowId: string;\n row: Row;\n rowIndex: number;\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}\n\nfunction GridRowComponent<Row>({\n columns,\n rowId,\n row,\n rowIndex,\n activeColumnId,\n selectedColumnIds,\n selected,\n selectedColumnId,\n focusedColumnIndex,\n rowsSelectable,\n cellsSelectable,\n}: GridRowProps<Row>) {\n return (\n <tr\n role=\"row\"\n // Two past the index: rows are counted from one, and the header is the\n // first of them.\n aria-rowindex={rowIndex + 2}\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(\"grid-row\", selected ? \"is-selected\" : \"\")}\n >\n {columns.map(({ id, column, alignment }, columnIndex) => {\n // Resolved either way, so a template that only formats the value never\n // has to walk the field path 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(cellsSelectable, \"aria-keyshortcuts\", \"Space Enter\")}\n className={classNames(\n \"grid-cell\",\n id === activeColumnId ? \"is-resizing\" : \"\",\n cellSelected || selectedColumnIds.has(id) ? \"is-selected\" : \"\",\n column.wrap?.cells ? \"is-wrapped\" : \"\",\n column.cellClassName ?? \"\",\n )}\n style={{ textAlign: alignment }}\n >\n {column.cellTemplate\n ? column.cellTemplate({ value, row, rowIndex, rowId, selected })\n : (value as ReactNode)}\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 { createPortal } from \"react-dom\";\nimport { resolveKeyboardDropTarget } from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"../DataGrid\";\nimport { classNames } from \"../classNames\";\nimport type { GroupByDropTarget } from \"../groupByDropTarget\";\nimport useGroupByDrag from \"../useGroupByDrag\";\nimport type { RowGroupingApi } from \"../useRowGrouping\";\n\ninterface GroupByBarProps<Row> {\n columns: readonly ResolvedColumn<Row>[];\n grouping: RowGroupingApi<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}\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 grouping,\n columnName,\n headerDragEligible,\n headerDragBlocked,\n headerDropTarget,\n}: GroupByBarProps<Row>) {\n const { groupBy } = grouping;\n const groupByIds = groupBy.map((entry) => entry.columnId);\n\n const chipDrag = useGroupByDrag({\n groupBy,\n onDrop: (movedId, beforeColumnId) => {\n grouping.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 return columns.find((entry) => entry.id === columnId)?.label ?? columnId;\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 grouping.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=\"Grouped by\"\n >\n {showPlaceholder && (\n <span className=\"group-by-bar-placeholder\">\n Drag a column here to group by it\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 \"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={\n groupBy.length > 1\n ? `${columnName(entry.columnId)}, level ${String(index + 1)} of ${String(groupBy.length)}`\n : columnName(entry.columnId)\n }\n aria-keyshortcuts=\"Control+ArrowLeft Control+ArrowRight\"\n onPointerDown={(event) => {\n chipDrag.startDrag(entry.columnId, event);\n }}\n onKeyDown={(event) => {\n const horizontal =\n event.key === \"ArrowLeft\" || event.key === \"ArrowRight\";\n if (horizontal && event.ctrlKey) {\n event.preventDefault();\n moveByKeyboard(\n entry.columnId,\n event.key === \"ArrowLeft\" ? -1 : 1,\n );\n }\n }}\n >\n <span className=\"group-by-chip-label\">\n {labelFor(entry.columnId)}\n </span>\n <button\n type=\"button\"\n className=\"group-by-chip-remove\"\n aria-label={`Stop grouping by ${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 grouping.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=\"group-by-chip 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 {\n movesGroupBy,\n resolveDropBefore,\n type GroupByState,\n} from \"@gridkitjs/core\";\nimport { elementAt, sideOf } from \"./useDragReorder\";\n\nexport interface GroupByDropTarget {\n readonly kind: \"group-by\";\n readonly beforeColumnId: string | null;\n}\n\n/**\n * Where a header or chip dropped at `(clientX, clientY)` would land within\n * the group-by bar, or `null` when the pointer isn't over the bar at all, or\n * when the drop would change nothing. Shared by `useColumnDrag` (a header\n * dragged in from outside the bar) and `useGroupByDrag` (a chip dragged\n * within it), so the two can never disagree about where a drop lands.\n */\nexport function resolveGroupByDropTarget(\n clientX: number,\n clientY: number,\n movedId: string,\n groupBy: GroupByState,\n): GroupByDropTarget | null {\n const overBar = elementAt(clientX, clientY, \"[data-gridkit-group-by-bar]\");\n if (overBar === null) {\n return null;\n }\n\n const overChip = elementAt(clientX, clientY, \"[data-gridkit-group-chip]\");\n const chipId = overChip?.getAttribute(\"data-gridkit-group-chip\");\n const beforeColumnId =\n overChip && chipId\n ? resolveDropBefore(\n groupBy.map((entry) => entry.columnId),\n chipId,\n sideOf(overChip, clientX),\n )\n : null; // Over the (possibly empty) bar itself, past every chip: append.\n\n return movesGroupBy(groupBy, movedId, beforeColumnId)\n ? { kind: \"group-by\", beforeColumnId }\n : null;\n}\n","import {\n useRef,\n useState,\n type PointerEvent as ReactPointerEvent,\n} from \"react\";\nimport type { DropSide } from \"@gridkitjs/core\";\nimport { startPointerGesture } from \"./pointerGesture\";\n\n/**\n * How far the pointer travels before a press becomes a drag. Below it the\n * gesture is still a click, which is what leaves the pressed element free to\n * take one — shared by every drag-to-reorder gesture in the grid.\n */\nconst DRAG_THRESHOLD = 4;\n\n/**\n * The closest ancestor of (or the element itself at) `(x, y)` matching\n * `selector`. `closest` is what makes the whole matched element the target:\n * a hit on a descendant (a header's label, a chip's remove button) resolves\n * to it.\n */\nexport function elementAt(\n x: number,\n y: number,\n selector: string,\n): Element | null {\n return document.elementFromPoint(x, y)?.closest(selector) ?? null;\n}\n\n/** Which half of `element` `x` falls in. */\nexport function sideOf(element: Element, x: number): DropSide {\n const rect = element.getBoundingClientRect();\n return x < rect.left + rect.width / 2 ? \"before\" : \"after\";\n}\n\ninterface UseDragReorderOptions<Target> {\n /**\n * Where a drop at `(clientX, clientY)` would land, or `null` for nowhere\n * valid — including a gap `id` already occupies, the same \"promises only\n * moves that happen\" contract every reorder here keeps. Called on every\n * pointer move once the drag has opened; in full control of its own\n * hit-testing, against one destination or several.\n */\n resolveTarget: (\n clientX: number,\n clientY: number,\n id: string,\n ) => Target | null;\n onDrop: (target: Target, id: string) => void;\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. */\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 the gesture that just ended was a drag rather than a click, for\n * a press that has something of its own to do with a click.\n *\n * Reading it clears it, so that a press which never opened a drag at all\n * does not see the last one's answer.\n */\n justDragged: () => boolean;\n}\n\n/**\n * The pointer mechanics behind every drag-to-reorder gesture in the grid —\n * capture, the drag threshold, the trailing ghost, and the click/drag\n * disambiguation `justDragged` reports — extracted so a column header drag\n * and a group-by chip drag (`useColumnDrag`, `useGroupByDrag`) share one\n * implementation and can only ever drift apart in their own hit-testing\n * (`resolveTarget`), not in how a pointer becomes a drag.\n *\n * Pointer events rather than HTML5 drag-and-drop, for the same reason\n * `useColumnDrag` originally chose them: `dragenter`/`dragleave` fire per\n * descendant, so a dragged item's own inner markup would each report the\n * target leaving and re-entering as the pointer crossed them.\n */\nexport default function useDragReorder<Target>({\n resolveTarget,\n onDrop,\n}: UseDragReorderOptions<Target>): DragReorderApi<Target> {\n const [draggedId, setDraggedId] = useState<string | null>(null);\n const [dropTarget, setDropTarget] = useState<Target | null>(null);\n const [ghostTransform, setGhostTransform] = useState<string | null>(null);\n const dragged = useRef(false);\n\n function justDragged(): boolean {\n const answer = dragged.current;\n dragged.current = false;\n return answer;\n }\n\n function startDrag(\n id: string,\n grabElement: HTMLElement,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n const { pointerId, clientX: startX } = event;\n const grabX = startX - grabElement.getBoundingClientRect().left;\n let dragging = false;\n let target: Target | null = null;\n\n /** Keeps the grab offset, so the pointer holds the spot it picked up. */\n function placeGhost(x: number, y: number): void {\n setGhostTransform(`translate(${String(x - grabX)}px, ${String(y)}px)`);\n }\n\n function reset(): void {\n setGhostTransform(null);\n setDraggedId(null);\n setDropTarget(null);\n }\n\n startPointerGesture(grabElement, pointerId, {\n onMove(moveEvent) {\n const { clientX, clientY } = moveEvent;\n\n if (!dragging) {\n if (Math.abs(clientX - startX) < DRAG_THRESHOLD) {\n return;\n }\n dragging = true;\n // Latched for the `click` that follows the release, which is the\n // only thing that can tell a drag apart from a press in the same\n // spot.\n dragged.current = true;\n setDraggedId(id);\n }\n\n placeGhost(clientX, clientY);\n\n target = resolveTarget(clientX, clientY, id);\n setDropTarget(target);\n },\n onEnd() {\n const dropped = target;\n reset();\n if (dragging && dropped !== null) {\n onDrop(dropped, id);\n }\n },\n // Escape and a cancelled pointer both leave the order as it was.\n onCancel() {\n target = null;\n reset();\n },\n });\n }\n\n // A new object each render, as `useColumnDrag`/`useColumnResize` return:\n // the handlers close over `resolveTarget`/`onDrop`, and a stable identity\n // would buy nothing.\n return {\n draggedId,\n dropTarget,\n ghostTransform,\n startDrag,\n justDragged,\n };\n}\n","interface PointerGestureHandlers {\n onMove: (event: PointerEvent) => void;\n onEnd: () => void;\n onCancel: () => void;\n}\n\n/**\n * Wires up a pointer-driven gesture — capture, move tracking, and an\n * Escape-to-cancel — leaving the caller's `onMove`/`onEnd`/`onCancel` to own\n * the gesture's own domain logic (and any state reset that goes with it).\n *\n * A plain function rather than a hook: the caller already owns every piece of\n * state involved via closures, so there is nothing here for React to manage.\n */\nexport function startPointerGesture(\n element: HTMLElement,\n pointerId: number,\n handlers: PointerGestureHandlers,\n): void {\n element.setPointerCapture(pointerId);\n\n function stop(): void {\n element.removeEventListener(\"pointermove\", move);\n element.removeEventListener(\"pointerup\", end);\n element.removeEventListener(\"pointercancel\", cancel);\n window.removeEventListener(\"keydown\", onKeyDown);\n if (element.hasPointerCapture(pointerId)) {\n element.releasePointerCapture(pointerId);\n }\n }\n\n function move(event: PointerEvent): void {\n handlers.onMove(event);\n }\n\n function end(): void {\n stop();\n handlers.onEnd();\n }\n\n function cancel(): void {\n stop();\n handlers.onCancel();\n }\n\n function onKeyDown(event: KeyboardEvent): void {\n if (event.key === \"Escape\") {\n cancel();\n }\n }\n\n element.addEventListener(\"pointermove\", move);\n element.addEventListener(\"pointerup\", end);\n element.addEventListener(\"pointercancel\", cancel);\n window.addEventListener(\"keydown\", onKeyDown);\n}\n","import type { PointerEvent as ReactPointerEvent } from \"react\";\nimport type { GroupByState } from \"@gridkitjs/core\";\nimport {\n resolveGroupByDropTarget,\n type GroupByDropTarget,\n} from \"./groupByDropTarget\";\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 /** Whether the gesture that just ended was a drag rather than a click. */\n justDragged: () => boolean;\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 justDragged: drag.justDragged,\n };\n}\n","import type { PointerEvent as ReactPointerEvent } from \"react\";\nimport {\n movesColumn,\n resolveDropBefore,\n resolveKeyboardDropTarget,\n type ColumnOrderState,\n type GroupByState,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport {\n resolveGroupByDropTarget,\n type GroupByDropTarget,\n} from \"./groupByDropTarget\";\nimport useDragReorder, { elementAt, sideOf } from \"./useDragReorder\";\n\n/**\n * Where a drop would land. A second drop zone — the group-by bar — is a\n * second member here rather than a reshaping of this state, exactly as\n * originally planned: a header dragged past every other header and onto the\n * bar produces `\"group-by\"` instead of `\"column-order\"`, and `handleDrop`\n * switches on `kind`.\n */\nexport type DropTarget =\n { kind: \"column-order\"; beforeId: string | null } | GroupByDropTarget;\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 onDrop: (target: DropTarget, 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: DropTarget | 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 gesture that just ended was a drag rather than a click, for a\n * header that has something of its own to do with a click.\n *\n * Reading it clears it, so that a press which never opened a drag at all —\n * on a column that cannot be reordered — does not see the last one's answer.\n */\n justDragged: () => 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 — this hook\n * supplies only the hit-testing: another header (reorder among columns) or\n * the group-by bar (add this column to the grouping), tried in that order.\n */\nexport default function useColumnDrag<Row>({\n order,\n groupBy,\n groupByDraggableIds,\n onDrop,\n}: UseColumnDragOptions): ColumnDragApi<Row> {\n const drag = useDragReorder<DropTarget>({\n resolveTarget(clientX, clientY, movedId) {\n // Hit-tested rather than read from the event's target, which pointer\n // capture pins to the header the drag opened on.\n const over = elementAt(clientX, clientY, \"th[data-gridkit-column]\");\n const overId = over?.getAttribute(\"data-gridkit-column\");\n\n // The rect is read fresh each move, so a width changed mid-drag\n // cannot leave the midpoint stale.\n const beforeId =\n over && overId\n ? resolveDropBefore(order, overId, sideOf(over, clientX))\n : undefined;\n\n if (beforeId !== undefined) {\n // A gap the column already sits in would promise a move that\n // `moveColumnBefore` then declines to make.\n return movesColumn(order, movedId, beforeId)\n ? { kind: \"column-order\", beforeId }\n : null;\n }\n\n // Already grouped: reordering it is the chip's job, not the header's —\n // dragging it back into the bar is never a valid target.\n const alreadyGrouped = groupBy.some(\n (entry) => entry.columnId === movedId,\n );\n\n return groupByDraggableIds.has(movedId) && !alreadyGrouped\n ? resolveGroupByDropTarget(clientX, clientY, movedId, groupBy)\n : null;\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 Dispatch,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n type SetStateAction,\n} from \"react\";\nimport {\n applyColumnResize,\n beginColumnResize,\n clampColumnWidth,\n resolveColumnConstraints,\n revertColumnSize,\n sizeColumnToContent,\n type ColumnResizeEvent,\n type ColumnSizeDefaults,\n type ColumnSizingState,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport measureColumnContent from \"./measureColumnContent\";\nimport { startPointerGesture } from \"./pointerGesture\";\n\ninterface UseColumnResizeOptions {\n tableRef: RefObject<HTMLTableElement | null>;\n sizing: ColumnSizingState;\n setSizing: Dispatch<SetStateAction<ColumnSizingState>>;\n columnSizeDefaults?: Partial<ColumnSizeDefaults> | undefined;\n onColumnResize?: ((event: ColumnResizeEvent) => void) | 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 sizeToContent: (entry: ResolvedColumn<Row>) => void;\n nudge: (entry: ResolvedColumn<Row>, delta: number) => void;\n}\n\n/**\n * Turns pointer and keyboard input into column widths. Every width it produces\n * comes from `@gridkitjs/core`; this hook only supplies the coordinates.\n */\nexport default function useColumnResize<Row>({\n tableRef,\n sizing,\n setSizing,\n columnSizeDefaults,\n onColumnResize,\n}: UseColumnResizeOptions): ColumnResizeApi<Row> {\n const [activeColumnId, setActiveColumnId] = useState<string | null>(null);\n\n /**\n * Deliberately not built on `commitIfChanged`: its \"move\" phase is called\n * on every pointer move, including ones pinned against a min/max clamp\n * where the resulting width doesn't change, and it intentionally fires\n * `onColumnResize` anyway rather than adopting the bail-if-unchanged guard\n * every other commit-style call site has.\n */\n function commit(\n base: ColumnSizingState,\n columnId: string,\n width: number,\n phase: \"move\" | \"end\",\n ): void {\n const next = { ...base, [columnId]: width };\n setSizing(next);\n onColumnResize?.({ columnId, width, sizing: next, phase });\n }\n\n function startResize(\n entry: ResolvedColumn<Row>,\n event: ReactPointerEvent<HTMLElement>,\n ): void {\n const handle = event.currentTarget;\n const { pointerId } = event;\n const session = beginColumnResize(\n entry.column,\n entry.width,\n event.clientX,\n columnSizeDefaults,\n );\n /**\n * Only the dragged column can change while the drag lasts, so the state as\n * it was when the drag opened stays a correct base to merge into — no ref\n * mirror is needed to dodge a stale closure.\n */\n const base = sizing;\n let width = session.startWidth;\n\n // Otherwise the drag selects the header text it started on.\n event.preventDefault();\n event.stopPropagation();\n setActiveColumnId(session.columnId);\n\n startPointerGesture(handle, pointerId, {\n onMove(moveEvent) {\n width = applyColumnResize(session, moveEvent.clientX);\n commit(base, session.columnId, width, \"move\");\n },\n onEnd() {\n setActiveColumnId(null);\n // A click with no intervening `move` — as every double-click's two\n // constituent clicks are — leaves `width` at `startWidth`. Committing\n // that anyway would fire a spurious onColumnResize on every click.\n if (width !== session.startWidth) {\n commit(base, 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 setSizing((current) => {\n const next = revertColumnSize(current, base, session.columnId);\n onColumnResize?.({\n columnId: session.columnId,\n width: session.startWidth,\n sizing: next,\n phase: \"end\",\n });\n return next;\n });\n },\n });\n }\n\n function sizeToContent(entry: ResolvedColumn<Row>): void {\n const table = tableRef.current;\n if (table === null) {\n return;\n }\n\n const measured = measureColumnContent(table, entry.id);\n if (measured === null) {\n return;\n }\n\n commit(\n sizing,\n entry.id,\n sizeColumnToContent(\n measured,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n }\n\n function nudge(entry: ResolvedColumn<Row>, delta: number): void {\n commit(\n sizing,\n entry.id,\n clampColumnWidth(\n entry.width + delta,\n resolveColumnConstraints(entry.column, columnSizeDefaults),\n ),\n \"end\",\n );\n }\n\n // Deliberately a new object each render: the handlers close over `sizing` to\n // merge into, and a stable identity would need either `sizing` in a\n // `useCallback` dep list (no gain) or the ref mirror avoided above.\n return { activeColumnId, startResize, sizeToContent, nudge };\n}\n","/**\n * The width the widest cell in `columnId` needs to show its content in full,\n * or `null` when the column has no cells.\n *\n * Measured with a `Range` over each cell's contents rather than the cell's own\n * `scrollWidth`. A range shrink-wraps what is actually laid out, so a column\n * far wider than its content reports the content width and can be sized *down*;\n * `scrollWidth` never reports less than the cell it is read from and so can\n * only ever grow a column.\n *\n * Only rendered rows are measured — once paging or virtualisation lands, that\n * means the visible ones.\n */\nexport default function measureColumnContent(\n table: HTMLTableElement,\n columnId: string,\n): number | null {\n const cells = table.querySelectorAll<HTMLElement>(\n `td[data-gridkit-column=\"${CSS.escape(columnId)}\"]`,\n );\n const range = document.createRange();\n let widest: number | null = null;\n\n for (const cell of cells) {\n range.selectNodeContents(cell);\n const style = getComputedStyle(cell);\n // The range covers the content box only, so the cell's own spacing has to\n // be added back or the column would clip by exactly its padding.\n const width =\n range.getBoundingClientRect().width +\n parseFloat(style.paddingLeft) +\n parseFloat(style.paddingRight) +\n parseFloat(style.borderLeftWidth) +\n parseFloat(style.borderRightWidth);\n\n if (widest === null || width > widest) {\n widest = width;\n }\n }\n\n return widest;\n}\n","import type { Dispatch, SetStateAction } from \"react\";\nimport {\n sortDirectionFor,\n sortPriorityFor,\n toggleColumnSort,\n type ColumnSortEvent,\n type ColumnSortState,\n type SortDirection,\n} from \"@gridkitjs/core\";\nimport type { ResolvedColumn } from \"./DataGrid\";\nimport { commitIfChanged } from \"./commitIfChanged\";\n\ninterface UseColumnSortOptions {\n sort: ColumnSortState;\n setSort: Dispatch<SetStateAction<ColumnSortState>>;\n onColumnSortChange?: ((event: ColumnSortEvent) => void) | undefined;\n}\n\nexport interface ColumnSortApi<Row> {\n sort: ColumnSortState;\n /** This column's direction, or `null` if it takes no part in the sort. */\n directionFor: (columnId: string) => SortDirection | null;\n /**\n * This column's 1-based place in the stack, or `null` outside it. Only\n * meaningful once two or more columns are stacked.\n */\n priorityFor: (columnId: string) => number | null;\n /** Cycles `entry`'s sort. A `shiftKey` stacks it; its absence replaces the stack. */\n toggle: (entry: ResolvedColumn<Row>, event: { shiftKey: boolean }) => void;\n}\n\n/**\n * Turns a click or keypress into a sort. Every transition it produces comes\n * from `@gridkitjs/core`; this hook only supplies the state to transform and\n * reports the result.\n */\nexport default function useColumnSort<Row>({\n sort,\n setSort,\n onColumnSortChange,\n}: UseColumnSortOptions): ColumnSortApi<Row> {\n function toggle(\n entry: ResolvedColumn<Row>,\n event: { shiftKey: boolean },\n ): void {\n const next = toggleColumnSort(sort, entry.id, { stack: event.shiftKey });\n commitIfChanged(sort, next, setSort, (committed) => {\n onColumnSortChange?.({ columnId: entry.id, sort: committed });\n });\n }\n\n // A new object each render, as the other hooks here return.\n return {\n sort,\n directionFor: (columnId) => sortDirectionFor(sort, columnId),\n priorityFor: (columnId) => sortPriorityFor(sort, columnId),\n toggle,\n };\n}\n","import { useLayoutEffect, useState, type RefObject } from \"react\";\n\n/**\n * The inner width of `ref`'s element, tracked as it changes.\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. Server rendering would want the usual\n * isomorphic-layout-effect shim here.\n *\n * Reads `clientWidth` rather than the observer entry's `contentRect` so the\n * first measurement and every later one come from the same, already-rounded,\n * source.\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\n setWidth(element.clientWidth);\n\n const observer = new ResizeObserver(() => {\n setWidth(element.clientWidth);\n });\n observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n }, [ref, enabled]);\n\n return width;\n}\n","import type { Dispatch, SetStateAction } from \"react\";\nimport {\n collapseAllGroups,\n expandAllGroups,\n moveGroupByBefore,\n toggleGroupExpansion,\n type DisplayRow,\n type GroupByEvent,\n type GroupByState,\n type GroupExpansionEvent,\n type GroupExpansionState,\n} from \"@gridkitjs/core\";\nimport { commitIfChanged } from \"./commitIfChanged\";\n\ninterface UseRowGroupingOptions {\n groupBy: GroupByState;\n setGroupBy: Dispatch<SetStateAction<GroupByState>>;\n expansion: GroupExpansionState;\n setExpansion: Dispatch<SetStateAction<GroupExpansionState>>;\n onGroupByChange?: ((event: GroupByEvent) => void) | undefined;\n onGroupExpansionChange?: ((event: GroupExpansionEvent) => void) | undefined;\n}\n\nexport interface RowGroupingApi<Row> {\n groupBy: GroupByState;\n expansion: GroupExpansionState;\n isExpanded: (groupId: string) => boolean;\n toggleExpansion: (groupId: string) => void;\n expandAll: () => void;\n collapseAll: (rows: readonly DisplayRow<Row>[]) => void;\n /** Appends or removes columnId from the group-by stack — the state change a group-bar drop or a \"group by this column\" header action produces. */\n toggleGroupBy: (columnId: string) => void;\n /**\n * Adds `columnId` to the group-by stack at a position, or repositions it\n * if it's already there — what dragging a header into the bar, dragging a\n * chip within it, or `Ctrl+ArrowLeft`/`Ctrl+ArrowRight` on a focused chip\n * all produce.\n */\n moveGroupBy: (columnId: string, beforeColumnId: string | null) => void;\n}\n\n/**\n * Turns a group-header click, a \"group by this column\" action, or a\n * group-bar rearrange into the next `GroupByState`/`GroupExpansionState`,\n * committing through `commitIfChanged` exactly as `useColumnSort` does, so a\n * no-op neither re-renders nor fires its `onChange`.\n */\nexport default function useRowGrouping<Row>({\n groupBy,\n setGroupBy,\n expansion,\n setExpansion,\n onGroupByChange,\n onGroupExpansionChange,\n}: UseRowGroupingOptions): RowGroupingApi<Row> {\n function commitExpansion(\n next: GroupExpansionState,\n groupId: string | null,\n ): void {\n commitIfChanged(expansion, next, setExpansion, (committed) => {\n onGroupExpansionChange?.({ groupId, expansion: committed });\n });\n }\n\n function commitGroupBy(next: GroupByState, columnId: string): void {\n commitIfChanged(groupBy, next, setGroupBy, (committed) => {\n onGroupByChange?.({ columnId, groupBy: committed });\n });\n }\n\n function toggleGroupBy(columnId: string): void {\n const isGrouped = groupBy.some((entry) => entry.columnId === columnId);\n const next = isGrouped\n ? groupBy.filter((entry) => entry.columnId !== columnId)\n : [...groupBy, { columnId }];\n commitGroupBy(next, columnId);\n }\n\n function moveGroupBy(columnId: string, beforeColumnId: string | null): void {\n commitGroupBy(\n moveGroupByBefore(groupBy, columnId, beforeColumnId),\n columnId,\n );\n }\n\n return {\n groupBy,\n expansion,\n isExpanded: (groupId) => !expansion.includes(groupId),\n toggleExpansion: (groupId) => {\n commitExpansion(toggleGroupExpansion(expansion, groupId), groupId);\n },\n expandAll: () => {\n commitExpansion(expandAllGroups(expansion), null);\n },\n collapseAll: (rows) => {\n commitExpansion(collapseAllGroups(rows), null);\n },\n toggleGroupBy,\n moveGroupBy,\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA,WAAAA;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OA2BK;;;AC3CP,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB,UAAU,qBAAqB;;;ACEpD,SAAS,SACd,WACA,KACA,OACsC;AACtC,SAAO,YAAa,EAAE,CAAC,GAAG,GAAG,MAAM,IAAqB,CAAC;AAC3D;;;ACVO,SAAS,cACX,QACK;AACR,SAAO,OAAO,OAAO,OAAO,EAAE,KAAK,GAAG;AACxC;;;ACJA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAKP,IAAM,gBAAgB;AA+Bf,SAAS,YACd,aACA,oBACQ;AACR,SAAO,gBAAgB,qBAAqB,IAAI;AAClD;AAeA,SAAS,OAAO,OAAyB,OAAsC;AAC7E,QAAM,MACJ,MAAM,aAAa,aACd,MAAM,OAAO,KAAK,CAAC,KAAK,OACxB,MAAM,QAAQ,CAAC,GAAG,KAAK,MAAM,QAAQ,KAAK;AACjD,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AACA,QAAM,cAAc,KAAK,I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AAAA,UACA,gBAAAA;AAAA,YAAC;AAAA;AAAA,cACC,SAAS;AAAA,cACT;AAAA,cACA;AAAA,cACA,MAAM;AAAA,cACN;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACF;AAAA,UACA,gBAAAA;AAAA,YAAC;AAAA;AAAA,cACC,SAAS;AAAA,cACT,MAAM;AAAA,cACN,gBAAgB,OAAO;AAAA,cACvB;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACF;AAAA;AAAA;AAAA,IACF;AAAA,IAKA,gBAAAA,KAAC,SAAI,WAAU,mBAAkB,MAAK,UAAS,aAAU,UACtD,wBACH;AAAA,KACF;AAEJ;","names":["useMemo","useRef","useState","useRef","useRef","useMemo","intentOf","jsx","jsxs","memo","jsx","memo","jsx","useMemo","intentOf","createPortal","useRef","useState","useState","useRef","jsx","jsxs","createPortal","resolveDropBefore","resolveKeyboardDropTarget","resolveDropBefore","resolveKeyboardDropTarget","useState","useState","useState","jsx","jsxs","useRef","useState","useMemo"]}