11import { __ } from '@wordpress/i18n'
22import { i18n } from 'stackable'
3- import { dispatch } from '@wordpress/data'
3+ import { dispatch , select } from '@wordpress/data'
44import { createInterpolateElement } from '@wordpress/element'
55
66export const advancedHoverStates = {
@@ -126,10 +126,10 @@ export const advancedHoverStates = {
126126 nextEvent : 'mousedown' ,
127127 nextEventTarget : '.stk-color-palette-control__popover-content *' ,
128128 postStep : ( ) => {
129- const allBlocks = wp . data . select ( 'core/block-editor' ) . getBlocks ( )
129+ const allBlocks = select ( 'core/block-editor' ) . getBlocks ( )
130130 const columnsBlock = allBlocks . find ( block => block . name === 'stackable/columns' )
131131 if ( columnsBlock ?. innerBlocks ?. [ 0 ] && ! columnsBlock . innerBlocks [ 0 ] . attributes ?. containerBackgroundColorHover ) {
132- wp . data . dispatch ( 'core/block-editor' ) . updateBlockAttributes ( columnsBlock . innerBlocks [ 0 ] . clientId , {
132+ dispatch ( 'core/block-editor' ) . updateBlockAttributes ( columnsBlock . innerBlocks [ 0 ] . clientId , {
133133 containerBackgroundColorHover : '#2b2b2b' ,
134134 } )
135135 }
@@ -145,10 +145,10 @@ export const advancedHoverStates = {
145145 } ) ,
146146 offsetX : '300px' ,
147147 postStep : ( ) => {
148- const allBlocks = wp . data . select ( 'core/block-editor' ) . getBlocks ( )
148+ const allBlocks = select ( 'core/block-editor' ) . getBlocks ( )
149149 const columnsBlock = allBlocks . find ( block => block . name === 'stackable/columns' )
150150 if ( columnsBlock ?. innerBlocks ?. [ 0 ] ?. innerBlocks ?. [ 0 ] ) {
151- wp . data . dispatch ( 'core/block-editor' ) . selectBlock ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 0 ] . clientId )
151+ dispatch ( 'core/block-editor' ) . selectBlock ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 0 ] . clientId )
152152 }
153153 } ,
154154 } ,
@@ -215,10 +215,10 @@ export const advancedHoverStates = {
215215 nextEvent : 'mousedown' ,
216216 nextEventTarget : '.stk-color-palette-control__popover-content *' ,
217217 postStep : ( ) => {
218- const allBlocks = wp . data . select ( 'core/block-editor' ) . getBlocks ( )
218+ const allBlocks = select ( 'core/block-editor' ) . getBlocks ( )
219219 const columnsBlock = allBlocks . find ( block => block . name === 'stackable/columns' )
220220 if ( columnsBlock ?. innerBlocks ?. [ 0 ] ?. innerBlocks ?. [ 0 ] && ! columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 0 ] . attributes ?. textColor1ParentHover ) {
221- wp . data . dispatch ( 'core/block-editor' ) . updateBlockAttributes ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 0 ] . clientId , {
221+ dispatch ( 'core/block-editor' ) . updateBlockAttributes ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 0 ] . clientId , {
222222 textColor1ParentHover : '#ffffff' ,
223223 } )
224224 }
@@ -231,10 +231,10 @@ export const advancedHoverStates = {
231231 description : __ ( 'Now the heading block is readable when your mouse hovers over the container. Let\'s do the same for the text color in the text block.' , i18n ) ,
232232 offsetX : '300px' ,
233233 postStep : ( ) => {
234- const allBlocks = wp . data . select ( 'core/block-editor' ) . getBlocks ( )
234+ const allBlocks = select ( 'core/block-editor' ) . getBlocks ( )
235235 const columnsBlock = allBlocks . find ( block => block . name === 'stackable/columns' )
236236 if ( columnsBlock ?. innerBlocks ?. [ 0 ] ?. innerBlocks ?. [ 1 ] ) {
237- wp . data . dispatch ( 'core/block-editor' ) . selectBlock ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 1 ] . clientId )
237+ dispatch ( 'core/block-editor' ) . selectBlock ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 1 ] . clientId )
238238 }
239239 } ,
240240 } ,
@@ -250,14 +250,18 @@ export const advancedHoverStates = {
250250 position : 'left' ,
251251 glowTarget : '.stk-control:has([data-attribute="textColor1"])' ,
252252 nextEventTarget : '.stk-control:has([data-attribute="textColor1"]) .stk-control-content button' ,
253+ modalDelay : 150 ,
253254 preStep : ( ) => {
254255 setTimeout ( ( ) => {
255256 const targetElTop = document . querySelector ( '.stk-control:has([data-attribute="textColor1"])' ) ?. getBoundingClientRect ( ) ?. top
256257 const editorSidebar = document . querySelector ( '.editor-sidebar.ugb--has-panel-tabs' )
257- editorSidebar . scrollTo ( {
258- top : targetElTop - editorSidebar . getBoundingClientRect ( ) . top - 100 ,
259- behavior : 'smooth' ,
260- } )
258+
259+ if ( editorSidebar && typeof targetElTop === 'number' ) {
260+ editorSidebar . scrollTo ( {
261+ top : targetElTop - editorSidebar . getBoundingClientRect ( ) . top - 100 ,
262+ behavior : 'smooth' ,
263+ } )
264+ }
261265 } , 100 )
262266 } ,
263267 postStep : ( ) => {
@@ -273,10 +277,10 @@ export const advancedHoverStates = {
273277 nextEvent : 'mousedown' ,
274278 nextEventTarget : '.stk-color-palette-control__popover-content *' ,
275279 postStep : ( ) => {
276- const allBlocks = wp . data . select ( 'core/block-editor' ) . getBlocks ( )
280+ const allBlocks = select ( 'core/block-editor' ) . getBlocks ( )
277281 const columnsBlock = allBlocks . find ( block => block . name === 'stackable/columns' )
278282 if ( columnsBlock ?. innerBlocks ?. [ 0 ] ?. innerBlocks ?. [ 1 ] && ! columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 1 ] . attributes ?. textColor1ParentHover ) {
279- wp . data . dispatch ( 'core/block-editor' ) . updateBlockAttributes ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 1 ] . clientId , {
283+ dispatch ( 'core/block-editor' ) . updateBlockAttributes ( columnsBlock . innerBlocks [ 0 ] . innerBlocks [ 1 ] . clientId , {
280284 textColor1ParentHover : '#ffffff' ,
281285 } )
282286 }
0 commit comments