@@ -13,7 +13,7 @@ import { getAppliedTypeScale } from './utils'
1313import {
1414 PanelAdvancedSettings , AdvancedSelectControl , ControlSeparator , FontPairPicker , ProControlButton , AdvancedToggleControl ,
1515} from '~stackable/components'
16- import { fetchSettings , getDefaultFontSize } from '~stackable/util'
16+ import { fetchSettings } from '~stackable/util'
1717import {
1818 i18n , isPro , showProNotice ,
1919} from 'stackable'
@@ -32,7 +32,7 @@ import {
3232 addFilter , applyFilters , doAction ,
3333} from '@wordpress/hooks'
3434import { __ , sprintf } from '@wordpress/i18n'
35- import { dispatch , useSelect } from '@wordpress/data'
35+ import { useSelect } from '@wordpress/data'
3636
3737export { GlobalTypographyStyles }
3838
@@ -142,13 +142,11 @@ const TYPE_SCALE = [
142142let saveTypographyThrottle = null
143143let saveSelectedFontPairThrottle = null
144144let saveCustomFontPairsThrottle = null
145- let saveTypographyAsPresetsThrottle = null
146145
147146addFilter ( 'stackable.global-settings.inspector' , 'stackable/global-typography' , output => {
148- const { allCustomPresets, useTypographyAsPresets } = useSelect ( select => {
149- const _customPresetControls = select ( 'stackable/global-preset-controls.custom' ) ?. getCustomPresetControls ( ) ?? { }
147+ const { useTypographyAsPresets } = useSelect ( select => {
150148 const _useTypographyAsPresets = select ( 'stackable/global-preset-controls.custom' ) ?. getUseTypographyAsPresets ( ) ?? false
151- return { allCustomPresets : { ... _customPresetControls } , useTypographyAsPresets : _useTypographyAsPresets }
149+ return { useTypographyAsPresets : _useTypographyAsPresets }
152150 } , [ ] )
153151
154152 const FONT_PAIRS = applyFilters ( 'stackable.global-settings.typography.font-pairs.premium-font-pairs' , FREE_FONT_PAIRS )
@@ -192,57 +190,11 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
192190
193191 useEffect ( ( ) => {
194192 // When typography styles are changed, trigger our editor style generator to update.
195- doAction ( 'stackable.global-settings.typography.update-trigger' , typographySettings , applySettingsTo , isApplyBodyToHTML )
196- } , [ JSON . stringify ( typographySettings ) , applySettingsTo , isApplyBodyToHTML ] )
197-
198- useEffect ( ( ) => {
199- // When typography styles are changed, trigger our editor style generator to update.
200- doAction ( 'stackable.global-settings.typography.update-trigger' , typographySettings , applySettingsTo , isApplyBodyToHTML )
201-
202- // Update the custom presets when using typography as presets
203- if ( useTypographyAsPresets ) {
204- const fontSizePresets = TYPOGRAPHY_TAGS
205- . filter ( ( { presetSlug } ) => ! ! presetSlug )
206- . map ( ( {
207- selector, presetName, presetSlug,
208- } ) => {
209- const size = typographySettings [ selector ] ?. fontSize ?? getDefaultFontSize ( selector ) ?? 16
210- const unit = typographySettings [ selector ] ?. fontSizeUnit ?? 'px'
211- return {
212- name : presetName ,
213- slug : presetSlug ,
214- size : `${ size } ${ unit } ` ,
215- }
216- } )
217- // Add the preset for extra small
218- let xSmallSize = typographySettings [ '.stk-subtitle' ] ?. fontSize ?? getDefaultFontSize ( '.stk-subtitle' ) ?? 16
219- let xSmallUnit = typographySettings [ '.stk-subtitle' ] ?. fontSizeUnit ?? 'px'
220- if ( xSmallUnit === 'px' ) {
221- xSmallSize = Math . pow ( xSmallSize / 16 , 2 )
222- xSmallUnit = 'rem'
223- } else {
224- xSmallSize = Math . pow ( xSmallSize , 2 )
225- }
226-
227- fontSizePresets . push ( {
228- name : 'XS' ,
229- slug : 'x-small' ,
230- size : `${ xSmallSize } ${ xSmallUnit ?? 'px' } ` ,
231- } )
232- // Reverse the presets so it's from smallest to biggest
233- fontSizePresets . reverse ( )
234-
235- const newSettings = { ...allCustomPresets , fontSizes : fontSizePresets }
236-
237- clearTimeout ( saveTypographyAsPresetsThrottle )
238- saveTypographyAsPresetsThrottle = setTimeout ( ( ) => {
239- const settings = new models . Settings ( { stackable_global_custom_preset_controls : newSettings } ) // eslint-disable-line camelcase
240- settings . save ( )
241- } , 300 )
242-
243- dispatch ( 'stackable/global-preset-controls.custom' ) . updateCustomPresetControls ( newSettings )
244- }
245- } , [ JSON . stringify ( typographySettings ) , useTypographyAsPresets ] )
193+ // This also triggers updating presets with typography, and applying body font size to html.
194+ doAction ( 'stackable.global-settings.typography.update-trigger' ,
195+ typographySettings , applySettingsTo , useTypographyAsPresets , isApplyBodyToHTML , TYPOGRAPHY_TAGS ,
196+ )
197+ } , [ JSON . stringify ( typographySettings ) , applySettingsTo , useTypographyAsPresets , isApplyBodyToHTML ] )
246198
247199 // Scroll to the selected font pair when Global Typography tab is toggled
248200 useEffect ( ( ) => {
0 commit comments