@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131006.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 (217) hide show
  1. package/build/components/media-editor/index.cjs +560 -0
  2. package/build/components/media-editor/index.cjs.map +7 -0
  3. package/build/components/media-editor-canvas/index.cjs +14 -2
  4. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  5. package/build/components/media-editor-crop-panel/index.cjs +34 -27
  6. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  7. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
  8. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
  9. package/build/components/media-editor-modal/index.cjs +42 -430
  10. package/build/components/media-editor-modal/index.cjs.map +3 -3
  11. package/build/components/media-editor-toolbar/index.cjs +143 -75
  12. package/build/components/media-editor-toolbar/index.cjs.map +3 -3
  13. package/build/components/media-form/index.cjs +3 -0
  14. package/build/components/media-form/index.cjs.map +2 -2
  15. package/build/components/rotation-ruler/index.cjs +197 -0
  16. package/build/components/rotation-ruler/index.cjs.map +7 -0
  17. package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
  18. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
  19. package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
  20. package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
  21. package/build/image-editor/core/constants.cjs +9 -0
  22. package/build/image-editor/core/constants.cjs.map +2 -2
  23. package/build/image-editor/core/containment.cjs +7 -13
  24. package/build/image-editor/core/containment.cjs.map +2 -2
  25. package/build/image-editor/core/interaction-controller.cjs +43 -7
  26. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  27. package/build/image-editor/core/state.cjs +5 -1
  28. package/build/image-editor/core/state.cjs.map +2 -2
  29. package/build/image-editor/core/transform-style.cjs.map +1 -1
  30. package/build/image-editor/core/types.cjs.map +1 -1
  31. package/build/image-editor/core/viewport-state.cjs +50 -0
  32. package/build/image-editor/core/viewport-state.cjs.map +7 -0
  33. package/build/image-editor/react/components/cropper.cjs +192 -72
  34. package/build/image-editor/react/components/cropper.cjs.map +3 -3
  35. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
  36. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
  37. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
  38. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  39. package/build/image-editor/react/components/viewport-provider.cjs +51 -0
  40. package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
  41. package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
  42. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  43. package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
  44. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
  45. package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
  46. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  47. package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
  48. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
  49. package/build/image-editor/react/visually-hidden-style.cjs +41 -0
  50. package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
  51. package/build/private-apis.cjs +2 -0
  52. package/build/private-apis.cjs.map +2 -2
  53. package/build-module/components/media-editor/index.mjs +545 -0
  54. package/build-module/components/media-editor/index.mjs.map +7 -0
  55. package/build-module/components/media-editor-canvas/index.mjs +14 -2
  56. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  57. package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
  58. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  59. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
  60. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
  61. package/build-module/components/media-editor-modal/index.mjs +46 -455
  62. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  63. package/build-module/components/media-editor-toolbar/index.mjs +137 -77
  64. package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
  65. package/build-module/components/media-form/index.mjs +3 -0
  66. package/build-module/components/media-form/index.mjs.map +2 -2
  67. package/build-module/components/rotation-ruler/index.mjs +166 -0
  68. package/build-module/components/rotation-ruler/index.mjs.map +7 -0
  69. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
  70. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
  71. package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
  72. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
  73. package/build-module/image-editor/core/constants.mjs +6 -0
  74. package/build-module/image-editor/core/constants.mjs.map +2 -2
  75. package/build-module/image-editor/core/containment.mjs +6 -12
  76. package/build-module/image-editor/core/containment.mjs.map +2 -2
  77. package/build-module/image-editor/core/interaction-controller.mjs +50 -8
  78. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  79. package/build-module/image-editor/core/state.mjs +5 -1
  80. package/build-module/image-editor/core/state.mjs.map +2 -2
  81. package/build-module/image-editor/core/transform-style.mjs.map +1 -1
  82. package/build-module/image-editor/core/viewport-state.mjs +24 -0
  83. package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
  84. package/build-module/image-editor/react/components/cropper.mjs +195 -73
  85. package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
  86. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
  87. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  88. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
  89. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  90. package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
  91. package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
  92. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
  93. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  94. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
  95. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
  96. package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
  97. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  98. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
  99. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
  100. package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
  101. package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
  102. package/build-module/private-apis.mjs +2 -0
  103. package/build-module/private-apis.mjs.map +2 -2
  104. package/build-style/style-rtl.css +254 -29
  105. package/build-style/style.css +254 -29
  106. package/build-types/components/media-editor/index.d.ts +34 -0
  107. package/build-types/components/media-editor/index.d.ts.map +1 -0
  108. package/build-types/components/media-editor-canvas/index.d.ts +10 -1
  109. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  110. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  111. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  112. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
  113. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
  114. package/build-types/components/media-editor-modal/index.d.ts +2 -2
  115. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  116. package/build-types/components/media-editor-provider/index.d.ts +1 -1
  117. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  118. package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
  119. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
  120. package/build-types/components/media-form/index.d.ts +1 -1
  121. package/build-types/components/media-form/index.d.ts.map +1 -1
  122. package/build-types/components/rotation-ruler/index.d.ts +46 -0
  123. package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
  124. package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
  125. package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
  126. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
  127. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
  128. package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
  129. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
  130. package/build-types/image-editor/core/constants.d.ts +9 -0
  131. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  132. package/build-types/image-editor/core/containment.d.ts +11 -7
  133. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  134. package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
  135. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  136. package/build-types/image-editor/core/state.d.ts.map +1 -1
  137. package/build-types/image-editor/core/transform-style.d.ts +1 -1
  138. package/build-types/image-editor/core/types.d.ts +25 -0
  139. package/build-types/image-editor/core/types.d.ts.map +1 -1
  140. package/build-types/image-editor/core/viewport-state.d.ts +7 -0
  141. package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
  142. package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
  143. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  144. package/build-types/image-editor/react/components/cropper.d.ts +2 -1
  145. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  146. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
  147. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  148. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
  149. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
  150. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
  151. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  152. package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
  153. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
  154. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  155. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
  156. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
  157. package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
  158. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  159. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
  160. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
  161. package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
  162. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
  163. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
  164. package/build-types/private-apis.d.ts.map +1 -1
  165. package/build-types/store/actions.d.ts +3 -3
  166. package/build-types/store/actions.d.ts.map +1 -1
  167. package/package.json +16 -15
  168. package/src/components/media-editor/index.tsx +709 -0
  169. package/src/components/media-editor/style.scss +89 -0
  170. package/src/components/media-editor-canvas/index.tsx +24 -0
  171. package/src/components/media-editor-crop-panel/index.tsx +39 -27
  172. package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
  173. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
  174. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
  175. package/src/components/media-editor-modal/index.tsx +49 -589
  176. package/src/components/media-editor-modal/style.scss +13 -112
  177. package/src/components/media-editor-toolbar/index.tsx +122 -63
  178. package/src/components/media-editor-toolbar/style.scss +39 -11
  179. package/src/components/media-form/index.tsx +5 -0
  180. package/src/components/rotation-ruler/README.md +37 -0
  181. package/src/components/rotation-ruler/index.tsx +266 -0
  182. package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
  183. package/src/components/rotation-ruler/style.scss +147 -0
  184. package/src/components/rotation-ruler/test/index.tsx +109 -0
  185. package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
  186. package/src/hooks/use-crop-gesture-handlers.ts +54 -0
  187. package/src/image-editor/core/constants.ts +12 -0
  188. package/src/image-editor/core/containment.ts +16 -28
  189. package/src/image-editor/core/interaction-controller.ts +66 -10
  190. package/src/image-editor/core/state.ts +15 -8
  191. package/src/image-editor/core/test/camera.ts +15 -26
  192. package/src/image-editor/core/test/interaction-controller.ts +158 -7
  193. package/src/image-editor/core/test/state.ts +21 -1
  194. package/src/image-editor/core/transform-style.ts +1 -1
  195. package/src/image-editor/core/types.ts +16 -0
  196. package/src/image-editor/core/viewport-state.ts +33 -0
  197. package/src/image-editor/docs/architecture.md +1 -1
  198. package/src/image-editor/docs/recipes.md +2 -2
  199. package/src/image-editor/react/components/cropper.scss +28 -0
  200. package/src/image-editor/react/components/cropper.tsx +268 -72
  201. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
  202. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
  203. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
  204. package/src/image-editor/react/components/test/cropper.tsx +294 -5
  205. package/src/image-editor/react/components/viewport-provider.tsx +39 -0
  206. package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
  207. package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
  208. package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
  209. package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
  210. package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
  211. package/src/image-editor/react/hooks/use-interaction.ts +36 -6
  212. package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
  213. package/src/image-editor/react/visually-hidden-style.ts +15 -0
  214. package/src/private-apis.ts +2 -0
  215. package/src/style.scss +3 -0
  216. package/tsconfig.json +1 -0
  217. package/tsconfig.tsbuildinfo +1 -1
@@ -1,432 +1,10 @@
1
1
  // packages/media-editor/src/components/media-editor-modal/index.tsx
2
- import apiFetch from "@wordpress/api-fetch";
3
- import {
4
- Button,
5
- Flex,
6
- Modal,
7
- Spinner,
8
- __experimentalConfirmDialog as ConfirmDialog,
9
- privateApis as componentsPrivateApis
10
- } from "@wordpress/components";
11
- import { Stack } from "@wordpress/ui";
12
- import { useDispatch, useRegistry, useSelect } from "@wordpress/data";
13
- import { store as coreStore } from "@wordpress/core-data";
14
- import {
15
- createPortal,
16
- useCallback,
17
- useContext,
18
- useEffect,
19
- useMemo,
20
- useRef,
21
- useState
22
- } from "@wordpress/element";
23
- import { __, sprintf } from "@wordpress/i18n";
24
- import { close, drawerRight } from "@wordpress/icons";
25
- import { SnackbarNotices, store as noticesStore } from "@wordpress/notices";
26
- import {
27
- ComplementaryArea,
28
- InterfaceSkeleton,
29
- PinnedItems
30
- } from "@wordpress/interface";
31
- import { MediaEditorProvider } from "../media-editor-provider/index.mjs";
32
- import MediaPreview from "../media-preview/index.mjs";
33
- import MediaEditorCanvas from "../media-editor-canvas/index.mjs";
34
- import MediaEditorToolbar from "../media-editor-toolbar/index.mjs";
35
- import MediaEditorCropPanel, {
36
- resolveAspectRatio
37
- } from "../media-editor-crop-panel/index.mjs";
38
- import MediaForm from "../media-form/index.mjs";
2
+ import { Modal } from "@wordpress/components";
3
+ import { useDispatch, useSelect } from "@wordpress/data";
4
+ import { __ } from "@wordpress/i18n";
5
+ import MediaEditor from "../media-editor/index.mjs";
39
6
  import { store as mediaEditorStore } from "../../store/index.mjs";
40
- import { unlock } from "../../lock-unlock.mjs";
41
- import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
42
- import { CropperProvider, useCropper } from "../../image-editor/index.mjs";
43
- import { buildModifiers } from "./build-modifiers.mjs";
44
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
45
- var METADATA_EDIT_KEYS = [
46
- "title",
47
- "caption",
48
- "description",
49
- "alt_text",
50
- "post"
51
- ];
52
- var NOTICES_CONTEXT = "media-editor";
53
- var PLACEMENT_CONTROL_IDLE_MS = 300;
54
- var { Tabs } = unlock(componentsPrivateApis);
55
- function MediaEditorModalSidebar({ tabs }) {
56
- const tabsContextValue = useContext(Tabs.Context);
57
- return /* @__PURE__ */ jsx(
58
- ComplementaryArea,
59
- {
60
- scope: "media-editor",
61
- identifier: "media-editor/details",
62
- title: __("Details"),
63
- icon: drawerRight,
64
- isActiveByDefault: true,
65
- className: "media-editor-modal__sidebar",
66
- panelClassName: "media-editor-modal__sidebar-panel",
67
- headerClassName: "media-editor-modal__sidebar-header",
68
- header: /* @__PURE__ */ jsx(Tabs.Context.Provider, { value: tabsContextValue, children: /* @__PURE__ */ jsx(Tabs.TabList, { children: tabs.map((tab) => /* @__PURE__ */ jsx(Tabs.Tab, { tabId: tab.id, children: tab.title }, tab.id)) }) }),
69
- children: /* @__PURE__ */ jsx(Tabs.Context.Provider, { value: tabsContextValue, children: tabs.map((tab) => /* @__PURE__ */ jsx(
70
- Tabs.TabPanel,
71
- {
72
- tabId: tab.id,
73
- focusable: false,
74
- children: tab.panel
75
- },
76
- tab.id
77
- )) })
78
- }
79
- );
80
- }
81
- function HeaderActions({
82
- isSaving,
83
- hasMedia,
84
- hasChanges,
85
- onCancel,
86
- onSave
87
- }) {
88
- const saveDisabled = isSaving || !hasMedia || !hasChanges;
89
- return /* @__PURE__ */ jsxs(
90
- Flex,
91
- {
92
- className: "media-editor-modal__header-actions",
93
- justify: "flex-end",
94
- expanded: false,
95
- gap: 2,
96
- children: [
97
- /* @__PURE__ */ jsx(PinnedItems.Slot, { scope: "media-editor" }),
98
- /* @__PURE__ */ jsx(
99
- Button,
100
- {
101
- size: "compact",
102
- variant: "tertiary",
103
- onClick: onCancel,
104
- disabled: isSaving,
105
- accessibleWhenDisabled: true,
106
- children: __("Cancel")
107
- }
108
- ),
109
- /* @__PURE__ */ jsx(
110
- Button,
111
- {
112
- size: "compact",
113
- variant: "primary",
114
- onClick: onSave,
115
- isBusy: isSaving,
116
- disabled: saveDisabled,
117
- accessibleWhenDisabled: true,
118
- children: __("Save")
119
- }
120
- ),
121
- /* @__PURE__ */ jsx(
122
- Button,
123
- {
124
- size: "compact",
125
- icon: close,
126
- label: __("Close"),
127
- onClick: onCancel,
128
- disabled: isSaving,
129
- accessibleWhenDisabled: true
130
- }
131
- )
132
- ]
133
- }
134
- );
135
- }
136
- function MediaEditorModalContent({
137
- fields,
138
- id,
139
- media,
140
- hasEdits,
141
- aspectRatioPresets,
142
- onUpdate
143
- }) {
144
- const cropper = useCropper();
145
- const hasChanges = cropper.isDirty || hasEdits;
146
- const registry = useRegistry();
147
- const {
148
- clearEntityRecordEdits,
149
- editEntityRecord,
150
- receiveEntityRecords,
151
- saveEditedEntityRecord
152
- } = useDispatch(coreStore);
153
- const { closeMediaEditorModal } = useDispatch(mediaEditorStore);
154
- const { createErrorNotice, removeAllNotices } = useDispatch(noticesStore);
155
- const [isSaving, setIsSaving] = useState(false);
156
- const [isDiscardDialogOpen, setIsDiscardDialogOpen] = useState(false);
157
- const [isPlacementActive, setIsPlacementActive] = useState(false);
158
- const placementControlTimerRef = useRef();
159
- const [aspectRatioValue, setAspectRatioValue] = useState("0");
160
- const [freeformCrop, setFreeformCrop] = useState(true);
161
- const signalPlacementControlInteraction = useCallback(() => {
162
- setIsPlacementActive(true);
163
- clearTimeout(placementControlTimerRef.current);
164
- placementControlTimerRef.current = setTimeout(() => {
165
- setIsPlacementActive(false);
166
- }, PLACEMENT_CONTROL_IDLE_MS);
167
- }, []);
168
- useEffect(() => {
169
- return () => {
170
- clearTimeout(placementControlTimerRef.current);
171
- };
172
- }, []);
173
- useEffect(() => {
174
- setAspectRatioValue("0");
175
- setFreeformCrop(true);
176
- }, [id]);
177
- const mediaType = getMediaTypeFromMimeType(media?.mime_type).type;
178
- const isImage = !!media && mediaType === "image";
179
- const imageAspectRatio = useMemo(() => {
180
- if (!isImage) {
181
- return null;
182
- }
183
- const naturalWidth = Number(media?.media_details?.width);
184
- const naturalHeight = Number(media?.media_details?.height);
185
- if (Number.isFinite(naturalWidth) && Number.isFinite(naturalHeight) && naturalHeight > 0) {
186
- return naturalWidth / naturalHeight;
187
- }
188
- return null;
189
- }, [isImage, media]);
190
- const tabs = useMemo(() => {
191
- const detailsTab = {
192
- id: "details",
193
- title: __("Details"),
194
- panel: /* @__PURE__ */ jsx(
195
- Stack,
196
- {
197
- className: "media-editor-modal__panel",
198
- direction: "column",
199
- gap: "lg",
200
- children: /* @__PURE__ */ jsx(MediaForm, {})
201
- }
202
- )
203
- };
204
- if (!isImage) {
205
- return [detailsTab];
206
- }
207
- return [
208
- {
209
- id: "crop",
210
- title: __("Crop"),
211
- panel: /* @__PURE__ */ jsx(
212
- Stack,
213
- {
214
- className: "media-editor-modal__panel",
215
- direction: "column",
216
- gap: "lg",
217
- children: /* @__PURE__ */ jsx(
218
- MediaEditorCropPanel,
219
- {
220
- aspectRatioValue,
221
- onAspectRatioChange: setAspectRatioValue,
222
- freeformCrop,
223
- onFreeformChange: setFreeformCrop,
224
- onPlacementControlInteraction: signalPlacementControlInteraction,
225
- aspectRatioPresets
226
- }
227
- )
228
- }
229
- )
230
- },
231
- detailsTab
232
- ];
233
- }, [
234
- isImage,
235
- aspectRatioValue,
236
- freeformCrop,
237
- aspectRatioPresets,
238
- signalPlacementControlInteraction
239
- ]);
240
- const handleChange = (updates) => {
241
- editEntityRecord("postType", "attachment", id, updates);
242
- };
243
- const discardAndClose = () => {
244
- removeAllNotices("snackbar", NOTICES_CONTEXT);
245
- clearEntityRecordEdits("postType", "attachment", id);
246
- closeMediaEditorModal();
247
- };
248
- const handleRequestClose = () => {
249
- if (isSaving) {
250
- return;
251
- }
252
- if (hasChanges) {
253
- setIsDiscardDialogOpen(true);
254
- return;
255
- }
256
- discardAndClose();
257
- };
258
- const handleSave = async () => {
259
- removeAllNotices("snackbar", NOTICES_CONTEXT);
260
- setIsSaving(true);
261
- try {
262
- let saved;
263
- const modifiers = cropper.isDirty && cropper.state.image ? buildModifiers(cropper.state, {
264
- width: cropper.state.image.naturalWidth,
265
- height: cropper.state.image.naturalHeight
266
- }) : [];
267
- if (modifiers.length > 0) {
268
- const pendingEdits = registry.select(coreStore).getEntityRecordNonTransientEdits(
269
- "postType",
270
- "attachment",
271
- id
272
- );
273
- const metadataEdits = {};
274
- for (const key of METADATA_EDIT_KEYS) {
275
- if (pendingEdits && key in pendingEdits) {
276
- metadataEdits[key] = pendingEdits[key];
277
- }
278
- }
279
- saved = await apiFetch({
280
- path: `/wp/v2/media/${id}/edit`,
281
- method: "POST",
282
- data: {
283
- src: media?.source_url,
284
- modifiers,
285
- ...metadataEdits
286
- }
287
- });
288
- if (saved) {
289
- receiveEntityRecords(
290
- "postType",
291
- "attachment",
292
- saved,
293
- void 0,
294
- true
295
- );
296
- }
297
- } else {
298
- saved = await saveEditedEntityRecord(
299
- "postType",
300
- "attachment",
301
- id
302
- );
303
- }
304
- const next = saved ?? media;
305
- if (next && next.id !== id) {
306
- clearEntityRecordEdits("postType", "attachment", id);
307
- }
308
- if (next && next.id && onUpdate) {
309
- onUpdate({ id: next.id, url: next.source_url });
310
- }
311
- closeMediaEditorModal();
312
- } catch (error) {
313
- const message = error instanceof Error ? error.message : error?.message ?? __("An unknown error occurred.");
314
- createErrorNotice(
315
- sprintf(
316
- /* translators: %s: Error message. */
317
- __("Could not save image. %s"),
318
- message
319
- ),
320
- { type: "snackbar", context: NOTICES_CONTEXT }
321
- );
322
- } finally {
323
- setIsSaving(false);
324
- }
325
- };
326
- return /* @__PURE__ */ jsxs(
327
- Modal,
328
- {
329
- className: "media-editor-modal",
330
- title: __("Edit media"),
331
- size: "fill",
332
- isDismissible: false,
333
- shouldCloseOnClickOutside: !hasChanges && !isSaving,
334
- onKeyDown: (event) => {
335
- if (event.code !== "Escape" && event.key !== "Escape") {
336
- return;
337
- }
338
- if (isSaving) {
339
- event.preventDefault();
340
- return;
341
- }
342
- if (hasChanges) {
343
- event.preventDefault();
344
- setIsDiscardDialogOpen(true);
345
- }
346
- },
347
- onRequestClose: handleRequestClose,
348
- headerActions: /* @__PURE__ */ jsx(
349
- HeaderActions,
350
- {
351
- isSaving,
352
- hasMedia: !!media,
353
- hasChanges,
354
- onCancel: handleRequestClose,
355
- onSave: handleSave
356
- }
357
- ),
358
- children: [
359
- /* @__PURE__ */ jsxs(
360
- MediaEditorProvider,
361
- {
362
- value: media ?? void 0,
363
- onChange: handleChange,
364
- settings: { fields },
365
- children: [
366
- !media ? /* @__PURE__ */ jsx("div", { className: "media-editor-modal__loading", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
367
- /* @__PURE__ */ jsx(Tabs, { children: /* @__PURE__ */ jsx(MediaEditorModalSidebar, { tabs }) }),
368
- /* @__PURE__ */ jsx(
369
- InterfaceSkeleton,
370
- {
371
- className: "media-editor-modal__skeleton",
372
- content: /* @__PURE__ */ jsx("div", { className: "media-editor-modal__canvas", children: isImage ? /* @__PURE__ */ jsx(
373
- MediaEditorCanvas,
374
- {
375
- aspectRatio: resolveAspectRatio(
376
- aspectRatioValue,
377
- imageAspectRatio
378
- ),
379
- freeformCrop,
380
- isPlacementActive
381
- }
382
- ) : /* @__PURE__ */ jsx(MediaPreview, {}) }),
383
- footer: isImage ? /* @__PURE__ */ jsx(
384
- MediaEditorToolbar,
385
- {
386
- onReset: () => {
387
- setAspectRatioValue("0");
388
- setFreeformCrop(true);
389
- },
390
- onPlacementControlInteraction: signalPlacementControlInteraction
391
- }
392
- ) : void 0,
393
- sidebar: /* @__PURE__ */ jsx(ComplementaryArea.Slot, { scope: "media-editor" })
394
- }
395
- )
396
- ] }),
397
- /* @__PURE__ */ jsx(
398
- ConfirmDialog,
399
- {
400
- isOpen: isDiscardDialogOpen,
401
- confirmButtonText: __("Discard"),
402
- cancelButtonText: __("Keep editing"),
403
- onCancel: () => setIsDiscardDialogOpen(false),
404
- onConfirm: () => {
405
- setIsDiscardDialogOpen(false);
406
- discardAndClose();
407
- },
408
- children: __(
409
- "Are you sure you want to discard your unsaved changes?"
410
- )
411
- }
412
- )
413
- ]
414
- }
415
- ),
416
- createPortal(
417
- /* @__PURE__ */ jsx(
418
- SnackbarNotices,
419
- {
420
- className: "media-editor-modal__snackbar",
421
- context: NOTICES_CONTEXT
422
- }
423
- ),
424
- document.body
425
- )
426
- ]
427
- }
428
- );
429
- }
7
+ import { jsx } from "react/jsx-runtime";
430
8
  function MediaEditorModal({
431
9
  fields = [],
432
10
  aspectRatioPresets
@@ -439,41 +17,54 @@ function MediaEditorModal({
439
17
  onUpdate: getOnUpdate()
440
18
  };
441
19
  }, []);
442
- const { media, hasEdits } = useSelect(
443
- (select) => {
444
- if (!id) {
445
- return { media: null, hasEdits: false };
446
- }
447
- const { getEditedEntityRecord, hasEditsForEntityRecord } = select(coreStore);
448
- return {
449
- media: getEditedEntityRecord(
450
- "postType",
451
- "attachment",
452
- id
453
- ),
454
- hasEdits: hasEditsForEntityRecord(
455
- "postType",
456
- "attachment",
457
- id
458
- )
459
- };
460
- },
461
- [id]
462
- );
20
+ const { closeMediaEditorModal } = useDispatch(mediaEditorStore);
463
21
  if (!isModalOpen || !id) {
464
22
  return null;
465
23
  }
466
- return /* @__PURE__ */ jsx(CropperProvider, { children: /* @__PURE__ */ jsx(
467
- MediaEditorModalContent,
24
+ const portalElement = typeof document === "undefined" ? null : document.body;
25
+ return /* @__PURE__ */ jsx(
26
+ MediaEditor,
468
27
  {
469
- fields,
470
28
  id,
471
- media,
472
- hasEdits,
29
+ fields,
473
30
  aspectRatioPresets,
474
- onUpdate
31
+ showCloseButton: true,
32
+ shouldCloseOnEsc: true,
33
+ noticesClassName: "media-editor-modal__snackbar",
34
+ noticesPortalElement: portalElement,
35
+ onClose: closeMediaEditorModal,
36
+ onSaved: ({ id: savedId, url }) => {
37
+ if (savedId && onUpdate) {
38
+ const update = {
39
+ id: savedId,
40
+ url
41
+ };
42
+ onUpdate(update);
43
+ }
44
+ closeMediaEditorModal();
45
+ },
46
+ renderFrame: ({
47
+ children,
48
+ headerActions,
49
+ onRequestClose,
50
+ onKeyDown,
51
+ shouldCloseOnClickOutside
52
+ }) => /* @__PURE__ */ jsx(
53
+ Modal,
54
+ {
55
+ className: "media-editor-modal",
56
+ title: __("Edit media"),
57
+ size: "fill",
58
+ isDismissible: false,
59
+ shouldCloseOnClickOutside,
60
+ onKeyDown,
61
+ onRequestClose,
62
+ headerActions,
63
+ children
64
+ }
65
+ )
475
66
  }
476
- ) }, id);
67
+ );
477
68
  }
478
69
  var media_editor_modal_default = MediaEditorModal;
479
70
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-editor-modal/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\tButton,\n\tFlex,\n\tModal,\n\tSpinner,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tcreatePortal,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { close, drawerRight } from '@wordpress/icons';\nimport { SnackbarNotices, store as noticesStore } from '@wordpress/notices';\nimport type { Field } from '@wordpress/dataviews';\nimport {\n\tComplementaryArea,\n\tInterfaceSkeleton,\n\tPinnedItems,\n\t// No type declarations available for @wordpress/interface.\n\t// @ts-expect-error\n} from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport { MediaEditorProvider } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport MediaPreview from '../media-preview';\nimport MediaEditorCanvas from '../media-editor-canvas';\nimport MediaEditorToolbar from '../media-editor-toolbar';\nimport MediaEditorCropPanel, {\n\tresolveAspectRatio,\n} from '../media-editor-crop-panel';\nimport MediaForm from '../media-form';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\nimport { unlock } from '../../lock-unlock';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { CropperProvider, useCropper } from '../../image-editor';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport { buildModifiers } from './build-modifiers';\n\n// Details-tab edits the modal bundles into a transformed `/edit` request.\n// Matches Core's `WP_REST_Attachments_Controller::get_edit_media_item_args`\n// \u2014 that endpoint's arg schema explicitly whitelists only these fields\n// (title / caption / description / alt_text / post), so forwarding any\n// others would fail REST validation with `rest_invalid_param`. Staged\n// edits to fields outside this list are not forwarded; a follow-up could\n// persist them via a separate `saveEditedEntityRecord` call.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope save-failure snackbars to this modal so they don't leak into the\n// host editor's notices tray (and vice versa).\nconst NOTICES_CONTEXT = 'media-editor';\nconst PLACEMENT_CONTROL_IDLE_MS = 300;\n\nconst { Tabs } = unlock( componentsPrivateApis );\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 modal.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\ninterface ModalTab {\n\tid: string;\n\ttitle: string;\n\tpanel: JSX.Element;\n}\n\n// Renders the `ComplementaryArea` with a tab list in its header, mirroring\n// the post editor's pattern in\n// `packages/editor/src/components/sidebar/index.js`. The `header` prop\n// replaces `ComplementaryArea`'s default `<h2>{ title }</h2>` row \u2014 `title`\n// is still passed so it can label the pinned toolbar button. Tabs context\n// must be re-provided on both sides of the Slot/Fill because the Fill\n// doesn't preserve the Tabs React context across to the Slot.\nfunction MediaEditorModalSidebar( { tabs }: { tabs: ModalTab[] } ) {\n\tconst tabsContextValue = useContext( Tabs.Context );\n\treturn (\n\t\t<ComplementaryArea\n\t\t\tscope=\"media-editor\"\n\t\t\tidentifier=\"media-editor/details\"\n\t\t\ttitle={ __( 'Details' ) }\n\t\t\ticon={ drawerRight }\n\t\t\tisActiveByDefault\n\t\t\tclassName=\"media-editor-modal__sidebar\"\n\t\t\tpanelClassName=\"media-editor-modal__sidebar-panel\"\n\t\t\theaderClassName=\"media-editor-modal__sidebar-header\"\n\t\t\theader={\n\t\t\t\t<Tabs.Context.Provider value={ tabsContextValue }>\n\t\t\t\t\t<Tabs.TabList>\n\t\t\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t\t\t<Tabs.Tab key={ tab.id } tabId={ tab.id }>\n\t\t\t\t\t\t\t\t{ tab.title }\n\t\t\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t</Tabs.TabList>\n\t\t\t\t</Tabs.Context.Provider>\n\t\t\t}\n\t\t>\n\t\t\t<Tabs.Context.Provider value={ tabsContextValue }>\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<Tabs.TabPanel\n\t\t\t\t\t\tkey={ tab.id }\n\t\t\t\t\t\ttabId={ tab.id }\n\t\t\t\t\t\tfocusable={ false }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ tab.panel }\n\t\t\t\t\t</Tabs.TabPanel>\n\t\t\t\t) ) }\n\t\t\t</Tabs.Context.Provider>\n\t\t</ComplementaryArea>\n\t);\n}\n\ninterface HeaderActionsProps {\n\tisSaving: boolean;\n\thasMedia: boolean;\n\thasChanges: boolean;\n\tonCancel: () => void;\n\tonSave: () => void;\n}\n\nfunction HeaderActions( {\n\tisSaving,\n\thasMedia,\n\thasChanges,\n\tonCancel,\n\tonSave,\n}: HeaderActionsProps ) {\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"media-editor-modal__header-actions\"\n\t\t\tjustify=\"flex-end\"\n\t\t\texpanded={ false }\n\t\t\tgap={ 2 }\n\t\t>\n\t\t\t<PinnedItems.Slot scope=\"media-editor\" />\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\tvariant=\"tertiary\"\n\t\t\t\tonClick={ onCancel }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ onSave }\n\t\t\t\tisBusy={ isSaving }\n\t\t\t\tdisabled={ saveDisabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t{ __( 'Save' ) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ close }\n\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\tonClick={ onCancel }\n\t\t\t\tdisabled={ isSaving }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t/>\n\t\t</Flex>\n\t);\n}\n\ninterface MediaEditorModalContentProps {\n\tfields: Field< Media >[];\n\tid: number;\n\tmedia: Media | null;\n\thasEdits: boolean;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonUpdate: ( ( updated: MediaEditorModalUpdate ) => void ) | null;\n}\n\n// Inner component rendered inside `CropperProvider` so it can read\n// `isDirty` from the cropper. The outer `MediaEditorModal` keeps the\n// store reads and provider tree above this.\nfunction MediaEditorModalContent( {\n\tfields,\n\tid,\n\tmedia,\n\thasEdits,\n\taspectRatioPresets,\n\tonUpdate,\n}: MediaEditorModalContentProps ) {\n\tconst cropper = useCropper();\n\tconst hasChanges = cropper.isDirty || hasEdits;\n\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\teditEntityRecord,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );\n\tconst [ isPlacementActive, setIsPlacementActive ] = useState( false );\n\tconst placementControlTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\n\n\tconst [ aspectRatioValue, setAspectRatioValue ] = useState( '0' );\n\tconst [ freeformCrop, setFreeformCrop ] = useState( true );\n\n\tconst signalPlacementControlInteraction = useCallback( () => {\n\t\tsetIsPlacementActive( true );\n\t\tclearTimeout( placementControlTimerRef.current );\n\t\tplacementControlTimerRef.current = setTimeout( () => {\n\t\t\tsetIsPlacementActive( false );\n\t\t}, PLACEMENT_CONTROL_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( placementControlTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Reset aspect-ratio / freeform state when the media changes, so the\n\t// next image starts from the defaults.\n\tuseEffect( () => {\n\t\tsetAspectRatioValue( '0' );\n\t\tsetFreeformCrop( true );\n\t}, [ id ] );\n\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;\n\tconst isImage = !! media && mediaType === 'image';\n\n\tconst imageAspectRatio = useMemo( () => {\n\t\tif ( ! isImage ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst naturalWidth = Number( media?.media_details?.width );\n\t\tconst naturalHeight = Number( media?.media_details?.height );\n\t\tif (\n\t\t\tNumber.isFinite( naturalWidth ) &&\n\t\t\tNumber.isFinite( naturalHeight ) &&\n\t\t\tnaturalHeight > 0\n\t\t) {\n\t\t\treturn naturalWidth / naturalHeight;\n\t\t}\n\t\treturn null;\n\t}, [ isImage, media ] );\n\n\tconst tabs = useMemo< ModalTab[] >( () => {\n\t\tconst detailsTab: ModalTab = {\n\t\t\tid: 'details',\n\t\t\ttitle: __( 'Details' ),\n\t\t\tpanel: (\n\t\t\t\t<Stack\n\t\t\t\t\tclassName=\"media-editor-modal__panel\"\n\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\tgap=\"lg\"\n\t\t\t\t>\n\t\t\t\t\t<MediaForm />\n\t\t\t\t</Stack>\n\t\t\t),\n\t\t};\n\t\tif ( ! isImage ) {\n\t\t\treturn [ detailsTab ];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tid: 'crop',\n\t\t\t\ttitle: __( 'Crop' ),\n\t\t\t\tpanel: (\n\t\t\t\t\t<Stack\n\t\t\t\t\t\tclassName=\"media-editor-modal__panel\"\n\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\tgap=\"lg\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MediaEditorCropPanel\n\t\t\t\t\t\t\taspectRatioValue={ aspectRatioValue }\n\t\t\t\t\t\t\tonAspectRatioChange={ setAspectRatioValue }\n\t\t\t\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\t\t\t\tonFreeformChange={ setFreeformCrop }\n\t\t\t\t\t\t\tonPlacementControlInteraction={\n\t\t\t\t\t\t\t\tsignalPlacementControlInteraction\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Stack>\n\t\t\t\t),\n\t\t\t},\n\t\t\tdetailsTab,\n\t\t];\n\t}, [\n\t\tisImage,\n\t\taspectRatioValue,\n\t\tfreeformCrop,\n\t\taspectRatioPresets,\n\t\tsignalPlacementControlInteraction,\n\t] );\n\n\tconst handleChange = ( updates: Partial< Media > ) => {\n\t\teditEntityRecord( 'postType', 'attachment', id, updates );\n\t};\n\n\tconst discardAndClose = () => {\n\t\tremoveAllNotices( 'snackbar', NOTICES_CONTEXT );\n\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\n\t\tcloseMediaEditorModal();\n\t};\n\n\tconst handleRequestClose = () => {\n\t\t// Disallow closing while a save is in flight so the in-progress\n\t\t// request can settle without the modal unmounting under it.\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasChanges ) {\n\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\treturn;\n\t\t}\n\t\tdiscardAndClose();\n\t};\n\n\tconst handleSave = async () => {\n\t\t// Clear any prior failure snackbar so a successful retry doesn't\n\t\t// leave a stale \"Could not save image\" hovering.\n\t\tremoveAllNotices( 'snackbar', NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\n\t\t\tconst modifiers =\n\t\t\t\tcropper.isDirty && cropper.state.image\n\t\t\t\t\t? buildModifiers( cropper.state, {\n\t\t\t\t\t\t\twidth: cropper.state.image.naturalWidth,\n\t\t\t\t\t\t\theight: cropper.state.image.naturalHeight,\n\t\t\t\t\t } )\n\t\t\t\t\t: [];\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\t// Bundle staged Details-tab edits into the same /edit\n\t\t\t\t// request. Transformed saves duplicate the attachment,\n\t\t\t\t// and the prior core-data edits were staged against the\n\t\t\t\t// old id \u2014 if we don't forward them here they'd be\n\t\t\t\t// silently lost. Core's `edit_media_item` honors these\n\t\t\t\t// keys via `prepare_item_for_database` and `alt_text`.\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tid\n\t\t\t\t\t) as Record< string, unknown > | undefined;\n\t\t\t\tconst metadataEdits: Record< string, unknown > = {};\n\t\t\t\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\t\t\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\t\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ id }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: media?.source_url,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\t// Put the newly-created attachment into the core-data\n\t\t\t\t\t// cache so downstream consumers see it without an\n\t\t\t\t\t// extra fetch round-trip.\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tid\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? media ) as Media | null;\n\n\t\t\t// A transformed save creates a new attachment; clear staged\n\t\t\t// edits on the old record so it doesn't appear dirty in the\n\t\t\t// Media Library afterwards.\n\t\t\tif ( next && next.id !== id ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', id );\n\t\t\t}\n\n\t\t\tif ( next && next.id && onUpdate ) {\n\t\t\t\t// Normalize to the public callback shape \u2014 see\n\t\t\t\t// `MediaEditorModalUpdate` in `../../store/actions.ts`.\n\t\t\t\tonUpdate( { id: next.id, url: next.source_url } );\n\t\t\t}\n\t\t\tcloseMediaEditorModal();\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( error as { message?: string } )?.message ??\n\t\t\t\t\t __( 'An unknown error occurred.' );\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\tmessage\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar', context: NOTICES_CONTEXT }\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-modal\"\n\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\tsize=\"fill\"\n\t\t\tisDismissible={ false }\n\t\t\tshouldCloseOnClickOutside={ ! hasChanges && ! isSaving }\n\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\tif ( event.code !== 'Escape' && event.key !== 'Escape' ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// While saving, swallow ESC so the in-progress request\n\t\t\t\t// can settle without the modal closing under it.\n\t\t\t\tif ( isSaving ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// When there are pending changes, intercept ESC and\n\t\t\t\t// open the confirm dialog ourselves. `preventDefault`\n\t\t\t\t// short-circuits Modal's own ESC-to-close handler on\n\t\t\t\t// the overlay so the modal doesn't animate out before\n\t\t\t\t// the dialog appears.\n\t\t\t\tif ( hasChanges ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonRequestClose={ handleRequestClose }\n\t\t\theaderActions={\n\t\t\t\t<HeaderActions\n\t\t\t\t\tisSaving={ isSaving }\n\t\t\t\t\thasMedia={ !! media }\n\t\t\t\t\thasChanges={ hasChanges }\n\t\t\t\t\tonCancel={ handleRequestClose }\n\t\t\t\t\tonSave={ handleSave }\n\t\t\t\t/>\n\t\t\t}\n\t\t>\n\t\t\t<MediaEditorProvider\n\t\t\t\tvalue={ media ?? undefined }\n\t\t\t\tonChange={ handleChange }\n\t\t\t\tsettings={ { fields } }\n\t\t\t>\n\t\t\t\t{ ! media ? (\n\t\t\t\t\t<div className=\"media-editor-modal__loading\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</div>\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<Tabs>\n\t\t\t\t\t\t\t<MediaEditorModalSidebar tabs={ tabs } />\n\t\t\t\t\t\t</Tabs>\n\t\t\t\t\t\t<InterfaceSkeleton\n\t\t\t\t\t\t\tclassName=\"media-editor-modal__skeleton\"\n\t\t\t\t\t\t\tcontent={\n\t\t\t\t\t\t\t\t<div className=\"media-editor-modal__canvas\">\n\t\t\t\t\t\t\t\t\t{ isImage ? (\n\t\t\t\t\t\t\t\t\t\t<MediaEditorCanvas\n\t\t\t\t\t\t\t\t\t\t\taspectRatio={ resolveAspectRatio(\n\t\t\t\t\t\t\t\t\t\t\t\taspectRatioValue,\n\t\t\t\t\t\t\t\t\t\t\t\timageAspectRatio\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\t\t\t\t\t\t\t\tisPlacementActive={\n\t\t\t\t\t\t\t\t\t\t\t\tisPlacementActive\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<MediaPreview />\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfooter={\n\t\t\t\t\t\t\t\tisImage ? (\n\t\t\t\t\t\t\t\t\t<MediaEditorToolbar\n\t\t\t\t\t\t\t\t\t\tonReset={ () => {\n\t\t\t\t\t\t\t\t\t\t\tsetAspectRatioValue( '0' );\n\t\t\t\t\t\t\t\t\t\t\tsetFreeformCrop( true );\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\tonPlacementControlInteraction={\n\t\t\t\t\t\t\t\t\t\t\tsignalPlacementControlInteraction\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsidebar={\n\t\t\t\t\t\t\t\t<ComplementaryArea.Slot scope=\"media-editor\" />\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\t{ /* Rendered inside the parent Modal so it's tracked as\n\t\t\t\t\t a nested dismisser. As a top-level sibling it would,\n\t\t\t\t\t on mount, request the parent Modal close. */ }\n\t\t\t\t<ConfirmDialog\n\t\t\t\t\tisOpen={ isDiscardDialogOpen }\n\t\t\t\t\tconfirmButtonText={ __( 'Discard' ) }\n\t\t\t\t\tcancelButtonText={ __( 'Keep editing' ) }\n\t\t\t\t\tonCancel={ () => setIsDiscardDialogOpen( false ) }\n\t\t\t\t\tonConfirm={ () => {\n\t\t\t\t\t\tsetIsDiscardDialogOpen( false );\n\t\t\t\t\t\tdiscardAndClose();\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Are you sure you want to discard your unsaved changes?'\n\t\t\t\t\t) }\n\t\t\t\t</ConfirmDialog>\n\t\t\t</MediaEditorProvider>\n\t\t\t{ createPortal(\n\t\t\t\t<SnackbarNotices\n\t\t\t\t\tclassName=\"media-editor-modal__snackbar\"\n\t\t\t\t\tcontext={ NOTICES_CONTEXT }\n\t\t\t\t/>,\n\t\t\t\tdocument.body\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate } = useSelect( ( select ) => {\n\t\tconst { isOpen, getId, getOnUpdate } = select( mediaEditorStore );\n\t\treturn {\n\t\t\tisModalOpen: isOpen(),\n\t\t\tid: getId(),\n\t\t\tonUpdate: getOnUpdate(),\n\t\t};\n\t}, [] );\n\n\tconst { media, hasEdits } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn { media: null, hasEdits: false };\n\t\t\t}\n\t\t\tconst { getEditedEntityRecord, hasEditsForEntityRecord } =\n\t\t\t\tselect( coreStore );\n\t\t\treturn {\n\t\t\t\tmedia: getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tid\n\t\t\t\t) as Media,\n\t\t\t\thasEdits: hasEditsForEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tid\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ id ]\n\t);\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\t// `CropperProvider` is always mounted while the modal is open \u2014 it's\n\t// just a `useReducer` with no side effects \u2014 so the inner component\n\t// can read `isDirty` for images without forking on media type. The\n\t// `key` remounts the provider when the edited attachment changes,\n\t// discarding the previous cropper state. Keying on `id` (rather than\n\t// `media?.id`) avoids a remount when `media` resolves from `null` to\n\t// the loaded record on open \u2014 that flip would otherwise re-run the\n\t// modal's entry animation and cause a visible flicker.\n\treturn (\n\t\t<CropperProvider key={ id }>\n\t\t\t<MediaEditorModalContent\n\t\t\t\tfields={ fields }\n\t\t\t\tid={ id }\n\t\t\t\tmedia={ media }\n\t\t\t\thasEdits={ hasEdits }\n\t\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\t\tonUpdate={ onUpdate }\n\t\t\t/>\n\t\t</CropperProvider>\n\t);\n}\n\nexport default MediaEditorModal;\n"],
5
- "mappings": ";AAGA,OAAO,cAAc;AACrB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAA+B;AAAA,EAC/B,eAAe;AAAA,OACT;AACP,SAAS,aAAa;AACtB,SAAS,aAAa,aAAa,iBAAiB;AACpD,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AA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SACC,oBAAC,mBACA;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACD,KARsB,EASvB;AAEF;AAEA,IAAO,6BAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\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\nexport function MediaEditorModal( {\n\tfields = [],\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate } = useSelect( ( select ) => {\n\t\tconst { isOpen, getId, getOnUpdate } = select( mediaEditorStore );\n\t\treturn {\n\t\t\tisModalOpen: isOpen(),\n\t\t\tid: getId(),\n\t\t\tonUpdate: getOnUpdate(),\n\t\t};\n\t}, [] );\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\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\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshowCloseButton\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ closeMediaEditorModal }\n\t\t\tonSaved={ ( { id: savedId, url } ) => {\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\tcloseMediaEditorModal();\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\theaderActions,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<Modal\n\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\theaderActions={ headerActions }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],
5
+ "mappings": ";AAGA,SAAS,aAAa;AACtB,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AAMnB,OAAO,iBAAiB;AAExB,SAAS,SAAS,wBAAwB;AAoEtC;AAjDG,SAAS,iBAAkB;AAAA,EACjC,SAAS,CAAC;AAAA,EACV;AACD,GAA2B;AAC1B,QAAM,EAAE,aAAa,IAAI,SAAS,IAAI,UAAW,CAAE,WAAY;AAC9D,UAAM,EAAE,QAAQ,OAAO,YAAY,IAAI,OAAQ,gBAAiB;AAChE,WAAO;AAAA,MACN,aAAa,OAA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