UNPKG

@wordpress/block-library

Version:
145 lines (143 loc) 3.5 kB
/** * WordPress dependencies */ import { createBlock } from '@wordpress/blocks'; const transforms = { from: [{ type: 'block', blocks: ['core/pullquote'], transform: _ref => { let { value, citation, anchor, fontSize, style } = _ref; return createBlock('core/quote', { citation, anchor, fontSize, style }, [createBlock('core/paragraph', { content: value })]); } }, { type: 'block', blocks: ['core/group'], transform: (_ref2, innerBlocks) => { let { anchor } = _ref2; return createBlock('core/quote', { anchor }, innerBlocks); } }, { type: 'prefix', prefix: '>', transform: content => createBlock('core/quote', {}, [createBlock('core/paragraph', { content })]) }, { type: 'raw', schema: () => ({ blockquote: { children: '*' } }), selector: 'blockquote', transform: (node, handler) => { return createBlock('core/quote', // Don't try to parse any `cite` out of this content. // * There may be more than one cite. // * There may be more attribution text than just the cite. // * If the cite is nested in the quoted text, it's wrong to // remove it. {}, handler({ HTML: node.innerHTML, mode: 'BLOCKS' })); } }, { type: 'block', isMultiBlock: true, blocks: ['*'], isMatch: (_ref3, blocks) => { let {} = _ref3; // When a single block is selected make the tranformation // available only to specific blocks that make sense. if (blocks.length === 1) { return ['core/paragraph', 'core/heading', 'core/list', 'core/pullquote'].includes(blocks[0].name); } return !blocks.some(_ref4 => { let { name } = _ref4; return name === 'core/quote'; }); }, __experimentalConvert: blocks => createBlock('core/quote', {}, blocks.map(block => createBlock(block.name, block.attributes, block.innerBlocks))) }], to: [{ type: 'block', blocks: ['core/pullquote'], isMatch: (_ref5, block) => { let {} = _ref5; return block.innerBlocks.every(_ref6 => { let { name } = _ref6; return name === 'core/paragraph'; }); }, transform: (_ref7, innerBlocks) => { let { citation, anchor, fontSize, style } = _ref7; const value = innerBlocks.map(_ref8 => { let { attributes } = _ref8; return `${attributes.content}`; }).join('<br>'); return createBlock('core/pullquote', { value, citation, anchor, fontSize, style }); } }, { type: 'block', blocks: ['core/group'], transform: (_ref9, innerBlocks) => { let { citation, anchor } = _ref9; return createBlock('core/group', { anchor }, citation ? [...innerBlocks, createBlock('core/paragraph', { content: citation })] : innerBlocks); } }, { type: 'block', blocks: ['*'], transform: (_ref10, innerBlocks) => { let { citation } = _ref10; return citation ? [...innerBlocks, createBlock('core/paragraph', { content: citation })] : innerBlocks; } }] }; export default transforms; //# sourceMappingURL=transforms.js.map