Skip to content

Commit

Permalink
Block Library: Move supports to block.json files for core blocks (#…
Browse files Browse the repository at this point in the history
…22422)

* Block Library: Move supports to block.json

* Blocks: Add "features" alias for "supports" field

* Block Library: Move "supports" to block.json files

* Remove server-register.json generator in favor of reading block.json files

* Remove temporary TODO code comments

* Improve registration on the server for the Post Comments block

* Move supports to block.json for Widget Area block

* Fix rebase issue for Query blocks
  • Loading branch information
gziolo authored May 20, 2020
1 parent 70f65da commit d26842b
Show file tree
Hide file tree
Showing 113 changed files with 481 additions and 378 deletions.
39 changes: 0 additions & 39 deletions bin/get-server-blocks.php

This file was deleted.

26 changes: 20 additions & 6 deletions docs/rfc/block-registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ To register a new block type, start by creating a `block.json` file. This file:
"selector": ".message"
}
},
"supports": {
"align": true,
"lightBlockWrapper": true
},
"styleVariations": [
{ "name": "default", "label": "Default", "isDefault": true },
{ "name": "other", "label": "Other" }
Expand Down Expand Up @@ -243,11 +247,22 @@ Attributes provide the structured data needs of a block. They can exist in diffe

See the [the attributes documentation](/docs/designers-developers/developers/block-api/block-attributes.md) for more details.

### Supports

* Type: `object`
* Optional
* Localized: No
* Property: `supports`

It contains as set of options to control features used in the editor.

See the [the supports documentation](/docs/designers-developers/developers/block-api/block-registration.md#supports-optional) for more details.

### Style Variations

* Type: `array`
* Optional
* Localized: Yes (`label`)
* Localized: Yes (`label` only)
* Property: `styles`
* Alias: `styleVariations`

Expand Down Expand Up @@ -323,7 +338,6 @@ The following properties are going to be supported for backward compatibility re
- `save` - see the [Edit and Save](/docs/designers-developers/developers/block-api/block-edit-save.md) documentation for more details.
- `transforms` - see the [Transforms](/docs/designers-developers/developers/block-api/block-registration.md#transforms-optional) documentation for more details.
- `deprecated` - see the [Deprecated Blocks](/docs/designers-developers/developers/block-api/block-deprecation.md) documentation for more details.
- `supports` - see the [block supports](/docs/designers-developers/developers/block-api/block-registration.md#supports-optional) documentation page for more details.
- `merge` - undocumented as of today. Its role is to handle merging multiple blocks into one.
- `getEditWrapperProps` - undocumented as well. Its role is to inject additional props to the block edit's component wrapper.

Expand All @@ -336,8 +350,8 @@ wp.blocks.registerBlockType( 'my-block/name', {
save: function() {
// Save definition goes here.
},
supports: {
html: false
getEditWrapperProps: function() {
// Implementation goes here.
}
} );
```
Expand Down Expand Up @@ -413,7 +427,7 @@ WordPress string discovery automatically translates these strings using the `tex
}
```

In JavaScript, with the help of a Babel plugin, this becomes:
In JavaScript, with the help of a new helper function `registerBlockTypeFromMetadata`, this becomes:

```js
const metadata = {
Expand All @@ -423,7 +437,7 @@ const metadata = {
}
```

In PHP, it is transformed at runtime to code roughly equivalent to:
In PHP, it is transformed at runtime with a new helper function `register_block_from_metadata` to code roughly equivalent to:

```php
<?php
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@
"dev:packages": "node ./bin/packages/watch.js",
"docs:build": "node ./docs/tool/index.js && node ./bin/api-docs/update-api-docs.js",
"fixtures:clean": "rimraf \"packages/e2e-tests/fixtures/blocks/*.+(json|serialized.html)\"",
"fixtures:server-registered": "packages/env/bin/wp-env run wordpress ./wp-content/plugins/gutenberg/bin/get-server-blocks.php > test/integration/full-content/server-registered.json",
"fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",
"fixtures:generate": "cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",
"fixtures:regenerate": "npm run fixtures:clean && npm run fixtures:generate",
"format-js": "wp-scripts format-js",
"lint": "concurrently \"npm run lint-lockfile\" \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"",
Expand Down
12 changes: 11 additions & 1 deletion packages/block-library/src/archives/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"attributes": {
"align": {
"type": "string",
"enum": [ "left", "center", "right", "wide", "full" ]
"enum": [
"left",
"center",
"right",
"wide",
"full"
]
},
"className": {
"type": "string"
Expand All @@ -17,5 +23,9 @@
"type": "boolean",
"default": false
}
},
"supports": {
"align": true,
"html": false
}
}
4 changes: 0 additions & 4 deletions packages/block-library/src/archives/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export const settings = {
title: __( 'Archives' ),
description: __( 'Display a monthly archive of your posts.' ),
icon,
supports: {
align: true,
html: false,
},
example: {},
edit,
};
4 changes: 4 additions & 0 deletions packages/block-library/src/audio/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@
"selector": "audio",
"attribute": "preload"
}
},
"supports": {
"align": true,
"lightBlockWrapper": true
}
}
4 changes: 0 additions & 4 deletions packages/block-library/src/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export const settings = {
icon,
transforms,
deprecated,
supports: {
align: true,
lightBlockWrapper: true,
},
edit,
save,
};
5 changes: 5 additions & 0 deletions packages/block-library/src/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"ref": {
"type": "number"
}
},
"supports": {
"customClassName": false,
"html": false,
"inserter": false
}
}
5 changes: 0 additions & 5 deletions packages/block-library/src/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ export const settings = {
description: __(
'Create and save content to reuse across your site. Update the block, and the changes apply everywhere it’s used.'
),
supports: {
customClassName: false,
html: false,
inserter: false,
},
edit,
};
9 changes: 9 additions & 0 deletions packages/block-library/src/button/block.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "core/button",
"category": "layout",
"parent": [
"core/buttons"
],
"attributes": {
"url": {
"type": "string",
Expand Down Expand Up @@ -49,5 +52,11 @@
"gradient": {
"type": "string"
}
},
"supports": {
"align": true,
"alignWide": false,
"reusable": false,
"lightBlockWrapper": true
}
}
7 changes: 0 additions & 7 deletions packages/block-library/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ export const settings = {
text: __( 'Call to Action' ),
},
},
supports: {
align: true,
alignWide: false,
reusable: false,
lightBlockWrapper: true,
},
parent: [ 'core/buttons' ],
styles: [
{ name: 'fill', label: __( 'Fill' ), isDefault: true },
{ name: 'outline', label: __( 'Outline' ) },
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/buttons/block.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"name": "core/buttons",
"category": "layout",
"attributes": {}
"supports": {
"align": true,
"alignWide": false,
"lightBlockWrapper": true
}
}
5 changes: 0 additions & 5 deletions packages/block-library/src/buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ export const settings = {
),
icon,
keywords: [ __( 'link' ) ],
supports: {
align: true,
alignWide: false,
lightBlockWrapper: true,
},
transforms,
edit,
save,
Expand Down
11 changes: 10 additions & 1 deletion packages/block-library/src/calendar/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"attributes": {
"align": {
"type": "string",
"enum": [ "left", "center", "right", "wide", "full" ]
"enum": [
"left",
"center",
"right",
"wide",
"full"
]
},
"className": {
"type": "string"
Expand All @@ -15,5 +21,8 @@
"year": {
"type": "integer"
}
},
"supports": {
"align": true
}
}
3 changes: 0 additions & 3 deletions packages/block-library/src/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export const settings = {
description: __( 'A calendar of your site’s posts.' ),
icon,
keywords: [ __( 'posts' ), __( 'archive' ) ],
supports: {
align: true,
},
example: {},
edit,
};
12 changes: 11 additions & 1 deletion packages/block-library/src/categories/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"attributes": {
"align": {
"type": "string",
"enum": [ "left", "center", "right", "wide", "full" ]
"enum": [
"left",
"center",
"right",
"wide",
"full"
]
},
"className": {
"type": "string"
Expand All @@ -21,5 +27,9 @@
"type": "boolean",
"default": false
}
},
"supports": {
"align": true,
"html": false
}
}
4 changes: 0 additions & 4 deletions packages/block-library/src/categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export const settings = {
title: __( 'Categories' ),
description: __( 'Display a list of all categories.' ),
icon,
supports: {
align: true,
html: false,
},
example: {},
edit,
};
5 changes: 5 additions & 0 deletions packages/block-library/src/classic/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"type": "string",
"source": "html"
}
},
"supports": {
"className": false,
"customClassName": false,
"reusable": false
}
}
7 changes: 0 additions & 7 deletions packages/block-library/src/classic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ export const settings = {
title: _x( 'Classic', 'block title' ),
description: __( 'Use the classic WordPress editor.' ),
icon,
supports: {
className: false,
customClassName: false,
// Hide 'Add to Reusable blocks' on Classic blocks. Showing it causes a
// confusing UX, because of its similarity to the 'Convert to Blocks' button.
reusable: false,
},
edit,
save,
};
4 changes: 4 additions & 0 deletions packages/block-library/src/code/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
"source": "text",
"selector": "code"
}
},
"supports": {
"html": false,
"lightBlockWrapper": true
}
}
4 changes: 0 additions & 4 deletions packages/block-library/src/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export const settings = {
/* eslint-enable @wordpress/i18n-no-collapsible-whitespace */
},
},
supports: {
html: false,
lightBlockWrapper: true,
},
transforms,
edit,
save,
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "core/column",
"category": "common",
"parent": [
"core/columns"
],
"attributes": {
"verticalAlignment": {
"type": "string"
Expand All @@ -10,5 +13,10 @@
"min": 0,
"max": 100
}
},
"supports": {
"reusable": false,
"html": false,
"lightBlockWrapper": true
}
}
Loading

0 comments on commit d26842b

Please sign in to comment.