Skip to content

Commit

Permalink
Reverts first attempt and now tries to harmonize the editor canvas is…
Browse files Browse the repository at this point in the history
…-focus-mode between site and post editors. By "harmonize", I mean use the same approach by driving the padding via a classname `is-focus-mode` on the edit-${site/post}-layout element, not centralize the code. The latter is difficult because the site editor has "modes", such as edit and view, which also affect the styles.

Reverts first attempt and now tries to harmonize the editor canvas is-focus-mode between site and post editors. By "harmonize", I mean use the same approach by driving the padding via a classname `is-focus-mode` on the edit-${site/post}-layout element, not centralize the code. The latter is difficult because the site editor has "modes", such as edit and view, which also affect the styles.
  • Loading branch information
ramonjd committed Feb 1, 2024
1 parent 8851c24 commit 63e4b3f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
7 changes: 0 additions & 7 deletions packages/block-editor/src/components/block-canvas/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,5 @@ iframe[name="editor-canvas"] {
width: 100%;
height: 100%;
display: block;
}

iframe[name="editor-canvas"]:not(.has-editor-padding) {
background-color: $white;
}

iframe[name="editor-canvas"].has-editor-padding {
padding: $grid-unit-60 $grid-unit-60 0;
}
17 changes: 14 additions & 3 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ export default function VisualEditor( { styles } ) {
isBlockBasedTheme,
hasV3BlocksOnly,
isEditingTemplate,
isEditingPattern,
} = useSelect( ( select ) => {
const { isFeatureActive } = select( editPostStore );
const { getEditorSettings, getRenderingMode } = select( editorStore );
const { getEditorSettings, getRenderingMode, getCurrentPostType } =
select( editorStore );
const { getBlockTypes } = select( blocksStore );
const editorSettings = getEditorSettings();
const currentPostType = getCurrentPostType();

return {
isWelcomeGuideVisible: isFeatureActive( 'welcomeGuide' ),
Expand All @@ -44,8 +47,8 @@ export default function VisualEditor( { styles } ) {
hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
return type.apiVersion >= 3;
} ),
isEditingTemplate:
select( editorStore ).getCurrentPostType() === 'wp_template',
isEditingPattern: currentPostType === 'wp_block',
isEditingTemplate: currentPostType === 'wp_template',
};
}, [] );
const hasMetaBoxes = useSelect(
Expand Down Expand Up @@ -83,6 +86,7 @@ export default function VisualEditor( { styles } ) {
<div
className={ classnames( 'edit-post-visual-editor', {
'has-inline-canvas': ! isToBeIframed,
'is-focus-mode': isEditingPattern || isEditingTemplate,
} ) }
>
<EditorCanvas
Expand All @@ -91,6 +95,13 @@ export default function VisualEditor( { styles } ) {
// We should auto-focus the canvas (title) on load.
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ ! isWelcomeGuideVisible }
iframeProps={ {
style: {
background: isEditingPattern
? 'transparent'
: undefined,
},
} }
/>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions packages/edit-post/src/components/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
// as align-items: stretch is inherited by default.Additionally due to older browser's flex height
// interpretation, any percentage value is likely going to cause issues, such as metaboxes overlapping.
// See also https://www.w3.org/TR/CSS22/visudet.html#the-height-property.

// Matches `.is-focus-mode` padding in
// packages/edit-site/src/components/block-editor/style.scss.
&.is-focus-mode {
padding: $grid-unit-60;
}
}

.edit-post-visual-editor__content-area {
Expand Down
8 changes: 0 additions & 8 deletions packages/edit-site/src/components/block-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
// Centralize the editor horizontally (flex-direction is column).
align-items: center;

// Controls height of editor and editor canvas container (style book, global styles revisions previews etc.)
iframe {
display: block;
width: 100%;
height: 100%;
background: $white;
}

.edit-site-visual-editor__editor-canvas {
&.is-focused {
outline: calc(2 * var(--wp-admin-border-width-focus)) solid var(--wp-admin-theme-color);
Expand Down
7 changes: 1 addition & 6 deletions packages/editor/src/components/editor-canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function EditorCanvas( {
wrapperBlockName,
wrapperUniqueId,
deviceType,
showEditorPadding,
} = useSelect( ( select ) => {
const {
getCurrentPostId,
Expand Down Expand Up @@ -139,7 +138,6 @@ function EditorCanvas( {
wrapperBlockName: _wrapperBlockName,
wrapperUniqueId: getCurrentPostId(),
deviceType: getDeviceType(),
showEditorPadding: !! editorSettings.goBack,
};
}, [] );
const { isCleanNewPost } = useSelect( editorStore );
Expand Down Expand Up @@ -305,14 +303,11 @@ function EditorCanvas( {
styles={ styles }
height="100%"
iframeProps={ {
className: classnames( 'editor-canvas__iframe', {
'has-editor-padding': showEditorPadding,
} ),
className: 'editor-canvas__iframe',
...iframeProps,
style: {
...iframeProps?.style,
...deviceStyles,
border: showEditorPadding ? undefined : 0,
},
} }
>
Expand Down

0 comments on commit 63e4b3f

Please sign in to comment.