@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
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation } = useMediaEditor().cropper;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAwB,wBAAyB,EAChD,+BACA,WAAW,SACsB;CACjC,MAAM,EAAE,OAAO,gBAAgB,eAAe,CAAC,CAAC;CAIhD,MAAM,0BAA0B,uBAAwB,EACvD,eAAe,MAChB,CAAE;CAKF,MAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CAEtD,MAAM,YADa,MAAM,KAAK,eAAe,MAAM,KAAK,WACzB,KAAK;CACpC,MAAM,cAAe,MAAM,WAAW,aAAc;CAEpD,MAAM,wBAAyB,UAAmB;EAIjD,MAAM,MAAM;EACZ,MAAM,UAAU,KAAK,IACpB,CAAC,sBAAsB,KACvB,KAAK,IAAK,sBAAsB,KAAK,KAAM,CAC5C;EACA,gCAAgC;EAChC,YAAa,YAAY,UAAU,SAAU;CAC9C;CAEA,OACC,oBAAC,OAAD;EACC,MAAK;EACL,WAAU;EACV,GAAK;EAEL,UAAA,oBAAC,eAAD;GACC,OAAQ,GAAI,eAAgB;GAC5B,KAAM,CAAC;GACP,KAAM;GACN,OAAQ;GACR,UAAW;GACA;EACX,CAAA;CACG,CAAA;AAEP"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation, maxRotationOffset } =\n\t\tuseMediaEditor().imageEditor;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-maxRotationOffset + EPS,\n\t\t\tMath.min( maxRotationOffset - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -maxRotationOffset }\n\t\t\t\tmax={ maxRotationOffset }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAwB,wBAAyB,EAChD,+BACA,WAAW,SACsB;CACjC,MAAM,EAAE,OAAO,aAAa,sBAC3B,eAAe,CAAC,CAAC;CAIlB,MAAM,0BAA0B,uBAAwB,EACvD,eAAe,MAChB,CAAE;CAKF,MAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CAEtD,MAAM,YADa,MAAM,KAAK,eAAe,MAAM,KAAK,WACzB,KAAK;CACpC,MAAM,cAAe,MAAM,WAAW,aAAc;CAEpD,MAAM,wBAAyB,UAAmB;EAIjD,MAAM,MAAM;EACZ,MAAM,UAAU,KAAK,IACpB,CAAC,oBAAoB,KACrB,KAAK,IAAK,oBAAoB,KAAK,KAAM,CAC1C;EACA,gCAAgC;EAChC,YAAa,YAAY,UAAU,SAAU;CAC9C;CAEA,OACC,oBAAC,OAAD;EACC,MAAK;EACL,WAAU;EACV,GAAK;EAEL,UAAA,oBAAC,eAAD;GACC,OAAQ,GAAI,eAAgB;GAC5B,KAAM,CAAC;GACP,KAAM;GACN,OAAQ;GACR,UAAW;GACA;EACX,CAAA;CACG,CAAA;AAEP"}
@@ -1,10 +1,8 @@
1
1
  import { Button } from "@wordpress/components";
2
2
  import { Menu } from "@wordpress/ui";
3
3
  import { __ } from "@wordpress/i18n";
4
- import { aspectRatio, flipHorizontal, flipVertical, lineSolid, plus, rotateLeft, rotateRight } from "@wordpress/icons";
4
+ import { aspectRatio, flipHorizontal, flipVertical, getAspectRatioIcon, lineSolid, plus, rotateLeft, rotateRight } from "@wordpress/icons";
5
5
  import { useMediaEditor } from "../../state/index.mjs";
6
- import { MAX_ZOOM } from "../../image-editor/core/constants.mjs";
7
- import { getMinZoom } from "../../image-editor/core/containment.mjs";
8
6
  import { useCropOptions } from "../media-editor/use-crop-options.mjs";
9
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
8
  // packages/media-editor/src/components/media-editor-image-controls/index.tsx
@@ -30,12 +28,11 @@ const DEFAULT_ZOOM_FACTOR = 1.2;
30
28
  * @param props.disabled
31
29
  */
32
30
  function MediaEditorImageControls({ withLabels = false, showAspectRatioControl = false, aspectRatioPresets, zoomFactor = DEFAULT_ZOOM_FACTOR, disabled = false }) {
33
- const { state, setFlip, snapRotate90, setZoom } = useMediaEditor().cropper;
31
+ const { state, setFlip, snapRotate90, setZoom, minZoom, maxZoom } = useMediaEditor().imageEditor;
34
32
  const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } = useCropOptions({ aspectRatioPresets });
35
33
  const hasAspectRatioControl = !withLabels && showAspectRatioControl;
36
- const minZoom = getMinZoom(state);
37
34
  const zoomByFactor = (factor) => {
38
- setZoom(Math.min(MAX_ZOOM, Math.max(minZoom, state.zoom * factor)));
35
+ setZoom(Math.min(maxZoom, Math.max(minZoom, state.zoom * factor)));
39
36
  };
40
37
  const rotateButtons = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
41
38
  size: "compact",
@@ -84,7 +81,7 @@ function MediaEditorImageControls({ withLabels = false, showAspectRatioControl =
84
81
  icon: plus,
85
82
  label: __("Zoom in"),
86
83
  showTooltip: true,
87
- disabled: disabled || state.zoom >= MAX_ZOOM,
84
+ disabled: disabled || state.zoom >= maxZoom,
88
85
  accessibleWhenDisabled: true,
89
86
  onClick: () => zoomByFactor(zoomFactor)
90
87
  }), /* @__PURE__ */ jsx(Button, {
@@ -118,6 +115,7 @@ function MediaEditorImageControls({ withLabels = false, showAspectRatioControl =
118
115
  value: preset.value.toString(),
119
116
  closeOnClick: true,
120
117
  disabled,
118
+ prefix: /* @__PURE__ */ jsx(Menu.PrefixIcon, { icon: getAspectRatioIcon(preset.value) }),
121
119
  children: /* @__PURE__ */ jsx(Menu.ItemLabel, { children: preset.label })
122
120
  }, preset.value))]
123
121
  })
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["aspectRatioIcon"],"sources":["../../../src/components/media-editor-image-controls/index.tsx"],"sourcesContent":["import { Button } from '@wordpress/components';\nimport {\n\t// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.\n\tMenu,\n} from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport {\n\taspectRatio as aspectRatioIcon,\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tlineSolid,\n\tplus,\n} from '@wordpress/icons';\nimport { useMediaEditor } from '../../state';\nimport {\n\tMAX_ZOOM,\n\ttype AspectRatioPreset,\n} from '../../image-editor/core/constants';\nimport { getMinZoom } from '../../image-editor/core/containment';\nimport { useCropOptions } from '../media-editor/use-crop-options';\n\n/**\n * Default zoom factor per +/- click. Zooming is geometric, so a fixed\n * multiplier — rather than an additive step — makes each click feel like the\n * same amount of zoom at any level (an additive `+0.1` is a 10% jump at 1× but\n * a ~1% nudge at 10×). `1.2` is ~+20% per click. Overridable via the\n * `zoomFactor` prop.\n */\nexport const DEFAULT_ZOOM_FACTOR = 1.2;\n\nexport interface MediaEditorImageControlsProps {\n\t/**\n\t * When `true`, render rotate, flip and zoom as labelled groups — the Crop\n\t * panel layout used on wide viewports. When `false` (default), render a\n\t * single flat row of icon buttons — the footer layout used at narrower\n\t * widths.\n\t */\n\twithLabels?: boolean;\n\t/**\n\t * When `true`, include an aspect-ratio dropdown in the flat toolbar.\n\t * Omitted from the labelled panel layout because the Crop panel already\n\t * renders the full aspect-ratio select control.\n\t */\n\tshowAspectRatioControl?: boolean;\n\t/** Optional caller-supplied aspect-ratio presets. */\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/**\n\t * Multiplier applied to the zoom per +/- click — zoom in multiplies by it,\n\t * zoom out divides by it. Must be greater than 1. Defaults to\n\t * `DEFAULT_ZOOM_FACTOR` (1.2).\n\t */\n\tzoomFactor?: number;\n\t/**\n\t * Disable every control. Set while the edit is saving, so the crop the\n\t * request was built from cannot change under it.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Image editing controls placed independently per viewport: on wide viewports\n * rotate/flip/zoom render inside the Crop panel (`withLabels`), and at narrower\n * widths they fall back into the footer toolbar (flat row), where the\n * aspect-ratio dropdown can also be shown.\n *\n * @param props\n * @param props.withLabels\n * @param props.showAspectRatioControl\n * @param props.aspectRatioPresets\n * @param props.zoomFactor\n * @param props.disabled\n */\nexport default function MediaEditorImageControls( {\n\twithLabels = false,\n\tshowAspectRatioControl = false,\n\taspectRatioPresets,\n\tzoomFactor = DEFAULT_ZOOM_FACTOR,\n\tdisabled = false,\n}: MediaEditorImageControlsProps ) {\n\tconst { state, setFlip, snapRotate90, setZoom } = useMediaEditor().cropper;\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst hasAspectRatioControl = ! withLabels && showAspectRatioControl;\n\tconst minZoom = getMinZoom( state );\n\tconst zoomByFactor = ( factor: number ) => {\n\t\tsetZoom(\n\t\t\tMath.min( MAX_ZOOM, Math.max( minZoom, state.zoom * factor ) )\n\t\t);\n\t};\n\n\tconst rotateButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90° counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90° clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst flipButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst zoomButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ plus }\n\t\t\t\tlabel={ __( 'Zoom in' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom >= MAX_ZOOM }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( zoomFactor ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ lineSolid }\n\t\t\t\tlabel={ __( 'Zoom out' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom <= minZoom }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( 1 / zoomFactor ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst aspectRatioDropdown = hasAspectRatioControl ? (\n\t\t<Menu.Root>\n\t\t\t<Menu.Trigger\n\t\t\t\tdisabled={ disabled }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ticon={ aspectRatioIcon }\n\t\t\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Menu.Popup\n\t\t\t\tpositioner={ <Menu.Positioner side=\"top\" align=\"center\" /> }\n\t\t\t>\n\t\t\t\t<Menu.RadioGroup\n\t\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\t\tonValueChange={ ( value ) => {\n\t\t\t\t\t\tif ( ! disabled ) {\n\t\t\t\t\t\t\tsetAspectRatioValue( value );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Menu.GroupLabel>{ __( 'Aspect ratio' ) }</Menu.GroupLabel>\n\t\t\t\t\t{ aspectRatioOptions.map( ( preset ) => (\n\t\t\t\t\t\t<Menu.RadioItem\n\t\t\t\t\t\t\tkey={ preset.value }\n\t\t\t\t\t\t\tvalue={ preset.value.toString() }\n\t\t\t\t\t\t\tcloseOnClick\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Menu.ItemLabel>{ preset.label }</Menu.ItemLabel>\n\t\t\t\t\t\t</Menu.RadioItem>\n\t\t\t\t\t) ) }\n\t\t\t\t</Menu.RadioGroup>\n\t\t\t</Menu.Popup>\n\t\t</Menu.Root>\n\t) : null;\n\n\tif ( withLabels ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-image-controls is-stacked\">\n\t\t\t\t<div className=\"media-editor-image-controls__transforms\">\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Rotate' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rotate' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ rotateButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Flip' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Flip' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ flipButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label={ __( 'Zoom' ) }\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Zoom' ) }\n\t\t\t\t\t</span>\n\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t{ zoomButtons }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-image-controls\">\n\t\t\t{ rotateButtons }\n\t\t\t{ flipButtons }\n\t\t\t{ zoomButtons }\n\t\t\t{ aspectRatioDropdown }\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,MAAa,sBAAsB;;;;;;;;;;;;;;AA4CnC,SAAwB,yBAA0B,EACjD,aAAa,OACb,yBAAyB,OACzB,oBACA,aAAa,qBACb,WAAW,SACuB;CAClC,MAAM,EAAE,OAAO,SAAS,cAAc,YAAY,eAAe,CAAC,CAAC;CACnE,MAAM,EAAE,kBAAkB,qBAAqB,uBAC9C,eAAgB,EAAE,mBAAmB,CAAE;CACxC,MAAM,wBAAwB,CAAE,cAAc;CAC9C,MAAM,UAAU,WAAY,KAAM;CAClC,MAAM,gBAAiB,WAAoB;EAC1C,QACC,KAAK,IAAK,UAAU,KAAK,IAAK,SAAS,MAAM,OAAO,MAAO,CAAE,CAC9D;CACD;CAEA,MAAM,gBACL,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EACC,MAAK;EACL,MAAO;EACP,OAAQ,GAAI,8BAA+B;EAC3C,aA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;GACR,CAAA,GACN,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,CACD;EACD,CAAA,CAAA;;CAIP,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACG;GACA;GACA;GACA;EACE;;AAEP"}
1
+ {"version":3,"file":"index.mjs","names":["aspectRatioIcon"],"sources":["../../../src/components/media-editor-image-controls/index.tsx"],"sourcesContent":["import { Button } from '@wordpress/components';\nimport {\n\t// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.\n\tMenu,\n} from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport {\n\taspectRatio as aspectRatioIcon,\n\tgetAspectRatioIcon,\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tlineSolid,\n\tplus,\n} from '@wordpress/icons';\nimport { useMediaEditor } from '../../state';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { useCropOptions } from '../media-editor/use-crop-options';\n\n/**\n * Default zoom factor per +/- click. Zooming is geometric, so a fixed\n * multiplier — rather than an additive step — makes each click feel like the\n * same amount of zoom at any level (an additive `+0.1` is a 10% jump at 1× but\n * a ~1% nudge at 10×). `1.2` is ~+20% per click. Overridable via the\n * `zoomFactor` prop.\n */\nexport const DEFAULT_ZOOM_FACTOR = 1.2;\n\nexport interface MediaEditorImageControlsProps {\n\t/**\n\t * When `true`, render rotate, flip and zoom as labelled groups — the Crop\n\t * panel layout used on wide viewports. When `false` (default), render a\n\t * single flat row of icon buttons — the footer layout used at narrower\n\t * widths.\n\t */\n\twithLabels?: boolean;\n\t/**\n\t * When `true`, include an aspect-ratio dropdown in the flat toolbar.\n\t * Omitted from the labelled panel layout because the Crop panel already\n\t * renders the full aspect-ratio select control.\n\t */\n\tshowAspectRatioControl?: boolean;\n\t/** Optional caller-supplied aspect-ratio presets. */\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/**\n\t * Multiplier applied to the zoom per +/- click — zoom in multiplies by it,\n\t * zoom out divides by it. Must be greater than 1. Defaults to\n\t * `DEFAULT_ZOOM_FACTOR` (1.2).\n\t */\n\tzoomFactor?: number;\n\t/**\n\t * Disable every control. Set while the edit is saving, so the crop the\n\t * request was built from cannot change under it.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Image editing controls placed independently per viewport: on wide viewports\n * rotate/flip/zoom render inside the Crop panel (`withLabels`), and at narrower\n * widths they fall back into the footer toolbar (flat row), where the\n * aspect-ratio dropdown can also be shown.\n *\n * @param props\n * @param props.withLabels\n * @param props.showAspectRatioControl\n * @param props.aspectRatioPresets\n * @param props.zoomFactor\n * @param props.disabled\n */\nexport default function MediaEditorImageControls( {\n\twithLabels = false,\n\tshowAspectRatioControl = false,\n\taspectRatioPresets,\n\tzoomFactor = DEFAULT_ZOOM_FACTOR,\n\tdisabled = false,\n}: MediaEditorImageControlsProps ) {\n\tconst { state, setFlip, snapRotate90, setZoom, minZoom, maxZoom } =\n\t\tuseMediaEditor().imageEditor;\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst hasAspectRatioControl = ! withLabels && showAspectRatioControl;\n\tconst zoomByFactor = ( factor: number ) => {\n\t\tsetZoom(\n\t\t\tMath.min( maxZoom, Math.max( minZoom, state.zoom * factor ) )\n\t\t);\n\t};\n\n\tconst rotateButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90° counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90° clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst flipButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst zoomButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ plus }\n\t\t\t\tlabel={ __( 'Zoom in' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom >= maxZoom }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( zoomFactor ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ lineSolid }\n\t\t\t\tlabel={ __( 'Zoom out' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom <= minZoom }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( 1 / zoomFactor ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst aspectRatioDropdown = hasAspectRatioControl ? (\n\t\t<Menu.Root>\n\t\t\t<Menu.Trigger\n\t\t\t\tdisabled={ disabled }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ticon={ aspectRatioIcon }\n\t\t\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Menu.Popup\n\t\t\t\tpositioner={ <Menu.Positioner side=\"top\" align=\"center\" /> }\n\t\t\t>\n\t\t\t\t<Menu.RadioGroup\n\t\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\t\tonValueChange={ ( value ) => {\n\t\t\t\t\t\tif ( ! disabled ) {\n\t\t\t\t\t\t\tsetAspectRatioValue( value );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Menu.GroupLabel>{ __( 'Aspect ratio' ) }</Menu.GroupLabel>\n\t\t\t\t\t{ aspectRatioOptions.map( ( preset ) => (\n\t\t\t\t\t\t<Menu.RadioItem\n\t\t\t\t\t\t\tkey={ preset.value }\n\t\t\t\t\t\t\tvalue={ preset.value.toString() }\n\t\t\t\t\t\t\tcloseOnClick\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\tprefix={\n\t\t\t\t\t\t\t\t<Menu.PrefixIcon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon( preset.value ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Menu.ItemLabel>{ preset.label }</Menu.ItemLabel>\n\t\t\t\t\t\t</Menu.RadioItem>\n\t\t\t\t\t) ) }\n\t\t\t\t</Menu.RadioGroup>\n\t\t\t</Menu.Popup>\n\t\t</Menu.Root>\n\t) : null;\n\n\tif ( withLabels ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-image-controls is-stacked\">\n\t\t\t\t<div className=\"media-editor-image-controls__transforms\">\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Rotate' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rotate' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ rotateButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Flip' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Flip' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ flipButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label={ __( 'Zoom' ) }\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Zoom' ) }\n\t\t\t\t\t</span>\n\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t{ zoomButtons }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-image-controls\">\n\t\t\t{ rotateButtons }\n\t\t\t{ flipButtons }\n\t\t\t{ zoomButtons }\n\t\t\t{ aspectRatioDropdown }\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAa,sBAAsB;;;;;;;;;;;;;;AA4CnC,SAAwB,yBAA0B,EACjD,aAAa,OACb,yBAAyB,OACzB,oBACA,aAAa,qBACb,WAAW,SACuB;CAClC,MAAM,EAAE,OAAO,SAAS,cAAc,SAAS,SAAS,YACvD,eAAe,CAAC,CAAC;CAClB,MAAM,EAAE,kBAAkB,qBAAqB,uBAC9C,eAAgB,EAAE,mBAAmB,CAAE;CACxC,MAAM,wBAAwB,CAAE,cAAc;CAC9C,MAAM,gBAAiB,WAAoB;EAC1C,QACC,KAAK,IAAK,SAAS,KAAK,IAAK,SAAS,MAAM,OAAO,MAAO,CAAE,CAC7D;CACD;CAEA,MAAM,gBACL,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EACC,MAAK;EACL,MAAO;EACP,OAAQ,GAAI,8BAA+B;EAC3C,aAAA;EACW;EACX,wBAAA;EACA,eAAgB,aAAc,EAAG;CACjC,CAAA,GACD,oBAAC,QAAD;EACC,MAAK;EACL,MAAO;EACP,OAAQ,GAAI,sBAAuB;EACnC,aAAA;EACW;EACX,wBAAA;EACA,eAAgB,aAAc,CAAE;CAChC,CAAA,CACA,EAAA,CAAA;CAGH,MAAM,cACL,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EACC,MAAK;EACL,MAAO;EACP,OAAQ,GAAI,i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ress/element";
3
3
  import { __ } from "@wordpress/i18n";
4
4
  import { displayShortcutList, shortcutAriaLabel } from "@wordpress/keycodes";
5
+ import { VisuallyHidden } from "@wordpress/ui";
5
6
  import { jsx, jsxs } from "react/jsx-runtime";
6
7
  // packages/media-editor/src/components/media-editor-keyboard-shortcuts-modal/index.tsx
7
8
  const SHORTCUTS = [
@@ -21,15 +22,13 @@ const SHORTCUTS = [
21
22
  },
22
23
  {
23
24
  description: __("Pan"),
24
- keyCombination: {
25
- character: [
26
- "↑",
27
- "↓",
28
- "←",
29
- "→"
30
- ],
31
- ariaLabel: __("Arrow keys")
32
- }
25
+ keyCombination: { character: [
26
+ "↑",
27
+ "↓",
28
+ "←",
29
+ "→"
30
+ ] },
31
+ label: __("Arrow keys")
33
32
  },
34
33
  {
35
34
  description: __("Zoom in"),
@@ -67,30 +66,31 @@ const SHORTCUTS = [
67
66
  "↓",
68
67
  "←",
69
68
  "→"
70
- ],
71
- ariaLabel: __("Shift + Arrow keys")
72
- }
69
+ ]
70
+ },
71
+ label: __("Shift + Arrow keys")
73
72
  }
74
73
  ];
75
- function KeyCombinationDisplay({ keyCombination }) {
76
- const { modifier, character, ariaLabel } = keyCombination;
77
- let keys;
78
- if (Array.isArray(character)) {
79
- if (modifier) keys = [...displayShortcutList[modifier](character[0]).slice(0, -1), ...character];
80
- else keys = character;
81
- } else keys = modifier ? displayShortcutList[modifier](character) : [character];
82
- const charString = Array.isArray(character) ? character.join("") : character;
83
- let label;
84
- if (ariaLabel) label = ariaLabel;
85
- else if (modifier) label = shortcutAriaLabel[modifier](charString);
86
- else label = charString;
87
- return /* @__PURE__ */ jsx("kbd", {
74
+ function KeyCombinationDisplay({ keyCombination, label }) {
75
+ const { character, modifier } = keyCombination;
76
+ const normalizedModifier = modifier ?? "undefined";
77
+ const characters = Array.isArray(character) ? character : [character];
78
+ const formatted = displayShortcutList[normalizedModifier](characters[0] ?? "");
79
+ const prefix = formatted.slice(0, -1);
80
+ const keys = Array.isArray(character) ? [...prefix, ...character] : formatted;
81
+ return /* @__PURE__ */ jsxs("kbd", {
88
82
  className: "media-editor-keyboard-shortcuts-modal__shortcut-term",
89
- "aria-label": label,
90
- children: keys.map((key, index) => key === "+" && modifier ? /* @__PURE__ */ jsx(Fragment, { children: key }, index) : /* @__PURE__ */ jsx("kbd", {
91
- className: "media-editor-keyboard-shortcuts-modal__shortcut-key",
92
- children: key
93
- }, index))
83
+ dir: "ltr",
84
+ children: [/* @__PURE__ */ jsx(VisuallyHidden, {
85
+ render: /* @__PURE__ */ jsx("span", {}),
86
+ children: label || shortcutAriaLabel[normalizedModifier](characters.join(""))
87
+ }), /* @__PURE__ */ jsx("span", {
88
+ "aria-hidden": "true",
89
+ children: keys.map((key, keyIndex) => key === "+" && keyIndex < prefix.length ? /* @__PURE__ */ jsx(Fragment, { children: key }, keyIndex) : /* @__PURE__ */ jsx("kbd", {
90
+ className: "media-editor-keyboard-shortcuts-modal__shortcut-key",
91
+ children: key
92
+ }, keyIndex))
93
+ })]
94
94
  });
95
95
  }
96
96
  function MediaEditorKeyboardShortcutsModal({ onClose }) {
@@ -104,12 +104,12 @@ function MediaEditorKeyboardShortcutsModal({ onClose }) {
104
104
  }), /* @__PURE__ */ jsx("ul", {
105
105
  className: "media-editor-keyboard-shortcuts-modal__shortcut-list",
106
106
  role: "list",
107
- children: SHORTCUTS.map(({ description, keyCombination }, index) => /* @__PURE__ */ jsxs("li", {
107
+ children: SHORTCUTS.map((shortcut, index) => /* @__PURE__ */ jsxs("li", {
108
108
  className: "media-editor-keyboard-shortcuts-modal__shortcut",
109
109
  children: [/* @__PURE__ */ jsx("span", {
110
110
  className: "media-editor-keyboard-shortcuts-modal__shortcut-description",
111
- children: description
112
- }), /* @__PURE__ */ jsx(KeyCombinationDisplay, { keyCombination })]
111
+ children: shortcut.description
112
+ }), /* @__PURE__ */ jsx(KeyCombinationDisplay, { ...shortcut })]
113
113
  }, index))
114
114
  })]
115
115
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\n\ninterface KeyCombination {\n\t/** Modifier for cross-platform display (e.g. 'primary', 'primaryShift', 'shift'). */\n\tmodifier?: WPKeycodeModifier;\n\t/** The key character(s) to display. Pass an array to render each as its own key. */\n\tcharacter: string | string[];\n\t/** Optional aria-label override (used when character is a symbol). */\n\tariaLabel?: string;\n}\n\ninterface ShortcutEntry {\n\tdescription: string;\n\tkeyCombination: KeyCombination;\n}\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Arrow keys' ),\n\t\t},\n\t},\n\t{\n\t\tdescription: __( 'Zoom in' ),\n\t\tkeyCombination: { character: '+' },\n\t},\n\t{\n\t\tdescription: __( 'Zoom out' ),\n\t\tkeyCombination: { character: '-' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° clockwise' ),\n\t\tkeyCombination: { character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° counter-clockwise' ),\n\t\tkeyCombination: { modifier: 'shift', character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Flip horizontal' ),\n\t\tkeyCombination: { character: 'H' },\n\t},\n\t{\n\t\tdescription: __( 'Flip vertical' ),\n\t\tkeyCombination: { character: 'V' },\n\t},\n\t{\n\t\tdescription: __( 'Pan or resize crop (large step)' ),\n\t\tkeyCombination: {\n\t\t\tmodifier: 'shift',\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Shift + Arrow keys' ),\n\t\t},\n\t},\n];\n\nfunction KeyCombinationDisplay( {\n\tkeyCombination,\n}: {\n\tkeyCombination: KeyCombination;\n} ) {\n\tconst { modifier, character, ariaLabel } = keyCombination;\n\n\tlet keys: string[];\n\tif ( Array.isArray( character ) ) {\n\t\tif ( modifier ) {\n\t\t\t// Get the modifier prefix (e.g. ['⇧', '+']) from the first char,\n\t\t\t// then replace the last element with all the individual chars.\n\t\t\tconst sample = displayShortcutList[ modifier ]( character[ 0 ] );\n\t\t\tkeys = [ ...sample.slice( 0, -1 ), ...character ];\n\t\t} else {\n\t\t\tkeys = character;\n\t\t}\n\t} else {\n\t\tkeys = modifier\n\t\t\t? displayShortcutList[ modifier ]( character )\n\t\t\t: [ character ];\n\t}\n\n\tconst charString = Array.isArray( character )\n\t\t? character.join( '' )\n\t\t: character;\n\tlet label: string;\n\tif ( ariaLabel ) {\n\t\tlabel = ariaLabel;\n\t} else if ( modifier ) {\n\t\tlabel = shortcutAriaLabel[ modifier ]( charString );\n\t} else {\n\t\tlabel = charString;\n\t}\n\n\treturn (\n\t\t<kbd\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-term\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ keys.map( ( key, index ) =>\n\t\t\t\tkey === '+' && modifier ? (\n\t\t\t\t\t<Fragment key={ index }>{ key }</Fragment>\n\t\t\t\t) : (\n\t\t\t\t\t<kbd\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-key\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ key }\n\t\t\t\t\t</kbd>\n\t\t\t\t)\n\t\t\t) }\n\t\t</kbd>\n\t);\n}\n\ninterface MediaEditorKeyboardShortcutsModalProps {\n\tonClose: () => void;\n}\n\nexport default function MediaEditorKeyboardShortcutsModal( {\n\tonClose,\n}: MediaEditorKeyboardShortcutsModalProps ) {\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal\"\n\t\t\ttitle={ __( 'Keyboard shortcuts' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t<p className=\"media-editor-keyboard-shortcuts-modal__note\">\n\t\t\t\t{ __(\n\t\t\t\t\t'These shortcuts work when the image editor has focus.'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t{ /*\n\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t */ }\n\t\t\t{ /* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t<ul\n\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-list\"\n\t\t\t\trole=\"list\"\n\t\t\t>\n\t\t\t\t{ SHORTCUTS.map( ( { description, keyCombination }, index ) => (\n\t\t\t\t\t<li\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"media-editor-keyboard-shortcuts-modal__shortcut-description\">\n\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<KeyCombinationDisplay\n\t\t\t\t\t\t\tkeyCombination={ keyCombination }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</li>\n\t\t\t\t) ) }\n\t\t\t</ul>\n\t\t\t{ /* eslint-enable jsx-a11y/no-redundant-roles */ }\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;AAuBA,MAAM,YAA6B;CAClC;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAW,WAAW;EAAI;CACvD;CACA;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAgB,WAAW;EAAI;CAC5D;CACA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,UAClB,QAAQ,OAAO,WACd,oBAAC,UAAD,EAAA,UAA0B,IAAe,GAAzB,KAAyB,IAEzC,oBAAC,OAAD;GAEC,WAAU;GAER,UAAA;EACE,GAJE,KAIF,CAEP;CACI,CAAA;AAEP;AAMA,SAAwB,kCAAmC,EAC1D,WAC2C;CAC3C,OACC,qBAAC,OAAD;EACC,WAAU;EACV,OAAQ,GAAI,oBAAqB;EACjC,gBAAiB;EAHlB,UAAA,CAKC,oBAAC,KAAD;GAAG,WAAU;GACV,UAAA,GACD,uDACD;EACE,CAAA,GAMH,oBAAC,MAAD;GACC,WAAU;GACV,MAAK;GAEH,UAAA,UAAU,KAAO,EAAE,aAAa,kBAAkB,UACnD,qBAAC,MAAD;IAEC,WAAU;IAFX,UAAA,CAIC,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA;IACG,CAAA,GACN,oBAAC,uBAAD,EACkB,eACjB,CAAA,CACE;GATG,GAAA,KASH,CACH;EACC,CAAA,CAEE;;AAET"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\nimport { VisuallyHidden } from '@wordpress/ui';\n\ntype KeyCombinationDisplayProps =\n\t| {\n\t\t\tkeyCombination: {\n\t\t\t\tcharacter: string;\n\t\t\t\tmodifier?: WPKeycodeModifier | null;\n\t\t\t};\n\t\t\tlabel?: string;\n\t }\n\t| {\n\t\t\tkeyCombination: {\n\t\t\t\tcharacter: string[];\n\t\t\t\tmodifier?: WPKeycodeModifier | null;\n\t\t\t};\n\t\t\tlabel: string;\n\t };\n\ntype ShortcutEntry = KeyCombinationDisplayProps & {\n\tdescription: string;\n};\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t},\n\t\tlabel: __( 'Arrow keys' ),\n\t},\n\t{\n\t\tdescription: __( 'Zoom in' ),\n\t\tkeyCombination: { character: '+' },\n\t},\n\t{\n\t\tdescription: __( 'Zoom out' ),\n\t\tkeyCombination: { character: '-' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° clockwise' ),\n\t\tkeyCombination: { character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° counter-clockwise' ),\n\t\tkeyCombination: { modifier: 'shift', character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Flip horizontal' ),\n\t\tkeyCombination: { character: 'H' },\n\t},\n\t{\n\t\tdescription: __( 'Flip vertical' ),\n\t\tkeyCombination: { character: 'V' },\n\t},\n\t{\n\t\tdescription: __( 'Pan or resize crop (large step)' ),\n\t\tkeyCombination: {\n\t\t\tmodifier: 'shift',\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t},\n\t\tlabel: __( 'Shift + Arrow keys' ),\n\t},\n];\n\nfunction KeyCombinationDisplay( {\n\tkeyCombination,\n\tlabel,\n}: KeyCombinationDisplayProps ) {\n\tconst { character, modifier } = keyCombination;\n\tconst normalizedModifier = modifier ?? 'undefined';\n\tconst characters = Array.isArray( character ) ? character : [ character ];\n\tconst formatted = displayShortcutList[ normalizedModifier ](\n\t\tcharacters[ 0 ] ?? ''\n\t);\n\tconst prefix = formatted.slice( 0, -1 );\n\tconst keys = Array.isArray( character )\n\t\t? [ ...prefix, ...character ]\n\t\t: formatted;\n\n\treturn (\n\t\t<kbd\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-term\"\n\t\t\tdir=\"ltr\"\n\t\t>\n\t\t\t<VisuallyHidden render={ <span /> }>\n\t\t\t\t{ label ||\n\t\t\t\t\tshortcutAriaLabel[ normalizedModifier ](\n\t\t\t\t\t\tcharacters.join( '' )\n\t\t\t\t\t) }\n\t\t\t</VisuallyHidden>\n\t\t\t<span aria-hidden=\"true\">\n\t\t\t\t{ keys.map( ( key, keyIndex ) =>\n\t\t\t\t\tkey === '+' && keyIndex < prefix.length ? (\n\t\t\t\t\t\t<Fragment key={ keyIndex }>{ key }</Fragment>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<kbd\n\t\t\t\t\t\t\tkey={ keyIndex }\n\t\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-key\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ key }\n\t\t\t\t\t\t</kbd>\n\t\t\t\t\t)\n\t\t\t\t) }\n\t\t\t</span>\n\t\t</kbd>\n\t);\n}\n\ninterface MediaEditorKeyboardShortcutsModalProps {\n\tonClose: () => void;\n}\n\nexport default function MediaEditorKeyboardShortcutsModal( {\n\tonClose,\n}: MediaEditorKeyboardShortcutsModalProps ) {\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal\"\n\t\t\ttitle={ __( 'Keyboard shortcuts' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t<p className=\"media-editor-keyboard-shortcuts-modal__note\">\n\t\t\t\t{ __(\n\t\t\t\t\t'These shortcuts work when the image editor has focus.'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t{ /*\n\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t */ }\n\t\t\t{ /* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t<ul\n\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-list\"\n\t\t\t\trole=\"list\"\n\t\t\t>\n\t\t\t\t{ SHORTCUTS.map( ( shortcut, index ) => (\n\t\t\t\t\t<li\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"media-editor-keyboard-shortcuts-modal__shortcut-description\">\n\t\t\t\t\t\t\t{ shortcut.description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<KeyCombinationDisplay { ...shortcut } />\n\t\t\t\t\t</li>\n\t\t\t\t) ) }\n\t\t\t</ul>\n\t\t\t{ /* eslint-enable jsx-a11y/no-redundant-roles */ }\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;AA8BA,MAAM,YAA6B;CAClC;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAW,WAAW;EAAI;CACvD;CACA;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAgB,WAAW;EAAI;CAC5D;CACA;EACC,aAAa,GAAI,KAAM;EACvB,gBAAgB,EACf,WAAW;GAAE;GAAK;GAAK;GAAK;EAAI,EACjC;EACA,OAAO,GAAI,YAAa;CACzB;CACA;EACC,aAAa,GAAI,SAAU;EAC3B,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,UAAW;EAC5B,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,sBAAuB;EACxC,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,8BAA+B;EAChD,gBAAgB;GAAE,UAAU;GAAS,WAAW;EAAI;CACrD;CACA;EACC,aAAa,GAAI,iBAAkB;EACnC,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,eAAgB;EACjC,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,iCAAkC;EACnD,gBAAgB;GACf,UAAU;GACV,WAAW;IAAE;IAAK;IAAK;IAAK;GA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,GAAA,KAOH,CACH;EACC,CAAA,CAEE;;AAET"}
@@ -51,6 +51,7 @@ function MediaEditorModal({ fields = [], form, aspectRatioPresets }) {
51
51
  shouldCloseOnEsc: true,
52
52
  noticesClassName: "media-editor-modal__snackbar",
53
53
  noticesPortalElement: portalElement,
54
+ defaultPanel: "core/crop",
54
55
  onClose: handleClose,
55
56
  onSaved: ({ id: savedId, url, previous }) => {
56
57
  if (savedId && onUpdate) onUpdate({
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["mediaEditorStore","noticesStore"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,cAAc;CACtB,OACC,qBAAC,OAAD;EACC,WAAU;EACV,MAAK;EACL,cAAa,GAAI,gBAAiB;EAHnC,UAAA,CAKC,oBAAC,YAAY,gBAAb,CAA6B,CAAA,GAC7B,oBAAC,YAAY,aAAb,CAA0B,CAAA,CACtB;;AAEP;AAEA,SAAgB,iBAAkB,EACjC,SAAS,CAAC,GACV,MACA,sBAC0B;CAC1B,MAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,YAAY,WACpD,WAAY;EACb,MAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,eAC9C,OAAQA,OAAiB;EAC1B,OAAO;GACN,aAAa,OAAO;GACpB,IAAI,MAAM;GACV,UAAU,YAAY;GACtB,QAAQ,UAAU;GAClB,SAAS,WAAW;EACrB;CACD,GACA,CAAC,CACF;CAEA,MAAM,EAAE,0BAA0B,YAAaA,OAAiB;CAChE,MAAM,EAAE,wBAAwB,YAAaC,KAAa;CAE1D,IAAK,CAAE,eAAe,CAAE,IACvB,OAAO;CAGR,MAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;CAMnD,MAAM,0BACL,UACI;EACJ,MAAM,gBAAgB;CACvB;CAEA,MAAM,oBAAoB;EACzB,sBAAsB;EACtB,UAAU;CACX;CAEA,OACC,oBAAC,aAAD;EACM;EACI;EACF;EACc;EACrB,kBAAA;EACA,kBAAiB;EACjB,sBAAuB;EACvB,SAAU;EACV,UAAY,EAAE,IAAI,SAAS,KAAK,eAAgB;GAC/C,IAAK,WAAW,UAKf,SAAU;IAHT,IAAI;IACJ;GAEc,CAAE;GAElB,YAAY;GACZ,IAAK,YAAY,YAAY,SAAS,MAAM,UAI3C,oBAAqB,GAAI,eAAgB,GAAG;IAC3C,MAAM;IACN,SAAS,CACR;KACC,OAAO,GAAI,MAAO;KAClB,eAAe;MACd,IAAK,QAAS;OACb,OAAO;OACP;MACD;MACA,SAAU;OACT,IAAI,SAAS;OACb,KAAK,SAAS;MACf,CAAE;KACH;IACD,CACD;GACD,CAAE;EAEJ;EACA,cAAgB,EACf,UACA,gBACA,WACA,gCAEA,oBAAC,kBAAD;GACC,WAAU;GACV,WAAY;GAEZ,UAAA,qBAAC,OAAD;IACC,WAAU;IACV,OAAQ,GAAI,YAAa;IACzB,MAAK;IACL,eAAgB;IACY;IAChB;IACK;IACjB,eACC,oBAAC,YAAY,eAAb,EAA2B,iBAAA,KAAiB,CAAA;IAT9C,UAAA,CAYG,UACF,oBAAC,aAAD,CAAc,CAAA,CACR;;EACU,CAAA;CAEnB,CAAA;AAEH"}
1
+ {"version":3,"file":"index.mjs","names":["mediaEditorStore","noticesStore"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\t// Rotate, flip and aspect ratio are only in the Crop panel for now.\n\t\t\t// This can go once they move under the canvas (#87282).\n\t\t\tdefaultPanel=\"core/crop\"\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,cAAc;CACtB,OACC,qBAAC,OAAD;EACC,WAAU;EACV,MAAK;EACL,cAAa,GAAI,gBAAiB;EAHnC,UAAA,CAKC,o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GAEZ,UAAA,qBAAC,OAAD;IACC,WAAU;IACV,OAAQ,GAAI,YAAa;IACzB,MAAK;IACL,eAAgB;IACY;IAChB;IACK;IACjB,eACC,oBAAC,YAAY,eAAb,EAA2B,iBAAA,KAAiB,CAAA;IAT9C,UAAA,CAYG,UACF,oBAAC,aAAD,CAAc,CAAA,CACR;;EACU,CAAA;CAEnB,CAAA;AAEH"}
@@ -0,0 +1,63 @@
1
+ import { Component } from "@wordpress/element";
2
+ import { speak } from "@wordpress/a11y";
3
+ import { useCopyToClipboard } from "@wordpress/compose";
4
+ import { __, _x, sprintf } from "@wordpress/i18n";
5
+ import { Notice } from "@wordpress/ui";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ // packages/media-editor/src/components/media-editor-panel/error-boundary.tsx
8
+ function getMessage(title) {
9
+ return {
10
+ title: sprintf(
11
+ /** translators: %s: the panel's title. */
12
+ __("The \"%s\" panel could not be shown"),
13
+ title
14
+ ),
15
+ description: __("An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.")
16
+ };
17
+ }
18
+ function CopyErrorButton({ error }) {
19
+ const ref = useCopyToClipboard(() => {
20
+ const { message, stack } = error ?? {};
21
+ return [[error, message].find((part) => typeof part === "string" && part) ?? "An unknown error occurred.", stack].filter((part) => typeof part === "string" && part).join("\n\n");
22
+ });
23
+ return /* @__PURE__ */ jsx(Notice.ActionButton, {
24
+ variant: "outline",
25
+ ref,
26
+ children: _x("Copy error", "button label")
27
+ });
28
+ }
29
+ /**
30
+ * Keeps a panel's failure inside its tab, so the rest of the editor stays
31
+ * usable.
32
+ */
33
+ var MediaEditorPanelErrorBoundary = class extends Component {
34
+ state = {
35
+ hasError: false,
36
+ error: null
37
+ };
38
+ static getDerivedStateFromError(error) {
39
+ return {
40
+ hasError: true,
41
+ error
42
+ };
43
+ }
44
+ componentDidCatch() {
45
+ const { title, description } = getMessage(this.props.title);
46
+ speak(`${title}. ${description}`, "assertive");
47
+ }
48
+ render() {
49
+ if (!this.state.hasError) return this.props.children;
50
+ const { title, description } = getMessage(this.props.title);
51
+ return /* @__PURE__ */ jsxs(Notice.Root, {
52
+ intent: "error",
53
+ children: [
54
+ /* @__PURE__ */ jsx(Notice.Title, { children: title }),
55
+ /* @__PURE__ */ jsx(Notice.Description, { children: description }),
56
+ /* @__PURE__ */ jsx(Notice.Actions, { children: /* @__PURE__ */ jsx(CopyErrorButton, { error: this.state.error }) })
57
+ ]
58
+ });
59
+ }
60
+ };
61
+ export { MediaEditorPanelErrorBoundary as default };
62
+
63
+ //# sourceMappingURL=error-boundary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.mjs","names":[],"sources":["../../../src/components/media-editor-panel/error-boundary.tsx"],"sourcesContent":["import { Component } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { Notice } from '@wordpress/ui';\nimport type { ReactNode } from 'react';\n\ninterface Props {\n\ttitle: string;\n\tchildren: ReactNode;\n}\n\ninterface State {\n\t/** Separate from `error`: a panel can throw a falsy value. */\n\thasError: boolean;\n\terror: unknown;\n}\n\nfunction getMessage( title: string ) {\n\treturn {\n\t\ttitle: sprintf(\n\t\t\t/* translators: %s: the panel's title. */\n\t\t\t__( 'The \"%s\" panel could not be shown' ),\n\t\t\ttitle\n\t\t),\n\t\tdescription: __(\n\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t),\n\t};\n}\n\n// A component, because the copy hook cannot run in the class below.\nfunction CopyErrorButton( { error }: { error: unknown } ) {\n\tconst ref = useCopyToClipboard< HTMLButtonElement >( () => {\n\t\t// A boundary catches whatever was thrown, which is not always an `Error`.\n\t\tconst { message, stack } = ( error ?? {} ) as {\n\t\t\tmessage?: unknown;\n\t\t\tstack?: unknown;\n\t\t};\n\t\tconst text = [ error, message ].find(\n\t\t\t( part ) => typeof part === 'string' && part\n\t\t);\n\t\treturn [ text ?? 'An unknown error occurred.', stack ]\n\t\t\t.filter( ( part ) => typeof part === 'string' && part )\n\t\t\t.join( '\\n\\n' );\n\t} );\n\treturn (\n\t\t<Notice.ActionButton variant=\"outline\" ref={ ref }>\n\t\t\t{ _x( 'Copy error', 'button label' ) }\n\t\t</Notice.ActionButton>\n\t);\n}\n\n/**\n * Keeps a panel's failure inside its tab, so the rest of the editor stays\n * usable.\n */\nexport default class MediaEditorPanelErrorBoundary extends Component<\n\tProps,\n\tState\n> {\n\tstate: State = { hasError: false, error: null };\n\n\tstatic getDerivedStateFromError( error: unknown ): State {\n\t\treturn { hasError: true, error };\n\t}\n\n\tcomponentDidCatch() {\n\t\tconst { title, description } = getMessage( this.props.title );\n\t\tspeak( `${ title }. ${ description }`, 'assertive' );\n\t}\n\n\trender() {\n\t\tif ( ! this.state.hasError ) {\n\t\t\treturn this.props.children;\n\t\t}\n\t\tconst { title, description } = getMessage( this.props.title );\n\t\treturn (\n\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t<Notice.Title>{ title }</Notice.Title>\n\t\t\t\t<Notice.Description>{ description }</Notice.Description>\n\t\t\t\t<Notice.Actions>\n\t\t\t\t\t<CopyErrorButton error={ this.state.error } />\n\t\t\t\t</Notice.Actions>\n\t\t\t</Notice.Root>\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;AAkBA,SAAS,WAAY,OAAgB;CACpC,OAAO;EACN,OAAO;;GAEN,GAAI,qCAAoC;GACxC;EACD;EACA,aAAa,GACZ,iHACD;CACD;AACD;AAGA,SAAS,gBAAiB,EAAE,SAA8B;CACzD,MAAM,MAAM,yBAA+C;EAE1D,MAAM,EAAE,SAAS,UAAY,SAAS,CAAC;EAOvC,OAAO,CAHM,CAAE,OAAO,OAAQ,CAAC,CAAC,MAC7B,SAAU,OAAO,SAAS,YAAY,IAEhC,KAAQ,8BAA8B,KAAM,CAAA,CACnD,QAAU,SAAU,OAAO,SAAS,YAAY,IAAK,CAAA,CACrD,KAAM,MAAO;CAChB,CAAE;CACF,OACC,oBAAC,OAAO,cAAR;EAAqB,SAAQ;EAAgB;EAC1C,UAAA,GAAI,cAAc,cAAe;CACf,CAAA;AAEvB;;;;;AAMA,IAAqB,gCAArB,cAA2D,UAGzD;CACD,QAAe;EAAE,UAAU;EAAO,OAAO;CAAK;CAE9C,OAAO,yBAA0B,OAAwB;EACxD,OAAO;GAAE,UAAU;GAAM;EAAM;CAChC;CAEA,oBAAoB;EACnB,MAAM,EAAE,OAAO,gBAAgB,WAAY,KAAK,MAAM,KAAM;EAC5D,MAAO,GAAI,MAAO,IAAK,eAAgB,WAAY;CACpD;CAEA,SAAS;EACR,IAAK,CAAE,KAAK,MAAM,UACjB,OAAO,KAAK,MAAM;EAEnB,MAAM,EAAE,OAAO,gBAAgB,WAAY,KAAK,MAAM,KAAM;EAC5D,OACC,qBAAC,OAAO,MAAR;GAAa,QAAO;GAApB,UAAA;IACC,oBAAC,OAAO,OAAR,EAAA,UAAgB,MAAqB,CAAA;IACrC,oBAAC,OAAO,aAAR,EAAA,UAAsB,YAAiC,CAAA;IACvD,oBAAC,OAAO,SAAR,EAAA,UACC,oBAAC,iBAAD,EAAiB,OAAQ,KAAK,MAAM,MAAS,CAAA,EAC9B,CAAA;GACJ;;CAEf;AACD"}
@@ -0,0 +1,123 @@
1
+ import fastDeepEqual from "fast-deep-equal/es6/index.js";
2
+ import { Fill } from "@wordpress/components";
3
+ import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState } from "@wordpress/element";
4
+ import warning from "@wordpress/warning";
5
+ import { MEDIA_TYPES } from "../../utils/index.mjs";
6
+ import MediaEditorPanelErrorBoundary from "./error-boundary.mjs";
7
+ import { jsx } from "react/jsx-runtime";
8
+ // packages/media-editor/src/components/media-editor-panel/index.tsx
9
+ const MediaEditorPanelsContext = createContext(null);
10
+ const MediaEditorPanelsProvider = MediaEditorPanelsContext.Provider;
11
+ /** The `registerPlugin` scope the editor mounts. */
12
+ const MEDIA_EDITOR_PLUGIN_SCOPE = "media-editor";
13
+ /** `vendor/panel`: lowercase letters, digits and dashes, with one slash. */
14
+ const PANEL_NAME_PATTERN = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/;
15
+ function getPanelSlotName(name) {
16
+ return `MediaEditorPanel/${name}`;
17
+ }
18
+ /**
19
+ * The mounted panels of one editor.
20
+ *
21
+ * @return The panels, in the order they mounted, and the context value to provide to them.
22
+ */
23
+ function useMediaEditorPanels() {
24
+ const [panels, setPanels] = useState({});
25
+ const ownersRef = useRef(/* @__PURE__ */ new Map());
26
+ const register = useCallback((panel, instance) => {
27
+ const owner = ownersRef.current.get(panel.name);
28
+ if (owner && owner !== instance) {
29
+ warning(`A media editor panel named "${panel.name}" is already registered, so this one is not shown. Give each panel a unique name.`);
30
+ return;
31
+ }
32
+ ownersRef.current.set(panel.name, instance);
33
+ setPanels((current) => {
34
+ const entry = current[panel.name];
35
+ if (entry?.owner === instance && fastDeepEqual(entry.registration, panel)) return current;
36
+ return {
37
+ ...current,
38
+ [panel.name]: {
39
+ registration: panel,
40
+ owner: instance
41
+ }
42
+ };
43
+ });
44
+ }, []);
45
+ const unregister = useCallback((name, instance) => {
46
+ if (ownersRef.current.get(name) !== instance) return;
47
+ ownersRef.current.delete(name);
48
+ setPanels((current) => {
49
+ if (!Object.hasOwn(current, name)) return current;
50
+ const next = { ...current };
51
+ delete next[name];
52
+ return next;
53
+ });
54
+ }, []);
55
+ const owners = useMemo(() => Object.fromEntries(Object.entries(panels).map(([name, { owner }]) => [name, owner])), [panels]);
56
+ const contextValue = useMemo(() => ({
57
+ register,
58
+ unregister,
59
+ owners
60
+ }), [
61
+ register,
62
+ unregister,
63
+ owners
64
+ ]);
65
+ return {
66
+ panels: useMemo(() => Object.values(panels).map(({ registration }) => registration), [panels]),
67
+ contextValue
68
+ };
69
+ }
70
+ /** A tab in the media editor's sidebar, filled with its children. */
71
+ function MediaEditorPanel({ name, title, mediaTypes, children }) {
72
+ const context = useContext(MediaEditorPanelsContext);
73
+ if (!context) throw new Error("MediaEditorPanel is rendered outside the media editor.");
74
+ const { register, unregister, owners } = context;
75
+ const [instance] = useState(() => ({}));
76
+ const owner = owners[name];
77
+ useLayoutEffect(() => {
78
+ if (!PANEL_NAME_PATTERN.test(name)) warning(`The media editor panel name "${name}" should be namespaced, like "my-plugin/my-panel": lowercase letters, digits and dashes, with one slash.`);
79
+ mediaTypes?.forEach((type) => {
80
+ if (!MEDIA_TYPES.includes(type)) warning(`The media editor panel "${name}" lists the media type "${type}", which the editor does not know, so the panel would never show for it. Known types: ${MEDIA_TYPES.join(", ")}.`);
81
+ });
82
+ register({
83
+ name,
84
+ title,
85
+ mediaTypes
86
+ }, instance);
87
+ }, [
88
+ name,
89
+ title,
90
+ mediaTypes,
91
+ register,
92
+ owner,
93
+ instance
94
+ ]);
95
+ useLayoutEffect(() => {
96
+ return () => unregister(name, instance);
97
+ }, [
98
+ name,
99
+ unregister,
100
+ instance
101
+ ]);
102
+ if (owner !== instance) return null;
103
+ return /* @__PURE__ */ jsx(Fill, {
104
+ name: getPanelSlotName(name),
105
+ children: (fillProps) => /* @__PURE__ */ jsx(MediaEditorPanelErrorBoundary, {
106
+ title,
107
+ children: /* @__PURE__ */ jsx(MediaEditorPanelContent, {
108
+ fillProps,
109
+ children
110
+ })
111
+ })
112
+ });
113
+ }
114
+ /**
115
+ * Calls a function child inside the error boundary, so one that throws is
116
+ * caught there.
117
+ */
118
+ function MediaEditorPanelContent({ fillProps, children }) {
119
+ return typeof children === "function" ? children(fillProps) : children;
120
+ }
121
+ export { MEDIA_EDITOR_PLUGIN_SCOPE, MediaEditorPanelsProvider, MediaEditorPanel as default, getPanelSlotName, useMediaEditorPanels };
122
+
123
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-panel/index.tsx"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport { Fill } from '@wordpress/components';\nimport {\n\tcreateContext,\n\tuseCallback,\n\tuseContext,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport warning from '@wordpress/warning';\nimport type { ReactNode } from 'react';\nimport { MEDIA_TYPES, type MediaType } from '../../utils';\nimport MediaEditorPanelErrorBoundary from './error-boundary';\n\nexport interface MediaEditorPanelFillProps {\n\t/** `true` while a save is running. */\n\tdisabled: boolean;\n}\n\nexport interface MediaEditorPanelRegistration {\n\t/** Unique, namespaced name, for example `core/crop`. */\n\tname: string;\n\t/** Tab label. */\n\ttitle: string;\n\t/** Omitted means every type. */\n\tmediaTypes?: readonly MediaType[ 'type' ][];\n}\n\nexport interface MediaEditorPanelProps extends MediaEditorPanelRegistration {\n\tchildren:\n\t\tReactNode | ( ( fillProps: MediaEditorPanelFillProps ) => ReactNode );\n}\n\ninterface MediaEditorPanelsContextValue {\n\tregister: ( panel: MediaEditorPanelRegistration, instance: object ) => void;\n\tunregister: ( name: string, instance: object ) => void;\n\t/** Panel name to the mounted panel that has it. */\n\towners: Record< string, object >;\n}\n\nconst MediaEditorPanelsContext =\n\tcreateContext< MediaEditorPanelsContextValue | null >( null );\n\nexport const MediaEditorPanelsProvider = MediaEditorPanelsContext.Provider;\n\n/** The `registerPlugin` scope the editor mounts. */\nexport const MEDIA_EDITOR_PLUGIN_SCOPE = 'media-editor';\n\n/** `vendor/panel`: lowercase letters, digits and dashes, with one slash. */\nconst PANEL_NAME_PATTERN = /^[a-z][a-z0-9-]*\\/[a-z][a-z0-9-]*$/;\n\nexport function getPanelSlotName( name: string ) {\n\treturn `MediaEditorPanel/${ name }`;\n}\n\n/**\n * The mounted panels of one editor.\n *\n * @return The panels, in the order they mounted, and the context value to provide to them.\n */\nexport function useMediaEditorPanels() {\n\tconst [ panels, setPanels ] = useState<\n\t\tRecord<\n\t\t\tstring,\n\t\t\t{ registration: MediaEditorPanelRegistration; owner: object }\n\t\t>\n\t>( {} );\n\t// The first panel to announce a name keeps it. A ref, so panels\n\t// announcing in the same commit see each other.\n\tconst ownersRef = useRef( new Map< string, object >() );\n\tconst register = useCallback(\n\t\t( panel: MediaEditorPanelRegistration, instance: object ) => {\n\t\t\tconst owner = ownersRef.current.get( panel.name );\n\t\t\tif ( owner && owner !== instance ) {\n\t\t\t\twarning(\n\t\t\t\t\t`A media editor panel named \"${ panel.name }\" is already registered, so this one is not shown. Give each panel a unique name.`\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\townersRef.current.set( panel.name, instance );\n\t\t\tsetPanels( ( current ) => {\n\t\t\t\t// Skip unchanged details: an inline `mediaTypes` array would\n\t\t\t\t// otherwise re-render the editor and the panel in a loop.\n\t\t\t\tconst entry = current[ panel.name ];\n\t\t\t\tif (\n\t\t\t\t\tentry?.owner === instance &&\n\t\t\t\t\tfastDeepEqual( entry.registration, panel )\n\t\t\t\t) {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...current,\n\t\t\t\t\t[ panel.name ]: { registration: panel, owner: instance },\n\t\t\t\t};\n\t\t\t} );\n\t\t},\n\t\t[]\n\t);\n\tconst unregister = useCallback( ( name: string, instance: object ) => {\n\t\tif ( ownersRef.current.get( name ) !== instance ) {\n\t\t\treturn;\n\t\t}\n\t\townersRef.current.delete( name );\n\t\tsetPanels( ( current ) => {\n\t\t\tif ( ! Object.hasOwn( current, name ) ) {\n\t\t\t\treturn current;\n\t\t\t}\n\t\t\tconst next = { ...current };\n\t\t\tdelete next[ name ];\n\t\t\treturn next;\n\t\t} );\n\t}, [] );\n\tconst owners = useMemo(\n\t\t() =>\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries( panels ).map( ( [ name, { owner } ] ) => [\n\t\t\t\t\tname,\n\t\t\t\t\towner,\n\t\t\t\t] )\n\t\t\t),\n\t\t[ panels ]\n\t);\n\tconst contextValue = useMemo(\n\t\t() => ( { register, unregister, owners } ),\n\t\t[ register, unregister, owners ]\n\t);\n\tconst registrations = useMemo(\n\t\t() =>\n\t\t\tObject.values( panels ).map( ( { registration } ) => registration ),\n\t\t[ panels ]\n\t);\n\treturn { panels: registrations, contextValue };\n}\n\n/** A tab in the media editor's sidebar, filled with its children. */\nexport default function MediaEditorPanel( {\n\tname,\n\ttitle,\n\tmediaTypes,\n\tchildren,\n}: MediaEditorPanelProps ) {\n\tconst context = useContext( MediaEditorPanelsContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'MediaEditorPanel is rendered outside the media editor.'\n\t\t);\n\t}\n\tconst { register, unregister, owners } = context;\n\t// Identifies this mounted panel.\n\tconst [ instance ] = useState( () => ( {} ) );\n\tconst owner = owners[ name ];\n\t// Layout effects, so the tab exists before the sidebar paints. Two of\n\t// them: details may change on any render, but the tab only goes when\n\t// the panel unmounts or changes its name.\n\tuseLayoutEffect( () => {\n\t\tif ( ! PANEL_NAME_PATTERN.test( name ) ) {\n\t\t\twarning(\n\t\t\t\t`The media editor panel name \"${ name }\" should be namespaced, like \"my-plugin/my-panel\": lowercase letters, digits and dashes, with one slash.`\n\t\t\t);\n\t\t}\n\t\tmediaTypes?.forEach( ( type ) => {\n\t\t\tif ( ! MEDIA_TYPES.includes( type ) ) {\n\t\t\t\twarning(\n\t\t\t\t\t`The media editor panel \"${ name }\" lists the media type \"${ type }\", which the editor does not know, so the panel would never show for it. Known types: ${ MEDIA_TYPES.join( ', ' ) }.`\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\t\tregister( { name, title, mediaTypes }, instance );\n\t\t// When two panels share a name, the second waits for the first to\n\t\t// unmount. `owner` changes at that point, which re-runs this effect\n\t\t// and gives the second panel the tab.\n\t}, [ name, title, mediaTypes, register, owner, instance ] );\n\tuseLayoutEffect( () => {\n\t\treturn () => unregister( name, instance );\n\t}, [ name, unregister, instance ] );\n\n\tif ( owner !== instance ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Fill name={ getPanelSlotName( name ) }>\n\t\t\t{ ( fillProps ) => (\n\t\t\t\t<MediaEditorPanelErrorBoundary title={ title }>\n\t\t\t\t\t<MediaEditorPanelContent\n\t\t\t\t\t\t// The slot passes exactly these props; `Fill` types them loosely.\n\t\t\t\t\t\tfillProps={ fillProps as MediaEditorPanelFillProps }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</MediaEditorPanelContent>\n\t\t\t\t</MediaEditorPanelErrorBoundary>\n\t\t\t) }\n\t\t</Fill>\n\t);\n}\n\n/**\n * Calls a function child inside the error boundary, so one that throws is\n * caught there.\n */\nfunction MediaEditorPanelContent( {\n\tfillProps,\n\tchildren,\n}: {\n\tfillProps: MediaEditorPanelFillProps;\n\tchildren: MediaEditorPanelProps[ 'children' ];\n} ) {\n\treturn typeof children === 'function' ? children( fillProps ) : children;\n}\n"],"mappings":";;;;;;;;AA0CA,MAAM,2BACL,cAAuD,IAAK;AAE7D,MAAa,4BAA4B,yBAAyB;;AAGlE,MAAa,4BAA4B;;AAGzC,MAAM,qBAAqB;AAE3B,SAAgB,iBAAkB,MAAe;CAChD,OAAO,oBAAqB;AAC7B;;;;;;AAOA,SAAgB,uBAAuB;CACtC,MAAM,CAAE,QAAQ,aAAc,SAK3B,CAAC,CAAE;CAGN,MAAM,YAAY,uBAAQ,IAAI,IAAsB,CAAE;CACtD,MAAM,WAAW,aACd,OAAqC,aAAsB;EAC5D,MAAM,QAAQ,UAAU,QAAQ,IAAK,MAAM,IAAK;EAChD,IAAK,SAAS,UAAU,UAAW;GAClC,QACC,+BAAgC,MAAM,KAAM,kFAC7C;GACA;EACD;EACA,UAAU,QAAQ,IAAK,MAAM,MAAM,QAAS;EAC5C,WAAa,YAAa;GAGzB,MAAM,QAAQ,QAAS,MAAM;GAC7B,IACC,OAAO,UAAU,YACjB,cAAe,MAAM,cAAc,KAAM,GAEzC,OAAO;GAER,OAAO;IACN,GAAG;KACD,MAAM,OAAQ;KAAE,cAAc;KAAO,OAAO;IAAS;GACxD;EACD,CAAE;CACH,GACA,C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,CAAE;CAC1D,sBAAuB;EACtB,aAAa,WAAY,MAAM,QAAS;CACzC,GAAG;EAAE;EAAM;EAAY;CAAS,CAAE;CAElC,IAAK,UAAU,UACd,OAAO;CAGR,OACC,oBAAC,MAAD;EAAM,MAAO,iBAAkB,IAAK;EAC/B,WAAA,cACH,oBAAC,+BAAD;GAAuC;GACtC,UAAA,oBAAC,yBAAD;IAEa;IAEV;GACsB,CAAA;EACK,CAAA;CAE3B,CAAA;AAER;;;;;AAMA,SAAS,wBAAyB,EACjC,WACA,YAIG;CACH,OAAO,OAAO,aAAa,aAAa,SAAU,SAAU,IAAI;AACjE"}
@@ -21,7 +21,13 @@ const DEFAULT_FORM = {
21
21
  }
22
22
  })),
23
23
  "date",
24
- "author",
24
+ {
25
+ id: "author",
26
+ layout: {
27
+ type: "panel",
28
+ showPlaceholderIfEmpty: true
29
+ }
30
+ },
25
31
  "filename",
26
32
  "mime_type",
27
33
  "filesize",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["WCSpinner","VStack"],"sources":["../../../src/components/media-form/index.tsx"],"sourcesContent":["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t'author',\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,eAAqB;CAC1B,QAAQ,EACP,MAAM,QACP;CACA,QAAQ;EACP,GAAG;GAAE;GAAS;GAAY;GAAW;EAAc,CAAC,CAAC,KAAO,QAAU;GACrE;GACA,QAAQ;IACP,MAAM;IACN,eAAe;GAChB;EACD,EAAI;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AACD;;;;;;;;;;;;;;;AAwBA,SAAwB,UAAW,EAClC,MAAM,eACN,UACmB;CACnB,MAAM,EACL,OACA,QACA,MAAM,cACN,aACG,sBAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAACA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,qBAACC,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,oBAAC,gBAAD;KAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;KAC3B,UAAA,GAAI,eAAgB;IACP,CAAA;IACd;IACF,oBAAC,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}
1
+ {"version":3,"file":"index.mjs","names":["WCSpinner","VStack"],"sources":["../../../src/components/media-form/index.tsx"],"sourcesContent":["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t{\n\t\t\tid: 'author',\n\t\t\tlayout: {\n\t\t\t\ttype: 'panel' as const,\n\t\t\t\tshowPlaceholderIfEmpty: true,\n\t\t\t},\n\t\t},\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,eAAqB;CAC1B,QAAQ,EACP,MAAM,QACP;CACA,QAAQ;EACP,GAAG;GAAE;GAAS;GAAY;GAAW;EAAc,CAAC,CAAC,KAAO,QAAU;GACrE;GACA,QAAQ;IACP,MAAM;IACN,eAAe;GAChB;EACD,EAAI;EACJ;EACA;GACC,IAAI;GACJ,QAAQ;IACP,MAAM;IACN,wBAAwB;GACzB;EACD;EACA;EACA;EACA;EACA;EACA;CACD;AACD;;;;;;;;;;;;;;;AAwBA,SAAwB,UAAW,EAClC,MAAM,eACN,UACmB;CACnB,MAAM,EACL,OACA,QACA,MAAM,cACN,aACG,sBAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAACA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,qBAACC,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,oBAAC,gBAAD;KAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;KAC3B,UAAA,GAAI,eAAgB;IACP,CAAA;IACd;IACF,oBAAC,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}