-
Notifications
You must be signed in to change notification settings - Fork 67
fix: resetting on global typography should only affect the current de… #3621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -350,11 +350,30 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const resetStyles = selector => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let newSettings = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentFontPair = getCurrentFontPair() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! isEditingFontPair && currentFontPair ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| newSettings = { ...typographySettings, [ selector ]: currentFontPair.typography[ selector ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceFontSizeKey = getDevicePropertyKey( 'fontSize', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceFontSizeUnitKey = getDevicePropertyKey( 'fontSizeUnit', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceLineHeightKey = getDevicePropertyKey( 'lineHeight', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceLetterSpacingKey = getDevicePropertyKey( 'letterSpacing', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| newSettings = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...typographySettings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ selector ]: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...typographySettings[ selector ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fontFamily: getDefaultFontFamily( selector ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fontWeight: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| textTransform: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Only reset the properties on to the current device type values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceFontSizeKey ]: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceFontSizeUnitKey ]: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceLineHeightKey ]: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceLetterSpacingKey ]: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Remove the keys with empty string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| newSettings[ selector ] = cleanTypographyStyle( newSettings[ selector ] ) || {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doAction( 'stackable.global-settings.typography-update-global-styles', newSettings ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateTypography( newSettings ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -369,20 +388,40 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const getIsAllowReset = selector => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentFontPair = getCurrentFontPair() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const typographyStyle = cleanTypographyStyle( typographySettings[ selector ] ) || {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const typographyStyle = typographySettings[ selector ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceFontSizeKey = getDevicePropertyKey( 'fontSize', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceFontSizeUnitKey = getDevicePropertyKey( 'fontSizeUnit', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceLineHeightKey = getDevicePropertyKey( 'lineHeight', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const deviceLetterSpacingKey = getDevicePropertyKey( 'letterSpacing', deviceType ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create a temporary typography style on the current device type for comparison | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const typographyStyleOnCurrentDevice = cleanTypographyStyle( { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fontFamily: typographyStyle?.fontFamily || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fontWeight: typographyStyle?.fontWeight || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| textTransform: typographyStyle?.textTransform || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceFontSizeKey ]: typographyStyle?.[ deviceFontSizeKey ] || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceFontSizeUnitKey ]: typographyStyle?.[ deviceFontSizeUnitKey ] || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceLineHeightKey ]: typographyStyle?.[ deviceLineHeightKey ] || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ deviceLetterSpacingKey ]: typographyStyle?.[ deviceLetterSpacingKey ] || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } ) || {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! isEditingFontPair && currentFontPair ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Clean style object to be consistent with changeStyles operation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! isEqual( fontPairStyle, typographyStyle ) && ! Array.isArray( typographyStyle ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! isEqual( fontPairStyle, typographyStyleOnCurrentDevice ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ! Array.isArray( typographyStyleOnCurrentDevice ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
409
to
417
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparison still trips reset in tablet/mobile
- const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {}
- if ( ! isEqual( fontPairStyle, typographyStyleOnCurrentDevice ) &&
+ const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {}
+ const fontPairStyleOnCurrentDevice = cleanTypographyStyle( {
+ fontFamily: fontPairStyle?.fontFamily || '',
+ fontWeight: fontPairStyle?.fontWeight || '',
+ textTransform: fontPairStyle?.textTransform || '',
+ [ deviceFontSizeKey ]: fontPairStyle?.[ deviceFontSizeKey ] || '',
+ [ deviceFontSizeUnitKey ]: fontPairStyle?.[ deviceFontSizeUnitKey ] || '',
+ [ deviceLineHeightKey ]: fontPairStyle?.[ deviceLineHeightKey ] || '',
+ [ deviceLetterSpacingKey ]: fontPairStyle?.[ deviceLetterSpacingKey ] || '',
+ } ) || {}
+ if ( ! isEqual( fontPairStyleOnCurrentDevice, typographyStyleOnCurrentDevice ) &&📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if ( typographyStyle && ( typographyStyle.fontFamily || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyle.fontSize || typographyStyle.tabletFontSize || typographyStyle.mobileFontSize || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyle.fontWeight || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyle.textTransform || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyle.lineHeight || typographyStyle.tabletLineHeight || typographyStyle.mobileLineHeight || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyle.letterSpacing || typographyStyle.tabletLetterSpacing || typographyStyle.mobileLetterSpacing ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if ( typographyStyleOnCurrentDevice && ( typographyStyleOnCurrentDevice.fontFamily || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyleOnCurrentDevice[ deviceFontSizeKey ] || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyleOnCurrentDevice[ deviceFontSizeUnitKey ] || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyleOnCurrentDevice[ deviceLineHeightKey ] || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyleOnCurrentDevice[ deviceLetterSpacingKey ] || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyleOnCurrentDevice.fontWeight || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typographyStyleOnCurrentDevice.textTransform ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a reset, shouldn't the fontFamily be blank?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default font family depends on the currently selected font pair, which will be provided by
getDefaultFontFamily.