@wordpress/edit-site 5.5.0 → 5.7.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 +4 -0
- package/build/components/add-new-template/new-template-part.js +3 -11
- package/build/components/add-new-template/new-template-part.js.map +1 -1
- package/build/components/add-new-template/new-template.js +23 -17
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +1 -1
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/app/index.js +4 -2
- package/build/components/app/index.js.map +1 -1
- package/build/components/block-editor/editor-canvas.js +7 -9
- package/build/components/block-editor/editor-canvas.js.map +1 -1
- package/build/components/editor/index.js +2 -4
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/border-panel.js +20 -159
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/context-menu.js +4 -6
- package/build/components/global-styles/context-menu.js.map +1 -1
- package/build/components/global-styles/hooks.js +0 -72
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/preview.js +3 -4
- package/build/components/global-styles/preview.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +5 -7
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-border.js +13 -5
- package/build/components/global-styles/screen-border.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +22 -211
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-root.js +2 -1
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/global-styles/screen-style-variations.js +2 -1
- package/build/components/global-styles/screen-style-variations.js.map +1 -1
- package/build/components/global-styles/screen-typography-element.js +4 -0
- package/build/components/global-styles/screen-typography-element.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +5 -0
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/ui.js +5 -35
- package/build/components/global-styles/ui.js.map +1 -1
- package/build/components/global-styles-renderer/index.js +1 -2
- package/build/components/global-styles-renderer/index.js.map +1 -1
- package/build/components/layout/index.js +7 -0
- package/build/components/layout/index.js.map +1 -1
- package/build/components/list/added-by.js +128 -136
- package/build/components/list/added-by.js.map +1 -1
- package/build/components/list/index.js +2 -1
- package/build/components/list/index.js.map +1 -1
- package/build/components/list/table.js +6 -5
- package/build/components/list/table.js.map +1 -1
- package/build/components/routes/link.js +4 -1
- package/build/components/routes/link.js.map +1 -1
- package/build/components/save-button/index.js +2 -5
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/save-hub/index.js +82 -0
- package/build/components/save-hub/index.js.map +1 -0
- package/build/components/secondary-sidebar/list-view-sidebar.js +6 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar/index.js +2 -4
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen/index.js +5 -2
- package/build/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-main/index.js +13 -13
- package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-item/index.js +9 -14
- package/build/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js +87 -10
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +19 -0
- package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
- package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +77 -0
- package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
- package/build/components/sidebar-navigation-screen-template/index.js +59 -10
- package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates/index.js +5 -2
- package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build/components/site-hub/index.js +3 -1
- package/build/components/site-hub/index.js.map +1 -1
- package/build/components/start-template-options/index.js +44 -9
- package/build/components/start-template-options/index.js.map +1 -1
- package/build/components/style-book/index.js +133 -19
- package/build/components/style-book/index.js.map +1 -1
- package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
- package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
- package/build/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
- package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build/components/template-details/index.js +0 -3
- package/build/components/template-details/index.js.map +1 -1
- package/build/components/template-part-converter/convert-to-regular.js +8 -12
- package/build/components/template-part-converter/convert-to-regular.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +2 -2
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/components/template-part-converter/index.js +19 -14
- package/build/components/template-part-converter/index.js.map +1 -1
- package/build/components/use-edited-entity-record/index.js +6 -6
- package/build/components/use-edited-entity-record/index.js.map +1 -1
- package/build/hooks/push-changes-to-global-styles/index.js +1 -0
- package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/utils/history.js +8 -2
- package/build/utils/history.js.map +1 -1
- package/build-module/components/add-new-template/new-template-part.js +3 -9
- package/build-module/components/add-new-template/new-template-part.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +25 -18
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +1 -1
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/app/index.js +3 -2
- package/build-module/components/app/index.js.map +1 -1
- package/build-module/components/block-editor/editor-canvas.js +8 -10
- package/build-module/components/block-editor/editor-canvas.js.map +1 -1
- package/build-module/components/editor/index.js +2 -3
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +21 -157
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/context-menu.js +4 -4
- package/build-module/components/global-styles/context-menu.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +0 -66
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/preview.js +3 -4
- package/build-module/components/global-styles/preview.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +5 -5
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-border.js +11 -2
- package/build-module/components/global-styles/screen-border.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +23 -208
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +2 -1
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/global-styles/screen-style-variations.js +2 -1
- package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
- package/build-module/components/global-styles/screen-typography-element.js +4 -0
- package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +5 -0
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/ui.js +5 -30
- package/build-module/components/global-styles/ui.js.map +1 -1
- package/build-module/components/global-styles-renderer/index.js +1 -2
- package/build-module/components/global-styles-renderer/index.js.map +1 -1
- package/build-module/components/layout/index.js +7 -0
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/list/added-by.js +126 -137
- package/build-module/components/list/added-by.js.map +1 -1
- package/build-module/components/list/index.js +2 -1
- package/build-module/components/list/index.js.map +1 -1
- package/build-module/components/list/table.js +6 -5
- package/build-module/components/list/table.js.map +1 -1
- package/build-module/components/routes/link.js +5 -2
- package/build-module/components/routes/link.js.map +1 -1
- package/build-module/components/save-button/index.js +2 -5
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/save-hub/index.js +68 -0
- package/build-module/components/save-hub/index.js.map +1 -0
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +6 -2
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar/index.js +2 -4
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen/index.js +5 -2
- package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-main/index.js +13 -13
- package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-item/index.js +13 -18
- package/build-module/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +81 -10
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +11 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +66 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-template/index.js +60 -13
- package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates/index.js +5 -2
- package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build-module/components/site-hub/index.js +3 -1
- package/build-module/components/site-hub/index.js.map +1 -1
- package/build-module/components/start-template-options/index.js +45 -10
- package/build-module/components/start-template-options/index.js.map +1 -1
- package/build-module/components/style-book/index.js +133 -21
- package/build-module/components/style-book/index.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
- package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build-module/components/template-details/index.js +0 -3
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-regular.js +9 -13
- package/build-module/components/template-part-converter/convert-to-regular.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +3 -3
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/components/template-part-converter/index.js +20 -15
- package/build-module/components/template-part-converter/index.js.map +1 -1
- package/build-module/components/use-edited-entity-record/index.js +6 -6
- package/build-module/components/use-edited-entity-record/index.js.map +1 -1
- package/build-module/hooks/push-changes-to-global-styles/index.js +1 -0
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build-module/index.js +4 -1
- package/build-module/index.js.map +1 -1
- package/build-module/utils/history.js +9 -3
- package/build-module/utils/history.js.map +1 -1
- package/build-style/style-rtl.css +172 -128
- package/build-style/style.css +172 -128
- package/package.json +31 -31
- package/src/components/add-new-template/new-template-part.js +1 -6
- package/src/components/add-new-template/new-template.js +60 -38
- package/src/components/add-new-template/style.scss +12 -1
- package/src/components/add-new-template/utils.js +1 -1
- package/src/components/app/index.js +9 -6
- package/src/components/block-editor/editor-canvas.js +13 -22
- package/src/components/editor/index.js +61 -65
- package/src/components/global-styles/border-panel.js +24 -199
- package/src/components/global-styles/context-menu.js +4 -4
- package/src/components/global-styles/hooks.js +0 -101
- package/src/components/global-styles/preview.js +1 -1
- package/src/components/global-styles/screen-block-list.js +4 -4
- package/src/components/global-styles/screen-border.js +9 -2
- package/src/components/global-styles/screen-colors.js +25 -229
- package/src/components/global-styles/screen-root.js +1 -1
- package/src/components/global-styles/screen-style-variations.js +5 -1
- package/src/components/global-styles/screen-typography-element.js +4 -0
- package/src/components/global-styles/screen-typography.js +6 -0
- package/src/components/global-styles/stories/index.js +425 -0
- package/src/components/global-styles/style.scss +14 -18
- package/src/components/global-styles/ui.js +6 -31
- package/src/components/global-styles-renderer/index.js +1 -2
- package/src/components/layout/index.js +15 -0
- package/src/components/layout/style.scss +1 -3
- package/src/components/list/added-by.js +144 -140
- package/src/components/list/index.js +3 -1
- package/src/components/list/table.js +7 -4
- package/src/components/routes/link.js +9 -2
- package/src/components/save-button/index.js +2 -2
- package/src/components/save-hub/index.js +78 -0
- package/src/components/save-hub/style.scss +15 -0
- package/src/components/secondary-sidebar/list-view-sidebar.js +4 -3
- package/src/components/sidebar/index.js +2 -3
- package/src/components/sidebar/style.scss +4 -3
- package/src/components/sidebar-button/style.scss +2 -1
- package/src/components/sidebar-navigation-item/style.scss +1 -23
- package/src/components/sidebar-navigation-screen/index.js +6 -0
- package/src/components/sidebar-navigation-screen/style.scss +15 -0
- package/src/components/sidebar-navigation-screen-main/index.js +21 -8
- package/src/components/sidebar-navigation-screen-navigation-item/index.js +30 -21
- package/src/components/sidebar-navigation-screen-navigation-menus/index.js +92 -9
- package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +9 -0
- package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +78 -0
- package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +108 -1
- package/src/components/sidebar-navigation-screen-template/index.js +82 -11
- package/src/components/sidebar-navigation-screen-template/style.scss +25 -0
- package/src/components/sidebar-navigation-screen-templates/index.js +7 -0
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -1
- package/src/components/site-hub/index.js +5 -1
- package/src/components/site-hub/style.scss +5 -1
- package/src/components/start-template-options/index.js +40 -8
- package/src/components/style-book/index.js +203 -54
- package/src/components/style-book/style.scss +2 -46
- package/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +38 -8
- package/src/components/sync-state-with-url/use-sync-path-with-url.js +12 -7
- package/src/components/template-details/index.js +0 -3
- package/src/components/template-part-converter/convert-to-regular.js +10 -17
- package/src/components/template-part-converter/convert-to-template-part.js +9 -16
- package/src/components/template-part-converter/index.js +28 -12
- package/src/components/use-edited-entity-record/index.js +26 -18
- package/src/hooks/push-changes-to-global-styles/index.js +1 -0
- package/src/index.js +5 -1
- package/src/store/test/actions.js +0 -2
- package/src/style.scss +2 -1
- package/src/utils/history.js +13 -9
- package/build/components/global-styles/color-utils.js +0 -17
- package/build/components/global-styles/color-utils.js.map +0 -1
- package/build/components/global-styles/screen-background-color.js +0 -114
- package/build/components/global-styles/screen-background-color.js.map +0 -1
- package/build/components/global-styles/screen-button-color.js +0 -88
- package/build/components/global-styles/screen-button-color.js.map +0 -1
- package/build/components/global-styles/screen-heading-color.js +0 -165
- package/build/components/global-styles/screen-heading-color.js.map +0 -1
- package/build/components/global-styles/screen-link-color.js +0 -105
- package/build/components/global-styles/screen-link-color.js.map +0 -1
- package/build/components/global-styles/screen-text-color.js +0 -71
- package/build/components/global-styles/screen-text-color.js.map +0 -1
- package/build/components/navigation-inspector/index.js +0 -161
- package/build/components/navigation-inspector/index.js.map +0 -1
- package/build/components/navigation-inspector/navigation-menu.js +0 -79
- package/build/components/navigation-inspector/navigation-menu.js.map +0 -1
- package/build-module/components/global-styles/color-utils.js +0 -9
- package/build-module/components/global-styles/color-utils.js.map +0 -1
- package/build-module/components/global-styles/screen-background-color.js +0 -97
- package/build-module/components/global-styles/screen-background-color.js.map +0 -1
- package/build-module/components/global-styles/screen-button-color.js +0 -73
- package/build-module/components/global-styles/screen-button-color.js.map +0 -1
- package/build-module/components/global-styles/screen-heading-color.js +0 -149
- package/build-module/components/global-styles/screen-heading-color.js.map +0 -1
- package/build-module/components/global-styles/screen-link-color.js +0 -89
- package/build-module/components/global-styles/screen-link-color.js.map +0 -1
- package/build-module/components/global-styles/screen-text-color.js +0 -56
- package/build-module/components/global-styles/screen-text-color.js.map +0 -1
- package/build-module/components/navigation-inspector/index.js +0 -146
- package/build-module/components/navigation-inspector/index.js.map +0 -1
- package/build-module/components/navigation-inspector/navigation-menu.js +0 -69
- package/build-module/components/navigation-inspector/navigation-menu.js.map +0 -1
- package/src/components/global-styles/color-utils.js +0 -14
- package/src/components/global-styles/screen-background-color.js +0 -132
- package/src/components/global-styles/screen-button-color.js +0 -104
- package/src/components/global-styles/screen-heading-color.js +0 -206
- package/src/components/global-styles/screen-link-color.js +0 -124
- package/src/components/global-styles/screen-text-color.js +0 -62
- package/src/components/navigation-inspector/index.js +0 -191
- package/src/components/navigation-inspector/navigation-menu.js +0 -84
- package/src/components/navigation-inspector/style.scss +0 -46
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
import { Modal } from '@wordpress/components';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { useState, useEffect, useMemo } from '@wordpress/element';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
__experimentalBlockPatternsList as BlockPatternsList,
|
|
9
|
+
store as blockEditorStore,
|
|
10
|
+
} from '@wordpress/block-editor';
|
|
8
11
|
import { useSelect } from '@wordpress/data';
|
|
9
12
|
import { useAsyncList } from '@wordpress/compose';
|
|
10
13
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
@@ -35,15 +38,40 @@ function useFallbackTemplateContent( slug, isCustom = false ) {
|
|
|
35
38
|
|
|
36
39
|
const START_BLANK_TITLE = __( 'Start blank' );
|
|
37
40
|
|
|
38
|
-
function
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
(
|
|
41
|
+
function useStartPatterns( fallbackContent ) {
|
|
42
|
+
const { slug, patterns } = useSelect( ( select ) => {
|
|
43
|
+
const { getEditedPostType, getEditedPostId } = select( editSiteStore );
|
|
44
|
+
const { getEntityRecord } = select( coreStore );
|
|
45
|
+
const postId = getEditedPostId();
|
|
46
|
+
const postType = getEditedPostType();
|
|
47
|
+
const record = getEntityRecord( 'postType', postType, postId );
|
|
48
|
+
const { getSettings } = select( blockEditorStore );
|
|
49
|
+
return {
|
|
50
|
+
slug: record.slug,
|
|
51
|
+
patterns: getSettings().__experimentalBlockPatterns,
|
|
52
|
+
};
|
|
53
|
+
}, [] );
|
|
54
|
+
|
|
55
|
+
return useMemo( () => {
|
|
56
|
+
// filter patterns that are supposed to be used in the current template being edited.
|
|
57
|
+
return [
|
|
42
58
|
{
|
|
43
59
|
name: 'fallback',
|
|
44
60
|
blocks: parse( fallbackContent ),
|
|
45
61
|
title: __( 'Fallback content' ),
|
|
46
62
|
},
|
|
63
|
+
...patterns
|
|
64
|
+
.filter( ( pattern ) => {
|
|
65
|
+
return (
|
|
66
|
+
Array.isArray( pattern.templateTypes ) &&
|
|
67
|
+
pattern.templateTypes.some( ( templateType ) =>
|
|
68
|
+
slug.startsWith( templateType )
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
} )
|
|
72
|
+
.map( ( pattern ) => {
|
|
73
|
+
return { ...pattern, blocks: parse( pattern.content ) };
|
|
74
|
+
} ),
|
|
47
75
|
{
|
|
48
76
|
name: 'start-blank',
|
|
49
77
|
blocks: parse(
|
|
@@ -51,9 +79,13 @@ function PatternSelection( { fallbackContent, onChoosePattern, postType } ) {
|
|
|
51
79
|
),
|
|
52
80
|
title: START_BLANK_TITLE,
|
|
53
81
|
},
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
|
|
82
|
+
];
|
|
83
|
+
}, [ fallbackContent, slug, patterns ] );
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function PatternSelection( { fallbackContent, onChoosePattern, postType } ) {
|
|
87
|
+
const [ , , onChange ] = useEntityBlockEditor( 'postType', postType );
|
|
88
|
+
const blockPatterns = useStartPatterns( fallbackContent );
|
|
57
89
|
const shownBlockPatterns = useAsyncList( blockPatterns );
|
|
58
90
|
|
|
59
91
|
return (
|
|
@@ -8,6 +8,10 @@ import classnames from 'classnames';
|
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
10
|
Button,
|
|
11
|
+
__unstableComposite as Composite,
|
|
12
|
+
__unstableUseCompositeState as useCompositeState,
|
|
13
|
+
__unstableCompositeItem as CompositeItem,
|
|
14
|
+
Disabled,
|
|
11
15
|
TabPanel,
|
|
12
16
|
createSlotFill,
|
|
13
17
|
__experimentalUseSlotFills as useSlotFills,
|
|
@@ -20,9 +24,13 @@ import {
|
|
|
20
24
|
createBlock,
|
|
21
25
|
} from '@wordpress/blocks';
|
|
22
26
|
import {
|
|
23
|
-
|
|
27
|
+
BlockList,
|
|
24
28
|
privateApis as blockEditorPrivateApis,
|
|
29
|
+
store as blockEditorStore,
|
|
30
|
+
__unstableEditorStyles as EditorStyles,
|
|
31
|
+
__unstableIframe as Iframe,
|
|
25
32
|
} from '@wordpress/block-editor';
|
|
33
|
+
import { useSelect } from '@wordpress/data';
|
|
26
34
|
import { closeSmall } from '@wordpress/icons';
|
|
27
35
|
import {
|
|
28
36
|
useResizeObserver,
|
|
@@ -38,12 +46,84 @@ import { ESCAPE } from '@wordpress/keycodes';
|
|
|
38
46
|
*/
|
|
39
47
|
import { unlock } from '../../private-apis';
|
|
40
48
|
|
|
41
|
-
const { useGlobalStyle } = unlock(
|
|
49
|
+
const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock(
|
|
50
|
+
blockEditorPrivateApis
|
|
51
|
+
);
|
|
42
52
|
|
|
43
53
|
const SLOT_FILL_NAME = 'EditSiteStyleBook';
|
|
44
54
|
const { Slot: StyleBookSlot, Fill: StyleBookFill } =
|
|
45
55
|
createSlotFill( SLOT_FILL_NAME );
|
|
46
56
|
|
|
57
|
+
// The content area of the Style Book is rendered within an iframe so that global styles
|
|
58
|
+
// are applied to elements within the entire content area. To support elements that are
|
|
59
|
+
// not part of the block previews, such as headings and layout for the block previews,
|
|
60
|
+
// additional CSS rules need to be passed into the iframe. These are hard-coded below.
|
|
61
|
+
// Note that button styles are unset, and then focus rules from the `Button` component are
|
|
62
|
+
// applied to the `button` element, targeted via `.edit-site-style-book__example`.
|
|
63
|
+
// This is to ensure that browser default styles for buttons are not applied to the previews.
|
|
64
|
+
const STYLE_BOOK_IFRAME_STYLES = `
|
|
65
|
+
.edit-site-style-book__examples {
|
|
66
|
+
max-width: 900px;
|
|
67
|
+
margin: 0 auto;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.edit-site-style-book__example {
|
|
71
|
+
border-radius: 2px;
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
gap: 40px;
|
|
76
|
+
margin-bottom: 40px;
|
|
77
|
+
padding: 16px;
|
|
78
|
+
width: 100%;
|
|
79
|
+
box-sizing: border-box;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.edit-site-style-book__example.is-selected {
|
|
83
|
+
box-shadow: 0 0 0 1px var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.edit-site-style-book__example:focus:not(:disabled) {
|
|
87
|
+
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
|
|
88
|
+
outline: 3px solid transparent;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.edit-site-style-book__examples.is-wide .edit-site-style-book__example {
|
|
92
|
+
flex-direction: row;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.edit-site-style-book__example-title {
|
|
96
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
97
|
+
font-size: 11px;
|
|
98
|
+
font-weight: 500;
|
|
99
|
+
line-height: normal;
|
|
100
|
+
margin: 0;
|
|
101
|
+
text-align: left;
|
|
102
|
+
text-transform: uppercase;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.edit-site-style-book__examples.is-wide .edit-site-style-book__example-title {
|
|
106
|
+
text-align: right;
|
|
107
|
+
width: 120px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.edit-site-style-book__example-preview {
|
|
111
|
+
width: 100%;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.edit-site-style-book__example-preview .block-editor-block-list__insertion-point,
|
|
115
|
+
.edit-site-style-book__example-preview .block-list-appender {
|
|
116
|
+
display: none;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.edit-site-style-book__example-preview .is-root-container > .wp-block:first-child {
|
|
120
|
+
margin-top: 0;
|
|
121
|
+
}
|
|
122
|
+
.edit-site-style-book__example-preview .is-root-container > .wp-block:last-child {
|
|
123
|
+
margin-bottom: 0;
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
|
|
47
127
|
function getExamples() {
|
|
48
128
|
// Use our own example for the Heading block so that we can show multiple
|
|
49
129
|
// heading levels.
|
|
@@ -118,6 +198,15 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
|
|
|
118
198
|
[ examples ]
|
|
119
199
|
);
|
|
120
200
|
|
|
201
|
+
const originalSettings = useSelect(
|
|
202
|
+
( select ) => select( blockEditorStore ).getSettings(),
|
|
203
|
+
[]
|
|
204
|
+
);
|
|
205
|
+
const settings = useMemo(
|
|
206
|
+
() => ( { ...originalSettings, __unstableIsPreviewMode: true } ),
|
|
207
|
+
[ originalSettings ]
|
|
208
|
+
);
|
|
209
|
+
|
|
121
210
|
function closeOnEscape( event ) {
|
|
122
211
|
if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
|
|
123
212
|
event.preventDefault();
|
|
@@ -156,12 +245,41 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
|
|
|
156
245
|
tabs={ tabs }
|
|
157
246
|
>
|
|
158
247
|
{ ( tab ) => (
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
248
|
+
<Iframe
|
|
249
|
+
className="edit-site-style-book__iframe"
|
|
250
|
+
name="style-book-canvas"
|
|
251
|
+
tabIndex={ 0 }
|
|
252
|
+
>
|
|
253
|
+
<EditorStyles styles={ settings.styles } />
|
|
254
|
+
<style>
|
|
255
|
+
{
|
|
256
|
+
// Forming a "block formatting context" to prevent margin collapsing.
|
|
257
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context
|
|
258
|
+
`.is-root-container { display: flow-root; }
|
|
259
|
+
body { position: relative; padding: 32px !important; }` +
|
|
260
|
+
STYLE_BOOK_IFRAME_STYLES
|
|
261
|
+
}
|
|
262
|
+
</style>
|
|
263
|
+
<Examples
|
|
264
|
+
className={ classnames(
|
|
265
|
+
'edit-site-style-book__examples',
|
|
266
|
+
{
|
|
267
|
+
'is-wide': sizes.width > 600,
|
|
268
|
+
}
|
|
269
|
+
) }
|
|
270
|
+
examples={ examples }
|
|
271
|
+
category={ tab.name }
|
|
272
|
+
label={ sprintf(
|
|
273
|
+
// translators: %s: Category of blocks, e.g. Text.
|
|
274
|
+
__(
|
|
275
|
+
'Examples of blocks in the %s category'
|
|
276
|
+
),
|
|
277
|
+
tab.title
|
|
278
|
+
) }
|
|
279
|
+
isSelected={ isSelected }
|
|
280
|
+
onSelect={ onSelect }
|
|
281
|
+
/>
|
|
282
|
+
</Iframe>
|
|
165
283
|
) }
|
|
166
284
|
</TabPanel>
|
|
167
285
|
</section>
|
|
@@ -169,52 +287,83 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
|
|
|
169
287
|
);
|
|
170
288
|
}
|
|
171
289
|
|
|
172
|
-
const Examples = memo(
|
|
173
|
-
|
|
174
|
-
{
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
290
|
+
const Examples = memo(
|
|
291
|
+
( { className, examples, category, label, isSelected, onSelect } ) => {
|
|
292
|
+
const composite = useCompositeState( { orientation: 'vertical' } );
|
|
293
|
+
return (
|
|
294
|
+
<Composite
|
|
295
|
+
{ ...composite }
|
|
296
|
+
className={ className }
|
|
297
|
+
aria-label={ label }
|
|
298
|
+
>
|
|
299
|
+
{ examples
|
|
300
|
+
.filter( ( example ) => example.category === category )
|
|
301
|
+
.map( ( example ) => (
|
|
302
|
+
<Example
|
|
303
|
+
key={ example.name }
|
|
304
|
+
id={ `example-${ example.name }` }
|
|
305
|
+
composite={ composite }
|
|
306
|
+
title={ example.title }
|
|
307
|
+
blocks={ example.blocks }
|
|
308
|
+
isSelected={ isSelected( example.name ) }
|
|
309
|
+
onClick={ () => {
|
|
310
|
+
onSelect( example.name );
|
|
311
|
+
} }
|
|
312
|
+
/>
|
|
313
|
+
) ) }
|
|
314
|
+
</Composite>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const Example = ( { composite, id, title, blocks, isSelected, onClick } ) => {
|
|
320
|
+
const originalSettings = useSelect(
|
|
321
|
+
( select ) => select( blockEditorStore ).getSettings(),
|
|
322
|
+
[]
|
|
323
|
+
);
|
|
324
|
+
const settings = useMemo(
|
|
325
|
+
() => ( { ...originalSettings, __unstableIsPreviewMode: true } ),
|
|
326
|
+
[ originalSettings ]
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
// Cache the list of blocks to avoid additional processing when the component is re-rendered.
|
|
330
|
+
const renderedBlocks = useMemo(
|
|
331
|
+
() => ( Array.isArray( blocks ) ? blocks : [ blocks ] ),
|
|
332
|
+
[ blocks ]
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
return (
|
|
336
|
+
<CompositeItem
|
|
337
|
+
{ ...composite }
|
|
338
|
+
className={ classnames( 'edit-site-style-book__example', {
|
|
339
|
+
'is-selected': isSelected,
|
|
340
|
+
} ) }
|
|
341
|
+
id={ id }
|
|
342
|
+
aria-label={ sprintf(
|
|
343
|
+
// translators: %s: Title of a block, e.g. Heading.
|
|
344
|
+
__( 'Open %s styles in Styles panel' ),
|
|
345
|
+
title
|
|
346
|
+
) }
|
|
347
|
+
onClick={ onClick }
|
|
348
|
+
role="button"
|
|
349
|
+
as="div"
|
|
350
|
+
>
|
|
351
|
+
<span className="edit-site-style-book__example-title">
|
|
352
|
+
{ title }
|
|
353
|
+
</span>
|
|
354
|
+
<div className="edit-site-style-book__example-preview" aria-hidden>
|
|
355
|
+
<Disabled className="edit-site-style-book__example-preview__content">
|
|
356
|
+
<ExperimentalBlockEditorProvider
|
|
357
|
+
value={ renderedBlocks }
|
|
358
|
+
settings={ settings }
|
|
359
|
+
>
|
|
360
|
+
<BlockList renderAppender={ false } />
|
|
361
|
+
</ExperimentalBlockEditorProvider>
|
|
362
|
+
</Disabled>
|
|
363
|
+
</div>
|
|
364
|
+
</CompositeItem>
|
|
365
|
+
);
|
|
366
|
+
};
|
|
218
367
|
|
|
219
368
|
function useHasStyleBook() {
|
|
220
369
|
const fills = useSlotFills( SLOT_FILL_NAME );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
.edit-site-style-book {
|
|
2
|
-
background: $white; // Fallback color,
|
|
2
|
+
background: $white; // Fallback color, overridden by JavaScript.
|
|
3
3
|
border-radius: $radius-block-ui;
|
|
4
4
|
bottom: 0;
|
|
5
5
|
left: 0;
|
|
@@ -26,53 +26,9 @@
|
|
|
26
26
|
bottom: 0;
|
|
27
27
|
left: 0;
|
|
28
28
|
overflow: auto;
|
|
29
|
-
padding:
|
|
29
|
+
padding: 0;
|
|
30
30
|
position: absolute;
|
|
31
31
|
right: 0;
|
|
32
32
|
top: $grid-unit-60; // Height of tabs.
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
.edit-site-style-book__examples {
|
|
37
|
-
max-width: 900px;
|
|
38
|
-
margin: 0 auto;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.edit-site-style-book__example {
|
|
42
|
-
background: none;
|
|
43
|
-
border-radius: $radius-block-ui;
|
|
44
|
-
border: none;
|
|
45
|
-
color: inherit;
|
|
46
|
-
cursor: pointer;
|
|
47
|
-
display: flex;
|
|
48
|
-
flex-direction: column;
|
|
49
|
-
gap: $grid-unit-50;
|
|
50
|
-
margin-bottom: $grid-unit-50;
|
|
51
|
-
padding: $grid-unit-20;
|
|
52
|
-
width: 100%;
|
|
53
|
-
|
|
54
|
-
&.is-selected {
|
|
55
|
-
box-shadow: 0 0 0 1px var(--wp-admin-theme-color);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.edit-site-style-book.is-wide & {
|
|
59
|
-
flex-direction: row;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.edit-site-style-book__example-title {
|
|
64
|
-
font-size: 11px;
|
|
65
|
-
font-weight: 500;
|
|
66
|
-
margin: 0;
|
|
67
|
-
text-align: left;
|
|
68
|
-
text-transform: uppercase;
|
|
69
|
-
|
|
70
|
-
.edit-site-style-book.is-wide & {
|
|
71
|
-
text-align: right;
|
|
72
|
-
width: 120px;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
.edit-site-style-book__example-preview {
|
|
77
|
-
width: 100%;
|
|
78
|
-
}
|
|
@@ -20,22 +20,52 @@ export default function useSyncCanvasModeWithURL() {
|
|
|
20
20
|
);
|
|
21
21
|
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
|
|
22
22
|
const currentCanvasMode = useRef( canvasMode );
|
|
23
|
-
const { canvas: canvasInUrl
|
|
23
|
+
const { canvas: canvasInUrl } = params;
|
|
24
24
|
const currentCanvasInUrl = useRef( canvasInUrl );
|
|
25
|
+
const currentUrlParams = useRef( params );
|
|
26
|
+
useEffect( () => {
|
|
27
|
+
currentUrlParams.current = params;
|
|
28
|
+
}, [ params ] );
|
|
29
|
+
|
|
25
30
|
useEffect( () => {
|
|
26
31
|
currentCanvasMode.current = canvasMode;
|
|
27
|
-
if (
|
|
32
|
+
if ( canvasMode === 'init' ) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (
|
|
37
|
+
canvasMode === 'edit' &&
|
|
38
|
+
currentCanvasInUrl.current !== canvasMode
|
|
39
|
+
) {
|
|
40
|
+
history.push( {
|
|
41
|
+
...currentUrlParams.current,
|
|
42
|
+
canvas: 'edit',
|
|
43
|
+
} );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
canvasMode === 'view' &&
|
|
48
|
+
currentCanvasInUrl.current !== undefined
|
|
49
|
+
) {
|
|
28
50
|
history.push( {
|
|
29
|
-
...
|
|
30
|
-
canvas:
|
|
51
|
+
...currentUrlParams.current,
|
|
52
|
+
canvas: undefined,
|
|
31
53
|
} );
|
|
32
54
|
}
|
|
33
|
-
}, [ canvasMode ] );
|
|
55
|
+
}, [ canvasMode, history ] );
|
|
34
56
|
|
|
35
57
|
useEffect( () => {
|
|
36
58
|
currentCanvasInUrl.current = canvasInUrl;
|
|
37
|
-
if (
|
|
38
|
-
|
|
59
|
+
if (
|
|
60
|
+
canvasInUrl === undefined &&
|
|
61
|
+
currentCanvasMode.current !== 'view'
|
|
62
|
+
) {
|
|
63
|
+
setCanvasMode( 'view' );
|
|
64
|
+
} else if (
|
|
65
|
+
canvasInUrl === 'edit' &&
|
|
66
|
+
currentCanvasMode.current !== 'edit'
|
|
67
|
+
) {
|
|
68
|
+
setCanvasMode( 'edit' );
|
|
39
69
|
}
|
|
40
|
-
}, [ canvasInUrl ] );
|
|
70
|
+
}, [ canvasInUrl, setCanvasMode ] );
|
|
41
71
|
}
|
|
@@ -41,8 +41,16 @@ export default function useSyncPathWithURL() {
|
|
|
41
41
|
} = useNavigator();
|
|
42
42
|
const currentUrlParams = useRef( urlParams );
|
|
43
43
|
const currentPath = useRef( navigatorLocation.path );
|
|
44
|
+
const isMounting = useRef( true );
|
|
44
45
|
|
|
45
46
|
useEffect( () => {
|
|
47
|
+
// The navigatorParams are only initially filled properly when the
|
|
48
|
+
// navigator screens mount. so we ignore the first synchronisation.
|
|
49
|
+
if ( isMounting.current ) {
|
|
50
|
+
isMounting.current = false;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
function updateUrlParams( newUrlParams ) {
|
|
47
55
|
if (
|
|
48
56
|
Object.entries( newUrlParams ).every( ( [ key, value ] ) => {
|
|
@@ -65,17 +73,14 @@ export default function useSyncPathWithURL() {
|
|
|
65
73
|
postId: navigatorParams?.postId,
|
|
66
74
|
path: undefined,
|
|
67
75
|
} );
|
|
68
|
-
} else if ( navigatorParams?.postType && ! navigatorParams?.postId ) {
|
|
69
|
-
updateUrlParams( {
|
|
70
|
-
postType: navigatorParams?.postType,
|
|
71
|
-
path: navigatorLocation.path,
|
|
72
|
-
postId: undefined,
|
|
73
|
-
} );
|
|
74
76
|
} else {
|
|
75
77
|
updateUrlParams( {
|
|
76
78
|
postType: undefined,
|
|
77
79
|
postId: undefined,
|
|
78
|
-
path:
|
|
80
|
+
path:
|
|
81
|
+
navigatorLocation.path === '/'
|
|
82
|
+
? undefined
|
|
83
|
+
: navigatorLocation.path,
|
|
79
84
|
} );
|
|
80
85
|
}
|
|
81
86
|
}, [ navigatorLocation?.path, navigatorParams, history ] );
|
|
@@ -32,9 +32,6 @@ export default function TemplateDetails( { template, onClose } ) {
|
|
|
32
32
|
|
|
33
33
|
// TODO: We should update this to filter by template part's areas as well.
|
|
34
34
|
const browseAllLinkProps = useLink( {
|
|
35
|
-
canvas: 'view',
|
|
36
|
-
postType: template.type,
|
|
37
|
-
postId: undefined,
|
|
38
35
|
path: '/' + template.type + '/all',
|
|
39
36
|
} );
|
|
40
37
|
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
BlockSettingsMenuControls,
|
|
7
|
-
store as blockEditorStore,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
6
|
import { MenuItem } from '@wordpress/components';
|
|
10
7
|
import { __ } from '@wordpress/i18n';
|
|
11
8
|
|
|
12
|
-
export default function ConvertToRegularBlocks( { clientId } ) {
|
|
9
|
+
export default function ConvertToRegularBlocks( { clientId, onClose } ) {
|
|
13
10
|
const { getBlocks } = useSelect( blockEditorStore );
|
|
14
11
|
const { replaceBlocks } = useDispatch( blockEditorStore );
|
|
15
12
|
|
|
@@ -23,17 +20,13 @@ export default function ConvertToRegularBlocks( { clientId } ) {
|
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
return (
|
|
26
|
-
<
|
|
27
|
-
{ (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{ __( 'Detach blocks from template part' ) }
|
|
35
|
-
</MenuItem>
|
|
36
|
-
) }
|
|
37
|
-
</BlockSettingsMenuControls>
|
|
23
|
+
<MenuItem
|
|
24
|
+
onClick={ () => {
|
|
25
|
+
replaceBlocks( clientId, getBlocks( clientId ) );
|
|
26
|
+
onClose();
|
|
27
|
+
} }
|
|
28
|
+
>
|
|
29
|
+
{ __( 'Detach blocks from template part' ) }
|
|
30
|
+
</MenuItem>
|
|
38
31
|
);
|
|
39
32
|
}
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
6
|
-
BlockSettingsMenuControls,
|
|
7
|
-
store as blockEditorStore,
|
|
8
|
-
} from '@wordpress/block-editor';
|
|
5
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
6
|
import { MenuItem } from '@wordpress/components';
|
|
10
7
|
import { createBlock, serialize } from '@wordpress/blocks';
|
|
11
8
|
import { __ } from '@wordpress/i18n';
|
|
@@ -78,18 +75,14 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) {
|
|
|
78
75
|
|
|
79
76
|
return (
|
|
80
77
|
<>
|
|
81
|
-
<
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
{ __( 'Create Template part' ) }
|
|
90
|
-
</MenuItem>
|
|
91
|
-
) }
|
|
92
|
-
</BlockSettingsMenuControls>
|
|
78
|
+
<MenuItem
|
|
79
|
+
icon={ symbolFilled }
|
|
80
|
+
onClick={ () => {
|
|
81
|
+
setIsModalOpen( true );
|
|
82
|
+
} }
|
|
83
|
+
>
|
|
84
|
+
{ __( 'Create Template part' ) }
|
|
85
|
+
</MenuItem>
|
|
93
86
|
{ isModalOpen && (
|
|
94
87
|
<CreateTemplatePartModal
|
|
95
88
|
closeModal={ () => {
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
BlockSettingsMenuControls,
|
|
7
|
+
store as blockEditorStore,
|
|
8
|
+
} from '@wordpress/block-editor';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Internal dependencies
|
|
@@ -11,20 +14,33 @@ import ConvertToRegularBlocks from './convert-to-regular';
|
|
|
11
14
|
import ConvertToTemplatePart from './convert-to-template-part';
|
|
12
15
|
|
|
13
16
|
export default function TemplatePartConverter() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
return (
|
|
18
|
+
<BlockSettingsMenuControls>
|
|
19
|
+
{ ( { selectedClientIds, onClose } ) => (
|
|
20
|
+
<TemplatePartConverterMenuItem
|
|
21
|
+
clientIds={ selectedClientIds }
|
|
22
|
+
onClose={ onClose }
|
|
23
|
+
/>
|
|
24
|
+
) }
|
|
25
|
+
</BlockSettingsMenuControls>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function TemplatePartConverterMenuItem( { clientIds, onClose } ) {
|
|
30
|
+
const blocks = useSelect(
|
|
31
|
+
( select ) =>
|
|
32
|
+
select( blockEditorStore ).getBlocksByClientId( clientIds ),
|
|
33
|
+
[ clientIds ]
|
|
34
|
+
);
|
|
23
35
|
|
|
24
36
|
// Allow converting a single template part to standard blocks.
|
|
25
37
|
if ( blocks.length === 1 && blocks[ 0 ]?.name === 'core/template-part' ) {
|
|
26
|
-
return
|
|
38
|
+
return (
|
|
39
|
+
<ConvertToRegularBlocks
|
|
40
|
+
clientId={ clientIds[ 0 ] }
|
|
41
|
+
onClose={ onClose }
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
27
44
|
}
|
|
28
|
-
|
|
29
45
|
return <ConvertToTemplatePart clientIds={ clientIds } blocks={ blocks } />;
|
|
30
46
|
}
|