@wordpress/block-editor 8.0.10 → 8.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/store/reducer.js +10 -82
- package/build/store/reducer.js.map +1 -1
- package/build-module/store/reducer.js +11 -83
- package/build-module/store/reducer.js.map +1 -1
- package/package.json +3 -3
- package/src/store/reducer.js +13 -104
package/src/store/reducer.js
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
isEmpty,
|
|
15
15
|
identity,
|
|
16
16
|
omitBy,
|
|
17
|
-
pickBy,
|
|
18
17
|
} from 'lodash';
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -122,48 +121,6 @@ function getFlattenedBlockAttributes( blocks ) {
|
|
|
122
121
|
return flattenBlocks( blocks, ( block ) => block.attributes );
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
/**
|
|
126
|
-
* Given a block order map object, returns *all* of the block client IDs that are
|
|
127
|
-
* a descendant of the given root client ID.
|
|
128
|
-
*
|
|
129
|
-
* Calling this with `rootClientId` set to `''` results in a list of client IDs
|
|
130
|
-
* that are in the post. That is, it excludes blocks like fetched reusable
|
|
131
|
-
* blocks which are stored into state but not visible. It also excludes
|
|
132
|
-
* InnerBlocks controllers, like template parts.
|
|
133
|
-
*
|
|
134
|
-
* It is important to exclude the full inner block controller and not just the
|
|
135
|
-
* inner blocks because in many cases, we need to persist the previous value of
|
|
136
|
-
* an inner block controller. To do so, it must be excluded from the list of
|
|
137
|
-
* client IDs which are considered to be part of the top-level entity.
|
|
138
|
-
*
|
|
139
|
-
* @param {Object} blocksOrder Object that maps block client IDs to a list of
|
|
140
|
-
* nested block client IDs.
|
|
141
|
-
* @param {?string} rootClientId The root client ID to search. Defaults to ''.
|
|
142
|
-
* @param {?Object} controlledInnerBlocks The InnerBlocks controller state.
|
|
143
|
-
*
|
|
144
|
-
* @return {Array} List of descendant client IDs.
|
|
145
|
-
*/
|
|
146
|
-
function getNestedBlockClientIds(
|
|
147
|
-
blocksOrder,
|
|
148
|
-
rootClientId = '',
|
|
149
|
-
controlledInnerBlocks = {}
|
|
150
|
-
) {
|
|
151
|
-
return reduce(
|
|
152
|
-
blocksOrder[ rootClientId ],
|
|
153
|
-
( result, clientId ) => {
|
|
154
|
-
if ( !! controlledInnerBlocks[ clientId ] ) {
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
return [
|
|
158
|
-
...result,
|
|
159
|
-
clientId,
|
|
160
|
-
...getNestedBlockClientIds( blocksOrder, clientId ),
|
|
161
|
-
];
|
|
162
|
-
},
|
|
163
|
-
[]
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
124
|
/**
|
|
168
125
|
* Returns an object against which it is safe to perform mutating operations,
|
|
169
126
|
* given the original object and its current working copy.
|
|
@@ -369,9 +326,14 @@ const withBlockTree = ( reducer ) => ( state = {}, action ) => {
|
|
|
369
326
|
...omit(
|
|
370
327
|
newState.tree,
|
|
371
328
|
action.replacedClientIds.concat(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
329
|
+
// Controlled inner blocks are only removed
|
|
330
|
+
// if the block doesn't move to another position
|
|
331
|
+
// otherwise their content will be lost.
|
|
332
|
+
action.replacedClientIds
|
|
333
|
+
.filter( ( clientId ) => ! subTree[ clientId ] )
|
|
334
|
+
.map(
|
|
335
|
+
( clientId ) => 'controlled||' + clientId
|
|
336
|
+
)
|
|
375
337
|
)
|
|
376
338
|
),
|
|
377
339
|
...subTree,
|
|
@@ -637,70 +599,17 @@ const withInnerBlocksRemoveCascade = ( reducer ) => ( state, action ) => {
|
|
|
637
599
|
*/
|
|
638
600
|
const withBlockReset = ( reducer ) => ( state, action ) => {
|
|
639
601
|
if ( action.type === 'RESET_BLOCKS' ) {
|
|
640
|
-
/**
|
|
641
|
-
* A list of client IDs associated with the top level entity (like a
|
|
642
|
-
* post or template). It excludes the client IDs of blocks associated
|
|
643
|
-
* with other entities, like inner block controllers or reusable blocks.
|
|
644
|
-
*/
|
|
645
|
-
const visibleClientIds = getNestedBlockClientIds(
|
|
646
|
-
state?.order ?? {},
|
|
647
|
-
'',
|
|
648
|
-
state?.controlledInnerBlocks ?? {}
|
|
649
|
-
);
|
|
650
|
-
|
|
651
|
-
// pickBy returns only the truthy values from controlledInnerBlocks
|
|
652
|
-
const controlledInnerBlocks = Object.keys(
|
|
653
|
-
pickBy( state?.controlledInnerBlocks ?? {} )
|
|
654
|
-
);
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* Each update operation consists of a few parts:
|
|
658
|
-
* 1. First, the client IDs associated with the top level entity are
|
|
659
|
-
* removed from the existing state key, leaving in place controlled
|
|
660
|
-
* blocks (like reusable blocks and inner block controllers).
|
|
661
|
-
* 2. Second, the blocks from the reset action are used to calculate the
|
|
662
|
-
* individual state keys. This will re-populate the clientIDs which
|
|
663
|
-
* were removed in step 1.
|
|
664
|
-
* 3. In some cases, we remove the recalculated inner block controllers,
|
|
665
|
-
* letting their old values persist. We need to do this because the
|
|
666
|
-
* reset block action from a top-level entity is not aware of any
|
|
667
|
-
* inner blocks inside InnerBlock controllers. So if the new values
|
|
668
|
-
* were used, it would not take into account the existing InnerBlocks
|
|
669
|
-
* which already exist in the state for inner block controllers. For
|
|
670
|
-
* example, `attributes` uses the newly computed value for controllers
|
|
671
|
-
* since attributes are stored in the top-level entity. But `order`
|
|
672
|
-
* uses the previous value for the controllers since the new value
|
|
673
|
-
* does not include the order of controlled inner blocks. So if the
|
|
674
|
-
* new value was used, template parts would disappear from the editor
|
|
675
|
-
* whenever you try to undo a change in the top level entity.
|
|
676
|
-
*/
|
|
677
602
|
const newState = {
|
|
678
603
|
...state,
|
|
679
|
-
byClientId:
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
...omit( state?.attributes, visibleClientIds ),
|
|
685
|
-
...getFlattenedBlockAttributes( action.blocks ),
|
|
686
|
-
},
|
|
687
|
-
order: {
|
|
688
|
-
...omit( state?.order, visibleClientIds ),
|
|
689
|
-
...omit(
|
|
690
|
-
mapBlockOrder( action.blocks ),
|
|
691
|
-
controlledInnerBlocks
|
|
692
|
-
),
|
|
693
|
-
},
|
|
694
|
-
parents: {
|
|
695
|
-
...omit( state?.parents, visibleClientIds ),
|
|
696
|
-
...mapBlockParents( action.blocks ),
|
|
697
|
-
},
|
|
698
|
-
controlledInnerBlocks: state?.controlledInnerBlocks || {},
|
|
604
|
+
byClientId: getFlattenedBlocksWithoutAttributes( action.blocks ),
|
|
605
|
+
attributes: getFlattenedBlockAttributes( action.blocks ),
|
|
606
|
+
order: mapBlockOrder( action.blocks ),
|
|
607
|
+
parents: mapBlockParents( action.blocks ),
|
|
608
|
+
controlledInnerBlocks: {},
|
|
699
609
|
};
|
|
700
610
|
|
|
701
611
|
const subTree = buildBlockTree( newState, action.blocks );
|
|
702
612
|
newState.tree = {
|
|
703
|
-
...omit( state?.tree, visibleClientIds ),
|
|
704
613
|
...subTree,
|
|
705
614
|
// Root
|
|
706
615
|
'': {
|