From 76163734ddcbbc1a73a85eb1502cf7d88d0ea3a8 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 2 Apr 2019 16:48:01 +0200 Subject: [PATCH] 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 705c561b58b7f9..da1ab153a4e5f9 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 dace40d4ea0003..05b07ad5bb2d19 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 8048056554ae25..00000000000000 --- 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 1fff04fe124054..82e4ed78972ba6 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 98e85861064b7b..c40f929eca496d 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 47fa6721cea7a7..80aa7f460f2463 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"