@sealcode/sealgen 0.18.8 → 0.19.0
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/.eslintrc.cjs +7 -2
- package/.xunit +75 -0
- package/@types/add-crud.d.sync-conflict-20250918-184311-TFDLWFG.ts +1 -0
- package/@types/builders/colors-builder.d.sync-conflict-20250918-184323-TFDLWFG.ts +10 -0
- package/@types/builders/colors-builder.d.ts +1 -1
- package/@types/builders/fonts-builder.d.sync-conflict-20250918-184322-TFDLWFG.ts +7 -0
- package/@types/builders/fonts-builder.d.ts +1 -1
- package/@types/controllers/table-add-button.d.ts +6 -0
- package/@types/controllers/table-add-button.stimulus.d.ts +6 -0
- package/@types/crud-field-snippets.d.sync-conflict-20250918-184323-TFDLWFG.ts +1 -0
- package/@types/crud-field-snippets.d.ts +1 -3
- package/@types/forms/controls/array.d.sync-conflict-20250918-184306-TFDLWFG.ts +33 -0
- package/@types/forms/controls/array.d.ts +1 -2
- package/@types/forms/controls/array.sync-conflict-20250918-222045-TFDLWFG.d.ts +33 -0
- package/@types/forms/controls/autocomplete.d.sync-conflict-20250918-222042-TFDLWFG.ts +22 -0
- package/@types/forms/controls/autocomplete.d.ts +1 -1
- package/@types/forms/controls/checkbox-group.d.sync-conflict-20250918-184319-TFDLWFG.ts +21 -0
- package/@types/forms/controls/checkbox-group.d.ts +3 -3
- package/@types/forms/controls/checkboxed-list-input.d.sync-conflict-20250918-184323-TFDLWFG.ts +21 -0
- package/@types/forms/controls/checkboxed-list-input.d.ts +3 -3
- package/@types/forms/controls/controls.d.ts +2 -2
- package/@types/forms/controls/derived-frame.d.sync-conflict-20250918-184314-TFDLWFG.ts +19 -0
- package/@types/forms/controls/derived-frame.d.ts +0 -1
- package/@types/forms/controls/dropdown.d.sync-conflict-20250918-222044-TFDLWFG.ts +30 -0
- package/@types/forms/controls/dropdown.d.ts +1 -1
- package/@types/forms/controls/file.d.sync-conflict-20250918-222045-TFDLWFG.ts +13 -0
- package/@types/forms/controls/file.d.ts +1 -2
- package/@types/forms/controls/form-control.d.sync-conflict-20250918-184322-TFDLWFG.ts +19 -0
- package/@types/forms/controls/form-control.d.sync-conflict-20250918-222046-TFDLWFG.ts +19 -0
- package/@types/forms/controls/form-control.d.ts +7 -3
- package/@types/forms/controls/image.d.ts +19 -0
- package/@types/forms/controls/image.test.d.ts +1 -0
- package/@types/forms/controls/multiple-files.d.sync-conflict-20250918-184318-TFDLWFG.ts +42 -0
- package/@types/forms/controls/multiple-files.d.ts +3 -0
- package/@types/forms/controls/multiple-images.d.ts +19 -0
- package/@types/forms/controls/number.d.sync-conflict-20250918-222046-TFDLWFG.ts +13 -0
- package/@types/forms/controls/number.d.ts +1 -1
- package/@types/forms/controls/photo.d.sync-conflict-20250918-184321-TFDLWFG.ts +19 -0
- package/@types/forms/controls/photo.d.ts +3 -5
- package/@types/forms/controls/simple-input.d.sync-conflict-20250918-184310-TFDLWFG.ts +33 -0
- package/@types/forms/controls/simple-input.d.sync-conflict-20250918-222042-TFDLWFG.ts +33 -0
- package/@types/forms/controls/simple-input.d.ts +5 -4
- package/@types/forms/controls/simple-input.sync-conflict-20250918-222045-TFDLWFG.d.ts +33 -0
- package/@types/forms/controls/single-reference.d.ts +3 -2
- package/@types/forms/controls/table.d.sync-conflict-20250918-184302-TFDLWFG.ts +39 -0
- package/@types/forms/controls/table.d.ts +8 -2
- package/@types/forms/controls/table.sync-conflict-20250918-222042-TFDLWFG.d.ts +39 -0
- package/@types/forms/controls/textarea.d.sync-conflict-20250918-222045-TFDLWFG.ts +25 -0
- package/@types/forms/controls/textarea.d.ts +3 -3
- package/@types/forms/fields/boolean.d.sync-conflict-20250918-184325-TFDLWFG.ts +22 -0
- package/@types/forms/fields/boolean.d.ts +6 -1
- package/@types/forms/fields/boolean.sync-conflict-20250918-222042-TFDLWFG.d.ts +22 -0
- package/@types/forms/fields/checkboxed-list.d.sync-conflict-20250918-184325-TFDLWFG.ts +23 -0
- package/@types/forms/fields/checkboxed-list.d.ts +3 -1
- package/@types/forms/fields/collection-field.d.sync-conflict-20250918-184319-TFDLWFG.ts +22 -0
- package/@types/forms/fields/collection-field.d.sync-conflict-20250918-222047-TFDLWFG.ts +22 -0
- package/@types/forms/fields/collection-field.d.ts +8 -1
- package/@types/forms/fields/color.d.ts +4 -0
- package/@types/forms/fields/coordinates.d.sync-conflict-20250918-222044-TFDLWFG.ts +14 -0
- package/@types/forms/fields/coordinates.d.ts +14 -0
- package/@types/forms/fields/date.d.ts +13 -0
- package/@types/forms/fields/datetime.d.sync-conflict-20250918-222050-TFDLWFG.ts +4 -0
- package/@types/forms/fields/datetime.d.ts +14 -0
- package/@types/forms/fields/deep-reverse-single-reference-list.d.ts +24 -0
- package/@types/forms/fields/deep-reverse-single-reference-table.d.ts +16 -0
- package/@types/forms/fields/email.d.sync-conflict-20250918-184303-TFDLWFG.ts +8 -0
- package/@types/forms/fields/email.d.ts +3 -0
- package/@types/forms/fields/enum-multiple-sealious.d.ts +16 -0
- package/@types/forms/fields/enum-multiple-sealious.sync-conflict-20250918-222047-TFDLWFG.d.ts +16 -0
- package/@types/forms/fields/field.d.sync-conflict-20250918-184306-TFDLWFG.ts +70 -0
- package/@types/forms/fields/field.d.ts +37 -5
- package/@types/forms/fields/fields.d.sync-conflict-20250918-184314-TFDLWFG.ts +29 -0
- package/@types/forms/fields/fields.d.ts +23 -8
- package/@types/forms/fields/file.d.sync-conflict-20250918-184310-TFDLWFG.ts +23 -0
- package/@types/forms/fields/file.d.sync-conflict-20250918-222046-TFDLWFG.ts +23 -0
- package/@types/forms/fields/file.d.ts +11 -5
- package/@types/forms/fields/file.sync-conflict-20250918-222049-TFDLWFG.d.ts +23 -0
- package/@types/forms/fields/float.d.ts +4 -0
- package/@types/forms/fields/get-field-for-sealious.d.sync-conflict-20250918-222046-TFDLWFG.ts +29 -0
- package/@types/forms/fields/get-field-for-sealious.d.ts +31 -0
- package/@types/forms/fields/get-field-for-sealious.sync-conflict-20250918-222042-TFDLWFG.d.ts +29 -0
- package/@types/forms/fields/html.d.ts +6 -0
- package/@types/forms/fields/image.d.sync-conflict-20250918-222042-TFDLWFG.ts +5 -0
- package/@types/forms/fields/image.d.ts +5 -0
- package/@types/forms/fields/int.d.ts +6 -0
- package/@types/forms/fields/json.d.ts +13 -0
- package/@types/forms/fields/markdown.d.ts +6 -0
- package/@types/forms/fields/multiple-files.d.sync-conflict-20250918-184304-TFDLWFG.ts +16 -0
- package/@types/forms/fields/multiple-files.d.ts +3 -1
- package/@types/forms/fields/number.d.sync-conflict-20250918-184317-TFDLWFG.ts +25 -0
- package/@types/forms/fields/number.d.sync-conflict-20250918-222047-TFDLWFG.ts +25 -0
- package/@types/forms/fields/number.d.ts +3 -1
- package/@types/forms/fields/password.d.ts +6 -0
- package/@types/forms/fields/pick-from-list-sealious.d.ts +11 -0
- package/@types/forms/fields/pick-from-list.d.sync-conflict-20250918-184322-TFDLWFG.ts +15 -0
- package/@types/forms/fields/pick-from-list.d.ts +4 -3
- package/@types/forms/fields/proxy-field.d.sync-conflict-20250918-184307-TFDLWFG.ts +15 -0
- package/@types/forms/fields/proxy-field.d.ts +3 -1
- package/@types/forms/fields/regexp.d.sync-conflict-20250918-184305-TFDLWFG.ts +21 -0
- package/@types/forms/fields/regexp.d.sync-conflict-20250918-222045-TFDLWFG.ts +21 -0
- package/@types/forms/fields/regexp.d.ts +6 -1
- package/@types/forms/fields/regexp.sync-conflict-20250918-222047-TFDLWFG.d.ts +21 -0
- package/@types/forms/fields/simple-form-field.d.sync-conflict-20250918-184309-TFDLWFG.ts +29 -0
- package/@types/forms/fields/simple-form-field.d.sync-conflict-20250918-222044-TFDLWFG.ts +29 -0
- package/@types/forms/fields/simple-form-field.d.ts +23 -3
- package/@types/forms/fields/simple-form-field.sync-conflict-20250918-222049-TFDLWFG.d.ts +29 -0
- package/@types/forms/fields/single-reference.d.ts +19 -0
- package/@types/forms/fields/single-reference.sync-conflict-20250918-222043-TFDLWFG.d.ts +10 -0
- package/@types/forms/fields/structured-array.d.sync-conflict-20250918-184302-TFDLWFG.ts +27 -0
- package/@types/forms/fields/structured-array.d.sync-conflict-20250918-222049-TFDLWFG.ts +27 -0
- package/@types/forms/fields/structured-array.d.ts +19 -10
- package/@types/forms/fields/structured-array.sync-conflict-20250918-222047-TFDLWFG.d.ts +27 -0
- package/@types/forms/fields/table.d.sync-conflict-20250918-184303-TFDLWFG.ts +16 -0
- package/@types/forms/fields/table.d.ts +3 -0
- package/@types/forms/fields/text.d.ts +6 -0
- package/@types/forms/fields/url.d.ts +6 -0
- package/@types/forms/form-types.d.sync-conflict-20250918-222045-TFDLWFG.ts +26 -0
- package/@types/forms/form-types.d.ts +2 -0
- package/@types/forms/form.d.sync-conflict-20250918-184315-TFDLWFG.ts +32 -0
- package/@types/forms/form.d.sync-conflict-20250918-222049-TFDLWFG.ts +32 -0
- package/@types/forms/form.d.ts +10 -7
- package/@types/forms/form.sync-conflict-20250918-222049-TFDLWFG.d.ts +33 -0
- package/@types/forms/form.test.d.sync-conflict-20250918-184318-TFDLWFG.ts +6 -0
- package/@types/forms/form.test.d.sync-conflict-20250918-222047-TFDLWFG.ts +6 -0
- package/@types/forms/form.test.d.ts +2 -2
- package/@types/forms/multiform.d.sync-conflict-20250918-184308-TFDLWFG.ts +23 -0
- package/@types/forms/multiform.d.ts +1 -1
- package/@types/forms/multiform.sync-conflict-20250918-222044-TFDLWFG.d.ts +23 -0
- package/@types/index.d.sync-conflict-20250918-184316-TFDLWFG.ts +46 -0
- package/@types/index.d.ts +2 -2
- package/@types/mount.d.sync-conflict-20250918-184320-TFDLWFG.ts +6 -0
- package/@types/page/list.d.sync-conflict-20250918-184318-TFDLWFG.ts +48 -0
- package/@types/page/list.d.sync-conflict-20250918-222046-TFDLWFG.ts +48 -0
- package/@types/page/list.d.ts +2 -2
- package/@types/page/list.sync-conflict-20250918-222048-TFDLWFG.d.ts +48 -0
- package/@types/page/mountable-with-fields.d.sync-conflict-20250918-184321-TFDLWFG.ts +42 -0
- package/@types/page/mountable-with-fields.d.sync-conflict-20250918-222046-TFDLWFG.ts +42 -0
- package/@types/page/mountable-with-fields.d.ts +3 -3
- package/@types/page/mountable-with-fields.sync-conflict-20250918-222044-TFDLWFG.d.ts +42 -0
- package/@types/page/mountable.d.sync-conflict-20250918-184306-TFDLWFG.ts +10 -0
- package/@types/page/page.d.sync-conflict-20250918-184320-TFDLWFG.ts +18 -0
- package/@types/page/props-parser.d.sync-conflict-20250918-184305-TFDLWFG.ts +15 -0
- package/@types/page/props-parser.d.ts +0 -1
- package/@types/page/stateful-page.d.sync-conflict-20250918-184326-TFDLWFG.ts +62 -0
- package/@types/templates/shared/shared-crud-form-fields.d.sync-conflict-20250918-184306-TFDLWFG.ts +1 -0
- package/@types/templates/shared/shared-crud-form-fields.d.ts +0 -67
- package/@types/test_utils/test-on-real-app.d.sync-conflict-20250918-184320-TFDLWFG.ts +26 -0
- package/@types/test_utils/test-on-real-app.d.ts +0 -1
- package/@types/utils/extract-fields-from-collection.d.sync-conflict-20250918-184312-TFDLWFG.ts +18 -0
- package/@types/utils/extract-fields-from-collection.d.ts +5 -1
- package/@types/utils/extract-fields-from-collection.sync-conflict-20250918-222045-TFDLWFG.d.ts +18 -0
- package/@types/utils/wrap-attributes.d.ts +3 -0
- package/README.md +5 -0
- package/assets/file-icon.svg +5 -0
- package/lib/add-crud.js +80 -89
- package/lib/add-list-route.test.js +1 -1
- package/lib/add-route.js +0 -7
- package/lib/build.js +3 -1
- package/lib/cli.js +2 -5
- package/lib/controllers/table-add-button.stimulus.js +35 -0
- package/lib/forms/controls/array.js +20 -16
- package/lib/forms/controls/big-radio-group.js +2 -2
- package/lib/forms/controls/checkbox-group.js +7 -7
- package/lib/forms/controls/checkboxed-list-input.js +9 -2
- package/lib/forms/controls/controls.js +2 -2
- package/lib/forms/controls/derived-frame.js +5 -1
- package/lib/forms/controls/derived.js +1 -1
- package/lib/forms/controls/dropdown.js +4 -1
- package/lib/forms/controls/editable-collection-subset.js +2 -2
- package/lib/forms/controls/file.js +26 -2
- package/lib/forms/controls/file.test.js +2 -2
- package/lib/forms/controls/hidden-input.js +4 -1
- package/lib/forms/controls/{photo.js → image.js} +6 -7
- package/lib/forms/controls/{photo.test.js → image.test.js} +6 -21
- package/lib/forms/controls/multiple-files.js +10 -1
- package/lib/forms/controls/{multiple-photos.js → multiple-images.js} +3 -3
- package/lib/forms/controls/simple-input.js +13 -12
- package/lib/forms/controls/single-reference.js +4 -0
- package/lib/forms/controls/table.js +66 -24
- package/lib/forms/controls/textarea.js +4 -2
- package/lib/forms/controls/tickable.js +13 -5
- package/lib/forms/fields/boolean.js +14 -0
- package/lib/forms/fields/checkboxed-list.js +4 -0
- package/lib/forms/fields/collection-field.js +9 -0
- package/lib/forms/fields/color.js +10 -0
- package/lib/forms/fields/coordinates.js +49 -0
- package/lib/forms/fields/date.js +34 -0
- package/lib/forms/fields/datetime.js +46 -0
- package/lib/forms/fields/deep-reverse-single-reference-list.js +81 -0
- package/lib/forms/fields/deep-reverse-single-reference-table.js +122 -0
- package/lib/forms/fields/email.js +7 -0
- package/lib/forms/fields/enum-multiple-sealious.js +32 -0
- package/lib/forms/fields/field.js +32 -4
- package/lib/forms/fields/field.test.js +5 -5
- package/lib/forms/fields/fields.js +23 -8
- package/lib/forms/fields/file.js +33 -9
- package/lib/forms/fields/file.test.js +4 -16
- package/lib/forms/fields/float.js +10 -0
- package/lib/forms/fields/get-field-for-sealious.js +213 -0
- package/lib/forms/fields/html.js +14 -0
- package/lib/forms/fields/image.js +13 -0
- package/lib/forms/fields/int.js +23 -0
- package/lib/forms/fields/json.js +31 -0
- package/lib/forms/fields/markdown.js +14 -0
- package/lib/forms/fields/multiple-files.js +4 -0
- package/lib/forms/fields/number.js +6 -0
- package/lib/forms/fields/password.js +13 -0
- package/lib/forms/fields/pick-from-list-sealious.js +17 -0
- package/lib/forms/fields/pick-from-list.js +6 -2
- package/lib/forms/fields/proxy-field.js +3 -0
- package/lib/forms/fields/regexp.js +14 -0
- package/lib/forms/fields/simple-form-field.js +60 -2
- package/lib/forms/fields/single-reference.js +44 -0
- package/lib/forms/fields/structured-array.js +63 -12
- package/lib/forms/fields/table.js +28 -1
- package/lib/forms/fields/text.js +17 -0
- package/lib/forms/fields/url.js +17 -0
- package/lib/forms/form.js +30 -13
- package/lib/forms/form.test.js +3 -4
- package/lib/forms/multiform.js +4 -2
- package/lib/forms/multiform.test.js +3 -3
- package/lib/generate-stimulus.js +1 -0
- package/lib/index.js +1 -0
- package/lib/make-hidden-inputs.js +1 -1
- package/lib/mount.js +11 -0
- package/lib/notifier.js +0 -1
- package/lib/page/list.js +15 -8
- package/lib/page/mountable-with-fields.js +14 -6
- package/lib/page/mountable-with-fields.test.js +1 -1
- package/lib/templates/form.js +8 -9
- package/lib/templates/multiform.js +4 -4
- package/lib/templates/page.js +0 -2
- package/lib/templates/shared/collection-create-form.js +28 -40
- package/lib/templates/shared/collection-edit-form.js +40 -77
- package/lib/templates/shared/collection-list.js +12 -20
- package/lib/templates/shared/shared-crud-form-fields.js +27 -95
- package/lib/test_utils/test-on-real-app.js +3 -3
- package/lib/utils/extract-fields-from-collection.js +60 -20
- package/lib/utils/make-slug.js +1 -1
- package/lib/utils/wrap-attributes.js +20 -0
- package/package.json +5 -4
- package/src/add-crud.ts +86 -97
- package/src/add-list-route.test.ts +1 -1
- package/src/add-route.ts +0 -7
- package/src/build.ts +3 -1
- package/src/cli.ts +3 -5
- package/src/controllers/table-add-button.stimulus.ts +35 -0
- package/src/forms/controls/array.ts +23 -20
- package/src/forms/controls/autocomplete.ts +1 -1
- package/src/forms/controls/big-radio-group.ts +2 -2
- package/src/forms/controls/checkbox-group.ts +9 -9
- package/src/forms/controls/checkboxed-list-input.ts +27 -15
- package/src/forms/controls/controls.ts +2 -2
- package/src/forms/controls/derived-frame.ts +5 -1
- package/src/forms/controls/derived.ts +1 -1
- package/src/forms/controls/dropdown.ts +5 -2
- package/src/forms/controls/editable-collection-subset.ts +2 -2
- package/src/forms/controls/file.test.ts +4 -2
- package/src/forms/controls/file.ts +31 -5
- package/src/forms/controls/form-control.ts +7 -2
- package/src/forms/controls/hidden-input.ts +4 -1
- package/src/forms/controls/{photo.test.ts → image.test.ts} +5 -22
- package/src/forms/controls/{photo.ts → image.ts} +3 -5
- package/src/forms/controls/multiple-files.ts +18 -1
- package/src/forms/controls/{multiple-photos.ts → multiple-images.ts} +1 -1
- package/src/forms/controls/number.ts +1 -1
- package/src/forms/controls/simple-input.ts +18 -34
- package/src/forms/controls/single-reference.ts +10 -2
- package/src/forms/controls/table.ts +90 -31
- package/src/forms/controls/textarea.ts +6 -4
- package/src/forms/controls/tickable.ts +13 -5
- package/src/forms/fields/boolean.ts +23 -1
- package/src/forms/fields/checkboxed-list.ts +11 -2
- package/src/forms/fields/collection-field.ts +16 -1
- package/src/forms/fields/color.ts +9 -0
- package/src/forms/fields/coordinates.ts +66 -0
- package/src/forms/fields/date.ts +50 -0
- package/src/forms/fields/datetime.ts +66 -0
- package/src/forms/fields/deep-reverse-single-reference-list.ts +136 -0
- package/src/forms/fields/deep-reverse-single-reference-table.ts +213 -0
- package/src/forms/fields/email.ts +9 -0
- package/src/forms/fields/enum-multiple-sealious.ts +48 -0
- package/src/forms/fields/field.test.ts +5 -5
- package/src/forms/fields/field.ts +94 -8
- package/src/forms/fields/fields.ts +23 -8
- package/src/forms/fields/file.test.ts +4 -16
- package/src/forms/fields/file.ts +43 -15
- package/src/forms/fields/float.ts +9 -0
- package/src/forms/fields/get-field-for-sealious.ts +304 -0
- package/src/forms/fields/html.ts +15 -0
- package/src/forms/fields/image.ts +12 -0
- package/src/forms/fields/int.ts +25 -0
- package/src/forms/fields/json.ts +48 -0
- package/src/forms/fields/markdown.ts +15 -0
- package/src/forms/fields/multiple-files.ts +10 -1
- package/src/forms/fields/number.ts +8 -1
- package/src/forms/fields/password.ts +17 -0
- package/src/forms/fields/pick-from-list-sealious.ts +22 -0
- package/src/forms/fields/pick-from-list.ts +7 -3
- package/src/forms/fields/proxy-field.ts +6 -1
- package/src/forms/fields/regexp.ts +27 -1
- package/src/forms/fields/simple-form-field.ts +95 -7
- package/src/forms/fields/single-reference.ts +62 -0
- package/src/forms/fields/structured-array.ts +115 -18
- package/src/forms/fields/table.ts +32 -1
- package/src/forms/fields/text.ts +18 -0
- package/src/forms/fields/url.ts +20 -0
- package/src/forms/form-types.ts +2 -0
- package/src/forms/form.test.ts +3 -4
- package/src/forms/form.ts +37 -16
- package/src/forms/forms.css +0 -85
- package/src/forms/multiform.test.ts +3 -3
- package/src/forms/multiform.ts +2 -0
- package/src/generate-stimulus.ts +1 -0
- package/src/index.ts +2 -1
- package/src/make-hidden-inputs.ts +1 -1
- package/src/mount.ts +14 -0
- package/src/notifier.ts +0 -1
- package/src/page/list.ts +15 -8
- package/src/page/mountable-with-fields.test.ts +1 -1
- package/src/page/mountable-with-fields.ts +18 -9
- package/src/register-external.ts +1 -1
- package/src/templates/form.ts +8 -9
- package/src/templates/multiform.ts +4 -4
- package/src/templates/page.ts +0 -2
- package/src/templates/shared/collection-create-form.ts +30 -66
- package/src/templates/shared/collection-edit-form.ts +41 -102
- package/src/templates/shared/collection-list.ts +12 -20
- package/src/templates/shared/item-delete.ts +0 -1
- package/src/templates/shared/shared-crud-form-fields.ts +37 -171
- package/src/test_utils/test-on-real-app.ts +4 -3
- package/src/utils/extract-fields-from-collection.ts +76 -25
- package/src/utils/make-slug.ts +1 -1
- package/src/utils/wrap-attributes.ts +17 -0
- package/lib/add-verbose-crud.js +0 -119
- package/lib/crud-field-snippets.js +0 -52
- package/lib/find-css-includes.js +0 -3
- package/lib/forms/controls/reverse-single-reference.js +0 -1
- package/lib/forms/fields/enum-multiple.js +0 -47
- package/lib/forms/fields/enum-multiple.test.js +0 -27
- package/lib/forms/fields/enum.js +0 -41
- package/lib/forms/fields/enum.test.js +0 -21
- package/lib/forms/fields/reverse-single-reference.js +0 -17
- package/lib/templates/shared/handlers/boolean.js +0 -14
- package/lib/templates/shared/handlers/date.js +0 -8
- package/lib/templates/shared/handlers/deep-reverse-single-reference.js +0 -209
- package/lib/templates/shared/handlers/default.js +0 -49
- package/lib/templates/shared/handlers/enum.js +0 -19
- package/lib/templates/shared/handlers/file.js +0 -23
- package/lib/templates/shared/handlers/image.js +0 -32
- package/lib/templates/shared/handlers/int.js +0 -11
- package/lib/templates/shared/handlers/jdd.js +0 -10
- package/lib/templates/shared/handlers/single-reference.js +0 -12
- package/lib/templates/shared/handlers/structured-array.js +0 -33
- package/src/add-verbose-crud.ts +0 -138
- package/src/crud-field-snippets.ts +0 -57
- package/src/find-css-includes.ts +0 -3
- package/src/forms/controls/reverse-single-reference.ts +0 -50
- package/src/forms/fields/enum-multiple.test.ts +0 -31
- package/src/forms/fields/enum-multiple.ts +0 -62
- package/src/forms/fields/enum.test.ts +0 -25
- package/src/forms/fields/enum.ts +0 -56
- package/src/forms/fields/reverse-single-reference.ts +0 -20
- package/src/templates/shared/handlers/boolean.ts +0 -18
- package/src/templates/shared/handlers/date.ts +0 -12
- package/src/templates/shared/handlers/deep-reverse-single-reference.ts +0 -244
- package/src/templates/shared/handlers/default.ts +0 -64
- package/src/templates/shared/handlers/enum.ts +0 -23
- package/src/templates/shared/handlers/file.ts +0 -27
- package/src/templates/shared/handlers/image.ts +0 -45
- package/src/templates/shared/handlers/int.ts +0 -15
- package/src/templates/shared/handlers/jdd.ts +0 -14
- package/src/templates/shared/handlers/single-reference.ts +0 -16
- package/src/templates/shared/handlers/structured-array.ts +0 -42
package/src/forms/forms.css
CHANGED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
.form-message {
|
|
2
|
-
--color: black;
|
|
3
|
-
border: 1px solid var(--color);
|
|
4
|
-
border-radius: 5px;
|
|
5
|
-
padding: 10px;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.form-message--error {
|
|
9
|
-
--color: #ff4136;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.form-message--success {
|
|
13
|
-
--color: #2ecc40;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.form__error {
|
|
17
|
-
color: #ff4136;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.form-input__wrapper--checkbox {
|
|
21
|
-
display: flex;
|
|
22
|
-
flex-flow: row nowrap;
|
|
23
|
-
align-items: center;
|
|
24
|
-
& > input[type="checkbox"] {
|
|
25
|
-
width: 15px;
|
|
26
|
-
height: 15px;
|
|
27
|
-
|
|
28
|
-
+ label {
|
|
29
|
-
padding-left: 10px;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.form-input__wrapper--multiple-files--photos {
|
|
35
|
-
ul {
|
|
36
|
-
list-style: none;
|
|
37
|
-
display: grid;
|
|
38
|
-
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
39
|
-
grid-gap: 10px;
|
|
40
|
-
margin-bottom: 20px;
|
|
41
|
-
|
|
42
|
-
li {
|
|
43
|
-
background-color: white;
|
|
44
|
-
box-shadow: 1px 1px 6px 0px #00000038;
|
|
45
|
-
padding: 10px;
|
|
46
|
-
display: grid;
|
|
47
|
-
grid-template-columns: 1fr 20px;
|
|
48
|
-
grid-template-rows: 20px auto min-content;
|
|
49
|
-
grid-row-gap: 10px;
|
|
50
|
-
|
|
51
|
-
a {
|
|
52
|
-
grid-row: 1/3;
|
|
53
|
-
grid-column: 1/3;
|
|
54
|
-
|
|
55
|
-
picture,
|
|
56
|
-
img {
|
|
57
|
-
width: 100%;
|
|
58
|
-
height: 150px;
|
|
59
|
-
object-fit: contain;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.filename {
|
|
64
|
-
grid-row: 3/4;
|
|
65
|
-
grid-column: 1/3;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
form {
|
|
69
|
-
grid-row: 1/2;
|
|
70
|
-
grid-column: 2/3;
|
|
71
|
-
position: relative;
|
|
72
|
-
z-index: 2;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.file-list-item {
|
|
79
|
-
display: flex;
|
|
80
|
-
flex-flow: row;
|
|
81
|
-
|
|
82
|
-
form {
|
|
83
|
-
padding-left: 20px;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -9,7 +9,7 @@ import { Multiform } from "./multiform.js";
|
|
|
9
9
|
import { assertThrowsAsync } from "../utils/utils.js";
|
|
10
10
|
import { form_factory } from "./form.test.js";
|
|
11
11
|
import { getBrowser } from "../utils/browser-creator.js";
|
|
12
|
-
import {
|
|
12
|
+
import { TextBasedSimpleField } from "./fields/simple-form-field.js";
|
|
13
13
|
import { Form } from "./form.js";
|
|
14
14
|
import { FormHeader } from "./controls/form-header.js";
|
|
15
15
|
import { SimpleInput } from "./controls/simple-input.js";
|
|
@@ -22,7 +22,7 @@ const port = await getPort();
|
|
|
22
22
|
console.log(`Using port ${port} form multiform.test.ts`);
|
|
23
23
|
|
|
24
24
|
const fields1 = {
|
|
25
|
-
email: new
|
|
25
|
+
email: new TextBasedSimpleField(true),
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const form1 = new (class extends Form<typeof fields1, void> {
|
|
@@ -35,7 +35,7 @@ const form1 = new (class extends Form<typeof fields1, void> {
|
|
|
35
35
|
})();
|
|
36
36
|
|
|
37
37
|
const fields2 = {
|
|
38
|
-
name: new
|
|
38
|
+
name: new TextBasedSimpleField(true),
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const form2 = new (class extends Form<Record<never, unknown>, void> {
|
package/src/forms/multiform.ts
CHANGED
|
@@ -103,6 +103,7 @@ export class Multiform extends MountableWithFields {
|
|
|
103
103
|
{
|
|
104
104
|
raw_values: await this.getSubformRawValues(ctx, sub_form_name),
|
|
105
105
|
messages: [],
|
|
106
|
+
field_messages: {},
|
|
106
107
|
},
|
|
107
108
|
show_field_errors
|
|
108
109
|
);
|
|
@@ -134,6 +135,7 @@ export class Multiform extends MountableWithFields {
|
|
|
134
135
|
return tempstream/* HTML */ `${this.renderMessages(ctx, {
|
|
135
136
|
raw_values: {},
|
|
136
137
|
messages,
|
|
138
|
+
field_messages: {},
|
|
137
139
|
})}
|
|
138
140
|
<div class="forms">
|
|
139
141
|
<form
|
package/src/generate-stimulus.ts
CHANGED
|
@@ -16,6 +16,7 @@ export async function generateStimulusControllers(
|
|
|
16
16
|
target_locreq.resolve("src/"),
|
|
17
17
|
...controller_dirs,
|
|
18
18
|
];
|
|
19
|
+
console.log("Looking for controllers in ", stimulus_search_dirs);
|
|
19
20
|
const controller_names = (
|
|
20
21
|
await Promise.all(stimulus_search_dirs.map((dir) => recursive(dir)))
|
|
21
22
|
)
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./forms/multiform.js";
|
|
|
16
16
|
export * as Components from "./components/components.js";
|
|
17
17
|
export * from "./mount.js";
|
|
18
18
|
export * from "./page/default-list-filters.js";
|
|
19
|
+
export * from "./forms/fields/get-field-for-sealious.js";
|
|
19
20
|
|
|
20
21
|
import { Context } from "koa";
|
|
21
22
|
import { Readable } from "node:stream";
|
|
@@ -37,7 +38,7 @@ export interface HTMLHeadOptions {
|
|
|
37
38
|
export interface HTMLArgs {
|
|
38
39
|
ctx: Context;
|
|
39
40
|
title: string | Promise<string>;
|
|
40
|
-
body: string | Promise<string
|
|
41
|
+
body: string | Promise<string> | Readable;
|
|
41
42
|
htmlOptions?: Partial<HTMLOptions>;
|
|
42
43
|
makeHead?: (
|
|
43
44
|
args: HTMLHeadOptions
|
package/src/mount.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { FileManager } from "@sealcode/file-manager";
|
|
|
4
4
|
import Koa, { Context } from "koa";
|
|
5
5
|
import { Middlewares as SealiousMiddlewares } from "sealious";
|
|
6
6
|
import { Mountable } from "./page/mountable.js";
|
|
7
|
+
import { KoaResponsiveImageRouter } from "koa-responsive-image-router";
|
|
7
8
|
|
|
8
9
|
async function handleHtmlPromise(ctx: Context, next: Koa.Next) {
|
|
9
10
|
await next();
|
|
@@ -24,6 +25,17 @@ export function mount(
|
|
|
24
25
|
: undefined
|
|
25
26
|
): void {
|
|
26
27
|
const raw_url = typeof url === "string" ? url : url.rawURL;
|
|
28
|
+
|
|
29
|
+
const imageRouter = new KoaResponsiveImageRouter({
|
|
30
|
+
staticPath: "/tmp",
|
|
31
|
+
thumbnailSize: 10,
|
|
32
|
+
cacheManagerResolutionThreshold: 10,
|
|
33
|
+
imageStoragePath: "/tmp",
|
|
34
|
+
smartCropStoragePath: "/tmp",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const fileManager = new FileManager("/tmp", "/uploaded_files");
|
|
38
|
+
|
|
27
39
|
const args = use_dummy_app
|
|
28
40
|
? [
|
|
29
41
|
async (ctx: Context, next: any) => {
|
|
@@ -32,6 +44,8 @@ export function mount(
|
|
|
32
44
|
// regard
|
|
33
45
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
34
46
|
ctx.$app = {
|
|
47
|
+
fileManager,
|
|
48
|
+
imageRouter,
|
|
35
49
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
36
50
|
Logger: new Proxy(
|
|
37
51
|
{},
|
package/src/notifier.ts
CHANGED
|
@@ -50,7 +50,6 @@ async function wait_for_app_to_be_stable(app_port: number, n = 3) {
|
|
|
50
50
|
let counter = 0;
|
|
51
51
|
// eslint-disable-next-line no-constant-condition
|
|
52
52
|
while (true) {
|
|
53
|
-
console.debug("notifier.ts:53");
|
|
54
53
|
// eslint-disable-next-line no-await-in-loop
|
|
55
54
|
const { status } = await get_status(app_port).catch(() => ({
|
|
56
55
|
status: "down",
|
package/src/page/list.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { naturalNumbers, UrlWithNewParams } from "../utils/utils.js";
|
|
|
8
8
|
import { makeHiddenInputs } from "../make-hidden-inputs.js";
|
|
9
9
|
import qs from "qs";
|
|
10
10
|
import { NumberField } from "../forms/fields/number.js";
|
|
11
|
-
import {
|
|
11
|
+
import { TextBasedSimpleField } from "../forms/fields/simple-form-field.js";
|
|
12
12
|
import { FormDataValue } from "../forms/form-types.js";
|
|
13
13
|
|
|
14
14
|
export const BasePagePropsShape = <const>{};
|
|
@@ -19,7 +19,7 @@ export const DEFAULT_ITEMS_PER_PAGE = 12;
|
|
|
19
19
|
export const BaseListPageFields = <const>{
|
|
20
20
|
page: new NumberField(false, 1),
|
|
21
21
|
itemsPerPage: new NumberField(false, DEFAULT_ITEMS_PER_PAGE),
|
|
22
|
-
sort: new
|
|
22
|
+
sort: new TextBasedSimpleField(false),
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export type ListSort = { field: string; order: "asc" | "desc" };
|
|
@@ -74,8 +74,8 @@ export abstract class ListPage<
|
|
|
74
74
|
|
|
75
75
|
init(): void {
|
|
76
76
|
super.init();
|
|
77
|
-
for (const [
|
|
78
|
-
void field.init(
|
|
77
|
+
for (const [, field] of Object.entries(this.filterFields)) {
|
|
78
|
+
void field.init();
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -85,12 +85,15 @@ export abstract class ListPage<
|
|
|
85
85
|
|
|
86
86
|
async getPaginationConfig(ctx: Context) {
|
|
87
87
|
const values = await this.extractRawValues(ctx);
|
|
88
|
-
let { parsed: page } = await this.fields.page.
|
|
88
|
+
let { parsed: page } = await this.fields.page.getParsedValue(
|
|
89
|
+
ctx,
|
|
90
|
+
values
|
|
91
|
+
);
|
|
89
92
|
if (!page) {
|
|
90
93
|
page = 1;
|
|
91
94
|
}
|
|
92
95
|
const { parsed: itemsPerPage } =
|
|
93
|
-
await this.fields.itemsPerPage.
|
|
96
|
+
await this.fields.itemsPerPage.getParsedValue(ctx, values);
|
|
94
97
|
return { page, itemsPerPage };
|
|
95
98
|
}
|
|
96
99
|
|
|
@@ -182,7 +185,7 @@ export abstract class ListPage<
|
|
|
182
185
|
const raw_values = await this.extractRawValues(ctx);
|
|
183
186
|
for (const [fieldname, field] of Object.entries(this.filterFields)) {
|
|
184
187
|
// eslint-disable-next-line no-await-in-loop
|
|
185
|
-
const { parsed } = await field.
|
|
188
|
+
const { parsed } = await field.getParsedValue(ctx, raw_values);
|
|
186
189
|
filter[fieldname] = field.mapToFilter(parsed);
|
|
187
190
|
}
|
|
188
191
|
return filter;
|
|
@@ -226,7 +229,11 @@ export abstract class ListPage<
|
|
|
226
229
|
return control.render(
|
|
227
230
|
this.makeFormControlContext(
|
|
228
231
|
ctx,
|
|
229
|
-
{
|
|
232
|
+
{
|
|
233
|
+
raw_values: values,
|
|
234
|
+
messages: [],
|
|
235
|
+
field_messages: {},
|
|
236
|
+
},
|
|
230
237
|
false
|
|
231
238
|
)
|
|
232
239
|
);
|
|
@@ -19,7 +19,7 @@ describe("mountable-with-fields", () => {
|
|
|
19
19
|
data.not_required?.trim();
|
|
20
20
|
// this should work without the optional chaining:
|
|
21
21
|
data.required.trim();
|
|
22
|
-
const { parsed: data2 } = await this.fields.not_required.
|
|
22
|
+
const { parsed: data2 } = await this.fields.not_required.getParsedValue(
|
|
23
23
|
ctx,
|
|
24
24
|
form_values.raw_values
|
|
25
25
|
);
|
|
@@ -2,6 +2,7 @@ import { ShapeToType } from "@sealcode/ts-predicates";
|
|
|
2
2
|
import { Context } from "koa";
|
|
3
3
|
import { FlatTemplatable, tempstream } from "tempstream";
|
|
4
4
|
import {
|
|
5
|
+
FieldMessages,
|
|
5
6
|
FormControl,
|
|
6
7
|
FormControlContext,
|
|
7
8
|
} from "../forms/controls/form-control.js";
|
|
@@ -20,7 +21,7 @@ export type Fields = Record<string, FormField<boolean, any>>;
|
|
|
20
21
|
|
|
21
22
|
type Resolved<T> = T extends Promise<infer X> ? X : never;
|
|
22
23
|
type ParsedValue<T extends FormField> = Resolved<
|
|
23
|
-
ReturnType<T["
|
|
24
|
+
ReturnType<T["getParsedValue"]>
|
|
24
25
|
>["parsed"];
|
|
25
26
|
|
|
26
27
|
export abstract class MountableWithFields<
|
|
@@ -37,8 +38,9 @@ export abstract class MountableWithFields<
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
init(): void {
|
|
40
|
-
for (const [
|
|
41
|
-
void field.init(
|
|
41
|
+
for (const [field_name, field] of Object.entries(this.fields)) {
|
|
42
|
+
void field.init();
|
|
43
|
+
field.setName(field_name);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -51,7 +53,7 @@ export abstract class MountableWithFields<
|
|
|
51
53
|
) {
|
|
52
54
|
return new FormControlContext(
|
|
53
55
|
ctx,
|
|
54
|
-
data
|
|
56
|
+
data,
|
|
55
57
|
data.messages,
|
|
56
58
|
field_name_prefix,
|
|
57
59
|
form_id,
|
|
@@ -81,10 +83,10 @@ export abstract class MountableWithFields<
|
|
|
81
83
|
values: Record<string, FormDataValue>
|
|
82
84
|
): Promise<{
|
|
83
85
|
valid: boolean;
|
|
84
|
-
field_errors:
|
|
86
|
+
field_errors: FieldMessages;
|
|
85
87
|
form_messages: FormMessage[];
|
|
86
88
|
}> {
|
|
87
|
-
const field_errors = {} as
|
|
89
|
+
const field_errors = {} as FieldMessages;
|
|
88
90
|
let valid = true;
|
|
89
91
|
const form_messages = [] as FormMessage[];
|
|
90
92
|
|
|
@@ -92,10 +94,13 @@ export abstract class MountableWithFields<
|
|
|
92
94
|
Object.keys(this.fields).map(async (key: keyof F) => {
|
|
93
95
|
const field = this.fields[key];
|
|
94
96
|
const { valid: fieldvalid, message: fieldmessage } =
|
|
95
|
-
await field.
|
|
97
|
+
await field.getParsedValue(ctx, values, true);
|
|
96
98
|
if (!fieldvalid) {
|
|
97
99
|
valid = false;
|
|
98
|
-
field_errors[field.name] =
|
|
100
|
+
field_errors[field.name] = {
|
|
101
|
+
type: "error",
|
|
102
|
+
message: fieldmessage,
|
|
103
|
+
};
|
|
99
104
|
}
|
|
100
105
|
})
|
|
101
106
|
);
|
|
@@ -149,7 +154,11 @@ export abstract class MountableWithFields<
|
|
|
149
154
|
const promises = Object.entries(this.fields).map(
|
|
150
155
|
async ([key, field]) => {
|
|
151
156
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
152
|
-
const { parsed } = await field.
|
|
157
|
+
const { parsed } = await field.getParsedValue(
|
|
158
|
+
ctx,
|
|
159
|
+
raw_values,
|
|
160
|
+
false
|
|
161
|
+
);
|
|
153
162
|
result[key] = parsed;
|
|
154
163
|
}
|
|
155
164
|
);
|
package/src/register-external.ts
CHANGED
|
@@ -70,7 +70,7 @@ async function updatePackageJson(
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const pathToAdd = `node_modules/${moduleName}/${subdirectory}`;
|
|
73
|
-
const existingPaths = packageJson.sealgen[type]
|
|
73
|
+
const existingPaths = packageJson.sealgen[type];
|
|
74
74
|
|
|
75
75
|
// Check if the path is already present
|
|
76
76
|
if (existingPaths.includes(pathToAdd)) {
|
package/src/templates/form.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
3
|
-
import { getPrettierConfig } from "../utils/prettier.js";
|
|
1
|
+
import { formatWithPrettier } from "../utils/prettier.js";
|
|
4
2
|
|
|
5
3
|
const defaults = {
|
|
6
4
|
postimport: `
|
|
7
5
|
import { Fields } from "@sealcode/sealgen";
|
|
8
6
|
import type {FormDataValue} from "@sealcode/sealgen";`,
|
|
9
7
|
fields: `
|
|
10
|
-
password: new Fields.
|
|
8
|
+
password: new Fields.Password(true),`,
|
|
11
9
|
controls: `
|
|
12
10
|
new Controls.SimpleInput(fields.password, {
|
|
13
11
|
label: "Password:",
|
|
@@ -18,8 +16,8 @@ const defaults = {
|
|
|
18
16
|
data: Record<string, FormDataValue>
|
|
19
17
|
): Promise<{ valid: boolean; error: string }> {
|
|
20
18
|
// just a silly example, please remove this with better logic
|
|
21
|
-
const { parsed: email } = await this.fields.email.
|
|
22
|
-
const { parsed: password } = await this.fields.password.
|
|
19
|
+
const { parsed: email } = await this.fields.email.getParsedValue(ctx, data);
|
|
20
|
+
const { parsed: password } = await this.fields.password.getParsedValue(ctx, data);
|
|
23
21
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
24
22
|
if ((password || "").length > ((email as string) || "").length) {
|
|
25
23
|
return { valid: false, error: "Password cannot be longer than email" };
|
|
@@ -49,11 +47,10 @@ export async function formTemplate(
|
|
|
49
47
|
_params: Partial<typeof defaults> & { success_message: string } = defaults
|
|
50
48
|
): Promise<string> {
|
|
51
49
|
const params = { ...defaults, ..._params };
|
|
52
|
-
const rel = curryImportPath(newfilefullpath);
|
|
53
50
|
const content = `import type { Context } from "koa";
|
|
54
51
|
import type { FormData } from "@sealcode/sealgen";
|
|
55
52
|
import { Form, Controls, fieldsToShape } from "@sealcode/sealgen";
|
|
56
|
-
import html from "
|
|
53
|
+
import html from "src/back/html.js";
|
|
57
54
|
|
|
58
55
|
${params.postimport}
|
|
59
56
|
|
|
@@ -63,6 +60,8 @@ const fields = {
|
|
|
63
60
|
${params.fields}
|
|
64
61
|
};
|
|
65
62
|
|
|
63
|
+
Form.initFieldNames(fields);
|
|
64
|
+
|
|
66
65
|
export const ${action_name}Shape = fieldsToShape(fields);
|
|
67
66
|
|
|
68
67
|
export default new (class ${action_name}Form extends Form<typeof fields, void> {
|
|
@@ -84,5 +83,5 @@ export default new (class ${action_name}Form extends Form<typeof fields, void> {
|
|
|
84
83
|
${params.render}
|
|
85
84
|
})();
|
|
86
85
|
`;
|
|
87
|
-
return
|
|
86
|
+
return formatWithPrettier(content);
|
|
88
87
|
}
|
|
@@ -13,8 +13,8 @@ import { FlatTemplatable } from "tempstream";
|
|
|
13
13
|
export const actionName = "${action_name}";
|
|
14
14
|
|
|
15
15
|
const fields1 = {
|
|
16
|
-
email: new Fields.
|
|
17
|
-
password: new Fields.
|
|
16
|
+
email: new Fields.TextBasedSimpleField(true),
|
|
17
|
+
password: new Fields.TextBasedSimpleField(true),
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const form1 = new (class extends Form<typeof fields1, unknown> {
|
|
@@ -30,8 +30,8 @@ const form1 = new (class extends Form<typeof fields1, unknown> {
|
|
|
30
30
|
})();
|
|
31
31
|
|
|
32
32
|
const fields2 = {
|
|
33
|
-
name: new Fields.
|
|
34
|
-
surname: new Fields.
|
|
33
|
+
name: new Fields.TextBasedSimpleField(true),
|
|
34
|
+
surname: new Fields.TextBasedSimpleField(true),
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const form2 = new (class extends Form<typeof fields2, unknown> {
|
package/src/templates/page.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
2
1
|
export async function pageTemplate(
|
|
3
2
|
action_name: string,
|
|
4
3
|
newfilefullpath: string
|
|
5
4
|
): Promise<string> {
|
|
6
|
-
const rel = curryImportPath(newfilefullpath);
|
|
7
5
|
return `import type { Context } from "koa";
|
|
8
6
|
import { TempstreamJSX } from "tempstream";
|
|
9
7
|
import { Page } from "@sealcode/sealgen";
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
2
|
import { formTemplate } from "../form.js";
|
|
3
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
4
3
|
|
|
5
4
|
import _locreq from "locreq";
|
|
6
5
|
import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
|
|
7
|
-
import {
|
|
6
|
+
import { wrapAttribute } from "../../utils/wrap-attributes.js";
|
|
8
7
|
|
|
9
8
|
export async function createItemFormTemplate(
|
|
10
9
|
create_action_name: string,
|
|
@@ -15,33 +14,20 @@ export async function createItemFormTemplate(
|
|
|
15
14
|
const collection_fields = await extract_fields_from_collection(
|
|
16
15
|
collection_name
|
|
17
16
|
);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const field_handler_results = await Promise.all(
|
|
21
|
-
collection_fields.map((field) =>
|
|
22
|
-
getFieldHandler(collection_name, field, importPath)
|
|
23
|
-
)
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const post_create_actions = field_handler_results
|
|
27
|
-
.map(({ post_create }) => post_create)
|
|
28
|
-
.filter((e) => e != "");
|
|
17
|
+
const formFieldsVar = `${toPascalCase(collection_name)}FormFields`;
|
|
29
18
|
|
|
30
19
|
return formTemplate(create_action_name, newfilefullpath, {
|
|
31
20
|
success_message: "Created!",
|
|
32
|
-
postimport: `import {${toPascalCase(
|
|
33
|
-
collection_name
|
|
34
|
-
)}FormFields, ${toPascalCase(
|
|
21
|
+
postimport: `import {${formFieldsVar}, get${toPascalCase(
|
|
35
22
|
collection_name
|
|
36
23
|
)}FormControls }from "./shared.js";
|
|
37
24
|
|
|
38
|
-
import { ${toPascalCase(
|
|
39
|
-
|
|
40
|
-
)}";
|
|
41
|
-
|
|
42
|
-
import { ${list_action}URL } from "${importPath("src/back/routes/urls.js")}";
|
|
25
|
+
import { ${toPascalCase(
|
|
26
|
+
collection_name
|
|
27
|
+
)} } from "src/back/collections/collections.js";
|
|
43
28
|
|
|
44
|
-
|
|
29
|
+
import { ${list_action}URL } from "src/back/routes/urls.js";
|
|
30
|
+
import {tempstream} from "tempstream";
|
|
45
31
|
`,
|
|
46
32
|
|
|
47
33
|
fields: `...${toPascalCase(collection_name)}FormFields`,
|
|
@@ -49,7 +35,7 @@ export async function createItemFormTemplate(
|
|
|
49
35
|
new Controls.FormHeader("Create ${toPascalCase(
|
|
50
36
|
collection_name
|
|
51
37
|
)}"),
|
|
52
|
-
|
|
38
|
+
...get${toPascalCase(collection_name)}FormControls()`,
|
|
53
39
|
|
|
54
40
|
can_access: `canAccess = async (ctx: Context) => {
|
|
55
41
|
const policy = ${toPascalCase(collection_name)}.getPolicy("create");
|
|
@@ -57,53 +43,31 @@ export async function createItemFormTemplate(
|
|
|
57
43
|
return { canAccess: response?.allowed || false, message: response?.reason || "" };
|
|
58
44
|
};`,
|
|
59
45
|
|
|
60
|
-
get_initial_values:
|
|
61
|
-
.filter((r) => !r.hide_initial_value_create)
|
|
62
|
-
.map(({ initial_value_create }) => initial_value_create)
|
|
63
|
-
.filter((e) => e != "").length
|
|
64
|
-
? `getInitialValues(ctx: Context){
|
|
65
|
-
return {
|
|
66
|
-
${field_handler_results
|
|
67
|
-
.filter((r) => !r.hide_initial_value_create)
|
|
68
|
-
.map(
|
|
69
|
-
({ initial_value_create }) =>
|
|
70
|
-
initial_value_create
|
|
71
|
-
)
|
|
72
|
-
.join(",\n")}
|
|
73
|
-
}
|
|
74
|
-
}`
|
|
75
|
-
: ``,
|
|
46
|
+
get_initial_values: "",
|
|
76
47
|
|
|
77
48
|
onsubmit: `
|
|
78
|
-
async onSubmit(ctx: Context) {
|
|
79
|
-
const
|
|
80
|
-
if (!data) {
|
|
81
|
-
throw new Error("Error when parsing the form values");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
${field_handler_results
|
|
85
|
-
.map(({ pre_create }) => pre_create)
|
|
86
|
-
.filter((e) => e !== "")
|
|
87
|
-
.join("\n")}
|
|
49
|
+
async onSubmit(ctx: Context, formData: FormData) {
|
|
50
|
+
const fctx = this.makeFormControlContext(ctx, formData, true);
|
|
88
51
|
|
|
89
|
-
${
|
|
90
|
-
|
|
91
|
-
|
|
52
|
+
const created = await ctx.$app.collections["${toKebabCase(
|
|
53
|
+
collection_name
|
|
54
|
+
)}"].createExtraSafe(
|
|
92
55
|
ctx.$context,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
56
|
+
{
|
|
57
|
+
${collection_fields
|
|
58
|
+
.map((field_info) =>
|
|
59
|
+
field_info.form_field.generateCreateValueGetter(field_info, {
|
|
60
|
+
form_field_types: formFieldsVar,
|
|
61
|
+
sealious_field: `fields${wrapAttribute(field_info.name)}`,
|
|
62
|
+
form_fields: "fields",
|
|
63
|
+
})
|
|
64
|
+
)
|
|
65
|
+
.join(",\n")}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
for(const field of Object.values(${formFieldsVar})){
|
|
69
|
+
await field.postSealiousCreate(ctx, created, formData)
|
|
70
|
+
}
|
|
107
71
|
}
|
|
108
72
|
`,
|
|
109
73
|
render: ` async render(ctx: Context, data: FormData, show_field_errors: boolean) {
|