From c379a68e990d8d88cef90fabbfc5c6903197fef4 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 13 Feb 2024 09:54:22 +0100 Subject: [PATCH 1/2] Fix layout for non viewable post types --- .../src/components/editor-canvas/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/components/editor-canvas/index.js b/packages/editor/src/components/editor-canvas/index.js index f011f285644c0..6d7656a47e015 100644 --- a/packages/editor/src/components/editor-canvas/index.js +++ b/packages/editor/src/components/editor-canvas/index.js @@ -93,6 +93,7 @@ function EditorCanvas( { wrapperUniqueId, deviceType, showEditorPadding, + isViewablePostType, } = useSelect( ( select ) => { const { getCurrentPostId, @@ -130,6 +131,7 @@ function EditorCanvas( { return { renderingMode: _renderingMode, postContentAttributes: editorSettings.postContentAttributes, + isViewablePostType: postType?.viewable, // Post template fetch returns a 404 on classic themes, which // messes with e2e tests, so check it's a block theme first. editedPostTemplate: @@ -164,7 +166,7 @@ function EditorCanvas( { // fallbackLayout is used if there is no Post Content, // and for Post Title. const fallbackLayout = useMemo( () => { - if ( renderingMode !== 'post-only' ) { + if ( renderingMode !== 'post-only' || ! isViewablePostType ) { return { type: 'default' }; } @@ -175,7 +177,12 @@ function EditorCanvas( { } // Set default layout for classic themes so all alignments are supported. return { type: 'default' }; - }, [ renderingMode, themeSupportsLayout, globalLayoutSettings ] ); + }, [ + renderingMode, + themeSupportsLayout, + globalLayoutSettings, + isViewablePostType, + ] ); const newestPostContentAttributes = useMemo( () => { if ( @@ -318,7 +325,8 @@ function EditorCanvas( { > { themeSupportsLayout && ! themeHasDisabledLayoutStyles && - renderingMode === 'post-only' && ( + renderingMode === 'post-only' && + isViewablePostType && ( <> ) } - { renderingMode === 'post-only' && ( + { renderingMode === 'post-only' && isViewablePostType && (
Date: Tue, 13 Feb 2024 10:43:31 +0100 Subject: [PATCH 2/2] Use a fixed list of post types --- .../src/components/editor-canvas/index.js | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/editor/src/components/editor-canvas/index.js b/packages/editor/src/components/editor-canvas/index.js index 6d7656a47e015..bc7d54583afbd 100644 --- a/packages/editor/src/components/editor-canvas/index.js +++ b/packages/editor/src/components/editor-canvas/index.js @@ -40,6 +40,17 @@ const { const noop = () => {}; +/** + * These post types have a special editor where they don't allow you to fill the title + * and they don't apply the layout styles. + */ +const DESIGN_POST_TYPES = [ + 'wp_block', + 'wp_template', + 'wp_navigation', + 'wp_template_part', +]; + /** * Given an array of nested blocks, find the first Post Content * block inside it, recursing through any nesting levels, @@ -93,7 +104,7 @@ function EditorCanvas( { wrapperUniqueId, deviceType, showEditorPadding, - isViewablePostType, + isDesignPostType, } = useSelect( ( select ) => { const { getCurrentPostId, @@ -131,7 +142,7 @@ function EditorCanvas( { return { renderingMode: _renderingMode, postContentAttributes: editorSettings.postContentAttributes, - isViewablePostType: postType?.viewable, + isDesignPostType: DESIGN_POST_TYPES.includes( postTypeSlug ), // Post template fetch returns a 404 on classic themes, which // messes with e2e tests, so check it's a block theme first. editedPostTemplate: @@ -166,7 +177,7 @@ function EditorCanvas( { // fallbackLayout is used if there is no Post Content, // and for Post Title. const fallbackLayout = useMemo( () => { - if ( renderingMode !== 'post-only' || ! isViewablePostType ) { + if ( renderingMode !== 'post-only' || isDesignPostType ) { return { type: 'default' }; } @@ -181,7 +192,7 @@ function EditorCanvas( { renderingMode, themeSupportsLayout, globalLayoutSettings, - isViewablePostType, + isDesignPostType, ] ); const newestPostContentAttributes = useMemo( () => { @@ -326,7 +337,7 @@ function EditorCanvas( { { themeSupportsLayout && ! themeHasDisabledLayoutStyles && renderingMode === 'post-only' && - isViewablePostType && ( + ! isDesignPostType && ( <> ) } - { renderingMode === 'post-only' && isViewablePostType && ( + { renderingMode === 'post-only' && ! isDesignPostType && (