diff --git a/packages/block-editor/src/components/provider/index.js b/packages/block-editor/src/components/provider/index.js index 5b61f940b5b484..b600ea9db8a801 100644 --- a/packages/block-editor/src/components/provider/index.js +++ b/packages/block-editor/src/components/provider/index.js @@ -38,7 +38,7 @@ const withRegistry = createHigherOrderComponent( * * @return {boolean} Whether the two objects have the same keys. */ -function hasSameKeys( a, b ) { +export function hasSameKeys( a, b ) { return isShallowEqual( Object.keys( a ), Object.keys( b ) ); } @@ -52,7 +52,7 @@ function hasSameKeys( a, b ) { * * @return {boolean} Whether actions are updating the same block attribute. */ -function isUpdatingSameBlockAttribute( action, lastAction ) { +export function isUpdatingSameBlockAttribute( action, lastAction ) { return ( action.type === 'UPDATE_BLOCK_ATTRIBUTES' && action.clientId === lastAction.clientId && @@ -86,7 +86,7 @@ function createChangeObserver( store, callback ) { isPendingCommit = false; } else if ( lastAction && lastState && state !== lastState ) { if ( - state.editor.blocks !== lastState.editor.blocks && + state.blocks !== lastState.blocks && isUpdatingSameBlockAttribute( action, lastAction ) ) { // So long as block updates occur as operating on the same diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index 65b80603df0ef0..46969eb68b3daf 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -155,7 +155,7 @@ const withInnerBlocksRemoveCascade = ( reducer ) => ( state, action ) => { // For each removed client ID, include its inner blocks to remove, // recursing into those so long as inner blocks exist. for ( let i = 0; i < clientIds.length; i++ ) { - clientIds.push( ...state.blocks.order[ clientIds[ i ] ] ); + clientIds.push( ...state.order[ clientIds[ i ] ] ); } action = { ...action, clientIds }; @@ -248,275 +248,270 @@ const withSaveReusableBlock = ( reducer ) => ( state, action ) => { * * @returns {Object} Updated state. */ -export const editor = flow( [ +export const blocks = flow( combineReducers, - withInnerBlocksRemoveCascade, -] )( { - blocks: flow( - combineReducers, - withBlockReset, - withSaveReusableBlock, - )( { - byClientId( state = {}, action ) { - switch ( action.type ) { - case 'RESET_BLOCKS': - return getFlattenedBlocksWithoutAttributes( action.blocks ); - - case 'RECEIVE_BLOCKS': - return { - ...state, - ...getFlattenedBlocksWithoutAttributes( action.blocks ), - }; + withBlockReset, + withSaveReusableBlock, +)( { + byClientId( state = {}, action ) { + switch ( action.type ) { + case 'RESET_BLOCKS': + return getFlattenedBlocksWithoutAttributes( action.blocks ); + + case 'RECEIVE_BLOCKS': + return { + ...state, + ...getFlattenedBlocksWithoutAttributes( action.blocks ), + }; - case 'UPDATE_BLOCK': - // Ignore updates if block isn't known - if ( ! state[ action.clientId ] ) { - return state; - } + case 'UPDATE_BLOCK': + // Ignore updates if block isn't known + if ( ! state[ action.clientId ] ) { + return state; + } - // Do nothing if only attributes change. - const changes = omit( action.updates, 'attributes' ); - if ( isEmpty( changes ) ) { - return state; - } + // Do nothing if only attributes change. + const changes = omit( action.updates, 'attributes' ); + if ( isEmpty( changes ) ) { + return state; + } - return { - ...state, - [ action.clientId ]: { - ...state[ action.clientId ], - ...changes, - }, - }; + return { + ...state, + [ action.clientId ]: { + ...state[ action.clientId ], + ...changes, + }, + }; - case 'INSERT_BLOCKS': - return { - ...state, - ...getFlattenedBlocksWithoutAttributes( action.blocks ), - }; + case 'INSERT_BLOCKS': + return { + ...state, + ...getFlattenedBlocksWithoutAttributes( action.blocks ), + }; - case 'REPLACE_BLOCKS': - if ( ! action.blocks ) { - return state; - } + case 'REPLACE_BLOCKS': + if ( ! action.blocks ) { + return state; + } - return { - ...omit( state, action.clientIds ), - ...getFlattenedBlocksWithoutAttributes( action.blocks ), - }; + return { + ...omit( state, action.clientIds ), + ...getFlattenedBlocksWithoutAttributes( action.blocks ), + }; - case 'REMOVE_BLOCKS': - return omit( state, action.clientIds ); - } + case 'REMOVE_BLOCKS': + return omit( state, action.clientIds ); + } - return state; - }, + return state; + }, - attributes( state = {}, action ) { - switch ( action.type ) { - case 'RESET_BLOCKS': - return getFlattenedBlockAttributes( action.blocks ); + attributes( state = {}, action ) { + switch ( action.type ) { + case 'RESET_BLOCKS': + return getFlattenedBlockAttributes( action.blocks ); - case 'RECEIVE_BLOCKS': - return { - ...state, - ...getFlattenedBlockAttributes( action.blocks ), - }; + case 'RECEIVE_BLOCKS': + return { + ...state, + ...getFlattenedBlockAttributes( action.blocks ), + }; - case 'UPDATE_BLOCK': - // Ignore updates if block isn't known or there are no attribute changes. - if ( ! state[ action.clientId ] || ! action.updates.attributes ) { - return state; - } + case 'UPDATE_BLOCK': + // Ignore updates if block isn't known or there are no attribute changes. + if ( ! state[ action.clientId ] || ! action.updates.attributes ) { + return state; + } - return { - ...state, - [ action.clientId ]: { - ...state[ action.clientId ], - ...action.updates.attributes, - }, - }; + return { + ...state, + [ action.clientId ]: { + ...state[ action.clientId ], + ...action.updates.attributes, + }, + }; - case 'UPDATE_BLOCK_ATTRIBUTES': - // Ignore updates if block isn't known - if ( ! state[ action.clientId ] ) { - return state; - } + case 'UPDATE_BLOCK_ATTRIBUTES': + // Ignore updates if block isn't known + if ( ! state[ action.clientId ] ) { + return state; + } - // Consider as updates only changed values - const nextAttributes = reduce( action.attributes, ( result, value, key ) => { - if ( value !== result[ key ] ) { - result = getMutateSafeObject( state[ action.clientId ], result ); - result[ key ] = value; - } + // Consider as updates only changed values + const nextAttributes = reduce( action.attributes, ( result, value, key ) => { + if ( value !== result[ key ] ) { + result = getMutateSafeObject( state[ action.clientId ], result ); + result[ key ] = value; + } - return result; - }, state[ action.clientId ] ); + return result; + }, state[ action.clientId ] ); - // Skip update if nothing has been changed. The reference will - // match the original block if `reduce` had no changed values. - if ( nextAttributes === state[ action.clientId ] ) { - return state; - } + // Skip update if nothing has been changed. The reference will + // match the original block if `reduce` had no changed values. + if ( nextAttributes === state[ action.clientId ] ) { + return state; + } - // Otherwise replace attributes in state - return { - ...state, - [ action.clientId ]: nextAttributes, - }; + // Otherwise replace attributes in state + return { + ...state, + [ action.clientId ]: nextAttributes, + }; - case 'INSERT_BLOCKS': - return { - ...state, - ...getFlattenedBlockAttributes( action.blocks ), - }; + case 'INSERT_BLOCKS': + return { + ...state, + ...getFlattenedBlockAttributes( action.blocks ), + }; - case 'REPLACE_BLOCKS': - if ( ! action.blocks ) { - return state; - } + case 'REPLACE_BLOCKS': + if ( ! action.blocks ) { + return state; + } - return { - ...omit( state, action.clientIds ), - ...getFlattenedBlockAttributes( action.blocks ), - }; + return { + ...omit( state, action.clientIds ), + ...getFlattenedBlockAttributes( action.blocks ), + }; - case 'REMOVE_BLOCKS': - return omit( state, action.clientIds ); - } + case 'REMOVE_BLOCKS': + return omit( state, action.clientIds ); + } - return state; - }, + return state; + }, - order( state = {}, action ) { - switch ( action.type ) { - case 'RESET_BLOCKS': - return mapBlockOrder( action.blocks ); + order( state = {}, action ) { + switch ( action.type ) { + case 'RESET_BLOCKS': + return mapBlockOrder( action.blocks ); - case 'RECEIVE_BLOCKS': - return { - ...state, - ...omit( mapBlockOrder( action.blocks ), '' ), - }; + case 'RECEIVE_BLOCKS': + return { + ...state, + ...omit( mapBlockOrder( action.blocks ), '' ), + }; - case 'INSERT_BLOCKS': { - const { rootClientId = '', blocks } = action; - const subState = state[ rootClientId ] || []; - const mappedBlocks = mapBlockOrder( blocks, rootClientId ); - const { index = subState.length } = action; + case 'INSERT_BLOCKS': { + const { rootClientId = '' } = action; + const subState = state[ rootClientId ] || []; + const mappedBlocks = mapBlockOrder( action.blocks, rootClientId ); + const { index = subState.length } = action; - return { - ...state, - ...mappedBlocks, - [ rootClientId ]: insertAt( subState, mappedBlocks[ rootClientId ], index ), - }; - } + return { + ...state, + ...mappedBlocks, + [ rootClientId ]: insertAt( subState, mappedBlocks[ rootClientId ], index ), + }; + } - case 'MOVE_BLOCK_TO_POSITION': { - const { fromRootClientId = '', toRootClientId = '', clientId } = action; - const { index = state[ toRootClientId ].length } = action; - - // Moving inside the same parent block - if ( fromRootClientId === toRootClientId ) { - const subState = state[ toRootClientId ]; - const fromIndex = subState.indexOf( clientId ); - return { - ...state, - [ toRootClientId ]: moveTo( state[ toRootClientId ], fromIndex, index ), - }; - } + case 'MOVE_BLOCK_TO_POSITION': { + const { fromRootClientId = '', toRootClientId = '', clientId } = action; + const { index = state[ toRootClientId ].length } = action; - // Moving from a parent block to another + // Moving inside the same parent block + if ( fromRootClientId === toRootClientId ) { + const subState = state[ toRootClientId ]; + const fromIndex = subState.indexOf( clientId ); return { ...state, - [ fromRootClientId ]: without( state[ fromRootClientId ], clientId ), - [ toRootClientId ]: insertAt( state[ toRootClientId ], clientId, index ), + [ toRootClientId ]: moveTo( state[ toRootClientId ], fromIndex, index ), }; } - case 'MOVE_BLOCKS_UP': { - const { clientIds, rootClientId = '' } = action; - const firstClientId = first( clientIds ); - const subState = state[ rootClientId ]; - - if ( ! subState.length || firstClientId === first( subState ) ) { - return state; - } + // Moving from a parent block to another + return { + ...state, + [ fromRootClientId ]: without( state[ fromRootClientId ], clientId ), + [ toRootClientId ]: insertAt( state[ toRootClientId ], clientId, index ), + }; + } - const firstIndex = subState.indexOf( firstClientId ); + case 'MOVE_BLOCKS_UP': { + const { clientIds, rootClientId = '' } = action; + const firstClientId = first( clientIds ); + const subState = state[ rootClientId ]; - return { - ...state, - [ rootClientId ]: moveTo( subState, firstIndex, firstIndex - 1, clientIds.length ), - }; + if ( ! subState.length || firstClientId === first( subState ) ) { + return state; } - case 'MOVE_BLOCKS_DOWN': { - const { clientIds, rootClientId = '' } = action; - const firstClientId = first( clientIds ); - const lastClientId = last( clientIds ); - const subState = state[ rootClientId ]; + const firstIndex = subState.indexOf( firstClientId ); - if ( ! subState.length || lastClientId === last( subState ) ) { - return state; - } + return { + ...state, + [ rootClientId ]: moveTo( subState, firstIndex, firstIndex - 1, clientIds.length ), + }; + } - const firstIndex = subState.indexOf( firstClientId ); + case 'MOVE_BLOCKS_DOWN': { + const { clientIds, rootClientId = '' } = action; + const firstClientId = first( clientIds ); + const lastClientId = last( clientIds ); + const subState = state[ rootClientId ]; - return { - ...state, - [ rootClientId ]: moveTo( subState, firstIndex, firstIndex + 1, clientIds.length ), - }; + if ( ! subState.length || lastClientId === last( subState ) ) { + return state; } - case 'REPLACE_BLOCKS': { - const { blocks, clientIds } = action; - if ( ! blocks ) { - return state; - } + const firstIndex = subState.indexOf( firstClientId ); - const mappedBlocks = mapBlockOrder( blocks ); - - return flow( [ - ( nextState ) => omit( nextState, clientIds ), - ( nextState ) => ( { - ...nextState, - ...omit( mappedBlocks, '' ), - } ), - ( nextState ) => mapValues( nextState, ( subState ) => ( - reduce( subState, ( result, clientId ) => { - if ( clientId === clientIds[ 0 ] ) { - return [ - ...result, - ...mappedBlocks[ '' ], - ]; - } - - if ( clientIds.indexOf( clientId ) === -1 ) { - result.push( clientId ); - } - - return result; - }, [] ) - ) ), - ] )( state ); - } + return { + ...state, + [ rootClientId ]: moveTo( subState, firstIndex, firstIndex + 1, clientIds.length ), + }; + } - case 'REMOVE_BLOCKS': - return flow( [ - // Remove inner block ordering for removed blocks - ( nextState ) => omit( nextState, action.clientIds ), + case 'REPLACE_BLOCKS': { + const { clientIds } = action; + if ( ! action.blocks ) { + return state; + } - // Remove deleted blocks from other blocks' orderings - ( nextState ) => mapValues( nextState, ( subState ) => ( - without( subState, ...action.clientIds ) - ) ), - ] )( state ); + const mappedBlocks = mapBlockOrder( action.blocks ); + + return flow( [ + ( nextState ) => omit( nextState, clientIds ), + ( nextState ) => ( { + ...nextState, + ...omit( mappedBlocks, '' ), + } ), + ( nextState ) => mapValues( nextState, ( subState ) => ( + reduce( subState, ( result, clientId ) => { + if ( clientId === clientIds[ 0 ] ) { + return [ + ...result, + ...mappedBlocks[ '' ], + ]; + } + + if ( clientIds.indexOf( clientId ) === -1 ) { + result.push( clientId ); + } + + return result; + }, [] ) + ) ), + ] )( state ); } - return state; - }, - } ), + case 'REMOVE_BLOCKS': + return flow( [ + // Remove inner block ordering for removed blocks + ( nextState ) => omit( nextState, action.clientIds ), + + // Remove deleted blocks from other blocks' orderings + ( nextState ) => mapValues( nextState, ( subState ) => ( + without( subState, ...action.clientIds ) + ) ), + ] )( state ); + } + + return state; + }, } ); /** @@ -827,7 +822,7 @@ export const blockListSettings = ( state = {}, action ) => { }; export default combineReducers( { - editor, + blocks, isTyping, isCaretWithinFormattedText, blockSelection, diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index c0c0cd545fd016..935962d76540c3 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -89,7 +89,7 @@ export const getBlockDependantsCacheBust = createSelector( * @return {string} Block name. */ export function getBlockName( state, clientId ) { - const block = state.editor.blocks.byClientId[ clientId ]; + const block = state.blocks.byClientId[ clientId ]; return block ? block.name : null; } @@ -102,7 +102,7 @@ export function getBlockName( state, clientId ) { * @return {boolean} Is Valid. */ export function isBlockValid( state, clientId ) { - const block = state.editor.blocks.byClientId[ clientId ]; + const block = state.blocks.byClientId[ clientId ]; return !! block && block.isValid; } @@ -117,12 +117,12 @@ export function isBlockValid( state, clientId ) { */ export const getBlockAttributes = createSelector( ( state, clientId ) => { - const block = state.editor.blocks.byClientId[ clientId ]; + const block = state.blocks.byClientId[ clientId ]; if ( ! block ) { return null; } - let attributes = state.editor.blocks.attributes[ clientId ]; + let attributes = state.blocks.attributes[ clientId ]; // Inject custom source attribute values. // @@ -146,8 +146,8 @@ export const getBlockAttributes = createSelector( return attributes; }, ( state, clientId ) => [ - state.editor.blocks.byClientId[ clientId ], - state.editor.blocks.attributes[ clientId ], + state.blocks.byClientId[ clientId ], + state.blocks.attributes[ clientId ], getPostMeta( state ), ] ); @@ -165,7 +165,7 @@ export const getBlockAttributes = createSelector( */ export const getBlock = createSelector( ( state, clientId ) => { - const block = state.editor.blocks.byClientId[ clientId ]; + const block = state.blocks.byClientId[ clientId ]; if ( ! block ) { return null; } @@ -184,7 +184,7 @@ export const getBlock = createSelector( export const __unstableGetBlockWithoutInnerBlocks = createSelector( ( state, clientId ) => { - const block = state.editor.blocks.byClientId[ clientId ]; + const block = state.blocks.byClientId[ clientId ]; if ( ! block ) { return null; } @@ -195,7 +195,7 @@ export const __unstableGetBlockWithoutInnerBlocks = createSelector( }; }, ( state, clientId ) => [ - state.editor.blocks.byClientId[ clientId ], + state.blocks.byClientId[ clientId ], ...getBlockAttributes.getDependants( state, clientId ), ] ); @@ -219,7 +219,7 @@ export const getBlocks = createSelector( ( clientId ) => getBlock( state, clientId ) ); }, - ( state ) => [ state.editor.blocks ] + ( state ) => [ state.blocks ] ); /** @@ -250,7 +250,7 @@ export const getClientIdsWithDescendants = createSelector( return [ ...topLevelIds, ...getClientIdsOfDescendants( state, topLevelIds ) ]; }, ( state ) => [ - state.editor.blocks.order, + state.blocks.order, ] ); @@ -270,13 +270,13 @@ export const getGlobalBlockCount = createSelector( return clientIds.length; } return reduce( clientIds, ( count, clientId ) => { - const block = state.editor.blocks.byClientId[ clientId ]; + const block = state.blocks.byClientId[ clientId ]; return block.name === blockName ? count + 1 : count; }, 0 ); }, ( state ) => [ - state.editor.blocks.order, - state.editor.blocks.byClientId, + state.blocks.order, + state.blocks.byClientId, ] ); @@ -296,7 +296,7 @@ export const getBlocksByClientId = createSelector( ), ( state ) => [ getPostMeta( state ), - state.editor.blocks, + state.blocks, ] ); @@ -380,7 +380,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.blocks.byClientId[ start ] ? start : null; + return start && start === end && !! state.blocks.byClientId[ start ] ? start : null; } /** @@ -407,7 +407,7 @@ export function getSelectedBlock( state ) { */ export const getBlockRootClientId = createSelector( ( state, clientId ) => { - const { order } = state.editor.blocks; + const { order } = state.blocks; for ( const rootClientId in order ) { if ( includes( order[ rootClientId ], clientId ) ) { @@ -418,7 +418,7 @@ export const getBlockRootClientId = createSelector( return null; }, ( state ) => [ - state.editor.blocks.order, + state.blocks.order, ] ); @@ -442,7 +442,7 @@ export const getBlockHierarchyRootClientId = createSelector( return current; }, ( state ) => [ - state.editor.blocks.order, + state.blocks.order, ] ); @@ -487,7 +487,7 @@ export function getAdjacentBlockClientId( state, startClientId, modifier = 1 ) { return null; } - const { order } = state.editor.blocks; + const { order } = state.blocks; const orderSet = order[ rootClientId ]; const index = orderSet.indexOf( startClientId ); const nextIndex = ( index + ( 1 * modifier ) ); @@ -587,7 +587,7 @@ export const getMultiSelectedBlockClientIds = createSelector( return blockOrder.slice( startIndex, endIndex + 1 ); }, ( state ) => [ - state.editor.blocks.order, + state.blocks.order, state.blockSelection.start, state.blockSelection.end, ], @@ -612,7 +612,7 @@ export const getMultiSelectedBlocks = createSelector( }, ( state ) => [ ...getMultiSelectedBlockClientIds.getDependants( state ), - state.editor.blocks, + state.blocks, getPostMeta( state ), ] ); @@ -660,7 +660,7 @@ const isAncestorOf = createSelector( return possibleAncestorId === idToCheck; }, ( state ) => [ - state.editor.blocks.order, + state.blocks.order, ], ); @@ -712,7 +712,7 @@ export const isAncestorMultiSelected = createSelector( return isMultiSelected; }, ( state ) => [ - state.editor.blocks.order, + state.blocks.order, state.blockSelection.start, state.blockSelection.end, ], @@ -768,7 +768,7 @@ export function getMultiSelectedBlocksEndClientId( state ) { * @return {Array} Ordered client IDs of editor blocks. */ export function getBlockOrder( state, rootClientId ) { - return state.editor.blocks.order[ rootClientId || '' ] || EMPTY_ARRAY; + return state.blocks.order[ rootClientId || '' ] || EMPTY_ARRAY; } /** @@ -1070,7 +1070,7 @@ export const canInsertBlockType = createSelector( canInsertBlockTypeUnmemoized, ( state, blockName, rootClientId ) => [ state.blockListSettings[ rootClientId ], - state.editor.blocks.byClientId[ rootClientId ], + state.blocks.byClientId[ rootClientId ], state.settings.allowedBlockTypes, state.settings.templateLock, ], @@ -1280,8 +1280,8 @@ export const getInserterItems = createSelector( }, ( state, rootClientId ) => [ state.blockListSettings[ rootClientId ], - state.editor.blocks.byClientId, - state.editor.blocks.order, + state.blocks.byClientId, + state.blocks.order, state.preferences.insertUsage, state.settings.allowedBlockTypes, state.settings.templateLock, @@ -1315,7 +1315,7 @@ export const hasInserterItems = createSelector( }, ( state, rootClientId ) => [ state.blockListSettings[ rootClientId ], - state.editor.blocks.byClientId, + state.blocks.byClientId, state.settings.allowedBlockTypes, state.settings.templateLock, getReusableBlocks( state ), @@ -1346,29 +1346,6 @@ export function getEditorSettings( state ) { return state.settings; } -/** - * Returns true if any past editor history snapshots exist, or false otherwise. - * - * @param {Object} state Global application state. - * - * @return {boolean} Whether undo history exists. - */ -export function hasEditorUndo( state ) { - return state.editor.past.length > 0; -} - -/** - * Returns true if any future editor history snapshots exist, or false - * otherwise. - * - * @param {Object} state Global application state. - * - * @return {boolean} Whether redo history exists. - */ -export function hasEditorRedo( state ) { - return state.editor.future.length > 0; -} - /** * Returns the value of a post meta from the editor settings. * diff --git a/packages/block-editor/src/store/test/reducer.js b/packages/block-editor/src/store/test/reducer.js index 3da3e1abed864c..17da02f344d9f1 100644 --- a/packages/block-editor/src/store/test/reducer.js +++ b/packages/block-editor/src/store/test/reducer.js @@ -17,7 +17,7 @@ import { * Internal dependencies */ import { - editor, + blocks, isTyping, isCaretWithinFormattedText, blockSelection, @@ -29,7 +29,7 @@ import { } from '../reducer'; describe( 'state', () => { - describe( 'editor()', () => { + describe( 'blocks()', () => { beforeAll( () => { registerBlockType( 'core/test-block', { save: noop, @@ -44,25 +44,25 @@ describe( 'state', () => { } ); it( 'should return empty edits, blocks by default', () => { - const state = editor( undefined, {} ); + const state = blocks( undefined, {} ); - expect( state.blocks.byClientId ).toEqual( {} ); - expect( state.blocks.order ).toEqual( {} ); + expect( state.byClientId ).toEqual( {} ); + expect( state.order ).toEqual( {} ); } ); it( 'should key by reset blocks clientId', () => { [ undefined, - editor( undefined, {} ), + blocks( undefined, {} ), ].forEach( ( original ) => { - const state = editor( original, { + const state = blocks( original, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'bananas', innerBlocks: [] } ], } ); - expect( Object.keys( state.blocks.byClientId ) ).toHaveLength( 1 ); - expect( values( state.blocks.byClientId )[ 0 ].clientId ).toBe( 'bananas' ); - expect( state.blocks.order ).toEqual( { + expect( Object.keys( state.byClientId ) ).toHaveLength( 1 ); + expect( values( state.byClientId )[ 0 ].clientId ).toBe( 'bananas' ); + expect( state.order ).toEqual( { '': [ 'bananas' ], bananas: [], } ); @@ -70,8 +70,8 @@ describe( 'state', () => { } ); it( 'should key by reset blocks clientId, including inner blocks', () => { - const original = editor( undefined, {} ); - const state = editor( original, { + const original = blocks( undefined, {} ); + const state = blocks( original, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'bananas', @@ -79,8 +79,8 @@ describe( 'state', () => { } ], } ); - expect( Object.keys( state.blocks.byClientId ) ).toHaveLength( 2 ); - expect( state.blocks.order ).toEqual( { + expect( Object.keys( state.byClientId ) ).toHaveLength( 2 ); + expect( state.order ).toEqual( { '': [ 'bananas' ], apples: [], bananas: [ 'apples' ], @@ -88,7 +88,7 @@ describe( 'state', () => { } ); it( 'should insert block', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -97,7 +97,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'INSERT_BLOCKS', blocks: [ { clientId: 'ribs', @@ -106,9 +106,9 @@ describe( 'state', () => { } ], } ); - expect( Object.keys( state.blocks.byClientId ) ).toHaveLength( 2 ); - expect( values( state.blocks.byClientId )[ 1 ].clientId ).toBe( 'ribs' ); - expect( state.blocks.order ).toEqual( { + expect( Object.keys( state.byClientId ) ).toHaveLength( 2 ); + expect( values( state.byClientId )[ 1 ].clientId ).toBe( 'ribs' ); + expect( state.order ).toEqual( { '': [ 'chicken', 'ribs' ], chicken: [], ribs: [], @@ -116,7 +116,7 @@ describe( 'state', () => { } ); it( 'should replace the block', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -125,7 +125,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'REPLACE_BLOCKS', clientIds: [ 'chicken' ], blocks: [ { @@ -135,10 +135,10 @@ describe( 'state', () => { } ], } ); - expect( Object.keys( state.blocks.byClientId ) ).toHaveLength( 1 ); - expect( values( state.blocks.byClientId )[ 0 ].name ).toBe( 'core/freeform' ); - expect( values( state.blocks.byClientId )[ 0 ].clientId ).toBe( 'wings' ); - expect( state.blocks.order ).toEqual( { + expect( Object.keys( state.byClientId ) ).toHaveLength( 1 ); + expect( values( state.byClientId )[ 0 ].name ).toBe( 'core/freeform' ); + expect( values( state.byClientId )[ 0 ].clientId ).toBe( 'wings' ); + expect( state.order ).toEqual( { '': [ 'wings' ], wings: [], } ); @@ -148,18 +148,18 @@ describe( 'state', () => { const nestedBlock = createBlock( 'core/test-block' ); const wrapperBlock = createBlock( 'core/test-block', {}, [ nestedBlock ] ); const replacementBlock = createBlock( 'core/test-block' ); - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ wrapperBlock ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'REPLACE_BLOCKS', clientIds: [ nestedBlock.clientId ], blocks: [ replacementBlock ], } ); - expect( state.blocks.order ).toEqual( { + expect( state.order ).toEqual( { '': [ wrapperBlock.clientId ], [ wrapperBlock.clientId ]: [ replacementBlock.clientId ], [ replacementBlock.clientId ]: [], @@ -167,7 +167,7 @@ describe( 'state', () => { } ); it( 'should replace the block even if the new block clientId is the same', () => { - const originalState = editor( undefined, { + const originalState = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -176,7 +176,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const replacedState = editor( originalState, { + const replacedState = blocks( originalState, { type: 'REPLACE_BLOCKS', clientIds: [ 'chicken' ], blocks: [ { @@ -186,11 +186,11 @@ describe( 'state', () => { } ], } ); - expect( Object.keys( replacedState.blocks.byClientId ) ).toHaveLength( 1 ); - expect( values( originalState.blocks.byClientId )[ 0 ].name ).toBe( 'core/test-block' ); - expect( values( replacedState.blocks.byClientId )[ 0 ].name ).toBe( 'core/freeform' ); - expect( values( replacedState.blocks.byClientId )[ 0 ].clientId ).toBe( 'chicken' ); - expect( replacedState.blocks.order ).toEqual( { + expect( Object.keys( replacedState.byClientId ) ).toHaveLength( 1 ); + expect( values( originalState.byClientId )[ 0 ].name ).toBe( 'core/test-block' ); + expect( values( replacedState.byClientId )[ 0 ].name ).toBe( 'core/freeform' ); + expect( values( replacedState.byClientId )[ 0 ].clientId ).toBe( 'chicken' ); + expect( replacedState.order ).toEqual( { '': [ 'chicken' ], chicken: [], } ); @@ -209,29 +209,29 @@ describe( 'state', () => { innerBlocks: [], }; - const originalNestedState = editor( undefined, { + const originalNestedState = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ wrapperBlock ], } ); - const replacedNestedState = editor( originalNestedState, { + const replacedNestedState = blocks( originalNestedState, { type: 'REPLACE_BLOCKS', clientIds: [ nestedBlock.clientId ], blocks: [ replacementNestedBlock ], } ); - expect( replacedNestedState.blocks.order ).toEqual( { + expect( replacedNestedState.order ).toEqual( { '': [ wrapperBlock.clientId ], [ wrapperBlock.clientId ]: [ replacementNestedBlock.clientId ], [ replacementNestedBlock.clientId ]: [], } ); - expect( originalNestedState.blocks.byClientId.chicken.name ).toBe( 'core/test-block' ); - expect( replacedNestedState.blocks.byClientId.chicken.name ).toBe( 'core/freeform' ); + expect( originalNestedState.byClientId.chicken.name ).toBe( 'core/test-block' ); + expect( replacedNestedState.byClientId.chicken.name ).toBe( 'core/freeform' ); } ); it( 'should update the block', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -241,7 +241,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( deepFreeze( original ), { + const state = blocks( deepFreeze( original ), { type: 'UPDATE_BLOCK', clientId: 'chicken', updates: { @@ -250,19 +250,19 @@ describe( 'state', () => { }, } ); - expect( state.blocks.byClientId.chicken ).toEqual( { + expect( state.byClientId.chicken ).toEqual( { clientId: 'chicken', name: 'core/test-block', isValid: true, } ); - expect( state.blocks.attributes.chicken ).toEqual( { + expect( state.attributes.chicken ).toEqual( { content: 'ribs', } ); } ); it( 'should update the reusable block reference if the temporary id is swapped', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -275,25 +275,25 @@ describe( 'state', () => { } ], } ); - const state = editor( deepFreeze( original ), { + const state = blocks( deepFreeze( original ), { type: 'SAVE_REUSABLE_BLOCK_SUCCESS', id: 'random-clientId', updatedId: 3, } ); - expect( state.blocks.byClientId.chicken ).toEqual( { + expect( state.byClientId.chicken ).toEqual( { clientId: 'chicken', name: 'core/block', isValid: false, } ); - expect( state.blocks.attributes.chicken ).toEqual( { + expect( state.attributes.chicken ).toEqual( { ref: 3, } ); } ); it( 'should move the block up', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -307,29 +307,29 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_UP', clientIds: [ 'ribs' ], } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'ribs', 'chicken' ] ); + expect( state.order[ '' ] ).toEqual( [ 'ribs', 'chicken' ] ); } ); it( 'should move the nested block up', () => { const movedBlock = createBlock( 'core/test-block' ); const siblingBlock = createBlock( 'core/test-block' ); const wrapperBlock = createBlock( 'core/test-block', {}, [ siblingBlock, movedBlock ] ); - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ wrapperBlock ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_UP', clientIds: [ movedBlock.clientId ], rootClientId: wrapperBlock.clientId, } ); - expect( state.blocks.order ).toEqual( { + expect( state.order ).toEqual( { '': [ wrapperBlock.clientId ], [ wrapperBlock.clientId ]: [ movedBlock.clientId, siblingBlock.clientId ], [ movedBlock.clientId ]: [], @@ -338,7 +338,7 @@ describe( 'state', () => { } ); it( 'should move multiple blocks up', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -357,12 +357,12 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_UP', clientIds: [ 'ribs', 'veggies' ], } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'ribs', 'veggies', 'chicken' ] ); + expect( state.order[ '' ] ).toEqual( [ 'ribs', 'veggies', 'chicken' ] ); } ); it( 'should move multiple nested blocks up', () => { @@ -370,17 +370,17 @@ describe( 'state', () => { const movedBlockB = createBlock( 'core/test-block' ); const siblingBlock = createBlock( 'core/test-block' ); const wrapperBlock = createBlock( 'core/test-block', {}, [ siblingBlock, movedBlockA, movedBlockB ] ); - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ wrapperBlock ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_UP', clientIds: [ movedBlockA.clientId, movedBlockB.clientId ], rootClientId: wrapperBlock.clientId, } ); - expect( state.blocks.order ).toEqual( { + expect( state.order ).toEqual( { '': [ wrapperBlock.clientId ], [ wrapperBlock.clientId ]: [ movedBlockA.clientId, movedBlockB.clientId, siblingBlock.clientId ], [ movedBlockA.clientId ]: [], @@ -390,7 +390,7 @@ describe( 'state', () => { } ); it( 'should not move the first block up', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -404,16 +404,16 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_UP', clientIds: [ 'chicken' ], } ); - expect( state.blocks.order ).toBe( original.blocks.order ); + expect( state.order ).toBe( original.order ); } ); it( 'should move the block down', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -427,29 +427,29 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_DOWN', clientIds: [ 'chicken' ], } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'ribs', 'chicken' ] ); + expect( state.order[ '' ] ).toEqual( [ 'ribs', 'chicken' ] ); } ); it( 'should move the nested block down', () => { const movedBlock = createBlock( 'core/test-block' ); const siblingBlock = createBlock( 'core/test-block' ); const wrapperBlock = createBlock( 'core/test-block', {}, [ movedBlock, siblingBlock ] ); - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ wrapperBlock ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_DOWN', clientIds: [ movedBlock.clientId ], rootClientId: wrapperBlock.clientId, } ); - expect( state.blocks.order ).toEqual( { + expect( state.order ).toEqual( { '': [ wrapperBlock.clientId ], [ wrapperBlock.clientId ]: [ siblingBlock.clientId, movedBlock.clientId ], [ movedBlock.clientId ]: [], @@ -458,7 +458,7 @@ describe( 'state', () => { } ); it( 'should move multiple blocks down', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -477,12 +477,12 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_DOWN', clientIds: [ 'chicken', 'ribs' ], } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'veggies', 'chicken', 'ribs' ] ); + expect( state.order[ '' ] ).toEqual( [ 'veggies', 'chicken', 'ribs' ] ); } ); it( 'should move multiple nested blocks down', () => { @@ -490,17 +490,17 @@ describe( 'state', () => { const movedBlockB = createBlock( 'core/test-block' ); const siblingBlock = createBlock( 'core/test-block' ); const wrapperBlock = createBlock( 'core/test-block', {}, [ movedBlockA, movedBlockB, siblingBlock ] ); - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ wrapperBlock ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_DOWN', clientIds: [ movedBlockA.clientId, movedBlockB.clientId ], rootClientId: wrapperBlock.clientId, } ); - expect( state.blocks.order ).toEqual( { + expect( state.order ).toEqual( { '': [ wrapperBlock.clientId ], [ wrapperBlock.clientId ]: [ siblingBlock.clientId, movedBlockA.clientId, movedBlockB.clientId ], [ movedBlockA.clientId ]: [], @@ -510,7 +510,7 @@ describe( 'state', () => { } ); it( 'should not move the last block down', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -524,16 +524,16 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCKS_DOWN', clientIds: [ 'ribs' ], } ); - expect( state.blocks.order ).toBe( original.blocks.order ); + expect( state.order ).toBe( original.order ); } ); it( 'should remove the block', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -547,26 +547,26 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'REMOVE_BLOCKS', clientIds: [ 'chicken' ], } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'ribs' ] ); - expect( state.blocks.order ).not.toHaveProperty( 'chicken' ); - expect( state.blocks.byClientId ).toEqual( { + expect( state.order[ '' ] ).toEqual( [ 'ribs' ] ); + expect( state.order ).not.toHaveProperty( 'chicken' ); + expect( state.byClientId ).toEqual( { ribs: { clientId: 'ribs', name: 'core/test-block', }, } ); - expect( state.blocks.attributes ).toEqual( { + expect( state.attributes ).toEqual( { ribs: {}, } ); } ); it( 'should remove multiple blocks', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -585,21 +585,21 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'REMOVE_BLOCKS', clientIds: [ 'chicken', 'veggies' ], } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'ribs' ] ); - expect( state.blocks.order ).not.toHaveProperty( 'chicken' ); - expect( state.blocks.order ).not.toHaveProperty( 'veggies' ); - expect( state.blocks.byClientId ).toEqual( { + expect( state.order[ '' ] ).toEqual( [ 'ribs' ] ); + expect( state.order ).not.toHaveProperty( 'chicken' ); + expect( state.order ).not.toHaveProperty( 'veggies' ); + expect( state.byClientId ).toEqual( { ribs: { clientId: 'ribs', name: 'core/test-block', }, } ); - expect( state.blocks.attributes ).toEqual( { + expect( state.attributes ).toEqual( { ribs: {}, } ); } ); @@ -611,24 +611,24 @@ describe( 'state', () => { ] ), ] ); - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ block ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'REMOVE_BLOCKS', clientIds: [ block.clientId ], } ); - expect( state.blocks.byClientId ).toEqual( {} ); - expect( state.blocks.order ).toEqual( { + expect( state.byClientId ).toEqual( {} ); + expect( state.order ).toEqual( { '': [], } ); } ); it( 'should insert at the specified index', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'kumquat', @@ -643,7 +643,7 @@ describe( 'state', () => { } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'INSERT_BLOCKS', index: 1, blocks: [ { @@ -653,12 +653,12 @@ describe( 'state', () => { } ], } ); - expect( Object.keys( state.blocks.byClientId ) ).toHaveLength( 3 ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'kumquat', 'persimmon', 'loquat' ] ); + expect( Object.keys( state.byClientId ) ).toHaveLength( 3 ); + expect( state.order[ '' ] ).toEqual( [ 'kumquat', 'persimmon', 'loquat' ] ); } ); it( 'should move block to lower index', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -677,17 +677,17 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCK_TO_POSITION', clientId: 'ribs', index: 0, } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'ribs', 'chicken', 'veggies' ] ); + expect( state.order[ '' ] ).toEqual( [ 'ribs', 'chicken', 'veggies' ] ); } ); it( 'should move block to higher index', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -706,17 +706,17 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCK_TO_POSITION', clientId: 'ribs', index: 2, } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'chicken', 'veggies', 'ribs' ] ); + expect( state.order[ '' ] ).toEqual( [ 'chicken', 'veggies', 'ribs' ] ); } ); it( 'should not move block if passed same index', () => { - const original = editor( undefined, { + const original = blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'chicken', @@ -735,13 +735,13 @@ describe( 'state', () => { innerBlocks: [], } ], } ); - const state = editor( original, { + const state = blocks( original, { type: 'MOVE_BLOCK_TO_POSITION', clientId: 'ribs', index: 1, } ); - expect( state.blocks.order[ '' ] ).toEqual( [ 'chicken', 'ribs', 'veggies' ] ); + expect( state.order[ '' ] ).toEqual( [ 'chicken', 'ribs', 'veggies' ] ); } ); describe( 'blocks', () => { @@ -772,9 +772,9 @@ describe( 'state', () => { ], }, ]; - const original = deepFreeze( actions.reduce( editor, undefined ) ); + const original = deepFreeze( actions.reduce( blocks, undefined ) ); - const state = editor( original, { + const state = blocks( original, { type: 'RESET_BLOCKS', blocks: [ { @@ -787,7 +787,7 @@ describe( 'state', () => { ], } ); - expect( state.blocks.byClientId ).toEqual( { + expect( state.byClientId ).toEqual( { block2: { clientId: 'block2' }, block21: { clientId: 'block21' }, block22: { clientId: 'block22' }, @@ -799,11 +799,11 @@ describe( 'state', () => { describe( 'byClientId', () => { it( 'should ignore updates to non-existent block', () => { - const original = deepFreeze( editor( undefined, { + const original = deepFreeze( blocks( undefined, { type: 'RESET_BLOCKS', blocks: [], } ) ); - const state = editor( original, { + const state = blocks( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', clientId: 'kumquat', attributes: { @@ -811,11 +811,11 @@ describe( 'state', () => { }, } ); - expect( state.blocks.byClientId ).toBe( original.blocks.byClientId ); + expect( state.byClientId ).toBe( original.byClientId ); } ); it( 'should return with same reference if no changes in updates', () => { - const original = deepFreeze( editor( undefined, { + const original = deepFreeze( blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'kumquat', @@ -825,7 +825,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ) ); - const state = editor( original, { + const state = blocks( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', clientId: 'kumquat', attributes: { @@ -833,13 +833,13 @@ describe( 'state', () => { }, } ); - expect( state.blocks.byClientId ).toBe( state.blocks.byClientId ); + expect( state.byClientId ).toBe( state.byClientId ); } ); } ); describe( 'attributes', () => { it( 'should return with attribute block updates', () => { - const original = deepFreeze( editor( undefined, { + const original = deepFreeze( blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'kumquat', @@ -847,7 +847,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ) ); - const state = editor( original, { + const state = blocks( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', clientId: 'kumquat', attributes: { @@ -855,11 +855,11 @@ describe( 'state', () => { }, } ); - expect( state.blocks.attributes.kumquat.updated ).toBe( true ); + expect( state.attributes.kumquat.updated ).toBe( true ); } ); it( 'should accumulate attribute block updates', () => { - const original = deepFreeze( editor( undefined, { + const original = deepFreeze( blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'kumquat', @@ -869,7 +869,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ) ); - const state = editor( original, { + const state = blocks( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', clientId: 'kumquat', attributes: { @@ -877,18 +877,18 @@ describe( 'state', () => { }, } ); - expect( state.blocks.attributes.kumquat ).toEqual( { + expect( state.attributes.kumquat ).toEqual( { updated: true, moreUpdated: true, } ); } ); it( 'should ignore updates to non-existent block', () => { - const original = deepFreeze( editor( undefined, { + const original = deepFreeze( blocks( undefined, { type: 'RESET_BLOCKS', blocks: [], } ) ); - const state = editor( original, { + const state = blocks( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', clientId: 'kumquat', attributes: { @@ -896,11 +896,11 @@ describe( 'state', () => { }, } ); - expect( state.blocks.attributes ).toBe( original.blocks.attributes ); + expect( state.attributes ).toBe( original.attributes ); } ); it( 'should return with same reference if no changes in updates', () => { - const original = deepFreeze( editor( undefined, { + const original = deepFreeze( blocks( undefined, { type: 'RESET_BLOCKS', blocks: [ { clientId: 'kumquat', @@ -910,7 +910,7 @@ describe( 'state', () => { innerBlocks: [], } ], } ) ); - const state = editor( original, { + const state = blocks( original, { type: 'UPDATE_BLOCK_ATTRIBUTES', clientId: 'kumquat', attributes: { @@ -918,7 +918,7 @@ describe( 'state', () => { }, } ); - expect( state.blocks.attributes ).toBe( state.blocks.attributes ); + expect( state.attributes ).toBe( state.attributes ); } ); } ); } ); diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index c43727c749eef7..bcda13ad755ff6 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -144,43 +144,33 @@ describe( 'selectors', () => { const rootBlockOrder = []; const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - }, - attributes: { - 123: rootBlockAttributes, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + }, + attributes: { + 123: rootBlockAttributes, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; const nextState = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - }, - attributes: { - 123: rootBlockAttributes, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + }, + attributes: { + 123: rootBlockAttributes, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; expect( @@ -190,46 +180,36 @@ describe( 'selectors', () => { it( 'returns a new reference on added inner block', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - }, - attributes: { - 123: rootBlockAttributes, - }, - order: { - '': rootOrder, - 123: [], - }, + blocks: { + byClientId: { + 123: rootBlock, + }, + attributes: { + 123: rootBlockAttributes, + }, + order: { + '': rootOrder, + 123: [], }, - edits: {}, }, - initialEdits: {}, }; const nextState = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - 456: { clientId: 456, name: 'core/paragraph' }, - }, - attributes: { - 123: rootBlockAttributes, - 456: {}, - }, - order: { - '': rootOrder, - 123: [ 456 ], - 456: [], - }, + blocks: { + byClientId: { + 123: rootBlock, + 456: { clientId: 456, name: 'core/paragraph' }, + }, + attributes: { + 123: rootBlockAttributes, + 456: {}, + }, + order: { + '': rootOrder, + 123: [ 456 ], + 456: [], }, - edits: {}, }, - initialEdits: {}, }; expect( @@ -244,49 +224,39 @@ describe( 'selectors', () => { const childBlockOrder = []; const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - 456: childBlock, - }, - attributes: { - 123: rootBlockAttributes, - 456: childBlockAttributes, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - 456: childBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + 456: childBlock, + }, + attributes: { + 123: rootBlockAttributes, + 456: childBlockAttributes, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, + 456: childBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; const nextState = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - 456: childBlock, - }, - attributes: { - 123: rootBlockAttributes, - 456: childBlockAttributes, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - 456: childBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + 456: childBlock, + }, + attributes: { + 123: rootBlockAttributes, + 456: childBlockAttributes, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, + 456: childBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; expect( @@ -299,49 +269,39 @@ describe( 'selectors', () => { const childBlockOrder = []; const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - 456: { clientId: 456, name: 'core/paragraph' }, - }, - attributes: { - 123: rootBlockAttributes, - 456: {}, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - 456: childBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + 456: { clientId: 456, name: 'core/paragraph' }, + }, + attributes: { + 123: rootBlockAttributes, + 456: {}, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, + 456: childBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; const nextState = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - 456: { clientId: 456, name: 'core/paragraph' }, - }, - attributes: { - 123: rootBlockAttributes, - 456: { content: [ 'foo' ] }, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - 456: childBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + 456: { clientId: 456, name: 'core/paragraph' }, + }, + attributes: { + 123: rootBlockAttributes, + 456: { content: [ 'foo' ] }, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, + 456: childBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; expect( @@ -357,55 +317,45 @@ describe( 'selectors', () => { const grandChildBlockOrder = []; const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - 456: childBlock, - 789: { clientId: 789, name: 'core/paragraph' }, - }, - attributes: { - 123: rootBlockAttributes, - 456: childBlockAttributes, - 789: {}, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - 456: childBlockOrder, - 789: grandChildBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + 456: childBlock, + 789: { clientId: 789, name: 'core/paragraph' }, + }, + attributes: { + 123: rootBlockAttributes, + 456: childBlockAttributes, + 789: {}, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, + 456: childBlockOrder, + 789: grandChildBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; const nextState = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: rootBlock, - 456: childBlock, - 789: { clientId: 789, name: 'core/paragraph' }, - }, - attributes: { - 123: rootBlockAttributes, - 456: childBlockAttributes, - 789: { content: [ 'foo' ] }, - }, - order: { - '': rootOrder, - 123: rootBlockOrder, - 456: childBlockOrder, - 789: grandChildBlockOrder, - }, + blocks: { + byClientId: { + 123: rootBlock, + 456: childBlock, + 789: { clientId: 789, name: 'core/paragraph' }, + }, + attributes: { + 123: rootBlockAttributes, + 456: childBlockAttributes, + 789: { content: [ 'foo' ] }, + }, + order: { + '': rootOrder, + 123: rootBlockOrder, + 456: childBlockOrder, + 789: grandChildBlockOrder, }, - edits: {}, }, - initialEdits: {}, }; expect( @@ -417,16 +367,11 @@ describe( 'selectors', () => { describe( 'getBlockName', () => { it( 'returns null if no block by clientId', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: {}, - attributes: {}, - order: {}, - }, - edits: {}, + blocks: { + byClientId: {}, + attributes: {}, + order: {}, }, - initialEdits: {}, }; const name = getBlockName( state, 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ); @@ -436,26 +381,21 @@ describe( 'selectors', () => { it( 'returns block name', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': { - clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', - name: 'core/paragraph', - }, - }, - attributes: { - 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': {}, - }, - order: { - '': [ 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ], - 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': [], + blocks: { + byClientId: { + 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': { + clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1', + name: 'core/paragraph', }, }, - edits: {}, + attributes: { + 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': {}, + }, + order: { + '': [ 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ], + 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1': [], + }, }, - initialEdits: {}, }; const name = getBlockName( state, 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1' ); @@ -467,23 +407,18 @@ describe( 'selectors', () => { describe( 'getBlock', () => { it( 'should return the block', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: { clientId: 123, name: 'core/paragraph' }, - }, - attributes: { - 123: {}, - }, - order: { - '': [ 123 ], - 123: [], - }, + blocks: { + byClientId: { + 123: { clientId: 123, name: 'core/paragraph' }, + }, + attributes: { + 123: {}, + }, + order: { + '': [ 123 ], + 123: [], }, - edits: {}, }, - initialEdits: {}, }; expect( getBlock( state, 123 ) ).toEqual( { @@ -496,16 +431,11 @@ describe( 'selectors', () => { it( 'should return null if the block is not present in state', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: {}, - attributes: {}, - order: {}, - }, - edits: {}, + blocks: { + byClientId: {}, + attributes: {}, + order: {}, }, - initialEdits: {}, }; expect( getBlock( state, 123 ) ).toBe( null ); @@ -513,26 +443,21 @@ describe( 'selectors', () => { it( 'should include inner blocks', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 123: { clientId: 123, name: 'core/paragraph' }, - 456: { clientId: 456, name: 'core/paragraph' }, - }, - attributes: { - 123: {}, - 456: {}, - }, - order: { - '': [ 123 ], - 123: [ 456 ], - 456: [], - }, + blocks: { + byClientId: { + 123: { clientId: 123, name: 'core/paragraph' }, + 456: { clientId: 456, name: 'core/paragraph' }, + }, + attributes: { + 123: {}, + 456: {}, + }, + order: { + '': [ 123 ], + 123: [ 456 ], + 456: [], }, - edits: {}, }, - initialEdits: {}, }; expect( getBlock( state, 123 ) ).toEqual( { @@ -570,22 +495,18 @@ describe( 'selectors', () => { }, }, }, - editor: { - blocks: { - byClientId: { - 123: { clientId: 123, name: 'core/meta-block' }, - }, - attributes: { - 123: {}, - }, - order: { - '': [ 123 ], - 123: [], - }, + blocks: { + byClientId: { + 123: { clientId: 123, name: 'core/meta-block' }, + }, + attributes: { + 123: {}, + }, + order: { + '': [ 123 ], + 123: [], }, - edits: {}, }, - initialEdits: {}, }; expect( getBlock( state, 123 ) ).toEqual( { @@ -604,24 +525,19 @@ describe( 'selectors', () => { describe( 'getBlocks', () => { it( 'should return the ordered blocks', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 23: { clientId: 23, name: 'core/heading' }, - 123: { clientId: 123, name: 'core/paragraph' }, - }, - attributes: { - 23: {}, - 123: {}, - }, - order: { - '': [ 123, 23 ], - }, + blocks: { + byClientId: { + 23: { clientId: 23, name: 'core/heading' }, + 123: { clientId: 123, name: 'core/paragraph' }, + }, + attributes: { + 23: {}, + 123: {}, + }, + order: { + '': [ 123, 23 ], }, - edits: {}, }, - initialEdits: {}, }; expect( getBlocks( state ) ).toEqual( [ @@ -634,64 +550,59 @@ describe( 'selectors', () => { describe( 'getClientIdsOfDescendants', () => { it( 'should return the ids of any descendants, given an array of clientIds', () => { const state = { - currentPost: {}, - editor: { - 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' }, - }, - attributes: { - 'uuid-2': {}, - 'uuid-4': {}, - 'uuid-6': {}, - 'uuid-8': {}, - 'uuid-10': {}, - 'uuid-12': {}, - 'uuid-14': {}, - 'uuid-16': {}, - 'uuid-18': {}, - 'uuid-20': {}, - 'uuid-22': {}, - 'uuid-24': {}, - 'uuid-26': {}, - 'uuid-28': {}, - 'uuid-30': {}, - }, - order: { - '': [ 'uuid-6', 'uuid-8', 'uuid-10', 'uuid-22' ], - 'uuid-2': [ ], - 'uuid-4': [ ], - 'uuid-6': [ ], - 'uuid-8': [ ], - 'uuid-10': [ 'uuid-12', 'uuid-14' ], - 'uuid-12': [ 'uuid-16' ], - 'uuid-14': [ 'uuid-18' ], - 'uuid-16': [ ], - 'uuid-18': [ 'uuid-24' ], - 'uuid-20': [ ], - 'uuid-22': [ ], - 'uuid-24': [ 'uuid-26', 'uuid-28' ], - 'uuid-26': [ ], - 'uuid-28': [ 'uuid-30' ], - }, + 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' }, + }, + attributes: { + 'uuid-2': {}, + 'uuid-4': {}, + 'uuid-6': {}, + 'uuid-8': {}, + 'uuid-10': {}, + 'uuid-12': {}, + 'uuid-14': {}, + 'uuid-16': {}, + 'uuid-18': {}, + 'uuid-20': {}, + 'uuid-22': {}, + 'uuid-24': {}, + 'uuid-26': {}, + 'uuid-28': {}, + 'uuid-30': {}, + }, + order: { + '': [ 'uuid-6', 'uuid-8', 'uuid-10', 'uuid-22' ], + 'uuid-2': [ ], + 'uuid-4': [ ], + 'uuid-6': [ ], + 'uuid-8': [ ], + 'uuid-10': [ 'uuid-12', 'uuid-14' ], + 'uuid-12': [ 'uuid-16' ], + 'uuid-14': [ 'uuid-18' ], + 'uuid-16': [ ], + 'uuid-18': [ 'uuid-24' ], + 'uuid-20': [ ], + 'uuid-22': [ ], + 'uuid-24': [ 'uuid-26', 'uuid-28' ], + 'uuid-26': [ ], + 'uuid-28': [ 'uuid-30' ], }, - edits: {}, }, - initialEdits: {}, }; expect( getClientIdsOfDescendants( state, [ 'uuid-10' ] ) ).toEqual( [ 'uuid-12', @@ -709,64 +620,59 @@ describe( 'selectors', () => { describe( 'getClientIdsWithDescendants', () => { it( 'should return the ids for top-level blocks and their descendants of any depth (for nested blocks).', () => { const state = { - currentPost: {}, - editor: { - 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' }, - }, - attributes: { - 'uuid-2': {}, - 'uuid-4': {}, - 'uuid-6': {}, - 'uuid-8': {}, - 'uuid-10': {}, - 'uuid-12': {}, - 'uuid-14': {}, - 'uuid-16': {}, - 'uuid-18': {}, - 'uuid-20': {}, - 'uuid-22': {}, - 'uuid-24': {}, - 'uuid-26': {}, - 'uuid-28': {}, - 'uuid-30': {}, - }, - order: { - '': [ 'uuid-6', 'uuid-8', 'uuid-10', 'uuid-22' ], - 'uuid-2': [ ], - 'uuid-4': [ ], - 'uuid-6': [ ], - 'uuid-8': [ ], - 'uuid-10': [ 'uuid-12', 'uuid-14' ], - 'uuid-12': [ 'uuid-16' ], - 'uuid-14': [ 'uuid-18' ], - 'uuid-16': [ ], - 'uuid-18': [ 'uuid-24' ], - 'uuid-20': [ ], - 'uuid-22': [ ], - 'uuid-24': [ 'uuid-26', 'uuid-28' ], - 'uuid-26': [ ], - 'uuid-28': [ 'uuid-30' ], - }, + 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' }, + }, + attributes: { + 'uuid-2': {}, + 'uuid-4': {}, + 'uuid-6': {}, + 'uuid-8': {}, + 'uuid-10': {}, + 'uuid-12': {}, + 'uuid-14': {}, + 'uuid-16': {}, + 'uuid-18': {}, + 'uuid-20': {}, + 'uuid-22': {}, + 'uuid-24': {}, + 'uuid-26': {}, + 'uuid-28': {}, + 'uuid-30': {}, + }, + order: { + '': [ 'uuid-6', 'uuid-8', 'uuid-10', 'uuid-22' ], + 'uuid-2': [ ], + 'uuid-4': [ ], + 'uuid-6': [ ], + 'uuid-8': [ ], + 'uuid-10': [ 'uuid-12', 'uuid-14' ], + 'uuid-12': [ 'uuid-16' ], + 'uuid-14': [ 'uuid-18' ], + 'uuid-16': [ ], + 'uuid-18': [ 'uuid-24' ], + 'uuid-20': [ ], + 'uuid-22': [ ], + 'uuid-24': [ 'uuid-26', 'uuid-28' ], + 'uuid-26': [ ], + 'uuid-28': [ 'uuid-30' ], }, - edits: {}, }, - initialEdits: {}, }; expect( getClientIdsWithDescendants( state ) ).toEqual( [ 'uuid-6', @@ -788,19 +694,17 @@ describe( 'selectors', () => { describe( 'getBlockCount', () => { it( 'should return the number of top-level blocks in the post', () => { const state = { - editor: { - blocks: { - byClientId: { - 23: { clientId: 23, name: 'core/heading' }, - 123: { clientId: 123, name: 'core/paragraph' }, - }, - attributes: { - 23: {}, - 123: {}, - }, - order: { - '': [ 123, 23 ], - }, + blocks: { + byClientId: { + 23: { clientId: 23, name: 'core/heading' }, + 123: { clientId: 123, name: 'core/paragraph' }, + }, + attributes: { + 23: {}, + 123: {}, + }, + order: { + '': [ 123, 23 ], }, }, }; @@ -810,22 +714,20 @@ describe( 'selectors', () => { it( 'should return the number of blocks in a nested context', () => { const state = { - editor: { - blocks: { - byClientId: { - 123: { clientId: 123, name: 'core/columns' }, - 456: { clientId: 456, name: 'core/paragraph' }, - 789: { clientId: 789, name: 'core/paragraph' }, - }, - attributes: { - 123: {}, - 456: {}, - 789: {}, - }, - order: { - '': [ 123 ], - 123: [ 456, 789 ], - }, + blocks: { + byClientId: { + 123: { clientId: 123, name: 'core/columns' }, + 456: { clientId: 456, name: 'core/paragraph' }, + 789: { clientId: 789, name: 'core/paragraph' }, + }, + attributes: { + 123: {}, + 456: {}, + 789: {}, + }, + order: { + '': [ 123 ], + 123: [ 456, 789 ], }, }, }; @@ -871,21 +773,19 @@ describe( 'selectors', () => { describe( 'getGlobalBlockCount', () => { const state = { - editor: { - blocks: { - byClientId: { - 123: { clientId: 123, name: 'core/heading' }, - 456: { clientId: 456, name: 'core/paragraph' }, - 789: { clientId: 789, name: 'core/paragraph' }, - }, - attributes: { - 123: {}, - 456: {}, - 789: {}, - }, - order: { - '': [ 123, 456 ], - }, + blocks: { + byClientId: { + 123: { clientId: 123, name: 'core/heading' }, + 456: { clientId: 456, name: 'core/paragraph' }, + 789: { clientId: 789, name: 'core/paragraph' }, + }, + attributes: { + 123: {}, + 456: {}, + 789: {}, + }, + order: { + '': [ 123, 456 ], }, }, }; @@ -900,12 +800,10 @@ describe( 'selectors', () => { it( 'should return 0 if no blocks exist', () => { const emptyState = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - order: {}, - }, + blocks: { + byClientId: {}, + attributes: {}, + order: {}, }, }; expect( getGlobalBlockCount( emptyState ) ).toBe( 0 ); @@ -932,12 +830,10 @@ describe( 'selectors', () => { it( 'should return the selected block ClientId', () => { const state = { - editor: { - blocks: { - byClientId: { - 23: { - name: 'fake block', - }, + blocks: { + byClientId: { + 23: { + name: 'fake block', }, }, }, @@ -951,26 +847,21 @@ describe( 'selectors', () => { describe( 'getSelectedBlock', () => { it( 'should return null if no block is selected', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 23: { clientId: 23, name: 'core/heading' }, - 123: { clientId: 123, name: 'core/paragraph' }, - }, - attributes: { - 23: {}, - 123: {}, - }, - order: { - '': [ 23, 123 ], - 23: [], - 123: [], - }, + blocks: { + byClientId: { + 23: { clientId: 23, name: 'core/heading' }, + 123: { clientId: 123, name: 'core/paragraph' }, + }, + attributes: { + 23: {}, + 123: {}, + }, + order: { + '': [ 23, 123 ], + 23: [], + 123: [], }, - edits: {}, }, - initialEdits: {}, blockSelection: { start: null, end: null }, }; @@ -979,26 +870,21 @@ describe( 'selectors', () => { it( 'should return null if there is multi selection', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 23: { clientId: 23, name: 'core/heading' }, - 123: { clientId: 123, name: 'core/paragraph' }, - }, - attributes: { - 23: {}, - 123: {}, - }, - order: { - '': [ 23, 123 ], - 23: [], - 123: [], - }, + blocks: { + byClientId: { + 23: { clientId: 23, name: 'core/heading' }, + 123: { clientId: 123, name: 'core/paragraph' }, + }, + attributes: { + 23: {}, + 123: {}, + }, + order: { + '': [ 23, 123 ], + 23: [], + 123: [], }, - edits: {}, }, - initialEdits: {}, blockSelection: { start: 23, end: 123 }, }; @@ -1007,26 +893,21 @@ describe( 'selectors', () => { it( 'should return the selected block', () => { const state = { - currentPost: {}, - editor: { - blocks: { - byClientId: { - 23: { clientId: 23, name: 'core/heading' }, - 123: { clientId: 123, name: 'core/paragraph' }, - }, - attributes: { - 23: {}, - 123: {}, - }, - order: { - '': [ 23, 123 ], - 23: [], - 123: [], - }, + blocks: { + byClientId: { + 23: { clientId: 23, name: 'core/heading' }, + 123: { clientId: 123, name: 'core/paragraph' }, + }, + attributes: { + 23: {}, + 123: {}, + }, + order: { + '': [ 23, 123 ], + 23: [], + 123: [], }, - edits: {}, }, - initialEdits: {}, blockSelection: { start: 23, end: 23 }, }; @@ -1042,10 +923,8 @@ describe( 'selectors', () => { describe( 'getBlockRootClientId', () => { it( 'should return null if the block does not exist', () => { const state = { - editor: { - blocks: { - order: {}, - }, + blocks: { + order: {}, }, }; @@ -1054,12 +933,10 @@ describe( 'selectors', () => { it( 'should return root ClientId relative the block ClientId', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456, 56 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456, 56 ], }, }, }; @@ -1071,10 +948,8 @@ describe( 'selectors', () => { describe( 'getBlockHierarchyRootClientId', () => { it( 'should return the given block if the block has no parents', () => { const state = { - editor: { - blocks: { - order: {}, - }, + blocks: { + order: {}, }, }; @@ -1083,12 +958,10 @@ describe( 'selectors', () => { it( 'should return root ClientId relative the block ClientId', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456, 56 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456, 56 ], }, }, }; @@ -1098,13 +971,11 @@ describe( 'selectors', () => { it( 'should return the top level root ClientId relative the block ClientId', () => { const state = { - editor: { - blocks: { - order: { - '': [ '123', '23' ], - 123: [ '456', '56' ], - 56: [ '12' ], - }, + blocks: { + order: { + '': [ '123', '23' ], + 123: [ '456', '56' ], + 56: [ '12' ], }, }, }; @@ -1116,11 +987,9 @@ describe( 'selectors', () => { describe( 'getMultiSelectedBlockClientIds', () => { it( 'should return empty if there is no multi selection', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - }, + blocks: { + order: { + '': [ 123, 23 ], }, }, blockSelection: { start: null, end: null }, @@ -1131,11 +1000,9 @@ describe( 'selectors', () => { it( 'should return selected block clientIds if there is multi selection', () => { const state = { - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], }, }, blockSelection: { start: 2, end: 4 }, @@ -1146,12 +1013,10 @@ describe( 'selectors', () => { it( 'should return selected block clientIds if there is multi selection (nested context)', () => { const state = { - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - 4: [ 9, 8, 7, 6 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], + 4: [ 9, 8, 7, 6 ], }, }, blockSelection: { start: 7, end: 9 }, @@ -1164,17 +1029,12 @@ describe( 'selectors', () => { describe( 'getMultiSelectedBlocks', () => { it( 'should return the same reference on subsequent invocations of empty selection', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - order: {}, - }, - edits: {}, + blocks: { + byClientId: {}, + attributes: {}, + order: {}, }, - initialEdits: {}, blockSelection: { start: null, end: null }, - currentPost: {}, }; expect( @@ -1222,11 +1082,9 @@ describe( 'selectors', () => { describe( 'getBlockOrder', () => { it( 'should return the ordered block ClientIds of top-level blocks by default', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - }, + blocks: { + order: { + '': [ 123, 23 ], }, }, }; @@ -1236,12 +1094,10 @@ describe( 'selectors', () => { it( 'should return the ordered block ClientIds at a specified rootClientId', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456 ], }, }, }; @@ -1253,11 +1109,9 @@ describe( 'selectors', () => { describe( 'getBlockIndex', () => { it( 'should return the block order', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - }, + blocks: { + order: { + '': [ 123, 23 ], }, }, }; @@ -1267,12 +1121,10 @@ describe( 'selectors', () => { it( 'should return the block order (nested context)', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456, 56 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456, 56 ], }, }, }; @@ -1284,11 +1136,9 @@ describe( 'selectors', () => { describe( 'getPreviousBlockClientId', () => { it( 'should return the previous block', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - }, + blocks: { + order: { + '': [ 123, 23 ], }, }, }; @@ -1298,12 +1148,10 @@ describe( 'selectors', () => { it( 'should return the previous block (nested context)', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456, 56 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456, 56 ], }, }, }; @@ -1313,11 +1161,9 @@ describe( 'selectors', () => { it( 'should return null for the first block', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - }, + blocks: { + order: { + '': [ 123, 23 ], }, }, }; @@ -1327,12 +1173,10 @@ describe( 'selectors', () => { it( 'should return null for the first block (nested context)', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456, 56 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456, 56 ], }, }, }; @@ -1344,11 +1188,9 @@ describe( 'selectors', () => { describe( 'getNextBlockClientId', () => { it( 'should return the following block', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - }, + blocks: { + order: { + '': [ 123, 23 ], }, }, }; @@ -1358,12 +1200,10 @@ describe( 'selectors', () => { it( 'should return the following block (nested context)', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456, 56 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456, 56 ], }, }, }; @@ -1373,11 +1213,9 @@ describe( 'selectors', () => { it( 'should return null for the last block', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - }, + blocks: { + order: { + '': [ 123, 23 ], }, }, }; @@ -1387,12 +1225,10 @@ describe( 'selectors', () => { it( 'should return null for the last block (nested context)', () => { const state = { - editor: { - blocks: { - order: { - '': [ 123, 23 ], - 123: [ 456, 56 ], - }, + blocks: { + order: { + '': [ 123, 23 ], + 123: [ 456, 56 ], }, }, }; @@ -1431,11 +1267,9 @@ describe( 'selectors', () => { it( 'should return false if the selected block is a child of the given ClientId', () => { const state = { blockSelection: { start: 5, end: 5 }, - editor: { - blocks: { - order: { - 4: [ 3, 2, 1 ], - }, + blocks: { + order: { + 4: [ 3, 2, 1 ], }, }, }; @@ -1446,11 +1280,9 @@ describe( 'selectors', () => { it( 'should return true if the selected block is a child of the given ClientId', () => { const state = { blockSelection: { start: 3, end: 3 }, - editor: { - blocks: { - order: { - 4: [ 3, 2, 1 ], - }, + blocks: { + order: { + 4: [ 3, 2, 1 ], }, }, }; @@ -1460,11 +1292,9 @@ describe( 'selectors', () => { it( 'should return true if a multi selection exists that contains children of the block with the given ClientId', () => { const state = { - editor: { - blocks: { - order: { - 6: [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + 6: [ 5, 4, 3, 2, 1 ], }, }, blockSelection: { start: 2, end: 4 }, @@ -1474,12 +1304,10 @@ describe( 'selectors', () => { it( 'should return false if a multi selection exists bot does not contains children of the block with the given ClientId', () => { const state = { - editor: { - blocks: { - order: { - 3: [ 2, 1 ], - 6: [ 5, 4 ], - }, + blocks: { + order: { + 3: [ 2, 1 ], + 6: [ 5, 4 ], }, }, blockSelection: { start: 5, end: 4 }, @@ -1492,11 +1320,9 @@ describe( 'selectors', () => { it( 'should return true if the block is selected but not the last', () => { const state = { blockSelection: { start: 5, end: 3 }, - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], }, }, }; @@ -1507,11 +1333,9 @@ describe( 'selectors', () => { it( 'should return false if the block is the last selected', () => { const state = { blockSelection: { start: 5, end: 3 }, - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], }, }, }; @@ -1522,11 +1346,9 @@ describe( 'selectors', () => { it( 'should return false if the block is not selected', () => { const state = { blockSelection: { start: 5, end: 3 }, - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], }, }, }; @@ -1537,11 +1359,9 @@ describe( 'selectors', () => { it( 'should return false if there is no selection', () => { const state = { blockSelection: {}, - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], }, }, }; @@ -1587,11 +1407,9 @@ describe( 'selectors', () => { describe( 'isBlockMultiSelected', () => { const state = { - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], }, }, blockSelection: { start: 2, end: 4 }, @@ -1608,11 +1426,9 @@ describe( 'selectors', () => { describe( 'isFirstMultiSelectedBlock', () => { const state = { - editor: { - blocks: { - order: { - '': [ 5, 4, 3, 2, 1 ], - }, + blocks: { + order: { + '': [ 5, 4, 3, 2, 1 ], }, }, blockSelection: { start: 2, end: 4 }, @@ -1708,31 +1524,25 @@ describe( 'selectors', () => { describe( 'getBlockInsertionPoint', () => { it( 'should return the explicitly assigned insertion point', () => { const state = { - currentPost: {}, - preferences: { mode: 'visual' }, blockSelection: { start: 'clientId2', end: 'clientId2', }, - editor: { - blocks: { - byClientId: { - clientId1: { clientId: 'clientId1' }, - clientId2: { clientId: 'clientId2' }, - }, - attributes: { - clientId1: {}, - clientId2: {}, - }, - order: { - '': [ 'clientId1' ], - clientId1: [ 'clientId2' ], - clientId2: [], - }, + blocks: { + byClientId: { + clientId1: { clientId: 'clientId1' }, + clientId2: { clientId: 'clientId2' }, + }, + attributes: { + clientId1: {}, + clientId2: {}, + }, + order: { + '': [ 'clientId1' ], + clientId1: [ 'clientId2' ], + clientId2: [], }, - edits: {}, }, - initialEdits: {}, insertionPoint: { rootClientId: undefined, index: 0, @@ -1747,28 +1557,22 @@ describe( 'selectors', () => { it( 'should return an object for the selected block', () => { const state = { - currentPost: {}, - preferences: { mode: 'visual' }, blockSelection: { start: 'clientId1', end: 'clientId1', }, - editor: { - blocks: { - byClientId: { - clientId1: { clientId: 'clientId1' }, - }, - attributes: { - clientId1: {}, - }, - order: { - '': [ 'clientId1' ], - clientId1: [], - }, + blocks: { + byClientId: { + clientId1: { clientId: 'clientId1' }, + }, + attributes: { + clientId1: {}, + }, + order: { + '': [ 'clientId1' ], + clientId1: [], }, - edits: {}, }, - initialEdits: {}, insertionPoint: null, }; @@ -1780,31 +1584,25 @@ describe( 'selectors', () => { it( 'should return an object for the nested selected block', () => { const state = { - currentPost: {}, - preferences: { mode: 'visual' }, blockSelection: { start: 'clientId2', end: 'clientId2', }, - editor: { - blocks: { - byClientId: { - clientId1: { clientId: 'clientId1' }, - clientId2: { clientId: 'clientId2' }, - }, - attributes: { - clientId1: {}, - clientId2: {}, - }, - order: { - '': [ 'clientId1' ], - clientId1: [ 'clientId2' ], - clientId2: [], - }, + blocks: { + byClientId: { + clientId1: { clientId: 'clientId1' }, + clientId2: { clientId: 'clientId2' }, + }, + attributes: { + clientId1: {}, + clientId2: {}, + }, + order: { + '': [ 'clientId1' ], + clientId1: [ 'clientId2' ], + clientId2: [], }, - edits: {}, }, - initialEdits: {}, insertionPoint: null, }; @@ -1816,31 +1614,25 @@ describe( 'selectors', () => { it( 'should return an object for the last multi selected clientId', () => { const state = { - currentPost: {}, - preferences: { mode: 'visual' }, blockSelection: { start: 'clientId1', end: 'clientId2', }, - editor: { - blocks: { - byClientId: { - clientId1: { clientId: 'clientId1' }, - clientId2: { clientId: 'clientId2' }, - }, - attributes: { - clientId1: {}, - clientId2: {}, - }, - order: { - '': [ 'clientId1', 'clientId2' ], - clientId1: [], - clientId2: [], - }, + blocks: { + byClientId: { + clientId1: { clientId: 'clientId1' }, + clientId2: { clientId: 'clientId2' }, + }, + attributes: { + clientId1: {}, + clientId2: {}, + }, + order: { + '': [ 'clientId1', 'clientId2' ], + clientId1: [], + clientId2: [], }, - edits: {}, }, - initialEdits: {}, insertionPoint: null, }; @@ -1852,31 +1644,25 @@ describe( 'selectors', () => { it( 'should return an object for the last block if no selection', () => { const state = { - currentPost: {}, - preferences: { mode: 'visual' }, blockSelection: { start: null, end: null, }, - editor: { - blocks: { - byClientId: { - clientId1: { clientId: 'clientId1' }, - clientId2: { clientId: 'clientId2' }, - }, - attributes: { - clientId1: {}, - clientId2: {}, - }, - order: { - '': [ 'clientId1', 'clientId2' ], - clientId1: [], - clientId2: [], - }, + blocks: { + byClientId: { + clientId1: { clientId: 'clientId1' }, + clientId2: { clientId: 'clientId2' }, + }, + attributes: { + clientId1: {}, + clientId2: {}, + }, + order: { + '': [ 'clientId1', 'clientId2' ], + clientId1: [], + clientId2: [], }, - edits: {}, }, - initialEdits: {}, insertionPoint: null, }; @@ -1911,11 +1697,9 @@ describe( 'selectors', () => { describe( 'canInsertBlockType', () => { it( 'should deny blocks that are not registered', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - }, + blocks: { + byClientId: {}, + attributes: {}, }, blockListSettings: {}, settings: {}, @@ -1925,11 +1709,9 @@ describe( 'selectors', () => { it( 'should deny blocks that are not allowed by the editor', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - }, + blocks: { + byClientId: {}, + attributes: {}, }, blockListSettings: {}, settings: { @@ -1941,11 +1723,9 @@ describe( 'selectors', () => { it( 'should allow blocks that are allowed by the editor', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - }, + blocks: { + byClientId: {}, + attributes: {}, }, blockListSettings: {}, settings: { @@ -1957,11 +1737,9 @@ describe( 'selectors', () => { it( 'should deny blocks when the editor has a template lock', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - }, + blocks: { + byClientId: {}, + attributes: {}, }, blockListSettings: {}, settings: { @@ -1973,11 +1751,9 @@ describe( 'selectors', () => { it( 'should deny blocks that restrict parent from being inserted into the root', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - }, + blocks: { + byClientId: {}, + attributes: {}, }, blockListSettings: {}, settings: {}, @@ -1987,14 +1763,12 @@ describe( 'selectors', () => { it( 'should deny blocks that restrict parent from being inserted into a restricted parent', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-a' }, - }, - attributes: { - block1: {}, - }, + blocks: { + byClientId: { + block1: { name: 'core/test-block-a' }, + }, + attributes: { + block1: {}, }, }, blockListSettings: {}, @@ -2005,14 +1779,12 @@ describe( 'selectors', () => { it( 'should allow blocks that restrict parent to be inserted into an allowed parent', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-b' }, - }, - attributes: { - block1: {}, - }, + blocks: { + byClientId: { + block1: { name: 'core/test-block-b' }, + }, + attributes: { + block1: {}, }, }, blockListSettings: {}, @@ -2023,14 +1795,12 @@ describe( 'selectors', () => { it( 'should deny restricted blocks from being inserted into a block that restricts allowedBlocks', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-a' }, - }, - attributes: { - block1: {}, - }, + blocks: { + byClientId: { + block1: { name: 'core/test-block-a' }, + }, + attributes: { + block1: {}, }, }, blockListSettings: { @@ -2045,14 +1815,12 @@ describe( 'selectors', () => { it( 'should allow allowed blocks to be inserted into a block that restricts allowedBlocks', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-a' }, - }, - attributes: { - block1: {}, - }, + blocks: { + byClientId: { + block1: { name: 'core/test-block-a' }, + }, + attributes: { + block1: {}, }, }, blockListSettings: { @@ -2067,14 +1835,12 @@ describe( 'selectors', () => { it( 'should prioritise parent over allowedBlocks', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-b' }, - }, - attributes: { - block1: {}, - }, + blocks: { + byClientId: { + block1: { name: 'core/test-block-b' }, + }, + attributes: { + block1: {}, }, }, blockListSettings: { @@ -2091,25 +1857,20 @@ describe( 'selectors', () => { describe( 'getInserterItems', () => { it( 'should properly list block type and reusable block items', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-a' }, - }, - attributes: { - block1: {}, - }, - order: {}, + blocks: { + byClientId: { + block1: { name: 'core/test-block-a' }, }, - edits: {}, + attributes: { + block1: {}, + }, + order: {}, }, - initialEdits: {}, settings: { __experimentalReusableBlocks: [ { id: 1, isTemporary: false, clientId: 'block1', title: 'Reusable Block 1' }, ], }, - currentPost: {}, preferences: { insertUsage: {}, }, @@ -2151,39 +1912,34 @@ describe( 'selectors', () => { it( 'should not list a reusable block item if it is being inserted inside it self', () => { const state = { - editor: { - blocks: { - byClientId: { - block1ref: { - name: 'core/block', - clientId: 'block1ref', - }, - itselfBlock1: { name: 'core/test-block-a' }, - itselfBlock2: { name: 'core/test-block-b' }, + blocks: { + byClientId: { + block1ref: { + name: 'core/block', + clientId: 'block1ref', }, - attributes: { - block1ref: { - attributes: { - ref: 1, - }, + itselfBlock1: { name: 'core/test-block-a' }, + itselfBlock2: { name: 'core/test-block-b' }, + }, + attributes: { + block1ref: { + attributes: { + ref: 1, }, - itselfBlock1: {}, - itselfBlock2: {}, - }, - order: { - '': [ 'block1ref' ], }, + itselfBlock1: {}, + itselfBlock2: {}, + }, + order: { + '': [ 'block1ref' ], }, - edits: {}, }, - initialEdits: {}, settings: { __experimentalReusableBlocks: [ { id: 1, isTemporary: false, clientId: 'itselfBlock1', title: 'Reusable Block 1' }, { id: 2, isTemporary: false, clientId: 'itselfBlock2', title: 'Reusable Block 2' }, ], }, - currentPost: {}, preferences: { insertUsage: {}, }, @@ -2210,45 +1966,41 @@ describe( 'selectors', () => { it( 'should not list a reusable block item if it is being inserted inside a descendent', () => { const state = { - editor: { - 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' }, + blocks: { + byClientId: { + block2ref: { + name: 'core/block', + clientId: 'block1ref', }, - attributes: { - block2ref: { - attributes: { - ref: 2, - }, + referredBlock1: { name: 'core/test-block-a' }, + referredBlock2: { name: 'core/test-block-b' }, + childReferredBlock2: { name: 'core/test-block-a' }, + grandchildReferredBlock2: { name: 'core/test-block-b' }, + }, + attributes: { + block2ref: { + attributes: { + ref: 2, }, - referredBlock1: {}, - referredBlock2: {}, - childReferredBlock2: {}, - grandchildReferredBlock2: {}, - }, - order: { - '': [ 'block2ref' ], - referredBlock2: [ 'childReferredBlock2' ], - childReferredBlock2: [ 'grandchildReferredBlock2' ], }, + referredBlock1: {}, + referredBlock2: {}, + childReferredBlock2: {}, + grandchildReferredBlock2: {}, + }, + order: { + '': [ 'block2ref' ], + referredBlock2: [ 'childReferredBlock2' ], + childReferredBlock2: [ 'grandchildReferredBlock2' ], }, - edits: {}, }, - initialEdits: {}, + settings: { __experimentalReusableBlocks: [ { id: 1, isTemporary: false, clientId: 'referredBlock1', title: 'Reusable Block 1' }, { id: 2, isTemporary: false, clientId: 'referredBlock2', title: 'Reusable Block 2' }, ], }, - currentPost: {}, preferences: { insertUsage: {}, }, @@ -2274,28 +2026,23 @@ describe( 'selectors', () => { } ); it( 'should order items by descending utility and frecency', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-a' }, - block2: { name: 'core/test-block-a' }, - }, - attributes: { - block1: {}, - block2: {}, - }, - order: {}, + blocks: { + byClientId: { + block1: { name: 'core/test-block-a' }, + block2: { name: 'core/test-block-a' }, }, - edits: {}, + attributes: { + block1: {}, + block2: {}, + }, + order: {}, }, - initialEdits: {}, settings: { __experimentalReusableBlocks: [ { id: 1, isTemporary: false, clientId: 'block1', title: 'Reusable Block 1' }, { id: 2, isTemporary: false, clientId: 'block2', title: 'Reusable Block 2' }, ], }, - currentPost: {}, preferences: { insertUsage: { 'core/block/1': { count: 10, time: 1000 }, @@ -2316,34 +2063,29 @@ describe( 'selectors', () => { it( 'should correctly cache the return values', () => { const state = { - editor: { - 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' }, - }, - attributes: { - block1: {}, - block2: {}, - block3: {}, - block4: {}, - }, - order: { - '': [ 'block3', 'block4' ], - }, + 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' }, + }, + attributes: { + block1: {}, + block2: {}, + block3: {}, + block4: {}, + }, + order: { + '': [ 'block3', 'block4' ], }, - edits: {}, }, - initialEdits: {}, settings: { __experimentalReusableBlocks: [ { id: 1, isTemporary: false, clientId: 'block1', title: 'Reusable Block 1' }, { id: 2, isTemporary: false, clientId: 'block2', title: 'Reusable Block 2' }, ], }, - currentPost: {}, preferences: { insertUsage: {}, }, @@ -2386,25 +2128,17 @@ describe( 'selectors', () => { it( 'should set isDisabled when a block with `multiple: false` has been used', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { clientId: 'block1', name: 'core/test-block-b' }, - }, - attributes: { - block1: { attribute: {} }, - }, - order: { - '': [ 'block1' ], - }, + blocks: { + byClientId: { + block1: { clientId: 'block1', name: 'core/test-block-b' }, + }, + attributes: { + block1: { attribute: {} }, + }, + order: { + '': [ 'block1' ], }, - edits: {}, - }, - initialEdits: {}, - reusableBlocks: { - data: {}, }, - currentPost: {}, preferences: { insertUsage: {}, }, @@ -2418,19 +2152,11 @@ describe( 'selectors', () => { it( 'should give common blocks a low utility', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - order: {}, - }, - edits: {}, - }, - initialEdits: {}, - reusableBlocks: { - data: {}, + blocks: { + byClientId: {}, + attributes: {}, + order: {}, }, - currentPost: {}, preferences: { insertUsage: {}, }, @@ -2444,19 +2170,11 @@ describe( 'selectors', () => { it( 'should give used blocks a medium utility and set a frecency', () => { const state = { - editor: { - blocks: { - byClientId: {}, - attributes: {}, - order: {}, - }, - edits: {}, - }, - initialEdits: {}, - reusableBlocks: { - data: {}, + blocks: { + byClientId: {}, + attributes: {}, + order: {}, }, - currentPost: {}, preferences: { insertUsage: { 'core/test-block-b': { count: 10, time: 1000 }, @@ -2473,25 +2191,17 @@ describe( 'selectors', () => { it( 'should give contextual blocks a high utility', () => { const state = { - editor: { - blocks: { - byClientId: { - block1: { name: 'core/test-block-b' }, - }, - attributes: { - block1: { attribute: {} }, - }, - order: { - '': [ 'block1' ], - }, + blocks: { + byClientId: { + block1: { name: 'core/test-block-b' }, + }, + attributes: { + block1: { attribute: {} }, + }, + order: { + '': [ 'block1' ], }, - edits: {}, - }, - initialEdits: {}, - reusableBlocks: { - data: {}, }, - currentPost: {}, preferences: { insertUsage: {}, },