-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
130 lines (116 loc) · 3.54 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* WordPress dependencies
*/
import {
registerBlockType,
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
setFreeformContentHandlerName,
store as blocksStore,
} from '@wordpress/blocks';
import { dispatch } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';
import { StrictMode, createRoot } from '@wordpress/element';
import {
registerCoreBlocks,
__experimentalGetCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
import {
registerLegacyWidgetBlock,
registerLegacyWidgetVariations,
registerWidgetGroupBlock,
} from '@wordpress/widgets';
import { store as preferencesStore } from '@wordpress/preferences';
/**
* Internal dependencies
*/
import './store';
import './filters';
import * as widgetArea from './blocks/widget-area';
import Layout from './components/layout';
import {
ALLOW_REUSABLE_BLOCKS,
ENABLE_EXPERIMENTAL_FSE_BLOCKS,
} from './constants';
const disabledBlocks = [
'core/more',
'core/freeform',
'core/template-part',
...( ALLOW_REUSABLE_BLOCKS ? [] : [ 'core/block' ] ),
];
/**
* Initializes the block editor in the widgets screen.
*
* @param {string} id ID of the root element to render the screen in.
* @param {Object} settings Block editor settings.
*/
export function initializeEditor( id, settings ) {
const target = document.getElementById( id );
const root = createRoot( target );
const coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => {
return ! (
disabledBlocks.includes( block.name ) ||
block.name.startsWith( 'core/post' ) ||
block.name.startsWith( 'core/query' ) ||
block.name.startsWith( 'core/site' ) ||
block.name.startsWith( 'core/navigation' )
);
} );
dispatch( preferencesStore ).setDefaults( 'core/edit-widgets', {
fixedToolbar: false,
welcomeGuide: true,
showBlockBreadcrumbs: true,
themeStyles: true,
} );
dispatch( blocksStore ).reapplyBlockTypeFilters();
registerCoreBlocks( coreBlocks );
registerLegacyWidgetBlock();
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
__experimentalRegisterExperimentalCoreBlocks( {
enableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS,
} );
}
registerLegacyWidgetVariations( settings );
registerBlock( widgetArea );
registerWidgetGroupBlock();
settings.__experimentalFetchLinkSuggestions = ( search, searchOptions ) =>
fetchLinkSuggestions( search, searchOptions, settings );
// 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' );
root.render(
<StrictMode>
<Layout blockEditorSettings={ settings } />
</StrictMode>
);
return root;
}
/**
* Compatibility export under the old `initialize` name.
*/
export const initialize = initializeEditor;
export function reinitializeEditor() {
deprecated( 'wp.editWidgets.reinitializeEditor', {
since: '6.2',
version: '6.3',
} );
}
/**
* Function to register an individual block.
*
* @param {Object} block The block to be registered.
*/
const registerBlock = ( block ) => {
if ( ! block ) {
return;
}
const { metadata, settings, name } = block;
if ( metadata ) {
unstable__bootstrapServerSideBlockDefinitions( { [ name ]: metadata } );
}
registerBlockType( name, settings );
};
export { store } from './store';