@wordpress/media-editor 0.21.0 → 0.22.0

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