Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Move the Excerpt panel to the editor package #57096

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { store as interfaceStore } from '@wordpress/interface';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import {
store as editorStore,
PostExcerptPanel,
PostFeaturedImagePanel,
PostLastRevisionPanel,
PostTaxonomiesPanel,
Expand All @@ -23,7 +24,6 @@ import {
*/
import SettingsHeader from '../settings-header';
import PostStatus from '../post-status';
import PostExcerpt from '../post-excerpt';
import DiscussionPanel from '../discussion-panel';
import PageAttributes from '../page-attributes';
import MetaBoxes from '../../meta-boxes';
Expand Down Expand Up @@ -84,7 +84,7 @@ const SidebarContent = ( {
<PostLastRevisionPanel />
<PostTaxonomiesPanel />
<PostFeaturedImagePanel />
<PostExcerpt />
<PostExcerptPanel />
<DiscussionPanel />
<PageAttributes />
<MetaBoxes location="side" />
Expand Down
11 changes: 9 additions & 2 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
registerLegacyWidgetBlock,
registerWidgetGroupBlock,
} from '@wordpress/widgets';
import { store as editorStore } from '@wordpress/editor';
import {
privateApis as editorPrivateApis,
store as editorStore,
} from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -24,6 +27,10 @@ import './hooks';
import './plugins';
import Editor from './editor';
import { store as editPostStore } from './store';
import { unlock } from './lock-unlock';

const { PluginPostExcerpt: __experimentalPluginPostExcerpt } =
unlock( editorPrivateApis );

/**
* Initializes and returns an instance of Editor.
Expand Down Expand Up @@ -208,5 +215,5 @@ export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';
export { default as __experimentalFullscreenModeClose } from './components/header/fullscreen-mode-close';
export { default as __experimentalMainDashboardButton } from './components/header/main-dashboard-button';
export { default as __experimentalPluginPostExcerpt } from './components/sidebar/plugin-post-excerpt';
export { __experimentalPluginPostExcerpt };
export { store } from './store';
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import {
PostExcerptPanel,
PostFeaturedImagePanel,
PostLastRevisionPanel,
PostTaxonomiesPanel,
Expand Down Expand Up @@ -102,6 +103,7 @@ export default function PagePanels() {
<PostLastRevisionPanel />
<PostTaxonomiesPanel />
<PostFeaturedImagePanel />
<PostExcerptPanel />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useSelect } from '@wordpress/data';
import { PanelBody } from '@wordpress/components';
import {
PostExcerptPanel,
PostFeaturedImagePanel,
PostLastRevisionPanel,
PostTaxonomiesPanel,
Expand Down Expand Up @@ -66,6 +67,7 @@ export default function TemplatePanel() {
<PostLastRevisionPanel />
<PostTaxonomiesPanel />
<PostFeaturedImagePanel />
<PostExcerptPanel />
</>
);
}
1 change: 1 addition & 0 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export { default as PostAuthorPanel } from './post-author/panel';
export { default as PostComments } from './post-comments';
export { default as PostExcerpt } from './post-excerpt';
export { default as PostExcerptCheck } from './post-excerpt/check';
export { default as PostExcerptPanel } from './post-excerpt/panel';
export { default as PostFeaturedImage } from './post-featured-image';
export { default as PostFeaturedImageCheck } from './post-featured-image/check';
export { default as PostFeaturedImagePanel } from './post-featured-image/panel';
Expand Down
18 changes: 18 additions & 0 deletions packages/editor/src/components/post-excerpt/check.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import PostTypeSupportCheck from '../post-type-support-check';
import { store as editorStore } from '../../store';

function PostExcerptCheck( { children } ) {
const postType = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
return getEditedPostAttribute( 'type' );
}, [] );

// This special case is unfortunate, but the REST API of wp_template and wp_template_part
// support the excerpt field throught the "description" field rather than "excerpt" which means
// the default ExcerptPanel won't work for these.
if ( [ 'wp_template', 'wp_template_part' ].includes( postType ) ) {
return null;
}

return (
<PostTypeSupportCheck supportKeys="excerpt">
{ children }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@
*/
import { __ } from '@wordpress/i18n';
import { PanelBody } from '@wordpress/components';
import {
PostExcerpt as PostExcerptForm,
PostExcerptCheck,
store as editorStore,
} from '@wordpress/editor';
import { useDispatch, useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import PluginPostExcerpt from '../plugin-post-excerpt';
import PostExcerptForm from './index';
import PostExcerptCheck from './check';
import PluginPostExcerpt from './plugin';
import { store as editorStore } from '../../store';

/**
* Module Constants
*/
const PANEL_NAME = 'post-excerpt';

export default function PostExcerpt() {
export default function PostExcerptPanel() {
const { isOpened, isEnabled } = useSelect( ( select ) => {
const { isEditorPanelOpened, isEditorPanelEnabled } =
select( editorStore );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SlotFillProvider } from '@wordpress/components';
/**
* Internal dependencies
*/
import PluginPostExcerptPanel from '../';
import PluginPostExcerptPanel from '../plugin';

describe( 'PluginPostExcerptPanel', () => {
test( 'renders fill properly', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EntitiesSavedStatesExtensible } from './components/entities-saved-state
import useBlockEditorSettings from './components/provider/use-block-editor-settings';
import PostPanelRow from './components/post-panel-row';
import PreviewDropdown from './components/preview-dropdown';
import PluginPostExcerpt from './components/post-excerpt/plugin';

export const privateApis = {};
lock( privateApis, {
Expand All @@ -16,6 +17,7 @@ lock( privateApis, {
EntitiesSavedStatesExtensible,
PostPanelRow,
PreviewDropdown,
PluginPostExcerpt,

// This is a temporary private API while we're updating the site editor to use EditorProvider.
useBlockEditorSettings,
Expand Down
Loading