Skip to content

Commit

Permalink
Editor: Unify PluginSidebarMoreMenuItem (#60853)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent db48edb commit 8923a83
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is done by setting the `target` on `<PluginSidebarMoreMenuItem>` to match t

```js
import { registerPlugin } from '@wordpress/plugins';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
import { image } from '@wordpress/icons';

const PluginSidebarMoreMenuItemTest = () => (
Expand Down
10 changes: 5 additions & 5 deletions packages/e2e-tests/plugins/plugins-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function enqueue_plugins_api_plugin_scripts() {
'gutenberg-test-plugins-api-post-status-info',
plugins_url( 'plugins-api/post-status-info.js', __FILE__ ),
array(
'wp-edit-post',
'wp-editor',
'wp-element',
'wp-i18n',
'wp-plugins',
Expand All @@ -28,7 +28,7 @@ function enqueue_plugins_api_plugin_scripts() {
'gutenberg-test-plugins-api-publish-pane;',
plugins_url( 'plugins-api/publish-panel.js', __FILE__ ),
array(
'wp-edit-post',
'wp-editor',
'wp-element',
'wp-i18n',
'wp-plugins',
Expand All @@ -44,7 +44,7 @@ function enqueue_plugins_api_plugin_scripts() {
'wp-components',
'wp-compose',
'wp-data',
'wp-edit-post',
'wp-editor',
'wp-block-editor',
'wp-editor',
'wp-element',
Expand All @@ -63,7 +63,7 @@ function enqueue_plugins_api_plugin_scripts() {
'wp-components',
'wp-compose',
'wp-data',
'wp-edit-post',
'wp-editor',
'wp-block-editor',
'wp-element',
'wp-i18n',
Expand All @@ -78,7 +78,7 @@ function enqueue_plugins_api_plugin_scripts() {
'gutenberg-test-plugins-api-document-setting',
plugins_url( 'plugins-api/document-setting.js', __FILE__ ),
array(
'wp-edit-post',
'wp-editor',
'wp-element',
'wp-i18n',
'wp-plugins',
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/plugins/plugins-api/annotations-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
const Component = wp.element.Component;
const __ = wp.i18n.__;
const registerPlugin = wp.plugins.registerPlugin;
const PluginSidebar = wp.editPost.PluginSidebar;
const PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
const PluginSidebar = wp.editor.PluginSidebar;
const PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;

class SidebarContents extends Component {
constructor( props ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/plugins/plugins-api/document-setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const el = wp.element.createElement;
const __ = wp.i18n.__;
const registerPlugin = wp.plugins.registerPlugin;
const PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel;
const PluginDocumentSettingPanel = wp.editor.PluginDocumentSettingPanel;

function MyDocumentSettingPlugin() {
return el(
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/plugins/plugins-api/post-status-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const el = wp.element.createElement;
const __ = wp.i18n.__;
const registerPlugin = wp.plugins.registerPlugin;
const PluginPostStatusInfo = wp.editPost.PluginPostStatusInfo;
const PluginPostStatusInfo = wp.editor.PluginPostStatusInfo;

function MyPostStatusInfoPlugin() {
return el(
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/plugins/plugins-api/publish-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const Fragment = wp.element.Fragment;
const __ = wp.i18n.__;
const registerPlugin = wp.plugins.registerPlugin;
const PluginPostPublishPanel = wp.editPost.PluginPostPublishPanel;
const PluginPrePublishPanel = wp.editPost.PluginPrePublishPanel;
const PluginPostPublishPanel = wp.editor.PluginPostPublishPanel;
const PluginPrePublishPanel = wp.editor.PluginPrePublishPanel;

function PanelContent() {
return el( 'p', {}, __( 'Here is the panel content!' ) );
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/plugins/plugins-api/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
const el = wp.element.createElement;
const __ = wp.i18n.__;
const registerPlugin = wp.plugins.registerPlugin;
const PluginSidebar = wp.editPost.PluginSidebar;
const PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
const PluginSidebar = wp.editor.PluginSidebar;
const PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;

function SidebarContents() {
const postTitle = useSelect( ( select ) =>
Expand Down
45 changes: 1 addition & 44 deletions packages/edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,50 +99,7 @@ Undocumented declaration.

### PluginSidebarMoreMenuItem

Renders a menu item in `Plugins` group in `More Menu` drop down, and can be used to activate the corresponding `PluginSidebar` component. The text within the component appears as the menu item label.

_Usage_

```js
// Using ES5 syntax
var __ = wp.i18n.__;
var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
var moreIcon = React.createElement( 'svg' ); //... svg element.

function MySidebarMoreMenuItem() {
return React.createElement(
PluginSidebarMoreMenuItem,
{
target: 'my-sidebar',
icon: moreIcon,
},
__( 'My sidebar title' )
);
}
```

```jsx
// Using ESNext syntax
import { __ } from '@wordpress/i18n';
import { PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
import { more } from '@wordpress/icons';

const MySidebarMoreMenuItem = () => (
<PluginSidebarMoreMenuItem target="my-sidebar" icon={ more }>
{ __( 'My sidebar title' ) }
</PluginSidebarMoreMenuItem>
);
```

_Parameters_

- _props_ `Object`: Component props.
- _props.target_ `string`: A string identifying the target sidebar you wish to be activated by this menu item. Must be the same as the `name` prop you have given to that sidebar.
- _props.icon_ `[WPBlockTypeIconRender]`: The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered to the left of the menu item label.

_Returns_

- `Component`: The component to be rendered.
Undocumented declaration.

### reinitializeEditor

Expand Down
3 changes: 2 additions & 1 deletion packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
PluginMoreMenuItem,
PluginPostStatusInfo,
PluginSidebar,
PluginSidebarMoreMenuItem,
privateApis as editorPrivateApis,
store as editorStore,
} from '@wordpress/editor';
Expand Down Expand Up @@ -170,9 +171,9 @@ export { PluginDocumentSettingPanel };
export { PluginMoreMenuItem };
export { PluginPostStatusInfo };
export { PluginSidebar };
export { PluginSidebarMoreMenuItem };
export { default as PluginPostPublishPanel } from './components/sidebar/plugin-post-publish-panel';
export { default as PluginPrePublishPanel } from './components/sidebar/plugin-pre-publish-panel';
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 { __experimentalPluginPostExcerpt };
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createRoot } from '@wordpress/element';
import {
PluginMoreMenuItem,
PluginSidebar,
PluginSidebarMoreMenuItem,
store as editorStore,
} from '@wordpress/editor';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -103,6 +104,6 @@ export function reinitializeEditor() {

export { PluginMoreMenuItem };
export { PluginSidebar };
export { default as PluginSidebarMoreMenuItem } from './components/header-edit-mode/plugin-sidebar-more-menu-item';
export { PluginSidebarMoreMenuItem };
export { default as PluginTemplateSettingPanel } from './components/plugin-template-setting-panel';
export { store } from './store';
47 changes: 47 additions & 0 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,53 @@ _Parameters_
- _props.isPinnable_ `[boolean]`: Whether to allow to pin sidebar to the toolbar. When set to `true` it also automatically renders a corresponding menu item.
- _props.icon_ `[WPBlockTypeIconRender]`: The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.

### PluginSidebarMoreMenuItem

Renders a menu item in `Plugins` group in `More Menu` drop down, and can be used to activate the corresponding `PluginSidebar` component. The text within the component appears as the menu item label.

_Usage_

```js
// Using ES5 syntax
var __ = wp.i18n.__;
var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
var moreIcon = React.createElement( 'svg' ); //... svg element.

function MySidebarMoreMenuItem() {
return React.createElement(
PluginSidebarMoreMenuItem,
{
target: 'my-sidebar',
icon: moreIcon,
},
__( 'My sidebar title' )
);
}
```

```jsx
// Using ESNext syntax
import { __ } from '@wordpress/i18n';
import { PluginSidebarMoreMenuItem } from '@wordpress/editor';
import { more } from '@wordpress/icons';

const MySidebarMoreMenuItem = () => (
<PluginSidebarMoreMenuItem target="my-sidebar" icon={ more }>
{ __( 'My sidebar title' ) }
</PluginSidebarMoreMenuItem>
);
```

_Parameters_

- _props_ `Object`: Component props.
- _props.target_ `string`: A string identifying the target sidebar you wish to be activated by this menu item. Must be the same as the `name` prop you have given to that sidebar.
- _props.icon_ `[WPBlockTypeIconRender]`: The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered to the left of the menu item label.

_Returns_

- `Component`: The component to be rendered.

### PostAuthor

Undocumented declaration.
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { default as PluginPostPublishPanel } from './plugin-post-publish-panel';
export { default as PluginPostStatusInfo } from './plugin-post-status-info';
export { default as PluginPrePublishPanel } from './plugin-pre-publish-panel';
export { default as PluginSidebar } from './plugin-sidebar';
export { default as PluginSidebarMoreMenuItem } from './plugin-sidebar-more-menu-item';
export { default as PostTemplatePanel } from './post-template/panel';
export { default as PostAuthor } from './post-author';
export { default as PostAuthorCheck } from './post-author/check';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
/**
* WordPress dependencies
*/
import { privateApis as editorPrivateApis } from '@wordpress/editor';

/**
* Internal dependencies
*/
import { unlock } from '../../../lock-unlock';

const { ComplementaryAreaMoreMenuItem } = unlock( editorPrivateApis );
import { ComplementaryAreaMoreMenuItem } from '@wordpress/interface';

/**
* Renders a menu item in `Plugins` group in `More Menu` drop down,
Expand All @@ -23,7 +16,7 @@ const { ComplementaryAreaMoreMenuItem } = unlock( editorPrivateApis );
* ```js
* // Using ES5 syntax
* var __ = wp.i18n.__;
* var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
* var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
* var moreIcon = React.createElement( 'svg' ); //... svg element.
*
* function MySidebarMoreMenuItem() {
Expand All @@ -42,7 +35,7 @@ const { ComplementaryAreaMoreMenuItem } = unlock( editorPrivateApis );
* ```jsx
* // Using ESNext syntax
* import { __ } from '@wordpress/i18n';
* import { PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
* import { PluginSidebarMoreMenuItem } from '@wordpress/editor';
* import { more } from '@wordpress/icons';
*
* const MySidebarMoreMenuItem = () => (
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ _Usage_
// Using ES5 syntax
var el = React.createElement;
var Fragment = wp.element.Fragment;
var PluginSidebar = wp.editPost.PluginSidebar;
var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
var PluginSidebar = wp.editor.PluginSidebar;
var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
var registerPlugin = wp.plugins.registerPlugin;
var moreIcon = React.createElement( 'svg' ); //... svg element.

Expand Down Expand Up @@ -123,7 +123,7 @@ registerPlugin( 'plugin-name', {

```js
// Using ESNext syntax
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
import { registerPlugin } from '@wordpress/plugins';
import { more } from '@wordpress/icons';

Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const plugins = {} as Record< string, WPPlugin >;
* // Using ES5 syntax
* var el = React.createElement;
* var Fragment = wp.element.Fragment;
* var PluginSidebar = wp.editPost.PluginSidebar;
* var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
* var PluginSidebar = wp.editor.PluginSidebar;
* var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
* var registerPlugin = wp.plugins.registerPlugin;
* var moreIcon = React.createElement( 'svg' ); //... svg element.
*
Expand Down Expand Up @@ -94,7 +94,7 @@ const plugins = {} as Record< string, WPPlugin >;
* @example
* ```js
* // Using ESNext syntax
* import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
* import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
* import { registerPlugin } from '@wordpress/plugins';
* import { more } from '@wordpress/icons';
*
Expand Down

0 comments on commit 8923a83

Please sign in to comment.