@sealcode/sealgen 0.19.32 → 0.19.34

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.
Files changed (82) hide show
  1. package/@types/forms/controls/dropdown.d.ts +2 -2
  2. package/@types/forms/fields/CollectionField.d.ts +1 -0
  3. package/@types/forms/fields/boolean.d.ts +1 -2
  4. package/@types/forms/fields/collection-field.d.ts +12 -5
  5. package/@types/forms/fields/coordinates.d.ts +2 -2
  6. package/@types/forms/fields/date.d.ts +1 -2
  7. package/@types/forms/fields/datetime.d.ts +1 -2
  8. package/@types/forms/fields/deep-reverse-single-reference-list.d.ts +1 -1
  9. package/@types/forms/fields/deep-reverse-single-reference-table.d.ts +1 -2
  10. package/@types/forms/fields/enum-multiple-sealious.d.ts +1 -2
  11. package/@types/forms/fields/field.d.ts +6 -2
  12. package/@types/forms/fields/fields.d.ts +1 -0
  13. package/@types/forms/fields/file.d.ts +4 -3
  14. package/@types/forms/fields/int.d.ts +1 -2
  15. package/@types/forms/fields/json.d.ts +1 -2
  16. package/@types/forms/fields/phone-number-with-country-code.d.ts +1 -2
  17. package/@types/forms/fields/regexp.d.ts +1 -2
  18. package/@types/forms/fields/simple-form-field.d.ts +2 -3
  19. package/@types/forms/fields/single-reference.d.ts +2 -3
  20. package/@types/forms/fields/structured-array.d.ts +1 -2
  21. package/@types/forms/fields/structured.d.ts +19 -0
  22. package/@types/forms/fields/text.d.ts +1 -2
  23. package/@types/forms/fields/url.d.ts +1 -2
  24. package/lib/forms/controls/checkboxed-list-input.test.js +3 -3
  25. package/lib/forms/controls/field-group.js +3 -1
  26. package/lib/forms/controls/simple-input.js +6 -4
  27. package/lib/forms/fields/boolean.js +2 -6
  28. package/lib/forms/fields/collection-field.js +49 -5
  29. package/lib/forms/fields/coordinates.js +1 -5
  30. package/lib/forms/fields/date.js +1 -8
  31. package/lib/forms/fields/datetime.js +1 -8
  32. package/lib/forms/fields/deep-reverse-single-reference-list.js +1 -1
  33. package/lib/forms/fields/deep-reverse-single-reference-table.js +1 -1
  34. package/lib/forms/fields/enum-multiple-sealious.js +1 -5
  35. package/lib/forms/fields/field.js +17 -4
  36. package/lib/forms/fields/fields.js +1 -0
  37. package/lib/forms/fields/file.js +6 -6
  38. package/lib/forms/fields/int.js +1 -8
  39. package/lib/forms/fields/json.js +1 -5
  40. package/lib/forms/fields/phone-number-with-country-code.js +1 -5
  41. package/lib/forms/fields/regexp.js +1 -5
  42. package/lib/forms/fields/simple-form-field.js +6 -16
  43. package/lib/forms/fields/single-reference.js +2 -6
  44. package/lib/forms/fields/structured-array.js +1 -5
  45. package/lib/forms/fields/structured.js +107 -0
  46. package/lib/forms/fields/text.js +1 -5
  47. package/lib/forms/fields/url.js +2 -6
  48. package/lib/forms/form.js +2 -1
  49. package/lib/templates/shared/collection-create-form.js +4 -0
  50. package/lib/templates/shared/collection-edit-form.js +5 -0
  51. package/lib/utils/input-wrapper.js +2 -2
  52. package/package.json +3 -2
  53. package/src/forms/controls/checkboxed-list-input.test.ts +3 -3
  54. package/src/forms/controls/dropdown.ts +1 -1
  55. package/src/forms/controls/field-group.ts +9 -7
  56. package/src/forms/controls/simple-input.ts +19 -15
  57. package/src/forms/controls/textarea.ts +1 -1
  58. package/src/forms/fields/boolean.ts +2 -7
  59. package/src/forms/fields/collection-field.ts +88 -11
  60. package/src/forms/fields/coordinates.ts +3 -7
  61. package/src/forms/fields/date.ts +1 -11
  62. package/src/forms/fields/datetime.ts +1 -11
  63. package/src/forms/fields/deep-reverse-single-reference-list.ts +1 -1
  64. package/src/forms/fields/deep-reverse-single-reference-table.ts +1 -2
  65. package/src/forms/fields/enum-multiple-sealious.ts +1 -6
  66. package/src/forms/fields/field.ts +26 -6
  67. package/src/forms/fields/fields.ts +1 -0
  68. package/src/forms/fields/file.ts +9 -9
  69. package/src/forms/fields/int.ts +1 -11
  70. package/src/forms/fields/json.ts +2 -7
  71. package/src/forms/fields/phone-number-with-country-code.ts +3 -6
  72. package/src/forms/fields/regexp.ts +1 -6
  73. package/src/forms/fields/simple-form-field.ts +6 -22
  74. package/src/forms/fields/single-reference.ts +7 -10
  75. package/src/forms/fields/structured-array.ts +2 -7
  76. package/src/forms/fields/structured.ts +151 -0
  77. package/src/forms/fields/text.ts +1 -6
  78. package/src/forms/fields/url.ts +2 -9
  79. package/src/forms/form.ts +2 -1
  80. package/src/templates/shared/collection-create-form.ts +4 -0
  81. package/src/templates/shared/collection-edit-form.ts +5 -0
  82. package/src/utils/input-wrapper.ts +2 -2
@@ -15,10 +15,10 @@ export type DropdownOption = {
15
15
  label: string;
16
16
  };
17
17
  export declare class FreeformDropdown<ParsedValue> extends SimpleInput {
18
- field: FormField<boolean, ParsedValue | null>;
18
+ field: FormField<boolean, ParsedValue>;
19
19
  _generateOptions: (ctx: Context) => Promise<DropdownOption[]>;
20
20
  options: DropdownOptions;
21
- constructor(field: FormField<boolean, ParsedValue | null>, _generateOptions: (ctx: Context) => Promise<DropdownOption[]>, options?: DropdownOptions);
21
+ constructor(field: FormField<boolean, ParsedValue>, _generateOptions: (ctx: Context) => Promise<DropdownOption[]>, options?: DropdownOptions);
22
22
  generateOptions(ctx: Context): Promise<DropdownOption[]>;
23
23
  getInputAttributes(fctx: FormControlContext): Promise<Record<string, string | boolean>>;
24
24
  renderInput(ctx: Context, attributes_str: string, data: Record<string, FormDataValue>): Promise<FlatTemplatable>;
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,6 @@ import { Context } from "koa";
2
2
  import { Checkbox } from "../controls/checkbox.js";
3
3
  import { FormDataValue } from "../form-types.js";
4
4
  import { FieldParseResult, FormField } from "./field.js";
5
- import { FormControlContext } from "../controls/form-control.js";
6
5
  export declare class Boolean<Required extends boolean> extends FormField<Required, boolean, Checkbox> {
7
6
  error_message: string;
8
7
  predicate: (v: unknown, w: unknown) => {
@@ -17,6 +16,6 @@ export declare class Boolean<Required extends boolean> extends FormField<Require
17
16
  parse(_: Context, value: FormDataValue): Promise<FieldParseResult<boolean>>;
18
17
  getEmptyValue(): boolean;
19
18
  getControl(): Checkbox;
20
- getSealiousCreateValue(fctx: FormControlContext): Promise<boolean>;
19
+ parsedToSealious(value: boolean): Promise<boolean>;
21
20
  sealiousValueToForm(_: Context, value: boolean | null): Promise<FormDataValue>;
22
21
  }
@@ -1,22 +1,29 @@
1
1
  import { Context } from "koa";
2
- import { ExtractFieldDecoded, Field } from "sealious";
3
- import { SimpleInput } from "../controls/controls.js";
2
+ import { CollectionItem, ExtractFieldDecoded, ExtractFieldInput, Field as SealiousField } from "sealious";
3
+ import { FormControl } from "../controls/controls.js";
4
4
  import { FormDataValue } from "../form-types.js";
5
5
  import { FieldParseResult, FormField, FormFieldValidationResponse } from "./field.js";
6
6
  import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
7
- export declare class CollectionField<F extends Field<any>, Required extends boolean> extends FormField<Required, ExtractFieldDecoded<F> | null, SimpleInput> {
7
+ export declare function sealiousFieldToFormField(sealiousField: SealiousField<any>, field_name: string, prefix: string): FormField;
8
+ export declare class CollectionField<F extends SealiousField<any>, Required extends boolean> extends FormField<Required, ExtractFieldDecoded<F>, FormControl, ExtractFieldInput<F>> {
8
9
  sealiousField: F;
9
10
  constructor(required: Required, sealiousField: F);
10
11
  predicate: (v: unknown, w: unknown) => {
11
12
  readonly match: true;
12
13
  readonly wildcard: unknown;
13
14
  };
14
- parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<ExtractFieldDecoded<F> | null>>;
15
+ parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<ExtractFieldDecoded<F>>>;
15
16
  isValueValid(ctx: Context, value: ExtractFieldDecoded<F>): Promise<FormFieldValidationResponse>;
17
+ parsedToSealious(parsed: unknown): Promise<ExtractFieldInput<F>>;
16
18
  getEmptyValue(): ExtractFieldDecoded<F>;
17
- getControl(): SimpleInput;
19
+ sealiousValueToForm(ctx: Context, value: any, item: CollectionItem<any>): Promise<FormDataValue>;
20
+ getControl(): FormControl;
18
21
  generateFieldDeclaration(field_info: ExtractedFieldInfo, vars: {
19
22
  form_field_types: string;
20
23
  sealious_field: string;
21
24
  }): string;
25
+ generateInitialValue(field_info: ExtractedFieldInfo, vars: {
26
+ form_field_types: string;
27
+ form_fields: string;
28
+ }): string;
22
29
  }
@@ -1,12 +1,12 @@
1
1
  import { Context } from "koa";
2
- import { FormControl, FormControlContext } from "../controls/form-control.js";
2
+ import { FormControl } from "../controls/form-control.js";
3
3
  import { SimpleInput } from "../controls/simple-input.js";
4
4
  import { FormDataValue } from "../form-types.js";
5
5
  import { FieldParseResult } from "./field.js";
6
6
  import { SimpleFormField } from "./simple-form-field.js";
7
7
  export declare class Coordinates<Required extends boolean, DefaultControl extends FormControl = SimpleInput> extends SimpleFormField<Required, DefaultControl, [number, number]> {
8
8
  parse(_: Context, raw_value: FormDataValue): Promise<FieldParseResult<[number, number]>>;
9
- getSealiousCreateValue(fctx: FormControlContext): Promise<[number, number] | undefined>;
9
+ parsedToSealious(parsed: [number, number]): Promise<[number, number] | undefined>;
10
10
  postSealiousCreate(): Promise<void>;
11
11
  postSealiousEdit(): Promise<void>;
12
12
  getControl(): DefaultControl;
@@ -1,5 +1,4 @@
1
1
  import { Context } from "koa";
2
- import { FormControlContext } from "../controls/form-control.js";
3
2
  import { SimpleInput, SimpleInputOptions } from "../controls/simple-input.js";
4
3
  import { FormDataValue } from "../form-types.js";
5
4
  import { FieldParseResult } from "./field.js";
@@ -9,5 +8,5 @@ export declare class DateField<Required extends boolean> extends SimpleFormField
9
8
  getEmptyValue(): Date;
10
9
  parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<Date>>;
11
10
  getControl(): SimpleInput<SimpleInputOptions>;
12
- getSealiousCreateValue(fctx: FormControlContext): Promise<string | null>;
11
+ parsedToSealious(parsed: Date): Promise<string | null>;
13
12
  }
@@ -1,6 +1,5 @@
1
1
  import { Context } from "koa";
2
2
  import { SimpleInput } from "../controls/controls.js";
3
- import { FormControlContext } from "../controls/form-control.js";
4
3
  import { FormDataValue } from "../form-types.js";
5
4
  import { FieldParseResult } from "./field.js";
6
5
  import { SimpleFormField } from "./simple-form-field.js";
@@ -8,7 +7,7 @@ export declare class DateTime<Required extends boolean> extends SimpleFormField<
8
7
  constructor(required: Required);
9
8
  getEmptyValue(): Date | null;
10
9
  parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<Date | null>>;
11
- getSealiousCreateValue(fctx: FormControlContext): Promise<number | null>;
10
+ parsedToSealious(parsed: Date): Promise<number | null>;
12
11
  getControl(): SimpleInput;
13
12
  sealiousValueToForm(ctx: Context, value: number | null): Promise<FormDataValue>;
14
13
  }
@@ -8,7 +8,7 @@ export declare class DeepReverseSingleReferenceList extends CheckboxedListField<
8
8
  item_label_getter: (item: CollectionItem<any>) => string;
9
9
  constructor(sealious_field: SealiousFieldTypes.DeepReverseSingleReference);
10
10
  setItemLabelGetter(getter: (item: CollectionItem<any>) => string): void;
11
- getSealiousCreateValue(): never;
11
+ parsedToSealious(): never;
12
12
  postSealiousCreate(ctx: Context, created_item: CollectionItem<any>, form_data: FormData): Promise<void>;
13
13
  postSealiousEdit(ctx: Context, edited_item: CollectionItem<any>, value: FormData): Promise<void>;
14
14
  sealiousValueToForm(_ctx: Context, value: string[] | null): Promise<FormDataValue>;
@@ -3,13 +3,12 @@ import { Table } from "./table.js";
3
3
  import { Table as TableControl } from "../controls/table.js";
4
4
  import { Context } from "koa";
5
5
  import { FormDataValue, FormData } from "../form-types.js";
6
- import { FormControlContext } from "../controls/form-control.js";
7
6
  import { FormField } from "./field.js";
8
7
  export declare class DeepReverseSingleReferenceTable extends Table<Record<string, FormField>> {
9
8
  sealious_field: SealiousFieldTypes.DeepReverseSingleReference;
10
9
  constructor(sealious_field: SealiousFieldTypes.DeepReverseSingleReference);
11
10
  getControl(): TableControl<any>;
12
- getSealiousCreateValue(_fctx: FormControlContext): Promise<unknown>;
11
+ parsedToSealious(_value: any): Promise<unknown>;
13
12
  postSealiousCreate(ctx: Context, created_item: CollectionItem<any>, form_data: FormData): Promise<void>;
14
13
  postSealiousEdit(ctx: Context, edited_item: CollectionItem<any>, form_data: FormData): Promise<void>;
15
14
  sealiousValueToForm(ctx: Context, _value: string[], item: CollectionItem<any>): Promise<FormDataValue>;
@@ -2,7 +2,6 @@ import { FieldTypes as SealiousFieldTypes } from "sealious";
2
2
  import { Context } from "koa";
3
3
  import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
4
4
  import { CheckboxedListField } from "./checkboxed-list.js";
5
- import { FormControlContext } from "../controls/form-control.js";
6
5
  import { FormDataValue } from "../form-types.js";
7
6
  export declare class EnumMultipleSealious<Values extends string> extends CheckboxedListField<boolean, Values> {
8
7
  sealious_field: SealiousFieldTypes.EnumMultiple<Values>;
@@ -11,6 +10,6 @@ export declare class EnumMultipleSealious<Values extends string> extends Checkbo
11
10
  form_field_types: string;
12
11
  sealious_field: string;
13
12
  }): string;
14
- getSealiousCreateValue(fctx: FormControlContext): Promise<Values[]>;
13
+ parsedToSealious(parsed: Record<string, unknown>): Promise<Values[]>;
15
14
  sealiousValueToForm(ctx: Context, sealious_value: Values[] | null): Promise<FormDataValue>;
16
15
  }
@@ -32,6 +32,7 @@ export type FieldParseResult<T> = {
32
32
  export declare abstract class FormField<Required extends boolean = boolean, ParsedValue = any, DefaultFormControl extends FormControl = FormControl, SealiousValue = any> {
33
33
  readonly required: Required;
34
34
  name: string;
35
+ value_path: string | undefined;
35
36
  label: string;
36
37
  constructor(required: Required);
37
38
  predicate: Predicate;
@@ -41,6 +42,8 @@ export declare abstract class FormField<Required extends boolean = boolean, Pars
41
42
  setName(name: string): this;
42
43
  setDisabled(status: boolean): this;
43
44
  setLabel(label: string): this;
45
+ getValuePath(): string;
46
+ setValuePath(path: string): this;
44
47
  _validate(ctx: Context, value: ParsedValue): Promise<FormFieldValidationResponse>;
45
48
  abstract getEmptyValue(): ParsedValue;
46
49
  isValueValid(_ctx: Context, _value: ParsedValue): Promise<FormFieldValidationResponse>;
@@ -56,10 +59,11 @@ export declare abstract class FormField<Required extends boolean = boolean, Pars
56
59
  parsed: ParsedValue | null;
57
60
  raw: FormDataValue;
58
61
  }>;
59
- setMapToFilter(fn: (parsed: ParsedValue) => unknown): this;
62
+ setMapToFilter(fn: (parsed: ParsedValue | null) => unknown): this;
60
63
  getDatabaseValue(ctx: Context, data: Record<string, FormDataValue>): Promise<unknown>;
61
64
  abstract getControl(): DefaultFormControl;
62
- getSealiousCreateValue(fctx: FormControlContext): Promise<SealiousValue>;
65
+ getSealiousCreateValue(fctx: FormControlContext): never;
66
+ parsedToSealious(parsed: ParsedValue): any;
63
67
  sealiousValueToForm(ctx: Context, sealiousValue: SealiousValue | null, item: CollectionItem<any>): Promise<FormDataValue>;
64
68
  postSealiousCreate(ctx: Context, created_item: CollectionItem<any>, form_data: FormData): Promise<void>;
65
69
  postSealiousEdit(ctx: Context, edited_item: CollectionItem<any>, form_data: FormData): Promise<void>;
@@ -32,3 +32,4 @@ export * from "./structured-array.js";
32
32
  export * from "./table.js";
33
33
  export * from "./text.js";
34
34
  export * from "./url.js";
35
+ export * from "./structured.js";
@@ -3,7 +3,8 @@ import { FilePointer } from "@sealcode/file-manager";
3
3
  import { FormDataValue } from "../form-types.js";
4
4
  import { FieldParseResult, FormField } from "./field.js";
5
5
  import { File as FileControl } from "../controls/file.js";
6
- import { FormControl, FormControlContext } from "../controls/form-control.js";
6
+ import { FormControl } from "../controls/form-control.js";
7
+ import { ImageValue } from "sealious";
7
8
  export type FileContainer = {
8
9
  old: FilePointer | null;
9
10
  new: FilePointer | null;
@@ -18,8 +19,8 @@ export declare class File<Required extends boolean> extends FormField<Required,
18
19
  new: null;
19
20
  };
20
21
  getControl(): FileControl;
21
- getSealiousCreateValue(fctx: FormControlContext): Promise<FilePointer | undefined>;
22
- sealiousValueToForm(ctx: Context, sealiousValue: FilePointer | string | null): Promise<{
22
+ parsedToSealious(value: FileContainer): Promise<FilePointer | undefined>;
23
+ sealiousValueToForm(ctx: Context, sealiousValue: FilePointer | ImageValue | string | null): Promise<{
23
24
  old: FilePointer | undefined;
24
25
  } | Record<string, never>>;
25
26
  }
@@ -1,6 +1,5 @@
1
- import { FormControlContext } from "../controls/form-control.js";
2
1
  import { NumberBasedSimpleField } from "./simple-form-field.js";
3
2
  export declare class Int<Required extends boolean> extends NumberBasedSimpleField<Required> {
4
3
  constructor(required: Required);
5
- getSealiousCreateValue(fctx: FormControlContext): Promise<number | undefined>;
4
+ parsedToSealious(parsed: number): Promise<number | undefined>;
6
5
  }
@@ -1,5 +1,4 @@
1
1
  import { Context } from "koa";
2
- import { FormControlContext } from "../controls/form-control.js";
3
2
  import { Textarea } from "../controls/textarea.js";
4
3
  import { FormDataValue } from "../form-types.js";
5
4
  import { FieldParseResult } from "./field.js";
@@ -9,5 +8,5 @@ export declare class JSONField<Required extends boolean> extends SimpleFormField
9
8
  getControl(): Textarea;
10
9
  getEmptyValue(): Record<string, unknown>;
11
10
  parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<Record<string, unknown>>>;
12
- getSealiousCreateValue(fctx: FormControlContext): Promise<Record<string, unknown> | null>;
11
+ parsedToSealious(parsed: Record<string, unknown>): Promise<Record<string, unknown> | null>;
13
12
  }
@@ -3,11 +3,10 @@ import { FieldTypes as SealiousFieldTypes } from "sealious";
3
3
  import { FormControl } from "../controls/controls.js";
4
4
  import { FormDataValue } from "../form-types.js";
5
5
  import { FieldParseResult, FormField } from "./field.js";
6
- import { FormControlContext } from "../../index.js";
7
6
  export declare class PhoneNumberWithCountryCode<Required extends boolean> extends FormField<Required, SealiousFieldTypes.PhoneNumberValue> {
8
7
  getEmptyValue(): SealiousFieldTypes.PhoneNumberValue;
9
8
  parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<SealiousFieldTypes.PhoneNumberValue>>;
10
9
  getControl(): FormControl;
11
- getSealiousCreateValue(fctx: FormControlContext): Promise<string>;
10
+ parsedToSealious(parsed: SealiousFieldTypes.PhoneNumberValue): Promise<string>;
12
11
  sealiousValueToForm(ctx: Context, sealiousValue: SealiousFieldTypes.PhoneNumberValue | null): Promise<FormDataValue>;
13
12
  }
@@ -2,7 +2,6 @@ import { Context } from "koa";
2
2
  import { SimpleInput } from "../controls/simple-input.js";
3
3
  import { FormDataValue } from "../form-types.js";
4
4
  import { FieldParseResult, FormField } from "./field.js";
5
- import { FormControlContext } from "../controls/form-control.js";
6
5
  export declare class RegExpField<Required extends boolean> extends FormField<Required, string, SimpleInput, string> {
7
6
  regexp: RegExp;
8
7
  error_message: string;
@@ -16,6 +15,6 @@ export declare class RegExpField<Required extends boolean> extends FormField<Req
16
15
  parse(_: Context, value: FormDataValue): Promise<FieldParseResult<string>>;
17
16
  getEmptyValue(): string;
18
17
  getControl(): SimpleInput;
19
- getSealiousCreateValue(fctx: FormControlContext): Promise<string>;
18
+ parsedToSealious(parsed: string): Promise<string>;
20
19
  sealiousValueToForm(ctx: Context, sealious_value: string | null): Promise<FormDataValue>;
21
20
  }
@@ -4,7 +4,6 @@ import { FieldParseResult, FormField } from "./field.js";
4
4
  import { SimpleInput } from "../controls/simple-input.js";
5
5
  import { FormControl } from "../controls/controls.js";
6
6
  import { CollectionItem } from "sealious";
7
- import { FormControlContext } from "../controls/form-control.js";
8
7
  export declare abstract class SimpleFormField<Required extends boolean, DefaultControl extends FormControl = SimpleInput, Parsed = string> extends FormField<Required, Parsed, DefaultControl> {
9
8
  type: string;
10
9
  predicate: import("@sealcode/ts-predicates").Predicate<string>;
@@ -15,7 +14,7 @@ export declare abstract class SimpleFormField<Required extends boolean, DefaultC
15
14
  }
16
15
  export declare class TextBasedSimpleField<Required extends boolean, DefaultControl extends FormControl = SimpleInput> extends SimpleFormField<Required, DefaultControl, string | null> {
17
16
  parse(_: Context, raw_value: FormDataValue): Promise<FieldParseResult<string>>;
18
- getSealiousCreateValue(fctx: FormControlContext): Promise<string | null>;
17
+ parsedToSealious(value: string): Promise<string>;
19
18
  postSealiousCreate(_ctx: Context, _created_item: CollectionItem<any>, _formData: FormData): Promise<void>;
20
19
  postSealiousEdit(_ctx: Context, _edited_item: CollectionItem<any>, _formData: FormData): Promise<void>;
21
20
  getControl(): DefaultControl;
@@ -23,7 +22,7 @@ export declare class TextBasedSimpleField<Required extends boolean, DefaultContr
23
22
  }
24
23
  export declare class NumberBasedSimpleField<Required extends boolean, DefaultControl extends FormControl = SimpleInput> extends SimpleFormField<Required, DefaultControl, number> {
25
24
  parse(_: Context, raw_value: FormDataValue): Promise<FieldParseResult<number>>;
26
- getSealiousCreateValue(fctx: FormControlContext): Promise<number | undefined>;
25
+ parsedToSealious(value: number): Promise<number | undefined>;
27
26
  postSealiousCreate(): Promise<void>;
28
27
  postSealiousEdit(): Promise<void>;
29
28
  getControl(): DefaultControl;
@@ -1,12 +1,11 @@
1
- import { Collection, FieldTypes as SealiousFieldTypes } from "sealious";
1
+ import { Collection, ExtractFieldInput, FieldTypes as SealiousFieldTypes } from "sealious";
2
2
  import { CollectionField } from "./collection-field.js";
3
3
  import { SingleReferenceDropdown } from "../controls/single-reference.js";
4
- import { FormControlContext } from "../controls/form-control.js";
5
4
  import { Context } from "koa";
6
5
  import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
7
6
  export declare class SingleReference<TargetCollection extends Collection, Required extends boolean, F extends SealiousFieldTypes.SingleReference> extends CollectionField<F, Required> {
8
7
  getControl(): SingleReferenceDropdown<TargetCollection, F, Required>;
9
- getSealiousCreateValue(fctx: FormControlContext): Promise<string | undefined>;
8
+ parsedToSealious(parsed: string): Promise<ExtractFieldInput<F>>;
10
9
  sealiousValueToForm(_ctx: Context, value: string | null): Promise<string | undefined>;
11
10
  generateImportsForFieldList(field_info: ExtractedFieldInfo): {
12
11
  what: string;
@@ -3,7 +3,6 @@ import { Field as SealiousField, FieldTypes as SealiousFieldTypes } from "sealio
3
3
  import { FormDataValue } from "../form-types.js";
4
4
  import { Table as TableControl } from "../controls/table.js";
5
5
  import { SealiousToFormField } from "./get-field-for-sealious.js";
6
- import { FormControlContext } from "../controls/form-control.js";
7
6
  import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
8
7
  import { Table } from "./table.js";
9
8
  export declare class StructuredArray<SealiousFields extends Record<string, SealiousField<unknown>>> extends Table<{
@@ -18,6 +17,6 @@ export declare class StructuredArray<SealiousFields extends Record<string, Seali
18
17
  form_field_types: string;
19
18
  sealious_field: string;
20
19
  }): string;
21
- getSealiousCreateValue(fctx: FormControlContext): Promise<import("./table.js").TableFieldParsed<{ [name in keyof SealiousFields]: SealiousToFormField<SealiousFields[name]>; }>>;
20
+ parsedToSealious(parsed: any): Promise<any>;
22
21
  sealiousValueToForm(ctx: Context, sealiousValue: Record<string, FormDataValue | null>[] | null): Promise<FormDataValue>;
23
22
  }
@@ -0,0 +1,19 @@
1
+ import { CollectionItem, ExtractFieldDecoded, ExtractFieldInput, Field as SealiousField, FieldTypes as SealiousFieldTypes } from "sealious";
2
+ import { FieldParseResult, FormField } from "./field.js";
3
+ import { FieldGroup, FormControl } from "../controls/controls.js";
4
+ import { Context } from "koa";
5
+ import { FormDataValue } from "../form-types.js";
6
+ import { ExtractedFieldInfo } from "../../utils/extract-fields-from-collection.js";
7
+ export declare class StructuredSealiousField<Structure extends Record<string, SealiousField<any>>, F extends SealiousFieldTypes.Structured<Structure>> extends FormField<false, ExtractFieldDecoded<F>, FormControl, ExtractFieldInput<F>> {
8
+ sealiousField: F;
9
+ constructor(sealiousField: F);
10
+ getEmptyValue(): ExtractFieldDecoded<F>;
11
+ parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<ExtractFieldDecoded<F>>>;
12
+ parsedToSealious(parsed: Record<string, unknown> | null): Promise<any>;
13
+ sealiousValueToForm(ctx: Context, sealiousValue: ExtractFieldDecoded<F> | ExtractFieldInput<F> | null, item: CollectionItem<any>): Promise<FormDataValue>;
14
+ getControl(): FieldGroup;
15
+ generateFieldDeclaration(_field_info: ExtractedFieldInfo, vars: {
16
+ form_field_types: string;
17
+ sealious_field: string;
18
+ }): string;
19
+ }
@@ -1,6 +1,5 @@
1
- import { FormControlContext } from "../controls/form-control.js";
2
1
  import { TextBasedSimpleField } from "./simple-form-field.js";
3
2
  export declare class Text<Required extends boolean> extends TextBasedSimpleField<Required> {
4
3
  constructor(required: Required);
5
- getSealiousCreateValue(fctx: FormControlContext): Promise<string>;
4
+ parsedToSealious(parsed: string): Promise<string>;
6
5
  }
@@ -1,6 +1,5 @@
1
- import { FormControlContext } from "../controls/form-control.js";
2
1
  import { TextBasedSimpleField } from "./simple-form-field.js";
3
2
  export declare class URLField<Required extends boolean> extends TextBasedSimpleField<Required> {
4
3
  constructor(required: Required);
5
- getSealiousCreateValue(fctx: FormControlContext): Promise<string | null>;
4
+ parsedToSealious(parsed: string | null): Promise<string>;
6
5
  }
@@ -54,8 +54,8 @@ describe("checkboxed-list", () => {
54
54
  const context = await browser.newContext();
55
55
  page = await context.newPage();
56
56
  await page.goto(`http://localhost:${port}`);
57
- await page.getByLabel("CO").check();
58
- await page.getByLabel("DE").check();
57
+ await page.getByLabel("CO", { exact: true }).check();
58
+ await page.getByLabel("DE", { exact: true }).check();
59
59
  await page.getByRole("button", { name: "Wy\u015Blij" }).click();
60
60
  assert.deepStrictEqual(received_values, { syllables: { co: "on", de: "on" } });
61
61
  });
@@ -186,7 +186,7 @@ describe("checkboxed-list", () => {
186
186
  const context = await browser.newContext();
187
187
  page = await context.newPage();
188
188
  await page.goto(`http://localhost:${port}`);
189
- await page.getByLabel("DE").check();
189
+ await page.getByLabel("DE", { exact: true }).check();
190
190
  await page.getByRole("button", { name: "Wy\u015Blij" }).click();
191
191
  await sleep(100);
192
192
  assert(submit_called);
@@ -28,7 +28,9 @@ class FieldGroup extends FormFieldControl {
28
28
  const { label, classes } = this.options;
29
29
  return tempstream`
30
30
  <div
31
- class="field-group ${(classes || []).join(" ")}"
31
+ class="field-group form-input__wrapper ${(classes || []).join(
32
+ " "
33
+ )}"
32
34
  ${this.options.containerID ? `id="${this.options.containerID}"` : ""}
33
35
  >
34
36
  ${this.preLabelContainer()}
@@ -81,17 +81,19 @@ class SimpleInput extends FormFieldControl {
81
81
  this.getWrapperModifiers(),
82
82
  tempstream`
83
83
  ${label ? `<label for="${id}">${label}</label>` : ""}
84
- ${await this.preInput(fctx, fctx.data.raw_values)}
85
- ${this.renderInput(
84
+ <div class="simple-input__inner-wrapper">
85
+ ${await this.preInput(fctx, fctx.data.raw_values)}
86
+ ${this.renderInput(
86
87
  fctx.ctx,
87
88
  renderAttributes(await this.getInputAttributes(fctx)),
88
89
  fctx.data.raw_values
89
90
  )}
90
- ${this.postInput(fctx.ctx)}
91
- ${~valid && !this.options.hide_errors && fctx.validate ? `<div class="input__error">${[
91
+ ${this.postInput(fctx.ctx)}
92
+ ${~valid && !this.options.hide_errors && fctx.validate ? `<div class="input__error">${[
92
93
  message,
93
94
  fctx.data.field_messages?.[this.field.name]?.message
94
95
  ].filter((e) => !!e).join(" \xB7 ")}</div>` : ""}
96
+ </div>
95
97
  `
96
98
  );
97
99
  }
@@ -46,12 +46,8 @@ class Boolean extends FormField {
46
46
  getControl() {
47
47
  return new Checkbox(this, { label: this.label || this.name });
48
48
  }
49
- async getSealiousCreateValue(fctx) {
50
- const { parsed } = await this.getParsedValue(
51
- fctx.ctx,
52
- fctx.data.raw_values
53
- );
54
- return !!parsed;
49
+ async parsedToSealious(value) {
50
+ return !!value;
55
51
  }
56
52
  async sealiousValueToForm(_, value) {
57
53
  return value ? "true" : "false";
@@ -1,8 +1,30 @@
1
1
  import { predicates } from "@sealcode/ts-predicates";
2
- import { SimpleInput } from "../controls/controls.js";
2
+ import {
3
+ FieldTypes as SealiousFieldTypes
4
+ } from "sealious";
3
5
  import {
4
6
  FormField
5
7
  } from "./field.js";
8
+ import { TextBasedSimpleField } from "./simple-form-field.js";
9
+ import { Image as ImageField } from "./image.js";
10
+ import { wrapAttribute, wrapKeyName } from "../../utils/wrap-attributes.js";
11
+ import { StructuredSealiousField } from "./structured.js";
12
+ function sealiousFieldToFormField(sealiousField, field_name, prefix) {
13
+ const name = prefix ? `${prefix}[${field_name}]` : field_name;
14
+ let formfield = new TextBasedSimpleField(false);
15
+ if (sealiousField instanceof SealiousFieldTypes.Image) {
16
+ formfield = new ImageField(false);
17
+ }
18
+ if (sealiousField instanceof SealiousFieldTypes.Structured) {
19
+ formfield = new StructuredSealiousField(sealiousField);
20
+ }
21
+ formfield.setName(name);
22
+ formfield.setLabel(field_name);
23
+ if (prefix) {
24
+ formfield.setValuePath(prefix + "." + field_name);
25
+ }
26
+ return formfield;
27
+ }
6
28
  class CollectionField extends FormField {
7
29
  constructor(required, sealiousField) {
8
30
  super(required);
@@ -11,7 +33,7 @@ class CollectionField extends FormField {
11
33
  }
12
34
  async parse(ctx, raw_value) {
13
35
  if (raw_value === void 0) {
14
- return { parsable: true, parsed_value: null, error: null };
36
+ return { parsable: true, parsed_value: {}, error: null };
15
37
  }
16
38
  const encoded_value = await this.sealiousField.encode(
17
39
  ctx.$context,
@@ -31,26 +53,48 @@ class CollectionField extends FormField {
31
53
  async isValueValid(ctx, value) {
32
54
  const { valid, reason } = await this.sealiousField.checkValue(
33
55
  ctx.$context,
34
- value,
56
+ this.parsedToSealious(value),
35
57
  void 0,
36
58
  null,
37
59
  void 0
38
60
  );
39
61
  return { valid, message: reason || (!valid ? "Wrong value" : "") };
40
62
  }
63
+ async parsedToSealious(parsed) {
64
+ return sealiousFieldToFormField(
65
+ this.sealiousField,
66
+ this.name,
67
+ ""
68
+ ).parsedToSealious(parsed);
69
+ }
41
70
  getEmptyValue() {
42
71
  return "";
43
72
  }
73
+ async sealiousValueToForm(ctx, value, item) {
74
+ return sealiousFieldToFormField(
75
+ this.sealiousField,
76
+ this.name,
77
+ ""
78
+ ).sealiousValueToForm(ctx, value, item);
79
+ }
44
80
  getControl() {
45
- return new SimpleInput(this);
81
+ return sealiousFieldToFormField(
82
+ this.sealiousField,
83
+ this.name,
84
+ ""
85
+ ).getControl();
46
86
  }
47
87
  generateFieldDeclaration(field_info, vars) {
48
88
  return `new ${vars.form_field_types}.${this.constructor.name}(${String(
49
89
  field_info.is_required
50
90
  )}, ${vars.sealious_field})`;
51
91
  }
92
+ generateInitialValue(field_info, vars) {
93
+ return `${wrapKeyName(field_info.name)}: await ${vars.form_fields}${wrapAttribute(field_info.name)}.sealiousValueToForm(ctx, item.get("${field_info.name}"), item)`;
94
+ }
52
95
  }
53
96
  export {
54
- CollectionField
97
+ CollectionField,
98
+ sealiousFieldToFormField
55
99
  };
56
100
  //# sourceMappingURL=collection-field.js.map
@@ -22,11 +22,7 @@ class Coordinates extends SimpleFormField {
22
22
  error: "should be an array or string"
23
23
  };
24
24
  }
25
- async getSealiousCreateValue(fctx) {
26
- const { parsed } = await this.getParsedValue(
27
- fctx.ctx,
28
- fctx.data.raw_values
29
- );
25
+ async parsedToSealious(parsed) {
30
26
  return parsed || void 0;
31
27
  }
32
28
  async postSealiousCreate() {
@@ -20,14 +20,7 @@ class DateField extends SimpleFormField {
20
20
  type: this.type
21
21
  });
22
22
  }
23
- async getSealiousCreateValue(fctx) {
24
- const { parsed } = await this.getParsedValue(
25
- fctx.ctx,
26
- fctx.data.raw_values
27
- );
28
- if (!parsed) {
29
- return null;
30
- }
23
+ async parsedToSealious(parsed) {
31
24
  return `${parsed.getFullYear()}-${(parsed.getMonth() + 1).toString().padStart(2, "0")}-${parsed.getDate().toString().padStart(2, "0")}`;
32
25
  }
33
26
  }
@@ -14,14 +14,7 @@ class DateTime extends SimpleFormField {
14
14
  const parsed_value = new Date(raw_value);
15
15
  return { parsable: true, error: null, parsed_value };
16
16
  }
17
- async getSealiousCreateValue(fctx) {
18
- const { parsed } = await this.getParsedValue(
19
- fctx.ctx,
20
- fctx.data.raw_values
21
- );
22
- if (parsed == null) {
23
- return null;
24
- }
17
+ async parsedToSealious(parsed) {
25
18
  return new Date(parsed).getTime();
26
19
  }
27
20
  getControl() {
@@ -15,7 +15,7 @@ class DeepReverseSingleReferenceList extends CheckboxedListField {
15
15
  setItemLabelGetter(getter) {
16
16
  this.item_label_getter = getter;
17
17
  }
18
- getSealiousCreateValue() {
18
+ parsedToSealious() {
19
19
  throw new Error(
20
20
  "This field is not set directly through field value, but instead relies on postSealiousCreate and postSealiousEdit"
21
21
  );
@@ -52,7 +52,7 @@ class DeepReverseSingleReferenceTable extends Table {
52
52
  }
53
53
  });
54
54
  }
55
- getSealiousCreateValue(_fctx) {
55
+ parsedToSealious(_value) {
56
56
  throw new Error("Method not implemented.");
57
57
  }
58
58
  async postSealiousCreate(ctx, created_item, form_data) {
@@ -12,11 +12,7 @@ class EnumMultipleSealious extends CheckboxedListField {
12
12
  generateFieldDeclaration(field_info, vars) {
13
13
  return `new ${vars.form_field_types}.${this.constructor.name}(${vars.sealious_field})`;
14
14
  }
15
- async getSealiousCreateValue(fctx) {
16
- const { parsed } = await this.getParsedValue(
17
- fctx.ctx,
18
- fctx.data.raw_values
19
- );
15
+ async parsedToSealious(parsed) {
20
16
  const result = Object.entries(parsed || {}).filter(([, value]) => value == "on").map(([key]) => key);
21
17
  return result;
22
18
  }