@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.
Files changed (374) hide show
  1. package/.eslintrc.cjs +7 -2
  2. package/.xunit +75 -0
  3. package/@types/add-crud.d.sync-conflict-20250918-184311-TFDLWFG.ts +1 -0
  4. package/@types/builders/colors-builder.d.sync-conflict-20250918-184323-TFDLWFG.ts +10 -0
  5. package/@types/builders/colors-builder.d.ts +1 -1
  6. package/@types/builders/fonts-builder.d.sync-conflict-20250918-184322-TFDLWFG.ts +7 -0
  7. package/@types/builders/fonts-builder.d.ts +1 -1
  8. package/@types/controllers/table-add-button.d.ts +6 -0
  9. package/@types/controllers/table-add-button.stimulus.d.ts +6 -0
  10. package/@types/crud-field-snippets.d.sync-conflict-20250918-184323-TFDLWFG.ts +1 -0
  11. package/@types/crud-field-snippets.d.ts +1 -3
  12. package/@types/forms/controls/array.d.sync-conflict-20250918-184306-TFDLWFG.ts +33 -0
  13. package/@types/forms/controls/array.d.ts +1 -2
  14. package/@types/forms/controls/array.sync-conflict-20250918-222045-TFDLWFG.d.ts +33 -0
  15. package/@types/forms/controls/autocomplete.d.sync-conflict-20250918-222042-TFDLWFG.ts +22 -0
  16. package/@types/forms/controls/autocomplete.d.ts +1 -1
  17. package/@types/forms/controls/checkbox-group.d.sync-conflict-20250918-184319-TFDLWFG.ts +21 -0
  18. package/@types/forms/controls/checkbox-group.d.ts +3 -3
  19. package/@types/forms/controls/checkboxed-list-input.d.sync-conflict-20250918-184323-TFDLWFG.ts +21 -0
  20. package/@types/forms/controls/checkboxed-list-input.d.ts +3 -3
  21. package/@types/forms/controls/controls.d.ts +2 -2
  22. package/@types/forms/controls/derived-frame.d.sync-conflict-20250918-184314-TFDLWFG.ts +19 -0
  23. package/@types/forms/controls/derived-frame.d.ts +0 -1
  24. package/@types/forms/controls/dropdown.d.sync-conflict-20250918-222044-TFDLWFG.ts +30 -0
  25. package/@types/forms/controls/dropdown.d.ts +1 -1
  26. package/@types/forms/controls/file.d.sync-conflict-20250918-222045-TFDLWFG.ts +13 -0
  27. package/@types/forms/controls/file.d.ts +1 -2
  28. package/@types/forms/controls/form-control.d.sync-conflict-20250918-184322-TFDLWFG.ts +19 -0
  29. package/@types/forms/controls/form-control.d.sync-conflict-20250918-222046-TFDLWFG.ts +19 -0
  30. package/@types/forms/controls/form-control.d.ts +7 -3
  31. package/@types/forms/controls/image.d.ts +19 -0
  32. package/@types/forms/controls/image.test.d.ts +1 -0
  33. package/@types/forms/controls/multiple-files.d.sync-conflict-20250918-184318-TFDLWFG.ts +42 -0
  34. package/@types/forms/controls/multiple-files.d.ts +3 -0
  35. package/@types/forms/controls/multiple-images.d.ts +19 -0
  36. package/@types/forms/controls/number.d.sync-conflict-20250918-222046-TFDLWFG.ts +13 -0
  37. package/@types/forms/controls/number.d.ts +1 -1
  38. package/@types/forms/controls/photo.d.sync-conflict-20250918-184321-TFDLWFG.ts +19 -0
  39. package/@types/forms/controls/photo.d.ts +3 -5
  40. package/@types/forms/controls/simple-input.d.sync-conflict-20250918-184310-TFDLWFG.ts +33 -0
  41. package/@types/forms/controls/simple-input.d.sync-conflict-20250918-222042-TFDLWFG.ts +33 -0
  42. package/@types/forms/controls/simple-input.d.ts +5 -4
  43. package/@types/forms/controls/simple-input.sync-conflict-20250918-222045-TFDLWFG.d.ts +33 -0
  44. package/@types/forms/controls/single-reference.d.ts +3 -2
  45. package/@types/forms/controls/table.d.sync-conflict-20250918-184302-TFDLWFG.ts +39 -0
  46. package/@types/forms/controls/table.d.ts +8 -2
  47. package/@types/forms/controls/table.sync-conflict-20250918-222042-TFDLWFG.d.ts +39 -0
  48. package/@types/forms/controls/textarea.d.sync-conflict-20250918-222045-TFDLWFG.ts +25 -0
  49. package/@types/forms/controls/textarea.d.ts +3 -3
  50. package/@types/forms/fields/boolean.d.sync-conflict-20250918-184325-TFDLWFG.ts +22 -0
  51. package/@types/forms/fields/boolean.d.ts +6 -1
  52. package/@types/forms/fields/boolean.sync-conflict-20250918-222042-TFDLWFG.d.ts +22 -0
  53. package/@types/forms/fields/checkboxed-list.d.sync-conflict-20250918-184325-TFDLWFG.ts +23 -0
  54. package/@types/forms/fields/checkboxed-list.d.ts +3 -1
  55. package/@types/forms/fields/collection-field.d.sync-conflict-20250918-184319-TFDLWFG.ts +22 -0
  56. package/@types/forms/fields/collection-field.d.sync-conflict-20250918-222047-TFDLWFG.ts +22 -0
  57. package/@types/forms/fields/collection-field.d.ts +8 -1
  58. package/@types/forms/fields/color.d.ts +4 -0
  59. package/@types/forms/fields/coordinates.d.sync-conflict-20250918-222044-TFDLWFG.ts +14 -0
  60. package/@types/forms/fields/coordinates.d.ts +14 -0
  61. package/@types/forms/fields/date.d.ts +13 -0
  62. package/@types/forms/fields/datetime.d.sync-conflict-20250918-222050-TFDLWFG.ts +4 -0
  63. package/@types/forms/fields/datetime.d.ts +14 -0
  64. package/@types/forms/fields/deep-reverse-single-reference-list.d.ts +24 -0
  65. package/@types/forms/fields/deep-reverse-single-reference-table.d.ts +16 -0
  66. package/@types/forms/fields/email.d.sync-conflict-20250918-184303-TFDLWFG.ts +8 -0
  67. package/@types/forms/fields/email.d.ts +3 -0
  68. package/@types/forms/fields/enum-multiple-sealious.d.ts +16 -0
  69. package/@types/forms/fields/enum-multiple-sealious.sync-conflict-20250918-222047-TFDLWFG.d.ts +16 -0
  70. package/@types/forms/fields/field.d.sync-conflict-20250918-184306-TFDLWFG.ts +70 -0
  71. package/@types/forms/fields/field.d.ts +37 -5
  72. package/@types/forms/fields/fields.d.sync-conflict-20250918-184314-TFDLWFG.ts +29 -0
  73. package/@types/forms/fields/fields.d.ts +23 -8
  74. package/@types/forms/fields/file.d.sync-conflict-20250918-184310-TFDLWFG.ts +23 -0
  75. package/@types/forms/fields/file.d.sync-conflict-20250918-222046-TFDLWFG.ts +23 -0
  76. package/@types/forms/fields/file.d.ts +11 -5
  77. package/@types/forms/fields/file.sync-conflict-20250918-222049-TFDLWFG.d.ts +23 -0
  78. package/@types/forms/fields/float.d.ts +4 -0
  79. package/@types/forms/fields/get-field-for-sealious.d.sync-conflict-20250918-222046-TFDLWFG.ts +29 -0
  80. package/@types/forms/fields/get-field-for-sealious.d.ts +31 -0
  81. package/@types/forms/fields/get-field-for-sealious.sync-conflict-20250918-222042-TFDLWFG.d.ts +29 -0
  82. package/@types/forms/fields/html.d.ts +6 -0
  83. package/@types/forms/fields/image.d.sync-conflict-20250918-222042-TFDLWFG.ts +5 -0
  84. package/@types/forms/fields/image.d.ts +5 -0
  85. package/@types/forms/fields/int.d.ts +6 -0
  86. package/@types/forms/fields/json.d.ts +13 -0
  87. package/@types/forms/fields/markdown.d.ts +6 -0
  88. package/@types/forms/fields/multiple-files.d.sync-conflict-20250918-184304-TFDLWFG.ts +16 -0
  89. package/@types/forms/fields/multiple-files.d.ts +3 -1
  90. package/@types/forms/fields/number.d.sync-conflict-20250918-184317-TFDLWFG.ts +25 -0
  91. package/@types/forms/fields/number.d.sync-conflict-20250918-222047-TFDLWFG.ts +25 -0
  92. package/@types/forms/fields/number.d.ts +3 -1
  93. package/@types/forms/fields/password.d.ts +6 -0
  94. package/@types/forms/fields/pick-from-list-sealious.d.ts +11 -0
  95. package/@types/forms/fields/pick-from-list.d.sync-conflict-20250918-184322-TFDLWFG.ts +15 -0
  96. package/@types/forms/fields/pick-from-list.d.ts +4 -3
  97. package/@types/forms/fields/proxy-field.d.sync-conflict-20250918-184307-TFDLWFG.ts +15 -0
  98. package/@types/forms/fields/proxy-field.d.ts +3 -1
  99. package/@types/forms/fields/regexp.d.sync-conflict-20250918-184305-TFDLWFG.ts +21 -0
  100. package/@types/forms/fields/regexp.d.sync-conflict-20250918-222045-TFDLWFG.ts +21 -0
  101. package/@types/forms/fields/regexp.d.ts +6 -1
  102. package/@types/forms/fields/regexp.sync-conflict-20250918-222047-TFDLWFG.d.ts +21 -0
  103. package/@types/forms/fields/simple-form-field.d.sync-conflict-20250918-184309-TFDLWFG.ts +29 -0
  104. package/@types/forms/fields/simple-form-field.d.sync-conflict-20250918-222044-TFDLWFG.ts +29 -0
  105. package/@types/forms/fields/simple-form-field.d.ts +23 -3
  106. package/@types/forms/fields/simple-form-field.sync-conflict-20250918-222049-TFDLWFG.d.ts +29 -0
  107. package/@types/forms/fields/single-reference.d.ts +19 -0
  108. package/@types/forms/fields/single-reference.sync-conflict-20250918-222043-TFDLWFG.d.ts +10 -0
  109. package/@types/forms/fields/structured-array.d.sync-conflict-20250918-184302-TFDLWFG.ts +27 -0
  110. package/@types/forms/fields/structured-array.d.sync-conflict-20250918-222049-TFDLWFG.ts +27 -0
  111. package/@types/forms/fields/structured-array.d.ts +19 -10
  112. package/@types/forms/fields/structured-array.sync-conflict-20250918-222047-TFDLWFG.d.ts +27 -0
  113. package/@types/forms/fields/table.d.sync-conflict-20250918-184303-TFDLWFG.ts +16 -0
  114. package/@types/forms/fields/table.d.ts +3 -0
  115. package/@types/forms/fields/text.d.ts +6 -0
  116. package/@types/forms/fields/url.d.ts +6 -0
  117. package/@types/forms/form-types.d.sync-conflict-20250918-222045-TFDLWFG.ts +26 -0
  118. package/@types/forms/form-types.d.ts +2 -0
  119. package/@types/forms/form.d.sync-conflict-20250918-184315-TFDLWFG.ts +32 -0
  120. package/@types/forms/form.d.sync-conflict-20250918-222049-TFDLWFG.ts +32 -0
  121. package/@types/forms/form.d.ts +10 -7
  122. package/@types/forms/form.sync-conflict-20250918-222049-TFDLWFG.d.ts +33 -0
  123. package/@types/forms/form.test.d.sync-conflict-20250918-184318-TFDLWFG.ts +6 -0
  124. package/@types/forms/form.test.d.sync-conflict-20250918-222047-TFDLWFG.ts +6 -0
  125. package/@types/forms/form.test.d.ts +2 -2
  126. package/@types/forms/multiform.d.sync-conflict-20250918-184308-TFDLWFG.ts +23 -0
  127. package/@types/forms/multiform.d.ts +1 -1
  128. package/@types/forms/multiform.sync-conflict-20250918-222044-TFDLWFG.d.ts +23 -0
  129. package/@types/index.d.sync-conflict-20250918-184316-TFDLWFG.ts +46 -0
  130. package/@types/index.d.ts +2 -2
  131. package/@types/mount.d.sync-conflict-20250918-184320-TFDLWFG.ts +6 -0
  132. package/@types/page/list.d.sync-conflict-20250918-184318-TFDLWFG.ts +48 -0
  133. package/@types/page/list.d.sync-conflict-20250918-222046-TFDLWFG.ts +48 -0
  134. package/@types/page/list.d.ts +2 -2
  135. package/@types/page/list.sync-conflict-20250918-222048-TFDLWFG.d.ts +48 -0
  136. package/@types/page/mountable-with-fields.d.sync-conflict-20250918-184321-TFDLWFG.ts +42 -0
  137. package/@types/page/mountable-with-fields.d.sync-conflict-20250918-222046-TFDLWFG.ts +42 -0
  138. package/@types/page/mountable-with-fields.d.ts +3 -3
  139. package/@types/page/mountable-with-fields.sync-conflict-20250918-222044-TFDLWFG.d.ts +42 -0
  140. package/@types/page/mountable.d.sync-conflict-20250918-184306-TFDLWFG.ts +10 -0
  141. package/@types/page/page.d.sync-conflict-20250918-184320-TFDLWFG.ts +18 -0
  142. package/@types/page/props-parser.d.sync-conflict-20250918-184305-TFDLWFG.ts +15 -0
  143. package/@types/page/props-parser.d.ts +0 -1
  144. package/@types/page/stateful-page.d.sync-conflict-20250918-184326-TFDLWFG.ts +62 -0
  145. package/@types/templates/shared/shared-crud-form-fields.d.sync-conflict-20250918-184306-TFDLWFG.ts +1 -0
  146. package/@types/templates/shared/shared-crud-form-fields.d.ts +0 -67
  147. package/@types/test_utils/test-on-real-app.d.sync-conflict-20250918-184320-TFDLWFG.ts +26 -0
  148. package/@types/test_utils/test-on-real-app.d.ts +0 -1
  149. package/@types/utils/extract-fields-from-collection.d.sync-conflict-20250918-184312-TFDLWFG.ts +18 -0
  150. package/@types/utils/extract-fields-from-collection.d.ts +5 -1
  151. package/@types/utils/extract-fields-from-collection.sync-conflict-20250918-222045-TFDLWFG.d.ts +18 -0
  152. package/@types/utils/wrap-attributes.d.ts +3 -0
  153. package/README.md +5 -0
  154. package/assets/file-icon.svg +5 -0
  155. package/lib/add-crud.js +80 -89
  156. package/lib/add-list-route.test.js +1 -1
  157. package/lib/add-route.js +0 -7
  158. package/lib/build.js +3 -1
  159. package/lib/cli.js +2 -5
  160. package/lib/controllers/table-add-button.stimulus.js +35 -0
  161. package/lib/forms/controls/array.js +20 -16
  162. package/lib/forms/controls/big-radio-group.js +2 -2
  163. package/lib/forms/controls/checkbox-group.js +7 -7
  164. package/lib/forms/controls/checkboxed-list-input.js +9 -2
  165. package/lib/forms/controls/controls.js +2 -2
  166. package/lib/forms/controls/derived-frame.js +5 -1
  167. package/lib/forms/controls/derived.js +1 -1
  168. package/lib/forms/controls/dropdown.js +4 -1
  169. package/lib/forms/controls/editable-collection-subset.js +2 -2
  170. package/lib/forms/controls/file.js +26 -2
  171. package/lib/forms/controls/file.test.js +2 -2
  172. package/lib/forms/controls/hidden-input.js +4 -1
  173. package/lib/forms/controls/{photo.js → image.js} +6 -7
  174. package/lib/forms/controls/{photo.test.js → image.test.js} +6 -21
  175. package/lib/forms/controls/multiple-files.js +10 -1
  176. package/lib/forms/controls/{multiple-photos.js → multiple-images.js} +3 -3
  177. package/lib/forms/controls/simple-input.js +13 -12
  178. package/lib/forms/controls/single-reference.js +4 -0
  179. package/lib/forms/controls/table.js +66 -24
  180. package/lib/forms/controls/textarea.js +4 -2
  181. package/lib/forms/controls/tickable.js +13 -5
  182. package/lib/forms/fields/boolean.js +14 -0
  183. package/lib/forms/fields/checkboxed-list.js +4 -0
  184. package/lib/forms/fields/collection-field.js +9 -0
  185. package/lib/forms/fields/color.js +10 -0
  186. package/lib/forms/fields/coordinates.js +49 -0
  187. package/lib/forms/fields/date.js +34 -0
  188. package/lib/forms/fields/datetime.js +46 -0
  189. package/lib/forms/fields/deep-reverse-single-reference-list.js +81 -0
  190. package/lib/forms/fields/deep-reverse-single-reference-table.js +122 -0
  191. package/lib/forms/fields/email.js +7 -0
  192. package/lib/forms/fields/enum-multiple-sealious.js +32 -0
  193. package/lib/forms/fields/field.js +32 -4
  194. package/lib/forms/fields/field.test.js +5 -5
  195. package/lib/forms/fields/fields.js +23 -8
  196. package/lib/forms/fields/file.js +33 -9
  197. package/lib/forms/fields/file.test.js +4 -16
  198. package/lib/forms/fields/float.js +10 -0
  199. package/lib/forms/fields/get-field-for-sealious.js +213 -0
  200. package/lib/forms/fields/html.js +14 -0
  201. package/lib/forms/fields/image.js +13 -0
  202. package/lib/forms/fields/int.js +23 -0
  203. package/lib/forms/fields/json.js +31 -0
  204. package/lib/forms/fields/markdown.js +14 -0
  205. package/lib/forms/fields/multiple-files.js +4 -0
  206. package/lib/forms/fields/number.js +6 -0
  207. package/lib/forms/fields/password.js +13 -0
  208. package/lib/forms/fields/pick-from-list-sealious.js +17 -0
  209. package/lib/forms/fields/pick-from-list.js +6 -2
  210. package/lib/forms/fields/proxy-field.js +3 -0
  211. package/lib/forms/fields/regexp.js +14 -0
  212. package/lib/forms/fields/simple-form-field.js +60 -2
  213. package/lib/forms/fields/single-reference.js +44 -0
  214. package/lib/forms/fields/structured-array.js +63 -12
  215. package/lib/forms/fields/table.js +28 -1
  216. package/lib/forms/fields/text.js +17 -0
  217. package/lib/forms/fields/url.js +17 -0
  218. package/lib/forms/form.js +30 -13
  219. package/lib/forms/form.test.js +3 -4
  220. package/lib/forms/multiform.js +4 -2
  221. package/lib/forms/multiform.test.js +3 -3
  222. package/lib/generate-stimulus.js +1 -0
  223. package/lib/index.js +1 -0
  224. package/lib/make-hidden-inputs.js +1 -1
  225. package/lib/mount.js +11 -0
  226. package/lib/notifier.js +0 -1
  227. package/lib/page/list.js +15 -8
  228. package/lib/page/mountable-with-fields.js +14 -6
  229. package/lib/page/mountable-with-fields.test.js +1 -1
  230. package/lib/templates/form.js +8 -9
  231. package/lib/templates/multiform.js +4 -4
  232. package/lib/templates/page.js +0 -2
  233. package/lib/templates/shared/collection-create-form.js +28 -40
  234. package/lib/templates/shared/collection-edit-form.js +40 -77
  235. package/lib/templates/shared/collection-list.js +12 -20
  236. package/lib/templates/shared/shared-crud-form-fields.js +27 -95
  237. package/lib/test_utils/test-on-real-app.js +3 -3
  238. package/lib/utils/extract-fields-from-collection.js +60 -20
  239. package/lib/utils/make-slug.js +1 -1
  240. package/lib/utils/wrap-attributes.js +20 -0
  241. package/package.json +5 -4
  242. package/src/add-crud.ts +86 -97
  243. package/src/add-list-route.test.ts +1 -1
  244. package/src/add-route.ts +0 -7
  245. package/src/build.ts +3 -1
  246. package/src/cli.ts +3 -5
  247. package/src/controllers/table-add-button.stimulus.ts +35 -0
  248. package/src/forms/controls/array.ts +23 -20
  249. package/src/forms/controls/autocomplete.ts +1 -1
  250. package/src/forms/controls/big-radio-group.ts +2 -2
  251. package/src/forms/controls/checkbox-group.ts +9 -9
  252. package/src/forms/controls/checkboxed-list-input.ts +27 -15
  253. package/src/forms/controls/controls.ts +2 -2
  254. package/src/forms/controls/derived-frame.ts +5 -1
  255. package/src/forms/controls/derived.ts +1 -1
  256. package/src/forms/controls/dropdown.ts +5 -2
  257. package/src/forms/controls/editable-collection-subset.ts +2 -2
  258. package/src/forms/controls/file.test.ts +4 -2
  259. package/src/forms/controls/file.ts +31 -5
  260. package/src/forms/controls/form-control.ts +7 -2
  261. package/src/forms/controls/hidden-input.ts +4 -1
  262. package/src/forms/controls/{photo.test.ts → image.test.ts} +5 -22
  263. package/src/forms/controls/{photo.ts → image.ts} +3 -5
  264. package/src/forms/controls/multiple-files.ts +18 -1
  265. package/src/forms/controls/{multiple-photos.ts → multiple-images.ts} +1 -1
  266. package/src/forms/controls/number.ts +1 -1
  267. package/src/forms/controls/simple-input.ts +18 -34
  268. package/src/forms/controls/single-reference.ts +10 -2
  269. package/src/forms/controls/table.ts +90 -31
  270. package/src/forms/controls/textarea.ts +6 -4
  271. package/src/forms/controls/tickable.ts +13 -5
  272. package/src/forms/fields/boolean.ts +23 -1
  273. package/src/forms/fields/checkboxed-list.ts +11 -2
  274. package/src/forms/fields/collection-field.ts +16 -1
  275. package/src/forms/fields/color.ts +9 -0
  276. package/src/forms/fields/coordinates.ts +66 -0
  277. package/src/forms/fields/date.ts +50 -0
  278. package/src/forms/fields/datetime.ts +66 -0
  279. package/src/forms/fields/deep-reverse-single-reference-list.ts +136 -0
  280. package/src/forms/fields/deep-reverse-single-reference-table.ts +213 -0
  281. package/src/forms/fields/email.ts +9 -0
  282. package/src/forms/fields/enum-multiple-sealious.ts +48 -0
  283. package/src/forms/fields/field.test.ts +5 -5
  284. package/src/forms/fields/field.ts +94 -8
  285. package/src/forms/fields/fields.ts +23 -8
  286. package/src/forms/fields/file.test.ts +4 -16
  287. package/src/forms/fields/file.ts +43 -15
  288. package/src/forms/fields/float.ts +9 -0
  289. package/src/forms/fields/get-field-for-sealious.ts +304 -0
  290. package/src/forms/fields/html.ts +15 -0
  291. package/src/forms/fields/image.ts +12 -0
  292. package/src/forms/fields/int.ts +25 -0
  293. package/src/forms/fields/json.ts +48 -0
  294. package/src/forms/fields/markdown.ts +15 -0
  295. package/src/forms/fields/multiple-files.ts +10 -1
  296. package/src/forms/fields/number.ts +8 -1
  297. package/src/forms/fields/password.ts +17 -0
  298. package/src/forms/fields/pick-from-list-sealious.ts +22 -0
  299. package/src/forms/fields/pick-from-list.ts +7 -3
  300. package/src/forms/fields/proxy-field.ts +6 -1
  301. package/src/forms/fields/regexp.ts +27 -1
  302. package/src/forms/fields/simple-form-field.ts +95 -7
  303. package/src/forms/fields/single-reference.ts +62 -0
  304. package/src/forms/fields/structured-array.ts +115 -18
  305. package/src/forms/fields/table.ts +32 -1
  306. package/src/forms/fields/text.ts +18 -0
  307. package/src/forms/fields/url.ts +20 -0
  308. package/src/forms/form-types.ts +2 -0
  309. package/src/forms/form.test.ts +3 -4
  310. package/src/forms/form.ts +37 -16
  311. package/src/forms/forms.css +0 -85
  312. package/src/forms/multiform.test.ts +3 -3
  313. package/src/forms/multiform.ts +2 -0
  314. package/src/generate-stimulus.ts +1 -0
  315. package/src/index.ts +2 -1
  316. package/src/make-hidden-inputs.ts +1 -1
  317. package/src/mount.ts +14 -0
  318. package/src/notifier.ts +0 -1
  319. package/src/page/list.ts +15 -8
  320. package/src/page/mountable-with-fields.test.ts +1 -1
  321. package/src/page/mountable-with-fields.ts +18 -9
  322. package/src/register-external.ts +1 -1
  323. package/src/templates/form.ts +8 -9
  324. package/src/templates/multiform.ts +4 -4
  325. package/src/templates/page.ts +0 -2
  326. package/src/templates/shared/collection-create-form.ts +30 -66
  327. package/src/templates/shared/collection-edit-form.ts +41 -102
  328. package/src/templates/shared/collection-list.ts +12 -20
  329. package/src/templates/shared/item-delete.ts +0 -1
  330. package/src/templates/shared/shared-crud-form-fields.ts +37 -171
  331. package/src/test_utils/test-on-real-app.ts +4 -3
  332. package/src/utils/extract-fields-from-collection.ts +76 -25
  333. package/src/utils/make-slug.ts +1 -1
  334. package/src/utils/wrap-attributes.ts +17 -0
  335. package/lib/add-verbose-crud.js +0 -119
  336. package/lib/crud-field-snippets.js +0 -52
  337. package/lib/find-css-includes.js +0 -3
  338. package/lib/forms/controls/reverse-single-reference.js +0 -1
  339. package/lib/forms/fields/enum-multiple.js +0 -47
  340. package/lib/forms/fields/enum-multiple.test.js +0 -27
  341. package/lib/forms/fields/enum.js +0 -41
  342. package/lib/forms/fields/enum.test.js +0 -21
  343. package/lib/forms/fields/reverse-single-reference.js +0 -17
  344. package/lib/templates/shared/handlers/boolean.js +0 -14
  345. package/lib/templates/shared/handlers/date.js +0 -8
  346. package/lib/templates/shared/handlers/deep-reverse-single-reference.js +0 -209
  347. package/lib/templates/shared/handlers/default.js +0 -49
  348. package/lib/templates/shared/handlers/enum.js +0 -19
  349. package/lib/templates/shared/handlers/file.js +0 -23
  350. package/lib/templates/shared/handlers/image.js +0 -32
  351. package/lib/templates/shared/handlers/int.js +0 -11
  352. package/lib/templates/shared/handlers/jdd.js +0 -10
  353. package/lib/templates/shared/handlers/single-reference.js +0 -12
  354. package/lib/templates/shared/handlers/structured-array.js +0 -33
  355. package/src/add-verbose-crud.ts +0 -138
  356. package/src/crud-field-snippets.ts +0 -57
  357. package/src/find-css-includes.ts +0 -3
  358. package/src/forms/controls/reverse-single-reference.ts +0 -50
  359. package/src/forms/fields/enum-multiple.test.ts +0 -31
  360. package/src/forms/fields/enum-multiple.ts +0 -62
  361. package/src/forms/fields/enum.test.ts +0 -25
  362. package/src/forms/fields/enum.ts +0 -56
  363. package/src/forms/fields/reverse-single-reference.ts +0 -20
  364. package/src/templates/shared/handlers/boolean.ts +0 -18
  365. package/src/templates/shared/handlers/date.ts +0 -12
  366. package/src/templates/shared/handlers/deep-reverse-single-reference.ts +0 -244
  367. package/src/templates/shared/handlers/default.ts +0 -64
  368. package/src/templates/shared/handlers/enum.ts +0 -23
  369. package/src/templates/shared/handlers/file.ts +0 -27
  370. package/src/templates/shared/handlers/image.ts +0 -45
  371. package/src/templates/shared/handlers/int.ts +0 -15
  372. package/src/templates/shared/handlers/jdd.ts +0 -14
  373. package/src/templates/shared/handlers/single-reference.ts +0 -16
  374. package/src/templates/shared/handlers/structured-array.ts +0 -42
@@ -13,14 +13,15 @@ class MountableWithFields extends Mountable {
13
13
  this.fields = {};
14
14
  }
15
15
  init() {
16
- for (const [name, field] of Object.entries(this.fields)) {
17
- void field.init(name);
16
+ for (const [field_name, field] of Object.entries(this.fields)) {
17
+ void field.init();
18
+ field.setName(field_name);
18
19
  }
19
20
  }
20
21
  makeFormControlContext(ctx, data, validate, field_name_prefix = this.field_names_prefix, form_id = this.form_id) {
21
22
  return new FormControlContext(
22
23
  ctx,
23
- data.raw_values,
24
+ data,
24
25
  data.messages,
25
26
  field_name_prefix,
26
27
  form_id,
@@ -44,10 +45,13 @@ class MountableWithFields extends Mountable {
44
45
  await Promise.all(
45
46
  Object.keys(this.fields).map(async (key) => {
46
47
  const field = this.fields[key];
47
- const { valid: fieldvalid, message: fieldmessage } = await field.getValue(ctx, values, true);
48
+ const { valid: fieldvalid, message: fieldmessage } = await field.getParsedValue(ctx, values, true);
48
49
  if (!fieldvalid) {
49
50
  valid = false;
50
- field_errors[field.name] = fieldmessage;
51
+ field_errors[field.name] = {
52
+ type: "error",
53
+ message: fieldmessage
54
+ };
51
55
  }
52
56
  })
53
57
  );
@@ -81,7 +85,11 @@ class MountableWithFields extends Mountable {
81
85
  const result = {};
82
86
  const promises = Object.entries(this.fields).map(
83
87
  async ([key, field]) => {
84
- const { parsed } = await field.getValue(ctx, raw_values, false);
88
+ const { parsed } = await field.getParsedValue(
89
+ ctx,
90
+ raw_values,
91
+ false
92
+ );
85
93
  result[key] = parsed;
86
94
  }
87
95
  );
@@ -17,7 +17,7 @@ describe("mountable-with-fields", () => {
17
17
  const data = await this.getParsedValues(ctx);
18
18
  data.not_required?.trim();
19
19
  data.required.trim();
20
- const { parsed: data2 } = await this.fields.not_required.getValue(
20
+ const { parsed: data2 } = await this.fields.not_required.getParsedValue(
21
21
  ctx,
22
22
  form_values.raw_values
23
23
  );
@@ -1,12 +1,10 @@
1
- import Prettier from "prettier";
2
- import { curryImportPath } from "../utils/import-path.js";
3
- import { getPrettierConfig } from "../utils/prettier.js";
1
+ import { formatWithPrettier } from "../utils/prettier.js";
4
2
  const defaults = {
5
3
  postimport: `
6
4
  import { Fields } from "@sealcode/sealgen";
7
5
  import type {FormDataValue} from "@sealcode/sealgen";`,
8
6
  fields: `
9
- password: new Fields.SimpleFormField(true),`,
7
+ password: new Fields.Password(true),`,
10
8
  controls: `
11
9
  new Controls.SimpleInput(fields.password, {
12
10
  label: "Password:",
@@ -17,8 +15,8 @@ const defaults = {
17
15
  data: Record<string, FormDataValue>
18
16
  ): Promise<{ valid: boolean; error: string }> {
19
17
  // just a silly example, please remove this with better logic
20
- const { parsed: email } = await this.fields.email.getValue(ctx, data);
21
- const { parsed: password } = await this.fields.password.getValue(ctx, data);
18
+ const { parsed: email } = await this.fields.email.getParsedValue(ctx, data);
19
+ const { parsed: password } = await this.fields.password.getParsedValue(ctx, data);
22
20
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
23
21
  if ((password || "").length > ((email as string) || "").length) {
24
22
  return { valid: false, error: "Password cannot be longer than email" };
@@ -43,11 +41,10 @@ const defaults = {
43
41
  };
44
42
  async function formTemplate(action_name, newfilefullpath, _params = defaults) {
45
43
  const params = { ...defaults, ..._params };
46
- const rel = curryImportPath(newfilefullpath);
47
44
  const content = `import type { Context } from "koa";
48
45
  import type { FormData } from "@sealcode/sealgen";
49
46
  import { Form, Controls, fieldsToShape } from "@sealcode/sealgen";
50
- import html from "${rel("src/back/html.js")}";
47
+ import html from "src/back/html.js";
51
48
 
52
49
  ${params.postimport}
53
50
 
@@ -57,6 +54,8 @@ const fields = {
57
54
  ${params.fields}
58
55
  };
59
56
 
57
+ Form.initFieldNames(fields);
58
+
60
59
  export const ${action_name}Shape = fieldsToShape(fields);
61
60
 
62
61
  export default new (class ${action_name}Form extends Form<typeof fields, void> {
@@ -78,7 +77,7 @@ export default new (class ${action_name}Form extends Form<typeof fields, void> {
78
77
  ${params.render}
79
78
  })();
80
79
  `;
81
- return Prettier.format(content, await getPrettierConfig());
80
+ return formatWithPrettier(content);
82
81
  }
83
82
  export {
84
83
  formTemplate
@@ -9,8 +9,8 @@ import { FlatTemplatable } from "tempstream";
9
9
  export const actionName = "${action_name}";
10
10
 
11
11
  const fields1 = {
12
- email: new Fields.SimpleFormField(true),
13
- password: new Fields.SimpleFormField(true),
12
+ email: new Fields.TextBasedSimpleField(true),
13
+ password: new Fields.TextBasedSimpleField(true),
14
14
  };
15
15
 
16
16
  const form1 = new (class extends Form<typeof fields1, unknown> {
@@ -26,8 +26,8 @@ const form1 = new (class extends Form<typeof fields1, unknown> {
26
26
  })();
27
27
 
28
28
  const fields2 = {
29
- name: new Fields.SimpleFormField(true),
30
- surname: new Fields.SimpleFormField(true),
29
+ name: new Fields.TextBasedSimpleField(true),
30
+ surname: new Fields.TextBasedSimpleField(true),
31
31
  };
32
32
 
33
33
  const form2 = new (class extends Form<typeof fields2, unknown> {
@@ -1,6 +1,4 @@
1
- import { curryImportPath } from "../utils/import-path.js";
2
1
  async function pageTemplate(action_name, newfilefullpath) {
3
- const rel = curryImportPath(newfilefullpath);
4
2
  return `import type { Context } from "koa";
5
3
  import { TempstreamJSX } from "tempstream";
6
4
  import { Page } from "@sealcode/sealgen";
@@ -1,70 +1,58 @@
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
  import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
5
- import { getFieldHandler } from "./shared-crud-form-fields.js";
4
+ import { wrapAttribute } from "../../utils/wrap-attributes.js";
6
5
  async function createItemFormTemplate(create_action_name, newfilefullpath, collection_name, list_action) {
7
6
  const collection_fields = await extract_fields_from_collection(
8
7
  collection_name
9
8
  );
10
- const importPath = curryImportPath(newfilefullpath);
11
- const field_handler_results = await Promise.all(
12
- collection_fields.map(
13
- (field) => getFieldHandler(collection_name, field, importPath)
14
- )
15
- );
16
- const post_create_actions = field_handler_results.map(({ post_create }) => post_create).filter((e) => e != "");
9
+ const formFieldsVar = `${toPascalCase(collection_name)}FormFields`;
17
10
  return formTemplate(create_action_name, newfilefullpath, {
18
11
  success_message: "Created!",
19
- postimport: `import {${toPascalCase(
20
- collection_name
21
- )}FormFields, ${toPascalCase(
12
+ postimport: `import {${formFieldsVar}, get${toPascalCase(
22
13
  collection_name
23
14
  )}FormControls }from "./shared.js";
24
15
 
25
- import { ${toPascalCase(collection_name)} } from "${importPath(
26
- "src/back/collections/collections.js"
27
- )}";
28
-
29
- import { ${list_action}URL } from "${importPath("src/back/routes/urls.js")}";
16
+ import { ${toPascalCase(
17
+ collection_name
18
+ )} } from "src/back/collections/collections.js";
30
19
 
31
- import {tempstream} from "tempstream";
20
+ import { ${list_action}URL } from "src/back/routes/urls.js";
21
+ import {tempstream} from "tempstream";
32
22
  `,
33
23
  fields: `...${toPascalCase(collection_name)}FormFields`,
34
24
  controls: `
35
25
  new Controls.FormHeader("Create ${toPascalCase(
36
26
  collection_name
37
27
  )}"),
38
- ...${toPascalCase(collection_name)}FormControls`,
28
+ ...get${toPascalCase(collection_name)}FormControls()`,
39
29
  can_access: `canAccess = async (ctx: Context) => {
40
30
  const policy = ${toPascalCase(collection_name)}.getPolicy("create");
41
31
  const response = await policy.check(ctx.$context);
42
32
  return { canAccess: response?.allowed || false, message: response?.reason || "" };
43
33
  };`,
44
- get_initial_values: field_handler_results.filter((r) => !r.hide_initial_value_create).map(({ initial_value_create }) => initial_value_create).filter((e) => e != "").length ? `getInitialValues(ctx: Context){
45
- return {
46
- ${field_handler_results.filter((r) => !r.hide_initial_value_create).map(
47
- ({ initial_value_create }) => initial_value_create
48
- ).join(",\n")}
49
- }
50
- }` : ``,
34
+ get_initial_values: "",
51
35
  onsubmit: `
52
- async onSubmit(ctx: Context) {
53
- const data = await this.getParsedValues(ctx);
54
- if (!data) {
55
- throw new Error("Error when parsing the form values");
56
- }
36
+ async onSubmit(ctx: Context, formData: FormData) {
37
+ const fctx = this.makeFormControlContext(ctx, formData, true);
57
38
 
58
- ${field_handler_results.map(({ pre_create }) => pre_create).filter((e) => e !== "").join("\n")}
59
-
60
- ${post_create_actions.length ? `const created = ` : ""} await ctx.$app.collections["${toKebabCase(collection_name)}"].create(
39
+ const created = await ctx.$app.collections["${toKebabCase(
40
+ collection_name
41
+ )}"].createExtraSafe(
61
42
  ctx.$context,
62
- {
63
- ${field_handler_results.filter((result) => !result.hide_sealious_value).map((result) => result.sealious_value(result)).filter((e) => e != "").join(",\n")}
64
- }
65
- );
66
- ${post_create_actions.length ? `/* ==== POST CREATE ACTIONS ==== */` : ""}
67
- ${post_create_actions.join("\n")}
43
+ {
44
+ ${collection_fields.map(
45
+ (field_info) => field_info.form_field.generateCreateValueGetter(field_info, {
46
+ form_field_types: formFieldsVar,
47
+ sealious_field: `fields${wrapAttribute(field_info.name)}`,
48
+ form_fields: "fields"
49
+ })
50
+ ).join(",\n")}
51
+ });
52
+
53
+ for(const field of Object.values(${formFieldsVar})){
54
+ await field.postSealiousCreate(ctx, created, formData)
55
+ }
68
56
  }
69
57
  `,
70
58
  render: ` async render(ctx: Context, data: FormData, show_field_errors: boolean) {
@@ -1,53 +1,38 @@
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
  import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
5
- import { getFieldHandler } from "./shared-crud-form-fields.js";
4
+ import { wrapAttribute } from "../../utils/wrap-attributes.js";
6
5
  async function editItemFormTemplate(edit_action_name, newfilefullpath, collection_name, list_action) {
7
6
  const collection_fields = await extract_fields_from_collection(
8
7
  collection_name
9
8
  );
10
- const importPath = curryImportPath(newfilefullpath);
11
- const field_handler_results = await Promise.all(
12
- collection_fields.map(async (field) => {
13
- return getFieldHandler(collection_name, field, importPath);
14
- })
15
- );
9
+ const formFieldsVar = `${toPascalCase(collection_name)}FormFields`;
10
+ const collectionVar = `${toPascalCase(collection_name)}`;
16
11
  return formTemplate(edit_action_name, newfilefullpath, {
17
12
  success_message: "Changes saved!",
18
- postimport: `import {${toPascalCase(
19
- collection_name
20
- )}FormFields, ${toPascalCase(
13
+ postimport: `import {${formFieldsVar}, get${toPascalCase(
21
14
  collection_name
22
15
  )}FormControls }from "../shared.js";
23
- import { ${toPascalCase(collection_name)} } from "${importPath(
24
- "src/back/collections/collections.js"
25
- )}";
26
- import { ${list_action}URL, ${edit_action_name}URL } from "${importPath(
27
- "src/back/routes/urls.js"
28
- )}";
29
- import {tempstream} from "tempstream";
30
-
31
- ${Array.from(
32
- new Set(field_handler_results.map(({ imports }) => imports.edit))
33
- ).join("\n")}
34
-
35
- ${collection_fields.filter((e) => !e.is_required).length ? `import {withFallback} from "@sealcode/sealgen";` : ""}
16
+ import { ${collectionVar} } from "src/back/collections/collections.js";
17
+ import { ${list_action}URL } from "src/back/routes/urls.js";
18
+ import {tempstream} from "tempstream";
19
+ import type { FormDataValue } from "@sealcode/sealgen";
20
+ import type { CollectionInputWithAllKeys } from "sealious";
36
21
  `,
37
22
  fields: `...${toPascalCase(collection_name)}FormFields`,
38
23
  controls: `
39
24
  new Controls.FormHeader("Edit ${toPascalCase(
40
25
  collection_name
41
26
  )}"),
42
- ...${toPascalCase(collection_name)}FormControls`,
27
+ ...get${toPascalCase(collection_name)}FormControls()`,
43
28
  can_access: `canAccess = async (ctx: Context) => {
44
29
  const policy = ${toPascalCase(collection_name)}.getPolicy("edit");
45
30
  const response = await policy.check(ctx.$context);
46
31
  return { canAccess: response?.allowed || false, message: response?.reason || "" };
47
32
  };`,
48
33
  onsubmit: `
49
- async onSubmit(ctx: Context) {
50
- const data = await this.getParsedValues(ctx);
34
+ async onSubmit(ctx: Context, formData: FormData) {
35
+ const fctx = this.makeFormControlContext(ctx, formData, true);
51
36
  const id = await this.getID(ctx);
52
37
  const {items: [item]} = await ctx.$app.collections["${toKebabCase(
53
38
  collection_name
@@ -60,33 +45,34 @@ async function editItemFormTemplate(edit_action_name, newfilefullpath, collectio
60
45
  throw new Error("Unknown id: " + id);
61
46
  }
62
47
 
63
- if (!data) {
64
- throw new Error("Error when parsing the form values");
65
- }
66
-
67
- ${field_handler_results.map((result) => result.pre_edit).filter((e) => e !== "").join("\n")}
68
48
 
69
- item.setMultiple(
70
- {
71
- ${field_handler_results.filter((r) => !r.hide_sealious_value).map((result) => result.sealious_value(result)).filter((e) => e != "").join(",\n")}
72
- }
49
+ item.setMultipleExtraSafe(
50
+ {
51
+ ${collection_fields.map(
52
+ (field_info) => field_info.form_field.generateCreateValueGetter(
53
+ field_info,
54
+ {
55
+ form_field_types: "FormFieldTypes",
56
+ sealious_field: `${collectionVar}.fields${wrapAttribute(
57
+ field_info.name
58
+ )}`,
59
+ form_fields: "fields"
60
+ }
61
+ )
62
+ ).join(",\n")}
63
+ } as CollectionInputWithAllKeys<typeof ${collectionVar}>
73
64
  );
65
+
74
66
  await item.save(ctx.$context);
75
67
 
76
-
77
- ${field_handler_results.map((result) => result.post_edit).filter((e) => e != "").length ? `// #### POST-EDIT ACTIONS ############` : ""}
78
- ${field_handler_results.map((result) => result.post_edit).filter((e) => e != "").join("\n")}
68
+ for(const field of Object.values(${formFieldsVar})){
69
+ await field.postSealiousEdit(ctx, item, formData)
70
+ }
79
71
  }
80
72
  `,
81
73
  other_methods: `
82
74
  async getID(ctx: Context): Promise<string>{
83
- // trying to automatically guess which param is the one that represents the ID
84
- // of the resource to edit.
85
- // If sealgen got it wrong, just return the param name that should be used here instead
86
- const param_name =
87
- ${edit_action_name}URL.params
88
- .find(param => param.toLowerCase().includes("id"))
89
- || ${edit_action_name}URL.params[0]
75
+ const param_name = "id";
90
76
  const id = ctx.params[param_name];
91
77
  if (!id) {
92
78
  throw new Error("Missing URL parameter: " + param_name);
@@ -94,7 +80,7 @@ async function editItemFormTemplate(edit_action_name, newfilefullpath, collectio
94
80
  return id
95
81
  }
96
82
  `,
97
- get_initial_values: `async getInitialValues(ctx: Context) {
83
+ get_initial_values: `async getInitialValues(ctx: Context): Promise<{ [key in keyof typeof fields]: FormDataValue | undefined }> {
98
84
  const id = await this.getID(ctx);
99
85
 
100
86
  const {
@@ -110,36 +96,13 @@ async function editItemFormTemplate(edit_action_name, newfilefullpath, collectio
110
96
  }
111
97
 
112
98
  return {
113
- ${field_handler_results.filter((r) => !r.hide_initial_value_edit).map(({ initial_value_edit, is_required, name }) => {
114
- if (typeof initial_value_edit == "string") {
115
- if (initial_value_edit == "") {
116
- return "";
117
- }
118
- return `${name}: ${initial_value_edit}`;
119
- }
120
- const main_value = initial_value_edit.main_value;
121
- if (!main_value) {
122
- throw new Error(
123
- "Missing main_value for initial_value_edit"
124
- );
125
- }
126
- const { parsed_value, fallback_value } = initial_value_edit;
127
- if (is_required) {
128
- return `${name}: ${parsed_value || main_value}`;
129
- }
130
- if (main_value && parsed_value && fallback_value) {
131
- if (main_value == parsed_value) {
132
- return `${name}: withFallback(${main_value}, ${fallback_value})`;
133
- } else {
134
- return `${name}: withFallback(${main_value}, ${parsed_value}, ${fallback_value})`;
135
- }
136
- } else {
137
- console.error(initial_value_edit);
138
- throw new Error(
139
- "Missing field info for generating initial value"
140
- );
141
- }
142
- }).filter((e) => e.trim() !== "").join(",\n")}
99
+
100
+ ${collection_fields.map(
101
+ (field_info) => field_info.form_field.generateInitialValue(field_info, {
102
+ form_field_types: "FieldTypes",
103
+ form_fields: "fields"
104
+ })
105
+ ).join(",\n")}
143
106
  };
144
107
  }
145
108
  `,
@@ -44,12 +44,12 @@ function makeDefaultDisplayFields(collection_fields) {
44
44
  return `{
45
45
  field: "${field.name}",
46
46
  label: "${field.name}",
47
- format: async (value: FilePointer) => {
48
- return imageRouter.image(await value.getPath(), {
47
+ format: async (value: FilePointer|null) => {
48
+ return value ? imageRouter.image(await value.getPath(), {
49
49
  container: { width: 45, height: 45 },
50
50
  crop: { width: 45, height: 45 },
51
51
  alt: "",
52
- });
52
+ }): "";
53
53
  },
54
54
  }`;
55
55
  }
@@ -91,7 +91,7 @@ import type { FlatTemplatable, Templatable } from "tempstream";
91
91
  import { TempstreamJSX, tempstream } from "tempstream";
92
92
  import { ${uppercase_collection} } from "src/back/collections/collections.js";
93
93
  import html from "src/back/html.js";
94
- import type { ListFilterRender } from "@sealcode/sealgen";
94
+ import type { ListFilterRender, FormDisplayInfo } from "@sealcode/sealgen";
95
95
  import {
96
96
  SealiousItemListPage,
97
97
  BaseListPageFields,
@@ -104,26 +104,18 @@ ${field_import_string}
104
104
 
105
105
  export const actionName = "${action_name}";
106
106
 
107
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
108
- const filterFields = [
109
- ${makeDefaultFilterFields(collection_fields)}
110
- ] as {
111
- field: keyof (typeof ${uppercase_collection})["fields"];
107
+ const filterFields:{
108
+ field: keyof (typeof HasAllFields)["fields"];
112
109
  render?: ListFilterRender;
113
- prepareValue?: (filter_value: unknown)=>unknown; // set this function to change what filter value is passed to Sealious
114
- }[];
110
+ prepareValue?: (filter_value: unknown) => unknown; // set this function to change what filter value is passed to Sealious
111
+ }[] = [
112
+ ${makeDefaultFilterFields(collection_fields)}
113
+ ];
115
114
 
116
115
 
117
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
118
- const displayFields = [
116
+ const displayFields: FormDisplayInfo<typeof ${uppercase_collection}>[] = [
119
117
  ${makeDefaultDisplayFields(collection_fields)}
120
- ] as {
121
- field: string;
122
- label: string;
123
- format?: (value: unknown, item: CollectionItem<typeof ${toPascalCase(
124
- collection_name
125
- )}>) => FlatTemplatable;
126
- }[];
118
+ ];
127
119
 
128
120
  export default new (class ${action_name}Page extends SealiousItemListPage<
129
121
  typeof ${uppercase_collection},
@@ -1,114 +1,46 @@
1
1
  import { toPascalCase } from "js-convert-case";
2
- import { extractCollectionClassname } from "../../generate-collections.js";
3
2
  import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
4
- import _locreq from "locreq";
5
- import { curryImportPath } from "../../utils/import-path.js";
6
3
  import { formatWithPrettier } from "../../utils/prettier.js";
7
- import { default_handler } from "./handlers/default.js";
8
- import { enum_handler } from "./handlers/enum.js";
9
- import { image_handler } from "./handlers/image.js";
10
- import { file_handler } from "./handlers/file.js";
11
- import { int_handler } from "./handlers/int.js";
12
- import { boolean_handler } from "./handlers/boolean.js";
13
- import { jdd_handler } from "./handlers/jdd.js";
14
- import { date_handler } from "./handlers/date.js";
15
- import { deep_reverse_single_reference_handler } from "./handlers/deep-reverse-single-reference.js";
16
- import { structured_array_handler } from "./handlers/structured-array.js";
17
- import { single_reference_handler } from "./handlers/single-reference.js";
18
- const target_locreq = _locreq(process.cwd());
19
- const field_handlers = {
20
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
21
- default: default_handler,
22
- enum: enum_handler,
23
- image: image_handler,
24
- file: file_handler,
25
- int: int_handler,
26
- boolean: boolean_handler,
27
- jdd: jdd_handler,
28
- date: date_handler,
29
- "deep-reverse-single-reference": deep_reverse_single_reference_handler,
30
- "structured-array": structured_array_handler,
31
- "single-reference": single_reference_handler
32
- };
33
- async function getFieldHandler(collection_name, field, importPath, fields_var) {
34
- const defaults = await field_handlers.default(
35
- collection_name,
36
- field,
37
- importPath,
38
- {},
39
- field_handlers,
40
- fields_var
41
- );
42
- const result = {
43
- ...defaults,
44
- ...await field_handlers[field.type]?.(
45
- collection_name,
46
- field,
47
- importPath,
48
- defaults,
49
- field_handlers,
50
- fields_var
51
- ) || {}
52
- };
53
- const result_initial_value_edit = result.initial_value_edit;
54
- result.initial_value_edit = typeof result_initial_value_edit == "string" ? result_initial_value_edit : {
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- ...defaults.initial_value_edit,
57
- ...result_initial_value_edit
58
- };
59
- return result;
60
- }
4
+ import { wrapAttribute } from "../../utils/wrap-attributes.js";
61
5
  async function sharedCrudFormFields(collection_name, newfilefullpath) {
62
- const [uppercase_collection, collection_fields] = await Promise.all([
63
- extractCollectionClassname(
64
- target_locreq.resolve(
65
- "src/back/collections/" + collection_name + ".ts"
66
- )
67
- ),
68
- extract_fields_from_collection(collection_name)
69
- ]);
70
- const importPath = curryImportPath(newfilefullpath);
71
- const field_handler_results = await Promise.all(
72
- collection_fields.map(async (field) => {
73
- return getFieldHandler(collection_name, field, importPath);
74
- })
6
+ const collection_fields = await extract_fields_from_collection(
7
+ collection_name
75
8
  );
9
+ const uppercase_collection = toPascalCase(collection_name);
76
10
  const result = `import { Controls, Fields } from "@sealcode/sealgen";
77
- import { ${uppercase_collection} } from "${importPath(
78
- "src/back/collections/collections.js"
79
- )}";
80
-
11
+ import { ${uppercase_collection} } from "src/back/collections/collections.js";
81
12
  ${Array.from(
82
13
  new Set(
83
- field_handler_results.filter(
84
- ({ hide_field, hide_control }) => !hide_field && !hide_control
85
- ).map(({ imports }) => imports.shared || "")
86
- )
87
- ).join("\n")}
88
-
89
-
14
+ collection_fields.map(
15
+ (field_info) => field_info.form_field.generateImportsForFieldList(field_info)
16
+ ).flat().map(
17
+ ({ what, from, as }) => `import {${what}${as ? ` as ${as}` : ""} } from "${from}"`
18
+ )
19
+ ).values()
20
+ ).join(";\n")}
90
21
 
91
- export const ${toPascalCase(collection_name)}FormFields = <const>
92
- {
93
- ${field_handler_results.filter(({ hide_field }) => !hide_field).map(({ field }) => field).filter((e) => e != "").join(",\n")}
22
+ export const ${toPascalCase(collection_name)}FormFields = <const>{
23
+ ${collection_fields.map((field_info) => {
24
+ return `${field_info.name}: ${field_info.form_field.generateFieldDeclaration(field_info, {
25
+ form_field_types: "Fields",
26
+ sealious_field: `${uppercase_collection}.fields${wrapAttribute(
27
+ field_info.name
28
+ )}`
29
+ })}`;
30
+ }).join(",\n")}
94
31
  };
95
32
 
96
- export const ${toPascalCase(collection_name)}FormControls = [
97
- ${field_handler_results.filter(({ hide_control }) => !hide_control).map(({ controls }) => controls).filter((e) => e != "").join(",\n")}
98
- ];
99
-
100
- ${Array.from(
101
- new Set(
102
- field_handler_results.map(({ top_level_shared }) => top_level_shared)
103
- )
104
- ).join("\n")}
33
+ const fields = ${toPascalCase(collection_name)}FormFields
105
34
 
35
+ export const get${toPascalCase(
36
+ collection_name
37
+ )}FormControls: () => Controls.FormControl[] = () => [
38
+ ${collection_fields.map(({ name }) => `fields${wrapAttribute(name)}.getControl()`).join(",\n")}
39
+ ];
106
40
  `;
107
41
  return formatWithPrettier(result);
108
42
  }
109
43
  export {
110
- field_handlers,
111
- getFieldHandler,
112
44
  sharedCrudFormFields
113
45
  };
114
46
  //# sourceMappingURL=shared-crud-form-fields.js.map
@@ -10,7 +10,8 @@ import { module_dirname } from "../utils/module-dirname.js";
10
10
  import EventEmitter from "events";
11
11
  const locreq = _locreq(module_dirname(import.meta.url));
12
12
  const callSealgenBin = () => `node ${locreq.resolve("lib/cli.js")}`;
13
- const sealious_minimal_commit = "833e70c";
13
+ const sealious_minimal_url = "https://hub.sealcode.org/source/sealious-minimal.git";
14
+ const sealious_minimal_commit = "77e3794";
14
15
  class RealAppTest {
15
16
  constructor() {
16
17
  this.emitter = new EventEmitter();
@@ -23,7 +24,7 @@ class RealAppTest {
23
24
  test_app.container_name = `sealgen-test-mongo-${timestamp}`;
24
25
  console.log(" cloning sealious-minimal...");
25
26
  await execAsync(
26
- `git clone https://hub.sealcode.org/source/sealious-minimal.git ${test_app.app_path} && cd ${test_app.app_path} && git checkout ${sealious_minimal_commit}`
27
+ `git clone ${sealious_minimal_url} ${test_app.app_path} && cd ${test_app.app_path} && git checkout ${sealious_minimal_commit}`
27
28
  );
28
29
  console.log(" installing dependencies and sealgen...");
29
30
  await execAsync(
@@ -135,7 +136,6 @@ class RealAppTest {
135
136
  });
136
137
  }
137
138
  async httpPOST(path2, body) {
138
- console.debug("POST", path2, body);
139
139
  return this.throwIfItKillsTheApp(async () => {
140
140
  const ret = await fetch(
141
141
  `http://localhost:${this.app_port}${path2}`,