@zag-js/number-input 0.0.0-dev-20220504084708 → 0.0.0-dev-20220508172505
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 +65 -14
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +65 -14
- package/dist/index.mjs.map +3 -3
- package/dist/number-input.utils.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -161,6 +161,30 @@ function observeAttributes(node, attributes, fn) {
|
|
|
161
161
|
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
162
162
|
return () => obs.disconnect();
|
|
163
163
|
}
|
|
164
|
+
function itemById(v, id) {
|
|
165
|
+
return v.find((node) => node.id === id);
|
|
166
|
+
}
|
|
167
|
+
function indexOfId(v, id) {
|
|
168
|
+
const item = itemById(v, id);
|
|
169
|
+
return item ? v.indexOf(item) : -1;
|
|
170
|
+
}
|
|
171
|
+
var getValueText = (item) => {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
|
|
174
|
+
};
|
|
175
|
+
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
176
|
+
var wrap = (v, idx) => {
|
|
177
|
+
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
178
|
+
};
|
|
179
|
+
function findByText(v, text, currentId) {
|
|
180
|
+
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
181
|
+
let items = currentId ? wrap(v, index) : v;
|
|
182
|
+
const isSingleKey = text.length === 1;
|
|
183
|
+
if (isSingleKey) {
|
|
184
|
+
items = items.filter((item) => item.id !== currentId);
|
|
185
|
+
}
|
|
186
|
+
return items.find((item) => match(getValueText(item), text));
|
|
187
|
+
}
|
|
164
188
|
function addPointerlockChangeListener(doc, fn) {
|
|
165
189
|
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
166
190
|
}
|
|
@@ -201,6 +225,34 @@ function requestPointerLock(doc, handlers = {}) {
|
|
|
201
225
|
exit();
|
|
202
226
|
};
|
|
203
227
|
}
|
|
228
|
+
function findByTypeahead(_items, options) {
|
|
229
|
+
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
230
|
+
const search = state2.keysSoFar + key;
|
|
231
|
+
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
232
|
+
const query2 = isRepeated ? search[0] : search;
|
|
233
|
+
let items = _items.slice();
|
|
234
|
+
const next = findByText(items, query2, activeId);
|
|
235
|
+
function cleanup() {
|
|
236
|
+
clearTimeout(state2.timer);
|
|
237
|
+
state2.timer = -1;
|
|
238
|
+
}
|
|
239
|
+
function update(value) {
|
|
240
|
+
state2.keysSoFar = value;
|
|
241
|
+
cleanup();
|
|
242
|
+
if (value !== "") {
|
|
243
|
+
state2.timer = +setTimeout(() => {
|
|
244
|
+
update("");
|
|
245
|
+
cleanup();
|
|
246
|
+
}, timeout);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
update(search);
|
|
250
|
+
return next;
|
|
251
|
+
}
|
|
252
|
+
findByTypeahead.defaultOptions = {
|
|
253
|
+
keysSoFar: "",
|
|
254
|
+
timer: -1
|
|
255
|
+
};
|
|
204
256
|
|
|
205
257
|
// ../../utilities/number/dist/index.mjs
|
|
206
258
|
var __defProp2 = Object.defineProperty;
|
|
@@ -227,7 +279,7 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal" });
|
|
|
227
279
|
function formatter(n) {
|
|
228
280
|
return parseFloat(nf.format(n));
|
|
229
281
|
}
|
|
230
|
-
function
|
|
282
|
+
function wrap2(num, max) {
|
|
231
283
|
return (num % max + max) % max;
|
|
232
284
|
}
|
|
233
285
|
function round(v, t2) {
|
|
@@ -352,7 +404,7 @@ var dom = {
|
|
|
352
404
|
const win = dom.getWin(ctx);
|
|
353
405
|
const width = win.innerWidth;
|
|
354
406
|
const half = roundToPx(7.5);
|
|
355
|
-
point.x =
|
|
407
|
+
point.x = wrap2(point.x + half, width) - half;
|
|
356
408
|
return { hint, point };
|
|
357
409
|
},
|
|
358
410
|
createVirtualCursor(ctx) {
|
|
@@ -382,15 +434,23 @@ var dom = {
|
|
|
382
434
|
}
|
|
383
435
|
};
|
|
384
436
|
|
|
437
|
+
// ../../utilities/core/dist/index.mjs
|
|
438
|
+
var pipe2 = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
439
|
+
var ua = (v) => isDom() && v.test(navigator.userAgent);
|
|
440
|
+
var isDom = () => !!(typeof window !== "undefined");
|
|
441
|
+
var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
|
|
442
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
443
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
444
|
+
|
|
385
445
|
// src/number-input.utils.ts
|
|
386
446
|
var utils = {
|
|
387
447
|
isValidNumericEvent: (ctx, event) => {
|
|
388
448
|
var _a, _b;
|
|
389
449
|
if (event.key == null)
|
|
390
450
|
return true;
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
451
|
+
const isModifier = isModifiedEvent(event);
|
|
452
|
+
const isSingleKey = event.key.length === 1;
|
|
453
|
+
if (isModifier || !isSingleKey)
|
|
394
454
|
return true;
|
|
395
455
|
return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
|
|
396
456
|
},
|
|
@@ -609,15 +669,6 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
609
669
|
|
|
610
670
|
// src/number-input.machine.ts
|
|
611
671
|
var import_core = require("@zag-js/core");
|
|
612
|
-
|
|
613
|
-
// ../../utilities/core/dist/index.mjs
|
|
614
|
-
var pipe2 = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
615
|
-
var ua = (v) => isDom() && v.test(navigator.userAgent);
|
|
616
|
-
var isDom = () => !!(typeof window !== "undefined");
|
|
617
|
-
var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
|
|
618
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
619
|
-
|
|
620
|
-
// src/number-input.machine.ts
|
|
621
672
|
var { not, and } = import_core.guards;
|
|
622
673
|
function machine(ctx = {}) {
|
|
623
674
|
return (0, import_core.createMachine)({
|