Skip to content

Commit

Permalink
Preserve citation when unwrapping the blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Apr 9, 2018
1 parent f4c2fdc commit de6c04b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions blocks/library/pullquote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ export const settings = {

attributes: blockAttributes,

transforms: {
to: [
{
type: 'unwrap',
transform: ( { citation }, innerBlocks ) => [
...innerBlocks,
createBlock( 'core/paragraph', { content: citation } ),
],
},
],
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) {
Expand Down
8 changes: 6 additions & 2 deletions editor/components/block-settings-menu/block-unwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
* External dependencies
*/
import { connect } from 'react-redux';
import { noop, flatMap } from 'lodash';
import { noop, flatMap, find } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { IconButton, withContext } from '@wordpress/components';
import { compose } from '@wordpress/element';
import { getBlockTransforms } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -50,7 +51,10 @@ export default compose(
onUnwrap( blocks ) {
dispatch( replaceBlocks(
ownProps.uids,
flatMap( blocks, ( { innerBlocks } ) => innerBlocks ),
flatMap( blocks, ( { name, attributes, innerBlocks } ) => {
const transform = find( getBlockTransforms( 'to', name ), { type: 'unwrap' } );
return transform ? transform.transform( attributes, innerBlocks ) : innerBlocks;
} ),
) );
},
} )
Expand Down

0 comments on commit de6c04b

Please sign in to comment.