@@ -350,11 +350,30 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
350350
351351 const resetStyles = selector => {
352352 let newSettings = { }
353- const currentFontPair = getCurrentFontPair ( )
354- if ( ! isEditingFontPair && currentFontPair ) {
355- newSettings = { ...typographySettings , [ selector ] : currentFontPair . typography [ selector ] }
353+
354+ const deviceFontSizeKey = getDevicePropertyKey ( 'fontSize' , deviceType )
355+ const deviceFontSizeUnitKey = getDevicePropertyKey ( 'fontSizeUnit' , deviceType )
356+ const deviceLineHeightKey = getDevicePropertyKey ( 'lineHeight' , deviceType )
357+ const deviceLetterSpacingKey = getDevicePropertyKey ( 'letterSpacing' , deviceType )
358+
359+ newSettings = {
360+ ...typographySettings ,
361+ [ selector ] : {
362+ ...typographySettings [ selector ] ,
363+ fontFamily : getDefaultFontFamily ( selector ) ,
364+ fontWeight : '' ,
365+ textTransform : '' ,
366+ // Only reset the properties on to the current device type values
367+ [ deviceFontSizeKey ] : '' ,
368+ [ deviceFontSizeUnitKey ] : '' ,
369+ [ deviceLineHeightKey ] : '' ,
370+ [ deviceLetterSpacingKey ] : '' ,
371+ } ,
356372 }
357373
374+ // Remove the keys with empty string
375+ newSettings [ selector ] = cleanTypographyStyle ( newSettings [ selector ] ) || { }
376+
358377 doAction ( 'stackable.global-settings.typography-update-global-styles' , newSettings )
359378
360379 updateTypography ( newSettings )
@@ -369,20 +388,40 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
369388
370389 const getIsAllowReset = selector => {
371390 const currentFontPair = getCurrentFontPair ( )
372- const typographyStyle = cleanTypographyStyle ( typographySettings [ selector ] ) || { }
391+ const typographyStyle = typographySettings [ selector ]
392+
393+ const deviceFontSizeKey = getDevicePropertyKey ( 'fontSize' , deviceType )
394+ const deviceFontSizeUnitKey = getDevicePropertyKey ( 'fontSizeUnit' , deviceType )
395+ const deviceLineHeightKey = getDevicePropertyKey ( 'lineHeight' , deviceType )
396+ const deviceLetterSpacingKey = getDevicePropertyKey ( 'letterSpacing' , deviceType )
397+
398+ // Create a temporary typography style on the current device type for comparison
399+ const typographyStyleOnCurrentDevice = cleanTypographyStyle ( {
400+ fontFamily : typographyStyle ?. fontFamily || '' ,
401+ fontWeight : typographyStyle ?. fontWeight || '' ,
402+ textTransform : typographyStyle ?. textTransform || '' ,
403+ [ deviceFontSizeKey ] : typographyStyle ?. [ deviceFontSizeKey ] || '' ,
404+ [ deviceFontSizeUnitKey ] : typographyStyle ?. [ deviceFontSizeUnitKey ] || '' ,
405+ [ deviceLineHeightKey ] : typographyStyle ?. [ deviceLineHeightKey ] || '' ,
406+ [ deviceLetterSpacingKey ] : typographyStyle ?. [ deviceLetterSpacingKey ] || '' ,
407+ } ) || { }
408+
373409 if ( ! isEditingFontPair && currentFontPair ) {
374410 // Clean style object to be consistent with changeStyles operation
375411 const fontPairStyle = cleanTypographyStyle ( currentFontPair . typography ?. [ selector ] ) || { }
376- if ( ! isEqual ( fontPairStyle , typographyStyle ) && ! Array . isArray ( typographyStyle ) ) {
412+ if ( ! isEqual ( fontPairStyle , typographyStyleOnCurrentDevice ) &&
413+ ! Array . isArray ( typographyStyleOnCurrentDevice )
414+ ) {
377415 return true
378416 }
379417 return false
380- } else if ( typographyStyle && ( typographyStyle . fontFamily ||
381- typographyStyle . fontSize || typographyStyle . tabletFontSize || typographyStyle . mobileFontSize ||
382- typographyStyle . fontWeight ||
383- typographyStyle . textTransform ||
384- typographyStyle . lineHeight || typographyStyle . tabletLineHeight || typographyStyle . mobileLineHeight ||
385- typographyStyle . letterSpacing || typographyStyle . tabletLetterSpacing || typographyStyle . mobileLetterSpacing ) ) {
418+ } else if ( typographyStyleOnCurrentDevice && ( typographyStyleOnCurrentDevice . fontFamily ||
419+ typographyStyleOnCurrentDevice [ deviceFontSizeKey ] ||
420+ typographyStyleOnCurrentDevice [ deviceFontSizeUnitKey ] ||
421+ typographyStyleOnCurrentDevice [ deviceLineHeightKey ] ||
422+ typographyStyleOnCurrentDevice [ deviceLetterSpacingKey ] ||
423+ typographyStyleOnCurrentDevice . fontWeight ||
424+ typographyStyleOnCurrentDevice . textTransform ) ) {
386425 return true
387426 }
388427 return false
0 commit comments