@neutro/form 0.0.4 → 0.0.5

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,6 +1,27 @@
1
- export * from '@neutro/form-angular';
2
- import '@neutro/form-react';
3
- import '@neutro/form-solid';
4
- import '@neutro/form-svelte';
5
- import '@neutro/form-vue';
6
- import '@neutro/form-core';
1
+ import * as _angular_core from '@angular/core';
2
+
3
+ declare function useAngularForm<T extends object>(form: any): {
4
+ state: _angular_core.Signal<any>;
5
+ get: any;
6
+ set: any;
7
+ connect: any;
8
+ submit: any;
9
+ handleSubmit: any;
10
+ reset: any;
11
+ batch: any;
12
+ arrayAppend: any;
13
+ arrayInsert: any;
14
+ arrayRemove: any;
15
+ arrayMove: any;
16
+ arraySwap: any;
17
+ };
18
+ declare function useAngularFormPath(form: any, path: string): {
19
+ value: _angular_core.Signal<unknown>;
20
+ fieldState: _angular_core.Signal<{
21
+ error?: string;
22
+ touched?: boolean;
23
+ dirty?: boolean;
24
+ } | null>;
25
+ };
26
+
27
+ export { useAngularForm, useAngularFormPath };
@@ -1,6 +1,27 @@
1
- export * from '@neutro/form-angular';
2
- import '@neutro/form-react';
3
- import '@neutro/form-solid';
4
- import '@neutro/form-svelte';
5
- import '@neutro/form-vue';
6
- import '@neutro/form-core';
1
+ import * as _angular_core from '@angular/core';
2
+
3
+ declare function useAngularForm<T extends object>(form: any): {
4
+ state: _angular_core.Signal<any>;
5
+ get: any;
6
+ set: any;
7
+ connect: any;
8
+ submit: any;
9
+ handleSubmit: any;
10
+ reset: any;
11
+ batch: any;
12
+ arrayAppend: any;
13
+ arrayInsert: any;
14
+ arrayRemove: any;
15
+ arrayMove: any;
16
+ arraySwap: any;
17
+ };
18
+ declare function useAngularFormPath(form: any, path: string): {
19
+ value: _angular_core.Signal<unknown>;
20
+ fieldState: _angular_core.Signal<{
21
+ error?: string;
22
+ touched?: boolean;
23
+ dirty?: boolean;
24
+ } | null>;
25
+ };
26
+
27
+ export { useAngularForm, useAngularFormPath };
@@ -1 +1,58 @@
1
- export * from '@neutro/form-react';
1
+ /**
2
+ * @neutro/form-core
3
+ * High-Performance, Zero-Dependency, Framework-Agnostic Reactive Form Engine.
4
+ */
5
+ type Primitive = string | number | boolean | null | undefined | Date | File;
6
+ type Prev = [never, 0, 1, 2, 3, 4, 5, ...any[]];
7
+ type PathImpl<T, K extends keyof T, Depth extends number = 5> = [Depth] extends [never] ? never : K extends string ? T[K] extends Primitive ? K : T[K] extends Array<infer U> ? K | `${K}.${number}` | (U extends object ? `${K}.${number}.${PathImpl<U, keyof U, Prev[Depth]>}` : never) : T[K] extends object ? K | `${K}.${PathImpl<T[K], keyof T[K], Prev[Depth]>}` : K : never;
8
+ type Path<T> = PathImpl<T, keyof T> & string;
9
+ type _GetPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? _GetPathValue<NonNullable<T[K]>, Rest> : T extends readonly any[] ? _GetPathValue<NonNullable<T[number]>, Rest> : unknown : P extends keyof T ? T[P] : T extends readonly any[] ? T[number] : unknown;
10
+ type GetPathValue<T, P extends string> = _GetPathValue<T, P>;
11
+ interface FormState<T> {
12
+ values: T;
13
+ errors: Record<string, string>;
14
+ touched: Record<string, boolean>;
15
+ dirty: Record<string, boolean>;
16
+ isSubmitting: boolean;
17
+ isValidating: boolean;
18
+ }
19
+ type FormSubscriber<T> = (state: FormState<T>) => void;
20
+ type PathSubscriber = (value: any, fieldState: {
21
+ error?: string;
22
+ touched?: boolean;
23
+ dirty?: boolean;
24
+ }) => void;
25
+ interface ConnectOptions {
26
+ persist?: boolean;
27
+ format?: (val: string) => string;
28
+ }
29
+ interface FormInstance<T extends object> {
30
+ subscribe: (fn: FormSubscriber<T>) => () => void;
31
+ subscribeToPath: (path: Path<T> | string, fn: PathSubscriber) => () => void;
32
+ get: (path: Path<T> | string | string[]) => any;
33
+ set: (path: Path<T> | string | string[], val: any, options?: {
34
+ touch?: boolean;
35
+ validate?: boolean;
36
+ }) => void;
37
+ validate: (scopePaths?: Path<T>[] | string[] | string[][]) => Promise<boolean>;
38
+ connect: (path: Path<T> | string, el: HTMLElement, options?: ConnectOptions) => () => void;
39
+ submit: (onValid: (payload: Partial<T>) => void | Promise<void>) => Promise<boolean>;
40
+ handleSubmit: (onValid: (payload: Partial<T>) => void | Promise<void>, onInvalid?: (errors: Record<string, string>) => void) => (e?: Event) => void;
41
+ getState: () => FormState<T>;
42
+ getPayload: () => Partial<T>;
43
+ batch: (fn: () => void) => void;
44
+ arrayAppend: (path: Path<T> | string | string[], item: any) => void;
45
+ arrayInsert: (path: Path<T> | string | string[], index: number, item: any) => void;
46
+ arrayRemove: (path: Path<T> | string | string[], index: number) => void;
47
+ arrayMove: (path: Path<T> | string | string[], fromIndex: number, toIndex: number) => void;
48
+ arraySwap: (path: Path<T> | string | string[], indexA: number, indexB: number) => void;
49
+ reset: (newValues?: T) => void;
50
+ getConnectedCount: () => number;
51
+ destroy: () => void;
52
+ }
53
+
54
+ declare function useForm<T extends object>(form: FormInstance<T>): FormState<T> & Omit<FormInstance<T>, 'subscribe' | 'getState'>;
55
+ declare function useFormPath<T extends object, P extends Path<T>>(form: FormInstance<T>, path: P): GetPathValue<T, P>;
56
+ declare function useFormConnect(form: any): (path: string, options?: any) => (el: HTMLElement | null) => void;
57
+
58
+ export { useForm, useFormConnect, useFormPath };
@@ -1 +1,58 @@
1
- export * from '@neutro/form-react';
1
+ /**
2
+ * @neutro/form-core
3
+ * High-Performance, Zero-Dependency, Framework-Agnostic Reactive Form Engine.
4
+ */
5
+ type Primitive = string | number | boolean | null | undefined | Date | File;
6
+ type Prev = [never, 0, 1, 2, 3, 4, 5, ...any[]];
7
+ type PathImpl<T, K extends keyof T, Depth extends number = 5> = [Depth] extends [never] ? never : K extends string ? T[K] extends Primitive ? K : T[K] extends Array<infer U> ? K | `${K}.${number}` | (U extends object ? `${K}.${number}.${PathImpl<U, keyof U, Prev[Depth]>}` : never) : T[K] extends object ? K | `${K}.${PathImpl<T[K], keyof T[K], Prev[Depth]>}` : K : never;
8
+ type Path<T> = PathImpl<T, keyof T> & string;
9
+ type _GetPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? _GetPathValue<NonNullable<T[K]>, Rest> : T extends readonly any[] ? _GetPathValue<NonNullable<T[number]>, Rest> : unknown : P extends keyof T ? T[P] : T extends readonly any[] ? T[number] : unknown;
10
+ type GetPathValue<T, P extends string> = _GetPathValue<T, P>;
11
+ interface FormState<T> {
12
+ values: T;
13
+ errors: Record<string, string>;
14
+ touched: Record<string, boolean>;
15
+ dirty: Record<string, boolean>;
16
+ isSubmitting: boolean;
17
+ isValidating: boolean;
18
+ }
19
+ type FormSubscriber<T> = (state: FormState<T>) => void;
20
+ type PathSubscriber = (value: any, fieldState: {
21
+ error?: string;
22
+ touched?: boolean;
23
+ dirty?: boolean;
24
+ }) => void;
25
+ interface ConnectOptions {
26
+ persist?: boolean;
27
+ format?: (val: string) => string;
28
+ }
29
+ interface FormInstance<T extends object> {
30
+ subscribe: (fn: FormSubscriber<T>) => () => void;
31
+ subscribeToPath: (path: Path<T> | string, fn: PathSubscriber) => () => void;
32
+ get: (path: Path<T> | string | string[]) => any;
33
+ set: (path: Path<T> | string | string[], val: any, options?: {
34
+ touch?: boolean;
35
+ validate?: boolean;
36
+ }) => void;
37
+ validate: (scopePaths?: Path<T>[] | string[] | string[][]) => Promise<boolean>;
38
+ connect: (path: Path<T> | string, el: HTMLElement, options?: ConnectOptions) => () => void;
39
+ submit: (onValid: (payload: Partial<T>) => void | Promise<void>) => Promise<boolean>;
40
+ handleSubmit: (onValid: (payload: Partial<T>) => void | Promise<void>, onInvalid?: (errors: Record<string, string>) => void) => (e?: Event) => void;
41
+ getState: () => FormState<T>;
42
+ getPayload: () => Partial<T>;
43
+ batch: (fn: () => void) => void;
44
+ arrayAppend: (path: Path<T> | string | string[], item: any) => void;
45
+ arrayInsert: (path: Path<T> | string | string[], index: number, item: any) => void;
46
+ arrayRemove: (path: Path<T> | string | string[], index: number) => void;
47
+ arrayMove: (path: Path<T> | string | string[], fromIndex: number, toIndex: number) => void;
48
+ arraySwap: (path: Path<T> | string | string[], indexA: number, indexB: number) => void;
49
+ reset: (newValues?: T) => void;
50
+ getConnectedCount: () => number;
51
+ destroy: () => void;
52
+ }
53
+
54
+ declare function useForm<T extends object>(form: FormInstance<T>): FormState<T> & Omit<FormInstance<T>, 'subscribe' | 'getState'>;
55
+ declare function useFormPath<T extends object, P extends Path<T>>(form: FormInstance<T>, path: P): GetPathValue<T, P>;
56
+ declare function useFormConnect(form: any): (path: string, options?: any) => (el: HTMLElement | null) => void;
57
+
58
+ export { useForm, useFormConnect, useFormPath };
@@ -1 +1,26 @@
1
- export * from '@neutro/form-solid';
1
+ import * as solid_js from 'solid-js';
2
+
3
+ declare function useSolidForm<T extends object>(form: any): readonly [any, {
4
+ readonly get: any;
5
+ readonly set: any;
6
+ readonly connect: any;
7
+ readonly submit: any;
8
+ readonly handleSubmit: any;
9
+ readonly reset: any;
10
+ readonly batch: any;
11
+ readonly arrayAppend: any;
12
+ readonly arrayInsert: any;
13
+ readonly arrayRemove: any;
14
+ readonly arrayMove: any;
15
+ readonly arraySwap: any;
16
+ }];
17
+ declare function useSolidFormPath(form: any, path: () => string): {
18
+ value: solid_js.Accessor<unknown>;
19
+ fieldState: solid_js.Accessor<{
20
+ error?: string;
21
+ touched?: boolean;
22
+ dirty?: boolean;
23
+ } | null>;
24
+ };
25
+
26
+ export { useSolidForm, useSolidFormPath };
@@ -1 +1,26 @@
1
- export * from '@neutro/form-solid';
1
+ import * as solid_js from 'solid-js';
2
+
3
+ declare function useSolidForm<T extends object>(form: any): readonly [any, {
4
+ readonly get: any;
5
+ readonly set: any;
6
+ readonly connect: any;
7
+ readonly submit: any;
8
+ readonly handleSubmit: any;
9
+ readonly reset: any;
10
+ readonly batch: any;
11
+ readonly arrayAppend: any;
12
+ readonly arrayInsert: any;
13
+ readonly arrayRemove: any;
14
+ readonly arrayMove: any;
15
+ readonly arraySwap: any;
16
+ }];
17
+ declare function useSolidFormPath(form: any, path: () => string): {
18
+ value: solid_js.Accessor<unknown>;
19
+ fieldState: solid_js.Accessor<{
20
+ error?: string;
21
+ touched?: boolean;
22
+ dirty?: boolean;
23
+ } | null>;
24
+ };
25
+
26
+ export { useSolidForm, useSolidFormPath };
@@ -1 +1,27 @@
1
- export * from '@neutro/form-svelte';
1
+ import * as svelte_store from 'svelte/store';
2
+
3
+ declare function useSvelteForm(form: any): {
4
+ state: svelte_store.Readable<any>;
5
+ get: any;
6
+ set: any;
7
+ connect: any;
8
+ submit: any;
9
+ handleSubmit: any;
10
+ reset: any;
11
+ batch: any;
12
+ arrayAppend: any;
13
+ arrayInsert: any;
14
+ arrayRemove: any;
15
+ arrayMove: any;
16
+ arraySwap: any;
17
+ };
18
+ declare function useSvelteFormPath(form: any, path: string): svelte_store.Readable<{
19
+ value: unknown;
20
+ fieldState: {
21
+ error?: string;
22
+ touched?: boolean;
23
+ dirty?: boolean;
24
+ } | null;
25
+ }>;
26
+
27
+ export { useSvelteForm, useSvelteFormPath };
@@ -1 +1,27 @@
1
- export * from '@neutro/form-svelte';
1
+ import * as svelte_store from 'svelte/store';
2
+
3
+ declare function useSvelteForm(form: any): {
4
+ state: svelte_store.Readable<any>;
5
+ get: any;
6
+ set: any;
7
+ connect: any;
8
+ submit: any;
9
+ handleSubmit: any;
10
+ reset: any;
11
+ batch: any;
12
+ arrayAppend: any;
13
+ arrayInsert: any;
14
+ arrayRemove: any;
15
+ arrayMove: any;
16
+ arraySwap: any;
17
+ };
18
+ declare function useSvelteFormPath(form: any, path: string): svelte_store.Readable<{
19
+ value: unknown;
20
+ fieldState: {
21
+ error?: string;
22
+ touched?: boolean;
23
+ dirty?: boolean;
24
+ } | null;
25
+ }>;
26
+
27
+ export { useSvelteForm, useSvelteFormPath };
@@ -1 +1,32 @@
1
- export * from '@neutro/form-vue';
1
+ import * as vue from 'vue';
2
+ import { MaybeRef } from 'vue';
3
+
4
+ declare function useVueForm<T extends object>(form: any): {
5
+ state: Readonly<vue.Ref<any, any>>;
6
+ get: any;
7
+ set: any;
8
+ connect: any;
9
+ submit: any;
10
+ handleSubmit: any;
11
+ reset: any;
12
+ batch: any;
13
+ arrayAppend: any;
14
+ arrayInsert: any;
15
+ arrayRemove: any;
16
+ arrayMove: any;
17
+ arraySwap: any;
18
+ };
19
+ declare function useVueFormPath(form: any, path: MaybeRef<string>): {
20
+ value: Readonly<vue.Ref<Readonly<unknown>, Readonly<unknown>>>;
21
+ fieldState: Readonly<vue.Ref<{
22
+ readonly error?: string | undefined;
23
+ readonly touched?: boolean | undefined;
24
+ readonly dirty?: boolean | undefined;
25
+ } | null, {
26
+ readonly error?: string | undefined;
27
+ readonly touched?: boolean | undefined;
28
+ readonly dirty?: boolean | undefined;
29
+ } | null>>;
30
+ };
31
+
32
+ export { useVueForm, useVueFormPath };
@@ -1 +1,32 @@
1
- export * from '@neutro/form-vue';
1
+ import * as vue from 'vue';
2
+ import { MaybeRef } from 'vue';
3
+
4
+ declare function useVueForm<T extends object>(form: any): {
5
+ state: Readonly<vue.Ref<any, any>>;
6
+ get: any;
7
+ set: any;
8
+ connect: any;
9
+ submit: any;
10
+ handleSubmit: any;
11
+ reset: any;
12
+ batch: any;
13
+ arrayAppend: any;
14
+ arrayInsert: any;
15
+ arrayRemove: any;
16
+ arrayMove: any;
17
+ arraySwap: any;
18
+ };
19
+ declare function useVueFormPath(form: any, path: MaybeRef<string>): {
20
+ value: Readonly<vue.Ref<Readonly<unknown>, Readonly<unknown>>>;
21
+ fieldState: Readonly<vue.Ref<{
22
+ readonly error?: string | undefined;
23
+ readonly touched?: boolean | undefined;
24
+ readonly dirty?: boolean | undefined;
25
+ } | null, {
26
+ readonly error?: string | undefined;
27
+ readonly touched?: boolean | undefined;
28
+ readonly dirty?: boolean | undefined;
29
+ } | null>>;
30
+ };
31
+
32
+ export { useVueForm, useVueFormPath };
package/dist/core.d.cts CHANGED
@@ -1 +1,161 @@
1
- export * from '@neutro/form-core';
1
+ /**
2
+ * @neutro/form-core
3
+ * High-Performance, Zero-Dependency, Framework-Agnostic Reactive Form Engine.
4
+ */
5
+ type Primitive = string | number | boolean | null | undefined | Date | File;
6
+ type DeepPartial<T> = T extends Primitive ? T : T extends Array<infer U> ? _DeepPartialArray<U> : T extends object ? _DeepPartialObject<T> : T | undefined;
7
+ interface _DeepPartialArray<T> extends Array<DeepPartial<T>> {
8
+ }
9
+ type _DeepPartialObject<T> = {
10
+ [P in keyof T]?: DeepPartial<T[P]>;
11
+ };
12
+ type Prev = [never, 0, 1, 2, 3, 4, 5, ...any[]];
13
+ type PathImpl<T, K extends keyof T, Depth extends number = 5> = [Depth] extends [never] ? never : K extends string ? T[K] extends Primitive ? K : T[K] extends Array<infer U> ? K | `${K}.${number}` | (U extends object ? `${K}.${number}.${PathImpl<U, keyof U, Prev[Depth]>}` : never) : T[K] extends object ? K | `${K}.${PathImpl<T[K], keyof T[K], Prev[Depth]>}` : K : never;
14
+ type Path<T> = PathImpl<T, keyof T> & string;
15
+ type _GetPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? _GetPathValue<NonNullable<T[K]>, Rest> : T extends readonly any[] ? _GetPathValue<NonNullable<T[number]>, Rest> : unknown : P extends keyof T ? T[P] : T extends readonly any[] ? T[number] : unknown;
16
+ type GetPathValue<T, P extends string> = _GetPathValue<T, P>;
17
+ interface FormState<T> {
18
+ values: T;
19
+ errors: Record<string, string>;
20
+ touched: Record<string, boolean>;
21
+ dirty: Record<string, boolean>;
22
+ isSubmitting: boolean;
23
+ isValidating: boolean;
24
+ }
25
+ type FormSubscriber<T> = (state: FormState<T>) => void;
26
+ type PathSubscriber = (value: any, fieldState: {
27
+ error?: string;
28
+ touched?: boolean;
29
+ dirty?: boolean;
30
+ }) => void;
31
+ type BuiltInRule = 'required' | 'accepted' | 'email' | 'url' | 'numeric' | 'integer' | 'positive' | 'nonNegative' | 'alpha' | 'alphanumeric' | 'date' | {
32
+ minLength: number;
33
+ message?: string;
34
+ } | {
35
+ maxLength: number;
36
+ message?: string;
37
+ } | {
38
+ min: number;
39
+ message?: string;
40
+ } | {
41
+ max: number;
42
+ message?: string;
43
+ } | {
44
+ startsWith: string;
45
+ message?: string;
46
+ } | {
47
+ endsWith: string;
48
+ message?: string;
49
+ } | {
50
+ includes: string;
51
+ message?: string;
52
+ } | {
53
+ pattern: string | RegExp;
54
+ message?: string;
55
+ } | {
56
+ minItems: number;
57
+ message?: string;
58
+ } | {
59
+ maxItems: number;
60
+ message?: string;
61
+ } | 'unique' | {
62
+ contains: unknown;
63
+ message?: string;
64
+ } | {
65
+ oneOf: unknown[];
66
+ message?: string;
67
+ } | {
68
+ notOneOf: unknown[];
69
+ message?: string;
70
+ } | {
71
+ matches: string;
72
+ message?: string;
73
+ } | {
74
+ doesNotMatch: string;
75
+ message?: string;
76
+ } | {
77
+ greaterThan: string;
78
+ message?: string;
79
+ } | {
80
+ lessThan: string;
81
+ message?: string;
82
+ } | {
83
+ after: string;
84
+ message?: string;
85
+ } | {
86
+ before: string;
87
+ message?: string;
88
+ } | {
89
+ requiredIf: string;
90
+ message?: string;
91
+ } | {
92
+ requiredUnless: string;
93
+ message?: string;
94
+ };
95
+ interface FormConfig<T> {
96
+ initialValues: T;
97
+ rules?: Partial<Record<string, BuiltInRule | BuiltInRule[]>>;
98
+ validator?: (values: T, scopePaths?: string[], signal?: AbortSignal) => Record<string, string> | Promise<Record<string, string>>;
99
+ dependencies?: Record<string, string[]>;
100
+ asyncDebounceMs?: number;
101
+ }
102
+ interface ConnectOptions {
103
+ persist?: boolean;
104
+ format?: (val: string) => string;
105
+ }
106
+ interface FormInstance<T extends object> {
107
+ subscribe: (fn: FormSubscriber<T>) => () => void;
108
+ subscribeToPath: (path: Path<T> | string, fn: PathSubscriber) => () => void;
109
+ get: (path: Path<T> | string | string[]) => any;
110
+ set: (path: Path<T> | string | string[], val: any, options?: {
111
+ touch?: boolean;
112
+ validate?: boolean;
113
+ }) => void;
114
+ validate: (scopePaths?: Path<T>[] | string[] | string[][]) => Promise<boolean>;
115
+ connect: (path: Path<T> | string, el: HTMLElement, options?: ConnectOptions) => () => void;
116
+ submit: (onValid: (payload: Partial<T>) => void | Promise<void>) => Promise<boolean>;
117
+ handleSubmit: (onValid: (payload: Partial<T>) => void | Promise<void>, onInvalid?: (errors: Record<string, string>) => void) => (e?: Event) => void;
118
+ getState: () => FormState<T>;
119
+ getPayload: () => Partial<T>;
120
+ batch: (fn: () => void) => void;
121
+ arrayAppend: (path: Path<T> | string | string[], item: any) => void;
122
+ arrayInsert: (path: Path<T> | string | string[], index: number, item: any) => void;
123
+ arrayRemove: (path: Path<T> | string | string[], index: number) => void;
124
+ arrayMove: (path: Path<T> | string | string[], fromIndex: number, toIndex: number) => void;
125
+ arraySwap: (path: Path<T> | string | string[], indexA: number, indexB: number) => void;
126
+ reset: (newValues?: T) => void;
127
+ getConnectedCount: () => number;
128
+ destroy: () => void;
129
+ }
130
+ declare function zodAdapter<T>(schema: {
131
+ safeParse: (values: T) => any;
132
+ }): (values: T) => Record<string, string>;
133
+ declare function valibotAdapter<T>(schema: {
134
+ safeParse: (values: T) => {
135
+ success: boolean;
136
+ issues?: Array<{
137
+ path: Array<{
138
+ key: string | number;
139
+ }>;
140
+ message: string;
141
+ }>;
142
+ };
143
+ }): (values: T) => Record<string, string>;
144
+ declare function yupAdapter<T>(schema: {
145
+ validate: (values: T, options: {
146
+ abortEarly: boolean;
147
+ }) => Promise<any>;
148
+ }): (values: T) => Promise<Record<string, string>>;
149
+ declare function classValidatorAdapter<T extends object>(cls: new () => T, validate: (obj: T) => Promise<Array<{
150
+ property: string;
151
+ constraints?: Record<string, string>;
152
+ }>>): (values: T) => Promise<Record<string, string>>;
153
+ declare function deepClone<T>(val: T, hash?: WeakMap<object, any>): T;
154
+ declare function getNestedValue(obj: any, path: string): any;
155
+ declare function setNestedValue(obj: any, path: string, value: any): void;
156
+ declare function isDeepEqual(a: any, b: any, hash?: WeakMap<object, any>): boolean;
157
+ declare function extractAllPaths(obj: any, prefix?: string): string[];
158
+ declare function compileDependencyScopes(dependencies: Record<string, string[]>, initialValues: any): Record<string, string[]>;
159
+ declare function createForm<T extends object>(config: FormConfig<T>): FormInstance<T>;
160
+
161
+ export { type BuiltInRule, type ConnectOptions, type DeepPartial, type FormConfig, type FormInstance, type FormState, type FormSubscriber, type GetPathValue, type Path, type PathImpl, type PathSubscriber, type Primitive, classValidatorAdapter, compileDependencyScopes, createForm, deepClone, extractAllPaths, getNestedValue, isDeepEqual, setNestedValue, valibotAdapter, yupAdapter, zodAdapter };
package/dist/core.d.ts CHANGED
@@ -1 +1,161 @@
1
- export * from '@neutro/form-core';
1
+ /**
2
+ * @neutro/form-core
3
+ * High-Performance, Zero-Dependency, Framework-Agnostic Reactive Form Engine.
4
+ */
5
+ type Primitive = string | number | boolean | null | undefined | Date | File;
6
+ type DeepPartial<T> = T extends Primitive ? T : T extends Array<infer U> ? _DeepPartialArray<U> : T extends object ? _DeepPartialObject<T> : T | undefined;
7
+ interface _DeepPartialArray<T> extends Array<DeepPartial<T>> {
8
+ }
9
+ type _DeepPartialObject<T> = {
10
+ [P in keyof T]?: DeepPartial<T[P]>;
11
+ };
12
+ type Prev = [never, 0, 1, 2, 3, 4, 5, ...any[]];
13
+ type PathImpl<T, K extends keyof T, Depth extends number = 5> = [Depth] extends [never] ? never : K extends string ? T[K] extends Primitive ? K : T[K] extends Array<infer U> ? K | `${K}.${number}` | (U extends object ? `${K}.${number}.${PathImpl<U, keyof U, Prev[Depth]>}` : never) : T[K] extends object ? K | `${K}.${PathImpl<T[K], keyof T[K], Prev[Depth]>}` : K : never;
14
+ type Path<T> = PathImpl<T, keyof T> & string;
15
+ type _GetPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? _GetPathValue<NonNullable<T[K]>, Rest> : T extends readonly any[] ? _GetPathValue<NonNullable<T[number]>, Rest> : unknown : P extends keyof T ? T[P] : T extends readonly any[] ? T[number] : unknown;
16
+ type GetPathValue<T, P extends string> = _GetPathValue<T, P>;
17
+ interface FormState<T> {
18
+ values: T;
19
+ errors: Record<string, string>;
20
+ touched: Record<string, boolean>;
21
+ dirty: Record<string, boolean>;
22
+ isSubmitting: boolean;
23
+ isValidating: boolean;
24
+ }
25
+ type FormSubscriber<T> = (state: FormState<T>) => void;
26
+ type PathSubscriber = (value: any, fieldState: {
27
+ error?: string;
28
+ touched?: boolean;
29
+ dirty?: boolean;
30
+ }) => void;
31
+ type BuiltInRule = 'required' | 'accepted' | 'email' | 'url' | 'numeric' | 'integer' | 'positive' | 'nonNegative' | 'alpha' | 'alphanumeric' | 'date' | {
32
+ minLength: number;
33
+ message?: string;
34
+ } | {
35
+ maxLength: number;
36
+ message?: string;
37
+ } | {
38
+ min: number;
39
+ message?: string;
40
+ } | {
41
+ max: number;
42
+ message?: string;
43
+ } | {
44
+ startsWith: string;
45
+ message?: string;
46
+ } | {
47
+ endsWith: string;
48
+ message?: string;
49
+ } | {
50
+ includes: string;
51
+ message?: string;
52
+ } | {
53
+ pattern: string | RegExp;
54
+ message?: string;
55
+ } | {
56
+ minItems: number;
57
+ message?: string;
58
+ } | {
59
+ maxItems: number;
60
+ message?: string;
61
+ } | 'unique' | {
62
+ contains: unknown;
63
+ message?: string;
64
+ } | {
65
+ oneOf: unknown[];
66
+ message?: string;
67
+ } | {
68
+ notOneOf: unknown[];
69
+ message?: string;
70
+ } | {
71
+ matches: string;
72
+ message?: string;
73
+ } | {
74
+ doesNotMatch: string;
75
+ message?: string;
76
+ } | {
77
+ greaterThan: string;
78
+ message?: string;
79
+ } | {
80
+ lessThan: string;
81
+ message?: string;
82
+ } | {
83
+ after: string;
84
+ message?: string;
85
+ } | {
86
+ before: string;
87
+ message?: string;
88
+ } | {
89
+ requiredIf: string;
90
+ message?: string;
91
+ } | {
92
+ requiredUnless: string;
93
+ message?: string;
94
+ };
95
+ interface FormConfig<T> {
96
+ initialValues: T;
97
+ rules?: Partial<Record<string, BuiltInRule | BuiltInRule[]>>;
98
+ validator?: (values: T, scopePaths?: string[], signal?: AbortSignal) => Record<string, string> | Promise<Record<string, string>>;
99
+ dependencies?: Record<string, string[]>;
100
+ asyncDebounceMs?: number;
101
+ }
102
+ interface ConnectOptions {
103
+ persist?: boolean;
104
+ format?: (val: string) => string;
105
+ }
106
+ interface FormInstance<T extends object> {
107
+ subscribe: (fn: FormSubscriber<T>) => () => void;
108
+ subscribeToPath: (path: Path<T> | string, fn: PathSubscriber) => () => void;
109
+ get: (path: Path<T> | string | string[]) => any;
110
+ set: (path: Path<T> | string | string[], val: any, options?: {
111
+ touch?: boolean;
112
+ validate?: boolean;
113
+ }) => void;
114
+ validate: (scopePaths?: Path<T>[] | string[] | string[][]) => Promise<boolean>;
115
+ connect: (path: Path<T> | string, el: HTMLElement, options?: ConnectOptions) => () => void;
116
+ submit: (onValid: (payload: Partial<T>) => void | Promise<void>) => Promise<boolean>;
117
+ handleSubmit: (onValid: (payload: Partial<T>) => void | Promise<void>, onInvalid?: (errors: Record<string, string>) => void) => (e?: Event) => void;
118
+ getState: () => FormState<T>;
119
+ getPayload: () => Partial<T>;
120
+ batch: (fn: () => void) => void;
121
+ arrayAppend: (path: Path<T> | string | string[], item: any) => void;
122
+ arrayInsert: (path: Path<T> | string | string[], index: number, item: any) => void;
123
+ arrayRemove: (path: Path<T> | string | string[], index: number) => void;
124
+ arrayMove: (path: Path<T> | string | string[], fromIndex: number, toIndex: number) => void;
125
+ arraySwap: (path: Path<T> | string | string[], indexA: number, indexB: number) => void;
126
+ reset: (newValues?: T) => void;
127
+ getConnectedCount: () => number;
128
+ destroy: () => void;
129
+ }
130
+ declare function zodAdapter<T>(schema: {
131
+ safeParse: (values: T) => any;
132
+ }): (values: T) => Record<string, string>;
133
+ declare function valibotAdapter<T>(schema: {
134
+ safeParse: (values: T) => {
135
+ success: boolean;
136
+ issues?: Array<{
137
+ path: Array<{
138
+ key: string | number;
139
+ }>;
140
+ message: string;
141
+ }>;
142
+ };
143
+ }): (values: T) => Record<string, string>;
144
+ declare function yupAdapter<T>(schema: {
145
+ validate: (values: T, options: {
146
+ abortEarly: boolean;
147
+ }) => Promise<any>;
148
+ }): (values: T) => Promise<Record<string, string>>;
149
+ declare function classValidatorAdapter<T extends object>(cls: new () => T, validate: (obj: T) => Promise<Array<{
150
+ property: string;
151
+ constraints?: Record<string, string>;
152
+ }>>): (values: T) => Promise<Record<string, string>>;
153
+ declare function deepClone<T>(val: T, hash?: WeakMap<object, any>): T;
154
+ declare function getNestedValue(obj: any, path: string): any;
155
+ declare function setNestedValue(obj: any, path: string, value: any): void;
156
+ declare function isDeepEqual(a: any, b: any, hash?: WeakMap<object, any>): boolean;
157
+ declare function extractAllPaths(obj: any, prefix?: string): string[];
158
+ declare function compileDependencyScopes(dependencies: Record<string, string[]>, initialValues: any): Record<string, string[]>;
159
+ declare function createForm<T extends object>(config: FormConfig<T>): FormInstance<T>;
160
+
161
+ export { type BuiltInRule, type ConnectOptions, type DeepPartial, type FormConfig, type FormInstance, type FormState, type FormSubscriber, type GetPathValue, type Path, type PathImpl, type PathSubscriber, type Primitive, classValidatorAdapter, compileDependencyScopes, createForm, deepClone, extractAllPaths, getNestedValue, isDeepEqual, setNestedValue, valibotAdapter, yupAdapter, zodAdapter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neutro/form",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "High-performance, zero-dependency, framework-agnostic reactive form engine.",
5
5
  "keywords": [
6
6
  "form",
@@ -107,10 +107,10 @@
107
107
  },
108
108
  "devDependencies": {
109
109
  "tsup": "^8.0.0",
110
- "@neutro/form-core": "0.0.1",
110
+ "@neutro/form-svelte": "0.0.1",
111
111
  "@neutro/form-react": "0.0.1",
112
112
  "@neutro/form-vue": "0.0.1",
113
- "@neutro/form-svelte": "0.0.1",
113
+ "@neutro/form-core": "0.0.1",
114
114
  "@neutro/form-angular": "0.0.1",
115
115
  "@neutro/form-solid": "0.0.1"
116
116
  },