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