@zag-js/range-slider
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -315,2 +315,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)); | ||
} | ||
var state = "default"; | ||
@@ -379,6 +403,34 @@ var savedUserSelect = ""; | ||
} | ||
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 | ||
}; | ||
// ../../utilities/number/dist/index.mjs | ||
var __pow2 = Math.pow; | ||
var nf = new Intl.NumberFormat("en-US", { style: "decimal" }); | ||
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 }); | ||
function formatter(n) { | ||
@@ -398,5 +450,12 @@ return parseFloat(nf.format(n)); | ||
} | ||
function countDecimals(v) { | ||
var _a, _b; | ||
return (_b = (_a = nf.formatToParts(v).find((p) => p.type === "fraction")) == null ? void 0 : _a.value.length) != null ? _b : 0; | ||
function countDecimals(value) { | ||
if (!Number.isFinite(value)) | ||
return 0; | ||
let e = 1; | ||
let p = 0; | ||
while (Math.round(value * e) / e !== value) { | ||
e *= 10; | ||
p += 1; | ||
} | ||
return p; | ||
} | ||
@@ -575,3 +634,3 @@ var increment = (v, s) => formatter(valueOf(v) + s); | ||
var isLeftClick2 = (v) => v.button === 0; | ||
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey || v.shiftKey; | ||
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey; | ||
@@ -578,0 +637,0 @@ // src/range-slider.dom.ts |
{ | ||
"name": "@zag-js/range-slider", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Core logic for the range-slider widget implemented as a state machine", | ||
@@ -32,9 +32,9 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/core": "0.1.2", | ||
"@zag-js/dom-utils": "0.1.0", | ||
"@zag-js/number-utils": "0.1.0", | ||
"@zag-js/rect-utils": "0.1.0", | ||
"@zag-js/slider": "0.1.2", | ||
"@zag-js/core": "0.1.3", | ||
"@zag-js/dom-utils": "0.1.1", | ||
"@zag-js/number-utils": "0.1.1", | ||
"@zag-js/rect-utils": "0.1.1", | ||
"@zag-js/slider": "0.1.3", | ||
"@zag-js/types": "0.1.0", | ||
"@zag-js/utils": "0.1.0" | ||
"@zag-js/utils": "0.1.1" | ||
}, | ||
@@ -41,0 +41,0 @@ "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
364766
2785
+ Added@zag-js/core@0.1.3(transitive)
+ Added@zag-js/dom-utils@0.1.1(transitive)
+ Added@zag-js/number-utils@0.1.1(transitive)
+ Added@zag-js/rect-utils@0.1.1(transitive)
+ Added@zag-js/slider@0.1.3(transitive)
+ Added@zag-js/utils@0.1.1(transitive)
- Removed@zag-js/core@0.1.2(transitive)
- Removed@zag-js/dom-utils@0.1.0(transitive)
- Removed@zag-js/number-utils@0.1.0(transitive)
- Removed@zag-js/rect-utils@0.1.0(transitive)
- Removed@zag-js/slider@0.1.2(transitive)
- Removed@zag-js/utils@0.1.0(transitive)
Updated@zag-js/core@0.1.3
Updated@zag-js/dom-utils@0.1.1
Updated@zag-js/number-utils@0.1.1
Updated@zag-js/rect-utils@0.1.1
Updated@zag-js/slider@0.1.3
Updated@zag-js/utils@0.1.1