Skip to content

Commit

Permalink
block-editor package: Replace hardcoded store name strings (#28775)
Browse files Browse the repository at this point in the history
* Replace hardcoded strings

* Extract store name to constants file

* Replace store names in actions

* Replace strings

* Fix import

* Fix tests

* Revert native files

* Replace core/block-editor in native files

* Revert native files

* Native files second try
  • Loading branch information
david-szabo97 committed Feb 8, 2021
1 parent e843e54 commit 1fecda1
Show file tree
Hide file tree
Showing 103 changed files with 447 additions and 277 deletions.
3 changes: 2 additions & 1 deletion packages/block-editor/src/autocompleters/block.js
Expand Up @@ -19,6 +19,7 @@ import { useMemo } from '@wordpress/element';
import { searchBlockItems } from '../components/inserter/search-items';
import useBlockTypesState from '../components/inserter/hooks/use-block-types-state';
import BlockIcon from '../components/block-icon';
import { store as blockEditorStore } from '../store';

const SHOWN_BLOCK_TYPES = 9;

Expand All @@ -42,7 +43,7 @@ function createBlockCompleter() {
getSelectedBlockClientId,
getBlockName,
getBlockInsertionPoint,
} = select( 'core/block-editor' );
} = select( blockEditorStore );
const selectedBlockClientId = getSelectedBlockClientId();
return {
selectedBlockName: selectedBlockClientId
Expand Down
5 changes: 3 additions & 2 deletions packages/block-editor/src/components/block-actions/index.js
Expand Up @@ -17,6 +17,7 @@ import {
* Internal dependencies
*/
import { useNotifyCopy } from '../copy-handler';
import { store as blockEditorStore } from '../../store';

export default function BlockActions( {
clientIds,
Expand All @@ -28,7 +29,7 @@ export default function BlockActions( {
getBlockRootClientId,
getBlocksByClientId,
getTemplateLock,
} = useSelect( ( select ) => select( 'core/block-editor' ), [] );
} = useSelect( ( select ) => select( blockEditorStore ), [] );
const { getDefaultBlockName, getGroupingBlockName } = useSelect(
( select ) => select( blocksStore ),
[]
Expand Down Expand Up @@ -59,7 +60,7 @@ export default function BlockActions( {
setBlockMovingClientId,
setNavigationMode,
selectBlock,
} = useDispatch( 'core/block-editor' );
} = useDispatch( blockEditorStore );

const notifyCopy = useNotifyCopy();

Expand Down
Expand Up @@ -16,6 +16,7 @@ import {
* Internal dependencies
*/
import { useLayout } from '../inner-blocks/layout';
import { store as blockEditorStore } from '../../store';

const BLOCK_ALIGNMENTS_CONTROLS = {
left: {
Expand Down Expand Up @@ -55,7 +56,7 @@ export function BlockAlignmentToolbar( {
isCollapsed = true,
} ) {
const { wideControlsEnabled = false } = useSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
const { getSettings } = select( blockEditorStore );
const settings = getSettings();
return {
wideControlsEnabled: settings.alignWide,
Expand Down
Expand Up @@ -9,22 +9,21 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import BlockTitle from '../block-title';
import { store as blockEditorStore } from '../../store';

/**
* Block breadcrumb component, displaying the hierarchy of the current block selection as a breadcrumb.
*
* @return {WPElement} Block Breadcrumb.
*/
function BlockBreadcrumb() {
const { selectBlock, clearSelectedBlock } = useDispatch(
'core/block-editor'
);
const { selectBlock, clearSelectedBlock } = useDispatch( blockEditorStore );
const { clientId, parents, hasSelection } = useSelect( ( select ) => {
const {
getSelectionStart,
getSelectedBlockClientId,
getBlockParents,
} = select( 'core/block-editor' );
} = select( blockEditorStore );
const selectedBlockClientId = getSelectedBlockClientId();
return {
parents: getBlockParents( selectedBlockClientId ),
Expand Down
Expand Up @@ -14,6 +14,7 @@ import { withDispatch, withSelect } from '@wordpress/data';
* Internal dependencies
*/
import styles from './styles.scss';
import { store as blockEditorStore } from '../../store';

const BlockCaption = ( {
accessible,
Expand Down Expand Up @@ -44,7 +45,7 @@ const BlockCaption = ( {
export default compose( [
withSelect( ( select, { clientId } ) => {
const { getBlockAttributes, getSelectedBlockClientId } = select(
'core/block-editor'
blockEditorStore
);
const { caption } = getBlockAttributes( clientId ) || {};
const isBlockSelected = getSelectedBlockClientId() === clientId;
Expand All @@ -60,7 +61,7 @@ export default compose( [
};
} ),
withDispatch( ( dispatch, { clientId } ) => {
const { updateBlockAttributes } = dispatch( 'core/block-editor' );
const { updateBlockAttributes } = dispatch( blockEditorStore );
return {
onChange: ( caption ) => {
updateBlockAttributes( clientId, { caption } );
Expand Down
5 changes: 3 additions & 2 deletions packages/block-editor/src/components/block-draggable/index.js
Expand Up @@ -11,6 +11,7 @@ import { useEffect, useRef } from '@wordpress/element';
*/
import BlockDraggableChip from './draggable-chip';
import useScrollWhenDragging from './use-scroll-when-dragging';
import { store as blockEditorStore } from '../../store';

const BlockDraggable = ( {
children,
Expand All @@ -26,7 +27,7 @@ const BlockDraggable = ( {
getBlockRootClientId,
getTemplateLock,
getBlockName,
} = select( 'core/block-editor' );
} = select( blockEditorStore );
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
const templateLock = rootClientId
? getTemplateLock( rootClientId )
Expand All @@ -49,7 +50,7 @@ const BlockDraggable = ( {
] = useScrollWhenDragging();

const { startDraggingBlocks, stopDraggingBlocks } = useDispatch(
'core/block-editor'
blockEditorStore
);

// Stop dragging blocks if the block draggable is unmounted
Expand Down
Expand Up @@ -26,6 +26,7 @@ import MultiSelectionInspector from '../multi-selection-inspector';
import DefaultStylePicker from '../default-style-picker';
import BlockVariationTransforms from '../block-variation-transforms';
import useBlockDisplayInformation from '../use-block-display-information';
import { store as blockEditorStore } from '../../store';

const BlockInspector = ( {
blockType,
Expand Down Expand Up @@ -137,7 +138,7 @@ export default withSelect( ( select ) => {
getSelectedBlockClientId,
getSelectedBlockCount,
getBlockName,
} = select( 'core/block-editor' );
} = select( blockEditorStore );
const { getBlockStyles } = select( blocksStore );
const selectedBlockClientId = getSelectedBlockClientId();
const selectedBlockName =
Expand Down
Expand Up @@ -16,6 +16,7 @@ import { getDefaultBlockName } from '@wordpress/blocks';
*/
import DefaultBlockAppender from '../default-block-appender';
import ButtonBlockAppender from '../button-block-appender';
import { store as blockEditorStore } from '../../store';

// A Context to store the map of the appender map.
export const AppenderNodesContext = createContext();
Expand Down Expand Up @@ -110,7 +111,7 @@ export default withSelect( ( select, { rootClientId } ) => {
canInsertBlockType,
getTemplateLock,
getSelectedBlockClientId,
} = select( 'core/block-editor' );
} = select( blockEditorStore );

return {
isLocked: !! getTemplateLock( rootClientId ),
Expand Down
Expand Up @@ -14,6 +14,7 @@ import { getDefaultBlockName } from '@wordpress/blocks';
*/
import DefaultBlockAppender from '../default-block-appender';
import styles from './style.scss';
import { store as blockEditorStore } from '../../store';

function BlockListAppender( {
blockClientIds,
Expand Down Expand Up @@ -48,7 +49,7 @@ function BlockListAppender( {

export default withSelect( ( select, { rootClientId } ) => {
const { getBlockOrder, canInsertBlockType, getTemplateLock } = select(
'core/block-editor'
blockEditorStore
);

return {
Expand Down
Expand Up @@ -15,14 +15,15 @@ import { useSelect } from '@wordpress/data';
*/
import NavigableToolbar from '../navigable-toolbar';
import { BlockToolbar } from '../';
import { store as blockEditorStore } from '../../store';

function BlockContextualToolbar( { focusOnMount, ...props } ) {
const { blockType, hasParents } = useSelect( ( select ) => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientIds,
} = select( 'core/block-editor' );
} = select( blockEditorStore );
const { getBlockType } = select( blocksStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand Down
9 changes: 7 additions & 2 deletions packages/block-editor/src/components/block-list/block-html.js
Expand Up @@ -16,13 +16,18 @@ import {
getSaveContent,
} from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';

function BlockHTML( { clientId } ) {
const [ html, setHtml ] = useState( '' );
const block = useSelect(
( select ) => select( 'core/block-editor' ).getBlock( clientId ),
( select ) => select( blockEditorStore ).getBlock( clientId ),
[ clientId ]
);
const { updateBlock } = useDispatch( 'core/block-editor' );
const { updateBlock } = useDispatch( blockEditorStore );
const onChange = () => {
const blockType = getBlockType( block.name );
const attributes = getBlockAttributes(
Expand Down
Expand Up @@ -13,6 +13,7 @@ import { withDispatch, withSelect } from '@wordpress/data';
*/
import Warning from '../warning';
import BlockCompare from '../block-compare';
import { store as blockEditorStore } from '../../store';

export function BlockInvalidWarning( {
convertToHTML,
Expand Down Expand Up @@ -103,10 +104,10 @@ const recoverBlock = ( { name, attributes, innerBlocks } ) =>

export default compose( [
withSelect( ( select, { clientId } ) => ( {
block: select( 'core/block-editor' ).getBlock( clientId ),
block: select( blockEditorStore ).getBlock( clientId ),
} ) ),
withDispatch( ( dispatch, { block } ) => {
const { replaceBlock } = dispatch( 'core/block-editor' );
const { replaceBlock } = dispatch( blockEditorStore );

return {
convertToClassic() {
Expand Down
Expand Up @@ -17,6 +17,7 @@ import { ReadableContentView, alignmentHelpers } from '@wordpress/components';
import BlockListBlock from './block';
import BlockInsertionPoint from './insertion-point';
import styles from './block-list-item.native.scss';
import { store as blockEditorStore } from '../../store';

const stretchStyle = {
flex: 1,
Expand Down Expand Up @@ -174,7 +175,7 @@ export default compose( [
getSettings,
getBlockParents,
__unstableGetBlockWithoutInnerBlocks,
} = select( 'core/block-editor' );
} = select( blockEditorStore );

const blockClientIds = getBlockOrder( rootClientId );
const insertionPoint = getBlockInsertionPoint();
Expand Down
Expand Up @@ -29,6 +29,7 @@ import BlockContextualToolbar from './block-contextual-toolbar';
import Inserter from '../inserter';
import { BlockNodes } from './';
import { getBlockDOMNode } from '../../utils/dom';
import { store as blockEditorStore } from '../../store';

function selector( select ) {
const {
Expand All @@ -39,7 +40,7 @@ function selector( select ) {
isCaretWithinFormattedText,
getSettings,
getLastMultiSelectedBlockClientId,
} = select( 'core/block-editor' );
} = select( blockEditorStore );
return {
isNavigationMode: isNavigationMode(),
isMultiSelecting: isMultiSelecting(),
Expand Down Expand Up @@ -71,7 +72,7 @@ function BlockPopover( {
const [ isToolbarForced, setIsToolbarForced ] = useState( false );
const [ isInserterShown, setIsInserterShown ] = useState( false );
const blockNodes = useContext( BlockNodes );
const { stopTyping } = useDispatch( 'core/block-editor' );
const { stopTyping } = useDispatch( blockEditorStore );

// Controls when the side inserter on empty lines should
// be shown, including writing and selection modes.
Expand Down Expand Up @@ -265,7 +266,7 @@ function wrapperSelector( select ) {
__unstableGetBlockWithoutInnerBlocks,
getBlockParents,
__experimentalGetBlockListSettingsForBlocks,
} = select( 'core/block-editor' );
} = select( blockEditorStore );

const clientId =
getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId();
Expand Down
Expand Up @@ -32,6 +32,7 @@ import { focus } from '@wordpress/dom';
* Internal dependencies
*/
import BlockTitle from '../block-title';
import { store as blockEditorStore } from '../../store';

/**
* Returns true if the user is using windows.
Expand All @@ -54,7 +55,7 @@ function selector( select ) {
getClientIdsOfDescendants,
canInsertBlockType,
getBlockName,
} = select( 'core/block-editor' );
} = select( blockEditorStore );

const selectedBlockClientId = getSelectedBlockClientId();
const selectionEndClientId = getMultiSelectedBlocksEndClientId();
Expand Down Expand Up @@ -94,7 +95,7 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
getBlockIndex,
hasBlockMovingClientId,
getBlockListSettings,
} = select( 'core/block-editor' );
} = select( blockEditorStore );
const index = getBlockIndex( clientId, rootClientId );
const { name, attributes } = __unstableGetBlockWithoutInnerBlocks(
clientId
Expand All @@ -111,9 +112,7 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
[ clientId, rootClientId ]
);
const { index, name, attributes, blockMovingMode, orientation } = selected;
const { setNavigationMode, removeBlock } = useDispatch(
'core/block-editor'
);
const { setNavigationMode, removeBlock } = useDispatch( blockEditorStore );
const ref = useRef();

// Focus the breadcrumb in navigation mode.
Expand Down Expand Up @@ -142,7 +141,7 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
clearSelectedBlock,
setBlockMovingClientId,
moveBlockToPosition,
} = useDispatch( 'core/block-editor' );
} = useDispatch( blockEditorStore );

function onKeyDown( event ) {
const { keyCode } = event;
Expand Down
Expand Up @@ -16,7 +16,7 @@ import { View, Text, TouchableOpacity } from 'react-native';
*/
import BlockTitle from '../block-title';
import SubdirectorSVG from './subdirectory-icon';

import { store as blockEditorStore } from '../../store';
import styles from './block-selection-button.scss';

const BlockSelectionButton = ( {
Expand Down Expand Up @@ -78,7 +78,7 @@ const BlockSelectionButton = ( {
export default compose( [
withSelect( ( select, { clientId } ) => {
const { getBlockRootClientId, getBlockName, getSettings } = select(
'core/block-editor'
blockEditorStore
);

const blockName = getBlockName( clientId );
Expand Down

0 comments on commit 1fecda1

Please sign in to comment.