@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/solid/index.js
CHANGED
|
@@ -1,117 +1,170 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { isFormInstance, createFormFromOptions, createExternalValuesSynchronizer, createSubmitHandler, fieldPathToDomName, getFieldState, createDomBinding, createFormStateSummary } from '../chunk-OBMSHDV2.js';
|
|
2
|
+
import '../chunk-EPQC3LKB.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,
|
|
8
11
|
get value() {
|
|
9
|
-
return
|
|
12
|
+
return binding.value;
|
|
10
13
|
},
|
|
11
14
|
get checked() {
|
|
12
|
-
return
|
|
15
|
+
return binding.checked;
|
|
13
16
|
},
|
|
14
|
-
onInput: (
|
|
15
|
-
|
|
17
|
+
onInput: (event) => {
|
|
18
|
+
binding.input(event.currentTarget);
|
|
16
19
|
},
|
|
17
|
-
onChange: (
|
|
18
|
-
|
|
20
|
+
onChange: (event) => {
|
|
21
|
+
binding.change(event.currentTarget);
|
|
19
22
|
},
|
|
20
23
|
onBlur: () => {
|
|
21
|
-
|
|
24
|
+
binding.blur();
|
|
22
25
|
},
|
|
23
26
|
onFocus: () => {
|
|
24
|
-
|
|
27
|
+
binding.focus();
|
|
25
28
|
}
|
|
26
29
|
};
|
|
30
|
+
return props;
|
|
27
31
|
}
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
|
|
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());
|
|
32
44
|
});
|
|
33
45
|
}
|
|
34
|
-
function
|
|
35
|
-
const [
|
|
36
|
-
|
|
46
|
+
function useFormSnapshot(form) {
|
|
47
|
+
const [snapshot, setSnapshot] = createSignal(form.getState(), { equals: false });
|
|
48
|
+
const unsubscribe = form.subscribe(() => {
|
|
49
|
+
setSnapshot(form.getState());
|
|
37
50
|
});
|
|
38
|
-
|
|
51
|
+
onCleanup(unsubscribe);
|
|
52
|
+
return snapshot;
|
|
39
53
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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));
|
|
43
61
|
return {
|
|
44
|
-
props
|
|
62
|
+
props,
|
|
45
63
|
get value() {
|
|
46
|
-
return
|
|
64
|
+
return getField().value;
|
|
47
65
|
},
|
|
48
|
-
setValue(
|
|
49
|
-
|
|
66
|
+
setValue(value) {
|
|
67
|
+
form.setValue(options.name, value, { source: "program" });
|
|
50
68
|
},
|
|
51
69
|
get errors() {
|
|
52
|
-
return [...
|
|
70
|
+
return [...getField().errors];
|
|
53
71
|
},
|
|
54
72
|
get dirty() {
|
|
55
|
-
return
|
|
73
|
+
return getField().dirty;
|
|
56
74
|
},
|
|
57
75
|
get touched() {
|
|
58
|
-
return
|
|
76
|
+
return getField().touched;
|
|
59
77
|
}
|
|
60
78
|
};
|
|
61
79
|
}
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
|
|
81
|
+
// src/solid/useFormState.ts
|
|
82
|
+
function useFormStateWithForm(form) {
|
|
83
|
+
const snapshot = useFormSnapshot(form);
|
|
84
|
+
const getSummary = () => createFormStateSummary(snapshot());
|
|
64
85
|
return {
|
|
65
86
|
get state() {
|
|
66
|
-
return
|
|
87
|
+
return snapshot();
|
|
67
88
|
},
|
|
68
89
|
get errors() {
|
|
69
|
-
return
|
|
90
|
+
return getSummary().errors;
|
|
70
91
|
},
|
|
71
92
|
get dirtyFields() {
|
|
72
|
-
return
|
|
93
|
+
return getSummary().dirtyFields;
|
|
73
94
|
},
|
|
74
95
|
get touchedFields() {
|
|
75
|
-
return
|
|
96
|
+
return getSummary().touchedFields;
|
|
97
|
+
},
|
|
98
|
+
get focusedField() {
|
|
99
|
+
return getSummary().focusedField;
|
|
76
100
|
},
|
|
77
101
|
get isDirty() {
|
|
78
|
-
return
|
|
102
|
+
return getSummary().isDirty;
|
|
79
103
|
},
|
|
80
104
|
get isValid() {
|
|
81
|
-
return
|
|
105
|
+
return getSummary().isValid;
|
|
82
106
|
},
|
|
83
107
|
get isSubmitting() {
|
|
84
|
-
return
|
|
108
|
+
return getSummary().isSubmitting;
|
|
85
109
|
},
|
|
86
110
|
get isSubmitted() {
|
|
87
|
-
return
|
|
111
|
+
return getSummary().isSubmitted;
|
|
88
112
|
},
|
|
89
113
|
get isSubmitSuccessful() {
|
|
90
|
-
return
|
|
114
|
+
return getSummary().isSubmitSuccessful;
|
|
91
115
|
},
|
|
92
116
|
get submitCount() {
|
|
93
|
-
return
|
|
117
|
+
return getSummary().submitCount;
|
|
94
118
|
}
|
|
95
119
|
};
|
|
96
120
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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)
|
|
105
133
|
));
|
|
106
|
-
return
|
|
134
|
+
return shouldReturnList ? bindings : bindings[0];
|
|
107
135
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
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];
|
|
110
144
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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 };
|
|
114
166
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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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,EAAA,MAAM,WAAA,IAAe,CAAC,KAAA,EAAA,GAAwD,IAAA,KAAqC,oBAAoB,IAAA,EAAM,KAAA,EAAO,GAAG,IAAI,CAAA,CAAA;AAC3J,EAAA,MAAM,QAAA,IAAY,CAAC,OAAA,KAA6B,gBAAA,CAAiB,MAAM,OAAO,CAAA,CAAA;AAC9E,EAAA,MAAM,YAAA,GAAe,MAAsD,oBAAA,CAAqB,IAAI,CAAA;AACpG,EAAA,MAAM,gBAAgB,CAAC,OAAA,EAAS,cAAc,mBAAA,CAAoB,IAAA,EAAM,SAAS,SAAS,CAAA,CAAA;AAE1F,EAAA,OAAO,EAAE,IAAA,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"]}
|
package/dist/svelte/index.d.ts
CHANGED
|
@@ -1,2 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 };
|
package/dist/svelte/index.js
CHANGED
|
@@ -1,111 +1,198 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}, f = () => {
|
|
20
|
-
u().focus();
|
|
1
|
+
import { isFormInstance, createFormFromOptions, createExternalValuesSynchronizer, createSubmitHandler, createFormStateSummary, getFieldState, createDomBinding, fieldPathToDomName } from '../chunk-OBMSHDV2.js';
|
|
2
|
+
import '../chunk-EPQC3LKB.js';
|
|
3
|
+
import { onDestroy } from 'svelte';
|
|
4
|
+
import { readable } from 'svelte/store';
|
|
5
|
+
|
|
6
|
+
// src/svelte/RegisterAction.ts
|
|
7
|
+
function createRegisterAction(form) {
|
|
8
|
+
return (node, initialOptions) => {
|
|
9
|
+
let options = initialOptions;
|
|
10
|
+
let cleanupSchema = registerSchema(form, options);
|
|
11
|
+
const getBinding = () => createDomBinding(
|
|
12
|
+
form,
|
|
13
|
+
resolveOptionsFromNode(node, options),
|
|
14
|
+
() => getFieldState(form, form.getState(), options.name),
|
|
15
|
+
fieldPathToDomName(options.name)
|
|
16
|
+
);
|
|
17
|
+
const syncNode = () => {
|
|
18
|
+
applyBindingToNode(node, getBinding(), options);
|
|
21
19
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const onInput = (event) => {
|
|
21
|
+
getBinding().input(event.currentTarget);
|
|
22
|
+
};
|
|
23
|
+
const onChange = (event) => {
|
|
24
|
+
getBinding().change(event.currentTarget);
|
|
25
|
+
};
|
|
26
|
+
const onBlur = () => {
|
|
27
|
+
getBinding().blur();
|
|
28
|
+
};
|
|
29
|
+
const onFocus = () => {
|
|
30
|
+
getBinding().focus();
|
|
31
|
+
};
|
|
32
|
+
node.addEventListener("input", onInput);
|
|
33
|
+
node.addEventListener("change", onChange);
|
|
34
|
+
node.addEventListener("blur", onBlur);
|
|
35
|
+
node.addEventListener("focus", onFocus);
|
|
36
|
+
const unsubscribe = form.subscribe(syncNode);
|
|
37
|
+
syncNode();
|
|
38
|
+
return {
|
|
39
|
+
update(nextOptions) {
|
|
40
|
+
cleanupSchema();
|
|
41
|
+
options = nextOptions;
|
|
42
|
+
cleanupSchema = registerSchema(form, options);
|
|
43
|
+
syncNode();
|
|
27
44
|
},
|
|
28
45
|
destroy() {
|
|
29
|
-
|
|
46
|
+
unsubscribe();
|
|
47
|
+
cleanupSchema();
|
|
48
|
+
node.removeEventListener("input", onInput);
|
|
49
|
+
node.removeEventListener("change", onChange);
|
|
50
|
+
node.removeEventListener("blur", onBlur);
|
|
51
|
+
node.removeEventListener("focus", onFocus);
|
|
30
52
|
}
|
|
31
53
|
};
|
|
32
54
|
};
|
|
33
55
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
function registerSchema(form, options) {
|
|
57
|
+
if (!options.schema) {
|
|
58
|
+
return () => void 0;
|
|
59
|
+
}
|
|
60
|
+
return form.registerFieldSchema(options.name, { schema: options.schema, schemaOptions: options.schemaOptions });
|
|
37
61
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
function resolveOptionsFromNode(node, options) {
|
|
63
|
+
if (options.type !== void 0 || !(node instanceof HTMLInputElement)) {
|
|
64
|
+
return options;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
...options,
|
|
68
|
+
type: node.type || "text"
|
|
42
69
|
};
|
|
43
70
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
function applyBindingToNode(node, binding, options) {
|
|
72
|
+
setNodeName(node, binding.name);
|
|
73
|
+
if (node instanceof HTMLInputElement) {
|
|
74
|
+
applyInputBinding(node, binding, options);
|
|
47
75
|
return;
|
|
48
76
|
}
|
|
49
|
-
if (
|
|
50
|
-
|
|
77
|
+
if (node instanceof HTMLSelectElement) {
|
|
78
|
+
applySelectBinding(node, binding);
|
|
51
79
|
return;
|
|
52
80
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
81
|
+
if (node instanceof HTMLTextAreaElement) {
|
|
82
|
+
setStringValue(node, binding.value);
|
|
55
83
|
return;
|
|
56
84
|
}
|
|
57
|
-
|
|
85
|
+
applyCustomBinding(node, binding);
|
|
58
86
|
}
|
|
59
|
-
function
|
|
60
|
-
if ("name" in
|
|
61
|
-
|
|
87
|
+
function setNodeName(node, name) {
|
|
88
|
+
if ("name" in node) {
|
|
89
|
+
node.name = name;
|
|
62
90
|
return;
|
|
63
91
|
}
|
|
64
|
-
|
|
92
|
+
node.setAttribute("name", name);
|
|
65
93
|
}
|
|
66
|
-
function
|
|
67
|
-
if (
|
|
68
|
-
|
|
94
|
+
function applyInputBinding(node, binding, options) {
|
|
95
|
+
if (options.type !== void 0 && node.type !== options.type) {
|
|
96
|
+
node.type = options.type;
|
|
97
|
+
}
|
|
98
|
+
if (node.type === "checkbox" || node.type === "radio") {
|
|
99
|
+
if (binding.value !== void 0) {
|
|
100
|
+
node.value = String(Array.isArray(binding.value) ? binding.value[0] : binding.value);
|
|
101
|
+
}
|
|
102
|
+
node.checked = Boolean(binding.checked);
|
|
69
103
|
return;
|
|
70
104
|
}
|
|
71
|
-
|
|
105
|
+
setStringValue(node, binding.value);
|
|
72
106
|
}
|
|
73
|
-
function
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
const
|
|
77
|
-
Array.from(
|
|
78
|
-
|
|
107
|
+
function applySelectBinding(node, binding) {
|
|
108
|
+
const value = binding.value;
|
|
109
|
+
if (node.multiple) {
|
|
110
|
+
const values = new Set((Array.isArray(value) ? value : value === void 0 ? [] : [value]).map(String));
|
|
111
|
+
Array.from(node.options).forEach((option) => {
|
|
112
|
+
option.selected = values.has(option.value);
|
|
79
113
|
});
|
|
80
114
|
return;
|
|
81
115
|
}
|
|
82
|
-
|
|
116
|
+
setStringValue(node, value);
|
|
83
117
|
}
|
|
84
|
-
function
|
|
85
|
-
const
|
|
86
|
-
|
|
118
|
+
function setStringValue(node, value) {
|
|
119
|
+
const nextValue = value === void 0 ? "" : String(Array.isArray(value) ? value[0] ?? "" : value);
|
|
120
|
+
if (node.value !== nextValue) {
|
|
121
|
+
node.value = nextValue;
|
|
122
|
+
}
|
|
87
123
|
}
|
|
88
|
-
function
|
|
89
|
-
"value" in
|
|
124
|
+
function applyCustomBinding(node, binding) {
|
|
125
|
+
if ("value" in node) {
|
|
126
|
+
node.value = binding.value;
|
|
127
|
+
}
|
|
128
|
+
if ("checked" in node) {
|
|
129
|
+
node.checked = Boolean(binding.checked);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function useFieldWithForm(form, options) {
|
|
133
|
+
const props = createBoundRegisterAction(form, options);
|
|
134
|
+
const getSnapshot = () => {
|
|
135
|
+
const field2 = getFieldState(form, form.getState(), options.name);
|
|
136
|
+
return {
|
|
137
|
+
dirty: field2.dirty,
|
|
138
|
+
errors: [...field2.errors],
|
|
139
|
+
touched: field2.touched,
|
|
140
|
+
value: field2.value
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const field = readable(getSnapshot(), (set) => {
|
|
144
|
+
set(getSnapshot());
|
|
145
|
+
return form.subscribe(() => set(getSnapshot()));
|
|
146
|
+
});
|
|
147
|
+
return Object.assign(field, {
|
|
148
|
+
props,
|
|
149
|
+
setValue(value) {
|
|
150
|
+
form.setValue(options.name, value, { source: "program" });
|
|
151
|
+
}
|
|
152
|
+
});
|
|
90
153
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})));
|
|
154
|
+
function createBoundRegisterAction(form, options) {
|
|
155
|
+
const register = createRegisterAction(form);
|
|
156
|
+
return (node, overrideOptions) => register(node, overrideOptions ?? options);
|
|
95
157
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
158
|
+
function useFormStateWithForm(form) {
|
|
159
|
+
return readable(createFormStateSummary(form.getState()), (set) => {
|
|
160
|
+
set(createFormStateSummary(form.getState()));
|
|
161
|
+
return form.subscribe(() => {
|
|
162
|
+
set(createFormStateSummary(form.getState()));
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/svelte/useForm.ts
|
|
168
|
+
function useForm(input) {
|
|
169
|
+
const form = isFormInstance(input) ? input : createFormFromOptions(input);
|
|
170
|
+
if (!isFormInstance(input) && input.values !== void 0) {
|
|
171
|
+
const synchronizeValues = createExternalValuesSynchronizer(form);
|
|
172
|
+
const resetOptions = input.resetOptions;
|
|
173
|
+
let unsubscribe;
|
|
174
|
+
onDestroy(() => {
|
|
175
|
+
unsubscribe?.();
|
|
176
|
+
});
|
|
177
|
+
unsubscribe = input.values.subscribe((values) => {
|
|
178
|
+
synchronizeValues(values, resetOptions);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
98
181
|
return {
|
|
99
|
-
form
|
|
100
|
-
register:
|
|
182
|
+
form,
|
|
183
|
+
register: createRegisterAction(form),
|
|
184
|
+
useField(options) {
|
|
185
|
+
return useFieldWithForm(form, options);
|
|
186
|
+
},
|
|
101
187
|
useFormState() {
|
|
102
|
-
return
|
|
188
|
+
return useFormStateWithForm(form);
|
|
103
189
|
},
|
|
104
|
-
handleSubmit(
|
|
105
|
-
return
|
|
190
|
+
handleSubmit(onValid, onInvalid) {
|
|
191
|
+
return createSubmitHandler(form, onValid, onInvalid);
|
|
106
192
|
}
|
|
107
193
|
};
|
|
108
194
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
195
|
+
|
|
196
|
+
export { useForm };
|
|
197
|
+
//# sourceMappingURL=index.js.map
|
|
198
|
+
//# sourceMappingURL=index.js.map
|