Skip to content

Commit c0d45c3

Browse files
committed
fix: move editingMode to pro code
1 parent f4b5fee commit c0d45c3

File tree

1 file changed

+50
-51
lines changed
  • src/plugins/global-settings/typography

1 file changed

+50
-51
lines changed

src/plugins/global-settings/typography/index.js

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import { fetchSettings } from '~stackable/util'
1616
import {
1717
i18n, isPro, showProNotice,
1818
} from 'stackable'
19-
import {
20-
omit, head, isEqual,
21-
} from 'lodash'
19+
import { head, isEqual } from 'lodash'
2220

2321
/**
2422
* WordPress dependencies
@@ -83,7 +81,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
8381
const [ applySettingsTo, setApplySettingsTo ] = useState( '' )
8482
const [ customFontPairs, setCustomFontPairs ] = useState( [] )
8583
const [ selectedFontPairName, setSelectedFontPairName ] = useState( '' )
86-
const [ editingFontPairName, setEditingFontPairName ] = useState( '' )
84+
const [ isEditingFontPair, setIsEditingFontPair ] = useState( false )
8785

8886
const fontPairContainerRef = useRef( null )
8987

@@ -178,24 +176,13 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
178176
}
179177

180178
updateTypography( newSettings )
181-
182-
if ( editingFontPairName ) {
183-
const updatedCustomFontPairs = customFontPairs
184-
.map( fontPair => fontPair.name === editingFontPairName ? { ...fontPair, typography: newSettings } : fontPair )
185-
updateCustomFontPairs( updatedCustomFontPairs )
186-
}
187179
}
188180

189181
const resetStyles = selector => {
190182
let newSettings
191183
const currentFontPair = [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
192-
if ( ! editingFontPairName && currentFontPair ) {
184+
if ( ! isEditingFontPair && currentFontPair ) {
193185
newSettings = { ...typographySettings, [ selector ]: currentFontPair.typography[ selector ] }
194-
} else {
195-
newSettings = omit( typographySettings, [ selector ] )
196-
const updatedCustomFontPairs = customFontPairs
197-
.map( fontPair => fontPair.name === editingFontPairName ? { ...fontPair, typography: newSettings } : fontPair )
198-
updateCustomFontPairs( updatedCustomFontPairs )
199186
}
200187

201188
doAction( 'stackable.global-settings.typography-update-global-styles', newSettings )
@@ -214,7 +201,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
214201
const getIsAllowReset = selector => {
215202
const currentFontPair = [ ...FONT_PAIRS, ...customFontPairs ].find( fontPair => fontPair.name === selectedFontPairName )
216203
const typographyStyle = typographySettings[ selector ]
217-
if ( ! editingFontPairName && currentFontPair ) {
204+
if ( ! isEditingFontPair && currentFontPair ) {
218205
const fontPairStyle = currentFontPair.typography[ selector ]
219206
if ( ! isEqual( fontPairStyle, typographyStyle ) ) {
220207
return true
@@ -255,6 +242,11 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
255242
Fragment,
256243
)
257244

245+
const EditingFontPairPanel = applyFilters(
246+
'stackable.global-settings.typography.font-pairs.editingFontPairPanel',
247+
Fragment,
248+
)
249+
258250
return (
259251
<Fragment>
260252
{ output }
@@ -265,8 +257,9 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
265257
setIsPanelOpen( prev => ! prev )
266258
} }
267259
>
268-
{ ! editingFontPairName &&
269-
<div>
260+
<style> { getThemeStyles() } </style>
261+
{ ! isEditingFontPair &&
262+
<>
270263
<p className="components-base-control__help">
271264
{ __( 'Change the typography of your headings for all your blocks in your site.', i18n ) }
272265
&nbsp;
@@ -294,7 +287,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
294287
[ ...FONT_PAIRS, ...customFontPairs ],
295288
selectedFontPairName,
296289
newFontPair => {
297-
setEditingFontPairName( newFontPair.name )
290+
setIsEditingFontPair( true )
298291
updateSelectedFontPair( newFontPair.name )
299292
updateCustomFontPairs( [ newFontPair, ...customFontPairs ] )
300293
}
@@ -327,7 +320,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
327320
changeStyles( typography )
328321
} }
329322
onEdit={ ( name, typography ) => {
330-
setEditingFontPairName( name )
323+
setIsEditingFontPair( true )
331324
updateSelectedFontPair( name )
332325
changeStyles( typography )
333326
} }
@@ -350,40 +343,46 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
350343
</div>
351344
{ showProNotice && <ProControl type="font-pairs" /> }
352345
<ControlSeparator />
353-
</div>
346+
347+
<h3>{ __( 'Typography Settings' ) }</h3>
348+
{ TYPOGRAPHY_TAGS.map( ( {
349+
label, selector, help,
350+
}, index ) => {
351+
return (
352+
<TypographyPicker
353+
help={ help }
354+
key={ index }
355+
label={ label }
356+
selector={ selector }
357+
value={ ( typographySettings[ selector ] ) || {} }
358+
isAllowReset={ getIsAllowReset( selector ) }
359+
onChange={ styles => changeStyles( { [ selector ]: styles } ) }
360+
onReset={ () => resetStyles( selector ) }
361+
/>
362+
)
363+
} ) }
364+
</>
354365
}
355-
{ isPro && editingFontPairName &&
356-
applyFilters(
357-
'stackable.global-settings.typography.font-pairs.inspector-sub-header',
358-
customFontPairs,
359-
editingFontPairName,
360-
() => setEditingFontPairName( '' ),
361-
updatedCustomFontPairs => {
362-
setEditingFontPairName( '' )
366+
367+
{ isPro && isEditingFontPair &&
368+
<EditingFontPairPanel
369+
TypographyPicker={ TypographyPicker }
370+
TYPOGRAPHY_TAGS={ TYPOGRAPHY_TAGS }
371+
typographySettings={ typographySettings }
372+
customFontPairs={ customFontPairs }
373+
selectedFontPairName={ selectedFontPairName }
374+
changeStyles={ changeStyles }
375+
updateTypography={ updateTypography }
376+
updateCustomFontPairs={ updateCustomFontPairs }
377+
setIsEditingFontPair={ setIsEditingFontPair }
378+
onDelete={ updatedCustomFontPairs => {
379+
setIsEditingFontPair( false )
363380
updateSelectedFontPair( '' )
364381
updateCustomFontPairs( updatedCustomFontPairs )
365-
}
366-
)
382+
} }
383+
getIsAllowReset={ getIsAllowReset }
384+
/>
367385
}
368-
369-
<h3>{ __( 'Typography Settings' ) }</h3>
370-
<style> { getThemeStyles() } </style>
371-
{ TYPOGRAPHY_TAGS.map( ( {
372-
label, selector, help,
373-
}, index ) => {
374-
return (
375-
<TypographyPicker
376-
help={ help }
377-
key={ index }
378-
label={ label }
379-
selector={ selector }
380-
value={ ( typographySettings[ selector ] ) || {} }
381-
isAllowReset={ getIsAllowReset( selector ) }
382-
onChange={ styles => changeStyles( { [ selector ]: styles } ) }
383-
onReset={ () => resetStyles( selector ) }
384-
/>
385-
)
386-
} ) }
387386
</PanelAdvancedSettings>
388387
</Fragment>
389388
)

0 commit comments

Comments
 (0)