diff --git a/packages/edit-site/CHANGELOG.md b/packages/edit-site/CHANGELOG.md index 5d5118e142e887..d5af36afa2c5d5 100644 --- a/packages/edit-site/CHANGELOG.md +++ b/packages/edit-site/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancements + +- Offer the Export tool only while editing a template or a template part, the entities the exported theme is made of. The menu item now lives in the editor package ([#81992](https://github.com/WordPress/gutenberg/pull/81992)). + ### Bug Fixes - Seed the root `ThemeProvider` with the admin color scheme primary color so portaled popovers and modals receive the scheme's accent colors ([#81653](https://github.com/WordPress/gutenberg/pull/81653)). diff --git a/packages/edit-site/src/components/more-menu/index.js b/packages/edit-site/src/components/more-menu/index.js index e0717a7a705a8c..9872146fd0b6a1 100644 --- a/packages/edit-site/src/components/more-menu/index.js +++ b/packages/edit-site/src/components/more-menu/index.js @@ -1,9 +1,9 @@ import { privateApis as editorPrivateApis } from '@wordpress/editor'; -import SiteExport from './site-export'; import WelcomeGuideMenuItem from './welcome-guide-menu-item'; import { unlock } from '../../lock-unlock'; -const { ToolsMoreMenuGroup, PreferencesModal } = unlock( editorPrivateApis ); +const { ToolsMoreMenuGroup, PreferencesModal, SiteExport } = + unlock( editorPrivateApis ); export default function MoreMenu() { return ( diff --git a/packages/editor/CHANGELOG.md b/packages/editor/CHANGELOG.md index f33c41a3b4ef5f..8771f992043d98 100644 --- a/packages/editor/CHANGELOG.md +++ b/packages/editor/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- Add a private `SiteExport` menu item, moved from `edit-site`. It offers downloading the theme with the user's changes, only while editing a template or a template part — the entities the exported theme is made of ([#81992](https://github.com/WordPress/gutenberg/pull/81992)). + ### Enhancements - Commands: Add a command palette entry that opens the current post on the front end once it is published, labelled with the post type's `view_item` label ([#66720](https://github.com/WordPress/gutenberg/pull/66720)). diff --git a/packages/edit-site/src/components/more-menu/site-export.js b/packages/editor/src/components/site-export/index.js similarity index 72% rename from packages/edit-site/src/components/more-menu/site-export.js rename to packages/editor/src/components/site-export/index.js index fee1a9d0631325..e6e1c778150b0c 100644 --- a/packages/edit-site/src/components/more-menu/site-export.js +++ b/packages/editor/src/components/site-export/index.js @@ -6,9 +6,33 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { downloadBlob } from '@wordpress/blob'; import { store as coreStore } from '@wordpress/core-data'; import { store as noticesStore } from '@wordpress/notices'; +import { store as editorStore } from '../../store'; +import { + TEMPLATE_POST_TYPE, + TEMPLATE_PART_POST_TYPE, +} from '../../store/constants'; +/** + * Menu item offering to download the active theme, with the user's template + * and style changes, as a zip. + * + * Offered only while editing one of the entities the exported theme is made + * of — a template or a template part — and only to users the export endpoint + * accepts. The host places it in a menu group. + * + * @return {React.ReactNode} The menu item, or nothing where export does not + * apply. + */ export default function SiteExport() { const canExport = useSelect( ( select ) => { + const postType = select( editorStore ).getCurrentPostType(); + if ( + postType !== TEMPLATE_POST_TYPE && + postType !== TEMPLATE_PART_POST_TYPE + ) { + return false; + } + const targetHints = select( coreStore ).getCurrentTheme()?._links?.[ 'wp:export-theme' diff --git a/packages/editor/src/private-apis.js b/packages/editor/src/private-apis.js index 17afc203ff480c..18549e77a46928 100644 --- a/packages/editor/src/private-apis.js +++ b/packages/editor/src/private-apis.js @@ -13,6 +13,7 @@ import PreferencesModal from './components/preferences-modal'; import { usePostActions } from './components/post-actions/actions'; import usePostFields from './components/post-fields'; import ToolsMoreMenuGroup from './components/more-menu/tools-more-menu-group'; +import SiteExport from './components/site-export'; import ViewMoreMenuGroup from './components/more-menu/view-more-menu-group'; import ResizableEditor from './components/resizable-editor'; import { registerCoreBlockBindingsSources } from './bindings/api'; @@ -37,6 +38,7 @@ lock( privateApis, { usePostActions, usePostFields, ToolsMoreMenuGroup, + SiteExport, ViewMoreMenuGroup, ResizableEditor, UploadProgressSnackbar, diff --git a/packages/lazy-editor/CHANGELOG.md b/packages/lazy-editor/CHANGELOG.md index 982c3cdf27336d..ffe79cd73c40fa 100644 --- a/packages/lazy-editor/CHANGELOG.md +++ b/packages/lazy-editor/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- Render the editor's Export tool, so a theme can be downloaded with the user's changes while editing a template or a template part ([#81992](https://github.com/WordPress/gutenberg/pull/81992)). + ### Bug Fixes - Add the styles a host passes to the theme's and the user's instead of replacing them, so an editor canvas keeps the CSS a theme registers with `add_editor_style` ([#81747](https://github.com/WordPress/gutenberg/pull/81747)). diff --git a/packages/lazy-editor/src/components/editor/index.tsx b/packages/lazy-editor/src/components/editor/index.tsx index 687a8b19f251ab..416f170e2d22b8 100644 --- a/packages/lazy-editor/src/components/editor/index.tsx +++ b/packages/lazy-editor/src/components/editor/index.tsx @@ -13,6 +13,8 @@ const { Editor: PrivateEditor, BackButton, PreferencesModal, + ToolsMoreMenuGroup, + SiteExport, } = unlock( editorPrivateApis ); interface EditorProps { @@ -139,6 +141,13 @@ export function Editor( { nothing until one of them opens it. */ } + { /* + Self-gated: renders only while editing a template or template + part, the entities the exported theme is made of. + */ } + + + ); }