@sealcode/sealgen 0.19.5 → 0.19.7

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 (66) hide show
  1. package/@types/forms/fields/field.d.ts +1 -0
  2. package/@types/forms/fields/fields.d.ts +2 -1
  3. package/@types/forms/fields/get-field-for-sealious.d.ts +2 -1
  4. package/@types/forms/fields/hybrid.d.ts +11 -0
  5. package/@types/forms/fields/item-draft.d.ts +20 -0
  6. package/@types/forms/form.d.ts +1 -0
  7. package/@types/forms/multiform.d.ts +2 -2
  8. package/@types/page/list.d.ts +5 -4
  9. package/@types/page/mountable-with-fields.d.ts +9 -2
  10. package/@types/page/mountable.d.ts +1 -1
  11. package/@types/page/page.d.ts +1 -1
  12. package/@types/templates/form.d.ts +2 -2
  13. package/lib/forms/controls/checkboxed-list-input.test.js +16 -12
  14. package/lib/forms/controls/file.test.js +2 -2
  15. package/lib/forms/controls/image.test.js +4 -4
  16. package/lib/forms/controls/single-reference.test.js +2 -2
  17. package/lib/forms/fields/field.test.js +9 -6
  18. package/lib/forms/fields/fields.js +2 -1
  19. package/lib/forms/fields/file.test.js +2 -2
  20. package/lib/forms/fields/get-field-for-sealious.js +6 -0
  21. package/lib/forms/fields/hybrid.js +37 -0
  22. package/lib/forms/fields/item-draft.js +34 -0
  23. package/lib/forms/form.js +11 -5
  24. package/lib/forms/form.test.js +9 -9
  25. package/lib/forms/multiform.js +7 -4
  26. package/lib/forms/multiform.test.js +7 -7
  27. package/lib/mount.js +4 -1
  28. package/lib/page/list.js +9 -6
  29. package/lib/page/mountable-with-fields.js +16 -1
  30. package/lib/page/mountable-with-fields.test.js +2 -2
  31. package/lib/page/mountable.js +1 -1
  32. package/lib/page/page.js +1 -1
  33. package/lib/templates/form.js +9 -18
  34. package/lib/templates/shared/collection-create-form.js +8 -8
  35. package/lib/templates/shared/collection-edit-form.js +9 -9
  36. package/lib/templates/shared/collection-list.js +2 -1
  37. package/lib/templates/shared/shared-crud-form-fields.js +4 -4
  38. package/lib/utils/extract-fields-from-collection.js +3 -0
  39. package/package.json +1 -1
  40. package/src/forms/controls/checkboxed-list-input.test.ts +16 -12
  41. package/src/forms/controls/file.test.ts +2 -2
  42. package/src/forms/controls/image.test.ts +4 -4
  43. package/src/forms/controls/single-reference.test.ts +2 -2
  44. package/src/forms/fields/field.test.ts +9 -6
  45. package/src/forms/fields/field.ts +5 -6
  46. package/src/forms/fields/fields.ts +2 -1
  47. package/src/forms/fields/file.test.ts +2 -2
  48. package/src/forms/fields/get-field-for-sealious.ts +8 -0
  49. package/src/forms/fields/hybrid.ts +47 -0
  50. package/src/forms/fields/item-draft.ts +44 -0
  51. package/src/forms/form.test.ts +15 -15
  52. package/src/forms/form.ts +34 -26
  53. package/src/forms/multiform.test.ts +7 -7
  54. package/src/forms/multiform.ts +10 -7
  55. package/src/mount.ts +11 -7
  56. package/src/page/list.ts +33 -28
  57. package/src/page/mountable-with-fields.test.ts +2 -2
  58. package/src/page/mountable-with-fields.ts +26 -5
  59. package/src/page/mountable.ts +1 -1
  60. package/src/page/page.ts +1 -1
  61. package/src/templates/form.ts +9 -18
  62. package/src/templates/shared/collection-create-form.ts +8 -8
  63. package/src/templates/shared/collection-edit-form.ts +9 -9
  64. package/src/templates/shared/collection-list.ts +5 -4
  65. package/src/templates/shared/shared-crud-form-fields.ts +5 -5
  66. package/src/utils/extract-fields-from-collection.ts +3 -0
@@ -12,12 +12,12 @@ export async function editItemFormTemplate(
12
12
  ): Promise<string> {
13
13
  const collection_fields =
14
14
  await extract_fields_from_collection(collection_name);
15
- const formFieldsVar = `${toPascalCase(collection_name)}FormFields`;
15
+ const formFieldsGetterVar = `get${toPascalCase(collection_name)}FormFields`;
16
16
  const collectionVar = `${toPascalCase(collection_name)}`;
17
17
 
18
18
  return formTemplate(edit_action_name, {
19
19
  success_message: "Changes saved!",
20
- postimport: `import {${formFieldsVar}, get${toPascalCase(
20
+ postimport: `import {${formFieldsGetterVar}, get${toPascalCase(
21
21
  collection_name
22
22
  )}FormControls }from "../shared.js";
23
23
  import { ${collectionVar} } from "src/back/collections/collections.js";
@@ -27,12 +27,12 @@ export async function editItemFormTemplate(
27
27
  import type { CollectionInputWithAllKeys } from "sealious";
28
28
  `,
29
29
 
30
- fields: `...${toPascalCase(collection_name)}FormFields`,
31
- controls: `
30
+ get_fields: formFieldsGetterVar,
31
+ get_controls: `(fields: ReturnType<typeof getFields>)=>[
32
32
  new Controls.FormHeader("Edit ${toPascalCase(
33
33
  collection_name
34
34
  )}"),
35
- ...get${toPascalCase(collection_name)}FormControls()`,
35
+ ...get${toPascalCase(collection_name)}FormControls(fields)]`,
36
36
 
37
37
  can_access: `canAccess = async (ctx: Context) => {
38
38
  const policy = ${toPascalCase(collection_name)}.getPolicy("edit");
@@ -67,7 +67,7 @@ export async function editItemFormTemplate(
67
67
  sealious_field: `${collectionVar}.fields${wrapAttribute(
68
68
  field_info.name
69
69
  )}`,
70
- form_fields: "fields",
70
+ form_fields: "this.fields",
71
71
  }
72
72
  )
73
73
  )
@@ -77,7 +77,7 @@ export async function editItemFormTemplate(
77
77
 
78
78
  await item.save(ctx.$context);
79
79
 
80
- for(const field of Object.values(${formFieldsVar})){
80
+ for(const field of Object.values(this.fields)){
81
81
  // eslint-disable-next-line no-await-in-loop
82
82
  await field.postSealiousEdit(ctx, item, formData)
83
83
  }
@@ -95,7 +95,7 @@ export async function editItemFormTemplate(
95
95
  }
96
96
  `,
97
97
 
98
- get_initial_values: `async getInitialValues(ctx: Context): Promise<{ [key in keyof typeof fields]: FormDataValue | undefined }> {
98
+ get_initial_values: `async getInitialValues(ctx: Context): Promise<{ [key in keyof typeof this.fields]: FormDataValue | undefined }> {
99
99
  const id = await this.getID(ctx);
100
100
 
101
101
  const {
@@ -116,7 +116,7 @@ export async function editItemFormTemplate(
116
116
  .map((field_info) =>
117
117
  field_info.form_field.generateInitialValue(field_info, {
118
118
  form_field_types: "FieldTypes",
119
- form_fields: "fields",
119
+ form_fields: "this.fields",
120
120
  })
121
121
  )
122
122
  .join(",\n")}
@@ -25,9 +25,9 @@ export function makeDefaultFilterFields(
25
25
  .map((field) => {
26
26
  const type = field.type;
27
27
  return `{ field: "${field.name}", ...${
28
- type in DefaultListFilters
29
- ? `DefaultListFilters["${field.type}"]`
30
- : `DefaultListFilters.fallback`
28
+ type in DefaultListFilters ?
29
+ `DefaultListFilters["${field.type}"]`
30
+ : `DefaultListFilters.fallback`
31
31
  } }`;
32
32
  })
33
33
  .join(",\n");
@@ -148,7 +148,8 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
148
148
  typeof ${uppercase_collection},
149
149
  typeof BaseListPageFields
150
150
  > {
151
- fields = BaseListPageFields;
151
+ getFields = ()=>BaseListPageFields;
152
+ getControls = ()=>[];
152
153
 
153
154
  async renderFilters(ctx: Context): Promise<FlatTemplatable> {
154
155
  const query_params = qs.parse(ctx.search.slice(1));
@@ -19,13 +19,13 @@ ${Array.from(
19
19
  )
20
20
  .flat()
21
21
  .map(
22
- ({ what, from, as }) =>
23
- `import {${what}${as ? ` as ${as}` : ""} } from "${from}"`
22
+ ({ what, from, as, type }) =>
23
+ `import ${type ? "type " : ""}{${what}${as ? ` as ${as}` : ""} } from "${from}"`
24
24
  )
25
25
  ).values()
26
26
  ).join(";\n")}
27
27
 
28
- export const ${toPascalCase(collection_name)}FormFields = <const>{
28
+ export const get${toPascalCase(collection_name)}FormFields = () => <const>{
29
29
  ${collection_fields
30
30
  .map((field_info) => {
31
31
  return `${
@@ -40,11 +40,11 @@ export const ${toPascalCase(collection_name)}FormFields = <const>{
40
40
  .join(",\n")}
41
41
  };
42
42
 
43
- const fields = ${toPascalCase(collection_name)}FormFields
43
+ const getFields = get${toPascalCase(collection_name)}FormFields
44
44
 
45
45
  export const get${toPascalCase(
46
46
  collection_name
47
- )}FormControls: () => Controls.FormControl[] = () => [
47
+ )}FormControls: (fields: ReturnType<typeof getFields>) => Controls.FormControl[] = (fields) => [
48
48
  ${collection_fields
49
49
  .map(({ name }) => `fields${wrapAttribute(name)}.getControl()`)
50
50
  .join(",\n")}
@@ -61,6 +61,9 @@ for (const field_name in c.fields){
61
61
  }
62
62
  if(type == "single-reference"){
63
63
  target = field.target_collection;
64
+ }
65
+ if(type == "item-draft"){
66
+ target = field.target_collection_name;
64
67
  }
65
68
  if(type == "deep-reverse-single-reference" || type =="reverse-single-reference"){
66
69
  target = field.target_collection;