From c30246d51cafc89413ee28be52c0ccddc8a14b06 Mon Sep 17 00:00:00 2001 From: Luis Felipe Zaguini Date: Tue, 15 Oct 2024 20:02:44 -0300 Subject: [PATCH] Access isPreviewMode directly from getSettings instead of through private symbol within RichText block --- .../block-editor/src/components/block-edit/context.js | 1 - .../block-editor/src/components/block-edit/index.js | 3 --- .../block-editor/src/components/rich-text/index.js | 11 ++++++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/block-edit/context.js b/packages/block-editor/src/components/block-edit/context.js index 6bb1861abd0a2b..e8480912a87f03 100644 --- a/packages/block-editor/src/components/block-edit/context.js +++ b/packages/block-editor/src/components/block-edit/context.js @@ -7,7 +7,6 @@ export const mayDisplayControlsKey = Symbol( 'mayDisplayControls' ); export const mayDisplayParentControlsKey = Symbol( 'mayDisplayParentControls' ); export const blockEditingModeKey = Symbol( 'blockEditingMode' ); export const blockBindingsKey = Symbol( 'blockBindings' ); -export const isPreviewModeKey = Symbol( 'isPreviewMode' ); export const DEFAULT_BLOCK_EDIT_CONTEXT = { name: '', diff --git a/packages/block-editor/src/components/block-edit/index.js b/packages/block-editor/src/components/block-edit/index.js index 0c29c0e98b1bfd..38d59f60c9b4e0 100644 --- a/packages/block-editor/src/components/block-edit/index.js +++ b/packages/block-editor/src/components/block-edit/index.js @@ -15,7 +15,6 @@ import { mayDisplayParentControlsKey, blockEditingModeKey, blockBindingsKey, - isPreviewModeKey, } from './context'; import { MultipleUsageWarning } from './multiple-usage-warning'; import { PrivateBlockContext } from '../block-list/private-block-context'; @@ -71,7 +70,6 @@ export default function BlockEdit( { [ mayDisplayParentControlsKey ]: mayDisplayParentControls, [ blockEditingModeKey ]: blockEditingMode, [ blockBindingsKey ]: bindings, - [ isPreviewModeKey ]: isPreviewMode, } ), [ name, @@ -84,7 +82,6 @@ export default function BlockEdit( { mayDisplayParentControls, blockEditingMode, bindings, - isPreviewMode, ] ) } > diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 8a5d99a7eb9f0a..37eef956ed3bb2 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -29,7 +29,7 @@ import { __, sprintf } from '@wordpress/i18n'; */ import { useBlockEditorAutocompleteProps } from '../autocomplete'; import { useBlockEditContext } from '../block-edit'; -import { blockBindingsKey, isPreviewModeKey } from '../block-edit/context'; +import { blockBindingsKey } from '../block-edit/context'; import FormatToolbarContainer from './format-toolbar-container'; import { store as blockEditorStore } from '../../store'; import { useMarkPersistent } from './use-mark-persistent'; @@ -503,8 +503,13 @@ PrivateRichText.isEmpty = ( value ) => { * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md */ const PublicForwardedRichTextContainer = forwardRef( ( props, ref ) => { - const context = useBlockEditContext(); - const isPreviewMode = context[ isPreviewModeKey ]; + const { isPreviewMode } = useSelect( ( select ) => { + const { getSettings } = select( blockEditorStore ); + + return { + isPreviewMode: getSettings().isPreviewMode, + }; + } ); if ( isPreviewMode ) { // Remove all non-content props.