@wordpress/edit-site 5.19.2 → 5.19.3
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/build/components/add-new-pattern/index.js +5 -9
- package/build/components/add-new-pattern/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/collection-font-details.js +3 -1
- package/build/components/global-styles/font-library-modal/collection-font-details.js.map +1 -1
- package/build/components/global-styles/font-library-modal/context.js +26 -30
- package/build/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build/components/global-styles/font-library-modal/font-collection.js +31 -11
- package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build/components/global-styles/font-library-modal/index.js +10 -3
- package/build/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js +27 -7
- package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/local-fonts.js +35 -8
- package/build/components/global-styles/font-library-modal/local-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/upload-fonts.js +26 -0
- package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -0
- package/build/components/global-styles/font-library-modal/utils/fonts-outline.js +4 -1
- package/build/components/global-styles/font-library-modal/utils/fonts-outline.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/get-notice-from-response.js +71 -0
- package/build/components/global-styles/font-library-modal/utils/get-notice-from-response.js.map +1 -0
- package/build/components/global-styles/font-library-modal/utils/index.js +3 -0
- package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
- package/build/components/page-patterns/grid.js +0 -1
- package/build/components/page-patterns/grid.js.map +1 -1
- package/build/components/page-patterns/patterns-list.js +1 -1
- package/build/components/page-patterns/patterns-list.js.map +1 -1
- package/build/components/page-patterns/use-patterns.js +5 -1
- package/build/components/page-patterns/use-patterns.js.map +1 -1
- package/build/components/page-template-parts/index.js +12 -1
- package/build/components/page-template-parts/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/reset-default-template.js +1 -1
- package/build/components/sidebar-edit-mode/page-panels/reset-default-template.js.map +1 -1
- package/build/components/sidebar-edit-mode/template-panel/pattern-categories.js +2 -2
- package/build/components/sidebar-edit-mode/template-panel/pattern-categories.js.map +1 -1
- package/build/components/sidebar-edit-mode/template-panel/template-areas.js +1 -1
- package/build/components/sidebar-edit-mode/template-panel/template-areas.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/index.js +14 -2
- package/build/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template/home-template-details.js +13 -18
- package/build/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +16 -4
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build-module/components/add-new-pattern/index.js +5 -9
- package/build-module/components/add-new-pattern/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/collection-font-details.js +3 -1
- package/build-module/components/global-styles/font-library-modal/collection-font-details.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/context.js +26 -30
- package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/font-collection.js +32 -12
- package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/index.js +10 -3
- package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js +28 -8
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/local-fonts.js +38 -11
- package/build-module/components/global-styles/font-library-modal/local-fonts.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/upload-fonts.js +17 -0
- package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/utils/fonts-outline.js +4 -1
- package/build-module/components/global-styles/font-library-modal/utils/fonts-outline.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/get-notice-from-response.js +63 -0
- package/build-module/components/global-styles/font-library-modal/utils/get-notice-from-response.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/utils/index.js +3 -0
- package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
- package/build-module/components/page-patterns/grid.js +0 -1
- package/build-module/components/page-patterns/grid.js.map +1 -1
- package/build-module/components/page-patterns/patterns-list.js +1 -1
- package/build-module/components/page-patterns/patterns-list.js.map +1 -1
- package/build-module/components/page-patterns/use-patterns.js +5 -1
- package/build-module/components/page-patterns/use-patterns.js.map +1 -1
- package/build-module/components/page-template-parts/index.js +12 -1
- package/build-module/components/page-template-parts/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/reset-default-template.js +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/reset-default-template.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/template-panel/pattern-categories.js +3 -3
- package/build-module/components/sidebar-edit-mode/template-panel/pattern-categories.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/template-panel/template-areas.js +1 -1
- package/build-module/components/sidebar-edit-mode/template-panel/template-areas.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/index.js +14 -2
- package/build-module/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template/home-template-details.js +14 -19
- package/build-module/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +16 -4
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build-style/style-rtl.css +16 -2
- package/build-style/style.css +16 -2
- package/package.json +40 -40
- package/src/components/add-new-pattern/index.js +5 -8
- package/src/components/global-styles/font-library-modal/collection-font-details.js +1 -1
- package/src/components/global-styles/font-library-modal/context.js +36 -38
- package/src/components/global-styles/font-library-modal/font-collection.js +41 -12
- package/src/components/global-styles/font-library-modal/index.js +16 -6
- package/src/components/global-styles/font-library-modal/installed-fonts.js +36 -6
- package/src/components/global-styles/font-library-modal/local-fonts.js +65 -23
- package/src/components/global-styles/font-library-modal/style.scss +18 -1
- package/src/components/global-styles/font-library-modal/upload-fonts.js +20 -0
- package/src/components/global-styles/font-library-modal/utils/fonts-outline.js +4 -3
- package/src/components/global-styles/font-library-modal/utils/get-notice-from-response.js +62 -0
- package/src/components/global-styles/font-library-modal/utils/index.js +4 -0
- package/src/components/page-patterns/grid.js +1 -1
- package/src/components/page-patterns/patterns-list.js +1 -1
- package/src/components/page-patterns/use-patterns.js +7 -3
- package/src/components/page-template-parts/index.js +14 -1
- package/src/components/sidebar-edit-mode/page-panels/reset-default-template.js +1 -1
- package/src/components/sidebar-edit-mode/template-panel/pattern-categories.js +18 -16
- package/src/components/sidebar-edit-mode/template-panel/template-areas.js +1 -1
- package/src/components/sidebar-navigation-screen/style.scss +0 -1
- package/src/components/sidebar-navigation-screen-patterns/index.js +25 -4
- package/src/components/sidebar-navigation-screen-template/home-template-details.js +27 -35
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -4
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
useEntityRecords,
|
|
10
10
|
store as coreStore,
|
|
11
11
|
} from '@wordpress/core-data';
|
|
12
|
-
import { store as noticesStore } from '@wordpress/notices';
|
|
13
|
-
import { __ } from '@wordpress/i18n';
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* Internal dependencies
|
|
@@ -51,8 +49,6 @@ function FontLibraryProvider( { children } ) {
|
|
|
51
49
|
const fontFamiliesHasChanges =
|
|
52
50
|
!! globalStyles?.edits?.settings?.typography?.fontFamilies;
|
|
53
51
|
|
|
54
|
-
const { createErrorNotice } = useDispatch( noticesStore );
|
|
55
|
-
|
|
56
52
|
const [ isInstalling, setIsInstalling ] = useState( false );
|
|
57
53
|
const [ refreshKey, setRefreshKey ] = useState( 0 );
|
|
58
54
|
|
|
@@ -202,7 +198,8 @@ function FontLibraryProvider( { children } ) {
|
|
|
202
198
|
// Prepare formData to install.
|
|
203
199
|
const formData = makeFormDataFromFontFamilies( fonts );
|
|
204
200
|
// Install the fonts (upload the font files to the server and create the post in the database).
|
|
205
|
-
const
|
|
201
|
+
const response = await fetchInstallFonts( formData );
|
|
202
|
+
const fontsInstalled = response?.successes || [];
|
|
206
203
|
// Get intersecting font faces between the fonts we tried to installed and the fonts that were installed
|
|
207
204
|
// (to avoid activating a non installed font).
|
|
208
205
|
const fontToBeActivated = getIntersectingFontFaces(
|
|
@@ -217,41 +214,40 @@ function FontLibraryProvider( { children } ) {
|
|
|
217
214
|
] );
|
|
218
215
|
refreshLibrary();
|
|
219
216
|
setIsInstalling( false );
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
console.error( e );
|
|
224
|
-
createErrorNotice( __( 'Error installing fonts.' ), {
|
|
225
|
-
type: 'snackbar',
|
|
226
|
-
} );
|
|
217
|
+
|
|
218
|
+
return response;
|
|
219
|
+
} catch ( error ) {
|
|
227
220
|
setIsInstalling( false );
|
|
228
|
-
return
|
|
221
|
+
return {
|
|
222
|
+
errors: [ error ],
|
|
223
|
+
};
|
|
229
224
|
}
|
|
230
225
|
}
|
|
231
226
|
|
|
232
227
|
async function uninstallFont( font ) {
|
|
233
228
|
try {
|
|
234
229
|
// Uninstall the font (remove the font files from the server and the post from the database).
|
|
235
|
-
await fetchUninstallFonts( [ font ] );
|
|
230
|
+
const response = await fetchUninstallFonts( [ font ] );
|
|
236
231
|
// Deactivate the font family (remove the font family from the global styles).
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
232
|
+
if ( ! response.errors ) {
|
|
233
|
+
deactivateFontFamily( font );
|
|
234
|
+
// Save the global styles to the database.
|
|
235
|
+
await saveSpecifiedEntityEdits(
|
|
236
|
+
'root',
|
|
237
|
+
'globalStyles',
|
|
238
|
+
globalStylesId,
|
|
239
|
+
[ 'settings.typography.fontFamilies' ]
|
|
240
|
+
);
|
|
241
|
+
}
|
|
245
242
|
// Refresh the library (the the library font families from database).
|
|
246
243
|
refreshLibrary();
|
|
247
|
-
return
|
|
248
|
-
} catch (
|
|
244
|
+
return response;
|
|
245
|
+
} catch ( error ) {
|
|
249
246
|
// eslint-disable-next-line no-console
|
|
250
|
-
console.error(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
return false;
|
|
247
|
+
console.error( error );
|
|
248
|
+
return {
|
|
249
|
+
errors: [ error ],
|
|
250
|
+
};
|
|
255
251
|
}
|
|
256
252
|
}
|
|
257
253
|
|
|
@@ -281,14 +277,16 @@ function FontLibraryProvider( { children } ) {
|
|
|
281
277
|
} );
|
|
282
278
|
// Add custom fonts to the browser.
|
|
283
279
|
fontsToAdd.forEach( ( font ) => {
|
|
284
|
-
font.fontFace
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
280
|
+
if ( font.fontFace ) {
|
|
281
|
+
font.fontFace.forEach( ( face ) => {
|
|
282
|
+
// Load font faces just in the iframe because they already are in the document.
|
|
283
|
+
loadFontFaceInBrowser(
|
|
284
|
+
face,
|
|
285
|
+
getDisplaySrcFromFontFace( face.src ),
|
|
286
|
+
'iframe'
|
|
287
|
+
);
|
|
288
|
+
} );
|
|
289
|
+
}
|
|
292
290
|
} );
|
|
293
291
|
};
|
|
294
292
|
|
|
@@ -311,7 +309,7 @@ function FontLibraryProvider( { children } ) {
|
|
|
311
309
|
// Get the src of the font.
|
|
312
310
|
const src = getDisplaySrcFromFontFace( fontFace.src, themeUrl );
|
|
313
311
|
// If the font is already loaded, don't load it again.
|
|
314
|
-
if ( loadedFontUrls.has( src ) ) return;
|
|
312
|
+
if ( ! src || loadedFontUrls.has( src ) ) return;
|
|
315
313
|
// Load the font in the browser.
|
|
316
314
|
loadFontFaceInBrowser( fontFace, src, 'document' );
|
|
317
315
|
// Add the font to the loaded fonts list.
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
FlexItem,
|
|
13
13
|
Flex,
|
|
14
14
|
Button,
|
|
15
|
+
Notice,
|
|
15
16
|
} from '@wordpress/components';
|
|
16
17
|
import { debounce } from '@wordpress/compose';
|
|
17
18
|
import { __ } from '@wordpress/i18n';
|
|
@@ -29,6 +30,7 @@ import CollectionFontDetails from './collection-font-details';
|
|
|
29
30
|
import { toggleFont } from './utils/toggleFont';
|
|
30
31
|
import { getFontsOutline } from './utils/fonts-outline';
|
|
31
32
|
import GoogleFontsConfirmDialog from './google-fonts-confirm-dialog';
|
|
33
|
+
import { getNoticeFromInstallResponse } from './utils/get-notice-from-response';
|
|
32
34
|
|
|
33
35
|
const DEFAULT_CATEGORY = {
|
|
34
36
|
id: 'all',
|
|
@@ -45,13 +47,15 @@ function FontCollection( { id } ) {
|
|
|
45
47
|
);
|
|
46
48
|
};
|
|
47
49
|
|
|
50
|
+
const [ notice, setNotice ] = useState( null );
|
|
48
51
|
const [ selectedFont, setSelectedFont ] = useState( null );
|
|
49
52
|
const [ fontsToInstall, setFontsToInstall ] = useState( [] );
|
|
50
53
|
const [ filters, setFilters ] = useState( {} );
|
|
51
54
|
const [ renderConfirmDialog, setRenderConfirmDialog ] = useState(
|
|
52
55
|
requiresPermission && ! getGoogleFontsPermissionFromStorage()
|
|
53
56
|
);
|
|
54
|
-
const { collections, getFontCollection } =
|
|
57
|
+
const { collections, getFontCollection, installFonts } =
|
|
58
|
+
useContext( FontLibraryContext );
|
|
55
59
|
const selectedCollection = collections.find(
|
|
56
60
|
( collection ) => collection.id === id
|
|
57
61
|
);
|
|
@@ -76,6 +80,16 @@ function FontCollection( { id } ) {
|
|
|
76
80
|
setSelectedFont( null );
|
|
77
81
|
}, [ id ] );
|
|
78
82
|
|
|
83
|
+
// Reset notice after 5 seconds
|
|
84
|
+
useEffect( () => {
|
|
85
|
+
if ( notice ) {
|
|
86
|
+
const timeout = setTimeout( () => {
|
|
87
|
+
setNotice( null );
|
|
88
|
+
}, 5000 );
|
|
89
|
+
return () => clearTimeout( timeout );
|
|
90
|
+
}
|
|
91
|
+
}, [ notice ] );
|
|
92
|
+
|
|
79
93
|
const collectionFonts = useMemo(
|
|
80
94
|
() => selectedCollection?.data?.fontFamilies ?? [],
|
|
81
95
|
[ selectedCollection ]
|
|
@@ -122,6 +136,13 @@ function FontCollection( { id } ) {
|
|
|
122
136
|
setFontsToInstall( [] );
|
|
123
137
|
};
|
|
124
138
|
|
|
139
|
+
const handleInstall = async () => {
|
|
140
|
+
const response = await installFonts( fontsToInstall );
|
|
141
|
+
const installNotice = getNoticeFromInstallResponse( response );
|
|
142
|
+
setNotice( installNotice );
|
|
143
|
+
resetFontsToInstall();
|
|
144
|
+
};
|
|
145
|
+
|
|
125
146
|
return (
|
|
126
147
|
<TabLayout
|
|
127
148
|
title={
|
|
@@ -135,10 +156,7 @@ function FontCollection( { id } ) {
|
|
|
135
156
|
handleBack={ !! selectedFont && handleUnselectFont }
|
|
136
157
|
footer={
|
|
137
158
|
fontsToInstall.length > 0 && (
|
|
138
|
-
<Footer
|
|
139
|
-
fontsToInstall={ fontsToInstall }
|
|
140
|
-
resetFontsToInstall={ resetFontsToInstall }
|
|
141
|
-
/>
|
|
159
|
+
<Footer handleInstall={ handleInstall } />
|
|
142
160
|
)
|
|
143
161
|
}
|
|
144
162
|
>
|
|
@@ -153,6 +171,22 @@ function FontCollection( { id } ) {
|
|
|
153
171
|
<Spinner />
|
|
154
172
|
) }
|
|
155
173
|
|
|
174
|
+
{ notice && (
|
|
175
|
+
<>
|
|
176
|
+
<FlexItem>
|
|
177
|
+
<Spacer margin={ 2 } />
|
|
178
|
+
<Notice
|
|
179
|
+
isDismissible={ false }
|
|
180
|
+
status={ notice.type }
|
|
181
|
+
className="font-library-modal__font-collection__notice"
|
|
182
|
+
>
|
|
183
|
+
{ notice.message }
|
|
184
|
+
</Notice>
|
|
185
|
+
</FlexItem>
|
|
186
|
+
<Spacer margin={ 2 } />
|
|
187
|
+
</>
|
|
188
|
+
) }
|
|
189
|
+
|
|
156
190
|
{ ! renderConfirmDialog && ! selectedFont && (
|
|
157
191
|
<Flex>
|
|
158
192
|
<FlexItem>
|
|
@@ -232,13 +266,8 @@ function FontCollection( { id } ) {
|
|
|
232
266
|
);
|
|
233
267
|
}
|
|
234
268
|
|
|
235
|
-
function Footer( {
|
|
236
|
-
const {
|
|
237
|
-
|
|
238
|
-
const handleInstall = async () => {
|
|
239
|
-
await installFonts( fontsToInstall );
|
|
240
|
-
resetFontsToInstall();
|
|
241
|
-
};
|
|
269
|
+
function Footer( { handleInstall } ) {
|
|
270
|
+
const { isInstalling } = useContext( FontLibraryContext );
|
|
242
271
|
|
|
243
272
|
return (
|
|
244
273
|
<Flex justify="flex-end">
|
|
@@ -10,13 +10,21 @@ import { useContext } from '@wordpress/element';
|
|
|
10
10
|
*/
|
|
11
11
|
import InstalledFonts from './installed-fonts';
|
|
12
12
|
import FontCollection from './font-collection';
|
|
13
|
+
import UploadFonts from './upload-fonts';
|
|
13
14
|
import { FontLibraryContext } from './context';
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const DEFAULT_TABS = [
|
|
17
|
+
{
|
|
18
|
+
name: 'installed-fonts',
|
|
19
|
+
title: __( 'Library' ),
|
|
20
|
+
className: 'installed-fonts',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'upload-fonts',
|
|
24
|
+
title: __( 'Upload' ),
|
|
25
|
+
className: 'upload-fonts',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
20
28
|
|
|
21
29
|
const tabsFromCollections = ( collections ) =>
|
|
22
30
|
collections.map( ( { id, name } ) => ( {
|
|
@@ -35,7 +43,7 @@ function FontLibraryModal( {
|
|
|
35
43
|
const { collections } = useContext( FontLibraryContext );
|
|
36
44
|
|
|
37
45
|
const tabs = [
|
|
38
|
-
|
|
46
|
+
...DEFAULT_TABS,
|
|
39
47
|
...tabsFromCollections( collections || [] ),
|
|
40
48
|
];
|
|
41
49
|
|
|
@@ -53,6 +61,8 @@ function FontLibraryModal( {
|
|
|
53
61
|
>
|
|
54
62
|
{ ( tab ) => {
|
|
55
63
|
switch ( tab.name ) {
|
|
64
|
+
case 'upload-fonts':
|
|
65
|
+
return <UploadFonts />;
|
|
56
66
|
case 'installed-fonts':
|
|
57
67
|
return <InstalledFonts />;
|
|
58
68
|
default:
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
__experimentalSpacer as Spacer,
|
|
10
10
|
Button,
|
|
11
11
|
Spinner,
|
|
12
|
+
Notice,
|
|
13
|
+
FlexItem,
|
|
12
14
|
} from '@wordpress/components';
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -19,8 +21,8 @@ import { FontLibraryContext } from './context';
|
|
|
19
21
|
import FontsGrid from './fonts-grid';
|
|
20
22
|
import LibraryFontDetails from './library-font-details';
|
|
21
23
|
import LibraryFontCard from './library-font-card';
|
|
22
|
-
import LocalFonts from './local-fonts';
|
|
23
24
|
import ConfirmDeleteDialog from './confirm-delete-dialog';
|
|
25
|
+
import { getNoticeFromUninstallResponse } from './utils/get-notice-from-response';
|
|
24
26
|
import { unlock } from '../../../lock-unlock';
|
|
25
27
|
const { ProgressBar } = unlock( componentsPrivateApis );
|
|
26
28
|
|
|
@@ -44,10 +46,14 @@ function InstalledFonts() {
|
|
|
44
46
|
handleSetLibraryFontSelected( font );
|
|
45
47
|
};
|
|
46
48
|
|
|
49
|
+
const [ notice, setNotice ] = useState( null );
|
|
50
|
+
|
|
47
51
|
const handleConfirmUninstall = async () => {
|
|
48
|
-
const
|
|
52
|
+
const response = await uninstallFont( libraryFontSelected );
|
|
53
|
+
const uninstallNotice = getNoticeFromUninstallResponse( response );
|
|
54
|
+
setNotice( uninstallNotice );
|
|
49
55
|
// If the font was succesfully uninstalled it is unselected
|
|
50
|
-
if (
|
|
56
|
+
if ( ! response?.errors?.length ) {
|
|
51
57
|
handleUnselectFont();
|
|
52
58
|
}
|
|
53
59
|
setIsConfirmDeleteOpen( false );
|
|
@@ -72,8 +78,19 @@ function InstalledFonts() {
|
|
|
72
78
|
|
|
73
79
|
useEffect( () => {
|
|
74
80
|
refreshLibrary();
|
|
81
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
82
|
}, [] );
|
|
76
83
|
|
|
84
|
+
// Reset notice after 5 seconds
|
|
85
|
+
useEffect( () => {
|
|
86
|
+
if ( notice ) {
|
|
87
|
+
const timeout = setTimeout( () => {
|
|
88
|
+
setNotice( null );
|
|
89
|
+
}, 5000 );
|
|
90
|
+
return () => clearTimeout( timeout );
|
|
91
|
+
}
|
|
92
|
+
}, [ notice ] );
|
|
93
|
+
|
|
77
94
|
return (
|
|
78
95
|
<TabLayout
|
|
79
96
|
title={ libraryFontSelected?.name || '' }
|
|
@@ -93,6 +110,22 @@ function InstalledFonts() {
|
|
|
93
110
|
handleCancelUninstall={ handleCancelUninstall }
|
|
94
111
|
/>
|
|
95
112
|
|
|
113
|
+
{ notice && (
|
|
114
|
+
<>
|
|
115
|
+
<FlexItem>
|
|
116
|
+
<Spacer margin={ 2 } />
|
|
117
|
+
<Notice
|
|
118
|
+
isDismissible={ false }
|
|
119
|
+
status={ notice.type }
|
|
120
|
+
className="font-library-modal__font-collection__notice"
|
|
121
|
+
>
|
|
122
|
+
{ notice.message }
|
|
123
|
+
</Notice>
|
|
124
|
+
</FlexItem>
|
|
125
|
+
<Spacer margin={ 4 } />
|
|
126
|
+
</>
|
|
127
|
+
) }
|
|
128
|
+
|
|
96
129
|
{ ! libraryFontSelected && (
|
|
97
130
|
<>
|
|
98
131
|
{ isResolvingLibrary && <Spinner /> }
|
|
@@ -129,9 +162,6 @@ function InstalledFonts() {
|
|
|
129
162
|
</FontsGrid>
|
|
130
163
|
</>
|
|
131
164
|
) }
|
|
132
|
-
|
|
133
|
-
<Spacer margin={ 8 } />
|
|
134
|
-
<LocalFonts />
|
|
135
165
|
</>
|
|
136
166
|
) }
|
|
137
167
|
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
5
|
import {
|
|
6
6
|
Button,
|
|
7
7
|
DropZone,
|
|
8
8
|
__experimentalSpacer as Spacer,
|
|
9
9
|
__experimentalText as Text,
|
|
10
|
+
__experimentalVStack as VStack,
|
|
10
11
|
FormFileUpload,
|
|
12
|
+
Notice,
|
|
13
|
+
FlexItem,
|
|
11
14
|
} from '@wordpress/components';
|
|
12
|
-
import { useContext } from '@wordpress/element';
|
|
15
|
+
import { useContext, useState, useEffect } from '@wordpress/element';
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Internal dependencies
|
|
@@ -19,9 +22,16 @@ import { FontLibraryContext } from './context';
|
|
|
19
22
|
import { Font } from '../../../../lib/lib-font.browser';
|
|
20
23
|
import makeFamiliesFromFaces from './utils/make-families-from-faces';
|
|
21
24
|
import { loadFontFaceInBrowser } from './utils';
|
|
25
|
+
import { getNoticeFromInstallResponse } from './utils/get-notice-from-response';
|
|
22
26
|
|
|
23
27
|
function LocalFonts() {
|
|
24
28
|
const { installFonts } = useContext( FontLibraryContext );
|
|
29
|
+
const [ notice, setNotice ] = useState( null );
|
|
30
|
+
const supportedFormats =
|
|
31
|
+
ALLOWED_FILE_EXTENSIONS.slice( 0, -1 )
|
|
32
|
+
.map( ( extension ) => `.${ extension }` )
|
|
33
|
+
.join( ', ' ) +
|
|
34
|
+
` ${ __( 'and' ) } .${ ALLOWED_FILE_EXTENSIONS.slice( -1 ) }`;
|
|
25
35
|
|
|
26
36
|
const handleDropZone = ( files ) => {
|
|
27
37
|
handleFilesUpload( files );
|
|
@@ -30,6 +40,16 @@ function LocalFonts() {
|
|
|
30
40
|
handleFilesUpload( event.target.files );
|
|
31
41
|
};
|
|
32
42
|
|
|
43
|
+
// Reset notice after 5 seconds
|
|
44
|
+
useEffect( () => {
|
|
45
|
+
if ( notice ) {
|
|
46
|
+
const timeout = setTimeout( () => {
|
|
47
|
+
setNotice( null );
|
|
48
|
+
}, 5000 );
|
|
49
|
+
return () => clearTimeout( timeout );
|
|
50
|
+
}
|
|
51
|
+
}, [ notice ] );
|
|
52
|
+
|
|
33
53
|
/**
|
|
34
54
|
* Filters the selected files to only allow the ones with the allowed extensions
|
|
35
55
|
*
|
|
@@ -37,6 +57,7 @@ function LocalFonts() {
|
|
|
37
57
|
* @return {void}
|
|
38
58
|
*/
|
|
39
59
|
const handleFilesUpload = ( files ) => {
|
|
60
|
+
setNotice( null );
|
|
40
61
|
const uniqueFilenames = new Set();
|
|
41
62
|
const selectedFiles = [ ...files ];
|
|
42
63
|
const allowedFiles = selectedFiles.filter( ( file ) => {
|
|
@@ -126,33 +147,54 @@ function LocalFonts() {
|
|
|
126
147
|
*/
|
|
127
148
|
const handleInstall = async ( fontFaces ) => {
|
|
128
149
|
const fontFamilies = makeFamiliesFromFaces( fontFaces );
|
|
129
|
-
await installFonts( fontFamilies );
|
|
150
|
+
const response = await installFonts( fontFamilies );
|
|
151
|
+
const installNotice = getNoticeFromInstallResponse( response );
|
|
152
|
+
setNotice( installNotice );
|
|
130
153
|
};
|
|
131
154
|
|
|
132
155
|
return (
|
|
133
156
|
<>
|
|
134
|
-
<
|
|
135
|
-
{ __( 'Upload Fonts' ) }
|
|
136
|
-
</Text>
|
|
137
|
-
<Spacer margin={ 2 } />
|
|
157
|
+
<Spacer margin={ 16 } />
|
|
138
158
|
<DropZone onFilesDrop={ handleDropZone } />
|
|
139
|
-
<
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
{ __( '
|
|
152
|
-
</
|
|
153
|
-
|
|
159
|
+
<VStack className="font-library-modal__local-fonts">
|
|
160
|
+
<FormFileUpload
|
|
161
|
+
accept={ ALLOWED_FILE_EXTENSIONS.map(
|
|
162
|
+
( ext ) => `.${ ext }`
|
|
163
|
+
).join( ',' ) }
|
|
164
|
+
multiple={ true }
|
|
165
|
+
onChange={ onFilesUpload }
|
|
166
|
+
render={ ( { openFileDialog } ) => (
|
|
167
|
+
<Button
|
|
168
|
+
className="font-library-modal__upload-area"
|
|
169
|
+
onClick={ openFileDialog }
|
|
170
|
+
>
|
|
171
|
+
<span>{ __( 'Upload font' ) }</span>
|
|
172
|
+
</Button>
|
|
173
|
+
) }
|
|
174
|
+
/>
|
|
175
|
+
{ notice && (
|
|
176
|
+
<FlexItem>
|
|
177
|
+
<Spacer margin={ 2 } />
|
|
178
|
+
<Notice
|
|
179
|
+
isDismissible={ false }
|
|
180
|
+
status={ notice.type }
|
|
181
|
+
className="font-library-modal__upload-area__notice"
|
|
182
|
+
>
|
|
183
|
+
{ notice.message }
|
|
184
|
+
</Notice>
|
|
185
|
+
</FlexItem>
|
|
154
186
|
) }
|
|
155
|
-
|
|
187
|
+
<Spacer margin={ 2 } />
|
|
188
|
+
<Text className="font-library-modal__upload-area__text">
|
|
189
|
+
{ sprintf(
|
|
190
|
+
/* translators: %s: supported font formats: ex: .ttf, .woff and .woff2 */
|
|
191
|
+
__(
|
|
192
|
+
'Uploaded fonts appear in your library and can be used in your theme. Supported formats: %s.'
|
|
193
|
+
),
|
|
194
|
+
supportedFormats
|
|
195
|
+
) }
|
|
196
|
+
</Text>
|
|
197
|
+
</VStack>
|
|
156
198
|
</>
|
|
157
199
|
);
|
|
158
200
|
}
|
|
@@ -92,11 +92,24 @@
|
|
|
92
92
|
align-items: center;
|
|
93
93
|
display: flex;
|
|
94
94
|
justify-content: center;
|
|
95
|
-
height:
|
|
95
|
+
height: 250px;
|
|
96
96
|
width: 100%;
|
|
97
97
|
background-color: #f0f0f0;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
.font-library-modal__local-fonts {
|
|
101
|
+
margin: 0 auto;
|
|
102
|
+
width: 80%;
|
|
103
|
+
|
|
104
|
+
.font-library-modal__upload-area__text {
|
|
105
|
+
color: #6e6e6e;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.font-library-modal__upload-area__notice {
|
|
109
|
+
margin: 0;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
.font-library-modal__font-name {
|
|
101
114
|
font-weight: bold;
|
|
102
115
|
}
|
|
@@ -137,3 +150,7 @@
|
|
|
137
150
|
max-width: 350px;
|
|
138
151
|
}
|
|
139
152
|
}
|
|
153
|
+
|
|
154
|
+
.font-library-modal__font-collection__notice {
|
|
155
|
+
margin: 0;
|
|
156
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __experimentalSpacer as Spacer } from '@wordpress/components';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import LocalFonts from './local-fonts';
|
|
10
|
+
|
|
11
|
+
function UploadFonts() {
|
|
12
|
+
return (
|
|
13
|
+
<>
|
|
14
|
+
<Spacer margin={ 8 } />
|
|
15
|
+
<LocalFonts />
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default UploadFonts;
|
|
@@ -15,7 +15,8 @@ export function getFontsOutline( fonts ) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function isFontFontFaceInOutline( slug, face, outline ) {
|
|
18
|
-
|
|
19
|
-
outline[ slug ]
|
|
20
|
-
|
|
18
|
+
if ( ! face ) {
|
|
19
|
+
return !! outline[ slug ];
|
|
20
|
+
}
|
|
21
|
+
return !! outline[ slug ]?.[ `${ face.fontStyle }-${ face.fontWeight }` ];
|
|
21
22
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
export function getNoticeFromInstallResponse( response ) {
|
|
7
|
+
const { errors = [], successes = [] } = response;
|
|
8
|
+
// Everything failed.
|
|
9
|
+
if ( errors.length && ! successes.length ) {
|
|
10
|
+
return {
|
|
11
|
+
type: 'error',
|
|
12
|
+
message: __( 'Error installing the fonts.' ),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Eveerything succeeded.
|
|
17
|
+
if ( ! errors.length && successes.length ) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'success',
|
|
20
|
+
message: __( 'Fonts were installed successfully.' ),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Some succeeded, some failed.
|
|
25
|
+
if ( errors.length && successes.length ) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'warning',
|
|
28
|
+
message: __(
|
|
29
|
+
'Some fonts were installed successfully and some failed.'
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getNoticeFromUninstallResponse( response ) {
|
|
36
|
+
const { errors = [], successes = [] } = response;
|
|
37
|
+
// Everything failed.
|
|
38
|
+
if ( errors.length && ! successes.length ) {
|
|
39
|
+
return {
|
|
40
|
+
type: 'error',
|
|
41
|
+
message: __( 'Error uninstalling the fonts.' ),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Everything succeeded.
|
|
46
|
+
if ( ! errors.length && successes.length ) {
|
|
47
|
+
return {
|
|
48
|
+
type: 'success',
|
|
49
|
+
message: __( 'Fonts were uninstalled successfully.' ),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Some succeeded, some failed.
|
|
54
|
+
if ( errors.length && successes.length ) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'warning',
|
|
57
|
+
message: __(
|
|
58
|
+
'Some fonts were uninstalled successfully and some failed.'
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -109,6 +109,10 @@ export async function loadFontFaceInBrowser( fontFace, source, addTo = 'all' ) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export function getDisplaySrcFromFontFace( input, urlPrefix ) {
|
|
112
|
+
if ( ! input ) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
let src;
|
|
113
117
|
if ( Array.isArray( input ) ) {
|
|
114
118
|
src = input[ 0 ];
|
|
@@ -9,7 +9,7 @@ export default function Grid( { categoryId, items, ...props } ) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
|
-
<ul
|
|
12
|
+
<ul className="edit-site-patterns__grid" { ...props }>
|
|
13
13
|
{ items.map( ( item ) => (
|
|
14
14
|
<GridItem
|
|
15
15
|
key={ item.name }
|
|
@@ -35,7 +35,7 @@ const { useLocation, useHistory } = unlock( routerPrivateApis );
|
|
|
35
35
|
const SYNC_FILTERS = {
|
|
36
36
|
all: __( 'All' ),
|
|
37
37
|
[ PATTERN_SYNC_TYPES.full ]: __( 'Synced' ),
|
|
38
|
-
[ PATTERN_SYNC_TYPES.unsynced ]: __( '
|
|
38
|
+
[ PATTERN_SYNC_TYPES.unsynced ]: __( 'Not synced' ),
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const SYNC_DESCRIPTIONS = {
|
|
@@ -155,9 +155,13 @@ const selectPatterns = createSelector(
|
|
|
155
155
|
];
|
|
156
156
|
|
|
157
157
|
if ( syncStatus ) {
|
|
158
|
-
patterns
|
|
159
|
-
|
|
160
|
-
)
|
|
158
|
+
// User patterns can have their sync statuses checked directly
|
|
159
|
+
// Non-user patterns are all unsynced for the time being.
|
|
160
|
+
patterns = patterns.filter( ( pattern ) => {
|
|
161
|
+
return pattern.id
|
|
162
|
+
? pattern.syncStatus === syncStatus
|
|
163
|
+
: syncStatus === PATTERN_SYNC_TYPES.unsynced;
|
|
164
|
+
} );
|
|
161
165
|
}
|
|
162
166
|
|
|
163
167
|
if ( categoryId ) {
|