From 404f5b31b563a9dd029a9ab17b54ccd73d0de60e Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 24 Jan 2023 14:35:41 +0800 Subject: [PATCH] Update block editor store to make the block interface API properly experimental --- packages/block-editor/src/store/actions.js | 22 ------------------- packages/block-editor/src/store/index.js | 6 +++++ .../block-editor/src/store/private-actions.js | 21 ++++++++++++++++++ .../src/store/private-selectors.js | 10 +++++++++ packages/block-editor/src/store/reducer.js | 4 ++-- packages/block-editor/src/store/selectors.js | 11 ---------- 6 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 packages/block-editor/src/store/private-actions.js create mode 100644 packages/block-editor/src/store/private-selectors.js diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index e1c88c2bd99b49..0b8da600e64541 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1263,28 +1263,6 @@ export function toggleBlockMode( clientId ) { }; } -/** - * Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be hidden. - * - * @return {Object} Action object. - */ -export function __experimentalHideBlockInterface() { - return { - type: 'HIDE_BLOCK_INTERFACE', - }; -} - -/** - * Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be shown. - * - * @return {Object} Action object. - */ -export function __experimentalShowBlockInterface() { - return { - type: 'SHOW_BLOCK_INTERFACE', - }; -} - /** * Returns an action object used in signalling that the user has begun to type. * diff --git a/packages/block-editor/src/store/index.js b/packages/block-editor/src/store/index.js index a4fc9f5b99a06f..1781a93f5dbf76 100644 --- a/packages/block-editor/src/store/index.js +++ b/packages/block-editor/src/store/index.js @@ -8,8 +8,11 @@ import { createReduxStore, registerStore } from '@wordpress/data'; */ import reducer from './reducer'; import * as selectors from './selectors'; +import * as privateActions from './private-actions'; +import * as privateSelectors from './private-selectors'; import * as actions from './actions'; import { STORE_NAME } from './constants'; +import { unlock } from '../experiments'; /** * Block editor data store configuration. @@ -32,6 +35,9 @@ export const store = createReduxStore( STORE_NAME, { persist: [ 'preferences' ], } ); +unlock( store ).registerPrivateActions( privateActions ); +unlock( store ).registerPrivateSelectors( privateSelectors ); + // Ideally we'd use register instead of register stores. registerStore( STORE_NAME, { ...storeConfig, diff --git a/packages/block-editor/src/store/private-actions.js b/packages/block-editor/src/store/private-actions.js new file mode 100644 index 00000000000000..72cd2df3e34f62 --- /dev/null +++ b/packages/block-editor/src/store/private-actions.js @@ -0,0 +1,21 @@ +/** + * Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be hidden. + * + * @return {Object} Action object. + */ +export function __experimentalHideBlockInterface() { + return { + type: '__experimental_HIDE_BLOCK_INTERFACE', + }; +} + +/** + * Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be shown. + * + * @return {Object} Action object. + */ +export function __experimentalShowBlockInterface() { + return { + type: '__experimental_SHOW_BLOCK_INTERFACE', + }; +} diff --git a/packages/block-editor/src/store/private-selectors.js b/packages/block-editor/src/store/private-selectors.js new file mode 100644 index 00000000000000..cd225f76739329 --- /dev/null +++ b/packages/block-editor/src/store/private-selectors.js @@ -0,0 +1,10 @@ +/** + * Returns true if the the block interface should be hidden, or false otherwise. + * + * @param {Object} state Global application state. + * + * @return {boolean} Whether the block toolbar is hidden. + */ +export function __experimentalIsBlockInterfaceHidden( state ) { + return state.isBlockInterfaceHidden; +} diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index 919ca1dceb4e32..ccb84a9f17e2ee 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -1197,10 +1197,10 @@ export const blocks = pipe( */ export function isBlockInterfaceHidden( state = false, action ) { switch ( action.type ) { - case 'HIDE_BLOCK_INTERFACE': + case '__experimental_HIDE_BLOCK_INTERFACE': return true; - case 'SHOW_BLOCK_INTERFACE': + case '__experimental_SHOW_BLOCK_INTERFACE': return false; } diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 68087f231e56a4..46899f91db090a 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1262,17 +1262,6 @@ export function isTyping( state ) { return state.isTyping; } -/** - * Returns true if the the block interface should be hidden, or false otherwise. - * - * @param {Object} state Global application state. - * - * @return {boolean} Whether the block toolbar is hidden. - */ -export function __experimentalIsBlockInterfaceHidden( state ) { - return state.isBlockInterfaceHidden; -} - /** * Returns true if the user is dragging blocks, or false otherwise. *