diff --git a/bin/build-plugin-zip.sh b/bin/build-plugin-zip.sh index 40e265eaa51e..1339b8ccec2b 100755 --- a/bin/build-plugin-zip.sh +++ b/bin/build-plugin-zip.sh @@ -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 \ diff --git a/bin/get-server-blocks.php b/bin/get-server-blocks.php index 8e3b20601838..851dbccfab6e 100755 --- a/bin/get-server-blocks.php +++ b/bin/get-server-blocks.php @@ -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; } diff --git a/block-library/editor.scss b/block-library/editor.scss deleted file mode 100644 index 764dac8ca8da..000000000000 --- a/block-library/editor.scss +++ /dev/null @@ -1 +0,0 @@ -@import "../packages/block-library/src/editor.scss"; diff --git a/block-library/index.js b/block-library/index.js deleted file mode 100644 index 03bdbe13466d..000000000000 --- a/block-library/index.js +++ /dev/null @@ -1,101 +0,0 @@ -/** - * WordPress dependencies - */ -import { - registerBlockType, - setDefaultBlockName, - setUnknownTypeHandlerName, -} from '@wordpress/blocks'; - -/** - * Internal dependencies - */ -import './style.scss'; -import './editor.scss'; -import './theme.scss'; -import * as paragraph from '../packages/block-library/src/paragraph'; -import * as image from '../packages/block-library/src/image'; -import * as heading from '../packages/block-library/src/heading'; -import * as quote from '../packages/block-library/src/quote'; -import * as gallery from '../packages/block-library/src/gallery'; -import * as archives from '../packages/block-library/src/archives'; -import * as audio from '../packages/block-library/src/audio'; -import * as button from '../packages/block-library/src/button'; -import * as categories from '../packages/block-library/src/categories'; -import * as code from '../packages/block-library/src/code'; -import * as columns from '../packages/block-library/src/columns'; -import * as column from '../packages/block-library/src/columns/column'; -import * as coverImage from '../packages/block-library/src/cover-image'; -import * as embed from '../packages/block-library/src/embed'; -import * as file from '../packages/block-library/src/file'; -import * as html from '../packages/block-library/src/html'; -import * as latestComments from '../packages/block-library/src/latest-comments'; -import * as latestPosts from '../packages/block-library/src/latest-posts'; -import * as list from '../packages/block-library/src/list'; -import * as more from '../packages/block-library/src/more'; -import * as nextpage from '../packages/block-library/src/nextpage'; -import * as preformatted from '../packages/block-library/src/preformatted'; -import * as pullquote from '../packages/block-library/src/pullquote'; -import * as reusableBlock from '../packages/block-library/src/block'; -import * as separator from '../packages/block-library/src/separator'; -import * as shortcode from '../packages/block-library/src/shortcode'; -import * as spacer from '../packages/block-library/src/spacer'; -import * as subhead from '../packages/block-library/src/subhead'; -import * as table from '../packages/block-library/src/table'; -import * as template from '../packages/block-library/src/template'; -import * as textColumns from '../packages/block-library/src/text-columns'; -import * as verse from '../packages/block-library/src/verse'; -import * as video from '../packages/block-library/src/video'; - -// The freeform block can't be moved to the "npm" packages folder because it requires the wp.oldEditor global. -import * as freeform from './freeform'; - -export const registerCoreBlocks = () => { - [ - // Common blocks are grouped at the top to prioritize their display - // in various contexts — like the inserter and auto-complete components. - paragraph, - image, - heading, - gallery, - list, - quote, - - // Register all remaining core blocks. - shortcode, - archives, - audio, - button, - categories, - code, - columns, - column, - coverImage, - embed, - ...embed.common, - ...embed.others, - file, - freeform, - html, - latestComments, - latestPosts, - more, - nextpage, - preformatted, - pullquote, - separator, - reusableBlock, - spacer, - subhead, - table, - template, - textColumns, - verse, - video, - ].forEach( ( { name, settings } ) => { - registerBlockType( name, settings ); - } ); - - setDefaultBlockName( paragraph.name ); - setUnknownTypeHandlerName( freeform.name ); -}; diff --git a/block-library/index.native.js b/block-library/index.native.js deleted file mode 100644 index 3779a1214f53..000000000000 --- a/block-library/index.native.js +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Internal dependencies - */ -import '../packages/block-library/src'; diff --git a/block-library/style.scss b/block-library/style.scss deleted file mode 100644 index 7afe88dde1f2..000000000000 --- a/block-library/style.scss +++ /dev/null @@ -1 +0,0 @@ -@import "../packages/block-library/src/style.scss"; diff --git a/block-library/theme.scss b/block-library/theme.scss deleted file mode 100644 index 39f6af550322..000000000000 --- a/block-library/theme.scss +++ /dev/null @@ -1 +0,0 @@ -@import "../packages/block-library/src/theme.scss"; diff --git a/lib/client-assets.php b/lib/client-assets.php index e7b09ae97330..f3cd1b427d41 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -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' ); diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index 43b9b38ee17c..1c11ea8435e0 100644 --- a/packages/block-library/CHANGELOG.md +++ b/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 diff --git a/block-library/freeform/edit.js b/packages/block-library/src/classic/edit.js similarity index 97% rename from block-library/freeform/edit.js rename to packages/block-library/src/classic/edit.js index 6fa71e20e1ec..6bede6a2df31 100644 --- a/block-library/freeform/edit.js +++ b/packages/block-library/src/classic/edit.js @@ -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: //


@@ -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 ); @@ -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 } diff --git a/block-library/freeform/editor.scss b/packages/block-library/src/classic/editor.scss similarity index 99% rename from block-library/freeform/editor.scss rename to packages/block-library/src/classic/editor.scss index 9c03b0667461..70c8e819c216 100644 --- a/block-library/freeform/editor.scss +++ b/packages/block-library/src/classic/editor.scss @@ -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; diff --git a/block-library/freeform/index.js b/packages/block-library/src/classic/index.js similarity index 100% rename from block-library/freeform/index.js rename to packages/block-library/src/classic/index.js diff --git a/block-library/freeform/test/__snapshots__/index.js.snap b/packages/block-library/src/classic/test/__snapshots__/index.js.snap similarity index 87% rename from block-library/freeform/test/__snapshots__/index.js.snap rename to packages/block-library/src/classic/test/__snapshots__/index.js.snap index c14bc40ad32d..690b0d5e30fd 100644 --- a/block-library/freeform/test/__snapshots__/index.js.snap +++ b/packages/block-library/src/classic/test/__snapshots__/index.js.snap @@ -3,7 +3,7 @@ exports[`core/freeform block edit matches snapshot 1`] = ` Array [
, diff --git a/block-library/freeform/test/index.js b/packages/block-library/src/classic/test/index.js similarity index 75% rename from block-library/freeform/test/index.js rename to packages/block-library/src/classic/test/index.js index 36e3735c12bc..824c835543e7 100644 --- a/block-library/freeform/test/index.js +++ b/packages/block-library/src/classic/test/index.js @@ -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', () => { diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index 94ac00322dca..70aa75c35b7f 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -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"; diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index a2991cebedb0..3c71cb52c702 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -5,6 +5,7 @@ import '@wordpress/core-data'; import { registerBlockType, setDefaultBlockName, + setUnknownTypeHandlerName, } from '@wordpress/blocks'; /** @@ -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 @@ -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, @@ -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 ); + } }; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index a7cfc9de3143..ce0669fe42a3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -22,7 +22,6 @@ ./bin - ./block-library ./packages/block-library/src ./lib ./lib/parser.php diff --git a/test/unit/__mocks__/@wordpress/block-library.js b/test/unit/__mocks__/@wordpress/block-library.js new file mode 100644 index 000000000000..72c9351ad7da --- /dev/null +++ b/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'; diff --git a/test/unit/jest.config.json b/test/unit/jest.config.json index 095317caed65..fbab20dac0d7 100644 --- a/test/unit/jest.config.json +++ b/test/unit/jest.config.json @@ -1,7 +1,7 @@ { "rootDir": "../../", "collectCoverageFrom": [ - "(edit-post|block-library)/**/*.js", + "(edit-post)/**/*.js", "packages/**/*.js" ], "coveragePathIgnorePatterns": [ @@ -13,7 +13,7 @@ "/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" }, diff --git a/webpack.config.js b/webpack.config.js index 1bc044099563..15dbd779cca2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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: [ @@ -78,7 +63,6 @@ function camelCaseDash( string ) { const entryPointNames = [ 'components', 'edit-post', - 'block-library', ]; const gutenbergPackages = [ @@ -87,6 +71,7 @@ const gutenbergPackages = [ 'autop', 'blob', 'blocks', + 'block-library', 'block-serialization-default-parser', 'block-serialization-spec-parser', 'compose', @@ -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( {