@zag-js/number-input 1.22.1 → 1.23.0
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 +11 -9
- package/dist/index.mjs +11 -9
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -111,7 +111,8 @@ function connect(service, normalize) {
|
|
|
111
111
|
const { state, send, prop, scope, computed } = service;
|
|
112
112
|
const focused = state.hasTag("focus");
|
|
113
113
|
const disabled = computed("isDisabled");
|
|
114
|
-
const readOnly = prop("readOnly");
|
|
114
|
+
const readOnly = !!prop("readOnly");
|
|
115
|
+
const required = !!prop("required");
|
|
115
116
|
const scrubbing = state.matches("scrubbing");
|
|
116
117
|
const empty = computed("isValueEmpty");
|
|
117
118
|
const invalid = computed("isOutOfRange") || !!prop("invalid");
|
|
@@ -163,6 +164,7 @@ function connect(service, normalize) {
|
|
|
163
164
|
"data-disabled": domQuery.dataAttr(disabled),
|
|
164
165
|
"data-focus": domQuery.dataAttr(focused),
|
|
165
166
|
"data-invalid": domQuery.dataAttr(invalid),
|
|
167
|
+
"data-required": domQuery.dataAttr(required),
|
|
166
168
|
"data-scrubbing": domQuery.dataAttr(scrubbing),
|
|
167
169
|
id: getLabelId(scope),
|
|
168
170
|
htmlFor: getInputId(scope)
|
|
@@ -361,8 +363,8 @@ function connect(service, normalize) {
|
|
|
361
363
|
}
|
|
362
364
|
|
|
363
365
|
// src/cursor.ts
|
|
364
|
-
function recordCursor(inputEl) {
|
|
365
|
-
if (!inputEl ||
|
|
366
|
+
function recordCursor(inputEl, scope) {
|
|
367
|
+
if (!inputEl || !scope.isActiveElement(inputEl)) return;
|
|
366
368
|
try {
|
|
367
369
|
const { selectionStart: start, selectionEnd: end, value } = inputEl;
|
|
368
370
|
const beforeTxt = value.substring(0, start);
|
|
@@ -377,8 +379,8 @@ function recordCursor(inputEl) {
|
|
|
377
379
|
} catch {
|
|
378
380
|
}
|
|
379
381
|
}
|
|
380
|
-
function restoreCursor(inputEl, selection) {
|
|
381
|
-
if (!inputEl ||
|
|
382
|
+
function restoreCursor(inputEl, selection, scope) {
|
|
383
|
+
if (!inputEl || !scope.isActiveElement(inputEl)) return;
|
|
382
384
|
if (!selection) {
|
|
383
385
|
inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length);
|
|
384
386
|
return;
|
|
@@ -493,11 +495,11 @@ var machine = createMachine({
|
|
|
493
495
|
valueText: ({ prop, context }) => prop("translations").valueText?.(context.get("value")),
|
|
494
496
|
formatter: core.memo(
|
|
495
497
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
496
|
-
(locale, formatOptions) => createFormatter(locale, formatOptions)
|
|
498
|
+
([locale, formatOptions]) => createFormatter(locale, formatOptions)
|
|
497
499
|
),
|
|
498
500
|
parser: core.memo(
|
|
499
501
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
500
|
-
(locale, formatOptions) => createParser(locale, formatOptions)
|
|
502
|
+
([locale, formatOptions]) => createParser(locale, formatOptions)
|
|
501
503
|
)
|
|
502
504
|
},
|
|
503
505
|
watch({ track, action, context, computed, prop }) {
|
|
@@ -813,10 +815,10 @@ var machine = createMachine({
|
|
|
813
815
|
syncInputElement({ context, event, computed, scope }) {
|
|
814
816
|
const value = event.type.endsWith("CHANGE") ? context.get("value") : computed("formattedValue");
|
|
815
817
|
const inputEl = getInputEl(scope);
|
|
816
|
-
const sel = recordCursor(inputEl);
|
|
818
|
+
const sel = recordCursor(inputEl, scope);
|
|
817
819
|
domQuery.raf(() => {
|
|
818
820
|
domQuery.setElementValue(inputEl, value);
|
|
819
|
-
restoreCursor(inputEl, sel);
|
|
821
|
+
restoreCursor(inputEl, sel, scope);
|
|
820
822
|
});
|
|
821
823
|
},
|
|
822
824
|
setFormattedValue({ context, computed }) {
|
package/dist/index.mjs
CHANGED
|
@@ -109,7 +109,8 @@ function connect(service, normalize) {
|
|
|
109
109
|
const { state, send, prop, scope, computed } = service;
|
|
110
110
|
const focused = state.hasTag("focus");
|
|
111
111
|
const disabled = computed("isDisabled");
|
|
112
|
-
const readOnly = prop("readOnly");
|
|
112
|
+
const readOnly = !!prop("readOnly");
|
|
113
|
+
const required = !!prop("required");
|
|
113
114
|
const scrubbing = state.matches("scrubbing");
|
|
114
115
|
const empty = computed("isValueEmpty");
|
|
115
116
|
const invalid = computed("isOutOfRange") || !!prop("invalid");
|
|
@@ -161,6 +162,7 @@ function connect(service, normalize) {
|
|
|
161
162
|
"data-disabled": dataAttr(disabled),
|
|
162
163
|
"data-focus": dataAttr(focused),
|
|
163
164
|
"data-invalid": dataAttr(invalid),
|
|
165
|
+
"data-required": dataAttr(required),
|
|
164
166
|
"data-scrubbing": dataAttr(scrubbing),
|
|
165
167
|
id: getLabelId(scope),
|
|
166
168
|
htmlFor: getInputId(scope)
|
|
@@ -359,8 +361,8 @@ function connect(service, normalize) {
|
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
// src/cursor.ts
|
|
362
|
-
function recordCursor(inputEl) {
|
|
363
|
-
if (!inputEl ||
|
|
364
|
+
function recordCursor(inputEl, scope) {
|
|
365
|
+
if (!inputEl || !scope.isActiveElement(inputEl)) return;
|
|
364
366
|
try {
|
|
365
367
|
const { selectionStart: start, selectionEnd: end, value } = inputEl;
|
|
366
368
|
const beforeTxt = value.substring(0, start);
|
|
@@ -375,8 +377,8 @@ function recordCursor(inputEl) {
|
|
|
375
377
|
} catch {
|
|
376
378
|
}
|
|
377
379
|
}
|
|
378
|
-
function restoreCursor(inputEl, selection) {
|
|
379
|
-
if (!inputEl ||
|
|
380
|
+
function restoreCursor(inputEl, selection, scope) {
|
|
381
|
+
if (!inputEl || !scope.isActiveElement(inputEl)) return;
|
|
380
382
|
if (!selection) {
|
|
381
383
|
inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length);
|
|
382
384
|
return;
|
|
@@ -491,11 +493,11 @@ var machine = createMachine({
|
|
|
491
493
|
valueText: ({ prop, context }) => prop("translations").valueText?.(context.get("value")),
|
|
492
494
|
formatter: memo(
|
|
493
495
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
494
|
-
(locale, formatOptions) => createFormatter(locale, formatOptions)
|
|
496
|
+
([locale, formatOptions]) => createFormatter(locale, formatOptions)
|
|
495
497
|
),
|
|
496
498
|
parser: memo(
|
|
497
499
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
498
|
-
(locale, formatOptions) => createParser(locale, formatOptions)
|
|
500
|
+
([locale, formatOptions]) => createParser(locale, formatOptions)
|
|
499
501
|
)
|
|
500
502
|
},
|
|
501
503
|
watch({ track, action, context, computed, prop }) {
|
|
@@ -811,10 +813,10 @@ var machine = createMachine({
|
|
|
811
813
|
syncInputElement({ context, event, computed, scope }) {
|
|
812
814
|
const value = event.type.endsWith("CHANGE") ? context.get("value") : computed("formattedValue");
|
|
813
815
|
const inputEl = getInputEl(scope);
|
|
814
|
-
const sel = recordCursor(inputEl);
|
|
816
|
+
const sel = recordCursor(inputEl, scope);
|
|
815
817
|
raf(() => {
|
|
816
818
|
setElementValue(inputEl, value);
|
|
817
|
-
restoreCursor(inputEl, sel);
|
|
819
|
+
restoreCursor(inputEl, sel, scope);
|
|
818
820
|
});
|
|
819
821
|
},
|
|
820
822
|
setFormattedValue({ context, computed }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Core logic for the number-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@internationalized/number": "3.6.
|
|
30
|
-
"@zag-js/anatomy": "1.
|
|
31
|
-
"@zag-js/core": "1.
|
|
32
|
-
"@zag-js/dom-query": "1.
|
|
33
|
-
"@zag-js/types": "1.
|
|
34
|
-
"@zag-js/utils": "1.
|
|
29
|
+
"@internationalized/number": "3.6.5",
|
|
30
|
+
"@zag-js/anatomy": "1.23.0",
|
|
31
|
+
"@zag-js/core": "1.23.0",
|
|
32
|
+
"@zag-js/dom-query": "1.23.0",
|
|
33
|
+
"@zag-js/types": "1.23.0",
|
|
34
|
+
"@zag-js/utils": "1.23.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"clean-package": "2.2.0"
|