-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (55 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { createHigherOrderComponent } from '@wordpress/compose';
import { InspectorControls } from '@wordpress/block-editor';
import { Fragment } from '@wordpress/element';
/**
* Extend core cover block settings
*
* @see https://developer.wordpress.org/block-editor/developers/filters/block-filters/#blocks-registerblocktype
*/
const registerBlockTypeHook = {
hookName: 'blocks.registerBlockType',
namespace: 'ups/extend/cover-settings',
callback(settings, name) {
if (name !== 'core/cover') {
return settings;
}
const updatedSettings = Object.assign({}, settings, {
supports: Object.assign({}, settings.supports, {
// Only allow center, wide, and full alignment options
align: ['center', 'wide', 'full'],
}),
});
return updatedSettings;
},
};
/**
* Extend core cover block edit component
*
* @see https://developer.wordpress.org/block-editor/developers/filters/block-filters/#editor-blockedit
*/
const blockEditHook = {
hookName: 'editor.BlockEdit',
namespace: 'ups/extend/cover-edit',
callback: createHigherOrderComponent(
BlockEdit => props => {
const { name } = props;
// Do nothing if it's another block than the cover.
if (name !== 'core/cover') {
return <BlockEdit {...props} />;
}
// Add a div above the Cover settings panel
// so we can target the BlockEdit component with CSS
return (
<Fragment>
<InspectorControls>
<div className="block-editor-cover"></div>
</InspectorControls>
<BlockEdit {...props} />
</Fragment>
);
},
'withInspectorControl',
),
};
export const hooks = [registerBlockTypeHook, blockEditHook];
export const name = 'cover';