@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.mjs
CHANGED
|
@@ -502,6 +502,30 @@ var getTabbables = (el, includeContainer = false) => {
|
|
|
502
502
|
var isTabbable = (el) => {
|
|
503
503
|
return isFocusable(el) && !isDisabled(el) && !isHidden(el);
|
|
504
504
|
};
|
|
505
|
+
function itemById(v, id) {
|
|
506
|
+
return v.find((node) => node.id === id);
|
|
507
|
+
}
|
|
508
|
+
function indexOfId(v, id) {
|
|
509
|
+
const item = itemById(v, id);
|
|
510
|
+
return item ? v.indexOf(item) : -1;
|
|
511
|
+
}
|
|
512
|
+
var getValueText = (item) => {
|
|
513
|
+
var _a, _b;
|
|
514
|
+
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
515
|
+
};
|
|
516
|
+
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
517
|
+
var wrap = (v, idx) => {
|
|
518
|
+
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
519
|
+
};
|
|
520
|
+
function findByText(v, text, currentId) {
|
|
521
|
+
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
522
|
+
let items = currentId ? wrap(v, index) : v;
|
|
523
|
+
const isSingleKey = text.length === 1;
|
|
524
|
+
if (isSingleKey) {
|
|
525
|
+
items = items.filter((item) => item.id !== currentId);
|
|
526
|
+
}
|
|
527
|
+
return items.find((item) => match(getValueText(item), text));
|
|
528
|
+
}
|
|
505
529
|
function trackPointerDown(doc, onPointerDown) {
|
|
506
530
|
var _a;
|
|
507
531
|
const win = (_a = doc.defaultView) != null ? _a : window;
|
|
@@ -512,6 +536,34 @@ function trackPointerDown(doc, onPointerDown) {
|
|
|
512
536
|
};
|
|
513
537
|
return addDomEvent(doc, "pointerdown", fn);
|
|
514
538
|
}
|
|
539
|
+
function findByTypeahead(_items, options) {
|
|
540
|
+
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
541
|
+
const search = state2.keysSoFar + key;
|
|
542
|
+
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
543
|
+
const query2 = isRepeated ? search[0] : search;
|
|
544
|
+
let items = _items.slice();
|
|
545
|
+
const next2 = findByText(items, query2, activeId);
|
|
546
|
+
function cleanup() {
|
|
547
|
+
clearTimeout(state2.timer);
|
|
548
|
+
state2.timer = -1;
|
|
549
|
+
}
|
|
550
|
+
function update(value) {
|
|
551
|
+
state2.keysSoFar = value;
|
|
552
|
+
cleanup();
|
|
553
|
+
if (value !== "") {
|
|
554
|
+
state2.timer = +setTimeout(() => {
|
|
555
|
+
update("");
|
|
556
|
+
cleanup();
|
|
557
|
+
}, timeout);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
update(search);
|
|
561
|
+
return next2;
|
|
562
|
+
}
|
|
563
|
+
findByTypeahead.defaultOptions = {
|
|
564
|
+
keysSoFar: "",
|
|
565
|
+
timer: -1
|
|
566
|
+
};
|
|
515
567
|
|
|
516
568
|
// src/popover.connect.ts
|
|
517
569
|
import { getPlacementStyles } from "@zag-js/popper";
|
|
@@ -554,6 +606,10 @@ var dom = {
|
|
|
554
606
|
return (_a = ctx.doc) != null ? _a : document;
|
|
555
607
|
},
|
|
556
608
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
609
|
+
getRootNode: (ctx) => {
|
|
610
|
+
var _a;
|
|
611
|
+
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
612
|
+
},
|
|
557
613
|
getAnchorId: (ctx) => {
|
|
558
614
|
var _a, _b;
|
|
559
615
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.uid}:anchor`;
|
|
@@ -580,12 +636,12 @@ var dom = {
|
|
|
580
636
|
var _a, _b;
|
|
581
637
|
return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeBtn) != null ? _b : `popover:${ctx.uid}:close-button`;
|
|
582
638
|
},
|
|
583
|
-
getAnchorEl: (ctx) => dom.
|
|
584
|
-
getTriggerEl: (ctx) => dom.
|
|
585
|
-
getContentEl: (ctx) => dom.
|
|
586
|
-
getPositionerEl: (ctx) => dom.
|
|
587
|
-
getTitleEl: (ctx) => dom.
|
|
588
|
-
getDescriptionEl: (ctx) => dom.
|
|
639
|
+
getAnchorEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getAnchorId(ctx)),
|
|
640
|
+
getTriggerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTriggerId(ctx)),
|
|
641
|
+
getContentEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getContentId(ctx)),
|
|
642
|
+
getPositionerEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getPositionerId(ctx)),
|
|
643
|
+
getTitleEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getTitleId(ctx)),
|
|
644
|
+
getDescriptionEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getDescriptionId(ctx)),
|
|
589
645
|
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
590
646
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
591
647
|
getDocTabbableEls: (ctx) => getTabbables(cast(dom.getDoc(ctx))),
|
|
@@ -606,7 +662,8 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
606
662
|
const isOpen = state.matches("open");
|
|
607
663
|
const pointerdownNode = state.context.pointerdownNode;
|
|
608
664
|
const popperStyles = getPlacementStyles({
|
|
609
|
-
measured: !!state.context.isPlacementComplete
|
|
665
|
+
measured: !!state.context.isPlacementComplete,
|
|
666
|
+
placement: state.context.currentPlacement
|
|
610
667
|
});
|
|
611
668
|
return {
|
|
612
669
|
portalled: state.context.currentPortalled,
|
|
@@ -890,25 +947,27 @@ function machine(ctx = {}) {
|
|
|
890
947
|
setupDocument(ctx2, evt) {
|
|
891
948
|
if (evt.doc)
|
|
892
949
|
ctx2.doc = ref(evt.doc);
|
|
950
|
+
if (evt.root)
|
|
951
|
+
ctx2.rootNode = ref(evt.root);
|
|
893
952
|
ctx2.uid = evt.id;
|
|
894
953
|
},
|
|
895
954
|
clearPointerDown(ctx2) {
|
|
896
955
|
ctx2.pointerdownNode = null;
|
|
897
956
|
},
|
|
898
957
|
focusContent(ctx2) {
|
|
899
|
-
|
|
958
|
+
raf(() => {
|
|
900
959
|
var _a;
|
|
901
960
|
(_a = dom.getContentEl(ctx2)) == null ? void 0 : _a.focus();
|
|
902
961
|
});
|
|
903
962
|
},
|
|
904
963
|
setInitialFocus(ctx2) {
|
|
905
|
-
|
|
964
|
+
raf(() => {
|
|
906
965
|
var _a;
|
|
907
966
|
(_a = dom.getInitialFocusEl(ctx2)) == null ? void 0 : _a.focus();
|
|
908
967
|
});
|
|
909
968
|
},
|
|
910
969
|
focusTrigger(ctx2) {
|
|
911
|
-
|
|
970
|
+
raf(() => {
|
|
912
971
|
var _a;
|
|
913
972
|
(_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
|
|
914
973
|
});
|
|
@@ -943,7 +1002,7 @@ function machine(ctx = {}) {
|
|
|
943
1002
|
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
944
1003
|
return;
|
|
945
1004
|
evt.preventDefault();
|
|
946
|
-
|
|
1005
|
+
raf(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
|
|
947
1006
|
}
|
|
948
1007
|
}
|
|
949
1008
|
});
|