@@ -34,48 +34,28 @@ import { useBlockProps } from '@wordpress/block-editor'
3434// Replaces the current block with a block made out of attributes.
3535const createBlockWithAttributes = ( blockName , attributes , innerBlocks , design ) => {
3636 const disabledBlocks = settings . stackable_block_states || { } // eslint-disable-line camelcase
37- const nonSubstitutableBlocks = new Set ( )
3837
3938 // Recursively substitute core blocks to disabled Stackable blocks
4039 const traverseBlocksAndSubstitute = blocks => {
4140 return blocks . map ( block => {
42- let [ blockName , blockAttributes , innerBlocks ] = block
43-
44- if ( innerBlocks && innerBlocks . length > 0 ) {
45- innerBlocks = traverseBlocksAndSubstitute ( innerBlocks )
41+ if ( block [ 2 ] && block [ 2 ] . length > 0 ) {
42+ block [ 2 ] = traverseBlocksAndSubstitute ( block [ 2 ] )
4643 }
4744
48- const substituted = substituteCoreIfDisabled ( blockName , blockAttributes , innerBlocks , substitutionRules )
49- const blockType = getBlockType ( blockName )
50-
51- // Get the disabled non-substitutable blocks
52- if ( ! ( blockName in substitutionRules ) &&
53- ( ! blockType || blockType [ 'stk-cannot-be-disabled' ] !== true ) &&
54- blockName in disabledBlocks &&
55- disabledBlocks [ blockName ] === BLOCK_STATE . DISABLED
56- ) {
57- nonSubstitutableBlocks . add ( blockName )
45+ // Check if the new substituted block is still disabled
46+ while ( block [ 0 ] in disabledBlocks && disabledBlocks [ block [ 0 ] ] === BLOCK_STATE . DISABLED ) {
47+ block = substituteCoreIfDisabled ( ...block , substitutionRules )
5848 }
5949
60- if ( ! Array . isArray ( substituted [ 2 ] ) ) {
61- substituted [ 2 ] = [ ]
50+ if ( ! Array . isArray ( block [ 2 ] ) ) {
51+ block [ 2 ] = [ ]
6252 }
63- return substituted
53+ return block
6454 } )
6555 }
6656
6757 innerBlocks = traverseBlocksAndSubstitute ( innerBlocks )
6858
69- // Warn the user which blocks are needed to be enabled
70- if ( nonSubstitutableBlocks . size > 0 ) {
71- // eslint-disable no-console
72- console . warn ( // eslint-disable-line no-console
73- `The selected design requires the following block(s) to be enabled for it to function properly:\n\n` +
74- `${ Array . from ( nonSubstitutableBlocks ) . join ( '\n' ) } `
75- )
76- // eslint-enable no-console
77- }
78-
7959 // const { replaceBlock } = dispatch( 'core/block-editor' )
8060
8161 // For wireframes, we'll need to apply any default block attributes to
0 commit comments