Skip to content

Commit

Permalink
Move the Classic block to the packages (#10397)
Browse files Browse the repository at this point in the history
* Move the Classic block to the packages

* Rename freeform => classic

* Update the changelog of the block library package

* Fix classic block editor styles
  • Loading branch information
youknowriad authored Oct 9, 2018
1 parent 0df814a commit c303621
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 171 deletions.
1 change: 0 additions & 1 deletion bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
File renamed without changes.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "./cover-image/editor.scss";
@import "./embed/editor.scss";
@import "./file/editor.scss";
@import "./classic/editor.scss";
@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
Original file line number Diff line number Diff line change
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 ) {
setUnknownTypeHandlerName( classic.name );
}
};
1 change: 0 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit c303621

Please sign in to comment.