@wordpress/block-library
Version:
Block library for the WordPress editor.
513 lines (512 loc) • 16.9 kB
JavaScript
"use strict";
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_data = require("@wordpress/data");
let __shared_js = require("./shared.cjs");
let ___utils_migrate_text_align_js = require("../utils/migrate-text-align.cjs");
___utils_migrate_text_align_js = __toESM(___utils_migrate_text_align_js);
let react_jsx_runtime = require("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 = !_wordpress_block_editor.RichText.isEmpty(citation);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", {
..._wordpress_block_editor.useBlockProps.save({ className: (0, clsx.default)({ [`has-text-align-${textAlign}`]: textAlign }) }),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("blockquote", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
tagName: "p",
value
}), shouldShowCitation && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
tagName: "cite",
value: citation
})] })
});
},
isEligible(attributes) {
return !!attributes.textAlign || !!attributes.className?.match(/\bhas-text-align-(left|center|right)\b/);
},
migrate: ___utils_migrate_text_align_js.default
},
{
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 = !_wordpress_block_editor.RichText.isEmpty(citation);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", {
..._wordpress_block_editor.useBlockProps.save({ className: (0, clsx.default)({ [`has-text-align-${textAlign}`]: textAlign }) }),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("blockquote", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
value,
multiline: true
}), shouldShowCitation && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
tagName: "cite",
value: citation
})] })
});
},
migrate({ value, ...attributes }) {
return (0, ___utils_migrate_text_align_js.default)({
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(__shared_js.SOLID_COLOR_CLASS);
let figureClasses, figureStyles;
if (isSolidColorStyle) {
const backgroundClass = (0, _wordpress_block_editor.getColorClassName)("background-color", mainColor);
figureClasses = (0, clsx.default)({
"has-background": backgroundClass || customMainColor,
[backgroundClass]: backgroundClass
});
figureStyles = { backgroundColor: backgroundClass ? void 0 : customMainColor };
} else if (customMainColor) figureStyles = { borderColor: customMainColor };
const blockquoteTextColorClass = (0, _wordpress_block_editor.getColorClassName)("color", textColor);
const blockquoteClasses = (0, clsx.default)({
"has-text-color": textColor || customTextColor,
[blockquoteTextColorClass]: blockquoteTextColorClass
});
const blockquoteStyles = blockquoteTextColorClass ? void 0 : { color: customTextColor };
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", {
..._wordpress_block_editor.useBlockProps.save({
className: figureClasses,
style: figureStyles
}),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("blockquote", {
className: blockquoteClasses,
style: blockquoteStyles,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
value,
multiline: true
}), !_wordpress_block_editor.RichText.isEmpty(citation) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
tagName: "cite",
value: citation
})]
})
});
},
migrate({ value, className, mainColor, customMainColor, customTextColor, ...attributes }) {
const isSolidColorStyle = className?.includes(__shared_js.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 (0, ___utils_migrate_text_align_js.default)({
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(__shared_js.SOLID_COLOR_CLASS);
let figureClasses, figureStyles;
if (isSolidColorStyle) {
const backgroundClass = (0, _wordpress_block_editor.getColorClassName)("background-color", mainColor);
figureClasses = (0, clsx.default)({
"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 = (0, _wordpress_block_editor.getColorClassName)("color", textColor);
const blockquoteClasses = (textColor || customTextColor) && (0, clsx.default)("has-text-color", { [blockquoteTextColorClass]: blockquoteTextColorClass });
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", {
className: figureClasses,
style: figureStyles,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("blockquote", {
className: blockquoteClasses,
style: blockquoteTextColorClass ? void 0 : { color: customTextColor },
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
value,
multiline: true
}), !_wordpress_block_editor.RichText.isEmpty(citation) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
tagName: "cite",
value: citation
})]
})
});
},
migrate({ value, className, figureStyle, mainColor, customMainColor, customTextColor, ...attributes }) {
const isSolidColorStyle = className?.includes(__shared_js.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 (0, ___utils_migrate_text_align_js.default)({
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(__shared_js.SOLID_COLOR_CLASS);
let figureClass, figureStyles;
if (isSolidColorStyle) {
figureClass = (0, _wordpress_block_editor.getColorClassName)("background-color", mainColor);
if (!figureClass) figureStyles = { backgroundColor: customMainColor };
} else if (customMainColor) figureStyles = { borderColor: customMainColor };
else if (mainColor) {
const colors = (0, _wordpress_data.select)(_wordpress_block_editor.store).getSettings().colors ?? [];
figureStyles = { borderColor: (0, _wordpress_block_editor.getColorObjectByAttributeValues)(colors, mainColor).color };
}
const blockquoteTextColorClass = (0, _wordpress_block_editor.getColorClassName)("color", textColor);
const blockquoteClasses = textColor || customTextColor ? (0, clsx.default)("has-text-color", { [blockquoteTextColorClass]: blockquoteTextColorClass }) : void 0;
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", {
className: figureClass,
style: figureStyles,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("blockquote", {
className: blockquoteClasses,
style: blockquoteTextColorClass ? void 0 : { color: customTextColor },
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
value,
multiline: true
}), !_wordpress_block_editor.RichText.isEmpty(citation) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
tagName: "cite",
value: citation
})]
})
});
},
migrate({ value, className, mainColor, customMainColor, customTextColor, ...attributes }) {
const isSolidColorStyle = className?.includes(__shared_js.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 (0, ___utils_migrate_text_align_js.default)({
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__ */ (0, react_jsx_runtime.jsxs)("blockquote", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
value,
multiline: true
}), !_wordpress_block_editor.RichText.isEmpty(citation) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.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__ */ (0, react_jsx_runtime.jsxs)("blockquote", {
className: `align${align}`,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
value,
multiline: true
}), !_wordpress_block_editor.RichText.isEmpty(citation) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText.Content, {
tagName: "footer",
value: citation
})]
});
},
migrate({ value, ...attributes }) {
return {
value: multilineToInline(value),
...attributes
};
}
}
];
exports.default = deprecated_default;
//# sourceMappingURL=deprecated.cjs.map