@zag-js/number-input 0.1.11 → 0.1.14

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