-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (40 loc) · 1.47 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
import { createHigherOrderComponent } from '@wordpress/compose';
/**
* Extend core gallery block edit component
*
* @see https://developer.wordpress.org/block-editor/developers/filters/block-filters/#editor-blockedit
*/
const blockEditHook = {
hookName: 'editor.BlockEdit',
namespace: 'ups/extend/video-edit',
callback: createHigherOrderComponent(
BlockEdit => props => {
const { name, attributes, setAttributes } = props;
if (name === 'core/video') {
// Set the default video settings (hide controls & autoplay on loop)
// WordPress has no inherent way to set defaults, and this function
// runs every time the block changes, so we only set the attributes
// if they are Undefined (read: not already set).
if (attributes.autoplay === undefined) {
setAttributes({ autoplay: true });
}
// Controls is enabled by default, so instead we check the existence of
// one of the other settings.
if (attributes.loop === undefined) {
setAttributes({ loop: true });
setAttributes({ controls: false });
}
if (attributes.muted === undefined) {
setAttributes({ muted: true });
}
if (attributes.playsInline === undefined) {
setAttributes({ playsInline: true });
}
}
return <BlockEdit {...props} />;
},
'withAttributesOverride',
),
};
export const hooks = [blockEditHook];
export const name = 'video';