@ilokesto/form 2.0.1 → 2.0.3
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/README.ko.md +40 -924
- package/README.md +39 -924
- package/dist/{FormInput-DuT7QFe-.d.ts → FormInput-BpDWf4hF.d.ts} +3 -0
- package/dist/chunk-M7Y4OJPP.js +2166 -0
- package/dist/chunk-M7Y4OJPP.js.map +1 -0
- package/dist/{chunk-JK644RR7.js → chunk-WO5TIXCR.js} +3 -3
- package/dist/chunk-WO5TIXCR.js.map +1 -0
- package/dist/index.d.ts +194 -23
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +104 -2
- package/dist/react/index.js +2 -2
- package/dist/react/index.js.map +1 -1
- package/dist/solid/index.d.ts +103 -2
- package/dist/solid/index.js +2 -2
- package/dist/solid/index.js.map +1 -1
- package/dist/svelte/index.d.ts +75 -2
- package/dist/svelte/index.js +2 -2
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/index.d.ts +103 -2
- package/dist/vue/index.js +2 -2
- package/dist/vue/index.js.map +1 -1
- package/package.json +36 -23
- package/dist/chunk-4F4SAGQ5.js +0 -1465
- package/dist/chunk-4F4SAGQ5.js.map +0 -1
- package/dist/chunk-JK644RR7.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { F as Form, C as CreateFormOptions, a as FormState, b as FieldPathInput,
|
|
|
2
2
|
export { g as StandardSchemaV1 } from './types-DBlvL6AC.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* @description Coordinates framework-neutral field, array, validation, and queued submission commands over one store.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const form = new CreateForm({ defaultValues: { email: "" } });
|
|
9
|
+
* form.setValue("email", "Ada");
|
|
10
|
+
* ```
|
|
10
11
|
*/
|
|
11
12
|
declare class CreateForm<TValues> implements Form<TValues> {
|
|
12
13
|
/** form의 단일 상태 저장소. 모든 값/필드 메타데이터/배열 키는 이 store를 통해 읽고 쓴다. */
|
|
@@ -18,40 +19,210 @@ declare class CreateForm<TValues> implements Form<TValues> {
|
|
|
18
19
|
/** submitCount 증가, submit validation, onValid/onInvalid 호출을 담당한다. */
|
|
19
20
|
private readonly submitter;
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* @description Create a form and connect its state, array, validation, and submission collaborators.
|
|
23
|
+
* @param {CreateFormOptions<TValues>} options - Default values, optional form schema, and automatic validation triggers.
|
|
24
|
+
* @param {TValues} options.defaultValues - Initial values and the baseline used for dirty checks and reset.
|
|
25
|
+
* @param {StandardSchemaV1<unknown, TValues> | undefined} [options.schema] - Standard Schema validator; a field-local schema takes precedence over the form schema.
|
|
26
|
+
* @param {StandardSchemaV1.Props<unknown, TValues>} [options.schema.~standard] - Standard Schema version, vendor, type metadata, and validation entry point.
|
|
27
|
+
* @param {1} [options.schema.~standard.version] - Standard Schema major version, which must be 1.
|
|
28
|
+
* @param {string} [options.schema.~standard.vendor] - Name of the schema library implementation.
|
|
29
|
+
* @param {StandardSchemaV1.Types<unknown, TValues> | undefined} [options.schema.~standard.types] - Optional compile-time input and output metadata.
|
|
30
|
+
* @param {unknown} [options.schema.~standard.types.input] - Schema input type metadata.
|
|
31
|
+
* @param {TValues} [options.schema.~standard.types.output] - Schema output type metadata.
|
|
32
|
+
* @param {(value: unknown, options?: StandardSchemaV1.Options | undefined) => StandardSchemaV1.Result<TValues> | Promise<StandardSchemaV1.Result<TValues>>} [options.schema.~standard.validate] - Validate unknown input and return accepted values or issues, synchronously or asynchronously.
|
|
33
|
+
* @param {StandardSchemaV1.Options | undefined} [options.schemaOptions] - Options forwarded to the Standard Schema validator.
|
|
34
|
+
* @param {Record<string, unknown> | undefined} [options.schemaOptions.libraryOptions] - Library-specific validation options; keys are defined by the schema library.
|
|
35
|
+
* @param {readonly ValidationTrigger[] | undefined} [options.validateOn] - Triggers that run automatic validation; defaults to submit.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const form = new CreateForm({ defaultValues: { email: "" } });
|
|
39
|
+
* ```
|
|
24
40
|
*/
|
|
25
41
|
constructor(options: CreateFormOptions<TValues>);
|
|
26
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* @description Read the current immutable form snapshot without cloning it.
|
|
44
|
+
* @returns {Readonly<FormState<TValues>>} Current read-only snapshot; callers must not mutate it.
|
|
45
|
+
* - defaultValues `TValues` - Initial values and the baseline used for dirty checks and reset.
|
|
46
|
+
* - fields `Record<string, FieldState<unknown>>` - Field snapshots indexed by normalized path keys.
|
|
47
|
+
* - submitCount `number` - Number of submission attempts started by the form.
|
|
48
|
+
* - isSubmitting `boolean` - Whether queued validation or a submit callback is still pending.
|
|
49
|
+
* - isSubmitted `boolean` - Whether a submission has completed at least once.
|
|
50
|
+
* - isSubmitSuccessful `boolean` - Whether the latest completed submission reached a successful valid callback.
|
|
51
|
+
* - arrayKeys `ArrayKeys` - Stable rendering keys indexed by array path.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* form.getState();
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
27
57
|
getState(): Readonly<FormState<TValues>>;
|
|
28
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* @description Subscribe to form state changes and return the callback that unsubscribes this listener.
|
|
60
|
+
* @param {() => void} listener - Callback invoked synchronously after a state change.
|
|
61
|
+
* @returns {() => void} Cleanup callback for this subscription or registration.
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* form.subscribe(() => render());
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
29
67
|
subscribe(listener: () => void): () => void;
|
|
30
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* @description Register a field-local schema; the returned cleanup removes only this registration if it is still current.
|
|
70
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
71
|
+
* @param {FieldSchemaOptions} options - Field-local schema and validation settings.
|
|
72
|
+
* @param {StandardSchemaV1<unknown, unknown>} options.schema - Standard Schema validator; a field-local schema takes precedence over the form schema.
|
|
73
|
+
* @param {StandardSchemaV1.Props<unknown, unknown>} options.schema.~standard - Standard Schema version, vendor, type metadata, and validation entry point.
|
|
74
|
+
* @param {1} options.schema.~standard.version - Standard Schema major version, which must be 1.
|
|
75
|
+
* @param {string} options.schema.~standard.vendor - Name of the schema library implementation.
|
|
76
|
+
* @param {StandardSchemaV1.Types<unknown, unknown> | undefined} [options.schema.~standard.types] - Optional compile-time input and output metadata.
|
|
77
|
+
* @param {unknown} [options.schema.~standard.types.input] - Schema input type metadata.
|
|
78
|
+
* @param {unknown} [options.schema.~standard.types.output] - Schema output type metadata.
|
|
79
|
+
* @param {(value: unknown, options?: StandardSchemaV1.Options | undefined) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>} options.schema.~standard.validate - Validate unknown input and return accepted values or issues, synchronously or asynchronously.
|
|
80
|
+
* @param {StandardSchemaV1.Options | undefined} [options.schemaOptions] - Options forwarded to the Standard Schema validator.
|
|
81
|
+
* @param {Record<string, unknown> | undefined} [options.schemaOptions.libraryOptions] - Library-specific validation options; keys are defined by the schema library.
|
|
82
|
+
* @returns {() => void} Cleanup callback for this subscription or registration.
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* form.registerFieldSchema(["email"], { schema });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
31
88
|
registerFieldSchema(path: FieldPathInput, options: FieldSchemaOptions): () => void;
|
|
32
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* @description Read field metadata and use a default snapshot when the field is not present.
|
|
91
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
92
|
+
* @returns {Readonly<FieldState>} Field snapshot, with a default shape when the leaf field is absent.
|
|
93
|
+
* - value `unknown` - Current field value.
|
|
94
|
+
* - errors `FormError[]` - Current validation errors for the field.
|
|
95
|
+
* - touched `boolean` - Whether the field has blurred at least once.
|
|
96
|
+
* - dirty `boolean` - Whether the current value differs from its default by Object.is.
|
|
97
|
+
* - modified `boolean` - Whether a user-originated write has changed this field.
|
|
98
|
+
* - isFocused `boolean` - Whether focus has been recorded without a subsequent blur.
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* form.getFieldState(["email"]);
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
33
104
|
getFieldState(path: FieldPathInput): Readonly<FieldState>;
|
|
34
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* @description Read only the current value of the selected field.
|
|
107
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
108
|
+
* @returns {unknown} Stored field value, or undefined when the field has no value.
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* form.getValue(["email"]);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
35
114
|
getValue(path: FieldPathInput): unknown;
|
|
36
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* @description Reconstruct the nested values object from leaf fields and array containers.
|
|
117
|
+
* @returns {TValues} Nested values reconstructed in the shape of the supplied defaults.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* form.getValues();
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
37
123
|
getValues(): TValues;
|
|
38
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* @description Write a field value, compare dirty state with its default, and mark user-originated changes as modified. Start change validation when explicitly requested or configured.
|
|
126
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
127
|
+
* @param {unknown} value - Value to store or inspect.
|
|
128
|
+
* @param {SetValueOptions} [options] - Write origin and optional immediate validation request.
|
|
129
|
+
* @param {"user" | "program" | undefined} [options.source] - Write origin; user writes mark the field as modified.
|
|
130
|
+
* @param {boolean | undefined} [options.validate] - Whether to start validation immediately after this write.
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* form.setValue(["email"], "Ada", { source: "user" });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
39
136
|
setValue(path: FieldPathInput, value: unknown, options?: SetValueOptions): void;
|
|
40
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* @description Clear focus and mark touched before running configured blur validation; return true when validation is disabled.
|
|
139
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
140
|
+
* @returns {Promise<boolean>} Promise resolving true when validation is disabled or the current field result is valid.
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* await form.blur(["email"]);
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
41
146
|
blur(path: FieldPathInput): Promise<boolean>;
|
|
42
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
* @description Record focus for this field without modifying its value.
|
|
149
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* form.focus(["email"]);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
43
155
|
focus(path: FieldPathInput): void;
|
|
44
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* @description Replace the selected field error list without running validation.
|
|
158
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
159
|
+
* @param {readonly FormError[]} errors - Current validation errors for the field.
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* form.setErrors(["email"], errors);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
45
165
|
setErrors(path: FieldPathInput, errors: readonly FormError[]): void;
|
|
46
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* @description Clear selected fields or all fields when no paths are provided.
|
|
168
|
+
* @param {FieldPathInput[]} paths - Fields to target; no paths means all fields.
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* form.clearErrors("email");
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
47
174
|
clearErrors(...paths: FieldPathInput[]): void;
|
|
48
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* @description Run manual schema validation for selected paths or the whole form when no paths are supplied.
|
|
177
|
+
* @param {FieldPathInput[]} paths - Fields to target; no paths means all fields.
|
|
178
|
+
* @returns {Promise<boolean>} Promise resolving true only when the targeted current validation result is valid.
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* await form.trigger("email");
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
49
184
|
trigger(...paths: FieldPathInput[]): Promise<boolean>;
|
|
50
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* @description Create commands for an array field that keep values, stable keys, and child state aligned.
|
|
187
|
+
* @param {FieldPathInput} path - Literal field name or tuple path; strings are not split on dots.
|
|
188
|
+
* @returns {FormArray} Array commands sharing the current form store and item-key generator.
|
|
189
|
+
* - keys `() => readonly string[]` - Stable item keys in array order.
|
|
190
|
+
* - insert `(index: number, value: unknown) => void` - Insert a value at a bounded array index.
|
|
191
|
+
* - push `(value: unknown) => void` - Append a value and allocate a stable item key.
|
|
192
|
+
* - remove `(index: number) => void` - Remove the indexed item and rebase surviving child fields.
|
|
193
|
+
* - move `(fromIndex: number, toIndex: number) => void` - Move an item while preserving its key and child metadata.
|
|
194
|
+
* - swap `(leftIndex: number, rightIndex: number) => void` - Swap item positions while preserving keys and child metadata.
|
|
195
|
+
* - replace `(values: readonly unknown[]) => void` - Replace all array items and regenerate their keys and child state.
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* form.array("users").push({ email: "" });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
51
201
|
array(path: FieldPathInput): FormArray;
|
|
52
|
-
/**
|
|
202
|
+
/**
|
|
203
|
+
* @description Reinitialize values and metadata, optionally retaining dirty values, errors, touched flags, and submission state.
|
|
204
|
+
* @param {TValues | undefined} [values] - Replacement or current form values.
|
|
205
|
+
* @param {ResetOptions | undefined} [options] - State preservation flags for this reset.
|
|
206
|
+
* @param {boolean | undefined} [options.keepDirtyValues] - Preserve current values and modified flags of dirty fields.
|
|
207
|
+
* @param {boolean | undefined} [options.keepErrors] - Preserve errors on surviving field paths.
|
|
208
|
+
* @param {boolean | undefined} [options.keepTouched] - Preserve touched flags on surviving field paths.
|
|
209
|
+
* @param {boolean | undefined} [options.keepSubmitState] - Preserve submission counters and lifecycle flags.
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* form.reset({ email: "Ada" }, { keepTouched: true });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
53
215
|
reset(values?: TValues, options?: ResetOptions): void;
|
|
54
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* @description Queue a submission, retry stale validation, and return the valid callback result or undefined after invalid validation.
|
|
218
|
+
* @param {(values: TValues) => TResult | Promise<TResult>} onValid - Callback receiving current values after successful validation.
|
|
219
|
+
* @param {((fields: Readonly<Record<PathKey, FieldState>>) => void) | undefined} [onInvalid] - Callback receiving field snapshots when validation fails.
|
|
220
|
+
* @returns {Promise<TResult | undefined>} Promise of the valid callback result, or undefined when validation fails; callback errors reject.
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* await form.submit(values => save(values), fields => showErrors(fields));
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
55
226
|
submit<TResult>(onValid: (values: TValues) => TResult | Promise<TResult>, onInvalid?: (fields: Readonly<Record<PathKey, FieldState>>) => void): Promise<TResult | undefined>;
|
|
56
227
|
}
|
|
57
228
|
|
package/dist/index.js
CHANGED
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { b as FieldPathInput, d as FieldState, h as FieldPathValue, F as Form, e as FormError, a as FormState } from '../types-DBlvL6AC.js';
|
|
2
2
|
import { ChangeEventHandler, FocusEventHandler, SelectHTMLAttributes, TextareaHTMLAttributes, InputHTMLAttributes, FormEvent } from 'react';
|
|
3
|
-
import { R as ReactiveFormOptions, a as RegisterOptions, S as SubmitValidHandler, b as SubmitInvalidHandler, c as SubmitHandler } from '../FormInput-
|
|
3
|
+
import { R as ReactiveFormOptions, a as RegisterOptions, S as SubmitValidHandler, b as SubmitInvalidHandler, c as SubmitHandler } from '../FormInput-BpDWf4hF.js';
|
|
4
4
|
|
|
5
5
|
/** React adapter가 form 생성 옵션에 더해 reactive external values를 받을 때 쓰는 옵션이다. */
|
|
6
6
|
type ReactFormOptions<TValues> = ReactiveFormOptions<TValues, TValues | undefined>;
|
|
@@ -9,31 +9,45 @@ type InputType = InputHTMLAttributes<HTMLInputElement>['type'];
|
|
|
9
9
|
type SelectValue = SelectHTMLAttributes<HTMLSelectElement>['value'];
|
|
10
10
|
type TextareaValue = TextareaHTMLAttributes<HTMLTextAreaElement>['value'];
|
|
11
11
|
type BindingHandlers<TElement extends HTMLElement> = {
|
|
12
|
+
/** Forward change events, including checked and selection state, into the form. */
|
|
12
13
|
onChange: ChangeEventHandler<TElement>;
|
|
14
|
+
/** Clear focus and mark the field touched. */
|
|
13
15
|
onBlur: FocusEventHandler<TElement>;
|
|
16
|
+
/** Record focus for this field. */
|
|
14
17
|
onFocus: FocusEventHandler<TElement>;
|
|
15
18
|
};
|
|
16
19
|
/** `<input {...useRegister(...)} />`에 바로 spread할 수 있는 기본 binding props다. */
|
|
17
20
|
type InputRegisterProps = BindingHandlers<HTMLInputElement> & {
|
|
21
|
+
/** DOM name string; tuple paths are JSON-serialized. */
|
|
18
22
|
name: string;
|
|
23
|
+
/** Input kind; checkbox and radio use checked semantics, otherwise defaults to text. */
|
|
19
24
|
type: InputType;
|
|
25
|
+
/** Current field value. */
|
|
20
26
|
value?: InputValue;
|
|
27
|
+
/** Whether this checkbox or radio represents the current field value. */
|
|
21
28
|
checked?: boolean;
|
|
22
29
|
};
|
|
23
30
|
/** `useRegister<HTMLSelectElement>(...)`로 좁혀 `<select>`에 spread할 수 있는 binding props다. */
|
|
24
31
|
type SelectRegisterProps = BindingHandlers<HTMLSelectElement> & {
|
|
32
|
+
/** DOM name string; tuple paths are JSON-serialized. */
|
|
25
33
|
name: string;
|
|
34
|
+
/** Current field value. */
|
|
26
35
|
value?: SelectValue;
|
|
27
36
|
};
|
|
28
37
|
/** `useRegister<HTMLTextAreaElement>(...)`로 좁혀 `<textarea>`에 spread할 수 있는 binding props다. */
|
|
29
38
|
type TextareaRegisterProps = BindingHandlers<HTMLTextAreaElement> & {
|
|
39
|
+
/** DOM name string; tuple paths are JSON-serialized. */
|
|
30
40
|
name: string;
|
|
41
|
+
/** Current field value. */
|
|
31
42
|
value?: TextareaValue;
|
|
32
43
|
};
|
|
33
44
|
/** DOM-compatible custom component용 escape-hatch binding props다. */
|
|
34
45
|
type CustomRegisterProps<TElement extends HTMLElement = HTMLElement> = BindingHandlers<TElement> & {
|
|
46
|
+
/** DOM name string; tuple paths are JSON-serialized. */
|
|
35
47
|
name: string;
|
|
48
|
+
/** Current field value. */
|
|
36
49
|
value?: unknown;
|
|
50
|
+
/** Whether this checkbox or radio represents the current field value. */
|
|
37
51
|
checked?: boolean;
|
|
38
52
|
};
|
|
39
53
|
type RegisterElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLElement;
|
|
@@ -42,27 +56,44 @@ type RegisterPropsForElement<TElement extends RegisterElement> = TElement extend
|
|
|
42
56
|
type RegisterProps = RegisterPropsForElement<RegisterElement>;
|
|
43
57
|
/** 한 field의 binding, value, meta, setter를 함께 제공한다. */
|
|
44
58
|
type UseFieldReturn<TProps extends RegisterProps = InputRegisterProps> = {
|
|
59
|
+
/** Binding properties to spread onto the matching DOM control. */
|
|
45
60
|
props: TProps;
|
|
61
|
+
/** Current field value. */
|
|
46
62
|
value: unknown;
|
|
63
|
+
/** Replace the field value as a programmatic write. */
|
|
47
64
|
setValue: (value: unknown) => void;
|
|
65
|
+
/** Current validation errors for the field. */
|
|
48
66
|
errors: FormError[];
|
|
67
|
+
/** Whether the current value differs from its default by Object.is. */
|
|
49
68
|
dirty: boolean;
|
|
69
|
+
/** Whether the field has blurred at least once. */
|
|
50
70
|
touched: boolean;
|
|
51
71
|
};
|
|
52
72
|
/** 한 field의 value와 meta를 form values 타입과 path에서 추론해 반환한다. */
|
|
53
73
|
type UseFieldStateReturn<TValues, TName extends FieldPathInput> = Readonly<FieldState<FieldPathValue<TValues, TName>>>;
|
|
54
74
|
/** form 전체 상태에서 React UI가 자주 쓰는 aggregate state다. */
|
|
55
75
|
type UseFormStateReturn<TValues> = {
|
|
76
|
+
/** Current immutable form snapshot. */
|
|
56
77
|
state: Readonly<FormState<TValues>>;
|
|
78
|
+
/** Nonempty validation error lists indexed by normalized field path. */
|
|
57
79
|
errors: Record<string, FormError[]>;
|
|
80
|
+
/** Normalized paths whose fields are dirty. */
|
|
58
81
|
dirtyFields: Record<string, true>;
|
|
82
|
+
/** Normalized paths whose fields are touched. */
|
|
59
83
|
touchedFields: Record<string, true>;
|
|
84
|
+
/** First focused field in entry order, or null; not necessarily the last focused field. */
|
|
60
85
|
focusedField: string | null;
|
|
86
|
+
/** Whether at least one field is dirty. */
|
|
61
87
|
isDirty: boolean;
|
|
88
|
+
/** Whether no field currently has recorded errors. */
|
|
62
89
|
isValid: boolean;
|
|
90
|
+
/** Whether queued validation or a submit callback is still pending. */
|
|
63
91
|
isSubmitting: boolean;
|
|
92
|
+
/** Whether a submission has completed at least once. */
|
|
64
93
|
isSubmitted: boolean;
|
|
94
|
+
/** Whether the latest completed submission reached a successful valid callback. */
|
|
65
95
|
isSubmitSuccessful: boolean;
|
|
96
|
+
/** Number of submission attempts started by the form. */
|
|
66
97
|
submitCount: number;
|
|
67
98
|
};
|
|
68
99
|
type RegisterPropsList<TElement extends RegisterElement, TOptions extends readonly RegisterOptions[]> = {
|
|
@@ -70,17 +101,88 @@ type RegisterPropsList<TElement extends RegisterElement, TOptions extends readon
|
|
|
70
101
|
};
|
|
71
102
|
/** `useForm(form)`이 반환하는 form-bound hook 모음이다. */
|
|
72
103
|
type ReactForm<TValues> = {
|
|
104
|
+
/** Core form instance shared by all bound helpers. */
|
|
73
105
|
form: Form<TValues>;
|
|
106
|
+
/** Create one binding or an ordered list from single, array, or variadic options. */
|
|
74
107
|
useRegister<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): RegisterPropsForElement<TElement>;
|
|
108
|
+
/** Create one binding or an ordered list from single, array, or variadic options. */
|
|
75
109
|
useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(options: TOptions): RegisterPropsList<TElement, TOptions>;
|
|
110
|
+
/** Create one binding or an ordered list from single, array, or variadic options. */
|
|
76
111
|
useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): RegisterPropsList<TElement, TOptions>;
|
|
112
|
+
/** Create field bindings, reactive value and metadata, and a setter. */
|
|
77
113
|
useField<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): UseFieldReturn<RegisterPropsForElement<TElement>>;
|
|
114
|
+
/** Subscribe to a path-typed field snapshot. */
|
|
78
115
|
useFieldState<const TName extends FieldPathInput>(name: TName): UseFieldStateReturn<TValues, TName>;
|
|
116
|
+
/** Subscribe to form-wide errors and lifecycle aggregates. */
|
|
79
117
|
useFormState(): UseFormStateReturn<TValues>;
|
|
118
|
+
/** Create an event handler that prevents default submission before validating. */
|
|
80
119
|
handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<FormEvent<HTMLFormElement>, TResult>;
|
|
81
120
|
};
|
|
82
121
|
|
|
83
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* @description Bind framework helpers to an existing form or create one from options; defined external-value reference changes reset it.
|
|
124
|
+
* @param {Form<TValues>} form - Core form instance shared by all bound helpers.
|
|
125
|
+
* @param {() => Readonly<FormState<TValues>>} form.getState - Read the current immutable form snapshot.
|
|
126
|
+
* @param {(listener: () => void) => () => void} form.subscribe - Subscribe to state changes and return an unsubscribe callback.
|
|
127
|
+
* @param {(path: FieldPathInput, options: FieldSchemaOptions) => () => void} form.registerFieldSchema - Register an overriding field-local validator and return its guarded cleanup.
|
|
128
|
+
* @param {(path: FieldPathInput) => Readonly<FieldState>} form.getFieldState - Read field metadata, using a default snapshot for an unknown field.
|
|
129
|
+
* @param {(path: FieldPathInput) => unknown} form.getValue - Read the current value of one field.
|
|
130
|
+
* @param {() => TValues} form.getValues - Reconstruct nested values from fields and array containers.
|
|
131
|
+
* @param {(path: FieldPathInput, value: unknown, options?: SetValueOptions) => void} form.setValue - Write a field with configurable user or program origin and optional immediate validation.
|
|
132
|
+
* @param {(path: FieldPathInput) => Promise<boolean>} form.blur - Clear focus, mark touched, and run configured blur validation.
|
|
133
|
+
* @param {(path: FieldPathInput) => void} form.focus - Record focus for the selected field.
|
|
134
|
+
* @param {(path: FieldPathInput, errors: readonly FormError[]) => void} form.setErrors - Replace all errors for the selected field.
|
|
135
|
+
* @param {(...paths: FieldPathInput[]) => void} form.clearErrors - Clear selected fields, or all field errors when no paths are supplied.
|
|
136
|
+
* @param {(...paths: FieldPathInput[]) => Promise<boolean>} form.trigger - Run manual validation for selected paths or the entire form.
|
|
137
|
+
* @param {(path: FieldPathInput) => FormArray} form.array - Return commands that keep array values, keys, and child metadata aligned.
|
|
138
|
+
* @param {(values?: TValues | undefined, options?: ResetOptions) => void} form.reset - Reinitialize from default or replacement values with optional preservation flags.
|
|
139
|
+
* @param {<TResult>(onValid: (values: TValues) => TResult | Promise<TResult>, onInvalid?: (fields: Readonly<Record<PathKey, FieldState>>) => void) => Promise<TResult | undefined>} form.submit - Queue validation and dispatch the valid or invalid callback.
|
|
140
|
+
* @param {ReactFormOptions<TValues>} options - Default values, optional form schema, and automatic validation triggers.
|
|
141
|
+
* @param {TValues} options.defaultValues - Initial values and the baseline used for dirty checks and reset.
|
|
142
|
+
* @param {StandardSchemaV1<unknown, TValues> | undefined} [options.schema] - Standard Schema validator; a field-local schema takes precedence over the form schema.
|
|
143
|
+
* @param {StandardSchemaV1.Props<unknown, TValues>} [options.schema.~standard] - Standard Schema version, vendor, type metadata, and validation entry point.
|
|
144
|
+
* @param {1} [options.schema.~standard.version] - Standard Schema major version, which must be 1.
|
|
145
|
+
* @param {string} [options.schema.~standard.vendor] - Name of the schema library implementation.
|
|
146
|
+
* @param {StandardSchemaV1.Types<unknown, TValues> | undefined} [options.schema.~standard.types] - Optional compile-time input and output metadata.
|
|
147
|
+
* @param {unknown} [options.schema.~standard.types.input] - Schema input type metadata.
|
|
148
|
+
* @param {TValues} [options.schema.~standard.types.output] - Schema output type metadata.
|
|
149
|
+
* @param {(value: unknown, options?: StandardSchemaV1.Options | undefined) => StandardSchemaV1.Result<TValues> | Promise<StandardSchemaV1.Result<TValues>>} [options.schema.~standard.validate] - Validate unknown input and return accepted values or issues, synchronously or asynchronously.
|
|
150
|
+
* @param {StandardSchemaV1.Options | undefined} [options.schemaOptions] - Options forwarded to the Standard Schema validator.
|
|
151
|
+
* @param {Record<string, unknown> | undefined} [options.schemaOptions.libraryOptions] - Library-specific validation options; keys are defined by the schema library.
|
|
152
|
+
* @param {readonly ValidationTrigger[] | undefined} [options.validateOn] - Triggers that run automatic validation; defaults to submit.
|
|
153
|
+
* @param {TValues | undefined} [options.values] - Replacement values; defined reference changes reset the form.
|
|
154
|
+
* @param {ResetOptions | undefined} [options.resetOptions] - State preservation policy for external-value resets.
|
|
155
|
+
* @param {boolean | undefined} [options.resetOptions.keepDirtyValues] - Preserve current values and modified flags of dirty fields.
|
|
156
|
+
* @param {boolean | undefined} [options.resetOptions.keepErrors] - Preserve errors on surviving field paths.
|
|
157
|
+
* @param {boolean | undefined} [options.resetOptions.keepTouched] - Preserve touched flags on surviving field paths.
|
|
158
|
+
* @param {boolean | undefined} [options.resetOptions.keepSubmitState] - Preserve submission counters and lifecycle flags.
|
|
159
|
+
* @returns {ReactForm<TValues>} Core form and bound framework helpers sharing its state and lifecycle.
|
|
160
|
+
* - form `Form<TValues>` - Core form instance shared by all bound helpers.
|
|
161
|
+
* : form.getState `() => Readonly<FormState<TValues>>` - Read the current immutable form snapshot.
|
|
162
|
+
* : form.subscribe `(listener: () => void) => () => void` - Subscribe to state changes and return an unsubscribe callback.
|
|
163
|
+
* : form.registerFieldSchema `(path: FieldPathInput, options: FieldSchemaOptions) => () => void` - Register an overriding field-local validator and return its guarded cleanup.
|
|
164
|
+
* : form.getFieldState `(path: FieldPathInput) => Readonly<FieldState>` - Read field metadata, using a default snapshot for an unknown field.
|
|
165
|
+
* : form.getValue `(path: FieldPathInput) => unknown` - Read the current value of one field.
|
|
166
|
+
* : form.getValues `() => TValues` - Reconstruct nested values from fields and array containers.
|
|
167
|
+
* : form.setValue `(path: FieldPathInput, value: unknown, options?: SetValueOptions) => void` - Write a field with configurable user or program origin and optional immediate validation.
|
|
168
|
+
* : form.blur `(path: FieldPathInput) => Promise<boolean>` - Clear focus, mark touched, and run configured blur validation.
|
|
169
|
+
* : form.focus `(path: FieldPathInput) => void` - Record focus for the selected field.
|
|
170
|
+
* : form.setErrors `(path: FieldPathInput, errors: readonly FormError[]) => void` - Replace all errors for the selected field.
|
|
171
|
+
* : form.clearErrors `(...paths: FieldPathInput[]) => void` - Clear selected fields, or all field errors when no paths are supplied.
|
|
172
|
+
* : form.trigger `(...paths: FieldPathInput[]) => Promise<boolean>` - Run manual validation for selected paths or the entire form.
|
|
173
|
+
* : form.array `(path: FieldPathInput) => FormArray` - Return commands that keep array values, keys, and child metadata aligned.
|
|
174
|
+
* : form.reset `(values?: TValues | undefined, options?: ResetOptions) => void` - Reinitialize from default or replacement values with optional preservation flags.
|
|
175
|
+
* : form.submit `<TResult>(onValid: (values: TValues) => TResult | Promise<TResult>, onInvalid?: (fields: Readonly<Record<PathKey, FieldState>>) => void) => Promise<TResult | undefined>` - Queue validation and dispatch the valid or invalid callback.
|
|
176
|
+
* - useRegister `{ <TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): RegisterPropsForElement<TElement>; <TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(options: TOptions): RegisterPropsList<TElement, TOptions>; <TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): RegisterPropsList<TElement, TOptions>; }` - Create one binding or an ordered list from single, array, or variadic options.
|
|
177
|
+
* - useField `<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions) => UseFieldReturn<RegisterPropsForElement<TElement>>` - Create field bindings, reactive value and metadata, and a setter.
|
|
178
|
+
* - useFieldState `<const TName extends FieldPathInput>(name: TName) => Readonly<FieldState<FieldPathValue<TValues, TName>>>` - Subscribe to a path-typed field snapshot.
|
|
179
|
+
* - useFormState `() => UseFormStateReturn<TValues>` - Subscribe to form-wide errors and lifecycle aggregates.
|
|
180
|
+
* - handleSubmit `<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler) => SubmitHandler<React.FormEvent<HTMLFormElement>, TResult>` - Create an event handler that prevents default submission before validating.
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* const { form, handleSubmit } = useForm({ defaultValues: { email: "" } });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
84
186
|
declare function useForm<TValues>(form: Form<TValues>): ReactForm<TValues>;
|
|
85
187
|
declare function useForm<TValues>(options: ReactFormOptions<TValues>): ReactForm<TValues>;
|
|
86
188
|
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isFormInstance, createFormFromOptions, createExternalValuesSynchronizer, createSubmitHandler, getFieldState, fieldPathToDomName, createFormStateSummary, createDomBinding } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { isFormInstance, createFormFromOptions, createExternalValuesSynchronizer, createSubmitHandler, getFieldState, fieldPathToDomName, createFormStateSummary, createDomBinding } from '../chunk-WO5TIXCR.js';
|
|
2
|
+
import '../chunk-M7Y4OJPP.js';
|
|
3
3
|
import { useRef, useMemo, useEffect, useCallback, useSyncExternalStore } from 'react';
|
|
4
4
|
|
|
5
5
|
// src/react/RegisterBinding.ts
|