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

Fix synced pattern editing in write mode and refactor block editing mode to reducer #67026

Draft
wants to merge 29 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4c7653a
Add higher order reducer for pattern block editing modes.
talldan Nov 12, 2024
e19dfa3
Add higher order reducer for block editing modes while section editing
talldan Nov 14, 2024
828d50c
Handle RESET_ZOOM_LEVEL action
talldan Nov 12, 2024
8d92546
Bug fixes
talldan Nov 14, 2024
758fa60
Avoid mutating `state` in new higher order reducers
talldan Nov 15, 2024
e1d6ca4
Try moving synced pattern client ids into a separate reducer
talldan Nov 15, 2024
1721a7a
Revert "Try moving synced pattern client ids into a separate reducer"
talldan Nov 15, 2024
c40fac0
Try amalgamating the different derived block editing modes
talldan Nov 15, 2024
edc59fe
Fixes
talldan Nov 15, 2024
38ac49c
Fix synced patterns in write mode, unbound content blocks being editable
talldan Nov 15, 2024
ea18275
Also update derived block editing mode on `REPLACE_INNER_BLOCKS
talldan Nov 18, 2024
49d0386
Fix descending through controlled inner blocks
talldan Nov 18, 2024
4378c0d
Fix nested pattern handling - always process synced patterns in the r…
talldan Nov 18, 2024
38a3ab3
Zoomed out fixes - content should never be editable in zoomed out, ev…
talldan Nov 18, 2024
a43d368
Docs
talldan Nov 18, 2024
4f44c44
Add end to end test
talldan Nov 18, 2024
d636bac
Remove navigation mode selector tests
talldan Nov 18, 2024
a599a3d
Fix partial mocking of blocks package
talldan Nov 18, 2024
60887f7
Add test for isContentBlock
talldan Nov 19, 2024
4ad95bc
Add unit tests
talldan Nov 19, 2024
eb11d91
Remove defaultBlockEditingMode concept
talldan Nov 20, 2024
06c50db
Handle patterns that are outside sections in nav mode
talldan Nov 20, 2024
9493ab9
Remove comment
talldan Nov 20, 2024
b183f7f
Refactor to handle tree subsections
talldan Nov 20, 2024
c8bcf35
Optimize each individual action
talldan Nov 20, 2024
3dfba9a
Fixes and refinements
talldan Nov 20, 2024
8207486
Comments and renamings
talldan Nov 20, 2024
da87cbc
Fix useBlockSync test
talldan Nov 20, 2024
6f69a32
Remove test mocking - else test chokes trying to unlock privateApis
talldan Nov 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const blockLabelMap = {
};

jest.mock( '@wordpress/blocks', () => {
const actualImplementation = jest.requireActual( '@wordpress/blocks' );
return {
...actualImplementation,
isReusableBlock( { title } ) {
return title === 'Reusable Block';
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jest.mock( '../../../store/actions', () => {
...actions,
resetBlocks: jest.fn( actions.resetBlocks ),
replaceInnerBlocks: jest.fn( actions.replaceInnerBlocks ),
setHasControlledInnerBlocks: jest.fn( actions.replaceInnerBlocks ),
setHasControlledInnerBlocks: jest.fn(
actions.setHasControlledInnerBlocks
),
};
} );

Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1669,14 +1669,16 @@ export const setNavigationMode =
*/
export const __unstableSetEditorMode =
( mode ) =>
( { registry } ) => {
( { registry, dispatch } ) => {
registry.dispatch( preferencesStore ).set( 'core', 'editorTool', mode );

if ( mode === 'navigation' ) {
speak( __( 'You are currently in Write mode.' ) );
} else if ( mode === 'edit' ) {
speak( __( 'You are currently in Design mode.' ) );
}

dispatch( { type: 'SET_EDITOR_MODE', mode } );
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the one that I'm not sure about because some people could call registry.dispatch( preferencesStore ).set( 'core', 'editorTool', mode ); directly. Maybe it's fine I don't know

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a good point, though I guess the spoken messages also won't work when changing the mode that way. Some options:

  • (I think you mentioned this one) Always calculate the block editing modes for write mode even when in design mode, then the selector can choose the right one. This'd be a shame as I expect it'd cause a performance hit.
  • Add a listener (probably an effect) that reacts to the preference change and sets the mode in the block editor store.
  • Make the preference key private so that it can only be called internally. I think this preference has already shipped in the plugin, so it would need some back compat wrangling. Possibly my preferred solution though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, what happens on "init"? which mode is used?

I may be leaning towards the first option personally to decouple the preference setting entirely from the computation of the mode.

};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function getEnabledClientIdsTreeUnmemoized( state, rootClientId ) {
export const getEnabledClientIdsTree = createRegistrySelector( ( select ) =>
createSelector( getEnabledClientIdsTreeUnmemoized, ( state ) => [
Copy link
Contributor

Choose a reason for hiding this comment

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

I think some of the dependencies here can probably be removed because they're not used in the selector anymore. But I don't expect that it impacts anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I'll take a look!

state.blocks.order,
state.derivedBlockEditingModes,
state.blockEditingModes,
state.settings.templateLock,
state.blockListSettings,
Expand Down
Loading
Loading