From c21d30e56041004814b149d22fa3e56e00281014 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 28 Sep 2017 09:48:35 +0100 Subject: [PATCH] Framework: Adding a legacy blocks package to avoid Breaking Changes --- blocks/README.md | 4 ++++ blocks/index.js | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/client-assets.php | 11 +++++++++++ webpack.config.js | 1 + 4 files changed, 59 insertions(+) create mode 100644 blocks/README.md create mode 100644 blocks/index.js diff --git a/blocks/README.md b/blocks/README.md new file mode 100644 index 0000000000000..5148d36cddf7c --- /dev/null +++ b/blocks/README.md @@ -0,0 +1,4 @@ +Blocks +====== + +This module is only here to ensure some backwards compatibility and encourage Plugin Authors to update the `wp.blocks.*` usage to `wp.editor.*` \ No newline at end of file diff --git a/blocks/index.js b/blocks/index.js new file mode 100644 index 0000000000000..d7675a9361b69 --- /dev/null +++ b/blocks/index.js @@ -0,0 +1,43 @@ +/** + * WordPress dependencies + */ +export { + source, + createBlock, + switchToBlockType, + parse, + pasteHandler, + serialize, + getBlockDefaultClassname, + getCategories, + unregisterBlockType, + setUnknownTypeHandlerName, + getUnknownTypeHandlerName, + setDefaultBlockName, + getDefaultBlockName, + getBlockType, + getBlockTypes, + AlignmentToolbar, + BlockAlignmentToolbar, + BlockControls, + BlockDescription, + BlockIcon, + ColorPalette, + Editable, + InspectorControls, + MediaUploadButton, + UrlInput, + UrlInputButton, +} from '@wordpress/editor'; + +import { registerBlockType as oldRegisterBlockType } from '@wordpress/editor'; + +const wrapWithDeprecationWarning = ( func ) => function() { + console.warn( // eslint-disable-line no-console + 'The "wp.blocks" module has been deprecated and replaced by "wp.editor". please update your usage.' + + ' Example: wp.editor.registerBlock instead of wp.blocks.registerBlock' + ); + return func( ...arguments ); +}; + +export const registerBlockType = wrapWithDeprecationWarning( oldRegisterBlockType ); diff --git a/lib/client-assets.php b/lib/client-assets.php index 936e46be3243a..5583fe5aed500 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -164,6 +164,16 @@ function gutenberg_register_scripts_and_styles() { 'before' ); + wp_register_script( + 'wp-blocks', + gutenberg_url( 'blocks/build/index.js' ), + array( + 'wp-editor', + ), + filemtime( gutenberg_dir_path() . 'blocks/build/index.js' ), + true // enqueue in the footer. + ); + // Editor Styles. wp_register_style( 'wp-components', @@ -632,6 +642,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) { // The editor code itself. wp_enqueue_script( 'wp-editor' ); + wp_enqueue_script( 'wp-blocks' ); gutenberg_fix_jetpack_freeform_block_conflict(); wp_localize_script( 'wp-editor', 'wpEditorL10n', array( diff --git a/webpack.config.js b/webpack.config.js index 7bbafdcb024fa..4a6e83a951876 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -43,6 +43,7 @@ const entryPointNames = [ 'element', 'i18n', 'utils', + 'blocks', ]; const externals = {