@@ -14,7 +14,9 @@ import {
1414} from '~stackable/components'
1515import { fetchSettings } from '~stackable/util'
1616import { i18n , isPro } from 'stackable'
17- import { omit , head } from 'lodash'
17+ import {
18+ omit , head , isEqual ,
19+ } from 'lodash'
1820
1921/**
2022 * WordPress dependencies
@@ -183,7 +185,17 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
183185 }
184186
185187 const resetStyles = selector => {
186- const newSettings = omit ( typographySettings , [ selector ] )
188+ let newSettings
189+ const currentFontPair = [ ...FONT_PAIRS , ...customFontPairs ] . find ( fontPair => fontPair . name === selectedFontPairName )
190+ if ( ! editingFontPairName ) {
191+ newSettings = { ...typographySettings , [ selector ] : currentFontPair . typography [ selector ] }
192+ } else {
193+ newSettings = omit ( typographySettings , [ selector ] )
194+ const updatedCustomFontPairs = customFontPairs
195+ . map ( fontPair => fontPair . name === editingFontPairName ? { ...fontPair , typography : newSettings } : fontPair )
196+ updateCustomFontPairs ( updatedCustomFontPairs )
197+ }
198+
187199 doAction ( 'stackable.global-settings.typography-update-global-styles' , newSettings )
188200
189201 updateTypography ( newSettings )
@@ -197,6 +209,26 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
197209 model . save ( )
198210 }
199211
212+ const getIsAllowReset = selector => {
213+ const currentFontPair = [ ...FONT_PAIRS , ...customFontPairs ] . find ( fontPair => fontPair . name === selectedFontPairName )
214+ const fontPairStyle = currentFontPair . typography [ selector ]
215+ const typographyStyle = typographySettings [ selector ]
216+ if ( ! editingFontPairName ) {
217+ if ( ! isEqual ( fontPairStyle , typographyStyle ) ) {
218+ return true
219+ }
220+ return false
221+ } else if ( typographyStyle && ( typographyStyle . fontFamily ||
222+ typographyStyle . fontSize || typographyStyle . tabletFontSize || typographyStyle . mobileFontSize ||
223+ typographyStyle . fontWeight ||
224+ typographyStyle . textTransform ||
225+ typographyStyle . lineHeight || typographyStyle . tabletLineHeight || typographyStyle . mobileLineHeight ||
226+ typographyStyle . letterSpacing || typographyStyle . tabletLetterSpacing || typographyStyle . mobileLetterSpacing ) ) {
227+ return true
228+ }
229+ return false
230+ }
231+
200232 const CustomFontPairPickers = applyFilters (
201233 'stackable.global-settings.typography.font-pairs.customPicker' ,
202234 Fragment ,
@@ -316,6 +348,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
316348 label = { label }
317349 selector = { selector }
318350 value = { ( typographySettings [ selector ] ) || { } }
351+ isAllowReset = { getIsAllowReset ( selector ) }
319352 onChange = { styles => changeStyles ( { [ selector ] : styles } ) }
320353 onReset = { ( ) => resetStyles ( selector ) }
321354 />
0 commit comments