@zag-js/number-input 0.2.11 → 0.2.13
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/{chunk-4A67X5BX.mjs → chunk-3O7PA63J.mjs} +13 -138
- package/dist/{chunk-6CS5P7OC.mjs → chunk-AXXDGYUW.mjs} +2 -8
- package/dist/{chunk-4ASBTBA5.mjs → chunk-DYFCS7PF.mjs} +46 -43
- package/dist/{chunk-GQN3V2LU.mjs → chunk-QYY4CWRS.mjs} +4 -13
- package/dist/index.js +105 -326
- package/dist/index.mjs +4 -5
- package/dist/number-input.connect.d.ts +39 -0
- package/dist/number-input.connect.js +81 -175
- package/dist/number-input.connect.mjs +3 -4
- package/dist/number-input.dom.d.ts +9 -6
- package/dist/number-input.dom.js +9 -65
- package/dist/number-input.dom.mjs +1 -2
- package/dist/number-input.machine.js +41 -266
- package/dist/number-input.machine.mjs +3 -4
- package/dist/number-input.utils.js +9 -54
- package/dist/number-input.utils.mjs +1 -2
- package/package.json +10 -8
- package/dist/chunk-EPCXXTFL.mjs +0 -141
package/dist/index.js
CHANGED
|
@@ -39,266 +39,15 @@ var anatomy = (0, import_anatomy.createAnatomy)("numberInput").parts(
|
|
|
39
39
|
);
|
|
40
40
|
var parts = anatomy.build();
|
|
41
41
|
|
|
42
|
-
//
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var ariaAttr = (guard) => {
|
|
47
|
-
return guard ? "true" : void 0;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// ../../utilities/dom/src/constants.ts
|
|
51
|
-
var MAX_Z_INDEX = 2147483647;
|
|
52
|
-
|
|
53
|
-
// ../../utilities/core/src/functions.ts
|
|
54
|
-
var runIfFn = (v, ...a) => {
|
|
55
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
56
|
-
return res ?? void 0;
|
|
57
|
-
};
|
|
58
|
-
var callAll = (...fns) => (...a) => {
|
|
59
|
-
fns.forEach(function(fn) {
|
|
60
|
-
fn?.(...a);
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// ../../utilities/core/src/guard.ts
|
|
65
|
-
var isArray = (v) => Array.isArray(v);
|
|
66
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
67
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
68
|
-
|
|
69
|
-
// ../../utilities/core/src/object.ts
|
|
70
|
-
function compact(obj) {
|
|
71
|
-
if (obj === void 0)
|
|
72
|
-
return obj;
|
|
73
|
-
return Object.fromEntries(
|
|
74
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// ../../utilities/dom/src/platform.ts
|
|
79
|
-
var isDom = () => typeof window !== "undefined";
|
|
80
|
-
function getPlatform() {
|
|
81
|
-
const agent = navigator.userAgentData;
|
|
82
|
-
return agent?.platform ?? navigator.platform;
|
|
83
|
-
}
|
|
84
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
85
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
86
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
87
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
88
|
-
|
|
89
|
-
// ../../utilities/dom/src/query.ts
|
|
90
|
-
function isDocument(el) {
|
|
91
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
92
|
-
}
|
|
93
|
-
function isWindow(value) {
|
|
94
|
-
return value?.toString() === "[object Window]";
|
|
95
|
-
}
|
|
96
|
-
function getDocument(el) {
|
|
97
|
-
if (isWindow(el))
|
|
98
|
-
return el.document;
|
|
99
|
-
if (isDocument(el))
|
|
100
|
-
return el;
|
|
101
|
-
return el?.ownerDocument ?? document;
|
|
102
|
-
}
|
|
103
|
-
function getWindow(el) {
|
|
104
|
-
return el?.ownerDocument.defaultView ?? window;
|
|
105
|
-
}
|
|
106
|
-
function defineDomHelpers(helpers) {
|
|
107
|
-
const dom2 = {
|
|
108
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
109
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
110
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
111
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
112
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
113
|
-
};
|
|
114
|
-
return {
|
|
115
|
-
...dom2,
|
|
116
|
-
...helpers
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ../../utilities/dom/src/event.ts
|
|
121
|
-
function getNativeEvent(e) {
|
|
122
|
-
return e.nativeEvent ?? e;
|
|
123
|
-
}
|
|
124
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
125
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
126
|
-
var isLeftClick = (v) => v.button === 0;
|
|
127
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
128
|
-
|
|
129
|
-
// ../../utilities/dom/src/get-event-point.ts
|
|
130
|
-
var fallback = {
|
|
131
|
-
pageX: 0,
|
|
132
|
-
pageY: 0,
|
|
133
|
-
clientX: 0,
|
|
134
|
-
clientY: 0
|
|
135
|
-
};
|
|
136
|
-
function getEventPoint(event, type = "page") {
|
|
137
|
-
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
|
|
138
|
-
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
142
|
-
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
143
|
-
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
144
|
-
function getEventStep(event) {
|
|
145
|
-
if (event.ctrlKey || event.metaKey) {
|
|
146
|
-
return 0.1;
|
|
147
|
-
} else {
|
|
148
|
-
const isPageKey = PAGE_KEYS.has(event.key);
|
|
149
|
-
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
|
|
150
|
-
return isSkipKey ? 10 : 1;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// ../../utilities/dom/src/listener.ts
|
|
155
|
-
var isRef = (v) => hasProp(v, "current");
|
|
156
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
157
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
158
|
-
node?.addEventListener(eventName, handler, options);
|
|
159
|
-
return () => {
|
|
160
|
-
node?.removeEventListener(eventName, handler, options);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// ../../utilities/dom/src/mutation-observer.ts
|
|
165
|
-
function observeAttributes(node, attributes, fn) {
|
|
166
|
-
if (!node)
|
|
167
|
-
return;
|
|
168
|
-
const attrs = Array.isArray(attributes) ? attributes : [attributes];
|
|
169
|
-
const win = node.ownerDocument.defaultView || window;
|
|
170
|
-
const obs = new win.MutationObserver((changes) => {
|
|
171
|
-
for (const change of changes) {
|
|
172
|
-
if (change.type === "attributes" && change.attributeName && attrs.includes(change.attributeName)) {
|
|
173
|
-
fn(change);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
178
|
-
return () => obs.disconnect();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
182
|
-
function raf(fn) {
|
|
183
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
184
|
-
return function cleanup() {
|
|
185
|
-
globalThis.cancelAnimationFrame(id);
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ../../utilities/dom/src/pointerlock.ts
|
|
190
|
-
function addPointerlockChangeListener(doc, fn) {
|
|
191
|
-
return addDomEvent(doc, "pointerlockchange", fn, false);
|
|
192
|
-
}
|
|
193
|
-
function addPointerlockErrorListener(doc, fn) {
|
|
194
|
-
doc.addEventListener("pointerlockerror", fn, false);
|
|
195
|
-
return function cleanup() {
|
|
196
|
-
doc.removeEventListener("pointerlockerror", fn, false);
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function requestPointerLock(doc, handlers = {}) {
|
|
200
|
-
const { onPointerLock, onPointerUnlock } = handlers;
|
|
201
|
-
const body = doc.body;
|
|
202
|
-
const supported = "pointerLockElement" in doc || "mozPointerLockElement" in doc;
|
|
203
|
-
const locked = !!doc.pointerLockElement;
|
|
204
|
-
function onPointerChange() {
|
|
205
|
-
if (locked)
|
|
206
|
-
onPointerLock?.();
|
|
207
|
-
else
|
|
208
|
-
onPointerUnlock?.();
|
|
209
|
-
}
|
|
210
|
-
function onPointerError(event) {
|
|
211
|
-
if (locked)
|
|
212
|
-
onPointerUnlock?.();
|
|
213
|
-
console.error("PointerLock error occured:", event);
|
|
214
|
-
exit();
|
|
215
|
-
}
|
|
216
|
-
function exit() {
|
|
217
|
-
doc.exitPointerLock();
|
|
218
|
-
}
|
|
219
|
-
if (!supported)
|
|
220
|
-
return;
|
|
221
|
-
try {
|
|
222
|
-
body.requestPointerLock();
|
|
223
|
-
} catch {
|
|
224
|
-
}
|
|
225
|
-
const cleanup = callAll(
|
|
226
|
-
addPointerlockChangeListener(doc, onPointerChange),
|
|
227
|
-
addPointerlockErrorListener(doc, onPointerError)
|
|
228
|
-
);
|
|
229
|
-
return function dispose() {
|
|
230
|
-
if (!supported)
|
|
231
|
-
return;
|
|
232
|
-
cleanup();
|
|
233
|
-
exit();
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// ../../utilities/number/src/number.ts
|
|
238
|
-
function wrap(num, max) {
|
|
239
|
-
return (num % max + max) % max;
|
|
240
|
-
}
|
|
241
|
-
function roundToDevicePixel(num) {
|
|
242
|
-
if (typeof window === "undefined")
|
|
243
|
-
return Math.round(num);
|
|
244
|
-
const dp = window.devicePixelRatio;
|
|
245
|
-
return Math.floor(num * dp + 0.5) / dp;
|
|
246
|
-
}
|
|
247
|
-
function clamp(v, o) {
|
|
248
|
-
return Math.min(Math.max(valueOf(v), o.min), o.max);
|
|
249
|
-
}
|
|
250
|
-
function countDecimals(value) {
|
|
251
|
-
if (!Number.isFinite(value))
|
|
252
|
-
return 0;
|
|
253
|
-
let e = 1, p = 0;
|
|
254
|
-
while (Math.round(value * e) / e !== value) {
|
|
255
|
-
e *= 10;
|
|
256
|
-
p += 1;
|
|
257
|
-
}
|
|
258
|
-
return p;
|
|
259
|
-
}
|
|
260
|
-
var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
|
|
261
|
-
var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
|
|
262
|
-
function valueOf(v) {
|
|
263
|
-
if (typeof v === "number")
|
|
264
|
-
return v;
|
|
265
|
-
const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
|
|
266
|
-
return !Number.isNaN(num) ? num : 0;
|
|
267
|
-
}
|
|
268
|
-
function formatDecimal(v, o) {
|
|
269
|
-
return new Intl.NumberFormat("en-US", {
|
|
270
|
-
useGrouping: false,
|
|
271
|
-
style: "decimal",
|
|
272
|
-
minimumFractionDigits: o.minFractionDigits,
|
|
273
|
-
maximumFractionDigits: o.maxFractionDigits
|
|
274
|
-
}).format(valueOf(v));
|
|
275
|
-
}
|
|
276
|
-
function isAtMax(v, o) {
|
|
277
|
-
const val = valueOf(v);
|
|
278
|
-
return val >= o.max;
|
|
279
|
-
}
|
|
280
|
-
function isAtMin(v, o) {
|
|
281
|
-
const val = valueOf(v);
|
|
282
|
-
return val <= o.min;
|
|
283
|
-
}
|
|
284
|
-
function isWithinRange(v, o) {
|
|
285
|
-
const val = valueOf(v);
|
|
286
|
-
return val >= o.min && val <= o.max;
|
|
287
|
-
}
|
|
288
|
-
function decimalOperation(a, op, b) {
|
|
289
|
-
let result = op === "+" ? a + b : a - b;
|
|
290
|
-
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
291
|
-
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
292
|
-
a = Math.round(a * multiplier);
|
|
293
|
-
b = Math.round(b * multiplier);
|
|
294
|
-
result = op === "+" ? a + b : a - b;
|
|
295
|
-
result /= multiplier;
|
|
296
|
-
}
|
|
297
|
-
return result;
|
|
298
|
-
}
|
|
42
|
+
// src/number-input.connect.ts
|
|
43
|
+
var import_dom_event2 = require("@zag-js/dom-event");
|
|
44
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
45
|
+
var import_number_utils3 = require("@zag-js/number-utils");
|
|
299
46
|
|
|
300
47
|
// src/number-input.dom.ts
|
|
301
|
-
var
|
|
48
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
49
|
+
var import_number_utils = require("@zag-js/number-utils");
|
|
50
|
+
var dom = (0, import_dom_query.createScope)({
|
|
302
51
|
getRootId: (ctx) => ctx.ids?.root ?? `number-input:${ctx.id}`,
|
|
303
52
|
getInputId: (ctx) => ctx.ids?.input ?? `number-input:${ctx.id}:input`,
|
|
304
53
|
getIncrementTriggerId: (ctx) => ctx.ids?.incrementTrigger ?? `number-input:${ctx.id}:inc`,
|
|
@@ -322,7 +71,7 @@ var dom = defineDomHelpers({
|
|
|
322
71
|
return btnEl;
|
|
323
72
|
},
|
|
324
73
|
setupVirtualCursor(ctx) {
|
|
325
|
-
if (isSafari
|
|
74
|
+
if ((0, import_dom_query.isSafari)())
|
|
326
75
|
return;
|
|
327
76
|
dom.createVirtualCursor(ctx);
|
|
328
77
|
return () => {
|
|
@@ -349,8 +98,8 @@ var dom = defineDomHelpers({
|
|
|
349
98
|
};
|
|
350
99
|
},
|
|
351
100
|
getMousementValue(ctx, event) {
|
|
352
|
-
const x = roundToDevicePixel(event.movementX);
|
|
353
|
-
const y = roundToDevicePixel(event.movementY);
|
|
101
|
+
const x = (0, import_number_utils.roundToDevicePixel)(event.movementX);
|
|
102
|
+
const y = (0, import_number_utils.roundToDevicePixel)(event.movementY);
|
|
354
103
|
let hint = x > 0 ? "increment" : x < 0 ? "decrement" : null;
|
|
355
104
|
if (ctx.isRtl && hint === "increment")
|
|
356
105
|
hint = "decrement";
|
|
@@ -362,8 +111,8 @@ var dom = defineDomHelpers({
|
|
|
362
111
|
};
|
|
363
112
|
const win = dom.getWin(ctx);
|
|
364
113
|
const width = win.innerWidth;
|
|
365
|
-
const half = roundToDevicePixel(7.5);
|
|
366
|
-
point.x = wrap(point.x + half, width) - half;
|
|
114
|
+
const half = (0, import_number_utils.roundToDevicePixel)(7.5);
|
|
115
|
+
point.x = (0, import_number_utils.wrap)(point.x + half, width) - half;
|
|
367
116
|
return { hint, point };
|
|
368
117
|
},
|
|
369
118
|
createVirtualCursor(ctx) {
|
|
@@ -378,7 +127,7 @@ var dom = defineDomHelpers({
|
|
|
378
127
|
pointerEvents: "none",
|
|
379
128
|
left: "0px",
|
|
380
129
|
top: "0px",
|
|
381
|
-
zIndex: MAX_Z_INDEX,
|
|
130
|
+
zIndex: import_dom_query.MAX_Z_INDEX,
|
|
382
131
|
transform: ctx.scrubberCursorPoint ? `translate3d(${ctx.scrubberCursorPoint.x}px, ${ctx.scrubberCursorPoint.y}px, 0px)` : void 0,
|
|
383
132
|
willChange: "transform"
|
|
384
133
|
});
|
|
@@ -394,11 +143,13 @@ var dom = defineDomHelpers({
|
|
|
394
143
|
});
|
|
395
144
|
|
|
396
145
|
// src/number-input.utils.ts
|
|
146
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
147
|
+
var import_number_utils2 = require("@zag-js/number-utils");
|
|
397
148
|
var utils = {
|
|
398
149
|
isValidNumericEvent: (ctx, event) => {
|
|
399
150
|
if (event.key == null)
|
|
400
151
|
return true;
|
|
401
|
-
const isModifier = isModifiedEvent(event);
|
|
152
|
+
const isModifier = (0, import_dom_event.isModifiedEvent)(event);
|
|
402
153
|
const isSingleKey = event.key.length === 1;
|
|
403
154
|
if (isModifier || !isSingleKey)
|
|
404
155
|
return true;
|
|
@@ -409,15 +160,15 @@ var utils = {
|
|
|
409
160
|
return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
|
|
410
161
|
},
|
|
411
162
|
increment: (ctx, step) => {
|
|
412
|
-
const value = increment(ctx.value, step ?? ctx.step);
|
|
413
|
-
return formatDecimal(clamp(value, ctx), ctx);
|
|
163
|
+
const value = (0, import_number_utils2.increment)(ctx.value, step ?? ctx.step);
|
|
164
|
+
return (0, import_number_utils2.formatDecimal)((0, import_number_utils2.clamp)(value, ctx), ctx);
|
|
414
165
|
},
|
|
415
166
|
decrement: (ctx, step) => {
|
|
416
|
-
const value = decrement(ctx.value, step ?? ctx.step);
|
|
417
|
-
return formatDecimal(clamp(value, ctx), ctx);
|
|
167
|
+
const value = (0, import_number_utils2.decrement)(ctx.value, step ?? ctx.step);
|
|
168
|
+
return (0, import_number_utils2.formatDecimal)((0, import_number_utils2.clamp)(value, ctx), ctx);
|
|
418
169
|
},
|
|
419
170
|
clamp: (ctx) => {
|
|
420
|
-
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
171
|
+
return (0, import_number_utils2.formatDecimal)((0, import_number_utils2.clamp)(ctx.value, ctx), ctx);
|
|
421
172
|
},
|
|
422
173
|
parse: (ctx, value) => {
|
|
423
174
|
return ctx.parse?.(value) ?? value;
|
|
@@ -427,7 +178,7 @@ var utils = {
|
|
|
427
178
|
return ctx.format?.(_val) ?? _val;
|
|
428
179
|
},
|
|
429
180
|
round: (ctx) => {
|
|
430
|
-
return formatDecimal(ctx.value, ctx);
|
|
181
|
+
return (0, import_number_utils2.formatDecimal)(ctx.value, ctx);
|
|
431
182
|
}
|
|
432
183
|
};
|
|
433
184
|
|
|
@@ -441,44 +192,83 @@ function connect(state, send, normalize) {
|
|
|
441
192
|
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
442
193
|
const translations = state.context.translations;
|
|
443
194
|
return {
|
|
195
|
+
/**
|
|
196
|
+
* Whether the input is focused.
|
|
197
|
+
*/
|
|
444
198
|
isFocused,
|
|
199
|
+
/**
|
|
200
|
+
* Whether the input is invalid.
|
|
201
|
+
*/
|
|
445
202
|
isInvalid,
|
|
203
|
+
/**
|
|
204
|
+
* Whether the input value is empty.
|
|
205
|
+
*/
|
|
446
206
|
isValueEmpty,
|
|
207
|
+
/**
|
|
208
|
+
* The formatted value of the input.
|
|
209
|
+
*/
|
|
447
210
|
value: state.context.formattedValue,
|
|
211
|
+
/**
|
|
212
|
+
* The value of the input as a number.
|
|
213
|
+
*/
|
|
448
214
|
valueAsNumber: state.context.valueAsNumber,
|
|
215
|
+
/**
|
|
216
|
+
* Function to set the value of the input.
|
|
217
|
+
*/
|
|
449
218
|
setValue(value) {
|
|
450
219
|
send({ type: "SET_VALUE", value: value.toString() });
|
|
451
220
|
},
|
|
221
|
+
/**
|
|
222
|
+
* Function to clear the value of the input.
|
|
223
|
+
*/
|
|
452
224
|
clearValue() {
|
|
453
225
|
send("CLEAR_VALUE");
|
|
454
226
|
},
|
|
227
|
+
/**
|
|
228
|
+
* Function to increment the value of the input by the step.
|
|
229
|
+
*/
|
|
455
230
|
increment() {
|
|
456
231
|
send("INCREMENT");
|
|
457
232
|
},
|
|
233
|
+
/**
|
|
234
|
+
* Function to decrement the value of the input by the step.
|
|
235
|
+
*/
|
|
458
236
|
decrement() {
|
|
459
237
|
send("DECREMENT");
|
|
460
238
|
},
|
|
239
|
+
/**
|
|
240
|
+
* Function to set the value of the input to the max.
|
|
241
|
+
*/
|
|
461
242
|
setToMax() {
|
|
462
243
|
send({ type: "SET_VALUE", value: state.context.max });
|
|
463
244
|
},
|
|
245
|
+
/**
|
|
246
|
+
* Function to set the value of the input to the min.
|
|
247
|
+
*/
|
|
464
248
|
setToMin() {
|
|
465
249
|
send({ type: "SET_VALUE", value: state.context.min });
|
|
466
250
|
},
|
|
251
|
+
/**
|
|
252
|
+
* Function to focus the input.
|
|
253
|
+
*/
|
|
467
254
|
focus() {
|
|
468
255
|
dom.getInputEl(state.context)?.focus();
|
|
469
256
|
},
|
|
257
|
+
/**
|
|
258
|
+
* Function to blur the input.
|
|
259
|
+
*/
|
|
470
260
|
blur() {
|
|
471
261
|
dom.getInputEl(state.context)?.blur();
|
|
472
262
|
},
|
|
473
263
|
rootProps: normalize.element({
|
|
474
264
|
id: dom.getRootId(state.context),
|
|
475
265
|
...parts.root.attrs,
|
|
476
|
-
"data-disabled": dataAttr(isDisabled)
|
|
266
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled)
|
|
477
267
|
}),
|
|
478
268
|
labelProps: normalize.label({
|
|
479
269
|
...parts.label.attrs,
|
|
480
|
-
"data-disabled": dataAttr(isDisabled),
|
|
481
|
-
"data-invalid": dataAttr(isInvalid),
|
|
270
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
271
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
482
272
|
id: dom.getLabelId(state.context),
|
|
483
273
|
htmlFor: dom.getInputId(state.context)
|
|
484
274
|
}),
|
|
@@ -486,9 +276,9 @@ function connect(state, send, normalize) {
|
|
|
486
276
|
...parts.control.attrs,
|
|
487
277
|
role: "group",
|
|
488
278
|
"aria-disabled": isDisabled,
|
|
489
|
-
"data-disabled": dataAttr(isDisabled),
|
|
490
|
-
"data-invalid": dataAttr(isInvalid),
|
|
491
|
-
"aria-invalid": ariaAttr(state.context.invalid)
|
|
279
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
280
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
281
|
+
"aria-invalid": (0, import_dom_query2.ariaAttr)(state.context.invalid)
|
|
492
282
|
}),
|
|
493
283
|
inputProps: normalize.input({
|
|
494
284
|
...parts.input.attrs,
|
|
@@ -499,10 +289,10 @@ function connect(state, send, normalize) {
|
|
|
499
289
|
defaultValue: state.context.formattedValue,
|
|
500
290
|
pattern: state.context.pattern,
|
|
501
291
|
inputMode: state.context.inputMode,
|
|
502
|
-
"aria-invalid":
|
|
503
|
-
"data-invalid": dataAttr(isInvalid),
|
|
292
|
+
"aria-invalid": (0, import_dom_query2.ariaAttr)(isInvalid),
|
|
293
|
+
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
504
294
|
disabled: isDisabled,
|
|
505
|
-
"data-disabled": dataAttr(isDisabled),
|
|
295
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
506
296
|
readOnly: !!state.context.readOnly,
|
|
507
297
|
autoComplete: "off",
|
|
508
298
|
autoCorrect: "off",
|
|
@@ -520,19 +310,19 @@ function connect(state, send, normalize) {
|
|
|
520
310
|
send("BLUR");
|
|
521
311
|
},
|
|
522
312
|
onChange(event) {
|
|
523
|
-
const evt = getNativeEvent(event);
|
|
313
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
524
314
|
if (evt.isComposing)
|
|
525
315
|
return;
|
|
526
316
|
send({ type: "CHANGE", target: event.currentTarget, hint: "set" });
|
|
527
317
|
},
|
|
528
318
|
onKeyDown(event) {
|
|
529
|
-
const evt = getNativeEvent(event);
|
|
319
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
530
320
|
if (evt.isComposing)
|
|
531
321
|
return;
|
|
532
322
|
if (!utils.isValidNumericEvent(state.context, event)) {
|
|
533
323
|
event.preventDefault();
|
|
534
324
|
}
|
|
535
|
-
const step = getEventStep(event) * state.context.step;
|
|
325
|
+
const step = (0, import_dom_event2.getEventStep)(event) * state.context.step;
|
|
536
326
|
const keyMap = {
|
|
537
327
|
ArrowUp() {
|
|
538
328
|
send({ type: "ARROW_UP", step });
|
|
@@ -558,7 +348,7 @@ function connect(state, send, normalize) {
|
|
|
558
348
|
...parts.decrementTrigger.attrs,
|
|
559
349
|
id: dom.getDecrementTriggerId(state.context),
|
|
560
350
|
disabled: isDecrementDisabled,
|
|
561
|
-
"data-disabled": dataAttr(isDecrementDisabled),
|
|
351
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDecrementDisabled),
|
|
562
352
|
"aria-label": translations.decrementLabel,
|
|
563
353
|
type: "button",
|
|
564
354
|
tabIndex: -1,
|
|
@@ -566,7 +356,7 @@ function connect(state, send, normalize) {
|
|
|
566
356
|
onPointerDown(event) {
|
|
567
357
|
if (isDecrementDisabled)
|
|
568
358
|
return;
|
|
569
|
-
send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "decrement" } : { type: "FOCUS" });
|
|
359
|
+
send((0, import_dom_event2.isLeftClick)(event) ? { type: "PRESS_DOWN", hint: "decrement" } : { type: "FOCUS" });
|
|
570
360
|
event.preventDefault();
|
|
571
361
|
},
|
|
572
362
|
onPointerUp() {
|
|
@@ -582,7 +372,7 @@ function connect(state, send, normalize) {
|
|
|
582
372
|
...parts.incrementTrigger.attrs,
|
|
583
373
|
id: dom.getIncrementTriggerId(state.context),
|
|
584
374
|
disabled: isIncrementDisabled,
|
|
585
|
-
"data-disabled": dataAttr(isIncrementDisabled),
|
|
375
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isIncrementDisabled),
|
|
586
376
|
"aria-label": translations.incrementLabel,
|
|
587
377
|
type: "button",
|
|
588
378
|
tabIndex: -1,
|
|
@@ -590,7 +380,7 @@ function connect(state, send, normalize) {
|
|
|
590
380
|
onPointerDown(event) {
|
|
591
381
|
if (isIncrementDisabled)
|
|
592
382
|
return;
|
|
593
|
-
send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "increment" } : { type: "FOCUS" });
|
|
383
|
+
send((0, import_dom_event2.isLeftClick)(event) ? { type: "PRESS_DOWN", hint: "increment" } : { type: "FOCUS" });
|
|
594
384
|
event.preventDefault();
|
|
595
385
|
},
|
|
596
386
|
onPointerUp() {
|
|
@@ -602,17 +392,17 @@ function connect(state, send, normalize) {
|
|
|
602
392
|
}),
|
|
603
393
|
scrubberProps: normalize.element({
|
|
604
394
|
...parts.scrubber.attrs,
|
|
605
|
-
"data-disabled": dataAttr(isDisabled),
|
|
395
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(isDisabled),
|
|
606
396
|
id: dom.getScrubberId(state.context),
|
|
607
397
|
role: "presentation",
|
|
608
398
|
onMouseDown(event) {
|
|
609
399
|
if (isDisabled)
|
|
610
400
|
return;
|
|
611
|
-
const evt = getNativeEvent(event);
|
|
401
|
+
const evt = (0, import_dom_event2.getNativeEvent)(event);
|
|
612
402
|
event.preventDefault();
|
|
613
|
-
const point =
|
|
614
|
-
point.x = point.x - roundToDevicePixel(7.5);
|
|
615
|
-
point.y = point.y - roundToDevicePixel(7.5);
|
|
403
|
+
const point = { x: evt.clientX, y: evt.clientY };
|
|
404
|
+
point.x = point.x - (0, import_number_utils3.roundToDevicePixel)(7.5);
|
|
405
|
+
point.y = point.y - (0, import_number_utils3.roundToDevicePixel)(7.5);
|
|
616
406
|
send({ type: "PRESS_DOWN_SCRUBBER", point });
|
|
617
407
|
},
|
|
618
408
|
style: {
|
|
@@ -624,29 +414,15 @@ function connect(state, send, normalize) {
|
|
|
624
414
|
|
|
625
415
|
// src/number-input.machine.ts
|
|
626
416
|
var import_core = require("@zag-js/core");
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}
|
|
634
|
-
function dispatchInputValueEvent(el, value) {
|
|
635
|
-
if (!el)
|
|
636
|
-
return;
|
|
637
|
-
const win = getWindow(el);
|
|
638
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
639
|
-
return;
|
|
640
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
641
|
-
desc.set?.call(el, value);
|
|
642
|
-
const event = new win.Event("input", { bubbles: true });
|
|
643
|
-
el.dispatchEvent(event);
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// src/number-input.machine.ts
|
|
417
|
+
var import_dom_event3 = require("@zag-js/dom-event");
|
|
418
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
419
|
+
var import_form_utils = require("@zag-js/form-utils");
|
|
420
|
+
var import_mutation_observer = require("@zag-js/mutation-observer");
|
|
421
|
+
var import_number_utils4 = require("@zag-js/number-utils");
|
|
422
|
+
var import_utils = require("@zag-js/utils");
|
|
647
423
|
var { not, and } = import_core.guards;
|
|
648
424
|
function machine(userContext) {
|
|
649
|
-
const ctx = compact(userContext);
|
|
425
|
+
const ctx = (0, import_utils.compact)(userContext);
|
|
650
426
|
return (0, import_core.createMachine)(
|
|
651
427
|
{
|
|
652
428
|
id: "number-input",
|
|
@@ -675,10 +451,10 @@ function machine(userContext) {
|
|
|
675
451
|
},
|
|
676
452
|
computed: {
|
|
677
453
|
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
678
|
-
valueAsNumber: (ctx2) => valueOf(ctx2.value),
|
|
679
|
-
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
680
|
-
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
681
|
-
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
454
|
+
valueAsNumber: (ctx2) => (0, import_number_utils4.valueOf)(ctx2.value),
|
|
455
|
+
isAtMin: (ctx2) => (0, import_number_utils4.isAtMin)(ctx2.value, ctx2),
|
|
456
|
+
isAtMax: (ctx2) => (0, import_number_utils4.isAtMax)(ctx2.value, ctx2),
|
|
457
|
+
isOutOfRange: (ctx2) => !(0, import_number_utils4.isWithinRange)(ctx2.value, ctx2),
|
|
682
458
|
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
683
459
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
684
460
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
@@ -859,7 +635,9 @@ function machine(userContext) {
|
|
|
859
635
|
},
|
|
860
636
|
trackButtonDisabled(ctx2, _evt, { send }) {
|
|
861
637
|
const btn = dom.getPressedTriggerEl(ctx2, ctx2.hint);
|
|
862
|
-
return observeAttributes(btn, "disabled", () =>
|
|
638
|
+
return (0, import_mutation_observer.observeAttributes)(btn, ["disabled"], () => {
|
|
639
|
+
send("PRESS_UP");
|
|
640
|
+
});
|
|
863
641
|
},
|
|
864
642
|
attachWheelListener(ctx2, _evt, { send }) {
|
|
865
643
|
const input = dom.getInputEl(ctx2);
|
|
@@ -877,12 +655,12 @@ function machine(userContext) {
|
|
|
877
655
|
send("DECREMENT");
|
|
878
656
|
}
|
|
879
657
|
}
|
|
880
|
-
return addDomEvent(input, "wheel", onWheel, { passive: false });
|
|
658
|
+
return (0, import_dom_event3.addDomEvent)(input, "wheel", onWheel, { passive: false });
|
|
881
659
|
},
|
|
882
660
|
activatePointerLock(ctx2) {
|
|
883
|
-
if (isSafari
|
|
661
|
+
if ((0, import_dom_query3.isSafari)())
|
|
884
662
|
return;
|
|
885
|
-
return requestPointerLock(dom.getDoc(ctx2));
|
|
663
|
+
return (0, import_dom_event3.requestPointerLock)(dom.getDoc(ctx2));
|
|
886
664
|
},
|
|
887
665
|
trackMousemove(ctx2, _evt, { send }) {
|
|
888
666
|
const doc = dom.getDoc(ctx2);
|
|
@@ -901,9 +679,9 @@ function machine(userContext) {
|
|
|
901
679
|
function onMouseup() {
|
|
902
680
|
send("POINTER_UP_SCRUBBER");
|
|
903
681
|
}
|
|
904
|
-
return callAll(
|
|
905
|
-
addDomEvent(doc, "mousemove", onMousemove, false),
|
|
906
|
-
addDomEvent(doc, "mouseup", onMouseup, false)
|
|
682
|
+
return (0, import_utils.callAll)(
|
|
683
|
+
(0, import_dom_event3.addDomEvent)(doc, "mousemove", onMousemove, false),
|
|
684
|
+
(0, import_dom_event3.addDomEvent)(doc, "mouseup", onMouseup, false)
|
|
907
685
|
);
|
|
908
686
|
}
|
|
909
687
|
},
|
|
@@ -912,7 +690,7 @@ function machine(userContext) {
|
|
|
912
690
|
if (!ctx2.focusInputOnChange)
|
|
913
691
|
return;
|
|
914
692
|
const input = dom.getInputEl(ctx2);
|
|
915
|
-
raf(() => input?.focus());
|
|
693
|
+
(0, import_dom_query3.raf)(() => input?.focus());
|
|
916
694
|
},
|
|
917
695
|
increment(ctx2, evt) {
|
|
918
696
|
ctx2.value = utils.increment(ctx2, evt.step);
|
|
@@ -987,6 +765,7 @@ function machine(userContext) {
|
|
|
987
765
|
valueAsNumber: ctx2.valueAsNumber
|
|
988
766
|
});
|
|
989
767
|
},
|
|
768
|
+
// sync input value, in event it was set from form libraries via `ref`, `bind:this`, etc.
|
|
990
769
|
syncInputValue(ctx2) {
|
|
991
770
|
const input = dom.getInputEl(ctx2);
|
|
992
771
|
if (!input || input.value == ctx2.value)
|
|
@@ -1008,7 +787,7 @@ function machine(userContext) {
|
|
|
1008
787
|
cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
1009
788
|
},
|
|
1010
789
|
dispatchChangeEvent(ctx2) {
|
|
1011
|
-
dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
|
|
790
|
+
(0, import_form_utils.dispatchInputValueEvent)(dom.getInputEl(ctx2), ctx2.formattedValue);
|
|
1012
791
|
}
|
|
1013
792
|
}
|
|
1014
793
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DYFCS7PF.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
6
|
} from "./chunk-XHRILSH3.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-EPCXXTFL.mjs";
|
|
9
|
+
} from "./chunk-3O7PA63J.mjs";
|
|
10
|
+
import "./chunk-QYY4CWRS.mjs";
|
|
11
|
+
import "./chunk-AXXDGYUW.mjs";
|
|
13
12
|
export {
|
|
14
13
|
anatomy,
|
|
15
14
|
connect,
|