@wordpress/edit-site 5.24.1 → 5.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/add-new-template/add-custom-template-modal-content.js +2 -3
- package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build/components/block-editor/editor-canvas.js +48 -23
- package/build/components/block-editor/editor-canvas.js.map +1 -1
- package/build/components/block-editor/site-editor-canvas.js +5 -54
- package/build/components/block-editor/site-editor-canvas.js.map +1 -1
- package/build/components/block-editor/use-site-editor-settings.js +14 -5
- package/build/components/block-editor/use-site-editor-settings.js.map +1 -1
- package/build/components/editor/index.js +6 -17
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/collection-font-variant.js +8 -7
- package/build/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -1
- package/build/components/global-styles/font-library-modal/context.js +1 -1
- package/build/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build/components/global-styles/font-library-modal/library-font-variant.js +8 -7
- package/build/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
- package/build/components/global-styles/screen-revisions/get-revision-changes.js +146 -0
- package/build/components/global-styles/screen-revisions/get-revision-changes.js.map +1 -0
- package/build/components/global-styles/screen-revisions/index.js +6 -10
- package/build/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build/components/global-styles/screen-revisions/revisions-buttons.js +63 -13
- package/build/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
- package/build/components/header-edit-mode/document-tools/index.js +17 -10
- package/build/components/header-edit-mode/document-tools/index.js.map +1 -1
- package/build/components/header-edit-mode/index.js +16 -38
- package/build/components/header-edit-mode/index.js.map +1 -1
- package/build/components/header-edit-mode/more-menu/index.js +11 -9
- package/build/components/header-edit-mode/more-menu/index.js.map +1 -1
- package/build/components/layout/index.js +9 -8
- package/build/components/layout/index.js.map +1 -1
- package/build/components/page/header.js +2 -1
- package/build/components/page/header.js.map +1 -1
- package/build/components/page-pages/index.js +31 -28
- package/build/components/page-pages/index.js.map +1 -1
- package/build/components/page-patterns/patterns-list.js +1 -2
- package/build/components/page-patterns/patterns-list.js.map +1 -1
- package/build/components/page-patterns/rename-menu-item.js +3 -0
- package/build/components/page-patterns/rename-menu-item.js.map +1 -1
- package/build/components/page-templates/dataviews-templates.js +18 -17
- package/build/components/page-templates/dataviews-templates.js.map +1 -1
- package/build/components/preferences-modal/index.js +36 -20
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/routes/use-title.js +3 -4
- package/build/components/routes/use-title.js.map +1 -1
- package/build/components/save-button/index.js +2 -1
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/sidebar/index.js +26 -12
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar-dataviews/dataview-item.js +2 -10
- package/build/components/sidebar-dataviews/dataview-item.js.map +1 -1
- package/build/components/sidebar-dataviews/default-views.js +2 -2
- package/build/components/sidebar-dataviews/default-views.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/index.js +9 -3
- package/build/components/sidebar-edit-mode/page-panels/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/page-summary.js +1 -2
- package/build/components/sidebar-edit-mode/page-panels/page-summary.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/rename-modal.js +3 -0
- package/build/components/sidebar-navigation-screen-navigation-menu/rename-modal.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +1 -1
- package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template/home-template-details.js +3 -89
- package/build/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template/index.js +2 -1
- package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template/template-areas.js +117 -0
- package/build/components/sidebar-navigation-screen-template/template-areas.js.map +1 -0
- package/build/components/site-hub/index.js +6 -3
- package/build/components/site-hub/index.js.map +1 -1
- package/build/components/template-actions/rename-menu-item.js +3 -0
- package/build/components/template-actions/rename-menu-item.js.map +1 -1
- package/build/components/welcome-guide/styles.js +1 -1
- package/build/components/welcome-guide/styles.js.map +1 -1
- package/build/hooks/commands/use-common-commands.js +9 -1
- package/build/hooks/commands/use-common-commands.js.map +1 -1
- package/build/hooks/navigation-menu-edit.js +1 -1
- package/build/hooks/navigation-menu-edit.js.map +1 -1
- package/build/hooks/template-part-edit.js +1 -1
- package/build/hooks/template-part-edit.js.map +1 -1
- package/build/store/actions.js +15 -8
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +0 -18
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +12 -6
- package/build/store/selectors.js.map +1 -1
- package/build/utils/constants.js +15 -1
- package/build/utils/constants.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build-module/components/block-editor/editor-canvas.js +50 -25
- package/build-module/components/block-editor/editor-canvas.js.map +1 -1
- package/build-module/components/block-editor/site-editor-canvas.js +8 -56
- package/build-module/components/block-editor/site-editor-canvas.js.map +1 -1
- package/build-module/components/block-editor/use-site-editor-settings.js +14 -5
- package/build-module/components/block-editor/use-site-editor-settings.js.map +1 -1
- package/build-module/components/editor/index.js +9 -20
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/collection-font-variant.js +9 -7
- package/build-module/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/context.js +1 -1
- package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/library-font-variant.js +9 -7
- package/build-module/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/get-revision-changes.js +139 -0
- package/build-module/components/global-styles/screen-revisions/get-revision-changes.js.map +1 -0
- package/build-module/components/global-styles/screen-revisions/index.js +7 -11
- package/build-module/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/revisions-buttons.js +64 -14
- package/build-module/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
- package/build-module/components/header-edit-mode/document-tools/index.js +17 -10
- package/build-module/components/header-edit-mode/document-tools/index.js.map +1 -1
- package/build-module/components/header-edit-mode/index.js +20 -42
- package/build-module/components/header-edit-mode/index.js.map +1 -1
- package/build-module/components/header-edit-mode/more-menu/index.js +12 -10
- package/build-module/components/header-edit-mode/more-menu/index.js.map +1 -1
- package/build-module/components/layout/index.js +9 -8
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/page/header.js +2 -1
- package/build-module/components/page/header.js.map +1 -1
- package/build-module/components/page-pages/index.js +31 -28
- package/build-module/components/page-pages/index.js.map +1 -1
- package/build-module/components/page-patterns/patterns-list.js +1 -2
- package/build-module/components/page-patterns/patterns-list.js.map +1 -1
- package/build-module/components/page-patterns/rename-menu-item.js +3 -0
- package/build-module/components/page-patterns/rename-menu-item.js.map +1 -1
- package/build-module/components/page-templates/dataviews-templates.js +18 -17
- package/build-module/components/page-templates/dataviews-templates.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +37 -21
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/routes/use-title.js +3 -4
- package/build-module/components/routes/use-title.js.map +1 -1
- package/build-module/components/save-button/index.js +2 -1
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/sidebar/index.js +26 -12
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar-dataviews/dataview-item.js +2 -10
- package/build-module/components/sidebar-dataviews/dataview-item.js.map +1 -1
- package/build-module/components/sidebar-dataviews/default-views.js +2 -2
- package/build-module/components/sidebar-dataviews/default-views.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/index.js +9 -3
- package/build-module/components/sidebar-edit-mode/page-panels/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/page-summary.js +2 -3
- package/build-module/components/sidebar-edit-mode/page-panels/page-summary.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/rename-modal.js +3 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menu/rename-modal.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template/home-template-details.js +5 -90
- package/build-module/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template/index.js +2 -1
- package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template/template-areas.js +109 -0
- package/build-module/components/sidebar-navigation-screen-template/template-areas.js.map +1 -0
- package/build-module/components/site-hub/index.js +6 -3
- package/build-module/components/site-hub/index.js.map +1 -1
- package/build-module/components/template-actions/rename-menu-item.js +3 -0
- package/build-module/components/template-actions/rename-menu-item.js.map +1 -1
- package/build-module/components/welcome-guide/styles.js +1 -1
- package/build-module/components/welcome-guide/styles.js.map +1 -1
- package/build-module/hooks/commands/use-common-commands.js +9 -1
- package/build-module/hooks/commands/use-common-commands.js.map +1 -1
- package/build-module/hooks/navigation-menu-edit.js +1 -1
- package/build-module/hooks/navigation-menu-edit.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +1 -1
- package/build-module/hooks/template-part-edit.js.map +1 -1
- package/build-module/store/actions.js +13 -6
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +0 -17
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +10 -3
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/constants.js +8 -0
- package/build-module/utils/constants.js.map +1 -1
- package/build-style/style-rtl.css +302 -354
- package/build-style/style.css +302 -354
- package/package.json +42 -42
- package/src/components/add-new-template/add-custom-template-modal-content.js +1 -1
- package/src/components/block-editor/editor-canvas.js +63 -47
- package/src/components/block-editor/site-editor-canvas.js +32 -96
- package/src/components/block-editor/style.scss +6 -12
- package/src/components/block-editor/use-site-editor-settings.js +47 -36
- package/src/components/editor/index.js +10 -16
- package/src/components/global-styles/font-library-modal/collection-font-variant.js +12 -6
- package/src/components/global-styles/font-library-modal/context.js +1 -1
- package/src/components/global-styles/font-library-modal/library-font-variant.js +12 -6
- package/src/components/global-styles/screen-revisions/get-revision-changes.js +171 -0
- package/src/components/global-styles/screen-revisions/index.js +4 -11
- package/src/components/global-styles/screen-revisions/revisions-buttons.js +86 -17
- package/src/components/global-styles/screen-revisions/style.scss +10 -2
- package/src/components/global-styles/screen-revisions/test/get-revision-changes.js +191 -0
- package/src/components/header-edit-mode/document-tools/index.js +13 -13
- package/src/components/header-edit-mode/index.js +29 -63
- package/src/components/header-edit-mode/more-menu/index.js +18 -22
- package/src/components/header-edit-mode/style.scss +58 -33
- package/src/components/layout/index.js +21 -20
- package/src/components/list/style.scss +5 -0
- package/src/components/page/header.js +2 -1
- package/src/components/page/style.scss +2 -2
- package/src/components/page-pages/index.js +59 -35
- package/src/components/page-pages/style.scss +3 -1
- package/src/components/page-patterns/patterns-list.js +5 -2
- package/src/components/page-patterns/rename-menu-item.js +7 -1
- package/src/components/page-templates/dataviews-templates.js +28 -13
- package/src/components/preferences-modal/index.js +59 -33
- package/src/components/routes/use-title.js +3 -10
- package/src/components/save-button/index.js +1 -0
- package/src/components/sidebar/index.js +41 -24
- package/src/components/sidebar/style.scss +10 -12
- package/src/components/sidebar-dataviews/dataview-item.js +3 -7
- package/src/components/sidebar-dataviews/default-views.js +2 -2
- package/src/components/sidebar-edit-mode/page-panels/index.js +39 -25
- package/src/components/sidebar-edit-mode/page-panels/page-summary.js +2 -2
- package/src/components/sidebar-edit-mode/page-panels/style.scss +1 -42
- package/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js +7 -1
- package/src/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +1 -1
- package/src/components/sidebar-navigation-screen-template/home-template-details.js +1 -96
- package/src/components/sidebar-navigation-screen-template/index.js +8 -2
- package/src/components/sidebar-navigation-screen-template/template-areas.js +135 -0
- package/src/components/site-hub/index.js +4 -5
- package/src/components/template-actions/rename-menu-item.js +7 -1
- package/src/components/welcome-guide/styles.js +1 -1
- package/src/hooks/commands/use-common-commands.js +10 -5
- package/src/hooks/navigation-menu-edit.js +1 -1
- package/src/hooks/template-part-edit.js +1 -1
- package/src/store/actions.js +15 -5
- package/src/store/reducer.js +0 -18
- package/src/store/selectors.js +15 -3
- package/src/style.scss +1 -2
- package/src/utils/constants.js +8 -0
- package/build/components/dataviews/add-filter.js +0 -91
- package/build/components/dataviews/add-filter.js.map +0 -1
- package/build/components/dataviews/constants.js +0 -14
- package/build/components/dataviews/constants.js.map +0 -1
- package/build/components/dataviews/dataviews.js +0 -99
- package/build/components/dataviews/dataviews.js.map +0 -1
- package/build/components/dataviews/filter-summary.js +0 -62
- package/build/components/dataviews/filter-summary.js.map +0 -1
- package/build/components/dataviews/filters.js +0 -63
- package/build/components/dataviews/filters.js.map +0 -1
- package/build/components/dataviews/index.js +0 -21
- package/build/components/dataviews/index.js.map +0 -1
- package/build/components/dataviews/item-actions.js +0 -184
- package/build/components/dataviews/item-actions.js.map +0 -1
- package/build/components/dataviews/pagination.js +0 -123
- package/build/components/dataviews/pagination.js.map +0 -1
- package/build/components/dataviews/reset-filters.js +0 -33
- package/build/components/dataviews/reset-filters.js.map +0 -1
- package/build/components/dataviews/search.js +0 -51
- package/build/components/dataviews/search.js.map +0 -1
- package/build/components/dataviews/view-actions.js +0 -244
- package/build/components/dataviews/view-actions.js.map +0 -1
- package/build/components/dataviews/view-grid.js +0 -82
- package/build/components/dataviews/view-grid.js.map +0 -1
- package/build/components/dataviews/view-list.js +0 -399
- package/build/components/dataviews/view-list.js.map +0 -1
- package/build/components/dataviews/view-side-by-side.js +0 -20
- package/build/components/dataviews/view-side-by-side.js.map +0 -1
- package/build/components/header-edit-mode/document-actions/index.js +0 -172
- package/build/components/header-edit-mode/document-actions/index.js.map +0 -1
- package/build/components/page-content-focus-notifications/back-to-page-notification.js +0 -61
- package/build/components/page-content-focus-notifications/back-to-page-notification.js.map +0 -1
- package/build/components/page-content-focus-notifications/edit-template-notification.js +0 -102
- package/build/components/page-content-focus-notifications/edit-template-notification.js.map +0 -1
- package/build/components/page-content-focus-notifications/index.js +0 -22
- package/build/components/page-content-focus-notifications/index.js.map +0 -1
- package/build/components/sidebar-edit-mode/page-panels/edit-template.js +0 -101
- package/build/components/sidebar-edit-mode/page-panels/edit-template.js.map +0 -1
- package/build/components/sidebar-edit-mode/page-panels/hooks.js +0 -79
- package/build/components/sidebar-edit-mode/page-panels/hooks.js.map +0 -1
- package/build/components/sidebar-edit-mode/page-panels/reset-default-template.js +0 -48
- package/build/components/sidebar-edit-mode/page-panels/reset-default-template.js.map +0 -1
- package/build/components/sidebar-edit-mode/page-panels/swap-template-button.js +0 -84
- package/build/components/sidebar-edit-mode/page-panels/swap-template-button.js.map +0 -1
- package/build/utils/use-debounced-input.js +0 -22
- package/build/utils/use-debounced-input.js.map +0 -1
- package/build-module/components/dataviews/add-filter.js +0 -84
- package/build-module/components/dataviews/add-filter.js.map +0 -1
- package/build-module/components/dataviews/constants.js +0 -6
- package/build-module/components/dataviews/constants.js.map +0 -1
- package/build-module/components/dataviews/dataviews.js +0 -90
- package/build-module/components/dataviews/dataviews.js.map +0 -1
- package/build-module/components/dataviews/filter-summary.js +0 -55
- package/build-module/components/dataviews/filter-summary.js.map +0 -1
- package/build-module/components/dataviews/filters.js +0 -55
- package/build-module/components/dataviews/filters.js.map +0 -1
- package/build-module/components/dataviews/index.js +0 -2
- package/build-module/components/dataviews/index.js.map +0 -1
- package/build-module/components/dataviews/item-actions.js +0 -177
- package/build-module/components/dataviews/item-actions.js.map +0 -1
- package/build-module/components/dataviews/pagination.js +0 -115
- package/build-module/components/dataviews/pagination.js.map +0 -1
- package/build-module/components/dataviews/reset-filters.js +0 -26
- package/build-module/components/dataviews/reset-filters.js.map +0 -1
- package/build-module/components/dataviews/search.js +0 -43
- package/build-module/components/dataviews/search.js.map +0 -1
- package/build-module/components/dataviews/view-actions.js +0 -237
- package/build-module/components/dataviews/view-actions.js.map +0 -1
- package/build-module/components/dataviews/view-grid.js +0 -74
- package/build-module/components/dataviews/view-grid.js.map +0 -1
- package/build-module/components/dataviews/view-list.js +0 -390
- package/build-module/components/dataviews/view-list.js.map +0 -1
- package/build-module/components/dataviews/view-side-by-side.js +0 -12
- package/build-module/components/dataviews/view-side-by-side.js.map +0 -1
- package/build-module/components/header-edit-mode/document-actions/index.js +0 -164
- package/build-module/components/header-edit-mode/document-actions/index.js.map +0 -1
- package/build-module/components/page-content-focus-notifications/back-to-page-notification.js +0 -54
- package/build-module/components/page-content-focus-notifications/back-to-page-notification.js.map +0 -1
- package/build-module/components/page-content-focus-notifications/edit-template-notification.js +0 -96
- package/build-module/components/page-content-focus-notifications/edit-template-notification.js.map +0 -1
- package/build-module/components/page-content-focus-notifications/index.js +0 -14
- package/build-module/components/page-content-focus-notifications/index.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/page-panels/edit-template.js +0 -93
- package/build-module/components/sidebar-edit-mode/page-panels/edit-template.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/page-panels/hooks.js +0 -69
- package/build-module/components/sidebar-edit-mode/page-panels/hooks.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/page-panels/reset-default-template.js +0 -41
- package/build-module/components/sidebar-edit-mode/page-panels/reset-default-template.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/page-panels/swap-template-button.js +0 -77
- package/build-module/components/sidebar-edit-mode/page-panels/swap-template-button.js.map +0 -1
- package/build-module/utils/use-debounced-input.js +0 -15
- package/build-module/utils/use-debounced-input.js.map +0 -1
- package/src/components/dataviews/README.md +0 -191
- package/src/components/dataviews/add-filter.js +0 -108
- package/src/components/dataviews/constants.js +0 -5
- package/src/components/dataviews/dataviews.js +0 -99
- package/src/components/dataviews/filter-summary.js +0 -79
- package/src/components/dataviews/filters.js +0 -65
- package/src/components/dataviews/index.js +0 -1
- package/src/components/dataviews/item-actions.js +0 -208
- package/src/components/dataviews/pagination.js +0 -144
- package/src/components/dataviews/reset-filters.js +0 -26
- package/src/components/dataviews/search.js +0 -42
- package/src/components/dataviews/style.scss +0 -131
- package/src/components/dataviews/view-actions.js +0 -319
- package/src/components/dataviews/view-grid.js +0 -90
- package/src/components/dataviews/view-list.js +0 -512
- package/src/components/dataviews/view-side-by-side.js +0 -9
- package/src/components/header-edit-mode/document-actions/index.js +0 -204
- package/src/components/header-edit-mode/document-actions/style.scss +0 -145
- package/src/components/page-content-focus-notifications/back-to-page-notification.js +0 -58
- package/src/components/page-content-focus-notifications/edit-template-notification.js +0 -104
- package/src/components/page-content-focus-notifications/index.js +0 -14
- package/src/components/sidebar-edit-mode/page-panels/edit-template.js +0 -108
- package/src/components/sidebar-edit-mode/page-panels/hooks.js +0 -99
- package/src/components/sidebar-edit-mode/page-panels/reset-default-template.js +0 -45
- package/src/components/sidebar-edit-mode/page-panels/swap-template-button.js +0 -83
- package/src/utils/use-debounced-input.js +0 -18
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
|
+
const globalStylesChangesCache = new Map();
|
|
6
|
+
const EMPTY_ARRAY = [];
|
|
7
|
+
const translationMap = {
|
|
8
|
+
caption: __('Caption'),
|
|
9
|
+
link: __('Link'),
|
|
10
|
+
button: __('Button'),
|
|
11
|
+
heading: __('Heading'),
|
|
12
|
+
'settings.color': __('Color settings'),
|
|
13
|
+
'settings.typography': __('Typography settings'),
|
|
14
|
+
'styles.color': __('Colors'),
|
|
15
|
+
'styles.spacing': __('Spacing'),
|
|
16
|
+
'styles.typography': __('Typography')
|
|
17
|
+
};
|
|
18
|
+
const isObject = obj => obj !== null && typeof obj === 'object';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get the translation for a given global styles key.
|
|
22
|
+
* @param {string} key A key representing a path to a global style property or setting.
|
|
23
|
+
* @param {Record<string,string>} blockNames A key/value pair object of block names and their rendered titles.
|
|
24
|
+
* @return {string|undefined} A translated key or undefined if no translation exists.
|
|
25
|
+
*/
|
|
26
|
+
function getTranslation(key, blockNames) {
|
|
27
|
+
if (translationMap[key]) {
|
|
28
|
+
return translationMap[key];
|
|
29
|
+
}
|
|
30
|
+
const keyArray = key.split('.');
|
|
31
|
+
if (keyArray?.[0] === 'blocks') {
|
|
32
|
+
const blockName = blockNames[keyArray[1]];
|
|
33
|
+
return blockName ? sprintf(
|
|
34
|
+
// translators: %s: block name.
|
|
35
|
+
__('%s block'), blockName) : keyArray[1];
|
|
36
|
+
}
|
|
37
|
+
if (keyArray?.[0] === 'elements') {
|
|
38
|
+
return sprintf(
|
|
39
|
+
// translators: %s: element name, e.g., heading button, link, caption.
|
|
40
|
+
__('%s element'), translationMap[keyArray[1]]);
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A deep comparison of two objects, optimized for comparing global styles.
|
|
47
|
+
* @param {Object} changedObject The changed object to compare.
|
|
48
|
+
* @param {Object} originalObject The original object to compare against.
|
|
49
|
+
* @param {string} parentPath A key/value pair object of block names and their rendered titles.
|
|
50
|
+
* @return {string[]} An array of paths whose values have changed.
|
|
51
|
+
*/
|
|
52
|
+
function deepCompare(changedObject, originalObject, parentPath = '') {
|
|
53
|
+
// We have two non-object values to compare.
|
|
54
|
+
if (!isObject(changedObject) && !isObject(originalObject)) {
|
|
55
|
+
/*
|
|
56
|
+
* Only return a path if the value has changed.
|
|
57
|
+
* And then only the path name up to 2 levels deep.
|
|
58
|
+
*/
|
|
59
|
+
return changedObject !== originalObject ? parentPath.split('.').slice(0, 2).join('.') : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Enable comparison when an object doesn't have a corresponding property to compare.
|
|
63
|
+
changedObject = isObject(changedObject) ? changedObject : {};
|
|
64
|
+
originalObject = isObject(originalObject) ? originalObject : {};
|
|
65
|
+
const allKeys = new Set([...Object.keys(changedObject), ...Object.keys(originalObject)]);
|
|
66
|
+
let diffs = [];
|
|
67
|
+
for (const key of allKeys) {
|
|
68
|
+
const path = parentPath ? parentPath + '.' + key : key;
|
|
69
|
+
const changedPath = deepCompare(changedObject[key], originalObject[key], path);
|
|
70
|
+
if (changedPath) {
|
|
71
|
+
diffs = diffs.concat(changedPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return diffs;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get an array of translated summarized global styles changes.
|
|
79
|
+
* Results are cached using a Map() key of `JSON.stringify( { revision, previousRevision } )`.
|
|
80
|
+
*
|
|
81
|
+
* @param {Object} revision The changed object to compare.
|
|
82
|
+
* @param {Object} previousRevision The original object to compare against.
|
|
83
|
+
* @param {Record<string,string>} blockNames A key/value pair object of block names and their rendered titles.
|
|
84
|
+
* @return {string[]} An array of translated changes.
|
|
85
|
+
*/
|
|
86
|
+
export default function getRevisionChanges(revision, previousRevision, blockNames) {
|
|
87
|
+
const cacheKey = JSON.stringify({
|
|
88
|
+
revision,
|
|
89
|
+
previousRevision
|
|
90
|
+
});
|
|
91
|
+
if (globalStylesChangesCache.has(cacheKey)) {
|
|
92
|
+
return globalStylesChangesCache.get(cacheKey);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* Compare the two revisions with normalized keys.
|
|
97
|
+
* The order of these keys determines the order in which
|
|
98
|
+
* they'll appear in the results.
|
|
99
|
+
*/
|
|
100
|
+
const changedValueTree = deepCompare({
|
|
101
|
+
styles: {
|
|
102
|
+
color: revision?.styles?.color,
|
|
103
|
+
typography: revision?.styles?.typography,
|
|
104
|
+
spacing: revision?.styles?.spacing
|
|
105
|
+
},
|
|
106
|
+
blocks: revision?.styles?.blocks,
|
|
107
|
+
elements: revision?.styles?.elements,
|
|
108
|
+
settings: revision?.settings
|
|
109
|
+
}, {
|
|
110
|
+
styles: {
|
|
111
|
+
color: previousRevision?.styles?.color,
|
|
112
|
+
typography: previousRevision?.styles?.typography,
|
|
113
|
+
spacing: previousRevision?.styles?.spacing
|
|
114
|
+
},
|
|
115
|
+
blocks: previousRevision?.styles?.blocks,
|
|
116
|
+
elements: previousRevision?.styles?.elements,
|
|
117
|
+
settings: previousRevision?.settings
|
|
118
|
+
});
|
|
119
|
+
if (!changedValueTree.length) {
|
|
120
|
+
globalStylesChangesCache.set(cacheKey, EMPTY_ARRAY);
|
|
121
|
+
return EMPTY_ARRAY;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Remove duplicate results.
|
|
125
|
+
const result = [...new Set(changedValueTree)]
|
|
126
|
+
/*
|
|
127
|
+
* Translate the keys.
|
|
128
|
+
* Remove duplicate or empty translations.
|
|
129
|
+
*/.reduce((acc, curr) => {
|
|
130
|
+
const translation = getTranslation(curr, blockNames);
|
|
131
|
+
if (translation && !acc.includes(translation)) {
|
|
132
|
+
acc.push(translation);
|
|
133
|
+
}
|
|
134
|
+
return acc;
|
|
135
|
+
}, []);
|
|
136
|
+
globalStylesChangesCache.set(cacheKey, result);
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=get-revision-changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__","sprintf","globalStylesChangesCache","Map","EMPTY_ARRAY","translationMap","caption","link","button","heading","isObject","obj","getTranslation","key","blockNames","keyArray","split","blockName","undefined","deepCompare","changedObject","originalObject","parentPath","slice","join","allKeys","Set","Object","keys","diffs","path","changedPath","concat","getRevisionChanges","revision","previousRevision","cacheKey","JSON","stringify","has","get","changedValueTree","styles","color","typography","spacing","blocks","elements","settings","length","set","result","reduce","acc","curr","translation","includes","push"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-revisions/get-revision-changes.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\nconst globalStylesChangesCache = new Map();\nconst EMPTY_ARRAY = [];\n\nconst translationMap = {\n\tcaption: __( 'Caption' ),\n\tlink: __( 'Link' ),\n\tbutton: __( 'Button' ),\n\theading: __( 'Heading' ),\n\t'settings.color': __( 'Color settings' ),\n\t'settings.typography': __( 'Typography settings' ),\n\t'styles.color': __( 'Colors' ),\n\t'styles.spacing': __( 'Spacing' ),\n\t'styles.typography': __( 'Typography' ),\n};\n\nconst isObject = ( obj ) => obj !== null && typeof obj === 'object';\n\n/**\n * Get the translation for a given global styles key.\n * @param {string} key A key representing a path to a global style property or setting.\n * @param {Record<string,string>} blockNames A key/value pair object of block names and their rendered titles.\n * @return {string|undefined} A translated key or undefined if no translation exists.\n */\nfunction getTranslation( key, blockNames ) {\n\tif ( translationMap[ key ] ) {\n\t\treturn translationMap[ key ];\n\t}\n\n\tconst keyArray = key.split( '.' );\n\n\tif ( keyArray?.[ 0 ] === 'blocks' ) {\n\t\tconst blockName = blockNames[ keyArray[ 1 ] ];\n\t\treturn blockName\n\t\t\t? sprintf(\n\t\t\t\t\t// translators: %s: block name.\n\t\t\t\t\t__( '%s block' ),\n\t\t\t\t\tblockName\n\t\t\t )\n\t\t\t: keyArray[ 1 ];\n\t}\n\n\tif ( keyArray?.[ 0 ] === 'elements' ) {\n\t\treturn sprintf(\n\t\t\t// translators: %s: element name, e.g., heading button, link, caption.\n\t\t\t__( '%s element' ),\n\t\t\ttranslationMap[ keyArray[ 1 ] ]\n\t\t);\n\t}\n\n\treturn undefined;\n}\n\n/**\n * A deep comparison of two objects, optimized for comparing global styles.\n * @param {Object} changedObject The changed object to compare.\n * @param {Object} originalObject The original object to compare against.\n * @param {string} parentPath A key/value pair object of block names and their rendered titles.\n * @return {string[]} An array of paths whose values have changed.\n */\nfunction deepCompare( changedObject, originalObject, parentPath = '' ) {\n\t// We have two non-object values to compare.\n\tif ( ! isObject( changedObject ) && ! isObject( originalObject ) ) {\n\t\t/*\n\t\t * Only return a path if the value has changed.\n\t\t * And then only the path name up to 2 levels deep.\n\t\t */\n\t\treturn changedObject !== originalObject\n\t\t\t? parentPath.split( '.' ).slice( 0, 2 ).join( '.' )\n\t\t\t: undefined;\n\t}\n\n\t// Enable comparison when an object doesn't have a corresponding property to compare.\n\tchangedObject = isObject( changedObject ) ? changedObject : {};\n\toriginalObject = isObject( originalObject ) ? originalObject : {};\n\n\tconst allKeys = new Set( [\n\t\t...Object.keys( changedObject ),\n\t\t...Object.keys( originalObject ),\n\t] );\n\n\tlet diffs = [];\n\tfor ( const key of allKeys ) {\n\t\tconst path = parentPath ? parentPath + '.' + key : key;\n\t\tconst changedPath = deepCompare(\n\t\t\tchangedObject[ key ],\n\t\t\toriginalObject[ key ],\n\t\t\tpath\n\t\t);\n\t\tif ( changedPath ) {\n\t\t\tdiffs = diffs.concat( changedPath );\n\t\t}\n\t}\n\treturn diffs;\n}\n\n/**\n * Get an array of translated summarized global styles changes.\n * Results are cached using a Map() key of `JSON.stringify( { revision, previousRevision } )`.\n *\n * @param {Object} revision The changed object to compare.\n * @param {Object} previousRevision The original object to compare against.\n * @param {Record<string,string>} blockNames A key/value pair object of block names and their rendered titles.\n * @return {string[]} An array of translated changes.\n */\nexport default function getRevisionChanges(\n\trevision,\n\tpreviousRevision,\n\tblockNames\n) {\n\tconst cacheKey = JSON.stringify( { revision, previousRevision } );\n\n\tif ( globalStylesChangesCache.has( cacheKey ) ) {\n\t\treturn globalStylesChangesCache.get( cacheKey );\n\t}\n\n\t/*\n\t * Compare the two revisions with normalized keys.\n\t * The order of these keys determines the order in which\n\t * they'll appear in the results.\n\t */\n\tconst changedValueTree = deepCompare(\n\t\t{\n\t\t\tstyles: {\n\t\t\t\tcolor: revision?.styles?.color,\n\t\t\t\ttypography: revision?.styles?.typography,\n\t\t\t\tspacing: revision?.styles?.spacing,\n\t\t\t},\n\t\t\tblocks: revision?.styles?.blocks,\n\t\t\telements: revision?.styles?.elements,\n\t\t\tsettings: revision?.settings,\n\t\t},\n\t\t{\n\t\t\tstyles: {\n\t\t\t\tcolor: previousRevision?.styles?.color,\n\t\t\t\ttypography: previousRevision?.styles?.typography,\n\t\t\t\tspacing: previousRevision?.styles?.spacing,\n\t\t\t},\n\t\t\tblocks: previousRevision?.styles?.blocks,\n\t\t\telements: previousRevision?.styles?.elements,\n\t\t\tsettings: previousRevision?.settings,\n\t\t}\n\t);\n\n\tif ( ! changedValueTree.length ) {\n\t\tglobalStylesChangesCache.set( cacheKey, EMPTY_ARRAY );\n\t\treturn EMPTY_ARRAY;\n\t}\n\n\t// Remove duplicate results.\n\tconst result = [ ...new Set( changedValueTree ) ]\n\t\t/*\n\t\t * Translate the keys.\n\t\t * Remove duplicate or empty translations.\n\t\t */\n\t\t.reduce( ( acc, curr ) => {\n\t\t\tconst translation = getTranslation( curr, blockNames );\n\t\t\tif ( translation && ! acc.includes( translation ) ) {\n\t\t\t\tacc.push( translation );\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, [] );\n\n\tglobalStylesChangesCache.set( cacheKey, result );\n\n\treturn result;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAE7C,MAAMC,wBAAwB,GAAG,IAAIC,GAAG,CAAC,CAAC;AAC1C,MAAMC,WAAW,GAAG,EAAE;AAEtB,MAAMC,cAAc,GAAG;EACtBC,OAAO,EAAEN,EAAE,CAAE,SAAU,CAAC;EACxBO,IAAI,EAAEP,EAAE,CAAE,MAAO,CAAC;EAClBQ,MAAM,EAAER,EAAE,CAAE,QAAS,CAAC;EACtBS,OAAO,EAAET,EAAE,CAAE,SAAU,CAAC;EACxB,gBAAgB,EAAEA,EAAE,CAAE,gBAAiB,CAAC;EACxC,qBAAqB,EAAEA,EAAE,CAAE,qBAAsB,CAAC;EAClD,cAAc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wBAAwB,CAACgD,GAAG,CAAEd,QAAQ,EAAEe,MAAO,CAAC;EAEhD,OAAOA,MAAM;AACd"}
|
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "react";
|
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
-
import { Button, __experimentalUseNavigator as useNavigator, __experimentalConfirmDialog as ConfirmDialog, Spinner
|
|
6
|
+
import { Button, __experimentalUseNavigator as useNavigator, __experimentalConfirmDialog as ConfirmDialog, Spinner } from '@wordpress/components';
|
|
7
7
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
9
9
|
import { useContext, useState, useEffect } from '@wordpress/element';
|
|
@@ -113,7 +113,8 @@ function ScreenRevisions() {
|
|
|
113
113
|
}
|
|
114
114
|
}, [shouldSelectFirstItem, firstRevision]);
|
|
115
115
|
|
|
116
|
-
// Only display load button if there is a revision to load
|
|
116
|
+
// Only display load button if there is a revision to load,
|
|
117
|
+
// and it is different from the current editor styles.
|
|
117
118
|
const isLoadButtonEnabled = !!currentlySelectedRevisionId && !selectedRevisionMatchesEditorStyles;
|
|
118
119
|
const shouldShowRevisions = !isLoading && revisions.length;
|
|
119
120
|
return createElement(Fragment, null, createElement(ScreenHeader, {
|
|
@@ -124,7 +125,7 @@ function ScreenRevisions() {
|
|
|
124
125
|
onBack: onCloseRevisions
|
|
125
126
|
}), isLoading && createElement(Spinner, {
|
|
126
127
|
className: "edit-site-global-styles-screen-revisions__loading"
|
|
127
|
-
}), shouldShowRevisions
|
|
128
|
+
}), shouldShowRevisions && createElement(Fragment, null, createElement(Revisions, {
|
|
128
129
|
blocks: blocks,
|
|
129
130
|
userConfig: currentlySelectedRevision,
|
|
130
131
|
onClose: onCloseRevisions
|
|
@@ -133,7 +134,8 @@ function ScreenRevisions() {
|
|
|
133
134
|
}, createElement(RevisionsButtons, {
|
|
134
135
|
onChange: selectRevision,
|
|
135
136
|
selectedRevisionId: currentlySelectedRevisionId,
|
|
136
|
-
userRevisions: revisions
|
|
137
|
+
userRevisions: revisions,
|
|
138
|
+
canApplyRevision: isLoadButtonEnabled
|
|
137
139
|
}), isLoadButtonEnabled && createElement(SidebarFixedBottom, null, createElement(Button, {
|
|
138
140
|
variant: "primary",
|
|
139
141
|
className: "edit-site-global-styles-screen-revisions__button",
|
|
@@ -150,13 +152,7 @@ function ScreenRevisions() {
|
|
|
150
152
|
confirmButtonText: __('Apply'),
|
|
151
153
|
onConfirm: () => restoreRevision(currentlySelectedRevision),
|
|
152
154
|
onCancel: () => setIsLoadingRevisionWithUnsavedChanges(false)
|
|
153
|
-
}, __('Any unsaved changes will be lost when you apply this revision.')))
|
|
154
|
-
marginX: 4,
|
|
155
|
-
"data-testid": "global-styles-no-revisions"
|
|
156
|
-
},
|
|
157
|
-
// Adding an existing translation here in case these changes are shipped to WordPress 6.3.
|
|
158
|
-
// Later we could update to something better, e.g., "There are currently no style revisions.".
|
|
159
|
-
__('No results found.')));
|
|
155
|
+
}, __('Any unsaved changes will be lost when you apply this revision.'))));
|
|
160
156
|
}
|
|
161
157
|
export default ScreenRevisions;
|
|
162
158
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","sprintf","Button","__experimentalUseNavigator","useNavigator","__experimentalConfirmDialog","ConfirmDialog","Spinner","__experimentalSpacer","Spacer","useSelect","useDispatch","store","coreStore","useContext","useState","useEffect","privateApis","blockEditorPrivateApis","blockEditorStore","ScreenHeader","unlock","Revisions","SidebarFixedBottom","editSiteStore","useGlobalStylesRevisions","RevisionsButtons","GlobalStylesContext","areGlobalStyleConfigsEqual","ScreenRevisions","goTo","user","currentEditorGlobalStyles","setUserConfig","blocks","editorCanvasContainerView","revisionsCount","select","getEntityRecord","__experimentalGetCurrentGlobalStylesId","__experimentalGetDirtyEntityRecords","isDirty","length","globalStylesId","globalStyles","undefined","_revisionsCount","_links","count","getEditorCanvasContainerView","getBlocks","revisions","isLoading","hasUnsavedChanges","currentlySelectedRevision","setCurrentlySelectedRevision","isLoadingRevisionWithUnsavedChanges","setIsLoadingRevisionWithUnsavedChanges","setEditorCanvasContainerView","selectedRevisionMatchesEditorStyles","onCloseRevisions","restoreRevision","revision","styles","settings","selectRevision","id","firstRevision","currentlySelectedRevisionId","shouldSelectFirstItem","isLoadButtonEnabled","shouldShowRevisions","createElement","Fragment","title","description","onBack","className","userConfig","onClose","onChange","selectedRevisionId","userRevisions","variant","disabled","onClick","isOpen","confirmButtonText","onConfirm","onCancel","marginX"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-revisions/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\t__experimentalUseNavigator as useNavigator,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\tSpinner,\n\t__experimentalSpacer as Spacer,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useContext, useState, useEffect } from '@wordpress/element';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport ScreenHeader from '../header';\nimport { unlock } from '../../../lock-unlock';\nimport Revisions from '../../revisions';\nimport SidebarFixedBottom from '../../sidebar-edit-mode/sidebar-fixed-bottom';\nimport { store as editSiteStore } from '../../../store';\nimport useGlobalStylesRevisions from './use-global-styles-revisions';\nimport RevisionsButtons from './revisions-buttons';\n\nconst { GlobalStylesContext, areGlobalStyleConfigsEqual } = unlock(\n\tblockEditorPrivateApis\n);\n\nfunction ScreenRevisions() {\n\tconst { goTo } = useNavigator();\n\tconst { user: currentEditorGlobalStyles, setUserConfig } =\n\t\tuseContext( GlobalStylesContext );\n\tconst { blocks, editorCanvasContainerView, revisionsCount } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEntityRecord,\n\t\t\t\t__experimentalGetCurrentGlobalStylesId,\n\t\t\t\t__experimentalGetDirtyEntityRecords,\n\t\t\t} = select( coreStore );\n\t\t\tconst isDirty = __experimentalGetDirtyEntityRecords().length > 0;\n\t\t\tconst globalStylesId = __experimentalGetCurrentGlobalStylesId();\n\t\t\tconst globalStyles = globalStylesId\n\t\t\t\t? getEntityRecord( 'root', 'globalStyles', globalStylesId )\n\t\t\t\t: undefined;\n\t\t\tlet _revisionsCount =\n\t\t\t\tglobalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count || 0;\n\t\t\t// one for the reset item.\n\t\t\t_revisionsCount++;\n\t\t\t// one for any dirty changes (unsaved).\n\t\t\tif ( isDirty ) {\n\t\t\t\t_revisionsCount++;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\teditorCanvasContainerView: unlock(\n\t\t\t\t\tselect( editSiteStore )\n\t\t\t\t).getEditorCanvasContainerView(),\n\t\t\t\tblocks: select( blockEditorStore ).getBlocks(),\n\t\t\t\trevisionsCount: _revisionsCount,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { revisions, isLoading, hasUnsavedChanges } =\n\t\tuseGlobalStylesRevisions();\n\tconst [ currentlySelectedRevision, setCurrentlySelectedRevision ] =\n\t\tuseState( currentEditorGlobalStyles );\n\tconst [\n\t\tisLoadingRevisionWithUnsavedChanges,\n\t\tsetIsLoadingRevisionWithUnsavedChanges,\n\t] = useState( false );\n\tconst { setEditorCanvasContainerView } = unlock(\n\t\tuseDispatch( editSiteStore )\n\t);\n\tconst selectedRevisionMatchesEditorStyles = areGlobalStyleConfigsEqual(\n\t\tcurrentlySelectedRevision,\n\t\tcurrentEditorGlobalStyles\n\t);\n\n\tconst onCloseRevisions = () => {\n\t\tgoTo( '/' ); // Return to global styles main panel.\n\t\tsetEditorCanvasContainerView( undefined );\n\t};\n\n\tconst restoreRevision = ( revision ) => {\n\t\tsetUserConfig( () => ( {\n\t\t\tstyles: revision?.styles,\n\t\t\tsettings: revision?.settings,\n\t\t} ) );\n\t\tsetIsLoadingRevisionWithUnsavedChanges( false );\n\t\tonCloseRevisions();\n\t};\n\n\tconst selectRevision = ( revision ) => {\n\t\tsetCurrentlySelectedRevision( {\n\t\t\tstyles: revision?.styles || {},\n\t\t\tsettings: revision?.settings || {},\n\t\t\tid: revision?.id,\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( editorCanvasContainerView !== 'global-styles-revisions' ) {\n\t\t\tgoTo( '/' ); // Return to global styles main panel.\n\t\t\tsetEditorCanvasContainerView( editorCanvasContainerView );\n\t\t}\n\t}, [ editorCanvasContainerView ] );\n\n\tconst firstRevision = revisions[ 0 ];\n\tconst currentlySelectedRevisionId = currentlySelectedRevision?.id;\n\tconst shouldSelectFirstItem =\n\t\t!! firstRevision?.id &&\n\t\t! selectedRevisionMatchesEditorStyles &&\n\t\t! currentlySelectedRevisionId;\n\n\tuseEffect( () => {\n\t\t/*\n\t\t * Ensure that the first item is selected and loaded into the preview pane\n\t\t * when no revision is selected and the selected styles don't match the current editor styles.\n\t\t * This is required in case editor styles are changed outside the revisions panel,\n\t\t * e.g., via the reset styles function of useGlobalStylesReset().\n\t\t * See: https://github.com/WordPress/gutenberg/issues/55866\n\t\t */\n\t\tif ( shouldSelectFirstItem ) {\n\t\t\tsetCurrentlySelectedRevision( {\n\t\t\t\tstyles: firstRevision?.styles || {},\n\t\t\t\tsettings: firstRevision?.settings || {},\n\t\t\t\tid: firstRevision?.id,\n\t\t\t} );\n\t\t}\n\t}, [ shouldSelectFirstItem, firstRevision ] );\n\n\t// Only display load button if there is a revision to load and it is different from the current editor styles.\n\tconst isLoadButtonEnabled =\n\t\t!! currentlySelectedRevisionId && ! selectedRevisionMatchesEditorStyles;\n\tconst shouldShowRevisions = ! isLoading && revisions.length;\n\n\treturn (\n\t\t<>\n\t\t\t<ScreenHeader\n\t\t\t\ttitle={\n\t\t\t\t\trevisionsCount &&\n\t\t\t\t\t// translators: %s: number of revisions.\n\t\t\t\t\tsprintf( __( 'Revisions (%s)' ), revisionsCount )\n\t\t\t\t}\n\t\t\t\tdescription={ __(\n\t\t\t\t\t'Click on previously saved styles to preview them. To restore a selected version to the editor, hit \"Apply.\" When you\\'re ready, use the Save button to save your changes.'\n\t\t\t\t) }\n\t\t\t\tonBack={ onCloseRevisions }\n\t\t\t/>\n\t\t\t{ isLoading && (\n\t\t\t\t<Spinner className=\"edit-site-global-styles-screen-revisions__loading\" />\n\t\t\t) }\n\t\t\t{ shouldShowRevisions ? (\n\t\t\t\t<>\n\t\t\t\t\t<Revisions\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tuserConfig={ currentlySelectedRevision }\n\t\t\t\t\t\tonClose={ onCloseRevisions }\n\t\t\t\t\t/>\n\t\t\t\t\t<div className=\"edit-site-global-styles-screen-revisions\">\n\t\t\t\t\t\t<RevisionsButtons\n\t\t\t\t\t\t\tonChange={ selectRevision }\n\t\t\t\t\t\t\tselectedRevisionId={ currentlySelectedRevisionId }\n\t\t\t\t\t\t\tuserRevisions={ revisions }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ isLoadButtonEnabled && (\n\t\t\t\t\t\t\t<SidebarFixedBottom>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-screen-revisions__button\"\n\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\t! currentlySelectedRevisionId ||\n\t\t\t\t\t\t\t\t\t\tcurrentlySelectedRevisionId ===\n\t\t\t\t\t\t\t\t\t\t\t'unsaved'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tif ( hasUnsavedChanges ) {\n\t\t\t\t\t\t\t\t\t\t\tsetIsLoadingRevisionWithUnsavedChanges(\n\t\t\t\t\t\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\trestoreRevision(\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentlySelectedRevision\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ currentlySelectedRevisionId === 'parent'\n\t\t\t\t\t\t\t\t\t\t? __( 'Reset to defaults' )\n\t\t\t\t\t\t\t\t\t\t: __( 'Apply' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</SidebarFixedBottom>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t\t{ isLoadingRevisionWithUnsavedChanges && (\n\t\t\t\t\t\t<ConfirmDialog\n\t\t\t\t\t\t\tisOpen={ isLoadingRevisionWithUnsavedChanges }\n\t\t\t\t\t\t\tconfirmButtonText={ __( 'Apply' ) }\n\t\t\t\t\t\t\tonConfirm={ () =>\n\t\t\t\t\t\t\t\trestoreRevision( currentlySelectedRevision )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonCancel={ () =>\n\t\t\t\t\t\t\t\tsetIsLoadingRevisionWithUnsavedChanges( false )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Any unsaved changes will be lost when you apply this revision.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</ConfirmDialog>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<Spacer marginX={ 4 } data-testid=\"global-styles-no-revisions\">\n\t\t\t\t\t{\n\t\t\t\t\t\t// Adding an existing translation here in case these changes are shipped to WordPress 6.3.\n\t\t\t\t\t\t// Later we could update to something better, e.g., \"There are currently no style revisions.\".\n\t\t\t\t\t\t__( 'No results found.' )\n\t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A,EAAE,CAAE,OAAQ,CACR,CACW,CAEjB,CAAC,EACJwD,mCAAmC,IACpCgB,aAAA,CAAClE,aAAa;IACbgF,MAAM,EAAG9B,mCAAqC;IAC9C+B,iBAAiB,EAAGvF,EAAE,CAAE,OAAQ,CAAG;IACnCwF,SAAS,EAAGA,CAAA,KACX3B,eAAe,CAAEP,yBAA0B,CAC3C;IACDmC,QAAQ,EAAGA,CAAA,KACVhC,sCAAsC,CAAE,KAAM;EAC9C,GAECzD,EAAE,CACH,gEACD,CACc,CAEf,CAAC,GAEHwE,aAAA,CAAC/D,MAAM;IAACiF,OAAO,EAAG,CAAG;IAAC,eAAY;EAA4B;EAE5D;EACA;EACA1F,EAAE,CAAE,mBAAoB,CAElB,CAER,CAAC;AAEL;AAEA,eAAe6B,eAAe"}
|
|
1
|
+
{"version":3,"names":["__","sprintf","Button","__experimentalUseNavigator","useNavigator","__experimentalConfirmDialog","ConfirmDialog","Spinner","useSelect","useDispatch","store","coreStore","useContext","useState","useEffect","privateApis","blockEditorPrivateApis","blockEditorStore","ScreenHeader","unlock","Revisions","SidebarFixedBottom","editSiteStore","useGlobalStylesRevisions","RevisionsButtons","GlobalStylesContext","areGlobalStyleConfigsEqual","ScreenRevisions","goTo","user","currentEditorGlobalStyles","setUserConfig","blocks","editorCanvasContainerView","revisionsCount","select","getEntityRecord","__experimentalGetCurrentGlobalStylesId","__experimentalGetDirtyEntityRecords","isDirty","length","globalStylesId","globalStyles","undefined","_revisionsCount","_links","count","getEditorCanvasContainerView","getBlocks","revisions","isLoading","hasUnsavedChanges","currentlySelectedRevision","setCurrentlySelectedRevision","isLoadingRevisionWithUnsavedChanges","setIsLoadingRevisionWithUnsavedChanges","setEditorCanvasContainerView","selectedRevisionMatchesEditorStyles","onCloseRevisions","restoreRevision","revision","styles","settings","selectRevision","id","firstRevision","currentlySelectedRevisionId","shouldSelectFirstItem","isLoadButtonEnabled","shouldShowRevisions","createElement","Fragment","title","description","onBack","className","userConfig","onClose","onChange","selectedRevisionId","userRevisions","canApplyRevision","variant","disabled","onClick","isOpen","confirmButtonText","onConfirm","onCancel"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-revisions/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\t__experimentalUseNavigator as useNavigator,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\tSpinner,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useContext, useState, useEffect } from '@wordpress/element';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport ScreenHeader from '../header';\nimport { unlock } from '../../../lock-unlock';\nimport Revisions from '../../revisions';\nimport SidebarFixedBottom from '../../sidebar-edit-mode/sidebar-fixed-bottom';\nimport { store as editSiteStore } from '../../../store';\nimport useGlobalStylesRevisions from './use-global-styles-revisions';\nimport RevisionsButtons from './revisions-buttons';\n\nconst { GlobalStylesContext, areGlobalStyleConfigsEqual } = unlock(\n\tblockEditorPrivateApis\n);\n\nfunction ScreenRevisions() {\n\tconst { goTo } = useNavigator();\n\tconst { user: currentEditorGlobalStyles, setUserConfig } =\n\t\tuseContext( GlobalStylesContext );\n\tconst { blocks, editorCanvasContainerView, revisionsCount } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEntityRecord,\n\t\t\t\t__experimentalGetCurrentGlobalStylesId,\n\t\t\t\t__experimentalGetDirtyEntityRecords,\n\t\t\t} = select( coreStore );\n\t\t\tconst isDirty = __experimentalGetDirtyEntityRecords().length > 0;\n\t\t\tconst globalStylesId = __experimentalGetCurrentGlobalStylesId();\n\t\t\tconst globalStyles = globalStylesId\n\t\t\t\t? getEntityRecord( 'root', 'globalStyles', globalStylesId )\n\t\t\t\t: undefined;\n\t\t\tlet _revisionsCount =\n\t\t\t\tglobalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count || 0;\n\t\t\t// one for the reset item.\n\t\t\t_revisionsCount++;\n\t\t\t// one for any dirty changes (unsaved).\n\t\t\tif ( isDirty ) {\n\t\t\t\t_revisionsCount++;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\teditorCanvasContainerView: unlock(\n\t\t\t\t\tselect( editSiteStore )\n\t\t\t\t).getEditorCanvasContainerView(),\n\t\t\t\tblocks: select( blockEditorStore ).getBlocks(),\n\t\t\t\trevisionsCount: _revisionsCount,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { revisions, isLoading, hasUnsavedChanges } =\n\t\tuseGlobalStylesRevisions();\n\tconst [ currentlySelectedRevision, setCurrentlySelectedRevision ] =\n\t\tuseState( currentEditorGlobalStyles );\n\tconst [\n\t\tisLoadingRevisionWithUnsavedChanges,\n\t\tsetIsLoadingRevisionWithUnsavedChanges,\n\t] = useState( false );\n\tconst { setEditorCanvasContainerView } = unlock(\n\t\tuseDispatch( editSiteStore )\n\t);\n\tconst selectedRevisionMatchesEditorStyles = areGlobalStyleConfigsEqual(\n\t\tcurrentlySelectedRevision,\n\t\tcurrentEditorGlobalStyles\n\t);\n\n\tconst onCloseRevisions = () => {\n\t\tgoTo( '/' ); // Return to global styles main panel.\n\t\tsetEditorCanvasContainerView( undefined );\n\t};\n\n\tconst restoreRevision = ( revision ) => {\n\t\tsetUserConfig( () => ( {\n\t\t\tstyles: revision?.styles,\n\t\t\tsettings: revision?.settings,\n\t\t} ) );\n\t\tsetIsLoadingRevisionWithUnsavedChanges( false );\n\t\tonCloseRevisions();\n\t};\n\n\tconst selectRevision = ( revision ) => {\n\t\tsetCurrentlySelectedRevision( {\n\t\t\tstyles: revision?.styles || {},\n\t\t\tsettings: revision?.settings || {},\n\t\t\tid: revision?.id,\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( editorCanvasContainerView !== 'global-styles-revisions' ) {\n\t\t\tgoTo( '/' ); // Return to global styles main panel.\n\t\t\tsetEditorCanvasContainerView( editorCanvasContainerView );\n\t\t}\n\t}, [ editorCanvasContainerView ] );\n\n\tconst firstRevision = revisions[ 0 ];\n\tconst currentlySelectedRevisionId = currentlySelectedRevision?.id;\n\tconst shouldSelectFirstItem =\n\t\t!! firstRevision?.id &&\n\t\t! selectedRevisionMatchesEditorStyles &&\n\t\t! currentlySelectedRevisionId;\n\n\tuseEffect( () => {\n\t\t/*\n\t\t * Ensure that the first item is selected and loaded into the preview pane\n\t\t * when no revision is selected and the selected styles don't match the current editor styles.\n\t\t * This is required in case editor styles are changed outside the revisions panel,\n\t\t * e.g., via the reset styles function of useGlobalStylesReset().\n\t\t * See: https://github.com/WordPress/gutenberg/issues/55866\n\t\t */\n\t\tif ( shouldSelectFirstItem ) {\n\t\t\tsetCurrentlySelectedRevision( {\n\t\t\t\tstyles: firstRevision?.styles || {},\n\t\t\t\tsettings: firstRevision?.settings || {},\n\t\t\t\tid: firstRevision?.id,\n\t\t\t} );\n\t\t}\n\t}, [ shouldSelectFirstItem, firstRevision ] );\n\n\t// Only display load button if there is a revision to load,\n\t// and it is different from the current editor styles.\n\tconst isLoadButtonEnabled =\n\t\t!! currentlySelectedRevisionId && ! selectedRevisionMatchesEditorStyles;\n\tconst shouldShowRevisions = ! isLoading && revisions.length;\n\n\treturn (\n\t\t<>\n\t\t\t<ScreenHeader\n\t\t\t\ttitle={\n\t\t\t\t\trevisionsCount &&\n\t\t\t\t\t// translators: %s: number of revisions.\n\t\t\t\t\tsprintf( __( 'Revisions (%s)' ), revisionsCount )\n\t\t\t\t}\n\t\t\t\tdescription={ __(\n\t\t\t\t\t'Click on previously saved styles to preview them. To restore a selected version to the editor, hit \"Apply.\" When you\\'re ready, use the Save button to save your changes.'\n\t\t\t\t) }\n\t\t\t\tonBack={ onCloseRevisions }\n\t\t\t/>\n\t\t\t{ isLoading && (\n\t\t\t\t<Spinner className=\"edit-site-global-styles-screen-revisions__loading\" />\n\t\t\t) }\n\t\t\t{ shouldShowRevisions && (\n\t\t\t\t<>\n\t\t\t\t\t<Revisions\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tuserConfig={ currentlySelectedRevision }\n\t\t\t\t\t\tonClose={ onCloseRevisions }\n\t\t\t\t\t/>\n\t\t\t\t\t<div className=\"edit-site-global-styles-screen-revisions\">\n\t\t\t\t\t\t<RevisionsButtons\n\t\t\t\t\t\t\tonChange={ selectRevision }\n\t\t\t\t\t\t\tselectedRevisionId={ currentlySelectedRevisionId }\n\t\t\t\t\t\t\tuserRevisions={ revisions }\n\t\t\t\t\t\t\tcanApplyRevision={ isLoadButtonEnabled }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ isLoadButtonEnabled && (\n\t\t\t\t\t\t\t<SidebarFixedBottom>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-screen-revisions__button\"\n\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\t! currentlySelectedRevisionId ||\n\t\t\t\t\t\t\t\t\t\tcurrentlySelectedRevisionId ===\n\t\t\t\t\t\t\t\t\t\t\t'unsaved'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tif ( hasUnsavedChanges ) {\n\t\t\t\t\t\t\t\t\t\t\tsetIsLoadingRevisionWithUnsavedChanges(\n\t\t\t\t\t\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\trestoreRevision(\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentlySelectedRevision\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ currentlySelectedRevisionId === 'parent'\n\t\t\t\t\t\t\t\t\t\t? __( 'Reset to defaults' )\n\t\t\t\t\t\t\t\t\t\t: __( 'Apply' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</SidebarFixedBottom>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t\t{ isLoadingRevisionWithUnsavedChanges && (\n\t\t\t\t\t\t<ConfirmDialog\n\t\t\t\t\t\t\tisOpen={ isLoadingRevisionWithUnsavedChanges }\n\t\t\t\t\t\t\tconfirmButtonText={ __( 'Apply' ) }\n\t\t\t\t\t\t\tonConfirm={ () =>\n\t\t\t\t\t\t\t\trestoreRevision( currentlySelectedRevision )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonCancel={ () =>\n\t\t\t\t\t\t\t\tsetIsLoadingRevisionWithUnsavedChanges( false )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Any unsaved changes will be lost when you apply this revision.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</ConfirmDialog>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default ScreenRevisions;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SACCC,MAAM,EACNC,0BAA0B,IAAIC,YAAY,EAC1CC,2BAA2B,IAAIC,aAAa,EAC5CC,OAAO,QACD,uBAAuB;AAC9B,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,UAAU,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACpE,SACCC,WAAW,IAAIC,sBAAsB,EACrCN,KAAK,IAAIO,gBAAgB,QACnB,yBAAyB;;AAEhC;AACA;AACA;AACA,OAAOC,YAAY,MA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,EAAGA,MAAQ;IACjB4C,UAAU,EAAGxB,yBAA2B;IACxCyB,OAAO,EAAGnB;EAAkB,CAC5B,CAAC,EACFY,aAAA;IAAKK,SAAS,EAAC;EAA0C,GACxDL,aAAA,CAAC9C,gBAAgB;IAChBsD,QAAQ,EAAGf,cAAgB;IAC3BgB,kBAAkB,EAAGb,2BAA6B;IAClDc,aAAa,EAAG/B,SAAW;IAC3BgC,gBAAgB,EAAGb;EAAqB,CACxC,CAAC,EACAA,mBAAmB,IACpBE,aAAA,CAACjD,kBAAkB,QAClBiD,aAAA,CAACpE,MAAM;IACNgF,OAAO,EAAC,SAAS;IACjBP,SAAS,EAAC,kDAAkD;IAC5DQ,QAAQ,EACP,CAAEjB,2BAA2B,IAC7BA,2BAA2B,KAC1B,SACD;IACDkB,OAAO,EAAGA,CAAA,KAAM;MACf,IAAKjC,iBAAiB,EAAG;QACxBI,sCAAsC,CACrC,IACD,CAAC;MACF,CAAC,MAAM;QACNI,eAAe,CACdP,yBACD,CAAC;MACF;IACD;EAAG,GAEDc,2BAA2B,KAAK,QAAQ,GACvClE,EAAE,CAAE,mBAAoB,CAAC,GACzBA,EAAE,CAAE,OAAQ,CACR,CACW,CAEjB,CAAC,EACJsD,mCAAmC,IACpCgB,aAAA,CAAChE,aAAa;IACb+E,MAAM,EAAG/B,mCAAqC;IAC9CgC,iBAAiB,EAAGtF,EAAE,CAAE,OAAQ,CAAG;IACnCuF,SAAS,EAAGA,CAAA,KACX5B,eAAe,CAAEP,yBAA0B,CAC3C;IACDoC,QAAQ,EAAGA,CAAA,KACVjC,sCAAsC,CAAE,KAAM;EAC9C,GAECvD,EAAE,CACH,gEACD,CACc,CAEf,CAEF,CAAC;AAEL;AAEA,eAAe2B,eAAe"}
|
|
@@ -7,32 +7,66 @@ import classnames from 'classnames';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
10
|
+
import { __, _n, sprintf } from '@wordpress/i18n';
|
|
11
11
|
import { Button } from '@wordpress/components';
|
|
12
12
|
import { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';
|
|
13
13
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
14
|
import { useSelect } from '@wordpress/data';
|
|
15
|
+
import { useMemo } from '@wordpress/element';
|
|
16
|
+
import { getBlockTypes } from '@wordpress/blocks';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import getRevisionChanges from './get-revision-changes';
|
|
15
22
|
const DAY_IN_MILLISECONDS = 60 * 60 * 1000 * 24;
|
|
23
|
+
const MAX_CHANGES = 7;
|
|
24
|
+
function ChangesSummary({
|
|
25
|
+
revision,
|
|
26
|
+
previousRevision,
|
|
27
|
+
blockNames
|
|
28
|
+
}) {
|
|
29
|
+
const changes = getRevisionChanges(revision, previousRevision, blockNames);
|
|
30
|
+
const changesLength = changes.length;
|
|
31
|
+
if (!changesLength) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Truncate to `n` results if necessary.
|
|
36
|
+
if (changesLength > MAX_CHANGES) {
|
|
37
|
+
const deleteCount = changesLength - MAX_CHANGES;
|
|
38
|
+
const andMoreText = sprintf(
|
|
39
|
+
// translators: %d: number of global styles changes that are not displayed in the UI.
|
|
40
|
+
_n('…and %d more change.', '…and %d more changes.', deleteCount), deleteCount);
|
|
41
|
+
changes.splice(MAX_CHANGES, deleteCount, andMoreText);
|
|
42
|
+
}
|
|
43
|
+
return createElement("span", {
|
|
44
|
+
"data-testid": "global-styles-revision-changes",
|
|
45
|
+
className: "edit-site-global-styles-screen-revisions__changes"
|
|
46
|
+
}, changes.join(', '));
|
|
47
|
+
}
|
|
16
48
|
|
|
17
49
|
/**
|
|
18
50
|
* Returns a button label for the revision.
|
|
19
51
|
*
|
|
20
52
|
* @param {string|number} id A revision object.
|
|
21
|
-
* @param {boolean} isLatest Whether the revision is the most current.
|
|
22
53
|
* @param {string} authorDisplayName Author name.
|
|
23
54
|
* @param {string} formattedModifiedDate Revision modified date formatted.
|
|
55
|
+
* @param {boolean} areStylesEqual Whether the revision matches the current editor styles.
|
|
24
56
|
* @return {string} Translated label.
|
|
25
57
|
*/
|
|
26
|
-
function getRevisionLabel(id,
|
|
58
|
+
function getRevisionLabel(id, authorDisplayName, formattedModifiedDate, areStylesEqual) {
|
|
27
59
|
if ('parent' === id) {
|
|
28
60
|
return __('Reset the styles to the theme defaults');
|
|
29
61
|
}
|
|
30
62
|
if ('unsaved' === id) {
|
|
31
|
-
return sprintf( /* translators: %s author display name */
|
|
63
|
+
return sprintf( /* translators: %s: author display name */
|
|
32
64
|
__('Unsaved changes by %s'), authorDisplayName);
|
|
33
65
|
}
|
|
34
|
-
return
|
|
35
|
-
|
|
66
|
+
return areStylesEqual ? sprintf(
|
|
67
|
+
// translators: %1$s: author display name, %2$s: revision creation date.
|
|
68
|
+
__('Changes saved by %1$s on %2$s. This revision matches current editor styles.'), authorDisplayName, formattedModifiedDate) : sprintf(
|
|
69
|
+
// translators: %1$s: author display name, %2$s: revision creation date.
|
|
36
70
|
__('Changes saved by %1$s on %2$s'), authorDisplayName, formattedModifiedDate);
|
|
37
71
|
}
|
|
38
72
|
|
|
@@ -50,7 +84,8 @@ function getRevisionLabel(id, isLatest, authorDisplayName, formattedModifiedDate
|
|
|
50
84
|
function RevisionsButtons({
|
|
51
85
|
userRevisions,
|
|
52
86
|
selectedRevisionId,
|
|
53
|
-
onChange
|
|
87
|
+
onChange,
|
|
88
|
+
canApplyRevision
|
|
54
89
|
}) {
|
|
55
90
|
const {
|
|
56
91
|
currentThemeName,
|
|
@@ -66,9 +101,18 @@ function RevisionsButtons({
|
|
|
66
101
|
currentUser: getCurrentUser()
|
|
67
102
|
};
|
|
68
103
|
}, []);
|
|
104
|
+
const blockNames = useMemo(() => {
|
|
105
|
+
const blockTypes = getBlockTypes();
|
|
106
|
+
return blockTypes.reduce((accumulator, {
|
|
107
|
+
name,
|
|
108
|
+
title
|
|
109
|
+
}) => {
|
|
110
|
+
accumulator[name] = title;
|
|
111
|
+
return accumulator;
|
|
112
|
+
}, {});
|
|
113
|
+
}, []);
|
|
69
114
|
const dateNowInMs = getDate().getTime();
|
|
70
115
|
const {
|
|
71
|
-
date: dateFormat,
|
|
72
116
|
datetimeAbbreviated
|
|
73
117
|
} = getSettings().formats;
|
|
74
118
|
return createElement("ol", {
|
|
@@ -78,7 +122,6 @@ function RevisionsButtons({
|
|
|
78
122
|
}, userRevisions.map((revision, index) => {
|
|
79
123
|
const {
|
|
80
124
|
id,
|
|
81
|
-
isLatest,
|
|
82
125
|
author,
|
|
83
126
|
modified
|
|
84
127
|
} = revision;
|
|
@@ -87,14 +130,17 @@ function RevisionsButtons({
|
|
|
87
130
|
const revisionAuthor = isUnsaved ? currentUser : author;
|
|
88
131
|
const authorDisplayName = revisionAuthor?.name || __('User');
|
|
89
132
|
const authorAvatar = revisionAuthor?.avatar_urls?.['48'];
|
|
90
|
-
const
|
|
133
|
+
const isFirstItem = index === 0;
|
|
134
|
+
const isSelected = selectedRevisionId ? selectedRevisionId === id : isFirstItem;
|
|
135
|
+
const areStylesEqual = !canApplyRevision && isSelected;
|
|
91
136
|
const isReset = 'parent' === id;
|
|
92
137
|
const modifiedDate = getDate(modified);
|
|
93
|
-
const displayDate = modified && dateNowInMs - modifiedDate.getTime() > DAY_IN_MILLISECONDS ? dateI18n(
|
|
94
|
-
const revisionLabel = getRevisionLabel(id,
|
|
138
|
+
const displayDate = modified && dateNowInMs - modifiedDate.getTime() > DAY_IN_MILLISECONDS ? dateI18n(datetimeAbbreviated, modifiedDate) : humanTimeDiff(modified);
|
|
139
|
+
const revisionLabel = getRevisionLabel(id, authorDisplayName, dateI18n(datetimeAbbreviated, modifiedDate), areStylesEqual);
|
|
95
140
|
return createElement("li", {
|
|
96
141
|
className: classnames('edit-site-global-styles-screen-revisions__revision-item', {
|
|
97
142
|
'is-selected': isSelected,
|
|
143
|
+
'is-active': areStylesEqual,
|
|
98
144
|
'is-reset': isReset
|
|
99
145
|
}),
|
|
100
146
|
key: id
|
|
@@ -104,7 +150,7 @@ function RevisionsButtons({
|
|
|
104
150
|
onClick: () => {
|
|
105
151
|
onChange(revision);
|
|
106
152
|
},
|
|
107
|
-
label: revisionLabel
|
|
153
|
+
"aria-label": revisionLabel
|
|
108
154
|
}, isReset ? createElement("span", {
|
|
109
155
|
className: "edit-site-global-styles-screen-revisions__description"
|
|
110
156
|
}, __('Default styles'), createElement("span", {
|
|
@@ -116,7 +162,11 @@ function RevisionsButtons({
|
|
|
116
162
|
}, __('(Unsaved)')) : createElement("time", {
|
|
117
163
|
className: "edit-site-global-styles-screen-revisions__date",
|
|
118
164
|
dateTime: modified
|
|
119
|
-
}, displayDate), createElement(
|
|
165
|
+
}, displayDate), isSelected && createElement(ChangesSummary, {
|
|
166
|
+
blockNames: blockNames,
|
|
167
|
+
revision: revision,
|
|
168
|
+
previousRevision: index < userRevisions.length ? userRevisions[index + 1] : {}
|
|
169
|
+
}), createElement("span", {
|
|
120
170
|
className: "edit-site-global-styles-screen-revisions__meta"
|
|
121
171
|
}, createElement("img", {
|
|
122
172
|
alt: authorDisplayName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classnames","__","sprintf","Button","dateI18n","getDate","humanTimeDiff","getSettings","store","coreStore","useSelect","DAY_IN_MILLISECONDS","getRevisionLabel","id","isLatest","authorDisplayName","formattedModifiedDate","RevisionsButtons","userRevisions","selectedRevisionId","onChange","currentThemeName","currentUser","select","getCurrentTheme","getCurrentUser","currentTheme","name","rendered","stylesheet","dateNowInMs","getTime","date","dateFormat","datetimeAbbreviated","formats","createElement","className","role","map","revision","index","author","modified","isUnsaved","revisionAuthor","authorAvatar","avatar_urls","isSelected","isReset","modifiedDate","displayDate","revisionLabel","key","disabled","onClick","label","dateTime","alt","src"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\n\nconst DAY_IN_MILLISECONDS = 60 * 60 * 1000 * 24;\n\n/**\n * Returns a button label for the revision.\n *\n * @param {string|number} id A revision object.\n * @param {boolean} isLatest Whether the revision is the most current.\n * @param {string} authorDisplayName Author name.\n * @param {string} formattedModifiedDate Revision modified date formatted.\n * @return {string} Translated label.\n */\nfunction getRevisionLabel(\n\tid,\n\tisLatest,\n\tauthorDisplayName,\n\tformattedModifiedDate\n) {\n\tif ( 'parent' === id ) {\n\t\treturn __( 'Reset the styles to the theme defaults' );\n\t}\n\n\tif ( 'unsaved' === id ) {\n\t\treturn sprintf(\n\t\t\t/* translators: %s author display name */\n\t\t\t__( 'Unsaved changes by %s' ),\n\t\t\tauthorDisplayName\n\t\t);\n\t}\n\n\treturn isLatest\n\t\t? sprintf(\n\t\t\t\t/* translators: %1$s author display name, %2$s: revision creation date */\n\t\t\t\t__( 'Changes saved by %1$s on %2$s (current)' ),\n\t\t\t\tauthorDisplayName,\n\t\t\t\tformattedModifiedDate\n\t\t )\n\t\t: sprintf(\n\t\t\t\t/* translators: %1$s author display name, %2$s: revision creation date */\n\t\t\t\t__( 'Changes saved by %1$s on %2$s' ),\n\t\t\t\tauthorDisplayName,\n\t\t\t\tformattedModifiedDate\n\t\t );\n}\n\n/**\n * Returns a rendered list of revisions buttons.\n *\n * @typedef {Object} props\n * @property {Array<Object>} userRevisions A collection of user revisions.\n * @property {number} selectedRevisionId The id of the currently-selected revision.\n * @property {Function} onChange Callback fired when a revision is selected.\n *\n * @param {props} Component props.\n * @return {JSX.Element} The modal component.\n */\nfunction RevisionsButtons( { userRevisions, selectedRevisionId, onChange } ) {\n\tconst { currentThemeName, currentUser } = useSelect( ( select ) => {\n\t\tconst { getCurrentTheme, getCurrentUser } = select( coreStore );\n\t\tconst currentTheme = getCurrentTheme();\n\t\treturn {\n\t\t\tcurrentThemeName:\n\t\t\t\tcurrentTheme?.name?.rendered || currentTheme?.stylesheet,\n\t\t\tcurrentUser: getCurrentUser(),\n\t\t};\n\t}, [] );\n\tconst dateNowInMs = getDate().getTime();\n\tconst { date: dateFormat, datetimeAbbreviated } = getSettings().formats;\n\n\treturn (\n\t\t<ol\n\t\t\tclassName=\"edit-site-global-styles-screen-revisions__revisions-list\"\n\t\t\taria-label={ __( 'Global styles revisions' ) }\n\t\t\trole=\"group\"\n\t\t>\n\t\t\t{ userRevisions.map( ( revision, index ) => {\n\t\t\t\tconst { id, isLatest, author, modified } = revision;\n\t\t\t\tconst isUnsaved = 'unsaved' === id;\n\t\t\t\t// Unsaved changes are created by the current user.\n\t\t\t\tconst revisionAuthor = isUnsaved ? currentUser : author;\n\t\t\t\tconst authorDisplayName = revisionAuthor?.name || __( 'User' );\n\t\t\t\tconst authorAvatar = revisionAuthor?.avatar_urls?.[ '48' ];\n\t\t\t\tconst isSelected = selectedRevisionId\n\t\t\t\t\t? selectedRevisionId === id\n\t\t\t\t\t: index === 0;\n\t\t\t\tconst isReset = 'parent' === id;\n\t\t\t\tconst modifiedDate = getDate( modified );\n\t\t\t\tconst displayDate =\n\t\t\t\t\tmodified &&\n\t\t\t\t\tdateNowInMs - modifiedDate.getTime() > DAY_IN_MILLISECONDS\n\t\t\t\t\t\t? dateI18n( dateFormat, modifiedDate )\n\t\t\t\t\t\t: humanTimeDiff( modified );\n\t\t\t\tconst revisionLabel = getRevisionLabel(\n\t\t\t\t\tid,\n\t\t\t\t\tisLatest,\n\t\t\t\t\tauthorDisplayName,\n\t\t\t\t\tdateI18n( datetimeAbbreviated, modifiedDate )\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<li\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'edit-site-global-styles-screen-revisions__revision-item',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t'is-selected': isSelected,\n\t\t\t\t\t\t\t\t'is-reset': isReset,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-screen-revisions__revision-button\"\n\t\t\t\t\t\t\tdisabled={ isSelected }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonChange( revision );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tlabel={ revisionLabel }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ isReset ? (\n\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__description\">\n\t\t\t\t\t\t\t\t\t{ __( 'Default styles' ) }\n\t\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__meta\">\n\t\t\t\t\t\t\t\t\t\t{ currentThemeName }\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__description\">\n\t\t\t\t\t\t\t\t\t{ isUnsaved ? (\n\t\t\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__date\">\n\t\t\t\t\t\t\t\t\t\t\t{ __( '(Unsaved)' ) }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<time\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-screen-revisions__date\"\n\t\t\t\t\t\t\t\t\t\t\tdateTime={ modified }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ displayDate }\n\t\t\t\t\t\t\t\t\t\t</time>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__meta\">\n\t\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\t\talt={ authorDisplayName }\n\t\t\t\t\t\t\t\t\t\t\tsrc={ authorAvatar }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t{ authorDisplayName }\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</li>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</ol>\n\t);\n}\n\nexport default RevisionsButtons;\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,QAAQ,EAAEC,OAAO,EAAEC,aAAa,EAAEC,WAAW,QAAQ,iBAAiB;AAC/E,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,SAAS,QAAQ,iBAAiB;AAE3C,MAAMC,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,gBAAgBA,CACxBC,EAAE,EACFC,QAAQ,EACRC,iBAAiB,EACjBC,qBAAqB,EACpB;EACD,IAAK,QAAQ,KAAKH,EAAE,EAAG;IACtB,OAAOZ,EAAE,CAAE,wCAAyC,CAAC;EACtD;EAEA,IAAK,SAAS,KAAKY,EAAE,EAAG;IACvB,OAAOX,OAAO,EACb;IACAD,EAAE,CAAE,uBAAwB,CAAC,EAC7Bc,iBACD,CAAC;EACF;EAEA,OAAOD,QAAQ,GACZZ,OAAO,EACP;EACAD,EAAE,CAAE,yCAA0C,CAAC,EAC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,WAAY,CACb,CAAC,GAEPmC,aAAA;MACCC,SAAS,EAAC,gDAAgD;MAC1DoB,QAAQ,EAAGd;IAAU,GAEnBQ,WACG,CACN,EACDf,aAAA;MAAMC,SAAS,EAAC;IAAgD,GAC/DD,aAAA;MACCsB,GAAG,EAAG3C,iBAAmB;MACzB4C,GAAG,EAAGb;IAAc,CACpB,CAAC,EACA/B,iBACG,CACD,CAEA,CACL,CAAC;EAEP,CAAE,CACC,CAAC;AAEP;AAEA,eAAeE,gBAAgB"}
|
|
1
|
+
{"version":3,"names":["classnames","__","_n","sprintf","Button","dateI18n","getDate","humanTimeDiff","getSettings","store","coreStore","useSelect","useMemo","getBlockTypes","getRevisionChanges","DAY_IN_MILLISECONDS","MAX_CHANGES","ChangesSummary","revision","previousRevision","blockNames","changes","changesLength","length","deleteCount","andMoreText","splice","createElement","className","join","getRevisionLabel","id","authorDisplayName","formattedModifiedDate","areStylesEqual","RevisionsButtons","userRevisions","selectedRevisionId","onChange","canApplyRevision","currentThemeName","currentUser","select","getCurrentTheme","getCurrentUser","currentTheme","name","rendered","stylesheet","blockTypes","reduce","accumulator","title","dateNowInMs","getTime","datetimeAbbreviated","formats","role","map","index","author","modified","isUnsaved","revisionAuthor","authorAvatar","avatar_urls","isFirstItem","isSelected","isReset","modifiedDate","displayDate","revisionLabel","key","disabled","onClick","dateTime","alt","src"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { getBlockTypes } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport getRevisionChanges from './get-revision-changes';\n\nconst DAY_IN_MILLISECONDS = 60 * 60 * 1000 * 24;\nconst MAX_CHANGES = 7;\n\nfunction ChangesSummary( { revision, previousRevision, blockNames } ) {\n\tconst changes = getRevisionChanges(\n\t\trevision,\n\t\tpreviousRevision,\n\t\tblockNames\n\t);\n\tconst changesLength = changes.length;\n\n\tif ( ! changesLength ) {\n\t\treturn null;\n\t}\n\n\t// Truncate to `n` results if necessary.\n\tif ( changesLength > MAX_CHANGES ) {\n\t\tconst deleteCount = changesLength - MAX_CHANGES;\n\t\tconst andMoreText = sprintf(\n\t\t\t// translators: %d: number of global styles changes that are not displayed in the UI.\n\t\t\t_n( '…and %d more change.', '…and %d more changes.', deleteCount ),\n\t\t\tdeleteCount\n\t\t);\n\t\tchanges.splice( MAX_CHANGES, deleteCount, andMoreText );\n\t}\n\n\treturn (\n\t\t<span\n\t\t\tdata-testid=\"global-styles-revision-changes\"\n\t\t\tclassName=\"edit-site-global-styles-screen-revisions__changes\"\n\t\t>\n\t\t\t{ changes.join( ', ' ) }\n\t\t</span>\n\t);\n}\n\n/**\n * Returns a button label for the revision.\n *\n * @param {string|number} id A revision object.\n * @param {string} authorDisplayName Author name.\n * @param {string} formattedModifiedDate Revision modified date formatted.\n * @param {boolean} areStylesEqual Whether the revision matches the current editor styles.\n * @return {string} Translated label.\n */\nfunction getRevisionLabel(\n\tid,\n\tauthorDisplayName,\n\tformattedModifiedDate,\n\tareStylesEqual\n) {\n\tif ( 'parent' === id ) {\n\t\treturn __( 'Reset the styles to the theme defaults' );\n\t}\n\n\tif ( 'unsaved' === id ) {\n\t\treturn sprintf(\n\t\t\t/* translators: %s: author display name */\n\t\t\t__( 'Unsaved changes by %s' ),\n\t\t\tauthorDisplayName\n\t\t);\n\t}\n\n\treturn areStylesEqual\n\t\t? sprintf(\n\t\t\t\t// translators: %1$s: author display name, %2$s: revision creation date.\n\t\t\t\t__(\n\t\t\t\t\t'Changes saved by %1$s on %2$s. This revision matches current editor styles.'\n\t\t\t\t),\n\t\t\t\tauthorDisplayName,\n\t\t\t\tformattedModifiedDate\n\t\t )\n\t\t: sprintf(\n\t\t\t\t// translators: %1$s: author display name, %2$s: revision creation date.\n\t\t\t\t__( 'Changes saved by %1$s on %2$s' ),\n\t\t\t\tauthorDisplayName,\n\t\t\t\tformattedModifiedDate\n\t\t );\n}\n\n/**\n * Returns a rendered list of revisions buttons.\n *\n * @typedef {Object} props\n * @property {Array<Object>} userRevisions A collection of user revisions.\n * @property {number} selectedRevisionId The id of the currently-selected revision.\n * @property {Function} onChange Callback fired when a revision is selected.\n *\n * @param {props} Component props.\n * @return {JSX.Element} The modal component.\n */\nfunction RevisionsButtons( {\n\tuserRevisions,\n\tselectedRevisionId,\n\tonChange,\n\tcanApplyRevision,\n} ) {\n\tconst { currentThemeName, currentUser } = useSelect( ( select ) => {\n\t\tconst { getCurrentTheme, getCurrentUser } = select( coreStore );\n\t\tconst currentTheme = getCurrentTheme();\n\t\treturn {\n\t\t\tcurrentThemeName:\n\t\t\t\tcurrentTheme?.name?.rendered || currentTheme?.stylesheet,\n\t\t\tcurrentUser: getCurrentUser(),\n\t\t};\n\t}, [] );\n\tconst blockNames = useMemo( () => {\n\t\tconst blockTypes = getBlockTypes();\n\t\treturn blockTypes.reduce( ( accumulator, { name, title } ) => {\n\t\t\taccumulator[ name ] = title;\n\t\t\treturn accumulator;\n\t\t}, {} );\n\t}, [] );\n\tconst dateNowInMs = getDate().getTime();\n\tconst { datetimeAbbreviated } = getSettings().formats;\n\n\treturn (\n\t\t<ol\n\t\t\tclassName=\"edit-site-global-styles-screen-revisions__revisions-list\"\n\t\t\taria-label={ __( 'Global styles revisions' ) }\n\t\t\trole=\"group\"\n\t\t>\n\t\t\t{ userRevisions.map( ( revision, index ) => {\n\t\t\t\tconst { id, author, modified } = revision;\n\t\t\t\tconst isUnsaved = 'unsaved' === id;\n\t\t\t\t// Unsaved changes are created by the current user.\n\t\t\t\tconst revisionAuthor = isUnsaved ? currentUser : author;\n\t\t\t\tconst authorDisplayName = revisionAuthor?.name || __( 'User' );\n\t\t\t\tconst authorAvatar = revisionAuthor?.avatar_urls?.[ '48' ];\n\t\t\t\tconst isFirstItem = index === 0;\n\t\t\t\tconst isSelected = selectedRevisionId\n\t\t\t\t\t? selectedRevisionId === id\n\t\t\t\t\t: isFirstItem;\n\t\t\t\tconst areStylesEqual = ! canApplyRevision && isSelected;\n\t\t\t\tconst isReset = 'parent' === id;\n\t\t\t\tconst modifiedDate = getDate( modified );\n\t\t\t\tconst displayDate =\n\t\t\t\t\tmodified &&\n\t\t\t\t\tdateNowInMs - modifiedDate.getTime() > DAY_IN_MILLISECONDS\n\t\t\t\t\t\t? dateI18n( datetimeAbbreviated, modifiedDate )\n\t\t\t\t\t\t: humanTimeDiff( modified );\n\t\t\t\tconst revisionLabel = getRevisionLabel(\n\t\t\t\t\tid,\n\t\t\t\t\tauthorDisplayName,\n\t\t\t\t\tdateI18n( datetimeAbbreviated, modifiedDate ),\n\t\t\t\t\tareStylesEqual\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<li\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'edit-site-global-styles-screen-revisions__revision-item',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t'is-selected': isSelected,\n\t\t\t\t\t\t\t\t'is-active': areStylesEqual,\n\t\t\t\t\t\t\t\t'is-reset': isReset,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-screen-revisions__revision-button\"\n\t\t\t\t\t\t\tdisabled={ isSelected }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonChange( revision );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-label={ revisionLabel }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ isReset ? (\n\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__description\">\n\t\t\t\t\t\t\t\t\t{ __( 'Default styles' ) }\n\t\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__meta\">\n\t\t\t\t\t\t\t\t\t\t{ currentThemeName }\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__description\">\n\t\t\t\t\t\t\t\t\t{ isUnsaved ? (\n\t\t\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__date\">\n\t\t\t\t\t\t\t\t\t\t\t{ __( '(Unsaved)' ) }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<time\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"edit-site-global-styles-screen-revisions__date\"\n\t\t\t\t\t\t\t\t\t\t\tdateTime={ modified }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ displayDate }\n\t\t\t\t\t\t\t\t\t\t</time>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ isSelected && (\n\t\t\t\t\t\t\t\t\t\t<ChangesSummary\n\t\t\t\t\t\t\t\t\t\t\tblockNames={ blockNames }\n\t\t\t\t\t\t\t\t\t\t\trevision={ revision }\n\t\t\t\t\t\t\t\t\t\t\tpreviousRevision={\n\t\t\t\t\t\t\t\t\t\t\t\tindex < userRevisions.length\n\t\t\t\t\t\t\t\t\t\t\t\t\t? userRevisions[ index + 1 ]\n\t\t\t\t\t\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t<span className=\"edit-site-global-styles-screen-revisions__meta\">\n\t\t\t\t\t\t\t\t\t\t<img\n\t\t\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G,CACN,EACCH,UAAU,IACXxC,aAAA,CAACV,cAAc;MACdG,UAAU,EAAGA,UAAY;MACzBF,QAAQ,EAAGA,QAAU;MACrBC,gBAAgB,EACfwC,KAAK,GAAGvB,aAAa,CAACb,MAAM,GACzBa,aAAa,CAAEuB,KAAK,GAAG,CAAC,CAAE,GAC1B,CAAC;IACJ,CACD,CACD,EACDhC,aAAA;MAAMC,SAAS,EAAC;IAAgD,GAC/DD,aAAA;MACCiD,GAAG,EAAG5C,iBAAmB;MACzB6C,GAAG,EAAGb;IAAc,CACpB,CAAC,EACAhC,iBACG,CACD,CAEA,CACL,CAAC;EAEP,CAAE,CACC,CAAC;AAEP;AAEA,eAAeG,gBAAgB"}
|
|
@@ -10,6 +10,7 @@ import { _x, __ } from '@wordpress/i18n';
|
|
|
10
10
|
import { listView, plus, chevronUpDown } from '@wordpress/icons';
|
|
11
11
|
import { Button, ToolbarItem } from '@wordpress/components';
|
|
12
12
|
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
13
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Internal dependencies
|
|
@@ -39,7 +40,6 @@ export default function DocumentTools({
|
|
|
39
40
|
isVisualMode
|
|
40
41
|
} = useSelect(select => {
|
|
41
42
|
const {
|
|
42
|
-
__experimentalGetPreviewDeviceType,
|
|
43
43
|
isInserterOpened,
|
|
44
44
|
isListViewOpened,
|
|
45
45
|
getEditorMode
|
|
@@ -48,7 +48,6 @@ export default function DocumentTools({
|
|
|
48
48
|
getShortcutRepresentation
|
|
49
49
|
} = select(keyboardShortcutsStore);
|
|
50
50
|
return {
|
|
51
|
-
deviceType: __experimentalGetPreviewDeviceType(),
|
|
52
51
|
isInserterOpen: isInserterOpened(),
|
|
53
52
|
isListViewOpen: isListViewOpened(),
|
|
54
53
|
listViewShortcut: getShortcutRepresentation('core/edit-site/toggle-list-view'),
|
|
@@ -56,13 +55,15 @@ export default function DocumentTools({
|
|
|
56
55
|
};
|
|
57
56
|
}, []);
|
|
58
57
|
const {
|
|
59
|
-
__experimentalSetPreviewDeviceType: setPreviewDeviceType,
|
|
60
58
|
setIsInserterOpened,
|
|
61
59
|
setIsListViewOpened
|
|
62
60
|
} = useDispatch(editSiteStore);
|
|
63
61
|
const {
|
|
64
62
|
__unstableSetEditorMode
|
|
65
63
|
} = useDispatch(blockEditorStore);
|
|
64
|
+
const {
|
|
65
|
+
setDeviceType
|
|
66
|
+
} = useDispatch(editorStore);
|
|
66
67
|
const isLargeViewport = useViewportMatch('medium');
|
|
67
68
|
const toggleInserter = useCallback(() => {
|
|
68
69
|
if (isInserterOpen) {
|
|
@@ -108,20 +109,24 @@ export default function DocumentTools({
|
|
|
108
109
|
icon: plus,
|
|
109
110
|
label: showIconLabels ? shortLabel : longLabel,
|
|
110
111
|
showTooltip: !showIconLabels,
|
|
111
|
-
"aria-expanded": isInserterOpen
|
|
112
|
+
"aria-expanded": isInserterOpen,
|
|
113
|
+
size: "compact"
|
|
112
114
|
}), isLargeViewport && createElement(Fragment, null, !hasFixedToolbar && createElement(ToolbarItem, {
|
|
113
115
|
as: ToolSelector,
|
|
114
116
|
showTooltip: !showIconLabels,
|
|
115
117
|
variant: showIconLabels ? 'tertiary' : undefined,
|
|
116
|
-
disabled: !isVisualMode
|
|
118
|
+
disabled: !isVisualMode,
|
|
119
|
+
size: "compact"
|
|
117
120
|
}), createElement(ToolbarItem, {
|
|
118
121
|
as: UndoButton,
|
|
119
122
|
showTooltip: !showIconLabels,
|
|
120
|
-
variant: showIconLabels ? 'tertiary' : undefined
|
|
123
|
+
variant: showIconLabels ? 'tertiary' : undefined,
|
|
124
|
+
size: "compact"
|
|
121
125
|
}), createElement(ToolbarItem, {
|
|
122
126
|
as: RedoButton,
|
|
123
127
|
showTooltip: !showIconLabels,
|
|
124
|
-
variant: showIconLabels ? 'tertiary' : undefined
|
|
128
|
+
variant: showIconLabels ? 'tertiary' : undefined,
|
|
129
|
+
size: "compact"
|
|
125
130
|
}), !isDistractionFree && createElement(ToolbarItem, {
|
|
126
131
|
as: Button,
|
|
127
132
|
className: "edit-site-header-edit-mode__list-view-toggle",
|
|
@@ -135,7 +140,8 @@ export default function DocumentTools({
|
|
|
135
140
|
shortcut: listViewShortcut,
|
|
136
141
|
showTooltip: !showIconLabels,
|
|
137
142
|
variant: showIconLabels ? 'tertiary' : undefined,
|
|
138
|
-
"aria-expanded": isListViewOpen
|
|
143
|
+
"aria-expanded": isListViewOpen,
|
|
144
|
+
size: "compact"
|
|
139
145
|
}), isZoomedOutViewExperimentEnabled && !isDistractionFree && !hasFixedToolbar && createElement(ToolbarItem, {
|
|
140
146
|
as: Button,
|
|
141
147
|
className: "edit-site-header-edit-mode__zoom-out-view-toggle",
|
|
@@ -144,9 +150,10 @@ export default function DocumentTools({
|
|
|
144
150
|
/* translators: button label text should, if possible, be under 16 characters. */,
|
|
145
151
|
label: __('Zoom-out View'),
|
|
146
152
|
onClick: () => {
|
|
147
|
-
|
|
153
|
+
setDeviceType('Desktop');
|
|
148
154
|
__unstableSetEditorMode(isZoomedOutView ? 'edit' : 'zoom-out');
|
|
149
|
-
}
|
|
155
|
+
},
|
|
156
|
+
size: "compact"
|
|
150
157
|
}))));
|
|
151
158
|
}
|
|
152
159
|
//# sourceMappingURL=index.js.map
|