@wordpress/blocks
Version:
Block API for WordPress.
108 lines (106 loc) • 3.71 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/blocks/src/api/parser/convert-legacy-block.js
var convert_legacy_block_exports = {};
__export(convert_legacy_block_exports, {
convertLegacyBlockNameAndAttributes: () => convertLegacyBlockNameAndAttributes
});
module.exports = __toCommonJS(convert_legacy_block_exports);
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];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
convertLegacyBlockNameAndAttributes
});
//# sourceMappingURL=convert-legacy-block.js.map