@wordpress/block-library
Version:
Block library for the WordPress editor.
270 lines (269 loc) • 7.39 kB
JavaScript
// packages/block-library/src/group/deprecated.js
import clsx from "clsx";
import {
InnerBlocks,
getColorClassName,
useBlockProps,
useInnerBlocksProps
} from "@wordpress/block-editor";
import { jsx } from "react/jsx-runtime";
var migrateAttributes = (attributes) => {
if (!attributes.tagName) {
attributes = {
...attributes,
tagName: "div"
};
}
if (!attributes.customTextColor && !attributes.customBackgroundColor) {
return attributes;
}
const style = { color: {} };
if (attributes.customTextColor) {
style.color.text = attributes.customTextColor;
}
if (attributes.customBackgroundColor) {
style.color.background = attributes.customBackgroundColor;
}
const { customTextColor, customBackgroundColor, ...restAttributes } = attributes;
return {
...restAttributes,
style
};
};
var deprecated = [
// Version with default layout.
{
attributes: {
tagName: {
type: "string",
default: "div"
},
templateLock: {
type: ["string", "boolean"],
enum: ["all", "insert", false]
}
},
supports: {
__experimentalOnEnter: true,
__experimentalSettings: true,
align: ["wide", "full"],
anchor: true,
ariaLabel: true,
html: false,
color: {
gradients: true,
link: true,
__experimentalDefaultControls: {
background: true,
text: true
}
},
spacing: {
margin: ["top", "bottom"],
padding: true,
blockGap: true,
__experimentalDefaultControls: {
padding: true,
blockGap: true
}
},
__experimentalBorder: {
color: true,
radius: true,
style: true,
width: true,
__experimentalDefaultControls: {
color: true,
radius: true,
style: true,
width: true
}
},
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontStyle: true,
__experimentalFontWeight: true,
__experimentalLetterSpacing: true,
__experimentalTextTransform: true,
__experimentalDefaultControls: {
fontSize: true
}
},
layout: true
},
save({ attributes: { tagName: Tag } }) {
return /* @__PURE__ */ jsx(Tag, { ...useInnerBlocksProps.save(useBlockProps.save()) });
},
isEligible: ({ layout }) => layout?.inherit || layout?.contentSize && layout?.type !== "constrained",
migrate: (attributes) => {
const { layout = null } = attributes;
if (layout?.inherit || layout?.contentSize) {
return {
...attributes,
layout: {
...layout,
type: "constrained"
}
};
}
}
},
// Version of the block with the double div.
{
attributes: {
tagName: {
type: "string",
default: "div"
},
templateLock: {
type: ["string", "boolean"],
enum: ["all", "insert", false]
}
},
supports: {
align: ["wide", "full"],
anchor: true,
color: {
gradients: true,
link: true
},
spacing: {
padding: true
},
__experimentalBorder: {
radius: true
}
},
save({ attributes }) {
const { tagName: Tag } = attributes;
return /* @__PURE__ */ jsx(Tag, { ...useBlockProps.save(), children: /* @__PURE__ */ jsx("div", { className: "wp-block-group__inner-container", children: /* @__PURE__ */ jsx(InnerBlocks.Content, {}) }) });
}
},
// Version of the block without global styles support
{
attributes: {
backgroundColor: {
type: "string"
},
customBackgroundColor: {
type: "string"
},
textColor: {
type: "string"
},
customTextColor: {
type: "string"
}
},
supports: {
align: ["wide", "full"],
anchor: true,
html: false
},
migrate: migrateAttributes,
save({ attributes }) {
const {
backgroundColor,
customBackgroundColor,
textColor,
customTextColor
} = attributes;
const backgroundClass = getColorClassName(
"background-color",
backgroundColor
);
const textClass = getColorClassName("color", textColor);
const className = clsx(backgroundClass, textClass, {
"has-text-color": textColor || customTextColor,
"has-background": backgroundColor || customBackgroundColor
});
const styles = {
backgroundColor: backgroundClass ? void 0 : customBackgroundColor,
color: textClass ? void 0 : customTextColor
};
return /* @__PURE__ */ jsx("div", { className, style: styles, children: /* @__PURE__ */ jsx("div", { className: "wp-block-group__inner-container", children: /* @__PURE__ */ jsx(InnerBlocks.Content, {}) }) });
}
},
// Version of the group block with a bug that made text color class not applied.
{
attributes: {
backgroundColor: {
type: "string"
},
customBackgroundColor: {
type: "string"
},
textColor: {
type: "string"
},
customTextColor: {
type: "string"
}
},
migrate: migrateAttributes,
supports: {
align: ["wide", "full"],
anchor: true,
html: false
},
save({ attributes }) {
const {
backgroundColor,
customBackgroundColor,
textColor,
customTextColor
} = attributes;
const backgroundClass = getColorClassName(
"background-color",
backgroundColor
);
const textClass = getColorClassName("color", textColor);
const className = clsx(backgroundClass, {
"has-text-color": textColor || customTextColor,
"has-background": backgroundColor || customBackgroundColor
});
const styles = {
backgroundColor: backgroundClass ? void 0 : customBackgroundColor,
color: textClass ? void 0 : customTextColor
};
return /* @__PURE__ */ jsx("div", { className, style: styles, children: /* @__PURE__ */ jsx("div", { className: "wp-block-group__inner-container", children: /* @__PURE__ */ jsx(InnerBlocks.Content, {}) }) });
}
},
// v1 of group block. Deprecated to add an inner-container div around `InnerBlocks.Content`.
{
attributes: {
backgroundColor: {
type: "string"
},
customBackgroundColor: {
type: "string"
}
},
supports: {
align: ["wide", "full"],
anchor: true,
html: false
},
migrate: migrateAttributes,
save({ attributes }) {
const { backgroundColor, customBackgroundColor } = attributes;
const backgroundClass = getColorClassName(
"background-color",
backgroundColor
);
const className = clsx(backgroundClass, {
"has-background": backgroundColor || customBackgroundColor
});
const styles = {
backgroundColor: backgroundClass ? void 0 : customBackgroundColor
};
return /* @__PURE__ */ jsx("div", { className, style: styles, children: /* @__PURE__ */ jsx(InnerBlocks.Content, {}) });
}
}
];
var deprecated_default = deprecated;
export {
deprecated_default as default
};
//# sourceMappingURL=deprecated.js.map