foorm 0.0.2-alpha.1 → 0.0.2-alpha.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.
- package/dist/index.cjs +6 -3
- package/dist/index.d.ts +94 -3
- package/dist/index.mjs +6 -3
- package/package.json +1 -1
- package/dist/foorm.d.ts +0 -46
- package/dist/foorm.spec.d.ts +0 -1
- package/dist/types.d.ts +0 -42
- package/dist/utils.d.ts +0 -3
- package/dist/utils.spec.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -99,13 +99,16 @@ class Foorm {
|
|
|
99
99
|
};
|
|
100
100
|
if (ctx.entry) {
|
|
101
101
|
if (typeof evalEntry.disabled === 'function') {
|
|
102
|
-
ctx.entry.disabled = evalEntry.disabled =
|
|
102
|
+
ctx.entry.disabled = evalEntry.disabled =
|
|
103
|
+
evalEntry.disabled(ctx);
|
|
103
104
|
}
|
|
104
105
|
if (typeof evalEntry.optional === 'function') {
|
|
105
|
-
ctx.entry.optional = evalEntry.optional =
|
|
106
|
+
ctx.entry.optional = evalEntry.optional =
|
|
107
|
+
evalEntry.optional(ctx);
|
|
106
108
|
}
|
|
107
109
|
if (typeof evalEntry.hidden === 'function') {
|
|
108
|
-
ctx.entry.hidden = evalEntry.hidden =
|
|
110
|
+
ctx.entry.hidden = evalEntry.hidden =
|
|
111
|
+
evalEntry.hidden(ctx);
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type TFtring = {
|
|
2
|
+
__is_ftring__: true;
|
|
3
|
+
v: string;
|
|
4
|
+
__type__?: 'boolean' | 'string' | 'number';
|
|
5
|
+
};
|
|
6
|
+
type StringOrFtring = string | TFtring;
|
|
7
|
+
type ObjSOF = Record<string, StringOrFtring>;
|
|
8
|
+
type TFoormFnCtx<T = string> = {
|
|
9
|
+
v?: T;
|
|
10
|
+
data: Record<string, unknown>;
|
|
11
|
+
entry?: Pick<TFoormEntry<T, unknown, string, boolean>, TRelevantFields> & {
|
|
12
|
+
optional?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
hidden?: boolean;
|
|
15
|
+
};
|
|
16
|
+
action?: string;
|
|
17
|
+
};
|
|
18
|
+
type TFoormValidatorFn<T = string> = (ctx: TFoormFnCtx<T>) => string | boolean;
|
|
19
|
+
type TFoormFn<T = string, R = string | boolean> = (ctx: TFoormFnCtx<T>) => R;
|
|
20
|
+
type TRelevantFields = 'field' | 'type' | 'component' | 'name' | 'attrs' | 'length';
|
|
21
|
+
interface TFoormEntry<T = string, O = string, SFTR = TFtring, BFTR = TFtring, FNFTR = TFtring> {
|
|
22
|
+
field: string;
|
|
23
|
+
label?: string | SFTR;
|
|
24
|
+
description?: string | SFTR;
|
|
25
|
+
hint?: string | SFTR;
|
|
26
|
+
placeholder?: string | SFTR;
|
|
27
|
+
classes?: (string | SFTR) | Record<string, boolean | BFTR>;
|
|
28
|
+
styles?: (string | SFTR) | Record<string, string | SFTR>;
|
|
29
|
+
type?: string;
|
|
30
|
+
component?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
value?: T;
|
|
33
|
+
options?: O[];
|
|
34
|
+
attrs?: Record<string, unknown>;
|
|
35
|
+
optional?: boolean | BFTR;
|
|
36
|
+
disabled?: boolean | BFTR;
|
|
37
|
+
hidden?: boolean | BFTR;
|
|
38
|
+
length?: number;
|
|
39
|
+
validators?: (FNFTR | TFoormValidatorFn<T>)[];
|
|
40
|
+
}
|
|
41
|
+
type RequireProps$1<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
42
|
+
type TFoormEntryExecutable<T = unknown, O = string> = RequireProps$1<TFoormEntry<T, O, TFoormFn<T, string>, TFoormFn<T, boolean>, TFoormValidatorFn<T>>, 'name' | 'label' | 'type'>;
|
|
43
|
+
|
|
44
|
+
interface TFoormSubmit<S = TFtring, B = TFtring> {
|
|
45
|
+
text: string | S;
|
|
46
|
+
disabled?: boolean | B;
|
|
47
|
+
}
|
|
48
|
+
interface TFoormOptions {
|
|
49
|
+
title?: StringOrFtring;
|
|
50
|
+
entries: TFoormEntry[];
|
|
51
|
+
submit?: TFoormSubmit;
|
|
52
|
+
}
|
|
53
|
+
declare class Foorm {
|
|
54
|
+
protected entries: TFoormEntry[];
|
|
55
|
+
protected submit?: TFoormSubmit;
|
|
56
|
+
protected title?: StringOrFtring;
|
|
57
|
+
private fns;
|
|
58
|
+
constructor(opts?: TFoormOptions);
|
|
59
|
+
addEntry(entry: TFoormEntry): void;
|
|
60
|
+
setTitle(title: string): void;
|
|
61
|
+
setSubmit(submit: TFoormSubmit): void;
|
|
62
|
+
transportable(): Required<TFoormOptions>;
|
|
63
|
+
protected normalizeEntry<T, O>(e: TFoormEntry<T, O>): RequireProps<TFoormEntry<T, O>, 'label' | 'name' | 'type'>;
|
|
64
|
+
executable(): {
|
|
65
|
+
title: string | TFoormFn<undefined, string>;
|
|
66
|
+
submit: {
|
|
67
|
+
text: string | TFoormFn<undefined, string>;
|
|
68
|
+
disabled: boolean | TFoormFn<undefined, boolean>;
|
|
69
|
+
};
|
|
70
|
+
entries: TFoormEntryExecutable[];
|
|
71
|
+
};
|
|
72
|
+
prepareValidators(_validators: TFoormEntry['validators']): TFoormValidatorFn<string>[];
|
|
73
|
+
getFormValidator(): (inputs: Record<string, unknown>) => {
|
|
74
|
+
passed: boolean;
|
|
75
|
+
errors: Record<string, string>;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
type TFoormExecutableMeta = ReturnType<Foorm['executable']>;
|
|
79
|
+
type TFoormExecutableEntry = TFoormExecutableMeta['entries'][number];
|
|
80
|
+
declare function validate<T = string>(opts: TFoormFnCtx<T> & {
|
|
81
|
+
validators: TFoormValidatorFn<T>[];
|
|
82
|
+
}): {
|
|
83
|
+
passed: boolean;
|
|
84
|
+
error: string;
|
|
85
|
+
} | {
|
|
86
|
+
passed: boolean;
|
|
87
|
+
error?: undefined;
|
|
88
|
+
};
|
|
89
|
+
type RequireProps<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
90
|
+
|
|
91
|
+
declare function isFtring(input: unknown): input is TFtring;
|
|
92
|
+
declare function ftring(strings: TemplateStringsArray, __type__?: TFtring['__type__']): TFtring;
|
|
93
|
+
|
|
94
|
+
export { Foorm, type ObjSOF, type StringOrFtring, type TFoormEntry, type TFoormEntryExecutable, type TFoormExecutableEntry, type TFoormExecutableMeta, type TFoormFn, type TFoormFnCtx, type TFoormOptions, type TFoormSubmit, type TFoormValidatorFn, type TFtring, ftring, isFtring, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -97,13 +97,16 @@ class Foorm {
|
|
|
97
97
|
};
|
|
98
98
|
if (ctx.entry) {
|
|
99
99
|
if (typeof evalEntry.disabled === 'function') {
|
|
100
|
-
ctx.entry.disabled = evalEntry.disabled =
|
|
100
|
+
ctx.entry.disabled = evalEntry.disabled =
|
|
101
|
+
evalEntry.disabled(ctx);
|
|
101
102
|
}
|
|
102
103
|
if (typeof evalEntry.optional === 'function') {
|
|
103
|
-
ctx.entry.optional = evalEntry.optional =
|
|
104
|
+
ctx.entry.optional = evalEntry.optional =
|
|
105
|
+
evalEntry.optional(ctx);
|
|
104
106
|
}
|
|
105
107
|
if (typeof evalEntry.hidden === 'function') {
|
|
106
|
-
ctx.entry.hidden = evalEntry.hidden =
|
|
108
|
+
ctx.entry.hidden = evalEntry.hidden =
|
|
109
|
+
evalEntry.hidden(ctx);
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
package/dist/foorm.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { StringOrFtring, TFoormEntry, TFoormValidatorFn, TFoormFnCtx, TFoormFn, TFtring, TFoormEntryExecutable } from './types';
|
|
2
|
-
export interface TFoormSubmit<S = TFtring, B = TFtring> {
|
|
3
|
-
text: string | S;
|
|
4
|
-
disabled?: boolean | B;
|
|
5
|
-
}
|
|
6
|
-
export interface TFoormOptions {
|
|
7
|
-
title?: StringOrFtring;
|
|
8
|
-
entries: TFoormEntry[];
|
|
9
|
-
submit?: TFoormSubmit;
|
|
10
|
-
}
|
|
11
|
-
export declare class Foorm {
|
|
12
|
-
protected entries: TFoormEntry[];
|
|
13
|
-
protected submit?: TFoormSubmit;
|
|
14
|
-
protected title?: StringOrFtring;
|
|
15
|
-
private fns;
|
|
16
|
-
constructor(opts?: TFoormOptions);
|
|
17
|
-
addEntry(entry: TFoormEntry): void;
|
|
18
|
-
setTitle(title: string): void;
|
|
19
|
-
setSubmit(submit: TFoormSubmit): void;
|
|
20
|
-
transportable(): Required<TFoormOptions>;
|
|
21
|
-
protected normalizeEntry<T, O>(e: TFoormEntry<T, O>): TFoormEntry<T, O>;
|
|
22
|
-
executable(): {
|
|
23
|
-
title: string | TFoormFn<undefined, string>;
|
|
24
|
-
submit: {
|
|
25
|
-
text: string | TFoormFn<undefined, string>;
|
|
26
|
-
disabled: boolean | TFoormFn<undefined, boolean>;
|
|
27
|
-
};
|
|
28
|
-
entries: TFoormEntryExecutable[];
|
|
29
|
-
};
|
|
30
|
-
prepareValidators(_validators: TFoormEntry['validators']): TFoormValidatorFn<string>[];
|
|
31
|
-
getFormValidator(): (inputs: Record<string, unknown>) => {
|
|
32
|
-
passed: boolean;
|
|
33
|
-
errors: Record<string, string>;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export type TFoormExecutableMeta = ReturnType<Foorm['executable']>;
|
|
37
|
-
export type TFoormExecutableEntry = TFoormExecutableMeta['entries'][number];
|
|
38
|
-
export declare function validate<T = string>(opts: TFoormFnCtx<T> & {
|
|
39
|
-
validators: TFoormValidatorFn<T>[];
|
|
40
|
-
}): {
|
|
41
|
-
passed: boolean;
|
|
42
|
-
error: string;
|
|
43
|
-
} | {
|
|
44
|
-
passed: boolean;
|
|
45
|
-
error?: undefined;
|
|
46
|
-
};
|
package/dist/foorm.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export type TFtring = {
|
|
2
|
-
__is_ftring__: true;
|
|
3
|
-
v: string;
|
|
4
|
-
__type__?: 'boolean' | 'string' | 'number';
|
|
5
|
-
};
|
|
6
|
-
export type StringOrFtring = string | TFtring;
|
|
7
|
-
export type ObjSOF = Record<string, StringOrFtring>;
|
|
8
|
-
export type TFoormFnCtx<T = string> = {
|
|
9
|
-
v?: T;
|
|
10
|
-
data: Record<string, unknown>;
|
|
11
|
-
entry?: Pick<TFoormEntry<T, unknown, string, boolean>, TRelevantFields> & {
|
|
12
|
-
optional?: boolean;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
hidden?: boolean;
|
|
15
|
-
};
|
|
16
|
-
action?: string;
|
|
17
|
-
};
|
|
18
|
-
export type TFoormValidatorFn<T = string> = (ctx: TFoormFnCtx<T>) => string | boolean;
|
|
19
|
-
export type TFoormFn<T = string, R = string | boolean> = (ctx: TFoormFnCtx<T>) => R;
|
|
20
|
-
type TRelevantFields = 'field' | 'type' | 'component' | 'name' | 'attrs' | 'length';
|
|
21
|
-
export interface TFoormEntry<T = string, O = string, SFTR = TFtring, BFTR = TFtring, FNFTR = TFtring> {
|
|
22
|
-
field: string;
|
|
23
|
-
label?: string | SFTR;
|
|
24
|
-
description?: string | SFTR;
|
|
25
|
-
hint?: string | SFTR;
|
|
26
|
-
placeholder?: string | SFTR;
|
|
27
|
-
classes?: (string | SFTR) | Record<string, boolean | BFTR>;
|
|
28
|
-
styles?: (string | SFTR) | Record<string, string | SFTR>;
|
|
29
|
-
type?: string;
|
|
30
|
-
component?: string;
|
|
31
|
-
name?: string;
|
|
32
|
-
value?: T;
|
|
33
|
-
options?: O[];
|
|
34
|
-
attrs?: Record<string, unknown>;
|
|
35
|
-
optional?: boolean | BFTR;
|
|
36
|
-
disabled?: boolean | BFTR;
|
|
37
|
-
hidden?: boolean | BFTR;
|
|
38
|
-
length?: number;
|
|
39
|
-
validators?: (FNFTR | TFoormValidatorFn<T>)[];
|
|
40
|
-
}
|
|
41
|
-
export type TFoormEntryExecutable<T = unknown, O = string> = TFoormEntry<T, O, TFoormFn<T, string>, TFoormFn<T, boolean>, TFoormValidatorFn<T>>;
|
|
42
|
-
export {};
|
package/dist/utils.d.ts
DELETED
package/dist/utils.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|