/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/block-library/src/group/transforms.js
46 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { createBlock, cloneSanitizedBlock } from '@wordpress/blocks'; const transforms = { from: [ { type: 'block', isMultiBlock: true, blocks: [ '*' ], __experimentalConvert( blocks ) { const alignments = [ 'wide', 'full' ]; // Determine the widest setting of all the blocks to be grouped const widestAlignment = blocks.reduce( ( accumulator, block ) => { const { align } = block.attributes; return alignments.indexOf( align ) > alignments.indexOf( accumulator ) ? align : accumulator; }, undefined ); // Clone the Blocks to be Grouped // Failing to create new block references causes the original blocks // to be replaced in the switchToBlockType call thereby meaning they // are removed both from their original location and within the // new group block. const groupInnerBlocks = blocks.map( ( block ) => cloneSanitizedBlock( block ) ); return createBlock( 'core/group', { align: widestAlignment, layout: { type: 'constrained' }, }, groupInnerBlocks ); }, }, ], }; export default transforms;