@wordpress/blocks
Version:
Block API for WordPress.
84 lines (83 loc) • 2.62 kB
JavaScript
// packages/blocks/src/api/parser/convert-legacy-block.js
function convertLegacyBlockNameAndAttributes(name, attributes) {
const newAttributes = { ...attributes };
if ("core/cover-image" === name) {
name = "core/cover";
}
if ("core/text" === name || "core/cover-text" === name) {
name = "core/paragraph";
}
if (name && name.indexOf("core/social-link-") === 0) {
newAttributes.service = name.substring(17);
name = "core/social-link";
}
if (name && name.indexOf("core-embed/") === 0) {
const providerSlug = name.substring(11);
const deprecated = {
speaker: "speaker-deck",
polldaddy: "crowdsignal"
};
newAttributes.providerNameSlug = providerSlug in deprecated ? deprecated[providerSlug] : providerSlug;
if (!["amazon-kindle", "wordpress"].includes(providerSlug)) {
newAttributes.responsive = true;
}
name = "core/embed";
}
if (name === "core/post-comment-author") {
name = "core/comment-author-name";
}
if (name === "core/post-comment-content") {
name = "core/comment-content";
}
if (name === "core/post-comment-date") {
name = "core/comment-date";
}
if (name === "core/comments-query-loop") {
name = "core/comments";
const { className = "" } = newAttributes;
if (!className.includes("wp-block-comments-query-loop")) {
newAttributes.className = [
"wp-block-comments-query-loop",
className
].join(" ");
}
}
if (name === "core/post-comments") {
name = "core/comments";
newAttributes.legacy = true;
}
if (attributes.layout?.type === "grid" && typeof attributes.layout?.columnCount === "string") {
newAttributes.layout = {
...newAttributes.layout,
columnCount: parseInt(attributes.layout.columnCount, 10)
};
}
if (typeof attributes.style?.layout?.columnSpan === "string") {
const columnSpanNumber = parseInt(
attributes.style.layout.columnSpan,
10
);
newAttributes.style = {
...newAttributes.style,
layout: {
...newAttributes.style.layout,
columnSpan: isNaN(columnSpanNumber) ? void 0 : columnSpanNumber
}
};
}
if (typeof attributes.style?.layout?.rowSpan === "string") {
const rowSpanNumber = parseInt(attributes.style.layout.rowSpan, 10);
newAttributes.style = {
...newAttributes.style,
layout: {
...newAttributes.style.layout,
rowSpan: isNaN(rowSpanNumber) ? void 0 : rowSpanNumber
}
};
}
return [name, newAttributes];
}
export {
convertLegacyBlockNameAndAttributes
};
//# sourceMappingURL=convert-legacy-block.js.map