@wordpress/block-editor
Version:
54 lines (43 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addLabelCallback = addLabelCallback;
var _hooks = require("@wordpress/hooks");
var _metadata = require("./metadata");
/**
* WordPress dependencies
*/
/**
* Internal 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, _metadata.hasBlockMetadataSupport)(settings, 'name', false // 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=metadata-name.js.map