@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.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";
|