-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathblocks.js
More file actions
64 lines (56 loc) · 1.84 KB
/
blocks.js
File metadata and controls
64 lines (56 loc) · 1.84 KB
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
/**
* This is the file that Webpack is compiling into editor_blocks.js
*/
/**
* Internal dependencies
*/
import './format-types'
import './plugins'
import './compatibility'
import './disabled-blocks'
/**
* External dependencies
*/
import { i18n } from 'stackable'
import {
addStackableBlockCategory,
registerBlockType,
} from '~stackable/util'
import { withVisualGuideContext } from '~stackable/higher-order'
/**
* WordPress dependencies
*/
import { getBlockType } from '@wordpress/blocks'
import { __ } from '@wordpress/i18n'
import { addFilter } from '@wordpress/hooks'
// Register our block category.
addStackableBlockCategory()
// Register all the blocks found
const importAllAndRegister = r => {
r.keys().forEach( key => {
const { settings } = r( key )
if ( ! settings ) {
return
}
const { name } = settings
// Labels of the block aren't translated automatically by WordPress, we need to manually do this.
// @see https://github.com/WordPress/gutenberg/issues/23636
settings.title = __( settings.title, i18n ) // eslint-disable-line @wordpress/i18n-no-variables
if ( settings.description ) {
settings.description = __( settings.description, i18n ) // eslint-disable-line @wordpress/i18n-no-variables
}
if ( settings.keywords ) {
settings.keywords = settings.keywords.map( keyword => __( keyword, i18n ) ) // eslint-disable-line @wordpress/i18n-no-variables
}
// Register the block if it's not already registered and not disabled.
if ( ! getBlockType( name ) ) {
registerBlockType( name, settings )
}
} )
}
// Add some HOCs that should be applied to all our blocks.
addFilter( 'stackable.registerBlockType.edit', 'stackable', edit => {
// This allows controls to show highlighted areas in the block.
return withVisualGuideContext( edit )
} )
importAllAndRegister( require.context( './block', true, /index\.js$/ ) )