@wordpress/edit-site 5.19.0 → 5.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/add-new-pattern/index.js +3 -3
- package/build/components/add-new-pattern/index.js.map +1 -1
- package/build/components/block-editor/block-editor-provider/default-block-editor-provider.js +73 -0
- package/build/components/block-editor/block-editor-provider/default-block-editor-provider.js.map +1 -0
- package/build/components/block-editor/block-editor-provider/index.js +31 -0
- package/build/components/block-editor/block-editor-provider/index.js.map +1 -0
- package/build/components/block-editor/{providers → block-editor-provider}/navigation-block-editor-provider.js +2 -1
- package/build/components/block-editor/block-editor-provider/navigation-block-editor-provider.js.map +1 -0
- package/build/components/block-editor/block-editor-provider/use-page-content-blocks.js +76 -0
- package/build/components/block-editor/block-editor-provider/use-page-content-blocks.js.map +1 -0
- package/build/components/block-editor/index.js +2 -9
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/block-editor/site-editor-canvas.js +1 -1
- package/build/components/block-editor/site-editor-canvas.js.map +1 -1
- package/build/components/create-template-part-modal/index.js +8 -12
- package/build/components/create-template-part-modal/index.js.map +1 -1
- package/build/components/editor/index.js +4 -1
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/font-families.js +2 -1
- package/build/components/global-styles/font-families.js.map +1 -1
- package/build/components/global-styles/font-family-item.js +2 -2
- package/build/components/global-styles/font-family-item.js.map +1 -1
- package/build/components/global-styles/font-library-modal/collection-font-details.js +49 -0
- package/build/components/global-styles/font-library-modal/collection-font-details.js.map +1 -0
- package/build/components/global-styles/font-library-modal/collection-font-variant.js +55 -0
- package/build/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -0
- package/build/components/global-styles/font-library-modal/context.js +26 -2
- package/build/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build/components/global-styles/font-library-modal/font-card.js +7 -4
- package/build/components/global-styles/font-library-modal/font-card.js.map +1 -1
- package/build/components/global-styles/font-library-modal/font-collection.js +172 -0
- package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -0
- package/build/components/global-styles/font-library-modal/font-demo.js +30 -13
- package/build/components/global-styles/font-library-modal/font-demo.js.map +1 -1
- package/build/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +41 -0
- package/build/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js.map +1 -0
- package/build/components/global-styles/font-library-modal/index.js +25 -7
- package/build/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js +2 -2
- 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 +0 -5
- 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-details.js +2 -1
- package/build/components/global-styles/font-library-modal/library-font-details.js.map +1 -1
- package/build/components/global-styles/font-library-modal/resolvers.js +16 -0
- package/build/components/global-styles/font-library-modal/resolvers.js.map +1 -1
- package/build/components/global-styles/font-library-modal/tab-layout.js +2 -2
- package/build/components/global-styles/font-library-modal/tab-layout.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/constants.js +1 -7
- package/build/components/global-styles/font-library-modal/utils/constants.js.map +1 -1
- package/build/components/global-styles/font-library-modal/utils/filter-fonts.js +21 -0
- package/build/components/global-styles/font-library-modal/utils/filter-fonts.js.map +1 -0
- package/build/components/global-styles/font-library-modal/utils/fonts-outline.js +20 -0
- package/build/components/global-styles/font-library-modal/utils/fonts-outline.js.map +1 -0
- package/build/components/global-styles/font-library-modal/utils/index.js +2 -52
- 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 +76 -0
- package/build/components/global-styles/font-library-modal/utils/preview-styles.js.map +1 -0
- package/build/components/global-styles/font-library-modal/utils/sort-font-faces.js +36 -0
- package/build/components/global-styles/font-library-modal/utils/sort-font-faces.js.map +1 -0
- package/build/components/global-styles/screen-typography.js +1 -1
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/header-edit-mode/document-actions/index.js +9 -8
- package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
- package/build/components/header-edit-mode/index.js +4 -1
- package/build/components/header-edit-mode/index.js.map +1 -1
- package/build/components/layout/index.js +5 -1
- package/build/components/layout/index.js.map +1 -1
- package/build/components/list/added-by.js +13 -8
- package/build/components/list/added-by.js.map +1 -1
- package/build/components/list/index.js +2 -1
- package/build/components/list/index.js.map +1 -1
- package/build/components/page-content-focus-manager/disable-non-page-content-blocks.js +2 -3
- package/build/components/page-content-focus-manager/disable-non-page-content-blocks.js.map +1 -1
- package/build/components/page-patterns/duplicate-menu-item.js +5 -5
- package/build/components/page-patterns/duplicate-menu-item.js.map +1 -1
- package/build/components/page-patterns/grid-item.js +5 -5
- package/build/components/page-patterns/grid-item.js.map +1 -1
- package/build/components/page-patterns/index.js +1 -1
- package/build/components/page-patterns/index.js.map +1 -1
- package/build/components/page-patterns/search-items.js +1 -1
- package/build/components/page-patterns/search-items.js.map +1 -1
- package/build/components/page-patterns/use-patterns.js +28 -34
- package/build/components/page-patterns/use-patterns.js.map +1 -1
- package/build/components/page-template-parts/add-new-template-part.js +3 -2
- package/build/components/page-template-parts/add-new-template-part.js.map +1 -1
- package/build/components/page-template-parts/index.js +2 -1
- package/build/components/page-template-parts/index.js.map +1 -1
- package/build/components/page-templates/index.js +3 -2
- package/build/components/page-templates/index.js.map +1 -1
- package/build/components/save-hub/index.js +2 -1
- package/build/components/save-hub/index.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +24 -17
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/edit-template.js +21 -3
- package/build/components/sidebar-edit-mode/page-panels/edit-template.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/hooks.js +2 -1
- package/build/components/sidebar-edit-mode/page-panels/hooks.js.map +1 -1
- package/build/components/sidebar-edit-mode/settings-header/index.js +2 -6
- package/build/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/template-panel/pattern-categories.js +9 -2
- package/build/components/sidebar-edit-mode/template-panel/pattern-categories.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/edit-button.js +2 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/edit-button.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +2 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js +3 -2
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-page/page-details.js +2 -1
- package/build/components/sidebar-navigation-screen-page/page-details.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pages/index.js +5 -4
- package/build/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/index.js +2 -1
- package/build/components/sidebar-navigation-screen-pattern/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +3 -2
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +2 -1
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +2 -1
- package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/use-pattern-details.js +8 -7
- package/build/components/sidebar-navigation-screen-pattern/use-pattern-details.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/index.js +3 -3
- package/build/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +7 -2
- package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +7 -2
- package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template/home-template-details.js +2 -1
- package/build/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates/index.js +4 -3
- package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +3 -2
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build/components/start-template-options/index.js +20 -2
- package/build/components/start-template-options/index.js.map +1 -1
- package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -4
- 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 +4 -3
- package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build/components/template-actions/index.js +2 -1
- package/build/components/template-actions/index.js.map +1 -1
- package/build/components/template-actions/rename-menu-item.js +8 -3
- package/build/components/template-actions/rename-menu-item.js.map +1 -1
- package/build/hooks/commands/use-edit-mode-commands.js +4 -3
- package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build/hooks/navigation-menu-edit.js +2 -1
- package/build/hooks/navigation-menu-edit.js.map +1 -1
- package/build/hooks/template-part-edit.js +2 -1
- package/build/hooks/template-part-edit.js.map +1 -1
- package/build/store/actions.js +10 -9
- package/build/store/actions.js.map +1 -1
- package/build/store/constants.js +1 -9
- package/build/store/constants.js.map +1 -1
- package/build/store/private-actions.js +21 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +23 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +19 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +3 -2
- package/build/store/selectors.js.map +1 -1
- package/build/utils/constants.js +22 -3
- package/build/utils/constants.js.map +1 -1
- package/build/utils/is-template-removable.js +1 -1
- package/build/utils/is-template-removable.js.map +1 -1
- package/build/utils/is-template-revertable.js +1 -1
- package/build/utils/is-template-revertable.js.map +1 -1
- package/build/utils/template-part-create.js +6 -1
- package/build/utils/template-part-create.js.map +1 -1
- package/build-module/components/add-new-pattern/index.js +3 -3
- package/build-module/components/add-new-pattern/index.js.map +1 -1
- package/build-module/components/block-editor/block-editor-provider/default-block-editor-provider.js +65 -0
- package/build-module/components/block-editor/block-editor-provider/default-block-editor-provider.js.map +1 -0
- package/build-module/components/block-editor/block-editor-provider/index.js +23 -0
- package/build-module/components/block-editor/block-editor-provider/index.js.map +1 -0
- package/build-module/components/block-editor/{providers → block-editor-provider}/navigation-block-editor-provider.js +2 -1
- package/build-module/components/block-editor/block-editor-provider/navigation-block-editor-provider.js.map +1 -0
- package/build-module/components/block-editor/block-editor-provider/use-page-content-blocks.js +70 -0
- package/build-module/components/block-editor/block-editor-provider/use-page-content-blocks.js.map +1 -0
- package/build-module/components/block-editor/index.js +1 -8
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/block-editor/site-editor-canvas.js +2 -2
- package/build-module/components/block-editor/site-editor-canvas.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +8 -12
- package/build-module/components/create-template-part-modal/index.js.map +1 -1
- package/build-module/components/editor/index.js +4 -1
- package/build-module/components/editor/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 +2 -2
- package/build-module/components/global-styles/font-family-item.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/collection-font-details.js +40 -0
- package/build-module/components/global-styles/font-library-modal/collection-font-details.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/collection-font-variant.js +45 -0
- package/build-module/components/global-styles/font-library-modal/collection-font-variant.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/context.js +27 -3
- package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/font-card.js +8 -5
- package/build-module/components/global-styles/font-library-modal/font-card.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/font-collection.js +164 -0
- package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/font-demo.js +30 -13
- package/build-module/components/global-styles/font-library-modal/font-demo.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +33 -0
- package/build-module/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/index.js +26 -7
- 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 +2 -2
- 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 +0 -5
- 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-details.js +2 -1
- package/build-module/components/global-styles/font-library-modal/library-font-details.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/resolvers.js +14 -0
- package/build-module/components/global-styles/font-library-modal/resolvers.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/tab-layout.js +2 -2
- package/build-module/components/global-styles/font-library-modal/tab-layout.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/constants.js +1 -6
- package/build-module/components/global-styles/font-library-modal/utils/constants.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/utils/filter-fonts.js +15 -0
- package/build-module/components/global-styles/font-library-modal/utils/filter-fonts.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/utils/fonts-outline.js +13 -0
- package/build-module/components/global-styles/font-library-modal/utils/fonts-outline.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/utils/index.js +2 -51
- 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 +68 -0
- package/build-module/components/global-styles/font-library-modal/utils/preview-styles.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/utils/sort-font-faces.js +30 -0
- package/build-module/components/global-styles/font-library-modal/utils/sort-font-faces.js.map +1 -0
- package/build-module/components/global-styles/screen-typography.js +1 -1
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/header-edit-mode/document-actions/index.js +9 -8
- package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
- package/build-module/components/header-edit-mode/index.js +4 -1
- package/build-module/components/header-edit-mode/index.js.map +1 -1
- package/build-module/components/layout/index.js +5 -1
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/list/added-by.js +13 -8
- package/build-module/components/list/added-by.js.map +1 -1
- package/build-module/components/list/index.js +2 -1
- package/build-module/components/list/index.js.map +1 -1
- package/build-module/components/page-content-focus-manager/disable-non-page-content-blocks.js +2 -3
- package/build-module/components/page-content-focus-manager/disable-non-page-content-blocks.js.map +1 -1
- package/build-module/components/page-patterns/duplicate-menu-item.js +5 -5
- package/build-module/components/page-patterns/duplicate-menu-item.js.map +1 -1
- package/build-module/components/page-patterns/grid-item.js +5 -5
- package/build-module/components/page-patterns/grid-item.js.map +1 -1
- package/build-module/components/page-patterns/index.js +1 -1
- package/build-module/components/page-patterns/index.js.map +1 -1
- package/build-module/components/page-patterns/search-items.js +2 -2
- package/build-module/components/page-patterns/search-items.js.map +1 -1
- package/build-module/components/page-patterns/use-patterns.js +28 -35
- package/build-module/components/page-patterns/use-patterns.js.map +1 -1
- package/build-module/components/page-template-parts/add-new-template-part.js +3 -2
- package/build-module/components/page-template-parts/add-new-template-part.js.map +1 -1
- package/build-module/components/page-template-parts/index.js +2 -1
- package/build-module/components/page-template-parts/index.js.map +1 -1
- package/build-module/components/page-templates/index.js +3 -2
- package/build-module/components/page-templates/index.js.map +1 -1
- package/build-module/components/save-hub/index.js +2 -1
- package/build-module/components/save-hub/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +26 -19
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/edit-template.js +21 -3
- package/build-module/components/sidebar-edit-mode/page-panels/edit-template.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/hooks.js +2 -1
- package/build-module/components/sidebar-edit-mode/page-panels/hooks.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/settings-header/index.js +2 -6
- package/build-module/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/template-panel/pattern-categories.js +9 -2
- package/build-module/components/sidebar-edit-mode/template-panel/pattern-categories.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/edit-button.js +2 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/edit-button.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +3 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +3 -2
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-page/page-details.js +2 -1
- package/build-module/components/sidebar-navigation-screen-page/page-details.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pages/index.js +5 -4
- package/build-module/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/index.js +2 -1
- package/build-module/components/sidebar-navigation-screen-pattern/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +3 -2
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +2 -1
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +2 -1
- package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/use-pattern-details.js +8 -7
- package/build-module/components/sidebar-navigation-screen-pattern/use-pattern-details.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/index.js +4 -4
- package/build-module/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +8 -3
- package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +7 -2
- package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template/home-template-details.js +2 -1
- package/build-module/components/sidebar-navigation-screen-template/home-template-details.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates/index.js +4 -3
- package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +3 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
- package/build-module/components/start-template-options/index.js +20 -2
- package/build-module/components/start-template-options/index.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -4
- 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 +4 -3
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build-module/components/template-actions/index.js +2 -1
- package/build-module/components/template-actions/index.js.map +1 -1
- package/build-module/components/template-actions/rename-menu-item.js +8 -3
- package/build-module/components/template-actions/rename-menu-item.js.map +1 -1
- package/build-module/hooks/commands/use-edit-mode-commands.js +4 -3
- package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build-module/hooks/navigation-menu-edit.js +2 -1
- package/build-module/hooks/navigation-menu-edit.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +2 -1
- package/build-module/hooks/template-part-edit.js.map +1 -1
- package/build-module/store/actions.js +10 -10
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/constants.js +0 -4
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/private-actions.js +19 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +22 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +18 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +3 -3
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/constants.js +17 -1
- package/build-module/utils/constants.js.map +1 -1
- package/build-module/utils/is-template-removable.js +2 -2
- package/build-module/utils/is-template-removable.js.map +1 -1
- package/build-module/utils/is-template-revertable.js +2 -2
- package/build-module/utils/is-template-revertable.js.map +1 -1
- package/build-module/utils/template-part-create.js +6 -1
- package/build-module/utils/template-part-create.js.map +1 -1
- package/build-style/style-rtl.css +23 -0
- package/build-style/style.css +23 -0
- package/package.json +40 -40
- package/src/components/add-new-pattern/index.js +3 -3
- package/src/components/block-editor/block-editor-provider/default-block-editor-provider.js +70 -0
- package/src/components/block-editor/block-editor-provider/index.js +29 -0
- package/src/components/block-editor/{providers → block-editor-provider}/navigation-block-editor-provider.js +2 -1
- package/src/components/block-editor/block-editor-provider/test/use-page-content-blocks.js +87 -0
- package/src/components/block-editor/block-editor-provider/use-page-content-blocks.js +77 -0
- package/src/components/block-editor/index.js +1 -14
- package/src/components/block-editor/site-editor-canvas.js +5 -2
- package/src/components/create-template-part-modal/index.js +11 -12
- package/src/components/editor/index.js +6 -2
- package/src/components/global-styles/font-families.js +5 -1
- package/src/components/global-styles/font-family-item.js +2 -2
- package/src/components/global-styles/font-library-modal/collection-font-details.js +56 -0
- package/src/components/global-styles/font-library-modal/collection-font-variant.js +45 -0
- package/src/components/global-styles/font-library-modal/context.js +33 -2
- package/src/components/global-styles/font-library-modal/font-card.js +9 -4
- package/src/components/global-styles/font-library-modal/font-collection.js +257 -0
- package/src/components/global-styles/font-library-modal/font-demo.js +36 -10
- package/src/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +50 -0
- package/src/components/global-styles/font-library-modal/index.js +30 -5
- package/src/components/global-styles/font-library-modal/installed-fonts.js +1 -1
- package/src/components/global-styles/font-library-modal/library-font-card.js +1 -8
- package/src/components/global-styles/font-library-modal/library-font-details.js +2 -3
- package/src/components/global-styles/font-library-modal/resolvers.js +16 -0
- package/src/components/global-styles/font-library-modal/style.scss +26 -0
- package/src/components/global-styles/font-library-modal/tab-layout.js +2 -2
- package/src/components/global-styles/font-library-modal/utils/constants.js +1 -9
- package/src/components/global-styles/font-library-modal/utils/filter-fonts.js +18 -0
- package/src/components/global-styles/font-library-modal/utils/fonts-outline.js +21 -0
- package/src/components/global-styles/font-library-modal/utils/index.js +9 -69
- package/src/components/global-styles/font-library-modal/utils/preview-styles.js +86 -0
- package/src/components/global-styles/font-library-modal/utils/sort-font-faces.js +33 -0
- package/src/components/global-styles/font-library-modal/utils/test/filter-fonts.spec.js +69 -0
- package/src/components/global-styles/font-library-modal/utils/test/fonts-outline.spec.js +109 -0
- package/src/components/global-styles/font-library-modal/utils/test/{getPreviewStyle.spec.js → preview-styles.spec.js} +49 -9
- package/src/components/global-styles/font-library-modal/utils/test/sort-font-faces.js +74 -0
- package/src/components/global-styles/screen-typography.js +4 -1
- package/src/components/header-edit-mode/document-actions/index.js +17 -8
- package/src/components/header-edit-mode/index.js +2 -1
- package/src/components/layout/index.js +10 -1
- package/src/components/list/added-by.js +29 -11
- package/src/components/list/index.js +7 -1
- package/src/components/page-content-focus-manager/disable-non-page-content-blocks.js +2 -8
- package/src/components/page-patterns/duplicate-menu-item.js +5 -5
- package/src/components/page-patterns/grid-item.js +5 -5
- package/src/components/page-patterns/index.js +1 -1
- package/src/components/page-patterns/search-items.js +7 -1
- package/src/components/page-patterns/use-patterns.js +190 -134
- package/src/components/page-template-parts/add-new-template-part.js +5 -2
- package/src/components/page-template-parts/index.js +2 -1
- package/src/components/page-templates/index.js +3 -2
- package/src/components/save-hub/index.js +2 -1
- package/src/components/secondary-sidebar/list-view-sidebar.js +31 -26
- package/src/components/sidebar-edit-mode/page-panels/edit-template.js +48 -20
- package/src/components/sidebar-edit-mode/page-panels/hooks.js +9 -4
- package/src/components/sidebar-edit-mode/page-panels/style.scss +6 -0
- package/src/components/sidebar-edit-mode/settings-header/index.js +4 -7
- package/src/components/sidebar-edit-mode/template-panel/pattern-categories.js +9 -2
- package/src/components/sidebar-navigation-screen-navigation-menu/edit-button.js +2 -1
- package/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +3 -1
- package/src/components/sidebar-navigation-screen-navigation-menus/index.js +3 -2
- package/src/components/sidebar-navigation-screen-page/page-details.js +2 -1
- package/src/components/sidebar-navigation-screen-pages/index.js +5 -4
- package/src/components/sidebar-navigation-screen-pattern/index.js +2 -1
- package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu-list-item.js +8 -2
- package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +7 -1
- package/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +2 -1
- package/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js +18 -8
- package/src/components/sidebar-navigation-screen-patterns/index.js +8 -4
- package/src/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +16 -3
- package/src/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +12 -2
- package/src/components/sidebar-navigation-screen-template/home-template-details.js +2 -1
- package/src/components/sidebar-navigation-screen-templates/index.js +4 -3
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +6 -2
- package/src/components/start-template-options/index.js +39 -2
- package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +10 -4
- package/src/components/sync-state-with-url/use-sync-path-with-url.js +8 -3
- package/src/components/template-actions/index.js +2 -1
- package/src/components/template-actions/rename-menu-item.js +8 -3
- package/src/hooks/commands/use-edit-mode-commands.js +4 -3
- package/src/hooks/navigation-menu-edit.js +2 -1
- package/src/hooks/template-part-edit.js +2 -1
- package/src/store/actions.js +18 -10
- package/src/store/constants.js +0 -5
- package/src/store/private-actions.js +19 -0
- package/src/store/private-selectors.js +22 -0
- package/src/store/reducer.js +18 -0
- package/src/store/selectors.js +6 -3
- package/src/store/test/reducer.js +18 -0
- package/src/utils/constants.js +17 -1
- package/src/utils/is-template-removable.js +2 -2
- package/src/utils/is-template-revertable.js +2 -2
- package/src/utils/template-part-create.js +6 -1
- package/build/components/block-editor/get-block-editor-provider.js +0 -35
- package/build/components/block-editor/get-block-editor-provider.js.map +0 -1
- package/build/components/block-editor/providers/default-block-editor-provider.js +0 -49
- package/build/components/block-editor/providers/default-block-editor-provider.js.map +0 -1
- package/build/components/block-editor/providers/navigation-block-editor-provider.js.map +0 -1
- package/build-module/components/block-editor/get-block-editor-provider.js +0 -28
- package/build-module/components/block-editor/get-block-editor-provider.js.map +0 -1
- package/build-module/components/block-editor/providers/default-block-editor-provider.js +0 -41
- package/build-module/components/block-editor/providers/default-block-editor-provider.js.map +0 -1
- package/build-module/components/block-editor/providers/navigation-block-editor-provider.js.map +0 -1
- package/src/components/block-editor/get-block-editor-provider.js +0 -29
- package/src/components/block-editor/providers/default-block-editor-provider.js +0 -44
|
@@ -4,9 +4,9 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
*/
|
|
5
5
|
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
6
6
|
import { Button } from '@wordpress/components';
|
|
7
|
-
import { useFocusOnMount,
|
|
7
|
+
import { useFocusOnMount, useMergeRefs } from '@wordpress/compose';
|
|
8
8
|
import { useDispatch } from '@wordpress/data';
|
|
9
|
-
import { useRef, useState } from '@wordpress/element';
|
|
9
|
+
import { useCallback, useRef, useState } from '@wordpress/element';
|
|
10
10
|
import { __ } from '@wordpress/i18n';
|
|
11
11
|
import { closeSmall } from '@wordpress/icons';
|
|
12
12
|
import { ESCAPE } from '@wordpress/keycodes';
|
|
@@ -21,21 +21,27 @@ import { unlock } from '../../lock-unlock';
|
|
|
21
21
|
const {
|
|
22
22
|
PrivateListView
|
|
23
23
|
} = unlock(blockEditorPrivateApis);
|
|
24
|
-
export default function ListViewSidebar(
|
|
24
|
+
export default function ListViewSidebar({
|
|
25
|
+
listViewToggleElement
|
|
26
|
+
}) {
|
|
25
27
|
const {
|
|
26
28
|
setIsListViewOpened
|
|
27
29
|
} = useDispatch(editSiteStore);
|
|
28
30
|
|
|
29
31
|
// This hook handles focus when the sidebar first renders.
|
|
30
32
|
const focusOnMountRef = useFocusOnMount('firstElement');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
// When closing the list view, focus should return to the toggle button.
|
|
35
|
+
const closeListView = useCallback(() => {
|
|
36
|
+
setIsListViewOpened(false);
|
|
37
|
+
listViewToggleElement?.focus();
|
|
38
|
+
}, [listViewToggleElement, setIsListViewOpened]);
|
|
39
|
+
const closeOnEscape = useCallback(event => {
|
|
35
40
|
if (event.keyCode === ESCAPE && !event.defaultPrevented) {
|
|
36
|
-
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
closeListView();
|
|
37
43
|
}
|
|
38
|
-
}
|
|
44
|
+
}, [closeListView]);
|
|
39
45
|
|
|
40
46
|
// Use internal state instead of a ref to make sure that the component
|
|
41
47
|
// re-renders when the dropZoneElement updates.
|
|
@@ -59,17 +65,19 @@ export default function ListViewSidebar() {
|
|
|
59
65
|
const listViewFocusArea = sidebarRef.current.contains(listViewApplicationFocus) ? listViewApplicationFocus : sidebarCloseButtonRef.current;
|
|
60
66
|
listViewFocusArea.focus();
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
// This only fires when the sidebar is open because of the conditional rendering. It is the same shortcut to open but that is defined as a global shortcut and only fires when the sidebar is closed.
|
|
64
|
-
useShortcut('core/edit-site/toggle-list-view', () => {
|
|
68
|
+
const handleToggleListViewShortcut = useCallback(() => {
|
|
65
69
|
// If the sidebar has focus, it is safe to close.
|
|
66
70
|
if (sidebarRef.current.contains(sidebarRef.current.ownerDocument.activeElement)) {
|
|
67
|
-
|
|
68
|
-
// If the list view or close button does not have focus, focus should be moved to it.
|
|
71
|
+
closeListView();
|
|
69
72
|
} else {
|
|
73
|
+
// If the list view or close button does not have focus, focus should be moved to it.
|
|
70
74
|
handleSidebarFocus();
|
|
71
75
|
}
|
|
72
|
-
});
|
|
76
|
+
}, [closeListView]);
|
|
77
|
+
|
|
78
|
+
// This only fires when the sidebar is open because of the conditional rendering.
|
|
79
|
+
// It is the same shortcut to open but that is defined as a global shortcut and only fires when the sidebar is closed.
|
|
80
|
+
useShortcut('core/edit-site/toggle-list-view', handleToggleListViewShortcut);
|
|
73
81
|
return (
|
|
74
82
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
75
83
|
createElement("div", {
|
|
@@ -77,16 +85,15 @@ export default function ListViewSidebar() {
|
|
|
77
85
|
onKeyDown: closeOnEscape,
|
|
78
86
|
ref: sidebarRef
|
|
79
87
|
}, createElement("div", {
|
|
80
|
-
className: "edit-site-editor__list-view-panel-header"
|
|
81
|
-
ref: headerFocusReturnRef
|
|
88
|
+
className: "edit-site-editor__list-view-panel-header"
|
|
82
89
|
}, createElement("strong", null, __('List View')), createElement(Button, {
|
|
83
90
|
icon: closeSmall,
|
|
84
91
|
label: __('Close'),
|
|
85
|
-
onClick:
|
|
92
|
+
onClick: closeListView,
|
|
86
93
|
ref: sidebarCloseButtonRef
|
|
87
94
|
})), createElement("div", {
|
|
88
95
|
className: "edit-site-editor__list-view-panel-content",
|
|
89
|
-
ref: useMergeRefs([
|
|
96
|
+
ref: useMergeRefs([focusOnMountRef, setDropZoneElement, listViewRef])
|
|
90
97
|
}, createElement(PrivateListView, {
|
|
91
98
|
dropZoneElement: dropZoneElement
|
|
92
99
|
})))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","blockEditorPrivateApis","Button","useFocusOnMount","
|
|
1
|
+
{"version":3,"names":["privateApis","blockEditorPrivateApis","Button","useFocusOnMount","useMergeRefs","useDispatch","useCallback","useRef","useState","__","closeSmall","ESCAPE","focus","useShortcut","store","editSiteStore","unlock","PrivateListView","ListViewSidebar","listViewToggleElement","setIsListViewOpened","focusOnMountRef","closeListView","closeOnEscape","event","keyCode","defaultPrevented","preventDefault","dropZoneElement","setDropZoneElement","sidebarRef","sidebarCloseButtonRef","listViewRef","handleSidebarFocus","listViewApplicationFocus","tabbable","find","current","listViewFocusArea","contains","handleToggleListViewShortcut","ownerDocument","activeElement","createElement","className","onKeyDown","ref","icon","label","onClick"],"sources":["@wordpress/edit-site/src/components/secondary-sidebar/list-view-sidebar.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { Button } from '@wordpress/components';\nimport { useFocusOnMount, useMergeRefs } from '@wordpress/compose';\nimport { useDispatch } from '@wordpress/data';\nimport { useCallback, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { closeSmall } from '@wordpress/icons';\nimport { ESCAPE } from '@wordpress/keycodes';\nimport { focus } from '@wordpress/dom';\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { PrivateListView } = unlock( blockEditorPrivateApis );\n\nexport default function ListViewSidebar( { listViewToggleElement } ) {\n\tconst { setIsListViewOpened } = useDispatch( editSiteStore );\n\n\t// This hook handles focus when the sidebar first renders.\n\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\n\t// When closing the list view, focus should return to the toggle button.\n\tconst closeListView = useCallback( () => {\n\t\tsetIsListViewOpened( false );\n\t\tlistViewToggleElement?.focus();\n\t}, [ listViewToggleElement, setIsListViewOpened ] );\n\n\tconst closeOnEscape = useCallback(\n\t\t( event ) => {\n\t\t\tif ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcloseListView();\n\t\t\t}\n\t\t},\n\t\t[ closeListView ]\n\t);\n\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the dropZoneElement updates.\n\tconst [ dropZoneElement, setDropZoneElement ] = useState( null );\n\n\t// This ref refers to the sidebar as a whole.\n\tconst sidebarRef = useRef();\n\t// This ref refers to the close button.\n\tconst sidebarCloseButtonRef = useRef();\n\t// This ref refers to the list view application area.\n\tconst listViewRef = useRef();\n\n\t/*\n\t * Callback function to handle list view or close button focus.\n\t *\n\t * @return void\n\t */\n\tfunction handleSidebarFocus() {\n\t\t// Either focus the list view or the sidebar close button. Must have a fallback because the list view does not render when there are no blocks.\n\t\tconst listViewApplicationFocus = focus.tabbable.find(\n\t\t\tlistViewRef.current\n\t\t)[ 0 ];\n\t\tconst listViewFocusArea = sidebarRef.current.contains(\n\t\t\tlistViewApplicationFocus\n\t\t)\n\t\t\t? listViewApplicationFocus\n\t\t\t: sidebarCloseButtonRef.current;\n\t\tlistViewFocusArea.focus();\n\t}\n\n\tconst handleToggleListViewShortcut = useCallback( () => {\n\t\t// If the sidebar has focus, it is safe to close.\n\t\tif (\n\t\t\tsidebarRef.current.contains(\n\t\t\t\tsidebarRef.current.ownerDocument.activeElement\n\t\t\t)\n\t\t) {\n\t\t\tcloseListView();\n\t\t} else {\n\t\t\t// If the list view or close button does not have focus, focus should be moved to it.\n\t\t\thandleSidebarFocus();\n\t\t}\n\t}, [ closeListView ] );\n\n\t// This only fires when the sidebar is open because of the conditional rendering.\n\t// It is the same shortcut to open but that is defined as a global shortcut and only fires when the sidebar is closed.\n\tuseShortcut(\n\t\t'core/edit-site/toggle-list-view',\n\t\thandleToggleListViewShortcut\n\t);\n\n\treturn (\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName=\"edit-site-editor__list-view-panel\"\n\t\t\tonKeyDown={ closeOnEscape }\n\t\t\tref={ sidebarRef }\n\t\t>\n\t\t\t<div className=\"edit-site-editor__list-view-panel-header\">\n\t\t\t\t<strong>{ __( 'List View' ) }</strong>\n\t\t\t\t<Button\n\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\tonClick={ closeListView }\n\t\t\t\t\tref={ sidebarCloseButtonRef }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div\n\t\t\t\tclassName=\"edit-site-editor__list-view-panel-content\"\n\t\t\t\tref={ useMergeRefs( [\n\t\t\t\t\tfocusOnMountRef,\n\t\t\t\t\tsetDropZoneElement,\n\t\t\t\t\tlistViewRef,\n\t\t\t\t] ) }\n\t\t\t>\n\t\t\t\t<PrivateListView dropZoneElement={ dropZoneElement } />\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,WAAW,IAAIC,sBAAsB,QAAQ,yBAAyB;AAC/E,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,eAAe,EAAEC,YAAY,QAAQ,oBAAoB;AAClE,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,oBAAoB;AAClE,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,KAAK,QAAQ,gBAAgB;AACtC,SAASC,WAAW,QAAQ,+BAA+B;;AAE3D;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,aAAa;AACpD,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,MAAM;EAAEC;AAAgB,CAAC,GAAGD,MAAM,CAAEf,sBAAuB,CAAC;AAE5D,eAAe,SAASiB,eAAeA,CAAE;EAAEC;AAAsB,CAAC,EAAG;EACpE,MAAM;IAAEC;EAAoB,CAAC,GAAGf,WAA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,UAAU,CAACO,OAAO,CAACI,aAAa,CAACC,aAClC,CAAC,EACA;MACDpB,aAAa,CAAC,CAAC;IAChB,CAAC,MAAM;MACN;MACAW,kBAAkB,CAAC,CAAC;IACrB;EACD,CAAC,EAAE,CAAEX,aAAa,CAAG,CAAC;;EAEtB;EACA;EACAT,WAAW,CACV,iCAAiC,EACjC2B,4BACD,CAAC;EAED;IACC;IACAG,aAAA;MACCC,SAAS,EAAC,mCAAmC;MAC7CC,SAAS,EAAGtB,aAAe;MAC3BuB,GAAG,EAAGhB;IAAY,GAElBa,aAAA;MAAKC,SAAS,EAAC;IAA0C,GACxDD,aAAA,iBAAUlC,EAAE,CAAE,WAAY,CAAW,CAAC,EACtCkC,aAAA,CAACzC,MAAM;MACN6C,IAAI,EAAGrC,UAAY;MACnBsC,KAAK,EAAGvC,EAAE,CAAE,OAAQ,CAAG;MACvBwC,OAAO,EAAG3B,aAAe;MACzBwB,GAAG,EAAGf;IAAuB,CAC7B,CACG,CAAC,EACNY,aAAA;MACCC,SAAS,EAAC,2CAA2C;MACrDE,GAAG,EAAG1C,YAAY,CAAE,CACnBiB,eAAe,EACfQ,kBAAkB,EAClBG,WAAW,CACV;IAAG,GAELW,aAAA,CAAC1B,eAAe;MAACW,eAAe,EAAGA;IAAiB,CAAE,CAClD,CACD;EAAC;AAER"}
|
|
@@ -7,6 +7,7 @@ import { decodeEntities } from '@wordpress/html-entities';
|
|
|
7
7
|
import { DropdownMenu, MenuGroup, MenuItem, __experimentalHStack as HStack, __experimentalText as Text } from '@wordpress/components';
|
|
8
8
|
import { __ } from '@wordpress/i18n';
|
|
9
9
|
import { store as coreStore } from '@wordpress/core-data';
|
|
10
|
+
import { check } from '@wordpress/icons';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Internal dependencies
|
|
@@ -14,6 +15,7 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
14
15
|
import { store as editSiteStore } from '../../../store';
|
|
15
16
|
import SwapTemplateButton from './swap-template-button';
|
|
16
17
|
import ResetDefaultTemplate from './reset-default-template';
|
|
18
|
+
import { unlock } from '../../../lock-unlock';
|
|
17
19
|
const POPOVER_PROPS = {
|
|
18
20
|
className: 'edit-site-page-panels-edit-template__dropdown',
|
|
19
21
|
placement: 'bottom-start'
|
|
@@ -21,13 +23,18 @@ const POPOVER_PROPS = {
|
|
|
21
23
|
export default function EditTemplate() {
|
|
22
24
|
const {
|
|
23
25
|
hasResolved,
|
|
24
|
-
template
|
|
26
|
+
template,
|
|
27
|
+
isTemplateHidden
|
|
25
28
|
} = useSelect(select => {
|
|
26
29
|
const {
|
|
27
30
|
getEditedPostContext,
|
|
28
31
|
getEditedPostType,
|
|
29
32
|
getEditedPostId
|
|
30
33
|
} = select(editSiteStore);
|
|
34
|
+
const {
|
|
35
|
+
getCanvasMode,
|
|
36
|
+
getPageContentFocusType
|
|
37
|
+
} = unlock(select(editSiteStore));
|
|
31
38
|
const {
|
|
32
39
|
getEditedEntityRecord,
|
|
33
40
|
hasFinishedResolution
|
|
@@ -37,12 +44,18 @@ export default function EditTemplate() {
|
|
|
37
44
|
return {
|
|
38
45
|
context: _context,
|
|
39
46
|
hasResolved: hasFinishedResolution('getEditedEntityRecord', queryArgs),
|
|
40
|
-
template: getEditedEntityRecord(...queryArgs)
|
|
47
|
+
template: getEditedEntityRecord(...queryArgs),
|
|
48
|
+
isTemplateHidden: getCanvasMode() === 'edit' && getPageContentFocusType() === 'hideTemplate'
|
|
41
49
|
};
|
|
42
50
|
}, []);
|
|
43
51
|
const {
|
|
44
52
|
setHasPageContentFocus
|
|
45
53
|
} = useDispatch(editSiteStore);
|
|
54
|
+
// Disable reason: `useDispatch` can't be called conditionally.
|
|
55
|
+
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
56
|
+
const {
|
|
57
|
+
setPageContentFocusType
|
|
58
|
+
} = unlock(useDispatch(editSiteStore));
|
|
46
59
|
if (!hasResolved) {
|
|
47
60
|
return null;
|
|
48
61
|
}
|
|
@@ -71,6 +84,11 @@ export default function EditTemplate() {
|
|
|
71
84
|
onClick: onClose
|
|
72
85
|
})), createElement(ResetDefaultTemplate, {
|
|
73
86
|
onClick: onClose
|
|
74
|
-
})
|
|
87
|
+
}), createElement(MenuGroup, null, createElement(MenuItem, {
|
|
88
|
+
icon: !isTemplateHidden ? check : undefined,
|
|
89
|
+
onClick: () => {
|
|
90
|
+
setPageContentFocusType(isTemplateHidden ? 'disableTemplate' : 'hideTemplate');
|
|
91
|
+
}
|
|
92
|
+
}, __('Template preview'))))));
|
|
75
93
|
}
|
|
76
94
|
//# sourceMappingURL=edit-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSelect","useDispatch","decodeEntities","DropdownMenu","MenuGroup","MenuItem","__experimentalHStack","HStack","__experimentalText","Text","__","store","coreStore","editSiteStore","SwapTemplateButton","ResetDefaultTemplate","POPOVER_PROPS","className","placement","EditTemplate","hasResolved","template","select","getEditedPostContext","getEditedPostType","getEditedPostId","getEditedEntityRecord","hasFinishedResolution","_context","queryArgs","context","setHasPageContentFocus","createElement","popoverProps","focusOnMount","toggleProps","variant","label","text","title","icon","onClose","Fragment","onClick"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/page-panels/edit-template.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\t__experimentalHStack as HStack,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../../store';\nimport SwapTemplateButton from './swap-template-button';\nimport ResetDefaultTemplate from './reset-default-template';\n\nconst POPOVER_PROPS = {\n\tclassName: 'edit-site-page-panels-edit-template__dropdown',\n\tplacement: 'bottom-start',\n};\n\nexport default function EditTemplate() {\n\tconst { hasResolved, template } = useSelect(
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","decodeEntities","DropdownMenu","MenuGroup","MenuItem","__experimentalHStack","HStack","__experimentalText","Text","__","store","coreStore","check","editSiteStore","SwapTemplateButton","ResetDefaultTemplate","unlock","POPOVER_PROPS","className","placement","EditTemplate","hasResolved","template","isTemplateHidden","select","getEditedPostContext","getEditedPostType","getEditedPostId","getCanvasMode","getPageContentFocusType","getEditedEntityRecord","hasFinishedResolution","_context","queryArgs","context","setHasPageContentFocus","setPageContentFocusType","createElement","popoverProps","focusOnMount","toggleProps","variant","label","text","title","icon","onClose","Fragment","onClick","undefined"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/page-panels/edit-template.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\t__experimentalHStack as HStack,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { check } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../../store';\nimport SwapTemplateButton from './swap-template-button';\nimport ResetDefaultTemplate from './reset-default-template';\nimport { unlock } from '../../../lock-unlock';\n\nconst POPOVER_PROPS = {\n\tclassName: 'edit-site-page-panels-edit-template__dropdown',\n\tplacement: 'bottom-start',\n};\n\nexport default function EditTemplate() {\n\tconst { hasResolved, template, isTemplateHidden } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedPostContext, getEditedPostType, getEditedPostId } =\n\t\t\t\tselect( editSiteStore );\n\t\t\tconst { getCanvasMode, getPageContentFocusType } = unlock(\n\t\t\t\tselect( editSiteStore )\n\t\t\t);\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst _context = getEditedPostContext();\n\t\t\tconst queryArgs = [\n\t\t\t\t'postType',\n\t\t\t\tgetEditedPostType(),\n\t\t\t\tgetEditedPostId(),\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tcontext: _context,\n\t\t\t\thasResolved: hasFinishedResolution(\n\t\t\t\t\t'getEditedEntityRecord',\n\t\t\t\t\tqueryArgs\n\t\t\t\t),\n\t\t\t\ttemplate: getEditedEntityRecord( ...queryArgs ),\n\t\t\t\tisTemplateHidden:\n\t\t\t\t\tgetCanvasMode() === 'edit' &&\n\t\t\t\t\tgetPageContentFocusType() === 'hideTemplate',\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { setHasPageContentFocus } = useDispatch( editSiteStore );\n\t// Disable reason: `useDispatch` can't be called conditionally.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setPageContentFocusType } = unlock( useDispatch( editSiteStore ) );\n\n\tif ( ! hasResolved ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<HStack className=\"edit-site-summary-field\">\n\t\t\t<Text className=\"edit-site-summary-field__label\">\n\t\t\t\t{ __( 'Template' ) }\n\t\t\t</Text>\n\t\t\t<DropdownMenu\n\t\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\t\tfocusOnMount\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'tertiary',\n\t\t\t\t\tclassName: 'edit-site-summary-field__trigger',\n\t\t\t\t} }\n\t\t\t\tlabel={ __( 'Template options' ) }\n\t\t\t\ttext={ decodeEntities( template.title ) }\n\t\t\t\ticon={ null }\n\t\t\t>\n\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tsetHasPageContentFocus( false );\n\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Edit template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t<SwapTemplateButton onClick={ onClose } />\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<ResetDefaultTemplate onClick={ onClose } />\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ ! isTemplateHidden ? check : undefined }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tsetPageContentFocusType(\n\t\t\t\t\t\t\t\t\t\tisTemplateHidden\n\t\t\t\t\t\t\t\t\t\t\t? 'disableTemplate'\n\t\t\t\t\t\t\t\t\t\t\t: 'hideTemplate'\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Template preview' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t</HStack>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SACCC,YAAY,EACZC,SAAS,EACTC,QAAQ,EACRC,oBAAoB,IAAIC,MAAM,EAC9BC,kBAAkB,IAAIC,IAAI,QACpB,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,KAAK,QAAQ,kBAAkB;;AAExC;AACA;AACA;AACA,SAASF,KAAK,IAAIG,aAAa,QAAQ,gBAAgB;AACvD,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,OAAOC,oBAAoB,MAAM,0BAA0B;AAC3D,SAASC,MAAM,QAAQ,sBAAsB;AAE7C,MAAMC,aAAa,GAA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AC7CT,EAAE,CAAE,UAAW,CACZ,CAAC,EACP4B,aAAA,CAACnC,YAAY;IACZoC,YAAY,EAAGrB,aAAe;IAC9BsB,YAAY;IACZC,WAAW,EAAG;MACbC,OAAO,EAAE,UAAU;MACnBvB,SAAS,EAAE;IACZ,CAAG;IACHwB,KAAK,EAAGjC,EAAE,CAAE,kBAAmB,CAAG;IAClCkC,IAAI,EAAG1C,cAAc,CAAEqB,QAAQ,CAACsB,KAAM,CAAG;IACzCC,IAAI,EAAG;EAAM,GAEX,CAAE;IAAEC;EAAQ,CAAC,KACdT,aAAA,CAAAU,QAAA,QACCV,aAAA,CAAClC,SAAS,QACTkC,aAAA,CAACjC,QAAQ;IACR4C,OAAO,EAAGA,CAAA,KAAM;MACfb,sBAAsB,CAAE,KAAM,CAAC;MAC/BW,OAAO,CAAC,CAAC;IACV;EAAG,GAEDrC,EAAE,CAAE,eAAgB,CACb,CAAC,EACX4B,aAAA,CAACvB,kBAAkB;IAACkC,OAAO,EAAGF;EAAS,CAAE,CAC/B,CAAC,EACZT,aAAA,CAACtB,oBAAoB;IAACiC,OAAO,EAAGF;EAAS,CAAE,CAAC,EAC5CT,aAAA,CAAClC,SAAS,QACTkC,aAAA,CAACjC,QAAQ;IACRyC,IAAI,EAAG,CAAEtB,gBAAgB,GAAGX,KAAK,GAAGqC,SAAW;IAC/CD,OAAO,EAAGA,CAAA,KAAM;MACfZ,uBAAuB,CACtBb,gBAAgB,GACb,iBAAiB,GACjB,cACJ,CAAC;IACF;EAAG,GAEDd,EAAE,CAAE,kBAAmB,CAChB,CACA,CACV,CAEU,CACP,CAAC;AAEX"}
|
|
@@ -9,6 +9,7 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
11
|
import { store as editSiteStore } from '../../../store';
|
|
12
|
+
import { TEMPLATE_POST_TYPE } from '../../../utils/constants';
|
|
12
13
|
export function useEditedPostContext() {
|
|
13
14
|
return useSelect(select => select(editSiteStore).getEditedPostContext(), []);
|
|
14
15
|
}
|
|
@@ -19,7 +20,7 @@ export function useIsPostsPage() {
|
|
|
19
20
|
return useSelect(select => +postId === select(coreStore).getEntityRecord('root', 'site')?.page_for_posts, [postId]);
|
|
20
21
|
}
|
|
21
22
|
function useTemplates() {
|
|
22
|
-
return useSelect(select => select(coreStore).getEntityRecords('postType',
|
|
23
|
+
return useSelect(select => select(coreStore).getEntityRecords('postType', TEMPLATE_POST_TYPE, {
|
|
23
24
|
per_page: -1,
|
|
24
25
|
post_type: 'page'
|
|
25
26
|
}), []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSelect","useMemo","store","coreStore","editSiteStore","useEditedPostContext","select","getEditedPostContext","useIsPostsPage","postId","getEntityRecord","page_for_posts","useTemplates","getEntityRecords","per_page","post_type","useAvailableTemplates","currentTemplateSlug","useCurrentTemplateSlug","isPostsPage","templates","filter","template","is_custom","slug","content","raw","postType","entityTemplate","post","getEditedEntityRecord","find"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/page-panels/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../../store';\n\nexport function useEditedPostContext() {\n\treturn useSelect(\n\t\t( select ) => select( editSiteStore ).getEditedPostContext(),\n\t\t[]\n\t);\n}\n\nexport function useIsPostsPage() {\n\tconst { postId } = useEditedPostContext();\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\t+postId ===\n\t\t\tselect( coreStore ).getEntityRecord( 'root', 'site' )\n\t\t\t\t?.page_for_posts,\n\t\t[ postId ]\n\t);\n}\n\nfunction useTemplates() {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords(
|
|
1
|
+
{"version":3,"names":["useSelect","useMemo","store","coreStore","editSiteStore","TEMPLATE_POST_TYPE","useEditedPostContext","select","getEditedPostContext","useIsPostsPage","postId","getEntityRecord","page_for_posts","useTemplates","getEntityRecords","per_page","post_type","useAvailableTemplates","currentTemplateSlug","useCurrentTemplateSlug","isPostsPage","templates","filter","template","is_custom","slug","content","raw","postType","entityTemplate","post","getEditedEntityRecord","find"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/page-panels/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../../store';\nimport { TEMPLATE_POST_TYPE } from '../../../utils/constants';\n\nexport function useEditedPostContext() {\n\treturn useSelect(\n\t\t( select ) => select( editSiteStore ).getEditedPostContext(),\n\t\t[]\n\t);\n}\n\nexport function useIsPostsPage() {\n\tconst { postId } = useEditedPostContext();\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\t+postId ===\n\t\t\tselect( coreStore ).getEntityRecord( 'root', 'site' )\n\t\t\t\t?.page_for_posts,\n\t\t[ postId ]\n\t);\n}\n\nfunction useTemplates() {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t\tpost_type: 'page',\n\t\t\t\t}\n\t\t\t),\n\t\t[]\n\t);\n}\n\nexport function useAvailableTemplates() {\n\tconst currentTemplateSlug = useCurrentTemplateSlug();\n\tconst isPostsPage = useIsPostsPage();\n\tconst templates = useTemplates();\n\treturn useMemo(\n\t\t() =>\n\t\t\t// The posts page template cannot be changed.\n\t\t\t! isPostsPage &&\n\t\t\ttemplates?.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== currentTemplateSlug &&\n\t\t\t\t\t!! template.content.raw // Skip empty templates.\n\t\t\t),\n\t\t[ templates, currentTemplateSlug, isPostsPage ]\n\t);\n}\n\nexport function useCurrentTemplateSlug() {\n\tconst { postType, postId } = useEditedPostContext();\n\tconst templates = useTemplates();\n\tconst entityTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t);\n\t\t\treturn post?.template;\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\tif ( ! entityTemplate ) {\n\t\treturn;\n\t}\n\t// If a page has a `template` set and is not included in the list\n\t// of the theme's templates, do not return it, in order to resolve\n\t// to the current theme's default template.\n\treturn templates?.find( ( template ) => template.slug === entityTemplate )\n\t\t?.slug;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASD,KAAK,IAAIE,aAAa,QAAQ,gBAAgB;AACvD,SAASC,kBAAkB,QAAQ,0BAA0B;AAE7D,OAAO,SAASC,oBAAoBA,CAAA,EAAG;EACtC,OAAON,SAAS,CACbO,MAAM,IAAMA,MAAM,CAAEH,aAAc,CAAC,CAACI,oBAAoB,CAAC,CAAC,EAC5D,EACD,CAAC;AACF;AAEA,OAAO,SAASC,cAAcA,CAAA,EAAG;EAChC,MAAM;IAAEC;EAAO,CAAC,GAAGJ,oBAAoB,CAAC,CAAC;EACzC,OAAON,SAAS,CACbO,MAAM,IACP,CAACG,MAAM,KACPH,MAAM,CAAEJ,SAAU,CAAC,CAACQ,eAAe,CAAE,MAAM,EAAE,MAAO,CAAC,EAClDC,cAAc,EAClB,CAAEF,MAAM,CACT,CAAC;AACF;AAEA,SAASG,YAAYA,CAAA,EAAG;EACvB,OAAOb,SAAS,CACbO,MAAM,IACPA,MAAM,C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import { store as interfaceStore } from '@wordpress/interface';
|
|
|
18
18
|
import { STORE_NAME } from '../../../store/constants';
|
|
19
19
|
import { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from '../constants';
|
|
20
20
|
import { store as editSiteStore } from '../../../store';
|
|
21
|
-
|
|
22
|
-
wp_navigation: __('Navigation'),
|
|
23
|
-
wp_block: __('Pattern'),
|
|
24
|
-
wp_template: __('Template')
|
|
25
|
-
};
|
|
21
|
+
import { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../../utils/constants';
|
|
26
22
|
const SettingsHeader = ({
|
|
27
23
|
sidebarName
|
|
28
24
|
}) => {
|
|
@@ -39,7 +35,7 @@ const SettingsHeader = ({
|
|
|
39
35
|
entityType: getEditedPostType()
|
|
40
36
|
};
|
|
41
37
|
});
|
|
42
|
-
const entityLabel =
|
|
38
|
+
const entityLabel = POST_TYPE_LABELS[entityType] || POST_TYPE_LABELS[TEMPLATE_POST_TYPE];
|
|
43
39
|
const {
|
|
44
40
|
enableComplementaryArea
|
|
45
41
|
} = useDispatch(interfaceStore);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classnames","Button","__","sprintf","useSelect","useDispatch","store","interfaceStore","STORE_NAME","SIDEBAR_BLOCK","SIDEBAR_TEMPLATE","editSiteStore","
|
|
1
|
+
{"version":3,"names":["classnames","Button","__","sprintf","useSelect","useDispatch","store","interfaceStore","STORE_NAME","SIDEBAR_BLOCK","SIDEBAR_TEMPLATE","editSiteStore","POST_TYPE_LABELS","TEMPLATE_POST_TYPE","SettingsHeader","sidebarName","hasPageContentFocus","entityType","select","getEditedPostType","_hasPageContentFocus","entityLabel","enableComplementaryArea","openTemplateSettings","openBlockSettings","templateAriaLabel","createElement","onClick","className"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/settings-header/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../../../store/constants';\nimport { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from '../constants';\nimport { store as editSiteStore } from '../../../store';\nimport { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../../utils/constants';\n\nconst SettingsHeader = ( { sidebarName } ) => {\n\tconst { hasPageContentFocus, entityType } = useSelect( ( select ) => {\n\t\tconst { getEditedPostType, hasPageContentFocus: _hasPageContentFocus } =\n\t\t\tselect( editSiteStore );\n\n\t\treturn {\n\t\t\thasPageContentFocus: _hasPageContentFocus(),\n\t\t\tentityType: getEditedPostType(),\n\t\t};\n\t} );\n\n\tconst entityLabel =\n\t\tPOST_TYPE_LABELS[ entityType ] ||\n\t\tPOST_TYPE_LABELS[ TEMPLATE_POST_TYPE ];\n\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\tconst openTemplateSettings = () =>\n\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_TEMPLATE );\n\tconst openBlockSettings = () =>\n\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );\n\n\tlet templateAriaLabel;\n\tif ( hasPageContentFocus ) {\n\t\ttemplateAriaLabel =\n\t\t\tsidebarName === SIDEBAR_TEMPLATE\n\t\t\t\t? // translators: ARIA label for the Template sidebar tab, selected.\n\t\t\t\t __( 'Page (selected)' )\n\t\t\t\t: // translators: ARIA label for the Template Settings Sidebar tab, not selected.\n\t\t\t\t __( 'Page' );\n\t} else {\n\t\ttemplateAriaLabel =\n\t\t\tsidebarName === SIDEBAR_TEMPLATE\n\t\t\t\t? // translators: ARIA label for the Template sidebar tab, selected.\n\t\t\t\t sprintf( __( '%s (selected)' ), entityLabel )\n\t\t\t\t: // translators: ARIA label for the Template Settings Sidebar tab, not selected.\n\t\t\t\t entityLabel;\n\t}\n\n\t/* Use a list so screen readers will announce how many tabs there are. */\n\treturn (\n\t\t<ul>\n\t\t\t<li>\n\t\t\t\t<Button\n\t\t\t\t\tonClick={ openTemplateSettings }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-sidebar-edit-mode__panel-tab',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'is-active': sidebarName === SIDEBAR_TEMPLATE,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-label={ templateAriaLabel }\n\t\t\t\t\tdata-label={\n\t\t\t\t\t\thasPageContentFocus ? __( 'Page' ) : entityLabel\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ hasPageContentFocus ? __( 'Page' ) : entityLabel }\n\t\t\t\t</Button>\n\t\t\t</li>\n\t\t\t<li>\n\t\t\t\t<Button\n\t\t\t\t\tonClick={ openBlockSettings }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-sidebar-edit-mode__panel-tab',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'is-active': sidebarName === SIDEBAR_BLOCK,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tsidebarName === SIDEBAR_BLOCK\n\t\t\t\t\t\t\t? // translators: ARIA label for the Block Settings Sidebar tab, selected.\n\t\t\t\t\t\t\t __( 'Block (selected)' )\n\t\t\t\t\t\t\t: // translators: ARIA label for the Block Settings Sidebar tab, not selected.\n\t\t\t\t\t\t\t __( 'Block' )\n\t\t\t\t\t}\n\t\t\t\t\tdata-label={ __( 'Block' ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Block' ) }\n\t\t\t\t</Button>\n\t\t\t</li>\n\t\t</ul>\n\t);\n};\n\nexport default SettingsHeader;\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,EAAE,E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gBAAgB;IAC7B;IACAP,OAAO,CAAED,EAAE,CAAE,eAAgB,CAAC,EAAEmB,WAAY,CAAC;IAC7C;IACAA,WAAW;EAChB;;EAEA;EACA,OACCK,aAAA,aACCA,aAAA,aACCA,aAAA,CAACzB,MAAM;IACN0B,OAAO,EAAGJ,oBAAsB;IAChCK,SAAS,EAAG5B,UAAU,CACrB,wCAAwC,EACxC;MACC,WAAW,EAAEe,WAAW,KAAKL;IAC9B,CACD,CAAG;IACH,cAAae,iBAAmB;IAChC,cACCT,mBAAmB,GAAGd,EAAE,CAAE,MAAO,CAAC,GAAGmB;EACrC,GAECL,mBAAmB,GAAGd,EAAE,CAAE,MAAO,CAAC,GAAGmB,WAChC,CACL,CAAC,EACLK,aAAA,aACCA,aAAA,CAACzB,MAAM;IACN0B,OAAO,EAAGH,iBAAmB;IAC7BI,SAAS,EAAG5B,UAAU,CACrB,wCAAwC,EACxC;MACC,WAAW,EAAEe,WAAW,KAAKN;IAC9B,CACD,CAAG;IACH,cACCM,WAAW,KAAKN,aAAa;IAC1B;IACAP,EAAE,CAAE,kBAAmB,CAAC;IACxB;IACAA,EAAE,CAAE,OAAQ,CACf;IACD,cAAaA,EAAE,CAAE,OAAQ;EAAG,GAE1BA,EAAE,CAAE,OAAQ,CACP,CACL,CACD,CAAC;AAEP,CAAC;AAED,eAAeY,cAAc"}
|
|
@@ -10,6 +10,11 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
10
10
|
import { useDebounce } from '@wordpress/compose';
|
|
11
11
|
import { store as noticesStore } from '@wordpress/notices';
|
|
12
12
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { PATTERN_TYPES } from '../../../utils/constants';
|
|
13
18
|
export const unescapeString = arg => {
|
|
14
19
|
return decodeEntities(arg);
|
|
15
20
|
};
|
|
@@ -114,7 +119,8 @@ export default function PatternCategories({
|
|
|
114
119
|
}, [searchResults]);
|
|
115
120
|
const {
|
|
116
121
|
saveEntityRecord,
|
|
117
|
-
editEntityRecord
|
|
122
|
+
editEntityRecord,
|
|
123
|
+
invalidateResolution
|
|
118
124
|
} = useDispatch(coreStore);
|
|
119
125
|
const {
|
|
120
126
|
createErrorNotice
|
|
@@ -127,6 +133,7 @@ export default function PatternCategories({
|
|
|
127
133
|
const newTerm = await saveEntityRecord('taxonomy', slug, term, {
|
|
128
134
|
throwOnError: true
|
|
129
135
|
});
|
|
136
|
+
invalidateResolution('getUserPatternCategories');
|
|
130
137
|
return unescapeTerm(newTerm);
|
|
131
138
|
} catch (error) {
|
|
132
139
|
if (error.code !== 'term_exists') {
|
|
@@ -139,7 +146,7 @@ export default function PatternCategories({
|
|
|
139
146
|
}
|
|
140
147
|
}
|
|
141
148
|
function onUpdateTerms(newTermIds) {
|
|
142
|
-
editEntityRecord('postType',
|
|
149
|
+
editEntityRecord('postType', PATTERN_TYPES.user, post.id, {
|
|
143
150
|
wp_pattern_category: newTermIds
|
|
144
151
|
});
|
|
145
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","_x","sprintf","useEffect","useMemo","useState","FormTokenField","PanelRow","useSelect","useDispatch","store","coreStore","useDebounce","noticesStore","decodeEntities","unescapeString","arg","unescapeTerm","term","name","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","_fields","context","isSameTermName","termA","termB","toLowerCase","termNamesToIds","names","terms","map","termName","find","id","PatternCategories","post","_taxonomy$labels$sing","slug","values","setValues","search","setSearch","debouncedSearch","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","select","_post$_links","_post$_links2","getEntityRecords","getTaxonomy","hasFinishedResolution","_taxonomy","_termIds","wp_pattern_category","length","query","include","join","_links","rest_base","termIds","searchResults","newValues","suggestions","saveEntityRecord","editEntityRecord","createErrorNotice","findOrCreateTerm","newTerm","throwOnError","error","code","data","term_id","onUpdateTerms","newTermIds","onChange","termNames","availableTerms","uniqueTerms","reduce","acc","some","n","push","newTermNames","filter","Promise","all","then","newTerms","newAvailableTerms","concat","catch","message","type","singularName","labels","singular_name","termAddedLabel","termRemovedLabel","removeTermLabel","createElement","initialOpen","title","__next40pxDefaultSize","value","onInputChange","maxSuggestions","label","messages","added","removed","remove","tokenizeOnBlur"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/template-panel/pattern-categories.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport { FormTokenField, PanelRow } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nexport const unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\n/**\n * Returns a term object with name unescaped.\n *\n * @param {Object} term The term object to unescape.\n *\n * @return {Object} Term object with name property unescaped.\n */\nexport const unescapeTerm = ( term ) => {\n\treturn {\n\t\t...term,\n\t\tname: unescapeString( term.name ),\n\t};\n};\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tterms.find( ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\nexport default function PatternCategories( { post } ) {\n\tconst slug = 'wp_pattern_category';\n\tconst [ values, setValues ] = useState( [] );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst {\n\t\tterms,\n\t\ttaxonomy,\n\t\thasAssignAction,\n\t\thasCreateAction,\n\t\thasResolvedTerms,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords, getTaxonomy, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst _taxonomy = getTaxonomy( slug );\n\t\t\tconst _termIds =\n\t\t\t\tpost?.wp_pattern_category?.length > 0\n\t\t\t\t\t? post?.wp_pattern_category\n\t\t\t\t\t: EMPTY_ARRAY;\n\t\t\tconst query = {\n\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\tinclude: _termIds?.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\thasCreateAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-create-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\thasAssignAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-assign-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\ttaxonomy: _taxonomy,\n\t\t\t\ttermIds: _termIds,\n\t\t\t\tterms: _termIds?.length\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, query )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t\thasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\tslug,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ slug, post ]\n\t);\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search, slug ]\n\t);\n\n\t// Update terms state only after the selectors are resolved.\n\t// We're using this to avoid terms temporarily disappearing on slow networks\n\t// while core data makes REST API requests.\n\tuseEffect( () => {\n\t\tif ( hasResolvedTerms ) {\n\t\t\tconst newValues = ( terms ?? [] ).map( ( term ) =>\n\t\t\t\tunescapeString( term.name )\n\t\t\t);\n\n\t\t\tsetValues( newValues );\n\t\t}\n\t}, [ terms, hasResolvedTerms ] );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\n\n\tconst { saveEntityRecord, editEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tif ( ! hasAssignAction ) {\n\t\treturn null;\n\t}\n\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\tconst newTerm = await saveEntityRecord( 'taxonomy', slug, term, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\treturn unescapeTerm( newTerm );\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: error.data.term_id,\n\t\t\t\tname: term.name,\n\t\t\t};\n\t\t}\n\t}\n\n\tfunction onUpdateTerms( newTermIds ) {\n\t\teditEntityRecord( 'postType', 'wp_block', post.id, {\n\t\t\twp_pattern_category: newTermIds,\n\t\t} );\n\t}\n\n\tfunction onChange( termNames ) {\n\t\tconst availableTerms = [\n\t\t\t...( terms ?? [] ),\n\t\t\t...( searchResults ?? [] ),\n\t\t];\n\t\tconst uniqueTerms = termNames.reduce( ( acc, name ) => {\n\t\t\tif (\n\t\t\t\t! acc.some( ( n ) => n.toLowerCase() === name.toLowerCase() )\n\t\t\t) {\n\t\t\t\tacc.push( name );\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, [] );\n\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! availableTerms.find( ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\t// Optimistically update term values.\n\t\t// The selector will always re-fetch terms later.\n\t\tsetValues( uniqueTerms );\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, availableTerms )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! hasCreateAction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tPromise.all(\n\t\t\tnewTermNames.map( ( termName ) =>\n\t\t\t\tfindOrCreateTerm( { name: termName } )\n\t\t\t)\n\t\t)\n\t\t\t.then( ( newTerms ) => {\n\t\t\t\tconst newAvailableTerms = availableTerms.concat( newTerms );\n\t\t\t\treturn onUpdateTerms(\n\t\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms )\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} );\n\t}\n\n\tconst singularName =\n\t\ttaxonomy?.labels?.singular_name ??\n\t\t( slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ) );\n\tconst termAddedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s added', 'term' ),\n\t\tsingularName\n\t);\n\tconst termRemovedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s removed', 'term' ),\n\t\tsingularName\n\t);\n\tconst removeTermLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( 'Remove %s', 'term' ),\n\t\tsingularName\n\t);\n\n\treturn (\n\t\t<PanelRow initialOpen={ true } title={ __( 'Categories' ) }>\n\t\t\t<FormTokenField\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ __( 'Pattern categories' ) }\n\t\t\t\tmessages={ {\n\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t} }\n\t\t\t\ttokenizeOnBlur\n\t\t\t/>\n\t\t</PanelRow>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACjE,SAASC,cAAc,EAAEC,QAAQ,QAAQ,uBAAuB;AAChE,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASF,KAAK,IAAIG,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,OAAO,MAAMC,cAAc,GAAKC,GAAG,IAAM;EACxC,OAAOF,cAAc,CAAEE,GAAI,CAAC;AAC7B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAKC,IAAI,IAAM;EACvC,OAAO;IACN,GAAGA,IAAI;IACPC,IAAI,EAAEJ,cAAc,CAAEG,IAAI,CAACC,IAAK;EACjC,CAAC;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA,MA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EZ,gBAAgB;MACzBa,MAAM,EAAEZ;IACT,CAAG;IACHa,cAAc;EAAA,CACd,CACQ,CAAC;AAEb"}
|
|
1
|
+
{"version":3,"names":["__","_x","sprintf","useEffect","useMemo","useState","FormTokenField","PanelRow","useSelect","useDispatch","store","coreStore","useDebounce","noticesStore","decodeEntities","PATTERN_TYPES","unescapeString","arg","unescapeTerm","term","name","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","_fields","context","isSameTermName","termA","termB","toLowerCase","termNamesToIds","names","terms","map","termName","find","id","PatternCategories","post","_taxonomy$labels$sing","slug","values","setValues","search","setSearch","debouncedSearch","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","select","_post$_links","_post$_links2","getEntityRecords","getTaxonomy","hasFinishedResolution","_taxonomy","_termIds","wp_pattern_category","length","query","include","join","_links","rest_base","termIds","searchResults","newValues","suggestions","saveEntityRecord","editEntityRecord","invalidateResolution","createErrorNotice","findOrCreateTerm","newTerm","throwOnError","error","code","data","term_id","onUpdateTerms","newTermIds","user","onChange","termNames","availableTerms","uniqueTerms","reduce","acc","some","n","push","newTermNames","filter","Promise","all","then","newTerms","newAvailableTerms","concat","catch","message","type","singularName","labels","singular_name","termAddedLabel","termRemovedLabel","removeTermLabel","createElement","initialOpen","title","__next40pxDefaultSize","value","onInputChange","maxSuggestions","label","messages","added","removed","remove","tokenizeOnBlur"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/template-panel/pattern-categories.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport { FormTokenField, PanelRow } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_TYPES } from '../../../utils/constants';\n\nexport const unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\n/**\n * Returns a term object with name unescaped.\n *\n * @param {Object} term The term object to unescape.\n *\n * @return {Object} Term object with name property unescaped.\n */\nexport const unescapeTerm = ( term ) => {\n\treturn {\n\t\t...term,\n\t\tname: unescapeString( term.name ),\n\t};\n};\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tterms.find( ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\nexport default function PatternCategories( { post } ) {\n\tconst slug = 'wp_pattern_category';\n\tconst [ values, setValues ] = useState( [] );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst {\n\t\tterms,\n\t\ttaxonomy,\n\t\thasAssignAction,\n\t\thasCreateAction,\n\t\thasResolvedTerms,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords, getTaxonomy, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst _taxonomy = getTaxonomy( slug );\n\t\t\tconst _termIds =\n\t\t\t\tpost?.wp_pattern_category?.length > 0\n\t\t\t\t\t? post?.wp_pattern_category\n\t\t\t\t\t: EMPTY_ARRAY;\n\t\t\tconst query = {\n\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\tinclude: _termIds?.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\thasCreateAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-create-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\thasAssignAction: _taxonomy\n\t\t\t\t\t? post._links?.[\n\t\t\t\t\t\t\t'wp:action-assign-' + _taxonomy.rest_base\n\t\t\t\t\t ] ?? false\n\t\t\t\t\t: false,\n\t\t\t\ttaxonomy: _taxonomy,\n\t\t\t\ttermIds: _termIds,\n\t\t\t\tterms: _termIds?.length\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, query )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t\thasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\tslug,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ slug, post ]\n\t);\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search, slug ]\n\t);\n\n\t// Update terms state only after the selectors are resolved.\n\t// We're using this to avoid terms temporarily disappearing on slow networks\n\t// while core data makes REST API requests.\n\tuseEffect( () => {\n\t\tif ( hasResolvedTerms ) {\n\t\t\tconst newValues = ( terms ?? [] ).map( ( term ) =>\n\t\t\t\tunescapeString( term.name )\n\t\t\t);\n\n\t\t\tsetValues( newValues );\n\t\t}\n\t}, [ terms, hasResolvedTerms ] );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\n\n\tconst { saveEntityRecord, editEntityRecord, invalidateResolution } =\n\t\tuseDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tif ( ! hasAssignAction ) {\n\t\treturn null;\n\t}\n\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\tconst newTerm = await saveEntityRecord( 'taxonomy', slug, term, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn unescapeTerm( newTerm );\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: error.data.term_id,\n\t\t\t\tname: term.name,\n\t\t\t};\n\t\t}\n\t}\n\n\tfunction onUpdateTerms( newTermIds ) {\n\t\teditEntityRecord( 'postType', PATTERN_TYPES.user, post.id, {\n\t\t\twp_pattern_category: newTermIds,\n\t\t} );\n\t}\n\n\tfunction onChange( termNames ) {\n\t\tconst availableTerms = [\n\t\t\t...( terms ?? [] ),\n\t\t\t...( searchResults ?? [] ),\n\t\t];\n\t\tconst uniqueTerms = termNames.reduce( ( acc, name ) => {\n\t\t\tif (\n\t\t\t\t! acc.some( ( n ) => n.toLowerCase() === name.toLowerCase() )\n\t\t\t) {\n\t\t\t\tacc.push( name );\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, [] );\n\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! availableTerms.find( ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\t// Optimistically update term values.\n\t\t// The selector will always re-fetch terms later.\n\t\tsetValues( uniqueTerms );\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, availableTerms )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! hasCreateAction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tPromise.all(\n\t\t\tnewTermNames.map( ( termName ) =>\n\t\t\t\tfindOrCreateTerm( { name: termName } )\n\t\t\t)\n\t\t)\n\t\t\t.then( ( newTerms ) => {\n\t\t\t\tconst newAvailableTerms = availableTerms.concat( newTerms );\n\t\t\t\treturn onUpdateTerms(\n\t\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms )\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} );\n\t}\n\n\tconst singularName =\n\t\ttaxonomy?.labels?.singular_name ??\n\t\t( slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ) );\n\tconst termAddedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s added', 'term' ),\n\t\tsingularName\n\t);\n\tconst termRemovedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s removed', 'term' ),\n\t\tsingularName\n\t);\n\tconst removeTermLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( 'Remove %s', 'term' ),\n\t\tsingularName\n\t);\n\n\treturn (\n\t\t<PanelRow initialOpen={ true } title={ __( 'Categories' ) }>\n\t\t\t<FormTokenField\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ __( 'Pattern categories' ) }\n\t\t\t\tmessages={ {\n\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t} }\n\t\t\t\ttokenizeOnBlur\n\t\t\t/>\n\t\t</PanelRow>\n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hE,qBAAA,GACjBO,QAAQ,EAAE0D,MAAM,EAAEC,aAAa,cAAAlE,qBAAA,cAAAA,qBAAA,GAC7BC,IAAI,KAAK,UAAU,GAAGzC,EAAE,CAAE,KAAM,CAAC,GAAGA,EAAE,CAAE,MAAO,CAAG;EACrD,MAAM2G,cAAc,GAAGzG,OAAO,EAC7B;EACAD,EAAE,CAAE,UAAU,EAAE,MAAO,CAAC,EACxBuG,YACD,CAAC;EACD,MAAMI,gBAAgB,GAAG1G,OAAO,EAC/B;EACAD,EAAE,CAAE,YAAY,EAAE,MAAO,CAAC,EAC1BuG,YACD,CAAC;EACD,MAAMK,eAAe,GAAG3G,OAAO,EAC9B;EACAD,EAAE,CAAE,WAAW,EAAE,MAAO,CAAC,EACzBuG,YACD,CAAC;EAED,OACCM,aAAA,CAACvG,QAAQ;IAACwG,WAAW,EAAG,IAAM;IAACC,KAAK,EAAGhH,EAAE,CAAE,YAAa;EAAG,GAC1D8G,aAAA,CAACxG,cAAc;IACd2G,qBAAqB;IACrBC,KAAK,EAAGxE,MAAQ;IAChB2B,WAAW,EAAGA,WAAa;IAC3Be,QAAQ,EAAGA,QAAU;IACrB+B,aAAa,EAAGrE,eAAiB;IACjCsE,cAAc,EAAG9F,qBAAuB;IACxC+F,KAAK,EAAGrH,EAAE,CAAE,oBAAqB,CAAG;IACpCsH,QAAQ,EAAG;MACVC,KAAK,EAAEZ,cAAc;MACrBa,OAAO,EAAEZ,gBAAgB;MACzBa,MAAM,EAAEZ;IACT,CAAG;IACHa,cAAc;EAAA,CACd,CACQ,CAAC;AAEb"}
|
|
@@ -9,12 +9,13 @@ import { pencil } from '@wordpress/icons';
|
|
|
9
9
|
*/
|
|
10
10
|
import SidebarButton from '../sidebar-button';
|
|
11
11
|
import { useLink } from '../routes/link';
|
|
12
|
+
import { NAVIGATION_POST_TYPE } from '../../utils/constants';
|
|
12
13
|
export default function EditButton({
|
|
13
14
|
postId
|
|
14
15
|
}) {
|
|
15
16
|
const linkInfo = useLink({
|
|
16
17
|
postId,
|
|
17
|
-
postType:
|
|
18
|
+
postType: NAVIGATION_POST_TYPE,
|
|
18
19
|
canvas: 'edit'
|
|
19
20
|
});
|
|
20
21
|
return createElement(SidebarButton, {
|
package/build-module/components/sidebar-navigation-screen-navigation-menu/edit-button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","pencil","SidebarButton","useLink","EditButton","postId","linkInfo","postType","canvas","createElement","label","icon"],"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menu/edit-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { pencil } from '@wordpress/icons';\n/**\n * Internal dependencies\n */\nimport SidebarButton from '../sidebar-button';\nimport { useLink } from '../routes/link';\n\nexport default function EditButton( { postId } ) {\n\tconst linkInfo = useLink( {\n\t\tpostId,\n\t\tpostType:
|
|
1
|
+
{"version":3,"names":["__","pencil","SidebarButton","useLink","NAVIGATION_POST_TYPE","EditButton","postId","linkInfo","postType","canvas","createElement","label","icon"],"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menu/edit-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { pencil } from '@wordpress/icons';\n/**\n * Internal dependencies\n */\nimport SidebarButton from '../sidebar-button';\nimport { useLink } from '../routes/link';\nimport { NAVIGATION_POST_TYPE } from '../../utils/constants';\n\nexport default function EditButton( { postId } ) {\n\tconst linkInfo = useLink( {\n\t\tpostId,\n\t\tpostType: NAVIGATION_POST_TYPE,\n\t\tcanvas: 'edit',\n\t} );\n\treturn (\n\t\t<SidebarButton { ...linkInfo } label={ __( 'Edit' ) } icon={ pencil } />\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,MAAM,QAAQ,kBAAkB;AACzC;AACA;AACA;AACA,OAAOC,aAAa,MAAM,mBAAmB;AAC7C,SAASC,OAAO,QAAQ,gBAAgB;AACxC,SAASC,oBAAoB,QAAQ,uBAAuB;AAE5D,eAAe,SAASC,UAAUA,CAAE;EAAEC;AAAO,CAAC,EAAG;EAChD,MAAMC,QAAQ,GAAGJ,OAAO,CAAE;IACzBG,MAAM;IACNE,QAAQ,EAAEJ,oBAAoB;IAC9BK,MAAM,EAAE;EACT,CAAE,CAAC;EACH,OACCC,aAAA,CAACR,aAAa;IAAA,GAAMK,QAAQ;IAAGI,KAAK,EAAGX,EAAE,CAAE,MAAO,CAAG;IAACY,IAAI,EAAGX;EAAQ,CAAE,CAAC;AAE1E"}
|
|
@@ -6,10 +6,12 @@ import { __experimentalUseNavigator as useNavigator } from '@wordpress/component
|
|
|
6
6
|
import { __, sprintf } from '@wordpress/i18n';
|
|
7
7
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
8
|
import { store as noticesStore } from '@wordpress/notices';
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
11
12
|
*/
|
|
12
13
|
import { postType } from '.';
|
|
14
|
+
import { NAVIGATION_POST_TYPE } from '../../utils/constants';
|
|
13
15
|
function useDeleteNavigationMenu() {
|
|
14
16
|
const {
|
|
15
17
|
goTo
|
|
@@ -67,7 +69,7 @@ function useSaveNavigationMenu() {
|
|
|
67
69
|
}
|
|
68
70
|
const postId = navigationMenu?.id;
|
|
69
71
|
// Prepare for revert in case of error.
|
|
70
|
-
const originalRecord = getEditedEntityRecord('postType',
|
|
72
|
+
const originalRecord = getEditedEntityRecord('postType', NAVIGATION_POST_TYPE, postId);
|
|
71
73
|
|
|
72
74
|
// Apply the edits.
|
|
73
75
|
editEntityRecord('postType', postType, postId, edits);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","coreStore","__experimentalUseNavigator","useNavigator","__","sprintf","useSelect","useDispatch","noticesStore","postType","useDeleteNavigationMenu","goTo","deleteEntityRecord","createSuccessNotice","createErrorNotice","handleDelete","navigationMenu","postId","id","force","throwOnError","type","error","message","useSaveNavigationMenu","getEditedEntityRecord","select","getEditedEntityRecordSelector","editEntityRecord","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","handleSave","edits","originalRecord","recordPropertiesToSave","Object","keys","useDuplicateNavigationMenu","saveEntityRecord","handleDuplicate","menuTitle","title","rendered","slug","savedRecord","content","raw","status","useNavigationMenuHandlers"],"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __experimentalUseNavigator as useNavigator } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { postType } from '.';\n\nfunction useDeleteNavigationMenu() {\n\tconst { goTo } = useNavigator();\n\n\tconst { deleteEntityRecord } = useDispatch( coreStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst handleDelete = async ( navigationMenu ) => {\n\t\tconst postId = navigationMenu?.id;\n\t\ttry {\n\t\t\tawait deleteEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId,\n\t\t\t\t{\n\t\t\t\t\tforce: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t\t\tcreateSuccessNotice( __( 'Deleted Navigation menu' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tgoTo( '/navigation' );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: error message describing why the navigation menu could not be deleted. */\n\t\t\t\t\t__( `Unable to delete Navigation menu (%s).` ),\n\t\t\t\t\terror?.message\n\t\t\t\t),\n\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n\treturn handleDelete;\n}\n\nfunction useSaveNavigationMenu() {\n\tconst { getEditedEntityRecord } = useSelect( ( select ) => {\n\t\tconst { getEditedEntityRecord: getEditedEntityRecordSelector } =\n\t\t\tselect( coreStore );\n\n\t\treturn {\n\t\t\tgetEditedEntityRecord: getEditedEntityRecordSelector,\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\teditEntityRecord,\n\t\t__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,\n\t} = useDispatch( coreStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst handleSave = async ( navigationMenu, edits ) => {\n\t\tif ( ! edits ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst postId = navigationMenu?.id;\n\t\t// Prepare for revert in case of error.\n\t\tconst originalRecord = getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\
|
|
1
|
+
{"version":3,"names":["store","coreStore","__experimentalUseNavigator","useNavigator","__","sprintf","useSelect","useDispatch","noticesStore","postType","NAVIGATION_POST_TYPE","useDeleteNavigationMenu","goTo","deleteEntityRecord","createSuccessNotice","createErrorNotice","handleDelete","navigationMenu","postId","id","force","throwOnError","type","error","message","useSaveNavigationMenu","getEditedEntityRecord","select","getEditedEntityRecordSelector","editEntityRecord","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","handleSave","edits","originalRecord","recordPropertiesToSave","Object","keys","useDuplicateNavigationMenu","saveEntityRecord","handleDuplicate","menuTitle","title","rendered","slug","savedRecord","content","raw","status","useNavigationMenuHandlers"],"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __experimentalUseNavigator as useNavigator } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { postType } from '.';\nimport { NAVIGATION_POST_TYPE } from '../../utils/constants';\n\nfunction useDeleteNavigationMenu() {\n\tconst { goTo } = useNavigator();\n\n\tconst { deleteEntityRecord } = useDispatch( coreStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst handleDelete = async ( navigationMenu ) => {\n\t\tconst postId = navigationMenu?.id;\n\t\ttry {\n\t\t\tawait deleteEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId,\n\t\t\t\t{\n\t\t\t\t\tforce: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t\t\tcreateSuccessNotice( __( 'Deleted Navigation menu' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tgoTo( '/navigation' );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: error message describing why the navigation menu could not be deleted. */\n\t\t\t\t\t__( `Unable to delete Navigation menu (%s).` ),\n\t\t\t\t\terror?.message\n\t\t\t\t),\n\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n\treturn handleDelete;\n}\n\nfunction useSaveNavigationMenu() {\n\tconst { getEditedEntityRecord } = useSelect( ( select ) => {\n\t\tconst { getEditedEntityRecord: getEditedEntityRecordSelector } =\n\t\t\tselect( coreStore );\n\n\t\treturn {\n\t\t\tgetEditedEntityRecord: getEditedEntityRecordSelector,\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\teditEntityRecord,\n\t\t__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,\n\t} = useDispatch( coreStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst handleSave = async ( navigationMenu, edits ) => {\n\t\tif ( ! edits ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst postId = navigationMenu?.id;\n\t\t// Prepare for revert in case of error.\n\t\tconst originalRecord = getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tNAVIGATION_POST_TYPE,\n\t\t\tpostId\n\t\t);\n\n\t\t// Apply the edits.\n\t\teditEntityRecord( 'postType', postType, postId, edits );\n\n\t\tconst recordPropertiesToSave = Object.keys( edits );\n\n\t\t// Attempt to persist.\n\t\ttry {\n\t\t\tawait saveSpecifiedEntityEdits(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId,\n\t\t\t\trecordPropertiesToSave,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t\t\tcreateSuccessNotice( __( 'Renamed Navigation menu' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\t// Revert to original in case of error.\n\t\t\teditEntityRecord( 'postType', postType, postId, originalRecord );\n\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: error message describing why the navigation menu could not be renamed. */\n\t\t\t\t\t__( `Unable to rename Navigation menu (%s).` ),\n\t\t\t\t\terror?.message\n\t\t\t\t),\n\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n\treturn handleSave;\n}\n\nfunction useDuplicateNavigationMenu() {\n\tconst { goTo } = useNavigator();\n\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst handleDuplicate = async ( navigationMenu ) => {\n\t\tconst menuTitle =\n\t\t\tnavigationMenu?.title?.rendered || navigationMenu?.slug;\n\n\t\ttry {\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\t{\n\t\t\t\t\ttitle: sprintf(\n\t\t\t\t\t\t/* translators: %s: Navigation menu title */\n\t\t\t\t\t\t__( '%s (Copy)' ),\n\t\t\t\t\t\tmenuTitle\n\t\t\t\t\t),\n\t\t\t\t\tcontent: navigationMenu?.content?.raw,\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( savedRecord ) {\n\t\t\t\tcreateSuccessNotice( __( 'Duplicated Navigation menu' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tgoTo( `/navigation/${ postType }/${ savedRecord.id }` );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: error message describing why the navigation menu could not be deleted. */\n\t\t\t\t\t__( `Unable to duplicate Navigation menu (%s).` ),\n\t\t\t\t\terror?.message\n\t\t\t\t),\n\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n\treturn handleDuplicate;\n}\n\nexport default function useNavigationMenuHandlers() {\n\treturn {\n\t\thandleDelete: useDeleteNavigationMenu(),\n\t\thandleSave: useSaveNavigationMenu(),\n\t\thandleDuplicate: useDuplicateNavigationMenu(),\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,0BAA0B,IAAIC,YAAY,QAAQ,uBAAuB;AAClF,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASP,KAAK,IAAIQ,YAAY,QAAQ,oBAAoB;;AAE1D;AACA;AACA;AACA,SAASC,QAAQ,QAAQ,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C,eAAe,GAAG,MAAQvB,cAAc,IAAM;IACnD,MAAMwB,SAAS,GACdxB,cAAc,EAAEyB,KAAK,EAAEC,QAAQ,IAAI1B,cAAc,EAAE2B,IAAI;IAExD,IAAI;MACH,MAAMC,WAAW,GAAG,MAAMN,gBAAgB,CACzC,UAAU,EACV9B,QAAQ,EACR;QACCiC,KAAK,EAAErC,OAAO,EACb;QACAD,EAAE,CAAE,WAAY,CAAC,EACjBqC,SACD,CAAC;QACDK,OAAO,EAAE7B,cAAc,EAAE6B,OAAO,EAAEC,GAAG;QACrCC,MAAM,EAAE;MACT,CAAC,EACD;QACC3B,YAAY,EAAE;MACf,CACD,CAAC;MAED,IAAKwB,WAAW,EAAG;QAClB/B,mBAAmB,CAAEV,EAAE,CAAE,4BAA6B,CAAC,EAAE;UACxDkB,IAAI,EAAE;QACP,CAAE,CAAC;QACHV,IAAI,CAAG,eAAeH,QAAU,IAAIoC,WAAW,CAAC1B,EAAI,EAAE,CAAC;MACxD;IACD,CAAC,CAAC,OAAQI,KAAK,EAAG;MACjBR,iBAAiB,CAChBV,OAAO,EACN;MACAD,EAAE,CAAG,2CAA2C,CAAC,EACjDmB,KAAK,EAAEC,OACR,CAAC,EAED;QACCF,IAAI,EAAE;MACP,CACD,CAAC;IACF;EACD,CAAC;EAED,OAAOkB,eAAe;AACvB;AAEA,eAAe,SAASS,yBAAyBA,CAAA,EAAG;EACnD,OAAO;IACNjC,YAAY,EAAEL,uBAAuB,CAAC,CAAC;IACvCqB,UAAU,EAAEP,qBAAqB,CAAC,CAAC;IACnCe,eAAe,EAAEF,0BAA0B,CAAC;EAC7C,CAAC;AACF"}
|
|
@@ -19,6 +19,7 @@ import { useLink } from '../routes/link';
|
|
|
19
19
|
import SingleNavigationMenu from '../sidebar-navigation-screen-navigation-menu/single-navigation-menu';
|
|
20
20
|
import useNavigationMenuHandlers from '../sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers';
|
|
21
21
|
import { unlock } from '../../lock-unlock';
|
|
22
|
+
import { NAVIGATION_POST_TYPE } from '../../utils/constants';
|
|
22
23
|
|
|
23
24
|
// Copied from packages/block-library/src/navigation/edit/navigation-menu-selector.js.
|
|
24
25
|
function buildMenuLabel(title, id, status) {
|
|
@@ -41,7 +42,7 @@ export default function SidebarNavigationScreenNavigationMenus() {
|
|
|
41
42
|
records: navigationMenus,
|
|
42
43
|
isResolving: isResolvingNavigationMenus,
|
|
43
44
|
hasResolved: hasResolvedNavigationMenus
|
|
44
|
-
} = useEntityRecords('postType',
|
|
45
|
+
} = useEntityRecords('postType', NAVIGATION_POST_TYPE, PRELOADED_NAVIGATION_MENUS_QUERY);
|
|
45
46
|
const isLoading = isResolvingNavigationMenus && !hasResolvedNavigationMenus;
|
|
46
47
|
const {
|
|
47
48
|
getNavigationFallbackId
|
|
@@ -114,7 +115,7 @@ const NavMenuItem = ({
|
|
|
114
115
|
}) => {
|
|
115
116
|
const linkInfo = useLink({
|
|
116
117
|
postId,
|
|
117
|
-
postType:
|
|
118
|
+
postType: NAVIGATION_POST_TYPE
|
|
118
119
|
});
|
|
119
120
|
return createElement(SidebarNavigationItem, {
|
|
120
121
|
...linkInfo,
|