Skip to content

Commit 56291a6

Browse files
committed
Editor: Unify the PluginSidebar slot between post and site editors
1 parent 3a07928 commit 56291a6

File tree

16 files changed

+89
-173
lines changed

16 files changed

+89
-173
lines changed

docs/how-to-guides/plugin-sidebar-0.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ The tutorial assumes you have an existing plugin setup and are ready to add PHP
1616

1717
### Step 1: Get a sidebar up and running
1818

19-
The first step is to tell the editor that there is a new plugin that will have its own sidebar. Use the [registerPlugin](/packages/plugins/README.md), [PluginSidebar](/packages/edit-post/README.md#pluginsidebar), and [createElement](/packages/element/README.md) utilities provided by the `@wordpress/plugins`, `@wordpress/edit-post`, and `react` packages, respectively.
19+
The first step is to tell the editor that there is a new plugin that will have its own sidebar. Use the [registerPlugin](/packages/plugins/README.md), [PluginSidebar](/packages/editor/README.md#pluginsidebar), and [createElement](/packages/element/README.md) utilities provided by the `@wordpress/plugins`, `@wordpress/editor`, and `react` packages, respectively.
2020

2121
Add the following code to a JavaScript file called `plugin-sidebar.js` and save it within your plugin's directory:
2222

2323
```js
2424
( function ( wp, React ) {
2525
var el = React.createElement;
2626
var registerPlugin = wp.plugins.registerPlugin;
27-
var PluginSidebar = wp.editPost.PluginSidebar;
27+
var PluginSidebar = wp.editor.PluginSidebar;
2828

2929
registerPlugin( 'my-plugin-sidebar', {
3030
render: function () {
@@ -57,7 +57,7 @@ function sidebar_plugin_register() {
5757
wp_register_script(
5858
'plugin-sidebar-js',
5959
plugins_url( 'plugin-sidebar.js', __FILE__ ),
60-
array( 'wp-plugins', 'wp-edit-post', 'react' )
60+
array( 'wp-plugins', 'wp-editor', 'react' )
6161
);
6262
}
6363
add_action( 'init', 'sidebar_plugin_register' );
@@ -82,7 +82,7 @@ To visualize and edit the meta field value you'll use an input component. The `@
8282
( function ( wp ) {
8383
var el = React.createElement;
8484
var registerPlugin = wp.plugins.registerPlugin;
85-
var PluginSidebar = wp.editPost.PluginSidebar;
85+
var PluginSidebar = wp.editor.PluginSidebar;
8686
var TextControl = wp.components.TextControl;
8787

8888
registerPlugin( 'my-plugin-sidebar', {
@@ -144,7 +144,7 @@ function sidebar_plugin_register() {
144144
array(
145145
'react',
146146
'wp-plugins',
147-
'wp-edit-post',
147+
'wp-editor',
148148
'wp-components'
149149
)
150150
);
@@ -202,7 +202,7 @@ With the field available in the editor store, it can now be surfaced to the UI.
202202
( function ( wp ) {
203203
var el = React.createElement;
204204
var registerPlugin = wp.plugins.registerPlugin;
205-
var PluginSidebar = wp.editPost.PluginSidebar;
205+
var PluginSidebar = wp.editor.PluginSidebar;
206206
var TextControl = wp.components.TextControl;
207207

208208
var MetaBlockField = function () {
@@ -243,7 +243,7 @@ The `useSelect` function is used to fetch data when the component loads and will
243243
( function ( wp ) {
244244
var el = React.createElement;
245245
var registerPlugin = wp.plugins.registerPlugin;
246-
var PluginSidebar = wp.editPost.PluginSidebar;
246+
var PluginSidebar = wp.editor.PluginSidebar;
247247
var Text = wp.components.TextControl;
248248
var useSelect = wp.data.useSelect;
249249

@@ -306,7 +306,7 @@ The `useDispatch` function takes a store name as its only argument and returns m
306306
( function ( wp ) {
307307
var el = React.createElement;
308308
var registerPlugin = wp.plugins.registerPlugin;
309-
var PluginSidebar = wp.editPost.PluginSidebar;
309+
var PluginSidebar = wp.editor.PluginSidebar;
310310
var TextControl = wp.components.TextControl;
311311
var useSelect = wp.data.useSelect;
312312
var useDispatch = wp.data.useDispatch;

docs/reference-guides/slotfills/plugin-sidebar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Using this slot will add an icon to the bar that, when clicked, will open a side
77

88
```js
99
import { registerPlugin } from '@wordpress/plugins';
10-
import { PluginSidebar } from '@wordpress/edit-post';
10+
import { PluginSidebar } from '@wordpress/editor';
1111
import { image } from '@wordpress/icons';
1212

1313
const PluginSidebarTest = () => (

packages/compose/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const compose = ( f, g ) => x
1111
=> f( g( x ) );
1212
```
1313

14-
Here's a simplified example of **compose** in use from Gutenberg's [`PluginSidebar` component](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js):
14+
Here's a simplified example of **compose** in use from Gutenberg's [`PluginSidebar` component](https://github.com/WordPress/gutenberg/blob/HEAD/packages/editor/src/components/plugin-sidebar/index.js):
1515

1616
Using compose:
1717

packages/e2e-test-utils/src/find-sidebar-panel-toggle-button-with-title.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
export async function findSidebarPanelToggleButtonWithTitle( panelTitle ) {
1111
const buttons = await page.$x(
12-
`//div[contains(@class,"edit-post-sidebar")]//button[@class="components-button components-panel__body-toggle"][contains(text(),"${ panelTitle }")]`
12+
`//div[contains(@class,"editor-sidebar")]//button[@class="components-button components-panel__body-toggle"][contains(text(),"${ panelTitle }")]`
1313
);
1414
return buttons[ 0 ];
1515
}

packages/e2e-test-utils/src/find-sidebar-panel-with-title.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @return {Promise<ElementHandle|undefined>} Object that represents an in-page DOM element.
99
*/
1010
export async function findSidebarPanelWithTitle( panelTitle ) {
11-
const panelToggleSelector = `//div[contains(@class, "edit-post-sidebar")]//button[contains(@class, "components-panel__body-toggle") and contains(text(),"${ panelTitle }")]`;
11+
const panelToggleSelector = `//div[contains(@class, "editor-sidebar")]//button[contains(@class, "components-panel__body-toggle") and contains(text(),"${ panelTitle }")]`;
1212
const panelSelector = `${ panelToggleSelector }/ancestor::*[contains(concat(" ", @class, " "), " components-panel__body ")]`;
1313
return await page.waitForXPath( panelSelector );
1414
}

packages/e2e-test-utils/src/open-document-settings-sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export async function openDocumentSettingsSidebar() {
1313

1414
if ( isClosed ) {
1515
await toggleButton.click();
16-
await page.waitForSelector( '.edit-post-sidebar' );
16+
await page.waitForSelector( '.editor-sidebar' );
1717
}
1818
}

packages/edit-post/README.md

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -135,63 +135,7 @@ _Returns_
135135

136136
### PluginSidebar
137137

138-
Renders a sidebar when activated. The contents within the `PluginSidebar` will appear as content within the sidebar. It also automatically renders a corresponding `PluginSidebarMenuItem` component when `isPinnable` flag is set to `true`. If you wish to display the sidebar, you can with use the `PluginSidebarMoreMenuItem` component or the `wp.data.dispatch` API:
139-
140-
```js
141-
wp.data
142-
.dispatch( 'core/edit-post' )
143-
.openGeneralSidebar( 'plugin-name/sidebar-name' );
144-
```
145-
146-
_Related_
147-
148-
- PluginSidebarMoreMenuItem
149-
150-
_Usage_
151-
152-
```js
153-
// Using ES5 syntax
154-
var __ = wp.i18n.__;
155-
var el = React.createElement;
156-
var PanelBody = wp.components.PanelBody;
157-
var PluginSidebar = wp.editPost.PluginSidebar;
158-
var moreIcon = React.createElement( 'svg' ); //... svg element.
159-
160-
function MyPluginSidebar() {
161-
return el(
162-
PluginSidebar,
163-
{
164-
name: 'my-sidebar',
165-
title: 'My sidebar title',
166-
icon: moreIcon,
167-
},
168-
el( PanelBody, {}, __( 'My sidebar content' ) )
169-
);
170-
}
171-
```
172-
173-
```jsx
174-
// Using ESNext syntax
175-
import { __ } from '@wordpress/i18n';
176-
import { PanelBody } from '@wordpress/components';
177-
import { PluginSidebar } from '@wordpress/edit-post';
178-
import { more } from '@wordpress/icons';
179-
180-
const MyPluginSidebar = () => (
181-
<PluginSidebar name="my-sidebar" title="My sidebar title" icon={ more }>
182-
<PanelBody>{ __( 'My sidebar content' ) }</PanelBody>
183-
</PluginSidebar>
184-
);
185-
```
186-
187-
_Parameters_
188-
189-
- _props_ `Object`: Element props.
190-
- _props.name_ `string`: A string identifying the sidebar. Must be unique for every sidebar registered within the scope of your plugin.
191-
- _props.className_ `[string]`: An optional class name added to the sidebar body.
192-
- _props.title_ `string`: Title displayed at the top of the sidebar.
193-
- _props.isPinnable_ `[boolean]`: Whether to allow to pin sidebar to the toolbar. When set to `true` it also automatically renders a corresponding menu item.
194-
- _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.
138+
Undocumented declaration.
195139

196140
### PluginSidebarMoreMenuItem
197141

packages/edit-post/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
PluginBlockSettingsMenuItem,
1919
PluginDocumentSettingPanel,
2020
PluginMoreMenuItem,
21+
PluginSidebar,
2122
privateApis as editorPrivateApis,
2223
store as editorStore,
2324
} from '@wordpress/editor';
@@ -166,10 +167,10 @@ export function reinitializeEditor() {
166167
export { PluginBlockSettingsMenuItem };
167168
export { PluginDocumentSettingPanel };
168169
export { PluginMoreMenuItem };
170+
export { PluginSidebar };
169171
export { default as PluginPostPublishPanel } from './components/sidebar/plugin-post-publish-panel';
170172
export { default as PluginPostStatusInfo } from './components/sidebar/plugin-post-status-info';
171173
export { default as PluginPrePublishPanel } from './components/sidebar/plugin-pre-publish-panel';
172-
export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
173174
export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';
174175
export { default as __experimentalFullscreenModeClose } from './components/header/fullscreen-mode-close';
175176
export { default as __experimentalMainDashboardButton } from './components/header/main-dashboard-button';

packages/edit-post/src/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ body.js.block-editor-page {
4242
// Target the editor UI excluding the visual editor contents, metaboxes and custom fields areas.
4343
.edit-post-header,
4444
.edit-post-text-editor,
45-
.edit-post-sidebar,
45+
.editor-sidebar,
4646
.editor-post-publish-panel {
4747
@include reset;
4848
}

packages/edit-site/src/components/sidebar-edit-mode/plugin-sidebar/index.js

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)