@wordpress/media-editor 0.22.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 (353) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/components/media-editor/index.cjs +74 -21
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +23 -3
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +6 -11
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +17 -1
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +4 -5
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +1 -0
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs.map +1 -1
  19. package/build/components/media-form/index.cjs +7 -1
  20. package/build/components/media-form/index.cjs.map +1 -1
  21. package/build/components/media-preview/index.cjs +0 -1
  22. package/build/components/media-preview/index.cjs.map +1 -1
  23. package/build/state/aspect-ratio-presets.cjs +10 -4
  24. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  25. package/build/state/composite-reducer.cjs +32 -67
  26. package/build/state/composite-reducer.cjs.map +1 -1
  27. package/build/state/index.cjs +0 -39
  28. package/build/state/types.cjs +1 -2
  29. package/build/state/types.cjs.map +1 -1
  30. package/build/state/use-media-editor-state.cjs +70 -106
  31. package/build/state/use-media-editor-state.cjs.map +1 -1
  32. package/build-module/components/media-editor/index.mjs +78 -25
  33. package/build-module/components/media-editor/index.mjs.map +1 -1
  34. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  35. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  36. package/build-module/components/media-editor/use-save-media-editor.mjs +23 -3
  37. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  38. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  39. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  40. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  41. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  42. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  43. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  44. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  45. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  46. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +1 -0
  47. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  48. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  49. package/build-module/components/media-form/index.mjs +7 -1
  50. package/build-module/components/media-form/index.mjs.map +1 -1
  51. package/build-module/components/media-preview/index.mjs +0 -1
  52. package/build-module/components/media-preview/index.mjs.map +1 -1
  53. package/build-module/state/aspect-ratio-presets.mjs +10 -5
  54. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  55. package/build-module/state/composite-reducer.mjs +32 -67
  56. package/build-module/state/composite-reducer.mjs.map +1 -1
  57. package/build-module/state/index.mjs +2 -5
  58. package/build-module/state/types.mjs +1 -2
  59. package/build-module/state/types.mjs.map +1 -1
  60. package/build-module/state/use-media-editor-state.mjs +70 -105
  61. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  62. package/build-style/style-rtl.css +104 -57
  63. package/build-style/style.css +103 -57
  64. package/build-types/components/media-editor/index.d.ts +17 -3
  65. package/build-types/components/media-editor/index.d.ts.map +1 -1
  66. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  67. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  68. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  69. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  70. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  71. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  72. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  73. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  74. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  75. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  76. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  77. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  78. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  79. package/build-types/components/media-form/index.d.ts.map +1 -1
  80. package/build-types/components/media-preview/index.d.ts.map +1 -1
  81. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  82. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  83. package/build-types/state/composite-reducer.d.ts +17 -19
  84. package/build-types/state/composite-reducer.d.ts.map +1 -1
  85. package/build-types/state/index.d.ts +2 -5
  86. package/build-types/state/index.d.ts.map +1 -1
  87. package/build-types/state/types.d.ts +20 -64
  88. package/build-types/state/types.d.ts.map +1 -1
  89. package/build-types/state/use-media-editor-state.d.ts +33 -52
  90. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  91. package/package.json +22 -23
  92. package/src/components/media-editor/index.tsx +163 -28
  93. package/src/components/media-editor/use-crop-options.ts +7 -11
  94. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  95. package/src/components/media-editor-canvas/index.tsx +15 -26
  96. package/src/components/media-editor-canvas/style.scss +6 -6
  97. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  98. package/src/components/media-editor-crop-panel/style.scss +21 -0
  99. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  100. package/src/components/media-editor-image-controls/index.tsx +11 -9
  101. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
  102. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  103. package/src/components/media-editor-modal/index.tsx +1 -1
  104. package/src/components/media-form/index.tsx +7 -1
  105. package/src/components/media-preview/index.tsx +0 -1
  106. package/src/components/rotation-ruler/style.scss +3 -3
  107. package/src/state/README.md +32 -0
  108. package/src/state/aspect-ratio-presets.ts +22 -3
  109. package/src/state/composite-reducer.ts +42 -80
  110. package/src/state/index.ts +2 -18
  111. package/src/state/types.ts +18 -68
  112. package/src/state/use-media-editor-state.ts +155 -240
  113. package/src/style.scss +2 -1
  114. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  115. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  116. package/build/image-editor/core/camera.cjs +0 -277
  117. package/build/image-editor/core/camera.cjs.map +0 -1
  118. package/build/image-editor/core/constants.cjs +0 -133
  119. package/build/image-editor/core/constants.cjs.map +0 -1
  120. package/build/image-editor/core/containment.cjs +0 -289
  121. package/build/image-editor/core/containment.cjs.map +0 -1
  122. package/build/image-editor/core/crop-rect.cjs +0 -37
  123. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  124. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  125. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  126. package/build/image-editor/core/index.cjs +0 -89
  127. package/build/image-editor/core/interaction-controller.cjs +0 -591
  128. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  129. package/build/image-editor/core/math/rotation.cjs +0 -32
  130. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  131. package/build/image-editor/core/math/sanitize.cjs +0 -136
  132. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  133. package/build/image-editor/core/setter-helpers.cjs +0 -61
  134. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  135. package/build/image-editor/core/source-region.cjs +0 -236
  136. package/build/image-editor/core/source-region.cjs.map +0 -1
  137. package/build/image-editor/core/state.cjs +0 -296
  138. package/build/image-editor/core/state.cjs.map +0 -1
  139. package/build/image-editor/core/stencil-math.cjs +0 -203
  140. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  141. package/build/image-editor/core/transform-style.cjs +0 -43
  142. package/build/image-editor/core/transform-style.cjs.map +0 -1
  143. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  144. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  145. package/build/image-editor/core/types.cjs +0 -5
  146. package/build/image-editor/core/viewport-state.cjs +0 -36
  147. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  148. package/build/image-editor/index.cjs +0 -68
  149. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  150. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  151. package/build/image-editor/react/components/cropper.cjs +0 -595
  152. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  153. package/build/image-editor/react/components/index.cjs +0 -25
  154. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  155. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  156. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  157. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  158. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  159. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  160. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  161. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  162. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  163. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  164. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  165. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  166. package/build/image-editor/react/hooks/index.cjs +0 -19
  167. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  168. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  169. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  170. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  171. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  172. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  173. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  174. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  175. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  176. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  177. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  178. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  179. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  180. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  181. package/build-module/image-editor/core/camera.mjs +0 -265
  182. package/build-module/image-editor/core/camera.mjs.map +0 -1
  183. package/build-module/image-editor/core/constants.mjs +0 -115
  184. package/build-module/image-editor/core/constants.mjs.map +0 -1
  185. package/build-module/image-editor/core/containment.mjs +0 -281
  186. package/build-module/image-editor/core/containment.mjs.map +0 -1
  187. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  188. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  189. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  190. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  191. package/build-module/image-editor/core/index.mjs +0 -7
  192. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  193. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  194. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  195. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  196. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  197. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  198. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  199. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  200. package/build-module/image-editor/core/source-region.mjs +0 -228
  201. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  202. package/build-module/image-editor/core/state.mjs +0 -288
  203. package/build-module/image-editor/core/state.mjs.map +0 -1
  204. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  205. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  206. package/build-module/image-editor/core/transform-style.mjs +0 -38
  207. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  208. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  209. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  210. package/build-module/image-editor/core/types.mjs +0 -0
  211. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  212. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  213. package/build-module/image-editor/index.mjs +0 -4
  214. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  215. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  216. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  217. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  218. package/build-module/image-editor/react/components/index.mjs +0 -3
  219. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  220. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  221. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  222. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  223. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  224. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  225. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  226. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  227. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  228. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  229. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  230. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  231. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  232. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  233. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  234. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  235. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  236. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  237. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  238. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  239. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  240. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  241. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  242. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  243. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  244. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  245. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  246. package/build-types/image-editor/core/camera.d.ts +0 -128
  247. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  248. package/build-types/image-editor/core/constants.d.ts +0 -98
  249. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  250. package/build-types/image-editor/core/containment.d.ts +0 -72
  251. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  252. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  253. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  254. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  255. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  256. package/build-types/image-editor/core/index.d.ts +0 -10
  257. package/build-types/image-editor/core/index.d.ts.map +0 -1
  258. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  259. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  260. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  261. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  262. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  263. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  264. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  265. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  266. package/build-types/image-editor/core/source-region.d.ts +0 -94
  267. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  268. package/build-types/image-editor/core/state.d.ts +0 -51
  269. package/build-types/image-editor/core/state.d.ts.map +0 -1
  270. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  271. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  272. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  273. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  274. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  275. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  276. package/build-types/image-editor/core/types.d.ts +0 -269
  277. package/build-types/image-editor/core/types.d.ts.map +0 -1
  278. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  279. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  280. package/build-types/image-editor/index.d.ts +0 -17
  281. package/build-types/image-editor/index.d.ts.map +0 -1
  282. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  283. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  284. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  285. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  286. package/build-types/image-editor/react/components/index.d.ts +0 -4
  287. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  288. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  289. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  290. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  291. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  292. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  293. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  294. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  295. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  296. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  297. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  298. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  299. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  300. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  301. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  302. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  303. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  304. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  305. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  306. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  307. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  308. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  309. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  310. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  311. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  312. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  313. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  314. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  315. package/src/image-editor/README.md +0 -61
  316. package/src/image-editor/core/camera.ts +0 -429
  317. package/src/image-editor/core/constants.ts +0 -137
  318. package/src/image-editor/core/containment.ts +0 -469
  319. package/src/image-editor/core/crop-rect.ts +0 -42
  320. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  321. package/src/image-editor/core/index.ts +0 -43
  322. package/src/image-editor/core/interaction-controller.ts +0 -976
  323. package/src/image-editor/core/math/rotation.ts +0 -26
  324. package/src/image-editor/core/math/sanitize.ts +0 -155
  325. package/src/image-editor/core/setter-helpers.ts +0 -63
  326. package/src/image-editor/core/source-region.ts +0 -367
  327. package/src/image-editor/core/state.ts +0 -484
  328. package/src/image-editor/core/stencil-math.ts +0 -379
  329. package/src/image-editor/core/transform-style.ts +0 -56
  330. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  331. package/src/image-editor/core/types.ts +0 -230
  332. package/src/image-editor/core/viewport-state.ts +0 -30
  333. package/src/image-editor/docs/architecture.md +0 -63
  334. package/src/image-editor/docs/recipes.md +0 -184
  335. package/src/image-editor/index.ts +0 -43
  336. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  337. package/src/image-editor/react/components/cropper.scss +0 -259
  338. package/src/image-editor/react/components/cropper.tsx +0 -1108
  339. package/src/image-editor/react/components/index.ts +0 -3
  340. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  341. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  342. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  343. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  344. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  345. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  346. package/src/image-editor/react/hooks/index.ts +0 -4
  347. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  348. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  349. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  350. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  351. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  352. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  353. package/src/image-editor/style.scss +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"use-media-editor-state.cjs","names":["ORIGINAL_ASPECT_RATIO","useReducer","mediaEditorReducer","buildInitialMediaEditorState","DEFAULT_STATE","useState","useRef","useCallback","areMediaEditorStatesEqual","useMemo","buildCropperSetters","enforceContainment","areCropperStatesEqual","exportCroppedImage"],"sources":["../../src/state/use-media-editor-state.ts"],"sourcesContent":["import {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport {\n\tORIGINAL_ASPECT_RATIO,\n\texportCroppedImage,\n\ttype CropperController,\n\ttype CropperState,\n\ttype NormalizedRect,\n\ttype Size,\n} from '../image-editor';\nimport {\n\tDEFAULT_STATE,\n\tareCropperStatesEqual,\n\tenforceContainment,\n\ttype CropperAction,\n} from '../image-editor/core';\nimport { buildCropperSetters } from '../image-editor/react/hooks';\nimport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nimport type {\n\tCropOptionsSlice,\n\tEditsSlice,\n\tEditValue,\n\tMediaEditorAction,\n\tMediaEditorState,\n} from './types';\n\n/**\n * Resolve an aspect-ratio preset value (the string the dropdown\n * round-trips) into a numeric width/height ratio for the cropper.\n *\n * - `'0'` → `undefined` (Free; no lock)\n * - `'-1'` (Original) → image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal → the parsed number.\n *\n * Centralizing here means the dropdown, the action dispatcher, and\n * the test harness all resolve the same way.\n *\n * @param presetKey Preset value from the dropdown.\n * @param cropperImage The cropper's loaded image, or `null`.\n * @return The resolved ratio, or `undefined` for Free / unresolvable.\n */\nexport function resolveAspectRatio(\n\tpresetKey: string,\n\tcropperImage: CropperState[ 'image' ] | null\n): number | undefined {\n\tconst num = parseFloat( presetKey );\n\tif ( num === 0 || Number.isNaN( num ) ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO ) {\n\t\tif (\n\t\t\tcropperImage &&\n\t\t\tcropperImage.naturalWidth > 0 &&\n\t\t\tcropperImage.naturalHeight > 0\n\t\t) {\n\t\t\treturn cropperImage.naturalWidth / cropperImage.naturalHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * The media editor session exposed by `useMediaEditorState`.\n *\n * The session owns what is being edited and how: the source image,\n * every editing slice, the shared undo/redo history, gesture\n * boundaries, and whether the edits change the saved image. The\n * cropper is one participant in the session — `cropper` is a\n * geometry-only controller that a `<Cropper>` takes via its\n * `controller` prop — rather than the session itself.\n */\nexport interface MediaEditorSession {\n\t/**\n\t * Geometry controller for the cropper slice. Its setters record\n\t * history in the session; its `isDirty` covers geometry only.\n\t * Its `setImage` is `setSourceImage`, so the `<Cropper>` reporting\n\t * a newly loaded image starts a fresh session.\n\t */\n\tcropper: CropperController;\n\t/** The cropOptions slice. */\n\tcropOptions: CropOptionsSlice;\n\t/** Set the aspect-ratio preset. Atomic with the cropRect reshape. */\n\tsetAspectRatioValue: ( presetKey: string ) => void;\n\t/**\n\t * Put every slice back to its starting state in one undo entry:\n\t * default geometry and crop options, no edits. Keeps the image.\n\t */\n\treset: () => void;\n\t/** The named edits other than crop, keyed by edit name. */\n\tedits: EditsSlice;\n\t/**\n\t * Set a named edit, or remove it by passing `undefined`. Recorded\n\t * in the session history like any crop change. Setting a value\n\t * equal in content to the current one is a no-op.\n\t */\n\tsetEdit: ( name: string, value: EditValue | undefined ) => void;\n\t/**\n\t * Replace the image being edited. A different image starts a\n\t * fresh session: default geometry and crop options, a clean\n\t * baseline, and no history. Reporting the same image again is a\n\t * no-op.\n\t */\n\tsetSourceImage: ( image: CropperState[ 'image' ] ) => void;\n\t/**\n\t * Whether anything in the session differs from its baseline,\n\t * including editor-only state such as the aspect-ratio preset.\n\t */\n\tisDirty: boolean;\n\t/**\n\t * Whether the edits change the saved image, so saving has to\n\t * produce new image output rather than only metadata.\n\t */\n\thasOutputEdits: boolean;\n\t/** Whether there's an undoable change in history. */\n\thasUndo: boolean;\n\t/** Whether there's a redoable change in history. */\n\thasRedo: boolean;\n\t/** Undo the last committed action across all slices. */\n\tundo: () => void;\n\t/** Redo the last undone action across all slices. */\n\tredo: () => void;\n\t/**\n\t * Open a gesture boundary. During a gesture all state-changing\n\t * actions coalesce into one undo entry — the snapshot taken at\n\t * `beginGesture`. Pair with `endGesture` on pointer-up / key-up.\n\t */\n\tbeginGesture: () => void;\n\t/** Close a gesture boundary and commit the pre-gesture snapshot. */\n\tendGesture: () => void;\n}\n\n/**\n * The media editor session.\n *\n * Owns the only undo/redo history for the editor. Cropper geometry\n * actions, sidebar cropOptions actions and named edits flow through\n * the same reducer and the same history stack.\n *\n * History semantics:\n * - Each action's pre-state is pushed to the undo stack before the\n * action commits, unless a gesture is open or the action is a\n * no-op (post-state value-equal to pre-state).\n * - During a gesture (`beginGesture` → `endGesture`) all mutations\n * coalesce: only the pre-gesture snapshot is pushed, at gesture\n * end. Any pending gesture is flushed on undo/redo.\n * - Viewport-driven cropRect reshapes (window resize) use a\n * dedicated non-recording dispatch path so they never produce\n * undo entries.\n *\n * `isDirty` tracks the full editor session, including undoable UI\n * state. Use `hasOutputEdits` when deciding whether the image output\n * needs saving.\n *\n * The session starts empty. Call `setSourceImage` to load an image.\n *\n * @return The media editor session.\n */\nexport function useMediaEditorState(): MediaEditorSession {\n\tconst [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>\n\t\tbuildInitialMediaEditorState( { ...DEFAULT_STATE } )\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setSourceImage` refreshes this when\n\t// a new image establishes a fresh baseline.\n\tconst [ initialBaseline, setInitialBaseline ] =\n\t\tuseState< MediaEditorState >( () => state );\n\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, dispatch wrapper). Every mutation path\n\t// (`dispatchWithHistory`, `setSourceImage`, `undo`, `redo`) writes this\n\t// synchronously, so multiple actions in one event see the latest\n\t// reducer output before React commits.\n\tconst stateRef = useRef( state );\n\tconst visualSizeRef = useRef< Size >( { width: 0, height: 0 } );\n\n\t// History stacks: full composite snapshots. Refs avoid re-renders\n\t// on every push; a boolean state pair drives the enabled/disabled\n\t// indicators for undo/redo buttons.\n\tconst historyRef = useRef< MediaEditorState[] >( [] );\n\tconst redoStackRef = useRef< MediaEditorState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Gesture state. While open, the first non-no-op action captures\n\t// the pre-gesture snapshot; subsequent actions don't push.\n\t// `endGesture` pushes the captured snapshot (or nothing, if the\n\t// gesture produced no changes).\n\tconst isGestureOpenRef = useRef( false );\n\tconst gestureSnapshotRef = useRef< MediaEditorState | null >( null );\n\n\tconst pushSnapshot = useCallback( ( snapshot: MediaEditorState ) => {\n\t\tconst last = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( last && areMediaEditorStatesEqual( last, snapshot ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, snapshot ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\t// Core dispatch wrapper. Synchronously computes the post-state via\n\t// the pure reducer so we can skip history pushes for no-op actions\n\t// and keep `stateRef` in lockstep with React's pending state.\n\tconst dispatchWithHistory = useCallback(\n\t\t( action: MediaEditorAction, recordHistory = true ) => {\n\t\t\tconst preState = stateRef.current;\n\t\t\tconst postState = mediaEditorReducer( preState, action );\n\t\t\tif ( recordHistory ) {\n\t\t\t\tif ( ! areMediaEditorStatesEqual( preState, postState ) ) {\n\t\t\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\t\t\tif ( gestureSnapshotRef.current === null ) {\n\t\t\t\t\t\t\tgestureSnapshotRef.current = preState;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpushSnapshot( preState );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tstateRef.current = postState;\n\t\t\tdispatch( action );\n\t\t},\n\t\t[ pushSnapshot ]\n\t);\n\n\tconst beginGesture = useCallback( () => {\n\t\tif ( isGestureOpenRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tisGestureOpenRef.current = true;\n\t\tgestureSnapshotRef.current = null;\n\t}, [] );\n\n\t// Close a gesture (or flush a pending one before undo/redo).\n\t// Pushes the pre-gesture snapshot only if it differs from current\n\t// state. Safe to call when no gesture is open.\n\tconst endGesture = useCallback( () => {\n\t\tconst snapshot = gestureSnapshotRef.current;\n\t\tif (\n\t\t\tsnapshot &&\n\t\t\t! areMediaEditorStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushSnapshot( snapshot );\n\t\t}\n\t\tgestureSnapshotRef.current = null;\n\t\tisGestureOpenRef.current = false;\n\t}, [ pushSnapshot ] );\n\n\t// =====================================================================\n\t// Cropper-slice setters (built from the shared factory so the pure\n\t// hook and this composite stay in lockstep — add a setter in\n\t// `buildCropperSetters` once and both hooks get it).\n\t// =====================================================================\n\n\tconst dispatchCropperAction = useCallback(\n\t\t( action: CropperAction ) => {\n\t\t\tdispatchWithHistory( { type: 'CROPPER', action } );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst cropperSetters = useMemo(\n\t\t() =>\n\t\t\tbuildCropperSetters(\n\t\t\t\tdispatchCropperAction,\n\t\t\t\t() => stateRef.current.cropper\n\t\t\t),\n\t\t[ dispatchCropperAction ]\n\t);\n\n\tconst setSourceImage = useCallback( ( image: CropperState[ 'image' ] ) => {\n\t\tif ( areCropperImagesEqual( stateRef.current.cropper.image, image ) ) {\n\t\t\treturn;\n\t\t}\n\t\t// New image = fresh session: default geometry and crop options, a\n\t\t// clean baseline, and no history. Built from defaults rather than\n\t\t// dispatching SET_IMAGE, which keeps the current pan / zoom /\n\t\t// rotation / flip / cropRect — edits made against one image must\n\t\t// not survive onto another.\n\t\tconst next = buildInitialMediaEditorState(\n\t\t\tenforceContainment( { ...DEFAULT_STATE, image } )\n\t\t);\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t\tsetInitialBaseline( next );\n\t\tisGestureOpenRef.current = false;\n\t\tgestureSnapshotRef.current = null;\n\t\thistoryRef.current = [];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( false );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\tconst resetCropper = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'CROPPER',\n\t\t\t\taction: { type: 'RESET', payload: resetState },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// CropOptions-slice setters\n\t// =====================================================================\n\n\tconst setAspectRatioValue = useCallback(\n\t\t( presetKey: string ) => {\n\t\t\tconst resolved = resolveAspectRatio(\n\t\t\t\tpresetKey,\n\t\t\t\tstateRef.current.cropper.image\n\t\t\t);\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_ASPECT_RATIO_VALUE',\n\t\t\t\tpayload: {\n\t\t\t\t\tpresetKey,\n\t\t\t\t\tresolved,\n\t\t\t\t\tvisualSize: visualSizeRef.current,\n\t\t\t\t},\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// Session\n\t// =====================================================================\n\n\tconst reset = useCallback( () => {\n\t\tdispatchWithHistory( { type: 'RESET' } );\n\t}, [ dispatchWithHistory ] );\n\n\t// =====================================================================\n\t// Edits-slice setters\n\t// =====================================================================\n\n\tconst setEdit = useCallback(\n\t\t( name: string, value: EditValue | undefined ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_EDIT',\n\t\t\t\tpayload: { name, value },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// History\n\t// =====================================================================\n\n\tconst undo = useCallback( () => {\n\t\tendGesture();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tstateRef.current = prev;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: prev } );\n\t}, [ endGesture ] );\n\n\tconst redo = useCallback( () => {\n\t\tendGesture();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t}, [ endGesture ] );\n\n\t// =====================================================================\n\t// Viewport\n\t// =====================================================================\n\n\tconst setVisualSize = useCallback( ( size: Size ) => {\n\t\tvisualSizeRef.current = size;\n\t}, [] );\n\n\tconst adjustCropRectForViewport = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatchWithHistory(\n\t\t\t\t{ type: 'VIEWPORT_ADJUST_CROP_RECT', payload: rect },\n\t\t\t\tfalse\n\t\t\t);\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// Derived\n\t// =====================================================================\n\n\tconst isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );\n\tconst isCropperDirty = ! areCropperStatesEqual(\n\t\tstate.cropper,\n\t\tinitialBaseline.cropper\n\t);\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.cropper.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded — call setSourceImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.cropper.image.src,\n\t\t\t\tstate.cropper,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state.cropper ]\n\t);\n\n\tconst cropper = useMemo< CropperController >(\n\t\t() => ( {\n\t\t\t...cropperSetters,\n\t\t\tstate: state.cropper,\n\t\t\tsetImage: setSourceImage,\n\t\t\treset: resetCropper,\n\t\t\tisDirty: isCropperDirty,\n\t\t\tgetCroppedImage,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t} ),\n\t\t[\n\t\t\tcropperSetters,\n\t\t\tstate.cropper,\n\t\t\tsetSourceImage,\n\t\t\tresetCropper,\n\t\t\tisCropperDirty,\n\t\t\tgetCroppedImage,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t]\n\t);\n\n\tconst session = useMemo< MediaEditorSession >(\n\t\t() => ( {\n\t\t\tcropper,\n\t\t\tcropOptions: state.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tedits: state.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\t// Only geometry changes the saved image so far.\n\t\t\thasOutputEdits: isCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t} ),\n\t\t[\n\t\t\tcropper,\n\t\t\tstate.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tstate.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\tisCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t]\n\t);\n\treturn session;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAgB,mBACf,WACA,cACqB;CACrB,MAAM,MAAM,WAAY,SAAU;CAClC,IAAK,QAAQ,KAAK,OAAO,MAAO,GAAI,GACnC;CAED,IAAK,QAAQA,yBAAAA,uBAAwB;EACpC,IACC,gBACA,aAAa,eAAe,KAC5B,aAAa,gBAAgB,GAE7B,OAAO,aAAa,eAAe,aAAa;EAEjD;CACD;CACA,IAAK,MAAM,GACV,OAAO;AAGT;AAEA,SAAS,sBACR,GACA,GACU;CACV,OACC,GAAG,QAAQ,GAAG,OACd,GAAG,iBAAiB,GAAG,gBACvB,GAAG,kBAAkB,GAAG;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,sBAA0C;CACzD,MAAM,CAAE,OAAO,aAAA,GAAaC,mBAAAA,WAAAA,CAAYC,uBAAAA,oBAAoB,aAAA,GAC3DC,uBAAAA,6BAAAA,CAA8B,EAAE,GAAGC,8BAAAA,cAAc,CAAE,CACpD;CAMA,MAAM,CAAE,iBAAiB,uBAAA,GACxBC,mBAAAA,SAAAA,OAAoC,KAAM;CAO3C,MAAM,YAAA,GAAWC,mBAAAA,OAAAA,CAAQ,KAAM;CAC/B,MAAM,iBAAA,GAAgBA,mBAAAA,OAAAA,CAAgB;EAAE,OAAO;EAAG,QAAQ;CAAE,CAAE;CAK9D,MAAM,cAAA,GAAaA,mBAAAA,OAAAA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AM,6BAAA,GAA4BA,mBAAAA,YAAAA,EAC/B,SAA0B;EAC3B,oBACC;GAAE,MAAM;GAA6B,SAAS;EAAK,GACnD,KACD;CACD,GACA,CAAE,mBAAoB,CACvB;CAMA,MAAM,UAAU,EAAA,GAAEC,uBAAAA,0BAAAA,CAA2B,OAAO,eAAgB;CACpE,MAAM,iBAAiB,EAAA,GAAEI,8BAAAA,sBAAAA,CACxB,MAAM,SACN,gBAAgB,OACjB;CAEA,MAAM,mBAAA,GAAkBL,mBAAAA,YAAAA,EACrB,UAAmB,YAAuC;EAC3D,IAAK,CAAE,MAAM,QAAQ,OACpB,OAAO,QAAQ,uBACd,IAAI,MAAO,8CAA+C,CAC3D;EAED,QAAA,GAAOM,yBAAAA,mBAAAA,CACN,MAAM,QAAQ,MAAM,KACpB,MAAM,SACN,UACA,OACD;CACD,GACA,CAAE,MAAM,OAAQ,CACjB;CAEA,MAAM,WAAA,GAAUJ,mBAAAA,QAAAA,QACP;EACP,GAAG;EACH,OAAO,MAAM;EACb,UAAU;EACV,OAAO;EACP,SAAS;EACT;EACA;EACA;CACD,IACA;EACC;EACA,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;CACD,CACD;CAuCA,QAAA,GArCgBA,mBAAAA,QAAAA,QACP;EACP;EACA,aAAa,MAAM;EACnB;EACA,OAAO,MAAM;EACb;EACA;EACA;EACA;EAEA,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA;CACD,IACA;EACC;EACA,MAAM;EACN;EACA,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAEY;AACd"}
1
+ {"version":3,"file":"use-media-editor-state.cjs","names":["ORIGINAL_ASPECT_RATIO","useReducer","mediaEditorReducer","buildInitialMediaEditorState","createImageEditorState","useState","useRef","useCallback","areMediaEditorStatesEqual","useImageEditor","useMemo"],"sources":["../../src/state/use-media-editor-state.ts"],"sourcesContent":["import {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport {\n\tcreateImageEditorState,\n\tuseImageEditor,\n\ttype ImageEditorController,\n\ttype ImageEditorState,\n} from '@wordpress/image-editor';\nimport { ORIGINAL_ASPECT_RATIO } from './aspect-ratio-presets';\nimport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nimport type {\n\tCropOptionsSlice,\n\tEditsSlice,\n\tEditValue,\n\tMediaEditorAction,\n\tMediaEditorState,\n} from './types';\n\n/**\n * Resolve an aspect-ratio preset value (the string the dropdown\n * round-trips) into a numeric width/height ratio for the image editor.\n *\n * - `'0'` → `undefined` (Free; no lock)\n * - `'-1'` (Original) → image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal → the parsed number.\n *\n * @param presetKey Preset value from the dropdown.\n * @param image The image editor's loaded image, or `null`.\n * @return The resolved ratio, or `undefined` for Free / unresolvable.\n */\nfunction resolveAspectRatio(\n\tpresetKey: string,\n\timage: ImageEditorState[ 'image' ] | null\n): number | undefined {\n\tconst num = parseFloat( presetKey );\n\tif ( num === 0 || Number.isNaN( num ) ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO ) {\n\t\tif ( image && image.naturalWidth > 0 && image.naturalHeight > 0 ) {\n\t\t\treturn image.naturalWidth / image.naturalHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\nfunction areImagesEqual(\n\ta: ImageEditorState[ 'image' ],\n\tb: ImageEditorState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * The media editor session exposed by `useMediaEditorState`.\n *\n * The session owns what is being edited and how: the source image,\n * every editing slice, the shared undo/redo history, gesture\n * boundaries, and whether the edits change the saved image. The\n * image editor is one participant in the session — `imageEditor` is the\n * controller an `<ImageEditorCanvas>` takes via its `controller` prop — rather\n * than the session itself.\n */\nexport interface MediaEditorSession {\n\t/**\n\t * Controller for the image editor. Its setters record history in the\n\t * session; its `isDirty` covers the crop only. Its `setImage` is\n\t * `setSourceImage`, so the `<ImageEditorCanvas>` reporting a newly loaded\n\t * image starts a fresh session.\n\t */\n\timageEditor: ImageEditorController;\n\t/** The cropOptions slice. */\n\tcropOptions: CropOptionsSlice;\n\t/** Set the aspect-ratio preset and reshape the crop in one undo entry. */\n\tsetAspectRatioValue: ( presetKey: string ) => void;\n\t/**\n\t * Put every slice back to its starting state in one undo entry:\n\t * default crop and crop options, no edits. Keeps the image.\n\t */\n\treset: () => void;\n\t/** The named edits other than crop, keyed by edit name. */\n\tedits: EditsSlice;\n\t/**\n\t * Set a named edit, or remove it by passing `undefined`. Recorded\n\t * in the session history like any crop change. Setting a value\n\t * equal in content to the current one is a no-op.\n\t */\n\tsetEdit: ( name: string, value: EditValue | undefined ) => void;\n\t/**\n\t * Replace the image being edited. A different image starts a\n\t * fresh session: default crop and crop options, a clean baseline,\n\t * and no history. Reporting the same image again is a no-op.\n\t */\n\tsetSourceImage: ( image: ImageEditorState[ 'image' ] ) => void;\n\t/**\n\t * Whether anything in the session differs from its baseline,\n\t * including editor-only state such as the aspect-ratio preset.\n\t */\n\tisDirty: boolean;\n\t/**\n\t * Whether the edits change the saved image, so saving has to\n\t * produce new image output rather than only metadata.\n\t */\n\thasOutputEdits: boolean;\n\t/** Whether there's an undoable change in history. */\n\thasUndo: boolean;\n\t/** Whether there's a redoable change in history. */\n\thasRedo: boolean;\n\t/** Undo the last committed change across all slices. */\n\tundo: () => void;\n\t/** Redo the last undone change across all slices. */\n\tredo: () => void;\n\t/**\n\t * Open a gesture boundary. During a gesture all changes coalesce\n\t * into one undo entry — the snapshot taken at `beginGesture`. Pair\n\t * with `endGesture` on pointer-up / key-up.\n\t */\n\tbeginGesture: () => void;\n\t/** Close a gesture boundary and commit the pre-gesture snapshot. */\n\tendGesture: () => void;\n}\n\n/**\n * The media editor session.\n *\n * Owns the only undo/redo history for the editor. The image editor's state,\n * the sidebar crop options and named edits are slices of one state, so\n * one history stack covers them all. The image editor works out its own\n * changes and reports each next state through `onChange`.\n *\n * History semantics:\n * - Each change pushes its pre-state to the undo stack, unless a\n * gesture is open or the change is a no-op (post-state value-equal\n * to pre-state).\n * - During a gesture (`beginGesture` → `endGesture`) changes coalesce:\n * only the pre-gesture snapshot is pushed, at gesture end. Undo and\n * redo close an open gesture first.\n * - Changes the image editor marks as not edits (an image loading, a refit\n * after a window resize) are never recorded.\n *\n * `isDirty` tracks the full session, including undoable UI state. Use\n * `hasOutputEdits` when deciding whether the image output needs saving.\n *\n * The session starts empty. Call `setSourceImage` to load an image.\n *\n * @return The media editor session.\n */\nexport function useMediaEditorState(): MediaEditorSession {\n\tconst [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>\n\t\tbuildInitialMediaEditorState( createImageEditorState() )\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. `setSourceImage` refreshes it when a new image starts a\n\t// fresh session.\n\tconst [ initialBaseline, setInitialBaseline ] =\n\t\tuseState< MediaEditorState >( () => state );\n\n\t// Latest state, so several actions in one event see each other's\n\t// output before React commits. Every mutation path writes it\n\t// synchronously.\n\tconst stateRef = useRef( state );\n\n\t// History stacks: full snapshots. Refs avoid re-renders on every\n\t// push; a boolean state pair drives the undo/redo indicators.\n\tconst historyRef = useRef< MediaEditorState[] >( [] );\n\tconst redoStackRef = useRef< MediaEditorState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Gesture state. While open, the first change captures the\n\t// pre-gesture snapshot; later changes don't push.\n\tconst isGestureOpenRef = useRef( false );\n\tconst gestureSnapshotRef = useRef< MediaEditorState | null >( null );\n\n\tconst pushSnapshot = useCallback( ( snapshot: MediaEditorState ) => {\n\t\tconst last = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( last && areMediaEditorStatesEqual( last, snapshot ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, snapshot ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\tconst dispatchWithHistory = useCallback(\n\t\t( action: MediaEditorAction, recordHistory = true ) => {\n\t\t\tconst preState = stateRef.current;\n\t\t\tconst postState = mediaEditorReducer( preState, action );\n\t\t\tif (\n\t\t\t\trecordHistory &&\n\t\t\t\t! areMediaEditorStatesEqual( preState, postState )\n\t\t\t) {\n\t\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\t\tif ( gestureSnapshotRef.current === null ) {\n\t\t\t\t\t\tgestureSnapshotRef.current = preState;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tpushSnapshot( preState );\n\t\t\t\t}\n\t\t\t}\n\t\t\tstateRef.current = postState;\n\t\t\tdispatch( action );\n\t\t},\n\t\t[ pushSnapshot ]\n\t);\n\n\tconst beginGesture = useCallback( () => {\n\t\tif ( isGestureOpenRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tisGestureOpenRef.current = true;\n\t\tgestureSnapshotRef.current = null;\n\t}, [] );\n\n\t// Close a gesture (or flush a pending one before undo/redo). Pushes\n\t// the pre-gesture snapshot only if it differs from the current\n\t// state. Safe to call when no gesture is open.\n\tconst endGesture = useCallback( () => {\n\t\tconst snapshot = gestureSnapshotRef.current;\n\t\tif (\n\t\t\tsnapshot &&\n\t\t\t! areMediaEditorStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushSnapshot( snapshot );\n\t\t}\n\t\tgestureSnapshotRef.current = null;\n\t\tisGestureOpenRef.current = false;\n\t}, [ pushSnapshot ] );\n\n\t// Run several changes as one undo entry, unless a gesture is already\n\t// open, which groups them anyway.\n\tconst asOneUndoEntry = useCallback(\n\t\t( run: () => void ) => {\n\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\trun();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbeginGesture();\n\t\t\trun();\n\t\t\tendGesture();\n\t\t},\n\t\t[ beginGesture, endGesture ]\n\t);\n\n\tconst setSourceImage = useCallback(\n\t\t( image: ImageEditorState[ 'image' ] ) => {\n\t\t\tif ( areImagesEqual( stateRef.current.imageEditor.image, image ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// New image = fresh session: default crop and crop options, a\n\t\t\t// clean baseline, and no history. Edits made against one\n\t\t\t// image must not survive onto another.\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcreateImageEditorState( { image } )\n\t\t\t);\n\t\t\tstateRef.current = next;\n\t\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t\t\tsetInitialBaseline( next );\n\t\t\tisGestureOpenRef.current = false;\n\t\t\tgestureSnapshotRef.current = null;\n\t\t\thistoryRef.current = [];\n\t\t\tredoStackRef.current = [];\n\t\t\tsetHasUndo( false );\n\t\t\tsetHasRedo( false );\n\t\t},\n\t\t[]\n\t);\n\n\tconst handleImageEditorChange = useCallback(\n\t\t( nextState: ImageEditorState, { isEdit }: { isEdit: boolean } ) => {\n\t\t\tif (\n\t\t\t\t! areImagesEqual(\n\t\t\t\t\tstateRef.current.imageEditor.image,\n\t\t\t\t\tnextState.image\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsetSourceImage( nextState.image );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdispatchWithHistory(\n\t\t\t\t{ type: 'SET_IMAGE_EDITOR', payload: nextState },\n\t\t\t\tisEdit\n\t\t\t);\n\t\t},\n\t\t[ dispatchWithHistory, setSourceImage ]\n\t);\n\n\tconst imageEditorController = useImageEditor( {\n\t\tstate: state.imageEditor,\n\t\tonChange: handleImageEditorChange,\n\t} );\n\n\t// The locked ratio has two owners: the preset the sidebar shows, and\n\t// the number the image editor holds. This is the only path that sets\n\t// both, so call it rather than `imageEditor.setAspectRatio`, which\n\t// would leave the sidebar showing a ratio the crop no longer has.\n\tconst setAspectRatioValue = useCallback(\n\t\t( presetKey: string ) => {\n\t\t\tasOneUndoEntry( () => {\n\t\t\t\tdispatchWithHistory( {\n\t\t\t\t\ttype: 'SET_ASPECT_RATIO_VALUE',\n\t\t\t\t\tpayload: presetKey,\n\t\t\t\t} );\n\t\t\t\timageEditorController.setAspectRatio(\n\t\t\t\t\tresolveAspectRatio(\n\t\t\t\t\t\tpresetKey,\n\t\t\t\t\t\tstateRef.current.imageEditor.image\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t} );\n\t\t},\n\t\t[ asOneUndoEntry, dispatchWithHistory, imageEditorController ]\n\t);\n\n\tconst reset = useCallback( () => {\n\t\tdispatchWithHistory( { type: 'RESET' } );\n\t}, [ dispatchWithHistory ] );\n\n\tconst setEdit = useCallback(\n\t\t( name: string, value: EditValue | undefined ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_EDIT',\n\t\t\t\tpayload: { name, value },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst undo = useCallback( () => {\n\t\tendGesture();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tstateRef.current = prev;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: prev } );\n\t}, [ endGesture ] );\n\n\tconst redo = useCallback( () => {\n\t\tendGesture();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t}, [ endGesture ] );\n\n\tconst imageEditor = useMemo< ImageEditorController >(\n\t\t() => ( { ...imageEditorController, setImage: setSourceImage } ),\n\t\t[ imageEditorController, setSourceImage ]\n\t);\n\n\tconst isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\timageEditor,\n\t\t\tcropOptions: state.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tedits: state.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\t// Only the crop changes the saved image so far.\n\t\t\t//\n\t\t\t// This reads the image editor's own clean state, not the\n\t\t\t// session's. The two agree because the session only ever\n\t\t\t// replaces the editor's slice with a state the editor handed\n\t\t\t// out, and because a fresh state for an image matches the\n\t\t\t// default one on every field `isDirty` compares. Change\n\t\t\t// either and this has to compare against the session's\n\t\t\t// baseline instead.\n\t\t\thasOutputEdits: imageEditor.isDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t} ),\n\t\t[\n\t\t\timageEditor,\n\t\t\tstate.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tstate.edits,\n\t\t\tsetEdit,\n\t\t\tsetSourceImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t]\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,mBACR,WACA,OACqB;CACrB,MAAM,MAAM,WAAY,SAAU;CAClC,IAAK,QAAQ,KAAK,OAAO,MAAO,GAAI,GACnC;CAED,IAA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AAU,CAAE,SAAS,SAAS,GAAG,aAAa,OAAQ;EACnE,WAAW,UAAU,WAAW,QAAQ,MAAO,GAAG,EAAG;EACrD,WAAY,WAAW,QAAQ,SAAS,CAAE;EAC1C,WAAY,IAAK;EACjB,SAAS,UAAU;EACnB,SAAU;GAAE,MAAM;GAAoB,SAAS;EAAK,CAAE;CACvD,GAAG,CAAE,UAAW,CAAE;CAElB,MAAM,QAAA,GAAOA,mBAAAA,YAAAA,OAAmB;EAC/B,WAAW;EACX,MAAM,OAAO,aAAa,QAAS;EACnC,IAAK,CAAE,MACN;EAED,WAAW,UAAU,CAAE,GAAG,WAAW,SAAS,SAAS,OAAQ;EAC/D,aAAa,UAAU,aAAa,QAAQ,MAAO,CAAE;EACrD,WAAY,IAAK;EACjB,WAAY,aAAa,QAAQ,SAAS,CAAE;EAC5C,SAAS,UAAU;EACnB,SAAU;GAAE,MAAM;GAAoB,SAAS;EAAK,CAAE;CACvD,GAAG,CAAE,UAAW,CAAE;CAElB,MAAM,eAAA,GAAcG,mBAAAA,QAAAA,QACX;EAAE,GAAG;EAAuB,UAAU;CAAe,IAC7D,CAAE,uBAAuB,cAAe,CACzC;CAEA,MAAM,UAAU,EAAA,GAAEF,uBAAAA,0BAAAA,CAA2B,OAAO,eAAgB;CAEpE,QAAA,GAAOE,mBAAAA,QAAAA,QACE;EACP;EACA,aAAa,MAAM;EACnB;EACA,OAAO,MAAM;EACb;EACA;EACA;EACA;EAUA,gBAAgB,YAAY;EAC5B;EACA;EACA;EACA;EACA;EACA;CACD,IACA;EACC;EACA,MAAM;EACN;EACA,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CACD;AACD"}
@@ -1,12 +1,12 @@
1
1
  import clsx from "clsx";
2
- import { Button, DropdownMenu, MenuGroup, MenuItem, Spinner, __experimentalConfirmDialog, __unstableAnimatePresence, __unstableMotion } from "@wordpress/components";
2
+ import { Button, DropdownMenu, MenuGroup, MenuItem, Modal, Spinner, __experimentalConfirmDialog, __unstableAnimatePresence, __unstableMotion } from "@wordpress/components";
3
3
  import { Stack, Tabs, VisuallyHidden } from "@wordpress/ui";
4
4
  import { useReducedMotion, useViewportMatch } from "@wordpress/compose";
5
- import { useDispatch, useSelect } from "@wordpress/data";
5
+ import { useDispatch, useRegistry, useSelect } from "@wordpress/data";
6
6
  import { store } from "@wordpress/core-data";
7
7
  import { NavigableRegion } from "@wordpress/admin-ui";
8
- import { createContext, createPortal, useCallback, useContext, useEffect, useRef, useState } from "@wordpress/element";
9
- import { __ } from "@wordpress/i18n";
8
+ import { createContext, createPortal, useCallback, useContext, useEffect, useMemo, useRef, useState } from "@wordpress/element";
9
+ import { __, _x, sprintf } from "@wordpress/i18n";
10
10
  import { backup, close, drawerRight, keyboard, moreVertical, redo, undo } from "@wordpress/icons";
11
11
  import { displayShortcut, isAppleOS, isKeyboardEvent } from "@wordpress/keycodes";
12
12
  import { SnackbarNotices, store as store$1 } from "@wordpress/notices";
@@ -103,24 +103,67 @@ function PanelToggle() {
103
103
  onClick: onTogglePanel
104
104
  });
105
105
  }
106
- function MoreMenu() {
107
- const { isImage } = useMediaEditorFrameContext();
106
+ function getActionLabel(action, items) {
107
+ return typeof action.label === "string" ? action.label : action.label(items);
108
+ }
109
+ function MediaActionModal({ action, items, closeModal }) {
110
+ const header = typeof action.modalHeader === "function" ? action.modalHeader(items) : action.modalHeader;
111
+ return /* @__PURE__ */ jsx(Modal, {
112
+ title: header || getActionLabel(action, items),
113
+ __experimentalHideHeader: !!action.hideModalHeader,
114
+ onRequestClose: closeModal,
115
+ focusOnMount: action.modalFocusOnMount ?? true,
116
+ size: action.modalSize || "medium",
117
+ children: /* @__PURE__ */ jsx(action.RenderModal, {
118
+ items,
119
+ closeModal
120
+ })
121
+ });
122
+ }
123
+ function MoreMenu({ actions = [], item }) {
124
+ const { isImage, isSaving } = useMediaEditorFrameContext();
125
+ const registry = useRegistry();
108
126
  const [isShortcutsModalOpen, setIsShortcutsModalOpen] = useState(false);
109
- if (!isImage) return null;
110
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(DropdownMenu, {
111
- icon: moreVertical,
112
- label: __("More options"),
113
- toggleProps: { size: "compact" },
114
- children: ({ onClose: closeMenu }) => /* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(MenuItem, {
115
- icon: keyboard,
116
- iconPosition: "left",
117
- onClick: () => {
118
- setIsShortcutsModalOpen(true);
119
- closeMenu();
120
- },
121
- children: __("Keyboard shortcuts")
122
- }) })
123
- }), isShortcutsModalOpen && /* @__PURE__ */ jsx(MediaEditorKeyboardShortcutsModal, { onClose: () => setIsShortcutsModalOpen(false) })] });
127
+ const [activeModalAction, setActiveModalAction] = useState(null);
128
+ const items = item ? [item] : [];
129
+ const eligibleActions = useMemo(() => item ? actions.filter((action) => !action.isEligible || action.isEligible(item)) : [], [actions, item]);
130
+ if (!isImage && !eligibleActions.length) return null;
131
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
132
+ /* @__PURE__ */ jsx(DropdownMenu, {
133
+ icon: moreVertical,
134
+ label: __("More options"),
135
+ toggleProps: { size: "compact" },
136
+ children: ({ onClose: closeMenu }) => /* @__PURE__ */ jsxs(Fragment, { children: [isImage && /* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(MenuItem, {
137
+ icon: keyboard,
138
+ iconPosition: "left",
139
+ onClick: () => {
140
+ setIsShortcutsModalOpen(true);
141
+ closeMenu();
142
+ },
143
+ children: __("Keyboard shortcuts")
144
+ }) }), !!eligibleActions.length && /* @__PURE__ */ jsx(MenuGroup, { children: eligibleActions.map((action) => {
145
+ const label = getActionLabel(action, items);
146
+ return /* @__PURE__ */ jsx(MenuItem, {
147
+ disabled: isSaving || action.disabled,
148
+ onClick: () => {
149
+ closeMenu();
150
+ if ("RenderModal" in action) {
151
+ setActiveModalAction(action);
152
+ return;
153
+ }
154
+ action.callback(items, { registry });
155
+ },
156
+ children: "RenderModal" in action ? sprintf(_x("%s…", "menu item requiring further input"), label) : label
157
+ }, action.id);
158
+ }) })] })
159
+ }),
160
+ isShortcutsModalOpen && /* @__PURE__ */ jsx(MediaEditorKeyboardShortcutsModal, { onClose: () => setIsShortcutsModalOpen(false) }),
161
+ activeModalAction && /* @__PURE__ */ jsx(MediaActionModal, {
162
+ action: activeModalAction,
163
+ items,
164
+ closeModal: () => setActiveModalAction(null)
165
+ })
166
+ ] });
124
167
  }
125
168
  function HeaderActions({ showCloseButton = false }) {
126
169
  const { isSaving, onCancel } = useMediaEditorFrameContext();
@@ -144,7 +187,7 @@ function HeaderActions({ showCloseButton = false }) {
144
187
  });
145
188
  }
146
189
  function HistoryActions() {
147
- const { isImage, isSaving, isUndoRedoDisabled, isWide, activePanel, canRestoreOriginal, isSourceReplaced, onRestoreOriginal } = useMediaEditorFrameContext();
190
+ const { isImage, isSaving, isUndoRedoDisabled, isWide, activePanel, canRestoreOriginal, isSourceReplaced, opensOriginal, onRestoreOriginal } = useMediaEditorFrameContext();
148
191
  const { reset, isDirty, hasUndo, hasRedo, undo: undoCrop, redo: redoCrop } = useMediaEditor();
149
192
  if (!isImage || !isWide && !!activePanel) return null;
150
193
  const handleUndo = () => {
@@ -207,7 +250,7 @@ function HistoryActions() {
207
250
  onRestoreOriginal();
208
251
  closeMenu();
209
252
  },
210
- children: __("Restore original")
253
+ children: opensOriginal ? __("Edit original") : __("Restore original")
211
254
  }) })] })
212
255
  })
213
256
  ]
@@ -241,7 +284,7 @@ function SaveActions({ size = "default" }) {
241
284
  })]
242
285
  });
243
286
  }
244
- function MediaEditorContent({ fields = [], form, id, aspectRatioPresets, onClose, onSaved, renderFrame, noticesClassName = "media-editor__snackbar", noticesPortalElement, shouldCloseOnEsc = false }) {
287
+ function MediaEditorContent({ fields = [], form, id, aspectRatioPresets, onClose, onSaved, onEditOriginal, renderFrame, noticesClassName = "media-editor__snackbar", noticesPortalElement, shouldCloseOnEsc = false }) {
245
288
  const session = useMediaEditor();
246
289
  const isWide = useViewportMatch("small");
247
290
  const sidebarTransition = {
@@ -319,8 +362,17 @@ function MediaEditorContent({ fields = [], form, id, aspectRatioPresets, onClose
319
362
  }, [activeId, invalidateResolution]);
320
363
  const handleRestoreOriginal = useCallback(() => {
321
364
  clearEntityRecordEdits("postType", "attachment", id);
365
+ if (onEditOriginal && originalId) {
366
+ onEditOriginal(originalId);
367
+ return;
368
+ }
322
369
  setIsSourceReplaced(true);
323
- }, [clearEntityRecordEdits, id]);
370
+ }, [
371
+ clearEntityRecordEdits,
372
+ id,
373
+ onEditOriginal,
374
+ originalId
375
+ ]);
324
376
  const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
325
377
  const mediaType = getMediaTypeFromMimeType(media?.mime_type).type;
326
378
  const isImage = !!media && mediaType === "image";
@@ -493,6 +545,7 @@ function MediaEditorContent({ fields = [], form, id, aspectRatioPresets, onClose
493
545
  onSave: saveMediaEditor,
494
546
  canRestoreOriginal,
495
547
  isSourceReplaced,
548
+ opensOriginal: !!onEditOriginal,
496
549
  onRestoreOriginal: handleRestoreOriginal
497
550
  };
498
551
  return /* @__PURE__ */ jsx(MediaEditorFrameContext.Provider, {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["coreStore","noticesStore","WCSpinner","AnimatePresence","motion","ConfirmDialog"],"sources":["../../../src/components/media-editor/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tButton,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tSpinner as WCSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\t__unstableAnimatePresence as AnimatePresence,\n\t__unstableMotion as motion,\n} from '@wordpress/components';\nimport { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';\nimport { useReducedMotion, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { NavigableRegion } from '@wordpress/admin-ui';\nimport {\n\tcreateContext,\n\tcreatePortal,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tbackup,\n\tclose,\n\tdrawerRight,\n\tkeyboard,\n\tmoreVertical,\n\tredo,\n\tundo,\n} from '@wordpress/icons';\nimport {\n\tdisplayShortcut,\n\tisAppleOS,\n\tisKeyboardEvent,\n} from '@wordpress/keycodes';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type {\n\tKeyboardEvent as ReactKeyboardEvent,\n\tReactElement,\n\tReactNode,\n} from 'react';\nimport { MediaEditorProvider } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport MediaPreview from '../media-preview';\nimport MediaEditorCanvas from '../media-editor-canvas';\nimport MediaEditorFineRotation from '../media-editor-fine-rotation';\nimport MediaEditorCropPanel from '../media-editor-crop-panel';\nimport MediaEditorImageControls from '../media-editor-image-controls';\nimport MediaForm from '../media-form';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { MediaEditorStateProvider, useMediaEditor } from '../../state';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';\nimport {\n\tMEDIA_EDITOR_NOTICES_CONTEXT,\n\tuseSaveMediaEditor,\n\ttype MediaEditorSaveResult,\n} from './use-save-media-editor';\nimport { useCropOptions } from './use-crop-options';\n\nexport type { MediaEditorSaveResult } from './use-save-media-editor';\n\n// Embed query for the attachment's author and parent post. Shared between\n// the `getEntityRecord` read and the matching `invalidateResolution` so the\n// two stay in lockstep.\nconst ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;\n\nconst PLACEMENT_CONTROL_IDLE_MS = 300;\n\n/**\n * Identifier for the details panel, and the panel the sidebar opens on before\n * the user picks another. The sidebar tracks which panel is open rather than\n * whether one is, so a further panel is a new id here and a new entry in the\n * tab list — not a change to the state's shape.\n */\nconst DETAILS_PANEL = 'details';\n\n/** Identifier for the crop panel. Images only; other media has nothing to crop. */\nconst CROP_PANEL = 'crop';\n\n// Matches the editor's sidebar in `ComplementaryArea`.\nconst SIDEBAR_ANIMATION_DURATION = 0.3;\n\ntype SidebarTransition = {\n\ttype: 'tween';\n\tduration: number;\n\tease: number[];\n};\n\nconst sidebarVariants = {\n\t// `auto` leaves the width to the sidebar's stylesheet.\n\topen: { width: 'auto' },\n\t// Takes the transition from `AnimatePresence`'s `custom` prop, so a\n\t// sidebar that is already closing still gets the current one.\n\tclosed: ( transition: SidebarTransition ) => ( {\n\t\twidth: 0,\n\t\ttransition,\n\t} ),\n};\n\ninterface MediaEditorTab {\n\tid: string;\n\ttitle: string;\n\trender: () => ReactElement;\n}\n\nexport interface MediaEditorFrameProps {\n\tchildren: ReactNode;\n\t/**\n\t * Whether the media being edited is an image. The history and transform\n\t * clusters render nothing for other media types, so a frame uses this to\n\t * decide whether the container it would put them in is worth rendering at\n\t * all.\n\t */\n\tisImage: boolean;\n\t/**\n\t * `narrow` below the `small` breakpoint, where the frame's header has no\n\t * room for the history cluster beside its other controls. A frame uses\n\t * this to place that cluster, not to decide whether it renders —\n\t * `HistoryActions` returns nothing on its own when the canvas is off\n\t * screen.\n\t */\n\tlayout: 'wide' | 'narrow';\n\tonRequestClose: () => void;\n\tonKeyDown: ( event: ReactKeyboardEvent< HTMLElement > ) => void;\n\tshouldCloseOnClickOutside: boolean;\n\tisSaving: boolean;\n\thasChanges: boolean;\n\thasMedia: boolean;\n}\n\nexport interface MediaEditorProps {\n\tfields?: Field< Media >[];\n\tform?: Form;\n\tid: number;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonClose?: () => void;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\trenderFrame: ( props: MediaEditorFrameProps ) => ReactElement;\n\tnoticesClassName?: string;\n\tnoticesPortalElement?: Element | null;\n\tshouldCloseOnEsc?: boolean;\n}\n\ninterface MediaEditorSidebarProps {\n\ttabs: MediaEditorTab[];\n\t/** The open panel's id. Always one of `tabs`. */\n\tactiveTab: string;\n\tonSelectTab: ( tab: string ) => void;\n\t/** Freeze the open panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\nfunction MediaEditorSidebar( {\n\ttabs,\n\tactiveTab,\n\tonSelectTab,\n\tdisabled = false,\n}: MediaEditorSidebarProps ) {\n\treturn (\n\t\t<NavigableRegion\n\t\t\tclassName=\"media-editor__sidebar\"\n\t\t\tariaLabel={ __( 'Media settings' ) }\n\t\t>\n\t\t\t{ /* No visible heading and no close button: the strip below names\n\t\t\t the open panel and the header's pressed toggle dismisses it.\n\t\t\t The heading stays for screen readers, which read neither as\n\t\t\t this region's title. */ }\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Media settings' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Tabs.Root\n\t\t\t\tclassName=\"media-editor__tabs\"\n\t\t\t\tvalue={ activeTab }\n\t\t\t\tonValueChange={ onSelectTab }\n\t\t\t>\n\t\t\t\t{ /* `Tabs.List` sizes itself to its tabs (`width: fit-content`),\n\t\t\t\t so the rule under the strip is drawn by this wrapper\n\t\t\t\t instead, which spans the column. */ }\n\t\t\t\t<div className=\"media-editor__tablist\">\n\t\t\t\t\t<Tabs.List variant=\"minimal\">\n\t\t\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t\t\t<Tabs.Tab\n\t\t\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ tab.title }\n\t\t\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Tabs.List>\n\t\t\t\t</div>\n\t\t\t\t{ /* One `Tabs.Panel` per tab: the counts have to match or\n\t\t\t\t `Tabs.Root` throws in dev. Only the active one paints\n\t\t\t\t anything — the rest render nothing. */ }\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<Tabs.Panel\n\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"column\" gap=\"lg\">\n\t\t\t\t\t\t\t{ tab.render() }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t</Tabs.Panel>\n\t\t\t\t) ) }\n\t\t\t</Tabs.Root>\n\t\t</NavigableRegion>\n\t);\n}\n\n/**\n * Everything the frame's action clusters need from the editor. Supplied by\n * context rather than by props so the clusters can be module-level components:\n * a component created during a render has a new identity on every pass, which\n * remounts its subtree and drops focus mid-interaction.\n */\ninterface MediaEditorFrameContextValue {\n\tisImage: boolean;\n\tisSaving: boolean;\n\thasMedia: boolean;\n\thasChanges: boolean;\n\tisUndoRedoDisabled: boolean;\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/** `true` above `large`, where the panel docks beside the canvas. */\n\tisWide: boolean;\n\t/** The open panel's id, or `null` when none is. */\n\tactivePanel: string | null;\n\t/**\n\t * Opens the sidebar on the last-shown panel, or closes it when one is\n\t * already open.\n\t */\n\tonTogglePanel: () => void;\n\tonCancel: () => void;\n\tonSave: () => void;\n\t/**\n\t * When `true`, the media has a lineage root to restore to, so the\n\t * history menu shows its \"Restore original\" item.\n\t */\n\tcanRestoreOriginal: boolean;\n\t/**\n\t * When `true`, another attachment has replaced the edited one in the\n\t * cropper this session (today, only the original), so the menu item is\n\t * disabled.\n\t */\n\tisSourceReplaced: boolean;\n\t/** Load the lineage root into the cropper as a dirty preview. */\n\tonRestoreOriginal: () => void;\n}\n\nconst MediaEditorFrameContext =\n\tcreateContext< MediaEditorFrameContextValue | null >( null );\n\n/**\n * Hook to access the media editor's frame context.\n *\n * Must be used within a MediaEditor component.\n *\n * @return MediaEditorFrameContextValue the action clusters render from.\n */\nfunction useMediaEditorFrameContext(): MediaEditorFrameContextValue {\n\tconst context = useContext( MediaEditorFrameContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorFrameContext must be used within MediaEditor'\n\t\t);\n\t}\n\treturn context;\n}\n\nexport interface HeaderActionsProps {\n\t/**\n\t * Whether to include a Close button. Frames with a dismissal affordance of\n\t * their own — a route's breadcrumbs, say — leave it out.\n\t *\n\t * @default false\n\t */\n\tshowCloseButton?: boolean;\n}\n\nfunction PanelToggle() {\n\tconst { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();\n\tconst isPanelOpen = !! activePanel;\n\t// The sidebar holds more than one panel, so this opens and closes the\n\t// sidebar rather than naming a panel: reopening returns to whichever tab\n\t// was last showing, and the tab strip inside switches between them.\n\treturn (\n\t\t<Button\n\t\t\tsize=\"compact\"\n\t\t\ticon={ drawerRight }\n\t\t\tlabel={ __( 'Media settings' ) }\n\t\t\tisPressed={ isPanelOpen }\n\t\t\t// Only a docked column really expands beside the canvas; below\n\t\t\t// that the panel replaces the view, which the pressed state\n\t\t\t// already describes.\n\t\t\taria-expanded={ isWide ? isPanelOpen : undefined }\n\t\t\tonClick={ onTogglePanel }\n\t\t/>\n\t);\n}\n\nfunction MoreMenu() {\n\tconst { isImage } = useMediaEditorFrameContext();\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\n\tif ( ! isImage ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ moreVertical }\n\t\t\t\tlabel={ __( 'More options' ) }\n\t\t\t\ttoggleProps={ { size: 'compact' } }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\ticon={ keyboard }\n\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetIsShortcutsModalOpen( true );\n\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Keyboard shortcuts' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ isShortcutsModalOpen && (\n\t\t\t\t<MediaEditorKeyboardShortcutsModal\n\t\t\t\t\tonClose={ () => setIsShortcutsModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {\n\tconst { isSaving, onCancel } = useMediaEditorFrameContext();\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__header-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<PanelToggle />\n\t\t\t<MoreMenu />\n\t\t\t{ showCloseButton && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ close }\n\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\tonClick={ onCancel }\n\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction HistoryActions() {\n\tconst {\n\t\tisImage,\n\t\tisSaving,\n\t\tisUndoRedoDisabled,\n\t\tisWide,\n\t\tactivePanel,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\tonRestoreOriginal,\n\t} = useMediaEditorFrameContext();\n\tconst {\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t} = useMediaEditor();\n\t// Reset, undo and redo act on the image edits, so they only appear where\n\t// the canvas does. Non-image media has no edit history at all; below the dock\n\t// breakpoint an open panel replaces the canvas, and leaving these behind\n\t// would put an enabled, destructive Reset next to metadata fields it does\n\t// not touch — clicking it would discard a crop the user cannot see.\n\t// (Metadata edits have no undo of their own; a history spanning both is a\n\t// larger change than hiding these.) Checked after the hooks above so the\n\t// hook order stays stable across renders.\n\tif ( ! isImage || ( ! isWide && !! activePanel ) ) {\n\t\treturn null;\n\t}\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\tconst handleReset = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\treset();\n\t};\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__history-actions\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ undo }\n\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleUndo }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ redo }\n\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={\n\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t}\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleRedo }\n\t\t\t/>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ backup }\n\t\t\t\tlabel={ __( 'History' ) }\n\t\t\t\tpopoverProps={ { placement: 'top-start' } }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tsize: 'compact',\n\t\t\t\t\tdisabled:\n\t\t\t\t\t\tisUndoRedoDisabled ||\n\t\t\t\t\t\t( ! isDirty && ! canRestoreOriginal ),\n\t\t\t\t\taccessibleWhenDisabled: true,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! isDirty }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\thandleReset();\n\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Reset image edits' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t{ canRestoreOriginal && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tdisabled={ isSourceReplaced || isSaving }\n\t\t\t\t\t\t\t\t\tinfo={ __( 'Discards unsaved changes.' ) }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonRestoreOriginal();\n\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Restore original' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t</Stack>\n\t);\n}\n\nexport interface SaveActionsProps {\n\t/**\n\t * Button height. Footers take the 40px default; frames placing these in a\n\t * page header pass `compact` to match the header's other controls.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: 'default' | 'compact';\n}\n\nfunction SaveActions( { size = 'default' }: SaveActionsProps ) {\n\tconst { isSaving, hasMedia, hasChanges, onCancel, onSave } =\n\t\tuseMediaEditorFrameContext();\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__save-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\tonClick={ onCancel }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ onSave }\n\t\t\t\tisBusy={ isSaving }\n\t\t\t\tdisabled={ saveDisabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Save' ) }\n\t\t\t</Button>\n\t\t</Stack>\n\t);\n}\n\nfunction MediaEditorContent( {\n\tfields = [],\n\tform,\n\tid,\n\taspectRatioPresets,\n\tonClose,\n\tonSaved,\n\trenderFrame,\n\tnoticesClassName = 'media-editor__snackbar',\n\tnoticesPortalElement,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst session = useMediaEditor();\n\t// Width decides whether the settings panel docks beside the canvas or\n\t// takes the whole body. It docks from `small` (600px): the modal is the\n\t// viewport less a 16px margin either side, so a 320px panel and the\n\t// canvas column's 2 x 24px gutters still leave the canvas ~200px there\n\t// and ~380px by 782px. Tight, but a full-screen panel would have hidden\n\t// the image altogether — you could not crop and preview at once.\n\t//\n\t// The same line moves the transform controls: docked, the Crop panel\n\t// carries them; below it they fall back to a row under the canvas.\n\t//\n\t// The choice is not carried across openings: the modal is transient, and\n\t// re-opening with the panel hidden on a wide screen is how #81487 read to\n\t// people in the first place. Within one opening it does hold — see\n\t// `chosenPanel` below.\n\tconst isWide = useViewportMatch( 'small' );\n\t// Below `small` the open panel replaces the canvas instead of sitting\n\t// beside it, so there is nothing to animate.\n\tconst disableSidebarMotion = useReducedMotion() || ! isWide;\n\tconst sidebarTransition: SidebarTransition = {\n\t\ttype: 'tween',\n\t\tduration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\t// Width picks the starting panel, but only until the user opens or closes\n\t// it. After that their choice holds for the rest of the session: closing\n\t// the panel and then resizing — or crossing the breakpoint by rotating a\n\t// tablet — should not reopen something they just dismissed. `undefined`\n\t// until then, otherwise `null` for closed or the open panel's id.\n\tconst [ chosenPanel, setChosenPanel ] = useState< string | null >();\n\t// The tab the user picked, `null` until they pick one. Tracked separately\n\t// from `chosenPanel` because the two answer different questions: whether\n\t// the panel should be open, and which tab it should show.\n\tconst [ chosenTab, setChosenTab ] = useState< string | null >( null );\n\t// Below `small` a frame's header cannot fit the history cluster alongside\n\t// its own controls, so it moves that cluster elsewhere. The same width\n\t// undocks the panel, so this is `isWide` rather than a second query.\n\tconst layout: 'wide' | 'narrow' = isWide ? 'wide' : 'narrow';\n\tconst sourceMedia = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tid\n\t\t\t) as Media,\n\t\t[ id ]\n\t);\n\n\tconst { clearEntityRecordEdits, editEntityRecord, invalidateResolution } =\n\t\tuseDispatch( coreStore );\n\tconst { removeAllNotices } = useDispatch( noticesStore );\n\n\tconst [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );\n\tconst [ isPlacementActive, setIsPlacementActive ] = useState( false );\n\tconst [ isCanvasGestureActive, setIsCanvasGestureActive ] =\n\t\tuseState( false );\n\t// Whether another attachment has replaced `id` in the cropper this\n\t// session (today, the original via \"Restore original image\"). Stays a\n\t// distinct flag (not derived from the cropper) so a bare replacement\n\t// counts as a change even though swapping the source resets the\n\t// cropper's own dirty baseline.\n\tconst [ isSourceReplaced, setIsSourceReplaced ] = useState( false );\n\tconst placementControlTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst signalPlacementControlInteraction = useCallback( () => {\n\t\tsetIsPlacementActive( true );\n\t\tclearTimeout( placementControlTimerRef.current );\n\t\tplacementControlTimerRef.current = setTimeout( () => {\n\t\t\tsetIsPlacementActive( false );\n\t\t}, PLACEMENT_CONTROL_IDLE_MS );\n\t}, [] );\n\tconst handleCanvasGestureStart = useCallback( () => {\n\t\tsetIsCanvasGestureActive( true );\n\t}, [] );\n\tconst handleCanvasGestureEnd = useCallback( () => {\n\t\tsetIsCanvasGestureActive( false );\n\t}, [] );\n\tconst isCropInteractionActive = isPlacementActive || isCanvasGestureActive;\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( placementControlTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Restore-original: the edit root the edited attachment descends from,\n\t// exposed by the server as the root-level `edit_root` id on the\n\t// attachment (edit context, embeddable via the `wp:edit-root` link).\n\t// Fetch the original's record for the URL and natural dimensions the\n\t// cropper needs to seed itself.\n\tconst originalId: number | undefined = sourceMedia?.edit_root;\n\tconst originalRecord = useSelect(\n\t\t( select ) =>\n\t\t\toriginalId\n\t\t\t\t? ( select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\toriginalId\n\t\t\t\t\t) as Media | undefined )\n\t\t\t\t: undefined,\n\t\t[ originalId ]\n\t);\n\tconst originalWidth = Number( originalRecord?.media_details?.width );\n\tconst originalHeight = Number( originalRecord?.media_details?.height );\n\tconst originalUrl = originalRecord?.source_url;\n\tconst originalSource =\n\t\toriginalId &&\n\t\toriginalRecord &&\n\t\ttypeof originalUrl === 'string' &&\n\t\toriginalUrl.length > 0 &&\n\t\tNumber.isFinite( originalWidth ) &&\n\t\toriginalWidth > 0 &&\n\t\tNumber.isFinite( originalHeight ) &&\n\t\toriginalHeight > 0\n\t\t\t? {\n\t\t\t\t\tid: originalId,\n\t\t\t\t\turl: originalUrl,\n\t\t\t\t\tmedia: originalRecord,\n\t\t\t\t}\n\t\t\t: undefined;\n\tconst canRestoreOriginal = !! originalSource;\n\tconst replacementSource =\n\t\tisSourceReplaced && originalSource\n\t\t\t? {\n\t\t\t\t\tid: originalSource.id,\n\t\t\t\t\turl: originalSource.url,\n\t\t\t\t\tmedia: originalSource.media,\n\t\t\t\t}\n\t\t\t: undefined;\n\t// Details and pending edits follow the attachment shown on the canvas.\n\t// Keep `sourceMedia` separate for the snackbar's previous attachment.\n\tconst activeId = replacementSource?.id ?? id;\n\tconst { media, hasEdits } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\tgetEntityRecord,\n\t\t\t\thasEditsForEntityRecord,\n\t\t\t} = select( coreStore );\n\t\t\t// Fetch embedded author and attached-post data for Details.\n\t\t\tgetEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tactiveId,\n\t\t\t\tATTACHMENT_EMBED_QUERY\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tmedia: getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t) as Media,\n\t\t\t\thasEdits: hasEditsForEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ activeId ]\n\t);\n\t// Refresh embedded data on opening or switching to the original.\n\tuseEffect( () => {\n\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t'postType',\n\t\t\t'attachment',\n\t\t\tactiveId,\n\t\t\tATTACHMENT_EMBED_QUERY,\n\t\t] );\n\t}, [ activeId, invalidateResolution ] );\n\tconst handleRestoreOriginal = useCallback( () => {\n\t\t// Restoring discards every pending edit, as the menu item says, so\n\t\t// nothing staged against the attachment being replaced reaches a save.\n\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\n\t\tsetIsSourceReplaced( true );\n\t}, [ clearEntityRecordEdits, id ] );\n\n\t// A bare replacement has no cropper diff, so OR the flag in explicitly.\n\tconst hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;\n\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;\n\tconst isImage = !! media && mediaType === 'image';\n\n\t// Docked, the panel opens on Crop: the canvas is still beside it and\n\t// cropping is what the editor is for. Below `small` an open panel covers\n\t// the canvas, and crop controls with no crop in sight are not worth\n\t// opening on, so Details leads there. Non-image media has no Crop tab at\n\t// all (see `tabs`), so it always gets Details.\n\tconst currentTab =\n\t\tchosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );\n\t// `null` when nothing is open, otherwise the open panel's id. Until the\n\t// user opens or closes the panel, follow the breakpoint: dragging a window\n\t// narrow hands the canvas the full width instead of leaving a panel\n\t// wedged beside it.\n\tlet activePanel = chosenPanel;\n\tif ( activePanel === undefined ) {\n\t\tactivePanel = isWide ? currentTab : null;\n\t}\n\t// Switching tabs says nothing about whether the panel should be open, so\n\t// it leaves `chosenPanel` unset: picking Details on a wide screen and then\n\t// dragging the window narrow should still hand the canvas the full width.\n\tconst selectPanel = useCallback( ( panel: string ) => {\n\t\tsetChosenTab( panel );\n\t\tsetChosenPanel( ( chosen ) =>\n\t\t\tchosen === undefined ? chosen : panel\n\t\t);\n\t}, [] );\n\tconst togglePanel = useCallback( () => {\n\t\tsetChosenPanel( activePanel ? null : currentTab );\n\t}, [ activePanel, currentTab ] );\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {\n\t\tsession,\n\t\tid,\n\t\tisImage,\n\t\tmedia: sourceMedia,\n\t\tonSaved,\n\t\treplacementSource,\n\t} );\n\n\tconst handleChange = ( updates: Partial< Media > ) => {\n\t\t// A save reads the pending edits once and then waits. An edit\n\t\t// arriving after that read misses the request, and a crop save\n\t\t// then clears the edits for this id, so it would be lost rather\n\t\t// than merely late. It would also land on the attachment being\n\t\t// replaced, not the new one the modal moves to.\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\teditEntityRecord( 'postType', 'attachment', activeId, updates );\n\t};\n\n\tconst discardAndClose = () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tclearEntityRecordEdits( 'postType', 'attachment', activeId );\n\t\tsetIsSourceReplaced( false );\n\t\tonClose?.();\n\t};\n\n\tconst handleRequestClose = () => {\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasChanges ) {\n\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\treturn;\n\t\t}\n\t\tdiscardAndClose();\n\t};\n\n\tconst handleKeyDown = ( event: ReactKeyboardEvent< HTMLElement > ) => {\n\t\tconst isUndoShortcut = isKeyboardEvent.primary( event, 'z' );\n\t\tconst isRedoShortcut =\n\t\t\tisKeyboardEvent.primaryShift( event, 'z' ) ||\n\t\t\t( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );\n\t\tif ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tconst isMetadataField =\n\t\t\t\t( target.tagName === 'INPUT' ||\n\t\t\t\t\ttarget.tagName === 'TEXTAREA' ||\n\t\t\t\t\ttarget.isContentEditable ) &&\n\t\t\t\t! target.closest( `[${ CROP_CONTROL_ATTR }]` );\n\t\t\tif ( ! isMetadataField ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( isCropInteractionActive || isSaving ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( isRedoShortcut ) {\n\t\t\t\t\tsession.redo();\n\t\t\t\t} else {\n\t\t\t\t\tsession.undo();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( shouldCloseOnEsc ) {\n\t\t\tif ( event.code !== 'Escape' && event.key !== 'Escape' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( isSaving ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( hasChanges ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\t}\n\t\t}\n\t};\n\n\tconst snackbar = (\n\t\t<SnackbarNotices\n\t\t\tclassName={ noticesClassName }\n\t\t\tcontext={ MEDIA_EDITOR_NOTICES_CONTEXT }\n\t\t/>\n\t);\n\n\t// Below `small` the panel is full screen, so an open one replaces the\n\t// canvas and these never share the screen with the Crop panel's copies:\n\t// this row is what reaches rotate/flip/zoom while the panel is closed,\n\t// with aspect ratio joining them as a dropdown. From `small` up the Crop\n\t// panel docks beside the canvas and carries them instead.\n\tconst imageControls =\n\t\tisImage && ! isWide ? (\n\t\t\t<MediaEditorImageControls\n\t\t\t\tshowAspectRatioControl\n\t\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t/>\n\t\t) : null;\n\n\t// Crop leads, since it is what the docked panel opens on. Non-image media\n\t// has nothing to crop and gets Details alone, which is why the sidebar\n\t// takes this list rather than deriving it.\n\tconst tabs: MediaEditorTab[] = [\n\t\t...( isImage\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: CROP_PANEL,\n\t\t\t\t\t\ttitle: __( 'Crop' ),\n\t\t\t\t\t\trender: () => (\n\t\t\t\t\t\t\t<MediaEditorCropPanel\n\t\t\t\t\t\t\t\taspectRatioValue={ aspectRatioValue }\n\t\t\t\t\t\t\t\tonAspectRatioChange={ setAspectRatioValue }\n\t\t\t\t\t\t\t\taspectRatioOptions={ aspectRatioOptions }\n\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [] ),\n\t\t{\n\t\t\tid: DETAILS_PANEL,\n\t\t\ttitle: __( 'Details' ),\n\t\t\trender: () => <MediaForm />,\n\t\t},\n\t];\n\n\tconst ruler = isImage ? (\n\t\t<MediaEditorFineRotation\n\t\t\tonPlacementControlInteraction={ signalPlacementControlInteraction }\n\t\t\tdisabled={ isSaving }\n\t\t/>\n\t) : null;\n\n\tconst children = (\n\t\t<MediaEditorProvider\n\t\t\tvalue={ media ?? undefined }\n\t\t\tonChange={ handleChange }\n\t\t\tsettings={ {\n\t\t\t\t// Disable the fields while saving, so the guard in\n\t\t\t\t// `handleChange` is not silently swallowing typing.\n\t\t\t\t// `readOnly` would swap the field's layout mid-save;\n\t\t\t\t// disabled keeps it in place and greys it out.\n\t\t\t\tfields: isSaving\n\t\t\t\t\t? fields.map( ( field ) => ( {\n\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\tisDisabled: true,\n\t\t\t\t\t\t} ) )\n\t\t\t\t\t: fields,\n\t\t\t\tform,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"media-editor\">\n\t\t\t\t{ ! media ? (\n\t\t\t\t\t<div className=\"media-editor__loading\">\n\t\t\t\t\t\t<WCSpinner />\n\t\t\t\t\t</div>\n\t\t\t\t) : (\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ clsx( 'media-editor__body', {\n\t\t\t\t\t\t\t'has-panel-open': !! activePanel,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<NavigableRegion\n\t\t\t\t\t\t\tclassName=\"media-editor__content\"\n\t\t\t\t\t\t\tariaLabel={\n\t\t\t\t\t\t\t\tisImage\n\t\t\t\t\t\t\t\t\t? __( 'Image editor' )\n\t\t\t\t\t\t\t\t\t: __( 'Media preview' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div className=\"media-editor__canvas-area\">\n\t\t\t\t\t\t\t\t{ isImage ? (\n\t\t\t\t\t\t\t\t\t<MediaEditorCanvas\n\t\t\t\t\t\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\t\t\t\t\t\tonGestureStart={\n\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureStart\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonGestureEnd={ handleCanvasGestureEnd }\n\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<MediaPreview />\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ isImage && (\n\t\t\t\t\t\t\t\t<div className=\"media-editor__canvas-toolbar\">\n\t\t\t\t\t\t\t\t\t{ ruler }\n\t\t\t\t\t\t\t\t\t{ imageControls }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</NavigableRegion>\n\t\t\t\t\t\t<AnimatePresence\n\t\t\t\t\t\t\tinitial={ false }\n\t\t\t\t\t\t\tcustom={ sidebarTransition }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ !! activePanel && (\n\t\t\t\t\t\t\t\t<motion.div\n\t\t\t\t\t\t\t\t\tclassName=\"media-editor__sidebar-container\"\n\t\t\t\t\t\t\t\t\tvariants={ sidebarVariants }\n\t\t\t\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\t\t\t\ttransition={ sidebarTransition }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<MediaEditorSidebar\n\t\t\t\t\t\t\t\t\t\ttabs={ tabs }\n\t\t\t\t\t\t\t\t\t\t// Swapping the edited media can drop the\n\t\t\t\t\t\t\t\t\t\t// Crop tab out from under an open panel —\n\t\t\t\t\t\t\t\t\t\t// saving a crop moves the editor to a new\n\t\t\t\t\t\t\t\t\t\t// id, which may resolve as non-image.\n\t\t\t\t\t\t\t\t\t\t// Fall back rather than hand `Tabs.Root`\n\t\t\t\t\t\t\t\t\t\t// a value no tab matches.\n\t\t\t\t\t\t\t\t\t\tactiveTab={\n\t\t\t\t\t\t\t\t\t\t\ttabs.some(\n\t\t\t\t\t\t\t\t\t\t\t\t( tab ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\ttab.id === activePanel\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t? activePanel\n\t\t\t\t\t\t\t\t\t\t\t\t: DETAILS_PANEL\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonSelectTab={ selectPanel }\n\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</motion.div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</AnimatePresence>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isDiscardDialogOpen }\n\t\t\t\tconfirmButtonText={ __( 'Discard' ) }\n\t\t\t\tcancelButtonText={ __( 'Keep editing' ) }\n\t\t\t\tonCancel={ () => setIsDiscardDialogOpen( false ) }\n\t\t\t\tonConfirm={ () => {\n\t\t\t\t\tsetIsDiscardDialogOpen( false );\n\t\t\t\t\tdiscardAndClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __(\n\t\t\t\t\t'Are you sure you want to discard your unsaved changes?'\n\t\t\t\t) }\n\t\t\t</ConfirmDialog>\n\t\t\t{ noticesPortalElement\n\t\t\t\t? createPortal( snackbar, noticesPortalElement )\n\t\t\t\t: snackbar }\n\t\t</MediaEditorProvider>\n\t);\n\n\t// Rebuilt each render, like the elements it replaces: consumers re-render\n\t// as they always did, but the cluster component types stay stable.\n\tconst contextValue: MediaEditorFrameContextValue = {\n\t\tisImage,\n\t\tisSaving,\n\t\thasMedia: !! media,\n\t\thasChanges,\n\t\t// Saving freezes the whole edit surface: `save()` reads the\n\t\t// modifiers once and then awaits, so anything changed after that\n\t\t// would be silently dropped when the save resolves.\n\t\tisUndoRedoDisabled: isCropInteractionActive || isSaving,\n\t\taspectRatioPresets,\n\t\tisWide,\n\t\tactivePanel,\n\t\tonTogglePanel: togglePanel,\n\t\tonCancel: handleRequestClose,\n\t\tonSave: saveMediaEditor,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\tonRestoreOriginal: handleRestoreOriginal,\n\t};\n\n\treturn (\n\t\t<MediaEditorFrameContext.Provider value={ contextValue }>\n\t\t\t{ renderFrame( {\n\t\t\t\tchildren,\n\t\t\t\tisImage,\n\t\t\t\tlayout,\n\t\t\t\tonRequestClose: handleRequestClose,\n\t\t\t\tonKeyDown: handleKeyDown,\n\t\t\t\tshouldCloseOnClickOutside: ! hasChanges && ! isSaving,\n\t\t\t\tisSaving,\n\t\t\t\thasChanges,\n\t\t\t\thasMedia: !! media,\n\t\t\t} ) }\n\t\t</MediaEditorFrameContext.Provider>\n\t);\n}\n\nexport function MediaEditor( props: MediaEditorProps ) {\n\treturn (\n\t\t<MediaEditorStateProvider key={ props.id }>\n\t\t\t<MediaEditorContent { ...props } />\n\t\t</MediaEditorStateProvider>\n\t);\n}\n\n// Attached to `MediaEditor` so frames import and arrange them, the way\n// `DataViewsPicker` exposes its own sub-components. They read what they need\n// from context, so a frame only chooses where they go and how they look.\nMediaEditor.HeaderActions = HeaderActions;\nMediaEditor.PanelToggle = PanelToggle;\nMediaEditor.MoreMenu = MoreMenu;\nMediaEditor.HistoryActions = HistoryActions;\nMediaEditor.SaveActions = SaveActions;\n\nexport default MediaEditor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAM,yBAAyB,EAAE,QAAQ,wBAAwB;AAEjE,MAAM,4BAA4B;;;;;;;AAQlC,MAAM,gBAAgB;;AAGtB,MAAM,aAAa;AAGnB,MAAM,6BAA6B;AAQnC,MAAM,kBAAkB;CAEvB,MAAM,EAAE,OAAO,OAAO;CAGtB,SAAU,gBAAqC;EAC9C,OAAO;EACP;CACD;AACD;AAuDA,SAAS,mBAAoB,EAC5B,MACA,WACA,aACA,WAAW,SACiB;CAC5B,OACC,qBAAC,iBAAD;EACC,WAAU;EACV,WAAY,GAAI,gBAAiB;EAFlC,UAAA,CAQC,oBAAC,gBAAD;GAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;GAC3B,UAAA,GAAI,gBAAiB;EACR,CAAA,GAChB,qBAAC,KAAK,MAAN;GACC,WAAU;GACV,OAAQ;GACR,eAAgB;GAHjB,UAAA,CAQC,oBAAC,OAAD;IAAK,WAAU;IACd,UAAA,oBAAC,KAAK,MAAN;KAAW,SAAQ;KAChB,UAAA,KAAK,KAAO,QACb,oBAAC,KAAK,KAAN;MAEC,OAAQ,IAAI;MACD;MAET,UAAA,IAAI;KACG,GALH,IAAI,EAKD,CACT;IACQ,CAAA;GACP,CAAA,GAIH,KAAK,KAAO,QACb,oBAAC,KAAK,OAAN;IAEC,OAAQ,IAAI;IACZ,UAAW;IACX,WAAU;IAEV,UAAA,oBAAC,OAAD;KAAO,WAAU;KAAS,KAAI;KAC3B,UAAA,IAAI,OAAO;IACP,CAAA;GACI,GARL,IAAI,EAQC,CACX,CACQ;EACK,CAAA,CAAA;;AAEnB;AAyCA,MAAM,0BACL,cAAsD,IAAK;;;;;;;;AAS5D,SA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,CACb;;GAEF,CAAA;GACL,oBAACC,6BAAD;IACC,QAAS;IACT,mBAAoB,GAAI,SAAU;IAClC,kBAAmB,GAAI,cAAe;IACtC,gBAAiB,uBAAwB,KAAM;IAC/C,iBAAkB;KACjB,uBAAwB,KAAM;KAC9B,gBAAgB;IACjB;IAEE,UAAA,GACD,wDACD;GACc,CAAA;GACb,uBACC,aAAc,UAAU,oBAAqB,IAC7C;EACiB;;CAKtB,MAAM,eAA6C;EAClD;EACA;EACA,UAAU,CAAC,CAAE;EACb;EAIA,oBAAoB,2BAA2B;EAC/C;EACA;EACA;EACA,eAAe;EACf,UAAU;EACV,QAAQ;EACR;EACA;EACA,mBAAmB;CACpB;CAEA,OACC,oBAAC,wBAAwB,UAAzB;EAAkC,OAAQ;EACvC,UAAA,YAAa;GACd;GACA;GACA;GACA,gBAAgB;GAChB,WAAW;GACX,2BAA2B,CAAE,cAAc,CAAE;GAC7C;GACA;GACA,UAAU,CAAC,CAAE;EACd,CAAE;CAC+B,CAAA;AAEpC;AAEA,SAAgB,YAAa,OAA0B;CACtD,OACC,oBAAC,0BAAD,EAAA,UACC,oBAAC,oBAAD,EAAoB,GAAK,MAAS,CAAA,EACT,GAFM,MAAM,EAEZ;AAE5B;AAKA,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,cAAc"}
1
+ {"version":3,"file":"index.mjs","names":["coreStore","noticesStore","WCSpinner","AnimatePresence","motion","ConfirmDialog"],"sources":["../../../src/components/media-editor/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tButton,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n\tSpinner as WCSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\t__unstableAnimatePresence as AnimatePresence,\n\t__unstableMotion as motion,\n} from '@wordpress/components';\nimport { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';\nimport { useReducedMotion, useViewportMatch } from '@wordpress/compose';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { NavigableRegion } from '@wordpress/admin-ui';\nimport {\n\tcreateContext,\n\tcreatePortal,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tbackup,\n\tclose,\n\tdrawerRight,\n\tkeyboard,\n\tmoreVertical,\n\tredo,\n\tundo,\n} from '@wordpress/icons';\nimport {\n\tdisplayShortcut,\n\tisAppleOS,\n\tisKeyboardEvent,\n} from '@wordpress/keycodes';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';\nimport type {\n\tKeyboardEvent as ReactKeyboardEvent,\n\tReactElement,\n\tReactNode,\n} from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { MediaEditorProvider } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport MediaPreview from '../media-preview';\nimport MediaEditorCanvas from '../media-editor-canvas';\nimport MediaEditorFineRotation from '../media-editor-fine-rotation';\nimport MediaEditorCropPanel from '../media-editor-crop-panel';\nimport MediaEditorImageControls from '../media-editor-image-controls';\nimport MediaForm from '../media-form';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { MediaEditorStateProvider, useMediaEditor } from '../../state';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';\nimport {\n\tMEDIA_EDITOR_NOTICES_CONTEXT,\n\tuseSaveMediaEditor,\n\ttype MediaEditorSaveResult,\n} from './use-save-media-editor';\nimport { useCropOptions } from './use-crop-options';\n\nexport type { MediaEditorSaveResult } from './use-save-media-editor';\n\n// Embed query for the attachment's author and parent post. Shared between\n// the `getEntityRecord` read and the matching `invalidateResolution` so the\n// two stay in lockstep.\nconst ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;\n\nconst PLACEMENT_CONTROL_IDLE_MS = 300;\n\n/**\n * Identifier for the details panel, and the panel the sidebar opens on before\n * the user picks another. The sidebar tracks which panel is open rather than\n * whether one is, so a further panel is a new id here and a new entry in the\n * tab list — not a change to the state's shape.\n */\nconst DETAILS_PANEL = 'details';\n\n/** Identifier for the crop panel. Images only; other media has nothing to crop. */\nconst CROP_PANEL = 'crop';\n\n// Matches the editor's sidebar in `ComplementaryArea`.\nconst SIDEBAR_ANIMATION_DURATION = 0.3;\n\ntype SidebarTransition = {\n\ttype: 'tween';\n\tduration: number;\n\tease: number[];\n};\n\nconst sidebarVariants = {\n\t// `auto` leaves the width to the sidebar's stylesheet.\n\topen: { width: 'auto' },\n\t// Takes the transition from `AnimatePresence`'s `custom` prop, so a\n\t// sidebar that is already closing still gets the current one.\n\tclosed: ( transition: SidebarTransition ) => ( {\n\t\twidth: 0,\n\t\ttransition,\n\t} ),\n};\n\ninterface MediaEditorTab {\n\tid: string;\n\ttitle: string;\n\trender: () => ReactElement;\n}\n\nexport interface MediaEditorFrameProps {\n\tchildren: ReactNode;\n\t/**\n\t * Whether the media being edited is an image. The history and transform\n\t * clusters render nothing for other media types, so a frame uses this to\n\t * decide whether the container it would put them in is worth rendering at\n\t * all.\n\t */\n\tisImage: boolean;\n\t/**\n\t * `narrow` below the `small` breakpoint, where the frame's header has no\n\t * room for the history cluster beside its other controls. A frame uses\n\t * this to place that cluster, not to decide whether it renders —\n\t * `HistoryActions` returns nothing on its own when the canvas is off\n\t * screen.\n\t */\n\tlayout: 'wide' | 'narrow';\n\tonRequestClose: () => void;\n\tonKeyDown: ( event: ReactKeyboardEvent< HTMLElement > ) => void;\n\tshouldCloseOnClickOutside: boolean;\n\tisSaving: boolean;\n\thasChanges: boolean;\n\thasMedia: boolean;\n}\n\nexport interface MediaEditorProps {\n\tfields?: Field< Media >[];\n\tform?: Form;\n\tid: number;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonClose?: () => void;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/** Called with the original's id when the user chooses \"Edit original\". */\n\tonEditOriginal?: ( originalId: number ) => void;\n\trenderFrame: ( props: MediaEditorFrameProps ) => ReactElement;\n\tnoticesClassName?: string;\n\tnoticesPortalElement?: Element | null;\n\tshouldCloseOnEsc?: boolean;\n}\n\ninterface MediaEditorSidebarProps {\n\ttabs: MediaEditorTab[];\n\t/** The open panel's id. Always one of `tabs`. */\n\tactiveTab: string;\n\tonSelectTab: ( tab: string ) => void;\n\t/** Freeze the open panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\nfunction MediaEditorSidebar( {\n\ttabs,\n\tactiveTab,\n\tonSelectTab,\n\tdisabled = false,\n}: MediaEditorSidebarProps ) {\n\treturn (\n\t\t<NavigableRegion\n\t\t\tclassName=\"media-editor__sidebar\"\n\t\t\tariaLabel={ __( 'Media settings' ) }\n\t\t>\n\t\t\t{ /* No visible heading and no close button: the strip below names\n\t\t\t the open panel and the header's pressed toggle dismisses it.\n\t\t\t The heading stays for screen readers, which read neither as\n\t\t\t this region's title. */ }\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Media settings' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Tabs.Root\n\t\t\t\tclassName=\"media-editor__tabs\"\n\t\t\t\tvalue={ activeTab }\n\t\t\t\tonValueChange={ onSelectTab }\n\t\t\t>\n\t\t\t\t{ /* `Tabs.List` sizes itself to its tabs (`width: fit-content`),\n\t\t\t\t so the rule under the strip is drawn by this wrapper\n\t\t\t\t instead, which spans the column. */ }\n\t\t\t\t<div className=\"media-editor__tablist\">\n\t\t\t\t\t<Tabs.List variant=\"minimal\">\n\t\t\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t\t\t<Tabs.Tab\n\t\t\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ tab.title }\n\t\t\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Tabs.List>\n\t\t\t\t</div>\n\t\t\t\t{ /* One `Tabs.Panel` per tab: the counts have to match or\n\t\t\t\t `Tabs.Root` throws in dev. Only the active one paints\n\t\t\t\t anything — the rest render nothing. */ }\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<Tabs.Panel\n\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\tvalue={ tab.id }\n\t\t\t\t\t\ttabIndex={ -1 }\n\t\t\t\t\t\tclassName=\"media-editor__panel\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stack direction=\"column\" gap=\"lg\">\n\t\t\t\t\t\t\t{ tab.render() }\n\t\t\t\t\t\t</Stack>\n\t\t\t\t\t</Tabs.Panel>\n\t\t\t\t) ) }\n\t\t\t</Tabs.Root>\n\t\t</NavigableRegion>\n\t);\n}\n\n/**\n * Everything the frame's action clusters need from the editor. Supplied by\n * context rather than by props so the clusters can be module-level components:\n * a component created during a render has a new identity on every pass, which\n * remounts its subtree and drops focus mid-interaction.\n */\ninterface MediaEditorFrameContextValue {\n\tisImage: boolean;\n\tisSaving: boolean;\n\thasMedia: boolean;\n\thasChanges: boolean;\n\tisUndoRedoDisabled: boolean;\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/** `true` above `large`, where the panel docks beside the canvas. */\n\tisWide: boolean;\n\t/** The open panel's id, or `null` when none is. */\n\tactivePanel: string | null;\n\t/**\n\t * Opens the sidebar on the last-shown panel, or closes it when one is\n\t * already open.\n\t */\n\tonTogglePanel: () => void;\n\tonCancel: () => void;\n\tonSave: () => void;\n\t/**\n\t * When `true`, the media has a lineage root to restore to, so the\n\t * history menu shows its \"Restore original\" item.\n\t */\n\tcanRestoreOriginal: boolean;\n\t/**\n\t * When `true`, another attachment has replaced the edited one in the\n\t * image editor this session (today, only the original), so the menu item is\n\t * disabled.\n\t */\n\tisSourceReplaced: boolean;\n\t/** Whether the frame opens the original itself. */\n\topensOriginal: boolean;\n\t/**\n\t * Load the lineage root into the image editor, or hand it to the\n\t * frame.\n\t */\n\tonRestoreOriginal: () => void;\n}\n\nconst MediaEditorFrameContext =\n\tcreateContext< MediaEditorFrameContextValue | null >( null );\n\n/**\n * Hook to access the media editor's frame context.\n *\n * Must be used within a MediaEditor component.\n *\n * @return MediaEditorFrameContextValue the action clusters render from.\n */\nfunction useMediaEditorFrameContext(): MediaEditorFrameContextValue {\n\tconst context = useContext( MediaEditorFrameContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorFrameContext must be used within MediaEditor'\n\t\t);\n\t}\n\treturn context;\n}\n\nexport interface HeaderActionsProps {\n\t/**\n\t * Whether to include a Close button. Frames with a dismissal affordance of\n\t * their own — a route's breadcrumbs, say — leave it out.\n\t *\n\t * @default false\n\t */\n\tshowCloseButton?: boolean;\n}\n\nfunction PanelToggle() {\n\tconst { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();\n\tconst isPanelOpen = !! activePanel;\n\t// The sidebar holds more than one panel, so this opens and closes the\n\t// sidebar rather than naming a panel: reopening returns to whichever tab\n\t// was last showing, and the tab strip inside switches between them.\n\treturn (\n\t\t<Button\n\t\t\tsize=\"compact\"\n\t\t\ticon={ drawerRight }\n\t\t\tlabel={ __( 'Media settings' ) }\n\t\t\tisPressed={ isPanelOpen }\n\t\t\t// Only a docked column really expands beside the canvas; below\n\t\t\t// that the panel replaces the view, which the pressed state\n\t\t\t// already describes.\n\t\t\taria-expanded={ isWide ? isPanelOpen : undefined }\n\t\t\tonClick={ onTogglePanel }\n\t\t/>\n\t);\n}\n\nfunction getActionLabel( action: Action< Media >, items: Media[] ) {\n\treturn typeof action.label === 'string'\n\t\t? action.label\n\t\t: action.label( items );\n}\n\ninterface MediaActionModalProps {\n\taction: ActionModal< Media >;\n\titems: Media[];\n\tcloseModal: () => void;\n}\n\n// A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't\n// exported. It could be replaced if dataviews exports it.\nfunction MediaActionModal( {\n\taction,\n\titems,\n\tcloseModal,\n}: MediaActionModalProps ) {\n\tconst header =\n\t\ttypeof action.modalHeader === 'function'\n\t\t\t? action.modalHeader( items )\n\t\t\t: action.modalHeader;\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ header || getActionLabel( action, items ) }\n\t\t\t__experimentalHideHeader={ !! action.hideModalHeader }\n\t\t\tonRequestClose={ closeModal }\n\t\t\tfocusOnMount={ action.modalFocusOnMount ?? true }\n\t\t\tsize={ action.modalSize || 'medium' }\n\t\t>\n\t\t\t<action.RenderModal items={ items } closeModal={ closeModal } />\n\t\t</Modal>\n\t);\n}\n\nexport interface MoreMenuProps {\n\t/**\n\t * Actions for the attachment, such as those from the entity actions API.\n\t * Only the ones whose `isEligible` passes for `item` are shown.\n\t */\n\tactions?: Action< Media >[];\n\t/**\n\t * The attachment the actions apply to, with anything their `isEligible`\n\t * checks need, such as `permissions`. Without it no actions are shown.\n\t */\n\titem?: Media;\n}\n\nfunction MoreMenu( { actions = [], item }: MoreMenuProps ) {\n\tconst { isImage, isSaving } = useMediaEditorFrameContext();\n\tconst registry = useRegistry();\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\n\tconst [ activeModalAction, setActiveModalAction ] =\n\t\tuseState< ActionModal< Media > | null >( null );\n\n\tconst items = item ? [ item ] : [];\n\tconst eligibleActions = useMemo(\n\t\t() =>\n\t\t\titem\n\t\t\t\t? actions.filter(\n\t\t\t\t\t\t( action ) =>\n\t\t\t\t\t\t\t! action.isEligible || action.isEligible( item )\n\t\t\t\t\t)\n\t\t\t\t: [],\n\t\t[ actions, item ]\n\t);\n\n\tif ( ! isImage && ! eligibleActions.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ moreVertical }\n\t\t\t\tlabel={ __( 'More options' ) }\n\t\t\t\ttoggleProps={ { size: 'compact' } }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isImage && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ keyboard }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsShortcutsModalOpen( true );\n\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Keyboard shortcuts' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ !! eligibleActions.length && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t{ eligibleActions.map( ( action ) => {\n\t\t\t\t\t\t\t\t\tconst label = getActionLabel(\n\t\t\t\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t\t\t\titems\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tkey={ action.id }\n\t\t\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\t\t\tisSaving || action.disabled\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t\t\t\tif ( 'RenderModal' in action ) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetActiveModalAction(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\taction\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\taction.callback( items, {\n\t\t\t\t\t\t\t\t\t\t\t\t\tregistry,\n\t\t\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ 'RenderModal' in action\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'%s…',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'menu item requiring further input'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t: label }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ isShortcutsModalOpen && (\n\t\t\t\t<MediaEditorKeyboardShortcutsModal\n\t\t\t\t\tonClose={ () => setIsShortcutsModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ activeModalAction && (\n\t\t\t\t<MediaActionModal\n\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\titems={ items }\n\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {\n\tconst { isSaving, onCancel } = useMediaEditorFrameContext();\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__header-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<PanelToggle />\n\t\t\t<MoreMenu />\n\t\t\t{ showCloseButton && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ close }\n\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\tonClick={ onCancel }\n\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction HistoryActions() {\n\tconst {\n\t\tisImage,\n\t\tisSaving,\n\t\tisUndoRedoDisabled,\n\t\tisWide,\n\t\tactivePanel,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\topensOriginal,\n\t\tonRestoreOriginal,\n\t} = useMediaEditorFrameContext();\n\tconst {\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t} = useMediaEditor();\n\t// Reset, undo and redo act on the image edits, so they only appear where\n\t// the canvas does. Non-image media has no edit history at all; below the dock\n\t// breakpoint an open panel replaces the canvas, and leaving these behind\n\t// would put an enabled, destructive Reset next to metadata fields it does\n\t// not touch — clicking it would discard a crop the user cannot see.\n\t// (Metadata edits have no undo of their own; a history spanning both is a\n\t// larger change than hiding these.) Checked after the hooks above so the\n\t// hook order stays stable across renders.\n\tif ( ! isImage || ( ! isWide && !! activePanel ) ) {\n\t\treturn null;\n\t}\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\tconst handleReset = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\treset();\n\t};\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__history-actions\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ undo }\n\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleUndo }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ redo }\n\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tshortcut={\n\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t}\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleRedo }\n\t\t\t/>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ backup }\n\t\t\t\tlabel={ __( 'History' ) }\n\t\t\t\tpopoverProps={ { placement: 'top-start' } }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tsize: 'compact',\n\t\t\t\t\tdisabled:\n\t\t\t\t\t\tisUndoRedoDisabled ||\n\t\t\t\t\t\t( ! isDirty && ! canRestoreOriginal ),\n\t\t\t\t\taccessibleWhenDisabled: true,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! isDirty }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\thandleReset();\n\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Reset image edits' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t{ canRestoreOriginal && (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tdisabled={ isSourceReplaced || isSaving }\n\t\t\t\t\t\t\t\t\tinfo={ __( 'Discards unsaved changes.' ) }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonRestoreOriginal();\n\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ opensOriginal\n\t\t\t\t\t\t\t\t\t\t? __( 'Edit original' )\n\t\t\t\t\t\t\t\t\t\t: __( 'Restore original' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t</Stack>\n\t);\n}\n\nexport interface SaveActionsProps {\n\t/**\n\t * Button height. Footers take the 40px default; frames placing these in a\n\t * page header pass `compact` to match the header's other controls.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: 'default' | 'compact';\n}\n\nfunction SaveActions( { size = 'default' }: SaveActionsProps ) {\n\tconst { isSaving, hasMedia, hasChanges, onCancel, onSave } =\n\t\tuseMediaEditorFrameContext();\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor__save-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\talign=\"center\"\n\t\t\tgap=\"sm\"\n\t\t>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\tonClick={ onCancel }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ onSave }\n\t\t\t\tisBusy={ isSaving }\n\t\t\t\tdisabled={ saveDisabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Save' ) }\n\t\t\t</Button>\n\t\t</Stack>\n\t);\n}\n\nfunction MediaEditorContent( {\n\tfields = [],\n\tform,\n\tid,\n\taspectRatioPresets,\n\tonClose,\n\tonSaved,\n\tonEditOriginal,\n\trenderFrame,\n\tnoticesClassName = 'media-editor__snackbar',\n\tnoticesPortalElement,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst session = useMediaEditor();\n\t// Width decides whether the settings panel docks beside the canvas or\n\t// takes the whole body. It docks from `small` (600px): the modal is the\n\t// viewport less a 16px margin either side, so a 320px panel and the\n\t// canvas column's 2 x 24px gutters still leave the canvas ~200px there\n\t// and ~380px by 782px. Tight, but a full-screen panel would have hidden\n\t// the image altogether — you could not crop and preview at once.\n\t//\n\t// The same line moves the transform controls: docked, the Crop panel\n\t// carries them; below it they fall back to a row under the canvas.\n\t//\n\t// The choice is not carried across openings: the modal is transient, and\n\t// re-opening with the panel hidden on a wide screen is how #81487 read to\n\t// people in the first place. Within one opening it does hold — see\n\t// `chosenPanel` below.\n\tconst isWide = useViewportMatch( 'small' );\n\t// Below `small` the open panel replaces the canvas instead of sitting\n\t// beside it, so there is nothing to animate.\n\tconst disableSidebarMotion = useReducedMotion() || ! isWide;\n\tconst sidebarTransition: SidebarTransition = {\n\t\ttype: 'tween',\n\t\tduration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\t// Width picks the starting panel, but only until the user opens or closes\n\t// it. After that their choice holds for the rest of the session: closing\n\t// the panel and then resizing — or crossing the breakpoint by rotating a\n\t// tablet — should not reopen something they just dismissed. `undefined`\n\t// until then, otherwise `null` for closed or the open panel's id.\n\tconst [ chosenPanel, setChosenPanel ] = useState< string | null >();\n\t// The tab the user picked, `null` until they pick one. Tracked separately\n\t// from `chosenPanel` because the two answer different questions: whether\n\t// the panel should be open, and which tab it should show.\n\tconst [ chosenTab, setChosenTab ] = useState< string | null >( null );\n\t// Below `small` a frame's header cannot fit the history cluster alongside\n\t// its own controls, so it moves that cluster elsewhere. The same width\n\t// undocks the panel, so this is `isWide` rather than a second query.\n\tconst layout: 'wide' | 'narrow' = isWide ? 'wide' : 'narrow';\n\tconst sourceMedia = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tid\n\t\t\t) as Media,\n\t\t[ id ]\n\t);\n\n\tconst { clearEntityRecordEdits, editEntityRecord, invalidateResolution } =\n\t\tuseDispatch( coreStore );\n\tconst { removeAllNotices } = useDispatch( noticesStore );\n\n\tconst [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );\n\tconst [ isPlacementActive, setIsPlacementActive ] = useState( false );\n\tconst [ isCanvasGestureActive, setIsCanvasGestureActive ] =\n\t\tuseState( false );\n\t// Whether another attachment has replaced `id` in the image editor this\n\t// session (today, the original via \"Restore original image\"). Stays a\n\t// distinct flag (not derived from the image editor) so a bare replacement\n\t// counts as a change even though swapping the source resets the\n\t// image editor's own dirty baseline.\n\tconst [ isSourceReplaced, setIsSourceReplaced ] = useState( false );\n\tconst placementControlTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst signalPlacementControlInteraction = useCallback( () => {\n\t\tsetIsPlacementActive( true );\n\t\tclearTimeout( placementControlTimerRef.current );\n\t\tplacementControlTimerRef.current = setTimeout( () => {\n\t\t\tsetIsPlacementActive( false );\n\t\t}, PLACEMENT_CONTROL_IDLE_MS );\n\t}, [] );\n\tconst handleCanvasGestureStart = useCallback( () => {\n\t\tsetIsCanvasGestureActive( true );\n\t}, [] );\n\tconst handleCanvasGestureEnd = useCallback( () => {\n\t\tsetIsCanvasGestureActive( false );\n\t}, [] );\n\tconst isCropInteractionActive = isPlacementActive || isCanvasGestureActive;\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( placementControlTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Restore-original: the edit root the edited attachment descends from,\n\t// exposed by the server as the root-level `edit_root` id on the\n\t// attachment (edit context, embeddable via the `wp:edit-root` link).\n\t// Fetch the original's record for the URL and natural dimensions the\n\t// image editor needs to seed itself.\n\tconst originalId: number | undefined = sourceMedia?.edit_root;\n\tconst originalRecord = useSelect(\n\t\t( select ) =>\n\t\t\toriginalId\n\t\t\t\t? ( select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\toriginalId\n\t\t\t\t\t) as Media | undefined )\n\t\t\t\t: undefined,\n\t\t[ originalId ]\n\t);\n\tconst originalWidth = Number( originalRecord?.media_details?.width );\n\tconst originalHeight = Number( originalRecord?.media_details?.height );\n\tconst originalUrl = originalRecord?.source_url;\n\tconst originalSource =\n\t\toriginalId &&\n\t\toriginalRecord &&\n\t\ttypeof originalUrl === 'string' &&\n\t\toriginalUrl.length > 0 &&\n\t\tNumber.isFinite( originalWidth ) &&\n\t\toriginalWidth > 0 &&\n\t\tNumber.isFinite( originalHeight ) &&\n\t\toriginalHeight > 0\n\t\t\t? {\n\t\t\t\t\tid: originalId,\n\t\t\t\t\turl: originalUrl,\n\t\t\t\t\tmedia: originalRecord,\n\t\t\t\t}\n\t\t\t: undefined;\n\tconst canRestoreOriginal = !! originalSource;\n\tconst replacementSource =\n\t\tisSourceReplaced && originalSource\n\t\t\t? {\n\t\t\t\t\tid: originalSource.id,\n\t\t\t\t\turl: originalSource.url,\n\t\t\t\t\tmedia: originalSource.media,\n\t\t\t\t}\n\t\t\t: undefined;\n\t// Details and pending edits follow the attachment shown on the canvas.\n\t// Keep `sourceMedia` separate for the snackbar's previous attachment.\n\tconst activeId = replacementSource?.id ?? id;\n\tconst { media, hasEdits } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\tgetEntityRecord,\n\t\t\t\thasEditsForEntityRecord,\n\t\t\t} = select( coreStore );\n\t\t\t// Fetch embedded author and attached-post data for Details.\n\t\t\tgetEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tactiveId,\n\t\t\t\tATTACHMENT_EMBED_QUERY\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tmedia: getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t) as Media,\n\t\t\t\thasEdits: hasEditsForEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tactiveId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ activeId ]\n\t);\n\t// Refresh embedded data on opening or switching to the original.\n\tuseEffect( () => {\n\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t'postType',\n\t\t\t'attachment',\n\t\t\tactiveId,\n\t\t\tATTACHMENT_EMBED_QUERY,\n\t\t] );\n\t}, [ activeId, invalidateResolution ] );\n\tconst handleRestoreOriginal = useCallback( () => {\n\t\t// Restoring discards every pending edit, as the menu item says, so\n\t\t// nothing staged against the attachment being replaced reaches a save.\n\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\n\t\tif ( onEditOriginal && originalId ) {\n\t\t\tonEditOriginal( originalId );\n\t\t\treturn;\n\t\t}\n\t\tsetIsSourceReplaced( true );\n\t}, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );\n\n\t// A bare replacement has no image editor change, so OR the flag in explicitly.\n\tconst hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;\n\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;\n\tconst isImage = !! media && mediaType === 'image';\n\n\t// Docked, the panel opens on Crop: the canvas is still beside it and\n\t// cropping is what the editor is for. Below `small` an open panel covers\n\t// the canvas, and crop controls with no crop in sight are not worth\n\t// opening on, so Details leads there. Non-image media has no Crop tab at\n\t// all (see `tabs`), so it always gets Details.\n\tconst currentTab =\n\t\tchosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );\n\t// `null` when nothing is open, otherwise the open panel's id. Until the\n\t// user opens or closes the panel, follow the breakpoint: dragging a window\n\t// narrow hands the canvas the full width instead of leaving a panel\n\t// wedged beside it.\n\tlet activePanel = chosenPanel;\n\tif ( activePanel === undefined ) {\n\t\tactivePanel = isWide ? currentTab : null;\n\t}\n\t// Switching tabs says nothing about whether the panel should be open, so\n\t// it leaves `chosenPanel` unset: picking Details on a wide screen and then\n\t// dragging the window narrow should still hand the canvas the full width.\n\tconst selectPanel = useCallback( ( panel: string ) => {\n\t\tsetChosenTab( panel );\n\t\tsetChosenPanel( ( chosen ) =>\n\t\t\tchosen === undefined ? chosen : panel\n\t\t);\n\t}, [] );\n\tconst togglePanel = useCallback( () => {\n\t\tsetChosenPanel( activePanel ? null : currentTab );\n\t}, [ activePanel, currentTab ] );\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {\n\t\tsession,\n\t\tid,\n\t\tisImage,\n\t\tmedia: sourceMedia,\n\t\tonSaved,\n\t\treplacementSource,\n\t} );\n\n\tconst handleChange = ( updates: Partial< Media > ) => {\n\t\t// A save reads the pending edits once and then waits. An edit\n\t\t// arriving after that read misses the request, and a crop save\n\t\t// then clears the edits for this id, so it would be lost rather\n\t\t// than merely late. It would also land on the attachment being\n\t\t// replaced, not the new one the modal moves to.\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\teditEntityRecord( 'postType', 'attachment', activeId, updates );\n\t};\n\n\tconst discardAndClose = () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tclearEntityRecordEdits( 'postType', 'attachment', activeId );\n\t\tsetIsSourceReplaced( false );\n\t\tonClose?.();\n\t};\n\n\tconst handleRequestClose = () => {\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasChanges ) {\n\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\treturn;\n\t\t}\n\t\tdiscardAndClose();\n\t};\n\n\tconst handleKeyDown = ( event: ReactKeyboardEvent< HTMLElement > ) => {\n\t\tconst isUndoShortcut = isKeyboardEvent.primary( event, 'z' );\n\t\tconst isRedoShortcut =\n\t\t\tisKeyboardEvent.primaryShift( event, 'z' ) ||\n\t\t\t( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );\n\t\tif ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tconst isMetadataField =\n\t\t\t\t( target.tagName === 'INPUT' ||\n\t\t\t\t\ttarget.tagName === 'TEXTAREA' ||\n\t\t\t\t\ttarget.isContentEditable ) &&\n\t\t\t\t! target.closest( `[${ CROP_CONTROL_ATTR }]` );\n\t\t\tif ( ! isMetadataField ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( isCropInteractionActive || isSaving ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( isRedoShortcut ) {\n\t\t\t\t\tsession.redo();\n\t\t\t\t} else {\n\t\t\t\t\tsession.undo();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( shouldCloseOnEsc ) {\n\t\t\tif ( event.code !== 'Escape' && event.key !== 'Escape' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( isSaving ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( hasChanges ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\t}\n\t\t}\n\t};\n\n\tconst snackbar = (\n\t\t<SnackbarNotices\n\t\t\tclassName={ noticesClassName }\n\t\t\tcontext={ MEDIA_EDITOR_NOTICES_CONTEXT }\n\t\t/>\n\t);\n\n\t// Below `small` the panel is full screen, so an open one replaces the\n\t// canvas and these never share the screen with the Crop panel's copies:\n\t// this row is what reaches rotate/flip/zoom while the panel is closed,\n\t// with aspect ratio joining them as a dropdown. From `small` up the Crop\n\t// panel docks beside the canvas and carries them instead.\n\tconst imageControls =\n\t\tisImage && ! isWide ? (\n\t\t\t<MediaEditorImageControls\n\t\t\t\tshowAspectRatioControl\n\t\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t/>\n\t\t) : null;\n\n\t// Crop leads, since it is what the docked panel opens on. Non-image media\n\t// has nothing to crop and gets Details alone, which is why the sidebar\n\t// takes this list rather than deriving it.\n\tconst tabs: MediaEditorTab[] = [\n\t\t...( isImage\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: CROP_PANEL,\n\t\t\t\t\t\ttitle: __( 'Crop' ),\n\t\t\t\t\t\trender: () => (\n\t\t\t\t\t\t\t<MediaEditorCropPanel\n\t\t\t\t\t\t\t\taspectRatioValue={ aspectRatioValue }\n\t\t\t\t\t\t\t\tonAspectRatioChange={ setAspectRatioValue }\n\t\t\t\t\t\t\t\taspectRatioOptions={ aspectRatioOptions }\n\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [] ),\n\t\t{\n\t\t\tid: DETAILS_PANEL,\n\t\t\ttitle: __( 'Details' ),\n\t\t\trender: () => <MediaForm />,\n\t\t},\n\t];\n\n\tconst ruler = isImage ? (\n\t\t<MediaEditorFineRotation\n\t\t\tonPlacementControlInteraction={ signalPlacementControlInteraction }\n\t\t\tdisabled={ isSaving }\n\t\t/>\n\t) : null;\n\n\tconst children = (\n\t\t<MediaEditorProvider\n\t\t\tvalue={ media ?? undefined }\n\t\t\tonChange={ handleChange }\n\t\t\tsettings={ {\n\t\t\t\t// Disable the fields while saving, so the guard in\n\t\t\t\t// `handleChange` is not silently swallowing typing.\n\t\t\t\t// `readOnly` would swap the field's layout mid-save;\n\t\t\t\t// disabled keeps it in place and greys it out.\n\t\t\t\tfields: isSaving\n\t\t\t\t\t? fields.map( ( field ) => ( {\n\t\t\t\t\t\t\t...field,\n\t\t\t\t\t\t\tisDisabled: true,\n\t\t\t\t\t\t} ) )\n\t\t\t\t\t: fields,\n\t\t\t\tform,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"media-editor\">\n\t\t\t\t{ ! media ? (\n\t\t\t\t\t<div className=\"media-editor__loading\">\n\t\t\t\t\t\t<WCSpinner />\n\t\t\t\t\t</div>\n\t\t\t\t) : (\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ clsx( 'media-editor__body', {\n\t\t\t\t\t\t\t'has-panel-open': !! activePanel,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<NavigableRegion\n\t\t\t\t\t\t\tclassName=\"media-editor__content\"\n\t\t\t\t\t\t\tariaLabel={\n\t\t\t\t\t\t\t\tisImage\n\t\t\t\t\t\t\t\t\t? __( 'Image editor' )\n\t\t\t\t\t\t\t\t\t: __( 'Media preview' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div className=\"media-editor__canvas-area\">\n\t\t\t\t\t\t\t\t{ isImage ? (\n\t\t\t\t\t\t\t\t\t<MediaEditorCanvas\n\t\t\t\t\t\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\t\t\t\t\t\tonGestureStart={\n\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureStart\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonGestureEnd={ handleCanvasGestureEnd }\n\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<MediaPreview />\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{ isImage && (\n\t\t\t\t\t\t\t\t<div className=\"media-editor__canvas-toolbar\">\n\t\t\t\t\t\t\t\t\t{ ruler }\n\t\t\t\t\t\t\t\t\t{ imageControls }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</NavigableRegion>\n\t\t\t\t\t\t<AnimatePresence\n\t\t\t\t\t\t\tinitial={ false }\n\t\t\t\t\t\t\tcustom={ sidebarTransition }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ !! activePanel && (\n\t\t\t\t\t\t\t\t<motion.div\n\t\t\t\t\t\t\t\t\tclassName=\"media-editor__sidebar-container\"\n\t\t\t\t\t\t\t\t\tvariants={ sidebarVariants }\n\t\t\t\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\t\t\t\ttransition={ sidebarTransition }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<MediaEditorSidebar\n\t\t\t\t\t\t\t\t\t\ttabs={ tabs }\n\t\t\t\t\t\t\t\t\t\t// Swapping the edited media can drop the\n\t\t\t\t\t\t\t\t\t\t// Crop tab out from under an open panel —\n\t\t\t\t\t\t\t\t\t\t// saving a crop moves the editor to a new\n\t\t\t\t\t\t\t\t\t\t// id, which may resolve as non-image.\n\t\t\t\t\t\t\t\t\t\t// Fall back rather than hand `Tabs.Root`\n\t\t\t\t\t\t\t\t\t\t// a value no tab matches.\n\t\t\t\t\t\t\t\t\t\tactiveTab={\n\t\t\t\t\t\t\t\t\t\t\ttabs.some(\n\t\t\t\t\t\t\t\t\t\t\t\t( tab ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t\ttab.id === activePanel\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t? activePanel\n\t\t\t\t\t\t\t\t\t\t\t\t: DETAILS_PANEL\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonSelectTab={ selectPanel }\n\t\t\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</motion.div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</AnimatePresence>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isDiscardDialogOpen }\n\t\t\t\tconfirmButtonText={ __( 'Discard' ) }\n\t\t\t\tcancelButtonText={ __( 'Keep editing' ) }\n\t\t\t\tonCancel={ () => setIsDiscardDialogOpen( false ) }\n\t\t\t\tonConfirm={ () => {\n\t\t\t\t\tsetIsDiscardDialogOpen( false );\n\t\t\t\t\tdiscardAndClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __(\n\t\t\t\t\t'Are you sure you want to discard your unsaved changes?'\n\t\t\t\t) }\n\t\t\t</ConfirmDialog>\n\t\t\t{ noticesPortalElement\n\t\t\t\t? createPortal( snackbar, noticesPortalElement )\n\t\t\t\t: snackbar }\n\t\t</MediaEditorProvider>\n\t);\n\n\t// Rebuilt each render, like the elements it replaces: consumers re-render\n\t// as they always did, but the cluster component types stay stable.\n\tconst contextValue: MediaEditorFrameContextValue = {\n\t\tisImage,\n\t\tisSaving,\n\t\thasMedia: !! media,\n\t\thasChanges,\n\t\t// Saving freezes the whole edit surface: `save()` reads the\n\t\t// modifiers once and then awaits, so anything changed after that\n\t\t// would be silently dropped when the save resolves.\n\t\tisUndoRedoDisabled: isCropInteractionActive || isSaving,\n\t\taspectRatioPresets,\n\t\tisWide,\n\t\tactivePanel,\n\t\tonTogglePanel: togglePanel,\n\t\tonCancel: handleRequestClose,\n\t\tonSave: saveMediaEditor,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\topensOriginal: !! onEditOriginal,\n\t\tonRestoreOriginal: handleRestoreOriginal,\n\t};\n\n\treturn (\n\t\t<MediaEditorFrameContext.Provider value={ contextValue }>\n\t\t\t{ renderFrame( {\n\t\t\t\tchildren,\n\t\t\t\tisImage,\n\t\t\t\tlayout,\n\t\t\t\tonRequestClose: handleRequestClose,\n\t\t\t\tonKeyDown: handleKeyDown,\n\t\t\t\tshouldCloseOnClickOutside: ! hasChanges && ! isSaving,\n\t\t\t\tisSaving,\n\t\t\t\thasChanges,\n\t\t\t\thasMedia: !! media,\n\t\t\t} ) }\n\t\t</MediaEditorFrameContext.Provider>\n\t);\n}\n\nexport function MediaEditor( props: MediaEditorProps ) {\n\treturn (\n\t\t<MediaEditorStateProvider key={ props.id }>\n\t\t\t<MediaEditorContent { ...props } />\n\t\t</MediaEditorStateProvider>\n\t);\n}\n\n// Attached to `MediaEditor` so frames import and arrange them, the way\n// `DataViewsPicker` exposes its own sub-components. They read what they need\n// from context, so a frame only chooses where they go and how they look.\nMediaEditor.HeaderActions = HeaderActions;\nMediaEditor.PanelToggle = PanelToggle;\nMediaEditor.MoreMenu = MoreMenu;\nMediaEditor.HistoryActions = HistoryActions;\nMediaEditor.SaveActions = SaveActions;\n\nexport default MediaEditor;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,MAAM,y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D;IACC,QAAS;IACT,mBAAoB,GAAI,SAAU;IAClC,kBAAmB,GAAI,cAAe;IACtC,gBAAiB,uBAAwB,KAAM;IAC/C,iBAAkB;KACjB,uBAAwB,KAAM;KAC9B,gBAAgB;IACjB;IAEE,UAAA,GACD,wDACD;GACc,CAAA;GACb,uBACC,aAAc,UAAU,oBAAqB,IAC7C;EACiB;;CAKtB,MAAM,eAA6C;EAClD;EACA;EACA,UAAU,CAAC,CAAE;EACb;EAIA,oBAAoB,2BAA2B;EAC/C;EACA;EACA;EACA,eAAe;EACf,UAAU;EACV,QAAQ;EACR;EACA;EACA,eAAe,CAAC,CAAE;EAClB,mBAAmB;CACpB;CAEA,OACC,oBAAC,wBAAwB,UAAzB;EAAkC,OAAQ;EACvC,UAAA,YAAa;GACd;GACA;GACA;GACA,gBAAgB;GAChB,WAAW;GACX,2BAA2B,CAAE,cAAc,CAAE;GAC7C;GACA;GACA,UAAU,CAAC,CAAE;EACd,CAAE;CAC+B,CAAA;AAEpC;AAEA,SAAgB,YAAa,OAA0B;CACtD,OACC,oBAAC,0BAAD,EAAA,UACC,oBAAC,oBAAD,EAAoB,GAAK,MAAS,CAAA,EACT,GAFM,MAAM,EAEZ;AAE5B;AAKA,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,WAAW;AACvB,YAAY,iBAAiB;AAC7B,YAAY,cAAc"}
@@ -1,5 +1,6 @@
1
1
  import { useMemo } from "@wordpress/element";
2
- import { DEFAULT_ASPECT_RATIOS, resolveAspectRatio, useMediaEditor } from "../../state/index.mjs";
2
+ import { DEFAULT_ASPECT_RATIOS } from "../../state/aspect-ratio-presets.mjs";
3
+ import { useMediaEditor } from "../../state/index.mjs";
3
4
  // packages/media-editor/src/components/media-editor/use-crop-options.ts
4
5
  /**
5
6
  * Build the preset list shown in the dropdown — always include the
@@ -15,8 +16,7 @@ function getAspectRatioOptions(aspectRatioPresets) {
15
16
  /**
16
17
  * Thin selector over the composite media-editor store for the Crop
17
18
  * sidebar tab. Reads the cropOptions slice (preset key) and exposes
18
- * the corresponding setters plus a render-time `resolvedAspectRatio`
19
- * derivation.
19
+ * the corresponding setters plus the ratio the image editor has locked.
20
20
  *
21
21
  * No local React state, no refs, no synchronization effects — the
22
22
  * composite store is the single source of truth.
@@ -27,9 +27,8 @@ function getAspectRatioOptions(aspectRatioPresets) {
27
27
  function useCropOptions({ aspectRatioPresets } = {}) {
28
28
  const controller = useMediaEditor();
29
29
  const { aspectRatioValue } = controller.cropOptions;
30
- const cropperImage = controller.cropper.state.image;
31
30
  const aspectRatioOptions = useMemo(() => getAspectRatioOptions(aspectRatioPresets), [aspectRatioPresets]);
32
- const resolvedAspectRatio = useMemo(() => resolveAspectRatio(aspectRatioValue, cropperImage), [aspectRatioValue, cropperImage]);
31
+ const resolvedAspectRatio = controller.imageEditor.state.aspectRatio;
33
32
  return {
34
33
  aspectRatioValue,
35
34
  setAspectRatioValue: controller.setAspectRatioValue,
@@ -1 +1 @@
1
- {"version":3,"file":"use-crop-options.mjs","names":[],"sources":["../../../src/components/media-editor/use-crop-options.ts"],"sourcesContent":["import { useMemo } from '@wordpress/element';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport {\n\tDEFAULT_ASPECT_RATIOS,\n\tuseMediaEditor,\n\tresolveAspectRatio,\n} from '../../state';\n\ninterface UseCropOptionsArgs {\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\ninterface UseCropOptionsReturn {\n\taspectRatioValue: string;\n\tsetAspectRatioValue: ( value: string ) => void;\n\taspectRatioOptions: AspectRatioPreset[];\n\tresolvedAspectRatio: number | undefined;\n}\n\n/**\n * Build the preset list shown in the dropdown — always include the\n * non-numeric presets (Free, Original) and append either the\n * caller-supplied set or the defaults.\n *\n * @param aspectRatioPresets Optional caller-supplied presets.\n * @return The full preset list to render.\n */\nexport function getAspectRatioOptions(\n\taspectRatioPresets?: AspectRatioPreset[]\n): AspectRatioPreset[] {\n\treturn [\n\t\t...DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value <= 0 ),\n\t\t...( aspectRatioPresets ??\n\t\t\tDEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value > 0 ) ),\n\t];\n}\n\n/**\n * Thin selector over the composite media-editor store for the Crop\n * sidebar tab. Reads the cropOptions slice (preset key) and exposes\n * the corresponding setters plus a render-time `resolvedAspectRatio`\n * derivation.\n *\n * No local React state, no refs, no synchronization effects — the\n * composite store is the single source of truth.\n *\n * @param args\n * @param args.aspectRatioPresets Optional caller-supplied aspect-ratio presets.\n */\nexport function useCropOptions( {\n\taspectRatioPresets,\n}: UseCropOptionsArgs = {} ): UseCropOptionsReturn {\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\tconst cropperImage = controller.cropper.state.image;\n\n\tconst aspectRatioOptions = useMemo(\n\t\t() => getAspectRatioOptions( aspectRatioPresets ),\n\t\t[ aspectRatioPresets ]\n\t);\n\n\tconst resolvedAspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\n\t);\n\n\treturn {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue: controller.setAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresolvedAspectRatio,\n\t};\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAgB,sBACf,oBACsB;CACtB,OAAO,CACN,GAAG,sBAAsB,QAAU,WAAY,OAAO,SAAS,CAAE,GACjE,GAAK,sBACJ,sBAAsB,QAAU,WAAY,OAAO,QAAQ,CAAE,CAC/D;AACD;;;;;;;;;;;;;AAcA,SAAgB,eAAgB,EAC/B,uBACuB,CAAC,GAA0B;CAClD,MAAM,aAAa,eAAe;CAClC,MAAM,EAAE,qBAAqB,WAAW;CACxC,MAAM,eAAe,WAAW,QAAQ,MAAM;CAE9C,MAAM,qBAAqB,cACpB,sBAAuB,kBAAmB,GAChD,CAAE,kBAAmB,CACtB;CAEA,MAAM,sBAAsB,cACrB,mBAAoB,kBAAkB,YAAa,GACzD,CAAE,kBAAkB,YAAa,CAClC;CAEA,OAAO;EACN;EACA,qBAAqB,WAAW;EAChC;EACA;CACD;AACD"}
1
+ {"version":3,"file":"use-crop-options.mjs","names":[],"sources":["../../../src/components/media-editor/use-crop-options.ts"],"sourcesContent":["import { useMemo } from '@wordpress/element';\nimport {\n\tDEFAULT_ASPECT_RATIOS,\n\ttype AspectRatioPreset,\n} from '../../state/aspect-ratio-presets';\nimport { useMediaEditor } from '../../state';\n\ninterface UseCropOptionsArgs {\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\ninterface UseCropOptionsReturn {\n\taspectRatioValue: string;\n\tsetAspectRatioValue: ( value: string ) => void;\n\taspectRatioOptions: AspectRatioPreset[];\n\tresolvedAspectRatio: number | undefined;\n}\n\n/**\n * Build the preset list shown in the dropdown — always include the\n * non-numeric presets (Free, Original) and append either the\n * caller-supplied set or the defaults.\n *\n * @param aspectRatioPresets Optional caller-supplied presets.\n * @return The full preset list to render.\n */\nexport function getAspectRatioOptions(\n\taspectRatioPresets?: AspectRatioPreset[]\n): AspectRatioPreset[] {\n\treturn [\n\t\t...DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value <= 0 ),\n\t\t...( aspectRatioPresets ??\n\t\t\tDEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value > 0 ) ),\n\t];\n}\n\n/**\n * Thin selector over the composite media-editor store for the Crop\n * sidebar tab. Reads the cropOptions slice (preset key) and exposes\n * the corresponding setters plus the ratio the image editor has locked.\n *\n * No local React state, no refs, no synchronization effects — the\n * composite store is the single source of truth.\n *\n * @param args\n * @param args.aspectRatioPresets Optional caller-supplied aspect-ratio presets.\n */\nexport function useCropOptions( {\n\taspectRatioPresets,\n}: UseCropOptionsArgs = {} ): UseCropOptionsReturn {\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\n\tconst aspectRatioOptions = useMemo(\n\t\t() => getAspectRatioOptions( aspectRatioPresets ),\n\t\t[ aspectRatioPresets ]\n\t);\n\n\t// The image editor owns the locked ratio; the preset is what the\n\t// dropdown shows.\n\tconst resolvedAspectRatio = controller.imageEditor.state.aspectRatio;\n\n\treturn {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue: controller.setAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresolvedAspectRatio,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,SAAgB,sBACf,oBACsB;CACtB,OAAO,CACN,GAAG,sBAAsB,QAAU,WAAY,OAAO,SAAS,CAAE,GACjE,GAAK,sBACJ,sBAAsB,QAAU,WAAY,OAAO,QAAQ,CAAE,CAC/D;AACD;;;;;;;;;;;;AAaA,SAAgB,eAAgB,EAC/B,uBACuB,CAAC,GAA0B;CAClD,MAAM,aAAa,eAAe;CAClC,MAAM,EAAE,qBAAqB,WAAW;CAExC,MAAM,qBAAqB,cACpB,sBAAuB,kBAAmB,GAChD,CAAE,kBAAmB,CACtB;CAIA,MAAM,sBAAsB,WAAW,YAAY,MAAM;CAEzD,OAAO;EACN;EACA,qBAAqB,WAAW;EAChC;EACA;CACD;AACD"}
@@ -4,7 +4,7 @@ import { store } from "@wordpress/core-data";
4
4
  import { useCallback, useState } from "@wordpress/element";
5
5
  import { __, sprintf } from "@wordpress/i18n";
6
6
  import { store as store$1 } from "@wordpress/notices";
7
- import { buildModifiers } from "../media-editor-modal/build-modifiers.mjs";
7
+ import { getImageEdit, mapImageEdit } from "@wordpress/image-editor";
8
8
  // packages/media-editor/src/components/media-editor/use-save-media-editor.ts
9
9
  const METADATA_EDIT_KEYS = [
10
10
  "title",
@@ -16,7 +16,27 @@ const METADATA_EDIT_KEYS = [
16
16
  const MEDIA_EDITOR_NOTICES_CONTEXT = "media-editor";
17
17
  function getCropModifiers(session) {
18
18
  if (!session.hasOutputEdits) return [];
19
- return buildModifiers(session.cropper);
19
+ const edit = getImageEdit(session.imageEditor.state);
20
+ if (!edit) return [];
21
+ return mapImageEdit(edit, {
22
+ flip: (flip) => ({
23
+ type: "flip",
24
+ args: { flip }
25
+ }),
26
+ rotation: (angle) => ({
27
+ type: "rotate",
28
+ args: { angle }
29
+ }),
30
+ crop: ({ x, y, width, height }) => ({
31
+ type: "crop",
32
+ args: {
33
+ left: x * 100,
34
+ top: y * 100,
35
+ width: width * 100,
36
+ height: height * 100
37
+ }
38
+ })
39
+ });
20
40
  }
21
41
  function getMetadataEdits(pendingEdits, media) {
22
42
  const metadataEdits = {};
@@ -61,7 +81,7 @@ function useSaveMediaEditor({ session, id, isImage, media, onSaved, replacementS
61
81
  const next = saved ?? targetMedia;
62
82
  if (next && next.id !== targetId) clearEntityRecordEdits("postType", "attachment", targetId);
63
83
  if (next && next.id) {
64
- if (next.id === id) session.cropper.reset();
84
+ if (next.id === id) session.reset();
65
85
  onSaved?.({
66
86
  id: next.id,
67
87
  url: next.source_url,