-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Allow template part editing in write mode #67372
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
Changes from 1 commit
3616308
e8c33f1
05542c6
0ebb6ea
700f059
508bd39
5e68eea
f609354
d6243e4
adde4d2
0d4cf1d
673f4b0
80d9048
98f98cb
e008553
0051caf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,13 @@ import usePostContentBlocks from './use-post-content-blocks'; | |
| */ | ||
| export default function DisableNonPageContentBlocks() { | ||
| const contentOnlyIds = usePostContentBlocks(); | ||
| const templateParts = useSelect( ( select ) => { | ||
| const { getBlocksByName } = select( blockEditorStore ); | ||
| return getBlocksByName( 'core/template-part' ); | ||
| const { templateParts, isNavigationMode } = useSelect( ( select ) => { | ||
| const { getBlocksByName, isNavigationMode: _isNavigationMode } = | ||
| select( blockEditorStore ); | ||
| return { | ||
| templateParts: getBlocksByName( 'core/template-part' ), | ||
| isNavigationMode: _isNavigationMode(), | ||
| }; | ||
| }, [] ); | ||
| const disabledIds = useSelect( | ||
| ( select ) => { | ||
|
|
@@ -41,8 +45,10 @@ export default function DisableNonPageContentBlocks() { | |
| for ( const clientId of contentOnlyIds ) { | ||
| setBlockEditingMode( clientId, 'contentOnly' ); | ||
| } | ||
| for ( const clientId of templateParts ) { | ||
| setBlockEditingMode( clientId, 'contentOnly' ); | ||
| if ( ! isNavigationMode ) { | ||
| for ( const clientId of templateParts ) { | ||
| setBlockEditingMode( clientId, 'contentOnly' ); | ||
| } | ||
| } | ||
| for ( const clientId of disabledIds ) { | ||
| setBlockEditingMode( clientId, 'disabled' ); | ||
|
|
@@ -55,15 +61,23 @@ export default function DisableNonPageContentBlocks() { | |
| for ( const clientId of contentOnlyIds ) { | ||
| unsetBlockEditingMode( clientId ); | ||
| } | ||
| for ( const clientId of templateParts ) { | ||
| unsetBlockEditingMode( clientId ); | ||
| if ( ! isNavigationMode ) { | ||
| for ( const clientId of templateParts ) { | ||
| unsetBlockEditingMode( clientId ); | ||
| } | ||
| } | ||
| for ( const clientId of disabledIds ) { | ||
| unsetBlockEditingMode( clientId ); | ||
| } | ||
| } ); | ||
| }; | ||
| }, [ templateParts, contentOnlyIds, disabledIds, registry ] ); | ||
| }, [ | ||
| templateParts, | ||
| contentOnlyIds, | ||
| disabledIds, | ||
| isNavigationMode, | ||
| registry, | ||
| ] ); | ||
|
|
||
| return null; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would it take to move away from this component entirely? The code here is so confusing. What happens if we passed a list of block types as settings to the block editor:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it is confusing! There's already a list like this - https://github.com/WordPress/gutenberg/blob/trunk/packages/editor/src/components/provider/use-post-content-blocks.js I think your idea works for most of the blocks, apart from the template part where the block itself is enabled but inner blocks are disabled. This is buggy anyway, as disabling the inner blocks like that doesn't prevent insertions, so at the moment you can still drag things into the template part block when editing a page. 😓 I personally think it'd be best to remove the way template parts are selectable in this mode. There's a parallel discussion on it here - #67621 (comment).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thing is that in the long run, I think it'd be interesting to determine these blocks via their bindings. E.g. if the user is editing a That's a bit far away, but it makes me thing that rather than Blocks with a post meta binding could already be made to work like this if they're in the template.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all these exceptions we're introducing to please some specific UX affordance are really not helping. We keep constructing and deconstructing. I'm not sure how to solve it personally but I think we should consider scaling back UX wise maybe and trying to systemize these changes. It's really not clear to me why we're treating template parts differently than reusable blocks. We should (at least in our minds) consider these two things the same.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll look into the template part / synced pattern disparity in a separate PR so design folk can be brought into a more focused conversation. My feeling is it might also take some improvements to both blocks to land in a happy place, but we'll see. I'm happy to discuss possibilities around
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
#68042 is the PR. Actually it does highlight something. Giving Site Title/Logo the We likely need some additional mechanic to make this work. |
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When editing a page (with 'Show template' on) in write mode, template parts are now 'disabled' (because they're not set to 'contentOnly').
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was just wondering about this, and what
navigationModeeven means in this context.So in this third useEffect, it sets template part blocks to content-only mode if not in navigation mode (which seems to be another term for write mode)?