@gridkitjs/dom 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ColumnResizeSession, ColumnOrderState, GroupByState, GridFocus, NavigationModifiers, VisibleRange, ResolvedToolbarItem, PrintPage } from '@gridkitjs/core';
1
+ import { ColumnResizeSession, NavigationModifiers, WritingDirection, VisibleRange } from '@gridkitjs/core/renderer';
2
+ import { ColumnOrderState, GroupByState, ColumnPin, GridFocus, ResolvedToolbarItem, PrintPage } from '@gridkitjs/core';
2
3
 
3
4
  /** A live region to report changes through. */
4
5
  interface LiveAnnouncer {
@@ -97,7 +98,8 @@ interface AttachedChecklist {
97
98
  */
98
99
  readonly focusItem: (index: number) => void;
99
100
  /**
100
- * Removes every listener and observer. The items keep their `tabindex`.
101
+ * Removes every listener and observer. The list and its items keep their
102
+ * `tabindex`.
101
103
  * After it, `setCount` and `focusItem` do nothing: they neither scroll
102
104
  * nor focus, and a move still waiting for its item is dropped.
103
105
  */
@@ -120,7 +122,10 @@ interface AttachedChecklist {
120
122
  * One item at a time has `tabindex="0"` — the focused one, or the first
121
123
  * mounted while the focused one is scrolled away — and the rest `-1`, kept
122
124
  * so as items mount by an observer of the list's children rather than by
123
- * the renderer. A move to an item outside the window asks `scrollToIndex`
125
+ * the renderer. The list itself gets `tabindex="-1"`: a browser may make an
126
+ * element that scrolls a tab stop of its own, as Firefox does, which would
127
+ * put a second stop before the items' one, on an element the keys do not
128
+ * move from. A move to an item outside the window asks `scrollToIndex`
124
129
  * for it and focuses it once it mounts, unless focus has gone somewhere
125
130
  * else in the meantime.
126
131
  *
@@ -221,6 +226,10 @@ interface ColumnResizeGestureHandlers {
221
226
  * only the primary button of the primary pointer starts one, and not once
222
227
  * `handlers.signal` has aborted.
223
228
  *
229
+ * The edge is the column's inline end, and dragging it outward grows the
230
+ * column: rightward on a left-to-right page, leftward under `dir="rtl"`, as
231
+ * `writingDirection` reads `handle` when the drag starts.
232
+ *
224
233
  * Captures the pointer on `handle`, so the drag keeps reporting wherever the
225
234
  * pointer goes, and prevents the press's default, so it does not select the
226
235
  * header text it started on. No minimum distance, unlike a reorder drag: the
@@ -358,6 +367,12 @@ interface ColumnDropContext {
358
367
  readonly groupBy: GroupByState;
359
368
  /** Column ids whose header may be dragged into the group-by bar at all. */
360
369
  readonly groupByDraggableIds: ReadonlySet<string>;
370
+ /**
371
+ * The edge each column is pinned to. A column stays in its pin group, so
372
+ * a header in another group is no target. Every column counts as unpinned
373
+ * when left out.
374
+ */
375
+ readonly pinOf?: ((columnId: string) => ColumnPin) | undefined;
361
376
  }
362
377
  /**
363
378
  * Where a header or chip dropped at `(clientX, clientY)` would land within
@@ -374,10 +389,27 @@ declare function resolveGroupByDropTarget(clientX: number, clientY: number, move
374
389
  * of it the pointer is over, or else in the group-by bar — or `null` for
375
390
  * nowhere a drop would change anything.
376
391
  *
377
- * A column already grouped never targets the bar: reordering it there is its
378
- * chip's job, not its header's.
392
+ * A header pinned to another edge than the moved column's is never a target:
393
+ * a column is pinned or unpinned on purpose, not by a drag. A column already
394
+ * grouped never targets the bar: reordering it there is its chip's job, not
395
+ * its header's.
379
396
  */
380
- declare function resolveColumnDropTarget(clientX: number, clientY: number, movedId: string, { order, groupBy, groupByDraggableIds }: ColumnDropContext): ColumnDropTarget | null;
397
+ declare function resolveColumnDropTarget(clientX: number, clientY: number, movedId: string, { order, groupBy, groupByDraggableIds, pinOf }: ColumnDropContext): ColumnDropTarget | null;
398
+
399
+ /**
400
+ * Reports `element`'s height now and on every change after, until the
401
+ * returned function disconnects it: what a renderer insets its scroll area
402
+ * by for a header or footer that sticks to its top or bottom edge.
403
+ *
404
+ * The first report is synchronous, like `observeElementWidth`'s, so a
405
+ * renderer calling this before paint sizes its scroll area right from the
406
+ * first frame.
407
+ *
408
+ * Reads the border box from `getBoundingClientRect()`, unrounded: an inset
409
+ * a fraction of a pixel short of a header leaves a sliver of the rows
410
+ * scrolled under it showing.
411
+ */
412
+ declare function observeElementHeight(element: HTMLElement, onHeight: (height: number) => void): () => void;
381
413
 
382
414
  /**
383
415
  * Reports `element`'s inner width now and on every change after, until the
@@ -453,8 +485,12 @@ interface GridFocusController {
453
485
  * them, in which case the caller prevents its default: taken even when the
454
486
  * move lands nowhere, or an arrow at the last row would scroll the page
455
487
  * out from under the grid.
488
+ *
489
+ * `direction` is the way the grid's rows run, which the left and right
490
+ * arrows follow — `writingDirection` of the element the key was pressed
491
+ * in. Defaults to `"ltr"`.
456
492
  */
457
- readonly handleKey: (key: string, modifiers: NavigationModifiers, pageSize: number) => boolean;
493
+ readonly handleKey: (key: string, modifiers: NavigationModifiers, pageSize: number, direction?: WritingDirection) => boolean;
458
494
  /**
459
495
  * Connects the tab stop to the rendered rows, which the browser's focus
460
496
  * then follows it among. Returns the function that disconnects them.
@@ -484,12 +520,13 @@ interface GridFocusController {
484
520
  */
485
521
  declare function findBodyRow(bodyTable: HTMLTableElement | null, rowIndex: number): HTMLTableRowElement | null;
486
522
  /**
487
- * How many rows fit `bodyTable`'s scroll wrapper — its parent, the row area
488
- * alone, not the header, footer and pager around it — which is what a page
489
- * key moves. Reads the first rendered row's height, and falls back to ten
523
+ * How many rows fit the area the rows scroll in, which is what a page key
524
+ * moves: `scrollElement`, or else `bodyTable`'s parent, less the block
525
+ * `scroll-margin` of the rows (what a header or footer sticking to its edges
526
+ * covers). Reads the first rendered row's height, and falls back to ten
490
527
  * rows when nothing can be measured.
491
528
  */
492
- declare function measurePageSize(bodyTable: HTMLTableElement | null): number;
529
+ declare function measurePageSize(bodyTable: HTMLTableElement | null, scrollElement?: HTMLElement | null): number;
493
530
  /**
494
531
  * The grid's single tab stop and the keys that move it, which is what
495
532
  * `role="grid"` obliges: arrow keys travel cell to cell and Tab passes the
@@ -531,7 +568,8 @@ interface InfiniteScroll {
531
568
  /**
532
569
  * Takes the current options. Cheap when nothing changed, so a renderer may
533
570
  * call it after every render; a new sentinel or `rootMargin` restarts the
534
- * observer, and a load finishing or `hasMore` changing re-checks at once.
571
+ * observer, as does a load finishing, so the next load waits for where
572
+ * the new rows left the sentinel; `hasMore` changing re-checks at once.
535
573
  * While a load it asked for has not reported `isLoadingMore`, it measures
536
574
  * where the sentinel sits, to tell whether rows answered it.
537
575
  */
@@ -568,10 +606,11 @@ interface MenuOptions {
568
606
  */
569
607
  readonly onActivate: (id: string) => void;
570
608
  /**
571
- * An enabled submenu item asks for its submenu: Enter, Space or ArrowRight
572
- * on it want its first item focused (`"first"`), a click or the pointer
573
- * resting on it want focus left where it is (`"none"`). It may come for a
574
- * submenu already open — ArrowRight on one the pointer opened — when a
609
+ * An enabled submenu item asks for its submenu: Enter, Space or the arrow
610
+ * pointing to the inline end — ArrowRight, or ArrowLeft in a right-to-left
611
+ * menu — on it want its first item focused (`"first"`), a click or the
612
+ * pointer resting on it want focus left where it is (`"none"`). It may come
613
+ * for a submenu already open — that arrow on one the pointer opened — when a
575
614
  * `"first"` asks for focus to move into it (`focusItem(0)` on its menu).
576
615
  * Opening it closes any other submenu open from this menu.
577
616
  */
@@ -585,9 +624,10 @@ interface MenuOptions {
585
624
  */
586
625
  readonly onCollapseSubmenu?: (() => void) | undefined;
587
626
  /**
588
- * ArrowLeft was pressed in this menu, which is a submenu: close it, and
589
- * focus goes back to the item that opened it. Passed only for a submenu —
590
- * in a menu without it, ArrowLeft does nothing.
627
+ * The arrow pointing to the inline start — ArrowLeft, or ArrowRight in a
628
+ * right-to-left menu — was pressed in this menu, which is a submenu: close
629
+ * it, and focus goes back to the item that opened it. Passed only for a
630
+ * submenu — in a menu without it, that arrow does nothing.
591
631
  */
592
632
  readonly onCloseSubmenu?: (() => void) | undefined;
593
633
  /**
@@ -613,6 +653,11 @@ interface AttachedMenu {
613
653
  * decides; the caller is told through the callbacks and draws the outcome —
614
654
  * runs the item, opens or closes a submenu.
615
655
  *
656
+ * A submenu opens toward the panel's inline end, so the arrow pointing there
657
+ * opens it and the other closes it: ArrowRight opens one in a left-to-right
658
+ * panel, ArrowLeft under `dir="rtl"`, read from `writingDirection(panel)` on
659
+ * each key.
660
+ *
616
661
  * Items are the panel's descendants with a menu item role (`menuitem`,
617
662
  * `menuitemcheckbox`, `menuitemradio`) and a `data-gridkit-menu-item` id,
618
663
  * read afresh on every key so items drawn since attaching count. A submenu
@@ -661,6 +706,17 @@ interface OverlayPlacementOptions {
661
706
  * still kept on screen. Defaults to `0`.
662
707
  */
663
708
  readonly offset?: number | undefined;
709
+ /**
710
+ * The writing direction the placement is read in. `"rtl"` mirrors it, as
711
+ * a right-to-left page is mirrored: `left` and `right` swap, `start` and
712
+ * `end` beside `top` or `bottom` are the anchor's right and left edges, an
713
+ * `offset` along those sides runs leftward, and an overlay wider than the
714
+ * viewport keeps its right edge in view. The placement it ends up with is
715
+ * reported in the same mirrored terms, so `"bottom-start"` lines up with
716
+ * the anchor's inline start and `"right-start"` opens a submenu toward
717
+ * the inline end in either direction. Defaults to `"ltr"`.
718
+ */
719
+ readonly direction?: WritingDirection | undefined;
664
720
  }
665
721
  /** Where an overlay goes: its top-left corner, and the placement it ended up with. */
666
722
  interface OverlayPosition {
@@ -679,6 +735,10 @@ interface OverlayPosition {
679
735
  * A point — a context menu opened where the pointer is — is an anchor with
680
736
  * no width or height, which is what makes `start`/`end` mean "after" and
681
737
  * "before" it.
738
+ *
739
+ * In `"rtl"` the anchor is mirrored across the viewport, placed as in
740
+ * left-to-right, and the result mirrored back, so every rule above holds
741
+ * with left and right exchanged.
682
742
  */
683
743
  declare function placeOverlay(anchor: OverlayRect, panel: OverlaySize, viewport: OverlaySize, options?: OverlayPlacementOptions): OverlayPosition;
684
744
 
@@ -763,6 +823,13 @@ interface OverlayOptions extends OverlayPlacementOptions {
763
823
  * where the anchor was, once it has left the page. Focus moves
764
824
  * where `initialFocus` says.
765
825
  *
826
+ * The placement is read in the panel's own writing direction unless
827
+ * `direction` names one, so a panel laid out right to left — given
828
+ * `dir="rtl"`, or rendered into a right-to-left page — opens toward the
829
+ * inline end of what it is drawn in. A renderer portalling the panel out of
830
+ * a right-to-left grid in a left-to-right page sets `dir` on it from the
831
+ * grid, which mirrors its content and its placement together.
832
+ *
766
833
  * Nothing that happens on or in the anchor dismisses the overlay, so a button
767
834
  * that toggles it can close it with its own click rather than having the
768
835
  * overlay close and the click reopen it.
@@ -859,6 +926,10 @@ declare function createRowVirtualizer(scrollElement: HTMLElement, options: RowVi
859
926
  * control, wrapping round the ends, and Home and End to the first and last.
860
927
  * Returns the function that stops it.
861
928
  *
929
+ * The arrows point the way focus moves: under `dir="rtl"`, where the
930
+ * controls run from the right, ArrowLeft moves to the next one. The
931
+ * direction is read from `writingDirection(toolbar)` on each key.
932
+ *
862
933
  * The toolbar's entries are its descendants with a `data-gridkit-toolbar-item`,
863
934
  * and each entry's control is the entry itself when it can take focus, else
864
935
  * the first element in it that can; an entry with none — a separator, a
@@ -927,6 +998,15 @@ interface ToolbarOverflow {
927
998
  */
928
999
  declare function observeToolbarOverflow(toolbar: HTMLElement, options: ToolbarOverflowOptions): ToolbarOverflow;
929
1000
 
1001
+ /**
1002
+ * The way `element`'s lines run, from its computed `direction`: what it
1003
+ * inherits from a `dir` attribute on it or an ancestor, or from the CSS
1004
+ * `direction` property. Read afresh on every call, never kept, so a page
1005
+ * whose direction changes is followed from the next key press, gesture or
1006
+ * overlay on.
1007
+ */
1008
+ declare function writingDirection(element: Element): WritingDirection;
1009
+
930
1010
  /** What `printDocument` prints: a document's title, its body's markup and its stylesheet. */
931
1011
  interface PrintDocumentOptions {
932
1012
  /** The document's title, as text — what the browser puts in a page's header and names a saved PDF. */
@@ -968,4 +1048,4 @@ declare function printDocument(options: PrintDocumentOptions): Promise<void>;
968
1048
  */
969
1049
  declare function printStyles(page: PrintPage): string;
970
1050
 
971
- export { type AttachedChecklist, type AttachedMenu, type BodyCellTarget, type BodyRowTarget, type ChecklistOptions, type ClipboardContent, 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 PrintDocumentOptions, type RowVirtualizer, type RowVirtualizerOptions, type ToolbarOverflow, type ToolbarOverflowItem, type ToolbarOverflowOptions, attachChecklist, attachContextMenuTrigger, attachInfiniteScroll, attachMenu, attachOverlay, attachToolbar, bodyCellFrom, bodyRowFrom, createGridFocus, createLiveAnnouncer, createRowVirtualizer, downloadBlob, findBodyRow, groupRowFrom, isNativeCopy, measureColumnContent, measurePageSize, observeElementWidth, observeToolbarOverflow, placeOverlay, printDocument, printStyles, resolveColumnDropTarget, resolveGroupByDropTarget, startColumnResizeGesture, startDragReorder, writeClipboard };
1051
+ export { type AttachedChecklist, type AttachedMenu, type BodyCellTarget, type BodyRowTarget, type ChecklistOptions, type ClipboardContent, 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 PrintDocumentOptions, type RowVirtualizer, type RowVirtualizerOptions, type ToolbarOverflow, type ToolbarOverflowItem, type ToolbarOverflowOptions, attachChecklist, attachContextMenuTrigger, attachInfiniteScroll, attachMenu, attachOverlay, attachToolbar, bodyCellFrom, bodyRowFrom, createGridFocus, createLiveAnnouncer, createRowVirtualizer, downloadBlob, findBodyRow, groupRowFrom, isNativeCopy, measureColumnContent, measurePageSize, observeElementHeight, observeElementWidth, observeToolbarOverflow, placeOverlay, printDocument, printStyles, resolveColumnDropTarget, resolveGroupByDropTarget, startColumnResizeGesture, startDragReorder, writeClipboard, writingDirection };
package/dist/index.js CHANGED
@@ -197,6 +197,7 @@ function attachChecklist(list, options) {
197
197
  subtree: true,
198
198
  attributeFilter: [INDEX]
199
199
  });
200
+ list.tabIndex = -1;
200
201
  setTabStop();
201
202
  list.addEventListener("keydown", onKeyDown2);
202
203
  list.addEventListener("focusin", onFocusIn);
@@ -334,16 +335,24 @@ function attachContextMenuTrigger(root, options) {
334
335
  }
335
336
 
336
337
  // src/columnResize.ts
337
- import { applyColumnResize } from "@gridkitjs/core";
338
+ import {
339
+ applyColumnResize
340
+ } from "@gridkitjs/core/renderer";
338
341
 
339
342
  // src/pointerGesture.ts
340
343
  function mayStartGesture(press, signal) {
341
344
  return press.button === 0 && press.isPrimary && signal?.aborted !== true;
342
345
  }
346
+ var HELD = { kind: "held" };
343
347
  function startPointerGesture(element, pointerId, handlers, signal) {
344
348
  const { ownerDocument } = element;
345
349
  element.setPointerCapture(pointerId);
350
+ let capture = HELD;
346
351
  function stop() {
352
+ if (capture.kind === "lost") {
353
+ window.clearTimeout(capture.timer);
354
+ capture = HELD;
355
+ }
347
356
  ownerDocument.removeEventListener("pointermove", move, true);
348
357
  ownerDocument.removeEventListener("pointerup", end, true);
349
358
  ownerDocument.removeEventListener("pointercancel", cancel, true);
@@ -371,9 +380,18 @@ function startPointerGesture(element, pointerId, handlers, signal) {
371
380
  }
372
381
  }
373
382
  function recapture(event) {
374
- if (event.pointerId === pointerId && element.isConnected) {
375
- element.setPointerCapture(pointerId);
383
+ if (event.pointerId !== pointerId || capture.kind === "lost") {
384
+ return;
376
385
  }
386
+ capture = {
387
+ kind: "lost",
388
+ timer: window.setTimeout(() => {
389
+ capture = HELD;
390
+ if (element.isConnected) {
391
+ element.setPointerCapture(pointerId);
392
+ }
393
+ }, 0)
394
+ };
377
395
  }
378
396
  function abandon() {
379
397
  stop();
@@ -392,12 +410,18 @@ function startPointerGesture(element, pointerId, handlers, signal) {
392
410
  signal?.addEventListener("abort", abandon);
393
411
  }
394
412
 
413
+ // src/writingDirection.ts
414
+ function writingDirection(element) {
415
+ return getComputedStyle(element).direction === "rtl" ? "rtl" : "ltr";
416
+ }
417
+
395
418
  // src/columnResize.ts
396
419
  function startColumnResizeGesture(handle, press, session, handlers) {
397
420
  if (!mayStartGesture(press, handlers.signal)) {
398
421
  return false;
399
422
  }
400
423
  press.preventDefault();
424
+ const direction = writingDirection(handle);
401
425
  let width = session.startWidth;
402
426
  let resized = false;
403
427
  startPointerGesture(
@@ -405,7 +429,7 @@ function startColumnResizeGesture(handle, press, session, handlers) {
405
429
  press.pointerId,
406
430
  {
407
431
  onMove(event) {
408
- width = applyColumnResize(session, event.clientX);
432
+ width = applyColumnResize(session, event.clientX, direction);
409
433
  resized ||= width !== session.startWidth;
410
434
  handlers.onMove(width);
411
435
  },
@@ -583,16 +607,20 @@ function startDragReorder(id, grabElement, press, handlers) {
583
607
 
584
608
  // src/dropTargets.ts
585
609
  import {
586
- movesColumn,
610
+ moveColumnInPinGroup,
587
611
  movesGroupBy,
588
612
  resolveDropBefore
589
- } from "@gridkitjs/core";
613
+ } from "@gridkitjs/core/renderer";
614
+ function unpinned() {
615
+ return "none";
616
+ }
590
617
  function elementAt(x, y, selector) {
591
618
  return document.elementFromPoint(x, y)?.closest(selector) ?? null;
592
619
  }
593
620
  function sideOf(element, x) {
594
621
  const rect = element.getBoundingClientRect();
595
- return x < rect.left + rect.width / 2 ? "before" : "after";
622
+ const leftHalf = x < rect.left + rect.width / 2;
623
+ return leftHalf === (writingDirection(element) === "ltr") ? "before" : "after";
596
624
  }
597
625
  function resolveGroupByDropTarget(clientX, clientY, movedId, groupBy) {
598
626
  const overBar = elementAt(clientX, clientY, "[data-gridkit-group-by-bar]");
@@ -608,17 +636,32 @@ function resolveGroupByDropTarget(clientX, clientY, movedId, groupBy) {
608
636
  ) : null;
609
637
  return movesGroupBy(groupBy, movedId, beforeColumnId) ? { kind: "group-by", beforeColumnId } : null;
610
638
  }
611
- function resolveColumnDropTarget(clientX, clientY, movedId, { order, groupBy, groupByDraggableIds }) {
639
+ function resolveColumnDropTarget(clientX, clientY, movedId, { order, groupBy, groupByDraggableIds, pinOf = unpinned }) {
612
640
  const over = elementAt(clientX, clientY, "th[data-gridkit-column]");
613
641
  const overId = over?.getAttribute("data-gridkit-column");
614
642
  const beforeId = over && overId ? resolveDropBefore(order, overId, sideOf(over, clientX)) : void 0;
615
- if (beforeId !== void 0) {
616
- return movesColumn(order, movedId, beforeId) ? { kind: "column-order", beforeId } : null;
643
+ if (overId && beforeId !== void 0) {
644
+ if (pinOf(overId) !== pinOf(movedId)) {
645
+ return null;
646
+ }
647
+ return moveColumnInPinGroup(order, pinOf, movedId, beforeId) !== order ? { kind: "column-order", beforeId } : null;
617
648
  }
618
649
  const alreadyGrouped = groupBy.some((entry) => entry.columnId === movedId);
619
650
  return groupByDraggableIds.has(movedId) && !alreadyGrouped ? resolveGroupByDropTarget(clientX, clientY, movedId, groupBy) : null;
620
651
  }
621
652
 
653
+ // src/elementHeight.ts
654
+ function observeElementHeight(element, onHeight) {
655
+ onHeight(element.getBoundingClientRect().height);
656
+ const observer = new ResizeObserver(() => {
657
+ onHeight(element.getBoundingClientRect().height);
658
+ });
659
+ observer.observe(element);
660
+ return () => {
661
+ observer.disconnect();
662
+ };
663
+ }
664
+
622
665
  // src/elementWidth.ts
623
666
  function observeElementWidth(element, onWidth) {
624
667
  onWidth(element.clientWidth);
@@ -632,11 +675,11 @@ function observeElementWidth(element, onWidth) {
632
675
  }
633
676
 
634
677
  // src/gridFocus.ts
678
+ import { headerFocus } from "@gridkitjs/core";
635
679
  import {
636
680
  clampFocus,
637
- headerFocus,
638
681
  nextFocusForKey
639
- } from "@gridkitjs/core";
682
+ } from "@gridkitjs/core/renderer";
640
683
  var FALLBACK_PAGE = 10;
641
684
  function cellIn(row, columnIndex) {
642
685
  if (row === null) {
@@ -655,13 +698,19 @@ function findBodyRow(bodyTable, rowIndex) {
655
698
  `:scope > tr[data-gridkit-row-index="${String(rowIndex)}"]`
656
699
  ) ?? null;
657
700
  }
658
- function measurePageSize(bodyTable) {
701
+ function pixelsOf(value) {
702
+ const pixels2 = Number.parseFloat(value);
703
+ return Number.isNaN(pixels2) ? 0 : pixels2;
704
+ }
705
+ function measurePageSize(bodyTable, scrollElement) {
659
706
  const firstRow = bodyTable?.tBodies[0]?.rows[0];
660
- const viewport = bodyTable?.parentElement;
707
+ const viewport = scrollElement ?? bodyTable?.parentElement;
661
708
  if (firstRow === void 0 || viewport === null || viewport === void 0 || firstRow.offsetHeight === 0) {
662
709
  return FALLBACK_PAGE;
663
710
  }
664
- return Math.max(1, Math.floor(viewport.clientHeight / firstRow.offsetHeight));
711
+ const style = getComputedStyle(firstRow);
712
+ const height = viewport.clientHeight - pixelsOf(style.scrollMarginTop) - pixelsOf(style.scrollMarginBottom);
713
+ return Math.max(1, Math.floor(height / firstRow.offsetHeight));
665
714
  }
666
715
  function createGridFocus(initialOptions) {
667
716
  let options = initialOptions;
@@ -728,7 +777,7 @@ function createGridFocus(initialOptions) {
728
777
  options = next;
729
778
  },
730
779
  focusCell,
731
- handleKey(key, modifiers, pageSize) {
780
+ handleKey(key, modifiers, pageSize, direction) {
732
781
  const next = nextFocusForKey(
733
782
  key,
734
783
  modifiers,
@@ -736,7 +785,8 @@ function createGridFocus(initialOptions) {
736
785
  options.rowCount,
737
786
  options.columnCount,
738
787
  pageSize,
739
- options.isSkippableRow
788
+ options.isSkippableRow,
789
+ direction
740
790
  );
741
791
  if (next === null) {
742
792
  return false;
@@ -764,7 +814,11 @@ function createGridFocus(initialOptions) {
764
814
  );
765
815
  if (cell !== null) {
766
816
  pendingMove = null;
817
+ const moving = cell.ownerDocument.activeElement !== cell;
767
818
  cell.focus();
819
+ if (moving) {
820
+ cell.scrollIntoView({ block: "nearest", inline: "nearest" });
821
+ }
768
822
  return;
769
823
  }
770
824
  const range = options.virtualRange;
@@ -855,10 +909,11 @@ function attachInfiniteScroll(root, options) {
855
909
  return;
856
910
  }
857
911
  const hasMoreChanged = next.hasMore !== latest.hasMore;
912
+ const loadFinished = state.kind === "loading" && !(next.isLoadingMore ?? false);
858
913
  latest = next;
859
914
  state = afterUpdate(state, next.isLoadingMore ?? false, hasMoreChanged);
860
915
  observe();
861
- if (requestAnswered()) {
916
+ if (loadFinished || requestAnswered()) {
862
917
  state = IDLE;
863
918
  disconnect();
864
919
  observe();
@@ -873,7 +928,11 @@ function attachInfiniteScroll(root, options) {
873
928
  }
874
929
 
875
930
  // src/menu/attachMenu.ts
876
- import { nextMenuIndex, typeaheadIndex } from "@gridkitjs/core";
931
+ import {
932
+ inlineStep,
933
+ nextMenuIndex,
934
+ typeaheadIndex
935
+ } from "@gridkitjs/core/renderer";
877
936
  var ITEM2 = [
878
937
  '[role="menuitem"][data-gridkit-menu-item]',
879
938
  '[role="menuitemcheckbox"][data-gridkit-menu-item]',
@@ -993,6 +1052,7 @@ function attachMenu(panel, options) {
993
1052
  const item = itemOf(event.target);
994
1053
  const from = item === null ? -1 : all.indexOf(item);
995
1054
  const move = MOVES[event.key];
1055
+ const step = inlineStep(event.key, writingDirection(panel));
996
1056
  if (move !== void 0) {
997
1057
  const next = all[nextMenuIndex(
998
1058
  all.map(() => AS_ENTRY),
@@ -1006,11 +1066,11 @@ function attachMenu(panel, options) {
1006
1066
  if (item !== null) {
1007
1067
  choose(item, "first");
1008
1068
  }
1009
- } else if (event.key === "ArrowRight") {
1069
+ } else if (step === 1) {
1010
1070
  if (item !== null && opensSubmenu(item)) {
1011
1071
  openSubmenu(item, "first");
1012
1072
  }
1013
- } else if (event.key === "ArrowLeft") {
1073
+ } else if (step === -1) {
1014
1074
  options.onCloseSubmenu?.();
1015
1075
  } else if (event.key === "Tab") {
1016
1076
  options.onClose("tab");
@@ -1167,6 +1227,21 @@ function clampIntoView(value, limit) {
1167
1227
  return Math.max(0, Math.min(value, limit));
1168
1228
  }
1169
1229
  function placeOverlay(anchor, panel, viewport, options = {}) {
1230
+ if (options.direction !== "rtl") {
1231
+ return placeLeftToRight(anchor, panel, viewport, options);
1232
+ }
1233
+ const mirrored = placeLeftToRight(
1234
+ { ...anchor, left: viewport.width - anchor.left - anchor.width },
1235
+ panel,
1236
+ viewport,
1237
+ options
1238
+ );
1239
+ return {
1240
+ ...mirrored,
1241
+ left: viewport.width - mirrored.left - panel.width
1242
+ };
1243
+ }
1244
+ function placeLeftToRight(anchor, panel, viewport, options) {
1170
1245
  const [preferredSide, preferredAlign] = (options.placement ?? "bottom-start").split("-");
1171
1246
  const gap = options.gap ?? 0;
1172
1247
  const offset = options.offset ?? 0;
@@ -1316,7 +1391,7 @@ function attachOverlay(anchor, panel, options) {
1316
1391
  width: document.documentElement.clientWidth,
1317
1392
  height: document.documentElement.clientHeight
1318
1393
  },
1319
- options
1394
+ { ...options, direction: options.direction ?? writingDirection(panel) }
1320
1395
  );
1321
1396
  panel.style.top = `${String(position.top)}px`;
1322
1397
  panel.style.left = `${String(position.left)}px`;
@@ -1373,7 +1448,7 @@ function attachOverlay(anchor, panel, options) {
1373
1448
  }
1374
1449
 
1375
1450
  // src/rowVirtualizer.ts
1376
- import { visibleRange } from "@gridkitjs/core";
1451
+ import { visibleRange } from "@gridkitjs/core/renderer";
1377
1452
  var READY = { kind: "ready" };
1378
1453
  function sameRange(a, b) {
1379
1454
  return a.startIndex === b.startIndex && a.endIndex === b.endIndex && a.offsetBefore === b.offsetBefore && a.offsetAfter === b.offsetAfter;
@@ -1515,7 +1590,10 @@ function createRowVirtualizer(scrollElement, options) {
1515
1590
  }
1516
1591
 
1517
1592
  // src/toolbar/attachToolbar.ts
1518
- import { nextMenuIndex as nextMenuIndex2 } from "@gridkitjs/core";
1593
+ import {
1594
+ inlineStep as inlineStep2,
1595
+ nextMenuIndex as nextMenuIndex2
1596
+ } from "@gridkitjs/core/renderer";
1519
1597
  var ENTRY = "[data-gridkit-toolbar-item]";
1520
1598
  var FOCUSABLE2 = [
1521
1599
  "button:not(:disabled)",
@@ -1525,12 +1603,17 @@ var FOCUSABLE2 = [
1525
1603
  "a[href]",
1526
1604
  "[tabindex]"
1527
1605
  ].join(", ");
1528
- var MOVES2 = {
1529
- ArrowRight: "next",
1530
- ArrowLeft: "previous",
1606
+ var JUMPS = {
1531
1607
  Home: "first",
1532
1608
  End: "last"
1533
1609
  };
1610
+ function moveFor(key, toolbar) {
1611
+ const step = inlineStep2(key, writingDirection(toolbar));
1612
+ if (step === null) {
1613
+ return JUMPS[key];
1614
+ }
1615
+ return step === 1 ? "next" : "previous";
1616
+ }
1534
1617
  var AS_ENTRY2 = { type: "item" };
1535
1618
  var CARETLESS_INPUTS = /* @__PURE__ */ new Set([
1536
1619
  "button",
@@ -1583,7 +1666,7 @@ function attachToolbar(toolbar) {
1583
1666
  }
1584
1667
  }
1585
1668
  function onKeyDown2(event) {
1586
- const move = MOVES2[event.key];
1669
+ const move = moveFor(event.key, toolbar);
1587
1670
  if (move === void 0 || event.isComposing || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || belongsToField(event.target, move)) {
1588
1671
  return;
1589
1672
  }
@@ -1631,10 +1714,7 @@ function attachToolbar(toolbar) {
1631
1714
  }
1632
1715
 
1633
1716
  // src/toolbar/observeToolbarOverflow.ts
1634
- import {
1635
- fitToolbarItems,
1636
- isPinnedToolbarItem
1637
- } from "@gridkitjs/core";
1717
+ import { fitToolbarItems, isPinnedToolbarItem } from "@gridkitjs/core/renderer";
1638
1718
  var ENTRY_ATTRIBUTE = "data-gridkit-toolbar-item";
1639
1719
  var MORE_ATTRIBUTE = "data-gridkit-toolbar-more";
1640
1720
  function pixels(value) {
@@ -1834,11 +1914,14 @@ function indentRule(selector, level) {
1834
1914
  }
1835
1915
  function groupIndentRules() {
1836
1916
  const rules = [
1837
- indentRule('.export-group:not([data-level="0"])', DEEPEST_INDENTED_LEVEL)
1917
+ indentRule(
1918
+ '.gridkit-export-group:not([data-level="0"])',
1919
+ DEEPEST_INDENTED_LEVEL
1920
+ )
1838
1921
  ];
1839
1922
  for (let level = 1; level < DEEPEST_INDENTED_LEVEL; level++) {
1840
1923
  rules.push(
1841
- indentRule(`.export-group[data-level="${String(level)}"]`, level)
1924
+ indentRule(`.gridkit-export-group[data-level="${String(level)}"]`, level)
1842
1925
  );
1843
1926
  }
1844
1927
  return rules.join("\n");
@@ -1846,8 +1929,8 @@ function groupIndentRules() {
1846
1929
  var BASE_RULES = `html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
1847
1930
  body { margin: 0; background: #fff; color: #000; font: 10pt/1.35 system-ui, sans-serif; }
1848
1931
  .gridkit-print-header { margin-bottom: 8pt; }
1849
- .print-title { margin: 0; font-size: 14pt; }
1850
- .print-subtitle, .print-timestamp { margin: 2pt 0 0; color: #444; }
1932
+ .gridkit-print-title { margin: 0; font-size: 14pt; }
1933
+ .gridkit-print-subtitle, .gridkit-print-timestamp { margin: 2pt 0 0; color: #444; }
1851
1934
  .gridkit-print-footer { margin-top: 8pt; color: #444; }
1852
1935
  .gridkit-export-table { width: 100%; border-collapse: collapse; }
1853
1936
  .gridkit-export-table thead { display: table-header-group; }
@@ -1855,8 +1938,8 @@ body { margin: 0; background: #fff; color: #000; font: 10pt/1.35 system-ui, sans
1855
1938
  .gridkit-export-table tr { break-inside: avoid; }
1856
1939
  .gridkit-export-table th, .gridkit-export-table td { border: 1px solid #bbb; padding: 3pt ${CELL_PADDING_X}; text-align: left; vertical-align: top; }
1857
1940
  .gridkit-export-table th { background: #eee; font-weight: 600; }
1858
- .export-group > td { background: #f5f5f5; font-weight: 600; }
1859
- .export-group-summary > td, .gridkit-export-table tfoot td { font-weight: 600; }
1941
+ .gridkit-export-group > td { background: #f5f5f5; font-weight: 600; }
1942
+ .gridkit-export-group-summary > td, .gridkit-export-table tfoot td { font-weight: 600; }
1860
1943
  .gridkit-export-table tfoot td { border-top: 2px solid #888; }`;
1861
1944
  var FIT_TO_WIDTH_RULES = `.gridkit-export-table { table-layout: fixed; font-size: 8pt; }
1862
1945
  .gridkit-export-table th, .gridkit-export-table td { overflow-wrap: anywhere; }`;
@@ -1887,6 +1970,7 @@ export {
1887
1970
  isNativeCopy,
1888
1971
  measureColumnContent,
1889
1972
  measurePageSize,
1973
+ observeElementHeight,
1890
1974
  observeElementWidth,
1891
1975
  observeToolbarOverflow,
1892
1976
  placeOverlay,
@@ -1896,6 +1980,7 @@ export {
1896
1980
  resolveGroupByDropTarget,
1897
1981
  startColumnResizeGesture,
1898
1982
  startDragReorder,
1899
- writeClipboard
1983
+ writeClipboard,
1984
+ writingDirection
1900
1985
  };
1901
1986
  //# sourceMappingURL=index.js.map