UNPKG

@wordpress/blocks

Version:
58 lines (56 loc) 2.14 kB
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/fix-aria-label.js var fix_aria_label_exports = {}; __export(fix_aria_label_exports, { fixAriaLabel: () => fixAriaLabel, getHTMLRootElementAriaLabel: () => getHTMLRootElementAriaLabel }); module.exports = __toCommonJS(fix_aria_label_exports); var import_registration = require("../registration"); var import_get_block_attributes = require("./get-block-attributes"); var ARIA_LABEL_ATTR_SCHEMA = { type: "string", source: "attribute", selector: "[data-aria-label] > *", attribute: "aria-label" }; function getHTMLRootElementAriaLabel(innerHTML) { const parsed = (0, import_get_block_attributes.parseWithAttributeSchema)( `<div data-aria-label>${innerHTML}</div>`, ARIA_LABEL_ATTR_SCHEMA ); return parsed; } function fixAriaLabel(blockAttributes, blockType, innerHTML) { if (!(0, import_registration.hasBlockSupport)(blockType, "ariaLabel", false)) { return blockAttributes; } const modifiedBlockAttributes = { ...blockAttributes }; const ariaLabel = getHTMLRootElementAriaLabel(innerHTML); if (ariaLabel) { modifiedBlockAttributes.ariaLabel = ariaLabel; } return modifiedBlockAttributes; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { fixAriaLabel, getHTMLRootElementAriaLabel }); //# sourceMappingURL=fix-aria-label.js.map