@gridkitjs/dom 0.1.0 → 0.2.1
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/README.md +22 -13
- package/dist/index.d.ts +252 -12
- package/dist/index.js +617 -36
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/announcer.ts","../src/bodyTargets.ts","../src/columnResize.ts","../src/pointerGesture.ts","../src/dragReorder.ts","../src/dropTargets.ts","../src/elementWidth.ts","../src/gridFocus.ts","../src/infiniteScroll.ts","../src/overlay/placeOverlay.ts","../src/overlay/attachOverlay.ts","../src/rowVirtualizer.ts"],"sourcesContent":["/** A live region to report changes through. */\nexport interface LiveAnnouncer {\n /**\n * Has assistive technology read `text` out, politely — after whatever it is\n * already saying. The same text twice in a row is read twice.\n */\n readonly announce: (text: string) => void;\n /** Removes the live region. */\n readonly destroy: () => void;\n}\n\n/** Whitespace to a screen reader, but a change to the text it is watching. */\nconst NO_BREAK_SPACE = String.fromCodePoint(0xa0);\n\n/**\n * Creates the one live region a grid reports through — a reorder, a resize, a\n * bulk selection, anything no visual cue can carry to a screen reader — as\n * the last child of `container`.\n *\n * Polite rather than assertive, so an announcement waits for a pause instead\n * of cutting across what the user is already hearing. The element carries\n * `gridkit-sr-only`, which the theme clips to nothing while leaving it in the\n * accessibility tree.\n *\n * A live region speaks only when its text changes, so a message identical to\n * the last would go unheard. A no-break space, added and dropped in turn,\n * makes the repeat a change without changing what is read.\n */\nexport function createLiveAnnouncer(\n container: HTMLElement = document.body,\n): LiveAnnouncer {\n const region = document.createElement(\"div\");\n region.className = \"gridkit-sr-only\";\n region.setAttribute(\"role\", \"status\");\n region.setAttribute(\"aria-live\", \"polite\");\n container.append(region);\n\n let last = \"\";\n let padded = false;\n\n return {\n announce(text) {\n padded = text === last && !padded;\n last = text;\n region.textContent = padded ? text + NO_BREAK_SPACE : text;\n },\n destroy() {\n region.remove();\n },\n };\n}\n","/** The data cell an event happened in. */\nexport interface BodyCellTarget {\n /** The row's place among every body row, from its `data-gridkit-row-index`. */\n readonly rowIndex: number;\n /** The cell's place in its row, off the table's own indices. */\n readonly columnIndex: number;\n readonly columnId: string;\n}\n\n/** The group-header row an event happened in. */\nexport interface GroupRowTarget {\n readonly rowIndex: number;\n readonly groupId: string;\n}\n\n/** The body row an event happened in — a data row, or a group's header or summary. */\nexport interface BodyRowTarget {\n readonly rowIndex: number;\n /** The column of the cell it happened in, `null` when it was in none. */\n readonly columnId: string | null;\n}\n\n/**\n * A row's place among every body row, off the `data-gridkit-row-index` each\n * row carries — not its DOM position, which under virtualization is off by\n * the rows not mounted. `null` without the attribute: a spacer row, or no row\n * at all.\n */\nfunction rowIndexOf(row: Element): number | null {\n const attribute = row.getAttribute(\"data-gridkit-row-index\");\n return attribute === null ? null : Number(attribute);\n}\n\n/**\n * The data cell `target` is in — what a renderer delegating its body's\n * events to one listener asks of each event. `closest` is what makes the\n * whole cell the target: a click on a template's own markup resolves to the\n * 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 keeps this to data rows without a check of its own.\n */\nexport function bodyCellFrom(\n target: EventTarget | null,\n): BodyCellTarget | 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 const rowIndex = row === null || row === undefined ? null : rowIndexOf(row);\n if (\n !(cell instanceof HTMLTableCellElement) ||\n !(row instanceof HTMLTableRowElement) ||\n columnId === null ||\n columnId === undefined ||\n rowIndex === null\n ) {\n return null;\n }\n return { rowIndex, columnIndex: cell.cellIndex, columnId };\n}\n\n/** The group-header row (`tr[data-gridkit-group]`) `target` is in. */\nexport function groupRowFrom(\n target: EventTarget | null,\n): GroupRowTarget | 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 const rowIndex = row === null ? null : rowIndexOf(row);\n if (\n !(row instanceof HTMLTableRowElement) ||\n groupId === null ||\n groupId === undefined ||\n rowIndex === null\n ) {\n return null;\n }\n return { rowIndex, groupId };\n}\n\n/**\n * The row `target` is in, cell or not — all a row click needs. The column is\n * read only off a cell of that very row, so a table inside a cell template\n * cannot lend it one of its own.\n */\nexport function bodyRowFrom(target: EventTarget | null): BodyRowTarget | null {\n if (!(target instanceof Element)) {\n return null;\n }\n const row = target.closest(\"tr[data-gridkit-row-index]\");\n const rowIndex = row === null ? null : rowIndexOf(row);\n if (rowIndex === null) {\n return null;\n }\n const cell = target.closest(\"td[data-gridkit-column]\");\n return {\n rowIndex,\n columnId:\n cell?.parentElement === row\n ? cell.getAttribute(\"data-gridkit-column\")\n : null,\n };\n}\n","import { applyColumnResize, type ColumnResizeSession } from \"@gridkitjs/core\";\nimport {\n isPrimaryPress,\n startPointerGesture,\n type PointerPress,\n} from \"./pointerGesture\";\n\nexport interface ColumnResizeGestureHandlers {\n /** Every pointer move, with the width the column takes there. */\n readonly onMove: (width: number) => void;\n /**\n * The pointer was released. `width` is the width to commit, or `null` when\n * it ended where it started: a click on the handle — as each half of a\n * double-click is — is not a resize, and reporting one would fire a\n * spurious resize on every click.\n */\n readonly onEnd: (width: number | null) => void;\n /** Escape, or a cancelled pointer: the column goes back to `session.startWidth`. */\n readonly onCancel: () => void;\n}\n\n/**\n * Drags a column's edge from `press` on its resize `handle`, turning pointer\n * positions into widths through `@gridkitjs/core`'s `session` — begun with\n * `beginColumnResize` — and reporting them. Returns whether a resize began:\n * only the primary button of the primary pointer starts one.\n *\n * Captures the pointer on `handle`, so the drag keeps reporting wherever the\n * pointer goes, and prevents the press's default, so it does not select the\n * header text it started on. No minimum distance, unlike a reorder drag: the\n * handle does nothing else a press could have meant.\n */\nexport function startColumnResizeGesture(\n handle: HTMLElement,\n press: PointerPress,\n session: ColumnResizeSession,\n handlers: ColumnResizeGestureHandlers,\n): boolean {\n if (!isPrimaryPress(press)) {\n return false;\n }\n press.preventDefault();\n\n let width = session.startWidth;\n startPointerGesture(handle, press.pointerId, {\n onMove(event) {\n width = applyColumnResize(session, event.clientX);\n handlers.onMove(width);\n },\n onEnd() {\n handlers.onEnd(width === session.startWidth ? null : width);\n },\n onCancel() {\n handlers.onCancel();\n },\n });\n return true;\n}\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 — what double-clicking a resize\n * handle sizes the column to, through `sizeColumnToContent`.\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 — on a paged or virtualized grid, the ones\n * on screen.\n */\nexport 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","/**\n * The `pointerdown` a gesture starts from. A native `PointerEvent` is one,\n * and so is a framework's wrapper around it, such as React's synthetic\n * event, so a renderer passes whichever its handler received.\n */\nexport interface PointerPress {\n readonly pointerId: number;\n readonly clientX: number;\n readonly clientY: number;\n readonly button: number;\n readonly isPrimary: boolean;\n preventDefault(): void;\n}\n\n/**\n * Whether `press` may start a gesture: the main button of the primary\n * pointer. A right-click opens a context menu and a second finger is not the\n * gesture already under way, so neither starts a drag or a resize.\n */\nexport function isPrimaryPress(press: PointerPress): boolean {\n return press.button === 0 && press.isPrimary;\n}\n\ninterface 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 */\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 {\n isPrimaryPress,\n startPointerGesture,\n type PointerPress,\n} 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.\n */\nconst DRAG_THRESHOLD = 4;\n\n/** What a renderer draws while a reorder drag is open. */\nexport interface DragReorderState<Target> {\n /** The item being dragged, once the press has become a drag. */\n readonly draggedId: string | null;\n /** Where it would land if released now, `null` for nowhere valid. */\n readonly dropTarget: Target | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n readonly ghostTransform: string | null;\n}\n\n/** The state while nothing is dragged — the one a drag reports when it ends. */\nexport const NO_DRAG: DragReorderState<never> = {\n draggedId: null,\n dropTarget: null,\n ghostTransform: null,\n};\n\nexport interface DragReorderHandlers<Target> {\n /**\n * Where a drop at `(clientX, clientY)` would land, or `null` for nowhere\n * valid — including a gap `id` already occupies, so a drop target only\n * ever promises a move that happens. Called on every pointer move once the\n * drag has opened. `resolveColumnDropTarget` and\n * `resolveGroupByDropTarget` are the grid's own.\n */\n readonly resolveTarget: (\n clientX: number,\n clientY: number,\n id: string,\n ) => Target | null;\n /** Every change to what the renderer draws, `NO_DRAG` once the drag ends. */\n readonly onState: (state: DragReorderState<Target>) => void;\n /** The pointer was released over a valid target. */\n readonly onDrop: (target: Target, id: string) => void;\n}\n\n/**\n * The pointer mechanics behind every drag-to-reorder gesture in the grid — a\n * column header dragged among the others or into the group-by bar, a\n * group-by chip dragged within it: capture, the drag threshold, and the ghost\n * trailing the pointer, holding the spot it was picked up by. Returns whether\n * a gesture began; only the main button of the primary pointer starts one.\n *\n * The press is left to its default, so the pressed element still takes focus;\n * until the pointer has travelled `DRAG_THRESHOLD` pixels nothing is\n * reported, so a press that never moves stays a click. Escape, or a cancelled\n * pointer, leaves the order as it was.\n *\n * Pointer events rather than HTML5 drag-and-drop: `dragenter`/`dragleave`\n * fire per descendant, so a dragged item's own inner markup would each report\n * the target leaving and re-entering as the pointer crossed them.\n */\nexport function startDragReorder<Target>(\n id: string,\n grabElement: HTMLElement,\n press: PointerPress,\n handlers: DragReorderHandlers<Target>,\n): boolean {\n if (!isPrimaryPress(press)) {\n return false;\n }\n\n const { pointerId, clientX: startX } = press;\n const grabX = startX - grabElement.getBoundingClientRect().left;\n let dragging = false;\n let target: Target | null = null;\n\n startPointerGesture(grabElement, pointerId, {\n onMove(moveEvent) {\n const { clientX, clientY } = moveEvent;\n if (!dragging) {\n if (Math.abs(clientX - startX) < DRAG_THRESHOLD) {\n return;\n }\n dragging = true;\n }\n target = handlers.resolveTarget(clientX, clientY, id);\n handlers.onState({\n draggedId: id,\n dropTarget: target,\n ghostTransform: `translate(${String(clientX - grabX)}px, ${String(clientY)}px)`,\n });\n },\n onEnd() {\n const dropped = target;\n handlers.onState(NO_DRAG);\n if (dragging && dropped !== null) {\n handlers.onDrop(dropped, id);\n }\n },\n onCancel() {\n target = null;\n handlers.onState(NO_DRAG);\n },\n });\n return true;\n}\n","import {\n movesColumn,\n movesGroupBy,\n resolveDropBefore,\n type ColumnOrderState,\n type DropSide,\n type GroupByState,\n} from \"@gridkitjs/core\";\n\n/** A drop into the group-by bar, in front of `beforeColumnId` — `null` to append. */\nexport interface GroupByDropTarget {\n readonly kind: \"group-by\";\n readonly beforeColumnId: string | null;\n}\n\n/**\n * Where a dragged column header would land: among the other headers, in\n * front of `beforeId` (`null` for the end), or in the group-by bar.\n */\nexport type ColumnDropTarget =\n | { readonly kind: \"column-order\"; readonly beforeId: string | null }\n | GroupByDropTarget;\n\nexport interface ColumnDropContext {\n /** The ids of the columns on screen, in order — what a drop is resolved among. */\n readonly order: ColumnOrderState;\n /** What a drop onto the group-by bar is resolved against. */\n readonly groupBy: GroupByState;\n /** Column ids whose header may be dragged into the group-by bar at all. */\n readonly groupByDraggableIds: ReadonlySet<string>;\n}\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 *\n * Hit-tested rather than read from an event's target, which pointer capture\n * pins to the element the drag opened on.\n */\nfunction elementAt(x: number, y: number, selector: string): Element | null {\n return document.elementFromPoint(x, y)?.closest(selector) ?? null;\n}\n\n/**\n * Which half of `element` `x` falls in. Read fresh on every move, so a width\n * changed mid-drag cannot leave the midpoint stale.\n */\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 * Where a header or chip dropped at `(clientX, clientY)` would land within\n * the group-by bar (`[data-gridkit-group-by-bar]`, its chips\n * `[data-gridkit-group-chip]`), or `null` when the pointer isn't over the bar\n * at all, or when the drop would change nothing. Shared by a header dragged\n * in from outside the bar and a chip dragged within it, so the two can never\n * 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\n/**\n * Where the header of `movedId` dropped at `(clientX, clientY)` would land:\n * before or after another header (`th[data-gridkit-column]`), by which half\n * of it the pointer is over, or else in the group-by bar — or `null` for\n * nowhere a drop would change anything.\n *\n * A column already grouped never targets the bar: reordering it there is its\n * chip's job, not its header's.\n */\nexport function resolveColumnDropTarget(\n clientX: number,\n clientY: number,\n movedId: string,\n { order, groupBy, groupByDraggableIds }: ColumnDropContext,\n): ColumnDropTarget | null {\n const over = elementAt(clientX, clientY, \"th[data-gridkit-column]\");\n const overId = over?.getAttribute(\"data-gridkit-column\");\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 const alreadyGrouped = groupBy.some((entry) => entry.columnId === movedId);\n return groupByDraggableIds.has(movedId) && !alreadyGrouped\n ? resolveGroupByDropTarget(clientX, clientY, movedId, groupBy)\n : null;\n}\n","/**\n * Reports `element`'s inner width now and on every change after, until the\n * returned function disconnects it — what `resizeMode: \"fit\"` fills.\n *\n * The first report is synchronous, so a renderer calling this before paint\n * lays its columns out at the right width from the first frame rather than\n * visibly jumping once the observer's first callback arrives.\n *\n * Reads `clientWidth` rather than the observer entry's `contentRect` so the\n * first report and every later one come from the same, already-rounded,\n * source.\n */\nexport function observeElementWidth(\n element: HTMLElement,\n onWidth: (width: number) => void,\n): () => void {\n onWidth(element.clientWidth);\n\n const observer = new ResizeObserver(() => {\n onWidth(element.clientWidth);\n });\n observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n}\n","import {\n clampFocus,\n HEADER_ROW,\n nextFocusForKey,\n type GridFocus,\n type NavigationModifiers,\n} from \"@gridkitjs/core\";\n\n/** Rows a page key moves when the viewport cannot be measured. */\nconst FALLBACK_PAGE = 10;\n\n/**\n * The window of rows a row virtualizer has drawn, and a way to bring a row\n * into it — what a focus move needs when its target row may not be mounted.\n */\nexport interface FocusVirtualRange {\n readonly startIndex: number;\n readonly endIndex: number;\n readonly scrollToIndex: (index: number) => void;\n}\n\n/** How to find the rendered rows the browser's focus moves among. */\nexport interface GridFocusRows {\n /** The header row's element, `null` while none is rendered. */\n readonly getHeaderRow: () => HTMLTableRowElement | null;\n /** Body row `rowIndex`'s element — `findBodyRow` finds it — `null` while it is not rendered. */\n readonly getBodyRow: (rowIndex: number) => HTMLTableRowElement | null;\n}\n\nexport interface GridFocusOptions {\n /** Body rows, counting group headers and summaries — every row a key could step through. */\n readonly rowCount: number;\n readonly columnCount: number;\n /**\n * Rows the vertical keys step over rather than stop on — a group's own\n * summary row, which takes a row slot but is not a stop of its own.\n */\n readonly isSkippableRow?: ((rowIndex: number) => boolean) | undefined;\n /**\n * The window the renderer drew, when rows are virtualized. A move can\n * target a row outside it — `ArrowDown` past its end, or `Ctrl+End` — that\n * no lookup would find until it is scrolled into range.\n */\n readonly virtualRange?: FocusVirtualRange | null | undefined;\n}\n\nexport interface GridFocusController {\n /**\n * The cell holding the grid's single tab stop, clamped into the current\n * row and column counts. The same object until it changes, so it can serve\n * as a renderer's snapshot.\n */\n readonly getFocus: () => GridFocus;\n /** Calls `listener` whenever the focused cell moves. Returns the unsubscribe. */\n readonly subscribe: (listener: () => void) => () => void;\n /**\n * Replaces the options, as a renderer does on every render with its\n * current counts and window. Calls no listener: the renderer calling it is\n * already drawing.\n */\n readonly setOptions: (options: GridFocusOptions) => void;\n /**\n * Moves the tab stop, and the browser's focus with it once the renderer\n * has drawn the move (see `focusDrawnCell`). Moving to the cell already\n * focused does nothing, which is what lets a cell's own `focus` event\n * report a click through here without a loop.\n */\n readonly focusCell: (rowIndex: number, columnIndex: number) => void;\n /**\n * Moves the tab stop as `key` does — the arrows, Home, End, the page keys,\n * with Ctrl for the grid's corners. Returns whether the key was one of\n * them, in which case the caller prevents its default: taken even when the\n * move lands nowhere, or an arrow at the last row would scroll the page\n * out from under the grid.\n */\n readonly handleKey: (\n key: string,\n modifiers: NavigationModifiers,\n pageSize: number,\n ) => boolean;\n /**\n * Connects the tab stop to the rendered rows, which the browser's focus\n * then follows it among. Returns the function that disconnects them.\n */\n readonly attach: (rows: GridFocusRows) => () => void;\n /**\n * Called by the renderer once it has drawn `drawn` — a value `getFocus`\n * returned — so the browser's focus follows a move to the cell now in the\n * markup. Does nothing unless a move to exactly that drawing is pending.\n */\n readonly focusDrawnCell: (drawn: GridFocus) => void;\n}\n\n/**\n * The cell at a coordinate. `columnIndex` is clamped to the row's own last\n * cell rather than read directly: a group-header row renders one\n * `<td colSpan>` regardless of the column count, so a focus arriving from a\n * data row further right would otherwise address a cell that row doesn't\n * have.\n */\nfunction cellIn(\n row: HTMLTableRowElement | null,\n columnIndex: number,\n): HTMLElement | null {\n if (row === null) {\n return null;\n }\n return row.cells[Math.min(columnIndex, row.cells.length - 1)] ?? null;\n}\n\n/**\n * Body row `rowIndex` in `bodyTable`, by its `data-gridkit-row-index` rather\n * than by its position in `tBodies[0].rows`: a virtualized body holds only a\n * slice of the rows, behind a leading spacer `<tr>`, so once the window\n * scrolls a DOM position no longer matches the row's index in the full array\n * and addresses some other mounted row, or none.\n *\n * The attribute holds a plain integer, so the selector needs no escaping,\n * unlike one built from a consumer's row id.\n */\nexport function findBodyRow(\n bodyTable: HTMLTableElement | null,\n rowIndex: number,\n): HTMLTableRowElement | null {\n return (\n bodyTable?.tBodies[0]?.querySelector<HTMLTableRowElement>(\n `:scope > tr[data-gridkit-row-index=\"${String(rowIndex)}\"]`,\n ) ?? null\n );\n}\n\n/**\n * How many rows fit `bodyTable`'s scroll wrapper — its parent, the row area\n * alone, not the header, footer and pager around it — which is what a page\n * key moves. Reads the first rendered row's height, and falls back to ten\n * rows when nothing can be measured.\n */\nexport function measurePageSize(bodyTable: HTMLTableElement | null): number {\n const firstRow = bodyTable?.tBodies[0]?.rows[0];\n const viewport = bodyTable?.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(1, Math.floor(viewport.clientHeight / firstRow.offsetHeight));\n}\n\n/**\n * The grid's single tab stop and the keys that move it, which is what\n * `role=\"grid\"` obliges: arrow keys travel cell to cell and Tab passes the\n * whole grid by. The renderer attaches its rows, draws `getFocus()` —\n * `tabindex=\"0\"` on that cell, `-1` on every other — re-reads it when\n * `subscribe` calls, and calls `focusDrawnCell` after drawing.\n *\n * Separate from selection, because focus and selection are different states:\n * a cell is focused while travelling before anything is selected, and every\n * cell of a range is selected without being focused. Navigation also has to\n * work with selection off entirely.\n *\n * Starts on the header row's first cell.\n */\nexport function createGridFocus(\n initialOptions: GridFocusOptions,\n): GridFocusController {\n let options = initialOptions;\n let rows: GridFocusRows | null = null;\n const listeners = new Set<() => void>();\n\n /**\n * Clamped on the way out rather than written back, so a coordinate pushed\n * out of range by a change to the data is restored when the data comes\n * back.\n */\n let stored: GridFocus = { rowIndex: HEADER_ROW, columnIndex: 0 };\n let snapshot = {\n stored,\n rowCount: options.rowCount,\n columnCount: options.columnCount,\n focus: clampFocus(stored, options.rowCount, options.columnCount),\n };\n\n /**\n * The move the browser's focus still has to follow, or `null` once it has.\n * Without it every drawing would pull focus into the grid, the first\n * included.\n *\n * Holds the very `stored` object `focusCell` wrote rather than a flag, so\n * only a drawing made from that move can act on it. Under virtualization a\n * scroll can commit a drawing just before a key press, and a renderer may\n * run that older drawing's after-draw step only once the press has marked\n * a new move pending. With a flag, that stale step found its own (still\n * mounted) cell, focused it and cleared the flag, so the new move's own\n * step returned early and never scrolled its row into range.\n */\n let pendingMove: GridFocus | null = null;\n\n function getFocus(): GridFocus {\n if (\n snapshot.stored !== stored ||\n snapshot.rowCount !== options.rowCount ||\n snapshot.columnCount !== options.columnCount\n ) {\n snapshot = {\n stored,\n rowCount: options.rowCount,\n columnCount: options.columnCount,\n focus: clampFocus(stored, options.rowCount, options.columnCount),\n };\n }\n return snapshot.focus;\n }\n\n function focusCell(rowIndex: number, columnIndex: number): void {\n const next = clampFocus(\n { rowIndex, columnIndex },\n options.rowCount,\n options.columnCount,\n );\n const current = getFocus();\n if (\n next.rowIndex === current.rowIndex &&\n next.columnIndex === current.columnIndex\n ) {\n return;\n }\n pendingMove = next;\n stored = next;\n for (const listener of listeners) {\n listener();\n }\n }\n\n return {\n getFocus,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n setOptions(next) {\n options = next;\n },\n focusCell,\n handleKey(key, modifiers, pageSize) {\n const next = nextFocusForKey(\n key,\n modifiers,\n getFocus(),\n options.rowCount,\n options.columnCount,\n pageSize,\n options.isSkippableRow,\n );\n if (next === null) {\n return false;\n }\n focusCell(next.rowIndex, next.columnIndex);\n return true;\n },\n attach(next) {\n rows = next;\n return () => {\n if (rows === next) {\n rows = null;\n }\n };\n },\n focusDrawnCell(drawn) {\n if (\n rows === null ||\n pendingMove === null ||\n snapshot.stored !== pendingMove ||\n snapshot.focus !== drawn\n ) {\n return;\n }\n const cell = cellIn(\n drawn.rowIndex === HEADER_ROW\n ? rows.getHeaderRow()\n : rows.getBodyRow(drawn.rowIndex),\n drawn.columnIndex,\n );\n if (cell !== null) {\n pendingMove = null;\n // Focusing the cell the browser already sits on is a no-op, which is\n // what makes one method serve both a key press and a cell reporting\n // a click.\n cell.focus();\n return;\n }\n\n // The target row isn't mounted — under virtualization, that means it's\n // outside the drawn window rather than an actual failure. Ask for it to\n // be brought into range; the move stays pending, so the next drawing\n // retries once the row mounts. Without virtualization (or for a row\n // out of bounds even for it) there is nothing further to try, so the\n // move is dropped rather than left to retry forever.\n const range = options.virtualRange;\n if (\n range != null &&\n drawn.rowIndex !== HEADER_ROW &&\n (drawn.rowIndex < range.startIndex || drawn.rowIndex > range.endIndex)\n ) {\n range.scrollToIndex(drawn.rowIndex);\n return;\n }\n pendingMove = null;\n },\n };\n}\n","export interface InfiniteScrollOptions {\n /**\n * The element whose approach triggers a load — the always-last row of the\n * body — or `null` while none is rendered.\n */\n readonly sentinel: Element | null;\n /** Whether a further load could still return more rows. `false` stops watching altogether. */\n readonly hasMore: boolean;\n /**\n * Called at most once per approach: when the sentinel comes within\n * `rootMargin` of the root's visible area, and not again until\n * `isLoadingMore` has gone from `true` back to `false`.\n */\n readonly onLoadMore?: (() => void) | undefined;\n /** Whether a load `onLoadMore` started is still in flight. */\n readonly isLoadingMore?: boolean | undefined;\n /** How far ahead of the sentinel scrolling into view a load starts, as CSS margins. Defaults to `\"200px\"`. */\n readonly rootMargin?: string | undefined;\n}\n\nexport interface InfiniteScroll {\n /**\n * Takes the current options. Cheap when nothing changed, so a renderer may\n * call it after every render; a new sentinel or `rootMargin` restarts the\n * observer, and `isLoadingMore` going back to `false` re-checks at once.\n */\n readonly update: (options: InfiniteScrollOptions) => void;\n /** Stops watching for good. */\n readonly detach: () => void;\n}\n\n/**\n * Turns a sentinel's approach to the bottom of the scrolling `root` into\n * `onLoadMore` calls, no more than one per \"the sentinel is near and no load\n * is in flight since the last one finished\".\n *\n * Three facts drive it: whether the sentinel is intersecting (as of the\n * observer's last report), whether `onLoadMore` has fired since the last\n * load finished, and whether a load was in flight at the last update. They\n * outlive the sentinel itself, which a renderer mounts and unmounts as\n * `hasMore` changes, so they live here rather than on any one observer.\n *\n * Off means off: with `hasMore` false, or no sentinel, no observer exists.\n */\nexport function attachInfiniteScroll(\n root: Element,\n options: InfiniteScrollOptions,\n): InfiniteScroll {\n let latest = options;\n let intersecting = false;\n /** Set once `onLoadMore` fires, cleared only when a load finishes. */\n let fired = false;\n let wasLoading = options.isLoadingMore ?? false;\n let observer: IntersectionObserver | null = null;\n let observed: { sentinel: Element; rootMargin: string } | null = null;\n\n function maybeLoadMore(): void {\n if (\n !intersecting ||\n !latest.hasMore ||\n (latest.isLoadingMore ?? false) ||\n fired\n ) {\n return;\n }\n fired = true;\n latest.onLoadMore?.();\n }\n\n function disconnect(): void {\n observer?.disconnect();\n observer = null;\n observed = null;\n intersecting = false;\n }\n\n function observe(): void {\n const sentinel = latest.hasMore ? latest.sentinel : null;\n const rootMargin = latest.rootMargin ?? \"200px\";\n if (\n observed !== null &&\n observed.sentinel === sentinel &&\n observed.rootMargin === rootMargin\n ) {\n return;\n }\n disconnect();\n if (sentinel === null) {\n return;\n }\n observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[entries.length - 1];\n if (entry === undefined) {\n return;\n }\n intersecting = entry.isIntersecting;\n maybeLoadMore();\n },\n { root, rootMargin },\n );\n observer.observe(sentinel);\n observed = { sentinel, rootMargin };\n }\n\n observe();\n\n return {\n update(next) {\n latest = next;\n const loading = next.isLoadingMore ?? false;\n if (wasLoading && !loading) {\n fired = false;\n // The rows a finished load appended may not have pushed the sentinel\n // out of `rootMargin` at all, in which case it never leaves and\n // re-enters — no observer report would come to trigger the next load.\n maybeLoadMore();\n }\n wasLoading = loading;\n observe();\n },\n detach: disconnect,\n };\n}\n","/** Which side of its anchor an overlay opens on. */\nexport type OverlaySide = \"top\" | \"bottom\" | \"left\" | \"right\";\n\n/**\n * Which edge of the anchor the overlay lines up with along that side: its\n * left edge (`start`) or right edge (`end`) for `top`/`bottom`, its top or\n * bottom edge for `left`/`right`.\n */\nexport type OverlayAlign = \"start\" | \"end\";\n\nexport type OverlayPlacement = `${OverlaySide}-${OverlayAlign}`;\n\n/** A box in viewport coordinates, as `getBoundingClientRect` reports one. */\nexport interface OverlayRect {\n readonly top: number;\n readonly left: number;\n readonly width: number;\n readonly height: number;\n}\n\nexport interface OverlaySize {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface OverlayPlacementOptions {\n /** Where the overlay would rather open. Defaults to `\"bottom-start\"`. */\n readonly placement?: OverlayPlacement | undefined;\n /** Space between the anchor and the overlay, in pixels. Defaults to `0`. */\n readonly gap?: number | undefined;\n}\n\n/** Where an overlay goes: its top-left corner, and the placement it ended up with. */\nexport interface OverlayPosition {\n readonly top: number;\n readonly left: number;\n readonly placement: OverlayPlacement;\n}\n\nconst OPPOSITE_SIDE: Readonly<Record<OverlaySide, OverlaySide>> = {\n top: \"bottom\",\n bottom: \"top\",\n left: \"right\",\n right: \"left\",\n};\n\nfunction isVertical(side: OverlaySide): boolean {\n return side === \"top\" || side === \"bottom\";\n}\n\n/** How much room `side` of `anchor` leaves before the viewport's edge. */\nfunction roomBeside(\n side: OverlaySide,\n anchor: OverlayRect,\n viewport: OverlaySize,\n): number {\n switch (side) {\n case \"top\":\n return anchor.top;\n case \"bottom\":\n return viewport.height - (anchor.top + anchor.height);\n case \"left\":\n return anchor.left;\n case \"right\":\n return viewport.width - (anchor.left + anchor.width);\n }\n}\n\n/**\n * The preferred side if the overlay fits there, the opposite one if it fits\n * there instead, and otherwise whichever has more room — a menu too tall for\n * either still shows as much of itself as it can.\n */\nfunction chooseSide(\n preferred: OverlaySide,\n needed: number,\n anchor: OverlayRect,\n viewport: OverlaySize,\n): OverlaySide {\n const opposite = OPPOSITE_SIDE[preferred];\n const room = roomBeside(preferred, anchor, viewport);\n const oppositeRoom = roomBeside(opposite, anchor, viewport);\n if (room >= needed) {\n return preferred;\n }\n return oppositeRoom >= needed || oppositeRoom > room ? opposite : preferred;\n}\n\n/** The preferred edge unless only the other one keeps the overlay on screen. */\nfunction chooseAlign(\n preferred: OverlayAlign,\n fitsAtStart: boolean,\n fitsAtEnd: boolean,\n): OverlayAlign {\n if (preferred === \"start\") {\n return fitsAtStart || !fitsAtEnd ? \"start\" : \"end\";\n }\n return fitsAtEnd || !fitsAtStart ? \"end\" : \"start\";\n}\n\n/** The overlay's offset away from the anchor: its top for `top`/`bottom`, its left otherwise. */\nfunction offsetBeside(\n side: OverlaySide,\n anchor: OverlayRect,\n panel: OverlaySize,\n gap: number,\n): number {\n switch (side) {\n case \"top\":\n return anchor.top - gap - panel.height;\n case \"bottom\":\n return anchor.top + anchor.height + gap;\n case \"left\":\n return anchor.left - gap - panel.width;\n case \"right\":\n return anchor.left + anchor.width + gap;\n }\n}\n\n/** Keeps `value` within `[0, limit]`, pinning to `0` when even that fails. */\nfunction clampIntoView(value: number, limit: number): number {\n return Math.max(0, Math.min(value, limit));\n}\n\n/**\n * Where an overlay of size `panel` goes beside `anchor` so that it stays in\n * `viewport`: on the preferred side unless only the opposite one has room,\n * lined up with the preferred edge unless that runs it off screen and the\n * other edge does not, and finally pushed back inside if it still overflows.\n * Pure, so the rules are testable without a browser; `attachOverlay` feeds it\n * the measurements.\n *\n * A point — a context menu opened where the pointer is — is an anchor with\n * no width or height, which is what makes `start`/`end` mean \"after\" and\n * \"before\" it.\n */\nexport function placeOverlay(\n anchor: OverlayRect,\n panel: OverlaySize,\n viewport: OverlaySize,\n options: OverlayPlacementOptions = {},\n): OverlayPosition {\n const [preferredSide, preferredAlign] = (\n options.placement ?? \"bottom-start\"\n ).split(\"-\") as [OverlaySide, OverlayAlign];\n const gap = options.gap ?? 0;\n const vertical = isVertical(preferredSide);\n\n const side = chooseSide(\n preferredSide,\n (vertical ? panel.height : panel.width) + gap,\n anchor,\n viewport,\n );\n\n // The axis the overlay runs along beside the anchor.\n const anchorStart = vertical ? anchor.left : anchor.top;\n const anchorEnd = anchorStart + (vertical ? anchor.width : anchor.height);\n const extent = vertical ? panel.width : panel.height;\n const room = vertical ? viewport.width : viewport.height;\n const align = chooseAlign(\n preferredAlign,\n anchorStart + extent <= room,\n anchorEnd - extent >= 0,\n );\n const along = align === \"start\" ? anchorStart : anchorEnd - extent;\n const away = offsetBeside(side, anchor, panel, gap);\n\n return {\n top: clampIntoView(vertical ? away : along, viewport.height - panel.height),\n left: clampIntoView(vertical ? along : away, viewport.width - panel.width),\n placement: `${side}-${align}`,\n };\n}\n","import {\n placeOverlay,\n type OverlayPlacementOptions,\n type OverlayRect,\n} from \"./placeOverlay\";\n\n/** What an overlay opens beside: an element, or a point in viewport coordinates. */\nexport type OverlayAnchor =\n Element | { readonly x: number; readonly y: number };\n\n/** Why an overlay asked to close. */\nexport type OverlayDismissReason =\n \"escape\" | \"outside\" | \"scroll\" | \"resize\" | \"blur\";\n\nexport interface OverlayOptions extends OverlayPlacementOptions {\n /**\n * The overlay asks to close: Escape was pressed, a pointer went down\n * outside it, something outside it scrolled, the window resized or lost\n * focus, or focus moved outside it. The caller closes it — removes the\n * panel and detaches — or keeps it open by doing nothing.\n */\n readonly onDismiss: (reason: OverlayDismissReason) => void;\n /**\n * Where focus goes when the overlay detaches. Defaults to the element that\n * had focus when it attached; `null` leaves focus alone.\n */\n readonly returnFocusTo?: HTMLElement | null | undefined;\n}\n\n/** Everything focusable by script, so a menu's `tabindex=\"-1\"` items count. */\nconst FOCUSABLE =\n \"a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]\";\n\nfunction anchorRect(anchor: OverlayAnchor): OverlayRect {\n if (anchor instanceof Element) {\n const { top, left, width, height } = anchor.getBoundingClientRect();\n return { top, left, width, height };\n }\n return { top: anchor.y, left: anchor.x, width: 0, height: 0 };\n}\n\n/**\n * Shows `panel` as an overlay beside `anchor` — a menu, a popover, a filter\n * editor — and returns the function that ends it. The caller renders the\n * panel, usually as a child of `document.body` so no scrolling ancestor clips\n * it; this positions it, moves focus into it, and reports through\n * `onDismiss` when the user is done with it.\n *\n * The panel is positioned `fixed`, at the place `placeOverlay` picks from the\n * anchor's and the panel's measured boxes, and carries that placement in\n * `data-gridkit-placement` (`\"top-start\"` once flipped above, say) for a\n * stylesheet to point an arrow by. Focus moves to the panel's first focusable\n * descendant, or to the panel itself — given `tabindex=\"-1\"` if it has no\n * `tabindex` — when there is none.\n *\n * Nothing that happens on or in the anchor dismisses the overlay, so a button\n * that toggles it can close it with its own click rather than having the\n * overlay close and the click reopen it.\n *\n * Detaching removes every listener and returns focus, but only when focus is\n * still in the panel or nowhere — a click that dismissed it by landing on\n * another control leaves focus on that control.\n */\nexport function attachOverlay(\n anchor: OverlayAnchor,\n panel: HTMLElement,\n options: OverlayOptions,\n): () => void {\n const { onDismiss } = options;\n const returnFocusTo =\n options.returnFocusTo === undefined\n ? document.activeElement instanceof HTMLElement\n ? document.activeElement\n : null\n : options.returnFocusTo;\n\n function belongs(target: EventTarget | null): boolean {\n return (\n target instanceof Node &&\n (panel.contains(target) ||\n (anchor instanceof Element && anchor.contains(target)))\n );\n }\n\n function onKeyDown(event: KeyboardEvent): void {\n if (event.key === \"Escape\") {\n onDismiss(\"escape\");\n }\n }\n\n function onPointerDown(event: PointerEvent): void {\n if (!belongs(event.target)) {\n onDismiss(\"outside\");\n }\n }\n\n // The overlay is placed in viewport coordinates, so any scroll that moves\n // its anchor leaves it behind — except a scroll inside the panel itself.\n function onScroll(event: Event): void {\n if (!(event.target instanceof Node && panel.contains(event.target))) {\n onDismiss(\"scroll\");\n }\n }\n\n function onResize(): void {\n onDismiss(\"resize\");\n }\n\n // Only a move to somewhere definite counts: focus dropping to nothing, as\n // when the focused item re-renders away, is not the user leaving.\n function onFocusOut(event: FocusEvent): void {\n if (event.relatedTarget !== null && !belongs(event.relatedTarget)) {\n onDismiss(\"blur\");\n }\n }\n\n function onWindowBlur(): void {\n onDismiss(\"blur\");\n }\n\n // Shrink-wrapped before it is measured: in normal flow a block panel\n // would report the full width of the page.\n panel.style.position = \"fixed\";\n panel.style.top = \"0px\";\n panel.style.left = \"0px\";\n const { width, height } = panel.getBoundingClientRect();\n const position = placeOverlay(\n anchorRect(anchor),\n { width, height },\n {\n width: document.documentElement.clientWidth,\n height: document.documentElement.clientHeight,\n },\n options,\n );\n panel.style.top = `${String(position.top)}px`;\n panel.style.left = `${String(position.left)}px`;\n panel.setAttribute(\"data-gridkit-placement\", position.placement);\n\n const first = panel.querySelector<HTMLElement>(FOCUSABLE);\n if (first === null && !panel.hasAttribute(\"tabindex\")) {\n panel.tabIndex = -1;\n }\n (first ?? panel).focus({ preventScroll: true });\n\n document.addEventListener(\"keydown\", onKeyDown, true);\n document.addEventListener(\"pointerdown\", onPointerDown, true);\n window.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n window.addEventListener(\"resize\", onResize);\n window.addEventListener(\"blur\", onWindowBlur);\n panel.addEventListener(\"focusout\", onFocusOut);\n\n let attached = true;\n return () => {\n if (!attached) {\n return;\n }\n attached = false;\n document.removeEventListener(\"keydown\", onKeyDown, true);\n document.removeEventListener(\"pointerdown\", onPointerDown, true);\n window.removeEventListener(\"scroll\", onScroll, { capture: true });\n window.removeEventListener(\"resize\", onResize);\n window.removeEventListener(\"blur\", onWindowBlur);\n panel.removeEventListener(\"focusout\", onFocusOut);\n\n const active = document.activeElement;\n if (\n returnFocusTo !== null &&\n (active === null || active === document.body || panel.contains(active))\n ) {\n returnFocusTo.focus({ preventScroll: true });\n }\n };\n}\n","import { visibleRange, type VisibleRange } from \"@gridkitjs/core\";\n\nexport interface RowVirtualizerOptions {\n /** The height assumed for a row not yet measured. */\n readonly estimatedRowHeight: number;\n /** Rows rendered beyond each edge of the visible area. */\n readonly overscan: number;\n /**\n * The window of rows to render moved: called whenever a scroll, a resize\n * of the scroll element, a measured row height or a change of rows moves\n * it, and never with a window equal to the last.\n */\n readonly onRange: (range: VisibleRange) => void;\n}\n\nexport interface RowVirtualizer {\n /** How many rows there are. Measured heights of the rows that remain are kept. */\n readonly setRowCount: (count: number) => void;\n /** Forgets every measured height, for rows that are no longer the ones measured. */\n readonly resetHeights: () => void;\n /**\n * A ref callback for the element of row `index` (its place among all the\n * rows, not among those rendered): measured while mounted, forgotten once\n * called with `null`. The same function for the same index every time, so\n * a renderer re-attaching it on every render costs nothing.\n */\n readonly measureRow: (index: number) => (element: HTMLElement | null) => void;\n /**\n * Scrolls so row `index` is in view. A mounted row is scrolled to directly;\n * one outside the window is jumped to at its estimated offset, then\n * scrolled to properly once it mounts and can be measured.\n */\n readonly scrollToIndex: (\n index: number,\n options?: ScrollIntoViewOptions,\n ) => void;\n /** Stops listening and measuring, for good. */\n readonly destroy: () => void;\n}\n\nfunction sameRange(a: VisibleRange, b: VisibleRange): boolean {\n return (\n a.startIndex === b.startIndex &&\n a.endIndex === b.endIndex &&\n a.offsetBefore === b.offsetBefore &&\n a.offsetAfter === b.offsetAfter\n );\n}\n\n/**\n * Windows a long list of rows inside `scrollElement` down to those near its\n * scroll position, measuring each rendered row's real height rather than\n * assuming a uniform one — rows are not uniform (`.is-wrapped` cells, group\n * header and summary rows), so a fixed-height virtualizer would either break\n * wrapping or rule it out. The renderer draws `onRange`'s window, with\n * spacers of `offsetBefore`/`offsetAfter` around it, and hands each row's\n * element to `measureRow`.\n *\n * The heights are a mutable array, not a structure rebuilt per measurement:\n * one can arrive many times a second while scrolling. The pure arithmetic\n * over them is `@gridkitjs/core`'s `visibleRange`; this owns only the\n * mutability around it and the listeners that feed it — the scroll position,\n * the scroll element's height, and one `ResizeObserver` shared by every\n * mounted row.\n */\nexport function createRowVirtualizer(\n scrollElement: HTMLElement,\n options: RowVirtualizerOptions,\n): RowVirtualizer {\n const { estimatedRowHeight, overscan, onRange } = options;\n\n let heights: (number | undefined)[] = [];\n let scrollTop = scrollElement.scrollTop;\n let viewportHeight = scrollElement.clientHeight;\n let range: VisibleRange | null = null;\n let destroyed = false;\n /** The row `scrollToIndex` is still waiting to mount, to scroll to it properly. */\n let pendingScroll:\n { index: number; options: ScrollIntoViewOptions | undefined } | undefined;\n\n const elements = new Map<number, HTMLElement>();\n const indexByElement = new Map<Element, number>();\n const refCallbacks = new Map<number, (element: HTMLElement | null) => void>();\n\n function recompute(): void {\n if (destroyed) {\n return;\n }\n const next = visibleRange(\n heights,\n estimatedRowHeight,\n scrollTop,\n viewportHeight,\n overscan,\n );\n if (range !== null && sameRange(range, next)) {\n return;\n }\n range = next;\n onRange(next);\n }\n\n const rowObserver = new ResizeObserver((entries) => {\n let changed = false;\n for (const entry of entries) {\n const index = indexByElement.get(entry.target);\n if (index === undefined) continue;\n const height = entry.target.getBoundingClientRect().height;\n if (heights[index] !== height) {\n heights[index] = height;\n changed = true;\n }\n }\n if (changed) {\n recompute();\n }\n });\n\n // Kept current here rather than read on each recompute: a scroll can fire\n // many times a second, and each one only needs to feed the next window.\n const viewportObserver = new ResizeObserver(() => {\n viewportHeight = scrollElement.clientHeight;\n recompute();\n });\n viewportObserver.observe(scrollElement);\n\n function handleScroll(): void {\n scrollTop = scrollElement.scrollTop;\n recompute();\n }\n scrollElement.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n function estimateOffsetBefore(index: number): number {\n let total = 0;\n for (let current = 0; current < index; current++) {\n total += heights[current] ?? estimatedRowHeight;\n }\n return total;\n }\n\n recompute();\n\n return {\n setRowCount(count) {\n heights = Array.from({ length: count }, (_, index) => heights[index]);\n recompute();\n },\n resetHeights() {\n heights = new Array<number | undefined>(heights.length).fill(undefined);\n recompute();\n },\n measureRow(index) {\n let callback = refCallbacks.get(index);\n if (callback === undefined) {\n callback = (element) => {\n const previous = elements.get(index);\n if (previous !== undefined) {\n rowObserver.unobserve(previous);\n indexByElement.delete(previous);\n elements.delete(index);\n }\n if (element === null || destroyed) {\n return;\n }\n elements.set(index, element);\n indexByElement.set(element, index);\n rowObserver.observe(element);\n if (pendingScroll?.index === index) {\n element.scrollIntoView(pendingScroll.options);\n pendingScroll = undefined;\n }\n };\n refCallbacks.set(index, callback);\n }\n return callback;\n },\n scrollToIndex(index, scrollOptions) {\n if (heights.length === 0) {\n return;\n }\n const clamped = Math.max(0, Math.min(index, heights.length - 1));\n const mounted = elements.get(clamped);\n if (mounted !== undefined) {\n mounted.scrollIntoView(scrollOptions);\n return;\n }\n pendingScroll = { index: clamped, options: scrollOptions };\n scrollElement.scrollTop = estimateOffsetBefore(clamped);\n },\n destroy() {\n destroyed = true;\n pendingScroll = undefined;\n scrollElement.removeEventListener(\"scroll\", handleScroll);\n viewportObserver.disconnect();\n rowObserver.disconnect();\n elements.clear();\n indexByElement.clear();\n },\n };\n}\n"],"mappings":";AAYA,IAAM,iBAAiB,OAAO,cAAc,GAAI;AAgBzC,SAAS,oBACd,YAAyB,SAAS,MACnB;AACf,QAAM,SAAS,SAAS,cAAc,KAAK;AAC3C,SAAO,YAAY;AACnB,SAAO,aAAa,QAAQ,QAAQ;AACpC,SAAO,aAAa,aAAa,QAAQ;AACzC,YAAU,OAAO,MAAM;AAEvB,MAAI,OAAO;AACX,MAAI,SAAS;AAEb,SAAO;AAAA,IACL,SAAS,MAAM;AACb,eAAS,SAAS,QAAQ,CAAC;AAC3B,aAAO;AACP,aAAO,cAAc,SAAS,OAAO,iBAAiB;AAAA,IACxD;AAAA,IACA,UAAU;AACR,aAAO,OAAO;AAAA,IAChB;AAAA,EACF;AACF;;;ACtBA,SAAS,WAAW,KAA6B;AAC/C,QAAM,YAAY,IAAI,aAAa,wBAAwB;AAC3D,SAAO,cAAc,OAAO,OAAO,OAAO,SAAS;AACrD;AAYO,SAAS,aACd,QACuB;AACvB,MAAI,EAAE,kBAAkB,UAAU;AAChC,WAAO;AAAA,EACT;AACA,QAAM,OAAO,OAAO,QAAQ,yBAAyB;AACrD,QAAM,MAAM,MAAM;AAClB,QAAM,WAAW,MAAM,aAAa,qBAAqB;AACzD,QAAM,WAAW,QAAQ,QAAQ,QAAQ,SAAY,OAAO,WAAW,GAAG;AAC1E,MACE,EA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oBAAoB,UAAU,YAAY;AACxD,uBAAiB,WAAW;AAC5B,kBAAY,WAAW;AACvB,eAAS,MAAM;AACf,qBAAe,MAAM;AAAA,IACvB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/announcer.ts","../src/bodyTargets.ts","../src/contextMenu/attachContextMenuTrigger.ts","../src/columnResize.ts","../src/pointerGesture.ts","../src/dragReorder.ts","../src/dropTargets.ts","../src/elementWidth.ts","../src/gridFocus.ts","../src/infiniteScroll.ts","../src/menu/attachMenu.ts","../src/overlay/overlayStack.ts","../src/overlay/placeOverlay.ts","../src/overlay/attachOverlay.ts","../src/rowVirtualizer.ts","../src/toolbar/attachToolbar.ts","../src/toolbar/observeToolbarOverflow.ts"],"sourcesContent":["/** A live region to report changes through. */\nexport interface LiveAnnouncer {\n /**\n * Has assistive technology read `text` out, politely — after whatever it is\n * already saying. The same text twice in a row is read twice.\n */\n readonly announce: (text: string) => void;\n /** Removes the live region. */\n readonly destroy: () => void;\n}\n\n/** Whitespace to a screen reader, but a change to the text it is watching. */\nconst NO_BREAK_SPACE = String.fromCodePoint(0xa0);\n\n/**\n * Creates the one live region a grid reports through — a reorder, a resize, a\n * bulk selection, anything no visual cue can carry to a screen reader — as\n * the last child of `container`.\n *\n * Polite rather than assertive, so an announcement waits for a pause instead\n * of cutting across what the user is already hearing. The element carries\n * `gridkit-sr-only`, which the theme clips to nothing while leaving it in the\n * accessibility tree.\n *\n * A live region speaks only when its text changes, so a message identical to\n * the last would go unheard. A no-break space, added and dropped in turn,\n * makes the repeat a change without changing what is read.\n */\nexport function createLiveAnnouncer(\n container: HTMLElement = document.body,\n): LiveAnnouncer {\n const region = document.createElement(\"div\");\n region.className = \"gridkit-sr-only\";\n region.setAttribute(\"role\", \"status\");\n region.setAttribute(\"aria-live\", \"polite\");\n container.append(region);\n\n let last = \"\";\n let padded = false;\n\n return {\n announce(text) {\n padded = text === last && !padded;\n last = text;\n region.textContent = padded ? text + NO_BREAK_SPACE : text;\n },\n destroy() {\n region.remove();\n },\n };\n}\n","/** The data cell an event happened in. */\nexport interface BodyCellTarget {\n /** The row's place among every body row, from its `data-gridkit-row-index`. */\n readonly rowIndex: number;\n /** The cell's place in its row, off the table's own indices. */\n readonly columnIndex: number;\n readonly columnId: string;\n}\n\n/** The group-header row an event happened in. */\nexport interface GroupRowTarget {\n readonly rowIndex: number;\n readonly groupId: string;\n}\n\n/** The body row an event happened in — a data row, or a group's header or summary. */\nexport interface BodyRowTarget {\n readonly rowIndex: number;\n /** The column of the cell it happened in, `null` when it was in none. */\n readonly columnId: string | null;\n}\n\n/**\n * A row's place among every body row, off the `data-gridkit-row-index` each\n * row carries — not its DOM position, which under virtualization is off by\n * the rows not mounted. `null` without the attribute: a spacer row, or no row\n * at all.\n */\nfunction rowIndexOf(row: Element): number | null {\n const attribute = row.getAttribute(\"data-gridkit-row-index\");\n return attribute === null ? null : Number(attribute);\n}\n\n/**\n * The data cell `target` is in — what a renderer delegating its body's\n * events to one listener asks of each event. `closest` is what makes the\n * whole cell the target: a click on a template's own markup resolves to the\n * 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 keeps this to data rows without a check of its own.\n */\nexport function bodyCellFrom(\n target: EventTarget | null,\n): BodyCellTarget | 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 const rowIndex = row === null || row === undefined ? null : rowIndexOf(row);\n if (\n !(cell instanceof HTMLTableCellElement) ||\n !(row instanceof HTMLTableRowElement) ||\n columnId === null ||\n columnId === undefined ||\n rowIndex === null\n ) {\n return null;\n }\n return { rowIndex, columnIndex: cell.cellIndex, columnId };\n}\n\n/** The group-header row (`tr[data-gridkit-group]`) `target` is in. */\nexport function groupRowFrom(\n target: EventTarget | null,\n): GroupRowTarget | 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 const rowIndex = row === null ? null : rowIndexOf(row);\n if (\n !(row instanceof HTMLTableRowElement) ||\n groupId === null ||\n groupId === undefined ||\n rowIndex === null\n ) {\n return null;\n }\n return { rowIndex, groupId };\n}\n\n/**\n * The row `target` is in, cell or not — all a row click needs. The column is\n * read only off a cell of that very row, so a table inside a cell template\n * cannot lend it one of its own.\n */\nexport function bodyRowFrom(target: EventTarget | null): BodyRowTarget | null {\n if (!(target instanceof Element)) {\n return null;\n }\n const row = target.closest(\"tr[data-gridkit-row-index]\");\n const rowIndex = row === null ? null : rowIndexOf(row);\n if (rowIndex === null) {\n return null;\n }\n const cell = target.closest(\"td[data-gridkit-column]\");\n return {\n rowIndex,\n columnId:\n cell?.parentElement === row\n ? cell.getAttribute(\"data-gridkit-column\")\n : null,\n };\n}\n","/**\n * How a context menu was asked for: by a pointer — a right-click, or a touch\n * held still — or by the keyboard.\n */\nexport type ContextMenuSource = \"pointer\" | \"keyboard\";\n\n/** A context menu asked for inside the root, as `onRequest` hears of it. */\nexport interface ContextMenuRequest {\n /** The element it was asked for on: the one under the pointer, or the one focused for a key. */\n readonly target: Element;\n /**\n * Where the pointer was, in viewport coordinates — where a menu opened by\n * it goes. `null` from the keyboard, which has no point: a menu it opens\n * goes beside the focused element instead.\n */\n readonly point: { readonly x: number; readonly y: number } | null;\n readonly source: ContextMenuSource;\n}\n\nexport interface ContextMenuTriggerOptions {\n /**\n * A context menu was asked for inside the root. Returns whether the caller\n * opened one of its own: if so the browser's menu is prevented, and if not\n * it shows as it would have.\n */\n readonly onRequest: (request: ContextMenuRequest) => boolean;\n}\n\n/** How long a touch rests on the screen before it asks for a menu. */\nconst LONG_PRESS_DELAY = 500;\n\n/** How far, in pixels, a touch may drift and still count as resting. */\nconst LONG_PRESS_SLOP = 10;\n\n/** Shift+F10 and the ContextMenu key: the keyboard's ways to ask for one. */\nfunction isContextMenuKey(event: KeyboardEvent): boolean {\n if (event.ctrlKey || event.altKey || event.metaKey) {\n return false;\n }\n return event.key === \"ContextMenu\" || (event.key === \"F10\" && event.shiftKey);\n}\n\n/** A touch pressing, until it asks, lifts or moves away. */\ninterface Press {\n readonly pointerId: number;\n readonly x: number;\n readonly y: number;\n readonly timer: number;\n}\n\n/**\n * Reports every context menu the user asks for inside `root` — a right-click,\n * Shift+F10, the ContextMenu key, or a touch held still for half a second —\n * through `onRequest`, and returns the function that stops it.\n *\n * Each gesture asks once. Pressing a key, or holding a touch, also makes some\n * browsers fire `contextmenu` of their own, and that event is taken, not\n * reported again, once the gesture opened a menu. The click a touch brings\n * as it lifts is taken too: the menu opened under the finger, and the click\n * would land in it.\n *\n * An event something already prevented is left alone, so a cell template\n * that shows a menu of its own keeps it. That is why the listeners are on the\n * document, in the bubble phase: a framework that handles events at its own\n * root container — React does — hears them before the document does, where\n * a listener on `root` itself would hear them first. Only events whose target\n * is inside `root` count.\n */\nexport function attachContextMenuTrigger(\n root: Element,\n options: ContextMenuTriggerOptions,\n): () => void {\n /**\n * Set once a key or a touch opened a menu, until the `contextmenu` event\n * the same gesture may still bring. A pointer or another key starts a new\n * gesture, so a browser that brings none does not cost the next\n * right-click.\n */\n let swallowContextMenu = false;\n /** Set once a touch opened a menu, until the click its lifting brings. */\n let swallowClick = false;\n let press: Press | null = null;\n\n /** Asks for a menu on what `event` happened to, unless something prevented it. */\n function ask(\n event: Event,\n point: ContextMenuRequest[\"point\"],\n source: ContextMenuSource,\n ): boolean {\n const { target } = event;\n return (\n !event.defaultPrevented &&\n target instanceof Element &&\n root.contains(target) &&\n options.onRequest({ target, point, source })\n );\n }\n\n /** `ask`, and the browser's own menu prevented when one opened. */\n function request(\n event: Event,\n point: ContextMenuRequest[\"point\"],\n source: ContextMenuSource,\n ): boolean {\n if (!ask(event, point, source)) {\n return false;\n }\n event.preventDefault();\n return true;\n }\n\n function cancelPress(): void {\n if (press !== null) {\n window.clearTimeout(press.timer);\n press = null;\n }\n }\n\n function onKeyDown(event: KeyboardEvent): void {\n swallowContextMenu = false;\n swallowClick = false;\n if (isContextMenuKey(event) && request(event, null, \"keyboard\")) {\n swallowContextMenu = true;\n }\n }\n\n /**\n * Every pointer starts a new gesture; a touch may become a long-press. It\n * is asked for once it has rested long enough, by which time the press\n * shows whether a template prevented it.\n */\n function onPointerDown(event: PointerEvent): void {\n swallowContextMenu = false;\n swallowClick = false;\n cancelPress();\n if (event.pointerType !== \"touch\" || !event.isPrimary) {\n return;\n }\n const point = { x: event.clientX, y: event.clientY };\n press = {\n pointerId: event.pointerId,\n ...point,\n timer: window.setTimeout(() => {\n press = null;\n if (ask(event, point, \"pointer\")) {\n swallowContextMenu = true;\n swallowClick = true;\n }\n }, LONG_PRESS_DELAY),\n };\n }\n\n function onPointerMove(event: PointerEvent): void {\n if (\n press?.pointerId === event.pointerId &&\n Math.hypot(event.clientX - press.x, event.clientY - press.y) >\n LONG_PRESS_SLOP\n ) {\n cancelPress();\n }\n }\n\n // Lifted, or taken over by the browser — to scroll, say.\n function onPointerEnd(event: PointerEvent): void {\n if (press?.pointerId === event.pointerId) {\n cancelPress();\n }\n }\n\n function onClick(event: MouseEvent): void {\n if (swallowClick) {\n swallowClick = false;\n event.preventDefault();\n event.stopPropagation();\n }\n }\n\n function onContextMenu(event: MouseEvent): void {\n if (swallowContextMenu) {\n swallowContextMenu = false;\n event.preventDefault();\n return;\n }\n // A browser that turns a held touch into `contextmenu` of its own asks\n // first, and the long-press need not.\n const touching = press !== null;\n cancelPress();\n if (\n request(event, { x: event.clientX, y: event.clientY }, \"pointer\") &&\n touching\n ) {\n swallowClick = true;\n }\n }\n\n document.addEventListener(\"keydown\", onKeyDown);\n document.addEventListener(\"pointerdown\", onPointerDown, true);\n document.addEventListener(\"pointermove\", onPointerMove, true);\n document.addEventListener(\"pointerup\", onPointerEnd, true);\n document.addEventListener(\"pointercancel\", onPointerEnd, true);\n // Captured, so the click is taken before anything under the finger hears it.\n document.addEventListener(\"click\", onClick, true);\n document.addEventListener(\"contextmenu\", onContextMenu);\n\n return () => {\n cancelPress();\n document.removeEventListener(\"keydown\", onKeyDown);\n document.removeEventListener(\"pointerdown\", onPointerDown, true);\n document.removeEventListener(\"pointermove\", onPointerMove, true);\n document.removeEventListener(\"pointerup\", onPointerEnd, true);\n document.removeEventListener(\"pointercancel\", onPointerEnd, true);\n document.removeEventListener(\"click\", onClick, true);\n document.removeEventListener(\"contextmenu\", onContextMenu);\n };\n}\n","import { applyColumnResize, type ColumnResizeSession } from \"@gridkitjs/core\";\nimport {\n isPrimaryPress,\n startPointerGesture,\n type PointerPress,\n} from \"./pointerGesture\";\n\nexport interface ColumnResizeGestureHandlers {\n /** Every pointer move, with the width the column takes there. */\n readonly onMove: (width: number) => void;\n /**\n * The pointer was released. `width` is the width to commit, or `null` when\n * it ended where it started: a click on the handle — as each half of a\n * double-click is — is not a resize, and reporting one would fire a\n * spurious resize on every click.\n */\n readonly onEnd: (width: number | null) => void;\n /** Escape, or a cancelled pointer: the column goes back to `session.startWidth`. */\n readonly onCancel: () => void;\n}\n\n/**\n * Drags a column's edge from `press` on its resize `handle`, turning pointer\n * positions into widths through `@gridkitjs/core`'s `session` — begun with\n * `beginColumnResize` — and reporting them. Returns whether a resize began:\n * only the primary button of the primary pointer starts one.\n *\n * Captures the pointer on `handle`, so the drag keeps reporting wherever the\n * pointer goes, and prevents the press's default, so it does not select the\n * header text it started on. No minimum distance, unlike a reorder drag: the\n * handle does nothing else a press could have meant.\n */\nexport function startColumnResizeGesture(\n handle: HTMLElement,\n press: PointerPress,\n session: ColumnResizeSession,\n handlers: ColumnResizeGestureHandlers,\n): boolean {\n if (!isPrimaryPress(press)) {\n return false;\n }\n press.preventDefault();\n\n let width = session.startWidth;\n startPointerGesture(handle, press.pointerId, {\n onMove(event) {\n width = applyColumnResize(session, event.clientX);\n handlers.onMove(width);\n },\n onEnd() {\n handlers.onEnd(width === session.startWidth ? null : width);\n },\n onCancel() {\n handlers.onCancel();\n },\n });\n return true;\n}\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 — what double-clicking a resize\n * handle sizes the column to, through `sizeColumnToContent`.\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 — on a paged or virtualized grid, the ones\n * on screen.\n */\nexport 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","/**\n * The `pointerdown` a gesture starts from. A native `PointerEvent` is one,\n * and so is a framework's wrapper around it, such as React's synthetic\n * event, so a renderer passes whichever its handler received.\n */\nexport interface PointerPress {\n readonly pointerId: number;\n readonly clientX: number;\n readonly clientY: number;\n readonly button: number;\n readonly isPrimary: boolean;\n preventDefault(): void;\n}\n\n/**\n * Whether `press` may start a gesture: the main button of the primary\n * pointer. A right-click opens a context menu and a second finger is not the\n * gesture already under way, so neither starts a drag or a resize.\n */\nexport function isPrimaryPress(press: PointerPress): boolean {\n return press.button === 0 && press.isPrimary;\n}\n\ninterface 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 */\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 {\n isPrimaryPress,\n startPointerGesture,\n type PointerPress,\n} 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.\n */\nconst DRAG_THRESHOLD = 4;\n\n/** What a renderer draws while a reorder drag is open. */\nexport interface DragReorderState<Target> {\n /** The item being dragged, once the press has become a drag. */\n readonly draggedId: string | null;\n /** Where it would land if released now, `null` for nowhere valid. */\n readonly dropTarget: Target | null;\n /** Where the element trailing the pointer sits, as a CSS `transform`. */\n readonly ghostTransform: string | null;\n}\n\n/** The state while nothing is dragged — the one a drag reports when it ends. */\nexport const NO_DRAG: DragReorderState<never> = {\n draggedId: null,\n dropTarget: null,\n ghostTransform: null,\n};\n\nexport interface DragReorderHandlers<Target> {\n /**\n * Where a drop at `(clientX, clientY)` would land, or `null` for nowhere\n * valid — including a gap `id` already occupies, so a drop target only\n * ever promises a move that happens. Called on every pointer move once the\n * drag has opened. `resolveColumnDropTarget` and\n * `resolveGroupByDropTarget` are the grid's own.\n */\n readonly resolveTarget: (\n clientX: number,\n clientY: number,\n id: string,\n ) => Target | null;\n /** Every change to what the renderer draws, `NO_DRAG` once the drag ends. */\n readonly onState: (state: DragReorderState<Target>) => void;\n /** The pointer was released over a valid target. */\n readonly onDrop: (target: Target, id: string) => void;\n}\n\n/**\n * The pointer mechanics behind every drag-to-reorder gesture in the grid — a\n * column header dragged among the others or into the group-by bar, a\n * group-by chip dragged within it: capture, the drag threshold, and the ghost\n * trailing the pointer, holding the spot it was picked up by. Returns whether\n * a gesture began; only the main button of the primary pointer starts one.\n *\n * The press is left to its default, so the pressed element still takes focus;\n * until the pointer has travelled `DRAG_THRESHOLD` pixels nothing is\n * reported, so a press that never moves stays a click. Escape, or a cancelled\n * pointer, leaves the order as it was.\n *\n * Pointer events rather than HTML5 drag-and-drop: `dragenter`/`dragleave`\n * fire per descendant, so a dragged item's own inner markup would each report\n * the target leaving and re-entering as the pointer crossed them.\n */\nexport function startDragReorder<Target>(\n id: string,\n grabElement: HTMLElement,\n press: PointerPress,\n handlers: DragReorderHandlers<Target>,\n): boolean {\n if (!isPrimaryPress(press)) {\n return false;\n }\n\n const { pointerId, clientX: startX } = press;\n const grabX = startX - grabElement.getBoundingClientRect().left;\n let dragging = false;\n let target: Target | null = null;\n\n startPointerGesture(grabElement, pointerId, {\n onMove(moveEvent) {\n const { clientX, clientY } = moveEvent;\n if (!dragging) {\n if (Math.abs(clientX - startX) < DRAG_THRESHOLD) {\n return;\n }\n dragging = true;\n }\n target = handlers.resolveTarget(clientX, clientY, id);\n handlers.onState({\n draggedId: id,\n dropTarget: target,\n ghostTransform: `translate(${String(clientX - grabX)}px, ${String(clientY)}px)`,\n });\n },\n onEnd() {\n const dropped = target;\n handlers.onState(NO_DRAG);\n if (dragging && dropped !== null) {\n handlers.onDrop(dropped, id);\n }\n },\n onCancel() {\n target = null;\n handlers.onState(NO_DRAG);\n },\n });\n return true;\n}\n","import {\n movesColumn,\n movesGroupBy,\n resolveDropBefore,\n type ColumnOrderState,\n type DropSide,\n type GroupByState,\n} from \"@gridkitjs/core\";\n\n/** A drop into the group-by bar, in front of `beforeColumnId` — `null` to append. */\nexport interface GroupByDropTarget {\n readonly kind: \"group-by\";\n readonly beforeColumnId: string | null;\n}\n\n/**\n * Where a dragged column header would land: among the other headers, in\n * front of `beforeId` (`null` for the end), or in the group-by bar.\n */\nexport type ColumnDropTarget =\n | { readonly kind: \"column-order\"; readonly beforeId: string | null }\n | GroupByDropTarget;\n\nexport interface ColumnDropContext {\n /** The ids of the columns on screen, in order — what a drop is resolved among. */\n readonly order: ColumnOrderState;\n /** What a drop onto the group-by bar is resolved against. */\n readonly groupBy: GroupByState;\n /** Column ids whose header may be dragged into the group-by bar at all. */\n readonly groupByDraggableIds: ReadonlySet<string>;\n}\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 *\n * Hit-tested rather than read from an event's target, which pointer capture\n * pins to the element the drag opened on.\n */\nfunction elementAt(x: number, y: number, selector: string): Element | null {\n return document.elementFromPoint(x, y)?.closest(selector) ?? null;\n}\n\n/**\n * Which half of `element` `x` falls in. Read fresh on every move, so a width\n * changed mid-drag cannot leave the midpoint stale.\n */\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 * Where a header or chip dropped at `(clientX, clientY)` would land within\n * the group-by bar (`[data-gridkit-group-by-bar]`, its chips\n * `[data-gridkit-group-chip]`), or `null` when the pointer isn't over the bar\n * at all, or when the drop would change nothing. Shared by a header dragged\n * in from outside the bar and a chip dragged within it, so the two can never\n * 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\n/**\n * Where the header of `movedId` dropped at `(clientX, clientY)` would land:\n * before or after another header (`th[data-gridkit-column]`), by which half\n * of it the pointer is over, or else in the group-by bar — or `null` for\n * nowhere a drop would change anything.\n *\n * A column already grouped never targets the bar: reordering it there is its\n * chip's job, not its header's.\n */\nexport function resolveColumnDropTarget(\n clientX: number,\n clientY: number,\n movedId: string,\n { order, groupBy, groupByDraggableIds }: ColumnDropContext,\n): ColumnDropTarget | null {\n const over = elementAt(clientX, clientY, \"th[data-gridkit-column]\");\n const overId = over?.getAttribute(\"data-gridkit-column\");\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 const alreadyGrouped = groupBy.some((entry) => entry.columnId === movedId);\n return groupByDraggableIds.has(movedId) && !alreadyGrouped\n ? resolveGroupByDropTarget(clientX, clientY, movedId, groupBy)\n : null;\n}\n","/**\n * Reports `element`'s inner width now and on every change after, until the\n * returned function disconnects it — what `resizeMode: \"fit\"` fills.\n *\n * The first report is synchronous, so a renderer calling this before paint\n * lays its columns out at the right width from the first frame rather than\n * visibly jumping once the observer's first callback arrives.\n *\n * Reads `clientWidth` rather than the observer entry's `contentRect` so the\n * first report and every later one come from the same, already-rounded,\n * source.\n */\nexport function observeElementWidth(\n element: HTMLElement,\n onWidth: (width: number) => void,\n): () => void {\n onWidth(element.clientWidth);\n\n const observer = new ResizeObserver(() => {\n onWidth(element.clientWidth);\n });\n observer.observe(element);\n\n return () => {\n observer.disconnect();\n };\n}\n","import {\n clampFocus,\n HEADER_ROW,\n nextFocusForKey,\n type GridFocus,\n type NavigationModifiers,\n} from \"@gridkitjs/core\";\n\n/** Rows a page key moves when the viewport cannot be measured. */\nconst FALLBACK_PAGE = 10;\n\n/**\n * The window of rows a row virtualizer has drawn, and a way to bring a row\n * into it — what a focus move needs when its target row may not be mounted.\n */\nexport interface FocusVirtualRange {\n readonly startIndex: number;\n readonly endIndex: number;\n readonly scrollToIndex: (index: number) => void;\n}\n\n/** How to find the rendered rows the browser's focus moves among. */\nexport interface GridFocusRows {\n /** The header row's element, `null` while none is rendered. */\n readonly getHeaderRow: () => HTMLTableRowElement | null;\n /** Body row `rowIndex`'s element — `findBodyRow` finds it — `null` while it is not rendered. */\n readonly getBodyRow: (rowIndex: number) => HTMLTableRowElement | null;\n}\n\nexport interface GridFocusOptions {\n /** Body rows, counting group headers and summaries — every row a key could step through. */\n readonly rowCount: number;\n readonly columnCount: number;\n /**\n * Rows the vertical keys step over rather than stop on — a group's own\n * summary row, which takes a row slot but is not a stop of its own.\n */\n readonly isSkippableRow?: ((rowIndex: number) => boolean) | undefined;\n /**\n * The window the renderer drew, when rows are virtualized. A move can\n * target a row outside it — `ArrowDown` past its end, or `Ctrl+End` — that\n * no lookup would find until it is scrolled into range.\n */\n readonly virtualRange?: FocusVirtualRange | null | undefined;\n}\n\nexport interface GridFocusController {\n /**\n * The cell holding the grid's single tab stop, clamped into the current\n * row and column counts. The same object until it changes, so it can serve\n * as a renderer's snapshot.\n */\n readonly getFocus: () => GridFocus;\n /** Calls `listener` whenever the focused cell moves. Returns the unsubscribe. */\n readonly subscribe: (listener: () => void) => () => void;\n /**\n * Replaces the options, as a renderer does on every render with its\n * current counts and window. Calls no listener: the renderer calling it is\n * already drawing.\n */\n readonly setOptions: (options: GridFocusOptions) => void;\n /**\n * Moves the tab stop, and the browser's focus with it once the renderer\n * has drawn the move (see `focusDrawnCell`). Moving to the cell already\n * focused does nothing, which is what lets a cell's own `focus` event\n * report a click through here without a loop.\n */\n readonly focusCell: (rowIndex: number, columnIndex: number) => void;\n /**\n * Moves the tab stop as `key` does — the arrows, Home, End, the page keys,\n * with Ctrl for the grid's corners. Returns whether the key was one of\n * them, in which case the caller prevents its default: taken even when the\n * move lands nowhere, or an arrow at the last row would scroll the page\n * out from under the grid.\n */\n readonly handleKey: (\n key: string,\n modifiers: NavigationModifiers,\n pageSize: number,\n ) => boolean;\n /**\n * Connects the tab stop to the rendered rows, which the browser's focus\n * then follows it among. Returns the function that disconnects them.\n */\n readonly attach: (rows: GridFocusRows) => () => void;\n /**\n * Called by the renderer once it has drawn `drawn` — a value `getFocus`\n * returned — so the browser's focus follows a move to the cell now in the\n * markup. Does nothing unless a move to exactly that drawing is pending.\n */\n readonly focusDrawnCell: (drawn: GridFocus) => void;\n}\n\n/**\n * The cell at a coordinate. `columnIndex` is clamped to the row's own last\n * cell rather than read directly: a group-header row renders one\n * `<td colSpan>` regardless of the column count, so a focus arriving from a\n * data row further right would otherwise address a cell that row doesn't\n * have.\n */\nfunction cellIn(\n row: HTMLTableRowElement | null,\n columnIndex: number,\n): HTMLElement | null {\n if (row === null) {\n return null;\n }\n return row.cells[Math.min(columnIndex, row.cells.length - 1)] ?? null;\n}\n\n/**\n * Body row `rowIndex` in `bodyTable`, by its `data-gridkit-row-index` rather\n * than by its position in `tBodies[0].rows`: a virtualized body holds only a\n * slice of the rows, behind a leading spacer `<tr>`, so once the window\n * scrolls a DOM position no longer matches the row's index in the full array\n * and addresses some other mounted row, or none.\n *\n * The attribute holds a plain integer, so the selector needs no escaping,\n * unlike one built from a consumer's row id.\n */\nexport function findBodyRow(\n bodyTable: HTMLTableElement | null,\n rowIndex: number,\n): HTMLTableRowElement | null {\n return (\n bodyTable?.tBodies[0]?.querySelector<HTMLTableRowElement>(\n `:scope > tr[data-gridkit-row-index=\"${String(rowIndex)}\"]`,\n ) ?? null\n );\n}\n\n/**\n * How many rows fit `bodyTable`'s scroll wrapper — its parent, the row area\n * alone, not the header, footer and pager around it — which is what a page\n * key moves. Reads the first rendered row's height, and falls back to ten\n * rows when nothing can be measured.\n */\nexport function measurePageSize(bodyTable: HTMLTableElement | null): number {\n const firstRow = bodyTable?.tBodies[0]?.rows[0];\n const viewport = bodyTable?.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(1, Math.floor(viewport.clientHeight / firstRow.offsetHeight));\n}\n\n/**\n * The grid's single tab stop and the keys that move it, which is what\n * `role=\"grid\"` obliges: arrow keys travel cell to cell and Tab passes the\n * whole grid by. The renderer attaches its rows, draws `getFocus()` —\n * `tabindex=\"0\"` on that cell, `-1` on every other — re-reads it when\n * `subscribe` calls, and calls `focusDrawnCell` after drawing.\n *\n * Separate from selection, because focus and selection are different states:\n * a cell is focused while travelling before anything is selected, and every\n * cell of a range is selected without being focused. Navigation also has to\n * work with selection off entirely.\n *\n * Starts on the header row's first cell.\n */\nexport function createGridFocus(\n initialOptions: GridFocusOptions,\n): GridFocusController {\n let options = initialOptions;\n let rows: GridFocusRows | null = null;\n const listeners = new Set<() => void>();\n\n /**\n * Clamped on the way out rather than written back, so a coordinate pushed\n * out of range by a change to the data is restored when the data comes\n * back.\n */\n let stored: GridFocus = { rowIndex: HEADER_ROW, columnIndex: 0 };\n let snapshot = {\n stored,\n rowCount: options.rowCount,\n columnCount: options.columnCount,\n focus: clampFocus(stored, options.rowCount, options.columnCount),\n };\n\n /**\n * The move the browser's focus still has to follow, or `null` once it has.\n * Without it every drawing would pull focus into the grid, the first\n * included.\n *\n * Holds the very `stored` object `focusCell` wrote rather than a flag, so\n * only a drawing made from that move can act on it. Under virtualization a\n * scroll can commit a drawing just before a key press, and a renderer may\n * run that older drawing's after-draw step only once the press has marked\n * a new move pending. With a flag, that stale step found its own (still\n * mounted) cell, focused it and cleared the flag, so the new move's own\n * step returned early and never scrolled its row into range.\n */\n let pendingMove: GridFocus | null = null;\n\n function getFocus(): GridFocus {\n if (\n snapshot.stored !== stored ||\n snapshot.rowCount !== options.rowCount ||\n snapshot.columnCount !== options.columnCount\n ) {\n snapshot = {\n stored,\n rowCount: options.rowCount,\n columnCount: options.columnCount,\n focus: clampFocus(stored, options.rowCount, options.columnCount),\n };\n }\n return snapshot.focus;\n }\n\n function focusCell(rowIndex: number, columnIndex: number): void {\n const next = clampFocus(\n { rowIndex, columnIndex },\n options.rowCount,\n options.columnCount,\n );\n const current = getFocus();\n if (\n next.rowIndex === current.rowIndex &&\n next.columnIndex === current.columnIndex\n ) {\n return;\n }\n pendingMove = next;\n stored = next;\n for (const listener of listeners) {\n listener();\n }\n }\n\n return {\n getFocus,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n setOptions(next) {\n options = next;\n },\n focusCell,\n handleKey(key, modifiers, pageSize) {\n const next = nextFocusForKey(\n key,\n modifiers,\n getFocus(),\n options.rowCount,\n options.columnCount,\n pageSize,\n options.isSkippableRow,\n );\n if (next === null) {\n return false;\n }\n focusCell(next.rowIndex, next.columnIndex);\n return true;\n },\n attach(next) {\n rows = next;\n return () => {\n if (rows === next) {\n rows = null;\n }\n };\n },\n focusDrawnCell(drawn) {\n if (\n rows === null ||\n pendingMove === null ||\n snapshot.stored !== pendingMove ||\n snapshot.focus !== drawn\n ) {\n return;\n }\n const cell = cellIn(\n drawn.rowIndex === HEADER_ROW\n ? rows.getHeaderRow()\n : rows.getBodyRow(drawn.rowIndex),\n drawn.columnIndex,\n );\n if (cell !== null) {\n pendingMove = null;\n // Focusing the cell the browser already sits on is a no-op, which is\n // what makes one method serve both a key press and a cell reporting\n // a click.\n cell.focus();\n return;\n }\n\n // The target row isn't mounted — under virtualization, that means it's\n // outside the drawn window rather than an actual failure. Ask for it to\n // be brought into range; the move stays pending, so the next drawing\n // retries once the row mounts. Without virtualization (or for a row\n // out of bounds even for it) there is nothing further to try, so the\n // move is dropped rather than left to retry forever.\n const range = options.virtualRange;\n if (\n range != null &&\n drawn.rowIndex !== HEADER_ROW &&\n (drawn.rowIndex < range.startIndex || drawn.rowIndex > range.endIndex)\n ) {\n range.scrollToIndex(drawn.rowIndex);\n return;\n }\n pendingMove = null;\n },\n };\n}\n","export interface InfiniteScrollOptions {\n /**\n * The element whose approach triggers a load — the always-last row of the\n * body — or `null` while none is rendered.\n */\n readonly sentinel: Element | null;\n /** Whether a further load could still return more rows. `false` stops watching altogether. */\n readonly hasMore: boolean;\n /**\n * Called at most once per approach: when the sentinel comes within\n * `rootMargin` of the root's visible area, and not again until\n * `isLoadingMore` has gone from `true` back to `false`.\n */\n readonly onLoadMore?: (() => void) | undefined;\n /** Whether a load `onLoadMore` started is still in flight. */\n readonly isLoadingMore?: boolean | undefined;\n /** How far ahead of the sentinel scrolling into view a load starts, as CSS margins. Defaults to `\"200px\"`. */\n readonly rootMargin?: string | undefined;\n}\n\nexport interface InfiniteScroll {\n /**\n * Takes the current options. Cheap when nothing changed, so a renderer may\n * call it after every render; a new sentinel or `rootMargin` restarts the\n * observer, and `isLoadingMore` going back to `false` re-checks at once.\n */\n readonly update: (options: InfiniteScrollOptions) => void;\n /** Stops watching for good. */\n readonly detach: () => void;\n}\n\n/**\n * Turns a sentinel's approach to the bottom of the scrolling `root` into\n * `onLoadMore` calls, no more than one per \"the sentinel is near and no load\n * is in flight since the last one finished\".\n *\n * Three facts drive it: whether the sentinel is intersecting (as of the\n * observer's last report), whether `onLoadMore` has fired since the last\n * load finished, and whether a load was in flight at the last update. They\n * outlive the sentinel itself, which a renderer mounts and unmounts as\n * `hasMore` changes, so they live here rather than on any one observer.\n *\n * Off means off: with `hasMore` false, or no sentinel, no observer exists.\n */\nexport function attachInfiniteScroll(\n root: Element,\n options: InfiniteScrollOptions,\n): InfiniteScroll {\n let latest = options;\n let intersecting = false;\n /** Set once `onLoadMore` fires, cleared only when a load finishes. */\n let fired = false;\n let wasLoading = options.isLoadingMore ?? false;\n let observer: IntersectionObserver | null = null;\n let observed: { sentinel: Element; rootMargin: string } | null = null;\n\n function maybeLoadMore(): void {\n if (\n !intersecting ||\n !latest.hasMore ||\n (latest.isLoadingMore ?? false) ||\n fired\n ) {\n return;\n }\n fired = true;\n latest.onLoadMore?.();\n }\n\n function disconnect(): void {\n observer?.disconnect();\n observer = null;\n observed = null;\n intersecting = false;\n }\n\n function observe(): void {\n const sentinel = latest.hasMore ? latest.sentinel : null;\n const rootMargin = latest.rootMargin ?? \"200px\";\n if (\n observed !== null &&\n observed.sentinel === sentinel &&\n observed.rootMargin === rootMargin\n ) {\n return;\n }\n disconnect();\n if (sentinel === null) {\n return;\n }\n observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[entries.length - 1];\n if (entry === undefined) {\n return;\n }\n intersecting = entry.isIntersecting;\n maybeLoadMore();\n },\n { root, rootMargin },\n );\n observer.observe(sentinel);\n observed = { sentinel, rootMargin };\n }\n\n observe();\n\n return {\n update(next) {\n latest = next;\n const loading = next.isLoadingMore ?? false;\n if (wasLoading && !loading) {\n fired = false;\n // The rows a finished load appended may not have pushed the sentinel\n // out of `rootMargin` at all, in which case it never leaves and\n // re-enters — no observer report would come to trigger the next load.\n maybeLoadMore();\n }\n wasLoading = loading;\n observe();\n },\n detach: disconnect,\n };\n}\n","import { nextMenuIndex, typeaheadIndex, type MenuMove } from \"@gridkitjs/core\";\n\n/**\n * Where focus goes when a submenu opens: its first item, or nowhere — it\n * stays on the item that opened it, as when the pointer opened it.\n */\nexport type MenuSubmenuFocus = \"first\" | \"none\";\n\n/** Why a menu asked for every menu to close. */\nexport type MenuCloseReason = \"tab\";\n\nexport interface MenuOptions {\n /**\n * An enabled item that opens no submenu was chosen — Enter, Space or a\n * click. The caller runs it, and closes every menu.\n */\n readonly onActivate: (id: string) => void;\n /**\n * An enabled submenu item asks for its submenu: Enter, Space or ArrowRight\n * on it want its first item focused (`\"first\"`), a click or the pointer\n * resting on it want focus left where it is (`\"none\"`). It may come for a\n * submenu already open — ArrowRight on one the pointer opened — when a\n * `\"first\"` asks for focus to move into it (`focusItem(0)` on its menu).\n * Opening it closes any other submenu open from this menu.\n */\n readonly onOpenSubmenu?:\n | ((id: string, options: { readonly focus: MenuSubmenuFocus }) => void)\n | undefined;\n /**\n * The pointer came to rest on an item that opens no submenu, or a disabled\n * one: close whatever submenu is open from this menu, if any. Moving on to\n * another item is how a pointer user leaves a submenu they did not want.\n */\n readonly onCollapseSubmenu?: (() => void) | undefined;\n /**\n * ArrowLeft was pressed in this menu, which is a submenu: close it, and\n * focus goes back to the item that opened it. Passed only for a submenu —\n * in a menu without it, ArrowLeft does nothing.\n */\n readonly onCloseSubmenu?: (() => void) | undefined;\n /**\n * Tab or Shift+Tab was pressed: close every menu, so focus returns to where\n * the first one was opened from rather than moving on past it.\n */\n readonly onClose: (reason: MenuCloseReason) => void;\n}\n\nexport interface AttachedMenu {\n /**\n * Focuses an item, by its `data-gridkit-menu-item` id or its place among\n * the items. Does nothing for an item the menu does not have.\n */\n readonly focusItem: (item: string | number) => void;\n /** Removes every listener. The items keep the `tabindex` they had. */\n readonly detach: () => void;\n}\n\n/** Every element `attachMenu` treats as an item. Separators are not. */\nconst ITEM = [\n '[role=\"menuitem\"][data-gridkit-menu-item]',\n '[role=\"menuitemcheckbox\"][data-gridkit-menu-item]',\n '[role=\"menuitemradio\"][data-gridkit-menu-item]',\n].join(\", \");\n\n/** How long the pointer rests on a submenu item before it opens. */\nconst HOVER_DELAY = 150;\n\n/** How long after the last key typed the typeahead starts afresh. */\nconst TYPEAHEAD_TIMEOUT = 500;\n\n/** Each item, as `nextMenuIndex` reads it: the separators are not among them. */\nconst AS_ENTRY = { type: \"item\" } as const;\n\n/** The keys that move focus, and where to. */\nconst MOVES: Readonly<Record<string, MenuMove>> = {\n ArrowDown: \"next\",\n ArrowUp: \"previous\",\n Home: \"first\",\n End: \"last\",\n};\n\nfunction idOf(item: HTMLElement): string {\n return item.getAttribute(\"data-gridkit-menu-item\") ?? \"\";\n}\n\nfunction isDisabled(item: HTMLElement): boolean {\n return item.getAttribute(\"aria-disabled\") === \"true\";\n}\n\nfunction opensSubmenu(item: HTMLElement): boolean {\n const popup = item.getAttribute(\"aria-haspopup\");\n return popup === \"menu\" || popup === \"true\";\n}\n\n/** What typeahead matches against: the item's `aria-label`, else its text. */\nfunction labelOf(item: HTMLElement): string {\n return (item.getAttribute(\"aria-label\") ?? item.textContent).trim();\n}\n\n/** A printable character, typed without a modifier that makes it a shortcut. */\nfunction isTypeahead(event: KeyboardEvent): boolean {\n return (\n /^\\S$/u.test(event.key) && !event.ctrlKey && !event.metaKey && !event.altKey\n );\n}\n\n/**\n * Makes `panel` — a `role=\"menu\"` element the renderer drew — behave as a\n * menu: the arrow keys, Home, End and typeahead move focus among its items,\n * Enter, Space and a click choose one, ArrowRight and ArrowLeft open and\n * close submenus, and the pointer moves focus to the item under it. It\n * decides; the caller is told through the callbacks and draws the outcome —\n * runs the item, opens or closes a submenu.\n *\n * Items are the panel's descendants with a menu item role (`menuitem`,\n * `menuitemcheckbox`, `menuitemradio`) and a `data-gridkit-menu-item` id,\n * read afresh on every key so items drawn since attaching count. A submenu\n * item says so with `aria-haspopup=\"menu\"`; an item with\n * `aria-disabled=\"true\"` takes focus, so a screen reader finds it, but is\n * never chosen. One item at a time has `tabindex=\"0\"` — the focused one, or\n * the first — and the rest `-1`: every item can take focus, and the first is\n * what an overlay's initial focus finds when the menu is attached before it.\n *\n * Escape is not handled: a menu is shown with `attachOverlay`, whose stack\n * gives Escape to the topmost overlay. A submenu is a menu of its own, in an\n * overlay of its own anchored to its item, attached when it opens.\n */\nexport function attachMenu(\n panel: HTMLElement,\n options: MenuOptions,\n): AttachedMenu {\n let typed = \"\";\n let typeaheadTimer: number | undefined;\n /** The item the pointer is over, and since when, through `hoverTimer`. */\n let hovered: HTMLElement | null = null;\n let hoverTimer: number | undefined;\n\n function items(): HTMLElement[] {\n return Array.from(panel.querySelectorAll<HTMLElement>(ITEM));\n }\n\n function itemOf(target: EventTarget | null): HTMLElement | null {\n const item =\n target instanceof Element ? target.closest<HTMLElement>(ITEM) : null;\n return item !== null && panel.contains(item) ? item : null;\n }\n\n function setTabStop(stop: HTMLElement | undefined): void {\n for (const item of items()) {\n item.tabIndex = item === stop ? 0 : -1;\n }\n }\n\n function focus(item: HTMLElement): void {\n setTabStop(item);\n item.focus();\n }\n\n function openSubmenu(item: HTMLElement, focusTo: MenuSubmenuFocus): void {\n if (!isDisabled(item)) {\n options.onOpenSubmenu?.(idOf(item), { focus: focusTo });\n }\n }\n\n function choose(item: HTMLElement, focusTo: MenuSubmenuFocus): void {\n if (opensSubmenu(item)) {\n openSubmenu(item, focusTo);\n } else if (!isDisabled(item)) {\n options.onActivate(idOf(item));\n }\n }\n\n function typeahead(key: string, all: HTMLElement[], from: number): void {\n typed += key;\n window.clearTimeout(typeaheadTimer);\n typeaheadTimer = window.setTimeout(() => {\n typed = \"\";\n }, TYPEAHEAD_TIMEOUT);\n const match = all[typeaheadIndex(all.map(labelOf), from, typed)];\n if (match !== undefined) {\n focus(match);\n }\n }\n\n // Every key it acts on is taken, the arrows included where they do\n // nothing: a menu has no caret for them to move, and the page scrolling\n // under it would dismiss its overlay.\n function onKeyDown(event: KeyboardEvent): void {\n if (event.isComposing) {\n return;\n }\n const all = items();\n const item = itemOf(event.target);\n const from = item === null ? -1 : all.indexOf(item);\n const move = MOVES[event.key];\n if (move !== undefined) {\n const next =\n all[\n nextMenuIndex(\n all.map(() => AS_ENTRY),\n from,\n move,\n )\n ];\n if (next !== undefined) {\n focus(next);\n }\n } else if (event.key === \"Enter\" || event.key === \" \") {\n if (item !== null) {\n choose(item, \"first\");\n }\n } else if (event.key === \"ArrowRight\") {\n if (item !== null && opensSubmenu(item)) {\n openSubmenu(item, \"first\");\n }\n } else if (event.key === \"ArrowLeft\") {\n options.onCloseSubmenu?.();\n } else if (event.key === \"Tab\") {\n options.onClose(\"tab\");\n } else if (isTypeahead(event)) {\n typeahead(event.key, all, from);\n } else {\n return;\n }\n event.preventDefault();\n }\n\n // However focus arrived — the overlay's initial focus, a click, a script —\n // the tab stop follows it.\n function onFocusIn(event: FocusEvent): void {\n const item = itemOf(event.target);\n if (item !== null) {\n setTabStop(item);\n }\n }\n\n function onClick(event: MouseEvent): void {\n const item = itemOf(event.target);\n if (item !== null) {\n choose(item, \"none\");\n }\n }\n\n // A pointer moving over the menu moves focus with it at once, but what the\n // item under it opens or closes waits until it rests there: a pointer\n // crossing a sibling on its way into an open submenu leaves the submenu\n // open. Touch has no hover, so only its taps count, as clicks.\n function onPointerMove(event: PointerEvent): void {\n if (event.pointerType === \"touch\") {\n return;\n }\n const item = itemOf(event.target);\n if (item !== null && document.activeElement !== item) {\n focus(item);\n }\n if (item === hovered) {\n return;\n }\n hovered = item;\n window.clearTimeout(hoverTimer);\n if (item !== null) {\n hoverTimer = window.setTimeout(() => {\n if (opensSubmenu(item) && !isDisabled(item)) {\n openSubmenu(item, \"none\");\n } else {\n options.onCollapseSubmenu?.();\n }\n }, HOVER_DELAY);\n }\n }\n\n // Leaving the panel — into the submenu, usually — is not resting anywhere.\n function onPointerLeave(): void {\n hovered = null;\n window.clearTimeout(hoverTimer);\n }\n\n const focused = itemOf(document.activeElement);\n setTabStop(focused ?? items()[0]);\n\n panel.addEventListener(\"keydown\", onKeyDown);\n panel.addEventListener(\"focusin\", onFocusIn);\n panel.addEventListener(\"click\", onClick);\n panel.addEventListener(\"pointermove\", onPointerMove);\n panel.addEventListener(\"pointerleave\", onPointerLeave);\n\n return {\n focusItem(which) {\n const all = items();\n const item =\n typeof which === \"number\"\n ? all[which]\n : all.find((candidate) => idOf(candidate) === which);\n if (item !== undefined) {\n focus(item);\n }\n },\n detach() {\n window.clearTimeout(typeaheadTimer);\n window.clearTimeout(hoverTimer);\n panel.removeEventListener(\"keydown\", onKeyDown);\n panel.removeEventListener(\"focusin\", onFocusIn);\n panel.removeEventListener(\"click\", onClick);\n panel.removeEventListener(\"pointermove\", onPointerMove);\n panel.removeEventListener(\"pointerleave\", onPointerLeave);\n },\n };\n}\n","/** What the stack needs of an attached overlay. */\nexport interface StackedOverlay {\n readonly panel: HTMLElement;\n /** Escape was pressed while this was the topmost overlay. */\n readonly onEscape: () => void;\n /** An overlay below this one detached, so this one has to go too. */\n readonly onParentDetached: () => void;\n}\n\n/**\n * Every attached overlay, in the order it attached: a submenu opened from a\n * menu sits above it. Module-level because nesting spans overlays that know\n * nothing of each other — a menu does not hold a reference to the submenu a\n * click inside it opened.\n */\nconst stack: StackedOverlay[] = [];\n\n/*\n * One listener for the whole stack, on `window` in the capture phase: the\n * first place a key event reaches, so neither React's root listener nor a\n * page's own Escape handler hears an Escape the topmost overlay took. An\n * Escape that ends an IME composition is the input method's, not ours.\n */\nfunction onKeyDown(event: KeyboardEvent): void {\n const topmost = stack.at(-1);\n if (event.key !== \"Escape\" || event.isComposing || topmost === undefined) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n topmost.onEscape();\n}\n\n/** Puts `overlay` on top of the stack. */\nexport function pushOverlay(overlay: StackedOverlay): void {\n if (stack.length === 0) {\n window.addEventListener(\"keydown\", onKeyDown, true);\n }\n stack.push(overlay);\n}\n\n/**\n * Takes `overlay` off the stack, and every overlay above it with it — each\n * told through `onParentDetached`, topmost first, so a submenu never outlives\n * the menu it opened from. Does nothing for an overlay no longer on it.\n */\nexport function removeOverlay(overlay: StackedOverlay): void {\n const index = stack.indexOf(overlay);\n if (index === -1) {\n return;\n }\n const above = stack.splice(index).slice(1).reverse();\n for (const child of above) {\n child.onParentDetached();\n }\n if (stack.length === 0) {\n window.removeEventListener(\"keydown\", onKeyDown, true);\n }\n}\n\n/** Whether `target` is inside an overlay that sits above `overlay`. */\nexport function isInsideOverlayAbove(\n overlay: StackedOverlay,\n target: Node,\n): boolean {\n const index = stack.indexOf(overlay);\n return (\n index !== -1 &&\n stack.slice(index + 1).some((above) => above.panel.contains(target))\n );\n}\n","/** Which side of its anchor an overlay opens on. */\nexport type OverlaySide = \"top\" | \"bottom\" | \"left\" | \"right\";\n\n/**\n * Which edge of the anchor the overlay lines up with along that side: its\n * left edge (`start`) or right edge (`end`) for `top`/`bottom`, its top or\n * bottom edge for `left`/`right`.\n */\nexport type OverlayAlign = \"start\" | \"end\";\n\nexport type OverlayPlacement = `${OverlaySide}-${OverlayAlign}`;\n\n/** A box in viewport coordinates, as `getBoundingClientRect` reports one. */\nexport interface OverlayRect {\n readonly top: number;\n readonly left: number;\n readonly width: number;\n readonly height: number;\n}\n\nexport interface OverlaySize {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface OverlayPlacementOptions {\n /** Where the overlay would rather open. Defaults to `\"bottom-start\"`. */\n readonly placement?: OverlayPlacement | undefined;\n /** Space between the anchor and the overlay, in pixels. Defaults to `0`. */\n readonly gap?: number | undefined;\n /**\n * Pixels to shift the overlay along the anchor's edge — down beside a\n * `left`/`right` side, right beside `top`/`bottom`; negative goes the other\n * way. A submenu opened `right-start` takes its own top padding, negated,\n * so its first item lines up with the item that opened it. The overlay is\n * still kept on screen. Defaults to `0`.\n */\n readonly offset?: number | undefined;\n}\n\n/** Where an overlay goes: its top-left corner, and the placement it ended up with. */\nexport interface OverlayPosition {\n readonly top: number;\n readonly left: number;\n readonly placement: OverlayPlacement;\n}\n\nconst OPPOSITE_SIDE: Readonly<Record<OverlaySide, OverlaySide>> = {\n top: \"bottom\",\n bottom: \"top\",\n left: \"right\",\n right: \"left\",\n};\n\nfunction isVertical(side: OverlaySide): boolean {\n return side === \"top\" || side === \"bottom\";\n}\n\n/** How much room `side` of `anchor` leaves before the viewport's edge. */\nfunction roomBeside(\n side: OverlaySide,\n anchor: OverlayRect,\n viewport: OverlaySize,\n): number {\n switch (side) {\n case \"top\":\n return anchor.top;\n case \"bottom\":\n return viewport.height - (anchor.top + anchor.height);\n case \"left\":\n return anchor.left;\n case \"right\":\n return viewport.width - (anchor.left + anchor.width);\n }\n}\n\n/**\n * The preferred side if the overlay fits there, the opposite one if it fits\n * there instead, and otherwise whichever has more room — a menu too tall for\n * either still shows as much of itself as it can.\n */\nfunction chooseSide(\n preferred: OverlaySide,\n needed: number,\n anchor: OverlayRect,\n viewport: OverlaySize,\n): OverlaySide {\n const opposite = OPPOSITE_SIDE[preferred];\n const room = roomBeside(preferred, anchor, viewport);\n const oppositeRoom = roomBeside(opposite, anchor, viewport);\n if (room >= needed) {\n return preferred;\n }\n return oppositeRoom >= needed || oppositeRoom > room ? opposite : preferred;\n}\n\n/** The preferred edge unless only the other one keeps the overlay on screen. */\nfunction chooseAlign(\n preferred: OverlayAlign,\n fitsAtStart: boolean,\n fitsAtEnd: boolean,\n): OverlayAlign {\n if (preferred === \"start\") {\n return fitsAtStart || !fitsAtEnd ? \"start\" : \"end\";\n }\n return fitsAtEnd || !fitsAtStart ? \"end\" : \"start\";\n}\n\n/** The overlay's offset away from the anchor: its top for `top`/`bottom`, its left otherwise. */\nfunction offsetBeside(\n side: OverlaySide,\n anchor: OverlayRect,\n panel: OverlaySize,\n gap: number,\n): number {\n switch (side) {\n case \"top\":\n return anchor.top - gap - panel.height;\n case \"bottom\":\n return anchor.top + anchor.height + gap;\n case \"left\":\n return anchor.left - gap - panel.width;\n case \"right\":\n return anchor.left + anchor.width + gap;\n }\n}\n\n/** Keeps `value` within `[0, limit]`, pinning to `0` when even that fails. */\nfunction clampIntoView(value: number, limit: number): number {\n return Math.max(0, Math.min(value, limit));\n}\n\n/**\n * Where an overlay of size `panel` goes beside `anchor` so that it stays in\n * `viewport`: on the preferred side unless only the opposite one has room,\n * lined up with the preferred edge unless that runs it off screen and the\n * other edge does not, and finally pushed back inside if it still overflows.\n * Pure, so the rules are testable without a browser; `attachOverlay` feeds it\n * the measurements.\n *\n * A point — a context menu opened where the pointer is — is an anchor with\n * no width or height, which is what makes `start`/`end` mean \"after\" and\n * \"before\" it.\n */\nexport function placeOverlay(\n anchor: OverlayRect,\n panel: OverlaySize,\n viewport: OverlaySize,\n options: OverlayPlacementOptions = {},\n): OverlayPosition {\n const [preferredSide, preferredAlign] = (\n options.placement ?? \"bottom-start\"\n ).split(\"-\") as [OverlaySide, OverlayAlign];\n const gap = options.gap ?? 0;\n const offset = options.offset ?? 0;\n const vertical = isVertical(preferredSide);\n\n const side = chooseSide(\n preferredSide,\n (vertical ? panel.height : panel.width) + gap,\n anchor,\n viewport,\n );\n\n // The axis the overlay runs along beside the anchor, shifted by the offset\n // before an edge is chosen, so the shifted overlay is what has to fit.\n const anchorStart = (vertical ? anchor.left : anchor.top) + offset;\n const anchorEnd = anchorStart + (vertical ? anchor.width : anchor.height);\n const extent = vertical ? panel.width : panel.height;\n const room = vertical ? viewport.width : viewport.height;\n const align = chooseAlign(\n preferredAlign,\n anchorStart + extent <= room,\n anchorEnd - extent >= 0,\n );\n const along = align === \"start\" ? anchorStart : anchorEnd - extent;\n const away = offsetBeside(side, anchor, panel, gap);\n\n return {\n top: clampIntoView(vertical ? away : along, viewport.height - panel.height),\n left: clampIntoView(vertical ? along : away, viewport.width - panel.width),\n placement: `${side}-${align}`,\n };\n}\n","import {\n isInsideOverlayAbove,\n pushOverlay,\n removeOverlay,\n type StackedOverlay,\n} from \"./overlayStack\";\nimport {\n placeOverlay,\n type OverlayPlacementOptions,\n type OverlayRect,\n} from \"./placeOverlay\";\n\n/** What an overlay opens beside: an element, or a point in viewport coordinates. */\nexport type OverlayAnchor =\n Element | { readonly x: number; readonly y: number };\n\n/**\n * Where focus goes when an overlay attaches: its first focusable descendant,\n * the panel itself, nowhere — focus stays where it was — or a given element.\n */\nexport type OverlayInitialFocus = \"first\" | \"panel\" | \"none\" | HTMLElement;\n\n/** Why an overlay asked to close. */\nexport type OverlayDismissReason =\n \"escape\" | \"outside\" | \"scroll\" | \"resize\" | \"blur\" | \"parent\";\n\nexport interface OverlayOptions extends OverlayPlacementOptions {\n /**\n * The overlay asks to close: Escape was pressed while it was the topmost\n * overlay, a pointer went down outside it, something outside it scrolled,\n * the window resized or lost focus, focus moved outside it, or the overlay\n * it was opened above detached. The caller closes it — removes the panel\n * and detaches — or keeps it open by doing nothing, except after\n * `\"parent\"`, which detaches it regardless.\n */\n readonly onDismiss: (reason: OverlayDismissReason) => void;\n /**\n * Where focus goes on attaching. Defaults to `\"first\"`: a menu focuses its\n * first item. A panel whose first control is not where the user starts — a\n * filter editor's operator picker before its value box — passes that\n * element, or `\"panel\"` to land on the panel itself; `\"none\"` leaves focus\n * where it was, as a suggestion list does while typing goes on in the\n * field that opened it.\n */\n readonly initialFocus?: OverlayInitialFocus | undefined;\n /**\n * Where focus goes when the overlay detaches. Defaults to the element that\n * had focus when it attached; `null` leaves focus alone.\n */\n readonly returnFocusTo?: HTMLElement | null | undefined;\n /**\n * Whether a scroll outside the panel just after input inside it — an\n * `input` or `change` event, in the two animation frames that follow it —\n * leaves it open. A panel whose controls change the page under it opts\n * in: a column chooser hiding a column narrows the grid it opened from,\n * and the browser scrolls that grid back within its narrower content.\n * Defaults to `false`, where every scroll outside the panel dismisses it.\n */\n readonly ignoreScrollAfterInput?: boolean | undefined;\n}\n\n/** Everything focusable by script, so a menu's `tabindex=\"-1\"` items count. */\nconst FOCUSABLE =\n \"a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]\";\n\nfunction anchorRect(anchor: OverlayAnchor): OverlayRect {\n if (anchor instanceof Element) {\n const { top, left, width, height } = anchor.getBoundingClientRect();\n return { top, left, width, height };\n }\n return { top: anchor.y, left: anchor.x, width: 0, height: 0 };\n}\n\n/**\n * The element `initialFocus` names, or `null` for none. The panel stands in\n * for a first focusable descendant it does not have, given `tabindex=\"-1\"`\n * when it has no `tabindex` of its own so that it can take focus.\n */\nfunction initialFocusTarget(\n panel: HTMLElement,\n initialFocus: OverlayInitialFocus,\n): HTMLElement | null {\n if (initialFocus === \"none\") {\n return null;\n }\n if (initialFocus instanceof HTMLElement) {\n return initialFocus;\n }\n const first =\n initialFocus === \"first\"\n ? panel.querySelector<HTMLElement>(FOCUSABLE)\n : null;\n if (first !== null) {\n return first;\n }\n if (!panel.hasAttribute(\"tabindex\")) {\n panel.tabIndex = -1;\n }\n return panel;\n}\n\n/**\n * Shows `panel` as an overlay beside `anchor` — a menu, a popover, a filter\n * editor — and returns the function that ends it. The caller renders the\n * panel, usually as a child of `document.body` so no scrolling ancestor clips\n * it; this positions it, moves focus into it, and reports through\n * `onDismiss` when the user is done with it.\n *\n * The panel is positioned `fixed`, at the place `placeOverlay` picks from the\n * anchor's and the panel's measured boxes, and carries that placement in\n * `data-gridkit-placement` (`\"top-start\"` once flipped above, say) for a\n * stylesheet to point an arrow by. Whenever the panel's size changes — a list\n * that shrinks under a search — it is placed again beside the anchor, so a\n * panel flipped above its anchor keeps its bottom edge there — or beside\n * where the anchor was, once it has left the page. Focus moves\n * where `initialFocus` says.\n *\n * Nothing that happens on or in the anchor dismisses the overlay, so a button\n * that toggles it can close it with its own click rather than having the\n * overlay close and the click reopen it.\n *\n * Overlays stack in the order they attach. Escape belongs to the topmost\n * alone, which takes it: it closes a submenu without closing the menu under\n * it, and nothing else on the page — a grid that clears its selection on\n * Escape — hears it. An overlay counts everything in the overlays above it\n * as inside itself, so a click in a submenu keeps its menu open while a click\n * elsewhere in the menu closes only the submenu.\n *\n * Detaching removes every listener and returns focus, but only when focus is\n * still in the panel, in an overlay above it, or nowhere — a click that\n * dismissed it by landing on another control leaves focus on that control.\n * Any overlay still above it is dismissed with `\"parent\"` and detached first.\n */\nexport function attachOverlay(\n anchor: OverlayAnchor,\n panel: HTMLElement,\n options: OverlayOptions,\n): () => void {\n const { onDismiss } = options;\n const returnFocusTo =\n options.returnFocusTo === undefined\n ? document.activeElement instanceof HTMLElement\n ? document.activeElement\n : null\n : options.returnFocusTo;\n\n const stacked: StackedOverlay = {\n panel,\n onEscape: () => {\n onDismiss(\"escape\");\n },\n onParentDetached: () => {\n onDismiss(\"parent\");\n detach();\n },\n };\n\n /** In the panel, or in an overlay opened above it. */\n function inside(target: EventTarget | null): boolean {\n return (\n target instanceof Node &&\n (panel.contains(target) || isInsideOverlayAbove(stacked, target))\n );\n }\n\n function belongs(target: EventTarget | null): boolean {\n return (\n inside(target) ||\n (anchor instanceof Element &&\n target instanceof Node &&\n anchor.contains(target))\n );\n }\n\n function onPointerDown(event: PointerEvent): void {\n if (!belongs(event.target)) {\n onDismiss(\"outside\");\n }\n }\n\n // Set from input in the panel until two frames have passed: the scroll an\n // input causes is dispatched by the frame after its layout, which may\n // itself wait for the next frame.\n let settlingFrame: number | null = null;\n function onInput(): void {\n if (settlingFrame !== null) {\n cancelAnimationFrame(settlingFrame);\n }\n settlingFrame = requestAnimationFrame(() => {\n settlingFrame = requestAnimationFrame(() => {\n settlingFrame = null;\n });\n });\n }\n\n // The overlay is placed in viewport coordinates, so any scroll that moves\n // its anchor leaves it behind — except a scroll inside the panel itself,\n // or one the panel's own input caused, when it asks for that.\n function onScroll(event: Event): void {\n if (!inside(event.target) && settlingFrame === null) {\n onDismiss(\"scroll\");\n }\n }\n\n function onResize(): void {\n onDismiss(\"resize\");\n }\n\n // Only a move to somewhere definite counts: focus dropping to nothing, as\n // when the focused item re-renders away, is not the user leaving.\n function onFocusOut(event: FocusEvent): void {\n if (event.relatedTarget !== null && !belongs(event.relatedTarget)) {\n onDismiss(\"blur\");\n }\n }\n\n function onWindowBlur(): void {\n onDismiss(\"blur\");\n }\n\n // An anchor taken out of the page has no box to read — the header of a\n // column the panel itself just hid — so the panel goes on being placed\n // beside where it last was, rather than in the viewport's corner.\n let lastAnchorBox: OverlayRect | null = null;\n function anchorBox(): OverlayRect {\n if (\n lastAnchorBox === null ||\n !(anchor instanceof Element) ||\n anchor.isConnected\n ) {\n lastAnchorBox = anchorRect(anchor);\n }\n return lastAnchorBox;\n }\n\n // Measured fixed at the viewport's top-left corner, shrink-wrapped and with\n // the whole viewport to grow into — in normal flow a block panel would\n // report the full width of the page — and from that corner every time, so\n // placing it again measures it the way the first placing did.\n function place(): void {\n panel.style.top = \"0px\";\n panel.style.left = \"0px\";\n const { width, height } = panel.getBoundingClientRect();\n const position = placeOverlay(\n anchorBox(),\n { width, height },\n {\n width: document.documentElement.clientWidth,\n height: document.documentElement.clientHeight,\n },\n options,\n );\n panel.style.top = `${String(position.top)}px`;\n panel.style.left = `${String(position.left)}px`;\n panel.setAttribute(\"data-gridkit-placement\", position.placement);\n }\n\n panel.style.position = \"fixed\";\n place();\n const resizeObserver = new ResizeObserver(place);\n resizeObserver.observe(panel);\n\n // On the stack before focus moves in, so the overlay below sees the focus\n // leaving it land inside an overlay above it rather than outside.\n pushOverlay(stacked);\n initialFocusTarget(panel, options.initialFocus ?? \"first\")?.focus({\n preventScroll: true,\n });\n\n document.addEventListener(\"pointerdown\", onPointerDown, true);\n window.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n window.addEventListener(\"resize\", onResize);\n window.addEventListener(\"blur\", onWindowBlur);\n panel.addEventListener(\"focusout\", onFocusOut);\n if (options.ignoreScrollAfterInput === true) {\n panel.addEventListener(\"input\", onInput);\n panel.addEventListener(\"change\", onInput);\n }\n\n let attached = true;\n function detach(): void {\n if (!attached) {\n return;\n }\n attached = false;\n // Read before the overlays above close and hand focus back to wherever\n // they took it from, which may already have left the page with this panel.\n const active = document.activeElement;\n const focusInside =\n active === null || active === document.body || inside(active);\n removeOverlay(stacked);\n resizeObserver.disconnect();\n document.removeEventListener(\"pointerdown\", onPointerDown, true);\n window.removeEventListener(\"scroll\", onScroll, { capture: true });\n window.removeEventListener(\"resize\", onResize);\n window.removeEventListener(\"blur\", onWindowBlur);\n panel.removeEventListener(\"focusout\", onFocusOut);\n panel.removeEventListener(\"input\", onInput);\n panel.removeEventListener(\"change\", onInput);\n if (settlingFrame !== null) {\n cancelAnimationFrame(settlingFrame);\n }\n\n if (returnFocusTo !== null && focusInside) {\n returnFocusTo.focus({ preventScroll: true });\n }\n }\n return detach;\n}\n","import { visibleRange, type VisibleRange } from \"@gridkitjs/core\";\n\nexport interface RowVirtualizerOptions {\n /** The height assumed for a row not yet measured. */\n readonly estimatedRowHeight: number;\n /** Rows rendered beyond each edge of the visible area. */\n readonly overscan: number;\n /**\n * The window of rows to render moved: called whenever a scroll, a resize\n * of the scroll element, a measured row height or a change of rows moves\n * it, and never with a window equal to the last.\n */\n readonly onRange: (range: VisibleRange) => void;\n}\n\nexport interface RowVirtualizer {\n /** How many rows there are. Measured heights of the rows that remain are kept. */\n readonly setRowCount: (count: number) => void;\n /** Forgets every measured height, for rows that are no longer the ones measured. */\n readonly resetHeights: () => void;\n /**\n * A ref callback for the element of row `index` (its place among all the\n * rows, not among those rendered): measured while mounted, forgotten once\n * called with `null`. The same function for the same index every time, so\n * a renderer re-attaching it on every render costs nothing.\n */\n readonly measureRow: (index: number) => (element: HTMLElement | null) => void;\n /**\n * Scrolls so row `index` is in view. A mounted row is scrolled to directly;\n * one outside the window is jumped to at its estimated offset, then\n * scrolled to properly once it mounts and can be measured.\n */\n readonly scrollToIndex: (\n index: number,\n options?: ScrollIntoViewOptions,\n ) => void;\n /** Stops listening and measuring, for good. */\n readonly destroy: () => void;\n}\n\nfunction sameRange(a: VisibleRange, b: VisibleRange): boolean {\n return (\n a.startIndex === b.startIndex &&\n a.endIndex === b.endIndex &&\n a.offsetBefore === b.offsetBefore &&\n a.offsetAfter === b.offsetAfter\n );\n}\n\n/**\n * Windows a long list of rows inside `scrollElement` down to those near its\n * scroll position, measuring each rendered row's real height rather than\n * assuming a uniform one — rows are not uniform (`.is-wrapped` cells, group\n * header and summary rows), so a fixed-height virtualizer would either break\n * wrapping or rule it out. The renderer draws `onRange`'s window, with\n * spacers of `offsetBefore`/`offsetAfter` around it, and hands each row's\n * element to `measureRow`.\n *\n * The heights are a mutable array, not a structure rebuilt per measurement:\n * one can arrive many times a second while scrolling. The pure arithmetic\n * over them is `@gridkitjs/core`'s `visibleRange`; this owns only the\n * mutability around it and the listeners that feed it — the scroll position,\n * the scroll element's height, and one `ResizeObserver` shared by every\n * mounted row.\n */\nexport function createRowVirtualizer(\n scrollElement: HTMLElement,\n options: RowVirtualizerOptions,\n): RowVirtualizer {\n const { estimatedRowHeight, overscan, onRange } = options;\n\n let heights: (number | undefined)[] = [];\n let scrollTop = scrollElement.scrollTop;\n let viewportHeight = scrollElement.clientHeight;\n let range: VisibleRange | null = null;\n let destroyed = false;\n /** The row `scrollToIndex` is still waiting to mount, to scroll to it properly. */\n let pendingScroll:\n { index: number; options: ScrollIntoViewOptions | undefined } | undefined;\n\n const elements = new Map<number, HTMLElement>();\n const indexByElement = new Map<Element, number>();\n const refCallbacks = new Map<number, (element: HTMLElement | null) => void>();\n\n function recompute(): void {\n if (destroyed) {\n return;\n }\n const next = visibleRange(\n heights,\n estimatedRowHeight,\n scrollTop,\n viewportHeight,\n overscan,\n );\n if (range !== null && sameRange(range, next)) {\n return;\n }\n range = next;\n onRange(next);\n }\n\n const rowObserver = new ResizeObserver((entries) => {\n let changed = false;\n for (const entry of entries) {\n const index = indexByElement.get(entry.target);\n if (index === undefined) continue;\n const height = entry.target.getBoundingClientRect().height;\n if (heights[index] !== height) {\n heights[index] = height;\n changed = true;\n }\n }\n if (changed) {\n recompute();\n }\n });\n\n // Kept current here rather than read on each recompute: a scroll can fire\n // many times a second, and each one only needs to feed the next window.\n const viewportObserver = new ResizeObserver(() => {\n viewportHeight = scrollElement.clientHeight;\n recompute();\n });\n viewportObserver.observe(scrollElement);\n\n function handleScroll(): void {\n scrollTop = scrollElement.scrollTop;\n recompute();\n }\n scrollElement.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n function estimateOffsetBefore(index: number): number {\n let total = 0;\n for (let current = 0; current < index; current++) {\n total += heights[current] ?? estimatedRowHeight;\n }\n return total;\n }\n\n recompute();\n\n return {\n setRowCount(count) {\n heights = Array.from({ length: count }, (_, index) => heights[index]);\n recompute();\n },\n resetHeights() {\n heights = new Array<number | undefined>(heights.length).fill(undefined);\n recompute();\n },\n measureRow(index) {\n let callback = refCallbacks.get(index);\n if (callback === undefined) {\n callback = (element) => {\n const previous = elements.get(index);\n if (previous !== undefined) {\n rowObserver.unobserve(previous);\n indexByElement.delete(previous);\n elements.delete(index);\n }\n if (element === null || destroyed) {\n return;\n }\n elements.set(index, element);\n indexByElement.set(element, index);\n rowObserver.observe(element);\n if (pendingScroll?.index === index) {\n element.scrollIntoView(pendingScroll.options);\n pendingScroll = undefined;\n }\n };\n refCallbacks.set(index, callback);\n }\n return callback;\n },\n scrollToIndex(index, scrollOptions) {\n if (heights.length === 0) {\n return;\n }\n const clamped = Math.max(0, Math.min(index, heights.length - 1));\n const mounted = elements.get(clamped);\n if (mounted !== undefined) {\n mounted.scrollIntoView(scrollOptions);\n return;\n }\n pendingScroll = { index: clamped, options: scrollOptions };\n scrollElement.scrollTop = estimateOffsetBefore(clamped);\n },\n destroy() {\n destroyed = true;\n pendingScroll = undefined;\n scrollElement.removeEventListener(\"scroll\", handleScroll);\n viewportObserver.disconnect();\n rowObserver.disconnect();\n elements.clear();\n indexByElement.clear();\n },\n };\n}\n","import { nextMenuIndex, type MenuMove } from \"@gridkitjs/core\";\n\n/** Every element a toolbar is made of. Those with no control in them — separators, spacers — are passed over. */\nconst ENTRY = \"[data-gridkit-toolbar-item]\";\n\n/** What can take focus: an entry's control is the entry itself, or the first of these in it. */\nconst FOCUSABLE = [\n \"button:not(:disabled)\",\n \"input:not(:disabled)\",\n \"select:not(:disabled)\",\n \"textarea:not(:disabled)\",\n \"a[href]\",\n \"[tabindex]\",\n].join(\", \");\n\n/** The keys that move focus, and where to. */\nconst MOVES: Readonly<Record<string, MenuMove>> = {\n ArrowRight: \"next\",\n ArrowLeft: \"previous\",\n Home: \"first\",\n End: \"last\",\n};\n\n/** Each control, as `nextMenuIndex` reads it: no separators are among them. */\nconst AS_ENTRY = { type: \"item\" } as const;\n\n/** Input types with no caret, whose arrow keys the toolbar may take. */\nconst CARETLESS_INPUTS = new Set([\n \"button\",\n \"checkbox\",\n \"color\",\n \"file\",\n \"image\",\n \"radio\",\n \"range\",\n \"reset\",\n \"submit\",\n]);\n\ninterface Control {\n /** The `data-gridkit-toolbar-item` element. */\n readonly entry: HTMLElement;\n /** What takes focus for it. */\n readonly target: HTMLElement;\n}\n\nfunction targetOf(entry: HTMLElement): HTMLElement | null {\n return entry.matches(FOCUSABLE)\n ? entry\n : entry.querySelector<HTMLElement>(FOCUSABLE);\n}\n\n/** A field typed in, whose caret the arrow keys move. */\nfunction textFieldOf(\n target: EventTarget | null,\n): HTMLInputElement | HTMLTextAreaElement | null {\n return target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLInputElement && !CARETLESS_INPUTS.has(target.type))\n ? target\n : null;\n}\n\n/**\n * Whether a key belongs to the text field it was pressed in rather than to\n * the toolbar: Home and End always do, and an arrow does unless the caret\n * sits at the end it points past — so the arrows still lead out of a field,\n * which would otherwise trap focus in it, the toolbar's one tab stop.\n */\nfunction belongsToField(target: EventTarget | null, move: MenuMove): boolean {\n if (target instanceof HTMLElement && target.isContentEditable) {\n return true;\n }\n const field = textFieldOf(target);\n if (field === null) {\n return false;\n }\n const { selectionStart, selectionEnd, value } = field;\n // A type that keeps its caret to itself — `email`, `number` — reports\n // none, so every key is left to it rather than taken from under a caret.\n if (\n move === \"first\" ||\n move === \"last\" ||\n selectionStart === null ||\n selectionStart !== selectionEnd\n ) {\n return true;\n }\n return move === \"previous\"\n ? selectionStart > 0\n : selectionStart < value.length;\n}\n\n/**\n * Makes `toolbar` — a `role=\"toolbar\"` element the renderer drew — one tab\n * stop that the arrow keys move within, following the WAI-ARIA toolbar\n * pattern: ArrowRight and ArrowLeft move focus to the next and previous\n * control, wrapping round the ends, and Home and End to the first and last.\n * Returns the function that stops it.\n *\n * The toolbar's entries are its descendants with a `data-gridkit-toolbar-item`,\n * and each entry's control is the entry itself when it can take focus, else\n * the first element in it that can; an entry with none — a separator, a\n * spacer — is passed over. They are read afresh on every key. One control at\n * a time has `tabindex=\"0\"` — the focused one, or the first — and the rest\n * `-1`, kept so as entries come and go; a control with\n * `aria-disabled=\"true\"` stays one of them, so a screen reader finds it.\n *\n * A text field keeps the keys it needs: Home and End, and an arrow while\n * the caret has text to move through in that direction. At the start or end\n * of its text, the arrow moves on to the next control.\n */\nexport function attachToolbar(toolbar: HTMLElement): () => void {\n /** The control with `tabindex=\"0\"`. */\n let stop: HTMLElement | undefined;\n\n function controls(): Control[] {\n return Array.from(toolbar.querySelectorAll<HTMLElement>(ENTRY)).flatMap(\n (entry) => {\n const target = targetOf(entry);\n return target === null ? [] : [{ entry, target }];\n },\n );\n }\n\n function indexOf(all: readonly Control[], node: EventTarget | null): number {\n return node instanceof Node\n ? all.findIndex((control) => control.entry.contains(node))\n : -1;\n }\n\n function setTabStop(next: HTMLElement | undefined): void {\n stop = next;\n for (const { target } of controls()) {\n target.tabIndex = target === next ? 0 : -1;\n }\n }\n\n function onKeyDown(event: KeyboardEvent): void {\n const move = MOVES[event.key];\n if (\n move === undefined ||\n event.isComposing ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.shiftKey ||\n belongsToField(event.target, move)\n ) {\n return;\n }\n const all = controls();\n const from = indexOf(all, event.target);\n if (from === -1) {\n return;\n }\n const next =\n all[\n nextMenuIndex(\n all.map(() => AS_ENTRY),\n from,\n move,\n )\n ];\n if (next !== undefined) {\n event.preventDefault();\n setTabStop(next.target);\n next.target.focus();\n }\n }\n\n // However focus arrived — a click, Tab, a script — the tab stop follows it.\n function onFocusIn(event: FocusEvent): void {\n const all = controls();\n const control = all[indexOf(all, event.target)];\n if (control !== undefined) {\n setTabStop(control.target);\n }\n }\n\n // A control drawn since — a button whose command became visible — would\n // otherwise come with the browser's own tab stop, and make two. The stop\n // stays where it was while its control is still drawn.\n const observer = new MutationObserver(() => {\n const all = controls();\n setTabStop(\n all.find(({ target }) => target === stop)?.target ?? all[0]?.target,\n );\n });\n\n const all = controls();\n setTabStop(\n all[indexOf(all, document.activeElement)]?.target ?? all[0]?.target,\n );\n toolbar.addEventListener(\"keydown\", onKeyDown);\n toolbar.addEventListener(\"focusin\", onFocusIn);\n observer.observe(toolbar, { childList: true, subtree: true });\n\n return () => {\n observer.disconnect();\n toolbar.removeEventListener(\"keydown\", onKeyDown);\n toolbar.removeEventListener(\"focusin\", onFocusIn);\n };\n}\n","import {\n fitToolbarItems,\n isPinnedToolbarItem,\n type ResolvedToolbarItem,\n} from \"@gridkitjs/core\";\n\n/**\n * A toolbar entry as the overflow reads it: its kind, the key its element\n * carries and, for a button or a dropdown, its label — a change to which,\n * while the entry is in \"More\" and not drawn, makes the width remembered for\n * it stale.\n */\nexport type ToolbarOverflowItem = Pick<ResolvedToolbarItem, \"type\" | \"key\"> & {\n readonly label?: string | undefined;\n};\n\nexport interface ToolbarOverflowOptions {\n /**\n * Every entry of the toolbar, in order — those drawn and those moved into\n * \"More\" alike — as `resolveToolbar` gave them.\n */\n readonly items: readonly ToolbarOverflowItem[];\n /**\n * How many entries fit, as `fitToolbarItems` counts them: called once\n * straight away, then whenever the count changes.\n */\n readonly onChange: (fit: number) => void;\n}\n\nexport interface ToolbarOverflow {\n /**\n * Call whenever the items change, with the current options: measures\n * again, and reports a changed count.\n */\n readonly update: (options: ToolbarOverflowOptions) => void;\n /** Stops observing. */\n readonly detach: () => void;\n}\n\nconst ENTRY_ATTRIBUTE = \"data-gridkit-toolbar-item\";\nconst MORE_ATTRIBUTE = \"data-gridkit-toolbar-more\";\n\nfunction pixels(value: string): number {\n return Number.parseFloat(value) || 0;\n}\n\n/** The room an element takes in its row: its box and its margins. */\nfunction outerWidth(element: HTMLElement): number {\n const style = getComputedStyle(element);\n return (\n element.getBoundingClientRect().width +\n pixels(style.marginLeft) +\n pixels(style.marginRight)\n );\n}\n\n/**\n * Measures how many of a toolbar's entries fit in it, reporting the count\n * through `onChange` straight away — so a renderer calling this before\n * paint draws the right entries from the first frame — and again whenever a\n * resize changes it. The arithmetic is @gridkitjs/core's `fitToolbarItems`:\n * the search box and custom entries always stay, and room for \"More\" is kept\n * only when something does not fit.\n *\n * Entries are found by their `data-gridkit-toolbar-item`, holding each\n * item's `key`, and the \"More\" button by `data-gridkit-toolbar-more`. An\n * entry moved into \"More\" is no longer drawn, so each width is remembered\n * by key from the last time it was; one never drawn yet counts as nothing,\n * which lets it be drawn, measured, and moved back out if it does not fit —\n * as one whose label changed while it was not drawn counts again.\n * A spacer counts as nothing too: its width is only the room left over. The\n * toolbar's padding and the `column-gap` between entries are allowed for.\n *\n * It measures again whenever the toolbar or an entry resizes and whenever\n * entries are drawn or taken away — the ones the count it reported let in,\n * or the \"More\" button — so a renderer only has to draw what it is told,\n * and to pass new items to `update`.\n */\nexport function observeToolbarOverflow(\n toolbar: HTMLElement,\n options: ToolbarOverflowOptions,\n): ToolbarOverflow {\n let current = options;\n const widths = new Map<string, number>();\n let moreWidth = 0;\n let reported: number | undefined;\n\n function drawnEntries(): HTMLElement[] {\n return Array.from(\n toolbar.querySelectorAll<HTMLElement>(`[${ENTRY_ATTRIBUTE}]`),\n );\n }\n\n function measure(): void {\n for (const element of drawnEntries()) {\n if (element.hasAttribute(MORE_ATTRIBUTE)) {\n moreWidth = outerWidth(element);\n } else {\n widths.set(\n element.getAttribute(ENTRY_ATTRIBUTE) ?? \"\",\n outerWidth(element),\n );\n }\n }\n const style = getComputedStyle(toolbar);\n // Every entry is counted with the gap after it, so the row gets one gap\n // more than it has — the one after its last entry — to share.\n const gap = pixels(style.columnGap);\n const fit = fitToolbarItems({\n widths: current.items.map(\n (item) =>\n (item.type === \"spacer\" ? 0 : (widths.get(item.key) ?? 0)) + gap,\n ),\n available:\n toolbar.clientWidth -\n pixels(style.paddingLeft) -\n pixels(style.paddingRight) +\n gap,\n moreWidth: moreWidth + gap,\n pinned: current.items.map(isPinnedToolbarItem),\n });\n if (fit !== reported) {\n reported = fit;\n current.onChange(fit);\n }\n }\n\n /** The toolbar for the room there is, and every entry drawn for a label that changed its width. */\n const resizes = new ResizeObserver(measure);\n\n function observeSizes(): void {\n resizes.disconnect();\n resizes.observe(toolbar);\n for (const element of drawnEntries()) {\n resizes.observe(element);\n }\n }\n\n const draws = new MutationObserver(() => {\n observeSizes();\n measure();\n });\n\n observeSizes();\n draws.observe(toolbar, { childList: true, subtree: true });\n measure();\n\n return {\n update(next) {\n // An entry whose label changed while it was in \"More\" is forgotten, so\n // it counts as never drawn: drawn, measured afresh, and moved back out\n // if it no longer fits. One drawn is measured again straight away.\n const labels = new Map(\n current.items.map((item) => [item.key, item.label]),\n );\n for (const item of next.items) {\n if (labels.has(item.key) && labels.get(item.key) !== item.label) {\n widths.delete(item.key);\n }\n }\n current = next;\n measure();\n },\n detach() {\n resizes.disconnect();\n draws.disconnect();\n },\n };\n}\n"],"mappings":";AAYA,IAAM,iBAAiB,OAAO,cAAc,GAAI;AAgBzC,SAAS,oBACd,YAAyB,SAAS,MACnB;AACf,QAAM,SAAS,SAAS,cAAc,KAAK;AAC3C,SAAO,YAAY;AACnB,SAAO,aAAa,QAAQ,QAAQ;AACpC,SAAO,aAAa,aAAa,QAAQ;AACzC,YAAU,OAAO,MAAM;AAEvB,MAAI,OAAO;AACX,MAAI,SAAS;AAEb,SAAO;AAAA,IACL,SAAS,MAAM;AACb,eAAS,SAAS,QAAQ,CAAC;AAC3B,aAAO;AACP,aAAO,cAAc,SAAS,OAAO,iBAAiB;AAAA,IACxD;AAAA,IACA,UAAU;AACR,aAAO,OAAO;AAAA,IAChB;AAAA,EACF;AACF;;;ACtBA,SAAS,WAAW,KAA6B;AAC/C,QAAM,YAAY,IAAI,aAAa,wBAAwB;AAC3D,SAAO,cAAc,OAAO,OAAO,OAAO,SAAS;AACrD;AAYO,SAAS,aACd,QACuB;AACvB,MAAI,EAAE,kBAAkB,UAAU;AAChC,WAAO;AAAA,EACT;AACA,QAAM,OAAO,OAAO,QAAQ,yBAAyB;AACrD,QAAM,MAAM,MAAM;AAClB,QAAM,WAAW,MAAM,aAAa,qBAAqB;AACzD,QAAM,WAAW,QAAQ,QAAQ,QAAQ,SAAY,OAAO,WAAW,GAAG;AAC1E,MACE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,KAAK,OAAO;AAC7B,YAAI,OAAO,IAAI,KAAK,GAAG,KAAK,OAAO,IAAI,KAAK,GAAG,MAAM,KAAK,OAAO;AAC/D,iBAAO,OAAO,KAAK,GAAG;AAAA,QACxB;AAAA,MACF;AACA,gBAAU;AACV,cAAQ;AAAA,IACV;AAAA,IACA,SAAS;AACP,cAAQ,WAAW;AACnB,YAAM,WAAW;AAAA,IACnB;AAAA,EACF;AACF;","names":["onKeyDown","onKeyDown","onKeyDown","nextMenuIndex","FOCUSABLE","MOVES","AS_ENTRY","all","onKeyDown"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gridkitjs/dom",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Framework-free browser behaviours for GridKit renderers: gestures, focus, observers, virtualization, overlays and announcements.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blagoja Blazhevski",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"README.md"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@gridkitjs/core": "0.
|
|
40
|
+
"@gridkitjs/core": "0.12.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"tsup": "^8.5.1",
|