@wordpress/media-editor 0.22.0 → 0.24.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 (391) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/build/components/media-editor/index.cjs +229 -126
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +41 -11
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +15 -18
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +26 -8
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +13 -12
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs +10 -7
  19. package/build/components/media-editor-modal/index.cjs.map +1 -1
  20. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  21. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  22. package/build/components/media-editor-panel/index.cjs +158 -0
  23. package/build/components/media-editor-panel/index.cjs.map +1 -0
  24. package/build/components/media-form/index.cjs +7 -1
  25. package/build/components/media-form/index.cjs.map +1 -1
  26. package/build/components/media-preview/index.cjs +143 -37
  27. package/build/components/media-preview/index.cjs.map +1 -1
  28. package/build/components/rotation-ruler/index.cjs +9 -7
  29. package/build/components/rotation-ruler/index.cjs.map +1 -1
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  32. package/build/index.cjs +10 -8
  33. package/build/private-apis.cjs.map +1 -1
  34. package/build/state/aspect-ratio-presets.cjs +12 -6
  35. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  36. package/build/state/composite-reducer.cjs +41 -74
  37. package/build/state/composite-reducer.cjs.map +1 -1
  38. package/build/state/index.cjs +0 -39
  39. package/build/state/types.cjs +1 -2
  40. package/build/state/types.cjs.map +1 -1
  41. package/build/state/use-media-editor-state.cjs +70 -106
  42. package/build/state/use-media-editor-state.cjs.map +1 -1
  43. package/build/store/index.cjs +11 -9
  44. package/build/store/index.cjs.map +1 -1
  45. package/build/utils/get-media-type.cjs +8 -0
  46. package/build/utils/get-media-type.cjs.map +1 -1
  47. package/build/utils/index.cjs +6 -0
  48. package/build-module/components/media-editor/index.mjs +217 -117
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  51. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  52. package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
  53. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  54. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  55. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  56. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  57. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  58. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  59. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  60. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  61. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  62. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
  63. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  64. package/build-module/components/media-editor-modal/index.mjs +1 -0
  65. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  66. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  67. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  68. package/build-module/components/media-editor-panel/index.mjs +123 -0
  69. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  70. package/build-module/components/media-form/index.mjs +7 -1
  71. package/build-module/components/media-form/index.mjs.map +1 -1
  72. package/build-module/components/media-preview/index.mjs +123 -41
  73. package/build-module/components/media-preview/index.mjs.map +1 -1
  74. package/build-module/state/aspect-ratio-presets.mjs +12 -7
  75. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  76. package/build-module/state/composite-reducer.mjs +32 -67
  77. package/build-module/state/composite-reducer.mjs.map +1 -1
  78. package/build-module/state/index.mjs +2 -5
  79. package/build-module/state/types.mjs +1 -2
  80. package/build-module/state/types.mjs.map +1 -1
  81. package/build-module/state/use-media-editor-state.mjs +70 -105
  82. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  83. package/build-module/utils/get-media-type.mjs +8 -1
  84. package/build-module/utils/get-media-type.mjs.map +1 -1
  85. package/build-module/utils/index.mjs +1 -1
  86. package/build-style/style-rtl.css +122 -87
  87. package/build-style/style.css +121 -87
  88. package/build-types/components/media-editor/index.d.ts +25 -3
  89. package/build-types/components/media-editor/index.d.ts.map +1 -1
  90. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  91. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  92. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  93. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  94. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  95. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  96. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  97. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  98. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  99. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  100. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  101. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  102. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  103. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  104. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  105. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  106. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  107. package/build-types/components/media-form/index.d.ts.map +1 -1
  108. package/build-types/components/media-preview/index.d.ts.map +1 -1
  109. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  110. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  111. package/build-types/state/composite-reducer.d.ts +17 -19
  112. package/build-types/state/composite-reducer.d.ts.map +1 -1
  113. package/build-types/state/index.d.ts +2 -5
  114. package/build-types/state/index.d.ts.map +1 -1
  115. package/build-types/state/types.d.ts +20 -64
  116. package/build-types/state/types.d.ts.map +1 -1
  117. package/build-types/state/use-media-editor-state.d.ts +40 -54
  118. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  119. package/build-types/utils/get-media-type.d.ts +3 -1
  120. package/build-types/utils/get-media-type.d.ts.map +1 -1
  121. package/build-types/utils/index.d.ts +1 -1
  122. package/build-types/utils/index.d.ts.map +1 -1
  123. package/package.json +27 -24
  124. package/src/components/media-editor/index.tsx +372 -142
  125. package/src/components/media-editor/style.scss +21 -1
  126. package/src/components/media-editor/use-crop-options.ts +7 -11
  127. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  128. package/src/components/media-editor-canvas/index.tsx +15 -26
  129. package/src/components/media-editor-canvas/style.scss +6 -6
  130. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  131. package/src/components/media-editor-crop-panel/style.scss +21 -0
  132. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  133. package/src/components/media-editor-image-controls/index.tsx +11 -9
  134. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
  135. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  136. package/src/components/media-editor-modal/index.tsx +4 -1
  137. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  138. package/src/components/media-editor-panel/index.tsx +211 -0
  139. package/src/components/media-form/index.tsx +7 -1
  140. package/src/components/media-preview/index.tsx +195 -37
  141. package/src/components/media-preview/style.scss +11 -32
  142. package/src/components/rotation-ruler/style.scss +3 -3
  143. package/src/state/README.md +34 -0
  144. package/src/state/aspect-ratio-presets.ts +22 -3
  145. package/src/state/composite-reducer.ts +42 -80
  146. package/src/state/index.ts +2 -18
  147. package/src/state/types.ts +18 -68
  148. package/src/state/use-media-editor-state.ts +162 -242
  149. package/src/style.scss +2 -1
  150. package/src/utils/get-media-type.ts +9 -1
  151. package/src/utils/index.ts +1 -1
  152. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  153. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  154. package/build/image-editor/core/camera.cjs +0 -277
  155. package/build/image-editor/core/camera.cjs.map +0 -1
  156. package/build/image-editor/core/constants.cjs +0 -133
  157. package/build/image-editor/core/constants.cjs.map +0 -1
  158. package/build/image-editor/core/containment.cjs +0 -289
  159. package/build/image-editor/core/containment.cjs.map +0 -1
  160. package/build/image-editor/core/crop-rect.cjs +0 -37
  161. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  162. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  163. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  164. package/build/image-editor/core/index.cjs +0 -89
  165. package/build/image-editor/core/interaction-controller.cjs +0 -591
  166. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  167. package/build/image-editor/core/math/rotation.cjs +0 -32
  168. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  169. package/build/image-editor/core/math/sanitize.cjs +0 -136
  170. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  171. package/build/image-editor/core/setter-helpers.cjs +0 -61
  172. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  173. package/build/image-editor/core/source-region.cjs +0 -236
  174. package/build/image-editor/core/source-region.cjs.map +0 -1
  175. package/build/image-editor/core/state.cjs +0 -296
  176. package/build/image-editor/core/state.cjs.map +0 -1
  177. package/build/image-editor/core/stencil-math.cjs +0 -203
  178. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  179. package/build/image-editor/core/transform-style.cjs +0 -43
  180. package/build/image-editor/core/transform-style.cjs.map +0 -1
  181. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  182. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  183. package/build/image-editor/core/types.cjs +0 -5
  184. package/build/image-editor/core/viewport-state.cjs +0 -36
  185. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  186. package/build/image-editor/index.cjs +0 -68
  187. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  188. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  189. package/build/image-editor/react/components/cropper.cjs +0 -595
  190. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  191. package/build/image-editor/react/components/index.cjs +0 -25
  192. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  193. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  194. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  195. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  196. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  197. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  198. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  199. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  200. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  201. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  202. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  203. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  204. package/build/image-editor/react/hooks/index.cjs +0 -19
  205. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  206. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  207. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  208. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  209. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  210. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  211. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  212. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  213. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  214. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  215. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  216. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  217. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  218. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  219. package/build-module/image-editor/core/camera.mjs +0 -265
  220. package/build-module/image-editor/core/camera.mjs.map +0 -1
  221. package/build-module/image-editor/core/constants.mjs +0 -115
  222. package/build-module/image-editor/core/constants.mjs.map +0 -1
  223. package/build-module/image-editor/core/containment.mjs +0 -281
  224. package/build-module/image-editor/core/containment.mjs.map +0 -1
  225. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  226. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  227. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  228. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  229. package/build-module/image-editor/core/index.mjs +0 -7
  230. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  231. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  232. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  233. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  234. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  235. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  236. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  237. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  238. package/build-module/image-editor/core/source-region.mjs +0 -228
  239. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  240. package/build-module/image-editor/core/state.mjs +0 -288
  241. package/build-module/image-editor/core/state.mjs.map +0 -1
  242. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  243. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  244. package/build-module/image-editor/core/transform-style.mjs +0 -38
  245. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  246. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  247. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  248. package/build-module/image-editor/core/types.mjs +0 -0
  249. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  250. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  251. package/build-module/image-editor/index.mjs +0 -4
  252. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  253. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  254. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  255. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  256. package/build-module/image-editor/react/components/index.mjs +0 -3
  257. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  258. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  259. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  260. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  261. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  262. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  263. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  264. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  265. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  266. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  267. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  268. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  269. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  270. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  271. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  272. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  273. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  274. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  275. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  276. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  277. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  278. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  279. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  280. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  281. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  282. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  283. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  284. package/build-types/image-editor/core/camera.d.ts +0 -128
  285. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  286. package/build-types/image-editor/core/constants.d.ts +0 -98
  287. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  288. package/build-types/image-editor/core/containment.d.ts +0 -72
  289. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  290. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  291. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  292. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  293. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  294. package/build-types/image-editor/core/index.d.ts +0 -10
  295. package/build-types/image-editor/core/index.d.ts.map +0 -1
  296. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  297. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  298. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  299. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  300. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  301. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  302. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  303. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  304. package/build-types/image-editor/core/source-region.d.ts +0 -94
  305. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  306. package/build-types/image-editor/core/state.d.ts +0 -51
  307. package/build-types/image-editor/core/state.d.ts.map +0 -1
  308. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  309. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  310. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  311. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  312. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  313. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  314. package/build-types/image-editor/core/types.d.ts +0 -269
  315. package/build-types/image-editor/core/types.d.ts.map +0 -1
  316. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  317. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  318. package/build-types/image-editor/index.d.ts +0 -17
  319. package/build-types/image-editor/index.d.ts.map +0 -1
  320. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  321. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  322. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  323. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  324. package/build-types/image-editor/react/components/index.d.ts +0 -4
  325. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  326. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  327. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  328. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  329. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  330. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  331. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  332. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  333. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  334. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  335. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  336. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  337. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  338. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  339. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  340. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  341. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  342. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  343. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  344. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  345. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  346. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  347. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  348. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  349. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  350. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  351. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  352. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  353. package/src/image-editor/README.md +0 -61
  354. package/src/image-editor/core/camera.ts +0 -429
  355. package/src/image-editor/core/constants.ts +0 -137
  356. package/src/image-editor/core/containment.ts +0 -469
  357. package/src/image-editor/core/crop-rect.ts +0 -42
  358. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  359. package/src/image-editor/core/index.ts +0 -43
  360. package/src/image-editor/core/interaction-controller.ts +0 -976
  361. package/src/image-editor/core/math/rotation.ts +0 -26
  362. package/src/image-editor/core/math/sanitize.ts +0 -155
  363. package/src/image-editor/core/setter-helpers.ts +0 -63
  364. package/src/image-editor/core/source-region.ts +0 -367
  365. package/src/image-editor/core/state.ts +0 -484
  366. package/src/image-editor/core/stencil-math.ts +0 -379
  367. package/src/image-editor/core/transform-style.ts +0 -56
  368. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  369. package/src/image-editor/core/types.ts +0 -230
  370. package/src/image-editor/core/viewport-state.ts +0 -30
  371. package/src/image-editor/docs/architecture.md +0 -63
  372. package/src/image-editor/docs/recipes.md +0 -184
  373. package/src/image-editor/index.ts +0 -43
  374. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  375. package/src/image-editor/react/components/cropper.scss +0 -259
  376. package/src/image-editor/react/components/cropper.tsx +0 -1108
  377. package/src/image-editor/react/components/index.ts +0 -3
  378. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  379. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  380. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  381. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  382. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  383. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  384. package/src/image-editor/react/hooks/index.ts +0 -4
  385. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  386. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  387. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  388. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  389. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  390. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  391. package/src/image-editor/style.scss +0 -1
@@ -4,14 +4,18 @@ import {
4
4
  DropdownMenu,
5
5
  MenuGroup,
6
6
  MenuItem,
7
+ Modal,
7
8
  Spinner as WCSpinner,
8
9
  __experimentalConfirmDialog as ConfirmDialog,
9
10
  __unstableAnimatePresence as AnimatePresence,
10
11
  __unstableMotion as motion,
12
+ Slot,
13
+ SlotFillProvider,
11
14
  } from '@wordpress/components';
12
15
  import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
16
+ import { PluginArea } from '@wordpress/plugins';
13
17
  import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
14
- import { useDispatch, useSelect } from '@wordpress/data';
18
+ import { useDispatch, useRegistry, useSelect } from '@wordpress/data';
15
19
  import { store as coreStore } from '@wordpress/core-data';
16
20
  import { NavigableRegion } from '@wordpress/admin-ui';
17
21
  import {
@@ -20,10 +24,11 @@ import {
20
24
  useCallback,
21
25
  useContext,
22
26
  useEffect,
27
+ useMemo,
23
28
  useRef,
24
29
  useState,
25
30
  } from '@wordpress/element';
26
- import { __ } from '@wordpress/i18n';
31
+ import { __, _x, sprintf } from '@wordpress/i18n';
27
32
  import {
28
33
  backup,
29
34
  close,
@@ -37,14 +42,17 @@ import {
37
42
  displayShortcut,
38
43
  isAppleOS,
39
44
  isKeyboardEvent,
45
+ withIgnoreIMEEvents,
40
46
  } from '@wordpress/keycodes';
41
47
  import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
42
- import type { Field, Form } from '@wordpress/dataviews';
48
+ import { inertValue } from '@wordpress/react-inert-value';
49
+ import type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';
43
50
  import type {
44
51
  KeyboardEvent as ReactKeyboardEvent,
45
52
  ReactElement,
46
53
  ReactNode,
47
54
  } from 'react';
55
+ import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
48
56
  import { MediaEditorProvider } from '../media-editor-provider';
49
57
  import type { Media } from '../media-editor-provider';
50
58
  import MediaPreview from '../media-preview';
@@ -53,9 +61,15 @@ import MediaEditorFineRotation from '../media-editor-fine-rotation';
53
61
  import MediaEditorCropPanel from '../media-editor-crop-panel';
54
62
  import MediaEditorImageControls from '../media-editor-image-controls';
55
63
  import MediaForm from '../media-form';
64
+ import MediaEditorPanel, {
65
+ MEDIA_EDITOR_PLUGIN_SCOPE,
66
+ MediaEditorPanelsProvider,
67
+ getPanelSlotName,
68
+ useMediaEditorPanels,
69
+ type MediaEditorPanelFillProps,
70
+ } from '../media-editor-panel';
56
71
  import { getMediaTypeFromMimeType } from '../../utils';
57
72
  import { MediaEditorStateProvider, useMediaEditor } from '../../state';
58
- import type { AspectRatioPreset } from '../../image-editor/core/constants';
59
73
  import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
60
74
  import MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';
61
75
  import {
@@ -75,15 +89,18 @@ const ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;
75
89
  const PLACEMENT_CONTROL_IDLE_MS = 300;
76
90
 
77
91
  /**
78
- * Identifier for the details panel, and the panel the sidebar opens on before
79
- * the user picks another. The sidebar tracks which panel is open rather than
80
- * whether one is, so a further panel is a new id here and a new entry in the
81
- * tab list — not a change to the state's shape.
92
+ * The Details panel's id. Every media type has this panel, so the sidebar
93
+ * shows it when the requested panel doesn't exist.
94
+ *
95
+ * The sidebar stores the open panel's id, so adding a panel only needs a new
96
+ * id and a new tab.
82
97
  */
83
- const DETAILS_PANEL = 'details';
98
+ const DETAILS_PANEL = 'core/details';
84
99
 
85
100
  /** Identifier for the crop panel. Images only; other media has nothing to crop. */
86
- const CROP_PANEL = 'crop';
101
+ const CROP_PANEL = 'core/crop';
102
+
103
+ const CROP_MEDIA_TYPES = [ 'image' ] as const;
87
104
 
88
105
  // Matches the editor's sidebar in `ComplementaryArea`.
89
106
  const SIDEBAR_ANIMATION_DURATION = 0.3;
@@ -143,10 +160,20 @@ export interface MediaEditorProps {
143
160
  aspectRatioPresets?: AspectRatioPreset[];
144
161
  onClose?: () => void;
145
162
  onSaved?: ( result: MediaEditorSaveResult ) => void;
163
+ /** Called with the original's id when the user chooses "Edit original". */
164
+ onEditOriginal?: ( originalId: number ) => void;
146
165
  renderFrame: ( props: MediaEditorFrameProps ) => ReactElement;
147
166
  noticesClassName?: string;
148
167
  noticesPortalElement?: Element | null;
149
168
  shouldCloseOnEsc?: boolean;
169
+ /**
170
+ * The id of the panel to open on, which is also shown as the first tab.
171
+ * Below `small`, or when no tab has this id, the sidebar opens on
172
+ * Details.
173
+ *
174
+ * @default 'core/details'
175
+ */
176
+ defaultPanel?: string;
150
177
  }
151
178
 
152
179
  interface MediaEditorSidebarProps {
@@ -206,6 +233,10 @@ function MediaEditorSidebar( {
206
233
  value={ tab.id }
207
234
  tabIndex={ -1 }
208
235
  className="media-editor__panel"
236
+ // A save reads the session once and then waits, so
237
+ // nothing in the panel may act on it meanwhile.
238
+ // `inert` covers panels that ignore `disabled`.
239
+ inert={ inertValue( disabled ) }
209
240
  >
210
241
  <Stack direction="column" gap="lg">
211
242
  { tab.render() }
@@ -248,11 +279,16 @@ interface MediaEditorFrameContextValue {
248
279
  canRestoreOriginal: boolean;
249
280
  /**
250
281
  * When `true`, another attachment has replaced the edited one in the
251
- * cropper this session (today, only the original), so the menu item is
282
+ * image editor this session (today, only the original), so the menu item is
252
283
  * disabled.
253
284
  */
254
285
  isSourceReplaced: boolean;
255
- /** Load the lineage root into the cropper as a dirty preview. */
286
+ /** Whether the frame opens the original itself. */
287
+ opensOriginal: boolean;
288
+ /**
289
+ * Load the lineage root into the image editor, or hand it to the
290
+ * frame.
291
+ */
256
292
  onRestoreOriginal: () => void;
257
293
  }
258
294
 
@@ -276,6 +312,20 @@ function useMediaEditorFrameContext(): MediaEditorFrameContextValue {
276
312
  return context;
277
313
  }
278
314
 
315
+ function CropPanelContent( { disabled }: MediaEditorPanelFillProps ) {
316
+ const { aspectRatioPresets } = useMediaEditorFrameContext();
317
+ const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
318
+ useCropOptions( { aspectRatioPresets } );
319
+ return (
320
+ <MediaEditorCropPanel
321
+ aspectRatioValue={ aspectRatioValue }
322
+ onAspectRatioChange={ setAspectRatioValue }
323
+ aspectRatioOptions={ aspectRatioOptions }
324
+ disabled={ disabled }
325
+ />
326
+ );
327
+ }
328
+
279
329
  export interface HeaderActionsProps {
280
330
  /**
281
331
  * Whether to include a Close button. Frames with a dismissal affordance of
@@ -307,10 +357,75 @@ function PanelToggle() {
307
357
  );
308
358
  }
309
359
 
310
- function MoreMenu() {
311
- const { isImage } = useMediaEditorFrameContext();
360
+ function getActionLabel( action: Action< Media >, items: Media[] ) {
361
+ return typeof action.label === 'string'
362
+ ? action.label
363
+ : action.label( items );
364
+ }
365
+
366
+ interface MediaActionModalProps {
367
+ action: ActionModal< Media >;
368
+ items: Media[];
369
+ closeModal: () => void;
370
+ }
371
+
372
+ // A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't
373
+ // exported. It could be replaced if dataviews exports it.
374
+ function MediaActionModal( {
375
+ action,
376
+ items,
377
+ closeModal,
378
+ }: MediaActionModalProps ) {
379
+ const header =
380
+ typeof action.modalHeader === 'function'
381
+ ? action.modalHeader( items )
382
+ : action.modalHeader;
383
+ return (
384
+ <Modal
385
+ title={ header || getActionLabel( action, items ) }
386
+ __experimentalHideHeader={ !! action.hideModalHeader }
387
+ onRequestClose={ closeModal }
388
+ focusOnMount={ action.modalFocusOnMount ?? true }
389
+ size={ action.modalSize || 'medium' }
390
+ >
391
+ <action.RenderModal items={ items } closeModal={ closeModal } />
392
+ </Modal>
393
+ );
394
+ }
395
+
396
+ export interface MoreMenuProps {
397
+ /**
398
+ * Actions for the attachment, such as those from the entity actions API.
399
+ * Only the ones whose `isEligible` passes for `item` are shown.
400
+ */
401
+ actions?: Action< Media >[];
402
+ /**
403
+ * The attachment the actions apply to, with anything their `isEligible`
404
+ * checks need, such as `permissions`. Without it no actions are shown.
405
+ */
406
+ item?: Media;
407
+ }
408
+
409
+ function MoreMenu( { actions = [], item }: MoreMenuProps ) {
410
+ const { isImage, isSaving } = useMediaEditorFrameContext();
411
+ const registry = useRegistry();
312
412
  const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
313
- if ( ! isImage ) {
413
+ const [ activeModalAction, setActiveModalAction ] =
414
+ useState< ActionModal< Media > | null >( null );
415
+
416
+ const items = item ? [ item ] : [];
417
+ const eligibleActions = useMemo(
418
+ () =>
419
+ item
420
+ ? actions.filter(
421
+ ( action ) =>
422
+ ! action.isEligible || action.isEligible( item )
423
+ )
424
+ : [],
425
+ [ actions, item ]
426
+ );
427
+
428
+ if ( ! isImage && ! eligibleActions.length ) {
314
429
  return null;
315
430
  }
316
431
  return (
@@ -321,18 +436,63 @@ function MoreMenu() {
321
436
  toggleProps={ { size: 'compact' } }
322
437
  >
323
438
  { ( { onClose: closeMenu } ) => (
324
- <MenuGroup>
325
- <MenuItem
326
- icon={ keyboard }
327
- iconPosition="left"
328
- onClick={ () => {
329
- setIsShortcutsModalOpen( true );
330
- closeMenu();
331
- } }
332
- >
333
- { __( 'Keyboard shortcuts' ) }
334
- </MenuItem>
335
- </MenuGroup>
439
+ <>
440
+ { isImage && (
441
+ <MenuGroup>
442
+ <MenuItem
443
+ icon={ keyboard }
444
+ iconPosition="left"
445
+ onClick={ () => {
446
+ setIsShortcutsModalOpen( true );
447
+ closeMenu();
448
+ } }
449
+ >
450
+ { __( 'Keyboard shortcuts' ) }
451
+ </MenuItem>
452
+ </MenuGroup>
453
+ ) }
454
+ { !! eligibleActions.length && (
455
+ <MenuGroup>
456
+ { eligibleActions.map( ( action ) => {
457
+ const label = getActionLabel(
458
+ action,
459
+ items
460
+ );
461
+ return (
462
+ <MenuItem
463
+ key={ action.id }
464
+ disabled={
465
+ isSaving || action.disabled
466
+ }
467
+ onClick={ () => {
468
+ closeMenu();
469
+ if ( 'RenderModal' in action ) {
470
+ setActiveModalAction(
471
+ action
472
+ );
473
+ return;
474
+ }
475
+ action.callback( items, {
476
+ registry,
477
+ } );
478
+ } }
479
+ >
480
+ { 'RenderModal' in action
481
+ ? sprintf(
482
+ /* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */
483
+ _x(
484
+ '%s…',
485
+ 'menu item requiring further input'
486
+ ),
487
+ label
488
+ )
489
+ : label }
490
+ </MenuItem>
491
+ );
492
+ } ) }
493
+ </MenuGroup>
494
+ ) }
495
+ </>
336
496
  ) }
337
497
  </DropdownMenu>
338
498
  { isShortcutsModalOpen && (
@@ -340,6 +500,13 @@ function MoreMenu() {
340
500
  onClose={ () => setIsShortcutsModalOpen( false ) }
341
501
  />
342
502
  ) }
503
+ { activeModalAction && (
504
+ <MediaActionModal
505
+ action={ activeModalAction }
506
+ items={ items }
507
+ closeModal={ () => setActiveModalAction( null ) }
508
+ />
509
+ ) }
343
510
  </>
344
511
  );
345
512
  }
@@ -378,6 +545,7 @@ function HistoryActions() {
378
545
  activePanel,
379
546
  canRestoreOriginal,
380
547
  isSourceReplaced,
548
+ opensOriginal,
381
549
  onRestoreOriginal,
382
550
  } = useMediaEditorFrameContext();
383
551
  const {
@@ -482,7 +650,9 @@ function HistoryActions() {
482
650
  closeMenu();
483
651
  } }
484
652
  >
485
- { __( 'Restore original' ) }
653
+ { opensOriginal
654
+ ? __( 'Edit original' )
655
+ : __( 'Restore original' ) }
486
656
  </MenuItem>
487
657
  </MenuGroup>
488
658
  ) }
@@ -546,10 +716,12 @@ function MediaEditorContent( {
546
716
  aspectRatioPresets,
547
717
  onClose,
548
718
  onSaved,
719
+ onEditOriginal,
549
720
  renderFrame,
550
721
  noticesClassName = 'media-editor__snackbar',
551
722
  noticesPortalElement,
552
723
  shouldCloseOnEsc = false,
724
+ defaultPanel = DETAILS_PANEL,
553
725
  }: MediaEditorProps ) {
554
726
  const session = useMediaEditor();
555
727
  // Width decides whether the settings panel docks beside the canvas or
@@ -601,17 +773,33 @@ function MediaEditorContent( {
601
773
 
602
774
  const { clearEntityRecordEdits, editEntityRecord, invalidateResolution } =
603
775
  useDispatch( coreStore );
604
- const { removeAllNotices } = useDispatch( noticesStore );
776
+ const { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );
777
+ // `PluginArea` drops a plugin whose render throws; tell the user.
778
+ const handlePluginError = useCallback(
779
+ ( name: string ) => {
780
+ createErrorNotice(
781
+ sprintf(
782
+ /* translators: %s: plugin name */
783
+ __(
784
+ 'The "%s" plugin has encountered an error and cannot be rendered.'
785
+ ),
786
+ name
787
+ ),
788
+ { type: 'snackbar', context: MEDIA_EDITOR_NOTICES_CONTEXT }
789
+ );
790
+ },
791
+ [ createErrorNotice ]
792
+ );
605
793
 
606
794
  const [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );
607
795
  const [ isPlacementActive, setIsPlacementActive ] = useState( false );
608
796
  const [ isCanvasGestureActive, setIsCanvasGestureActive ] =
609
797
  useState( false );
610
- // Whether another attachment has replaced `id` in the cropper this
798
+ // Whether another attachment has replaced `id` in the image editor this
611
799
  // session (today, the original via "Restore original image"). Stays a
612
- // distinct flag (not derived from the cropper) so a bare replacement
800
+ // distinct flag (not derived from the image editor) so a bare replacement
613
801
  // counts as a change even though swapping the source resets the
614
- // cropper's own dirty baseline.
802
+ // image editor's own dirty baseline.
615
803
  const [ isSourceReplaced, setIsSourceReplaced ] = useState( false );
616
804
  const placementControlTimerRef = useRef<
617
805
  ReturnType< typeof setTimeout > | undefined
@@ -642,7 +830,7 @@ function MediaEditorContent( {
642
830
  // exposed by the server as the root-level `edit_root` id on the
643
831
  // attachment (edit context, embeddable via the `wp:edit-root` link).
644
832
  // Fetch the original's record for the URL and natural dimensions the
645
- // cropper needs to seed itself.
833
+ // image editor needs to seed itself.
646
834
  const originalId: number | undefined = sourceMedia?.edit_root;
647
835
  const originalRecord = useSelect(
648
836
  ( select ) =>
@@ -727,22 +915,25 @@ function MediaEditorContent( {
727
915
  // Restoring discards every pending edit, as the menu item says, so
728
916
  // nothing staged against the attachment being replaced reaches a save.
729
917
  clearEntityRecordEdits( 'postType', 'attachment', id );
918
+ if ( onEditOriginal && originalId ) {
919
+ onEditOriginal( originalId );
920
+ return;
921
+ }
730
922
  setIsSourceReplaced( true );
731
- }, [ clearEntityRecordEdits, id ] );
923
+ }, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );
732
924
 
733
- // A bare replacement has no cropper diff, so OR the flag in explicitly.
925
+ // A bare replacement has no image editor change, so OR the flag in explicitly.
926
+ // Nothing saves named edits (`session.edits`), so `hasOutputEdits` leaves
927
+ // them out: counting them would enable Save for a change it then drops.
734
928
  const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
735
929
 
736
930
  const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
737
931
  const isImage = !! media && mediaType === 'image';
738
932
 
739
- // Docked, the panel opens on Crop: the canvas is still beside it and
740
- // cropping is what the editor is for. Below `small` an open panel covers
741
- // the canvas, and crop controls with no crop in sight are not worth
742
- // opening on, so Details leads there. Non-image media has no Crop tab at
743
- // all (see `tabs`), so it always gets Details.
744
- const currentTab =
745
- chosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );
933
+ // Below `small` the panel covers the canvas, so open on Details rather
934
+ // than a panel that needs the canvas in view. If no tab matches
935
+ // `defaultPanel`, the sidebar shows Details (see `activeTab` below).
936
+ const currentTab = chosenTab ?? ( isWide ? defaultPanel : DETAILS_PANEL );
746
937
  // `null` when nothing is open, otherwise the open panel's id. Until the
747
938
  // user opens or closes the panel, follow the breakpoint: dragging a window
748
939
  // narrow hands the canvas the full width instead of leaving a panel
@@ -763,8 +954,6 @@ function MediaEditorContent( {
763
954
  const togglePanel = useCallback( () => {
764
955
  setChosenPanel( activePanel ? null : currentTab );
765
956
  }, [ activePanel, currentTab ] );
766
- const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
767
- useCropOptions( { aspectRatioPresets } );
768
957
  const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
769
958
  session,
770
959
  id,
@@ -804,45 +993,47 @@ function MediaEditorContent( {
804
993
  discardAndClose();
805
994
  };
806
995
 
807
- const handleKeyDown = ( event: ReactKeyboardEvent< HTMLElement > ) => {
808
- const isUndoShortcut = isKeyboardEvent.primary( event, 'z' );
809
- const isRedoShortcut =
810
- isKeyboardEvent.primaryShift( event, 'z' ) ||
811
- ( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );
812
- if ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {
813
- const target = event.target as HTMLElement;
814
- const isMetadataField =
815
- ( target.tagName === 'INPUT' ||
816
- target.tagName === 'TEXTAREA' ||
817
- target.isContentEditable ) &&
818
- ! target.closest( `[${ CROP_CONTROL_ATTR }]` );
819
- if ( ! isMetadataField ) {
820
- event.preventDefault();
821
- if ( isCropInteractionActive || isSaving ) {
822
- return;
823
- }
824
- if ( isRedoShortcut ) {
825
- session.redo();
826
- } else {
827
- session.undo();
996
+ const handleKeyDown = withIgnoreIMEEvents(
997
+ ( event: ReactKeyboardEvent< HTMLElement > ) => {
998
+ const isUndoShortcut = isKeyboardEvent.primary( event, 'z' );
999
+ const isRedoShortcut =
1000
+ isKeyboardEvent.primaryShift( event, 'z' ) ||
1001
+ ( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );
1002
+ if ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {
1003
+ const target = event.target as HTMLElement;
1004
+ const isMetadataField =
1005
+ ( target.tagName === 'INPUT' ||
1006
+ target.tagName === 'TEXTAREA' ||
1007
+ target.isContentEditable ) &&
1008
+ ! target.closest( `[${ CROP_CONTROL_ATTR }]` );
1009
+ if ( ! isMetadataField ) {
1010
+ event.preventDefault();
1011
+ if ( isCropInteractionActive || isSaving ) {
1012
+ return;
1013
+ }
1014
+ if ( isRedoShortcut ) {
1015
+ session.redo();
1016
+ } else {
1017
+ session.undo();
1018
+ }
828
1019
  }
829
1020
  }
830
- }
831
1021
 
832
- if ( shouldCloseOnEsc ) {
833
- if ( event.code !== 'Escape' && event.key !== 'Escape' ) {
834
- return;
835
- }
836
- if ( isSaving ) {
837
- event.preventDefault();
838
- return;
839
- }
840
- if ( hasChanges ) {
841
- event.preventDefault();
842
- setIsDiscardDialogOpen( true );
1022
+ if ( shouldCloseOnEsc ) {
1023
+ if ( event.code !== 'Escape' && event.key !== 'Escape' ) {
1024
+ return;
1025
+ }
1026
+ if ( isSaving ) {
1027
+ event.preventDefault();
1028
+ return;
1029
+ }
1030
+ if ( hasChanges ) {
1031
+ event.preventDefault();
1032
+ setIsDiscardDialogOpen( true );
1033
+ }
843
1034
  }
844
1035
  }
845
- };
1036
+ );
846
1037
 
847
1038
  const snackbar = (
848
1039
  <SnackbarNotices
@@ -865,32 +1056,31 @@ function MediaEditorContent( {
865
1056
  />
866
1057
  ) : null;
867
1058
 
868
- // Crop leads, since it is what the docked panel opens on. Non-image media
869
- // has nothing to crop and gets Details alone, which is why the sidebar
870
- // takes this list rather than deriving it.
871
- const tabs: MediaEditorTab[] = [
872
- ...( isImage
873
- ? [
874
- {
875
- id: CROP_PANEL,
876
- title: __( 'Crop' ),
877
- render: () => (
878
- <MediaEditorCropPanel
879
- aspectRatioValue={ aspectRatioValue }
880
- onAspectRatioChange={ setAspectRatioValue }
881
- aspectRatioOptions={ aspectRatioOptions }
882
- disabled={ isSaving }
883
- />
884
- ),
885
- },
886
- ]
887
- : [] ),
888
- {
889
- id: DETAILS_PANEL,
890
- title: __( 'Details' ),
891
- render: () => <MediaForm />,
892
- },
893
- ];
1059
+ const { panels, contextValue: panelsContextValue } = useMediaEditorPanels();
1060
+ const availableTabs: MediaEditorTab[] = panels
1061
+ .filter(
1062
+ ( panel ) =>
1063
+ ! panel.mediaTypes || panel.mediaTypes.includes( mediaType )
1064
+ )
1065
+ .map( ( panel ) => ( {
1066
+ id: panel.name,
1067
+ title: panel.title,
1068
+ render: () => (
1069
+ <Slot
1070
+ bubblesVirtually
1071
+ name={ getPanelSlotName( panel.name ) }
1072
+ fillProps={ { disabled: isSaving } }
1073
+ />
1074
+ ),
1075
+ } ) );
1076
+ // Put the default panel first and keep the others in order.
1077
+ const defaultTab = availableTabs.find( ( tab ) => tab.id === defaultPanel );
1078
+ const tabs = defaultTab
1079
+ ? [
1080
+ defaultTab,
1081
+ ...availableTabs.filter( ( tab ) => tab !== defaultTab ),
1082
+ ]
1083
+ : availableTabs;
894
1084
 
895
1085
  const ruler = isImage ? (
896
1086
  <MediaEditorFineRotation
@@ -900,23 +1090,7 @@ function MediaEditorContent( {
900
1090
  ) : null;
901
1091
 
902
1092
  const children = (
903
- <MediaEditorProvider
904
- value={ media ?? undefined }
905
- onChange={ handleChange }
906
- settings={ {
907
- // Disable the fields while saving, so the guard in
908
- // `handleChange` is not silently swallowing typing.
909
- // `readOnly` would swap the field's layout mid-save;
910
- // disabled keeps it in place and greys it out.
911
- fields: isSaving
912
- ? fields.map( ( field ) => ( {
913
- ...field,
914
- isDisabled: true,
915
- } ) )
916
- : fields,
917
- form,
918
- } }
919
- >
1093
+ <>
920
1094
  <div className="media-editor">
921
1095
  { ! media ? (
922
1096
  <div className="media-editor__loading">
@@ -970,25 +1144,31 @@ function MediaEditorContent( {
970
1144
  exit="closed"
971
1145
  transition={ sidebarTransition }
972
1146
  >
973
- <MediaEditorSidebar
974
- tabs={ tabs }
975
- // Swapping the edited media can drop the
976
- // Crop tab out from under an open panel —
977
- // saving a crop moves the editor to a new
978
- // id, which may resolve as non-image.
979
- // Fall back rather than hand `Tabs.Root`
980
- // a value no tab matches.
981
- activeTab={
982
- tabs.some(
983
- ( tab ) =>
984
- tab.id === activePanel
985
- )
986
- ? activePanel
987
- : DETAILS_PANEL
988
- }
989
- onSelectTab={ selectPanel }
990
- disabled={ isSaving }
991
- />
1147
+ { /* Panels announce their tabs after the
1148
+ first render. Waiting for them outside
1149
+ this container would slide it in on
1150
+ every open. */ }
1151
+ { tabs.length > 0 && (
1152
+ <MediaEditorSidebar
1153
+ tabs={ tabs }
1154
+ // Swapping the edited media can drop the
1155
+ // Crop tab out from under an open panel —
1156
+ // saving a crop moves the editor to a new
1157
+ // id, which may resolve as non-image.
1158
+ // Fall back rather than hand `Tabs.Root`
1159
+ // a value no tab matches.
1160
+ activeTab={
1161
+ tabs.some(
1162
+ ( tab ) =>
1163
+ tab.id === activePanel
1164
+ )
1165
+ ? activePanel
1166
+ : DETAILS_PANEL
1167
+ }
1168
+ onSelectTab={ selectPanel }
1169
+ disabled={ isSaving }
1170
+ />
1171
+ ) }
992
1172
  </motion.div>
993
1173
  ) }
994
1174
  </AnimatePresence>
@@ -1012,7 +1192,7 @@ function MediaEditorContent( {
1012
1192
  { noticesPortalElement
1013
1193
  ? createPortal( snackbar, noticesPortalElement )
1014
1194
  : snackbar }
1015
- </MediaEditorProvider>
1195
+ </>
1016
1196
  );
1017
1197
 
1018
1198
  // Rebuilt each render, like the elements it replaces: consumers re-render
@@ -1034,13 +1214,63 @@ function MediaEditorContent( {
1034
1214
  onSave: saveMediaEditor,
1035
1215
  canRestoreOriginal,
1036
1216
  isSourceReplaced,
1217
+ opensOriginal: !! onEditOriginal,
1037
1218
  onRestoreOriginal: handleRestoreOriginal,
1038
1219
  };
1039
1220
 
1040
1221
  return (
1041
1222
  <MediaEditorFrameContext.Provider value={ contextValue }>
1042
1223
  { renderFrame( {
1043
- children,
1224
+ children: (
1225
+ <MediaEditorProvider
1226
+ value={ media ?? undefined }
1227
+ onChange={ handleChange }
1228
+ settings={ {
1229
+ // Disable the fields while saving, so the guard in
1230
+ // `handleChange` is not silently swallowing typing.
1231
+ // `readOnly` would swap the field's layout mid-save;
1232
+ // disabled keeps it in place and greys it out.
1233
+ fields: isSaving
1234
+ ? fields.map( ( field ) => ( {
1235
+ ...field,
1236
+ isDisabled: true,
1237
+ } ) )
1238
+ : fields,
1239
+ form,
1240
+ } }
1241
+ >
1242
+ <SlotFillProvider>
1243
+ <MediaEditorPanelsProvider
1244
+ value={ panelsContextValue }
1245
+ >
1246
+ { /* Inside the session and `MediaEditorProvider`, so
1247
+ panel content can read both. */ }
1248
+ <MediaEditorPanel
1249
+ name={ CROP_PANEL }
1250
+ title={ __( 'Crop' ) }
1251
+ mediaTypes={ CROP_MEDIA_TYPES }
1252
+ >
1253
+ { ( { disabled } ) => (
1254
+ <CropPanelContent
1255
+ disabled={ disabled }
1256
+ />
1257
+ ) }
1258
+ </MediaEditorPanel>
1259
+ <MediaEditorPanel
1260
+ name={ DETAILS_PANEL }
1261
+ title={ __( 'Details' ) }
1262
+ >
1263
+ <MediaForm />
1264
+ </MediaEditorPanel>
1265
+ <PluginArea
1266
+ scope={ MEDIA_EDITOR_PLUGIN_SCOPE }
1267
+ onError={ handlePluginError }
1268
+ />
1269
+ { children }
1270
+ </MediaEditorPanelsProvider>
1271
+ </SlotFillProvider>
1272
+ </MediaEditorProvider>
1273
+ ),
1044
1274
  isImage,
1045
1275
  layout,
1046
1276
  onRequestClose: handleRequestClose,