Skip to content

Commit

Permalink
Move StopEditingAsBlocksOnOutsideSelect to Root (#58412)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Feb 15, 2024
1 parent 7063e5e commit eff9877
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,26 @@ const pendingBlockVisibilityUpdatesPerRegistry = new WeakMap();

function Root( { className, ...settings } ) {
const isLargeViewport = useViewportMatch( 'medium' );
const { isOutlineMode, isFocusMode, editorMode } = useSelect(
( select ) => {
const { getSettings, __unstableGetEditorMode } =
select( blockEditorStore );
const { outlineMode, focusMode } = getSettings();
return {
isOutlineMode: outlineMode,
isFocusMode: focusMode,
editorMode: __unstableGetEditorMode(),
};
},
[]
);
const {
isOutlineMode,
isFocusMode,
editorMode,
temporarilyEditingAsBlocks,
} = useSelect( ( select ) => {
const {
getSettings,
__unstableGetEditorMode,
__unstableGetTemporarilyEditingAsBlocks,
} = select( blockEditorStore );
const { outlineMode, focusMode } = getSettings();
return {
isOutlineMode: outlineMode,
isFocusMode: focusMode,
editorMode: __unstableGetEditorMode(),
temporarilyEditingAsBlocks:
__unstableGetTemporarilyEditingAsBlocks(),
};
}, [] );
const registry = useRegistry();
const { setBlockVisibility } = useDispatch( blockEditorStore );

Expand Down Expand Up @@ -115,6 +122,11 @@ function Root( { className, ...settings } ) {
return (
<IntersectionObserver.Provider value={ intersectionObserver }>
<div { ...innerBlocksProps } />
{ !! temporarilyEditingAsBlocks && (
<StopEditingAsBlocksOnOutsideSelect
clientId={ temporarilyEditingAsBlocks }
/>
) }
</IntersectionObserver.Provider>
);
}
Expand Down Expand Up @@ -159,43 +171,36 @@ function Items( {
// function on every render.
const hasAppender = CustomAppender !== false;
const hasCustomAppender = !! CustomAppender;
const {
order,
selectedBlocks,
visibleBlocks,
temporarilyEditingAsBlocks,
shouldRenderAppender,
} = useSelect(
( select ) => {
const {
getBlockOrder,
getSelectedBlockClientId,
getSelectedBlockClientIds,
__unstableGetVisibleBlocks,
__unstableGetTemporarilyEditingAsBlocks,
getTemplateLock,
getBlockEditingMode,
__unstableGetEditorMode,
} = select( blockEditorStore );
const selectedBlockClientId = getSelectedBlockClientId();
return {
order: getBlockOrder( rootClientId ),
selectedBlocks: getSelectedBlockClientIds(),
visibleBlocks: __unstableGetVisibleBlocks(),
temporarilyEditingAsBlocks:
__unstableGetTemporarilyEditingAsBlocks(),
shouldRenderAppender:
hasAppender &&
( hasCustomAppender
? ! getTemplateLock( rootClientId ) &&
getBlockEditingMode( rootClientId ) !== 'disabled' &&
__unstableGetEditorMode() !== 'zoom-out'
: rootClientId === selectedBlockClientId ||
( ! rootClientId && ! selectedBlockClientId ) ),
};
},
[ rootClientId, hasAppender, hasCustomAppender ]
);
const { order, selectedBlocks, visibleBlocks, shouldRenderAppender } =
useSelect(
( select ) => {
const {
getBlockOrder,
getSelectedBlockClientId,
getSelectedBlockClientIds,
__unstableGetVisibleBlocks,
getTemplateLock,
getBlockEditingMode,
__unstableGetEditorMode,
} = select( blockEditorStore );
const selectedBlockClientId = getSelectedBlockClientId();
return {
order: getBlockOrder( rootClientId ),
selectedBlocks: getSelectedBlockClientIds(),
visibleBlocks: __unstableGetVisibleBlocks(),
shouldRenderAppender:
hasAppender &&
( hasCustomAppender
? ! getTemplateLock( rootClientId ) &&
getBlockEditingMode( rootClientId ) !==
'disabled' &&
__unstableGetEditorMode() !== 'zoom-out'
: rootClientId === selectedBlockClientId ||
( ! rootClientId && ! selectedBlockClientId ) ),
};
},
[ rootClientId, hasAppender, hasCustomAppender ]
);

return (
<LayoutProvider value={ layout }>
Expand All @@ -216,11 +221,6 @@ function Items( {
</AsyncModeProvider>
) ) }
{ order.length < 1 && placeholder }
{ !! temporarilyEditingAsBlocks && (
<StopEditingAsBlocksOnOutsideSelect
clientId={ temporarilyEditingAsBlocks }
/>
) }
{ shouldRenderAppender && (
<BlockListAppender
tagName={ __experimentalAppenderTagName }
Expand Down

1 comment on commit eff9877

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in eff9877.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7921408900
📝 Reported issues:

Please sign in to comment.