Repository navigation
Conversation
The hook is named after its implementation. What it returns is the cropper controller, and its sibling `useCropper` reads that controller from the provider. Rename it before anything outside the package imports it, after which the old name would need a deprecation cycle.
The previous commit moved the hook and its test to their new names; this one points every import, call, comment and doc at `useCropperController` and describes the hook as the controller it returns.
`DEFAULT_ASPECT_RATIOS` carried translated labels, the engine's only user-facing strings and its only `@wordpress/i18n` import. The list now lives in the session layer, which owns presets. The engine keeps the `ORIGINAL_ASPECT_RATIO` sentinel and the preset type.
…rnals `image-editor/index.ts` is the cropper's contract, but it also exported what the media editor's session needs to delegate cropper actions through the pure reducer: the reducer, containment, state equality, the setters factory and the default state. A consumer building a cropper needs none of that, and anything the barrel exports is a commitment. Those move to `image-editor/internals`, which the session imports and the contract does not mention.
`setVisualSize` and `adjustCropRectForViewport` exist for `Cropper`, which reports its rendered size and viewport-driven reshapes through them; the pure hook ignores one and aliases the other. On a controller a consumer holds they read as things to call. Say what they are for.
🤖 PR meta 🤖📦 Bundle sizeSize Change: 0 B Total Size: 9.06 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
🏁 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. Regression: updating a specific option will only change its value and will not corrupt others in
|
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
Small clean-ups to the cropper code in
@wordpress/media-editorbefore any of it is made available outside the package. No behaviour change. Nothing is exported from the package yet.Why
The cropper is the part of the media editor that a plugin, or a site without WordPress, could one day use on its own: the
Croppercomponent, the hook that gives you its controller, and a few pure helpers. Its names, and the list of things it exports, become a commitment the moment anything outside the package imports them. This fixes the ones that would be awkward to change later, while changing them still costs nothing.What changed
useCropperReduceris renameduseCropperController. The old name described how the hook is built: it wraps a reducer. What a caller gets back is the cropper's controller, which is the current state plus the setters such assetZoomandsnapRotate90,reset,isDirtyandgetCroppedImage. Callers never see the reducer. The type is already calledCropperController, anduseCropper, which reads that same controller fromCropperProvider, already calls it the controller. The new name says what you get, matches the type and the provider hook, and lands before anyone outside the package imports the old one.src/image-editor/index.tsis the list of what the cropper exports. It also exported the helpers that only the media editor's own state code uses to drive the cropper through the pure reducer:cropperReducer,enforceContainment,areCropperStatesEqual,applyOperationToState,computeInscribedRect,buildCropperSettersandDEFAULT_STATE. Those move to a new file,src/image-editor/internals.ts, which the state code imports instead. The index keepsuseCropperController,Cropper,CropperProvider,useCropper, the types,ORIGINAL_ASPECT_RATIO,getSourceRegion,stateFromPipeline,exportCroppedImageandapplyToCanvas.src/image-editor/coreintosrc/state, next to the rest of the preset handling. Thecorefolder now has no@wordpress/i18nimport, so it holds no user-facing text.setVisualSizeandadjustCropRectForViewport, exist only soCroppercan report its rendered size and viewport changes. Their doc comments now say so, so nobody reads them as something to call.