@zag-js/number-input 0.1.12 → 0.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/number-input",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "description": "Core logic for the number-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,21 +29,23 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.1.8",
33
- "@zag-js/types": "0.2.2"
32
+ "@zag-js/core": "0.1.9",
33
+ "@zag-js/types": "0.2.4"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.7",
37
- "@zag-js/number-utils": "0.1.2",
38
- "@zag-js/utils": "0.1.2"
36
+ "@zag-js/dom-utils": "0.1.10",
37
+ "@zag-js/form-utils": "0.1.0",
38
+ "@zag-js/number-utils": "0.1.3",
39
+ "@zag-js/utils": "0.1.3"
39
40
  },
40
41
  "scripts": {
41
- "build:fast": "zag build",
42
- "start": "zag build --watch",
43
- "build": "zag build --prod",
42
+ "build-fast": "tsup src/index.ts --format=esm,cjs",
43
+ "start": "pnpm build --watch",
44
+ "build": "tsup src/index.ts --format=esm,cjs --dts",
44
45
  "test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
45
46
  "lint": "eslint src --ext .ts,.tsx",
46
- "test:ci": "yarn test --ci --runInBand",
47
- "test:watch": "yarn test --watch --updateSnapshot"
47
+ "test-ci": "pnpm test --ci --runInBand",
48
+ "test-watch": "pnpm test --watch -u",
49
+ "typecheck": "tsc --noEmit"
48
50
  }
49
- }
51
+ }
@@ -1,23 +0,0 @@
1
- import type { NormalizeProps, PropTypes } from "@zag-js/types";
2
- import type { Send, State } from "./number-input.types";
3
- export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
4
- isFocused: boolean;
5
- isInvalid: boolean;
6
- isValueEmpty: boolean;
7
- value: string;
8
- valueAsNumber: number;
9
- setValue(value: string | number): void;
10
- clearValue(): void;
11
- increment(): void;
12
- decrement(): void;
13
- setToMax(): void;
14
- setToMin(): void;
15
- focus(): void;
16
- rootProps: T["element"];
17
- labelProps: T["label"];
18
- groupProps: T["element"];
19
- inputProps: T["input"];
20
- decrementButtonProps: T["button"];
21
- incrementButtonProps: T["button"];
22
- scrubberProps: T["element"];
23
- };
@@ -1,39 +0,0 @@
1
- import type { MachineContext as Ctx } from "./number-input.types";
2
- export declare const dom: {
3
- getRootNode: (ctx: {
4
- getRootNode?: () => Node | Document | ShadowRoot;
5
- }) => Document | ShadowRoot;
6
- getDoc: (ctx: {
7
- getRootNode?: () => Node | Document | ShadowRoot;
8
- }) => Document;
9
- getWin: (ctx: {
10
- getRootNode?: () => Node | Document | ShadowRoot;
11
- }) => Window & typeof globalThis;
12
- getActiveElement: (ctx: {
13
- getRootNode?: () => Node | Document | ShadowRoot;
14
- }) => HTMLElement;
15
- getById: <T_1 = HTMLElement>(ctx: {
16
- getRootNode?: () => Node | Document | ShadowRoot;
17
- }, id: string) => T_1;
18
- } & {
19
- getRootId: (ctx: Ctx) => string;
20
- getInputId: (ctx: Ctx) => string;
21
- getIncButtonId: (ctx: Ctx) => string;
22
- getDecButtonId: (ctx: Ctx) => string;
23
- getScrubberId: (ctx: Ctx) => string;
24
- getCursorId: (ctx: Ctx) => string;
25
- getLabelId: (ctx: Ctx) => string;
26
- getInputEl: (ctx: Ctx) => HTMLElement;
27
- getIncButtonEl: (ctx: Ctx) => HTMLButtonElement;
28
- getDecButtonEl: (ctx: Ctx) => HTMLButtonElement;
29
- getScrubberEl: (ctx: Ctx) => HTMLElement;
30
- getCursorEl: (ctx: Ctx) => HTMLElement;
31
- getMousementValue(ctx: Ctx, event: MouseEvent): {
32
- hint: string;
33
- point: {
34
- x: number;
35
- y: number;
36
- };
37
- };
38
- createVirtualCursor(ctx: Ctx): void;
39
- };
@@ -1,2 +0,0 @@
1
- import type { MachineContext, MachineState, UserDefinedContext } from "./number-input.types";
2
- export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,212 +0,0 @@
1
- import type { StateMachine as S } from "@zag-js/core";
2
- import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
3
- declare type ValidityState = "rangeUnderflow" | "rangeOverflow";
4
- declare type ElementIds = Partial<{
5
- root: string;
6
- label: string;
7
- input: string;
8
- incBtn: string;
9
- decBtn: string;
10
- scrubber: string;
11
- }>;
12
- declare type IntlMessages = {
13
- /**
14
- * Function that returns the human-readable value.
15
- * It is used to set the `aria-valuetext` property of the input
16
- */
17
- valueText?: (value: string) => string;
18
- /**
19
- * The label foe the increment button
20
- */
21
- incrementLabel: string;
22
- /**
23
- * The label for the decrement button
24
- */
25
- decrementLabel: string;
26
- };
27
- declare type PublicContext = DirectionProperty & CommonProperties & {
28
- /**
29
- * The ids of the elements in the number input. Useful for composition.
30
- */
31
- ids?: ElementIds;
32
- /**
33
- * The name attribute of the number input. Useful for form submission.
34
- */
35
- name?: string;
36
- /**
37
- * Whether the number input is disabled.
38
- */
39
- disabled?: boolean;
40
- /**
41
- * Whether the number input is readonly
42
- */
43
- readonly?: boolean;
44
- /**
45
- * Whether the number input value is invalid.
46
- */
47
- invalid?: boolean;
48
- /**
49
- * The pattern used to check the <input> element's value against
50
- *
51
- * @default
52
- * "[0-9]*(.[0-9]+)?"
53
- */
54
- pattern: string;
55
- /**
56
- * The value of the input
57
- */
58
- value: string;
59
- /**
60
- * The minimum value of the number input
61
- */
62
- min: number;
63
- /**
64
- * The maximum value of the number input
65
- */
66
- max: number;
67
- /**
68
- * The amount to increment or decrement the value by
69
- */
70
- step: number;
71
- /**
72
- * Whether to allow mouse wheel to change the value
73
- */
74
- allowMouseWheel?: boolean;
75
- /**
76
- * Whether to allow the value overflow the min/max range
77
- * @default true
78
- */
79
- allowOverflow: boolean;
80
- /**
81
- * Whether the pressed key should be allowed in the input.
82
- * The default behavior is to allow DOM floating point characters defined by /^[Ee0-9+\-.]$/
83
- */
84
- validateCharacter?: (char: string) => boolean;
85
- /**
86
- * Whether to clamp the value when the input loses focus (blur)
87
- * @default true
88
- */
89
- clampValueOnBlur: boolean;
90
- /**
91
- * Whether to focus input when the value changes
92
- * @default true
93
- */
94
- focusInputOnChange: boolean;
95
- /**
96
- * Specifies the localized strings that identifies the accessibility elements and their states
97
- */
98
- messages: IntlMessages;
99
- /**
100
- * If using a custom display format, this converts the custom format to a format `parseFloat` understands.
101
- */
102
- parse?: (value: string) => string;
103
- /**
104
- * If using a custom display format, this converts the default format to the custom format.
105
- */
106
- format?: (value: string) => string | number;
107
- /**
108
- * Hints at the type of data that might be entered by the user. It also determines
109
- * the type of keyboard shown to the user on mobile devices
110
- * @default "decimal"
111
- */
112
- inputMode: "text" | "tel" | "numeric" | "decimal";
113
- /**
114
- * Function invoked when the value changes
115
- */
116
- onChange?: (details: {
117
- value: string;
118
- valueAsNumber: number;
119
- }) => void;
120
- /**
121
- * Function invoked when the value overflows or underflows the min/max range
122
- */
123
- onInvalid?: (details: {
124
- reason: ValidityState;
125
- value: string;
126
- valueAsNumber: number;
127
- }) => void;
128
- /**
129
- * The minimum number of fraction digits to use. Possible values are from 0 to 20
130
- */
131
- minFractionDigits?: number;
132
- /**
133
- * The maximum number of fraction digits to use. Possible values are from 0 to 20;
134
- */
135
- maxFractionDigits?: number;
136
- };
137
- export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
138
- declare type ComputedContext = Readonly<{
139
- /**
140
- * @computed
141
- * The value of the input as a number
142
- */
143
- valueAsNumber: number;
144
- /**
145
- * @computed
146
- * Whether the value is at the min
147
- */
148
- isAtMin: boolean;
149
- /**
150
- * @computed
151
- * Whether the value is at the max
152
- */
153
- isAtMax: boolean;
154
- /**
155
- * @computed
156
- * Whether the value is out of the min/max range
157
- */
158
- isOutOfRange: boolean;
159
- /**
160
- * @computed
161
- * Whether the value is empty
162
- */
163
- isValueEmpty: boolean;
164
- /**
165
- * @computed
166
- * Whether the increment button is enabled
167
- */
168
- canIncrement: boolean;
169
- /**
170
- * @computed
171
- * Whether the decrement button is enabled
172
- */
173
- canDecrement: boolean;
174
- /**
175
- * @computed
176
- * The `aria-valuetext` attribute of the input
177
- */
178
- valueText: string | undefined;
179
- /**
180
- * @computed
181
- * The formatted value of the input
182
- */
183
- formattedValue: string;
184
- /**
185
- * @computed
186
- * Whether the writing direction is RTL
187
- */
188
- isRtl: boolean;
189
- }>;
190
- declare type PrivateContext = Context<{
191
- /**
192
- * @internal
193
- * The hint that determines if we're incrementing or decrementing
194
- */
195
- hint: "increment" | "decrement" | "set" | null;
196
- /**
197
- * @internal
198
- * The scrubber cursor position
199
- */
200
- scrubberCursorPoint: {
201
- x: number;
202
- y: number;
203
- } | null;
204
- }>;
205
- export declare type MachineContext = PublicContext & PrivateContext & ComputedContext;
206
- export declare type MachineState = {
207
- value: "unknown" | "idle" | "focused" | "spinning" | "before:spin" | "scrubbing";
208
- tags: "focus";
209
- };
210
- export declare type State = S.State<MachineContext, MachineState>;
211
- export declare type Send = S.Send<S.AnyEventObject>;
212
- export {};
@@ -1,13 +0,0 @@
1
- import type { JSX } from "@zag-js/types";
2
- import type { MachineContext as Ctx } from "./number-input.types";
3
- export declare const utils: {
4
- isValidNumericEvent: (ctx: Ctx, event: JSX.KeyboardEvent) => boolean;
5
- isFloatingPoint: (v: string) => boolean;
6
- sanitize: (ctx: Ctx, value: string) => string;
7
- increment: (ctx: Ctx, step?: number) => string;
8
- decrement: (ctx: Ctx, step?: number) => string;
9
- clamp: (ctx: Ctx) => string;
10
- parse: (ctx: Ctx, value: string) => string;
11
- format: (ctx: Ctx, value: string | number) => string | number;
12
- round: (ctx: Ctx) => string;
13
- };