Skip to content
Open
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
10 changes: 10 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ npm run wp-env run cli wp config delete CNL_EDITOR_UI_THEME

The `create-not-learn-editor_ui_theme` filter can override it too. The theme's settings live in `src/theme/`.

## Saving and publishing

Changes are published in two places, one for each scope, and only one save-like button shows at a time.

- **The site's changes** are anything visitors would see on more than one page: the site's name, logo and colours, its header and footer, its layouts, a menu that is shown somewhere, which menu a place shows, and the homepage setting. Pages changed from a screen beside the canvas, their title or place in the menu say, count too. They wait for **Publish site** at the end of the dark top bar (`src/top-bar/`), which shows "Up to date" when there's nothing waiting.
- **The page or post open in the canvas** saves and publishes there, with core's post editor buttons. While one is open, Publish site steps back to a quiet note, "N site changes waiting", which does nothing.
- **Anything nobody can see yet** saves at once and is never counted. For menus that means drafts: new menus start as drafts, as core never shows one, and save as they are changed. A published menu may be shown anywhere, so every change to it waits, its name included. Publish site publishes a draft it puts somewhere.

Nothing is kept between visits yet, so the editor warns before the page is left with anything unsaved. See `src/top-bar/README.md`.

## Site changes are explicit

The editor does not automatically create pages, navigation, or homepage settings, when it loads or when the plugin is activated. A new site keeps WordPress's own default of latest posts on the homepage. Home then offers to set the homepage up the way the workspace expects, step by step, and nothing changes until the person finishes.
Expand Down
6 changes: 3 additions & 3 deletions docs/webmcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

An agent working in the browser can use the editor through [WebMCP](https://github.com/webmachinelearning/webmcp), the same way a person would. The editor registers its own tools (`src/webmcp/`), and they change the page open in the canvas, so the person sees each change as it happens.

Every change is an unsaved edit, like one made by hand. It can be undone, and nothing goes live until the person saves it with Save or Review changes. There's no tool for saving.
Every change is an unsaved edit, like one made by hand. It can be undone, and nothing goes live until the person saves or publishes it: the page's own Save or Publish in the canvas, or Publish site in the top bar for the site's changes. There's no tool for saving.

## Connecting an agent

Expand Down Expand Up @@ -36,7 +36,7 @@ The AI plugin's other features, and the AI the site uses itself, need an AI prov
| `cnl-connect` | Gives the agent's name, for the canvas toolbar's list of its changes |
| `cnl-start-task` | Names what the agent is working on, so its changes are grouped under it |
| `cnl-set-workspace` | Switches workspace, such as to Agent, where the canvas fills the screen so the person can watch, and keeps the page open |
| `cnl-set-canvas` | Switches the canvas to Browse, Edit or Compose, and to desktop, tablet or mobile. Browse asks the person about unsaved changes first, as the canvas's own switch does |
| `cnl-set-canvas` | Switches the canvas to Browse, Edit or Compose, and to desktop, tablet or mobile. Browse asks the person about unsaved edits to the open page first, as Exit does, and stays in the editor while site changes it can't show are waiting |
| `cnl-list-pages` | Lists the pages, which one is the homepage and which one is open |
| `cnl-open-page` | Opens a page in the canvas, by ID, title or `home` |
| `cnl-get-page` | Lists the open page's sections by number, as the canvas names them, with the colours, layouts and widths each can take |
Expand All @@ -59,7 +59,7 @@ The tools work alongside the official [AI plugin](https://wordpress.org/plugins/

Each change is scrolled into view and flashed for three seconds, without being picked, so the person can watch without the editor's bars opening over the page. The flash is an orange outline and tint, the agent's own colour, with an "Updated by agent" badge in the block label's place (`src/webmcp/flash.js`, `includes/block-canvas-styles.php`). It looks like core's highlight, but is drawn by the editor, as core's `flashBlock` only highlights one block at a time. WebMCP doesn't tell the page which agent called a tool, so the badge can't name it.

In the Agent workspace, while an agent is connected, the canvas toolbar says "Agent: connected" before Save, with a green dot that pulses while the agent works (`src/top-bar/agent-status.jsx`).
In the Agent workspace, while an agent is connected, the top bar says "Agent: connected" before Publish site, with a green dot that pulses while the agent works (`src/top-bar/agent-status.jsx`).

Opened, it lists what the agent has changed since the editor loaded, under its name, as one row for each request it worked on, newest first, so a long session stays short to read. The agent names each request with `cnl-start-task`, and its changes go under it until it names the next; changes it makes without naming one are grouped until it pauses for two minutes.

Expand Down
4 changes: 2 additions & 2 deletions packages/app-init/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { registerSectionPatterns } from '../../../src/editor-extensions/section-
import { registerTemplatePartEditing } from '../../../src/editor-extensions/template-part-editing';
import { mountEditorLayer } from '../../../src/editor-layer';
import { registerLayoutWireframes } from '../../../src/layouts';
import { mountSaveControls } from '../../../src/top-bar';
import { mountTopBar } from '../../../src/top-bar';
import { mountWorkspaces } from '../../../src/workspaces';
import { registerWebMcpTools } from '../../../src/webmcp';
import { mountPreferences } from '../../../src/preferences';
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function init() {
mountMenuSections();
mountPreferences();
mountAdminBar();
mountSaveControls();
mountTopBar();
mountCommands();
enhanceSidebar();
registerWebMcpTools();
Expand Down
2 changes: 1 addition & 1 deletion src/pickers/identity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export function SiteIdentityFields( {
<div className="routes-styles__save">
<Text className="routes-styles__muted" variant="body-sm">
{ __(
'You are previewing changes. Visitors see them once you save.'
'You are previewing changes. Visitors see them once you publish the site.'
) }
</Text>
<Stack gap="sm">
Expand Down
2 changes: 1 addition & 1 deletion src/routes/content/pages/homepage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export function useUseAsHomepage( state ) {
{ sprintf(
/* translators: %s: page title. */
__(
'“%s” isn’t published yet. To be your homepage, visitors need to see it, so it will be published when you save your changes.'
'“%s” isn’t published yet. To be your homepage, visitors need to see it, so it will be published when you publish the site.'
),
getPageTitle( pending )
) }
Expand Down
27 changes: 9 additions & 18 deletions src/routes/home/site-card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ import { useNavigate } from '@wordpress/route';
import { startHomeTrip } from '../../home-trip';
import { settings } from '../../settings';
import { getSiteAddress } from './site-address';
import { ReviewChanges } from '../../top-bar/review-changes';
import { PublishSiteDialog } from '../../top-bar/publish-site-dialog';
import { useChanges } from '../../top-bar/use-changes';
import {
Badge,
Icon,
Link,
Tooltip,
_n,
__,
coreDataStore,
decodeEntities,
pencilIcon,
sprintf,
useSelect,
useState,
} from '../../wordpress-packages';
Expand Down Expand Up @@ -128,15 +126,16 @@ export function SiteAddress( { fallbackLabel } ) {
}

/**
* How many changes aren't saved yet, as a badge beside the site's name that
* opens the same review Save does. Nothing shows once everything is saved.
* Whether the site has changes waiting to go live, as a badge beside the
* site's name that opens the same dialog Publish site does. Nothing shows
* once everything is published.
*
* @return {?Element} The status.
*/
export function SiteStatus() {
const { changes, isSaving } = useChanges();
const { siteChanges, isSaving } = useChanges();
const [ isReviewOpen, setIsReviewOpen ] = useState( false );
const count = changes.length;
const count = siteChanges.length;

let badge = null;

Expand All @@ -157,19 +156,11 @@ export function SiteStatus() {
render={ <button type="button" /> }
onClick={ () => setIsReviewOpen( true ) }
>
{ sprintf(
/* translators: %d: Number of changes waiting to be saved. */
_n(
'%d unsaved change',
'%d unsaved changes',
count
),
count
) }
{ __( 'Changes waiting' ) }
</Badge>
}
/>
<Tooltip.Popup>{ __( 'Review changes' ) }</Tooltip.Popup>
<Tooltip.Popup>{ __( 'Publish site' ) }</Tooltip.Popup>
</Tooltip.Root>
);
}
Expand All @@ -179,7 +170,7 @@ export function SiteStatus() {
<>
{ badge }
{ isReviewOpen && (
<ReviewChanges onClose={ () => setIsReviewOpen( false ) } />
<PublishSiteDialog onClose={ () => setIsReviewOpen( false ) } />
) }
</>
);
Expand Down
145 changes: 98 additions & 47 deletions src/routes/navigation-edit/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,89 @@ import {
useDispatch,
useEffect,
useRef,
useSelect,
useState,
__,
} from '../../wordpress-packages';
import { getRenamedNotice, renameMenu } from '../navigation/menu-helpers';
import { DeleteNavigationMenuModal } from '../navigation/menu-row';
import { setSelfSaving } from '../../site-canvas/mode';
import { useMenuItemsEditor } from './menu-items-editor';
import NavigationEditCanvas from './navigation-edit-canvas';
import { ADD_MENU_ITEMS_SEARCH, NAVIGATION_POST_TYPE } from './shared';
import { useNavigationLocations } from './use-navigation-locations';

// Long enough that a run of edits saves once.
const SAVE_DELAY_MS = 600;

/**
* Save a draft menu as it is changed. Core never shows a draft, nor picks
* it for a Navigation block with no menu of its own, so nobody can see it
* and its edits have nothing to wait for. A published menu may be shown
* anywhere, in a header, a page or a widget, so every change to it waits
* for Publish site. See `src/top-bar/README.md`.
*
* @param {number} navigationId The menu.
* @return {boolean} Whether the menu is live, published.
*/
function useSaveWhileDraft( navigationId ) {
const { hasEdits, status } = useSelect(
( select ) => {
const store = select( coreDataStore );

return {
// Leaving out a draft Publish site is publishing, marked to
// publish with the site's changes, which saves it there.
hasEdits:
store.hasEditsForEntityRecord(
'postType',
NAVIGATION_POST_TYPE,
navigationId
) &&
store.getEntityRecordEdits(
'postType',
NAVIGATION_POST_TYPE,
navigationId
)?.status === undefined,
// As saved, not as edited.
status: store.getEntityRecord(
'postType',
NAVIGATION_POST_TYPE,
navigationId
)?.status,
};
},
[ navigationId ]
);
const { saveEditedEntityRecord } = useDispatch( coreDataStore );
const isDraft = status === 'draft';
const recordId = `postType|${ NAVIGATION_POST_TYPE }|${ navigationId }`;

useEffect( () => {
setSelfSaving( recordId, isDraft );
}, [ recordId, isDraft ] );
useEffect( () => () => setSelfSaving( recordId, false ), [ recordId ] );

useEffect( () => {
if ( ! isDraft || ! hasEdits ) {
return undefined;
}

const timer = window.setTimeout(
() =>
saveEditedEntityRecord(
'postType',
NAVIGATION_POST_TYPE,
navigationId
),
SAVE_DELAY_MS
);

return () => window.clearTimeout( timer );
}, [ hasEdits, isDraft, navigationId, saveEditedEntityRecord ] );

return status === 'publish';
}

function NavigationEditStage() {
const navigate = useNavigate();
Expand All @@ -44,8 +121,10 @@ function NavigationEditStage() {
const [ isRenaming, setIsRenaming ] = useState( false );
const [ isDeleting, setIsDeleting ] = useState( false );
const [ renameTitle, setRenameTitle ] = useState( '' );
const { deleteEntityRecord, editEntityRecord } =
const { deleteEntityRecord, editEntityRecord, saveEntityRecord } =
useDispatch( coreDataStore );
const isLive = useSaveWhileDraft( navigationId );
const { locations } = useNavigationLocations( navigationId );
const { invalidateNavigationMenus } = useDispatch( cnlEditorStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
Expand Down Expand Up @@ -78,14 +157,6 @@ function NavigationEditStage() {
} );
}, [ canAddMenuItems, navigate, navigationId, openAddMenuItems, search ] );

const editNavigationMenu = ( edits ) =>
editEntityRecord(
'postType',
NAVIGATION_POST_TYPE,
navigationId,
edits
);

const openRenameModal = () => {
setRenameTitle( menuTitle );
setIsRenaming( true );
Expand All @@ -107,12 +178,17 @@ function NavigationEditStage() {
setIsSaving( true );

try {
editNavigationMenu( { title: trimmedTitle } );
await renameMenu( {
editEntityRecord,
id: navigationId,
isLive,
saveEntityRecord,
title: trimmedTitle,
} );
invalidateNavigationMenus();
setIsRenaming( false );
createSuccessNotice(
__(
'Navigation menu renamed. Review and save changes when you are ready.'
),
getRenamedNotice( { status: isLive ? 'publish' : 'draft' } ),
{ type: 'snackbar' }
);
} catch ( error ) {
Expand Down Expand Up @@ -276,45 +352,20 @@ function NavigationEditStage() {
onClick={ renameNavigationMenu }
variant="primary"
>
{ __( 'Save' ) }
{ __( 'Rename' ) }
</Button>
</div>
</Modal>
) }
{ isDeleting && (
<Modal
className="routes-navigation-edit__item-modal"
onRequestClose={ closeDeleteModal }
title={ __( 'Delete navigation menu' ) }
>
<p>
{ sprintf(
/* translators: %s: navigation menu title. */
__(
'Are you sure you want to delete "%s"? This cannot be undone.'
),
menuTitle
) }
</p>
<div className="routes-navigation-edit__modal-actions">
<Button
disabled={ isSaving }
onClick={ closeDeleteModal }
variant="tertiary"
>
{ __( 'Cancel' ) }
</Button>
<Button
disabled={ isSaving }
isBusy={ isSaving }
isDestructive
onClick={ deleteNavigationMenu }
variant="primary"
>
{ __( 'Delete' ) }
</Button>
</div>
</Modal>
<DeleteNavigationMenuModal
isSaving={ isSaving }
isLive={ isLive }
locations={ locations }
menuTitle={ menuTitle }
onClose={ closeDeleteModal }
onDelete={ deleteNavigationMenu }
/>
) }
</div>
) }
Expand Down
27 changes: 6 additions & 21 deletions src/routes/navigation-edit/menu-items-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,8 @@ export function useMenuItemsEditor( navigationId ) {
: createNavigationLinkBlockFromPage( page ),
],
mode === 'submenu-page'
? __(
'Submenu added to menu. Review and save changes when you are ready.'
)
: __(
'Page added to menu. Review and save changes when you are ready.'
)
? __( 'Submenu added to menu.' )
: __( 'Page added to menu.' )
);

const addCustomLinkToMenu = ( { isSubmenu, label, url } ) =>
Expand All @@ -243,12 +239,8 @@ export function useMenuItemsEditor( navigationId ) {
} ),
],
isSubmenu
? __(
'Submenu added to menu. Review and save changes when you are ready.'
)
: __(
'Link added to menu. Review and save changes when you are ready.'
)
? __( 'Submenu added to menu.' )
: __( 'Link added to menu.' )
);

const addLabelOnlySubmenuToMenu = ( label ) =>
Expand All @@ -259,18 +251,11 @@ export function useMenuItemsEditor( navigationId ) {
url: '#',
} ),
],
__(
'Submenu added to menu. Review and save changes when you are ready.'
)
__( 'Submenu added to menu.' )
);

const addMenuItemsToMenu = ( blocks ) =>
addNavigationBlocks(
blocks,
__(
'Menu items added. Review and save changes when you are ready.'
)
);
addNavigationBlocks( blocks, __( 'Menu items added.' ) );

// Turn the auto menu into links to the pages it lists now, as a change to
// review and save with the rest.
Expand Down
Loading