@wordpress/media-editor 0.21.0 → 0.22.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 (339) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/components/media-editor/index.cjs +533 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +43 -57
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  6. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +122 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +65 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +183 -257
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  19. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  20. package/build/components/media-editor-modal/index.cjs +112 -155
  21. package/build/components/media-editor-modal/index.cjs.map +1 -7
  22. package/build/components/media-editor-provider/index.cjs +32 -55
  23. package/build/components/media-editor-provider/index.cjs.map +1 -7
  24. package/build/components/media-form/index.cjs +76 -77
  25. package/build/components/media-form/index.cjs.map +1 -7
  26. package/build/components/media-preview/index.cjs +114 -114
  27. package/build/components/media-preview/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/index.cjs +181 -188
  29. package/build/components/rotation-ruler/index.cjs.map +1 -7
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  32. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  33. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  34. package/build/image-editor/core/camera.cjs +257 -205
  35. package/build/image-editor/core/camera.cjs.map +1 -7
  36. package/build/image-editor/core/constants.cjs +127 -102
  37. package/build/image-editor/core/constants.cjs.map +1 -7
  38. package/build/image-editor/core/containment.cjs +275 -262
  39. package/build/image-editor/core/containment.cjs.map +1 -7
  40. package/build/image-editor/core/crop-rect.cjs +33 -44
  41. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  42. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  43. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  44. package/build/image-editor/core/index.cjs +88 -61
  45. package/build/image-editor/core/interaction-controller.cjs +583 -646
  46. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  47. package/build/image-editor/core/math/rotation.cjs +26 -35
  48. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  49. package/build/image-editor/core/math/sanitize.cjs +124 -80
  50. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  51. package/build/image-editor/core/setter-helpers.cjs +57 -60
  52. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  53. package/build/image-editor/core/source-region.cjs +220 -190
  54. package/build/image-editor/core/source-region.cjs.map +1 -7
  55. package/build/image-editor/core/state.cjs +278 -265
  56. package/build/image-editor/core/state.cjs.map +1 -7
  57. package/build/image-editor/core/stencil-math.cjs +193 -206
  58. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  59. package/build/image-editor/core/transform-style.cjs +39 -48
  60. package/build/image-editor/core/transform-style.cjs.map +1 -7
  61. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  62. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  63. package/build/image-editor/core/types.cjs +4 -18
  64. package/build/image-editor/core/viewport-state.cjs +31 -45
  65. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  66. package/build/image-editor/index.cjs +65 -64
  67. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  68. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  69. package/build/image-editor/react/components/cropper.cjs +583 -710
  70. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  71. package/build/image-editor/react/components/index.cjs +22 -33
  72. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  74. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  76. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  78. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  80. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  81. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  82. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  84. package/build/image-editor/react/hooks/index.cjs +16 -31
  85. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  87. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  89. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  90. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  91. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  92. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  93. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  95. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  96. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  97. package/build/index.cjs +45 -39
  98. package/build/lock-unlock.cjs +9 -35
  99. package/build/lock-unlock.cjs.map +1 -7
  100. package/build/private-apis.cjs +16 -37
  101. package/build/private-apis.cjs.map +1 -7
  102. package/build/state/aspect-ratio-presets.cjs +53 -0
  103. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  104. package/build/state/composite-reducer.cjs +134 -112
  105. package/build/state/composite-reducer.cjs.map +1 -7
  106. package/build/state/index.cjs +63 -47
  107. package/build/state/media-editor-state-provider.cjs +35 -48
  108. package/build/state/media-editor-state-provider.cjs.map +1 -7
  109. package/build/state/types.cjs +12 -31
  110. package/build/state/types.cjs.map +1 -7
  111. package/build/state/use-media-editor-state.cjs +261 -294
  112. package/build/state/use-media-editor-state.cjs.map +1 -7
  113. package/build/store/actions.cjs +17 -44
  114. package/build/store/actions.cjs.map +1 -7
  115. package/build/store/constants.cjs +8 -29
  116. package/build/store/constants.cjs.map +1 -7
  117. package/build/store/index.cjs +33 -40
  118. package/build/store/index.cjs.map +1 -7
  119. package/build/store/reducer.cjs +28 -50
  120. package/build/store/reducer.cjs.map +1 -7
  121. package/build/store/selectors.cjs +16 -41
  122. package/build/store/selectors.cjs.map +1 -7
  123. package/build/utils/get-media-type.cjs +18 -41
  124. package/build/utils/get-media-type.cjs.map +1 -7
  125. package/build/utils/index.cjs +9 -28
  126. package/build-module/components/media-editor/index.mjs +490 -673
  127. package/build-module/components/media-editor/index.mjs.map +1 -7
  128. package/build-module/components/media-editor/use-crop-options.mjs +38 -32
  129. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  130. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  131. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  132. package/build-module/components/media-editor-canvas/index.mjs +98 -96
  133. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  134. package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
  135. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  136. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  137. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  138. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  139. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  140. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  142. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  144. package/build-module/components/media-editor-modal/index.mjs +88 -124
  145. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  146. package/build-module/components/media-editor-provider/index.mjs +26 -29
  147. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  148. package/build-module/components/media-form/index.mjs +68 -56
  149. package/build-module/components/media-form/index.mjs.map +1 -7
  150. package/build-module/components/media-preview/index.mjs +106 -90
  151. package/build-module/components/media-preview/index.mjs.map +1 -7
  152. package/build-module/components/rotation-ruler/index.mjs +161 -164
  153. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  154. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  156. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  158. package/build-module/image-editor/core/camera.mjs +245 -178
  159. package/build-module/image-editor/core/camera.mjs.map +1 -7
  160. package/build-module/image-editor/core/constants.mjs +110 -64
  161. package/build-module/image-editor/core/constants.mjs.map +1 -7
  162. package/build-module/image-editor/core/containment.mjs +265 -237
  163. package/build-module/image-editor/core/containment.mjs.map +1 -7
  164. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  165. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  166. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  168. package/build-module/image-editor/core/index.mjs +5 -34
  169. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  170. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  171. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  172. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  173. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  174. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  175. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  176. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  177. package/build-module/image-editor/core/source-region.mjs +210 -160
  178. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  179. package/build-module/image-editor/core/state.mjs +271 -243
  180. package/build-module/image-editor/core/state.mjs.map +1 -7
  181. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  182. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  183. package/build-module/image-editor/core/transform-style.mjs +34 -23
  184. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  185. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  186. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  187. package/build-module/image-editor/core/types.mjs +0 -1
  188. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  189. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  190. package/build-module/image-editor/index.mjs +3 -38
  191. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  192. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  193. package/build-module/image-editor/react/components/cropper.mjs +550 -686
  194. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  195. package/build-module/image-editor/react/components/index.mjs +1 -7
  196. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  198. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  200. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  202. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  204. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  205. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  206. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  208. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  209. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  211. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  213. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  215. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  217. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  219. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  220. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  221. package/build-module/index.mjs +3 -10
  222. package/build-module/lock-unlock.mjs +5 -10
  223. package/build-module/lock-unlock.mjs.map +1 -7
  224. package/build-module/private-apis.mjs +8 -9
  225. package/build-module/private-apis.mjs.map +1 -7
  226. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  227. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  228. package/build-module/state/composite-reducer.mjs +114 -90
  229. package/build-module/state/composite-reducer.mjs.map +1 -7
  230. package/build-module/state/index.mjs +5 -25
  231. package/build-module/state/media-editor-state-provider.mjs +29 -24
  232. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  233. package/build-module/state/types.mjs +8 -7
  234. package/build-module/state/types.mjs.map +1 -7
  235. package/build-module/state/use-media-editor-state.mjs +256 -286
  236. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  237. package/build-module/store/actions.mjs +12 -19
  238. package/build-module/store/actions.mjs.map +1 -7
  239. package/build-module/store/constants.mjs +4 -5
  240. package/build-module/store/constants.mjs.map +1 -7
  241. package/build-module/store/index.mjs +8 -9
  242. package/build-module/store/index.mjs.map +1 -7
  243. package/build-module/store/reducer.mjs +23 -26
  244. package/build-module/store/reducer.mjs.map +1 -7
  245. package/build-module/store/selectors.mjs +8 -13
  246. package/build-module/store/selectors.mjs.map +1 -7
  247. package/build-module/utils/get-media-type.mjs +14 -17
  248. package/build-module/utils/get-media-type.mjs.map +1 -7
  249. package/build-module/utils/index.mjs +1 -6
  250. package/build-style/style-rtl.css +41 -4
  251. package/build-style/style.css +41 -4
  252. package/build-types/components/media-editor/index.d.ts +4 -0
  253. package/build-types/components/media-editor/index.d.ts.map +1 -1
  254. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  256. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  257. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  258. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  259. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  260. package/build-types/components/media-preview/index.d.ts.map +1 -1
  261. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  262. package/build-types/image-editor/core/constants.d.ts +0 -1
  263. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  264. package/build-types/image-editor/core/index.d.ts +1 -1
  265. package/build-types/image-editor/core/index.d.ts.map +1 -1
  266. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  267. package/build-types/image-editor/core/types.d.ts +1 -1
  268. package/build-types/image-editor/index.d.ts +7 -6
  269. package/build-types/image-editor/index.d.ts.map +1 -1
  270. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  271. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  272. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  273. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  274. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  275. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  276. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  277. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  278. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  279. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  280. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  281. package/build-types/state/composite-reducer.d.ts +1 -1
  282. package/build-types/state/composite-reducer.d.ts.map +1 -1
  283. package/build-types/state/index.d.ts +1 -0
  284. package/build-types/state/index.d.ts.map +1 -1
  285. package/build-types/state/types.d.ts +2 -1
  286. package/build-types/state/types.d.ts.map +1 -1
  287. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  288. package/package.json +21 -21
  289. package/src/components/media-editor/index.tsx +215 -162
  290. package/src/components/media-editor/style.scss +19 -0
  291. package/src/components/media-editor/use-crop-options.ts +5 -2
  292. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  293. package/src/components/media-editor-canvas/index.tsx +16 -26
  294. package/src/components/media-editor-image-controls/index.tsx +4 -2
  295. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  296. package/src/components/media-editor-modal/style.scss +1 -1
  297. package/src/components/media-preview/index.tsx +66 -23
  298. package/src/components/media-preview/style.scss +16 -2
  299. package/src/components/rotation-ruler/style.scss +6 -2
  300. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  301. package/src/image-editor/README.md +8 -8
  302. package/src/image-editor/core/constants.ts +0 -13
  303. package/src/image-editor/core/index.ts +1 -5
  304. package/src/image-editor/core/setter-helpers.ts +1 -1
  305. package/src/image-editor/core/types.ts +1 -1
  306. package/src/image-editor/docs/architecture.md +1 -1
  307. package/src/image-editor/docs/recipes.md +3 -3
  308. package/src/image-editor/index.ts +7 -16
  309. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  310. package/src/image-editor/react/components/cropper.tsx +19 -27
  311. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  312. package/src/image-editor/react/hooks/index.ts +2 -2
  313. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  314. package/src/state/aspect-ratio-presets.ts +18 -0
  315. package/src/state/composite-reducer.ts +2 -2
  316. package/src/state/index.ts +1 -0
  317. package/src/state/types.ts +2 -6
  318. package/src/state/use-media-editor-state.ts +7 -5
  319. package/build/image-editor/core/index.cjs.map +0 -7
  320. package/build/image-editor/core/types.cjs.map +0 -7
  321. package/build/image-editor/index.cjs.map +0 -7
  322. package/build/image-editor/react/components/index.cjs.map +0 -7
  323. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  324. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  325. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  326. package/build/index.cjs.map +0 -7
  327. package/build/state/index.cjs.map +0 -7
  328. package/build/utils/index.cjs.map +0 -7
  329. package/build-module/image-editor/core/index.mjs.map +0 -7
  330. package/build-module/image-editor/core/types.mjs.map +0 -7
  331. package/build-module/image-editor/index.mjs.map +0 -7
  332. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  333. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  334. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  335. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  336. package/build-module/index.mjs.map +0 -7
  337. package/build-module/state/index.mjs.map +0 -7
  338. package/build-module/utils/index.mjs.map +0 -7
  339. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
@@ -6,9 +6,11 @@ import {
6
6
  MenuItem,
7
7
  Spinner as WCSpinner,
8
8
  __experimentalConfirmDialog as ConfirmDialog,
9
+ __unstableAnimatePresence as AnimatePresence,
10
+ __unstableMotion as motion,
9
11
  } from '@wordpress/components';
10
12
  import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
11
- import { useViewportMatch } from '@wordpress/compose';
13
+ import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
12
14
  import { useDispatch, useSelect } from '@wordpress/data';
13
15
  import { store as coreStore } from '@wordpress/core-data';
14
16
  import { NavigableRegion } from '@wordpress/admin-ui';
@@ -83,6 +85,26 @@ const DETAILS_PANEL = 'details';
83
85
  /** Identifier for the crop panel. Images only; other media has nothing to crop. */
84
86
  const CROP_PANEL = 'crop';
85
87
 
88
+ // Matches the editor's sidebar in `ComplementaryArea`.
89
+ const SIDEBAR_ANIMATION_DURATION = 0.3;
90
+
91
+ type SidebarTransition = {
92
+ type: 'tween';
93
+ duration: number;
94
+ ease: number[];
95
+ };
96
+
97
+ const sidebarVariants = {
98
+ // `auto` leaves the width to the sidebar's stylesheet.
99
+ open: { width: 'auto' },
100
+ // Takes the transition from `AnimatePresence`'s `custom` prop, so a
101
+ // sidebar that is already closing still gets the current one.
102
+ closed: ( transition: SidebarTransition ) => ( {
103
+ width: 0,
104
+ transition,
105
+ } ),
106
+ };
107
+
86
108
  interface MediaEditorTab {
87
109
  id: string;
88
110
  title: string;
@@ -221,7 +243,7 @@ interface MediaEditorFrameContextValue {
221
243
  onSave: () => void;
222
244
  /**
223
245
  * When `true`, the media has a lineage root to restore to, so the
224
- * "Restore original image" menu item is shown.
246
+ * history menu shows its "Restore original" item.
225
247
  */
226
248
  canRestoreOriginal: boolean;
227
249
  /**
@@ -264,20 +286,66 @@ export interface HeaderActionsProps {
264
286
  showCloseButton?: boolean;
265
287
  }
266
288
 
267
- function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
268
- const {
269
- isImage,
270
- isSaving,
271
- onCancel,
272
- isWide,
273
- activePanel,
274
- onTogglePanel,
275
- canRestoreOriginal,
276
- isSourceReplaced,
277
- onRestoreOriginal,
278
- } = useMediaEditorFrameContext();
289
+ function PanelToggle() {
290
+ const { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();
279
291
  const isPanelOpen = !! activePanel;
292
+ // The sidebar holds more than one panel, so this opens and closes the
293
+ // sidebar rather than naming a panel: reopening returns to whichever tab
294
+ // was last showing, and the tab strip inside switches between them.
295
+ return (
296
+ <Button
297
+ size="compact"
298
+ icon={ drawerRight }
299
+ label={ __( 'Media settings' ) }
300
+ isPressed={ isPanelOpen }
301
+ // Only a docked column really expands beside the canvas; below
302
+ // that the panel replaces the view, which the pressed state
303
+ // already describes.
304
+ aria-expanded={ isWide ? isPanelOpen : undefined }
305
+ onClick={ onTogglePanel }
306
+ />
307
+ );
308
+ }
309
+
310
+ function MoreMenu() {
311
+ const { isImage } = useMediaEditorFrameContext();
280
312
  const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
313
+ if ( ! isImage ) {
314
+ return null;
315
+ }
316
+ return (
317
+ <>
318
+ <DropdownMenu
319
+ icon={ moreVertical }
320
+ label={ __( 'More options' ) }
321
+ toggleProps={ { size: 'compact' } }
322
+ >
323
+ { ( { onClose: closeMenu } ) => (
324
+ <MenuGroup>
325
+ <MenuItem
326
+ icon={ keyboard }
327
+ iconPosition="left"
328
+ onClick={ () => {
329
+ setIsShortcutsModalOpen( true );
330
+ closeMenu();
331
+ } }
332
+ >
333
+ { __( 'Keyboard shortcuts' ) }
334
+ </MenuItem>
335
+ </MenuGroup>
336
+ ) }
337
+ </DropdownMenu>
338
+ { isShortcutsModalOpen && (
339
+ <MediaEditorKeyboardShortcutsModal
340
+ onClose={ () => setIsShortcutsModalOpen( false ) }
341
+ />
342
+ ) }
343
+ </>
344
+ );
345
+ }
346
+
347
+ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
348
+ const { isSaving, onCancel } = useMediaEditorFrameContext();
281
349
  return (
282
350
  <Stack
283
351
  className="media-editor__header-actions"
@@ -285,65 +353,8 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
285
353
  align="center"
286
354
  gap="sm"
287
355
  >
288
- { /* The sidebar holds more than one panel, so this opens and
289
- closes the sidebar rather than naming a panel: reopening
290
- returns to whichever tab was last showing, and the tab strip
291
- inside switches between them. */ }
292
- <Button
293
- size="compact"
294
- icon={ drawerRight }
295
- label={ __( 'Media settings' ) }
296
- isPressed={ isPanelOpen }
297
- // Only a docked column really expands beside the canvas; below
298
- // that the panel replaces the view, which the pressed state
299
- // already describes.
300
- aria-expanded={ isWide ? isPanelOpen : undefined }
301
- onClick={ onTogglePanel }
302
- />
303
- { isImage && (
304
- <DropdownMenu
305
- icon={ moreVertical }
306
- label={ __( 'More options' ) }
307
- toggleProps={ { size: 'compact' } }
308
- >
309
- { ( { onClose: closeMenu } ) => (
310
- <>
311
- { canRestoreOriginal && (
312
- <MenuGroup>
313
- <MenuItem
314
- icon={ backup }
315
- iconPosition="left"
316
- disabled={
317
- isSourceReplaced || isSaving
318
- }
319
- info={ __(
320
- 'Discards unsaved changes and loads the original image.'
321
- ) }
322
- onClick={ () => {
323
- onRestoreOriginal();
324
- closeMenu();
325
- } }
326
- >
327
- { __( 'Restore original image' ) }
328
- </MenuItem>
329
- </MenuGroup>
330
- ) }
331
- <MenuGroup>
332
- <MenuItem
333
- icon={ keyboard }
334
- iconPosition="left"
335
- onClick={ () => {
336
- setIsShortcutsModalOpen( true );
337
- closeMenu();
338
- } }
339
- >
340
- { __( 'Keyboard shortcuts' ) }
341
- </MenuItem>
342
- </MenuGroup>
343
- </>
344
- ) }
345
- </DropdownMenu>
346
- ) }
356
+ <PanelToggle />
357
+ <MoreMenu />
347
358
  { showCloseButton && (
348
359
  <Button
349
360
  size="compact"
@@ -354,18 +365,21 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
354
365
  accessibleWhenDisabled
355
366
  />
356
367
  ) }
357
- { isShortcutsModalOpen && (
358
- <MediaEditorKeyboardShortcutsModal
359
- onClose={ () => setIsShortcutsModalOpen( false ) }
360
- />
361
- ) }
362
368
  </Stack>
363
369
  );
364
370
  }
365
371
 
366
372
  function HistoryActions() {
367
- const { isImage, isUndoRedoDisabled, isWide, activePanel } =
368
- useMediaEditorFrameContext();
373
+ const {
374
+ isImage,
375
+ isSaving,
376
+ isUndoRedoDisabled,
377
+ isWide,
378
+ activePanel,
379
+ canRestoreOriginal,
380
+ isSourceReplaced,
381
+ onRestoreOriginal,
382
+ } = useMediaEditorFrameContext();
369
383
  const {
370
384
  reset,
371
385
  isDirty,
@@ -409,15 +423,6 @@ function HistoryActions() {
409
423
  align="center"
410
424
  gap="sm"
411
425
  >
412
- <Button
413
- size="compact"
414
- variant="tertiary"
415
- disabled={ isUndoRedoDisabled || ! isDirty }
416
- accessibleWhenDisabled
417
- onClick={ handleReset }
418
- >
419
- { __( 'Reset' ) }
420
- </Button>
421
426
  <Button
422
427
  size="compact"
423
428
  icon={ undo }
@@ -442,6 +447,48 @@ function HistoryActions() {
442
447
  accessibleWhenDisabled
443
448
  onClick={ handleRedo }
444
449
  />
450
+ <DropdownMenu
451
+ icon={ backup }
452
+ label={ __( 'History' ) }
453
+ popoverProps={ { placement: 'top-start' } }
454
+ toggleProps={ {
455
+ size: 'compact',
456
+ disabled:
457
+ isUndoRedoDisabled ||
458
+ ( ! isDirty && ! canRestoreOriginal ),
459
+ accessibleWhenDisabled: true,
460
+ } }
461
+ >
462
+ { ( { onClose: closeMenu } ) => (
463
+ <>
464
+ <MenuGroup>
465
+ <MenuItem
466
+ disabled={ isUndoRedoDisabled || ! isDirty }
467
+ onClick={ () => {
468
+ handleReset();
469
+ closeMenu();
470
+ } }
471
+ >
472
+ { __( 'Reset image edits' ) }
473
+ </MenuItem>
474
+ </MenuGroup>
475
+ { canRestoreOriginal && (
476
+ <MenuGroup>
477
+ <MenuItem
478
+ disabled={ isSourceReplaced || isSaving }
479
+ info={ __( 'Discards unsaved changes.' ) }
480
+ onClick={ () => {
481
+ onRestoreOriginal();
482
+ closeMenu();
483
+ } }
484
+ >
485
+ { __( 'Restore original' ) }
486
+ </MenuItem>
487
+ </MenuGroup>
488
+ ) }
489
+ </>
490
+ ) }
491
+ </DropdownMenu>
445
492
  </Stack>
446
493
  );
447
494
  }
@@ -518,36 +565,26 @@ function MediaEditorContent( {
518
565
  // The choice is not carried across openings: the modal is transient, and
519
566
  // re-opening with the panel hidden on a wide screen is how #81487 read to
520
567
  // people in the first place. Within one opening it does hold — see
521
- // `hasChosenPanelRef` below.
568
+ // `chosenPanel` below.
522
569
  const isWide = useViewportMatch( 'small' );
523
- // `null` when nothing is open, otherwise the open panel's id.
524
- const [ activePanel, setActivePanel ] = useState< string | null >(
525
- isWide ? DETAILS_PANEL : null
526
- );
527
- // Width picks the starting panel, but only until the user picks one. After
528
- // that their choice holds for the rest of the session: closing the panel
529
- // and then resizing — or crossing the breakpoint by rotating a tablet —
530
- // should not reopen something they just dismissed.
531
- const hasChosenPanelRef = useRef( false );
532
- // The panel the toggle reopens, and the one width picks until the user
533
- // picks their own. Tracked separately from `hasChosenPanelRef` because
534
- // the two answer different questions: whether the panel should be open,
535
- // and which tab it should show.
536
- const lastPanelRef = useRef( DETAILS_PANEL );
537
- const hasChosenTabRef = useRef( false );
538
- // Switching tabs says nothing about whether the panel should be open, so
539
- // it leaves `hasChosenPanelRef` alone: picking Details on a wide screen
540
- // and then dragging the window narrow should still hand the canvas the
541
- // full width.
542
- const selectPanel = useCallback( ( panel: string ) => {
543
- hasChosenTabRef.current = true;
544
- lastPanelRef.current = panel;
545
- setActivePanel( panel );
546
- }, [] );
547
- const togglePanel = useCallback( () => {
548
- hasChosenPanelRef.current = true;
549
- setActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );
550
- }, [] );
570
+ // Below `small` the open panel replaces the canvas instead of sitting
571
+ // beside it, so there is nothing to animate.
572
+ const disableSidebarMotion = useReducedMotion() || ! isWide;
573
+ const sidebarTransition: SidebarTransition = {
574
+ type: 'tween',
575
+ duration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,
576
+ ease: [ 0.6, 0, 0.4, 1 ],
577
+ };
578
+ // Width picks the starting panel, but only until the user opens or closes
579
+ // it. After that their choice holds for the rest of the session: closing
580
+ // the panel and then resizing — or crossing the breakpoint by rotating a
581
+ // tablet — should not reopen something they just dismissed. `undefined`
582
+ // until then, otherwise `null` for closed or the open panel's id.
583
+ const [ chosenPanel, setChosenPanel ] = useState< string | null >();
584
+ // The tab the user picked, `null` until they pick one. Tracked separately
585
+ // from `chosenPanel` because the two answer different questions: whether
586
+ // the panel should be open, and which tab it should show.
587
+ const [ chosenTab, setChosenTab ] = useState< string | null >( null );
551
588
  // Below `small` a frame's header cannot fit the history cluster alongside
552
589
  // its own controls, so it moves that cluster elsewhere. The same width
553
590
  // undocks the panel, so this is `isWide` rather than a second query.
@@ -601,12 +638,6 @@ function MediaEditorContent( {
601
638
  };
602
639
  }, [] );
603
640
 
604
- useEffect( () => {
605
- setIsPlacementActive( false );
606
- setIsCanvasGestureActive( false );
607
- setIsSourceReplaced( false );
608
- }, [ id ] );
609
-
610
641
  // Restore-original: the edit root the edited attachment descends from,
611
642
  // exposed by the server as the root-level `edit_root` id on the
612
643
  // attachment (edit context, embeddable via the `wp:edit-root` link).
@@ -705,29 +736,33 @@ function MediaEditorContent( {
705
736
  const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
706
737
  const isImage = !! media && mediaType === 'image';
707
738
 
708
- // Until the user picks a panel, follow the breakpoint: dragging a window
709
- // narrow hands the canvas the full width instead of leaving a panel
710
- // wedged beside it.
711
- //
712
739
  // Docked, the panel opens on Crop: the canvas is still beside it and
713
740
  // cropping is what the editor is for. Below `small` an open panel covers
714
741
  // the canvas, and crop controls with no crop in sight are not worth
715
742
  // opening on, so Details leads there. Non-image media has no Crop tab at
716
- // all (see `tabs`), so it always gets Details. `isImage` comes from a
717
- // record that resolves after mount, which is why this runs in an effect
718
- // rather than seeding `useState`.
719
- useEffect( () => {
720
- if ( hasChosenPanelRef.current && hasChosenTabRef.current ) {
721
- return;
722
- }
723
- const defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;
724
- if ( ! hasChosenTabRef.current ) {
725
- lastPanelRef.current = defaultPanel;
726
- }
727
- if ( ! hasChosenPanelRef.current ) {
728
- setActivePanel( isWide ? lastPanelRef.current : null );
729
- }
730
- }, [ isWide, isImage ] );
743
+ // all (see `tabs`), so it always gets Details.
744
+ const currentTab =
745
+ chosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );
746
+ // `null` when nothing is open, otherwise the open panel's id. Until the
747
+ // user opens or closes the panel, follow the breakpoint: dragging a window
748
+ // narrow hands the canvas the full width instead of leaving a panel
749
+ // wedged beside it.
750
+ let activePanel = chosenPanel;
751
+ if ( activePanel === undefined ) {
752
+ activePanel = isWide ? currentTab : null;
753
+ }
754
+ // Switching tabs says nothing about whether the panel should be open, so
755
+ // it leaves `chosenPanel` unset: picking Details on a wide screen and then
756
+ // dragging the window narrow should still hand the canvas the full width.
757
+ const selectPanel = useCallback( ( panel: string ) => {
758
+ setChosenTab( panel );
759
+ setChosenPanel( ( chosen ) =>
760
+ chosen === undefined ? chosen : panel
761
+ );
762
+ }, [] );
763
+ const togglePanel = useCallback( () => {
764
+ setChosenPanel( activePanel ? null : currentTab );
765
+ }, [ activePanel, currentTab ] );
731
766
  const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
732
767
  useCropOptions( { aspectRatioPresets } );
733
768
  const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
@@ -922,25 +957,41 @@ function MediaEditorContent( {
922
957
  </div>
923
958
  ) }
924
959
  </NavigableRegion>
925
- { !! activePanel && (
926
- <MediaEditorSidebar
927
- tabs={ tabs }
928
- // Swapping the edited media can drop the Crop
929
- // tab out from under an open panel — saving a
930
- // crop moves the editor to a new id, which may
931
- // resolve as non-image. Fall back rather than
932
- // hand `Tabs.Root` a value no tab matches.
933
- activeTab={
934
- tabs.some(
935
- ( tab ) => tab.id === activePanel
936
- )
937
- ? activePanel
938
- : DETAILS_PANEL
939
- }
940
- onSelectTab={ selectPanel }
941
- disabled={ isSaving }
942
- />
943
- ) }
960
+ <AnimatePresence
961
+ initial={ false }
962
+ custom={ sidebarTransition }
963
+ >
964
+ { !! activePanel && (
965
+ <motion.div
966
+ className="media-editor__sidebar-container"
967
+ variants={ sidebarVariants }
968
+ initial="closed"
969
+ animate="open"
970
+ exit="closed"
971
+ transition={ sidebarTransition }
972
+ >
973
+ <MediaEditorSidebar
974
+ tabs={ tabs }
975
+ // Swapping the edited media can drop the
976
+ // Crop tab out from under an open panel —
977
+ // saving a crop moves the editor to a new
978
+ // id, which may resolve as non-image.
979
+ // Fall back rather than hand `Tabs.Root`
980
+ // a value no tab matches.
981
+ activeTab={
982
+ tabs.some(
983
+ ( tab ) =>
984
+ tab.id === activePanel
985
+ )
986
+ ? activePanel
987
+ : DETAILS_PANEL
988
+ }
989
+ onSelectTab={ selectPanel }
990
+ disabled={ isSaving }
991
+ />
992
+ </motion.div>
993
+ ) }
994
+ </AnimatePresence>
944
995
  </div>
945
996
  ) }
946
997
  </div>
@@ -1015,6 +1066,8 @@ export function MediaEditor( props: MediaEditorProps ) {
1015
1066
  // `DataViewsPicker` exposes its own sub-components. They read what they need
1016
1067
  // from context, so a frame only chooses where they go and how they look.
1017
1068
  MediaEditor.HeaderActions = HeaderActions;
1069
+ MediaEditor.PanelToggle = PanelToggle;
1070
+ MediaEditor.MoreMenu = MoreMenu;
1018
1071
  MediaEditor.HistoryActions = HistoryActions;
1019
1072
  MediaEditor.SaveActions = SaveActions;
1020
1073
 
@@ -51,8 +51,13 @@
51
51
  // canvas takes whatever the 320px panel leaves — about 200px at
52
52
  // 600px, 380px at 782px. Cramped, but a cramped preview beside
53
53
  // reachable controls beats a panel that hides the image outright.
54
+ // The right gutter goes when the sidebar opens beside the canvas. It
55
+ // moves with the sidebar's width animation, so it uses the same
56
+ // duration and easing.
54
57
  @include break-small() {
55
58
  margin: 0 $grid-unit-30;
59
+ transition: margin-right 0.3s cubic-bezier(0.6, 0, 0.4, 1);
60
+ @include reduce-motion("transition");
56
61
  }
57
62
 
58
63
  // Promise the canvas a floor only where the body is wide enough to
@@ -123,6 +128,20 @@
123
128
  }
124
129
  }
125
130
 
131
+ // Animates its width when the sidebar opens or closes. The sidebar keeps
132
+ // its own width inside, so its contents are clipped rather than reflowed.
133
+ .media-editor__sidebar-container {
134
+ display: flex;
135
+ flex: 1;
136
+ min-width: 0;
137
+ min-height: 0;
138
+ overflow: hidden;
139
+
140
+ @include break-small() {
141
+ flex: none;
142
+ }
143
+ }
144
+
126
145
  // Settings panel. Below `small` it takes the whole body: there is no room
127
146
  // to put a 320px column beside a canvas worth looking at, and that is
128
147
  // also where the transform controls fall back to a row under the canvas.
@@ -1,7 +1,10 @@
1
1
  import { useMemo } from '@wordpress/element';
2
- import { DEFAULT_ASPECT_RATIOS } from '../../image-editor/core/constants';
3
2
  import type { AspectRatioPreset } from '../../image-editor/core/constants';
4
- import { useMediaEditor, resolveAspectRatio } from '../../state';
3
+ import {
4
+ DEFAULT_ASPECT_RATIOS,
5
+ useMediaEditor,
6
+ resolveAspectRatio,
7
+ } from '../../state';
5
8
 
6
9
  interface UseCropOptionsArgs {
7
10
  aspectRatioPresets?: AspectRatioPreset[];
@@ -62,14 +62,10 @@ interface UseSaveMediaEditorReturn {
62
62
  }
63
63
 
64
64
  function getCropModifiers( session: MediaEditorSession ): Modifier[] {
65
- const { state } = session.cropper;
66
- if ( ! session.hasOutputEdits || ! state.image ) {
65
+ if ( ! session.hasOutputEdits ) {
67
66
  return [];
68
67
  }
69
- return buildModifiers( state, {
70
- width: state.image.naturalWidth,
71
- height: state.image.naturalHeight,
72
- } );
68
+ return buildModifiers( session.cropper );
73
69
  }
74
70
 
75
71
  function getMetadataEdits(
@@ -50,9 +50,12 @@ export default function MediaEditorCanvas( {
50
50
  // Tracks whether the image pixels have actually loaded. The cropper's
51
51
  // geometry is driven by the known media dimensions, so its handles and
52
52
  // overlays would otherwise appear before the image finishes streaming in.
53
- const [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(
54
- 'loading'
55
- );
53
+ // Stored with the URL it is for, so a new URL (restoring the original
54
+ // swaps it in place) counts as loading until the cropper reports back.
55
+ const [ settled, setSettled ] = useState< {
56
+ url: string | undefined;
57
+ status: 'loaded' | 'error';
58
+ } >();
56
59
 
57
60
  // Resolved aspect ratio is derived from the preset key + the
58
61
  // loaded image (for the "Original" preset). The reducer doesn't
@@ -96,29 +99,14 @@ export default function MediaEditorCanvas( {
96
99
  }, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );
97
100
 
98
101
  const isImage = mediaType.type === 'image';
99
-
100
- // Probe the image to know when its pixels have loaded (or failed),
101
- // independent of the cropper. The browser shares one fetch/cache with the
102
- // cropper's own `<img>`, so this adds no network cost. The cropper stays
103
- // framework-pure — load/error handling lives here in the wrapper layer.
104
- useEffect( () => {
105
- if ( ! mediaUrl || ! isImage ) {
106
- return;
107
- }
108
- setStatus( 'loading' );
109
- const probe = new window.Image();
110
- probe.onload = () => setStatus( 'loaded' );
111
- probe.onerror = () => setStatus( 'error' );
112
- probe.src = mediaUrl;
113
- // Cached images may already be complete before listeners attach.
114
- if ( probe.complete ) {
115
- setStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );
116
- }
117
- return () => {
118
- probe.onload = null;
119
- probe.onerror = null;
120
- };
121
- }, [ mediaUrl, isImage ] );
102
+ const status =
103
+ settled && settled.url === mediaUrl ? settled.status : 'loading';
104
+ const handleImageLoaded = useCallback( () => {
105
+ setSettled( { url: mediaUrl, status: 'loaded' } );
106
+ }, [ mediaUrl ] );
107
+ const handleImageError = useCallback( () => {
108
+ setSettled( { url: mediaUrl, status: 'error' } );
109
+ }, [ mediaUrl ] );
122
110
 
123
111
  if ( ! mediaUrl || ! isImage ) {
124
112
  return null;
@@ -165,6 +153,8 @@ export default function MediaEditorCanvas( {
165
153
  isPlacementActive={ isPlacementActive }
166
154
  onGestureStart={ handleGestureStart }
167
155
  onGestureEnd={ handleGestureEnd }
156
+ onImageLoaded={ handleImageLoaded }
157
+ onImageError={ handleImageError }
168
158
  disabled={ disabled }
169
159
  />
170
160
  </div>
@@ -1,6 +1,8 @@
1
1
  import { Button } from '@wordpress/components';
2
- // eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.
3
- import { Menu } from '@wordpress/ui';
2
+ import {
3
+ // eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.
4
+ Menu,
5
+ } from '@wordpress/ui';
4
6
  import { __ } from '@wordpress/i18n';
5
7
  import {
6
8
  aspectRatio as aspectRatioIcon,
@@ -1,4 +1,4 @@
1
- import type { CropperState, Size } from '../../image-editor';
1
+ import type { CropperController } from '../../image-editor';
2
2
  import { getRotatedBBox } from '../../image-editor/core/camera';
3
3
 
4
4
  /**
@@ -71,20 +71,26 @@ const CROP_TOLERANCE = 0.1;
71
71
  * leave the sign alone because `flip_h · flip_v = -I` commutes with
72
72
  * rotation.
73
73
  *
74
- * @param state Current cropper state.
75
- * @param imageSize Natural dimensions of the source image.
76
- * @return Ordered modifier array; empty when nothing is server-relevant.
74
+ * @param cropper The cropper controller. The current edit and the loaded
75
+ * image's natural size are both read from its state.
76
+ * @return Ordered modifier array; empty when nothing is server-relevant or
77
+ * no image has loaded.
77
78
  */
78
79
  export function buildModifiers(
79
- state: CropperState,
80
- imageSize: Size
80
+ cropper: Pick< CropperController, 'state' >
81
81
  ): Modifier[] {
82
82
  const modifiers: Modifier[] = [];
83
+ const { state } = cropper;
84
+ const { image } = state;
83
85
 
84
- if ( imageSize.width === 0 || imageSize.height === 0 ) {
86
+ if ( ! image || image.naturalWidth === 0 || image.naturalHeight === 0 ) {
85
87
  return modifiers;
86
88
  }
87
89
 
90
+ const imageSize = {
91
+ width: image.naturalWidth,
92
+ height: image.naturalHeight,
93
+ };
88
94
  const { cropRect, pan, zoom, flip } = state;
89
95
  const hasFlipH = flip.horizontal;
90
96
  const hasFlipV = flip.vertical;
@@ -41,7 +41,7 @@
41
41
  }
42
42
 
43
43
  // Active (enabled) undo/redo icon buttons take the admin accent colour so
44
- // they read as live alongside the Reset/Cancel/Save actions. Disabled
44
+ // they read as live alongside the Cancel/Save actions. Disabled
45
45
  // buttons (rendered with `aria-disabled` via `accessibleWhenDisabled`)
46
46
  // keep the default muted icon colour.
47
47
  // Scoped to the modal: the package ships one stylesheet, so an unscoped