@zag-js/popover 0.1.1 → 0.1.4
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 +70 -11
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +70 -11
- package/dist/index.mjs.map +3 -3
- package/dist/popover.connect.d.ts.map +1 -1
- package/dist/popover.dom.d.ts +1 -0
- package/dist/popover.dom.d.ts.map +1 -1
- package/dist/popover.machine.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -525,6 +525,30 @@ var getTabbables = (el, includeContainer = false) => {
|
|
|
525
525
|
var isTabbable = (el) => {
|
|
526
526
|
return isFocusable(el) && !isDisabled(el) && !isHidden(el);
|
|
527
527
|
};
|
|
528
|
+
function itemById(v, id) {
|
|
529
|
+
return v.find((node) => node.id === id);
|
|
530
|
+
}
|
|
531
|
+
function indexOfId(v, id) {
|
|
532
|
+
const item = itemById(v, id);
|
|
533
|
+
return item ? v.indexOf(item) : -1;
|
|
534
|
+
}
|
|
535
|
+
var getValueText = (item) => {
|
|
536
|
+
var _a, _b;
|
|
537
|
+
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
538
|
+
};
|
|
539
|
+
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
540
|
+
var wrap = (v, idx) => {
|
|
541
|
+
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
542
|
+
};
|
|
543
|
+
function findByText(v, text, currentId) {
|
|
544
|
+
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
545
|
+
let items = currentId ? wrap(v, index) : v;
|
|
546
|
+
const isSingleKey = text.length === 1;
|
|
547
|
+
if (isSingleKey) {
|
|
548
|
+
items = items.filter((item) => item.id !== currentId);
|
|
549
|
+
}
|
|
550
|
+
return items.find((item) => match(getValueText(item), text));
|
|
551
|
+
}
|
|
528
552
|
function trackPointerDown(doc, onPointerDown) {
|
|
529
553
|
var _a;
|
|
530
554
|
const win = (_a = doc.defaultView) != null ? _a : window;
|
|
@@ -535,6 +559,34 @@ function trackPointerDown(doc, onPointerDown) {
|
|
|
535
559
|
};
|
|
536
560
|
return addDomEvent(doc, "pointerdown", fn);
|
|
537
561
|
}
|
|
562
|
+
function findByTypeahead(_items, options) {
|
|
563
|
+
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
564
|
+
const search = state2.keysSoFar + key;
|
|
565
|
+
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
566
|
+
const query2 = isRepeated ? search[0] : search;
|
|
567
|
+
let items = _items.slice();
|
|
568
|
+
const next2 = findByText(items, query2, activeId);
|
|
569
|
+
function cleanup() {
|
|
570
|
+
clearTimeout(state2.timer);
|
|
571
|
+
state2.timer = -1;
|
|
572
|
+
}
|
|
573
|
+
function update(value) {
|
|
574
|
+
state2.keysSoFar = value;
|
|
575
|
+
cleanup();
|
|
576
|
+
if (value !== "") {
|
|
577
|
+
state2.timer = +setTimeout(() => {
|
|
578
|
+
update("");
|
|
579
|
+
cleanup();
|
|
580
|
+
}, timeout);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
update(search);
|
|
584
|
+
return next2;
|
|
585
|
+
}
|
|
586
|
+
findByTypeahead.defaultOptions = {
|
|
587
|
+
keysSoFar: "",
|
|
588
|
+
timer: -1
|
|
589
|
+
};
|
|
538
590
|
|
|
539
591
|
// src/popover.connect.ts
|
|
540
592
|
var import_popper = require("@zag-js/popper");
|
|
@@ -577,6 +629,10 @@ var dom = {
|
|
|
577
629
|
return (_a = ctx.doc) != null ? _a : document;
|
|
578
630
|
},
|
|
579
631
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
632
|
+
getRootNode: (ctx) => {
|
|
633
|
+
var _a;
|
|
634
|
+
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
635
|
+
},
|
|
580
636
|
getAnchorId: (ctx) => {
|
|
581
637
|
var _a, _b;
|
|
582
638
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.uid}:anchor`;
|
|
@@ -603,12 +659,12 @@ var dom = {
|
|
|
603
659
|
var _a, _b;
|
|
604
660
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.uid}:close-button`;
|
|
605
661
|
},
|
|
606
|
-
getAnchorEl: (ctx) => dom.
|
|
607
|
-
getTriggerEl: (ctx) => dom.
|
|
608
|
-
getContentEl: (ctx) => dom.
|
|
609
|
-
getPositionerEl: (ctx) => dom.
|
|
610
|
-
getTitleEl: (ctx) => dom.
|
|
611
|
-
getDescriptionEl: (ctx) => dom.
|
|
662
|
+
getAnchorEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getAnchorId(ctx)),
|
|
663
|
+
getTriggerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx)),
|
|
664
|
+
getContentEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getContentId(ctx)),
|
|
665
|
+
getPositionerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPositionerId(ctx)),
|
|
666
|
+
getTitleEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTitleId(ctx)),
|
|
667
|
+
getDescriptionEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getDescriptionId(ctx)),
|
|
612
668
|
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
613
669
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
614
670
|
getDocTabbableEls: (ctx) => getTabbables(cast(dom.getDoc(ctx))),
|
|
@@ -629,7 +685,8 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
629
685
|
const isOpen = state.matches("open");
|
|
630
686
|
const pointerdownNode = state.context.pointerdownNode;
|
|
631
687
|
const popperStyles = (0, import_popper.getPlacementStyles)({
|
|
632
|
-
measured: !!state.context.isPlacementComplete
|
|
688
|
+
measured: !!state.context.isPlacementComplete,
|
|
689
|
+
placement: state.context.currentPlacement
|
|
633
690
|
});
|
|
634
691
|
return {
|
|
635
692
|
portalled: state.context.currentPortalled,
|
|
@@ -913,25 +970,27 @@ function machine(ctx = {}) {
|
|
|
913
970
|
setupDocument(ctx2, evt) {
|
|
914
971
|
if (evt.doc)
|
|
915
972
|
ctx2.doc = (0, import_core.ref)(evt.doc);
|
|
973
|
+
if (evt.root)
|
|
974
|
+
ctx2.rootNode = (0, import_core.ref)(evt.root);
|
|
916
975
|
ctx2.uid = evt.id;
|
|
917
976
|
},
|
|
918
977
|
clearPointerDown(ctx2) {
|
|
919
978
|
ctx2.pointerdownNode = null;
|
|
920
979
|
},
|
|
921
980
|
focusContent(ctx2) {
|
|
922
|
-
|
|
981
|
+
raf(() => {
|
|
923
982
|
var _a;
|
|
924
983
|
(_a = dom.getContentEl(ctx2)) == null ? void 0 : _a.focus();
|
|
925
984
|
});
|
|
926
985
|
},
|
|
927
986
|
setInitialFocus(ctx2) {
|
|
928
|
-
|
|
987
|
+
raf(() => {
|
|
929
988
|
var _a;
|
|
930
989
|
(_a = dom.getInitialFocusEl(ctx2)) == null ? void 0 : _a.focus();
|
|
931
990
|
});
|
|
932
991
|
},
|
|
933
992
|
focusTrigger(ctx2) {
|
|
934
|
-
|
|
993
|
+
raf(() => {
|
|
935
994
|
var _a;
|
|
936
995
|
(_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
|
|
937
996
|
});
|
|
@@ -966,7 +1025,7 @@ function machine(ctx = {}) {
|
|
|
966
1025
|
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
967
1026
|
return;
|
|
968
1027
|
evt.preventDefault();
|
|
969
|
-
|
|
1028
|
+
raf(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
|
|
970
1029
|
}
|
|
971
1030
|
}
|
|
972
1031
|
});
|