@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
59 lines (58 loc) • 2.03 kB
JavaScript
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { store as interfaceStore } from '@wordpress/interface';
import { applyFilters } from '@wordpress/hooks';
import { useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { TEMPLATE_POST_TYPE } from '../../store/constants';
import { store as editorStore } from '../../store';
import { jsx as _jsx } from "react/jsx-runtime";
const {
BlockQuickNavigation
} = unlock(blockEditorPrivateApis);
const POST_CONTENT_BLOCK_TYPES = ['core/post-title', 'core/post-featured-image', 'core/post-content'];
const TEMPLATE_PART_BLOCK = 'core/template-part';
export default function TemplateContentPanel() {
const postContentBlockTypes = useMemo(() => applyFilters('editor.postContentBlockTypes', POST_CONTENT_BLOCK_TYPES), []);
const {
clientIds,
postType,
renderingMode
} = useSelect(select => {
const {
getCurrentPostType,
getPostBlocksByName,
getRenderingMode
} = unlock(select(editorStore));
const _postType = getCurrentPostType();
return {
postType: _postType,
clientIds: getPostBlocksByName(TEMPLATE_POST_TYPE === _postType ? TEMPLATE_PART_BLOCK : postContentBlockTypes),
renderingMode: getRenderingMode()
};
}, [postContentBlockTypes]);
const {
enableComplementaryArea
} = useDispatch(interfaceStore);
if (renderingMode === 'post-only' && postType !== TEMPLATE_POST_TYPE || clientIds.length === 0) {
return null;
}
return /*#__PURE__*/_jsx(PanelBody, {
title: __('Content'),
children: /*#__PURE__*/_jsx(BlockQuickNavigation, {
clientIds: clientIds,
onSelect: () => {
enableComplementaryArea('core', 'edit-post/document');
}
})
});
}
//# sourceMappingURL=index.js.map