Created
November 28, 2018 11:09
-
-
Save sgomes/1b38919a07ba02a0712e390fa6b263cc to your computer and use it in GitHub Desktop.
WIP block key extraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js | |
index e9817533a..6ac65cd81 100644 | |
--- a/packages/editor/src/store/reducer.js | |
+++ b/packages/editor/src/store/reducer.js | |
@@ -13,7 +13,6 @@ import { | |
omitBy, | |
keys, | |
isEqual, | |
- isEmpty, | |
overSome, | |
get, | |
} from 'lodash'; | |
@@ -47,6 +46,14 @@ const EDIT_MERGE_PROPERTIES = new Set( [ | |
'meta', | |
] ); | |
+/** | |
+ * List of keys in `block`. These will be split out as objects indexed by | |
+ * clientId. | |
+ * | |
+ * @type {Array} | |
+ */ | |
+export const BLOCK_KEYS = [ 'name', 'isValid', 'originalContent', 'attributes' ]; | |
+ | |
/** | |
* Returns a post attribute value, flattening nested rendered content using its | |
* raw value in place of its original object form. | |
@@ -110,32 +117,6 @@ function flattenBlocks( blocks, transform ) { | |
return result; | |
} | |
-/** | |
- * Given an array of blocks, returns an object containing all blocks, without | |
- * attributes, recursing into inner blocks. Keys correspond to the block client | |
- * ID, the value of which is the attributes object. | |
- * | |
- * @param {Array} blocks Blocks to flatten. | |
- * | |
- * @return {Object} Flattened block attributes object. | |
- */ | |
-function getFlattenedBlocksWithoutAttributes( blocks ) { | |
- return flattenBlocks( blocks, ( block ) => omit( block, 'attributes' ) ); | |
-} | |
- | |
-/** | |
- * Given an array of blocks, returns an object containing all block attributes, | |
- * recursing into inner blocks. Keys correspond to the block client ID, the | |
- * value of which is the attributes object. | |
- * | |
- * @param {Array} blocks Blocks to flatten. | |
- * | |
- * @return {Object} Flattened block attributes object. | |
- */ | |
-function getFlattenedBlockAttributes( blocks ) { | |
- return flattenBlocks( blocks, ( block ) => block.attributes ); | |
-} | |
- | |
/** | |
* Given a block order map object, returns *all* of the block client IDs that are | |
* a descendant of the given root client ID. | |
@@ -283,14 +264,13 @@ const withBlockReset = ( reducer ) => ( state, action ) => { | |
const visibleClientIds = getNestedBlockClientIds( state.order ); | |
return { | |
...state, | |
- byClientId: { | |
- ...omit( state.byClientId, visibleClientIds ), | |
- ...getFlattenedBlocksWithoutAttributes( action.blocks ), | |
- }, | |
- attributesByClientId: { | |
- ...omit( state.attributesByClientId, visibleClientIds ), | |
- ...getFlattenedBlockAttributes( action.blocks ), | |
- }, | |
+ ...BLOCK_KEYS.reduce( ( result, key ) => { | |
+ result[ key ] = { | |
+ ...omit( state[ key ], visibleClientIds ), | |
+ ...flattenBlocks( action.blocks, ( block ) => block[ key ] ), | |
+ }; | |
+ return result; | |
+ }, {} ), | |
order: { | |
...omit( state.order, visibleClientIds ), | |
...mapBlockOrder( action.blocks ), | |
@@ -305,7 +285,7 @@ const withBlockReset = ( reducer ) => ( state, action ) => { | |
* Higher-order reducer which targets the combined blocks reducer and handles | |
* the `SAVE_REUSABLE_BLOCK_SUCCESS` action. This action can't be handled by | |
* regular reducers and needs a higher-order reducer since it needs access to | |
- * both `byClientId` and `attributesByClientId` simultaneously. | |
+ * both `name` and `attributes` simultaneously. | |
* | |
* @param {Function} reducer Original reducer function. | |
* | |
@@ -322,8 +302,8 @@ const withSaveReusableBlock = ( reducer ) => ( state, action ) => { | |
state = { ...state }; | |
- state.attributesByClientId = mapValues( state.attributesByClientId, ( attributes, clientId ) => { | |
- const { name } = state.byClientId[ clientId ]; | |
+ state.attributes = mapValues( state.attributes, ( attributes, clientId ) => { | |
+ const name = state.name[ clientId ]; | |
if ( name === 'core/block' && attributes.ref === id ) { | |
return { | |
...attributes, | |
@@ -338,6 +318,99 @@ const withSaveReusableBlock = ( reducer ) => ( state, action ) => { | |
return reducer( state, action ); | |
}; | |
+const processAttributeUpdate = ( state, action, attributes ) => { | |
+ return reduce( attributes, ( result, value, att ) => { | |
+ if ( value !== result[ att ] ) { | |
+ result = getMutateSafeObject( state[ action.clientId ], result ); | |
+ result[ att ] = value; | |
+ } | |
+ | |
+ return result; | |
+ }, state[ action.clientId ] ); | |
+}; | |
+ | |
+const onBlockKey = ( key ) => ( state = {}, action ) => { | |
+ const getFlatBlocks = () => flattenBlocks( action.blocks, ( block ) => block[ key ] ); | |
+ | |
+ switch ( action.type ) { | |
+ case 'SETUP_EDITOR_STATE': | |
+ return getFlatBlocks(); | |
+ | |
+ case 'RECEIVE_BLOCKS': | |
+ return { | |
+ ...state, | |
+ ...getFlatBlocks(), | |
+ }; | |
+ | |
+ case 'UPDATE_BLOCK': | |
+ // Ignore updates if block isn't known | |
+ if ( ! ( action.clientId in state ) ) { | |
+ return state; | |
+ } | |
+ | |
+ // Do nothing if this key isn't changing. | |
+ let changes = action.updates[ key ]; | |
+ if ( changes === undefined ) { | |
+ return state; | |
+ } | |
+ | |
+ // For attributes, since they're an object, some extra work is needed. | |
+ if ( key === 'attributes' ) { | |
+ changes = processAttributeUpdate( state, action, action.updates.attributes ); | |
+ | |
+ // Skip update if nothing has been changed (the reference will match). | |
+ if ( changes === state[ action.clientId ] ) { | |
+ return state; | |
+ } | |
+ } | |
+ | |
+ // Replace attributes in state | |
+ return { | |
+ ...state, | |
+ [ action.clientId ]: changes, | |
+ }; | |
+ | |
+ case 'UPDATE_BLOCK_ATTRIBUTES': | |
+ // Ignore updates if block isn't known, or if any key other than attributes. | |
+ if ( ! state[ action.clientId ] || key !== 'attributes' ) { | |
+ return state; | |
+ } | |
+ | |
+ const nextAttributes = processAttributeUpdate( state, action, action.attributes ); | |
+ // Skip update if nothing has been changed (the reference will match). | |
+ if ( nextAttributes === state[ action.clientId ] ) { | |
+ return state; | |
+ } | |
+ | |
+ // Otherwise replace attributes in state | |
+ return { | |
+ ...state, | |
+ [ action.clientId ]: nextAttributes, | |
+ }; | |
+ | |
+ case 'INSERT_BLOCKS': | |
+ return { | |
+ ...state, | |
+ ...getFlatBlocks(), | |
+ }; | |
+ | |
+ case 'REPLACE_BLOCKS': | |
+ if ( ! action.blocks ) { | |
+ return state; | |
+ } | |
+ | |
+ return { | |
+ ...omit( state, action.clientIds ), | |
+ ...getFlatBlocks(), | |
+ }; | |
+ | |
+ case 'REMOVE_BLOCKS': | |
+ return omit( state, action.clientIds ); | |
+ } | |
+ | |
+ return state; | |
+}; | |
+ | |
/** | |
* Undoable reducer returning the editor post state, including blocks parsed | |
* from current HTML markup. | |
@@ -425,7 +498,11 @@ export const editor = flow( [ | |
ignoreTypes: [ 'RECEIVE_BLOCKS', 'RESET_POST', 'UPDATE_POST' ], | |
} ), | |
] )( { | |
- byClientId( state = {}, action ) { | |
+ ...BLOCK_KEYS.reduce( ( reducers, key ) => { | |
+ reducers[ key ] = onBlockKey( key ); | |
+ return reducers; | |
+ }, {} ), | |
+ /*byClientId( state = {}, action ) { | |
switch ( action.type ) { | |
case 'SETUP_EDITOR_STATE': | |
return getFlattenedBlocksWithoutAttributes( action.blocks ); | |
@@ -553,7 +630,7 @@ export const editor = flow( [ | |
} | |
return state; | |
- }, | |
+ },*/ | |
order( state = {}, action ) { | |
switch ( action.type ) { | |
diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js | |
index a507f415b..256ce236c 100644 | |
--- a/packages/editor/src/store/selectors.js | |
+++ b/packages/editor/src/store/selectors.js | |
@@ -39,6 +39,7 @@ import { addQueryArgs } from '@wordpress/url'; | |
* Dependencies | |
*/ | |
import { PREFERENCES_DEFAULTS } from './defaults'; | |
+import { BLOCK_KEYS } from './reducer'; | |
/*** | |
* Module constants | |
@@ -595,8 +596,7 @@ export const getBlockDependantsCacheBust = createSelector( | |
* @return {string} Block name. | |
*/ | |
export function getBlockName( state, clientId ) { | |
- const block = state.editor.present.blocks.byClientId[ clientId ]; | |
- return block ? block.name : null; | |
+ return state.editor.present.blocks.name[ clientId ] || null; | |
} | |
/** | |
@@ -608,8 +608,7 @@ export function getBlockName( state, clientId ) { | |
* @return {boolean} Is Valid. | |
*/ | |
export function isBlockValid( state, clientId ) { | |
- const block = state.editor.present.blocks.byClientId[ clientId ]; | |
- return !! block && block.isValid; | |
+ return !! state.editor.present.blocks.isValid[ clientId ]; | |
} | |
/** | |
@@ -625,17 +624,22 @@ export function isBlockValid( state, clientId ) { | |
*/ | |
export const getBlock = createSelector( | |
( state, clientId ) => { | |
- const block = state.editor.present.blocks.byClientId[ clientId ]; | |
- if ( ! block ) { | |
+ const name = state.editor.present.blocks.name[ clientId ]; | |
+ if ( ! name ) { | |
return null; | |
} | |
- let attributes = state.editor.present.blocks.attributesByClientId[ clientId ]; | |
+ const block = BLOCK_KEYS.reduce( ( result, key ) => { | |
+ result[ key ] = state.editor.present.blocks[ key ] && | |
+ state.editor.present.blocks[ key ][ clientId ]; | |
+ return result; | |
+ }, {} ); | |
// Inject custom source attribute values. | |
// | |
// TODO: Create generic external sourcing pattern, not explicitly | |
// targeting meta attributes. | |
+ let attributes = state.editor.present.blocks.attributes[ clientId ]; | |
const type = getBlockType( block.name ); | |
if ( type ) { | |
attributes = reduce( type.attributes, ( result, value, key ) => { | |
@@ -653,15 +657,16 @@ export const getBlock = createSelector( | |
return { | |
...block, | |
+ clientId, | |
attributes, | |
innerBlocks: getBlocks( state, clientId ), | |
}; | |
}, | |
( state, clientId ) => [ | |
- state.editor.present.blocks.byClientId[ clientId ], | |
- state.editor.present.blocks.attributesByClientId[ clientId ], | |
- getBlockDependantsCacheBust( state, clientId ), | |
+ ...BLOCK_KEYS.map( ( key ) => state.editor.present.blocks[ key ] && | |
+ state.editor.present.blocks[ key ][ clientId ] ), | |
state.editor.present.blocks.order[ clientId ], | |
+ getBlockDependantsCacheBust( state, clientId ), | |
state.editor.present.edits.meta, | |
state.initialEdits.meta, | |
state.currentPost.meta, | |
@@ -753,13 +758,13 @@ export const getGlobalBlockCount = createSelector( | |
return clientIds.length; | |
} | |
return reduce( clientIds, ( count, clientId ) => { | |
- const block = state.editor.present.blocks.byClientId[ clientId ]; | |
- return block.name === blockName ? count + 1 : count; | |
+ const name = state.editor.present.blocks.name[ clientId ]; | |
+ return name === blockName ? count + 1 : count; | |
}, 0 ); | |
}, | |
( state ) => [ | |
state.editor.present.blocks.order, | |
- state.editor.present.blocks.byClientId, | |
+ state.editor.present.blocks.name, | |
] | |
); | |
@@ -865,7 +870,7 @@ export function getSelectedBlockClientId( state ) { | |
// We need to check the block exists because the current state.blockSelection reducer | |
// doesn't take into account the UNDO / REDO actions to update selection. | |
// To be removed when that's fixed. | |
- return start && start === end && !! state.editor.present.blocks.byClientId[ start ] ? start : null; | |
+ return start && start === end && !! state.editor.present.blocks.name[ start ] ? start : null; | |
} | |
/** | |
@@ -1744,7 +1749,7 @@ export const canInsertBlockType = createSelector( | |
canInsertBlockTypeUnmemoized, | |
( state, blockName, rootClientId ) => [ | |
state.blockListSettings[ rootClientId ], | |
- state.editor.present.blocks.byClientId[ rootClientId ], | |
+ state.editor.present.blocks.name[ rootClientId ], | |
state.settings.allowedBlockTypes, | |
state.settings.templateLock, | |
], | |
@@ -1954,7 +1959,7 @@ export const getInserterItems = createSelector( | |
}, | |
( state, rootClientId ) => [ | |
state.blockListSettings[ rootClientId ], | |
- state.editor.present.blocks.byClientId, | |
+ state.editor.present.blocks.name, | |
state.editor.present.blocks.order, | |
state.preferences.insertUsage, | |
state.settings.allowedBlockTypes, | |
@@ -1989,7 +1994,8 @@ export const hasInserterItems = createSelector( | |
}, | |
( state, rootClientId ) => [ | |
state.blockListSettings[ rootClientId ], | |
- state.editor.present.blocks.byClientId, | |
+ state.editor.present.blocks.name, | |
+ state.editor.present.blocks.order, | |
state.settings.allowedBlockTypes, | |
state.settings.templateLock, | |
state.reusableBlocks.data, | |
diff --git a/packages/editor/src/store/test/reducer.js b/packages/editor/src/store/test/reducer.js | |
index 2ab1446c4..32992333b 100644 | |
--- a/packages/editor/src/store/test/reducer.js | |
+++ b/packages/editor/src/store/test/reducer.js | |
@@ -285,7 +285,7 @@ describe( 'state', () => { | |
expect( state.past ).toEqual( [] ); | |
expect( state.future ).toEqual( [] ); | |
expect( state.present.edits ).toEqual( {} ); | |
- expect( state.present.blocks.byClientId ).toEqual( {} ); | |
+ expect( state.present.blocks.name ).toEqual( {} ); | |
expect( state.present.blocks.order ).toEqual( {} ); | |
expect( state.present.blocks.isDirty ).toBe( false ); | |
} ); | |
@@ -294,11 +294,11 @@ describe( 'state', () => { | |
const original = editor( undefined, {} ); | |
const state = editor( original, { | |
type: 'RESET_BLOCKS', | |
- blocks: [ { clientId: 'bananas', innerBlocks: [] } ], | |
+ blocks: [ { clientId: 'bananas', name: 'fruit', innerBlocks: [] } ], | |
} ); | |
- expect( Object.keys( state.present.blocks.byClientId ) ).toHaveLength( 1 ); | |
- expect( values( state.present.blocks.byClientId )[ 0 ].clientId ).toBe( 'bananas' ); | |
+ expect( Object.keys( state.present.blocks.name ) ).toHaveLength( 1 ); | |
+ expect( values( state.present.blocks.name )[ 0 ] ).toBe( 'fruit' ); | |
expect( state.present.blocks.order ).toEqual( { | |
'': [ 'bananas' ], | |
bananas: [], | |
@@ -315,7 +315,7 @@ describe( 'state', () => { | |
} ], | |
} ); | |
- expect( Object.keys( state.present.blocks.byClientId ) ).toHaveLength( 2 ); | |
+ expect( Object.keys( state.present.blocks.name ) ).toHaveLength( 2 ); | |
expect( state.present.blocks.order ).toEqual( { | |
'': [ 'bananas' ], | |
apples: [], | |
@@ -342,8 +342,8 @@ describe( 'state', () => { | |
} ], | |
} ); | |
- expect( Object.keys( state.present.blocks.byClientId ) ).toHaveLength( 2 ); | |
- expect( values( state.present.blocks.byClientId )[ 1 ].clientId ).toBe( 'ribs' ); | |
+ expect( Object.keys( state.present.blocks.name ) ).toHaveLength( 2 ); | |
+ expect( values( state.present.blocks.name )[ 1 ] ).toBe( 'core/freeform' ); | |
expect( state.present.blocks.order ).toEqual( { | |
'': [ 'chicken', 'ribs' ], | |
chicken: [], | |
@@ -371,9 +371,8 @@ describe( 'state', () => { | |
} ], | |
} ); | |
- expect( Object.keys( state.present.blocks.byClientId ) ).toHaveLength( 1 ); | |
- expect( values( state.present.blocks.byClientId )[ 0 ].name ).toBe( 'core/freeform' ); | |
- expect( values( state.present.blocks.byClientId )[ 0 ].clientId ).toBe( 'wings' ); | |
+ expect( Object.keys( state.present.blocks.name ) ).toHaveLength( 1 ); | |
+ expect( values( state.present.blocks.name )[ 0 ] ).toBe( 'core/freeform' ); | |
expect( state.present.blocks.order ).toEqual( { | |
'': [ 'wings' ], | |
wings: [], | |
@@ -422,10 +421,9 @@ describe( 'state', () => { | |
} ], | |
} ); | |
- expect( Object.keys( replacedState.present.blocks.byClientId ) ).toHaveLength( 1 ); | |
- expect( values( originalState.present.blocks.byClientId )[ 0 ].name ).toBe( 'core/test-block' ); | |
- expect( values( replacedState.present.blocks.byClientId )[ 0 ].name ).toBe( 'core/freeform' ); | |
- expect( values( replacedState.present.blocks.byClientId )[ 0 ].clientId ).toBe( 'chicken' ); | |
+ expect( Object.keys( replacedState.present.blocks.name ) ).toHaveLength( 1 ); | |
+ expect( values( originalState.present.blocks.name )[ 0 ] ).toBe( 'core/test-block' ); | |
+ expect( values( replacedState.present.blocks.name )[ 0 ] ).toBe( 'core/freeform' ); | |
expect( replacedState.present.blocks.order ).toEqual( { | |
'': [ 'chicken' ], | |
chicken: [], | |
@@ -462,8 +460,8 @@ describe( 'state', () => { | |
[ replacementNestedBlock.clientId ]: [], | |
} ); | |
- expect( originalNestedState.present.blocks.byClientId.chicken.name ).toBe( 'core/test-block' ); | |
- expect( replacedNestedState.present.blocks.byClientId.chicken.name ).toBe( 'core/freeform' ); | |
+ expect( originalNestedState.present.blocks.name.chicken ).toBe( 'core/test-block' ); | |
+ expect( replacedNestedState.present.blocks.name.chicken ).toBe( 'core/freeform' ); | |
} ); | |
it( 'should update the block', () => { | |
@@ -486,13 +484,9 @@ describe( 'state', () => { | |
}, | |
} ); | |
- expect( state.present.blocks.byClientId.chicken ).toEqual( { | |
- clientId: 'chicken', | |
- name: 'core/test-block', | |
- isValid: true, | |
- } ); | |
- | |
- expect( state.present.blocks.attributesByClientId.chicken ).toEqual( { | |
+ expect( state.present.blocks.name.chicken ).toEqual( 'core/test-block' ); | |
+ expect( state.present.blocks.isValid.chicken ).toEqual( true ); | |
+ expect( state.present.blocks.attributes.chicken ).toEqual( { | |
content: 'ribs', | |
} ); | |
} ); | |
@@ -517,13 +511,9 @@ describe( 'state', () => { | |
updatedId: 3, | |
} ); | |
- expect( state.present.blocks.byClientId.chicken ).toEqual( { | |
- clientId: 'chicken', | |
- name: 'core/block', | |
- isValid: false, | |
- } ); | |
- | |
- expect( state.present.blocks.attributesByClientId.chicken ).toEqual( { | |
+ expect( state.present.blocks.name.chicken ).toEqual( 'core/block' ); | |
+ expect( state.present.blocks.isValid.chicken ).toEqual( false ); | |
+ expect( state.present.blocks.attributes.chicken ).toEqual( { | |
ref: 3, | |
} ); | |
} ); | |
@@ -790,13 +780,10 @@ describe( 'state', () => { | |
expect( state.present.blocks.order[ '' ] ).toEqual( [ 'ribs' ] ); | |
expect( state.present.blocks.order ).not.toHaveProperty( 'chicken' ); | |
- expect( state.present.blocks.byClientId ).toEqual( { | |
- ribs: { | |
- clientId: 'ribs', | |
- name: 'core/test-block', | |
- }, | |
+ expect( state.present.blocks.name ).toEqual( { | |
+ ribs: 'core/test-block', | |
} ); | |
- expect( state.present.blocks.attributesByClientId ).toEqual( { | |
+ expect( state.present.blocks.attributes ).toEqual( { | |
ribs: {}, | |
} ); | |
} ); | |
@@ -829,13 +816,10 @@ describe( 'state', () => { | |
expect( state.present.blocks.order[ '' ] ).toEqual( [ 'ribs' ] ); | |
expect( state.present.blocks.order ).not.toHaveProperty( 'chicken' ); | |
expect( state.present.blocks.order ).not.toHaveProperty( 'veggies' ); | |
- expect( state.present.blocks.byClientId ).toEqual( { | |
- ribs: { | |
- clientId: 'ribs', | |
- name: 'core/test-block', | |
- }, | |
+ expect( state.present.blocks.name ).toEqual( { | |
+ ribs: 'core/test-block', | |
} ); | |
- expect( state.present.blocks.attributesByClientId ).toEqual( { | |
+ expect( state.present.blocks.attributes ).toEqual( { | |
ribs: {}, | |
} ); | |
} ); | |
@@ -857,7 +841,7 @@ describe( 'state', () => { | |
clientIds: [ block.clientId ], | |
} ); | |
- expect( state.present.blocks.byClientId ).toEqual( {} ); | |
+ expect( state.present.blocks.name ).toEqual( {} ); | |
expect( state.present.blocks.order ).toEqual( { | |
'': [], | |
} ); | |
@@ -889,7 +873,7 @@ describe( 'state', () => { | |
} ], | |
} ); | |
- expect( Object.keys( state.present.blocks.byClientId ) ).toHaveLength( 3 ); | |
+ expect( Object.keys( state.present.blocks.name ) ).toHaveLength( 3 ); | |
expect( state.present.blocks.order[ '' ] ).toEqual( [ 'kumquat', 'persimmon', 'loquat' ] ); | |
} ); | |
@@ -1208,17 +1192,17 @@ describe( 'state', () => { | |
], | |
} ); | |
- expect( state.present.blocks.byClientId ).toEqual( { | |
- block2: { clientId: 'block2' }, | |
- block21: { clientId: 'block21' }, | |
- block22: { clientId: 'block22' }, | |
- block3: { clientId: 'block3' }, | |
- block31: { clientId: 'block31' }, | |
- block32: { clientId: 'block32' }, | |
- } ); | |
+ expect( Object.keys( state.present.blocks.name ).sort() ).toEqual( [ | |
+ 'block2', | |
+ 'block21', | |
+ 'block22', | |
+ 'block3', | |
+ 'block31', | |
+ 'block32', | |
+ ] ); | |
} ); | |
- describe( 'byClientId', () => { | |
+ describe( 'name', () => { | |
it( 'should ignore updates to non-existent block', () => { | |
const original = deepFreeze( editor( undefined, { | |
type: 'RESET_BLOCKS', | |
@@ -1232,7 +1216,7 @@ describe( 'state', () => { | |
}, | |
} ); | |
- expect( state.present.blocks.byClientId ).toBe( original.present.blocks.byClientId ); | |
+ expect( state.present.blocks.name ).toBe( original.present.blocks.name ); | |
} ); | |
it( 'should return with same reference if no changes in updates', () => { | |
@@ -1254,11 +1238,11 @@ describe( 'state', () => { | |
}, | |
} ); | |
- expect( state.present.blocks.byClientId ).toBe( state.present.blocks.byClientId ); | |
+ expect( state.present.blocks.name ).toBe( state.present.blocks.name ); | |
} ); | |
} ); | |
- describe( 'attributesByClientId', () => { | |
+ describe( 'attributes', () => { | |
it( 'should return with attribute block updates', () => { | |
const original = deepFreeze( editor( undefined, { | |
type: 'RESET_BLOCKS', | |
@@ -1276,7 +1260,7 @@ describe( 'state', () => { | |
}, | |
} ); | |
- expect( state.present.blocks.attributesByClientId.kumquat.updated ).toBe( true ); | |
+ expect( state.present.blocks.attributes.kumquat.updated ).toBe( true ); | |
} ); | |
it( 'should accumulate attribute block updates', () => { | |
@@ -1298,7 +1282,7 @@ describe( 'state', () => { | |
}, | |
} ); | |
- expect( state.present.blocks.attributesByClientId.kumquat ).toEqual( { | |
+ expect( state.present.blocks.attributes.kumquat ).toEqual( { | |
updated: true, | |
moreUpdated: true, | |
} ); | |
@@ -1317,7 +1301,7 @@ describe( 'state', () => { | |
}, | |
} ); | |
- expect( state.present.blocks.attributesByClientId ).toBe( original.present.blocks.attributesByClientId ); | |
+ expect( state.present.blocks.attributes ).toBe( original.present.blocks.attributes ); | |
} ); | |
it( 'should return with same reference if no changes in updates', () => { | |
@@ -1339,7 +1323,7 @@ describe( 'state', () => { | |
}, | |
} ); | |
- expect( state.present.blocks.attributesByClientId ).toBe( state.present.blocks.attributesByClientId ); | |
+ expect( state.present.blocks.attributes ).toBe( state.present.blocks.attributes ); | |
} ); | |
} ); | |
} ); | |
diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js | |
index 61db20e9d..5a334d4d5 100644 | |
--- a/packages/editor/src/store/test/selectors.js | |
+++ b/packages/editor/src/store/test/selectors.js | |
@@ -1,7 +1,7 @@ | |
/** | |
* External dependencies | |
*/ | |
-import { filter, without, omit } from 'lodash'; | |
+import { filter, without } from 'lodash'; | |
/** | |
* WordPress dependencies | |
@@ -1123,8 +1123,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1143,8 +1143,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1167,8 +1167,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1189,8 +1189,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1211,14 +1211,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-block-a', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
text: '', | |
}, | |
@@ -1243,13 +1239,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-freeform', | |
- }, | |
+ name: { | |
+ 123: 'core/test-freeform', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
content: '', | |
}, | |
@@ -1274,14 +1267,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-freeform', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-freeform', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
content: '', | |
}, | |
@@ -1310,8 +1299,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1337,8 +1326,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1483,8 +1472,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1502,14 +1491,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-block-a', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
text: '', | |
}, | |
@@ -1533,14 +1518,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-block-a', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
text: '', | |
}, | |
@@ -1568,8 +1549,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -1589,8 +1570,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: { | |
@@ -1610,14 +1591,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-freeform', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-freeform', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
content: '', | |
}, | |
@@ -1641,14 +1618,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-freeform', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-freeform', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
content: '', | |
}, | |
@@ -1674,14 +1647,13 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-freeform', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-freeform', | |
+ }, | |
+ isValid: { | |
+ 123: true, | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
content: 'Test Data', | |
}, | |
@@ -1707,19 +1679,15 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { | |
- clientId: 123, | |
- name: 'core/test-freeform', | |
- isValid: true, | |
- }, | |
- 456: { | |
- clientId: 456, | |
- name: 'core/test-freeform', | |
- isValid: true, | |
- }, | |
+ name: { | |
+ 123: 'core/test-freeform', | |
+ 456: 'core/test-freeform', | |
+ }, | |
+ isValid: { | |
+ 123: true, | |
+ 456: true, | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: { | |
content: '', | |
}, | |
@@ -1867,27 +1835,33 @@ describe( 'selectors', () => { | |
} ); | |
describe( 'getBlockDependantsCacheBust', () => { | |
- const rootBlock = { clientId: 123, name: 'core/paragraph' }; | |
- const rootBlockAttributes = {}; | |
+ const rootName = 'core/paragraph'; | |
+ const rootAttributes = {}; | |
const rootOrder = [ 123 ]; | |
it( 'returns an unchanging reference', () => { | |
- const rootBlockOrder = []; | |
+ const order = []; | |
const state = { | |
currentPost: {}, | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
+ name: { | |
+ 123: rootName, | |
+ }, | |
+ isValid: { | |
+ 123: true, | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
+ originalContent: { | |
+ 123: '', | |
+ }, | |
+ attributes: { | |
+ 123: rootAttributes, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
+ 123: order, | |
}, | |
}, | |
edits: {}, | |
@@ -1901,15 +1875,21 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
+ name: { | |
+ 123: rootName, | |
+ }, | |
+ isValid: { | |
+ 123: true, | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
+ originalContent: { | |
+ 123: '', | |
+ }, | |
+ attributes: { | |
+ 123: rootAttributes, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
+ 123: order, | |
}, | |
}, | |
edits: {}, | |
@@ -1929,11 +1909,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
+ name: { | |
+ 123: rootName, | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
+ attributes: { | |
+ 123: rootAttributes, | |
}, | |
order: { | |
'': rootOrder, | |
@@ -1951,12 +1931,12 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
- 456: { clientId: 456, name: 'core/paragraph' }, | |
+ name: { | |
+ 123: rootName, | |
+ 456: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
+ attributes: { | |
+ 123: rootAttributes, | |
456: {}, | |
}, | |
order: { | |
@@ -1977,28 +1957,28 @@ describe( 'selectors', () => { | |
} ); | |
it( 'returns an unchanging reference on unchanging inner block', () => { | |
- const rootBlockOrder = [ 456 ]; | |
- const childBlock = { clientId: 456, name: 'core/paragraph' }; | |
- const childBlockAttributes = {}; | |
- const childBlockOrder = []; | |
+ const order = [ 456 ]; | |
+ const childName = 'core/paragraph'; | |
+ const childAttributes = {}; | |
+ const childOrder = []; | |
const state = { | |
currentPost: {}, | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
- 456: childBlock, | |
+ name: { | |
+ 123: rootName, | |
+ 456: childName, | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
- 456: childBlockAttributes, | |
+ attributes: { | |
+ 123: rootAttributes, | |
+ 456: childAttributes, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
- 456: childBlockOrder, | |
+ 123: order, | |
+ 456: childOrder, | |
}, | |
}, | |
edits: {}, | |
@@ -2012,18 +1992,18 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
- 456: childBlock, | |
+ name: { | |
+ 123: rootName, | |
+ 456: childName, | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
- 456: childBlockAttributes, | |
+ attributes: { | |
+ 123: rootAttributes, | |
+ 456: childAttributes, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
- 456: childBlockOrder, | |
+ 123: order, | |
+ 456: childOrder, | |
}, | |
}, | |
edits: {}, | |
@@ -2038,26 +2018,26 @@ describe( 'selectors', () => { | |
} ); | |
it( 'returns a new reference on updated inner block', () => { | |
- const rootBlockOrder = [ 456 ]; | |
- const childBlockOrder = []; | |
+ const order = [ 456 ]; | |
+ const childOrder = []; | |
const state = { | |
currentPost: {}, | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
- 456: { clientId: 456, name: 'core/paragraph' }, | |
+ name: { | |
+ 123: rootName, | |
+ 456: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
+ attributes: { | |
+ 123: rootAttributes, | |
456: {}, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
- 456: childBlockOrder, | |
+ 123: order, | |
+ 456: childOrder, | |
}, | |
}, | |
edits: {}, | |
@@ -2071,18 +2051,18 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
- 456: { clientId: 456, name: 'core/paragraph' }, | |
+ name: { | |
+ 123: rootName, | |
+ 456: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
+ attributes: { | |
+ 123: rootAttributes, | |
456: { content: [ 'foo' ] }, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
- 456: childBlockOrder, | |
+ 123: order, | |
+ 456: childOrder, | |
}, | |
}, | |
edits: {}, | |
@@ -2097,32 +2077,32 @@ describe( 'selectors', () => { | |
} ); | |
it( 'returns a new reference on updated grandchild inner block', () => { | |
- const rootBlockOrder = [ 456 ]; | |
- const childBlock = { clientId: 456, name: 'core/paragraph' }; | |
- const childBlockAttributes = {}; | |
- const childBlockOrder = [ 789 ]; | |
- const grandChildBlockOrder = []; | |
+ const order = [ 456 ]; | |
+ const childName = 'core/paragraph'; | |
+ const childAttributes = {}; | |
+ const childOrder = [ 789 ]; | |
+ const grandchildOrder = []; | |
const state = { | |
currentPost: {}, | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
- 456: childBlock, | |
- 789: { clientId: 789, name: 'core/paragraph' }, | |
- }, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
- 456: childBlockAttributes, | |
+ name: { | |
+ 123: rootName, | |
+ 456: childName, | |
+ 789: 'core/paragraph', | |
+ }, | |
+ attributes: { | |
+ 123: rootAttributes, | |
+ 456: childAttributes, | |
789: {}, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
- 456: childBlockOrder, | |
- 789: grandChildBlockOrder, | |
+ 123: order, | |
+ 456: childOrder, | |
+ 789: grandchildOrder, | |
}, | |
}, | |
edits: {}, | |
@@ -2136,21 +2116,21 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: rootBlock, | |
- 456: childBlock, | |
- 789: { clientId: 789, name: 'core/paragraph' }, | |
- }, | |
- attributesByClientId: { | |
- 123: rootBlockAttributes, | |
- 456: childBlockAttributes, | |
+ name: { | |
+ 123: rootName, | |
+ 456: childName, | |
+ 789: 'core/paragraph', | |
+ }, | |
+ attributes: { | |
+ 123: rootAttributes, | |
+ 456: childAttributes, | |
789: { content: [ 'foo' ] }, | |
}, | |
order: { | |
'': rootOrder, | |
- 123: rootBlockOrder, | |
- 456: childBlockOrder, | |
- 789: grandChildBlockOrder, | |
+ 123: order, | |
+ 456: childOrder, | |
+ 789: grandchildOrder, | |
}, | |
}, | |
edits: {}, | |
@@ -2172,8 +2152,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -2193,13 +2173,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': { | |
- clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', | |
- name: 'core/paragraph', | |
- }, | |
+ name: { | |
+ 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': {}, | |
}, | |
order: { | |
@@ -2226,10 +2203,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { clientId: 123, name: 'core/paragraph' }, | |
+ name: { | |
+ 123: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: {}, | |
}, | |
order: { | |
@@ -2257,8 +2234,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -2276,11 +2253,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { clientId: 123, name: 'core/paragraph' }, | |
- 456: { clientId: 456, name: 'core/paragraph' }, | |
+ name: { | |
+ 123: 'core/paragraph', | |
+ 456: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: {}, | |
456: {}, | |
}, | |
@@ -2332,10 +2309,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { clientId: 123, name: 'core/meta-block' }, | |
+ name: { | |
+ 123: 'core/meta-block', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: {}, | |
}, | |
order: { | |
@@ -2369,11 +2346,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 23: { clientId: 23, name: 'core/heading' }, | |
- 123: { clientId: 123, name: 'core/paragraph' }, | |
+ name: { | |
+ 23: 'core/heading', | |
+ 123: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
23: {}, | |
123: {}, | |
}, | |
@@ -2401,24 +2378,24 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 'uuid-2': { clientId: 'uuid-2', name: 'core/image' }, | |
- 'uuid-4': { clientId: 'uuid-4', name: 'core/paragraph' }, | |
- 'uuid-6': { clientId: 'uuid-6', name: 'core/paragraph' }, | |
- 'uuid-8': { clientId: 'uuid-8', name: 'core/block' }, | |
- 'uuid-10': { clientId: 'uuid-10', name: 'core/columns' }, | |
- 'uuid-12': { clientId: 'uuid-12', name: 'core/column' }, | |
- 'uuid-14': { clientId: 'uuid-14', name: 'core/column' }, | |
- 'uuid-16': { clientId: 'uuid-16', name: 'core/quote' }, | |
- 'uuid-18': { clientId: 'uuid-18', name: 'core/block' }, | |
- 'uuid-20': { clientId: 'uuid-20', name: 'core/gallery' }, | |
- 'uuid-22': { clientId: 'uuid-22', name: 'core/block' }, | |
- 'uuid-24': { clientId: 'uuid-24', name: 'core/columns' }, | |
- 'uuid-26': { clientId: 'uuid-26', name: 'core/column' }, | |
- 'uuid-28': { clientId: 'uuid-28', name: 'core/column' }, | |
- 'uuid-30': { clientId: 'uuid-30', name: 'core/paragraph' }, | |
- }, | |
- attributesByClientId: { | |
+ name: { | |
+ 'uuid-2': 'core/image', | |
+ 'uuid-4': 'core/paragraph', | |
+ 'uuid-6': 'core/paragraph', | |
+ 'uuid-8': 'core/block', | |
+ 'uuid-10': 'core/columns', | |
+ 'uuid-12': 'core/column', | |
+ 'uuid-14': 'core/column', | |
+ 'uuid-16': 'core/quote', | |
+ 'uuid-18': 'core/block', | |
+ 'uuid-20': 'core/gallery', | |
+ 'uuid-22': 'core/block', | |
+ 'uuid-24': 'core/columns', | |
+ 'uuid-26': 'core/column', | |
+ 'uuid-28': 'core/column', | |
+ 'uuid-30': 'core/paragraph', | |
+ }, | |
+ attributes: { | |
'uuid-2': {}, | |
'uuid-4': {}, | |
'uuid-6': {}, | |
@@ -2478,24 +2455,24 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 'uuid-2': { clientId: 'uuid-2', name: 'core/image' }, | |
- 'uuid-4': { clientId: 'uuid-4', name: 'core/paragraph' }, | |
- 'uuid-6': { clientId: 'uuid-6', name: 'core/paragraph' }, | |
- 'uuid-8': { clientId: 'uuid-8', name: 'core/block' }, | |
- 'uuid-10': { clientId: 'uuid-10', name: 'core/columns' }, | |
- 'uuid-12': { clientId: 'uuid-12', name: 'core/column' }, | |
- 'uuid-14': { clientId: 'uuid-14', name: 'core/column' }, | |
- 'uuid-16': { clientId: 'uuid-16', name: 'core/quote' }, | |
- 'uuid-18': { clientId: 'uuid-18', name: 'core/block' }, | |
- 'uuid-20': { clientId: 'uuid-20', name: 'core/gallery' }, | |
- 'uuid-22': { clientId: 'uuid-22', name: 'core/block' }, | |
- 'uuid-24': { clientId: 'uuid-24', name: 'core/columns' }, | |
- 'uuid-26': { clientId: 'uuid-26', name: 'core/column' }, | |
- 'uuid-28': { clientId: 'uuid-28', name: 'core/column' }, | |
- 'uuid-30': { clientId: 'uuid-30', name: 'core/paragraph' }, | |
- }, | |
- attributesByClientId: { | |
+ name: { | |
+ 'uuid-2': 'core/image', | |
+ 'uuid-4': 'core/paragraph', | |
+ 'uuid-6': 'core/paragraph', | |
+ 'uuid-8': 'core/block', | |
+ 'uuid-10': 'core/columns', | |
+ 'uuid-12': 'core/column', | |
+ 'uuid-14': 'core/column', | |
+ 'uuid-16': 'core/quote', | |
+ 'uuid-18': 'core/block', | |
+ 'uuid-20': 'core/gallery', | |
+ 'uuid-22': 'core/block', | |
+ 'uuid-24': 'core/columns', | |
+ 'uuid-26': 'core/column', | |
+ 'uuid-28': 'core/column', | |
+ 'uuid-30': 'core/paragraph', | |
+ }, | |
+ attributes: { | |
'uuid-2': {}, | |
'uuid-4': {}, | |
'uuid-6': {}, | |
@@ -2558,11 +2535,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 23: { clientId: 23, name: 'core/heading' }, | |
- 123: { clientId: 123, name: 'core/paragraph' }, | |
+ name: { | |
+ 23: 'core/heading', | |
+ 123: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
23: {}, | |
123: {}, | |
}, | |
@@ -2582,12 +2559,12 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { clientId: 123, name: 'core/columns' }, | |
- 456: { clientId: 456, name: 'core/paragraph' }, | |
- 789: { clientId: 789, name: 'core/paragraph' }, | |
+ name: { | |
+ 123: 'core/columns', | |
+ 456: 'core/paragraph', | |
+ 789: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: {}, | |
456: {}, | |
789: {}, | |
@@ -2645,12 +2622,12 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { clientId: 123, name: 'core/heading' }, | |
- 456: { clientId: 456, name: 'core/paragraph' }, | |
- 789: { clientId: 789, name: 'core/paragraph' }, | |
+ name: { | |
+ 123: 'core/heading', | |
+ 456: 'core/paragraph', | |
+ 789: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: {}, | |
456: {}, | |
789: {}, | |
@@ -2676,8 +2653,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
}, | |
@@ -2707,7 +2684,7 @@ describe( 'selectors', () => { | |
it( 'should return the selected block ClientId', () => { | |
const state = { | |
- editor: { present: { blocks: { byClientId: { 23: { name: 'fake block' } } } } }, | |
+ editor: { present: { blocks: { name: { 23: 'fake block' } } } }, | |
blockSelection: { start: 23, end: 23 }, | |
}; | |
@@ -2722,11 +2699,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 23: { clientId: 23, name: 'core/heading' }, | |
- 123: { clientId: 123, name: 'core/paragraph' }, | |
+ name: { | |
+ 23: 'core/heading', | |
+ 123: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
23: {}, | |
123: {}, | |
}, | |
@@ -2752,11 +2729,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 23: { clientId: 23, name: 'core/heading' }, | |
- 123: { clientId: 123, name: 'core/paragraph' }, | |
+ name: { | |
+ 23: 'core/heading', | |
+ 123: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
23: {}, | |
123: {}, | |
}, | |
@@ -2782,11 +2759,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 23: { clientId: 23, name: 'core/heading' }, | |
- 123: { clientId: 123, name: 'core/paragraph' }, | |
+ name: { | |
+ 23: 'core/heading', | |
+ 123: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
23: {}, | |
123: {}, | |
}, | |
@@ -2956,8 +2933,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -3552,11 +3529,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- clientId1: { clientId: 'clientId1' }, | |
- clientId2: { clientId: 'clientId2' }, | |
+ name: { | |
+ clientId1: '', | |
+ clientId2: '', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
clientId1: {}, | |
clientId2: {}, | |
}, | |
@@ -3593,10 +3570,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- clientId1: { clientId: 'clientId1' }, | |
+ name: { | |
+ clientId1: '', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
clientId1: {}, | |
}, | |
order: { | |
@@ -3628,11 +3605,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- clientId1: { clientId: 'clientId1' }, | |
- clientId2: { clientId: 'clientId2' }, | |
+ name: { | |
+ clientId1: '', | |
+ clientId2: '', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
clientId1: {}, | |
clientId2: {}, | |
}, | |
@@ -3666,11 +3643,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- clientId1: { clientId: 'clientId1' }, | |
- clientId2: { clientId: 'clientId2' }, | |
+ name: { | |
+ clientId1: '', | |
+ clientId2: '', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
clientId1: {}, | |
clientId2: {}, | |
}, | |
@@ -3704,11 +3681,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- clientId1: { clientId: 'clientId1' }, | |
- clientId2: { clientId: 'clientId2' }, | |
+ name: { | |
+ clientId1: '', | |
+ clientId2: '', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
clientId1: {}, | |
clientId2: {}, | |
}, | |
@@ -3825,8 +3802,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -3844,11 +3821,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { clientId: 123, name: 'core/image' }, | |
- 456: { clientId: 456, name: 'core/quote' }, | |
+ name: { | |
+ 123: 'core/image', | |
+ 456: 'core/quote', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: {}, | |
456: {}, | |
}, | |
@@ -3871,10 +3848,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 123: { clientId: 123, name: 'core/image' }, | |
+ name: { | |
+ 123: 'core/image', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
123: {}, | |
}, | |
order: { | |
@@ -3896,10 +3873,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 456: { clientId: 456, name: 'core/quote' }, | |
+ name: { | |
+ 456: 'core/quote', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
456: {}, | |
}, | |
order: { | |
@@ -3921,10 +3898,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 567: { clientId: 567, name: 'core-embed/youtube' }, | |
+ name: { | |
+ 567: 'core-embed/youtube', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
567: {}, | |
}, | |
order: { | |
@@ -3946,11 +3923,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- 456: { clientId: 456, name: 'core/quote' }, | |
- 789: { clientId: 789, name: 'core/paragraph' }, | |
+ name: { | |
+ 456: 'core/quote', | |
+ 789: 'core/paragraph', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
456: {}, | |
789: {}, | |
}, | |
@@ -4003,10 +3980,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- [ block.clientId ]: omit( block, 'attributes' ), | |
+ name: { | |
+ [ block.clientId ]: block.name, | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
[ block.clientId ]: block.attributes, | |
}, | |
order: { | |
@@ -4034,10 +4011,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- [ block.clientId ]: omit( block, 'attributes' ), | |
+ name: { | |
+ [ block.clientId ]: block.name, | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
[ block.clientId ]: block.attributes, | |
}, | |
order: { | |
@@ -4064,10 +4041,16 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- [ unknownBlock.clientId ]: omit( unknownBlock, 'attributes' ), | |
+ name: { | |
+ [ unknownBlock.clientId ]: unknownBlock.name, | |
+ }, | |
+ isValid: { | |
+ [ unknownBlock.clientId ]: unknownBlock.isValid, | |
}, | |
- attributesByClientId: { | |
+ originalContent: { | |
+ [ unknownBlock.clientId ]: unknownBlock.originalContent, | |
+ }, | |
+ attributes: { | |
[ unknownBlock.clientId ]: unknownBlock.attributes, | |
}, | |
order: { | |
@@ -4097,11 +4080,19 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- [ firstUnknown.clientId ]: omit( firstUnknown, 'attributes' ), | |
- [ secondUnknown.clientId ]: omit( secondUnknown, 'attributes' ), | |
+ name: { | |
+ [ firstUnknown.clientId ]: firstUnknown.name, | |
+ [ secondUnknown.clientId ]: secondUnknown.name, | |
+ }, | |
+ isValid: { | |
+ [ firstUnknown.clientId ]: firstUnknown.isValid, | |
+ [ secondUnknown.clientId ]: secondUnknown.isValid, | |
}, | |
- attributesByClientId: { | |
+ originalContent: { | |
+ [ firstUnknown.clientId ]: firstUnknown.originalContent, | |
+ [ secondUnknown.clientId ]: secondUnknown.originalContent, | |
+ }, | |
+ attributes: { | |
[ firstUnknown.clientId ]: firstUnknown.attributes, | |
[ secondUnknown.clientId ]: secondUnknown.attributes, | |
}, | |
@@ -4127,10 +4118,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- [ defaultBlock.clientId ]: omit( defaultBlock, 'attributes' ), | |
+ name: { | |
+ [ defaultBlock.clientId ]: defaultBlock.name, | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
[ defaultBlock.clientId ]: defaultBlock.attributes, | |
}, | |
order: { | |
@@ -4155,12 +4146,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- [ defaultBlock.clientId ]: { | |
- ...omit( defaultBlock, 'attributes' ), | |
- }, | |
+ name: { | |
+ [ defaultBlock.clientId ]: defaultBlock.name, | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
[ defaultBlock.clientId ]: { | |
...defaultBlock.attributes, | |
modified: true, | |
@@ -4189,8 +4178,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
}, | |
}, | |
}, | |
@@ -4205,8 +4194,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
}, | |
}, | |
}, | |
@@ -4223,8 +4212,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
}, | |
}, | |
}, | |
@@ -4241,8 +4230,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
}, | |
}, | |
}, | |
@@ -4259,8 +4248,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
}, | |
}, | |
}, | |
@@ -4275,10 +4264,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-a' }, | |
+ name: { | |
+ block1: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
}, | |
}, | |
@@ -4295,10 +4284,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-b' }, | |
+ name: { | |
+ block1: 'core/test-block-b', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
}, | |
}, | |
@@ -4315,10 +4304,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-a' }, | |
+ name: { | |
+ block1: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
}, | |
}, | |
@@ -4339,10 +4328,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-a' }, | |
+ name: { | |
+ block1: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
}, | |
}, | |
@@ -4363,10 +4352,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-b' }, | |
+ name: { | |
+ block1: 'core/test-block-b', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
}, | |
}, | |
@@ -4389,10 +4378,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-a' }, | |
+ name: { | |
+ block1: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
}, | |
order: {}, | |
@@ -4452,15 +4441,12 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1ref: { | |
- name: 'core/block', | |
- clientId: 'block1ref', | |
- }, | |
- itselfBlock1: { name: 'core/test-block-a' }, | |
- itselfBlock2: { name: 'core/test-block-b' }, | |
+ name: { | |
+ block1ref: 'core/block', | |
+ itselfBlock1: 'core/test-block-a', | |
+ itselfBlock2: 'core/test-block-b', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1ref: { | |
attributes: { | |
ref: 1, | |
@@ -4514,17 +4500,14 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block2ref: { | |
- name: 'core/block', | |
- clientId: 'block1ref', | |
- }, | |
- referredBlock1: { name: 'core/test-block-a' }, | |
- referredBlock2: { name: 'core/test-block-b' }, | |
- childReferredBlock2: { name: 'core/test-block-a' }, | |
- grandchildReferredBlock2: { name: 'core/test-block-b' }, | |
- }, | |
- attributesByClientId: { | |
+ name: { | |
+ block2ref: 'core/block', | |
+ referredBlock1: 'core/test-block-a', | |
+ referredBlock2: 'core/test-block-b', | |
+ childReferredBlock2: 'core/test-block-a', | |
+ grandchildReferredBlock2: 'core/test-block-b', | |
+ }, | |
+ attributes: { | |
block2ref: { | |
attributes: { | |
ref: 2, | |
@@ -4581,11 +4564,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-a' }, | |
- block2: { name: 'core/test-block-a' }, | |
+ name: { | |
+ block1: 'core/test-block-a', | |
+ block2: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
block2: {}, | |
}, | |
@@ -4626,13 +4609,13 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-a' }, | |
- block2: { name: 'core/test-block-a' }, | |
- block3: { name: 'core/test-block-a' }, | |
- block4: { name: 'core/test-block-a' }, | |
+ name: { | |
+ block1: 'core/test-block-a', | |
+ block2: 'core/test-block-a', | |
+ block3: 'core/test-block-a', | |
+ block4: 'core/test-block-a', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: {}, | |
block2: {}, | |
block3: {}, | |
@@ -4699,11 +4682,11 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { clientId: 'block1', name: 'core/test-block-b' }, | |
+ name: { | |
+ block1: 'core/test-block-b', | |
}, | |
- attributesByClientId: { | |
- block1: { attribute: {} }, | |
+ attributes: { | |
+ block1: {}, | |
}, | |
order: { | |
'': [ 'block1' ], | |
@@ -4733,8 +4716,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -4761,8 +4744,8 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: {}, | |
- attributesByClientId: {}, | |
+ name: {}, | |
+ attributes: {}, | |
order: {}, | |
}, | |
edits: {}, | |
@@ -4792,10 +4775,10 @@ describe( 'selectors', () => { | |
editor: { | |
present: { | |
blocks: { | |
- byClientId: { | |
- block1: { name: 'core/test-block-b' }, | |
+ name: { | |
+ block1: 'core/test-block-b', | |
}, | |
- attributesByClientId: { | |
+ attributes: { | |
block1: { attribute: {} }, | |
}, | |
order: { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment