Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor: Add ability to focus on editing a page's content vs the page's template #50857

Merged
merged 49 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5f3c1b2
Add ability to prevent editing blocks using useBlockEditingMode()
noisysocks May 15, 2023
bcf6949
Make useBlockEditingMode use context
noisysocks May 22, 2023
6ab13d7
Remove rootBlockEditingMode setting
noisysocks May 22, 2023
6426fca
Fix private createRegistrySelector selectors
noisysocks May 22, 2023
bd2f478
Consolidate templateLock=contentOnly logic into getBlockEditingMode
noisysocks May 22, 2023
f00dc25
Hide disabled blocks from List View
noisysocks May 22, 2023
c7e128c
Hide disabled blocks from breadcrumbs
noisysocks May 22, 2023
2a9b9e5
Add doc comments
noisysocks May 22, 2023
692cd76
Add unit tests
noisysocks May 23, 2023
8162afe
Use @typedef to document mode param
noisysocks May 23, 2023
52c4df0
Merge remote-tracking branch 'origin/trunk' into try/block-editing-mode
noisysocks May 23, 2023
3d437a4
Restore packages/components/package.json from trunk
noisysocks May 23, 2023
25f3e58
Restore packages/block-library/src/post-title/edit.js from trunk
noisysocks May 23, 2023
f1e1a11
Move BlockListBlockContext out of block.js so that it exists on mobil…
noisysocks May 23, 2023
6bf1ddd
Site Editor: Add ability to focus on editing a page's content vs the …
noisysocks May 23, 2023
727ecd2
Show page information in DocumentActions
noisysocks May 24, 2023
6bd3ab8
Merge remote-tracking branch 'origin/trunk' into add/template-post-co…
noisysocks May 24, 2023
12e8ad4
Implement Content panel
noisysocks May 24, 2023
4489da2
Prevent block overlay on disabled blocks
noisysocks May 24, 2023
fda46cd
Fix Navigation block being selectable
noisysocks May 24, 2023
0443db4
Show 'Page' in breadcrumbs when focused on editing page
noisysocks May 24, 2023
8c1c4a6
Update post title, post featured image, and post content blocks to sa…
noisysocks May 24, 2023
bed91ec
toolbar title styling
SaxonF May 24, 2023
23837de
Remove removePostFromContentBlockLabels for now
noisysocks May 25, 2023
3cd4a17
Fix being able to select text within disabled blocks
noisysocks May 25, 2023
599a4d1
Hide BlockAppender when block is disabled
noisysocks May 25, 2023
5d52359
Fix comments block in non-post templates
noisysocks May 25, 2023
055b7f1
Update template card selector in E2E tests
noisysocks May 25, 2023
79c59bf
Fix 'Add submenu' button in Navigation block
noisysocks May 25, 2023
726c6cc
Merge remote-tracking branch 'origin/trunk' into add/template-post-co…
noisysocks May 25, 2023
89212cd
Remove unhelpful comments
noisysocks May 25, 2023
bdee82a
Remove more unnecessary comments
noisysocks May 25, 2023
0395bf0
Use constant for block types array
noisysocks May 25, 2023
67cf0db
Use BEMish selectors
noisysocks May 25, 2023
50748c2
Be explicit that we're switching away from the page lock
noisysocks May 25, 2023
a468d55
Update removePageFromBlockContext() test
noisysocks May 25, 2023
261d076
Fix post context from appearing in Edit Template preview
noisysocks May 25, 2023
64d0e43
Clear block selection when switching from template focus to page focus
noisysocks May 25, 2023
c860258
Prevent insertion into a disabled block
noisysocks May 25, 2023
c22368a
Don't allow removing and moving children of disabled blocks
noisysocks May 25, 2023
32b5413
Work around @wordpress/data bug by not using createRegistrySelector()…
noisysocks May 26, 2023
9eba206
Fix typo
ramonjd May 31, 2023
245a0bb
Fix select() mock
noisysocks Jun 1, 2023
97e8f23
Fix block-editor selector tests
noisysocks Jun 1, 2023
46c4074
Merge remote-tracking branch 'origin/trunk' into add/template-post-co…
noisysocks Jun 1, 2023
cd90a63
Revert block-editor changes
noisysocks Jun 1, 2023
7e64fa5
Merge remote-tracking branch 'origin/trunk' into add/template-post-co…
noisysocks Jun 2, 2023
fa8133b
Improve useDisableNonContentBlocks performance
noisysocks Jun 2, 2023
f3fc2ca
Fix performance tests
noisysocks Jun 2, 2023
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
36 changes: 36 additions & 0 deletions docs/reference-guides/data/data-core-edit-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ _Returns_

- `Object`: Settings.

### hasPageContentLock

Whether or not the editor is locked so that only page content can be edited.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `boolean`: Whether or not the editor is locked.

### isFeatureActive

> **Deprecated**
Expand Down Expand Up @@ -174,6 +186,22 @@ _Returns_

> **Deprecated**

### isPage

Whether or not the editor has a page loaded into it.

_Related_

- setPage

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `boolean`: Whether or not the editor has a page loaded into it.

### isSaveViewOpened

Returns the current opened/closed state of the save panel.
Expand Down Expand Up @@ -252,6 +280,14 @@ _Returns_

- `number`: The resolved template ID for the page route.

### setHasPageContentLock

Sets whether or not the editor is locked so that only page content can be edited.

_Parameters_

- _hasPageContentLock_ `boolean`: True to enable lock, false to disable.

### setHomeTemplateId

> **Deprecated**
Expand Down
26 changes: 14 additions & 12 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -508,20 +508,22 @@ body.editor-styles-wrapper .wp-block-navigation__responsive-container.is-menu-op
// so focus is applied naturally on the block container.
// It's important the right container has focus, otherwise you can't press
// "Delete" to remove the block.
.wp-block-navigation__responsive-container,
.wp-block-navigation__responsive-close {
@include break-small() {
pointer-events: none;

.wp-block-navigation__responsive-container-close,
.block-editor-block-list__layout * {
pointer-events: all;
.wp-block-navigation:not(.is-editing-disabled) {
.wp-block-navigation__responsive-container,
.wp-block-navigation__responsive-close {
@include break-small() {
pointer-events: none;

.wp-block-navigation__responsive-container-close,
.block-editor-block-list__layout * {
pointer-events: all;
}
}
}

// Page List items should remain inert.
.wp-block-pages-list__item__link {
pointer-events: none;
// Page List items should remain inert.
.wp-block-pages-list__item__link {
pointer-events: none;
}
}
}

Expand Down
35 changes: 21 additions & 14 deletions packages/block-library/src/post-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
InspectorControls,
useBlockProps,
PlainText,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { ToggleControl, TextControl, PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
Expand All @@ -23,6 +24,9 @@ import { useEntityProp } from '@wordpress/core-data';
*/
import HeadingLevelDropdown from '../heading/heading-level-dropdown';
import { useCanEditEntity } from '../utils/hooks';
import { unlock } from '../private-apis';

const { useBlockEditingMode } = unlock( blockEditorPrivateApis );

export default function PostTitleEdit( {
attributes: { level, textAlign, isLink, rel, linkTarget },
Expand Down Expand Up @@ -58,6 +62,7 @@ export default function PostTitleEdit( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
} );
const blockEditingMode = useBlockEditingMode();

let titleElement = <TagName { ...blockProps }>{ __( 'Title' ) }</TagName>;

Expand Down Expand Up @@ -112,20 +117,22 @@ export default function PostTitleEdit( {

return (
<>
<BlockControls group="block">
<HeadingLevelDropdown
selectedLevel={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
{ blockEditingMode === 'default' && (
<BlockControls group="block">
Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2023-05-31 at 3 32 14 pm

The black dot is a collapsed border style, and appears on all page blocks that are contentOnly, e.g., feature image block as well.

There's a permanent border on the following element (I've added border:0 inline to remove it via the console)

<div id="id-0f1fdc" role="toolbar" aria-orientation="horizontal" aria-label="Block tools" class="components-accessible-toolbar block-editor-block-contextual-toolbar" style="
    border: 0;
"><div class="block-editor-block-toolbar"><div></div></div></div>

This element is rendered by <BlockContextualToolbar /> (block-contextual-toolbar.js). The offending CSS rule for .block-editor-block-contextual-toolbar is in style.scss.

The element is always rendered, even when the slots are empty.

I'm not sure what the best approach is. Checking via useSlotFills() whether the slot is, indeed filled? Would we have to loop through all groups.js?

I'm also guessing the value of blockEditingMode in might not be useful to since the toolbar can show fordefaultandcontentOnly. In this case the site title block has a value of contentOnly`, but the slots are not filled.

Just dumping my brain here in case it helps... :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for digging into this. I'm also not sure how best to fix it. It's a shame we can't use the :empty pseudo selector in CSS because the toolbar technically isn't empty (there's a <div />). Checking if there's fills via useSlotFills() is probably the best bet like you say.

At any rate I'm going to leave fix this for a follow-up PR. (It's noted in the PR description.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we do something like :has( > div:empty:only-child)? Fine to address as a follow-up though 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

:has doesn't work in Firefox 😭 I'll pick your brain about this next week.

<HeadingLevelDropdown
selectedLevel={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
<AlignmentControl
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
) }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still able to edit/interact with block toolbars in the header when in content editing mode, though the toolbars no longer show the block type:

Screenshot 2023-05-25 at 1 27 28 pm Screenshot 2023-05-25 at 1 27 57 pm

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, I don't see that... what steps did you take?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can too - site title and paragraphs in the header and footer seem to be editable. Not sure I did anything special.

I also noticed that when switching from editing the template back to editing the page content, the block you have selected might be part of the template, but it remains selected and has a toolbar.

Copy link
Contributor

@andrewserong andrewserong May 25, 2023

Choose a reason for hiding this comment

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

I noticed the same. This PR is otherwise testing quite nicely for me, though!

Here's a screengrab in case it helps:

2023-05-25.16.22.38.mp4

Copy link
Member Author

@noisysocks noisysocks May 25, 2023

Choose a reason for hiding this comment

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

Do you have the latest changes pulled? There was a bug where you could select a locked block by double clicking or dragging that should be fixed in 3cd4a17.

Copy link
Contributor

@andrewserong andrewserong May 25, 2023

Choose a reason for hiding this comment

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

Do you have the latest changes pulled?

Yes, just tried re-pulling, and my environment says it's up to date, and I re-ran npm run dev. In the screengrab, I'm single-clicking the Site Title block in the header, but I can also reproduce by clicking the Site Title or Paragraph blocks in the footer, too.

Very weird — I can see the pointer-events: none rule should be applying, but I was still able to select the block 🤔

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I have latest changes too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you using TT3?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep!

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha, looks like it only happens in Chrome. I'll investigate tomorrow.

<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-tests/specs/performance/site-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ describe( 'Site Editor Performance', () => {
await enterEditMode();

// Insert a new paragraph right under the first one.
await firstParagraph.focus();
await firstParagraph.click(); // Once to select the block overlay.
await firstParagraph.click(); // Once again to select the paragraph.
await insertBlock( 'Paragraph' );

// Start tracing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ async function getActiveTabLabel() {
async function getTemplateCard() {
return {
title: await page.$eval(
'.edit-site-template-card__title',
'.edit-site-sidebar-card__title',
( element ) => element.innerText
),
description: await page.$eval(
'.edit-site-template-card__description',
'.edit-site-sidebar-card__description',
( element ) => element.innerText
),
};
Expand Down
39 changes: 25 additions & 14 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import ResizableEditor from './resizable-editor';
import EditorCanvas from './editor-canvas';
import { unlock } from '../../private-apis';
import EditorCanvasContainer from '../editor-canvas-container';
import {
PageContentLock,
usePageContentLockNotifications,
} from '../page-content-lock';

const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );

Expand All @@ -49,20 +53,25 @@ const LAYOUT = {

export default function BlockEditor() {
const { setIsInserterOpened } = useDispatch( editSiteStore );
const { storedSettings, templateType, canvasMode } = useSelect(
( select ) => {
const { getSettings, getEditedPostType, getCanvasMode } = unlock(
select( editSiteStore )
);

return {
storedSettings: getSettings( setIsInserterOpened ),
templateType: getEditedPostType(),
canvasMode: getCanvasMode(),
};
},
[ setIsInserterOpened ]
);
const { storedSettings, templateType, canvasMode, hasPageContentLock } =
useSelect(
( select ) => {
const {
getSettings,
getEditedPostType,
getCanvasMode,
hasPageContentLock: _hasPageContentLock,
} = unlock( select( editSiteStore ) );

return {
storedSettings: getSettings( setIsInserterOpened ),
templateType: getEditedPostType(),
canvasMode: getCanvasMode(),
hasPageContentLock: _hasPageContentLock(),
};
},
[ setIsInserterOpened ]
);

const settingsBlockPatterns =
storedSettings.__experimentalAdditionalBlockPatterns ?? // WP 6.0
Expand Down Expand Up @@ -137,6 +146,7 @@ export default function BlockEditor() {
contentRef,
useClipboardHandler(),
useTypingObserver(),
usePageContentLockNotifications(),
noisysocks marked this conversation as resolved.
Show resolved Hide resolved
] );
const isMobileViewport = useViewportMatch( 'small', '<' );
const { clearSelectedBlock } = useDispatch( blockEditorStore );
Expand All @@ -162,6 +172,7 @@ export default function BlockEditor() {
onChange={ onChange }
useSubRegistry={ false }
>
{ hasPageContentLock && <PageContentLock /> }
<TemplatePartConverter />
<SidebarInspectorFill>
<BlockInspector />
Expand Down
22 changes: 14 additions & 8 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import WelcomeGuide from '../welcome-guide';
import StartTemplateOptions from '../start-template-options';
import { store as editSiteStore } from '../../store';
import { GlobalStylesRenderer } from '../global-styles-renderer';

import useTitle from '../routes/use-title';
import CanvasSpinner from '../canvas-spinner';
import { unlock } from '../../private-apis';
Expand Down Expand Up @@ -74,13 +73,15 @@ export default function Editor( { isLoading } ) {
isListViewOpen,
showIconLabels,
showBlockBreadcrumbs,
hasPageContentLock,
} = useSelect( ( select ) => {
const {
getEditedPostContext,
getEditorMode,
getCanvasMode,
isInserterOpened,
isListViewOpened,
hasPageContentLock: _hasPageContentLock,
} = unlock( select( editSiteStore ) );
const { __unstableGetEditorMode } = select( blockEditorStore );
const { getActiveComplementaryArea } = select( interfaceStore );
Expand All @@ -105,6 +106,7 @@ export default function Editor( { isLoading } ) {
'core/edit-site',
'showBlockBreadcrumbs'
),
hasPageContentLock: _hasPageContentLock(),
};
}, [] );
const { setEditedPostContext } = useDispatch( editSiteStore );
Expand All @@ -122,9 +124,10 @@ export default function Editor( { isLoading } ) {
const secondarySidebarLabel = isListViewOpen
? __( 'List View' )
: __( 'Block Library' );
const blockContext = useMemo(
() => ( {
...context,
const blockContext = useMemo( () => {
const { postType, postId, ...nonPostFields } = context ?? {};
return {
...( hasPageContentLock ? context : nonPostFields ),
queryContext: [
context?.queryContext || { page: 1 },
( newQueryContext ) =>
Expand All @@ -136,9 +139,8 @@ export default function Editor( { isLoading } ) {
},
} ),
],
} ),
[ context, setEditedPostContext ]
);
};
}, [ hasPageContentLock, context, setEditedPostContext ] );

let title;
if ( hasLoadedPost ) {
Expand Down Expand Up @@ -227,7 +229,11 @@ export default function Editor( { isLoading } ) {
footer={
shouldShowBlockBreakcrumbs && (
<BlockBreadcrumb
rootLabelText={ __( 'Template' ) }
rootLabelText={
hasPageContentLock
? __( 'Page' )
: __( 'Template' )
}
/>
)
}
Expand Down
Loading