Repository navigation
Media editor: Build the sidebar tabs from mounted panels - #84664
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +1.34 kB (+0.02%) Total Size: 8.73 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Actions are reachable via RIGHT/LEFT arrow keys in
|
6c07a06 to
d9129ee
Compare
|
This PR doesn't expose any public or experimental public API yet, but you can manually test adding tabs with the following: Export the component and state hookdiff --git a/packages/editor/src/private-apis.js b/packages/editor/src/private-apis.js
index 3ed92793fe0..ed69b7b9031 100644
--- a/packages/editor/src/private-apis.js
+++ b/packages/editor/src/private-apis.js
@@ -1,5 +1,6 @@
import * as interfaceApis from '@wordpress/interface';
-import { lock } from './lock-unlock';
+import { privateApis as mediaEditorPrivateApis } from '@wordpress/media-editor';
+import { lock, unlock } from './lock-unlock';
import BackButton from './components/header/back-button';
import Editor from './components/editor';
import PluginPostExcerpt from './components/post-excerpt/plugin';
@@ -21,6 +22,9 @@ import { GlobalStylesActionMenu } from './components/global-styles/menu';
import UploadProgressSnackbar from './components/upload-progress-snackbar';
const { store: interfaceStore, ...remainingInterfaceApis } = interfaceApis;
+// Media editor panels, re-exposed the way `PluginSidebar` is: a plugin
+// registers one from `registerPlugin( …, { scope: 'media-editor' } )`.
+const { MediaEditorPanel, useMediaEditor } = unlock( mediaEditorPrivateApis );
export const privateApis = {};
lock( privateApis, {
@@ -38,6 +42,8 @@ lock( privateApis, {
ViewMoreMenuGroup,
ResizableEditor,
UploadProgressSnackbar,
+ MediaEditorPanel,
+ useMediaEditor,
registerCoreBlockBindingsSources,
// Global Styles
GlobalStylesUIWrapper,
diff --git a/packages/media-editor/src/private-apis.ts b/packages/media-editor/src/private-apis.ts
index 261bb2022bc..b1b4149be00 100644
--- a/packages/media-editor/src/private-apis.ts
+++ b/packages/media-editor/src/private-apis.ts
@@ -2,10 +2,15 @@ import { lock } from './lock-unlock';
import { store } from './store';
import { MediaEditorModal } from './components/media-editor-modal';
import { MediaEditor } from './components/media-editor';
+import MediaEditorPanel from './components/media-editor-panel';
+import { useMediaEditor } from './state';
export const privateApis = {};
lock( privateApis, {
store,
MediaEditor,
MediaEditorModal,
+ // For panels: the tab + slot, and the session they drive.
+ MediaEditorPanel,
+ useMediaEditor,
} );Add a panel from the browser consoleconst { unlock } = wp.privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/editor'
);
const { MediaEditorPanel, useMediaEditor } = unlock( wp.editor.privateApis );
const { createElement: el } = wp.element;
const { RangeControl, Button } = wp.components;
function TesterPanel( { disabled } ) {
const {
edits, setEdit, setAspectRatioValue, cropper, beginGesture, endGesture,
} = useMediaEditor();
const amount = edits[ 'tester/vignette' ]?.amount ?? 0;
return el( 'div', null,
// One undo entry per drag: the gesture opens on pointer down, every
// change during the drag coalesces, and pointer up commits it. The
// same for a key held down. `data-crop-control` tells the editor the
// slider is an image control, so Cmd+Z while it has focus still undoes.
el( 'div', {
role: 'presentation',
'data-crop-control': true,
onPointerDownCapture: beginGesture,
onPointerUp: endGesture,
onPointerCancel: endGesture,
onKeyDownCapture: beginGesture,
onKeyUp: endGesture,
},
el( RangeControl, {
label: 'Vignette', value: amount, min: 0, max: 1, step: 0.05, disabled,
onChange: ( next ) => setEdit( 'tester/vignette', next ? { amount: next } : undefined ),
} )
),
el( Button, { disabled, onClick: () => setAspectRatioValue( '1' ) }, 'Square crop' ),
el( Button, { disabled, onClick: () => cropper.setRotation( 90 ) }, 'Rotate 90°' )
);
}
wp.plugins.registerPlugin( 'tester-panel', {
scope: 'media-editor',
render: () => el( MediaEditorPanel,
{ name: 'tester/vignette', title: 'Tester', order: 30, mediaTypes: [ 'image' ] },
( { disabled } ) => el( TesterPanel, { disabled } )
),
} );2026-10-23.12.36.52.mp4 |
There was a problem hiding this comment.
🟡 Changes recommended
Closing the media editor removes shared plugin subscriptions, preventing subsequent registration changes from notifying the host editor.
1 open issue
What changed in this PR
The media editor now builds sidebar tabs from mounted panels, laying the groundwork for extensions without exposing a public API.
Changes:
- Adds panel registration, ordering, cleanup, and Slot/Fill rendering.
- Migrates Crop and Details to panels and mounts scoped plugins inside the session provider.
- Adds panel tests, architecture documentation, and dependency configuration.
| File | Description |
|---|---|
| packages/media-editor/tsconfig.json | Adds the plugins project reference for development. |
| packages/media-editor/tsconfig.build.json | Adds the plugins project reference for builds. |
| packages/media-editor/src/image-editor/docs/architecture.md | Documents mounted panels and session access. |
| packages/media-editor/src/components/media-editor/index.tsx | Builds tabs from panels and mounts scoped plugins. |
| packages/media-editor/src/components/media-editor-panel/test/index.jsdom.test.tsx | Tests panel rendering, ordering, props, and lifecycle. |
| packages/media-editor/src/components/media-editor-panel/index.tsx | Implements panel registration and Slot/Fill content. |
| packages/media-editor/package.json | Declares the plugins dependency. |
| package-lock.json | Records the added dependency. |
Review effort: Balanced
|
Actually, this is getting too big. I've a mind to return it to draft and split it up into a stacked PR once it's working properly.
|
Sounds good, let me know when it's ready for a closer look! Just a drive-by comment re: naming. I'm wondering if A couple of wording ideas: Anyway, just a nit-picky drive-by thought, I don't feel strongly about this! 🙂 |
This is a good point, thanks for raising it. And maybe it won't be a tab one day too, e.g., accordion or some other UI. I don't want to paint things into a corner, and my guess it'd have to work with the media library too potentially. I like Or I imagine this PR, or a version of it, would land a long time before we made the extension point public. I was hoping to get the crop panel using the registration system first to see how it landed. There are a lot of tiny PRs to get to a public API in general. It'd be great, for example, if we could use a dumb cropper in the site settings > site icon crop step. Anyway, I digress. 😄 |
Good point! In that case, yeah, I think
Oh, nice idea. Yes, in that case we'll have the "core" version of it all hooked up to demonstrate how it all works. We might then even make it possible for plugins to de-register or filter panels/sidebars that they don't want folks to see or use. I.e. a cropper that is just cropping but no details tab 🤔 In any case, now I digress 😄 |
This is a good idea! Thanks! |
3f7a1ac to
ce4f739
Compare
ce4f739 to
fe9605d
Compare
fe9605d to
9119aef
Compare
React 19 takes inert as a boolean, but React 18 ignores a boolean and needs the string 'true'. inertValue returns whichever the running version renders, and the repo's other inert call sites already use it. Add @wordpress/react-inert-value as a dependency.
Trunk's `defaultPanel` prop names panels by id, and this branch renames the ids to `core/crop` and `core/details`. The modal still asked for `crop`, which no tab has, so it opened on Details. Update the modal, the prop's documented default and the test, and note that the default panel is listed first whatever its `order`.
823b3aa to
a9ff47b
Compare
The boundary took the thrown value as its sign that the panel had failed. A panel that threw `null` left that value falsy, so the boundary rendered the panel again, and the second throw went to the next boundary up. For a plugin's panel that removed the whole plugin, its other panels included. Track the failure in its own `hasError` flag.
Drop comments that restate the code or describe this change, and the ones that say a plugin renders a panel, which nothing exported makes possible yet. Keep the reasons a reader could not work out from the code.
They name each prop without describing it, and the lint does not ask for them in these files.
| * Keeps a panel's failure inside its tab, so the canvas, the other tabs and | ||
| * saving stay usable and the tab names the panel that failed. | ||
| */ | ||
| export default class MediaEditorPanelErrorBoundary extends Component< |
There was a problem hiding this comment.
TL;DR The error boundary stops a broken panel from taking out the rest of the sidebar with it.
It repeated `mediaType === 'image'`, and nothing read it.
This makes me wonder how much we can leverage the PHP-driven actions/fields APIs here (or if at all?). We just updated the AI plugin in the 7.2 cycle to make use of this API to, for example, update the excerpt in the inspector. |
Thank you for raising this @oandregal!! I suspect there's little scope to leverage those APIs right now. If I understand things correctly, the fields APIs deal with record data, and, for now, the goal is to get the panels to work on unsaved canvas states (pixels and crop states for example). Not to say that we shouldn't let third parties define custom fields from within extensions, but how that interacts with the attachment record and the existing details panel would need some chin scratching 😄 But! I think there's a lot we can learn from the patterns, e.g., registering actions/panels. Once the public API settles here, it's something I'd be interested to look into. Did I answer your question? 😅 |
andrewserong
left a comment
There was a problem hiding this comment.
Nice progress, this is looking pretty close to me, and it's smoke-testing well (including the default panel behaviour).
Just left a few comments, some nit-picky, but the main questions I had were about the scope/shape of the panels API (i.e. if we need order at this stage) and the useMediaEditorPanelContext hook and which data we will or won't need / want to expose.
What do you reckon?
| // Rebuilt each render, like the elements it replaces: consumers re-render | ||
| // as they always did, but the cluster component types stay stable. | ||
| const contextValue: MediaEditorFrameContextValue = { | ||
| isImage, |
There was a problem hiding this comment.
Just a note for a follow-up: if we're passing in mediaType, we can likely remove isImage (I think the route version uses it, so better as a follow-up)
There was a problem hiding this comment.
Good call. I'll do this in a separate refactor follow up
Tabs now follow the order their panels mount, with Core's first, and the editor still moves its default panel to the front. Only Core's two panels set an order.
Use the editor crash screen's description, which says what the user can do. The old line promised the rest of the editor kept working, which the notice cannot know.
A raw error message means little to the person looking at a broken tab, so the notice no longer prints or announces it. The button copies the message and the stack for a bug report, as the editor crash screen does.
Only Core's Crop panel read it, and only for the three aspect-ratio values `useCropOptions` already returns, so Crop calls that again. What panels from outside Core get is left for the change that exports them.
andrewserong
left a comment
There was a problem hiding this comment.
Thanks for the updates, this is looking great to me!
Left a couple more nit-picky comments, and whether the de-duping can be simplified a little. Nothing blocking as it's just internal behaviour, and this is mostly just me jotting down notes while I read through the code.
All smoke-testing well for me, thanks again for the back-and-forth. LGTM! 🚀
An object thrown without a message was copied as "[object Object]", and `null` as "null". Copy "An unknown error occurred." in those cases, as the editor crash screen does.
The comment named the dependency before the case it is for, and a reviewer could not tell what it described.
The error also told people to call `registerPlugin`, for a component nothing exports yet.
|
Thanks for the help to land this @andrewserong I'll merge and start on the follow ups |
|

What?
Part of #79175.
Plugins can add their own tabs to the media editor's sidebar, the way
PluginSidebaradds one to the post editor. Crop and Details are built the same way. This works in the post editor's modal and on the media editor page.Nothing changes on screen. Nothing is exported yet either, so plugins can't use it until a follow-up exposes it.
Why?
Extensions such as filters or an AI tool (WordPress/ai#325) have nowhere to go in the media editor.
Testing Instructions