@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
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { C as a } from "./CreateForm-hQ4cxAK-.js";
|
|
2
|
-
function j(e, t, r) {
|
|
3
|
-
const n = e.getFieldState(r);
|
|
4
|
-
if (b(t, r))
|
|
5
|
-
return n;
|
|
6
|
-
const i = y(e.getValues(), l(r));
|
|
7
|
-
return {
|
|
8
|
-
...n,
|
|
9
|
-
value: i
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function l(e) {
|
|
13
|
-
return typeof e == "string" ? [e] : e;
|
|
14
|
-
}
|
|
15
|
-
function b(e, t) {
|
|
16
|
-
return m(t) in e.fields;
|
|
17
|
-
}
|
|
18
|
-
function m(e) {
|
|
19
|
-
const t = l(e);
|
|
20
|
-
return t.length === 0 ? "$" : JSON.stringify(t);
|
|
21
|
-
}
|
|
22
|
-
function y(e, t) {
|
|
23
|
-
let r = e;
|
|
24
|
-
for (const n of t) {
|
|
25
|
-
if (r == null || typeof r != "object" && typeof r != "function")
|
|
26
|
-
return;
|
|
27
|
-
r = r[n];
|
|
28
|
-
}
|
|
29
|
-
return r;
|
|
30
|
-
}
|
|
31
|
-
const d = /* @__PURE__ */ Symbol("skip change");
|
|
32
|
-
function x(e, t, r, n) {
|
|
33
|
-
const i = t.type ?? "text";
|
|
34
|
-
return {
|
|
35
|
-
name: n,
|
|
36
|
-
type: i,
|
|
37
|
-
get value() {
|
|
38
|
-
return v(i, r().value, u(t));
|
|
39
|
-
},
|
|
40
|
-
get checked() {
|
|
41
|
-
return O(i, r().value, u(t));
|
|
42
|
-
},
|
|
43
|
-
input(c) {
|
|
44
|
-
h(c, t) || s(e, t, r().value, c);
|
|
45
|
-
},
|
|
46
|
-
change(c) {
|
|
47
|
-
s(e, t, r().value, c);
|
|
48
|
-
},
|
|
49
|
-
blur() {
|
|
50
|
-
e.blur(t.name);
|
|
51
|
-
},
|
|
52
|
-
focus() {
|
|
53
|
-
e.focus(t.name);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function E(e) {
|
|
58
|
-
return typeof e == "string" ? e : JSON.stringify(e);
|
|
59
|
-
}
|
|
60
|
-
function s(e, t, r, n) {
|
|
61
|
-
const i = S(n, t, r);
|
|
62
|
-
i !== d && e.setValue(t.name, i, { source: "user" });
|
|
63
|
-
}
|
|
64
|
-
function h(e, t) {
|
|
65
|
-
const r = t.type ?? e.type;
|
|
66
|
-
return r === "checkbox" || r === "radio" || !!e.multiple;
|
|
67
|
-
}
|
|
68
|
-
function u(e) {
|
|
69
|
-
return e.value ?? e.checkedValue;
|
|
70
|
-
}
|
|
71
|
-
function v(e, t, r) {
|
|
72
|
-
return e === "checkbox" ? o(r) : e === "radio" ? o(r) ?? "" : o(t) ?? "";
|
|
73
|
-
}
|
|
74
|
-
function O(e, t, r) {
|
|
75
|
-
if (e === "checkbox")
|
|
76
|
-
return r !== void 0 && Array.isArray(t) ? t.some((n) => Object.is(n, r)) : r !== void 0 ? Object.is(t, r) : !!t;
|
|
77
|
-
if (e === "radio")
|
|
78
|
-
return Object.is(t, r);
|
|
79
|
-
}
|
|
80
|
-
function S(e, t, r) {
|
|
81
|
-
const n = t.type ?? e.type;
|
|
82
|
-
return n === "checkbox" ? g(e, t, r) : n === "radio" ? e.checked ? u(t) ?? e.value : d : e.multiple && e.selectedOptions ? [...e.selectedOptions].map((i) => i.value) : e.value;
|
|
83
|
-
}
|
|
84
|
-
function g(e, t, r) {
|
|
85
|
-
if (t.checkedValue === void 0 && t.value === void 0)
|
|
86
|
-
return !!e.checked;
|
|
87
|
-
if (Array.isArray(r)) {
|
|
88
|
-
const n = u(t);
|
|
89
|
-
return e.checked ? r.some((i) => Object.is(i, n)) ? r : [...r, n] : r.filter((i) => !Object.is(i, n));
|
|
90
|
-
}
|
|
91
|
-
return e.checked ? u(t) : t.uncheckedValue ?? !1;
|
|
92
|
-
}
|
|
93
|
-
function o(e) {
|
|
94
|
-
if (e != null)
|
|
95
|
-
return typeof e == "string" || typeof e == "number" ? e : Array.isArray(e) ? e.map((t) => String(t)) : String(e);
|
|
96
|
-
}
|
|
97
|
-
function F(e, t, r) {
|
|
98
|
-
return async (n) => (n?.preventDefault?.(), e.submit(t, r));
|
|
99
|
-
}
|
|
100
|
-
function A(e) {
|
|
101
|
-
return "subscribe" in e && "submit" in e;
|
|
102
|
-
}
|
|
103
|
-
function C(e) {
|
|
104
|
-
const { values: t, resetOptions: r, ...n } = e;
|
|
105
|
-
return new a(n);
|
|
106
|
-
}
|
|
107
|
-
function B(e) {
|
|
108
|
-
const t = p(e), r = f(e, "dirty"), n = f(e, "touched");
|
|
109
|
-
return {
|
|
110
|
-
state: e,
|
|
111
|
-
errors: t,
|
|
112
|
-
dirtyFields: r,
|
|
113
|
-
touchedFields: n,
|
|
114
|
-
isDirty: Object.keys(r).length > 0,
|
|
115
|
-
isValid: Object.keys(t).length === 0,
|
|
116
|
-
isSubmitting: e.isSubmitting,
|
|
117
|
-
isSubmitted: e.isSubmitted,
|
|
118
|
-
isSubmitSuccessful: e.isSubmitSuccessful,
|
|
119
|
-
submitCount: e.submitCount
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
function p(e) {
|
|
123
|
-
return Object.fromEntries(
|
|
124
|
-
Object.entries(e.fields).filter(([, t]) => t.errors.length > 0).map(([t, r]) => [t, [...r.errors]])
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
function f(e, t) {
|
|
128
|
-
return Object.fromEntries(
|
|
129
|
-
Object.entries(e.fields).filter(([, r]) => r[t]).map(([r]) => [r, !0])
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
export {
|
|
133
|
-
C as a,
|
|
134
|
-
B as b,
|
|
135
|
-
x as c,
|
|
136
|
-
F as d,
|
|
137
|
-
E as f,
|
|
138
|
-
j as g,
|
|
139
|
-
A as i
|
|
140
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type CreateFormOptions, type Form, type ResetOptions } from '../core/index.js';
|
|
2
|
-
export type ReactiveFormOptions<TValues> = CreateFormOptions<TValues> & {
|
|
3
|
-
values?: TValues;
|
|
4
|
-
resetOptions?: ResetOptions;
|
|
5
|
-
};
|
|
6
|
-
export type FormInput<TValues> = Form<TValues> | ReactiveFormOptions<TValues>;
|
|
7
|
-
export declare function isFormInstance<TValues>(input: FormInput<TValues>): input is Form<TValues>;
|
|
8
|
-
export declare function createFormFromOptions<TValues>(options: ReactiveFormOptions<TValues>): Form<TValues>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { FormError, FormState } from '../core/index.js';
|
|
2
|
-
export type FormStateSummary<TValues> = {
|
|
3
|
-
state: Readonly<FormState<TValues>>;
|
|
4
|
-
errors: Record<string, FormError[]>;
|
|
5
|
-
dirtyFields: Record<string, true>;
|
|
6
|
-
touchedFields: Record<string, true>;
|
|
7
|
-
isDirty: boolean;
|
|
8
|
-
isValid: boolean;
|
|
9
|
-
isSubmitting: boolean;
|
|
10
|
-
isSubmitted: boolean;
|
|
11
|
-
isSubmitSuccessful: boolean;
|
|
12
|
-
submitCount: number;
|
|
13
|
-
};
|
|
14
|
-
export declare function createFormStateSummary<TValues>(state: Readonly<FormState<TValues>>): FormStateSummary<TValues>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { FieldPathInput, FieldState, Form } from '../../core/index.js';
|
|
2
|
-
import type { DomValue, FieldEventTarget, RegisterOptions } from './types.js';
|
|
3
|
-
export type DomBindingCore = {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
readonly type: string;
|
|
6
|
-
readonly value?: DomValue;
|
|
7
|
-
readonly checked?: boolean;
|
|
8
|
-
input(target: FieldEventTarget): void;
|
|
9
|
-
change(target: FieldEventTarget): void;
|
|
10
|
-
blur(): void;
|
|
11
|
-
focus(): void;
|
|
12
|
-
};
|
|
13
|
-
export declare function createDomBinding<TValues>(form: Form<TValues>, options: RegisterOptions, getField: () => Readonly<FieldState>, domName: string): DomBindingCore;
|
|
14
|
-
export declare function fieldPathToDomName(name: FieldPathInput): string;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FieldState, Form } from '../../core/index.js';
|
|
2
|
-
import type { PathKey } from '../../core/types.js';
|
|
3
|
-
export type SubmitEventLike = {
|
|
4
|
-
preventDefault?: () => void;
|
|
5
|
-
};
|
|
6
|
-
export type SubmitValidHandler<TValues, TResult> = (values: TValues) => TResult | Promise<TResult>;
|
|
7
|
-
export type SubmitInvalidHandler = (fields: Readonly<Record<PathKey, FieldState>>) => void;
|
|
8
|
-
export type SubmitHandler<TEvent extends SubmitEventLike, TResult> = (event?: TEvent) => Promise<TResult | undefined>;
|
|
9
|
-
export declare function createSubmitHandler<TValues, TEvent extends SubmitEventLike, TResult>(form: Form<TValues>, onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<TEvent, TResult>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { getFieldState } from './FieldValue.js';
|
|
2
|
-
export { createDomBinding, fieldPathToDomName, type DomBindingCore } from './RegisterBinding.js';
|
|
3
|
-
export { createSubmitHandler } from './SubmitHandler.js';
|
|
4
|
-
export type { SubmitEventLike, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from './SubmitHandler.js';
|
|
5
|
-
export type { DomValue, FieldEventTarget, FieldHookOptions, RegisterOptions } from './types.js';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { FieldPathInput, StandardSchemaV1 } from '../../core/index.js';
|
|
2
|
-
export type FieldHookOptions = {
|
|
3
|
-
name: FieldPathInput;
|
|
4
|
-
schema?: StandardSchemaV1<unknown, unknown>;
|
|
5
|
-
schemaOptions?: StandardSchemaV1.Options;
|
|
6
|
-
};
|
|
7
|
-
export type RegisterOptions = FieldHookOptions & {
|
|
8
|
-
type?: string;
|
|
9
|
-
value?: unknown;
|
|
10
|
-
checkedValue?: unknown;
|
|
11
|
-
uncheckedValue?: unknown;
|
|
12
|
-
};
|
|
13
|
-
export type FieldEventTarget = HTMLElement & {
|
|
14
|
-
type?: string;
|
|
15
|
-
value?: unknown;
|
|
16
|
-
checked?: boolean;
|
|
17
|
-
multiple?: boolean;
|
|
18
|
-
selectedOptions?: Iterable<{
|
|
19
|
-
value: string;
|
|
20
|
-
}>;
|
|
21
|
-
};
|
|
22
|
-
export type DomValue = string | number | readonly string[];
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type IndexMapper = (index: number) => number | undefined;
|
|
2
|
-
export declare class ArrayItemReorder {
|
|
3
|
-
static createIndexMapper(previousLength: number, nextOrder: readonly number[]): IndexMapper;
|
|
4
|
-
static moveItem<T>(items: readonly T[], fromIndex: number, toIndex: number): T[];
|
|
5
|
-
static swapItems<T>(items: readonly T[], leftIndex: number, rightIndex: number): T[];
|
|
6
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ArrayKeyGenerator } from './ArrayKeyGenerator.js';
|
|
2
|
-
import { FormStateStore } from '../state/index.js';
|
|
3
|
-
import type { FieldPath, FormArray } from '../types.js';
|
|
4
|
-
export declare class FormArrayController<TValues> implements FormArray {
|
|
5
|
-
private readonly store;
|
|
6
|
-
private readonly keyGenerator;
|
|
7
|
-
private readonly fieldPath;
|
|
8
|
-
private readonly mutations;
|
|
9
|
-
constructor(store: FormStateStore<TValues>, keys: ArrayKeyGenerator, fieldPath: FieldPath);
|
|
10
|
-
keys(): readonly string[];
|
|
11
|
-
insert(index: number, value: unknown): void;
|
|
12
|
-
push(value: unknown): void;
|
|
13
|
-
remove(index: number): void;
|
|
14
|
-
move(fromIndex: number, toIndex: number): void;
|
|
15
|
-
swap(leftIndex: number, rightIndex: number): void;
|
|
16
|
-
replace(values: readonly unknown[]): void;
|
|
17
|
-
private getArray;
|
|
18
|
-
private getKeys;
|
|
19
|
-
private applyMutation;
|
|
20
|
-
private rebase;
|
|
21
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { FormStateStore } from '../state/index.js';
|
|
2
|
-
import type { FieldPath, FormArray } from '../types.js';
|
|
3
|
-
export declare class FormArrayFactory<TValues> {
|
|
4
|
-
private readonly store;
|
|
5
|
-
private readonly keys;
|
|
6
|
-
constructor(store: FormStateStore<TValues>);
|
|
7
|
-
create(fieldPath: FieldPath): FormArray;
|
|
8
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type IndexMapper } from './ArrayItemReorder.js';
|
|
2
|
-
export type FormArrayMutation = {
|
|
3
|
-
values: readonly unknown[];
|
|
4
|
-
keys: readonly string[];
|
|
5
|
-
mapPreviousIndex: IndexMapper;
|
|
6
|
-
};
|
|
7
|
-
export declare class FormArrayMutationPlanner {
|
|
8
|
-
insert(currentArray: readonly unknown[], currentKeys: readonly string[], index: number, value: unknown, nextKey: string): FormArrayMutation;
|
|
9
|
-
push(currentArray: readonly unknown[], currentKeys: readonly string[], value: unknown, nextKey: string): FormArrayMutation;
|
|
10
|
-
remove(currentArray: readonly unknown[], currentKeys: readonly string[], index: number): FormArrayMutation | undefined;
|
|
11
|
-
move(currentArray: readonly unknown[], currentKeys: readonly string[], fromIndex: number, toIndex: number): FormArrayMutation | undefined;
|
|
12
|
-
swap(currentArray: readonly unknown[], currentKeys: readonly string[], leftIndex: number, rightIndex: number): FormArrayMutation | undefined;
|
|
13
|
-
replace(values: readonly unknown[], nextKeys: readonly string[]): FormArrayMutation;
|
|
14
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { FieldPath } from '../types.js';
|
|
2
|
-
export declare class FormArrayPath {
|
|
3
|
-
static hasPathPrefix(fieldPath: FieldPath, prefix: FieldPath): boolean;
|
|
4
|
-
static isArrayChildPath(fieldPath: FieldPath, arrayPath: FieldPath): boolean;
|
|
5
|
-
static replaceArrayIndex(fieldPath: FieldPath, arrayPath: FieldPath, nextIndex: number): FieldPath;
|
|
6
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { IndexMapper } from './ArrayItemReorder.js';
|
|
2
|
-
import { FormStateStore } from '../state/index.js';
|
|
3
|
-
import type { FieldPath, FormState } from '../types.js';
|
|
4
|
-
export type { IndexMapper } from './ArrayItemReorder.js';
|
|
5
|
-
export declare class FormArrayRebaser {
|
|
6
|
-
static rebase<TValues>(store: FormStateStore<TValues>, fieldPath: FieldPath, nextArray: readonly unknown[], nextKeys: readonly string[], mapPreviousIndex: IndexMapper): FormState<TValues>;
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { FormArrayFactory } from './FormArrayFactory.js';
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { CreateFormOptions, FieldPathInput, FieldSchemaOptions, FieldState, Form, FormArray, FormError, FormState, PathKey, ResetOptions, SetValueOptions } from '../types.js';
|
|
2
|
-
export declare class CreateForm<TValues> implements Form<TValues> {
|
|
3
|
-
private readonly store;
|
|
4
|
-
private readonly fields;
|
|
5
|
-
private readonly arrays;
|
|
6
|
-
private readonly submitter;
|
|
7
|
-
constructor(options: CreateFormOptions<TValues>);
|
|
8
|
-
getState(): Readonly<FormState<TValues>>;
|
|
9
|
-
subscribe(listener: () => void): () => void;
|
|
10
|
-
registerFieldSchema(path: FieldPathInput, options: FieldSchemaOptions): () => void;
|
|
11
|
-
getFieldState(path: FieldPathInput): Readonly<FieldState>;
|
|
12
|
-
getValue(path: FieldPathInput): unknown;
|
|
13
|
-
getValues(): TValues;
|
|
14
|
-
setValue(path: FieldPathInput, value: unknown, options?: SetValueOptions): void;
|
|
15
|
-
blur(path: FieldPathInput): Promise<boolean>;
|
|
16
|
-
focus(path: FieldPathInput): void;
|
|
17
|
-
setErrors(path: FieldPathInput, errors: readonly FormError[]): void;
|
|
18
|
-
clearErrors(...paths: FieldPathInput[]): void;
|
|
19
|
-
trigger(...paths: FieldPathInput[]): Promise<boolean>;
|
|
20
|
-
array(path: FieldPathInput): FormArray;
|
|
21
|
-
reset(values?: TValues, options?: ResetOptions): void;
|
|
22
|
-
submit<TResult>(onValid: (values: TValues) => TResult | Promise<TResult>, onInvalid?: (fields: Readonly<Record<PathKey, FieldState>>) => void): Promise<TResult | undefined>;
|
|
23
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { FormStateStore } from '../state/index.js';
|
|
2
|
-
import type { ValidationEngine } from '../validation/index.js';
|
|
3
|
-
import type { FieldPathInput, FieldSchemaOptions, FormError, SetValueOptions } from '../types.js';
|
|
4
|
-
export declare class FormFieldCommands<TValues> {
|
|
5
|
-
private readonly store;
|
|
6
|
-
private readonly validation;
|
|
7
|
-
constructor(store: FormStateStore<TValues>, validation: ValidationEngine<TValues>);
|
|
8
|
-
setValue(path: FieldPathInput, value: unknown, options?: SetValueOptions): void;
|
|
9
|
-
registerFieldSchema(path: FieldPathInput, options: FieldSchemaOptions): () => void;
|
|
10
|
-
blur(path: FieldPathInput): Promise<boolean>;
|
|
11
|
-
focus(_path: FieldPathInput): void;
|
|
12
|
-
setErrors(path: FieldPathInput, errors: readonly FormError[]): void;
|
|
13
|
-
clearErrors(paths: readonly FieldPathInput[]): void;
|
|
14
|
-
trigger(paths: readonly FieldPathInput[]): Promise<boolean>;
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FormStateStore } from '../state/index.js';
|
|
2
|
-
import type { ValidationEngine } from '../validation/index.js';
|
|
3
|
-
import type { FieldState, PathKey } from '../types.js';
|
|
4
|
-
export declare class FormSubmitter<TValues> {
|
|
5
|
-
private readonly store;
|
|
6
|
-
private readonly validation;
|
|
7
|
-
constructor(store: FormStateStore<TValues>, validation: ValidationEngine<TValues>);
|
|
8
|
-
submit<TResult>(onValid: (values: TValues) => TResult | Promise<TResult>, onInvalid?: (fields: Readonly<Record<PathKey, FieldState>>) => void): Promise<TResult | undefined>;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CreateForm } from './CreateForm.js';
|
package/dist/core/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { FieldPath, FieldPathInput, PathKey } from '../types.js';
|
|
2
|
-
export declare class FormPath {
|
|
3
|
-
static readonly ROOT_PATH_KEY = "$";
|
|
4
|
-
static path(...segments: FieldPath): FieldPath;
|
|
5
|
-
static toFieldPath(fieldPath: FieldPathInput): FieldPath;
|
|
6
|
-
static pathInputToKey(fieldPath: FieldPathInput): PathKey;
|
|
7
|
-
static pathToKey(fieldPath: FieldPath): PathKey;
|
|
8
|
-
static keyToPath(key: PathKey): FieldPath;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { FormPath } from './FormPath.js';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { FormState } from '../types.js';
|
|
2
|
-
export declare class FormStateInitializer {
|
|
3
|
-
static initialize<TValues>(defaultValues: TValues): FormState<TValues>;
|
|
4
|
-
private static isTraversableObject;
|
|
5
|
-
private static createInitialArrayKeys;
|
|
6
|
-
private static visitInitialValue;
|
|
7
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { FieldPath, FieldPathInput, FieldState, FormState, PathKey } from '../types.js';
|
|
2
|
-
export declare class FormStateReader<TValues> {
|
|
3
|
-
private readonly getSnapshot;
|
|
4
|
-
constructor(getSnapshot: () => Readonly<FormState<TValues>>);
|
|
5
|
-
getKnownFieldPaths(): Record<PathKey, FieldPath>;
|
|
6
|
-
getFieldStateByKey(fieldKey: PathKey): Readonly<FieldState>;
|
|
7
|
-
getFieldState(fieldPath: FieldPathInput): Readonly<FieldState>;
|
|
8
|
-
getValue(fieldPath: FieldPathInput): unknown;
|
|
9
|
-
getValues(): TValues;
|
|
10
|
-
getValueAtPath(fieldPath: FieldPath): unknown;
|
|
11
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { FieldPath, FieldPathInput, FieldState, FormError, FormState, PathKey, ResetOptions, SetValueOptions } from '../types.js';
|
|
2
|
-
export declare class FormStateStore<TValues> {
|
|
3
|
-
private readonly store;
|
|
4
|
-
private readonly reader;
|
|
5
|
-
private readonly writer;
|
|
6
|
-
static getDefaultFieldState(): FieldState;
|
|
7
|
-
constructor(defaultValues: TValues);
|
|
8
|
-
getState(): Readonly<FormState<TValues>>;
|
|
9
|
-
subscribe(listener: () => void): () => void;
|
|
10
|
-
getKnownFieldPaths(): Record<PathKey, FieldPath>;
|
|
11
|
-
getFieldStateByKey(fieldKey: PathKey): Readonly<FieldState>;
|
|
12
|
-
getFieldState(fieldPath: FieldPathInput): Readonly<FieldState>;
|
|
13
|
-
getValue(fieldPath: FieldPathInput): unknown;
|
|
14
|
-
getValues(): TValues;
|
|
15
|
-
getValueAtPath(fieldPath: FieldPath): unknown;
|
|
16
|
-
setValue(fieldPath: FieldPath, value: unknown, options?: SetValueOptions): PathKey;
|
|
17
|
-
touchField(fieldKey: PathKey): void;
|
|
18
|
-
setErrorsByKey(fieldKey: PathKey, errors: readonly FormError[]): void;
|
|
19
|
-
clearErrors(fieldKeys?: readonly PathKey[]): void;
|
|
20
|
-
reset(values?: TValues, options?: ResetOptions): void;
|
|
21
|
-
beginSubmit(): void;
|
|
22
|
-
completeSubmit(successful: boolean): void;
|
|
23
|
-
replaceState(updater: (previousState: FormState<TValues>) => FormState<TValues>): void;
|
|
24
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Store } from '@ilokesto/store';
|
|
2
|
-
import type { FieldPath, FormError, FormState, PathKey, ResetOptions, SetValueOptions } from '../types.js';
|
|
3
|
-
type WritableFormStore<TValues> = Pick<Store<FormState<TValues>>, 'getState' | 'setState'>;
|
|
4
|
-
export declare class FormStateWriter<TValues> {
|
|
5
|
-
private readonly store;
|
|
6
|
-
constructor(store: WritableFormStore<TValues>);
|
|
7
|
-
setValue(fieldPath: FieldPath, value: unknown, options?: SetValueOptions): PathKey;
|
|
8
|
-
touchField(fieldKey: PathKey): void;
|
|
9
|
-
setErrorsByKey(fieldKey: PathKey, errors: readonly FormError[]): void;
|
|
10
|
-
clearErrors(fieldKeys?: readonly PathKey[]): void;
|
|
11
|
-
reset(values?: TValues, options?: ResetOptions): void;
|
|
12
|
-
beginSubmit(): void;
|
|
13
|
-
completeSubmit(successful: boolean): void;
|
|
14
|
-
replaceState(updater: (previousState: FormState<TValues>) => FormState<TValues>): void;
|
|
15
|
-
private static isSameValue;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { FormStateStore } from './FormStateStore.js';
|
package/dist/core/types.d.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
export type FieldPathSegment = string | number;
|
|
2
|
-
export type FieldPath = readonly FieldPathSegment[];
|
|
3
|
-
export type FieldPathInput = string | FieldPath;
|
|
4
|
-
export type PathKey = string;
|
|
5
|
-
export type FormError = {
|
|
6
|
-
type?: string;
|
|
7
|
-
message: string;
|
|
8
|
-
};
|
|
9
|
-
export type ValidationTrigger = 'change' | 'blur' | 'submit' | 'manual';
|
|
10
|
-
export type StandardSchemaV1<Input = unknown, Output = Input> = {
|
|
11
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
12
|
-
};
|
|
13
|
-
export declare namespace StandardSchemaV1 {
|
|
14
|
-
type Props<Input = unknown, Output = Input> = {
|
|
15
|
-
readonly version: 1;
|
|
16
|
-
readonly vendor: string;
|
|
17
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
18
|
-
readonly validate: (value: unknown, options?: Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
19
|
-
};
|
|
20
|
-
type Types<Input = unknown, Output = Input> = {
|
|
21
|
-
readonly input: Input;
|
|
22
|
-
readonly output: Output;
|
|
23
|
-
};
|
|
24
|
-
type Options = {
|
|
25
|
-
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
26
|
-
};
|
|
27
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
28
|
-
type SuccessResult<Output> = {
|
|
29
|
-
readonly value: Output;
|
|
30
|
-
readonly issues?: undefined;
|
|
31
|
-
};
|
|
32
|
-
type FailureResult = {
|
|
33
|
-
readonly issues: readonly Issue[];
|
|
34
|
-
};
|
|
35
|
-
type Issue = {
|
|
36
|
-
readonly message: string;
|
|
37
|
-
readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;
|
|
38
|
-
};
|
|
39
|
-
type PathSegment = {
|
|
40
|
-
readonly key: PropertyKey;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export type FieldState<TValue = unknown> = {
|
|
44
|
-
value: TValue;
|
|
45
|
-
errors: FormError[];
|
|
46
|
-
touched: boolean;
|
|
47
|
-
dirty: boolean;
|
|
48
|
-
modified: boolean;
|
|
49
|
-
};
|
|
50
|
-
export type FieldPathValue<TValues, TName extends FieldPathInput> = TName extends string ? StringFieldValue<TValues, TName> : TName extends FieldPath ? TuplePathValue<TValues, TName> : unknown;
|
|
51
|
-
type StringFieldValue<TValues, TName extends string> = TName extends keyof NonNullable<TValues> ? NonNullable<TValues>[TName] | MissingContainer<TValues> : unknown;
|
|
52
|
-
type TuplePathValue<TValue, TPath extends FieldPath> = TPath extends readonly [] ? TValue : TPath extends readonly [infer THead, ...infer TRest] ? THead extends FieldPathSegment ? TRest extends FieldPath ? SegmentValue<TValue, THead, TRest> : unknown : unknown : unknown;
|
|
53
|
-
type SegmentValue<TValue, THead extends FieldPathSegment, TRest extends FieldPath> = NonNullable<TValue> extends readonly unknown[] ? THead extends number ? TuplePathValue<ArrayElement<NonNullable<TValue>, THead>, TRest> | MissingContainer<TValue> : unknown : THead extends keyof NonNullable<TValue> ? TuplePathValue<NonNullable<TValue>[THead], TRest> | MissingContainer<TValue> : unknown;
|
|
54
|
-
type ArrayElement<TArray, TIndex extends number> = TArray extends readonly unknown[] ? TIndex extends keyof TArray ? TArray[TIndex] : TArray[number] : unknown;
|
|
55
|
-
type MissingContainer<TValue> = Extract<TValue, null | undefined> extends never ? never : undefined;
|
|
56
|
-
export type ArrayKeys = Record<PathKey, string[]>;
|
|
57
|
-
export type FormState<TValues> = {
|
|
58
|
-
defaultValues: TValues;
|
|
59
|
-
fields: Record<PathKey, FieldState>;
|
|
60
|
-
submitCount: number;
|
|
61
|
-
isSubmitting: boolean;
|
|
62
|
-
isSubmitted: boolean;
|
|
63
|
-
isSubmitSuccessful: boolean;
|
|
64
|
-
arrayKeys: ArrayKeys;
|
|
65
|
-
};
|
|
66
|
-
export type CreateFormOptions<TValues> = {
|
|
67
|
-
defaultValues: TValues;
|
|
68
|
-
schema?: StandardSchemaV1<unknown, TValues>;
|
|
69
|
-
schemaOptions?: StandardSchemaV1.Options;
|
|
70
|
-
validateOn?: readonly ValidationTrigger[];
|
|
71
|
-
};
|
|
72
|
-
export type ResetOptions = {
|
|
73
|
-
keepDirtyValues?: boolean;
|
|
74
|
-
keepErrors?: boolean;
|
|
75
|
-
keepTouched?: boolean;
|
|
76
|
-
keepSubmitState?: boolean;
|
|
77
|
-
};
|
|
78
|
-
export type FieldSchemaOptions = {
|
|
79
|
-
schema: StandardSchemaV1<unknown, unknown>;
|
|
80
|
-
schemaOptions?: StandardSchemaV1.Options;
|
|
81
|
-
};
|
|
82
|
-
export type Form<TValues> = {
|
|
83
|
-
getState(): Readonly<FormState<TValues>>;
|
|
84
|
-
subscribe(listener: () => void): () => void;
|
|
85
|
-
registerFieldSchema(path: FieldPathInput, options: FieldSchemaOptions): () => void;
|
|
86
|
-
getFieldState(path: FieldPathInput): Readonly<FieldState>;
|
|
87
|
-
getValue(path: FieldPathInput): unknown;
|
|
88
|
-
getValues(): TValues;
|
|
89
|
-
setValue(path: FieldPathInput, value: unknown, options?: SetValueOptions): void;
|
|
90
|
-
blur(path: FieldPathInput): Promise<boolean>;
|
|
91
|
-
focus(path: FieldPathInput): void;
|
|
92
|
-
setErrors(path: FieldPathInput, errors: readonly FormError[]): void;
|
|
93
|
-
clearErrors(...paths: FieldPathInput[]): void;
|
|
94
|
-
trigger(...paths: FieldPathInput[]): Promise<boolean>;
|
|
95
|
-
array(path: FieldPathInput): FormArray;
|
|
96
|
-
reset(values?: TValues, options?: ResetOptions): void;
|
|
97
|
-
submit<TResult>(onValid: (values: TValues) => TResult | Promise<TResult>, onInvalid?: (fields: Readonly<Record<PathKey, FieldState>>) => void): Promise<TResult | undefined>;
|
|
98
|
-
};
|
|
99
|
-
export type FormArray = {
|
|
100
|
-
keys(): readonly string[];
|
|
101
|
-
insert(index: number, value: unknown): void;
|
|
102
|
-
push(value: unknown): void;
|
|
103
|
-
remove(index: number): void;
|
|
104
|
-
move(fromIndex: number, toIndex: number): void;
|
|
105
|
-
swap(leftIndex: number, rightIndex: number): void;
|
|
106
|
-
replace(values: readonly unknown[]): void;
|
|
107
|
-
};
|
|
108
|
-
export type SetValueOptions = {
|
|
109
|
-
source?: 'user' | 'program';
|
|
110
|
-
validate?: boolean;
|
|
111
|
-
};
|
|
112
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { FormError, PathKey, StandardSchemaV1 } from '../types.js';
|
|
2
|
-
export declare class StandardSchemaValidator<TValues> {
|
|
3
|
-
private readonly schema;
|
|
4
|
-
private readonly options?;
|
|
5
|
-
constructor(schema: StandardSchemaV1<unknown, TValues>, options?: StandardSchemaV1.Options | undefined);
|
|
6
|
-
validate(values: TValues): Promise<StandardSchemaValidationResult>;
|
|
7
|
-
validateValue(value: unknown): Promise<FormError[]>;
|
|
8
|
-
private static issuePathToFieldPath;
|
|
9
|
-
private static issuePathSegmentToKey;
|
|
10
|
-
}
|
|
11
|
-
export type StandardSchemaValidationResult = {
|
|
12
|
-
valid: boolean;
|
|
13
|
-
errorsByKey: Record<PathKey, FormError[]>;
|
|
14
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { FormStateStore } from '../state/index.js';
|
|
2
|
-
import type { CreateFormOptions, FieldSchemaOptions, PathKey, ValidationTrigger } from '../types.js';
|
|
3
|
-
export declare class ValidationEngine<TValues> {
|
|
4
|
-
private static readonly DEFAULT_VALIDATE_ON;
|
|
5
|
-
private readonly store;
|
|
6
|
-
private readonly schema?;
|
|
7
|
-
private readonly fieldSchemas;
|
|
8
|
-
private readonly validateOn;
|
|
9
|
-
private nextFieldSchemaId;
|
|
10
|
-
constructor(store: FormStateStore<TValues>, options: CreateFormOptions<TValues>);
|
|
11
|
-
shouldValidateOn(trigger: ValidationTrigger): boolean;
|
|
12
|
-
registerFieldSchema(fieldKey: PathKey, options: FieldSchemaOptions): () => void;
|
|
13
|
-
validateField(fieldKey: PathKey, _trigger: ValidationTrigger): Promise<boolean>;
|
|
14
|
-
validateFields(fieldKeys: readonly PathKey[], _trigger: ValidationTrigger): Promise<boolean>;
|
|
15
|
-
validateRegisteredFields(_trigger: ValidationTrigger): Promise<boolean>;
|
|
16
|
-
private validateSchema;
|
|
17
|
-
private applyErrors;
|
|
18
|
-
private validateFieldSchema;
|
|
19
|
-
private validateFieldSchemas;
|
|
20
|
-
private validateRegisteredFieldSchemas;
|
|
21
|
-
private mergeErrorsByKey;
|
|
22
|
-
private getValidationWriteKeys;
|
|
23
|
-
private static unique;
|
|
24
|
-
private static createValidSchemaResult;
|
|
25
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ValidationEngine } from './ValidationEngine.js';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { FieldPath, FormState, PathKey } from '../types.js';
|
|
2
|
-
export declare class ValueHelper {
|
|
3
|
-
private static createEmptyRoot;
|
|
4
|
-
static getValueAtPath(source: unknown, path: FieldPath): unknown;
|
|
5
|
-
static setValueAtPath<TValues>(source: TValues, path: FieldPath, value: unknown): TValues;
|
|
6
|
-
static getValuesFromFields<TValues>(state: FormState<TValues>, fieldPaths: Readonly<Record<PathKey, FieldPath>>): TValues;
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ValueHelper } from './ValueHelper.js';
|
|
@@ -1,5 +0,0 @@
|
|
|
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 };
|