Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the DisableNonContentBlocks component to the editor package #56423

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
NAVIGATION_POST_TYPE,
} from '../../utils/constants';
import { unlock } from '../../lock-unlock';
import PageContentFocusManager from '../page-content-focus-manager';
import PageContentFocusNotifications from '../page-content-focus-notifications';

const LAYOUT = {
type: 'default',
Expand Down Expand Up @@ -149,7 +149,7 @@ export default function SiteEditorCanvas() {
)
}
</EditorCanvasContainer.Slot>
<PageContentFocusManager contentRef={ contentRef } />
<PageContentFocusNotifications contentRef={ contentRef } />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@ import { useEffect } from '@wordpress/element';
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';
import DisableNonPageContentBlocks from './disable-non-page-content-blocks';
import EditTemplateNotification from './edit-template-notification';
import BackToPageNotification from './back-to-page-notification';
import { unlock } from '../../lock-unlock';

export default function PageContentFocusManager( { contentRef } ) {
const { hasPageContentFocus, pageContentFocusType, canvasMode } = useSelect(
( select ) => {
const { getPageContentFocusType, getCanvasMode } = unlock(
select( editSiteStore )
);
const _canvasMode = getCanvasMode();
return {
canvasMode: _canvasMode,
pageContentFocusType: getPageContentFocusType(),
hasPageContentFocus:
select( editSiteStore ).hasPageContentFocus(),
};
},
[]
);
export default function PageContentFocusNotifications( { contentRef } ) {
const { pageContentFocusType, canvasMode } = useSelect( ( select ) => {
const { getPageContentFocusType, getCanvasMode } = unlock(
select( editSiteStore )
);
const _canvasMode = getCanvasMode();
return {
canvasMode: _canvasMode,
pageContentFocusType: getPageContentFocusType(),
};
}, [] );
const { setPageContentFocusType } = unlock( useDispatch( editSiteStore ) );

/*
Expand All @@ -39,11 +33,10 @@ export default function PageContentFocusManager( { contentRef } ) {
if ( canvasMode !== 'edit' && !! pageContentFocusType ) {
setPageContentFocusType( null );
}
}, [ canvasMode, pageContentFocusType ] );
}, [ canvasMode, pageContentFocusType, setPageContentFocusType ] );

return (
<>
{ hasPageContentFocus && <DisableNonPageContentBlocks /> }
<EditTemplateNotification contentRef={ contentRef } />
<BackToPageNotification />
</>
Expand Down
5 changes: 5 additions & 0 deletions packages/editor/src/components/provider/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const PAGE_CONTENT_BLOCK_TYPES = [
'core/post-title',
'core/post-featured-image',
'core/post-content',
];
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import { PAGE_CONTENT_BLOCK_TYPES } from '../../utils/constants';
import { PAGE_CONTENT_BLOCK_TYPES } from './constants';

function DisableBlock( { clientId } ) {
const isDescendentOfQueryLoop = useSelect(
Expand Down Expand Up @@ -46,9 +46,7 @@ export default function DisableNonPageContentBlocks() {
const clientIds = useSelect( ( select ) => {
const { __experimentalGetGlobalBlocksByName } =
select( blockEditorStore );
return __experimentalGetGlobalBlocksByName(
Object.keys( PAGE_CONTENT_BLOCK_TYPES )
);
return __experimentalGetGlobalBlocksByName( PAGE_CONTENT_BLOCK_TYPES );
}, [] );

return clientIds.map( ( clientId ) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ import withRegistryProvider from './with-registry-provider';
import { store as editorStore } from '../../store';
import useBlockEditorSettings from './use-block-editor-settings';
import { unlock } from '../../lock-unlock';
import DisableNonPageContentBlocks from './disable-non-page-content-blocks';
import { PAGE_CONTENT_BLOCK_TYPES } from './constants';

const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );
const { PatternsMenuItems } = unlock( editPatternsPrivateApis );

const noop = () => {};
export const PAGE_CONTENT_BLOCK_TYPES = [
'core/post-title',
'core/post-featured-image',
'core/post-content',
];

/**
* For the Navigation block editor, we need to force the block editor to contentOnly for that block.
Expand Down Expand Up @@ -308,6 +305,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
>
{ children }
<PatternsMenuItems />
{ [ 'post-only', 'template-locked' ].includes(
mode
) && <DisableNonPageContentBlocks /> }
</BlockEditorProviderComponent>
</BlockContextProvider>
</EntityProvider>
Expand Down
Loading