@@ -29,6 +29,7 @@ import { useSelect } from '@wordpress/data'
2929export const GlobalTypographyStyles = ( ) => {
3030 const [ typographySettings , setTypographySettings ] = useState ( [ ] )
3131 const [ applySettingsTo , setApplySettingsTo ] = useState ( '' )
32+ const [ isApplyBodyToHTML , setIsApplyBodyToHTML ] = useState ( false )
3233
3334 // These are for debouncing the style generation to make things faster.
3435 const [ styles , setStyles ] = useState ( '' )
@@ -54,12 +55,16 @@ export const GlobalTypographyStyles = () => {
5455 fetchSettings ( ) . then ( response => {
5556 setTypographySettings ( ( head ( response . stackable_global_typography ) ) || { } )
5657 setApplySettingsTo ( response . stackable_global_typography_apply_to || 'blocks-stackable-native' )
58+ setIsApplyBodyToHTML ( response . stackable_is_apply_body_to_html || false )
5759 } )
5860
5961 // Allow actions to trigger styles to update.
60- addAction ( 'stackable.global-settings.typography.update-trigger' , 'stackable/typography-styles' , ( newTypographySettings , newAapplySettingsTo ) => {
62+ addAction ( 'stackable.global-settings.typography.update-trigger' , 'stackable/typography-styles' , (
63+ newTypographySettings , newAapplySettingsTo , newIsApplyBodyToHTML
64+ ) => {
6165 setTypographySettings ( newTypographySettings )
6266 setApplySettingsTo ( newAapplySettingsTo )
67+ setIsApplyBodyToHTML ( newIsApplyBodyToHTML )
6368 } )
6469 return ( ) => {
6570 removeAction ( 'stackable.global-settings.typography.update-trigger' , 'stackable/typography-styles' )
@@ -71,7 +76,7 @@ export const GlobalTypographyStyles = () => {
7176 addAction ( 'stackable.global-settings.typography-update-global-styles' , 'stackable/typography-styles' , typographySettings => {
7277 // Generate all the typography styles.
7378 const styleObject = Object . keys ( typographySettings ) . map ( tag => {
74- const selectors = formSelectors ( tag , applySettingsTo )
79+ const selectors = formSelectors ( tag , applySettingsTo , isApplyBodyToHTML )
7580
7681 // Build our selector, target h2.block or .block h2.
7782 // Some blocks may output the heading tag right away.
@@ -118,16 +123,16 @@ export const GlobalTypographyStyles = () => {
118123 setStyleTimeout ( setTimeout ( ( ) => doAction ( 'stackable.global-settings.typography-update-global-styles' , typographySettings ) , 200 ) )
119124
120125 return ( ) => removeAction ( 'stackable.global-settings.typography-update-global-styles' , 'stackable/typography-styles' )
121- } , [ JSON . stringify ( typographySettings ) , applySettingsTo , device , editorMode ] )
126+ } , [ JSON . stringify ( typographySettings ) , applySettingsTo , isApplyBodyToHTML , device , editorMode ] )
122127
123128 return styles
124129}
125130
126- export const formSelectors = ( selector , applyTo ) => {
131+ export const formSelectors = ( selector , applyTo , isApplyBodyToHTML ) => {
127132 if ( [ 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' ] . includes ( selector ) || selector . startsWith ( '.' ) ) {
128133 return formClassOrTagSelectors ( selector , applyTo )
129134 }
130- return formParagraphSelectors ( applyTo )
135+ return formParagraphSelectors ( applyTo , isApplyBodyToHTML )
131136}
132137
133138export const formClassOrTagSelectors = ( selector , applyTo ) => {
@@ -152,8 +157,8 @@ export const formClassOrTagSelectors = ( selector, applyTo ) => {
152157 return applyFilters ( 'stackable.global-settings.typography-selectors' , selectors , selector )
153158}
154159
155- export const formParagraphSelectors = applyTo => {
156- return applyFilters ( 'stackable.global-settings.typography- selectors' , [
160+ export const formParagraphSelectors = ( applyTo , isApplyBodyToHTML ) => {
161+ const selectors = [
157162 ...formClassOrTagSelectors ( 'p' , applyTo ) ,
158163 ...formClassOrTagSelectors ( 'li' , applyTo ) ,
159164 `.editor-styles-wrapper p.block-editor-block-list__block[data-type^="core/"]` ,
@@ -162,7 +167,13 @@ export const formParagraphSelectors = applyTo => {
162167 `.editor-styles-wrapper .block-editor-block-list__block[data-type^="core/"] td` ,
163168 // Apply the font styles to the content placeholder text when the post is blank.
164169 '.block-editor-default-block-appender.has-visible-prompt' ,
165- ] , '' )
170+ ]
171+
172+ // Add 'html' only if is_apply_body_to_html is true
173+ if ( isApplyBodyToHTML ) {
174+ selectors . push ( 'html' )
175+ }
176+ return applyFilters ( 'stackable.global-settings.typography-selectors' , selectors , '' )
166177}
167178
168179// Make sure that this isn't applied to the native query loop block, otherwise
0 commit comments