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 26 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
40 changes: 40 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 @@ -355,6 +383,18 @@ _Parameters_

- _featureName_ `string`: Feature name.

### togglePageContentLock

Action that toggles 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, or undefined to toggle.

_Returns_

- `Object`: Action object.

### updateSettings

Returns an action object used to update the settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getDefaultBlockName } from '@wordpress/blocks';
import DefaultBlockAppender from '../default-block-appender';
import ButtonBlockAppender from '../button-block-appender';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

function DefaultAppender( { rootClientId } ) {
const canInsertDefaultBlock = useSelect( ( select ) =>
Expand Down Expand Up @@ -46,13 +47,15 @@ function useAppender( rootClientId, CustomAppender ) {
getTemplateLock,
getSelectedBlockClientId,
__unstableGetEditorMode,
} = select( blockEditorStore );
getBlockEditingMode,
} = unlock( select( blockEditorStore ) );

const selectedBlockClientId = getSelectedBlockClientId();

return {
hideInserter:
!! getTemplateLock( rootClientId ) ||
getBlockEditingMode( rootClientId ) === 'disabled' ||
__unstableGetEditorMode() === 'zoom-out',
isParentSelected:
rootClientId === selectedBlockClientId ||
Expand Down
22 changes: 10 additions & 12 deletions packages/block-editor/src/components/block-list/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,6 @@
padding: 0;
}

.block-editor-block-list__layout,
.block-editor-block-list__block {
pointer-events: initial;

&.is-editing-disabled {
pointer-events: none;
}
}

.block-editor-block-list__layout .block-editor-block-list__block {
// With `position: static`, Safari marks a full-width selection rectangle, including margins.
// With `position: relative`, Safari marks an inline selection rectangle, similar to that of
Expand All @@ -178,12 +169,19 @@
// We choose relative, as that matches the multi-selection, which is limited to the block footprint.
position: relative;

// Re-enable text-selection on editable blocks.
user-select: text;

// Break long strings of text without spaces so they don't overflow the block.
overflow-wrap: break-word;

// Enable pointer events on editable blocks.
pointer-events: auto;
user-select: text;

// But disable when editing is disabled.
noisysocks marked this conversation as resolved.
Show resolved Hide resolved
&.is-editing-disabled {
pointer-events: none;
user-select: none;
}

.reusable-block-edit-panel * {
z-index: z-index(".block-editor-block-list__block .reusable-block-edit-panel *");
}
Expand Down
8 changes: 8 additions & 0 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import deprecated from '@wordpress/deprecated';
*/
import { mapRichTextSettings } from './utils';
import { orderBy } from '../utils/sorting';
import { getBlockEditingMode } from './private-selectors';

/**
* A block selection object.
Expand Down Expand Up @@ -2788,6 +2789,13 @@ export function __unstableGetTemporarilyEditingAsBlocks( state ) {
}

export function __unstableHasActiveBlockOverlayActive( state, clientId ) {
// Prevent overlay on disabled blocks. It's redundant since disabled blocks
// can't be selected, and prevents non-disabled nested blocks from being
// selected.
if ( getBlockEditingMode( state, clientId ) === 'disabled' ) {
return false;
}

// If the block editing is locked, the block overlay is always active.
if ( ! canEditBlock( state, clientId ) ) {
return true;
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,11 @@ body.editor-styles-wrapper .wp-block-navigation__responsive-container.is-menu-op
@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-close,
.block-editor-block-list__layout * {
pointer-events: all;
}
}
}

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 }>{ __( 'Post Title' ) }</TagName>
Expand Down Expand Up @@ -114,20 +119,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
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
51 changes: 34 additions & 17 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ 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';
import useEditedEntityRecord from '../use-edited-entity-record';
import { SidebarFixedBottomSlot } from '../sidebar-edit-mode/sidebar-fixed-bottom';
import removePageFromBlockContext from '../../utils/remove-page-from-block-context';

const interfaceLabels = {
/* translators: accessibility text for the editor content landmark region. */
Expand Down Expand Up @@ -74,13 +74,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 +107,7 @@ export default function Editor( { isLoading } ) {
'core/edit-site',
'showBlockBreadcrumbs'
),
hasPageContentLock: _hasPageContentLock(),
};
}, [] );
const { setEditedPostContext } = useDispatch( editSiteStore );
Expand All @@ -123,21 +126,14 @@ export default function Editor( { isLoading } ) {
? __( 'List View' )
: __( 'Block Library' );
const blockContext = useMemo(
() => ( {
...context,
queryContext: [
context?.queryContext || { page: 1 },
( newQueryContext ) =>
setEditedPostContext( {
...context,
queryContext: {
...context?.queryContext,
...newQueryContext,
},
} ),
],
} ),
[ context, setEditedPostContext ]
() =>
addQueryContextToBlockContext(
hasPageContentLock
? context
: removePageFromBlockContext( context ),
setEditedPostContext
),
[ hasPageContentLock, context, setEditedPostContext ]
);

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

function addQueryContextToBlockContext( context, setContext ) {
return {
...context,
queryContext: [
context?.queryContext || { page: 1 },
( newQueryContext ) =>
setContext( {
...context,
queryContext: {
...context?.queryContext,
...newQueryContext,
},
} ),
],
};
}
Loading