@wordpress/global-styles-ui 1.15.0 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/build/font-library/font-card.cjs +10 -1
- package/build/font-library/font-card.cjs.map +2 -2
- package/build/font-library/font-collection.cjs +5 -0
- package/build/font-library/font-collection.cjs.map +2 -2
- package/build/font-library/installed-fonts.cjs +29 -1
- package/build/font-library/installed-fonts.cjs.map +2 -2
- package/build/variations/variation.cjs +5 -2
- package/build/variations/variation.cjs.map +3 -3
- package/build-module/font-library/font-card.mjs +10 -1
- package/build-module/font-library/font-card.mjs.map +2 -2
- package/build-module/font-library/font-collection.mjs +5 -0
- package/build-module/font-library/font-collection.mjs.map +2 -2
- package/build-module/font-library/installed-fonts.mjs +30 -2
- package/build-module/font-library/installed-fonts.mjs.map +2 -2
- package/build-module/variations/variation.mjs +6 -3
- package/build-module/variations/variation.mjs.map +2 -2
- package/build-style/style-rtl.css +4 -5
- package/build-style/style.css +4 -6
- package/build-types/font-library/font-card.d.ts +2 -1
- package/build-types/font-library/font-card.d.ts.map +1 -1
- package/build-types/font-library/font-collection.d.ts.map +1 -1
- package/build-types/font-library/installed-fonts.d.ts.map +1 -1
- package/build-types/variations/variation.d.ts.map +1 -1
- package/package.json +26 -21
- package/src/font-library/font-card.tsx +11 -0
- package/src/font-library/font-collection.tsx +11 -0
- package/src/font-library/installed-fonts.tsx +57 -3
- package/src/style.scss +11 -15
- package/src/variations/variation.tsx +7 -5
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { _n, sprintf, isRTL } from '@wordpress/i18n';
|
|
5
|
+
import { useEffect, useRef } from '@wordpress/element';
|
|
5
6
|
import {
|
|
6
7
|
useNavigator,
|
|
7
8
|
__experimentalText as WCText,
|
|
@@ -22,11 +23,13 @@ function FontCard( {
|
|
|
22
23
|
onClick,
|
|
23
24
|
variantsText,
|
|
24
25
|
navigatorPath,
|
|
26
|
+
shouldFocus,
|
|
25
27
|
}: {
|
|
26
28
|
font: FontFamily;
|
|
27
29
|
onClick: () => void;
|
|
28
30
|
variantsText?: string;
|
|
29
31
|
navigatorPath?: string;
|
|
32
|
+
shouldFocus?: boolean;
|
|
30
33
|
} ) {
|
|
31
34
|
const variantsCount = font.fontFace?.length || 1;
|
|
32
35
|
|
|
@@ -35,9 +38,17 @@ function FontCard( {
|
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
const navigator = useNavigator();
|
|
41
|
+
const ref = useRef< HTMLButtonElement >( null );
|
|
42
|
+
|
|
43
|
+
useEffect( () => {
|
|
44
|
+
if ( shouldFocus ) {
|
|
45
|
+
ref.current?.focus();
|
|
46
|
+
}
|
|
47
|
+
}, [ shouldFocus ] );
|
|
38
48
|
|
|
39
49
|
return (
|
|
40
50
|
<Button
|
|
51
|
+
ref={ ref }
|
|
41
52
|
__next40pxDefaultSize
|
|
42
53
|
onClick={ () => {
|
|
43
54
|
onClick();
|
|
@@ -76,6 +76,9 @@ function FontCollection( { slug }: { slug: string } ) {
|
|
|
76
76
|
const [ selectedFont, setSelectedFont ] = useState< FontFamily | null >(
|
|
77
77
|
null
|
|
78
78
|
);
|
|
79
|
+
const [ lastSelectedFontSlug, setLastSelectedFontSlug ] = useState<
|
|
80
|
+
string | undefined
|
|
81
|
+
>( undefined );
|
|
79
82
|
const [ notice, setNotice ] = useState< {
|
|
80
83
|
type: 'success' | 'error' | 'info';
|
|
81
84
|
message: string;
|
|
@@ -361,6 +364,11 @@ function FontCollection( { slug }: { slug: string } ) {
|
|
|
361
364
|
font.font_family_settings
|
|
362
365
|
}
|
|
363
366
|
navigatorPath="/fontFamily"
|
|
367
|
+
shouldFocus={
|
|
368
|
+
font.font_family_settings
|
|
369
|
+
.slug ===
|
|
370
|
+
lastSelectedFontSlug
|
|
371
|
+
}
|
|
364
372
|
onClick={ () => {
|
|
365
373
|
setSelectedFont(
|
|
366
374
|
font.font_family_settings
|
|
@@ -382,6 +390,9 @@ function FontCollection( { slug }: { slug: string } ) {
|
|
|
382
390
|
}
|
|
383
391
|
size="small"
|
|
384
392
|
onClick={ () => {
|
|
393
|
+
setLastSelectedFontSlug(
|
|
394
|
+
selectedFont?.slug
|
|
395
|
+
);
|
|
385
396
|
setSelectedFont( null );
|
|
386
397
|
setNotice( null );
|
|
387
398
|
} }
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from '@wordpress/components';
|
|
19
19
|
import { useEntityRecord, store as coreStore } from '@wordpress/core-data';
|
|
20
20
|
import { useSelect } from '@wordpress/data';
|
|
21
|
-
import { useContext, useEffect, useState } from '@wordpress/element';
|
|
21
|
+
import { useContext, useEffect, useMemo, useState } from '@wordpress/element';
|
|
22
22
|
import { __, _x, sprintf, isRTL } from '@wordpress/i18n';
|
|
23
23
|
import { chevronLeft, chevronRight } from '@wordpress/icons';
|
|
24
24
|
import type {
|
|
@@ -42,6 +42,34 @@ import {
|
|
|
42
42
|
} from './utils';
|
|
43
43
|
import { useSetting } from '../hooks';
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Comparison key for font families. Sorts families by slug and faces
|
|
47
|
+
* by style+weight so order differences don't produce false positives.
|
|
48
|
+
*
|
|
49
|
+
* @param fontFamilies Font families record keyed by source (e.g. "theme", "custom").
|
|
50
|
+
*/
|
|
51
|
+
function getFontFamiliesKey(
|
|
52
|
+
fontFamilies: Record< string, FontFamilyPreset[] > | undefined
|
|
53
|
+
): string {
|
|
54
|
+
if ( ! fontFamilies ) {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
const normalized: Record< string, unknown[] > = {};
|
|
58
|
+
for ( const source of Object.keys( fontFamilies ).sort() ) {
|
|
59
|
+
normalized[ source ] = ( fontFamilies[ source ] ?? [] )
|
|
60
|
+
.map( ( family ) => ( {
|
|
61
|
+
slug: family.slug,
|
|
62
|
+
fontFace: ( family.fontFace ?? [] )
|
|
63
|
+
.map(
|
|
64
|
+
( face ) => `${ face.fontStyle }-${ face.fontWeight }`
|
|
65
|
+
)
|
|
66
|
+
.sort(),
|
|
67
|
+
} ) )
|
|
68
|
+
.sort( ( a, b ) => a.slug.localeCompare( b.slug ) );
|
|
69
|
+
}
|
|
70
|
+
return JSON.stringify( normalized );
|
|
71
|
+
}
|
|
72
|
+
|
|
45
73
|
function InstalledFonts() {
|
|
46
74
|
const {
|
|
47
75
|
baseCustomFonts,
|
|
@@ -57,6 +85,10 @@ function InstalledFonts() {
|
|
|
57
85
|
const [ fontFamilies, setFontFamilies ] = useSetting<
|
|
58
86
|
Record< string, FontFamilyPreset[] > | undefined
|
|
59
87
|
>( 'typography.fontFamilies' );
|
|
88
|
+
const [ lastSelectedFontSlug, setLastSelectedFontSlug ] = useState<
|
|
89
|
+
string | undefined
|
|
90
|
+
>( undefined );
|
|
91
|
+
|
|
60
92
|
const [ isConfirmDeleteOpen, setIsConfirmDeleteOpen ] =
|
|
61
93
|
useState< boolean >( false );
|
|
62
94
|
const [ notice, setNotice ] = useState< {
|
|
@@ -75,8 +107,19 @@ function InstalledFonts() {
|
|
|
75
107
|
'globalStyles',
|
|
76
108
|
globalStylesId
|
|
77
109
|
);
|
|
78
|
-
const
|
|
79
|
-
|
|
110
|
+
const editedFontFamilies =
|
|
111
|
+
globalStyles?.edits?.settings?.typography?.fontFamilies;
|
|
112
|
+
const savedFontFamilies =
|
|
113
|
+
globalStyles?.record?.settings?.typography?.fontFamilies;
|
|
114
|
+
const fontFamiliesHasChanges = useMemo( () => {
|
|
115
|
+
if ( editedFontFamilies === undefined ) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return (
|
|
119
|
+
getFontFamiliesKey( editedFontFamilies ) !==
|
|
120
|
+
getFontFamiliesKey( savedFontFamilies )
|
|
121
|
+
);
|
|
122
|
+
}, [ editedFontFamilies, savedFontFamilies ] );
|
|
80
123
|
|
|
81
124
|
const themeFonts = fontFamilies?.theme
|
|
82
125
|
? fontFamilies.theme
|
|
@@ -288,6 +331,10 @@ function InstalledFonts() {
|
|
|
288
331
|
variantsText={ getFontCardVariantsText(
|
|
289
332
|
font
|
|
290
333
|
) }
|
|
334
|
+
shouldFocus={
|
|
335
|
+
font.slug ===
|
|
336
|
+
lastSelectedFontSlug
|
|
337
|
+
}
|
|
291
338
|
onClick={ () => {
|
|
292
339
|
setNotice( null );
|
|
293
340
|
handleSetLibraryFontSelected(
|
|
@@ -329,6 +376,10 @@ function InstalledFonts() {
|
|
|
329
376
|
variantsText={ getFontCardVariantsText(
|
|
330
377
|
font
|
|
331
378
|
) }
|
|
379
|
+
shouldFocus={
|
|
380
|
+
font.slug ===
|
|
381
|
+
lastSelectedFontSlug
|
|
382
|
+
}
|
|
332
383
|
onClick={ () => {
|
|
333
384
|
setNotice( null );
|
|
334
385
|
handleSetLibraryFontSelected(
|
|
@@ -366,6 +417,9 @@ function InstalledFonts() {
|
|
|
366
417
|
}
|
|
367
418
|
size="small"
|
|
368
419
|
onClick={ () => {
|
|
420
|
+
setLastSelectedFontSlug(
|
|
421
|
+
libraryFontSelected?.slug
|
|
422
|
+
);
|
|
369
423
|
handleSetLibraryFontSelected(
|
|
370
424
|
undefined
|
|
371
425
|
);
|
package/src/style.scss
CHANGED
|
@@ -188,27 +188,23 @@
|
|
|
188
188
|
flex-direction: column;
|
|
189
189
|
margin: 16px;
|
|
190
190
|
|
|
191
|
-
.
|
|
191
|
+
.block-editor-global-styles-advanced-panel {
|
|
192
192
|
flex: 1 1 auto;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.block-editor-global-styles-advanced-panel__custom-css-input {
|
|
196
|
+
flex: 1 1 auto;
|
|
197
|
+
display: flex;
|
|
198
|
+
flex-direction: column;
|
|
193
199
|
|
|
194
|
-
.
|
|
200
|
+
.components-base-control__field {
|
|
195
201
|
flex: 1 1 auto;
|
|
196
202
|
display: flex;
|
|
197
203
|
flex-direction: column;
|
|
204
|
+
}
|
|
198
205
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
display: flex;
|
|
202
|
-
flex-direction: column;
|
|
203
|
-
|
|
204
|
-
.components-textarea-control__input {
|
|
205
|
-
flex: 1 1 auto;
|
|
206
|
-
// CSS input is always LTR regardless of language.
|
|
207
|
-
|
|
208
|
-
/*rtl:ignore*/
|
|
209
|
-
direction: ltr;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
206
|
+
textarea {
|
|
207
|
+
flex: 1 1 auto;
|
|
212
208
|
}
|
|
213
209
|
}
|
|
214
210
|
}
|
|
@@ -3,10 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { Tooltip as WCTooltip } from '@wordpress/components';
|
|
10
6
|
import { useMemo, useContext, useState } from '@wordpress/element';
|
|
11
7
|
import { ENTER } from '@wordpress/keycodes';
|
|
12
8
|
import { _x, sprintf } from '@wordpress/i18n';
|
|
@@ -14,11 +10,14 @@ import {
|
|
|
14
10
|
areGlobalStylesEqual,
|
|
15
11
|
mergeGlobalStyles,
|
|
16
12
|
} from '@wordpress/global-styles-engine';
|
|
13
|
+
// eslint-disable-next-line @wordpress/use-recommended-components -- `Tooltip` is not yet on the recommended `@wordpress/ui` allow-list; landing as a migration step ahead of the wider rollout.
|
|
14
|
+
import { Tooltip } from '@wordpress/ui';
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
17
|
* Internal dependencies
|
|
20
18
|
*/
|
|
21
19
|
import { GlobalStylesContext } from '../context';
|
|
20
|
+
|
|
22
21
|
import { filterObjectByProperties } from '../utils';
|
|
23
22
|
|
|
24
23
|
interface VariationProps {
|
|
@@ -107,7 +106,10 @@ export default function Variation( {
|
|
|
107
106
|
return (
|
|
108
107
|
<GlobalStylesContext.Provider value={ context }>
|
|
109
108
|
{ showTooltip ? (
|
|
110
|
-
<
|
|
109
|
+
<Tooltip.Root>
|
|
110
|
+
<Tooltip.Trigger render={ content } />
|
|
111
|
+
<Tooltip.Popup>{ variation?.title }</Tooltip.Popup>
|
|
112
|
+
</Tooltip.Root>
|
|
111
113
|
) : (
|
|
112
114
|
content
|
|
113
115
|
) }
|