@ilokesto/form 1.0.0 → 1.0.2

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.
@@ -1,2 +1,2 @@
1
1
  export { useForm } from './useForm.js';
2
- export type { RegisterOptions, } from './types.js';
2
+ export type { ReactFormOptions, RegisterOptions, UseFieldStateReturn, } from './types.js';
@@ -1,83 +1,91 @@
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);
1
+ import { useEffect as F, useSyncExternalStore as R, useMemo as i, useCallback as b, useRef as v } from "react";
2
+ import { c as O, f as g, g as S, b as A, a as W, i as k, d as E } from "../FormStateSummary-gmEQdNXj.js";
3
+ function f(e, n, r, s) {
4
+ const t = O(e, n, () => r, s);
5
5
  return {
6
- name: n.name,
7
- type: n.type,
8
- value: n.value,
9
- checked: n.checked,
6
+ name: t.name,
7
+ type: t.type,
8
+ value: t.value,
9
+ checked: t.checked,
10
10
  onChange: (c) => {
11
- n.change(c.currentTarget);
11
+ t.change(c.currentTarget);
12
12
  },
13
13
  onBlur: () => {
14
- n.blur();
14
+ t.blur();
15
15
  },
16
16
  onFocus: () => {
17
- n.focus();
17
+ t.focus();
18
18
  }
19
19
  };
20
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]);
21
+ function N(e, n) {
22
+ const { name: r, schema: s, schemaOptions: t } = n;
23
+ F(() => {
24
+ if (s)
25
+ return e.registerFieldSchema(r, { schema: s, schemaOptions: t });
26
+ }, [e, r, s, t]);
27
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 })] : []);
28
+ function V(e, n) {
29
+ const r = n.map((s) => `${g(s.name)}:${s.schema ? "schema" : "none"}`).join("|");
30
+ F(() => {
31
+ const s = n.flatMap((t) => t.schema ? [e.registerFieldSchema(t.name, { schema: t.schema, schemaOptions: t.schemaOptions })] : []);
32
32
  return () => {
33
- a.forEach((n) => n());
33
+ s.forEach((t) => t());
34
34
  };
35
- }, [e, t, s]);
35
+ }, [e, n, r]);
36
36
  }
37
- function o(e) {
38
- return S(
39
- (t) => e.subscribe(t),
37
+ function m(e) {
38
+ return R(
39
+ (n) => e.subscribe(n),
40
40
  () => e.getState(),
41
41
  () => e.getState()
42
42
  );
43
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]);
44
+ function x(e, n) {
45
+ N(e, n);
46
+ const r = m(e), s = S(e, r, n.name), t = g(n.name), a = i(() => f(e, n, s, t), [e, n, s, t]), c = b((u) => {
47
+ e.setValue(n.name, u, { source: "program" });
48
+ }, [e, n.name]);
49
49
  return i(() => ({
50
- props: r,
51
- value: a.value,
50
+ props: a,
51
+ value: s.value,
52
52
  setValue: c,
53
- errors: [...a.errors],
54
- dirty: a.dirty,
55
- touched: a.touched
56
- }), [a, r, c]);
53
+ errors: [...s.errors],
54
+ dirty: s.dirty,
55
+ touched: s.touched
56
+ }), [s, a, c]);
57
57
  }
58
- function O(e) {
59
- const t = o(e);
60
- return i(() => R(t), [t]);
58
+ function B(e, n) {
59
+ const r = m(e);
60
+ return S(e, r, n);
61
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);
62
+ function C(e) {
63
+ const n = m(e);
64
+ return i(() => A(n), [n]);
65
+ }
66
+ function D(e, n, ...r) {
67
+ const s = Array.isArray(n) || r.length > 0, t = M(n, r);
68
+ V(e, t);
69
+ const a = m(e), c = i(
70
+ () => t.map((u) => {
71
+ const l = S(e, a, u.name), d = g(u.name);
72
+ return f(e, u, l, d);
69
73
  }),
70
- [e, n, r]
74
+ [e, t, a]
71
75
  );
72
- return a ? c : c[0];
76
+ return s ? c : c[0];
73
77
  }
74
- function E(e, t) {
75
- return Array.isArray(e) ? e : t.length > 0 ? [e, ...t] : [e];
78
+ function M(e, n) {
79
+ return Array.isArray(e) ? e : n.length > 0 ? [e, ...n] : [e];
76
80
  }
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]);
81
+ function $(e) {
82
+ const n = v(void 0), r = v(void 0), s = k(e), t = s ? e : n.current ??= W(e), a = s ? void 0 : e.values, c = s ? void 0 : e.resetOptions;
83
+ F(() => {
84
+ a === void 0 || r.current === a || (r.current = a, t.reset(a, c));
85
+ }, [t, c, a]);
86
+ const u = ((o, ...h) => D(t, o, ...h)), l = ((o) => x(t, o)), d = ((o) => B(t, o)), p = () => C(t), y = ((o, h) => E(t, o, h));
87
+ return i(() => ({ form: t, useRegister: u, useField: l, useFieldState: d, useFormState: p, handleSubmit: y }), [t]);
80
88
  }
81
89
  export {
82
- f as useForm
90
+ $ as useForm
83
91
  };
@@ -1,7 +1,11 @@
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';
1
+ import type { ChangeEventHandler, FocusEventHandler, InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes, FormEvent } from 'react';
2
+ import type { CreateFormOptions, FieldPathInput, FieldPathValue, FieldState, Form, FormError, FormState, ResetOptions } from '../core/index.js';
3
+ import type { RegisterOptions, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from '../adapters/dom.js';
4
4
  export type { RegisterOptions } from '../adapters/dom.js';
5
+ export type ReactFormOptions<TValues> = CreateFormOptions<TValues> & {
6
+ values?: TValues;
7
+ resetOptions?: ResetOptions;
8
+ };
5
9
  type InputValue = InputHTMLAttributes<HTMLInputElement>['value'];
6
10
  type InputType = InputHTMLAttributes<HTMLInputElement>['type'];
7
11
  type SelectValue = SelectHTMLAttributes<HTMLSelectElement>['value'];
@@ -41,6 +45,7 @@ export type UseFieldReturn<TProps extends RegisterProps = InputRegisterProps> =
41
45
  dirty: boolean;
42
46
  touched: boolean;
43
47
  };
48
+ export type UseFieldStateReturn<TValues, TName extends FieldPathInput> = Readonly<FieldState<FieldPathValue<TValues, TName>>>;
44
49
  export type UseFormStateReturn<TValues> = {
45
50
  state: Readonly<FormState<TValues>>;
46
51
  errors: Record<string, FormError[]>;
@@ -49,6 +54,8 @@ export type UseFormStateReturn<TValues> = {
49
54
  isDirty: boolean;
50
55
  isValid: boolean;
51
56
  isSubmitting: boolean;
57
+ isSubmitted: boolean;
58
+ isSubmitSuccessful: boolean;
52
59
  submitCount: number;
53
60
  };
54
61
  export type RegisterPropsList<TElement extends RegisterElement, TOptions extends readonly RegisterOptions[]> = {
@@ -60,5 +67,7 @@ export type ReactForm<TValues> = {
60
67
  useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(options: TOptions): RegisterPropsList<TElement, TOptions>;
61
68
  useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): RegisterPropsList<TElement, TOptions>;
62
69
  useField<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): UseFieldReturn<RegisterPropsForElement<TElement>>;
70
+ useFieldState<const TName extends FieldPathInput>(name: TName): UseFieldStateReturn<TValues, TName>;
63
71
  useFormState(): UseFormStateReturn<TValues>;
72
+ handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<FormEvent<HTMLFormElement>, TResult>;
64
73
  };
@@ -0,0 +1,3 @@
1
+ import type { FieldPathInput, Form } from '../core/index.js';
2
+ import type { UseFieldStateReturn } from './types.js';
3
+ export declare function useFieldStateWithForm<TValues, const TName extends FieldPathInput>(form: Form<TValues>, name: TName): UseFieldStateReturn<TValues, TName>;
@@ -1,3 +1,4 @@
1
1
  import type { Form } from '../core/index.js';
2
- import type { ReactForm } from './types.js';
2
+ import type { ReactForm, ReactFormOptions } from './types.js';
3
3
  export declare function useForm<TValues>(form: Form<TValues>): ReactForm<TValues>;
4
+ export declare function useForm<TValues>(options: ReactFormOptions<TValues>): ReactForm<TValues>;
@@ -1,7 +1,7 @@
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);
1
+ import { c as h, f as o, g as m, b as S, i as F, a as p, d as b } from "../FormStateSummary-gmEQdNXj.js";
2
+ import { onCleanup as g, createSignal as y } from "solid-js";
3
+ function l(e, t, r, n) {
4
+ const s = h(e, t, r, n);
5
5
  return {
6
6
  name: s.name,
7
7
  type: s.type,
@@ -11,11 +11,11 @@ function h(e, t, r, n) {
11
11
  get checked() {
12
12
  return s.checked;
13
13
  },
14
- onInput: (a) => {
15
- s.input(a.currentTarget);
14
+ onInput: (u) => {
15
+ s.input(u.currentTarget);
16
16
  },
17
- onChange: (a) => {
18
- s.change(a.currentTarget);
17
+ onChange: (u) => {
18
+ s.change(u.currentTarget);
19
19
  },
20
20
  onBlur: () => {
21
21
  s.blur();
@@ -25,28 +25,28 @@ function h(e, t, r, n) {
25
25
  }
26
26
  };
27
27
  }
28
- function m(e, t) {
28
+ function d(e, t) {
29
29
  const r = t.flatMap((n) => n.schema ? [e.registerFieldSchema(n.name, { schema: n.schema, schemaOptions: n.schemaOptions })] : []);
30
- r.length !== 0 && l(() => {
30
+ r.length !== 0 && g(() => {
31
31
  r.forEach((n) => n());
32
32
  });
33
33
  }
34
34
  function c(e) {
35
- const [t, r] = F(e.getState(), { equals: !1 }), n = e.subscribe(() => {
35
+ const [t, r] = y(e.getState(), { equals: !1 }), n = e.subscribe(() => {
36
36
  r(e.getState());
37
37
  });
38
- return l(n), t;
38
+ return g(n), t;
39
39
  }
40
- function S(e, t) {
41
- m(e, [t]);
42
- const r = c(e), n = () => g(e, r(), t.name);
40
+ function f(e, t) {
41
+ d(e, [t]);
42
+ const r = c(e), n = () => m(e, r(), t.name);
43
43
  return {
44
- props: h(e, t, n, o(t.name)),
44
+ props: l(e, t, n, o(t.name)),
45
45
  get value() {
46
46
  return n().value;
47
47
  },
48
- setValue(u) {
49
- e.setValue(t.name, u, { source: "program" });
48
+ setValue(i) {
49
+ e.setValue(t.name, i, { source: "program" });
50
50
  },
51
51
  get errors() {
52
52
  return [...n().errors];
@@ -59,8 +59,8 @@ function S(e, t) {
59
59
  }
60
60
  };
61
61
  }
62
- function y(e) {
63
- const t = c(e), r = () => p(t());
62
+ function R(e) {
63
+ const t = c(e), r = () => S(t());
64
64
  return {
65
65
  get state() {
66
66
  return t();
@@ -83,28 +83,35 @@ function y(e) {
83
83
  get isSubmitting() {
84
84
  return r().isSubmitting;
85
85
  },
86
+ get isSubmitted() {
87
+ return r().isSubmitted;
88
+ },
89
+ get isSubmitSuccessful() {
90
+ return r().isSubmitSuccessful;
91
+ },
86
92
  get submitCount() {
87
93
  return r().submitCount;
88
94
  }
89
95
  };
90
96
  }
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(
97
+ function v(e, t, ...r) {
98
+ const n = Array.isArray(t) || r.length > 0, s = A(t, r);
99
+ d(e, s);
100
+ const i = c(e), u = s.map((a) => l(
95
101
  e,
96
- i,
97
- () => g(e, u(), i.name),
98
- o(i.name)
102
+ a,
103
+ () => m(e, i(), a.name),
104
+ o(a.name)
99
105
  ));
100
- return n ? a : a[0];
106
+ return n ? u : u[0];
101
107
  }
102
- function R(e, t) {
108
+ function A(e, t) {
103
109
  return Array.isArray(e) ? e : t.length > 0 ? [e, ...t] : [e];
104
110
  }
105
- function A(e) {
106
- return { form: e, useRegister: ((s, ...u) => b(e, s, ...u)), useField: ((s) => S(e, s)), useFormState: () => y(e) };
111
+ function O(e) {
112
+ const t = F(e) ? e : p(e);
113
+ return { form: t, useRegister: ((u, ...a) => v(t, u, ...a)), useField: ((u) => f(t, u)), useFormState: () => R(t), handleSubmit: ((u, a) => b(t, u, a)) };
107
114
  }
108
115
  export {
109
- A as useForm
116
+ O as useForm
110
117
  };
@@ -1,5 +1,5 @@
1
1
  import type { Form, FormError, FormState } from '../core/index.js';
2
- import type { DomValue, RegisterOptions } from '../adapters/dom.js';
2
+ import type { DomValue, RegisterOptions, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from '../adapters/dom.js';
3
3
  export type { RegisterOptions } from '../adapters/dom.js';
4
4
  type SolidBindingHandlers<TElement extends HTMLElement> = {
5
5
  onInput: (event: InputEvent & {
@@ -56,6 +56,8 @@ export type SolidFormStateReturn<TValues> = {
56
56
  readonly isDirty: boolean;
57
57
  readonly isValid: boolean;
58
58
  readonly isSubmitting: boolean;
59
+ readonly isSubmitted: boolean;
60
+ readonly isSubmitSuccessful: boolean;
59
61
  readonly submitCount: number;
60
62
  };
61
63
  export type SolidForm<TValues> = {
@@ -65,4 +67,5 @@ export type SolidForm<TValues> = {
65
67
  useRegister<TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
66
68
  useField<TElement extends SolidRegisterElement = HTMLInputElement>(options: RegisterOptions): SolidFieldReturn<SolidRegisterPropsForElement<TElement>>;
67
69
  useFormState(): SolidFormStateReturn<TValues>;
70
+ handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<Event, TResult>;
68
71
  };
@@ -1,3 +1,4 @@
1
- import type { Form } from '../core/index.js';
1
+ import type { CreateFormOptions, Form } from '../core/index.js';
2
2
  import type { SolidForm } from './types.js';
3
3
  export declare function useForm<TValues>(form: Form<TValues>): SolidForm<TValues>;
4
+ export declare function useForm<TValues>(options: CreateFormOptions<TValues>): SolidForm<TValues>;
@@ -1,76 +1,76 @@
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) {
1
+ import { c as h, f as S, g, b as i, i as E, a as F, d as L } from "../FormStateSummary-gmEQdNXj.js";
2
+ import { readable as A } from "svelte/store";
3
+ function B(e) {
4
4
  return (t, r) => {
5
- let a = r, n = o(e, a);
5
+ let a = r, n = p(e, a);
6
6
  const u = () => h(
7
7
  e,
8
- A(t, a),
8
+ T(t, a),
9
9
  () => g(e, e.getState(), a.name),
10
10
  S(a.name)
11
- ), i = () => {
12
- B(t, u(), a);
11
+ ), s = () => {
12
+ k(t, u(), a);
13
13
  }, m = (c) => {
14
14
  u().input(c.currentTarget);
15
- }, v = (c) => {
15
+ }, o = (c) => {
16
16
  u().change(c.currentTarget);
17
- }, p = () => {
17
+ }, v = () => {
18
18
  u().blur();
19
19
  }, f = () => {
20
20
  u().focus();
21
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(), {
22
+ t.addEventListener("input", m), t.addEventListener("change", o), t.addEventListener("blur", v), t.addEventListener("focus", f);
23
+ const y = e.subscribe(s);
24
+ return s(), {
25
25
  update(c) {
26
- n(), a = c, n = o(e, a), i();
26
+ n(), a = c, n = p(e, a), s();
27
27
  },
28
28
  destroy() {
29
- y(), n(), t.removeEventListener("input", m), t.removeEventListener("change", v), t.removeEventListener("blur", p), t.removeEventListener("focus", f);
29
+ y(), n(), t.removeEventListener("input", m), t.removeEventListener("change", o), t.removeEventListener("blur", v), t.removeEventListener("focus", f);
30
30
  }
31
31
  };
32
32
  };
33
33
  }
34
- function o(e, t) {
34
+ function p(e, t) {
35
35
  return t.schema ? e.registerFieldSchema(t.name, { schema: t.schema, schemaOptions: t.schemaOptions }) : () => {
36
36
  };
37
37
  }
38
- function A(e, t) {
38
+ function T(e, t) {
39
39
  return t.type !== void 0 || !(e instanceof HTMLInputElement) ? t : {
40
40
  ...t,
41
41
  type: e.type || "text"
42
42
  };
43
43
  }
44
- function B(e, t, r) {
45
- if (F(e, t.name), e instanceof HTMLInputElement) {
46
- T(e, t, r);
44
+ function k(e, t, r) {
45
+ if (N(e, t.name), e instanceof HTMLInputElement) {
46
+ b(e, t, r);
47
47
  return;
48
48
  }
49
49
  if (e instanceof HTMLSelectElement) {
50
- k(e, t);
50
+ x(e, t);
51
51
  return;
52
52
  }
53
53
  if (e instanceof HTMLTextAreaElement) {
54
54
  l(e, t.value);
55
55
  return;
56
56
  }
57
- N(e, t);
57
+ H(e, t);
58
58
  }
59
- function F(e, t) {
59
+ function N(e, t) {
60
60
  if ("name" in e) {
61
61
  e.name = t;
62
62
  return;
63
63
  }
64
64
  e.setAttribute("name", t);
65
65
  }
66
- function T(e, t, r) {
66
+ function b(e, t, r) {
67
67
  if (r.type !== void 0 && e.type !== r.type && (e.type = r.type), e.type === "checkbox" || e.type === "radio") {
68
68
  t.value !== void 0 && (e.value = String(Array.isArray(t.value) ? t.value[0] : t.value)), e.checked = !!t.checked;
69
69
  return;
70
70
  }
71
71
  l(e, t.value);
72
72
  }
73
- function k(e, t) {
73
+ function x(e, t) {
74
74
  const r = t.value;
75
75
  if (e.multiple) {
76
76
  const a = new Set((Array.isArray(r) ? r : r === void 0 ? [] : [r]).map(String));
@@ -85,23 +85,27 @@ function l(e, t) {
85
85
  const r = t === void 0 ? "" : String(Array.isArray(t) ? t[0] ?? "" : t);
86
86
  e.value !== r && (e.value = r);
87
87
  }
88
- function N(e, t) {
88
+ function H(e, t) {
89
89
  "value" in e && (e.value = t.value), "checked" in e && (e.checked = !!t.checked);
90
90
  }
91
- function x(e) {
92
- return E(s(e.getState()), (t) => (t(s(e.getState())), e.subscribe(() => {
93
- t(s(e.getState()));
91
+ function I(e) {
92
+ return A(i(e.getState()), (t) => (t(i(e.getState())), e.subscribe(() => {
93
+ t(i(e.getState()));
94
94
  })));
95
95
  }
96
- function M(e) {
96
+ function C(e) {
97
+ const t = E(e) ? e : F(e);
97
98
  return {
98
- form: e,
99
- register: L(e),
99
+ form: t,
100
+ register: B(t),
100
101
  useFormState() {
101
- return x(e);
102
+ return I(t);
103
+ },
104
+ handleSubmit(r, a) {
105
+ return L(t, r, a);
102
106
  }
103
107
  };
104
108
  }
105
109
  export {
106
- M as useForm
110
+ C as useForm
107
111
  };
@@ -2,11 +2,12 @@ import type { Action } from 'svelte/action';
2
2
  import type { Readable } from 'svelte/store';
3
3
  import type { Form } from '../core/index.js';
4
4
  import type { FormStateSummary } from '../adapters/FormStateSummary.js';
5
- import type { RegisterOptions } from '../adapters/dom.js';
5
+ import type { RegisterOptions, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from '../adapters/dom.js';
6
6
  export type { RegisterOptions } from '../adapters/dom.js';
7
7
  export type SvelteRegisterAction = Action<HTMLElement, RegisterOptions>;
8
8
  export type SvelteForm<TValues> = {
9
9
  form: Form<TValues>;
10
10
  register: SvelteRegisterAction;
11
11
  useFormState(): Readable<FormStateSummary<TValues>>;
12
+ handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<Event, TResult>;
12
13
  };
@@ -1,3 +1,4 @@
1
- import type { Form } from '../core/index.js';
1
+ import type { CreateFormOptions, Form } from '../core/index.js';
2
2
  import type { SvelteForm } from './types.js';
3
3
  export declare function useForm<TValues>(form: Form<TValues>): SvelteForm<TValues>;
4
+ export declare function useForm<TValues>(options: CreateFormOptions<TValues>): SvelteForm<TValues>;
package/dist/vue/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { c as p, f as o, g, a as F } from "../FormStateSummary-YyGT9nfY.js";
2
- import { getCurrentScope as l, onScopeDispose as h, shallowRef as S } from "vue";
3
- function m(e, t, r, n) {
4
- const s = p(e, t, r, n);
1
+ import { c as S, f as o, g as m, b as F, i as p, a as b, d as y } from "../FormStateSummary-gmEQdNXj.js";
2
+ import { getCurrentScope as g, onScopeDispose as l, shallowRef as f } from "vue";
3
+ function d(e, t, r, n) {
4
+ const s = S(e, t, r, n);
5
5
  return {
6
6
  name: s.name,
7
7
  type: s.type,
@@ -11,11 +11,11 @@ function m(e, t, r, n) {
11
11
  get checked() {
12
12
  return s.checked;
13
13
  },
14
- onInput: (a) => {
15
- s.input(a.currentTarget);
14
+ onInput: (u) => {
15
+ s.input(u.currentTarget);
16
16
  },
17
- onChange: (a) => {
18
- s.change(a.currentTarget);
17
+ onChange: (u) => {
18
+ s.change(u.currentTarget);
19
19
  },
20
20
  onBlur: () => {
21
21
  s.blur();
@@ -25,28 +25,28 @@ function m(e, t, r, n) {
25
25
  }
26
26
  };
27
27
  }
28
- function d(e, t) {
28
+ function h(e, t) {
29
29
  const r = t.flatMap((n) => n.schema ? [e.registerFieldSchema(n.name, { schema: n.schema, schemaOptions: n.schemaOptions })] : []);
30
- r.length !== 0 && l() && h(() => {
30
+ r.length !== 0 && g() && l(() => {
31
31
  r.forEach((n) => n());
32
32
  });
33
33
  }
34
34
  function c(e) {
35
- const t = S(e.getState()), r = e.subscribe(() => {
35
+ const t = f(e.getState()), r = e.subscribe(() => {
36
36
  t.value = e.getState();
37
37
  });
38
- return l() && h(r), t;
38
+ return g() && l(r), t;
39
39
  }
40
- function y(e, t) {
41
- d(e, [t]);
42
- const r = c(e), n = () => g(e, r.value, t.name);
40
+ function v(e, t) {
41
+ h(e, [t]);
42
+ const r = c(e), n = () => m(e, r.value, t.name);
43
43
  return {
44
- props: m(e, t, n, o(t.name)),
44
+ props: d(e, t, n, o(t.name)),
45
45
  get value() {
46
46
  return n().value;
47
47
  },
48
- setValue(u) {
49
- e.setValue(t.name, u, { source: "program" });
48
+ setValue(i) {
49
+ e.setValue(t.name, i, { source: "program" });
50
50
  },
51
51
  get errors() {
52
52
  return [...n().errors];
@@ -59,7 +59,7 @@ function y(e, t) {
59
59
  }
60
60
  };
61
61
  }
62
- function b(e) {
62
+ function R(e) {
63
63
  const t = c(e), r = () => F(t.value);
64
64
  return {
65
65
  get state() {
@@ -83,28 +83,35 @@ function b(e) {
83
83
  get isSubmitting() {
84
84
  return r().isSubmitting;
85
85
  },
86
+ get isSubmitted() {
87
+ return r().isSubmitted;
88
+ },
89
+ get isSubmitSuccessful() {
90
+ return r().isSubmitSuccessful;
91
+ },
86
92
  get submitCount() {
87
93
  return r().submitCount;
88
94
  }
89
95
  };
90
96
  }
91
- function v(e, t, ...r) {
92
- const n = Array.isArray(t) || r.length > 0, s = R(t, r);
93
- d(e, s);
94
- const u = c(e), a = s.map((i) => m(
97
+ function D(e, t, ...r) {
98
+ const n = Array.isArray(t) || r.length > 0, s = A(t, r);
99
+ h(e, s);
100
+ const i = c(e), u = s.map((a) => d(
95
101
  e,
96
- i,
97
- () => g(e, u.value, i.name),
98
- o(i.name)
102
+ a,
103
+ () => m(e, i.value, a.name),
104
+ o(a.name)
99
105
  ));
100
- return n ? a : a[0];
106
+ return n ? u : u[0];
101
107
  }
102
- function R(e, t) {
108
+ function A(e, t) {
103
109
  return Array.isArray(e) ? e : t.length > 0 ? [e, ...t] : [e];
104
110
  }
105
- function A(e) {
106
- return { form: e, useRegister: ((s, ...u) => v(e, s, ...u)), useField: ((s) => y(e, s)), useFormState: () => b(e) };
111
+ function V(e) {
112
+ const t = p(e) ? e : b(e);
113
+ return { form: t, useRegister: ((u, ...a) => D(t, u, ...a)), useField: ((u) => v(t, u)), useFormState: () => R(t), handleSubmit: ((u, a) => y(t, u, a)) };
107
114
  }
108
115
  export {
109
- A as useForm
116
+ V as useForm
110
117
  };