You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e5f999f
Browse filesBrowse the repository at this point in the historyBrowse files
Media editor: Add a session boundary above the cropper
The media editor controller now represents the editing session rather
than extending CropperController. The cropper becomes a geometry-only
sub-controller at `session.cropper`, passed to `<Cropper>`.
- `setSourceImage` replaces `setImage` on the session. A different
image resets geometry and crop options, the baseline and history.
The cropper's `setImage` calls it.
- `hasOutputEdits` replaces `isCropperDirty` for deciding whether
saving produces new image output. The save hook reads the session.
See #79175.
Copy file name to clipboardExpand all lines: packages/media-editor/src/image-editor/docs/architecture.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@
8
8
| React cropper |`src/image-editor/react/`| DOM measurement, interaction hooks, overlays, stencil rendering, and the pure `useCropperReducer` hook. |
9
9
| Media editor state |`src/state/`| Composite state for the media editor: cropper state, crop options, undo/redo, and gesture boundaries. |
10
10
11
-
The cropper layer does not own editor history. History belongs to the composite media editor controller because sidebar controls and cropper gestures need one shared undo stack.
11
+
The cropper layer does not own editor history. History belongs to the media editor session because sidebar controls and cropper gestures need one shared undo stack.
12
12
13
13
## Coordinate Spaces
14
14
@@ -37,6 +37,10 @@ The render path uses focused calculations for CSS transforms, stencil placement,
37
37
38
38
The core reducer is framework-agnostic and serializable. React and media-editor layers add DOM measurement, gestures, undo/redo, save behavior, and UI state.
39
39
40
+
### Session
41
+
42
+
`useMediaEditorState()` returns the media editor session. The session owns the source image, every editing slice, the shared undo/redo history, gesture boundaries, and whether the edits change the saved image (`hasOutputEdits`). The cropper is one participant: `session.cropper` is a geometry-only `CropperController` that a `<Cropper>` takes via its `controller` prop, and its `isDirty` covers geometry alone. Replacing the source image (`setSourceImage`, which the cropper's `setImage` also calls) starts a fresh session with default geometry and crop options, a clean baseline, and no history. Save code asks the session, not the cropper, whether image output needs saving.
43
+
40
44
### Viewport
41
45
42
46
Viewport pan/zoom lets the user inspect or follow the crop area without changing the crop output. It is not part of export and should not create undo entries.
@@ -52,4 +56,4 @@ These APIs let code inside `@wordpress/media-editor` compose the cropper. They a
52
56
| Crop data for REST requests |`getSourceRegion()` and `getSourceRegionPercent()`. |
53
57
| Canvas export |`exportCroppedImage()` or `applyToCanvas()`. |
54
58
| Shared cropper state across internal components |`CropperProvider` / `useCropper()`. |
55
-
| Media editor history |`useMediaEditorState()`composite controller. |
59
+
| Media editor history |`useMediaEditorState()`session. |
Use the media editor controller when cropper state must share history with controls such as aspect ratio.
81
+
Use the media editor session when cropper state must share history with controls such as aspect ratio. The session owns history and gesture boundaries; pass its `cropper` controller to `<Cropper>`.
0 commit comments