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: Fix the issue where statics for deprecated components were not hoisted #16152

Merged
merged 1 commit into from
Jun 14, 2019
Merged
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
30 changes: 20 additions & 10 deletions packages/editor/src/components/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
RichText as RootRichText,
RichTextShortcut as RootRichTextShortcut,
RichTextToolbarButton as RootRichTextToolbarButton,
RichTextInserterItem as RootRichTextInserterItem,
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no such component in @wordpress/block-editor ...

__unstableRichTextInputEvent as __unstableRootRichTextInputEvent,
MediaPlaceholder as RootMediaPlaceholder,
MediaUpload as RootMediaUpload,
Expand All @@ -64,14 +63,23 @@ import {

export { default as ServerSideRender } from '@wordpress/server-side-render';

function deprecateComponent( name, Wrapped ) {
return forwardRef( ( props, ref ) => {
function deprecateComponent( name, Wrapped, staticsToHoist = [] ) {
const Component = forwardRef( ( props, ref ) => {
deprecated( 'wp.editor.' + name, {
alternative: 'wp.blockEditor.' + name,
} );

return <Wrapped ref={ ref }{ ...props } />;
} );

staticsToHoist.forEach( ( staticName ) => {
Component[ staticName ] = deprecateComponent(
name + '.' + staticName,
Wrapped[ staticName ]
);
} );

return Component;
}

function deprecateFunction( name, func ) {
Expand All @@ -84,13 +92,17 @@ function deprecateFunction( name, func ) {
};
}

const RichText = deprecateComponent( 'RichText', RootRichText, [ 'Content' ] );
RichText.isEmpty = deprecateFunction( 'RichText.isEmpty', RootRichText.isEmpty );

export { RichText };
export const Autocomplete = deprecateComponent( 'Autocomplete', RootAutocomplete );
export const AlignmentToolbar = deprecateComponent( 'AlignmentToolbar', RootAlignmentToolbar );
export const BlockAlignmentToolbar = deprecateComponent( 'BlockAlignmentToolbar', RootBlockAlignmentToolbar );
export const BlockControls = deprecateComponent( 'BlockControls', RootBlockControls );
export const BlockControls = deprecateComponent( 'BlockControls', RootBlockControls, [ 'Slot' ] );
export const BlockEdit = deprecateComponent( 'BlockEdit', RootBlockEdit );
export const BlockEditorKeyboardShortcuts = deprecateComponent( 'BlockEditorKeyboardShortcuts', RootBlockEditorKeyboardShortcuts );
export const BlockFormatControls = deprecateComponent( 'BlockFormatControls', RootBlockFormatControls );
export const BlockFormatControls = deprecateComponent( 'BlockFormatControls', RootBlockFormatControls, [ 'Slot' ] );
export const BlockIcon = deprecateComponent( 'BlockIcon', RootBlockIcon );
export const BlockInspector = deprecateComponent( 'BlockInspector', RootBlockInspector );
export const BlockList = deprecateComponent( 'BlockList', RootBlockList );
Expand All @@ -106,15 +118,13 @@ export const CopyHandler = deprecateComponent( 'CopyHandler', RootCopyHandler );
export const DefaultBlockAppender = deprecateComponent( 'DefaultBlockAppender', RootDefaultBlockAppender );
export const FontSizePicker = deprecateComponent( 'FontSizePicker', RootFontSizePicker );
export const Inserter = deprecateComponent( 'Inserter', RootInserter );
export const InnerBlocks = deprecateComponent( 'InnerBlocks', RootInnerBlocks );
export const InspectorAdvancedControls = deprecateComponent( 'InspectorAdvancedControls', RootInspectorAdvancedControls );
export const InspectorControls = deprecateComponent( 'InspectorControls', RootInspectorControls );
export const InnerBlocks = deprecateComponent( 'InnerBlocks', RootInnerBlocks, [ 'ButtonBlockAppender', 'DefaultBlockAppender', 'Content' ] );
export const InspectorAdvancedControls = deprecateComponent( 'InspectorAdvancedControls', RootInspectorAdvancedControls, [ 'Slot' ] );
export const InspectorControls = deprecateComponent( 'InspectorControls', RootInspectorControls, [ 'Slot' ] );
export const PanelColorSettings = deprecateComponent( 'PanelColorSettings', RootPanelColorSettings );
export const PlainText = deprecateComponent( 'PlainText', RootPlainText );
export const RichText = deprecateComponent( 'RichText', RootRichText );
export const RichTextShortcut = deprecateComponent( 'RichTextShortcut', RootRichTextShortcut );
export const RichTextToolbarButton = deprecateComponent( 'RichTextToolbarButton', RootRichTextToolbarButton );
export const RichTextInserterItem = deprecateComponent( 'RichTextInserterItem', RootRichTextInserterItem );
export const __unstableRichTextInputEvent = deprecateComponent( '__unstableRichTextInputEvent', __unstableRootRichTextInputEvent );
export const MediaPlaceholder = deprecateComponent( 'MediaPlaceholder', RootMediaPlaceholder );
export const MediaUpload = deprecateComponent( 'MediaUpload', RootMediaUpload );
Expand Down