@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,43 +1,15 @@
1
- // packages/media-editor/src/components/media-editor/index.tsx
2
1
  import clsx from "clsx";
3
- import {
4
- Button,
5
- DropdownMenu,
6
- MenuGroup,
7
- MenuItem,
8
- Spinner,
9
- __experimentalConfirmDialog as ConfirmDialog
10
- } from "@wordpress/components";
2
+ import { Button, DropdownMenu, MenuGroup, MenuItem, Spinner, __experimentalConfirmDialog, __unstableAnimatePresence, __unstableMotion } from "@wordpress/components";
11
3
  import { Stack, Tabs, VisuallyHidden } from "@wordpress/ui";
12
- import { useViewportMatch } from "@wordpress/compose";
4
+ import { useReducedMotion, useViewportMatch } from "@wordpress/compose";
13
5
  import { useDispatch, useSelect } from "@wordpress/data";
14
- import { store as coreStore } from "@wordpress/core-data";
6
+ import { store } from "@wordpress/core-data";
15
7
  import { NavigableRegion } from "@wordpress/admin-ui";
16
- import {
17
- createContext,
18
- createPortal,
19
- useCallback,
20
- useContext,
21
- useEffect,
22
- useRef,
23
- useState
24
- } from "@wordpress/element";
8
+ import { createContext, createPortal, useCallback, useContext, useEffect, useRef, useState } from "@wordpress/element";
25
9
  import { __ } from "@wordpress/i18n";
26
- import {
27
- backup,
28
- close,
29
- drawerRight,
30
- keyboard,
31
- moreVertical,
32
- redo,
33
- undo
34
- } from "@wordpress/icons";
35
- import {
36
- displayShortcut,
37
- isAppleOS,
38
- isKeyboardEvent
39
- } from "@wordpress/keycodes";
40
- import { SnackbarNotices, store as noticesStore } from "@wordpress/notices";
10
+ import { backup, close, drawerRight, keyboard, moreVertical, redo, undo } from "@wordpress/icons";
11
+ import { displayShortcut, isAppleOS, isKeyboardEvent } from "@wordpress/keycodes";
12
+ import { SnackbarNotices, store as store$1 } from "@wordpress/notices";
41
13
  import { MediaEditorProvider } from "../media-editor-provider/index.mjs";
42
14
  import MediaPreview from "../media-preview/index.mjs";
43
15
  import MediaEditorCanvas from "../media-editor-canvas/index.mjs";
@@ -49,667 +21,503 @@ import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
49
21
  import { MediaEditorStateProvider, useMediaEditor } from "../../state/index.mjs";
50
22
  import { CROP_CONTROL_ATTR } from "../../hooks/use-crop-gesture-handlers.mjs";
51
23
  import MediaEditorKeyboardShortcutsModal from "../media-editor-keyboard-shortcuts-modal/index.mjs";
52
- import {
53
- MEDIA_EDITOR_NOTICES_CONTEXT,
54
- useSaveMediaEditor
55
- } from "./use-save-media-editor.mjs";
24
+ import { MEDIA_EDITOR_NOTICES_CONTEXT, useSaveMediaEditor } from "./use-save-media-editor.mjs";
56
25
  import { useCropOptions } from "./use-crop-options.mjs";
57
26
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
58
- var ATTACHMENT_EMBED_QUERY = { _embed: "author,wp:attached-to" };
59
- var PLACEMENT_CONTROL_IDLE_MS = 300;
60
- var DETAILS_PANEL = "details";
61
- var CROP_PANEL = "crop";
62
- function MediaEditorSidebar({
63
- tabs,
64
- activeTab,
65
- onSelectTab,
66
- disabled = false
67
- }) {
68
- return /* @__PURE__ */ jsxs(
69
- NavigableRegion,
70
- {
71
- className: "media-editor__sidebar",
72
- ariaLabel: __("Media settings"),
73
- children: [
74
- /* @__PURE__ */ jsx(VisuallyHidden, { render: /* @__PURE__ */ jsx("h2", {}), children: __("Media settings") }),
75
- /* @__PURE__ */ jsxs(
76
- Tabs.Root,
77
- {
78
- className: "media-editor__tabs",
79
- value: activeTab,
80
- onValueChange: onSelectTab,
81
- children: [
82
- /* @__PURE__ */ jsx("div", { className: "media-editor__tablist", children: /* @__PURE__ */ jsx(Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ jsx(
83
- Tabs.Tab,
84
- {
85
- value: tab.id,
86
- disabled,
87
- children: tab.title
88
- },
89
- tab.id
90
- )) }) }),
91
- tabs.map((tab) => /* @__PURE__ */ jsx(
92
- Tabs.Panel,
93
- {
94
- value: tab.id,
95
- tabIndex: -1,
96
- className: "media-editor__panel",
97
- children: /* @__PURE__ */ jsx(Stack, { direction: "column", gap: "lg", children: tab.render() })
98
- },
99
- tab.id
100
- ))
101
- ]
102
- }
103
- )
104
- ]
105
- }
106
- );
27
+ // packages/media-editor/src/components/media-editor/index.tsx
28
+ const ATTACHMENT_EMBED_QUERY = { _embed: "author,wp:attached-to" };
29
+ const PLACEMENT_CONTROL_IDLE_MS = 300;
30
+ /**
31
+ * Identifier for the details panel, and the panel the sidebar opens on before
32
+ * the user picks another. The sidebar tracks which panel is open rather than
33
+ * whether one is, so a further panel is a new id here and a new entry in the
34
+ * tab list — not a change to the state's shape.
35
+ */
36
+ const DETAILS_PANEL = "details";
37
+ /** Identifier for the crop panel. Images only; other media has nothing to crop. */
38
+ const CROP_PANEL = "crop";
39
+ const SIDEBAR_ANIMATION_DURATION = .3;
40
+ const sidebarVariants = {
41
+ open: { width: "auto" },
42
+ closed: (transition) => ({
43
+ width: 0,
44
+ transition
45
+ })
46
+ };
47
+ function MediaEditorSidebar({ tabs, activeTab, onSelectTab, disabled = false }) {
48
+ return /* @__PURE__ */ jsxs(NavigableRegion, {
49
+ className: "media-editor__sidebar",
50
+ ariaLabel: __("Media settings"),
51
+ children: [/* @__PURE__ */ jsx(VisuallyHidden, {
52
+ render: /* @__PURE__ */ jsx("h2", {}),
53
+ children: __("Media settings")
54
+ }), /* @__PURE__ */ jsxs(Tabs.Root, {
55
+ className: "media-editor__tabs",
56
+ value: activeTab,
57
+ onValueChange: onSelectTab,
58
+ children: [/* @__PURE__ */ jsx("div", {
59
+ className: "media-editor__tablist",
60
+ children: /* @__PURE__ */ jsx(Tabs.List, {
61
+ variant: "minimal",
62
+ children: tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Tab, {
63
+ value: tab.id,
64
+ disabled,
65
+ children: tab.title
66
+ }, tab.id))
67
+ })
68
+ }), tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Panel, {
69
+ value: tab.id,
70
+ tabIndex: -1,
71
+ className: "media-editor__panel",
72
+ children: /* @__PURE__ */ jsx(Stack, {
73
+ direction: "column",
74
+ gap: "lg",
75
+ children: tab.render()
76
+ })
77
+ }, tab.id))]
78
+ })]
79
+ });
107
80
  }
108
- var MediaEditorFrameContext = createContext(null);
81
+ const MediaEditorFrameContext = createContext(null);
82
+ /**
83
+ * Hook to access the media editor's frame context.
84
+ *
85
+ * Must be used within a MediaEditor component.
86
+ *
87
+ * @return MediaEditorFrameContextValue the action clusters render from.
88
+ */
109
89
  function useMediaEditorFrameContext() {
110
- const context = useContext(MediaEditorFrameContext);
111
- if (!context) {
112
- throw new Error(
113
- "useMediaEditorFrameContext must be used within MediaEditor"
114
- );
115
- }
116
- return context;
90
+ const context = useContext(MediaEditorFrameContext);
91
+ if (!context) throw new Error("useMediaEditorFrameContext must be used within MediaEditor");
92
+ return context;
93
+ }
94
+ function PanelToggle() {
95
+ const { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();
96
+ const isPanelOpen = !!activePanel;
97
+ return /* @__PURE__ */ jsx(Button, {
98
+ size: "compact",
99
+ icon: drawerRight,
100
+ label: __("Media settings"),
101
+ isPressed: isPanelOpen,
102
+ "aria-expanded": isWide ? isPanelOpen : void 0,
103
+ onClick: onTogglePanel
104
+ });
105
+ }
106
+ function MoreMenu() {
107
+ const { isImage } = useMediaEditorFrameContext();
108
+ const [isShortcutsModalOpen, setIsShortcutsModalOpen] = useState(false);
109
+ if (!isImage) return null;
110
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(DropdownMenu, {
111
+ icon: moreVertical,
112
+ label: __("More options"),
113
+ toggleProps: { size: "compact" },
114
+ children: ({ onClose: closeMenu }) => /* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(MenuItem, {
115
+ icon: keyboard,
116
+ iconPosition: "left",
117
+ onClick: () => {
118
+ setIsShortcutsModalOpen(true);
119
+ closeMenu();
120
+ },
121
+ children: __("Keyboard shortcuts")
122
+ }) })
123
+ }), isShortcutsModalOpen && /* @__PURE__ */ jsx(MediaEditorKeyboardShortcutsModal, { onClose: () => setIsShortcutsModalOpen(false) })] });
117
124
  }
118
125
  function HeaderActions({ showCloseButton = false }) {
119
- const {
120
- isImage,
121
- isSaving,
122
- onCancel,
123
- isWide,
124
- activePanel,
125
- onTogglePanel,
126
- canRestoreOriginal,
127
- isSourceReplaced,
128
- onRestoreOriginal
129
- } = useMediaEditorFrameContext();
130
- const isPanelOpen = !!activePanel;
131
- const [isShortcutsModalOpen, setIsShortcutsModalOpen] = useState(false);
132
- return /* @__PURE__ */ jsxs(
133
- Stack,
134
- {
135
- className: "media-editor__header-actions",
136
- justify: "flex-end",
137
- align: "center",
138
- gap: "sm",
139
- children: [
140
- /* @__PURE__ */ jsx(
141
- Button,
142
- {
143
- size: "compact",
144
- icon: drawerRight,
145
- label: __("Media settings"),
146
- isPressed: isPanelOpen,
147
- "aria-expanded": isWide ? isPanelOpen : void 0,
148
- onClick: onTogglePanel
149
- }
150
- ),
151
- isImage && /* @__PURE__ */ jsx(
152
- DropdownMenu,
153
- {
154
- icon: moreVertical,
155
- label: __("More options"),
156
- toggleProps: { size: "compact" },
157
- children: ({ onClose: closeMenu }) => /* @__PURE__ */ jsxs(Fragment, { children: [
158
- canRestoreOriginal && /* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(
159
- MenuItem,
160
- {
161
- icon: backup,
162
- iconPosition: "left",
163
- disabled: isSourceReplaced || isSaving,
164
- info: __(
165
- "Discards unsaved changes and loads the original image."
166
- ),
167
- onClick: () => {
168
- onRestoreOriginal();
169
- closeMenu();
170
- },
171
- children: __("Restore original image")
172
- }
173
- ) }),
174
- /* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(
175
- MenuItem,
176
- {
177
- icon: keyboard,
178
- iconPosition: "left",
179
- onClick: () => {
180
- setIsShortcutsModalOpen(true);
181
- closeMenu();
182
- },
183
- children: __("Keyboard shortcuts")
184
- }
185
- ) })
186
- ] })
187
- }
188
- ),
189
- showCloseButton && /* @__PURE__ */ jsx(
190
- Button,
191
- {
192
- size: "compact",
193
- icon: close,
194
- label: __("Close"),
195
- onClick: onCancel,
196
- disabled: isSaving,
197
- accessibleWhenDisabled: true
198
- }
199
- ),
200
- isShortcutsModalOpen && /* @__PURE__ */ jsx(
201
- MediaEditorKeyboardShortcutsModal,
202
- {
203
- onClose: () => setIsShortcutsModalOpen(false)
204
- }
205
- )
206
- ]
207
- }
208
- );
126
+ const { isSaving, onCancel } = useMediaEditorFrameContext();
127
+ return /* @__PURE__ */ jsxs(Stack, {
128
+ className: "media-editor__header-actions",
129
+ justify: "flex-end",
130
+ align: "center",
131
+ gap: "sm",
132
+ children: [
133
+ /* @__PURE__ */ jsx(PanelToggle, {}),
134
+ /* @__PURE__ */ jsx(MoreMenu, {}),
135
+ showCloseButton && /* @__PURE__ */ jsx(Button, {
136
+ size: "compact",
137
+ icon: close,
138
+ label: __("Close"),
139
+ onClick: onCancel,
140
+ disabled: isSaving,
141
+ accessibleWhenDisabled: true
142
+ })
143
+ ]
144
+ });
209
145
  }
210
146
  function HistoryActions() {
211
- const { isImage, isUndoRedoDisabled, onReset, isWide, activePanel } = useMediaEditorFrameContext();
212
- const {
213
- cropper: { reset },
214
- isDirty,
215
- hasUndo,
216
- hasRedo,
217
- undo: undoCrop,
218
- redo: redoCrop,
219
- beginGesture,
220
- endGesture
221
- } = useMediaEditor();
222
- if (!isImage || !isWide && !!activePanel) {
223
- return null;
224
- }
225
- const handleUndo = () => {
226
- if (isUndoRedoDisabled) {
227
- return;
228
- }
229
- undoCrop();
230
- };
231
- const handleRedo = () => {
232
- if (isUndoRedoDisabled) {
233
- return;
234
- }
235
- redoCrop();
236
- };
237
- const handleReset = () => {
238
- if (isUndoRedoDisabled) {
239
- return;
240
- }
241
- beginGesture();
242
- reset();
243
- onReset();
244
- endGesture();
245
- };
246
- return /* @__PURE__ */ jsxs(
247
- Stack,
248
- {
249
- className: "media-editor__history-actions",
250
- align: "center",
251
- gap: "sm",
252
- children: [
253
- /* @__PURE__ */ jsx(
254
- Button,
255
- {
256
- size: "compact",
257
- variant: "tertiary",
258
- disabled: isUndoRedoDisabled || !isDirty,
259
- accessibleWhenDisabled: true,
260
- onClick: handleReset,
261
- children: __("Reset")
262
- }
263
- ),
264
- /* @__PURE__ */ jsx(
265
- Button,
266
- {
267
- size: "compact",
268
- icon: undo,
269
- label: __("Undo"),
270
- showTooltip: true,
271
- shortcut: displayShortcut.primary("z"),
272
- disabled: isUndoRedoDisabled || !hasUndo,
273
- accessibleWhenDisabled: true,
274
- onClick: handleUndo
275
- }
276
- ),
277
- /* @__PURE__ */ jsx(
278
- Button,
279
- {
280
- size: "compact",
281
- icon: redo,
282
- label: __("Redo"),
283
- showTooltip: true,
284
- shortcut: isAppleOS() ? displayShortcut.primaryShift("z") : displayShortcut.primary("y"),
285
- disabled: isUndoRedoDisabled || !hasRedo,
286
- accessibleWhenDisabled: true,
287
- onClick: handleRedo
288
- }
289
- )
290
- ]
291
- }
292
- );
147
+ const { isImage, isSaving, isUndoRedoDisabled, isWide, activePanel, canRestoreOriginal, isSourceReplaced, onRestoreOriginal } = useMediaEditorFrameContext();
148
+ const { reset, isDirty, hasUndo, hasRedo, undo: undoCrop, redo: redoCrop } = useMediaEditor();
149
+ if (!isImage || !isWide && !!activePanel) return null;
150
+ const handleUndo = () => {
151
+ if (isUndoRedoDisabled) return;
152
+ undoCrop();
153
+ };
154
+ const handleRedo = () => {
155
+ if (isUndoRedoDisabled) return;
156
+ redoCrop();
157
+ };
158
+ const handleReset = () => {
159
+ if (isUndoRedoDisabled) return;
160
+ reset();
161
+ };
162
+ return /* @__PURE__ */ jsxs(Stack, {
163
+ className: "media-editor__history-actions",
164
+ align: "center",
165
+ gap: "sm",
166
+ children: [
167
+ /* @__PURE__ */ jsx(Button, {
168
+ size: "compact",
169
+ icon: undo,
170
+ label: __("Undo"),
171
+ showTooltip: true,
172
+ shortcut: displayShortcut.primary("z"),
173
+ disabled: isUndoRedoDisabled || !hasUndo,
174
+ accessibleWhenDisabled: true,
175
+ onClick: handleUndo
176
+ }),
177
+ /* @__PURE__ */ jsx(Button, {
178
+ size: "compact",
179
+ icon: redo,
180
+ label: __("Redo"),
181
+ showTooltip: true,
182
+ shortcut: isAppleOS() ? displayShortcut.primaryShift("z") : displayShortcut.primary("y"),
183
+ disabled: isUndoRedoDisabled || !hasRedo,
184
+ accessibleWhenDisabled: true,
185
+ onClick: handleRedo
186
+ }),
187
+ /* @__PURE__ */ jsx(DropdownMenu, {
188
+ icon: backup,
189
+ label: __("History"),
190
+ popoverProps: { placement: "top-start" },
191
+ toggleProps: {
192
+ size: "compact",
193
+ disabled: isUndoRedoDisabled || !isDirty && !canRestoreOriginal,
194
+ accessibleWhenDisabled: true
195
+ },
196
+ children: ({ onClose: closeMenu }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(MenuItem, {
197
+ disabled: isUndoRedoDisabled || !isDirty,
198
+ onClick: () => {
199
+ handleReset();
200
+ closeMenu();
201
+ },
202
+ children: __("Reset image edits")
203
+ }) }), canRestoreOriginal && /* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(MenuItem, {
204
+ disabled: isSourceReplaced || isSaving,
205
+ info: __("Discards unsaved changes."),
206
+ onClick: () => {
207
+ onRestoreOriginal();
208
+ closeMenu();
209
+ },
210
+ children: __("Restore original")
211
+ }) })] })
212
+ })
213
+ ]
214
+ });
293
215
  }
294
216
  function SaveActions({ size = "default" }) {
295
- const { isSaving, hasMedia, hasChanges, onCancel, onSave } = useMediaEditorFrameContext();
296
- const saveDisabled = isSaving || !hasMedia || !hasChanges;
297
- return /* @__PURE__ */ jsxs(
298
- Stack,
299
- {
300
- className: "media-editor__save-actions",
301
- justify: "flex-end",
302
- align: "center",
303
- gap: "sm",
304
- children: [
305
- /* @__PURE__ */ jsx(
306
- Button,
307
- {
308
- __next40pxDefaultSize: true,
309
- size,
310
- variant: "tertiary",
311
- onClick: onCancel,
312
- disabled: isSaving,
313
- accessibleWhenDisabled: true,
314
- children: __("Cancel")
315
- }
316
- ),
317
- /* @__PURE__ */ jsx(
318
- Button,
319
- {
320
- __next40pxDefaultSize: true,
321
- size,
322
- variant: "primary",
323
- onClick: onSave,
324
- isBusy: isSaving,
325
- disabled: saveDisabled,
326
- accessibleWhenDisabled: true,
327
- children: __("Save")
328
- }
329
- )
330
- ]
331
- }
332
- );
217
+ const { isSaving, hasMedia, hasChanges, onCancel, onSave } = useMediaEditorFrameContext();
218
+ const saveDisabled = isSaving || !hasMedia || !hasChanges;
219
+ return /* @__PURE__ */ jsxs(Stack, {
220
+ className: "media-editor__save-actions",
221
+ justify: "flex-end",
222
+ align: "center",
223
+ gap: "sm",
224
+ children: [/* @__PURE__ */ jsx(Button, {
225
+ __next40pxDefaultSize: true,
226
+ size,
227
+ variant: "tertiary",
228
+ onClick: onCancel,
229
+ disabled: isSaving,
230
+ accessibleWhenDisabled: true,
231
+ children: __("Cancel")
232
+ }), /* @__PURE__ */ jsx(Button, {
233
+ __next40pxDefaultSize: true,
234
+ size,
235
+ variant: "primary",
236
+ onClick: onSave,
237
+ isBusy: isSaving,
238
+ disabled: saveDisabled,
239
+ accessibleWhenDisabled: true,
240
+ children: __("Save")
241
+ })]
242
+ });
333
243
  }
334
- function MediaEditorContent({
335
- fields = [],
336
- id,
337
- aspectRatioPresets,
338
- onClose,
339
- onSaved,
340
- renderFrame,
341
- noticesClassName = "media-editor__snackbar",
342
- noticesPortalElement,
343
- shouldCloseOnEsc = false
344
- }) {
345
- const session = useMediaEditor();
346
- const isWide = useViewportMatch("small");
347
- const [activePanel, setActivePanel] = useState(
348
- isWide ? DETAILS_PANEL : null
349
- );
350
- const hasChosenPanelRef = useRef(false);
351
- const lastPanelRef = useRef(DETAILS_PANEL);
352
- const hasChosenTabRef = useRef(false);
353
- const selectPanel = useCallback((panel) => {
354
- hasChosenTabRef.current = true;
355
- lastPanelRef.current = panel;
356
- setActivePanel(panel);
357
- }, []);
358
- const togglePanel = useCallback(() => {
359
- hasChosenPanelRef.current = true;
360
- setActivePanel((open) => open ? null : lastPanelRef.current);
361
- }, []);
362
- const layout = isWide ? "wide" : "narrow";
363
- const sourceMedia = useSelect(
364
- (select) => select(coreStore).getEntityRecord(
365
- "postType",
366
- "attachment",
367
- id
368
- ),
369
- [id]
370
- );
371
- const { clearEntityRecordEdits, editEntityRecord, invalidateResolution } = useDispatch(coreStore);
372
- const { removeAllNotices } = useDispatch(noticesStore);
373
- const [isDiscardDialogOpen, setIsDiscardDialogOpen] = useState(false);
374
- const [isPlacementActive, setIsPlacementActive] = useState(false);
375
- const [isCanvasGestureActive, setIsCanvasGestureActive] = useState(false);
376
- const [isSourceReplaced, setIsSourceReplaced] = useState(false);
377
- const placementControlTimerRef = useRef(void 0);
378
- const signalPlacementControlInteraction = useCallback(() => {
379
- setIsPlacementActive(true);
380
- clearTimeout(placementControlTimerRef.current);
381
- placementControlTimerRef.current = setTimeout(() => {
382
- setIsPlacementActive(false);
383
- }, PLACEMENT_CONTROL_IDLE_MS);
384
- }, []);
385
- const handleCanvasGestureStart = useCallback(() => {
386
- setIsCanvasGestureActive(true);
387
- }, []);
388
- const handleCanvasGestureEnd = useCallback(() => {
389
- setIsCanvasGestureActive(false);
390
- }, []);
391
- const isCropInteractionActive = isPlacementActive || isCanvasGestureActive;
392
- useEffect(() => {
393
- return () => {
394
- clearTimeout(placementControlTimerRef.current);
395
- };
396
- }, []);
397
- useEffect(() => {
398
- setIsPlacementActive(false);
399
- setIsCanvasGestureActive(false);
400
- setIsSourceReplaced(false);
401
- }, [id]);
402
- const originalId = sourceMedia?.edit_root;
403
- const originalRecord = useSelect(
404
- (select) => originalId ? select(coreStore).getEntityRecord(
405
- "postType",
406
- "attachment",
407
- originalId
408
- ) : void 0,
409
- [originalId]
410
- );
411
- const originalWidth = Number(originalRecord?.media_details?.width);
412
- const originalHeight = Number(originalRecord?.media_details?.height);
413
- const originalUrl = originalRecord?.source_url;
414
- const originalSource = originalId && originalRecord && typeof originalUrl === "string" && originalUrl.length > 0 && Number.isFinite(originalWidth) && originalWidth > 0 && Number.isFinite(originalHeight) && originalHeight > 0 ? {
415
- id: originalId,
416
- url: originalUrl,
417
- media: originalRecord
418
- } : void 0;
419
- const canRestoreOriginal = !!originalSource;
420
- const replacementSource = isSourceReplaced && originalSource ? {
421
- id: originalSource.id,
422
- url: originalSource.url,
423
- media: originalSource.media
424
- } : void 0;
425
- const activeId = replacementSource?.id ?? id;
426
- const { media, hasEdits } = useSelect(
427
- (select) => {
428
- const {
429
- getEditedEntityRecord,
430
- getEntityRecord,
431
- hasEditsForEntityRecord
432
- } = select(coreStore);
433
- getEntityRecord(
434
- "postType",
435
- "attachment",
436
- activeId,
437
- ATTACHMENT_EMBED_QUERY
438
- );
439
- return {
440
- media: getEditedEntityRecord(
441
- "postType",
442
- "attachment",
443
- activeId
444
- ),
445
- hasEdits: hasEditsForEntityRecord(
446
- "postType",
447
- "attachment",
448
- activeId
449
- )
450
- };
451
- },
452
- [activeId]
453
- );
454
- useEffect(() => {
455
- invalidateResolution("getEntityRecord", [
456
- "postType",
457
- "attachment",
458
- activeId,
459
- ATTACHMENT_EMBED_QUERY
460
- ]);
461
- }, [activeId, invalidateResolution]);
462
- const handleRestoreOriginal = useCallback(() => {
463
- clearEntityRecordEdits("postType", "attachment", id);
464
- setIsSourceReplaced(true);
465
- }, [clearEntityRecordEdits, id]);
466
- const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
467
- const mediaType = getMediaTypeFromMimeType(media?.mime_type).type;
468
- const isImage = !!media && mediaType === "image";
469
- useEffect(() => {
470
- if (hasChosenPanelRef.current && hasChosenTabRef.current) {
471
- return;
472
- }
473
- const defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;
474
- if (!hasChosenTabRef.current) {
475
- lastPanelRef.current = defaultPanel;
476
- }
477
- if (!hasChosenPanelRef.current) {
478
- setActivePanel(isWide ? lastPanelRef.current : null);
479
- }
480
- }, [isWide, isImage]);
481
- const {
482
- aspectRatioValue,
483
- setAspectRatioValue,
484
- aspectRatioOptions,
485
- resetCropOptions
486
- } = useCropOptions({ aspectRatioPresets });
487
- const { isSaving, save: saveMediaEditor } = useSaveMediaEditor({
488
- session,
489
- id,
490
- isImage,
491
- media: sourceMedia,
492
- onSaved,
493
- replacementSource
494
- });
495
- const handleChange = (updates) => {
496
- if (isSaving) {
497
- return;
498
- }
499
- editEntityRecord("postType", "attachment", activeId, updates);
500
- };
501
- const discardAndClose = () => {
502
- removeAllNotices("snackbar", MEDIA_EDITOR_NOTICES_CONTEXT);
503
- clearEntityRecordEdits("postType", "attachment", activeId);
504
- setIsSourceReplaced(false);
505
- onClose?.();
506
- };
507
- const handleRequestClose = () => {
508
- if (isSaving) {
509
- return;
510
- }
511
- if (hasChanges) {
512
- setIsDiscardDialogOpen(true);
513
- return;
514
- }
515
- discardAndClose();
516
- };
517
- const handleKeyDown = (event) => {
518
- const isUndoShortcut = isKeyboardEvent.primary(event, "z");
519
- const isRedoShortcut = isKeyboardEvent.primaryShift(event, "z") || !isAppleOS() && isKeyboardEvent.primary(event, "y");
520
- if ((isUndoShortcut || isRedoShortcut) && isImage) {
521
- const target = event.target;
522
- const isMetadataField = (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) && !target.closest(`[${CROP_CONTROL_ATTR}]`);
523
- if (!isMetadataField) {
524
- event.preventDefault();
525
- if (isCropInteractionActive || isSaving) {
526
- return;
527
- }
528
- if (isRedoShortcut) {
529
- session.redo();
530
- } else {
531
- session.undo();
532
- }
533
- }
534
- }
535
- if (shouldCloseOnEsc) {
536
- if (event.code !== "Escape" && event.key !== "Escape") {
537
- return;
538
- }
539
- if (isSaving) {
540
- event.preventDefault();
541
- return;
542
- }
543
- if (hasChanges) {
544
- event.preventDefault();
545
- setIsDiscardDialogOpen(true);
546
- }
547
- }
548
- };
549
- const snackbar = /* @__PURE__ */ jsx(
550
- SnackbarNotices,
551
- {
552
- className: noticesClassName,
553
- context: MEDIA_EDITOR_NOTICES_CONTEXT
554
- }
555
- );
556
- const imageControls = isImage && !isWide ? /* @__PURE__ */ jsx(
557
- MediaEditorImageControls,
558
- {
559
- showAspectRatioControl: true,
560
- aspectRatioPresets,
561
- disabled: isSaving
562
- }
563
- ) : null;
564
- const tabs = [
565
- ...isImage ? [
566
- {
567
- id: CROP_PANEL,
568
- title: __("Crop"),
569
- render: () => /* @__PURE__ */ jsx(
570
- MediaEditorCropPanel,
571
- {
572
- aspectRatioValue,
573
- onAspectRatioChange: setAspectRatioValue,
574
- aspectRatioOptions,
575
- disabled: isSaving
576
- }
577
- )
578
- }
579
- ] : [],
580
- {
581
- id: DETAILS_PANEL,
582
- title: __("Details"),
583
- render: () => /* @__PURE__ */ jsx(MediaForm, {})
584
- }
585
- ];
586
- const ruler = isImage ? /* @__PURE__ */ jsx(
587
- MediaEditorFineRotation,
588
- {
589
- onPlacementControlInteraction: signalPlacementControlInteraction,
590
- disabled: isSaving
591
- }
592
- ) : null;
593
- const children = /* @__PURE__ */ jsxs(
594
- MediaEditorProvider,
595
- {
596
- value: media ?? void 0,
597
- onChange: handleChange,
598
- settings: {
599
- // Disable the fields while saving, so the guard in
600
- // `handleChange` is not silently swallowing typing.
601
- // `readOnly` would swap the field's layout mid-save;
602
- // disabled keeps it in place and greys it out.
603
- fields: isSaving ? fields.map((field) => ({
604
- ...field,
605
- isDisabled: true
606
- })) : fields
607
- },
608
- children: [
609
- /* @__PURE__ */ jsx("div", { className: "media-editor", children: !media ? /* @__PURE__ */ jsx("div", { className: "media-editor__loading", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(
610
- "div",
611
- {
612
- className: clsx("media-editor__body", {
613
- "has-panel-open": !!activePanel
614
- }),
615
- children: [
616
- /* @__PURE__ */ jsxs(
617
- NavigableRegion,
618
- {
619
- className: "media-editor__content",
620
- ariaLabel: isImage ? __("Image editor") : __("Media preview"),
621
- children: [
622
- /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-area", children: isImage ? /* @__PURE__ */ jsx(
623
- MediaEditorCanvas,
624
- {
625
- isPlacementActive,
626
- onGestureStart: handleCanvasGestureStart,
627
- onGestureEnd: handleCanvasGestureEnd,
628
- disabled: isSaving
629
- }
630
- ) : /* @__PURE__ */ jsx(MediaPreview, {}) }),
631
- isImage && /* @__PURE__ */ jsxs("div", { className: "media-editor__canvas-toolbar", children: [
632
- ruler,
633
- imageControls
634
- ] })
635
- ]
636
- }
637
- ),
638
- !!activePanel && /* @__PURE__ */ jsx(
639
- MediaEditorSidebar,
640
- {
641
- tabs,
642
- activeTab: tabs.some(
643
- (tab) => tab.id === activePanel
644
- ) ? activePanel : DETAILS_PANEL,
645
- onSelectTab: selectPanel,
646
- disabled: isSaving
647
- }
648
- )
649
- ]
650
- }
651
- ) }),
652
- /* @__PURE__ */ jsx(
653
- ConfirmDialog,
654
- {
655
- isOpen: isDiscardDialogOpen,
656
- confirmButtonText: __("Discard"),
657
- cancelButtonText: __("Keep editing"),
658
- onCancel: () => setIsDiscardDialogOpen(false),
659
- onConfirm: () => {
660
- setIsDiscardDialogOpen(false);
661
- discardAndClose();
662
- },
663
- children: __(
664
- "Are you sure you want to discard your unsaved changes?"
665
- )
666
- }
667
- ),
668
- noticesPortalElement ? createPortal(snackbar, noticesPortalElement) : snackbar
669
- ]
670
- }
671
- );
672
- const contextValue = {
673
- isImage,
674
- isSaving,
675
- hasMedia: !!media,
676
- hasChanges,
677
- // Saving freezes the whole edit surface: `save()` reads the
678
- // modifiers once and then awaits, so anything changed after that
679
- // would be silently dropped when the save resolves.
680
- isUndoRedoDisabled: isCropInteractionActive || isSaving,
681
- aspectRatioPresets,
682
- isWide,
683
- activePanel,
684
- onTogglePanel: togglePanel,
685
- onCancel: handleRequestClose,
686
- onSave: saveMediaEditor,
687
- onReset: resetCropOptions,
688
- canRestoreOriginal,
689
- isSourceReplaced,
690
- onRestoreOriginal: handleRestoreOriginal
691
- };
692
- return /* @__PURE__ */ jsx(MediaEditorFrameContext.Provider, { value: contextValue, children: renderFrame({
693
- children,
694
- isImage,
695
- layout,
696
- onRequestClose: handleRequestClose,
697
- onKeyDown: handleKeyDown,
698
- shouldCloseOnClickOutside: !hasChanges && !isSaving,
699
- isSaving,
700
- hasChanges,
701
- hasMedia: !!media
702
- }) });
244
+ function MediaEditorContent({ fields = [], form, id, aspectRatioPresets, onClose, onSaved, renderFrame, noticesClassName = "media-editor__snackbar", noticesPortalElement, shouldCloseOnEsc = false }) {
245
+ const session = useMediaEditor();
246
+ const isWide = useViewportMatch("small");
247
+ const sidebarTransition = {
248
+ type: "tween",
249
+ duration: useReducedMotion() || !isWide ? 0 : SIDEBAR_ANIMATION_DURATION,
250
+ ease: [
251
+ .6,
252
+ 0,
253
+ .4,
254
+ 1
255
+ ]
256
+ };
257
+ const [chosenPanel, setChosenPanel] = useState();
258
+ const [chosenTab, setChosenTab] = useState(null);
259
+ const layout = isWide ? "wide" : "narrow";
260
+ const sourceMedia = useSelect((select) => select(store).getEntityRecord("postType", "attachment", id), [id]);
261
+ const { clearEntityRecordEdits, editEntityRecord, invalidateResolution } = useDispatch(store);
262
+ const { removeAllNotices } = useDispatch(store$1);
263
+ const [isDiscardDialogOpen, setIsDiscardDialogOpen] = useState(false);
264
+ const [isPlacementActive, setIsPlacementActive] = useState(false);
265
+ const [isCanvasGestureActive, setIsCanvasGestureActive] = useState(false);
266
+ const [isSourceReplaced, setIsSourceReplaced] = useState(false);
267
+ const placementControlTimerRef = useRef(void 0);
268
+ const signalPlacementControlInteraction = useCallback(() => {
269
+ setIsPlacementActive(true);
270
+ clearTimeout(placementControlTimerRef.current);
271
+ placementControlTimerRef.current = setTimeout(() => {
272
+ setIsPlacementActive(false);
273
+ }, PLACEMENT_CONTROL_IDLE_MS);
274
+ }, []);
275
+ const handleCanvasGestureStart = useCallback(() => {
276
+ setIsCanvasGestureActive(true);
277
+ }, []);
278
+ const handleCanvasGestureEnd = useCallback(() => {
279
+ setIsCanvasGestureActive(false);
280
+ }, []);
281
+ const isCropInteractionActive = isPlacementActive || isCanvasGestureActive;
282
+ useEffect(() => {
283
+ return () => {
284
+ clearTimeout(placementControlTimerRef.current);
285
+ };
286
+ }, []);
287
+ const originalId = sourceMedia?.edit_root;
288
+ const originalRecord = useSelect((select) => originalId ? select(store).getEntityRecord("postType", "attachment", originalId) : void 0, [originalId]);
289
+ const originalWidth = Number(originalRecord?.media_details?.width);
290
+ const originalHeight = Number(originalRecord?.media_details?.height);
291
+ const originalUrl = originalRecord?.source_url;
292
+ const originalSource = originalId && originalRecord && typeof originalUrl === "string" && originalUrl.length > 0 && Number.isFinite(originalWidth) && originalWidth > 0 && Number.isFinite(originalHeight) && originalHeight > 0 ? {
293
+ id: originalId,
294
+ url: originalUrl,
295
+ media: originalRecord
296
+ } : void 0;
297
+ const canRestoreOriginal = !!originalSource;
298
+ const replacementSource = isSourceReplaced && originalSource ? {
299
+ id: originalSource.id,
300
+ url: originalSource.url,
301
+ media: originalSource.media
302
+ } : void 0;
303
+ const activeId = replacementSource?.id ?? id;
304
+ const { media, hasEdits } = useSelect((select) => {
305
+ const { getEditedEntityRecord, getEntityRecord, hasEditsForEntityRecord } = select(store);
306
+ getEntityRecord("postType", "attachment", activeId, ATTACHMENT_EMBED_QUERY);
307
+ return {
308
+ media: getEditedEntityRecord("postType", "attachment", activeId),
309
+ hasEdits: hasEditsForEntityRecord("postType", "attachment", activeId)
310
+ };
311
+ }, [activeId]);
312
+ useEffect(() => {
313
+ invalidateResolution("getEntityRecord", [
314
+ "postType",
315
+ "attachment",
316
+ activeId,
317
+ ATTACHMENT_EMBED_QUERY
318
+ ]);
319
+ }, [activeId, invalidateResolution]);
320
+ const handleRestoreOriginal = useCallback(() => {
321
+ clearEntityRecordEdits("postType", "attachment", id);
322
+ setIsSourceReplaced(true);
323
+ }, [clearEntityRecordEdits, id]);
324
+ const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
325
+ const mediaType = getMediaTypeFromMimeType(media?.mime_type).type;
326
+ const isImage = !!media && mediaType === "image";
327
+ const currentTab = chosenTab ?? (isWide && isImage ? CROP_PANEL : DETAILS_PANEL);
328
+ let activePanel = chosenPanel;
329
+ if (activePanel === void 0) activePanel = isWide ? currentTab : null;
330
+ const selectPanel = useCallback((panel) => {
331
+ setChosenTab(panel);
332
+ setChosenPanel((chosen) => chosen === void 0 ? chosen : panel);
333
+ }, []);
334
+ const togglePanel = useCallback(() => {
335
+ setChosenPanel(activePanel ? null : currentTab);
336
+ }, [activePanel, currentTab]);
337
+ const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } = useCropOptions({ aspectRatioPresets });
338
+ const { isSaving, save: saveMediaEditor } = useSaveMediaEditor({
339
+ session,
340
+ id,
341
+ isImage,
342
+ media: sourceMedia,
343
+ onSaved,
344
+ replacementSource
345
+ });
346
+ const handleChange = (updates) => {
347
+ if (isSaving) return;
348
+ editEntityRecord("postType", "attachment", activeId, updates);
349
+ };
350
+ const discardAndClose = () => {
351
+ removeAllNotices("snackbar", MEDIA_EDITOR_NOTICES_CONTEXT);
352
+ clearEntityRecordEdits("postType", "attachment", activeId);
353
+ setIsSourceReplaced(false);
354
+ onClose?.();
355
+ };
356
+ const handleRequestClose = () => {
357
+ if (isSaving) return;
358
+ if (hasChanges) {
359
+ setIsDiscardDialogOpen(true);
360
+ return;
361
+ }
362
+ discardAndClose();
363
+ };
364
+ const handleKeyDown = (event) => {
365
+ const isUndoShortcut = isKeyboardEvent.primary(event, "z");
366
+ const isRedoShortcut = isKeyboardEvent.primaryShift(event, "z") || !isAppleOS() && isKeyboardEvent.primary(event, "y");
367
+ if ((isUndoShortcut || isRedoShortcut) && isImage) {
368
+ const target = event.target;
369
+ if (!((target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) && !target.closest(`[${CROP_CONTROL_ATTR}]`))) {
370
+ event.preventDefault();
371
+ if (isCropInteractionActive || isSaving) return;
372
+ if (isRedoShortcut) session.redo();
373
+ else session.undo();
374
+ }
375
+ }
376
+ if (shouldCloseOnEsc) {
377
+ if (event.code !== "Escape" && event.key !== "Escape") return;
378
+ if (isSaving) {
379
+ event.preventDefault();
380
+ return;
381
+ }
382
+ if (hasChanges) {
383
+ event.preventDefault();
384
+ setIsDiscardDialogOpen(true);
385
+ }
386
+ }
387
+ };
388
+ const snackbar = /* @__PURE__ */ jsx(SnackbarNotices, {
389
+ className: noticesClassName,
390
+ context: MEDIA_EDITOR_NOTICES_CONTEXT
391
+ });
392
+ const imageControls = isImage && !isWide ? /* @__PURE__ */ jsx(MediaEditorImageControls, {
393
+ showAspectRatioControl: true,
394
+ aspectRatioPresets,
395
+ disabled: isSaving
396
+ }) : null;
397
+ const tabs = [...isImage ? [{
398
+ id: CROP_PANEL,
399
+ title: __("Crop"),
400
+ render: () => /* @__PURE__ */ jsx(MediaEditorCropPanel, {
401
+ aspectRatioValue,
402
+ onAspectRatioChange: setAspectRatioValue,
403
+ aspectRatioOptions,
404
+ disabled: isSaving
405
+ })
406
+ }] : [], {
407
+ id: DETAILS_PANEL,
408
+ title: __("Details"),
409
+ render: () => /* @__PURE__ */ jsx(MediaForm, {})
410
+ }];
411
+ const ruler = isImage ? /* @__PURE__ */ jsx(MediaEditorFineRotation, {
412
+ onPlacementControlInteraction: signalPlacementControlInteraction,
413
+ disabled: isSaving
414
+ }) : null;
415
+ const children = /* @__PURE__ */ jsxs(MediaEditorProvider, {
416
+ value: media ?? void 0,
417
+ onChange: handleChange,
418
+ settings: {
419
+ fields: isSaving ? fields.map((field) => ({
420
+ ...field,
421
+ isDisabled: true
422
+ })) : fields,
423
+ form
424
+ },
425
+ children: [
426
+ /* @__PURE__ */ jsx("div", {
427
+ className: "media-editor",
428
+ children: !media ? /* @__PURE__ */ jsx("div", {
429
+ className: "media-editor__loading",
430
+ children: /* @__PURE__ */ jsx(Spinner, {})
431
+ }) : /* @__PURE__ */ jsxs("div", {
432
+ className: clsx("media-editor__body", { "has-panel-open": !!activePanel }),
433
+ children: [/* @__PURE__ */ jsxs(NavigableRegion, {
434
+ className: "media-editor__content",
435
+ ariaLabel: isImage ? __("Image editor") : __("Media preview"),
436
+ children: [/* @__PURE__ */ jsx("div", {
437
+ className: "media-editor__canvas-area",
438
+ children: isImage ? /* @__PURE__ */ jsx(MediaEditorCanvas, {
439
+ isPlacementActive,
440
+ onGestureStart: handleCanvasGestureStart,
441
+ onGestureEnd: handleCanvasGestureEnd,
442
+ disabled: isSaving
443
+ }) : /* @__PURE__ */ jsx(MediaPreview, {})
444
+ }), isImage && /* @__PURE__ */ jsxs("div", {
445
+ className: "media-editor__canvas-toolbar",
446
+ children: [ruler, imageControls]
447
+ })]
448
+ }), /* @__PURE__ */ jsx(__unstableAnimatePresence, {
449
+ initial: false,
450
+ custom: sidebarTransition,
451
+ children: !!activePanel && /* @__PURE__ */ jsx(__unstableMotion.div, {
452
+ className: "media-editor__sidebar-container",
453
+ variants: sidebarVariants,
454
+ initial: "closed",
455
+ animate: "open",
456
+ exit: "closed",
457
+ transition: sidebarTransition,
458
+ children: /* @__PURE__ */ jsx(MediaEditorSidebar, {
459
+ tabs,
460
+ activeTab: tabs.some((tab) => tab.id === activePanel) ? activePanel : DETAILS_PANEL,
461
+ onSelectTab: selectPanel,
462
+ disabled: isSaving
463
+ })
464
+ })
465
+ })]
466
+ })
467
+ }),
468
+ /* @__PURE__ */ jsx(__experimentalConfirmDialog, {
469
+ isOpen: isDiscardDialogOpen,
470
+ confirmButtonText: __("Discard"),
471
+ cancelButtonText: __("Keep editing"),
472
+ onCancel: () => setIsDiscardDialogOpen(false),
473
+ onConfirm: () => {
474
+ setIsDiscardDialogOpen(false);
475
+ discardAndClose();
476
+ },
477
+ children: __("Are you sure you want to discard your unsaved changes?")
478
+ }),
479
+ noticesPortalElement ? createPortal(snackbar, noticesPortalElement) : snackbar
480
+ ]
481
+ });
482
+ const contextValue = {
483
+ isImage,
484
+ isSaving,
485
+ hasMedia: !!media,
486
+ hasChanges,
487
+ isUndoRedoDisabled: isCropInteractionActive || isSaving,
488
+ aspectRatioPresets,
489
+ isWide,
490
+ activePanel,
491
+ onTogglePanel: togglePanel,
492
+ onCancel: handleRequestClose,
493
+ onSave: saveMediaEditor,
494
+ canRestoreOriginal,
495
+ isSourceReplaced,
496
+ onRestoreOriginal: handleRestoreOriginal
497
+ };
498
+ return /* @__PURE__ */ jsx(MediaEditorFrameContext.Provider, {
499
+ value: contextValue,
500
+ children: renderFrame({
501
+ children,
502
+ isImage,
503
+ layout,
504
+ onRequestClose: handleRequestClose,
505
+ onKeyDown: handleKeyDown,
506
+ shouldCloseOnClickOutside: !hasChanges && !isSaving,
507
+ isSaving,
508
+ hasChanges,
509
+ hasMedia: !!media
510
+ })
511
+ });
703
512
  }
704
513
  function MediaEditor(props) {
705
- return /* @__PURE__ */ jsx(MediaEditorStateProvider, { children: /* @__PURE__ */ jsx(MediaEditorContent, { ...props }) }, props.id);
514
+ return /* @__PURE__ */ jsx(MediaEditorStateProvider, { children: /* @__PURE__ */ jsx(MediaEditorContent, { ...props }) }, props.id);
706
515
  }
707
516
  MediaEditor.HeaderActions = HeaderActions;
517
+ MediaEditor.PanelToggle = PanelToggle;
518
+ MediaEditor.MoreMenu = MoreMenu;
708
519
  MediaEditor.HistoryActions = HistoryActions;
709
520
  MediaEditor.SaveActions = SaveActions;
710
- var media_editor_default = MediaEditor;
711
- export {
712
- MediaEditor,
713
- media_editor_default as default
714
- };
715
- //# sourceMappingURL=index.mjs.map
521
+ export { MediaEditor, MediaEditor as default };
522
+
523
+ //# sourceMappingURL=index.mjs.map