From bb9ec5ef29287467a823790d19b18244910cd347 Mon Sep 17 00:00:00 2001 From: Rafael Galani Date: Sat, 19 Dec 2020 19:51:35 -0300 Subject: [PATCH] Removing 'rich-text' references to the store name (#27820) --- packages/rich-text/src/component/index.native.js | 3 ++- .../rich-text/src/component/use-format-types.js | 6 +++++- packages/rich-text/src/get-format-type.js | 6 +++++- packages/rich-text/src/get-format-types.js | 6 +++++- packages/rich-text/src/register-format-type.js | 13 ++++++++----- packages/rich-text/src/test/register-format-type.js | 3 ++- packages/rich-text/src/unregister-format-type.js | 9 +++++++-- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 55014be9be7cf..3ecede565bbde 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -43,6 +43,7 @@ import { removeLineSeparator } from '../remove-line-separator'; import { isCollapsed } from '../is-collapsed'; import { remove } from '../remove'; import styles from './style.scss'; +import { store as richTextStore } from '../store'; const unescapeSpaces = ( text ) => { return text.replace( / | /gi, ' ' ); @@ -955,7 +956,7 @@ export default compose( [ get( parentBlock, [ 'attributes', 'childrenStyles' ] ) || {}; return { - formatTypes: select( 'core/rich-text' ).getFormatTypes(), + formatTypes: select( richTextStore ).getFormatTypes(), isMentionsSupported: getSettings( 'capabilities' ).mentions === true, ...{ parentBlockStyles }, diff --git a/packages/rich-text/src/component/use-format-types.js b/packages/rich-text/src/component/use-format-types.js index 285e5ee540eaf..c1df61ac093c1 100644 --- a/packages/rich-text/src/component/use-format-types.js +++ b/packages/rich-text/src/component/use-format-types.js @@ -2,9 +2,13 @@ * WordPress dependencies */ import { useSelect, useDispatch } from '@wordpress/data'; +/** + * Internal dependencies + */ +import { store as richTextStore } from '../store'; function formatTypesSelector( select ) { - return select( 'core/rich-text' ).getFormatTypes(); + return select( richTextStore ).getFormatTypes(); } /** diff --git a/packages/rich-text/src/get-format-type.js b/packages/rich-text/src/get-format-type.js index 7b266f66779a7..48e41d41b9c79 100644 --- a/packages/rich-text/src/get-format-type.js +++ b/packages/rich-text/src/get-format-type.js @@ -2,6 +2,10 @@ * WordPress dependencies */ import { select } from '@wordpress/data'; +/** + * Internal dependencies + */ +import { store as richTextStore } from './store'; /** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */ @@ -13,5 +17,5 @@ import { select } from '@wordpress/data'; * @return {RichTextFormatType|undefined} Format type. */ export function getFormatType( name ) { - return select( 'core/rich-text' ).getFormatType( name ); + return select( richTextStore ).getFormatType( name ); } diff --git a/packages/rich-text/src/get-format-types.js b/packages/rich-text/src/get-format-types.js index 8f2d88f004099..74bec3a355aa6 100644 --- a/packages/rich-text/src/get-format-types.js +++ b/packages/rich-text/src/get-format-types.js @@ -2,6 +2,10 @@ * WordPress dependencies */ import { select } from '@wordpress/data'; +/** + * Internal dependencies + */ +import { store as richTextStore } from './store'; /** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */ @@ -11,5 +15,5 @@ import { select } from '@wordpress/data'; * @return {Array} Format settings. */ export function getFormatTypes() { - return select( 'core/rich-text' ).getFormatTypes(); + return select( richTextStore ).getFormatTypes(); } diff --git a/packages/rich-text/src/register-format-type.js b/packages/rich-text/src/register-format-type.js index 80e9d1680bc7f..e3c096804e0ee 100644 --- a/packages/rich-text/src/register-format-type.js +++ b/packages/rich-text/src/register-format-type.js @@ -2,7 +2,10 @@ * WordPress dependencies */ import { select, dispatch } from '@wordpress/data'; - +/** + * Internal dependencies + */ +import { store as richTextStore } from './store'; /** * @typedef {Object} WPFormat * @@ -44,7 +47,7 @@ export function registerFormatType( name, settings ) { return; } - if ( select( 'core/rich-text' ).getFormatType( settings.name ) ) { + if ( select( richTextStore ).getFormatType( settings.name ) ) { window.console.error( 'Format "' + settings.name + '" is already registered.' ); @@ -76,7 +79,7 @@ export function registerFormatType( name, settings ) { if ( settings.className === null ) { const formatTypeForBareElement = select( - 'core/rich-text' + richTextStore ).getFormatTypeForBareElement( settings.tagName ); if ( formatTypeForBareElement ) { @@ -87,7 +90,7 @@ export function registerFormatType( name, settings ) { } } else { const formatTypeForClassName = select( - 'core/rich-text' + richTextStore ).getFormatTypeForClassName( settings.className ); if ( formatTypeForClassName ) { @@ -119,7 +122,7 @@ export function registerFormatType( name, settings ) { return; } - dispatch( 'core/rich-text' ).addFormatTypes( settings ); + dispatch( richTextStore ).addFormatTypes( settings ); return settings; } diff --git a/packages/rich-text/src/test/register-format-type.js b/packages/rich-text/src/test/register-format-type.js index 9983c48f85f39..0d044d28facfa 100644 --- a/packages/rich-text/src/test/register-format-type.js +++ b/packages/rich-text/src/test/register-format-type.js @@ -9,6 +9,7 @@ import { select } from '@wordpress/data'; import { registerFormatType } from '../register-format-type'; import { unregisterFormatType } from '../unregister-format-type'; import { getFormatType } from '../get-format-type'; +import { store as richTextStore } from '../store'; describe( 'registerFormatType', () => { beforeAll( () => { @@ -17,7 +18,7 @@ describe( 'registerFormatType', () => { } ); afterEach( () => { - select( 'core/rich-text' ) + select( richTextStore ) .getFormatTypes() .forEach( ( { name } ) => { unregisterFormatType( name ); diff --git a/packages/rich-text/src/unregister-format-type.js b/packages/rich-text/src/unregister-format-type.js index 97ee623c9383e..519e33362d5b6 100644 --- a/packages/rich-text/src/unregister-format-type.js +++ b/packages/rich-text/src/unregister-format-type.js @@ -3,6 +3,11 @@ */ import { select, dispatch } from '@wordpress/data'; +/** + * Internal dependencies + */ +import { store as richTextStore } from './store'; + /** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */ /** @@ -15,14 +20,14 @@ import { select, dispatch } from '@wordpress/data'; * otherwise `undefined`. */ export function unregisterFormatType( name ) { - const oldFormat = select( 'core/rich-text' ).getFormatType( name ); + const oldFormat = select( richTextStore ).getFormatType( name ); if ( ! oldFormat ) { window.console.error( `Format ${ name } is not registered.` ); return; } - dispatch( 'core/rich-text' ).removeFormatTypes( name ); + dispatch( richTextStore ).removeFormatTypes( name ); return oldFormat; }