-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Site Editor: Update to use the EditorInterface component from the editor package. #62146
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,25 +9,12 @@ | |
} | ||
|
||
// Adjust the position of the notices | ||
.edit-post-layout .components-editor-notices__snackbar { | ||
.components-editor-notices__snackbar { | ||
position: fixed; | ||
right: 0; | ||
bottom: 16px; | ||
padding-left: 16px; | ||
padding-right: 16px; | ||
} | ||
|
||
.is-distraction-free { | ||
.components-editor-notices__snackbar { | ||
bottom: 16px; | ||
} | ||
} | ||
|
||
// Adjust the position of the notices when breadcrumbs are present | ||
.has-block-breadcrumbs { | ||
.components-editor-notices__snackbar { | ||
bottom: 40px; | ||
} | ||
bottom: 24px; | ||
padding-left: 24px; | ||
padding-right: 24px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplified the position of the snackbars in the post editor (to be a fixed position like the site editor) |
||
} | ||
|
||
@include editor-left(".edit-post-layout .components-editor-notices__snackbar"); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,3 @@ | ||
// The button element easily inherits styles that are meant for the editor style. | ||
// These rules enhance the specificity to reduce that inheritance. | ||
// This is duplicated in visual-editor. | ||
.edit-site-block-editor__editor-styles-wrapper .components-button { | ||
font-family: $default-font; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This style is already in the editor package (so inherited in the site editor) |
||
font-size: $default-font-size; | ||
padding: 6px 12px; | ||
|
||
&.is-tertiary, | ||
&.has-icon { | ||
padding: 6px; | ||
} | ||
} | ||
|
||
.edit-site-visual-editor { | ||
height: 100%; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This style moved to the specific editor-canvas-container component. It's only useful there. |
||
background-color: $gray-300; | ||
|
||
// Controls height of editor and editor canvas container (style book, global styles revisions previews etc.) | ||
iframe { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
|
||
.edit-site-visual-editor__editor-canvas { | ||
&.is-focused { | ||
outline: calc(2 * var(--wp-admin-border-width-focus)) solid var(--wp-admin-theme-color); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,22 +8,17 @@ import clsx from 'clsx'; | |
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { ENTER, SPACE } from '@wordpress/keycodes'; | ||
import { useState, useEffect, useMemo } from '@wordpress/element'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
store as editorStore, | ||
privateApis as editorPrivateApis, | ||
} from '@wordpress/editor'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
import { store as editSiteStore } from '../../store'; | ||
|
||
const { VisualEditor } = unlock( editorPrivateApis ); | ||
|
||
function EditorCanvas( { settings } ) { | ||
export default function useEditorIframeProps() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly this enables the site editor to have the "click on canvas" behavior that is not present and not needed in the post editor. I wish it could be just an onClick prop to the EditorCanvas component but for now, I just left it as is and just passed down the iframeProps prop. |
||
const { canvasMode, currentPostIsTrashed } = useSelect( ( select ) => { | ||
const { getCanvasMode } = unlock( select( editSiteStore ) ); | ||
|
||
|
@@ -75,36 +70,10 @@ function EditorCanvas( { settings } ) { | |
readonly: true, | ||
}; | ||
|
||
const styles = useMemo( | ||
() => [ | ||
...settings.styles, | ||
{ | ||
// Forming a "block formatting context" to prevent margin collapsing. | ||
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context | ||
|
||
css: `body{${ | ||
canvasMode === 'view' | ||
? `min-height: 100vh; ${ | ||
currentPostIsTrashed ? '' : 'cursor: pointer;' | ||
}` | ||
: '' | ||
}}}`, | ||
}, | ||
], | ||
[ settings.styles, canvasMode, currentPostIsTrashed ] | ||
); | ||
|
||
return ( | ||
<VisualEditor | ||
styles={ styles } | ||
iframeProps={ { | ||
className: clsx( 'edit-site-visual-editor__editor-canvas', { | ||
'is-focused': isFocused && canvasMode === 'view', | ||
} ), | ||
...( canvasMode === 'view' ? viewModeIframeProps : {} ), | ||
} } | ||
/> | ||
); | ||
return { | ||
className: clsx( 'edit-site-visual-editor__editor-canvas', { | ||
'is-focused': isFocused && canvasMode === 'view', | ||
} ), | ||
...( canvasMode === 'view' ? viewModeIframeProps : {} ), | ||
}; | ||
} | ||
|
||
export default EditorCanvas; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
import { Children, cloneElement, useState } from '@wordpress/element'; | ||
import { | ||
Button, | ||
privateApis as componentsPrivateApis, | ||
__experimentalUseSlotFills as useSlotFills, | ||
} from '@wordpress/components'; | ||
import { ESCAPE } from '@wordpress/keycodes'; | ||
|
@@ -24,7 +23,7 @@ import { | |
import { unlock } from '../../lock-unlock'; | ||
import { store as editSiteStore } from '../../store'; | ||
|
||
const { ResizableEditor } = unlock( editorPrivateApis ); | ||
const { EditorContentSlotFill, ResizableEditor } = unlock( editorPrivateApis ); | ||
|
||
/** | ||
* Returns a translated string for the title of the editor canvas container. | ||
|
@@ -45,15 +44,6 @@ function getEditorCanvasContainerTitle( view ) { | |
} | ||
} | ||
|
||
// Creates a private slot fill. | ||
const { createPrivateSlotFill } = unlock( componentsPrivateApis ); | ||
const SLOT_FILL_NAME = 'EditSiteEditorCanvasContainerSlot'; | ||
const { | ||
privateKey, | ||
Slot: EditorCanvasContainerSlot, | ||
Fill: EditorCanvasContainerFill, | ||
} = createPrivateSlotFill( SLOT_FILL_NAME ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The creation and the rendering of the slot has moved to the editor package. So any editor (post or site editor) can decide to actually update the "content" are using a fill. (like we do for style book and style revisions). There are probably better ways to do implement this behavior but I didn't want to change too much here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What do you think? Do you mean in terms of restricting the behavior to the post editor or finding a different way to swap editor content in and out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few thoughts that I have here:
This is to say, in my mind, there are two valid paths forward:
Both of these can be valid, right now, I'm thinking the former is probably better but it's a very loosely held opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for the thorough feedback!
I could see this as an alternative, particularly if we could isolate it to the site editor. I guess we have access to context/edited post in the site editor Editor component. Worth an experiment. I'll create an issue and put it on the backlog. Thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The important feature, at least for global style revisions, was to have a "separate" editor view that could be edited independently of the main editor canvas. So changes could be made to styles etc in the alt. canvas view, and when it closes, the user is returned to the main editor canvas in whatever state they left it. |
||
|
||
function EditorCanvasContainer( { | ||
children, | ||
closeButtonLabel, | ||
|
@@ -123,7 +113,7 @@ function EditorCanvasContainer( { | |
const shouldShowCloseButton = onClose || closeButtonLabel; | ||
|
||
return ( | ||
<EditorCanvasContainerFill> | ||
<EditorContentSlotFill.Fill> | ||
<div className="edit-site-editor-canvas-container"> | ||
<ResizableEditor enableResizing={ enableResizing }> | ||
{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ } | ||
|
@@ -145,14 +135,13 @@ function EditorCanvasContainer( { | |
</section> | ||
</ResizableEditor> | ||
</div> | ||
</EditorCanvasContainerFill> | ||
</EditorContentSlotFill.Fill> | ||
); | ||
} | ||
function useHasEditorCanvasContainer() { | ||
const fills = useSlotFills( privateKey ); | ||
const fills = useSlotFills( EditorContentSlotFill.privateKey ); | ||
return !! fills?.length; | ||
} | ||
|
||
EditorCanvasContainer.Slot = EditorCanvasContainerSlot; | ||
export default EditorCanvasContainer; | ||
export { useHasEditorCanvasContainer, getEditorCanvasContainerTitle }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snackbars need to be rendered only once in the site editor (or the post editor) so I left this responsibility out of the EditorCanvas component for now.