@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
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/state/index.ts
21
+ var state_exports = {};
22
+ __export(state_exports, {
23
+ DEFAULT_CROP_OPTIONS: () => import_types.DEFAULT_CROP_OPTIONS,
24
+ MediaEditorStateProvider: () => import_media_editor_state_provider.MediaEditorStateProvider,
25
+ areMediaEditorStatesEqual: () => import_composite_reducer.areMediaEditorStatesEqual,
26
+ buildInitialMediaEditorState: () => import_composite_reducer.buildInitialMediaEditorState,
27
+ mediaEditorReducer: () => import_composite_reducer.mediaEditorReducer,
28
+ resolveAspectRatio: () => import_use_media_editor_state.resolveAspectRatio,
29
+ useMediaEditor: () => import_media_editor_state_provider.useMediaEditor,
30
+ useMediaEditorState: () => import_use_media_editor_state.useMediaEditorState
31
+ });
32
+ module.exports = __toCommonJS(state_exports);
33
+ var import_use_media_editor_state = require("./use-media-editor-state.cjs");
34
+ var import_media_editor_state_provider = require("./media-editor-state-provider.cjs");
35
+ var import_composite_reducer = require("./composite-reducer.cjs");
36
+ var import_types = require("./types.cjs");
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ DEFAULT_CROP_OPTIONS,
40
+ MediaEditorStateProvider,
41
+ areMediaEditorStatesEqual,
42
+ buildInitialMediaEditorState,
43
+ mediaEditorReducer,
44
+ resolveAspectRatio,
45
+ useMediaEditor,
46
+ useMediaEditorState
47
+ });
48
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/state/index.ts"],
4
+ "sourcesContent": ["export {\n\tuseMediaEditorState,\n\tresolveAspectRatio,\n} from './use-media-editor-state';\nexport type { MediaEditorController } from './use-media-editor-state';\nexport {\n\tMediaEditorStateProvider,\n\tuseMediaEditor,\n} from './media-editor-state-provider';\nexport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nexport { DEFAULT_CROP_OPTIONS } from './types';\nexport type {\n\tCropOptionsSlice,\n\tMediaEditorState,\n\tMediaEditorAction,\n} from './types';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAGO;AAEP,yCAGO;AACP,+BAIO;AACP,mBAAqC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/state/media-editor-state-provider.tsx
21
+ var media_editor_state_provider_exports = {};
22
+ __export(media_editor_state_provider_exports, {
23
+ MediaEditorStateProvider: () => MediaEditorStateProvider,
24
+ useMediaEditor: () => useMediaEditor
25
+ });
26
+ module.exports = __toCommonJS(media_editor_state_provider_exports);
27
+ var import_element = require("@wordpress/element");
28
+ var import_use_media_editor_state = require("./use-media-editor-state.cjs");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
30
+ var MediaEditorStateContext = (0, import_element.createContext)(
31
+ null
32
+ );
33
+ function MediaEditorStateProvider({
34
+ initialCropperState,
35
+ initialCropOptions,
36
+ children
37
+ }) {
38
+ const controller = (0, import_use_media_editor_state.useMediaEditorState)({
39
+ cropper: initialCropperState,
40
+ cropOptions: initialCropOptions
41
+ });
42
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorStateContext.Provider, { value: controller, children });
43
+ }
44
+ function useMediaEditor() {
45
+ const context = (0, import_element.useContext)(MediaEditorStateContext);
46
+ if (!context) {
47
+ throw new Error(
48
+ "useMediaEditor must be used within a MediaEditorStateProvider."
49
+ );
50
+ }
51
+ return context;
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ MediaEditorStateProvider,
56
+ useMediaEditor
57
+ });
58
+ //# sourceMappingURL=media-editor-state-provider.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/state/media-editor-state-provider.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState } from '../image-editor';\nimport {\n\tuseMediaEditorState,\n\ttype MediaEditorController,\n} from './use-media-editor-state';\nimport type { CropOptionsSlice } from './types';\n\nconst MediaEditorStateContext = createContext< MediaEditorController | null >(\n\tnull\n);\n\ninterface MediaEditorStateProviderProps {\n\t/** Optional cropper-slice initial state. */\n\tinitialCropperState?: Partial< CropperState >;\n\t/** Optional cropOptions-slice initial state. */\n\tinitialCropOptions?: Partial< CropOptionsSlice >;\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Provider that vends the composite media-editor controller via\n * context. Wrap the media editor in this so every consumer\n * (canvas, toolbar, sidebar) reads from the same store.\n *\n * @param props\n * @param props.initialCropperState\n * @param props.initialCropOptions\n * @param props.children\n */\nexport function MediaEditorStateProvider( {\n\tinitialCropperState,\n\tinitialCropOptions,\n\tchildren,\n}: MediaEditorStateProviderProps ) {\n\tconst controller = useMediaEditorState( {\n\t\tcropper: initialCropperState,\n\t\tcropOptions: initialCropOptions,\n\t} );\n\n\treturn (\n\t\t<MediaEditorStateContext.Provider value={ controller }>\n\t\t\t{ children }\n\t\t</MediaEditorStateContext.Provider>\n\t);\n}\n\n/**\n * Consume the composite media-editor controller. Throws if used\n * outside a `<MediaEditorStateProvider>`.\n *\n * @return The composite controller.\n */\nexport function useMediaEditor(): MediaEditorController {\n\tconst context = useContext( MediaEditorStateContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditor must be used within a MediaEditorStateProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0C;AAM1C,oCAGO;AAqCL;AAlCF,IAAM,8BAA0B;AAAA,EAC/B;AACD;AAqBO,SAAS,yBAA0B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,iBAAa,mDAAqB;AAAA,IACvC,SAAS;AAAA,IACT,aAAa;AAAA,EACd,CAAE;AAEF,SACC,4CAAC,wBAAwB,UAAxB,EAAiC,OAAQ,YACvC,UACH;AAEF;AAQO,SAAS,iBAAwC;AACvD,QAAM,cAAU,2BAAY,uBAAwB;AACpD,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/state/types.ts
21
+ var types_exports = {};
22
+ __export(types_exports, {
23
+ DEFAULT_CROP_OPTIONS: () => DEFAULT_CROP_OPTIONS
24
+ });
25
+ module.exports = __toCommonJS(types_exports);
26
+ var DEFAULT_CROP_OPTIONS = {
27
+ aspectRatioValue: "0"
28
+ };
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ DEFAULT_CROP_OPTIONS
32
+ });
33
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/state/types.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tCropperAction,\n\tCropperState,\n\tNormalizedRect,\n\tSize,\n} from '../image-editor';\n\n/**\n * Sidebar control state for the cropper. Lives in the composite store\n * so it participates in the same undo history as cropper geometry.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * Default values for the crop-options slice. Mirrors the initial state\n * used by the sidebar before the user has touched anything.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * The full composite state for the media editor \u2014 cropper geometry\n * plus the sidebar control slice. Future feature slices (text\n * overlays, filters, \u2026) extend this object.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\tcropper: CropperState;\n\tcropOptions: CropOptionsSlice;\n}\n\n/**\n * Composite reducer action union.\n *\n * Cropper geometry actions are wrapped in a `CROPPER` envelope and\n * delegated to the pure `cropperReducer`. Sidebar and history\n * concerns are first-class actions on this reducer.\n */\nexport type MediaEditorAction =\n\t/**\n\t * Delegate to the underlying cropper reducer. Used for every\n\t * geometry transition (pan / zoom / rotation / flip / cropRect /\n\t * settle / etc.).\n\t */\n\t| {\n\t\t\ttype: 'CROPPER';\n\t\t\taction: CropperAction;\n\t }\n\t/**\n\t * Set the aspect-ratio preset. Atomically updates the preset key\n\t * and the cropRect (computed from the resolved ratio and the\n\t * current visualSize). One transaction = one undo entry.\n\t */\n\t| {\n\t\t\ttype: 'SET_ASPECT_RATIO_VALUE';\n\t\t\tpayload: {\n\t\t\t\t/** Preset key as it appears in the dropdown. */\n\t\t\t\tpresetKey: string;\n\t\t\t\t/**\n\t\t\t\t * Resolved width/height ratio. `undefined` = Free\n\t\t\t\t * (no lock; cropRect stays where it is).\n\t\t\t\t */\n\t\t\t\tresolved: number | undefined;\n\t\t\t\t/**\n\t\t\t\t * Rendered image size used to compute the inscribed\n\t\t\t\t * rect. Caller supplies it because the reducer is\n\t\t\t\t * framework-agnostic and has no DOM access.\n\t\t\t\t */\n\t\t\t\tvisualSize: Size;\n\t\t\t};\n\t }\n\t/** Reset cropOptions to defaults. */\n\t| { type: 'RESET_CROP_OPTIONS' }\n\t/**\n\t * Replace the entire composite state with `payload`. Used by\n\t * undo/redo to restore a full snapshot atomically.\n\t */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState }\n\t/**\n\t * Adjust the cropper's cropRect in response to a viewport change\n\t * (e.g., window resize). Behaviorally identical to a `CROPPER\n\t * SET_CROP_RECT` dispatch, but tagged so the hook layer can skip\n\t * history recording \u2014 viewport reshapes aren't editor actions.\n\t */\n\t| {\n\t\t\ttype: 'VIEWPORT_ADJUST_CROP_RECT';\n\t\t\tpayload: NormalizedRect;\n\t };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BO,IAAM,uBAAyC;AAAA,EACrD,kBAAkB;AACnB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/state/use-media-editor-state.ts
21
+ var use_media_editor_state_exports = {};
22
+ __export(use_media_editor_state_exports, {
23
+ resolveAspectRatio: () => resolveAspectRatio,
24
+ useMediaEditorState: () => useMediaEditorState
25
+ });
26
+ module.exports = __toCommonJS(use_media_editor_state_exports);
27
+ var import_element = require("@wordpress/element");
28
+ var import_image_editor = require("../image-editor/index.cjs");
29
+ var import_composite_reducer = require("./composite-reducer.cjs");
30
+ function resolveAspectRatio(presetKey, cropperImage) {
31
+ const num = parseFloat(presetKey);
32
+ if (num === 0 || Number.isNaN(num)) {
33
+ return void 0;
34
+ }
35
+ if (num === import_image_editor.ORIGINAL_ASPECT_RATIO) {
36
+ if (cropperImage && cropperImage.naturalWidth > 0 && cropperImage.naturalHeight > 0) {
37
+ return cropperImage.naturalWidth / cropperImage.naturalHeight;
38
+ }
39
+ return void 0;
40
+ }
41
+ if (num > 0) {
42
+ return num;
43
+ }
44
+ return void 0;
45
+ }
46
+ function areCropperImagesEqual(a, b) {
47
+ return a?.src === b?.src && a?.naturalWidth === b?.naturalWidth && a?.naturalHeight === b?.naturalHeight;
48
+ }
49
+ function useMediaEditorState(initialState) {
50
+ const [state, dispatch] = (0, import_element.useReducer)(
51
+ import_composite_reducer.mediaEditorReducer,
52
+ null,
53
+ () => (0, import_composite_reducer.buildInitialMediaEditorState)(
54
+ (0, import_image_editor.enforceContainment)({
55
+ ...import_image_editor.DEFAULT_STATE,
56
+ ...initialState?.cropper
57
+ }),
58
+ initialState?.cropOptions
59
+ )
60
+ );
61
+ const [initialBaseline, setInitialBaseline] = (0, import_element.useState)(() => state);
62
+ const stateRef = (0, import_element.useRef)(state);
63
+ const visualSizeRef = (0, import_element.useRef)({ width: 0, height: 0 });
64
+ const historyRef = (0, import_element.useRef)([]);
65
+ const redoStackRef = (0, import_element.useRef)([]);
66
+ const [hasUndo, setHasUndo] = (0, import_element.useState)(false);
67
+ const [hasRedo, setHasRedo] = (0, import_element.useState)(false);
68
+ const isGestureOpenRef = (0, import_element.useRef)(false);
69
+ const gestureSnapshotRef = (0, import_element.useRef)(null);
70
+ const pushSnapshot = (0, import_element.useCallback)((snapshot) => {
71
+ const last = historyRef.current[historyRef.current.length - 1];
72
+ if (last && (0, import_composite_reducer.areMediaEditorStatesEqual)(last, snapshot)) {
73
+ return;
74
+ }
75
+ historyRef.current = [...historyRef.current, snapshot];
76
+ redoStackRef.current = [];
77
+ setHasUndo(true);
78
+ setHasRedo(false);
79
+ }, []);
80
+ const dispatchWithHistory = (0, import_element.useCallback)(
81
+ (action, recordHistory = true) => {
82
+ const preState = stateRef.current;
83
+ const postState = (0, import_composite_reducer.mediaEditorReducer)(preState, action);
84
+ if (recordHistory) {
85
+ if (!(0, import_composite_reducer.areMediaEditorStatesEqual)(preState, postState)) {
86
+ if (isGestureOpenRef.current) {
87
+ if (gestureSnapshotRef.current === null) {
88
+ gestureSnapshotRef.current = preState;
89
+ }
90
+ } else {
91
+ pushSnapshot(preState);
92
+ }
93
+ }
94
+ }
95
+ stateRef.current = postState;
96
+ dispatch(action);
97
+ },
98
+ [pushSnapshot]
99
+ );
100
+ const beginGesture = (0, import_element.useCallback)(() => {
101
+ if (isGestureOpenRef.current) {
102
+ return;
103
+ }
104
+ isGestureOpenRef.current = true;
105
+ gestureSnapshotRef.current = null;
106
+ }, []);
107
+ const endGesture = (0, import_element.useCallback)(() => {
108
+ const snapshot = gestureSnapshotRef.current;
109
+ if (snapshot && !(0, import_composite_reducer.areMediaEditorStatesEqual)(snapshot, stateRef.current)) {
110
+ pushSnapshot(snapshot);
111
+ }
112
+ gestureSnapshotRef.current = null;
113
+ isGestureOpenRef.current = false;
114
+ }, [pushSnapshot]);
115
+ const dispatchCropperAction = (0, import_element.useCallback)(
116
+ (action) => {
117
+ dispatchWithHistory({ type: "CROPPER", action });
118
+ },
119
+ [dispatchWithHistory]
120
+ );
121
+ const cropperSetters = (0, import_element.useMemo)(
122
+ () => (0, import_image_editor.buildCropperSetters)(
123
+ dispatchCropperAction,
124
+ () => stateRef.current.cropper
125
+ ),
126
+ [dispatchCropperAction]
127
+ );
128
+ const setImage = (0, import_element.useCallback)((image) => {
129
+ if (areCropperImagesEqual(stateRef.current.cropper.image, image)) {
130
+ return;
131
+ }
132
+ const action = {
133
+ type: "CROPPER",
134
+ action: { type: "SET_IMAGE", payload: image }
135
+ };
136
+ const next = (0, import_composite_reducer.mediaEditorReducer)(stateRef.current, action);
137
+ stateRef.current = next;
138
+ dispatch(action);
139
+ setInitialBaseline(next);
140
+ isGestureOpenRef.current = false;
141
+ gestureSnapshotRef.current = null;
142
+ historyRef.current = [];
143
+ redoStackRef.current = [];
144
+ setHasUndo(false);
145
+ setHasRedo(false);
146
+ }, []);
147
+ const reset = (0, import_element.useCallback)(
148
+ (resetState) => {
149
+ dispatchWithHistory({
150
+ type: "CROPPER",
151
+ action: { type: "RESET", payload: resetState }
152
+ });
153
+ },
154
+ [dispatchWithHistory]
155
+ );
156
+ const setAspectRatioValue = (0, import_element.useCallback)(
157
+ (presetKey) => {
158
+ const resolved = resolveAspectRatio(
159
+ presetKey,
160
+ stateRef.current.cropper.image
161
+ );
162
+ dispatchWithHistory({
163
+ type: "SET_ASPECT_RATIO_VALUE",
164
+ payload: {
165
+ presetKey,
166
+ resolved,
167
+ visualSize: visualSizeRef.current
168
+ }
169
+ });
170
+ },
171
+ [dispatchWithHistory]
172
+ );
173
+ const resetCropOptions = (0, import_element.useCallback)(() => {
174
+ dispatchWithHistory({ type: "RESET_CROP_OPTIONS" });
175
+ }, [dispatchWithHistory]);
176
+ const undo = (0, import_element.useCallback)(() => {
177
+ endGesture();
178
+ const prev = historyRef.current[historyRef.current.length - 1];
179
+ if (!prev) {
180
+ return;
181
+ }
182
+ redoStackRef.current = [stateRef.current, ...redoStackRef.current];
183
+ historyRef.current = historyRef.current.slice(0, -1);
184
+ setHasUndo(historyRef.current.length > 0);
185
+ setHasRedo(true);
186
+ stateRef.current = prev;
187
+ dispatch({ type: "RESTORE_SNAPSHOT", payload: prev });
188
+ }, [endGesture]);
189
+ const redo = (0, import_element.useCallback)(() => {
190
+ endGesture();
191
+ const next = redoStackRef.current[0];
192
+ if (!next) {
193
+ return;
194
+ }
195
+ historyRef.current = [...historyRef.current, stateRef.current];
196
+ redoStackRef.current = redoStackRef.current.slice(1);
197
+ setHasUndo(true);
198
+ setHasRedo(redoStackRef.current.length > 0);
199
+ stateRef.current = next;
200
+ dispatch({ type: "RESTORE_SNAPSHOT", payload: next });
201
+ }, [endGesture]);
202
+ const setVisualSize = (0, import_element.useCallback)((size) => {
203
+ visualSizeRef.current = size;
204
+ }, []);
205
+ const adjustCropRectForViewport = (0, import_element.useCallback)(
206
+ (rect) => {
207
+ dispatchWithHistory(
208
+ { type: "VIEWPORT_ADJUST_CROP_RECT", payload: rect },
209
+ false
210
+ );
211
+ },
212
+ [dispatchWithHistory]
213
+ );
214
+ const isDirty = !(0, import_composite_reducer.areMediaEditorStatesEqual)(state, initialBaseline);
215
+ const isCropperDirty = !(0, import_image_editor.areCropperStatesEqual)(
216
+ state.cropper,
217
+ initialBaseline.cropper
218
+ );
219
+ const getCroppedImage = (0, import_element.useCallback)(
220
+ (mimeType, quality) => {
221
+ if (!state.cropper.image) {
222
+ return Promise.reject(
223
+ new Error("No image loaded \u2014 call setImage first.")
224
+ );
225
+ }
226
+ return (0, import_image_editor.exportCroppedImage)(
227
+ state.cropper.image.src,
228
+ state.cropper,
229
+ mimeType,
230
+ quality
231
+ );
232
+ },
233
+ [state.cropper]
234
+ );
235
+ const controller = (0, import_element.useMemo)(
236
+ () => ({
237
+ // CropperController surface (state is the cropper slice so a
238
+ // <Cropper> takes this controller as-is).
239
+ ...cropperSetters,
240
+ state: state.cropper,
241
+ setImage,
242
+ reset,
243
+ isDirty,
244
+ getCroppedImage,
245
+ // Composite extensions
246
+ cropOptions: state.cropOptions,
247
+ setAspectRatioValue,
248
+ resetCropOptions,
249
+ isCropperDirty,
250
+ hasUndo,
251
+ hasRedo,
252
+ undo,
253
+ redo,
254
+ beginGesture,
255
+ endGesture,
256
+ setVisualSize,
257
+ adjustCropRectForViewport
258
+ }),
259
+ [
260
+ cropperSetters,
261
+ state.cropper,
262
+ setImage,
263
+ reset,
264
+ isDirty,
265
+ getCroppedImage,
266
+ state.cropOptions,
267
+ setAspectRatioValue,
268
+ resetCropOptions,
269
+ isCropperDirty,
270
+ hasUndo,
271
+ hasRedo,
272
+ undo,
273
+ redo,
274
+ beginGesture,
275
+ endGesture,
276
+ setVisualSize,
277
+ adjustCropRectForViewport
278
+ ]
279
+ );
280
+ return controller;
281
+ }
282
+ // Annotate the CommonJS export names for ESM import in node:
283
+ 0 && (module.exports = {
284
+ resolveAspectRatio,
285
+ useMediaEditorState
286
+ });
287
+ //# sourceMappingURL=use-media-editor-state.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/state/use-media-editor-state.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tDEFAULT_STATE,\n\tORIGINAL_ASPECT_RATIO,\n\tareCropperStatesEqual,\n\tbuildCropperSetters,\n\tenforceContainment,\n\texportCroppedImage,\n\ttype CropperAction,\n\ttype CropperController,\n\ttype CropperState,\n\ttype NormalizedRect,\n\ttype Size,\n} from '../image-editor';\nimport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nimport type {\n\tCropOptionsSlice,\n\tMediaEditorAction,\n\tMediaEditorState,\n} from './types';\n\n/**\n * Resolve an aspect-ratio preset value (the string the dropdown\n * round-trips) into a numeric width/height ratio for the cropper.\n *\n * - `'0'` \u2192 `undefined` (Free; no lock)\n * - `'-1'` (Original) \u2192 image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal \u2192 the parsed number.\n *\n * Centralizing here means the dropdown, the action dispatcher, and\n * the test harness all resolve the same way.\n *\n * @param presetKey Preset value from the dropdown.\n * @param cropperImage The cropper's loaded image, or `null`.\n * @return The resolved ratio, or `undefined` for Free / unresolvable.\n */\nexport function resolveAspectRatio(\n\tpresetKey: string,\n\tcropperImage: CropperState[ 'image' ] | null\n): number | undefined {\n\tconst num = parseFloat( presetKey );\n\tif ( num === 0 || Number.isNaN( num ) ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO ) {\n\t\tif (\n\t\t\tcropperImage &&\n\t\t\tcropperImage.naturalWidth > 0 &&\n\t\t\tcropperImage.naturalHeight > 0\n\t\t) {\n\t\t\treturn cropperImage.naturalWidth / cropperImage.naturalHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * The composite controller exposed by `useMediaEditorState`.\n *\n * Satisfies `CropperController` (so a `<Cropper>` can take this\n * controller directly via the `controller` prop) and adds slice\n * setters, undo/redo, gesture boundaries, and viewport reporting.\n */\nexport interface MediaEditorController extends CropperController {\n\t/** The cropOptions slice. */\n\tcropOptions: CropOptionsSlice;\n\t/** Set the aspect-ratio preset. Atomic with the cropRect reshape. */\n\tsetAspectRatioValue: ( presetKey: string ) => void;\n\t/** Reset cropOptions to defaults. */\n\tresetCropOptions: () => void;\n\t/**\n\t * Whether the cropper geometry differs from the initial baseline.\n\t */\n\tisCropperDirty: boolean;\n\t/** Whether there's an undoable change in history. */\n\thasUndo: boolean;\n\t/** Whether there's a redoable change in history. */\n\thasRedo: boolean;\n\t/** Undo the last committed action across all slices. */\n\tundo: () => void;\n\t/** Redo the last undone action across all slices. */\n\tredo: () => void;\n\t/**\n\t * Open a gesture boundary. During a gesture all state-changing\n\t * actions coalesce into one undo entry \u2014 the snapshot taken at\n\t * `beginGesture`. Pair with `endGesture` on pointer-up / key-up.\n\t */\n\tbeginGesture: () => void;\n\t/** Close a gesture boundary and commit the pre-gesture snapshot. */\n\tendGesture: () => void;\n\t/**\n\t * Report the current rendered image size to the controller. The\n\t * Cropper component calls this whenever its visualSize changes;\n\t * the controller needs it to compute aspect-ratio reshapes.\n\t */\n\tsetVisualSize: ( size: Size ) => void;\n\t/**\n\t * Reshape the cropRect in response to a viewport change. Behaves\n\t * like `setCropRect` but does NOT record an undo entry \u2014 window\n\t * resizes aren't editor actions.\n\t */\n\tadjustCropRectForViewport: ( rect: NormalizedRect ) => void;\n}\n\ninterface InitialMediaEditorState {\n\tcropper?: Partial< CropperState >;\n\tcropOptions?: Partial< CropOptionsSlice >;\n}\n\n/**\n * Composite store for the media editor.\n *\n * Owns the only undo/redo history for the editor. Cropper geometry\n * actions and sidebar cropOptions actions flow through the same\n * reducer and the same history stack.\n *\n * History semantics:\n * - Each action's pre-state is pushed to the undo stack before the\n * action commits, unless a gesture is open or the action is a\n * no-op (post-state value-equal to pre-state).\n * - During a gesture (`beginGesture` \u2192 `endGesture`) all mutations\n * coalesce: only the pre-gesture snapshot is pushed, at gesture\n * end. Any pending gesture is flushed on undo/redo.\n * - Viewport-driven cropRect reshapes (window resize) use a\n * dedicated non-recording dispatch path so they never produce\n * undo entries.\n *\n * `isDirty` tracks the full editor session, including undoable UI\n * state. Use `isCropperDirty` when deciding whether the image output\n * needs saving.\n *\n * @param initialState Optional seed for the cropper and cropOptions slices.\n * @return The composite controller.\n */\nexport function useMediaEditorState(\n\tinitialState?: InitialMediaEditorState\n): MediaEditorController {\n\tconst [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>\n\t\tbuildInitialMediaEditorState(\n\t\t\tenforceContainment( {\n\t\t\t\t...DEFAULT_STATE,\n\t\t\t\t...initialState?.cropper,\n\t\t\t} ),\n\t\t\tinitialState?.cropOptions\n\t\t)\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setImage` refreshes this when\n\t// a new image establishes a fresh baseline.\n\tconst [ initialBaseline, setInitialBaseline ] =\n\t\tuseState< MediaEditorState >( () => state );\n\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, dispatch wrapper). Every mutation path\n\t// (`dispatchWithHistory`, `setImage`, `undo`, `redo`) writes this\n\t// synchronously, so multiple actions in one event see the latest\n\t// reducer output before React commits.\n\tconst stateRef = useRef( state );\n\tconst visualSizeRef = useRef< Size >( { width: 0, height: 0 } );\n\n\t// History stacks: full composite snapshots. Refs avoid re-renders\n\t// on every push; a boolean state pair drives the enabled/disabled\n\t// indicators for undo/redo buttons.\n\tconst historyRef = useRef< MediaEditorState[] >( [] );\n\tconst redoStackRef = useRef< MediaEditorState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Gesture state. While open, the first non-no-op action captures\n\t// the pre-gesture snapshot; subsequent actions don't push.\n\t// `endGesture` pushes the captured snapshot (or nothing, if the\n\t// gesture produced no changes).\n\tconst isGestureOpenRef = useRef( false );\n\tconst gestureSnapshotRef = useRef< MediaEditorState | null >( null );\n\n\tconst pushSnapshot = useCallback( ( snapshot: MediaEditorState ) => {\n\t\tconst last = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( last && areMediaEditorStatesEqual( last, snapshot ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, snapshot ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\t// Core dispatch wrapper. Synchronously computes the post-state via\n\t// the pure reducer so we can skip history pushes for no-op actions\n\t// and keep `stateRef` in lockstep with React's pending state.\n\tconst dispatchWithHistory = useCallback(\n\t\t( action: MediaEditorAction, recordHistory = true ) => {\n\t\t\tconst preState = stateRef.current;\n\t\t\tconst postState = mediaEditorReducer( preState, action );\n\t\t\tif ( recordHistory ) {\n\t\t\t\tif ( ! areMediaEditorStatesEqual( preState, postState ) ) {\n\t\t\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\t\t\tif ( gestureSnapshotRef.current === null ) {\n\t\t\t\t\t\t\tgestureSnapshotRef.current = preState;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpushSnapshot( preState );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tstateRef.current = postState;\n\t\t\tdispatch( action );\n\t\t},\n\t\t[ pushSnapshot ]\n\t);\n\n\tconst beginGesture = useCallback( () => {\n\t\tif ( isGestureOpenRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tisGestureOpenRef.current = true;\n\t\tgestureSnapshotRef.current = null;\n\t}, [] );\n\n\t// Close a gesture (or flush a pending one before undo/redo).\n\t// Pushes the pre-gesture snapshot only if it differs from current\n\t// state. Safe to call when no gesture is open.\n\tconst endGesture = useCallback( () => {\n\t\tconst snapshot = gestureSnapshotRef.current;\n\t\tif (\n\t\t\tsnapshot &&\n\t\t\t! areMediaEditorStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushSnapshot( snapshot );\n\t\t}\n\t\tgestureSnapshotRef.current = null;\n\t\tisGestureOpenRef.current = false;\n\t}, [ pushSnapshot ] );\n\n\t// =====================================================================\n\t// Cropper-slice setters (built from the shared factory so the pure\n\t// hook and this composite stay in lockstep \u2014 add a setter in\n\t// `buildCropperSetters` once and both hooks get it).\n\t// =====================================================================\n\n\tconst dispatchCropperAction = useCallback(\n\t\t( action: CropperAction ) => {\n\t\t\tdispatchWithHistory( { type: 'CROPPER', action } );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst cropperSetters = useMemo(\n\t\t() =>\n\t\t\tbuildCropperSetters(\n\t\t\t\tdispatchCropperAction,\n\t\t\t\t() => stateRef.current.cropper\n\t\t\t),\n\t\t[ dispatchCropperAction ]\n\t);\n\n\tconst setImage = useCallback( ( image: CropperState[ 'image' ] ) => {\n\t\tif ( areCropperImagesEqual( stateRef.current.cropper.image, image ) ) {\n\t\t\treturn;\n\t\t}\n\t\t// New image = fresh canvas: clear history, refresh the\n\t\t// initial snapshot so isDirty starts at false.\n\t\tconst action = {\n\t\t\ttype: 'CROPPER' as const,\n\t\t\taction: { type: 'SET_IMAGE' as const, payload: image },\n\t\t};\n\t\tconst next = mediaEditorReducer( stateRef.current, action );\n\t\tstateRef.current = next;\n\t\tdispatch( action );\n\t\tsetInitialBaseline( next );\n\t\tisGestureOpenRef.current = false;\n\t\tgestureSnapshotRef.current = null;\n\t\thistoryRef.current = [];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( false );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'CROPPER',\n\t\t\t\taction: { type: 'RESET', payload: resetState },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// CropOptions-slice setters\n\t// =====================================================================\n\n\tconst setAspectRatioValue = useCallback(\n\t\t( presetKey: string ) => {\n\t\t\tconst resolved = resolveAspectRatio(\n\t\t\t\tpresetKey,\n\t\t\t\tstateRef.current.cropper.image\n\t\t\t);\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_ASPECT_RATIO_VALUE',\n\t\t\t\tpayload: {\n\t\t\t\t\tpresetKey,\n\t\t\t\t\tresolved,\n\t\t\t\t\tvisualSize: visualSizeRef.current,\n\t\t\t\t},\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst resetCropOptions = useCallback( () => {\n\t\tdispatchWithHistory( { type: 'RESET_CROP_OPTIONS' } );\n\t}, [ dispatchWithHistory ] );\n\n\t// =====================================================================\n\t// History\n\t// =====================================================================\n\n\tconst undo = useCallback( () => {\n\t\tendGesture();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tstateRef.current = prev;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: prev } );\n\t}, [ endGesture ] );\n\n\tconst redo = useCallback( () => {\n\t\tendGesture();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t}, [ endGesture ] );\n\n\t// =====================================================================\n\t// Viewport\n\t// =====================================================================\n\n\tconst setVisualSize = useCallback( ( size: Size ) => {\n\t\tvisualSizeRef.current = size;\n\t}, [] );\n\n\tconst adjustCropRectForViewport = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatchWithHistory(\n\t\t\t\t{ type: 'VIEWPORT_ADJUST_CROP_RECT', payload: rect },\n\t\t\t\tfalse\n\t\t\t);\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// Derived\n\t// =====================================================================\n\n\tconst isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );\n\tconst isCropperDirty = ! areCropperStatesEqual(\n\t\tstate.cropper,\n\t\tinitialBaseline.cropper\n\t);\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.cropper.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded \u2014 call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.cropper.image.src,\n\t\t\t\tstate.cropper,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state.cropper ]\n\t);\n\n\tconst controller = useMemo< MediaEditorController >(\n\t\t() => ( {\n\t\t\t// CropperController surface (state is the cropper slice so a\n\t\t\t// <Cropper> takes this controller as-is).\n\t\t\t...cropperSetters,\n\t\t\tstate: state.cropper,\n\t\t\tsetImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\tgetCroppedImage,\n\t\t\t// Composite extensions\n\t\t\tcropOptions: state.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tresetCropOptions,\n\t\t\tisCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t} ),\n\t\t[\n\t\t\tcropperSetters,\n\t\t\tstate.cropper,\n\t\t\tsetImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\tgetCroppedImage,\n\t\t\tstate.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tresetCropOptions,\n\t\t\tisCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t]\n\t);\n\treturn controller;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAMO;AAKP,0BAYO;AACP,+BAIO;AAuBA,SAAS,mBACf,WACA,cACqB;AACrB,QAAM,MAAM,WAAY,SAAU;AAClC,MAAK,QAAQ,KAAK,OAAO,MAAO,GAAI,GAAI;AACvC,WAAO;AAAA,EACR;AACA,MAAK,QAAQ,2CAAwB;AACpC,QACC,gBACA,aAAa,eAAe,KAC5B,aAAa,gBAAgB,GAC5B;AACD,aAAO,aAAa,eAAe,aAAa;AAAA,IACjD;AACA,WAAO;AAAA,EACR;AACA,MAAK,MAAM,GAAI;AACd,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAEA,SAAS,sBACR,GACA,GACU;AACV,SACC,GAAG,QAAQ,GAAG,OACd,GAAG,iBAAiB,GAAG,gBACvB,GAAG,kBAAkB,GAAG;AAE1B;AAgFO,SAAS,oBACf,cACwB;AACxB,QAAM,CAAE,OAAO,QAAS,QAAI;AAAA,IAAY;AAAA,IAAoB;AAAA,IAAM,UACjE;AAAA,UACC,wCAAoB;AAAA,QACnB,GAAG;AAAA,QACH,GAAG,cAAc;AAAA,MAClB,CAAE;AAAA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
6
+ "names": []
7
+ }
@@ -26,12 +26,14 @@ __export(actions_exports, {
26
26
  module.exports = __toCommonJS(actions_exports);
27
27
  function openMediaEditorModal({
28
28
  id,
29
- onUpdate
29
+ onUpdate,
30
+ onClose
30
31
  }) {
31
32
  return {
32
33
  type: "OPEN_MEDIA_EDITOR_MODAL",
33
34
  id,
34
- onUpdate: onUpdate ?? null
35
+ onUpdate: onUpdate ?? null,
36
+ onClose: onClose ?? null
35
37
  };
36
38
  }
37
39
  function closeMediaEditorModal() {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/store/actions.ts"],
4
- "sourcesContent": ["/**\n * Shape passed to `onUpdate` after a successful save. Deliberately normalized\n * and minimal: `url` instead of REST's `source_url`, so consumers can drop\n * it straight into block attributes (matches the legacy `ImageEditor`'s\n * `onSaveImage` shape at\n * `packages/block-editor/src/components/image-editor/use-save-image.js`).\n * Keeping this decoupled from the REST field names also leaves room to reuse\n * the modal outside a WordPress REST context (e.g. native/Electron hosts).\n */\nexport interface MediaEditorModalUpdate {\n\tid: number;\n\turl?: string;\n}\n\ninterface OpenMediaEditorModalArgs {\n\tid: number;\n\tonUpdate?: ( updated: MediaEditorModalUpdate ) => void;\n}\n\nexport function openMediaEditorModal( {\n\tid,\n\tonUpdate,\n}: OpenMediaEditorModalArgs ) {\n\treturn {\n\t\ttype: 'OPEN_MEDIA_EDITOR_MODAL' as const,\n\t\tid,\n\t\tonUpdate: onUpdate ?? null,\n\t};\n}\n\nexport function closeMediaEditorModal() {\n\treturn { type: 'CLOSE_MEDIA_EDITOR_MODAL' as const };\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBO,SAAS,qBAAsB;AAAA,EACrC;AAAA,EACA;AACD,GAA8B;AAC7B,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,UAAU,YAAY;AAAA,EACvB;AACD;AAEO,SAAS,wBAAwB;AACvC,SAAO,EAAE,MAAM,2BAAoC;AACpD;",
4
+ "sourcesContent": ["/**\n * Shape passed to `onUpdate` after a successful save. Deliberately normalized\n * and minimal: `url` instead of REST's `source_url`, so consumers can drop\n * it straight into block attributes (matches the legacy `ImageEditor`'s\n * `onSaveImage` shape at\n * `packages/block-editor/src/components/image-editor/use-save-image.js`).\n * Keeping this decoupled from the REST field names also leaves room to reuse\n * the modal outside a WordPress REST context (e.g. native/Electron hosts).\n */\nexport interface MediaEditorModalUpdate {\n\tid: number;\n\turl?: string;\n}\n\ninterface OpenMediaEditorModalArgs {\n\tid: number;\n\tonUpdate?: ( updated: MediaEditorModalUpdate ) => void;\n\tonClose?: () => void;\n}\n\nexport function openMediaEditorModal( {\n\tid,\n\tonUpdate,\n\tonClose,\n}: OpenMediaEditorModalArgs ) {\n\treturn {\n\t\ttype: 'OPEN_MEDIA_EDITOR_MODAL' as const,\n\t\tid,\n\t\tonUpdate: onUpdate ?? null,\n\t\tonClose: onClose ?? null,\n\t};\n}\n\nexport function closeMediaEditorModal() {\n\treturn { type: 'CLOSE_MEDIA_EDITOR_MODAL' as const };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBO,SAAS,qBAAsB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AACD,GAA8B;AAC7B,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,UAAU,YAAY;AAAA,IACtB,SAAS,WAAW;AAAA,EACrB;AACD;AAEO,SAAS,wBAAwB;AACvC,SAAO,EAAE,MAAM,2BAAoC;AACpD;",
6
6
  "names": []
7
7
  }
@@ -27,16 +27,18 @@ module.exports = __toCommonJS(reducer_exports);
27
27
  var DEFAULT_STATE = {
28
28
  isOpen: false,
29
29
  id: null,
30
- onUpdate: null
30
+ onUpdate: null,
31
+ onClose: null
31
32
  };
32
33
  function reducer(state = DEFAULT_STATE, action) {
33
34
  switch (action.type) {
34
35
  case "OPEN_MEDIA_EDITOR_MODAL": {
35
- const { id, onUpdate } = action;
36
+ const { id, onUpdate, onClose } = action;
36
37
  return {
37
38
  isOpen: true,
38
39
  id,
39
- onUpdate
40
+ onUpdate,
41
+ onClose
40
42
  };
41
43
  }
42
44
  case "CLOSE_MEDIA_EDITOR_MODAL":
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/store/reducer.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { MediaEditorModalUpdate } from './actions';\n\ntype OnUpdateCallback = ( updated: MediaEditorModalUpdate ) => void;\n\nexport interface State {\n\tisOpen: boolean;\n\tid: number | null;\n\tonUpdate: OnUpdateCallback | null;\n}\n\nexport const DEFAULT_STATE: State = {\n\tisOpen: false,\n\tid: null,\n\tonUpdate: null,\n};\n\ntype Action =\n\t| {\n\t\t\ttype: 'OPEN_MEDIA_EDITOR_MODAL';\n\t\t\tid: number;\n\t\t\tonUpdate: OnUpdateCallback | null;\n\t }\n\t| { type: 'CLOSE_MEDIA_EDITOR_MODAL' };\n\nexport default function reducer(\n\tstate: State = DEFAULT_STATE,\n\taction: Action | { type: string }\n): State {\n\tswitch ( action.type ) {\n\t\tcase 'OPEN_MEDIA_EDITOR_MODAL': {\n\t\t\tconst { id, onUpdate } = action as Extract<\n\t\t\t\tAction,\n\t\t\t\t{ type: 'OPEN_MEDIA_EDITOR_MODAL' }\n\t\t\t>;\n\t\t\treturn {\n\t\t\t\tisOpen: true,\n\t\t\t\tid,\n\t\t\t\tonUpdate,\n\t\t\t};\n\t\t}\n\t\tcase 'CLOSE_MEDIA_EDITOR_MODAL':\n\t\t\treturn DEFAULT_STATE;\n\t}\n\treturn state;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,IAAM,gBAAuB;AAAA,EACnC,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AACX;AAUe,SAAR,QACN,QAAe,eACf,QACQ;AACR,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,2BAA2B;AAC/B,YAAM,EAAE,IAAI,SAAS,IAAI;AAIzB,aAAO;AAAA,QACN,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,KAAK;AACJ,aAAO;AAAA,EACT;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { MediaEditorModalUpdate } from './actions';\n\ntype OnUpdateCallback = ( updated: MediaEditorModalUpdate ) => void;\ntype OnCloseCallback = () => void;\n\nexport interface State {\n\tisOpen: boolean;\n\tid: number | null;\n\tonUpdate: OnUpdateCallback | null;\n\tonClose: OnCloseCallback | null;\n}\n\nexport const DEFAULT_STATE: State = {\n\tisOpen: false,\n\tid: null,\n\tonUpdate: null,\n\tonClose: null,\n};\n\ntype Action =\n\t| {\n\t\t\ttype: 'OPEN_MEDIA_EDITOR_MODAL';\n\t\t\tid: number;\n\t\t\tonUpdate: OnUpdateCallback | null;\n\t\t\tonClose: OnCloseCallback | null;\n\t }\n\t| { type: 'CLOSE_MEDIA_EDITOR_MODAL' };\n\nexport default function reducer(\n\tstate: State = DEFAULT_STATE,\n\taction: Action | { type: string }\n): State {\n\tswitch ( action.type ) {\n\t\tcase 'OPEN_MEDIA_EDITOR_MODAL': {\n\t\t\tconst { id, onUpdate, onClose } = action as Extract<\n\t\t\t\tAction,\n\t\t\t\t{ type: 'OPEN_MEDIA_EDITOR_MODAL' }\n\t\t\t>;\n\t\t\treturn {\n\t\t\t\tisOpen: true,\n\t\t\t\tid,\n\t\t\t\tonUpdate,\n\t\t\t\tonClose,\n\t\t\t};\n\t\t}\n\t\tcase 'CLOSE_MEDIA_EDITOR_MODAL':\n\t\t\treturn DEFAULT_STATE;\n\t}\n\treturn state;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,IAAM,gBAAuB;AAAA,EACnC,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,SAAS;AACV;AAWe,SAAR,QACN,QAAe,eACf,QACQ;AACR,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,2BAA2B;AAC/B,YAAM,EAAE,IAAI,UAAU,QAAQ,IAAI;AAIlC,aAAO;AAAA,QACN,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,KAAK;AACJ,aAAO;AAAA,EACT;AACA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var selectors_exports = {};
22
22
  __export(selectors_exports, {
23
23
  getId: () => getId,
24
+ getOnClose: () => getOnClose,
24
25
  getOnUpdate: () => getOnUpdate,
25
26
  isOpen: () => isOpen
26
27
  });
@@ -34,9 +35,13 @@ function getId(state) {
34
35
  function getOnUpdate(state) {
35
36
  return state.onUpdate;
36
37
  }
38
+ function getOnClose(state) {
39
+ return state.onClose;
40
+ }
37
41
  // Annotate the CommonJS export names for ESM import in node:
38
42
  0 && (module.exports = {
39
43
  getId,
44
+ getOnClose,
40
45
  getOnUpdate,
41
46
  isOpen
42
47
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/store/selectors.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { State } from './reducer';\n\nexport function isOpen( state: State ): boolean {\n\treturn state.isOpen;\n}\n\nexport function getId( state: State ): number | null {\n\treturn state.id;\n}\n\nexport function getOnUpdate( state: State ) {\n\treturn state.onUpdate;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,OAAQ,OAAwB;AAC/C,SAAO,MAAM;AACd;AAEO,SAAS,MAAO,OAA8B;AACpD,SAAO,MAAM;AACd;AAEO,SAAS,YAAa,OAAe;AAC3C,SAAO,MAAM;AACd;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { State } from './reducer';\n\nexport function isOpen( state: State ): boolean {\n\treturn state.isOpen;\n}\n\nexport function getId( state: State ): number | null {\n\treturn state.id;\n}\n\nexport function getOnUpdate( state: State ) {\n\treturn state.onUpdate;\n}\n\nexport function getOnClose( state: State ) {\n\treturn state.onClose;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,OAAQ,OAAwB;AAC/C,SAAO,MAAM;AACd;AAEO,SAAS,MAAO,OAA8B;AACpD,SAAO,MAAM;AACd;AAEO,SAAS,YAAa,OAAe;AAC3C,SAAO,MAAM;AACd;AAEO,SAAS,WAAY,OAAe;AAC1C,SAAO,MAAM;AACd;",
6
6
  "names": []
7
7
  }