@wordpress/edit-site 5.19.1 → 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.
Files changed (120) hide show
  1. package/build/components/add-new-pattern/index.js +5 -9
  2. package/build/components/add-new-pattern/index.js.map +1 -1
  3. package/build/components/global-styles/font-families.js +2 -1
  4. package/build/components/global-styles/font-families.js.map +1 -1
  5. package/build/components/global-styles/font-library-modal/collection-font-details.js +3 -1
  6. package/build/components/global-styles/font-library-modal/collection-font-details.js.map +1 -1
  7. package/build/components/global-styles/font-library-modal/context.js +26 -30
  8. package/build/components/global-styles/font-library-modal/context.js.map +1 -1
  9. package/build/components/global-styles/font-library-modal/font-collection.js +31 -11
  10. package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  11. package/build/components/global-styles/font-library-modal/index.js +10 -3
  12. package/build/components/global-styles/font-library-modal/index.js.map +1 -1
  13. package/build/components/global-styles/font-library-modal/installed-fonts.js +27 -7
  14. package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  15. package/build/components/global-styles/font-library-modal/local-fonts.js +35 -8
  16. package/build/components/global-styles/font-library-modal/local-fonts.js.map +1 -1
  17. package/build/components/global-styles/font-library-modal/upload-fonts.js +26 -0
  18. package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -0
  19. package/build/components/global-styles/font-library-modal/utils/fonts-outline.js +4 -1
  20. package/build/components/global-styles/font-library-modal/utils/fonts-outline.js.map +1 -1
  21. package/build/components/global-styles/font-library-modal/utils/get-notice-from-response.js +71 -0
  22. package/build/components/global-styles/font-library-modal/utils/get-notice-from-response.js.map +1 -0
  23. package/build/components/global-styles/font-library-modal/utils/index.js +3 -0
  24. package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  25. package/build/components/global-styles/screen-typography.js +1 -1
  26. package/build/components/global-styles/screen-typography.js.map +1 -1
  27. package/build/components/page-patterns/grid.js +0 -1
  28. package/build/components/page-patterns/grid.js.map +1 -1
  29. package/build/components/page-patterns/patterns-list.js +1 -1
  30. package/build/components/page-patterns/patterns-list.js.map +1 -1
  31. package/build/components/page-patterns/use-patterns.js +5 -1
  32. package/build/components/page-patterns/use-patterns.js.map +1 -1
  33. package/build/components/page-template-parts/index.js +12 -1
  34. package/build/components/page-template-parts/index.js.map +1 -1
  35. package/build/components/sidebar-edit-mode/page-panels/reset-default-template.js +1 -1
  36. package/build/components/sidebar-edit-mode/page-panels/reset-default-template.js.map +1 -1
  37. package/build/components/sidebar-edit-mode/template-panel/pattern-categories.js +2 -2
  38. package/build/components/sidebar-edit-mode/template-panel/pattern-categories.js.map +1 -1
  39. package/build/components/sidebar-edit-mode/template-panel/template-areas.js +1 -1
  40. package/build/components/sidebar-edit-mode/template-panel/template-areas.js.map +1 -1
  41. package/build/components/sidebar-navigation-screen-patterns/index.js +14 -2
  42. package/build/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
  43. package/build/components/sidebar-navigation-screen-template/home-template-details.js +13 -18
  44. package/build/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
  45. package/build/components/sidebar-navigation-screen-templates-browse/index.js +16 -4
  46. package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  47. package/build-module/components/add-new-pattern/index.js +5 -9
  48. package/build-module/components/add-new-pattern/index.js.map +1 -1
  49. package/build-module/components/global-styles/font-families.js +3 -2
  50. package/build-module/components/global-styles/font-families.js.map +1 -1
  51. package/build-module/components/global-styles/font-library-modal/collection-font-details.js +3 -1
  52. package/build-module/components/global-styles/font-library-modal/collection-font-details.js.map +1 -1
  53. package/build-module/components/global-styles/font-library-modal/context.js +26 -30
  54. package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
  55. package/build-module/components/global-styles/font-library-modal/font-collection.js +32 -12
  56. package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  57. package/build-module/components/global-styles/font-library-modal/index.js +10 -3
  58. package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
  59. package/build-module/components/global-styles/font-library-modal/installed-fonts.js +28 -8
  60. package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  61. package/build-module/components/global-styles/font-library-modal/local-fonts.js +38 -11
  62. package/build-module/components/global-styles/font-library-modal/local-fonts.js.map +1 -1
  63. package/build-module/components/global-styles/font-library-modal/upload-fonts.js +17 -0
  64. package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -0
  65. package/build-module/components/global-styles/font-library-modal/utils/fonts-outline.js +4 -1
  66. package/build-module/components/global-styles/font-library-modal/utils/fonts-outline.js.map +1 -1
  67. package/build-module/components/global-styles/font-library-modal/utils/get-notice-from-response.js +63 -0
  68. package/build-module/components/global-styles/font-library-modal/utils/get-notice-from-response.js.map +1 -0
  69. package/build-module/components/global-styles/font-library-modal/utils/index.js +3 -0
  70. package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  71. package/build-module/components/global-styles/screen-typography.js +1 -1
  72. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  73. package/build-module/components/page-patterns/grid.js +0 -1
  74. package/build-module/components/page-patterns/grid.js.map +1 -1
  75. package/build-module/components/page-patterns/patterns-list.js +1 -1
  76. package/build-module/components/page-patterns/patterns-list.js.map +1 -1
  77. package/build-module/components/page-patterns/use-patterns.js +5 -1
  78. package/build-module/components/page-patterns/use-patterns.js.map +1 -1
  79. package/build-module/components/page-template-parts/index.js +12 -1
  80. package/build-module/components/page-template-parts/index.js.map +1 -1
  81. package/build-module/components/sidebar-edit-mode/page-panels/reset-default-template.js +1 -1
  82. package/build-module/components/sidebar-edit-mode/page-panels/reset-default-template.js.map +1 -1
  83. package/build-module/components/sidebar-edit-mode/template-panel/pattern-categories.js +3 -3
  84. package/build-module/components/sidebar-edit-mode/template-panel/pattern-categories.js.map +1 -1
  85. package/build-module/components/sidebar-edit-mode/template-panel/template-areas.js +1 -1
  86. package/build-module/components/sidebar-edit-mode/template-panel/template-areas.js.map +1 -1
  87. package/build-module/components/sidebar-navigation-screen-patterns/index.js +14 -2
  88. package/build-module/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
  89. package/build-module/components/sidebar-navigation-screen-template/home-template-details.js +14 -19
  90. package/build-module/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
  91. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +16 -4
  92. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  93. package/build-style/style-rtl.css +16 -2
  94. package/build-style/style.css +16 -2
  95. package/package.json +40 -40
  96. package/src/components/add-new-pattern/index.js +5 -8
  97. package/src/components/global-styles/font-families.js +5 -1
  98. package/src/components/global-styles/font-library-modal/collection-font-details.js +1 -1
  99. package/src/components/global-styles/font-library-modal/context.js +36 -38
  100. package/src/components/global-styles/font-library-modal/font-collection.js +41 -12
  101. package/src/components/global-styles/font-library-modal/index.js +16 -6
  102. package/src/components/global-styles/font-library-modal/installed-fonts.js +36 -6
  103. package/src/components/global-styles/font-library-modal/local-fonts.js +65 -23
  104. package/src/components/global-styles/font-library-modal/style.scss +18 -1
  105. package/src/components/global-styles/font-library-modal/upload-fonts.js +20 -0
  106. package/src/components/global-styles/font-library-modal/utils/fonts-outline.js +4 -3
  107. package/src/components/global-styles/font-library-modal/utils/get-notice-from-response.js +62 -0
  108. package/src/components/global-styles/font-library-modal/utils/index.js +4 -0
  109. package/src/components/global-styles/screen-typography.js +4 -3
  110. package/src/components/page-patterns/grid.js +1 -1
  111. package/src/components/page-patterns/patterns-list.js +1 -1
  112. package/src/components/page-patterns/use-patterns.js +7 -3
  113. package/src/components/page-template-parts/index.js +14 -1
  114. package/src/components/sidebar-edit-mode/page-panels/reset-default-template.js +1 -1
  115. package/src/components/sidebar-edit-mode/template-panel/pattern-categories.js +18 -16
  116. package/src/components/sidebar-edit-mode/template-panel/template-areas.js +1 -1
  117. package/src/components/sidebar-navigation-screen/style.scss +0 -1
  118. package/src/components/sidebar-navigation-screen-patterns/index.js +25 -4
  119. package/src/components/sidebar-navigation-screen-template/home-template-details.js +27 -35
  120. package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-site",
3
- "version": "5.19.1",
3
+ "version": "5.19.3",
4
4
  "description": "Edit Site Page module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,44 +27,44 @@
27
27
  "react-native": "src/index",
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
- "@wordpress/a11y": "^3.42.1",
31
- "@wordpress/api-fetch": "^6.39.1",
32
- "@wordpress/block-editor": "^12.10.1",
33
- "@wordpress/block-library": "^8.19.1",
34
- "@wordpress/blocks": "^12.19.1",
35
- "@wordpress/commands": "^0.13.1",
36
- "@wordpress/components": "^25.8.1",
37
- "@wordpress/compose": "^6.19.1",
38
- "@wordpress/core-commands": "^0.11.1",
39
- "@wordpress/core-data": "^6.19.1",
40
- "@wordpress/data": "^9.12.1",
41
- "@wordpress/date": "^4.42.1",
42
- "@wordpress/deprecated": "^3.42.1",
43
- "@wordpress/dom": "^3.42.1",
44
- "@wordpress/editor": "^13.19.1",
45
- "@wordpress/element": "^5.19.1",
46
- "@wordpress/escape-html": "^2.42.1",
47
- "@wordpress/hooks": "^3.42.1",
48
- "@wordpress/html-entities": "^3.42.1",
49
- "@wordpress/i18n": "^4.42.1",
50
- "@wordpress/icons": "^9.33.1",
51
- "@wordpress/interface": "^5.19.1",
52
- "@wordpress/keyboard-shortcuts": "^4.19.1",
53
- "@wordpress/keycodes": "^3.42.1",
54
- "@wordpress/media-utils": "^4.33.1",
55
- "@wordpress/notices": "^4.10.1",
56
- "@wordpress/patterns": "^1.3.1",
57
- "@wordpress/plugins": "^6.10.1",
58
- "@wordpress/preferences": "^3.19.1",
59
- "@wordpress/primitives": "^3.40.1",
60
- "@wordpress/private-apis": "^0.24.1",
61
- "@wordpress/reusable-blocks": "^4.19.1",
62
- "@wordpress/router": "^0.11.1",
63
- "@wordpress/style-engine": "^1.25.1",
64
- "@wordpress/url": "^3.43.1",
65
- "@wordpress/viewport": "^5.19.1",
66
- "@wordpress/widgets": "^3.19.1",
67
- "@wordpress/wordcount": "^3.42.1",
30
+ "@wordpress/a11y": "^3.42.3",
31
+ "@wordpress/api-fetch": "^6.39.3",
32
+ "@wordpress/block-editor": "^12.10.3",
33
+ "@wordpress/block-library": "^8.19.3",
34
+ "@wordpress/blocks": "^12.19.3",
35
+ "@wordpress/commands": "^0.13.3",
36
+ "@wordpress/components": "^25.8.3",
37
+ "@wordpress/compose": "^6.19.3",
38
+ "@wordpress/core-commands": "^0.11.3",
39
+ "@wordpress/core-data": "^6.19.3",
40
+ "@wordpress/data": "^9.12.3",
41
+ "@wordpress/date": "^4.42.3",
42
+ "@wordpress/deprecated": "^3.42.3",
43
+ "@wordpress/dom": "^3.42.3",
44
+ "@wordpress/editor": "^13.19.3",
45
+ "@wordpress/element": "^5.19.3",
46
+ "@wordpress/escape-html": "^2.42.3",
47
+ "@wordpress/hooks": "^3.42.3",
48
+ "@wordpress/html-entities": "^3.42.3",
49
+ "@wordpress/i18n": "^4.42.3",
50
+ "@wordpress/icons": "^9.33.3",
51
+ "@wordpress/interface": "^5.19.3",
52
+ "@wordpress/keyboard-shortcuts": "^4.19.3",
53
+ "@wordpress/keycodes": "^3.42.3",
54
+ "@wordpress/media-utils": "^4.33.3",
55
+ "@wordpress/notices": "^4.10.3",
56
+ "@wordpress/patterns": "^1.3.3",
57
+ "@wordpress/plugins": "^6.10.3",
58
+ "@wordpress/preferences": "^3.19.3",
59
+ "@wordpress/primitives": "^3.40.3",
60
+ "@wordpress/private-apis": "^0.24.3",
61
+ "@wordpress/reusable-blocks": "^4.19.3",
62
+ "@wordpress/router": "^0.11.3",
63
+ "@wordpress/style-engine": "^1.25.3",
64
+ "@wordpress/url": "^3.43.3",
65
+ "@wordpress/viewport": "^5.19.3",
66
+ "@wordpress/widgets": "^3.19.3",
67
+ "@wordpress/wordcount": "^3.42.3",
68
68
  "change-case": "^4.1.2",
69
69
  "classnames": "^2.3.1",
70
70
  "colord": "^2.9.2",
@@ -84,5 +84,5 @@
84
84
  "publishConfig": {
85
85
  "access": "public"
86
86
  },
87
- "gitHead": "4987d16acb5c41b62704dc4f88225acb97ddd698"
87
+ "gitHead": "6256f93c37705d142f75a99f1fc808540ca7dca8"
88
88
  }
@@ -11,6 +11,7 @@ import {
11
11
  privateApis as editPatternsPrivateApis,
12
12
  store as patternsStore,
13
13
  } from '@wordpress/patterns';
14
+ import { store as coreStore } from '@wordpress/core-data';
14
15
  import { store as noticesStore } from '@wordpress/notices';
15
16
 
16
17
  /**
@@ -19,7 +20,6 @@ import { store as noticesStore } from '@wordpress/notices';
19
20
  import CreateTemplatePartModal from '../create-template-part-modal';
20
21
  import SidebarButton from '../sidebar-button';
21
22
  import { unlock } from '../../lock-unlock';
22
- import { store as editSiteStore } from '../../store';
23
23
  import {
24
24
  PATTERN_TYPES,
25
25
  PATTERN_DEFAULT_CATEGORY,
@@ -36,9 +36,8 @@ export default function AddNewPattern() {
36
36
  const [ showPatternModal, setShowPatternModal ] = useState( false );
37
37
  const [ showTemplatePartModal, setShowTemplatePartModal ] =
38
38
  useState( false );
39
- const isTemplatePartsMode = useSelect( ( select ) => {
40
- const settings = select( editSiteStore ).getSettings();
41
- return !! settings.supportsTemplatePartsMode;
39
+ const isBlockBasedTheme = useSelect( ( select ) => {
40
+ return select( coreStore ).getCurrentTheme()?.is_block_theme;
42
41
  }, [] );
43
42
  const { createPatternFromFile } = unlock( useDispatch( patternsStore ) );
44
43
  const { createSuccessNotice, createErrorNotice } =
@@ -52,7 +51,7 @@ export default function AddNewPattern() {
52
51
  history.push( {
53
52
  postId: pattern.id,
54
53
  postType: PATTERN_TYPES.user,
55
- categoryType: PATTERN_TYPES.user,
54
+ categoryType: PATTERN_TYPES.theme,
56
55
  categoryId,
57
56
  canvas: 'edit',
58
57
  } );
@@ -82,9 +81,7 @@ export default function AddNewPattern() {
82
81
  },
83
82
  ];
84
83
 
85
- // Remove condition when command palette issues are resolved.
86
- // See: https://github.com/WordPress/gutenberg/issues/52154.
87
- if ( ! isTemplatePartsMode ) {
84
+ if ( isBlockBasedTheme ) {
88
85
  controls.push( {
89
86
  icon: symbolFilled,
90
87
  onClick: () => setShowTemplatePartModal( true ),
@@ -64,8 +64,12 @@ function FontFamilies() {
64
64
  );
65
65
  }
66
66
 
67
- export default ( { ...props } ) => (
67
+ const FontFamiliesComponent = ( { ...props } ) => (
68
68
  <FontLibraryProvider>
69
69
  <FontFamilies { ...props } />
70
70
  </FontLibraryProvider>
71
71
  );
72
+
73
+ export default process.env.IS_GUTENBERG_PLUGIN
74
+ ? FontFamiliesComponent
75
+ : undefined;
@@ -42,7 +42,7 @@ function CollectionFontDetails( {
42
42
  handleToggleVariant={ handleToggleVariant }
43
43
  selected={ isFontFontFaceInOutline(
44
44
  font.slug,
45
- face,
45
+ font.fontFace ? face : null, // If the font has no fontFace, we want to check if the font is in the outline
46
46
  fontToInstallOutline
47
47
  ) }
48
48
  />
@@ -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 fontsInstalled = await fetchInstallFonts( formData );
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
- return true;
221
- } catch ( e ) {
222
- // eslint-disable-next-line no-console
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 false;
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
- deactivateFontFamily( font );
238
- // Save the global styles to the database.
239
- await saveSpecifiedEntityEdits(
240
- 'root',
241
- 'globalStyles',
242
- globalStylesId,
243
- [ 'settings.typography.fontFamilies' ]
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 true;
248
- } catch ( e ) {
244
+ return response;
245
+ } catch ( error ) {
249
246
  // eslint-disable-next-line no-console
250
- console.error( e );
251
- createErrorNotice( __( 'Error uninstalling fonts.' ), {
252
- type: 'snackbar',
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.forEach( ( face ) => {
285
- // Load font faces just in the iframe because they already are in the document.
286
- loadFontFaceInBrowser(
287
- face,
288
- getDisplaySrcFromFontFace( face.src ),
289
- 'iframe'
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 } = useContext( FontLibraryContext );
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( { fontsToInstall, resetFontsToInstall } ) {
236
- const { installFonts, isInstalling } = useContext( FontLibraryContext );
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 INSTALLED_FONTS_TAB = {
16
- name: 'installed-fonts',
17
- title: __( 'Library' ),
18
- className: 'installed-fonts',
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
- INSTALLED_FONTS_TAB,
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 result = await uninstallFont( libraryFontSelected );
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 ( result ) {
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
- <Text className="font-library-modal__subtitle">
135
- { __( 'Upload Fonts' ) }
136
- </Text>
137
- <Spacer margin={ 2 } />
157
+ <Spacer margin={ 16 } />
138
158
  <DropZone onFilesDrop={ handleDropZone } />
139
- <FormFileUpload
140
- accept={ ALLOWED_FILE_EXTENSIONS.map(
141
- ( ext ) => `.${ ext }`
142
- ).join( ',' ) }
143
- multiple={ true }
144
- onChange={ onFilesUpload }
145
- render={ ( { openFileDialog } ) => (
146
- <Button
147
- className="font-library-modal__upload-area"
148
- onClick={ openFileDialog }
149
- >
150
- <span>
151
- { __( 'Drag and drop your font files here.' ) }
152
- </span>
153
- </Button>
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
  }