@wordpress/media-editor 0.9.0 → 0.10.1

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 (322) hide show
  1. package/build/components/media-editor/index.cjs +212 -170
  2. package/build/components/media-editor/index.cjs.map +3 -3
  3. package/build/components/media-editor/use-crop-options.cjs +63 -0
  4. package/build/components/media-editor/use-crop-options.cjs.map +7 -0
  5. package/build/components/media-editor/use-save-media-editor.cjs +185 -0
  6. package/build/components/media-editor/use-save-media-editor.cjs.map +7 -0
  7. package/build/components/media-editor-canvas/index.cjs +33 -12
  8. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  9. package/build/components/media-editor-crop-panel/index.cjs +70 -84
  10. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  11. package/build/components/media-editor-fine-rotation/index.cjs +81 -0
  12. package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
  13. package/build/components/media-editor-modal/index.cjs +63 -16
  14. package/build/components/media-editor-modal/index.cjs.map +3 -3
  15. package/build/components/media-editor-transform-controls/index.cjs +84 -0
  16. package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
  17. package/build/components/media-form/index.cjs +19 -1
  18. package/build/components/media-form/index.cjs.map +3 -3
  19. package/build/components/media-form/sidebar-datetime-view.cjs +53 -0
  20. package/build/components/media-form/sidebar-datetime-view.cjs.map +7 -0
  21. package/build/components/rotation-ruler/index.cjs +8 -2
  22. package/build/components/rotation-ruler/index.cjs.map +2 -2
  23. package/build/hooks/use-crop-gesture-handlers.cjs +41 -4
  24. package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
  25. package/build/image-editor/core/camera.cjs +29 -11
  26. package/build/image-editor/core/camera.cjs.map +2 -2
  27. package/build/image-editor/core/constants.cjs +6 -0
  28. package/build/image-editor/core/constants.cjs.map +2 -2
  29. package/build/image-editor/core/containment.cjs +71 -34
  30. package/build/image-editor/core/containment.cjs.map +2 -2
  31. package/build/image-editor/core/crop-rect.cjs +48 -0
  32. package/build/image-editor/core/crop-rect.cjs.map +7 -0
  33. package/build/image-editor/core/index.cjs +12 -0
  34. package/build/image-editor/core/index.cjs.map +2 -2
  35. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  36. package/build/image-editor/core/math/sanitize.cjs +92 -0
  37. package/build/image-editor/core/math/sanitize.cjs.map +7 -0
  38. package/build/image-editor/core/setter-helpers.cjs +64 -0
  39. package/build/image-editor/core/setter-helpers.cjs.map +7 -0
  40. package/build/image-editor/core/source-region.cjs +16 -14
  41. package/build/image-editor/core/source-region.cjs.map +2 -2
  42. package/build/image-editor/core/state.cjs +20 -10
  43. package/build/image-editor/core/state.cjs.map +2 -2
  44. package/build/image-editor/core/stencil-math.cjs +31 -20
  45. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  46. package/build/image-editor/core/transform-style.cjs +12 -6
  47. package/build/image-editor/core/transform-style.cjs.map +2 -2
  48. package/build/image-editor/core/types.cjs.map +1 -1
  49. package/build/image-editor/index.cjs +12 -2
  50. package/build/image-editor/index.cjs.map +2 -2
  51. package/build/image-editor/react/components/cropper-provider.cjs +2 -2
  52. package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
  53. package/build/image-editor/react/components/cropper.cjs +120 -47
  54. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  55. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +172 -0
  56. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +7 -0
  57. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +19 -9
  58. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  59. package/build/image-editor/react/hooks/build-cropper-setters.cjs +71 -0
  60. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +7 -0
  61. package/build/image-editor/react/hooks/index.cjs +6 -3
  62. package/build/image-editor/react/hooks/index.cjs.map +2 -2
  63. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +113 -0
  64. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +7 -0
  65. package/build/state/composite-reducer.cjs +103 -0
  66. package/build/state/composite-reducer.cjs.map +7 -0
  67. package/build/state/index.cjs +48 -0
  68. package/build/state/index.cjs.map +7 -0
  69. package/build/state/media-editor-state-provider.cjs +58 -0
  70. package/build/state/media-editor-state-provider.cjs.map +7 -0
  71. package/build/state/types.cjs +33 -0
  72. package/build/state/types.cjs.map +7 -0
  73. package/build/state/use-media-editor-state.cjs +287 -0
  74. package/build/state/use-media-editor-state.cjs.map +7 -0
  75. package/build/store/actions.cjs +4 -2
  76. package/build/store/actions.cjs.map +2 -2
  77. package/build/store/reducer.cjs +5 -3
  78. package/build/store/reducer.cjs.map +2 -2
  79. package/build/store/selectors.cjs +5 -0
  80. package/build/store/selectors.cjs.map +2 -2
  81. package/build-module/components/media-editor/index.mjs +224 -177
  82. package/build-module/components/media-editor/index.mjs.map +2 -2
  83. package/build-module/components/media-editor/use-crop-options.mjs +37 -0
  84. package/build-module/components/media-editor/use-crop-options.mjs.map +7 -0
  85. package/build-module/components/media-editor/use-save-media-editor.mjs +151 -0
  86. package/build-module/components/media-editor/use-save-media-editor.mjs.map +7 -0
  87. package/build-module/components/media-editor-canvas/index.mjs +34 -13
  88. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  89. package/build-module/components/media-editor-crop-panel/index.mjs +73 -89
  90. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  91. package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
  92. package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
  93. package/build-module/components/media-editor-modal/index.mjs +64 -17
  94. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  95. package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
  96. package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
  97. package/build-module/components/media-form/index.mjs +9 -1
  98. package/build-module/components/media-form/index.mjs.map +2 -2
  99. package/build-module/components/media-form/sidebar-datetime-view.mjs +32 -0
  100. package/build-module/components/media-form/sidebar-datetime-view.mjs.map +7 -0
  101. package/build-module/components/rotation-ruler/index.mjs +8 -2
  102. package/build-module/components/rotation-ruler/index.mjs.map +2 -2
  103. package/build-module/hooks/use-crop-gesture-handlers.mjs +41 -4
  104. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
  105. package/build-module/image-editor/core/camera.mjs +34 -11
  106. package/build-module/image-editor/core/camera.mjs.map +2 -2
  107. package/build-module/image-editor/core/constants.mjs +4 -0
  108. package/build-module/image-editor/core/constants.mjs.map +2 -2
  109. package/build-module/image-editor/core/containment.mjs +75 -34
  110. package/build-module/image-editor/core/containment.mjs.map +2 -2
  111. package/build-module/image-editor/core/crop-rect.mjs +23 -0
  112. package/build-module/image-editor/core/crop-rect.mjs.map +7 -0
  113. package/build-module/image-editor/core/index.mjs +12 -0
  114. package/build-module/image-editor/core/index.mjs.map +2 -2
  115. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  116. package/build-module/image-editor/core/math/sanitize.mjs +63 -0
  117. package/build-module/image-editor/core/math/sanitize.mjs.map +7 -0
  118. package/build-module/image-editor/core/setter-helpers.mjs +39 -0
  119. package/build-module/image-editor/core/setter-helpers.mjs.map +7 -0
  120. package/build-module/image-editor/core/source-region.mjs +16 -14
  121. package/build-module/image-editor/core/source-region.mjs.map +2 -2
  122. package/build-module/image-editor/core/state.mjs +25 -11
  123. package/build-module/image-editor/core/state.mjs.map +2 -2
  124. package/build-module/image-editor/core/stencil-math.mjs +30 -19
  125. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  126. package/build-module/image-editor/core/transform-style.mjs +12 -6
  127. package/build-module/image-editor/core/transform-style.mjs.map +2 -2
  128. package/build-module/image-editor/index.mjs +11 -2
  129. package/build-module/image-editor/index.mjs.map +2 -2
  130. package/build-module/image-editor/react/components/cropper-provider.mjs +3 -3
  131. package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
  132. package/build-module/image-editor/react/components/cropper.mjs +121 -48
  133. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  134. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +147 -0
  135. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +7 -0
  136. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +19 -9
  137. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  138. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +46 -0
  139. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +7 -0
  140. package/build-module/image-editor/react/hooks/index.mjs +4 -2
  141. package/build-module/image-editor/react/hooks/index.mjs.map +2 -2
  142. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +100 -0
  143. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +7 -0
  144. package/build-module/state/composite-reducer.mjs +82 -0
  145. package/build-module/state/composite-reducer.mjs.map +7 -0
  146. package/build-module/state/index.mjs +26 -0
  147. package/build-module/state/index.mjs.map +7 -0
  148. package/build-module/state/media-editor-state-provider.mjs +34 -0
  149. package/build-module/state/media-editor-state-provider.mjs.map +7 -0
  150. package/build-module/state/types.mjs +8 -0
  151. package/build-module/state/types.mjs.map +7 -0
  152. package/build-module/state/use-media-editor-state.mjs +278 -0
  153. package/build-module/state/use-media-editor-state.mjs.map +7 -0
  154. package/build-module/store/actions.mjs +4 -2
  155. package/build-module/store/actions.mjs.map +2 -2
  156. package/build-module/store/reducer.mjs +5 -3
  157. package/build-module/store/reducer.mjs.map +2 -2
  158. package/build-module/store/selectors.mjs +4 -0
  159. package/build-module/store/selectors.mjs.map +2 -2
  160. package/build-style/style-rtl.css +97 -44
  161. package/build-style/style.css +97 -44
  162. package/build-types/components/media-editor/index.d.ts +14 -5
  163. package/build-types/components/media-editor/index.d.ts.map +1 -1
  164. package/build-types/components/media-editor/use-crop-options.d.ts +35 -0
  165. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -0
  166. package/build-types/components/media-editor/use-save-media-editor.d.ts +29 -0
  167. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -0
  168. package/build-types/components/media-editor-canvas/index.d.ts +5 -10
  169. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  170. package/build-types/components/media-editor-crop-panel/index.d.ts +6 -25
  171. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  172. package/build-types/components/media-editor-fine-rotation/index.d.ts +14 -0
  173. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
  174. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  175. package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
  176. package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
  177. package/build-types/components/media-form/index.d.ts.map +1 -1
  178. package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
  179. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
  180. package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
  181. package/build-types/hooks/use-crop-gesture-handlers.d.ts +13 -14
  182. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
  183. package/build-types/image-editor/core/camera.d.ts.map +1 -1
  184. package/build-types/image-editor/core/constants.d.ts +18 -0
  185. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  186. package/build-types/image-editor/core/containment.d.ts +10 -0
  187. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  188. package/build-types/image-editor/core/crop-rect.d.ts +19 -0
  189. package/build-types/image-editor/core/crop-rect.d.ts.map +1 -0
  190. package/build-types/image-editor/core/index.d.ts +3 -1
  191. package/build-types/image-editor/core/index.d.ts.map +1 -1
  192. package/build-types/image-editor/core/interaction-controller.d.ts +5 -1
  193. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  194. package/build-types/image-editor/core/math/sanitize.d.ts +70 -0
  195. package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -0
  196. package/build-types/image-editor/core/setter-helpers.d.ts +24 -0
  197. package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -0
  198. package/build-types/image-editor/core/source-region.d.ts.map +1 -1
  199. package/build-types/image-editor/core/state.d.ts +12 -0
  200. package/build-types/image-editor/core/state.d.ts.map +1 -1
  201. package/build-types/image-editor/core/stencil-math.d.ts +23 -18
  202. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  203. package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
  204. package/build-types/image-editor/core/types.d.ts +23 -4
  205. package/build-types/image-editor/core/types.d.ts.map +1 -1
  206. package/build-types/image-editor/index.d.ts +4 -4
  207. package/build-types/image-editor/index.d.ts.map +1 -1
  208. package/build-types/image-editor/react/components/cropper-provider.d.ts +11 -7
  209. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  210. package/build-types/image-editor/react/components/cropper.d.ts +6 -4
  211. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  212. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +36 -0
  213. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -0
  214. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +2 -1
  215. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  216. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +47 -0
  217. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -0
  218. package/build-types/image-editor/react/hooks/index.d.ts +4 -2
  219. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  220. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +58 -0
  221. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -0
  222. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
  223. package/build-types/state/composite-reducer.d.ts +39 -0
  224. package/build-types/state/composite-reducer.d.ts.map +1 -0
  225. package/build-types/state/index.d.ts +7 -0
  226. package/build-types/state/index.d.ts.map +1 -0
  227. package/build-types/state/media-editor-state-provider.d.ts +34 -0
  228. package/build-types/state/media-editor-state-provider.d.ts.map +1 -0
  229. package/build-types/state/types.d.ts +96 -0
  230. package/build-types/state/types.d.ts.map +1 -0
  231. package/build-types/state/use-media-editor-state.d.ts +101 -0
  232. package/build-types/state/use-media-editor-state.d.ts.map +1 -0
  233. package/build-types/store/actions.d.ts +3 -1
  234. package/build-types/store/actions.d.ts.map +1 -1
  235. package/build-types/store/reducer.d.ts +3 -0
  236. package/build-types/store/reducer.d.ts.map +1 -1
  237. package/build-types/store/selectors.d.ts +1 -0
  238. package/build-types/store/selectors.d.ts.map +1 -1
  239. package/package.json +19 -16
  240. package/src/components/media-editor/index.tsx +262 -229
  241. package/src/components/media-editor/style.scss +0 -9
  242. package/src/components/media-editor/test/use-crop-options.tsx +110 -0
  243. package/src/components/media-editor/use-crop-options.ts +79 -0
  244. package/src/components/media-editor/use-save-media-editor.ts +214 -0
  245. package/src/components/media-editor-canvas/index.tsx +57 -25
  246. package/src/components/media-editor-crop-panel/index.tsx +53 -87
  247. package/src/components/media-editor-crop-panel/test/index.tsx +46 -53
  248. package/src/components/media-editor-fine-rotation/index.tsx +74 -0
  249. package/src/components/media-editor-modal/index.tsx +70 -16
  250. package/src/components/media-editor-modal/style.scss +80 -0
  251. package/src/components/media-editor-modal/test/build-modifiers.test.ts +14 -0
  252. package/src/components/media-editor-modal/test/index.tsx +146 -0
  253. package/src/components/media-editor-transform-controls/index.tsx +70 -0
  254. package/src/components/media-editor-transform-controls/style.scss +8 -0
  255. package/src/components/media-form/index.tsx +15 -1
  256. package/src/components/media-form/sidebar-datetime-view.tsx +47 -0
  257. package/src/components/media-form/test/sidebar-datetime-view.test.tsx +96 -0
  258. package/src/components/rotation-ruler/README.md +11 -25
  259. package/src/components/rotation-ruler/index.tsx +17 -2
  260. package/src/components/rotation-ruler/style.scss +49 -13
  261. package/src/hooks/use-crop-gesture-handlers.ts +64 -17
  262. package/src/image-editor/README.md +28 -129
  263. package/src/image-editor/core/camera.ts +51 -26
  264. package/src/image-editor/core/constants.ts +19 -0
  265. package/src/image-editor/core/containment.ts +102 -49
  266. package/src/image-editor/core/crop-rect.ts +45 -0
  267. package/src/image-editor/core/index.ts +16 -4
  268. package/src/image-editor/core/interaction-controller.ts +5 -1
  269. package/src/image-editor/core/math/sanitize.ts +158 -0
  270. package/src/image-editor/core/math/test/sanitize.ts +244 -0
  271. package/src/image-editor/core/setter-helpers.ts +66 -0
  272. package/src/image-editor/core/source-region.ts +21 -14
  273. package/src/image-editor/core/state.ts +67 -15
  274. package/src/image-editor/core/stencil-math.ts +55 -35
  275. package/src/image-editor/core/test/camera.ts +367 -1
  276. package/src/image-editor/core/test/state.ts +101 -8
  277. package/src/image-editor/core/test/stencil-math.ts +193 -0
  278. package/src/image-editor/core/transform-style.ts +21 -6
  279. package/src/image-editor/core/types.ts +24 -4
  280. package/src/image-editor/docs/architecture.md +48 -89
  281. package/src/image-editor/docs/recipes.md +123 -659
  282. package/src/image-editor/index.ts +12 -3
  283. package/src/image-editor/react/components/cropper-provider.tsx +16 -12
  284. package/src/image-editor/react/components/cropper.scss +23 -4
  285. package/src/image-editor/react/components/cropper.tsx +194 -89
  286. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +269 -0
  287. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +19 -8
  288. package/src/image-editor/react/components/test/cropper.tsx +55 -13
  289. package/src/image-editor/react/hooks/build-cropper-setters.ts +105 -0
  290. package/src/image-editor/react/hooks/index.ts +4 -2
  291. package/src/image-editor/react/hooks/test/{use-cropper-state.ts → use-cropper-reducer.ts} +142 -286
  292. package/src/image-editor/react/hooks/use-cropper-reducer.ts +204 -0
  293. package/src/image-editor/stories/rectangle-crop.story.tsx +7 -17
  294. package/src/state/composite-reducer.ts +137 -0
  295. package/src/state/index.ts +20 -0
  296. package/src/state/media-editor-state-provider.tsx +70 -0
  297. package/src/state/test/use-media-editor-state.ts +330 -0
  298. package/src/state/types.ts +101 -0
  299. package/src/state/use-media-editor-state.ts +472 -0
  300. package/src/store/actions.ts +3 -0
  301. package/src/store/reducer.ts +6 -1
  302. package/src/store/selectors.ts +4 -0
  303. package/src/store/test/reducer.ts +9 -0
  304. package/src/style.scss +1 -1
  305. package/tsconfig.json +3 -0
  306. package/tsconfig.tsbuildinfo +1 -1
  307. package/build/components/media-editor-toolbar/index.cjs +0 -214
  308. package/build/components/media-editor-toolbar/index.cjs.map +0 -7
  309. package/build/image-editor/react/hooks/use-cropper-state.cjs +0 -277
  310. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +0 -7
  311. package/build-module/components/media-editor-toolbar/index.mjs +0 -190
  312. package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
  313. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +0 -262
  314. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +0 -7
  315. package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
  316. package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
  317. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -97
  318. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
  319. package/src/components/media-editor-toolbar/index.tsx +0 -209
  320. package/src/components/media-editor-toolbar/style.scss +0 -49
  321. package/src/image-editor/docs/roadmap.md +0 -66
  322. package/src/image-editor/react/hooks/use-cropper-state.ts +0 -457
@@ -34,9 +34,9 @@ __export(media_editor_exports, {
34
34
  default: () => media_editor_default
35
35
  });
36
36
  module.exports = __toCommonJS(media_editor_exports);
37
- var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
38
37
  var import_components = require("@wordpress/components");
39
38
  var import_ui = require("@wordpress/ui");
39
+ var import_compose = require("@wordpress/compose");
40
40
  var import_data = require("@wordpress/data");
41
41
  var import_core_data = require("@wordpress/core-data");
42
42
  var import_element = require("@wordpress/element");
@@ -48,25 +48,19 @@ var import_interface = require("@wordpress/interface");
48
48
  var import_media_editor_provider = require("../media-editor-provider/index.cjs");
49
49
  var import_media_preview = __toESM(require("../media-preview/index.cjs"));
50
50
  var import_media_editor_canvas = __toESM(require("../media-editor-canvas/index.cjs"));
51
- var import_media_editor_toolbar = __toESM(require("../media-editor-toolbar/index.cjs"));
51
+ var import_media_editor_fine_rotation = __toESM(require("../media-editor-fine-rotation/index.cjs"));
52
+ var import_media_editor_transform_controls = __toESM(require("../media-editor-transform-controls/index.cjs"));
52
53
  var import_media_editor_crop_panel = __toESM(require("../media-editor-crop-panel/index.cjs"));
53
54
  var import_media_form = __toESM(require("../media-form/index.cjs"));
54
55
  var import_lock_unlock = require("../../lock-unlock.cjs");
55
56
  var import_utils = require("../../utils/index.cjs");
56
- var import_image_editor = require("../../image-editor/index.cjs");
57
+ var import_state = require("../../state/index.cjs");
57
58
  var import_use_crop_gesture_handlers = require("../../hooks/use-crop-gesture-handlers.cjs");
58
- var import_build_modifiers = require("../media-editor-modal/build-modifiers.cjs");
59
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");
60
62
  var import_jsx_runtime = require("react/jsx-runtime");
61
- var METADATA_EDIT_KEYS = [
62
- "title",
63
- "caption",
64
- "description",
65
- "alt_text",
66
- "post"
67
- ];
68
63
  var ATTACHMENT_EMBED_QUERY = { _embed: "author,wp:attached-to" };
69
- var NOTICES_CONTEXT = "media-editor";
70
64
  var PLACEMENT_CONTROL_IDLE_MS = 300;
71
65
  var { Tabs } = (0, import_lock_unlock.unlock)(import_components.privateApis);
72
66
  function MediaEditorSidebar({ tabs }) {
@@ -97,14 +91,10 @@ function MediaEditorSidebar({ tabs }) {
97
91
  }
98
92
  function HeaderActions({
99
93
  isSaving,
100
- hasMedia,
101
- hasChanges,
102
94
  isImage,
103
95
  showCloseButton = false,
104
- onCancel,
105
- onSave
96
+ onCancel
106
97
  }) {
107
- const saveDisabled = isSaving || !hasMedia || !hasChanges;
108
98
  const [isShortcutsModalOpen, setIsShortcutsModalOpen] = (0, import_element.useState)(false);
109
99
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
110
100
  import_components.Flex,
@@ -124,44 +114,144 @@ function HeaderActions({
124
114
  }
125
115
  ),
126
116
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_interface.PinnedItems.Slot, { scope: "media-editor" }),
127
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
117
+ showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
128
118
  import_components.Button,
129
119
  {
130
120
  size: "compact",
131
- variant: "tertiary",
121
+ icon: import_icons.close,
122
+ label: (0, import_i18n.__)("Close"),
132
123
  onClick: onCancel,
133
124
  disabled: isSaving,
125
+ accessibleWhenDisabled: true
126
+ }
127
+ ),
128
+ isShortcutsModalOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
+ import_media_editor_keyboard_shortcuts_modal.default,
130
+ {
131
+ onClose: () => setIsShortcutsModalOpen(false)
132
+ }
133
+ )
134
+ ]
135
+ }
136
+ );
137
+ }
138
+ function HistoryActions({
139
+ isUndoRedoDisabled = false,
140
+ onReset
141
+ }) {
142
+ const {
143
+ reset,
144
+ isDirty,
145
+ hasUndo,
146
+ hasRedo,
147
+ undo: undoCrop,
148
+ redo: redoCrop,
149
+ beginGesture,
150
+ endGesture
151
+ } = (0, import_state.useMediaEditor)();
152
+ const handleUndo = () => {
153
+ if (isUndoRedoDisabled) {
154
+ return;
155
+ }
156
+ undoCrop();
157
+ };
158
+ const handleRedo = () => {
159
+ if (isUndoRedoDisabled) {
160
+ return;
161
+ }
162
+ redoCrop();
163
+ };
164
+ const handleReset = () => {
165
+ beginGesture();
166
+ reset();
167
+ onReset();
168
+ endGesture();
169
+ };
170
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
171
+ import_components.Flex,
172
+ {
173
+ className: "media-editor__history-actions",
174
+ expanded: false,
175
+ gap: 2,
176
+ children: [
177
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
178
+ import_components.Button,
179
+ {
180
+ size: "compact",
181
+ icon: import_icons.undo,
182
+ label: (0, import_i18n.__)("Undo"),
183
+ showTooltip: true,
184
+ shortcut: import_keycodes.displayShortcut.primary("z"),
185
+ disabled: isUndoRedoDisabled || !hasUndo,
134
186
  accessibleWhenDisabled: true,
135
- children: (0, import_i18n.__)("Cancel")
187
+ onClick: handleUndo
136
188
  }
137
189
  ),
138
190
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
139
191
  import_components.Button,
140
192
  {
141
193
  size: "compact",
142
- variant: "primary",
143
- onClick: onSave,
144
- isBusy: isSaving,
145
- disabled: saveDisabled,
194
+ icon: import_icons.redo,
195
+ label: (0, import_i18n.__)("Redo"),
196
+ showTooltip: true,
197
+ shortcut: (0, import_keycodes.isAppleOS)() ? import_keycodes.displayShortcut.primaryShift("z") : import_keycodes.displayShortcut.primary("y"),
198
+ disabled: isUndoRedoDisabled || !hasRedo,
146
199
  accessibleWhenDisabled: true,
147
- children: (0, import_i18n.__)("Save")
200
+ onClick: handleRedo
148
201
  }
149
202
  ),
150
- showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
203
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
151
204
  import_components.Button,
152
205
  {
153
206
  size: "compact",
154
- icon: import_icons.close,
155
- label: (0, import_i18n.__)("Close"),
207
+ variant: "tertiary",
208
+ disabled: !isDirty,
209
+ accessibleWhenDisabled: true,
210
+ onClick: handleReset,
211
+ children: (0, import_i18n.__)("Reset")
212
+ }
213
+ )
214
+ ]
215
+ }
216
+ );
217
+ }
218
+ function FooterActions({
219
+ isSaving,
220
+ hasMedia,
221
+ hasChanges,
222
+ onCancel,
223
+ onSave
224
+ }) {
225
+ const saveDisabled = isSaving || !hasMedia || !hasChanges;
226
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
227
+ import_components.Flex,
228
+ {
229
+ className: "media-editor__footer-actions",
230
+ justify: "flex-end",
231
+ expanded: false,
232
+ gap: 2,
233
+ children: [
234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
235
+ import_components.Button,
236
+ {
237
+ __next40pxDefaultSize: true,
238
+ variant: "tertiary",
156
239
  onClick: onCancel,
157
240
  disabled: isSaving,
158
- accessibleWhenDisabled: true
241
+ accessibleWhenDisabled: true,
242
+ children: (0, import_i18n.__)("Cancel")
159
243
  }
160
244
  ),
161
- isShortcutsModalOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
162
- import_media_editor_keyboard_shortcuts_modal.default,
245
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
246
+ import_components.Button,
163
247
  {
164
- onClose: () => setIsShortcutsModalOpen(false)
248
+ __next40pxDefaultSize: true,
249
+ variant: "primary",
250
+ onClick: onSave,
251
+ isBusy: isSaving,
252
+ disabled: saveDisabled,
253
+ accessibleWhenDisabled: true,
254
+ children: (0, import_i18n.__)("Save")
165
255
  }
166
256
  )
167
257
  ]
@@ -180,7 +270,15 @@ function MediaEditorContent({
180
270
  showCloseButton = false,
181
271
  shouldCloseOnEsc = false
182
272
  }) {
183
- const cropper = (0, import_image_editor.useCropper)();
273
+ const cropper = (0, import_state.useMediaEditor)();
274
+ const isWideViewport = (0, import_compose.useViewportMatch)("xlarge");
275
+ const isMediumViewport = (0, import_compose.useViewportMatch)("medium");
276
+ let footerLayout = "narrow";
277
+ if (isWideViewport) {
278
+ footerLayout = "wide";
279
+ } else if (isMediumViewport) {
280
+ footerLayout = "medium";
281
+ }
184
282
  const { media, hasEdits } = (0, import_data.useSelect)(
185
283
  (select) => {
186
284
  const {
@@ -209,23 +307,13 @@ function MediaEditorContent({
209
307
  },
210
308
  [id]
211
309
  );
212
- const hasChanges = cropper.isDirty || hasEdits;
213
- const registry = (0, import_data.useRegistry)();
214
- const {
215
- clearEntityRecordEdits,
216
- editEntityRecord,
217
- invalidateResolution,
218
- receiveEntityRecords,
219
- saveEditedEntityRecord
220
- } = (0, import_data.useDispatch)(import_core_data.store);
221
- const { createErrorNotice, removeAllNotices } = (0, import_data.useDispatch)(import_notices.store);
222
- const [isSaving, setIsSaving] = (0, import_element.useState)(false);
310
+ const hasChanges = cropper.isCropperDirty || hasEdits;
311
+ const { clearEntityRecordEdits, editEntityRecord, invalidateResolution } = (0, import_data.useDispatch)(import_core_data.store);
312
+ const { removeAllNotices } = (0, import_data.useDispatch)(import_notices.store);
223
313
  const [isDiscardDialogOpen, setIsDiscardDialogOpen] = (0, import_element.useState)(false);
224
314
  const [isPlacementActive, setIsPlacementActive] = (0, import_element.useState)(false);
225
315
  const [isCanvasGestureActive, setIsCanvasGestureActive] = (0, import_element.useState)(false);
226
316
  const placementControlTimerRef = (0, import_element.useRef)();
227
- const [aspectRatioValue, setAspectRatioValue] = (0, import_element.useState)("0");
228
- const [freeformCrop, setFreeformCrop] = (0, import_element.useState)(true);
229
317
  const signalPlacementControlInteraction = (0, import_element.useCallback)(() => {
230
318
  setIsPlacementActive(true);
231
319
  clearTimeout(placementControlTimerRef.current);
@@ -246,8 +334,6 @@ function MediaEditorContent({
246
334
  };
247
335
  }, []);
248
336
  (0, import_element.useEffect)(() => {
249
- setAspectRatioValue("0");
250
- setFreeformCrop(true);
251
337
  setIsPlacementActive(false);
252
338
  setIsCanvasGestureActive(false);
253
339
  }, [id]);
@@ -261,17 +347,21 @@ function MediaEditorContent({
261
347
  }, [id, invalidateResolution]);
262
348
  const mediaType = (0, import_utils.getMediaTypeFromMimeType)(media?.mime_type).type;
263
349
  const isImage = !!media && mediaType === "image";
264
- const imageAspectRatio = (0, import_element.useMemo)(() => {
265
- if (!isImage) {
266
- return null;
267
- }
268
- const naturalWidth = Number(media?.media_details?.width);
269
- const naturalHeight = Number(media?.media_details?.height);
270
- if (Number.isFinite(naturalWidth) && Number.isFinite(naturalHeight) && naturalHeight > 0) {
271
- return naturalWidth / naturalHeight;
272
- }
273
- return null;
274
- }, [isImage, media]);
350
+ const {
351
+ aspectRatioValue,
352
+ setAspectRatioValue,
353
+ aspectRatioOptions,
354
+ resetCropOptions
355
+ } = (0, import_use_crop_options.useCropOptions)({
356
+ aspectRatioPresets
357
+ });
358
+ const { isSaving, save: saveMediaEditor } = (0, import_use_save_media_editor.useSaveMediaEditor)({
359
+ cropper,
360
+ id,
361
+ isImage,
362
+ media,
363
+ onSaved
364
+ });
275
365
  const tabs = (0, import_element.useMemo)(() => {
276
366
  const detailsTab = {
277
367
  id: "details",
@@ -304,10 +394,8 @@ function MediaEditorContent({
304
394
  {
305
395
  aspectRatioValue,
306
396
  onAspectRatioChange: setAspectRatioValue,
307
- freeformCrop,
308
- onFreeformChange: setFreeformCrop,
309
397
  onPlacementControlInteraction: signalPlacementControlInteraction,
310
- aspectRatioPresets
398
+ aspectRatioOptions
311
399
  }
312
400
  )
313
401
  }
@@ -318,15 +406,15 @@ function MediaEditorContent({
318
406
  }, [
319
407
  isImage,
320
408
  aspectRatioValue,
321
- freeformCrop,
322
- aspectRatioPresets,
409
+ setAspectRatioValue,
410
+ aspectRatioOptions,
323
411
  signalPlacementControlInteraction
324
412
  ]);
325
413
  const handleChange = (updates) => {
326
414
  editEntityRecord("postType", "attachment", id, updates);
327
415
  };
328
416
  const discardAndClose = () => {
329
- removeAllNotices("snackbar", NOTICES_CONTEXT);
417
+ removeAllNotices("snackbar", import_use_save_media_editor.MEDIA_EDITOR_NOTICES_CONTEXT);
330
418
  clearEntityRecordEdits("postType", "attachment", id);
331
419
  onClose?.();
332
420
  };
@@ -340,87 +428,6 @@ function MediaEditorContent({
340
428
  }
341
429
  discardAndClose();
342
430
  };
343
- const handleSave = async () => {
344
- removeAllNotices("snackbar", NOTICES_CONTEXT);
345
- setIsSaving(true);
346
- try {
347
- let saved;
348
- const modifiers = cropper.isDirty && cropper.state.image ? (0, import_build_modifiers.buildModifiers)(cropper.state, {
349
- width: cropper.state.image.naturalWidth,
350
- height: cropper.state.image.naturalHeight
351
- }) : [];
352
- if (modifiers.length > 0) {
353
- const pendingEdits = registry.select(import_core_data.store).getEntityRecordNonTransientEdits(
354
- "postType",
355
- "attachment",
356
- id
357
- );
358
- const metadataEdits = {};
359
- for (const key of METADATA_EDIT_KEYS) {
360
- if (pendingEdits && key in pendingEdits) {
361
- metadataEdits[key] = pendingEdits[key];
362
- }
363
- }
364
- if (!("post" in metadataEdits) && media?.post !== void 0) {
365
- metadataEdits.post = media.post;
366
- }
367
- saved = await (0, import_api_fetch.default)({
368
- path: `/wp/v2/media/${id}/edit`,
369
- method: "POST",
370
- data: {
371
- src: media?.source_url,
372
- modifiers,
373
- ...metadataEdits
374
- }
375
- });
376
- if (saved) {
377
- receiveEntityRecords(
378
- "postType",
379
- "attachment",
380
- saved,
381
- void 0,
382
- true
383
- );
384
- }
385
- } else {
386
- saved = await saveEditedEntityRecord(
387
- "postType",
388
- "attachment",
389
- id
390
- );
391
- }
392
- const next = saved ?? media;
393
- if (next && next.id !== id) {
394
- clearEntityRecordEdits("postType", "attachment", id);
395
- }
396
- if (next && next.id) {
397
- if (next.id === id) {
398
- cropper.reset();
399
- }
400
- onSaved?.({
401
- id: next.id,
402
- url: next.source_url,
403
- media: next
404
- });
405
- }
406
- } catch (error) {
407
- const message = error instanceof Error ? error.message : error?.message ?? (0, import_i18n.__)("An unknown error occurred.");
408
- createErrorNotice(
409
- isImage ? (0, import_i18n.sprintf)(
410
- /* translators: %s: Error message. */
411
- (0, import_i18n.__)("Could not save image. %s"),
412
- message
413
- ) : (0, import_i18n.sprintf)(
414
- /* translators: %s: Error message. */
415
- (0, import_i18n.__)("Could not save media. %s"),
416
- message
417
- ),
418
- { type: "snackbar", context: NOTICES_CONTEXT }
419
- );
420
- } finally {
421
- setIsSaving(false);
422
- }
423
- };
424
431
  const handleKeyDown = (event) => {
425
432
  const isUndoShortcut = import_keycodes.isKeyboardEvent.primary(event, "z");
426
433
  const isRedoShortcut = import_keycodes.isKeyboardEvent.primaryShift(event, "z") || !(0, import_keycodes.isAppleOS)() && import_keycodes.isKeyboardEvent.primary(event, "y");
@@ -457,7 +464,7 @@ function MediaEditorContent({
457
464
  import_notices.SnackbarNotices,
458
465
  {
459
466
  className: noticesClassName,
460
- context: NOTICES_CONTEXT
467
+ context: import_use_save_media_editor.MEDIA_EDITOR_NOTICES_CONTEXT
461
468
  }
462
469
  );
463
470
  const children = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
@@ -475,34 +482,17 @@ function MediaEditorContent({
475
482
  className: "media-editor__skeleton",
476
483
  labels: {
477
484
  body: isImage ? (0, import_i18n.__)("Image editor") : (0, import_i18n.__)("Media preview"),
478
- sidebar: (0, import_i18n.__)("Media details"),
479
- footer: (0, import_i18n.__)("Image editing tools")
485
+ sidebar: (0, import_i18n.__)("Media details")
480
486
  },
481
487
  content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor__canvas", children: isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
482
488
  import_media_editor_canvas.default,
483
489
  {
484
- aspectRatio: (0, import_media_editor_crop_panel.resolveAspectRatio)(
485
- aspectRatioValue,
486
- imageAspectRatio
487
- ),
488
- freeformCrop,
489
490
  focusOnMount: true,
490
491
  isPlacementActive,
491
492
  onGestureStart: handleCanvasGestureStart,
492
493
  onGestureEnd: handleCanvasGestureEnd
493
494
  }
494
495
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_preview.default, {}) }),
495
- footer: isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
496
- import_media_editor_toolbar.default,
497
- {
498
- onReset: () => {
499
- setAspectRatioValue("0");
500
- setFreeformCrop(true);
501
- },
502
- onPlacementControlInteraction: signalPlacementControlInteraction,
503
- isUndoRedoDisabled: isCropInteractionActive
504
- }
505
- ) : void 0,
506
496
  sidebar: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_interface.ComplementaryArea.Slot, { scope: "media-editor" })
507
497
  }
508
498
  )
@@ -527,20 +517,72 @@ function MediaEditorContent({
527
517
  ]
528
518
  }
529
519
  );
520
+ const history = isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
521
+ HistoryActions,
522
+ {
523
+ isUndoRedoDisabled: isCropInteractionActive,
524
+ onReset: resetCropOptions
525
+ }
526
+ ) : null;
527
+ const ruler = isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
528
+ import_media_editor_fine_rotation.default,
529
+ {
530
+ onPlacementControlInteraction: signalPlacementControlInteraction
531
+ }
532
+ ) : null;
533
+ const transform = isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor_transform_controls.default, {}) : null;
534
+ const actions = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
535
+ FooterActions,
536
+ {
537
+ isSaving,
538
+ hasMedia: !!media,
539
+ hasChanges,
540
+ onCancel: handleRequestClose,
541
+ onSave: saveMediaEditor
542
+ }
543
+ );
544
+ let footerActions;
545
+ if (footerLayout === "wide") {
546
+ footerActions = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
547
+ history,
548
+ isImage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-modal__footer-toolbar", children: [
549
+ ruler,
550
+ transform
551
+ ] }),
552
+ actions
553
+ ] });
554
+ } else if (footerLayout === "medium") {
555
+ footerActions = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
556
+ ruler,
557
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-modal__footer-row", children: [
558
+ history,
559
+ transform,
560
+ actions
561
+ ] })
562
+ ] });
563
+ } else {
564
+ footerActions = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
565
+ ruler,
566
+ transform,
567
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-modal__footer-row", children: [
568
+ history,
569
+ actions
570
+ ] })
571
+ ] });
572
+ }
530
573
  return renderFrame({
531
574
  children,
532
575
  headerActions: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
533
576
  HeaderActions,
534
577
  {
535
578
  isSaving,
536
- hasMedia: !!media,
537
- hasChanges,
538
579
  isImage,
539
580
  showCloseButton,
540
- onCancel: handleRequestClose,
541
- onSave: handleSave
581
+ onCancel: handleRequestClose
542
582
  }
543
583
  ),
584
+ footerActions,
585
+ footerLayout,
544
586
  onRequestClose: handleRequestClose,
545
587
  onKeyDown: handleKeyDown,
546
588
  shouldCloseOnClickOutside: !hasChanges && !isSaving,
@@ -550,7 +592,7 @@ function MediaEditorContent({
550
592
  });
551
593
  }
552
594
  function MediaEditor(props) {
553
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image_editor.CropperProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorContent, { ...props }) }, props.id);
595
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_state.MediaEditorStateProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorContent, { ...props }) }, props.id);
554
596
  }
555
597
  var media_editor_default = MediaEditor;
556
598
  // Annotate the CommonJS export names for ESM import in node: