@gridkitjs/forms-dom 0.0.0-dev-20261206092422 → 0.0.0-dev-20261206115313

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,14 @@
1
+ // src/abortSignals.ts
2
+ var abortSignals = () => {
3
+ const controller = new AbortController();
4
+ return {
5
+ signal: controller.signal,
6
+ abort: () => {
7
+ controller.abort();
8
+ }
9
+ };
10
+ };
11
+
1
12
  // src/announcer.ts
2
13
  var NO_BREAK_SPACE = String.fromCodePoint(160);
3
14
  function createLiveAnnouncer(container = document.body, options = {}) {
@@ -376,6 +387,753 @@ function attachChecklist(list, options) {
376
387
  };
377
388
  }
378
389
 
390
+ // src/writingDirection.ts
391
+ function writingDirection(element) {
392
+ return getComputedStyle(element).direction === "rtl" ? "rtl" : "ltr";
393
+ }
394
+
395
+ // src/listbox/attachCombobox.ts
396
+ var OPEN_KEYS = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp", "F4"]);
397
+ var SELECT_ONLY_OPEN_KEYS = /* @__PURE__ */ new Set(["Enter", " ", "Home", "End"]);
398
+ function hasFocus(control) {
399
+ const root = control.getRootNode();
400
+ return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === control;
401
+ }
402
+ function isPrintable(event) {
403
+ return !event.ctrlKey && !event.metaKey && !event.altKey && Array.from(event.key).length === 1;
404
+ }
405
+ function caretAtStart(control) {
406
+ return (control instanceof HTMLInputElement || control instanceof HTMLTextAreaElement) && control.selectionStart === 0 && control.selectionEnd === 0;
407
+ }
408
+ function textOf(control) {
409
+ return control instanceof HTMLInputElement || control instanceof HTMLTextAreaElement ? control.value : "";
410
+ }
411
+ function attachCombobox(control, controller, initialOptions) {
412
+ let options = initialOptions;
413
+ let attached = true;
414
+ let pendingKeys = [];
415
+ let unsubscribe = null;
416
+ let panelEvents = null;
417
+ const events = new AbortController();
418
+ const { signal } = events;
419
+ const isOpen = () => options.listbox !== null;
420
+ function writeAria() {
421
+ if (!attached) {
422
+ return;
423
+ }
424
+ const { listbox } = options;
425
+ control.setAttribute("aria-expanded", String(listbox !== null));
426
+ const listId = listbox?.element.id ?? "";
427
+ if (listId === "") {
428
+ control.removeAttribute("aria-controls");
429
+ } else {
430
+ control.setAttribute("aria-controls", listId);
431
+ }
432
+ const activeId = listbox?.activeId() ?? null;
433
+ if (activeId === null) {
434
+ control.removeAttribute("aria-activedescendant");
435
+ } else {
436
+ control.setAttribute("aria-activedescendant", activeId);
437
+ }
438
+ }
439
+ function connect(next, previous) {
440
+ if (next.listbox !== previous?.listbox) {
441
+ unsubscribe?.();
442
+ unsubscribe = next.listbox?.subscribe(writeAria) ?? null;
443
+ }
444
+ if (next.panel !== previous?.panel) {
445
+ panelEvents?.abort();
446
+ panelEvents = null;
447
+ if (next.panel !== null) {
448
+ panelEvents = new AbortController();
449
+ next.panel.addEventListener(
450
+ "mousedown",
451
+ (event) => {
452
+ event.preventDefault();
453
+ },
454
+ { signal: panelEvents.signal }
455
+ );
456
+ }
457
+ }
458
+ }
459
+ function requestOpen(reason, event) {
460
+ if (!options.readOnly) {
461
+ options.onOpenRequest(reason, event);
462
+ }
463
+ }
464
+ function forwardPendingKeys() {
465
+ const { listbox } = options;
466
+ if (listbox === null) {
467
+ return;
468
+ }
469
+ const keys = pendingKeys;
470
+ pendingKeys = [];
471
+ for (const key of keys) {
472
+ listbox.handleKey(key);
473
+ }
474
+ }
475
+ function onChipKey(event) {
476
+ const { onChipKey: handler } = options;
477
+ if (handler === void 0 || event.ctrlKey || event.metaKey || event.altKey) {
478
+ return false;
479
+ }
480
+ const previousKey = writingDirection(control) === "rtl" ? "ArrowRight" : "ArrowLeft";
481
+ if (event.key === previousKey && !event.shiftKey && (!options.editable || caretAtStart(control))) {
482
+ handler("previous", event);
483
+ return true;
484
+ }
485
+ if (event.key === "Backspace" && textOf(control) === "") {
486
+ handler("remove-last", event);
487
+ return true;
488
+ }
489
+ return false;
490
+ }
491
+ function onClosedKey(event) {
492
+ const { editable } = options;
493
+ if (event.key === "Escape") {
494
+ return !editable && controller.revert(event);
495
+ }
496
+ if (event.ctrlKey || event.metaKey) {
497
+ return false;
498
+ }
499
+ if (OPEN_KEYS.has(event.key) && (!event.altKey || event.key === "ArrowDown") || !editable && !event.altKey && SELECT_ONLY_OPEN_KEYS.has(event.key)) {
500
+ requestOpen("keyboard", event);
501
+ return true;
502
+ }
503
+ if (!editable && isPrintable(event) && !options.readOnly) {
504
+ pendingKeys.push(event);
505
+ requestOpen("typing", event);
506
+ forwardPendingKeys();
507
+ return true;
508
+ }
509
+ return onChipKey(event);
510
+ }
511
+ function textBoxKeeps(event) {
512
+ return event.key === "Home" || event.key === "End" || event.key === " " || isPrintable(event) || (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "a" || event.shiftKey && (event.key === "ArrowDown" || event.key === "ArrowUp");
513
+ }
514
+ function onOpenKey(event, listbox) {
515
+ switch (event.key) {
516
+ case "Escape":
517
+ options.onCloseRequest("escape", event);
518
+ return true;
519
+ case "F4":
520
+ options.onCloseRequest("button", event);
521
+ return true;
522
+ }
523
+ if (event.altKey) {
524
+ if (event.key === "ArrowUp") {
525
+ options.onCloseRequest("button", event);
526
+ return true;
527
+ }
528
+ return false;
529
+ }
530
+ if (options.editable && textBoxKeeps(event)) {
531
+ if (event.key === "Home" || event.key === "End") {
532
+ listbox.activate(null, "keyboard");
533
+ }
534
+ return false;
535
+ }
536
+ if (listbox.handleKey(event)) {
537
+ return true;
538
+ }
539
+ return onChipKey(event);
540
+ }
541
+ function onTab(event) {
542
+ if (event.ctrlKey || event.altKey || event.metaKey) {
543
+ return;
544
+ }
545
+ const { listbox } = options;
546
+ if (listbox !== null && options.tabChooses && !options.multiple && !event.shiftKey) {
547
+ listbox.chooseActive(event);
548
+ }
549
+ if (isOpen()) {
550
+ options.onCloseRequest("blur", event);
551
+ }
552
+ if (!options.editable && controller.commit("tab", event).kind === "refused") {
553
+ event.preventDefault();
554
+ }
555
+ }
556
+ function onKeyDown(event) {
557
+ if (event.defaultPrevented || event.isComposing) {
558
+ return;
559
+ }
560
+ if (event.key === "Tab") {
561
+ onTab(event);
562
+ return;
563
+ }
564
+ const { listbox } = options;
565
+ const taken = listbox === null ? onClosedKey(event) : onOpenKey(event, listbox);
566
+ if (taken) {
567
+ event.preventDefault();
568
+ }
569
+ }
570
+ function onInput(event) {
571
+ if (options.editable && !isOpen()) {
572
+ requestOpen("typing", event);
573
+ }
574
+ }
575
+ function onClick(event) {
576
+ if (!isOpen()) {
577
+ requestOpen("button", event);
578
+ } else if (!options.editable) {
579
+ options.onCloseRequest("button", event);
580
+ }
581
+ }
582
+ function onFocus(event) {
583
+ if (!options.editable) {
584
+ controller.focus(event);
585
+ }
586
+ }
587
+ function onBlur(event) {
588
+ pendingKeys = [];
589
+ if (isOpen()) {
590
+ options.onCloseRequest("blur", event);
591
+ }
592
+ if (!options.editable) {
593
+ controller.blur(event);
594
+ }
595
+ }
596
+ control.addEventListener("keydown", onKeyDown, { signal, capture: true });
597
+ control.addEventListener("input", onInput, { signal });
598
+ control.addEventListener("click", onClick, { signal });
599
+ control.addEventListener("focus", onFocus, { signal });
600
+ control.addEventListener("blur", onBlur, { signal });
601
+ connect(options, null);
602
+ writeAria();
603
+ if (!options.editable && hasFocus(control)) {
604
+ controller.focus(null);
605
+ }
606
+ return {
607
+ setOptions(next) {
608
+ if (!attached) {
609
+ return;
610
+ }
611
+ const previous = options;
612
+ options = next;
613
+ connect(next, previous);
614
+ if (previous.listbox !== null && next.listbox === null) {
615
+ pendingKeys = [];
616
+ }
617
+ writeAria();
618
+ forwardPendingKeys();
619
+ },
620
+ detach() {
621
+ if (!attached) {
622
+ return;
623
+ }
624
+ attached = false;
625
+ events.abort();
626
+ panelEvents?.abort();
627
+ unsubscribe?.();
628
+ pendingKeys = [];
629
+ control.removeAttribute("aria-controls");
630
+ control.removeAttribute("aria-activedescendant");
631
+ }
632
+ };
633
+ }
634
+
635
+ // src/listbox/attachListbox.ts
636
+ import {
637
+ isLandingRow,
638
+ moveActive,
639
+ typeaheadRow
640
+ } from "@gridkitjs/forms-core";
641
+ var ROW_ATTRIBUTE = "data-gridkit-forms-row";
642
+ var ROW = `[${ROW_ATTRIBUTE}]`;
643
+ var TYPEAHEAD_RESET = 500;
644
+ var NEAR_END = 5;
645
+ var INACTIVE = { kind: "inactive" };
646
+ function rowIndex(row) {
647
+ return Number(row.getAttribute(ROW_ATTRIBUTE));
648
+ }
649
+ function nearestLanding(rows, from, disabledOptions) {
650
+ for (let index = Math.max(from, 0); index < rows.length; index++) {
651
+ const row = rows[index];
652
+ if (row !== void 0 && isLandingRow(row, disabledOptions)) {
653
+ return index;
654
+ }
655
+ }
656
+ for (let index = Math.min(from, rows.length) - 1; index >= 0; index--) {
657
+ const row = rows[index];
658
+ if (row !== void 0 && isLandingRow(row, disabledOptions)) {
659
+ return index;
660
+ }
661
+ }
662
+ return null;
663
+ }
664
+ function isPrintable2(event) {
665
+ return !event.ctrlKey && !event.metaKey && !event.altKey && Array.from(event.key).length === 1;
666
+ }
667
+ function attachListbox(list, initialOptions) {
668
+ let options = initialOptions;
669
+ let rows = [];
670
+ let state = INACTIVE;
671
+ let anchorKey = null;
672
+ let typed = "";
673
+ let typeaheadTimer;
674
+ let nearEndFor = -1;
675
+ let pointerPressed = false;
676
+ const listeners = /* @__PURE__ */ new Set();
677
+ const events = new AbortController();
678
+ const { signal } = events;
679
+ const disabledOptions = () => options.disabledOptions ?? "skip";
680
+ const roving = () => options.focus === "roving";
681
+ function activeIndex() {
682
+ return state.kind === "active" || state.kind === "awaiting" ? state.index : null;
683
+ }
684
+ function rowElement(index) {
685
+ return list.querySelector(
686
+ `[${ROW_ATTRIBUTE}="${String(index)}"]`
687
+ );
688
+ }
689
+ function rowOf(target) {
690
+ const row = target instanceof Element ? target.closest(ROW) : null;
691
+ return row !== null && list.contains(row) ? row : null;
692
+ }
693
+ function notify() {
694
+ for (const listener of [...listeners]) {
695
+ listener();
696
+ }
697
+ }
698
+ function setTabStop() {
699
+ if (!roving()) {
700
+ return;
701
+ }
702
+ const mounted = Array.from(list.querySelectorAll(ROW));
703
+ const active = activeIndex();
704
+ const stop = mounted.find((row) => rowIndex(row) === active) ?? mounted.find((row) => {
705
+ const described = rows[rowIndex(row)];
706
+ return described !== void 0 && isLandingRow(described, disabledOptions());
707
+ });
708
+ for (const row of mounted) {
709
+ row.tabIndex = row === stop ? 0 : -1;
710
+ }
711
+ }
712
+ function checkNearEnd() {
713
+ if (options.onNearEnd === void 0 || nearEndFor === rows.length) {
714
+ return;
715
+ }
716
+ const threshold = rows.length - NEAR_END;
717
+ const active = activeIndex();
718
+ const last = Array.from(list.querySelectorAll(ROW)).at(-1);
719
+ if (active !== null && active >= threshold || last !== void 0 && rowIndex(last) >= threshold) {
720
+ nearEndFor = rows.length;
721
+ options.onNearEnd();
722
+ }
723
+ }
724
+ function focusActiveRow() {
725
+ if (!roving() || state.kind !== "active" && state.kind !== "awaiting") {
726
+ return;
727
+ }
728
+ const row = rowElement(state.index);
729
+ if (row === null) {
730
+ state = { kind: "awaiting", index: state.index };
731
+ } else {
732
+ state = { kind: "active", index: state.index };
733
+ row.focus({ preventScroll: true });
734
+ }
735
+ }
736
+ function setActive(index, by, align) {
737
+ if (state.kind === "detached") {
738
+ return;
739
+ }
740
+ const previous = activeIndex();
741
+ if (index === null || rows[index] === void 0) {
742
+ state = INACTIVE;
743
+ } else {
744
+ state = { kind: "active", index };
745
+ if (align !== null) {
746
+ options.scrollToIndex(index, align);
747
+ }
748
+ focusActiveRow();
749
+ }
750
+ const next = activeIndex();
751
+ if (next !== previous) {
752
+ options.onActiveChange(next, by);
753
+ }
754
+ setTabStop();
755
+ notify();
756
+ checkNearEnd();
757
+ }
758
+ function anchorFor(fallback) {
759
+ const index = anchorKey === null ? -1 : rows.findIndex((row) => row.key === anchorKey);
760
+ if (index !== -1) {
761
+ return index;
762
+ }
763
+ anchorKey = rows[fallback]?.key ?? null;
764
+ return fallback;
765
+ }
766
+ function choose(index, choice, event) {
767
+ const row = rows[index];
768
+ if (row === void 0 || row.kind === "header") {
769
+ return false;
770
+ }
771
+ if (choice.kind !== "all" && row.disabled) {
772
+ return false;
773
+ }
774
+ if (choice.kind === "one" || choice.kind === "toggle") {
775
+ anchorKey = row.key;
776
+ }
777
+ options.onChoose(index, choice, event);
778
+ return true;
779
+ }
780
+ function chooseAlone(index, event) {
781
+ choose(index, { kind: options.multiple ? "toggle" : "one" }, event);
782
+ }
783
+ function pageSize() {
784
+ const top = list.getBoundingClientRect().top + list.clientTop;
785
+ const bottom = top + list.clientHeight;
786
+ const whole = Array.from(list.querySelectorAll(ROW)).filter((row) => {
787
+ const box = row.getBoundingClientRect();
788
+ return box.top >= top && box.bottom <= bottom;
789
+ }).length;
790
+ return Math.max(1, whole);
791
+ }
792
+ function move(step, event) {
793
+ const from = activeIndex();
794
+ const relative = step.kind !== "first" && step.kind !== "last";
795
+ if (relative && from !== null && !roving() && rowElement(from) === null) {
796
+ options.scrollToIndex(from, "nearest");
797
+ return true;
798
+ }
799
+ const to = moveActive(rows, from, step, disabledOptions());
800
+ if (to === null) {
801
+ return true;
802
+ }
803
+ const ranging = event.shiftKey && options.multiple;
804
+ const anchor = ranging ? anchorFor(from ?? to) : null;
805
+ setActive(to, "keyboard", "nearest");
806
+ if (to === from) {
807
+ return true;
808
+ }
809
+ if (anchor !== null) {
810
+ choose(to, { kind: "range", anchor }, event);
811
+ } else if (options.selectionFollowsFocus === true && !options.multiple) {
812
+ choose(to, { kind: "one" }, event);
813
+ }
814
+ return true;
815
+ }
816
+ function typeahead(event) {
817
+ if (!options.typeahead || !isPrintable2(event)) {
818
+ return false;
819
+ }
820
+ if (event.key === " " && typed === "") {
821
+ return false;
822
+ }
823
+ typed += event.key;
824
+ clearTimeout(typeaheadTimer);
825
+ typeaheadTimer = setTimeout(() => {
826
+ typed = "";
827
+ }, TYPEAHEAD_RESET);
828
+ const from = activeIndex();
829
+ const to = typeaheadRow(
830
+ rows,
831
+ from,
832
+ typed,
833
+ options.locale,
834
+ disabledOptions()
835
+ );
836
+ if (to !== null && to !== from) {
837
+ setActive(to, "keyboard", "nearest");
838
+ if (options.selectionFollowsFocus === true && !options.multiple) {
839
+ choose(to, { kind: "one" }, event);
840
+ }
841
+ }
842
+ return true;
843
+ }
844
+ function space(event) {
845
+ const active = activeIndex();
846
+ if (active === null) {
847
+ return false;
848
+ }
849
+ if (event.repeat) {
850
+ return true;
851
+ }
852
+ if (!roving()) {
853
+ chooseAlone(active, event);
854
+ } else if (options.multiple && event.shiftKey) {
855
+ choose(active, { kind: "range", anchor: anchorFor(active) }, event);
856
+ } else {
857
+ chooseAlone(active, event);
858
+ }
859
+ return true;
860
+ }
861
+ function onKey(event) {
862
+ if (state.kind === "detached" || event.isComposing || event.altKey) {
863
+ return false;
864
+ }
865
+ const modified = event.ctrlKey || event.metaKey;
866
+ if (typeahead(event)) {
867
+ return true;
868
+ }
869
+ switch (event.key) {
870
+ case "ArrowDown":
871
+ return !modified && move({ kind: "next" }, event);
872
+ case "ArrowUp":
873
+ return !modified && move({ kind: "previous" }, event);
874
+ case "PageDown":
875
+ return !modified && move({ kind: "pageDown", rows: pageSize() }, event);
876
+ case "PageUp":
877
+ return !modified && move({ kind: "pageUp", rows: pageSize() }, event);
878
+ // Ctrl+Shift+Home and End range as Shift+Home and End do.
879
+ case "Home":
880
+ return (!modified || event.shiftKey) && move({ kind: "first" }, event);
881
+ case "End":
882
+ return (!modified || event.shiftKey) && move({ kind: "last" }, event);
883
+ case "Enter": {
884
+ const active = activeIndex();
885
+ if (roving() || active === null) {
886
+ return false;
887
+ }
888
+ chooseAlone(active, event);
889
+ return true;
890
+ }
891
+ case " ":
892
+ return !modified && space(event);
893
+ case "a":
894
+ case "A": {
895
+ if (!modified || !options.multiple) {
896
+ return false;
897
+ }
898
+ const target = activeIndex() ?? nearestLanding(rows, 0, disabledOptions());
899
+ return target !== null && choose(target, { kind: "all" }, event);
900
+ }
901
+ default:
902
+ return false;
903
+ }
904
+ }
905
+ function onKeyDown(event) {
906
+ if (roving() && onKey(event)) {
907
+ event.preventDefault();
908
+ }
909
+ }
910
+ function onFocusIn(event) {
911
+ const row = rowOf(event.target);
912
+ if (!roving() || row === null || state.kind === "detached") {
913
+ return;
914
+ }
915
+ const index = rowIndex(row);
916
+ const previous = activeIndex();
917
+ state = { kind: "active", index };
918
+ if (index !== previous) {
919
+ options.onActiveChange(index, pointerPressed ? "pointer" : "keyboard");
920
+ }
921
+ setTabStop();
922
+ notify();
923
+ checkNearEnd();
924
+ }
925
+ function onPointerMove(event) {
926
+ if (roving() || event.pointerType !== "mouse") {
927
+ return;
928
+ }
929
+ const row = rowOf(event.target);
930
+ if (row === null) {
931
+ return;
932
+ }
933
+ const index = rowIndex(row);
934
+ const described = rows[index];
935
+ if (index !== activeIndex() && described !== void 0 && isLandingRow(described, disabledOptions())) {
936
+ setActive(index, "pointer", null);
937
+ }
938
+ }
939
+ function onClick(event) {
940
+ const row = rowOf(event.target);
941
+ const index = row === null ? -1 : rowIndex(row);
942
+ const described = rows[index];
943
+ if (row === null || state.kind === "detached" || described === void 0 || !isLandingRow(described, disabledOptions())) {
944
+ return;
945
+ }
946
+ setActive(index, "pointer", null);
947
+ if (roving() && options.multiple && event.shiftKey) {
948
+ choose(index, { kind: "range", anchor: anchorFor(index) }, event);
949
+ } else if (roving() && (event.ctrlKey || event.metaKey)) {
950
+ choose(index, { kind: "toggle" }, event);
951
+ } else {
952
+ chooseAlone(index, event);
953
+ }
954
+ }
955
+ const observer = new MutationObserver(() => {
956
+ setTabStop();
957
+ if (state.kind === "awaiting") {
958
+ const row = rowElement(state.index);
959
+ const focused = document.activeElement;
960
+ if (row !== null) {
961
+ state = { kind: "active", index: state.index };
962
+ if (focused === null || focused === document.body || list.contains(focused)) {
963
+ row.focus({ preventScroll: true });
964
+ }
965
+ }
966
+ }
967
+ notify();
968
+ checkNearEnd();
969
+ });
970
+ observer.observe(list, {
971
+ childList: true,
972
+ subtree: true,
973
+ attributeFilter: [ROW_ATTRIBUTE]
974
+ });
975
+ list.tabIndex = -1;
976
+ list.addEventListener("keydown", onKeyDown, { signal });
977
+ list.addEventListener("focusin", onFocusIn, { signal });
978
+ list.addEventListener("pointermove", onPointerMove, { signal });
979
+ list.addEventListener("click", onClick, { signal });
980
+ list.addEventListener(
981
+ "pointerdown",
982
+ () => {
983
+ pointerPressed = true;
984
+ },
985
+ { signal }
986
+ );
987
+ list.ownerDocument.addEventListener(
988
+ "pointerup",
989
+ () => {
990
+ pointerPressed = false;
991
+ },
992
+ { signal, capture: true }
993
+ );
994
+ return {
995
+ element: list,
996
+ setRows(next) {
997
+ if (state.kind === "detached") {
998
+ return;
999
+ }
1000
+ const previous = activeIndex();
1001
+ const previousKey = previous === null ? void 0 : rows[previous]?.key;
1002
+ rows = next;
1003
+ if (state.kind === "active" || state.kind === "awaiting") {
1004
+ const kept = previousKey === void 0 ? -1 : next.findIndex((row) => row.key === previousKey);
1005
+ const index = kept !== -1 ? kept : nearestLanding(
1006
+ next,
1007
+ Math.min(state.index, next.length - 1),
1008
+ disabledOptions()
1009
+ );
1010
+ state = index === null ? INACTIVE : { kind: state.kind, index };
1011
+ if (index !== previous) {
1012
+ options.onActiveChange(index, "list");
1013
+ }
1014
+ }
1015
+ setTabStop();
1016
+ notify();
1017
+ checkNearEnd();
1018
+ },
1019
+ setOptions(next) {
1020
+ options = next;
1021
+ setTabStop();
1022
+ },
1023
+ activate(index, by) {
1024
+ setActive(
1025
+ index,
1026
+ by,
1027
+ by === "pointer" ? null : by === "open" ? "center" : "nearest"
1028
+ );
1029
+ },
1030
+ handleKey(event) {
1031
+ if (roving() || !onKey(event)) {
1032
+ return false;
1033
+ }
1034
+ event.preventDefault();
1035
+ return true;
1036
+ },
1037
+ chooseActive(nativeEvent) {
1038
+ const active = activeIndex();
1039
+ return state.kind !== "detached" && active !== null && choose(active, { kind: "one" }, nativeEvent);
1040
+ },
1041
+ getActive: activeIndex,
1042
+ activeId() {
1043
+ const active = activeIndex();
1044
+ const row = active === null ? null : rowElement(active);
1045
+ return row === null || row.id === "" ? null : row.id;
1046
+ },
1047
+ subscribe(listener) {
1048
+ listeners.add(listener);
1049
+ return () => {
1050
+ listeners.delete(listener);
1051
+ };
1052
+ },
1053
+ detach() {
1054
+ if (state.kind === "detached") {
1055
+ return;
1056
+ }
1057
+ state = { kind: "detached" };
1058
+ observer.disconnect();
1059
+ events.abort();
1060
+ clearTimeout(typeaheadTimer);
1061
+ listeners.clear();
1062
+ }
1063
+ };
1064
+ }
1065
+
1066
+ // src/scheduleTimeout.ts
1067
+ var scheduleTimeout = (callback, delay) => {
1068
+ const timer = setTimeout(callback, delay);
1069
+ return () => {
1070
+ clearTimeout(timer);
1071
+ };
1072
+ };
1073
+
1074
+ // src/listbox/choiceAnnouncer.ts
1075
+ var DEFAULT_SETTLE_DELAY = 500;
1076
+ function createChoiceAnnouncer(container, initialOptions) {
1077
+ let options = initialOptions;
1078
+ const region = createLiveAnnouncer(container, {
1079
+ className: options.className
1080
+ });
1081
+ let state = { kind: "quiet", last: null };
1082
+ function settle(last) {
1083
+ if (state.kind === "settling") {
1084
+ state.cancel();
1085
+ }
1086
+ state = { kind: "quiet", last };
1087
+ }
1088
+ return {
1089
+ results(query, count) {
1090
+ if (state.kind === "destroyed") {
1091
+ return;
1092
+ }
1093
+ const key = JSON.stringify([query, count]);
1094
+ const { last } = state;
1095
+ settle(last);
1096
+ if (key === last) {
1097
+ return;
1098
+ }
1099
+ const cancel = scheduleTimeout(() => {
1100
+ state = { kind: "quiet", last: key };
1101
+ const { messages } = options;
1102
+ region.announce(
1103
+ count === 0 ? messages.noMatches(query) : messages.resultCount(count)
1104
+ );
1105
+ }, options.settleDelay ?? DEFAULT_SETTLE_DELAY);
1106
+ state = { kind: "settling", last, cancel };
1107
+ },
1108
+ selected(count) {
1109
+ if (state.kind !== "destroyed") {
1110
+ region.announce(options.messages.selectedCount(count));
1111
+ }
1112
+ },
1113
+ announce(text) {
1114
+ if (state.kind !== "destroyed") {
1115
+ region.announce(text);
1116
+ }
1117
+ },
1118
+ cancel() {
1119
+ if (state.kind !== "destroyed") {
1120
+ settle(null);
1121
+ }
1122
+ },
1123
+ setOptions(next) {
1124
+ options = next;
1125
+ },
1126
+ destroy() {
1127
+ if (state.kind === "destroyed") {
1128
+ return;
1129
+ }
1130
+ settle(null);
1131
+ state = { kind: "destroyed" };
1132
+ region.destroy();
1133
+ }
1134
+ };
1135
+ }
1136
+
379
1137
  // src/overlay/overlayStack.ts
380
1138
  var STACK_KEY = /* @__PURE__ */ Symbol.for("@gridkitjs/overlay-stack");
381
1139
  function createStack() {
@@ -522,11 +1280,6 @@ function placeLeftToRight(anchor, panel, viewport, options) {
522
1280
  };
523
1281
  }
524
1282
 
525
- // src/writingDirection.ts
526
- function writingDirection(element) {
527
- return getComputedStyle(element).direction === "rtl" ? "rtl" : "ltr";
528
- }
529
-
530
1283
  // src/overlay/attachOverlay.ts
531
1284
  var FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
532
1285
  function tabbables(panel) {
@@ -849,14 +1602,6 @@ function createRowVirtualizer(scrollElement, options) {
849
1602
  };
850
1603
  }
851
1604
 
852
- // src/scheduleTimeout.ts
853
- var scheduleTimeout = (callback, delay) => {
854
- const timer = setTimeout(callback, delay);
855
- return () => {
856
- clearTimeout(timer);
857
- };
858
- };
859
-
860
1605
  // src/step/attachHoldRepeat.ts
861
1606
  var IDLE = { kind: "idle" };
862
1607
  var DETACHED2 = { kind: "detached" };
@@ -980,7 +1725,7 @@ function keyStep(key, edges) {
980
1725
  return null;
981
1726
  }
982
1727
  }
983
- function hasFocus(control) {
1728
+ function hasFocus2(control) {
984
1729
  const root = control.getRootNode();
985
1730
  return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === control;
986
1731
  }
@@ -1008,7 +1753,7 @@ function attachStepKeys(control, initialOptions) {
1008
1753
  control.addEventListener(
1009
1754
  "wheel",
1010
1755
  (event) => {
1011
- if (options.wheel !== true || !hasFocus(control)) {
1756
+ if (options.wheel !== true || !hasFocus2(control)) {
1012
1757
  wheelTravel = 0;
1013
1758
  return;
1014
1759
  }
@@ -1196,7 +1941,7 @@ function sourceOf(inputType) {
1196
1941
  }
1197
1942
  return inputType.startsWith("history") ? "undo" : "typing";
1198
1943
  }
1199
- function hasFocus2(control) {
1944
+ function hasFocus3(control) {
1200
1945
  const root = control.getRootNode();
1201
1946
  return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === control;
1202
1947
  }
@@ -1244,7 +1989,7 @@ function attachTextInput(control, controller, initialOptions = {}) {
1244
1989
  };
1245
1990
  }
1246
1991
  function writeText(text) {
1247
- if (!hasFocus2(control)) {
1992
+ if (!hasFocus3(control)) {
1248
1993
  control.value = text;
1249
1994
  return;
1250
1995
  }
@@ -1537,7 +2282,7 @@ function attachTextInput(control, controller, initialOptions = {}) {
1537
2282
  function limitCaret() {
1538
2283
  const { lastCaret } = options;
1539
2284
  const { selectionStart, selectionEnd } = control;
1540
- if (lastCaret === void 0 || selectionStart === null || selectionStart !== selectionEnd || !hasFocus2(control)) {
2285
+ if (lastCaret === void 0 || selectionStart === null || selectionStart !== selectionEnd || !hasFocus3(control)) {
1541
2286
  return;
1542
2287
  }
1543
2288
  const last = lastCaret(control.value);
@@ -1557,7 +2302,7 @@ function attachTextInput(control, controller, initialOptions = {}) {
1557
2302
  element.addEventListener(
1558
2303
  "pointerdown",
1559
2304
  () => {
1560
- pointerFocus = !hasFocus2(control);
2305
+ pointerFocus = !hasFocus3(control);
1561
2306
  },
1562
2307
  { signal }
1563
2308
  );
@@ -1585,7 +2330,7 @@ function attachTextInput(control, controller, initialOptions = {}) {
1585
2330
  element.addEventListener("keydown", onKeyDown, { signal });
1586
2331
  control.ownerDocument.addEventListener("reset", onReset, { signal });
1587
2332
  const unsubscribe = controller.subscribe(render);
1588
- if (hasFocus2(control) && !inGroup()) {
2333
+ if (hasFocus3(control) && !inGroup()) {
1589
2334
  controller.focus(null);
1590
2335
  }
1591
2336
  render();
@@ -1609,7 +2354,7 @@ function attachTextInput(control, controller, initialOptions = {}) {
1609
2354
  import {
1610
2355
  nextCheckedValue
1611
2356
  } from "@gridkitjs/forms-core";
1612
- function hasFocus3(control) {
2357
+ function hasFocus4(control) {
1613
2358
  const root = control.getRootNode();
1614
2359
  return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === control;
1615
2360
  }
@@ -1686,7 +2431,7 @@ function attachToggle(control, controller, initialOptions = {}) {
1686
2431
  );
1687
2432
  control.ownerDocument.addEventListener("reset", onReset, { signal });
1688
2433
  const unsubscribe = controller.subscribe(render);
1689
- if (hasFocus3(control)) {
2434
+ if (hasFocus4(control)) {
1690
2435
  controller.focus(null);
1691
2436
  }
1692
2437
  render();
@@ -2303,18 +3048,22 @@ function attachSegments(group, controller, initialOptions) {
2303
3048
  };
2304
3049
  }
2305
3050
  export {
3051
+ abortSignals,
2306
3052
  attachAutoGrow,
2307
3053
  attachChecklist,
3054
+ attachCombobox,
2308
3055
  attachEnterNavigation,
2309
3056
  attachFitCount,
2310
3057
  attachFocusGroup,
2311
3058
  attachHoldRepeat,
3059
+ attachListbox,
2312
3060
  attachOverlay,
2313
3061
  attachSegments,
2314
3062
  attachStepKeys,
2315
3063
  attachTextInput,
2316
3064
  attachToggle,
2317
3065
  compareDocumentOrder,
3066
+ createChoiceAnnouncer,
2318
3067
  createLiveAnnouncer,
2319
3068
  createRowVirtualizer,
2320
3069
  findFirstInvalidControl,