UNPKG

4.16 kBJavaScriptView Raw
1/**
2 * WordPress dependencies
3 */
4import '@wordpress/core-data';
5import '@wordpress/block-editor';
6import '@wordpress/editor';
7import '@wordpress/nux';
8import '@wordpress/viewport';
9import '@wordpress/notices';
10import { registerCoreBlocks } from '@wordpress/block-library';
11import { render, unmountComponentAtNode } from '@wordpress/element';
12import { dispatch } from '@wordpress/data';
13
14/**
15 * Internal dependencies
16 */
17import './hooks';
18import './plugins';
19import './store';
20import Editor from './editor';
21
22/**
23 * Reinitializes the editor after the user chooses to reboot the editor after
24 * an unhandled error occurs, replacing previously mounted editor element using
25 * an initial state from prior to the crash.
26 *
27 * @param {Object} postType Post type of the post to edit.
28 * @param {Object} postId ID of the post to edit.
29 * @param {Element} target DOM node in which editor is rendered.
30 * @param {?Object} settings Editor settings object.
31 * @param {Object} initialEdits Programmatic edits to apply initially, to be
32 * considered as non-user-initiated (bypass for
33 * unsaved changes prompt).
34 */
35export function reinitializeEditor( postType, postId, target, settings, initialEdits ) {
36 unmountComponentAtNode( target );
37 const reboot = reinitializeEditor.bind( null, postType, postId, target, settings, initialEdits );
38
39 render(
40 <Editor
41 settings={ settings }
42 onError={ reboot }
43 postId={ postId }
44 postType={ postType }
45 initialEdits={ initialEdits }
46 recovery
47 />,
48 target
49 );
50}
51
52/**
53 * Initializes and returns an instance of Editor.
54 *
55 * The return value of this function is not necessary if we change where we
56 * call initializeEditor(). This is due to metaBox timing.
57 *
58 * @param {string} id Unique identifier for editor instance.
59 * @param {Object} postType Post type of the post to edit.
60 * @param {Object} postId ID of the post to edit.
61 * @param {?Object} settings Editor settings object.
62 * @param {Object} initialEdits Programmatic edits to apply initially, to be
63 * considered as non-user-initiated (bypass for
64 * unsaved changes prompt).
65 */
66export function initializeEditor( id, postType, postId, settings, initialEdits ) {
67 const target = document.getElementById( id );
68 const reboot = reinitializeEditor.bind( null, postType, postId, target, settings, initialEdits );
69
70 registerCoreBlocks();
71
72 // Show a console log warning if the browser is not in Standards rendering mode.
73 const documentMode = document.compatMode === 'CSS1Compat' ? 'Standards' : 'Quirks';
74 if ( documentMode !== 'Standards' ) {
75 // eslint-disable-next-line no-console
76 console.warn( "Your browser is using Quirks Mode. \nThis can cause rendering issues such as blocks overlaying meta boxes in the editor. Quirks Mode can be triggered by PHP errors or HTML code appearing before the opening <!DOCTYPE html>. Try checking the raw page source or your site's PHP error log and resolving errors there, removing any HTML before the doctype, or disabling plugins." );
77 }
78
79 dispatch( 'core/nux' ).triggerGuide( [
80 'core/editor.inserter',
81 'core/editor.settings',
82 'core/editor.preview',
83 'core/editor.publish',
84 ] );
85
86 render(
87 <Editor
88 settings={ settings }
89 onError={ reboot }
90 postId={ postId }
91 postType={ postType }
92 initialEdits={ initialEdits }
93 />,
94 target
95 );
96}
97
98export { default as PluginBlockSettingsMenuItem } from './components/block-settings-menu/plugin-block-settings-menu-item';
99export { default as PluginMoreMenuItem } from './components/header/plugin-more-menu-item';
100export { default as PluginPostPublishPanel } from './components/sidebar/plugin-post-publish-panel';
101export { default as PluginPostStatusInfo } from './components/sidebar/plugin-post-status-info';
102export { default as PluginPrePublishPanel } from './components/sidebar/plugin-pre-publish-panel';
103export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
104export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';