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

Block Library: Reimplement Reusable Block using EditorProvider for embedded post editor #14715

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 4 additions & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
@@ -197,6 +197,10 @@ Undocumented declaration.

Undocumented declaration.

<a name="FormatToolbar" href="#FormatToolbar">#</a> **FormatToolbar**

Undocumented declaration.

<a name="getColorClassName" href="#getColorClassName">#</a> **getColorClassName**

Returns a class based on the context a color is being used and its slug.
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ export {
RichTextShortcut,
RichTextToolbarButton,
__unstableRichTextInputEvent,
FormatToolbar,
} from './rich-text';
export { default as URLInput } from './url-input';
export { default as URLInputButton } from './url-input/button';
10 changes: 4 additions & 6 deletions packages/block-editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { DropZoneProvider, SlotFillProvider } from '@wordpress/components';
import { DropZoneProvider } from '@wordpress/components';
import { withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';

@@ -121,11 +121,9 @@ class BlockEditorProvider extends Component {
const { children } = this.props;

return (
<SlotFillProvider>
<DropZoneProvider>
{ children }
</DropZoneProvider>
</SlotFillProvider>
<DropZoneProvider>
{ children }
</DropZoneProvider>
);
}
}
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@ import { orderBy } from 'lodash';
*/

import { __ } from '@wordpress/i18n';
import { Toolbar, Slot, DropdownMenu } from '@wordpress/components';
import { Toolbar, Slot, DropdownMenu, createSlotFill } from '@wordpress/components';

const { Slot: ToolbarControlsSlot } = createSlotFill( 'RichText.ToolbarControls' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was only to have a reference to the slot so we can pass it to SlotFillProvider right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was only to have a reference to the slot so we can pass it to SlotFillProvider right?

Yes, rather than reference these by their string names (which so far we've considered an internal implementation detail), it seems we may instead want to reference the components themselves.


const FormatToolbar = ( { controls } ) => {
return (
@@ -18,7 +20,7 @@ const FormatToolbar = ( { controls } ) => {
{ controls.map( ( format ) =>
<Slot name={ `RichText.ToolbarControls.${ format }` } key={ format } />
) }
<Slot name="RichText.ToolbarControls">
<ToolbarControlsSlot>
{ ( fills ) => fills.length !== 0 &&
<DropdownMenu
icon={ false }
@@ -27,10 +29,12 @@ const FormatToolbar = ( { controls } ) => {
controls={ orderBy( fills.map( ( [ { props } ] ) => props ), 'title' ) }
/>
}
</Slot>
</ToolbarControlsSlot>
</Toolbar>
</div>
);
};

FormatToolbar.Slot = ToolbarControlsSlot;

export default FormatToolbar;
Original file line number Diff line number Diff line change
@@ -2,17 +2,21 @@
* WordPress dependencies
*/

import { Toolbar, Slot } from '@wordpress/components';
import { Toolbar, Slot, createSlotFill } from '@wordpress/components';

const { Slot: ToolbarControlsSlot } = createSlotFill( 'RichText.ToolbarControls' );

const FormatToolbar = ( { controls } ) => {
return (
<Toolbar>
{ controls.map( ( format ) =>
<Slot name={ `RichText.ToolbarControls.${ format }` } key={ format } />
) }
<Slot name="RichText.ToolbarControls" />
<ToolbarControlsSlot />
</Toolbar>
);
};

FormatToolbar.Slot = ToolbarControlsSlot;

export default FormatToolbar;
1 change: 1 addition & 0 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
@@ -1217,3 +1217,4 @@ export default RichTextContainer;
export { RichTextShortcut } from './shortcut';
export { RichTextToolbarButton } from './toolbar-button';
export { __unstableRichTextInputEvent } from './input-event';
export { FormatToolbar };
37 changes: 35 additions & 2 deletions packages/block-library/src/block/edit-panel/index.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@ import { Button } from '@wordpress/components';
import { Component, createRef } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { ESCAPE } from '@wordpress/keycodes';
import { withInstanceId } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { withInstanceId, compose } from '@wordpress/compose';

class ReusableBlockEditPanel extends Component {
constructor() {
@@ -107,4 +108,36 @@ class ReusableBlockEditPanel extends Component {
}
}

export default withInstanceId( ReusableBlockEditPanel );
export default compose( [
withInstanceId,
withSelect( ( select ) => {
const { getEditedPostAttribute, isSavingPost } = select( 'core/editor' );

return {
title: getEditedPostAttribute( 'title' ),
isSaving: isSavingPost(),
};
} ),
withDispatch( ( dispatch, ownProps ) => {
const {
editPost,
savePost,
clearSelectedBlock,
} = dispatch( 'core/editor' );

return {
onChangeTitle( title ) {
editPost( { title } );
},
onSave() {
clearSelectedBlock();
savePost();
ownProps.onSave();
},
onCancel() {
clearSelectedBlock();
ownProps.onCancel();
},
};
} ),
] )( ReusableBlockEditPanel );
Loading