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

Fix metabox reordering #30617

Merged
merged 22 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 5 additions & 1 deletion packages/edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ call initializeEditor(). This is due to metaBox timing.
_Parameters_

- _id_ `string`: Unique identifier for editor instance.
- _postType_ `Object`: Post type of the post to edit.
- _postType_ `string`: Post type of the post to edit.
- _postId_ `Object`: ID of the post to edit.
- _settings_ `?Object`: Editor settings object.
- _initialEdits_ `Object`: Programmatic edits to apply initially, to be considered as non-user-initiated (bypass for unsaved changes prompt).

_Returns_

- `Promise`: Promise that resolves when editor is initialized.

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

Renders a new item in the block settings menu.
Expand Down
15 changes: 14 additions & 1 deletion packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function Editor( {
settings,
initialEdits,
onError,
markEditorReady,
...props
} ) {
const {
Expand All @@ -50,6 +51,7 @@ function Editor( {
keepCaretInsideBlock,
isTemplateMode,
template,
isEditorReady,
} = useSelect( ( select ) => {
const {
isFeatureActive,
Expand All @@ -61,7 +63,9 @@ function Editor( {
const { getEntityRecord, getPostType, getEntityRecords } = select(
'core'
);
const { getEditorSettings } = select( 'core/editor' );
const { getEditorSettings, __unstableIsEditorReady } = select(
'core/editor'
);
const { getBlockTypes } = select( blocksStore );
const isTemplate = [ 'wp_template', 'wp_template_part' ].includes(
postType
Expand Down Expand Up @@ -102,6 +106,7 @@ function Editor( {
? getEditedPostTemplate()
: null,
post: postObject,
isEditorReady: __unstableIsEditorReady(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading the coding standards and wondering if this should be returned with the __unstable prefix too.

What am I missing? This is mainly for my own education rather than an opinion either way :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I was following the style established elsewhere in the code where __unstable and __experimental is often removed, for example here:

import {
BlockBreadcrumb,
__experimentalLibrary as Library,
} from '@wordpress/block-editor';
import { Button, ScrollLock, Popover } from '@wordpress/components';
import {
useViewportMatch,
__experimentalUseDialog as useDialog,
} from '@wordpress/compose';

Also, if I'm not mistaken, it seems that the __unstable and __experimental prefix is there for people using Gutenberg packages in their projects, so it's important not to document these functions and tell people to use them and so forth. Here it's just used locally and not exported anywhere.

That's just my reasoning for renaming it, but I'll put the __unstable prefix back if you think that would be better.

};
} );

Expand Down Expand Up @@ -165,6 +170,14 @@ function Editor( {
return null;
}

/**
* Some features like back compat metaboxes rely on editor notifying that
* it's ready by calling markEditorReady.
*/
if ( markEditorReady && isEditorReady ) {
markEditorReady();
}

return (
<StrictMode>
<EditPostSettings.Provider value={ settings }>
Expand Down
28 changes: 16 additions & 12 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { render, unmountComponentAtNode } from '@wordpress/element';
*/
import './hooks';
import './plugins';
export { store } from './store';
import Editor from './editor';

/**
Expand Down Expand Up @@ -68,12 +67,13 @@ export function reinitializeEditor(
* call initializeEditor(). This is due to metaBox timing.
*
* @param {string} id Unique identifier for editor instance.
* @param {Object} postType Post type of the post to edit.
* @param {string} postType Post type of the post to edit.
* @param {Object} postId ID of the post to edit.
* @param {?Object} settings Editor settings object.
* @param {Object} initialEdits Programmatic edits to apply initially, to be
* considered as non-user-initiated (bypass for
* unsaved changes prompt).
* @return {Promise} Promise that resolves when editor is initialized.
*/
export function initializeEditor(
id,
Expand Down Expand Up @@ -138,16 +138,19 @@ export function initializeEditor(
} );
}

render(
<Editor
settings={ settings }
onError={ reboot }
postId={ postId }
postType={ postType }
initialEdits={ initialEdits }
/>,
target
);
return new Promise( ( resolve ) => {
render(
<Editor
settings={ settings }
onError={ reboot }
postId={ postId }
postType={ postType }
initialEdits={ initialEdits }
markEditorReady={ resolve }
/>,
target
);
} );
}

export { default as PluginBlockSettingsMenuItem } from './components/block-settings-menu/plugin-block-settings-menu-item';
Expand All @@ -160,3 +163,4 @@ export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
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 { store } from './store';