@@ -10,6 +10,7 @@ import { once } from 'lodash';
10
10
* Internal dependencies
11
11
*/
12
12
import { applyAPIMiddleware } from './api-middleware' ;
13
+ import { isEnabled } from 'config' ;
13
14
import debugFactory from 'debug' ;
14
15
15
16
const debug = debugFactory ( 'calypso:gutenberg' ) ;
@@ -20,8 +21,16 @@ const WPCOM_UNSUPPORTED_CORE_BLOCKS = [
20
21
'core/file' , // see D19851 for more details.
21
22
] ;
22
23
23
- // We need to ensure that his function is executed only once to avoid
24
- // registering core blocks and applying middleware twice.
24
+ const loadA8CExtensions = ( ) => {
25
+ require ( '../extensions/classic-block/editor' ) ;
26
+
27
+ if ( isEnabled ( 'gutenberg/block/jetpack-preset' ) ) {
28
+ require ( 'gutenberg/extensions/presets/jetpack/editor.js' ) ;
29
+ }
30
+ } ;
31
+
32
+ // We need to ensure that his function is executed only once to avoid duplicate
33
+ // block registration, API middleware application etc.
25
34
export const initGutenberg = once ( ( userId , siteSlug ) => {
26
35
debug ( 'Starting Gutenberg editor initialization...' ) ;
27
36
@@ -36,18 +45,14 @@ export const initGutenberg = once( ( userId, siteSlug ) => {
36
45
37
46
// Avoid using top level imports for this since they will statically
38
47
// initialize core-data before required plugins are loaded.
39
- const blockLibrary = require ( '@wordpress/block-library' ) ;
40
- const blocks = require ( '@wordpress/blocks' ) ;
48
+ const { registerCoreBlocks } = require ( '@wordpress/block-library' ) ;
49
+ const { unregisterBlockType , setFreeformContentHandlerName } = require ( '@wordpress/blocks' ) ;
41
50
42
51
debug ( 'Registering core blocks' ) ;
43
- blockLibrary . registerCoreBlocks ( ) ;
52
+ registerCoreBlocks ( ) ;
44
53
45
54
debug ( 'Removing core blocks that are not yet supported in Calypso' ) ;
46
- WPCOM_UNSUPPORTED_CORE_BLOCKS . forEach ( blockName => blocks . unregisterBlockType ( blockName ) ) ;
47
-
48
- debug ( 'Registering Calypso Classic Block handler' ) ;
49
- require ( '../extensions/classic-block/editor' ) ;
50
- blocks . setFreeformContentHandlerName ( 'a8c/classic' ) ;
55
+ WPCOM_UNSUPPORTED_CORE_BLOCKS . forEach ( blockName => unregisterBlockType ( blockName ) ) ;
51
56
52
57
// Needed for list block indent/outdent functionality
53
58
debug ( 'Loading required TinyMCE plugins' ) ;
@@ -59,6 +64,12 @@ export const initGutenberg = once( ( userId, siteSlug ) => {
59
64
debug ( 'Applying API middleware' ) ;
60
65
applyAPIMiddleware ( siteSlug ) ;
61
66
67
+ debug ( 'Loading A8C editor extensions' ) ;
68
+ loadA8CExtensions ( ) ;
69
+
70
+ debug ( 'Registering Calypso Classic Block handler' ) ;
71
+ setFreeformContentHandlerName ( 'a8c/classic' ) ;
72
+
62
73
debug ( 'Gutenberg editor initialization complete.' ) ;
63
74
64
75
return require ( 'gutenberg/editor/main' ) . default ;
0 commit comments