UNPKG

@wordpress/block-library

Version:
284 lines (283 loc) 7.41 kB
// packages/block-library/src/quote/deprecated.js import clsx from "clsx"; import { createBlock, parseWithAttributeSchema } from "@wordpress/blocks"; import { InnerBlocks, RichText, useBlockProps } from "@wordpress/block-editor"; import { jsx, jsxs } from "react/jsx-runtime"; var migrateToQuoteV2 = (attributes) => { const { value, ...restAttributes } = attributes; return [ { ...restAttributes }, value ? parseWithAttributeSchema(value, { type: "array", source: "query", selector: "p", query: { content: { type: "string", source: "html" } } }).map( ({ content }) => createBlock("core/paragraph", { content }) ) : createBlock("core/paragraph") ]; }; var TEXT_ALIGN_OPTIONS = ["left", "right", "center"]; var migrateTextAlign = (attributes, innerBlocks) => { const { align, ...rest } = attributes; const migratedAttributes = TEXT_ALIGN_OPTIONS.includes(align) ? { ...rest, textAlign: align } : attributes; return [migratedAttributes, innerBlocks]; }; var migrateLargeStyle = (attributes, innerBlocks) => { return [ { ...attributes, className: attributes.className ? attributes.className + " is-style-large" : "is-style-large" }, innerBlocks ]; }; var v4 = { attributes: { value: { type: "string", source: "html", selector: "blockquote", multiline: "p", default: "", role: "content" }, citation: { type: "string", source: "html", selector: "cite", default: "", role: "content" }, align: { type: "string" } }, supports: { anchor: true, html: false, __experimentalOnEnter: true, __experimentalOnMerge: true, typography: { fontSize: true, lineHeight: true, __experimentalFontFamily: true, __experimentalFontWeight: true, __experimentalFontStyle: true, __experimentalTextTransform: true, __experimentalTextDecoration: true, __experimentalLetterSpacing: true, __experimentalDefaultControls: { fontSize: true, fontAppearance: true } }, color: { gradients: true, heading: true, link: true, __experimentalDefaultControls: { background: true, text: true } } }, isEligible: ({ align }) => TEXT_ALIGN_OPTIONS.includes(align), save({ attributes }) { const { align, citation } = attributes; const className = clsx({ [`has-text-align-${align}`]: align }); return /* @__PURE__ */ jsxs("blockquote", { ...useBlockProps.save({ className }), children: [ /* @__PURE__ */ jsx(InnerBlocks.Content, {}), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation }) ] }); }, migrate: migrateTextAlign }; var v3 = { attributes: { value: { type: "string", source: "html", selector: "blockquote", multiline: "p", default: "", role: "content" }, citation: { type: "string", source: "html", selector: "cite", default: "", role: "content" }, align: { type: "string" } }, supports: { anchor: true, __experimentalSlashInserter: true, typography: { fontSize: true, lineHeight: true, __experimentalFontStyle: true, __experimentalFontWeight: true, __experimentalLetterSpacing: true, __experimentalTextTransform: true, __experimentalDefaultControls: { fontSize: true, fontAppearance: true } } }, save({ attributes }) { const { align, value, citation } = attributes; const className = clsx({ [`has-text-align-${align}`]: align }); return /* @__PURE__ */ jsxs("blockquote", { ...useBlockProps.save({ className }), children: [ /* @__PURE__ */ jsx(RichText.Content, { multiline: true, value }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation }) ] }); }, migrate(attributes) { return migrateTextAlign(...migrateToQuoteV2(attributes)); } }; var v2 = { attributes: { value: { type: "string", source: "html", selector: "blockquote", multiline: "p", default: "" }, citation: { type: "string", source: "html", selector: "cite", default: "" }, align: { type: "string" } }, migrate(attributes) { return migrateTextAlign(...migrateToQuoteV2(attributes)); }, save({ attributes }) { const { align, value, citation } = attributes; return /* @__PURE__ */ jsxs("blockquote", { style: { textAlign: align ? align : null }, children: [ /* @__PURE__ */ jsx(RichText.Content, { multiline: true, value }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation }) ] }); } }; var v1 = { attributes: { value: { type: "string", source: "html", selector: "blockquote", multiline: "p", default: "" }, citation: { type: "string", source: "html", selector: "cite", default: "" }, align: { type: "string" }, style: { type: "number", default: 1 } }, migrate(attributes) { if (attributes.style === 2) { const { style, ...restAttributes } = attributes; return migrateTextAlign( ...migrateLargeStyle(...migrateToQuoteV2(restAttributes)) ); } return migrateTextAlign(...migrateToQuoteV2(attributes)); }, save({ attributes }) { const { align, value, citation, style } = attributes; return /* @__PURE__ */ jsxs( "blockquote", { className: style === 2 ? "is-large" : "", style: { textAlign: align ? align : null }, children: [ /* @__PURE__ */ jsx(RichText.Content, { multiline: true, value }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation }) ] } ); } }; var v0 = { attributes: { value: { type: "string", source: "html", selector: "blockquote", multiline: "p", default: "" }, citation: { type: "string", source: "html", selector: "footer", default: "" }, align: { type: "string" }, style: { type: "number", default: 1 } }, migrate(attributes) { if (!isNaN(parseInt(attributes.style))) { const { style, ...restAttributes } = attributes; return migrateTextAlign(...migrateToQuoteV2(restAttributes)); } return migrateTextAlign(...migrateToQuoteV2(attributes)); }, save({ attributes }) { const { align, value, citation, style } = attributes; return /* @__PURE__ */ jsxs( "blockquote", { className: `blocks-quote-style-${style}`, style: { textAlign: align ? align : null }, children: [ /* @__PURE__ */ jsx(RichText.Content, { multiline: true, value }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "footer", value: citation }) ] } ); } }; var deprecated_default = [v4, v3, v2, v1, v0]; export { deprecated_default as default, migrateToQuoteV2 }; //# sourceMappingURL=deprecated.js.map