diff --git a/babel.config.js b/babel.config.js index b56ad5b149478b..7679cc1e837041 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,5 +3,6 @@ module.exports = function( api ) { return { presets: [ '@wordpress/babel-preset-default' ], + plugins: [ 'babel-plugin-inline-json-import' ], }; }; diff --git a/package-lock.json b/package-lock.json index 40ebb372807de8..3d13faa76d4059 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4065,6 +4065,15 @@ } } }, + "babel-plugin-inline-json-import": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/babel-plugin-inline-json-import/-/babel-plugin-inline-json-import-0.3.2.tgz", + "integrity": "sha512-QNNJx08KjmMT25Cw7rAPQ6dlREDPiZGDyApHL8KQ9vrQHbrr4PTi7W8g1tMMZPz0jEMd39nx/eH7xjnDNxq5sA==", + "dev": true, + "requires": { + "decache": "^4.5.1" + } + }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -4699,6 +4708,12 @@ "integrity": "sha1-JtII6onje1y95gJQoV8DHBak1ms=", "dev": true }, + "callsite": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz", + "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA=", + "dev": true + }, "callsites": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.0.0.tgz", @@ -7211,6 +7226,15 @@ "integrity": "sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=", "dev": true }, + "decache": { + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/decache/-/decache-4.5.1.tgz", + "integrity": "sha512-5J37nATc6FmOTLbcsr9qx7Nm28qQyg1SK4xyEHqM0IBkNhWFp0Sm+vKoWYHD8wq+OUEb9jLyaKFfzzd1A9hcoA==", + "dev": true, + "requires": { + "callsite": "^1.0.0" + } + }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", diff --git a/package.json b/package.json index 0f979954ba2dc0..ee92bafcfda43d 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "@wordpress/npm-package-json-lint-config": "file:packages/npm-package-json-lint-config", "@wordpress/postcss-themes": "file:packages/postcss-themes", "@wordpress/scripts": "file:packages/scripts", + "babel-plugin-inline-json-import": "0.3.2", "benchmark": "2.1.4", "browserslist": "4.4.1", "chalk": "2.4.1", diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 81a0e9bec632b4..65c4dd6d4144f6 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -9,6 +9,7 @@ import { setDefaultBlockName, setFreeformContentHandlerName, setUnregisteredTypeHandlerName, + unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase } from '@wordpress/blocks'; /** @@ -120,7 +121,10 @@ export const registerCoreBlocks = () => { if ( ! block ) { return; } - const { name, settings } = block; + const { metadata, settings, name } = block; + if ( metadata ) { + unstable__bootstrapServerSideBlockDefinitions( { [ name ]: metadata } ); // eslint-disable-line camelcase + } registerBlockType( name, settings ); } ); diff --git a/packages/block-library/src/text-columns/block.json b/packages/block-library/src/text-columns/block.json new file mode 100644 index 00000000000000..cf86b62ec572c0 --- /dev/null +++ b/packages/block-library/src/text-columns/block.json @@ -0,0 +1,26 @@ +{ + "name": "core/text-columns", + "icon": "columns", + "category": "layout", + "attributes": { + "content": { + "type": "array", + "source": "query", + "selector": "p", + "query": { + "children": { + "type": "string", + "source": "html" + } + }, + "default": [ {}, {} ] + }, + "columns": { + "type": "number", + "default": 2 + }, + "width": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/text-columns/index.js b/packages/block-library/src/text-columns/index.js index f14b3b8153baa8..6ec2e8b977109a 100644 --- a/packages/block-library/src/text-columns/index.js +++ b/packages/block-library/src/text-columns/index.js @@ -18,7 +18,14 @@ import { } from '@wordpress/block-editor'; import deprecated from '@wordpress/deprecated'; -export const name = 'core/text-columns'; +/** + * Internal dependencies + */ +import metadata from './block.json'; + +const { name } = metadata; + +export { metadata, name }; export const settings = { // Disable insertion as this block is deprecated and ultimately replaced by the Columns block. @@ -30,32 +37,6 @@ export const settings = { description: __( 'This block is deprecated. Please use the Columns block instead.' ), - icon: 'columns', - - category: 'layout', - - attributes: { - content: { - type: 'array', - source: 'query', - selector: 'p', - query: { - children: { - type: 'string', - source: 'html', - }, - }, - default: [ {}, {} ], - }, - columns: { - type: 'number', - default: 2, - }, - width: { - type: 'string', - }, - }, - transforms: { to: [ { diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index f6d5a29544803c..61b1d8f2c3c442 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -49,12 +49,15 @@ import { isValidIcon, normalizeIconObject } from './utils'; let serverSideBlockDefinitions = {}; /** - * Set the server side block definition of blocks. + * Sets the server side block definition of blocks. * * @param {Object} definitions Server-side block definitions */ export function unstable__bootstrapServerSideBlockDefinitions( definitions ) { // eslint-disable-line camelcase - serverSideBlockDefinitions = definitions; + serverSideBlockDefinitions = { + ...serverSideBlockDefinitions, + ...definitions, + }; } /** diff --git a/playground/.babelrc b/playground/.babelrc index 4e7ed80cab13cd..5b8ba9724e13af 100644 --- a/playground/.babelrc +++ b/playground/.babelrc @@ -3,6 +3,7 @@ "plugins": [ [ "@babel/plugin-transform-react-jsx", { "pragma": "createElement" - } ] + } ], + "babel-plugin-inline-json-import" ] -} \ No newline at end of file +}