@zag-js/popover 0.1.2 → 0.1.3
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 +52 -0
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +52 -0
- package/dist/index.mjs.map +3 -3
- package/package.json +5 -5
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");
|