@zag-js/dom-utils
Advanced tools
Comparing version 0.0.0-dev-20220427162539 to 0.0.0-dev-20220508172505
@@ -27,2 +27,3 @@ export * from "./attrs"; | ||
export * from "./wait"; | ||
export * from "./typeahead"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -43,2 +43,3 @@ var __create = Object.create; | ||
findByText: () => findByText, | ||
findByTypeahead: () => findByTypeahead, | ||
focusableSelector: () => focusableSelector, | ||
@@ -65,2 +66,3 @@ forceReflow: () => forceReflow, | ||
isDisabled: () => isDisabled, | ||
isElementEditable: () => isElementEditable, | ||
isFocusable: () => isFocusable, | ||
@@ -466,2 +468,13 @@ isHTMLElement: () => isHTMLElement, | ||
} | ||
function isElementEditable(el) { | ||
if (el == null) | ||
return false; | ||
const selectors = [ | ||
"input:not([readonly])", | ||
"textarea:not([readonly])", | ||
"[contenteditable]", | ||
"select:not([readonly])" | ||
].join(", "); | ||
return el.matches(selectors) || el.isContentEditable; | ||
} | ||
@@ -876,9 +889,18 @@ // src/scrollable.ts | ||
} | ||
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 filtered = v.filter((item) => { | ||
var _a; | ||
const str = (_a = item.dataset.valuetext) != null ? _a : item.textContent; | ||
return !!(str == null ? void 0 : str.toLowerCase().startsWith(text.toLowerCase())); | ||
}); | ||
return currentId ? nextById(filtered, currentId) : null; | ||
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)); | ||
} | ||
@@ -1114,2 +1136,32 @@ function sortByTreeOrder(v) { | ||
} | ||
// src/typeahead.ts | ||
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 | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -14,3 +14,4 @@ /// <reference types="react" /> | ||
export declare function getNativeEvent<E>(event: E): React.ChangeEvent<any> extends E ? InputEvent : E extends React.SyntheticEvent<any, infer T> ? T : never; | ||
export declare function isElementEditable(el: HTMLElement | null): boolean; | ||
export {}; | ||
//# sourceMappingURL=query.d.ts.map |
{ | ||
"name": "@zag-js/dom-utils", | ||
"version": "0.0.0-dev-20220427162539", | ||
"version": "0.0.0-dev-20220508172505", | ||
"description": "", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
"@types/react": "^18.0.0", | ||
"@zag-js/utils": "^0.0.0-dev-20220427162539", | ||
"@zag-js/utils": "0.0.0-dev-20220508172505", | ||
"scroll-into-view-if-needed": "^2.2.29" | ||
@@ -42,2 +42,2 @@ }, | ||
} | ||
} | ||
} |
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
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
251490
65
2543
2208
+ Added@zag-js/utils@0.0.0-dev-20220508172505(transitive)
- Removed@zag-js/utils@0.0.0-dev-20240723090825(transitive)