diff --git a/apps/full-site-editing/full-site-editing-plugin/full-site-editing/editor/disable-block-settings/index.js b/apps/full-site-editing/full-site-editing-plugin/full-site-editing/editor/disable-block-settings/index.js new file mode 100644 index 0000000000000..558084143c540 --- /dev/null +++ b/apps/full-site-editing/full-site-editing-plugin/full-site-editing/editor/disable-block-settings/index.js @@ -0,0 +1,33 @@ +/* global fullSiteEditing */ + +/** + * External dependencies + */ +import { select, dispatch, subscribe } from '@wordpress/data'; +import { get } from 'lodash'; + +/** + * Removes the block settings panel if the template or post content blocks are selected. + * Since it is not possible to disable the block settings entirely through Gutenberg state, + * we use a hack to deselect the block, which removes the option to change its settings. + * This is also done officially in the core PostTitle block, so there is prior art. + * + * @see https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/post-title/index.js + */ +const unsubscribe = subscribe( () => { + // We don't care about this on the template or post editor + if ( 'page' !== fullSiteEditing.editorPostType ) { + return unsubscribe(); + } + + // Determine which block we have selected: + const selectedBlock = select( 'core/editor' ).getSelectedBlock(); + const blockName = get( selectedBlock, 'name', null ); + + // If we have selected one the template block, deselect it. + // Note: this does not work for post content because you can't + // edit inner blocks if the block is not selected. + if ( 'a8c/template' === blockName ) { + dispatch( 'core/block-editor' ).clearSelectedBlock( blockName ); + } +} ); diff --git a/apps/full-site-editing/full-site-editing-plugin/full-site-editing/editor/index.js b/apps/full-site-editing/full-site-editing-plugin/full-site-editing/editor/index.js index 5caae82f29606..44c929feda65e 100644 --- a/apps/full-site-editing/full-site-editing-plugin/full-site-editing/editor/index.js +++ b/apps/full-site-editing/full-site-editing-plugin/full-site-editing/editor/index.js @@ -4,4 +4,5 @@ import './block-inserter'; import './template-validity-override'; import './image-block-keywords'; +import './disable-block-settings'; import './style.scss';