UNPKG

@wordpress/block-editor

Version:
41 lines (38 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useBlockContext; var _blocks = require("@wordpress/blocks"); var _data = require("@wordpress/data"); var _store = require("../../store"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * Returns a context object for a given block. * * @param {string} clientId The block client ID. * * @return {Record<string,*>} Context value. */ function useBlockContext(clientId) { return (0, _data.useSelect)(select => { const block = select(_store.store).getBlock(clientId); if (!block) { return undefined; } const blockType = select(_blocks.store).getBlockType(block.name); if (!blockType) { return undefined; } if (Object.keys(blockType.providesContext).length === 0) { return undefined; } return Object.fromEntries(Object.entries(blockType.providesContext).map(([contextName, attributeName]) => [contextName, block.attributes[attributeName]])); }, [clientId]); } //# sourceMappingURL=use-block-context.js.map