Skip to content

Commit

Permalink
Adds grouping interaction to state
Browse files Browse the repository at this point in the history
Enables the ability register a given block as the block which handles “grouping” interactions within the editor.

Related #14908
  • Loading branch information
getdave committed Jun 5, 2019
1 parent 788a3d2 commit 0cefdb2
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/designers-developers/developers/data/data-core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ _Returns_

- `?string`: Name of the block for handling non-block content.

<a name="getGroupingBlockName" href="#getGroupingBlockName">#</a> **getGroupingBlockName**

Returns the name of the block for handling unregistered blocks.

_Parameters_

- _state_ `Object`: Data state.

_Returns_

- `?string`: Name of the block for handling unregistered blocks.

<a name="getUnregisteredFallbackBlockName" href="#getUnregisteredFallbackBlockName">#</a> **getUnregisteredFallbackBlockName**

Returns the name of the block for handling unregistered blocks.
Expand Down Expand Up @@ -270,6 +282,20 @@ _Returns_

- `Object`: Action object.

<a name="setGroupingBlockName" href="#setGroupingBlockName">#</a> **setGroupingBlockName**

Returns an action object used to set the name of the block used
when grouping other blocks
eg: in "Group/Ungroup" interactions

_Parameters_

- _name_ `string`: Block name.

_Returns_

- `Object`: Action object.

<a name="setUnregisteredFallbackBlockName" href="#setUnregisteredFallbackBlockName">#</a> **setUnregisteredFallbackBlockName**

Returns an action object used to set the name of the block used as a fallback
Expand Down
17 changes: 17 additions & 0 deletions packages/blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,15 @@ _Returns_

- `?string`: Blog name.

<a name="getGroupingBlockName" href="#getGroupingBlockName">#</a> **getGroupingBlockName**

Retrieves name of block used for handling grouping interactions, or undefined if no
handler has been defined.

_Returns_

- `?string`: Blog name.

<a name="getPhrasingContentSchema" href="#getPhrasingContentSchema">#</a> **getPhrasingContentSchema**

Get schema of possible paths for phrasing content.
Expand Down Expand Up @@ -668,6 +677,14 @@ _Parameters_

- _blockName_ `string`: Block name.

<a name="setGroupingBlockName" href="#setGroupingBlockName">#</a> **setGroupingBlockName**

Assigns the name of the block used in grouping interactions.

_Parameters_

- _name_ `string`: Block name.

<a name="switchToBlockType" href="#switchToBlockType">#</a> **switchToBlockType**

Switch one or more blocks into one or more blocks of the new block type.
Expand Down
2 changes: 2 additions & 0 deletions packages/blocks/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export {
getUnregisteredTypeHandlerName,
setDefaultBlockName,
getDefaultBlockName,
setGroupingBlockName,
getGroupingBlockName,
getBlockType,
getBlockTypes,
getBlockSupport,
Expand Down
18 changes: 18 additions & 0 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ export function getFreeformContentHandlerName() {
return select( 'core/blocks' ).getFreeformFallbackBlockName();
}

/**
* Retrieves name of block used for handling grouping interactions
*
* @return {?string} Blog name.
*/
export function getGroupingBlockName() {
return select( 'core/blocks' ).getGroupingBlockName();
}

/**
* Assigns name of block handling unregistered block types.
*
Expand Down Expand Up @@ -227,6 +236,15 @@ export function setDefaultBlockName( name ) {
dispatch( 'core/blocks' ).setDefaultBlockName( name );
}

/**
* Assigns the grouping block name.
*
* @param {string} name Block name.
*/
export function setGroupingBlockName( name ) {
dispatch( 'core/blocks' ).setGroupingBlockName( name );
}

/**
* Retrieves the default block name.
*
Expand Down
16 changes: 16 additions & 0 deletions packages/blocks/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ export function setUnregisteredFallbackBlockName( name ) {
};
}

/**
* Returns an action object used to set the name of the block used
* when grouping other blocks
* eg: in "Group/Ungroup" interactions
*
* @param {string} name Block name.
*
* @return {Object} Action object.
*/
export function setGroupingBlockName( name ) {
return {
type: 'SET_GROUPING_BLOCK_NAME',
name,
};
}

/**
* Returns an action object used to set block categories.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function createBlockNameSetterReducer( setActionType ) {
export const defaultBlockName = createBlockNameSetterReducer( 'SET_DEFAULT_BLOCK_NAME' );
export const freeformFallbackBlockName = createBlockNameSetterReducer( 'SET_FREEFORM_FALLBACK_BLOCK_NAME' );
export const unregisteredFallbackBlockName = createBlockNameSetterReducer( 'SET_UNREGISTERED_FALLBACK_BLOCK_NAME' );
export const groupingBlockName = createBlockNameSetterReducer( 'SET_GROUPING_BLOCK_NAME' );

/**
* Reducer managing the categories
Expand Down Expand Up @@ -164,5 +165,6 @@ export default combineReducers( {
defaultBlockName,
freeformFallbackBlockName,
unregisteredFallbackBlockName,
groupingBlockName,
categories,
} );
11 changes: 11 additions & 0 deletions packages/blocks/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ export function getUnregisteredFallbackBlockName( state ) {
return state.unregisteredFallbackBlockName;
}

/**
* Returns the name of the block for handling unregistered blocks.
*
* @param {Object} state Data state.
*
* @return {string?} Name of the block for handling unregistered blocks.
*/
export function getGroupingBlockName( state ) {
return state.groupingBlockName;
}

/**
* Returns an array with the child blocks of a given block.
*
Expand Down

0 comments on commit 0cefdb2

Please sign in to comment.