Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework: Per-block script bundles, server enqueues #4841

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blocks/api/raw-handling/test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import path from 'path';
/**
* Internal dependencies
*/
import { registerCoreBlocks } from '../../../../library';
import rawHandler from '../../index';
import serialize from '../../../serializer';

Expand All @@ -24,7 +23,8 @@ describe( 'raw handling: integration', () => {
beforeAll( () => {
// Load all hooks that modify blocks
require( 'blocks/hooks' );
registerCoreBlocks();

// TODO: Need to load/register core blocks. Maybe requireIndex ?
} );

types.forEach( ( type ) => {
Expand Down
1 change: 0 additions & 1 deletion blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import './hooks';
// Blocks are inferred from the HTML source of a post through a parsing mechanism
// and then stored as objects in state, from which it is then rendered for editing.
export * from './api';
export { registerCoreBlocks } from './library';
export { default as AlignmentToolbar } from './alignment-toolbar';
export { default as BlockAlignmentToolbar } from './block-alignment-toolbar';
export { default as BlockControls } from './block-controls';
Expand Down
91 changes: 0 additions & 91 deletions blocks/library/index.js

This file was deleted.

14 changes: 9 additions & 5 deletions blocks/library/paragraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
createBlock,
registerBlockType,
setDefaultBlockName,
} from '@wordpress/blocks';
import { concatChildren, Component } from '@wordpress/element';
import { Autocomplete, PanelBody, PanelColor, withFallbackStyles } from '@wordpress/components';

Expand All @@ -15,7 +20,6 @@ import { Autocomplete, PanelBody, PanelColor, withFallbackStyles } from '@wordpr
*/
import './editor.scss';
import './style.scss';
import { createBlock } from '../../api';
import { blockAutocompleter, userAutocompleter } from '../../autocompleters';
import AlignmentToolbar from '../../alignment-toolbar';
import BlockAlignmentToolbar from '../../block-alignment-toolbar';
Expand Down Expand Up @@ -192,9 +196,7 @@ class ParagraphBlock extends Component {
}
}

export const name = 'core/paragraph';

export const settings = {
registerBlockType( 'core/paragraph', {
title: __( 'Paragraph' ),

description: __( 'This is a simple text only block for adding a single paragraph of content.' ),
Expand Down Expand Up @@ -283,4 +285,6 @@ export const settings = {

return <p style={ styles } className={ className ? className : undefined }>{ content }</p>;
},
};
} );

setDefaultBlockName( 'core/paragraph' );
16 changes: 16 additions & 0 deletions blocks/library/paragraph/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Server-side rendering of the `core/paragraph` block.
*
* @package gutenberg
*/

function register_core_paragraph_block() {
wp_register_script( 'core-paragraph-block', gutenberg_url( '/build/__block_paragraph.js' ) );

register_block_type( 'core/paragraph', array(
'editor_script' => 'core-paragraph-block',
) );
}

add_action( 'init', 'register_core_paragraph_block' );
4 changes: 2 additions & 2 deletions blocks/test/full-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { format } from 'util';
/**
* Internal dependencies
*/
import { registerCoreBlocks } from '../library';
import parse from '../api/parser';
import { parse as grammarParse } from '../api/post.pegjs';
import serialize from '../api/serializer';
Expand Down Expand Up @@ -94,7 +93,8 @@ describe( 'full post content fixture', () => {

// Load all hooks that modify blocks
require( 'blocks/hooks' );
registerCoreBlocks();

// TODO: Need to load/register core blocks. Maybe requireIndex ?
} );

fileBasenames.forEach( f => {
Expand Down
4 changes: 2 additions & 2 deletions editor/components/document-outline/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { shallow } from 'enzyme';
/**
* WordPress dependencies
*/
import { createBlock, registerCoreBlocks } from '@wordpress/blocks';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { DocumentOutline } from '../';

describe( 'DocumentOutline', () => {
registerCoreBlocks();
// TODO: Need to load/register core blocks. Maybe requireIndex ?

const paragraph = createBlock( 'core/paragraph' );
const headingH1 = createBlock( 'core/heading', {
Expand Down
3 changes: 1 addition & 2 deletions editor/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import deepFreeze from 'deep-freeze';
* WordPress dependencies
*/
import {
registerCoreBlocks,
registerBlockType,
unregisterBlockType,
} from '@wordpress/blocks';
Expand Down Expand Up @@ -958,7 +957,7 @@ describe( 'state', () => {

describe( 'preferences()', () => {
beforeAll( () => {
registerCoreBlocks();
// TODO: Need to load/register core blocks (or at least some demo blocks). Maybe requireIndex ?
} );

it( 'should apply all defaults', () => {
Expand Down
4 changes: 2 additions & 2 deletions editor/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { union } from 'lodash';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { registerBlockType, unregisterBlockType, registerCoreBlocks, getBlockTypes } from '@wordpress/blocks';
import { registerBlockType, unregisterBlockType, getBlockTypes } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -1949,7 +1949,7 @@ describe( 'selectors', () => {

describe( 'getRecentInserterItems', () => {
beforeAll( () => {
registerCoreBlocks();
// TODO: Need to load/register core blocks (or at least some demo blocks). Maybe requireIndex ?
} );

it( 'should return the 8 most recently used blocks', () => {
Expand Down
43 changes: 21 additions & 22 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,27 @@ function gutenberg_register_scripts_and_styles() {
// Editor Scripts.
wp_register_script(
'wp-data',
gutenberg_url( 'data/build/index.js' ),
gutenberg_url( 'build/data.js' ),
array( 'wp-element' ),
filemtime( gutenberg_dir_path() . 'data/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/data.js' )
);
wp_register_script(
'wp-utils',
gutenberg_url( 'utils/build/index.js' ),
gutenberg_url( 'build/utils.js' ),
array(),
filemtime( gutenberg_dir_path() . 'utils/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/utils.js' )
);
wp_register_script(
'wp-hooks',
gutenberg_url( 'hooks/build/index.js' ),
gutenberg_url( 'build/hooks.js' ),
array(),
filemtime( gutenberg_dir_path() . 'hooks/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/hooks.js' )
);
wp_register_script(
'wp-date',
gutenberg_url( 'date/build/index.js' ),
gutenberg_url( 'build/date.js' ),
array( 'moment' ),
filemtime( gutenberg_dir_path() . 'date/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/date.js' )
);
global $wp_locale;
wp_add_inline_script( 'wp-date', 'window._wpDateSettings = ' . wp_json_encode( array(
Expand Down Expand Up @@ -128,27 +128,27 @@ function gutenberg_register_scripts_and_styles() {
) ), 'before' );
wp_register_script(
'wp-i18n',
gutenberg_url( 'i18n/build/index.js' ),
gutenberg_url( 'build/i18n.js' ),
array(),
filemtime( gutenberg_dir_path() . 'i18n/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/i18n.js' )
);
wp_register_script(
'wp-element',
gutenberg_url( 'element/build/index.js' ),
gutenberg_url( 'build/element.js' ),
array( 'react', 'react-dom', 'react-dom-server' ),
filemtime( gutenberg_dir_path() . 'element/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/element.js' )
);
wp_register_script(
'wp-components',
gutenberg_url( 'components/build/index.js' ),
gutenberg_url( 'build/components.js' ),
array( 'wp-element', 'wp-i18n', 'wp-utils', 'wp-hooks', 'wp-api-request', 'moment' ),
filemtime( gutenberg_dir_path() . 'components/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/components.js' )
);
wp_register_script(
'wp-blocks',
gutenberg_url( 'blocks/build/index.js' ),
gutenberg_url( 'build/blocks.js' ),
array( 'wp-element', 'wp-components', 'wp-utils', 'wp-hooks', 'wp-i18n', 'tinymce-latest', 'tinymce-latest-lists', 'tinymce-latest-paste', 'tinymce-latest-table', 'media-views', 'media-models', 'shortcode' ),
filemtime( gutenberg_dir_path() . 'blocks/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/blocks.js' )
);
wp_add_inline_script(
'wp-blocks',
Expand All @@ -161,16 +161,16 @@ function gutenberg_register_scripts_and_styles() {

wp_register_script(
'wp-editor',
gutenberg_url( 'editor/build/index.js' ),
gutenberg_url( 'build/editor.js' ),
array( 'postbox', 'jquery', 'wp-api', 'wp-data', 'wp-date', 'wp-i18n', 'wp-blocks', 'wp-element', 'wp-components', 'wp-utils', 'word-count', 'editor' ),
filemtime( gutenberg_dir_path() . 'editor/build/index.js' )
filemtime( gutenberg_dir_path() . 'build/editor.js' )
);

wp_register_script(
'wp-edit-post',
gutenberg_url( 'edit-post/build/index.js' ),
gutenberg_url( 'build/editPost.js' ),
array( 'jquery', 'heartbeat', 'wp-element', 'wp-components', 'wp-editor', 'wp-i18n', 'wp-date', 'wp-utils', 'wp-data' ),
filemtime( gutenberg_dir_path() . 'edit-post/build/index.js' ),
filemtime( gutenberg_dir_path() . 'build/editPost.js' ),
true
);

Expand Down Expand Up @@ -897,8 +897,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
$script .= sprintf( 'var editorSettings = %s;', wp_json_encode( $editor_settings ) );
$script .= <<<JS
window._wpLoadGutenbergEditor = wp.api.init().then( function() {
wp.blocks.registerCoreBlocks();
return wp[ 'edit-post' ].initializeEditor( 'editor', window._wpGutenbergPost, editorSettings );
return wp.editPost.initializeEditor( 'editor', window._wpGutenbergPost, editorSettings );
} );
JS;
$script .= '} )();';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/setup-wp-aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ global.wp = {
'date',
'editor',
'data',
'edit-post',
'editPost',
].forEach( entryPointName => {
Object.defineProperty( global.wp, entryPointName, {
get: () => require( entryPointName ),
Expand Down
Loading