diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js
index 8429e58419f725..6b3f1b5ce24d2e 100644
--- a/packages/edit-site/src/components/block-editor/index.js
+++ b/packages/edit-site/src/components/block-editor/index.js
@@ -10,6 +10,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { useCallback, useRef } from '@wordpress/element';
import { useEntityBlockEditor } from '@wordpress/core-data';
import {
+ BlockList,
BlockEditorProvider,
__experimentalLinkControl,
BlockInspector,
@@ -32,16 +33,26 @@ import EditTemplatePartMenuButton from '../edit-template-part-menu-button';
import BackButton from './back-button';
import ResizableEditor from './resizable-editor';
+const LAYOUT = {
+ type: 'default',
+ // At the root level of the site editor, no alignments should be allowed.
+ alignments: [],
+};
+
export default function BlockEditor( { setIsInserterOpen } ) {
- const { settings, templateType, page } = useSelect(
+ const { settings, templateType, templateId, page } = useSelect(
( select ) => {
- const { getSettings, getEditedPostType, getPage } = select(
- editSiteStore
- );
+ const {
+ getSettings,
+ getEditedPostType,
+ getEditedPostId,
+ getPage,
+ } = select( editSiteStore );
return {
settings: getSettings( setIsInserterOpen ),
templateType: getEditedPostType(),
+ templateId: getEditedPostId(),
page: getPage(),
};
},
@@ -99,6 +110,8 @@ export default function BlockEditor( { setIsInserterOpen } ) {
+ >
+
+
<__unstableBlockSettingsMenuFirstItem>
{ ( { onClose } ) => (
diff --git a/packages/edit-site/src/components/block-editor/resizable-editor.js b/packages/edit-site/src/components/block-editor/resizable-editor.js
index cfd85615917fcb..7b1e44881e0d18 100644
--- a/packages/edit-site/src/components/block-editor/resizable-editor.js
+++ b/packages/edit-site/src/components/block-editor/resizable-editor.js
@@ -1,21 +1,15 @@
-/**
- * External dependencies
- */
-import { omit } from 'lodash';
-
/**
* WordPress dependencies
*/
import { useState, useEffect, useRef, useCallback } from '@wordpress/element';
import { ResizableBox } from '@wordpress/components';
import {
- BlockList,
__experimentalUseResizeCanvas as useResizeCanvas,
__unstableEditorStyles as EditorStyles,
__unstableIframe as Iframe,
__unstableUseMouseMoveTypingReset as useMouseMoveTypingReset,
} from '@wordpress/block-editor';
-import { useDispatch, useSelect } from '@wordpress/data';
+import { useSelect } from '@wordpress/data';
import { useMergeRefs } from '@wordpress/compose';
/**
@@ -24,14 +18,6 @@ import { useMergeRefs } from '@wordpress/compose';
import { store as editSiteStore } from '../../store';
import ResizeHandle from './resize-handle';
-const LAYOUT = {
- type: 'default',
- // At the root level of the site editor, no alignments should be allowed.
- alignments: [],
-};
-
-const RESPONSIVE_DEVICE = 'responsive';
-
const DEFAULT_STYLES = {
width: '100%',
height: '100%',
@@ -56,34 +42,45 @@ function ResizableEditor( { enableResizing, settings, ...props } ) {
select( editSiteStore ).__experimentalGetPreviewDeviceType(),
[]
);
- const resizedCanvasStyles = useResizeCanvas( deviceType ) ?? DEFAULT_STYLES;
- const previousResizedCanvasStylesRef = useRef( resizedCanvasStyles );
- // Keep the height of the canvas when resizing on each device type.
- const styles =
- deviceType === RESPONSIVE_DEVICE
- ? previousResizedCanvasStylesRef.current
- : resizedCanvasStyles;
- const [ width, setWidth ] = useState( styles.width );
- const {
- __experimentalSetPreviewDeviceType: setPreviewDeviceType,
- } = useDispatch( editSiteStore );
+ const deviceStyles = useResizeCanvas( deviceType );
+ const [ width, setWidth ] = useState( DEFAULT_STYLES.width );
+ const [ height, setHeight ] = useState( DEFAULT_STYLES.height );
const iframeRef = useRef();
const mouseMoveTypingResetRef = useMouseMoveTypingReset();
const ref = useMergeRefs( [ iframeRef, mouseMoveTypingResetRef ] );
useEffect(
- function setWidthWhenDeviceTypeChanged() {
- if ( deviceType !== RESPONSIVE_DEVICE ) {
- setWidth( resizedCanvasStyles.width );
- previousResizedCanvasStylesRef.current = resizedCanvasStyles;
+ function autoResizeIframeHeight() {
+ const iframe = iframeRef.current;
+
+ if ( ! iframe || ! enableResizing ) {
+ return;
}
+
+ const resizeObserver = new iframe.contentWindow.ResizeObserver(
+ () => {
+ setHeight(
+ iframe.contentDocument.querySelector(
+ `.edit-site-block-editor__block-list`
+ ).offsetHeight
+ );
+ }
+ );
+
+ // Observing the rather than the
because the latter
+ // gets destroyed and remounted after initialization in