Skip to content

Commit

Permalink
WP.com block editor: Exclude WP.com features from Jetpack sites (#14230)
Browse files Browse the repository at this point in the history
In order to don't expose some `@automattic/wpcom-block-editor` features to Jetpack sites that are specific of WP.com sites, the `common` bundle has been split into two new bundles `default` and `wpcom` in Automattic/wp-calypso#38248.

This PRs changes the WordPress.com block editor module to replace the `common` bundle with the new  `default` and to load `wpcom` only when the site is a WP.com site (Atomic).
  • Loading branch information
mmtr authored Dec 20, 2019
1 parent 8537cdd commit b3651ff
Showing 1 changed file with 51 additions and 53 deletions.
104 changes: 51 additions & 53 deletions modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ private function __construct() {
}

add_action( 'login_init', array( $this, 'allow_block_editor_login' ), 1 );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts' ), 9 );
add_action( 'enqueue_block_assets', array( $this, 'enqueue_styles' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ), 9 );
add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ) );
add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugins' ) );
}

Expand Down Expand Up @@ -253,37 +253,32 @@ public function filter_salt( $salt, $scheme ) {
}

/**
* Enqueue the scripts for the WordPress.com block editor integration.
* Enqueues the WordPress.com block editor integration assets for the editor.
*/
public function enqueue_scripts() {
public function enqueue_block_editor_assets() {
$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$version = gmdate( 'Ymd' );

$src_common = $debug
? '//widgets.wp.com/wpcom-block-editor/common.js?minify=false'
: '//widgets.wp.com/wpcom-block-editor/common.min.js';

wp_enqueue_script(
'wpcom-block-editor-common',
$src_common,
'wpcom-block-editor-default-editor-script',
$debug
? '//widgets.wp.com/wpcom-block-editor/default.editor.js?minify=false'
: '//widgets.wp.com/wpcom-block-editor/default.editor.min.js',
array(
'jquery',
'lodash',
'wp-blocks',
'wp-compose',
'wp-data',
'wp-dom-ready',
'wp-editor',
'wp-nux',
'wp-plugins',
'wp-polyfill',
'wp-element',
'wp-rich-text',
),
$version,
true
);

wp_localize_script(
'wpcom-block-editor-common',
'wpcom-block-editor-default-editor-script',
'wpcomGutenberg',
array(
'switchToClassic' => array(
Expand All @@ -298,14 +293,30 @@ public function enqueue_scripts() {
)
);

if ( $this->is_iframed_block_editor() ) {
$src_calypso_iframe_bridge = $debug
? '//widgets.wp.com/wpcom-block-editor/calypso-iframe-bridge-server.js?minify=false'
: '//widgets.wp.com/wpcom-block-editor/calypso-iframe-bridge-server.min.js';
if ( jetpack_is_atomic_site() ) {
wp_enqueue_script(
'wpcom-block-editor-wpcom-editor-script',
$debug
? '//widgets.wp.com/wpcom-block-editor/wpcom.editor.js?minify=false'
: '//widgets.wp.com/wpcom-block-editor/wpcom.editor.min.js',
array(
'lodash',
'wp-blocks',
'wp-data',
'wp-dom-ready',
'wp-plugins',
),
$version,
true
);
}

if ( $this->is_iframed_block_editor() ) {
wp_enqueue_script(
'wpcom-block-editor-calypso-iframe-bridge',
$src_calypso_iframe_bridge,
'wpcom-block-editor-calypso-editor-script',
$debug
? '//widgets.wp.com/wpcom-block-editor/calypso.editor.js?minify=false'
: '//widgets.wp.com/wpcom-block-editor/calypso.editor.min.js',
array(
'calypsoify_wpadminmods_js',
'jquery',
Expand All @@ -314,43 +325,31 @@ public function enqueue_scripts() {
'wp-blocks',
'wp-data',
'wp-hooks',
'wp-polyfill',
'wp-tinymce',
'wp-url',
),
$version,
true
);

wp_enqueue_style(
'wpcom-block-editor-calypso-editor-styles',
$debug
? '//widgets.wp.com/wpcom-block-editor/calypso.editor.css?minify=false'
: '//widgets.wp.com/wpcom-block-editor/calypso.editor.min.css',
array(),
$version
);
}
}

/**
* Enqueue WP.com block editor common styles.
* Enqueues the WordPress.com block editor integration assets for both editor and front-end.
*/
public function enqueue_styles() {
// Enqueue only for the block editor in WP Admin.
global $pagenow;
if ( is_admin() && ! in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
return;
}

// Enqueue on the front-end only if justified blocks are present.
if ( ! is_admin() && ! $this->has_justified_block() ) {
return;
}

$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$version = gmdate( 'Ymd' );

$src_styles = $debug
? '//widgets.wp.com/wpcom-block-editor/common.css?minify=false'
: '//widgets.wp.com/wpcom-block-editor/common.min.css';
wp_enqueue_style(
'wpcom-block-editor-styles',
$src_styles,
array(),
$version
);
public function enqueue_block_assets() {
// These styles are manually copied from //widgets.wp.com/wpcom-block-editor/default.view.css in order to
// improve the performance by avoiding an extra network request to download the CSS file on every page.
wp_add_inline_style( 'wp-block-library', '.has-text-align-justify{text-align:justify;}' );
}

/**
Expand Down Expand Up @@ -379,15 +378,14 @@ public function has_justified_block() {
*/
public function add_tinymce_plugins( $plugin_array ) {
if ( $this->is_iframed_block_editor() ) {
$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$src_calypso_tinymce = $debug
? '//widgets.wp.com/wpcom-block-editor/calypso-tinymce.js?minify=false'
: '//widgets.wp.com/wpcom-block-editor/calypso-tinymce.min.js';
$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;

$plugin_array['gutenberg-wpcom-iframe-media-modal'] = add_query_arg(
'v',
gmdate( 'YW' ),
$src_calypso_tinymce
$debug
? '//widgets.wp.com/wpcom-block-editor/calypso.tinymce.js?minify=false'
: '//widgets.wp.com/wpcom-block-editor/calypso.tinymce.min.js'
);
}

Expand Down

0 comments on commit b3651ff

Please sign in to comment.