diff --git a/packages/block-library/CHANGELOG.md b/packages/block-library/CHANGELOG.md index 13d42304fbc8e..0c30aa8b6bdad 100644 --- a/packages/block-library/CHANGELOG.md +++ b/packages/block-library/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Feature + +- Made it possible to import individual blocks ([#42258](https://github.com/WordPress/gutenberg/pull/42258)). Check [README](./README.md#loading-individual-blocks) for more information. + ## 7.13.0 (2022-08-24) ### Bug Fix diff --git a/packages/block-library/README.md b/packages/block-library/README.md index ffe7f81f9f080..85d41759887a8 100644 --- a/packages/block-library/README.md +++ b/packages/block-library/README.md @@ -12,62 +12,6 @@ npm install @wordpress/block-library --save _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._ -## Building JavaScript for the browser - -If a `view.js` file (or a file prefixed with `view`, e.g. `view-example.js`) is present in the block's directory, this file will be built along other assets, making it available to load from the browser. - -This enables us to, for instance, load this file when the block is present on the page in two ways: - -1. Using the block's `render_callback`: - -```php -function render_block_my_block() { - $script_path = __DIR__ . '/my-block/view.js'; - - if ( file_exists( $script_path ) ) { - wp_enqueue_script( - 'wp-block-my-block-view', - plugins_url( 'view.js', $script_path ), - array(), - false, - true - ); - } -} - -function register_block_my_block() { - register_block_type( - __DIR__ . '/my-block', - array( - 'render_callback' => 'render_block_my_block', - ) - ); -} - - -add_action( 'init', 'register_block_my_block' ); -``` - -2. Using the `render_block` filter: - -```php -function render_block_my_block() { - $script_path = __DIR__ . '/my-block/view.js'; - - if ( file_exists( $script_path ) ) { - wp_enqueue_script( - 'wp-block-my-block-view', - plugins_url( 'view.js', $script_path ), - array(), - false, - true - ); - } -} - -apply_filter( 'render_block', 'render_block_my_block' ); -``` - ## API @@ -90,6 +34,28 @@ _Parameters_ +## Registering individual blocks + +1. When you only care about registering the block when file gets imported: + + ```js + import '@wordpress/block-library/build-module/verse/init'; + ``` + +2. When you want to use the reference to the block after it gets automatically registered: + + ```js + import verseBlock from '@wordpress/block-library/build-module/verse/init'; + ``` + +3. When you need a full control over when the block gets registered: + + ```js + import { init } from '@wordpress/block-library/build-module/verse'; + + const verseBlock = init(); + ``` + ## Contributing to this package This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects. @@ -100,17 +66,57 @@ To find out more about contributing to this package or Gutenberg as a whole, ple ⚠️ Adding new blocks to this package **requires** additional steps! -1. Do not forget to register your new block in the [`index.js`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/index.js) file of this package. For example, if you were to add a new core block called `core/blinking-paragraph`, you would have to add something like: +1. Do not forget to register a new core block in the [`index.js`](https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/index.js) file of this package. For example, if you were to add the new core block called `core/blinking-paragraph`, you would have to add something like: ```js // packages/block-library/src/index.js import * as blinkingParagraph from './blinking-paragraph'; + ``` + + Then add `blinkingParagraph` to the list in the `getAllBlocks()` function. + + If it's experimental, add the following property to `block. json`: + + ```json + { + "__experimental": "true" + } + ``` - // Then add `blinkingParagraph` to `getAllBlocks()` - // If it's experimental, add the following property to block.json: - __experimental: 'true'; +2. Register the block in the `gutenberg_reregister_core_block_types()` function of the [`lib/blocks.php`](https://github.com/WordPress/gutenberg/blob/trunk/lib/blocks.php) file. Add it to the `block_folders` array if it's a [static block](https://developer.wordpress.org/block-editor/explanations/glossary/#static-block) or to the `block_names` array if it's a [dynamic block](https://developer.wordpress.org/block-editor/explanations/glossary/#dynamic-block). + +3. Add `init.js` file to the directory of the new block: + + ```js + /** + * Internal dependencies + */ + import { init } from './'; + + export default init(); ``` -2. Register your block in the `gutenberg_reregister_core_block_types()` function of the [`lib/blocks.php`](https://github.com/WordPress/gutenberg/blob/trunk/lib/blocks.php) file. Add it to the `block_folders` array if it's a [static block](https://developer.wordpress.org/block-editor/explanations/glossary/#static-block) or to the `block_names` array if it's a [dynamic block](https://developer.wordpress.org/block-editor/explanations/glossary/#dynamic-block). + This file is used when using the option to register individual block from the `@wordpress/block-library` package. + +4. If a `view.js` file (or a file prefixed with `view`, e.g. `view-example.js`) is present in the block's directory, this file will be built along other assets, making it available to load from the browser. You only need to reference a `view.min.js` (notice the different file extension) file in the `block.json` file as follows: + + ```json + { + "viewScript": "file:./view.min.js" + } + ``` + + This file will get automatically loaded when the static block is present on the front end. For dynamic block, you need to manually enqueue the view script in `render_callback` of the block, example: + + ```php + function render_block_core_blinking_paragraph( $attributes, $content ) { + $should_load_view_script = ! empty( $attributes['isInteractive'] ) && ! wp_script_is( 'wp-block-blinking-paragraph-view' ); + if ( $should_load_view_script ) { + wp_enqueue_script( 'wp-block-blinking-paragraph-view' ); + } + + return $content; + } + ```

Code is Poetry.

diff --git a/packages/block-library/babel-plugin.js b/packages/block-library/babel-plugin.js index ed688777169f3..1fba03a39a35a 100644 --- a/packages/block-library/babel-plugin.js +++ b/packages/block-library/babel-plugin.js @@ -6,7 +6,7 @@ const fs = require( 'fs' ); /** * Internal dependencies */ -const isBlockMetadataExperimental = require( './src/is-block-metadata-experimental' ); +const isBlockMetadataExperimental = require( './src/utils/is-block-metadata-experimental' ); /** * Creates a babel plugin that replaces experimental block imports with diff --git a/packages/block-library/package.json b/packages/block-library/package.json index 38bea5efd407b..ae2920cf6b0a1 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -27,10 +27,7 @@ "sideEffects": [ "build-style/**", "src/**/*.scss", - "src/navigation-link/index.js", - "src/template-part/index.js", - "src/query/index.js", - "src/post-terms/index.js" + "{src,build,build-module}/*/init.js" ], "dependencies": { "@babel/runtime": "^7.16.0", diff --git a/packages/block-library/src/archives/index.js b/packages/block-library/src/archives/index.js index e1f01f30a7187..40844eb9cb7d7 100644 --- a/packages/block-library/src/archives/index.js +++ b/packages/block-library/src/archives/index.js @@ -6,6 +6,7 @@ import { archive as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -18,3 +19,5 @@ export const settings = { example: {}, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/archives/init.js b/packages/block-library/src/archives/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/archives/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/audio/index.js b/packages/block-library/src/audio/index.js index d3047dd5af445..0d3d05936ef90 100644 --- a/packages/block-library/src/audio/index.js +++ b/packages/block-library/src/audio/index.js @@ -6,6 +6,7 @@ import { audio as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -28,3 +29,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/audio/init.js b/packages/block-library/src/audio/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/audio/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/audio/transforms.native.js b/packages/block-library/src/audio/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/audio/transforms.native.js +++ b/packages/block-library/src/audio/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/avatar/index.js b/packages/block-library/src/avatar/index.js index ef71f2751459a..d318450aec390 100644 --- a/packages/block-library/src/avatar/index.js +++ b/packages/block-library/src/avatar/index.js @@ -6,6 +6,7 @@ import { commentAuthorAvatar as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/avatar/init.js b/packages/block-library/src/avatar/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/avatar/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/block/index.js b/packages/block-library/src/block/index.js index fff0109a543ac..95e090f0afd6a 100644 --- a/packages/block-library/src/block/index.js +++ b/packages/block-library/src/block/index.js @@ -6,6 +6,7 @@ import { symbol as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -17,3 +18,5 @@ export const settings = { edit, icon, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/block/init.js b/packages/block-library/src/block/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/block/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/button/index.js b/packages/block-library/src/button/index.js index c454e46bf681b..2b05b280028ab 100644 --- a/packages/block-library/src/button/index.js +++ b/packages/block-library/src/button/index.js @@ -7,6 +7,7 @@ import { button as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -32,3 +33,5 @@ export const settings = { text: ( a.text || '' ) + text, } ), }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/button/init.js b/packages/block-library/src/button/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/button/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/buttons/index.js b/packages/block-library/src/buttons/index.js index 52d406e0ca976..810922fbcb839 100644 --- a/packages/block-library/src/buttons/index.js +++ b/packages/block-library/src/buttons/index.js @@ -7,6 +7,7 @@ import { buttons as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import transforms from './transforms'; import edit from './edit'; @@ -36,3 +37,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/buttons/init.js b/packages/block-library/src/buttons/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/buttons/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/buttons/transforms.native.js b/packages/block-library/src/buttons/transforms.native.js index 0816b765fee29..c497af10c918f 100644 --- a/packages/block-library/src/buttons/transforms.native.js +++ b/packages/block-library/src/buttons/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/calendar/index.js b/packages/block-library/src/calendar/index.js index a8fed300b171e..7fff20826e271 100644 --- a/packages/block-library/src/calendar/index.js +++ b/packages/block-library/src/calendar/index.js @@ -6,6 +6,7 @@ import { calendar as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import transforms from './transforms'; @@ -20,3 +21,5 @@ export const settings = { edit, transforms, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/calendar/init.js b/packages/block-library/src/calendar/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/calendar/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/categories/index.js b/packages/block-library/src/categories/index.js index 9698dacfdaff3..8cdcad450862a 100644 --- a/packages/block-library/src/categories/index.js +++ b/packages/block-library/src/categories/index.js @@ -6,6 +6,7 @@ import { category as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -18,3 +19,5 @@ export const settings = { example: {}, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/categories/init.js b/packages/block-library/src/categories/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/categories/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/code/index.js b/packages/block-library/src/code/index.js index 8301b13d9ff57..08e2fffaf5480 100644 --- a/packages/block-library/src/code/index.js +++ b/packages/block-library/src/code/index.js @@ -7,6 +7,7 @@ import { code as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -32,3 +33,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/code/init.js b/packages/block-library/src/code/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/code/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/code/transforms.native.js b/packages/block-library/src/code/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/code/transforms.native.js +++ b/packages/block-library/src/code/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/column/index.js b/packages/block-library/src/column/index.js index e935e682f45ca..687b8c180b1f5 100644 --- a/packages/block-library/src/column/index.js +++ b/packages/block-library/src/column/index.js @@ -6,6 +6,7 @@ import { column as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -21,3 +22,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/column/init.js b/packages/block-library/src/column/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/column/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/columns/index.js b/packages/block-library/src/columns/index.js index d5185f0ee368a..45f7bd70e61ff 100644 --- a/packages/block-library/src/columns/index.js +++ b/packages/block-library/src/columns/index.js @@ -7,6 +7,7 @@ import { columns as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -83,3 +84,5 @@ export const settings = { save, transforms, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/columns/init.js b/packages/block-library/src/columns/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/columns/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/columns/transforms.native.js b/packages/block-library/src/columns/transforms.native.js index 032a346425894..cea16e6fd62a2 100644 --- a/packages/block-library/src/columns/transforms.native.js +++ b/packages/block-library/src/columns/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/comment-author-avatar/index.js b/packages/block-library/src/comment-author-avatar/index.js index ef71f2751459a..d318450aec390 100644 --- a/packages/block-library/src/comment-author-avatar/index.js +++ b/packages/block-library/src/comment-author-avatar/index.js @@ -6,6 +6,7 @@ import { commentAuthorAvatar as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-author-avatar/init.js b/packages/block-library/src/comment-author-avatar/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comment-author-avatar/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comment-author-name/index.js b/packages/block-library/src/comment-author-name/index.js index d1481d359b0a0..4d85bbebe047b 100644 --- a/packages/block-library/src/comment-author-name/index.js +++ b/packages/block-library/src/comment-author-name/index.js @@ -6,6 +6,7 @@ import { commentAuthorName as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import deprecated from './deprecated'; @@ -18,3 +19,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-author-name/init.js b/packages/block-library/src/comment-author-name/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comment-author-name/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comment-content/index.js b/packages/block-library/src/comment-content/index.js index 6020aab70e0f8..130f1d3012555 100644 --- a/packages/block-library/src/comment-content/index.js +++ b/packages/block-library/src/comment-content/index.js @@ -6,6 +6,7 @@ import { commentContent as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-content/init.js b/packages/block-library/src/comment-content/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comment-content/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comment-date/index.js b/packages/block-library/src/comment-date/index.js index c2384da69192d..fddae539acfa3 100644 --- a/packages/block-library/src/comment-date/index.js +++ b/packages/block-library/src/comment-date/index.js @@ -6,6 +6,7 @@ import { postDate as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import deprecated from './deprecated'; @@ -18,3 +19,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-date/init.js b/packages/block-library/src/comment-date/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comment-date/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comment-edit-link/index.js b/packages/block-library/src/comment-edit-link/index.js index 8e1ee77e388b4..6639dda86a7a4 100644 --- a/packages/block-library/src/comment-edit-link/index.js +++ b/packages/block-library/src/comment-edit-link/index.js @@ -6,6 +6,7 @@ import { commentEditLink as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-edit-link/init.js b/packages/block-library/src/comment-edit-link/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comment-edit-link/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comment-reply-link/index.js b/packages/block-library/src/comment-reply-link/index.js index 491c0ca7d95e1..c04f8ce7b1bba 100644 --- a/packages/block-library/src/comment-reply-link/index.js +++ b/packages/block-library/src/comment-reply-link/index.js @@ -6,6 +6,7 @@ import { commentReplyLink as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { edit, icon, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-reply-link/init.js b/packages/block-library/src/comment-reply-link/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comment-reply-link/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comment-template/index.js b/packages/block-library/src/comment-template/index.js index b6e6d280626bf..afc295cad4c12 100644 --- a/packages/block-library/src/comment-template/index.js +++ b/packages/block-library/src/comment-template/index.js @@ -6,6 +6,7 @@ import { layout as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -18,3 +19,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comment-template/init.js b/packages/block-library/src/comment-template/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comment-template/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comments-pagination-next/index.js b/packages/block-library/src/comments-pagination-next/index.js index d339ed2ca7581..2df0e8da6aa99 100644 --- a/packages/block-library/src/comments-pagination-next/index.js +++ b/packages/block-library/src/comments-pagination-next/index.js @@ -6,6 +6,7 @@ import { queryPaginationNext as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination-next/init.js b/packages/block-library/src/comments-pagination-next/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comments-pagination-next/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comments-pagination-numbers/index.js b/packages/block-library/src/comments-pagination-numbers/index.js index 9f1818b1f14a0..3fd903e2d9ef4 100644 --- a/packages/block-library/src/comments-pagination-numbers/index.js +++ b/packages/block-library/src/comments-pagination-numbers/index.js @@ -6,6 +6,7 @@ import { queryPaginationNumbers as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination-numbers/init.js b/packages/block-library/src/comments-pagination-numbers/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comments-pagination-numbers/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comments-pagination-previous/index.js b/packages/block-library/src/comments-pagination-previous/index.js index a66be07616944..80e555ccc79d9 100644 --- a/packages/block-library/src/comments-pagination-previous/index.js +++ b/packages/block-library/src/comments-pagination-previous/index.js @@ -6,6 +6,7 @@ import { queryPaginationPrevious as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination-previous/init.js b/packages/block-library/src/comments-pagination-previous/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comments-pagination-previous/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comments-pagination/index.js b/packages/block-library/src/comments-pagination/index.js index a15bdd4389cee..3d9bc853db140 100644 --- a/packages/block-library/src/comments-pagination/index.js +++ b/packages/block-library/src/comments-pagination/index.js @@ -6,6 +6,7 @@ import { queryPagination as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -18,3 +19,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-pagination/init.js b/packages/block-library/src/comments-pagination/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comments-pagination/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comments-title/index.js b/packages/block-library/src/comments-title/index.js index 374a379746df3..86bdab0dbccbf 100644 --- a/packages/block-library/src/comments-title/index.js +++ b/packages/block-library/src/comments-title/index.js @@ -6,6 +6,7 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import deprecated from './deprecated'; @@ -18,3 +19,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments-title/init.js b/packages/block-library/src/comments-title/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comments-title/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/comments/index.js b/packages/block-library/src/comments/index.js index 9cecb54f5a64d..21db8b986d6e5 100644 --- a/packages/block-library/src/comments/index.js +++ b/packages/block-library/src/comments/index.js @@ -6,6 +6,7 @@ import { postComments as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import deprecated from './deprecated'; import edit from './edit'; @@ -20,3 +21,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/comments/init.js b/packages/block-library/src/comments/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/comments/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/cover/index.js b/packages/block-library/src/cover/index.js index 89576d2ae55e1..45d91ab1e5c41 100644 --- a/packages/block-library/src/cover/index.js +++ b/packages/block-library/src/cover/index.js @@ -7,6 +7,7 @@ import { cover as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -41,3 +42,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/cover/init.js b/packages/block-library/src/cover/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/cover/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/cover/test/edit.native.js b/packages/block-library/src/cover/test/edit.native.js index a6781a785bd24..df8a6e1f618e2 100644 --- a/packages/block-library/src/cover/test/edit.native.js +++ b/packages/block-library/src/cover/test/edit.native.js @@ -28,7 +28,6 @@ import { import { IMAGE_BACKGROUND_TYPE } from '../shared'; import * as paragraph from '../../paragraph'; import * as cover from '..'; -import { registerBlock } from '../..'; // Avoid errors due to mocked stylesheet files missing required selectors. jest.mock( '@wordpress/compose', () => ( { @@ -84,8 +83,8 @@ beforeAll( () => { ); // Register required blocks. - registerBlock( paragraph ); - registerBlock( cover ); + paragraph.init(); + cover.init(); setDefaultBlockName( paragraph.name ); } ); diff --git a/packages/block-library/src/cover/transforms.native.js b/packages/block-library/src/cover/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/cover/transforms.native.js +++ b/packages/block-library/src/cover/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/embed/index.js b/packages/block-library/src/embed/index.js index 5f0e38c1aabf2..065cf9665fa9b 100644 --- a/packages/block-library/src/embed/index.js +++ b/packages/block-library/src/embed/index.js @@ -1,6 +1,7 @@ /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import save from './save'; import metadata from './block.json'; @@ -20,3 +21,5 @@ export const settings = { variations, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/embed/init.js b/packages/block-library/src/embed/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/embed/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/embed/test/index.native.js b/packages/block-library/src/embed/test/index.native.js index d3ef251dab9a9..b846406205bcc 100644 --- a/packages/block-library/src/embed/test/index.native.js +++ b/packages/block-library/src/embed/test/index.native.js @@ -29,7 +29,6 @@ import { requestPreview } from '@wordpress/react-native-bridge'; */ import * as paragraph from '../../paragraph'; import * as embed from '..'; -import { registerBlock } from '../..'; // Override modal mock to prevent unmounting it when is not visible. // This is required to be able to trigger onClose and onDismiss events when @@ -180,8 +179,8 @@ const initializeWithEmbedBlock = async ( initialHtml, selectBlock = true ) => { beforeAll( () => { // Paragraph block needs to be registered because by default a paragraph // block is added to empty posts. - registerBlock( paragraph ); - registerBlock( embed ); + paragraph.init(); + embed.init(); setDefaultBlockName( paragraph.name ); } ); diff --git a/packages/block-library/src/embed/transforms.native.js b/packages/block-library/src/embed/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/embed/transforms.native.js +++ b/packages/block-library/src/embed/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/file/index.js b/packages/block-library/src/file/index.js index bf2b6a6b918f1..46b9691ea88a7 100644 --- a/packages/block-library/src/file/index.js +++ b/packages/block-library/src/file/index.js @@ -7,6 +7,7 @@ import { file as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -30,3 +31,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/file/init.js b/packages/block-library/src/file/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/file/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/file/transforms.native.js b/packages/block-library/src/file/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/file/transforms.native.js +++ b/packages/block-library/src/file/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/freeform/index.js b/packages/block-library/src/freeform/index.js index b4d7cf715442b..e94a459487b89 100644 --- a/packages/block-library/src/freeform/index.js +++ b/packages/block-library/src/freeform/index.js @@ -6,6 +6,7 @@ import { classic as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -19,3 +20,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/freeform/init.js b/packages/block-library/src/freeform/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/freeform/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/gallery/index.js b/packages/block-library/src/gallery/index.js index c9b82278a507a..f865072526098 100644 --- a/packages/block-library/src/gallery/index.js +++ b/packages/block-library/src/gallery/index.js @@ -6,6 +6,7 @@ import { gallery as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit-wrapper'; import metadata from './block.json'; @@ -42,3 +43,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/gallery/init.js b/packages/block-library/src/gallery/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/gallery/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/gallery/transforms.native.js b/packages/block-library/src/gallery/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/gallery/transforms.native.js +++ b/packages/block-library/src/gallery/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/group/index.js b/packages/block-library/src/group/index.js index ddee42e095f7a..2d06f1a965c52 100644 --- a/packages/block-library/src/group/index.js +++ b/packages/block-library/src/group/index.js @@ -7,6 +7,7 @@ import { group as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -86,3 +87,5 @@ export const settings = { deprecated, variations, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/group/init.js b/packages/block-library/src/group/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/group/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/heading/index.js b/packages/block-library/src/heading/index.js index e829a7ae15108..56bf1f670e92d 100644 --- a/packages/block-library/src/heading/index.js +++ b/packages/block-library/src/heading/index.js @@ -12,6 +12,7 @@ import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -66,3 +67,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/heading/init.js b/packages/block-library/src/heading/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/heading/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/heading/transforms.native.js b/packages/block-library/src/heading/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/heading/transforms.native.js +++ b/packages/block-library/src/heading/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/home-link/index.js b/packages/block-library/src/home-link/index.js index 5bb3914bb1bf3..71d62dcd8c44e 100644 --- a/packages/block-library/src/home-link/index.js +++ b/packages/block-library/src/home-link/index.js @@ -7,6 +7,7 @@ import { home } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -28,3 +29,5 @@ export const settings = { }, }, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/home-link/init.js b/packages/block-library/src/home-link/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/home-link/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/html/index.js b/packages/block-library/src/html/index.js index cb1fb915ee8b5..cd25f25126a61 100644 --- a/packages/block-library/src/html/index.js +++ b/packages/block-library/src/html/index.js @@ -7,6 +7,7 @@ import { html as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -30,3 +31,5 @@ export const settings = { save, transforms, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/html/init.js b/packages/block-library/src/html/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/html/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/image/index.js b/packages/block-library/src/image/index.js index dcdbd4e76882c..1477fa99c702c 100644 --- a/packages/block-library/src/image/index.js +++ b/packages/block-library/src/image/index.js @@ -7,6 +7,7 @@ import { image as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -54,3 +55,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/image/init.js b/packages/block-library/src/image/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/image/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/image/transforms.native.js b/packages/block-library/src/image/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/image/transforms.native.js +++ b/packages/block-library/src/image/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index e71ee9326a4b8..88d2c26f02403 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -2,7 +2,6 @@ * WordPress dependencies */ import { - registerBlockType, setDefaultBlockName, setFreeformContentHandlerName, setUnregisteredTypeHandlerName, @@ -115,126 +114,113 @@ import * as textColumns from './text-columns'; import * as verse from './verse'; import * as video from './video'; -import isBlockMetadataExperimental from './is-block-metadata-experimental'; - -/** - * Function to register an individual block. - * - * @param {Object} block The block to be registered. - * - */ -const registerBlock = ( block ) => { - if ( ! block ) { - return; - } - const { metadata, settings, name } = block; - registerBlockType( { name, ...metadata }, settings ); -}; +import isBlockMetadataExperimental from './utils/is-block-metadata-experimental'; /** * Function to get all the block-library blocks in an array */ -const getAllBlocks = () => [ - // 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, - listItem, - quote, +const getAllBlocks = () => + [ + // 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, + listItem, + quote, - // Register all remaining core blocks. - archives, - audio, - button, - buttons, - calendar, - categories, - ...( window.wp && window.wp.oldEditor ? [ classic ] : [] ), // Only add the classic block in WP Context. - code, - column, - columns, - commentAuthorAvatar, - cover, - embed, - file, - group, - html, - latestComments, - latestPosts, - mediaText, - missing, - more, - nextpage, - pageList, - pattern, - preformatted, - pullquote, - reusableBlock, - rss, - search, - separator, - shortcode, - socialLink, - socialLinks, - spacer, - table, - tagCloud, - textColumns, - verse, - video, + // Register all remaining core blocks. + archives, + audio, + button, + buttons, + calendar, + categories, + ...( window.wp && window.wp.oldEditor ? [ classic ] : [] ), // Only add the classic block in WP Context. + code, + column, + columns, + commentAuthorAvatar, + cover, + embed, + file, + group, + html, + latestComments, + latestPosts, + mediaText, + missing, + more, + nextpage, + pageList, + pattern, + preformatted, + pullquote, + reusableBlock, + rss, + search, + separator, + shortcode, + socialLink, + socialLinks, + spacer, + table, + tagCloud, + textColumns, + verse, + video, - // theme blocks - navigation, - navigationLink, - navigationSubmenu, - siteLogo, - siteTitle, - siteTagline, - query, - templatePart, - avatar, - postTitle, - postExcerpt, - postFeaturedImage, - postContent, - postAuthor, - postAuthorName, - postComment, - postCommentsCount, - postCommentsLink, - postDate, - postTerms, - postNavigationLink, - postTemplate, - queryPagination, - queryPaginationNext, - queryPaginationNumbers, - queryPaginationPrevious, - queryNoResults, - readMore, - comments, - commentAuthorName, - commentContent, - commentDate, - commentEditLink, - commentReplyLink, - commentTemplate, - commentsTitle, - commentsPagination, - commentsPaginationNext, - commentsPaginationNumbers, - commentsPaginationPrevious, - postCommentsForm, - tableOfContents, - homeLink, - logInOut, - termDescription, - queryTitle, - postAuthorBiography, -]; + // theme blocks + navigation, + navigationLink, + navigationSubmenu, + siteLogo, + siteTitle, + siteTagline, + query, + templatePart, + avatar, + postTitle, + postExcerpt, + postFeaturedImage, + postContent, + postAuthor, + postAuthorName, + postComment, + postCommentsCount, + postCommentsLink, + postDate, + postTerms, + postNavigationLink, + postTemplate, + queryPagination, + queryPaginationNext, + queryPaginationNumbers, + queryPaginationPrevious, + queryNoResults, + readMore, + comments, + commentAuthorName, + commentContent, + commentDate, + commentEditLink, + commentReplyLink, + commentTemplate, + commentsTitle, + commentsPagination, + commentsPaginationNext, + commentsPaginationNumbers, + commentsPaginationPrevious, + postCommentsForm, + tableOfContents, + homeLink, + logInOut, + termDescription, + queryTitle, + postAuthorBiography, + ].filter( Boolean ); /** * Function to get all the core blocks in an array. @@ -266,7 +252,7 @@ export const __experimentalGetCoreBlocks = () => export const registerCoreBlocks = ( blocks = __experimentalGetCoreBlocks() ) => { - blocks.forEach( registerBlock ); + blocks.forEach( ( { init } ) => init() ); setDefaultBlockName( paragraph.name ); if ( window.wp && window.wp.oldEditor ) { @@ -300,6 +286,6 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env __experimental === true || enabledExperiments.includes( __experimental ) ) - .forEach( registerBlock ); + .forEach( ( { init } ) => init() ); } : undefined; diff --git a/packages/block-library/src/index.native.js b/packages/block-library/src/index.native.js index 1acc90c0116c6..1a0f0c017024e 100644 --- a/packages/block-library/src/index.native.js +++ b/packages/block-library/src/index.native.js @@ -63,9 +63,7 @@ import * as buttons from './buttons'; import * as socialLink from './social-link'; import * as socialLinks from './social-links'; -import { transformationCategory } from './transformationCategories'; - -const ALLOWED_BLOCKS_GRADIENT_SUPPORT = [ 'core/button' ]; +import { transformationCategory } from './utils/transformation-categories'; export const coreBlocks = [ // Common blocks are grouped at the top to prioritize their display @@ -119,38 +117,6 @@ export const coreBlocks = [ return accumulator; }, {} ); -/** - * Function to register an individual block. - * - * @param {Object} block The block to be registered. - * - */ -export const registerBlock = ( block ) => { - if ( ! block ) { - return; - } - const { metadata, settings, name } = block; - const { supports } = metadata; - - registerBlockType( - { - name, - ...metadata, - // Gradients support only available for blocks listed in ALLOWED_BLOCKS_GRADIENT_SUPPORT. - ...( ! ALLOWED_BLOCKS_GRADIENT_SUPPORT.includes( name ) && - supports?.color?.gradients - ? { - supports: { - ...supports, - color: { ...supports.color, gradients: false }, - }, - } - : {} ), - }, - settings - ); -}; - /** * Function to register a block variations e.g. social icons different types. * @@ -275,7 +241,9 @@ export const registerCoreBlocks = () => { reusableBlock, search, embed, - ].forEach( registerBlock ); + ] + .filter( Boolean ) + .forEach( ( { init } ) => init() ); registerBlockVariations( socialLink ); setDefaultBlockName( paragraph.name ); diff --git a/packages/block-library/src/latest-comments/index.js b/packages/block-library/src/latest-comments/index.js index 6497e8b5b927d..5c2bab45638df 100644 --- a/packages/block-library/src/latest-comments/index.js +++ b/packages/block-library/src/latest-comments/index.js @@ -6,6 +6,7 @@ import { comment as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -18,3 +19,5 @@ export const settings = { example: {}, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/latest-comments/init.js b/packages/block-library/src/latest-comments/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/latest-comments/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/latest-posts/index.js b/packages/block-library/src/latest-posts/index.js index a0f8ffa74898b..5ea877488d72a 100644 --- a/packages/block-library/src/latest-posts/index.js +++ b/packages/block-library/src/latest-posts/index.js @@ -6,6 +6,7 @@ import { postList as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -19,3 +20,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/latest-posts/init.js b/packages/block-library/src/latest-posts/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/latest-posts/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/list-item/index.js b/packages/block-library/src/list-item/index.js index 480f811c85c1e..61756019baf92 100644 --- a/packages/block-library/src/list-item/index.js +++ b/packages/block-library/src/list-item/index.js @@ -6,6 +6,7 @@ import { listItem as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -25,3 +26,5 @@ export const settings = { }; }, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/list-item/init.js b/packages/block-library/src/list-item/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/list-item/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index 6df2d4ef40333..dc0f31822680a 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -7,6 +7,7 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -50,3 +51,5 @@ const settings = { }; export { settings }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/list/init.js b/packages/block-library/src/list/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/list/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/list/transforms.native.js b/packages/block-library/src/list/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/list/transforms.native.js +++ b/packages/block-library/src/list/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/loginout/index.js b/packages/block-library/src/loginout/index.js index 4f91f96242217..65c611621fd62 100644 --- a/packages/block-library/src/loginout/index.js +++ b/packages/block-library/src/loginout/index.js @@ -6,6 +6,7 @@ import { login as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/loginout/init.js b/packages/block-library/src/loginout/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/loginout/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/media-text/index.js b/packages/block-library/src/media-text/index.js index 3b7bf4b889ee9..373050cb77fd5 100644 --- a/packages/block-library/src/media-text/index.js +++ b/packages/block-library/src/media-text/index.js @@ -7,6 +7,7 @@ import { mediaAndText as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -48,3 +49,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/media-text/init.js b/packages/block-library/src/media-text/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/media-text/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/media-text/transforms.native.js b/packages/block-library/src/media-text/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/media-text/transforms.native.js +++ b/packages/block-library/src/media-text/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/missing/index.js b/packages/block-library/src/missing/index.js index 97db4e5c09b69..766381156eb34 100644 --- a/packages/block-library/src/missing/index.js +++ b/packages/block-library/src/missing/index.js @@ -6,6 +6,7 @@ import { getBlockType } from '@wordpress/blocks'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -34,3 +35,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/missing/init.js b/packages/block-library/src/missing/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/missing/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/more/index.js b/packages/block-library/src/more/index.js index efe76cf07a17f..4c1fad3cb67f4 100644 --- a/packages/block-library/src/more/index.js +++ b/packages/block-library/src/more/index.js @@ -6,6 +6,7 @@ import { more as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -27,3 +28,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/more/init.js b/packages/block-library/src/more/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/more/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/more/transforms.native.js b/packages/block-library/src/more/transforms.native.js index 0816b765fee29..c497af10c918f 100644 --- a/packages/block-library/src/more/transforms.native.js +++ b/packages/block-library/src/more/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/navigation-link/index.js b/packages/block-library/src/navigation-link/index.js index 04389ffb7d10d..3d1f0207ff955 100644 --- a/packages/block-library/src/navigation-link/index.js +++ b/packages/block-library/src/navigation-link/index.js @@ -9,6 +9,7 @@ import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -88,9 +89,12 @@ export const settings = { transforms, }; -// importing this file includes side effects. This is added in block-library/package.json under sideEffects -addFilter( - 'blocks.registerBlockType', - 'core/navigation-link', - enhanceNavigationLinkVariations -); +export const init = () => { + addFilter( + 'blocks.registerBlockType', + 'core/navigation-link', + enhanceNavigationLinkVariations + ); + + return initBlock( { name, metadata, settings } ); +}; diff --git a/packages/block-library/src/navigation-link/init.js b/packages/block-library/src/navigation-link/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/navigation-link/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/navigation-submenu/index.js b/packages/block-library/src/navigation-submenu/index.js index 9d270e3c9e003..c14ae6096fc9f 100644 --- a/packages/block-library/src/navigation-submenu/index.js +++ b/packages/block-library/src/navigation-submenu/index.js @@ -6,7 +6,7 @@ import { addSubmenu } from '@wordpress/icons'; /** * Internal dependencies */ - +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -27,3 +27,5 @@ export const settings = { transforms, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/navigation-submenu/init.js b/packages/block-library/src/navigation-submenu/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/navigation-submenu/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/navigation/index.js b/packages/block-library/src/navigation/index.js index fe3b2d555bd2e..c581d5d0bd03a 100644 --- a/packages/block-library/src/navigation/index.js +++ b/packages/block-library/src/navigation/index.js @@ -7,6 +7,7 @@ import { navigation as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -50,3 +51,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/navigation/init.js b/packages/block-library/src/navigation/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/navigation/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/nextpage/index.js b/packages/block-library/src/nextpage/index.js index fabb7349c45e5..5f425e7e952c6 100644 --- a/packages/block-library/src/nextpage/index.js +++ b/packages/block-library/src/nextpage/index.js @@ -6,6 +6,7 @@ import { pageBreak as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -22,3 +23,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/nextpage/init.js b/packages/block-library/src/nextpage/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/nextpage/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/nextpage/transforms.native.js b/packages/block-library/src/nextpage/transforms.native.js index 0816b765fee29..c497af10c918f 100644 --- a/packages/block-library/src/nextpage/transforms.native.js +++ b/packages/block-library/src/nextpage/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/page-list/index.js b/packages/block-library/src/page-list/index.js index ef026f2e916e9..7e13c23f229f2 100644 --- a/packages/block-library/src/page-list/index.js +++ b/packages/block-library/src/page-list/index.js @@ -6,6 +6,7 @@ import { pages as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit.js'; @@ -18,3 +19,5 @@ export const settings = { example: {}, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/page-list/init.js b/packages/block-library/src/page-list/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/page-list/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/paragraph/index.js b/packages/block-library/src/paragraph/index.js index 40a9db6d131db..70ae87ccf5f36 100644 --- a/packages/block-library/src/paragraph/index.js +++ b/packages/block-library/src/paragraph/index.js @@ -12,6 +12,7 @@ import { paragraph as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -55,3 +56,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/paragraph/init.js b/packages/block-library/src/paragraph/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/paragraph/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/paragraph/transforms.native.js b/packages/block-library/src/paragraph/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/paragraph/transforms.native.js +++ b/packages/block-library/src/paragraph/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/pattern/index.js b/packages/block-library/src/pattern/index.js index 5ab74fdd0c967..e4af712da8bb2 100644 --- a/packages/block-library/src/pattern/index.js +++ b/packages/block-library/src/pattern/index.js @@ -1,6 +1,7 @@ /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import PatternEdit from './edit'; @@ -10,3 +11,5 @@ export { metadata, name }; export const settings = { edit: PatternEdit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/pattern/init.js b/packages/block-library/src/pattern/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/pattern/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-author-biography/index.js b/packages/block-library/src/post-author-biography/index.js index 68fb2c2f737c2..8c91b99f7f6f5 100644 --- a/packages/block-library/src/post-author-biography/index.js +++ b/packages/block-library/src/post-author-biography/index.js @@ -1,13 +1,14 @@ /** - * Internal dependencies + * WordPress dependencies */ -import metadata from './block.json'; -import edit from './edit'; +import { postAuthor as icon } from '@wordpress/icons'; /** - * WordPress dependencies + * Internal dependencies */ -import { postAuthor as icon } from '@wordpress/icons'; +import initBlock from '../utils/init-block'; +import metadata from './block.json'; +import edit from './edit'; const { name } = metadata; export { metadata, name }; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author-biography/init.js b/packages/block-library/src/post-author-biography/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-author-biography/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-author-name/index.js b/packages/block-library/src/post-author-name/index.js index 34dcccd9acdd0..dce3e48c86f63 100644 --- a/packages/block-library/src/post-author-name/index.js +++ b/packages/block-library/src/post-author-name/index.js @@ -1,15 +1,16 @@ +/** + * WordPress dependencies + */ +import { postAuthor as icon } from '@wordpress/icons'; + /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import transforms from './transforms'; -/** - * WordPress dependencies - */ -import { postAuthor as icon } from '@wordpress/icons'; - const { name } = metadata; export { metadata, name }; @@ -18,3 +19,5 @@ export const settings = { transforms, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author-name/init.js b/packages/block-library/src/post-author-name/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-author-name/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-author/index.js b/packages/block-library/src/post-author/index.js index 68fb2c2f737c2..8c91b99f7f6f5 100644 --- a/packages/block-library/src/post-author/index.js +++ b/packages/block-library/src/post-author/index.js @@ -1,13 +1,14 @@ /** - * Internal dependencies + * WordPress dependencies */ -import metadata from './block.json'; -import edit from './edit'; +import { postAuthor as icon } from '@wordpress/icons'; /** - * WordPress dependencies + * Internal dependencies */ -import { postAuthor as icon } from '@wordpress/icons'; +import initBlock from '../utils/init-block'; +import metadata from './block.json'; +import edit from './edit'; const { name } = metadata; export { metadata, name }; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-author/init.js b/packages/block-library/src/post-author/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-author/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-comment/index.js b/packages/block-library/src/post-comment/index.js index 3a11344bad652..2fca916307a79 100644 --- a/packages/block-library/src/post-comment/index.js +++ b/packages/block-library/src/post-comment/index.js @@ -6,6 +6,7 @@ import { comment as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -18,3 +19,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comment/init.js b/packages/block-library/src/post-comment/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-comment/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-comments-count/index.js b/packages/block-library/src/post-comments-count/index.js index cdf53006c224e..1d2525ddf2d9e 100644 --- a/packages/block-library/src/post-comments-count/index.js +++ b/packages/block-library/src/post-comments-count/index.js @@ -6,6 +6,7 @@ import { postCommentsCount as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comments-count/init.js b/packages/block-library/src/post-comments-count/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-comments-count/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-comments-form/index.js b/packages/block-library/src/post-comments-form/index.js index bcc113faad411..4d0444194241d 100644 --- a/packages/block-library/src/post-comments-form/index.js +++ b/packages/block-library/src/post-comments-form/index.js @@ -6,6 +6,7 @@ import { postCommentsForm as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comments-form/init.js b/packages/block-library/src/post-comments-form/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-comments-form/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-comments-link/index.js b/packages/block-library/src/post-comments-link/index.js index f79a7ad55adaf..36e9673a08a1d 100644 --- a/packages/block-library/src/post-comments-link/index.js +++ b/packages/block-library/src/post-comments-link/index.js @@ -6,6 +6,7 @@ import { postCommentsCount as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { edit, icon, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-comments-link/init.js b/packages/block-library/src/post-comments-link/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-comments-link/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-content/index.js b/packages/block-library/src/post-content/index.js index e5025ba5110e0..80196db27878b 100644 --- a/packages/block-library/src/post-content/index.js +++ b/packages/block-library/src/post-content/index.js @@ -6,6 +6,7 @@ import { postContent as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-content/init.js b/packages/block-library/src/post-content/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-content/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-date/index.js b/packages/block-library/src/post-date/index.js index c2384da69192d..fddae539acfa3 100644 --- a/packages/block-library/src/post-date/index.js +++ b/packages/block-library/src/post-date/index.js @@ -6,6 +6,7 @@ import { postDate as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import deprecated from './deprecated'; @@ -18,3 +19,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-date/init.js b/packages/block-library/src/post-date/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-date/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-excerpt/index.js b/packages/block-library/src/post-excerpt/index.js index 1f035a7940a6d..41b868965eec5 100644 --- a/packages/block-library/src/post-excerpt/index.js +++ b/packages/block-library/src/post-excerpt/index.js @@ -6,6 +6,7 @@ import { postExcerpt as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import transforms from './transforms'; @@ -18,3 +19,5 @@ export const settings = { transforms, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-excerpt/init.js b/packages/block-library/src/post-excerpt/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-excerpt/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-featured-image/index.js b/packages/block-library/src/post-featured-image/index.js index 3fcab4a081367..aa28444114fb3 100644 --- a/packages/block-library/src/post-featured-image/index.js +++ b/packages/block-library/src/post-featured-image/index.js @@ -6,6 +6,7 @@ import { postFeaturedImage as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-featured-image/init.js b/packages/block-library/src/post-featured-image/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-featured-image/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-navigation-link/index.js b/packages/block-library/src/post-navigation-link/index.js index 5f564739f69d0..e85e594990adb 100644 --- a/packages/block-library/src/post-navigation-link/index.js +++ b/packages/block-library/src/post-navigation-link/index.js @@ -1,6 +1,7 @@ /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import variations from './variations'; @@ -12,3 +13,5 @@ export const settings = { edit, variations, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-navigation-link/init.js b/packages/block-library/src/post-navigation-link/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-navigation-link/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-template/index.js b/packages/block-library/src/post-template/index.js index ace8add51d328..bc6f8ffa13ab6 100644 --- a/packages/block-library/src/post-template/index.js +++ b/packages/block-library/src/post-template/index.js @@ -6,6 +6,7 @@ import { layout } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -18,3 +19,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-template/init.js b/packages/block-library/src/post-template/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-template/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-terms/index.js b/packages/block-library/src/post-terms/index.js index 58390cf91e80f..3a00f04b77fd2 100644 --- a/packages/block-library/src/post-terms/index.js +++ b/packages/block-library/src/post-terms/index.js @@ -7,6 +7,7 @@ import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import enhanceVariations from './hooks'; @@ -19,9 +20,12 @@ export const settings = { edit, }; -// Importing this file includes side effects. This is added in block-library/package.json under sideEffects -addFilter( - 'blocks.registerBlockType', - 'core/template-part', - enhanceVariations -); +export const init = () => { + addFilter( + 'blocks.registerBlockType', + 'core/template-part', + enhanceVariations + ); + + return initBlock( { name, metadata, settings } ); +}; diff --git a/packages/block-library/src/post-terms/init.js b/packages/block-library/src/post-terms/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-terms/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/post-title/index.js b/packages/block-library/src/post-title/index.js index 374a379746df3..86bdab0dbccbf 100644 --- a/packages/block-library/src/post-title/index.js +++ b/packages/block-library/src/post-title/index.js @@ -6,6 +6,7 @@ import { title as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import deprecated from './deprecated'; @@ -18,3 +19,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/post-title/init.js b/packages/block-library/src/post-title/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/post-title/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/preformatted/index.js b/packages/block-library/src/preformatted/index.js index 2962464dce423..491acd02bab1d 100644 --- a/packages/block-library/src/preformatted/index.js +++ b/packages/block-library/src/preformatted/index.js @@ -7,6 +7,7 @@ import { preformatted as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -37,3 +38,5 @@ export const settings = { }; }, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/preformatted/init.js b/packages/block-library/src/preformatted/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/preformatted/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/preformatted/transforms.native.js b/packages/block-library/src/preformatted/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/preformatted/transforms.native.js +++ b/packages/block-library/src/preformatted/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/pullquote/index.js b/packages/block-library/src/pullquote/index.js index 41b97f510c8eb..9d2b42f7698ab 100644 --- a/packages/block-library/src/pullquote/index.js +++ b/packages/block-library/src/pullquote/index.js @@ -7,6 +7,7 @@ import { pullquote as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -34,3 +35,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/pullquote/init.js b/packages/block-library/src/pullquote/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/pullquote/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/pullquote/transforms.native.js b/packages/block-library/src/pullquote/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/pullquote/transforms.native.js +++ b/packages/block-library/src/pullquote/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/query-no-results/index.js b/packages/block-library/src/query-no-results/index.js index cd0c3209e00a9..1c56638cdfdba 100644 --- a/packages/block-library/src/query-no-results/index.js +++ b/packages/block-library/src/query-no-results/index.js @@ -6,6 +6,7 @@ import { loop as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -18,3 +19,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-no-results/init.js b/packages/block-library/src/query-no-results/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/query-no-results/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/query-pagination-next/index.js b/packages/block-library/src/query-pagination-next/index.js index d339ed2ca7581..2df0e8da6aa99 100644 --- a/packages/block-library/src/query-pagination-next/index.js +++ b/packages/block-library/src/query-pagination-next/index.js @@ -6,6 +6,7 @@ import { queryPaginationNext as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination-next/init.js b/packages/block-library/src/query-pagination-next/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/query-pagination-next/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/query-pagination-numbers/index.js b/packages/block-library/src/query-pagination-numbers/index.js index 9f1818b1f14a0..3fd903e2d9ef4 100644 --- a/packages/block-library/src/query-pagination-numbers/index.js +++ b/packages/block-library/src/query-pagination-numbers/index.js @@ -6,6 +6,7 @@ import { queryPaginationNumbers as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination-numbers/init.js b/packages/block-library/src/query-pagination-numbers/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/query-pagination-numbers/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/query-pagination-previous/index.js b/packages/block-library/src/query-pagination-previous/index.js index a66be07616944..80e555ccc79d9 100644 --- a/packages/block-library/src/query-pagination-previous/index.js +++ b/packages/block-library/src/query-pagination-previous/index.js @@ -6,6 +6,7 @@ import { queryPaginationPrevious as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination-previous/init.js b/packages/block-library/src/query-pagination-previous/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/query-pagination-previous/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/query-pagination/index.js b/packages/block-library/src/query-pagination/index.js index 05124f3321b67..b113a8384b043 100644 --- a/packages/block-library/src/query-pagination/index.js +++ b/packages/block-library/src/query-pagination/index.js @@ -6,6 +6,7 @@ import { queryPagination as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -20,3 +21,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-pagination/init.js b/packages/block-library/src/query-pagination/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/query-pagination/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/query-title/index.js b/packages/block-library/src/query-title/index.js index 236a7c5898a58..875c2b8b86504 100644 --- a/packages/block-library/src/query-title/index.js +++ b/packages/block-library/src/query-title/index.js @@ -1,16 +1,17 @@ +/** + * WordPress dependencies + */ +import { title as icon } from '@wordpress/icons'; + /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import variations from './variations'; import deprecated from './deprecated'; -/** - * WordPress dependencies - */ -import { title as icon } from '@wordpress/icons'; - const { name } = metadata; export { metadata, name }; @@ -20,3 +21,5 @@ export const settings = { variations, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/query-title/init.js b/packages/block-library/src/query-title/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/query-title/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/query/index.js b/packages/block-library/src/query/index.js index 4a87004087997..baf58470b76ac 100644 --- a/packages/block-library/src/query/index.js +++ b/packages/block-library/src/query/index.js @@ -7,6 +7,7 @@ import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import save from './save'; @@ -25,6 +26,8 @@ export const settings = { deprecated, }; -// Importing this file includes side effects and is added -// in block-library/package.json under `sideEffects`. -addFilter( 'editor.BlockEdit', 'core/query', queryInspectorControls ); +export const init = () => { + addFilter( 'editor.BlockEdit', 'core/query', queryInspectorControls ); + + return initBlock( { name, metadata, settings } ); +}; diff --git a/packages/block-library/src/query/init.js b/packages/block-library/src/query/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/query/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index 8140ad49f3495..d67685f3561b0 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -7,6 +7,7 @@ import { quote as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -37,3 +38,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/quote/init.js b/packages/block-library/src/quote/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/quote/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/quote/transforms.native.js b/packages/block-library/src/quote/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/quote/transforms.native.js +++ b/packages/block-library/src/quote/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/read-more/index.js b/packages/block-library/src/read-more/index.js index e463830969348..497cd77f429e6 100644 --- a/packages/block-library/src/read-more/index.js +++ b/packages/block-library/src/read-more/index.js @@ -6,6 +6,7 @@ import { link as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/read-more/init.js b/packages/block-library/src/read-more/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/read-more/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/rss/index.js b/packages/block-library/src/rss/index.js index f0c4c3c3789bf..439d14c4edcdd 100644 --- a/packages/block-library/src/rss/index.js +++ b/packages/block-library/src/rss/index.js @@ -6,6 +6,7 @@ import { rss as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -22,3 +23,5 @@ export const settings = { }, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/rss/init.js b/packages/block-library/src/rss/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/rss/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/search/index.js b/packages/block-library/src/search/index.js index 7e946636c5048..441336316415b 100644 --- a/packages/block-library/src/search/index.js +++ b/packages/block-library/src/search/index.js @@ -6,6 +6,7 @@ import { search as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import variations from './variations'; @@ -20,3 +21,5 @@ export const settings = { variations, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/search/init.js b/packages/block-library/src/search/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/search/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/separator/index.js b/packages/block-library/src/separator/index.js index 4a73823a81224..712caef775146 100644 --- a/packages/block-library/src/separator/index.js +++ b/packages/block-library/src/separator/index.js @@ -6,6 +6,7 @@ import { separator as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -29,3 +30,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/separator/init.js b/packages/block-library/src/separator/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/separator/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/separator/transforms.native.js b/packages/block-library/src/separator/transforms.native.js index 0816b765fee29..c497af10c918f 100644 --- a/packages/block-library/src/separator/transforms.native.js +++ b/packages/block-library/src/separator/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/shortcode/index.js b/packages/block-library/src/shortcode/index.js index 37749dbfa7365..6fe36bdbfb3d3 100644 --- a/packages/block-library/src/shortcode/index.js +++ b/packages/block-library/src/shortcode/index.js @@ -6,6 +6,7 @@ import { shortcode as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import save from './save'; import transforms from './transforms'; @@ -21,3 +22,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/shortcode/init.js b/packages/block-library/src/shortcode/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/shortcode/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/shortcode/transforms.native.js b/packages/block-library/src/shortcode/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/shortcode/transforms.native.js +++ b/packages/block-library/src/shortcode/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/site-logo/index.js b/packages/block-library/src/site-logo/index.js index d5e652d958057..68d8eb6f8b930 100644 --- a/packages/block-library/src/site-logo/index.js +++ b/packages/block-library/src/site-logo/index.js @@ -6,6 +6,7 @@ import { siteLogo as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import transforms from './transforms'; @@ -18,3 +19,5 @@ export const settings = { edit, transforms, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/site-logo/init.js b/packages/block-library/src/site-logo/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/site-logo/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/site-tagline/index.js b/packages/block-library/src/site-tagline/index.js index 89477ca98f643..1d0090f9dcea1 100644 --- a/packages/block-library/src/site-tagline/index.js +++ b/packages/block-library/src/site-tagline/index.js @@ -1,6 +1,7 @@ /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import icon from './icon'; @@ -14,3 +15,5 @@ export const settings = { edit, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/site-tagline/init.js b/packages/block-library/src/site-tagline/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/site-tagline/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/site-title/index.js b/packages/block-library/src/site-title/index.js index 2c38d37390a76..01fe15598d6f1 100644 --- a/packages/block-library/src/site-title/index.js +++ b/packages/block-library/src/site-title/index.js @@ -6,6 +6,7 @@ import { mapMarker as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import deprecated from './deprecated'; @@ -20,3 +21,5 @@ export const settings = { transforms, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/site-title/init.js b/packages/block-library/src/site-title/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/site-title/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/social-link/index.js b/packages/block-library/src/social-link/index.js index 2944183dc4089..161e6f2697acc 100644 --- a/packages/block-library/src/social-link/index.js +++ b/packages/block-library/src/social-link/index.js @@ -6,6 +6,7 @@ import { share as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import variations from './variations'; @@ -19,3 +20,5 @@ export const settings = { edit, variations, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/social-link/init.js b/packages/block-library/src/social-link/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/social-link/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/social-links/index.js b/packages/block-library/src/social-links/index.js index b323624b2b5b6..601a8c63ec539 100644 --- a/packages/block-library/src/social-links/index.js +++ b/packages/block-library/src/social-links/index.js @@ -6,6 +6,7 @@ import { share as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -46,3 +47,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/social-links/init.js b/packages/block-library/src/social-links/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/social-links/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/spacer/index.js b/packages/block-library/src/spacer/index.js index 4b71001cefad8..d77c51bc96cea 100644 --- a/packages/block-library/src/spacer/index.js +++ b/packages/block-library/src/spacer/index.js @@ -6,6 +6,7 @@ import { resizeCornerNE as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -21,3 +22,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/spacer/init.js b/packages/block-library/src/spacer/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/spacer/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/table-of-contents/index.js b/packages/block-library/src/table-of-contents/index.js index 62bb5e89953a1..8952f0ff381bb 100644 --- a/packages/block-library/src/table-of-contents/index.js +++ b/packages/block-library/src/table-of-contents/index.js @@ -1,6 +1,7 @@ /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import icon from './icon'; @@ -15,3 +16,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/table-of-contents/init.js b/packages/block-library/src/table-of-contents/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/table-of-contents/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/table/index.js b/packages/block-library/src/table/index.js index cfa7bb0b02aa6..5839abc4c19f2 100644 --- a/packages/block-library/src/table/index.js +++ b/packages/block-library/src/table/index.js @@ -7,6 +7,7 @@ import { blockTable as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -96,3 +97,5 @@ export const settings = { save, deprecated, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/table/init.js b/packages/block-library/src/table/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/table/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/tag-cloud/index.js b/packages/block-library/src/tag-cloud/index.js index 503dcb934ecc3..6dc0931663fcd 100644 --- a/packages/block-library/src/tag-cloud/index.js +++ b/packages/block-library/src/tag-cloud/index.js @@ -6,6 +6,7 @@ import { tag as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import transforms from './transforms'; import metadata from './block.json'; import edit from './edit'; @@ -20,3 +21,5 @@ export const settings = { edit, transforms, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/tag-cloud/init.js b/packages/block-library/src/tag-cloud/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/tag-cloud/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/template-part/index.js b/packages/block-library/src/template-part/index.js index 18d268fa13803..562e4f713ee1a 100644 --- a/packages/block-library/src/template-part/index.js +++ b/packages/block-library/src/template-part/index.js @@ -15,6 +15,7 @@ import { decodeEntities } from '@wordpress/html-entities'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; import { enhanceTemplatePartVariations } from './variations'; @@ -48,37 +49,42 @@ export const settings = { edit, }; -// Importing this file includes side effects. This is added in block-library/package.json under sideEffects -addFilter( - 'blocks.registerBlockType', - 'core/template-part', - enhanceTemplatePartVariations -); +export const init = () => { + addFilter( + 'blocks.registerBlockType', + 'core/template-part', + enhanceTemplatePartVariations + ); -// Prevent adding template parts inside post templates. -const DISALLOWED_PARENTS = [ 'core/post-template', 'core/post-content' ]; -addFilter( - 'blockEditor.__unstableCanInsertBlockType', - 'removeTemplatePartsFromPostTemplates', - ( - can, - blockType, - rootClientId, - { getBlock, getBlockParentsByBlockName } - ) => { - if ( blockType.name !== 'core/template-part' ) { - return can; - } + // Prevent adding template parts inside post templates. + const DISALLOWED_PARENTS = [ 'core/post-template', 'core/post-content' ]; + addFilter( + 'blockEditor.__unstableCanInsertBlockType', + 'removeTemplatePartsFromPostTemplates', + ( + can, + blockType, + rootClientId, + { getBlock, getBlockParentsByBlockName } + ) => { + if ( blockType.name !== 'core/template-part' ) { + return can; + } - for ( const disallowedParentType of DISALLOWED_PARENTS ) { - const hasDisallowedParent = - getBlock( rootClientId )?.name === disallowedParentType || - getBlockParentsByBlockName( rootClientId, disallowedParentType ) - .length; - if ( hasDisallowedParent ) { - return false; + for ( const disallowedParentType of DISALLOWED_PARENTS ) { + const hasDisallowedParent = + getBlock( rootClientId )?.name === disallowedParentType || + getBlockParentsByBlockName( + rootClientId, + disallowedParentType + ).length; + if ( hasDisallowedParent ) { + return false; + } } + return true; } - return true; - } -); + ); + + return initBlock( { name, metadata, settings } ); +}; diff --git a/packages/block-library/src/template-part/init.js b/packages/block-library/src/template-part/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/template-part/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/term-description/index.js b/packages/block-library/src/term-description/index.js index 76670d556d075..0ff710a91f5d5 100644 --- a/packages/block-library/src/term-description/index.js +++ b/packages/block-library/src/term-description/index.js @@ -6,6 +6,7 @@ import { termDescription as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; @@ -16,3 +17,5 @@ export const settings = { icon, edit, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/term-description/init.js b/packages/block-library/src/term-description/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/term-description/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/text-columns/index.js b/packages/block-library/src/text-columns/index.js index 29c11a7c05bb4..c0bce35b96f4e 100644 --- a/packages/block-library/src/text-columns/index.js +++ b/packages/block-library/src/text-columns/index.js @@ -1,6 +1,7 @@ /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -21,3 +22,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/text-columns/init.js b/packages/block-library/src/text-columns/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/text-columns/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/text-columns/transforms.native.js b/packages/block-library/src/text-columns/transforms.native.js index 032a346425894..cea16e6fd62a2 100644 --- a/packages/block-library/src/text-columns/transforms.native.js +++ b/packages/block-library/src/text-columns/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/utils/init-block.js b/packages/block-library/src/utils/init-block.js new file mode 100644 index 0000000000000..fb48f422a07cf --- /dev/null +++ b/packages/block-library/src/utils/init-block.js @@ -0,0 +1,20 @@ +/** + * WordPress dependencies + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Function to register an individual block. + * + * @param {Object} block The block to be registered. + * + * @return {?WPBlockType} The block, if it has been successfully registered; + * otherwise `undefined`. + */ +export default function initBlock( block ) { + if ( ! block ) { + return; + } + const { metadata, settings, name } = block; + return registerBlockType( { name, ...metadata }, settings ); +} diff --git a/packages/block-library/src/utils/init-block.native.js b/packages/block-library/src/utils/init-block.native.js new file mode 100644 index 0000000000000..699473e0ea5a2 --- /dev/null +++ b/packages/block-library/src/utils/init-block.native.js @@ -0,0 +1,40 @@ +/** + * WordPress dependencies + */ +import { registerBlockType } from '@wordpress/blocks'; + +const ALLOWED_BLOCKS_GRADIENT_SUPPORT = [ 'core/button' ]; + +/** + * Function to register an individual block. + * + * @param {Object} block The block to be registered. + * + * @return {?WPBlockType} The block, if it has been successfully registered; + * otherwise `undefined`. + */ +export default function initBlock( block ) { + if ( ! block ) { + return; + } + const { metadata, settings, name } = block; + const { supports } = metadata; + + return registerBlockType( + { + name, + ...metadata, + // Gradients support only available for blocks listed in ALLOWED_BLOCKS_GRADIENT_SUPPORT. + ...( ! ALLOWED_BLOCKS_GRADIENT_SUPPORT.includes( name ) && + supports?.color?.gradients + ? { + supports: { + ...supports, + color: { ...supports.color, gradients: false }, + }, + } + : {} ), + }, + settings + ); +} diff --git a/packages/block-library/src/is-block-metadata-experimental.js b/packages/block-library/src/utils/is-block-metadata-experimental.js similarity index 100% rename from packages/block-library/src/is-block-metadata-experimental.js rename to packages/block-library/src/utils/is-block-metadata-experimental.js diff --git a/packages/block-library/src/transformationCategories.native.js b/packages/block-library/src/utils/transformation-categories.native.js similarity index 100% rename from packages/block-library/src/transformationCategories.native.js rename to packages/block-library/src/utils/transformation-categories.native.js diff --git a/packages/block-library/src/verse/index.js b/packages/block-library/src/verse/index.js index a880300e8793a..6cf8b9b9fb9e4 100644 --- a/packages/block-library/src/verse/index.js +++ b/packages/block-library/src/verse/index.js @@ -7,6 +7,7 @@ import { verse as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import deprecated from './deprecated'; import edit from './edit'; import metadata from './block.json'; @@ -39,3 +40,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/verse/init.js b/packages/block-library/src/verse/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/verse/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/verse/transforms.native.js b/packages/block-library/src/verse/transforms.native.js index 21b6405a15030..25ce6b9b40c43 100644 --- a/packages/block-library/src/verse/transforms.native.js +++ b/packages/block-library/src/verse/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/block-library/src/video/index.js b/packages/block-library/src/video/index.js index 029df51c5ebab..688d5ca944f84 100644 --- a/packages/block-library/src/video/index.js +++ b/packages/block-library/src/video/index.js @@ -7,6 +7,7 @@ import { video as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import initBlock from '../utils/init-block'; import edit from './edit'; import metadata from './block.json'; import save from './save'; @@ -29,3 +30,5 @@ export const settings = { edit, save, }; + +export const init = () => initBlock( { name, metadata, settings } ); diff --git a/packages/block-library/src/video/init.js b/packages/block-library/src/video/init.js new file mode 100644 index 0000000000000..79f0492c2cb2f --- /dev/null +++ b/packages/block-library/src/video/init.js @@ -0,0 +1,6 @@ +/** + * Internal dependencies + */ +import { init } from './'; + +export default init(); diff --git a/packages/block-library/src/video/transforms.native.js b/packages/block-library/src/video/transforms.native.js index 839cdfe3c9381..a9bf418541e88 100644 --- a/packages/block-library/src/video/transforms.native.js +++ b/packages/block-library/src/video/transforms.native.js @@ -2,7 +2,7 @@ * Internal dependencies */ import webTransforms from './transforms.js'; -import transformationCategories from '../transformationCategories'; +import transformationCategories from '../utils/transformation-categories'; const transforms = { ...webTransforms, diff --git a/packages/format-library/src/text-color/test/index.native.js b/packages/format-library/src/text-color/test/index.native.js index e37aad76e5dc3..2ad92c404d7c8 100644 --- a/packages/format-library/src/text-color/test/index.native.js +++ b/packages/format-library/src/text-color/test/index.native.js @@ -12,7 +12,7 @@ import { * WordPress dependencies */ import { setDefaultBlockName, unregisterBlockType } from '@wordpress/blocks'; -import { registerBlock, coreBlocks } from '@wordpress/block-library'; +import { coreBlocks } from '@wordpress/block-library'; const COLOR_PINK = '#f78da7'; const paragraph = coreBlocks[ 'core/paragraph' ]; @@ -22,7 +22,7 @@ const TEXT_WITH_COLOR = ` `; beforeAll( () => { - registerBlock( paragraph ); + paragraph.init(); setDefaultBlockName( paragraph.name ); } ); @@ -164,7 +164,7 @@ describe( 'Text color', () => { initialHtml: `

this is test

- +

this is a test

`, diff --git a/packages/rich-text/src/test/index.native.js b/packages/rich-text/src/test/index.native.js index 1bb288139bc57..dad84f207dc4d 100644 --- a/packages/rich-text/src/test/index.native.js +++ b/packages/rich-text/src/test/index.native.js @@ -9,7 +9,7 @@ import { getEditorHtml, render, initializeEditor } from 'test/helpers'; */ import { select } from '@wordpress/data'; import { store as blockEditorStore } from '@wordpress/block-editor'; -import { coreBlocks, registerBlock } from '@wordpress/block-library'; +import { coreBlocks } from '@wordpress/block-library'; import { getBlockTypes, setDefaultBlockName, @@ -60,7 +60,7 @@ describe( '', () => { beforeAll( () => { // Register Paragraph block. const paragraph = coreBlocks[ 'core/paragraph' ]; - registerBlock( paragraph ); + paragraph.init(); setDefaultBlockName( paragraph.name ); } ); diff --git a/test/native/integration-test-helpers/setup-core-blocks.js b/test/native/integration-test-helpers/setup-core-blocks.js index 47b074dc3ece3..fd71e51a2bab8 100644 --- a/test/native/integration-test-helpers/setup-core-blocks.js +++ b/test/native/integration-test-helpers/setup-core-blocks.js @@ -6,11 +6,7 @@ import { setDefaultBlockName, unregisterBlockType, } from '@wordpress/blocks'; -import { - coreBlocks, - registerBlock, - registerCoreBlocks, -} from '@wordpress/block-library'; +import { coreBlocks, registerCoreBlocks } from '@wordpress/block-library'; /** * Registers all core blocks or a specific list of blocks before running tests. @@ -21,15 +17,13 @@ import { export const setupCoreBlocks = ( blocks ) => { beforeAll( () => { if ( blocks ) { - blocks.forEach( ( blockName ) => - registerBlock( coreBlocks[ blockName ] ) - ); + blocks.forEach( ( blockName ) => coreBlocks[ blockName ].init() ); // Paragraph block should always be registered as it's // the default block. const paragraphBlock = coreBlocks[ 'core/paragraph' ]; if ( ! blocks.includes( paragraphBlock.name ) ) { - registerBlock( paragraphBlock ); + paragraphBlock.init(); } setDefaultBlockName( paragraphBlock.name );