@webiny/app-headless-cms 6.6.0-alpha.1 → 6.6.0-alpha.11

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 (360) hide show
  1. package/ContentEntriesModule.js +20 -3
  2. package/ContentEntriesModule.js.map +1 -1
  3. package/admin/RoutesConfig.js +5 -1
  4. package/admin/RoutesConfig.js.map +1 -1
  5. package/admin/components/ContentEntries/BulkActions/ActionDelete.js +2 -1
  6. package/admin/components/ContentEntries/BulkActions/ActionDelete.js.map +1 -1
  7. package/admin/components/ContentEntries/BulkActions/ActionDelete.test.d.ts +1 -0
  8. package/admin/components/ContentEntries/BulkActions/ActionDelete.test.js +125 -0
  9. package/admin/components/ContentEntries/BulkActions/ActionDelete.test.js.map +1 -0
  10. package/admin/components/ContentEntries/Filters/RefFieldRenderer.d.ts +2 -0
  11. package/admin/components/ContentEntries/Filters/RefFieldRenderer.js +85 -0
  12. package/admin/components/ContentEntries/Filters/RefFieldRenderer.js.map +1 -0
  13. package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.d.ts +2 -0
  14. package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.js +34 -0
  15. package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.js.map +1 -0
  16. package/admin/components/ContentEntries/Table/Actions/index.d.ts +1 -0
  17. package/admin/components/ContentEntries/Table/Actions/index.js +1 -0
  18. package/admin/components/ContentEntries/Table/Cells/CellLive.js +9 -2
  19. package/admin/components/ContentEntries/Table/Cells/CellLive.js.map +1 -1
  20. package/admin/components/ContentModelEditor/ContentModelEditor.js +1 -1
  21. package/admin/components/ContentModelEditor/ContentModelEditor.js.map +1 -1
  22. package/admin/components/ContentModelEditor/evaluateExpression.d.ts +1 -1
  23. package/admin/components/ContentModelEditor/evaluateExpression.js +6 -0
  24. package/admin/components/ContentModelEditor/evaluateExpression.js.map +1 -1
  25. package/admin/components/ContentModelEditor/operatorOptions.js +12 -0
  26. package/admin/components/ContentModelEditor/operatorOptions.js.map +1 -1
  27. package/admin/components/Dialogs/DuplicateEntryConfirmDialog.d.ts +2 -0
  28. package/admin/components/Dialogs/DuplicateEntryConfirmDialog.js +22 -0
  29. package/admin/components/Dialogs/DuplicateEntryConfirmDialog.js.map +1 -0
  30. package/admin/components/Dialogs/EditRevisionNoteDialog.d.ts +2 -0
  31. package/admin/components/Dialogs/EditRevisionNoteDialog.js +33 -0
  32. package/admin/components/Dialogs/EditRevisionNoteDialog.js.map +1 -0
  33. package/admin/components/FieldEditor/Field.js +4 -4
  34. package/admin/components/FieldEditor/Field.js.map +1 -1
  35. package/admin/components/ModelFieldProvider/ModelFieldContext.d.ts +1 -0
  36. package/admin/config/contentEntries/editor/ContentEntryEditorConfig.d.ts +1 -1
  37. package/admin/graphql/contentModels.d.ts +2 -2
  38. package/admin/graphql/contentModels.js +1 -0
  39. package/admin/graphql/contentModels.js.map +1 -1
  40. package/admin/hooks/usePermission.js +6 -34
  41. package/admin/hooks/usePermission.js.map +1 -1
  42. package/admin/plugins/editor/defaultBar/Name/Name.d.ts +0 -5
  43. package/admin/plugins/editor/defaultBar/Name/Name.js +0 -2
  44. package/admin/plugins/editor/defaultBar/Name/Name.js.map +1 -1
  45. package/admin/plugins/editor/formSettings/components/GeneralSettings.js +0 -16
  46. package/admin/plugins/editor/formSettings/components/GeneralSettings.js.map +1 -1
  47. package/domain/permissions/checkCmsPermission.d.ts +14 -0
  48. package/domain/permissions/checkCmsPermission.js +20 -0
  49. package/domain/permissions/checkCmsPermission.js.map +1 -0
  50. package/domain/permissions/hasAccessForModel.d.ts +11 -0
  51. package/domain/permissions/hasAccessForModel.js +20 -0
  52. package/domain/permissions/hasAccessForModel.js.map +1 -0
  53. package/domain/permissions/isModelAllowed.d.ts +2 -0
  54. package/domain/permissions/isModelAllowed.js +11 -0
  55. package/domain/permissions/isModelAllowed.js.map +1 -0
  56. package/features/contentEntry/CmsEntryError.d.ts +10 -0
  57. package/features/contentEntry/CmsEntryError.js +11 -0
  58. package/features/contentEntry/CmsEntryError.js.map +1 -0
  59. package/features/contentEntry/bulkAction/BulkActionGateway.js +6 -1
  60. package/features/contentEntry/bulkAction/BulkActionGateway.js.map +1 -1
  61. package/features/contentEntry/bulkAction/BulkActionGateway.test.d.ts +1 -0
  62. package/features/contentEntry/bulkAction/BulkActionGateway.test.js +134 -0
  63. package/features/contentEntry/bulkAction/BulkActionGateway.test.js.map +1 -0
  64. package/features/contentEntry/createEntry/CreateEntryGateway.d.ts +0 -1
  65. package/features/contentEntry/createEntry/CreateEntryGateway.js +3 -10
  66. package/features/contentEntry/createEntry/CreateEntryGateway.js.map +1 -1
  67. package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.d.ts +3 -1
  68. package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js +8 -3
  69. package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js.map +1 -1
  70. package/features/contentEntry/deleteEntry/DeleteEntryGateway.js +6 -1
  71. package/features/contentEntry/deleteEntry/DeleteEntryGateway.js.map +1 -1
  72. package/features/contentEntry/deleteEntry/DeleteEntryGateway.test.d.ts +1 -0
  73. package/features/contentEntry/deleteEntry/DeleteEntryGateway.test.js +116 -0
  74. package/features/contentEntry/deleteEntry/DeleteEntryGateway.test.js.map +1 -0
  75. package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.js +6 -1
  76. package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.js.map +1 -1
  77. package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.test.d.ts +1 -0
  78. package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.test.js +112 -0
  79. package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.test.js.map +1 -0
  80. package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.d.ts +14 -0
  81. package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.js +43 -0
  82. package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.js.map +1 -0
  83. package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.d.ts +15 -0
  84. package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.js +34 -0
  85. package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.js.map +1 -0
  86. package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.d.ts +11 -0
  87. package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.js +18 -0
  88. package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.js.map +1 -0
  89. package/features/contentEntry/duplicateEntry/abstractions.d.ts +26 -0
  90. package/features/contentEntry/duplicateEntry/abstractions.js +7 -0
  91. package/features/contentEntry/duplicateEntry/abstractions.js.map +1 -0
  92. package/features/contentEntry/duplicateEntry/feature.d.ts +3 -0
  93. package/features/contentEntry/duplicateEntry/feature.js +21 -0
  94. package/features/contentEntry/duplicateEntry/feature.js.map +1 -0
  95. package/features/contentEntry/entryValueGateways.test.d.ts +1 -0
  96. package/features/contentEntry/entryValueGateways.test.js +106 -0
  97. package/features/contentEntry/entryValueGateways.test.js.map +1 -0
  98. package/features/contentEntry/feature.js +4 -2
  99. package/features/contentEntry/feature.js.map +1 -1
  100. package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.js +6 -1
  101. package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.js.map +1 -1
  102. package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.test.d.ts +1 -0
  103. package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.test.js +130 -0
  104. package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.test.js.map +1 -0
  105. package/features/contentEntry/referenceTitles/ReferenceTitles.d.ts +18 -0
  106. package/features/contentEntry/referenceTitles/ReferenceTitles.js +58 -0
  107. package/features/contentEntry/referenceTitles/ReferenceTitles.js.map +1 -0
  108. package/features/contentEntry/referenceTitles/ReferenceTitles.test.d.ts +1 -0
  109. package/features/contentEntry/referenceTitles/ReferenceTitles.test.js +173 -0
  110. package/features/contentEntry/referenceTitles/ReferenceTitles.test.js.map +1 -0
  111. package/features/contentEntry/referenceTitles/RememberTitlesDecorators.d.ts +22 -0
  112. package/features/contentEntry/referenceTitles/RememberTitlesDecorators.js +40 -0
  113. package/features/contentEntry/referenceTitles/RememberTitlesDecorators.js.map +1 -0
  114. package/features/contentEntry/referenceTitles/abstractions.d.ts +16 -0
  115. package/features/contentEntry/referenceTitles/abstractions.js +5 -0
  116. package/features/contentEntry/referenceTitles/abstractions.js.map +1 -0
  117. package/features/contentEntry/referenceTitles/feature.d.ts +3 -0
  118. package/features/contentEntry/referenceTitles/feature.js +20 -0
  119. package/features/contentEntry/referenceTitles/feature.js.map +1 -0
  120. package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.d.ts +0 -1
  121. package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js +3 -10
  122. package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js.map +1 -1
  123. package/features/contentEntry/updateEntry/UpdateEntryGateway.d.ts +0 -1
  124. package/features/contentEntry/updateEntry/UpdateEntryGateway.js +3 -10
  125. package/features/contentEntry/updateEntry/UpdateEntryGateway.js.map +1 -1
  126. package/features/contentEntry/valueTransformers/DynamicZoneValueTransformer.js +7 -2
  127. package/features/contentEntry/valueTransformers/DynamicZoneValueTransformer.js.map +1 -1
  128. package/features/contentEntry/valueTransformers/EntryDataPreparer.d.ts +9 -0
  129. package/features/contentEntry/valueTransformers/EntryDataPreparer.js +8 -0
  130. package/features/contentEntry/valueTransformers/EntryDataPreparer.js.map +1 -1
  131. package/features/contentEntry/valueTransformers/EntryDataPreparer.test.d.ts +1 -0
  132. package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js +113 -0
  133. package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js.map +1 -0
  134. package/features/contentEntry/valueTransformers/ObjectValueTransformer.js +16 -2
  135. package/features/contentEntry/valueTransformers/ObjectValueTransformer.js.map +1 -1
  136. package/features/contentEntry/valueTransformers/entryValueFixtures.d.ts +146 -0
  137. package/features/contentEntry/valueTransformers/entryValueFixtures.js +171 -0
  138. package/features/contentEntry/valueTransformers/entryValueFixtures.js.map +1 -0
  139. package/features/formModel/CmsFormModelBuilder.d.ts +9 -1
  140. package/features/formModel/CmsFormModelBuilder.js +26 -15
  141. package/features/formModel/CmsFormModelBuilder.js.map +1 -1
  142. package/features/formModel/CmsFormModelBuilder.test.d.ts +1 -0
  143. package/features/formModel/CmsFormModelBuilder.test.js +465 -0
  144. package/features/formModel/CmsFormModelBuilder.test.js.map +1 -0
  145. package/features/formModel/CmsLayoutMapper.d.ts +8 -1
  146. package/features/formModel/CmsLayoutMapper.js +27 -5
  147. package/features/formModel/CmsLayoutMapper.js.map +1 -1
  148. package/features/formModel/CmsRefFieldValueFormatter.d.ts +12 -0
  149. package/features/formModel/CmsRefFieldValueFormatter.js +29 -0
  150. package/features/formModel/CmsRefFieldValueFormatter.js.map +1 -0
  151. package/features/formModel/CmsValidationMapper.d.ts +9 -0
  152. package/features/formModel/CmsValidationMapper.js +25 -19
  153. package/features/formModel/CmsValidationMapper.js.map +1 -1
  154. package/features/formModel/feature.js +2 -2
  155. package/features/formModel/feature.js.map +1 -1
  156. package/features/formModel/mappers/DateTimeFieldMapper.js +3 -0
  157. package/features/formModel/mappers/DateTimeFieldMapper.js.map +1 -1
  158. package/features/formModel/mappers/DynamicZoneFieldMapper.js +8 -2
  159. package/features/formModel/mappers/DynamicZoneFieldMapper.js.map +1 -1
  160. package/features/formModel/mappers/ObjectFieldMapper.js +12 -5
  161. package/features/formModel/mappers/ObjectFieldMapper.js.map +1 -1
  162. package/features/formModel/mappers/applyFieldProps.js +2 -1
  163. package/features/formModel/mappers/applyFieldProps.js.map +1 -1
  164. package/features/formModel/mappers/applyFieldProps.test.d.ts +1 -0
  165. package/features/formModel/mappers/applyFieldProps.test.js +59 -0
  166. package/features/formModel/mappers/applyFieldProps.test.js.map +1 -0
  167. package/features/model/deleteModel/DeleteModelGateway.js +6 -1
  168. package/features/model/deleteModel/DeleteModelGateway.js.map +1 -1
  169. package/features/model/deleteModel/DeleteModelGateway.test.d.ts +1 -0
  170. package/features/model/deleteModel/DeleteModelGateway.test.js +71 -0
  171. package/features/model/deleteModel/DeleteModelGateway.test.js.map +1 -0
  172. package/features/model/exportModels/ExportModelsGateway.d.ts +1 -1
  173. package/features/model/exportModels/ExportModelsGateway.js.map +1 -1
  174. package/features/model/exportModels/ExportModelsUseCase.js +7 -1
  175. package/features/model/exportModels/ExportModelsUseCase.js.map +1 -1
  176. package/features/model/exportModels/abstractions.d.ts +8 -2
  177. package/features/model/exportModels/abstractions.js.map +1 -1
  178. package/package.json +30 -28
  179. package/presentation/cloneContentModel/CloneContentModelPresenter.d.ts +1 -0
  180. package/presentation/cloneContentModel/CloneContentModelPresenter.js +8 -6
  181. package/presentation/cloneContentModel/CloneContentModelPresenter.js.map +1 -1
  182. package/presentation/contentEntries/bulkActions/BulkDeletePresenter.d.ts +1 -1
  183. package/presentation/contentEntries/bulkActions/BulkDeletePresenter.js +6 -1
  184. package/presentation/contentEntries/bulkActions/BulkDeletePresenter.js.map +1 -1
  185. package/presentation/contentEntries/bulkActions/BulkDeletePresenter.test.d.ts +1 -0
  186. package/presentation/contentEntries/bulkActions/BulkDeletePresenter.test.js +124 -0
  187. package/presentation/contentEntries/bulkActions/BulkDeletePresenter.test.js.map +1 -0
  188. package/presentation/contentEntries/bulkActions/abstractions.d.ts +1 -1
  189. package/presentation/contentEntries/bulkActions/abstractions.js.map +1 -1
  190. package/presentation/contentEntries/form/ContentEntryFormPresenter.d.ts +2 -0
  191. package/presentation/contentEntries/form/ContentEntryFormPresenter.deleteEntry.test.d.ts +1 -0
  192. package/presentation/contentEntries/form/ContentEntryFormPresenter.deleteEntry.test.js +107 -0
  193. package/presentation/contentEntries/form/ContentEntryFormPresenter.deleteEntry.test.js.map +1 -0
  194. package/presentation/contentEntries/form/ContentEntryFormPresenter.js +47 -30
  195. package/presentation/contentEntries/form/ContentEntryFormPresenter.js.map +1 -1
  196. package/presentation/contentEntries/form/ContentEntryFormPresenter.test.d.ts +1 -0
  197. package/presentation/contentEntries/form/ContentEntryFormPresenter.test.js +244 -0
  198. package/presentation/contentEntries/form/ContentEntryFormPresenter.test.js.map +1 -0
  199. package/presentation/contentEntries/form/abstractions.d.ts +1 -0
  200. package/presentation/contentEntries/form/abstractions.js.map +1 -1
  201. package/presentation/contentEntries/form/getFieldBuilders.test.js +4 -2
  202. package/presentation/contentEntries/form/getFieldBuilders.test.js.map +1 -1
  203. package/presentation/contentEntries/form/toFormErrors.d.ts +7 -0
  204. package/presentation/contentEntries/form/toFormErrors.js +49 -0
  205. package/presentation/contentEntries/form/toFormErrors.js.map +1 -0
  206. package/presentation/contentEntries/form/toFormErrors.test.d.ts +1 -0
  207. package/presentation/contentEntries/form/toFormErrors.test.js +175 -0
  208. package/presentation/contentEntries/form/toFormErrors.test.js.map +1 -0
  209. package/presentation/contentEntries/list/ContentEntriesDataSource.d.ts +5 -0
  210. package/presentation/contentEntries/list/ContentEntriesDataSource.js +16 -4
  211. package/presentation/contentEntries/list/ContentEntriesDataSource.js.map +1 -1
  212. package/presentation/contentEntries/list/ContentEntriesPresenter.d.ts +6 -2
  213. package/presentation/contentEntries/list/ContentEntriesPresenter.js +27 -2
  214. package/presentation/contentEntries/list/ContentEntriesPresenter.js.map +1 -1
  215. package/presentation/contentEntries/list/ContentEntriesPresenter.test.js +130 -5
  216. package/presentation/contentEntries/list/ContentEntriesPresenter.test.js.map +1 -1
  217. package/presentation/contentEntries/list/abstractions.d.ts +12 -0
  218. package/presentation/contentEntries/list/abstractions.js.map +1 -1
  219. package/presentation/contentEntries/preview/ComponentDiscoveryIframe.d.ts +3 -2
  220. package/presentation/contentEntries/preview/ComponentDiscoveryIframe.js +2 -2
  221. package/presentation/contentEntries/preview/ComponentDiscoveryIframe.js.map +1 -1
  222. package/presentation/contentEntries/preview/LivePreviewPresenter.d.ts +12 -1
  223. package/presentation/contentEntries/preview/LivePreviewPresenter.js +48 -5
  224. package/presentation/contentEntries/preview/LivePreviewPresenter.js.map +1 -1
  225. package/presentation/contentEntries/preview/LivePreviewPresenter.test.d.ts +1 -0
  226. package/presentation/contentEntries/preview/LivePreviewPresenter.test.js +81 -0
  227. package/presentation/contentEntries/preview/LivePreviewPresenter.test.js.map +1 -0
  228. package/presentation/contentEntries/preview/ModelEditorComponentDiscovery.js +8 -5
  229. package/presentation/contentEntries/preview/ModelEditorComponentDiscovery.js.map +1 -1
  230. package/presentation/contentEntries/preview/PreviewDecorator.js +30 -10
  231. package/presentation/contentEntries/preview/PreviewDecorator.js.map +1 -1
  232. package/presentation/contentEntries/preview/PreviewDomainStatus.d.ts +10 -0
  233. package/presentation/contentEntries/preview/PreviewDomainStatus.js +19 -0
  234. package/presentation/contentEntries/preview/PreviewDomainStatus.js.map +1 -0
  235. package/presentation/contentEntries/preview/PreviewPane.d.ts +12 -3
  236. package/presentation/contentEntries/preview/PreviewPane.js +82 -46
  237. package/presentation/contentEntries/preview/PreviewPane.js.map +1 -1
  238. package/presentation/contentEntries/preview/abstractions.d.ts +8 -0
  239. package/presentation/contentEntries/preview/abstractions.js.map +1 -1
  240. package/presentation/contentEntries/preview/resolvePreviewUrl.d.ts +23 -2
  241. package/presentation/contentEntries/preview/resolvePreviewUrl.js +62 -10
  242. package/presentation/contentEntries/preview/resolvePreviewUrl.js.map +1 -1
  243. package/presentation/contentEntries/preview/resolvePreviewUrl.test.d.ts +1 -0
  244. package/presentation/contentEntries/preview/resolvePreviewUrl.test.js +127 -0
  245. package/presentation/contentEntries/preview/resolvePreviewUrl.test.js.map +1 -0
  246. package/presentation/contentEntries/revisionsList/RevisionsListPresenter.d.ts +21 -2
  247. package/presentation/contentEntries/revisionsList/RevisionsListPresenter.js +143 -6
  248. package/presentation/contentEntries/revisionsList/RevisionsListPresenter.js.map +1 -1
  249. package/presentation/contentEntries/revisionsList/RevisionsListPresenter.test.d.ts +1 -0
  250. package/presentation/contentEntries/revisionsList/RevisionsListPresenter.test.js +384 -0
  251. package/presentation/contentEntries/revisionsList/RevisionsListPresenter.test.js.map +1 -0
  252. package/presentation/contentEntries/revisionsList/abstractions.d.ts +16 -0
  253. package/presentation/contentEntries/revisionsList/abstractions.js.map +1 -1
  254. package/presentation/contentEntries/singleEntry/SingleEntryPresenter.js +9 -4
  255. package/presentation/contentEntries/singleEntry/SingleEntryPresenter.js.map +1 -1
  256. package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.d.ts +1 -0
  257. package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.js +122 -0
  258. package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.js.map +1 -0
  259. package/presentation/contentEntries/views/ContentEntriesListLayout.js +1 -0
  260. package/presentation/contentEntries/views/ContentEntriesListLayout.js.map +1 -1
  261. package/presentation/contentEntries/views/ContentEntriesView.js +2 -0
  262. package/presentation/contentEntries/views/ContentEntriesView.js.map +1 -1
  263. package/presentation/contentEntries/views/ContentEntryFormView.js +4 -1
  264. package/presentation/contentEntries/views/ContentEntryFormView.js.map +1 -1
  265. package/presentation/contentEntries/views/OlderRevisionAlert.d.ts +4 -0
  266. package/presentation/contentEntries/views/OlderRevisionAlert.js +43 -0
  267. package/presentation/contentEntries/views/OlderRevisionAlert.js.map +1 -0
  268. package/presentation/contentEntries/views/RevisionDrawer.js +4 -0
  269. package/presentation/contentEntries/views/RevisionDrawer.js.map +1 -1
  270. package/presentation/contentEntries/views/RevisionListItem.d.ts +3 -3
  271. package/presentation/contentEntries/views/RevisionListItem.js +82 -14
  272. package/presentation/contentEntries/views/RevisionListItem.js.map +1 -1
  273. package/presentation/contentEntries/views/RevisionsList.js +3 -3
  274. package/presentation/contentEntries/views/RevisionsList.js.map +1 -1
  275. package/presentation/contentEntries/views/actions/CreateNewRevisionButton.js +11 -0
  276. package/presentation/contentEntries/views/actions/CreateNewRevisionButton.js.map +1 -1
  277. package/presentation/contentModels/ContentModelsPresenter.d.ts +5 -5
  278. package/presentation/contentModels/ContentModelsPresenter.js +1 -1
  279. package/presentation/contentModels/ContentModelsPresenter.js.map +1 -1
  280. package/presentation/contentModels/abstractions.d.ts +7 -2
  281. package/presentation/contentModels/abstractions.js.map +1 -1
  282. package/presentation/contentModels/components/ContentModelsDataList.js +6 -5
  283. package/presentation/contentModels/components/ContentModelsDataList.js.map +1 -1
  284. package/presentation/contentModels/components/fullDelete/FullyDeleteModelDialog.js +8 -3
  285. package/presentation/contentModels/components/fullDelete/FullyDeleteModelDialog.js.map +1 -1
  286. package/presentation/contentModels/components/fullDelete/dialog/Content.js +7 -2
  287. package/presentation/contentModels/components/fullDelete/dialog/Content.js.map +1 -1
  288. package/presentation/contentModels/components/fullDelete/dialog/Content.test.d.ts +1 -0
  289. package/presentation/contentModels/components/fullDelete/dialog/Content.test.js +54 -0
  290. package/presentation/contentModels/components/fullDelete/dialog/Content.test.js.map +1 -0
  291. package/presentation/contentModels/components/fullDelete/dialog/FullyDeleteModelError.d.ts +25 -0
  292. package/presentation/contentModels/components/fullDelete/dialog/FullyDeleteModelError.js +9 -0
  293. package/presentation/contentModels/components/fullDelete/dialog/FullyDeleteModelError.js.map +1 -0
  294. package/presentation/fieldEditor/groups/AppearanceGroup.js +12 -0
  295. package/presentation/fieldEditor/groups/AppearanceGroup.js.map +1 -1
  296. package/presentation/fieldEditor/groups/GeneralGroup.d.ts +5 -5
  297. package/presentation/fieldEditor/groups/GeneralGroup.js +5 -1
  298. package/presentation/fieldEditor/groups/GeneralGroup.js.map +1 -1
  299. package/presentation/fieldEditor/groups/GeneralGroup.test.d.ts +1 -0
  300. package/presentation/fieldEditor/groups/GeneralGroup.test.js +68 -0
  301. package/presentation/fieldEditor/groups/GeneralGroup.test.js.map +1 -0
  302. package/presentation/fieldEditor/groups/ValidationsGroup.d.ts +2 -0
  303. package/presentation/fieldEditor/groups/ValidationsGroup.js +20 -6
  304. package/presentation/fieldEditor/groups/ValidationsGroup.js.map +1 -1
  305. package/presentation/fieldEditor/renderers/CmsValidatorsRenderer.js +2 -2
  306. package/presentation/fieldEditor/renderers/CmsValidatorsRenderer.js.map +1 -1
  307. package/presentation/fieldRenderers/feature.js +2 -1
  308. package/presentation/fieldRenderers/feature.js.map +1 -1
  309. package/presentation/fieldRenderers/ref/CmsRefInputRenderer.js +1 -0
  310. package/presentation/fieldRenderers/ref/CmsRefInputRenderer.js.map +1 -1
  311. package/presentation/fieldRenderers/ref/CmsRefInputsRenderer.js +1 -0
  312. package/presentation/fieldRenderers/ref/CmsRefInputsRenderer.js.map +1 -1
  313. package/presentation/fieldRenderers/ref/autocomplete/BaseAutocompletePresenter.d.ts +1 -0
  314. package/presentation/fieldRenderers/ref/autocomplete/BaseAutocompletePresenter.js +8 -2
  315. package/presentation/fieldRenderers/ref/autocomplete/BaseAutocompletePresenter.js.map +1 -1
  316. package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.d.ts +1 -0
  317. package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.js +185 -0
  318. package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.js.map +1 -0
  319. package/presentation/fieldRenderers/ref/autocomplete/multi/RefMultiAutocompletePresenter.js +1 -1
  320. package/presentation/fieldRenderers/ref/autocomplete/multi/RefMultiAutocompletePresenter.js.map +1 -1
  321. package/presentation/fieldRenderers/ref/autocomplete/single/RefSingleAutocompletePresenter.js +1 -1
  322. package/presentation/fieldRenderers/ref/autocomplete/single/RefSingleAutocompletePresenter.js.map +1 -1
  323. package/presentation/fieldRenderers/ref/components/RefFieldOptions.js +3 -2
  324. package/presentation/fieldRenderers/ref/components/RefFieldOptions.js.map +1 -1
  325. package/presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.d.ts +15 -0
  326. package/presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.js +19 -0
  327. package/presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.js.map +1 -0
  328. package/presentation/fieldTypes/renderers/index.d.ts +1 -0
  329. package/presentation/fieldTypes/renderers/index.js +1 -0
  330. package/presentation/fieldValidators/abstractions.d.ts +7 -0
  331. package/presentation/fieldValidators/abstractions.js.map +1 -1
  332. package/presentation/fieldValidators/validators/DateGteValidator.d.ts +6 -0
  333. package/presentation/fieldValidators/validators/DateGteValidator.js +17 -25
  334. package/presentation/fieldValidators/validators/DateGteValidator.js.map +1 -1
  335. package/presentation/fieldValidators/validators/DateLteValidator.d.ts +6 -0
  336. package/presentation/fieldValidators/validators/DateLteValidator.js +17 -25
  337. package/presentation/fieldValidators/validators/DateLteValidator.js.map +1 -1
  338. package/presentation/fieldValidators/validators/dateLimitSettings.d.ts +20 -0
  339. package/presentation/fieldValidators/validators/dateLimitSettings.js +124 -0
  340. package/presentation/fieldValidators/validators/dateLimitSettings.js.map +1 -0
  341. package/presentation/fieldValidators/validators/dateLimitSettings.test.d.ts +1 -0
  342. package/presentation/fieldValidators/validators/dateLimitSettings.test.js +111 -0
  343. package/presentation/fieldValidators/validators/dateLimitSettings.test.js.map +1 -0
  344. package/presentation/importContentModels/ImportContentModelsPresenter.js +1 -1
  345. package/presentation/importContentModels/ImportContentModelsPresenter.js.map +1 -1
  346. package/presentation/importContentModels/components/Model/DataListModelItem.js +3 -3
  347. package/presentation/importContentModels/components/Model/DataListModelItem.js.map +1 -1
  348. package/presentation/importContentModels/components/Model/DataListModelItemInfo.js +2 -2
  349. package/presentation/importContentModels/components/Model/DataListModelItemInfo.js.map +1 -1
  350. package/presentation/modelGroup/ModelGroupPresenter.js +1 -2
  351. package/presentation/modelGroup/ModelGroupPresenter.js.map +1 -1
  352. package/presentation/newContentModel/NewContentModelPresenter.d.ts +1 -0
  353. package/presentation/newContentModel/NewContentModelPresenter.js +8 -6
  354. package/presentation/newContentModel/NewContentModelPresenter.js.map +1 -1
  355. package/utils/normalizeIcon.d.ts +4 -0
  356. package/utils/normalizeIcon.js +9 -6
  357. package/utils/normalizeIcon.js.map +1 -1
  358. package/features/formModel/CmsAccessControlRuleEvaluator.d.ts +0 -9
  359. package/features/formModel/CmsAccessControlRuleEvaluator.js +0 -16
  360. package/features/formModel/CmsAccessControlRuleEvaluator.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"presentation/fieldValidators/abstractions.js","sources":["../../../src/presentation/fieldValidators/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport { FormModel, FormModelFactory } from \"@webiny/app-admin\";\nimport type { IFieldBuilder } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModelField } from \"~/types.js\";\nimport type { CmsModelFieldValidator } from \"~/types.js\";\n\nexport interface ICmsFieldValidatorVariable {\n name: string;\n description: string;\n}\n\nexport interface ICmsFieldValidatorFormBuilder {\n message: FormModelFactory.FieldBuilder;\n fields(\n fn: (\n fields: FormModelFactory.FieldBuilderRegistry\n ) => Record<string, FormModelFactory.FieldBuilder>\n ): void;\n layout(fn: (layout: FormModelFactory.LayoutBuilder) => FormModel.LayoutNodeBuilder[]): void;\n}\n\nexport interface ICmsFieldValidatorContext {\n field: CmsModelField;\n}\n\nexport interface ICmsFieldValidator {\n readonly name: string;\n readonly label: string;\n readonly description: string;\n readonly defaultMessage: string;\n readonly defaultSettings?: Record<string, unknown>;\n readonly variables?: ICmsFieldValidatorVariable[];\n\n getVariableValues?(context: { validator: CmsModelFieldValidator }): Record<string, string>;\n\n buildSettingsForm?(\n form: ICmsFieldValidatorFormBuilder,\n context: ICmsFieldValidatorContext\n ): void;\n\n mapToFieldBuilder(\n builder: IFieldBuilder,\n validator: CmsModelFieldValidator,\n field: CmsModelField\n ): void;\n}\n\nexport const CmsFieldValidator = createAbstraction<ICmsFieldValidator>(\"CmsFieldValidator\");\n\nexport namespace CmsFieldValidator {\n export type Interface = ICmsFieldValidator;\n export type FormBuilder = ICmsFieldValidatorFormBuilder;\n export type Context = ICmsFieldValidatorContext;\n export type Variable = ICmsFieldValidatorVariable;\n}\n"],"names":["CmsFieldValidator","createAbstraction"],"mappings":";AA+CO,MAAMA,oBAAoBC,kBAAsC"}
1
+ {"version":3,"file":"presentation/fieldValidators/abstractions.js","sources":["../../../src/presentation/fieldValidators/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport { FormModel, FormModelFactory } from \"@webiny/app-admin\";\nimport type { IFieldBuilder } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModelField } from \"~/types.js\";\nimport type { CmsModelFieldValidator } from \"~/types.js\";\n\nexport interface ICmsFieldValidatorVariable {\n name: string;\n description: string;\n}\n\nexport interface ICmsFieldValidatorFormBuilder {\n message: FormModelFactory.FieldBuilder;\n fields(\n fn: (\n fields: FormModelFactory.FieldBuilderRegistry\n ) => Record<string, FormModelFactory.FieldBuilder>\n ): void;\n layout(fn: (layout: FormModelFactory.LayoutBuilder) => FormModel.LayoutNodeBuilder[]): void;\n}\n\nexport interface ICmsFieldValidatorContext {\n field: CmsModelField;\n}\n\nexport interface ICmsFieldValidator {\n readonly name: string;\n readonly label: string;\n readonly description: string;\n readonly defaultMessage: string;\n readonly defaultSettings?: Record<string, unknown>;\n readonly variables?: ICmsFieldValidatorVariable[];\n\n getVariableValues?(context: { validator: CmsModelFieldValidator }): Record<string, string>;\n\n buildSettingsForm?(\n form: ICmsFieldValidatorFormBuilder,\n context: ICmsFieldValidatorContext\n ): void;\n\n /**\n * Turns the stored settings into the settings form's values, when the form shows them\n * differently. Without it, the stored settings are the form's values.\n */\n mapSettingsToForm?(\n settings: Record<string, unknown>,\n context: ICmsFieldValidatorContext\n ): Record<string, unknown>;\n\n /** Turns the settings form's values back into the settings to store. */\n mapSettingsFromForm?(\n settings: Record<string, unknown>,\n context: ICmsFieldValidatorContext\n ): Record<string, unknown>;\n\n mapToFieldBuilder(\n builder: IFieldBuilder,\n validator: CmsModelFieldValidator,\n field: CmsModelField\n ): void;\n}\n\nexport const CmsFieldValidator = createAbstraction<ICmsFieldValidator>(\"CmsFieldValidator\");\n\nexport namespace CmsFieldValidator {\n export type Interface = ICmsFieldValidator;\n export type FormBuilder = ICmsFieldValidatorFormBuilder;\n export type Context = ICmsFieldValidatorContext;\n export type Variable = ICmsFieldValidatorVariable;\n}\n"],"names":["CmsFieldValidator","createAbstraction"],"mappings":";AA8DO,MAAMA,oBAAoBC,kBAAsC"}
@@ -8,7 +8,13 @@ declare class DateGteValidatorImpl implements CmsFieldValidator.Interface {
8
8
  label: string;
9
9
  description: string;
10
10
  defaultMessage: string;
11
+ variables: {
12
+ name: string;
13
+ description: string;
14
+ }[];
11
15
  buildSettingsForm(form: ICmsFieldValidatorFormBuilder, context: ICmsFieldValidatorContext): void;
16
+ mapSettingsToForm(settings: Record<string, unknown>, context: ICmsFieldValidatorContext): Record<string, unknown>;
17
+ mapSettingsFromForm(settings: Record<string, unknown>): Record<string, unknown>;
12
18
  mapToFieldBuilder(builder: IFieldBuilder, validator: CmsModelFieldValidator, _field: CmsModelField): void;
13
19
  }
14
20
  export declare const DateGteValidator: typeof DateGteValidatorImpl & {
@@ -1,31 +1,17 @@
1
1
  import { z } from "zod";
2
2
  import { CmsFieldValidator } from "../abstractions.js";
3
+ import { buildDateLimitSettingsForm, dateLimitSettingsFromForm, dateLimitSettingsToForm } from "./dateLimitSettings.js";
3
4
  class DateGteValidatorImpl {
4
5
  buildSettingsForm(form, context) {
5
- const type = context.field.settings ? context.field.settings.type : "date";
6
- form.fields((fields)=>{
7
- const valueField = fields.datetime().label("Value").description("This is the earliest date/time that will be allowed.");
8
- switch(type){
9
- case "time":
10
- valueField.timeOnly();
11
- break;
12
- case "dateTimeWithTimezone":
13
- valueField.withTimezone();
14
- break;
15
- case "dateTimeWithoutTimezone":
16
- valueField.withoutTimezone();
17
- break;
18
- default:
19
- valueField.dateOnly();
20
- break;
21
- }
22
- return {
23
- value: valueField
24
- };
6
+ buildDateLimitSettingsForm(form, context, {
7
+ valueDescription: "This is the earliest date/time that will be allowed."
25
8
  });
26
- form.layout((layout)=>[
27
- layout.row("value")
28
- ]);
9
+ }
10
+ mapSettingsToForm(settings, context) {
11
+ return dateLimitSettingsToForm(settings, context);
12
+ }
13
+ mapSettingsFromForm(settings) {
14
+ return dateLimitSettingsFromForm(settings);
29
15
  }
30
16
  mapToFieldBuilder(builder, validator, _field) {
31
17
  const minDate = validator.settings?.value;
@@ -36,8 +22,14 @@ class DateGteValidatorImpl {
36
22
  constructor(){
37
23
  this.name = "dateGte";
38
24
  this.label = "Later or equal";
39
- this.description = "Entered date/time must be equal or later compared to the provided date.";
40
- this.defaultMessage = "Date/time is earlier than the provided one.";
25
+ this.description = "Entered date/time must be equal or later compared to the provided date. A date relative to today is worked out from the current date every time the value is checked.";
26
+ this.defaultMessage = "Must be on or after {date}.";
27
+ this.variables = [
28
+ {
29
+ name: "date",
30
+ description: "The earliest allowed date, worked out when the value is checked."
31
+ }
32
+ ];
41
33
  }
42
34
  }
43
35
  const DateGteValidator = CmsFieldValidator.createImplementation({
@@ -1 +1 @@
1
- {"version":3,"file":"presentation/fieldValidators/validators/DateGteValidator.js","sources":["../../../../src/presentation/fieldValidators/validators/DateGteValidator.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { IFieldBuilder } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModelFieldValidator } from \"~/types.js\";\nimport type { CmsModelField } from \"~/types.js\";\nimport { CmsFieldValidator } from \"../abstractions.js\";\nimport type { ICmsFieldValidatorFormBuilder, ICmsFieldValidatorContext } from \"../abstractions.js\";\n\nclass DateGteValidatorImpl implements CmsFieldValidator.Interface {\n name = \"dateGte\";\n label = \"Later or equal\";\n description = \"Entered date/time must be equal or later compared to the provided date.\";\n defaultMessage = \"Date/time is earlier than the provided one.\";\n\n buildSettingsForm(form: ICmsFieldValidatorFormBuilder, context: ICmsFieldValidatorContext) {\n const type = context.field.settings ? context.field.settings.type : \"date\";\n\n form.fields(fields => {\n const valueField = fields\n .datetime()\n .label(\"Value\")\n .description(\"This is the earliest date/time that will be allowed.\");\n\n switch (type) {\n case \"time\":\n valueField.timeOnly();\n break;\n case \"dateTimeWithTimezone\":\n valueField.withTimezone();\n break;\n case \"dateTimeWithoutTimezone\":\n valueField.withoutTimezone();\n break;\n default:\n valueField.dateOnly();\n break;\n }\n\n return { value: valueField };\n });\n form.layout(layout => [layout.row(\"value\")]);\n }\n\n mapToFieldBuilder(\n builder: IFieldBuilder,\n validator: CmsModelFieldValidator,\n _field: CmsModelField\n ) {\n const minDate = validator.settings?.value;\n if (minDate != null) {\n builder.schema(\n z.string().refine(val => val >= minDate, {\n message: validator.message || `Must be on or after ${minDate}`\n })\n );\n }\n }\n}\n\nexport const DateGteValidator = CmsFieldValidator.createImplementation({\n implementation: DateGteValidatorImpl,\n dependencies: []\n});\n"],"names":["DateGteValidatorImpl","form","context","type","fields","valueField","layout","builder","validator","_field","minDate","z","val","DateGteValidator","CmsFieldValidator"],"mappings":";;AAOA,MAAMA;IAMF,kBAAkBC,IAAmC,EAAEC,OAAkC,EAAE;QACvF,MAAMC,OAAOD,QAAQ,KAAK,CAAC,QAAQ,GAAGA,QAAQ,KAAK,CAAC,QAAQ,CAAC,IAAI,GAAG;QAEpED,KAAK,MAAM,CAACG,CAAAA;YACR,MAAMC,aAAaD,OACd,QAAQ,GACR,KAAK,CAAC,SACN,WAAW,CAAC;YAEjB,OAAQD;gBACJ,KAAK;oBACDE,WAAW,QAAQ;oBACnB;gBACJ,KAAK;oBACDA,WAAW,YAAY;oBACvB;gBACJ,KAAK;oBACDA,WAAW,eAAe;oBAC1B;gBACJ;oBACIA,WAAW,QAAQ;oBACnB;YACR;YAEA,OAAO;gBAAE,OAAOA;YAAW;QAC/B;QACAJ,KAAK,MAAM,CAACK,CAAAA,SAAU;gBAACA,OAAO,GAAG,CAAC;aAAS;IAC/C;IAEA,kBACIC,OAAsB,EACtBC,SAAiC,EACjCC,MAAqB,EACvB;QACE,MAAMC,UAAUF,UAAU,QAAQ,EAAE;QACpC,IAAIE,AAAW,QAAXA,SACAH,QAAQ,MAAM,CACVI,EAAE,MAAM,GAAG,MAAM,CAACC,CAAAA,MAAOA,OAAOF,SAAS;YACrC,SAASF,UAAU,OAAO,IAAI,CAAC,oBAAoB,EAAEE,SAAS;QAClE;IAGZ;;aA/CA,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAAG;aACd,cAAc,GAAG;;AA6CrB;AAEO,MAAMG,mBAAmBC,kBAAkB,oBAAoB,CAAC;IACnE,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"presentation/fieldValidators/validators/DateGteValidator.js","sources":["../../../../src/presentation/fieldValidators/validators/DateGteValidator.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { IFieldBuilder } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModelFieldValidator } from \"~/types.js\";\nimport type { CmsModelField } from \"~/types.js\";\nimport { CmsFieldValidator } from \"../abstractions.js\";\nimport type { ICmsFieldValidatorFormBuilder, ICmsFieldValidatorContext } from \"../abstractions.js\";\nimport {\n buildDateLimitSettingsForm,\n dateLimitSettingsFromForm,\n dateLimitSettingsToForm\n} from \"./dateLimitSettings.js\";\n\nclass DateGteValidatorImpl implements CmsFieldValidator.Interface {\n name = \"dateGte\";\n label = \"Later or equal\";\n description =\n \"Entered date/time must be equal or later compared to the provided date. A date relative to today is worked out from the current date every time the value is checked.\";\n defaultMessage = \"Must be on or after {date}.\";\n variables = [\n {\n name: \"date\",\n description: \"The earliest allowed date, worked out when the value is checked.\"\n }\n ];\n\n buildSettingsForm(form: ICmsFieldValidatorFormBuilder, context: ICmsFieldValidatorContext) {\n buildDateLimitSettingsForm(form, context, {\n valueDescription: \"This is the earliest date/time that will be allowed.\"\n });\n }\n\n mapSettingsToForm(settings: Record<string, unknown>, context: ICmsFieldValidatorContext) {\n return dateLimitSettingsToForm(settings, context);\n }\n\n mapSettingsFromForm(settings: Record<string, unknown>) {\n return dateLimitSettingsFromForm(settings);\n }\n\n mapToFieldBuilder(\n builder: IFieldBuilder,\n validator: CmsModelFieldValidator,\n _field: CmsModelField\n ) {\n const minDate = validator.settings?.value;\n if (minDate != null) {\n builder.schema(\n z.string().refine(val => val >= minDate, {\n message: validator.message || `Must be on or after ${minDate}`\n })\n );\n }\n }\n}\n\nexport const DateGteValidator = CmsFieldValidator.createImplementation({\n implementation: DateGteValidatorImpl,\n dependencies: []\n});\n"],"names":["DateGteValidatorImpl","form","context","buildDateLimitSettingsForm","settings","dateLimitSettingsToForm","dateLimitSettingsFromForm","builder","validator","_field","minDate","z","val","DateGteValidator","CmsFieldValidator"],"mappings":";;;AAYA,MAAMA;IAaF,kBAAkBC,IAAmC,EAAEC,OAAkC,EAAE;QACvFC,2BAA2BF,MAAMC,SAAS;YACtC,kBAAkB;QACtB;IACJ;IAEA,kBAAkBE,QAAiC,EAAEF,OAAkC,EAAE;QACrF,OAAOG,wBAAwBD,UAAUF;IAC7C;IAEA,oBAAoBE,QAAiC,EAAE;QACnD,OAAOE,0BAA0BF;IACrC;IAEA,kBACIG,OAAsB,EACtBC,SAAiC,EACjCC,MAAqB,EACvB;QACE,MAAMC,UAAUF,UAAU,QAAQ,EAAE;QACpC,IAAIE,AAAW,QAAXA,SACAH,QAAQ,MAAM,CACVI,EAAE,MAAM,GAAG,MAAM,CAACC,CAAAA,MAAOA,OAAOF,SAAS;YACrC,SAASF,UAAU,OAAO,IAAI,CAAC,oBAAoB,EAAEE,SAAS;QAClE;IAGZ;;aAvCA,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GACP;aACJ,cAAc,GAAG;aACjB,SAAS,GAAG;YACR;gBACI,MAAM;gBACN,aAAa;YACjB;SACH;;AA8BL;AAEO,MAAMG,mBAAmBC,kBAAkB,oBAAoB,CAAC;IACnE,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
@@ -8,7 +8,13 @@ declare class DateLteValidatorImpl implements CmsFieldValidator.Interface {
8
8
  label: string;
9
9
  description: string;
10
10
  defaultMessage: string;
11
+ variables: {
12
+ name: string;
13
+ description: string;
14
+ }[];
11
15
  buildSettingsForm(form: ICmsFieldValidatorFormBuilder, context: ICmsFieldValidatorContext): void;
16
+ mapSettingsToForm(settings: Record<string, unknown>, context: ICmsFieldValidatorContext): Record<string, unknown>;
17
+ mapSettingsFromForm(settings: Record<string, unknown>): Record<string, unknown>;
12
18
  mapToFieldBuilder(builder: IFieldBuilder, validator: CmsModelFieldValidator, _field: CmsModelField): void;
13
19
  }
14
20
  export declare const DateLteValidator: typeof DateLteValidatorImpl & {
@@ -1,31 +1,17 @@
1
1
  import { z } from "zod";
2
2
  import { CmsFieldValidator } from "../abstractions.js";
3
+ import { buildDateLimitSettingsForm, dateLimitSettingsFromForm, dateLimitSettingsToForm } from "./dateLimitSettings.js";
3
4
  class DateLteValidatorImpl {
4
5
  buildSettingsForm(form, context) {
5
- const type = context.field.settings ? context.field.settings.type : "date";
6
- form.fields((fields)=>{
7
- const valueField = fields.datetime().label("Value").description("This is the latest date/time that will be allowed.");
8
- switch(type){
9
- case "time":
10
- valueField.timeOnly();
11
- break;
12
- case "dateTimeWithTimezone":
13
- valueField.withTimezone();
14
- break;
15
- case "dateTimeWithoutTimezone":
16
- valueField.withoutTimezone();
17
- break;
18
- default:
19
- valueField.dateOnly();
20
- break;
21
- }
22
- return {
23
- value: valueField
24
- };
6
+ buildDateLimitSettingsForm(form, context, {
7
+ valueDescription: "This is the latest date/time that will be allowed."
25
8
  });
26
- form.layout((layout)=>[
27
- layout.row("value")
28
- ]);
9
+ }
10
+ mapSettingsToForm(settings, context) {
11
+ return dateLimitSettingsToForm(settings, context);
12
+ }
13
+ mapSettingsFromForm(settings) {
14
+ return dateLimitSettingsFromForm(settings);
29
15
  }
30
16
  mapToFieldBuilder(builder, validator, _field) {
31
17
  const maxDate = validator.settings?.value;
@@ -36,8 +22,14 @@ class DateLteValidatorImpl {
36
22
  constructor(){
37
23
  this.name = "dateLte";
38
24
  this.label = "Earlier or equal";
39
- this.description = "Entered date/time must be equal or earlier compared to the provided date.";
40
- this.defaultMessage = "Date/time is later than the provided one.";
25
+ this.description = "Entered date/time must be equal or earlier compared to the provided date. A date relative to today is worked out from the current date every time the value is checked.";
26
+ this.defaultMessage = "Must be on or before {date}.";
27
+ this.variables = [
28
+ {
29
+ name: "date",
30
+ description: "The latest allowed date, worked out when the value is checked."
31
+ }
32
+ ];
41
33
  }
42
34
  }
43
35
  const DateLteValidator = CmsFieldValidator.createImplementation({
@@ -1 +1 @@
1
- {"version":3,"file":"presentation/fieldValidators/validators/DateLteValidator.js","sources":["../../../../src/presentation/fieldValidators/validators/DateLteValidator.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { IFieldBuilder } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModelFieldValidator } from \"~/types.js\";\nimport type { CmsModelField } from \"~/types.js\";\nimport { CmsFieldValidator } from \"../abstractions.js\";\nimport type { ICmsFieldValidatorFormBuilder, ICmsFieldValidatorContext } from \"../abstractions.js\";\n\nclass DateLteValidatorImpl implements CmsFieldValidator.Interface {\n name = \"dateLte\";\n label = \"Earlier or equal\";\n description = \"Entered date/time must be equal or earlier compared to the provided date.\";\n defaultMessage = \"Date/time is later than the provided one.\";\n\n buildSettingsForm(form: ICmsFieldValidatorFormBuilder, context: ICmsFieldValidatorContext) {\n const type = context.field.settings ? context.field.settings.type : \"date\";\n\n form.fields(fields => {\n const valueField = fields\n .datetime()\n .label(\"Value\")\n .description(\"This is the latest date/time that will be allowed.\");\n\n switch (type) {\n case \"time\":\n valueField.timeOnly();\n break;\n case \"dateTimeWithTimezone\":\n valueField.withTimezone();\n break;\n case \"dateTimeWithoutTimezone\":\n valueField.withoutTimezone();\n break;\n default:\n valueField.dateOnly();\n break;\n }\n\n return { value: valueField };\n });\n form.layout(layout => [layout.row(\"value\")]);\n }\n\n mapToFieldBuilder(\n builder: IFieldBuilder,\n validator: CmsModelFieldValidator,\n _field: CmsModelField\n ) {\n const maxDate = validator.settings?.value;\n if (maxDate != null) {\n builder.schema(\n z.string().refine(val => val <= maxDate, {\n message: validator.message || `Must be on or before ${maxDate}`\n })\n );\n }\n }\n}\n\nexport const DateLteValidator = CmsFieldValidator.createImplementation({\n implementation: DateLteValidatorImpl,\n dependencies: []\n});\n"],"names":["DateLteValidatorImpl","form","context","type","fields","valueField","layout","builder","validator","_field","maxDate","z","val","DateLteValidator","CmsFieldValidator"],"mappings":";;AAOA,MAAMA;IAMF,kBAAkBC,IAAmC,EAAEC,OAAkC,EAAE;QACvF,MAAMC,OAAOD,QAAQ,KAAK,CAAC,QAAQ,GAAGA,QAAQ,KAAK,CAAC,QAAQ,CAAC,IAAI,GAAG;QAEpED,KAAK,MAAM,CAACG,CAAAA;YACR,MAAMC,aAAaD,OACd,QAAQ,GACR,KAAK,CAAC,SACN,WAAW,CAAC;YAEjB,OAAQD;gBACJ,KAAK;oBACDE,WAAW,QAAQ;oBACnB;gBACJ,KAAK;oBACDA,WAAW,YAAY;oBACvB;gBACJ,KAAK;oBACDA,WAAW,eAAe;oBAC1B;gBACJ;oBACIA,WAAW,QAAQ;oBACnB;YACR;YAEA,OAAO;gBAAE,OAAOA;YAAW;QAC/B;QACAJ,KAAK,MAAM,CAACK,CAAAA,SAAU;gBAACA,OAAO,GAAG,CAAC;aAAS;IAC/C;IAEA,kBACIC,OAAsB,EACtBC,SAAiC,EACjCC,MAAqB,EACvB;QACE,MAAMC,UAAUF,UAAU,QAAQ,EAAE;QACpC,IAAIE,AAAW,QAAXA,SACAH,QAAQ,MAAM,CACVI,EAAE,MAAM,GAAG,MAAM,CAACC,CAAAA,MAAOA,OAAOF,SAAS;YACrC,SAASF,UAAU,OAAO,IAAI,CAAC,qBAAqB,EAAEE,SAAS;QACnE;IAGZ;;aA/CA,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAAG;aACd,cAAc,GAAG;;AA6CrB;AAEO,MAAMG,mBAAmBC,kBAAkB,oBAAoB,CAAC;IACnE,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"presentation/fieldValidators/validators/DateLteValidator.js","sources":["../../../../src/presentation/fieldValidators/validators/DateLteValidator.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { IFieldBuilder } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport type { CmsModelFieldValidator } from \"~/types.js\";\nimport type { CmsModelField } from \"~/types.js\";\nimport { CmsFieldValidator } from \"../abstractions.js\";\nimport type { ICmsFieldValidatorFormBuilder, ICmsFieldValidatorContext } from \"../abstractions.js\";\nimport {\n buildDateLimitSettingsForm,\n dateLimitSettingsFromForm,\n dateLimitSettingsToForm\n} from \"./dateLimitSettings.js\";\n\nclass DateLteValidatorImpl implements CmsFieldValidator.Interface {\n name = \"dateLte\";\n label = \"Earlier or equal\";\n description =\n \"Entered date/time must be equal or earlier compared to the provided date. A date relative to today is worked out from the current date every time the value is checked.\";\n defaultMessage = \"Must be on or before {date}.\";\n variables = [\n {\n name: \"date\",\n description: \"The latest allowed date, worked out when the value is checked.\"\n }\n ];\n\n buildSettingsForm(form: ICmsFieldValidatorFormBuilder, context: ICmsFieldValidatorContext) {\n buildDateLimitSettingsForm(form, context, {\n valueDescription: \"This is the latest date/time that will be allowed.\"\n });\n }\n\n mapSettingsToForm(settings: Record<string, unknown>, context: ICmsFieldValidatorContext) {\n return dateLimitSettingsToForm(settings, context);\n }\n\n mapSettingsFromForm(settings: Record<string, unknown>) {\n return dateLimitSettingsFromForm(settings);\n }\n\n mapToFieldBuilder(\n builder: IFieldBuilder,\n validator: CmsModelFieldValidator,\n _field: CmsModelField\n ) {\n const maxDate = validator.settings?.value;\n if (maxDate != null) {\n builder.schema(\n z.string().refine(val => val <= maxDate, {\n message: validator.message || `Must be on or before ${maxDate}`\n })\n );\n }\n }\n}\n\nexport const DateLteValidator = CmsFieldValidator.createImplementation({\n implementation: DateLteValidatorImpl,\n dependencies: []\n});\n"],"names":["DateLteValidatorImpl","form","context","buildDateLimitSettingsForm","settings","dateLimitSettingsToForm","dateLimitSettingsFromForm","builder","validator","_field","maxDate","z","val","DateLteValidator","CmsFieldValidator"],"mappings":";;;AAYA,MAAMA;IAaF,kBAAkBC,IAAmC,EAAEC,OAAkC,EAAE;QACvFC,2BAA2BF,MAAMC,SAAS;YACtC,kBAAkB;QACtB;IACJ;IAEA,kBAAkBE,QAAiC,EAAEF,OAAkC,EAAE;QACrF,OAAOG,wBAAwBD,UAAUF;IAC7C;IAEA,oBAAoBE,QAAiC,EAAE;QACnD,OAAOE,0BAA0BF;IACrC;IAEA,kBACIG,OAAsB,EACtBC,SAAiC,EACjCC,MAAqB,EACvB;QACE,MAAMC,UAAUF,UAAU,QAAQ,EAAE;QACpC,IAAIE,AAAW,QAAXA,SACAH,QAAQ,MAAM,CACVI,EAAE,MAAM,GAAG,MAAM,CAACC,CAAAA,MAAOA,OAAOF,SAAS;YACrC,SAASF,UAAU,OAAO,IAAI,CAAC,qBAAqB,EAAEE,SAAS;QACnE;IAGZ;;aAvCA,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GACP;aACJ,cAAc,GAAG;aACjB,SAAS,GAAG;YACR;gBACI,MAAM;gBACN,aAAa;YACjB;SACH;;AA8BL;AAEO,MAAMG,mBAAmBC,kBAAkB,oBAAoB,CAAC;IACnE,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,20 @@
1
+ import { type DateExpressionUnit } from "@webiny/utils";
2
+ import type { ICmsFieldValidatorFormBuilder, ICmsFieldValidatorContext } from "../abstractions.js";
3
+ /**
4
+ * The settings form of the `dateGte`/`dateLte` validators. On a date-only field, a limit is a
5
+ * fixed date or relative to today: a number, a unit and a direction, which the form turns into
6
+ * a date expression (`today-18y`) when the field is saved, and back when it's opened.
7
+ */
8
+ type DateLimitDirection = "before" | "after";
9
+ interface DateLimitFormOptions {
10
+ /** The Value field's description, for a fixed limit. */
11
+ valueDescription: string;
12
+ }
13
+ export declare function buildDateLimitSettingsForm(form: ICmsFieldValidatorFormBuilder, context: ICmsFieldValidatorContext, options: DateLimitFormOptions): void;
14
+ /** Stored settings (`{ value }` or `{ expression }`) as the settings form's values. */
15
+ export declare function dateLimitSettingsToForm(settings: Record<string, unknown>, context: ICmsFieldValidatorContext): Record<string, unknown>;
16
+ /** The settings form's values as stored settings: a fixed `value` or an `expression`. */
17
+ export declare function dateLimitSettingsFromForm(settings: Record<string, unknown>): Record<string, unknown>;
18
+ /** `today`, or `today` plus or minus the amount: 18 years before today is `today-18y`. */
19
+ export declare function toDateExpression(amount: number, unit: DateExpressionUnit, direction: DateLimitDirection): string;
20
+ export {};
@@ -0,0 +1,124 @@
1
+ import { z } from "zod";
2
+ import { parseDateExpression } from "@webiny/utils";
3
+ const isDateOnly = (field)=>{
4
+ const type = field.settings ? field.settings.type : "date";
5
+ return !type || "date" === type;
6
+ };
7
+ const isLiveDateOnly = (form)=>{
8
+ try {
9
+ const type = form.field("general.settingsType").getValue();
10
+ return "string" != typeof type || "date" === type;
11
+ } catch {
12
+ return true;
13
+ }
14
+ };
15
+ const isRelative = ({ field, form })=>isLiveDateOnly(form) && "relative" === field.parent().field("mode").getValue();
16
+ function buildDateLimitSettingsForm(form, context, options) {
17
+ const type = context.field.settings ? context.field.settings.type : "date";
18
+ const relativeAllowed = isDateOnly(context.field);
19
+ form.fields((fields)=>{
20
+ const valueField = fields.datetime().label("Value").description(options.valueDescription);
21
+ switch(type){
22
+ case "time":
23
+ valueField.timeOnly();
24
+ break;
25
+ case "dateTimeWithTimezone":
26
+ valueField.withTimezone();
27
+ break;
28
+ case "dateTimeWithoutTimezone":
29
+ valueField.withoutTimezone();
30
+ break;
31
+ default:
32
+ valueField.dateOnly();
33
+ break;
34
+ }
35
+ if (!relativeAllowed) return {
36
+ value: valueField
37
+ };
38
+ return {
39
+ mode: fields.text().label("Limit").description("A date relative to today is worked out from the current date every time the value is checked.").options([
40
+ {
41
+ value: "fixed",
42
+ label: "Fixed date"
43
+ },
44
+ {
45
+ value: "relative",
46
+ label: "Relative to today"
47
+ }
48
+ ]).defaultValue("fixed").hiddenWhen(({ form })=>!isLiveDateOnly(form)),
49
+ value: valueField.hiddenWhen(isRelative),
50
+ amount: fields.number().label("Amount").required("Enter a number.").schema(z.number().int("Use a whole number.").min(0, "Use 0 or more.")).hiddenWhen((params)=>!isRelative(params)),
51
+ unit: fields.text().label("Unit").options([
52
+ {
53
+ value: "d",
54
+ label: "Days"
55
+ },
56
+ {
57
+ value: "m",
58
+ label: "Months"
59
+ },
60
+ {
61
+ value: "y",
62
+ label: "Years"
63
+ }
64
+ ]).defaultValue("y").hiddenWhen((params)=>!isRelative(params)),
65
+ direction: fields.text().label("Direction").options([
66
+ {
67
+ value: "before",
68
+ label: "Before today"
69
+ },
70
+ {
71
+ value: "after",
72
+ label: "After today"
73
+ }
74
+ ]).defaultValue("before").hiddenWhen((params)=>!isRelative(params))
75
+ };
76
+ });
77
+ form.layout((layout)=>relativeAllowed ? [
78
+ layout.row("mode"),
79
+ layout.row("value"),
80
+ layout.row("amount", "unit", "direction")
81
+ ] : [
82
+ layout.row("value")
83
+ ]);
84
+ }
85
+ function dateLimitSettingsToForm(settings, context) {
86
+ if (!isDateOnly(context.field)) return settings;
87
+ const { expression, ...rest } = settings;
88
+ const parsed = "string" == typeof expression ? parseDateExpression(expression) : null;
89
+ if (!parsed) return {
90
+ ...rest,
91
+ mode: "fixed",
92
+ unit: "y",
93
+ direction: "before"
94
+ };
95
+ const direction = parsed.amount > 0 ? "after" : "before";
96
+ return {
97
+ ...rest,
98
+ mode: "relative",
99
+ amount: Math.abs(parsed.amount),
100
+ unit: 0 === parsed.amount ? "y" : parsed.unit,
101
+ direction
102
+ };
103
+ }
104
+ function dateLimitSettingsFromForm(settings) {
105
+ const { mode, amount, unit, direction, value, expression: _expression, ...rest } = settings;
106
+ if ("relative" === mode) {
107
+ if ("number" != typeof amount) return rest;
108
+ return {
109
+ ...rest,
110
+ expression: toDateExpression(amount, unit, direction)
111
+ };
112
+ }
113
+ return null == value ? rest : {
114
+ ...rest,
115
+ value
116
+ };
117
+ }
118
+ function toDateExpression(amount, unit, direction) {
119
+ if (0 === amount) return "today";
120
+ return `today${"after" === direction ? "+" : "-"}${amount}${unit}`;
121
+ }
122
+ export { buildDateLimitSettingsForm, dateLimitSettingsFromForm, dateLimitSettingsToForm, toDateExpression };
123
+
124
+ //# sourceMappingURL=dateLimitSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation/fieldValidators/validators/dateLimitSettings.js","sources":["../../../../src/presentation/fieldValidators/validators/dateLimitSettings.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { parseDateExpression, type DateExpressionUnit } from \"@webiny/utils\";\nimport type { FormModel, FormModelFactory } from \"@webiny/app-admin\";\nimport type { CmsModelField } from \"~/types.js\";\nimport type { ICmsFieldValidatorFormBuilder, ICmsFieldValidatorContext } from \"../abstractions.js\";\n\n/**\n * The settings form of the `dateGte`/`dateLte` validators. On a date-only field, a limit is a\n * fixed date or relative to today: a number, a unit and a direction, which the form turns into\n * a date expression (`today-18y`) when the field is saved, and back when it's opened.\n */\n\ntype DateLimitDirection = \"before\" | \"after\";\n\ninterface DateLimitFormOptions {\n /** The Value field's description, for a fixed limit. */\n valueDescription: string;\n}\n\nconst isDateOnly = (field: Pick<CmsModelField, \"settings\">): boolean => {\n const type = field.settings ? field.settings.type : \"date\";\n return !type || type === \"date\";\n};\n\n/**\n * The field's Format as it is in the open dialog, which can differ from the saved one on a new\n * field. Only date/time fields have it, and `form.field()` throws for a path the form doesn't\n * have.\n */\nconst isLiveDateOnly = (form: FormModel.Interface): boolean => {\n try {\n const type = form.field(\"general.settingsType\").getValue();\n return typeof type !== \"string\" || type === \"date\";\n } catch {\n return true;\n }\n};\n\nconst isRelative = ({ field, form }: FormModel.CallbackParams): boolean =>\n isLiveDateOnly(form) && field.parent().field(\"mode\").getValue() === \"relative\";\n\nexport function buildDateLimitSettingsForm(\n form: ICmsFieldValidatorFormBuilder,\n context: ICmsFieldValidatorContext,\n options: DateLimitFormOptions\n): void {\n const type = context.field.settings ? context.field.settings.type : \"date\";\n const relativeAllowed = isDateOnly(context.field);\n\n form.fields((fields): Record<string, FormModelFactory.FieldBuilder> => {\n const valueField = fields.datetime().label(\"Value\").description(options.valueDescription);\n\n switch (type) {\n case \"time\":\n valueField.timeOnly();\n break;\n case \"dateTimeWithTimezone\":\n valueField.withTimezone();\n break;\n case \"dateTimeWithoutTimezone\":\n valueField.withoutTimezone();\n break;\n default:\n valueField.dateOnly();\n break;\n }\n\n if (!relativeAllowed) {\n return { value: valueField };\n }\n\n return {\n mode: fields\n .text()\n .label(\"Limit\")\n .description(\n \"A date relative to today is worked out from the current date every time the value is checked.\"\n )\n .options([\n { value: \"fixed\", label: \"Fixed date\" },\n { value: \"relative\", label: \"Relative to today\" }\n ])\n .defaultValue(\"fixed\")\n .hiddenWhen(({ form }: FormModel.CallbackParams) => !isLiveDateOnly(form)),\n value: valueField.hiddenWhen(isRelative),\n amount: fields\n .number()\n .label(\"Amount\")\n .required(\"Enter a number.\")\n .schema(z.number().int(\"Use a whole number.\").min(0, \"Use 0 or more.\"))\n .hiddenWhen(params => !isRelative(params)),\n unit: fields\n .text()\n .label(\"Unit\")\n .options([\n { value: \"d\", label: \"Days\" },\n { value: \"m\", label: \"Months\" },\n { value: \"y\", label: \"Years\" }\n ])\n .defaultValue(\"y\")\n .hiddenWhen(params => !isRelative(params)),\n direction: fields\n .text()\n .label(\"Direction\")\n .options([\n { value: \"before\", label: \"Before today\" },\n { value: \"after\", label: \"After today\" }\n ])\n .defaultValue(\"before\")\n .hiddenWhen(params => !isRelative(params))\n };\n });\n\n form.layout(layout =>\n relativeAllowed\n ? [layout.row(\"mode\"), layout.row(\"value\"), layout.row(\"amount\", \"unit\", \"direction\")]\n : [layout.row(\"value\")]\n );\n}\n\n/** Stored settings (`{ value }` or `{ expression }`) as the settings form's values. */\nexport function dateLimitSettingsToForm(\n settings: Record<string, unknown>,\n context: ICmsFieldValidatorContext\n): Record<string, unknown> {\n if (!isDateOnly(context.field)) {\n return settings;\n }\n const { expression, ...rest } = settings;\n const parsed = typeof expression === \"string\" ? parseDateExpression(expression) : null;\n if (!parsed) {\n return { ...rest, mode: \"fixed\", unit: \"y\", direction: \"before\" };\n }\n const direction: DateLimitDirection = parsed.amount > 0 ? \"after\" : \"before\";\n return {\n ...rest,\n mode: \"relative\",\n amount: Math.abs(parsed.amount),\n // Plain `today` parses as 0 days; years is the form's default unit.\n unit: parsed.amount === 0 ? \"y\" : parsed.unit,\n direction\n };\n}\n\n/** The settings form's values as stored settings: a fixed `value` or an `expression`. */\nexport function dateLimitSettingsFromForm(\n settings: Record<string, unknown>\n): Record<string, unknown> {\n const { mode, amount, unit, direction, value, expression: _expression, ...rest } = settings;\n if (mode === \"relative\") {\n if (typeof amount !== \"number\") {\n return rest;\n }\n return {\n ...rest,\n expression: toDateExpression(\n amount,\n unit as DateExpressionUnit,\n direction as DateLimitDirection\n )\n };\n }\n return value == null ? rest : { ...rest, value };\n}\n\n/** `today`, or `today` plus or minus the amount: 18 years before today is `today-18y`. */\nexport function toDateExpression(\n amount: number,\n unit: DateExpressionUnit,\n direction: DateLimitDirection\n): string {\n if (amount === 0) {\n return \"today\";\n }\n return `today${direction === \"after\" ? \"+\" : \"-\"}${amount}${unit}`;\n}\n"],"names":["isDateOnly","field","type","isLiveDateOnly","form","isRelative","buildDateLimitSettingsForm","context","options","relativeAllowed","fields","valueField","z","params","layout","dateLimitSettingsToForm","settings","expression","rest","parsed","parseDateExpression","direction","Math","dateLimitSettingsFromForm","mode","amount","unit","value","_expression","toDateExpression"],"mappings":";;AAmBA,MAAMA,aAAa,CAACC;IAChB,MAAMC,OAAOD,MAAM,QAAQ,GAAGA,MAAM,QAAQ,CAAC,IAAI,GAAG;IACpD,OAAO,CAACC,QAAQA,AAAS,WAATA;AACpB;AAOA,MAAMC,iBAAiB,CAACC;IACpB,IAAI;QACA,MAAMF,OAAOE,KAAK,KAAK,CAAC,wBAAwB,QAAQ;QACxD,OAAO,AAAgB,YAAhB,OAAO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,EAAEL,SAAS,EAAEM,KAAK,EAAE,YAAYC,WAAW,EAAE,GAAGV,MAAM,GAAGF;IACnF,IAAIQ,AAAS,eAATA,MAAqB;QACrB,IAAI,AAAkB,YAAlB,OAAOC,QACP,OAAOP;QAEX,OAAO;YACH,GAAGA,IAAI;YACP,YAAYW,iBACRJ,QACAC,MACAL;QAER;IACJ;IACA,OAAOM,AAAS,QAATA,QAAgBT,OAAO;QAAE,GAAGA,IAAI;QAAES;IAAM;AACnD;AAGO,SAASE,iBACZJ,MAAc,EACdC,IAAwB,EACxBL,SAA6B;IAE7B,IAAII,AAAW,MAAXA,QACA,OAAO;IAEX,OAAO,CAAC,KAAK,EAAEJ,AAAc,YAAdA,YAAwB,MAAM,MAAMI,SAASC,MAAM;AACtE"}
@@ -0,0 +1,111 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { dateLimitSettingsFromForm, dateLimitSettingsToForm, toDateExpression } from "./dateLimitSettings.js";
3
+ const context = (type)=>({
4
+ field: {
5
+ type: "datetime",
6
+ settings: type ? {
7
+ type
8
+ } : {}
9
+ }
10
+ });
11
+ describe("date limit settings", ()=>{
12
+ it("opens a relative limit as an amount, a unit and a direction", ()=>{
13
+ expect(dateLimitSettingsToForm({
14
+ expression: "today-18y"
15
+ }, context("date"))).toEqual({
16
+ mode: "relative",
17
+ amount: 18,
18
+ unit: "y",
19
+ direction: "before"
20
+ });
21
+ expect(dateLimitSettingsToForm({
22
+ expression: "today+1d"
23
+ }, context("date"))).toEqual({
24
+ mode: "relative",
25
+ amount: 1,
26
+ unit: "d",
27
+ direction: "after"
28
+ });
29
+ expect(dateLimitSettingsToForm({
30
+ expression: "today"
31
+ }, context())).toMatchObject({
32
+ mode: "relative",
33
+ amount: 0
34
+ });
35
+ });
36
+ it("opens a fixed limit as a fixed date", ()=>{
37
+ expect(dateLimitSettingsToForm({
38
+ value: "2000-12-31"
39
+ }, context("date"))).toEqual({
40
+ value: "2000-12-31",
41
+ mode: "fixed",
42
+ unit: "y",
43
+ direction: "before"
44
+ });
45
+ });
46
+ it("leaves the settings of a time or datetime field as they are", ()=>{
47
+ expect(dateLimitSettingsToForm({
48
+ value: "10:00:00"
49
+ }, context("time"))).toEqual({
50
+ value: "10:00:00"
51
+ });
52
+ });
53
+ it("saves a relative limit as an expression, without the form's own values", ()=>{
54
+ expect(dateLimitSettingsFromForm({
55
+ mode: "relative",
56
+ value: "2000-12-31",
57
+ amount: 18,
58
+ unit: "y",
59
+ direction: "before"
60
+ })).toEqual({
61
+ expression: "today-18y"
62
+ });
63
+ expect(dateLimitSettingsFromForm({
64
+ mode: "relative",
65
+ amount: 0,
66
+ unit: "d",
67
+ direction: "after"
68
+ })).toEqual({
69
+ expression: "today"
70
+ });
71
+ });
72
+ it("saves a fixed limit as a value, dropping an earlier expression", ()=>{
73
+ expect(dateLimitSettingsFromForm({
74
+ mode: "fixed",
75
+ value: "2000-12-31",
76
+ expression: "today-18y",
77
+ amount: 18,
78
+ unit: "y",
79
+ direction: "before"
80
+ })).toEqual({
81
+ value: "2000-12-31"
82
+ });
83
+ expect(dateLimitSettingsFromForm({
84
+ value: "10:00:00"
85
+ })).toEqual({
86
+ value: "10:00:00"
87
+ });
88
+ });
89
+ it("round-trips what it opens", ()=>{
90
+ for (const expression of [
91
+ "today-18y",
92
+ "today+3m",
93
+ "today-100y",
94
+ "today+1d"
95
+ ]){
96
+ const form = dateLimitSettingsToForm({
97
+ expression
98
+ }, context("date"));
99
+ expect(dateLimitSettingsFromForm(form)).toEqual({
100
+ expression
101
+ });
102
+ }
103
+ });
104
+ it("builds expressions", ()=>{
105
+ expect(toDateExpression(18, "y", "before")).toBe("today-18y");
106
+ expect(toDateExpression(2, "m", "after")).toBe("today+2m");
107
+ expect(toDateExpression(0, "y", "before")).toBe("today");
108
+ });
109
+ });
110
+
111
+ //# sourceMappingURL=dateLimitSettings.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation/fieldValidators/validators/dateLimitSettings.test.js","sources":["../../../../src/presentation/fieldValidators/validators/dateLimitSettings.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport type { CmsModelField } from \"~/types.js\";\nimport {\n dateLimitSettingsFromForm,\n dateLimitSettingsToForm,\n toDateExpression\n} from \"./dateLimitSettings.js\";\n\nconst context = (type?: string) => ({\n field: { type: \"datetime\", settings: type ? { type } : {} } as unknown as CmsModelField\n});\n\ndescribe(\"date limit settings\", () => {\n it(\"opens a relative limit as an amount, a unit and a direction\", () => {\n expect(dateLimitSettingsToForm({ expression: \"today-18y\" }, context(\"date\"))).toEqual({\n mode: \"relative\",\n amount: 18,\n unit: \"y\",\n direction: \"before\"\n });\n expect(dateLimitSettingsToForm({ expression: \"today+1d\" }, context(\"date\"))).toEqual({\n mode: \"relative\",\n amount: 1,\n unit: \"d\",\n direction: \"after\"\n });\n expect(dateLimitSettingsToForm({ expression: \"today\" }, context())).toMatchObject({\n mode: \"relative\",\n amount: 0\n });\n });\n\n it(\"opens a fixed limit as a fixed date\", () => {\n expect(dateLimitSettingsToForm({ value: \"2000-12-31\" }, context(\"date\"))).toEqual({\n value: \"2000-12-31\",\n mode: \"fixed\",\n unit: \"y\",\n direction: \"before\"\n });\n });\n\n it(\"leaves the settings of a time or datetime field as they are\", () => {\n expect(dateLimitSettingsToForm({ value: \"10:00:00\" }, context(\"time\"))).toEqual({\n value: \"10:00:00\"\n });\n });\n\n it(\"saves a relative limit as an expression, without the form's own values\", () => {\n expect(\n dateLimitSettingsFromForm({\n mode: \"relative\",\n value: \"2000-12-31\",\n amount: 18,\n unit: \"y\",\n direction: \"before\"\n })\n ).toEqual({ expression: \"today-18y\" });\n expect(\n dateLimitSettingsFromForm({\n mode: \"relative\",\n amount: 0,\n unit: \"d\",\n direction: \"after\"\n })\n ).toEqual({ expression: \"today\" });\n });\n\n it(\"saves a fixed limit as a value, dropping an earlier expression\", () => {\n expect(\n dateLimitSettingsFromForm({\n mode: \"fixed\",\n value: \"2000-12-31\",\n expression: \"today-18y\",\n amount: 18,\n unit: \"y\",\n direction: \"before\"\n })\n ).toEqual({ value: \"2000-12-31\" });\n // A time or datetime field's form has only the value.\n expect(dateLimitSettingsFromForm({ value: \"10:00:00\" })).toEqual({ value: \"10:00:00\" });\n });\n\n it(\"round-trips what it opens\", () => {\n for (const expression of [\"today-18y\", \"today+3m\", \"today-100y\", \"today+1d\"]) {\n const form = dateLimitSettingsToForm({ expression }, context(\"date\"));\n expect(dateLimitSettingsFromForm(form)).toEqual({ expression });\n }\n });\n\n it(\"builds expressions\", () => {\n expect(toDateExpression(18, \"y\", \"before\")).toBe(\"today-18y\");\n expect(toDateExpression(2, \"m\", \"after\")).toBe(\"today+2m\");\n expect(toDateExpression(0, \"y\", \"before\")).toBe(\"today\");\n });\n});\n"],"names":["context","type","describe","it","expect","dateLimitSettingsToForm","dateLimitSettingsFromForm","expression","form","toDateExpression"],"mappings":";;AAQA,MAAMA,UAAU,CAACC,OAAmB;QAChC,OAAO;YAAE,MAAM;YAAY,UAAUA,OAAO;gBAAEA;YAAK,IAAI,CAAC;QAAE;IAC9D;AAEAC,SAAS,uBAAuB;IAC5BC,GAAG,+DAA+D;QAC9DC,OAAOC,wBAAwB;YAAE,YAAY;QAAY,GAAGL,QAAQ,UAAU,OAAO,CAAC;YAClF,MAAM;YACN,QAAQ;YACR,MAAM;YACN,WAAW;QACf;QACAI,OAAOC,wBAAwB;YAAE,YAAY;QAAW,GAAGL,QAAQ,UAAU,OAAO,CAAC;YACjF,MAAM;YACN,QAAQ;YACR,MAAM;YACN,WAAW;QACf;QACAI,OAAOC,wBAAwB;YAAE,YAAY;QAAQ,GAAGL,YAAY,aAAa,CAAC;YAC9E,MAAM;YACN,QAAQ;QACZ;IACJ;IAEAG,GAAG,uCAAuC;QACtCC,OAAOC,wBAAwB;YAAE,OAAO;QAAa,GAAGL,QAAQ,UAAU,OAAO,CAAC;YAC9E,OAAO;YACP,MAAM;YACN,MAAM;YACN,WAAW;QACf;IACJ;IAEAG,GAAG,+DAA+D;QAC9DC,OAAOC,wBAAwB;YAAE,OAAO;QAAW,GAAGL,QAAQ,UAAU,OAAO,CAAC;YAC5E,OAAO;QACX;IACJ;IAEAG,GAAG,0EAA0E;QACzEC,OACIE,0BAA0B;YACtB,MAAM;YACN,OAAO;YACP,QAAQ;YACR,MAAM;YACN,WAAW;QACf,IACF,OAAO,CAAC;YAAE,YAAY;QAAY;QACpCF,OACIE,0BAA0B;YACtB,MAAM;YACN,QAAQ;YACR,MAAM;YACN,WAAW;QACf,IACF,OAAO,CAAC;YAAE,YAAY;QAAQ;IACpC;IAEAH,GAAG,kEAAkE;QACjEC,OACIE,0BAA0B;YACtB,MAAM;YACN,OAAO;YACP,YAAY;YACZ,QAAQ;YACR,MAAM;YACN,WAAW;QACf,IACF,OAAO,CAAC;YAAE,OAAO;QAAa;QAEhCF,OAAOE,0BAA0B;YAAE,OAAO;QAAW,IAAI,OAAO,CAAC;YAAE,OAAO;QAAW;IACzF;IAEAH,GAAG,6BAA6B;QAC5B,KAAK,MAAMI,cAAc;YAAC;YAAa;YAAY;YAAc;SAAW,CAAE;YAC1E,MAAMC,OAAOH,wBAAwB;gBAAEE;YAAW,GAAGP,QAAQ;YAC7DI,OAAOE,0BAA0BE,OAAO,OAAO,CAAC;gBAAED;YAAW;QACjE;IACJ;IAEAJ,GAAG,sBAAsB;QACrBC,OAAOK,iBAAiB,IAAI,KAAK,WAAW,IAAI,CAAC;QACjDL,OAAOK,iBAAiB,GAAG,KAAK,UAAU,IAAI,CAAC;QAC/CL,OAAOK,iBAAiB,GAAG,KAAK,WAAW,IAAI,CAAC;IACpD;AACJ"}
@@ -9,7 +9,7 @@ const createSelected = (params)=>{
9
9
  for (const id of item.related){
10
10
  const model = models.find((model)=>model.id === id);
11
11
  if (!model) continue;
12
- if (selected.has(model.id) || model.imported) continue;
12
+ else if (selected.has(model.id) || model.imported) continue;
13
13
  const related = createSelected({
14
14
  previous: selected,
15
15
  models,
@@ -1 +1 @@
1
- {"version":3,"file":"presentation/importContentModels/ImportContentModelsPresenter.js","sources":["../../../src/presentation/importContentModels/ImportContentModelsPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport type { CmsGroup, CmsModel } from \"@webiny/app-headless-cms-common/types/index.js\";\nimport type { ImportGroupData, ImportModelData } from \"./types.js\";\nimport { ImportAction } from \"./types.js\";\nimport type { ImportStructureVariablesGroup, ImportStructureVariablesModel } from \"./graphql.js\";\nimport { ValidateImportUseCase } from \"~/features/model/importModels/abstractions.js\";\nimport { ImportModelsUseCase } from \"~/features/model/importModels/abstractions.js\";\nimport {\n ImportContentModelsPresenter as Abstraction,\n type IImportContentModelsPresenter,\n type IImportContentModelsPresenterViewModel\n} from \"./abstractions.js\";\n\ninterface Data {\n groups: CmsGroup[];\n models: CmsModel[];\n}\n\ntype Selected = Map<string, string[]>;\n\ninterface CreateSelectedParams {\n previous: Selected;\n models: Pick<ImportModelData, \"id\" | \"related\" | \"imported\">[];\n item: Pick<ImportModelData, \"id\" | \"related\">;\n}\n\nconst createSelected = (params: CreateSelectedParams): Selected => {\n const { previous, models, item } = params;\n let selected = new Map(previous);\n\n selected.set(item.id, item.related);\n for (const id of item.related) {\n const model = models.find(model => model.id === id);\n if (!model) {\n continue;\n } else if (selected.has(model.id) || model.imported) {\n continue;\n }\n const related = createSelected({\n previous: selected,\n models,\n item: model\n });\n selected = new Map([...selected, ...related]);\n }\n\n return selected;\n};\n\ninterface DataToImportResult {\n groups: ImportStructureVariablesGroup[];\n models: ImportStructureVariablesModel[];\n}\n\nclass ImportContentModelsPresenterImpl implements IImportContentModelsPresenter {\n private data: Data | null = null;\n private loading = false;\n private groups: ImportGroupData[] = [];\n private models: ImportModelData[] = [];\n private file: File | null = null;\n private errors: string[] = [];\n private validated = false;\n private selected: Selected = new Map();\n\n constructor(\n private validateUseCase: ValidateImportUseCase.Interface,\n private importUseCase: ImportModelsUseCase.Interface\n ) {\n makeAutoObservable<ImportContentModelsPresenterImpl, \"validateUseCase\" | \"importUseCase\">(\n this,\n {\n validateUseCase: false,\n importUseCase: false\n }\n );\n }\n\n get vm(): IImportContentModelsPresenterViewModel {\n return {\n data: this.data,\n loading: this.loading,\n groups: this.groups,\n models: this.models,\n file: this.file,\n errors: this.errors,\n validated: this.validated\n };\n }\n\n hasSelected(): boolean {\n return this.selected.size > 0;\n }\n\n isModelSelected(item: Pick<ImportModelData, \"id\">): boolean {\n return this.selected.has(item.id);\n }\n\n isModelRelated({ id: target }: Pick<ImportModelData, \"id\">): boolean {\n for (const id of this.selected.keys()) {\n if (id === target) {\n continue;\n }\n const related = this.selected.get(id);\n if (related && related.includes(target)) {\n return true;\n }\n }\n return false;\n }\n\n onFile(file: File): void {\n const reader = new FileReader();\n reader.addEventListener(\"load\", event => {\n try {\n const data = this.parseFileContent(event.target?.result);\n runInAction(() => {\n this.models = [];\n this.groups = [];\n this.selected = new Map();\n this.errors = [];\n this.validated = false;\n this.file = file;\n this.data = data;\n });\n } catch (ex: any) {\n runInAction(() => {\n this.file = file;\n this.selected = new Map();\n this.validated = false;\n this.groups = [];\n this.models = [];\n this.data = null;\n this.errors = [ex.message];\n });\n }\n });\n reader.readAsText(file);\n }\n\n onFileError(error: string): void {\n this.file = null;\n this.errors = [error];\n }\n\n toggleModel(item: Pick<ImportModelData, \"id\" | \"name\" | \"related\">): void {\n if (this.isModelSelected(item)) {\n this.removeModel(item);\n } else {\n this.addModel(item);\n }\n }\n\n async handleModelsValidation(): Promise<void> {\n if (!this.data) {\n return;\n }\n\n this.loading = true;\n\n try {\n const data = await this.validateUseCase.execute(this.data as any);\n\n runInAction(() => {\n this.loading = false;\n this.groups = data.groups.map(group => ({\n id: group.group.id,\n name: group.group.name,\n slug: group.group.slug,\n error: group.error,\n action: group.action\n }));\n this.models = data.models.map(model => ({\n id: model.model.modelId,\n name: model.model.name,\n group: model.model.group,\n related: model.related || [],\n error: model.error,\n action: model.action\n }));\n this.validated = true;\n });\n } catch (ex: any) {\n runInAction(() => {\n this.loading = false;\n this.errors = [ex.message];\n });\n }\n }\n\n async handleModelsImport(): Promise<void> {\n if (!this.data || !this.groups.length || !this.models.length || !this.selected.size) {\n return;\n }\n\n this.loading = true;\n\n const dataToImport = this.getDataToImport();\n\n try {\n const data = await this.importUseCase.execute(dataToImport);\n\n runInAction(() => {\n this.loading = false;\n this.selected = new Map();\n this.groups = this.groups.map(group => {\n const result = data.groups.find(item => item.group.id === group.id);\n return {\n id: result?.group.id || group.id,\n name: result?.group.name || group.name,\n slug: result?.group.slug || group.slug,\n error: result?.error || group.error,\n imported: result ? result.imported : group.imported\n };\n });\n this.models = this.models.map(model => {\n const result = data.models.find(item => item.model.modelId === model.id);\n return {\n id: result?.model.modelId || model.id,\n name: result?.model.name || model.name,\n group: result?.model.group || model.group,\n related: result?.related || model.related || [],\n action: result?.action || model.action,\n error: result?.error || model.error,\n imported: result ? result.imported : model.imported\n };\n });\n this.validated = true;\n });\n } catch (ex: any) {\n runInAction(() => {\n this.loading = false;\n this.errors = [ex.message];\n });\n }\n }\n\n reset(): void {\n this.data = null;\n this.loading = false;\n this.groups = [];\n this.models = [];\n this.file = null;\n this.errors = [];\n this.validated = false;\n this.selected = new Map();\n }\n\n private addModel(item: Pick<ImportModelData, \"id\" | \"name\" | \"related\">): void {\n if (this.isModelSelected(item)) {\n return;\n }\n this.selected = createSelected({\n previous: this.selected,\n models: this.models,\n item\n });\n }\n\n private removeModel(item: Pick<ImportModelData, \"id\" | \"name\" | \"related\">): void {\n if (this.isModelRelated(item)) {\n return;\n }\n const selected = new Map(this.selected);\n selected.delete(item.id);\n this.selected = selected;\n }\n\n private getDataToImport(): DataToImportResult {\n const selected = Array.from(this.selected.keys());\n const groups: Map<string, ImportStructureVariablesGroup> = new Map();\n const models: Map<string, ImportStructureVariablesModel> = new Map();\n const noAction = [ImportAction.CODE, ImportAction.NONE];\n\n for (const id of selected) {\n const validatedModel = this.models.find(model => model.id === id);\n if (\n !validatedModel?.action ||\n validatedModel.error ||\n noAction.includes(validatedModel.action)\n ) {\n continue;\n }\n const validatedGroup = this.groups.find(group => group.slug === validatedModel.group);\n if (!validatedGroup?.action || validatedGroup.error) {\n continue;\n }\n\n const model = this.data?.models?.find(model => model.modelId === id);\n if (!model) {\n continue;\n }\n models.set(id, {\n ...model,\n layout: model.layout || [],\n titleFieldId: model.titleFieldId || \"id\",\n descriptionFieldId: model.descriptionFieldId || \"\",\n imageFieldId: model.imageFieldId || \"\",\n group: validatedModel.group\n });\n\n if (noAction.includes(validatedGroup.action)) {\n continue;\n }\n\n const group = this.data?.groups?.find(group => group.slug === validatedModel.group);\n if (!group) {\n continue;\n }\n groups.set(group.id, group);\n }\n\n return {\n groups: Array.from(groups.values()),\n models: Array.from(models.values())\n };\n }\n\n private parseFileContent(content?: string | ArrayBuffer | null): Data {\n if (!content) {\n throw new Error(\"Missing data in uploaded file.\");\n }\n const raw =\n content instanceof ArrayBuffer ? Buffer.from(content).toString(\"utf8\") : content;\n\n let data: Record<string, any> = {};\n try {\n data = JSON.parse(raw);\n } catch {\n throw new Error(\"Could not parse the uploaded file. Make sure it's a valid JSON file.\");\n }\n if (!data.groups?.length && !data.models?.length) {\n throw new Error(\"No groups and models in the uploaded file.\");\n } else if (data.groups.length === 0) {\n throw new Error(\"No groups in the uploaded file. There must be at least one group.\");\n }\n return {\n groups: data.groups,\n models: data.models\n };\n }\n}\n\nexport const ImportContentModelsPresenter = Abstraction.createImplementation({\n implementation: ImportContentModelsPresenterImpl,\n dependencies: [ValidateImportUseCase, ImportModelsUseCase]\n});\n"],"names":["createSelected","params","previous","models","item","selected","Map","id","model","related","ImportContentModelsPresenterImpl","validateUseCase","importUseCase","makeAutoObservable","target","file","reader","FileReader","event","data","runInAction","ex","error","group","dataToImport","result","Array","groups","noAction","ImportAction","validatedModel","validatedGroup","content","Error","raw","ArrayBuffer","Buffer","JSON","ImportContentModelsPresenter","Abstraction","ValidateImportUseCase","ImportModelsUseCase"],"mappings":";;;;AA0BA,MAAMA,iBAAiB,CAACC;IACpB,MAAM,E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AAvBA,KAAK,MAAM,CAAC,MAAM,EACzB,MAAM,IAAIc,MAAM;QACpB,OAHI,MAAM,IAAIA,MAAM;QAIpB,OAAO;YACH,QAAQd,KAAK,MAAM;YACnB,QAAQA,KAAK,MAAM;QACvB;IACJ;AACJ;AAEO,MAAMmB,4DAA+BC,6BAAAA,oBAAgC,CAAC;IACzE,gBAAgB7B;IAChB,cAAc;QAAC8B;QAAuBC;KAAoB;AAC9D"}
1
+ {"version":3,"file":"presentation/importContentModels/ImportContentModelsPresenter.js","sources":["../../../src/presentation/importContentModels/ImportContentModelsPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport type { CmsGroup, CmsModel } from \"@webiny/app-headless-cms-common/types/index.js\";\nimport type { ImportGroupData, ImportModelData } from \"./types.js\";\nimport { ImportAction } from \"./types.js\";\nimport type { ImportStructureVariablesGroup, ImportStructureVariablesModel } from \"./graphql.js\";\nimport { ValidateImportUseCase } from \"~/features/model/importModels/abstractions.js\";\nimport { ImportModelsUseCase } from \"~/features/model/importModels/abstractions.js\";\nimport {\n ImportContentModelsPresenter as Abstraction,\n type IImportContentModelsPresenter,\n type IImportContentModelsPresenterViewModel\n} from \"./abstractions.js\";\n\ninterface Data {\n groups: CmsGroup[];\n models: CmsModel[];\n}\n\ntype Selected = Map<string, string[]>;\n\ninterface CreateSelectedParams {\n previous: Selected;\n models: Pick<ImportModelData, \"id\" | \"related\" | \"imported\">[];\n item: Pick<ImportModelData, \"id\" | \"related\">;\n}\n\nconst createSelected = (params: CreateSelectedParams): Selected => {\n const { previous, models, item } = params;\n let selected = new Map(previous);\n\n selected.set(item.id, item.related);\n for (const id of item.related) {\n const model = models.find(model => model.id === id);\n if (!model) {\n continue;\n } else if (selected.has(model.id) || model.imported) {\n continue;\n }\n const related = createSelected({\n previous: selected,\n models,\n item: model\n });\n selected = new Map([...selected, ...related]);\n }\n\n return selected;\n};\n\ninterface DataToImportResult {\n groups: ImportStructureVariablesGroup[];\n models: ImportStructureVariablesModel[];\n}\n\nclass ImportContentModelsPresenterImpl implements IImportContentModelsPresenter {\n private data: Data | null = null;\n private loading = false;\n private groups: ImportGroupData[] = [];\n private models: ImportModelData[] = [];\n private file: File | null = null;\n private errors: string[] = [];\n private validated = false;\n private selected: Selected = new Map();\n\n constructor(\n private validateUseCase: ValidateImportUseCase.Interface,\n private importUseCase: ImportModelsUseCase.Interface\n ) {\n makeAutoObservable<ImportContentModelsPresenterImpl, \"validateUseCase\" | \"importUseCase\">(\n this,\n {\n validateUseCase: false,\n importUseCase: false\n }\n );\n }\n\n get vm(): IImportContentModelsPresenterViewModel {\n return {\n data: this.data,\n loading: this.loading,\n groups: this.groups,\n models: this.models,\n file: this.file,\n errors: this.errors,\n validated: this.validated\n };\n }\n\n hasSelected(): boolean {\n return this.selected.size > 0;\n }\n\n isModelSelected(item: Pick<ImportModelData, \"id\">): boolean {\n return this.selected.has(item.id);\n }\n\n isModelRelated({ id: target }: Pick<ImportModelData, \"id\">): boolean {\n for (const id of this.selected.keys()) {\n if (id === target) {\n continue;\n }\n const related = this.selected.get(id);\n if (related && related.includes(target)) {\n return true;\n }\n }\n return false;\n }\n\n onFile(file: File): void {\n const reader = new FileReader();\n reader.addEventListener(\"load\", event => {\n try {\n const data = this.parseFileContent(event.target?.result);\n runInAction(() => {\n this.models = [];\n this.groups = [];\n this.selected = new Map();\n this.errors = [];\n this.validated = false;\n this.file = file;\n this.data = data;\n });\n } catch (ex: any) {\n runInAction(() => {\n this.file = file;\n this.selected = new Map();\n this.validated = false;\n this.groups = [];\n this.models = [];\n this.data = null;\n this.errors = [ex.message];\n });\n }\n });\n reader.readAsText(file);\n }\n\n onFileError(error: string): void {\n this.file = null;\n this.errors = [error];\n }\n\n toggleModel(item: Pick<ImportModelData, \"id\" | \"name\" | \"related\">): void {\n if (this.isModelSelected(item)) {\n this.removeModel(item);\n } else {\n this.addModel(item);\n }\n }\n\n async handleModelsValidation(): Promise<void> {\n if (!this.data) {\n return;\n }\n\n this.loading = true;\n\n try {\n const data = await this.validateUseCase.execute(this.data as any);\n\n runInAction(() => {\n this.loading = false;\n this.groups = data.groups.map(group => ({\n id: group.group.id,\n name: group.group.name,\n slug: group.group.slug,\n error: group.error,\n action: group.action\n }));\n this.models = data.models.map(model => ({\n id: model.model.modelId,\n name: model.model.name,\n group: model.model.group,\n related: model.related || [],\n error: model.error,\n action: model.action\n }));\n this.validated = true;\n });\n } catch (ex: any) {\n runInAction(() => {\n this.loading = false;\n this.errors = [ex.message];\n });\n }\n }\n\n async handleModelsImport(): Promise<void> {\n if (!this.data || !this.groups.length || !this.models.length || !this.selected.size) {\n return;\n }\n\n this.loading = true;\n\n const dataToImport = this.getDataToImport();\n\n try {\n const data = await this.importUseCase.execute(dataToImport);\n\n runInAction(() => {\n this.loading = false;\n this.selected = new Map();\n this.groups = this.groups.map(group => {\n const result = data.groups.find(item => item.group.id === group.id);\n return {\n id: result?.group.id || group.id,\n name: result?.group.name || group.name,\n slug: result?.group.slug || group.slug,\n error: result?.error || group.error,\n imported: result ? result.imported : group.imported\n };\n });\n this.models = this.models.map(model => {\n const result = data.models.find(item => item.model.modelId === model.id);\n return {\n id: result?.model.modelId || model.id,\n name: result?.model.name || model.name,\n group: result?.model.group || model.group,\n related: result?.related || model.related || [],\n action: result?.action || model.action,\n error: result?.error || model.error,\n imported: result ? result.imported : model.imported\n };\n });\n this.validated = true;\n });\n } catch (ex: any) {\n runInAction(() => {\n this.loading = false;\n this.errors = [ex.message];\n });\n }\n }\n\n reset(): void {\n this.data = null;\n this.loading = false;\n this.groups = [];\n this.models = [];\n this.file = null;\n this.errors = [];\n this.validated = false;\n this.selected = new Map();\n }\n\n private addModel(item: Pick<ImportModelData, \"id\" | \"name\" | \"related\">): void {\n if (this.isModelSelected(item)) {\n return;\n }\n this.selected = createSelected({\n previous: this.selected,\n models: this.models,\n item\n });\n }\n\n private removeModel(item: Pick<ImportModelData, \"id\" | \"name\" | \"related\">): void {\n if (this.isModelRelated(item)) {\n return;\n }\n const selected = new Map(this.selected);\n selected.delete(item.id);\n this.selected = selected;\n }\n\n private getDataToImport(): DataToImportResult {\n const selected = Array.from(this.selected.keys());\n const groups: Map<string, ImportStructureVariablesGroup> = new Map();\n const models: Map<string, ImportStructureVariablesModel> = new Map();\n const noAction = [ImportAction.CODE, ImportAction.NONE];\n\n for (const id of selected) {\n const validatedModel = this.models.find(model => model.id === id);\n if (\n !validatedModel?.action ||\n validatedModel.error ||\n noAction.includes(validatedModel.action)\n ) {\n continue;\n }\n const validatedGroup = this.groups.find(group => group.slug === validatedModel.group);\n if (!validatedGroup?.action || validatedGroup.error) {\n continue;\n }\n\n const model = this.data?.models?.find(model => model.modelId === id);\n if (!model) {\n continue;\n }\n models.set(id, {\n ...model,\n layout: model.layout || [],\n titleFieldId: model.titleFieldId || \"id\",\n descriptionFieldId: model.descriptionFieldId || \"\",\n imageFieldId: model.imageFieldId || \"\",\n group: validatedModel.group\n });\n\n if (noAction.includes(validatedGroup.action)) {\n continue;\n }\n\n const group = this.data?.groups?.find(group => group.slug === validatedModel.group);\n if (!group) {\n continue;\n }\n groups.set(group.id, group);\n }\n\n return {\n groups: Array.from(groups.values()),\n models: Array.from(models.values())\n };\n }\n\n private parseFileContent(content?: string | ArrayBuffer | null): Data {\n if (!content) {\n throw new Error(\"Missing data in uploaded file.\");\n }\n const raw =\n content instanceof ArrayBuffer ? Buffer.from(content).toString(\"utf8\") : content;\n\n let data: Record<string, any> = {};\n try {\n data = JSON.parse(raw);\n } catch {\n throw new Error(\"Could not parse the uploaded file. Make sure it's a valid JSON file.\");\n }\n if (!data.groups?.length && !data.models?.length) {\n throw new Error(\"No groups and models in the uploaded file.\");\n } else if (data.groups.length === 0) {\n throw new Error(\"No groups in the uploaded file. There must be at least one group.\");\n }\n return {\n groups: data.groups,\n models: data.models\n };\n }\n}\n\nexport const ImportContentModelsPresenter = Abstraction.createImplementation({\n implementation: ImportContentModelsPresenterImpl,\n dependencies: [ValidateImportUseCase, ImportModelsUseCase]\n});\n"],"names":["createSelected","params","previous","models","item","selected","Map","id","model","related","ImportContentModelsPresenterImpl","validateUseCase","importUseCase","makeAutoObservable","target","file","reader","FileReader","event","data","runInAction","ex","error","group","dataToImport","result","Array","groups","noAction","ImportAction","validatedModel","validatedGroup","content","Error","raw","ArrayBuffer","Buffer","JSON","ImportContentModelsPresenter","Abstraction","ValidateImportUseCase","ImportModelsUseCase"],"mappings":";;;;AA0BA,MAAMA,iBAAiB,CAACC;IACpB,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGH;IACnC,IAAII,WAAW,IAAIC,IAAIJ;IAEvBG,SAAS,GAAG,CAACD,KAAK,EAAE,EAAEA,KAAK,OAAO;IAClC,KAAK,MAAMG,MAAMH,KAAK,OAAO,CAAE;QAC3B,MAAMI,QAAQL,OAAO,IAAI,CAACK,CAAAA,QAASA,MAAM,EAAE,KAAKD;QAChD,IAAI,CAACC,OACD;aACG,IAAIH,SAAS,GAAG,CAACG,MAAM,EAAE,KAAKA,MAAM,QAAQ,EAC/C;QAEJ,MAAMC,UAAUT,eAAe;YAC3B,UAAUK;YACVF;YACA,MAAMK;QACV;QACAH,WAAW,IAAIC,IAAI;eAAID;eAAaI;SAAQ;IAChD;IAEA,OAAOJ;AACX;AAOA,MAAMK;IAUF,YACYC,eAAgD,EAChDC,aAA4C,CACtD;aAFUD,eAAe,GAAfA;aACAC,aAAa,GAAbA;aAXJ,IAAI,GAAgB;aACpB,OAAO,GAAG;aACV,MAAM,GAAsB,EAAE;aAC9B,MAAM,GAAsB,EAAE;aAC9B,IAAI,GAAgB;aACpB,MAAM,GAAa,EAAE;aACrB,SAAS,GAAG;aACZ,QAAQ,GAAa,IAAIN;QAM7BO,mBACI,IAAI,EACJ;YACI,iBAAiB;YACjB,eAAe;QACnB;IAER;IAEA,IAAI,KAA6C;QAC7C,OAAO;YACH,MAAM,IAAI,CAAC,IAAI;YACf,SAAS,IAAI,CAAC,OAAO;YACrB,QAAQ,IA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