Skip to content

Commit 94b3ad4

Browse files
youknowriadjameskoster
authored andcommitted
Editor: Move the resizing of the editor to the EditorCanvas component (WordPress#61896)
Co-authored-by: youknowriad <[email protected]> Co-authored-by: jameskoster <[email protected]>
1 parent ee5571a commit 94b3ad4

File tree

15 files changed

+313
-308
lines changed

15 files changed

+313
-308
lines changed

packages/block-editor/src/components/block-canvas/style.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@ iframe[name="editor-canvas"] {
44
display: block;
55
background-color: $gray-300;
66
}
7-
8-
9-
iframe[name="editor-canvas"].has-editor-padding {
10-
padding: $grid-unit-30 $grid-unit-30 0;
11-
}

packages/block-editor/src/components/iframe/content.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.block-editor-iframe__body {
2+
position: relative;
3+
}
4+
15
.block-editor-iframe__container {
26
width: 100%;
37
height: 100%;

packages/edit-post/src/components/visual-editor/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import { usePaddingAppender } from './use-padding-appender';
2525
const { EditorCanvas } = unlock( editorPrivateApis );
2626

2727
const isGutenbergPlugin = globalThis.IS_GUTENBERG_PLUGIN ? true : false;
28+
const DESIGN_POST_TYPES = [
29+
'wp_template',
30+
'wp_template_part',
31+
'wp_block',
32+
'wp_navigation',
33+
];
2834

2935
export default function VisualEditor( { styles } ) {
3036
const {
@@ -34,22 +40,25 @@ export default function VisualEditor( { styles } ) {
3440
hasV3BlocksOnly,
3541
isEditingTemplate,
3642
isZoomedOutView,
43+
postType,
3744
} = useSelect( ( select ) => {
3845
const { isFeatureActive } = select( editPostStore );
39-
const { getEditorSettings, getRenderingMode } = select( editorStore );
46+
const { getEditorSettings, getRenderingMode, getCurrentPostType } =
47+
select( editorStore );
4048
const { getBlockTypes } = select( blocksStore );
4149
const { __unstableGetEditorMode } = select( blockEditorStore );
4250
const editorSettings = getEditorSettings();
51+
const _postType = getCurrentPostType();
4352
return {
4453
isWelcomeGuideVisible: isFeatureActive( 'welcomeGuide' ),
4554
renderingMode: getRenderingMode(),
4655
isBlockBasedTheme: editorSettings.__unstableIsBlockBasedTheme,
4756
hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
4857
return type.apiVersion >= 3;
4958
} ),
50-
isEditingTemplate:
51-
select( editorStore ).getCurrentPostType() === 'wp_template',
59+
isEditingTemplate: _postType === 'wp_template',
5260
isZoomedOutView: __unstableGetEditorMode() === 'zoom-out',
61+
postType: _postType,
5362
};
5463
}, [] );
5564
const hasMetaBoxes = useSelect(
@@ -66,7 +75,8 @@ export default function VisualEditor( { styles } ) {
6675
if (
6776
! isZoomedOutView &&
6877
! hasMetaBoxes &&
69-
renderingMode === 'post-only'
78+
renderingMode === 'post-only' &&
79+
! DESIGN_POST_TYPES.includes( postType )
7080
) {
7181
paddingBottom = '40vh';
7282
}

packages/edit-site/src/components/block-editor/editor-canvas.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828

2929
const { EditorCanvas: EditorCanvasRoot } = unlock( editorPrivateApis );
3030

31-
function EditorCanvas( { enableResizing, settings, children, ...props } ) {
31+
function EditorCanvas( { settings, children } ) {
3232
const {
3333
hasBlocks,
3434
isFocusMode,
@@ -109,11 +109,7 @@ function EditorCanvas( { enableResizing, settings, children, ...props } ) {
109109
// Forming a "block formatting context" to prevent margin collapsing.
110110
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context
111111

112-
css: `.is-root-container{display:flow-root;${
113-
// Some themes will have `min-height: 100vh` for the root container,
114-
// which isn't a requirement in auto resize mode.
115-
enableResizing ? 'min-height:0!important;' : ''
116-
}}body{position:relative; ${
112+
css: `body{${
117113
canvasMode === 'view'
118114
? `min-height: 100vh; ${
119115
currentPostIsTrashed ? '' : 'cursor: pointer;'
@@ -122,7 +118,7 @@ function EditorCanvas( { enableResizing, settings, children, ...props } ) {
122118
}}}`,
123119
},
124120
],
125-
[ settings.styles, enableResizing, canvasMode, currentPostIsTrashed ]
121+
[ settings.styles, canvasMode, currentPostIsTrashed ]
126122
);
127123

128124
return (
@@ -136,7 +132,6 @@ function EditorCanvas( { enableResizing, settings, children, ...props } ) {
136132
className: clsx( 'edit-site-visual-editor__editor-canvas', {
137133
'is-focused': isFocused && canvasMode === 'view',
138134
} ),
139-
...props,
140135
...( canvasMode === 'view' ? viewModeIframeProps : {} ),
141136
} }
142137
>

packages/edit-site/src/components/block-editor/site-editor-canvas.js

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,98 +6,41 @@ import clsx from 'clsx';
66
* WordPress dependencies
77
*/
88
import { useSelect } from '@wordpress/data';
9-
import { useViewportMatch, useResizeObserver } from '@wordpress/compose';
10-
import { store as blockEditorStore } from '@wordpress/block-editor';
119

1210
/**
1311
* Internal dependencies
1412
*/
15-
import ResizableEditor from './resizable-editor';
1613
import EditorCanvas from './editor-canvas';
1714
import EditorCanvasContainer from '../editor-canvas-container';
1815
import useSiteEditorSettings from './use-site-editor-settings';
1916
import { store as editSiteStore } from '../../store';
20-
import {
21-
FOCUSABLE_ENTITIES,
22-
NAVIGATION_POST_TYPE,
23-
TEMPLATE_POST_TYPE,
24-
} from '../../utils/constants';
2517
import { unlock } from '../../lock-unlock';
26-
import { privateApis as routerPrivateApis } from '@wordpress/router';
27-
28-
const { useLocation } = unlock( routerPrivateApis );
2918

3019
export default function SiteEditorCanvas() {
31-
const location = useLocation();
32-
const { templateType, isFocusableEntity, isViewMode, isZoomOutMode } =
33-
useSelect( ( select ) => {
34-
const { getEditedPostType, getCanvasMode } = unlock(
35-
select( editSiteStore )
36-
);
37-
const { __unstableGetEditorMode } = select( blockEditorStore );
38-
const _templateType = getEditedPostType();
20+
const { isViewMode } = useSelect( ( select ) => {
21+
const { getCanvasMode } = unlock( select( editSiteStore ) );
3922

40-
return {
41-
templateType: _templateType,
42-
isFocusableEntity: FOCUSABLE_ENTITIES.includes( _templateType ),
43-
isViewMode: getCanvasMode() === 'view',
44-
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
45-
};
46-
}, [] );
47-
const isFocusMode = location.params.focusMode || isFocusableEntity;
48-
const [ resizeObserver, sizes ] = useResizeObserver();
23+
return {
24+
isViewMode: getCanvasMode() === 'view',
25+
};
26+
}, [] );
4927

5028
const settings = useSiteEditorSettings();
5129

52-
const isMobileViewport = useViewportMatch( 'small', '<' );
53-
const enableResizing =
54-
isFocusMode &&
55-
! isViewMode &&
56-
// Disable resizing in mobile viewport.
57-
! isMobileViewport &&
58-
// Dsiable resizing in zoomed-out mode.
59-
! isZoomOutMode &&
60-
// Disable resizing when editing a template in focus mode.
61-
templateType !== TEMPLATE_POST_TYPE;
62-
63-
const isTemplateTypeNavigation = templateType === NAVIGATION_POST_TYPE;
64-
const isNavigationFocusMode = isTemplateTypeNavigation && isFocusMode;
65-
const forceFullHeight = isNavigationFocusMode;
66-
6730
return (
6831
<EditorCanvasContainer.Slot>
6932
{ ( [ editorCanvasView ] ) =>
7033
editorCanvasView ? (
71-
<div className="edit-site-visual-editor is-focus-mode">
34+
<div className="edit-site-visual-editor">
7235
{ editorCanvasView }
7336
</div>
7437
) : (
7538
<div
7639
className={ clsx( 'edit-site-visual-editor', {
77-
'is-focus-mode': isFocusMode || !! editorCanvasView,
7840
'is-view-mode': isViewMode,
7941
} ) }
8042
>
81-
<ResizableEditor
82-
enableResizing={ enableResizing }
83-
height={
84-
sizes.height && ! forceFullHeight
85-
? sizes.height
86-
: '100%'
87-
}
88-
>
89-
<EditorCanvas
90-
enableResizing={ enableResizing }
91-
settings={ settings }
92-
>
93-
{
94-
// Avoid resize listeners when not needed,
95-
// these will trigger unnecessary re-renders
96-
// when animating the iframe width.
97-
enableResizing && resizeObserver
98-
}
99-
</EditorCanvas>
100-
</ResizableEditor>
43+
<EditorCanvas settings={ settings } />
10144
</div>
10245
)
10346
}

packages/edit-site/src/components/block-editor/style.scss

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -40,98 +40,4 @@
4040
outline-offset: calc(-2 * var(--wp-admin-border-width-focus));
4141
}
4242
}
43-
44-
45-
&.is-focus-mode {
46-
.edit-site-layout.is-full-canvas & {
47-
padding: $grid-unit-30;
48-
}
49-
50-
.edit-site-visual-editor__editor-canvas {
51-
max-height: 100%;
52-
}
53-
54-
// To hide the horizontal scrollbar and show the drag handle on the
55-
// left and right of the container.
56-
.components-resizable-box__container {
57-
overflow: visible;
58-
}
59-
}
60-
61-
& > .components-resizable-box__container {
62-
margin: 0 auto;
63-
}
64-
}
65-
66-
.resizable-editor__drag-handle {
67-
position: absolute;
68-
top: 0;
69-
bottom: 0;
70-
padding: 0;
71-
margin: auto 0;
72-
width: $grid-unit-15;
73-
appearance: none;
74-
cursor: ew-resize;
75-
outline: none;
76-
background: none;
77-
border-radius: $radius-block-ui;
78-
border: 0;
79-
80-
&.is-variation-default {
81-
height: 100px;
82-
}
83-
84-
&.is-variation-separator {
85-
height: 100%;
86-
width: $grid-unit-30;
87-
right: 0;
88-
89-
&::after {
90-
width: 2px;
91-
border-radius: 0;
92-
background: transparent;
93-
left: 50%;
94-
transform: translateX(-1px);
95-
right: 0;
96-
transition: all ease 0.2s;
97-
transition-delay: 0.1s;
98-
@include reduce-motion;
99-
}
100-
}
101-
102-
&::after {
103-
position: absolute;
104-
top: $grid-unit-20;
105-
left: $grid-unit-05;
106-
right: 0;
107-
bottom: $grid-unit-20;
108-
content: "";
109-
width: $grid-unit-05;
110-
background-color: rgba($gray-700, 0.4);
111-
border-radius: $radius-block-ui;
112-
}
113-
114-
&.is-left {
115-
// Subtract half of the handle width to properly center.
116-
left: -$grid-unit-20 - math.div($grid-unit-05, 2);
117-
}
118-
119-
&.is-right {
120-
// Subtract half of the handle width to properly center.
121-
right: -$grid-unit-20 - math.div($grid-unit-05, 2);
122-
}
123-
124-
&:hover,
125-
&:focus,
126-
&:active {
127-
opacity: 1;
128-
&::after {
129-
background-color: var(--wp-admin-theme-color);
130-
}
131-
}
132-
133-
&.is-variation-separator:focus::after {
134-
border-radius: $radius-block-ui;
135-
box-shadow: inset 0 0 0 2px var(--wp-admin-theme-color);
136-
}
13743
}

packages/edit-site/src/components/editor-canvas-container/index.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ import { useDispatch, useSelect } from '@wordpress/data';
1313
import { closeSmall } from '@wordpress/icons';
1414
import { useFocusOnMount, useFocusReturn } from '@wordpress/compose';
1515
import { store as preferencesStore } from '@wordpress/preferences';
16-
import { store as editorStore } from '@wordpress/editor';
16+
import {
17+
store as editorStore,
18+
privateApis as editorPrivateApis,
19+
} from '@wordpress/editor';
1720

1821
/**
1922
* Internal dependencies
2023
*/
2124
import { unlock } from '../../lock-unlock';
2225
import { store as editSiteStore } from '../../store';
23-
import ResizableEditor from '../block-editor/resizable-editor';
26+
27+
const { ResizableEditor } = unlock( editorPrivateApis );
2428

2529
/**
2630
* Returns a translated string for the title of the editor canvas container.
@@ -120,25 +124,27 @@ function EditorCanvasContainer( {
120124

121125
return (
122126
<EditorCanvasContainerFill>
123-
<ResizableEditor enableResizing={ enableResizing }>
124-
{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
125-
<section
126-
className="edit-site-editor-canvas-container"
127-
ref={ shouldShowCloseButton ? focusOnMountRef : null }
128-
onKeyDown={ closeOnEscape }
129-
aria-label={ title }
130-
>
131-
{ shouldShowCloseButton && (
132-
<Button
133-
className="edit-site-editor-canvas-container__close-button"
134-
icon={ closeSmall }
135-
label={ closeButtonLabel || __( 'Close' ) }
136-
onClick={ onCloseContainer }
137-
/>
138-
) }
139-
{ childrenWithProps }
140-
</section>
141-
</ResizableEditor>
127+
<div className="edit-site-editor-canvas-container">
128+
<ResizableEditor enableResizing={ enableResizing }>
129+
{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
130+
<section
131+
className="edit-site-editor-canvas-container__section"
132+
ref={ shouldShowCloseButton ? focusOnMountRef : null }
133+
onKeyDown={ closeOnEscape }
134+
aria-label={ title }
135+
>
136+
{ shouldShowCloseButton && (
137+
<Button
138+
className="edit-site-editor-canvas-container__close-button"
139+
icon={ closeSmall }
140+
label={ closeButtonLabel || __( 'Close' ) }
141+
onClick={ onCloseContainer }
142+
/>
143+
) }
144+
{ childrenWithProps }
145+
</section>
146+
</ResizableEditor>
147+
</div>
142148
</EditorCanvasContainerFill>
143149
);
144150
}

packages/edit-site/src/components/editor-canvas-container/style.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
.edit-site-editor-canvas-container {
2+
height: 100%;
3+
4+
.edit-site-layout.is-full-canvas & {
5+
padding: $grid-unit-30 $grid-unit-30 0;
6+
}
7+
}
8+
9+
.edit-site-editor-canvas-container__section {
210
background: $white; // Fallback color, overridden by JavaScript.
311
border-radius: $radius-block-ui;
412
bottom: 0;

0 commit comments

Comments
 (0)