PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.0
GenerateBlocks v1.0
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 / blocks / container / block-controls.js
generateblocks / src / blocks / container Last commit date
css 6 years ago attributes.js 6 years ago block-controls.js 6 years ago block.js 6 years ago edit.js 6 years ago editor.scss 6 years ago save.js 6 years ago section-tag.js 6 years ago style.scss 6 years ago
block-controls.js
108 lines
1 import getIcon from '../../utils/get-icon';
2
3 /**
4 * WordPress Dependencies
5 */
6 const {
7 __,
8 } = wp.i18n;
9
10 const {
11 addFilter,
12 } = wp.hooks;
13
14 const {
15 Fragment,
16 } = wp.element;
17
18 const {
19 BlockControls,
20 } = wp.blockEditor;
21
22 const {
23 Toolbar,
24 Tooltip,
25 Button,
26 } = wp.components;
27
28 const {
29 createHigherOrderComponent,
30 } = wp.compose;
31
32 const {
33 cloneBlock,
34 } = wp.blocks;
35
36 /**
37 * Add mobile visibility controls on Advanced Block Panel.
38 *
39 * @param {function} BlockEdit Block edit component.
40 *
41 * @return {function} BlockEdit Modified block edit component.
42 */
43 const withAdvancedControls = createHigherOrderComponent( ( BlockEdit ) => {
44 return ( props ) => {
45 const {
46 name,
47 attributes,
48 isSelected,
49 clientId,
50 } = props;
51
52 const {
53 isGrid,
54 } = attributes;
55
56 let parentGridId = false;
57
58 if ( typeof wp.data.select( 'core/block-editor' ).getBlockParentsByBlockName === 'function' ) {
59 parentGridId = wp.data.select( 'core/block-editor' ).getBlockParentsByBlockName( clientId, 'generateblocks/grid', true )[ 0 ];
60 } else {
61 parentGridId = wp.data.select( 'core/block-editor' ).getBlockRootClientId( clientId );
62 }
63
64 return (
65 <Fragment>
66 { isSelected && isGrid && parentGridId && 'generateblocks/container' === name &&
67 <BlockControls>
68 <Toolbar>
69 <Tooltip text={ __( 'Duplicate Grid Item', 'generateblocks' ) }>
70 <Button
71 className="gblocks-block-control-icon gblocks-add-grid-item"
72 icon={ getIcon( 'addContainer' ) }
73 onClick={ () => {
74 const thisBlock = wp.data.select( 'core/block-editor' ).getBlocksByClientId( clientId )[ 0 ];
75 const clonedBlock = cloneBlock( thisBlock );
76
77 wp.data.dispatch( 'core/block-editor' ).insertBlocks( clonedBlock, undefined, parentGridId );
78 } }
79 />
80 </Tooltip>
81 </Toolbar>
82
83 <Toolbar>
84 <Tooltip text={ __( 'Select Parent Grid', 'generateblocks' ) }>
85 <Button
86 className="gblocks-block-control-icon"
87 icon={ getIcon( 'grid' ) }
88 onClick={ () => {
89 wp.data.dispatch( 'core/block-editor' ).selectBlock( parentGridId );
90 } }
91 />
92 </Tooltip>
93 </Toolbar>
94 </BlockControls>
95 }
96
97 <BlockEdit { ...props } />
98 </Fragment>
99 );
100 };
101 }, 'withAdvancedControls' );
102
103 addFilter(
104 'editor.BlockEdit',
105 'generateblocks/container-block-controls',
106 withAdvancedControls
107 );
108