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

Move the Classic block to the packages #10397

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/build-plugin-zip.sh
Expand Up @@ -120,7 +120,6 @@ status "Creating archive... 🎁"
zip -r gutenberg.zip \
gutenberg.php \
lib/*.php \
block-library/*/*.php \
packages/block-library/src/*/*.php \
packages/block-serialization-default-parser/*.php \
post-content.php \
Expand Down
3 changes: 0 additions & 3 deletions bin/get-server-blocks.php
Expand Up @@ -30,9 +30,6 @@
require_once dirname( dirname( __FILE__ ) ) . '/lib/client-assets.php';

// Register server-side code for individual blocks.
foreach ( glob( dirname( dirname( __FILE__ ) ) . '/block-library/*/index.php' ) as $block_logic ) {
require_once $block_logic;
}
foreach ( glob( dirname( dirname( __FILE__ ) ) . '/packages/block-library/src/*/index.php' ) as $block_logic ) {
require_once $block_logic;
}
Expand Down
1 change: 0 additions & 1 deletion block-library/editor.scss

This file was deleted.

101 changes: 0 additions & 101 deletions block-library/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions block-library/index.native.js

This file was deleted.

1 change: 0 additions & 1 deletion block-library/style.scss

This file was deleted.

1 change: 0 additions & 1 deletion block-library/theme.scss

This file was deleted.

4 changes: 2 additions & 2 deletions lib/client-assets.php
Expand Up @@ -731,14 +731,14 @@ function gutenberg_register_scripts_and_styles() {

wp_register_style(
'wp-edit-blocks',
gutenberg_url( 'build/block-library/edit-blocks.css' ),
gutenberg_url( 'build/block-library/editor.css' ),
array(
'wp-components',
'wp-editor',
// Always include visual styles so the editor never appears broken.
'wp-block-library-theme',
),
filemtime( gutenberg_dir_path() . 'build/block-library/edit-blocks.css' )
filemtime( gutenberg_dir_path() . 'build/block-library/editor.css' )
);
wp_style_add_data( 'wp-edit-blocks', 'rtl', 'replace' );

Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/CHANGELOG.md
@@ -1,3 +1,9 @@
## 2.1.0 (Unreleased)

### New Features

- Include the classic block if `wp.oldEditor` is defined.

## 2.0.0 (2018-09-05)

### Breaking Change
Expand Down
Expand Up @@ -5,11 +5,6 @@ import { Component } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { BACKSPACE, DELETE, F10 } from '@wordpress/keycodes';

/**
* Internal dependencies
*/
import './editor.scss';

function isTmceEmpty( editor ) {
// When tinyMce is empty the content seems to be:
// <p><br data-mce-bogus="1"></p>
Expand All @@ -26,7 +21,7 @@ function isTmceEmpty( editor ) {
return /^\n?$/.test( body.innerText || body.textContent );
}

export default class FreeformEdit extends Component {
export default class ClassicEdit extends Component {
constructor( props ) {
super( props );
this.initialize = this.initialize.bind( this );
Expand Down Expand Up @@ -176,7 +171,7 @@ export default class FreeformEdit extends Component {
key="toolbar"
id={ `toolbar-${ clientId }` }
ref={ ( ref ) => this.ref = ref }
className="freeform-toolbar"
className="block-library-classic__toolbar"
onClick={ this.focus }
data-placeholder={ __( 'Classic' ) }
onKeyDown={ this.onToolbarKeyDown }
Expand Down
Expand Up @@ -144,7 +144,7 @@ div[data-type="core/freeform"] .editor-block-contextual-toolbar + div {
padding-top: 0;
}

.freeform-toolbar {
.block-library-classic__toolbar {
width: auto;
margin: 0 #{ -$block-padding };
position: sticky;
Expand Down
Expand Up @@ -3,7 +3,7 @@
exports[`core/freeform block edit matches snapshot 1`] = `
Array [
<div
class="freeform-toolbar"
class="block-library-classic__toolbar"
data-placeholder="Classic"
id="toolbar-undefined"
/>,
Expand Down
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import { name, settings } from '../';
import { blockEditRender } from '../../../packages/block-library/src/test/helpers';
import { blockEditRender } from '../../test/helpers';

describe( 'core/freeform', () => {
test( 'block edit matches snapshot', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Expand Up @@ -7,6 +7,7 @@
@import "./cover-image/editor.scss";
@import "./embed/editor.scss";
@import "./file/editor.scss";
@import "./freeform/editor.scss";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be updated, too

@import "./gallery/editor.scss";
@import "./heading/editor.scss";
@import "./html/editor.scss";
Expand Down
13 changes: 12 additions & 1 deletion packages/block-library/src/index.js
Expand Up @@ -5,6 +5,7 @@ import '@wordpress/core-data';
import {
registerBlockType,
setDefaultBlockName,
setUnknownTypeHandlerName,
} from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -44,6 +45,8 @@ import * as textColumns from './text-columns';
import * as verse from './verse';
import * as video from './video';

import * as classic from './classic';

export const registerCoreBlocks = () => {
[
// Common blocks are grouped at the top to prioritize their display
Expand All @@ -69,6 +72,7 @@ export const registerCoreBlocks = () => {
...embed.common,
...embed.others,
file,
window.wp && window.wp.oldEditor ? classic : null, // Only add the classic block in WP Context
html,
latestComments,
latestPosts,
Expand All @@ -85,9 +89,16 @@ export const registerCoreBlocks = () => {
textColumns,
verse,
video,
].forEach( ( { name, settings } ) => {
].forEach( ( block ) => {
if ( ! block ) {
return;
}
const { name, settings } = block;
registerBlockType( name, settings );
} );

setDefaultBlockName( paragraph.name );
if ( window.wp && window.wp.oldEditor ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could register Classic block in here to avoid conditional in other parts.

if ( window.wp && window.wp.oldEditor ) {
    registerBlockType( freeform.name, freeform.settings );
    setUnknownTypeHandlerName( freeform.name );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about the implication of the order of the block's registration, I know it has some importance in the transforms priority.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is important in this case, but I'm fine with leaving it as it is.

setUnknownTypeHandlerName( classic.name );
}
};
1 change: 0 additions & 1 deletion phpcs.xml.dist
Expand Up @@ -22,7 +22,6 @@
<arg name="extensions" value="php"/>

<file>./bin</file>
<file>./block-library</file>
<file>./packages/block-library/src</file>
<file>./lib</file>
<exclude-pattern>./lib/parser.php</exclude-pattern>
Expand Down
5 changes: 5 additions & 0 deletions test/unit/__mocks__/@wordpress/block-library.js
@@ -0,0 +1,5 @@
// Make sure the classic block is registered.
window.wp = window.wp || {};
window.wp.oldEditor = {};

export * from '../../../../packages/block-library/src';
4 changes: 2 additions & 2 deletions test/unit/jest.config.json
@@ -1,7 +1,7 @@
{
"rootDir": "../../",
"collectCoverageFrom": [
"(edit-post|block-library)/**/*.js",
"(edit-post)/**/*.js",
"packages/**/*.js"
],
"coveragePathIgnorePatterns": [
Expand All @@ -13,7 +13,7 @@
"<rootDir>/gutenberg-mobile/"
],
"moduleNameMapper": {
"@wordpress\\/(components|edit-post|block-library)$": "$1",
"@wordpress\\/(components|edit-post)$": "$1",
"@wordpress\\/(block-serialization-spec-parser|is-shallow-equal)$": "packages/$1",
"@wordpress\\/([a-z0-9-]+)$": "packages/$1/src"
},
Expand Down
44 changes: 1 addition & 43 deletions webpack.config.js
Expand Up @@ -21,21 +21,6 @@ const mainCSSExtractTextPlugin = new ExtractTextPlugin( {
filename: './build/[basename]/style.css',
} );

// CSS loader for styles specific to block editing.
const editBlocksCSSPlugin = new ExtractTextPlugin( {
filename: './build/block-library/edit-blocks.css',
} );

// CSS loader for styles specific to blocks in general.
const blocksCSSPlugin = new ExtractTextPlugin( {
filename: './build/block-library/style.css',
} );

// CSS loader for default visual block styles.
const themeBlocksCSSPlugin = new ExtractTextPlugin( {
filename: './build/block-library/theme.css',
} );

// Configuration for the ExtractTextPlugin.
const extractConfig = {
use: [
Expand Down Expand Up @@ -78,7 +63,6 @@ function camelCaseDash( string ) {
const entryPointNames = [
'components',
'edit-post',
'block-library',
];

const gutenbergPackages = [
Expand All @@ -87,6 +71,7 @@ const gutenbergPackages = [
'autop',
'blob',
'blocks',
'block-library',
'block-serialization-default-parser',
'block-serialization-spec-parser',
'compose',
Expand Down Expand Up @@ -182,40 +167,13 @@ const config = {
],
use: 'babel-loader',
},
{
test: /style\.s?css$/,
include: [
/block-library/,
],
use: blocksCSSPlugin.extract( extractConfig ),
},
{
test: /editor\.s?css$/,
include: [
/block-library/,
],
use: editBlocksCSSPlugin.extract( extractConfig ),
},
{
test: /theme\.s?css$/,
include: [
/block-library/,
],
use: themeBlocksCSSPlugin.extract( extractConfig ),
},
{
test: /\.s?css$/,
exclude: [
/block-library/,
],
use: mainCSSExtractTextPlugin.extract( extractConfig ),
},
],
},
plugins: [
blocksCSSPlugin,
editBlocksCSSPlugin,
themeBlocksCSSPlugin,
mainCSSExtractTextPlugin,
// Create RTL files with a -rtl suffix
new WebpackRTLPlugin( {
Expand Down