@sealcode/sealgen 0.7.15 → 0.8.1
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/big-radio-group.d.ts +15 -0
- package/@types/forms/controls/checkbox.d.ts +8 -0
- package/@types/forms/controls/checkboxed-list-input.d.ts +2 -2
- package/@types/forms/controls/controls.d.ts +5 -0
- package/@types/forms/controls/derived.d.ts +11 -0
- package/@types/forms/controls/dropdown.d.ts +2 -2
- package/@types/forms/controls/editable-collection-subset.d.ts +2 -2
- package/@types/forms/controls/html.d.ts +6 -3
- package/@types/forms/controls/radio.d.ts +16 -0
- package/@types/forms/controls/tickable.d.ts +26 -0
- package/@types/forms/fields/boolean.d.ts +17 -0
- package/@types/forms/fields/checkboxed-list.d.ts +7 -3
- package/@types/forms/fields/collection-field.d.ts +6 -2
- package/@types/forms/fields/email.d.ts +3 -2
- package/@types/forms/fields/enum.d.ts +8 -4
- package/@types/forms/fields/field.d.ts +12 -4
- package/@types/forms/fields/number.d.ts +3 -2
- package/@types/forms/fields/pick-from-list.d.ts +6 -5
- package/@types/forms/fields/regexp.d.ts +3 -2
- package/@types/forms/fields/simple-form-field.d.ts +3 -1
- package/@types/forms/form.d.ts +6 -5
- package/@types/forms/multiform.d.ts +2 -2
- package/@types/page/list.d.ts +2 -2
- package/@types/page/mountable-with-fields.d.ts +4 -2
- package/lib/forms/controls/big-radio-group.js +37 -0
- package/lib/forms/controls/big-radio-group.js.map +1 -0
- package/lib/forms/controls/checkbox.js +18 -0
- package/lib/forms/controls/checkbox.js.map +1 -0
- package/lib/forms/controls/checkboxed-list-input.js.map +1 -1
- package/lib/forms/controls/controls.js +15 -0
- package/lib/forms/controls/controls.js.map +1 -1
- package/lib/forms/controls/derived.js +70 -0
- package/lib/forms/controls/derived.js.map +1 -0
- package/lib/forms/controls/dropdown.js.map +1 -1
- package/lib/forms/controls/editable-collection-subset.js.map +1 -1
- package/lib/forms/controls/html.js +11 -3
- package/lib/forms/controls/html.js.map +1 -1
- package/lib/forms/controls/radio.js +29 -0
- package/lib/forms/controls/radio.js.map +1 -0
- package/lib/forms/controls/simple-input.js +3 -1
- package/lib/forms/controls/simple-input.js.map +1 -1
- package/lib/forms/controls/textarea.js +3 -1
- package/lib/forms/controls/textarea.js.map +1 -1
- package/lib/forms/controls/tickable.js +72 -0
- package/lib/forms/controls/tickable.js.map +1 -0
- package/lib/forms/fields/boolean.js +45 -0
- package/lib/forms/fields/boolean.js.map +1 -0
- package/lib/forms/fields/checkboxed-list.js +2 -1
- package/lib/forms/fields/checkboxed-list.js.map +1 -1
- package/lib/forms/fields/collection-field.js +2 -0
- package/lib/forms/fields/collection-field.js.map +1 -1
- package/lib/forms/fields/email.js +3 -1
- package/lib/forms/fields/email.js.map +1 -1
- package/lib/forms/fields/enum.js +2 -1
- package/lib/forms/fields/enum.js.map +1 -1
- package/lib/forms/fields/field.js +9 -2
- package/lib/forms/fields/field.js.map +1 -1
- package/lib/forms/fields/number.js +2 -1
- package/lib/forms/fields/number.js.map +1 -1
- package/lib/forms/fields/pick-from-list.js +2 -1
- package/lib/forms/fields/pick-from-list.js.map +1 -1
- package/lib/forms/fields/regexp.js +2 -1
- package/lib/forms/fields/regexp.js.map +1 -1
- package/lib/forms/fields/simple-form-field.js +5 -0
- package/lib/forms/fields/simple-form-field.js.map +1 -1
- package/lib/forms/form.js +9 -5
- package/lib/forms/form.js.map +1 -1
- package/lib/forms/multiform.js.map +1 -1
- package/lib/mount.js +4 -2
- package/lib/mount.js.map +1 -1
- package/lib/page/mountable-with-fields.js +10 -0
- package/lib/page/mountable-with-fields.js.map +1 -1
- package/lib/templates/form.js +3 -1
- package/lib/templates/form.js.map +1 -1
- package/lib/tests/manual/multiform.js.map +1 -1
- package/package.json +2 -2
- package/src/forms/controls/big-radio-group.ts +63 -0
- package/src/forms/controls/checkbox.ts +19 -0
- package/src/forms/controls/checkboxed-list-input.ts +1 -1
- package/src/forms/controls/controls.ts +5 -0
- package/src/forms/controls/derived.ts +81 -0
- package/src/forms/controls/dropdown.ts +1 -1
- package/src/forms/controls/editable-collection-subset.ts +1 -1
- package/src/forms/controls/html.ts +21 -3
- package/src/forms/controls/radio.ts +43 -0
- package/src/forms/controls/simple-input.ts +4 -1
- package/src/forms/controls/textarea.ts +3 -1
- package/src/forms/controls/tickable.ts +112 -0
- package/src/forms/fields/boolean.ts +55 -0
- package/src/forms/fields/checkboxed-list.ts +7 -2
- package/src/forms/fields/collection-field.ts +8 -4
- package/src/forms/fields/email.ts +6 -2
- package/src/forms/fields/enum.ts +9 -4
- package/src/forms/fields/field.ts +32 -3
- package/src/forms/fields/number.ts +6 -3
- package/src/forms/fields/pick-from-list.ts +7 -3
- package/src/forms/fields/regexp.ts +4 -2
- package/src/forms/fields/simple-form-field.ts +11 -1
- package/src/forms/form.ts +27 -13
- package/src/forms/multiform.ts +4 -2
- package/src/mount.ts +4 -2
- package/src/page/mountable-with-fields.ts +18 -2
- package/src/templates/form.ts +3 -1
- package/src/tests/manual/multiform.ts +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { FlatTemplatable } from "tempstream";
|
|
3
|
+
import { FormField } from "../fields/field";
|
|
4
|
+
import { FormDataValue } from "../form";
|
|
5
|
+
import { FormFieldControl } from "./form-field-control";
|
|
6
|
+
export declare class BigRadioGroup extends FormFieldControl {
|
|
7
|
+
field: FormField;
|
|
8
|
+
options: Record<string, {
|
|
9
|
+
description: FlatTemplatable | ((ctx: Context, data: Record<string, FormDataValue>, messages: [], feld_name_prefix: string, form_id: string) => FlatTemplatable);
|
|
10
|
+
}>;
|
|
11
|
+
constructor(field: FormField, options: Record<string, {
|
|
12
|
+
description: FlatTemplatable | ((ctx: Context, data: Record<string, FormDataValue>, messages: [], feld_name_prefix: string, form_id: string) => FlatTemplatable);
|
|
13
|
+
}>);
|
|
14
|
+
render(ctx: Context, data: Record<string, FormDataValue>, messages: [], field_name_prefix: string, form_id: string): Promise<FlatTemplatable>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { FormDataValue } from "../form";
|
|
3
|
+
import { Tickable } from "./tickable";
|
|
4
|
+
export declare class Checkbox extends Tickable<boolean> {
|
|
5
|
+
type: "checkbox";
|
|
6
|
+
isChecked(_ctx: Context, _data: Record<string, FormDataValue>, value: boolean): boolean;
|
|
7
|
+
getValueAttribute(): string;
|
|
8
|
+
}
|
|
@@ -4,11 +4,11 @@ import { ChekboxedListField } from "../fields/field";
|
|
|
4
4
|
import { FormDataValue } from "../form";
|
|
5
5
|
import { FormFieldControl } from "./controls";
|
|
6
6
|
export declare class CheckboxedListInput extends FormFieldControl {
|
|
7
|
-
field: ChekboxedListField
|
|
7
|
+
field: ChekboxedListField<boolean>;
|
|
8
8
|
options: {
|
|
9
9
|
label: string;
|
|
10
10
|
};
|
|
11
|
-
constructor(field: ChekboxedListField
|
|
11
|
+
constructor(field: ChekboxedListField<boolean>, options?: {
|
|
12
12
|
label: string;
|
|
13
13
|
});
|
|
14
14
|
render(ctx: Context, data: Record<string, FormDataValue>): Promise<import("stream").Readable>;
|
|
@@ -11,3 +11,8 @@ export { HTML } from "./html";
|
|
|
11
11
|
export { HiddenInput } from "./hidden-input";
|
|
12
12
|
export { Textarea } from "./textarea";
|
|
13
13
|
export { FieldGroup } from "./field-group";
|
|
14
|
+
export * from "./derived";
|
|
15
|
+
export * from "./tickable";
|
|
16
|
+
export * from "./checkbox";
|
|
17
|
+
export * from "./radio";
|
|
18
|
+
export * from "./big-radio-group";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FlatTemplatable } from "tempstream";
|
|
2
|
+
import { FormField } from "../fields/field";
|
|
3
|
+
import { FormControl } from "./form-control";
|
|
4
|
+
export declare class Derived<Consts extends Record<string, unknown> | undefined> extends FormControl {
|
|
5
|
+
fields: FormField[];
|
|
6
|
+
_render: (values: Record<string, string>, consts: Consts) => string;
|
|
7
|
+
consts: Consts;
|
|
8
|
+
role: "decoration";
|
|
9
|
+
constructor(fields: FormField[], _render: (values: Record<string, string>, consts: Consts) => string, consts: Consts);
|
|
10
|
+
render(): FlatTemplatable;
|
|
11
|
+
}
|
|
@@ -4,13 +4,13 @@ import { FormField, PickFromListField } from "../fields/field";
|
|
|
4
4
|
import { FormDataValue } from "../form";
|
|
5
5
|
import { FormFieldControl } from "./controls";
|
|
6
6
|
export declare class Dropdown extends FormFieldControl {
|
|
7
|
-
field: PickFromListField
|
|
7
|
+
field: PickFromListField<boolean>;
|
|
8
8
|
options: {
|
|
9
9
|
label: string;
|
|
10
10
|
autosubmit?: boolean;
|
|
11
11
|
autocomplete?: boolean;
|
|
12
12
|
};
|
|
13
|
-
constructor(field: PickFromListField
|
|
13
|
+
constructor(field: PickFromListField<boolean>, options?: {
|
|
14
14
|
label: string;
|
|
15
15
|
autosubmit?: boolean;
|
|
16
16
|
autocomplete?: boolean;
|
|
@@ -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
|
-
field: PickFromListField
|
|
14
|
+
field: PickFromListField<false>;
|
|
15
15
|
actionname: string;
|
|
16
16
|
listLabel?: string | undefined;
|
|
17
17
|
selectLabel?: string | undefined;
|
|
18
|
-
constructor(field: PickFromListField
|
|
18
|
+
constructor(field: PickFromListField<false>, actionname: string, listLabel?: string | undefined, selectLabel?: string | undefined);
|
|
19
19
|
render(ctx: Context, data: Record<string, FormDataValue>): Promise<FlatTemplatable>;
|
|
20
20
|
role: "input";
|
|
21
21
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FlatTemplatable } from "tempstream";
|
|
3
3
|
import { FormControl } from "./controls";
|
|
4
|
+
declare type Renderer = ((ctx: Context) => FlatTemplatable) | FlatTemplatable;
|
|
4
5
|
export declare class HTML extends FormControl {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor(
|
|
6
|
+
role: "decoration" | "submit";
|
|
7
|
+
renderer: Renderer;
|
|
8
|
+
constructor(role: "decoration" | "submit", renderer: Renderer);
|
|
9
|
+
constructor(renderer: Renderer);
|
|
8
10
|
render(ctx: Context): Promise<FlatTemplatable>;
|
|
9
11
|
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { FormField } from "../fields/field";
|
|
3
|
+
import { FormDataValue } from "../form";
|
|
4
|
+
import { Tickable } from "./tickable";
|
|
5
|
+
export declare class Radio extends Tickable<string> {
|
|
6
|
+
field: FormField<boolean, string>;
|
|
7
|
+
value: string;
|
|
8
|
+
type: "radio";
|
|
9
|
+
constructor(field: FormField<boolean, string>, value: string, options: {
|
|
10
|
+
label?: string;
|
|
11
|
+
});
|
|
12
|
+
makeInputID(): string;
|
|
13
|
+
getValueAttribute(): string;
|
|
14
|
+
getWrapperClasses(ctx: Context, data: Record<string, FormDataValue>, value: string): string[];
|
|
15
|
+
isChecked(_ctx: Context, _data: Record<string, FormDataValue>, value: string): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { FlatTemplatable } from "tempstream";
|
|
3
|
+
import { FormField } from "../fields/field";
|
|
4
|
+
import { FormDataValue } from "../form";
|
|
5
|
+
import { FormFieldControl } from "./controls";
|
|
6
|
+
export declare abstract class Tickable<T extends unknown> extends FormFieldControl {
|
|
7
|
+
field: FormField<boolean, T>;
|
|
8
|
+
options: {
|
|
9
|
+
id?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
hide_errors?: boolean;
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
};
|
|
14
|
+
constructor(field: FormField<boolean, T>, options?: {
|
|
15
|
+
id?: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
hide_errors?: boolean;
|
|
18
|
+
readonly?: boolean;
|
|
19
|
+
});
|
|
20
|
+
type: "checkbox" | "radio";
|
|
21
|
+
abstract getValueAttribute(ctx: Context, data: Record<string, FormDataValue>, value: T): string;
|
|
22
|
+
abstract isChecked(ctx: Context, data: Record<string, FormDataValue>, value: T): boolean;
|
|
23
|
+
makeInputID(): string;
|
|
24
|
+
getWrapperClasses(ctx: Context, data: Record<string, FormDataValue>, value: T): string[];
|
|
25
|
+
render<Fields extends Record<string, FormField>>(ctx: Context, data: Record<string, FormDataValue>, _: unknown[], field_prefix: string, form_id: string): Promise<FlatTemplatable>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { FormDataValue } from "../form";
|
|
3
|
+
import { FieldParseResult, FormField } from "./field";
|
|
4
|
+
export declare class Boolean<Required extends boolean> extends FormField<Required, boolean> {
|
|
5
|
+
error_message: string;
|
|
6
|
+
predicate: (v: unknown, w: unknown) => {
|
|
7
|
+
readonly match: boolean;
|
|
8
|
+
readonly wildcard: boolean;
|
|
9
|
+
};
|
|
10
|
+
constructor(required: Required, error_message?: string);
|
|
11
|
+
isValueValid(_: Context, value: boolean): Promise<{
|
|
12
|
+
valid: boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
}>;
|
|
15
|
+
parse(_: Context, value: FormDataValue): Promise<FieldParseResult<boolean>>;
|
|
16
|
+
getEmptyValue(): boolean;
|
|
17
|
+
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FormDataValue } from "../form";
|
|
3
3
|
import { FieldParseResult, FormField, FormFieldValidationResponse } from "./field";
|
|
4
|
-
export declare class ChekboxedListField extends FormField<Record<string, "on">> {
|
|
5
|
-
required:
|
|
4
|
+
export declare class ChekboxedListField<Required extends boolean> extends FormField<Required, Record<string, "on">> {
|
|
5
|
+
required: Required;
|
|
6
6
|
generateOptions: (ctx: Context) => Promise<Record<string, string> | {
|
|
7
7
|
[i: string]: string;
|
|
8
8
|
}>;
|
|
9
9
|
isVisible: (ctx: Context) => Promise<boolean>;
|
|
10
|
-
constructor(required:
|
|
10
|
+
constructor(required: Required, generateOptions: (ctx: Context) => Promise<Record<string, string> | {
|
|
11
11
|
[i: string]: string;
|
|
12
12
|
}>, isVisible?: (ctx: Context) => Promise<boolean>);
|
|
13
|
+
predicate: (v: unknown, w: unknown) => {
|
|
14
|
+
readonly match: boolean;
|
|
15
|
+
readonly wildcard: string[];
|
|
16
|
+
};
|
|
13
17
|
isValueValid(_: Context, value: unknown): Promise<FormFieldValidationResponse>;
|
|
14
18
|
parse(_: Context, raw_value: FormDataValue): Promise<FieldParseResult<Record<string, "on">>>;
|
|
15
19
|
getEmptyValue(): Record<string, "on">;
|
|
@@ -2,9 +2,13 @@ import { Context } from "koa";
|
|
|
2
2
|
import { Depromisify, Field, FieldOutput } from "sealious";
|
|
3
3
|
import { FormDataValue } from "../form";
|
|
4
4
|
import { FieldParseResult, FormField, FormFieldValidationResponse } from "./field";
|
|
5
|
-
export declare class CollectionField<F extends Field> extends FormField<FieldOutput<F>> {
|
|
5
|
+
export declare class CollectionField<F extends Field, Required extends boolean> extends FormField<Required, FieldOutput<F>> {
|
|
6
6
|
sealiousField: F;
|
|
7
|
-
constructor(required:
|
|
7
|
+
constructor(required: Required, sealiousField: F);
|
|
8
|
+
predicate: (v: unknown, w: unknown) => {
|
|
9
|
+
readonly match: true;
|
|
10
|
+
readonly wildcard: unknown;
|
|
11
|
+
};
|
|
8
12
|
parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<FieldOutput<F>>>;
|
|
9
13
|
isValueValid(ctx: Context, value: FieldOutput<F>): Promise<FormFieldValidationResponse>;
|
|
10
14
|
getEmptyValue(): Depromisify<ReturnType<F["decode"]>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RegExpField } from "./regexp";
|
|
2
|
-
export declare class EmailField extends RegExpField {
|
|
2
|
+
export declare class EmailField<Required extends boolean> extends RegExpField<Required> {
|
|
3
3
|
error_message: string;
|
|
4
4
|
default_value: string;
|
|
5
|
-
|
|
5
|
+
predicate: import("@sealcode/ts-predicates").Predicate<string>;
|
|
6
|
+
constructor(required: Required, error_message?: string, default_value?: string);
|
|
6
7
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FormDataValue } from "../form";
|
|
3
3
|
import { FieldParseResult, FormField } from "./field";
|
|
4
|
-
export declare class EnumField extends FormField<string> {
|
|
5
|
-
options:
|
|
6
|
-
error_message: (options:
|
|
7
|
-
constructor(required:
|
|
4
|
+
export declare class EnumField<Options extends readonly string[], Required extends boolean> extends FormField<Required, string> {
|
|
5
|
+
options: Options;
|
|
6
|
+
error_message: (options: Options) => string;
|
|
7
|
+
constructor(required: Required, options: Options, error_message?: (options: Options) => string);
|
|
8
|
+
predicate: (v: unknown, w: unknown) => {
|
|
9
|
+
readonly match: boolean;
|
|
10
|
+
readonly wildcard: Options[number];
|
|
11
|
+
};
|
|
8
12
|
isValueValid(_: Context, value: unknown): Promise<{
|
|
9
13
|
valid: boolean;
|
|
10
14
|
message: string;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { Predicate, predicates } from "@sealcode/ts-predicates";
|
|
1
2
|
import { Context } from "koa";
|
|
2
3
|
import { FormDataValue } from "../form";
|
|
3
4
|
export declare type FormFieldValidationResponse = {
|
|
4
5
|
valid: boolean;
|
|
5
6
|
message: string;
|
|
6
7
|
};
|
|
7
|
-
export declare type FormFieldValidationFn<ValueType> = (ctx: Context, value: ValueType, field: FormField<ValueType>) => Promise<FormFieldValidationResponse>;
|
|
8
|
+
export declare type FormFieldValidationFn<ValueType> = (ctx: Context, value: ValueType, field: FormField<boolean, ValueType>) => Promise<FormFieldValidationResponse>;
|
|
8
9
|
export declare type FieldParsedValue<T> = T extends FormField<infer R> ? R : never;
|
|
10
|
+
export declare type GetPredicate<F extends FormField> = F extends FormField<true> ? F["predicate"] : F["predicate"] | typeof predicates.undefined;
|
|
11
|
+
export declare type FieldsToShape<T extends Record<string, FormField>> = {
|
|
12
|
+
[property in keyof T]: GetPredicate<T[property]>;
|
|
13
|
+
};
|
|
14
|
+
export declare function fieldsToShape<Fields extends Record<string, FormField>>(obj: Fields): FieldsToShape<Fields>;
|
|
9
15
|
export declare type FieldParseResult<T> = {
|
|
10
16
|
parsable: false;
|
|
11
17
|
error: string;
|
|
@@ -15,10 +21,11 @@ export declare type FieldParseResult<T> = {
|
|
|
15
21
|
error: null;
|
|
16
22
|
parsed_value: T;
|
|
17
23
|
};
|
|
18
|
-
export declare abstract class FormField<ParsedValue extends unknown = unknown> {
|
|
19
|
-
required:
|
|
24
|
+
export declare abstract class FormField<Required extends boolean = boolean, ParsedValue extends unknown = unknown> {
|
|
25
|
+
readonly required: Required;
|
|
20
26
|
name: string;
|
|
21
|
-
constructor(required
|
|
27
|
+
constructor(required: Required);
|
|
28
|
+
predicate: Predicate;
|
|
22
29
|
init(fieldname: string): void;
|
|
23
30
|
_validate(ctx: Context, value: ParsedValue): Promise<FormFieldValidationResponse>;
|
|
24
31
|
abstract getEmptyValue(): ParsedValue;
|
|
@@ -39,3 +46,4 @@ export * from "./pick-from-list";
|
|
|
39
46
|
export * from "./regexp";
|
|
40
47
|
export * from "./email";
|
|
41
48
|
export * from "./enum";
|
|
49
|
+
export * from "./boolean";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FormDataValue } from "../form";
|
|
3
3
|
import { FieldParseResult, FormField } from "./field";
|
|
4
|
-
export declare class NumberField<DefaultValue extends number | null = null> extends FormField<number | DefaultValue> {
|
|
4
|
+
export declare class NumberField<DefaultValue extends number | null = null, Required extends boolean = boolean> extends FormField<Required, number | DefaultValue> {
|
|
5
5
|
default_value: DefaultValue;
|
|
6
|
-
constructor(required:
|
|
6
|
+
constructor(required: Required, default_value: DefaultValue);
|
|
7
|
+
predicate: import("@sealcode/ts-predicates").Predicate<number>;
|
|
7
8
|
isValueValid(_: Context, value: unknown): Promise<{
|
|
8
9
|
valid: boolean;
|
|
9
10
|
message: string;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FormFieldValidationResponse } from "./field";
|
|
3
3
|
import { SimpleFormField } from "./simple-form-field";
|
|
4
|
-
export declare class PickFromListField extends SimpleFormField {
|
|
5
|
-
required:
|
|
4
|
+
export declare class PickFromListField<Required extends boolean> extends SimpleFormField<Required> {
|
|
5
|
+
required: Required;
|
|
6
6
|
generateOptions: (ctx: Context) => Promise<Record<string, string> | {
|
|
7
7
|
[i: string]: string;
|
|
8
8
|
}>;
|
|
9
|
-
customValidation: (ctx: Context, value: unknown, instance: PickFromListField) => Promise<FormFieldValidationResponse>;
|
|
10
|
-
constructor(required:
|
|
9
|
+
customValidation: (ctx: Context, value: unknown, instance: PickFromListField<Required>) => Promise<FormFieldValidationResponse>;
|
|
10
|
+
constructor(required: Required, generateOptions: (ctx: Context) => Promise<Record<string, string> | {
|
|
11
11
|
[i: string]: string;
|
|
12
|
-
}>, customValidation?: (ctx: Context, value: unknown, instance: PickFromListField) => Promise<FormFieldValidationResponse>);
|
|
12
|
+
}>, customValidation?: (ctx: Context, value: unknown, instance: PickFromListField<Required>) => Promise<FormFieldValidationResponse>);
|
|
13
|
+
predicate: import("@sealcode/ts-predicates").Predicate<string>;
|
|
13
14
|
isValueValid(ctx: Context, value: string): Promise<FormFieldValidationResponse>;
|
|
14
15
|
valueInList(ctx: Context, value: unknown): Promise<FormFieldValidationResponse>;
|
|
15
16
|
getEmptyValue(): string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FormDataValue } from "../form";
|
|
3
3
|
import { FieldParseResult, FormField } from "./field";
|
|
4
|
-
export declare class RegExpField extends FormField<
|
|
4
|
+
export declare class RegExpField<Required extends boolean> extends FormField<Required> {
|
|
5
5
|
regexp: RegExp;
|
|
6
6
|
error_message: string;
|
|
7
7
|
default_value: string;
|
|
8
|
-
constructor(required:
|
|
8
|
+
constructor(required: Required, regexp: RegExp, error_message: string, default_value?: string);
|
|
9
|
+
predicate: import("@sealcode/ts-predicates").Predicate<string>;
|
|
9
10
|
isValueValid(_: Context, value: unknown): Promise<{
|
|
10
11
|
valid: boolean;
|
|
11
12
|
message: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { FieldParseResult, FormField } from "./field";
|
|
2
2
|
import { FormDataValue } from "../form";
|
|
3
3
|
import { Context } from "koa";
|
|
4
|
-
export declare class SimpleFormField extends FormField<string | null> {
|
|
4
|
+
export declare class SimpleFormField<Required extends boolean> extends FormField<Required, string | null> {
|
|
5
5
|
parse(_: Context, raw_value: FormDataValue): Promise<FieldParseResult<string>>;
|
|
6
|
+
predicate: import("@sealcode/ts-predicates").Predicate<string>;
|
|
6
7
|
getEmptyValue(): string;
|
|
8
|
+
constructor(required: Required);
|
|
7
9
|
}
|
package/@types/forms/form.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ import Router from "@koa/router";
|
|
|
4
4
|
import { FlatTemplatable } from "tempstream";
|
|
5
5
|
import { FormField } from "./fields/field";
|
|
6
6
|
import { Fields, MountableWithFields, PageErrorMessage } from "../page/mountable-with-fields";
|
|
7
|
-
export declare type FormDataPrimitive = string | string[] | undefined;
|
|
7
|
+
export declare type FormDataPrimitive = string | string[] | number | undefined;
|
|
8
8
|
export declare type FormDataValue = FormDataPrimitive | Record<string, FormDataPrimitive>;
|
|
9
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>>> = {
|
|
10
|
+
export declare type FormFieldsToValues<F extends Record<string, FormField<boolean, keyof F>>> = {
|
|
11
11
|
[Property in keyof F]: FieldValueType<F[Property]>;
|
|
12
12
|
};
|
|
13
13
|
export declare type FormMessage = {
|
|
@@ -27,10 +27,11 @@ export declare type FormReaction = {
|
|
|
27
27
|
url: string;
|
|
28
28
|
messages?: FormMessage[];
|
|
29
29
|
};
|
|
30
|
-
export declare abstract class Form<F extends Fields> extends MountableWithFields<F> {
|
|
30
|
+
export declare abstract class Form<F extends Fields, SubmitResult extends any> extends MountableWithFields<F> {
|
|
31
31
|
defaultSuccessMessage: string;
|
|
32
32
|
submitButtonText: string;
|
|
33
33
|
action: string;
|
|
34
|
+
useTurbo: boolean;
|
|
34
35
|
canAccess(_: Context): Promise<{
|
|
35
36
|
canAccess: boolean;
|
|
36
37
|
message: string;
|
|
@@ -43,8 +44,8 @@ export declare abstract class Form<F extends Fields> extends MountableWithFields
|
|
|
43
44
|
makeCloseFormTag(): FlatTemplatable;
|
|
44
45
|
onValuesInvalid(ctx: Context, form_messages: FormMessage[]): Promise<FormReaction>;
|
|
45
46
|
onError(ctx: Context, data: FormData, error: unknown): Promise<FormReaction>;
|
|
46
|
-
abstract onSubmit(ctx: Context, data: FormData):
|
|
47
|
-
onSuccess(ctx: Context, data: FormData): Promise<FormReaction>;
|
|
47
|
+
abstract onSubmit(ctx: Context, data: FormData): SubmitResult | Promise<SubmitResult>;
|
|
48
|
+
onSuccess(ctx: Context, data: FormData, _submitResult: SubmitResult): Promise<FormReaction>;
|
|
48
49
|
handlePost(ctx: Context): Promise<FormReaction>;
|
|
49
50
|
mount(router: Router, path: string): void;
|
|
50
51
|
extractRawValues(ctx: Context): Record<string, FormDataValue>;
|
|
@@ -7,14 +7,14 @@ import { Fields, MountableWithFields } from "../page/mountable-with-fields";
|
|
|
7
7
|
export declare class Multiform extends MountableWithFields {
|
|
8
8
|
controls: never[];
|
|
9
9
|
name: string;
|
|
10
|
-
forms: Record<string, Form<Fields>>;
|
|
10
|
+
forms: Record<string, Form<Fields, unknown>>;
|
|
11
11
|
init(): void;
|
|
12
12
|
extractRawValues(ctx: Context): Record<string, FormDataValue>;
|
|
13
13
|
canAccess(): Promise<{
|
|
14
14
|
canAccess: boolean;
|
|
15
15
|
message: string;
|
|
16
16
|
}>;
|
|
17
|
-
getSubformsToRender(ctx: Context): Array<readonly [string, Form<any>]>;
|
|
17
|
+
getSubformsToRender(ctx: Context): Array<readonly [string, Form<any, unknown>]>;
|
|
18
18
|
renderSubform(ctx: Context, sub_form_name: string): Promise<FlatTemplatable>;
|
|
19
19
|
getSubformRawValues(ctx: Context, sub_form_name: string): Record<string, FormDataValue>;
|
|
20
20
|
render(ctx: Context, messages: FormMessage[], prerenderedForms?: Record<string, FlatTemplatable | undefined>): Promise<FlatTemplatable>;
|
package/@types/page/list.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { FormDataValue } from "..";
|
|
|
9
9
|
export declare const BasePagePropsShape: {};
|
|
10
10
|
export declare type BasePageProps = ShapeToType<typeof BasePagePropsShape>;
|
|
11
11
|
export declare const BaseListPageFields: {
|
|
12
|
-
readonly page: NumberField<1>;
|
|
13
|
-
readonly itemsPerPage: NumberField<12>;
|
|
12
|
+
readonly page: NumberField<1, false>;
|
|
13
|
+
readonly itemsPerPage: NumberField<12, false>;
|
|
14
14
|
};
|
|
15
15
|
export declare abstract class ListPage<ItemType, F extends typeof BaseListPageFields> extends Page<F> {
|
|
16
16
|
abstract getItems(ctx: Context, page: number, itemsPerPage: number, values: Record<string, FormDataValue>): Promise<ItemType[]>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { ShapeToType } from "@sealcode/ts-predicates";
|
|
1
2
|
import { Context } from "koa";
|
|
2
3
|
import { FlatTemplatable } from "tempstream";
|
|
3
4
|
import { FormControl } from "../forms/controls/form-control";
|
|
4
|
-
import { FormField } from "../forms/fields/field";
|
|
5
|
+
import { FieldsToShape, FormField } from "../forms/fields/field";
|
|
5
6
|
import { FormData, FormDataValue, FormMessage } from "../forms/form";
|
|
6
7
|
import { Mountable } from "./mountable";
|
|
7
8
|
export declare type PageErrorMessage = {
|
|
8
9
|
type: "access" | "internal";
|
|
9
10
|
message: string;
|
|
10
11
|
};
|
|
11
|
-
export declare type Fields = Record<string, FormField<unknown>>;
|
|
12
|
+
export declare type Fields = Record<string, FormField<boolean, unknown>>;
|
|
12
13
|
export declare abstract class MountableWithFields<F extends Fields = Fields> extends Mountable {
|
|
13
14
|
fields: F;
|
|
14
15
|
field_names_prefix: string;
|
|
@@ -29,4 +30,5 @@ export declare abstract class MountableWithFields<F extends Fields = Fields> ext
|
|
|
29
30
|
renderError(_: Context, error: PageErrorMessage): Promise<FlatTemplatable>;
|
|
30
31
|
renderMessages(_: Context, data: FormData<keyof Fields>): FlatTemplatable;
|
|
31
32
|
abstract extractRawValues(ctx: Context): Record<string, FormDataValue>;
|
|
33
|
+
getParsedValues(ctx: Context): Promise<ShapeToType<FieldsToShape<F>>>;
|
|
32
34
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BigRadioGroup = void 0;
|
|
4
|
+
const tempstream_1 = require("tempstream");
|
|
5
|
+
const form_field_control_1 = require("./form-field-control");
|
|
6
|
+
class BigRadioGroup extends form_field_control_1.FormFieldControl {
|
|
7
|
+
constructor(field, options) {
|
|
8
|
+
super([field]);
|
|
9
|
+
this.field = field;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async render(ctx, data, messages, field_name_prefix, form_id) {
|
|
13
|
+
const { raw: current_value } = await this.field.getValue(ctx, data);
|
|
14
|
+
return tempstream_1.tempstream /* HTML */ `<div class="bigradios">
|
|
15
|
+
${Object.entries(this.options).map(([key, { description }]) => {
|
|
16
|
+
const id = `${this.field.name}-radio-${key}`;
|
|
17
|
+
return tempstream_1.tempstream /* HTML */ `<input
|
|
18
|
+
type="radio"
|
|
19
|
+
name="${this.field.name}"
|
|
20
|
+
value="${key}"
|
|
21
|
+
id="${id}"
|
|
22
|
+
style="display: none"
|
|
23
|
+
${this.field.required ? "required" : ""}
|
|
24
|
+
${key == current_value ? "checked" : ""}
|
|
25
|
+
/>
|
|
26
|
+
<div class="bigradio">
|
|
27
|
+
${typeof description == "function"
|
|
28
|
+
? description(ctx, data, messages, field_name_prefix, form_id)
|
|
29
|
+
: description}
|
|
30
|
+
<label class="bigradio__cta" for="${id}">Wybierz</label>
|
|
31
|
+
</div>`;
|
|
32
|
+
})}
|
|
33
|
+
</div>`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.BigRadioGroup = BigRadioGroup;
|
|
37
|
+
//# sourceMappingURL=big-radio-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"big-radio-group.js","sourceRoot":"","sources":["../../../src/forms/controls/big-radio-group.ts"],"names":[],"mappings":";;;AACA,2CAAyD;AAGzD,6DAAwD;AAExD,MAAa,aAAc,SAAQ,qCAAgB;IAClD,YACQ,KAAgB,EAChB,OAaN;QAED,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAhBR,UAAK,GAAL,KAAK,CAAW;QAChB,YAAO,GAAP,OAAO,CAab;IAGF,CAAC;IAED,KAAK,CAAC,MAAM,CACX,GAAY,EACZ,IAAmC,EACnC,QAAY,EACZ,iBAAyB,EACzB,OAAe;QAEf,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACpE,OAAO,uBAAU,CAAA,UAAU,CAAC;KACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE;YAC7D,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,UAAU,GAAG,EAAE,CAAC;YAC7C,OAAO,uBAAU,CAAA,UAAU,CAAC;;cAElB,IAAI,CAAC,KAAK,CAAC,IAAI;eACd,GAAG;YACN,EAAE;;QAEN,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;QACrC,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;;;QAGrC,OAAO,WAAW,IAAI,UAAU;gBACjC,CAAC,CAAC,WAAW,CACX,GAAG,EACH,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACjB,OAAO,CACN;gBACH,CAAC,CAAC,WAAW;0CACsB,EAAE;YAChC,CAAC;QACV,CAAC,CAAC;SACI,CAAC;IACT,CAAC;CACD;AAxDD,sCAwDC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Checkbox = void 0;
|
|
4
|
+
const tickable_1 = require("./tickable");
|
|
5
|
+
class Checkbox extends tickable_1.Tickable {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.type = "checkbox";
|
|
9
|
+
}
|
|
10
|
+
isChecked(_ctx, _data, value) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
getValueAttribute() {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Checkbox = Checkbox;
|
|
18
|
+
//# sourceMappingURL=checkbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../../src/forms/controls/checkbox.ts"],"names":[],"mappings":";;;AAEA,yCAAsC;AAEtC,MAAa,QAAS,SAAQ,mBAAiB;IAA/C;;QACC,SAAI,GAAU,UAAU,CAAC;IAa1B,CAAC;IAXA,SAAS,CACR,IAAa,EACb,KAAoC,EACpC,KAAc;QAEd,OAAO,KAAK,CAAC;IACd,CAAC;IAED,iBAAiB;QAChB,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AAdD,4BAcC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkboxed-list-input.js","sourceRoot":"","sources":["../../../src/forms/controls/checkboxed-list-input.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AAEzD,2CAAwC;AACxC,6DAA2E;AAG3E,yCAA8C;AAE9C,MAAa,mBAAoB,SAAQ,2BAAgB;IACxD,YACQ,
|
|
1
|
+
{"version":3,"file":"checkboxed-list-input.js","sourceRoot":"","sources":["../../../src/forms/controls/checkboxed-list-input.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AAEzD,2CAAwC;AACxC,6DAA2E;AAG3E,yCAA8C;AAE9C,MAAa,mBAAoB,SAAQ,2BAAgB;IACxD,YACQ,KAAkC,EAClC,UAA6B,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE;QAEzD,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAHR,UAAK,GAAL,KAAK,CAA6B;QAClC,YAAO,GAAP,OAAO,CAA2C;IAG1D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAY,EAAE,IAAmC;QAC7D,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACtE,IAAI,CAAC,kBAAE,CAAC,YAAY,EAAE,0BAAU,CAAC,KAAK,CAAC,0BAAU,CAAC,MAAM,CAAC,CAAC,EAAE;YAC3D,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC5D;QACD,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC9C,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC;YAC/B,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;SACzB,CAAC,CAAC;QAEH,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAEtC,OAAO,uBAAU,CAAA,UAAU,CAAC,GAAG,SAAS;YACvC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAC9C,4BAAY,CACX,CAAC,IAAI,EAAE,gCAAgB,CAAC,QAAQ,CAAC,CAAC;YAClC,UAAU,CAAC;;;cAGH,IAAI,IAAI,KAAK;gBACX,IAAI,IAAI,KAAK;UACnB,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;;qBAElC,IAAI,IAAI,KAAK,KAAK,IAAI;OACpC,CACD,CACA;YACH,CAAC,CAAC,EAAE,EAAE,CAAC;IACT,CAAC;CACD;AArCD,kDAqCC"}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
2
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
13
|
exports.FieldGroup = exports.Textarea = exports.HiddenInput = exports.HTML = exports.FormParagraph = exports.FormHeader = exports.SimpleInput = exports.Dropdown = exports.CheckboxedListInput = exports.Frame = exports.EditableCollectionSubset = exports.FormFieldControl = exports.FormControl = void 0;
|
|
4
14
|
var form_control_1 = require("./form-control");
|
|
@@ -27,4 +37,9 @@ var textarea_1 = require("./textarea");
|
|
|
27
37
|
Object.defineProperty(exports, "Textarea", { enumerable: true, get: function () { return textarea_1.Textarea; } });
|
|
28
38
|
var field_group_1 = require("./field-group");
|
|
29
39
|
Object.defineProperty(exports, "FieldGroup", { enumerable: true, get: function () { return field_group_1.FieldGroup; } });
|
|
40
|
+
__exportStar(require("./derived"), exports);
|
|
41
|
+
__exportStar(require("./tickable"), exports);
|
|
42
|
+
__exportStar(require("./checkbox"), exports);
|
|
43
|
+
__exportStar(require("./radio"), exports);
|
|
44
|
+
__exportStar(require("./big-radio-group"), exports);
|
|
30
45
|
//# sourceMappingURL=controls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controls.js","sourceRoot":"","sources":["../../../src/forms/controls/controls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controls.js","sourceRoot":"","sources":["../../../src/forms/controls/controls.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,4CAA0B;AAC1B,6CAA2B;AAC3B,6CAA2B;AAC3B,0CAAwB;AACxB,oDAAkC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Derived = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const tempstream_1 = require("tempstream");
|
|
6
|
+
const form_control_1 = require("./form-control");
|
|
7
|
+
class Derived extends form_control_1.FormControl {
|
|
8
|
+
constructor(fields, _render, consts) {
|
|
9
|
+
super();
|
|
10
|
+
this.fields = fields;
|
|
11
|
+
this._render = _render;
|
|
12
|
+
this.consts = consts;
|
|
13
|
+
this.role = "decoration";
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
const id = "A" + crypto_1.randomUUID(); // the A makes it always a valid id, as it cannot start with a number
|
|
17
|
+
return tempstream_1.tempstream /* HTML */ `<div>
|
|
18
|
+
<script>
|
|
19
|
+
(function () {
|
|
20
|
+
const consts = {
|
|
21
|
+
${Object.entries(this.consts || {})
|
|
22
|
+
.map(([key, value]) => {
|
|
23
|
+
return `"${key}": ${typeof value === "object"
|
|
24
|
+
? JSON.stringify(value)
|
|
25
|
+
: value.toString()}`;
|
|
26
|
+
})
|
|
27
|
+
.join(",")},
|
|
28
|
+
};
|
|
29
|
+
const form = document.currentScript.closest("form");
|
|
30
|
+
const render = ${this._render.toString()};
|
|
31
|
+
function getValues() {
|
|
32
|
+
return Object.fromEntries(
|
|
33
|
+
${JSON.stringify(this.fields.map((field) => field.name))}.map((field_name) => {
|
|
34
|
+
let input = form.querySelector(
|
|
35
|
+
\`input[name="\${field_name}"]\`
|
|
36
|
+
);
|
|
37
|
+
if (input.type === "radio") {
|
|
38
|
+
input = form.querySelector(
|
|
39
|
+
\`input[name="\${field_name}"]:checked\`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return [field_name, input.value];
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function setupWatcher(field_name) {
|
|
47
|
+
form.querySelectorAll(
|
|
48
|
+
\`input[name="\${field_name}"]\`
|
|
49
|
+
).forEach((input) => {
|
|
50
|
+
input.onchange = () => {
|
|
51
|
+
document.querySelector("#${id}").innerHTML =
|
|
52
|
+
render(getValues(), consts);
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
${JSON.stringify(this.fields.map((field) => field.name))}.forEach(setupWatcher);
|
|
57
|
+
setTimeout(
|
|
58
|
+
() =>
|
|
59
|
+
(document.querySelector("#${id}").innerHTML =
|
|
60
|
+
render(getValues(), consts)),
|
|
61
|
+
0
|
|
62
|
+
);
|
|
63
|
+
})();
|
|
64
|
+
</script>
|
|
65
|
+
<div id="${id}">${this._render({}, this.consts)}</div>
|
|
66
|
+
</div>`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.Derived = Derived;
|
|
70
|
+
//# sourceMappingURL=derived.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derived.js","sourceRoot":"","sources":["../../../src/forms/controls/derived.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AACpC,2CAAyD;AAEzD,iDAA6C;AAE7C,MAAa,OAEX,SAAQ,0BAAW;IAGpB,YACQ,MAAmB,EACnB,OAGI,EACJ,MAAc;QAErB,KAAK,EAAE,CAAC;QAPD,WAAM,GAAN,MAAM,CAAa;QACnB,YAAO,GAAP,OAAO,CAGH;QACJ,WAAM,GAAN,MAAM,CAAQ;QARtB,SAAI,GAAU,YAAY,CAAC;IAW3B,CAAC;IAED,MAAM;QACL,MAAM,EAAE,GAAG,GAAG,GAAG,mBAAU,EAAE,CAAC,CAAC,qEAAqE;QACpG,OAAO,uBAAU,CAAA,UAAU,CAAC;;;;QAItB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;aACjC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACrB,OAAO,IAAI,GAAG,MACb,OAAO,KAAK,KAAK,QAAQ;gBACxB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;gBACvB,CAAC,CAAE,KAAgB,CAAC,QAAQ,EAC9B,EAAE,CAAC;QACJ,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC;;;sBAGK,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;;;SAGpC,IAAI,CAAC,SAAS,CACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CACtC;;;;;;;;;;;;;;;;;;mCAkB2B,EAAE;;;;;OAK9B,IAAI,CAAC,SAAS,CACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CACtC;;;mCAG6B,EAAE;;;;;;cAMvB,EAAE,KAAK,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC;SACzC,CAAC;IACT,CAAC;CACD;AA3ED,0BA2EC"}
|