1+ /**
2+ * Internal dependencies
3+ */
4+ import { getDefault } from './utils'
5+
16/**
27 * WordPress dependencies
38 */
49import { useSelect } from '@wordpress/data'
510import { useEffect , useState } from '@wordpress/element'
6- import { useBlockEditContext } from '@wordpress/block-editor'
711
812/**
913 * External dependencies
1014 */
1115import { compact } from 'lodash'
1216import { useBlockHoverState } from '~stackable/hooks'
13- /*
14- :root { --stk-container-border-radius: 10px 10px 10px 10px; :where(.stk--is-hovered, .stk-block:hover) {--stk-container-border-radius: 50px 50px 50px 50px;}}
15- */
16-
17- const transformToNested = ( _blockLayouts ) => {
18- const devices = [ "desktop" , "tablet" , "mobile" ]
19-
20- const blockLayouts = { }
21-
22- for ( const property in _blockLayouts ) {
23- blockLayouts [ property ] = { }
24-
25- devices . forEach ( device => {
26- blockLayouts [ property ] [ device ] = { }
27-
28- if ( typeof blockLayouts [ property ] [ `${ device } ` ] !== undefined ) {
29- blockLayouts [ property ] [ device ] [ 'normal' ] = blockLayouts [ property ] [ `${ device } ` ]
30- }
31-
32- if ( typeof blockLayouts [ property ] [ `${ device } Hover` ] !== undefined ) {
33- blockLayouts [ property ] [ device ] [ 'hover' ] = blockLayouts [ property ] [ `${ device } Hover` ]
34- }
35-
36- if ( typeof blockLayouts [ property ] [ `${ device } ParentHover` ] !== undefined ) {
37- blockLayouts [ property ] [ device ] [ 'parent-hover' ] = blockLayouts [ property ] [ `${ device } ParentHover` ]
38- }
39- } )
40- }
41-
42- return blockLayouts
43- }
4417
4518const renderGlobalStyles = ( blockLayouts , setStyles , currentHoverState , blockUniqueId , parentHoverBlock , breakDesktop = 1024 , breakTablet = 768 ) => {
4619 if ( Object . keys ( blockLayouts ) . length === 0 ) {
@@ -50,9 +23,9 @@ const renderGlobalStyles = ( blockLayouts, setStyles, currentHoverState, blockUn
5023 let css = ''
5124
5225 const deviceCss = {
53- ' desktop' : [ ] ,
54- ' tablet' : [ ] ,
55- ' mobile' : [ ]
26+ desktop : [ ] ,
27+ tablet : [ ] ,
28+ mobile : [ ] ,
5629 }
5730
5831 const getUnit = ( property , state ) => {
@@ -69,10 +42,16 @@ const renderGlobalStyles = ( blockLayouts, setStyles, currentHoverState, blockUn
6942 }
7043
7144 let style = ''
72- if ( property . includes ( 'shadow' ) ) {
45+ if ( typeof value === 'string' ) {
7346 style = `${ property } : ${ value } ;`
7447 } else if ( typeof value === 'object' ) {
75- style = `${ property } : ${ value . top } ${ unit } ${ value . right } ${ unit } ${ value . left } ${ unit } ${ value . bottom } ${ unit } ;`
48+ const defaultValue = getDefault ( _property , device )
49+ const top = value . top !== undefined ? value . top : defaultValue . top
50+ const right = value . right !== undefined ? value . right : defaultValue . right
51+ const bottom = value . bottom !== undefined ? value . bottom : defaultValue . bottom
52+ const left = value . left !== undefined ? value . left : defaultValue . left
53+
54+ style = `${ property } : ${ top } ${ unit } ${ right } ${ unit } ${ bottom } ${ unit } ${ left } ${ unit } ;`
7655 } else {
7756 style = `${ property } : ${ value } ${ unit } ;`
7857 }
@@ -109,7 +88,7 @@ const renderGlobalStyles = ( blockLayouts, setStyles, currentHoverState, blockUn
10988 }
11089
11190 if ( deviceCss . tablet . length > 0 ) {
112- css += `@media screen and (max-width: ${ breakDesktop - 1 } px){ :root { ${ compact ( deviceCss . tablet ) . join ( '' ) } } }`
91+ css += `@media screen and (max-width: ${ breakDesktop - 1 } px){ :root { ${ compact ( deviceCss . tablet ) . join ( '' ) } }}`
11392 }
11493
11594 if ( deviceCss . mobile . length > 0 ) {
@@ -120,12 +99,14 @@ const renderGlobalStyles = ( blockLayouts, setStyles, currentHoverState, blockUn
12099}
121100
122101export const GlobalBlockLayoutStyles = ( ) => {
123- const { blockLayouts, selectedBlockUniqueId, SelectedParentHoverBlock, SelectedParentHoverBlockChildren, SelectedHoverChildren } = useSelect ( select => ( {
102+ const {
103+ blockLayouts, selectedBlockUniqueId, SelectedParentHoverBlock,
104+ } = useSelect ( select => ( {
124105 blockLayouts : select ( 'stackable/global-block-layouts' ) . getBlockLayouts ( ) || [ ] ,
125106 selectedBlockUniqueId : select ( 'core/block-editor' ) . getSelectedBlock ( ) ?. attributes ?. uniqueId ,
126- SelectedParentHoverBlock : select ( 'stackable/hover-state' ) . getSelectedParentHoverBlock ( ) ,
127- SelectedParentHoverBlockChildren : select ( 'stackable/hover-state' ) . getSelectedParentHoverBlockChildren ( ) ,
128- SelectedHoverChildren : select ( 'stackable/hover-state' ) . getSelectedHoverChildren ( )
107+ SelectedParentHoverBlock : select ( 'stackable/hover-state' ) . getSelectedParentHoverBlock ( ) ,
108+ SelectedParentHoverBlockChildren : select ( 'stackable/hover-state' ) . getSelectedParentHoverBlockChildren ( ) ,
109+ SelectedHoverChildren : select ( 'stackable/hover-state' ) . getSelectedHoverChildren ( ) ,
129110 } ) , [ ] )
130111
131112 const [ currentHoverState ] = useBlockHoverState ( { globalControl : true } )
0 commit comments