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 canvas container: include resizeable iframe in component #50682

Merged
merged 3 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default function BlockEditor() {
const [ resizeObserver, sizes ] = useResizeObserver();

const isTemplatePart = templateType === 'wp_template_part';

const hasBlocks = blocks.length !== 0;
const enableResizing =
isTemplatePart &&
Expand All @@ -169,9 +170,7 @@ export default function BlockEditor() {
{ ( [ editorCanvasView ] ) =>
editorCanvasView ? (
<div className="edit-site-visual-editor is-focus-mode">
<ResizableEditor enableResizing>
{ editorCanvasView }
</ResizableEditor>
{ editorCanvasView }
</div>
) : (
<BlockTools
Expand Down
47 changes: 28 additions & 19 deletions packages/edit-site/src/components/editor-canvas-container/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useFocusOnMount, useFocusReturn } from '@wordpress/compose';
*/
import { unlock } from '../../private-apis';
import { store as editSiteStore } from '../../store';
import ResizableEditor from '../block-editor/resizable-editor';

/**
* Returns a translated string for the title of the editor canvas container.
Expand Down Expand Up @@ -46,7 +47,12 @@ const {
Fill: EditorCanvasContainerFill,
} = createPrivateSlotFill( SLOT_FILL_NAME );

function EditorCanvasContainer( { children, closeButtonLabel, onClose } ) {
function EditorCanvasContainer( {
children,
closeButtonLabel,
onClose,
enableResizing = false,
} ) {
const editorCanvasContainerView = useSelect(
( select ) =>
unlock( select( editSiteStore ) ).getEditorCanvasContainerView(),
Expand All @@ -62,6 +68,7 @@ function EditorCanvasContainer( { children, closeButtonLabel, onClose } ) {
() => getEditorCanvasContainerTitle( editorCanvasContainerView ),
[ editorCanvasContainerView ]
);

function onCloseContainer() {
if ( typeof onClose === 'function' ) {
onClose();
Expand Down Expand Up @@ -97,24 +104,26 @@ function EditorCanvasContainer( { children, closeButtonLabel, onClose } ) {

return (
<EditorCanvasContainerFill>
{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
<section
className="edit-site-editor-canvas-container"
ref={ shouldShowCloseButton ? focusOnMountRef : null }
onKeyDown={ closeOnEscape }
aria-label={ title }
>
{ shouldShowCloseButton && (
<Button
className="edit-site-editor-canvas-container__close-button"
icon={ closeSmall }
label={ closeButtonLabel || __( 'Close' ) }
onClick={ onCloseContainer }
showTooltip={ false }
/>
) }
{ childrenWithProps }
</section>
<ResizableEditor enableResizing={ enableResizing }>
{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
<section
className="edit-site-editor-canvas-container"
ref={ shouldShowCloseButton ? focusOnMountRef : null }
onKeyDown={ closeOnEscape }
aria-label={ title }
>
{ shouldShowCloseButton && (
<Button
className="edit-site-editor-canvas-container__close-button"
icon={ closeSmall }
label={ closeButtonLabel || __( 'Close' ) }
onClick={ onCloseContainer }
showTooltip={ false }
/>
) }
{ childrenWithProps }
</section>
</ResizableEditor>
</EditorCanvasContainerFill>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/components/revisions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function Revisions( { onClose, userConfig, blocks } ) {
title={ __( 'Revisions' ) }
onClose={ onClose }
closeButtonLabel={ __( 'Close revisions' ) }
enableResizing={ true }
>
<Iframe
className="edit-site-revisions__iframe"
Expand Down
5 changes: 4 additions & 1 deletion packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ function StyleBook( { isSelected, onSelect } ) {
);

return (
<EditorCanvasContainer closeButtonLabel={ __( 'Close Style Book' ) }>
<EditorCanvasContainer
enableResizing={ true }
closeButtonLabel={ __( 'Close Style Book' ) }
>
<div
className={ classnames( 'edit-site-style-book', {
'is-wide': sizes.width > 600,
Expand Down