@wordpress/edit-site 5.26.0 → 5.27.0
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/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-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/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-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 +302 -188
- package/build-style/style.css +302 -188
- 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 +1 -0
- 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-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
|
@@ -3,17 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.batchInstallFontFaces = batchInstallFontFaces;
|
|
7
|
+
exports.checkFontFaceInstalled = checkFontFaceInstalled;
|
|
8
|
+
exports.downloadFontFaceAsset = downloadFontFaceAsset;
|
|
6
9
|
exports.getDisplaySrcFromFontFace = getDisplaySrcFromFontFace;
|
|
7
10
|
exports.getFontFaceVariantName = getFontFaceVariantName;
|
|
8
11
|
exports.isUrlEncoded = isUrlEncoded;
|
|
9
12
|
exports.loadFontFaceInBrowser = loadFontFaceInBrowser;
|
|
10
|
-
exports.
|
|
13
|
+
exports.makeFontFacesFormData = makeFontFacesFormData;
|
|
14
|
+
exports.makeFontFamilyFormData = makeFontFamilyFormData;
|
|
11
15
|
exports.mergeFontFaces = mergeFontFaces;
|
|
12
16
|
exports.mergeFontFamilies = mergeFontFamilies;
|
|
13
17
|
exports.setUIValuesNeeded = setUIValuesNeeded;
|
|
14
18
|
var _components = require("@wordpress/components");
|
|
15
19
|
var _constants = require("./constants");
|
|
16
20
|
var _lockUnlock = require("../../../../lock-unlock");
|
|
21
|
+
var _resolvers = require("../resolvers");
|
|
22
|
+
var _previewStyles = require("./preview-styles");
|
|
17
23
|
/**
|
|
18
24
|
* WordPress dependencies
|
|
19
25
|
*/
|
|
@@ -22,6 +28,12 @@ var _lockUnlock = require("../../../../lock-unlock");
|
|
|
22
28
|
* Internal dependencies
|
|
23
29
|
*/
|
|
24
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Browser dependencies
|
|
33
|
+
*/
|
|
34
|
+
const {
|
|
35
|
+
File
|
|
36
|
+
} = window;
|
|
25
37
|
function setUIValuesNeeded(font, extraValues = {}) {
|
|
26
38
|
if (!font.name && (font.fontFamily || font.slug)) {
|
|
27
39
|
font.name = font.fontFamily || font.slug;
|
|
@@ -96,10 +108,10 @@ async function loadFontFaceInBrowser(fontFace, source, addTo = 'all') {
|
|
|
96
108
|
// eslint-disable-next-line no-undef
|
|
97
109
|
} else if (source instanceof File) {
|
|
98
110
|
dataSource = await source.arrayBuffer();
|
|
111
|
+
} else {
|
|
112
|
+
return;
|
|
99
113
|
}
|
|
100
|
-
|
|
101
|
-
// eslint-disable-next-line no-undef
|
|
102
|
-
const newFont = new FontFace(fontFace.fontFamily, dataSource, {
|
|
114
|
+
const newFont = new window.FontFace((0, _previewStyles.formatFontFamily)(fontFace.fontFamily), dataSource, {
|
|
103
115
|
style: fontFace.fontStyle,
|
|
104
116
|
weight: fontFace.fontWeight
|
|
105
117
|
});
|
|
@@ -131,38 +143,112 @@ function getDisplaySrcFromFontFace(input, urlPrefix) {
|
|
|
131
143
|
}
|
|
132
144
|
return src;
|
|
133
145
|
}
|
|
134
|
-
function
|
|
146
|
+
function makeFontFamilyFormData(fontFamily) {
|
|
135
147
|
const formData = new FormData();
|
|
136
148
|
const {
|
|
137
149
|
kebabCase
|
|
138
150
|
} = (0, _lockUnlock.unlock)(_components.privateApis);
|
|
139
|
-
const
|
|
140
|
-
|
|
151
|
+
const {
|
|
152
|
+
fontFace,
|
|
153
|
+
category,
|
|
154
|
+
...familyWithValidParameters
|
|
155
|
+
} = fontFamily;
|
|
156
|
+
const fontFamilySettings = {
|
|
157
|
+
...familyWithValidParameters,
|
|
141
158
|
slug: kebabCase(fontFamily.slug)
|
|
142
159
|
};
|
|
143
|
-
|
|
144
|
-
|
|
160
|
+
formData.append('font_family_settings', JSON.stringify(fontFamilySettings));
|
|
161
|
+
return formData;
|
|
162
|
+
}
|
|
163
|
+
function makeFontFacesFormData(font) {
|
|
164
|
+
if (font?.fontFace) {
|
|
165
|
+
const fontFacesFormData = font.fontFace.map((face, faceIndex) => {
|
|
166
|
+
const formData = new FormData();
|
|
145
167
|
if (face.file) {
|
|
146
168
|
// Slugified file name because the it might contain spaces or characters treated differently on the server.
|
|
147
169
|
const fileId = `file-${faceIndex}`;
|
|
148
170
|
// Add the files to the formData
|
|
149
171
|
formData.append(fileId, face.file, face.file.name);
|
|
150
|
-
// remove the file object from the face object the file is referenced
|
|
172
|
+
// remove the file object from the face object the file is referenced in src
|
|
151
173
|
const {
|
|
152
174
|
file,
|
|
153
175
|
...faceWithoutFileProperty
|
|
154
176
|
} = face;
|
|
155
|
-
const
|
|
177
|
+
const fontFaceSettings = {
|
|
156
178
|
...faceWithoutFileProperty,
|
|
157
|
-
|
|
179
|
+
src: fileId
|
|
158
180
|
};
|
|
159
|
-
|
|
181
|
+
formData.append('font_face_settings', JSON.stringify(fontFaceSettings));
|
|
182
|
+
} else {
|
|
183
|
+
formData.append('font_face_settings', JSON.stringify(face));
|
|
160
184
|
}
|
|
161
|
-
return
|
|
185
|
+
return formData;
|
|
162
186
|
});
|
|
163
|
-
|
|
187
|
+
return fontFacesFormData;
|
|
164
188
|
}
|
|
165
|
-
|
|
166
|
-
|
|
189
|
+
}
|
|
190
|
+
async function batchInstallFontFaces(fontFamilyId, fontFacesData) {
|
|
191
|
+
const promises = fontFacesData.map(faceData => (0, _resolvers.fetchInstallFontFace)(fontFamilyId, faceData));
|
|
192
|
+
const responses = await Promise.allSettled(promises);
|
|
193
|
+
const results = {
|
|
194
|
+
errors: [],
|
|
195
|
+
successes: []
|
|
196
|
+
};
|
|
197
|
+
responses.forEach((result, index) => {
|
|
198
|
+
if (result.status === 'fulfilled') {
|
|
199
|
+
const response = result.value;
|
|
200
|
+
if (response.id) {
|
|
201
|
+
results.successes.push(response);
|
|
202
|
+
} else {
|
|
203
|
+
results.errors.push({
|
|
204
|
+
data: fontFacesData[index],
|
|
205
|
+
message: `Error: ${response.message}`
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
// Handle network errors or other fetch-related errors
|
|
210
|
+
results.errors.push({
|
|
211
|
+
data: fontFacesData[index],
|
|
212
|
+
message: `Fetch error: ${result.reason.message}`
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
return results;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/*
|
|
220
|
+
* Downloads a font face asset from a URL to the client and returns a File object.
|
|
221
|
+
*/
|
|
222
|
+
async function downloadFontFaceAsset(url) {
|
|
223
|
+
return fetch(new Request(url)).then(response => {
|
|
224
|
+
if (!response.ok) {
|
|
225
|
+
throw new Error(`Error downloading font face asset from ${url}. Server responded with status: ${response.status}`);
|
|
226
|
+
}
|
|
227
|
+
return response.blob();
|
|
228
|
+
}).then(blob => {
|
|
229
|
+
const filename = url.split('/').pop();
|
|
230
|
+
const file = new File([blob], filename, {
|
|
231
|
+
type: blob.type
|
|
232
|
+
});
|
|
233
|
+
return file;
|
|
234
|
+
}).catch(error => {
|
|
235
|
+
// eslint-disable-next-line no-console
|
|
236
|
+
console.error(`Error downloading font face asset from ${url}:`, error);
|
|
237
|
+
throw error;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/*
|
|
242
|
+
* Determine if a given Font Face is present in a given collection.
|
|
243
|
+
* We determine that a font face has been installed by comparing the fontWeight and fontStyle
|
|
244
|
+
*
|
|
245
|
+
* @param {Object} fontFace The Font Face to seek
|
|
246
|
+
* @param {Array} collection The Collection to seek in
|
|
247
|
+
* @returns True if the font face is found in the collection. Otherwise False.
|
|
248
|
+
*/
|
|
249
|
+
function checkFontFaceInstalled(fontFace, collection) {
|
|
250
|
+
return -1 !== collection.findIndex(collectionFontFace => {
|
|
251
|
+
return collectionFontFace.fontWeight === fontFace.fontWeight && collectionFontFace.fontStyle === fontFace.fontStyle;
|
|
252
|
+
});
|
|
167
253
|
}
|
|
168
254
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_constants","_lockUnlock","setUIValuesNeeded","font","extraValues","name","fontFamily","slug","isUrlEncoded","url","decodeURIComponent","getFontFaceVariantName","face","weightName","FONT_WEIGHTS","fontWeight","styleName","fontStyle","FONT_STYLES","mergeFontFaces","existing","incoming","map","Map","set","Array","from","values","mergeFontFamilies","has","fontFace","incomingFontFaces","restIncoming","existingFont","get","mergedFontFaces","loadFontFaceInBrowser","source","addTo","dataSource","File","arrayBuffer","newFont","FontFace","style","weight","loadedFace","load","document","fonts","add","iframeDocument","querySelector","contentDocument","getDisplaySrcFromFontFace","input","urlPrefix","src","isArray","startsWith","replace","encodeURI","makeFormDataFromFontFamily","formData","FormData","kebabCase","unlock","componentsPrivateApis","newFontFamily","newFontFaces","faceIndex","file","fileId","append","faceWithoutFileProperty","newFace","uploadedFile","JSON","stringify"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { FONT_WEIGHTS, FONT_STYLES } from './constants';\nimport { unlock } from '../../../../lock-unlock';\n\nexport function setUIValuesNeeded( font, extraValues = {} ) {\n\tif ( ! font.name && ( font.fontFamily || font.slug ) ) {\n\t\tfont.name = font.fontFamily || font.slug;\n\t}\n\treturn {\n\t\t...font,\n\t\t...extraValues,\n\t};\n}\n\nexport function isUrlEncoded( url ) {\n\tif ( typeof url !== 'string' ) {\n\t\treturn false;\n\t}\n\treturn url !== decodeURIComponent( url );\n}\n\nexport function getFontFaceVariantName( face ) {\n\tconst weightName = FONT_WEIGHTS[ face.fontWeight ] || face.fontWeight;\n\tconst styleName =\n\t\tface.fontStyle === 'normal'\n\t\t\t? ''\n\t\t\t: FONT_STYLES[ face.fontStyle ] || face.fontStyle;\n\treturn `${ weightName } ${ styleName }`;\n}\n\nexport function mergeFontFaces( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\tfor ( const face of existing ) {\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\tfor ( const face of incoming ) {\n\t\t// This will overwrite if the src already exists, keeping it unique.\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\treturn Array.from( map.values() );\n}\n\nexport function mergeFontFamilies( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\t// Add the existing array to the map.\n\tfor ( const font of existing ) {\n\t\tmap.set( font.slug, { ...font } );\n\t}\n\t// Add the incoming array to the map, overwriting existing values excepting fontFace that need to be merged.\n\tfor ( const font of incoming ) {\n\t\tif ( map.has( font.slug ) ) {\n\t\t\tconst { fontFace: incomingFontFaces, ...restIncoming } = font;\n\t\t\tconst existingFont = map.get( font.slug );\n\t\t\t// Merge the fontFaces existing with the incoming fontFaces.\n\t\t\tconst mergedFontFaces = mergeFontFaces(\n\t\t\t\texistingFont.fontFace,\n\t\t\t\tincomingFontFaces\n\t\t\t);\n\t\t\t// Except for the fontFace key all the other keys are overwritten with the incoming values.\n\t\t\tmap.set( font.slug, {\n\t\t\t\t...restIncoming,\n\t\t\t\tfontFace: mergedFontFaces,\n\t\t\t} );\n\t\t} else {\n\t\t\tmap.set( font.slug, { ...font } );\n\t\t}\n\t}\n\treturn Array.from( map.values() );\n}\n\n/*\n * Loads the font face from a URL and adds it to the browser.\n * It also adds it to the iframe document.\n */\nexport async function loadFontFaceInBrowser( fontFace, source, addTo = 'all' ) {\n\tlet dataSource;\n\n\tif ( typeof source === 'string' ) {\n\t\tdataSource = `url(${ source })`;\n\t\t// eslint-disable-next-line no-undef\n\t} else if ( source instanceof File ) {\n\t\tdataSource = await source.arrayBuffer();\n\t}\n\n\t// eslint-disable-next-line no-undef\n\tconst newFont = new FontFace( fontFace.fontFamily, dataSource, {\n\t\tstyle: fontFace.fontStyle,\n\t\tweight: fontFace.fontWeight,\n\t} );\n\n\tconst loadedFace = await newFont.load();\n\n\tif ( addTo === 'document' || addTo === 'all' ) {\n\t\tdocument.fonts.add( loadedFace );\n\t}\n\n\tif ( addTo === 'iframe' || addTo === 'all' ) {\n\t\tconst iframeDocument = document.querySelector(\n\t\t\t'iframe[name=\"editor-canvas\"]'\n\t\t).contentDocument;\n\t\tiframeDocument.fonts.add( loadedFace );\n\t}\n}\n\nexport function getDisplaySrcFromFontFace( input, urlPrefix ) {\n\tif ( ! input ) {\n\t\treturn;\n\t}\n\n\tlet src;\n\tif ( Array.isArray( input ) ) {\n\t\tsrc = input[ 0 ];\n\t} else {\n\t\tsrc = input;\n\t}\n\t// If it is a theme font, we need to make the url absolute\n\tif ( src.startsWith( 'file:.' ) && urlPrefix ) {\n\t\tsrc = src.replace( 'file:.', urlPrefix );\n\t}\n\tif ( ! isUrlEncoded( src ) ) {\n\t\tsrc = encodeURI( src );\n\t}\n\treturn src;\n}\n\nexport function makeFormDataFromFontFamily( fontFamily ) {\n\tconst formData = new FormData();\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\n\tconst newFontFamily = {\n\t\t...fontFamily,\n\t\tslug: kebabCase( fontFamily.slug ),\n\t};\n\n\tif ( newFontFamily?.fontFace ) {\n\t\tconst newFontFaces = newFontFamily.fontFace.map(\n\t\t\t( face, faceIndex ) => {\n\t\t\t\tif ( face.file ) {\n\t\t\t\t\t// Slugified file name because the it might contain spaces or characters treated differently on the server.\n\t\t\t\t\tconst fileId = `file-${ faceIndex }`;\n\t\t\t\t\t// Add the files to the formData\n\t\t\t\t\tformData.append( fileId, face.file, face.file.name );\n\t\t\t\t\t// remove the file object from the face object the file is referenced by the uploadedFile key\n\t\t\t\t\tconst { file, ...faceWithoutFileProperty } = face;\n\t\t\t\t\tconst newFace = {\n\t\t\t\t\t\t...faceWithoutFileProperty,\n\t\t\t\t\t\tuploadedFile: fileId,\n\t\t\t\t\t};\n\t\t\t\t\treturn newFace;\n\t\t\t\t}\n\t\t\t\treturn face;\n\t\t\t}\n\t\t);\n\t\tnewFontFamily.fontFace = newFontFaces;\n\t}\n\n\tformData.append( 'font_family_settings', JSON.stringify( newFontFamily ) );\n\treturn formData;\n}\n"],"mappings":";;;;;;;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIO,SAASG,iBAAiBA,CAAEC,IAAI,EAAEC,WAAW,GAAG,CAAC,CAAC,EAAG;EAC3D,IAAK,CAAED,IAAI,CAACE,IAAI,KAAMF,IAAI,CAACG,UAAU,IAAIH,IAAI,CAACI,IAAI,CAAE,EAAG;IACtDJ,IAAI,CAACE,IAAI,GAAGF,IAAI,CAACG,UAAU,IAAIH,IAAI,CAACI,IAAI;EACzC;EACA,OAAO;IACN,GAAGJ,IAAI;IACP,GAAGC;EACJ,CAAC;AACF;AAEO,SAASI,YAAYA,CAAEC,GAAG,EAAG;EACnC,IAAK,OAAOA,GAAG,KAAK,QAAQ,EAAG;IAC9B,OAAO,KAAK;EACb;EACA,OAAOA,GAAG,KAAKC,kBAAkB,CAAED,GAAI,CAAC;AACzC;AAEO,SAASE,sBAAsBA,CAAEC,IAAI,EAAG;EAC9C,MAAMC,UAAU,GAAGC,uBAAY,CAAEF,IAAI,CAACG,UAAU,CAAE,IAAIH,IAAI,CAACG,UAAU;EACrE,MAAMC,SAAS,GACdJ,IAAI,CAACK,SAAS,KAAK,QAAQ,GACxB,EAAE,GACFC,sBAAW,CAAEN,IAAI,CAACK,SAAS,CAAE,IAAIL,IAAI,CAACK,SAAS;EACnD,OAAQ,GAAGJ,UAAY,IAAIG,SAAW,EAAC;AACxC;AAEO,SAASG,cAAcA,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GD,uBAAuB;UAC1BE,YAAY,EAAEJ;QACf,CAAC;QACD,OAAOG,OAAO;MACf;MACA,OAAO/D,IAAI;IACZ,CACD,CAAC;IACDwD,aAAa,CAACtC,QAAQ,GAAGuC,YAAY;EACtC;EAEAN,QAAQ,CAACU,MAAM,CAAE,sBAAsB,EAAEI,IAAI,CAACC,SAAS,CAAEV,aAAc,CAAE,CAAC;EAC1E,OAAOL,QAAQ;AAChB"}
|
|
1
|
+
{"version":3,"names":["_components","require","_constants","_lockUnlock","_resolvers","_previewStyles","File","window","setUIValuesNeeded","font","extraValues","name","fontFamily","slug","isUrlEncoded","url","decodeURIComponent","getFontFaceVariantName","face","weightName","FONT_WEIGHTS","fontWeight","styleName","fontStyle","FONT_STYLES","mergeFontFaces","existing","incoming","map","Map","set","Array","from","values","mergeFontFamilies","has","fontFace","incomingFontFaces","restIncoming","existingFont","get","mergedFontFaces","loadFontFaceInBrowser","source","addTo","dataSource","arrayBuffer","newFont","FontFace","formatFontFamily","style","weight","loadedFace","load","document","fonts","add","iframeDocument","querySelector","contentDocument","getDisplaySrcFromFontFace","input","urlPrefix","src","isArray","startsWith","replace","encodeURI","makeFontFamilyFormData","formData","FormData","kebabCase","unlock","componentsPrivateApis","category","familyWithValidParameters","fontFamilySettings","append","JSON","stringify","makeFontFacesFormData","fontFacesFormData","faceIndex","file","fileId","faceWithoutFileProperty","fontFaceSettings","batchInstallFontFaces","fontFamilyId","fontFacesData","promises","faceData","fetchInstallFontFace","responses","Promise","allSettled","results","errors","successes","forEach","result","index","status","response","value","id","push","data","message","reason","downloadFontFaceAsset","fetch","Request","then","ok","Error","blob","filename","split","pop","type","catch","error","console","checkFontFaceInstalled","collection","findIndex","collectionFontFace"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { FONT_WEIGHTS, FONT_STYLES } from './constants';\nimport { unlock } from '../../../../lock-unlock';\nimport { fetchInstallFontFace } from '../resolvers';\nimport { formatFontFamily } from './preview-styles';\n\n/**\n * Browser dependencies\n */\nconst { File } = window;\n\nexport function setUIValuesNeeded( font, extraValues = {} ) {\n\tif ( ! font.name && ( font.fontFamily || font.slug ) ) {\n\t\tfont.name = font.fontFamily || font.slug;\n\t}\n\treturn {\n\t\t...font,\n\t\t...extraValues,\n\t};\n}\n\nexport function isUrlEncoded( url ) {\n\tif ( typeof url !== 'string' ) {\n\t\treturn false;\n\t}\n\treturn url !== decodeURIComponent( url );\n}\n\nexport function getFontFaceVariantName( face ) {\n\tconst weightName = FONT_WEIGHTS[ face.fontWeight ] || face.fontWeight;\n\tconst styleName =\n\t\tface.fontStyle === 'normal'\n\t\t\t? ''\n\t\t\t: FONT_STYLES[ face.fontStyle ] || face.fontStyle;\n\treturn `${ weightName } ${ styleName }`;\n}\n\nexport function mergeFontFaces( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\tfor ( const face of existing ) {\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\tfor ( const face of incoming ) {\n\t\t// This will overwrite if the src already exists, keeping it unique.\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\treturn Array.from( map.values() );\n}\n\nexport function mergeFontFamilies( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\t// Add the existing array to the map.\n\tfor ( const font of existing ) {\n\t\tmap.set( font.slug, { ...font } );\n\t}\n\t// Add the incoming array to the map, overwriting existing values excepting fontFace that need to be merged.\n\tfor ( const font of incoming ) {\n\t\tif ( map.has( font.slug ) ) {\n\t\t\tconst { fontFace: incomingFontFaces, ...restIncoming } = font;\n\t\t\tconst existingFont = map.get( font.slug );\n\t\t\t// Merge the fontFaces existing with the incoming fontFaces.\n\t\t\tconst mergedFontFaces = mergeFontFaces(\n\t\t\t\texistingFont.fontFace,\n\t\t\t\tincomingFontFaces\n\t\t\t);\n\t\t\t// Except for the fontFace key all the other keys are overwritten with the incoming values.\n\t\t\tmap.set( font.slug, {\n\t\t\t\t...restIncoming,\n\t\t\t\tfontFace: mergedFontFaces,\n\t\t\t} );\n\t\t} else {\n\t\t\tmap.set( font.slug, { ...font } );\n\t\t}\n\t}\n\treturn Array.from( map.values() );\n}\n\n/*\n * Loads the font face from a URL and adds it to the browser.\n * It also adds it to the iframe document.\n */\nexport async function loadFontFaceInBrowser( fontFace, source, addTo = 'all' ) {\n\tlet dataSource;\n\n\tif ( typeof source === 'string' ) {\n\t\tdataSource = `url(${ source })`;\n\t\t// eslint-disable-next-line no-undef\n\t} else if ( source instanceof File ) {\n\t\tdataSource = await source.arrayBuffer();\n\t} else {\n\t\treturn;\n\t}\n\n\tconst newFont = new window.FontFace(\n\t\tformatFontFamily( fontFace.fontFamily ),\n\t\tdataSource,\n\t\t{\n\t\t\tstyle: fontFace.fontStyle,\n\t\t\tweight: fontFace.fontWeight,\n\t\t}\n\t);\n\n\tconst loadedFace = await newFont.load();\n\n\tif ( addTo === 'document' || addTo === 'all' ) {\n\t\tdocument.fonts.add( loadedFace );\n\t}\n\n\tif ( addTo === 'iframe' || addTo === 'all' ) {\n\t\tconst iframeDocument = document.querySelector(\n\t\t\t'iframe[name=\"editor-canvas\"]'\n\t\t).contentDocument;\n\t\tiframeDocument.fonts.add( loadedFace );\n\t}\n}\n\nexport function getDisplaySrcFromFontFace( input, urlPrefix ) {\n\tif ( ! input ) {\n\t\treturn;\n\t}\n\n\tlet src;\n\tif ( Array.isArray( input ) ) {\n\t\tsrc = input[ 0 ];\n\t} else {\n\t\tsrc = input;\n\t}\n\t// If it is a theme font, we need to make the url absolute\n\tif ( src.startsWith( 'file:.' ) && urlPrefix ) {\n\t\tsrc = src.replace( 'file:.', urlPrefix );\n\t}\n\tif ( ! isUrlEncoded( src ) ) {\n\t\tsrc = encodeURI( src );\n\t}\n\treturn src;\n}\n\nexport function makeFontFamilyFormData( fontFamily ) {\n\tconst formData = new FormData();\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\n\tconst { fontFace, category, ...familyWithValidParameters } = fontFamily;\n\tconst fontFamilySettings = {\n\t\t...familyWithValidParameters,\n\t\tslug: kebabCase( fontFamily.slug ),\n\t};\n\n\tformData.append(\n\t\t'font_family_settings',\n\t\tJSON.stringify( fontFamilySettings )\n\t);\n\treturn formData;\n}\n\nexport function makeFontFacesFormData( font ) {\n\tif ( font?.fontFace ) {\n\t\tconst fontFacesFormData = font.fontFace.map( ( face, faceIndex ) => {\n\t\t\tconst formData = new FormData();\n\t\t\tif ( face.file ) {\n\t\t\t\t// Slugified file name because the it might contain spaces or characters treated differently on the server.\n\t\t\t\tconst fileId = `file-${ faceIndex }`;\n\t\t\t\t// Add the files to the formData\n\t\t\t\tformData.append( fileId, face.file, face.file.name );\n\t\t\t\t// remove the file object from the face object the file is referenced in src\n\t\t\t\tconst { file, ...faceWithoutFileProperty } = face;\n\t\t\t\tconst fontFaceSettings = {\n\t\t\t\t\t...faceWithoutFileProperty,\n\t\t\t\t\tsrc: fileId,\n\t\t\t\t};\n\t\t\t\tformData.append(\n\t\t\t\t\t'font_face_settings',\n\t\t\t\t\tJSON.stringify( fontFaceSettings )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t}\n\t\t\treturn formData;\n\t\t} );\n\n\t\treturn fontFacesFormData;\n\t}\n}\n\nexport async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {\n\tconst promises = fontFacesData.map( ( faceData ) =>\n\t\tfetchInstallFontFace( fontFamilyId, faceData )\n\t);\n\tconst responses = await Promise.allSettled( promises );\n\n\tconst results = {\n\t\terrors: [],\n\t\tsuccesses: [],\n\t};\n\n\tresponses.forEach( ( result, index ) => {\n\t\tif ( result.status === 'fulfilled' ) {\n\t\t\tconst response = result.value;\n\t\t\tif ( response.id ) {\n\t\t\t\tresults.successes.push( response );\n\t\t\t} else {\n\t\t\t\tresults.errors.push( {\n\t\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\t\tmessage: `Error: ${ response.message }`,\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\t// Handle network errors or other fetch-related errors\n\t\t\tresults.errors.push( {\n\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\tmessage: `Fetch error: ${ result.reason.message }`,\n\t\t\t} );\n\t\t}\n\t} );\n\n\treturn results;\n}\n\n/*\n * Downloads a font face asset from a URL to the client and returns a File object.\n */\nexport async function downloadFontFaceAsset( url ) {\n\treturn fetch( new Request( url ) )\n\t\t.then( ( response ) => {\n\t\t\tif ( ! response.ok ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Error downloading font face asset from ${ url }. Server responded with status: ${ response.status }`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn response.blob();\n\t\t} )\n\t\t.then( ( blob ) => {\n\t\t\tconst filename = url.split( '/' ).pop();\n\t\t\tconst file = new File( [ blob ], filename, {\n\t\t\t\ttype: blob.type,\n\t\t\t} );\n\t\t\treturn file;\n\t\t} )\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`Error downloading font face asset from ${ url }:`,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow error;\n\t\t} );\n}\n\n/*\n * Determine if a given Font Face is present in a given collection.\n * We determine that a font face has been installed by comparing the fontWeight and fontStyle\n *\n * @param {Object} fontFace The Font Face to seek\n * @param {Array} collection The Collection to seek in\n * @returns True if the font face is found in the collection. Otherwise False.\n */\nexport function checkFontFaceInstalled( fontFace, collection ) {\n\treturn (\n\t\t-1 !==\n\t\tcollection.findIndex( ( collectionFontFace ) => {\n\t\t\treturn (\n\t\t\t\tcollectionFontFace.fontWeight === fontFace.fontWeight &&\n\t\t\t\tcollectionFontFace.fontStyle === fontFace.fontStyle\n\t\t\t);\n\t\t} )\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,IAAAA,WAAA,G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ACC,SAAS,CAAIC,kBAAkB,IAAM;IAC/C,OACCA,kBAAkB,CAAC1G,UAAU,KAAKe,QAAQ,CAACf,UAAU,IACrD0G,kBAAkB,CAACxG,SAAS,KAAKa,QAAQ,CAACb,SAAS;EAErD,CAAE,CAAC;AAEL"}
|
|
@@ -35,9 +35,10 @@ function extractFontWeights(fontFaces) {
|
|
|
35
35
|
function formatFontFamily(input) {
|
|
36
36
|
return input.split(',').map(font => {
|
|
37
37
|
font = font.trim(); // Remove any leading or trailing white spaces
|
|
38
|
-
// If the font doesn't
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
// If the font doesn't start with quotes and contains a space, then wrap in quotes.
|
|
39
|
+
// Check that string starts with a single or double quote and not a space
|
|
40
|
+
if (!(font.startsWith('"') || font.startsWith("'")) && font.indexOf(' ') !== -1) {
|
|
41
|
+
return `"${font}"`;
|
|
41
42
|
}
|
|
42
43
|
return font; // Return font as is if no transformation is needed
|
|
43
44
|
}).join(', ');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["findNearest","input","numbers","length","sort","a","b","Math","abs","extractFontWeights","fontFaces","result","forEach","face","weights","String","fontWeight","split","start","parseInt","end","i","push","formatFontFamily","map","font","trim","startsWith","indexOf","join","getFamilyPreviewStyle","family","style","fontFamily","Array","isArray","fontFace","fontStyle","normalFaces","filter","toLowerCase","normalWeights","nearestWeight","getFacePreviewStyle"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/preview-styles.js"],"sourcesContent":["function findNearest( input, numbers ) {\n\t// If the numbers array is empty, return null\n\tif ( numbers.length === 0 ) {\n\t\treturn null;\n\t}\n\t// Sort the array based on the absolute difference with the input\n\tnumbers.sort( ( a, b ) => Math.abs( input - a ) - Math.abs( input - b ) );\n\t// Return the first element (which will be the nearest) from the sorted array\n\treturn numbers[ 0 ];\n}\n\nfunction extractFontWeights( fontFaces ) {\n\tconst result = [];\n\n\tfontFaces.forEach( ( face ) => {\n\t\tconst weights = String( face.fontWeight ).split( ' ' );\n\n\t\tif ( weights.length === 2 ) {\n\t\t\tconst start = parseInt( weights[ 0 ] );\n\t\t\tconst end = parseInt( weights[ 1 ] );\n\n\t\t\tfor ( let i = start; i <= end; i += 100 ) {\n\t\t\t\tresult.push( i );\n\t\t\t}\n\t\t} else if ( weights.length === 1 ) {\n\t\t\tresult.push( parseInt( weights[ 0 ] ) );\n\t\t}\n\t} );\n\n\treturn result;\n}\n\nexport function formatFontFamily( input ) {\n\treturn input\n\t\t.split( ',' )\n\t\t.map( ( font ) => {\n\t\t\tfont = font.trim(); // Remove any leading or trailing white spaces\n\t\t\t// If the font doesn't
|
|
1
|
+
{"version":3,"names":["findNearest","input","numbers","length","sort","a","b","Math","abs","extractFontWeights","fontFaces","result","forEach","face","weights","String","fontWeight","split","start","parseInt","end","i","push","formatFontFamily","map","font","trim","startsWith","indexOf","join","getFamilyPreviewStyle","family","style","fontFamily","Array","isArray","fontFace","fontStyle","normalFaces","filter","toLowerCase","normalWeights","nearestWeight","getFacePreviewStyle"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/preview-styles.js"],"sourcesContent":["function findNearest( input, numbers ) {\n\t// If the numbers array is empty, return null\n\tif ( numbers.length === 0 ) {\n\t\treturn null;\n\t}\n\t// Sort the array based on the absolute difference with the input\n\tnumbers.sort( ( a, b ) => Math.abs( input - a ) - Math.abs( input - b ) );\n\t// Return the first element (which will be the nearest) from the sorted array\n\treturn numbers[ 0 ];\n}\n\nfunction extractFontWeights( fontFaces ) {\n\tconst result = [];\n\n\tfontFaces.forEach( ( face ) => {\n\t\tconst weights = String( face.fontWeight ).split( ' ' );\n\n\t\tif ( weights.length === 2 ) {\n\t\t\tconst start = parseInt( weights[ 0 ] );\n\t\t\tconst end = parseInt( weights[ 1 ] );\n\n\t\t\tfor ( let i = start; i <= end; i += 100 ) {\n\t\t\t\tresult.push( i );\n\t\t\t}\n\t\t} else if ( weights.length === 1 ) {\n\t\t\tresult.push( parseInt( weights[ 0 ] ) );\n\t\t}\n\t} );\n\n\treturn result;\n}\n\nexport function formatFontFamily( input ) {\n\treturn input\n\t\t.split( ',' )\n\t\t.map( ( font ) => {\n\t\t\tfont = font.trim(); // Remove any leading or trailing white spaces\n\t\t\t// If the font doesn't start with quotes and contains a space, then wrap in quotes.\n\t\t\t// Check that string starts with a single or double quote and not a space\n\t\t\tif (\n\t\t\t\t! ( font.startsWith( '\"' ) || font.startsWith( \"'\" ) ) &&\n\t\t\t\tfont.indexOf( ' ' ) !== -1\n\t\t\t) {\n\t\t\t\treturn `\"${ font }\"`;\n\t\t\t}\n\t\t\treturn font; // Return font as is if no transformation is needed\n\t\t} )\n\t\t.join( ', ' );\n}\n\nexport function getFamilyPreviewStyle( family ) {\n\tconst style = { fontFamily: formatFontFamily( family.fontFamily ) };\n\n\tif ( ! Array.isArray( family.fontFace ) ) {\n\t\tstyle.fontWeight = '400';\n\t\tstyle.fontStyle = 'normal';\n\t\treturn style;\n\t}\n\n\tif ( family.fontFace ) {\n\t\t//get all the font faces with normal style\n\t\tconst normalFaces = family.fontFace.filter(\n\t\t\t( face ) => face.fontStyle.toLowerCase() === 'normal'\n\t\t);\n\t\tif ( normalFaces.length > 0 ) {\n\t\t\tstyle.fontStyle = 'normal';\n\t\t\tconst normalWeights = extractFontWeights( normalFaces );\n\t\t\tconst nearestWeight = findNearest( 400, normalWeights );\n\t\t\tstyle.fontWeight = String( nearestWeight ) || '400';\n\t\t} else {\n\t\t\tstyle.fontStyle =\n\t\t\t\t( family.fontFace.length && family.fontFace[ 0 ].fontStyle ) ||\n\t\t\t\t'normal';\n\t\t\tstyle.fontWeight =\n\t\t\t\t( family.fontFace.length &&\n\t\t\t\t\tString( family.fontFace[ 0 ].fontWeight ) ) ||\n\t\t\t\t'400';\n\t\t}\n\t}\n\n\treturn style;\n}\n\nexport function getFacePreviewStyle( face ) {\n\treturn {\n\t\tfontFamily: formatFontFamily( face.fontFamily ),\n\t\tfontStyle: face.fontStyle || 'normal',\n\t\tf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SAAS,GACZN,MAAM,CAACK,QAAQ,CAACjC,MAAM,IAAI4B,MAAM,CAACK,QAAQ,CAAE,CAAC,CAAE,CAACC,SAAS,IAC1D,QAAQ;MACTL,KAAK,CAAChB,UAAU,GACbe,MAAM,CAACK,QAAQ,CAACjC,MAAM,IACvBY,MAAM,CAAEgB,MAAM,CAACK,QAAQ,CAAE,CAAC,CAAE,CAACpB,UAAW,CAAC,IAC1C,KAAK;IACP;EACD;EAEA,OAAOgB,KAAK;AACb;AAEO,SAASW,mBAAmBA,CAAE9B,IAAI,EAAG;EAC3C,OAAO;IACNoB,UAAU,EAAEV,gBAAgB,CAAEV,IAAI,CAACoB,UAAW,CAAC;IAC/CI,SAAS,EAAExB,IAAI,CAACwB,SAAS,IAAI,QAAQ;IACrCrB,UAAU,EAAEH,IAAI,CAACG,UAAU,IAAI;EAChC,CAAC;AACF"}
|
|
@@ -8,6 +8,8 @@ exports.default = void 0;
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _i18n = require("@wordpress/i18n");
|
|
10
10
|
var _components = require("@wordpress/components");
|
|
11
|
+
var _editor = require("@wordpress/editor");
|
|
12
|
+
var _data = require("@wordpress/data");
|
|
11
13
|
var _typogrphyElements = _interopRequireDefault(require("./typogrphy-elements"));
|
|
12
14
|
var _fontFamilies = _interopRequireDefault(require("./font-families"));
|
|
13
15
|
var _header = _interopRequireDefault(require("./header"));
|
|
@@ -20,6 +22,7 @@ var _header = _interopRequireDefault(require("./header"));
|
|
|
20
22
|
*/
|
|
21
23
|
|
|
22
24
|
function ScreenTypography() {
|
|
25
|
+
const fontLibraryEnabled = (0, _data.useSelect)(select => select(_editor.store).getEditorSettings().fontLibraryEnabled, []);
|
|
23
26
|
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_header.default, {
|
|
24
27
|
title: (0, _i18n.__)('Typography'),
|
|
25
28
|
description: (0, _i18n.__)('Manage the typography settings for different elements.')
|
|
@@ -27,7 +30,7 @@ function ScreenTypography() {
|
|
|
27
30
|
className: "edit-site-global-styles-screen-typography"
|
|
28
31
|
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
29
32
|
spacing: 6
|
|
30
|
-
},
|
|
33
|
+
}, fontLibraryEnabled && (0, _react.createElement)(_fontFamilies.default, null), (0, _react.createElement)(_typogrphyElements.default, null))));
|
|
31
34
|
}
|
|
32
35
|
var _default = ScreenTypography;
|
|
33
36
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_typogrphyElements","_interopRequireDefault","_fontFamilies","_header","ScreenTypography","_react","createElement","Fragment","default","title","__","description","className","__experimentalVStack","spacing","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_editor","_data","_typogrphyElements","_interopRequireDefault","_fontFamilies","_header","ScreenTypography","fontLibraryEnabled","useSelect","select","editorStore","getEditorSettings","_react","createElement","Fragment","default","title","__","description","className","__experimentalVStack","spacing","_default","exports"],"sources":["@wordpress/edit-site/src/components/global-styles/screen-typography.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { __experimentalVStack as VStack } from '@wordpress/components';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport TypographyElements from './typogrphy-elements';\nimport FontFamilies from './font-families';\nimport ScreenHeader from './header';\n\nfunction ScreenTypography() {\n\tconst fontLibraryEnabled = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getEditorSettings().fontLibraryEnabled,\n\t\t[]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<ScreenHeader\n\t\t\t\ttitle={ __( 'Typography' ) }\n\t\t\t\tdescription={ __(\n\t\t\t\t\t'Manage the typography settings for different elements.'\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t<div className=\"edit-site-global-styles-screen-typography\">\n\t\t\t\t<VStack spacing={ 6 }>\n\t\t\t\t\t{ fontLibraryEnabled && <FontFamilies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
@@ -48,16 +48,17 @@ function useIsSiteEditorLoading() {
|
|
|
48
48
|
(0, _element.useEffect)(() => {
|
|
49
49
|
if (inLoadingPause) {
|
|
50
50
|
/*
|
|
51
|
-
* We're using an arbitrary
|
|
52
|
-
* without any resolving selectors that would result in
|
|
53
|
-
* brief flickers of loading state and loaded state.
|
|
51
|
+
* We're using an arbitrary 100ms timeout here to catch brief
|
|
52
|
+
* moments without any resolving selectors that would result in
|
|
53
|
+
* displaying brief flickers of loading state and loaded state.
|
|
54
54
|
*
|
|
55
55
|
* It's worth experimenting with different values, since this also
|
|
56
|
-
* adds
|
|
56
|
+
* adds 100ms of artificial delay after loading has finished.
|
|
57
57
|
*/
|
|
58
|
+
const ARTIFICIAL_DELAY = 100;
|
|
58
59
|
const timeout = setTimeout(() => {
|
|
59
60
|
setLoaded(true);
|
|
60
|
-
},
|
|
61
|
+
}, ARTIFICIAL_DELAY);
|
|
61
62
|
return () => {
|
|
62
63
|
clearTimeout(timeout);
|
|
63
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_data","_coreData","_useEditedEntityRecord","_interopRequireDefault","MAX_LOADING_TIME","useIsSiteEditorLoading","isLoaded","hasLoadedPost","useEditedEntityRecord","loaded","setLoaded","useState","inLoadingPause","useSelect","select","hasResolvingSelectors","coreStore","useEffect","timeout","setTimeout","clearTimeout"],"sources":["@wordpress/edit-site/src/components/layout/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport useEditedEntityRecord from '../use-edited-entity-record';\n\nconst MAX_LOADING_TIME = 10000; // 10 seconds\n\nexport function useIsSiteEditorLoading() {\n\tconst { isLoaded: hasLoadedPost } = useEditedEntityRecord();\n\tconst [ loaded, setLoaded ] = useState( false );\n\tconst inLoadingPause = useSelect(\n\t\t( select ) => {\n\t\t\tconst hasResolvingSelectors =\n\t\t\t\tselect( coreStore ).hasResolvingSelectors();\n\t\t\treturn ! loaded && ! hasResolvingSelectors;\n\t\t},\n\t\t[ loaded ]\n\t);\n\n\t/*\n\t * If the maximum expected loading time has passed, we're marking the\n\t * editor as loaded, in order to prevent any failed requests from blocking\n\t * the editor canvas from appearing.\n\t */\n\tuseEffect( () => {\n\t\tlet timeout;\n\n\t\tif ( ! loaded ) {\n\t\t\ttimeout = setTimeout( () => {\n\t\t\t\tsetLoaded( true );\n\t\t\t}, MAX_LOADING_TIME );\n\t\t}\n\n\t\treturn () => {\n\t\t\tclearTimeout( timeout );\n\t\t};\n\t}, [ loaded ] );\n\n\tuseEffect( () => {\n\t\tif ( inLoadingPause ) {\n\t\t\t/*\n\t\t\t * We're using an arbitrary
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_coreData","_useEditedEntityRecord","_interopRequireDefault","MAX_LOADING_TIME","useIsSiteEditorLoading","isLoaded","hasLoadedPost","useEditedEntityRecord","loaded","setLoaded","useState","inLoadingPause","useSelect","select","hasResolvingSelectors","coreStore","useEffect","timeout","setTimeout","clearTimeout","ARTIFICIAL_DELAY"],"sources":["@wordpress/edit-site/src/components/layout/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport useEditedEntityRecord from '../use-edited-entity-record';\n\nconst MAX_LOADING_TIME = 10000; // 10 seconds\n\nexport function useIsSiteEditorLoading() {\n\tconst { isLoaded: hasLoadedPost } = useEditedEntityRecord();\n\tconst [ loaded, setLoaded ] = useState( false );\n\tconst inLoadingPause = useSelect(\n\t\t( select ) => {\n\t\t\tconst hasResolvingSelectors =\n\t\t\t\tselect( coreStore ).hasResolvingSelectors();\n\t\t\treturn ! loaded && ! hasResolvingSelectors;\n\t\t},\n\t\t[ loaded ]\n\t);\n\n\t/*\n\t * If the maximum expected loading time has passed, we're marking the\n\t * editor as loaded, in order to prevent any failed requests from blocking\n\t * the editor canvas from appearing.\n\t */\n\tuseEffect( () => {\n\t\tlet timeout;\n\n\t\tif ( ! loaded ) {\n\t\t\ttimeout = setTimeout( () => {\n\t\t\t\tsetLoaded( true );\n\t\t\t}, MAX_LOADING_TIME );\n\t\t}\n\n\t\treturn () => {\n\t\t\tclearTimeout( timeout );\n\t\t};\n\t}, [ loaded ] );\n\n\tuseEffect( () => {\n\t\tif ( inLoadingPause ) {\n\t\t\t/*\n\t\t\t * We're using an arbitrary 100ms timeout here to catch brief\n\t\t\t * moments without any resolving selectors that would result in\n\t\t\t * displaying brief flickers of loading state and loaded state.\n\t\t\t *\n\t\t\t * It's worth experimenting with different values, since this also\n\t\t\t * adds 100ms of artificial delay after loading has finished.\n\t\t\t */\n\t\t\tconst ARTIFICIAL_DELAY = 100;\n\t\t\tconst timeout = setTimeout( () => {\n\t\t\t\tsetLoaded( true );\n\t\t\t}, ARTIFICIAL_DELAY );\n\n\t\t\treturn () => {\n\t\t\t\tclearTimeout( timeout );\n\t\t\t};\n\t\t}\n\t}, [ inLoadingPause ] );\n\n\treturn ! loaded || ! hasLoadedPost;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,sBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,MAAMK,gBAAgB,GAAG,KAAK,CAAC,CAAC;;AAEzB,SAASC,sBAAsBA,CAAA,EAAG;EACxC,MAAM;IAAEC,QAAQ,EAAEC;EAAc,CAAC,GAAG,IAAAC,8BAAqB,EAAC,CAAC;EAC3D,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EAC/C,MAAMC,cAAc,GAAG,IAAAC,eAAS,EAC7BC,MAAM,IAAM;IACb,MAAMC,qBAAqB,GAC1BD,MAAM,CAAEE,eAAU,CAAC,CAACD,qBAAqB,CAAC,CAAC;IAC5C,OAAO,CAAEN,MAAM,IAAI,CAAEM,qBAAqB;EAC3C,CAAC,EACD,CAAEN,MAAM,CACT,CAAC;;EAED;AACD;AACA;AACA;AACA;EACC,IAAAQ,kBAAS,EAAE,MAAM;IAChB,IAAIC,OAAO;IAEX,IAAK,CAAET,MAAM,EAAG;MACfS,OAAO,GAAGC,UAAU,CAAE,MAAM;QAC3BT,SAAS,CAAE,IAAK,CAAC;MAClB,CAAC,EAAEN,gBAAiB,CAAC;IACtB;IAEA,OAAO,MAAM;MACZgB,YAAY,CAAEF,OAAQ,CAAC;IACxB,CAAC;EACF,CAAC,EAAE,CAAET,MAAM,CAAG,CAAC;EAEf,IAAAQ,kBAAS,EAAE,MAAM;IAChB,IAAKL,cAAc,EAAG;MACrB;AACH;AACA;AACA;AACA;AACA;AACA;AACA;MACG,MAAMS,gBAAgB,GAAG,GAAG;MAC5B,MAAMH,OAAO,GAAGC,UAAU,CAAE,MAAM;QACjCT,SAAS,CAAE,IAAK,CAAC;MAClB,CAAC,EAAEW,gBAAiB,CAAC;MAErB,OAAO,MAAM;QACZD,YAAY,CAAEF,OAAQ,CAAC;MACxB,CAAC;IACF;EACD,CAAC,EAAE,CAAEN,cAAc,CAAG,CAAC;EAEvB,OAAO,CAAEH,MAAM,IAAI,CAAEF,aAAa;AACnC"}
|
|
@@ -17,13 +17,10 @@ var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
|
|
|
17
17
|
var _commands = require("@wordpress/commands");
|
|
18
18
|
var _preferences = require("@wordpress/preferences");
|
|
19
19
|
var _blockEditor = require("@wordpress/block-editor");
|
|
20
|
-
var _router = require("@wordpress/router");
|
|
21
20
|
var _coreCommands = require("@wordpress/core-commands");
|
|
22
21
|
var _sidebar = _interopRequireDefault(require("../sidebar"));
|
|
23
|
-
var _editor = _interopRequireDefault(require("../editor"));
|
|
24
22
|
var _errorBoundary = _interopRequireDefault(require("../error-boundary"));
|
|
25
23
|
var _store = require("../../store");
|
|
26
|
-
var _getIsListPage = _interopRequireDefault(require("../../utils/get-is-list-page"));
|
|
27
24
|
var _headerEditMode = _interopRequireDefault(require("../header-edit-mode"));
|
|
28
25
|
var _useInitEditedEntityFromUrl = _interopRequireDefault(require("../sync-state-with-url/use-init-edited-entity-from-url"));
|
|
29
26
|
var _siteHub = _interopRequireDefault(require("../site-hub"));
|
|
@@ -35,8 +32,8 @@ var _register = _interopRequireDefault(require("../keyboard-shortcuts/register")
|
|
|
35
32
|
var _global = _interopRequireDefault(require("../keyboard-shortcuts/global"));
|
|
36
33
|
var _useCommonCommands = require("../../hooks/commands/use-common-commands");
|
|
37
34
|
var _useEditModeCommands = require("../../hooks/commands/use-edit-mode-commands");
|
|
38
|
-
var _pageMain = _interopRequireDefault(require("../page-main"));
|
|
39
35
|
var _hooks = require("./hooks");
|
|
36
|
+
var _router = _interopRequireDefault(require("./router"));
|
|
40
37
|
/**
|
|
41
38
|
* External dependencies
|
|
42
39
|
*/
|
|
@@ -55,9 +52,6 @@ const {
|
|
|
55
52
|
const {
|
|
56
53
|
useCommandContext
|
|
57
54
|
} = (0, _lockUnlock.unlock)(_commands.privateApis);
|
|
58
|
-
const {
|
|
59
|
-
useLocation
|
|
60
|
-
} = (0, _lockUnlock.unlock)(_router.privateApis);
|
|
61
55
|
const {
|
|
62
56
|
useGlobalStyle
|
|
63
57
|
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
@@ -70,12 +64,7 @@ function Layout() {
|
|
|
70
64
|
(0, _useEditModeCommands.useEditModeCommands)();
|
|
71
65
|
(0, _useCommonCommands.useCommonCommands)();
|
|
72
66
|
(0, _blockEditor.useBlockCommands)();
|
|
73
|
-
const {
|
|
74
|
-
params
|
|
75
|
-
} = useLocation();
|
|
76
67
|
const isMobileViewport = (0, _compose.useViewportMatch)('medium', '<');
|
|
77
|
-
const isListPage = (0, _getIsListPage.default)(params, isMobileViewport);
|
|
78
|
-
const isEditorPage = !isListPage;
|
|
79
68
|
const {
|
|
80
69
|
isDistractionFree,
|
|
81
70
|
hasFixedToolbar,
|
|
@@ -99,19 +88,19 @@ function Layout() {
|
|
|
99
88
|
hasBlockSelected: select(_blockEditor.store).getBlockSelectionStart()
|
|
100
89
|
};
|
|
101
90
|
}, []);
|
|
102
|
-
const isEditing = canvasMode === 'edit';
|
|
103
91
|
const navigateRegionsProps = (0, _components.__unstableUseNavigateRegions)({
|
|
104
92
|
previous: previousShortcut,
|
|
105
93
|
next: nextShortcut
|
|
106
94
|
});
|
|
107
95
|
const disableMotion = (0, _compose.useReducedMotion)();
|
|
108
|
-
const showSidebar = isMobileViewport && canvasMode === 'view' && !isListPage || !isMobileViewport && (canvasMode === 'view' || !isEditorPage);
|
|
109
|
-
const showCanvas = isMobileViewport && isEditorPage && isEditing || !isMobileViewport || !isEditorPage;
|
|
110
|
-
const isFullCanvas = isMobileViewport && isListPage || isEditorPage && isEditing;
|
|
111
96
|
const [canvasResizer, canvasSize] = (0, _compose.useResizeObserver)();
|
|
112
97
|
const [fullResizer] = (0, _compose.useResizeObserver)();
|
|
113
98
|
const isEditorLoading = (0, _hooks.useIsSiteEditorLoading)();
|
|
114
99
|
const [isResizableFrameOversized, setIsResizableFrameOversized] = (0, _element.useState)(false);
|
|
100
|
+
const {
|
|
101
|
+
areas,
|
|
102
|
+
widths
|
|
103
|
+
} = (0, _router.default)();
|
|
115
104
|
|
|
116
105
|
// This determines which animation variant should apply to the header.
|
|
117
106
|
// There is also a `isDistractionFreeHovering` state that gets priority
|
|
@@ -135,7 +124,7 @@ function Layout() {
|
|
|
135
124
|
|
|
136
125
|
// Sets the right context for the command palette
|
|
137
126
|
let commandContext = 'site-editor';
|
|
138
|
-
if (canvasMode === 'edit'
|
|
127
|
+
if (canvasMode === 'edit') {
|
|
139
128
|
commandContext = 'site-editor-edit';
|
|
140
129
|
}
|
|
141
130
|
if (hasBlockSelected) {
|
|
@@ -155,9 +144,8 @@ function Layout() {
|
|
|
155
144
|
...navigateRegionsProps,
|
|
156
145
|
ref: navigateRegionsProps.ref,
|
|
157
146
|
className: (0, _classnames.default)('edit-site-layout', navigateRegionsProps.className, {
|
|
158
|
-
'is-distraction-free': isDistractionFree &&
|
|
159
|
-
'is-full-canvas':
|
|
160
|
-
'is-edit-mode': isEditing,
|
|
147
|
+
'is-distraction-free': isDistractionFree && canvasMode === 'edit',
|
|
148
|
+
'is-full-canvas': canvasMode === 'edit',
|
|
161
149
|
'has-fixed-toolbar': hasFixedToolbar,
|
|
162
150
|
'is-block-toolbar-visible': hasBlockSelected
|
|
163
151
|
})
|
|
@@ -196,7 +184,7 @@ function Layout() {
|
|
|
196
184
|
className: "edit-site-layout__hub"
|
|
197
185
|
}), (0, _react.createElement)(_components.__unstableAnimatePresence, {
|
|
198
186
|
initial: false
|
|
199
|
-
},
|
|
187
|
+
}, canvasMode === 'edit' && (0, _react.createElement)(_interface.NavigableRegion, {
|
|
200
188
|
key: "header",
|
|
201
189
|
className: "edit-site-layout__header",
|
|
202
190
|
ariaLabel: (0, _i18n.__)('Editor top bar'),
|
|
@@ -236,7 +224,7 @@ function Layout() {
|
|
|
236
224
|
}, (0, _react.createElement)(_interface.NavigableRegion, {
|
|
237
225
|
ariaLabel: (0, _i18n.__)('Navigation'),
|
|
238
226
|
className: "edit-site-layout__sidebar-region"
|
|
239
|
-
}, (0, _react.createElement)(_components.__unstableAnimatePresence, null,
|
|
227
|
+
}, (0, _react.createElement)(_components.__unstableAnimatePresence, null, canvasMode === 'view' && (0, _react.createElement)(_components.__unstableMotion.div, {
|
|
240
228
|
initial: {
|
|
241
229
|
opacity: 0
|
|
242
230
|
},
|
|
@@ -254,10 +242,15 @@ function Layout() {
|
|
|
254
242
|
ease: 'easeOut'
|
|
255
243
|
},
|
|
256
244
|
className: "edit-site-layout__sidebar"
|
|
257
|
-
}, (0, _react.createElement)(_sidebar.default, null)))), (0, _react.createElement)(_savePanel.default, null),
|
|
245
|
+
}, (0, _react.createElement)(_sidebar.default, null)))), (0, _react.createElement)(_savePanel.default, null), areas.content && canvasMode !== 'edit' && (0, _react.createElement)("div", {
|
|
246
|
+
className: "edit-site-layout__area",
|
|
247
|
+
style: {
|
|
248
|
+
maxWidth: widths?.content
|
|
249
|
+
}
|
|
250
|
+
}, areas.content), areas.preview && (0, _react.createElement)("div", {
|
|
258
251
|
className: "edit-site-layout__canvas-container"
|
|
259
252
|
}, canvasResizer, !!canvasSize.width && (0, _react.createElement)(_components.__unstableMotion.div, {
|
|
260
|
-
whileHover:
|
|
253
|
+
whileHover: canvasMode === 'view' ? {
|
|
261
254
|
scale: 1.005,
|
|
262
255
|
transition: {
|
|
263
256
|
duration: disableMotion ? 0 : 0.5,
|
|
@@ -276,7 +269,7 @@ function Layout() {
|
|
|
276
269
|
}
|
|
277
270
|
}, (0, _react.createElement)(_errorBoundary.default, null, (0, _react.createElement)(_resizableFrame.default, {
|
|
278
271
|
isReady: !isEditorLoading,
|
|
279
|
-
isFullWidth:
|
|
272
|
+
isFullWidth: canvasMode === 'edit',
|
|
280
273
|
defaultSize: {
|
|
281
274
|
width: canvasSize.width - 24 /* $canvas-padding */,
|
|
282
275
|
height: canvasSize.height
|
|
@@ -286,8 +279,6 @@ function Layout() {
|
|
|
286
279
|
innerContentStyle: {
|
|
287
280
|
background: gradientValue !== null && gradientValue !== void 0 ? gradientValue : backgroundColor
|
|
288
281
|
}
|
|
289
|
-
},
|
|
290
|
-
isLoading: isEditorLoading
|
|
291
|
-
})))))))));
|
|
282
|
+
}, areas.preview)))))));
|
|
292
283
|
}
|
|
293
284
|
//# sourceMappingURL=index.js.map
|