@wordpress/media-editor 0.20.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 (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -4,11 +4,13 @@ import {
4
4
  DropdownMenu,
5
5
  MenuGroup,
6
6
  MenuItem,
7
- Spinner,
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';
@@ -37,7 +39,7 @@ import {
37
39
  isKeyboardEvent,
38
40
  } from '@wordpress/keycodes';
39
41
  import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
40
- import type { Field } from '@wordpress/dataviews';
42
+ import type { Field, Form } from '@wordpress/dataviews';
41
43
  import type {
42
44
  KeyboardEvent as ReactKeyboardEvent,
43
45
  ReactElement,
@@ -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;
@@ -116,6 +138,7 @@ export interface MediaEditorFrameProps {
116
138
 
117
139
  export interface MediaEditorProps {
118
140
  fields?: Field< Media >[];
141
+ form?: Form;
119
142
  id: number;
120
143
  aspectRatioPresets?: AspectRatioPreset[];
121
144
  onClose?: () => void;
@@ -218,10 +241,9 @@ interface MediaEditorFrameContextValue {
218
241
  onTogglePanel: () => void;
219
242
  onCancel: () => void;
220
243
  onSave: () => void;
221
- onReset: () => 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,30 +365,31 @@ 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, onReset, isWide, activePanel } =
368
- useMediaEditorFrameContext();
369
373
  const {
370
- cropper: { reset },
374
+ isImage,
375
+ isSaving,
376
+ isUndoRedoDisabled,
377
+ isWide,
378
+ activePanel,
379
+ canRestoreOriginal,
380
+ isSourceReplaced,
381
+ onRestoreOriginal,
382
+ } = useMediaEditorFrameContext();
383
+ const {
384
+ reset,
371
385
  isDirty,
372
386
  hasUndo,
373
387
  hasRedo,
374
388
  undo: undoCrop,
375
389
  redo: redoCrop,
376
- beginGesture,
377
- endGesture,
378
390
  } = useMediaEditor();
379
- // Reset, undo and redo act on the cropper, so they only appear where the
380
- // canvas does. Non-image media has no edit history at all; below the dock
391
+ // Reset, undo and redo act on the image edits, so they only appear where
392
+ // the canvas does. Non-image media has no edit history at all; below the dock
381
393
  // breakpoint an open panel replaces the canvas, and leaving these behind
382
394
  // would put an enabled, destructive Reset next to metadata fields it does
383
395
  // not touch — clicking it would discard a crop the user cannot see.
@@ -403,10 +415,7 @@ function HistoryActions() {
403
415
  if ( isUndoRedoDisabled ) {
404
416
  return;
405
417
  }
406
- beginGesture();
407
418
  reset();
408
- onReset();
409
- endGesture();
410
419
  };
411
420
  return (
412
421
  <Stack
@@ -414,15 +423,6 @@ function HistoryActions() {
414
423
  align="center"
415
424
  gap="sm"
416
425
  >
417
- <Button
418
- size="compact"
419
- variant="tertiary"
420
- disabled={ isUndoRedoDisabled || ! isDirty }
421
- accessibleWhenDisabled
422
- onClick={ handleReset }
423
- >
424
- { __( 'Reset' ) }
425
- </Button>
426
426
  <Button
427
427
  size="compact"
428
428
  icon={ undo }
@@ -447,6 +447,48 @@ function HistoryActions() {
447
447
  accessibleWhenDisabled
448
448
  onClick={ handleRedo }
449
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>
450
492
  </Stack>
451
493
  );
452
494
  }
@@ -499,6 +541,7 @@ function SaveActions( { size = 'default' }: SaveActionsProps ) {
499
541
 
500
542
  function MediaEditorContent( {
501
543
  fields = [],
544
+ form,
502
545
  id,
503
546
  aspectRatioPresets,
504
547
  onClose,
@@ -522,36 +565,26 @@ function MediaEditorContent( {
522
565
  // The choice is not carried across openings: the modal is transient, and
523
566
  // re-opening with the panel hidden on a wide screen is how #81487 read to
524
567
  // people in the first place. Within one opening it does hold — see
525
- // `hasChosenPanelRef` below.
568
+ // `chosenPanel` below.
526
569
  const isWide = useViewportMatch( 'small' );
527
- // `null` when nothing is open, otherwise the open panel's id.
528
- const [ activePanel, setActivePanel ] = useState< string | null >(
529
- isWide ? DETAILS_PANEL : null
530
- );
531
- // Width picks the starting panel, but only until the user picks one. After
532
- // that their choice holds for the rest of the session: closing the panel
533
- // and then resizing — or crossing the breakpoint by rotating a tablet —
534
- // should not reopen something they just dismissed.
535
- const hasChosenPanelRef = useRef( false );
536
- // The panel the toggle reopens, and the one width picks until the user
537
- // picks their own. Tracked separately from `hasChosenPanelRef` because
538
- // the two answer different questions: whether the panel should be open,
539
- // and which tab it should show.
540
- const lastPanelRef = useRef( DETAILS_PANEL );
541
- const hasChosenTabRef = useRef( false );
542
- // Switching tabs says nothing about whether the panel should be open, so
543
- // it leaves `hasChosenPanelRef` alone: picking Details on a wide screen
544
- // and then dragging the window narrow should still hand the canvas the
545
- // full width.
546
- const selectPanel = useCallback( ( panel: string ) => {
547
- hasChosenTabRef.current = true;
548
- lastPanelRef.current = panel;
549
- setActivePanel( panel );
550
- }, [] );
551
- const togglePanel = useCallback( () => {
552
- hasChosenPanelRef.current = true;
553
- setActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );
554
- }, [] );
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 );
555
588
  // Below `small` a frame's header cannot fit the history cluster alongside
556
589
  // its own controls, so it moves that cluster elsewhere. The same width
557
590
  // undocks the panel, so this is `isWide` rather than a second query.
@@ -605,12 +638,6 @@ function MediaEditorContent( {
605
638
  };
606
639
  }, [] );
607
640
 
608
- useEffect( () => {
609
- setIsPlacementActive( false );
610
- setIsCanvasGestureActive( false );
611
- setIsSourceReplaced( false );
612
- }, [ id ] );
613
-
614
641
  // Restore-original: the edit root the edited attachment descends from,
615
642
  // exposed by the server as the root-level `edit_root` id on the
616
643
  // attachment (edit context, embeddable via the `wp:edit-root` link).
@@ -709,37 +736,35 @@ function MediaEditorContent( {
709
736
  const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
710
737
  const isImage = !! media && mediaType === 'image';
711
738
 
712
- // Until the user picks a panel, follow the breakpoint: dragging a window
713
- // narrow hands the canvas the full width instead of leaving a panel
714
- // wedged beside it.
715
- //
716
739
  // Docked, the panel opens on Crop: the canvas is still beside it and
717
740
  // cropping is what the editor is for. Below `small` an open panel covers
718
741
  // the canvas, and crop controls with no crop in sight are not worth
719
742
  // opening on, so Details leads there. Non-image media has no Crop tab at
720
- // all (see `tabs`), so it always gets Details. `isImage` comes from a
721
- // record that resolves after mount, which is why this runs in an effect
722
- // rather than seeding `useState`.
723
- useEffect( () => {
724
- if ( hasChosenPanelRef.current && hasChosenTabRef.current ) {
725
- return;
726
- }
727
- const defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;
728
- if ( ! hasChosenTabRef.current ) {
729
- lastPanelRef.current = defaultPanel;
730
- }
731
- if ( ! hasChosenPanelRef.current ) {
732
- setActivePanel( isWide ? lastPanelRef.current : null );
733
- }
734
- }, [ isWide, isImage ] );
735
- // Only `resetCropOptions` is needed here, for the Reset button; the
736
- // aspect-ratio members are read by `MediaEditorImageControls` itself.
737
- const {
738
- aspectRatioValue,
739
- setAspectRatioValue,
740
- aspectRatioOptions,
741
- resetCropOptions,
742
- } = useCropOptions( { aspectRatioPresets } );
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 ] );
766
+ const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
767
+ useCropOptions( { aspectRatioPresets } );
743
768
  const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
744
769
  session,
745
770
  id,
@@ -889,12 +914,13 @@ function MediaEditorContent( {
889
914
  isDisabled: true,
890
915
  } ) )
891
916
  : fields,
917
+ form,
892
918
  } }
893
919
  >
894
920
  <div className="media-editor">
895
921
  { ! media ? (
896
922
  <div className="media-editor__loading">
897
- <Spinner />
923
+ <WCSpinner />
898
924
  </div>
899
925
  ) : (
900
926
  <div
@@ -931,25 +957,41 @@ function MediaEditorContent( {
931
957
  </div>
932
958
  ) }
933
959
  </NavigableRegion>
934
- { !! activePanel && (
935
- <MediaEditorSidebar
936
- tabs={ tabs }
937
- // Swapping the edited media can drop the Crop
938
- // tab out from under an open panel — saving a
939
- // crop moves the editor to a new id, which may
940
- // resolve as non-image. Fall back rather than
941
- // hand `Tabs.Root` a value no tab matches.
942
- activeTab={
943
- tabs.some(
944
- ( tab ) => tab.id === activePanel
945
- )
946
- ? activePanel
947
- : DETAILS_PANEL
948
- }
949
- onSelectTab={ selectPanel }
950
- disabled={ isSaving }
951
- />
952
- ) }
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>
953
995
  </div>
954
996
  ) }
955
997
  </div>
@@ -990,7 +1032,6 @@ function MediaEditorContent( {
990
1032
  onTogglePanel: togglePanel,
991
1033
  onCancel: handleRequestClose,
992
1034
  onSave: saveMediaEditor,
993
- onReset: resetCropOptions,
994
1035
  canRestoreOriginal,
995
1036
  isSourceReplaced,
996
1037
  onRestoreOriginal: handleRestoreOriginal,
@@ -1025,6 +1066,8 @@ export function MediaEditor( props: MediaEditorProps ) {
1025
1066
  // `DataViewsPicker` exposes its own sub-components. They read what they need
1026
1067
  // from context, so a frame only chooses where they go and how they look.
1027
1068
  MediaEditor.HeaderActions = HeaderActions;
1069
+ MediaEditor.PanelToggle = PanelToggle;
1070
+ MediaEditor.MoreMenu = MoreMenu;
1028
1071
  MediaEditor.HistoryActions = HistoryActions;
1029
1072
  MediaEditor.SaveActions = SaveActions;
1030
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[];
@@ -12,7 +15,6 @@ interface UseCropOptionsReturn {
12
15
  setAspectRatioValue: ( value: string ) => void;
13
16
  aspectRatioOptions: AspectRatioPreset[];
14
17
  resolvedAspectRatio: number | undefined;
15
- resetCropOptions: () => void;
16
18
  }
17
19
 
18
20
  /**
@@ -67,6 +69,5 @@ export function useCropOptions( {
67
69
  setAspectRatioValue: controller.setAspectRatioValue,
68
70
  aspectRatioOptions,
69
71
  resolvedAspectRatio,
70
- resetCropOptions: controller.resetCropOptions,
71
72
  };
72
73
  }
@@ -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(