From 0cefdb2d841ef177a517b3b813f9fa07ff48bff0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 22 May 2019 11:36:48 +0100 Subject: [PATCH] Adds grouping interaction to state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enables the ability register a given block as the block which handles “grouping” interactions within the editor. Related https://github.com/WordPress/gutenberg/pull/14908 --- .../developers/data/data-core-blocks.md | 26 +++++++++++++++++++ packages/blocks/README.md | 17 ++++++++++++ packages/blocks/src/api/index.js | 2 ++ packages/blocks/src/api/registration.js | 18 +++++++++++++ packages/blocks/src/store/actions.js | 16 ++++++++++++ packages/blocks/src/store/reducer.js | 2 ++ packages/blocks/src/store/selectors.js | 11 ++++++++ 7 files changed, 92 insertions(+) diff --git a/docs/designers-developers/developers/data/data-core-blocks.md b/docs/designers-developers/developers/data/data-core-blocks.md index 5256587043602d..b1d377ed11a6fe 100644 --- a/docs/designers-developers/developers/data/data-core-blocks.md +++ b/docs/designers-developers/developers/data/data-core-blocks.md @@ -108,6 +108,18 @@ _Returns_ - `?string`: Name of the block for handling non-block content. +# **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. + # **getUnregisteredFallbackBlockName** Returns the name of the block for handling unregistered blocks. @@ -270,6 +282,20 @@ _Returns_ - `Object`: Action object. +# **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. + # **setUnregisteredFallbackBlockName** Returns an action object used to set the name of the block used as a fallback diff --git a/packages/blocks/README.md b/packages/blocks/README.md index b7a8e5fd70c9dd..84c7dbba40f037 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -372,6 +372,15 @@ _Returns_ - `?string`: Blog name. +# **getGroupingBlockName** + +Retrieves name of block used for handling grouping interactions, or undefined if no +handler has been defined. + +_Returns_ + +- `?string`: Blog name. + # **getPhrasingContentSchema** Get schema of possible paths for phrasing content. @@ -668,6 +677,14 @@ _Parameters_ - _blockName_ `string`: Block name. +# **setGroupingBlockName** + +Assigns the name of the block used in grouping interactions. + +_Parameters_ + +- _name_ `string`: Block name. + # **switchToBlockType** Switch one or more blocks into one or more blocks of the new block type. diff --git a/packages/blocks/src/api/index.js b/packages/blocks/src/api/index.js index c13b28f4903ca0..68e60ed43952b1 100644 --- a/packages/blocks/src/api/index.js +++ b/packages/blocks/src/api/index.js @@ -35,6 +35,8 @@ export { getUnregisteredTypeHandlerName, setDefaultBlockName, getDefaultBlockName, + setGroupingBlockName, + getGroupingBlockName, getBlockType, getBlockTypes, getBlockSupport, diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index 8f1155fbce3400..c04a909546d2a4 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -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. * @@ -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. * diff --git a/packages/blocks/src/store/actions.js b/packages/blocks/src/store/actions.js index 8f2d9c834d26dc..220ae9be0ea0d3 100644 --- a/packages/blocks/src/store/actions.js +++ b/packages/blocks/src/store/actions.js @@ -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. * diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index bfeeec10ec1e10..4e3131ca7b62e0 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -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 @@ -164,5 +165,6 @@ export default combineReducers( { defaultBlockName, freeformFallbackBlockName, unregisteredFallbackBlockName, + groupingBlockName, categories, } ); diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index 97d323c65fb168..25fe40ca9f6111 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -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. *