Skip to content

Commit

Permalink
Decouple editor and edit-post
Browse files Browse the repository at this point in the history
editor exposes the _BlockSettingsMenuPluginsExtension component that
specific implementations can use. edit-post chooses to fill that slot
with a component of their own (PluginBlockSettingsMenuGroup) which
happens to be a slot as well. This way, third-party authors can hook
into the edit-post specific implementation by using the
PluginsBlockSettingsMenuItem fill.
  • Loading branch information
oandregal committed Jul 26, 2018
1 parent 398a9a8 commit 566a1b8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createSlotFill } from '@wordpress/components';
import { Fragment } from '@wordpress/element';
import { withSelect } from '@wordpress/data';

const { Fill: PluginBlockSettingsMenuGroup, Slot } = createSlotFill( 'BlockSettingsMenuPluginsGroup' );
const { Fill: PluginBlockSettingsMenuGroup, Slot } = createSlotFill( 'PluginBlockSettingsMenuGroup' );

const PluginBlockSettingsMenuGroupSlot = ( { fillProps, selectedBlocks } ) => {
selectedBlocks = map( selectedBlocks, ( block ) => block.name );
Expand Down
5 changes: 5 additions & 0 deletions edit-post/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
BlockSelectionClearer,
MultiSelectScrollIntoView,
_BlockSettingsMenuFirstItem,
_BlockSettingsMenuPluginsExtension,
} from '@wordpress/editor';

/**
* Internal dependencies
*/
import './style.scss';
import BlockInspectorButton from './block-inspector-button';
import PluginBlockSettingsMenuGroup from '../block-settings-menu/plugin-block-settings-menu-group';

function VisualEditor() {
return (
Expand All @@ -34,6 +36,9 @@ function VisualEditor() {
<_BlockSettingsMenuFirstItem>
{ ( { onClose } ) => <BlockInspectorButton onClick={ onClose } role="menuitem" /> }
</_BlockSettingsMenuFirstItem>
<_BlockSettingsMenuPluginsExtension>
{ ( { clientIds, onClose } ) => <PluginBlockSettingsMenuGroup.Slot fillProps={ { clientIds, onClose } } /> }
</_BlockSettingsMenuPluginsExtension>
</BlockSelectionClearer>
);
}
Expand Down
1 change: 0 additions & 1 deletion edit-post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export function initializeEditor( id, postType, postId, settings, overridePost )
}

export { default as PluginBlockSettingsMenuItem } from './components/block-settings-menu/plugin-block-settings-menu-item';
export { default as PluginBlockSettingsMenuGroup } from './components/block-settings-menu/plugin-block-settings-menu-group';
export { default as PluginPostPublishPanel } from './components/sidebar/plugin-post-publish-panel';
export { default as PluginPostStatusInfo } from './components/sidebar/plugin-post-status-info';
export { default as PluginPrePublishPanel } from './components/sidebar/plugin-pre-publish-panel';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

const { Fill: _BlockSettingsMenuPluginsExtension, Slot } = createSlotFill( '_BlockSettingsMenuPluginsExtension' );

_BlockSettingsMenuPluginsExtension.Slot = Slot;

export default _BlockSettingsMenuPluginsExtension;
4 changes: 2 additions & 2 deletions editor/components/block-settings-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import SharedBlockDeleteButton from './shared-block-delete-button';
import BlockHTMLConvertButton from './block-html-convert-button';
import BlockUnknownConvertButton from './block-unknown-convert-button';
import _BlockSettingsMenuFirstItem from './block-settings-menu-first-item';
import _BlockSettingsMenuPluginsExtension from './block-settings-menu-plugins-extension';
import withDeprecatedUniqueId from '../with-deprecated-unique-id';

export class BlockSettingsMenu extends Component {
Expand Down Expand Up @@ -56,7 +57,6 @@ export class BlockSettingsMenu extends Component {
focus,
rootClientId,
isHidden,
PluginExtension,
} = this.props;
const { isFocused } = this.state;
const blockClientIds = castArray( clientIds );
Expand Down Expand Up @@ -128,7 +128,7 @@ export class BlockSettingsMenu extends Component {
itemsRole="menuitem"
/>
) }
{ PluginExtension && ( <PluginExtension fillProps={ { clientIds, onClose } } /> ) }
<_BlockSettingsMenuPluginsExtension.Slot fillProps={ { clientIds, onClose } } />
<div className="editor-block-settings-menu__separator" />
{ count === 1 && (
<SharedBlockDeleteButton
Expand Down
1 change: 1 addition & 0 deletions editor/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export { default as BlockMover } from './block-mover';
export { default as BlockSelectionClearer } from './block-selection-clearer';
export { default as BlockSettingsMenu } from './block-settings-menu';
export { default as _BlockSettingsMenuFirstItem } from './block-settings-menu/block-settings-menu-first-item';
export { default as _BlockSettingsMenuPluginsExtension } from './block-settings-menu/block-settings-menu-plugins-extension';
export { default as BlockTitle } from './block-title';
export { default as BlockToolbar } from './block-toolbar';
export { default as CopyHandler } from './copy-handler';
Expand Down

0 comments on commit 566a1b8

Please sign in to comment.