From e05fbc2101cc0bce3e06decad14fcaa75e0ba37b Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Wed, 24 Jul 2024 09:55:08 +0100 Subject: [PATCH 1/3] Font Library: Remove unused font library experiment (#63890) Co-authored-by: scruffian Co-authored-by: mikachan --- .../src/components/global-styles/screen-typography.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/screen-typography.js b/packages/edit-site/src/components/global-styles/screen-typography.js index 6d1b69f0ddb5e..a58802a204ce3 100644 --- a/packages/edit-site/src/components/global-styles/screen-typography.js +++ b/packages/edit-site/src/components/global-styles/screen-typography.js @@ -32,8 +32,7 @@ function ScreenTypography() { />
- { ! window.__experimentalDisableFontLibrary && - fontLibraryEnabled && } + { fontLibraryEnabled && } From a15e048dccf3b4b9325a5349a8ef3233e35bb537 Mon Sep 17 00:00:00 2001 From: Sunil Prajapati <61308756+akasunil@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:36:53 +0530 Subject: [PATCH 2/3] Font Library: Include a "Select All" options to activate/deactivate all fonts (#63531) * Add function to activate all fonts on select all click * implement toggle to select all fonts * add style for select all option * Add style for select all lable * Removed unneccessory use of flex component * Remove new function added to context * Modified flow of select all toggle function * Removed extra spaces * Remove use of context * Update logic to choose all fonts on click in the indeterminate condition * Fix the issue of select all toggle for fonts without font faces * Remove ad hoc font style for select all label * Updated styles for select all toggle's checkbox to align with other checkboxes Co-authored-by: akasunil Co-authored-by: t-hamano Co-authored-by: jameskoster Co-authored-by: jasmussen Co-authored-by: annezazu Co-authored-by: creativecoder Co-authored-by: beafialho --- .../font-library-modal/installed-fonts.js | 71 ++++++++++++++++++- .../font-library-modal/style.scss | 9 +++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js index 76618a54aeb92..6602a778dc66c 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js @@ -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'; @@ -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 ); @@ -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', @@ -61,7 +70,6 @@ function InstalledFonts() { const { __experimentalGetCurrentGlobalStylesId } = select( coreStore ); return __experimentalGetCurrentGlobalStylesId(); } ); - const globalStyles = useEntityRecord( 'root', 'globalStyles', @@ -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 (
@@ -311,6 +368,14 @@ function InstalledFonts() { + { getFontFacesToDisplay( libraryFontSelected diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/style.scss b/packages/edit-site/src/components/global-styles/font-library-modal/style.scss index 5b9b595a1e647..5cbb53a6296cc 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/style.scss +++ b/packages/edit-site/src/components/global-styles/font-library-modal/style.scss @@ -186,3 +186,12 @@ button.font-library-modal__upload-area { justify-content: center; } } + +.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; + } +} + From c5f3dd50867543cd08889f79627bbbac18a096c4 Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Wed, 24 Jul 2024 04:10:38 -0500 Subject: [PATCH 3/3] Don't automatically show inserter when zoom out mode initiates (#63859) Co-authored-by: jeryj Co-authored-by: scruffian --- .../block-tools/zoom-out-mode-inserters.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js index 5f5b0401b512e..5d273a4f3f6d5 100644 --- a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js +++ b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js @@ -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 @@ -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( () => {