From 862940cfe3890f684188e5ec3a32c9cf829c5e87 Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Mon, 31 Jul 2023 17:30:04 +0800 Subject: [PATCH 1/2] Fix not expanding pattern in page editor --- packages/block-library/src/pattern/edit.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/pattern/edit.js b/packages/block-library/src/pattern/edit.js index b4900536ec274..824960f90b379 100644 --- a/packages/block-library/src/pattern/edit.js +++ b/packages/block-library/src/pattern/edit.js @@ -9,7 +9,12 @@ import { useBlockProps, } from '@wordpress/block-editor'; -const PatternEdit = ( { attributes, clientId } ) => { +/** + * Internal dependencies + */ +import { unlock } from '../lock-unlock'; + +const PatternEdit = ( { attributes, clientId, rootClientId } ) => { const selectedPattern = useSelect( ( select ) => select( blockEditorStore ).__experimentalGetParsedPattern( @@ -20,6 +25,8 @@ const PatternEdit = ( { attributes, clientId } ) => { const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } = useDispatch( blockEditorStore ); + const { setBlockEditingMode } = unlock( useDispatch( blockEditorStore ) ); + const { getBlockEditingMode } = unlock( useSelect( blockEditorStore ) ); // Run this effect when the component loads. // This adds the Pattern's contents to the post. @@ -38,15 +45,26 @@ const PatternEdit = ( { attributes, clientId } ) => { const clonedBlocks = selectedPattern.blocks.map( ( block ) => cloneBlock( block ) ); + const rootEditingMode = getBlockEditingMode( rootClientId ); + // Temporarily set the root block to default mode to allow replacing the pattern. + // This could happen when the page is disabling edits of non-content blocks. + __unstableMarkNextChangeAsNotPersistent(); + setBlockEditingMode( rootClientId, 'default' ); __unstableMarkNextChangeAsNotPersistent(); replaceBlocks( clientId, clonedBlocks ); + // Restore the root block's original mode. + __unstableMarkNextChangeAsNotPersistent(); + setBlockEditingMode( rootClientId, rootEditingMode ); } ); } }, [ + rootClientId, clientId, selectedPattern?.blocks, __unstableMarkNextChangeAsNotPersistent, replaceBlocks, + getBlockEditingMode, + setBlockEditingMode, ] ); const props = useBlockProps(); From 599ab90dc13ddc355f35c0b2d3dd060a8a977f13 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:38:36 +1000 Subject: [PATCH 2/2] Tweak is descendent of query check --- .../disable-non-page-content-blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/page-content-focus-manager/disable-non-page-content-blocks.js b/packages/edit-site/src/components/page-content-focus-manager/disable-non-page-content-blocks.js index 7b184ff253c7e..eb0c622840a75 100644 --- a/packages/edit-site/src/components/page-content-focus-manager/disable-non-page-content-blocks.js +++ b/packages/edit-site/src/components/page-content-focus-manager/disable-non-page-content-blocks.js @@ -49,7 +49,7 @@ export function useDisableNonPageContentBlocks() { const withDisableNonPageContentBlocks = createHigherOrderComponent( ( BlockEdit ) => ( props ) => { - const isDescendentOfQueryLoop = !! props.context.queryId; + const isDescendentOfQueryLoop = props.context.queryId !== undefined; const isPageContent = PAGE_CONTENT_BLOCK_TYPES.includes( props.name ) && ! isDescendentOfQueryLoop;