UNPKG

@wordpress/block-editor

Version:
56 lines (45 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useBlockCustomClassName = useBlockCustomClassName; var _data = require("@wordpress/data"); var _blocks = require("@wordpress/blocks"); var _store = require("../../../store"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * Returns the custom class name if the block is a light block. * * @param {string} clientId The block client ID. * * @return {string} The custom class name. */ function useBlockCustomClassName(clientId) { // It's good for this to be a separate selector because it will be executed // on every attribute change, while the other selectors are not re-evaluated // as much. return (0, _data.useSelect)(select => { const { getBlockName, getBlockAttributes } = select(_store.store); const { className } = getBlockAttributes(clientId); if (!className) { return; } const blockType = (0, _blocks.getBlockType)(getBlockName(clientId)); const hasLightBlockWrapper = blockType.apiVersion > 1 || (0, _blocks.hasBlockSupport)(blockType, 'lightBlockWrapper', false); if (!hasLightBlockWrapper) { return; } return className; }, [clientId]); } //# sourceMappingURL=use-block-custom-class-name.js.map