-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
103 lines (92 loc) · 2.97 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* WordPress dependencies
*/
import { render } from '@wordpress/element';
import {
registerCoreBlocks,
__experimentalGetCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import {
registerLegacyWidgetBlock,
registerLegacyWidgetVariations,
registerWidgetGroupBlock,
} from '@wordpress/widgets';
import {
setFreeformContentHandlerName,
store as blocksStore,
} from '@wordpress/blocks';
import { dispatch } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';
/**
* Internal dependencies
*/
import CustomizeWidgets from './components/customize-widgets';
import getSidebarSection from './controls/sidebar-section';
import getSidebarControl from './controls/sidebar-control';
import './filters';
const { wp } = window;
const DISABLED_BLOCKS = [
'core/more',
'core/block',
'core/freeform',
'core/template-part',
];
const ENABLE_EXPERIMENTAL_FSE_BLOCKS = false;
/**
* Initializes the widgets block editor in the customizer.
*
* @param {string} editorName The editor name.
* @param {Object} blockEditorSettings Block editor settings.
*/
export function initialize( editorName, blockEditorSettings ) {
dispatch( preferencesStore ).setDefaults( 'core/customize-widgets', {
fixedToolbar: false,
welcomeGuide: true,
} );
dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();
const coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => {
return ! (
DISABLED_BLOCKS.includes( block.name ) ||
block.name.startsWith( 'core/post' ) ||
block.name.startsWith( 'core/query' ) ||
block.name.startsWith( 'core/site' ) ||
block.name.startsWith( 'core/navigation' )
);
} );
registerCoreBlocks( coreBlocks );
registerLegacyWidgetBlock();
if ( process.env.IS_GUTENBERG_PLUGIN ) {
__experimentalRegisterExperimentalCoreBlocks( {
enableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS,
} );
}
registerLegacyWidgetVariations( blockEditorSettings );
registerWidgetGroupBlock();
// As we are unregistering `core/freeform` to avoid the Classic block, we must
// replace it with something as the default freeform content handler. Failure to
// do this will result in errors in the default block parser.
// see: https://github.com/WordPress/gutenberg/issues/33097
setFreeformContentHandlerName( 'core/html' );
const SidebarControl = getSidebarControl( blockEditorSettings );
wp.customize.sectionConstructor.sidebar = getSidebarSection();
wp.customize.controlConstructor.sidebar_block_editor = SidebarControl;
const container = document.createElement( 'div' );
document.body.appendChild( container );
wp.customize.bind( 'ready', () => {
const sidebarControls = [];
wp.customize.control.each( ( control ) => {
if ( control instanceof SidebarControl ) {
sidebarControls.push( control );
}
} );
render(
<CustomizeWidgets
api={ wp.customize }
sidebarControls={ sidebarControls }
blockEditorSettings={ blockEditorSettings }
/>,
container
);
} );
}