@@ -35,7 +35,7 @@ import {
35
35
getContentAlignmentClasses ,
36
36
Typography ,
37
37
} from '~stackable/block-components'
38
- import { useBlockContext , useDeviceType } from '~stackable/hooks'
38
+ import { useDeviceType } from '~stackable/hooks'
39
39
import {
40
40
withBlockAttributeContext ,
41
41
withBlockWrapperIsHovered ,
@@ -52,7 +52,7 @@ import {
52
52
} from '@wordpress/i18n'
53
53
import { InnerBlocks } from '@wordpress/block-editor'
54
54
import { addFilter } from '@wordpress/hooks'
55
- import { dispatch } from '@wordpress/data'
55
+ import { dispatch , useSelect } from '@wordpress/data'
56
56
import {
57
57
useEffect , useRef , useState , memo ,
58
58
} from '@wordpress/element'
@@ -96,9 +96,30 @@ const Edit = props => {
96
96
const separatorClass = getSeparatorClasses ( props . attributes )
97
97
const blockAlignmentClass = getAlignmentClasses ( props . attributes )
98
98
const typographyClass = getTypographyClasses ( props . attributes )
99
+
99
100
const {
100
101
hasInnerBlocks, nextBlock, previousBlock, adjacentBlocks, blockIndex,
101
- } = useBlockContext ( )
102
+ } = useSelect ( select => {
103
+ const {
104
+ getBlockRootClientId, getBlocks, getBlockIndex,
105
+ } = select ( 'core/block-editor' )
106
+
107
+ const parentClientId = getBlockRootClientId ( clientId )
108
+ const adjacentBlocks = getBlocks ( parentClientId )
109
+ const blockIndex = getBlockIndex ( clientId )
110
+ const hasInnerBlocks = adjacentBlocks [ blockIndex ] ?. innerBlocks ?. length > 0
111
+ const nextBlock = blockIndex < adjacentBlocks . length - 1 ? adjacentBlocks [ blockIndex + 1 ] : undefined
112
+ const previousBlock = blockIndex > 0 ? adjacentBlocks [ blockIndex - 1 ] : undefined
113
+
114
+ return {
115
+ hasInnerBlocks,
116
+ nextBlock,
117
+ previousBlock,
118
+ adjacentBlocks,
119
+ blockIndex,
120
+ }
121
+ } , [ clientId ] )
122
+
102
123
const deviceType = useDeviceType ( )
103
124
104
125
const middleRef = useRef ( )
@@ -302,7 +323,7 @@ const Edit = props => {
302
323
dispatch ( 'core/block-editor' ) . __unstableMarkNextChangeAsNotPersistent ( )
303
324
setAttributes ( { timelineIsLast : false } )
304
325
isUpdating = true
305
- } else if ( ( ! nextBlock || nextBlock . name !== 'stackable/timeline' ) && props . attributes . timelineIsLast ) {
326
+ } else if ( ( ! nextBlock || nextBlock . name !== 'stackable/timeline' ) && ! props . attributes . timelineIsLast ) {
306
327
dispatch ( 'core/block-editor' ) . __unstableMarkNextChangeAsNotPersistent ( )
307
328
setAttributes ( { timelineIsLast : true } )
308
329
isUpdating = true
0 commit comments