Skip to content

Commit

Permalink
Framework: Adding a legacy blocks package to avoid Breaking Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Sep 28, 2017
1 parent 94a905c commit c21d30e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions blocks/README.md
Original file line number Diff line number Diff line change
@@ -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.*`
43 changes: 43 additions & 0 deletions blocks/index.js
Original file line number Diff line number Diff line change
@@ -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 );
11 changes: 11 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const entryPointNames = [
'element',
'i18n',
'utils',
'blocks',
];

const externals = {
Expand Down

0 comments on commit c21d30e

Please sign in to comment.