PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / extend / template-selector / templateContext.js
generateblocks / src / extend / template-selector Last commit date
editor.scss 2 years ago index.js 2 years ago templateContext.js 3 years ago
templateContext.js
34 lines
1 import { applyFilters } from '@wordpress/hooks';
2 import { createContext } from '@wordpress/element';
3 import { useInnerBlocksCount } from '../../hooks';
4 import TemplateSelector from './index';
5
6 const defaultContext = {
7 label: 'Label',
8 instructions: 'Instructions...',
9 templates: [],
10 };
11
12 const TemplateContext = createContext( defaultContext );
13
14 export const withTemplateContext = ( WrappedComponent ) => ( ( props ) => {
15 const { clientId } = props;
16 const innerBlocksCount = useInnerBlocksCount( clientId );
17 const templateContext = applyFilters(
18 'generateblocks.editor.templateContext',
19 defaultContext,
20 props
21 );
22
23 return (
24 <TemplateContext.Provider value={ templateContext }>
25 { 0 < templateContext.templates.length && 0 === innerBlocksCount
26 ? <WrappedComponent { ...props } ContentRenderer={ TemplateSelector } />
27 : <WrappedComponent { ...props } />
28 }
29 </TemplateContext.Provider>
30 );
31 } );
32
33 export default TemplateContext;
34