Skip to content

Commit

Permalink
Block library: Introduce block.json metadata for all client side blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 2, 2019
1 parent 304d43a commit 9fe927f
Show file tree
Hide file tree
Showing 60 changed files with 443 additions and 182 deletions.
38 changes: 38 additions & 0 deletions packages/block-library/src/audio/block.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
42 changes: 4 additions & 38 deletions packages/block-library/src/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -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: [
{
Expand Down
35 changes: 35 additions & 0 deletions packages/block-library/src/button/block.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
39 changes: 3 additions & 36 deletions packages/block-library/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,11 @@ import {
* Internal dependencies
*/
import edit from './edit';
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( {
Expand All @@ -68,12 +39,8 @@ export const settings = {

icon: <SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path fill="none" d="M0 0h24v24H0V0z" /><G><Path d="M19 6H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 10H5V8h14v8z" /></G></SVG>,

category: 'layout',

keywords: [ __( 'link' ) ],

attributes: blockAttributes,

supports: {
align: true,
alignWide: false,
Expand Down
10 changes: 10 additions & 0 deletions packages/block-library/src/classic/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "core/freeform",
"category": "formatting",
"attributes": {
"content": {
"type": "string",
"source": "html"
}
}
}
14 changes: 4 additions & 10 deletions packages/block-library/src/classic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { Path, Rect, SVG } from '@wordpress/components';
* Internal dependencies
*/
import edit from './edit';
import metadata from './block.json';

export const name = 'core/freeform';
const { name } = metadata;

export { metadata, name };

export const settings = {
title: _x( 'Classic', 'block title' ),
Expand All @@ -19,15 +22,6 @@ export const settings = {

icon: <SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path d="M0,0h24v24H0V0z M0,0h24v24H0V0z" fill="none" /><Path d="m20 7v10h-16v-10h16m0-2h-16c-1.1 0-1.99 0.9-1.99 2l-0.01 10c0 1.1 0.9 2 2 2h16c1.1 0 2-0.9 2-2v-10c0-1.1-0.9-2-2-2z" /><Rect x="11" y="8" width="2" height="2" /><Rect x="11" y="11" width="2" height="2" /><Rect x="8" y="8" width="2" height="2" /><Rect x="8" y="11" width="2" height="2" /><Rect x="5" y="11" width="2" height="2" /><Rect x="5" y="8" width="2" height="2" /><Rect x="8" y="14" width="8" height="2" /><Rect x="14" y="11" width="2" height="2" /><Rect x="14" y="8" width="2" height="2" /><Rect x="17" y="11" width="2" height="2" /><Rect x="17" y="8" width="2" height="2" /></SVG>,

category: 'formatting',

attributes: {
content: {
type: 'string',
source: 'html',
},
},

supports: {
className: false,
customClassName: false,
Expand Down
11 changes: 11 additions & 0 deletions packages/block-library/src/code/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "core/code",
"category": "formatting",
"attributes": {
"content": {
"type": "string",
"source": "text",
"selector": "code"
}
}
}
15 changes: 4 additions & 11 deletions packages/block-library/src/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import {
* Internal dependencies
*/
import edit from './edit';
import metadata from './block.json';

export const name = 'core/code';
const { name } = metadata;

export { metadata, name };

export const settings = {
title: __( 'Code' ),
Expand All @@ -22,16 +25,6 @@ export const settings = {

icon: <SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path d="M0,0h24v24H0V0z" fill="none" /><Path d="M9.4,16.6L4.8,12l4.6-4.6L8,6l-6,6l6,6L9.4,16.6z M14.6,16.6l4.6-4.6l-4.6-4.6L16,6l6,6l-6,6L14.6,16.6z" /></SVG>,

category: 'formatting',

attributes: {
content: {
type: 'string',
source: 'text',
selector: 'code',
},
},

supports: {
html: false,
},
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "core/column",
"category": "common",
"attributes": {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,8 +77,6 @@ export const settings = {

description: __( 'A single column within a columns block.' ),

category: 'common',

attributes: {
verticalAlignment: {
type: 'string',
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/columns/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "core/columns",
"category": "layout",
"attributes": {

}
}
7 changes: 4 additions & 3 deletions packages/block-library/src/columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ import {
*/
import deprecated from './deprecated';
import edit from './edit';
import metadata from './block.json';

export const name = 'core/columns';
const { name } = metadata;

export { metadata, name };

export const settings = {
title: __( 'Columns' ),

icon: <SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path fill="none" d="M0 0h24v24H0V0z" /><G><Path d="M4,4H20a2,2,0,0,1,2,2V18a2,2,0,0,1-2,2H4a2,2,0,0,1-2-2V6A2,2,0,0,1,4,4ZM4 6V18H8V6Zm6 0V18h4V6Zm6 0V18h4V6Z" /></G></SVG>,

category: 'layout',

attributes: {
columns: {
type: 'number',
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "core/cover",
"category": "common",
"attributes": {

}
}
9 changes: 5 additions & 4 deletions packages/block-library/src/cover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import {
backgroundImageStyles,
dimRatioToClass,
} from './edit';
import metadata from './block.json';

const { name } = metadata;

export { metadata, name };

const blockAttributes = {
url: {
Expand Down Expand Up @@ -57,17 +62,13 @@ const blockAttributes = {
},
};

export const name = 'core/cover';

export const settings = {
title: __( 'Cover' ),

description: __( 'Add an image or video with a text overlay — great for headers.' ),

icon,

category: 'common',

attributes: blockAttributes,

supports: {
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/file/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "core/file",
"category": "common",
"attributes": {

}
}
Loading

0 comments on commit 9fe927f

Please sign in to comment.