UNPKG

@wordpress/editor

Version:
58 lines (57 loc) 2.1 kB
// packages/editor/src/components/template-content-panel/index.js 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 { unlock } from "../../lock-unlock.mjs"; import { TEMPLATE_POST_TYPE } from "../../store/constants.mjs"; import { store as editorStore } from "../../store/index.mjs"; import usePostContentBlockTypes from "../provider/use-post-content-block-types.mjs"; import { jsx } from "react/jsx-runtime"; var { BlockQuickNavigation } = unlock(blockEditorPrivateApis); var TEMPLATE_PART_BLOCK = "core/template-part"; function TemplateContentPanelInner({ postType }) { const postContentBlockTypes = usePostContentBlockTypes(); const clientIds = useSelect( (select) => { const { getPostBlocksByName } = unlock(select(editorStore)); return getPostBlocksByName( TEMPLATE_POST_TYPE === postType ? TEMPLATE_PART_BLOCK : postContentBlockTypes ); }, [postType, postContentBlockTypes] ); const { enableComplementaryArea } = useDispatch(interfaceStore); if (clientIds.length === 0) { return null; } return /* @__PURE__ */ jsx(PanelBody, { title: __("Content"), children: /* @__PURE__ */ jsx( BlockQuickNavigation, { clientIds, onSelect: () => { enableComplementaryArea("core", "edit-post/document"); } } ) }); } function TemplateContentPanel() { const { postType, renderingMode } = useSelect((select) => { const { getCurrentPostType, getRenderingMode } = unlock( select(editorStore) ); return { postType: getCurrentPostType(), renderingMode: getRenderingMode() }; }, []); if (renderingMode === "post-only" && postType !== TEMPLATE_POST_TYPE) { return null; } return /* @__PURE__ */ jsx(TemplateContentPanelInner, { postType }); } export { TemplateContentPanel as default }; //# sourceMappingURL=index.mjs.map