From ede822c2f89c5d5da95ce96261abf38abf160d55 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 10 Apr 2019 12:52:55 +0200 Subject: [PATCH] Refactor core blocks to have save and transforms in their own files (part 3) --- packages/block-library/src/group/icon.js | 8 + packages/block-library/src/group/index.js | 36 +--- packages/block-library/src/group/save.js | 28 +++ .../src/media-text/deprecated.js | 5 +- .../block-library/src/media-text/index.js | 132 +----------- packages/block-library/src/media-text/save.js | 69 +++++++ .../src/media-text/transforms.js | 63 ++++++ packages/block-library/src/missing/index.js | 9 +- packages/block-library/src/missing/save.js | 9 + packages/block-library/src/more/index.js | 58 +----- packages/block-library/src/more/save.js | 27 +++ packages/block-library/src/more/transforms.js | 31 +++ packages/block-library/src/nextpage/index.js | 34 +--- packages/block-library/src/nextpage/save.js | 12 ++ .../block-library/src/nextpage/transforms.js | 21 ++ packages/block-library/src/paragraph/index.js | 75 +------ packages/block-library/src/paragraph/save.js | 58 ++++++ .../block-library/src/paragraph/transforms.js | 22 ++ .../block-library/src/preformatted/index.js | 52 +---- .../block-library/src/preformatted/save.js | 10 + .../src/preformatted/transforms.js | 42 ++++ packages/block-library/src/pullquote/edit.js | 6 +- packages/block-library/src/pullquote/index.js | 74 +------ packages/block-library/src/pullquote/save.js | 65 ++++++ .../block-library/src/pullquote/shared.js | 2 + packages/block-library/src/quote/index.js | 191 +----------------- packages/block-library/src/quote/save.js | 15 ++ .../block-library/src/quote/transforms.js | 175 ++++++++++++++++ packages/block-library/src/rss/index.js | 6 - packages/block-library/src/search/index.js | 6 - packages/block-library/src/separator/index.js | 31 +-- packages/block-library/src/separator/save.js | 3 + .../block-library/src/separator/transforms.js | 23 +++ packages/block-library/src/shortcode/index.js | 40 +--- packages/block-library/src/shortcode/save.js | 8 + .../block-library/src/shortcode/transforms.js | 31 +++ packages/block-library/src/spacer/index.js | 9 +- packages/block-library/src/spacer/save.js | 3 + 38 files changed, 776 insertions(+), 713 deletions(-) create mode 100644 packages/block-library/src/group/icon.js create mode 100644 packages/block-library/src/group/save.js create mode 100644 packages/block-library/src/media-text/save.js create mode 100644 packages/block-library/src/media-text/transforms.js create mode 100644 packages/block-library/src/missing/save.js create mode 100644 packages/block-library/src/more/save.js create mode 100644 packages/block-library/src/more/transforms.js create mode 100644 packages/block-library/src/nextpage/save.js create mode 100644 packages/block-library/src/nextpage/transforms.js create mode 100644 packages/block-library/src/paragraph/save.js create mode 100644 packages/block-library/src/paragraph/transforms.js create mode 100644 packages/block-library/src/preformatted/save.js create mode 100644 packages/block-library/src/preformatted/transforms.js create mode 100644 packages/block-library/src/pullquote/save.js create mode 100644 packages/block-library/src/pullquote/shared.js create mode 100644 packages/block-library/src/quote/save.js create mode 100644 packages/block-library/src/quote/transforms.js create mode 100644 packages/block-library/src/separator/save.js create mode 100644 packages/block-library/src/separator/transforms.js create mode 100644 packages/block-library/src/shortcode/save.js create mode 100644 packages/block-library/src/shortcode/transforms.js create mode 100644 packages/block-library/src/spacer/save.js diff --git a/packages/block-library/src/group/icon.js b/packages/block-library/src/group/icon.js new file mode 100644 index 00000000000000..959b844350615f --- /dev/null +++ b/packages/block-library/src/group/icon.js @@ -0,0 +1,8 @@ +/** + * WordPress dependencies + */ +import { Path, SVG } from '@wordpress/components'; + +export default ( + +); diff --git a/packages/block-library/src/group/index.js b/packages/block-library/src/group/index.js index 13c02c9c955c72..9bab779f5863b5 100644 --- a/packages/block-library/src/group/index.js +++ b/packages/block-library/src/group/index.js @@ -1,20 +1,15 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - /** * WordPress dependencies */ -import { Path, SVG } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { InnerBlocks, getColorClassName } from '@wordpress/block-editor'; /** * Internal dependencies */ import edit from './edit'; +import icon from './icon'; import metadata from './block.json'; +import save from './save'; const { name } = metadata; @@ -22,37 +17,14 @@ export { metadata, name }; export const settings = { title: __( 'Group' ), - - icon: , - + icon, description: __( 'A block that groups other blocks.' ), - keywords: [ __( 'container' ), __( 'wrapper' ), __( 'row' ), __( 'section' ) ], - supports: { align: [ 'wide', 'full' ], anchor: true, html: false, }, - edit, - - save( { attributes } ) { - const { backgroundColor, customBackgroundColor } = attributes; - - const backgroundClass = getColorClassName( 'background-color', backgroundColor ); - const className = classnames( backgroundClass, { - 'has-background': backgroundColor || customBackgroundColor, - } ); - - const styles = { - backgroundColor: backgroundClass ? undefined : customBackgroundColor, - }; - - return ( -
- -
- ); - }, + save, }; diff --git a/packages/block-library/src/group/save.js b/packages/block-library/src/group/save.js new file mode 100644 index 00000000000000..a0ee8246c69a8d --- /dev/null +++ b/packages/block-library/src/group/save.js @@ -0,0 +1,28 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + +/** + * WordPress dependencies + */ +import { InnerBlocks, getColorClassName } from '@wordpress/block-editor'; + +export default function save( { attributes } ) { + const { backgroundColor, customBackgroundColor } = attributes; + + const backgroundClass = getColorClassName( 'background-color', backgroundColor ); + const className = classnames( backgroundClass, { + 'has-background': backgroundColor || customBackgroundColor, + } ); + + const styles = { + backgroundColor: backgroundClass ? undefined : customBackgroundColor, + }; + + return ( +
+ +
+ ); +} diff --git a/packages/block-library/src/media-text/deprecated.js b/packages/block-library/src/media-text/deprecated.js index ab36e6859b3e84..2123e259a97faf 100644 --- a/packages/block-library/src/media-text/deprecated.js +++ b/packages/block-library/src/media-text/deprecated.js @@ -12,10 +12,7 @@ import { getColorClassName, } from '@wordpress/block-editor'; -/** - * Internal dependencies - */ -import { DEFAULT_MEDIA_WIDTH } from './index'; +const DEFAULT_MEDIA_WIDTH = 50; export default [ { diff --git a/packages/block-library/src/media-text/index.js b/packages/block-library/src/media-text/index.js index 781b7e60b52cf9..b20dc9693bafa8 100644 --- a/packages/block-library/src/media-text/index.js +++ b/packages/block-library/src/media-text/index.js @@ -1,29 +1,17 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; -import { noop } from 'lodash'; - /** * WordPress dependencies */ -import { createBlock } from '@wordpress/blocks'; -import { - InnerBlocks, - getColorClassName, -} from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ +import deprecated from './deprecated'; import edit from './edit'; import icon from './icon'; -import deprecated from './deprecated'; -import { imageFillStyles } from './media-container'; import metadata from './block.json'; - -export const DEFAULT_MEDIA_WIDTH = 50; +import save from './save'; +import transforms from './transforms'; const { name } = metadata; @@ -31,125 +19,15 @@ export { metadata, name }; export const settings = { title: __( 'Media & Text' ), - description: __( 'Set media and words side-by-side for a richer layout.' ), - icon, - keywords: [ __( 'image' ), __( 'video' ) ], - supports: { align: [ 'wide', 'full' ], html: false, }, - - transforms: { - from: [ - { - type: 'block', - blocks: [ 'core/image' ], - transform: ( { alt, url, id } ) => ( - createBlock( 'core/media-text', { - mediaAlt: alt, - mediaId: id, - mediaUrl: url, - mediaType: 'image', - } ) - ), - }, - { - type: 'block', - blocks: [ 'core/video' ], - transform: ( { src, id } ) => ( - createBlock( 'core/media-text', { - mediaId: id, - mediaUrl: src, - mediaType: 'video', - } ) - ), - }, - ], - to: [ - { - type: 'block', - blocks: [ 'core/image' ], - isMatch: ( { mediaType, mediaUrl } ) => { - return ! mediaUrl || mediaType === 'image'; - }, - transform: ( { mediaAlt, mediaId, mediaUrl } ) => { - return createBlock( 'core/image', { - alt: mediaAlt, - id: mediaId, - url: mediaUrl, - } ); - }, - }, - { - type: 'block', - blocks: [ 'core/video' ], - isMatch: ( { mediaType, mediaUrl } ) => { - return ! mediaUrl || mediaType === 'video'; - }, - transform: ( { mediaId, mediaUrl } ) => { - return createBlock( 'core/video', { - id: mediaId, - src: mediaUrl, - } ); - }, - }, - ], - }, - + transforms, edit, - - save( { attributes } ) { - const { - backgroundColor, - customBackgroundColor, - isStackedOnMobile, - mediaAlt, - mediaPosition, - mediaType, - mediaUrl, - mediaWidth, - mediaId, - verticalAlignment, - imageFill, - focalPoint, - } = attributes; - const mediaTypeRenders = { - image: () => {, - video: () =>