@wordpress/edit-site 5.26.0 → 5.27.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 +2 -0
- package/build/components/actions/index.js +139 -36
- package/build/components/actions/index.js.map +1 -1
- package/build/components/editor-canvas-container/index.js +1 -1
- package/build/components/editor-canvas-container/index.js.map +1 -1
- package/build/components/global-styles/font-families.js +3 -2
- package/build/components/global-styles/font-families.js.map +1 -1
- package/build/components/global-styles/font-family-item.js +3 -4
- package/build/components/global-styles/font-family-item.js.map +1 -1
- package/build/components/global-styles/font-library-modal/context.js +80 -41
- package/build/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build/components/global-styles/font-library-modal/font-collection.js +49 -22
- package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build/components/global-styles/font-library-modal/fonts-grid.js +4 -1
- package/build/components/global-styles/font-library-modal/fonts-grid.js.map +1 -1
- package/build/components/global-styles/font-library-modal/index.js +4 -4
- package/build/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js +16 -8
- package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/library-font-card.js +1 -1
- package/build/components/global-styles/font-library-modal/library-font-card.js.map +1 -1
- package/build/components/global-styles/font-library-modal/library-font-variant.js +2 -2
- package/build/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
- package/build/components/global-styles/font-library-modal/local-fonts.js +13 -4
- package/build/components/global-styles/font-library-modal/local-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/resolvers.js +49 -20
- package/build/components/global-styles/font-library-modal/resolvers.js.map +1 -1
- package/build/components/global-styles/font-library-modal/tab-panel-layout.js +6 -2
- package/build/components/global-styles/font-library-modal/tab-panel-layout.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/filter-fonts.js +17 -2
- package/build/components/global-styles/font-library-modal/utils/filter-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/index.js +103 -17
- package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/preview-styles.js +4 -3
- package/build/components/global-styles/font-library-modal/utils/preview-styles.js.map +1 -1
- package/build/components/global-styles/screen-block.js +10 -0
- package/build/components/global-styles/screen-block.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +4 -1
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/layout/hooks.js +6 -5
- package/build/components/layout/hooks.js.map +1 -1
- package/build/components/layout/index.js +19 -28
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/router.js +135 -0
- package/build/components/layout/router.js.map +1 -0
- package/build/components/page-pages/index.js +92 -69
- package/build/components/page-pages/index.js.map +1 -1
- package/build/components/page-patterns/dataviews-pattern-actions.js +11 -6
- package/build/components/page-patterns/dataviews-pattern-actions.js.map +1 -1
- package/build/components/page-patterns/index.js +295 -15
- package/build/components/page-patterns/index.js.map +1 -1
- package/build/components/{page-templates/template-actions.js → page-templates-template-parts/actions.js} +51 -23
- package/build/components/page-templates-template-parts/actions.js.map +1 -0
- package/build/components/page-templates-template-parts/add-new-template-part.js.map +1 -0
- package/build/components/page-templates-template-parts/index.js +395 -0
- package/build/components/page-templates-template-parts/index.js.map +1 -0
- package/build/components/preferences-modal/index.js +9 -134
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/revisions/index.js +1 -1
- package/build/components/revisions/index.js.map +1 -1
- package/build/components/save-button/index.js +4 -2
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/save-panel/index.js +6 -5
- package/build/components/save-panel/index.js.map +1 -1
- package/build/components/sidebar/index.js +3 -1
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar-dataviews/dataview-item.js +3 -1
- package/build/components/sidebar-dataviews/dataview-item.js.map +1 -1
- package/build/components/sidebar-dataviews/default-views.js +4 -2
- package/build/components/sidebar-dataviews/default-views.js.map +1 -1
- package/build/components/sidebar-dataviews/index.js +2 -2
- package/build/components/sidebar-dataviews/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen/index.js +8 -7
- package/build/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pages/index.js +2 -10
- package/build/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pages-dataviews/index.js +26 -3
- package/build/components/sidebar-navigation-screen-pages-dataviews/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates/index.js +63 -8
- package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +76 -0
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -0
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +9 -2
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build/components/site-hub/index.js +3 -1
- package/build/components/site-hub/index.js.map +1 -1
- package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +47 -12
- package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
- package/build/components/sync-state-with-url/use-sync-path-with-url.js +25 -2
- package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build/hooks/commands/use-edit-mode-commands.js +33 -5
- package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build/hooks/push-changes-to-global-styles/index.js +13 -6
- package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build/hooks/template-part-edit.js +7 -6
- package/build/hooks/template-part-edit.js.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/store/actions.js +11 -29
- package/build/store/actions.js.map +1 -1
- package/build/store/private-actions.js +85 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/selectors.js +2 -2
- package/build/store/selectors.js.map +1 -1
- package/build/utils/get-is-list-page.js +1 -1
- package/build/utils/get-is-list-page.js.map +1 -1
- package/build/utils/use-actual-current-theme.js +32 -0
- package/build/utils/use-actual-current-theme.js.map +1 -0
- package/build-module/components/actions/index.js +139 -36
- package/build-module/components/actions/index.js.map +1 -1
- package/build-module/components/editor-canvas-container/index.js +1 -1
- package/build-module/components/editor-canvas-container/index.js.map +1 -1
- package/build-module/components/global-styles/font-families.js +3 -2
- package/build-module/components/global-styles/font-families.js.map +1 -1
- package/build-module/components/global-styles/font-family-item.js +4 -5
- package/build-module/components/global-styles/font-family-item.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/context.js +82 -42
- 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 +49 -22
- package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/fonts-grid.js +4 -1
- package/build-module/components/global-styles/font-library-modal/fonts-grid.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/index.js +4 -4
- 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 +16 -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/library-font-card.js +1 -1
- package/build-module/components/global-styles/font-library-modal/library-font-card.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/library-font-variant.js +2 -2
- package/build-module/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/local-fonts.js +13 -4
- package/build-module/components/global-styles/font-library-modal/local-fonts.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/resolvers.js +45 -18
- package/build-module/components/global-styles/font-library-modal/resolvers.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js +6 -2
- package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/filter-fonts.js +17 -2
- package/build-module/components/global-styles/font-library-modal/utils/filter-fonts.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/index.js +99 -16
- package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/preview-styles.js +4 -3
- package/build-module/components/global-styles/font-library-modal/utils/preview-styles.js.map +1 -1
- package/build-module/components/global-styles/screen-block.js +10 -0
- package/build-module/components/global-styles/screen-block.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +4 -1
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/layout/hooks.js +6 -5
- package/build-module/components/layout/hooks.js.map +1 -1
- package/build-module/components/layout/index.js +19 -28
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/router.js +127 -0
- package/build-module/components/layout/router.js.map +1 -0
- package/build-module/components/page-pages/index.js +91 -70
- package/build-module/components/page-pages/index.js.map +1 -1
- package/build-module/components/page-patterns/dataviews-pattern-actions.js +11 -6
- package/build-module/components/page-patterns/dataviews-pattern-actions.js.map +1 -1
- package/build-module/components/page-patterns/index.js +296 -16
- package/build-module/components/page-patterns/index.js.map +1 -1
- package/build-module/components/{page-templates/template-actions.js → page-templates-template-parts/actions.js} +52 -24
- package/build-module/components/page-templates-template-parts/actions.js.map +1 -0
- package/build-module/components/page-templates-template-parts/add-new-template-part.js.map +1 -0
- package/build-module/components/page-templates-template-parts/index.js +385 -0
- package/build-module/components/page-templates-template-parts/index.js.map +1 -0
- package/build-module/components/preferences-modal/index.js +12 -136
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/revisions/index.js +1 -1
- package/build-module/components/revisions/index.js.map +1 -1
- package/build-module/components/save-button/index.js +4 -2
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/save-panel/index.js +7 -6
- package/build-module/components/save-panel/index.js.map +1 -1
- package/build-module/components/sidebar/index.js +3 -1
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar-dataviews/dataview-item.js +3 -1
- package/build-module/components/sidebar-dataviews/dataview-item.js.map +1 -1
- package/build-module/components/sidebar-dataviews/default-views.js +4 -2
- package/build-module/components/sidebar-dataviews/default-views.js.map +1 -1
- package/build-module/components/sidebar-dataviews/index.js +2 -2
- package/build-module/components/sidebar-dataviews/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen/index.js +8 -7
- package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pages/index.js +2 -10
- package/build-module/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pages-dataviews/index.js +27 -4
- package/build-module/components/sidebar-navigation-screen-pages-dataviews/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates/index.js +64 -9
- package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +68 -0
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +9 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build-module/components/site-hub/index.js +3 -1
- package/build-module/components/site-hub/index.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +47 -11
- package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +25 -2
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build-module/hooks/commands/use-edit-mode-commands.js +33 -5
- package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build-module/hooks/push-changes-to-global-styles/index.js +13 -6
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +7 -6
- package/build-module/hooks/template-part-edit.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +13 -30
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-actions.js +83 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/selectors.js +2 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/get-is-list-page.js +1 -1
- package/build-module/utils/get-is-list-page.js.map +1 -1
- package/build-module/utils/use-actual-current-theme.js +24 -0
- package/build-module/utils/use-actual-current-theme.js.map +1 -0
- package/build-style/style-rtl.css +316 -215
- package/build-style/style.css +316 -215
- package/package.json +42 -42
- package/src/components/actions/index.js +236 -84
- package/src/components/editor-canvas-container/index.js +1 -1
- package/src/components/global-styles/font-families.js +14 -8
- package/src/components/global-styles/font-family-item.js +7 -4
- package/src/components/global-styles/font-library-modal/context.js +156 -50
- package/src/components/global-styles/font-library-modal/font-collection.js +56 -21
- package/src/components/global-styles/font-library-modal/fonts-grid.js +6 -2
- package/src/components/global-styles/font-library-modal/index.js +4 -4
- package/src/components/global-styles/font-library-modal/installed-fonts.js +18 -8
- package/src/components/global-styles/font-library-modal/library-font-card.js +2 -1
- package/src/components/global-styles/font-library-modal/library-font-variant.js +10 -9
- package/src/components/global-styles/font-library-modal/local-fonts.js +14 -4
- package/src/components/global-styles/font-library-modal/resolvers.js +50 -17
- package/src/components/global-styles/font-library-modal/style.scss +23 -35
- package/src/components/global-styles/font-library-modal/tab-panel-layout.js +30 -26
- package/src/components/global-styles/font-library-modal/utils/filter-fonts.js +19 -2
- package/src/components/global-styles/font-library-modal/utils/index.js +136 -29
- package/src/components/global-styles/font-library-modal/utils/preview-styles.js +7 -3
- package/src/components/global-styles/font-library-modal/utils/test/filter-fonts.spec.js +40 -10
- package/src/components/global-styles/font-library-modal/utils/test/preview-styles.spec.js +5 -5
- package/src/components/global-styles/screen-block.js +10 -0
- package/src/components/global-styles/screen-typography.js +9 -3
- package/src/components/global-styles/style.scss +4 -0
- package/src/components/header-edit-mode/style.scss +15 -5
- package/src/components/layout/hooks.js +6 -5
- package/src/components/layout/index.js +80 -96
- package/src/components/layout/router.js +121 -0
- package/src/components/layout/style.scss +13 -16
- package/src/components/page/style.scss +1 -8
- package/src/components/page-pages/index.js +142 -148
- package/src/components/page-pages/style.scss +41 -2
- package/src/components/page-patterns/dataviews-pattern-actions.js +11 -6
- package/src/components/page-patterns/index.js +392 -14
- package/src/components/page-patterns/style.scss +36 -2
- package/src/components/{page-templates/template-actions.js → page-templates-template-parts/actions.js} +90 -37
- package/src/components/{page-templates → page-templates-template-parts}/index.js +198 -169
- package/src/components/page-templates-template-parts/style.scss +44 -0
- package/src/components/preferences-modal/index.js +8 -211
- package/src/components/revisions/index.js +1 -1
- package/src/components/save-button/index.js +7 -4
- package/src/components/save-panel/index.js +13 -12
- package/src/components/sidebar/index.js +4 -5
- package/src/components/sidebar-dataviews/dataview-item.js +2 -1
- package/src/components/sidebar-dataviews/default-views.js +4 -2
- package/src/components/sidebar-dataviews/index.js +8 -6
- package/src/components/sidebar-navigation-item/style.scss +1 -1
- package/src/components/sidebar-navigation-screen/index.js +19 -10
- package/src/components/sidebar-navigation-screen-pages/index.js +2 -10
- package/src/components/sidebar-navigation-screen-pages-dataviews/index.js +32 -6
- package/src/components/sidebar-navigation-screen-templates/index.js +85 -28
- package/src/components/sidebar-navigation-screen-templates/style.scss +9 -0
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +73 -0
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +10 -1
- package/src/components/site-hub/index.js +4 -1
- package/src/components/site-hub/style.scss +1 -12
- package/src/components/site-icon/style.scss +1 -1
- package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +40 -10
- package/src/components/sync-state-with-url/use-sync-path-with-url.js +32 -0
- package/src/hooks/commands/use-edit-mode-commands.js +50 -3
- package/src/hooks/push-changes-to-global-styles/index.js +29 -23
- package/src/hooks/template-part-edit.js +12 -12
- package/src/index.js +1 -1
- package/src/store/actions.js +17 -51
- package/src/store/private-actions.js +133 -0
- package/src/store/selectors.js +2 -4
- package/src/style.scss +2 -1
- package/src/utils/get-is-list-page.js +3 -2
- package/src/utils/use-actual-current-theme.js +27 -0
- package/build/components/global-styles/font-library-modal/utils/get-intersecting-font-faces.js +0 -58
- package/build/components/global-styles/font-library-modal/utils/get-intersecting-font-faces.js.map +0 -1
- package/build/components/global-styles/font-library-modal/utils/get-notice-from-response.js +0 -71
- package/build/components/global-styles/font-library-modal/utils/get-notice-from-response.js.map +0 -1
- package/build/components/page-main/index.js +0 -44
- package/build/components/page-main/index.js.map +0 -1
- package/build/components/page-patterns/dataviews-patterns.js +0 -307
- package/build/components/page-patterns/dataviews-patterns.js.map +0 -1
- package/build/components/page-template-parts/add-new-template-part.js.map +0 -1
- package/build/components/page-template-parts/index.js +0 -81
- package/build/components/page-template-parts/index.js.map +0 -1
- package/build/components/page-templates/index.js +0 -352
- package/build/components/page-templates/index.js.map +0 -1
- package/build/components/page-templates/template-actions.js.map +0 -1
- package/build/components/post-preview/index.js +0 -29
- package/build/components/post-preview/index.js.map +0 -1
- package/build/components/preferences-modal/enable-feature.js +0 -36
- package/build/components/preferences-modal/enable-feature.js.map +0 -1
- package/build/components/preferences-modal/enable-panel-option.js +0 -33
- package/build/components/preferences-modal/enable-panel-option.js.map +0 -1
- package/build-module/components/global-styles/font-library-modal/utils/get-intersecting-font-faces.js +0 -52
- package/build-module/components/global-styles/font-library-modal/utils/get-intersecting-font-faces.js.map +0 -1
- package/build-module/components/global-styles/font-library-modal/utils/get-notice-from-response.js +0 -63
- package/build-module/components/global-styles/font-library-modal/utils/get-notice-from-response.js.map +0 -1
- package/build-module/components/page-main/index.js +0 -36
- package/build-module/components/page-main/index.js.map +0 -1
- package/build-module/components/page-patterns/dataviews-patterns.js +0 -299
- package/build-module/components/page-patterns/dataviews-patterns.js.map +0 -1
- package/build-module/components/page-template-parts/add-new-template-part.js.map +0 -1
- package/build-module/components/page-template-parts/index.js +0 -73
- package/build-module/components/page-template-parts/index.js.map +0 -1
- package/build-module/components/page-templates/index.js +0 -344
- package/build-module/components/page-templates/index.js.map +0 -1
- package/build-module/components/page-templates/template-actions.js.map +0 -1
- package/build-module/components/post-preview/index.js +0 -21
- package/build-module/components/post-preview/index.js.map +0 -1
- package/build-module/components/preferences-modal/enable-feature.js +0 -29
- package/build-module/components/preferences-modal/enable-feature.js.map +0 -1
- package/build-module/components/preferences-modal/enable-panel-option.js +0 -26
- package/build-module/components/preferences-modal/enable-panel-option.js.map +0 -1
- package/src/components/global-styles/font-library-modal/utils/get-intersecting-font-faces.js +0 -58
- package/src/components/global-styles/font-library-modal/utils/get-notice-from-response.js +0 -62
- package/src/components/global-styles/font-library-modal/utils/test/getIntersectingFontFaces.spec.js +0 -271
- package/src/components/global-styles/font-library-modal/utils/test/makeFormDataFromFontFamily.spec.js +0 -58
- package/src/components/page-main/index.js +0 -38
- package/src/components/page-patterns/dataviews-patterns.js +0 -380
- package/src/components/page-template-parts/index.js +0 -99
- package/src/components/page-templates/style.scss +0 -13
- package/src/components/post-preview/index.js +0 -16
- package/src/components/preferences-modal/enable-feature.js +0 -31
- package/src/components/preferences-modal/enable-panel-option.js +0 -23
- /package/build/components/{page-template-parts → page-templates-template-parts}/add-new-template-part.js +0 -0
- /package/build-module/components/{page-template-parts → page-templates-template-parts}/add-new-template-part.js +0 -0
- /package/src/components/{page-template-parts → page-templates-template-parts}/add-new-template-part.js +0 -0
|
@@ -21,6 +21,7 @@ function FontFamilies() {
|
|
|
21
21
|
themeFonts,
|
|
22
22
|
customFonts
|
|
23
23
|
} = useContext(FontLibraryContext);
|
|
24
|
+
const hasFonts = 0 < customFonts.length || 0 < themeFonts.length;
|
|
24
25
|
return createElement(Fragment, null, !!modalTabOpen && createElement(FontLibraryModal, {
|
|
25
26
|
onRequestClose: () => toggleModal(),
|
|
26
27
|
initialTabName: modalTabOpen
|
|
@@ -39,7 +40,7 @@ function FontFamilies() {
|
|
|
39
40
|
"aria-label": __('Manage fonts'),
|
|
40
41
|
icon: typography,
|
|
41
42
|
size: 'small'
|
|
42
|
-
})))), createElement(ItemGroup, {
|
|
43
|
+
})))), hasFonts ? createElement(ItemGroup, {
|
|
43
44
|
isBordered: true,
|
|
44
45
|
isSeparated: true
|
|
45
46
|
}, customFonts.map(font => createElement(FontFamilyItem, {
|
|
@@ -48,7 +49,7 @@ function FontFamilies() {
|
|
|
48
49
|
})), themeFonts.map(font => createElement(FontFamilyItem, {
|
|
49
50
|
key: font.slug,
|
|
50
51
|
font: font
|
|
51
|
-
})))));
|
|
52
|
+
}))) : createElement(Fragment, null, __('No fonts installed.'))));
|
|
52
53
|
}
|
|
53
54
|
export default (({
|
|
54
55
|
...props
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","__experimentalItemGroup","ItemGroup","__experimentalVStack","VStack","__experimentalHStack","HStack","Button","Tooltip","typography","useContext","FontLibraryProvider","FontLibraryContext","FontLibraryModal","FontFamilyItem","Subtitle","FontFamilies","modalTabOpen","toggleModal","themeFonts","customFonts","createElement","Fragment","onRequestClose","initialTabName","spacing","justify","level","text","onClick","icon","size","isBordered","isSeparated","map","font","key","slug","props"],"sources":["@wordpress/edit-site/src/components/global-styles/font-families.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n\tButton,\n\tTooltip,\n} from '@wordpress/components';\nimport { typography } from '@wordpress/icons';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport FontLibraryProvider, {\n\tFontLibraryContext,\n} from './font-library-modal/context';\nimport FontLibraryModal from './font-library-modal';\nimport FontFamilyItem from './font-family-item';\nimport Subtitle from './subtitle';\n\nfunction FontFamilies() {\n\tconst { modalTabOpen, toggleModal, themeFonts, customFonts } =\n\t\tuseContext( FontLibraryContext );\n\n\treturn (\n\t\t<>\n\t\t\t{ !! modalTabOpen && (\n\t\t\t\t<FontLibraryModal\n\t\t\t\t\tonRequestClose={ () => toggleModal() }\n\t\t\t\t\tinitialTabName={ modalTabOpen }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t<HStack justify=\"space-between\">\n\t\t\t\t\t<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle>\n\t\t\t\t\t<HStack justify=\"flex-end\">\n\t\t\t\t\t\t<Tooltip text={ __( 'Manage fonts' ) }>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\ttoggleModal( 'installed-fonts' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\taria-label={ __( 'Manage fonts' ) }\n\t\t\t\t\t\t\t\ticon={ typography }\n\t\t\t\t\t\t\t\tsize={ 'small' }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t</HStack>\n\t\t\t\t</HStack>\n\t\t\t\t<ItemGroup isBordered isSeparated>\n\t\t\t\t\t{ customFonts.map( ( font ) => (\n\t\t\t\t\t\t<FontFamilyItem key={ font.slug } font={ font } />\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ themeFonts.map( ( font ) => (\n\t\t\t\t\t\t<FontFamilyItem key={ font.slug } font={ font } />\n\t\t\t\t\t) ) }\n\t\t\t\t</ItemGroup>\n\t\t\t</VStack>\n\t\t</>\n\t);\n}\n\nexport default ( { ...props } ) => (\n\t<FontLibraryProvider>\n\t\t<FontFamilies { ...props } />\n\t</FontLibraryProvider>\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SACCC,uBAAuB,IAAIC,SAAS,EACpCC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,MAAM,EACNC,OAAO,QACD,uBAAuB;AAC9B,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,OAAOC,mBAAmB,IACzBC,kBAAkB,QACZ,8BAA8B;AACrC,OAAOC,gBAAgB,MAAM,sBAAsB;AACnD,OAAOC,cAAc,MAAM,oBAAoB;AAC/C,OAAOC,QAAQ,MAAM,YAAY;AAEjC,SAASC,YAAYA,CAAA,EAAG;EACvB,MAAM;IAAEC,YAAY;IAAEC,WAAW;IAAEC,UAAU;IAAEC;EAAY,CAAC,GAC3DV,UAAU,CAAEE,kBAAmB,CAAC;EAEjC,
|
|
1
|
+
{"version":3,"names":["__","__experimentalItemGroup","ItemGroup","__experimentalVStack","VStack","__experimentalHStack","HStack","Button","Tooltip","typography","useContext","FontLibraryProvider","FontLibraryContext","FontLibraryModal","FontFamilyItem","Subtitle","FontFamilies","modalTabOpen","toggleModal","themeFonts","customFonts","hasFonts","length","createElement","Fragment","onRequestClose","initialTabName","spacing","justify","level","text","onClick","icon","size","isBordered","isSeparated","map","font","key","slug","props"],"sources":["@wordpress/edit-site/src/components/global-styles/font-families.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n\tButton,\n\tTooltip,\n} from '@wordpress/components';\nimport { typography } from '@wordpress/icons';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport FontLibraryProvider, {\n\tFontLibraryContext,\n} from './font-library-modal/context';\nimport FontLibraryModal from './font-library-modal';\nimport FontFamilyItem from './font-family-item';\nimport Subtitle from './subtitle';\n\nfunction FontFamilies() {\n\tconst { modalTabOpen, toggleModal, themeFonts, customFonts } =\n\t\tuseContext( FontLibraryContext );\n\n\tconst hasFonts = 0 < customFonts.length || 0 < themeFonts.length;\n\n\treturn (\n\t\t<>\n\t\t\t{ !! modalTabOpen && (\n\t\t\t\t<FontLibraryModal\n\t\t\t\t\tonRequestClose={ () => toggleModal() }\n\t\t\t\t\tinitialTabName={ modalTabOpen }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t<HStack justify=\"space-between\">\n\t\t\t\t\t<Subtitle level={ 3 }>{ __( 'Fonts' ) }</Subtitle>\n\t\t\t\t\t<HStack justify=\"flex-end\">\n\t\t\t\t\t\t<Tooltip text={ __( 'Manage fonts' ) }>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\ttoggleModal( 'installed-fonts' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\taria-label={ __( 'Manage fonts' ) }\n\t\t\t\t\t\t\t\ticon={ typography }\n\t\t\t\t\t\t\t\tsize={ 'small' }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t</HStack>\n\t\t\t\t</HStack>\n\t\t\t\t{ hasFonts ? (\n\t\t\t\t\t<ItemGroup isBordered isSeparated>\n\t\t\t\t\t\t{ customFonts.map( ( font ) => (\n\t\t\t\t\t\t\t<FontFamilyItem key={ font.slug } font={ font } />\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t{ themeFonts.map( ( font ) => (\n\t\t\t\t\t\t\t<FontFamilyItem key={ font.slug } font={ font } />\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</ItemGroup>\n\t\t\t\t) : (\n\t\t\t\t\t<>{ __( 'No fonts installed.' ) }</>\n\t\t\t\t) }\n\t\t\t</VStack>\n\t\t</>\n\t);\n}\n\nexport default ( { ...props } ) => (\n\t<FontLibraryProvider>\n\t\t<FontFamilies { ...props } />\n\t</FontLibraryProvider>\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SACCC,uBAAuB,IAAIC,SAAS,EACpCC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,MAAM,EACNC,OAAO,QACD,uBAAuB;AAC9B,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,OAAOC,mBAAmB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AAI,CAACE,IAAM;IAACF,IAAI,EAAGA;EAAM,CAAE,CAChD,CAAC,EACDlB,UAAU,CAACiB,GAAG,CAAIC,IAAI,IACvBd,aAAA,CAACT,cAAc;IAACwB,GAAG,EAAGD,IAAI,CAACE,IAAM;IAACF,IAAI,EAAGA;EAAM,CAAE,CAChD,CACQ,CAAC,GAEZd,aAAA,CAAAC,QAAA,QAAIxB,EAAE,CAAE,qBAAsB,CAAK,CAE7B,CACP,CAAC;AAEL;AAEA,gBAAe,CAAE;EAAE,GAAGwC;AAAM,CAAC,KAC5BjB,aAAA,CAACZ,mBAAmB,QACnBY,aAAA,CAACP,YAAY;EAAA,GAAMwB;AAAK,CAAI,CACR,CACrB"}
|
|
@@ -2,7 +2,7 @@ import { createElement } from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
|
-
import { _n } from '@wordpress/i18n';
|
|
5
|
+
import { _n, sprintf } from '@wordpress/i18n';
|
|
6
6
|
import { __experimentalHStack as HStack, __experimentalItem as Item, FlexItem } from '@wordpress/components';
|
|
7
7
|
import { useContext } from '@wordpress/element';
|
|
8
8
|
|
|
@@ -31,10 +31,9 @@ function FontFamilyItem({
|
|
|
31
31
|
}, createElement(FlexItem, {
|
|
32
32
|
style: previewStyle
|
|
33
33
|
}, font.name), createElement(FlexItem, {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, variantsCount, ' ', _n('variant', 'variants', variantsCount))));
|
|
34
|
+
className: "edit-site-global-styles-screen-typography__font-variants-count"
|
|
35
|
+
}, sprintf( /* translators: %d: Number of font variants. */
|
|
36
|
+
_n('%d variant', '%d variants', variantsCount), variantsCount))));
|
|
38
37
|
}
|
|
39
38
|
export default FontFamilyItem;
|
|
40
39
|
//# sourceMappingURL=font-family-item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_n","__experimentalHStack","HStack","__experimentalItem","Item","FlexItem","useContext","FontLibraryContext","getFamilyPreviewStyle","FontFamilyItem","font","handleSetLibraryFontSelected","toggleModal","variantsCount","fontFace","length","handleClick","previewStyle","createElement","onClick","justify","style","name","
|
|
1
|
+
{"version":3,"names":["_n","sprintf","__experimentalHStack","HStack","__experimentalItem","Item","FlexItem","useContext","FontLibraryContext","getFamilyPreviewStyle","FontFamilyItem","font","handleSetLibraryFontSelected","toggleModal","variantsCount","fontFace","length","handleClick","previewStyle","createElement","onClick","justify","style","name","className"],"sources":["@wordpress/edit-site/src/components/global-styles/font-family-item.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { _n, sprintf } from '@wordpress/i18n';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalItem as Item,\n\tFlexItem,\n} from '@wordpress/components';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { FontLibraryContext } from './font-library-modal/context';\nimport { getFamilyPreviewStyle } from './font-library-modal/utils/preview-styles';\n\nfunction FontFamilyItem( { font } ) {\n\tconst { handleSetLibraryFontSelected, toggleModal } =\n\t\tuseContext( FontLibraryContext );\n\n\tconst variantsCount = font?.fontFace?.length || 1;\n\n\tconst handleClick = () => {\n\t\thandleSetLibraryFontSelected( font );\n\t\ttoggleModal( 'installed-fonts' );\n\t};\n\n\tconst previewStyle = getFamilyPreviewStyle( font );\n\n\treturn (\n\t\t<Item onClick={ handleClick }>\n\t\t\t<HStack justify=\"space-between\">\n\t\t\t\t<FlexItem style={ previewStyle }>{ font.name }</FlexItem>\n\t\t\t\t<FlexItem className=\"edit-site-global-styles-screen-typography__font-variants-count\">\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t/* translators: %d: Number of font variants. */\n\t\t\t\t\t\t_n( '%d variant', '%d variants', variantsCount ),\n\t\t\t\t\t\tvariantsCount\n\t\t\t\t\t) }\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</Item>\n\t);\n}\n\nexport default FontFamilyItem;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,kBAAkB,IAAIC,IAAI,EAC1BC,QAAQ,QACF,uBAAuB;AAC9B,SAASC,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,qBAAqB,QAAQ,2CAA2C;AAEjF,SAASC,cAAcA,CAAE;EAAEC;AAAK,CAAC,EAAG;EACnC,MAAM;IAAEC,4BAA4B;IAAEC;EAAY,CAAC,GAClDN,UAAU,CAAEC,kBAAmB,CAAC;EAEjC,MAAMM,aAAa,GAAGH,IAAI,EAAEI,QAAQ,EAAEC,MAAM,IAAI,CAAC;EAEjD,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACzBL,4BAA4B,CAAED,IAAK,CAAC;IACpCE,WAAW,CAAE,iBAAkB,CAAC;EACjC,CAAC;EAED,MAAMK,YAAY,GAAGT,qBAAqB,CAAEE,IAAK,CAAC;EAElD,OACCQ,aAAA,CAACd,IAAI;IAACe,OAAO,EAAGH;EAAa,GAC5BE,aAAA,CAAChB,MAAM;IAACkB,OAAO,EAAC;EAAe,GAC9BF,aAAA,CAACb,QAAQ;IAACgB,KAAK,EAAGJ;EAAc,GAAGP,IAAI,CAACY,IAAgB,CAAC,EACzDJ,aAAA,CAACb,QAAQ;IAACkB,SAAS,EAAC;EAAgE,GACjFvB,OAAO,EACR;EACAD,EAAE,CAAE,YAAY,EAAE,aAAa,EAAEc,aAAc,CAAC,EAChDA,aACD,CACS,CACH,CACH,CAAC;AAET;AAEA,eAAeJ,cAAc"}
|
|
@@ -6,18 +6,18 @@ import { createContext, useState, useEffect } from '@wordpress/element';
|
|
|
6
6
|
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
7
7
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
8
|
import { useEntityRecord, useEntityRecords, store as coreStore } from '@wordpress/core-data';
|
|
9
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Internal dependencies
|
|
12
13
|
*/
|
|
13
|
-
import {
|
|
14
|
+
import { fetchGetFontFamilyBySlug, fetchInstallFontFamily, fetchUninstallFontFamily, fetchFontCollections, fetchFontCollection } from './resolvers';
|
|
14
15
|
import { unlock } from '../../../lock-unlock';
|
|
15
16
|
const {
|
|
16
17
|
useGlobalSetting
|
|
17
18
|
} = unlock(blockEditorPrivateApis);
|
|
18
|
-
import { setUIValuesNeeded, mergeFontFamilies, loadFontFaceInBrowser, getDisplaySrcFromFontFace,
|
|
19
|
+
import { setUIValuesNeeded, mergeFontFamilies, loadFontFaceInBrowser, getDisplaySrcFromFontFace, makeFontFacesFormData, makeFontFamilyFormData, batchInstallFontFaces, checkFontFaceInstalled } from './utils';
|
|
19
20
|
import { toggleFont } from './utils/toggleFont';
|
|
20
|
-
import getIntersectingFontFaces from './utils/get-intersecting-font-faces';
|
|
21
21
|
export const FontLibraryContext = createContext({});
|
|
22
22
|
function FontLibraryProvider({
|
|
23
23
|
children
|
|
@@ -47,9 +47,16 @@ function FontLibraryProvider({
|
|
|
47
47
|
isResolving: isResolvingLibrary,
|
|
48
48
|
hasResolved: hasResolvedLibrary
|
|
49
49
|
} = useEntityRecords('postType', 'wp_font_family', {
|
|
50
|
-
refreshKey
|
|
50
|
+
refreshKey,
|
|
51
|
+
_embed: true
|
|
51
52
|
});
|
|
52
|
-
const libraryFonts = (libraryPosts || []).map(
|
|
53
|
+
const libraryFonts = (libraryPosts || []).map(fontFamilyPost => {
|
|
54
|
+
return {
|
|
55
|
+
id: fontFamilyPost.id,
|
|
56
|
+
...fontFamilyPost.font_family_settings,
|
|
57
|
+
fontFace: fontFamilyPost?._embedded?.font_faces.map(face => face.font_face_settings) || []
|
|
58
|
+
};
|
|
59
|
+
}) || [];
|
|
53
60
|
|
|
54
61
|
// Global Styles (settings) font families
|
|
55
62
|
const [fontFamilies, setFontFamilies] = useGlobalSetting('typography.fontFamilies');
|
|
@@ -117,7 +124,7 @@ function FontLibraryProvider({
|
|
|
117
124
|
const themeUrl = site?.url + '/wp-content/themes/' + currentTheme?.stylesheet;
|
|
118
125
|
const getAvailableFontsOutline = availableFontFamilies => {
|
|
119
126
|
const outline = availableFontFamilies.reduce((acc, font) => {
|
|
120
|
-
const availableFontFaces =
|
|
127
|
+
const availableFontFaces = font?.fontFace && font.fontFace?.length > 0 ? font?.fontFace.map(face => `${face.fontStyle + face.fontWeight}`) : ['normal400']; // If the font doesn't have fontFace, we assume it is a system font and we add the defaults: normal 400
|
|
121
128
|
|
|
122
129
|
acc[font.slug] = availableFontFaces;
|
|
123
130
|
return acc;
|
|
@@ -142,50 +149,85 @@ function FontLibraryProvider({
|
|
|
142
149
|
const getFontFacesActivated = (slug, source) => {
|
|
143
150
|
return getActivatedFontsOutline(source)[slug] || [];
|
|
144
151
|
};
|
|
145
|
-
async function installFont(
|
|
152
|
+
async function installFont(fontFamilyToInstall) {
|
|
146
153
|
setIsInstalling(true);
|
|
147
154
|
try {
|
|
148
|
-
//
|
|
149
|
-
|
|
155
|
+
// Get the font family if it already exists.
|
|
156
|
+
let installedFontFamily = await fetchGetFontFamilyBySlug(fontFamilyToInstall.slug);
|
|
157
|
+
|
|
158
|
+
// Otherwise create it.
|
|
159
|
+
if (!installedFontFamily) {
|
|
160
|
+
// Prepare font family form data to install.
|
|
161
|
+
installedFontFamily = await fetchInstallFontFamily(makeFontFamilyFormData(fontFamilyToInstall));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Collect font faces that have already been installed (to be activated later)
|
|
165
|
+
const alreadyInstalledFontFaces = installedFontFamily.fontFace && fontFamilyToInstall.fontFace ? installedFontFamily.fontFace.filter(fontFaceToInstall => checkFontFaceInstalled(fontFaceToInstall, fontFamilyToInstall.fontFace)) : [];
|
|
166
|
+
|
|
167
|
+
// Filter out Font Faces that have already been installed (so that they are not re-installed)
|
|
168
|
+
if (installedFontFamily.fontFace && fontFamilyToInstall.fontFace) {
|
|
169
|
+
fontFamilyToInstall.fontFace = fontFamilyToInstall.fontFace.filter(fontFaceToInstall => !checkFontFaceInstalled(fontFaceToInstall, installedFontFamily.fontFace));
|
|
170
|
+
}
|
|
171
|
+
|
|
150
172
|
// Install the fonts (upload the font files to the server and create the post in the database).
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
173
|
+
let sucessfullyInstalledFontFaces = [];
|
|
174
|
+
let unsucessfullyInstalledFontFaces = [];
|
|
175
|
+
if (fontFamilyToInstall?.fontFace?.length > 0) {
|
|
176
|
+
const response = await batchInstallFontFaces(installedFontFamily.id, makeFontFacesFormData(fontFamilyToInstall));
|
|
177
|
+
sucessfullyInstalledFontFaces = response?.successes;
|
|
178
|
+
unsucessfullyInstalledFontFaces = response?.errors;
|
|
179
|
+
}
|
|
180
|
+
const detailedErrorMessage = unsucessfullyInstalledFontFaces.reduce((errorMessageCollection, error) => {
|
|
181
|
+
return `${errorMessageCollection} ${error.message}`;
|
|
182
|
+
}, '');
|
|
183
|
+
|
|
184
|
+
// If there were no successes and nothing already installed then we don't need to activate anything and can bounce now.
|
|
185
|
+
if (fontFamilyToInstall?.fontFace?.length > 0 && sucessfullyInstalledFontFaces.length === 0 && alreadyInstalledFontFaces.length === 0) {
|
|
186
|
+
throw new Error(sprintf( /* translators: %s: Specific error message returned from server. */
|
|
187
|
+
__('No font faces were installed. %s'), detailedErrorMessage));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Use the sucessfully installed font faces
|
|
191
|
+
// As well as any font faces that were already installed (those will be activated)
|
|
192
|
+
if (sucessfullyInstalledFontFaces?.length > 0 || alreadyInstalledFontFaces?.length > 0) {
|
|
193
|
+
fontFamilyToInstall.fontFace = [...sucessfullyInstalledFontFaces, ...alreadyInstalledFontFaces];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Activate the font family (add the font family to the global styles).
|
|
197
|
+
activateCustomFontFamilies([fontFamilyToInstall]);
|
|
198
|
+
|
|
158
199
|
// Save the global styles to the database.
|
|
159
200
|
saveSpecifiedEntityEdits('root', 'globalStyles', globalStylesId, ['settings.typography.fontFamilies']);
|
|
160
201
|
refreshLibrary();
|
|
202
|
+
if (unsucessfullyInstalledFontFaces.length > 0) {
|
|
203
|
+
throw new Error(sprintf( /* translators: %s: Specific error message returned from server. */
|
|
204
|
+
__('Some font faces were installed. There were some errors. %s'), detailedErrorMessage));
|
|
205
|
+
}
|
|
206
|
+
} finally {
|
|
161
207
|
setIsInstalling(false);
|
|
162
|
-
return response;
|
|
163
|
-
} catch (error) {
|
|
164
|
-
setIsInstalling(false);
|
|
165
|
-
return {
|
|
166
|
-
errors: [error]
|
|
167
|
-
};
|
|
168
208
|
}
|
|
169
209
|
}
|
|
170
|
-
async function
|
|
210
|
+
async function uninstallFontFamily(fontFamilyToUninstall) {
|
|
171
211
|
try {
|
|
172
|
-
// Uninstall the font
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
212
|
+
// Uninstall the font family.
|
|
213
|
+
// (Removes the font files from the server and the posts from the database).
|
|
214
|
+
const uninstalledFontFamily = await fetchUninstallFontFamily(fontFamilyToUninstall.id);
|
|
215
|
+
|
|
216
|
+
// Deactivate the font family if delete request is successful
|
|
217
|
+
// (Removes the font family from the global styles).
|
|
218
|
+
if (uninstalledFontFamily.deleted) {
|
|
219
|
+
deactivateFontFamily(fontFamilyToUninstall);
|
|
177
220
|
// Save the global styles to the database.
|
|
178
221
|
await saveSpecifiedEntityEdits('root', 'globalStyles', globalStylesId, ['settings.typography.fontFamilies']);
|
|
179
222
|
}
|
|
180
|
-
|
|
223
|
+
|
|
224
|
+
// Refresh the library (the library font families from database).
|
|
181
225
|
refreshLibrary();
|
|
182
|
-
return
|
|
226
|
+
return uninstalledFontFamily;
|
|
183
227
|
} catch (error) {
|
|
184
228
|
// eslint-disable-next-line no-console
|
|
185
|
-
console.error(error);
|
|
186
|
-
|
|
187
|
-
errors: [error]
|
|
188
|
-
};
|
|
229
|
+
console.error(`There was an error uninstalling the font family:`, error);
|
|
230
|
+
throw error;
|
|
189
231
|
}
|
|
190
232
|
}
|
|
191
233
|
const deactivateFontFamily = font => {
|
|
@@ -249,16 +291,14 @@ function FontLibraryProvider({
|
|
|
249
291
|
const response = await fetchFontCollections();
|
|
250
292
|
setFontCollections(response);
|
|
251
293
|
};
|
|
252
|
-
const getFontCollection = async
|
|
294
|
+
const getFontCollection = async slug => {
|
|
253
295
|
try {
|
|
254
|
-
const hasData = !!collections.find(collection => collection.
|
|
296
|
+
const hasData = !!collections.find(collection => collection.slug === slug)?.font_families;
|
|
255
297
|
if (hasData) return;
|
|
256
|
-
const response = await fetchFontCollection(
|
|
257
|
-
const updatedCollections = collections.map(collection => collection.
|
|
298
|
+
const response = await fetchFontCollection(slug);
|
|
299
|
+
const updatedCollections = collections.map(collection => collection.slug === slug ? {
|
|
258
300
|
...collection,
|
|
259
|
-
|
|
260
|
-
...response?.data
|
|
261
|
-
}
|
|
301
|
+
...response
|
|
262
302
|
} : collection);
|
|
263
303
|
setFontCollections(updatedCollections);
|
|
264
304
|
} catch (e) {
|
|
@@ -282,7 +322,7 @@ function FontLibraryProvider({
|
|
|
282
322
|
getFontFacesActivated,
|
|
283
323
|
loadFontFaceAsset,
|
|
284
324
|
installFont,
|
|
285
|
-
|
|
325
|
+
uninstallFontFamily,
|
|
286
326
|
toggleActivateFont,
|
|
287
327
|
getAvailableFontsOutline,
|
|
288
328
|
modalTabOpen,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useState","useEffect","privateApis","blockEditorPrivateApis","useSelect","useDispatch","useEntityRecord","useEntityRecords","store","coreStore","fetchInstallFont","fetchUninstallFonts","fetchFontCollections","fetchFontCollection","unlock","useGlobalSetting","setUIValuesNeeded","mergeFontFamilies","loadFontFaceInBrowser","getDisplaySrcFromFontFace","makeFormDataFromFontFamily","toggleFont","getIntersectingFontFaces","FontLibraryContext","FontLibraryProvider","children","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","globalStylesId","select","__experimentalGetCurrentGlobalStylesId","globalStyles","fontFamiliesHasChanges","edits","settings","typography","fontFamilies","isInstalling","setIsInstalling","refreshKey","setRefreshKey","refreshLibrary","Date","now","records","libraryPosts","isResolving","isResolvingLibrary","hasResolved","hasResolvedLibrary","libraryFonts","map","post","JSON","parse","content","raw","setFontFamilies","baseFontFamilies","undefined","saveFontFamilies","modalTabOpen","setModalTabOpen","libraryFontSelected","setLibraryFontSelected","baseThemeFonts","theme","f","source","sort","a","b","name","localeCompare","themeFonts","customFonts","custom","baseCustomFonts","handleSetLibraryFontSelected","font","fonts","fontSelected","find","slug","toggleModal","tabName","loadedFontUrls","Set","site","currentTheme","getSite","getCurrentTheme","themeUrl","url","stylesheet","getAvailableFontsOutline","availableFontFamilies","outline","reduce","acc","availableFontFaces","Array","isArray","fontFace","face","fontStyle","fontWeight","getActivatedFontsOutline","isFontActivated","style","weight","includes","getFontFacesActivated","installFont","formData","response","fontsInstalled","successes","fontToBeActivated","activateCustomFontFamilies","error","errors","uninstallFont","length","deactivateFontFamily","console","_fontFamilies$font$so","initialCustomFonts","newCustomFonts","filter","fontsToAdd","forEach","src","toggleActivateFont","_fontFamilies$font$so2","initialFonts","newFonts","loadFontFaceAsset","has","add","collections","setFontCollections","getFontCollections","getFontCollection","id","hasData","collection","data","updatedCollections","e","createElement","Provider","value"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useState, useEffect } from '@wordpress/element';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseEntityRecord,\n\tuseEntityRecords,\n\tstore as coreStore,\n} from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfetchInstallFont,\n\tfetchUninstallFonts,\n\tfetchFontCollections,\n\tfetchFontCollection,\n} from './resolvers';\nimport { unlock } from '../../../lock-unlock';\nconst { useGlobalSetting } = unlock( blockEditorPrivateApis );\nimport {\n\tsetUIValuesNeeded,\n\tmergeFontFamilies,\n\tloadFontFaceInBrowser,\n\tgetDisplaySrcFromFontFace,\n\tmakeFormDataFromFontFamily,\n} from './utils';\nimport { toggleFont } from './utils/toggleFont';\nimport getIntersectingFontFaces from './utils/get-intersecting-font-faces';\n\nexport const FontLibraryContext = createContext( {} );\n\nfunction FontLibraryProvider( { children } ) {\n\tconst { __experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits } =\n\t\tuseDispatch( coreStore );\n\tconst { globalStylesId } = useSelect( ( select ) => {\n\t\tconst { __experimentalGetCurrentGlobalStylesId } = select( coreStore );\n\t\treturn { globalStylesId: __experimentalGetCurrentGlobalStylesId() };\n\t} );\n\n\tconst globalStyles = useEntityRecord(\n\t\t'root',\n\t\t'globalStyles',\n\t\tglobalStylesId\n\t);\n\tconst fontFamiliesHasChanges =\n\t\t!! globalStyles?.edits?.settings?.typography?.fontFamilies;\n\n\tconst [ isInstalling, setIsInstalling ] = useState( false );\n\tconst [ refreshKey, setRefreshKey ] = useState( 0 );\n\n\tconst refreshLibrary = () => {\n\t\tsetRefreshKey( Date.now() );\n\t};\n\n\tconst {\n\t\trecords: libraryPosts = [],\n\t\tisResolving: isResolvingLibrary,\n\t\thasResolved: hasResolvedLibrary,\n\t} = useEntityRecords( 'postType', 'wp_font_family', { refreshKey } );\n\n\tconst libraryFonts =\n\t\t( libraryPosts || [] ).map( ( post ) =>\n\t\t\tJSON.parse( post.content.raw )\n\t\t) || [];\n\n\t// Global Styles (settings) font families\n\tconst [ fontFamilies, setFontFamilies ] = useGlobalSetting(\n\t\t'typography.fontFamilies'\n\t);\n\t// theme.json file font families\n\tconst [ baseFontFamilies ] = useGlobalSetting(\n\t\t'typography.fontFamilies',\n\t\tundefined,\n\t\t'base'\n\t);\n\n\t// Save font families to the global styles post in the database.\n\tconst saveFontFamilies = () => {\n\t\tsaveSpecifiedEntityEdits( 'root', 'globalStyles', globalStylesId, [\n\t\t\t'settings.typography.fontFamilies',\n\t\t] );\n\t};\n\n\t// Library Fonts\n\tconst [ modalTabOpen, setModalTabOpen ] = useState( false );\n\tconst [ libraryFontSelected, setLibraryFontSelected ] = useState( null );\n\n\tconst baseThemeFonts = baseFontFamilies?.theme\n\t\t? baseFontFamilies.theme\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'theme' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst themeFonts = fontFamilies?.theme\n\t\t? fontFamilies.theme\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'theme' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst customFonts = fontFamilies?.custom\n\t\t? fontFamilies.custom\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'custom' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst baseCustomFonts = libraryFonts\n\t\t? libraryFonts\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'custom' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tuseEffect( () => {\n\t\tif ( ! modalTabOpen ) {\n\t\t\tsetLibraryFontSelected( null );\n\t\t}\n\t}, [ modalTabOpen ] );\n\n\tconst handleSetLibraryFontSelected = ( font ) => {\n\t\t// If font is null, reset the selected font\n\t\tif ( ! font ) {\n\t\t\tsetLibraryFontSelected( null );\n\t\t\treturn;\n\t\t}\n\n\t\tconst fonts =\n\t\t\tfont.source === 'theme' ? baseThemeFonts : baseCustomFonts;\n\n\t\t// Tries to find the font in the installed fonts\n\t\tconst fontSelected = fonts.find( ( f ) => f.slug === font.slug );\n\t\t// If the font is not found (it is only defined in custom styles), use the font from custom styles\n\t\tsetLibraryFontSelected( {\n\t\t\t...( fontSelected || font ),\n\t\t\tsource: font.source,\n\t\t} );\n\t};\n\n\tconst toggleModal = ( tabName ) => {\n\t\tsetModalTabOpen( tabName || null );\n\t};\n\n\t// Demo\n\tconst [ loadedFontUrls ] = useState( new Set() );\n\n\t// Theme data\n\tconst { site, currentTheme } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tsite: select( coreStore ).getSite(),\n\t\t\tcurrentTheme: select( coreStore ).getCurrentTheme(),\n\t\t};\n\t} );\n\tconst themeUrl =\n\t\tsite?.url + '/wp-content/themes/' + currentTheme?.stylesheet;\n\n\tconst getAvailableFontsOutline = ( availableFontFamilies ) => {\n\t\tconst outline = availableFontFamilies.reduce( ( acc, font ) => {\n\t\t\tconst availableFontFaces = Array.isArray( font?.fontFace )\n\t\t\t\t? font?.fontFace.map(\n\t\t\t\t\t\t( face ) => `${ face.fontStyle + face.fontWeight }`\n\t\t\t\t )\n\t\t\t\t: [ 'normal400' ]; // If the font doesn't have fontFace, we assume it is a system font and we add the defaults: normal 400\n\n\t\t\tacc[ font.slug ] = availableFontFaces;\n\t\t\treturn acc;\n\t\t}, {} );\n\t\treturn outline;\n\t};\n\n\tconst getActivatedFontsOutline = ( source ) => {\n\t\tswitch ( source ) {\n\t\t\tcase 'theme':\n\t\t\t\treturn getAvailableFontsOutline( themeFonts );\n\t\t\tcase 'custom':\n\t\t\tdefault:\n\t\t\t\treturn getAvailableFontsOutline( customFonts );\n\t\t}\n\t};\n\n\tconst isFontActivated = ( slug, style, weight, source ) => {\n\t\tif ( ! style && ! weight ) {\n\t\t\treturn !! getActivatedFontsOutline( source )[ slug ];\n\t\t}\n\t\treturn !! getActivatedFontsOutline( source )[ slug ]?.includes(\n\t\t\tstyle + weight\n\t\t);\n\t};\n\n\tconst getFontFacesActivated = ( slug, source ) => {\n\t\treturn getActivatedFontsOutline( source )[ slug ] || [];\n\t};\n\n\tasync function installFont( font ) {\n\t\tsetIsInstalling( true );\n\t\ttry {\n\t\t\t// Prepare formData to install.\n\t\t\tconst formData = makeFormDataFromFontFamily( font );\n\t\t\t// Install the fonts (upload the font files to the server and create the post in the database).\n\t\t\tconst response = await fetchInstallFont( formData );\n\t\t\tconst fontsInstalled = response?.successes || [];\n\t\t\t// Get intersecting font faces between the fonts we tried to installed and the fonts that were installed\n\t\t\t// (to avoid activating a non installed font).\n\t\t\tconst fontToBeActivated = getIntersectingFontFaces(\n\t\t\t\tfontsInstalled,\n\t\t\t\t[ font ]\n\t\t\t);\n\t\t\t// Activate the font families (add the font families to the global styles).\n\t\t\tactivateCustomFontFamilies( fontToBeActivated );\n\t\t\t// Save the global styles to the database.\n\t\t\tsaveSpecifiedEntityEdits( 'root', 'globalStyles', globalStylesId, [\n\t\t\t\t'settings.typography.fontFamilies',\n\t\t\t] );\n\t\t\trefreshLibrary();\n\t\t\tsetIsInstalling( false );\n\n\t\t\treturn response;\n\t\t} catch ( error ) {\n\t\t\tsetIsInstalling( false );\n\t\t\treturn {\n\t\t\t\terrors: [ error ],\n\t\t\t};\n\t\t}\n\t}\n\n\tasync function uninstallFont( font ) {\n\t\ttry {\n\t\t\t// Uninstall the font (remove the font files from the server and the post from the database).\n\t\t\tconst response = await fetchUninstallFonts( [ font ] );\n\t\t\t// Deactivate the font family (remove the font family from the global styles).\n\t\t\tif ( 0 === response.errors.length ) {\n\t\t\t\tdeactivateFontFamily( font );\n\t\t\t\t// Save the global styles to the database.\n\t\t\t\tawait saveSpecifiedEntityEdits(\n\t\t\t\t\t'root',\n\t\t\t\t\t'globalStyles',\n\t\t\t\t\tglobalStylesId,\n\t\t\t\t\t[ 'settings.typography.fontFamilies' ]\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Refresh the library (the the library font families from database).\n\t\t\trefreshLibrary();\n\t\t\treturn response;\n\t\t} catch ( error ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( error );\n\t\t\treturn {\n\t\t\t\terrors: [ error ],\n\t\t\t};\n\t\t}\n\t}\n\n\tconst deactivateFontFamily = ( font ) => {\n\t\t// If the user doesn't have custom fonts defined, include as custom fonts all the theme fonts\n\t\t// We want to save as active all the theme fonts at the beginning\n\t\tconst initialCustomFonts = fontFamilies?.[ font.source ] ?? [];\n\t\tconst newCustomFonts = initialCustomFonts.filter(\n\t\t\t( f ) => f.slug !== font.slug\n\t\t);\n\t\tsetFontFamilies( {\n\t\t\t...fontFamilies,\n\t\t\t[ font.source ]: newCustomFonts,\n\t\t} );\n\t};\n\n\tconst activateCustomFontFamilies = ( fontsToAdd ) => {\n\t\t// Merge the existing custom fonts with the new fonts.\n\t\tconst newCustomFonts = mergeFontFamilies(\n\t\t\tfontFamilies?.custom,\n\t\t\tfontsToAdd\n\t\t);\n\t\t// Activate the fonts by set the new custom fonts array.\n\t\tsetFontFamilies( {\n\t\t\t...fontFamilies,\n\t\t\tcustom: newCustomFonts,\n\t\t} );\n\t\t// Add custom fonts to the browser.\n\t\tfontsToAdd.forEach( ( font ) => {\n\t\t\tif ( font.fontFace ) {\n\t\t\t\tfont.fontFace.forEach( ( face ) => {\n\t\t\t\t\t// Load font faces just in the iframe because they already are in the document.\n\t\t\t\t\tloadFontFaceInBrowser(\n\t\t\t\t\t\tface,\n\t\t\t\t\t\tgetDisplaySrcFromFontFace( face.src ),\n\t\t\t\t\t\t'iframe'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t};\n\n\tconst toggleActivateFont = ( font, face ) => {\n\t\t// If the user doesn't have custom fonts defined, include as custom fonts all the theme fonts\n\t\t// We want to save as active all the theme fonts at the beginning\n\t\tconst initialFonts = fontFamilies?.[ font.source ] ?? [];\n\t\t// Toggles the received font family or font face\n\t\tconst newFonts = toggleFont( font, face, initialFonts );\n\t\t// Updates the font families activated in global settings:\n\t\tsetFontFamilies( {\n\t\t\t...fontFamilies,\n\t\t\t[ font.source ]: newFonts,\n\t\t} );\n\t};\n\n\tconst loadFontFaceAsset = async ( fontFace ) => {\n\t\t// If the font doesn't have a src, don't load it.\n\t\tif ( ! fontFace.src ) return;\n\t\t// Get the src of the font.\n\t\tconst src = getDisplaySrcFromFontFace( fontFace.src, themeUrl );\n\t\t// If the font is already loaded, don't load it again.\n\t\tif ( ! src || loadedFontUrls.has( src ) ) return;\n\t\t// Load the font in the browser.\n\t\tloadFontFaceInBrowser( fontFace, src, 'document' );\n\t\t// Add the font to the loaded fonts list.\n\t\tloadedFontUrls.add( src );\n\t};\n\n\t// Font Collections\n\tconst [ collections, setFontCollections ] = useState( [] );\n\tconst getFontCollections = async () => {\n\t\tconst response = await fetchFontCollections();\n\t\tsetFontCollections( response );\n\t};\n\tconst getFontCollection = async ( id ) => {\n\t\ttry {\n\t\t\tconst hasData = !! collections.find(\n\t\t\t\t( collection ) => collection.id === id\n\t\t\t)?.data;\n\t\t\tif ( hasData ) return;\n\t\t\tconst response = await fetchFontCollection( id );\n\t\t\tconst updatedCollections = collections.map( ( collection ) =>\n\t\t\t\tcollection.id === id\n\t\t\t\t\t? { ...collection, data: { ...response?.data } }\n\t\t\t\t\t: collection\n\t\t\t);\n\t\t\tsetFontCollections( updatedCollections );\n\t\t} catch ( e ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( e );\n\t\t\tthrow e;\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tgetFontCollections();\n\t}, [] );\n\n\treturn (\n\t\t<FontLibraryContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tlibraryFontSelected,\n\t\t\t\thandleSetLibraryFontSelected,\n\t\t\t\tthemeFonts,\n\t\t\t\tbaseThemeFonts,\n\t\t\t\tcustomFonts,\n\t\t\t\tbaseCustomFonts,\n\t\t\t\tisFontActivated,\n\t\t\t\tgetFontFacesActivated,\n\t\t\t\tloadFontFaceAsset,\n\t\t\t\tinstallFont,\n\t\t\t\tuninstallFont,\n\t\t\t\ttoggleActivateFont,\n\t\t\t\tgetAvailableFontsOutline,\n\t\t\t\tmodalTabOpen,\n\t\t\t\ttoggleModal,\n\t\t\t\trefreshLibrary,\n\t\t\t\tsaveFontFamilies,\n\t\t\t\tfontFamiliesHasChanges,\n\t\t\t\tisResolvingLibrary,\n\t\t\t\thasResolvedLibrary,\n\t\t\t\tisInstalling,\n\t\t\t\tcollections,\n\t\t\t\tgetFontCollection,\n\t\t\t} }\n\t\t>\n\t\t\t{ children }\n\t\t</FontLibraryContext.Provider>\n\t);\n}\n\nexport default FontLibraryProvider;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACvE,SAASC,WAAW,IAAIC,sBAAsB,QAAQ,yBAAyB;AAC/E,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SACCC,eAAe,EACfC,gBAAgB,EAChBC,KAAK,IAAIC,SAAS,QACZ,sBAAsB;;AAE7B;AACA;AACA;AACA,SACCC,gBAAgB,EAChBC,mBAAmB,EACnBC,oBAAoB,EACpBC,mBAAmB,QACb,aAAa;AACpB,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,MAAM;EAAEC;AAAiB,CAAC,GAAGD,MAAM,CAAEX,sBAAuB,CAAC;AAC7D,SACCa,iBAAiB,EACjBC,iBAAiB,EACjBC,qBAAqB,EACrBC,yBAAyB,EACzBC,0BAA0B,QACpB,SAAS;AAChB,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,OAAOC,wBAAwB,MAAM,qCAAqC;AAE1E,OAAO,MAAMC,kBAAkB,GAAGxB,aAAa,CAAE,CAAC,CAAE,CAAC;AAErD,SAASyB,mBAAmBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC5C,MAAM;IAAEC,sCAAsC,EAAEC;EAAyB,CAAC,GACzEtB,WAAW,CAAEI,SAAU,CAAC;EACzB,MAAM;IAAEmB;EAAe,CAAC,GAAGxB,SAAS,CAAIyB,MAAM,IAAM;IACnD,MAAM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AMI,kBAAkB,GAAGR,WAAW,CAACzF,GAAG,CAAI+F,UAAU,IACvDA,UAAU,CAACF,EAAE,KAAKA,EAAE,GACjB;QAAE,GAAGE,UAAU;QAAEC,IAAI,EAAE;UAAE,GAAGhC,QAAQ,EAAEgC;QAAK;MAAE,CAAC,GAC9CD,UACJ,CAAC;MACDL,kBAAkB,CAAEO,kBAAmB,CAAC;IACzC,CAAC,CAAC,OAAQC,CAAC,EAAG;MACb;MACAxB,OAAO,CAACL,KAAK,CAAE6B,CAAE,CAAC;MAClB,MAAMA,CAAC;IACR;EACD,CAAC;EAEDpJ,SAAS,CAAE,MAAM;IAChB6I,kBAAkB,CAAC,CAAC;EACrB,CAAC,EAAE,EAAG,CAAC;EAEP,OACCQ,aAAA,CAAC/H,kBAAkB,CAACgI,QAAQ;IAC3BC,KAAK,EAAG;MACPzF,mBAAmB;MACnBe,4BAA4B;MAC5BJ,UAAU;MACVT,cAAc;MACdU,WAAW;MACXE,eAAe;MACf+B,eAAe;MACfI,qBAAqB;MACrByB,iBAAiB;MACjBxB,WAAW;MACXS,aAAa;MACbW,kBAAkB;MAClBtC,wBAAwB;MACxBlC,YAAY;MACZuB,WAAW;MACX3C,cAAc;MACdmB,gBAAgB;MAChB5B,sBAAsB;MACtBe,kBAAkB;MAClBE,kBAAkB;MAClBZ,YAAY;MACZuG,WAAW;MACXG;IACD;EAAG,GAEDtH,QAC0B,CAAC;AAEhC;AAEA,eAAeD,mBAAmB"}
|
|
1
|
+
{"version":3,"names":["createContext","useState","useEffect","privateApis","blockEditorPrivateApis","useSelect","useDispatch","useEntityRecord","useEntityRecords","store","coreStore","__","sprintf","fetchGetFontFamilyBySlug","fetchInstallFontFamily","fetchUninstallFontFamily","fetchFontCollections","fetchFontCollection","unlock","useGlobalSetting","setUIValuesNeeded","mergeFontFamilies","loadFontFaceInBrowser","getDisplaySrcFromFontFace","makeFontFacesFormData","makeFontFamilyFormData","batchInstallFontFaces","checkFontFaceInstalled","toggleFont","FontLibraryContext","FontLibraryProvider","children","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","globalStylesId","select","__experimentalGetCurrentGlobalStylesId","globalStyles","fontFamiliesHasChanges","edits","settings","typography","fontFamilies","isInstalling","setIsInstalling","refreshKey","setRefreshKey","refreshLibrary","Date","now","records","libraryPosts","isResolving","isResolvingLibrary","hasResolved","hasResolvedLibrary","_embed","libraryFonts","map","fontFamilyPost","id","font_family_settings","fontFace","_embedded","font_faces","face","font_face_settings","setFontFamilies","baseFontFamilies","undefined","saveFontFamilies","modalTabOpen","setModalTabOpen","libraryFontSelected","setLibraryFontSelected","baseThemeFonts","theme","f","source","sort","a","b","name","localeCompare","themeFonts","customFonts","custom","baseCustomFonts","handleSetLibraryFontSelected","font","fonts","fontSelected","find","slug","toggleModal","tabName","loadedFontUrls","Set","site","currentTheme","getSite","getCurrentTheme","themeUrl","url","stylesheet","getAvailableFontsOutline","availableFontFamilies","outline","reduce","acc","availableFontFaces","length","fontStyle","fontWeight","getActivatedFontsOutline","isFontActivated","style","weight","includes","getFontFacesActivated","installFont","fontFamilyToInstall","installedFontFamily","alreadyInstalledFontFaces","filter","fontFaceToInstall","sucessfullyInstalledFontFaces","unsucessfullyInstalledFontFaces","response","successes","errors","detailedErrorMessage","errorMessageCollection","error","message","Error","activateCustomFontFamilies","uninstallFontFamily","fontFamilyToUninstall","uninstalledFontFamily","deleted","deactivateFontFamily","console","_fontFamilies$font$so","initialCustomFonts","newCustomFonts","fontsToAdd","forEach","src","toggleActivateFont","_fontFamilies$font$so2","initialFonts","newFonts","loadFontFaceAsset","has","add","collections","setFontCollections","getFontCollections","getFontCollection","hasData","collection","font_families","updatedCollections","e","createElement","Provider","value"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useState, useEffect } from '@wordpress/element';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseEntityRecord,\n\tuseEntityRecords,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfetchGetFontFamilyBySlug,\n\tfetchInstallFontFamily,\n\tfetchUninstallFontFamily,\n\tfetchFontCollections,\n\tfetchFontCollection,\n} from './resolvers';\nimport { unlock } from '../../../lock-unlock';\nconst { useGlobalSetting } = unlock( blockEditorPrivateApis );\nimport {\n\tsetUIValuesNeeded,\n\tmergeFontFamilies,\n\tloadFontFaceInBrowser,\n\tgetDisplaySrcFromFontFace,\n\tmakeFontFacesFormData,\n\tmakeFontFamilyFormData,\n\tbatchInstallFontFaces,\n\tcheckFontFaceInstalled,\n} from './utils';\nimport { toggleFont } from './utils/toggleFont';\n\nexport const FontLibraryContext = createContext( {} );\n\nfunction FontLibraryProvider( { children } ) {\n\tconst { __experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits } =\n\t\tuseDispatch( coreStore );\n\tconst { globalStylesId } = useSelect( ( select ) => {\n\t\tconst { __experimentalGetCurrentGlobalStylesId } = select( coreStore );\n\t\treturn { globalStylesId: __experimentalGetCurrentGlobalStylesId() };\n\t} );\n\n\tconst globalStyles = useEntityRecord(\n\t\t'root',\n\t\t'globalStyles',\n\t\tglobalStylesId\n\t);\n\tconst fontFamiliesHasChanges =\n\t\t!! globalStyles?.edits?.settings?.typography?.fontFamilies;\n\n\tconst [ isInstalling, setIsInstalling ] = useState( false );\n\tconst [ refreshKey, setRefreshKey ] = useState( 0 );\n\n\tconst refreshLibrary = () => {\n\t\tsetRefreshKey( Date.now() );\n\t};\n\n\tconst {\n\t\trecords: libraryPosts = [],\n\t\tisResolving: isResolvingLibrary,\n\t\thasResolved: hasResolvedLibrary,\n\t} = useEntityRecords( 'postType', 'wp_font_family', {\n\t\trefreshKey,\n\t\t_embed: true,\n\t} );\n\n\tconst libraryFonts =\n\t\t( libraryPosts || [] ).map( ( fontFamilyPost ) => {\n\t\t\treturn {\n\t\t\t\tid: fontFamilyPost.id,\n\t\t\t\t...fontFamilyPost.font_family_settings,\n\t\t\t\tfontFace:\n\t\t\t\t\tfontFamilyPost?._embedded?.font_faces.map(\n\t\t\t\t\t\t( face ) => face.font_face_settings\n\t\t\t\t\t) || [],\n\t\t\t};\n\t\t} ) || [];\n\n\t// Global Styles (settings) font families\n\tconst [ fontFamilies, setFontFamilies ] = useGlobalSetting(\n\t\t'typography.fontFamilies'\n\t);\n\t// theme.json file font families\n\tconst [ baseFontFamilies ] = useGlobalSetting(\n\t\t'typography.fontFamilies',\n\t\tundefined,\n\t\t'base'\n\t);\n\n\t// Save font families to the global styles post in the database.\n\tconst saveFontFamilies = () => {\n\t\tsaveSpecifiedEntityEdits( 'root', 'globalStyles', globalStylesId, [\n\t\t\t'settings.typography.fontFamilies',\n\t\t] );\n\t};\n\n\t// Library Fonts\n\tconst [ modalTabOpen, setModalTabOpen ] = useState( false );\n\tconst [ libraryFontSelected, setLibraryFontSelected ] = useState( null );\n\n\tconst baseThemeFonts = baseFontFamilies?.theme\n\t\t? baseFontFamilies.theme\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'theme' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst themeFonts = fontFamilies?.theme\n\t\t? fontFamilies.theme\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'theme' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst customFonts = fontFamilies?.custom\n\t\t? fontFamilies.custom\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'custom' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tconst baseCustomFonts = libraryFonts\n\t\t? libraryFonts\n\t\t\t\t.map( ( f ) => setUIValuesNeeded( f, { source: 'custom' } ) )\n\t\t\t\t.sort( ( a, b ) => a.name.localeCompare( b.name ) )\n\t\t: [];\n\n\tuseEffect( () => {\n\t\tif ( ! modalTabOpen ) {\n\t\t\tsetLibraryFontSelected( null );\n\t\t}\n\t}, [ modalTabOpen ] );\n\n\tconst handleSetLibraryFontSelected = ( font ) => {\n\t\t// If font is null, reset the selected font\n\t\tif ( ! font ) {\n\t\t\tsetLibraryFontSelected( null );\n\t\t\treturn;\n\t\t}\n\n\t\tconst fonts =\n\t\t\tfont.source === 'theme' ? baseThemeFonts : baseCustomFonts;\n\n\t\t// Tries to find the font in the installed fonts\n\t\tconst fontSelected = fonts.find( ( f ) => f.slug === font.slug );\n\t\t// If the font is not found (it is only defined in custom styles), use the font from custom styles\n\t\tsetLibraryFontSelected( {\n\t\t\t...( fontSelected || font ),\n\t\t\tsource: font.source,\n\t\t} );\n\t};\n\n\tconst toggleModal = ( tabName ) => {\n\t\tsetModalTabOpen( tabName || null );\n\t};\n\n\t// Demo\n\tconst [ loadedFontUrls ] = useState( new Set() );\n\n\t// Theme data\n\tconst { site, currentTheme } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tsite: select( coreStore ).getSite(),\n\t\t\tcurrentTheme: select( coreStore ).getCurrentTheme(),\n\t\t};\n\t} );\n\tconst themeUrl =\n\t\tsite?.url + '/wp-content/themes/' + currentTheme?.stylesheet;\n\n\tconst getAvailableFontsOutline = ( availableFontFamilies ) => {\n\t\tconst outline = availableFontFamilies.reduce( ( acc, font ) => {\n\t\t\tconst availableFontFaces =\n\t\t\t\tfont?.fontFace && font.fontFace?.length > 0\n\t\t\t\t\t? font?.fontFace.map(\n\t\t\t\t\t\t\t( face ) => `${ face.fontStyle + face.fontWeight }`\n\t\t\t\t\t )\n\t\t\t\t\t: [ 'normal400' ]; // If the font doesn't have fontFace, we assume it is a system font and we add the defaults: normal 400\n\n\t\t\tacc[ font.slug ] = availableFontFaces;\n\t\t\treturn acc;\n\t\t}, {} );\n\t\treturn outline;\n\t};\n\n\tconst getActivatedFontsOutline = ( source ) => {\n\t\tswitch ( source ) {\n\t\t\tcase 'theme':\n\t\t\t\treturn getAvailableFontsOutline( themeFonts );\n\t\t\tcase 'custom':\n\t\t\tdefault:\n\t\t\t\treturn getAvailableFontsOutline( customFonts );\n\t\t}\n\t};\n\n\tconst isFontActivated = ( slug, style, weight, source ) => {\n\t\tif ( ! style && ! weight ) {\n\t\t\treturn !! getActivatedFontsOutline( source )[ slug ];\n\t\t}\n\t\treturn !! getActivatedFontsOutline( source )[ slug ]?.includes(\n\t\t\tstyle + weight\n\t\t);\n\t};\n\n\tconst getFontFacesActivated = ( slug, source ) => {\n\t\treturn getActivatedFontsOutline( source )[ slug ] || [];\n\t};\n\n\tasync function installFont( fontFamilyToInstall ) {\n\t\tsetIsInstalling( true );\n\t\ttry {\n\t\t\t// Get the font family if it already exists.\n\t\t\tlet installedFontFamily = await fetchGetFontFamilyBySlug(\n\t\t\t\tfontFamilyToInstall.slug\n\t\t\t);\n\n\t\t\t// Otherwise create it.\n\t\t\tif ( ! installedFontFamily ) {\n\t\t\t\t// Prepare font family form data to install.\n\t\t\t\tinstalledFontFamily = await fetchInstallFontFamily(\n\t\t\t\t\tmakeFontFamilyFormData( fontFamilyToInstall )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Collect font faces that have already been installed (to be activated later)\n\t\t\tconst alreadyInstalledFontFaces =\n\t\t\t\tinstalledFontFamily.fontFace && fontFamilyToInstall.fontFace\n\t\t\t\t\t? installedFontFamily.fontFace.filter(\n\t\t\t\t\t\t\t( fontFaceToInstall ) =>\n\t\t\t\t\t\t\t\tcheckFontFaceInstalled(\n\t\t\t\t\t\t\t\t\tfontFaceToInstall,\n\t\t\t\t\t\t\t\t\tfontFamilyToInstall.fontFace\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t )\n\t\t\t\t\t: [];\n\n\t\t\t// Filter out Font Faces that have already been installed (so that they are not re-installed)\n\t\t\tif (\n\t\t\t\tinstalledFontFamily.fontFace &&\n\t\t\t\tfontFamilyToInstall.fontFace\n\t\t\t) {\n\t\t\t\tfontFamilyToInstall.fontFace =\n\t\t\t\t\tfontFamilyToInstall.fontFace.filter(\n\t\t\t\t\t\t( fontFaceToInstall ) =>\n\t\t\t\t\t\t\t! checkFontFaceInstalled(\n\t\t\t\t\t\t\t\tfontFaceToInstall,\n\t\t\t\t\t\t\t\tinstalledFontFamily.fontFace\n\t\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Install the fonts (upload the font files to the server and create the post in the database).\n\t\t\tlet sucessfullyInstalledFontFaces = [];\n\t\t\tlet unsucessfullyInstalledFontFaces = [];\n\t\t\tif ( fontFamilyToInstall?.fontFace?.length > 0 ) {\n\t\t\t\tconst response = await batchInstallFontFaces(\n\t\t\t\t\tinstalledFontFamily.id,\n\t\t\t\t\tmakeFontFacesFormData( fontFamilyToInstall )\n\t\t\t\t);\n\t\t\t\tsucessfullyInstalledFontFaces = response?.successes;\n\t\t\t\tunsucessfullyInstalledFontFaces = response?.errors;\n\t\t\t}\n\n\t\t\tconst detailedErrorMessage = unsucessfullyInstalledFontFaces.reduce(\n\t\t\t\t( errorMessageCollection, error ) => {\n\t\t\t\t\treturn `${ errorMessageCollection } ${ error.message }`;\n\t\t\t\t},\n\t\t\t\t''\n\t\t\t);\n\n\t\t\t// If there were no successes and nothing already installed then we don't need to activate anything and can bounce now.\n\t\t\tif (\n\t\t\t\tfontFamilyToInstall?.fontFace?.length > 0 &&\n\t\t\t\tsucessfullyInstalledFontFaces.length === 0 &&\n\t\t\t\talreadyInstalledFontFaces.length === 0\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: Specific error message returned from server. */\n\t\t\t\t\t\t__( 'No font faces were installed. %s' ),\n\t\t\t\t\t\tdetailedErrorMessage\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Use the sucessfully installed font faces\n\t\t\t// As well as any font faces that were already installed (those will be activated)\n\t\t\tif (\n\t\t\t\tsucessfullyInstalledFontFaces?.length > 0 ||\n\t\t\t\talreadyInstalledFontFaces?.length > 0\n\t\t\t) {\n\t\t\t\tfontFamilyToInstall.fontFace = [\n\t\t\t\t\t...sucessfullyInstalledFontFaces,\n\t\t\t\t\t...alreadyInstalledFontFaces,\n\t\t\t\t];\n\t\t\t}\n\n\t\t\t// Activate the font family (add the font family to the global styles).\n\t\t\tactivateCustomFontFamilies( [ fontFamilyToInstall ] );\n\n\t\t\t// Save the global styles to the database.\n\t\t\tsaveSpecifiedEntityEdits( 'root', 'globalStyles', globalStylesId, [\n\t\t\t\t'settings.typography.fontFamilies',\n\t\t\t] );\n\n\t\t\trefreshLibrary();\n\n\t\t\tif ( unsucessfullyInstalledFontFaces.length > 0 ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: Specific error message returned from server. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some font faces were installed. There were some errors. %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdetailedErrorMessage\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t} finally {\n\t\t\tsetIsInstalling( false );\n\t\t}\n\t}\n\n\tasync function uninstallFontFamily( fontFamilyToUninstall ) {\n\t\ttry {\n\t\t\t// Uninstall the font family.\n\t\t\t// (Removes the font files from the server and the posts from the database).\n\t\t\tconst uninstalledFontFamily = await fetchUninstallFontFamily(\n\t\t\t\tfontFamilyToUninstall.id\n\t\t\t);\n\n\t\t\t// Deactivate the font family if delete request is successful\n\t\t\t// (Removes the font family from the global styles).\n\t\t\tif ( uninstalledFontFamily.deleted ) {\n\t\t\t\tdeactivateFontFamily( fontFamilyToUninstall );\n\t\t\t\t// Save the global styles to the database.\n\t\t\t\tawait saveSpecifiedEntityEdits(\n\t\t\t\t\t'root',\n\t\t\t\t\t'globalStyles',\n\t\t\t\t\tglobalStylesId,\n\t\t\t\t\t[ 'settings.typography.fontFamilies' ]\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Refresh the library (the library font families from database).\n\t\t\trefreshLibrary();\n\n\t\t\treturn uninstalledFontFamily;\n\t\t} catch ( error ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(\n\t\t\t\t`There was an error uninstalling the font family:`,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tconst deactivateFontFamily = ( font ) => {\n\t\t// If the user doesn't have custom fonts defined, include as custom fonts all the theme fonts\n\t\t// We want to save as active all the theme fonts at the beginning\n\t\tconst initialCustomFonts = fontFamilies?.[ font.source ] ?? [];\n\t\tconst newCustomFonts = initialCustomFonts.filter(\n\t\t\t( f ) => f.slug !== font.slug\n\t\t);\n\t\tsetFontFamilies( {\n\t\t\t...fontFamilies,\n\t\t\t[ font.source ]: newCustomFonts,\n\t\t} );\n\t};\n\n\tconst activateCustomFontFamilies = ( fontsToAdd ) => {\n\t\t// Merge the existing custom fonts with the new fonts.\n\t\tconst newCustomFonts = mergeFontFamilies(\n\t\t\tfontFamilies?.custom,\n\t\t\tfontsToAdd\n\t\t);\n\t\t// Activate the fonts by set the new custom fonts array.\n\t\tsetFontFamilies( {\n\t\t\t...fontFamilies,\n\t\t\tcustom: newCustomFonts,\n\t\t} );\n\t\t// Add custom fonts to the browser.\n\t\tfontsToAdd.forEach( ( font ) => {\n\t\t\tif ( font.fontFace ) {\n\t\t\t\tfont.fontFace.forEach( ( face ) => {\n\t\t\t\t\t// Load font faces just in the iframe because they already are in the document.\n\t\t\t\t\tloadFontFaceInBrowser(\n\t\t\t\t\t\tface,\n\t\t\t\t\t\tgetDisplaySrcFromFontFace( face.src ),\n\t\t\t\t\t\t'iframe'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t};\n\n\tconst toggleActivateFont = ( font, face ) => {\n\t\t// If the user doesn't have custom fonts defined, include as custom fonts all the theme fonts\n\t\t// We want to save as active all the theme fonts at the beginning\n\t\tconst initialFonts = fontFamilies?.[ font.source ] ?? [];\n\t\t// Toggles the received font family or font face\n\t\tconst newFonts = toggleFont( font, face, initialFonts );\n\t\t// Updates the font families activated in global settings:\n\t\tsetFontFamilies( {\n\t\t\t...fontFamilies,\n\t\t\t[ font.source ]: newFonts,\n\t\t} );\n\t};\n\n\tconst loadFontFaceAsset = async ( fontFace ) => {\n\t\t// If the font doesn't have a src, don't load it.\n\t\tif ( ! fontFace.src ) return;\n\t\t// Get the src of the font.\n\t\tconst src = getDisplaySrcFromFontFace( fontFace.src, themeUrl );\n\t\t// If the font is already loaded, don't load it again.\n\t\tif ( ! src || loadedFontUrls.has( src ) ) return;\n\t\t// Load the font in the browser.\n\t\tloadFontFaceInBrowser( fontFace, src, 'document' );\n\t\t// Add the font to the loaded fonts list.\n\t\tloadedFontUrls.add( src );\n\t};\n\n\t// Font Collections\n\tconst [ collections, setFontCollections ] = useState( [] );\n\tconst getFontCollections = async () => {\n\t\tconst response = await fetchFontCollections();\n\t\tsetFontCollections( response );\n\t};\n\tconst getFontCollection = async ( slug ) => {\n\t\ttry {\n\t\t\tconst hasData = !! collections.find(\n\t\t\t\t( collection ) => collection.slug === slug\n\t\t\t)?.font_families;\n\t\t\tif ( hasData ) return;\n\t\t\tconst response = await fetchFontCollection( slug );\n\t\t\tconst updatedCollections = collections.map( ( collection ) =>\n\t\t\t\tcollection.slug === slug\n\t\t\t\t\t? { ...collection, ...response }\n\t\t\t\t\t: collection\n\t\t\t);\n\t\t\tsetFontCollections( updatedCollections );\n\t\t} catch ( e ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( e );\n\t\t\tthrow e;\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tgetFontCollections();\n\t}, [] );\n\n\treturn (\n\t\t<FontLibraryContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tlibraryFontSelected,\n\t\t\t\thandleSetLibraryFontSelected,\n\t\t\t\tthemeFonts,\n\t\t\t\tbaseThemeFonts,\n\t\t\t\tcustomFonts,\n\t\t\t\tbaseCustomFonts,\n\t\t\t\tisFontActivated,\n\t\t\t\tgetFontFacesActivated,\n\t\t\t\tloadFontFaceAsset,\n\t\t\t\tinstallFont,\n\t\t\t\tuninstallFontFamily,\n\t\t\t\ttoggleActivateFont,\n\t\t\t\tgetAvailableFontsOutline,\n\t\t\t\tmodalTabOpen,\n\t\t\t\ttoggleModal,\n\t\t\t\trefreshLibrary,\n\t\t\t\tsaveFontFamilies,\n\t\t\t\tfontFamiliesHasChanges,\n\t\t\t\tisResolvingLibrary,\n\t\t\t\thasResolvedLibrary,\n\t\t\t\tisInstalling,\n\t\t\t\tcollections,\n\t\t\t\tgetFontCollection,\n\t\t\t} }\n\t\t>\n\t\t\t{ children }\n\t\t</FontLibraryContext.Provider>\n\t);\n}\n\nexport default FontLibraryProvider;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACvE,SAASC,WAAW,IAAIC,sBAAsB,QAAQ,yBAAyB;AAC/E,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SACCC,eAAe,EACfC,gBAAgB,EAChBC,KAAK,IAAIC,SAAS,QACZ,sBAAsB;AAC7B,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,SACCC,wBAAwB,EACxBC,sBAAsB,EACtBC,wBAAwB,EACxBC,oBAAoB,EACpBC,mBAAmB,QACb,aAAa;AACpB,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,MAAM;EAAEC;AAAiB,CAAC,GAAGD,MAAM,CAAEd,sBAAuB,CAAC;AAC7D,SACCgB,iBAAiB,EACjBC,iBAAiB,EACjBC,qBAAqB,EACrBC,yBAAyB,EACzBC,qBAAqB,EACrBC,sBAAsB,EACtBC,qBAAqB,EACrBC,sBAAsB,QAChB,SAAS;AAChB,SAASC,UAAU,QAAQ,oBA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P9F,mBAAmB;MACnBe,4BAA4B;MAC5BJ,UAAU;MACVT,cAAc;MACdU,WAAW;MACXE,eAAe;MACf4B,eAAe;MACfI,qBAAqB;MACrBkC,iBAAiB;MACjBjC,WAAW;MACXiB,mBAAmB;MACnBY,kBAAkB;MAClB5C,wBAAwB;MACxBlC,YAAY;MACZuB,WAAW;MACX/C,cAAc;MACduB,gBAAgB;MAChBhC,sBAAsB;MACtBe,kBAAkB;MAClBE,kBAAkB;MAClBZ,YAAY;MACZiH,WAAW;MACXG;IACD;EAAG,GAEDhI,QAC0B,CAAC;AAEhC;AAEA,eAAeD,mBAAmB"}
|
|
@@ -20,16 +20,16 @@ import CollectionFontDetails from './collection-font-details';
|
|
|
20
20
|
import { toggleFont } from './utils/toggleFont';
|
|
21
21
|
import { getFontsOutline } from './utils/fonts-outline';
|
|
22
22
|
import GoogleFontsConfirmDialog from './google-fonts-confirm-dialog';
|
|
23
|
-
import {
|
|
23
|
+
import { downloadFontFaceAsset } from './utils';
|
|
24
24
|
const DEFAULT_CATEGORY = {
|
|
25
|
-
|
|
25
|
+
slug: 'all',
|
|
26
26
|
name: __('All')
|
|
27
27
|
};
|
|
28
28
|
function FontCollection({
|
|
29
|
-
|
|
29
|
+
slug
|
|
30
30
|
}) {
|
|
31
|
-
var _selectedCollection$
|
|
32
|
-
const requiresPermission =
|
|
31
|
+
var _selectedCollection$c;
|
|
32
|
+
const requiresPermission = slug === 'default-font-collection';
|
|
33
33
|
const getGoogleFontsPermissionFromStorage = () => {
|
|
34
34
|
return window.localStorage.getItem('wp-font-library-default-font-collection-permission') === 'true';
|
|
35
35
|
};
|
|
@@ -43,7 +43,7 @@ function FontCollection({
|
|
|
43
43
|
getFontCollection,
|
|
44
44
|
installFont
|
|
45
45
|
} = useContext(FontLibraryContext);
|
|
46
|
-
const selectedCollection = collections.find(collection => collection.
|
|
46
|
+
const selectedCollection = collections.find(collection => collection.slug === slug);
|
|
47
47
|
useEffect(() => {
|
|
48
48
|
const handleStorage = () => {
|
|
49
49
|
setRenderConfirmDialog(requiresPermission && !getGoogleFontsPermissionFromStorage());
|
|
@@ -51,11 +51,11 @@ function FontCollection({
|
|
|
51
51
|
handleStorage();
|
|
52
52
|
window.addEventListener('storage', handleStorage);
|
|
53
53
|
return () => window.removeEventListener('storage', handleStorage);
|
|
54
|
-
}, [
|
|
54
|
+
}, [slug, requiresPermission]);
|
|
55
55
|
useEffect(() => {
|
|
56
56
|
const fetchFontCollection = async () => {
|
|
57
57
|
try {
|
|
58
|
-
await getFontCollection(
|
|
58
|
+
await getFontCollection(slug);
|
|
59
59
|
resetFilters();
|
|
60
60
|
} catch (e) {
|
|
61
61
|
setNotice({
|
|
@@ -67,11 +67,11 @@ function FontCollection({
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
fetchFontCollection();
|
|
70
|
-
}, [
|
|
70
|
+
}, [slug, getFontCollection]);
|
|
71
71
|
useEffect(() => {
|
|
72
72
|
setSelectedFont(null);
|
|
73
73
|
setNotice(null);
|
|
74
|
-
}, [
|
|
74
|
+
}, [slug]);
|
|
75
75
|
useEffect(() => {
|
|
76
76
|
// If the selected fonts change, reset the selected fonts to install
|
|
77
77
|
setFontsToInstall([]);
|
|
@@ -88,10 +88,10 @@ function FontCollection({
|
|
|
88
88
|
}
|
|
89
89
|
}, [notice]);
|
|
90
90
|
const collectionFonts = useMemo(() => {
|
|
91
|
-
var _selectedCollection$
|
|
92
|
-
return (_selectedCollection$
|
|
91
|
+
var _selectedCollection$f;
|
|
92
|
+
return (_selectedCollection$f = selectedCollection?.font_families) !== null && _selectedCollection$f !== void 0 ? _selectedCollection$f : [];
|
|
93
93
|
}, [selectedCollection]);
|
|
94
|
-
const collectionCategories = (_selectedCollection$
|
|
94
|
+
const collectionCategories = (_selectedCollection$c = selectedCollection?.categories) !== null && _selectedCollection$c !== void 0 ? _selectedCollection$c : [];
|
|
95
95
|
const categories = [DEFAULT_CATEGORY, ...collectionCategories];
|
|
96
96
|
const fonts = useMemo(() => filterFonts(collectionFonts, filters), [collectionFonts, filters]);
|
|
97
97
|
const handleCategoryFilter = category => {
|
|
@@ -128,9 +128,36 @@ function FontCollection({
|
|
|
128
128
|
setFontsToInstall([]);
|
|
129
129
|
};
|
|
130
130
|
const handleInstall = async () => {
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const fontFamily = fontsToInstall[0];
|
|
132
|
+
try {
|
|
133
|
+
if (fontFamily?.fontFace) {
|
|
134
|
+
await Promise.all(fontFamily.fontFace.map(async fontFace => {
|
|
135
|
+
if (fontFace.src) {
|
|
136
|
+
fontFace.file = await downloadFontFaceAsset(fontFace.src);
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
// If any of the fonts fail to download,
|
|
142
|
+
// show an error notice and stop the request from being sent.
|
|
143
|
+
setNotice({
|
|
144
|
+
type: 'error',
|
|
145
|
+
message: __('Error installing the fonts, could not be downloaded.')
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
await installFont(fontFamily);
|
|
151
|
+
setNotice({
|
|
152
|
+
type: 'success',
|
|
153
|
+
message: __('Fonts were installed successfully.')
|
|
154
|
+
});
|
|
155
|
+
} catch (error) {
|
|
156
|
+
setNotice({
|
|
157
|
+
type: 'error',
|
|
158
|
+
message: error.message
|
|
159
|
+
});
|
|
160
|
+
}
|
|
134
161
|
resetFontsToInstall();
|
|
135
162
|
};
|
|
136
163
|
return createElement(TabPanelLayout, {
|
|
@@ -167,19 +194,19 @@ function FontCollection({
|
|
|
167
194
|
value: filters.category,
|
|
168
195
|
onChange: handleCategoryFilter
|
|
169
196
|
}, categories && categories.map(category => createElement("option", {
|
|
170
|
-
value: category.
|
|
171
|
-
key: category.
|
|
197
|
+
value: category.slug,
|
|
198
|
+
key: category.slug
|
|
172
199
|
}, category.name))))), createElement(Spacer, {
|
|
173
200
|
margin: 4
|
|
174
|
-
}), !renderConfirmDialog && !selectedCollection?.
|
|
201
|
+
}), !renderConfirmDialog && !selectedCollection?.font_families && !notice && createElement(Spinner, null), !renderConfirmDialog && !!selectedCollection?.font_families?.length && !fonts.length && createElement(Text, null, __('No fonts found. Try with a different search term')), !renderConfirmDialog && selectedFont && createElement(CollectionFontDetails, {
|
|
175
202
|
font: selectedFont,
|
|
176
203
|
handleToggleVariant: handleToggleVariant,
|
|
177
204
|
fontToInstallOutline: fontToInstallOutline
|
|
178
205
|
}), !renderConfirmDialog && !selectedFont && createElement(FontsGrid, null, fonts.map(font => createElement(FontCard, {
|
|
179
|
-
key: font.slug,
|
|
180
|
-
font: font,
|
|
206
|
+
key: font.font_family_settings.slug,
|
|
207
|
+
font: font.font_family_settings,
|
|
181
208
|
onClick: () => {
|
|
182
|
-
setSelectedFont(font);
|
|
209
|
+
setSelectedFont(font.font_family_settings);
|
|
183
210
|
}
|
|
184
211
|
}))));
|
|
185
212
|
}
|