@wordpress/media-editor 0.11.0 → 0.11.2-next.v.202606191442.0

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.
Files changed (179) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/components/media-editor/index.cjs +41 -51
  3. package/build/components/media-editor/index.cjs.map +3 -3
  4. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  5. package/build/components/media-editor-canvas/index.cjs +63 -15
  6. package/build/components/media-editor-canvas/index.cjs.map +3 -3
  7. package/build/components/media-editor-crop-panel/index.cjs +15 -45
  8. package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
  9. package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
  10. package/build/components/media-editor-image-controls/index.cjs +230 -0
  11. package/build/components/media-editor-image-controls/index.cjs.map +7 -0
  12. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +4 -4
  13. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
  14. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -1
  15. package/build/components/media-form/index.cjs +12 -23
  16. package/build/components/media-form/index.cjs.map +3 -3
  17. package/build/components/rotation-ruler/index.cjs +1 -1
  18. package/build/components/rotation-ruler/index.cjs.map +1 -1
  19. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  20. package/build/image-editor/core/camera.cjs +13 -0
  21. package/build/image-editor/core/camera.cjs.map +2 -2
  22. package/build/image-editor/core/constants.cjs +15 -3
  23. package/build/image-editor/core/constants.cjs.map +2 -2
  24. package/build/image-editor/core/containment.cjs.map +1 -1
  25. package/build/image-editor/core/crop-rect.cjs.map +1 -1
  26. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -1
  27. package/build/image-editor/core/interaction-controller.cjs +9 -7
  28. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  29. package/build/image-editor/core/math/sanitize.cjs.map +1 -1
  30. package/build/image-editor/core/setter-helpers.cjs.map +1 -1
  31. package/build/image-editor/core/source-region.cjs +111 -2
  32. package/build/image-editor/core/source-region.cjs.map +2 -2
  33. package/build/image-editor/core/state.cjs.map +1 -1
  34. package/build/image-editor/core/stencil-math.cjs +14 -6
  35. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  36. package/build/image-editor/core/transform-style.cjs.map +1 -1
  37. package/build/image-editor/core/types.cjs.map +1 -1
  38. package/build/image-editor/react/components/cropper.cjs +231 -49
  39. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  40. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -1
  41. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +1 -0
  42. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
  43. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +65 -19
  44. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  45. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -1
  46. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +1 -1
  47. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
  48. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -1
  49. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -1
  50. package/build/index.cjs.map +1 -1
  51. package/build/state/types.cjs.map +1 -1
  52. package/build/state/use-media-editor-state.cjs +1 -1
  53. package/build/state/use-media-editor-state.cjs.map +2 -2
  54. package/build-module/components/media-editor/index.mjs +41 -51
  55. package/build-module/components/media-editor/index.mjs.map +2 -2
  56. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  57. package/build-module/components/media-editor-canvas/index.mjs +55 -17
  58. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  59. package/build-module/components/media-editor-crop-panel/index.mjs +8 -51
  60. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  61. package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
  62. package/build-module/components/media-editor-image-controls/index.mjs +221 -0
  63. package/build-module/components/media-editor-image-controls/index.mjs.map +7 -0
  64. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +4 -4
  65. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
  66. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -1
  67. package/build-module/components/media-form/index.mjs +12 -13
  68. package/build-module/components/media-form/index.mjs.map +2 -2
  69. package/build-module/components/rotation-ruler/index.mjs +1 -1
  70. package/build-module/components/rotation-ruler/index.mjs.map +1 -1
  71. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -1
  72. package/build-module/image-editor/core/camera.mjs +12 -0
  73. package/build-module/image-editor/core/camera.mjs.map +2 -2
  74. package/build-module/image-editor/core/constants.mjs +10 -2
  75. package/build-module/image-editor/core/constants.mjs.map +2 -2
  76. package/build-module/image-editor/core/containment.mjs.map +1 -1
  77. package/build-module/image-editor/core/crop-rect.mjs.map +1 -1
  78. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -1
  79. package/build-module/image-editor/core/interaction-controller.mjs +9 -7
  80. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  81. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -1
  82. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -1
  83. package/build-module/image-editor/core/source-region.mjs +108 -1
  84. package/build-module/image-editor/core/source-region.mjs.map +2 -2
  85. package/build-module/image-editor/core/state.mjs.map +1 -1
  86. package/build-module/image-editor/core/stencil-math.mjs +12 -5
  87. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  88. package/build-module/image-editor/core/transform-style.mjs.map +1 -1
  89. package/build-module/image-editor/react/components/cropper.mjs +242 -52
  90. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  91. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -1
  92. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +1 -0
  93. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  94. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +65 -19
  95. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  96. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -1
  97. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +1 -1
  98. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
  99. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -1
  100. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -1
  101. package/build-module/index.mjs.map +1 -1
  102. package/build-module/state/types.mjs.map +1 -1
  103. package/build-module/state/use-media-editor-state.mjs +1 -1
  104. package/build-module/state/use-media-editor-state.mjs.map +2 -2
  105. package/build-style/style-rtl.css +179 -47
  106. package/build-style/style.css +179 -46
  107. package/build-types/components/media-editor/index.d.ts +6 -7
  108. package/build-types/components/media-editor/index.d.ts.map +1 -1
  109. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  110. package/build-types/components/media-editor-crop-panel/index.d.ts +11 -6
  111. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  112. package/build-types/components/media-editor-fine-rotation/index.d.ts +4 -3
  113. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  114. package/build-types/components/media-editor-image-controls/index.d.ts +46 -0
  115. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -0
  116. package/build-types/components/media-form/index.d.ts.map +1 -1
  117. package/build-types/image-editor/core/camera.d.ts +25 -1
  118. package/build-types/image-editor/core/camera.d.ts.map +1 -1
  119. package/build-types/image-editor/core/constants.d.ts +30 -1
  120. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  121. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  122. package/build-types/image-editor/core/source-region.d.ts +23 -1
  123. package/build-types/image-editor/core/source-region.d.ts.map +1 -1
  124. package/build-types/image-editor/core/stencil-math.d.ts +22 -4
  125. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  126. package/build-types/image-editor/core/types.d.ts +14 -0
  127. package/build-types/image-editor/core/types.d.ts.map +1 -1
  128. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  129. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  130. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +17 -14
  131. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  132. package/package.json +30 -20
  133. package/src/components/media-editor/index.tsx +69 -77
  134. package/src/components/media-editor/style.scss +136 -4
  135. package/src/components/media-editor-canvas/index.tsx +82 -13
  136. package/src/components/media-editor-canvas/style.scss +41 -0
  137. package/src/components/media-editor-crop-panel/index.tsx +16 -62
  138. package/src/components/media-editor-crop-panel/test/index.tsx +25 -41
  139. package/src/components/media-editor-fine-rotation/index.tsx +4 -3
  140. package/src/components/media-editor-image-controls/index.tsx +262 -0
  141. package/src/components/media-editor-image-controls/style.scss +48 -0
  142. package/src/components/media-editor-image-controls/test/index.tsx +150 -0
  143. package/src/components/media-editor-modal/style.scss +32 -42
  144. package/src/components/media-form/index.tsx +17 -21
  145. package/src/components/media-form/style.scss +6 -0
  146. package/src/components/rotation-ruler/style.scss +10 -3
  147. package/src/image-editor/core/camera.ts +60 -1
  148. package/src/image-editor/core/constants.ts +34 -1
  149. package/src/image-editor/core/interaction-controller.ts +25 -11
  150. package/src/image-editor/core/source-region.ts +202 -1
  151. package/src/image-editor/core/stencil-math.ts +42 -10
  152. package/src/image-editor/core/test/camera.ts +272 -1
  153. package/src/image-editor/core/test/interaction-controller.ts +100 -0
  154. package/src/image-editor/core/test/stencil-math.ts +153 -0
  155. package/src/image-editor/core/types.ts +17 -0
  156. package/src/image-editor/react/components/cropper.scss +28 -17
  157. package/src/image-editor/react/components/cropper.tsx +362 -62
  158. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +1 -0
  159. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +101 -32
  160. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +169 -17
  161. package/src/image-editor/react/components/test/cropper.tsx +689 -6
  162. package/src/style.scss +2 -1
  163. package/tsconfig.tsbuildinfo +1 -1
  164. package/build/components/media-editor-transform-controls/index.cjs +0 -84
  165. package/build/components/media-editor-transform-controls/index.cjs.map +0 -7
  166. package/build/components/media-form/sidebar-datetime-view.cjs +0 -53
  167. package/build/components/media-form/sidebar-datetime-view.cjs.map +0 -7
  168. package/build-module/components/media-editor-transform-controls/index.mjs +0 -68
  169. package/build-module/components/media-editor-transform-controls/index.mjs.map +0 -7
  170. package/build-module/components/media-form/sidebar-datetime-view.mjs +0 -32
  171. package/build-module/components/media-form/sidebar-datetime-view.mjs.map +0 -7
  172. package/build-types/components/media-editor-transform-controls/index.d.ts +0 -8
  173. package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
  174. package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
  175. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
  176. package/src/components/media-editor-transform-controls/index.tsx +0 -70
  177. package/src/components/media-editor-transform-controls/style.scss +0 -8
  178. package/src/components/media-form/sidebar-datetime-view.tsx +0 -47
  179. package/src/components/media-form/test/sidebar-datetime-view.test.tsx +0 -96
@@ -0,0 +1,262 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ Button,
6
+ DropdownMenu,
7
+ MenuGroup,
8
+ MenuItem,
9
+ } from '@wordpress/components';
10
+ import { __ } from '@wordpress/i18n';
11
+ import {
12
+ aspectRatio as aspectRatioIcon,
13
+ check,
14
+ rotateLeft,
15
+ rotateRight,
16
+ flipHorizontal,
17
+ flipVertical,
18
+ lineSolid,
19
+ plus,
20
+ } from '@wordpress/icons';
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+ import { useMediaEditor } from '../../state';
26
+ import {
27
+ MAX_ZOOM,
28
+ type AspectRatioPreset,
29
+ } from '../../image-editor/core/constants';
30
+ import { getMinZoom } from '../../image-editor/core/containment';
31
+ import { useCropOptions } from '../media-editor/use-crop-options';
32
+
33
+ /**
34
+ * Default zoom factor per +/- click. Zooming is geometric, so a fixed
35
+ * multiplier — rather than an additive step — makes each click feel like the
36
+ * same amount of zoom at any level (an additive `+0.1` is a 10% jump at 1× but
37
+ * a ~1% nudge at 10×). `1.2` is ~+20% per click. Overridable via the
38
+ * `zoomFactor` prop.
39
+ */
40
+ export const DEFAULT_ZOOM_FACTOR = 1.2;
41
+
42
+ export interface MediaEditorImageControlsProps {
43
+ /**
44
+ * When `true`, render rotate, flip and zoom as labelled groups — the Crop
45
+ * panel layout used on wide viewports. When `false` (default), render a
46
+ * single flat row of icon buttons — the footer layout used at narrower
47
+ * widths.
48
+ */
49
+ withLabels?: boolean;
50
+ /**
51
+ * When `true`, include an aspect-ratio dropdown in the flat toolbar.
52
+ * Omitted from the labelled panel layout because the Crop panel already
53
+ * renders the full aspect-ratio select control.
54
+ */
55
+ showAspectRatioControl?: boolean;
56
+ /** Optional caller-supplied aspect-ratio presets. */
57
+ aspectRatioPresets?: AspectRatioPreset[];
58
+ /**
59
+ * Multiplier applied to the zoom per +/- click — zoom in multiplies by it,
60
+ * zoom out divides by it. Must be greater than 1. Defaults to
61
+ * `DEFAULT_ZOOM_FACTOR` (1.2).
62
+ */
63
+ zoomFactor?: number;
64
+ }
65
+
66
+ /**
67
+ * Image editing controls placed independently per viewport: on wide viewports
68
+ * rotate/flip/zoom render inside the Crop panel (`withLabels`), and at narrower
69
+ * widths they fall back into the footer toolbar (flat row), where the
70
+ * aspect-ratio dropdown can also be shown.
71
+ *
72
+ * @param props
73
+ * @param props.withLabels
74
+ * @param props.showAspectRatioControl
75
+ * @param props.aspectRatioPresets
76
+ * @param props.zoomFactor
77
+ */
78
+ export default function MediaEditorImageControls( {
79
+ withLabels = false,
80
+ showAspectRatioControl = false,
81
+ aspectRatioPresets,
82
+ zoomFactor = DEFAULT_ZOOM_FACTOR,
83
+ }: MediaEditorImageControlsProps ) {
84
+ const { state, setFlip, snapRotate90, setZoom } = useMediaEditor();
85
+ const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
86
+ useCropOptions( { aspectRatioPresets } );
87
+ const hasAspectRatioControl = ! withLabels && showAspectRatioControl;
88
+ const minZoom = getMinZoom( state );
89
+ const zoomByFactor = ( factor: number ) => {
90
+ setZoom(
91
+ Math.min( MAX_ZOOM, Math.max( minZoom, state.zoom * factor ) )
92
+ );
93
+ };
94
+
95
+ const rotateButtons = (
96
+ <>
97
+ <Button
98
+ size="compact"
99
+ icon={ rotateLeft }
100
+ label={ __( 'Rotate 90° counter-clockwise' ) }
101
+ showTooltip
102
+ onClick={ () => snapRotate90( -1 ) }
103
+ />
104
+ <Button
105
+ size="compact"
106
+ icon={ rotateRight }
107
+ label={ __( 'Rotate 90° clockwise' ) }
108
+ showTooltip
109
+ onClick={ () => snapRotate90( 1 ) }
110
+ />
111
+ </>
112
+ );
113
+
114
+ const flipButtons = (
115
+ <>
116
+ <Button
117
+ size="compact"
118
+ icon={ flipHorizontal }
119
+ label={ __( 'Flip horizontal' ) }
120
+ showTooltip
121
+ isPressed={ state.flip.horizontal }
122
+ onClick={ () =>
123
+ setFlip( {
124
+ horizontal: ! state.flip.horizontal,
125
+ vertical: state.flip.vertical,
126
+ } )
127
+ }
128
+ />
129
+ <Button
130
+ size="compact"
131
+ icon={ flipVertical }
132
+ label={ __( 'Flip vertical' ) }
133
+ showTooltip
134
+ isPressed={ state.flip.vertical }
135
+ onClick={ () =>
136
+ setFlip( {
137
+ horizontal: state.flip.horizontal,
138
+ vertical: ! state.flip.vertical,
139
+ } )
140
+ }
141
+ />
142
+ </>
143
+ );
144
+
145
+ const zoomButtons = (
146
+ <>
147
+ <Button
148
+ size="compact"
149
+ icon={ plus }
150
+ label={ __( 'Zoom in' ) }
151
+ showTooltip
152
+ disabled={ state.zoom >= MAX_ZOOM }
153
+ accessibleWhenDisabled
154
+ onClick={ () => zoomByFactor( zoomFactor ) }
155
+ />
156
+ <Button
157
+ size="compact"
158
+ icon={ lineSolid }
159
+ label={ __( 'Zoom out' ) }
160
+ showTooltip
161
+ disabled={ state.zoom <= minZoom }
162
+ accessibleWhenDisabled
163
+ onClick={ () => zoomByFactor( 1 / zoomFactor ) }
164
+ />
165
+ </>
166
+ );
167
+
168
+ const aspectRatioDropdown = hasAspectRatioControl ? (
169
+ <DropdownMenu
170
+ icon={ aspectRatioIcon }
171
+ label={ __( 'Aspect ratio' ) }
172
+ popoverProps={ { placement: 'top' } }
173
+ toggleProps={ { size: 'compact' } }
174
+ >
175
+ { ( { onClose } ) => (
176
+ <MenuGroup label={ __( 'Aspect ratio' ) }>
177
+ { aspectRatioOptions.map( ( preset ) => {
178
+ const value = preset.value.toString();
179
+ const isSelected = value === aspectRatioValue;
180
+ return (
181
+ <MenuItem
182
+ key={ value }
183
+ role="menuitemradio"
184
+ isSelected={ isSelected }
185
+ icon={ isSelected ? check : undefined }
186
+ onClick={ () => {
187
+ setAspectRatioValue( value );
188
+ onClose();
189
+ } }
190
+ >
191
+ { preset.label }
192
+ </MenuItem>
193
+ );
194
+ } ) }
195
+ </MenuGroup>
196
+ ) }
197
+ </DropdownMenu>
198
+ ) : null;
199
+
200
+ if ( withLabels ) {
201
+ return (
202
+ <div className="media-editor-image-controls is-stacked">
203
+ <div className="media-editor-image-controls__transforms">
204
+ <div
205
+ className="media-editor-image-controls__group"
206
+ role="group"
207
+ aria-label={ __( 'Rotate' ) }
208
+ >
209
+ <span
210
+ className="media-editor-image-controls__label"
211
+ aria-hidden="true"
212
+ >
213
+ { __( 'Rotate' ) }
214
+ </span>
215
+ <div className="media-editor-image-controls__buttons">
216
+ { rotateButtons }
217
+ </div>
218
+ </div>
219
+ <div
220
+ className="media-editor-image-controls__group"
221
+ role="group"
222
+ aria-label={ __( 'Flip' ) }
223
+ >
224
+ <span
225
+ className="media-editor-image-controls__label"
226
+ aria-hidden="true"
227
+ >
228
+ { __( 'Flip' ) }
229
+ </span>
230
+ <div className="media-editor-image-controls__buttons">
231
+ { flipButtons }
232
+ </div>
233
+ </div>
234
+ </div>
235
+ <div
236
+ className="media-editor-image-controls__group"
237
+ role="group"
238
+ aria-label={ __( 'Zoom' ) }
239
+ >
240
+ <span
241
+ className="media-editor-image-controls__label"
242
+ aria-hidden="true"
243
+ >
244
+ { __( 'Zoom' ) }
245
+ </span>
246
+ <div className="media-editor-image-controls__buttons">
247
+ { zoomButtons }
248
+ </div>
249
+ </div>
250
+ </div>
251
+ );
252
+ }
253
+
254
+ return (
255
+ <div className="media-editor-image-controls">
256
+ { rotateButtons }
257
+ { flipButtons }
258
+ { zoomButtons }
259
+ { aspectRatioDropdown }
260
+ </div>
261
+ );
262
+ }
@@ -0,0 +1,48 @@
1
+ @use "@wordpress/base-styles/variables" as *;
2
+ @use "@wordpress/base-styles/colors" as *;
3
+
4
+ .media-editor-image-controls {
5
+ display: flex;
6
+ flex-wrap: nowrap;
7
+ align-items: center;
8
+ gap: $grid-unit-10;
9
+
10
+ // Stacked layout used inside the Crop panel on wide viewports: the Rotate
11
+ // and Flip groups sit side by side (rotate left, flip right) in a row, with
12
+ // the Zoom group beneath them. The aspect-ratio select renders separately
13
+ // below in the Crop panel.
14
+ &.is-stacked {
15
+ flex-direction: column;
16
+ align-items: flex-start;
17
+ gap: $grid-unit-30;
18
+ }
19
+
20
+ &__transforms {
21
+ display: flex;
22
+ gap: $grid-unit-60;
23
+ }
24
+
25
+ &__group {
26
+ display: flex;
27
+ flex-direction: column;
28
+ gap: $grid-unit-05;
29
+ }
30
+
31
+ // Match the uppercase 11px heading the panel's other controls use for
32
+ // their labels (Zoom, Aspect ratio) so the groups read as section
33
+ // headings. Mirrors `baseLabelTypography` from `@wordpress/components`.
34
+ &__label {
35
+ font-size: 11px;
36
+ font-weight: 500;
37
+ line-height: 1.4;
38
+ text-transform: uppercase;
39
+ }
40
+
41
+ &__buttons {
42
+ display: flex;
43
+ gap: $grid-unit-10;
44
+ // Small leading inset so the leftmost (rotate) button's focus ring
45
+ // isn't clipped by the sidebar's `overflow: hidden`.
46
+ padding-inline: 2px 0;
47
+ }
48
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import MediaEditorImageControls from '..';
10
+ import type { MediaEditorImageControlsProps } from '..';
11
+ import { MediaEditorStateProvider, useMediaEditor } from '../../../state';
12
+ import type { CropperState } from '../../../image-editor';
13
+ import { MAX_ZOOM } from '../../../image-editor/core/constants';
14
+
15
+ function setup(
16
+ props: MediaEditorImageControlsProps = {},
17
+ initialCropperState?: Partial< CropperState >
18
+ ) {
19
+ render(
20
+ <MediaEditorStateProvider initialCropperState={ initialCropperState }>
21
+ <MediaEditorImageControls { ...props } />
22
+ <CurrentState />
23
+ </MediaEditorStateProvider>
24
+ );
25
+ }
26
+
27
+ function CurrentState() {
28
+ const { state, cropOptions } = useMediaEditor();
29
+
30
+ return (
31
+ <>
32
+ <output data-testid="current-aspect-ratio">
33
+ { cropOptions.aspectRatioValue }
34
+ </output>
35
+ <output data-testid="current-zoom">{ state.zoom }</output>
36
+ </>
37
+ );
38
+ }
39
+
40
+ describe( 'MediaEditorImageControls', () => {
41
+ it( 'renders a flat row of rotate, flip and zoom buttons by default', () => {
42
+ setup();
43
+
44
+ expect(
45
+ screen.getByRole( 'button', {
46
+ name: 'Rotate 90° counter-clockwise',
47
+ } )
48
+ ).toBeInTheDocument();
49
+ expect(
50
+ screen.getByRole( 'button', { name: 'Flip horizontal' } )
51
+ ).toBeInTheDocument();
52
+ expect(
53
+ screen.getByRole( 'button', { name: 'Zoom in' } )
54
+ ).toBeInTheDocument();
55
+ expect(
56
+ screen.getByRole( 'button', { name: 'Zoom out' } )
57
+ ).toBeInTheDocument();
58
+
59
+ // No visible group labels in the flat (footer) layout.
60
+ expect( screen.queryByText( 'Rotate' ) ).not.toBeInTheDocument();
61
+ expect( screen.queryByText( 'Flip' ) ).not.toBeInTheDocument();
62
+ expect( screen.queryByText( 'Zoom' ) ).not.toBeInTheDocument();
63
+ } );
64
+
65
+ it( 'renders labelled rotate, flip and zoom groups when withLabels is set', () => {
66
+ setup( { withLabels: true } );
67
+
68
+ expect( screen.getByText( 'Rotate' ) ).toBeInTheDocument();
69
+ expect( screen.getByText( 'Flip' ) ).toBeInTheDocument();
70
+ expect( screen.getByText( 'Zoom' ) ).toBeInTheDocument();
71
+ expect(
72
+ screen.getByRole( 'button', { name: 'Rotate 90° clockwise' } )
73
+ ).toBeInTheDocument();
74
+ expect(
75
+ screen.getByRole( 'button', { name: 'Zoom in' } )
76
+ ).toBeInTheDocument();
77
+ } );
78
+
79
+ it( 'zoom in multiplies the zoom and zoom out divides it', () => {
80
+ setup( {}, { zoom: 2 } );
81
+
82
+ fireEvent.click( screen.getByRole( 'button', { name: 'Zoom in' } ) );
83
+ const zoomedIn = Number(
84
+ screen.getByTestId( 'current-zoom' ).textContent
85
+ );
86
+ expect( zoomedIn ).toBeGreaterThan( 2 );
87
+
88
+ fireEvent.click( screen.getByRole( 'button', { name: 'Zoom out' } ) );
89
+ expect(
90
+ Number( screen.getByTestId( 'current-zoom' ).textContent )
91
+ ).toBeLessThan( zoomedIn );
92
+ } );
93
+
94
+ it( 'honors a custom zoomFactor', () => {
95
+ setup( { zoomFactor: 2 }, { zoom: 2 } );
96
+
97
+ fireEvent.click( screen.getByRole( 'button', { name: 'Zoom in' } ) );
98
+
99
+ // A factor of 2 from zoom 2 lands at 4 (within [minZoom, MAX_ZOOM]).
100
+ expect(
101
+ Number( screen.getByTestId( 'current-zoom' ).textContent )
102
+ ).toBe( 4 );
103
+ } );
104
+
105
+ it( 'disables Zoom in at the maximum zoom', () => {
106
+ setup( {}, { zoom: MAX_ZOOM } );
107
+ // Buttons use `accessibleWhenDisabled`, so the disabled state is
108
+ // expressed via aria-disabled, not the `disabled` attribute.
109
+ expect(
110
+ screen.getByRole( 'button', { name: 'Zoom in' } )
111
+ ).toHaveAttribute( 'aria-disabled', 'true' );
112
+ } );
113
+
114
+ it( 'disables Zoom out at the minimum zoom', () => {
115
+ setup();
116
+ expect(
117
+ screen.getByRole( 'button', { name: 'Zoom out' } )
118
+ ).toHaveAttribute( 'aria-disabled', 'true' );
119
+ } );
120
+
121
+ it( 'renders an aspect ratio dropdown in the flat toolbar when enabled', async () => {
122
+ setup( {
123
+ showAspectRatioControl: true,
124
+ } );
125
+
126
+ fireEvent.click(
127
+ screen.getByRole( 'button', { name: 'Aspect ratio' } )
128
+ );
129
+ fireEvent.click(
130
+ screen.getByRole( 'menuitemradio', { name: 'Square (1:1)' } )
131
+ );
132
+
133
+ await waitFor( () =>
134
+ expect(
135
+ screen.getByTestId( 'current-aspect-ratio' )
136
+ ).toHaveTextContent( '1' )
137
+ );
138
+ } );
139
+
140
+ it( 'omits the aspect ratio dropdown from the labelled panel layout', () => {
141
+ setup( {
142
+ withLabels: true,
143
+ showAspectRatioControl: true,
144
+ } );
145
+
146
+ expect(
147
+ screen.queryByRole( 'button', { name: 'Aspect ratio' } )
148
+ ).not.toBeInTheDocument();
149
+ } );
150
+ } );
@@ -21,71 +21,51 @@
21
21
  min-height: 0;
22
22
  }
23
23
 
24
- // Footer chrome — three layouts driven by `is-wide` / `is-medium` /
25
- // `is-narrow` modifier classes set from the media editor. Wide is a single
26
- // flex row; medium and narrow stack via `flex-direction: column`. Each
27
- // layout has its own JSX tree (not `order` reshuffling, which the project's
28
- // stylelint rule treats as an a11y red flag), so DOM order always matches
29
- // visual order.
24
+ // Footer chrome — two layouts driven by `is-wide` / `is-narrow` modifier
25
+ // classes set from the media editor at the sidebar-collapse breakpoint.
26
+ // Wide is a single flex row (History | Cancel/Save); narrow stacks via
27
+ // `flex-direction: column` (image controls above the History |
28
+ // Cancel/Save row). Each layout has its own JSX tree (not `order`
29
+ // reshuffling, which the project's stylelint rule treats as an a11y red
30
+ // flag), so DOM order always matches visual order.
30
31
  .media-editor-modal.components-modal__frame .media-editor-modal__footer {
31
32
  flex-shrink: 0;
32
33
  display: flex;
33
34
  gap: $grid-unit-20;
34
- padding: $grid-unit-10 $grid-unit-30;
35
- border-top: $border-width solid $gray-300;
35
+ // Borderless: sections are demarcated by the inset canvas panel and
36
+ // spacing, not divider lines. 16px top / 32px sides / 24px bottom.
37
+ padding: $grid-unit-20 $grid-unit-40 $grid-unit-30;
36
38
  background: $white;
39
+ // Above the `.interface-interface-skeleton__sidebar` which has a z-index of 100000.
40
+ z-index: z-index(".media-editor-modal__footer");
37
41
 
38
42
  &.is-wide {
39
43
  flex-direction: row;
40
44
  align-items: center;
41
45
 
42
- // Wide-only wrapper: ruler + transform controls are grouped
43
- // together, centered between History and Cancel/Save with a
44
- // divider rule between them — preserving the long-standing
45
- // wide-desktop look.
46
- .media-editor-modal__footer-toolbar {
47
- flex: 1 1 0;
48
- min-width: 0;
49
- display: flex;
50
- align-items: center;
51
- justify-content: center;
52
- gap: $grid-unit-10;
53
- }
54
-
55
- .media-editor-fine-rotation {
56
- flex: 1 1 280px;
57
- min-width: 0;
58
- max-width: 360px;
59
- }
60
-
61
- .media-editor-transform-controls {
62
- border-left: $border-width solid $gray-300;
63
- padding-left: $grid-unit-15;
64
- }
65
-
66
- // `margin-left: auto` guarantees right alignment whether or not
67
- // History / the toolbar is rendered (handles non-image
68
- // attachments where only `FooterActions` is present).
46
+ // Panel mode: the footer holds only History (left) and
47
+ // Cancel/Save (right). `margin-left: auto` pins the actions to the
48
+ // right edge whether or not History renders (e.g. non-image
49
+ // attachments show only `FooterActions`).
69
50
  .media-editor__footer-actions {
70
51
  margin-left: auto;
71
52
  }
72
53
  }
73
54
 
74
- &.is-medium,
75
55
  &.is-narrow {
76
56
  flex-direction: column;
77
57
  }
78
58
 
79
- // Narrow only: transform cluster sits on its own row, centered.
80
- &.is-narrow > .media-editor-transform-controls {
59
+ // Narrow only: image controls sit on their own row, centered.
60
+ &.is-narrow > .media-editor-image-controls {
81
61
  align-self: center;
82
62
  }
83
63
  }
84
64
 
85
- // Secondary row used by medium (History + Transform + Cancel/Save) and
86
- // narrow (History + Cancel/Save). `margin-left: auto` on the transform
65
+ // Secondary row used by medium (History + Image controls + Cancel/Save) and
66
+ // narrow (History + Cancel/Save). `margin-left: auto` on the image controls
87
67
  // cluster and on Cancel/Save splits any free space — History gets the
88
- // left edge, Cancel/Save the right edge, and the transform cluster (when
68
+ // left edge, Cancel/Save the right edge, and the image controls (when
89
69
  // present, i.e. medium only) approximately centers. Exact centering only
90
70
  // holds when History and Cancel/Save have matching widths; in practice
91
71
  // they're close enough that the offset is imperceptible.
@@ -95,12 +75,22 @@
95
75
  align-items: center;
96
76
  gap: $grid-unit-20;
97
77
 
98
- .media-editor-transform-controls,
78
+ .media-editor-image-controls,
99
79
  .media-editor__footer-actions {
100
80
  margin-left: auto;
101
81
  }
102
82
  }
103
83
 
84
+ // Active (enabled) undo/redo icon buttons take the admin accent colour so
85
+ // they read as live alongside the Reset/Cancel/Save actions. Disabled
86
+ // buttons (rendered with `aria-disabled` via `accessibleWhenDisabled`)
87
+ // keep the default muted icon colour.
88
+ // NOTE: overrides @wordpress/components Button internals (`.components-button`,
89
+ // `.has-icon`), scoped to our history-actions wrapper. Update if renamed.
90
+ .media-editor__history-actions .components-button.has-icon:not([aria-disabled="true"]) {
91
+ color: var(--wp-admin-theme-color);
92
+ }
93
+
104
94
  .media-editor-modal {
105
95
  display: flex;
106
96
  flex-direction: column;
@@ -6,7 +6,6 @@ import type { Form, Field } from '@wordpress/dataviews';
6
6
  import { Spinner, __experimentalVStack as VStack } from '@wordpress/components';
7
7
  import { VisuallyHidden } from '@wordpress/ui';
8
8
  import { __ } from '@wordpress/i18n';
9
- import { useMemo } from '@wordpress/element';
10
9
  import type { ReactNode } from 'react';
11
10
 
12
11
  /**
@@ -14,7 +13,6 @@ import type { ReactNode } from 'react';
14
13
  */
15
14
  import { useMediaEditorContext } from '../media-editor-provider';
16
15
  import type { Media } from '../media-editor-provider';
17
- import SidebarDatetimeView from './sidebar-datetime-view';
18
16
 
19
17
  /**
20
18
  * Props for MediaForm component.
@@ -41,18 +39,6 @@ export default function MediaForm( {
41
39
  }: MediaFormProps ) {
42
40
  const { media, fields, onChange } = useMediaEditorContext();
43
41
 
44
- // Render readonly datetime fields compactly in the sidebar: date only,
45
- // with the full datetime exposed on hover via Tooltip and `title`.
46
- const formFields = useMemo(
47
- () =>
48
- fields.map( ( field: Field< Media > ) =>
49
- field.type === 'datetime' && field.readOnly
50
- ? { ...field, render: SidebarDatetimeView }
51
- : field
52
- ),
53
- [ fields ]
54
- );
55
-
56
42
  if ( ! media || ! onChange ) {
57
43
  return (
58
44
  <div className="media-editor-form media-editor-form--loading">
@@ -61,18 +47,28 @@ export default function MediaForm( {
61
47
  );
62
48
  }
63
49
 
50
+ // Fields that use a regular (non-panel) layout, rendered at the top.
51
+ const regularFieldIds = [ 'title', 'alt_text', 'caption', 'description' ];
52
+
53
+ // Place the non-panel (regular layout) fields at the top of the array,
54
+ // with the remaining panel fields below.
55
+ const sortedFields = [
56
+ ...fields.filter( ( field: Field< Media > ) =>
57
+ regularFieldIds.includes( field.id )
58
+ ),
59
+ ...fields.filter(
60
+ ( field: Field< Media > ) => ! regularFieldIds.includes( field.id )
61
+ ),
62
+ ];
63
+
64
64
  // Default form structure with panel layout
65
65
  const defaultForm: Form = {
66
66
  layout: {
67
67
  type: 'panel',
68
68
  },
69
- fields: fields.map( ( field: Field< Media > ) => {
69
+ fields: sortedFields.map( ( field: Field< Media > ) => {
70
70
  // Use regular layout for main editable fields
71
- if (
72
- [ 'title', 'alt_text', 'caption', 'description' ].includes(
73
- field.id
74
- )
75
- ) {
71
+ if ( regularFieldIds.includes( field.id ) ) {
76
72
  return {
77
73
  id: field.id,
78
74
  layout: {
@@ -96,7 +92,7 @@ export default function MediaForm( {
96
92
  { header }
97
93
  <DataForm
98
94
  data={ media }
99
- fields={ formFields }
95
+ fields={ fields }
100
96
  form={ form }
101
97
  onChange={ onChange }
102
98
  />
@@ -0,0 +1,6 @@
1
+ // Discourage an orphaned "am/pm" (or other single-word widow) when a read-only
2
+ // value wraps in the narrow Details panel. Progressive enhancement: browsers
3
+ // without `text-wrap: pretty` simply wrap normally.
4
+ .media-editor-form .dataforms-layouts-panel__field-control {
5
+ text-wrap: pretty;
6
+ }
@@ -80,6 +80,12 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
80
80
 
81
81
  .rotation-ruler__ticks {
82
82
  position: absolute;
83
+ // The tick offset is applied as a JS-set inline `transform: translateX()`
84
+ // (see rotation-ruler/index.tsx), which rtlcss can't mirror. If rtlcss
85
+ // flipped this `left` to `right`, the anchor and the transform would
86
+ // disagree and the ticks would render off-screen in RTL. Keep it `left`
87
+ // so the two stay in sync; the strip is a symmetric number line anyway.
88
+ /*rtl:ignore*/
83
89
  left: 50%;
84
90
  top: 0;
85
91
  display: block;
@@ -118,8 +124,9 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
118
124
  // pointer while the SVG behind it transitions smoothly. The label box
119
125
  // is sized to the number alone — the unit is positioned absolutely so
120
126
  // it does not influence centering — and a fixed-width ::before
121
- // pseudo-element provides the white-fading-to-transparent mask that
122
- // occludes the static labels directly behind.
127
+ // pseudo-element provides the grey-fading-to-transparent mask (matching
128
+ // the canvas/ruler surface) that occludes the static labels directly
129
+ // behind.
123
130
  .rotation-ruler__active-label {
124
131
  position: absolute;
125
132
  top: 0;
@@ -140,7 +147,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
140
147
  width: 60px;
141
148
  height: 100%;
142
149
  transform: translateX(-50%);
143
- background: linear-gradient(to right, transparent 0, $white 12px, $white calc(100% - 12px), transparent 100%);
150
+ background: linear-gradient(to right, transparent 0, $gray-200 12px, $gray-200 calc(100% - 12px), transparent 100%);
144
151
  }
145
152
  }
146
153