@ilokesto/form 1.0.3 → 2.0.1

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.
Files changed (151) hide show
  1. package/LICENSE +21 -0
  2. package/README.ko.md +153 -487
  3. package/README.md +155 -490
  4. package/dist/FormInput-DuT7QFe-.d.ts +37 -0
  5. package/dist/chunk-4F4SAGQ5.js +1465 -0
  6. package/dist/chunk-4F4SAGQ5.js.map +1 -0
  7. package/dist/chunk-JK644RR7.js +215 -0
  8. package/dist/chunk-JK644RR7.js.map +1 -0
  9. package/dist/index.d.ts +58 -2
  10. package/dist/index.js +3 -1
  11. package/dist/index.js.map +1 -0
  12. package/dist/react/index.d.ts +87 -2
  13. package/dist/react/index.js +131 -1
  14. package/dist/react/index.js.map +1 -0
  15. package/dist/solid/index.d.ts +89 -2
  16. package/dist/solid/index.js +170 -1
  17. package/dist/solid/index.js.map +1 -0
  18. package/dist/svelte/index.d.ts +68 -2
  19. package/dist/svelte/index.js +198 -1
  20. package/dist/svelte/index.js.map +1 -0
  21. package/dist/types-DBlvL6AC.d.ts +229 -0
  22. package/dist/vue/index.d.ts +87 -2
  23. package/dist/vue/index.js +192 -1
  24. package/dist/vue/index.js.map +1 -0
  25. package/package.json +15 -8
  26. package/dist/adapters/FormInput.d.ts +0 -8
  27. package/dist/adapters/FormInput.js +0 -10
  28. package/dist/adapters/FormStateSummary.d.ts +0 -14
  29. package/dist/adapters/FormStateSummary.js +0 -27
  30. package/dist/adapters/dom/FieldValue.d.ts +0 -2
  31. package/dist/adapters/dom/FieldValue.js +0 -34
  32. package/dist/adapters/dom/RegisterBinding.d.ts +0 -14
  33. package/dist/adapters/dom/RegisterBinding.js +0 -110
  34. package/dist/adapters/dom/SubmitHandler.d.ts +0 -9
  35. package/dist/adapters/dom/SubmitHandler.js +0 -6
  36. package/dist/adapters/dom/index.d.ts +0 -5
  37. package/dist/adapters/dom/index.js +0 -3
  38. package/dist/adapters/dom/types.d.ts +0 -22
  39. package/dist/adapters/dom/types.js +0 -1
  40. package/dist/core/array/ArrayItemReorder.d.ts +0 -6
  41. package/dist/core/array/ArrayItemReorder.js +0 -24
  42. package/dist/core/array/ArrayKeyGenerator.d.ts +0 -4
  43. package/dist/core/array/ArrayKeyGenerator.js +0 -7
  44. package/dist/core/array/FormArrayController.d.ts +0 -21
  45. package/dist/core/array/FormArrayController.js +0 -54
  46. package/dist/core/array/FormArrayFactory.d.ts +0 -8
  47. package/dist/core/array/FormArrayFactory.js +0 -13
  48. package/dist/core/array/FormArrayMutationPlanner.d.ts +0 -14
  49. package/dist/core/array/FormArrayMutationPlanner.js +0 -68
  50. package/dist/core/array/FormArrayPath.d.ts +0 -6
  51. package/dist/core/array/FormArrayPath.js +0 -11
  52. package/dist/core/array/FormArrayRebaser.d.ts +0 -7
  53. package/dist/core/array/FormArrayRebaser.js +0 -54
  54. package/dist/core/array/index.d.ts +0 -1
  55. package/dist/core/array/index.js +0 -1
  56. package/dist/core/form/CreateForm.d.ts +0 -23
  57. package/dist/core/form/CreateForm.js +0 -64
  58. package/dist/core/form/FormFieldCommands.d.ts +0 -15
  59. package/dist/core/form/FormFieldCommands.js +0 -40
  60. package/dist/core/form/FormSubmitter.d.ts +0 -9
  61. package/dist/core/form/FormSubmitter.js +0 -26
  62. package/dist/core/form/index.d.ts +0 -1
  63. package/dist/core/form/index.js +0 -1
  64. package/dist/core/index.d.ts +0 -2
  65. package/dist/core/index.js +0 -1
  66. package/dist/core/path/FormPath.d.ts +0 -9
  67. package/dist/core/path/FormPath.js +0 -36
  68. package/dist/core/path/index.d.ts +0 -1
  69. package/dist/core/path/index.js +0 -1
  70. package/dist/core/state/FieldStateFactory.d.ts +0 -6
  71. package/dist/core/state/FieldStateFactory.js +0 -19
  72. package/dist/core/state/FormStateInitializer.d.ts +0 -7
  73. package/dist/core/state/FormStateInitializer.js +0 -45
  74. package/dist/core/state/FormStateReader.d.ts +0 -11
  75. package/dist/core/state/FormStateReader.js +0 -30
  76. package/dist/core/state/FormStateStore.d.ts +0 -24
  77. package/dist/core/state/FormStateStore.js +0 -66
  78. package/dist/core/state/FormStateWriter.d.ts +0 -17
  79. package/dist/core/state/FormStateWriter.js +0 -107
  80. package/dist/core/state/index.d.ts +0 -1
  81. package/dist/core/state/index.js +0 -1
  82. package/dist/core/types.d.ts +0 -112
  83. package/dist/core/types.js +0 -1
  84. package/dist/core/validation/StandardSchemaValidator.d.ts +0 -14
  85. package/dist/core/validation/StandardSchemaValidator.js +0 -63
  86. package/dist/core/validation/ValidationEngine.d.ts +0 -25
  87. package/dist/core/validation/ValidationEngine.js +0 -116
  88. package/dist/core/validation/index.d.ts +0 -1
  89. package/dist/core/validation/index.js +0 -1
  90. package/dist/core/value/ValueHelper.d.ts +0 -7
  91. package/dist/core/value/ValueHelper.js +0 -66
  92. package/dist/core/value/index.d.ts +0 -1
  93. package/dist/core/value/index.js +0 -1
  94. package/dist/react/RegisterBinding.d.ts +0 -5
  95. package/dist/react/RegisterBinding.js +0 -21
  96. package/dist/react/types.d.ts +0 -73
  97. package/dist/react/types.js +0 -1
  98. package/dist/react/useField.d.ts +0 -3
  99. package/dist/react/useField.js +0 -23
  100. package/dist/react/useFieldSchemaRegistration.d.ts +0 -4
  101. package/dist/react/useFieldSchemaRegistration.js +0 -25
  102. package/dist/react/useFieldState.d.ts +0 -3
  103. package/dist/react/useFieldState.js +0 -6
  104. package/dist/react/useForm.d.ts +0 -4
  105. package/dist/react/useForm.js +0 -30
  106. package/dist/react/useFormSnapshot.d.ts +0 -2
  107. package/dist/react/useFormSnapshot.js +0 -4
  108. package/dist/react/useFormState.d.ts +0 -3
  109. package/dist/react/useFormState.js +0 -7
  110. package/dist/react/useRegister.d.ts +0 -6
  111. package/dist/react/useRegister.js +0 -26
  112. package/dist/solid/RegisterBinding.d.ts +0 -5
  113. package/dist/solid/RegisterBinding.js +0 -28
  114. package/dist/solid/types.d.ts +0 -71
  115. package/dist/solid/types.js +0 -1
  116. package/dist/solid/useField.d.ts +0 -3
  117. package/dist/solid/useField.js +0 -28
  118. package/dist/solid/useFieldSchemaRegistration.d.ts +0 -3
  119. package/dist/solid/useFieldSchemaRegistration.js +0 -15
  120. package/dist/solid/useForm.d.ts +0 -4
  121. package/dist/solid/useForm.js +0 -13
  122. package/dist/solid/useFormSnapshot.d.ts +0 -3
  123. package/dist/solid/useFormSnapshot.js +0 -9
  124. package/dist/solid/useFormState.d.ts +0 -3
  125. package/dist/solid/useFormState.js +0 -38
  126. package/dist/solid/useRegister.d.ts +0 -6
  127. package/dist/solid/useRegister.js +0 -21
  128. package/dist/svelte/RegisterAction.d.ts +0 -4
  129. package/dist/svelte/RegisterAction.js +0 -121
  130. package/dist/svelte/types.d.ts +0 -13
  131. package/dist/svelte/types.js +0 -1
  132. package/dist/svelte/useForm.d.ts +0 -4
  133. package/dist/svelte/useForm.js +0 -17
  134. package/dist/svelte/useFormState.d.ts +0 -4
  135. package/dist/svelte/useFormState.js +0 -10
  136. package/dist/vue/RegisterBinding.d.ts +0 -5
  137. package/dist/vue/RegisterBinding.js +0 -28
  138. package/dist/vue/types.d.ts +0 -71
  139. package/dist/vue/types.js +0 -1
  140. package/dist/vue/useField.d.ts +0 -3
  141. package/dist/vue/useField.js +0 -28
  142. package/dist/vue/useFieldSchemaRegistration.d.ts +0 -3
  143. package/dist/vue/useFieldSchemaRegistration.js +0 -17
  144. package/dist/vue/useForm.d.ts +0 -4
  145. package/dist/vue/useForm.js +0 -13
  146. package/dist/vue/useFormSnapshot.d.ts +0 -3
  147. package/dist/vue/useFormSnapshot.js +0 -11
  148. package/dist/vue/useFormState.d.ts +0 -3
  149. package/dist/vue/useFormState.js +0 -38
  150. package/dist/vue/useRegister.d.ts +0 -6
  151. package/dist/vue/useRegister.js +0 -21
@@ -1,2 +1,87 @@
1
- export { useForm } from './useForm';
2
- export type { ReactFormOptions, RegisterOptions, UseFieldStateReturn, } from './types';
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 };
@@ -1 +1,131 @@
1
- export { useForm } from './useForm';
1
+ import { isFormInstance, createFormFromOptions, createExternalValuesSynchronizer, createSubmitHandler, getFieldState, fieldPathToDomName, createFormStateSummary, createDomBinding } from '../chunk-JK644RR7.js';
2
+ import '../chunk-4F4SAGQ5.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);
15
+ },
16
+ onBlur: () => {
17
+ binding.blur();
18
+ },
19
+ onFocus: () => {
20
+ binding.focus();
21
+ }
22
+ };
23
+ return props;
24
+ }
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]);
33
+ }
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
+ });
43
+ return () => {
44
+ cleanups.forEach((cleanup) => cleanup());
45
+ };
46
+ }, [form, options, schemaSignature]);
47
+ }
48
+ function useFormSnapshot(form) {
49
+ return useSyncExternalStore(
50
+ (listener) => form.subscribe(listener),
51
+ () => form.getState(),
52
+ () => form.getState()
53
+ );
54
+ }
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]);
74
+ }
75
+
76
+ // src/react/useFieldState.ts
77
+ function useFieldStateWithForm(form, name) {
78
+ const state = useFormSnapshot(form);
79
+ return getFieldState(form, state, name);
80
+ }
81
+ function useFormStateWithForm(form) {
82
+ const state = useFormSnapshot(form);
83
+ return useMemo(() => createFormStateSummary(state), [state]);
84
+ }
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);
95
+ }),
96
+ [form, options, state]
97
+ );
98
+ return shouldReturnList ? bindings : bindings[0];
99
+ }
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];
108
+ }
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]);
127
+ }
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/useFor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MAAA,GAAS,MAAA,GAAY,KAAA,CAAM,YAAA;AAChD,EAAA,MAAM,iBAAA,GAAoBA,QAAQ,MAAM,gCAAA,CAAiC,IAAI,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AAEtF,EAAAC,UAAU,MAAM;AACd,IAAA,iBAAA,CAAkB,QAAQ,YAAY,CAAA;AAAA,EACxC,CAAA,EAAG,CAAC,YAAA,EAAc,iBAAA,EAAmB,MAAM,CAAC,CAAA;AAE5C,EAAA,MAAM,WAAA,IAAe,CACnB,KAAA,EAAA,GACG,IAAA,KACA,oBAAoB,IAAA,EAAM,KAAA,EAAO,GAAG,IAAI,CAAA,CAAA;AAC7C,EAAA,MAAM,QAAA,IAAY,CAAC,OAAA,KACjB,gBAAA,CAAiB,MAAM,OAAO,CAAA,CAAA;AAChC,EAAA,MAAM,aAAA,IAAiB,CAAC,IAAA,KACtB,qBAAA,CAAsB,MAAM,IAAI,CAAA,CAAA;AAClC,EAAA,MAAM,YAAA,GAAe,MACnB,oBAAA,CAAqB,IAAI,CAAA;AAC3B,EAAA,MAAM,gBAAgB,CAAC,OAAA,EAAS,cAC9B,mBAAA,CAAoB,IAAA,EAAM,SAAS,SAAS,CAAA,CAAA;AAE9C,EAAA,OAAOD,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"]}
@@ -1,2 +1,89 @@
1
- export { useForm } from './useForm';
2
- export type { RegisterOptions, } from './types';
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 };
@@ -1 +1,170 @@
1
- export { useForm } from './useForm';
1
+ import { isFormInstance, createFormFromOptions, createExternalValuesSynchronizer, createSubmitHandler, fieldPathToDomName, getFieldState, createDomBinding, createFormStateSummary } from '../chunk-JK644RR7.js';
2
+ import '../chunk-4F4SAGQ5.js';
3
+ import { getOwner, createRenderEffect, onCleanup, createSignal } from 'solid-js';
4
+
5
+ // src/solid/RegisterBinding.ts
6
+ function createRegisterProps(form, options, getField, domName) {
7
+ const binding = createDomBinding(form, options, getField, domName);
8
+ const props = {
9
+ name: binding.name,
10
+ type: binding.type,
11
+ get value() {
12
+ return binding.value;
13
+ },
14
+ get checked() {
15
+ return binding.checked;
16
+ },
17
+ onInput: (event) => {
18
+ binding.input(event.currentTarget);
19
+ },
20
+ onChange: (event) => {
21
+ binding.change(event.currentTarget);
22
+ },
23
+ onBlur: () => {
24
+ binding.blur();
25
+ },
26
+ onFocus: () => {
27
+ binding.focus();
28
+ }
29
+ };
30
+ return props;
31
+ }
32
+ function useFieldSchemaRegistrations(form, options) {
33
+ const cleanups = options.flatMap((option) => {
34
+ if (!option.schema) {
35
+ return [];
36
+ }
37
+ return [form.registerFieldSchema(option.name, { schema: option.schema, schemaOptions: option.schemaOptions })];
38
+ });
39
+ if (cleanups.length === 0) {
40
+ return;
41
+ }
42
+ onCleanup(() => {
43
+ cleanups.forEach((cleanup) => cleanup());
44
+ });
45
+ }
46
+ function useFormSnapshot(form) {
47
+ const [snapshot, setSnapshot] = createSignal(form.getState(), { equals: false });
48
+ const unsubscribe = form.subscribe(() => {
49
+ setSnapshot(form.getState());
50
+ });
51
+ onCleanup(unsubscribe);
52
+ return snapshot;
53
+ }
54
+
55
+ // src/solid/useField.ts
56
+ function useFieldWithForm(form, options) {
57
+ useFieldSchemaRegistrations(form, [options]);
58
+ const snapshot = useFormSnapshot(form);
59
+ const getField = () => getFieldState(form, snapshot(), options.name);
60
+ const props = createRegisterProps(form, options, getField, fieldPathToDomName(options.name));
61
+ return {
62
+ props,
63
+ get value() {
64
+ return getField().value;
65
+ },
66
+ setValue(value) {
67
+ form.setValue(options.name, value, { source: "program" });
68
+ },
69
+ get errors() {
70
+ return [...getField().errors];
71
+ },
72
+ get dirty() {
73
+ return getField().dirty;
74
+ },
75
+ get touched() {
76
+ return getField().touched;
77
+ }
78
+ };
79
+ }
80
+
81
+ // src/solid/useFormState.ts
82
+ function useFormStateWithForm(form) {
83
+ const snapshot = useFormSnapshot(form);
84
+ const getSummary = () => createFormStateSummary(snapshot());
85
+ return {
86
+ get state() {
87
+ return snapshot();
88
+ },
89
+ get errors() {
90
+ return getSummary().errors;
91
+ },
92
+ get dirtyFields() {
93
+ return getSummary().dirtyFields;
94
+ },
95
+ get touchedFields() {
96
+ return getSummary().touchedFields;
97
+ },
98
+ get focusedField() {
99
+ return getSummary().focusedField;
100
+ },
101
+ get isDirty() {
102
+ return getSummary().isDirty;
103
+ },
104
+ get isValid() {
105
+ return getSummary().isValid;
106
+ },
107
+ get isSubmitting() {
108
+ return getSummary().isSubmitting;
109
+ },
110
+ get isSubmitted() {
111
+ return getSummary().isSubmitted;
112
+ },
113
+ get isSubmitSuccessful() {
114
+ return getSummary().isSubmitSuccessful;
115
+ },
116
+ get submitCount() {
117
+ return getSummary().submitCount;
118
+ }
119
+ };
120
+ }
121
+
122
+ // src/solid/useRegister.ts
123
+ function useRegisterWithForm(form, first, ...rest) {
124
+ const shouldReturnList = Array.isArray(first) || rest.length > 0;
125
+ const options = normalizeRegisterOptions(first, rest);
126
+ useFieldSchemaRegistrations(form, options);
127
+ const snapshot = useFormSnapshot(form);
128
+ const bindings = options.map((option) => createRegisterProps(
129
+ form,
130
+ option,
131
+ () => getFieldState(form, snapshot(), option.name),
132
+ fieldPathToDomName(option.name)
133
+ ));
134
+ return shouldReturnList ? bindings : bindings[0];
135
+ }
136
+ function normalizeRegisterOptions(first, rest) {
137
+ if (Array.isArray(first)) {
138
+ return first;
139
+ }
140
+ if (rest.length > 0) {
141
+ return [first, ...rest];
142
+ }
143
+ return [first];
144
+ }
145
+
146
+ // src/solid/useForm.ts
147
+ function useForm(input) {
148
+ const isForm = isFormInstance(input);
149
+ if (!isForm && input.values !== void 0 && getOwner() === null) {
150
+ throw new TypeError("Reactive Solid form options require an active owner");
151
+ }
152
+ const form = isForm ? input : createFormFromOptions(input);
153
+ if (!isForm && input.values !== void 0) {
154
+ const synchronizeValues = createExternalValuesSynchronizer(form);
155
+ const values = input.values;
156
+ const resetOptions = input.resetOptions;
157
+ createRenderEffect(() => {
158
+ synchronizeValues(values(), resetOptions);
159
+ });
160
+ }
161
+ const useRegister = ((first, ...rest) => useRegisterWithForm(form, first, ...rest));
162
+ const useField = ((options) => useFieldWithForm(form, options));
163
+ const useFormState = () => useFormStateWithForm(form);
164
+ const handleSubmit = ((onValid, onInvalid) => createSubmitHandler(form, onValid, onInvalid));
165
+ return { form, useRegister, useField, useFormState, handleSubmit };
166
+ }
167
+
168
+ export { useForm };
169
+ //# sourceMappingURL=index.js.map
170
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/solid/RegisterBinding.ts","../../src/solid/useFieldSchemaRegistration.ts","../../src/solid/useFormSnapshot.ts","../../src/solid/useField.ts","../../src/solid/useFormState.ts","../../src/solid/useRegister.ts","../../src/solid/useForm.ts"],"names":["onCleanup"],"mappings":";;;;;AAKO,SAAS,mBAAA,CACd,IAAA,EACA,OAAA,EACA,QAAA,EACA,OAAA,EACwC;AACxC,EAAA,MAAM,OAAA,GAAU,gBAAA,CAAiB,IAAA,EAAM,OAAA,EAAS,UAAU,OAAO,CAAA;AACjE,EAAA,MAAM,KAAA,GAAQ;AAAA,IACZ,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,IAAI,KAAA,GAAQ;AACV,MAAA,OAAO,OAAA,CAAQ,KAAA;AAAA,IACjB,CAAA;AAAA,IACA,IAAI,OAAA,GAAU;AACZ,MAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IACjB,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,KAAA,KAAuD;AAC/D,MAAA,OAAA,CAAQ,KAAA,CAAM,MAAM,aAAiC,CAAA;AAAA,IACvD,CAAA;AAAA,IACA,QAAA,EAAU,CAAC,KAAA,KAAkD;AAC3D,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;AC/BO,SAAS,2BAAA,CAAqC,MAAqB,OAAA,EAA2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A,EAAM,WAAA,EAAa,QAAA,EAAU,cAAc,YAAA,EAAa;AACnE","file":"index.js","sourcesContent":["import type { FieldState, Form } from '../core/index';\nimport { createDomBinding, type FieldEventTarget, type RegisterOptions, fieldPathToDomName } from '../adapters/dom';\nimport type { SolidRegisterElement, SolidRegisterPropsForElement } from './types';\n\n/** Solid JSX spread용 binding props를 생성한다. */\nexport function createRegisterProps<TValues, TElement extends SolidRegisterElement>(\n form: Form<TValues>,\n options: RegisterOptions,\n getField: () => Readonly<FieldState>,\n domName: string,\n): SolidRegisterPropsForElement<TElement> {\n const binding = createDomBinding(form, options, getField, domName);\n const props = {\n name: binding.name,\n type: binding.type,\n get value() {\n return binding.value;\n },\n get checked() {\n return binding.checked;\n },\n onInput: (event: InputEvent & { currentTarget: HTMLElement }) => {\n binding.input(event.currentTarget as FieldEventTarget);\n },\n onChange: (event: Event & { currentTarget: 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 SolidRegisterPropsForElement<TElement>;\n}\n\nexport { fieldPathToDomName };\n","import { onCleanup } from 'solid-js';\nimport type { Form } from '../core/index';\nimport type { RegisterOptions } from './types';\n\n/** field-local schema를 Solid owner lifecycle에 맞춰 등록한다. */\nexport function useFieldSchemaRegistrations<TValues>(form: Form<TValues>, options: readonly RegisterOptions[]): void {\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 if (cleanups.length === 0) {\n return;\n }\n\n onCleanup(() => {\n cleanups.forEach(cleanup => cleanup());\n });\n}\n","import { createSignal, onCleanup, type Accessor } from 'solid-js';\nimport type { Form, FormState } from '../core/index';\n\n/** core form snapshot을 Solid signal로 연결한다. */\nexport function useFormSnapshot<TValues>(form: Form<TValues>): Accessor<Readonly<FormState<TValues>>> {\n const [snapshot, setSnapshot] = createSignal<Readonly<FormState<TValues>>>(form.getState(), { equals: false });\n const unsubscribe = form.subscribe(() => {\n setSnapshot(form.getState());\n });\n\n onCleanup(unsubscribe);\n\n return snapshot;\n}\n","import type { Form } from '../core/index';\nimport { getFieldState } from '../adapters/dom';\nimport { createRegisterProps, fieldPathToDomName } from './RegisterBinding';\nimport type { RegisterOptions, SolidFieldReturn, SolidRegisterElement, SolidRegisterPropsForElement } from './types';\nimport { useFieldSchemaRegistrations } from './useFieldSchemaRegistration';\nimport { useFormSnapshot } from './useFormSnapshot';\n\n/** 한 field의 binding, value, meta, setter를 함께 반환한다. */\nexport function useFieldWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): SolidFieldReturn<SolidRegisterPropsForElement<TElement>> {\n useFieldSchemaRegistrations(form, [options]);\n\n const snapshot = useFormSnapshot(form);\n const getField = () => getFieldState(form, snapshot(), options.name);\n const props = createRegisterProps<TValues, TElement>(form, options, getField, fieldPathToDomName(options.name));\n\n return {\n props,\n get value() {\n return getField().value;\n },\n setValue(value: unknown) {\n form.setValue(options.name, value, { source: 'program' });\n },\n get errors() {\n return [...getField().errors];\n },\n get dirty() {\n return getField().dirty;\n },\n get touched() {\n return getField().touched;\n },\n };\n}\n","import type { Form } from '../core/index';\nimport { createFormStateSummary } from '../adapters/FormStateSummary';\nimport type { SolidFormStateReturn } from './types';\nimport { useFormSnapshot } from './useFormSnapshot';\n\n/** form 전체 상태에서 Solid UI가 자주 쓰는 aggregate state를 반환한다. */\nexport function useFormStateWithForm<TValues>(form: Form<TValues>): SolidFormStateReturn<TValues> {\n const snapshot = useFormSnapshot(form);\n const getSummary = () => createFormStateSummary(snapshot());\n\n return {\n get state() {\n return snapshot();\n },\n get errors() {\n return getSummary().errors;\n },\n get dirtyFields() {\n return getSummary().dirtyFields;\n },\n get touchedFields() {\n return getSummary().touchedFields;\n },\n get focusedField() {\n return getSummary().focusedField;\n },\n get isDirty() {\n return getSummary().isDirty;\n },\n get isValid() {\n return getSummary().isValid;\n },\n get isSubmitting() {\n return getSummary().isSubmitting;\n },\n get isSubmitted() {\n return getSummary().isSubmitted;\n },\n get isSubmitSuccessful() {\n return getSummary().isSubmitSuccessful;\n },\n get submitCount() {\n return getSummary().submitCount;\n },\n };\n}\n","import type { Form } from '../core/index';\nimport { getFieldState } from '../adapters/dom';\nimport { createRegisterProps, fieldPathToDomName } from './RegisterBinding';\nimport type { RegisterOptions, SolidRegisterElement, SolidRegisterPropsForElement, SolidRegisterPropsList } from './types';\nimport { useFieldSchemaRegistrations } from './useFieldSchemaRegistration';\nimport { useFormSnapshot } from './useFormSnapshot';\n\nexport function useRegisterWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): SolidRegisterPropsForElement<TElement>;\nexport function useRegisterWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, options: TOptions): SolidRegisterPropsList<TElement, TOptions>;\nexport function useRegisterWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, ...options: TOptions): SolidRegisterPropsList<TElement, TOptions>;\nexport function useRegisterWithForm<TValues>(form: Form<TValues>, first: RegisterOptions | readonly RegisterOptions[], ...rest: readonly RegisterOptions[]): SolidRegisterPropsForElement<SolidRegisterElement> | SolidRegisterPropsForElement<SolidRegisterElement>[];\n\n/** 단일 또는 여러 field의 Solid binding props를 만든다. */\nexport function useRegisterWithForm<TValues>(\n form: Form<TValues>,\n first: RegisterOptions | readonly RegisterOptions[],\n ...rest: readonly RegisterOptions[]\n): SolidRegisterPropsForElement<SolidRegisterElement> | SolidRegisterPropsForElement<SolidRegisterElement>[] {\n const shouldReturnList = Array.isArray(first) || rest.length > 0;\n const options = normalizeRegisterOptions(first, rest);\n\n useFieldSchemaRegistrations(form, options);\n\n const snapshot = useFormSnapshot(form);\n const bindings = options.map(option => createRegisterProps(\n form,\n option,\n () => getFieldState(form, snapshot(), option.name),\n fieldPathToDomName(option.name),\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 { createRenderEffect, getOwner } from 'solid-js';\nimport { createSubmitHandler } from '../adapters/dom';\nimport {\n createExternalValuesSynchronizer,\n createFormFromOptions,\n isFormInstance,\n type FormInput,\n} from '../adapters/FormInput';\nimport type { Form } from '../core/index';\nimport type { RegisterOptions, SolidForm, SolidFormOptions } from './types';\nimport { useFieldWithForm } from './useField';\nimport { useFormStateWithForm } from './useFormState';\nimport { useRegisterWithForm } from './useRegister';\n\n/** Solid helper surface를 core Form 인스턴스에 바인딩한다. */\nexport function useForm<TValues>(form: Form<TValues>): SolidForm<TValues>;\nexport function useForm<TValues>(options: SolidFormOptions<TValues>): SolidForm<TValues>;\nexport function useForm<TValues>(input: FormInput<TValues, SolidFormOptions<TValues>>): SolidForm<TValues> {\n const isForm = isFormInstance(input);\n if (!isForm && input.values !== undefined && getOwner() === null) {\n throw new TypeError('Reactive Solid form options require an active owner');\n }\n\n const form = isForm ? input : createFormFromOptions(input);\n if (!isForm && input.values !== undefined) {\n const synchronizeValues = createExternalValuesSynchronizer(form);\n const values = input.values;\n const resetOptions = input.resetOptions;\n createRenderEffect(() => {\n synchronizeValues(values(), resetOptions);\n });\n }\n\n const useRegister = ((first: RegisterOptions | readonly RegisterOptions[], ...rest: readonly RegisterOptions[]) => useRegisterWithForm(form, first, ...rest)) as SolidForm<TValues>['useRegister'];\n const useField = ((options: RegisterOptions) => useFieldWithForm(form, options)) as SolidForm<TValues>['useField'];\n const useFormState = (): ReturnType<SolidForm<TValues>['useFormState']> => useFormStateWithForm(form);\n const handleSubmit = ((onValid, onInvalid) => createSubmitHandler(form, onValid, onInvalid)) as SolidForm<TValues>['handleSubmit'];\n\n return { form, useRegister, useField, useFormState, handleSubmit };\n}\n"]}
@@ -1,2 +1,68 @@
1
- export { useForm } from './useForm';
2
- export type { RegisterOptions, } from './types';
1
+ import { a as FormState, e as FormError, F as Form } from '../types-DBlvL6AC.js';
2
+ import { Action } from 'svelte/action';
3
+ import { Readable } from 'svelte/store';
4
+ import { a as RegisterOptions, R as ReactiveFormOptions, S as SubmitValidHandler, b as SubmitInvalidHandler, c as SubmitHandler } from '../FormInput-DuT7QFe-.js';
5
+
6
+ type FormStateSummary<TValues> = {
7
+ state: Readonly<FormState<TValues>>;
8
+ errors: Record<string, FormError[]>;
9
+ dirtyFields: Record<string, true>;
10
+ touchedFields: Record<string, true>;
11
+ /**
12
+ * 현재 focus 된 field의 PathKey 중 하나를 반환하거나 focus 된 field가 없으면 null을 반환한다.
13
+ *
14
+ * @remarks
15
+ * core는 DOM과 독립적으로 동작하므로 focus() 호출로 여러 field가 동시에 isFocused: true가 될 수 있다.
16
+ * 이 값은 entries 순서상 첫 번째로 발견된 focused field이지 "마지막으로 focus 된 field"가 아니다.
17
+ * DOM 어댑터에서는 브라우저가 이전 element의 blur를 자연스럽게 발생시켜 항상 1개 이하가 유지되지만,
18
+ * core를 직접 사용할 때는 여러 field가 focus 될 수 있으므로 이 값만으로 전체 focus 상태를 파악하면 안 된다.
19
+ * 모든 focused field를 알려면 state.fields를 직접 순회하라.
20
+ */
21
+ focusedField: string | null;
22
+ isDirty: boolean;
23
+ isValid: boolean;
24
+ isSubmitting: boolean;
25
+ isSubmitted: boolean;
26
+ isSubmitSuccessful: boolean;
27
+ submitCount: number;
28
+ };
29
+
30
+ /** Svelte component가 외부 values readable과 함께 form을 만들 때 쓰는 옵션이다. */
31
+ type SvelteFormOptions<TValues> = ReactiveFormOptions<TValues, Readable<TValues | undefined>>;
32
+ type SvelteRegisterAction = Action<HTMLElement, RegisterOptions>;
33
+ /** Svelte store 구독으로 갱신되는 한 field의 value와 meta snapshot이다. */
34
+ type SvelteFieldSnapshot = {
35
+ /** 현재 field value다. */
36
+ readonly value: unknown;
37
+ /** 현재 field에 붙어 있는 validation errors다. */
38
+ readonly errors: readonly FormError[];
39
+ /** 현재 값이 initial value와 다른지 여부다. */
40
+ readonly dirty: boolean;
41
+ /** field가 한 번 이상 blur 되었는지 여부다. */
42
+ readonly touched: boolean;
43
+ };
44
+ /** 한 field의 readable snapshot, binding action, setter를 함께 제공한다. */
45
+ type SvelteFieldReturn = Readable<SvelteFieldSnapshot> & {
46
+ /** `<input use:props />`에 바로 전달할 수 있는, options가 고정된 register action이다. */
47
+ readonly props: SvelteRegisterAction;
48
+ /** field value를 programmatic하게 갱신한다. */
49
+ setValue(value: unknown): void;
50
+ };
51
+ /** `useForm(form)`이 반환하는 Svelte action 중심 surface다. */
52
+ type SvelteForm<TValues> = {
53
+ form: Form<TValues>;
54
+ /** `<input use:register={{ name: 'email' }} />`처럼 사용하는 Svelte action이다. */
55
+ register: SvelteRegisterAction;
56
+ /** 한 field의 readable snapshot, binding, setter를 함께 반환한다. */
57
+ useField(options: RegisterOptions): SvelteFieldReturn;
58
+ /** form-wide aggregate state를 Svelte readable store로 반환한다. */
59
+ useFormState(): Readable<FormStateSummary<TValues>>;
60
+ /** submit event를 막고 core submit 흐름을 실행하는 handler factory다. */
61
+ handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<Event, TResult>;
62
+ };
63
+
64
+ /** Svelte action surface를 core Form 인스턴스에 바인딩한다. */
65
+ declare function useForm<TValues>(form: Form<TValues>): SvelteForm<TValues>;
66
+ declare function useForm<TValues>(options: SvelteFormOptions<TValues>): SvelteForm<TValues>;
67
+
68
+ export { RegisterOptions, type SvelteFieldReturn, type SvelteFieldSnapshot, type SvelteFormOptions, useForm };