@gridkitjs/dom 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,755 @@
1
+ import { ColumnResizeSession, ColumnOrderState, GroupByState, GridFocus, NavigationModifiers, VisibleRange, ResolvedToolbarItem } from '@gridkitjs/core';
2
+
3
+ /** A live region to report changes through. */
4
+ interface LiveAnnouncer {
5
+ /**
6
+ * Has assistive technology read `text` out, politely — after whatever it is
7
+ * already saying. The same text twice in a row is read twice.
8
+ */
9
+ readonly announce: (text: string) => void;
10
+ /** Removes the live region. */
11
+ readonly destroy: () => void;
12
+ }
13
+ /**
14
+ * Creates the one live region a grid reports through — a reorder, a resize, a
15
+ * bulk selection, anything no visual cue can carry to a screen reader — as
16
+ * the last child of `container`.
17
+ *
18
+ * Polite rather than assertive, so an announcement waits for a pause instead
19
+ * of cutting across what the user is already hearing. The element carries
20
+ * `gridkit-sr-only`, which the theme clips to nothing while leaving it in the
21
+ * accessibility tree.
22
+ *
23
+ * A live region speaks only when its text changes, so a message identical to
24
+ * the last would go unheard. A no-break space, added and dropped in turn,
25
+ * makes the repeat a change without changing what is read.
26
+ */
27
+ declare function createLiveAnnouncer(container?: HTMLElement): LiveAnnouncer;
28
+
29
+ /** The data cell an event happened in. */
30
+ interface BodyCellTarget {
31
+ /** The row's place among every body row, from its `data-gridkit-row-index`. */
32
+ readonly rowIndex: number;
33
+ /** The cell's place in its row, off the table's own indices. */
34
+ readonly columnIndex: number;
35
+ readonly columnId: string;
36
+ }
37
+ /** The group-header row an event happened in. */
38
+ interface GroupRowTarget {
39
+ readonly rowIndex: number;
40
+ readonly groupId: string;
41
+ }
42
+ /** The body row an event happened in — a data row, or a group's header or summary. */
43
+ interface BodyRowTarget {
44
+ readonly rowIndex: number;
45
+ /** The column of the cell it happened in, `null` when it was in none. */
46
+ readonly columnId: string | null;
47
+ }
48
+ /**
49
+ * The data cell `target` is in — what a renderer delegating its body's
50
+ * events to one listener asks of each event. `closest` is what makes the
51
+ * whole cell the target: a click on a template's own markup resolves to the
52
+ * cell holding it.
53
+ *
54
+ * Never matches inside a group-header row: that row's single `<td>` carries
55
+ * no `data-gridkit-column` (it spans every column at once, so no one column
56
+ * id applies), which keeps this to data rows without a check of its own.
57
+ */
58
+ declare function bodyCellFrom(target: EventTarget | null): BodyCellTarget | null;
59
+ /** The group-header row (`tr[data-gridkit-group]`) `target` is in. */
60
+ declare function groupRowFrom(target: EventTarget | null): GroupRowTarget | null;
61
+ /**
62
+ * The row `target` is in, cell or not — all a row click needs. The column is
63
+ * read only off a cell of that very row, so a table inside a cell template
64
+ * cannot lend it one of its own.
65
+ */
66
+ declare function bodyRowFrom(target: EventTarget | null): BodyRowTarget | null;
67
+
68
+ /**
69
+ * How a context menu was asked for: by a pointer — a right-click, or a touch
70
+ * held still — or by the keyboard.
71
+ */
72
+ type ContextMenuSource = "pointer" | "keyboard";
73
+ /** A context menu asked for inside the root, as `onRequest` hears of it. */
74
+ interface ContextMenuRequest {
75
+ /** The element it was asked for on: the one under the pointer, or the one focused for a key. */
76
+ readonly target: Element;
77
+ /**
78
+ * Where the pointer was, in viewport coordinates — where a menu opened by
79
+ * it goes. `null` from the keyboard, which has no point: a menu it opens
80
+ * goes beside the focused element instead.
81
+ */
82
+ readonly point: {
83
+ readonly x: number;
84
+ readonly y: number;
85
+ } | null;
86
+ readonly source: ContextMenuSource;
87
+ }
88
+ interface ContextMenuTriggerOptions {
89
+ /**
90
+ * A context menu was asked for inside the root. Returns whether the caller
91
+ * opened one of its own: if so the browser's menu is prevented, and if not
92
+ * it shows as it would have.
93
+ */
94
+ readonly onRequest: (request: ContextMenuRequest) => boolean;
95
+ }
96
+ /**
97
+ * Reports every context menu the user asks for inside `root` — a right-click,
98
+ * Shift+F10, the ContextMenu key, or a touch held still for half a second —
99
+ * through `onRequest`, and returns the function that stops it.
100
+ *
101
+ * Each gesture asks once. Pressing a key, or holding a touch, also makes some
102
+ * browsers fire `contextmenu` of their own, and that event is taken, not
103
+ * reported again, once the gesture opened a menu. The click a touch brings
104
+ * as it lifts is taken too: the menu opened under the finger, and the click
105
+ * would land in it.
106
+ *
107
+ * An event something already prevented is left alone, so a cell template
108
+ * that shows a menu of its own keeps it. That is why the listeners are on the
109
+ * document, in the bubble phase: a framework that handles events at its own
110
+ * root container — React does — hears them before the document does, where
111
+ * a listener on `root` itself would hear them first. Only events whose target
112
+ * is inside `root` count.
113
+ */
114
+ declare function attachContextMenuTrigger(root: Element, options: ContextMenuTriggerOptions): () => void;
115
+
116
+ /**
117
+ * The `pointerdown` a gesture starts from. A native `PointerEvent` is one,
118
+ * and so is a framework's wrapper around it, such as React's synthetic
119
+ * event, so a renderer passes whichever its handler received.
120
+ */
121
+ interface PointerPress {
122
+ readonly pointerId: number;
123
+ readonly clientX: number;
124
+ readonly clientY: number;
125
+ readonly button: number;
126
+ readonly isPrimary: boolean;
127
+ preventDefault(): void;
128
+ }
129
+
130
+ interface ColumnResizeGestureHandlers {
131
+ /** Every pointer move, with the width the column takes there. */
132
+ readonly onMove: (width: number) => void;
133
+ /**
134
+ * The pointer was released. `width` is the width to commit, or `null` when
135
+ * it ended where it started: a click on the handle — as each half of a
136
+ * double-click is — is not a resize, and reporting one would fire a
137
+ * spurious resize on every click.
138
+ */
139
+ readonly onEnd: (width: number | null) => void;
140
+ /** Escape, or a cancelled pointer: the column goes back to `session.startWidth`. */
141
+ readonly onCancel: () => void;
142
+ }
143
+ /**
144
+ * Drags a column's edge from `press` on its resize `handle`, turning pointer
145
+ * positions into widths through `@gridkitjs/core`'s `session` — begun with
146
+ * `beginColumnResize` — and reporting them. Returns whether a resize began:
147
+ * only the primary button of the primary pointer starts one.
148
+ *
149
+ * Captures the pointer on `handle`, so the drag keeps reporting wherever the
150
+ * pointer goes, and prevents the press's default, so it does not select the
151
+ * header text it started on. No minimum distance, unlike a reorder drag: the
152
+ * handle does nothing else a press could have meant.
153
+ */
154
+ declare function startColumnResizeGesture(handle: HTMLElement, press: PointerPress, session: ColumnResizeSession, handlers: ColumnResizeGestureHandlers): boolean;
155
+ /**
156
+ * The width the widest cell in `columnId` needs to show its content in full,
157
+ * or `null` when the column has no cells — what double-clicking a resize
158
+ * handle sizes the column to, through `sizeColumnToContent`.
159
+ *
160
+ * Measured with a `Range` over each cell's contents rather than the cell's own
161
+ * `scrollWidth`. A range shrink-wraps what is actually laid out, so a column
162
+ * far wider than its content reports the content width and can be sized *down*;
163
+ * `scrollWidth` never reports less than the cell it is read from and so can
164
+ * only ever grow a column.
165
+ *
166
+ * Only rendered rows are measured — on a paged or virtualized grid, the ones
167
+ * on screen.
168
+ */
169
+ declare function measureColumnContent(table: HTMLTableElement, columnId: string): number | null;
170
+
171
+ /** What a renderer draws while a reorder drag is open. */
172
+ interface DragReorderState<Target> {
173
+ /** The item being dragged, once the press has become a drag. */
174
+ readonly draggedId: string | null;
175
+ /** Where it would land if released now, `null` for nowhere valid. */
176
+ readonly dropTarget: Target | null;
177
+ /** Where the element trailing the pointer sits, as a CSS `transform`. */
178
+ readonly ghostTransform: string | null;
179
+ }
180
+ /** The state while nothing is dragged — the one a drag reports when it ends. */
181
+ declare const NO_DRAG: DragReorderState<never>;
182
+ interface DragReorderHandlers<Target> {
183
+ /**
184
+ * Where a drop at `(clientX, clientY)` would land, or `null` for nowhere
185
+ * valid — including a gap `id` already occupies, so a drop target only
186
+ * ever promises a move that happens. Called on every pointer move once the
187
+ * drag has opened. `resolveColumnDropTarget` and
188
+ * `resolveGroupByDropTarget` are the grid's own.
189
+ */
190
+ readonly resolveTarget: (clientX: number, clientY: number, id: string) => Target | null;
191
+ /** Every change to what the renderer draws, `NO_DRAG` once the drag ends. */
192
+ readonly onState: (state: DragReorderState<Target>) => void;
193
+ /** The pointer was released over a valid target. */
194
+ readonly onDrop: (target: Target, id: string) => void;
195
+ }
196
+ /**
197
+ * The pointer mechanics behind every drag-to-reorder gesture in the grid — a
198
+ * column header dragged among the others or into the group-by bar, a
199
+ * group-by chip dragged within it: capture, the drag threshold, and the ghost
200
+ * trailing the pointer, holding the spot it was picked up by. Returns whether
201
+ * a gesture began; only the main button of the primary pointer starts one.
202
+ *
203
+ * The press is left to its default, so the pressed element still takes focus;
204
+ * until the pointer has travelled `DRAG_THRESHOLD` pixels nothing is
205
+ * reported, so a press that never moves stays a click. Escape, or a cancelled
206
+ * pointer, leaves the order as it was.
207
+ *
208
+ * Pointer events rather than HTML5 drag-and-drop: `dragenter`/`dragleave`
209
+ * fire per descendant, so a dragged item's own inner markup would each report
210
+ * the target leaving and re-entering as the pointer crossed them.
211
+ */
212
+ declare function startDragReorder<Target>(id: string, grabElement: HTMLElement, press: PointerPress, handlers: DragReorderHandlers<Target>): boolean;
213
+
214
+ /** A drop into the group-by bar, in front of `beforeColumnId` — `null` to append. */
215
+ interface GroupByDropTarget {
216
+ readonly kind: "group-by";
217
+ readonly beforeColumnId: string | null;
218
+ }
219
+ /**
220
+ * Where a dragged column header would land: among the other headers, in
221
+ * front of `beforeId` (`null` for the end), or in the group-by bar.
222
+ */
223
+ type ColumnDropTarget = {
224
+ readonly kind: "column-order";
225
+ readonly beforeId: string | null;
226
+ } | GroupByDropTarget;
227
+ interface ColumnDropContext {
228
+ /** The ids of the columns on screen, in order — what a drop is resolved among. */
229
+ readonly order: ColumnOrderState;
230
+ /** What a drop onto the group-by bar is resolved against. */
231
+ readonly groupBy: GroupByState;
232
+ /** Column ids whose header may be dragged into the group-by bar at all. */
233
+ readonly groupByDraggableIds: ReadonlySet<string>;
234
+ }
235
+ /**
236
+ * Where a header or chip dropped at `(clientX, clientY)` would land within
237
+ * the group-by bar (`[data-gridkit-group-by-bar]`, its chips
238
+ * `[data-gridkit-group-chip]`), or `null` when the pointer isn't over the bar
239
+ * at all, or when the drop would change nothing. Shared by a header dragged
240
+ * in from outside the bar and a chip dragged within it, so the two can never
241
+ * disagree about where a drop lands.
242
+ */
243
+ declare function resolveGroupByDropTarget(clientX: number, clientY: number, movedId: string, groupBy: GroupByState): GroupByDropTarget | null;
244
+ /**
245
+ * Where the header of `movedId` dropped at `(clientX, clientY)` would land:
246
+ * before or after another header (`th[data-gridkit-column]`), by which half
247
+ * of it the pointer is over, or else in the group-by bar — or `null` for
248
+ * nowhere a drop would change anything.
249
+ *
250
+ * A column already grouped never targets the bar: reordering it there is its
251
+ * chip's job, not its header's.
252
+ */
253
+ declare function resolveColumnDropTarget(clientX: number, clientY: number, movedId: string, { order, groupBy, groupByDraggableIds }: ColumnDropContext): ColumnDropTarget | null;
254
+
255
+ /**
256
+ * Reports `element`'s inner width now and on every change after, until the
257
+ * returned function disconnects it — what `resizeMode: "fit"` fills.
258
+ *
259
+ * The first report is synchronous, so a renderer calling this before paint
260
+ * lays its columns out at the right width from the first frame rather than
261
+ * visibly jumping once the observer's first callback arrives.
262
+ *
263
+ * Reads `clientWidth` rather than the observer entry's `contentRect` so the
264
+ * first report and every later one come from the same, already-rounded,
265
+ * source.
266
+ */
267
+ declare function observeElementWidth(element: HTMLElement, onWidth: (width: number) => void): () => void;
268
+
269
+ /**
270
+ * The window of rows a row virtualizer has drawn, and a way to bring a row
271
+ * into it — what a focus move needs when its target row may not be mounted.
272
+ */
273
+ interface FocusVirtualRange {
274
+ readonly startIndex: number;
275
+ readonly endIndex: number;
276
+ readonly scrollToIndex: (index: number) => void;
277
+ }
278
+ /** How to find the rendered rows the browser's focus moves among. */
279
+ interface GridFocusRows {
280
+ /** The header row's element, `null` while none is rendered. */
281
+ readonly getHeaderRow: () => HTMLTableRowElement | null;
282
+ /** Body row `rowIndex`'s element — `findBodyRow` finds it — `null` while it is not rendered. */
283
+ readonly getBodyRow: (rowIndex: number) => HTMLTableRowElement | null;
284
+ }
285
+ interface GridFocusOptions {
286
+ /** Body rows, counting group headers and summaries — every row a key could step through. */
287
+ readonly rowCount: number;
288
+ readonly columnCount: number;
289
+ /**
290
+ * Rows the vertical keys step over rather than stop on — a group's own
291
+ * summary row, which takes a row slot but is not a stop of its own.
292
+ */
293
+ readonly isSkippableRow?: ((rowIndex: number) => boolean) | undefined;
294
+ /**
295
+ * The window the renderer drew, when rows are virtualized. A move can
296
+ * target a row outside it — `ArrowDown` past its end, or `Ctrl+End` — that
297
+ * no lookup would find until it is scrolled into range.
298
+ */
299
+ readonly virtualRange?: FocusVirtualRange | null | undefined;
300
+ }
301
+ interface GridFocusController {
302
+ /**
303
+ * The cell holding the grid's single tab stop, clamped into the current
304
+ * row and column counts. The same object until it changes, so it can serve
305
+ * as a renderer's snapshot.
306
+ */
307
+ readonly getFocus: () => GridFocus;
308
+ /** Calls `listener` whenever the focused cell moves. Returns the unsubscribe. */
309
+ readonly subscribe: (listener: () => void) => () => void;
310
+ /**
311
+ * Replaces the options, as a renderer does on every render with its
312
+ * current counts and window. Calls no listener: the renderer calling it is
313
+ * already drawing.
314
+ */
315
+ readonly setOptions: (options: GridFocusOptions) => void;
316
+ /**
317
+ * Moves the tab stop, and the browser's focus with it once the renderer
318
+ * has drawn the move (see `focusDrawnCell`). Moving to the cell already
319
+ * focused does nothing, which is what lets a cell's own `focus` event
320
+ * report a click through here without a loop.
321
+ */
322
+ readonly focusCell: (rowIndex: number, columnIndex: number) => void;
323
+ /**
324
+ * Moves the tab stop as `key` does — the arrows, Home, End, the page keys,
325
+ * with Ctrl for the grid's corners. Returns whether the key was one of
326
+ * them, in which case the caller prevents its default: taken even when the
327
+ * move lands nowhere, or an arrow at the last row would scroll the page
328
+ * out from under the grid.
329
+ */
330
+ readonly handleKey: (key: string, modifiers: NavigationModifiers, pageSize: number) => boolean;
331
+ /**
332
+ * Connects the tab stop to the rendered rows, which the browser's focus
333
+ * then follows it among. Returns the function that disconnects them.
334
+ */
335
+ readonly attach: (rows: GridFocusRows) => () => void;
336
+ /**
337
+ * Called by the renderer once it has drawn `drawn` — a value `getFocus`
338
+ * returned — so the browser's focus follows a move to the cell now in the
339
+ * markup. Does nothing unless a move to exactly that drawing is pending.
340
+ */
341
+ readonly focusDrawnCell: (drawn: GridFocus) => void;
342
+ }
343
+ /**
344
+ * Body row `rowIndex` in `bodyTable`, by its `data-gridkit-row-index` rather
345
+ * than by its position in `tBodies[0].rows`: a virtualized body holds only a
346
+ * slice of the rows, behind a leading spacer `<tr>`, so once the window
347
+ * scrolls a DOM position no longer matches the row's index in the full array
348
+ * and addresses some other mounted row, or none.
349
+ *
350
+ * The attribute holds a plain integer, so the selector needs no escaping,
351
+ * unlike one built from a consumer's row id.
352
+ */
353
+ declare function findBodyRow(bodyTable: HTMLTableElement | null, rowIndex: number): HTMLTableRowElement | null;
354
+ /**
355
+ * How many rows fit `bodyTable`'s scroll wrapper — its parent, the row area
356
+ * alone, not the header, footer and pager around it — which is what a page
357
+ * key moves. Reads the first rendered row's height, and falls back to ten
358
+ * rows when nothing can be measured.
359
+ */
360
+ declare function measurePageSize(bodyTable: HTMLTableElement | null): number;
361
+ /**
362
+ * The grid's single tab stop and the keys that move it, which is what
363
+ * `role="grid"` obliges: arrow keys travel cell to cell and Tab passes the
364
+ * whole grid by. The renderer attaches its rows, draws `getFocus()` —
365
+ * `tabindex="0"` on that cell, `-1` on every other — re-reads it when
366
+ * `subscribe` calls, and calls `focusDrawnCell` after drawing.
367
+ *
368
+ * Separate from selection, because focus and selection are different states:
369
+ * a cell is focused while travelling before anything is selected, and every
370
+ * cell of a range is selected without being focused. Navigation also has to
371
+ * work with selection off entirely.
372
+ *
373
+ * Starts on the header row's first cell.
374
+ */
375
+ declare function createGridFocus(initialOptions: GridFocusOptions): GridFocusController;
376
+
377
+ interface InfiniteScrollOptions {
378
+ /**
379
+ * The element whose approach triggers a load — the always-last row of the
380
+ * body — or `null` while none is rendered.
381
+ */
382
+ readonly sentinel: Element | null;
383
+ /** Whether a further load could still return more rows. `false` stops watching altogether. */
384
+ readonly hasMore: boolean;
385
+ /**
386
+ * Called at most once per approach: when the sentinel comes within
387
+ * `rootMargin` of the root's visible area, and not again until
388
+ * `isLoadingMore` has gone from `true` back to `false`.
389
+ */
390
+ readonly onLoadMore?: (() => void) | undefined;
391
+ /** Whether a load `onLoadMore` started is still in flight. */
392
+ readonly isLoadingMore?: boolean | undefined;
393
+ /** How far ahead of the sentinel scrolling into view a load starts, as CSS margins. Defaults to `"200px"`. */
394
+ readonly rootMargin?: string | undefined;
395
+ }
396
+ interface InfiniteScroll {
397
+ /**
398
+ * Takes the current options. Cheap when nothing changed, so a renderer may
399
+ * call it after every render; a new sentinel or `rootMargin` restarts the
400
+ * observer, and `isLoadingMore` going back to `false` re-checks at once.
401
+ */
402
+ readonly update: (options: InfiniteScrollOptions) => void;
403
+ /** Stops watching for good. */
404
+ readonly detach: () => void;
405
+ }
406
+ /**
407
+ * Turns a sentinel's approach to the bottom of the scrolling `root` into
408
+ * `onLoadMore` calls, no more than one per "the sentinel is near and no load
409
+ * is in flight since the last one finished".
410
+ *
411
+ * Three facts drive it: whether the sentinel is intersecting (as of the
412
+ * observer's last report), whether `onLoadMore` has fired since the last
413
+ * load finished, and whether a load was in flight at the last update. They
414
+ * outlive the sentinel itself, which a renderer mounts and unmounts as
415
+ * `hasMore` changes, so they live here rather than on any one observer.
416
+ *
417
+ * Off means off: with `hasMore` false, or no sentinel, no observer exists.
418
+ */
419
+ declare function attachInfiniteScroll(root: Element, options: InfiniteScrollOptions): InfiniteScroll;
420
+
421
+ /**
422
+ * Where focus goes when a submenu opens: its first item, or nowhere — it
423
+ * stays on the item that opened it, as when the pointer opened it.
424
+ */
425
+ type MenuSubmenuFocus = "first" | "none";
426
+ /** Why a menu asked for every menu to close. */
427
+ type MenuCloseReason = "tab";
428
+ interface MenuOptions {
429
+ /**
430
+ * An enabled item that opens no submenu was chosen — Enter, Space or a
431
+ * click. The caller runs it, and closes every menu.
432
+ */
433
+ readonly onActivate: (id: string) => void;
434
+ /**
435
+ * An enabled submenu item asks for its submenu: Enter, Space or ArrowRight
436
+ * on it want its first item focused (`"first"`), a click or the pointer
437
+ * resting on it want focus left where it is (`"none"`). It may come for a
438
+ * submenu already open — ArrowRight on one the pointer opened — when a
439
+ * `"first"` asks for focus to move into it (`focusItem(0)` on its menu).
440
+ * Opening it closes any other submenu open from this menu.
441
+ */
442
+ readonly onOpenSubmenu?: ((id: string, options: {
443
+ readonly focus: MenuSubmenuFocus;
444
+ }) => void) | undefined;
445
+ /**
446
+ * The pointer came to rest on an item that opens no submenu, or a disabled
447
+ * one: close whatever submenu is open from this menu, if any. Moving on to
448
+ * another item is how a pointer user leaves a submenu they did not want.
449
+ */
450
+ readonly onCollapseSubmenu?: (() => void) | undefined;
451
+ /**
452
+ * ArrowLeft was pressed in this menu, which is a submenu: close it, and
453
+ * focus goes back to the item that opened it. Passed only for a submenu —
454
+ * in a menu without it, ArrowLeft does nothing.
455
+ */
456
+ readonly onCloseSubmenu?: (() => void) | undefined;
457
+ /**
458
+ * Tab or Shift+Tab was pressed: close every menu, so focus returns to where
459
+ * the first one was opened from rather than moving on past it.
460
+ */
461
+ readonly onClose: (reason: MenuCloseReason) => void;
462
+ }
463
+ interface AttachedMenu {
464
+ /**
465
+ * Focuses an item, by its `data-gridkit-menu-item` id or its place among
466
+ * the items. Does nothing for an item the menu does not have.
467
+ */
468
+ readonly focusItem: (item: string | number) => void;
469
+ /** Removes every listener. The items keep the `tabindex` they had. */
470
+ readonly detach: () => void;
471
+ }
472
+ /**
473
+ * Makes `panel` — a `role="menu"` element the renderer drew — behave as a
474
+ * menu: the arrow keys, Home, End and typeahead move focus among its items,
475
+ * Enter, Space and a click choose one, ArrowRight and ArrowLeft open and
476
+ * close submenus, and the pointer moves focus to the item under it. It
477
+ * decides; the caller is told through the callbacks and draws the outcome —
478
+ * runs the item, opens or closes a submenu.
479
+ *
480
+ * Items are the panel's descendants with a menu item role (`menuitem`,
481
+ * `menuitemcheckbox`, `menuitemradio`) and a `data-gridkit-menu-item` id,
482
+ * read afresh on every key so items drawn since attaching count. A submenu
483
+ * item says so with `aria-haspopup="menu"`; an item with
484
+ * `aria-disabled="true"` takes focus, so a screen reader finds it, but is
485
+ * never chosen. One item at a time has `tabindex="0"` — the focused one, or
486
+ * the first — and the rest `-1`: every item can take focus, and the first is
487
+ * what an overlay's initial focus finds when the menu is attached before it.
488
+ *
489
+ * Escape is not handled: a menu is shown with `attachOverlay`, whose stack
490
+ * gives Escape to the topmost overlay. A submenu is a menu of its own, in an
491
+ * overlay of its own anchored to its item, attached when it opens.
492
+ */
493
+ declare function attachMenu(panel: HTMLElement, options: MenuOptions): AttachedMenu;
494
+
495
+ /** Which side of its anchor an overlay opens on. */
496
+ type OverlaySide = "top" | "bottom" | "left" | "right";
497
+ /**
498
+ * Which edge of the anchor the overlay lines up with along that side: its
499
+ * left edge (`start`) or right edge (`end`) for `top`/`bottom`, its top or
500
+ * bottom edge for `left`/`right`.
501
+ */
502
+ type OverlayAlign = "start" | "end";
503
+ type OverlayPlacement = `${OverlaySide}-${OverlayAlign}`;
504
+ /** A box in viewport coordinates, as `getBoundingClientRect` reports one. */
505
+ interface OverlayRect {
506
+ readonly top: number;
507
+ readonly left: number;
508
+ readonly width: number;
509
+ readonly height: number;
510
+ }
511
+ interface OverlaySize {
512
+ readonly width: number;
513
+ readonly height: number;
514
+ }
515
+ interface OverlayPlacementOptions {
516
+ /** Where the overlay would rather open. Defaults to `"bottom-start"`. */
517
+ readonly placement?: OverlayPlacement | undefined;
518
+ /** Space between the anchor and the overlay, in pixels. Defaults to `0`. */
519
+ readonly gap?: number | undefined;
520
+ /**
521
+ * Pixels to shift the overlay along the anchor's edge — down beside a
522
+ * `left`/`right` side, right beside `top`/`bottom`; negative goes the other
523
+ * way. A submenu opened `right-start` takes its own top padding, negated,
524
+ * so its first item lines up with the item that opened it. The overlay is
525
+ * still kept on screen. Defaults to `0`.
526
+ */
527
+ readonly offset?: number | undefined;
528
+ }
529
+ /** Where an overlay goes: its top-left corner, and the placement it ended up with. */
530
+ interface OverlayPosition {
531
+ readonly top: number;
532
+ readonly left: number;
533
+ readonly placement: OverlayPlacement;
534
+ }
535
+ /**
536
+ * Where an overlay of size `panel` goes beside `anchor` so that it stays in
537
+ * `viewport`: on the preferred side unless only the opposite one has room,
538
+ * lined up with the preferred edge unless that runs it off screen and the
539
+ * other edge does not, and finally pushed back inside if it still overflows.
540
+ * Pure, so the rules are testable without a browser; `attachOverlay` feeds it
541
+ * the measurements.
542
+ *
543
+ * A point — a context menu opened where the pointer is — is an anchor with
544
+ * no width or height, which is what makes `start`/`end` mean "after" and
545
+ * "before" it.
546
+ */
547
+ declare function placeOverlay(anchor: OverlayRect, panel: OverlaySize, viewport: OverlaySize, options?: OverlayPlacementOptions): OverlayPosition;
548
+
549
+ /** What an overlay opens beside: an element, or a point in viewport coordinates. */
550
+ type OverlayAnchor = Element | {
551
+ readonly x: number;
552
+ readonly y: number;
553
+ };
554
+ /**
555
+ * Where focus goes when an overlay attaches: its first focusable descendant,
556
+ * the panel itself, nowhere — focus stays where it was — or a given element.
557
+ */
558
+ type OverlayInitialFocus = "first" | "panel" | "none" | HTMLElement;
559
+ /** Why an overlay asked to close. */
560
+ type OverlayDismissReason = "escape" | "outside" | "scroll" | "resize" | "blur" | "parent";
561
+ interface OverlayOptions extends OverlayPlacementOptions {
562
+ /**
563
+ * The overlay asks to close: Escape was pressed while it was the topmost
564
+ * overlay, a pointer went down outside it, something outside it scrolled,
565
+ * the window resized or lost focus, focus moved outside it, or the overlay
566
+ * it was opened above detached. The caller closes it — removes the panel
567
+ * and detaches — or keeps it open by doing nothing, except after
568
+ * `"parent"`, which detaches it regardless.
569
+ */
570
+ readonly onDismiss: (reason: OverlayDismissReason) => void;
571
+ /**
572
+ * Where focus goes on attaching. Defaults to `"first"`: a menu focuses its
573
+ * first item. A panel whose first control is not where the user starts — a
574
+ * filter editor's operator picker before its value box — passes that
575
+ * element, or `"panel"` to land on the panel itself; `"none"` leaves focus
576
+ * where it was, as a suggestion list does while typing goes on in the
577
+ * field that opened it.
578
+ */
579
+ readonly initialFocus?: OverlayInitialFocus | undefined;
580
+ /**
581
+ * Where focus goes when the overlay detaches. Defaults to the element that
582
+ * had focus when it attached; `null` leaves focus alone.
583
+ */
584
+ readonly returnFocusTo?: HTMLElement | null | undefined;
585
+ /**
586
+ * Whether a scroll outside the panel just after input inside it — an
587
+ * `input` or `change` event, in the two animation frames that follow it —
588
+ * leaves it open. A panel whose controls change the page under it opts
589
+ * in: a column chooser hiding a column narrows the grid it opened from,
590
+ * and the browser scrolls that grid back within its narrower content.
591
+ * Defaults to `false`, where every scroll outside the panel dismisses it.
592
+ */
593
+ readonly ignoreScrollAfterInput?: boolean | undefined;
594
+ }
595
+ /**
596
+ * Shows `panel` as an overlay beside `anchor` — a menu, a popover, a filter
597
+ * editor — and returns the function that ends it. The caller renders the
598
+ * panel, usually as a child of `document.body` so no scrolling ancestor clips
599
+ * it; this positions it, moves focus into it, and reports through
600
+ * `onDismiss` when the user is done with it.
601
+ *
602
+ * The panel is positioned `fixed`, at the place `placeOverlay` picks from the
603
+ * anchor's and the panel's measured boxes, and carries that placement in
604
+ * `data-gridkit-placement` (`"top-start"` once flipped above, say) for a
605
+ * stylesheet to point an arrow by. Whenever the panel's size changes — a list
606
+ * that shrinks under a search — it is placed again beside the anchor, so a
607
+ * panel flipped above its anchor keeps its bottom edge there — or beside
608
+ * where the anchor was, once it has left the page. Focus moves
609
+ * where `initialFocus` says.
610
+ *
611
+ * Nothing that happens on or in the anchor dismisses the overlay, so a button
612
+ * that toggles it can close it with its own click rather than having the
613
+ * overlay close and the click reopen it.
614
+ *
615
+ * Overlays stack in the order they attach. Escape belongs to the topmost
616
+ * alone, which takes it: it closes a submenu without closing the menu under
617
+ * it, and nothing else on the page — a grid that clears its selection on
618
+ * Escape — hears it. An overlay counts everything in the overlays above it
619
+ * as inside itself, so a click in a submenu keeps its menu open while a click
620
+ * elsewhere in the menu closes only the submenu.
621
+ *
622
+ * Detaching removes every listener and returns focus, but only when focus is
623
+ * still in the panel, in an overlay above it, or nowhere — a click that
624
+ * dismissed it by landing on another control leaves focus on that control.
625
+ * Any overlay still above it is dismissed with `"parent"` and detached first.
626
+ */
627
+ declare function attachOverlay(anchor: OverlayAnchor, panel: HTMLElement, options: OverlayOptions): () => void;
628
+
629
+ interface RowVirtualizerOptions {
630
+ /** The height assumed for a row not yet measured. */
631
+ readonly estimatedRowHeight: number;
632
+ /** Rows rendered beyond each edge of the visible area. */
633
+ readonly overscan: number;
634
+ /**
635
+ * The window of rows to render moved: called whenever a scroll, a resize
636
+ * of the scroll element, a measured row height or a change of rows moves
637
+ * it, and never with a window equal to the last.
638
+ */
639
+ readonly onRange: (range: VisibleRange) => void;
640
+ }
641
+ interface RowVirtualizer {
642
+ /** How many rows there are. Measured heights of the rows that remain are kept. */
643
+ readonly setRowCount: (count: number) => void;
644
+ /** Forgets every measured height, for rows that are no longer the ones measured. */
645
+ readonly resetHeights: () => void;
646
+ /**
647
+ * A ref callback for the element of row `index` (its place among all the
648
+ * rows, not among those rendered): measured while mounted, forgotten once
649
+ * called with `null`. The same function for the same index every time, so
650
+ * a renderer re-attaching it on every render costs nothing.
651
+ */
652
+ readonly measureRow: (index: number) => (element: HTMLElement | null) => void;
653
+ /**
654
+ * Scrolls so row `index` is in view. A mounted row is scrolled to directly;
655
+ * one outside the window is jumped to at its estimated offset, then
656
+ * scrolled to properly once it mounts and can be measured.
657
+ */
658
+ readonly scrollToIndex: (index: number, options?: ScrollIntoViewOptions) => void;
659
+ /** Stops listening and measuring, for good. */
660
+ readonly destroy: () => void;
661
+ }
662
+ /**
663
+ * Windows a long list of rows inside `scrollElement` down to those near its
664
+ * scroll position, measuring each rendered row's real height rather than
665
+ * assuming a uniform one — rows are not uniform (`.is-wrapped` cells, group
666
+ * header and summary rows), so a fixed-height virtualizer would either break
667
+ * wrapping or rule it out. The renderer draws `onRange`'s window, with
668
+ * spacers of `offsetBefore`/`offsetAfter` around it, and hands each row's
669
+ * element to `measureRow`.
670
+ *
671
+ * The heights are a mutable array, not a structure rebuilt per measurement:
672
+ * one can arrive many times a second while scrolling. The pure arithmetic
673
+ * over them is `@gridkitjs/core`'s `visibleRange`; this owns only the
674
+ * mutability around it and the listeners that feed it — the scroll position,
675
+ * the scroll element's height, and one `ResizeObserver` shared by every
676
+ * mounted row.
677
+ */
678
+ declare function createRowVirtualizer(scrollElement: HTMLElement, options: RowVirtualizerOptions): RowVirtualizer;
679
+
680
+ /**
681
+ * Makes `toolbar` — a `role="toolbar"` element the renderer drew — one tab
682
+ * stop that the arrow keys move within, following the WAI-ARIA toolbar
683
+ * pattern: ArrowRight and ArrowLeft move focus to the next and previous
684
+ * control, wrapping round the ends, and Home and End to the first and last.
685
+ * Returns the function that stops it.
686
+ *
687
+ * The toolbar's entries are its descendants with a `data-gridkit-toolbar-item`,
688
+ * and each entry's control is the entry itself when it can take focus, else
689
+ * the first element in it that can; an entry with none — a separator, a
690
+ * spacer — is passed over. They are read afresh on every key. One control at
691
+ * a time has `tabindex="0"` — the focused one, or the first — and the rest
692
+ * `-1`, kept so as entries come and go; a control with
693
+ * `aria-disabled="true"` stays one of them, so a screen reader finds it.
694
+ *
695
+ * A text field keeps the keys it needs: Home and End, and an arrow while
696
+ * the caret has text to move through in that direction. At the start or end
697
+ * of its text, the arrow moves on to the next control.
698
+ */
699
+ declare function attachToolbar(toolbar: HTMLElement): () => void;
700
+
701
+ /**
702
+ * A toolbar entry as the overflow reads it: its kind, the key its element
703
+ * carries and, for a button or a dropdown, its label — a change to which,
704
+ * while the entry is in "More" and not drawn, makes the width remembered for
705
+ * it stale.
706
+ */
707
+ type ToolbarOverflowItem = Pick<ResolvedToolbarItem, "type" | "key"> & {
708
+ readonly label?: string | undefined;
709
+ };
710
+ interface ToolbarOverflowOptions {
711
+ /**
712
+ * Every entry of the toolbar, in order — those drawn and those moved into
713
+ * "More" alike — as `resolveToolbar` gave them.
714
+ */
715
+ readonly items: readonly ToolbarOverflowItem[];
716
+ /**
717
+ * How many entries fit, as `fitToolbarItems` counts them: called once
718
+ * straight away, then whenever the count changes.
719
+ */
720
+ readonly onChange: (fit: number) => void;
721
+ }
722
+ interface ToolbarOverflow {
723
+ /**
724
+ * Call whenever the items change, with the current options: measures
725
+ * again, and reports a changed count.
726
+ */
727
+ readonly update: (options: ToolbarOverflowOptions) => void;
728
+ /** Stops observing. */
729
+ readonly detach: () => void;
730
+ }
731
+ /**
732
+ * Measures how many of a toolbar's entries fit in it, reporting the count
733
+ * through `onChange` straight away — so a renderer calling this before
734
+ * paint draws the right entries from the first frame — and again whenever a
735
+ * resize changes it. The arithmetic is @gridkitjs/core's `fitToolbarItems`:
736
+ * the search box and custom entries always stay, and room for "More" is kept
737
+ * only when something does not fit.
738
+ *
739
+ * Entries are found by their `data-gridkit-toolbar-item`, holding each
740
+ * item's `key`, and the "More" button by `data-gridkit-toolbar-more`. An
741
+ * entry moved into "More" is no longer drawn, so each width is remembered
742
+ * by key from the last time it was; one never drawn yet counts as nothing,
743
+ * which lets it be drawn, measured, and moved back out if it does not fit —
744
+ * as one whose label changed while it was not drawn counts again.
745
+ * A spacer counts as nothing too: its width is only the room left over. The
746
+ * toolbar's padding and the `column-gap` between entries are allowed for.
747
+ *
748
+ * It measures again whenever the toolbar or an entry resizes and whenever
749
+ * entries are drawn or taken away — the ones the count it reported let in,
750
+ * or the "More" button — so a renderer only has to draw what it is told,
751
+ * and to pass new items to `update`.
752
+ */
753
+ declare function observeToolbarOverflow(toolbar: HTMLElement, options: ToolbarOverflowOptions): ToolbarOverflow;
754
+
755
+ export { type AttachedMenu, type BodyCellTarget, type BodyRowTarget, type ColumnDropContext, type ColumnDropTarget, type ColumnResizeGestureHandlers, type ContextMenuRequest, type ContextMenuSource, type ContextMenuTriggerOptions, type DragReorderHandlers, type DragReorderState, type FocusVirtualRange, type GridFocusController, type GridFocusOptions, type GridFocusRows, type GroupByDropTarget, type GroupRowTarget, type InfiniteScroll, type InfiniteScrollOptions, type LiveAnnouncer, type MenuCloseReason, type MenuOptions, type MenuSubmenuFocus, NO_DRAG, type OverlayAlign, type OverlayAnchor, type OverlayDismissReason, type OverlayInitialFocus, type OverlayOptions, type OverlayPlacement, type OverlayPlacementOptions, type OverlayPosition, type OverlayRect, type OverlaySide, type OverlaySize, type PointerPress, type RowVirtualizer, type RowVirtualizerOptions, type ToolbarOverflow, type ToolbarOverflowItem, type ToolbarOverflowOptions, attachContextMenuTrigger, attachInfiniteScroll, attachMenu, attachOverlay, attachToolbar, bodyCellFrom, bodyRowFrom, createGridFocus, createLiveAnnouncer, createRowVirtualizer, findBodyRow, groupRowFrom, measureColumnContent, measurePageSize, observeElementWidth, observeToolbarOverflow, placeOverlay, resolveColumnDropTarget, resolveGroupByDropTarget, startColumnResizeGesture, startDragReorder };