Skip to content

Commit

Permalink
Blocks: Replace store name string with exposed store definition (#27336)
Browse files Browse the repository at this point in the history
* Removing internal references to the store name

* Removing block-library package references to the store name

* Removing edit-post package references to the store name

* Removing edit-site package references to the store name

* Removing editor package references to the store name

* Removing block-editor package references to the store name

* Try: Triggering checks/E2E tests
  • Loading branch information
rafaelgallani authored Nov 30, 2020
1 parent 31184e8 commit 2239c5d
Show file tree
Hide file tree
Showing 33 changed files with 138 additions and 79 deletions.
8 changes: 6 additions & 2 deletions packages/block-editor/src/components/block-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { castArray, first, last, every } from 'lodash';
* WordPress dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { hasBlockSupport, switchToBlockType } from '@wordpress/blocks';
import {
hasBlockSupport,
switchToBlockType,
store as blocksStore,
} from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -26,7 +30,7 @@ export default function BlockActions( {
getTemplateLock,
} = useSelect( ( select ) => select( 'core/block-editor' ), [] );
const { getDefaultBlockName, getGroupingBlockName } = useSelect(
( select ) => select( 'core/blocks' ),
( select ) => select( blocksStore ),
[]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getBlockType,
getUnregisteredTypeHandlerName,
hasBlockSupport,
store as blocksStore,
} from '@wordpress/blocks';
import {
PanelBody,
Expand Down Expand Up @@ -121,7 +122,7 @@ export default withSelect( ( select ) => {
getSelectedBlockCount,
getBlockName,
} = select( 'core/block-editor' );
const { getBlockStyles } = select( 'core/blocks' );
const { getBlockStyles } = select( blocksStore );
const selectedBlockClientId = getSelectedBlockClientId();
const selectedBlockName =
selectedBlockClientId && getBlockName( selectedBlockClientId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { hasBlockSupport } from '@wordpress/blocks';
import { hasBlockSupport, store as blocksStore } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';

/**
Expand All @@ -16,7 +16,7 @@ function BlockContextualToolbar( { focusOnMount, ...props } ) {
const { getBlockName, getSelectedBlockClientIds } = select(
'core/block-editor'
);
const { getBlockType } = select( 'core/blocks' );
const { getBlockType } = select( blocksStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { getBlockType } from '@wordpress/blocks';
import { getBlockType, store as blocksStore } from '@wordpress/blocks';
import { ToolbarButton } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
Expand All @@ -26,7 +26,7 @@ export default function BlockParentSelector() {
getBlockParents,
getSelectedBlockClientId,
} = select( 'core/block-editor' );
const { hasBlockSupport } = select( 'core/blocks' );
const { hasBlockSupport } = select( blocksStore );
const selectedBlockClientId = getSelectedBlockClientId();
const parents = getBlockParents( selectedBlockClientId );
const _firstParentClientId = parents[ parents.length - 1 ];
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/block-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getBlockType,
cloneBlock,
getBlockFromExample,
store as blocksStore,
} from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -43,7 +44,7 @@ function BlockStyles( {
} ) {
const selector = ( select ) => {
const { getBlock } = select( 'core/block-editor' );
const { getBlockStyles } = select( 'core/blocks' );
const { getBlockStyles } = select( blocksStore );
const block = getBlock( clientId );
const blockType = getBlockType( block.name );
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { find } from 'lodash';
/**
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
import { _x } from '@wordpress/i18n';

Expand All @@ -20,7 +21,7 @@ import containerStyles from './style.scss';
function BlockStyles( { clientId, url } ) {
const selector = ( select ) => {
const { getBlock } = select( 'core/block-editor' );
const { getBlockStyles } = select( 'core/blocks' );
const { getBlockStyles } = select( blocksStore );
const block = getBlock( clientId );
return {
styles: getBlockStyles( block.name ),
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
switchToBlockType,
cloneBlock,
getBlockFromExample,
store as blocksStore,
} from '@wordpress/blocks';
import { Component } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -238,7 +239,7 @@ export default compose(
getBlockRootClientId,
getInserterItems,
} = select( 'core/block-editor' );
const { getBlockStyles } = select( 'core/blocks' );
const { getBlockStyles } = select( blocksStore );
const rootClientId = getBlockRootClientId(
castArray( clientIds )[ 0 ]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
*/
import { withSelect, useDispatch } from '@wordpress/data';
import { compose, usePreferredColorSchemeStyle } from '@wordpress/compose';
import { createBlocksFromInnerBlocksTemplate } from '@wordpress/blocks';
import {
createBlocksFromInnerBlocksTemplate,
store as blocksStore,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import {
PanelBody,
Expand Down Expand Up @@ -110,7 +113,7 @@ function BlockVariationPicker( { isVisible, onClose, clientId, variations } ) {

export default compose(
withSelect( ( select, {} ) => {
const { getBlockVariations } = select( 'core/blocks' );
const { getBlockVariations } = select( blocksStore );

return {
date: getBlockVariations( 'core/columns', 'block' ),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import {
DropdownMenu,
Expand All @@ -21,7 +22,7 @@ function __experimentalBlockVariationTransforms( { blockClientId } ) {
const { updateBlockAttributes } = useDispatch( 'core/block-editor' );
const { variations, blockAttributes } = useSelect(
( select ) => {
const { getBlockVariations } = select( 'core/blocks' );
const { getBlockVariations } = select( blocksStore );
const { getBlockName, getBlockAttributes } = select(
'core/block-editor'
);
Expand Down
8 changes: 6 additions & 2 deletions packages/block-editor/src/components/copy-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* WordPress dependencies
*/
import { useCallback, useEffect, useRef } from '@wordpress/element';
import { serialize, pasteHandler } from '@wordpress/blocks';
import {
serialize,
pasteHandler,
store as blocksStore,
} from '@wordpress/blocks';
import {
documentHasSelection,
documentHasUncollapsedSelection,
Expand All @@ -21,7 +25,7 @@ export function useNotifyCopy() {
[]
);
const { getBlockType } = useSelect(
( select ) => select( 'core/blocks' ),
( select ) => select( blocksStore ),
[]
);
const { createSuccessNotice } = useDispatch( 'core/notices' );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { useMemo, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { SelectControl } from '@wordpress/components';
Expand All @@ -20,7 +21,7 @@ export default function DefaultStylePicker( { blockName } ) {
preferredStyle: preferredStyleVariations?.value?.[ blockName ],
onUpdatePreferredStyleVariations:
preferredStyleVariations?.onChange ?? null,
styles: select( 'core/blocks' ).getBlockStyles( blockName ),
styles: select( blocksStore ).getBlockStyles( blockName ),
};
},
[ blockName ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { map, findIndex, flow, sortBy, groupBy, orderBy } from 'lodash';
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { store as blocksStore } from '@wordpress/blocks';
import { useMemo, useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

Expand Down Expand Up @@ -36,7 +37,7 @@ export function BlockTypesTab( {
const hasChildItems = useSelect(
( select ) => {
const { getBlockName } = select( 'core/block-editor' );
const { getChildBlockNames } = select( 'core/blocks' );
const { getChildBlockNames } = select( blocksStore );
const rootBlockName = getBlockName( rootClientId );

return !! getChildBlockNames( rootBlockName ).length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';

/**
Expand All @@ -10,7 +11,7 @@ import BlockIcon from '../block-icon';

export default function ChildBlocks( { rootClientId, children } ) {
const { rootBlockTitle, rootBlockIcon } = useSelect( ( select ) => {
const { getBlockType } = select( 'core/blocks' );
const { getBlockType } = select( blocksStore );
const { getBlockName } = select( 'core/block-editor' );
const rootBlockName = getBlockName( rootClientId );
const rootBlockType = getBlockType( rootBlockName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
createBlock,
createBlocksFromInnerBlocksTemplate,
store as blocksStore,
} from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';

Expand All @@ -18,7 +19,7 @@ const useBlockTypesState = ( rootClientId, onInsert ) => {
const { categories, collections, items } = useSelect(
( select ) => {
const { getInserterItems } = select( 'core/block-editor' );
const { getCategories, getCollections } = select( 'core/blocks' );
const { getCategories, getCollections } = select( blocksStore );

return {
categories: getCategories(),
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Dropdown, Button } from '@wordpress/components';
import { Component } from '@wordpress/element';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose, ifCondition } from '@wordpress/compose';
import { createBlock } from '@wordpress/blocks';
import { createBlock, store as blocksStore } from '@wordpress/blocks';
import { plus } from '@wordpress/icons';

/**
Expand Down Expand Up @@ -199,7 +199,7 @@ export default compose( [
hasInserterItems,
__experimentalGetAllowedBlocks,
} = select( 'core/block-editor' );
const { getBlockVariations } = select( 'core/blocks' );
const { getBlockVariations } = select( blocksStore );

rootClientId =
rootClientId || getBlockRootClientId( clientId ) || undefined;
Expand Down
8 changes: 6 additions & 2 deletions packages/block-editor/src/components/inserter/menu.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { pick } from 'lodash';
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { createBlock, rawHandler } from '@wordpress/blocks';
import {
createBlock,
rawHandler,
store as blocksStore,
} from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import { withInstanceId, compose } from '@wordpress/compose';
import {
Expand Down Expand Up @@ -181,7 +185,7 @@ export default compose(
getSettings,
canInsertBlockType,
} = select( 'core/block-editor' );
const { getChildBlockNames, getBlockType } = select( 'core/blocks' );
const { getChildBlockNames, getBlockType } = select( blocksStore );
const { getClipboard } = select( 'core/editor' );

let destinationRootClientId = rootClientId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { noop } from 'lodash';
/**
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { Toolbar, ToolbarButton } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { withSelect, withDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -37,7 +38,7 @@ export default compose( [
'core/block-editor'
);

const { getGroupingBlockName } = select( 'core/blocks' );
const { getGroupingBlockName } = select( blocksStore );

const selectedId = getSelectedBlockClientId();
const selectedBlock = getBlock( selectedId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { get, isObject } from 'lodash';
/**
* WordPress dependencies
*/
import { store as blocksStore } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';

/**
Expand Down Expand Up @@ -78,7 +79,7 @@ export default function useEditorFeature( featurePath ) {
'core/block-editor'
);
const settings = getSettings();
const blockType = select( 'core/blocks' ).getBlockType( blockName );
const blockType = select( blocksStore ).getBlockType( blockName );

let context = blockName;
const selectors = get( blockType, [
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { withDispatch, useDispatch, useSelect } from '@wordpress/data';
import {
createBlock,
createBlocksFromInnerBlocksTemplate,
store as blocksStore,
} from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -209,7 +210,7 @@ function Placeholder( { clientId, name, setAttributes } ) {
getBlockVariations,
getBlockType,
getDefaultBlockVariation,
} = select( 'core/blocks' );
} = select( blocksStore );

return {
blockType: getBlockType( name ),
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/post-hierarchical-terms/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useBlockProps,
__experimentalBlockVariationPicker as BlockVariationPicker,
} from '@wordpress/block-editor';
import { store as blocksStore } from '@wordpress/blocks';
import { Spinner } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
Expand All @@ -39,7 +40,7 @@ export default function PostHierarchicalTermsEdit( {
getBlockVariations,
getBlockType,
getDefaultBlockVariation,
} = select( 'core/blocks' );
} = select( blocksStore );

return {
blockType: getBlockType( name ),
Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/query/edit/query-placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
__experimentalBlockVariationPicker,
__experimentalGetMatchingVariation as getMatchingVariation,
} from '@wordpress/block-editor';
import { createBlocksFromInnerBlocksTemplate } from '@wordpress/blocks';
import {
createBlocksFromInnerBlocksTemplate,
store as blocksStore,
} from '@wordpress/blocks';

const QueryPlaceholder = ( { clientId, name, attributes, setAttributes } ) => {
const {
Expand All @@ -21,7 +24,7 @@ const QueryPlaceholder = ( { clientId, name, attributes, setAttributes } ) => {
getBlockVariations,
getBlockType,
getDefaultBlockVariation,
} = select( 'core/blocks' );
} = select( blocksStore );

return {
blockType: getBlockType( name ),
Expand Down
Loading

0 comments on commit 2239c5d

Please sign in to comment.