@zag-js/popper
Advanced tools
Comparing version 0.0.0-dev-20220427162539 to 0.0.0-dev-20220508172505
@@ -128,2 +128,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 getObservedElements() { | ||
@@ -181,2 +205,30 @@ ; | ||
} | ||
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 next = 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 next; | ||
} | ||
findByTypeahead.defaultOptions = { | ||
keysSoFar: "", | ||
timer: -1 | ||
}; | ||
@@ -183,0 +235,0 @@ // src/auto-update.ts |
{ | ||
"name": "@zag-js/popper", | ||
"version": "0.0.0-dev-20220427162539", | ||
"version": "0.0.0-dev-20220508172505", | ||
"description": "Dynamic positioning logic for ui machines", | ||
@@ -29,4 +29,4 @@ "keywords": [ | ||
"@floating-ui/dom": "^0.4.2", | ||
"@zag-js/dom-utils": "^0.0.0-dev-20220427162539", | ||
"@zag-js/utils": "^0.0.0-dev-20220427162539" | ||
"@zag-js/dom-utils": "0.0.0-dev-20220508172505", | ||
"@zag-js/utils": "0.0.0-dev-20220508172505" | ||
}, | ||
@@ -42,2 +42,2 @@ "scripts": { | ||
} | ||
} | ||
} |
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
187021
979
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@18.3.11(transitive)
+ Added@zag-js/dom-utils@0.0.0-dev-20220508172505(transitive)
+ Added@zag-js/utils@0.0.0-dev-20220508172505(transitive)
+ Addedcompute-scroll-into-view@1.0.20(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedscroll-into-view-if-needed@2.2.31(transitive)
- Removed@zag-js/dom-utils@0.0.0-dev-20230202113057(transitive)
- Removed@zag-js/types@0.0.0-dev-20230202113057(transitive)
- Removed@zag-js/utils@0.0.0-dev-20240723090825(transitive)
- Removedcsstype@3.1.1(transitive)