From bb109b8b5605b5f33502984c9e7547f7d04c5db6 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 18 May 2021 13:24:32 +0300 Subject: [PATCH 1/2] Replace string literals with store definitions in block-library --- packages/block-library/src/button/edit.native.js | 5 +++-- packages/block-library/src/categories/edit.js | 4 ++-- packages/block-library/src/columns/edit.native.js | 3 ++- packages/block-library/src/embed/edit.js | 4 ++-- packages/block-library/src/file/edit.native.js | 5 +++-- packages/block-library/src/image/edit.native.js | 3 ++- packages/block-library/src/latest-posts/edit.native.js | 3 ++- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/block-library/src/button/edit.native.js b/packages/block-library/src/button/edit.native.js index 7818d3e37d197a..c797f6565c4882 100644 --- a/packages/block-library/src/button/edit.native.js +++ b/packages/block-library/src/button/edit.native.js @@ -28,6 +28,7 @@ import { import { Component } from '@wordpress/element'; import { withSelect, withDispatch } from '@wordpress/data'; import { link } from '@wordpress/icons'; +import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies @@ -521,7 +522,7 @@ export default compose( [ withInstanceId, withGradient, withSelect( ( select, { clientId, isSelected } ) => { - const { isEditorSidebarOpened } = select( 'core/edit-post' ); + const { isEditorSidebarOpened } = select( editPostStore ); const { getBlockCount, getBlockRootClientId, getSettings } = select( blockEditorStore ); @@ -539,7 +540,7 @@ export default compose( [ withDispatch( ( dispatch ) => { return { closeSettingsBottomSheet() { - dispatch( 'core/edit-post' ).closeGeneralSidebar(); + dispatch( editPostStore ).closeGeneralSidebar(); }, }; } ), diff --git a/packages/block-library/src/categories/edit.js b/packages/block-library/src/categories/edit.js index 12adf03e1ffcee..efb499ddef1a2e 100644 --- a/packages/block-library/src/categories/edit.js +++ b/packages/block-library/src/categories/edit.js @@ -14,7 +14,7 @@ import { VisuallyHidden, } from '@wordpress/components'; import { useInstanceId } from '@wordpress/compose'; -import { useSelect } from '@wordpress/data'; +import { useSelect, store as dataStore } from '@wordpress/data'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import { pin } from '@wordpress/icons'; @@ -27,7 +27,7 @@ export default function CategoriesEdit( { const selectId = useInstanceId( CategoriesEdit, 'blocks-category-select' ); const { categories, isRequesting } = useSelect( ( select ) => { const { getEntityRecords } = select( coreStore ); - const { isResolving } = select( 'core/data' ); + const { isResolving } = select( dataStore ); const query = { per_page: -1, hide_empty: true }; return { categories: getEntityRecords( 'taxonomy', 'category', query ), diff --git a/packages/block-library/src/columns/edit.native.js b/packages/block-library/src/columns/edit.native.js index 241e5fe247e358..fbc1a26c957ea7 100644 --- a/packages/block-library/src/columns/edit.native.js +++ b/packages/block-library/src/columns/edit.native.js @@ -36,6 +36,7 @@ import { import { useResizeObserver } from '@wordpress/compose'; import { createBlock } from '@wordpress/blocks'; import { columns } from '@wordpress/icons'; +import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies */ @@ -454,7 +455,7 @@ const ColumnsEdit = ( props ) => { getBlockParents, getBlockAttributes, } = select( blockEditorStore ); - const { isEditorSidebarOpened } = select( 'core/edit-post' ); + const { isEditorSidebarOpened } = select( editPostStore ); const innerBlocks = getBlocks( clientId ); const isContentEmpty = map( diff --git a/packages/block-library/src/embed/edit.js b/packages/block-library/src/embed/edit.js index a02371c0d4c637..0bcabc5cf57c25 100644 --- a/packages/block-library/src/embed/edit.js +++ b/packages/block-library/src/embed/edit.js @@ -24,7 +24,7 @@ import classnames from 'classnames'; */ import { __, _x, sprintf } from '@wordpress/i18n'; import { useState, useEffect, Platform } from '@wordpress/element'; -import { useDispatch, useSelect } from '@wordpress/data'; +import { useDispatch, useSelect, store as dataStore } from '@wordpress/data'; import { useBlockProps } from '@wordpress/block-editor'; import { store as coreStore } from '@wordpress/core-data'; import { View } from '@wordpress/primitives'; @@ -64,7 +64,7 @@ const EmbedEdit = ( props ) => { const [ url, setURL ] = useState( attributesUrl ); const [ isEditingURL, setIsEditingURL ] = useState( false ); - const { invalidateResolution } = useDispatch( 'core/data' ); + const { invalidateResolution } = useDispatch( dataStore ); const { preview, diff --git a/packages/block-library/src/file/edit.native.js b/packages/block-library/src/file/edit.native.js index 07d2ecf57a2be7..c8e39b2051df36 100644 --- a/packages/block-library/src/file/edit.native.js +++ b/packages/block-library/src/file/edit.native.js @@ -46,6 +46,7 @@ import { compose, withPreferredColorScheme } from '@wordpress/compose'; import { withDispatch, withSelect } from '@wordpress/data'; import { getProtocol } from '@wordpress/url'; import { store as coreStore } from '@wordpress/core-data'; +import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies @@ -589,7 +590,7 @@ export default compose( [ withSelect( ( select, props ) => { const { attributes, isSelected, clientId } = props; const { id, href } = attributes; - const { isEditorSidebarOpened } = select( 'core/edit-post' ); + const { isEditorSidebarOpened } = select( editPostStore ); const isNotFileHref = id && getProtocol( href ) !== 'file:'; return { media: isNotFileHref @@ -602,7 +603,7 @@ export default compose( [ }; } ), withDispatch( ( dispatch ) => { - const { openGeneralSidebar } = dispatch( 'core/edit-post' ); + const { openGeneralSidebar } = dispatch( editPostStore ); return { openSidebar: () => openGeneralSidebar( 'edit-post/block' ), }; diff --git a/packages/block-library/src/image/edit.native.js b/packages/block-library/src/image/edit.native.js index 78de0798441183..aaba0e8ebd8b2f 100644 --- a/packages/block-library/src/image/edit.native.js +++ b/packages/block-library/src/image/edit.native.js @@ -52,6 +52,7 @@ import { textColor, } from '@wordpress/icons'; import { store as coreStore } from '@wordpress/core-data'; +import { store as editorStore } from '@wordpress/editor'; /** * Internal dependencies @@ -603,7 +604,7 @@ export default compose( [ const { getSettings, wasBlockJustInserted } = select( blockEditorStore ); - const { getEditedPostAttribute } = select( 'core/editor' ); + const { getEditedPostAttribute } = select( editorStore ); const { attributes: { id, url }, isSelected, diff --git a/packages/block-library/src/latest-posts/edit.native.js b/packages/block-library/src/latest-posts/edit.native.js index 0aefc6b889cb91..068debe28cefd1 100644 --- a/packages/block-library/src/latest-posts/edit.native.js +++ b/packages/block-library/src/latest-posts/edit.native.js @@ -22,6 +22,7 @@ import { RangeControl, QueryControls, } from '@wordpress/components'; +import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies @@ -235,7 +236,7 @@ class LatestPostsEdit extends Component { export default compose( [ withDispatch( ( dispatch ) => { - const { openGeneralSidebar } = dispatch( 'core/edit-post' ); + const { openGeneralSidebar } = dispatch( editPostStore ); return { openGeneralSidebar: () => openGeneralSidebar( 'edit-post/block' ), From 2520d35ae013c0962040c84f87e7767bb4fcfdcb Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 18 May 2021 16:45:03 +0300 Subject: [PATCH 2/2] revert changes to native files --- packages/block-library/src/button/edit.native.js | 5 ++--- packages/block-library/src/columns/edit.native.js | 3 +-- packages/block-library/src/file/edit.native.js | 5 ++--- packages/block-library/src/image/edit.native.js | 3 +-- packages/block-library/src/latest-posts/edit.native.js | 3 +-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/block-library/src/button/edit.native.js b/packages/block-library/src/button/edit.native.js index c797f6565c4882..7818d3e37d197a 100644 --- a/packages/block-library/src/button/edit.native.js +++ b/packages/block-library/src/button/edit.native.js @@ -28,7 +28,6 @@ import { import { Component } from '@wordpress/element'; import { withSelect, withDispatch } from '@wordpress/data'; import { link } from '@wordpress/icons'; -import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies @@ -522,7 +521,7 @@ export default compose( [ withInstanceId, withGradient, withSelect( ( select, { clientId, isSelected } ) => { - const { isEditorSidebarOpened } = select( editPostStore ); + const { isEditorSidebarOpened } = select( 'core/edit-post' ); const { getBlockCount, getBlockRootClientId, getSettings } = select( blockEditorStore ); @@ -540,7 +539,7 @@ export default compose( [ withDispatch( ( dispatch ) => { return { closeSettingsBottomSheet() { - dispatch( editPostStore ).closeGeneralSidebar(); + dispatch( 'core/edit-post' ).closeGeneralSidebar(); }, }; } ), diff --git a/packages/block-library/src/columns/edit.native.js b/packages/block-library/src/columns/edit.native.js index fbc1a26c957ea7..241e5fe247e358 100644 --- a/packages/block-library/src/columns/edit.native.js +++ b/packages/block-library/src/columns/edit.native.js @@ -36,7 +36,6 @@ import { import { useResizeObserver } from '@wordpress/compose'; import { createBlock } from '@wordpress/blocks'; import { columns } from '@wordpress/icons'; -import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies */ @@ -455,7 +454,7 @@ const ColumnsEdit = ( props ) => { getBlockParents, getBlockAttributes, } = select( blockEditorStore ); - const { isEditorSidebarOpened } = select( editPostStore ); + const { isEditorSidebarOpened } = select( 'core/edit-post' ); const innerBlocks = getBlocks( clientId ); const isContentEmpty = map( diff --git a/packages/block-library/src/file/edit.native.js b/packages/block-library/src/file/edit.native.js index c8e39b2051df36..07d2ecf57a2be7 100644 --- a/packages/block-library/src/file/edit.native.js +++ b/packages/block-library/src/file/edit.native.js @@ -46,7 +46,6 @@ import { compose, withPreferredColorScheme } from '@wordpress/compose'; import { withDispatch, withSelect } from '@wordpress/data'; import { getProtocol } from '@wordpress/url'; import { store as coreStore } from '@wordpress/core-data'; -import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies @@ -590,7 +589,7 @@ export default compose( [ withSelect( ( select, props ) => { const { attributes, isSelected, clientId } = props; const { id, href } = attributes; - const { isEditorSidebarOpened } = select( editPostStore ); + const { isEditorSidebarOpened } = select( 'core/edit-post' ); const isNotFileHref = id && getProtocol( href ) !== 'file:'; return { media: isNotFileHref @@ -603,7 +602,7 @@ export default compose( [ }; } ), withDispatch( ( dispatch ) => { - const { openGeneralSidebar } = dispatch( editPostStore ); + const { openGeneralSidebar } = dispatch( 'core/edit-post' ); return { openSidebar: () => openGeneralSidebar( 'edit-post/block' ), }; diff --git a/packages/block-library/src/image/edit.native.js b/packages/block-library/src/image/edit.native.js index aaba0e8ebd8b2f..78de0798441183 100644 --- a/packages/block-library/src/image/edit.native.js +++ b/packages/block-library/src/image/edit.native.js @@ -52,7 +52,6 @@ import { textColor, } from '@wordpress/icons'; import { store as coreStore } from '@wordpress/core-data'; -import { store as editorStore } from '@wordpress/editor'; /** * Internal dependencies @@ -604,7 +603,7 @@ export default compose( [ const { getSettings, wasBlockJustInserted } = select( blockEditorStore ); - const { getEditedPostAttribute } = select( editorStore ); + const { getEditedPostAttribute } = select( 'core/editor' ); const { attributes: { id, url }, isSelected, diff --git a/packages/block-library/src/latest-posts/edit.native.js b/packages/block-library/src/latest-posts/edit.native.js index 068debe28cefd1..0aefc6b889cb91 100644 --- a/packages/block-library/src/latest-posts/edit.native.js +++ b/packages/block-library/src/latest-posts/edit.native.js @@ -22,7 +22,6 @@ import { RangeControl, QueryControls, } from '@wordpress/components'; -import { store as editPostStore } from '@wordpress/edit-post'; /** * Internal dependencies @@ -236,7 +235,7 @@ class LatestPostsEdit extends Component { export default compose( [ withDispatch( ( dispatch ) => { - const { openGeneralSidebar } = dispatch( editPostStore ); + const { openGeneralSidebar } = dispatch( 'core/edit-post' ); return { openGeneralSidebar: () => openGeneralSidebar( 'edit-post/block' ),