@ilokesto/form 1.0.2 → 2.0.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/LICENSE +21 -0
- package/README.ko.md +86 -13
- package/README.md +86 -15
- package/dist/FormInput-DuT7QFe-.d.ts +37 -0
- package/dist/chunk-EPQC3LKB.js +1649 -0
- package/dist/chunk-EPQC3LKB.js.map +1 -0
- package/dist/chunk-OBMSHDV2.js +215 -0
- package/dist/chunk-OBMSHDV2.js.map +1 -0
- package/dist/index.d.ts +58 -2
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +87 -2
- package/dist/react/index.js +110 -70
- package/dist/react/index.js.map +1 -0
- package/dist/solid/index.d.ts +89 -2
- package/dist/solid/index.js +115 -62
- package/dist/solid/index.js.map +1 -0
- package/dist/svelte/index.d.ts +68 -2
- package/dist/svelte/index.js +162 -75
- package/dist/svelte/index.js.map +1 -0
- package/dist/types-DBlvL6AC.d.ts +229 -0
- package/dist/vue/index.d.ts +87 -2
- package/dist/vue/index.js +137 -62
- package/dist/vue/index.js.map +1 -0
- package/package.json +15 -8
- package/dist/CreateForm-hQ4cxAK-.js +0 -1283
- package/dist/FormStateSummary-gmEQdNXj.js +0 -140
- package/dist/adapters/FormInput.d.ts +0 -8
- package/dist/adapters/FormStateSummary.d.ts +0 -14
- package/dist/adapters/dom/FieldValue.d.ts +0 -2
- package/dist/adapters/dom/RegisterBinding.d.ts +0 -14
- package/dist/adapters/dom/SubmitHandler.d.ts +0 -9
- package/dist/adapters/dom/index.d.ts +0 -5
- package/dist/adapters/dom/types.d.ts +0 -22
- package/dist/core/array/ArrayItemReorder.d.ts +0 -6
- package/dist/core/array/ArrayKeyGenerator.d.ts +0 -4
- package/dist/core/array/FormArrayController.d.ts +0 -21
- package/dist/core/array/FormArrayFactory.d.ts +0 -8
- package/dist/core/array/FormArrayMutationPlanner.d.ts +0 -14
- package/dist/core/array/FormArrayPath.d.ts +0 -6
- package/dist/core/array/FormArrayRebaser.d.ts +0 -7
- package/dist/core/array/index.d.ts +0 -1
- package/dist/core/form/CreateForm.d.ts +0 -23
- package/dist/core/form/FormFieldCommands.d.ts +0 -15
- package/dist/core/form/FormSubmitter.d.ts +0 -9
- package/dist/core/form/index.d.ts +0 -1
- package/dist/core/index.d.ts +0 -2
- package/dist/core/path/FormPath.d.ts +0 -9
- package/dist/core/path/index.d.ts +0 -1
- package/dist/core/state/FieldStateFactory.d.ts +0 -6
- package/dist/core/state/FormStateInitializer.d.ts +0 -7
- package/dist/core/state/FormStateReader.d.ts +0 -11
- package/dist/core/state/FormStateStore.d.ts +0 -24
- package/dist/core/state/FormStateWriter.d.ts +0 -17
- package/dist/core/state/index.d.ts +0 -1
- package/dist/core/types.d.ts +0 -112
- package/dist/core/validation/StandardSchemaValidator.d.ts +0 -14
- package/dist/core/validation/ValidationEngine.d.ts +0 -25
- package/dist/core/validation/index.d.ts +0 -1
- package/dist/core/value/ValueHelper.d.ts +0 -7
- package/dist/core/value/index.d.ts +0 -1
- package/dist/react/RegisterBinding.d.ts +0 -5
- package/dist/react/types.d.ts +0 -73
- package/dist/react/useField.d.ts +0 -3
- package/dist/react/useFieldSchemaRegistration.d.ts +0 -4
- package/dist/react/useFieldState.d.ts +0 -3
- package/dist/react/useForm.d.ts +0 -4
- package/dist/react/useFormSnapshot.d.ts +0 -2
- package/dist/react/useFormState.d.ts +0 -3
- package/dist/react/useRegister.d.ts +0 -6
- package/dist/solid/RegisterBinding.d.ts +0 -5
- package/dist/solid/types.d.ts +0 -71
- package/dist/solid/useField.d.ts +0 -3
- package/dist/solid/useFieldSchemaRegistration.d.ts +0 -3
- package/dist/solid/useForm.d.ts +0 -4
- package/dist/solid/useFormSnapshot.d.ts +0 -3
- package/dist/solid/useFormState.d.ts +0 -3
- package/dist/solid/useRegister.d.ts +0 -6
- package/dist/svelte/RegisterAction.d.ts +0 -4
- package/dist/svelte/types.d.ts +0 -13
- package/dist/svelte/useForm.d.ts +0 -4
- package/dist/svelte/useFormState.d.ts +0 -4
- package/dist/vue/RegisterBinding.d.ts +0 -5
- package/dist/vue/types.d.ts +0 -71
- package/dist/vue/useField.d.ts +0 -3
- package/dist/vue/useFieldSchemaRegistration.d.ts +0 -3
- package/dist/vue/useForm.d.ts +0 -4
- package/dist/vue/useFormSnapshot.d.ts +0 -3
- package/dist/vue/useFormState.d.ts +0 -3
- package/dist/vue/useRegister.d.ts +0 -6
package/dist/react/index.d.ts
CHANGED
|
@@ -1,2 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
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-DuT7QFe-.js';
|
|
4
|
+
|
|
5
|
+
/** React adapter가 form 생성 옵션에 더해 reactive external values를 받을 때 쓰는 옵션이다. */
|
|
6
|
+
type ReactFormOptions<TValues> = ReactiveFormOptions<TValues, TValues | undefined>;
|
|
7
|
+
type InputValue = InputHTMLAttributes<HTMLInputElement>['value'];
|
|
8
|
+
type InputType = InputHTMLAttributes<HTMLInputElement>['type'];
|
|
9
|
+
type SelectValue = SelectHTMLAttributes<HTMLSelectElement>['value'];
|
|
10
|
+
type TextareaValue = TextareaHTMLAttributes<HTMLTextAreaElement>['value'];
|
|
11
|
+
type BindingHandlers<TElement extends HTMLElement> = {
|
|
12
|
+
onChange: ChangeEventHandler<TElement>;
|
|
13
|
+
onBlur: FocusEventHandler<TElement>;
|
|
14
|
+
onFocus: FocusEventHandler<TElement>;
|
|
15
|
+
};
|
|
16
|
+
/** `<input {...useRegister(...)} />`에 바로 spread할 수 있는 기본 binding props다. */
|
|
17
|
+
type InputRegisterProps = BindingHandlers<HTMLInputElement> & {
|
|
18
|
+
name: string;
|
|
19
|
+
type: InputType;
|
|
20
|
+
value?: InputValue;
|
|
21
|
+
checked?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** `useRegister<HTMLSelectElement>(...)`로 좁혀 `<select>`에 spread할 수 있는 binding props다. */
|
|
24
|
+
type SelectRegisterProps = BindingHandlers<HTMLSelectElement> & {
|
|
25
|
+
name: string;
|
|
26
|
+
value?: SelectValue;
|
|
27
|
+
};
|
|
28
|
+
/** `useRegister<HTMLTextAreaElement>(...)`로 좁혀 `<textarea>`에 spread할 수 있는 binding props다. */
|
|
29
|
+
type TextareaRegisterProps = BindingHandlers<HTMLTextAreaElement> & {
|
|
30
|
+
name: string;
|
|
31
|
+
value?: TextareaValue;
|
|
32
|
+
};
|
|
33
|
+
/** DOM-compatible custom component용 escape-hatch binding props다. */
|
|
34
|
+
type CustomRegisterProps<TElement extends HTMLElement = HTMLElement> = BindingHandlers<TElement> & {
|
|
35
|
+
name: string;
|
|
36
|
+
value?: unknown;
|
|
37
|
+
checked?: boolean;
|
|
38
|
+
};
|
|
39
|
+
type RegisterElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLElement;
|
|
40
|
+
/** element generic에 맞춘 DOM-event-compatible field binding props다. */
|
|
41
|
+
type RegisterPropsForElement<TElement extends RegisterElement> = TElement extends HTMLSelectElement ? SelectRegisterProps : TElement extends HTMLTextAreaElement ? TextareaRegisterProps : TElement extends HTMLInputElement ? InputRegisterProps : CustomRegisterProps<TElement>;
|
|
42
|
+
type RegisterProps = RegisterPropsForElement<RegisterElement>;
|
|
43
|
+
/** 한 field의 binding, value, meta, setter를 함께 제공한다. */
|
|
44
|
+
type UseFieldReturn<TProps extends RegisterProps = InputRegisterProps> = {
|
|
45
|
+
props: TProps;
|
|
46
|
+
value: unknown;
|
|
47
|
+
setValue: (value: unknown) => void;
|
|
48
|
+
errors: FormError[];
|
|
49
|
+
dirty: boolean;
|
|
50
|
+
touched: boolean;
|
|
51
|
+
};
|
|
52
|
+
/** 한 field의 value와 meta를 form values 타입과 path에서 추론해 반환한다. */
|
|
53
|
+
type UseFieldStateReturn<TValues, TName extends FieldPathInput> = Readonly<FieldState<FieldPathValue<TValues, TName>>>;
|
|
54
|
+
/** form 전체 상태에서 React UI가 자주 쓰는 aggregate state다. */
|
|
55
|
+
type UseFormStateReturn<TValues> = {
|
|
56
|
+
state: Readonly<FormState<TValues>>;
|
|
57
|
+
errors: Record<string, FormError[]>;
|
|
58
|
+
dirtyFields: Record<string, true>;
|
|
59
|
+
touchedFields: Record<string, true>;
|
|
60
|
+
focusedField: string | null;
|
|
61
|
+
isDirty: boolean;
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
isSubmitting: boolean;
|
|
64
|
+
isSubmitted: boolean;
|
|
65
|
+
isSubmitSuccessful: boolean;
|
|
66
|
+
submitCount: number;
|
|
67
|
+
};
|
|
68
|
+
type RegisterPropsList<TElement extends RegisterElement, TOptions extends readonly RegisterOptions[]> = {
|
|
69
|
+
[Index in keyof TOptions]: TOptions[Index] extends RegisterOptions ? RegisterPropsForElement<TElement> : never;
|
|
70
|
+
};
|
|
71
|
+
/** `useForm(form)`이 반환하는 form-bound hook 모음이다. */
|
|
72
|
+
type ReactForm<TValues> = {
|
|
73
|
+
form: Form<TValues>;
|
|
74
|
+
useRegister<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): RegisterPropsForElement<TElement>;
|
|
75
|
+
useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(options: TOptions): RegisterPropsList<TElement, TOptions>;
|
|
76
|
+
useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): RegisterPropsList<TElement, TOptions>;
|
|
77
|
+
useField<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): UseFieldReturn<RegisterPropsForElement<TElement>>;
|
|
78
|
+
useFieldState<const TName extends FieldPathInput>(name: TName): UseFieldStateReturn<TValues, TName>;
|
|
79
|
+
useFormState(): UseFormStateReturn<TValues>;
|
|
80
|
+
handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<FormEvent<HTMLFormElement>, TResult>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** React hook surface를 core Form 인스턴스에 바인딩한다. */
|
|
84
|
+
declare function useForm<TValues>(form: Form<TValues>): ReactForm<TValues>;
|
|
85
|
+
declare function useForm<TValues>(options: ReactFormOptions<TValues>): ReactForm<TValues>;
|
|
86
|
+
|
|
87
|
+
export { type ReactFormOptions, RegisterOptions, type UseFieldStateReturn, useForm };
|
package/dist/react/index.js
CHANGED
|
@@ -1,91 +1,131 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { isFormInstance, createFormFromOptions, createExternalValuesSynchronizer, createSubmitHandler, getFieldState, fieldPathToDomName, createFormStateSummary, createDomBinding } from '../chunk-OBMSHDV2.js';
|
|
2
|
+
import '../chunk-EPQC3LKB.js';
|
|
3
|
+
import { useRef, useMemo, useEffect, useCallback, useSyncExternalStore } from 'react';
|
|
4
|
+
|
|
5
|
+
// src/react/RegisterBinding.ts
|
|
6
|
+
function createRegisterProps(form, options, field, domName) {
|
|
7
|
+
const binding = createDomBinding(form, options, () => field, domName);
|
|
8
|
+
const props = {
|
|
9
|
+
name: binding.name,
|
|
10
|
+
type: binding.type,
|
|
11
|
+
value: binding.value,
|
|
12
|
+
checked: binding.checked,
|
|
13
|
+
onChange: (event) => {
|
|
14
|
+
binding.change(event.currentTarget);
|
|
12
15
|
},
|
|
13
16
|
onBlur: () => {
|
|
14
|
-
|
|
17
|
+
binding.blur();
|
|
15
18
|
},
|
|
16
19
|
onFocus: () => {
|
|
17
|
-
|
|
20
|
+
binding.focus();
|
|
18
21
|
}
|
|
19
22
|
};
|
|
23
|
+
return props;
|
|
20
24
|
}
|
|
21
|
-
function
|
|
22
|
-
const { name
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
26
|
-
|
|
25
|
+
function useFieldSchemaRegistration(form, options) {
|
|
26
|
+
const { name, schema, schemaOptions } = options;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!schema) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
return form.registerFieldSchema(name, { schema, schemaOptions });
|
|
32
|
+
}, [form, name, schema, schemaOptions]);
|
|
27
33
|
}
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
34
|
+
function useFieldSchemaRegistrations(form, options) {
|
|
35
|
+
const schemaSignature = options.map((option) => `${fieldPathToDomName(option.name)}:${option.schema ? "schema" : "none"}`).join("|");
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const cleanups = options.flatMap((option) => {
|
|
38
|
+
if (!option.schema) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return [form.registerFieldSchema(option.name, { schema: option.schema, schemaOptions: option.schemaOptions })];
|
|
42
|
+
});
|
|
32
43
|
return () => {
|
|
33
|
-
|
|
44
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
34
45
|
};
|
|
35
|
-
}, [
|
|
46
|
+
}, [form, options, schemaSignature]);
|
|
36
47
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
39
|
-
(
|
|
40
|
-
() =>
|
|
41
|
-
() =>
|
|
48
|
+
function useFormSnapshot(form) {
|
|
49
|
+
return useSyncExternalStore(
|
|
50
|
+
(listener) => form.subscribe(listener),
|
|
51
|
+
() => form.getState(),
|
|
52
|
+
() => form.getState()
|
|
42
53
|
);
|
|
43
54
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
|
|
56
|
+
// src/react/useField.ts
|
|
57
|
+
function useFieldWithForm(form, options) {
|
|
58
|
+
useFieldSchemaRegistration(form, options);
|
|
59
|
+
const state = useFormSnapshot(form);
|
|
60
|
+
const field = getFieldState(form, state, options.name);
|
|
61
|
+
const domName = fieldPathToDomName(options.name);
|
|
62
|
+
const props = useMemo(() => createRegisterProps(form, options, field, domName), [form, options, field, domName]);
|
|
63
|
+
const setValue = useCallback((value) => {
|
|
64
|
+
form.setValue(options.name, value, { source: "program" });
|
|
65
|
+
}, [form, options.name]);
|
|
66
|
+
return useMemo(() => ({
|
|
67
|
+
props,
|
|
68
|
+
value: field.value,
|
|
69
|
+
setValue,
|
|
70
|
+
errors: [...field.errors],
|
|
71
|
+
dirty: field.dirty,
|
|
72
|
+
touched: field.touched
|
|
73
|
+
}), [field, props, setValue]);
|
|
57
74
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
|
|
76
|
+
// src/react/useFieldState.ts
|
|
77
|
+
function useFieldStateWithForm(form, name) {
|
|
78
|
+
const state = useFormSnapshot(form);
|
|
79
|
+
return getFieldState(form, state, name);
|
|
61
80
|
}
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
return
|
|
81
|
+
function useFormStateWithForm(form) {
|
|
82
|
+
const state = useFormSnapshot(form);
|
|
83
|
+
return useMemo(() => createFormStateSummary(state), [state]);
|
|
65
84
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
function useRegisterWithForm(form, first, ...rest) {
|
|
86
|
+
const shouldReturnList = Array.isArray(first) || rest.length > 0;
|
|
87
|
+
const options = normalizeRegisterOptions(first, rest);
|
|
88
|
+
useFieldSchemaRegistrations(form, options);
|
|
89
|
+
const state = useFormSnapshot(form);
|
|
90
|
+
const bindings = useMemo(
|
|
91
|
+
() => options.map((option) => {
|
|
92
|
+
const field = getFieldState(form, state, option.name);
|
|
93
|
+
const domName = fieldPathToDomName(option.name);
|
|
94
|
+
return createRegisterProps(form, option, field, domName);
|
|
73
95
|
}),
|
|
74
|
-
[
|
|
96
|
+
[form, options, state]
|
|
75
97
|
);
|
|
76
|
-
return
|
|
98
|
+
return shouldReturnList ? bindings : bindings[0];
|
|
77
99
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
100
|
+
function normalizeRegisterOptions(first, rest) {
|
|
101
|
+
if (Array.isArray(first)) {
|
|
102
|
+
return first;
|
|
103
|
+
}
|
|
104
|
+
if (rest.length > 0) {
|
|
105
|
+
return [first, ...rest];
|
|
106
|
+
}
|
|
107
|
+
return [first];
|
|
80
108
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
109
|
+
|
|
110
|
+
// src/react/useForm.ts
|
|
111
|
+
function useForm(input) {
|
|
112
|
+
const optionsFormRef = useRef(void 0);
|
|
113
|
+
const isForm = isFormInstance(input);
|
|
114
|
+
const form = isForm ? input : optionsFormRef.current ??= createFormFromOptions(input);
|
|
115
|
+
const values = isForm ? void 0 : input.values;
|
|
116
|
+
const resetOptions = isForm ? void 0 : input.resetOptions;
|
|
117
|
+
const synchronizeValues = useMemo(() => createExternalValuesSynchronizer(form), [form]);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
synchronizeValues(values, resetOptions);
|
|
120
|
+
}, [resetOptions, synchronizeValues, values]);
|
|
121
|
+
const useRegister = ((first, ...rest) => useRegisterWithForm(form, first, ...rest));
|
|
122
|
+
const useField = ((options) => useFieldWithForm(form, options));
|
|
123
|
+
const useFieldState = ((name) => useFieldStateWithForm(form, name));
|
|
124
|
+
const useFormState = () => useFormStateWithForm(form);
|
|
125
|
+
const handleSubmit = ((onValid, onInvalid) => createSubmitHandler(form, onValid, onInvalid));
|
|
126
|
+
return useMemo(() => ({ form, useRegister, useField, useFieldState, useFormState, handleSubmit }), [form]);
|
|
88
127
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
128
|
+
|
|
129
|
+
export { useForm };
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
131
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/RegisterBinding.ts","../../src/react/useFieldSchemaRegistration.ts","../../src/react/useFormSnapshot.ts","../../src/react/useField.ts","../../src/react/useFieldState.ts","../../src/react/useFormState.ts","../../src/react/useRegister.ts","../../src/react/useForm.ts"],"names":["useMemo","useEffect"],"mappings":";;;;;AAMO,SAAS,mBAAA,CACd,IAAA,EACA,OAAA,EACA,KAAA,EACA,OAAA,EACmC;AACnC,EAAA,MAAM,UAAU,gBAAA,CAAiB,IAAA,EAAM,OAAA,EAAS,MAAM,OAAO,OAAO,CAAA;AACpE,EAAA,MAAM,KAAA,GAAQ;AAAA,IACZ,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,OAAO,OAAA,CAAQ,KAAA;AAAA,IACf,SAAS,OAAA,CAAQ,OAAA;AAAA,IACjB,QAAA,EAAU,CAAC,KAAA,KAAoC;AAC7C,MAAA,OAAA,CAAQ,MAAA,CAAO,MAAM,aAAiC,CAAA;AAAA,IACxD,CAAA;AAAA,IACA,QAAQ,MAAM;AACZ,MAAA,OAAA,CAAQ,IAAA,EAAK;AAAA,IACf,CAAA;AAAA,IACA,SAAS,MAAM;AACb,MAAA,OAAA,CAAQ,KAAA,EAAM;AAAA,IAChB;AAAA,GACF;AAEA,EAAA,OAAO,KAAA;AACT;ACxBO,SAAS,0BAAA,CAAoC,MAAqB,OAAA,EAAgC;AACvG,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,E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AAOD,OAAAA,CAAQ,OAAO,EAAE,IAAA,EAAM,WAAA,EAAa,QAAA,EAAU,aAAA,EAAe,YAAA,EAAc,YAAA,EAAa,CAAA,EAAI,CAAC,IAAI,CAAC,CAAA;AAC3G","file":"index.js","sourcesContent":["import type { ChangeEvent } from 'react';\nimport type { FieldState, Form } from '../core/index';\nimport { createDomBinding, type FieldEventTarget, type RegisterOptions, fieldPathToDomName } from '../adapters/dom';\nimport type { RegisterElement, RegisterPropsForElement } from './types';\n\n/** binding props를 생성한다. 이벤트 handler는 DOM event에서 값을 읽어 core form에 전달한다. */\nexport function createRegisterProps<TValues, TElement extends RegisterElement>(\n form: Form<TValues>,\n options: RegisterOptions,\n field: Readonly<FieldState>,\n domName: string,\n): RegisterPropsForElement<TElement> {\n const binding = createDomBinding(form, options, () => field, domName);\n const props = {\n name: binding.name,\n type: binding.type,\n value: binding.value,\n checked: binding.checked,\n onChange: (event: ChangeEvent<HTMLElement>) => {\n binding.change(event.currentTarget as FieldEventTarget);\n },\n onBlur: () => {\n binding.blur();\n },\n onFocus: () => {\n binding.focus();\n },\n };\n\n return props as unknown as RegisterPropsForElement<TElement>;\n}\n\nexport { fieldPathToDomName };\n","import { useEffect } from 'react';\nimport type { Form } from '../core/index';\nimport type { RegisterOptions } from './types';\nimport { fieldPathToDomName } from './RegisterBinding';\n\n/** field-local schema 하나를 effect lifecycle에 맞춰 등록한다. */\nexport function useFieldSchemaRegistration<TValues>(form: Form<TValues>, options: RegisterOptions): void {\n const { name, schema, schemaOptions } = options;\n\n useEffect(() => {\n if (!schema) {\n return undefined;\n }\n\n return form.registerFieldSchema(name, { schema, schemaOptions });\n }, [form, name, schema, schemaOptions]);\n}\n\n/** bulk register에서도 hook 호출 수가 옵션 길이에 의존하지 않도록 한 effect에서 모두 등록한다. */\nexport function useFieldSchemaRegistrations<TValues>(form: Form<TValues>, options: readonly RegisterOptions[]): void {\n const schemaSignature = options.map(option => `${fieldPathToDomName(option.name)}:${option.schema ? 'schema' : 'none'}`).join('|');\n\n useEffect(() => {\n const cleanups = options.flatMap(option => {\n if (!option.schema) {\n return [];\n }\n\n return [form.registerFieldSchema(option.name, { schema: option.schema, schemaOptions: option.schemaOptions })];\n });\n\n return () => {\n cleanups.forEach(cleanup => cleanup());\n };\n }, [form, options, schemaSignature]);\n}\n","import { useSyncExternalStore } from 'react';\nimport type { Form, FormState } from '../core/index';\n\n/** React 18+ 외부 store 구독 API로 core form snapshot을 구독한다. */\nexport function useFormSnapshot<TValues>(form: Form<TValues>): Readonly<FormState<TValues>> {\n return useSyncExternalStore(\n listener => form.subscribe(listener),\n () => form.getState(),\n () => form.getState(),\n );\n}\n","import { useCallback, useMemo } from 'react';\nimport type { Form } from '../core/index';\nimport type { RegisterElement, RegisterOptions, RegisterPropsForElement, UseFieldReturn } from './types';\nimport { createRegisterProps, fieldPathToDomName } from './RegisterBinding';\nimport { getFieldState } from '../adapters/dom';\nimport { useFieldSchemaRegistration } from './useFieldSchemaRegistration';\nimport { useFormSnapshot } from './useFormSnapshot';\n\n/** 한 field의 binding, value, meta, setter를 함께 반환한다. */\nexport function useFieldWithForm<TValues, TElement extends RegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): UseFieldReturn<RegisterPropsForElement<TElement>> {\n useFieldSchemaRegistration(form, options);\n\n const state = useFormSnapshot(form);\n const field = getFieldState(form, state, options.name);\n const domName = fieldPathToDomName(options.name);\n const props = useMemo(() => createRegisterProps<TValues, TElement>(form, options, field, domName), [form, options, field, domName]);\n\n const setValue = useCallback((value: unknown) => {\n form.setValue(options.name, value, { source: 'program' });\n }, [form, options.name]);\n\n return useMemo(() => ({\n props,\n value: field.value,\n setValue,\n errors: [...field.errors],\n dirty: field.dirty,\n touched: field.touched,\n }), [field, props, setValue]);\n}\n","import type { FieldPathInput, Form } from '../core/index';\nimport { getFieldState } from '../adapters/dom';\nimport type { UseFieldStateReturn } from './types';\nimport { useFormSnapshot } from './useFormSnapshot';\n\n/** 한 field의 value와 meta를 typed path 기준으로 반환한다. */\nexport function useFieldStateWithForm<TValues, const TName extends FieldPathInput>(form: Form<TValues>, name: TName): UseFieldStateReturn<TValues, TName> {\n const state = useFormSnapshot(form);\n\n return getFieldState(form, state, name) as UseFieldStateReturn<TValues, TName>;\n}\n","import { useMemo } from 'react';\nimport type { Form } from '../core/index';\nimport { createFormStateSummary } from '../adapters/FormStateSummary';\nimport type { UseFormStateReturn } from './types';\nimport { useFormSnapshot } from './useFormSnapshot';\n\n/** form 전체 aggregate state를 반환한다. */\nexport function useFormStateWithForm<TValues>(form: Form<TValues>): UseFormStateReturn<TValues> {\n const state = useFormSnapshot(form);\n\n return useMemo(() => createFormStateSummary(state), [state]);\n}\n","import { useMemo } from 'react';\nimport type { Form } from '../core/index';\nimport type { RegisterElement, RegisterOptions, RegisterPropsForElement, RegisterPropsList } from './types';\nimport { getFieldState } from '../adapters/dom';\nimport { createRegisterProps, fieldPathToDomName } from './RegisterBinding';\nimport { useFieldSchemaRegistrations } from './useFieldSchemaRegistration';\nimport { useFormSnapshot } from './useFormSnapshot';\n\nexport function useRegisterWithForm<TValues, TElement extends RegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): RegisterPropsForElement<TElement>;\nexport function useRegisterWithForm<TValues, TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, options: TOptions): RegisterPropsList<TElement, TOptions>;\nexport function useRegisterWithForm<TValues, TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, ...options: TOptions): RegisterPropsList<TElement, TOptions>;\nexport function useRegisterWithForm<TValues>(form: Form<TValues>, first: RegisterOptions | readonly RegisterOptions[], ...rest: readonly RegisterOptions[]): RegisterPropsForElement<RegisterElement> | RegisterPropsForElement<RegisterElement>[];\n\n/** 단일 또는 여러 field의 DOM binding props를 만든다. */\nexport function useRegisterWithForm<TValues>(\n form: Form<TValues>,\n first: RegisterOptions | readonly RegisterOptions[],\n ...rest: readonly RegisterOptions[]\n): RegisterPropsForElement<RegisterElement> | RegisterPropsForElement<RegisterElement>[] {\n const shouldReturnList = Array.isArray(first) || rest.length > 0;\n const options = normalizeRegisterOptions(first, rest);\n\n useFieldSchemaRegistrations(form, options);\n\n const state = useFormSnapshot(form);\n const bindings = useMemo(\n () => options.map(option => {\n const field = getFieldState(form, state, option.name);\n const domName = fieldPathToDomName(option.name);\n\n return createRegisterProps(form, option, field, domName);\n }),\n [form, options, state],\n );\n\n return shouldReturnList ? bindings : bindings[0];\n}\n\nfunction normalizeRegisterOptions(first: RegisterOptions | readonly RegisterOptions[], rest: readonly RegisterOptions[]): readonly RegisterOptions[] {\n if (Array.isArray(first)) {\n return first as readonly RegisterOptions[];\n }\n\n if (rest.length > 0) {\n return [first as RegisterOptions, ...rest];\n }\n\n return [first as RegisterOptions];\n}\n","import { useEffect, useMemo, useRef } from 'react';\nimport { createSubmitHandler } from '../adapters/dom';\nimport {\n createExternalValuesSynchronizer,\n createFormFromOptions,\n isFormInstance,\n type FormInput,\n} from '../adapters/FormInput';\nimport type { FieldPathInput, Form } from '../core/index';\nimport type { ReactForm, ReactFormOptions, RegisterOptions } from './types';\nimport { useFieldWithForm } from './useField';\nimport { useFieldStateWithForm } from './useFieldState';\nimport { useFormStateWithForm } from './useFormState';\nimport { useRegisterWithForm } from './useRegister';\n\n/** React hook surface를 core Form 인스턴스에 바인딩한다. */\nexport function useForm<TValues>(form: Form<TValues>): ReactForm<TValues>;\nexport function useForm<TValues>(options: ReactFormOptions<TValues>): ReactForm<TValues>;\nexport function useForm<TValues>(input: FormInput<TValues, ReactFormOptions<TValues>>): ReactForm<TValues> {\n const optionsFormRef = useRef<Form<TValues> | undefined>(undefined);\n const isForm = isFormInstance(input);\n const form = isForm\n ? input\n : (optionsFormRef.current ??= createFormFromOptions(input));\n const values = isForm ? undefined : input.values;\n const resetOptions = isForm ? undefined : input.resetOptions;\n const synchronizeValues = useMemo(() => createExternalValuesSynchronizer(form), [form]);\n\n useEffect(() => {\n synchronizeValues(values, resetOptions);\n }, [resetOptions, synchronizeValues, values]);\n\n const useRegister = ((\n first: RegisterOptions | readonly RegisterOptions[],\n ...rest: readonly RegisterOptions[]\n ) => useRegisterWithForm(form, first, ...rest)) as ReactForm<TValues>['useRegister'];\n const useField = ((options: RegisterOptions) =>\n useFieldWithForm(form, options)) as ReactForm<TValues>['useField'];\n const useFieldState = ((name: FieldPathInput) =>\n useFieldStateWithForm(form, name)) as ReactForm<TValues>['useFieldState'];\n const useFormState = (): ReturnType<ReactForm<TValues>['useFormState']> =>\n useFormStateWithForm(form);\n const handleSubmit = ((onValid, onInvalid) =>\n createSubmitHandler(form, onValid, onInvalid)) as ReactForm<TValues>['handleSubmit'];\n\n return useMemo(() => ({ form, useRegister, useField, useFieldState, useFormState, handleSubmit }), [form]);\n}\n"]}
|
package/dist/solid/index.d.ts
CHANGED
|
@@ -1,2 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { F as Form, e as FormError, a as FormState } from '../types-DBlvL6AC.js';
|
|
2
|
+
import { Accessor } from 'solid-js';
|
|
3
|
+
import { R as ReactiveFormOptions, a as RegisterOptions, D as DomValue, S as SubmitValidHandler, b as SubmitInvalidHandler, c as SubmitHandler } from '../FormInput-DuT7QFe-.js';
|
|
4
|
+
|
|
5
|
+
/** Solid owner가 외부 values accessor와 함께 form을 만들 때 쓰는 옵션이다. */
|
|
6
|
+
type SolidFormOptions<TValues> = ReactiveFormOptions<TValues, Accessor<TValues | undefined>>;
|
|
7
|
+
type SolidBindingHandlers<TElement extends HTMLElement> = {
|
|
8
|
+
onInput: (event: InputEvent & {
|
|
9
|
+
currentTarget: TElement;
|
|
10
|
+
}) => void;
|
|
11
|
+
onChange: (event: Event & {
|
|
12
|
+
currentTarget: TElement;
|
|
13
|
+
}) => void;
|
|
14
|
+
onBlur: (event: FocusEvent & {
|
|
15
|
+
currentTarget: TElement;
|
|
16
|
+
}) => void;
|
|
17
|
+
onFocus: (event: FocusEvent & {
|
|
18
|
+
currentTarget: TElement;
|
|
19
|
+
}) => void;
|
|
20
|
+
};
|
|
21
|
+
/** `<input {...useRegister(...)} />`에 바로 spread할 수 있는 기본 binding props다. */
|
|
22
|
+
type SolidInputRegisterProps = SolidBindingHandlers<HTMLInputElement> & {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly type: string;
|
|
25
|
+
readonly value?: DomValue;
|
|
26
|
+
readonly checked?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** `useRegister<HTMLSelectElement>(...)`로 좁혀 `<select>`에 spread할 수 있는 binding props다. */
|
|
29
|
+
type SolidSelectRegisterProps = SolidBindingHandlers<HTMLSelectElement> & {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly value?: DomValue;
|
|
32
|
+
};
|
|
33
|
+
/** `useRegister<HTMLTextAreaElement>(...)`로 좁혀 `<textarea>`에 spread할 수 있는 binding props다. */
|
|
34
|
+
type SolidTextareaRegisterProps = SolidBindingHandlers<HTMLTextAreaElement> & {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly value?: string | number;
|
|
37
|
+
};
|
|
38
|
+
/** DOM-compatible custom component용 escape-hatch binding props다. */
|
|
39
|
+
type SolidCustomRegisterProps<TElement extends HTMLElement = HTMLElement> = SolidBindingHandlers<TElement> & {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly value?: unknown;
|
|
42
|
+
readonly checked?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type SolidRegisterElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLElement;
|
|
45
|
+
/** element generic에 맞춘 Solid DOM-event-compatible field binding props다. */
|
|
46
|
+
type SolidRegisterPropsForElement<TElement extends SolidRegisterElement> = TElement extends HTMLSelectElement ? SolidSelectRegisterProps : TElement extends HTMLTextAreaElement ? SolidTextareaRegisterProps : TElement extends HTMLInputElement ? SolidInputRegisterProps : SolidCustomRegisterProps<TElement>;
|
|
47
|
+
type SolidRegisterProps = SolidRegisterPropsForElement<SolidRegisterElement>;
|
|
48
|
+
type SolidRegisterPropsList<TElement extends SolidRegisterElement, TOptions extends readonly RegisterOptions[]> = {
|
|
49
|
+
[Index in keyof TOptions]: TOptions[Index] extends RegisterOptions ? SolidRegisterPropsForElement<TElement> : never;
|
|
50
|
+
};
|
|
51
|
+
/** 한 field의 binding, value, meta, setter를 함께 제공한다. */
|
|
52
|
+
type SolidFieldReturn<TProps extends SolidRegisterProps = SolidInputRegisterProps> = {
|
|
53
|
+
readonly props: TProps;
|
|
54
|
+
readonly value: unknown;
|
|
55
|
+
setValue(value: unknown): void;
|
|
56
|
+
readonly errors: FormError[];
|
|
57
|
+
readonly dirty: boolean;
|
|
58
|
+
readonly touched: boolean;
|
|
59
|
+
};
|
|
60
|
+
/** form 전체 상태에서 Solid UI가 자주 쓰는 aggregate state다. */
|
|
61
|
+
type SolidFormStateReturn<TValues> = {
|
|
62
|
+
readonly state: Readonly<FormState<TValues>>;
|
|
63
|
+
readonly errors: Record<string, FormError[]>;
|
|
64
|
+
readonly dirtyFields: Record<string, true>;
|
|
65
|
+
readonly touchedFields: Record<string, true>;
|
|
66
|
+
readonly focusedField: string | null;
|
|
67
|
+
readonly isDirty: boolean;
|
|
68
|
+
readonly isValid: boolean;
|
|
69
|
+
readonly isSubmitting: boolean;
|
|
70
|
+
readonly isSubmitted: boolean;
|
|
71
|
+
readonly isSubmitSuccessful: boolean;
|
|
72
|
+
readonly submitCount: number;
|
|
73
|
+
};
|
|
74
|
+
/** `useForm(form)`이 반환하는 form-bound helper 모음이다. */
|
|
75
|
+
type SolidForm<TValues> = {
|
|
76
|
+
form: Form<TValues>;
|
|
77
|
+
useRegister<TElement extends SolidRegisterElement = HTMLInputElement>(options: RegisterOptions): SolidRegisterPropsForElement<TElement>;
|
|
78
|
+
useRegister<TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
|
|
79
|
+
useRegister<TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
|
|
80
|
+
useField<TElement extends SolidRegisterElement = HTMLInputElement>(options: RegisterOptions): SolidFieldReturn<SolidRegisterPropsForElement<TElement>>;
|
|
81
|
+
useFormState(): SolidFormStateReturn<TValues>;
|
|
82
|
+
handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<Event, TResult>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** Solid helper surface를 core Form 인스턴스에 바인딩한다. */
|
|
86
|
+
declare function useForm<TValues>(form: Form<TValues>): SolidForm<TValues>;
|
|
87
|
+
declare function useForm<TValues>(options: SolidFormOptions<TValues>): SolidForm<TValues>;
|
|
88
|
+
|
|
89
|
+
export { RegisterOptions, type SolidFormOptions, useForm };
|