diff --git a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-iframe-preview.js b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-iframe-preview.js
index 33feeb7e092ea..ecf7440f4ec24 100644
--- a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-iframe-preview.js
+++ b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-iframe-preview.js
@@ -84,6 +84,7 @@ const BlockFramePreview = ( {
blocks,
settings,
setTimeout = noop,
+ title,
} ) => {
const frameContainerRef = useRef();
const renderedBlocksRef = useRef();
@@ -121,6 +122,31 @@ const BlockFramePreview = ( {
} );
}, [ viewportWidth ] );
+ /*
+ * Temporarily manually set the PostTitle from DOM.
+ * It isn't currently possible to manually force the `` component
+ * to render a title provided as a prop. A Core PR will rectify this (see below).
+ * Until then we use direct DOM manipulation to set the post title.
+ *
+ * See: https://github.com/WordPress/gutenberg/pull/20609/
+ */
+ useEffect( () => {
+ const iframeBody = get( iframeRef, [ 'current', 'contentDocument', 'body' ] );
+ if ( ! iframeBody ) {
+ return;
+ }
+
+ const templateTitle = iframeBody.querySelector(
+ '.editor-post-title .editor-post-title__input'
+ );
+
+ if ( ! templateTitle ) {
+ return;
+ }
+
+ templateTitle.value = title;
+ }, [ recomputeBlockListKey ] );
+
// Populate iFrame styles.
useEffect( () => {
setTimeout( () => {
@@ -183,17 +209,15 @@ const BlockFramePreview = ( {
style={ style }
/>
-
+
- { blocks && blocks.length ? (
-
- ) : null }
+
diff --git a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-preview.js b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-preview.js
index 063cc558c1e44..2f655e3ea61c6 100644
--- a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-preview.js
+++ b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/block-preview.js
@@ -11,6 +11,7 @@
*/
import { BlockEditorProvider, BlockList } from '@wordpress/block-editor';
import { Disabled } from '@wordpress/components';
+import { PostTitle } from '@wordpress/editor';
// Exists as a pass through component to simplify automatted testing of
// components which need to `BlockEditorProvider`. Setting up JSDom to handle
@@ -18,11 +19,16 @@ import { Disabled } from '@wordpress/components';
// Therefore this component exists to simplify mocking out the Block Editor
// when under test conditions.
export default function( { blocks, settings, recomputeBlockListKey } ) {
+ /* eslint-disable wpcalypso/jsx-classname-namespace */
return (
+
);
+ /* eslint-enable wpcalypso/jsx-classname-namespace */
}
diff --git a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/template-selector-preview.js b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/template-selector-preview.js
index 8a30ac60bbb06..2134b2e923c4e 100644
--- a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/template-selector-preview.js
+++ b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/template-selector-preview.js
@@ -10,7 +10,7 @@ import { __ } from '@wordpress/i18n';
*/
import BlockIframePreview from './block-iframe-preview';
-const TemplateSelectorPreview = ( { blocks = [], viewportWidth } ) => {
+const TemplateSelectorPreview = ( { blocks = [], viewportWidth, title } ) => {
const noBlocks = ! blocks.length;
return (
/* eslint-disable wpcalypso/jsx-classname-namespace */
@@ -26,7 +26,7 @@ const TemplateSelectorPreview = ( { blocks = [], viewportWidth } ) => {
{ /* Always render preview iframe to ensure it's ready to populate with Blocks. */
/* Without this some browsers will experience a noticavle delay
/* before Blocks are populated into the iframe. */ }
-
+
/* eslint-enable wpcalypso/jsx-classname-namespace */
);
diff --git a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/index.js b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/index.js
index 59297af7d1f14..764dc69b681e8 100644
--- a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/index.js
+++ b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/index.js
@@ -10,7 +10,7 @@ import { compose } from '@wordpress/compose';
import { Button, Modal, Spinner, IconButton } from '@wordpress/components';
import { withDispatch, withSelect } from '@wordpress/data';
import { Component } from '@wordpress/element';
-import { parse as parseBlocks, createBlock } from '@wordpress/blocks';
+import { parse as parseBlocks } from '@wordpress/blocks';
/**
* Internal dependencies
@@ -43,21 +43,9 @@ class PageTemplateModal extends Component {
getBlocksByTemplateSlugs = memoize( templates =>
reduce(
templates,
- ( prev, { slug, content, title } ) => {
+ ( prev, { slug, content } ) => {
prev[ slug ] = content
- ? [
- /*
- * Let's add the page title as a heading block.
- * It will be remove when inserting the template
- * blocks into the editor.
- */
- createBlock( 'core/heading', {
- content: title,
- align: 'center',
- level: 1,
- } ),
- ...parseBlocks( replacePlaceholders( content, this.props.siteInformation ) ),
- ]
+ ? parseBlocks( replacePlaceholders( content, this.props.siteInformation ) )
: [];
return prev;
},
@@ -175,9 +163,6 @@ class PageTemplateModal extends Component {
// Load content.
const blocks = this.getBlocksForSelection( slug );
- // Let's pull the title before to insert blocks in the editor.
- blocks.shift();
-
// Only overwrite the page title if the template is not one of the Homepage Layouts
const title = isHomepageTemplate ? null : this.getTitleByTemplateSlug( slug );
diff --git a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/styles/starter-page-templates-editor.scss b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/styles/starter-page-templates-editor.scss
index 8e9bddc04b3e8..f644d10279ce2 100644
--- a/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/styles/starter-page-templates-editor.scss
+++ b/apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/styles/starter-page-templates-editor.scss
@@ -381,7 +381,7 @@ body.admin-bar:not( .is-fullscreen-mode ) .page-template-modal-screen-overlay {
.sidebar-modal-opener__warning-options {
float: right;
margin-top: 20px;
-
+
.components-button {
margin-left: 12px;
}
@@ -439,14 +439,14 @@ body.admin-bar:not( .is-fullscreen-mode ) .page-template-modal-screen-overlay {
}
// Manual CSS Overrides. Remove after better solutions are in place.
-
+
// Removes empty paragraph placeholders, i.e. "Write Title..."
[data-type='core/paragraph'] [data-rich-text-placeholder] {
display: none;
}
/*
- * Fixes jetpack .wp-block-jetpack-slideshow styles, as the /wp-content/plugins/jetpack/_inc/blocks/vendors~swiper.[hash].css
+ * Fixes jetpack .wp-block-jetpack-slideshow styles, as the /wp-content/plugins/jetpack/_inc/blocks/vendors~swiper.[hash].css
* file is loaded on block insert, not on page load. After the iframe is grabbing these styles, we can remove this code.
*/
.swiper-wrapper {
@@ -475,9 +475,8 @@ body.admin-bar:not( .is-fullscreen-mode ) .page-template-modal-screen-overlay {
}
}
- // Fixes a rendering bug where the margins of the top/bottom blocks weren't contained in the iframe body
- // For details see issue #39799
- .block-editor-block-list__layout {
- overflow: hidden;
+ // Tweak template title (post-title) component.
+ .block-iframe-preview__template-title {
+ padding-top: 20px;
}
}