@zag-js/number-input 1.48.0 → 1.49.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/number-input.connect.d.mts +1 -1
- package/dist/number-input.connect.d.ts +1 -1
- package/dist/number-input.connect.js +4 -5
- package/dist/number-input.connect.mjs +4 -5
- package/dist/number-input.dom.d.mts +1 -1
- package/dist/number-input.dom.d.ts +1 -1
- package/dist/number-input.machine.js +14 -5
- package/dist/number-input.machine.mjs +14 -5
- package/dist/number-input.props.js +2 -1
- package/dist/number-input.props.mjs +1 -1
- package/dist/number-input.translations.d.mts +1 -1
- package/dist/number-input.translations.d.ts +1 -1
- package/dist/number-input.types.d.mts +5 -1
- package/dist/number-input.types.d.ts +5 -1
- package/dist/number-input.utils.d.mts +2 -2
- package/dist/number-input.utils.d.ts +2 -2
- package/package.json +6 -6
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NumberInputApi, NumberInputService } from "./number-input.types.mjs";
|
|
2
1
|
import { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
+
import { NumberInputApi, NumberInputService } from "./number-input.types.mjs";
|
|
3
3
|
export declare function connect<T extends PropTypes>(service: NumberInputService, normalize: NormalizeProps<T>): NumberInputApi<T>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NumberInputApi, NumberInputService } from "./number-input.types.js";
|
|
2
1
|
import { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
+
import { NumberInputApi, NumberInputService } from "./number-input.types.js";
|
|
3
3
|
export declare function connect<T extends PropTypes>(service: NumberInputService, normalize: NormalizeProps<T>): NumberInputApi<T>;
|
|
@@ -2,12 +2,12 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
6
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
5
7
|
const require_cursor = require("./cursor.js");
|
|
6
8
|
const require_number_input_anatomy = require("./number-input.anatomy.js");
|
|
7
9
|
const require_number_input_dom = require("./number-input.dom.js");
|
|
8
10
|
const require_number_input_translations = require("./number-input.translations.js");
|
|
9
|
-
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
10
|
-
let _zag_js_utils = require("@zag-js/utils");
|
|
11
11
|
// src/number-input.connect.ts
|
|
12
12
|
function connect(service, normalize) {
|
|
13
13
|
const { state, send, prop, scope, computed } = service;
|
|
@@ -167,7 +167,7 @@ function connect(service, normalize) {
|
|
|
167
167
|
largeStep: prop("largeStep"),
|
|
168
168
|
smallStep: prop("smallStep")
|
|
169
169
|
});
|
|
170
|
-
|
|
170
|
+
(0, {
|
|
171
171
|
ArrowUp() {
|
|
172
172
|
send({
|
|
173
173
|
type: "INPUT.ARROW_UP",
|
|
@@ -199,8 +199,7 @@ function connect(service, normalize) {
|
|
|
199
199
|
selection
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
|
-
}[event.key];
|
|
203
|
-
exec?.(event);
|
|
202
|
+
}[event.key])?.(event);
|
|
204
203
|
}
|
|
205
204
|
});
|
|
206
205
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { ariaAttr, dataAttr, getEventPoint, getEventStepValue, getWindow, isComposingEvent, isLeftClick, isModifierKey, raf, setCaretToEnd } from "@zag-js/dom-query";
|
|
2
|
+
import { mergeWithDefault, roundToDpr } from "@zag-js/utils";
|
|
1
3
|
import { recordCursor } from "./cursor.mjs";
|
|
2
4
|
import { parts } from "./number-input.anatomy.mjs";
|
|
3
5
|
import { getDecrementTriggerId, getIncrementTriggerId, getInputEl, getInputId, getLabelId, getRootId, getScrubberId } from "./number-input.dom.mjs";
|
|
4
6
|
import { defaultTranslations } from "./number-input.translations.mjs";
|
|
5
|
-
import { ariaAttr, dataAttr, getEventPoint, getEventStepValue, getWindow, isComposingEvent, isLeftClick, isModifierKey, raf, setCaretToEnd } from "@zag-js/dom-query";
|
|
6
|
-
import { mergeWithDefault, roundToDpr } from "@zag-js/utils";
|
|
7
7
|
// src/number-input.connect.ts
|
|
8
8
|
function connect(service, normalize) {
|
|
9
9
|
const { state, send, prop, scope, computed } = service;
|
|
@@ -163,7 +163,7 @@ function connect(service, normalize) {
|
|
|
163
163
|
largeStep: prop("largeStep"),
|
|
164
164
|
smallStep: prop("smallStep")
|
|
165
165
|
});
|
|
166
|
-
|
|
166
|
+
(0, {
|
|
167
167
|
ArrowUp() {
|
|
168
168
|
send({
|
|
169
169
|
type: "INPUT.ARROW_UP",
|
|
@@ -195,8 +195,7 @@ function connect(service, normalize) {
|
|
|
195
195
|
selection
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
-
}[event.key];
|
|
199
|
-
exec?.(event);
|
|
198
|
+
}[event.key])?.(event);
|
|
200
199
|
}
|
|
201
200
|
});
|
|
202
201
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HintValue } from "./number-input.types.mjs";
|
|
2
1
|
import { Scope } from "@zag-js/core";
|
|
3
2
|
import { Point } from "@zag-js/types";
|
|
3
|
+
import { HintValue } from "./number-input.types.mjs";
|
|
4
4
|
export declare const getRootId: (ctx: Scope) => any;
|
|
5
5
|
export declare const getInputId: (ctx: Scope) => any;
|
|
6
6
|
export declare const getIncrementTriggerId: (ctx: Scope) => any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HintValue } from "./number-input.types.js";
|
|
2
1
|
import { Scope } from "@zag-js/core";
|
|
3
2
|
import { Point } from "@zag-js/types";
|
|
3
|
+
import { HintValue } from "./number-input.types.js";
|
|
4
4
|
export declare const getRootId: (ctx: Scope) => any;
|
|
5
5
|
export declare const getInputId: (ctx: Scope) => any;
|
|
6
6
|
export declare const getIncrementTriggerId: (ctx: Scope) => any;
|
|
@@ -2,13 +2,13 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
let _zag_js_core = require("@zag-js/core");
|
|
6
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
7
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
5
8
|
const require_cursor = require("./cursor.js");
|
|
6
9
|
const require_number_input_dom = require("./number-input.dom.js");
|
|
7
10
|
const require_number_input_translations = require("./number-input.translations.js");
|
|
8
11
|
const require_number_input_utils = require("./number-input.utils.js");
|
|
9
|
-
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
10
|
-
let _zag_js_utils = require("@zag-js/utils");
|
|
11
|
-
let _zag_js_core = require("@zag-js/core");
|
|
12
12
|
// src/number-input.machine.ts
|
|
13
13
|
const { choose, guards, createMachine } = (0, _zag_js_core.setup)();
|
|
14
14
|
const { not, and } = guards;
|
|
@@ -63,6 +63,9 @@ const machine = createMachine({
|
|
|
63
63
|
fieldsetDisabled: bindable(() => ({ defaultValue: false }))
|
|
64
64
|
};
|
|
65
65
|
},
|
|
66
|
+
refs() {
|
|
67
|
+
return { syncFrame: _zag_js_dom_query.AnimationFrame.create() };
|
|
68
|
+
},
|
|
66
69
|
computed: {
|
|
67
70
|
isRtl: ({ prop }) => prop("dir") === "rtl",
|
|
68
71
|
valueAsNumber: ({ context, computed, prop }) => require_number_input_utils.parseValue(context.get("value"), {
|
|
@@ -102,6 +105,7 @@ const machine = createMachine({
|
|
|
102
105
|
});
|
|
103
106
|
},
|
|
104
107
|
effects: ["trackFormControl"],
|
|
108
|
+
exit: ["cancelSyncFrame"],
|
|
105
109
|
on: {
|
|
106
110
|
"VALUE.SET": { actions: ["setRawValue"] },
|
|
107
111
|
"VALUE.CLEAR": { actions: ["clearValue"] },
|
|
@@ -455,15 +459,20 @@ const machine = createMachine({
|
|
|
455
459
|
valueAsNumber: computed("valueAsNumber")
|
|
456
460
|
});
|
|
457
461
|
},
|
|
458
|
-
syncInputElement({ context, event, computed, scope }) {
|
|
462
|
+
syncInputElement({ context, event, computed, scope, refs }) {
|
|
459
463
|
const value = event.type.endsWith("CHANGE") ? context.get("value") : computed("formattedValue");
|
|
460
464
|
const inputEl = require_number_input_dom.getInputEl(scope);
|
|
461
465
|
const sel = event.selection ?? require_cursor.recordCursor(inputEl, scope);
|
|
462
|
-
|
|
466
|
+
const scheduledText = inputEl?.value;
|
|
467
|
+
refs.get("syncFrame").request(() => {
|
|
468
|
+
if (inputEl && inputEl.value !== scheduledText) return;
|
|
463
469
|
(0, _zag_js_dom_query.setElementValue)(inputEl, value);
|
|
464
470
|
require_cursor.restoreCursor(inputEl, sel, scope);
|
|
465
471
|
});
|
|
466
472
|
},
|
|
473
|
+
cancelSyncFrame({ refs }) {
|
|
474
|
+
refs.get("syncFrame").cancel();
|
|
475
|
+
},
|
|
467
476
|
setFormattedValue({ context, computed, action }) {
|
|
468
477
|
context.set("value", computed("formattedValue"));
|
|
469
478
|
action(["syncInputElement"]);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { memo, setup } from "@zag-js/core";
|
|
2
|
+
import { AnimationFrame, addDomEvent, isSafari, observeAttributes, raf, requestPointerLock, setElementValue, trackFormControl } from "@zag-js/dom-query";
|
|
3
|
+
import { callAll, clampValue, decrementValue, incrementValue, isValueAtMax, isValueAtMin, isValueWithinRange, mergeWithDefault } from "@zag-js/utils";
|
|
1
4
|
import { recordCursor, restoreCursor } from "./cursor.mjs";
|
|
2
5
|
import { getCursorEl, getInputEl, getMousemoveValue, getPressedTriggerEl, preventTextSelection, setupVirtualCursor } from "./number-input.dom.mjs";
|
|
3
6
|
import { defaultTranslations } from "./number-input.translations.mjs";
|
|
4
7
|
import { createFormatter, createParser, formatValue, getDefaultStep, parseValue } from "./number-input.utils.mjs";
|
|
5
|
-
import { addDomEvent, isSafari, observeAttributes, raf, requestPointerLock, setElementValue, trackFormControl } from "@zag-js/dom-query";
|
|
6
|
-
import { callAll, clampValue, decrementValue, incrementValue, isValueAtMax, isValueAtMin, isValueWithinRange, mergeWithDefault } from "@zag-js/utils";
|
|
7
|
-
import { memo, setup } from "@zag-js/core";
|
|
8
8
|
// src/number-input.machine.ts
|
|
9
9
|
const { choose, guards, createMachine } = setup();
|
|
10
10
|
const { not, and } = guards;
|
|
@@ -59,6 +59,9 @@ const machine = createMachine({
|
|
|
59
59
|
fieldsetDisabled: bindable(() => ({ defaultValue: false }))
|
|
60
60
|
};
|
|
61
61
|
},
|
|
62
|
+
refs() {
|
|
63
|
+
return { syncFrame: AnimationFrame.create() };
|
|
64
|
+
},
|
|
62
65
|
computed: {
|
|
63
66
|
isRtl: ({ prop }) => prop("dir") === "rtl",
|
|
64
67
|
valueAsNumber: ({ context, computed, prop }) => parseValue(context.get("value"), {
|
|
@@ -98,6 +101,7 @@ const machine = createMachine({
|
|
|
98
101
|
});
|
|
99
102
|
},
|
|
100
103
|
effects: ["trackFormControl"],
|
|
104
|
+
exit: ["cancelSyncFrame"],
|
|
101
105
|
on: {
|
|
102
106
|
"VALUE.SET": { actions: ["setRawValue"] },
|
|
103
107
|
"VALUE.CLEAR": { actions: ["clearValue"] },
|
|
@@ -451,15 +455,20 @@ const machine = createMachine({
|
|
|
451
455
|
valueAsNumber: computed("valueAsNumber")
|
|
452
456
|
});
|
|
453
457
|
},
|
|
454
|
-
syncInputElement({ context, event, computed, scope }) {
|
|
458
|
+
syncInputElement({ context, event, computed, scope, refs }) {
|
|
455
459
|
const value = event.type.endsWith("CHANGE") ? context.get("value") : computed("formattedValue");
|
|
456
460
|
const inputEl = getInputEl(scope);
|
|
457
461
|
const sel = event.selection ?? recordCursor(inputEl, scope);
|
|
458
|
-
|
|
462
|
+
const scheduledText = inputEl?.value;
|
|
463
|
+
refs.get("syncFrame").request(() => {
|
|
464
|
+
if (inputEl && inputEl.value !== scheduledText) return;
|
|
459
465
|
setElementValue(inputEl, value);
|
|
460
466
|
restoreCursor(inputEl, sel, scope);
|
|
461
467
|
});
|
|
462
468
|
},
|
|
469
|
+
cancelSyncFrame({ refs }) {
|
|
470
|
+
refs.get("syncFrame").cancel();
|
|
471
|
+
},
|
|
463
472
|
setFormattedValue({ context, computed, action }) {
|
|
464
473
|
context.set("value", computed("formattedValue"));
|
|
465
474
|
action(["syncInputElement"]);
|
|
@@ -2,9 +2,10 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
let _zag_js_types = require("@zag-js/types");
|
|
5
6
|
let _zag_js_utils = require("@zag-js/utils");
|
|
6
7
|
// src/number-input.props.ts
|
|
7
|
-
const props = (0,
|
|
8
|
+
const props = (0, _zag_js_types.createProps)()([
|
|
8
9
|
"allowMouseWheel",
|
|
9
10
|
"allowOverflow",
|
|
10
11
|
"clampValueOnBlur",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IntlTranslations } from "./number-input.types.mjs";
|
|
2
1
|
import { Required } from "@zag-js/types";
|
|
2
|
+
import { IntlTranslations } from "./number-input.types.mjs";
|
|
3
3
|
export declare const defaultTranslations: Required<Pick<IntlTranslations, "incrementLabel" | "decrementLabel">>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IntlTranslations } from "./number-input.types.js";
|
|
2
1
|
import { Required } from "@zag-js/types";
|
|
2
|
+
import { IntlTranslations } from "./number-input.types.js";
|
|
3
3
|
export declare const defaultTranslations: Required<Pick<IntlTranslations, "incrementLabel" | "decrementLabel">>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnimationFrame } from "@zag-js/dom-query";
|
|
2
2
|
import { NumberParser } from "@internationalized/number";
|
|
3
|
+
import { EventObject, Machine, Service } from "@zag-js/core";
|
|
3
4
|
import { CommonProperties, LocaleProperties, PropTypes, RequiredBy } from "@zag-js/types";
|
|
4
5
|
export interface ValueChangeDetails {
|
|
5
6
|
value: string;
|
|
@@ -243,6 +244,9 @@ export interface NumberInputSchema {
|
|
|
243
244
|
props: RequiredBy<NumberInputProps, PropsWithDefault>;
|
|
244
245
|
context: PrivateContext;
|
|
245
246
|
computed: ComputedContext;
|
|
247
|
+
refs: {
|
|
248
|
+
syncFrame: AnimationFrame;
|
|
249
|
+
};
|
|
246
250
|
action: string;
|
|
247
251
|
event: EventObject;
|
|
248
252
|
guard: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { AnimationFrame } from "@zag-js/dom-query";
|
|
2
|
+
import { NumberParser } from "@internationalized/number";
|
|
1
3
|
import { EventObject, Machine, Service } from "@zag-js/core";
|
|
2
4
|
import { CommonProperties, LocaleProperties, PropTypes, RequiredBy } from "@zag-js/types";
|
|
3
|
-
import { NumberParser } from "@internationalized/number";
|
|
4
5
|
export interface ValueChangeDetails {
|
|
5
6
|
value: string;
|
|
6
7
|
valueAsNumber: number;
|
|
@@ -243,6 +244,9 @@ export interface NumberInputSchema {
|
|
|
243
244
|
props: RequiredBy<NumberInputProps, PropsWithDefault>;
|
|
244
245
|
context: PrivateContext;
|
|
245
246
|
computed: ComputedContext;
|
|
247
|
+
refs: {
|
|
248
|
+
syncFrame: AnimationFrame;
|
|
249
|
+
};
|
|
246
250
|
action: string;
|
|
247
251
|
event: EventObject;
|
|
248
252
|
guard: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NumberInputSchema } from "./number-input.types.mjs";
|
|
2
|
-
import { Params } from "@zag-js/core";
|
|
3
1
|
import { NumberParser } from "@internationalized/number";
|
|
2
|
+
import { Params } from "@zag-js/core";
|
|
3
|
+
import { NumberInputSchema } from "./number-input.types.mjs";
|
|
4
4
|
export declare const createFormatter: (locale: string, options?: Intl.NumberFormatOptions) => Intl.NumberFormat;
|
|
5
5
|
export declare const createParser: (locale: string, options?: Intl.NumberFormatOptions) => NumberParser;
|
|
6
6
|
type Ctx = Pick<Params<NumberInputSchema>, "prop" | "computed">;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NumberInputSchema } from "./number-input.types.js";
|
|
2
|
-
import { Params } from "@zag-js/core";
|
|
3
1
|
import { NumberParser } from "@internationalized/number";
|
|
2
|
+
import { Params } from "@zag-js/core";
|
|
3
|
+
import { NumberInputSchema } from "./number-input.types.js";
|
|
4
4
|
export declare const createFormatter: (locale: string, options?: Intl.NumberFormatOptions) => Intl.NumberFormat;
|
|
5
5
|
export declare const createParser: (locale: string, options?: Intl.NumberFormatOptions) => NumberParser;
|
|
6
6
|
type Ctx = Pick<Params<NumberInputSchema>, "prop" | "computed">;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"description": "Core logic for the number-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@internationalized/number": "3.6.9",
|
|
33
|
-
"@zag-js/anatomy": "1.
|
|
34
|
-
"@zag-js/core": "1.
|
|
35
|
-
"@zag-js/dom-query": "1.
|
|
36
|
-
"@zag-js/types": "1.
|
|
37
|
-
"@zag-js/utils": "1.
|
|
33
|
+
"@zag-js/anatomy": "1.49.0",
|
|
34
|
+
"@zag-js/core": "1.49.0",
|
|
35
|
+
"@zag-js/dom-query": "1.49.0",
|
|
36
|
+
"@zag-js/types": "1.49.0",
|
|
37
|
+
"@zag-js/utils": "1.49.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"clean-package": "2.2.0"
|