-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
69 lines (63 loc) · 1.74 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
/**
* WordPress dependencies
*/
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
import {
registerCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { render } from '@wordpress/element';
/**
* Internal dependencies
*/
import './plugins';
import './hooks';
import './store';
import Editor from './components/editor';
const fetchLinkSuggestions = ( search, { perPage = 20 } = {} ) =>
apiFetch( {
path: addQueryArgs( '/wp/v2/search', {
per_page: perPage,
search,
type: 'post',
subtype: 'post',
} ),
} )
.then( ( posts ) =>
Promise.all(
posts.map( ( post ) =>
apiFetch( { url: post._links.self[ 0 ].href } )
)
)
)
.then( ( posts ) =>
posts.map( ( post ) => ( {
url: post.link,
type: post.type,
id: post.id,
slug: post.slug,
title: post.title.rendered || __( '(no title)' ),
} ) )
);
/**
* Initializes the site editor screen.
*
* @param {string} id ID of the root element to render the screen in.
* @param {Object} settings Editor settings.
*/
export function initialize( id, settings ) {
settings.__experimentalFetchLinkSuggestions = fetchLinkSuggestions;
settings.__experimentalSpotlightEntityBlocks = [ 'core/template-part' ];
registerCoreBlocks();
if ( process.env.GUTENBERG_PHASE === 2 ) {
__experimentalRegisterExperimentalCoreBlocks( true );
}
render(
<Editor initialSettings={ settings } />,
document.getElementById( id )
);
}
export { default as __experimentalMainDashboardButton } from './components/main-dashboard-button';
export { default as __experimentalNavigationToggle } from './components/navigation-sidebar/navigation-toggle';