@sealcode/sealgen 0.3.2 → 0.4.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/@types/forms/controls/checkboxed-list-input.d.ts +5 -6
- package/@types/forms/controls/dropdown.d.ts +5 -6
- package/@types/forms/controls/editable-collection-subset.d.ts +6 -6
- package/@types/forms/controls/form-control.d.ts +3 -4
- package/@types/forms/controls/form-field-control.d.ts +9 -8
- package/@types/forms/controls/frame.d.ts +2 -2
- package/@types/forms/controls/simple-input.d.ts +5 -5
- package/@types/forms/field.d.ts +47 -16
- package/@types/forms/fields/checkboxed-list.d.ts +16 -0
- package/@types/forms/fields/collection-field.d.ts +11 -0
- package/@types/forms/fields/field.d.ts +38 -0
- package/@types/forms/fields/number.d.ts +13 -0
- package/@types/forms/fields/pick-from-list.d.ts +16 -0
- package/@types/forms/fields/simple-form-field.d.ts +7 -0
- package/@types/forms/form-fields-list.d.ts +1 -1
- package/@types/forms/form.d.ts +24 -29
- package/@types/forms/simple-form-field.d.ts +6 -0
- package/@types/forms/validator.d.ts +0 -3
- package/@types/index.d.ts +8 -5
- package/@types/make-hidden-inputs.d.ts +4 -0
- package/@types/page/list.d.ts +23 -42
- package/@types/page/mountable.d.ts +36 -0
- package/@types/page/page.d.ts +10 -17
- package/@types/page/props-parser.d.ts +5 -10
- package/@types/utils/translate.d.ts +3 -0
- package/lib/build.js +2 -1
- package/lib/build.js.map +1 -1
- package/lib/forms/controls/checkboxed-list-input.js +10 -17
- package/lib/forms/controls/checkboxed-list-input.js.map +1 -1
- package/lib/forms/controls/dropdown.js +16 -20
- package/lib/forms/controls/dropdown.js.map +1 -1
- package/lib/forms/controls/editable-collection-subset.js +33 -35
- package/lib/forms/controls/editable-collection-subset.js.map +1 -1
- package/lib/forms/controls/form-control.js.map +1 -1
- package/lib/forms/controls/form-field-control.js +2 -11
- package/lib/forms/controls/form-field-control.js.map +1 -1
- package/lib/forms/controls/simple-input.js +17 -23
- package/lib/forms/controls/simple-input.js.map +1 -1
- package/lib/forms/field.js +96 -20
- package/lib/forms/field.js.map +1 -1
- package/lib/forms/fields/checkboxed-list.js +43 -0
- package/lib/forms/fields/checkboxed-list.js.map +1 -0
- package/lib/forms/fields/collection-field.js +28 -0
- package/lib/forms/fields/collection-field.js.map +1 -0
- package/lib/forms/fields/field.js +70 -0
- package/lib/forms/fields/field.js.map +1 -0
- package/lib/forms/fields/number.js +45 -0
- package/lib/forms/fields/number.js.map +1 -0
- package/lib/forms/fields/pick-from-list.js +34 -0
- package/lib/forms/fields/pick-from-list.js.map +1 -0
- package/lib/forms/fields/simple-form-field.js +18 -0
- package/lib/forms/fields/simple-form-field.js.map +1 -0
- package/lib/forms/form.js +50 -96
- package/lib/forms/form.js.map +1 -1
- package/lib/forms/simple-form-field.js +18 -0
- package/lib/forms/simple-form-field.js.map +1 -0
- package/lib/forms/validator.js +0 -10
- package/lib/forms/validator.js.map +1 -1
- package/lib/generate-routes.js +19 -2
- package/lib/generate-routes.js.map +1 -1
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/make-hidden-inputs.js +17 -0
- package/lib/make-hidden-inputs.js.map +1 -0
- package/lib/page/list.js +65 -79
- package/lib/page/list.js.map +1 -1
- package/lib/page/mountable.js +56 -0
- package/lib/page/mountable.js.map +1 -0
- package/lib/page/page.js +11 -1
- package/lib/page/page.js.map +1 -1
- package/lib/page/props-parser.js +4 -47
- package/lib/page/props-parser.js.map +1 -1
- package/lib/templates/form.js +32 -17
- package/lib/templates/form.js.map +1 -1
- package/lib/templates/list.js +30 -20
- package/lib/templates/list.js.map +1 -1
- package/lib/utils/translate.js +10 -0
- package/lib/utils/translate.js.map +1 -0
- package/package.json +4 -3
- package/src/build.ts +2 -1
- package/src/forms/controls/checkboxed-list-input.ts +12 -23
- package/src/forms/controls/dropdown.ts +27 -32
- package/src/forms/controls/editable-collection-subset.ts +57 -54
- package/src/forms/controls/form-control.ts +5 -6
- package/src/forms/controls/form-field-control.ts +13 -29
- package/src/forms/controls/frame.ts +2 -2
- package/src/forms/controls/simple-input.ts +27 -24
- package/src/forms/fields/checkboxed-list.ts +61 -0
- package/src/forms/fields/collection-field.ts +54 -0
- package/src/forms/fields/field.ts +116 -0
- package/src/forms/fields/number.ts +53 -0
- package/src/forms/fields/pick-from-list.ts +49 -0
- package/src/forms/fields/simple-form-field.ts +20 -0
- package/src/forms/form.ts +98 -163
- package/src/generate-routes.ts +19 -2
- package/src/index.ts +8 -5
- package/src/make-hidden-inputs.ts +22 -0
- package/src/page/list.ts +115 -126
- package/src/page/mountable.ts +105 -0
- package/src/page/page.ts +21 -12
- package/src/page/props-parser.ts +9 -67
- package/src/templates/form.ts +32 -17
- package/src/templates/list.ts +30 -20
- package/src/utils/translate.ts +13 -0
- package/src/forms/controls.ts +0 -0
- package/src/forms/field.ts +0 -119
- package/src/forms/form-fields-list.ts +0 -7
- package/src/forms/validator.ts +0 -10
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BaseContext } from "koa";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ChekboxedListField } from "../fields/field";
|
|
4
|
+
import { FormDataValue } from "../form";
|
|
5
5
|
import { FormFieldControl } from "./controls";
|
|
6
6
|
export declare class CheckboxedListInput extends FormFieldControl {
|
|
7
|
-
|
|
7
|
+
field: ChekboxedListField;
|
|
8
8
|
options: {
|
|
9
9
|
label: string;
|
|
10
10
|
};
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(field: ChekboxedListField, options?: {
|
|
12
12
|
label: string;
|
|
13
13
|
});
|
|
14
|
-
|
|
15
|
-
_render(ctx: BaseContext, fields: FormField[], data: FormData): Promise<import("stream").Readable>;
|
|
14
|
+
render(ctx: BaseContext, data: Record<string, FormDataValue>): Promise<import("stream").Readable>;
|
|
16
15
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BaseContext } from "koa";
|
|
3
|
-
import { FormField } from "../field";
|
|
4
|
-
import {
|
|
3
|
+
import { FormField, PickFromListField } from "../fields/field";
|
|
4
|
+
import { FormDataValue } from "../form";
|
|
5
5
|
import { FormFieldControl } from "./controls";
|
|
6
6
|
export declare class Dropdown extends FormFieldControl {
|
|
7
|
-
|
|
7
|
+
field: PickFromListField;
|
|
8
8
|
options: {
|
|
9
9
|
label: string;
|
|
10
10
|
autosubmit?: boolean;
|
|
11
11
|
autocomplete?: boolean;
|
|
12
12
|
};
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(field: PickFromListField, options?: {
|
|
14
14
|
label: string;
|
|
15
15
|
autosubmit?: boolean;
|
|
16
16
|
autocomplete?: boolean;
|
|
17
17
|
});
|
|
18
|
-
|
|
19
|
-
_render(ctx: BaseContext, fields: FormField[], data: FormData): import("stream").Readable;
|
|
18
|
+
render<Fields extends Record<string, FormField>>(ctx: BaseContext, data: Record<string, FormDataValue>): Promise<import("stream").Readable>;
|
|
20
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseContext } from "koa";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { FlatTemplatable } from "tempstream";
|
|
3
|
+
import { PickFromListField } from "../fields/field";
|
|
4
|
+
import { FormDataValue } from "../form";
|
|
5
5
|
import { FormFieldControl } from "./controls";
|
|
6
6
|
/**
|
|
7
7
|
* This control has own forms in it so if you want to use it you
|
|
@@ -11,11 +11,11 @@ import { FormFieldControl } from "./controls";
|
|
|
11
11
|
* this control for reference.
|
|
12
12
|
*/
|
|
13
13
|
export declare class EditableCollectionSubset extends FormFieldControl {
|
|
14
|
-
|
|
14
|
+
field: PickFromListField;
|
|
15
15
|
actionname: string;
|
|
16
16
|
listLabel?: string | undefined;
|
|
17
17
|
selectLabel?: string | undefined;
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
18
|
+
constructor(field: PickFromListField, actionname: string, listLabel?: string | undefined, selectLabel?: string | undefined);
|
|
19
|
+
render(ctx: BaseContext, data: Record<string, FormDataValue>): Promise<FlatTemplatable>;
|
|
20
20
|
role: "input";
|
|
21
21
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BaseContext } from "koa";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { FormData } from "../form";
|
|
2
|
+
import { FlatTemplatable } from "tempstream";
|
|
3
|
+
import { FormDataValue, FormMessage } from "../form";
|
|
5
4
|
export declare abstract class FormControl {
|
|
6
|
-
abstract render(ctx: BaseContext,
|
|
5
|
+
abstract render(ctx: BaseContext, data: Record<string, FormDataValue>, messages: FormMessage[]): FlatTemplatable | Promise<FlatTemplatable>;
|
|
7
6
|
abstract role: "input" | "decoration" | "messages" | "submit";
|
|
8
7
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { BaseContext } from "koa";
|
|
2
|
-
import {
|
|
3
|
-
import { FormField } from "../field";
|
|
4
|
-
import {
|
|
2
|
+
import { FlatTemplatable } from "tempstream";
|
|
3
|
+
import { FormField } from "../fields/field";
|
|
4
|
+
import { FieldValueType, FormDataValue } from "../form";
|
|
5
5
|
import { FormControl } from "./form-control";
|
|
6
|
+
export declare type FormFieldsToTypes<FormFields extends readonly FormField[]> = {
|
|
7
|
+
[Index in keyof FormFields]: FormFields[Index] extends FormField ? FieldValueType<FormFields[Index]> : never;
|
|
8
|
+
};
|
|
6
9
|
export declare abstract class FormFieldControl extends FormControl {
|
|
7
|
-
|
|
10
|
+
fields: FormField[];
|
|
8
11
|
role: "input";
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
abstract _render(ctx: BaseContext, fields: FormField[], data: FormData): Templatable | Promise<Templatable>;
|
|
12
|
-
render(ctx: BaseContext, fields: FormField[], data: FormData): Templatable | Promise<Templatable>;
|
|
12
|
+
constructor(fields: FormField[]);
|
|
13
|
+
abstract render(ctx: BaseContext, data: Record<string, FormDataValue>): FlatTemplatable | Promise<FlatTemplatable>;
|
|
13
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FlatTemplatable } from "tempstream";
|
|
2
2
|
import { FormControl } from "./controls";
|
|
3
3
|
/**
|
|
4
4
|
* This class will render `turbo-frame` tag so that u can
|
|
@@ -12,6 +12,6 @@ import { FormControl } from "./controls";
|
|
|
12
12
|
export declare class Frame extends FormControl {
|
|
13
13
|
src: string;
|
|
14
14
|
constructor(src: string);
|
|
15
|
-
render():
|
|
15
|
+
render(): FlatTemplatable | Promise<FlatTemplatable>;
|
|
16
16
|
role: "decoration";
|
|
17
17
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseContext } from "koa";
|
|
2
|
-
import { FormField } from "../field";
|
|
3
|
-
import {
|
|
2
|
+
import { FormField } from "../fields/field";
|
|
3
|
+
import { FormDataValue } from "../form";
|
|
4
4
|
import { FormFieldControl } from "./controls";
|
|
5
5
|
export declare class SimpleInput extends FormFieldControl {
|
|
6
|
-
|
|
6
|
+
field: FormField;
|
|
7
7
|
options: {
|
|
8
8
|
id?: string;
|
|
9
9
|
label?: string;
|
|
@@ -14,7 +14,7 @@ export declare class SimpleInput extends FormFieldControl {
|
|
|
14
14
|
readonly?: boolean;
|
|
15
15
|
step?: number;
|
|
16
16
|
};
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(field: FormField, options?: {
|
|
18
18
|
id?: string;
|
|
19
19
|
label?: string;
|
|
20
20
|
autocomplete?: boolean;
|
|
@@ -24,5 +24,5 @@ export declare class SimpleInput extends FormFieldControl {
|
|
|
24
24
|
readonly?: boolean;
|
|
25
25
|
step?: number;
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
render<Fields extends Record<string, FormField>>(ctx: BaseContext, data: Record<string, FormDataValue>): Promise<string>;
|
|
28
28
|
}
|
package/@types/forms/field.d.ts
CHANGED
|
@@ -1,42 +1,73 @@
|
|
|
1
1
|
import { BaseContext } from "koa";
|
|
2
|
+
import { FormDataValue } from "..";
|
|
2
3
|
export declare type FormFieldValidationResponse = {
|
|
3
4
|
valid: boolean;
|
|
4
5
|
message: string;
|
|
5
6
|
};
|
|
6
|
-
export declare type FormFieldValidationFn = (ctx: BaseContext, value:
|
|
7
|
-
export declare
|
|
8
|
-
|
|
7
|
+
export declare type FormFieldValidationFn<ValueType> = (ctx: BaseContext, value: ValueType, field: FormField<ValueType>) => Promise<FormFieldValidationResponse>;
|
|
8
|
+
export declare type FieldParsedValue<T> = T extends FormField<infer R> ? R : never;
|
|
9
|
+
export declare type FieldParseResult<T> = {
|
|
10
|
+
parsable: false;
|
|
11
|
+
error: string;
|
|
12
|
+
parsed_value: null;
|
|
13
|
+
} | {
|
|
14
|
+
parsable: true;
|
|
15
|
+
error: null;
|
|
16
|
+
parsed_value: T;
|
|
17
|
+
};
|
|
18
|
+
export declare abstract class FormField<ParsedValue extends unknown = unknown> {
|
|
9
19
|
required: boolean;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
|
|
20
|
+
name: string;
|
|
21
|
+
constructor(required?: boolean);
|
|
22
|
+
init(fieldname: string): void;
|
|
23
|
+
_validate(ctx: BaseContext, value: ParsedValue): Promise<FormFieldValidationResponse>;
|
|
24
|
+
abstract getEmptyValue(): ParsedValue;
|
|
25
|
+
isValueValid(ctx: BaseContext, value: ParsedValue): Promise<FormFieldValidationResponse>;
|
|
26
|
+
abstract parse(raw_value: FormDataValue): Promise<FieldParseResult<ParsedValue>>;
|
|
27
|
+
getValue(ctx: BaseContext, all_form_values: Record<string, FormDataValue>): Promise<{
|
|
28
|
+
valid: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
parsed: ParsedValue;
|
|
31
|
+
raw: FormDataValue;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export declare class SimpleFormField extends FormField<string> {
|
|
35
|
+
parse(raw_value: FormDataValue): Promise<FieldParseResult<string>>;
|
|
13
36
|
getEmptyValue(): string;
|
|
14
37
|
}
|
|
15
|
-
export declare class PickFromListField
|
|
16
|
-
name: Fieldnames;
|
|
38
|
+
export declare class PickFromListField extends SimpleFormField {
|
|
17
39
|
required: boolean;
|
|
18
40
|
generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
19
41
|
[i: string]: string;
|
|
20
42
|
}>;
|
|
21
43
|
customValidation: (ctx: BaseContext, value: unknown, instance: PickFromListField) => Promise<FormFieldValidationResponse>;
|
|
22
|
-
constructor(
|
|
44
|
+
constructor(required: boolean, generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
23
45
|
[i: string]: string;
|
|
24
46
|
}>, customValidation?: (ctx: BaseContext, value: unknown, instance: PickFromListField) => Promise<FormFieldValidationResponse>);
|
|
47
|
+
isValueValid(ctx: BaseContext, value: string): Promise<FormFieldValidationResponse>;
|
|
25
48
|
valueInList(ctx: BaseContext, value: unknown): Promise<FormFieldValidationResponse>;
|
|
49
|
+
getEmptyValue(): string;
|
|
26
50
|
}
|
|
27
|
-
export declare class ChekboxedListField
|
|
28
|
-
name: Fieldnames;
|
|
51
|
+
export declare class ChekboxedListField extends FormField<Record<string, "on">> {
|
|
29
52
|
required: boolean;
|
|
30
53
|
generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
31
54
|
[i: string]: string;
|
|
32
55
|
}>;
|
|
33
56
|
isVisible: (ctx: BaseContext) => Promise<boolean>;
|
|
34
|
-
constructor(
|
|
57
|
+
constructor(required: boolean, generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
35
58
|
[i: string]: string;
|
|
36
59
|
}>, isVisible?: (ctx: BaseContext) => Promise<boolean>);
|
|
37
|
-
|
|
60
|
+
isValueValid(_: BaseContext, value: unknown): Promise<FormFieldValidationResponse>;
|
|
61
|
+
parse(raw_value: FormDataValue): Promise<FieldParseResult<Record<string, "on">>>;
|
|
62
|
+
getEmptyValue(): Record<string, "on">;
|
|
38
63
|
}
|
|
39
|
-
export declare class NumberField<
|
|
40
|
-
|
|
41
|
-
|
|
64
|
+
export declare class NumberField<DefaultValue extends number | null = null> extends FormField<number | DefaultValue> {
|
|
65
|
+
default_value: DefaultValue;
|
|
66
|
+
constructor(required: boolean | undefined, default_value: DefaultValue);
|
|
67
|
+
isValueValid(_: BaseContext, value: unknown): Promise<{
|
|
68
|
+
valid: boolean;
|
|
69
|
+
message: string;
|
|
70
|
+
}>;
|
|
71
|
+
parse(value: FormDataValue): Promise<FieldParseResult<number>>;
|
|
72
|
+
getEmptyValue(): DefaultValue;
|
|
42
73
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseContext } from "koa";
|
|
2
|
+
import { FormDataValue } from "../form";
|
|
3
|
+
import { FieldParseResult, FormField, FormFieldValidationResponse } from "./field";
|
|
4
|
+
export declare class ChekboxedListField extends FormField<Record<string, "on">> {
|
|
5
|
+
required: boolean;
|
|
6
|
+
generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
7
|
+
[i: string]: string;
|
|
8
|
+
}>;
|
|
9
|
+
isVisible: (ctx: BaseContext) => Promise<boolean>;
|
|
10
|
+
constructor(required: boolean, generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
11
|
+
[i: string]: string;
|
|
12
|
+
}>, isVisible?: (ctx: BaseContext) => Promise<boolean>);
|
|
13
|
+
isValueValid(_: BaseContext, value: unknown): Promise<FormFieldValidationResponse>;
|
|
14
|
+
parse(_: BaseContext, raw_value: FormDataValue): Promise<FieldParseResult<Record<string, "on">>>;
|
|
15
|
+
getEmptyValue(): Record<string, "on">;
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseContext } from "koa";
|
|
2
|
+
import { Depromisify, Field, FieldOutput } from "sealious";
|
|
3
|
+
import { FormDataValue } from "../form";
|
|
4
|
+
import { FieldParseResult, FormField, FormFieldValidationResponse } from "./field";
|
|
5
|
+
export declare class CollectionField<F extends Field> extends FormField<FieldOutput<F>> {
|
|
6
|
+
sealiousField: F;
|
|
7
|
+
constructor(required: boolean, sealiousField: F);
|
|
8
|
+
parse(ctx: BaseContext, raw_value: FormDataValue): Promise<FieldParseResult<FieldOutput<F>>>;
|
|
9
|
+
isValueValid(ctx: BaseContext, value: FieldOutput<F>): Promise<FormFieldValidationResponse>;
|
|
10
|
+
getEmptyValue(): Depromisify<ReturnType<F["decode"]>>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseContext } from "koa";
|
|
2
|
+
import { FormDataValue } from "../form";
|
|
3
|
+
export declare type FormFieldValidationResponse = {
|
|
4
|
+
valid: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type FormFieldValidationFn<ValueType> = (ctx: BaseContext, value: ValueType, field: FormField<ValueType>) => Promise<FormFieldValidationResponse>;
|
|
8
|
+
export declare type FieldParsedValue<T> = T extends FormField<infer R> ? R : never;
|
|
9
|
+
export declare type FieldParseResult<T> = {
|
|
10
|
+
parsable: false;
|
|
11
|
+
error: string;
|
|
12
|
+
parsed_value: null;
|
|
13
|
+
} | {
|
|
14
|
+
parsable: true;
|
|
15
|
+
error: null;
|
|
16
|
+
parsed_value: T;
|
|
17
|
+
};
|
|
18
|
+
export declare abstract class FormField<ParsedValue extends unknown = unknown> {
|
|
19
|
+
required: boolean;
|
|
20
|
+
name: string;
|
|
21
|
+
constructor(required?: boolean);
|
|
22
|
+
init(fieldname: string): void;
|
|
23
|
+
_validate(ctx: BaseContext, value: ParsedValue): Promise<FormFieldValidationResponse>;
|
|
24
|
+
abstract getEmptyValue(): ParsedValue;
|
|
25
|
+
isValueValid(ctx: BaseContext, value: ParsedValue): Promise<FormFieldValidationResponse>;
|
|
26
|
+
abstract parse(ctx: BaseContext, raw_value: FormDataValue): Promise<FieldParseResult<ParsedValue>>;
|
|
27
|
+
getValue(ctx: BaseContext, all_form_values: Record<string, FormDataValue>): Promise<{
|
|
28
|
+
valid: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
parsed: ParsedValue;
|
|
31
|
+
raw: FormDataValue;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export * from "./simple-form-field";
|
|
35
|
+
export * from "./checkboxed-list";
|
|
36
|
+
export * from "./collection-field";
|
|
37
|
+
export * from "./number";
|
|
38
|
+
export * from "./pick-from-list";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseContext } from "koa";
|
|
2
|
+
import { FormDataValue } from "../form";
|
|
3
|
+
import { FieldParseResult, FormField } from "./field";
|
|
4
|
+
export declare class NumberField<DefaultValue extends number | null = null> extends FormField<number | DefaultValue> {
|
|
5
|
+
default_value: DefaultValue;
|
|
6
|
+
constructor(required: boolean | undefined, default_value: DefaultValue);
|
|
7
|
+
isValueValid(_: BaseContext, value: unknown): Promise<{
|
|
8
|
+
valid: boolean;
|
|
9
|
+
message: string;
|
|
10
|
+
}>;
|
|
11
|
+
parse(_: BaseContext, value: FormDataValue): Promise<FieldParseResult<number>>;
|
|
12
|
+
getEmptyValue(): DefaultValue;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseContext } from "koa";
|
|
2
|
+
import { FormFieldValidationResponse } from "./field";
|
|
3
|
+
import { SimpleFormField } from "./simple-form-field";
|
|
4
|
+
export declare class PickFromListField extends SimpleFormField {
|
|
5
|
+
required: boolean;
|
|
6
|
+
generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
7
|
+
[i: string]: string;
|
|
8
|
+
}>;
|
|
9
|
+
customValidation: (ctx: BaseContext, value: unknown, instance: PickFromListField) => Promise<FormFieldValidationResponse>;
|
|
10
|
+
constructor(required: boolean, generateOptions: (ctx: BaseContext) => Promise<Record<string, string> | {
|
|
11
|
+
[i: string]: string;
|
|
12
|
+
}>, customValidation?: (ctx: BaseContext, value: unknown, instance: PickFromListField) => Promise<FormFieldValidationResponse>);
|
|
13
|
+
isValueValid(ctx: BaseContext, value: string): Promise<FormFieldValidationResponse>;
|
|
14
|
+
valueInList(ctx: BaseContext, value: unknown): Promise<FormFieldValidationResponse>;
|
|
15
|
+
getEmptyValue(): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FieldParseResult, FormField } from "./field";
|
|
2
|
+
import { FormDataValue } from "../form";
|
|
3
|
+
import { BaseContext } from "koa";
|
|
4
|
+
export declare class SimpleFormField extends FormField<string | null> {
|
|
5
|
+
parse(_: BaseContext, raw_value: FormDataValue): Promise<FieldParseResult<string>>;
|
|
6
|
+
getEmptyValue(): string;
|
|
7
|
+
}
|
package/@types/forms/form.d.ts
CHANGED
|
@@ -1,42 +1,37 @@
|
|
|
1
1
|
/// <reference types="koa__router" />
|
|
2
2
|
import { BaseContext } from "koa";
|
|
3
3
|
import Router from "@koa/router";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Mountable, PageErrorMessage } from "../page/
|
|
7
|
-
|
|
4
|
+
import { FlatTemplatable } from "tempstream";
|
|
5
|
+
import { FormField } from "./fields/field";
|
|
6
|
+
import { Fields, Mountable, PageErrorMessage } from "../page/mountable";
|
|
7
|
+
export declare type FormDataPrimitive = string | string[] | undefined;
|
|
8
|
+
export declare type FormDataValue = FormDataPrimitive | Record<string, FormDataPrimitive>;
|
|
9
|
+
export declare type FieldValueType<F extends FormField> = F extends FormField<infer R> ? R : never;
|
|
10
|
+
export declare type FormFieldsToValues<F extends Record<string, FormField<keyof F>>> = {
|
|
11
|
+
[Property in keyof F]: FieldValueType<F[Property]>;
|
|
12
|
+
};
|
|
13
|
+
export declare type FormMessage = {
|
|
14
|
+
type: "info" | "success" | "error";
|
|
15
|
+
text: string;
|
|
16
|
+
};
|
|
8
17
|
export declare type FormData<Fieldnames extends string = string> = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
errors: Partial<Record<Fieldnames, string>>;
|
|
12
|
-
messages: {
|
|
13
|
-
type: "info" | "success" | "error";
|
|
14
|
-
text: string;
|
|
15
|
-
}[];
|
|
18
|
+
raw_values: Record<Fieldnames, FormDataValue>;
|
|
19
|
+
messages: FormMessage[];
|
|
16
20
|
};
|
|
17
|
-
export declare abstract class Form<
|
|
18
|
-
abstract fields: FormField<Fieldnames>[];
|
|
19
|
-
abstract controls: FormControl[];
|
|
21
|
+
export declare abstract class Form<F extends Fields> extends Mountable<F> {
|
|
20
22
|
defaultSuccessMessage: string;
|
|
21
23
|
submitButtonText: string;
|
|
22
24
|
canAccess(_: BaseContext): Promise<{
|
|
23
25
|
canAccess: boolean;
|
|
24
26
|
message: string;
|
|
25
27
|
}>;
|
|
26
|
-
renderError(_: BaseContext, error: PageErrorMessage): Promise<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
renderMessages(_: BaseContext, data: FormData): Templatable;
|
|
34
|
-
renderControls(ctx: BaseContext, data: FormData): Templatable;
|
|
35
|
-
makeFormTag(path: string): string;
|
|
36
|
-
private generateData;
|
|
37
|
-
onValuesInvalid(ctx: BaseContext, errors: Record<Fieldnames, string>, form_path: string): Promise<void>;
|
|
38
|
-
onError(ctx: BaseContext, error: unknown, form_path: string): Promise<void>;
|
|
39
|
-
abstract onSubmit(ctx: BaseContext, values: Record<Fieldnames, string | string[] | number>): void | Promise<void>;
|
|
40
|
-
onSuccess(ctx: BaseContext, form_path: string): Promise<void>;
|
|
28
|
+
renderError(_: BaseContext, error: PageErrorMessage): Promise<FlatTemplatable>;
|
|
29
|
+
render(ctx: BaseContext, data: FormData): Promise<FlatTemplatable>;
|
|
30
|
+
makeFormTag(): FlatTemplatable;
|
|
31
|
+
onValuesInvalid(ctx: BaseContext, form_messages: FormMessage[]): Promise<void>;
|
|
32
|
+
onError(ctx: BaseContext, data: FormData, error: unknown): Promise<void>;
|
|
33
|
+
abstract onSubmit(ctx: BaseContext, data: FormData): void | Promise<void>;
|
|
34
|
+
onSuccess(ctx: BaseContext, data: FormData): Promise<void>;
|
|
41
35
|
mount(router: Router, path: string): void;
|
|
36
|
+
extractRawValues(ctx: BaseContext): Record<string, FormDataValue>;
|
|
42
37
|
}
|
package/@types/index.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import Sealious from "sealious";
|
|
1
|
+
import Sealious, { App } from "sealious";
|
|
2
|
+
import { FormDataValue } from "./forms/form";
|
|
2
3
|
declare module "koa" {
|
|
3
4
|
interface BaseContext {
|
|
4
5
|
$context: Sealious.Context;
|
|
5
|
-
$
|
|
6
|
+
$app: App;
|
|
7
|
+
$body: Record<string, FormDataValue>;
|
|
6
8
|
}
|
|
7
9
|
}
|
|
8
|
-
export * from "./forms/form";
|
|
9
10
|
export * from "./forms/controls/controls";
|
|
10
|
-
export * from "./forms/field";
|
|
11
|
+
export * from "./forms/fields/field";
|
|
12
|
+
export * from "./page/mountable";
|
|
11
13
|
export * from "./page/page";
|
|
14
|
+
export * from "./forms/form";
|
|
12
15
|
export * from "./page/props-parser";
|
|
13
16
|
export * from "./utils/utils";
|
|
14
|
-
export * from "./forms/validator";
|
|
15
17
|
export * from "./page/list";
|
|
18
|
+
export * from "./utils/translate";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BaseContext } from "koa";
|
|
2
|
+
import { FlatTemplatable } from "tempstream";
|
|
3
|
+
import { FormDataValue, FormField } from ".";
|
|
4
|
+
export declare function makeHiddenInputs(ctx: BaseContext, fields: Record<string, FormField>, values: Record<string, FormDataValue>, fields_to_skip: string[]): FlatTemplatable;
|
package/@types/page/list.d.ts
CHANGED
|
@@ -1,57 +1,38 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { BaseContext } from "koa";
|
|
3
|
-
import { Collection, CollectionItem } from "sealious";
|
|
4
|
-
import { Templatable } from "tempstream";
|
|
2
|
+
import { Collection, CollectionItem, ItemList } from "sealious";
|
|
3
|
+
import { Templatable, FlatTemplatable } from "tempstream";
|
|
5
4
|
import { Page } from "./page";
|
|
6
5
|
import { ShapeToType } from "@sealcode/ts-predicates";
|
|
7
|
-
import { PagePropsParser } from "./props-parser";
|
|
8
6
|
import { FormFieldControl } from "../forms/controls/controls";
|
|
9
|
-
import { FormField } from "../forms/field";
|
|
7
|
+
import { FormField, NumberField } from "../forms/fields/field";
|
|
8
|
+
import { FormDataValue } from "..";
|
|
10
9
|
export declare const BasePagePropsShape: {};
|
|
11
10
|
export declare type BasePageProps = ShapeToType<typeof BasePagePropsShape>;
|
|
12
|
-
export declare const
|
|
13
|
-
readonly page:
|
|
14
|
-
readonly itemsPerPage:
|
|
11
|
+
export declare const BaseListPageFields: {
|
|
12
|
+
readonly page: NumberField<1>;
|
|
13
|
+
readonly itemsPerPage: NumberField<12>;
|
|
15
14
|
};
|
|
16
|
-
export declare
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export declare type PropsErrors<PropsType> = Partial<Record<keyof PropsType, string>>;
|
|
22
|
-
export declare abstract class ListPage<ItemType, PropsType extends BaseListPageProps = BaseListPageProps> extends Page {
|
|
23
|
-
abstract getItems(ctx: BaseContext, props: PropsType): Promise<{
|
|
24
|
-
items: ItemType[];
|
|
25
|
-
}>;
|
|
26
|
-
abstract getTotalPages(ctx: BaseContext, props: PropsType): Promise<number>;
|
|
27
|
-
abstract renderItem(ctx: BaseContext, item: ItemType): Promise<Templatable>;
|
|
28
|
-
abstract propsParser: PagePropsParser<PropsType>;
|
|
29
|
-
filterFields: FormField<keyof PropsType>[];
|
|
15
|
+
export declare abstract class ListPage<ItemType, F extends typeof BaseListPageFields> extends Page<F> {
|
|
16
|
+
abstract getItems(ctx: BaseContext, page: number, itemsPerPage: number, values: Record<string, FormDataValue>): Promise<ItemType[]>;
|
|
17
|
+
abstract getTotalPages(ctx: BaseContext, itemsPerPage: number, values: Record<string, FormDataValue>): Promise<number>;
|
|
18
|
+
abstract renderItem(ctx: BaseContext, item: ItemType): Promise<FlatTemplatable>;
|
|
19
|
+
filterFields: Record<string, FormField>;
|
|
30
20
|
filterControls: FormFieldControl[];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}>;
|
|
36
|
-
getProps(ctx: BaseContext): Promise<{
|
|
37
|
-
parsed_props: PropsType;
|
|
38
|
-
errors: PropsErrors<PropsType>;
|
|
39
|
-
raw_props: PropsType;
|
|
40
|
-
}>;
|
|
41
|
-
render(ctx: BaseContext): Promise<import("stream").Readable>;
|
|
42
|
-
renderPagination(ctx: BaseContext, props: PropsType): Promise<import("stream").Readable>;
|
|
21
|
+
init(): void;
|
|
22
|
+
renderListContainer(_: BaseContext, content: Templatable): FlatTemplatable;
|
|
23
|
+
render(ctx: BaseContext): Promise<FlatTemplatable>;
|
|
24
|
+
renderPagination(ctx: BaseContext, values: Record<string, FormDataValue>): Promise<FlatTemplatable>;
|
|
43
25
|
private renderPageButton;
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
getFilterValues(ctx: BaseContext): Promise<Record<string, unknown>>;
|
|
27
|
+
renderFilters(ctx: BaseContext): FlatTemplatable;
|
|
46
28
|
}
|
|
47
|
-
export declare abstract class SealiousItemListPage<C extends Collection,
|
|
29
|
+
export declare abstract class SealiousItemListPage<C extends Collection, F extends typeof BaseListPageFields> extends ListPage<CollectionItem<C>, F> {
|
|
48
30
|
collection: C;
|
|
49
31
|
constructor(collection: C);
|
|
50
|
-
getTotalPages(ctx: BaseContext,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
renderItem(_: BaseContext, item: CollectionItem<C>): Promise<Templatable>;
|
|
32
|
+
getTotalPages(ctx: BaseContext, itemsPerPage: number): Promise<number>;
|
|
33
|
+
protected addFilter(ctx: BaseContext, list: ItemList<C>): Promise<void>;
|
|
34
|
+
getItems(ctx: BaseContext, page: number, itemsPerPage: number): Promise<CollectionItem<C>[]>;
|
|
35
|
+
renderItem(_: BaseContext, item: CollectionItem<C>): Promise<FlatTemplatable>;
|
|
55
36
|
canAccess: (ctx: BaseContext) => Promise<{
|
|
56
37
|
canAccess: boolean;
|
|
57
38
|
message: string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import Router from "@koa/router";
|
|
3
|
+
import { FormControl } from "../forms/controls/form-control";
|
|
4
|
+
import { BaseContext } from "koa";
|
|
5
|
+
import { FlatTemplatable } from "tempstream";
|
|
6
|
+
import { FormField } from "../forms/fields/field";
|
|
7
|
+
import { FormData, FormDataValue, FormMessage } from "../forms/form";
|
|
8
|
+
export declare type PageErrorMessage = {
|
|
9
|
+
type: "access" | "internal";
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type Fields = Record<string, FormField<unknown>>;
|
|
13
|
+
export declare abstract class Mountable<F extends Fields = Fields> {
|
|
14
|
+
fields: F;
|
|
15
|
+
constructor();
|
|
16
|
+
abstract controls: FormControl[];
|
|
17
|
+
abstract mount(router: Router, path: string): void;
|
|
18
|
+
abstract canAccess(ctx: BaseContext): Promise<{
|
|
19
|
+
canAccess: boolean;
|
|
20
|
+
message: string;
|
|
21
|
+
}>;
|
|
22
|
+
abstract renderError(ctx: BaseContext, error: PageErrorMessage): Promise<FlatTemplatable>;
|
|
23
|
+
abstract extractRawValues(ctx: BaseContext): Record<string, FormDataValue>;
|
|
24
|
+
validateValues(ctx: BaseContext, data: Record<string, FormDataValue>): Promise<{
|
|
25
|
+
valid: boolean;
|
|
26
|
+
error: string;
|
|
27
|
+
}>;
|
|
28
|
+
protected validate(ctx: BaseContext, values: Record<string, FormDataValue>): Promise<{
|
|
29
|
+
valid: boolean;
|
|
30
|
+
field_errors: Partial<Record<keyof Fields, string>>;
|
|
31
|
+
form_messages: FormMessage[];
|
|
32
|
+
}>;
|
|
33
|
+
init(): void;
|
|
34
|
+
renderControls(ctx: BaseContext, data: FormData<keyof Fields>): FlatTemplatable;
|
|
35
|
+
renderMessages(_: BaseContext, data: FormData<keyof Fields>): FlatTemplatable;
|
|
36
|
+
}
|