UNPKG

@wordpress/block-library

Version:
485 lines (484 loc) • 14.2 kB
import clsx from "clsx"; import { RichText, getColorClassName, getColorObjectByAttributeValues, store, useBlockProps } from "@wordpress/block-editor"; import { select } from "@wordpress/data"; import { SOLID_COLOR_CLASS } from "./shared.mjs"; import migrateTextAlignAttributeToBlockSupport from "../utils/migrate-text-align.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/block-library/src/pullquote/deprecated.jsx const blockAttributes = { value: { type: "string", source: "html", selector: "blockquote", multiline: "p" }, citation: { type: "string", source: "html", selector: "cite", default: "" }, mainColor: { type: "string" }, customMainColor: { type: "string" }, textColor: { type: "string" }, customTextColor: { type: "string" } }; function parseBorderColor(styleString) { if (!styleString) return; const matches = styleString.match(/border-color:([^;]+)[;]?/); if (matches && matches[1]) return matches[1]; } function multilineToInline(value) { value = value || `<p></p>`; const values = `</p>${value}<p>`.split(`</p><p>`); values.shift(); values.pop(); return values.join("<br>"); } /** * New deprecations need to be placed first * for them to have higher priority. * * Old deprecations may need to be updated as well. * * See block-deprecation.md */ var deprecated_default = [ { attributes: { value: { type: "rich-text", source: "rich-text", selector: "p", role: "content" }, citation: { type: "rich-text", source: "rich-text", selector: "cite", role: "content" }, textAlign: { type: "string" } }, supports: { anchor: true, align: [ "left", "right", "wide", "full" ], background: { backgroundImage: true, backgroundSize: true, __experimentalDefaultControls: { backgroundImage: true } }, color: { gradients: true, background: true, link: true, __experimentalDefaultControls: { background: true, text: true } }, dimensions: { minHeight: true }, spacing: { margin: true, padding: true }, typography: { fontSize: true, lineHeight: true, __experimentalFontFamily: true, __experimentalFontWeight: true, __experimentalFontStyle: true, __experimentalTextTransform: true, __experimentalTextDecoration: true, __experimentalLetterSpacing: true, __experimentalDefaultControls: { fontSize: true } }, __experimentalBorder: { color: true, radius: true, style: true, width: true, __experimentalDefaultControls: { color: true, radius: true, style: true, width: true } }, __experimentalStyle: { typography: { fontSize: "1.5em", lineHeight: "1.6" } }, interactivity: { clientNavigation: true } }, save({ attributes }) { const { textAlign, citation, value } = attributes; const shouldShowCitation = !RichText.isEmpty(citation); return /* @__PURE__ */ jsx("figure", { ...useBlockProps.save({ className: clsx({ [`has-text-align-${textAlign}`]: textAlign }) }), children: /* @__PURE__ */ jsxs("blockquote", { children: [/* @__PURE__ */ jsx(RichText.Content, { tagName: "p", value }), shouldShowCitation && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation })] }) }); }, isEligible(attributes) { return !!attributes.textAlign || !!attributes.className?.match(/\bhas-text-align-(left|center|right)\b/); }, migrate: migrateTextAlignAttributeToBlockSupport }, { attributes: { value: { type: "string", source: "html", selector: "blockquote", multiline: "p", role: "content" }, citation: { type: "string", source: "html", selector: "cite", default: "", role: "content" }, textAlign: { type: "string" } }, supports: { anchor: true, align: [ "left", "right", "wide", "full" ], color: { gradients: true, background: true, link: true, __experimentalDefaultControls: { background: true, text: true } }, typography: { fontSize: true, lineHeight: true, __experimentalFontFamily: true, __experimentalFontWeight: true, __experimentalFontStyle: true, __experimentalTextTransform: true, __experimentalTextDecoration: true, __experimentalLetterSpacing: true, __experimentalDefaultControls: { fontSize: true, fontAppearance: true } }, __experimentalBorder: { color: true, radius: true, style: true, width: true, __experimentalDefaultControls: { color: true, radius: true, style: true, width: true } }, __experimentalStyle: { typography: { fontSize: "1.5em", lineHeight: "1.6" } } }, save({ attributes }) { const { textAlign, citation, value } = attributes; const shouldShowCitation = !RichText.isEmpty(citation); return /* @__PURE__ */ jsx("figure", { ...useBlockProps.save({ className: clsx({ [`has-text-align-${textAlign}`]: textAlign }) }), children: /* @__PURE__ */ jsxs("blockquote", { children: [/* @__PURE__ */ jsx(RichText.Content, { value, multiline: true }), shouldShowCitation && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation })] }) }); }, migrate({ value, ...attributes }) { return migrateTextAlignAttributeToBlockSupport({ value: multilineToInline(value), ...attributes }); } }, { attributes: { ...blockAttributes }, supports: { anchor: true, align: [ "left", "right", "wide", "full" ], color: { gradients: true, background: true, link: true }, __experimentalBorder: { color: true, radius: true, style: true, width: true } }, save({ attributes }) { const { mainColor, customMainColor, customTextColor, textColor, value, citation, className } = attributes; const isSolidColorStyle = className?.includes(SOLID_COLOR_CLASS); let figureClasses, figureStyles; if (isSolidColorStyle) { const backgroundClass = getColorClassName("background-color", mainColor); figureClasses = clsx({ "has-background": backgroundClass || customMainColor, [backgroundClass]: backgroundClass }); figureStyles = { backgroundColor: backgroundClass ? void 0 : customMainColor }; } else if (customMainColor) figureStyles = { borderColor: customMainColor }; const blockquoteTextColorClass = getColorClassName("color", textColor); const blockquoteClasses = clsx({ "has-text-color": textColor || customTextColor, [blockquoteTextColorClass]: blockquoteTextColorClass }); const blockquoteStyles = blockquoteTextColorClass ? void 0 : { color: customTextColor }; return /* @__PURE__ */ jsx("figure", { ...useBlockProps.save({ className: figureClasses, style: figureStyles }), children: /* @__PURE__ */ jsxs("blockquote", { className: blockquoteClasses, style: blockquoteStyles, children: [/* @__PURE__ */ jsx(RichText.Content, { value, multiline: true }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation })] }) }); }, migrate({ value, className, mainColor, customMainColor, customTextColor, ...attributes }) { const isSolidColorStyle = className?.includes(SOLID_COLOR_CLASS); let style; if (customMainColor) { if (!isSolidColorStyle) style = { border: { color: customMainColor } }; else style = { color: { background: customMainColor } }; } if (customTextColor && style) style.color = { ...style.color, text: customTextColor }; return migrateTextAlignAttributeToBlockSupport({ value: multilineToInline(value), className, backgroundColor: isSolidColorStyle ? mainColor : void 0, borderColor: isSolidColorStyle ? void 0 : mainColor, textAlign: isSolidColorStyle ? "left" : void 0, ...attributes, style }); } }, { attributes: { ...blockAttributes, figureStyle: { source: "attribute", selector: "figure", attribute: "style" } }, save({ attributes }) { const { mainColor, customMainColor, textColor, customTextColor, value, citation, className, figureStyle } = attributes; const isSolidColorStyle = className?.includes(SOLID_COLOR_CLASS); let figureClasses, figureStyles; if (isSolidColorStyle) { const backgroundClass = getColorClassName("background-color", mainColor); figureClasses = clsx({ "has-background": backgroundClass || customMainColor, [backgroundClass]: backgroundClass }); figureStyles = { backgroundColor: backgroundClass ? void 0 : customMainColor }; } else if (customMainColor) figureStyles = { borderColor: customMainColor }; else if (mainColor) figureStyles = { borderColor: parseBorderColor(figureStyle) }; const blockquoteTextColorClass = getColorClassName("color", textColor); const blockquoteClasses = (textColor || customTextColor) && clsx("has-text-color", { [blockquoteTextColorClass]: blockquoteTextColorClass }); return /* @__PURE__ */ jsx("figure", { className: figureClasses, style: figureStyles, children: /* @__PURE__ */ jsxs("blockquote", { className: blockquoteClasses, style: blockquoteTextColorClass ? void 0 : { color: customTextColor }, children: [/* @__PURE__ */ jsx(RichText.Content, { value, multiline: true }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation })] }) }); }, migrate({ value, className, figureStyle, mainColor, customMainColor, customTextColor, ...attributes }) { const isSolidColorStyle = className?.includes(SOLID_COLOR_CLASS); let style; if (customMainColor) { if (!isSolidColorStyle) style = { border: { color: customMainColor } }; else style = { color: { background: customMainColor } }; } if (customTextColor && style) style.color = { ...style.color, text: customTextColor }; if (!isSolidColorStyle && mainColor && figureStyle) { const borderColor = parseBorderColor(figureStyle); if (borderColor) return { value: multilineToInline(value), ...attributes, className, style: { border: { color: borderColor } } }; } return migrateTextAlignAttributeToBlockSupport({ value: multilineToInline(value), className, backgroundColor: isSolidColorStyle ? mainColor : void 0, borderColor: isSolidColorStyle ? void 0 : mainColor, textAlign: isSolidColorStyle ? "left" : void 0, ...attributes, style }); } }, { attributes: blockAttributes, save({ attributes }) { const { mainColor, customMainColor, textColor, customTextColor, value, citation, className } = attributes; const isSolidColorStyle = className?.includes(SOLID_COLOR_CLASS); let figureClass, figureStyles; if (isSolidColorStyle) { figureClass = getColorClassName("background-color", mainColor); if (!figureClass) figureStyles = { backgroundColor: customMainColor }; } else if (customMainColor) figureStyles = { borderColor: customMainColor }; else if (mainColor) { const colors = select(store).getSettings().colors ?? []; figureStyles = { borderColor: getColorObjectByAttributeValues(colors, mainColor).color }; } const blockquoteTextColorClass = getColorClassName("color", textColor); const blockquoteClasses = textColor || customTextColor ? clsx("has-text-color", { [blockquoteTextColorClass]: blockquoteTextColorClass }) : void 0; return /* @__PURE__ */ jsx("figure", { className: figureClass, style: figureStyles, children: /* @__PURE__ */ jsxs("blockquote", { className: blockquoteClasses, style: blockquoteTextColorClass ? void 0 : { color: customTextColor }, children: [/* @__PURE__ */ jsx(RichText.Content, { value, multiline: true }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation })] }) }); }, migrate({ value, className, mainColor, customMainColor, customTextColor, ...attributes }) { const isSolidColorStyle = className?.includes(SOLID_COLOR_CLASS); let style = {}; if (customMainColor) { if (!isSolidColorStyle) style = { border: { color: customMainColor } }; else style = { color: { background: customMainColor } }; } if (customTextColor && style) style.color = { ...style.color, text: customTextColor }; return migrateTextAlignAttributeToBlockSupport({ value: multilineToInline(value), className, backgroundColor: isSolidColorStyle ? mainColor : void 0, borderColor: isSolidColorStyle ? void 0 : mainColor, textAlign: isSolidColorStyle ? "left" : void 0, ...attributes, style }); } }, { attributes: { ...blockAttributes }, save({ attributes }) { const { value, citation } = attributes; return /* @__PURE__ */ jsxs("blockquote", { children: [/* @__PURE__ */ jsx(RichText.Content, { value, multiline: true }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "cite", value: citation })] }); }, migrate({ value, ...attributes }) { return { value: multilineToInline(value), ...attributes }; } }, { attributes: { ...blockAttributes, citation: { type: "string", source: "html", selector: "footer" }, align: { type: "string", default: "none" } }, save({ attributes }) { const { value, citation, align } = attributes; return /* @__PURE__ */ jsxs("blockquote", { className: `align${align}`, children: [/* @__PURE__ */ jsx(RichText.Content, { value, multiline: true }), !RichText.isEmpty(citation) && /* @__PURE__ */ jsx(RichText.Content, { tagName: "footer", value: citation })] }); }, migrate({ value, ...attributes }) { return { value: multilineToInline(value), ...attributes }; } } ]; export { deprecated_default as default }; //# sourceMappingURL=deprecated.mjs.map