From 4ca40d88657dd4f0cce6e84d9945108da408e612 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 2 Apr 2019 15:06:33 +0200 Subject: [PATCH 1/2] Block library: Introduce block.json metadata for all client side blocks --- packages/block-library/src/audio/block.json | 38 +++++++++++ packages/block-library/src/audio/index.js | 42 ++---------- packages/block-library/src/button/block.json | 35 ++++++++++ packages/block-library/src/button/index.js | 39 +---------- packages/block-library/src/classic/block.json | 10 +++ packages/block-library/src/classic/index.js | 14 ++-- packages/block-library/src/code/block.json | 11 +++ packages/block-library/src/code/index.js | 15 ++-- packages/block-library/src/column/block.json | 9 +++ .../{columns/column.js => column/index.js} | 17 +++-- packages/block-library/src/columns/block.json | 13 ++++ packages/block-library/src/columns/index.js | 17 ++--- packages/block-library/src/cover/block.json | 33 +++++++++ packages/block-library/src/cover/index.js | 37 +--------- packages/block-library/src/file/block.json | 4 ++ packages/block-library/src/file/index.js | 7 +- packages/block-library/src/gallery/block.json | 55 +++++++++++++++ packages/block-library/src/gallery/index.js | 57 +--------------- packages/block-library/src/heading/block.json | 22 ++++++ packages/block-library/src/heading/index.js | 30 ++------ packages/block-library/src/html/block.json | 10 +++ packages/block-library/src/html/index.js | 14 ++-- packages/block-library/src/image/block.json | 64 +++++++++++++++++ packages/block-library/src/image/index.js | 68 +------------------ packages/block-library/src/index.js | 11 ++- packages/block-library/src/index.native.js | 7 +- packages/block-library/src/list/block.json | 17 +++++ packages/block-library/src/list/index.js | 24 ++----- .../block-library/src/media-text/block.json | 56 +++++++++++++++ .../block-library/src/media-text/index.js | 60 +--------------- packages/block-library/src/missing/block.json | 16 +++++ packages/block-library/src/missing/index.js | 19 ++---- packages/block-library/src/more/block.json | 13 ++++ packages/block-library/src/more/index.js | 17 ++--- .../block-library/src/nextpage/block.json | 4 ++ packages/block-library/src/nextpage/index.js | 9 ++- .../block-library/src/paragraph/block.json | 44 ++++++++++++ packages/block-library/src/paragraph/index.js | 52 ++------------ .../block-library/src/preformatted/block.json | 12 ++++ .../block-library/src/preformatted/index.js | 16 ++--- .../block-library/src/pullquote/block.json | 30 ++++++++ packages/block-library/src/pullquote/index.js | 34 +--------- packages/block-library/src/quote/block.json | 4 ++ packages/block-library/src/quote/index.js | 8 ++- packages/block-library/src/section/block.json | 12 ++++ packages/block-library/src/section/index.js | 16 ++--- .../block-library/src/separator/block.json | 4 ++ packages/block-library/src/separator/index.js | 7 +- packages/block-library/src/spacer/block.json | 10 +++ packages/block-library/src/spacer/index.js | 14 ++-- packages/block-library/src/subhead/block.json | 14 ++++ packages/block-library/src/subhead/index.js | 18 ++--- .../block-library/src/template/block.json | 4 ++ packages/block-library/src/template/index.js | 7 +- .../block-library/src/text-columns/index.js | 4 -- packages/block-library/src/verse/block.json | 15 ++++ packages/block-library/src/verse/index.js | 19 ++---- packages/block-library/src/video/block.json | 64 +++++++++++++++++ packages/block-library/src/video/index.js | 68 ++----------------- .../fixtures/blocks/core__cover.json | 2 +- .../blocks/core__cover__video-overlay.json | 2 +- .../fixtures/blocks/core__cover__video.json | 2 +- .../blocks/core__image__center-caption.json | 4 +- ..._media-text__media-right-custom-width.json | 2 +- .../blocks/core__paragraph__align-right.json | 2 +- .../blocks-raw-handling.spec.js.snap | 6 +- 66 files changed, 757 insertions(+), 653 deletions(-) create mode 100644 packages/block-library/src/audio/block.json create mode 100644 packages/block-library/src/button/block.json create mode 100644 packages/block-library/src/classic/block.json create mode 100644 packages/block-library/src/code/block.json create mode 100644 packages/block-library/src/column/block.json rename packages/block-library/src/{columns/column.js => column/index.js} (95%) create mode 100644 packages/block-library/src/columns/block.json create mode 100644 packages/block-library/src/cover/block.json create mode 100644 packages/block-library/src/file/block.json create mode 100644 packages/block-library/src/gallery/block.json create mode 100644 packages/block-library/src/heading/block.json create mode 100644 packages/block-library/src/html/block.json create mode 100644 packages/block-library/src/image/block.json create mode 100644 packages/block-library/src/list/block.json create mode 100644 packages/block-library/src/media-text/block.json create mode 100644 packages/block-library/src/missing/block.json create mode 100644 packages/block-library/src/more/block.json create mode 100644 packages/block-library/src/nextpage/block.json create mode 100644 packages/block-library/src/paragraph/block.json create mode 100644 packages/block-library/src/preformatted/block.json create mode 100644 packages/block-library/src/pullquote/block.json create mode 100644 packages/block-library/src/quote/block.json create mode 100644 packages/block-library/src/section/block.json create mode 100644 packages/block-library/src/separator/block.json create mode 100644 packages/block-library/src/spacer/block.json create mode 100644 packages/block-library/src/subhead/block.json create mode 100644 packages/block-library/src/template/block.json create mode 100644 packages/block-library/src/verse/block.json create mode 100644 packages/block-library/src/video/block.json diff --git a/packages/block-library/src/audio/block.json b/packages/block-library/src/audio/block.json new file mode 100644 index 0000000000000..c3bfc5fe13fe5 --- /dev/null +++ b/packages/block-library/src/audio/block.json @@ -0,0 +1,38 @@ +{ + "name": "core/audio", + "category": "common", + "attributes": { + "src": { + "type": "string", + "source": "attribute", + "selector": "audio", + "attribute": "src" + }, + "caption": { + "type": "string", + "source": "html", + "selector": "figcaption" + }, + "id": { + "type": "number" + }, + "autoplay": { + "type": "boolean", + "source": "attribute", + "selector": "audio", + "attribute": "autoplay" + }, + "loop": { + "type": "boolean", + "source": "attribute", + "selector": "audio", + "attribute": "loop" + }, + "preload": { + "type": "string", + "source": "attribute", + "selector": "audio", + "attribute": "preload" + } + } +} diff --git a/packages/block-library/src/audio/index.js b/packages/block-library/src/audio/index.js index f51937c8d4614..4da18817e2076 100644 --- a/packages/block-library/src/audio/index.js +++ b/packages/block-library/src/audio/index.js @@ -11,8 +11,11 @@ import { __ } from '@wordpress/i18n'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/audio'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Audio' ), @@ -21,43 +24,6 @@ export const settings = { icon, - category: 'common', - - attributes: { - src: { - type: 'string', - source: 'attribute', - selector: 'audio', - attribute: 'src', - }, - caption: { - type: 'string', - source: 'html', - selector: 'figcaption', - }, - id: { - type: 'number', - }, - autoplay: { - type: 'boolean', - source: 'attribute', - selector: 'audio', - attribute: 'autoplay', - }, - loop: { - type: 'boolean', - source: 'attribute', - selector: 'audio', - attribute: 'loop', - }, - preload: { - type: 'string', - source: 'attribute', - selector: 'audio', - attribute: 'preload', - }, - }, - transforms: { from: [ { diff --git a/packages/block-library/src/button/block.json b/packages/block-library/src/button/block.json new file mode 100644 index 0000000000000..61c040d8f4508 --- /dev/null +++ b/packages/block-library/src/button/block.json @@ -0,0 +1,35 @@ +{ + "name": "core/button", + "category": "layout", + "attributes": { + "url": { + "type": "string", + "source": "attribute", + "selector": "a", + "attribute": "href" + }, + "title": { + "type": "string", + "source": "attribute", + "selector": "a", + "attribute": "title" + }, + "text": { + "type": "string", + "source": "html", + "selector": "a" + }, + "backgroundColor": { + "type": "string" + }, + "textColor": { + "type": "string" + }, + "customBackgroundColor": { + "type": "string" + }, + "customTextColor": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/button/index.js b/packages/block-library/src/button/index.js index 909f067465ea8..866759fffcdb9 100644 --- a/packages/block-library/src/button/index.js +++ b/packages/block-library/src/button/index.js @@ -18,40 +18,11 @@ import { */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -const blockAttributes = { - url: { - type: 'string', - source: 'attribute', - selector: 'a', - attribute: 'href', - }, - title: { - type: 'string', - source: 'attribute', - selector: 'a', - attribute: 'title', - }, - text: { - type: 'string', - source: 'html', - selector: 'a', - }, - backgroundColor: { - type: 'string', - }, - textColor: { - type: 'string', - }, - customBackgroundColor: { - type: 'string', - }, - customTextColor: { - type: 'string', - }, -}; +const { name, attributes: blockAttributes } = metadata; -export const name = 'core/button'; +export { metadata, name }; const colorsMigration = ( attributes ) => { return omit( { @@ -68,12 +39,8 @@ export const settings = { icon, - category: 'layout', - keywords: [ __( 'link' ) ], - attributes: blockAttributes, - supports: { align: true, alignWide: false, diff --git a/packages/block-library/src/classic/block.json b/packages/block-library/src/classic/block.json new file mode 100644 index 0000000000000..d178848a1526a --- /dev/null +++ b/packages/block-library/src/classic/block.json @@ -0,0 +1,10 @@ +{ + "name": "core/freeform", + "category": "formatting", + "attributes": { + "content": { + "type": "string", + "source": "html" + } + } +} diff --git a/packages/block-library/src/classic/index.js b/packages/block-library/src/classic/index.js index 6c888df411380..4c17699404a89 100644 --- a/packages/block-library/src/classic/index.js +++ b/packages/block-library/src/classic/index.js @@ -9,8 +9,11 @@ import { __, _x } from '@wordpress/i18n'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/freeform'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: _x( 'Classic', 'block title' ), @@ -19,15 +22,6 @@ export const settings = { icon, - category: 'formatting', - - attributes: { - content: { - type: 'string', - source: 'html', - }, - }, - supports: { className: false, customClassName: false, diff --git a/packages/block-library/src/code/block.json b/packages/block-library/src/code/block.json new file mode 100644 index 0000000000000..d39e5f213bbe6 --- /dev/null +++ b/packages/block-library/src/code/block.json @@ -0,0 +1,11 @@ +{ + "name": "core/code", + "category": "formatting", + "attributes": { + "content": { + "type": "string", + "source": "text", + "selector": "code" + } + } +} diff --git a/packages/block-library/src/code/index.js b/packages/block-library/src/code/index.js index 708f054ab318b..8752fcb393d4b 100644 --- a/packages/block-library/src/code/index.js +++ b/packages/block-library/src/code/index.js @@ -9,8 +9,11 @@ import { createBlock } from '@wordpress/blocks'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/code'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Code' ), @@ -19,16 +22,6 @@ export const settings = { icon, - category: 'formatting', - - attributes: { - content: { - type: 'string', - source: 'text', - selector: 'code', - }, - }, - supports: { html: false, }, diff --git a/packages/block-library/src/column/block.json b/packages/block-library/src/column/block.json new file mode 100644 index 0000000000000..9fc52d8e47f90 --- /dev/null +++ b/packages/block-library/src/column/block.json @@ -0,0 +1,9 @@ +{ + "name": "core/column", + "category": "common", + "attributes": { + "verticalAlignment": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/columns/column.js b/packages/block-library/src/column/index.js similarity index 95% rename from packages/block-library/src/columns/column.js rename to packages/block-library/src/column/index.js index d2c725997d0bb..9c9b4d9271c40 100644 --- a/packages/block-library/src/columns/column.js +++ b/packages/block-library/src/column/index.js @@ -12,7 +12,14 @@ import { InnerBlocks, BlockControls, BlockVerticalAlignmentToolbar } from '@word import { withDispatch, withSelect } from '@wordpress/data'; import { compose } from '@wordpress/compose'; -export const name = 'core/column'; +/** + * Internal dependencies + */ +import metadata from './block.json'; + +const { name } = metadata; + +export { metadata, name }; const ColumnEdit = ( { attributes, updateAlignment } ) => { const { verticalAlignment } = attributes; @@ -70,14 +77,6 @@ export const settings = { description: __( 'A single column within a columns block.' ), - category: 'common', - - attributes: { - verticalAlignment: { - type: 'string', - }, - }, - supports: { inserter: false, reusable: false, diff --git a/packages/block-library/src/columns/block.json b/packages/block-library/src/columns/block.json new file mode 100644 index 0000000000000..267aef219883e --- /dev/null +++ b/packages/block-library/src/columns/block.json @@ -0,0 +1,13 @@ +{ + "name": "core/columns", + "category": "layout", + "attributes": { + "columns": { + "type": "number", + "default": 2 + }, + "verticalAlignment": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/columns/index.js b/packages/block-library/src/columns/index.js index 7900a7132ebb6..da0798fa7d2b1 100644 --- a/packages/block-library/src/columns/index.js +++ b/packages/block-library/src/columns/index.js @@ -18,26 +18,17 @@ import { import deprecated from './deprecated'; import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/columns'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Columns' ), icon, - category: 'layout', - - attributes: { - columns: { - type: 'number', - default: 2, - }, - verticalAlignment: { - type: 'string', - }, - }, - description: __( 'Add a block that displays content in multiple columns, then add whatever content blocks you’d like.' ), supports: { diff --git a/packages/block-library/src/cover/block.json b/packages/block-library/src/cover/block.json new file mode 100644 index 0000000000000..6bd22bc15123c --- /dev/null +++ b/packages/block-library/src/cover/block.json @@ -0,0 +1,33 @@ +{ + "name": "core/cover", + "category": "common", + "attributes": { + "url": { + "type": "string" + }, + "id": { + "type": "number" + }, + "hasParallax": { + "type": "boolean", + "default": false + }, + "dimRatio": { + "type": "number", + "default": 50 + }, + "overlayColor": { + "type": "string" + }, + "customOverlayColor": { + "type": "string" + }, + "backgroundType": { + "type": "string", + "default": "image" + }, + "focalPoint": { + "type": "object" + } + } +} diff --git a/packages/block-library/src/cover/index.js b/packages/block-library/src/cover/index.js index de5a34699e414..943d6342acd36 100644 --- a/packages/block-library/src/cover/index.js +++ b/packages/block-library/src/cover/index.js @@ -26,38 +26,11 @@ import { backgroundImageStyles, dimRatioToClass, } from './edit'; +import metadata from './block.json'; -const blockAttributes = { - url: { - type: 'string', - }, - id: { - type: 'number', - }, - hasParallax: { - type: 'boolean', - default: false, - }, - dimRatio: { - type: 'number', - default: 50, - }, - overlayColor: { - type: 'string', - }, - customOverlayColor: { - type: 'string', - }, - backgroundType: { - type: 'string', - default: 'image', - }, - focalPoint: { - type: 'object', - }, -}; +const { name, attributes: blockAttributes } = metadata; -export const name = 'core/cover'; +export { metadata, name }; export const settings = { title: __( 'Cover' ), @@ -66,10 +39,6 @@ export const settings = { icon, - category: 'common', - - attributes: blockAttributes, - supports: { align: true, }, diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json new file mode 100644 index 0000000000000..df285cfb60541 --- /dev/null +++ b/packages/block-library/src/file/block.json @@ -0,0 +1,4 @@ +{ + "name": "core/file", + "category": "common" +} diff --git a/packages/block-library/src/file/index.js b/packages/block-library/src/file/index.js index 7a58074192e21..57d6fe5bc2c2b 100644 --- a/packages/block-library/src/file/index.js +++ b/packages/block-library/src/file/index.js @@ -17,8 +17,11 @@ import { RichText } from '@wordpress/block-editor'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/file'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'File' ), @@ -27,8 +30,6 @@ export const settings = { icon, - category: 'common', - keywords: [ __( 'document' ), __( 'pdf' ) ], attributes: { diff --git a/packages/block-library/src/gallery/block.json b/packages/block-library/src/gallery/block.json new file mode 100644 index 0000000000000..c089b6c9ffe92 --- /dev/null +++ b/packages/block-library/src/gallery/block.json @@ -0,0 +1,55 @@ +{ + "name": "core/gallery", + "category": "common", + "attributes": { + "images": { + "type": "array", + "default": [ ], + "source": "query", + "selector": "ul.wp-block-gallery .blocks-gallery-item", + "query": { + "url": { + "source": "attribute", + "selector": "img", + "attribute": "src" + }, + "link": { + "source": "attribute", + "selector": "img", + "attribute": "data-link" + }, + "alt": { + "source": "attribute", + "selector": "img", + "attribute": "alt", + "default": "" + }, + "id": { + "source": "attribute", + "selector": "img", + "attribute": "data-id" + }, + "caption": { + "type": "string", + "source": "html", + "selector": "figcaption" + } + } + }, + "ids": { + "type": "array", + "default": [ ] + }, + "columns": { + "type": "number" + }, + "imageCrop": { + "type": "boolean", + "default": true + }, + "linkTo": { + "type": "string", + "default": "none" + } + } +} diff --git a/packages/block-library/src/gallery/index.js b/packages/block-library/src/gallery/index.js index 4387f9a5e7083..7f8aaa79bb3f4 100644 --- a/packages/block-library/src/gallery/index.js +++ b/packages/block-library/src/gallery/index.js @@ -17,60 +17,11 @@ import { createBlobURL } from '@wordpress/blob'; */ import { default as edit, defaultColumnsNumber, pickRelevantMediaFiles } from './edit'; import icon from './icon'; +import metadata from './block.json'; -const blockAttributes = { - images: { - type: 'array', - default: [], - source: 'query', - selector: 'ul.wp-block-gallery .blocks-gallery-item', - query: { - url: { - source: 'attribute', - selector: 'img', - attribute: 'src', - }, - link: { - source: 'attribute', - selector: 'img', - attribute: 'data-link', - }, - alt: { - source: 'attribute', - selector: 'img', - attribute: 'alt', - default: '', - }, - id: { - source: 'attribute', - selector: 'img', - attribute: 'data-id', - }, - caption: { - type: 'string', - source: 'html', - selector: 'figcaption', - }, - }, - }, - ids: { - type: 'array', - default: [], - }, - columns: { - type: 'number', - }, - imageCrop: { - type: 'boolean', - default: true, - }, - linkTo: { - type: 'string', - default: 'none', - }, -}; +const { name, attributes: blockAttributes } = metadata; -export const name = 'core/gallery'; +export { metadata, name }; const parseShortcodeIds = ( ids ) => { if ( ! ids ) { @@ -86,9 +37,7 @@ export const settings = { title: __( 'Gallery' ), description: __( 'Display multiple images in a rich gallery.' ), icon, - category: 'common', keywords: [ __( 'images' ), __( 'photos' ) ], - attributes: blockAttributes, supports: { align: true, }, diff --git a/packages/block-library/src/heading/block.json b/packages/block-library/src/heading/block.json new file mode 100644 index 0000000000000..120bece3d39ae --- /dev/null +++ b/packages/block-library/src/heading/block.json @@ -0,0 +1,22 @@ +{ + "name": "core/heading", + "category": "common", + "attributes": { + "align": { + "type": "string" + }, + "content": { + "type": "string", + "source": "html", + "selector": "h1,h2,h3,h4,h5,h6", + "default": "" + }, + "level": { + "type": "number", + "default": 2 + }, + "placeholder": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/heading/index.js b/packages/block-library/src/heading/index.js index eb1dc86d231c6..4cbe792e8ec8e 100644 --- a/packages/block-library/src/heading/index.js +++ b/packages/block-library/src/heading/index.js @@ -19,6 +19,11 @@ import { RichText } from '@wordpress/block-editor'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; + +const { name, attributes: schema } = metadata; + +export { metadata, name }; /** * Given a node name string for a heading node, returns its numeric level. @@ -36,27 +41,6 @@ const supports = { anchor: true, }; -const schema = { - content: { - type: 'string', - source: 'html', - selector: 'h1,h2,h3,h4,h5,h6', - default: '', - }, - level: { - type: 'number', - default: 2, - }, - align: { - type: 'string', - }, - placeholder: { - type: 'string', - }, -}; - -export const name = 'core/heading'; - export const settings = { title: __( 'Heading' ), @@ -64,14 +48,10 @@ export const settings = { icon, - category: 'common', - keywords: [ __( 'title' ), __( 'subtitle' ) ], supports, - attributes: schema, - transforms: { from: [ { diff --git a/packages/block-library/src/html/block.json b/packages/block-library/src/html/block.json new file mode 100644 index 0000000000000..1a62e7c76a36d --- /dev/null +++ b/packages/block-library/src/html/block.json @@ -0,0 +1,10 @@ +{ + "name": "core/html", + "category": "formatting", + "attributes": { + "content": { + "type": "string", + "source": "html" + } + } +} diff --git a/packages/block-library/src/html/index.js b/packages/block-library/src/html/index.js index 2abb2fcb80d30..603199158a292 100644 --- a/packages/block-library/src/html/index.js +++ b/packages/block-library/src/html/index.js @@ -10,8 +10,11 @@ import { getPhrasingContentSchema } from '@wordpress/blocks'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/html'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Custom HTML' ), @@ -20,8 +23,6 @@ export const settings = { icon, - category: 'formatting', - keywords: [ __( 'embed' ) ], supports: { @@ -30,13 +31,6 @@ export const settings = { html: false, }, - attributes: { - content: { - type: 'string', - source: 'html', - }, - }, - transforms: { from: [ { diff --git a/packages/block-library/src/image/block.json b/packages/block-library/src/image/block.json new file mode 100644 index 0000000000000..4abbee34871a8 --- /dev/null +++ b/packages/block-library/src/image/block.json @@ -0,0 +1,64 @@ +{ + "name": "core/image", + "category": "common", + "attributes": { + "align": { + "type": "string" + }, + "url": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "src" + }, + "alt": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "alt", + "default": "" + }, + "caption": { + "type": "string", + "source": "html", + "selector": "figcaption" + }, + "href": { + "type": "string", + "source": "attribute", + "selector": "figure > a", + "attribute": "href" + }, + "rel": { + "type": "string", + "source": "attribute", + "selector": "figure > a", + "attribute": "rel" + }, + "linkClass": { + "type": "string", + "source": "attribute", + "selector": "figure > a", + "attribute": "class" + }, + "id": { + "type": "number" + }, + "width": { + "type": "number" + }, + "height": { + "type": "number" + }, + "linkDestination": { + "type": "string", + "default": "none" + }, + "linkTarget": { + "type": "string", + "source": "attribute", + "selector": "figure > a", + "attribute": "target" + } + } +} diff --git a/packages/block-library/src/image/index.js b/packages/block-library/src/image/index.js index ace6b55f31636..a61d51e0b4aba 100644 --- a/packages/block-library/src/image/index.js +++ b/packages/block-library/src/image/index.js @@ -21,69 +21,11 @@ import { __ } from '@wordpress/i18n'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/image'; +const { name, attributes: blockAttributes } = metadata; -const blockAttributes = { - url: { - type: 'string', - source: 'attribute', - selector: 'img', - attribute: 'src', - }, - alt: { - type: 'string', - source: 'attribute', - selector: 'img', - attribute: 'alt', - default: '', - }, - caption: { - type: 'string', - source: 'html', - selector: 'figcaption', - }, - href: { - type: 'string', - source: 'attribute', - selector: 'figure > a', - attribute: 'href', - }, - rel: { - type: 'string', - source: 'attribute', - selector: 'figure > a', - attribute: 'rel', - }, - linkClass: { - type: 'string', - source: 'attribute', - selector: 'figure > a', - attribute: 'class', - }, - id: { - type: 'number', - }, - align: { - type: 'string', - }, - width: { - type: 'number', - }, - height: { - type: 'number', - }, - linkDestination: { - type: 'string', - default: 'none', - }, - linkTarget: { - type: 'string', - source: 'attribute', - selector: 'figure > a', - attribute: 'target', - }, -}; +export { metadata, name }; const imageSchema = { img: { @@ -149,15 +91,11 @@ export const settings = { icon, - category: 'common', - keywords: [ 'img', // "img" is not translated as it is intended to reflect the HTML tag. __( 'photo' ), ], - attributes: blockAttributes, - transforms: { from: [ { diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 4c00ba5391419..705c561b58b7f 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -9,7 +9,6 @@ import { setDefaultBlockName, setFreeformContentHandlerName, setUnregisteredTypeHandlerName, - unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase } from '@wordpress/blocks'; /** @@ -27,7 +26,7 @@ import * as calendar from './calendar'; import * as categories from './categories'; import * as code from './code'; import * as columns from './columns'; -import * as column from './columns/column'; +import * as column from './column'; import * as cover from './cover'; import * as embed from './embed'; import * as file from './file'; @@ -124,10 +123,10 @@ export const registerCoreBlocks = () => { return; } const { metadata, settings, name } = block; - if ( metadata ) { - unstable__bootstrapServerSideBlockDefinitions( { [ name ]: metadata } ); // eslint-disable-line camelcase - } - registerBlockType( name, settings ); + registerBlockType( name, { + ...metadata, + ...settings, + } ); } ); setDefaultBlockName( paragraph.name ); diff --git a/packages/block-library/src/index.native.js b/packages/block-library/src/index.native.js index 19f3ee31e231e..a066c89270cff 100644 --- a/packages/block-library/src/index.native.js +++ b/packages/block-library/src/index.native.js @@ -111,8 +111,11 @@ export const registerCoreBlocks = () => { image, nextpage, list, - ].forEach( ( { name, settings } ) => { - registerBlockType( name, settings ); + ].forEach( ( { metadata, name, settings } ) => { + registerBlockType( name, { + ...metadata, + ...settings, + } ); } ); }; diff --git a/packages/block-library/src/list/block.json b/packages/block-library/src/list/block.json new file mode 100644 index 0000000000000..26cdf8c19d678 --- /dev/null +++ b/packages/block-library/src/list/block.json @@ -0,0 +1,17 @@ +{ + "name": "core/list", + "category": "common", + "attributes": { + "ordered": { + "type": "boolean", + "default": false + }, + "values": { + "type": "string", + "source": "html", + "selector": "ol,ul", + "multiline": "li", + "default": "" + } + } +} diff --git a/packages/block-library/src/list/index.js b/packages/block-library/src/list/index.js index c389d914f508a..f10dfde61d744 100644 --- a/packages/block-library/src/list/index.js +++ b/packages/block-library/src/list/index.js @@ -20,6 +20,11 @@ import { replace, join, split, create, toHTMLString, LINE_SEPARATOR } from '@wor */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; + +const { name, attributes: schema } = metadata; + +export { metadata, name }; const listContentSchema = { ...getPhrasingContentSchema(), @@ -42,31 +47,12 @@ const supports = { className: false, }; -const schema = { - ordered: { - type: 'boolean', - default: false, - }, - values: { - type: 'string', - source: 'html', - selector: 'ol,ul', - multiline: 'li', - default: '', - }, -}; - -export const name = 'core/list'; - export const settings = { title: __( 'List' ), description: __( 'Create a bulleted or numbered list.' ), icon, - category: 'common', keywords: [ __( 'bullet list' ), __( 'ordered list' ), __( 'numbered list' ) ], - attributes: schema, - supports, transforms: { diff --git a/packages/block-library/src/media-text/block.json b/packages/block-library/src/media-text/block.json new file mode 100644 index 0000000000000..6eda1f4d5969e --- /dev/null +++ b/packages/block-library/src/media-text/block.json @@ -0,0 +1,56 @@ +{ + "name": "core/media-text", + "category": "layout", + "attributes": { + "align": { + "type": "string", + "default": "wide" + }, + "backgroundColor": { + "type": "string" + }, + "customBackgroundColor": { + "type": "string" + }, + "mediaAlt": { + "type": "string", + "source": "attribute", + "selector": "figure img", + "attribute": "alt", + "default": "" + }, + "mediaPosition": { + "type": "string", + "default": "left" + }, + "mediaId": { + "type": "number" + }, + "mediaUrl": { + "type": "string", + "source": "attribute", + "selector": "figure video,figure img", + "attribute": "src" + }, + "mediaType": { + "type": "string" + }, + "mediaWidth": { + "type": "number", + "default": 50 + }, + "isStackedOnMobile": { + "type": "boolean", + "default": false + }, + "verticalAlignment": { + "type": "string" + }, + "imageFill": { + "type": "boolean" + }, + "focalPoint": { + "type": "object" + } + } +} diff --git a/packages/block-library/src/media-text/index.js b/packages/block-library/src/media-text/index.js index 3f5988887cc18..781b7e60b52cf 100644 --- a/packages/block-library/src/media-text/index.js +++ b/packages/block-library/src/media-text/index.js @@ -21,63 +21,13 @@ import edit from './edit'; import icon from './icon'; import deprecated from './deprecated'; import { imageFillStyles } from './media-container'; +import metadata from './block.json'; export const DEFAULT_MEDIA_WIDTH = 50; -export const name = 'core/media-text'; +const { name } = metadata; -const blockAttributes = { - align: { - type: 'string', - default: 'wide', - }, - backgroundColor: { - type: 'string', - }, - customBackgroundColor: { - type: 'string', - }, - mediaAlt: { - type: 'string', - source: 'attribute', - selector: 'figure img', - attribute: 'alt', - default: '', - }, - mediaPosition: { - type: 'string', - default: 'left', - }, - mediaId: { - type: 'number', - }, - mediaUrl: { - type: 'string', - source: 'attribute', - selector: 'figure video,figure img', - attribute: 'src', - }, - mediaType: { - type: 'string', - }, - mediaWidth: { - type: 'number', - default: 50, - }, - isStackedOnMobile: { - type: 'boolean', - default: false, - }, - verticalAlignment: { - type: 'string', - }, - imageFill: { - type: 'boolean', - }, - focalPoint: { - type: 'object', - }, -}; +export { metadata, name }; export const settings = { title: __( 'Media & Text' ), @@ -86,12 +36,8 @@ export const settings = { icon, - category: 'layout', - keywords: [ __( 'image' ), __( 'video' ) ], - attributes: blockAttributes, - supports: { align: [ 'wide', 'full' ], html: false, diff --git a/packages/block-library/src/missing/block.json b/packages/block-library/src/missing/block.json new file mode 100644 index 0000000000000..46d919560865e --- /dev/null +++ b/packages/block-library/src/missing/block.json @@ -0,0 +1,16 @@ +{ + "name": "core/missing", + "category": "common", + "attributes": { + "originalName": { + "type": "string" + }, + "originalUndelimitedContent": { + "type": "string" + }, + "originalContent": { + "type": "string", + "source": "html" + } + } +} diff --git a/packages/block-library/src/missing/index.js b/packages/block-library/src/missing/index.js index 8f2c001498c09..b57e48309c9e9 100644 --- a/packages/block-library/src/missing/index.js +++ b/packages/block-library/src/missing/index.js @@ -8,12 +8,14 @@ import { RawHTML } from '@wordpress/element'; * Internal dependencies */ import edit from './edit'; +import metadata from './block.json'; -export const name = 'core/missing'; +const { name } = metadata; + +export { metadata, name }; export const settings = { name, - category: 'common', title: __( 'Unrecognized Block' ), description: __( 'Your site doesn’t include support for this block.' ), @@ -25,19 +27,6 @@ export const settings = { reusable: false, }, - attributes: { - originalName: { - type: 'string', - }, - originalUndelimitedContent: { - type: 'string', - }, - originalContent: { - type: 'string', - source: 'html', - }, - }, - edit, save( { attributes } ) { // Preserve the missing block's content. diff --git a/packages/block-library/src/more/block.json b/packages/block-library/src/more/block.json new file mode 100644 index 0000000000000..15cd328807682 --- /dev/null +++ b/packages/block-library/src/more/block.json @@ -0,0 +1,13 @@ +{ + "name": "core/more", + "category": "layout", + "attributes": { + "customText": { + "type": "string" + }, + "noTeaser": { + "type": "boolean", + "default": false + } + } +} diff --git a/packages/block-library/src/more/index.js b/packages/block-library/src/more/index.js index 37764c4065384..a9893832876ad 100644 --- a/packages/block-library/src/more/index.js +++ b/packages/block-library/src/more/index.js @@ -15,8 +15,11 @@ import { createBlock } from '@wordpress/blocks'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/more'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: _x( 'More', 'block name' ), @@ -25,8 +28,6 @@ export const settings = { icon, - category: 'layout', - supports: { customClassName: false, className: false, @@ -34,16 +35,6 @@ export const settings = { multiple: false, }, - attributes: { - customText: { - type: 'string', - }, - noTeaser: { - type: 'boolean', - default: false, - }, - }, - transforms: { from: [ { diff --git a/packages/block-library/src/nextpage/block.json b/packages/block-library/src/nextpage/block.json new file mode 100644 index 0000000000000..2d3ccc904ed63 --- /dev/null +++ b/packages/block-library/src/nextpage/block.json @@ -0,0 +1,4 @@ +{ + "name": "core/nextpage", + "category": "layout" +} diff --git a/packages/block-library/src/nextpage/index.js b/packages/block-library/src/nextpage/index.js index 6ab1cfacd755f..e565f003eb522 100644 --- a/packages/block-library/src/nextpage/index.js +++ b/packages/block-library/src/nextpage/index.js @@ -10,8 +10,11 @@ import { createBlock } from '@wordpress/blocks'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/nextpage'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Page Break' ), @@ -20,8 +23,6 @@ export const settings = { icon, - category: 'layout', - keywords: [ __( 'next page' ), __( 'pagination' ) ], supports: { @@ -30,8 +31,6 @@ export const settings = { html: false, }, - attributes: {}, - transforms: { from: [ { diff --git a/packages/block-library/src/paragraph/block.json b/packages/block-library/src/paragraph/block.json new file mode 100644 index 0000000000000..4f1d668b7c4d5 --- /dev/null +++ b/packages/block-library/src/paragraph/block.json @@ -0,0 +1,44 @@ +{ + "name": "core/paragraph", + "category": "common", + "attributes": { + "align": { + "type": "string" + }, + "content": { + "type": "string", + "source": "html", + "selector": "p", + "default": "" + }, + "dropCap": { + "type": "boolean", + "default": false + }, + "placeholder": { + "type": "string" + }, + "textColor": { + "type": "string" + }, + "customTextColor": { + "type": "string" + }, + "backgroundColor": { + "type": "string" + }, + "customBackgroundColor": { + "type": "string" + }, + "fontSize": { + "type": "string" + }, + "customFontSize": { + "type": "number" + }, + "direction": { + "type": "string", + "enum": [ "ltr", "rtl" ] + } + } +} diff --git a/packages/block-library/src/paragraph/index.js b/packages/block-library/src/paragraph/index.js index d0c73c548cc97..5da558c07d4ff 100644 --- a/packages/block-library/src/paragraph/index.js +++ b/packages/block-library/src/paragraph/index.js @@ -23,54 +23,16 @@ import { getPhrasingContentSchema } from '@wordpress/blocks'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; + +const { name, attributes: schema } = metadata; + +export { metadata, name }; const supports = { className: false, }; -const schema = { - content: { - type: 'string', - source: 'html', - selector: 'p', - default: '', - }, - align: { - type: 'string', - }, - dropCap: { - type: 'boolean', - default: false, - }, - placeholder: { - type: 'string', - }, - textColor: { - type: 'string', - }, - customTextColor: { - type: 'string', - }, - backgroundColor: { - type: 'string', - }, - customBackgroundColor: { - type: 'string', - }, - fontSize: { - type: 'string', - }, - customFontSize: { - type: 'number', - }, - direction: { - type: 'string', - enum: [ 'ltr', 'rtl' ], - }, -}; - -export const name = 'core/paragraph'; - export const settings = { title: __( 'Paragraph' ), @@ -78,14 +40,10 @@ export const settings = { icon, - category: 'common', - keywords: [ __( 'text' ) ], supports, - attributes: schema, - transforms: { from: [ { diff --git a/packages/block-library/src/preformatted/block.json b/packages/block-library/src/preformatted/block.json new file mode 100644 index 0000000000000..fadcbd4a860ed --- /dev/null +++ b/packages/block-library/src/preformatted/block.json @@ -0,0 +1,12 @@ +{ + "name": "core/preformatted", + "category": "formatting", + "attributes": { + "content": { + "type": "string", + "source": "html", + "selector": "pre", + "default": "" + } + } +} diff --git a/packages/block-library/src/preformatted/index.js b/packages/block-library/src/preformatted/index.js index 95348fb4b6c38..cbc3d0190b0b5 100644 --- a/packages/block-library/src/preformatted/index.js +++ b/packages/block-library/src/preformatted/index.js @@ -10,8 +10,11 @@ import { RichText } from '@wordpress/block-editor'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/preformatted'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Preformatted' ), @@ -20,17 +23,6 @@ export const settings = { icon, - category: 'formatting', - - attributes: { - content: { - type: 'string', - source: 'html', - selector: 'pre', - default: '', - }, - }, - transforms: { from: [ { diff --git a/packages/block-library/src/pullquote/block.json b/packages/block-library/src/pullquote/block.json new file mode 100644 index 0000000000000..59784cbf567e8 --- /dev/null +++ b/packages/block-library/src/pullquote/block.json @@ -0,0 +1,30 @@ +{ + "name": "core/pullquote", + "category": "formatting", + "attributes": { + "value": { + "type": "string", + "source": "html", + "selector": "blockquote", + "multiline": "p" + }, + "citation": { + "type": "string", + "source": "html", + "selector": "cite", + "default": "" + }, + "mainColor": { + "type": "string" + }, + "customMainColor": { + "type": "string" + }, + "textColor": { + "type": "string" + }, + "customTextColor": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/pullquote/index.js b/packages/block-library/src/pullquote/index.js index 354264ffaa41d..dca6f603b70b5 100644 --- a/packages/block-library/src/pullquote/index.js +++ b/packages/block-library/src/pullquote/index.js @@ -26,35 +26,11 @@ import { SOLID_COLOR_CLASS, } from './edit'; import icon from './icon'; +import metadata from './block.json'; -const blockAttributes = { - value: { - type: 'string', - source: 'html', - selector: 'blockquote', - multiline: 'p', - }, - citation: { - type: 'string', - source: 'html', - selector: 'cite', - default: '', - }, - mainColor: { - type: 'string', - }, - customMainColor: { - type: 'string', - }, - textColor: { - type: 'string', - }, - customTextColor: { - type: 'string', - }, -}; +const { name, attributes: blockAttributes } = metadata; -export const name = 'core/pullquote'; +export { metadata, name }; export const settings = { @@ -64,10 +40,6 @@ export const settings = { icon, - category: 'formatting', - - attributes: blockAttributes, - styles: [ { name: 'default', label: _x( 'Default', 'block style' ), isDefault: true }, { name: SOLID_COLOR_STYLE_NAME, label: __( 'Solid Color' ) }, diff --git a/packages/block-library/src/quote/block.json b/packages/block-library/src/quote/block.json new file mode 100644 index 0000000000000..dace40d4ea000 --- /dev/null +++ b/packages/block-library/src/quote/block.json @@ -0,0 +1,4 @@ +{ + "name": "core/quote", + "category": "common" +} diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index 7afeceb6732c6..98e85861064b7 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -17,6 +17,11 @@ import { join, split, create, toHTMLString } from '@wordpress/rich-text'; import edit from './edit'; import icon from './icon'; import { ATTRIBUTE_QUOTE, ATTRIBUTE_CITATION } from './contants'; +import metadata from './block.json'; + +const { name } = metadata; + +export { metadata, name }; const blockAttributes = { [ ATTRIBUTE_QUOTE ]: { @@ -37,13 +42,10 @@ const blockAttributes = { }, }; -export const name = 'core/quote'; - export const settings = { title: __( 'Quote' ), description: __( 'Give quoted text visual emphasis. "In quoting others, we cite ourselves." — Julio Cortázar' ), icon, - category: 'common', keywords: [ __( 'blockquote' ) ], attributes: blockAttributes, diff --git a/packages/block-library/src/section/block.json b/packages/block-library/src/section/block.json new file mode 100644 index 0000000000000..dfd7ef8320cbd --- /dev/null +++ b/packages/block-library/src/section/block.json @@ -0,0 +1,12 @@ +{ + "name": "core/section", + "category": "layout", + "attributes": { + "backgroundColor": { + "type": "string" + }, + "customBackgroundColor": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/section/index.js b/packages/block-library/src/section/index.js index d119bfa324a4d..cc2511a0bda3a 100644 --- a/packages/block-library/src/section/index.js +++ b/packages/block-library/src/section/index.js @@ -14,16 +14,17 @@ import { InnerBlocks, getColorClassName } from '@wordpress/block-editor'; * Internal dependencies */ import edit from './edit'; +import metadata from './block.json'; -export const name = 'core/section'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Section' ), icon: , - category: 'layout', - description: __( 'A wrapping section acting as a container for other blocks.' ), keywords: [ __( 'container' ), __( 'wrapper' ), __( 'row' ) ], @@ -34,15 +35,6 @@ export const settings = { html: false, }, - attributes: { - backgroundColor: { - type: 'string', - }, - customBackgroundColor: { - type: 'string', - }, - }, - edit, save( { attributes } ) { diff --git a/packages/block-library/src/separator/block.json b/packages/block-library/src/separator/block.json new file mode 100644 index 0000000000000..70060a329cdfd --- /dev/null +++ b/packages/block-library/src/separator/block.json @@ -0,0 +1,4 @@ +{ + "name": "core/separator", + "category": "layout" +} diff --git a/packages/block-library/src/separator/index.js b/packages/block-library/src/separator/index.js index b846b76b623b2..3a7dae05ea357 100644 --- a/packages/block-library/src/separator/index.js +++ b/packages/block-library/src/separator/index.js @@ -9,8 +9,11 @@ import { createBlock } from '@wordpress/blocks'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/separator'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Separator' ), @@ -19,8 +22,6 @@ export const settings = { icon, - category: 'layout', - keywords: [ __( 'horizontal-line' ), 'hr', __( 'divider' ) ], styles: [ diff --git a/packages/block-library/src/spacer/block.json b/packages/block-library/src/spacer/block.json new file mode 100644 index 0000000000000..c8240f036ca77 --- /dev/null +++ b/packages/block-library/src/spacer/block.json @@ -0,0 +1,10 @@ +{ + "name": "core/spacer", + "category": "layout", + "attributes": { + "height": { + "type": "number", + "default": 100 + } + } +} diff --git a/packages/block-library/src/spacer/index.js b/packages/block-library/src/spacer/index.js index db167da48b927..44a151168fb7a 100644 --- a/packages/block-library/src/spacer/index.js +++ b/packages/block-library/src/spacer/index.js @@ -8,8 +8,11 @@ import { __ } from '@wordpress/i18n'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/spacer'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Spacer' ), @@ -18,15 +21,6 @@ export const settings = { icon, - category: 'layout', - - attributes: { - height: { - type: 'number', - default: 100, - }, - }, - edit, save( { attributes } ) { diff --git a/packages/block-library/src/subhead/block.json b/packages/block-library/src/subhead/block.json new file mode 100644 index 0000000000000..ebb48d386ed3d --- /dev/null +++ b/packages/block-library/src/subhead/block.json @@ -0,0 +1,14 @@ +{ + "name": "core/subhead", + "category": "common", + "attributes": { + "align": { + "type": "string" + }, + "content": { + "type": "string", + "source": "html", + "selector": "p" + } + } +} diff --git a/packages/block-library/src/subhead/index.js b/packages/block-library/src/subhead/index.js index 467b33af8eec6..1286a236e1ea8 100644 --- a/packages/block-library/src/subhead/index.js +++ b/packages/block-library/src/subhead/index.js @@ -10,8 +10,11 @@ import { RichText } from '@wordpress/block-editor'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/subhead'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Subheading (deprecated)' ), @@ -20,25 +23,12 @@ export const settings = { icon, - category: 'common', - supports: { // Hide from inserter as this block is deprecated. inserter: false, multiple: false, }, - attributes: { - content: { - type: 'string', - source: 'html', - selector: 'p', - }, - align: { - type: 'string', - }, - }, - transforms: { to: [ { diff --git a/packages/block-library/src/template/block.json b/packages/block-library/src/template/block.json new file mode 100644 index 0000000000000..fc5600a48cc3a --- /dev/null +++ b/packages/block-library/src/template/block.json @@ -0,0 +1,4 @@ +{ + "name": "core/template", + "category": "reusable" +} diff --git a/packages/block-library/src/template/index.js b/packages/block-library/src/template/index.js index 755f31b724b83..e9d8138556929 100644 --- a/packages/block-library/src/template/index.js +++ b/packages/block-library/src/template/index.js @@ -8,14 +8,15 @@ import { InnerBlocks } from '@wordpress/block-editor'; * Internal dependencies */ import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/template'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Reusable Template' ), - category: 'reusable', - description: __( 'Template block used as a container.' ), icon, diff --git a/packages/block-library/src/text-columns/index.js b/packages/block-library/src/text-columns/index.js index ce56b9d5bef2f..49e6bd6c40062 100644 --- a/packages/block-library/src/text-columns/index.js +++ b/packages/block-library/src/text-columns/index.js @@ -14,10 +14,6 @@ import { RichText } from '@wordpress/block-editor'; * Internal dependencies */ import edit from './edit'; - -/** - * Internal dependencies - */ import metadata from './block.json'; const { name } = metadata; diff --git a/packages/block-library/src/verse/block.json b/packages/block-library/src/verse/block.json new file mode 100644 index 0000000000000..d0def4bb7b74f --- /dev/null +++ b/packages/block-library/src/verse/block.json @@ -0,0 +1,15 @@ +{ + "name": "core/verse", + "category": "formatting", + "attributes": { + "content": { + "type": "string", + "source": "html", + "selector": "pre", + "default": "" + }, + "textAlign": { + "type": "string" + } + } +} diff --git a/packages/block-library/src/verse/index.js b/packages/block-library/src/verse/index.js index 87c9a019d5399..5dafc67347a5f 100644 --- a/packages/block-library/src/verse/index.js +++ b/packages/block-library/src/verse/index.js @@ -10,8 +10,11 @@ import { RichText } from '@wordpress/block-editor'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/verse'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Verse' ), @@ -20,22 +23,8 @@ export const settings = { icon, - category: 'formatting', - keywords: [ __( 'poetry' ) ], - attributes: { - content: { - type: 'string', - source: 'html', - selector: 'pre', - default: '', - }, - textAlign: { - type: 'string', - }, - }, - transforms: { from: [ { diff --git a/packages/block-library/src/video/block.json b/packages/block-library/src/video/block.json new file mode 100644 index 0000000000000..c62179b360d2b --- /dev/null +++ b/packages/block-library/src/video/block.json @@ -0,0 +1,64 @@ +{ + "name": "core/video", + "category": "common", + "attributes": { + "autoplay": { + "type": "boolean", + "source": "attribute", + "selector": "video", + "attribute": "autoplay" + }, + "caption": { + "type": "string", + "source": "html", + "selector": "figcaption" + }, + "controls": { + "type": "boolean", + "source": "attribute", + "selector": "video", + "attribute": "controls", + "default": true + }, + "id": { + "type": "number" + }, + "loop": { + "type": "boolean", + "source": "attribute", + "selector": "video", + "attribute": "loop" + }, + "muted": { + "type": "boolean", + "source": "attribute", + "selector": "video", + "attribute": "muted" + }, + "poster": { + "type": "string", + "source": "attribute", + "selector": "video", + "attribute": "poster" + }, + "preload": { + "type": "string", + "source": "attribute", + "selector": "video", + "attribute": "preload", + "default": "metadata" + }, + "src": { + "type": "string", + "source": "attribute", + "selector": "video", + "attribute": "src" + }, + "playsInline": { + "type": "boolean", + "source": "attribute", + "selector": "video", + "attribute": "playsinline" + } + } +} diff --git a/packages/block-library/src/video/index.js b/packages/block-library/src/video/index.js index d4055080d8f37..1600dcb9b5d40 100644 --- a/packages/block-library/src/video/index.js +++ b/packages/block-library/src/video/index.js @@ -11,8 +11,11 @@ import { __ } from '@wordpress/i18n'; */ import edit from './edit'; import icon from './icon'; +import metadata from './block.json'; -export const name = 'core/video'; +const { name } = metadata; + +export { metadata, name }; export const settings = { title: __( 'Video' ), @@ -23,69 +26,6 @@ export const settings = { keywords: [ __( 'movie' ) ], - category: 'common', - - attributes: { - autoplay: { - type: 'boolean', - source: 'attribute', - selector: 'video', - attribute: 'autoplay', - }, - caption: { - type: 'string', - source: 'html', - selector: 'figcaption', - }, - controls: { - type: 'boolean', - source: 'attribute', - selector: 'video', - attribute: 'controls', - default: true, - }, - id: { - type: 'number', - }, - loop: { - type: 'boolean', - source: 'attribute', - selector: 'video', - attribute: 'loop', - }, - muted: { - type: 'boolean', - source: 'attribute', - selector: 'video', - attribute: 'muted', - }, - poster: { - type: 'string', - source: 'attribute', - selector: 'video', - attribute: 'poster', - }, - preload: { - type: 'string', - source: 'attribute', - selector: 'video', - attribute: 'preload', - default: 'metadata', - }, - src: { - type: 'string', - source: 'attribute', - selector: 'video', - attribute: 'src', - }, - playsInline: { - type: 'boolean', - source: 'attribute', - selector: 'video', - attribute: 'playsinline', - }, - }, - transforms: { from: [ { diff --git a/packages/e2e-tests/fixtures/blocks/core__cover.json b/packages/e2e-tests/fixtures/blocks/core__cover.json index 78ce136bea2b6..93776fce2cdc0 100644 --- a/packages/e2e-tests/fixtures/blocks/core__cover.json +++ b/packages/e2e-tests/fixtures/blocks/core__cover.json @@ -15,8 +15,8 @@ "name": "core/paragraph", "isValid": true, "attributes": { - "content": "\n\t\t\tGuten Berg!\n\t\t", "align": "center", + "content": "\n\t\t\tGuten Berg!\n\t\t", "dropCap": false, "placeholder": "Write title…", "fontSize": "large" diff --git a/packages/e2e-tests/fixtures/blocks/core__cover__video-overlay.json b/packages/e2e-tests/fixtures/blocks/core__cover__video-overlay.json index 36298998345e8..f7e2b42ff234c 100644 --- a/packages/e2e-tests/fixtures/blocks/core__cover__video-overlay.json +++ b/packages/e2e-tests/fixtures/blocks/core__cover__video-overlay.json @@ -16,8 +16,8 @@ "name": "core/paragraph", "isValid": true, "attributes": { - "content": "\n\t\t\tGuten Berg!\n\t\t", "align": "center", + "content": "\n\t\t\tGuten Berg!\n\t\t", "dropCap": false, "placeholder": "Write title…", "fontSize": "large" diff --git a/packages/e2e-tests/fixtures/blocks/core__cover__video.json b/packages/e2e-tests/fixtures/blocks/core__cover__video.json index 4c05b5f2f0c1f..f91f443e785e1 100644 --- a/packages/e2e-tests/fixtures/blocks/core__cover__video.json +++ b/packages/e2e-tests/fixtures/blocks/core__cover__video.json @@ -15,8 +15,8 @@ "name": "core/paragraph", "isValid": true, "attributes": { - "content": "\n\t\t\tGuten Berg!\n\t\t", "align": "center", + "content": "\n\t\t\tGuten Berg!\n\t\t", "dropCap": false, "placeholder": "Write title…", "fontSize": "large" diff --git a/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json b/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json index 525502f15232e..47fa6721cea7a 100644 --- a/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json +++ b/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json @@ -4,10 +4,10 @@ "name": "core/image", "isValid": true, "attributes": { - "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==", + "align": "center", + "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==", "alt": "", "caption": "Give it a try. Press the \"really wide\" button on the image toolbar.", - "align": "center", "linkDestination": "none" }, "innerBlocks": [], diff --git a/packages/e2e-tests/fixtures/blocks/core__media-text__media-right-custom-width.json b/packages/e2e-tests/fixtures/blocks/core__media-text__media-right-custom-width.json index b3bf94da24828..c31ac7581e255 100644 --- a/packages/e2e-tests/fixtures/blocks/core__media-text__media-right-custom-width.json +++ b/packages/e2e-tests/fixtures/blocks/core__media-text__media-right-custom-width.json @@ -18,8 +18,8 @@ "name": "core/paragraph", "isValid": true, "attributes": { - "content": "My video", "align": "right", + "content": "My video", "dropCap": false, "placeholder": "Content…", "fontSize": "large" diff --git a/packages/e2e-tests/fixtures/blocks/core__paragraph__align-right.json b/packages/e2e-tests/fixtures/blocks/core__paragraph__align-right.json index 079d9a704f2e9..2ab7bad89f192 100644 --- a/packages/e2e-tests/fixtures/blocks/core__paragraph__align-right.json +++ b/packages/e2e-tests/fixtures/blocks/core__paragraph__align-right.json @@ -4,8 +4,8 @@ "name": "core/paragraph", "isValid": true, "attributes": { - "content": "... like this one, which is separate from the above and right aligned.", "align": "right", + "content": "... like this one, which is separate from the above and right aligned.", "dropCap": false }, "innerBlocks": [], diff --git a/test/integration/__snapshots__/blocks-raw-handling.spec.js.snap b/test/integration/__snapshots__/blocks-raw-handling.spec.js.snap index 9d8761f906216..d7bdedf537779 100644 --- a/test/integration/__snapshots__/blocks-raw-handling.spec.js.snap +++ b/test/integration/__snapshots__/blocks-raw-handling.spec.js.snap @@ -56,19 +56,19 @@ exports[`rawHandler should convert HTML post to blocks with minimal content chan `; exports[`rawHandler should convert a caption shortcode 1`] = ` -" +"
\\"\\"
test
" `; exports[`rawHandler should convert a caption shortcode with caption 1`] = ` -" +"
\\"\\"
test
" `; exports[`rawHandler should convert a caption shortcode with link 1`] = ` -" +"
\\"Bell
Bell on wharf in San Francisco
" `; From 3de1a78b6e3d7b3ebed9c7fd76b0bcefb9623ac3 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 2 Apr 2019 16:48:01 +0200 Subject: [PATCH 2/2] Quote: Stop using constants for attribute keys and move definition to block.json --- packages/block-library/src/index.js | 9 +++---- packages/block-library/src/quote/block.json | 20 +++++++++++++++- packages/block-library/src/quote/contants.js | 2 -- packages/block-library/src/quote/edit.js | 15 +++--------- packages/block-library/src/quote/index.js | 24 ++----------------- .../blocks/core__image__center-caption.json | 2 +- 6 files changed, 30 insertions(+), 42 deletions(-) delete mode 100644 packages/block-library/src/quote/contants.js diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 705c561b58b7f..da1ab153a4e5f 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'; /** @@ -123,10 +124,10 @@ export const registerCoreBlocks = () => { return; } const { metadata, settings, name } = block; - registerBlockType( name, { - ...metadata, - ...settings, - } ); + if ( metadata ) { + unstable__bootstrapServerSideBlockDefinitions( { [ name ]: metadata } ); // eslint-disable-line camelcase + } + registerBlockType( name, settings ); } ); setDefaultBlockName( paragraph.name ); diff --git a/packages/block-library/src/quote/block.json b/packages/block-library/src/quote/block.json index dace40d4ea000..05b07ad5bb2d1 100644 --- a/packages/block-library/src/quote/block.json +++ b/packages/block-library/src/quote/block.json @@ -1,4 +1,22 @@ { "name": "core/quote", - "category": "common" + "category": "common", + "attributes": { + "value": { + "type": "string", + "source": "html", + "selector": "blockquote", + "multiline": "p", + "default": "" + }, + "citation": { + "type": "string", + "source": "html", + "selector": "cite", + "default": "" + }, + "align": { + "type": "string" + } + } } diff --git a/packages/block-library/src/quote/contants.js b/packages/block-library/src/quote/contants.js deleted file mode 100644 index 8048056554ae2..0000000000000 --- a/packages/block-library/src/quote/contants.js +++ /dev/null @@ -1,2 +0,0 @@ -export const ATTRIBUTE_QUOTE = 'value'; -export const ATTRIBUTE_CITATION = 'citation'; diff --git a/packages/block-library/src/quote/edit.js b/packages/block-library/src/quote/edit.js index 1fff04fe12405..82e4ed78972ba 100644 --- a/packages/block-library/src/quote/edit.js +++ b/packages/block-library/src/quote/edit.js @@ -3,16 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import { Fragment } from '@wordpress/element'; -import { - BlockControls, - AlignmentToolbar, - RichText, -} from '@wordpress/block-editor'; - -/** - * Internal dependencies - */ -import { ATTRIBUTE_QUOTE, ATTRIBUTE_CITATION } from './contants'; +import { AlignmentToolbar, BlockControls, RichText } from '@wordpress/block-editor'; export default function QuoteEdit( { attributes, setAttributes, isSelected, mergeBlocks, onReplace, className } ) { const { align, value, citation } = attributes; @@ -28,7 +19,7 @@ export default function QuoteEdit( { attributes, setAttributes, isSelected, merg
{ ( ! RichText.isEmpty( citation ) || isSelected ) && ( setAttributes( { diff --git a/packages/block-library/src/quote/index.js b/packages/block-library/src/quote/index.js index 98e85861064b7..c40f929eca496 100644 --- a/packages/block-library/src/quote/index.js +++ b/packages/block-library/src/quote/index.js @@ -9,39 +9,19 @@ import { omit } from 'lodash'; import { __, _x } from '@wordpress/i18n'; import { createBlock, getPhrasingContentSchema } from '@wordpress/blocks'; import { RichText } from '@wordpress/block-editor'; -import { join, split, create, toHTMLString } from '@wordpress/rich-text'; +import { create, join, split, toHTMLString } from '@wordpress/rich-text'; /** * Internal dependencies */ import edit from './edit'; import icon from './icon'; -import { ATTRIBUTE_QUOTE, ATTRIBUTE_CITATION } from './contants'; import metadata from './block.json'; -const { name } = metadata; +const { name, attributes: blockAttributes } = metadata; export { metadata, name }; -const blockAttributes = { - [ ATTRIBUTE_QUOTE ]: { - type: 'string', - source: 'html', - selector: 'blockquote', - multiline: 'p', - default: '', - }, - [ ATTRIBUTE_CITATION ]: { - type: 'string', - source: 'html', - selector: 'cite', - default: '', - }, - align: { - type: 'string', - }, -}; - export const settings = { title: __( 'Quote' ), description: __( 'Give quoted text visual emphasis. "In quoting others, we cite ourselves." — Julio Cortázar' ), diff --git a/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json b/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json index 47fa6721cea7a..80aa7f460f246 100644 --- a/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json +++ b/packages/e2e-tests/fixtures/blocks/core__image__center-caption.json @@ -5,7 +5,7 @@ "isValid": true, "attributes": { "align": "center", - "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==", + "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==", "alt": "", "caption": "Give it a try. Press the \"really wide\" button on the image toolbar.", "linkDestination": "none"