@wordpress/media-editor 0.21.0 → 0.23.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 (432) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/components/media-editor/index.cjs +586 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +42 -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 +131 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +117 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +81 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +61 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +181 -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 +120 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/index.cjs +112 -155
  19. package/build/components/media-editor-modal/index.cjs.map +1 -7
  20. package/build/components/media-editor-provider/index.cjs +32 -55
  21. package/build/components/media-editor-provider/index.cjs.map +1 -7
  22. package/build/components/media-form/index.cjs +82 -77
  23. package/build/components/media-form/index.cjs.map +1 -7
  24. package/build/components/media-preview/index.cjs +113 -114
  25. package/build/components/media-preview/index.cjs.map +1 -7
  26. package/build/components/rotation-ruler/index.cjs +181 -188
  27. package/build/components/rotation-ruler/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  29. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  30. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  32. package/build/index.cjs +45 -39
  33. package/build/lock-unlock.cjs +9 -35
  34. package/build/lock-unlock.cjs.map +1 -7
  35. package/build/private-apis.cjs +16 -37
  36. package/build/private-apis.cjs.map +1 -7
  37. package/build/state/aspect-ratio-presets.cjs +59 -0
  38. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  39. package/build/state/composite-reducer.cjs +100 -113
  40. package/build/state/composite-reducer.cjs.map +1 -7
  41. package/build/state/index.cjs +22 -45
  42. package/build/state/media-editor-state-provider.cjs +35 -48
  43. package/build/state/media-editor-state-provider.cjs.map +1 -7
  44. package/build/state/types.cjs +11 -31
  45. package/build/state/types.cjs.map +1 -7
  46. package/build/state/use-media-editor-state.cjs +227 -296
  47. package/build/state/use-media-editor-state.cjs.map +1 -7
  48. package/build/store/actions.cjs +17 -44
  49. package/build/store/actions.cjs.map +1 -7
  50. package/build/store/constants.cjs +8 -29
  51. package/build/store/constants.cjs.map +1 -7
  52. package/build/store/index.cjs +33 -40
  53. package/build/store/index.cjs.map +1 -7
  54. package/build/store/reducer.cjs +28 -50
  55. package/build/store/reducer.cjs.map +1 -7
  56. package/build/store/selectors.cjs +16 -41
  57. package/build/store/selectors.cjs.map +1 -7
  58. package/build/utils/get-media-type.cjs +18 -41
  59. package/build/utils/get-media-type.cjs.map +1 -7
  60. package/build/utils/index.cjs +9 -28
  61. package/build-module/components/media-editor/index.mjs +545 -675
  62. package/build-module/components/media-editor/index.mjs.map +1 -7
  63. package/build-module/components/media-editor/use-crop-options.mjs +37 -32
  64. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  65. package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
  66. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  67. package/build-module/components/media-editor-canvas/index.mjs +95 -98
  68. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  69. package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
  70. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  71. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
  72. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  73. package/build-module/components/media-editor-image-controls/index.mjs +171 -238
  74. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  75. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
  76. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  77. package/build-module/components/media-editor-modal/index.mjs +88 -124
  78. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  79. package/build-module/components/media-editor-provider/index.mjs +26 -29
  80. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  81. package/build-module/components/media-form/index.mjs +74 -56
  82. package/build-module/components/media-form/index.mjs.map +1 -7
  83. package/build-module/components/media-preview/index.mjs +105 -90
  84. package/build-module/components/media-preview/index.mjs.map +1 -7
  85. package/build-module/components/rotation-ruler/index.mjs +161 -164
  86. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  87. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  88. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  89. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  90. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  91. package/build-module/index.mjs +3 -10
  92. package/build-module/lock-unlock.mjs +5 -10
  93. package/build-module/lock-unlock.mjs.map +1 -7
  94. package/build-module/private-apis.mjs +8 -9
  95. package/build-module/private-apis.mjs.map +1 -7
  96. package/build-module/state/aspect-ratio-presets.mjs +53 -0
  97. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  98. package/build-module/state/composite-reducer.mjs +80 -91
  99. package/build-module/state/composite-reducer.mjs.map +1 -7
  100. package/build-module/state/index.mjs +3 -26
  101. package/build-module/state/media-editor-state-provider.mjs +29 -24
  102. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  103. package/build-module/state/types.mjs +7 -7
  104. package/build-module/state/types.mjs.map +1 -7
  105. package/build-module/state/use-media-editor-state.mjs +223 -288
  106. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  107. package/build-module/store/actions.mjs +12 -19
  108. package/build-module/store/actions.mjs.map +1 -7
  109. package/build-module/store/constants.mjs +4 -5
  110. package/build-module/store/constants.mjs.map +1 -7
  111. package/build-module/store/index.mjs +8 -9
  112. package/build-module/store/index.mjs.map +1 -7
  113. package/build-module/store/reducer.mjs +23 -26
  114. package/build-module/store/reducer.mjs.map +1 -7
  115. package/build-module/store/selectors.mjs +8 -13
  116. package/build-module/store/selectors.mjs.map +1 -7
  117. package/build-module/utils/get-media-type.mjs +14 -17
  118. package/build-module/utils/get-media-type.mjs.map +1 -7
  119. package/build-module/utils/index.mjs +1 -6
  120. package/build-style/style-rtl.css +145 -61
  121. package/build-style/style.css +144 -61
  122. package/build-types/components/media-editor/index.d.ts +20 -2
  123. package/build-types/components/media-editor/index.d.ts.map +1 -1
  124. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  125. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  126. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  127. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  128. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  129. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  130. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  131. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  132. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  133. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  134. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  135. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  136. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  137. package/build-types/components/media-form/index.d.ts.map +1 -1
  138. package/build-types/components/media-preview/index.d.ts.map +1 -1
  139. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  140. package/build-types/state/aspect-ratio-presets.d.ts +24 -0
  141. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  142. package/build-types/state/composite-reducer.d.ts +17 -19
  143. package/build-types/state/composite-reducer.d.ts.map +1 -1
  144. package/build-types/state/index.d.ts +2 -4
  145. package/build-types/state/index.d.ts.map +1 -1
  146. package/build-types/state/types.d.ts +20 -63
  147. package/build-types/state/types.d.ts.map +1 -1
  148. package/build-types/state/use-media-editor-state.d.ts +33 -52
  149. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  150. package/package.json +22 -23
  151. package/src/components/media-editor/index.tsx +355 -167
  152. package/src/components/media-editor/style.scss +19 -0
  153. package/src/components/media-editor/use-crop-options.ts +9 -10
  154. package/src/components/media-editor/use-save-media-editor.ts +48 -10
  155. package/src/components/media-editor-canvas/index.tsx +30 -51
  156. package/src/components/media-editor-canvas/style.scss +6 -6
  157. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  158. package/src/components/media-editor-crop-panel/style.scss +21 -0
  159. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  160. package/src/components/media-editor-image-controls/index.tsx +15 -11
  161. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
  162. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  163. package/src/components/media-editor-modal/index.tsx +1 -1
  164. package/src/components/media-editor-modal/style.scss +1 -1
  165. package/src/components/media-form/index.tsx +7 -1
  166. package/src/components/media-preview/index.tsx +65 -23
  167. package/src/components/media-preview/style.scss +16 -2
  168. package/src/components/rotation-ruler/style.scss +9 -5
  169. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  170. package/src/state/README.md +32 -0
  171. package/src/state/aspect-ratio-presets.ts +37 -0
  172. package/src/state/composite-reducer.ts +42 -80
  173. package/src/state/index.ts +2 -17
  174. package/src/state/types.ts +18 -72
  175. package/src/state/use-media-editor-state.ts +155 -238
  176. package/src/style.scss +2 -1
  177. package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
  178. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
  179. package/build/image-editor/core/camera.cjs +0 -225
  180. package/build/image-editor/core/camera.cjs.map +0 -7
  181. package/build/image-editor/core/constants.cjs +0 -108
  182. package/build/image-editor/core/constants.cjs.map +0 -7
  183. package/build/image-editor/core/containment.cjs +0 -276
  184. package/build/image-editor/core/containment.cjs.map +0 -7
  185. package/build/image-editor/core/crop-rect.cjs +0 -48
  186. package/build/image-editor/core/crop-rect.cjs.map +0 -7
  187. package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
  188. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
  189. package/build/image-editor/core/index.cjs +0 -62
  190. package/build/image-editor/core/index.cjs.map +0 -7
  191. package/build/image-editor/core/interaction-controller.cjs +0 -654
  192. package/build/image-editor/core/interaction-controller.cjs.map +0 -7
  193. package/build/image-editor/core/math/rotation.cjs +0 -41
  194. package/build/image-editor/core/math/rotation.cjs.map +0 -7
  195. package/build/image-editor/core/math/sanitize.cjs +0 -92
  196. package/build/image-editor/core/math/sanitize.cjs.map +0 -7
  197. package/build/image-editor/core/setter-helpers.cjs +0 -64
  198. package/build/image-editor/core/setter-helpers.cjs.map +0 -7
  199. package/build/image-editor/core/source-region.cjs +0 -206
  200. package/build/image-editor/core/source-region.cjs.map +0 -7
  201. package/build/image-editor/core/state.cjs +0 -283
  202. package/build/image-editor/core/state.cjs.map +0 -7
  203. package/build/image-editor/core/stencil-math.cjs +0 -216
  204. package/build/image-editor/core/stencil-math.cjs.map +0 -7
  205. package/build/image-editor/core/transform-style.cjs +0 -52
  206. package/build/image-editor/core/transform-style.cjs.map +0 -7
  207. package/build/image-editor/core/transforms/pipeline.cjs +0 -43
  208. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
  209. package/build/image-editor/core/types.cjs +0 -19
  210. package/build/image-editor/core/types.cjs.map +0 -7
  211. package/build/image-editor/core/viewport-state.cjs +0 -50
  212. package/build/image-editor/core/viewport-state.cjs.map +0 -7
  213. package/build/image-editor/index.cjs +0 -67
  214. package/build/image-editor/index.cjs.map +0 -7
  215. package/build/image-editor/react/components/cropper-provider.cjs +0 -50
  216. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
  217. package/build/image-editor/react/components/cropper.cjs +0 -722
  218. package/build/image-editor/react/components/cropper.cjs.map +0 -7
  219. package/build/image-editor/react/components/index.cjs +0 -36
  220. package/build/image-editor/react/components/index.cjs.map +0 -7
  221. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
  222. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
  223. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
  224. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
  225. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
  226. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
  227. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
  228. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
  229. package/build/image-editor/react/components/viewport-provider.cjs +0 -51
  230. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
  231. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
  232. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
  233. package/build/image-editor/react/hooks/index.cjs +0 -34
  234. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  235. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
  236. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -7
  237. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  238. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  239. package/build/image-editor/react/hooks/use-interaction.cjs +0 -213
  240. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
  241. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
  242. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
  243. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
  244. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
  245. package/build/image-editor/react/visually-hidden-style.cjs +0 -41
  246. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -7
  247. package/build/index.cjs.map +0 -7
  248. package/build/state/index.cjs.map +0 -7
  249. package/build/utils/index.cjs.map +0 -7
  250. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -66
  251. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
  252. package/build-module/image-editor/core/camera.mjs +0 -198
  253. package/build-module/image-editor/core/camera.mjs.map +0 -7
  254. package/build-module/image-editor/core/constants.mjs +0 -69
  255. package/build-module/image-editor/core/constants.mjs.map +0 -7
  256. package/build-module/image-editor/core/containment.mjs +0 -253
  257. package/build-module/image-editor/core/containment.mjs.map +0 -7
  258. package/build-module/image-editor/core/crop-rect.mjs +0 -23
  259. package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
  260. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
  261. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
  262. package/build-module/image-editor/core/index.mjs +0 -36
  263. package/build-module/image-editor/core/index.mjs.map +0 -7
  264. package/build-module/image-editor/core/interaction-controller.mjs +0 -635
  265. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
  266. package/build-module/image-editor/core/math/rotation.mjs +0 -15
  267. package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
  268. package/build-module/image-editor/core/math/sanitize.mjs +0 -63
  269. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
  270. package/build-module/image-editor/core/setter-helpers.mjs +0 -39
  271. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
  272. package/build-module/image-editor/core/source-region.mjs +0 -178
  273. package/build-module/image-editor/core/source-region.mjs.map +0 -7
  274. package/build-module/image-editor/core/state.mjs +0 -260
  275. package/build-module/image-editor/core/state.mjs.map +0 -7
  276. package/build-module/image-editor/core/stencil-math.mjs +0 -187
  277. package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
  278. package/build-module/image-editor/core/transform-style.mjs +0 -27
  279. package/build-module/image-editor/core/transform-style.mjs.map +0 -7
  280. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
  281. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
  282. package/build-module/image-editor/core/types.mjs +0 -1
  283. package/build-module/image-editor/core/types.mjs.map +0 -7
  284. package/build-module/image-editor/core/viewport-state.mjs +0 -24
  285. package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
  286. package/build-module/image-editor/index.mjs +0 -39
  287. package/build-module/image-editor/index.mjs.map +0 -7
  288. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
  289. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
  290. package/build-module/image-editor/react/components/cropper.mjs +0 -704
  291. package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
  292. package/build-module/image-editor/react/components/index.mjs +0 -9
  293. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  294. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
  295. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
  296. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
  297. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
  298. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
  299. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
  300. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
  301. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
  302. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
  303. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
  304. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
  305. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
  306. package/build-module/image-editor/react/hooks/index.mjs +0 -8
  307. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  308. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
  309. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -7
  310. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  311. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  312. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -190
  313. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
  314. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
  315. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
  316. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
  317. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
  318. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
  319. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -7
  320. package/build-module/index.mjs.map +0 -7
  321. package/build-module/state/index.mjs.map +0 -7
  322. package/build-module/utils/index.mjs.map +0 -7
  323. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -80
  324. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  325. package/build-types/image-editor/core/camera.d.ts +0 -128
  326. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  327. package/build-types/image-editor/core/constants.d.ts +0 -99
  328. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  329. package/build-types/image-editor/core/containment.d.ts +0 -72
  330. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  331. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  332. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  333. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  334. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  335. package/build-types/image-editor/core/index.d.ts +0 -10
  336. package/build-types/image-editor/core/index.d.ts.map +0 -1
  337. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  338. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  339. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  340. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  341. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  342. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  343. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  344. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  345. package/build-types/image-editor/core/source-region.d.ts +0 -94
  346. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  347. package/build-types/image-editor/core/state.d.ts +0 -51
  348. package/build-types/image-editor/core/state.d.ts.map +0 -1
  349. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  350. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  351. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  352. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  353. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  354. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  355. package/build-types/image-editor/core/types.d.ts +0 -269
  356. package/build-types/image-editor/core/types.d.ts.map +0 -1
  357. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  358. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  359. package/build-types/image-editor/index.d.ts +0 -16
  360. package/build-types/image-editor/index.d.ts.map +0 -1
  361. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  362. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  363. package/build-types/image-editor/react/components/cropper.d.ts +0 -63
  364. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  365. package/build-types/image-editor/react/components/index.d.ts +0 -4
  366. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  367. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  368. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  369. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  370. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  371. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  372. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  373. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  374. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  375. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  376. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  377. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  378. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  379. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  380. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  381. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  382. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  383. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
  384. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  385. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  386. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  387. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  388. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  389. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  390. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  391. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  392. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  393. package/src/components/media-editor-modal/build-modifiers.ts +0 -161
  394. package/src/image-editor/README.md +0 -61
  395. package/src/image-editor/core/camera.ts +0 -429
  396. package/src/image-editor/core/constants.ts +0 -150
  397. package/src/image-editor/core/containment.ts +0 -469
  398. package/src/image-editor/core/crop-rect.ts +0 -42
  399. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  400. package/src/image-editor/core/index.ts +0 -47
  401. package/src/image-editor/core/interaction-controller.ts +0 -976
  402. package/src/image-editor/core/math/rotation.ts +0 -26
  403. package/src/image-editor/core/math/sanitize.ts +0 -155
  404. package/src/image-editor/core/setter-helpers.ts +0 -63
  405. package/src/image-editor/core/source-region.ts +0 -367
  406. package/src/image-editor/core/state.ts +0 -484
  407. package/src/image-editor/core/stencil-math.ts +0 -379
  408. package/src/image-editor/core/transform-style.ts +0 -56
  409. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  410. package/src/image-editor/core/types.ts +0 -230
  411. package/src/image-editor/core/viewport-state.ts +0 -30
  412. package/src/image-editor/docs/architecture.md +0 -63
  413. package/src/image-editor/docs/recipes.md +0 -184
  414. package/src/image-editor/index.ts +0 -52
  415. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  416. package/src/image-editor/react/components/cropper.scss +0 -259
  417. package/src/image-editor/react/components/cropper.tsx +0 -1116
  418. package/src/image-editor/react/components/index.ts +0 -3
  419. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  420. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  421. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  422. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  423. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  424. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  425. package/src/image-editor/react/hooks/index.ts +0 -4
  426. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  427. package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
  428. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  429. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  430. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  431. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  432. package/src/image-editor/style.scss +0 -1
@@ -4,12 +4,15 @@ import {
4
4
  DropdownMenu,
5
5
  MenuGroup,
6
6
  MenuItem,
7
+ Modal,
7
8
  Spinner as WCSpinner,
8
9
  __experimentalConfirmDialog as ConfirmDialog,
10
+ __unstableAnimatePresence as AnimatePresence,
11
+ __unstableMotion as motion,
9
12
  } from '@wordpress/components';
10
13
  import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
11
- import { useViewportMatch } from '@wordpress/compose';
12
- import { useDispatch, useSelect } from '@wordpress/data';
14
+ import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
15
+ import { useDispatch, useRegistry, useSelect } from '@wordpress/data';
13
16
  import { store as coreStore } from '@wordpress/core-data';
14
17
  import { NavigableRegion } from '@wordpress/admin-ui';
15
18
  import {
@@ -18,10 +21,11 @@ import {
18
21
  useCallback,
19
22
  useContext,
20
23
  useEffect,
24
+ useMemo,
21
25
  useRef,
22
26
  useState,
23
27
  } from '@wordpress/element';
24
- import { __ } from '@wordpress/i18n';
28
+ import { __, _x, sprintf } from '@wordpress/i18n';
25
29
  import {
26
30
  backup,
27
31
  close,
@@ -37,12 +41,13 @@ import {
37
41
  isKeyboardEvent,
38
42
  } from '@wordpress/keycodes';
39
43
  import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
40
- import type { Field, Form } from '@wordpress/dataviews';
44
+ import type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';
41
45
  import type {
42
46
  KeyboardEvent as ReactKeyboardEvent,
43
47
  ReactElement,
44
48
  ReactNode,
45
49
  } from 'react';
50
+ import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
46
51
  import { MediaEditorProvider } from '../media-editor-provider';
47
52
  import type { Media } from '../media-editor-provider';
48
53
  import MediaPreview from '../media-preview';
@@ -53,7 +58,6 @@ import MediaEditorImageControls from '../media-editor-image-controls';
53
58
  import MediaForm from '../media-form';
54
59
  import { getMediaTypeFromMimeType } from '../../utils';
55
60
  import { MediaEditorStateProvider, useMediaEditor } from '../../state';
56
- import type { AspectRatioPreset } from '../../image-editor/core/constants';
57
61
  import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
58
62
  import MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';
59
63
  import {
@@ -83,6 +87,26 @@ const DETAILS_PANEL = 'details';
83
87
  /** Identifier for the crop panel. Images only; other media has nothing to crop. */
84
88
  const CROP_PANEL = 'crop';
85
89
 
90
+ // Matches the editor's sidebar in `ComplementaryArea`.
91
+ const SIDEBAR_ANIMATION_DURATION = 0.3;
92
+
93
+ type SidebarTransition = {
94
+ type: 'tween';
95
+ duration: number;
96
+ ease: number[];
97
+ };
98
+
99
+ const sidebarVariants = {
100
+ // `auto` leaves the width to the sidebar's stylesheet.
101
+ open: { width: 'auto' },
102
+ // Takes the transition from `AnimatePresence`'s `custom` prop, so a
103
+ // sidebar that is already closing still gets the current one.
104
+ closed: ( transition: SidebarTransition ) => ( {
105
+ width: 0,
106
+ transition,
107
+ } ),
108
+ };
109
+
86
110
  interface MediaEditorTab {
87
111
  id: string;
88
112
  title: string;
@@ -121,6 +145,8 @@ export interface MediaEditorProps {
121
145
  aspectRatioPresets?: AspectRatioPreset[];
122
146
  onClose?: () => void;
123
147
  onSaved?: ( result: MediaEditorSaveResult ) => void;
148
+ /** Called with the original's id when the user chooses "Edit original". */
149
+ onEditOriginal?: ( originalId: number ) => void;
124
150
  renderFrame: ( props: MediaEditorFrameProps ) => ReactElement;
125
151
  noticesClassName?: string;
126
152
  noticesPortalElement?: Element | null;
@@ -221,16 +247,21 @@ interface MediaEditorFrameContextValue {
221
247
  onSave: () => void;
222
248
  /**
223
249
  * When `true`, the media has a lineage root to restore to, so the
224
- * "Restore original image" menu item is shown.
250
+ * history menu shows its "Restore original" item.
225
251
  */
226
252
  canRestoreOriginal: boolean;
227
253
  /**
228
254
  * When `true`, another attachment has replaced the edited one in the
229
- * cropper this session (today, only the original), so the menu item is
255
+ * image editor this session (today, only the original), so the menu item is
230
256
  * disabled.
231
257
  */
232
258
  isSourceReplaced: boolean;
233
- /** Load the lineage root into the cropper as a dirty preview. */
259
+ /** Whether the frame opens the original itself. */
260
+ opensOriginal: boolean;
261
+ /**
262
+ * Load the lineage root into the image editor, or hand it to the
263
+ * frame.
264
+ */
234
265
  onRestoreOriginal: () => void;
235
266
  }
236
267
 
@@ -264,70 +295,108 @@ export interface HeaderActionsProps {
264
295
  showCloseButton?: boolean;
265
296
  }
266
297
 
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();
298
+ function PanelToggle() {
299
+ const { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();
279
300
  const isPanelOpen = !! activePanel;
280
- const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
301
+ // The sidebar holds more than one panel, so this opens and closes the
302
+ // sidebar rather than naming a panel: reopening returns to whichever tab
303
+ // was last showing, and the tab strip inside switches between them.
281
304
  return (
282
- <Stack
283
- className="media-editor__header-actions"
284
- justify="flex-end"
285
- align="center"
286
- gap="sm"
305
+ <Button
306
+ size="compact"
307
+ icon={ drawerRight }
308
+ label={ __( 'Media settings' ) }
309
+ isPressed={ isPanelOpen }
310
+ // Only a docked column really expands beside the canvas; below
311
+ // that the panel replaces the view, which the pressed state
312
+ // already describes.
313
+ aria-expanded={ isWide ? isPanelOpen : undefined }
314
+ onClick={ onTogglePanel }
315
+ />
316
+ );
317
+ }
318
+
319
+ function getActionLabel( action: Action< Media >, items: Media[] ) {
320
+ return typeof action.label === 'string'
321
+ ? action.label
322
+ : action.label( items );
323
+ }
324
+
325
+ interface MediaActionModalProps {
326
+ action: ActionModal< Media >;
327
+ items: Media[];
328
+ closeModal: () => void;
329
+ }
330
+
331
+ // A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't
332
+ // exported. It could be replaced if dataviews exports it.
333
+ function MediaActionModal( {
334
+ action,
335
+ items,
336
+ closeModal,
337
+ }: MediaActionModalProps ) {
338
+ const header =
339
+ typeof action.modalHeader === 'function'
340
+ ? action.modalHeader( items )
341
+ : action.modalHeader;
342
+ return (
343
+ <Modal
344
+ title={ header || getActionLabel( action, items ) }
345
+ __experimentalHideHeader={ !! action.hideModalHeader }
346
+ onRequestClose={ closeModal }
347
+ focusOnMount={ action.modalFocusOnMount ?? true }
348
+ size={ action.modalSize || 'medium' }
287
349
  >
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
- ) }
350
+ <action.RenderModal items={ items } closeModal={ closeModal } />
351
+ </Modal>
352
+ );
353
+ }
354
+
355
+ export interface MoreMenuProps {
356
+ /**
357
+ * Actions for the attachment, such as those from the entity actions API.
358
+ * Only the ones whose `isEligible` passes for `item` are shown.
359
+ */
360
+ actions?: Action< Media >[];
361
+ /**
362
+ * The attachment the actions apply to, with anything their `isEligible`
363
+ * checks need, such as `permissions`. Without it no actions are shown.
364
+ */
365
+ item?: Media;
366
+ }
367
+
368
+ function MoreMenu( { actions = [], item }: MoreMenuProps ) {
369
+ const { isImage, isSaving } = useMediaEditorFrameContext();
370
+ const registry = useRegistry();
371
+ const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
372
+ const [ activeModalAction, setActiveModalAction ] =
373
+ useState< ActionModal< Media > | null >( null );
374
+
375
+ const items = item ? [ item ] : [];
376
+ const eligibleActions = useMemo(
377
+ () =>
378
+ item
379
+ ? actions.filter(
380
+ ( action ) =>
381
+ ! action.isEligible || action.isEligible( item )
382
+ )
383
+ : [],
384
+ [ actions, item ]
385
+ );
386
+
387
+ if ( ! isImage && ! eligibleActions.length ) {
388
+ return null;
389
+ }
390
+ return (
391
+ <>
392
+ <DropdownMenu
393
+ icon={ moreVertical }
394
+ label={ __( 'More options' ) }
395
+ toggleProps={ { size: 'compact' } }
396
+ >
397
+ { ( { onClose: closeMenu } ) => (
398
+ <>
399
+ { isImage && (
331
400
  <MenuGroup>
332
401
  <MenuItem
333
402
  icon={ keyboard }
@@ -340,10 +409,78 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
340
409
  { __( 'Keyboard shortcuts' ) }
341
410
  </MenuItem>
342
411
  </MenuGroup>
343
- </>
344
- ) }
345
- </DropdownMenu>
412
+ ) }
413
+ { !! eligibleActions.length && (
414
+ <MenuGroup>
415
+ { eligibleActions.map( ( action ) => {
416
+ const label = getActionLabel(
417
+ action,
418
+ items
419
+ );
420
+ return (
421
+ <MenuItem
422
+ key={ action.id }
423
+ disabled={
424
+ isSaving || action.disabled
425
+ }
426
+ onClick={ () => {
427
+ closeMenu();
428
+ if ( 'RenderModal' in action ) {
429
+ setActiveModalAction(
430
+ action
431
+ );
432
+ return;
433
+ }
434
+ action.callback( items, {
435
+ registry,
436
+ } );
437
+ } }
438
+ >
439
+ { 'RenderModal' in action
440
+ ? sprintf(
441
+ /* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */
442
+ _x(
443
+ '%s…',
444
+ 'menu item requiring further input'
445
+ ),
446
+ label
447
+ )
448
+ : label }
449
+ </MenuItem>
450
+ );
451
+ } ) }
452
+ </MenuGroup>
453
+ ) }
454
+ </>
455
+ ) }
456
+ </DropdownMenu>
457
+ { isShortcutsModalOpen && (
458
+ <MediaEditorKeyboardShortcutsModal
459
+ onClose={ () => setIsShortcutsModalOpen( false ) }
460
+ />
461
+ ) }
462
+ { activeModalAction && (
463
+ <MediaActionModal
464
+ action={ activeModalAction }
465
+ items={ items }
466
+ closeModal={ () => setActiveModalAction( null ) }
467
+ />
346
468
  ) }
469
+ </>
470
+ );
471
+ }
472
+
473
+ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
474
+ const { isSaving, onCancel } = useMediaEditorFrameContext();
475
+ return (
476
+ <Stack
477
+ className="media-editor__header-actions"
478
+ justify="flex-end"
479
+ align="center"
480
+ gap="sm"
481
+ >
482
+ <PanelToggle />
483
+ <MoreMenu />
347
484
  { showCloseButton && (
348
485
  <Button
349
486
  size="compact"
@@ -354,18 +491,22 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
354
491
  accessibleWhenDisabled
355
492
  />
356
493
  ) }
357
- { isShortcutsModalOpen && (
358
- <MediaEditorKeyboardShortcutsModal
359
- onClose={ () => setIsShortcutsModalOpen( false ) }
360
- />
361
- ) }
362
494
  </Stack>
363
495
  );
364
496
  }
365
497
 
366
498
  function HistoryActions() {
367
- const { isImage, isUndoRedoDisabled, isWide, activePanel } =
368
- useMediaEditorFrameContext();
499
+ const {
500
+ isImage,
501
+ isSaving,
502
+ isUndoRedoDisabled,
503
+ isWide,
504
+ activePanel,
505
+ canRestoreOriginal,
506
+ isSourceReplaced,
507
+ opensOriginal,
508
+ onRestoreOriginal,
509
+ } = useMediaEditorFrameContext();
369
510
  const {
370
511
  reset,
371
512
  isDirty,
@@ -409,15 +550,6 @@ function HistoryActions() {
409
550
  align="center"
410
551
  gap="sm"
411
552
  >
412
- <Button
413
- size="compact"
414
- variant="tertiary"
415
- disabled={ isUndoRedoDisabled || ! isDirty }
416
- accessibleWhenDisabled
417
- onClick={ handleReset }
418
- >
419
- { __( 'Reset' ) }
420
- </Button>
421
553
  <Button
422
554
  size="compact"
423
555
  icon={ undo }
@@ -442,6 +574,50 @@ function HistoryActions() {
442
574
  accessibleWhenDisabled
443
575
  onClick={ handleRedo }
444
576
  />
577
+ <DropdownMenu
578
+ icon={ backup }
579
+ label={ __( 'History' ) }
580
+ popoverProps={ { placement: 'top-start' } }
581
+ toggleProps={ {
582
+ size: 'compact',
583
+ disabled:
584
+ isUndoRedoDisabled ||
585
+ ( ! isDirty && ! canRestoreOriginal ),
586
+ accessibleWhenDisabled: true,
587
+ } }
588
+ >
589
+ { ( { onClose: closeMenu } ) => (
590
+ <>
591
+ <MenuGroup>
592
+ <MenuItem
593
+ disabled={ isUndoRedoDisabled || ! isDirty }
594
+ onClick={ () => {
595
+ handleReset();
596
+ closeMenu();
597
+ } }
598
+ >
599
+ { __( 'Reset image edits' ) }
600
+ </MenuItem>
601
+ </MenuGroup>
602
+ { canRestoreOriginal && (
603
+ <MenuGroup>
604
+ <MenuItem
605
+ disabled={ isSourceReplaced || isSaving }
606
+ info={ __( 'Discards unsaved changes.' ) }
607
+ onClick={ () => {
608
+ onRestoreOriginal();
609
+ closeMenu();
610
+ } }
611
+ >
612
+ { opensOriginal
613
+ ? __( 'Edit original' )
614
+ : __( 'Restore original' ) }
615
+ </MenuItem>
616
+ </MenuGroup>
617
+ ) }
618
+ </>
619
+ ) }
620
+ </DropdownMenu>
445
621
  </Stack>
446
622
  );
447
623
  }
@@ -499,6 +675,7 @@ function MediaEditorContent( {
499
675
  aspectRatioPresets,
500
676
  onClose,
501
677
  onSaved,
678
+ onEditOriginal,
502
679
  renderFrame,
503
680
  noticesClassName = 'media-editor__snackbar',
504
681
  noticesPortalElement,
@@ -518,36 +695,26 @@ function MediaEditorContent( {
518
695
  // The choice is not carried across openings: the modal is transient, and
519
696
  // re-opening with the panel hidden on a wide screen is how #81487 read to
520
697
  // people in the first place. Within one opening it does hold — see
521
- // `hasChosenPanelRef` below.
698
+ // `chosenPanel` below.
522
699
  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
- }, [] );
700
+ // Below `small` the open panel replaces the canvas instead of sitting
701
+ // beside it, so there is nothing to animate.
702
+ const disableSidebarMotion = useReducedMotion() || ! isWide;
703
+ const sidebarTransition: SidebarTransition = {
704
+ type: 'tween',
705
+ duration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,
706
+ ease: [ 0.6, 0, 0.4, 1 ],
707
+ };
708
+ // Width picks the starting panel, but only until the user opens or closes
709
+ // it. After that their choice holds for the rest of the session: closing
710
+ // the panel and then resizing — or crossing the breakpoint by rotating a
711
+ // tablet — should not reopen something they just dismissed. `undefined`
712
+ // until then, otherwise `null` for closed or the open panel's id.
713
+ const [ chosenPanel, setChosenPanel ] = useState< string | null >();
714
+ // The tab the user picked, `null` until they pick one. Tracked separately
715
+ // from `chosenPanel` because the two answer different questions: whether
716
+ // the panel should be open, and which tab it should show.
717
+ const [ chosenTab, setChosenTab ] = useState< string | null >( null );
551
718
  // Below `small` a frame's header cannot fit the history cluster alongside
552
719
  // its own controls, so it moves that cluster elsewhere. The same width
553
720
  // undocks the panel, so this is `isWide` rather than a second query.
@@ -570,11 +737,11 @@ function MediaEditorContent( {
570
737
  const [ isPlacementActive, setIsPlacementActive ] = useState( false );
571
738
  const [ isCanvasGestureActive, setIsCanvasGestureActive ] =
572
739
  useState( false );
573
- // Whether another attachment has replaced `id` in the cropper this
740
+ // Whether another attachment has replaced `id` in the image editor this
574
741
  // session (today, the original via "Restore original image"). Stays a
575
- // distinct flag (not derived from the cropper) so a bare replacement
742
+ // distinct flag (not derived from the image editor) so a bare replacement
576
743
  // counts as a change even though swapping the source resets the
577
- // cropper's own dirty baseline.
744
+ // image editor's own dirty baseline.
578
745
  const [ isSourceReplaced, setIsSourceReplaced ] = useState( false );
579
746
  const placementControlTimerRef = useRef<
580
747
  ReturnType< typeof setTimeout > | undefined
@@ -601,17 +768,11 @@ function MediaEditorContent( {
601
768
  };
602
769
  }, [] );
603
770
 
604
- useEffect( () => {
605
- setIsPlacementActive( false );
606
- setIsCanvasGestureActive( false );
607
- setIsSourceReplaced( false );
608
- }, [ id ] );
609
-
610
771
  // Restore-original: the edit root the edited attachment descends from,
611
772
  // exposed by the server as the root-level `edit_root` id on the
612
773
  // attachment (edit context, embeddable via the `wp:edit-root` link).
613
774
  // Fetch the original's record for the URL and natural dimensions the
614
- // cropper needs to seed itself.
775
+ // image editor needs to seed itself.
615
776
  const originalId: number | undefined = sourceMedia?.edit_root;
616
777
  const originalRecord = useSelect(
617
778
  ( select ) =>
@@ -696,38 +857,46 @@ function MediaEditorContent( {
696
857
  // Restoring discards every pending edit, as the menu item says, so
697
858
  // nothing staged against the attachment being replaced reaches a save.
698
859
  clearEntityRecordEdits( 'postType', 'attachment', id );
860
+ if ( onEditOriginal && originalId ) {
861
+ onEditOriginal( originalId );
862
+ return;
863
+ }
699
864
  setIsSourceReplaced( true );
700
- }, [ clearEntityRecordEdits, id ] );
865
+ }, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );
701
866
 
702
- // A bare replacement has no cropper diff, so OR the flag in explicitly.
867
+ // A bare replacement has no image editor change, so OR the flag in explicitly.
703
868
  const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
704
869
 
705
870
  const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
706
871
  const isImage = !! media && mediaType === 'image';
707
872
 
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
873
  // Docked, the panel opens on Crop: the canvas is still beside it and
713
874
  // cropping is what the editor is for. Below `small` an open panel covers
714
875
  // the canvas, and crop controls with no crop in sight are not worth
715
876
  // 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 ] );
877
+ // all (see `tabs`), so it always gets Details.
878
+ const currentTab =
879
+ chosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );
880
+ // `null` when nothing is open, otherwise the open panel's id. Until the
881
+ // user opens or closes the panel, follow the breakpoint: dragging a window
882
+ // narrow hands the canvas the full width instead of leaving a panel
883
+ // wedged beside it.
884
+ let activePanel = chosenPanel;
885
+ if ( activePanel === undefined ) {
886
+ activePanel = isWide ? currentTab : null;
887
+ }
888
+ // Switching tabs says nothing about whether the panel should be open, so
889
+ // it leaves `chosenPanel` unset: picking Details on a wide screen and then
890
+ // dragging the window narrow should still hand the canvas the full width.
891
+ const selectPanel = useCallback( ( panel: string ) => {
892
+ setChosenTab( panel );
893
+ setChosenPanel( ( chosen ) =>
894
+ chosen === undefined ? chosen : panel
895
+ );
896
+ }, [] );
897
+ const togglePanel = useCallback( () => {
898
+ setChosenPanel( activePanel ? null : currentTab );
899
+ }, [ activePanel, currentTab ] );
731
900
  const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
732
901
  useCropOptions( { aspectRatioPresets } );
733
902
  const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
@@ -922,25 +1091,41 @@ function MediaEditorContent( {
922
1091
  </div>
923
1092
  ) }
924
1093
  </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
- ) }
1094
+ <AnimatePresence
1095
+ initial={ false }
1096
+ custom={ sidebarTransition }
1097
+ >
1098
+ { !! activePanel && (
1099
+ <motion.div
1100
+ className="media-editor__sidebar-container"
1101
+ variants={ sidebarVariants }
1102
+ initial="closed"
1103
+ animate="open"
1104
+ exit="closed"
1105
+ transition={ sidebarTransition }
1106
+ >
1107
+ <MediaEditorSidebar
1108
+ tabs={ tabs }
1109
+ // Swapping the edited media can drop the
1110
+ // Crop tab out from under an open panel —
1111
+ // saving a crop moves the editor to a new
1112
+ // id, which may resolve as non-image.
1113
+ // Fall back rather than hand `Tabs.Root`
1114
+ // a value no tab matches.
1115
+ activeTab={
1116
+ tabs.some(
1117
+ ( tab ) =>
1118
+ tab.id === activePanel
1119
+ )
1120
+ ? activePanel
1121
+ : DETAILS_PANEL
1122
+ }
1123
+ onSelectTab={ selectPanel }
1124
+ disabled={ isSaving }
1125
+ />
1126
+ </motion.div>
1127
+ ) }
1128
+ </AnimatePresence>
944
1129
  </div>
945
1130
  ) }
946
1131
  </div>
@@ -983,6 +1168,7 @@ function MediaEditorContent( {
983
1168
  onSave: saveMediaEditor,
984
1169
  canRestoreOriginal,
985
1170
  isSourceReplaced,
1171
+ opensOriginal: !! onEditOriginal,
986
1172
  onRestoreOriginal: handleRestoreOriginal,
987
1173
  };
988
1174
 
@@ -1015,6 +1201,8 @@ export function MediaEditor( props: MediaEditorProps ) {
1015
1201
  // `DataViewsPicker` exposes its own sub-components. They read what they need
1016
1202
  // from context, so a frame only chooses where they go and how they look.
1017
1203
  MediaEditor.HeaderActions = HeaderActions;
1204
+ MediaEditor.PanelToggle = PanelToggle;
1205
+ MediaEditor.MoreMenu = MoreMenu;
1018
1206
  MediaEditor.HistoryActions = HistoryActions;
1019
1207
  MediaEditor.SaveActions = SaveActions;
1020
1208