@wordpress/media-editor 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/components/media-editor/index.cjs +115 -119
  3. package/build/components/media-editor/index.cjs.map +3 -3
  4. package/build/components/media-editor/use-crop-options.cjs.map +2 -2
  5. package/build/components/media-editor/use-save-media-editor.cjs.map +2 -2
  6. package/build/components/media-editor-canvas/index.cjs +0 -2
  7. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  8. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  9. package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
  10. package/build/components/media-editor-image-controls/index.cjs.map +2 -2
  11. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
  12. package/build/components/media-editor-modal/build-modifiers.cjs.map +2 -2
  13. package/build/components/media-editor-modal/index.cjs +31 -15
  14. package/build/components/media-editor-modal/index.cjs.map +3 -3
  15. package/build/components/media-editor-provider/index.cjs.map +2 -2
  16. package/build/components/media-form/index.cjs.map +2 -2
  17. package/build/components/media-preview/index.cjs.map +2 -2
  18. package/build/components/rotation-ruler/index.cjs.map +2 -2
  19. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +2 -2
  20. package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
  21. package/build/image-editor/core/camera.cjs.map +2 -2
  22. package/build/image-editor/core/constants.cjs.map +2 -2
  23. package/build/image-editor/core/containment.cjs.map +2 -2
  24. package/build/image-editor/core/crop-rect.cjs.map +2 -2
  25. package/build/image-editor/core/export/canvas-renderer.cjs.map +2 -2
  26. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  27. package/build/image-editor/core/math/sanitize.cjs.map +2 -2
  28. package/build/image-editor/core/setter-helpers.cjs.map +2 -2
  29. package/build/image-editor/core/source-region.cjs.map +2 -2
  30. package/build/image-editor/core/state.cjs.map +2 -2
  31. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  32. package/build/image-editor/core/transform-style.cjs.map +2 -2
  33. package/build/image-editor/core/transforms/pipeline.cjs.map +2 -2
  34. package/build/image-editor/core/viewport-state.cjs.map +2 -2
  35. package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
  36. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  37. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +2 -2
  38. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
  39. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +2 -2
  40. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  41. package/build/image-editor/react/components/viewport-provider.cjs.map +2 -2
  42. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +2 -2
  43. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  44. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
  45. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  46. package/build/image-editor/react/hooks/use-transform-style.cjs.map +2 -2
  47. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +2 -2
  48. package/build/lock-unlock.cjs.map +2 -2
  49. package/build/private-apis.cjs.map +2 -2
  50. package/build/state/composite-reducer.cjs.map +2 -2
  51. package/build/state/media-editor-state-provider.cjs.map +2 -2
  52. package/build/state/types.cjs.map +2 -2
  53. package/build/state/use-media-editor-state.cjs.map +2 -2
  54. package/build/store/index.cjs.map +2 -2
  55. package/build/store/reducer.cjs.map +2 -2
  56. package/build/store/selectors.cjs.map +2 -2
  57. package/build-module/components/media-editor/index.mjs +117 -120
  58. package/build-module/components/media-editor/index.mjs.map +2 -2
  59. package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
  60. package/build-module/components/media-editor/use-save-media-editor.mjs.map +2 -2
  61. package/build-module/components/media-editor-canvas/index.mjs +0 -2
  62. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  63. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  64. package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
  65. package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
  66. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
  67. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +2 -2
  68. package/build-module/components/media-editor-modal/index.mjs +31 -15
  69. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  70. package/build-module/components/media-editor-provider/index.mjs.map +2 -2
  71. package/build-module/components/media-form/index.mjs.map +2 -2
  72. package/build-module/components/media-preview/index.mjs.map +2 -2
  73. package/build-module/components/rotation-ruler/index.mjs.map +2 -2
  74. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +2 -2
  75. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
  76. package/build-module/image-editor/core/camera.mjs.map +2 -2
  77. package/build-module/image-editor/core/constants.mjs.map +2 -2
  78. package/build-module/image-editor/core/containment.mjs.map +2 -2
  79. package/build-module/image-editor/core/crop-rect.mjs.map +2 -2
  80. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +2 -2
  81. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  82. package/build-module/image-editor/core/math/sanitize.mjs.map +2 -2
  83. package/build-module/image-editor/core/setter-helpers.mjs.map +2 -2
  84. package/build-module/image-editor/core/source-region.mjs.map +2 -2
  85. package/build-module/image-editor/core/state.mjs.map +2 -2
  86. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  87. package/build-module/image-editor/core/transform-style.mjs.map +2 -2
  88. package/build-module/image-editor/core/transforms/pipeline.mjs.map +2 -2
  89. package/build-module/image-editor/core/viewport-state.mjs.map +2 -2
  90. package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
  91. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  92. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +2 -2
  93. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  94. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +2 -2
  95. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  96. package/build-module/image-editor/react/components/viewport-provider.mjs.map +2 -2
  97. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +2 -2
  98. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  99. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
  100. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  101. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +2 -2
  102. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +2 -2
  103. package/build-module/lock-unlock.mjs.map +2 -2
  104. package/build-module/private-apis.mjs.map +2 -2
  105. package/build-module/state/composite-reducer.mjs.map +2 -2
  106. package/build-module/state/media-editor-state-provider.mjs.map +2 -2
  107. package/build-module/state/types.mjs.map +2 -2
  108. package/build-module/state/use-media-editor-state.mjs.map +2 -2
  109. package/build-module/store/index.mjs.map +2 -2
  110. package/build-module/store/reducer.mjs.map +2 -2
  111. package/build-module/store/selectors.mjs.map +2 -2
  112. package/build-style/style-rtl.css +6 -6
  113. package/build-style/style.css +6 -6
  114. package/build-types/components/media-editor/index.d.ts +46 -11
  115. package/build-types/components/media-editor/index.d.ts.map +1 -1
  116. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  117. package/build-types/components/media-editor/use-save-media-editor.d.ts +0 -3
  118. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  119. package/build-types/components/media-editor-canvas/index.d.ts +1 -4
  120. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  121. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  122. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  123. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  124. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  125. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -3
  126. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  127. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  128. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  129. package/build-types/components/media-form/index.d.ts.map +1 -1
  130. package/build-types/components/media-preview/index.d.ts.map +1 -1
  131. package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
  132. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  133. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
  134. package/build-types/image-editor/core/camera.d.ts +0 -3
  135. package/build-types/image-editor/core/camera.d.ts.map +1 -1
  136. package/build-types/image-editor/core/constants.d.ts +0 -3
  137. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  138. package/build-types/image-editor/core/containment.d.ts +0 -3
  139. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  140. package/build-types/image-editor/core/crop-rect.d.ts +0 -3
  141. package/build-types/image-editor/core/crop-rect.d.ts.map +1 -1
  142. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -3
  143. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -1
  144. package/build-types/image-editor/core/interaction-controller.d.ts +0 -3
  145. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  146. package/build-types/image-editor/core/math/sanitize.d.ts +0 -3
  147. package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -1
  148. package/build-types/image-editor/core/setter-helpers.d.ts +0 -3
  149. package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -1
  150. package/build-types/image-editor/core/source-region.d.ts +0 -3
  151. package/build-types/image-editor/core/source-region.d.ts.map +1 -1
  152. package/build-types/image-editor/core/state.d.ts +0 -3
  153. package/build-types/image-editor/core/state.d.ts.map +1 -1
  154. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  155. package/build-types/image-editor/core/transform-style.d.ts +0 -3
  156. package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
  157. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -3
  158. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -1
  159. package/build-types/image-editor/core/viewport-state.d.ts +0 -3
  160. package/build-types/image-editor/core/viewport-state.d.ts.map +1 -1
  161. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -3
  162. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  163. package/build-types/image-editor/react/components/cropper.d.ts +0 -6
  164. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  165. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -3
  166. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -1
  167. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -3
  168. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  169. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -3
  170. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
  171. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -3
  172. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  173. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -3
  174. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -1
  175. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -3
  176. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -1
  177. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -3
  178. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  179. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -3
  180. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -1
  181. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -3
  182. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  183. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -3
  184. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -1
  185. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -3
  186. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -1
  187. package/build-types/lock-unlock.d.ts.map +1 -1
  188. package/build-types/private-apis.d.ts.map +1 -1
  189. package/build-types/state/composite-reducer.d.ts +0 -3
  190. package/build-types/state/composite-reducer.d.ts.map +1 -1
  191. package/build-types/state/media-editor-state-provider.d.ts +0 -3
  192. package/build-types/state/media-editor-state-provider.d.ts.map +1 -1
  193. package/build-types/state/types.d.ts +0 -3
  194. package/build-types/state/types.d.ts.map +1 -1
  195. package/build-types/state/use-media-editor-state.d.ts +0 -3
  196. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  197. package/build-types/store/index.d.ts.map +1 -1
  198. package/build-types/store/reducer.d.ts +0 -3
  199. package/build-types/store/reducer.d.ts.map +1 -1
  200. package/build-types/store/selectors.d.ts +0 -3
  201. package/build-types/store/selectors.d.ts.map +1 -1
  202. package/global.d.ts +5 -0
  203. package/package.json +24 -22
  204. package/src/components/media-editor/index.tsx +233 -194
  205. package/src/components/media-editor/style.scss +6 -3
  206. package/src/components/media-editor/test/use-crop-options.tsx +0 -7
  207. package/src/components/media-editor/use-crop-options.ts +0 -7
  208. package/src/components/media-editor/use-save-media-editor.ts +0 -7
  209. package/src/components/media-editor-canvas/index.tsx +5 -20
  210. package/src/components/media-editor-crop-panel/index.tsx +0 -7
  211. package/src/components/media-editor-crop-panel/test/index.tsx +0 -7
  212. package/src/components/media-editor-fine-rotation/index.tsx +0 -7
  213. package/src/components/media-editor-image-controls/index.tsx +0 -7
  214. package/src/components/media-editor-image-controls/test/index.tsx +0 -7
  215. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +0 -3
  216. package/src/components/media-editor-modal/build-modifiers.ts +0 -3
  217. package/src/components/media-editor-modal/index.tsx +43 -19
  218. package/src/components/media-editor-modal/style.scss +8 -4
  219. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -8
  220. package/src/components/media-editor-modal/test/index.tsx +0 -11
  221. package/src/components/media-editor-provider/index.tsx +0 -3
  222. package/src/components/media-form/index.tsx +0 -7
  223. package/src/components/media-preview/index.tsx +0 -7
  224. package/src/components/rotation-ruler/index.tsx +0 -11
  225. package/src/components/rotation-ruler/stories/index.story.tsx +0 -11
  226. package/src/components/rotation-ruler/test/index.tsx +0 -7
  227. package/src/components/rotation-ruler/use-ruler-drag.ts +0 -3
  228. package/src/hooks/use-crop-gesture-handlers.ts +0 -7
  229. package/src/image-editor/core/camera.ts +0 -7
  230. package/src/image-editor/core/constants.ts +0 -7
  231. package/src/image-editor/core/containment.ts +0 -7
  232. package/src/image-editor/core/crop-rect.ts +0 -3
  233. package/src/image-editor/core/export/canvas-renderer.ts +0 -3
  234. package/src/image-editor/core/export/test/canvas-renderer.ts +0 -3
  235. package/src/image-editor/core/interaction-controller.ts +0 -3
  236. package/src/image-editor/core/math/sanitize.ts +0 -3
  237. package/src/image-editor/core/math/test/sanitize.ts +0 -3
  238. package/src/image-editor/core/setter-helpers.ts +0 -3
  239. package/src/image-editor/core/source-region.ts +0 -7
  240. package/src/image-editor/core/state.ts +0 -3
  241. package/src/image-editor/core/stencil-math.ts +0 -3
  242. package/src/image-editor/core/test/interaction-controller.ts +0 -3
  243. package/src/image-editor/core/test/preview-export-parity.ts +0 -1
  244. package/src/image-editor/core/test/stencil-math.ts +0 -3
  245. package/src/image-editor/core/transform-style.ts +0 -3
  246. package/src/image-editor/core/transforms/pipeline.ts +0 -3
  247. package/src/image-editor/core/transforms/test/pipeline.ts +0 -3
  248. package/src/image-editor/core/viewport-state.ts +0 -3
  249. package/src/image-editor/react/components/cropper-provider.tsx +0 -7
  250. package/src/image-editor/react/components/cropper.tsx +0 -12
  251. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -7
  252. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -3
  253. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -3
  254. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -7
  255. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +0 -7
  256. package/src/image-editor/react/components/test/cropper.tsx +0 -7
  257. package/src/image-editor/react/components/viewport-provider.tsx +0 -7
  258. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -3
  259. package/src/image-editor/react/hooks/test/use-aria-announcer.ts +0 -11
  260. package/src/image-editor/react/hooks/test/use-cropper-reducer.ts +0 -7
  261. package/src/image-editor/react/hooks/test/use-interaction.ts +0 -7
  262. package/src/image-editor/react/hooks/test/use-transform-style.ts +0 -7
  263. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -7
  264. package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -7
  265. package/src/image-editor/react/hooks/use-interaction.ts +0 -7
  266. package/src/image-editor/react/hooks/use-transform-style.ts +0 -7
  267. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -7
  268. package/src/image-editor/stories/rectangle-crop.story.tsx +15 -11
  269. package/src/lock-unlock.ts +0 -3
  270. package/src/private-apis.ts +0 -3
  271. package/src/state/composite-reducer.ts +0 -3
  272. package/src/state/media-editor-state-provider.tsx +0 -7
  273. package/src/state/test/use-media-editor-state.ts +0 -7
  274. package/src/state/types.ts +0 -3
  275. package/src/state/use-media-editor-state.ts +0 -7
  276. package/src/store/index.ts +0 -7
  277. package/src/store/reducer.ts +0 -3
  278. package/src/store/selectors.ts +0 -3
  279. package/src/store/test/reducer.ts +0 -3
  280. package/tsconfig.build.json +26 -0
  281. package/tsconfig.build.tsbuildinfo +1 -0
  282. package/tsconfig.json +22 -15
  283. package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
  284. package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
  285. package/build-types/components/media-editor-transform-controls/index.d.ts +0 -21
  286. package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
  287. package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
  288. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
  289. package/build-types/components/rotation-ruler/stories/index.story.d.ts +0 -14
  290. package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +0 -1
  291. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -108
  292. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
  293. package/build-types/image-editor/stories/rectangle-crop.story.d.ts +0 -16
  294. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +0 -1
  295. package/tsconfig.tsbuildinfo +0 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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'` → `undefined` (Free; no lock)\n * - `'-1'` (Original) → image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal → 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 — 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 — 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` → `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 — 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 — 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;AA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AAQ;AAAA;AAAA;AAAA,MAGP,GAAG;AAAA,MACH,OAAO,MAAM;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,aAAa,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["import {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\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'` → `undefined` (Free; no lock)\n * - `'-1'` (Original) → image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal → 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 — 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 — 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` → `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 — 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 — 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;AAAA,qBAMO;AACP,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,2C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,GAAG;AAAA,MACH,OAAO,MAAM;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,aAAa,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/store/index.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,cAAyB;AACzB,gBAA2B;AAC3B,uBAA2B;AAEpB,IAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
4
+ "sourcesContent": ["import { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2C;AAC3C,qBAAoB;AACpB,cAAyB;AACzB,gBAA2B;AAC3B,uBAA2B;AAEpB,IAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
6
6
  "names": ["reducer"]
7
7
  }
@@ -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;\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;",
4
+ "sourcesContent": ["import 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;AAYO,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
  }
@@ -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\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;",
4
+ "sourcesContent": ["import 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;AAEO,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
  }
@@ -1,7 +1,6 @@
1
1
  // packages/media-editor/src/components/media-editor/index.tsx
2
2
  import {
3
3
  Button,
4
- Flex,
5
4
  Spinner,
6
5
  __experimentalConfirmDialog as ConfirmDialog
7
6
  } from "@wordpress/components";
@@ -10,8 +9,10 @@ import { useViewportMatch } from "@wordpress/compose";
10
9
  import { useDispatch, useSelect } from "@wordpress/data";
11
10
  import { store as coreStore } from "@wordpress/core-data";
12
11
  import {
12
+ createContext,
13
13
  createPortal,
14
14
  useCallback,
15
+ useContext,
15
16
  useEffect,
16
17
  useMemo,
17
18
  useRef,
@@ -49,11 +50,16 @@ import { useCropOptions } from "./use-crop-options.mjs";
49
50
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
50
51
  var ATTACHMENT_EMBED_QUERY = { _embed: "author,wp:attached-to" };
51
52
  var PLACEMENT_CONTROL_IDLE_MS = 300;
52
- function MediaEditorSidebar({ tabs }) {
53
+ function MediaEditorSidebar({
54
+ tabs,
55
+ activeTabId,
56
+ onTabChange,
57
+ scope
58
+ }) {
53
59
  return /* @__PURE__ */ jsx(
54
60
  ComplementaryArea,
55
61
  {
56
- scope: "media-editor",
62
+ scope,
57
63
  identifier: "media-editor/details",
58
64
  title: __("Details"),
59
65
  icon: drawerRight,
@@ -62,25 +68,38 @@ function MediaEditorSidebar({ tabs }) {
62
68
  panelClassName: "media-editor__sidebar-panel",
63
69
  headerClassName: "media-editor__sidebar-header",
64
70
  closeLabel: __("Close media panel"),
71
+ render: /* @__PURE__ */ jsx(
72
+ Tabs.Root,
73
+ {
74
+ value: activeTabId,
75
+ onValueChange: (value) => onTabChange(value)
76
+ }
77
+ ),
65
78
  header: /* @__PURE__ */ jsx(Tabs.List, { variant: "minimal", children: tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Tab, { value: tab.id, children: tab.title }, tab.id)) }),
66
79
  children: tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Panel, { value: tab.id, tabIndex: -1, children: tab.panel }, tab.id))
67
80
  }
68
81
  );
69
82
  }
70
- function HeaderActions({
71
- isSaving,
72
- isImage,
73
- showCloseButton = false,
74
- onCancel
75
- }) {
83
+ var MediaEditorFrameContext = createContext(null);
84
+ function useMediaEditorFrameContext() {
85
+ const context = useContext(MediaEditorFrameContext);
86
+ if (!context) {
87
+ throw new Error(
88
+ "useMediaEditorFrameContext must be used within MediaEditor"
89
+ );
90
+ }
91
+ return context;
92
+ }
93
+ function HeaderActions({ showCloseButton = false }) {
94
+ const { isImage, isSaving, onCancel, scope } = useMediaEditorFrameContext();
76
95
  const [isShortcutsModalOpen, setIsShortcutsModalOpen] = useState(false);
77
96
  return /* @__PURE__ */ jsxs(
78
- Flex,
97
+ Stack,
79
98
  {
80
99
  className: "media-editor__header-actions",
81
100
  justify: "flex-end",
82
- expanded: false,
83
- gap: 2,
101
+ align: "center",
102
+ gap: "sm",
84
103
  children: [
85
104
  isImage && /* @__PURE__ */ jsx(
86
105
  Button,
@@ -91,7 +110,7 @@ function HeaderActions({
91
110
  onClick: () => setIsShortcutsModalOpen(true)
92
111
  }
93
112
  ),
94
- /* @__PURE__ */ jsx(PinnedItems.Slot, { scope: "media-editor" }),
113
+ /* @__PURE__ */ jsx(PinnedItems.Slot, { scope }),
95
114
  showCloseButton && /* @__PURE__ */ jsx(
96
115
  Button,
97
116
  {
@@ -113,10 +132,8 @@ function HeaderActions({
113
132
  }
114
133
  );
115
134
  }
116
- function HistoryActions({
117
- isUndoRedoDisabled = false,
118
- onReset
119
- }) {
135
+ function HistoryActions() {
136
+ const { isImage, isUndoRedoDisabled, onReset } = useMediaEditorFrameContext();
120
137
  const {
121
138
  reset,
122
139
  isDirty,
@@ -127,6 +144,9 @@ function HistoryActions({
127
144
  beginGesture,
128
145
  endGesture
129
146
  } = useMediaEditor();
147
+ if (!isImage) {
148
+ return null;
149
+ }
130
150
  const handleUndo = () => {
131
151
  if (isUndoRedoDisabled) {
132
152
  return;
@@ -146,11 +166,11 @@ function HistoryActions({
146
166
  endGesture();
147
167
  };
148
168
  return /* @__PURE__ */ jsxs(
149
- Flex,
169
+ Stack,
150
170
  {
151
171
  className: "media-editor__history-actions",
152
- expanded: false,
153
- gap: 2,
172
+ align: "center",
173
+ gap: "sm",
154
174
  children: [
155
175
  /* @__PURE__ */ jsx(
156
176
  Button,
@@ -193,26 +213,22 @@ function HistoryActions({
193
213
  }
194
214
  );
195
215
  }
196
- function FooterActions({
197
- isSaving,
198
- hasMedia,
199
- hasChanges,
200
- onCancel,
201
- onSave
202
- }) {
216
+ function SaveActions({ size = "default" }) {
217
+ const { isSaving, hasMedia, hasChanges, onCancel, onSave } = useMediaEditorFrameContext();
203
218
  const saveDisabled = isSaving || !hasMedia || !hasChanges;
204
219
  return /* @__PURE__ */ jsxs(
205
- Flex,
220
+ Stack,
206
221
  {
207
- className: "media-editor__footer-actions",
222
+ className: "media-editor__save-actions",
208
223
  justify: "flex-end",
209
- expanded: false,
210
- gap: 2,
224
+ align: "center",
225
+ gap: "sm",
211
226
  children: [
212
227
  /* @__PURE__ */ jsx(
213
228
  Button,
214
229
  {
215
230
  __next40pxDefaultSize: true,
231
+ size,
216
232
  variant: "tertiary",
217
233
  onClick: onCancel,
218
234
  disabled: isSaving,
@@ -224,6 +240,7 @@ function FooterActions({
224
240
  Button,
225
241
  {
226
242
  __next40pxDefaultSize: true,
243
+ size,
227
244
  variant: "primary",
228
245
  onClick: onSave,
229
246
  isBusy: isSaving,
@@ -236,6 +253,19 @@ function FooterActions({
236
253
  }
237
254
  );
238
255
  }
256
+ function ImageControls() {
257
+ const { isImage, aspectRatioPresets } = useMediaEditorFrameContext();
258
+ if (!isImage) {
259
+ return null;
260
+ }
261
+ return /* @__PURE__ */ jsx(
262
+ MediaEditorImageControls,
263
+ {
264
+ showAspectRatioControl: true,
265
+ aspectRatioPresets
266
+ }
267
+ );
268
+ }
239
269
  function MediaEditorContent({
240
270
  fields = [],
241
271
  id,
@@ -245,12 +275,12 @@ function MediaEditorContent({
245
275
  renderFrame,
246
276
  noticesClassName = "media-editor__snackbar",
247
277
  noticesPortalElement,
248
- showCloseButton = false,
249
- shouldCloseOnEsc = false
278
+ shouldCloseOnEsc = false,
279
+ scope = "media-editor"
250
280
  }) {
251
281
  const cropper = useMediaEditor();
252
282
  const isPanelLayout = useViewportMatch("small");
253
- const footerLayout = isPanelLayout ? "wide" : "narrow";
283
+ const layout = isPanelLayout ? "wide" : "narrow";
254
284
  const { media, hasEdits } = useSelect(
255
285
  (select) => {
256
286
  const {
@@ -454,40 +484,39 @@ function MediaEditorContent({
454
484
  onChange: handleChange,
455
485
  settings: { fields },
456
486
  children: [
457
- !media ? /* @__PURE__ */ jsx("div", { className: "media-editor", children: /* @__PURE__ */ jsx("div", { className: "media-editor__loading", children: /* @__PURE__ */ jsx(Spinner, {}) }) }) : /* @__PURE__ */ jsxs(
458
- Tabs.Root,
459
- {
460
- className: "media-editor",
461
- value: activeTabId,
462
- onValueChange: (value) => setSelectedTabId(value),
463
- children: [
464
- /* @__PURE__ */ jsx(MediaEditorSidebar, { tabs }),
465
- /* @__PURE__ */ jsx(
466
- InterfaceSkeleton,
467
- {
468
- className: "media-editor__skeleton",
469
- labels: {
470
- body: isImage ? __("Image editor") : __("Media preview"),
471
- sidebar: __("Media details")
472
- },
473
- content: /* @__PURE__ */ jsxs("div", { className: "media-editor__content", children: [
474
- /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-area", children: isImage ? /* @__PURE__ */ jsx(
475
- MediaEditorCanvas,
476
- {
477
- focusOnMount: true,
478
- isPlacementActive,
479
- onGestureStart: handleCanvasGestureStart,
480
- onGestureEnd: handleCanvasGestureEnd
481
- }
482
- ) : /* @__PURE__ */ jsx(MediaPreview, {}) }),
483
- isImage && /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-toolbar", children: ruler })
484
- ] }),
485
- sidebar: /* @__PURE__ */ jsx(ComplementaryArea.Slot, { scope: "media-editor" })
486
- }
487
- )
488
- ]
489
- }
490
- ),
487
+ /* @__PURE__ */ jsx("div", { className: "media-editor", children: !media ? /* @__PURE__ */ jsx("div", { className: "media-editor__loading", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
488
+ /* @__PURE__ */ jsx(
489
+ MediaEditorSidebar,
490
+ {
491
+ tabs,
492
+ activeTabId,
493
+ onTabChange: setSelectedTabId,
494
+ scope
495
+ }
496
+ ),
497
+ /* @__PURE__ */ jsx(
498
+ InterfaceSkeleton,
499
+ {
500
+ className: "media-editor__skeleton",
501
+ labels: {
502
+ body: isImage ? __("Image editor") : __("Media preview"),
503
+ sidebar: __("Media details")
504
+ },
505
+ content: /* @__PURE__ */ jsxs("div", { className: "media-editor__content", children: [
506
+ /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-area", children: isImage ? /* @__PURE__ */ jsx(
507
+ MediaEditorCanvas,
508
+ {
509
+ isPlacementActive,
510
+ onGestureStart: handleCanvasGestureStart,
511
+ onGestureEnd: handleCanvasGestureEnd
512
+ }
513
+ ) : /* @__PURE__ */ jsx(MediaPreview, {}) }),
514
+ isImage && /* @__PURE__ */ jsx("div", { className: "media-editor__canvas-toolbar", children: ruler })
515
+ ] }),
516
+ sidebar: /* @__PURE__ */ jsx(ComplementaryArea.Slot, { scope })
517
+ }
518
+ )
519
+ ] }) }),
491
520
  /* @__PURE__ */ jsx(
492
521
  ConfirmDialog,
493
522
  {
@@ -508,69 +537,37 @@ function MediaEditorContent({
508
537
  ]
509
538
  }
510
539
  );
511
- const history = isImage ? /* @__PURE__ */ jsx(
512
- HistoryActions,
513
- {
514
- isUndoRedoDisabled: isCropInteractionActive,
515
- onReset: resetCropOptions
516
- }
517
- ) : null;
518
- const imageControls = isImage ? /* @__PURE__ */ jsx(
519
- MediaEditorImageControls,
520
- {
521
- showAspectRatioControl: true,
522
- aspectRatioPresets
523
- }
524
- ) : null;
525
- const actions = /* @__PURE__ */ jsx(
526
- FooterActions,
527
- {
528
- isSaving,
529
- hasMedia: !!media,
530
- hasChanges,
531
- onCancel: handleRequestClose,
532
- onSave: saveMediaEditor
533
- }
534
- );
535
- let footerActions;
536
- if (footerLayout === "wide") {
537
- footerActions = /* @__PURE__ */ jsxs(Fragment, { children: [
538
- history,
539
- actions
540
- ] });
541
- } else {
542
- footerActions = /* @__PURE__ */ jsxs(Fragment, { children: [
543
- imageControls,
544
- /* @__PURE__ */ jsxs("div", { className: "media-editor-modal__footer-row", children: [
545
- history,
546
- actions
547
- ] })
548
- ] });
549
- }
550
- return renderFrame({
540
+ const contextValue = {
541
+ isImage,
542
+ isSaving,
543
+ hasMedia: !!media,
544
+ hasChanges,
545
+ isUndoRedoDisabled: isCropInteractionActive,
546
+ scope,
547
+ aspectRatioPresets,
548
+ onCancel: handleRequestClose,
549
+ onSave: saveMediaEditor,
550
+ onReset: resetCropOptions
551
+ };
552
+ return /* @__PURE__ */ jsx(MediaEditorFrameContext.Provider, { value: contextValue, children: renderFrame({
551
553
  children,
552
- headerActions: /* @__PURE__ */ jsx(
553
- HeaderActions,
554
- {
555
- isSaving,
556
- isImage,
557
- showCloseButton,
558
- onCancel: handleRequestClose
559
- }
560
- ),
561
- footerActions,
562
- footerLayout,
554
+ isImage,
555
+ layout,
563
556
  onRequestClose: handleRequestClose,
564
557
  onKeyDown: handleKeyDown,
565
558
  shouldCloseOnClickOutside: !hasChanges && !isSaving,
566
559
  isSaving,
567
560
  hasChanges,
568
561
  hasMedia: !!media
569
- });
562
+ }) });
570
563
  }
571
564
  function MediaEditor(props) {
572
565
  return /* @__PURE__ */ jsx(MediaEditorStateProvider, { children: /* @__PURE__ */ jsx(MediaEditorContent, { ...props }) }, props.id);
573
566
  }
567
+ MediaEditor.HeaderActions = HeaderActions;
568
+ MediaEditor.HistoryActions = HistoryActions;
569
+ MediaEditor.SaveActions = SaveActions;
570
+ MediaEditor.ImageControls = ImageControls;
574
571
  var media_editor_default = MediaEditor;
575
572
  export {
576
573
  MediaEditor,