UNPKG

@wordpress/block-editor

Version:
35 lines (34 loc) 996 B
// packages/block-editor/src/components/inner-blocks/use-block-context.js import { store as blocksStore } from "@wordpress/blocks"; import { useSelect } from "@wordpress/data"; import { store as blockEditorStore } from "../../store"; function useBlockContext(clientId) { return useSelect( (select) => { const block = select(blockEditorStore).getBlock(clientId); if (!block) { return void 0; } const blockType = select(blocksStore).getBlockType(block.name); if (!blockType) { return void 0; } if (Object.keys(blockType.providesContext).length === 0) { return void 0; } return Object.fromEntries( Object.entries(blockType.providesContext).map( ([contextName, attributeName]) => [ contextName, block.attributes[attributeName] ] ) ); }, [clientId] ); } export { useBlockContext as default }; //# sourceMappingURL=use-block-context.js.map