UNPKG

@gechiui/block-editor

Version:
44 lines (38 loc) 1.23 kB
/** * GeChiUI dependencies */ import { useSelect } from '@gechiui/data'; import { getBlockType } from '@gechiui/blocks'; /** * Internal dependencies */ import { store as blockEditorStore } from '../../../store'; /** * 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. */ export 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 useSelect(select => { const { getBlockName, getBlockAttributes } = select(blockEditorStore); const attributes = getBlockAttributes(clientId); if (!(attributes !== null && attributes !== void 0 && attributes.className)) { return; } const blockType = getBlockType(getBlockName(clientId)); const hasLightBlockWrapper = (blockType === null || blockType === void 0 ? void 0 : blockType.apiVersion) > 1; if (!hasLightBlockWrapper) { return; } return attributes.className; }, [clientId]); } //# sourceMappingURL=use-block-custom-class-name.js.map