@wordpress/media-editor 0.20.0 → 0.22.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 (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -1,166 +1,125 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
2
7
  var __create = Object.create;
3
8
  var __defProp = Object.defineProperty;
4
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
11
  var __getProtoOf = Object.getPrototypeOf;
7
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
13
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
19
22
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let _wordpress_components = require("@wordpress/components");
28
+ let _wordpress_data = require("@wordpress/data");
29
+ let _wordpress_i18n = require("@wordpress/i18n");
30
+ let _wordpress_keyboard_shortcuts = require("@wordpress/keyboard-shortcuts");
31
+ let _wordpress_notices = require("@wordpress/notices");
32
+ let ___media_editor_index_tsx = require("../media-editor/index.cjs");
33
+ ___media_editor_index_tsx = __toESM(___media_editor_index_tsx);
34
+ let ______store_index_ts = require("../../store/index.cjs");
35
+ let react_jsx_runtime = require("react/jsx-runtime");
30
36
  // packages/media-editor/src/components/media-editor-modal/index.tsx
31
- var media_editor_modal_exports = {};
32
- __export(media_editor_modal_exports, {
33
- MediaEditorModal: () => MediaEditorModal,
34
- default: () => media_editor_modal_default
35
- });
36
- module.exports = __toCommonJS(media_editor_modal_exports);
37
- var import_components = require("@wordpress/components");
38
- var import_data = require("@wordpress/data");
39
- var import_i18n = require("@wordpress/i18n");
40
- var import_keyboard_shortcuts = require("@wordpress/keyboard-shortcuts");
41
- var import_notices = require("@wordpress/notices");
42
- var import_media_editor = __toESM(require("../media-editor/index.cjs"));
43
- var import_store = require("../../store/index.cjs");
44
- var import_jsx_runtime = require("react/jsx-runtime");
37
+ /**
38
+ * The modal's footer chrome. The fine-rotation ruler and the image controls
39
+ * both live under the canvas (in `media-editor__content`), never here, so the
40
+ * footer has one layout at every width: History on the left, Cancel/Save on
41
+ * the right.
42
+ */
45
43
  function ModalFooter() {
46
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
47
- "div",
48
- {
49
- className: "media-editor-modal__footer",
50
- role: "region",
51
- "aria-label": (0, import_i18n.__)("Editor actions"),
52
- children: [
53
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.HistoryActions, {}),
54
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.SaveActions, {})
55
- ]
56
- }
57
- );
44
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
45
+ className: "media-editor-modal__footer",
46
+ role: "region",
47
+ "aria-label": (0, _wordpress_i18n.__)("Editor actions"),
48
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(___media_editor_index_tsx.default.HistoryActions, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___media_editor_index_tsx.default.SaveActions, {})]
49
+ });
58
50
  }
59
- function MediaEditorModal({
60
- fields = [],
61
- aspectRatioPresets
62
- }) {
63
- const { isModalOpen, id, onUpdate, onUndo, onClose } = (0, import_data.useSelect)(
64
- (select) => {
65
- const { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } = select(import_store.store);
66
- return {
67
- isModalOpen: isOpen(),
68
- id: getId(),
69
- onUpdate: getOnUpdate(),
70
- onUndo: getOnUndo(),
71
- onClose: getOnClose()
72
- };
73
- },
74
- []
75
- );
76
- const { closeMediaEditorModal } = (0, import_data.useDispatch)(import_store.store);
77
- const { createSuccessNotice } = (0, import_data.useDispatch)(import_notices.store);
78
- if (!isModalOpen || !id) {
79
- return null;
80
- }
81
- const portalElement = typeof document === "undefined" ? null : document.body;
82
- const stopKeyDownPropagation = (event) => {
83
- event.stopPropagation();
84
- };
85
- const handleClose = () => {
86
- closeMediaEditorModal();
87
- onClose?.();
88
- };
89
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
90
- import_media_editor.default,
91
- {
92
- id,
93
- fields,
94
- aspectRatioPresets,
95
- shouldCloseOnEsc: true,
96
- noticesClassName: "media-editor-modal__snackbar",
97
- noticesPortalElement: portalElement,
98
- onClose: handleClose,
99
- onSaved: ({ id: savedId, url, previous }) => {
100
- if (savedId && onUpdate) {
101
- const update = {
102
- id: savedId,
103
- url
104
- };
105
- onUpdate(update);
106
- }
107
- handleClose();
108
- if (previous && savedId !== previous.id && onUpdate) {
109
- createSuccessNotice((0, import_i18n.__)("Image edited."), {
110
- type: "snackbar",
111
- actions: [
112
- {
113
- label: (0, import_i18n.__)("Undo"),
114
- onClick: () => {
115
- if (onUndo) {
116
- onUndo();
117
- return;
118
- }
119
- onUpdate({
120
- id: previous.id,
121
- url: previous.url
122
- });
123
- }
124
- }
125
- ]
126
- });
127
- }
128
- },
129
- renderFrame: ({
130
- children,
131
- onRequestClose,
132
- onKeyDown,
133
- shouldCloseOnClickOutside
134
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
135
- import_keyboard_shortcuts.ShortcutProvider,
136
- {
137
- className: "media-editor-modal__shortcut-scope",
138
- onKeyDown: stopKeyDownPropagation,
139
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
140
- import_components.Modal,
141
- {
142
- className: "media-editor-modal",
143
- title: (0, import_i18n.__)("Edit media"),
144
- size: "fill",
145
- isDismissible: false,
146
- shouldCloseOnClickOutside,
147
- onKeyDown,
148
- onRequestClose,
149
- headerActions: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_editor.default.HeaderActions, { showCloseButton: true }),
150
- children: [
151
- children,
152
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter, {})
153
- ]
154
- }
155
- )
156
- }
157
- )
158
- }
159
- );
51
+ function MediaEditorModal({ fields = [], form, aspectRatioPresets }) {
52
+ const { isModalOpen, id, onUpdate, onUndo, onClose } = (0, _wordpress_data.useSelect)((select) => {
53
+ const { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } = select(______store_index_ts.store);
54
+ return {
55
+ isModalOpen: isOpen(),
56
+ id: getId(),
57
+ onUpdate: getOnUpdate(),
58
+ onUndo: getOnUndo(),
59
+ onClose: getOnClose()
60
+ };
61
+ }, []);
62
+ const { closeMediaEditorModal } = (0, _wordpress_data.useDispatch)(______store_index_ts.store);
63
+ const { createSuccessNotice } = (0, _wordpress_data.useDispatch)(_wordpress_notices.store);
64
+ if (!isModalOpen || !id) return null;
65
+ const portalElement = typeof document === "undefined" ? null : document.body;
66
+ const stopKeyDownPropagation = (event) => {
67
+ event.stopPropagation();
68
+ };
69
+ const handleClose = () => {
70
+ closeMediaEditorModal();
71
+ onClose?.();
72
+ };
73
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___media_editor_index_tsx.default, {
74
+ id,
75
+ fields,
76
+ form,
77
+ aspectRatioPresets,
78
+ shouldCloseOnEsc: true,
79
+ noticesClassName: "media-editor-modal__snackbar",
80
+ noticesPortalElement: portalElement,
81
+ onClose: handleClose,
82
+ onSaved: ({ id: savedId, url, previous }) => {
83
+ if (savedId && onUpdate) onUpdate({
84
+ id: savedId,
85
+ url
86
+ });
87
+ handleClose();
88
+ if (previous && savedId !== previous.id && onUpdate) createSuccessNotice((0, _wordpress_i18n.__)("Image edited."), {
89
+ type: "snackbar",
90
+ actions: [{
91
+ label: (0, _wordpress_i18n.__)("Undo"),
92
+ onClick: () => {
93
+ if (onUndo) {
94
+ onUndo();
95
+ return;
96
+ }
97
+ onUpdate({
98
+ id: previous.id,
99
+ url: previous.url
100
+ });
101
+ }
102
+ }]
103
+ });
104
+ },
105
+ renderFrame: ({ children, onRequestClose, onKeyDown, shouldCloseOnClickOutside }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_keyboard_shortcuts.ShortcutProvider, {
106
+ className: "media-editor-modal__shortcut-scope",
107
+ onKeyDown: stopKeyDownPropagation,
108
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.Modal, {
109
+ className: "media-editor-modal",
110
+ title: (0, _wordpress_i18n.__)("Edit media"),
111
+ size: "fill",
112
+ isDismissible: false,
113
+ shouldCloseOnClickOutside,
114
+ onKeyDown,
115
+ onRequestClose,
116
+ headerActions: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___media_editor_index_tsx.default.HeaderActions, { showCloseButton: true }),
117
+ children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModalFooter, {})]
118
+ })
119
+ })
120
+ });
160
121
  }
161
- var media_editor_modal_default = MediaEditorModal;
162
- // Annotate the CommonJS export names for ESM import in node:
163
- 0 && (module.exports = {
164
- MediaEditorModal
165
- });
166
- //# sourceMappingURL=index.cjs.map
122
+ exports.MediaEditorModal = MediaEditorModal;
123
+ exports.default = MediaEditorModal;
124
+
125
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor-modal/index.tsx"],
4
- "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 } 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 * 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\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\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAsB;AACtB,kBAAuC;AACvC,kBAAmB;AACnB,gCAAiC;AACjC,qBAAsC;AAGtC,0BAAwB;AAExB,mBAA0C;AA2BxC;AAFF,SAAS,cAAc;AACtB,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,MAAK;AAAA,MACL,kBAAa,gBAAI,gBAAiB;AAAA,MAElC;AAAA,oDAAC,oBAAAA,QAAY,gBAAZ,EAA2B;AAAA,QAC5B,4CAAC,oBAAAA,QAAY,aAAZ,EAAwB;AAAA;AAAA;AAAA,EAC1B;AAEF;AAEO,SAAS,iBAAkB;AAAA,EACjC,SAAS,CAAC;AAAA,EACV;AACD,GAA2B;AAC1B,QAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,QAAQ,QAAI;AAAA,IACtD,CAAE,WAAY;AACb,YAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,WAAW,IACzD,OAAQ,aAAAC,KAAiB;AAC1B,aAAO;AAAA,QACN,aAAa,OAAO;AAAA,QACpB,IAAI,MAAM;AAAA,QACV,UAAU,YAAY;AAAA,QACtB,QAAQ,UAAU;AAAA,QAClB,SAAS,WAAW;AAAA,MACrB;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAEA,QAAM,EAAE,sBAAsB,QAAI,yBAAa,aAAAA,KAAiB;AAChE,QAAM,EAAE,oBAAoB,QAAI,yBAAa,eAAAC,KAAa;AAE1D,MAAK,CAAE,eAAe,CAAE,IAAK;AAC5B,WAAO;AAAA,EACR;AAEA,QAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;AAMnD,QAAM,yBAAyB,CAC9B,UACI;AACJ,UAAM,gBAAgB;AAAA,EACvB;AAEA,QAAM,cAAc,MAAM;AACzB,0BAAsB;AACtB,cAAU;AAAA,EACX;AAEA,SACC;AAAA,IAAC,oBAAAF;AAAA,IAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAgB;AAAA,MAChB,kBAAiB;AAAA,MACjB,sBAAuB;AAAA,MACvB,SAAU;AAAA,MACV,SAAU,CAAE,EAAE,IAAI,SAAS,KAAK,SAAS,MAAO;AAC/C,YAAK,WAAW,UAAW;AAC1B,gBAAM,SAAiC;AAAA,YACtC,IAAI;AAAA,YACJ;AAAA,UACD;AACA,mBAAU,MAAO;AAAA,QAClB;AACA,oBAAY;AACZ,YAAK,YAAY,YAAY,SAAS,MAAM,UAAW;AAItD,kCAAqB,gBAAI,eAAgB,GAAG;AAAA,YAC3C,MAAM;AAAA,YACN,SAAS;AAAA,cACR;AAAA,gBACC,WAAO,gBAAI,MAAO;AAAA,gBAClB,SAAS,MAAM;AACd,sBAAK,QAAS;AACb,2BAAO;AACP;AAAA,kBACD;AACA,2BAAU;AAAA,oBACT,IAAI,SAAS;AAAA,oBACb,KAAK,SAAS;AAAA,kBACf,CAAE;AAAA,gBACH;AAAA,cACD;AAAA,YACD;AAAA,UACD,CAAE;AAAA,QACH;AAAA,MACD;AAAA,MACA,aAAc,CAAE;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD,MACC;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV,WAAY;AAAA,UAEZ;AAAA,YAAC;AAAA;AAAA,cACA,WAAU;AAAA,cACV,WAAQ,gBAAI,YAAa;AAAA,cACzB,MAAK;AAAA,cACL,eAAgB;AAAA,cAChB;AAAA,cACA;AAAA,cACA;AAAA,cACA,eACC,4CAAC,oBAAAA,QAAY,eAAZ,EAA0B,iBAAe,MAAC;AAAA,cAG1C;AAAA;AAAA,gBACF,4CAAC,eAAY;AAAA;AAAA;AAAA,UACd;AAAA;AAAA,MACD;AAAA;AAAA,EAEF;AAEF;AAEA,IAAO,6BAAQ;",
6
- "names": ["MediaEditor", "mediaEditorStore", "noticesStore"]
7
- }
1
+ {"version":3,"file":"index.cjs","names":["__","MediaEditor","useSelect","mediaEditorStore","useDispatch","noticesStore","ShortcutProvider","Modal"],"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,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EACC,WAAU;EACV,MAAK;EACL,eAAA,GAAaA,gBAAAA,GAAAA,CAAI,gBAAiB;EAHnC,UAAA,CAKC,iBAAA,GAAA,kBAAA,IAAA,CAACC,0BAAAA,QAAY,gBAAb,CAA6B,CAAA,GAC7B,iBAAA,GAAA,kBAAA,IAAA,CAACA,0BAAAA,QAAY,aAAb,CAA0B,CAAA,CACtB;;AAEP;AAEA,SAAgB,iBAAkB,EACjC,SAAS,CAAC,GACV,MACA,sBAC0B;CAC1B,MAAM,EAAE,aAAa,IAAI,UAAU,QAAQ,aAAA,GAAYC,gBAAAA,UAAAA,EACpD,WAAY;EACb,MAAM,EAAE,QAAQ,OAAO,aAAa,WAAW,eAC9C,OAAQC,qBAAAA,KAAiB;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,2BAAA,GAA0BC,gBAAAA,YAAAA,CAAaD,qBAAAA,KAAiB;CAChE,MAAM,EAAE,yBAAA,GAAwBC,gBAAAA,YAAAA,CAAaC,mBAAAA,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,iBAAA,GAAA,kBAAA,IAAA,CAACJ,0BAAAA,SAAD;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,qBAAA,GAAqBD,gBAAAA,GAAAA,CAAI,eAAgB,GAAG;IAC3C,MAAM;IACN,SAAS,CACR;KACC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,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,iBAAA,GAAA,kBAAA,IAAA,CAACM,8BAAAA,kBAAD;GACC,WAAU;GACV,WAAY;GAEZ,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,OAAD;IACC,WAAU;IACV,QAAA,GAAQP,gBAAAA,GAAAA,CAAI,YAAa;IACzB,MAAK;IACL,eAAgB;IACY;IAChB;IACK;IACjB,eACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,0BAAAA,QAAY,eAAb,EAA2B,iBAAA,KAAiB,CAAA;IAT9C,UAAA,CAYG,UACF,iBAAA,GAAA,kBAAA,IAAA,CAAC,aAAD,CAAc,CAAA,CACR;;EACU,CAAA;CAEnB,CAAA;AAEH"}
@@ -1,59 +1,37 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/components/media-editor-provider/index.tsx
21
- var media_editor_provider_exports = {};
22
- __export(media_editor_provider_exports, {
23
- MediaEditorProvider: () => MediaEditorProvider,
24
- useMediaEditorContext: () => useMediaEditorContext
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
25
5
  });
26
- module.exports = __toCommonJS(media_editor_provider_exports);
27
- var import_element = require("@wordpress/element");
28
- var import_jsx_runtime = require("react/jsx-runtime");
29
- var MediaEditorContext = (0, import_element.createContext)(
30
- void 0
31
- );
32
- function MediaEditorProvider({
33
- value,
34
- onChange,
35
- settings = {},
36
- children
37
- }) {
38
- const contextValue = {
39
- media: value,
40
- onChange,
41
- fields: settings.fields || []
42
- };
43
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorContext.Provider, { value: contextValue, children });
6
+ let _wordpress_element = require("@wordpress/element");
7
+ let react_jsx_runtime = require("react/jsx-runtime");
8
+ // packages/media-editor/src/components/media-editor-provider/index.tsx
9
+ const MediaEditorContext = (0, _wordpress_element.createContext)(void 0);
10
+ function MediaEditorProvider({ value, onChange, settings = {}, children }) {
11
+ const contextValue = {
12
+ media: value,
13
+ onChange,
14
+ fields: settings.fields || [],
15
+ form: settings.form
16
+ };
17
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaEditorContext.Provider, {
18
+ value: contextValue,
19
+ children
20
+ });
44
21
  }
22
+ /**
23
+ * Hook to access the MediaEditor context.
24
+ *
25
+ * Must be used within a MediaEditorProvider component.
26
+ *
27
+ * @return MediaEditorContextValue value with media, onChange, and fields, etc.
28
+ */
45
29
  function useMediaEditorContext() {
46
- const context = (0, import_element.useContext)(MediaEditorContext);
47
- if (!context) {
48
- throw new Error(
49
- "useMediaEditorContext must be used within MediaEditorProvider"
50
- );
51
- }
52
- return context;
30
+ const context = (0, _wordpress_element.useContext)(MediaEditorContext);
31
+ if (!context) throw new Error("useMediaEditorContext must be used within MediaEditorProvider");
32
+ return context;
53
33
  }
54
- // Annotate the CommonJS export names for ESM import in node:
55
- 0 && (module.exports = {
56
- MediaEditorProvider,
57
- useMediaEditorContext
58
- });
59
- //# sourceMappingURL=index.cjs.map
34
+ exports.MediaEditorProvider = MediaEditorProvider;
35
+ exports.useMediaEditorContext = useMediaEditorContext;
36
+
37
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor-provider/index.tsx"],
4
- "sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport type { Field } from '@wordpress/dataviews';\nimport type { ReactNode } from 'react';\n\n/**\n * Media object from WordPress REST API.\n */\nexport interface Media {\n\tid?: number;\n\tsource_url?: string;\n\tmime_type?: string;\n\talt_text?: string;\n\ttitle?: string | { rendered?: string; raw?: string };\n\tcaption?: string | { rendered?: string; raw?: string };\n\tdescription?: string | { rendered?: string; raw?: string };\n\t[ key: string ]: any;\n}\n\n/**\n * Context value for MediaEditor.\n */\nexport interface MediaEditorContextValue {\n\tmedia?: Media;\n\tonChange?: ( updates: Partial< Media > ) => void;\n\tfields: Field< Media >[];\n}\n\n/**\n * Props for MediaEditorProvider.\n */\nexport interface MediaEditorProviderProps {\n\t/** The media object to edit. */\n\tvalue?: Media;\n\t/**\n\t * Callback when media is updated.\n\t *\n\t * Optional - if not provided, the MediaEditor can be used in a read-only mode,\n\t * useful for preview-only scenarios.\n\t */\n\tonChange?: ( updates: Partial< Media > ) => void;\n\t/** Configuration settings for the media editor. */\n\tsettings?: {\n\t\tfields?: Field< Media >[];\n\t};\n\t/** Child components. */\n\tchildren: ReactNode;\n}\n\nconst MediaEditorContext = createContext< MediaEditorContextValue | undefined >(\n\tundefined\n);\n\nexport function MediaEditorProvider( {\n\tvalue,\n\tonChange,\n\tsettings = {},\n\tchildren,\n}: MediaEditorProviderProps ) {\n\tconst contextValue: MediaEditorContextValue = {\n\t\tmedia: value,\n\t\tonChange,\n\t\tfields: settings.fields || [],\n\t};\n\n\treturn (\n\t\t<MediaEditorContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</MediaEditorContext.Provider>\n\t);\n}\n\n/**\n * Hook to access the MediaEditor context.\n *\n * Must be used within a MediaEditorProvider component.\n *\n * @return MediaEditorContextValue value with media, onChange, and fields, etc.\n */\nexport function useMediaEditorContext(): MediaEditorContextValue {\n\tconst context = useContext( MediaEditorContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorContext must be used within MediaEditorProvider'\n\t\t);\n\t}\n\treturn context;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0C;AAiExC;AAjBF,IAAM,yBAAqB;AAAA,EAC1B;AACD;AAEO,SAAS,oBAAqB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ;AACD,GAA8B;AAC7B,QAAM,eAAwC;AAAA,IAC7C,OAAO;AAAA,IACP;AAAA,IACA,QAAQ,SAAS,UAAU,CAAC;AAAA,EAC7B;AAEA,SACC,4CAAC,mBAAmB,UAAnB,EAA4B,OAAQ,cAClC,UACH;AAEF;AASO,SAAS,wBAAiD;AAChE,QAAM,cAAU,2BAAY,kBAAmB;AAC/C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.cjs","names":["createContext","useContext"],"sources":["../../../src/components/media-editor-provider/index.tsx"],"sourcesContent":["import { createContext, useContext } from '@wordpress/element';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { ReactNode } from 'react';\n\n/**\n * Media object from WordPress REST API.\n */\nexport interface Media {\n\tid?: number;\n\tsource_url?: string;\n\tmime_type?: string;\n\talt_text?: string;\n\ttitle?: string | { rendered?: string; raw?: string };\n\tcaption?: string | { rendered?: string; raw?: string };\n\tdescription?: string | { rendered?: string; raw?: string };\n\t[ key: string ]: any;\n}\n\n/**\n * Context value for MediaEditor.\n */\nexport interface MediaEditorContextValue {\n\tmedia?: Media;\n\tonChange?: ( updates: Partial< Media > ) => void;\n\tfields: Field< Media >[];\n\tform?: Form;\n}\n\n/**\n * Props for MediaEditorProvider.\n */\nexport interface MediaEditorProviderProps {\n\t/** The media object to edit. */\n\tvalue?: Media;\n\t/**\n\t * Callback when media is updated.\n\t *\n\t * Optional - if not provided, the MediaEditor can be used in a read-only mode,\n\t * useful for preview-only scenarios.\n\t */\n\tonChange?: ( updates: Partial< Media > ) => void;\n\t/** Configuration settings for the media editor. */\n\tsettings?: {\n\t\tfields?: Field< Media >[];\n\t\t/**\n\t\t * The form the fields are laid out with. When omitted, `MediaForm`\n\t\t * uses a default layout of the core attachment fields.\n\t\t */\n\t\tform?: Form;\n\t};\n\t/** Child components. */\n\tchildren: ReactNode;\n}\n\nconst MediaEditorContext = createContext< MediaEditorContextValue | undefined >(\n\tundefined\n);\n\nexport function MediaEditorProvider( {\n\tvalue,\n\tonChange,\n\tsettings = {},\n\tchildren,\n}: MediaEditorProviderProps ) {\n\tconst contextValue: MediaEditorContextValue = {\n\t\tmedia: value,\n\t\tonChange,\n\t\tfields: settings.fields || [],\n\t\tform: settings.form,\n\t};\n\n\treturn (\n\t\t<MediaEditorContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</MediaEditorContext.Provider>\n\t);\n}\n\n/**\n * Hook to access the MediaEditor context.\n *\n * Must be used within a MediaEditorProvider component.\n *\n * @return MediaEditorContextValue value with media, onChange, and fields, etc.\n */\nexport function useMediaEditorContext(): MediaEditorContextValue {\n\tconst context = useContext( MediaEditorContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorContext must be used within MediaEditorProvider'\n\t\t);\n\t}\n\treturn context;\n}\n"],"mappings":";;;;;;;;AAsDA,MAAM,sBAAA,GAAqBA,mBAAAA,cAAAA,CAC1B,KAAA,CACD;AAEA,SAAgB,oBAAqB,EACpC,OACA,UACA,WAAW,CAAC,GACZ,YAC6B;CAC7B,MAAM,eAAwC;EAC7C,OAAO;EACP;EACA,QAAQ,SAAS,UAAU,CAAC;EAC5B,MAAM,SAAS;CAChB;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,mBAAmB,UAApB;EAA6B,OAAQ;EAClC;CAC0B,CAAA;AAE/B;;;;;;;;AASA,SAAgB,wBAAiD;CAChE,MAAM,WAAA,GAAUC,mBAAAA,WAAAA,CAAY,kBAAmB;CAC/C,IAAK,CAAE,SACN,MAAM,IAAI,MACT,+DACD;CAED,OAAO;AACR"}
@@ -1,81 +1,80 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/components/media-form/index.tsx
21
- var media_form_exports = {};
22
- __export(media_form_exports, {
23
- default: () => MediaForm
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(media_form_exports);
26
- var import_dataviews = require("@wordpress/dataviews");
27
- var import_components = require("@wordpress/components");
28
- var import_ui = require("@wordpress/ui");
29
- var import_i18n = require("@wordpress/i18n");
30
- var import_media_editor_provider = require("../media-editor-provider/index.cjs");
31
- var import_jsx_runtime = require("react/jsx-runtime");
32
- function MediaForm({
33
- form: formOverrides,
34
- header
35
- }) {
36
- const { media, fields, onChange } = (0, import_media_editor_provider.useMediaEditorContext)();
37
- if (!media || !onChange) {
38
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-form media-editor-form--loading", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) });
39
- }
40
- const regularFieldIds = ["title", "alt_text", "caption", "description"];
41
- const sortedFields = [
42
- ...fields.filter(
43
- (field) => regularFieldIds.includes(field.id)
44
- ),
45
- ...fields.filter(
46
- (field) => !regularFieldIds.includes(field.id)
47
- )
48
- ];
49
- const defaultForm = {
50
- layout: {
51
- type: "panel"
52
- },
53
- fields: sortedFields.map((field) => {
54
- if (regularFieldIds.includes(field.id)) {
55
- return {
56
- id: field.id,
57
- layout: {
58
- type: "regular",
59
- labelPosition: "top"
60
- }
61
- };
62
- }
63
- return field.id;
64
- })
65
- };
66
- const form = formOverrides || defaultForm;
67
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-form", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [
68
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.VisuallyHidden, { render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {}), children: (0, import_i18n.__)("Media details") }),
69
- header,
70
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
71
- import_dataviews.DataForm,
72
- {
73
- data: media,
74
- fields,
75
- form,
76
- onChange
77
- }
78
- )
79
- ] }) });
6
+ let _wordpress_dataviews = require("@wordpress/dataviews");
7
+ let _wordpress_components = require("@wordpress/components");
8
+ let _wordpress_ui = require("@wordpress/ui");
9
+ let _wordpress_i18n = require("@wordpress/i18n");
10
+ let ___media_editor_provider_index_tsx = require("../media-editor-provider/index.cjs");
11
+ let react_jsx_runtime = require("react/jsx-runtime");
12
+ // packages/media-editor/src/components/media-form/index.tsx
13
+ const DEFAULT_FORM = {
14
+ layout: { type: "panel" },
15
+ fields: [
16
+ ...[
17
+ "title",
18
+ "alt_text",
19
+ "caption",
20
+ "description"
21
+ ].map((id) => ({
22
+ id,
23
+ layout: {
24
+ type: "regular",
25
+ labelPosition: "top"
26
+ }
27
+ })),
28
+ "date",
29
+ "author",
30
+ "filename",
31
+ "mime_type",
32
+ "filesize",
33
+ "media_dimensions",
34
+ "attached_to"
35
+ ]
36
+ };
37
+ /**
38
+ * MediaForm component for editing media metadata.
39
+ *
40
+ * Renders a DataForm with fields for editing media properties like
41
+ * title, alt text, caption, description, etc. The fields are laid out with
42
+ * the `form` prop, else the form of the provider settings, else a default
43
+ * form of the core attachment fields.
44
+ *
45
+ * @param props - Component props.
46
+ * @param props.form - Optional form configuration, which takes precedence
47
+ * over the form of the provider settings.
48
+ * @param props.header - Optional header content to display above the form.
49
+ * @return The MediaForm component.
50
+ */
51
+ function MediaForm({ form: formOverrides, header }) {
52
+ const { media, fields, form: settingsForm, onChange } = (0, ___media_editor_provider_index_tsx.useMediaEditorContext)();
53
+ if (!media || !onChange) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
54
+ className: "media-editor-form media-editor-form--loading",
55
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Spinner, {})
56
+ });
57
+ const form = formOverrides || settingsForm || DEFAULT_FORM;
58
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
59
+ className: "media-editor-form",
60
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalVStack, {
61
+ spacing: 4,
62
+ children: [
63
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.VisuallyHidden, {
64
+ render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {}),
65
+ children: (0, _wordpress_i18n.__)("Media details")
66
+ }),
67
+ header,
68
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_dataviews.DataForm, {
69
+ data: media,
70
+ fields,
71
+ form,
72
+ onChange
73
+ })
74
+ ]
75
+ })
76
+ });
80
77
  }
81
- //# sourceMappingURL=index.cjs.map
78
+ exports.default = MediaForm;
79
+
80
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-form/index.tsx"],
4
- "sourcesContent": ["import { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\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.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\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 { media, fields, onChange } = 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<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Fields that use a regular (non-panel) layout, rendered at the top.\n\tconst regularFieldIds = [ 'title', 'alt_text', 'caption', 'description' ];\n\n\t// Place the non-panel (regular layout) fields at the top of the array,\n\t// with the remaining panel fields below.\n\tconst sortedFields = [\n\t\t...fields.filter( ( field: Field< Media > ) =>\n\t\t\tregularFieldIds.includes( field.id )\n\t\t),\n\t\t...fields.filter(\n\t\t\t( field: Field< Media > ) => ! regularFieldIds.includes( field.id )\n\t\t),\n\t];\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: sortedFields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif ( regularFieldIds.includes( field.id ) ) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB;AAEzB,wBAAwD;AACxD,gBAA+B;AAC/B,kBAAmB;AAEnB,mCAAsC;AA+BlC;AATW,SAAR,UAA4B;AAAA,EAClC,MAAM;AAAA,EACN;AACD,GAAoB;AACnB,QAAM,EAAE,OAAO,QAAQ,SAAS,QAAI,oDAAsB;AAE1D,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WACC,4CAAC,SAAI,WAAU,gDACd,sDAAC,6BAAQ,GACV;AAAA,EAEF;AAGA,QAAM,kBAAkB,CAAE,SAAS,YAAY,WAAW,aAAc;AAIxE,QAAM,eAAe;AAAA,IACpB,GAAG,OAAO;AAAA,MAAQ,CAAE,UACnB,gBAAgB,SAAU,MAAM,EAAG;AAAA,IACpC;AAAA,IACA,GAAG,OAAO;AAAA,MACT,CAAE,UAA2B,CAAE,gBAAgB,SAAU,MAAM,EAAG;AAAA,IACnE;AAAA,EACD;AAGA,QAAM,cAAoB;AAAA,IACzB,QAAQ;AAAA,MACP,MAAM;AAAA,IACP;AAAA,IACA,QAAQ,aAAa,IAAK,CAAE,UAA2B;AAEtD,UAAK,gBAAgB,SAAU,MAAM,EAAG,GAAI;AAC3C,eAAO;AAAA,UACN,IAAI,MAAM;AAAA,UACV,QAAQ;AAAA,YACP,MAAM;AAAA,YACN,eAAe;AAAA,UAChB;AAAA,QACD;AAAA,MACD;AACA,aAAO,MAAM;AAAA,IACd,CAAE;AAAA,EACH;AAEA,QAAM,OAAO,iBAAiB;AAE9B,SACC,4CAAC,SAAI,WAAU,qBACd,uDAAC,kBAAAA,sBAAA,EAAO,SAAU,GACjB;AAAA,gDAAC,4BAAe,QAAS,4CAAC,QAAG,GAC1B,8BAAI,eAAgB,GACvB;AAAA,IACE;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
6
- "names": ["VStack"]
7
- }
1
+ {"version":3,"file":"index.cjs","names":["useMediaEditorContext","WCSpinner","VStack","VisuallyHidden","__","DataForm"],"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,cAAA,GACGA,mCAAAA,sBAAAA,CAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAU;EACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAU;EACd,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,gBAAD;KAAgB,QAAS,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,CAAK,CAAA;KAC3BC,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,eAAgB;IACP,CAAA;IACd;IACF,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}