Skip to content

Commit

Permalink
Access isPreviewMode directly from getSettings instead of through pri…
Browse files Browse the repository at this point in the history
…vate symbol within RichText block
  • Loading branch information
zaguiini committed Oct 15, 2024
1 parent b667808 commit c30246d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/block-editor/src/components/block-edit/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
3 changes: 0 additions & 3 deletions packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -71,7 +70,6 @@ export default function BlockEdit( {
[ mayDisplayParentControlsKey ]: mayDisplayParentControls,
[ blockEditingModeKey ]: blockEditingMode,
[ blockBindingsKey ]: bindings,
[ isPreviewModeKey ]: isPreviewMode,
} ),
[
name,
Expand All @@ -84,7 +82,6 @@ export default function BlockEdit( {
mayDisplayParentControls,
blockEditingMode,
bindings,
isPreviewMode,
]
) }
>
Expand Down
11 changes: 8 additions & 3 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c30246d

Please sign in to comment.