UNPKG

@wordpress/block-library

Version:
37 lines (36 loc) • 1.4 kB
import { createBlock } from "@wordpress/blocks"; import { __unstableCreateElement } from "@wordpress/rich-text"; import { getTransformedAttributes } from "../utils/get-transformed-attributes.mjs"; // packages/block-library/src/buttons/transforms.js const transforms = { from: [{ type: "block", isMultiBlock: true, blocks: ["core/button"], transform: (buttons) => createBlock("core/buttons", {}, buttons.map((attributes) => createBlock("core/button", attributes))) }, { type: "block", isMultiBlock: true, blocks: ["core/paragraph"], transform: (buttons) => createBlock("core/buttons", {}, buttons.map((attributes) => { const { content } = attributes; const element = __unstableCreateElement(document, content); const text = element.innerText || ""; const url = element.querySelector("a")?.getAttribute("href"); return createBlock("core/button", { ...attributes, ...getTransformedAttributes(attributes, "core/button", ({ content: contentBinding }) => ({ text: contentBinding })), text, url }); })), isMatch: (paragraphs) => { return paragraphs.every((attributes) => { const element = __unstableCreateElement(document, attributes.content); const text = element.innerText || ""; const links = element.querySelectorAll("a"); return text.length <= 30 && links.length <= 1; }); } }] }; export { transforms as default }; //# sourceMappingURL=transforms.mjs.map