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
27 changes: 27 additions & 0 deletions src/page-finder/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* canvas's light colours.
*/

@use "../colors" as *;

$field-height: 32px;
$panel-gap: 4px;

Expand Down Expand Up @@ -436,6 +438,31 @@ $light-fill-strong: rgba(0, 0, 0, 0.08);
&.is-publish {
color: var(--wpds-color-foreground-content-neutral-weak);
}

// What every page shares, in its purple. See `src/global-scope`.
&.is-shared {
color: $cnl-global;
}
}

// A layout or template part's name and what it is, in the purple of what
// every page shares. See `src/global-scope`.
.cnl-page-switcher.is-shared .cnl-page-switcher__label > * {
color: $cnl-global;
}

// Names what is open without going anywhere, so it doesn't act like a field.
.cnl-page-switcher.is-static {

.cnl-page-switcher__toggle,
.cnl-page-switcher__toggle:hover {
background: $light-fill;
cursor: default;
}

.cnl-page-switcher__status {
cursor: default;
}
}

/*
Expand Down
42 changes: 19 additions & 23 deletions src/routes/content/template-canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
*/
import { GLOBAL_CANVAS_CSS, GlobalScope } from '../../global-scope';
import { settings } from '../../settings';
import { DocumentTitle, SiteCanvas, useSiteCanvas } from '../../site-canvas';
import { PageSwitcher, SiteCanvas, useSiteCanvas } from '../../site-canvas';
import { useCanvasStyles } from '../../site-canvas/use-canvas-styles';
import { getTemplateIcon, getTemplateTitle } from './helpers';
import { getTemplateTitle } from './helpers';
import { getSystemPage } from './pages/system-pages';
import { getTemplatePreviewUrl } from './template-preview-url';
import { __, Icon, useMemo, useRef } from '../../wordpress-packages';
import { __, useMemo, useRef } from '../../wordpress-packages';

const GLOBAL_STYLE_ID = 'cnl-template-canvas-global';

Expand All @@ -41,31 +41,27 @@ const EDITOR_SETTINGS = { disableContentOnlyForUnsyncedPatterns: true };
* @param {boolean} props.isSystemPage Whether the layout makes one of the
* system pages, listed by Pages.
* @param {Object} props.template Template record.
* @return {Element} The layout's name, for the canvas toolbar.
* @return {Element} The layout's name, for the canvas toolbar, in the bar
* pages have, marked as shared.
*/
function TemplateDocument( { isSystemPage, template } ) {
const systemPage = isSystemPage ? getSystemPage( template ) : null;

return (
<div className="cnl-editor-homepage-document is-global">
<div className="cnl-editor-homepage-document__text">
<div className="cnl-editor-homepage-document__heading">
<Icon
className="cnl-editor-homepage-document__icon"
icon={ systemPage?.icon || getTemplateIcon( template ) }
/>
<DocumentTitle
title={
systemPage?.title || getTemplateTitle( template )
}
/>
</div>
<p className="cnl-editor-homepage-document__meta">
{ systemPage
? __( 'System page · Your site makes this one' )
: __( 'Layout · Changes everywhere it is used' ) }
</p>
</div>
<div className="cnl-editor-homepage-document">
<PageSwitcher
meta={ systemPage ? __( 'System page' ) : __( 'Layout' ) }
shared={
systemPage
? __(
'Your site makes this page. Changes show wherever it does.'
)
: __(
'Changes show on every page that uses this layout.'
)
}
title={ systemPage?.title || getTemplateTitle( template ) }
/>
</div>
);
}
Expand Down
44 changes: 19 additions & 25 deletions src/routes/site-part/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { cnlEditorStore, getTitleText } from '../../records';
import ScreenLinks from '../../screen-links';
import { settings } from '../../settings';
import {
DocumentTitle,
PageSwitcher,
SiteCanvas,
useCanvasDocument,
useSiteCanvas,
Expand Down Expand Up @@ -60,7 +60,6 @@ import {
blockEditorStore,
Breadcrumbs,
Button,
Icon,
Modal,
noticesStore,
Page,
Expand Down Expand Up @@ -811,21 +810,23 @@ function SitePartsStage() {
);
}

function PartDocument( { icon, title } ) {
// The bar pages have, marked as shared, as the part is on every page. It
// doesn't go to other pages, as the screen is about the part.
function PartDocument( { title } ) {
return (
<div className="cnl-editor-homepage-document is-global">
<div className="cnl-editor-homepage-document__text">
<div className="cnl-editor-homepage-document__heading">
<Icon
className="cnl-editor-homepage-document__icon"
icon={ icon }
/>
<DocumentTitle title={ title } />
</div>
<p className="cnl-editor-homepage-document__meta">
{ __( 'Same on every page' ) }
</p>
</div>
<div className="cnl-editor-homepage-document">
<PageSwitcher
canSwitch={ false }
meta={ __( 'Every page' ) }
shared={ sprintf(
/* translators: %s: Header or Footer. */
__(
'The %s is the same on every page. Changes show on all of them.'
),
title
) }
title={ title }
/>
</div>
);
}
Expand Down Expand Up @@ -861,12 +862,7 @@ function createCanvas( area ) {
canCompose={ false }
canvas={ { ...canvas, editRoute } }
className={ `cnl-site-part-canvas is-${ area }` }
document={
<PartDocument
icon={ SITE_PARTS[ area ].icon }
title={ SITE_PARTS[ area ].title }
/>
}
document={ <PartDocument title={ SITE_PARTS[ area ].title } /> }
editorRef={ editorRef }
// The part is all Edit offers, the rest of the page dimmed.
focusId={ clientId }
Expand Down Expand Up @@ -896,9 +892,7 @@ function SitePartsCanvas() {
canCompose={ false }
canvas={ canvas }
className="cnl-site-part-canvas"
document={
<PartDocument icon={ headerIcon } title={ SITE_PARTS_TITLE } />
}
document={ <PartDocument title={ SITE_PARTS_TITLE } /> }
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/site-canvas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Moving to Browse with unsaved changes asks to save or discard them, because the
| `use-site-canvas.js` | `useSiteCanvas()`: the canvas's state and the rules for moving between modes. |
| `mode.js` | The shared mode: `useCanvasMode()`, `getCanvasMode()`, `setCanvasMode()`. |
| `writing-mode.js` | Which blocks are containers, and how a page's runs of text between them are grouped into sections. |
| `page-switcher.jsx` | The page's name in the middle of the toolbar, which turns into the page finder, and the page's status at its end. |
| `page-switcher.jsx` | The page's name in the middle of the toolbar, which turns into the page finder, and the page's status at its end. Layouts and template parts use the same bar, with their name in purple and a purple globe in place of the status, and a template part's bar doesn't open the finder. |
| `page-settings.jsx` | A page's status as a button that opens its settings in a popover, every detail the Pages screen has for it, where core's editor has them in its sidebar's Page tab. Changes are unsaved edits to the page, saved with Save. Only Layout leads on, to the layouts in the sidebar. |
| `toolbar.jsx` | Edit while viewing and Exit while editing, undo and redo, Document Overview, the preview's history, the View menu (the device, the live page in a new tab and the full-screen editor), and Zoom out (Compose). |
| `zoom-controls.jsx` | Compose from the canvas itself: a zoom in and zoom out pair in its corner, as on a map, and a pinch on a trackpad, or Ctrl or ⌘ with the scroll wheel. One gesture moves one step. |
Expand Down
141 changes: 90 additions & 51 deletions src/site-canvas/page-switcher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@
* in its own tooltip and in the bar's name, so a long name keeps its room.
* For a page, the icon is a button that opens the page's settings
* (`page-settings.jsx`). The bar's tooltip is the page's address.
*
* Layouts and template parts use the same bar. What sets them apart is that
* changing one changes every page that uses it, so in place of a status they
* get a purple globe, the mark Review changes gives site-wide changes, with
* a tooltip saying where changes show, and their name in the same purple.
* A template part's bar doesn't open the finder: while one is open, going
* to a page isn't what the screen is for.
*/

/**
* WordPress dependencies
*/
import { globe as globeIcon } from '@wordpress/icons';
import { Icon } from '@wordpress/ui';

/**
Expand All @@ -31,6 +39,7 @@ import {
useEffect,
useRef,
useState,
VisuallyHidden,
} from '../wordpress-packages';

/**
Expand All @@ -49,16 +58,21 @@ function getReadableUrl( url ) {
}

/**
* @param {Object} props
* @param {string} props.title The page's name.
* @param {?string} props.status The page's status, like `draft`, when it is
* a post with one.
* @param {?string} props.meta More to say after the name, like what the
* homepage shows.
* @param {?string} props.url The page's address on the live site, for the
* bar's tooltip, when it has one.
* @param {?number} props.pageId The page's ID, when it is a page, whose
* settings its status then opens.
* @param {Object} props
* @param {string} props.title The page's name.
* @param {?string} props.status The page's status, like `draft`, when it is
* a post with one.
* @param {?string} props.meta More to say after the name, like what the
* homepage shows.
* @param {?string} props.url The page's address on the live site, for the
* bar's tooltip, when it has one.
* @param {?number} props.pageId The page's ID, when it is a page, whose
* settings its status then opens.
* @param {?string} props.shared For a layout or template part, where changes
* to it show. Marks the bar as shared.
* @param {?boolean} props.canSwitch Whether clicking the bar opens the page
* finder. Without it, the bar only names
* what is open.
* @return {Element} The switcher.
*/
export function PageSwitcher( {
Expand All @@ -67,12 +81,28 @@ export function PageSwitcher( {
meta = '',
url = '',
pageId = 0,
shared = '',
canSwitch = true,
} ) {
const [ isFinding, setIsFinding ] = useState( false );
const toggleRef = useRef();
const shouldRefocus = useRef( false );
const statusIcon = POST_STATUS_ICONS[ status ];
const statusLabel = statusIcon ? getStatusLabel( status ) : '';
const statusIcon = shared ? globeIcon : POST_STATUS_ICONS[ status ];
const statusLabel =
shared || ( statusIcon ? getStatusLabel( status ) : '' );
const openFinder = canSwitch ? () => setIsFinding( true ) : undefined;
const label = (
<span className="cnl-page-switcher__label">
<span className="cnl-page-switcher__title cnl-editor-homepage-document__title">
{ title }
</span>
{ meta && (
<span className="cnl-page-switcher__meta cnl-editor-homepage-document__meta">
{ meta }
</span>
) }
</span>
);

// Escape hands focus back to the bar, rather than losing it to the body.
useEffect( () => {
Expand All @@ -84,7 +114,12 @@ export function PageSwitcher( {

return (
<div
className={ [ 'cnl-page-switcher', isFinding && 'is-finding' ]
className={ [
'cnl-page-switcher',
isFinding && 'is-finding',
shared && 'is-shared',
! canSwitch && 'is-static',
]
.filter( Boolean )
.join( ' ' ) }
>
Expand All @@ -102,43 +137,45 @@ export function PageSwitcher( {
// Still the screen's heading, as the page's name was before it
// became a button.
<h1 className="cnl-page-switcher__heading">
<Tooltip.Root disabled={ ! url }>
<Tooltip.Trigger
aria-label={ sprintf(
/* translators: %s: The name of the page on show, and its status. */
__( '%s. Go to another page' ),
[ title, statusLabel ]
.filter( Boolean )
.join( ', ' )
) }
className="cnl-page-switcher__toggle"
onClick={ () => setIsFinding( true ) }
ref={ toggleRef }
render={ <button type="button" /> }
>
<Icon
className="cnl-page-switcher__search"
icon={ searchIcon }
size={ 20 }
/>
<span className="cnl-page-switcher__label">
<span className="cnl-page-switcher__title cnl-editor-homepage-document__title">
{ title }
</span>
{ meta && (
<span className="cnl-page-switcher__meta cnl-editor-homepage-document__meta">
{ meta }
</span>
{ canSwitch ? (
<Tooltip.Root disabled={ ! url }>
<Tooltip.Trigger
aria-label={ sprintf(
/* translators: %s: The name of the page on show, and its status. */
__( '%s. Go to another page' ),
[ title, statusLabel ]
.filter( Boolean )
.join( ', ' )
) }
</span>
</Tooltip.Trigger>
{ /* Below, as the bar is at the top of the window. */ }
<Tooltip.Popup
positioner={ <Tooltip.Positioner side="bottom" /> }
>
{ getReadableUrl( url ) }
</Tooltip.Popup>
</Tooltip.Root>
className="cnl-page-switcher__toggle"
onClick={ openFinder }
ref={ toggleRef }
render={ <button type="button" /> }
>
<Icon
className="cnl-page-switcher__search"
icon={ searchIcon }
size={ 20 }
/>
{ label }
</Tooltip.Trigger>
{ /* Below, as the bar is at the top of the window. */ }
<Tooltip.Popup
positioner={
<Tooltip.Positioner side="bottom" />
}
>
{ getReadableUrl( url ) }
</Tooltip.Popup>
</Tooltip.Root>
) : (
<div className="cnl-page-switcher__toggle">
{ label }
{ shared && (
<VisuallyHidden>{ shared }</VisuallyHidden>
) }
</div>
) }
{ /*
* Over the bar's end rather than in it, so it has a
* tooltip of its own. A page's opens its settings.
Expand All @@ -160,8 +197,10 @@ export function PageSwitcher( {
<Tooltip.Root>
<Tooltip.Trigger
aria-hidden
className={ `cnl-page-switcher__status is-${ status }` }
onClick={ () => setIsFinding( true ) }
className={ `cnl-page-switcher__status is-${
shared ? 'shared' : status
}` }
onClick={ openFinder }
render={ <span /> }
>
<Icon icon={ statusIcon } size={ 20 } />
Expand Down
Loading