From f7d617cfb8e71ead2ab589011bffad5a22f35d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=83=C2=B3=C3=85=E2=80=9Akowski?= Date: Wed, 1 Jul 2020 12:27:10 +0000 Subject: [PATCH] Editor: Register core blocks on the server Exposes all core blocks (excluding embeds) on the server to be used with the REST API block types endpoint. Props spacedmonkey, timothyblynjacobs. Fixes #50263. git-svn-id: https://develop.svn.wordpress.org/trunk@48262 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks/audio/block.json | 42 ++++++ src/wp-includes/blocks/button/block.json | 62 +++++++++ src/wp-includes/blocks/buttons/block.json | 9 ++ src/wp-includes/blocks/classic/block.json | 15 +++ src/wp-includes/blocks/code/block.json | 15 +++ src/wp-includes/blocks/column/block.json | 22 +++ src/wp-includes/blocks/columns/block.json | 21 +++ src/wp-includes/blocks/file/block.json | 41 ++++++ src/wp-includes/blocks/gallery/block.json | 82 +++++++++++ src/wp-includes/blocks/group/block.json | 23 ++++ src/wp-includes/blocks/heading/block.json | 41 ++++++ src/wp-includes/blocks/html/block.json | 15 +++ src/wp-includes/blocks/image/block.json | 76 +++++++++++ src/wp-includes/blocks/index.php | 58 ++++++++ src/wp-includes/blocks/list/block.json | 35 +++++ src/wp-includes/blocks/media-text/block.json | 92 +++++++++++++ src/wp-includes/blocks/missing/block.json | 23 ++++ src/wp-includes/blocks/more/block.json | 19 +++ src/wp-includes/blocks/nextpage/block.json | 10 ++ src/wp-includes/blocks/paragraph/block.json | 45 +++++++ .../blocks/preformatted/block.json | 16 +++ src/wp-includes/blocks/pullquote/block.json | 38 ++++++ src/wp-includes/blocks/quote/block.json | 22 +++ src/wp-includes/blocks/separator/block.json | 12 ++ .../blocks/social-links/block.json | 12 ++ src/wp-includes/blocks/spacer/block.json | 10 ++ src/wp-includes/blocks/subhead/block.json | 18 +++ src/wp-includes/blocks/table/block.json | 127 ++++++++++++++++++ .../blocks/text-columns/block.json | 32 +++++ src/wp-includes/blocks/verse/block.json | 19 +++ src/wp-includes/blocks/video/block.json | 68 ++++++++++ src/wp-settings.php | 12 +- tools/webpack/packages.js | 53 +++++++- 33 files changed, 1167 insertions(+), 18 deletions(-) create mode 100644 src/wp-includes/blocks/audio/block.json create mode 100644 src/wp-includes/blocks/button/block.json create mode 100644 src/wp-includes/blocks/buttons/block.json create mode 100644 src/wp-includes/blocks/classic/block.json create mode 100644 src/wp-includes/blocks/code/block.json create mode 100644 src/wp-includes/blocks/column/block.json create mode 100644 src/wp-includes/blocks/columns/block.json create mode 100644 src/wp-includes/blocks/file/block.json create mode 100644 src/wp-includes/blocks/gallery/block.json create mode 100644 src/wp-includes/blocks/group/block.json create mode 100644 src/wp-includes/blocks/heading/block.json create mode 100644 src/wp-includes/blocks/html/block.json create mode 100644 src/wp-includes/blocks/image/block.json create mode 100644 src/wp-includes/blocks/index.php create mode 100644 src/wp-includes/blocks/list/block.json create mode 100644 src/wp-includes/blocks/media-text/block.json create mode 100644 src/wp-includes/blocks/missing/block.json create mode 100644 src/wp-includes/blocks/more/block.json create mode 100644 src/wp-includes/blocks/nextpage/block.json create mode 100644 src/wp-includes/blocks/paragraph/block.json create mode 100644 src/wp-includes/blocks/preformatted/block.json create mode 100644 src/wp-includes/blocks/pullquote/block.json create mode 100644 src/wp-includes/blocks/quote/block.json create mode 100644 src/wp-includes/blocks/separator/block.json create mode 100644 src/wp-includes/blocks/social-links/block.json create mode 100644 src/wp-includes/blocks/spacer/block.json create mode 100644 src/wp-includes/blocks/subhead/block.json create mode 100644 src/wp-includes/blocks/table/block.json create mode 100644 src/wp-includes/blocks/text-columns/block.json create mode 100644 src/wp-includes/blocks/verse/block.json create mode 100644 src/wp-includes/blocks/video/block.json diff --git a/src/wp-includes/blocks/audio/block.json b/src/wp-includes/blocks/audio/block.json new file mode 100644 index 0000000000..31c6c8f9ef --- /dev/null +++ b/src/wp-includes/blocks/audio/block.json @@ -0,0 +1,42 @@ +{ + "name": "core/audio", + "category": "media", + "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" + } + }, + "supports": { + "align": true, + "lightBlockWrapper": true + } +} diff --git a/src/wp-includes/blocks/button/block.json b/src/wp-includes/blocks/button/block.json new file mode 100644 index 0000000000..b2af0f5a4c --- /dev/null +++ b/src/wp-includes/blocks/button/block.json @@ -0,0 +1,62 @@ +{ + "name": "core/button", + "category": "design", + "parent": [ + "core/buttons" + ], + "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" + }, + "linkTarget": { + "type": "string", + "source": "attribute", + "selector": "a", + "attribute": "target" + }, + "rel": { + "type": "string", + "source": "attribute", + "selector": "a", + "attribute": "rel" + }, + "placeholder": { + "type": "string" + }, + "borderRadius": { + "type": "number" + }, + "style": { + "type": "object" + }, + "backgroundColor": { + "type": "string" + }, + "textColor": { + "type": "string" + }, + "gradient": { + "type": "string" + } + }, + "supports": { + "align": true, + "alignWide": false, + "reusable": false, + "lightBlockWrapper": true + } +} diff --git a/src/wp-includes/blocks/buttons/block.json b/src/wp-includes/blocks/buttons/block.json new file mode 100644 index 0000000000..4004a9591a --- /dev/null +++ b/src/wp-includes/blocks/buttons/block.json @@ -0,0 +1,9 @@ +{ + "name": "core/buttons", + "category": "design", + "supports": { + "align": true, + "alignWide": false, + "lightBlockWrapper": true + } +} diff --git a/src/wp-includes/blocks/classic/block.json b/src/wp-includes/blocks/classic/block.json new file mode 100644 index 0000000000..63d2c9f37e --- /dev/null +++ b/src/wp-includes/blocks/classic/block.json @@ -0,0 +1,15 @@ +{ + "name": "core/freeform", + "category": "text", + "attributes": { + "content": { + "type": "string", + "source": "html" + } + }, + "supports": { + "className": false, + "customClassName": false, + "reusable": false + } +} diff --git a/src/wp-includes/blocks/code/block.json b/src/wp-includes/blocks/code/block.json new file mode 100644 index 0000000000..d7cab6cf34 --- /dev/null +++ b/src/wp-includes/blocks/code/block.json @@ -0,0 +1,15 @@ +{ + "name": "core/code", + "category": "text", + "attributes": { + "content": { + "type": "string", + "source": "text", + "selector": "code" + } + }, + "supports": { + "html": false, + "lightBlockWrapper": true + } +} diff --git a/src/wp-includes/blocks/column/block.json b/src/wp-includes/blocks/column/block.json new file mode 100644 index 0000000000..328dbb6201 --- /dev/null +++ b/src/wp-includes/blocks/column/block.json @@ -0,0 +1,22 @@ +{ + "name": "core/column", + "category": "text", + "parent": [ + "core/columns" + ], + "attributes": { + "verticalAlignment": { + "type": "string" + }, + "width": { + "type": "number", + "min": 0, + "max": 100 + } + }, + "supports": { + "reusable": false, + "html": false, + "lightBlockWrapper": true + } +} diff --git a/src/wp-includes/blocks/columns/block.json b/src/wp-includes/blocks/columns/block.json new file mode 100644 index 0000000000..352b1e5caa --- /dev/null +++ b/src/wp-includes/blocks/columns/block.json @@ -0,0 +1,21 @@ +{ + "name": "core/columns", + "category": "design", + "attributes": { + "verticalAlignment": { + "type": "string" + } + }, + "supports": { + "align": [ + "wide", + "full" + ], + "html": false, + "lightBlockWrapper": true, + "__experimentalColor": { + "gradients": true, + "linkColor": true + } + } +} diff --git a/src/wp-includes/blocks/file/block.json b/src/wp-includes/blocks/file/block.json new file mode 100644 index 0000000000..664ec1154a --- /dev/null +++ b/src/wp-includes/blocks/file/block.json @@ -0,0 +1,41 @@ +{ + "name": "core/file", + "category": "media", + "attributes": { + "id": { + "type": "number" + }, + "href": { + "type": "string" + }, + "fileName": { + "type": "string", + "source": "html", + "selector": "a:not([download])" + }, + "textLinkHref": { + "type": "string", + "source": "attribute", + "selector": "a:not([download])", + "attribute": "href" + }, + "textLinkTarget": { + "type": "string", + "source": "attribute", + "selector": "a:not([download])", + "attribute": "target" + }, + "showDownloadButton": { + "type": "boolean", + "default": true + }, + "downloadButtonText": { + "type": "string", + "source": "html", + "selector": "a[download]" + } + }, + "supports": { + "align": true + } +} diff --git a/src/wp-includes/blocks/gallery/block.json b/src/wp-includes/blocks/gallery/block.json new file mode 100644 index 0000000000..c16a21e734 --- /dev/null +++ b/src/wp-includes/blocks/gallery/block.json @@ -0,0 +1,82 @@ +{ + "name": "core/gallery", + "category": "media", + "attributes": { + "images": { + "type": "array", + "default": [], + "source": "query", + "selector": ".blocks-gallery-item", + "query": { + "url": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "src" + }, + "fullUrl": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "data-full-url" + }, + "link": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "data-link" + }, + "alt": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "alt", + "default": "" + }, + "id": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "data-id" + }, + "caption": { + "type": "string", + "source": "html", + "selector": ".blocks-gallery-item__caption" + } + } + }, + "ids": { + "type": "array", + "items": { + "type": "number" + }, + "default": [] + }, + "columns": { + "type": "number", + "minimum": 1, + "maximum": 8 + }, + "caption": { + "type": "string", + "source": "html", + "selector": ".blocks-gallery-caption" + }, + "imageCrop": { + "type": "boolean", + "default": true + }, + "linkTo": { + "type": "string", + "default": "none" + }, + "sizeSlug": { + "type": "string", + "default": "large" + } + }, + "supports": { + "align": true + } +} diff --git a/src/wp-includes/blocks/group/block.json b/src/wp-includes/blocks/group/block.json new file mode 100644 index 0000000000..1e32b1443c --- /dev/null +++ b/src/wp-includes/blocks/group/block.json @@ -0,0 +1,23 @@ +{ + "name": "core/group", + "category": "design", + "attributes": { + "tagName": { + "type": "string", + "default": "div" + } + }, + "supports": { + "align": [ + "wide", + "full" + ], + "anchor": true, + "html": false, + "lightBlockWrapper": true, + "__experimentalColor": { + "gradients": true, + "linkColor": true + } + } +} diff --git a/src/wp-includes/blocks/heading/block.json b/src/wp-includes/blocks/heading/block.json new file mode 100644 index 0000000000..fd03a4487e --- /dev/null +++ b/src/wp-includes/blocks/heading/block.json @@ -0,0 +1,41 @@ +{ + "name": "core/heading", + "category": "text", + "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" + } + }, + "supports": { + "anchor": true, + "className": false, + "lightBlockWrapper": true, + "__experimentalColor": { + "linkColor": true + }, + "__experimentalFontSize": true, + "__experimentalLineHeight": true, + "__experimentalSelector": { + "core/heading/h1": "h1", + "core/heading/h2": "h2", + "core/heading/h3": "h3", + "core/heading/h4": "h4", + "core/heading/h5": "h5", + "core/heading/h6": "h6" + }, + "__unstablePasteTextInline": true + } +} diff --git a/src/wp-includes/blocks/html/block.json b/src/wp-includes/blocks/html/block.json new file mode 100644 index 0000000000..b9624b4b3e --- /dev/null +++ b/src/wp-includes/blocks/html/block.json @@ -0,0 +1,15 @@ +{ + "name": "core/html", + "category": "widgets", + "attributes": { + "content": { + "type": "string", + "source": "html" + } + }, + "supports": { + "customClassName": false, + "className": false, + "html": false + } +} diff --git a/src/wp-includes/blocks/image/block.json b/src/wp-includes/blocks/image/block.json new file mode 100644 index 0000000000..d403ec3827 --- /dev/null +++ b/src/wp-includes/blocks/image/block.json @@ -0,0 +1,76 @@ +{ + "name": "core/image", + "category": "media", + "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" + }, + "title": { + "type": "string", + "source": "attribute", + "selector": "img", + "attribute": "title" + }, + "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" + }, + "sizeSlug": { + "type": "string" + }, + "linkDestination": { + "type": "string", + "default": "none" + }, + "linkTarget": { + "type": "string", + "source": "attribute", + "selector": "figure > a", + "attribute": "target" + } + }, + "supports": { + "lightBlockWrapper": true + } +} diff --git a/src/wp-includes/blocks/index.php b/src/wp-includes/blocks/index.php new file mode 100644 index 0000000000..53aaf2756a --- /dev/null +++ b/src/wp-includes/blocks/index.php @@ -0,0 +1,58 @@ + { + ...dynamicBlockFolders.reduce( ( files, blockName ) => { files[ `block-library/src/${ blockName }/index.php` ] = `wp-includes/blocks/${ blockName }.php`; return files; } , {} ), }; - const blockMetadataCopies = { - from: join( baseDir, `node_modules/@wordpress/block-library/src/+(${ blockNames.join( '|' ) })/block.json` ), - test: new RegExp( `\/([^/]+)\/block\.json$` ), - to: join( baseDir, `${ buildTarget }/blocks/[1]/block.json` ), + const blockMetadataFiles = { + ...blockFolders.reduce( ( files, blockName ) => { + files[ `block-library/src/${ blockName }/block.json` ] = `wp-includes/blocks/${ blockName }/block.json`; + return files; + } , {} ), }; const developmentCopies = mapVendorCopies( vendors, buildTarget ); @@ -172,6 +206,11 @@ module.exports = function( env = { environment: 'production', watch: false, buil to: join( baseDir, `src/${ phpFiles[ filename ] }` ), } ) ); + const blockMetadataCopies = Object.keys( blockMetadataFiles ).map( ( filename ) => ( { + from: join( baseDir, `node_modules/@wordpress/${ filename }` ), + to: join( baseDir, `src/${ blockMetadataFiles[ filename ] }` ), + } ) ); + const config = { mode, @@ -254,7 +293,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil ...vendorCopies, ...cssCopies, ...phpCopies, - blockMetadataCopies, + ...blockMetadataCopies, ], ), ],