Skip to content

Commit

Permalink
Fix synced pattern editing in write mode and refactor block editing m…
Browse files Browse the repository at this point in the history
…ode to reducer (#67026)

* Add higher order reducer for pattern block editing modes.

- Remove the prev. React effect for managing pattern block editing modes
- Implement higher order reducer in the block editor store ... it:
    - Tracks the clientIds of pattern blocks.
    - Uses the pattern block clientIds to manage block editing modes
      for pattern blocks and their inner blocks.
    - Updates both on any actions that change block lists.

* Add higher order reducer for block editing modes while section editing

* Handle RESET_ZOOM_LEVEL action

* Bug fixes

* Avoid mutating `state` in new higher order reducers

* Try moving synced pattern client ids into a separate reducer

* Revert "Try moving synced pattern client ids into a separate reducer"

This reverts commit e1d6ca4.

It doesn't really work, since reducer won't have access to `state.blocks.tree`.

* Try amalgamating the different derived block editing modes

* Fixes

* Fix synced patterns in write mode, unbound content blocks being editable

* Also update derived block editing mode on `REPLACE_INNER_BLOCKS

* Fix descending through controlled inner blocks

* Fix nested pattern handling - always process synced patterns in the reducer. Add special handling for only adding pattern block itself as content only when not in zoomed out or nav mode

* Zoomed out fixes - content should never be editable in zoomed out, even synced pattern overrides or when write mode is active

* Docs

* Add end to end test

* Remove navigation mode selector tests

* Fix partial mocking of blocks package

* Add test for isContentBlock

* Add unit tests

* Remove defaultBlockEditingMode concept

* Handle patterns that are outside sections in nav mode

* Remove comment

* Refactor to handle tree subsections

* Optimize each individual action

* Fixes and refinements

* Comments and renamings

* Remove test mocking - else test chokes trying to unlock privateApis

* Rework reducer unit tests and add more cases

* Add more tests

* Handle when the SET_HAS_CONTROLLED_INNER_BLOCKS block has been removed from the state

* Inline editing mode calculation for individual blocks

* Calculate both the regular and nav mode derived block editing modes at the same time

* Update getEnabledClientIdsTree dependencies

* Fix tests

* Update more tests

* Enable write mode experiment for e2e pattern overrides block editing mode tests

----

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: draganescu <andraganescu@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
  • Loading branch information
6 people authored Nov 28, 2024
1 parent 756cfe0 commit 9a9af21
Show file tree
Hide file tree
Showing 14 changed files with 1,908 additions and 340 deletions.
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
12 changes: 6 additions & 6 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ function getEnabledClientIdsTreeUnmemoized( state, rootClientId ) {
*
* @return {Object[]} Tree of block objects with only clientID and innerBlocks set.
*/
export const getEnabledClientIdsTree = createRegistrySelector( ( select ) =>
createSelector( getEnabledClientIdsTreeUnmemoized, ( state ) => [
export const getEnabledClientIdsTree = createSelector(
getEnabledClientIdsTreeUnmemoized,
( state ) => [
state.blocks.order,
state.derivedBlockEditingModes,
state.derivedNavModeBlockEditingModes,
state.blockEditingModes,
state.settings.templateLock,
state.blockListSettings,
select( STORE_NAME ).__unstableGetEditorMode( state ),
state.zoomLevel,
getSectionRootClientId( state ),
] )
]
);

/**
Expand Down
Loading

0 comments on commit 9a9af21

Please sign in to comment.