UNPKG

@wordpress/block-editor

Version:
60 lines (59 loc) 2.22 kB
// packages/block-editor/src/components/block-settings-menu-controls/edit-section-menu-item.js import { MenuItem } from "@wordpress/components"; import { _x } from "@wordpress/i18n"; import { useSelect } from "@wordpress/data"; import { isReusableBlock, isTemplatePart } from "@wordpress/blocks"; import useContentOnlySectionEdit from "../../hooks/use-content-only-section-edit"; import { store as blockEditorStore } from "../../store"; import { jsx } from "react/jsx-runtime"; function EditSectionMenuItem({ clientId, onClose }) { const { isSectionBlock, isEditingContentOnlySection, editContentOnlySection } = useContentOnlySectionEdit(clientId); const { block, onNavigateToEntityRecord } = useSelect( (select) => { const { getBlock, getSettings } = select(blockEditorStore); return { block: getBlock(clientId), onNavigateToEntityRecord: getSettings().onNavigateToEntityRecord }; }, [clientId] ); if (!window?.__experimentalContentOnlyPatternInsertion || !isSectionBlock || isEditingContentOnlySection) { return null; } const blockAttributes = block?.attributes || {}; const isSyncedPattern = isReusableBlock(block); const isTemplatePartBlock = isTemplatePart(block); const shouldNavigateToIsolatedEditor = (isSyncedPattern || isTemplatePartBlock) && onNavigateToEntityRecord; const handleClick = () => { if (shouldNavigateToIsolatedEditor) { if (isSyncedPattern) { onNavigateToEntityRecord({ postId: blockAttributes.ref, postType: "wp_block" }); } else if (isTemplatePartBlock) { const { theme, slug } = blockAttributes; const templatePartId = theme && slug ? `${theme}//${slug}` : null; if (templatePartId) { onNavigateToEntityRecord({ postId: templatePartId, postType: "wp_template_part" }); } } } else { editContentOnlySection(clientId); } onClose(); }; return /* @__PURE__ */ jsx(MenuItem, { onClick: handleClick, children: _x("Edit section", "Editing a section in the Editor") }); } export { EditSectionMenuItem }; //# sourceMappingURL=edit-section-menu-item.js.map