@zag-js/popover
Advanced tools
Comparing version 0.0.0-dev-20220504084708 to 0.0.0-dev-20220508172505
@@ -528,2 +528,26 @@ var __defProp = Object.defineProperty; | ||
}; | ||
function itemById(v, id) { | ||
return v.find((node) => node.id === id); | ||
} | ||
function indexOfId(v, id) { | ||
const item = itemById(v, id); | ||
return item ? v.indexOf(item) : -1; | ||
} | ||
var getValueText = (item) => { | ||
var _a, _b; | ||
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : ""; | ||
}; | ||
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase()); | ||
var wrap = (v, idx) => { | ||
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]); | ||
}; | ||
function findByText(v, text, currentId) { | ||
const index = currentId ? indexOfId(v, currentId) : -1; | ||
let items = currentId ? wrap(v, index) : v; | ||
const isSingleKey = text.length === 1; | ||
if (isSingleKey) { | ||
items = items.filter((item) => item.id !== currentId); | ||
} | ||
return items.find((item) => match(getValueText(item), text)); | ||
} | ||
function trackPointerDown(doc, onPointerDown) { | ||
@@ -539,2 +563,30 @@ var _a; | ||
} | ||
function findByTypeahead(_items, options) { | ||
const { state: state2, activeId, key, timeout = 350 } = options; | ||
const search = state2.keysSoFar + key; | ||
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]); | ||
const query2 = isRepeated ? search[0] : search; | ||
let items = _items.slice(); | ||
const next2 = findByText(items, query2, activeId); | ||
function cleanup() { | ||
clearTimeout(state2.timer); | ||
state2.timer = -1; | ||
} | ||
function update(value) { | ||
state2.keysSoFar = value; | ||
cleanup(); | ||
if (value !== "") { | ||
state2.timer = +setTimeout(() => { | ||
update(""); | ||
cleanup(); | ||
}, timeout); | ||
} | ||
} | ||
update(search); | ||
return next2; | ||
} | ||
findByTypeahead.defaultOptions = { | ||
keysSoFar: "", | ||
timer: -1 | ||
}; | ||
@@ -541,0 +593,0 @@ // src/popover.connect.ts |
{ | ||
"name": "@zag-js/popover", | ||
"version": "0.0.0-dev-20220504084708", | ||
"version": "0.0.0-dev-20220508172505", | ||
"description": "Core logic for the popover widget implemented as a state machine", | ||
@@ -32,7 +32,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/core": "0.0.0-dev-20220504084708", | ||
"@zag-js/dom-utils": "0.1.0", | ||
"@zag-js/core": "0.0.0-dev-20220508172505", | ||
"@zag-js/dom-utils": "0.0.0-dev-20220508172505", | ||
"@zag-js/types": "0.1.0", | ||
"@zag-js/popper": "0.1.0", | ||
"@zag-js/utils": "0.1.0", | ||
"@zag-js/popper": "0.0.0-dev-20220508172505", | ||
"@zag-js/utils": "0.0.0-dev-20220508172505", | ||
"@zag-js/aria-hidden": "0.1.0", | ||
@@ -39,0 +39,0 @@ "focus-trap": "^6.7.1" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
323986
2171
+ Added@zag-js/core@0.0.0-dev-20220508172505(transitive)
+ Added@zag-js/dom-utils@0.0.0-dev-20220508172505(transitive)
+ Added@zag-js/popper@0.0.0-dev-20220508172505(transitive)
+ Added@zag-js/utils@0.0.0-dev-20220508172505(transitive)
- Removed@zag-js/core@0.0.0-dev-20220504084708(transitive)
- Removed@zag-js/dom-utils@0.1.0(transitive)
- Removed@zag-js/popper@0.1.0(transitive)
- Removed@zag-js/utils@0.1.0(transitive)