Move unlocking core store and block editor store to private apis

[MAILPOET-6319]
This commit is contained in:
Rostislav Wolny
2024-11-22 13:48:11 +01:00
committed by Oluwaseun Olorunsola
parent d8a3289414
commit ceecfe69a5
3 changed files with 50 additions and 7 deletions

View File

@@ -11,12 +11,16 @@ import {
import { useMemo } from '@wordpress/element';
import { SlotFillProvider, Spinner } from '@wordpress/components';
import { Post, store as coreStore } from '@wordpress/core-data';
import { storeName } from '../../store';
import { unlock } from '../../lock-unlock';
/**
* WordPress private dependencies
*/
import { unlockPatternsRelatedSelectorsFromCoreStore } from '../../private-apis';
/**
* Internal dependencies
*/
import { storeName } from '../../store';
import { Layout } from './layout';
import { useNavigateToEntityRecord } from '../../hooks/use-navigate-to-entity-record';
@@ -69,7 +73,7 @@ export function InnerEditor( {
const blockPatterns = useSelect(
( select ) => {
const { hasFinishedResolution, getBlockPatternsForPostType } =
unlock( select( coreStore ) );
unlockPatternsRelatedSelectorsFromCoreStore( select );
const patterns = getBlockPatternsForPostType(
currentPost.postType
) as Post[];

View File

@@ -8,7 +8,7 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { unlock } from '../../../lock-unlock';
import { unlockGetEnabledClientIdsTree } from '../../../private-apis';
const DISTANCE_THRESHOLD = 500;
@@ -25,9 +25,11 @@ function distanceFromRect( x: number, y: number, rect ) {
export default function useSelectNearestEditableBlock( {
isEnabled = true,
} = {} ) {
const { getEnabledClientIdsTree, getBlockName, getBlockOrder } = unlock(
const getEnabledClientIdsTree = unlockGetEnabledClientIdsTree(
useSelect( blockEditorStore )
);
const { getBlockName, getBlockOrder } = useSelect( blockEditorStore );
const { selectBlock } = useDispatch( blockEditorStore );
return useRefEffect(
@@ -39,11 +41,13 @@ export default function useSelectNearestEditableBlock( {
const selectNearestEditableBlock = ( x, y ) => {
const editableBlockClientIds =
getEnabledClientIdsTree().flatMap( ( { clientId } ) => {
// @ts-expect-error getBlockName is not typed
const blockName = getBlockName( clientId );
if ( blockName === 'core/template-part' ) {
return [];
}
if ( blockName === 'core/post-content' ) {
// @ts-expect-error getBlockOrder is not typed
const innerBlocks = getBlockOrder( clientId );
if ( innerBlocks.length ) {
return innerBlocks as string[];