@wordpress/block-library
Version:
Block library for the WordPress editor.
83 lines (82 loc) • 3.19 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);
var get_transformed_attributes_exports = {};
__export(get_transformed_attributes_exports, {
getTransformedAttributes: () => getTransformedAttributes
});
module.exports = __toCommonJS(get_transformed_attributes_exports);
var import_blocks = require("@wordpress/blocks");
function getTransformedAttributes(attributes, newBlockName, bindingsCallback = null) {
if (!attributes) {
return void 0;
}
const newBlockType = (0, import_blocks.getBlockType)(newBlockName);
if (!newBlockType) {
return void 0;
}
const transformedAttributes = {};
if ((0, import_blocks.hasBlockSupport)(newBlockType, "allowedBlocks") && attributes.allowedBlocks) {
transformedAttributes.allowedBlocks = attributes.allowedBlocks;
}
if ((0, import_blocks.hasBlockSupport)(newBlockType, "anchor") && attributes.anchor) {
transformedAttributes.anchor = attributes.anchor;
}
if ((0, import_blocks.hasBlockSupport)(newBlockType, "ariaLabel") && attributes.ariaLabel) {
transformedAttributes.ariaLabel = attributes.ariaLabel;
}
if ((0, import_blocks.hasBlockSupport)(newBlockType, "className") && attributes.className) {
transformedAttributes.className = attributes.className;
}
if (attributes.metadata) {
const transformedMetadata = ["noteId"];
if (bindingsCallback) {
transformedMetadata.push("id", "bindings");
}
if ((0, import_blocks.hasBlockSupport)(newBlockType, "renaming", true)) {
transformedMetadata.push("name");
}
if ((0, import_blocks.hasBlockSupport)(newBlockType, "blockVisibility", true)) {
transformedMetadata.push("blockVisibility");
}
if (transformedMetadata.length > 0) {
const newMetadata = Object.entries(attributes.metadata).reduce(
(obj, [prop, value]) => {
if (!transformedMetadata.includes(prop)) {
return obj;
}
obj[prop] = prop === "bindings" ? bindingsCallback(value) : value;
return obj;
},
{}
);
if (Object.keys(newMetadata).length > 0) {
transformedAttributes.metadata = newMetadata;
}
}
}
if (Object.keys(transformedAttributes).length === 0) {
return void 0;
}
return transformedAttributes;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getTransformedAttributes
});
//# sourceMappingURL=get-transformed-attributes.js.map