Repository navigation
Conversation
`useMediaEditorEdit( name, defaultValue )` is what a panel gets for the edit it owns: `value`, `setValue`, `beginGesture` and `endGesture`, and nothing else of the session. The default lives with the panel; setting a value equal in content to it removes the edit, so the session reads as clean. See #79175.
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. 📦 Bundle sizeSize Change: 0 B Total Size: 8.64 MB
⚡ 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
|
Panels drive the editor through the session itself; this hook only covers a panel that owns one value. The docblocks and architecture note now say so.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This PR introduces a new hook
useMediaEditorEdit( name, defaultValue ), which is a shortcut for a panel that owns one named edit.So, think of a plugin that adds a Media Editor panel to apply image filters.
It's a baby step towards a public API for the image editor.
Fourth step of #79175, after #84591.
Why
Panels drive the editor through the session,
useMediaEditor(): the cropper controller, crop options, edits, the source image, reset and history. That is the interface plugins get, so a plugin can ship its own crop tools or load new pixels and the canvas follows.Core keeps what lives outside the session: the canvas component, the modal shell, Save and Cancel, shortcuts, notices, persistence, and the undo stacks themselves.
Within that, most panels will own a single value, a slider amount or a filter preset, and every one of them would write the same two lines: read
session.edits[ name ] ?? default, and on change decide whether to store the value or remove the edit. This hook is that convenience. It also holds the one rule we kept out of the engine in #83899: the session only knows an edit that is set, so the default lives with the panel. When a panel sets a value equal in content to its default, the hook removes the edit rather than storing it, so the session reads as clean and no undo entry is spent on a default.It is not a fence. A panel that needs more than its own value, an AI tool that also crops to the subject it found, say, uses the session directly alongside this hook.
What changed
state/use-media-editor-edit.ts, exported from the package'sstatebarrel. Not onprivateApisyet; nothing outside the package needs it until panels register.architecture.md.Nothing in production calls it, so there is no visible change.
Tests
Four cases in a new
use-media-editor-edit.jsdom.test.ts: the default is reported while the edit is not set;setValuerecords the value and the session is dirty; setting a value equal to the default removes the edit and the session is clean; changes inside a gesture make one undo entry.Manual testing
No behaviour change. Open the media editor from an Image block and confirm crop, undo, redo and Reset behave as on trunk.