From 5cc9944ea0292ca52f5c664631798e02259b5c29 Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Sat, 25 Aug 2018 23:08:16 -0500 Subject: [PATCH 1/2] =?UTF-8?q?Add=20Text=20Columns=20=E2=86=92=20Columns?= =?UTF-8?q?=20transform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/block-library/src/columns/index.js | 32 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/columns/index.js b/packages/block-library/src/columns/index.js index 5474cfae1e07ac..6bf7896d87b0a2 100644 --- a/packages/block-library/src/columns/index.js +++ b/packages/block-library/src/columns/index.js @@ -39,6 +39,10 @@ const getColumnsTemplate = memoize( ( columns ) => { return times( columns, () => [ 'core/column' ] ); } ); +const supports = { + align: [ 'wide', 'full' ], +}; + export const name = 'core/columns'; export const settings = { @@ -62,8 +66,32 @@ export const settings = { description: __( 'Add a block that displays content in multiple columns, then add whatever content blocks you’d like.' ), - supports: { - align: [ 'wide', 'full' ], + supports, + + transforms: { + from: [ + { + type: 'block', + blocks: [ 'core/text-columns' ], + transform: ( { className, columns, content, width } ) => ( + createBlock( + 'core/columns', + { + align: supports.align.includes( width ) ? width : undefined, + className, + columns, + }, + content.map( ( { children } ) => + createBlock( + 'core/column', + {}, + [ createBlock( 'core/paragraph', { content: children } ) ] + ) + ) + ) + ), + }, + ], }, deprecated: [ From 0d8d627871baa1096e683e2ba6d07bedf7c1ce41 Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Mon, 27 Aug 2018 09:44:18 -0500 Subject: [PATCH 2/2] Moved transform to text-columns/index.js --- packages/block-library/src/columns/index.js | 32 ++----------------- .../block-library/src/text-columns/index.js | 27 ++++++++++++++++ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/packages/block-library/src/columns/index.js b/packages/block-library/src/columns/index.js index 6bf7896d87b0a2..5474cfae1e07ac 100644 --- a/packages/block-library/src/columns/index.js +++ b/packages/block-library/src/columns/index.js @@ -39,10 +39,6 @@ const getColumnsTemplate = memoize( ( columns ) => { return times( columns, () => [ 'core/column' ] ); } ); -const supports = { - align: [ 'wide', 'full' ], -}; - export const name = 'core/columns'; export const settings = { @@ -66,32 +62,8 @@ export const settings = { description: __( 'Add a block that displays content in multiple columns, then add whatever content blocks you’d like.' ), - supports, - - transforms: { - from: [ - { - type: 'block', - blocks: [ 'core/text-columns' ], - transform: ( { className, columns, content, width } ) => ( - createBlock( - 'core/columns', - { - align: supports.align.includes( width ) ? width : undefined, - className, - columns, - }, - content.map( ( { children } ) => - createBlock( - 'core/column', - {}, - [ createBlock( 'core/paragraph', { content: children } ) ] - ) - ) - ) - ), - }, - ], + supports: { + align: [ 'wide', 'full' ], }, deprecated: [ diff --git a/packages/block-library/src/text-columns/index.js b/packages/block-library/src/text-columns/index.js index 0c162daab067d5..c1bb09f0bdfa0a 100644 --- a/packages/block-library/src/text-columns/index.js +++ b/packages/block-library/src/text-columns/index.js @@ -6,6 +6,7 @@ import { get, times } from 'lodash'; /** * WordPress dependencies */ +import { createBlock } from '@wordpress/blocks'; import { __ } from '@wordpress/i18n'; import { PanelBody, RangeControl } from '@wordpress/components'; import { Fragment } from '@wordpress/element'; @@ -54,6 +55,32 @@ export const settings = { }, }, + transforms: { + to: [ + { + type: 'block', + blocks: [ 'core/columns' ], + transform: ( { className, columns, content, width } ) => ( + createBlock( + 'core/columns', + { + align: ( 'wide' === width || 'full' === width ) ? width : undefined, + className, + columns, + }, + content.map( ( { children } ) => + createBlock( + 'core/column', + {}, + [ createBlock( 'core/paragraph', { content: children } ) ] + ) + ) + ) + ), + }, + ], + }, + getEditWrapperProps( attributes ) { const { width } = attributes; if ( 'wide' === width || 'full' === width ) {