Skip to content

Commit aca4c8f

Browse files
committed
fix: restructure block dependency
1 parent 2ebbfda commit aca4c8f

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

src/block/button/block.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
],
1414
"textdomain": "stackable-ultimate-gutenberg-blocks",
1515
"stk-type": "hidden",
16-
"stk-demo": "https://wpstackable.com/button-block/?utm_source=welcome&utm_medium=settings&utm_campaign=view_demo&utm_content=demolink"
16+
"stk-demo": "https://wpstackable.com/button-block/?utm_source=welcome&utm_medium=settings&utm_campaign=view_demo&utm_content=demolink",
17+
"stk-block-dependency": "stackable/button-group|button"
1718
}

src/block/icon-button/block.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
],
1414
"textdomain": "stackable-ultimate-gutenberg-blocks",
1515
"stk-type": "hidden",
16-
"stk-demo": "https://wpstackable.com/icon-button-block/?utm_source=welcome&utm_medium=settings&utm_campaign=view_demo&utm_content=demolink"
16+
"stk-demo": "https://wpstackable.com/icon-button-block/?utm_source=welcome&utm_medium=settings&utm_campaign=view_demo&utm_content=demolink",
17+
"stk-block-dependency": "stackable/button-group|icon-button"
1718
}

src/disabled-blocks.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { settings } from 'stackable'
66
import { addFilter } from '@wordpress/hooks'
77
import {
88
BLOCK_STATE,
9-
BLOCK_DEPENDENCIES,
109
substituteCoreIfDisabled,
1110
} from '~stackable/util'
1211
import _ from 'lodash'
@@ -55,8 +54,8 @@ const applySettingsToMeta = metadata => {
5554
}
5655

5756
// Check if this block is dependent on another variation being enabled.
58-
if ( BLOCK_DEPENDENCIES[ metadata.name ] && BLOCK_DEPENDENCIES[ metadata.name ] in disabledBlocks ) {
59-
inserter = ! disabledBlocks[ BLOCK_DEPENDENCIES[ metadata.name ] ] === BLOCK_STATE.HIDDEN
57+
if ( metadata[ 'stk-block-dependency' ] && metadata[ 'stk-block-dependency' ] in disabledBlocks ) {
58+
inserter = ! disabledBlocks[ metadata[ 'stk-block-dependency' ] ] === BLOCK_STATE.HIDDEN
6059
}
6160

6261
const variationsToRemove = getVariationsToRemove( disabledBlocks, metadata.name )

src/util/blocks.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ export const BLOCK_STATE = Object.freeze( {
4646
DISABLED: 3,
4747
} )
4848

49-
/**
50-
* Block dependencies. If a block is hidden/disabled, the block it depends on will also be one.
51-
*/
52-
export const BLOCK_DEPENDENCIES = {
53-
'stackable/icon-button': 'stackable/button-group|icon-button',
54-
'stackable/button': 'stackable/button-group|button',
55-
}
56-
5749
/**
5850
* Converts the registered block name into a block name string that can be used in hook names or ids.
5951
*
@@ -498,8 +490,8 @@ export const addStackableBlockCategory = () => {
498490
*/
499491
export const registerBlockType = ( name, _settings ) => {
500492
// Do not register the block if the block is disabled.
501-
if ( ( BLOCK_DEPENDENCIES[ name ] in stackableSettings.stackable_block_states &&
502-
stackableSettings.stackable_block_states[ BLOCK_DEPENDENCIES[ name ] ] === BLOCK_STATE.DISABLED ) ||
493+
if ( ( _settings[ 'stk-block-dependency' ] in stackableSettings.stackable_block_states &&
494+
stackableSettings.stackable_block_states[ _settings[ 'stk-block-dependency' ] ] === BLOCK_STATE.DISABLED ) ||
503495
stackableSettings.stackable_block_states[ name ] === BLOCK_STATE.DISABLED
504496
) {
505497
return

0 commit comments

Comments
 (0)