Skip to content

Commit 37bda2d

Browse files
committed
Merge branch 'trunk' of github.com:WordPress/gutenberg into fix/placeholder-instructions-accessibility
2 parents e4a0f6a + 1873738 commit 37bda2d

30 files changed

+56764
-140
lines changed

lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face-resolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ private static function parse_settings( array $settings ) {
5656
foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
5757
foreach ( $font_families as $definition ) {
5858

59-
// Skip if font-family "name" is not defined.
60-
if ( empty( $definition['name'] ) ) {
61-
continue;
62-
}
59+
// // Skip if font-family "name" is not defined.
60+
// if ( empty( $definition['name'] ) ) {
61+
// continue;
62+
// }
6363

6464
// Skip if "fontFace" is not defined, meaning there are no variations.
6565
if ( empty( $definition['fontFace'] ) ) {

lib/experimental/fonts/font-library/class-wp-font-collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function get_data() {
8282
return new WP_Error( 'font_collection_file_error', __( 'Font Collection data JSON file does not exist.', 'gutenberg' ) );
8383
}
8484

85-
$data = file_get_contents( $this->config['data_json_file'] );
85+
$data = wp_json_file_decode( $this->config['data_json_file'], array( 'associative' => true ) );
8686
if ( empty( $data ) ) {
8787
return new WP_Error( 'font_collection_read_error', __( 'Error reading the Font Collection data JSON file contents.', 'gutenberg' ) );
8888
}

lib/experimental/fonts/font-library/default-font-collection.json

Lines changed: 55714 additions & 0 deletions
Large diffs are not rendered by default.

lib/experimental/fonts/font-library/font-library.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,18 @@ function wp_register_font_collection( $config ) {
5757
}
5858
}
5959

60-
// @core-merge: This code needs to be removed.
6160
add_action(
6261
'enqueue_block_editor_assets',
6362
function () {
6463
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalFontLibrary = true', 'before' );
6564
}
6665
);
66+
67+
$default_font_collection = array(
68+
'id' => 'default-font-collection',
69+
'name' => 'Google Fonts',
70+
'description' => __( 'Add from Google Fonts. Fonts are copied to and served from your site.', 'gutenberg' ),
71+
'data_json_file' => path_join( __DIR__, 'default-font-collection.json' ),
72+
);
73+
74+
wp_register_font_collection( $default_font_collection );

packages/edit-site/src/components/global-styles/font-family-item.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useContext } from '@wordpress/element';
1313
* Internal dependencies
1414
*/
1515
import { FontLibraryContext } from './font-library-modal/context';
16-
import { getPreviewStyle } from './font-library-modal/utils';
16+
import { getFamilyPreviewStyle } from './font-library-modal/utils/preview-styles';
1717

1818
function FontFamilyItem( { font } ) {
1919
const { handleSetLibraryFontSelected, toggleModal } =
@@ -26,7 +26,7 @@ function FontFamilyItem( { font } ) {
2626
toggleModal( 'installed-fonts' );
2727
};
2828

29-
const previewStyle = getPreviewStyle( font );
29+
const previewStyle = getFamilyPreviewStyle( font );
3030

3131
return (
3232
<Item onClick={ handleClick }>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import {
5+
__experimentalVStack as VStack,
6+
__experimentalSpacer as Spacer,
7+
} from '@wordpress/components';
8+
9+
/**
10+
* Internal dependencies
11+
*/
12+
import CollectionFontVariant from './collection-font-variant';
13+
import { isFontFontFaceInOutline } from './utils/fonts-outline';
14+
import { sortFontFaces } from './utils/sort-font-faces';
15+
16+
function CollectionFontDetails( {
17+
font,
18+
handleToggleVariant,
19+
fontToInstallOutline,
20+
} ) {
21+
const fontFaces =
22+
font.fontFace && font.fontFace.length
23+
? sortFontFaces( font.fontFace )
24+
: [
25+
{
26+
fontFamily: font.fontFamily,
27+
fontStyle: 'normal',
28+
fontWeight: '400',
29+
},
30+
];
31+
32+
return (
33+
<>
34+
<Spacer margin={ 4 } />
35+
<VStack spacing={ 0 }>
36+
<Spacer margin={ 8 } />
37+
{ fontFaces.map( ( face, i ) => (
38+
<CollectionFontVariant
39+
font={ font }
40+
face={ face }
41+
key={ `face${ i }` }
42+
handleToggleVariant={ handleToggleVariant }
43+
selected={ isFontFontFaceInOutline(
44+
font.slug,
45+
face,
46+
fontToInstallOutline
47+
) }
48+
/>
49+
) ) }
50+
</VStack>
51+
<Spacer margin={ 8 } />
52+
</>
53+
);
54+
}
55+
56+
export default CollectionFontDetails;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { CheckboxControl, Flex } from '@wordpress/components';
5+
/**
6+
* Internal dependencies
7+
*/
8+
import { getFontFaceVariantName } from './utils';
9+
10+
/**
11+
* Internal dependencies
12+
*/
13+
import FontFaceDemo from './font-demo';
14+
15+
function CollectionFontVariant( {
16+
face,
17+
font,
18+
handleToggleVariant,
19+
selected,
20+
} ) {
21+
const handleToggleActivation = () => {
22+
if ( font?.fontFace ) {
23+
handleToggleVariant( font, face );
24+
return;
25+
}
26+
handleToggleVariant( font );
27+
};
28+
29+
const displayName = font.name + ' ' + getFontFaceVariantName( face );
30+
31+
return (
32+
<div className="font-library-modal__library-font-variant">
33+
<Flex justify="space-between" align="center" gap="1rem">
34+
<FontFaceDemo fontFace={ face } text={ displayName } />
35+
<CheckboxControl
36+
checked={ selected }
37+
onChange={ handleToggleActivation }
38+
__nextHasNoMarginBottom={ true }
39+
/>
40+
</Flex>
41+
</div>
42+
);
43+
}
44+
45+
export default CollectionFontVariant;

packages/edit-site/src/components/global-styles/font-library-modal/context.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import { __ } from '@wordpress/i18n';
1515
/**
1616
* Internal dependencies
1717
*/
18-
import { fetchInstallFonts, fetchUninstallFonts } from './resolvers';
18+
import {
19+
fetchInstallFonts,
20+
fetchUninstallFonts,
21+
fetchFontCollections,
22+
fetchFontCollection,
23+
} from './resolvers';
1924
import { unlock } from '../../../lock-unlock';
2025
const { useGlobalSetting } = unlock( blockEditorPrivateApis );
2126
import {
@@ -52,7 +57,7 @@ function FontLibraryProvider( { children } ) {
5257
const [ refreshKey, setRefreshKey ] = useState( 0 );
5358

5459
const refreshLibrary = () => {
55-
setRefreshKey( ( prevKey ) => prevKey + 1 );
60+
setRefreshKey( Date.now() );
5661
};
5762

5863
const {
@@ -313,6 +318,30 @@ function FontLibraryProvider( { children } ) {
313318
loadedFontUrls.add( src );
314319
};
315320

321+
// Font Collections
322+
const [ collections, setFontCollections ] = useState( [] );
323+
const getFontCollections = async () => {
324+
const response = await fetchFontCollections();
325+
setFontCollections( response );
326+
};
327+
const getFontCollection = async ( id ) => {
328+
const hasData = !! collections.find(
329+
( collection ) => collection.id === id
330+
)?.data;
331+
if ( hasData ) return;
332+
const response = await fetchFontCollection( id );
333+
const updatedCollections = collections.map( ( collection ) =>
334+
collection.id === id
335+
? { ...collection, data: { ...response?.data } }
336+
: collection
337+
);
338+
setFontCollections( updatedCollections );
339+
};
340+
341+
useEffect( () => {
342+
getFontCollections();
343+
}, [] );
344+
316345
return (
317346
<FontLibraryContext.Provider
318347
value={ {
@@ -337,6 +366,8 @@ function FontLibraryProvider( { children } ) {
337366
isResolvingLibrary,
338367
hasResolvedLibrary,
339368
isInstalling,
369+
collections,
370+
getFontCollection,
340371
} }
341372
>
342373
{ children }

packages/edit-site/src/components/global-styles/font-library-modal/font-card.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import {
77
Button,
88
Flex,
99
FlexItem,
10+
Icon,
1011
} from '@wordpress/components';
1112

1213
/**
1314
* Internal dependencies
1415
*/
1516
import FontDemo from './font-demo';
16-
import { getPreviewStyle } from './utils';
17+
import { getFamilyPreviewStyle } from './utils/preview-styles';
18+
import { chevronRight } from '@wordpress/icons';
1719

18-
function FontCard( { font, onClick, actionHandler, variantsText } ) {
20+
function FontCard( { font, onClick, variantsText } ) {
1921
const fakeFontFace = {
2022
fontStyle: 'normal',
2123
fontWeight: '400',
@@ -31,7 +33,7 @@ function FontCard( { font, onClick, actionHandler, variantsText } ) {
3133
) || font.fontFace[ 0 ]
3234
: fakeFontFace;
3335

34-
const demoStyle = getPreviewStyle( font );
36+
const demoStyle = getFamilyPreviewStyle( font );
3537

3638
const variantsCount = font.fontFace?.length || 1;
3739

@@ -47,6 +49,7 @@ function FontCard( { font, onClick, actionHandler, variantsText } ) {
4749
>
4850
<Flex justify="space-between" wrap={ false }>
4951
<FontDemo
52+
customPreviewUrl={ font.preview }
5053
fontFace={ displayFontFace }
5154
text={ font.name }
5255
style={ demoStyle }
@@ -60,7 +63,9 @@ function FontCard( { font, onClick, actionHandler, variantsText } ) {
6063
_n( 'variant', 'variants', variantsCount ) }
6164
</Text>
6265
</FlexItem>
63-
<FlexItem>{ !! actionHandler && actionHandler }</FlexItem>
66+
<FlexItem>
67+
<Icon icon={ chevronRight } />
68+
</FlexItem>
6469
</Flex>
6570
</Flex>
6671
</Button>

0 commit comments

Comments
 (0)