@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
@@ -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 *;
@@ -28,18 +29,64 @@
28
29
  flex-direction: column;
29
30
  }
30
31
 
32
+ // The skeleton must always sit in the modal's flow (`top: auto`). The reset
33
+ // above sets that, but external rules can outrank its low specificity — e.g.
34
+ // the "Omnipresent Toolbar" experiment (`gutenberg-omnibar`)
35
+ // offsets every `.interface-interface-skeleton` below the admin bar via a
36
+ // `body.has-admin-bar-in-editor.is-fullscreen-mode` rule, which would push
37
+ // the editor (and the fine-rotation ruler under the canvas) down inside our
38
+ // full-screen modal that already overlays the admin bar. Re-assert `top` at a
39
+ // specificity that beats such rules, anchored on the modal frame
40
+ // (`.media-editor` only ever renders inside `.media-editor-modal`) rather
41
+ // than on the experiment's class, which may change if it ever graduates.
42
+ .media-editor-modal & .interface-interface-skeleton.interface-interface-skeleton {
43
+ top: auto;
44
+ }
45
+
31
46
  .interface-interface-skeleton__editor {
32
47
  min-width: 0;
33
48
  flex: 1;
34
49
  }
35
50
 
36
- .media-editor__canvas {
51
+ // Canvas column: image fills the available height; in panel mode the
52
+ // fine-rotation ruler sits directly beneath it.
53
+ .media-editor__content {
54
+ display: flex;
55
+ flex: 1;
56
+ flex-direction: column;
57
+ min-height: 0;
58
+ // Inset the canvas + fine-rotation ruler as one rounded grey panel
59
+ // with a horizontal-only gutter. The ruler is always a child here
60
+ // (never the footer), so the two share a container and the panel is
61
+ // fully rounded at every viewport.
62
+ margin: 0 $grid-unit-30;
63
+ border-radius: $radius-large;
64
+ overflow: hidden;
65
+ }
66
+
67
+ .media-editor__canvas-toolbar {
68
+ display: flex;
69
+ flex-shrink: 0;
70
+ justify-content: center;
71
+ // Share the canvas grey so the ruler strip blends into the same
72
+ // surface as the area around the image.
73
+ background: $gray-200;
74
+ padding: $grid-unit-10 $grid-unit-20;
75
+
76
+ .media-editor-fine-rotation {
77
+ flex: 0 1 360px;
78
+ min-width: 0;
79
+ }
80
+ }
81
+
82
+ .media-editor__canvas-area {
37
83
  display: flex;
38
84
  align-items: center;
39
85
  justify-content: center;
40
- background: $gray-100;
86
+ background: $gray-200;
41
87
  overflow: auto;
42
- height: 100%;
88
+ flex: 1;
89
+ min-height: 0;
43
90
 
44
91
  .media-editor-preview {
45
92
  height: 100%;
@@ -55,24 +102,109 @@
55
102
 
56
103
  .media-editor__sidebar {
57
104
  @include reset;
105
+
106
+ // Small left gutter so the tabs and panel content (and the zoom
107
+ // slider's thumb at its minimum) sit off the sidebar edge.
108
+ @include break-small() {
109
+ padding-left: 1px;
110
+ }
58
111
  }
59
112
 
113
+ .media-editor__sidebar-panel {
114
+ padding-bottom: $grid-unit-30;
115
+ }
116
+
117
+ // Borderless controls panel: clear the InterfaceSkeleton sidebar's
118
+ // default top border, left box-shadow, and high-contrast outline so the
119
+ // panel sits flush with no divider lines.
120
+ // NOTE: overrides @wordpress/interface internals. The sidebar region has
121
+ // no className prop, so this targets `interface-interface-skeleton__sidebar`
122
+ // directly — update here if that class is renamed upstream.
123
+ .interface-interface-skeleton__sidebar {
124
+ border-top: 0;
125
+ box-shadow: none;
126
+ outline: 1px solid transparent;
127
+ }
128
+
129
+ // Below `small` the sidebar is a full-width overlay, so the panel carries
130
+ // its own all-around gutter. From `small` up it's the right-hand column and
131
+ // drops its left/bottom padding (the sidebar supplies the left gutter).
60
132
  .media-editor__panel {
61
133
  padding: $grid-unit-20;
134
+
135
+ @include break-small() {
136
+ padding: $grid-unit-20 $grid-unit-30 0 0;
137
+ }
62
138
  }
63
139
 
140
+ // NOTE: overrides @wordpress/components Panel/Button internals to align
141
+ // the sidebar header (tabs + close button). Targets their classes
142
+ // directly; update here if they are renamed upstream.
64
143
  .components-panel__header.media-editor__sidebar-header {
65
144
  padding-left: 0;
66
145
  padding-right: $grid-unit-10;
146
+ margin-right: $grid-unit-30;
147
+ margin-right: 0;
67
148
 
149
+ // When the sidebar is not a full page column, we offset the header to match the overall gutter.
150
+ @include break-small() {
151
+ margin-right: $grid-unit-30;
152
+ }
68
153
  .components-button.has-icon {
69
154
  padding: 0;
70
155
 
71
- @include break-medium() {
156
+ @include break-small() {
72
157
  display: flex;
73
158
  }
74
159
  }
75
160
  }
161
+
162
+ // `ComplementaryArea`'s "mobile" mode is hard-coded to the `medium`
163
+ // breakpoint: below 782px it renders an animated fill wrapper and writes
164
+ // `width: 100vw` inline on both it and the inner panel. We want the sidebar
165
+ // to mirror InterfaceSkeleton's column/overlay collapse but shifted to
166
+ // `small`, so we override that inline width by breakpoint (`!important` is
167
+ // the only way to beat an inline style). `:has(__fill)` scopes the changes
168
+ // to when the panel is actually open: the skeleton sidebar wrapper is always
169
+ // present (empty when closed), so touching it unconditionally would paint an
170
+ // empty box over the canvas.
171
+
172
+ // Column (small–medium): between 600px and 782px `ComplementaryArea` is
173
+ // still in its mobile mode (inline `100vw`, see above) and the skeleton
174
+ // sidebar is absolutely positioned, so pull the open panel back in-flow at
175
+ // the sidebar width to sit it beside the canvas as a column.
176
+ //
177
+ // Bounded *below* the medium breakpoint on purpose. From 782px up,
178
+ // `InterfaceSkeleton` already makes the sidebar a `position: relative`,
179
+ // `width: auto` column and `ComplementaryArea` animates its width to
180
+ // `$sidebar-width` — exactly like the main editor. Pinning the width with
181
+ // `!important` there would freeze that open/close tween (the panel would
182
+ // sit mounted and unchanged for the animation's duration, then pop in or
183
+ // out), so we leave it to the skeleton. Below 782px there's nothing to
184
+ // freeze: `ComplementaryArea` zeroes the animation duration in mobile mode.
185
+ @media (min-width: #{ breakpoints.$break-small }) and (max-width: #{ (breakpoints.$break-medium - 1) }) {
186
+ .interface-interface-skeleton__sidebar:has(.interface-complementary-area__fill) {
187
+ position: relative !important;
188
+ }
189
+
190
+ .interface-complementary-area__fill,
191
+ .interface-complementary-area {
192
+ width: $sidebar-width !important;
193
+ }
194
+ }
195
+
196
+ // Overlay (< small): the open panel fills the modal width (it would
197
+ // otherwise shrink-wrap, since the inline `100vw` is overridden below).
198
+ @media (max-width: #{ (breakpoints.$break-small - 1) }) {
199
+ .interface-interface-skeleton__sidebar:has(.interface-complementary-area__fill) {
200
+ width: 100%;
201
+ }
202
+
203
+ .interface-complementary-area__fill,
204
+ .interface-complementary-area {
205
+ width: 100% !important;
206
+ }
207
+ }
76
208
  }
77
209
 
78
210
  .media-editor__snackbar {
@@ -1,7 +1,14 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import clsx from 'clsx';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
- import { useCallback, useEffect, useMemo } from '@wordpress/element';
9
+ import { useCallback, useEffect, useMemo, useState } from '@wordpress/element';
10
+ import { Spinner } from '@wordpress/components';
11
+ import { __ } from '@wordpress/i18n';
5
12
 
6
13
  /**
7
14
  * Internal dependencies
@@ -48,6 +55,13 @@ export default function MediaEditorCanvas( {
48
55
  const cropperImage = controller.state.image;
49
56
  const { beginGesture, endGesture, setImage } = controller;
50
57
 
58
+ // Tracks whether the image pixels have actually loaded. The cropper's
59
+ // geometry is driven by the known media dimensions, so its handles and
60
+ // overlays would otherwise appear before the image finishes streaming in.
61
+ const [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(
62
+ 'loading'
63
+ );
64
+
51
65
  // Resolved aspect ratio is derived from the preset key + the
52
66
  // loaded image (for the "Original" preset). The reducer doesn't
53
67
  // store this number — only the preset key — so it's a render-time
@@ -90,23 +104,78 @@ export default function MediaEditorCanvas( {
90
104
  } );
91
105
  }, [ cropperImage, mediaUrl, mediaWidth, mediaHeight, setImage ] );
92
106
 
93
- if ( ! mediaUrl || mediaType.type !== 'image' ) {
107
+ const isImage = mediaType.type === 'image';
108
+
109
+ // Probe the image to know when its pixels have loaded (or failed),
110
+ // independent of the cropper. The browser shares one fetch/cache with the
111
+ // cropper's own `<img>`, so this adds no network cost. The cropper stays
112
+ // framework-pure — load/error handling lives here in the wrapper layer.
113
+ useEffect( () => {
114
+ if ( ! mediaUrl || ! isImage ) {
115
+ return;
116
+ }
117
+ setStatus( 'loading' );
118
+ const probe = new window.Image();
119
+ probe.onload = () => setStatus( 'loaded' );
120
+ probe.onerror = () => setStatus( 'error' );
121
+ probe.src = mediaUrl;
122
+ // Cached images may already be complete before listeners attach.
123
+ if ( probe.complete ) {
124
+ setStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );
125
+ }
126
+ return () => {
127
+ probe.onload = null;
128
+ probe.onerror = null;
129
+ };
130
+ }, [ mediaUrl, isImage ] );
131
+
132
+ if ( ! mediaUrl || ! isImage ) {
94
133
  return null;
95
134
  }
96
135
 
136
+ if ( status === 'error' ) {
137
+ return (
138
+ <div className="media-editor-canvas">
139
+ <div className="media-editor-canvas__error" role="alert">
140
+ <p>{ __( 'Failed to load image.' ) }</p>
141
+ </div>
142
+ </div>
143
+ );
144
+ }
145
+
97
146
  return (
98
147
  <div className="media-editor-canvas">
99
- <Cropper
100
- src={ mediaUrl }
101
- controller={ controller }
102
- aspectRatio={ aspectRatio }
103
- freeformCrop
104
- focusOnMount={ focusOnMount }
105
- showGrid="interactive"
106
- isPlacementActive={ isPlacementActive }
107
- onGestureStart={ handleGestureStart }
108
- onGestureEnd={ handleGestureEnd }
109
- />
148
+ { status === 'loading' && (
149
+ <div className="media-editor-canvas__spinner">
150
+ <Spinner />
151
+ </div>
152
+ ) }
153
+ { /*
154
+ * The cropper stays mounted while loading (hidden behind the
155
+ * spinner) so the image decodes off-screen and reveals in one paint
156
+ * instead of streaming in top-to-bottom. Until it's revealed it's
157
+ * non-interactive (`pointer-events: none` in CSS), and focus is
158
+ * withheld by gating `focusOnMount` on the loaded state — the
159
+ * cropper's focus effect keys off that prop, so focus lands on the
160
+ * crop area only once it's visible.
161
+ */ }
162
+ <div
163
+ className={ clsx( 'media-editor-canvas__cropper', {
164
+ 'is-loaded': status === 'loaded',
165
+ } ) }
166
+ >
167
+ <Cropper
168
+ src={ mediaUrl }
169
+ controller={ controller }
170
+ aspectRatio={ aspectRatio }
171
+ freeformCrop
172
+ focusOnMount={ focusOnMount && status === 'loaded' }
173
+ showGrid="interactive"
174
+ isPlacementActive={ isPlacementActive }
175
+ onGestureStart={ handleGestureStart }
176
+ onGestureEnd={ handleGestureEnd }
177
+ />
178
+ </div>
110
179
  </div>
111
180
  );
112
181
  }
@@ -1,3 +1,6 @@
1
+ @use "@wordpress/base-styles/animations" as *;
2
+ @use "@wordpress/base-styles/colors" as *;
3
+
1
4
  // The canvas wrapper fills the modal's canvas area so the cropper has a
2
5
  // sized parent (the cropper uses 100% width/height of its container).
3
6
  // `position: relative` establishes a stacking context for any future
@@ -6,4 +9,42 @@
6
9
  position: relative;
7
10
  width: 100%;
8
11
  height: 100%;
12
+
13
+ // The cropper stays mounted while loading so the image decodes behind the
14
+ // spinner and reveals in one paint. It's hidden and non-interactive until
15
+ // the image has loaded, then fades in.
16
+ &__cropper {
17
+ width: 100%;
18
+ height: 100%;
19
+ opacity: 0;
20
+ pointer-events: none;
21
+
22
+ // Explicit `opacity: 1` (not just the animation's fill mode) keeps the
23
+ // cropper visible for reduced-motion users, since `animation__fade-in`
24
+ // is gated behind `@media not (prefers-reduced-motion)`.
25
+ &.is-loaded {
26
+ opacity: 1;
27
+ pointer-events: auto;
28
+ @include animation__fade-in( 0.2s );
29
+ }
30
+ }
31
+
32
+ &__spinner {
33
+ position: absolute;
34
+ top: 50%;
35
+ left: 50%;
36
+ transform: translate(-50%, -50%);
37
+ }
38
+
39
+ // Centered fallback shown in place of the cropper when the image
40
+ // fails to load.
41
+ &__error {
42
+ display: flex;
43
+ align-items: center;
44
+ justify-content: center;
45
+ width: 100%;
46
+ height: 100%;
47
+ color: $gray-700;
48
+ text-align: center;
49
+ }
9
50
  }
@@ -1,33 +1,17 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { RangeControl, SelectControl } from '@wordpress/components';
4
+ import { SelectControl } from '@wordpress/components';
5
5
  import { Stack, VisuallyHidden } from '@wordpress/ui';
6
- import { __, sprintf } from '@wordpress/i18n';
6
+ import { __ } from '@wordpress/i18n';
7
7
 
8
8
  /**
9
9
  * Internal dependencies
10
10
  */
11
- import { useMediaEditor } from '../../state';
12
- import {
13
- useCropGestureHandlers,
14
- CROP_CONTROL_ATTR,
15
- } from '../../hooks/use-crop-gesture-handlers';
16
- import { MAX_ZOOM } from '../../image-editor/core/constants';
17
- import { getMinZoom } from '../../image-editor/core/containment';
11
+ import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
12
+ import MediaEditorImageControls from '../media-editor-image-controls';
18
13
  import type { AspectRatioPreset } from '../../image-editor/core/constants';
19
14
 
20
- const ZOOM_PERCENTAGE_SCALE = 100;
21
- const MAX_ZOOM_PERCENTAGE = MAX_ZOOM * ZOOM_PERCENTAGE_SCALE;
22
-
23
- function getZoomPercentageForDisplay( zoom: number ): number {
24
- return Math.round( zoom * ZOOM_PERCENTAGE_SCALE );
25
- }
26
-
27
- function getMinZoomPercentageForDisplay( zoom: number ): number {
28
- return Math.ceil( zoom * ZOOM_PERCENTAGE_SCALE );
29
- }
30
-
31
15
  export interface MediaEditorCropPanelProps {
32
16
  /**
33
17
  * Selected aspect-ratio preset value as a string (so it round-trips
@@ -37,33 +21,32 @@ export interface MediaEditorCropPanelProps {
37
21
  aspectRatioValue: string;
38
22
  /** Setter for the aspect-ratio preset value. */
39
23
  onAspectRatioChange: ( value: string ) => void;
40
- /** Signal that a placement-oriented control is being adjusted. */
41
- onPlacementControlInteraction?: () => void;
42
24
  /** Aspect-ratio presets to display in the selector. */
43
25
  aspectRatioOptions: AspectRatioPreset[];
26
+ /**
27
+ * When `true`, render the rotate/flip/zoom image controls at the top of
28
+ * the panel. Used on wide viewports where the footer no longer carries
29
+ * them.
30
+ */
31
+ showTransformControls?: boolean;
44
32
  }
45
33
 
46
34
  /**
47
- * Sidebar panel for crop-shape controls. The tactile verbs (rotate, flip)
48
- * live in the bottom toolbar instead.
35
+ * Sidebar panel for crop controls. Renders the aspect-ratio selector, plus the
36
+ * rotate/flip and zoom controls on wide viewports (these move to the footer
37
+ * toolbar when the sidebar collapses).
49
38
  * @param props
50
39
  * @param props.aspectRatioValue
51
40
  * @param props.onAspectRatioChange
52
- * @param props.onPlacementControlInteraction
53
41
  * @param props.aspectRatioOptions
42
+ * @param props.showTransformControls
54
43
  */
55
44
  export default function MediaEditorCropPanel( {
56
45
  aspectRatioValue,
57
46
  onAspectRatioChange,
58
- onPlacementControlInteraction,
59
47
  aspectRatioOptions,
48
+ showTransformControls = false,
60
49
  }: MediaEditorCropPanelProps ) {
61
- const { state, setZoom } = useMediaEditor();
62
- const zoomGestureHandlers = useCropGestureHandlers();
63
- const minZoom = getMinZoom( state );
64
- const zoomPercentage = getZoomPercentageForDisplay( state.zoom );
65
- const minZoomPercentage = getMinZoomPercentageForDisplay( minZoom );
66
-
67
50
  return (
68
51
  // Tag the whole panel as a crop-control region so the modal's
69
52
  // Cmd+Z handler doesn't mistake the SelectControl input for a
@@ -76,6 +59,7 @@ export default function MediaEditorCropPanel( {
76
59
  <VisuallyHidden render={ <h2 /> }>
77
60
  { __( 'Crop options' ) }
78
61
  </VisuallyHidden>
62
+ { showTransformControls && <MediaEditorImageControls withLabels /> }
79
63
  <SelectControl
80
64
  __next40pxDefaultSize
81
65
  label={ __( 'Aspect ratio' ) }
@@ -86,36 +70,6 @@ export default function MediaEditorCropPanel( {
86
70
  value: preset.value.toString(),
87
71
  } ) ) }
88
72
  />
89
- <div role="presentation" { ...zoomGestureHandlers }>
90
- <RangeControl
91
- __next40pxDefaultSize
92
- label={ __( 'Zoom (%)' ) }
93
- min={ minZoomPercentage }
94
- max={ MAX_ZOOM_PERCENTAGE }
95
- step={ 1 }
96
- shiftStep={ 10 }
97
- value={ zoomPercentage }
98
- onChange={ ( value ) => {
99
- onPlacementControlInteraction?.();
100
- setZoom(
101
- typeof value === 'number'
102
- ? value / ZOOM_PERCENTAGE_SCALE
103
- : minZoom
104
- );
105
- } }
106
- renderTooltipContent={ ( value ) => {
107
- const percentage =
108
- typeof value === 'number'
109
- ? value
110
- : minZoomPercentage;
111
- return sprintf(
112
- /* translators: %d: zoom level as a percentage. */
113
- __( '%d%%' ),
114
- Math.round( percentage )
115
- );
116
- } }
117
- />
118
- </div>
119
73
  </Stack>
120
74
  );
121
75
  }
@@ -8,7 +8,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
8
8
  */
9
9
  import MediaEditorCropPanel from '..';
10
10
  import type { MediaEditorCropPanelProps } from '..';
11
- import { MediaEditorStateProvider, useMediaEditor } from '../../../state';
11
+ import { MediaEditorStateProvider } from '../../../state';
12
12
  import type { CropperState } from '../../../image-editor';
13
13
 
14
14
  function setupCropPanel(
@@ -29,31 +29,13 @@ function setupCropPanel(
29
29
  render(
30
30
  <MediaEditorStateProvider initialCropperState={ initialCropperState }>
31
31
  <MediaEditorCropPanel { ...props } />
32
- <CurrentZoomValue />
33
32
  </MediaEditorStateProvider>
34
33
  );
35
34
 
36
35
  return props;
37
36
  }
38
37
 
39
- function CurrentZoomValue() {
40
- const { state } = useMediaEditor();
41
-
42
- return <output data-testid="current-zoom">{ state.zoom }</output>;
43
- }
44
-
45
38
  describe( 'MediaEditorCropPanel', () => {
46
- it( 'renders crop shape controls before zoom controls', () => {
47
- setupCropPanel();
48
-
49
- const aspectRatio = screen.getByLabelText( 'Aspect ratio' );
50
- const zoom = screen.getByRole( 'slider', { name: 'Zoom (%)' } );
51
-
52
- expect( aspectRatio.compareDocumentPosition( zoom ) ).toBe(
53
- Node.DOCUMENT_POSITION_FOLLOWING
54
- );
55
- } );
56
-
57
39
  it( 'passes selected aspect ratio changes to the caller', () => {
58
40
  const controls = setupCropPanel( {
59
41
  aspectRatioValue: '1',
@@ -69,34 +51,36 @@ describe( 'MediaEditorCropPanel', () => {
69
51
  ).toBe( '0' );
70
52
  } );
71
53
 
72
- it( 'displays zoom as a percentage without changing cropper state', () => {
73
- setupCropPanel( {}, { zoom: 3.749999999999999 } );
54
+ it( 'omits the image controls by default', () => {
55
+ setupCropPanel();
74
56
 
75
- const zoomInput = screen.getByRole( 'spinbutton', {
76
- name: 'Zoom (%)',
77
- } );
57
+ expect( screen.queryByText( 'Rotate' ) ).not.toBeInTheDocument();
58
+ expect( screen.queryByText( 'Flip' ) ).not.toBeInTheDocument();
59
+ expect( screen.queryByText( 'Zoom' ) ).not.toBeInTheDocument();
60
+ } );
78
61
 
79
- expect( zoomInput ).toHaveValue( 375 );
80
- expect( screen.getByTestId( 'current-zoom' ) ).toHaveTextContent(
81
- '3.749999999999999'
82
- );
62
+ it( 'renders rotate, flip and zoom controls when showTransformControls is set', () => {
63
+ setupCropPanel( { showTransformControls: true } );
64
+
65
+ expect( screen.getByText( 'Rotate' ) ).toBeInTheDocument();
66
+ expect( screen.getByText( 'Flip' ) ).toBeInTheDocument();
67
+ expect( screen.getByText( 'Zoom' ) ).toBeInTheDocument();
68
+ expect(
69
+ screen.getByRole( 'button', { name: 'Rotate 90° clockwise' } )
70
+ ).toBeInTheDocument();
71
+ expect(
72
+ screen.getByRole( 'button', { name: 'Zoom in' } )
73
+ ).toBeInTheDocument();
83
74
  } );
84
75
 
85
- it( 'converts percentage input back to the cropper zoom multiplier', () => {
86
- const controls = setupCropPanel( {
87
- onPlacementControlInteraction: jest.fn(),
88
- } );
76
+ it( 'renders the image controls above the aspect-ratio selector', () => {
77
+ setupCropPanel( { showTransformControls: true } );
89
78
 
90
- fireEvent.change(
91
- screen.getByRole( 'spinbutton', { name: 'Zoom (%)' } ),
92
- {
93
- target: { value: '250' },
94
- }
95
- );
79
+ const rotate = screen.getByText( 'Rotate' );
80
+ const aspectRatio = screen.getByLabelText( 'Aspect ratio' );
96
81
 
97
- expect( screen.getByTestId( 'current-zoom' ) ).toHaveTextContent(
98
- '2.5'
82
+ expect( rotate.compareDocumentPosition( aspectRatio ) ).toBe(
83
+ Node.DOCUMENT_POSITION_FOLLOWING
99
84
  );
100
- expect( controls.onPlacementControlInteraction ).toHaveBeenCalled();
101
85
  } );
102
86
  } );
@@ -17,9 +17,10 @@ export interface MediaEditorFineRotationProps {
17
17
  }
18
18
 
19
19
  /**
20
- * Fine-rotation slider for the media-editor footer. Lives separately from
21
- * the snap-rotate / flip buttons so the footer can place the two halves on
22
- * different rows at intermediate viewport widths.
20
+ * Fine-rotation slider for the media editor. It renders under the canvas so it
21
+ * stays constrained to the canvas column at all viewport sizes. Lives
22
+ * separately from the snap-rotate / flip buttons so the two can be placed
23
+ * independently per viewport.
23
24
  *
24
25
  * @param props
25
26
  * @param props.onPlacementControlInteraction