@webiny/app-headless-cms 6.6.0-alpha.1 → 6.6.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ContentEntriesModule.js +20 -3
- package/ContentEntriesModule.js.map +1 -1
- package/admin/RoutesConfig.js +5 -1
- package/admin/RoutesConfig.js.map +1 -1
- package/admin/components/ContentEntries/BulkActions/ActionDelete.js +2 -1
- package/admin/components/ContentEntries/BulkActions/ActionDelete.js.map +1 -1
- package/admin/components/ContentEntries/BulkActions/ActionDelete.test.d.ts +1 -0
- package/admin/components/ContentEntries/BulkActions/ActionDelete.test.js +125 -0
- package/admin/components/ContentEntries/BulkActions/ActionDelete.test.js.map +1 -0
- package/admin/components/ContentEntries/Filters/RefFieldRenderer.d.ts +2 -0
- package/admin/components/ContentEntries/Filters/RefFieldRenderer.js +85 -0
- package/admin/components/ContentEntries/Filters/RefFieldRenderer.js.map +1 -0
- package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.d.ts +2 -0
- package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.js +34 -0
- package/admin/components/ContentEntries/Table/Actions/DuplicateEntry.js.map +1 -0
- package/admin/components/ContentEntries/Table/Actions/index.d.ts +1 -0
- package/admin/components/ContentEntries/Table/Actions/index.js +1 -0
- package/admin/components/ContentEntries/Table/Cells/CellLive.js +9 -2
- package/admin/components/ContentEntries/Table/Cells/CellLive.js.map +1 -1
- package/admin/components/ContentModelEditor/ContentModelEditor.js +1 -1
- package/admin/components/ContentModelEditor/ContentModelEditor.js.map +1 -1
- package/admin/components/ContentModelEditor/evaluateExpression.d.ts +1 -1
- package/admin/components/ContentModelEditor/evaluateExpression.js +6 -0
- package/admin/components/ContentModelEditor/evaluateExpression.js.map +1 -1
- package/admin/components/ContentModelEditor/operatorOptions.js +12 -0
- package/admin/components/ContentModelEditor/operatorOptions.js.map +1 -1
- package/admin/components/Dialogs/DuplicateEntryConfirmDialog.d.ts +2 -0
- package/admin/components/Dialogs/DuplicateEntryConfirmDialog.js +22 -0
- package/admin/components/Dialogs/DuplicateEntryConfirmDialog.js.map +1 -0
- package/admin/components/Dialogs/EditRevisionNoteDialog.d.ts +2 -0
- package/admin/components/Dialogs/EditRevisionNoteDialog.js +33 -0
- package/admin/components/Dialogs/EditRevisionNoteDialog.js.map +1 -0
- package/admin/components/FieldEditor/Field.js +4 -4
- package/admin/components/FieldEditor/Field.js.map +1 -1
- package/admin/components/ModelFieldProvider/ModelFieldContext.d.ts +1 -0
- package/admin/config/contentEntries/editor/ContentEntryEditorConfig.d.ts +1 -1
- package/admin/graphql/contentModels.d.ts +2 -2
- package/admin/graphql/contentModels.js +1 -0
- package/admin/graphql/contentModels.js.map +1 -1
- package/admin/hooks/usePermission.js +6 -34
- package/admin/hooks/usePermission.js.map +1 -1
- package/admin/plugins/editor/defaultBar/Name/Name.d.ts +0 -5
- package/admin/plugins/editor/defaultBar/Name/Name.js +0 -2
- package/admin/plugins/editor/defaultBar/Name/Name.js.map +1 -1
- package/admin/plugins/editor/formSettings/components/GeneralSettings.js +0 -16
- package/admin/plugins/editor/formSettings/components/GeneralSettings.js.map +1 -1
- package/domain/permissions/checkCmsPermission.d.ts +14 -0
- package/domain/permissions/checkCmsPermission.js +20 -0
- package/domain/permissions/checkCmsPermission.js.map +1 -0
- package/domain/permissions/hasAccessForModel.d.ts +11 -0
- package/domain/permissions/hasAccessForModel.js +20 -0
- package/domain/permissions/hasAccessForModel.js.map +1 -0
- package/domain/permissions/isModelAllowed.d.ts +2 -0
- package/domain/permissions/isModelAllowed.js +11 -0
- package/domain/permissions/isModelAllowed.js.map +1 -0
- package/features/contentEntry/CmsEntryError.d.ts +10 -0
- package/features/contentEntry/CmsEntryError.js +11 -0
- package/features/contentEntry/CmsEntryError.js.map +1 -0
- package/features/contentEntry/bulkAction/BulkActionGateway.js +6 -1
- package/features/contentEntry/bulkAction/BulkActionGateway.js.map +1 -1
- package/features/contentEntry/bulkAction/BulkActionGateway.test.d.ts +1 -0
- package/features/contentEntry/bulkAction/BulkActionGateway.test.js +134 -0
- package/features/contentEntry/bulkAction/BulkActionGateway.test.js.map +1 -0
- package/features/contentEntry/createEntry/CreateEntryGateway.d.ts +0 -1
- package/features/contentEntry/createEntry/CreateEntryGateway.js +3 -10
- package/features/contentEntry/createEntry/CreateEntryGateway.js.map +1 -1
- package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.d.ts +3 -1
- package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js +8 -3
- package/features/contentEntry/createRevisionFrom/CreateRevisionFromGateway.js.map +1 -1
- package/features/contentEntry/deleteEntry/DeleteEntryGateway.js +6 -1
- package/features/contentEntry/deleteEntry/DeleteEntryGateway.js.map +1 -1
- package/features/contentEntry/deleteEntry/DeleteEntryGateway.test.d.ts +1 -0
- package/features/contentEntry/deleteEntry/DeleteEntryGateway.test.js +116 -0
- package/features/contentEntry/deleteEntry/DeleteEntryGateway.test.js.map +1 -0
- package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.js +6 -1
- package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.js.map +1 -1
- package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.test.d.ts +1 -0
- package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.test.js +112 -0
- package/features/contentEntry/deleteEntryRevision/DeleteEntryRevisionGateway.test.js.map +1 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.d.ts +14 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.js +43 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryGateway.js.map +1 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.d.ts +15 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.js +34 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryRepository.js.map +1 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.d.ts +11 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.js +18 -0
- package/features/contentEntry/duplicateEntry/DuplicateEntryUseCase.js.map +1 -0
- package/features/contentEntry/duplicateEntry/abstractions.d.ts +26 -0
- package/features/contentEntry/duplicateEntry/abstractions.js +7 -0
- package/features/contentEntry/duplicateEntry/abstractions.js.map +1 -0
- package/features/contentEntry/duplicateEntry/feature.d.ts +3 -0
- package/features/contentEntry/duplicateEntry/feature.js +21 -0
- package/features/contentEntry/duplicateEntry/feature.js.map +1 -0
- package/features/contentEntry/entryValueGateways.test.d.ts +1 -0
- package/features/contentEntry/entryValueGateways.test.js +106 -0
- package/features/contentEntry/entryValueGateways.test.js.map +1 -0
- package/features/contentEntry/feature.js +4 -2
- package/features/contentEntry/feature.js.map +1 -1
- package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.js +6 -1
- package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.js.map +1 -1
- package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.test.d.ts +1 -0
- package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.test.js +130 -0
- package/features/contentEntry/permanentlyDeleteEntry/PermanentlyDeleteEntryGateway.test.js.map +1 -0
- package/features/contentEntry/referenceTitles/ReferenceTitles.d.ts +18 -0
- package/features/contentEntry/referenceTitles/ReferenceTitles.js +58 -0
- package/features/contentEntry/referenceTitles/ReferenceTitles.js.map +1 -0
- package/features/contentEntry/referenceTitles/ReferenceTitles.test.d.ts +1 -0
- package/features/contentEntry/referenceTitles/ReferenceTitles.test.js +173 -0
- package/features/contentEntry/referenceTitles/ReferenceTitles.test.js.map +1 -0
- package/features/contentEntry/referenceTitles/RememberTitlesDecorators.d.ts +22 -0
- package/features/contentEntry/referenceTitles/RememberTitlesDecorators.js +40 -0
- package/features/contentEntry/referenceTitles/RememberTitlesDecorators.js.map +1 -0
- package/features/contentEntry/referenceTitles/abstractions.d.ts +16 -0
- package/features/contentEntry/referenceTitles/abstractions.js +5 -0
- package/features/contentEntry/referenceTitles/abstractions.js.map +1 -0
- package/features/contentEntry/referenceTitles/feature.d.ts +3 -0
- package/features/contentEntry/referenceTitles/feature.js +20 -0
- package/features/contentEntry/referenceTitles/feature.js.map +1 -0
- package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.d.ts +0 -1
- package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js +3 -10
- package/features/contentEntry/singletonEntry/UpdateSingletonEntryGateway.js.map +1 -1
- package/features/contentEntry/updateEntry/UpdateEntryGateway.d.ts +0 -1
- package/features/contentEntry/updateEntry/UpdateEntryGateway.js +3 -10
- package/features/contentEntry/updateEntry/UpdateEntryGateway.js.map +1 -1
- package/features/contentEntry/valueTransformers/DynamicZoneValueTransformer.js +7 -2
- package/features/contentEntry/valueTransformers/DynamicZoneValueTransformer.js.map +1 -1
- package/features/contentEntry/valueTransformers/EntryDataPreparer.d.ts +9 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.js +8 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.js.map +1 -1
- package/features/contentEntry/valueTransformers/EntryDataPreparer.test.d.ts +1 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js +113 -0
- package/features/contentEntry/valueTransformers/EntryDataPreparer.test.js.map +1 -0
- package/features/contentEntry/valueTransformers/ObjectValueTransformer.js +16 -2
- package/features/contentEntry/valueTransformers/ObjectValueTransformer.js.map +1 -1
- package/features/contentEntry/valueTransformers/entryValueFixtures.d.ts +146 -0
- package/features/contentEntry/valueTransformers/entryValueFixtures.js +171 -0
- package/features/contentEntry/valueTransformers/entryValueFixtures.js.map +1 -0
- package/features/formModel/CmsFormModelBuilder.d.ts +9 -1
- package/features/formModel/CmsFormModelBuilder.js +26 -15
- package/features/formModel/CmsFormModelBuilder.js.map +1 -1
- package/features/formModel/CmsFormModelBuilder.test.d.ts +1 -0
- package/features/formModel/CmsFormModelBuilder.test.js +465 -0
- package/features/formModel/CmsFormModelBuilder.test.js.map +1 -0
- package/features/formModel/CmsLayoutMapper.d.ts +8 -1
- package/features/formModel/CmsLayoutMapper.js +27 -5
- package/features/formModel/CmsLayoutMapper.js.map +1 -1
- package/features/formModel/CmsRefFieldValueFormatter.d.ts +12 -0
- package/features/formModel/CmsRefFieldValueFormatter.js +29 -0
- package/features/formModel/CmsRefFieldValueFormatter.js.map +1 -0
- package/features/formModel/CmsValidationMapper.d.ts +9 -0
- package/features/formModel/CmsValidationMapper.js +25 -19
- package/features/formModel/CmsValidationMapper.js.map +1 -1
- package/features/formModel/feature.js +2 -2
- package/features/formModel/feature.js.map +1 -1
- package/features/formModel/mappers/DateTimeFieldMapper.js +3 -0
- package/features/formModel/mappers/DateTimeFieldMapper.js.map +1 -1
- package/features/formModel/mappers/DynamicZoneFieldMapper.js +8 -2
- package/features/formModel/mappers/DynamicZoneFieldMapper.js.map +1 -1
- package/features/formModel/mappers/ObjectFieldMapper.js +12 -5
- package/features/formModel/mappers/ObjectFieldMapper.js.map +1 -1
- package/features/formModel/mappers/applyFieldProps.js +2 -1
- package/features/formModel/mappers/applyFieldProps.js.map +1 -1
- package/features/formModel/mappers/applyFieldProps.test.d.ts +1 -0
- package/features/formModel/mappers/applyFieldProps.test.js +59 -0
- package/features/formModel/mappers/applyFieldProps.test.js.map +1 -0
- package/features/model/deleteModel/DeleteModelGateway.js +6 -1
- package/features/model/deleteModel/DeleteModelGateway.js.map +1 -1
- package/features/model/deleteModel/DeleteModelGateway.test.d.ts +1 -0
- package/features/model/deleteModel/DeleteModelGateway.test.js +71 -0
- package/features/model/deleteModel/DeleteModelGateway.test.js.map +1 -0
- package/features/model/exportModels/ExportModelsGateway.d.ts +1 -1
- package/features/model/exportModels/ExportModelsGateway.js.map +1 -1
- package/features/model/exportModels/ExportModelsUseCase.js +7 -1
- package/features/model/exportModels/ExportModelsUseCase.js.map +1 -1
- package/features/model/exportModels/abstractions.d.ts +8 -2
- package/features/model/exportModels/abstractions.js.map +1 -1
- package/package.json +30 -28
- package/presentation/cloneContentModel/CloneContentModelPresenter.d.ts +1 -0
- package/presentation/cloneContentModel/CloneContentModelPresenter.js +8 -6
- package/presentation/cloneContentModel/CloneContentModelPresenter.js.map +1 -1
- package/presentation/contentEntries/bulkActions/BulkDeletePresenter.d.ts +1 -1
- package/presentation/contentEntries/bulkActions/BulkDeletePresenter.js +6 -1
- package/presentation/contentEntries/bulkActions/BulkDeletePresenter.js.map +1 -1
- package/presentation/contentEntries/bulkActions/BulkDeletePresenter.test.d.ts +1 -0
- package/presentation/contentEntries/bulkActions/BulkDeletePresenter.test.js +124 -0
- package/presentation/contentEntries/bulkActions/BulkDeletePresenter.test.js.map +1 -0
- package/presentation/contentEntries/bulkActions/abstractions.d.ts +1 -1
- package/presentation/contentEntries/bulkActions/abstractions.js.map +1 -1
- package/presentation/contentEntries/form/ContentEntryFormPresenter.d.ts +2 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.deleteEntry.test.d.ts +1 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.deleteEntry.test.js +107 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.deleteEntry.test.js.map +1 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.js +47 -30
- package/presentation/contentEntries/form/ContentEntryFormPresenter.js.map +1 -1
- package/presentation/contentEntries/form/ContentEntryFormPresenter.test.d.ts +1 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.test.js +244 -0
- package/presentation/contentEntries/form/ContentEntryFormPresenter.test.js.map +1 -0
- package/presentation/contentEntries/form/abstractions.d.ts +1 -0
- package/presentation/contentEntries/form/abstractions.js.map +1 -1
- package/presentation/contentEntries/form/getFieldBuilders.test.js +4 -2
- package/presentation/contentEntries/form/getFieldBuilders.test.js.map +1 -1
- package/presentation/contentEntries/form/toFormErrors.d.ts +7 -0
- package/presentation/contentEntries/form/toFormErrors.js +49 -0
- package/presentation/contentEntries/form/toFormErrors.js.map +1 -0
- package/presentation/contentEntries/form/toFormErrors.test.d.ts +1 -0
- package/presentation/contentEntries/form/toFormErrors.test.js +175 -0
- package/presentation/contentEntries/form/toFormErrors.test.js.map +1 -0
- package/presentation/contentEntries/list/ContentEntriesDataSource.d.ts +5 -0
- package/presentation/contentEntries/list/ContentEntriesDataSource.js +16 -4
- package/presentation/contentEntries/list/ContentEntriesDataSource.js.map +1 -1
- package/presentation/contentEntries/list/ContentEntriesPresenter.d.ts +6 -2
- package/presentation/contentEntries/list/ContentEntriesPresenter.js +27 -2
- package/presentation/contentEntries/list/ContentEntriesPresenter.js.map +1 -1
- package/presentation/contentEntries/list/ContentEntriesPresenter.test.js +130 -5
- package/presentation/contentEntries/list/ContentEntriesPresenter.test.js.map +1 -1
- package/presentation/contentEntries/list/abstractions.d.ts +12 -0
- package/presentation/contentEntries/list/abstractions.js.map +1 -1
- package/presentation/contentEntries/preview/ComponentDiscoveryIframe.d.ts +3 -2
- package/presentation/contentEntries/preview/ComponentDiscoveryIframe.js +2 -2
- package/presentation/contentEntries/preview/ComponentDiscoveryIframe.js.map +1 -1
- package/presentation/contentEntries/preview/LivePreviewPresenter.d.ts +12 -1
- package/presentation/contentEntries/preview/LivePreviewPresenter.js +48 -5
- package/presentation/contentEntries/preview/LivePreviewPresenter.js.map +1 -1
- package/presentation/contentEntries/preview/LivePreviewPresenter.test.d.ts +1 -0
- package/presentation/contentEntries/preview/LivePreviewPresenter.test.js +81 -0
- package/presentation/contentEntries/preview/LivePreviewPresenter.test.js.map +1 -0
- package/presentation/contentEntries/preview/ModelEditorComponentDiscovery.js +8 -5
- package/presentation/contentEntries/preview/ModelEditorComponentDiscovery.js.map +1 -1
- package/presentation/contentEntries/preview/PreviewDecorator.js +30 -10
- package/presentation/contentEntries/preview/PreviewDecorator.js.map +1 -1
- package/presentation/contentEntries/preview/PreviewDomainStatus.d.ts +10 -0
- package/presentation/contentEntries/preview/PreviewDomainStatus.js +19 -0
- package/presentation/contentEntries/preview/PreviewDomainStatus.js.map +1 -0
- package/presentation/contentEntries/preview/PreviewPane.d.ts +12 -3
- package/presentation/contentEntries/preview/PreviewPane.js +82 -46
- package/presentation/contentEntries/preview/PreviewPane.js.map +1 -1
- package/presentation/contentEntries/preview/abstractions.d.ts +8 -0
- package/presentation/contentEntries/preview/abstractions.js.map +1 -1
- package/presentation/contentEntries/preview/resolvePreviewUrl.d.ts +23 -2
- package/presentation/contentEntries/preview/resolvePreviewUrl.js +62 -10
- package/presentation/contentEntries/preview/resolvePreviewUrl.js.map +1 -1
- package/presentation/contentEntries/preview/resolvePreviewUrl.test.d.ts +1 -0
- package/presentation/contentEntries/preview/resolvePreviewUrl.test.js +127 -0
- package/presentation/contentEntries/preview/resolvePreviewUrl.test.js.map +1 -0
- package/presentation/contentEntries/revisionsList/RevisionsListPresenter.d.ts +21 -2
- package/presentation/contentEntries/revisionsList/RevisionsListPresenter.js +143 -6
- package/presentation/contentEntries/revisionsList/RevisionsListPresenter.js.map +1 -1
- package/presentation/contentEntries/revisionsList/RevisionsListPresenter.test.d.ts +1 -0
- package/presentation/contentEntries/revisionsList/RevisionsListPresenter.test.js +384 -0
- package/presentation/contentEntries/revisionsList/RevisionsListPresenter.test.js.map +1 -0
- package/presentation/contentEntries/revisionsList/abstractions.d.ts +16 -0
- package/presentation/contentEntries/revisionsList/abstractions.js.map +1 -1
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.js +9 -4
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.js.map +1 -1
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.d.ts +1 -0
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.js +122 -0
- package/presentation/contentEntries/singleEntry/SingleEntryPresenter.test.js.map +1 -0
- package/presentation/contentEntries/views/ContentEntriesListLayout.js +1 -0
- package/presentation/contentEntries/views/ContentEntriesListLayout.js.map +1 -1
- package/presentation/contentEntries/views/ContentEntriesView.js +2 -0
- package/presentation/contentEntries/views/ContentEntriesView.js.map +1 -1
- package/presentation/contentEntries/views/ContentEntryFormView.js +4 -1
- package/presentation/contentEntries/views/ContentEntryFormView.js.map +1 -1
- package/presentation/contentEntries/views/OlderRevisionAlert.d.ts +4 -0
- package/presentation/contentEntries/views/OlderRevisionAlert.js +43 -0
- package/presentation/contentEntries/views/OlderRevisionAlert.js.map +1 -0
- package/presentation/contentEntries/views/RevisionDrawer.js +4 -0
- package/presentation/contentEntries/views/RevisionDrawer.js.map +1 -1
- package/presentation/contentEntries/views/RevisionListItem.d.ts +3 -3
- package/presentation/contentEntries/views/RevisionListItem.js +82 -14
- package/presentation/contentEntries/views/RevisionListItem.js.map +1 -1
- package/presentation/contentEntries/views/RevisionsList.js +3 -3
- package/presentation/contentEntries/views/RevisionsList.js.map +1 -1
- package/presentation/contentEntries/views/actions/CreateNewRevisionButton.js +11 -0
- package/presentation/contentEntries/views/actions/CreateNewRevisionButton.js.map +1 -1
- package/presentation/contentModels/ContentModelsPresenter.d.ts +5 -5
- package/presentation/contentModels/ContentModelsPresenter.js +1 -1
- package/presentation/contentModels/ContentModelsPresenter.js.map +1 -1
- package/presentation/contentModels/abstractions.d.ts +7 -2
- package/presentation/contentModels/abstractions.js.map +1 -1
- package/presentation/contentModels/components/ContentModelsDataList.js +6 -5
- package/presentation/contentModels/components/ContentModelsDataList.js.map +1 -1
- package/presentation/contentModels/components/fullDelete/FullyDeleteModelDialog.js +8 -3
- package/presentation/contentModels/components/fullDelete/FullyDeleteModelDialog.js.map +1 -1
- package/presentation/contentModels/components/fullDelete/dialog/Content.js +7 -2
- package/presentation/contentModels/components/fullDelete/dialog/Content.js.map +1 -1
- package/presentation/contentModels/components/fullDelete/dialog/Content.test.d.ts +1 -0
- package/presentation/contentModels/components/fullDelete/dialog/Content.test.js +54 -0
- package/presentation/contentModels/components/fullDelete/dialog/Content.test.js.map +1 -0
- package/presentation/contentModels/components/fullDelete/dialog/FullyDeleteModelError.d.ts +25 -0
- package/presentation/contentModels/components/fullDelete/dialog/FullyDeleteModelError.js +9 -0
- package/presentation/contentModels/components/fullDelete/dialog/FullyDeleteModelError.js.map +1 -0
- package/presentation/fieldEditor/groups/AppearanceGroup.js +12 -0
- package/presentation/fieldEditor/groups/AppearanceGroup.js.map +1 -1
- package/presentation/fieldEditor/groups/GeneralGroup.d.ts +5 -5
- package/presentation/fieldEditor/groups/GeneralGroup.js +5 -1
- package/presentation/fieldEditor/groups/GeneralGroup.js.map +1 -1
- package/presentation/fieldEditor/groups/GeneralGroup.test.d.ts +1 -0
- package/presentation/fieldEditor/groups/GeneralGroup.test.js +68 -0
- package/presentation/fieldEditor/groups/GeneralGroup.test.js.map +1 -0
- package/presentation/fieldEditor/groups/ValidationsGroup.d.ts +2 -0
- package/presentation/fieldEditor/groups/ValidationsGroup.js +20 -6
- package/presentation/fieldEditor/groups/ValidationsGroup.js.map +1 -1
- package/presentation/fieldEditor/renderers/CmsValidatorsRenderer.js +2 -2
- package/presentation/fieldEditor/renderers/CmsValidatorsRenderer.js.map +1 -1
- package/presentation/fieldRenderers/feature.js +2 -1
- package/presentation/fieldRenderers/feature.js.map +1 -1
- package/presentation/fieldRenderers/ref/CmsRefInputRenderer.js +1 -0
- package/presentation/fieldRenderers/ref/CmsRefInputRenderer.js.map +1 -1
- package/presentation/fieldRenderers/ref/CmsRefInputsRenderer.js +1 -0
- package/presentation/fieldRenderers/ref/CmsRefInputsRenderer.js.map +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/BaseAutocompletePresenter.d.ts +1 -0
- package/presentation/fieldRenderers/ref/autocomplete/BaseAutocompletePresenter.js +8 -2
- package/presentation/fieldRenderers/ref/autocomplete/BaseAutocompletePresenter.js.map +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.d.ts +1 -0
- package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.js +185 -0
- package/presentation/fieldRenderers/ref/autocomplete/RefAutocompletePresenters.test.js.map +1 -0
- package/presentation/fieldRenderers/ref/autocomplete/multi/RefMultiAutocompletePresenter.js +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/multi/RefMultiAutocompletePresenter.js.map +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/single/RefSingleAutocompletePresenter.js +1 -1
- package/presentation/fieldRenderers/ref/autocomplete/single/RefSingleAutocompletePresenter.js.map +1 -1
- package/presentation/fieldRenderers/ref/components/RefFieldOptions.js +3 -2
- package/presentation/fieldRenderers/ref/components/RefFieldOptions.js.map +1 -1
- package/presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.d.ts +15 -0
- package/presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.js +19 -0
- package/presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.js.map +1 -0
- package/presentation/fieldTypes/renderers/index.d.ts +1 -0
- package/presentation/fieldTypes/renderers/index.js +1 -0
- package/presentation/fieldValidators/abstractions.d.ts +7 -0
- package/presentation/fieldValidators/abstractions.js.map +1 -1
- package/presentation/fieldValidators/validators/DateGteValidator.d.ts +6 -0
- package/presentation/fieldValidators/validators/DateGteValidator.js +17 -25
- package/presentation/fieldValidators/validators/DateGteValidator.js.map +1 -1
- package/presentation/fieldValidators/validators/DateLteValidator.d.ts +6 -0
- package/presentation/fieldValidators/validators/DateLteValidator.js +17 -25
- package/presentation/fieldValidators/validators/DateLteValidator.js.map +1 -1
- package/presentation/fieldValidators/validators/dateLimitSettings.d.ts +20 -0
- package/presentation/fieldValidators/validators/dateLimitSettings.js +124 -0
- package/presentation/fieldValidators/validators/dateLimitSettings.js.map +1 -0
- package/presentation/fieldValidators/validators/dateLimitSettings.test.d.ts +1 -0
- package/presentation/fieldValidators/validators/dateLimitSettings.test.js +111 -0
- package/presentation/fieldValidators/validators/dateLimitSettings.test.js.map +1 -0
- package/presentation/importContentModels/ImportContentModelsPresenter.js +1 -1
- package/presentation/importContentModels/ImportContentModelsPresenter.js.map +1 -1
- package/presentation/importContentModels/components/Model/DataListModelItem.js +3 -3
- package/presentation/importContentModels/components/Model/DataListModelItem.js.map +1 -1
- package/presentation/importContentModels/components/Model/DataListModelItemInfo.js +2 -2
- package/presentation/importContentModels/components/Model/DataListModelItemInfo.js.map +1 -1
- package/presentation/modelGroup/ModelGroupPresenter.js +1 -2
- package/presentation/modelGroup/ModelGroupPresenter.js.map +1 -1
- package/presentation/newContentModel/NewContentModelPresenter.d.ts +1 -0
- package/presentation/newContentModel/NewContentModelPresenter.js +8 -6
- package/presentation/newContentModel/NewContentModelPresenter.js.map +1 -1
- package/utils/normalizeIcon.d.ts +4 -0
- package/utils/normalizeIcon.js +9 -6
- package/utils/normalizeIcon.js.map +1 -1
- package/features/formModel/CmsAccessControlRuleEvaluator.d.ts +0 -9
- package/features/formModel/CmsAccessControlRuleEvaluator.js +0 -16
- package/features/formModel/CmsAccessControlRuleEvaluator.js.map +0 -1
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Container } from "@webiny/di";
|
|
3
|
+
import { FormModelFeature } from "@webiny/app-admin/features/formModel/feature.js";
|
|
4
|
+
import { IdentityContextFeature } from "@webiny/app-admin/features/security/IdentityContext/feature.js";
|
|
5
|
+
import { FormModelFactory } from "@webiny/app-admin/features/formModel/abstractions.js";
|
|
6
|
+
import { CmsFormModelBuilder } from "./abstractions.js";
|
|
7
|
+
import { CmsFormModelFeature } from "./feature.js";
|
|
8
|
+
import { DateTimeInputRenderer } from "../../presentation/fieldTypes/renderers/dateTime/DateTimeInputRenderer.js";
|
|
9
|
+
import { DateTimeInputsRenderer } from "../../presentation/fieldTypes/renderers/dateTime/DateTimeInputsRenderer.js";
|
|
10
|
+
import { BirthdayInputRenderer } from "../../presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.js";
|
|
11
|
+
import { TextInputRenderer } from "../../presentation/fieldTypes/renderers/text/TextInputRenderer.js";
|
|
12
|
+
import { TextInputsRenderer } from "../../presentation/fieldTypes/renderers/text/TextInputsRenderer.js";
|
|
13
|
+
const field = (fieldId, type, list, renderer, extra = {})=>({
|
|
14
|
+
id: fieldId,
|
|
15
|
+
fieldId,
|
|
16
|
+
type,
|
|
17
|
+
label: fieldId,
|
|
18
|
+
tags: [],
|
|
19
|
+
list,
|
|
20
|
+
renderer: {
|
|
21
|
+
name: renderer,
|
|
22
|
+
settings: {}
|
|
23
|
+
},
|
|
24
|
+
validation: [],
|
|
25
|
+
listValidation: [],
|
|
26
|
+
settings: {},
|
|
27
|
+
predefinedValues: {
|
|
28
|
+
enabled: false,
|
|
29
|
+
values: []
|
|
30
|
+
},
|
|
31
|
+
...extra
|
|
32
|
+
});
|
|
33
|
+
function createCmsForm(fields) {
|
|
34
|
+
const container = new Container();
|
|
35
|
+
IdentityContextFeature.register(container);
|
|
36
|
+
FormModelFeature.register(container);
|
|
37
|
+
CmsFormModelFeature.register(container);
|
|
38
|
+
container.register(DateTimeInputRenderer);
|
|
39
|
+
container.register(DateTimeInputsRenderer);
|
|
40
|
+
container.register(BirthdayInputRenderer);
|
|
41
|
+
container.register(TextInputRenderer);
|
|
42
|
+
container.register(TextInputsRenderer);
|
|
43
|
+
const model = {
|
|
44
|
+
modelId: "test",
|
|
45
|
+
fields,
|
|
46
|
+
layout: fields.map((f)=>[
|
|
47
|
+
f.fieldId
|
|
48
|
+
])
|
|
49
|
+
};
|
|
50
|
+
const config = container.resolve(CmsFormModelBuilder).build(model);
|
|
51
|
+
return container.resolve(FormModelFactory).create(config);
|
|
52
|
+
}
|
|
53
|
+
describe("CmsFormModelBuilder renderer cardinality", ()=>{
|
|
54
|
+
it("keeps renderers that match the field's cardinality", ()=>{
|
|
55
|
+
const form = createCmsForm([
|
|
56
|
+
field("single", "datetime", false, "date-time-input"),
|
|
57
|
+
field("many", "datetime", true, "date-time-inputs")
|
|
58
|
+
]);
|
|
59
|
+
expect(form.field("single").vm.renderer).toBe("dateTimeInput");
|
|
60
|
+
expect(form.field("many").vm.renderer).toBe("dateTimeInputs");
|
|
61
|
+
});
|
|
62
|
+
it("falls back to the single-value renderer when a list renderer is set on a non-list field", ()=>{
|
|
63
|
+
const form = createCmsForm([
|
|
64
|
+
field("openTime", "datetime", false, "date-time-inputs"),
|
|
65
|
+
field("name", "text", false, "text-inputs")
|
|
66
|
+
]);
|
|
67
|
+
expect(form.field("openTime").vm.renderer).toBe("dateTimeInput");
|
|
68
|
+
expect(form.field("name").vm.renderer).toBe("textInput");
|
|
69
|
+
});
|
|
70
|
+
it("keeps the list renderer for list datetime fields with a subtype", ()=>{
|
|
71
|
+
const form = createCmsForm([
|
|
72
|
+
"date",
|
|
73
|
+
"time",
|
|
74
|
+
"dateTimeWithTimezone",
|
|
75
|
+
"dateTimeWithoutTimezone"
|
|
76
|
+
].map((type)=>field(type, "datetime", true, "date-time-inputs", {
|
|
77
|
+
settings: {
|
|
78
|
+
type
|
|
79
|
+
}
|
|
80
|
+
})));
|
|
81
|
+
expect(form.field("date").vm.renderer).toBe("dateTimeInputs");
|
|
82
|
+
expect(form.field("time").vm.renderer).toBe("dateTimeInputs");
|
|
83
|
+
expect(form.field("dateTimeWithTimezone").vm.renderer).toBe("dateTimeInputs");
|
|
84
|
+
expect(form.field("dateTimeWithoutTimezone").vm.renderer).toBe("dateTimeInputs");
|
|
85
|
+
});
|
|
86
|
+
it("applies the fallback to fields nested in object lists", ()=>{
|
|
87
|
+
const form = createCmsForm([
|
|
88
|
+
field("holidayHours", "object", true, "objects-accordion", {
|
|
89
|
+
settings: {
|
|
90
|
+
fields: [
|
|
91
|
+
field("openTime", "datetime", false, "date-time-inputs")
|
|
92
|
+
],
|
|
93
|
+
layout: [
|
|
94
|
+
[
|
|
95
|
+
"openTime"
|
|
96
|
+
]
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
]);
|
|
101
|
+
form.setData({
|
|
102
|
+
holidayHours: [
|
|
103
|
+
{
|
|
104
|
+
openTime: "2026-12-24T09:00:00.000Z"
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
const item = form.field("holidayHours").items[0];
|
|
109
|
+
expect(item.children.get("openTime").vm.renderer).toBe("dateTimeInput");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe("CmsFormModelBuilder birthday picker", ()=>{
|
|
113
|
+
it("renders a date-only field with the birthday picker and keeps its value", ()=>{
|
|
114
|
+
const form = createCmsForm([
|
|
115
|
+
field("dob", "datetime", false, "birthday-input", {
|
|
116
|
+
settings: {
|
|
117
|
+
type: "date"
|
|
118
|
+
},
|
|
119
|
+
renderer: {
|
|
120
|
+
name: "birthday-input",
|
|
121
|
+
settings: null
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
]);
|
|
125
|
+
form.setData({
|
|
126
|
+
dob: "1990-02-09"
|
|
127
|
+
});
|
|
128
|
+
const vm = form.field("dob").vm;
|
|
129
|
+
expect(vm.renderer).toBe("birthdayInput");
|
|
130
|
+
expect(vm.rendererSettings).toEqual({
|
|
131
|
+
type: "date"
|
|
132
|
+
});
|
|
133
|
+
expect(vm.value).toBe("1990-02-09");
|
|
134
|
+
});
|
|
135
|
+
it("hands the field's date limits to the birthday picker", ()=>{
|
|
136
|
+
const form = createCmsForm([
|
|
137
|
+
field("dob", "datetime", false, "birthday-input", {
|
|
138
|
+
settings: {
|
|
139
|
+
type: "date"
|
|
140
|
+
},
|
|
141
|
+
validation: [
|
|
142
|
+
{
|
|
143
|
+
name: "dateGte",
|
|
144
|
+
message: "Too old.",
|
|
145
|
+
settings: {
|
|
146
|
+
value: "1950-01-01"
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "dateLte",
|
|
151
|
+
message: "You must be 18 or older.",
|
|
152
|
+
settings: {
|
|
153
|
+
expression: "today-18y",
|
|
154
|
+
type: "date"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
})
|
|
159
|
+
]);
|
|
160
|
+
expect(form.field("dob").vm.rendererSettings).toEqual({
|
|
161
|
+
type: "date",
|
|
162
|
+
dateLimits: {
|
|
163
|
+
gte: [
|
|
164
|
+
"1950-01-01"
|
|
165
|
+
],
|
|
166
|
+
lte: [
|
|
167
|
+
{
|
|
168
|
+
expression: "today-18y"
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
it("falls back to the date/time input when the field is no longer date-only", ()=>{
|
|
175
|
+
const form = createCmsForm([
|
|
176
|
+
field("openTime", "datetime", false, "birthday-input", {
|
|
177
|
+
settings: {
|
|
178
|
+
type: "time"
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
]);
|
|
182
|
+
expect(form.field("openTime").vm.renderer).toBe("dateTimeInput");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("CmsFormModelBuilder validators", ()=>{
|
|
186
|
+
const validate = async (form, name)=>{
|
|
187
|
+
const valid = await form.field(name).validate({
|
|
188
|
+
force: true
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
valid,
|
|
192
|
+
message: form.field(name).vm.validation.message
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
it("checks both date limits on a field that has two", async ()=>{
|
|
196
|
+
const form = createCmsForm([
|
|
197
|
+
field("bornOn", "datetime", false, "date-time-input", {
|
|
198
|
+
settings: {
|
|
199
|
+
type: "date"
|
|
200
|
+
},
|
|
201
|
+
validation: [
|
|
202
|
+
{
|
|
203
|
+
name: "dateGte",
|
|
204
|
+
message: "Too early.",
|
|
205
|
+
settings: {
|
|
206
|
+
value: "1950-01-01"
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "dateLte",
|
|
211
|
+
message: "Too late.",
|
|
212
|
+
settings: {
|
|
213
|
+
value: "2000-12-31"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
})
|
|
218
|
+
]);
|
|
219
|
+
form.setData({
|
|
220
|
+
bornOn: "2005-01-01"
|
|
221
|
+
});
|
|
222
|
+
expect(await validate(form, "bornOn")).toEqual({
|
|
223
|
+
valid: false,
|
|
224
|
+
message: "Too late."
|
|
225
|
+
});
|
|
226
|
+
form.setData({
|
|
227
|
+
bornOn: "1949-01-01"
|
|
228
|
+
});
|
|
229
|
+
expect(await validate(form, "bornOn")).toEqual({
|
|
230
|
+
valid: false,
|
|
231
|
+
message: "Too early."
|
|
232
|
+
});
|
|
233
|
+
form.setData({
|
|
234
|
+
bornOn: "1975-06-15"
|
|
235
|
+
});
|
|
236
|
+
expect((await validate(form, "bornOn")).valid).toBe(true);
|
|
237
|
+
});
|
|
238
|
+
it("works out a relative limit from today", async ()=>{
|
|
239
|
+
const form = createCmsForm([
|
|
240
|
+
field("bornOn", "datetime", false, "birthday-input", {
|
|
241
|
+
settings: {
|
|
242
|
+
type: "date"
|
|
243
|
+
},
|
|
244
|
+
validation: [
|
|
245
|
+
{
|
|
246
|
+
name: "dateLte",
|
|
247
|
+
message: "You must be 18 or older.",
|
|
248
|
+
settings: {
|
|
249
|
+
expression: "today-18y",
|
|
250
|
+
type: "date"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
})
|
|
255
|
+
]);
|
|
256
|
+
form.setData({
|
|
257
|
+
bornOn: `${new Date().getFullYear() - 10}-01-01`
|
|
258
|
+
});
|
|
259
|
+
expect(await validate(form, "bornOn")).toEqual({
|
|
260
|
+
valid: false,
|
|
261
|
+
message: "You must be 18 or older."
|
|
262
|
+
});
|
|
263
|
+
form.setData({
|
|
264
|
+
bornOn: `${new Date().getFullYear() - 30}-01-01`
|
|
265
|
+
});
|
|
266
|
+
expect((await validate(form, "bornOn")).valid).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
it("checks every validator on a text field that has several", async ()=>{
|
|
269
|
+
const form = createCmsForm([
|
|
270
|
+
field("code", "text", false, "text-input", {
|
|
271
|
+
validation: [
|
|
272
|
+
{
|
|
273
|
+
name: "minLength",
|
|
274
|
+
message: "Too short.",
|
|
275
|
+
settings: {
|
|
276
|
+
value: 3
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: "maxLength",
|
|
281
|
+
message: "Too long.",
|
|
282
|
+
settings: {
|
|
283
|
+
value: 5
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "pattern",
|
|
288
|
+
message: "Letters only.",
|
|
289
|
+
settings: {
|
|
290
|
+
regex: "^[a-z]+$"
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
})
|
|
295
|
+
]);
|
|
296
|
+
form.setData({
|
|
297
|
+
code: "ab"
|
|
298
|
+
});
|
|
299
|
+
expect(await validate(form, "code")).toEqual({
|
|
300
|
+
valid: false,
|
|
301
|
+
message: "Too short."
|
|
302
|
+
});
|
|
303
|
+
form.setData({
|
|
304
|
+
code: "abcdef"
|
|
305
|
+
});
|
|
306
|
+
expect(await validate(form, "code")).toEqual({
|
|
307
|
+
valid: false,
|
|
308
|
+
message: "Too long."
|
|
309
|
+
});
|
|
310
|
+
form.setData({
|
|
311
|
+
code: "ab1"
|
|
312
|
+
});
|
|
313
|
+
expect(await validate(form, "code")).toEqual({
|
|
314
|
+
valid: false,
|
|
315
|
+
message: "Letters only."
|
|
316
|
+
});
|
|
317
|
+
form.setData({
|
|
318
|
+
code: "abcd"
|
|
319
|
+
});
|
|
320
|
+
expect((await validate(form, "code")).valid).toBe(true);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
const rowNames = (layout)=>layout.map((row)=>row.fields.map((f)=>f.name));
|
|
324
|
+
describe("CmsFormModelBuilder nested layouts", ()=>{
|
|
325
|
+
it("lays out a single object with the layout stored on the field", ()=>{
|
|
326
|
+
const form = createCmsForm([
|
|
327
|
+
field("address", "object", false, "object-accordion", {
|
|
328
|
+
settings: {
|
|
329
|
+
fields: [
|
|
330
|
+
field("street", "text", false, "text-input"),
|
|
331
|
+
field("city", "text", false, "text-input", {
|
|
332
|
+
id: "c1ty"
|
|
333
|
+
}),
|
|
334
|
+
field("zipCode", "text", false, "text-input")
|
|
335
|
+
],
|
|
336
|
+
layout: [
|
|
337
|
+
[
|
|
338
|
+
"street"
|
|
339
|
+
],
|
|
340
|
+
[
|
|
341
|
+
"c1ty",
|
|
342
|
+
"zipCode"
|
|
343
|
+
]
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
]);
|
|
348
|
+
expect(rowNames(form.field("address").vm.layout)).toEqual([
|
|
349
|
+
[
|
|
350
|
+
"street"
|
|
351
|
+
],
|
|
352
|
+
[
|
|
353
|
+
"city",
|
|
354
|
+
"zipCode"
|
|
355
|
+
]
|
|
356
|
+
]);
|
|
357
|
+
});
|
|
358
|
+
it("lays out every item of an object list", ()=>{
|
|
359
|
+
const form = createCmsForm([
|
|
360
|
+
field("facilityStats", "object", true, "objects-accordion", {
|
|
361
|
+
settings: {
|
|
362
|
+
fields: [
|
|
363
|
+
field("statValue", "text", false, "text-input"),
|
|
364
|
+
field("statLabel", "text", false, "text-input")
|
|
365
|
+
],
|
|
366
|
+
layout: [
|
|
367
|
+
[
|
|
368
|
+
"statValue",
|
|
369
|
+
"statLabel"
|
|
370
|
+
]
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
]);
|
|
375
|
+
form.setData({
|
|
376
|
+
facilityStats: [
|
|
377
|
+
{
|
|
378
|
+
statValue: "1",
|
|
379
|
+
statLabel: "a"
|
|
380
|
+
}
|
|
381
|
+
]
|
|
382
|
+
});
|
|
383
|
+
const vm = form.field("facilityStats").vm;
|
|
384
|
+
expect(rowNames(vm.items[0].layout)).toEqual([
|
|
385
|
+
[
|
|
386
|
+
"statValue",
|
|
387
|
+
"statLabel"
|
|
388
|
+
]
|
|
389
|
+
]);
|
|
390
|
+
});
|
|
391
|
+
it("gives children missing from the stored layout a row of their own", ()=>{
|
|
392
|
+
const form = createCmsForm([
|
|
393
|
+
field("address", "object", false, "object-accordion", {
|
|
394
|
+
settings: {
|
|
395
|
+
fields: [
|
|
396
|
+
field("street", "text", false, "text-input"),
|
|
397
|
+
field("city", "text", false, "text-input"),
|
|
398
|
+
field("state", "text", false, "text-input")
|
|
399
|
+
],
|
|
400
|
+
layout: [
|
|
401
|
+
[
|
|
402
|
+
"street",
|
|
403
|
+
"city"
|
|
404
|
+
]
|
|
405
|
+
]
|
|
406
|
+
}
|
|
407
|
+
})
|
|
408
|
+
]);
|
|
409
|
+
expect(rowNames(form.field("address").vm.layout)).toEqual([
|
|
410
|
+
[
|
|
411
|
+
"street",
|
|
412
|
+
"city"
|
|
413
|
+
],
|
|
414
|
+
[
|
|
415
|
+
"state"
|
|
416
|
+
]
|
|
417
|
+
]);
|
|
418
|
+
});
|
|
419
|
+
it("lays out a dynamic zone template with the template's layout", ()=>{
|
|
420
|
+
const form = createCmsForm([
|
|
421
|
+
field("blocks", "dynamicZone", true, "dynamicZone", {
|
|
422
|
+
settings: {
|
|
423
|
+
templates: [
|
|
424
|
+
{
|
|
425
|
+
id: "hero",
|
|
426
|
+
name: "Hero",
|
|
427
|
+
gqlTypeName: "Hero",
|
|
428
|
+
description: "",
|
|
429
|
+
icon: null,
|
|
430
|
+
fields: [
|
|
431
|
+
field("title", "text", false, "text-input"),
|
|
432
|
+
field("subtitle", "text", false, "text-input")
|
|
433
|
+
],
|
|
434
|
+
layout: [
|
|
435
|
+
[
|
|
436
|
+
"title",
|
|
437
|
+
"subtitle"
|
|
438
|
+
]
|
|
439
|
+
],
|
|
440
|
+
validation: []
|
|
441
|
+
}
|
|
442
|
+
]
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
]);
|
|
446
|
+
form.setData({
|
|
447
|
+
blocks: [
|
|
448
|
+
{
|
|
449
|
+
_templateId: "hero",
|
|
450
|
+
title: "T",
|
|
451
|
+
subtitle: "S"
|
|
452
|
+
}
|
|
453
|
+
]
|
|
454
|
+
});
|
|
455
|
+
const vm = form.field("blocks").vm;
|
|
456
|
+
expect(rowNames(vm.items[0].layout)).toEqual([
|
|
457
|
+
[
|
|
458
|
+
"title",
|
|
459
|
+
"subtitle"
|
|
460
|
+
]
|
|
461
|
+
]);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
//# sourceMappingURL=CmsFormModelBuilder.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/formModel/CmsFormModelBuilder.test.js","sources":["../../../src/features/formModel/CmsFormModelBuilder.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { FormModelFeature } from \"@webiny/app-admin/features/formModel/feature.js\";\nimport { IdentityContextFeature } from \"@webiny/app-admin/features/security/IdentityContext/feature.js\";\nimport { FormModelFactory } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport { CmsFormModelBuilder } from \"~/features/formModel/abstractions.js\";\nimport { CmsFormModelFeature } from \"~/features/formModel/feature.js\";\nimport { DateTimeInputRenderer } from \"~/presentation/fieldTypes/renderers/dateTime/DateTimeInputRenderer.js\";\nimport { DateTimeInputsRenderer } from \"~/presentation/fieldTypes/renderers/dateTime/DateTimeInputsRenderer.js\";\nimport { BirthdayInputRenderer } from \"~/presentation/fieldTypes/renderers/dateTime/BirthdayInputRenderer.js\";\nimport { TextInputRenderer } from \"~/presentation/fieldTypes/renderers/text/TextInputRenderer.js\";\nimport { TextInputsRenderer } from \"~/presentation/fieldTypes/renderers/text/TextInputsRenderer.js\";\n\nconst field = (fieldId: string, type: string, list: boolean, renderer: string, extra = {}) => ({\n id: fieldId,\n fieldId,\n type,\n label: fieldId,\n tags: [],\n list,\n renderer: { name: renderer, settings: {} },\n validation: [],\n listValidation: [],\n settings: {},\n predefinedValues: { enabled: false, values: [] },\n ...extra\n});\n\nfunction createCmsForm(fields: any[]) {\n const container = new Container();\n IdentityContextFeature.register(container);\n FormModelFeature.register(container);\n CmsFormModelFeature.register(container);\n container.register(DateTimeInputRenderer);\n container.register(DateTimeInputsRenderer);\n container.register(BirthdayInputRenderer);\n container.register(TextInputRenderer);\n container.register(TextInputsRenderer);\n\n const model = {\n modelId: \"test\",\n fields,\n layout: fields.map(f => [f.fieldId])\n } as any;\n const config = container.resolve(CmsFormModelBuilder).build(model);\n return container.resolve(FormModelFactory).create(config);\n}\n\ndescribe(\"CmsFormModelBuilder renderer cardinality\", () => {\n it(\"keeps renderers that match the field's cardinality\", () => {\n const form = createCmsForm([\n field(\"single\", \"datetime\", false, \"date-time-input\"),\n field(\"many\", \"datetime\", true, \"date-time-inputs\")\n ]);\n\n expect(form.field(\"single\").vm.renderer).toBe(\"dateTimeInput\");\n expect(form.field(\"many\").vm.renderer).toBe(\"dateTimeInputs\");\n });\n\n it(\"falls back to the single-value renderer when a list renderer is set on a non-list field\", () => {\n const form = createCmsForm([\n field(\"openTime\", \"datetime\", false, \"date-time-inputs\"),\n field(\"name\", \"text\", false, \"text-inputs\")\n ]);\n\n expect(form.field(\"openTime\").vm.renderer).toBe(\"dateTimeInput\");\n expect(form.field(\"name\").vm.renderer).toBe(\"textInput\");\n });\n\n it(\"keeps the list renderer for list datetime fields with a subtype\", () => {\n const form = createCmsForm(\n [\"date\", \"time\", \"dateTimeWithTimezone\", \"dateTimeWithoutTimezone\"].map(type =>\n field(type, \"datetime\", true, \"date-time-inputs\", { settings: { type } })\n )\n );\n\n expect(form.field(\"date\").vm.renderer).toBe(\"dateTimeInputs\");\n expect(form.field(\"time\").vm.renderer).toBe(\"dateTimeInputs\");\n expect(form.field(\"dateTimeWithTimezone\").vm.renderer).toBe(\"dateTimeInputs\");\n expect(form.field(\"dateTimeWithoutTimezone\").vm.renderer).toBe(\"dateTimeInputs\");\n });\n\n it(\"applies the fallback to fields nested in object lists\", () => {\n const form = createCmsForm([\n field(\"holidayHours\", \"object\", true, \"objects-accordion\", {\n settings: {\n fields: [field(\"openTime\", \"datetime\", false, \"date-time-inputs\")],\n layout: [[\"openTime\"]]\n }\n })\n ]);\n\n form.setData({ holidayHours: [{ openTime: \"2026-12-24T09:00:00.000Z\" }] });\n const item = (form.field(\"holidayHours\") as any).items[0];\n\n expect(item.children.get(\"openTime\").vm.renderer).toBe(\"dateTimeInput\");\n });\n});\n\ndescribe(\"CmsFormModelBuilder birthday picker\", () => {\n it(\"renders a date-only field with the birthday picker and keeps its value\", () => {\n const form = createCmsForm([\n field(\"dob\", \"datetime\", false, \"birthday-input\", {\n settings: { type: \"date\" },\n renderer: { name: \"birthday-input\", settings: null }\n })\n ]);\n form.setData({ dob: \"1990-02-09\" });\n\n const vm = form.field(\"dob\").vm as any;\n expect(vm.renderer).toBe(\"birthdayInput\");\n expect(vm.rendererSettings).toEqual({ type: \"date\" });\n expect(vm.value).toBe(\"1990-02-09\");\n });\n\n it(\"hands the field's date limits to the birthday picker\", () => {\n const form = createCmsForm([\n field(\"dob\", \"datetime\", false, \"birthday-input\", {\n settings: { type: \"date\" },\n validation: [\n { name: \"dateGte\", message: \"Too old.\", settings: { value: \"1950-01-01\" } },\n {\n name: \"dateLte\",\n message: \"You must be 18 or older.\",\n settings: { expression: \"today-18y\", type: \"date\" }\n }\n ]\n })\n ]);\n\n expect((form.field(\"dob\").vm as any).rendererSettings).toEqual({\n type: \"date\",\n dateLimits: { gte: [\"1950-01-01\"], lte: [{ expression: \"today-18y\" }] }\n });\n });\n\n it(\"falls back to the date/time input when the field is no longer date-only\", () => {\n const form = createCmsForm([\n field(\"openTime\", \"datetime\", false, \"birthday-input\", { settings: { type: \"time\" } })\n ]);\n\n expect(form.field(\"openTime\").vm.renderer).toBe(\"dateTimeInput\");\n });\n});\n\ndescribe(\"CmsFormModelBuilder validators\", () => {\n const validate = async (form: ReturnType<typeof createCmsForm>, name: string) => {\n const valid = await form.field(name).validate({ force: true });\n return { valid, message: form.field(name).vm.validation.message };\n };\n\n it(\"checks both date limits on a field that has two\", async () => {\n const form = createCmsForm([\n field(\"bornOn\", \"datetime\", false, \"date-time-input\", {\n settings: { type: \"date\" },\n validation: [\n { name: \"dateGte\", message: \"Too early.\", settings: { value: \"1950-01-01\" } },\n { name: \"dateLte\", message: \"Too late.\", settings: { value: \"2000-12-31\" } }\n ]\n })\n ]);\n\n form.setData({ bornOn: \"2005-01-01\" });\n expect(await validate(form, \"bornOn\")).toEqual({ valid: false, message: \"Too late.\" });\n\n form.setData({ bornOn: \"1949-01-01\" });\n expect(await validate(form, \"bornOn\")).toEqual({ valid: false, message: \"Too early.\" });\n\n form.setData({ bornOn: \"1975-06-15\" });\n expect((await validate(form, \"bornOn\")).valid).toBe(true);\n });\n\n it(\"works out a relative limit from today\", async () => {\n const form = createCmsForm([\n field(\"bornOn\", \"datetime\", false, \"birthday-input\", {\n settings: { type: \"date\" },\n validation: [\n {\n name: \"dateLte\",\n message: \"You must be 18 or older.\",\n settings: { expression: \"today-18y\", type: \"date\" }\n }\n ]\n })\n ]);\n\n form.setData({ bornOn: `${new Date().getFullYear() - 10}-01-01` });\n expect(await validate(form, \"bornOn\")).toEqual({\n valid: false,\n message: \"You must be 18 or older.\"\n });\n\n form.setData({ bornOn: `${new Date().getFullYear() - 30}-01-01` });\n expect((await validate(form, \"bornOn\")).valid).toBe(true);\n });\n\n it(\"checks every validator on a text field that has several\", async () => {\n const form = createCmsForm([\n field(\"code\", \"text\", false, \"text-input\", {\n validation: [\n { name: \"minLength\", message: \"Too short.\", settings: { value: 3 } },\n { name: \"maxLength\", message: \"Too long.\", settings: { value: 5 } },\n { name: \"pattern\", message: \"Letters only.\", settings: { regex: \"^[a-z]+$\" } }\n ]\n })\n ]);\n\n form.setData({ code: \"ab\" });\n expect(await validate(form, \"code\")).toEqual({ valid: false, message: \"Too short.\" });\n\n form.setData({ code: \"abcdef\" });\n expect(await validate(form, \"code\")).toEqual({ valid: false, message: \"Too long.\" });\n\n form.setData({ code: \"ab1\" });\n expect(await validate(form, \"code\")).toEqual({ valid: false, message: \"Letters only.\" });\n\n form.setData({ code: \"abcd\" });\n expect((await validate(form, \"code\")).valid).toBe(true);\n });\n});\n\nconst rowNames = (layout: any[]) => layout.map(row => row.fields.map((f: any) => f.name));\n\ndescribe(\"CmsFormModelBuilder nested layouts\", () => {\n it(\"lays out a single object with the layout stored on the field\", () => {\n const form = createCmsForm([\n field(\"address\", \"object\", false, \"object-accordion\", {\n settings: {\n fields: [\n field(\"street\", \"text\", false, \"text-input\"),\n // Fields created in the model editor have an `id` that differs from `fieldId`.\n field(\"city\", \"text\", false, \"text-input\", { id: \"c1ty\" }),\n field(\"zipCode\", \"text\", false, \"text-input\")\n ],\n layout: [[\"street\"], [\"c1ty\", \"zipCode\"]]\n }\n })\n ]);\n\n expect(rowNames((form.field(\"address\").vm as any).layout)).toEqual([\n [\"street\"],\n [\"city\", \"zipCode\"]\n ]);\n });\n\n it(\"lays out every item of an object list\", () => {\n const form = createCmsForm([\n field(\"facilityStats\", \"object\", true, \"objects-accordion\", {\n settings: {\n fields: [\n field(\"statValue\", \"text\", false, \"text-input\"),\n field(\"statLabel\", \"text\", false, \"text-input\")\n ],\n layout: [[\"statValue\", \"statLabel\"]]\n }\n })\n ]);\n\n form.setData({ facilityStats: [{ statValue: \"1\", statLabel: \"a\" }] });\n const vm = form.field(\"facilityStats\").vm as any;\n\n expect(rowNames(vm.items[0].layout)).toEqual([[\"statValue\", \"statLabel\"]]);\n });\n\n it(\"gives children missing from the stored layout a row of their own\", () => {\n const form = createCmsForm([\n field(\"address\", \"object\", false, \"object-accordion\", {\n settings: {\n fields: [\n field(\"street\", \"text\", false, \"text-input\"),\n field(\"city\", \"text\", false, \"text-input\"),\n field(\"state\", \"text\", false, \"text-input\")\n ],\n layout: [[\"street\", \"city\"]]\n }\n })\n ]);\n\n expect(rowNames((form.field(\"address\").vm as any).layout)).toEqual([\n [\"street\", \"city\"],\n [\"state\"]\n ]);\n });\n\n it(\"lays out a dynamic zone template with the template's layout\", () => {\n const form = createCmsForm([\n field(\"blocks\", \"dynamicZone\", true, \"dynamicZone\", {\n settings: {\n templates: [\n {\n id: \"hero\",\n name: \"Hero\",\n gqlTypeName: \"Hero\",\n description: \"\",\n icon: null,\n fields: [\n field(\"title\", \"text\", false, \"text-input\"),\n field(\"subtitle\", \"text\", false, \"text-input\")\n ],\n layout: [[\"title\", \"subtitle\"]],\n validation: []\n }\n ]\n }\n })\n ]);\n\n form.setData({ blocks: [{ _templateId: \"hero\", title: \"T\", subtitle: \"S\" }] });\n const vm = form.field(\"blocks\").vm as any;\n\n expect(rowNames(vm.items[0].layout)).toEqual([[\"title\", \"subtitle\"]]);\n });\n});\n"],"names":["field","fieldId","type","list","renderer","extra","createCmsForm","fields","container","Container","IdentityContextFeature","FormModelFeature","CmsFormModelFeature","DateTimeInputRenderer","DateTimeInputsRenderer","BirthdayInputRenderer","TextInputRenderer","TextInputsRenderer","model","f","config","CmsFormModelBuilder","FormModelFactory","describe","it","form","expect","item","vm","validate","name","valid","Date","rowNames","layout","row"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,QAAQ,CAACC,SAAiBC,MAAcC,MAAeC,UAAkBC,QAAQ,CAAC,CAAC,GAAM;QAC3F,IAAIJ;QACJA;QACAC;QACA,OAAOD;QACP,MAAM,EAAE;QACRE;QACA,UAAU;YAAE,MAAMC;YAAU,UAAU,CAAC;QAAE;QACzC,YAAY,EAAE;QACd,gBAAgB,EAAE;QAClB,UAAU,CAAC;QACX,kBAAkB;YAAE,SAAS;YAAO,QAAQ,EAAE;QAAC;QAC/C,GAAGC,KAAK;IACZ;AAEA,SAASC,cAAcC,MAAa;IAChC,MAAMC,YAAY,IAAIC;IACtBC,uBAAuB,QAAQ,CAACF;IAChCG,iBAAiB,QAAQ,CAACH;IAC1BI,oBAAoB,QAAQ,CAACJ;IAC7BA,UAAU,QAAQ,CAACK;IACnBL,UAAU,QAAQ,CAACM;IACnBN,UAAU,QAAQ,CAACO;IACnBP,UAAU,QAAQ,CAACQ;IACnBR,UAAU,QAAQ,CAACS;IAEnB,MAAMC,QAAQ;QACV,SAAS;QACTX;QACA,QAAQA,OAAO,GAAG,CAACY,CAAAA,IAAK;gBAACA,EAAE,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CAAC,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC;YAAC;gBAAC;gBAAS;aAAW;SAAC;IACxE;AACJ"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { type CmsEditorFieldsLayout } from "../../types.js";
|
|
1
|
+
import { type CmsEditorFieldsLayout, type CmsModelField } from "../../types.js";
|
|
2
2
|
import type { ILayoutBuilder, ILayoutNodeBuilder } from "@webiny/app-admin/features/formModel/abstractions.js";
|
|
3
3
|
export declare function mapCmsLayout(cmsLayout: CmsEditorFieldsLayout, layoutBuilder: ILayoutBuilder, idToFieldId: Map<string, string>): ILayoutNodeBuilder[];
|
|
4
|
+
export declare function collectFieldIds(layout: CmsEditorFieldsLayout, idToFieldId: Map<string, string>): Set<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Maps the layout stored on an object field or a dynamic zone template. Returns `undefined`
|
|
7
|
+
* when there is no layout, so the form falls back to one row per child. Children missing
|
|
8
|
+
* from the layout get a row of their own at the end, so a stale layout can't hide them.
|
|
9
|
+
*/
|
|
10
|
+
export declare function mapCmsNestedLayout(cmsLayout: CmsEditorFieldsLayout | undefined, fields: CmsModelField[]): ((layoutBuilder: ILayoutBuilder) => ILayoutNodeBuilder[]) | undefined;
|
|
@@ -19,6 +19,28 @@ function mapCmsLayout(cmsLayout, layoutBuilder, idToFieldId) {
|
|
|
19
19
|
}
|
|
20
20
|
return nodes;
|
|
21
21
|
}
|
|
22
|
+
function collectFieldIds(layout, idToFieldId) {
|
|
23
|
+
const fieldIds = new Set();
|
|
24
|
+
for (const row of layout)for (const cell of row)if ("string" == typeof cell) {
|
|
25
|
+
const fieldId = idToFieldId.get(cell);
|
|
26
|
+
if (fieldId) fieldIds.add(fieldId);
|
|
27
|
+
} else if (isLayoutField(cell) && "tabs" === cell.type) {
|
|
28
|
+
const tabsField = cell;
|
|
29
|
+
for (const tab of tabsField.tabs)for (const id of collectFieldIds(tab.layout, idToFieldId))fieldIds.add(id);
|
|
30
|
+
}
|
|
31
|
+
return fieldIds;
|
|
32
|
+
}
|
|
33
|
+
function mapCmsNestedLayout(cmsLayout, fields) {
|
|
34
|
+
if (!cmsLayout || 0 === cmsLayout.length) return;
|
|
35
|
+
const idToFieldId = new Map();
|
|
36
|
+
for (const field of fields)idToFieldId.set(field.id, field.fieldId);
|
|
37
|
+
const fieldIdsInLayout = collectFieldIds(cmsLayout, idToFieldId);
|
|
38
|
+
return (layoutBuilder)=>{
|
|
39
|
+
const nodes = mapCmsLayout(cmsLayout, layoutBuilder, idToFieldId);
|
|
40
|
+
for (const field of fields)if (!fieldIdsInLayout.has(field.fieldId)) nodes.push(layoutBuilder.row(field.fieldId));
|
|
41
|
+
return nodes;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
22
44
|
function mapLayoutField(field, layoutBuilder, idToFieldId) {
|
|
23
45
|
switch(field.type){
|
|
24
46
|
case "separator":
|
|
@@ -39,7 +61,7 @@ function mapSeparator(field, layoutBuilder) {
|
|
|
39
61
|
type: r.type,
|
|
40
62
|
target: r.target,
|
|
41
63
|
operator: r.operator,
|
|
42
|
-
value:
|
|
64
|
+
value: r.value ?? null,
|
|
43
65
|
action: r.action
|
|
44
66
|
})));
|
|
45
67
|
return builder;
|
|
@@ -57,7 +79,7 @@ function mapTabs(field, layoutBuilder, idToFieldId) {
|
|
|
57
79
|
type: r.type,
|
|
58
80
|
target: r.target,
|
|
59
81
|
operator: r.operator,
|
|
60
|
-
value:
|
|
82
|
+
value: r.value ?? null,
|
|
61
83
|
action: r.action
|
|
62
84
|
})));
|
|
63
85
|
});
|
|
@@ -65,7 +87,7 @@ function mapTabs(field, layoutBuilder, idToFieldId) {
|
|
|
65
87
|
type: r.type,
|
|
66
88
|
target: r.target,
|
|
67
89
|
operator: r.operator,
|
|
68
|
-
value:
|
|
90
|
+
value: r.value ?? null,
|
|
69
91
|
action: r.action
|
|
70
92
|
})));
|
|
71
93
|
return tabsBuilder;
|
|
@@ -78,11 +100,11 @@ function mapAlert(field, layoutBuilder) {
|
|
|
78
100
|
type: r.type,
|
|
79
101
|
target: r.target,
|
|
80
102
|
operator: r.operator,
|
|
81
|
-
value:
|
|
103
|
+
value: r.value ?? null,
|
|
82
104
|
action: r.action
|
|
83
105
|
})));
|
|
84
106
|
return builder;
|
|
85
107
|
}
|
|
86
|
-
export { mapCmsLayout };
|
|
108
|
+
export { collectFieldIds, mapCmsLayout, mapCmsNestedLayout };
|
|
87
109
|
|
|
88
110
|
//# sourceMappingURL=CmsLayoutMapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/formModel/CmsLayoutMapper.js","sources":["../../../src/features/formModel/CmsLayoutMapper.ts"],"sourcesContent":["import {\n isLayoutField,\n type CmsEditorFieldsLayout,\n type CmsLayoutField,\n type CmsSeparatorLayoutField,\n type CmsTabLayoutField,\n type CmsAlertLayoutField\n} from \"~/types.js\";\nimport type {\n ILayoutBuilder,\n ILayoutNodeBuilder\n} from \"@webiny/app-admin/features/formModel/abstractions.js\";\n\nexport function mapCmsLayout(\n cmsLayout: CmsEditorFieldsLayout,\n layoutBuilder: ILayoutBuilder,\n idToFieldId: Map<string, string>\n): ILayoutNodeBuilder[] {\n const nodes: ILayoutNodeBuilder[] = [];\n\n for (const row of cmsLayout) {\n if (row.length === 0) {\n continue;\n }\n\n const firstCell = row[0];\n\n if (row.length === 1 && isLayoutField(firstCell)) {\n const layoutField = firstCell as CmsLayoutField;\n const node = mapLayoutField(layoutField, layoutBuilder, idToFieldId);\n if (node) {\n nodes.push(node);\n }\n continue;\n }\n\n const fieldIds: string[] = [];\n for (const cell of row) {\n if (typeof cell === \"string\") {\n const fieldId = idToFieldId.get(cell);\n if (fieldId) {\n fieldIds.push(fieldId);\n }\n }\n }\n\n if (fieldIds.length > 0) {\n nodes.push(layoutBuilder.row(...fieldIds));\n }\n }\n\n return nodes;\n}\n\nfunction mapLayoutField(\n field: CmsLayoutField,\n layoutBuilder: ILayoutBuilder,\n idToFieldId: Map<string, string>\n): ILayoutNodeBuilder | null {\n switch (field.type) {\n case \"separator\":\n return mapSeparator(field as CmsSeparatorLayoutField, layoutBuilder);\n\n case \"tabs\":\n return mapTabs(field as CmsTabLayoutField, layoutBuilder, idToFieldId);\n\n case \"alert\":\n return mapAlert(field as CmsAlertLayoutField, layoutBuilder);\n\n default:\n return null;\n }\n}\n\nfunction mapSeparator(\n field: CmsSeparatorLayoutField,\n layoutBuilder: ILayoutBuilder\n): ILayoutNodeBuilder {\n const builder = layoutBuilder.separator();\n if (field.label) {\n builder.title(field.label);\n }\n if (field.description) {\n builder.description(field.description);\n }\n if (field.rules) {\n builder.rules(\n field.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value != null ? String(r.value) : null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n return builder;\n}\n\nfunction mapTabs(\n field: CmsTabLayoutField,\n layoutBuilder: ILayoutBuilder,\n idToFieldId: Map<string, string>\n): ILayoutNodeBuilder {\n const tabsBuilder = layoutBuilder.tabs(field.id);\n\n for (const tab of field.tabs) {\n tabsBuilder.tab(tab.id, t => {\n t.label(tab.label);\n if (tab.icon) {\n t.icon({ type: \"icon\", name: tab.icon });\n }\n t.layout(l => mapCmsLayout(tab.layout, l, idToFieldId));\n if (tab.rules) {\n t.rules(\n tab.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value != null ? String(r.value) : null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n });\n }\n\n if (field.rules) {\n tabsBuilder.rules(\n field.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value != null ? String(r.value) : null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n\n return tabsBuilder;\n}\n\nfunction mapAlert(field: CmsAlertLayoutField, layoutBuilder: ILayoutBuilder): ILayoutNodeBuilder {\n const builder = layoutBuilder.alert();\n if (field.label) {\n builder.message(field.label);\n }\n if (field.alertType) {\n builder.alertType(field.alertType);\n }\n if (field.rules) {\n builder.rules(\n field.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value != null ? String(r.value) : null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n return builder;\n}\n"],"names":["mapCmsLayout","cmsLayout","layoutBuilder","idToFieldId","nodes","row","firstCell","isLayoutField","layoutField","node","mapLayoutField","fieldIds","cell","fieldId","field","mapSeparator","mapTabs","mapAlert","builder","r","String","tabsBuilder","tab","t","l"],"mappings":";AAaO,SAASA,aACZC,SAAgC,EAChCC,aAA6B,EAC7BC,WAAgC;IAEhC,MAAMC,QAA8B,EAAE;IAEtC,KAAK,MAAMC,OAAOJ,UAAW;QACzB,IAAII,AAAe,MAAfA,IAAI,MAAM,EACV;QAGJ,MAAMC,YAAYD,GAAG,CAAC,EAAE;QAExB,IAAIA,AAAe,MAAfA,IAAI,MAAM,IAAUE,cAAcD,YAAY;YAC9C,MAAME,cAAcF;YACpB,MAAMG,OAAOC,eAAeF,aAAaN,eAAeC;YACxD,IAAIM,MACAL,MAAM,IAAI,CAACK;YAEf;QACJ;QAEA,MAAME,WAAqB,EAAE;QAC7B,KAAK,MAAMC,QAAQP,IACf,IAAI,AAAgB,YAAhB,OAAOO,MAAmB;YAC1B,MAAMC,UAAUV,YAAY,GAAG,CAACS;YAChC,IAAIC,SACAF,SAAS,IAAI,CAACE;QAEtB;QAGJ,IAAIF,SAAS,MAAM,GAAG,GAClBP,MAAM,IAAI,CAACF,cAAc,GAAG,IAAIS;IAExC;IAEA,OAAOP;AACX;AAEA,SAASM,eACLI,KAAqB,EACrBZ,aAA6B,EAC7BC,WAAgC;IAEhC,OAAQW,MAAM,IAAI;QACd,KAAK;YACD,OAAOC,aAAaD,OAAkCZ;QAE1D,KAAK;YACD,OAAOc,QAAQF,OAA4BZ,eAAeC;QAE9D,KAAK;YACD,OAAOc,SAASH,OAA8BZ;QAElD;YACI,OAAO;IACf;AACJ;AAEA,SAASa,aACLD,KAA8B,EAC9BZ,aAA6B;IAE7B,M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CAAAA,IAAM;YAClB,MAAMA,EAAE,IAAI;YACZ,QAAQA,EAAE,MAAM;YAChB,UAAUA,EAAE,QAAQ;YACpB,OAAOA,AAAW,QAAXA,EAAE,KAAK,GAAWC,OAAOD,EAAE,KAAK,IAAI;YAC3C,QAAQA,EAAE,MAAM;QACpB;IAIR,OAAOE;AACX;AAEA,SAASJ,SAASH,KAA0B,EAAEZ,aAA6B;IACvE,MAAMgB,UAAUhB,cAAc,KAAK;IACnC,IAAIY,MAAM,KAAK,EACXI,QAAQ,OAAO,CAACJ,MAAM,KAAK;IAE/B,IAAIA,MAAM,SAAS,EACfI,QAAQ,SAAS,CAACJ,MAAM,SAAS;IAErC,IAAIA,MAAM,KAAK,EACXI,QAAQ,KAAK,CACTJ,MAAM,KAAK,CAAC,GAAG,CAACK,CAAAA,IAAM;YAClB,MAAMA,EAAE,IAAI;YACZ,QAAQA,EAAE,MAAM;YAChB,UAAUA,EAAE,QAAQ;YACpB,OAAOA,AAAW,QAAXA,EAAE,KAAK,GAAWC,OAAOD,EAAE,KAAK,IAAI;YAC3C,QAAQA,EAAE,MAAM;QACpB;IAGR,OAAOD;AACX"}
|
|
1
|
+
{"version":3,"file":"features/formModel/CmsLayoutMapper.js","sources":["../../../src/features/formModel/CmsLayoutMapper.ts"],"sourcesContent":["import {\n isLayoutField,\n type CmsEditorFieldsLayout,\n type CmsLayoutField,\n type CmsModelField,\n type CmsSeparatorLayoutField,\n type CmsTabLayoutField,\n type CmsAlertLayoutField\n} from \"~/types.js\";\nimport type {\n ILayoutBuilder,\n ILayoutNodeBuilder\n} from \"@webiny/app-admin/features/formModel/abstractions.js\";\n\nexport function mapCmsLayout(\n cmsLayout: CmsEditorFieldsLayout,\n layoutBuilder: ILayoutBuilder,\n idToFieldId: Map<string, string>\n): ILayoutNodeBuilder[] {\n const nodes: ILayoutNodeBuilder[] = [];\n\n for (const row of cmsLayout) {\n if (row.length === 0) {\n continue;\n }\n\n const firstCell = row[0];\n\n if (row.length === 1 && isLayoutField(firstCell)) {\n const layoutField = firstCell as CmsLayoutField;\n const node = mapLayoutField(layoutField, layoutBuilder, idToFieldId);\n if (node) {\n nodes.push(node);\n }\n continue;\n }\n\n const fieldIds: string[] = [];\n for (const cell of row) {\n if (typeof cell === \"string\") {\n const fieldId = idToFieldId.get(cell);\n if (fieldId) {\n fieldIds.push(fieldId);\n }\n }\n }\n\n if (fieldIds.length > 0) {\n nodes.push(layoutBuilder.row(...fieldIds));\n }\n }\n\n return nodes;\n}\n\nexport function collectFieldIds(\n layout: CmsEditorFieldsLayout,\n idToFieldId: Map<string, string>\n): Set<string> {\n const fieldIds = new Set<string>();\n\n for (const row of layout) {\n for (const cell of row) {\n if (typeof cell === \"string\") {\n const fieldId = idToFieldId.get(cell);\n if (fieldId) {\n fieldIds.add(fieldId);\n }\n } else if (isLayoutField(cell) && cell.type === \"tabs\") {\n const tabsField = cell as { tabs: Array<{ layout: CmsEditorFieldsLayout }> };\n for (const tab of tabsField.tabs) {\n for (const id of collectFieldIds(tab.layout, idToFieldId)) {\n fieldIds.add(id);\n }\n }\n }\n }\n }\n\n return fieldIds;\n}\n\n/**\n * Maps the layout stored on an object field or a dynamic zone template. Returns `undefined`\n * when there is no layout, so the form falls back to one row per child. Children missing\n * from the layout get a row of their own at the end, so a stale layout can't hide them.\n */\nexport function mapCmsNestedLayout(\n cmsLayout: CmsEditorFieldsLayout | undefined,\n fields: CmsModelField[]\n): ((layoutBuilder: ILayoutBuilder) => ILayoutNodeBuilder[]) | undefined {\n if (!cmsLayout || cmsLayout.length === 0) {\n return undefined;\n }\n\n const idToFieldId = new Map<string, string>();\n for (const field of fields) {\n idToFieldId.set(field.id, field.fieldId);\n }\n\n const fieldIdsInLayout = collectFieldIds(cmsLayout, idToFieldId);\n\n return layoutBuilder => {\n const nodes = mapCmsLayout(cmsLayout, layoutBuilder, idToFieldId);\n for (const field of fields) {\n if (!fieldIdsInLayout.has(field.fieldId)) {\n nodes.push(layoutBuilder.row(field.fieldId));\n }\n }\n return nodes;\n };\n}\n\nfunction mapLayoutField(\n field: CmsLayoutField,\n layoutBuilder: ILayoutBuilder,\n idToFieldId: Map<string, string>\n): ILayoutNodeBuilder | null {\n switch (field.type) {\n case \"separator\":\n return mapSeparator(field as CmsSeparatorLayoutField, layoutBuilder);\n\n case \"tabs\":\n return mapTabs(field as CmsTabLayoutField, layoutBuilder, idToFieldId);\n\n case \"alert\":\n return mapAlert(field as CmsAlertLayoutField, layoutBuilder);\n\n default:\n return null;\n }\n}\n\nfunction mapSeparator(\n field: CmsSeparatorLayoutField,\n layoutBuilder: ILayoutBuilder\n): ILayoutNodeBuilder {\n const builder = layoutBuilder.separator();\n if (field.label) {\n builder.title(field.label);\n }\n if (field.description) {\n builder.description(field.description);\n }\n if (field.rules) {\n builder.rules(\n field.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value ?? null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n return builder;\n}\n\nfunction mapTabs(\n field: CmsTabLayoutField,\n layoutBuilder: ILayoutBuilder,\n idToFieldId: Map<string, string>\n): ILayoutNodeBuilder {\n const tabsBuilder = layoutBuilder.tabs(field.id);\n\n for (const tab of field.tabs) {\n tabsBuilder.tab(tab.id, t => {\n t.label(tab.label);\n if (tab.icon) {\n t.icon({ type: \"icon\", name: tab.icon });\n }\n t.layout(l => mapCmsLayout(tab.layout, l, idToFieldId));\n if (tab.rules) {\n t.rules(\n tab.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value ?? null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n });\n }\n\n if (field.rules) {\n tabsBuilder.rules(\n field.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value ?? null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n\n return tabsBuilder;\n}\n\nfunction mapAlert(field: CmsAlertLayoutField, layoutBuilder: ILayoutBuilder): ILayoutNodeBuilder {\n const builder = layoutBuilder.alert();\n if (field.label) {\n builder.message(field.label);\n }\n if (field.alertType) {\n builder.alertType(field.alertType);\n }\n if (field.rules) {\n builder.rules(\n field.rules.map(r => ({\n type: r.type,\n target: r.target,\n operator: r.operator,\n value: r.value ?? null,\n action: r.action as \"hide\" | \"disable\"\n }))\n );\n }\n return builder;\n}\n"],"names":["mapCmsLayout","cmsLayout","layoutBuilder","idToFieldId","nodes","row","firstCell","isLayoutField","layoutField","node","mapLayoutField","fieldIds","cell","fieldId","collectFieldIds","layout","Set","tabsField","tab","id","mapCmsNestedLayout","fields","Map","field","fieldIdsInLayout","mapSeparator","mapTabs","mapAlert","builder","r","tabsBuilder","t","l"],"mappings":";AAcO,SAASA,aACZC,SAAgC,EAChCC,aAA6B,EAC7BC,WAAgC;IAEhC,MAAMC,QAA8B,EAAE;IAEtC,KAAK,MAAMC,OAAOJ,UAAW;QACzB,IAAII,AAAe,MAAfA,IAAI,MAAM,EACV;QAGJ,MAAMC,YAAYD,GAAG,CAAC,EAAE;QAExB,IAAIA,AAAe,MAAfA,IAAI,MAAM,IAAUE,cAAcD,YAAY;YAC9C,MAAME,cAAcF;YACpB,MAAMG,OAAOC,eAAeF,aAAaN,eAAeC;YACxD,IAAIM,MACAL,MAAM,IAAI,CAACK;YAEf;QACJ;QAEA,MAAME,WAAqB,EAAE;QAC7B,KAAK,MAAMC,QAAQP,IACf,IAAI,AAAgB,YAAhB,OAAOO,MAAmB;YAC1B,MAAMC,UAAUV,YAAY,GAAG,CAACS;YAChC,IAAIC,SACAF,SAAS,IAAI,CAACE;QAEtB;QAGJ,IAAIF,SAAS,MAAM,GAAG,GAClBP,MAAM,IAAI,CAACF,cAAc,GAAG,IAAIS;IAExC;IAEA,OAAOP;AACX;AAEO,SAASU,gBACZC,MAA6B,EAC7BZ,WAAgC;IAEhC,MAAMQ,WAAW,IAAIK;IAErB,KAAK,MAAMX,OAAOU,OACd,KAAK,MAAMH,QAAQP,IACf,IAAI,AAAgB,YAAhB,OAAOO,MAAmB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AU1B,cAAc,KAAK;IACnC,IAAIqB,MAAM,KAAK,EACXK,QAAQ,OAAO,CAACL,MAAM,KAAK;IAE/B,IAAIA,MAAM,SAAS,EACfK,QAAQ,SAAS,CAACL,MAAM,SAAS;IAErC,IAAIA,MAAM,KAAK,EACXK,QAAQ,KAAK,CACTL,MAAM,KAAK,CAAC,GAAG,CAACM,CAAAA,IAAM;YAClB,MAAMA,EAAE,IAAI;YACZ,QAAQA,EAAE,MAAM;YAChB,UAAUA,EAAE,QAAQ;YACpB,OAAOA,EAAE,KAAK,IAAI;YAClB,QAAQA,EAAE,MAAM;QACpB;IAGR,OAAOD;AACX"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FieldValueFormatter, type IFieldVM } from "@webiny/app-admin/features/formModel/abstractions.js";
|
|
2
|
+
import { ReferenceTitles } from "../../features/contentEntry/referenceTitles/abstractions.js";
|
|
3
|
+
declare class CmsRefFieldValueFormatterImpl implements FieldValueFormatter.Interface {
|
|
4
|
+
private titles;
|
|
5
|
+
readonly type = "ref";
|
|
6
|
+
constructor(titles: ReferenceTitles.Interface);
|
|
7
|
+
format(field: IFieldVM): string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare const CmsRefFieldValueFormatter: typeof CmsRefFieldValueFormatterImpl & {
|
|
10
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/app-admin/features/formModel").IFieldValueFormatter>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|