@wordpress/media-editor 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/build/components/media-editor/index.cjs +41 -51
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor-crop-panel/index.cjs +15 -45
- package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
- package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
- package/build/components/media-editor-image-controls/index.cjs +230 -0
- package/build/components/media-editor-image-controls/index.cjs.map +7 -0
- package/build/components/media-form/index.cjs +12 -23
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/image-editor/core/constants.cjs +3 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/stencil-math.cjs +11 -2
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +12 -7
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +41 -51
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +8 -51
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs +221 -0
- package/build-module/components/media-editor-image-controls/index.mjs.map +7 -0
- package/build-module/components/media-form/index.mjs +12 -13
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +2 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/stencil-math.mjs +9 -1
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +12 -7
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-style/style-rtl.css +136 -47
- package/build-style/style.css +136 -46
- package/build-types/components/media-editor/index.d.ts +6 -7
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +11 -6
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +4 -3
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +46 -0
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -0
- package/build-types/components/media-editor-toolbar/index.d.ts +24 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts +18 -5
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +10 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +16 -3
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +108 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/package.json +25 -20
- package/src/components/media-editor/index.tsx +69 -77
- package/src/components/media-editor/style.scss +124 -4
- package/src/components/media-editor-crop-panel/index.tsx +16 -62
- package/src/components/media-editor-crop-panel/test/index.tsx +25 -41
- package/src/components/media-editor-fine-rotation/index.tsx +4 -3
- package/src/components/media-editor-image-controls/index.tsx +262 -0
- package/src/components/media-editor-image-controls/style.scss +48 -0
- package/src/components/media-editor-image-controls/test/index.tsx +150 -0
- package/src/components/media-editor-modal/style.scss +32 -42
- package/src/components/media-form/index.tsx +17 -21
- package/src/components/media-form/style.scss +6 -0
- package/src/components/rotation-ruler/style.scss +10 -3
- package/src/image-editor/core/constants.ts +11 -0
- package/src/image-editor/core/stencil-math.ts +23 -0
- package/src/image-editor/core/test/stencil-math.ts +39 -0
- package/src/image-editor/react/components/cropper.scss +28 -17
- package/src/image-editor/react/components/cropper.tsx +17 -7
- package/src/style.scss +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-transform-controls/index.cjs +0 -84
- package/build/components/media-editor-transform-controls/index.cjs.map +0 -7
- package/build/components/media-form/sidebar-datetime-view.cjs +0 -53
- package/build/components/media-form/sidebar-datetime-view.cjs.map +0 -7
- package/build-module/components/media-editor-transform-controls/index.mjs +0 -68
- package/build-module/components/media-editor-transform-controls/index.mjs.map +0 -7
- package/build-module/components/media-form/sidebar-datetime-view.mjs +0 -32
- package/build-module/components/media-form/sidebar-datetime-view.mjs.map +0 -7
- package/src/components/media-editor-transform-controls/index.tsx +0 -70
- package/src/components/media-editor-transform-controls/style.scss +0 -8
- package/src/components/media-form/sidebar-datetime-view.tsx +0 -47
- package/src/components/media-form/test/sidebar-datetime-view.test.tsx +0 -96
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState, TransformOperation, NormalizedPoint, NormalizedRect, Flip } from '../../core/types';
|
|
5
|
+
/**
|
|
6
|
+
* The return type of the useCropperState hook.
|
|
7
|
+
*
|
|
8
|
+
* The hook exposes its state through named setter methods rather
|
|
9
|
+
* than a raw dispatch function. Each setter has a specific
|
|
10
|
+
* behavioral contract (see individual JSDoc) that maps 1:1 to a
|
|
11
|
+
* reducer action internally. Keeping the reducer actions private
|
|
12
|
+
* lets the implementation evolve without breaking consumers.
|
|
13
|
+
*/
|
|
14
|
+
export interface UseCropperStateReturn {
|
|
15
|
+
/** The current cropper state (read-only). */
|
|
16
|
+
state: CropperState;
|
|
17
|
+
/** Set the loaded image (natural size and src). */
|
|
18
|
+
setImage: (image: CropperState['image']) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Set the image pan offset in normalized coordinates. Use
|
|
21
|
+
* `setCropRect` for the crop rectangle.
|
|
22
|
+
*/
|
|
23
|
+
setPan: (pan: NormalizedPoint) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Set the zoom level, anchored at the crop center. Clamped to the
|
|
26
|
+
* coverage-aware minimum and maximum zoom.
|
|
27
|
+
*
|
|
28
|
+
* Pointer-driven zoom (wheel, pinch, double-tap) anchors at the
|
|
29
|
+
* cursor via `setZoomAtPoint`. Cursorless surfaces — the slider, the
|
|
30
|
+
* `+`/`-` keys, programmatic toolbar buttons — have no natural
|
|
31
|
+
* focal point, so they default to the crop center. Otherwise
|
|
32
|
+
* `enforceContainment` would translate the image whichever way is
|
|
33
|
+
* shortest, which snaps the framed content toward the nearest
|
|
34
|
+
* viewport corner when zooming out from an off-center position.
|
|
35
|
+
*/
|
|
36
|
+
setZoom: (zoom: number) => void;
|
|
37
|
+
/** Set zoom and pan together so focal-point zoom remains atomic. */
|
|
38
|
+
setZoomAtPoint: (zoom: number, pan: NormalizedPoint) => void;
|
|
39
|
+
/** Set the rotation in degrees. Normalized to [0, 360). */
|
|
40
|
+
setRotation: (rotation: number) => void;
|
|
41
|
+
/** Set the flip state. */
|
|
42
|
+
setFlip: (flip: Flip) => void;
|
|
43
|
+
/** Toggle flip on the given axis. */
|
|
44
|
+
toggleFlip: (direction: 'horizontal' | 'vertical') => void;
|
|
45
|
+
/** Snap rotate 90° preserving the image selection (Google Photos style). */
|
|
46
|
+
snapRotate90: (direction: 1 | -1) => void;
|
|
47
|
+
/** Set the crop rectangle in normalized coordinates. */
|
|
48
|
+
setCropRect: (rect: NormalizedRect) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Settle the crop rect after a resize drag: expand to fill the
|
|
51
|
+
* available visual area while preserving the framed image region.
|
|
52
|
+
* Typically called from a stencil's `onResizeEnd` callback.
|
|
53
|
+
*
|
|
54
|
+
* Flushes the pending resize history before dispatching, then suppresses
|
|
55
|
+
* the settle dispatch itself so resizing and settling undo as one step.
|
|
56
|
+
*/
|
|
57
|
+
settleCrop: () => void;
|
|
58
|
+
/** Apply a transform operation through the pipeline. */
|
|
59
|
+
applyOperation: (op: TransformOperation) => void;
|
|
60
|
+
/** Reset the state. Optionally merge partial state overrides. */
|
|
61
|
+
reset: (resetState?: Partial<CropperState>) => void;
|
|
62
|
+
/** Whether the current state differs from the initial state. */
|
|
63
|
+
isDirty: boolean;
|
|
64
|
+
/** Whether there is a cropper state to undo. */
|
|
65
|
+
hasUndo: boolean;
|
|
66
|
+
/** Whether there is a cropper state to redo. */
|
|
67
|
+
hasRedo: boolean;
|
|
68
|
+
/** Undo the last committed cropper operation. */
|
|
69
|
+
undo: () => void;
|
|
70
|
+
/** Redo the last undone cropper operation. */
|
|
71
|
+
redo: () => void;
|
|
72
|
+
/**
|
|
73
|
+
* Flush the pending history entry immediately, bypassing the debounce
|
|
74
|
+
* timer. Useful in two situations:
|
|
75
|
+
*
|
|
76
|
+
* - **Pointer-up / key-up**: commit as soon as the user releases so the
|
|
77
|
+
* undo button lights up without waiting for the debounce window.
|
|
78
|
+
* - **Gesture start**: pass to `onGestureStart` on the `Cropper` so any
|
|
79
|
+
* pending sidebar interaction is committed before a new canvas gesture
|
|
80
|
+
* begins, keeping the two interactions as separate undo steps.
|
|
81
|
+
*/
|
|
82
|
+
commitHistory: () => void;
|
|
83
|
+
/**
|
|
84
|
+
* Export the cropped image as a Blob. Throws on failure — see
|
|
85
|
+
* `exportCroppedImage` in core for the error semantics (image
|
|
86
|
+
* load errors, CORS taint, missing canvas context). Wrap in
|
|
87
|
+
* try/catch if you need to recover.
|
|
88
|
+
*/
|
|
89
|
+
getCroppedImage: (mimeType?: string, quality?: number) => Promise<Blob>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reducer-based state management hook for the image editor.
|
|
93
|
+
*
|
|
94
|
+
* Provides the full cropper state and named setter methods for
|
|
95
|
+
* every supported transition. The reducer and containment logic
|
|
96
|
+
* live in core/state.ts (framework-agnostic); this hook is a thin
|
|
97
|
+
* React wrapper around that pure reducer, with memoized callbacks.
|
|
98
|
+
*
|
|
99
|
+
* History is recorded via a state-change debounce: any state change
|
|
100
|
+
* starts a 300 ms timer; when it fires the pre-change state is pushed
|
|
101
|
+
* onto the undo stack. `commitHistory` flushes the timer immediately
|
|
102
|
+
* (useful on pointer-up / key-up for a crisp commit feel).
|
|
103
|
+
*
|
|
104
|
+
* @param initialState Optional partial state to merge with DEFAULT_STATE.
|
|
105
|
+
* @return The cropper state, setters, and utilities.
|
|
106
|
+
*/
|
|
107
|
+
export declare function useCropperState(initialState?: Partial<CropperState>): UseCropperStateReturn;
|
|
108
|
+
//# sourceMappingURL=use-cropper-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-cropper-state.d.ts","sourceRoot":"","sources":["../../../../src/image-editor/react/hooks/use-cropper-state.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,IAAI,EACJ,MAAM,kBAAkB,CAAC;AAU1B;;;;;;;;GAQG;AACH,MAAM,WAAW,qBAAqB;IACrC,6CAA6C;IAC7C,KAAK,EAAE,YAAY,CAAC;IACpB,mDAAmD;IACnD,QAAQ,EAAE,CAAE,KAAK,EAAE,YAAY,CAAE,OAAO,CAAE,KAAM,IAAI,CAAC;IACrD;;;OAGG;IACH,MAAM,EAAE,CAAE,GAAG,EAAE,eAAe,KAAM,IAAI,CAAC;IACzC;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,CAAE,IAAI,EAAE,MAAM,KAAM,IAAI,CAAC;IAClC,oEAAoE;IACpE,cAAc,EAAE,CAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,KAAM,IAAI,CAAC;IAC/D,2DAA2D;IAC3D,WAAW,EAAE,CAAE,QAAQ,EAAE,MAAM,KAAM,IAAI,CAAC;IAC1C,0BAA0B;IAC1B,OAAO,EAAE,CAAE,IAAI,EAAE,IAAI,KAAM,IAAI,CAAC;IAChC,qCAAqC;IACrC,UAAU,EAAE,CAAE,SAAS,EAAE,YAAY,GAAG,UAAU,KAAM,IAAI,CAAC;IAC7D,4EAA4E;IAC5E,YAAY,EAAE,CAAE,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,KAAM,IAAI,CAAC;IAC5C,wDAAwD;IACxD,WAAW,EAAE,CAAE,IAAI,EAAE,cAAc,KAAM,IAAI,CAAC;IAC9C;;;;;;;OAOG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,wDAAwD;IACxD,cAAc,EAAE,CAAE,EAAE,EAAE,kBAAkB,KAAM,IAAI,CAAC;IACnD,iEAAiE;IACjE,KAAK,EAAE,CAAE,UAAU,CAAC,EAAE,OAAO,CAAE,YAAY,CAAE,KAAM,IAAI,CAAC;IACxD,gEAAgE;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB;;;;;;;;;OASG;IACH,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B;;;;;OAKG;IACH,eAAe,EAAE,CAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAM,OAAO,CAAE,IAAI,CAAE,CAAC;CAC5E;AAgCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC9B,YAAY,CAAC,EAAE,OAAO,CAAE,YAAY,CAAE,GACpC,qBAAqB,CAmVvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/media-editor",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Media editor components for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
},
|
|
35
35
|
"./package.json": "./package.json"
|
|
36
36
|
},
|
|
37
|
-
"react-native": "src/index",
|
|
38
37
|
"types": "build-types",
|
|
39
38
|
"sideEffects": [
|
|
40
39
|
"build-style/**",
|
|
@@ -44,31 +43,37 @@
|
|
|
44
43
|
"build-module/store/index.mjs"
|
|
45
44
|
],
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@wordpress/
|
|
49
|
-
"@wordpress/
|
|
50
|
-
"@wordpress/
|
|
51
|
-
"@wordpress/
|
|
52
|
-
"@wordpress/data": "^
|
|
53
|
-
"@wordpress/
|
|
54
|
-
"@wordpress/
|
|
55
|
-
"@wordpress/
|
|
56
|
-
"@wordpress/
|
|
57
|
-
"@wordpress/
|
|
58
|
-
"@wordpress/
|
|
59
|
-
"@wordpress/
|
|
60
|
-
"@wordpress/
|
|
61
|
-
"@wordpress/
|
|
62
|
-
"@wordpress/
|
|
63
|
-
"@wordpress/
|
|
46
|
+
"@types/react": "^18.3.27",
|
|
47
|
+
"@wordpress/api-fetch": "^7.48.1",
|
|
48
|
+
"@wordpress/base-styles": "^10.0.1",
|
|
49
|
+
"@wordpress/components": "^35.0.1",
|
|
50
|
+
"@wordpress/compose": "^8.1.1",
|
|
51
|
+
"@wordpress/core-data": "^7.48.1",
|
|
52
|
+
"@wordpress/data": "^10.48.1",
|
|
53
|
+
"@wordpress/dataviews": "^16.0.1",
|
|
54
|
+
"@wordpress/date": "^5.48.1",
|
|
55
|
+
"@wordpress/element": "^8.0.1",
|
|
56
|
+
"@wordpress/i18n": "^6.21.1",
|
|
57
|
+
"@wordpress/icons": "^14.0.1",
|
|
58
|
+
"@wordpress/interface": "^9.33.1",
|
|
59
|
+
"@wordpress/keyboard-shortcuts": "^5.48.1",
|
|
60
|
+
"@wordpress/keycodes": "^4.48.1",
|
|
61
|
+
"@wordpress/notices": "^5.48.1",
|
|
62
|
+
"@wordpress/private-apis": "^1.48.1",
|
|
63
|
+
"@wordpress/ui": "^0.15.1",
|
|
64
64
|
"clsx": "^2.1.1",
|
|
65
65
|
"gl-matrix": "^3.4.3"
|
|
66
66
|
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@testing-library/dom": "^10.4.1",
|
|
69
|
+
"@testing-library/react": "^16.3.2",
|
|
70
|
+
"@testing-library/user-event": "^14.6.1"
|
|
71
|
+
},
|
|
67
72
|
"peerDependencies": {
|
|
68
73
|
"react": "^18.0.0"
|
|
69
74
|
},
|
|
70
75
|
"publishConfig": {
|
|
71
76
|
"access": "public"
|
|
72
77
|
},
|
|
73
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "99df7432c5c7cb83ba41146fd1f57f3c19004305"
|
|
74
79
|
}
|
|
@@ -47,7 +47,7 @@ import type { Media } from '../media-editor-provider';
|
|
|
47
47
|
import MediaPreview from '../media-preview';
|
|
48
48
|
import MediaEditorCanvas from '../media-editor-canvas';
|
|
49
49
|
import MediaEditorFineRotation from '../media-editor-fine-rotation';
|
|
50
|
-
import
|
|
50
|
+
import MediaEditorImageControls from '../media-editor-image-controls';
|
|
51
51
|
import MediaEditorCropPanel from '../media-editor-crop-panel';
|
|
52
52
|
import MediaForm from '../media-form';
|
|
53
53
|
import { unlock } from '../../lock-unlock';
|
|
@@ -86,15 +86,14 @@ export interface MediaEditorFrameProps {
|
|
|
86
86
|
footerActions: ReactNode;
|
|
87
87
|
/**
|
|
88
88
|
* Footer layout selector. Frames apply this to the footer container
|
|
89
|
-
* as a modifier class.
|
|
89
|
+
* as a modifier class. Tracks the sidebar-collapse breakpoint (`medium`).
|
|
90
90
|
*
|
|
91
|
-
* - `wide` —
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* Cancel/Save.
|
|
91
|
+
* - `wide` — sidebar is a column; footer is a single row of History |
|
|
92
|
+
* Cancel/Save (transform controls live in the Crop panel).
|
|
93
|
+
* - `narrow` — sidebar collapsed; transform controls sit above a
|
|
94
|
+
* History | Cancel/Save row.
|
|
96
95
|
*/
|
|
97
|
-
footerLayout: 'wide' | '
|
|
96
|
+
footerLayout: 'wide' | 'narrow';
|
|
98
97
|
onRequestClose: () => void;
|
|
99
98
|
onKeyDown: ( event: ReactKeyboardEvent< HTMLElement > ) => void;
|
|
100
99
|
shouldCloseOnClickOutside: boolean;
|
|
@@ -128,6 +127,7 @@ function MediaEditorSidebar( { tabs }: { tabs: EditorTab[] } ) {
|
|
|
128
127
|
className="media-editor__sidebar"
|
|
129
128
|
panelClassName="media-editor__sidebar-panel"
|
|
130
129
|
headerClassName="media-editor__sidebar-header"
|
|
130
|
+
closeLabel={ __( 'Close media panel' ) }
|
|
131
131
|
header={
|
|
132
132
|
<Tabs.Context.Provider value={ tabsContextValue }>
|
|
133
133
|
<Tabs.TabList>
|
|
@@ -247,6 +247,15 @@ function HistoryActions( {
|
|
|
247
247
|
expanded={ false }
|
|
248
248
|
gap={ 2 }
|
|
249
249
|
>
|
|
250
|
+
<Button
|
|
251
|
+
size="compact"
|
|
252
|
+
variant="tertiary"
|
|
253
|
+
disabled={ ! isDirty }
|
|
254
|
+
accessibleWhenDisabled
|
|
255
|
+
onClick={ handleReset }
|
|
256
|
+
>
|
|
257
|
+
{ __( 'Reset' ) }
|
|
258
|
+
</Button>
|
|
250
259
|
<Button
|
|
251
260
|
size="compact"
|
|
252
261
|
icon={ undo }
|
|
@@ -271,15 +280,6 @@ function HistoryActions( {
|
|
|
271
280
|
accessibleWhenDisabled
|
|
272
281
|
onClick={ handleRedo }
|
|
273
282
|
/>
|
|
274
|
-
<Button
|
|
275
|
-
size="compact"
|
|
276
|
-
variant="tertiary"
|
|
277
|
-
disabled={ ! isDirty }
|
|
278
|
-
accessibleWhenDisabled
|
|
279
|
-
onClick={ handleReset }
|
|
280
|
-
>
|
|
281
|
-
{ __( 'Reset' ) }
|
|
282
|
-
</Button>
|
|
283
283
|
</Flex>
|
|
284
284
|
);
|
|
285
285
|
}
|
|
@@ -343,19 +343,15 @@ function MediaEditorContent( {
|
|
|
343
343
|
shouldCloseOnEsc = false,
|
|
344
344
|
}: MediaEditorProps ) {
|
|
345
345
|
const cropper = useMediaEditor();
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
footerLayout = 'wide';
|
|
356
|
-
} else if ( isMediumViewport ) {
|
|
357
|
-
footerLayout = 'medium';
|
|
358
|
-
}
|
|
346
|
+
// The sidebar is a side column from the `small` breakpoint up and collapses
|
|
347
|
+
// to an overlay below it — mirroring InterfaceSkeleton's behaviour, shifted
|
|
348
|
+
// from `medium` to `small` (see the matching CSS overrides in style.scss).
|
|
349
|
+
// Track that single breakpoint: in "panel mode" (≥ small) the
|
|
350
|
+
// rotate/flip/zoom controls live in the Crop panel and the footer is just
|
|
351
|
+
// History + Cancel/Save; below it the controls drop into the footer. (The
|
|
352
|
+
// fine-rotation ruler always sits under the canvas.)
|
|
353
|
+
const isPanelLayout = useViewportMatch( 'small' );
|
|
354
|
+
const footerLayout: 'wide' | 'narrow' = isPanelLayout ? 'wide' : 'narrow';
|
|
359
355
|
|
|
360
356
|
const { media, hasEdits } = useSelect(
|
|
361
357
|
( select ) => {
|
|
@@ -489,10 +485,8 @@ function MediaEditorContent( {
|
|
|
489
485
|
<MediaEditorCropPanel
|
|
490
486
|
aspectRatioValue={ aspectRatioValue }
|
|
491
487
|
onAspectRatioChange={ setAspectRatioValue }
|
|
492
|
-
onPlacementControlInteraction={
|
|
493
|
-
signalPlacementControlInteraction
|
|
494
|
-
}
|
|
495
488
|
aspectRatioOptions={ aspectRatioOptions }
|
|
489
|
+
showTransformControls={ isPanelLayout }
|
|
496
490
|
/>
|
|
497
491
|
</Stack>
|
|
498
492
|
),
|
|
@@ -504,7 +498,7 @@ function MediaEditorContent( {
|
|
|
504
498
|
aspectRatioValue,
|
|
505
499
|
setAspectRatioValue,
|
|
506
500
|
aspectRatioOptions,
|
|
507
|
-
|
|
501
|
+
isPanelLayout,
|
|
508
502
|
] );
|
|
509
503
|
|
|
510
504
|
const handleChange = ( updates: Partial< Media > ) => {
|
|
@@ -575,6 +569,12 @@ function MediaEditorContent( {
|
|
|
575
569
|
/>
|
|
576
570
|
);
|
|
577
571
|
|
|
572
|
+
const ruler = isImage ? (
|
|
573
|
+
<MediaEditorFineRotation
|
|
574
|
+
onPlacementControlInteraction={ signalPlacementControlInteraction }
|
|
575
|
+
/>
|
|
576
|
+
) : null;
|
|
577
|
+
|
|
578
578
|
const children = (
|
|
579
579
|
<MediaEditorProvider
|
|
580
580
|
value={ media ?? undefined }
|
|
@@ -600,22 +600,29 @@ function MediaEditorContent( {
|
|
|
600
600
|
sidebar: __( 'Media details' ),
|
|
601
601
|
} }
|
|
602
602
|
content={
|
|
603
|
-
<div className="media-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
isPlacementActive
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
603
|
+
<div className="media-editor__content">
|
|
604
|
+
<div className="media-editor__canvas-area">
|
|
605
|
+
{ isImage ? (
|
|
606
|
+
<MediaEditorCanvas
|
|
607
|
+
focusOnMount
|
|
608
|
+
isPlacementActive={
|
|
609
|
+
isPlacementActive
|
|
610
|
+
}
|
|
611
|
+
onGestureStart={
|
|
612
|
+
handleCanvasGestureStart
|
|
613
|
+
}
|
|
614
|
+
onGestureEnd={
|
|
615
|
+
handleCanvasGestureEnd
|
|
616
|
+
}
|
|
617
|
+
/>
|
|
618
|
+
) : (
|
|
619
|
+
<MediaPreview />
|
|
620
|
+
) }
|
|
621
|
+
</div>
|
|
622
|
+
{ isImage && (
|
|
623
|
+
<div className="media-editor__canvas-toolbar">
|
|
624
|
+
{ ruler }
|
|
625
|
+
</div>
|
|
619
626
|
) }
|
|
620
627
|
</div>
|
|
621
628
|
}
|
|
@@ -652,12 +659,12 @@ function MediaEditorContent( {
|
|
|
652
659
|
onReset={ resetCropOptions }
|
|
653
660
|
/>
|
|
654
661
|
) : null;
|
|
655
|
-
const
|
|
656
|
-
<
|
|
657
|
-
|
|
662
|
+
const imageControls = isImage ? (
|
|
663
|
+
<MediaEditorImageControls
|
|
664
|
+
showAspectRatioControl
|
|
665
|
+
aspectRatioPresets={ aspectRatioPresets }
|
|
658
666
|
/>
|
|
659
667
|
) : null;
|
|
660
|
-
const transform = isImage ? <MediaEditorTransformControls /> : null;
|
|
661
668
|
const actions = (
|
|
662
669
|
<FooterActions
|
|
663
670
|
isSaving={ isSaving }
|
|
@@ -668,40 +675,25 @@ function MediaEditorContent( {
|
|
|
668
675
|
/>
|
|
669
676
|
);
|
|
670
677
|
|
|
671
|
-
//
|
|
672
|
-
//
|
|
673
|
-
//
|
|
674
|
-
//
|
|
678
|
+
// The fine-rotation ruler always lives under the canvas (in
|
|
679
|
+
// `media-editor__content`), never the footer, so it stays constrained to
|
|
680
|
+
// the canvas column at every viewport. One JSX tree per layout; DOM order
|
|
681
|
+
// matches visual order.
|
|
675
682
|
let footerActions: ReactNode;
|
|
676
683
|
if ( footerLayout === 'wide' ) {
|
|
684
|
+
// Sidebar is a column: image controls live in the Crop panel, so
|
|
685
|
+
// the footer is just History + Cancel/Save.
|
|
677
686
|
footerActions = (
|
|
678
687
|
<>
|
|
679
688
|
{ history }
|
|
680
|
-
{ isImage && (
|
|
681
|
-
<div className="media-editor-modal__footer-toolbar">
|
|
682
|
-
{ ruler }
|
|
683
|
-
{ transform }
|
|
684
|
-
</div>
|
|
685
|
-
) }
|
|
686
689
|
{ actions }
|
|
687
690
|
</>
|
|
688
691
|
);
|
|
689
|
-
} else if ( footerLayout === 'medium' ) {
|
|
690
|
-
footerActions = (
|
|
691
|
-
<>
|
|
692
|
-
{ ruler }
|
|
693
|
-
<div className="media-editor-modal__footer-row">
|
|
694
|
-
{ history }
|
|
695
|
-
{ transform }
|
|
696
|
-
{ actions }
|
|
697
|
-
</div>
|
|
698
|
-
</>
|
|
699
|
-
);
|
|
700
692
|
} else {
|
|
693
|
+
// Sidebar collapsed: the image controls drop into the footer.
|
|
701
694
|
footerActions = (
|
|
702
695
|
<>
|
|
703
|
-
{
|
|
704
|
-
{ transform }
|
|
696
|
+
{ imageControls }
|
|
705
697
|
<div className="media-editor-modal__footer-row">
|
|
706
698
|
{ history }
|
|
707
699
|
{ actions }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/breakpoints" as breakpoints;
|
|
1
2
|
@use "@wordpress/base-styles/colors" as *;
|
|
2
3
|
@use "@wordpress/base-styles/mixins" as *;
|
|
3
4
|
@use "@wordpress/base-styles/variables" as *;
|
|
@@ -33,13 +34,50 @@
|
|
|
33
34
|
flex: 1;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
// Canvas column: image fills the available height; in panel mode the
|
|
38
|
+
// fine-rotation ruler sits directly beneath it.
|
|
39
|
+
.media-editor__content {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex: 1;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
min-height: 0;
|
|
44
|
+
// Inset the canvas + fine-rotation ruler as one rounded grey panel
|
|
45
|
+
// with a horizontal-only gutter. The ruler is always a child here
|
|
46
|
+
// (never the footer), so the two share a container and the panel is
|
|
47
|
+
// fully rounded at every viewport.
|
|
48
|
+
margin: 0 $grid-unit-30;
|
|
49
|
+
border-radius: $radius-large;
|
|
50
|
+
overflow: hidden;
|
|
51
|
+
@include break-small() {
|
|
52
|
+
// Compensate for the left gutter in the sidebar panel
|
|
53
|
+
// so the modal padding is uniform (24px).
|
|
54
|
+
margin-right: $grid-unit-30 - $grid-unit-10;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.media-editor__canvas-toolbar {
|
|
59
|
+
display: flex;
|
|
60
|
+
flex-shrink: 0;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
// Share the canvas grey so the ruler strip blends into the same
|
|
63
|
+
// surface as the area around the image.
|
|
64
|
+
background: $gray-200;
|
|
65
|
+
padding: $grid-unit-10 $grid-unit-20;
|
|
66
|
+
|
|
67
|
+
.media-editor-fine-rotation {
|
|
68
|
+
flex: 0 1 360px;
|
|
69
|
+
min-width: 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.media-editor__canvas-area {
|
|
37
74
|
display: flex;
|
|
38
75
|
align-items: center;
|
|
39
76
|
justify-content: center;
|
|
40
|
-
background: $gray-
|
|
77
|
+
background: $gray-200;
|
|
41
78
|
overflow: auto;
|
|
42
|
-
|
|
79
|
+
flex: 1;
|
|
80
|
+
min-height: 0;
|
|
43
81
|
|
|
44
82
|
.media-editor-preview {
|
|
45
83
|
height: 100%;
|
|
@@ -55,24 +93,106 @@
|
|
|
55
93
|
|
|
56
94
|
.media-editor__sidebar {
|
|
57
95
|
@include reset;
|
|
96
|
+
|
|
97
|
+
// Small left gutter so the tabs and panel content (and the zoom
|
|
98
|
+
// slider's thumb at its minimum) sit off the sidebar edge. Only in the
|
|
99
|
+
// column layout; below `small` the sidebar is a full-width overlay and
|
|
100
|
+
// uses the panel's own gutter instead.
|
|
101
|
+
@include break-small() {
|
|
102
|
+
padding-left: $grid-unit-10;
|
|
103
|
+
}
|
|
58
104
|
}
|
|
59
105
|
|
|
106
|
+
.media-editor__sidebar-panel {
|
|
107
|
+
padding-bottom: $grid-unit-30;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Borderless controls panel: clear the InterfaceSkeleton sidebar's
|
|
111
|
+
// default top border, left box-shadow, and high-contrast outline so the
|
|
112
|
+
// panel sits flush with no divider lines.
|
|
113
|
+
// NOTE: overrides @wordpress/interface internals. The sidebar region has
|
|
114
|
+
// no className prop, so this targets `interface-interface-skeleton__sidebar`
|
|
115
|
+
// directly — update here if that class is renamed upstream.
|
|
116
|
+
.interface-interface-skeleton__sidebar {
|
|
117
|
+
border-top: 0;
|
|
118
|
+
box-shadow: none;
|
|
119
|
+
outline: 1px solid transparent;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Below `small` the sidebar is a full-width overlay, so the panel carries
|
|
123
|
+
// its own all-around gutter. From `small` up it's the right-hand column and
|
|
124
|
+
// drops its left/bottom padding (the sidebar supplies the left gutter).
|
|
60
125
|
.media-editor__panel {
|
|
61
126
|
padding: $grid-unit-20;
|
|
127
|
+
|
|
128
|
+
@include break-small() {
|
|
129
|
+
padding: $grid-unit-20 $grid-unit-30 0 0;
|
|
130
|
+
}
|
|
62
131
|
}
|
|
63
132
|
|
|
133
|
+
// NOTE: overrides @wordpress/components Panel/Button internals to align
|
|
134
|
+
// the sidebar header (tabs + close button). Targets their classes
|
|
135
|
+
// directly; update here if they are renamed upstream.
|
|
64
136
|
.components-panel__header.media-editor__sidebar-header {
|
|
65
137
|
padding-left: 0;
|
|
66
138
|
padding-right: $grid-unit-10;
|
|
139
|
+
margin-right: $grid-unit-30;
|
|
67
140
|
|
|
68
141
|
.components-button.has-icon {
|
|
69
142
|
padding: 0;
|
|
70
143
|
|
|
71
|
-
@include break-
|
|
144
|
+
@include break-small() {
|
|
72
145
|
display: flex;
|
|
73
146
|
}
|
|
74
147
|
}
|
|
75
148
|
}
|
|
149
|
+
|
|
150
|
+
// `ComplementaryArea`'s "mobile" mode is hard-coded to the `medium`
|
|
151
|
+
// breakpoint: below 782px it renders an animated fill wrapper and writes
|
|
152
|
+
// `width: 100vw` inline on both it and the inner panel. We want the sidebar
|
|
153
|
+
// to mirror InterfaceSkeleton's column/overlay collapse but shifted to
|
|
154
|
+
// `small`, so we override that inline width by breakpoint (`!important` is
|
|
155
|
+
// the only way to beat an inline style). `:has(__fill)` scopes the changes
|
|
156
|
+
// to when the panel is actually open: the skeleton sidebar wrapper is always
|
|
157
|
+
// present (empty when closed), so touching it unconditionally would paint an
|
|
158
|
+
// empty box over the canvas.
|
|
159
|
+
|
|
160
|
+
// Column (small–medium): between 600px and 782px `ComplementaryArea` is
|
|
161
|
+
// still in its mobile mode (inline `100vw`, see above) and the skeleton
|
|
162
|
+
// sidebar is absolutely positioned, so pull the open panel back in-flow at
|
|
163
|
+
// the sidebar width to sit it beside the canvas as a column.
|
|
164
|
+
//
|
|
165
|
+
// Bounded *below* the medium breakpoint on purpose. From 782px up,
|
|
166
|
+
// `InterfaceSkeleton` already makes the sidebar a `position: relative`,
|
|
167
|
+
// `width: auto` column and `ComplementaryArea` animates its width to
|
|
168
|
+
// `$sidebar-width` — exactly like the main editor. Pinning the width with
|
|
169
|
+
// `!important` there would freeze that open/close tween (the panel would
|
|
170
|
+
// sit mounted and unchanged for the animation's duration, then pop in or
|
|
171
|
+
// out), so we leave it to the skeleton. Below 782px there's nothing to
|
|
172
|
+
// freeze: `ComplementaryArea` zeroes the animation duration in mobile mode.
|
|
173
|
+
@media (min-width: #{ breakpoints.$break-small }) and (max-width: #{ (breakpoints.$break-medium - 1) }) {
|
|
174
|
+
.interface-interface-skeleton__sidebar:has(.interface-complementary-area__fill) {
|
|
175
|
+
position: relative !important;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.interface-complementary-area__fill,
|
|
179
|
+
.interface-complementary-area {
|
|
180
|
+
width: $sidebar-width !important;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Overlay (< small): the open panel fills the modal width (it would
|
|
185
|
+
// otherwise shrink-wrap, since the inline `100vw` is overridden below).
|
|
186
|
+
@media (max-width: #{ (breakpoints.$break-small - 1) }) {
|
|
187
|
+
.interface-interface-skeleton__sidebar:has(.interface-complementary-area__fill) {
|
|
188
|
+
width: 100%;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.interface-complementary-area__fill,
|
|
192
|
+
.interface-complementary-area {
|
|
193
|
+
width: 100% !important;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
76
196
|
}
|
|
77
197
|
|
|
78
198
|
.media-editor__snackbar {
|