@wordpress/edit-site 5.11.0 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/add-new-page/index.js +105 -0
- package/build/components/add-new-page/index.js.map +1 -0
- package/build/components/add-new-template/add-custom-generic-template-modal-content.js +4 -5
- package/build/components/add-new-template/add-custom-generic-template-modal-content.js.map +1 -1
- package/build/components/add-new-template/add-custom-template-modal-content.js +19 -22
- package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build/components/add-new-template/index.js +4 -5
- package/build/components/add-new-template/index.js.map +1 -1
- package/build/components/add-new-template/new-template-part.js +9 -12
- package/build/components/add-new-template/new-template-part.js.map +1 -1
- package/build/components/add-new-template/new-template.js +19 -26
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +71 -120
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/back-button.js +1 -3
- package/build/components/block-editor/back-button.js.map +1 -1
- package/build/components/block-editor/block-inspector-button.js +3 -4
- package/build/components/block-editor/block-inspector-button.js.map +1 -1
- package/build/components/block-editor/editor-canvas.js +6 -7
- package/build/components/block-editor/editor-canvas.js.map +1 -1
- package/build/components/block-editor/index.js +13 -10
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/block-editor/inserter-media-categories.js +25 -42
- package/build/components/block-editor/inserter-media-categories.js.map +1 -1
- package/build/components/block-editor/resizable-editor.js +6 -7
- package/build/components/block-editor/resizable-editor.js.map +1 -1
- package/build/components/block-editor/resize-handle.js +5 -7
- package/build/components/block-editor/resize-handle.js.map +1 -1
- package/build/components/code-editor/code-editor-text-area.js +5 -6
- package/build/components/code-editor/code-editor-text-area.js.map +1 -1
- package/build/components/create-template-part-modal/index.js +25 -29
- package/build/components/create-template-part-modal/index.js.map +1 -1
- package/build/components/editor/index.js +26 -17
- package/build/components/editor/index.js.map +1 -1
- package/build/components/editor-canvas-container/index.js +7 -8
- package/build/components/editor-canvas-container/index.js.map +1 -1
- package/build/components/error-boundary/warning.js +8 -10
- package/build/components/error-boundary/warning.js.map +1 -1
- package/build/components/global-styles/block-preview-panel.js +7 -10
- package/build/components/global-styles/block-preview-panel.js.map +1 -1
- package/build/components/global-styles/color-indicator-wrapper.js +4 -5
- package/build/components/global-styles/color-indicator-wrapper.js.map +1 -1
- package/build/components/global-styles/color-palette-panel.js +3 -4
- package/build/components/global-styles/color-palette-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +1 -3
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js +8 -10
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/gradients-palette-panel.js +3 -4
- package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build/components/global-styles/header.js +4 -5
- package/build/components/global-styles/header.js.map +1 -1
- package/build/components/global-styles/icon-with-current-color.js +4 -5
- package/build/components/global-styles/icon-with-current-color.js.map +1 -1
- package/build/components/global-styles/navigation-button.js +5 -6
- package/build/components/global-styles/navigation-button.js.map +1 -1
- package/build/components/global-styles/palette.js +10 -14
- package/build/components/global-styles/palette.js.map +1 -1
- package/build/components/global-styles/preview.js +41 -51
- package/build/components/global-styles/preview.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +4 -7
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-block.js +9 -10
- package/build/components/global-styles/screen-block.js.map +1 -1
- package/build/components/global-styles/screen-color-palette.js +3 -4
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-revisions/index.js +8 -8
- package/build/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build/components/global-styles/screen-revisions/revisions-buttons.js +14 -19
- package/build/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
- package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js +5 -11
- package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
- package/build/components/global-styles/screen-root.js +3 -3
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/global-styles/screen-typography-element.js +3 -4
- package/build/components/global-styles/screen-typography-element.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +5 -6
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/style-variations-container.js +5 -6
- package/build/components/global-styles/style-variations-container.js.map +1 -1
- package/build/components/global-styles/subtitle.js +4 -5
- package/build/components/global-styles/subtitle.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +4 -5
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/typography-preview.js +5 -6
- package/build/components/global-styles/typography-preview.js.map +1 -1
- package/build/components/global-styles/ui.js +40 -21
- package/build/components/global-styles/ui.js.map +1 -1
- package/build/components/global-styles/variations-panel.js +5 -6
- package/build/components/global-styles/variations-panel.js.map +1 -1
- package/build/components/header-edit-mode/document-actions/index.js +102 -23
- package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
- package/build/components/header-edit-mode/index.js +2 -6
- package/build/components/header-edit-mode/index.js.map +1 -1
- package/build/components/header-edit-mode/more-menu/index.js +49 -53
- package/build/components/header-edit-mode/more-menu/index.js.map +1 -1
- package/build/components/header-edit-mode/tools-more-menu-group/index.js +5 -14
- package/build/components/header-edit-mode/tools-more-menu-group/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +3 -4
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +41 -51
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +10 -12
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/layout/index.js +4 -12
- package/build/components/layout/index.js.map +1 -1
- package/build/components/list/added-by.js +13 -23
- package/build/components/list/added-by.js.map +1 -1
- package/build/components/list/header.js +4 -7
- package/build/components/list/header.js.map +1 -1
- package/build/components/list/index.js +2 -4
- package/build/components/list/index.js.map +1 -1
- package/build/components/list/table.js +35 -40
- package/build/components/list/table.js.map +1 -1
- package/build/components/page-actions/delete-page-menu-item.js +70 -0
- package/build/components/page-actions/delete-page-menu-item.js.map +1 -0
- package/build/components/page-actions/index.js +43 -0
- package/build/components/page-actions/index.js.map +1 -0
- package/build/components/page-content-lock/constants.js +9 -0
- package/build/components/page-content-lock/constants.js.map +1 -0
- package/build/components/page-content-lock/index.js +29 -0
- package/build/components/page-content-lock/index.js.map +1 -0
- package/build/components/page-content-lock/use-disable-non-content-blocks.js +49 -0
- package/build/components/page-content-lock/use-disable-non-content-blocks.js.map +1 -0
- package/build/components/page-content-lock/use-page-content-lock-notifications.js +112 -0
- package/build/components/page-content-lock/use-page-content-lock-notifications.js.map +1 -0
- package/build/components/preferences-modal/index.js +4 -5
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/resizable-frame/index.js +20 -12
- package/build/components/resizable-frame/index.js.map +1 -1
- package/build/components/revisions/index.js +11 -14
- package/build/components/revisions/index.js.map +1 -1
- package/build/components/routes/link.js +8 -12
- package/build/components/routes/link.js.map +1 -1
- package/build/components/routes/use-title.js +1 -5
- package/build/components/routes/use-title.js.map +1 -1
- package/build/components/save-button/index.js +13 -7
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/save-hub/index.js +97 -5
- package/build/components/save-hub/index.js.map +1 -1
- package/build/components/save-panel/index.js +63 -17
- package/build/components/save-panel/index.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +8 -3
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar/index.js +7 -5
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/default-sidebar.js +11 -12
- package/build/components/sidebar-edit-mode/default-sidebar.js.map +1 -1
- package/build/components/sidebar-edit-mode/index.js +13 -10
- package/build/components/sidebar-edit-mode/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/content-blocks-list.js +79 -0
- package/build/components/sidebar-edit-mode/page-panels/content-blocks-list.js.map +1 -0
- package/build/components/sidebar-edit-mode/page-panels/index.js +86 -0
- package/build/components/sidebar-edit-mode/page-panels/index.js.map +1 -0
- package/build/components/sidebar-edit-mode/plugin-sidebar/index.js +4 -5
- package/build/components/sidebar-edit-mode/plugin-sidebar/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/settings-header/index.js +39 -21
- package/build/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/sidebar-card/index.js +46 -0
- package/build/components/sidebar-edit-mode/sidebar-card/index.js.map +1 -0
- package/build/components/sidebar-edit-mode/sidebar-fixed-bottom.js +3 -4
- package/build/components/sidebar-edit-mode/sidebar-fixed-bottom.js.map +1 -1
- package/build/components/sidebar-edit-mode/{template-card → template-panel}/index.js +22 -18
- package/build/components/sidebar-edit-mode/template-panel/index.js.map +1 -0
- package/build/components/sidebar-edit-mode/{template-revisions/index.js → template-panel/last-revision.js} +7 -8
- package/{build-module/components/sidebar-edit-mode/template-revisions/index.js.map → build/components/sidebar-edit-mode/template-panel/last-revision.js.map} +1 -1
- package/build/components/sidebar-edit-mode/{template-card → template-panel}/template-actions.js +12 -16
- package/build/components/sidebar-edit-mode/template-panel/template-actions.js.map +1 -0
- package/build/components/sidebar-edit-mode/{template-card → template-panel}/template-areas.js +15 -19
- package/build/components/sidebar-edit-mode/template-panel/template-areas.js.map +1 -0
- package/build/components/sidebar-navigation-item/index.js +7 -8
- package/build/components/sidebar-navigation-item/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen/index.js +21 -14
- package/build/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-global-styles/index.js +103 -13
- package/build/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-item/index.js +3 -5
- package/build/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/index.js +7 -10
- package/build/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js +17 -23
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +20 -23
- package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +4 -5
- package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +8 -9
- package/build/components/sidebar-navigation-screen-navigation-menus/navigator-button.js.map +1 -1
- package/build/components/sidebar-navigation-screen-page/index.js +81 -10
- package/build/components/sidebar-navigation-screen-page/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-page/page-details.js +148 -0
- package/build/components/sidebar-navigation-screen-page/page-details.js.map +1 -0
- package/build/components/sidebar-navigation-screen-page/status-label.js +110 -0
- package/build/components/sidebar-navigation-screen-page/status-label.js.map +1 -0
- package/build/components/sidebar-navigation-screen-pages/index.js +128 -17
- package/build/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template/index.js +22 -16
- package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-template-part/index.js +105 -0
- package/build/components/sidebar-navigation-screen-template-part/index.js.map +1 -0
- package/build/components/sidebar-navigation-screen-templates/index.js +13 -18
- package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build/components/sidebar-navigation-subtitle/index.js +3 -4
- package/build/components/sidebar-navigation-subtitle/index.js.map +1 -1
- package/build/components/site-hub/index.js +20 -13
- package/build/components/site-hub/index.js.map +1 -1
- package/build/components/site-icon/index.js +4 -5
- package/build/components/site-icon/index.js.map +1 -1
- package/build/components/start-template-options/index.js +15 -21
- package/build/components/start-template-options/index.js.map +1 -1
- package/build/components/style-book/index.js +35 -39
- package/build/components/style-book/index.js.map +1 -1
- package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +2 -2
- 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 +9 -10
- package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build/components/{list/actions → template-actions}/index.js +34 -31
- package/build/components/template-actions/index.js.map +1 -0
- package/build/components/{list/actions → template-actions}/rename-menu-item.js +4 -5
- package/build/components/template-actions/rename-menu-item.js.map +1 -0
- package/build/components/template-part-converter/convert-to-regular.js +4 -5
- package/build/components/template-part-converter/convert-to-regular.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +8 -10
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/components/template-part-converter/index.js +12 -18
- package/build/components/template-part-converter/index.js.map +1 -1
- package/build/components/welcome-guide/image.js +4 -5
- package/build/components/welcome-guide/image.js.map +1 -1
- package/build/hooks/commands/use-edit-mode-commands.js +6 -8
- package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build/hooks/push-changes-to-global-styles/index.js +11 -8
- package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build/hooks/template-part-edit.js +5 -6
- package/build/hooks/template-part-edit.js.map +1 -1
- package/build/index.js +3 -6
- package/build/index.js.map +1 -1
- package/build/store/actions.js +129 -125
- package/build/store/actions.js.map +1 -1
- package/build/store/private-actions.js +7 -10
- package/build/store/private-actions.js.map +1 -1
- package/build/store/reducer.js +32 -33
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +35 -11
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +1 -3
- package/build/store/utils.js.map +1 -1
- package/build/utils/get-is-list-page.js +3 -4
- package/build/utils/get-is-list-page.js.map +1 -1
- package/build/utils/is-previewing-theme.js +1 -3
- package/build/utils/is-previewing-theme.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-module/components/add-new-page/index.js +93 -0
- package/build-module/components/add-new-page/index.js.map +1 -0
- package/build-module/components/add-new-template/add-custom-generic-template-modal-content.js +4 -5
- package/build-module/components/add-new-template/add-custom-generic-template-modal-content.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js +19 -22
- package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build-module/components/add-new-template/index.js +4 -5
- package/build-module/components/add-new-template/index.js.map +1 -1
- package/build-module/components/add-new-template/new-template-part.js +9 -12
- package/build-module/components/add-new-template/new-template-part.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +18 -26
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +71 -120
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/block-editor/back-button.js +1 -3
- package/build-module/components/block-editor/back-button.js.map +1 -1
- package/build-module/components/block-editor/block-inspector-button.js +3 -4
- package/build-module/components/block-editor/block-inspector-button.js.map +1 -1
- package/build-module/components/block-editor/editor-canvas.js +6 -7
- package/build-module/components/block-editor/editor-canvas.js.map +1 -1
- package/build-module/components/block-editor/index.js +12 -10
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/block-editor/inserter-media-categories.js +25 -42
- package/build-module/components/block-editor/inserter-media-categories.js.map +1 -1
- package/build-module/components/block-editor/resizable-editor.js +6 -7
- package/build-module/components/block-editor/resizable-editor.js.map +1 -1
- package/build-module/components/block-editor/resize-handle.js +5 -7
- package/build-module/components/block-editor/resize-handle.js.map +1 -1
- package/build-module/components/code-editor/code-editor-text-area.js +5 -6
- package/build-module/components/code-editor/code-editor-text-area.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +25 -29
- package/build-module/components/create-template-part-modal/index.js.map +1 -1
- package/build-module/components/editor/index.js +26 -17
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/editor-canvas-container/index.js +7 -8
- package/build-module/components/editor-canvas-container/index.js.map +1 -1
- package/build-module/components/error-boundary/warning.js +8 -10
- package/build-module/components/error-boundary/warning.js.map +1 -1
- package/build-module/components/global-styles/block-preview-panel.js +7 -10
- package/build-module/components/global-styles/block-preview-panel.js.map +1 -1
- package/build-module/components/global-styles/color-indicator-wrapper.js +4 -5
- package/build-module/components/global-styles/color-indicator-wrapper.js.map +1 -1
- package/build-module/components/global-styles/color-palette-panel.js +3 -4
- package/build-module/components/global-styles/color-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +1 -3
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js +8 -10
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/gradients-palette-panel.js +3 -4
- package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/header.js +4 -5
- package/build-module/components/global-styles/header.js.map +1 -1
- package/build-module/components/global-styles/icon-with-current-color.js +4 -5
- package/build-module/components/global-styles/icon-with-current-color.js.map +1 -1
- package/build-module/components/global-styles/navigation-button.js +5 -6
- package/build-module/components/global-styles/navigation-button.js.map +1 -1
- package/build-module/components/global-styles/palette.js +10 -14
- package/build-module/components/global-styles/palette.js.map +1 -1
- package/build-module/components/global-styles/preview.js +41 -51
- package/build-module/components/global-styles/preview.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +4 -7
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-block.js +9 -10
- package/build-module/components/global-styles/screen-block.js.map +1 -1
- package/build-module/components/global-styles/screen-color-palette.js +3 -4
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/index.js +8 -8
- package/build-module/components/global-styles/screen-revisions/index.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/revisions-buttons.js +14 -19
- package/build-module/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
- package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js +5 -10
- package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +3 -3
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/global-styles/screen-typography-element.js +3 -4
- package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +5 -6
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/style-variations-container.js +5 -6
- package/build-module/components/global-styles/style-variations-container.js.map +1 -1
- package/build-module/components/global-styles/subtitle.js +4 -5
- package/build-module/components/global-styles/subtitle.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +4 -5
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-preview.js +5 -6
- package/build-module/components/global-styles/typography-preview.js.map +1 -1
- package/build-module/components/global-styles/ui.js +40 -21
- package/build-module/components/global-styles/ui.js.map +1 -1
- package/build-module/components/global-styles/variations-panel.js +5 -6
- package/build-module/components/global-styles/variations-panel.js.map +1 -1
- package/build-module/components/header-edit-mode/document-actions/index.js +102 -24
- package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
- package/build-module/components/header-edit-mode/index.js +2 -6
- package/build-module/components/header-edit-mode/index.js.map +1 -1
- package/build-module/components/header-edit-mode/more-menu/index.js +49 -53
- package/build-module/components/header-edit-mode/more-menu/index.js.map +1 -1
- package/build-module/components/header-edit-mode/tools-more-menu-group/index.js +5 -13
- package/build-module/components/header-edit-mode/tools-more-menu-group/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +3 -4
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +39 -49
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +10 -12
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/layout/index.js +4 -12
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/list/added-by.js +13 -23
- package/build-module/components/list/added-by.js.map +1 -1
- package/build-module/components/list/header.js +4 -7
- package/build-module/components/list/header.js.map +1 -1
- package/build-module/components/list/index.js +2 -4
- package/build-module/components/list/index.js.map +1 -1
- package/build-module/components/list/table.js +34 -39
- package/build-module/components/list/table.js.map +1 -1
- package/build-module/components/page-actions/delete-page-menu-item.js +58 -0
- package/build-module/components/page-actions/delete-page-menu-item.js.map +1 -0
- package/build-module/components/page-actions/index.js +30 -0
- package/build-module/components/page-actions/index.js.map +1 -0
- package/build-module/components/page-content-lock/constants.js +2 -0
- package/build-module/components/page-content-lock/constants.js.map +1 -0
- package/build-module/components/page-content-lock/index.js +14 -0
- package/build-module/components/page-content-lock/index.js.map +1 -0
- package/build-module/components/page-content-lock/use-disable-non-content-blocks.js +36 -0
- package/build-module/components/page-content-lock/use-disable-non-content-blocks.js.map +1 -0
- package/build-module/components/page-content-lock/use-page-content-lock-notifications.js +98 -0
- package/build-module/components/page-content-lock/use-page-content-lock-notifications.js.map +1 -0
- package/build-module/components/preferences-modal/index.js +4 -5
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/resizable-frame/index.js +20 -12
- package/build-module/components/resizable-frame/index.js.map +1 -1
- package/build-module/components/revisions/index.js +11 -13
- package/build-module/components/revisions/index.js.map +1 -1
- package/build-module/components/routes/link.js +8 -12
- package/build-module/components/routes/link.js.map +1 -1
- package/build-module/components/routes/use-title.js +1 -5
- package/build-module/components/routes/use-title.js.map +1 -1
- package/build-module/components/save-button/index.js +13 -7
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/save-hub/index.js +95 -8
- package/build-module/components/save-hub/index.js.map +1 -1
- package/build-module/components/save-panel/index.js +62 -19
- package/build-module/components/save-panel/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +9 -3
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar/index.js +6 -5
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/default-sidebar.js +11 -12
- package/build-module/components/sidebar-edit-mode/default-sidebar.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/index.js +14 -11
- package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/content-blocks-list.js +67 -0
- package/build-module/components/sidebar-edit-mode/page-panels/content-blocks-list.js.map +1 -0
- package/build-module/components/sidebar-edit-mode/page-panels/index.js +67 -0
- package/build-module/components/sidebar-edit-mode/page-panels/index.js.map +1 -0
- package/build-module/components/sidebar-edit-mode/plugin-sidebar/index.js +4 -5
- package/build-module/components/sidebar-edit-mode/plugin-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/settings-header/index.js +36 -22
- package/build-module/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/sidebar-card/index.js +35 -0
- package/build-module/components/sidebar-edit-mode/sidebar-card/index.js.map +1 -0
- package/build-module/components/sidebar-edit-mode/sidebar-fixed-bottom.js +3 -4
- package/build-module/components/sidebar-edit-mode/sidebar-fixed-bottom.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/{template-card → template-panel}/index.js +20 -19
- package/build-module/components/sidebar-edit-mode/template-panel/index.js.map +1 -0
- package/build-module/components/sidebar-edit-mode/{template-revisions/index.js → template-panel/last-revision.js} +7 -8
- package/build-module/components/sidebar-edit-mode/template-panel/last-revision.js.map +1 -0
- package/build-module/components/sidebar-edit-mode/{template-card → template-panel}/template-actions.js +12 -16
- package/build-module/components/sidebar-edit-mode/template-panel/template-actions.js.map +1 -0
- package/build-module/components/sidebar-edit-mode/{template-card → template-panel}/template-areas.js +15 -19
- package/build-module/components/sidebar-edit-mode/template-panel/template-areas.js.map +1 -0
- package/build-module/components/sidebar-navigation-item/index.js +7 -8
- package/build-module/components/sidebar-navigation-item/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen/index.js +22 -15
- package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-global-styles/index.js +104 -14
- package/build-module/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-item/index.js +3 -5
- package/build-module/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js +7 -10
- package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +17 -23
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +20 -23
- package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +4 -5
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +8 -9
- package/build-module/components/sidebar-navigation-screen-navigation-menus/navigator-button.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-page/index.js +79 -14
- package/build-module/components/sidebar-navigation-screen-page/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-page/page-details.js +131 -0
- package/build-module/components/sidebar-navigation-screen-page/page-details.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-page/status-label.js +97 -0
- package/build-module/components/sidebar-navigation-screen-page/status-label.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-pages/index.js +125 -19
- package/build-module/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template/index.js +22 -17
- package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-template-part/index.js +86 -0
- package/build-module/components/sidebar-navigation-screen-template-part/index.js.map +1 -0
- package/build-module/components/sidebar-navigation-screen-templates/index.js +13 -18
- package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-subtitle/index.js +3 -4
- package/build-module/components/sidebar-navigation-subtitle/index.js.map +1 -1
- package/build-module/components/site-hub/index.js +21 -14
- package/build-module/components/site-hub/index.js.map +1 -1
- package/build-module/components/site-icon/index.js +4 -5
- package/build-module/components/site-icon/index.js.map +1 -1
- package/build-module/components/start-template-options/index.js +15 -21
- package/build-module/components/start-template-options/index.js.map +1 -1
- package/build-module/components/style-book/index.js +35 -39
- package/build-module/components/style-book/index.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +2 -2
- 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 +9 -10
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build-module/components/{list/actions → template-actions}/index.js +34 -31
- package/build-module/components/template-actions/index.js.map +1 -0
- package/build-module/components/{list/actions → template-actions}/rename-menu-item.js +4 -5
- package/build-module/components/template-actions/rename-menu-item.js.map +1 -0
- package/build-module/components/template-part-converter/convert-to-regular.js +4 -5
- package/build-module/components/template-part-converter/convert-to-regular.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +8 -10
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/components/template-part-converter/index.js +12 -18
- package/build-module/components/template-part-converter/index.js.map +1 -1
- package/build-module/components/welcome-guide/image.js +4 -5
- package/build-module/components/welcome-guide/image.js.map +1 -1
- package/build-module/hooks/commands/use-edit-mode-commands.js +6 -8
- package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
- package/build-module/hooks/push-changes-to-global-styles/index.js +11 -8
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +5 -6
- package/build-module/hooks/template-part-edit.js.map +1 -1
- package/build-module/index.js +3 -6
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +125 -126
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-actions.js +7 -10
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/reducer.js +30 -33
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +31 -11
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +1 -3
- package/build-module/store/utils.js.map +1 -1
- package/build-module/utils/get-is-list-page.js +3 -4
- package/build-module/utils/get-is-list-page.js.map +1 -1
- package/build-module/utils/is-previewing-theme.js +1 -3
- package/build-module/utils/is-previewing-theme.js.map +1 -1
- package/build-module/utils/is-template-revertable.js +1 -1
- package/build-module/utils/is-template-revertable.js.map +1 -1
- package/build-style/style-rtl.css +281 -59
- package/build-style/style.css +281 -59
- package/package.json +39 -36
- package/src/components/add-new-page/index.js +105 -0
- package/src/components/add-new-template/new-template.js +2 -1
- package/src/components/block-editor/index.js +25 -14
- package/src/components/editor/index.js +14 -8
- package/src/components/editor/style.scss +6 -11
- package/src/components/global-styles/screen-revisions/use-global-styles-revisions.js +7 -5
- package/src/components/global-styles/ui.js +28 -0
- package/src/components/header-edit-mode/document-actions/index.js +126 -32
- package/src/components/header-edit-mode/document-actions/style.scss +64 -9
- package/src/components/header-edit-mode/tools-more-menu-group/index.js +1 -6
- package/src/components/layout/index.js +3 -9
- package/src/components/list/table.js +6 -2
- package/src/components/page-actions/delete-page-menu-item.js +71 -0
- package/src/components/page-actions/index.js +36 -0
- package/src/components/page-content-lock/constants.js +5 -0
- package/src/components/page-content-lock/index.js +14 -0
- package/src/components/page-content-lock/use-disable-non-content-blocks.js +44 -0
- package/src/components/page-content-lock/use-page-content-lock-notifications.js +128 -0
- package/src/components/resizable-frame/index.js +15 -5
- package/src/components/resizable-frame/style.scss +20 -18
- package/src/components/revisions/index.js +6 -7
- package/src/components/save-button/index.js +6 -0
- package/src/components/save-hub/index.js +143 -38
- package/src/components/save-hub/style.scss +6 -0
- package/src/components/save-panel/index.js +62 -15
- package/src/components/secondary-sidebar/list-view-sidebar.js +8 -1
- package/src/components/sidebar/index.js +6 -4
- package/src/components/sidebar/style.scss +3 -4
- package/src/components/sidebar-edit-mode/index.js +16 -14
- package/src/components/sidebar-edit-mode/page-panels/content-blocks-list.js +77 -0
- package/src/components/sidebar-edit-mode/page-panels/index.js +89 -0
- package/src/components/sidebar-edit-mode/page-panels/style.scss +10 -0
- package/src/components/sidebar-edit-mode/settings-header/index.js +51 -28
- package/src/components/sidebar-edit-mode/sidebar-card/index.js +34 -0
- package/src/components/sidebar-edit-mode/sidebar-card/style.scss +34 -0
- package/src/components/sidebar-edit-mode/{template-card → template-panel}/index.js +22 -19
- package/src/components/sidebar-edit-mode/{template-card → template-panel}/style.scss +2 -32
- package/src/components/sidebar-navigation-screen/index.js +74 -50
- package/src/components/sidebar-navigation-screen/style.scss +45 -4
- package/src/components/sidebar-navigation-screen-global-styles/index.js +118 -12
- package/src/components/sidebar-navigation-screen-global-styles/style.scss +15 -0
- package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +1 -1
- package/src/components/sidebar-navigation-screen-page/index.js +137 -24
- package/src/components/sidebar-navigation-screen-page/page-details.js +163 -0
- package/src/components/sidebar-navigation-screen-page/status-label.js +101 -0
- package/src/components/sidebar-navigation-screen-page/style.scss +80 -0
- package/src/components/sidebar-navigation-screen-pages/index.js +180 -44
- package/src/components/sidebar-navigation-screen-template/index.js +25 -22
- package/src/components/sidebar-navigation-screen-template-part/index.js +103 -0
- package/src/components/sidebar-navigation-screen-templates/index.js +1 -1
- package/src/components/sidebar-navigation-subtitle/style.scss +2 -2
- package/src/components/site-hub/index.js +21 -6
- package/src/components/site-hub/style.scss +26 -0
- package/src/components/{list/actions → template-actions}/index.js +19 -6
- package/src/hooks/push-changes-to-global-styles/index.js +13 -7
- package/src/store/actions.js +20 -1
- package/src/store/reducer.js +20 -0
- package/src/store/selectors.js +24 -0
- package/src/store/test/actions.js +31 -0
- package/src/store/test/reducer.js +44 -0
- package/src/store/test/selectors.js +57 -0
- package/src/style.scss +5 -2
- package/src/utils/is-previewing-theme.js +1 -4
- package/build/components/list/actions/index.js.map +0 -1
- package/build/components/list/actions/rename-menu-item.js.map +0 -1
- package/build/components/sidebar-edit-mode/template-card/index.js.map +0 -1
- package/build/components/sidebar-edit-mode/template-card/template-actions.js.map +0 -1
- package/build/components/sidebar-edit-mode/template-card/template-areas.js.map +0 -1
- package/build/components/sidebar-edit-mode/template-revisions/index.js.map +0 -1
- package/build-module/components/list/actions/index.js.map +0 -1
- package/build-module/components/list/actions/rename-menu-item.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/template-card/index.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/template-card/template-actions.js.map +0 -1
- package/build-module/components/sidebar-edit-mode/template-card/template-areas.js.map +0 -1
- package/src/components/sidebar-navigation-screen-pages/style.scss +0 -4
- /package/src/components/sidebar-edit-mode/{template-revisions/index.js → template-panel/last-revision.js} +0 -0
- /package/src/components/sidebar-edit-mode/{template-card → template-panel}/template-actions.js +0 -0
- /package/src/components/sidebar-edit-mode/{template-card → template-panel}/template-areas.js +0 -0
- /package/src/components/{list/actions → template-actions}/rename-menu-item.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = AddNewPageModal;
|
|
7
|
+
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
9
|
+
|
|
10
|
+
var _lodash = require("lodash");
|
|
11
|
+
|
|
12
|
+
var _components = require("@wordpress/components");
|
|
13
|
+
|
|
14
|
+
var _i18n = require("@wordpress/i18n");
|
|
15
|
+
|
|
16
|
+
var _data = require("@wordpress/data");
|
|
17
|
+
|
|
18
|
+
var _coreData = require("@wordpress/core-data");
|
|
19
|
+
|
|
20
|
+
var _notices = require("@wordpress/notices");
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* External dependencies
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* WordPress dependencies
|
|
28
|
+
*/
|
|
29
|
+
function AddNewPageModal({
|
|
30
|
+
onSave,
|
|
31
|
+
onClose
|
|
32
|
+
}) {
|
|
33
|
+
const [isCreatingPage, setIsCreatingPage] = (0, _element.useState)(false);
|
|
34
|
+
const [title, setTitle] = (0, _element.useState)('');
|
|
35
|
+
const {
|
|
36
|
+
saveEntityRecord
|
|
37
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
38
|
+
const {
|
|
39
|
+
createErrorNotice,
|
|
40
|
+
createSuccessNotice
|
|
41
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
42
|
+
|
|
43
|
+
async function createPage(event) {
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
|
|
46
|
+
if (isCreatingPage) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setIsCreatingPage(true);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const newPage = await saveEntityRecord('postType', 'page', {
|
|
54
|
+
status: 'draft',
|
|
55
|
+
title,
|
|
56
|
+
slug: (0, _lodash.kebabCase)(title || (0, _i18n.__)('No title'))
|
|
57
|
+
}, {
|
|
58
|
+
throwOnError: true
|
|
59
|
+
});
|
|
60
|
+
onSave(newPage);
|
|
61
|
+
createSuccessNotice((0, _i18n.sprintf)( // translators: %s: Title of the created template e.g: "Category".
|
|
62
|
+
(0, _i18n.__)('"%s" successfully created.'), newPage.title?.rendered || title), {
|
|
63
|
+
type: 'snackbar'
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0, _i18n.__)('An error occurred while creating the page.');
|
|
67
|
+
createErrorNotice(errorMessage, {
|
|
68
|
+
type: 'snackbar'
|
|
69
|
+
});
|
|
70
|
+
} finally {
|
|
71
|
+
setIsCreatingPage(false);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (0, _element.createElement)(_components.Modal, {
|
|
76
|
+
title: (0, _i18n.__)('Draft a new page'),
|
|
77
|
+
onRequestClose: onClose
|
|
78
|
+
}, (0, _element.createElement)("form", {
|
|
79
|
+
onSubmit: createPage
|
|
80
|
+
}, (0, _element.createElement)(_components.__experimentalVStack, {
|
|
81
|
+
spacing: 3
|
|
82
|
+
}, (0, _element.createElement)(_components.TextControl
|
|
83
|
+
/* eslint-disable jsx-a11y/no-autofocus */
|
|
84
|
+
, {
|
|
85
|
+
autoFocus: true
|
|
86
|
+
/* eslint-enable jsx-a11y/no-autofocus */
|
|
87
|
+
,
|
|
88
|
+
label: (0, _i18n.__)('Page title'),
|
|
89
|
+
onChange: setTitle,
|
|
90
|
+
placeholder: (0, _i18n.__)('No title'),
|
|
91
|
+
value: title
|
|
92
|
+
}), (0, _element.createElement)(_components.__experimentalHStack, {
|
|
93
|
+
spacing: 2,
|
|
94
|
+
justify: "end"
|
|
95
|
+
}, (0, _element.createElement)(_components.Button, {
|
|
96
|
+
variant: "tertiary",
|
|
97
|
+
onClick: onClose
|
|
98
|
+
}, (0, _i18n.__)('Cancel')), (0, _element.createElement)(_components.Button, {
|
|
99
|
+
variant: "primary",
|
|
100
|
+
type: "submit",
|
|
101
|
+
isBusy: isCreatingPage,
|
|
102
|
+
"aria-disabled": isCreatingPage
|
|
103
|
+
}, (0, _i18n.__)('Create draft'))))));
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-page/index.js"],"names":["AddNewPageModal","onSave","onClose","isCreatingPage","setIsCreatingPage","title","setTitle","saveEntityRecord","coreStore","createErrorNotice","createSuccessNotice","noticesStore","createPage","event","preventDefault","newPage","status","slug","throwOnError","rendered","type","error","errorMessage","message","code"],"mappings":";;;;;;;AAiBA;;AAdA;;AAKA;;AAOA;;AACA;;AAEA;;AACA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;AAce,SAASA,eAAT,CAA0B;AAAEC,EAAAA,MAAF;AAAUC,EAAAA;AAAV,CAA1B,EAAgD;AAC9D,QAAM,CAAEC,cAAF,EAAkBC,iBAAlB,IAAwC,uBAAU,KAAV,CAA9C;AACA,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsB,uBAAU,EAAV,CAA5B;AAEA,QAAM;AAAEC,IAAAA;AAAF,MAAuB,uBAAaC,eAAb,CAA7B;AACA,QAAM;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA;AAArB,MACL,uBAAaC,cAAb,CADD;;AAGA,iBAAeC,UAAf,CAA2BC,KAA3B,EAAmC;AAClCA,IAAAA,KAAK,CAACC,cAAN;;AAEA,QAAKX,cAAL,EAAsB;AACrB;AACA;;AACDC,IAAAA,iBAAiB,CAAE,IAAF,CAAjB;;AACA,QAAI;AACH,YAAMW,OAAO,GAAG,MAAMR,gBAAgB,CACrC,UADqC,EAErC,MAFqC,EAGrC;AACCS,QAAAA,MAAM,EAAE,OADT;AAECX,QAAAA,KAFD;AAGCY,QAAAA,IAAI,EAAE,uBAAWZ,KAAK,IAAI,cAAI,UAAJ,CAApB;AAHP,OAHqC,EAQrC;AAAEa,QAAAA,YAAY,EAAE;AAAhB,OARqC,CAAtC;AAWAjB,MAAAA,MAAM,CAAEc,OAAF,CAAN;AAEAL,MAAAA,mBAAmB,CAClB,oBACC;AACA,oBAAI,4BAAJ,CAFD,EAGCK,OAAO,CAACV,KAAR,EAAec,QAAf,IAA2Bd,KAH5B,CADkB,EAMlB;AACCe,QAAAA,IAAI,EAAE;AADP,OANkB,CAAnB;AAUA,KAxBD,CAwBE,OAAQC,KAAR,EAAgB;AACjB,YAAMC,YAAY,GACjBD,KAAK,CAACE,OAAN,IAAiBF,KAAK,CAACG,IAAN,KAAe,eAAhC,GACGH,KAAK,CAACE,OADT,GAEG,cAAI,4CAAJ,CAHJ;AAKAd,MAAAA,iBAAiB,CAAEa,YAAF,EAAgB;AAChCF,QAAAA,IAAI,EAAE;AAD0B,OAAhB,CAAjB;AAGA,KAjCD,SAiCU;AACThB,MAAAA,iBAAiB,CAAE,KAAF,CAAjB;AACA;AACD;;AAED,SACC,4BAAC,iBAAD;AAAO,IAAA,KAAK,EAAG,cAAI,kBAAJ,CAAf;AAA0C,IAAA,cAAc,EAAGF;AAA3D,KACC;AAAM,IAAA,QAAQ,EAAGU;AAAjB,KACC,4BAAC,gCAAD;AAAQ,IAAA,OAAO,EAAG;AAAlB,KACC,4BAAC;AACA;AADD;AAEC,IAAA,SAAS;AACT;AAHD;AAIC,IAAA,KAAK,EAAG,cAAI,YAAJ,CAJT;AAKC,IAAA,QAAQ,EAAGN,QALZ;AAMC,IAAA,WAAW,EAAG,cAAI,UAAJ,CANf;AAOC,IAAA,KAAK,EAAGD;AAPT,IADD,EAUC,4BAAC,gCAAD;AAAQ,IAAA,OAAO,EAAG,CAAlB;AAAsB,IAAA,OAAO,EAAC;AAA9B,KACC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGH;AAArC,KACG,cAAI,QAAJ,CADH,CADD,EAIC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGC,cAHV;AAIC,qBAAgBA;AAJjB,KAMG,cAAI,cAAJ,CANH,CAJD,CAVD,CADD,CADD,CADD;AA8BA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tTextControl,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\n\nexport default function AddNewPageModal( { onSave, onClose } ) {\n\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tasync function createPage( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isCreatingPage ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsCreatingPage( true );\n\t\ttry {\n\t\t\tconst newPage = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'page',\n\t\t\t\t{\n\t\t\t\t\tstatus: 'draft',\n\t\t\t\t\ttitle,\n\t\t\t\t\tslug: kebabCase( title || __( 'No title' ) ),\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tonSave( newPage );\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\tnewPage.title?.rendered || title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the page.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsCreatingPage( false );\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal title={ __( 'Draft a new page' ) } onRequestClose={ onClose }>\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t/* eslint-disable jsx-a11y/no-autofocus */\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\t/* eslint-enable jsx-a11y/no-autofocus */\n\t\t\t\t\t\tlabel={ __( 'Page title' ) }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ onClose }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create draft' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"]}
|
|
@@ -20,11 +20,10 @@ var _components = require("@wordpress/components");
|
|
|
20
20
|
/**
|
|
21
21
|
* WordPress dependencies
|
|
22
22
|
*/
|
|
23
|
-
function AddCustomGenericTemplateModalContent(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} = _ref;
|
|
23
|
+
function AddCustomGenericTemplateModalContent({
|
|
24
|
+
onClose,
|
|
25
|
+
createTemplate
|
|
26
|
+
}) {
|
|
28
27
|
const [title, setTitle] = (0, _element.useState)('');
|
|
29
28
|
const defaultTitle = (0, _i18n.__)('Custom Template');
|
|
30
29
|
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-generic-template-modal-content.js"],"names":["AddCustomGenericTemplateModalContent","onClose","createTemplate","title","setTitle","defaultTitle","isBusy","setIsBusy","onCreateTemplate","event","preventDefault","slug"],"mappings":";;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAUA,SAASA,oCAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-generic-template-modal-content.js"],"names":["AddCustomGenericTemplateModalContent","onClose","createTemplate","title","setTitle","defaultTitle","isBusy","setIsBusy","onCreateTemplate","event","preventDefault","slug"],"mappings":";;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAUA,SAASA,oCAAT,CAA+C;AAAEC,EAAAA,OAAF;AAAWC,EAAAA;AAAX,CAA/C,EAA6E;AAC5E,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsB,uBAAU,EAAV,CAA5B;AACA,QAAMC,YAAY,GAAG,cAAI,iBAAJ,CAArB;AACA,QAAM,CAAEC,MAAF,EAAUC,SAAV,IAAwB,uBAAU,KAAV,CAA9B;;AACA,iBAAeC,gBAAf,CAAiCC,KAAjC,EAAyC;AACxCA,IAAAA,KAAK,CAACC,cAAN;;AACA,QAAKJ,MAAL,EAAc;AACb;AACA;;AACDC,IAAAA,SAAS,CAAE,IAAF,CAAT;;AACA,QAAI;AACH,YAAML,cAAc,CACnB;AACCS,QAAAA,IAAI,EACH,wBACA,uBAAWR,KAAK,IAAIE,YAApB,CAHF;AAICF,QAAAA,KAAK,EAAEA,KAAK,IAAIE;AAJjB,OADmB,EAOnB,KAPmB,CAApB;AASA,KAVD,SAUU;AACTE,MAAAA,SAAS,CAAE,KAAF,CAAT;AACA;AACD;;AACD,SACC;AAAM,IAAA,QAAQ,EAAGC;AAAjB,KACC,4BAAC,gCAAD;AAAQ,IAAA,OAAO,EAAG;AAAlB,KACC,4BAAC,uBAAD;AACC,IAAA,uBAAuB,MADxB;AAEC,IAAA,KAAK,EAAG,cAAI,MAAJ,CAFT;AAGC,IAAA,KAAK,EAAGL,KAHT;AAIC,IAAA,QAAQ,EAAGC,QAJZ;AAKC,IAAA,WAAW,EAAGC,YALf;AAMC,IAAA,QAAQ,EAAGC,MANZ;AAOC,IAAA,IAAI,EAAG,cACN,iHADM;AAPR,IADD,EAYC,4BAAC,gCAAD;AACC,IAAA,SAAS,EAAC,kDADX;AAEC,IAAA,OAAO,EAAC;AAFT,KAIC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfL,MAAAA,OAAO;AACP;AAJF,KAMG,cAAI,QAAJ,CANH,CAJD,EAYC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGK,MAHV;AAIC,qBAAgBA;AAJjB,KAMG,cAAI,QAAJ,CANH,CAZD,CAZD,CADD,CADD;AAsCA;;eAEcN,oC","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\n\nfunction AddCustomGenericTemplateModalContent( { onClose, createTemplate } ) {\n\tconst [ title, setTitle ] = useState( '' );\n\tconst defaultTitle = __( 'Custom Template' );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\tasync function onCreateTemplate( event ) {\n\t\tevent.preventDefault();\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsBusy( true );\n\t\ttry {\n\t\t\tawait createTemplate(\n\t\t\t\t{\n\t\t\t\t\tslug:\n\t\t\t\t\t\t'wp-custom-template-' +\n\t\t\t\t\t\tkebabCase( title || defaultTitle ),\n\t\t\t\t\ttitle: title || defaultTitle,\n\t\t\t\t},\n\t\t\t\tfalse\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsBusy( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form onSubmit={ onCreateTemplate }>\n\t\t\t<VStack spacing={ 6 }>\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\tplaceholder={ defaultTitle }\n\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Describe the template, e.g. \"Post with sidebar\". A custom template can be manually applied to any post or page.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t\t<HStack\n\t\t\t\t\tclassName=\"edit-site-custom-generic-template__modal-actions\"\n\t\t\t\t\tjustify=\"right\"\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nexport default AddCustomGenericTemplateModalContent;\n"]}
|
|
@@ -32,14 +32,13 @@ var _utils = require("./utils");
|
|
|
32
32
|
*/
|
|
33
33
|
const EMPTY_ARRAY = [];
|
|
34
34
|
|
|
35
|
-
function SuggestionListItem(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} = _ref;
|
|
35
|
+
function SuggestionListItem({
|
|
36
|
+
suggestion,
|
|
37
|
+
search,
|
|
38
|
+
onSelect,
|
|
39
|
+
entityForSuggestions,
|
|
40
|
+
composite
|
|
41
|
+
}) {
|
|
43
42
|
const baseCssClass = 'edit-site-custom-template-modal__suggestions_list__list-item';
|
|
44
43
|
return (0, _element.createElement)(_components.__unstableCompositeItem, (0, _extends2.default)({
|
|
45
44
|
role: "option",
|
|
@@ -96,7 +95,7 @@ function useSearchSuggestions(entityForSuggestions, search) {
|
|
|
96
95
|
if (!searchHasResolved) return;
|
|
97
96
|
let newSuggestions = EMPTY_ARRAY;
|
|
98
97
|
|
|
99
|
-
if (searchResults
|
|
98
|
+
if (searchResults?.length) {
|
|
100
99
|
newSuggestions = searchResults;
|
|
101
100
|
|
|
102
101
|
if (config.recordNamePath) {
|
|
@@ -111,11 +110,10 @@ function useSearchSuggestions(entityForSuggestions, search) {
|
|
|
111
110
|
return suggestions;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
function SuggestionList(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
} = _ref2;
|
|
113
|
+
function SuggestionList({
|
|
114
|
+
entityForSuggestions,
|
|
115
|
+
onSelect
|
|
116
|
+
}) {
|
|
119
117
|
const composite = (0, _components.__unstableUseCompositeState)({
|
|
120
118
|
orientation: 'vertical'
|
|
121
119
|
});
|
|
@@ -126,7 +124,7 @@ function SuggestionList(_ref2) {
|
|
|
126
124
|
} = entityForSuggestions;
|
|
127
125
|
const [showSearchControl, setShowSearchControl] = (0, _element.useState)(false);
|
|
128
126
|
|
|
129
|
-
if (!showSearchControl &&
|
|
127
|
+
if (!showSearchControl && suggestions?.length > 9) {
|
|
130
128
|
setShowSearchControl(true);
|
|
131
129
|
}
|
|
132
130
|
|
|
@@ -136,7 +134,7 @@ function SuggestionList(_ref2) {
|
|
|
136
134
|
value: search,
|
|
137
135
|
label: labels.search_items,
|
|
138
136
|
placeholder: labels.search_items
|
|
139
|
-
}), !!
|
|
137
|
+
}), !!suggestions?.length && (0, _element.createElement)(_components.__unstableComposite, (0, _extends2.default)({}, composite, {
|
|
140
138
|
role: "listbox",
|
|
141
139
|
className: "edit-site-custom-template-modal__suggestions_list",
|
|
142
140
|
"aria-label": (0, _i18n.__)('Suggestions list')
|
|
@@ -147,17 +145,16 @@ function SuggestionList(_ref2) {
|
|
|
147
145
|
onSelect: onSelect,
|
|
148
146
|
entityForSuggestions: entityForSuggestions,
|
|
149
147
|
composite: composite
|
|
150
|
-
}))), debouncedSearch && !
|
|
148
|
+
}))), debouncedSearch && !suggestions?.length && (0, _element.createElement)(_components.__experimentalText, {
|
|
151
149
|
as: "p",
|
|
152
150
|
className: "edit-site-custom-template-modal__no-results"
|
|
153
151
|
}, labels.not_found));
|
|
154
152
|
}
|
|
155
153
|
|
|
156
|
-
function AddCustomTemplateModalContent(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
} = _ref3;
|
|
154
|
+
function AddCustomTemplateModalContent({
|
|
155
|
+
onSelect,
|
|
156
|
+
entityForSuggestions
|
|
157
|
+
}) {
|
|
161
158
|
const [showSearchEntities, setShowSearchEntities] = (0, _element.useState)(entityForSuggestions.hasGeneralTemplate);
|
|
162
159
|
return (0, _element.createElement)(_components.__experimentalVStack, {
|
|
163
160
|
spacing: 4,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal-content.js"],"names":["EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","Button","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModalContent","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","title","description","templatePrefix","template","all_items","singular_name"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAYA;;AACA;;AACA;;AAKA;;AAxBA;AACA;AACA;;AAmBA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;;AAEA,SAASC,kBAAT,OAMI;AAAA,MANyB;AAC5BC,IAAAA,UAD4B;AAE5BC,IAAAA,MAF4B;AAG5BC,IAAAA,QAH4B;AAI5BC,IAAAA,oBAJ4B;AAK5BC,IAAAA;AAL4B,GAMzB;AACH,QAAMC,YAAY,GACjB,8DADD;AAEA,SACC,4BAAC,mCAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,EAAE,EAAGC;AAFN,KAGMF,SAHN;AAIC,IAAA,SAAS,EAAGC,YAJb;AAKC,IAAA,OAAO,EAAG,MACTH,QAAQ,CACPC,oBAAoB,CAACI,MAArB,CAA4BC,mBAA5B,CACCR,UADD,CADO;AANV,MAaC,4BAAC,8BAAD;AACC,IAAA,IAAI,EAAC,MADN;AAEC,IAAA,UAAU,EAAG,aAFd,CAE8B;AAF9B;AAGC,IAAA,MAAM,EAAG,GAHV;AAIC,IAAA,SAAS,EAAI,GAAGK,YAAc;AAJ/B,KAMC,4BAAC,yBAAD;AACC,IAAA,IAAI,EAAG,kCAAgBL,UAAU,CAACS,IAA3B,CADR;AAEC,IAAA,SAAS,EAAGR;AAFb,IAND,CAbD,EAwBGD,UAAU,CAACU,IAAX,IACD,4BAAC,8BAAD;AACC,IAAA,IAAI,EAAC,MADN;AAEC,IAAA,UAAU,EAAG,aAFd,CAE8B;AAF9B;AAGC,IAAA,SAAS,EAAI,GAAGL,YAAc;AAH/B,KAKGL,UAAU,CAACU,IALd,CAzBF,CADD;AAoCA;;AAED,SAASC,iBAAT,GAA6B;AAC5B,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsB,u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Memo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<Text\n\t\t\t\tsize=\"body\"\n\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\tweight={ 500 }\n\t\t\t\tclassName={ `${ baseCssClass }__title` }\n\t\t\t>\n\t\t\t\t<TextHighlight\n\t\t\t\t\ttext={ decodeEntities( suggestion.name ) }\n\t\t\t\t\thighlight={ search }\n\t\t\t\t/>\n\t\t\t</Text>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<Text\n\t\t\t\t\tsize=\"body\"\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\tclassName={ `${ baseCssClass }__info` }\n\t\t\t\t>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\t{ ...composite }\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<Text\n\t\t\t\t\tas=\"p\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__no-results\"\n\t\t\t\t>\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModalContent( { onSelect, entityForSuggestions } ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 4 }\n\t\t\tclassName=\"edit-site-custom-template-modal__contents-wrapper\"\n\t\t\talignment=\"left\"\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName=\"edit-site-custom-template-modal__contents\"\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} = entityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport default AddCustomTemplateModalContent;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal-content.js"],"names":["EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","Button","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModalContent","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","title","description","templatePrefix","template","all_items","singular_name"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAYA;;AACA;;AACA;;AAKA;;AAxBA;AACA;AACA;;AAmBA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;;AAEA,SAASC,kBAAT,CAA6B;AAC5BC,EAAAA,UAD4B;AAE5BC,EAAAA,MAF4B;AAG5BC,EAAAA,QAH4B;AAI5BC,EAAAA,oBAJ4B;AAK5BC,EAAAA;AAL4B,CAA7B,EAMI;AACH,QAAMC,YAAY,GACjB,8DADD;AAEA,SACC,4BAAC,mCAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,EAAE,EAAGC;AAFN,KAGMF,SAHN;AAIC,IAAA,SAAS,EAAGC,YAJb;AAKC,IAAA,OAAO,EAAG,MACTH,QAAQ,CACPC,oBAAoB,CAACI,MAArB,CAA4BC,mBAA5B,CACCR,UADD,CADO;AANV,MAaC,4BAAC,8BAAD;AACC,IAAA,IAAI,EAAC,MADN;AAEC,IAAA,UAAU,EAAG,aAFd,CAE8B;AAF9B;AAGC,IAAA,MAAM,EAAG,GAHV;AAIC,IAAA,SAAS,EAAI,GAAGK,YAAc;AAJ/B,KAMC,4BAAC,yBAAD;AACC,IAAA,IA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AAAM,IAAA,EAAE,EAAC;AAAT,KACG,cACD,+DADC,CADH,CADD,EAMC,4BAAC,cAAD;AACC,IAAA,oBAAoB,EAAG1C,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CAhFF,CADD;AA+FA;;eAEc0C,6B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<Text\n\t\t\t\tsize=\"body\"\n\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\tweight={ 500 }\n\t\t\t\tclassName={ `${ baseCssClass }__title` }\n\t\t\t>\n\t\t\t\t<TextHighlight\n\t\t\t\t\ttext={ decodeEntities( suggestion.name ) }\n\t\t\t\t\thighlight={ search }\n\t\t\t\t/>\n\t\t\t</Text>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<Text\n\t\t\t\t\tsize=\"body\"\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\tclassName={ `${ baseCssClass }__info` }\n\t\t\t\t>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\t{ ...composite }\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<Text\n\t\t\t\t\tas=\"p\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__no-results\"\n\t\t\t\t>\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModalContent( { onSelect, entityForSuggestions } ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 4 }\n\t\t\tclassName=\"edit-site-custom-template-modal__contents-wrapper\"\n\t\t\talignment=\"left\"\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName=\"edit-site-custom-template-modal__contents\"\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} = entityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport default AddCustomTemplateModalContent;\n"]}
|
|
@@ -26,11 +26,10 @@ var _newTemplatePart = _interopRequireDefault(require("./new-template-part"));
|
|
|
26
26
|
/**
|
|
27
27
|
* Internal dependencies
|
|
28
28
|
*/
|
|
29
|
-
function AddNewTemplate(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} = _ref;
|
|
29
|
+
function AddNewTemplate({
|
|
30
|
+
templateType = 'wp_template',
|
|
31
|
+
...props
|
|
32
|
+
}) {
|
|
34
33
|
const postType = (0, _data.useSelect)(select => select(_coreData.store).getPostType(templateType), [templateType]);
|
|
35
34
|
|
|
36
35
|
if (!postType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"names":["AddNewTemplate","templateType","props","postType","select","coreStore","getPostType"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIe,SAASA,cAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"names":["AddNewTemplate","templateType","props","postType","select","coreStore","getPostType"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIe,SAASA,cAAT,CAAyB;AACvCC,EAAAA,YAAY,GAAG,aADwB;AAEvC,KAAGC;AAFoC,CAAzB,EAGX;AACH,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAcA,MAAM,CAAEC,eAAF,CAAN,CAAoBC,WAApB,CAAiCL,YAAjC,CADE,EAEhB,CAAEA,YAAF,CAFgB,CAAjB;;AAKA,MAAK,CAAEE,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,MAAKF,YAAY,KAAK,aAAtB,EAAsC;AACrC,WAAO,4BAAC,oBAAD,6BAAkBC,KAAlB;AAA0B,MAAA,QAAQ,EAAGC;AAArC,OAAP;AACA,GAFD,MAEO,IAAKF,YAAY,KAAK,kBAAtB,EAA2C;AACjD,WAAO,4BAAC,wBAAD,6BAAsBC,KAAtB;AAA8B,MAAA,QAAQ,EAAGC;AAAzC,OAAP;AACA;;AAED,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport NewTemplate from './new-template';\nimport NewTemplatePart from './new-template-part';\n\nexport default function AddNewTemplate( {\n\ttemplateType = 'wp_template',\n\t...props\n} ) {\n\tconst postType = useSelect(\n\t\t( select ) => select( coreStore ).getPostType( templateType ),\n\t\t[ templateType ]\n\t);\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\tif ( templateType === 'wp_template' ) {\n\t\treturn <NewTemplate { ...props } postType={ postType } />;\n\t} else if ( templateType === 'wp_template_part' ) {\n\t\treturn <NewTemplatePart { ...props } postType={ postType } />;\n\t}\n\n\treturn null;\n}\n"]}
|
|
@@ -42,12 +42,11 @@ const {
|
|
|
42
42
|
useHistory
|
|
43
43
|
} = (0, _privateApis.unlock)(_router.privateApis);
|
|
44
44
|
|
|
45
|
-
function NewTemplatePart(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = _ref;
|
|
45
|
+
function NewTemplatePart({
|
|
46
|
+
postType,
|
|
47
|
+
showIcon = true,
|
|
48
|
+
toggleProps
|
|
49
|
+
}) {
|
|
51
50
|
const history = useHistory();
|
|
52
51
|
const [isModalOpen, setIsModalOpen] = (0, _element.useState)(false);
|
|
53
52
|
const {
|
|
@@ -58,12 +57,10 @@ function NewTemplatePart(_ref) {
|
|
|
58
57
|
} = (0, _data.useDispatch)(_coreData.store);
|
|
59
58
|
const existingTemplateParts = (0, _templatePartCreate.useExistingTemplateParts)();
|
|
60
59
|
|
|
61
|
-
async function createTemplatePart(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} = _ref2;
|
|
66
|
-
|
|
60
|
+
async function createTemplatePart({
|
|
61
|
+
title,
|
|
62
|
+
area
|
|
63
|
+
}) {
|
|
67
64
|
if (!title) {
|
|
68
65
|
createErrorNotice((0, _i18n.__)('Title is not defined.'), {
|
|
69
66
|
type: 'snackbar'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template-part.js"],"names":["useHistory","routerPrivateApis","NewTemplatePart","postType","showIcon","toggleProps","history","isModalOpen","setIsModalOpen","createErrorNotice","noticesStore","saveEntityRecord","coreStore","existingTemplateParts","createTemplatePart","title","area","type","uniqueTitle","cleanSlug","templatePart","slug","content","throwOnError","push","postId","id","canvas","error","errorMessage","message","code","as","Toggle","Button","restToggleProps","plus","labels","add_new"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AArBA;AACA;AACA;;AAUA;AACA;AACA;AASA,MAAM;AAAEA,EAAAA;AAAF,IAAiB,yBAAQC,mBAAR,CAAvB;;AAEe,SAASC,eAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template-part.js"],"names":["useHistory","routerPrivateApis","NewTemplatePart","postType","showIcon","toggleProps","history","isModalOpen","setIsModalOpen","createErrorNotice","noticesStore","saveEntityRecord","coreStore","existingTemplateParts","createTemplatePart","title","area","type","uniqueTitle","cleanSlug","templatePart","slug","content","throwOnError","push","postId","id","canvas","error","errorMessage","message","code","as","Toggle","Button","restToggleProps","plus","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AACAF,MAAAA,OAAO,CAACkB,IAAR,CAAc;AACbC,QAAAA,MAAM,EAAEL,YAAY,CAACM,EADR;AAEbvB,QAAAA,QAAQ,EAAE,kBAFG;AAGbwB,QAAAA,MAAM,EAAE;AAHK,OAAd,EAtBG,CA4BH;AACA,KA7BD,CA6BE,OAAQC,KAAR,EAAgB;AACjB,YAAMC,YAAY,GACjBD,KAAK,CAACE,OAAN,IAAiBF,KAAK,CAACG,IAAN,KAAe,eAAhC,GACGH,KAAK,CAACE,OADT,GAEG,cACA,qDADA,CAHJ;AAOArB,MAAAA,iBAAiB,CAAEoB,YAAF,EAAgB;AAAEZ,QAAAA,IAAI,EAAE;AAAR,OAAhB,CAAjB;AAEAT,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA;AACD;;AACD,QAAM;AAAEwB,IAAAA,EAAE,EAAEC,MAAM,GAAGC,kBAAf;AAAuB,OAAGC;AAA1B,MAA8C9B,WAA9C,aAA8CA,WAA9C,cAA8CA,WAA9C,GAA6D,EAAnE;AAEA,SACC,qDACC,4BAAC,MAAD,6BACM8B,eADN;AAEC,IAAA,OAAO,EAAG,MAAM;AACf3B,MAAAA,cAAc,CAAE,IAAF,CAAd;AACA,KAJF;AAKC,IAAA,IAAI,EAAGJ,QAAQ,GAAGgC,WAAH,GAAU,IAL1B;AAMC,IAAA,KAAK,EAAGjC,QAAQ,CAACkC,MAAT,CAAgBC;AANzB,MAQGlC,QAAQ,GAAG,IAAH,GAAUD,QAAQ,CAACkC,MAAT,CAAgBC,OARrC,CADD,EAWG/B,WAAW,IACZ,4BAAC,gCAAD;AACC,IAAA,UAAU,EAAG,MAAMC,cAAc,CAAE,KAAF,CADlC;AAEC,IAAA,QAAQ,EAAGM;AAFZ,IAZF,CADD;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport CreateTemplatePartModal from '../create-template-part-modal';\nimport {\n\tuseExistingTemplateParts,\n\tgetUniqueTemplatePartTitle,\n\tgetCleanTemplatePartSlug,\n} from '../../utils/template-part-create';\nimport { unlock } from '../../private-apis';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport default function NewTemplatePart( {\n\tpostType,\n\tshowIcon = true,\n\ttoggleProps,\n} ) {\n\tconst history = useHistory();\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tasync function createTemplatePart( { title, area } ) {\n\t\tif ( ! title ) {\n\t\t\tcreateErrorNotice( __( 'Title is not defined.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: '',\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tsetIsModalOpen( false );\n\n\t\t\t// Navigate to the created template part editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: templatePart.id,\n\t\t\t\tpostType: 'wp_template_part',\n\t\t\t\tcanvas: 'edit',\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tsetIsModalOpen( false );\n\t\t}\n\t}\n\tconst { as: Toggle = Button, ...restToggleProps } = toggleProps ?? {};\n\n\treturn (\n\t\t<>\n\t\t\t<Toggle\n\t\t\t\t{ ...restToggleProps }\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsModalOpen( true );\n\t\t\t\t} }\n\t\t\t\ticon={ showIcon ? plus : null }\n\t\t\t\tlabel={ postType.labels.add_new }\n\t\t\t>\n\t\t\t\t{ showIcon ? null : postType.labels.add_new }\n\t\t\t</Toggle>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreateTemplatePartModal\n\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\tonCreate={ createTemplatePart }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -15,6 +15,8 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
15
15
|
|
|
16
16
|
var _components = require("@wordpress/components");
|
|
17
17
|
|
|
18
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
19
|
+
|
|
18
20
|
var _data = require("@wordpress/data");
|
|
19
21
|
|
|
20
22
|
var _coreData = require("@wordpress/core-data");
|
|
@@ -55,12 +57,11 @@ const {
|
|
|
55
57
|
} = (0, _privateApis.unlock)(_router.privateApis);
|
|
56
58
|
const DEFAULT_TEMPLATE_SLUGS = ['front-page', 'home', 'single', 'page', 'index', 'archive', 'author', 'category', 'date', 'tag', 'taxonomy', 'search', '404'];
|
|
57
59
|
|
|
58
|
-
function TemplateListItem(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
} = _ref;
|
|
60
|
+
function TemplateListItem({
|
|
61
|
+
title,
|
|
62
|
+
description,
|
|
63
|
+
onClick
|
|
64
|
+
}) {
|
|
64
65
|
return (0, _element.createElement)(_components.Button, {
|
|
65
66
|
onClick: onClick
|
|
66
67
|
}, (0, _element.createElement)(_components.__experimentalVStack, {
|
|
@@ -86,12 +87,11 @@ const modalContentMap = {
|
|
|
86
87
|
customGenericTemplate: 3
|
|
87
88
|
};
|
|
88
89
|
|
|
89
|
-
function NewTemplate(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
} = _ref2;
|
|
90
|
+
function NewTemplate({
|
|
91
|
+
postType,
|
|
92
|
+
toggleProps,
|
|
93
|
+
showIcon = true
|
|
94
|
+
}) {
|
|
95
95
|
const [showModal, setShowModal] = (0, _element.useState)(false);
|
|
96
96
|
const [modalContent, setModalContent] = (0, _element.useState)(modalContentMap.templatesList);
|
|
97
97
|
const [entityForSuggestions, setEntityForSuggestions] = (0, _element.useState)({});
|
|
@@ -108,9 +108,7 @@ function NewTemplate(_ref2) {
|
|
|
108
108
|
setTemplate
|
|
109
109
|
} = (0, _privateApis.unlock)((0, _data.useDispatch)(_store.store));
|
|
110
110
|
|
|
111
|
-
async function createTemplate(template) {
|
|
112
|
-
let isWPSuggestion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
113
|
-
|
|
111
|
+
async function createTemplate(template, isWPSuggestion = true) {
|
|
114
112
|
if (isCreatingTemplate) {
|
|
115
113
|
return;
|
|
116
114
|
}
|
|
@@ -118,8 +116,6 @@ function NewTemplate(_ref2) {
|
|
|
118
116
|
setIsCreatingTemplate(true);
|
|
119
117
|
|
|
120
118
|
try {
|
|
121
|
-
var _newTemplate$title;
|
|
122
|
-
|
|
123
119
|
const {
|
|
124
120
|
title,
|
|
125
121
|
description,
|
|
@@ -145,7 +141,7 @@ function NewTemplate(_ref2) {
|
|
|
145
141
|
canvas: 'edit'
|
|
146
142
|
});
|
|
147
143
|
createSuccessNotice((0, _i18n.sprintf)( // translators: %s: Title of the created template e.g: "Category".
|
|
148
|
-
(0, _i18n.__)('"%s" successfully created.'), ((
|
|
144
|
+
(0, _i18n.__)('"%s" successfully created.'), (0, _htmlEntities.decodeEntities)(newTemplate.title?.rendered || title)), {
|
|
149
145
|
type: 'snackbar'
|
|
150
146
|
});
|
|
151
147
|
} catch (error) {
|
|
@@ -229,16 +225,13 @@ function NewTemplate(_ref2) {
|
|
|
229
225
|
function useMissingTemplates(setEntityForSuggestions, onClick) {
|
|
230
226
|
const existingTemplates = (0, _utils.useExistingTemplates)();
|
|
231
227
|
const defaultTemplateTypes = (0, _utils.useDefaultTemplateTypes)();
|
|
232
|
-
const existingTemplateSlugs = (existingTemplates || []).map(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
} = _ref3;
|
|
236
|
-
return slug;
|
|
237
|
-
});
|
|
228
|
+
const existingTemplateSlugs = (existingTemplates || []).map(({
|
|
229
|
+
slug
|
|
230
|
+
}) => slug);
|
|
238
231
|
const missingDefaultTemplates = (defaultTemplateTypes || []).filter(template => DEFAULT_TEMPLATE_SLUGS.includes(template.slug) && !existingTemplateSlugs.includes(template.slug));
|
|
239
232
|
|
|
240
233
|
const onClickMenuItem = _entityForSuggestions => {
|
|
241
|
-
onClick
|
|
234
|
+
onClick?.();
|
|
242
235
|
setEntityForSuggestions(_entityForSuggestions);
|
|
243
236
|
}; // We need to replace existing default template types with
|
|
244
237
|
// the create specific template functionality. The original
|
|
@@ -274,7 +267,7 @@ function useMissingTemplates(setEntityForSuggestions, onClick) {
|
|
|
274
267
|
}
|
|
275
268
|
}); // Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.
|
|
276
269
|
|
|
277
|
-
enhancedMissingDefaultTemplateTypes
|
|
270
|
+
enhancedMissingDefaultTemplateTypes?.sort((template1, template2) => {
|
|
278
271
|
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
279
272
|
});
|
|
280
273
|
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...(0, _utils.usePostTypeArchiveMenuItems)(), ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["useHistory","routerPrivateApis","DEFAULT_TEMPLATE_SLUGS","TemplateListItem","title","description","onClick","width","modalContentMap","templatesList","customTemplate","customGenericTemplate","NewTemplate","postType","toggleProps","showIcon","showModal","setShowModal","modalContent","setModalContent","entityForSuggestions","setEntityForSuggestions","isCreatingTemplate","setIsCreatingTemplate","history","saveEntityRecord","coreStore","createErrorNotice","createSuccessNotice","noticesStore","setTemplate","editSiteStore","createTemplate","template","isWPSuggestion","slug","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","canvas","rendered","error","errorMessage","message","code","onModalClose","missingTemplates","useMissingTemplates","length","as","Toggle","Button","restToggleProps","modalTitle","labels","singular_name","plus","add_new_item","undefined","map","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;;;;;;;;AAeA;;;;AAZA;;AAKA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AAtCA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;AAeA,MAAM;AAAEA,EAAAA;AAAF,IAAiB,yBAAQC,mBAAR,CAAvB;AAEA,MAAMC,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,MAF8B,EAG9B,QAH8B,EAI9B,MAJ8B,EAK9B,OAL8B,EAM9B,SAN8B,EAO9B,QAP8B,E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CAA5C;AACA,QAAM;AAAEM,IAAAA,0BAAF;AAA8BC,IAAAA;AAA9B,MACL,mCAAwBJ,eAAxB,CADD;AAEA,QAAM;AAAEK,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACL,iCAAsBN,eAAtB,CADD;AAGA,QAAMO,cAAc,GAAG,8BAAmBP,eAAnB,CAAvB;AACA,GACC,GAAGG,0BADJ,EAEC,GAAGE,yBAFJ,EAGCE,cAHD,EAIEC,OAJF,CAIaC,QAAF,IAAgB;AAC1B,QAAK,CAAEA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGR,mCAAmC,CAACS,SAApC,CAChBlD,QAAF,IAAgBA,QAAQ,CAACE,IAAT,KAAkB8C,QAAQ,CAAC9C,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAK+C,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAChC,IAApC,CAA0CuC,QAA1C;AACA;AACD,GArBD,EA1BgE,CAgDhE;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACCpF,sBAAsB,CAACqF,OAAvB,CAAgCF,SAAS,CAAClD,IAA1C,IACAjC,sBAAsB,CAACqF,OAAvB,CAAgCD,SAAS,CAACnD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMiB,gBAAgB,GAAG,CACxB,GAAGsB,mCADqB,EAExB,GAAG,yCAFqB,EAGxB,GAAGI,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOxB,gBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalGrid as Grid,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModalContent from './add-custom-template-modal-content';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModalContent from './add-custom-generic-template-modal-content';\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../private-apis';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'home',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nfunction TemplateListItem( { title, description, onClick } ) {\n\treturn (\n\t\t<Button onClick={ onClick }>\n\t\t\t<VStack\n\t\t\t\tas=\"span\"\n\t\t\t\tspacing={ 2 }\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t>\n\t\t\t\t<Text\n\t\t\t\t\tweight={ 500 }\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</Text>\n\t\t\t\t<Text\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t>\n\t\t\t\t\t{ description }\n\t\t\t\t</Text>\n\t\t\t</VStack>\n\t\t</Button>\n\t);\n}\n\nconst modalContentMap = {\n\ttemplatesList: 1,\n\tcustomTemplate: 2,\n\tcustomGenericTemplate: 3,\n};\n\nexport default function NewTemplate( {\n\tpostType,\n\ttoggleProps,\n\tshowIcon = true,\n} ) {\n\tconst [ showModal, setShowModal ] = useState( false );\n\tconst [ modalContent, setModalContent ] = useState(\n\t\tmodalContentMap.templatesList\n\t);\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isCreatingTemplate, setIsCreatingTemplate ] = useState( false );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate } = unlock( useDispatch( editSiteStore ) );\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isCreatingTemplate ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsCreatingTemplate( true );\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t\tcanvas: 'edit',\n\t\t\t} );\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\tnewTemplate.title?.rendered || title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsCreatingTemplate( false );\n\t\t}\n\t}\n\tconst onModalClose = () => {\n\t\tsetShowModal( false );\n\t\tsetModalContent( modalContentMap.templatesList );\n\t};\n\n\tconst missingTemplates = useMissingTemplates( setEntityForSuggestions, () =>\n\t\tsetModalContent( modalContentMap.customTemplate )\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\tconst { as: Toggle = Button, ...restToggleProps } = toggleProps ?? {};\n\n\tlet modalTitle = __( 'Add template' );\n\tif ( modalContent === modalContentMap.customTemplate ) {\n\t\tmodalTitle = sprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Add template: %s' ),\n\t\t\tentityForSuggestions.labels.singular_name\n\t\t);\n\t} else if ( modalContent === modalContentMap.customGenericTemplate ) {\n\t\tmodalTitle = __( 'Create custom template' );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ isCreatingTemplate && <TemplateActionsLoadingScreen /> }\n\t\t\t<Toggle\n\t\t\t\t{ ...restToggleProps }\n\t\t\t\tonClick={ () => setShowModal( true ) }\n\t\t\t\ticon={ showIcon ? plus : null }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t>\n\t\t\t\t{ showIcon ? null : postType.labels.add_new_item }\n\t\t\t</Toggle>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ modalTitle }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-add-new-template__modal',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'edit-site-add-new-template__modal_template_list':\n\t\t\t\t\t\t\t\tmodalContent === modalContentMap.templatesList,\n\t\t\t\t\t\t\t'edit-site-custom-template-modal':\n\t\t\t\t\t\t\t\tmodalContent === modalContentMap.customTemplate,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\tonRequestClose={ onModalClose }\n\t\t\t\t\toverlayClassName={\n\t\t\t\t\t\tmodalContent === modalContentMap.customGenericTemplate\n\t\t\t\t\t\t\t? 'edit-site-custom-generic-template__modal'\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ modalContent === modalContentMap.templatesList && (\n\t\t\t\t\t\t<Grid\n\t\t\t\t\t\t\tcolumns={ 3 }\n\t\t\t\t\t\t\tgap={ 4 }\n\t\t\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\t\t\tjustify=\"center\"\n\t\t\t\t\t\t\tclassName=\"edit-site-add-new-template__template-list__contents\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst { title, description, slug, onClick } =\n\t\t\t\t\t\t\t\t\ttemplate;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\t\t\t\t\tdescription={ description }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t}\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<TemplateListItem\n\t\t\t\t\t\t\t\ttitle={ __( 'Custom template' ) }\n\t\t\t\t\t\t\t\tdescription={ __(\n\t\t\t\t\t\t\t\t\t'A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetModalContent(\n\t\t\t\t\t\t\t\t\t\tmodalContentMap.customGenericTemplate\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</Grid>\n\t\t\t\t\t) }\n\t\t\t\t\t{ modalContent === modalContentMap.customTemplate && (\n\t\t\t\t\t\t<AddCustomTemplateModalContent\n\t\t\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ modalContent ===\n\t\t\t\t\t\tmodalContentMap.customGenericTemplate && (\n\t\t\t\t\t\t<AddCustomGenericTemplateModalContent\n\t\t\t\t\t\t\tonClose={ onModalClose }\n\t\t\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates( setEntityForSuggestions, onClick ) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tonClick?.();\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["useHistory","routerPrivateApis","DEFAULT_TEMPLATE_SLUGS","TemplateListItem","title","description","onClick","width","modalContentMap","templatesList","customTemplate","customGenericTemplate","NewTemplate","postType","toggleProps","showIcon","showModal","setShowModal","modalContent","setModalContent","entityForSuggestions","setEntityForSuggestions","isCreatingTemplate","setIsCreatingTemplate","history","saveEntityRecord","coreStore","createErrorNotice","createSuccessNotice","noticesStore","setTemplate","editSiteStore","createTemplate","template","isWPSuggestion","slug","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","canvas","rendered","error","errorMessage","message","code","onModalClose","missingTemplates","useMissingTemplates","length","as","Toggle","Button","restToggleProps","modalTitle","labels","singular_name","plus","add_new_item","undefined","map","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;;;;;;;;AAgBA;;;;AAbA;;AAKA;;AAOA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AAvCA;AACA;AACA;;AAGA;AACA;AACA;;AAiBA;AACA;AACA;AAeA,MAAM;AAAEA,EAAAA;AAAF,IAAiB,yBAAQC,mBAAR,CAAvB;AAEA,MAAMC,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,MAF8B,EAG9B,QAH8B,EAI9B,MAJ8B,EAK9B,OAL8B,EAM9B,SAN8B,EAO9B,QAP8B,EAQ9B,UAR8B,EAS9B,MAT8B,EAU9B,KAV8B,EAW9B,UAX8B,EAY9B,QAZ8B,EAa9B,KAb8B,CAA/B;;AAgBA,SAASC,gBAAT,CAA2B;AAAEC,EAAAA,KAAF;AAASC,EAAAA,WAAT;AAAsBC,EAAAA;AAAtB,CAA3B,EAA6D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,OAJF,CAIaC,QAAF,IAAgB;AAC1B,QAAK,CAAEA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGR,mCAAmC,CAACS,SAApC,CAChBlD,QAAF,IAAgBA,QAAQ,CAACE,IAAT,KAAkB8C,QAAQ,CAAC9C,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAK+C,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAChC,IAApC,CAA0CuC,QAA1C;AACA;AACD,GArBD,EA1BgE,CAgDhE;;AACAP,EAAAA,mCAAmC,EAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACCpF,sBAAsB,CAACqF,OAAvB,CAAgCF,SAAS,CAAClD,IAA1C,IACAjC,sBAAsB,CAACqF,OAAvB,CAAgCD,SAAS,CAACnD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMiB,gBAAgB,GAAG,CACxB,GAAGsB,mCADqB,EAExB,GAAG,yCAFqB,EAGxB,GAAGI,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOxB,gBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalGrid as Grid,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModalContent from './add-custom-template-modal-content';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModalContent from './add-custom-generic-template-modal-content';\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../private-apis';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'home',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nfunction TemplateListItem( { title, description, onClick } ) {\n\treturn (\n\t\t<Button onClick={ onClick }>\n\t\t\t<VStack\n\t\t\t\tas=\"span\"\n\t\t\t\tspacing={ 2 }\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t>\n\t\t\t\t<Text\n\t\t\t\t\tweight={ 500 }\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</Text>\n\t\t\t\t<Text\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t>\n\t\t\t\t\t{ description }\n\t\t\t\t</Text>\n\t\t\t</VStack>\n\t\t</Button>\n\t);\n}\n\nconst modalContentMap = {\n\ttemplatesList: 1,\n\tcustomTemplate: 2,\n\tcustomGenericTemplate: 3,\n};\n\nexport default function NewTemplate( {\n\tpostType,\n\ttoggleProps,\n\tshowIcon = true,\n} ) {\n\tconst [ showModal, setShowModal ] = useState( false );\n\tconst [ modalContent, setModalContent ] = useState(\n\t\tmodalContentMap.templatesList\n\t);\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isCreatingTemplate, setIsCreatingTemplate ] = useState( false );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate } = unlock( useDispatch( editSiteStore ) );\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isCreatingTemplate ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsCreatingTemplate( true );\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t\tcanvas: 'edit',\n\t\t\t} );\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\tdecodeEntities( newTemplate.title?.rendered || title )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsCreatingTemplate( false );\n\t\t}\n\t}\n\tconst onModalClose = () => {\n\t\tsetShowModal( false );\n\t\tsetModalContent( modalContentMap.templatesList );\n\t};\n\n\tconst missingTemplates = useMissingTemplates( setEntityForSuggestions, () =>\n\t\tsetModalContent( modalContentMap.customTemplate )\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\tconst { as: Toggle = Button, ...restToggleProps } = toggleProps ?? {};\n\n\tlet modalTitle = __( 'Add template' );\n\tif ( modalContent === modalContentMap.customTemplate ) {\n\t\tmodalTitle = sprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Add template: %s' ),\n\t\t\tentityForSuggestions.labels.singular_name\n\t\t);\n\t} else if ( modalContent === modalContentMap.customGenericTemplate ) {\n\t\tmodalTitle = __( 'Create custom template' );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ isCreatingTemplate && <TemplateActionsLoadingScreen /> }\n\t\t\t<Toggle\n\t\t\t\t{ ...restToggleProps }\n\t\t\t\tonClick={ () => setShowModal( true ) }\n\t\t\t\ticon={ showIcon ? plus : null }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t>\n\t\t\t\t{ showIcon ? null : postType.labels.add_new_item }\n\t\t\t</Toggle>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ modalTitle }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-add-new-template__modal',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'edit-site-add-new-template__modal_template_list':\n\t\t\t\t\t\t\t\tmodalContent === modalContentMap.templatesList,\n\t\t\t\t\t\t\t'edit-site-custom-template-modal':\n\t\t\t\t\t\t\t\tmodalContent === modalContentMap.customTemplate,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\tonRequestClose={ onModalClose }\n\t\t\t\t\toverlayClassName={\n\t\t\t\t\t\tmodalContent === modalContentMap.customGenericTemplate\n\t\t\t\t\t\t\t? 'edit-site-custom-generic-template__modal'\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ modalContent === modalContentMap.templatesList && (\n\t\t\t\t\t\t<Grid\n\t\t\t\t\t\t\tcolumns={ 3 }\n\t\t\t\t\t\t\tgap={ 4 }\n\t\t\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\t\t\tjustify=\"center\"\n\t\t\t\t\t\t\tclassName=\"edit-site-add-new-template__template-list__contents\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst { title, description, slug, onClick } =\n\t\t\t\t\t\t\t\t\ttemplate;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\t\t\t\t\tdescription={ description }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t}\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<TemplateListItem\n\t\t\t\t\t\t\t\ttitle={ __( 'Custom template' ) }\n\t\t\t\t\t\t\t\tdescription={ __(\n\t\t\t\t\t\t\t\t\t'A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetModalContent(\n\t\t\t\t\t\t\t\t\t\tmodalContentMap.customGenericTemplate\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</Grid>\n\t\t\t\t\t) }\n\t\t\t\t\t{ modalContent === modalContentMap.customTemplate && (\n\t\t\t\t\t\t<AddCustomTemplateModalContent\n\t\t\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ modalContent ===\n\t\t\t\t\t\tmodalContentMap.customGenericTemplate && (\n\t\t\t\t\t\t<AddCustomGenericTemplateModalContent\n\t\t\t\t\t\t\tonClose={ onModalClose }\n\t\t\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates( setEntityForSuggestions, onClick ) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tonClick?.();\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|