Skip to content
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bug Fixes

- `EditorInterface`: Apply the `showListViewByDefault` preference when the editor enters edit mode, so every editor built on the package honors it — including the extensible site editor, which previously ignored it. The logic moves here from `edit-post` and `edit-site`.
- `StylesCanvas`: In preview mode, render edge to edge without the close button and Escape handler. There the canvas is the whole surface rather than a frame opened over an editing session, and whatever opened it owns closing it.

### Bug Fixes

Expand Down
41 changes: 25 additions & 16 deletions packages/editor/src/components/styles-canvas/index.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import { Button } from '@wordpress/components';
import { ESCAPE } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -35,8 +36,8 @@ export function getStylesCanvasTitle( path, showStylebook ) {
* @return {React.JSX.Element} The styles canvas or null if nothing to render.
*/
export default function StylesCanvas() {
const { stylesPath, showStylebook, showListViewByDefault } = useSelect(
( select ) => {
const { stylesPath, showStylebook, showListViewByDefault, isPreviewMode } =
useSelect( ( select ) => {
const { getStylesPath, getShowStylebook } = unlock(
select( editorStore )
);
Expand All @@ -50,10 +51,10 @@ export default function StylesCanvas() {
stylesPath: getStylesPath(),
showStylebook: getShowStylebook(),
showListViewByDefault: _showListViewByDefault,
isPreviewMode:
select( editorStore ).getEditorSettings().isPreviewMode,
};
},
[]
);
}, [] );
const { resetStylesNavigation, setStylesPath } = unlock(
useDispatch( editorStore )
);
Expand Down Expand Up @@ -95,23 +96,31 @@ export default function StylesCanvas() {
}
};

// In preview mode (e.g. the styles route of the extensible site editor),
// the canvas is not opened over an editing session: whatever opened it
// owns closing it, so the close affordances would only desync that owner.
return (
<div className="editor-styles-canvas">
<div
className={ clsx( 'editor-styles-canvas', {
'is-preview-mode': isPreviewMode,
} ) }
>
<ResizableEditor enableResizing={ false }>
{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
<section
className="editor-styles-canvas__section"
ref={ focusOnMountRef }
onKeyDown={ closeOnEscape }
ref={ isPreviewMode ? undefined : focusOnMountRef }
onKeyDown={ isPreviewMode ? undefined : closeOnEscape }
aria-label={ title }
>
<Button
size="compact"
className="editor-styles-canvas__close-button"
icon={ closeSmall }
label={ __( 'Close' ) }
onClick={ onCloseCanvas }
/>
{ ! isPreviewMode && (
<Button
size="compact"
className="editor-styles-canvas__close-button"
icon={ closeSmall }
label={ __( 'Close' ) }
onClick={ onCloseCanvas }
/>
) }
{ content }
</section>
</ResizableEditor>
Expand Down
6 changes: 6 additions & 0 deletions packages/editor/src/components/styles-canvas/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
width: 100%;
height: 100%;
}

// In preview mode the canvas is the whole surface, not a frame opened
// over an editing session, so it renders edge to edge.
&.is-preview-mode {
padding: 0;
}
}

.editor-styles-canvas__section {
Expand Down
48 changes: 48 additions & 0 deletions routes/styles/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,46 @@ import { useEditorAssets, useEditorSettings } from '@wordpress/lazy-editor';
import { Spinner } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useGlobalStylesRevisions } from '@wordpress/global-styles-ui';
import { unlock } from '@wordpress/routes-lock-unlock';

const { StyleBookPreview } = unlock( editorPrivateApis );

// Rendered instead of the plain style book while a revision is selected in
// the revisions screen, so the style book previews that revision's styles
// rather than the current ones. A separate component so the revisions (and
// authors) are only fetched once a revision is actually selected.
function RevisionStyleBookPreview( {
revisionId,
section,
onChangeSection,
settings,
}: {
revisionId: string;
section: string;
onChangeSection: ( updatedSection: string ) => void;
settings: any;
} ) {
const { revisions, isLoading } = useGlobalStylesRevisions();

if ( isLoading ) {
return null;
}

const selectedRevision = revisions.find(
( revision: any ) => String( revision.id ) === revisionId
);

return (
<StyleBookPreview
path={ section }
onPathChange={ onChangeSection }
settings={ settings }
userConfig={ selectedRevision }
/>
);
}

function Canvas() {
const { isReady: assetsReady } = useEditorAssets();
const navigate = useNavigate();
Expand Down Expand Up @@ -63,6 +99,18 @@ function Canvas() {
return <StyleBookPreview isStatic settings={ editorSettings } />;
}

const revisionId = section.match( /^\/revisions\/(.+)$/ )?.[ 1 ];
if ( revisionId ) {
return (
<RevisionStyleBookPreview
revisionId={ revisionId }
section={ section }
onChangeSection={ onChangeSection }
settings={ editorSettings }
/>
);
}

return (
<StyleBookPreview
path={ section }
Expand Down
1 change: 1 addition & 0 deletions routes/styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@wordpress/data": "file:../../packages/data",
"@wordpress/editor": "file:../../packages/editor",
"@wordpress/element": "file:../../packages/element",
"@wordpress/global-styles-ui": "file:../../packages/global-styles-ui",
"@wordpress/html-entities": "file:../../packages/html-entities",
"@wordpress/i18n": "file:../../packages/i18n",
"@wordpress/icons": "file:../../packages/icons",
Expand Down
62 changes: 54 additions & 8 deletions routes/styles/stage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { useNavigate, useSearch } from '@wordpress/route';
import { Page } from '@wordpress/admin-ui';
import { __ } from '@wordpress/i18n';
import { privateApis as editorPrivateApis } from '@wordpress/editor';
import {
privateApis as editorPrivateApis,
store as editorStore,
} from '@wordpress/editor';
import { useViewportMatch } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import {
Button,
Modal,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';
import { seen } from '@wordpress/icons';
import { useState } from '@wordpress/element';
import { backup, seen } from '@wordpress/icons';
import { useEffect, useState } from '@wordpress/element';
import { useEditorSettings } from '@wordpress/lazy-editor';
import { unlock } from '@wordpress/routes-lock-unlock';
import { ActivatePanel } from './activate-panel';
Expand All @@ -28,15 +31,25 @@ function Stage() {
const isMobileViewport = useViewportMatch( 'medium', '<' );
const isPreviewingTheme = !! getPreviewedStylesheet();
const [ isActivatePanelOpen, setIsActivatePanelOpen ] = useState( false );
const { globalStylesId, themeName } = useSelect(
const { globalStylesId, hasRevisions, themeName } = useSelect(
( select ) => {
const { getCurrentTheme, __experimentalGetCurrentGlobalStylesId } =
select( coreStore ) as any;
const {
getCurrentTheme,
getEntityRecord,
__experimentalGetCurrentGlobalStylesId,
} = select( coreStore ) as any;
const themeNameRendered = isPreviewingTheme
? getCurrentTheme()?.name?.rendered
: undefined;
const _globalStylesId = __experimentalGetCurrentGlobalStylesId();
const globalStyles = _globalStylesId
? getEntityRecord( 'root', 'globalStyles', _globalStylesId )
: undefined;
return {
globalStylesId: __experimentalGetCurrentGlobalStylesId(),
globalStylesId: _globalStylesId,
hasRevisions:
!! globalStyles?._links?.[ 'version-history' ]?.[ 0 ]
?.count,
themeName: themeNameRendered
? decodeEntities( themeNameRendered )
: undefined,
Expand All @@ -49,6 +62,21 @@ function Stage() {
} );

const section = ( search.section ?? '/' ) as string;
const areRevisionsOpened = section.startsWith( '/revisions' );

// The canvas on this route is the editor in preview mode, and its
// revisions preview is driven by the editor store's styles path rather
// than this route's `section` search param. Keep the store in sync while
// the revisions screen is open so selecting a revision previews it in
// the canvas.
const { setStylesPath } = unlock( useDispatch( editorStore ) );
useEffect( () => {
if ( ! areRevisionsOpened ) {
return;
}
setStylesPath( section );
return () => setStylesPath( '/' );
}, [ areRevisionsOpened, section, setStylesPath ] );
const [ isStyleBookOpened, setIsStyleBookOpened ] = useState(
search.preview === 'stylebook'
);
Expand Down Expand Up @@ -97,6 +125,24 @@ function Stage() {
} );
} }
/>
<Button
size="compact"
isPressed={ areRevisionsOpened }
icon={ backup }
label={ __( 'Revisions' ) }
// The revisions screen has no empty
// state; it expects to be opened only
// when revisions exist.
accessibleWhenDisabled
disabled={ ! hasRevisions }
onClick={ () =>
onChangeSection(
areRevisionsOpened
? '/'
: '/revisions'
)
}
/>
<GlobalStylesActionMenu
hideWelcomeGuide
onChangePath={ onChangeSection }
Expand Down
1 change: 1 addition & 0 deletions routes/styles/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{ "path": "../../packages/data" },
{ "path": "../../packages/editor/tsconfig.build.json" },
{ "path": "../../packages/element/tsconfig.build.json" },
{ "path": "../../packages/global-styles-ui" },
{ "path": "../../packages/html-entities/tsconfig.build.json" },
{ "path": "../../packages/i18n/tsconfig.build.json" },
{ "path": "../../packages/icons/tsconfig.build.json" },
Expand Down
Loading