@plone/volto 19.0.0-alpha.2 → 19.0.0-alpha.20
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/.eslintignore +1 -0
- package/.eslintrc +37 -3
- package/CHANGELOG.md +338 -1
- package/README.md +20 -16
- package/babel.js +1 -3
- package/cypress/docker/prefixed-rules.yml +26 -0
- package/cypress/docker/prefixed.yml +24 -0
- package/cypress/support/commands.js +12 -6
- package/cypress/support/guillotina.js +1 -0
- package/cypress.config.js +1 -0
- package/global-test-setup.js +1 -2
- package/locales/af.json +1 -0
- package/locales/ar.json +1 -0
- package/locales/bg.json +1 -0
- package/locales/bn.json +1 -0
- package/locales/ca/LC_MESSAGES/volto.po +124 -17
- package/locales/ca.json +1 -1
- package/locales/cs.json +1 -0
- package/locales/cy.json +1 -0
- package/locales/da.json +1 -0
- package/locales/de/LC_MESSAGES/volto.po +135 -28
- package/locales/de.json +1 -1
- package/locales/el.json +1 -0
- package/locales/en/LC_MESSAGES/volto.po +125 -18
- package/locales/en.json +1 -1
- package/locales/en_AU.json +1 -0
- package/locales/en_GB.json +1 -0
- package/locales/eo.json +1 -0
- package/locales/es/LC_MESSAGES/volto.po +125 -18
- package/locales/es.json +1 -1
- package/locales/et.json +1 -0
- package/locales/eu/LC_MESSAGES/volto.po +124 -17
- package/locales/eu.json +1 -1
- package/locales/fa.json +1 -0
- package/locales/fi/LC_MESSAGES/volto.po +124 -17
- package/locales/fi.json +1 -1
- package/locales/fr/LC_MESSAGES/volto.po +125 -18
- package/locales/fr.json +1 -1
- package/locales/fu.json +1 -0
- package/locales/gl.json +1 -0
- package/locales/he.json +1 -0
- package/locales/hi/LC_MESSAGES/volto.po +128 -21
- package/locales/hi.json +1 -1
- package/locales/hr.json +1 -0
- package/locales/hu.json +1 -0
- package/locales/hy.json +1 -0
- package/locales/id.json +1 -0
- package/locales/it/LC_MESSAGES/volto.po +129 -22
- package/locales/it.json +1 -1
- package/locales/ja/LC_MESSAGES/volto.po +124 -17
- package/locales/ja.json +1 -1
- package/locales/ka.json +1 -0
- package/locales/kn.json +1 -0
- package/locales/ko.json +1 -0
- package/locales/lt.json +1 -0
- package/locales/lv.json +1 -0
- package/locales/mi.json +1 -0
- package/locales/mk.json +1 -0
- package/locales/my.json +1 -0
- package/locales/nb_NO.json +1 -0
- package/locales/nl/LC_MESSAGES/volto.po +128 -21
- package/locales/nl.json +1 -1
- package/locales/nn.json +1 -0
- package/locales/pl.json +1 -0
- package/locales/pt/LC_MESSAGES/volto.po +124 -17
- package/locales/pt.json +1 -1
- package/locales/pt_BR/LC_MESSAGES/volto.po +147 -40
- package/locales/pt_BR.json +1 -1
- package/locales/rm.json +1 -0
- package/locales/ro/LC_MESSAGES/volto.po +128 -21
- package/locales/ro.json +1 -1
- package/locales/ru/LC_MESSAGES/volto.po +128 -21
- package/locales/ru.json +1 -1
- package/locales/sk.json +1 -0
- package/locales/sl.json +1 -0
- package/locales/sm.json +1 -0
- package/locales/sq.json +1 -0
- package/locales/sr.json +1 -0
- package/locales/sr@cyrl.json +1 -0
- package/locales/sr@latn.json +1 -0
- package/locales/sv.json +1 -1
- package/locales/ta.json +1 -0
- package/locales/te.json +1 -0
- package/locales/th.json +1 -0
- package/locales/to.json +1 -0
- package/locales/tr.json +1 -0
- package/locales/uk.json +1 -0
- package/locales/vi.json +1 -0
- package/locales/volto.pot +125 -18
- package/locales/zh_CN/LC_MESSAGES/volto.po +124 -17
- package/locales/zh_CN.json +1 -1
- package/locales/zh_Hant.json +1 -0
- package/locales/zh_Hant_HK.json +1 -0
- package/package.json +43 -100
- package/razzle.config.js +21 -21
- package/src/actions/content/content.js +0 -1
- package/src/actions/controlpanels/controlpanels.js +13 -7
- package/src/actions/controlpanels/controlpanels.test.js +11 -5
- package/src/actions/users/users.js +2 -2
- package/src/components/manage/Actions/Actions.test.jsx +1 -5
- package/src/components/manage/Add/Add.jsx +5 -6
- package/src/components/manage/BlockChooser/BlockChooser.jsx +1 -0
- package/src/components/manage/Blocks/Block/BlocksForm.test.jsx +1 -5
- package/src/components/manage/Blocks/Block/Edit.jsx +1 -0
- package/src/components/manage/Blocks/Block/EditBlockWrapper.jsx +9 -4
- package/src/components/manage/Blocks/Block/Settings.test.jsx +1 -5
- package/src/components/manage/Blocks/HTML/Edit.test.jsx +1 -5
- package/src/components/manage/Blocks/Image/Edit.jsx +5 -1
- package/src/components/manage/Blocks/Image/ImageSidebar.test.jsx +1 -5
- package/src/components/manage/Blocks/LeadImage/Edit.jsx +2 -2
- package/src/components/manage/Blocks/LeadImage/LeadImageSidebar.jsx +1 -1
- package/src/components/manage/Blocks/LeadImage/LeadImageSidebar.test.jsx +1 -5
- package/src/components/manage/Blocks/Listing/ImageGallery.jsx +6 -4
- package/src/components/manage/Blocks/Maps/Edit.jsx +2 -1
- package/src/components/manage/Blocks/Maps/MapsSidebar.test.jsx +1 -5
- package/src/components/manage/Blocks/Search/SearchBlockView.jsx +21 -4
- package/src/components/manage/Blocks/Search/components/DateRangeFacet.test.jsx +1 -6
- package/src/components/manage/Blocks/Search/components/SelectFacet.test.jsx +1 -6
- package/src/components/manage/Blocks/Teaser/Data.jsx +21 -7
- package/src/components/manage/Blocks/Teaser/DefaultBody.jsx +1 -1
- package/src/components/manage/Blocks/Teaser/schema.js +8 -3
- package/src/components/manage/Blocks/Video/Edit.jsx +2 -1
- package/src/components/manage/Blocks/Video/VideoSidebar.test.jsx +1 -5
- package/src/components/manage/Contents/Contents.jsx +689 -654
- package/src/components/manage/Contents/Contents.test.jsx +8 -5
- package/src/components/manage/Contents/ContentsBreadcrumbs.Multilingual.test.jsx +18 -5
- package/src/components/manage/Contents/ContentsBreadcrumbs.jsx +20 -26
- package/src/components/manage/Contents/ContentsBreadcrumbs.test.jsx +14 -0
- package/src/components/manage/Contents/ContentsDeleteModal.jsx +258 -206
- package/src/components/manage/Contents/ContentsDeleteModal.stories.jsx +26 -8
- package/src/components/manage/Contents/ContentsItem.jsx +10 -2
- package/src/components/manage/Contents/ContentsPropertiesModal.test.jsx +1 -5
- package/src/components/manage/Contents/ContentsRenameModal.test.jsx +1 -5
- package/src/components/manage/Contents/ContentsTagsModal.test.jsx +1 -5
- package/src/components/manage/Contents/ContentsUploadModal.test.jsx +13 -22
- package/src/components/manage/Contents/ContentsWorkflowModal.test.jsx +1 -5
- package/src/components/manage/Contents/DropZoneContent.jsx +323 -0
- package/src/components/manage/Contents/__mocks__/index.tsx +2 -18
- package/src/components/manage/Controlpanels/Aliases.test.jsx +1 -5
- package/src/components/manage/Controlpanels/ContentType.jsx +1 -1
- package/src/components/manage/Controlpanels/ContentType.test.jsx +1 -5
- package/src/components/manage/Controlpanels/Groups/GroupsControlpanel.jsx +3 -2
- package/src/components/manage/Controlpanels/Relations/Relations.jsx +1 -1
- package/src/components/manage/Controlpanels/Rules/AddRule.test.jsx +1 -5
- package/src/components/manage/Controlpanels/Rules/EditRule.test.jsx +1 -5
- package/src/components/manage/Controlpanels/UndoControlpanel.test.jsx +1 -5
- package/src/components/manage/Controlpanels/Users/RenderUsers.jsx +156 -175
- package/src/components/manage/Controlpanels/Users/UsersControlpanel.jsx +575 -630
- package/src/components/manage/Controlpanels/Users/UsersControlpanel.test.jsx +4 -3
- package/src/components/manage/Diff/Diff.test.jsx +1 -6
- package/src/components/manage/Diff/DiffField.test.jsx +1 -6
- package/src/components/manage/Display/Display.test.jsx +2 -11
- package/src/components/manage/Edit/Edit.jsx +2 -3
- package/src/components/manage/Edit/Edit.test.jsx +1 -5
- package/src/components/manage/Form/BlockDataForm.test.jsx +1 -5
- package/src/components/manage/Form/Form.test.jsx +1 -5
- package/src/components/manage/Form/InlineForm.jsx +2 -2
- package/src/components/manage/Form/InlineForm.test.jsx +1 -5
- package/src/components/manage/Form/ModalForm.jsx +12 -10
- package/src/components/manage/Form/ModalForm.test.jsx +27 -5
- package/src/components/manage/Form/__mocks__/index.tsx +9 -27
- package/src/components/manage/Multilingual/CompareLanguages.jsx +2 -5
- package/src/components/manage/Multilingual/CreateTranslation.jsx +8 -8
- package/src/components/manage/Multilingual/ManageTranslations.jsx +4 -2
- package/src/components/manage/Multilingual/ManageTranslations.test.jsx +5 -1
- package/src/components/manage/Multilingual/TranslationObject.jsx +1 -1
- package/src/components/manage/Preferences/ChangePassword.test.jsx +1 -5
- package/src/components/manage/Preferences/PersonalPreferences.test.jsx +1 -17
- package/src/components/manage/Sidebar/ObjectBrowser.jsx +3 -0
- package/src/components/manage/Sidebar/ObjectBrowserBody.jsx +13 -1
- package/src/components/manage/Sidebar/ObjectBrowserNav.jsx +2 -1
- package/src/components/manage/Sidebar/SidebarPortal.test.tsx +42 -0
- package/src/components/manage/Sidebar/SidebarPortal.tsx +48 -0
- package/src/components/manage/TemplateChooser/TemplateChooser.jsx +2 -1
- package/src/components/manage/Toolbar/More.jsx +4 -1
- package/src/components/manage/Toolbar/More.test.jsx +3 -0
- package/src/components/manage/Toolbar/PersonalTools.jsx +2 -1
- package/src/components/manage/Toolbar/Toolbar.jsx +3 -4
- package/src/components/manage/Toolbar/Types.jsx +7 -7
- package/src/components/manage/UniversalLink/UniversalLink.tsx +1 -0
- package/src/components/manage/Widgets/AlignWidget.stories.jsx +9 -0
- package/src/components/manage/Widgets/AlignWidget.test.tsx +95 -0
- package/src/components/manage/Widgets/{AlignWidget.jsx → AlignWidget.tsx} +23 -7
- package/src/components/manage/Widgets/ArrayWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/BlockAlignment.stories.tsx +104 -0
- package/src/components/manage/Widgets/BlockAlignment.test.tsx +104 -0
- package/src/components/manage/Widgets/BlockAlignment.tsx +88 -0
- package/src/components/manage/Widgets/BlockWidth.stories.tsx +69 -0
- package/src/components/manage/Widgets/BlockWidth.test.tsx +62 -0
- package/src/components/manage/Widgets/BlockWidth.tsx +101 -0
- package/src/components/manage/Widgets/ButtonsWidget.stories.jsx +61 -0
- package/src/components/manage/Widgets/ButtonsWidget.test.tsx +138 -0
- package/src/components/manage/Widgets/ButtonsWidget.tsx +176 -0
- package/src/components/manage/Widgets/CheckboxGroupWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/DatetimeWidget.jsx +16 -1
- package/src/components/manage/Widgets/DatetimeWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/FileWidget.jsx +14 -8
- package/src/components/manage/Widgets/FormFieldWrapper.jsx +146 -168
- package/src/components/manage/Widgets/ImageWidget.jsx +171 -38
- package/src/components/manage/Widgets/InternalUrlWidget.jsx +2 -0
- package/src/components/manage/Widgets/ObjectBrowserWidget.jsx +8 -0
- package/src/components/manage/Widgets/ObjectListWidget.test.jsx +2 -11
- package/src/components/manage/Widgets/ObjectWidget.test.jsx +1 -5
- package/src/components/manage/Widgets/QueryWidget.jsx +137 -9
- package/src/components/manage/Widgets/RadioGroupWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/RecurrenceWidget/RecurrenceWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/RegistryImageWidget.test.jsx +3 -2
- package/src/components/manage/Widgets/SchemaWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/SchemaWidgetFieldset.test.jsx +1 -6
- package/src/components/manage/Widgets/SelectAutoComplete.jsx +29 -12
- package/src/components/manage/Widgets/SelectAutoComplete.test.jsx +1 -6
- package/src/components/manage/Widgets/SelectWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/Size.stories.tsx +69 -0
- package/src/components/manage/Widgets/Size.test.tsx +59 -0
- package/src/components/manage/Widgets/Size.tsx +78 -0
- package/src/components/manage/Widgets/TimeWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/TokenWidget.test.jsx +1 -6
- package/src/components/manage/Widgets/UrlWidget.jsx +2 -0
- package/src/components/manage/Widgets/VocabularyTermsWidget.test.jsx +2 -11
- package/src/components/manage/Widgets/__mocks__/index.tsx +33 -51
- package/src/components/manage/Widgets/index.tsx +21 -0
- package/src/components/manage/Workflow/Workflow.test.jsx +2 -11
- package/src/components/theme/AlternateHrefLangs/AlternateHrefLangs.jsx +1 -3
- package/src/components/theme/AlternateHrefLangs/AlternateHrefLangs.test.jsx +0 -4
- package/src/components/theme/App/App.jsx +5 -1
- package/src/components/theme/App/App.test.jsx +1 -0
- package/src/components/theme/Avatar/Avatar.jsx +2 -1
- package/src/components/theme/Comments/CommentEditModal.test.jsx +1 -5
- package/src/components/theme/Comments/Comments.test.jsx +2 -11
- package/src/components/theme/ContactForm/ContactForm.test.jsx +1 -5
- package/src/components/theme/FormattedDate/FormattedDate.stories.jsx +20 -2
- package/src/components/theme/Image/Image.jsx +11 -8
- package/src/components/theme/InjectPloneComponentsCSS/InjectPloneComponentsCSS.tsx +7 -0
- package/src/components/theme/LanguageSelector/{LanguageSelector.test.jsx → LanguageSelector.test.tsx} +6 -6
- package/src/components/theme/LanguageSelector/LanguageSelector.tsx +89 -0
- package/src/components/theme/Logo/Logo.Multilingual.test.jsx +0 -5
- package/src/components/theme/MultilingualRedirector/MultilingualRedirector.jsx +10 -14
- package/src/components/theme/MultilingualRedirector/MultilingualRedirector.test.jsx +3 -5
- package/src/components/theme/Navigation/NavItem.jsx +1 -5
- package/src/components/theme/Navigation/Navigation.Multilingual.test.jsx +0 -5
- package/src/components/theme/NotFound/NotFound.jsx +5 -2
- package/src/components/theme/NotFound/NotFound.test.jsx +3 -0
- package/src/components/theme/PasswordReset/RequestPasswordReset.test.jsx +1 -5
- package/src/components/theme/PreviewImage/PreviewImage.jsx +1 -1
- package/src/components/theme/Register/Register.test.jsx +1 -5
- package/src/components/theme/RequestTimeout/RequestTimeout.jsx +1 -1
- package/src/components/theme/Sitemap/Sitemap.jsx +6 -5
- package/src/components/theme/Sitemap/Sitemap.test.jsx +0 -1
- package/src/components/theme/Unauthorized/Unauthorized.jsx +5 -2
- package/src/components/theme/View/EventDatesInfo.test.jsx +1 -6
- package/src/components/theme/View/EventView.test.jsx +1 -6
- package/src/components/theme/View/FileView.jsx +9 -1
- package/src/components/theme/View/View.jsx +8 -1
- package/src/components/theme/Widgets/ImageWidget.jsx +2 -1
- package/src/config/ControlPanels.js +1 -0
- package/src/config/Widgets.jsx +7 -0
- package/src/config/index.js +18 -25
- package/src/config/server.js +0 -2
- package/src/config/slots.js +19 -0
- package/src/express-middleware/devproxy.js +20 -5
- package/src/helpers/Api/APIResourceWithAuth.js +8 -3
- package/src/helpers/Api/Api.js +7 -4
- package/src/helpers/AsyncConnect/ssr.js +4 -1
- package/src/helpers/Content/Content.js +23 -0
- package/src/helpers/Content/Content.test.js +39 -0
- package/src/helpers/Content/withClientSideContent.jsx +35 -0
- package/src/helpers/Extensions/withBlockSchemaEnhancer.jsx +4 -1
- package/src/helpers/Html/Html.jsx +13 -7
- package/src/helpers/LanguageMap/LanguageMap.js +115 -8
- package/src/helpers/Loadable/__mocks__/Loadable.jsx +7 -22
- package/src/helpers/MessageLabels/MessageLabels.js +5 -0
- package/src/helpers/Sitemap/Sitemap.js +4 -4
- package/src/helpers/Url/Url.js +33 -2
- package/src/helpers/Url/Url.test.js +62 -0
- package/src/hooks/user/useUser.js +1 -1
- package/src/internalChecks.test.ts +11 -0
- package/src/middleware/Api.test.js +4 -0
- package/src/middleware/api.js +82 -28
- package/src/middleware/storeProtectLoadUtils.test.js +3 -3
- package/src/reducers/content/content.js +3 -18
- package/src/reducers/diff/diff.js +5 -1
- package/src/reducers/diff/diff.test.js +60 -4
- package/src/reducers/querystring/querystring.js +8 -1
- package/src/routes.js +4 -2
- package/src/server.jsx +45 -14
- package/src/start-client.jsx +9 -6
- package/src/start-server.js +9 -3
- package/test-addons-loader.js +3 -0
- package/test-setup-config.jsx +0 -2
- package/test-setup-globals.js +30 -2
- package/theme/themes/pastanaga/extras/blocks.less +26 -0
- package/theme/themes/pastanaga/extras/contents.less +80 -5
- package/theme/themes/pastanaga/extras/main.less +17 -2
- package/theme/themes/pastanaga/extras/widgets.less +79 -0
- package/tsconfig.declarations.json +1 -1
- package/tsconfig.json +4 -5
- package/types/components/manage/Blocks/Teaser/schema.d.ts +1 -0
- package/types/components/manage/Contents/DropZoneContent.d.ts +2 -0
- package/types/components/manage/Contents/__mocks__/index.d.ts +2 -2
- package/types/components/manage/Controlpanels/Relations/RelationsMatrix.d.ts +1 -1
- package/types/components/manage/Controlpanels/Users/RenderUsers.d.ts +18 -2
- package/types/components/manage/Controlpanels/Users/UsersControlpanel.d.ts +6 -2
- package/types/components/manage/Controlpanels/index.d.ts +2 -2
- package/types/components/manage/Form/__mocks__/index.d.ts +8 -8
- package/types/components/manage/Multilingual/ManageTranslations.d.ts +1 -1
- package/types/components/manage/Sidebar/ObjectBrowser.d.ts +1 -1
- package/types/components/manage/Sidebar/SidebarPortal.d.ts +7 -15
- package/types/components/manage/Widgets/AlignWidget.d.ts +8 -10
- package/types/components/manage/Widgets/AlignWidget.stories.d.ts +1 -0
- package/types/components/manage/Widgets/BlockAlignment.d.ts +7 -0
- package/types/components/manage/Widgets/BlockAlignment.stories.d.ts +8 -0
- package/types/components/manage/Widgets/BlockWidth.d.ts +7 -0
- package/types/components/manage/Widgets/BlockWidth.stories.d.ts +6 -0
- package/types/components/manage/Widgets/ButtonsWidget.d.ts +48 -1
- package/types/components/manage/Widgets/ButtonsWidget.stories.d.ts +3 -0
- package/types/components/manage/Widgets/FormFieldWrapper.d.ts +28 -5
- package/types/components/manage/Widgets/ImageWidget.d.ts +41 -1
- package/types/components/manage/Widgets/InternalUrlWidget.d.ts +1 -1
- package/types/components/manage/Widgets/ObjectBrowserWidget.d.ts +2 -0
- package/types/components/manage/Widgets/QueryWidget.d.ts +5 -2
- package/types/components/manage/Widgets/RecurrenceWidget/Utils.d.ts +12 -18
- package/types/components/manage/Widgets/Size.d.ts +7 -0
- package/types/components/manage/Widgets/Size.stories.d.ts +6 -0
- package/types/components/manage/Widgets/UrlWidget.d.ts +1 -1
- package/types/components/manage/Widgets/__mocks__/index.d.ts +33 -33
- package/types/components/manage/Widgets/index.d.ts +11 -6
- package/types/components/theme/FormattedDate/FormattedDate.stories.d.ts +1 -1
- package/types/components/theme/InjectPloneComponentsCSS/InjectPloneComponentsCSS.d.ts +3 -0
- package/types/components/theme/LanguageSelector/LanguageSelector.d.ts +3 -10
- package/types/components/theme/Unauthorized/Unauthorized.d.ts +2 -2
- package/types/config/Widgets.d.ts +6 -0
- package/types/config/slots.d.ts +7 -0
- package/types/helpers/Content/Content.d.ts +7 -0
- package/types/helpers/Content/withClientSideContent.d.ts +1 -0
- package/types/helpers/Extensions/withBlockSchemaEnhancer.d.ts +4 -5
- package/types/helpers/Helmet/Helmet.d.ts +1 -1
- package/types/helpers/LanguageMap/LanguageMap.d.ts +428 -4
- package/types/helpers/Loadable/__mocks__/Loadable.d.ts +2 -2
- package/types/helpers/MessageLabels/MessageLabels.d.ts +68 -62
- package/types/helpers/Url/Url.d.ts +14 -0
- package/types/helpers/Url/bulkFlattenToAppURL.d.ts +5 -0
- package/types/middleware/api.d.ts +6 -9
- package/types/reducers/index.d.ts +1 -0
- package/types/start-client.d.ts +0 -1
- package/vitest.config.mjs +4 -4
- package/webpack-plugins/webpack-scss-plugin.js +172 -0
- package/jest-addons-loader.js +0 -3
- package/jest-extender-plugin.js +0 -39
- package/jest-setup-afterenv.js +0 -2
- package/jest-svgsystem-transform.js +0 -10
- package/package-why.json +0 -34
- package/patches/patchit.sh +0 -2
- package/patches/razzle-jest.patch +0 -10
- package/src/actions/content/content.multilingual.test.js +0 -17
- package/src/components/manage/Contents/__mocks__/index.vitest.tsx +0 -5
- package/src/components/manage/Form/__mocks__/index.vitest.tsx +0 -73
- package/src/components/manage/Sidebar/SidebarPortal.jsx +0 -47
- package/src/components/manage/Sidebar/SidebarPortal.test.jsx +0 -26
- package/src/components/manage/Widgets/AlignWidget.test.jsx +0 -59
- package/src/components/manage/Widgets/ButtonsWidget.jsx +0 -41
- package/src/components/manage/Widgets/ButtonsWidget.test.jsx +0 -70
- package/src/components/manage/Widgets/__mocks__/index.vitest.tsx +0 -41
- package/src/components/theme/LanguageSelector/LanguageSelector.jsx +0 -77
- package/src/helpers/Loadable/__mocks__/Loadable.vitest.jsx +0 -39
- package/test-setup-globals-vitest.js +0 -46
- package/theme/themes/pastanaga/extras/utils.less +0 -63
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import BlockWidth from './BlockWidth';
|
|
5
|
+
import type { ButtonsWidgetProps } from './ButtonsWidget';
|
|
6
|
+
import {
|
|
7
|
+
RealStoreWrapper as Wrapper,
|
|
8
|
+
FormUndoWrapper,
|
|
9
|
+
} from '@plone/volto/storybook';
|
|
10
|
+
|
|
11
|
+
const meta: Meta<typeof BlockWidth> = {
|
|
12
|
+
title: 'Edit Widgets/BlockWidth',
|
|
13
|
+
component: BlockWidth,
|
|
14
|
+
decorators: [
|
|
15
|
+
(Story) => (
|
|
16
|
+
<div className="ui segment form attached" style={{ width: '400px' }}>
|
|
17
|
+
<h4>Block width widget</h4>
|
|
18
|
+
<Story />
|
|
19
|
+
</div>
|
|
20
|
+
),
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
|
|
26
|
+
type Story = StoryObj<typeof BlockWidth>;
|
|
27
|
+
|
|
28
|
+
type TemplateParameters = {
|
|
29
|
+
initialValue?: ButtonsWidgetProps['value'];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const Template: StoryFn<typeof BlockWidth> = (args, context) => {
|
|
33
|
+
const { initialValue } =
|
|
34
|
+
(context.parameters as TemplateParameters | undefined) ?? {};
|
|
35
|
+
const { value: _ignoredValue, onChange: argsOnChange, ...restArgs } = args;
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Wrapper location={{ pathname: '/folder2/folder21/doc212' }}>
|
|
39
|
+
<FormUndoWrapper
|
|
40
|
+
initialState={{ value: initialValue ?? _ignoredValue }}
|
|
41
|
+
showControls
|
|
42
|
+
>
|
|
43
|
+
{({ state, onChange }) => (
|
|
44
|
+
<div className="ui segment form attached" style={{ width: '400px' }}>
|
|
45
|
+
<BlockWidth
|
|
46
|
+
{...(restArgs as ButtonsWidgetProps)}
|
|
47
|
+
value={state.value}
|
|
48
|
+
onChange={(id, nextValue) => {
|
|
49
|
+
argsOnChange?.(id, nextValue);
|
|
50
|
+
onChange({ value: nextValue });
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
<pre>Value: {JSON.stringify(state.value, null, 2)}</pre>
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
</FormUndoWrapper>
|
|
57
|
+
</Wrapper>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const DefaultWidth: Story = {
|
|
62
|
+
render: Template,
|
|
63
|
+
args: {
|
|
64
|
+
id: 'blockWidth',
|
|
65
|
+
title: 'Block width',
|
|
66
|
+
block: 'block',
|
|
67
|
+
fieldSet: 'default',
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
3
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
4
|
+
import configureStore from 'redux-mock-store';
|
|
5
|
+
import { Provider } from 'react-intl-redux';
|
|
6
|
+
|
|
7
|
+
import BlockWidth from './BlockWidth';
|
|
8
|
+
import type { ButtonsWidgetProps } from './ButtonsWidget';
|
|
9
|
+
|
|
10
|
+
const mockStore = configureStore();
|
|
11
|
+
|
|
12
|
+
const renderWidget = (props: Partial<ButtonsWidgetProps> = {}) => {
|
|
13
|
+
const onChange = props.onChange ?? vi.fn();
|
|
14
|
+
const widgetProps: ButtonsWidgetProps = {
|
|
15
|
+
id: 'blockWidth',
|
|
16
|
+
title: 'Block width',
|
|
17
|
+
fieldSet: 'default',
|
|
18
|
+
onChange,
|
|
19
|
+
value: undefined,
|
|
20
|
+
default: undefined,
|
|
21
|
+
disabled: false,
|
|
22
|
+
isDisabled: false,
|
|
23
|
+
...props,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
onChange,
|
|
28
|
+
...render(
|
|
29
|
+
<Provider
|
|
30
|
+
store={mockStore({
|
|
31
|
+
intl: {
|
|
32
|
+
locale: 'en',
|
|
33
|
+
messages: {},
|
|
34
|
+
},
|
|
35
|
+
})}
|
|
36
|
+
>
|
|
37
|
+
<BlockWidth {...widgetProps} />
|
|
38
|
+
</Provider>,
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe('BlockWidth', () => {
|
|
44
|
+
it('renders the default action buttons provided by the widget', () => {
|
|
45
|
+
renderWidget();
|
|
46
|
+
|
|
47
|
+
expect(screen.getByRole('radio', { name: 'Narrow' })).toBeInTheDocument();
|
|
48
|
+
expect(screen.getByRole('radio', { name: 'Default' })).toBeInTheDocument();
|
|
49
|
+
expect(screen.getByRole('radio', { name: 'Layout' })).toBeInTheDocument();
|
|
50
|
+
expect(screen.getByRole('radio', { name: 'Full' })).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('emits the correct value for the default actions', () => {
|
|
54
|
+
const { onChange } = renderWidget();
|
|
55
|
+
|
|
56
|
+
fireEvent.click(screen.getByRole('radio', { name: 'Layout' }));
|
|
57
|
+
|
|
58
|
+
expect(onChange).toHaveBeenCalledWith('blockWidth', {
|
|
59
|
+
'--block-width': 'var(--layout-container-width)',
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { defineMessages, useIntl } from 'react-intl';
|
|
3
|
+
import type { IntlShape } from 'react-intl';
|
|
4
|
+
import ButtonsWidget, {
|
|
5
|
+
type ActionInfo,
|
|
6
|
+
type ButtonsWidgetProps,
|
|
7
|
+
} from './ButtonsWidget';
|
|
8
|
+
import imageFitSVG from '@plone/volto/icons/image-fit.svg';
|
|
9
|
+
import imageNarrowSVG from '@plone/volto/icons/image-narrow.svg';
|
|
10
|
+
import imageWideSVG from '@plone/volto/icons/image-wide.svg';
|
|
11
|
+
import imageFullSVG from '@plone/volto/icons/image-full.svg';
|
|
12
|
+
import type { StyleDefinition } from '@plone/types';
|
|
13
|
+
|
|
14
|
+
const messages = defineMessages({
|
|
15
|
+
narrow: {
|
|
16
|
+
id: 'Narrow',
|
|
17
|
+
defaultMessage: 'Narrow',
|
|
18
|
+
},
|
|
19
|
+
default: {
|
|
20
|
+
id: 'Default',
|
|
21
|
+
defaultMessage: 'Default',
|
|
22
|
+
},
|
|
23
|
+
layout: {
|
|
24
|
+
id: 'Layout',
|
|
25
|
+
defaultMessage: 'Layout',
|
|
26
|
+
},
|
|
27
|
+
full: {
|
|
28
|
+
id: 'Full',
|
|
29
|
+
defaultMessage: 'Full',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const defaultActionsInfo = ({
|
|
34
|
+
intl,
|
|
35
|
+
}: {
|
|
36
|
+
intl: IntlShape;
|
|
37
|
+
}): Record<string, ActionInfo> => ({
|
|
38
|
+
narrow: [imageNarrowSVG, intl.formatMessage(messages.narrow)],
|
|
39
|
+
default: [imageFitSVG, intl.formatMessage(messages.default)],
|
|
40
|
+
layout: [imageWideSVG, intl.formatMessage(messages.layout)],
|
|
41
|
+
full: [imageFullSVG, intl.formatMessage(messages.full)],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const DEFAULT_ACTIONS: StyleDefinition[] = [
|
|
45
|
+
{
|
|
46
|
+
style: {
|
|
47
|
+
'--block-width': 'var(--narrow-container-width)',
|
|
48
|
+
},
|
|
49
|
+
name: 'narrow',
|
|
50
|
+
label: 'Narrow',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
style: {
|
|
54
|
+
'--block-width': 'var(--default-container-width)',
|
|
55
|
+
},
|
|
56
|
+
name: 'default',
|
|
57
|
+
label: 'Default',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
style: {
|
|
61
|
+
'--block-width': 'var(--layout-container-width)',
|
|
62
|
+
},
|
|
63
|
+
name: 'layout',
|
|
64
|
+
label: 'Layout',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
style: {
|
|
68
|
+
'--block-width': 'unset',
|
|
69
|
+
},
|
|
70
|
+
name: 'full',
|
|
71
|
+
label: 'Full',
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
const BlockWidthWidget = (props: ButtonsWidgetProps) => {
|
|
76
|
+
const intl = useIntl();
|
|
77
|
+
|
|
78
|
+
const { actions = DEFAULT_ACTIONS, actionsInfoMap, filterActions } = props;
|
|
79
|
+
const filteredActions =
|
|
80
|
+
filterActions && filterActions.length > 0
|
|
81
|
+
? actions.filter((action) => {
|
|
82
|
+
const actionName = typeof action === 'string' ? action : action.name;
|
|
83
|
+
return filterActions.includes(actionName);
|
|
84
|
+
})
|
|
85
|
+
: actions;
|
|
86
|
+
|
|
87
|
+
const actionsInfo = {
|
|
88
|
+
...defaultActionsInfo({ intl }),
|
|
89
|
+
...actionsInfoMap,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<ButtonsWidget
|
|
94
|
+
{...props}
|
|
95
|
+
actions={filteredActions}
|
|
96
|
+
actionsInfoMap={actionsInfo}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default BlockWidthWidget;
|
|
@@ -21,6 +21,67 @@ export const Buttons = WidgetStory.bind({
|
|
|
21
21
|
widget: ButtonsWidget,
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
export const ButtonsWithDefaultValue = WidgetStory.bind({
|
|
25
|
+
props: {
|
|
26
|
+
id: 'buttons-default',
|
|
27
|
+
title: 'Buttons with Default Value',
|
|
28
|
+
default: 'centered',
|
|
29
|
+
actions: ['left', 'right', 'centered'],
|
|
30
|
+
actionsInfoMap: {
|
|
31
|
+
left: [textLeftSVG, 'Text Left'],
|
|
32
|
+
right: [textRightSVG, 'Text Right'],
|
|
33
|
+
centered: [textCenteredSVG, 'Text Centered'],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
widget: ButtonsWidget,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const ButtonsWithStyleDefinitions = WidgetStory.bind({
|
|
40
|
+
props: {
|
|
41
|
+
id: 'buttons-style-definitions',
|
|
42
|
+
title: 'Buttons with Style Definitions',
|
|
43
|
+
actions: [
|
|
44
|
+
{
|
|
45
|
+
name: 'small',
|
|
46
|
+
label: 'Small',
|
|
47
|
+
style: { '--button-size': 'small' },
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'medium',
|
|
51
|
+
label: 'Medium',
|
|
52
|
+
style: { '--button-size': 'medium' },
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'large',
|
|
56
|
+
label: 'Large',
|
|
57
|
+
style: { '--button-size': 'large' },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
actionsInfoMap: {
|
|
61
|
+
small: ['S', 'Small Buttons'],
|
|
62
|
+
medium: ['M', 'Medium Buttons'],
|
|
63
|
+
large: ['L', 'Large Buttons'],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
widget: ButtonsWidget,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const ButtonsFiltered = WidgetStory.bind({
|
|
70
|
+
props: {
|
|
71
|
+
id: 'buttons-filtered',
|
|
72
|
+
title: 'Filtered Buttons',
|
|
73
|
+
actions: ['left', 'right', 'centered', 'justified'],
|
|
74
|
+
filterActions: ['centered', 'justified'],
|
|
75
|
+
actionsInfoMap: {
|
|
76
|
+
left: [textLeftSVG, 'Text Left'],
|
|
77
|
+
right: [textRightSVG, 'Text Right'],
|
|
78
|
+
justified: [textJustifiedSVG, 'Text Justified'],
|
|
79
|
+
centered: [textCenteredSVG, 'Text Centered'],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
widget: ButtonsWidget,
|
|
83
|
+
});
|
|
84
|
+
|
|
24
85
|
export default {
|
|
25
86
|
title: 'Edit Widgets/Buttons',
|
|
26
87
|
component: ButtonsWidget,
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
3
|
+
import { render, fireEvent, screen } from '@testing-library/react';
|
|
4
|
+
import configureStore from 'redux-mock-store';
|
|
5
|
+
import { Provider } from 'react-intl-redux';
|
|
6
|
+
import imageFullSVG from '@plone/volto/icons/image-full.svg';
|
|
7
|
+
import textJustifiedSVG from '@plone/volto/icons/align-justify.svg';
|
|
8
|
+
import textCenteredSVG from '@plone/volto/icons/align-center.svg';
|
|
9
|
+
import textLeftSVG from '@plone/volto/icons/align-left.svg';
|
|
10
|
+
import textRightSVG from '@plone/volto/icons/align-right.svg';
|
|
11
|
+
|
|
12
|
+
import ButtonsWidget from './ButtonsWidget';
|
|
13
|
+
|
|
14
|
+
const mockStore = configureStore();
|
|
15
|
+
|
|
16
|
+
const renderWidget = (ui: React.ReactElement) =>
|
|
17
|
+
render(
|
|
18
|
+
<Provider
|
|
19
|
+
store={mockStore({
|
|
20
|
+
intl: {
|
|
21
|
+
locale: 'en',
|
|
22
|
+
messages: {},
|
|
23
|
+
},
|
|
24
|
+
})}
|
|
25
|
+
>
|
|
26
|
+
{ui}
|
|
27
|
+
</Provider>,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
describe('ButtonsWidget', () => {
|
|
31
|
+
it('renders string-based actions', () => {
|
|
32
|
+
const { asFragment } = renderWidget(
|
|
33
|
+
<ButtonsWidget
|
|
34
|
+
id="align"
|
|
35
|
+
title="Alignment"
|
|
36
|
+
fieldSet="default"
|
|
37
|
+
onChange={() => {}}
|
|
38
|
+
actions={['left', 'right', 'centered', 'justified']}
|
|
39
|
+
actionsInfoMap={{
|
|
40
|
+
left: [textLeftSVG, 'Text Left'],
|
|
41
|
+
right: [textRightSVG, 'Text Right'],
|
|
42
|
+
justified: [textJustifiedSVG, 'Text Justified'],
|
|
43
|
+
centered: [textCenteredSVG, 'Text Centered'],
|
|
44
|
+
}}
|
|
45
|
+
/>,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect(asFragment()).toMatchSnapshot();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('renders actions info provided via props', () => {
|
|
52
|
+
const { asFragment } = renderWidget(
|
|
53
|
+
<ButtonsWidget
|
|
54
|
+
id="align"
|
|
55
|
+
title="Alignment"
|
|
56
|
+
fieldSet="default"
|
|
57
|
+
onChange={() => {}}
|
|
58
|
+
actions={['additional']}
|
|
59
|
+
actionsInfoMap={{
|
|
60
|
+
additional: [imageFullSVG, 'Additional action title'],
|
|
61
|
+
}}
|
|
62
|
+
/>,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(asFragment()).toMatchSnapshot();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('falls back to the action name when no info map entry is present', () => {
|
|
69
|
+
renderWidget(
|
|
70
|
+
<ButtonsWidget
|
|
71
|
+
id="align"
|
|
72
|
+
title="Alignment"
|
|
73
|
+
fieldSet="default"
|
|
74
|
+
onChange={() => {}}
|
|
75
|
+
actions={['missing']}
|
|
76
|
+
/>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(screen.getByRole('radio', { name: 'missing' })).toBeInTheDocument();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('normalizes style definitions when an action is pressed', () => {
|
|
83
|
+
const handleChange = vi.fn();
|
|
84
|
+
|
|
85
|
+
renderWidget(
|
|
86
|
+
<ButtonsWidget
|
|
87
|
+
id="align"
|
|
88
|
+
title="Alignment"
|
|
89
|
+
fieldSet="default"
|
|
90
|
+
onChange={handleChange}
|
|
91
|
+
actions={[
|
|
92
|
+
{
|
|
93
|
+
name: 'wide',
|
|
94
|
+
label: 'Wide',
|
|
95
|
+
style: {
|
|
96
|
+
'--layout-width': 'wide',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
]}
|
|
100
|
+
actionsInfoMap={{
|
|
101
|
+
wide: ['Wide', 'Wide width'],
|
|
102
|
+
}}
|
|
103
|
+
/>,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
fireEvent.click(screen.getByRole('radio', { name: 'Wide width' }));
|
|
107
|
+
|
|
108
|
+
expect(handleChange).toHaveBeenCalledWith('align', {
|
|
109
|
+
'--layout-width': 'wide',
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('selects default value from string names', () => {
|
|
114
|
+
renderWidget(
|
|
115
|
+
<ButtonsWidget
|
|
116
|
+
id="align"
|
|
117
|
+
title="Alignment"
|
|
118
|
+
fieldSet="default"
|
|
119
|
+
onChange={() => {}}
|
|
120
|
+
actions={[
|
|
121
|
+
{
|
|
122
|
+
name: 'justified',
|
|
123
|
+
label: 'Justified',
|
|
124
|
+
style: {
|
|
125
|
+
'--layout-width': 'wide',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
]}
|
|
129
|
+
default="justified"
|
|
130
|
+
actionsInfoMap={{
|
|
131
|
+
justified: [textJustifiedSVG, 'Text Justified'],
|
|
132
|
+
}}
|
|
133
|
+
/>,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect(screen.getByRole('radio', { name: 'Text Justified' })).toBeChecked();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormFieldWrapper from '@plone/volto/components/manage/Widgets/FormFieldWrapper';
|
|
3
|
+
import Icon from '@plone/volto/components/theme/Icon/Icon';
|
|
4
|
+
import { Radio, RadioGroup } from '@plone/components';
|
|
5
|
+
import isEqual from 'lodash/isEqual';
|
|
6
|
+
import type { StyleDefinition } from '@plone/types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A tuple that has an icon in the first element and a i18n string in the second.
|
|
10
|
+
*/
|
|
11
|
+
export type ActionInfo = [React.ReactElement<any>, string] | [string, string];
|
|
12
|
+
|
|
13
|
+
type ActionValue = string | Record<`--${string}`, string>;
|
|
14
|
+
|
|
15
|
+
export type ButtonsWidgetProps = {
|
|
16
|
+
/**
|
|
17
|
+
* Unique identifier for the widget.
|
|
18
|
+
*/
|
|
19
|
+
id: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Callback function to handle changes.
|
|
23
|
+
*/
|
|
24
|
+
onChange: (id: string, value: ActionValue) => void;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* List of actions available for the widget.
|
|
28
|
+
*/
|
|
29
|
+
actions?: Array<StyleDefinition | string>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Map containing additional the information (icon and i18n string) for each action.
|
|
33
|
+
*/
|
|
34
|
+
actionsInfoMap?: Record<string, ActionInfo>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* List of actions to be filtered out. In case that we don't want the default ones
|
|
38
|
+
* we can filter them out.
|
|
39
|
+
*/
|
|
40
|
+
filterActions?: string[];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Current value of the widget.
|
|
44
|
+
*/
|
|
45
|
+
value?: ActionValue;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Default value of the widget.
|
|
49
|
+
*/
|
|
50
|
+
default?: ActionValue;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Indicates if the widget is disabled.
|
|
54
|
+
*/
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Indicates if the widget is disabled (alternative flag for compatibility reasons).
|
|
59
|
+
*/
|
|
60
|
+
isDisabled?: boolean;
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
type NormalizedAction = {
|
|
65
|
+
name: string;
|
|
66
|
+
value: ActionValue;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const ButtonsWidget = (props: ButtonsWidgetProps) => {
|
|
70
|
+
const {
|
|
71
|
+
disabled,
|
|
72
|
+
id,
|
|
73
|
+
onChange,
|
|
74
|
+
actions = [],
|
|
75
|
+
actionsInfoMap,
|
|
76
|
+
value,
|
|
77
|
+
isDisabled,
|
|
78
|
+
default: defaultValue,
|
|
79
|
+
} = props;
|
|
80
|
+
|
|
81
|
+
const normalizedActions: NormalizedAction[] = actions.map((action) =>
|
|
82
|
+
typeof action === 'string'
|
|
83
|
+
? { name: action, value: action }
|
|
84
|
+
: {
|
|
85
|
+
name: action.name,
|
|
86
|
+
value: action.style ?? action.name,
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const selectedActionName = normalizedActions.find((action) =>
|
|
91
|
+
isEqual(value, action.value),
|
|
92
|
+
)?.name;
|
|
93
|
+
|
|
94
|
+
const defaultSelectedActionName = (() => {
|
|
95
|
+
if (!defaultValue) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (typeof defaultValue === 'string') {
|
|
100
|
+
const matchedByName = normalizedActions.find(
|
|
101
|
+
({ name }) => name === defaultValue,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
if (matchedByName) {
|
|
105
|
+
return matchedByName.name;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return normalizedActions.find(({ value: actionValue }) =>
|
|
110
|
+
isEqual(defaultValue, actionValue),
|
|
111
|
+
)?.name;
|
|
112
|
+
})();
|
|
113
|
+
|
|
114
|
+
const radioGroupValueProps: {
|
|
115
|
+
value?: string;
|
|
116
|
+
defaultValue?: string;
|
|
117
|
+
} = selectedActionName
|
|
118
|
+
? { value: selectedActionName }
|
|
119
|
+
: defaultSelectedActionName
|
|
120
|
+
? { defaultValue: defaultSelectedActionName }
|
|
121
|
+
: {};
|
|
122
|
+
|
|
123
|
+
const handleChange = (selectedName: string) => {
|
|
124
|
+
const selectedAction = normalizedActions.find(
|
|
125
|
+
({ name }) => name === selectedName,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
if (selectedAction) {
|
|
129
|
+
onChange(id, selectedAction.value);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<FormFieldWrapper {...props} className="widget">
|
|
135
|
+
<RadioGroup
|
|
136
|
+
aria-label={props.title || props.label || id}
|
|
137
|
+
orientation="horizontal"
|
|
138
|
+
{...radioGroupValueProps}
|
|
139
|
+
onChange={handleChange}
|
|
140
|
+
isDisabled={disabled || isDisabled}
|
|
141
|
+
className="buttons buttons-widget"
|
|
142
|
+
>
|
|
143
|
+
{normalizedActions.map((action) => {
|
|
144
|
+
const actionInfo = actionsInfoMap?.[action.name];
|
|
145
|
+
const [iconOrText, ariaLabel] = actionInfo ?? [
|
|
146
|
+
action.name,
|
|
147
|
+
action.name,
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<Radio
|
|
152
|
+
key={action.name}
|
|
153
|
+
aria-label={ariaLabel}
|
|
154
|
+
value={action.name}
|
|
155
|
+
className="buttons-widget-option"
|
|
156
|
+
>
|
|
157
|
+
{typeof iconOrText === 'string' ? (
|
|
158
|
+
<div className="image-sizes-text">{iconOrText}</div>
|
|
159
|
+
) : (
|
|
160
|
+
<Icon
|
|
161
|
+
// TODO: Refactor Icon component and type it correctly
|
|
162
|
+
name={iconOrText as any}
|
|
163
|
+
title={ariaLabel || action.name}
|
|
164
|
+
size="24px"
|
|
165
|
+
ariaHidden={true}
|
|
166
|
+
/>
|
|
167
|
+
)}
|
|
168
|
+
</Radio>
|
|
169
|
+
);
|
|
170
|
+
})}
|
|
171
|
+
</RadioGroup>
|
|
172
|
+
</FormFieldWrapper>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export default ButtonsWidget;
|
|
@@ -7,12 +7,7 @@ import CheckboxGroupWidget from './CheckboxGroupWidget';
|
|
|
7
7
|
|
|
8
8
|
const mockStore = configureStore();
|
|
9
9
|
|
|
10
|
-
vi.mock('@plone/volto/helpers/Loadable/Loadable'
|
|
11
|
-
return await import(
|
|
12
|
-
'@plone/volto/helpers/Loadable/__mocks__/Loadable.vitest.jsx'
|
|
13
|
-
);
|
|
14
|
-
});
|
|
15
|
-
|
|
10
|
+
vi.mock('@plone/volto/helpers/Loadable/Loadable');
|
|
16
11
|
beforeAll(async () => {
|
|
17
12
|
const { __setLoadables } = await import(
|
|
18
13
|
'@plone/volto/helpers/Loadable/Loadable'
|
|
@@ -27,6 +27,10 @@ const messages = defineMessages({
|
|
|
27
27
|
id: 'Time',
|
|
28
28
|
defaultMessage: 'Time',
|
|
29
29
|
},
|
|
30
|
+
clearDateTime: {
|
|
31
|
+
id: 'Clear date/time',
|
|
32
|
+
defaultMessage: 'Clear date and time',
|
|
33
|
+
},
|
|
30
34
|
});
|
|
31
35
|
|
|
32
36
|
const PrevIcon = () => (
|
|
@@ -80,6 +84,7 @@ const DatetimeWidgetComponent = (props) => {
|
|
|
80
84
|
widget,
|
|
81
85
|
noPastDates: propNoPastDates,
|
|
82
86
|
isDisabled,
|
|
87
|
+
formData,
|
|
83
88
|
} = props;
|
|
84
89
|
|
|
85
90
|
const intl = useIntl();
|
|
@@ -102,12 +107,21 @@ const DatetimeWidgetComponent = (props) => {
|
|
|
102
107
|
);
|
|
103
108
|
}, [value, lang, moment]);
|
|
104
109
|
|
|
110
|
+
// If open_end is checked and this is the end field, don't render
|
|
111
|
+
if (id === 'end' && formData?.open_end) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
105
115
|
const getInternalValue = () => {
|
|
106
116
|
return parseDateTime(toBackendLang(lang), value, undefined, moment.default);
|
|
107
117
|
};
|
|
108
118
|
|
|
109
119
|
const getDateOnly = () => {
|
|
110
|
-
return
|
|
120
|
+
return (
|
|
121
|
+
dateOnly ||
|
|
122
|
+
widget === 'date' ||
|
|
123
|
+
((id === 'start' || id === 'end') && formData?.whole_day)
|
|
124
|
+
);
|
|
111
125
|
};
|
|
112
126
|
|
|
113
127
|
const onDateChange = (date) => {
|
|
@@ -207,6 +221,7 @@ const DatetimeWidgetComponent = (props) => {
|
|
|
207
221
|
disabled={isDisabled || !datetime}
|
|
208
222
|
onClick={onResetDates}
|
|
209
223
|
className="item ui noborder button"
|
|
224
|
+
aria-label={intl.formatMessage(messages.clearDateTime)}
|
|
210
225
|
>
|
|
211
226
|
<Icon name={clearSVG} size="24px" className="close" />
|
|
212
227
|
</button>
|
|
@@ -6,12 +6,7 @@ import { waitFor, render, screen } from '@testing-library/react';
|
|
|
6
6
|
|
|
7
7
|
const mockStore = configureStore();
|
|
8
8
|
|
|
9
|
-
vi.mock('@plone/volto/helpers/Loadable/Loadable'
|
|
10
|
-
return await import(
|
|
11
|
-
'@plone/volto/helpers/Loadable/__mocks__/Loadable.vitest.jsx'
|
|
12
|
-
);
|
|
13
|
-
});
|
|
14
|
-
|
|
9
|
+
vi.mock('@plone/volto/helpers/Loadable/Loadable');
|
|
15
10
|
beforeAll(async () => {
|
|
16
11
|
const { __setLoadables } = await import(
|
|
17
12
|
'@plone/volto/helpers/Loadable/Loadable'
|