@wordpress/media-editor 0.21.0 → 0.23.0

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