@@ -32,7 +32,7 @@ import {
32
32
Transform ,
33
33
} from '~stackable/block-components'
34
34
import {
35
- useBlockAttributesContext , useBlockContext , useBlockSetAttributesContext ,
35
+ useBlockAttributesContext , useBlockSetAttributesContext ,
36
36
} from '~stackable/hooks'
37
37
import {
38
38
withBlockAttributeContext , withBlockWrapperIsHovered , withQueryLoopContext ,
@@ -46,7 +46,7 @@ import variations, { defaultIcon } from './variations'
46
46
/**
47
47
* WordPress dependencies
48
48
*/
49
- import { InnerBlocks } from '@wordpress/block-editor'
49
+ import { InnerBlocks , useBlockEditContext } from '@wordpress/block-editor'
50
50
import { __ } from '@wordpress/i18n'
51
51
import { compose } from '@wordpress/compose'
52
52
import { useSelect } from '@wordpress/data'
@@ -64,7 +64,12 @@ const Edit = props => {
64
64
} = props
65
65
66
66
const [ isOpen , setIsOpen ] = useState ( props . attributes . startOpen )
67
- const { hasInnerBlocks } = useBlockContext ( )
67
+ const { hasInnerBlocks } = useSelect ( select => {
68
+ const { getBlockOrder } = select ( 'core/block-editor' )
69
+ return {
70
+ hasInnerBlocks : getBlockOrder ( clientId ) . length > 0 ,
71
+ }
72
+ } , [ clientId ] )
68
73
const [ hasInitClickHandler , setHasInitClickHandler ] = useState ( false )
69
74
const { getEditorDom } = useSelect ( 'stackable/editor-dom' )
70
75
@@ -215,8 +220,15 @@ addFilter( 'stackable.block-component.icon.after', 'stackable/blockquote', outpu
215
220
const icon2 = useBlockAttributesContext ( attributes => attributes . icon2 )
216
221
const setAttributes = useBlockSetAttributesContext ( )
217
222
218
- const { parentTree } = useBlockContext ( )
219
- const { getBlock } = useSelect ( 'core/block-editor' )
223
+ const { clientId } = useBlockEditContext ( )
224
+ const { parentTree, getBlock } = useSelect ( select => {
225
+ const { getBlock, getBlockParents } = select ( 'core/block-editor' )
226
+ const parentTree = getBlockParents ( clientId ) . map ( parentClientId => ( { clientId : parentClientId , name : getBlock ( parentClientId ) . name } ) )
227
+ return {
228
+ getBlock,
229
+ parentTree,
230
+ }
231
+ } , [ clientId ] )
220
232
const { getActiveBlockVariation } = useSelect ( 'core/blocks' )
221
233
222
234
const accordionBlock = findLast ( parentTree , pt => pt . name === 'stackable/accordion' )
@@ -259,8 +271,15 @@ addFilter( 'stackable.block-default-styles.use-saved-style', 'stackable/icon-lab
259
271
260
272
// Return default icon for accordion
261
273
addFilter ( 'stackable.block-component.icon.default' , 'stackable/accordion' , starIcon => {
262
- const { parentTree } = useBlockContext ( )
263
- const { getBlock } = useSelect ( 'core/block-editor' )
274
+ const { clientId } = useBlockEditContext ( )
275
+ const { parentTree, getBlock } = useSelect ( select => {
276
+ const { getBlock, getBlockParents } = select ( 'core/block-editor' )
277
+ const parentTree = getBlockParents ( clientId ) . map ( parentClientId => ( { clientId : parentClientId , name : getBlock ( parentClientId ) . name } ) )
278
+ return {
279
+ getBlock,
280
+ parentTree,
281
+ }
282
+ } , [ clientId ] )
264
283
const { getActiveBlockVariation } = useSelect ( 'core/blocks' )
265
284
266
285
const accordionBlock = findLast ( parentTree , pt => pt . name === 'stackable/accordion' )
0 commit comments