UNPKG

@wordpress/block-editor

Version:
46 lines (42 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addLabelCallback = addLabelCallback; var _hooks = require("@wordpress/hooks"); var _blocks = require("@wordpress/blocks"); /** * WordPress dependencies */ /** * Filters registered block settings, adding an `__experimentalLabel` callback if one does not already exist. * * @param {Object} settings Original block settings. * * @return {Object} Filtered block settings. */ function addLabelCallback(settings) { // If blocks provide their own label callback, do not override it. if (settings.__experimentalLabel) { return settings; } const supportsBlockNaming = (0, _blocks.hasBlockSupport)(settings, 'renaming', true // default value ); // Check whether block metadata is supported before using it. if (supportsBlockNaming) { settings.__experimentalLabel = (attributes, { context }) => { const { metadata } = attributes; // In the list view, use the block's name attribute as the label. if (context === 'list-view' && metadata?.name) { return metadata.name; } }; } return settings; } (0, _hooks.addFilter)('blocks.registerBlockType', 'core/metadata/addLabelCallback', addLabelCallback); //# sourceMappingURL=block-renaming.js.map