@@ -293,40 +293,35 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
293293 }
294294
295295 const changeStyles = _typography => {
296- const typography = cloneDeep ( _typography )
297- const newSettings = { ...typographySettings }
296+ setTypographySettings ( prevTypographySettings => {
297+ const typography = cloneDeep ( _typography )
298+ const newSettings = { ...prevTypographySettings }
298299
299- Object . entries ( typography ) . forEach ( ( [ selector , styles ] ) => {
300- if ( ! selector || typeof styles !== 'object' ) {
301- return
302- }
300+ Object . entries ( typography ) . forEach ( ( [ selector , styles ] ) => {
301+ if ( ! selector || typeof styles !== 'object' ) {
302+ return
303+ }
303304
304- // Merge the new styles with the previous, while overwritting similar styles.
305- // This allow adding styles without removing the previous ones.
306- // Check if the object is empty, used for resetting the whole setting.
307- if ( Object . keys ( styles ) . length !== 0 ) {
308- styles = { ...newSettings [ selector ] , ...styles }
309- }
310- /**
311- * Delete the object keys with empty strings.
312- * Otherwise, the API will throw an error code 400
313- * because of incompatible schema type.
314- */
315- Object . keys ( styles ) . forEach ( key => {
316- if ( styles [ key ] === '' ) {
317- delete styles [ key ]
305+ if ( Object . keys ( styles ) . length !== 0 ) {
306+ styles = { ...newSettings [ selector ] , ...styles }
318307 }
319- } )
320308
321- newSettings [ selector ] = styles
322- } )
309+ Object . keys ( styles ) . forEach ( key => {
310+ if ( styles [ key ] === '' ) {
311+ delete styles [ key ]
312+ }
313+ } )
323314
324- // Update the global styles immediately when reset font size is triggered.
325- if ( Object . values ( typography ) . some ( styles => styles && ! styles . fontSize ) ) {
326- doAction ( 'stackable.global-settings.typography-update-global-styles' , newSettings )
327- }
315+ newSettings [ selector ] = styles
316+ } )
328317
329- updateTypography ( newSettings )
318+ // Update the global styles immediately when reset font size is triggered.
319+ if ( Object . values ( typography ) . some ( styles => styles && ! styles . fontSize ) ) {
320+ doAction ( 'stackable.global-settings.typography-update-global-styles' , newSettings )
321+ }
322+
323+ return newSettings
324+ } )
330325 }
331326
332327 const resetStyles = selector => {
0 commit comments