Skip to content

Commit

Permalink
Quote: Stop using constants for attribute keys and move definition to…
Browse files Browse the repository at this point in the history
… block.json
  • Loading branch information
gziolo committed Apr 5, 2019
1 parent 19b2498 commit 45723df
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 42 deletions.
9 changes: 5 additions & 4 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
setDefaultBlockName,
setFreeformContentHandlerName,
setUnregisteredTypeHandlerName,
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
} from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -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 );
Expand Down
20 changes: 19 additions & 1 deletion packages/block-library/src/quote/block.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
2 changes: 0 additions & 2 deletions packages/block-library/src/quote/contants.js

This file was deleted.

15 changes: 3 additions & 12 deletions packages/block-library/src/quote/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +19,7 @@ export default function QuoteEdit( { attributes, setAttributes, isSelected, merg
</BlockControls>
<blockquote className={ className } style={ { textAlign: align } }>
<RichText
identifier={ ATTRIBUTE_QUOTE }
identifier="value"
multiline
value={ value }
onChange={
Expand All @@ -50,7 +41,7 @@ export default function QuoteEdit( { attributes, setAttributes, isSelected, merg
/>
{ ( ! RichText.isEmpty( citation ) || isSelected ) && (
<RichText
identifier={ ATTRIBUTE_CITATION }
identifier="citation"
value={ citation }
onChange={
( nextCitation ) => setAttributes( {
Expand Down
24 changes: 2 additions & 22 deletions packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 45723df

Please sign in to comment.