Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Move the BlockCanvas component within the EditorCanvas component #56850

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import {
} from '@wordpress/editor';
import {
BlockTools,
__unstableUseTypewriter as useTypewriter,
__experimentalUseResizeCanvas as useResizeCanvas,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { useRef, useMemo } from '@wordpress/element';
import { __unstableMotion as motion } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { useMergeRefs } from '@wordpress/compose';
import { store as blocksStore } from '@wordpress/blocks';

/**
Expand All @@ -28,9 +25,6 @@ import { store as blocksStore } from '@wordpress/blocks';
import { store as editPostStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { ExperimentalBlockCanvas: BlockCanvas } = unlock(
blockEditorPrivateApis
);
const { EditorCanvas } = unlock( editorPrivateApis );

const isGutenbergPlugin = process.env.IS_GUTENBERG_PLUGIN ? true : false;
Expand Down Expand Up @@ -104,7 +98,6 @@ export default function VisualEditor( { styles } ) {
}

const ref = useRef();
const contentRef = useMergeRefs( [ ref, useTypewriter() ] );

styles = useMemo(
() => [
Expand Down Expand Up @@ -146,25 +139,14 @@ export default function VisualEditor( { styles } ) {
initial={ desktopCanvasStyles }
className={ previewMode }
>
<BlockCanvas
shouldIframe={ isToBeIframed }
contentRef={ contentRef }
<EditorCanvas
ref={ ref }
disableIframe={ isToBeIframed }
styles={ styles }
height="100%"
>
<EditorCanvas
dropZoneElement={
// When iframed, pass in the html element of the iframe to
// ensure the drop zone extends to the edges of the iframe.
isToBeIframed
? ref.current?.parentNode
: ref.current
}
// We should auto-focus the canvas (title) on load.
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ ! isWelcomeGuideVisible }
/>
</BlockCanvas>
// We should auto-focus the canvas (title) on load.
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ ! isWelcomeGuideVisible }
/>
</motion.div>
</motion.div>
</BlockTools>
Expand Down
60 changes: 30 additions & 30 deletions packages/edit-site/src/components/block-editor/editor-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import classnames from 'classnames';
*/
import {
__experimentalUseResizeCanvas as useResizeCanvas,
privateApis as blockEditorPrivateApis,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { ENTER, SPACE } from '@wordpress/keycodes';
import { useState, useEffect } from '@wordpress/element';
import { useState, useEffect, useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { privateApis as editorPrivateApis } from '@wordpress/editor';

Expand All @@ -27,9 +26,6 @@ import {
NAVIGATION_POST_TYPE,
} from '../../utils/constants';

const { ExperimentalBlockCanvas: BlockCanvas } = unlock(
blockEditorPrivateApis
);
const { EditorCanvas: EditorCanvasRoot } = unlock( editorPrivateApis );

function EditorCanvas( {
Expand Down Expand Up @@ -101,9 +97,35 @@ function EditorCanvas( {
? false
: undefined;

const styles = useMemo(
() => [
...settings.styles,
{
// Forming a "block formatting context" to prevent margin collapsing.
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context

css: `.is-root-container{display:flow-root;${
// Some themes will have `min-height: 100vh` for the root container,
// which isn't a requirement in auto resize mode.
enableResizing ? 'min-height:0!important;' : ''
}}body{position:relative; ${
canvasMode === 'view'
? 'cursor: pointer; min-height: 100vh;'
: ''
}}}`,
},
],
[ settings.styles, enableResizing, canvasMode ]
);

return (
<BlockCanvas
height="100%"
<EditorCanvasRoot
ref={ contentRef }
className={ classnames( 'edit-site-editor-canvas__block-list', {
'is-navigation-block': isTemplateTypeNavigation,
} ) }
renderAppender={ showBlockAppender }
styles={ styles }
iframeProps={ {
expand: isZoomOutMode,
scale: isZoomOutMode ? 0.45 : undefined,
Expand All @@ -118,31 +140,9 @@ function EditorCanvas( {
...props,
...( canvasMode === 'view' ? viewModeProps : {} ),
} }
styles={ settings.styles }
contentRef={ contentRef }
>
<style>{
// Forming a "block formatting context" to prevent margin collapsing.
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context
`.is-root-container{display:flow-root;${
// Some themes will have `min-height: 100vh` for the root container,
// which isn't a requirement in auto resize mode.
enableResizing ? 'min-height:0!important;' : ''
}}body{position:relative; ${
canvasMode === 'view'
? 'cursor: pointer; min-height: 100vh;'
: ''
}}}`
}</style>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this style tag to the "styles" object. (we do something similar in the post editor)

<EditorCanvasRoot
dropZoneElement={ contentRef.current?.parentNode }
className={ classnames( 'edit-site-editor-canvas__block-list', {
'is-navigation-block': isTemplateTypeNavigation,
} ) }
renderAppender={ showBlockAppender }
/>
{ children }
</BlockCanvas>
</EditorCanvasRoot>
);
}

Expand Down
Loading
Loading