Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add support for view canvas mode
  • Loading branch information
tyxla committed Apr 25, 2023
commit 85b1deb4feb017fef31129f533f996b3aed8eb0a
44 changes: 33 additions & 11 deletions packages/block-editor/src/components/loading-screen/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classNames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -34,11 +39,16 @@ const SuspenseDataDependency = ( { store, selector, args = [] } ) => {
* Component that will render a loading screen if dependencies have not resolved,
* or its children if all dependencies have resolved.
*
* @param {Object} props Component props
* @param {Array} props.dataDependencies Array of dependencies
* @param {string} props.children Component children
* @param {Object} props Component props
* @param {Array} props.dataDependencies Array of dependencies
* @param {string} props.children Component children
* @param {string?} props.overlayClassName Additional overlay classname
*/
const SuspenseWithLoadingScreen = ( { dataDependencies, children } ) => {
const SuspenseWithLoadingScreen = ( {
dataDependencies,
children,
overlayClassName,
} ) => {
const [ loaded, setLoaded ] = useState( false );

const finishedLoading = () => {
Expand All @@ -51,12 +61,20 @@ const SuspenseWithLoadingScreen = ( { dataDependencies, children } ) => {
<LoadingScreenContext.Provider value={ loaded }>
{ loaded ? (
<>
<LoadingScreen autoClose />
<LoadingScreen
overlayClassName={ overlayClassName }
autoClose
/>
{ children }
</>
) : (
<Suspense
fallback={ <LoadingScreen onUnmount={ finishedLoading } /> }
fallback={
<LoadingScreen
onUnmount={ finishedLoading }
overlayClassName={ overlayClassName }
/>
}
>
{ dataDependencies.map(
( { store, selector, args }, depindex ) => (
Expand All @@ -79,11 +97,12 @@ const SuspenseWithLoadingScreen = ( { dataDependencies, children } ) => {
* Renders a loading screen.
* Supports automatic closing with the `autoClose` prop.
*
* @param {Object} props Component props
* @param {Function?} props.onUnmount Optional callback to call on unmount.
* @param {boolean} props.autoClose Whether to automatically close.
* @param {Object} props Component props
* @param {Function?} props.onUnmount Optional callback to call on unmount.
* @param {boolean} props.autoClose Whether to automatically close.
* @param {string?} props.overlayClassName Additional overlay classname
*/
const LoadingScreen = ( { onUnmount, autoClose } ) => {
const LoadingScreen = ( { onUnmount, autoClose, overlayClassName } ) => {
const [ visible, setVisible ] = useState( true );

useEffect( () => {
Expand Down Expand Up @@ -111,7 +130,10 @@ const LoadingScreen = ( { onUnmount, autoClose } ) => {
onRequestClose={ () => {} }
__experimentalHideHeader
className="block-editor-loading-screen-modal"
overlayClassName="block-editor-loading-screen-modal-overlay"
overlayClassName={ classNames(
'block-editor-loading-screen-modal-overlay',
overlayClassName
) }
>
<div className="block-editor-loading-screen-wrapper">
<Spinner />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
padding-top: $header-height;
}

.block-editor-loading-screen-modal-overlay.is-canvas-view {
padding-top: 0;
}

.block-editor-loading-screen-modal.is-full-screen {
box-shadow: 0 0 0 transparent;
width: 100%;
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ export default function Editor() {
<>
<LoadingScreen
dataDependencies={ contentDependencies }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's how we pass declared dependencies to the suspense boundary.

Technically, this gives us the flexibility to have multiple suspense boundaries that have different data dependencies.

overlayClassName={
isViewMode
? 'is-canvas-view'
: undefined
}
>
<GlobalStylesRenderer />
{ isEditMode && <EditorNotices /> }
Expand Down