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