From 536dff22638913bbb1a95cb692a4f0a44cac853c Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 24 Dec 2024 13:08:29 +0800 Subject: [PATCH 1/3] Avoid showing EditTemplate double click notification when in Write Mode --- .../edit-template-blocks-notification.js | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/packages/editor/src/components/visual-editor/edit-template-blocks-notification.js b/packages/editor/src/components/visual-editor/edit-template-blocks-notification.js index bacf1beb1abecd..7132377be5e878 100644 --- a/packages/editor/src/components/visual-editor/edit-template-blocks-notification.js +++ b/packages/editor/src/components/visual-editor/edit-template-blocks-notification.js @@ -3,6 +3,7 @@ */ import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; +import { store as blockEditorStore } from '@wordpress/block-editor'; import { useEffect, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components'; @@ -27,7 +28,12 @@ import { store as editorStore } from '../../store'; * editor iframe canvas. */ export default function EditTemplateBlocksNotification( { contentRef } ) { - const { onNavigateToEntityRecord, templateId } = useSelect( ( select ) => { + const { + onNavigateToEntityRecord, + templateId, + canEditTemplate, + isNavigationMode, + } = useSelect( ( select ) => { const { getEditorSettings, getCurrentTemplateId } = select( editorStore ); @@ -35,26 +41,35 @@ export default function EditTemplateBlocksNotification( { contentRef } ) { onNavigateToEntityRecord: getEditorSettings().onNavigateToEntityRecord, templateId: getCurrentTemplateId(), - }; - }, [] ); - - const canEditTemplate = useSelect( - ( select ) => - !! select( coreStore ).canUser( 'create', { + canEditTemplate: !! select( coreStore ).canUser( 'create', { kind: 'postType', name: 'wp_template', } ), - [] + isNavigationMode: select( blockEditorStore ).isNavigationMode(), + }; + }, [] ); + + if ( ! canEditTemplate || isNavigationMode ) { + return null; + } + + return ( + ); +} +function EditTemplateBlocksDialog( { + contentRef, + onNavigateToEntityRecord, + templateId, +} ) { const [ isDialogOpen, setIsDialogOpen ] = useState( false ); - useEffect( () => { const handleDblClick = ( event ) => { - if ( ! canEditTemplate ) { - return; - } - if ( ! event.target.classList.contains( 'is-root-container' ) || event.target.dataset?.type === 'core/template-part' @@ -73,11 +88,7 @@ export default function EditTemplateBlocksNotification( { contentRef } ) { return () => { canvas?.removeEventListener( 'dblclick', handleDblClick ); }; - }, [ contentRef, canEditTemplate ] ); - - if ( ! canEditTemplate ) { - return null; - } + }, [ contentRef ] ); return ( Date: Tue, 24 Dec 2024 13:20:56 +0800 Subject: [PATCH 2/3] Remove template part double click focus mode editing in Write Mode --- .../src/template-part/edit/inner-blocks.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/template-part/edit/inner-blocks.js b/packages/block-library/src/template-part/edit/inner-blocks.js index 8582caba4cde47..2559fd34ccee5e 100644 --- a/packages/block-library/src/template-part/edit/inner-blocks.js +++ b/packages/block-library/src/template-part/edit/inner-blocks.js @@ -100,9 +100,16 @@ function EditableTemplatePartInnerBlocks( { tagName: TagName, blockProps, } ) { - const onNavigateToEntityRecord = useSelect( - ( select ) => - select( blockEditorStore ).getSettings().onNavigateToEntityRecord, + const { onNavigateToEntityRecord, isNavigationMode } = useSelect( + ( select ) => { + const { getSettings, isNavigationMode: _isNavigationMode } = + select( blockEditorStore ); + return { + onNavigateToEntityRecord: + getSettings().onNavigateToEntityRecord, + isNavigationMode: _isNavigationMode(), + }; + }, [] ); @@ -123,7 +130,9 @@ function EditableTemplatePartInnerBlocks( { const blockEditingMode = useBlockEditingMode(); const customProps = - blockEditingMode === 'contentOnly' && onNavigateToEntityRecord + ! isNavigationMode && + blockEditingMode === 'contentOnly' && + onNavigateToEntityRecord ? { onDoubleClick: () => onNavigateToEntityRecord( { From d1d7d626ed8b306e3bf2b5b5e43ce0de81ae94c3 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 24 Dec 2024 14:23:00 +0800 Subject: [PATCH 3/3] Avoid showing Edit buttons on template part and synced pattern block toolbars when in Write Mode --- packages/block-library/src/block/edit.js | 21 ++++++++++++------- .../src/template-part/edit/index.js | 9 +++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index 3d4d07e52b386a..c4c58f9df6a870 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -111,19 +111,24 @@ function ReusableBlockControl( { handleEditOriginal, resetContent, } ) { - const canUserEdit = useSelect( - ( select ) => - !! select( coreStore ).canUser( 'update', { - kind: 'postType', - name: 'wp_block', - id: recordId, - } ), + const { canUserEdit, isNavigationMode } = useSelect( + ( select ) => { + const { canUser } = select( coreStore ); + return { + canUserEdit: !! canUser( 'update', { + kind: 'postType', + name: 'wp_block', + id: recordId, + } ), + isNavigationMode: select( blockEditorStore ).isNavigationMode(), + }; + }, [ recordId ] ); return ( <> - { canUserEdit && !! handleEditOriginal && ( + { canUserEdit && ! isNavigationMode && !! handleEditOriginal && ( diff --git a/packages/block-library/src/template-part/edit/index.js b/packages/block-library/src/template-part/edit/index.js index ba66ffa673ff87..016145da5ce6b0 100644 --- a/packages/block-library/src/template-part/edit/index.js +++ b/packages/block-library/src/template-part/edit/index.js @@ -126,11 +126,16 @@ export default function TemplatePartEdit( { onNavigateToEntityRecord, title, canUserEdit, + isNavigationMode, } = useSelect( ( select ) => { const { getEditedEntityRecord, hasFinishedResolution } = select( coreStore ); - const { getBlockCount, getSettings } = select( blockEditorStore ); + const { + getBlockCount, + getSettings, + isNavigationMode: _isNavigationMode, + } = select( blockEditorStore ); const getEntityArgs = [ 'postType', @@ -168,6 +173,7 @@ export default function TemplatePartEdit( { getSettings().onNavigateToEntityRecord, title: entityRecord?.title, canUserEdit: !! _canUserEdit, + isNavigationMode: _isNavigationMode(), }; }, [ templatePartId, attributes.area, clientId ] @@ -236,6 +242,7 @@ export default function TemplatePartEdit( { <> { isEntityAvailable && + ! isNavigationMode && onNavigateToEntityRecord && canUserEdit && (