@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,720 +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, onReset, isWide, activePanel } = useMediaEditorFrameContext();
217
- const {
218
- cropper: { reset },
219
- isDirty,
220
- hasUndo,
221
- hasRedo,
222
- undo: undoCrop,
223
- redo: redoCrop,
224
- beginGesture,
225
- endGesture
226
- } = (0, import_state.useMediaEditor)();
227
- if (!isImage || !isWide && !!activePanel) {
228
- return null;
229
- }
230
- const handleUndo = () => {
231
- if (isUndoRedoDisabled) {
232
- return;
233
- }
234
- undoCrop();
235
- };
236
- const handleRedo = () => {
237
- if (isUndoRedoDisabled) {
238
- return;
239
- }
240
- redoCrop();
241
- };
242
- const handleReset = () => {
243
- if (isUndoRedoDisabled) {
244
- return;
245
- }
246
- beginGesture();
247
- reset();
248
- onReset();
249
- endGesture();
250
- };
251
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
252
- import_ui.Stack,
253
- {
254
- className: "media-editor__history-actions",
255
- align: "center",
256
- gap: "sm",
257
- children: [
258
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
259
- import_components.Button,
260
- {
261
- size: "compact",
262
- variant: "tertiary",
263
- disabled: isUndoRedoDisabled || !isDirty,
264
- accessibleWhenDisabled: true,
265
- onClick: handleReset,
266
- children: (0, import_i18n.__)("Reset")
267
- }
268
- ),
269
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
270
- import_components.Button,
271
- {
272
- size: "compact",
273
- icon: import_icons.undo,
274
- label: (0, import_i18n.__)("Undo"),
275
- showTooltip: true,
276
- shortcut: import_keycodes.displayShortcut.primary("z"),
277
- disabled: isUndoRedoDisabled || !hasUndo,
278
- accessibleWhenDisabled: true,
279
- onClick: handleUndo
280
- }
281
- ),
282
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
283
- import_components.Button,
284
- {
285
- size: "compact",
286
- icon: import_icons.redo,
287
- label: (0, import_i18n.__)("Redo"),
288
- showTooltip: true,
289
- shortcut: (0, import_keycodes.isAppleOS)() ? import_keycodes.displayShortcut.primaryShift("z") : import_keycodes.displayShortcut.primary("y"),
290
- disabled: isUndoRedoDisabled || !hasRedo,
291
- accessibleWhenDisabled: true,
292
- onClick: handleRedo
293
- }
294
- )
295
- ]
296
- }
297
- );
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
+ });
298
249
  }
299
250
  function SaveActions({ size = "default" }) {
300
- const { isSaving, hasMedia, hasChanges, onCancel, onSave } = useMediaEditorFrameContext();
301
- const saveDisabled = isSaving || !hasMedia || !hasChanges;
302
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
303
- import_ui.Stack,
304
- {
305
- className: "media-editor__save-actions",
306
- justify: "flex-end",
307
- align: "center",
308
- gap: "sm",
309
- children: [
310
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
311
- import_components.Button,
312
- {
313
- __next40pxDefaultSize: true,
314
- size,
315
- variant: "tertiary",
316
- onClick: onCancel,
317
- disabled: isSaving,
318
- accessibleWhenDisabled: true,
319
- children: (0, import_i18n.__)("Cancel")
320
- }
321
- ),
322
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
323
- import_components.Button,
324
- {
325
- __next40pxDefaultSize: true,
326
- size,
327
- variant: "primary",
328
- onClick: onSave,
329
- isBusy: isSaving,
330
- disabled: saveDisabled,
331
- accessibleWhenDisabled: true,
332
- children: (0, import_i18n.__)("Save")
333
- }
334
- )
335
- ]
336
- }
337
- );
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
+ });
338
277
  }
339
- function MediaEditorContent({
340
- fields = [],
341
- id,
342
- aspectRatioPresets,
343
- onClose,
344
- onSaved,
345
- renderFrame,
346
- noticesClassName = "media-editor__snackbar",
347
- noticesPortalElement,
348
- shouldCloseOnEsc = false
349
- }) {
350
- const session = (0, import_state.useMediaEditor)();
351
- const isWide = (0, import_compose.useViewportMatch)("small");
352
- const [activePanel, setActivePanel] = (0, import_element.useState)(
353
- isWide ? DETAILS_PANEL : null
354
- );
355
- const hasChosenPanelRef = (0, import_element.useRef)(false);
356
- const lastPanelRef = (0, import_element.useRef)(DETAILS_PANEL);
357
- const hasChosenTabRef = (0, import_element.useRef)(false);
358
- const selectPanel = (0, import_element.useCallback)((panel) => {
359
- hasChosenTabRef.current = true;
360
- lastPanelRef.current = panel;
361
- setActivePanel(panel);
362
- }, []);
363
- const togglePanel = (0, import_element.useCallback)(() => {
364
- hasChosenPanelRef.current = true;
365
- setActivePanel((open) => open ? null : lastPanelRef.current);
366
- }, []);
367
- const layout = isWide ? "wide" : "narrow";
368
- const sourceMedia = (0, import_data.useSelect)(
369
- (select) => select(import_core_data.store).getEntityRecord(
370
- "postType",
371
- "attachment",
372
- id
373
- ),
374
- [id]
375
- );
376
- const { clearEntityRecordEdits, editEntityRecord, invalidateResolution } = (0, import_data.useDispatch)(import_core_data.store);
377
- const { removeAllNotices } = (0, import_data.useDispatch)(import_notices.store);
378
- const [isDiscardDialogOpen, setIsDiscardDialogOpen] = (0, import_element.useState)(false);
379
- const [isPlacementActive, setIsPlacementActive] = (0, import_element.useState)(false);
380
- const [isCanvasGestureActive, setIsCanvasGestureActive] = (0, import_element.useState)(false);
381
- const [isSourceReplaced, setIsSourceReplaced] = (0, import_element.useState)(false);
382
- const placementControlTimerRef = (0, import_element.useRef)(void 0);
383
- const signalPlacementControlInteraction = (0, import_element.useCallback)(() => {
384
- setIsPlacementActive(true);
385
- clearTimeout(placementControlTimerRef.current);
386
- placementControlTimerRef.current = setTimeout(() => {
387
- setIsPlacementActive(false);
388
- }, PLACEMENT_CONTROL_IDLE_MS);
389
- }, []);
390
- const handleCanvasGestureStart = (0, import_element.useCallback)(() => {
391
- setIsCanvasGestureActive(true);
392
- }, []);
393
- const handleCanvasGestureEnd = (0, import_element.useCallback)(() => {
394
- setIsCanvasGestureActive(false);
395
- }, []);
396
- const isCropInteractionActive = isPlacementActive || isCanvasGestureActive;
397
- (0, import_element.useEffect)(() => {
398
- return () => {
399
- clearTimeout(placementControlTimerRef.current);
400
- };
401
- }, []);
402
- (0, import_element.useEffect)(() => {
403
- setIsPlacementActive(false);
404
- setIsCanvasGestureActive(false);
405
- setIsSourceReplaced(false);
406
- }, [id]);
407
- const originalId = sourceMedia?.edit_root;
408
- const originalRecord = (0, import_data.useSelect)(
409
- (select) => originalId ? select(import_core_data.store).getEntityRecord(
410
- "postType",
411
- "attachment",
412
- originalId
413
- ) : void 0,
414
- [originalId]
415
- );
416
- const originalWidth = Number(originalRecord?.media_details?.width);
417
- const originalHeight = Number(originalRecord?.media_details?.height);
418
- const originalUrl = originalRecord?.source_url;
419
- const originalSource = originalId && originalRecord && typeof originalUrl === "string" && originalUrl.length > 0 && Number.isFinite(originalWidth) && originalWidth > 0 && Number.isFinite(originalHeight) && originalHeight > 0 ? {
420
- id: originalId,
421
- url: originalUrl,
422
- media: originalRecord
423
- } : void 0;
424
- const canRestoreOriginal = !!originalSource;
425
- const replacementSource = isSourceReplaced && originalSource ? {
426
- id: originalSource.id,
427
- url: originalSource.url,
428
- media: originalSource.media
429
- } : void 0;
430
- const activeId = replacementSource?.id ?? id;
431
- const { media, hasEdits } = (0, import_data.useSelect)(
432
- (select) => {
433
- const {
434
- getEditedEntityRecord,
435
- getEntityRecord,
436
- hasEditsForEntityRecord
437
- } = select(import_core_data.store);
438
- getEntityRecord(
439
- "postType",
440
- "attachment",
441
- activeId,
442
- ATTACHMENT_EMBED_QUERY
443
- );
444
- return {
445
- media: getEditedEntityRecord(
446
- "postType",
447
- "attachment",
448
- activeId
449
- ),
450
- hasEdits: hasEditsForEntityRecord(
451
- "postType",
452
- "attachment",
453
- activeId
454
- )
455
- };
456
- },
457
- [activeId]
458
- );
459
- (0, import_element.useEffect)(() => {
460
- invalidateResolution("getEntityRecord", [
461
- "postType",
462
- "attachment",
463
- activeId,
464
- ATTACHMENT_EMBED_QUERY
465
- ]);
466
- }, [activeId, invalidateResolution]);
467
- const handleRestoreOriginal = (0, import_element.useCallback)(() => {
468
- clearEntityRecordEdits("postType", "attachment", id);
469
- setIsSourceReplaced(true);
470
- }, [clearEntityRecordEdits, id]);
471
- const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
472
- const mediaType = (0, import_utils.getMediaTypeFromMimeType)(media?.mime_type).type;
473
- const isImage = !!media && mediaType === "image";
474
- (0, import_element.useEffect)(() => {
475
- if (hasChosenPanelRef.current && hasChosenTabRef.current) {
476
- return;
477
- }
478
- const defaultPanel = isWide && isImage ? CROP_PANEL : DETAILS_PANEL;
479
- if (!hasChosenTabRef.current) {
480
- lastPanelRef.current = defaultPanel;
481
- }
482
- if (!hasChosenPanelRef.current) {
483
- setActivePanel(isWide ? lastPanelRef.current : null);
484
- }
485
- }, [isWide, isImage]);
486
- const {
487
- aspectRatioValue,
488
- setAspectRatioValue,
489
- aspectRatioOptions,
490
- resetCropOptions
491
- } = (0, import_use_crop_options.useCropOptions)({ aspectRatioPresets });
492
- const { isSaving, save: saveMediaEditor } = (0, import_use_save_media_editor.useSaveMediaEditor)({
493
- session,
494
- id,
495
- isImage,
496
- media: sourceMedia,
497
- onSaved,
498
- replacementSource
499
- });
500
- const handleChange = (updates) => {
501
- if (isSaving) {
502
- return;
503
- }
504
- editEntityRecord("postType", "attachment", activeId, updates);
505
- };
506
- const discardAndClose = () => {
507
- removeAllNotices("snackbar", import_use_save_media_editor.MEDIA_EDITOR_NOTICES_CONTEXT);
508
- clearEntityRecordEdits("postType", "attachment", activeId);
509
- setIsSourceReplaced(false);
510
- onClose?.();
511
- };
512
- const handleRequestClose = () => {
513
- if (isSaving) {
514
- return;
515
- }
516
- if (hasChanges) {
517
- setIsDiscardDialogOpen(true);
518
- return;
519
- }
520
- discardAndClose();
521
- };
522
- const handleKeyDown = (event) => {
523
- const isUndoShortcut = import_keycodes.isKeyboardEvent.primary(event, "z");
524
- const isRedoShortcut = import_keycodes.isKeyboardEvent.primaryShift(event, "z") || !(0, import_keycodes.isAppleOS)() && import_keycodes.isKeyboardEvent.primary(event, "y");
525
- if ((isUndoShortcut || isRedoShortcut) && isImage) {
526
- const target = event.target;
527
- const isMetadataField = (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) && !target.closest(`[${import_use_crop_gesture_handlers.CROP_CONTROL_ATTR}]`);
528
- if (!isMetadataField) {
529
- event.preventDefault();
530
- if (isCropInteractionActive || isSaving) {
531
- return;
532
- }
533
- if (isRedoShortcut) {
534
- session.redo();
535
- } else {
536
- session.undo();
537
- }
538
- }
539
- }
540
- if (shouldCloseOnEsc) {
541
- if (event.code !== "Escape" && event.key !== "Escape") {
542
- return;
543
- }
544
- if (isSaving) {
545
- event.preventDefault();
546
- return;
547
- }
548
- if (hasChanges) {
549
- event.preventDefault();
550
- setIsDiscardDialogOpen(true);
551
- }
552
- }
553
- };
554
- const snackbar = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
555
- import_notices.SnackbarNotices,
556
- {
557
- className: noticesClassName,
558
- context: import_use_save_media_editor.MEDIA_EDITOR_NOTICES_CONTEXT
559
- }
560
- );
561
- const imageControls = isImage && !isWide ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
562
- import_media_editor_image_controls.default,
563
- {
564
- showAspectRatioControl: true,
565
- aspectRatioPresets,
566
- disabled: isSaving
567
- }
568
- ) : null;
569
- const tabs = [
570
- ...isImage ? [
571
- {
572
- id: CROP_PANEL,
573
- title: (0, import_i18n.__)("Crop"),
574
- render: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
575
- import_media_editor_crop_panel.default,
576
- {
577
- aspectRatioValue,
578
- onAspectRatioChange: setAspectRatioValue,
579
- aspectRatioOptions,
580
- disabled: isSaving
581
- }
582
- )
583
- }
584
- ] : [],
585
- {
586
- id: DETAILS_PANEL,
587
- title: (0, import_i18n.__)("Details"),
588
- render: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_form.default, {})
589
- }
590
- ];
591
- const ruler = isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
592
- import_media_editor_fine_rotation.default,
593
- {
594
- onPlacementControlInteraction: signalPlacementControlInteraction,
595
- disabled: isSaving
596
- }
597
- ) : null;
598
- const children = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
599
- import_media_editor_provider.MediaEditorProvider,
600
- {
601
- value: media ?? void 0,
602
- onChange: handleChange,
603
- settings: {
604
- // Disable the fields while saving, so the guard in
605
- // `handleChange` is not silently swallowing typing.
606
- // `readOnly` would swap the field's layout mid-save;
607
- // disabled keeps it in place and greys it out.
608
- fields: isSaving ? fields.map((field) => ({
609
- ...field,
610
- isDisabled: true
611
- })) : fields
612
- },
613
- children: [
614
- /* @__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)(
615
- "div",
616
- {
617
- className: (0, import_clsx.default)("media-editor__body", {
618
- "has-panel-open": !!activePanel
619
- }),
620
- children: [
621
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
622
- import_admin_ui.NavigableRegion,
623
- {
624
- className: "media-editor__content",
625
- ariaLabel: isImage ? (0, import_i18n.__)("Image editor") : (0, import_i18n.__)("Media preview"),
626
- children: [
627
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor__canvas-area", children: isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
628
- import_media_editor_canvas.default,
629
- {
630
- isPlacementActive,
631
- onGestureStart: handleCanvasGestureStart,
632
- onGestureEnd: handleCanvasGestureEnd,
633
- disabled: isSaving
634
- }
635
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_preview.default, {}) }),
636
- isImage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor__canvas-toolbar", children: [
637
- ruler,
638
- imageControls
639
- ] })
640
- ]
641
- }
642
- ),
643
- !!activePanel && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
644
- MediaEditorSidebar,
645
- {
646
- tabs,
647
- activeTab: tabs.some(
648
- (tab) => tab.id === activePanel
649
- ) ? activePanel : DETAILS_PANEL,
650
- onSelectTab: selectPanel,
651
- disabled: isSaving
652
- }
653
- )
654
- ]
655
- }
656
- ) }),
657
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
658
- import_components.__experimentalConfirmDialog,
659
- {
660
- isOpen: isDiscardDialogOpen,
661
- confirmButtonText: (0, import_i18n.__)("Discard"),
662
- cancelButtonText: (0, import_i18n.__)("Keep editing"),
663
- onCancel: () => setIsDiscardDialogOpen(false),
664
- onConfirm: () => {
665
- setIsDiscardDialogOpen(false);
666
- discardAndClose();
667
- },
668
- children: (0, import_i18n.__)(
669
- "Are you sure you want to discard your unsaved changes?"
670
- )
671
- }
672
- ),
673
- noticesPortalElement ? (0, import_element.createPortal)(snackbar, noticesPortalElement) : snackbar
674
- ]
675
- }
676
- );
677
- const contextValue = {
678
- isImage,
679
- isSaving,
680
- hasMedia: !!media,
681
- hasChanges,
682
- // Saving freezes the whole edit surface: `save()` reads the
683
- // modifiers once and then awaits, so anything changed after that
684
- // would be silently dropped when the save resolves.
685
- isUndoRedoDisabled: isCropInteractionActive || isSaving,
686
- aspectRatioPresets,
687
- isWide,
688
- activePanel,
689
- onTogglePanel: togglePanel,
690
- onCancel: handleRequestClose,
691
- onSave: saveMediaEditor,
692
- onReset: resetCropOptions,
693
- canRestoreOriginal,
694
- isSourceReplaced,
695
- onRestoreOriginal: handleRestoreOriginal
696
- };
697
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorFrameContext.Provider, { value: contextValue, children: renderFrame({
698
- children,
699
- isImage,
700
- layout,
701
- onRequestClose: handleRequestClose,
702
- onKeyDown: handleKeyDown,
703
- shouldCloseOnClickOutside: !hasChanges && !isSaving,
704
- isSaving,
705
- hasChanges,
706
- hasMedia: !!media
707
- }) });
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
+ });
708
546
  }
709
547
  function MediaEditor(props) {
710
- 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);
711
549
  }
712
550
  MediaEditor.HeaderActions = HeaderActions;
551
+ MediaEditor.PanelToggle = PanelToggle;
552
+ MediaEditor.MoreMenu = MoreMenu;
713
553
  MediaEditor.HistoryActions = HistoryActions;
714
554
  MediaEditor.SaveActions = SaveActions;
715
- var media_editor_default = MediaEditor;
716
- // Annotate the CommonJS export names for ESM import in node:
717
- 0 && (module.exports = {
718
- MediaEditor
719
- });
720
- //# sourceMappingURL=index.cjs.map
555
+ exports.MediaEditor = MediaEditor;
556
+ exports.default = MediaEditor;
557
+
558
+ //# sourceMappingURL=index.cjs.map