UNPKG

@wordpress/block-library

Version:
40 lines (39 loc) • 1.76 kB
import { capitalCase } from "change-case"; import { store } from "@wordpress/core-data"; import { select } from "@wordpress/data"; import { symbolFilled } from "@wordpress/icons"; import { addFilter } from "@wordpress/hooks"; import { decodeEntities } from "@wordpress/html-entities"; import initBlock from "../utils/init-block.mjs"; import metadata from "./block.json"; import edit from "./edit/index.mjs"; import { enhanceTemplatePartVariations } from "./variations.mjs"; // packages/block-library/src/template-part/index.js const { name } = metadata; const settings = { icon: symbolFilled, __experimentalLabel: ({ slug, theme }) => { if (!slug) return; const { getCurrentTheme, getEditedEntityRecord } = select(store); const entity = getEditedEntityRecord("postType", "wp_template_part", (theme || getCurrentTheme()?.stylesheet) + "//" + slug); if (!entity) return; return decodeEntities(entity.title) || capitalCase(entity.slug || ""); }, edit }; const init = () => { addFilter("blocks.registerBlockType", "core/template-part", enhanceTemplatePartVariations); const DISALLOWED_PARENTS = ["core/post-content"]; addFilter("blockEditor.__unstableCanInsertBlockType", "core/block-library/removeTemplatePartsFromPostTemplates", (canInsert, blockType, rootClientId, { getBlock, getBlockParentsByBlockName }) => { if (blockType.name !== "core/template-part") return canInsert; for (const disallowedParentType of DISALLOWED_PARENTS) if (getBlock(rootClientId)?.name === disallowedParentType || getBlockParentsByBlockName(rootClientId, disallowedParentType).length) return false; return canInsert; }); return initBlock({ name, metadata, settings }); }; export { init, metadata, name, settings }; //# sourceMappingURL=index.mjs.map