From b5be74e0c6bfdc5d415ca913c60fc27171324aa0 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 26 Apr 2018 17:23:33 +0200 Subject: [PATCH 1/2] Framework: Make sure block assets are always registered before wp-edit-post script --- lib/client-assets.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 1e4732d1431a9..c176884abfb90 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -834,6 +834,18 @@ function gutenberg_editor_scripts_and_styles( $hook ) { // to disable it outright. wp_enqueue_script( 'heartbeat' ); + /** + * Fires after block assets have been enqueued for the editing interface. + * + * Call `add_action` on any hook before 'admin_enqueue_scripts'. + * + * In the function call you supply, simply use `wp_enqueue_script` and + * `wp_enqueue_style` to add your functionality to the Gutenberg editor. + * + * @since 0.4.0 + */ + do_action( 'enqueue_block_editor_assets' ); + // Ignore Classic Editor's `rich_editing` user option, aka "Disable visual // editor". Forcing this to be true guarantees that TinyMCE and its plugins // are available in Gutenberg. Fixes @@ -999,16 +1011,4 @@ function gutenberg_editor_scripts_and_styles( $hook ) { * Styles */ wp_enqueue_style( 'wp-edit-post' ); - - /** - * Fires after block assets have been enqueued for the editing interface. - * - * Call `add_action` on any hook before 'admin_enqueue_scripts'. - * - * In the function call you supply, simply use `wp_enqueue_script` and - * `wp_enqueue_style` to add your functionality to the Gutenberg editor. - * - * @since 0.4.0 - */ - do_action( 'enqueue_block_editor_assets' ); } From 0ca49c94707f9cd58c77ef19b4b80a4adeeaea72 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 27 Apr 2018 19:50:35 +0200 Subject: [PATCH 2/2] Framework: Use domReady to make sure that all blocks are properly registered --- edit-post/index.js | 32 ++++++++++++++++++++------------ lib/client-assets.php | 29 +++++++++++++++-------------- package-lock.json | 8 ++++---- package.json | 1 + 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/edit-post/index.js b/edit-post/index.js index 19cfe5d6b024f..8858c482c037a 100644 --- a/edit-post/index.js +++ b/edit-post/index.js @@ -6,6 +6,8 @@ import { get, isString, some } from 'lodash'; /** * WordPress dependencies */ +import { registerCoreBlocks } from '@wordpress/core-blocks'; +import domReady from '@wordpress/dom-ready'; import { render, unmountComponentAtNode } from '@wordpress/element'; import { deprecated } from '@wordpress/utils'; @@ -59,9 +61,6 @@ export function reinitializeEditor( target, settings ) { * @return {Object} Editor interface. */ export function initializeEditor( id, post, settings ) { - const target = document.getElementById( id ); - const reboot = reinitializeEditor.bind( null, target, settings ); - if ( 'production' !== process.env.NODE_ENV ) { // Remove with 3.0 release. window.console.info( @@ -84,16 +83,25 @@ export function initializeEditor( id, post, settings ) { ); } - render( - , - target - ); + return new Promise( ( resolve ) => { + domReady( () => { + const target = document.getElementById( id ); + const reboot = reinitializeEditor.bind( null, target, settings ); + + registerCoreBlocks(); + + render( + , + target + ); - return { - initializeMetaBoxes( metaBoxes ) { - store.dispatch( initializeMetaBoxState( metaBoxes ) ); - }, - }; + resolve( { + initializeMetaBoxes( metaBoxes ) { + store.dispatch( initializeMetaBoxState( metaBoxes ) ); + }, + } ); + } ); + } ); } export { default as PluginSidebar } from './components/sidebar/plugin-sidebar'; diff --git a/lib/client-assets.php b/lib/client-assets.php index c176884abfb90..d8e29e9272d9e 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -834,18 +834,6 @@ function gutenberg_editor_scripts_and_styles( $hook ) { // to disable it outright. wp_enqueue_script( 'heartbeat' ); - /** - * Fires after block assets have been enqueued for the editing interface. - * - * Call `add_action` on any hook before 'admin_enqueue_scripts'. - * - * In the function call you supply, simply use `wp_enqueue_script` and - * `wp_enqueue_style` to add your functionality to the Gutenberg editor. - * - * @since 0.4.0 - */ - do_action( 'enqueue_block_editor_assets' ); - // Ignore Classic Editor's `rich_editing` user option, aka "Disable visual // editor". Forcing this to be true guarantees that TinyMCE and its plugins // are available in Gutenberg. Fixes @@ -991,8 +979,9 @@ function gutenberg_editor_scripts_and_styles( $hook ) { $script = '( function() {'; $script .= sprintf( 'var editorSettings = %s;', wp_json_encode( $editor_settings ) ); $script .= <<