Skip to content

Commit

Permalink
Synced with trunk and resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
akasunil committed Jul 24, 2024
2 parents 48564e3 + c5f3dd5 commit 7a67203
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useEffect, useRef, useState } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -50,17 +50,6 @@ function ZoomOutModeInserters() {
};
}, [] );

const isMounted = useRef( false );

useEffect( () => {
if ( ! isMounted.current ) {
isMounted.current = true;
return;
}
// reset insertion point when the block order changes
setInserterIsOpened( true );
}, [ blockOrder, setInserterIsOpened ] );

// Defer the initial rendering to avoid the jumps due to the animation.
useEffect( () => {
const timeout = setTimeout( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Flex,
Notice,
ProgressBar,
CheckboxControl,
} from '@wordpress/components';
import { useEntityRecord, store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
Expand All @@ -31,7 +32,12 @@ import { FontLibraryContext } from './context';
import FontCard from './font-card';
import LibraryFontVariant from './library-font-variant';
import { sortFontFaces } from './utils/sort-font-faces';
import { setUIValuesNeeded } from './utils';
import {
setUIValuesNeeded,
loadFontFaceInBrowser,
unloadFontFaceInBrowser,
getDisplaySrcFromFontFace,
} from './utils';
import { unlock } from '../../../lock-unlock';

const { useGlobalSetting } = unlock( blockEditorPrivateApis );
Expand All @@ -49,8 +55,11 @@ function InstalledFonts() {
getFontFacesActivated,
notice,
setNotice,
fontFamilies,
} = useContext( FontLibraryContext );

const [ fontFamilies, setFontFamilies ] = useGlobalSetting(
'typography.fontFamilies'
);
const [ isConfirmDeleteOpen, setIsConfirmDeleteOpen ] = useState( false );
const [ baseFontFamilies ] = useGlobalSetting(
'typography.fontFamilies',
Expand All @@ -61,7 +70,6 @@ function InstalledFonts() {
const { __experimentalGetCurrentGlobalStylesId } = select( coreStore );
return __experimentalGetCurrentGlobalStylesId();
} );

const globalStyles = useEntityRecord(
'root',
'globalStyles',
Expand Down Expand Up @@ -148,6 +156,55 @@ function InstalledFonts() {
refreshLibrary();
}, [] );

// Get activated fonts count.
const activeFontsCount = libraryFontSelected
? getFontFacesActivated(
libraryFontSelected.slug,
libraryFontSelected.source
).length
: 0;

const selectedFontsCount =
libraryFontSelected?.fontFace?.length ??
( libraryFontSelected?.fontFamily ? 1 : 0 );

// Check if any fonts are selected.
const isIndeterminate =
activeFontsCount > 0 && activeFontsCount !== selectedFontsCount;

// Check if all fonts are selected.
const isSelectAllChecked = activeFontsCount === selectedFontsCount;

// Toggle select all fonts.
const toggleSelectAll = () => {
const initialFonts =
fontFamilies?.[ libraryFontSelected.source ]?.filter(
( f ) => f.slug !== libraryFontSelected.slug
) ?? [];
const newFonts = isSelectAllChecked
? initialFonts
: [ ...initialFonts, libraryFontSelected ];

setFontFamilies( {
...fontFamilies,
[ libraryFontSelected.source ]: newFonts,
} );

if ( libraryFontSelected.fontFace ) {
libraryFontSelected.fontFace.forEach( ( face ) => {
if ( isSelectAllChecked ) {
unloadFontFaceInBrowser( face, 'all' );
} else {
loadFontFaceInBrowser(
face,
getDisplaySrcFromFontFace( face?.src ),
'all'
);
}
} );
}
};

const hasFonts = baseThemeFonts.length > 0 || baseCustomFonts.length > 0;
return (
<div className="font-library-modal__tabpanel-layout">
Expand Down Expand Up @@ -311,6 +368,14 @@ function InstalledFonts() {
</Text>
<Spacer margin={ 4 } />
<VStack spacing={ 0 }>
<CheckboxControl
className="font-library-modal__select-all"
label={ __( 'Select all' ) }
checked={ isSelectAllChecked }
onChange={ toggleSelectAll }
indeterminate={ isIndeterminate }
__nextHasNoMarginBottom
/>
<Spacer margin={ 8 } />
{ getFontFacesToDisplay(
libraryFontSelected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ button.font-library-modal__upload-area {
}
}

.font-library-modal__select-all {
padding: $grid-unit-20 $grid-unit-20 $grid-unit-20 $grid-unit-20 + $border-width;

.components-checkbox-control__label {
padding-left: $grid-unit-20;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function ScreenTypography() {
/>
<div className="edit-site-global-styles-screen">
<VStack spacing={ 7 }>
{ ! window.__experimentalDisableFontLibrary &&
fontLibraryEnabled && <FontFamilies /> }
{ fontLibraryEnabled && <FontFamilies /> }
<TypographyElements />
<TypographyVariations title={ __( 'Presets' ) } />
<FontSizesCount />
Expand Down

0 comments on commit 7a67203

Please sign in to comment.