UNPKG

@wordpress/block-library

Version:
73 lines (71 loc) 2.65 kB
"use strict"; 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/block-library/src/utils/get-transformed-attributes.js 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, "anchor") && attributes.anchor) { transformedAttributes.anchor = attributes.anchor; } if ((0, import_blocks.hasBlockSupport)(newBlockType, "ariaLabel") && attributes.ariaLabel) { transformedAttributes.ariaLabel = attributes.ariaLabel; } if (attributes.metadata) { const transformedMetadata = []; if (bindingsCallback) { transformedMetadata.push("id", "bindings"); } 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