UNPKG

@wordpress/block-editor

Version:
65 lines (62 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addAttribute = addAttribute; exports.addSaveProps = addSaveProps; exports.default = void 0; var _hooks = require("@wordpress/hooks"); var _blocks = require("@wordpress/blocks"); /** * WordPress dependencies */ /** * Filters registered block settings, extending attributes with ariaLabel using aria-label * of the first node. * * @param {Object} settings Original block settings. * * @return {Object} Filtered block settings. */ function addAttribute(settings) { // Allow blocks to specify their own attribute definition with default values if needed. if (settings?.attributes?.ariaLabel?.type) { return settings; } if ((0, _blocks.hasBlockSupport)(settings, 'ariaLabel')) { // Gracefully handle if settings.attributes is undefined. settings.attributes = { ...settings.attributes, ariaLabel: { type: 'string' } }; } return settings; } /** * Override props assigned to save component to inject aria-label, if block * supports ariaLabel. This is only applied if the block's save result is an * element and not a markup string. * * @param {Object} extraProps Additional props applied to save element. * @param {Object} blockType Block type. * @param {Object} attributes Current block attributes. * * @return {Object} Filtered props applied to save element. */ function addSaveProps(extraProps, blockType, attributes) { if ((0, _blocks.hasBlockSupport)(blockType, 'ariaLabel')) { extraProps['aria-label'] = attributes.ariaLabel === '' ? null : attributes.ariaLabel; } return extraProps; } var _default = exports.default = { addSaveProps, attributeKeys: ['ariaLabel'], hasSupport(name) { return (0, _blocks.hasBlockSupport)(name, 'ariaLabel'); } }; (0, _hooks.addFilter)('blocks.registerBlockType', 'core/ariaLabel/attribute', addAttribute); //# sourceMappingURL=aria-label.js.map