@ilokesto/form 1.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.
Files changed (74) hide show
  1. package/README.ko.md +1276 -0
  2. package/README.md +1277 -0
  3. package/dist/FormStateSummary-YyGT9nfY.js +124 -0
  4. package/dist/adapters/FormStateSummary.d.ts +12 -0
  5. package/dist/adapters/dom/FieldValue.d.ts +2 -0
  6. package/dist/adapters/dom/RegisterBinding.d.ts +14 -0
  7. package/dist/adapters/dom/index.d.ts +3 -0
  8. package/dist/adapters/dom/types.d.ts +22 -0
  9. package/dist/core/array/ArrayItemReorder.d.ts +6 -0
  10. package/dist/core/array/ArrayKeyGenerator.d.ts +4 -0
  11. package/dist/core/array/FormArrayController.d.ts +21 -0
  12. package/dist/core/array/FormArrayFactory.d.ts +8 -0
  13. package/dist/core/array/FormArrayMutationPlanner.d.ts +14 -0
  14. package/dist/core/array/FormArrayPath.d.ts +6 -0
  15. package/dist/core/array/FormArrayRebaser.d.ts +7 -0
  16. package/dist/core/array/index.d.ts +1 -0
  17. package/dist/core/form/CreateForm.d.ts +23 -0
  18. package/dist/core/form/FormFieldCommands.d.ts +15 -0
  19. package/dist/core/form/FormSubmitter.d.ts +9 -0
  20. package/dist/core/form/index.d.ts +1 -0
  21. package/dist/core/index.d.ts +2 -0
  22. package/dist/core/path/FormPath.d.ts +9 -0
  23. package/dist/core/path/index.d.ts +1 -0
  24. package/dist/core/state/FieldStateFactory.d.ts +6 -0
  25. package/dist/core/state/FormStateInitializer.d.ts +7 -0
  26. package/dist/core/state/FormStateReader.d.ts +11 -0
  27. package/dist/core/state/FormStateStore.d.ts +23 -0
  28. package/dist/core/state/FormStateWriter.d.ts +16 -0
  29. package/dist/core/state/index.d.ts +1 -0
  30. package/dist/core/types.d.ts +96 -0
  31. package/dist/core/validation/StandardSchemaValidator.d.ts +14 -0
  32. package/dist/core/validation/ValidationEngine.d.ts +25 -0
  33. package/dist/core/validation/index.d.ts +1 -0
  34. package/dist/core/value/ValueHelper.d.ts +7 -0
  35. package/dist/core/value/index.d.ts +1 -0
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.js +1245 -0
  38. package/dist/react/RegisterBinding.d.ts +5 -0
  39. package/dist/react/index.d.ts +2 -0
  40. package/dist/react/index.js +83 -0
  41. package/dist/react/types.d.ts +64 -0
  42. package/dist/react/useField.d.ts +3 -0
  43. package/dist/react/useFieldSchemaRegistration.d.ts +4 -0
  44. package/dist/react/useForm.d.ts +3 -0
  45. package/dist/react/useFormSnapshot.d.ts +2 -0
  46. package/dist/react/useFormState.d.ts +3 -0
  47. package/dist/react/useRegister.d.ts +6 -0
  48. package/dist/solid/RegisterBinding.d.ts +5 -0
  49. package/dist/solid/index.d.ts +2 -0
  50. package/dist/solid/index.js +110 -0
  51. package/dist/solid/types.d.ts +68 -0
  52. package/dist/solid/useField.d.ts +3 -0
  53. package/dist/solid/useFieldSchemaRegistration.d.ts +3 -0
  54. package/dist/solid/useForm.d.ts +3 -0
  55. package/dist/solid/useFormSnapshot.d.ts +3 -0
  56. package/dist/solid/useFormState.d.ts +3 -0
  57. package/dist/solid/useRegister.d.ts +6 -0
  58. package/dist/svelte/RegisterAction.d.ts +4 -0
  59. package/dist/svelte/index.d.ts +2 -0
  60. package/dist/svelte/index.js +107 -0
  61. package/dist/svelte/types.d.ts +12 -0
  62. package/dist/svelte/useForm.d.ts +3 -0
  63. package/dist/svelte/useFormState.d.ts +4 -0
  64. package/dist/vue/RegisterBinding.d.ts +5 -0
  65. package/dist/vue/index.d.ts +2 -0
  66. package/dist/vue/index.js +110 -0
  67. package/dist/vue/types.d.ts +68 -0
  68. package/dist/vue/useField.d.ts +3 -0
  69. package/dist/vue/useFieldSchemaRegistration.d.ts +3 -0
  70. package/dist/vue/useForm.d.ts +3 -0
  71. package/dist/vue/useFormSnapshot.d.ts +3 -0
  72. package/dist/vue/useFormState.d.ts +3 -0
  73. package/dist/vue/useRegister.d.ts +6 -0
  74. package/package.json +93 -0
@@ -0,0 +1,5 @@
1
+ import type { FieldState, Form } from '../core/index.js';
2
+ import { type RegisterOptions, fieldPathToDomName } from '../adapters/dom.js';
3
+ import type { RegisterElement, RegisterPropsForElement } from './types.js';
4
+ export declare function createRegisterProps<TValues, TElement extends RegisterElement>(form: Form<TValues>, options: RegisterOptions, field: Readonly<FieldState>, domName: string): RegisterPropsForElement<TElement>;
5
+ export { fieldPathToDomName };
@@ -0,0 +1,2 @@
1
+ export { useForm } from './useForm.js';
2
+ export type { RegisterOptions, } from './types.js';
@@ -0,0 +1,83 @@
1
+ import { useEffect as h, useSyncExternalStore as S, useMemo as i, useCallback as y } from "react";
2
+ import { c as p, f as m, g as l, a as R } from "../FormStateSummary-YyGT9nfY.js";
3
+ function d(e, t, s, a) {
4
+ const n = p(e, t, () => s, a);
5
+ return {
6
+ name: n.name,
7
+ type: n.type,
8
+ value: n.value,
9
+ checked: n.checked,
10
+ onChange: (c) => {
11
+ n.change(c.currentTarget);
12
+ },
13
+ onBlur: () => {
14
+ n.blur();
15
+ },
16
+ onFocus: () => {
17
+ n.focus();
18
+ }
19
+ };
20
+ }
21
+ function b(e, t) {
22
+ const { name: s, schema: a, schemaOptions: n } = t;
23
+ h(() => {
24
+ if (a)
25
+ return e.registerFieldSchema(s, { schema: a, schemaOptions: n });
26
+ }, [e, s, a, n]);
27
+ }
28
+ function v(e, t) {
29
+ const s = t.map((a) => `${m(a.name)}:${a.schema ? "schema" : "none"}`).join("|");
30
+ h(() => {
31
+ const a = t.flatMap((n) => n.schema ? [e.registerFieldSchema(n.name, { schema: n.schema, schemaOptions: n.schemaOptions })] : []);
32
+ return () => {
33
+ a.forEach((n) => n());
34
+ };
35
+ }, [e, t, s]);
36
+ }
37
+ function o(e) {
38
+ return S(
39
+ (t) => e.subscribe(t),
40
+ () => e.getState(),
41
+ () => e.getState()
42
+ );
43
+ }
44
+ function A(e, t) {
45
+ b(e, t);
46
+ const s = o(e), a = l(e, s, t.name), n = m(t.name), r = i(() => d(e, t, a, n), [e, t, a, n]), c = y((u) => {
47
+ e.setValue(t.name, u, { source: "program" });
48
+ }, [e, t.name]);
49
+ return i(() => ({
50
+ props: r,
51
+ value: a.value,
52
+ setValue: c,
53
+ errors: [...a.errors],
54
+ dirty: a.dirty,
55
+ touched: a.touched
56
+ }), [a, r, c]);
57
+ }
58
+ function O(e) {
59
+ const t = o(e);
60
+ return i(() => R(t), [t]);
61
+ }
62
+ function k(e, t, ...s) {
63
+ const a = Array.isArray(t) || s.length > 0, n = E(t, s);
64
+ v(e, n);
65
+ const r = o(e), c = i(
66
+ () => n.map((u) => {
67
+ const g = l(e, r, u.name), F = m(u.name);
68
+ return d(e, u, g, F);
69
+ }),
70
+ [e, n, r]
71
+ );
72
+ return a ? c : c[0];
73
+ }
74
+ function E(e, t) {
75
+ return Array.isArray(e) ? e : t.length > 0 ? [e, ...t] : [e];
76
+ }
77
+ function f(e) {
78
+ const t = ((n, ...r) => k(e, n, ...r)), s = ((n) => A(e, n)), a = () => O(e);
79
+ return i(() => ({ form: e, useRegister: t, useField: s, useFormState: a }), [e]);
80
+ }
81
+ export {
82
+ f as useForm
83
+ };
@@ -0,0 +1,64 @@
1
+ import type { ChangeEventHandler, FocusEventHandler, InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react';
2
+ import type { Form, FormError, FormState } from '../core/index.js';
3
+ import type { RegisterOptions } from '../adapters/dom.js';
4
+ export type { RegisterOptions } from '../adapters/dom.js';
5
+ type InputValue = InputHTMLAttributes<HTMLInputElement>['value'];
6
+ type InputType = InputHTMLAttributes<HTMLInputElement>['type'];
7
+ type SelectValue = SelectHTMLAttributes<HTMLSelectElement>['value'];
8
+ type TextareaValue = TextareaHTMLAttributes<HTMLTextAreaElement>['value'];
9
+ type BindingHandlers<TElement extends HTMLElement> = {
10
+ onChange: ChangeEventHandler<TElement>;
11
+ onBlur: FocusEventHandler<TElement>;
12
+ onFocus: FocusEventHandler<TElement>;
13
+ };
14
+ export type InputRegisterProps = BindingHandlers<HTMLInputElement> & {
15
+ name: string;
16
+ type: InputType;
17
+ value?: InputValue;
18
+ checked?: boolean;
19
+ };
20
+ export type SelectRegisterProps = BindingHandlers<HTMLSelectElement> & {
21
+ name: string;
22
+ value?: SelectValue;
23
+ };
24
+ export type TextareaRegisterProps = BindingHandlers<HTMLTextAreaElement> & {
25
+ name: string;
26
+ value?: TextareaValue;
27
+ };
28
+ export type CustomRegisterProps<TElement extends HTMLElement = HTMLElement> = BindingHandlers<TElement> & {
29
+ name: string;
30
+ value?: unknown;
31
+ checked?: boolean;
32
+ };
33
+ export type RegisterElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLElement;
34
+ export type RegisterPropsForElement<TElement extends RegisterElement> = TElement extends HTMLSelectElement ? SelectRegisterProps : TElement extends HTMLTextAreaElement ? TextareaRegisterProps : TElement extends HTMLInputElement ? InputRegisterProps : CustomRegisterProps<TElement>;
35
+ export type RegisterProps = RegisterPropsForElement<RegisterElement>;
36
+ export type UseFieldReturn<TProps extends RegisterProps = InputRegisterProps> = {
37
+ props: TProps;
38
+ value: unknown;
39
+ setValue: (value: unknown) => void;
40
+ errors: FormError[];
41
+ dirty: boolean;
42
+ touched: boolean;
43
+ };
44
+ export type UseFormStateReturn<TValues> = {
45
+ state: Readonly<FormState<TValues>>;
46
+ errors: Record<string, FormError[]>;
47
+ dirtyFields: Record<string, true>;
48
+ touchedFields: Record<string, true>;
49
+ isDirty: boolean;
50
+ isValid: boolean;
51
+ isSubmitting: boolean;
52
+ submitCount: number;
53
+ };
54
+ export type RegisterPropsList<TElement extends RegisterElement, TOptions extends readonly RegisterOptions[]> = {
55
+ [Index in keyof TOptions]: TOptions[Index] extends RegisterOptions ? RegisterPropsForElement<TElement> : never;
56
+ };
57
+ export type ReactForm<TValues> = {
58
+ form: Form<TValues>;
59
+ useRegister<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): RegisterPropsForElement<TElement>;
60
+ useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(options: TOptions): RegisterPropsList<TElement, TOptions>;
61
+ useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): RegisterPropsList<TElement, TOptions>;
62
+ useField<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): UseFieldReturn<RegisterPropsForElement<TElement>>;
63
+ useFormState(): UseFormStateReturn<TValues>;
64
+ };
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { RegisterElement, RegisterOptions, RegisterPropsForElement, UseFieldReturn } from './types.js';
3
+ export declare function useFieldWithForm<TValues, TElement extends RegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): UseFieldReturn<RegisterPropsForElement<TElement>>;
@@ -0,0 +1,4 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { RegisterOptions } from './types.js';
3
+ export declare function useFieldSchemaRegistration<TValues>(form: Form<TValues>, options: RegisterOptions): void;
4
+ export declare function useFieldSchemaRegistrations<TValues>(form: Form<TValues>, options: readonly RegisterOptions[]): void;
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { ReactForm } from './types.js';
3
+ export declare function useForm<TValues>(form: Form<TValues>): ReactForm<TValues>;
@@ -0,0 +1,2 @@
1
+ import type { Form, FormState } from '../core/index.js';
2
+ export declare function useFormSnapshot<TValues>(form: Form<TValues>): Readonly<FormState<TValues>>;
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { UseFormStateReturn } from './types.js';
3
+ export declare function useFormStateWithForm<TValues>(form: Form<TValues>): UseFormStateReturn<TValues>;
@@ -0,0 +1,6 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { RegisterElement, RegisterOptions, RegisterPropsForElement, RegisterPropsList } from './types.js';
3
+ export declare function useRegisterWithForm<TValues, TElement extends RegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): RegisterPropsForElement<TElement>;
4
+ export declare function useRegisterWithForm<TValues, TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, options: TOptions): RegisterPropsList<TElement, TOptions>;
5
+ export declare function useRegisterWithForm<TValues, TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, ...options: TOptions): RegisterPropsList<TElement, TOptions>;
6
+ export declare function useRegisterWithForm<TValues>(form: Form<TValues>, first: RegisterOptions | readonly RegisterOptions[], ...rest: readonly RegisterOptions[]): RegisterPropsForElement<RegisterElement> | RegisterPropsForElement<RegisterElement>[];
@@ -0,0 +1,5 @@
1
+ import type { FieldState, Form } from '../core/index.js';
2
+ import { type RegisterOptions, fieldPathToDomName } from '../adapters/dom.js';
3
+ import type { SolidRegisterElement, SolidRegisterPropsForElement } from './types.js';
4
+ export declare function createRegisterProps<TValues, TElement extends SolidRegisterElement>(form: Form<TValues>, options: RegisterOptions, getField: () => Readonly<FieldState>, domName: string): SolidRegisterPropsForElement<TElement>;
5
+ export { fieldPathToDomName };
@@ -0,0 +1,2 @@
1
+ export { useForm } from './useForm.js';
2
+ export type { RegisterOptions, } from './types.js';
@@ -0,0 +1,110 @@
1
+ import { c as d, f as o, g, a as p } from "../FormStateSummary-YyGT9nfY.js";
2
+ import { onCleanup as l, createSignal as F } from "solid-js";
3
+ function h(e, t, r, n) {
4
+ const s = d(e, t, r, n);
5
+ return {
6
+ name: s.name,
7
+ type: s.type,
8
+ get value() {
9
+ return s.value;
10
+ },
11
+ get checked() {
12
+ return s.checked;
13
+ },
14
+ onInput: (a) => {
15
+ s.input(a.currentTarget);
16
+ },
17
+ onChange: (a) => {
18
+ s.change(a.currentTarget);
19
+ },
20
+ onBlur: () => {
21
+ s.blur();
22
+ },
23
+ onFocus: () => {
24
+ s.focus();
25
+ }
26
+ };
27
+ }
28
+ function m(e, t) {
29
+ const r = t.flatMap((n) => n.schema ? [e.registerFieldSchema(n.name, { schema: n.schema, schemaOptions: n.schemaOptions })] : []);
30
+ r.length !== 0 && l(() => {
31
+ r.forEach((n) => n());
32
+ });
33
+ }
34
+ function c(e) {
35
+ const [t, r] = F(e.getState(), { equals: !1 }), n = e.subscribe(() => {
36
+ r(e.getState());
37
+ });
38
+ return l(n), t;
39
+ }
40
+ function S(e, t) {
41
+ m(e, [t]);
42
+ const r = c(e), n = () => g(e, r(), t.name);
43
+ return {
44
+ props: h(e, t, n, o(t.name)),
45
+ get value() {
46
+ return n().value;
47
+ },
48
+ setValue(u) {
49
+ e.setValue(t.name, u, { source: "program" });
50
+ },
51
+ get errors() {
52
+ return [...n().errors];
53
+ },
54
+ get dirty() {
55
+ return n().dirty;
56
+ },
57
+ get touched() {
58
+ return n().touched;
59
+ }
60
+ };
61
+ }
62
+ function y(e) {
63
+ const t = c(e), r = () => p(t());
64
+ return {
65
+ get state() {
66
+ return t();
67
+ },
68
+ get errors() {
69
+ return r().errors;
70
+ },
71
+ get dirtyFields() {
72
+ return r().dirtyFields;
73
+ },
74
+ get touchedFields() {
75
+ return r().touchedFields;
76
+ },
77
+ get isDirty() {
78
+ return r().isDirty;
79
+ },
80
+ get isValid() {
81
+ return r().isValid;
82
+ },
83
+ get isSubmitting() {
84
+ return r().isSubmitting;
85
+ },
86
+ get submitCount() {
87
+ return r().submitCount;
88
+ }
89
+ };
90
+ }
91
+ function b(e, t, ...r) {
92
+ const n = Array.isArray(t) || r.length > 0, s = R(t, r);
93
+ m(e, s);
94
+ const u = c(e), a = s.map((i) => h(
95
+ e,
96
+ i,
97
+ () => g(e, u(), i.name),
98
+ o(i.name)
99
+ ));
100
+ return n ? a : a[0];
101
+ }
102
+ function R(e, t) {
103
+ return Array.isArray(e) ? e : t.length > 0 ? [e, ...t] : [e];
104
+ }
105
+ function A(e) {
106
+ return { form: e, useRegister: ((s, ...u) => b(e, s, ...u)), useField: ((s) => S(e, s)), useFormState: () => y(e) };
107
+ }
108
+ export {
109
+ A as useForm
110
+ };
@@ -0,0 +1,68 @@
1
+ import type { Form, FormError, FormState } from '../core/index.js';
2
+ import type { DomValue, RegisterOptions } from '../adapters/dom.js';
3
+ export type { RegisterOptions } from '../adapters/dom.js';
4
+ type SolidBindingHandlers<TElement extends HTMLElement> = {
5
+ onInput: (event: InputEvent & {
6
+ currentTarget: TElement;
7
+ }) => void;
8
+ onChange: (event: Event & {
9
+ currentTarget: TElement;
10
+ }) => void;
11
+ onBlur: (event: FocusEvent & {
12
+ currentTarget: TElement;
13
+ }) => void;
14
+ onFocus: (event: FocusEvent & {
15
+ currentTarget: TElement;
16
+ }) => void;
17
+ };
18
+ export type SolidInputRegisterProps = SolidBindingHandlers<HTMLInputElement> & {
19
+ readonly name: string;
20
+ readonly type: string;
21
+ readonly value?: DomValue;
22
+ readonly checked?: boolean;
23
+ };
24
+ export type SolidSelectRegisterProps = SolidBindingHandlers<HTMLSelectElement> & {
25
+ readonly name: string;
26
+ readonly value?: DomValue;
27
+ };
28
+ export type SolidTextareaRegisterProps = SolidBindingHandlers<HTMLTextAreaElement> & {
29
+ readonly name: string;
30
+ readonly value?: string | number;
31
+ };
32
+ export type SolidCustomRegisterProps<TElement extends HTMLElement = HTMLElement> = SolidBindingHandlers<TElement> & {
33
+ readonly name: string;
34
+ readonly value?: unknown;
35
+ readonly checked?: boolean;
36
+ };
37
+ export type SolidRegisterElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLElement;
38
+ export type SolidRegisterPropsForElement<TElement extends SolidRegisterElement> = TElement extends HTMLSelectElement ? SolidSelectRegisterProps : TElement extends HTMLTextAreaElement ? SolidTextareaRegisterProps : TElement extends HTMLInputElement ? SolidInputRegisterProps : SolidCustomRegisterProps<TElement>;
39
+ export type SolidRegisterProps = SolidRegisterPropsForElement<SolidRegisterElement>;
40
+ export type SolidRegisterPropsList<TElement extends SolidRegisterElement, TOptions extends readonly RegisterOptions[]> = {
41
+ [Index in keyof TOptions]: TOptions[Index] extends RegisterOptions ? SolidRegisterPropsForElement<TElement> : never;
42
+ };
43
+ export type SolidFieldReturn<TProps extends SolidRegisterProps = SolidInputRegisterProps> = {
44
+ readonly props: TProps;
45
+ readonly value: unknown;
46
+ setValue(value: unknown): void;
47
+ readonly errors: FormError[];
48
+ readonly dirty: boolean;
49
+ readonly touched: boolean;
50
+ };
51
+ export type SolidFormStateReturn<TValues> = {
52
+ readonly state: Readonly<FormState<TValues>>;
53
+ readonly errors: Record<string, FormError[]>;
54
+ readonly dirtyFields: Record<string, true>;
55
+ readonly touchedFields: Record<string, true>;
56
+ readonly isDirty: boolean;
57
+ readonly isValid: boolean;
58
+ readonly isSubmitting: boolean;
59
+ readonly submitCount: number;
60
+ };
61
+ export type SolidForm<TValues> = {
62
+ form: Form<TValues>;
63
+ useRegister<TElement extends SolidRegisterElement = HTMLInputElement>(options: RegisterOptions): SolidRegisterPropsForElement<TElement>;
64
+ useRegister<TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
65
+ useRegister<TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
66
+ useField<TElement extends SolidRegisterElement = HTMLInputElement>(options: RegisterOptions): SolidFieldReturn<SolidRegisterPropsForElement<TElement>>;
67
+ useFormState(): SolidFormStateReturn<TValues>;
68
+ };
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { RegisterOptions, SolidFieldReturn, SolidRegisterElement, SolidRegisterPropsForElement } from './types.js';
3
+ export declare function useFieldWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): SolidFieldReturn<SolidRegisterPropsForElement<TElement>>;
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { RegisterOptions } from './types.js';
3
+ export declare function useFieldSchemaRegistrations<TValues>(form: Form<TValues>, options: readonly RegisterOptions[]): void;
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { SolidForm } from './types.js';
3
+ export declare function useForm<TValues>(form: Form<TValues>): SolidForm<TValues>;
@@ -0,0 +1,3 @@
1
+ import { type Accessor } from 'solid-js';
2
+ import type { Form, FormState } from '../core/index.js';
3
+ export declare function useFormSnapshot<TValues>(form: Form<TValues>): Accessor<Readonly<FormState<TValues>>>;
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { SolidFormStateReturn } from './types.js';
3
+ export declare function useFormStateWithForm<TValues>(form: Form<TValues>): SolidFormStateReturn<TValues>;
@@ -0,0 +1,6 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { RegisterOptions, SolidRegisterElement, SolidRegisterPropsForElement, SolidRegisterPropsList } from './types.js';
3
+ export declare function useRegisterWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement>(form: Form<TValues>, options: RegisterOptions): SolidRegisterPropsForElement<TElement>;
4
+ export declare function useRegisterWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
5
+ export declare function useRegisterWithForm<TValues, TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(form: Form<TValues>, ...options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
6
+ export declare function useRegisterWithForm<TValues>(form: Form<TValues>, first: RegisterOptions | readonly RegisterOptions[], ...rest: readonly RegisterOptions[]): SolidRegisterPropsForElement<SolidRegisterElement> | SolidRegisterPropsForElement<SolidRegisterElement>[];
@@ -0,0 +1,4 @@
1
+ import type { Action } from 'svelte/action';
2
+ import type { Form } from '../core/index.js';
3
+ import { type RegisterOptions } from '../adapters/dom.js';
4
+ export declare function createRegisterAction<TValues>(form: Form<TValues>): Action<HTMLElement, RegisterOptions>;
@@ -0,0 +1,2 @@
1
+ export { useForm } from './useForm.js';
2
+ export type { RegisterOptions, } from './types.js';
@@ -0,0 +1,107 @@
1
+ import { c as h, f as S, g, a as s } from "../FormStateSummary-YyGT9nfY.js";
2
+ import { readable as E } from "svelte/store";
3
+ function L(e) {
4
+ return (t, r) => {
5
+ let a = r, n = o(e, a);
6
+ const u = () => h(
7
+ e,
8
+ A(t, a),
9
+ () => g(e, e.getState(), a.name),
10
+ S(a.name)
11
+ ), i = () => {
12
+ B(t, u(), a);
13
+ }, m = (c) => {
14
+ u().input(c.currentTarget);
15
+ }, v = (c) => {
16
+ u().change(c.currentTarget);
17
+ }, p = () => {
18
+ u().blur();
19
+ }, f = () => {
20
+ u().focus();
21
+ };
22
+ t.addEventListener("input", m), t.addEventListener("change", v), t.addEventListener("blur", p), t.addEventListener("focus", f);
23
+ const y = e.subscribe(i);
24
+ return i(), {
25
+ update(c) {
26
+ n(), a = c, n = o(e, a), i();
27
+ },
28
+ destroy() {
29
+ y(), n(), t.removeEventListener("input", m), t.removeEventListener("change", v), t.removeEventListener("blur", p), t.removeEventListener("focus", f);
30
+ }
31
+ };
32
+ };
33
+ }
34
+ function o(e, t) {
35
+ return t.schema ? e.registerFieldSchema(t.name, { schema: t.schema, schemaOptions: t.schemaOptions }) : () => {
36
+ };
37
+ }
38
+ function A(e, t) {
39
+ return t.type !== void 0 || !(e instanceof HTMLInputElement) ? t : {
40
+ ...t,
41
+ type: e.type || "text"
42
+ };
43
+ }
44
+ function B(e, t, r) {
45
+ if (F(e, t.name), e instanceof HTMLInputElement) {
46
+ T(e, t, r);
47
+ return;
48
+ }
49
+ if (e instanceof HTMLSelectElement) {
50
+ k(e, t);
51
+ return;
52
+ }
53
+ if (e instanceof HTMLTextAreaElement) {
54
+ l(e, t.value);
55
+ return;
56
+ }
57
+ N(e, t);
58
+ }
59
+ function F(e, t) {
60
+ if ("name" in e) {
61
+ e.name = t;
62
+ return;
63
+ }
64
+ e.setAttribute("name", t);
65
+ }
66
+ function T(e, t, r) {
67
+ if (r.type !== void 0 && e.type !== r.type && (e.type = r.type), e.type === "checkbox" || e.type === "radio") {
68
+ t.value !== void 0 && (e.value = String(Array.isArray(t.value) ? t.value[0] : t.value)), e.checked = !!t.checked;
69
+ return;
70
+ }
71
+ l(e, t.value);
72
+ }
73
+ function k(e, t) {
74
+ const r = t.value;
75
+ if (e.multiple) {
76
+ const a = new Set((Array.isArray(r) ? r : r === void 0 ? [] : [r]).map(String));
77
+ Array.from(e.options).forEach((n) => {
78
+ n.selected = a.has(n.value);
79
+ });
80
+ return;
81
+ }
82
+ l(e, r);
83
+ }
84
+ function l(e, t) {
85
+ const r = t === void 0 ? "" : String(Array.isArray(t) ? t[0] ?? "" : t);
86
+ e.value !== r && (e.value = r);
87
+ }
88
+ function N(e, t) {
89
+ "value" in e && (e.value = t.value), "checked" in e && (e.checked = !!t.checked);
90
+ }
91
+ function x(e) {
92
+ return E(s(e.getState()), (t) => (t(s(e.getState())), e.subscribe(() => {
93
+ t(s(e.getState()));
94
+ })));
95
+ }
96
+ function M(e) {
97
+ return {
98
+ form: e,
99
+ register: L(e),
100
+ useFormState() {
101
+ return x(e);
102
+ }
103
+ };
104
+ }
105
+ export {
106
+ M as useForm
107
+ };
@@ -0,0 +1,12 @@
1
+ import type { Action } from 'svelte/action';
2
+ import type { Readable } from 'svelte/store';
3
+ import type { Form } from '../core/index.js';
4
+ import type { FormStateSummary } from '../adapters/FormStateSummary.js';
5
+ import type { RegisterOptions } from '../adapters/dom.js';
6
+ export type { RegisterOptions } from '../adapters/dom.js';
7
+ export type SvelteRegisterAction = Action<HTMLElement, RegisterOptions>;
8
+ export type SvelteForm<TValues> = {
9
+ form: Form<TValues>;
10
+ register: SvelteRegisterAction;
11
+ useFormState(): Readable<FormStateSummary<TValues>>;
12
+ };
@@ -0,0 +1,3 @@
1
+ import type { Form } from '../core/index.js';
2
+ import type { SvelteForm } from './types.js';
3
+ export declare function useForm<TValues>(form: Form<TValues>): SvelteForm<TValues>;
@@ -0,0 +1,4 @@
1
+ import { type Readable } from 'svelte/store';
2
+ import type { Form } from '../core/index.js';
3
+ import { type FormStateSummary } from '../adapters/FormStateSummary.js';
4
+ export declare function useFormStateWithForm<TValues>(form: Form<TValues>): Readable<FormStateSummary<TValues>>;
@@ -0,0 +1,5 @@
1
+ import type { FieldState, Form } from '../core/index.js';
2
+ import { type RegisterOptions, fieldPathToDomName } from '../adapters/dom.js';
3
+ import type { VueRegisterElement, VueRegisterPropsForElement } from './types.js';
4
+ export declare function createRegisterProps<TValues, TElement extends VueRegisterElement>(form: Form<TValues>, options: RegisterOptions, getField: () => Readonly<FieldState>, domName: string): VueRegisterPropsForElement<TElement>;
5
+ export { fieldPathToDomName };
@@ -0,0 +1,2 @@
1
+ export { useForm } from './useForm.js';
2
+ export type { RegisterOptions, } from './types.js';