From 65be8c72de47333ecf145019af3fac75e3849856 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Nov 2026 13:40:08 +0000 Subject: [PATCH] Use the page title bar for layouts and template parts Layouts, system pages, the header and the footer now show their name in PageSwitcher, the bar pages use, marked as shared with a purple globe, name and meta. The header and footer bar doesn't open the page finder. Co-Authored-By: Claude Opus 5.5 --- src/page-finder/style.scss | 27 +++++ src/routes/content/template-canvas.jsx | 42 ++++---- src/routes/site-part/content.jsx | 44 ++++---- src/site-canvas/README.md | 2 +- src/site-canvas/page-switcher.jsx | 141 ++++++++++++++++--------- src/styles/_canvas.scss | 16 --- 6 files changed, 156 insertions(+), 116 deletions(-) diff --git a/src/page-finder/style.scss b/src/page-finder/style.scss index 8b48612..29b3589 100644 --- a/src/page-finder/style.scss +++ b/src/page-finder/style.scss @@ -5,6 +5,8 @@ * canvas's light colours. */ +@use "../colors" as *; + $field-height: 32px; $panel-gap: 4px; @@ -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; + } } /* diff --git a/src/routes/content/template-canvas.jsx b/src/routes/content/template-canvas.jsx index dd80ab7..0e08368 100644 --- a/src/routes/content/template-canvas.jsx +++ b/src/routes/content/template-canvas.jsx @@ -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'; @@ -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 ( -
-
-
- - -
-

- { systemPage - ? __( 'System page · Your site makes this one' ) - : __( 'Layout · Changes everywhere it is used' ) } -

-
+
+
); } diff --git a/src/routes/site-part/content.jsx b/src/routes/site-part/content.jsx index c501745..46101e8 100644 --- a/src/routes/site-part/content.jsx +++ b/src/routes/site-part/content.jsx @@ -25,7 +25,7 @@ import { cnlEditorStore, getTitleText } from '../../records'; import ScreenLinks from '../../screen-links'; import { settings } from '../../settings'; import { - DocumentTitle, + PageSwitcher, SiteCanvas, useCanvasDocument, useSiteCanvas, @@ -60,7 +60,6 @@ import { blockEditorStore, Breadcrumbs, Button, - Icon, Modal, noticesStore, Page, @@ -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 ( -
-
-
- - -
-

- { __( 'Same on every page' ) } -

-
+
+
); } @@ -861,12 +862,7 @@ function createCanvas( area ) { canCompose={ false } canvas={ { ...canvas, editRoute } } className={ `cnl-site-part-canvas is-${ area }` } - document={ - - } + document={ } editorRef={ editorRef } // The part is all Edit offers, the rest of the page dimmed. focusId={ clientId } @@ -896,9 +892,7 @@ function SitePartsCanvas() { canCompose={ false } canvas={ canvas } className="cnl-site-part-canvas" - document={ - - } + document={ } /> ); } diff --git a/src/site-canvas/README.md b/src/site-canvas/README.md index df846bd..ebddd40 100644 --- a/src/site-canvas/README.md +++ b/src/site-canvas/README.md @@ -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. | diff --git a/src/site-canvas/page-switcher.jsx b/src/site-canvas/page-switcher.jsx index d12e1ad..6f65544 100644 --- a/src/site-canvas/page-switcher.jsx +++ b/src/site-canvas/page-switcher.jsx @@ -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'; /** @@ -31,6 +39,7 @@ import { useEffect, useRef, useState, + VisuallyHidden, } from '../wordpress-packages'; /** @@ -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( { @@ -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 = ( + + + { title } + + { meta && ( + + { meta } + + ) } + + ); // Escape hands focus back to the bar, rather than losing it to the body. useEffect( () => { @@ -84,7 +114,12 @@ export function PageSwitcher( { return (
@@ -102,43 +137,45 @@ export function PageSwitcher( { // Still the screen's heading, as the page's name was before it // became a button.

- - setIsFinding( true ) } - ref={ toggleRef } - render={