@wordpress/block-library
Version:
Block library for the WordPress editor.
76 lines (75 loc) • 2.04 kB
JavaScript
import clsx from "clsx";
import { InnerBlocks, useBlockProps } from "@wordpress/block-editor";
import { jsx } from "react/jsx-runtime";
// packages/block-library/src/buttons/deprecated.jsx
/**
* @param {Object} attributes Block's attributes.
*/
const migrateWithLayout = (attributes) => {
if (!!attributes.layout) return attributes;
const { contentJustification, orientation, ...updatedAttributes } = attributes;
if (contentJustification || orientation) Object.assign(updatedAttributes, { layout: {
type: "flex",
...contentJustification && { justifyContent: contentJustification },
...orientation && { orientation }
} });
return updatedAttributes;
};
const deprecated = [{
attributes: {
contentJustification: { type: "string" },
orientation: {
type: "string",
default: "horizontal"
}
},
supports: {
anchor: true,
align: ["wide", "full"],
__experimentalExposeControlsToChildren: true,
spacing: {
blockGap: true,
margin: ["top", "bottom"],
__experimentalDefaultControls: { blockGap: true }
}
},
isEligible: ({ contentJustification, orientation }) => !!contentJustification || !!orientation,
migrate: migrateWithLayout,
save({ attributes: { contentJustification, orientation } }) {
return /* @__PURE__ */ jsx("div", {
...useBlockProps.save({ className: clsx({
[`is-content-justification-${contentJustification}`]: contentJustification,
"is-vertical": orientation === "vertical"
}) }),
children: /* @__PURE__ */ jsx(InnerBlocks.Content, {})
});
}
}, {
supports: {
align: [
"center",
"left",
"right"
],
anchor: true
},
save() {
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(InnerBlocks.Content, {}) });
},
isEligible({ align }) {
return align && [
"center",
"left",
"right"
].includes(align);
},
migrate(attributes) {
return migrateWithLayout({
...attributes,
align: void 0,
contentJustification: attributes.align
});
}
}];
export { deprecated as default };
//# sourceMappingURL=deprecated.mjs.map