@wordpress/media-editor 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor/index.tsx"],
4
- "sourcesContent": ["import clsx from 'clsx';\nimport {\n\tButton,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';\nimport { 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 } 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\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\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\tonReset: () => void;\n\t/**\n\t * When `true`, the media has a lineage root to restore to, so the\n\t * \"Restore original image\" menu item is shown.\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 HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {\n\tconst {\n\t\tisImage,\n\t\tisSaving,\n\t\tonCancel,\n\t\tisWide,\n\t\tactivePanel,\n\t\tonTogglePanel,\n\t\tcanRestoreOriginal,\n\t\tisSourceReplaced,\n\t\tonRestoreOriginal,\n\t} = useMediaEditorFrameContext();\n\tconst isPanelOpen = !! activePanel;\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\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{ /* The sidebar holds more than one panel, so this opens and\n\t\t\t closes the sidebar rather than naming a panel: reopening\n\t\t\t returns to whichever tab was last showing, and the tab strip\n\t\t\t inside switches between them. */ }\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ drawerRight }\n\t\t\t\tlabel={ __( 'Media settings' ) }\n\t\t\t\tisPressed={ isPanelOpen }\n\t\t\t\t// Only a docked column really expands beside the canvas; below\n\t\t\t\t// that the panel replaces the view, which the pressed state\n\t\t\t\t// already describes.\n\t\t\t\taria-expanded={ isWide ? isPanelOpen : undefined }\n\t\t\t\tonClick={ onTogglePanel }\n\t\t\t/>\n\t\t\t{ isImage && (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\tlabel={ __( 'More options' ) }\n\t\t\t\t\ttoggleProps={ { size: 'compact' } }\n\t\t\t\t>\n\t\t\t\t\t{ ( { onClose: closeMenu } ) => (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ canRestoreOriginal && (\n\t\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={ backup }\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t\t\t\t\tisSourceReplaced || isSaving\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t\t\t'Discards unsaved changes and loads the original image.'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonRestoreOriginal();\n\t\t\t\t\t\t\t\t\t\t\tcloseMenu();\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Restore original image' ) }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t\t) }\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) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\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\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</Stack>\n\t);\n}\n\nfunction HistoryActions() {\n\tconst { isImage, isUndoRedoDisabled, onReset, isWide, activePanel } =\n\t\tuseMediaEditorFrameContext();\n\tconst {\n\t\tcropper: { reset },\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t\tbeginGesture,\n\t\tendGesture,\n\t} = useMediaEditor();\n\t// Reset, undo and redo act on the cropper, so they only appear where the\n\t// 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\tbeginGesture();\n\t\treset();\n\t\tonReset();\n\t\tendGesture();\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\tvariant=\"tertiary\"\n\t\t\t\tdisabled={ isUndoRedoDisabled || ! isDirty }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ handleReset }\n\t\t\t>\n\t\t\t\t{ __( 'Reset' ) }\n\t\t\t</Button>\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</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\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// `hasChosenPanelRef` below.\n\tconst isWide = useViewportMatch( 'small' );\n\t// `null` when nothing is open, otherwise the open panel's id.\n\tconst [ activePanel, setActivePanel ] = useState< string | null >(\n\t\tisWide ? DETAILS_PANEL : null\n\t);\n\t// Width picks the starting panel, but only until the user picks one. After\n\t// that their choice holds for the rest of the session: closing the panel\n\t// and then resizing — or crossing the breakpoint by rotating a tablet —\n\t// should not reopen something they just dismissed.\n\tconst hasChosenPanelRef = useRef( false );\n\t// The panel the toggle reopens, and the one width picks until the user\n\t// picks their own. Tracked separately from `hasChosenPanelRef` because\n\t// the two answer different questions: whether the panel should be open,\n\t// and which tab it should show.\n\tconst lastPanelRef = useRef( DETAILS_PANEL );\n\tconst hasChosenTabRef = useRef( false );\n\t// Switching tabs says nothing about whether the panel should be open, so\n\t// it leaves `hasChosenPanelRef` alone: picking Details on a wide screen\n\t// and then dragging the window narrow should still hand the canvas the\n\t// full width.\n\tconst selectPanel = useCallback( ( panel: string ) => {\n\t\thasChosenTabRef.current = true;\n\t\tlastPanelRef.current = panel;\n\t\tsetActivePanel( panel );\n\t}, [] );\n\tconst togglePanel = useCallback( () => {\n\t\thasChosenPanelRef.current = true;\n\t\tsetActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );\n\t}, [] );\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\tuseEffect( () => {\n\t\tsetIsPlacementActive( false );\n\t\tsetIsCanvasGestureActive( false );\n\t\tsetIsSourceReplaced( false );\n\t}, [ id ] );\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// Until the user picks a 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\t//\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. `isImage` comes from a\n\t// record that resolves after mount, which is why this runs in an effect\n\t// rather than seeding `useState`.\n\tuseEffect( () => {\n\t\tif ( hasChosenPanelRef.current && hasChosenTabRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tconst defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;\n\t\tif ( ! hasChosenTabRef.current ) {\n\t\t\tlastPanelRef.current = defaultPanel;\n\t\t}\n\t\tif ( ! hasChosenPanelRef.current ) {\n\t\t\tsetActivePanel( isWide ? lastPanelRef.current : null );\n\t\t}\n\t}, [ isWide, isImage ] );\n\t// Only `resetCropOptions` is needed here, for the Reset button; the\n\t// aspect-ratio members are read by `MediaEditorImageControls` itself.\n\tconst {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresetCropOptions,\n\t} = useCropOptions( { 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} }\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<Spinner />\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{ !! activePanel && (\n\t\t\t\t\t\t\t<MediaEditorSidebar\n\t\t\t\t\t\t\t\ttabs={ tabs }\n\t\t\t\t\t\t\t\t// Swapping the edited media can drop the Crop\n\t\t\t\t\t\t\t\t// tab out from under an open panel — saving a\n\t\t\t\t\t\t\t\t// crop moves the editor to a new id, which may\n\t\t\t\t\t\t\t\t// resolve as non-image. Fall back rather than\n\t\t\t\t\t\t\t\t// hand `Tabs.Root` a value no tab matches.\n\t\t\t\t\t\t\t\tactiveTab={\n\t\t\t\t\t\t\t\t\ttabs.some(\n\t\t\t\t\t\t\t\t\t\t( tab ) => tab.id === activePanel\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t? activePanel\n\t\t\t\t\t\t\t\t\t\t: DETAILS_PANEL\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonSelectTab={ selectPanel }\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</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\tonReset: resetCropOptions,\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.HistoryActions = HistoryActions;\nMediaEditor.SaveActions = SaveActions;\n\nexport default MediaEditor;\n"],
5
- "mappings": ";AAAA,OAAO,UAAU;AACjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAA+B;AAAA,OACzB;AACP,SAAS,OAAO,MAAM,sBAAsB;AAC5C,SAAS,wBAAwB;AACjC,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,iBAAiB;AACnC,SAAS,uBAAuB;AAChC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,iBAAiB,SAAS,oBAAoB;AAOvD,SAAS,2BAA2B;AAEpC,OAAO,kBAAkB;AACzB,OAAO,uBAAuB;AAC9B,OAAO,6BAA6B;AACpC,OAAO,0BAA0B;AACjC,OAAO,8BAA8B;AACrC,OAAO,eAAe;AACtB,SAAS,gCAAgC;AACzC,SAAS,0BAA0B,sBAAsB;AAEzD,SAAS,yBAAyB;AAClC,OAAO,uCAAuC;AAC9C;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W;AAAA,IACX,2BAA2B,CAAE,cAAc,CAAE;AAAA,IAC7C;AAAA,IACA;AAAA,IACA,UAAU,CAAC,CAAE;AAAA,EACd,CAAE,GACH;AAEF;AAEO,SAAS,YAAa,OAA0B;AACtD,SACC,oBAAC,4BACA,8BAAC,sBAAqB,GAAG,OAAQ,KADF,MAAM,EAEtC;AAEF;AAKA,YAAY,gBAAgB;AAC5B,YAAY,iBAAiB;AAC7B,YAAY,cAAc;AAE1B,IAAO,uBAAQ;",
6
- "names": []
7
- }
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;E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,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,37 +1,42 @@
1
- // packages/media-editor/src/components/media-editor/use-crop-options.ts
2
1
  import { useMemo } from "@wordpress/element";
3
- import { DEFAULT_ASPECT_RATIOS } from "../../image-editor/core/constants.mjs";
4
- import { useMediaEditor, resolveAspectRatio } from "../../state/index.mjs";
2
+ import { DEFAULT_ASPECT_RATIOS, resolveAspectRatio, useMediaEditor } from "../../state/index.mjs";
3
+ // packages/media-editor/src/components/media-editor/use-crop-options.ts
4
+ /**
5
+ * Build the preset list shown in the dropdown — always include the
6
+ * non-numeric presets (Free, Original) and append either the
7
+ * caller-supplied set or the defaults.
8
+ *
9
+ * @param aspectRatioPresets Optional caller-supplied presets.
10
+ * @return The full preset list to render.
11
+ */
5
12
  function getAspectRatioOptions(aspectRatioPresets) {
6
- return [
7
- ...DEFAULT_ASPECT_RATIOS.filter((preset) => preset.value <= 0),
8
- ...aspectRatioPresets ?? DEFAULT_ASPECT_RATIOS.filter((preset) => preset.value > 0)
9
- ];
13
+ return [...DEFAULT_ASPECT_RATIOS.filter((preset) => preset.value <= 0), ...aspectRatioPresets ?? DEFAULT_ASPECT_RATIOS.filter((preset) => preset.value > 0)];
10
14
  }
11
- function useCropOptions({
12
- aspectRatioPresets
13
- } = {}) {
14
- const controller = useMediaEditor();
15
- const { aspectRatioValue } = controller.cropOptions;
16
- const cropperImage = controller.cropper.state.image;
17
- const aspectRatioOptions = useMemo(
18
- () => getAspectRatioOptions(aspectRatioPresets),
19
- [aspectRatioPresets]
20
- );
21
- const resolvedAspectRatio = useMemo(
22
- () => resolveAspectRatio(aspectRatioValue, cropperImage),
23
- [aspectRatioValue, cropperImage]
24
- );
25
- return {
26
- aspectRatioValue,
27
- setAspectRatioValue: controller.setAspectRatioValue,
28
- aspectRatioOptions,
29
- resolvedAspectRatio,
30
- resetCropOptions: controller.resetCropOptions
31
- };
15
+ /**
16
+ * Thin selector over the composite media-editor store for the Crop
17
+ * sidebar tab. Reads the cropOptions slice (preset key) and exposes
18
+ * the corresponding setters plus a render-time `resolvedAspectRatio`
19
+ * derivation.
20
+ *
21
+ * No local React state, no refs, no synchronization effects — the
22
+ * composite store is the single source of truth.
23
+ *
24
+ * @param args
25
+ * @param args.aspectRatioPresets Optional caller-supplied aspect-ratio presets.
26
+ */
27
+ function useCropOptions({ aspectRatioPresets } = {}) {
28
+ const controller = useMediaEditor();
29
+ const { aspectRatioValue } = controller.cropOptions;
30
+ const cropperImage = controller.cropper.state.image;
31
+ const aspectRatioOptions = useMemo(() => getAspectRatioOptions(aspectRatioPresets), [aspectRatioPresets]);
32
+ const resolvedAspectRatio = useMemo(() => resolveAspectRatio(aspectRatioValue, cropperImage), [aspectRatioValue, cropperImage]);
33
+ return {
34
+ aspectRatioValue,
35
+ setAspectRatioValue: controller.setAspectRatioValue,
36
+ aspectRatioOptions,
37
+ resolvedAspectRatio
38
+ };
32
39
  }
33
- export {
34
- getAspectRatioOptions,
35
- useCropOptions
36
- };
37
- //# sourceMappingURL=use-crop-options.mjs.map
40
+ export { getAspectRatioOptions, useCropOptions };
41
+
42
+ //# sourceMappingURL=use-crop-options.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor/use-crop-options.ts"],
4
- "sourcesContent": ["import { useMemo } from '@wordpress/element';\nimport { DEFAULT_ASPECT_RATIOS } from '../../image-editor/core/constants';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport { useMediaEditor, resolveAspectRatio } 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\tresetCropOptions: () => void;\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\tresetCropOptions: controller.resetCropOptions,\n\t};\n}\n"],
5
- "mappings": ";AAAA,SAAS,eAAe;AACxB,SAAS,6BAA6B;AAEtC,SAAS,gBAAgB,0BAA0B;AAsB5C,SAAS,sBACf,oBACsB;AACtB,SAAO;AAAA,IACN,GAAG,sBAAsB,OAAQ,CAAE,WAAY,OAAO,SAAS,CAAE;AAAA,IACjE,GAAK,sBACJ,sBAAsB,OAAQ,CAAE,WAAY,OAAO,QAAQ,CAAE;AAAA,EAC/D;AACD;AAcO,SAAS,eAAgB;AAAA,EAC/B;AACD,IAAwB,CAAC,GAA0B;AAClD,QAAM,aAAa,eAAe;AAClC,QAAM,EAAE,iBAAiB,IAAI,WAAW;AACxC,QAAM,eAAe,WAAW,QAAQ,MAAM;AAE9C,QAAM,qBAAqB;AAAA,IAC1B,MAAM,sBAAuB,kBAAmB;AAAA,IAChD,CAAE,kBAAmB;AAAA,EACtB;AAEA,QAAM,sBAAsB;AAAA,IAC3B,MAAM,mBAAoB,kBAAkB,YAAa;AAAA,IACzD,CAAE,kBAAkB,YAAa;AAAA,EAClC;AAEA,SAAO;AAAA,IACN;AAAA,IACA,qBAAqB,WAAW;AAAA,IAChC;AAAA,IACA;AAAA,IACA,kBAAkB,WAAW;AAAA,EAC9B;AACD;",
6
- "names": []
7
- }
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,167 +1,99 @@
1
- // packages/media-editor/src/components/media-editor/use-save-media-editor.ts
2
1
  import apiFetch from "@wordpress/api-fetch";
3
2
  import { useDispatch, useRegistry } from "@wordpress/data";
4
- import { store as coreStore } from "@wordpress/core-data";
3
+ import { store } from "@wordpress/core-data";
5
4
  import { useCallback, useState } from "@wordpress/element";
6
5
  import { __, sprintf } from "@wordpress/i18n";
7
- import { store as noticesStore } from "@wordpress/notices";
8
- import {
9
- buildModifiers
10
- } from "../media-editor-modal/build-modifiers.mjs";
11
- var METADATA_EDIT_KEYS = [
12
- "title",
13
- "caption",
14
- "description",
15
- "alt_text",
16
- "post"
6
+ import { store as store$1 } from "@wordpress/notices";
7
+ import { buildModifiers } from "../media-editor-modal/build-modifiers.mjs";
8
+ // packages/media-editor/src/components/media-editor/use-save-media-editor.ts
9
+ const METADATA_EDIT_KEYS = [
10
+ "title",
11
+ "caption",
12
+ "description",
13
+ "alt_text",
14
+ "post"
17
15
  ];
18
- var MEDIA_EDITOR_NOTICES_CONTEXT = "media-editor";
16
+ const MEDIA_EDITOR_NOTICES_CONTEXT = "media-editor";
19
17
  function getCropModifiers(session) {
20
- const { state } = session.cropper;
21
- if (!session.hasOutputEdits || !state.image) {
22
- return [];
23
- }
24
- return buildModifiers(state, {
25
- width: state.image.naturalWidth,
26
- height: state.image.naturalHeight
27
- });
18
+ if (!session.hasOutputEdits) return [];
19
+ return buildModifiers(session.cropper);
28
20
  }
29
21
  function getMetadataEdits(pendingEdits, media) {
30
- const metadataEdits = {};
31
- for (const key of METADATA_EDIT_KEYS) {
32
- if (pendingEdits && key in pendingEdits) {
33
- metadataEdits[key] = pendingEdits[key];
34
- }
35
- }
36
- if (!("post" in metadataEdits) && media?.post !== void 0) {
37
- metadataEdits.post = media.post;
38
- }
39
- return metadataEdits;
22
+ const metadataEdits = {};
23
+ for (const key of METADATA_EDIT_KEYS) if (pendingEdits && key in pendingEdits) metadataEdits[key] = pendingEdits[key];
24
+ if (!("post" in metadataEdits) && media?.post !== void 0) metadataEdits.post = media.post;
25
+ return metadataEdits;
40
26
  }
41
- function useSaveMediaEditor({
42
- session,
43
- id,
44
- isImage,
45
- media,
46
- onSaved,
47
- replacementSource
48
- }) {
49
- const registry = useRegistry();
50
- const {
51
- clearEntityRecordEdits,
52
- receiveEntityRecords,
53
- saveEditedEntityRecord
54
- } = useDispatch(coreStore);
55
- const { createErrorNotice, removeAllNotices } = useDispatch(noticesStore);
56
- const [isSaving, setIsSaving] = useState(false);
57
- const save = useCallback(async () => {
58
- removeAllNotices("snackbar", MEDIA_EDITOR_NOTICES_CONTEXT);
59
- setIsSaving(true);
60
- try {
61
- let saved;
62
- const modifiers = getCropModifiers(session);
63
- const targetId = replacementSource?.id ?? id;
64
- const targetUrl = replacementSource?.url ?? media?.source_url;
65
- const targetMedia = replacementSource?.media ?? media;
66
- const previous = (modifiers.length > 0 || replacementSource) && media ? {
67
- id,
68
- url: media.source_url
69
- } : void 0;
70
- if (modifiers.length > 0) {
71
- const pendingEdits = registry.select(coreStore).getEntityRecordNonTransientEdits(
72
- "postType",
73
- "attachment",
74
- targetId
75
- );
76
- const metadataEdits = getMetadataEdits(
77
- pendingEdits,
78
- targetMedia
79
- );
80
- saved = await apiFetch({
81
- path: `/wp/v2/media/${targetId}/edit`,
82
- method: "POST",
83
- data: {
84
- src: targetUrl,
85
- modifiers,
86
- ...metadataEdits
87
- }
88
- });
89
- if (saved) {
90
- receiveEntityRecords(
91
- "postType",
92
- "attachment",
93
- saved,
94
- void 0,
95
- true
96
- );
97
- }
98
- } else if (replacementSource && !registry.select(coreStore).hasEditsForEntityRecord(
99
- "postType",
100
- "attachment",
101
- targetId
102
- )) {
103
- saved = replacementSource.media;
104
- } else {
105
- saved = await saveEditedEntityRecord(
106
- "postType",
107
- "attachment",
108
- targetId,
109
- { throwOnError: true }
110
- );
111
- }
112
- const next = saved ?? targetMedia;
113
- if (next && next.id !== targetId) {
114
- clearEntityRecordEdits("postType", "attachment", targetId);
115
- }
116
- if (next && next.id) {
117
- if (next.id === id) {
118
- session.cropper.reset();
119
- }
120
- onSaved?.({
121
- id: next.id,
122
- url: next.source_url,
123
- media: next,
124
- previous
125
- });
126
- }
127
- } catch (error) {
128
- const message = error instanceof Error ? error.message : error?.message ?? __("An unknown error occurred.");
129
- createErrorNotice(
130
- isImage ? sprintf(
131
- /* translators: %s: Error message. */
132
- __("Could not save image. %s"),
133
- message
134
- ) : sprintf(
135
- /* translators: %s: Error message. */
136
- __("Could not save media. %s"),
137
- message
138
- ),
139
- {
140
- type: "snackbar",
141
- context: MEDIA_EDITOR_NOTICES_CONTEXT
142
- }
143
- );
144
- } finally {
145
- setIsSaving(false);
146
- }
147
- }, [
148
- clearEntityRecordEdits,
149
- createErrorNotice,
150
- id,
151
- isImage,
152
- media,
153
- onSaved,
154
- receiveEntityRecords,
155
- registry,
156
- removeAllNotices,
157
- replacementSource,
158
- saveEditedEntityRecord,
159
- session
160
- ]);
161
- return { isSaving, save };
27
+ function useSaveMediaEditor({ session, id, isImage, media, onSaved, replacementSource }) {
28
+ const registry = useRegistry();
29
+ const { clearEntityRecordEdits, receiveEntityRecords, saveEditedEntityRecord } = useDispatch(store);
30
+ const { createErrorNotice, removeAllNotices } = useDispatch(store$1);
31
+ const [isSaving, setIsSaving] = useState(false);
32
+ return {
33
+ isSaving,
34
+ save: useCallback(async () => {
35
+ removeAllNotices("snackbar", MEDIA_EDITOR_NOTICES_CONTEXT);
36
+ setIsSaving(true);
37
+ try {
38
+ let saved;
39
+ const modifiers = getCropModifiers(session);
40
+ const targetId = replacementSource?.id ?? id;
41
+ const targetUrl = replacementSource?.url ?? media?.source_url;
42
+ const targetMedia = replacementSource?.media ?? media;
43
+ const previous = (modifiers.length > 0 || replacementSource) && media ? {
44
+ id,
45
+ url: media.source_url
46
+ } : void 0;
47
+ if (modifiers.length > 0) {
48
+ const metadataEdits = getMetadataEdits(registry.select(store).getEntityRecordNonTransientEdits("postType", "attachment", targetId), targetMedia);
49
+ saved = await apiFetch({
50
+ path: `/wp/v2/media/${targetId}/edit`,
51
+ method: "POST",
52
+ data: {
53
+ src: targetUrl,
54
+ modifiers,
55
+ ...metadataEdits
56
+ }
57
+ });
58
+ if (saved) receiveEntityRecords("postType", "attachment", saved, void 0, true);
59
+ } else if (replacementSource && !registry.select(store).hasEditsForEntityRecord("postType", "attachment", targetId)) saved = replacementSource.media;
60
+ else saved = await saveEditedEntityRecord("postType", "attachment", targetId, { throwOnError: true });
61
+ const next = saved ?? targetMedia;
62
+ if (next && next.id !== targetId) clearEntityRecordEdits("postType", "attachment", targetId);
63
+ if (next && next.id) {
64
+ if (next.id === id) session.cropper.reset();
65
+ onSaved?.({
66
+ id: next.id,
67
+ url: next.source_url,
68
+ media: next,
69
+ previous
70
+ });
71
+ }
72
+ } catch (error) {
73
+ const message = error instanceof Error ? error.message : error?.message ?? __("An unknown error occurred.");
74
+ createErrorNotice(isImage ? sprintf(__("Could not save image. %s"), message) : sprintf(__("Could not save media. %s"), message), {
75
+ type: "snackbar",
76
+ context: MEDIA_EDITOR_NOTICES_CONTEXT
77
+ });
78
+ } finally {
79
+ setIsSaving(false);
80
+ }
81
+ }, [
82
+ clearEntityRecordEdits,
83
+ createErrorNotice,
84
+ id,
85
+ isImage,
86
+ media,
87
+ onSaved,
88
+ receiveEntityRecords,
89
+ registry,
90
+ removeAllNotices,
91
+ replacementSource,
92
+ saveEditedEntityRecord,
93
+ session
94
+ ])
95
+ };
162
96
  }
163
- export {
164
- MEDIA_EDITOR_NOTICES_CONTEXT,
165
- useSaveMediaEditor
166
- };
167
- //# sourceMappingURL=use-save-media-editor.mjs.map
97
+ export { MEDIA_EDITOR_NOTICES_CONTEXT, useSaveMediaEditor };
98
+
99
+ //# sourceMappingURL=use-save-media-editor.mjs.map