@@ -11,14 +11,16 @@ import { SVGStackableIcon } from '~stackable/icons'
1111import {
1212 deprecateBlockBackgroundColorOpacity , deprecateContainerBackgroundColorOpacity , deprecateTypographyGradientColor ,
1313} from '~stackable/block-components'
14+ import { substituteCoreIfDisabled } from '~stackable/util'
15+ import { substitutionRules } from '../../blocks'
1416
1517/**
1618 * WordPress dependencies
1719 */
1820import { __ } from '@wordpress/i18n'
1921import { dispatch } from '@wordpress/data'
2022import {
21- createBlock , parse , createBlocksFromInnerBlocksTemplate , getBlockVariations ,
23+ createBlock , parse , createBlocksFromInnerBlocksTemplate , getBlockVariations , getBlockType ,
2224} from '@wordpress/blocks'
2325import { useState } from '@wordpress/element'
2426import { addFilter , applyFilters } from '@wordpress/hooks'
@@ -27,6 +29,22 @@ import { useBlockProps } from '@wordpress/block-editor'
2729
2830// Replaces the current block with a block made out of attributes.
2931const createBlockWithAttributes = ( blockName , attributes , innerBlocks , design ) => {
32+ // Recursively substitute core blocks to disabled Stackable blocks
33+ const traverseBlocksAndSubstitute = blocks => {
34+ return blocks . map ( block => {
35+ let [ blockName , blockAttributes , innerBlocks ] = block
36+ if ( innerBlocks && innerBlocks . length > 0 ) {
37+ innerBlocks = traverseBlocksAndSubstitute ( innerBlocks )
38+ }
39+ const substituted = substituteCoreIfDisabled ( blockName , blockAttributes , innerBlocks , substitutionRules )
40+ if ( ! Array . isArray ( substituted [ 2 ] ) ) {
41+ substituted [ 2 ] = [ ]
42+ }
43+ return substituted
44+ } )
45+ }
46+
47+ innerBlocks = traverseBlocksAndSubstitute ( innerBlocks )
3048 // const { replaceBlock } = dispatch( 'core/block-editor' )
3149
3250 // For wireframes, we'll need to apply any default block attributes to
@@ -44,9 +62,9 @@ const createBlockWithAttributes = ( blockName, attributes, innerBlocks, design )
4462 blocks . forEach ( block => {
4563 const blockName = block [ 0 ]
4664
47- // For blocks with varitions , do not remove the uniqueId
65+ // For blocks with variations , do not remove the uniqueId
4866 // since that will prompt the layout picker to show.
49- const hasVariations = getBlockVariations ( blockName ) . length > 0
67+ const hasVariations = ! ! getBlockType ( blockName ) && getBlockVariations ( blockName ) . length > 0
5068 if ( ! hasVariations && block [ 1 ] . uniqueId ) {
5169 delete block [ 1 ] . uniqueId
5270 }
0 commit comments