@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131032.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.
- package/build/components/media-editor/index.cjs +560 -0
- package/build/components/media-editor/index.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +14 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +34 -27
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +42 -430
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-toolbar/index.cjs +143 -75
- package/build/components/media-editor-toolbar/index.cjs.map +3 -3
- package/build/components/media-form/index.cjs +3 -0
- package/build/components/media-form/index.cjs.map +2 -2
- package/build/components/rotation-ruler/index.cjs +197 -0
- package/build/components/rotation-ruler/index.cjs.map +7 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
- package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
- package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +9 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +7 -13
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs +43 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +5 -1
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs.map +1 -1
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/core/viewport-state.cjs +50 -0
- package/build/image-editor/core/viewport-state.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +192 -72
- package/build/image-editor/react/components/cropper.cjs.map +3 -3
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/components/viewport-provider.cjs +51 -0
- package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
- package/build/image-editor/react/visually-hidden-style.cjs +41 -0
- package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
- package/build/private-apis.cjs +2 -0
- package/build/private-apis.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +545 -0
- package/build-module/components/media-editor/index.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +14 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +46 -455
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-toolbar/index.mjs +137 -77
- package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs +3 -0
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs +166 -0
- package/build-module/components/rotation-ruler/index.mjs.map +7 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +6 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +6 -12
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs +50 -8
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +5 -1
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/core/viewport-state.mjs +24 -0
- package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +195 -73
- package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
- package/build-module/private-apis.mjs +2 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-style/style-rtl.css +254 -29
- package/build-style/style.css +254 -29
- package/build-types/components/media-editor/index.d.ts +34 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +10 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +2 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +1 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/index.d.ts +46 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +9 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +11 -7
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +25 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/core/viewport-state.d.ts +7 -0
- package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +2 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -3
- package/build-types/store/actions.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/components/media-editor/index.tsx +709 -0
- package/src/components/media-editor/style.scss +89 -0
- package/src/components/media-editor-canvas/index.tsx +24 -0
- package/src/components/media-editor-crop-panel/index.tsx +39 -27
- package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
- package/src/components/media-editor-modal/index.tsx +49 -589
- package/src/components/media-editor-modal/style.scss +13 -112
- package/src/components/media-editor-toolbar/index.tsx +122 -63
- package/src/components/media-editor-toolbar/style.scss +39 -11
- package/src/components/media-form/index.tsx +5 -0
- package/src/components/rotation-ruler/README.md +37 -0
- package/src/components/rotation-ruler/index.tsx +266 -0
- package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
- package/src/components/rotation-ruler/style.scss +147 -0
- package/src/components/rotation-ruler/test/index.tsx +109 -0
- package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
- package/src/hooks/use-crop-gesture-handlers.ts +54 -0
- package/src/image-editor/core/constants.ts +12 -0
- package/src/image-editor/core/containment.ts +16 -28
- package/src/image-editor/core/interaction-controller.ts +66 -10
- package/src/image-editor/core/state.ts +15 -8
- package/src/image-editor/core/test/camera.ts +15 -26
- package/src/image-editor/core/test/interaction-controller.ts +158 -7
- package/src/image-editor/core/test/state.ts +21 -1
- package/src/image-editor/core/transform-style.ts +1 -1
- package/src/image-editor/core/types.ts +16 -0
- package/src/image-editor/core/viewport-state.ts +33 -0
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.scss +28 -0
- package/src/image-editor/react/components/cropper.tsx +268 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
- package/src/image-editor/react/components/test/cropper.tsx +294 -5
- package/src/image-editor/react/components/viewport-provider.tsx +39 -0
- package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
- package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
- package/src/image-editor/react/hooks/use-interaction.ts +36 -6
- package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
- package/src/image-editor/react/visually-hidden-style.ts +15 -0
- package/src/private-apis.ts +2 -0
- package/src/style.scss +3 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -34,413 +34,12 @@ __export(media_editor_modal_exports, {
|
|
|
34
34
|
default: () => media_editor_modal_default
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(media_editor_modal_exports);
|
|
37
|
-
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
38
37
|
var import_components = require("@wordpress/components");
|
|
39
|
-
var import_ui = require("@wordpress/ui");
|
|
40
38
|
var import_data = require("@wordpress/data");
|
|
41
|
-
var import_core_data = require("@wordpress/core-data");
|
|
42
|
-
var import_element = require("@wordpress/element");
|
|
43
39
|
var import_i18n = require("@wordpress/i18n");
|
|
44
|
-
var
|
|
45
|
-
var import_notices = require("@wordpress/notices");
|
|
46
|
-
var import_interface = require("@wordpress/interface");
|
|
47
|
-
var import_media_editor_provider = require("../media-editor-provider/index.cjs");
|
|
48
|
-
var import_media_preview = __toESM(require("../media-preview/index.cjs"));
|
|
49
|
-
var import_media_editor_canvas = __toESM(require("../media-editor-canvas/index.cjs"));
|
|
50
|
-
var import_media_editor_toolbar = __toESM(require("../media-editor-toolbar/index.cjs"));
|
|
51
|
-
var import_media_editor_crop_panel = __toESM(require("../media-editor-crop-panel/index.cjs"));
|
|
52
|
-
var import_media_form = __toESM(require("../media-form/index.cjs"));
|
|
40
|
+
var import_media_editor = __toESM(require("../media-editor/index.cjs"));
|
|
53
41
|
var import_store = require("../../store/index.cjs");
|
|
54
|
-
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
55
|
-
var import_utils = require("../../utils/index.cjs");
|
|
56
|
-
var import_image_editor = require("../../image-editor/index.cjs");
|
|
57
|
-
var import_build_modifiers = require("./build-modifiers.cjs");
|
|
58
42
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
59
|
-
var METADATA_EDIT_KEYS = [
|
|
60
|
-
"title",
|
|
61
|
-
"caption",
|
|
62
|
-
"description",
|
|
63
|
-
"alt_text",
|
|
64
|
-
"post"
|
|
65
|
-
];
|
|
66
|
-
var NOTICES_CONTEXT = "media-editor";
|
|
67
|
-
var PLACEMENT_CONTROL_IDLE_MS = 300;
|
|
68
|
-
var { Tabs } = (0, import_lock_unlock.unlock)(import_components.privateApis);
|
|
69
|
-
function MediaEditorModalSidebar({ tabs }) {
|
|
70
|
-
const tabsContextValue = (0, import_element.useContext)(Tabs.Context);
|
|
71
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
|
-
import_interface.ComplementaryArea,
|
|
73
|
-
{
|
|
74
|
-
scope: "media-editor",
|
|
75
|
-
identifier: "media-editor/details",
|
|
76
|
-
title: (0, import_i18n.__)("Details"),
|
|
77
|
-
icon: import_icons.drawerRight,
|
|
78
|
-
isActiveByDefault: true,
|
|
79
|
-
className: "media-editor-modal__sidebar",
|
|
80
|
-
panelClassName: "media-editor-modal__sidebar-panel",
|
|
81
|
-
headerClassName: "media-editor-modal__sidebar-header",
|
|
82
|
-
header: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.Context.Provider, { value: tabsContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.TabList, { children: tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.Tab, { tabId: tab.id, children: tab.title }, tab.id)) }) }),
|
|
83
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.Context.Provider, { value: tabsContextValue, children: tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
84
|
-
Tabs.TabPanel,
|
|
85
|
-
{
|
|
86
|
-
tabId: tab.id,
|
|
87
|
-
focusable: false,
|
|
88
|
-
children: tab.panel
|
|
89
|
-
},
|
|
90
|
-
tab.id
|
|
91
|
-
)) })
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
function HeaderActions({
|
|
96
|
-
isSaving,
|
|
97
|
-
hasMedia,
|
|
98
|
-
hasChanges,
|
|
99
|
-
onCancel,
|
|
100
|
-
onSave
|
|
101
|
-
}) {
|
|
102
|
-
const saveDisabled = isSaving || !hasMedia || !hasChanges;
|
|
103
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
104
|
-
import_components.Flex,
|
|
105
|
-
{
|
|
106
|
-
className: "media-editor-modal__header-actions",
|
|
107
|
-
justify: "flex-end",
|
|
108
|
-
expanded: false,
|
|
109
|
-
gap: 2,
|
|
110
|
-
children: [
|
|
111
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_interface.PinnedItems.Slot, { scope: "media-editor" }),
|
|
112
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
113
|
-
import_components.Button,
|
|
114
|
-
{
|
|
115
|
-
size: "compact",
|
|
116
|
-
variant: "tertiary",
|
|
117
|
-
onClick: onCancel,
|
|
118
|
-
disabled: isSaving,
|
|
119
|
-
accessibleWhenDisabled: true,
|
|
120
|
-
children: (0, import_i18n.__)("Cancel")
|
|
121
|
-
}
|
|
122
|
-
),
|
|
123
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
-
import_components.Button,
|
|
125
|
-
{
|
|
126
|
-
size: "compact",
|
|
127
|
-
variant: "primary",
|
|
128
|
-
onClick: onSave,
|
|
129
|
-
isBusy: isSaving,
|
|
130
|
-
disabled: saveDisabled,
|
|
131
|
-
accessibleWhenDisabled: true,
|
|
132
|
-
children: (0, import_i18n.__)("Save")
|
|
133
|
-
}
|
|
134
|
-
),
|
|
135
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
-
import_components.Button,
|
|
137
|
-
{
|
|
138
|
-
size: "compact",
|
|
139
|
-
icon: import_icons.close,
|
|
140
|
-
label: (0, import_i18n.__)("Close"),
|
|
141
|
-
onClick: onCancel,
|
|
142
|
-
disabled: isSaving,
|
|
143
|
-
accessibleWhenDisabled: true
|
|
144
|
-
}
|
|
145
|
-
)
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
function MediaEditorModalContent({
|
|
151
|
-
fields,
|
|
152
|
-
id,
|
|
153
|
-
media,
|
|
154
|
-
hasEdits,
|
|
155
|
-
aspectRatioPresets,
|
|
156
|
-
onUpdate
|
|
157
|
-
}) {
|
|
158
|
-
const cropper = (0, import_image_editor.useCropper)();
|
|
159
|
-
const hasChanges = cropper.isDirty || hasEdits;
|
|
160
|
-
const registry = (0, import_data.useRegistry)();
|
|
161
|
-
const {
|
|
162
|
-
clearEntityRecordEdits,
|
|
163
|
-
editEntityRecord,
|
|
164
|
-
receiveEntityRecords,
|
|
165
|
-
saveEditedEntityRecord
|
|
166
|
-
} = (0, import_data.useDispatch)(import_core_data.store);
|
|
167
|
-
const { closeMediaEditorModal } = (0, import_data.useDispatch)(import_store.store);
|
|
168
|
-
const { createErrorNotice, removeAllNotices } = (0, import_data.useDispatch)(import_notices.store);
|
|
169
|
-
const [isSaving, setIsSaving] = (0, import_element.useState)(false);
|
|
170
|
-
const [isDiscardDialogOpen, setIsDiscardDialogOpen] = (0, import_element.useState)(false);
|
|
171
|
-
const [isPlacementActive, setIsPlacementActive] = (0, import_element.useState)(false);
|
|
172
|
-
const placementControlTimerRef = (0, import_element.useRef)();
|
|
173
|
-
const [aspectRatioValue, setAspectRatioValue] = (0, import_element.useState)("0");
|
|
174
|
-
const [freeformCrop, setFreeformCrop] = (0, import_element.useState)(true);
|
|
175
|
-
const signalPlacementControlInteraction = (0, import_element.useCallback)(() => {
|
|
176
|
-
setIsPlacementActive(true);
|
|
177
|
-
clearTimeout(placementControlTimerRef.current);
|
|
178
|
-
placementControlTimerRef.current = setTimeout(() => {
|
|
179
|
-
setIsPlacementActive(false);
|
|
180
|
-
}, PLACEMENT_CONTROL_IDLE_MS);
|
|
181
|
-
}, []);
|
|
182
|
-
(0, import_element.useEffect)(() => {
|
|
183
|
-
return () => {
|
|
184
|
-
clearTimeout(placementControlTimerRef.current);
|
|
185
|
-
};
|
|
186
|
-
}, []);
|
|
187
|
-
(0, import_element.useEffect)(() => {
|
|
188
|
-
setAspectRatioValue("0");
|
|
189
|
-
setFreeformCrop(true);
|
|
190
|
-
}, [id]);
|
|
191
|
-
const mediaType = (0, import_utils.getMediaTypeFromMimeType)(media?.mime_type).type;
|
|
192
|
-
const isImage = !!media && mediaType === "image";
|
|
193
|
-
const imageAspectRatio = (0, import_element.useMemo)(() => {
|
|
194
|
-
if (!isImage) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
const naturalWidth = Number(media?.media_details?.width);
|
|
198
|
-
const naturalHeight = Number(media?.media_details?.height);
|
|
199
|
-
if (Number.isFinite(naturalWidth) && Number.isFinite(naturalHeight) && naturalHeight > 0) {
|
|
200
|
-
return naturalWidth / naturalHeight;
|
|
201
|
-
}
|
|
202
|
-
return null;
|
|
203
|
-
}, [isImage, media]);
|
|
204
|
-
const tabs = (0, import_element.useMemo)(() => {
|
|
205
|
-
const detailsTab = {
|
|
206
|
-
id: "details",
|
|
207
|
-
title: (0, import_i18n.__)("Details"),
|
|
208
|
-
panel: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
209
|
-
import_ui.Stack,
|
|
210
|
-
{
|
|
211
|
-
className: "media-editor-modal__panel",
|
|
212
|
-
direction: "column",
|
|
213
|
-
gap: "lg",
|
|
214
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_form.default, {})
|
|
215
|
-
}
|
|
216
|
-
)
|
|
217
|
-
};
|
|
218
|
-
if (!isImage) {
|
|
219
|
-
return [detailsTab];
|
|
220
|
-
}
|
|
221
|
-
return [
|
|
222
|
-
{
|
|
223
|
-
id: "crop",
|
|
224
|
-
title: (0, import_i18n.__)("Crop"),
|
|
225
|
-
panel: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
226
|
-
import_ui.Stack,
|
|
227
|
-
{
|
|
228
|
-
className: "media-editor-modal__panel",
|
|
229
|
-
direction: "column",
|
|
230
|
-
gap: "lg",
|
|
231
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
232
|
-
import_media_editor_crop_panel.default,
|
|
233
|
-
{
|
|
234
|
-
aspectRatioValue,
|
|
235
|
-
onAspectRatioChange: setAspectRatioValue,
|
|
236
|
-
freeformCrop,
|
|
237
|
-
onFreeformChange: setFreeformCrop,
|
|
238
|
-
onPlacementControlInteraction: signalPlacementControlInteraction,
|
|
239
|
-
aspectRatioPresets
|
|
240
|
-
}
|
|
241
|
-
)
|
|
242
|
-
}
|
|
243
|
-
)
|
|
244
|
-
},
|
|
245
|
-
detailsTab
|
|
246
|
-
];
|
|
247
|
-
}, [
|
|
248
|
-
isImage,
|
|
249
|
-
aspectRatioValue,
|
|
250
|
-
freeformCrop,
|
|
251
|
-
aspectRatioPresets,
|
|
252
|
-
signalPlacementControlInteraction
|
|
253
|
-
]);
|
|
254
|
-
const handleChange = (updates) => {
|
|
255
|
-
editEntityRecord("postType", "attachment", id, updates);
|
|
256
|
-
};
|
|
257
|
-
const discardAndClose = () => {
|
|
258
|
-
removeAllNotices("snackbar", NOTICES_CONTEXT);
|
|
259
|
-
clearEntityRecordEdits("postType", "attachment", id);
|
|
260
|
-
closeMediaEditorModal();
|
|
261
|
-
};
|
|
262
|
-
const handleRequestClose = () => {
|
|
263
|
-
if (isSaving) {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
if (hasChanges) {
|
|
267
|
-
setIsDiscardDialogOpen(true);
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
discardAndClose();
|
|
271
|
-
};
|
|
272
|
-
const handleSave = async () => {
|
|
273
|
-
removeAllNotices("snackbar", NOTICES_CONTEXT);
|
|
274
|
-
setIsSaving(true);
|
|
275
|
-
try {
|
|
276
|
-
let saved;
|
|
277
|
-
const modifiers = cropper.isDirty && cropper.state.image ? (0, import_build_modifiers.buildModifiers)(cropper.state, {
|
|
278
|
-
width: cropper.state.image.naturalWidth,
|
|
279
|
-
height: cropper.state.image.naturalHeight
|
|
280
|
-
}) : [];
|
|
281
|
-
if (modifiers.length > 0) {
|
|
282
|
-
const pendingEdits = registry.select(import_core_data.store).getEntityRecordNonTransientEdits(
|
|
283
|
-
"postType",
|
|
284
|
-
"attachment",
|
|
285
|
-
id
|
|
286
|
-
);
|
|
287
|
-
const metadataEdits = {};
|
|
288
|
-
for (const key of METADATA_EDIT_KEYS) {
|
|
289
|
-
if (pendingEdits && key in pendingEdits) {
|
|
290
|
-
metadataEdits[key] = pendingEdits[key];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
saved = await (0, import_api_fetch.default)({
|
|
294
|
-
path: `/wp/v2/media/${id}/edit`,
|
|
295
|
-
method: "POST",
|
|
296
|
-
data: {
|
|
297
|
-
src: media?.source_url,
|
|
298
|
-
modifiers,
|
|
299
|
-
...metadataEdits
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
if (saved) {
|
|
303
|
-
receiveEntityRecords(
|
|
304
|
-
"postType",
|
|
305
|
-
"attachment",
|
|
306
|
-
saved,
|
|
307
|
-
void 0,
|
|
308
|
-
true
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
saved = await saveEditedEntityRecord(
|
|
313
|
-
"postType",
|
|
314
|
-
"attachment",
|
|
315
|
-
id
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
const next = saved ?? media;
|
|
319
|
-
if (next && next.id !== id) {
|
|
320
|
-
clearEntityRecordEdits("postType", "attachment", id);
|
|
321
|
-
}
|
|
322
|
-
if (next && next.id && onUpdate) {
|
|
323
|
-
onUpdate({ id: next.id, url: next.source_url });
|
|
324
|
-
}
|
|
325
|
-
closeMediaEditorModal();
|
|
326
|
-
} catch (error) {
|
|
327
|
-
const message = error instanceof Error ? error.message : error?.message ?? (0, import_i18n.__)("An unknown error occurred.");
|
|
328
|
-
createErrorNotice(
|
|
329
|
-
(0, import_i18n.sprintf)(
|
|
330
|
-
/* translators: %s: Error message. */
|
|
331
|
-
(0, import_i18n.__)("Could not save image. %s"),
|
|
332
|
-
message
|
|
333
|
-
),
|
|
334
|
-
{ type: "snackbar", context: NOTICES_CONTEXT }
|
|
335
|
-
);
|
|
336
|
-
} finally {
|
|
337
|
-
setIsSaving(false);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
341
|
-
import_components.Modal,
|
|
342
|
-
{
|
|
343
|
-
className: "media-editor-modal",
|
|
344
|
-
title: (0, import_i18n.__)("Edit media"),
|
|
345
|
-
size: "fill",
|
|
346
|
-
isDismissible: false,
|
|
347
|
-
shouldCloseOnClickOutside: !hasChanges && !isSaving,
|
|
348
|
-
onKeyDown: (event) => {
|
|
349
|
-
if (event.code !== "Escape" && event.key !== "Escape") {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
if (isSaving) {
|
|
353
|
-
event.preventDefault();
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
if (hasChanges) {
|
|
357
|
-
event.preventDefault();
|
|
358
|
-
setIsDiscardDialogOpen(true);
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
onRequestClose: handleRequestClose,
|
|
362
|
-
headerActions: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
363
|
-
HeaderActions,
|
|
364
|
-
{
|
|
365
|
-
isSaving,
|
|
366
|
-
hasMedia: !!media,
|
|
367
|
-
hasChanges,
|
|
368
|
-
onCancel: handleRequestClose,
|
|
369
|
-
onSave: handleSave
|
|
370
|
-
}
|
|
371
|
-
),
|
|
372
|
-
children: [
|
|
373
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
374
|
-
import_media_editor_provider.MediaEditorProvider,
|
|
375
|
-
{
|
|
376
|
-
value: media ?? void 0,
|
|
377
|
-
onChange: handleChange,
|
|
378
|
-
settings: { fields },
|
|
379
|
-
children: [
|
|
380
|
-
!media ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-modal__loading", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
381
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorModalSidebar, { tabs }) }),
|
|
382
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
383
|
-
import_interface.InterfaceSkeleton,
|
|
384
|
-
{
|
|
385
|
-
className: "media-editor-modal__skeleton",
|
|
386
|
-
content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-modal__canvas", children: isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
387
|
-
import_media_editor_canvas.default,
|
|
388
|
-
{
|
|
389
|
-
aspectRatio: (0, import_media_editor_crop_panel.resolveAspectRatio)(
|
|
390
|
-
aspectRatioValue,
|
|
391
|
-
imageAspectRatio
|
|
392
|
-
),
|
|
393
|
-
freeformCrop,
|
|
394
|
-
isPlacementActive
|
|
395
|
-
}
|
|
396
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_preview.default, {}) }),
|
|
397
|
-
footer: isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
398
|
-
import_media_editor_toolbar.default,
|
|
399
|
-
{
|
|
400
|
-
onReset: () => {
|
|
401
|
-
setAspectRatioValue("0");
|
|
402
|
-
setFreeformCrop(true);
|
|
403
|
-
},
|
|
404
|
-
onPlacementControlInteraction: signalPlacementControlInteraction
|
|
405
|
-
}
|
|
406
|
-
) : void 0,
|
|
407
|
-
sidebar: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_interface.ComplementaryArea.Slot, { scope: "media-editor" })
|
|
408
|
-
}
|
|
409
|
-
)
|
|
410
|
-
] }),
|
|
411
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
412
|
-
import_components.__experimentalConfirmDialog,
|
|
413
|
-
{
|
|
414
|
-
isOpen: isDiscardDialogOpen,
|
|
415
|
-
confirmButtonText: (0, import_i18n.__)("Discard"),
|
|
416
|
-
cancelButtonText: (0, import_i18n.__)("Keep editing"),
|
|
417
|
-
onCancel: () => setIsDiscardDialogOpen(false),
|
|
418
|
-
onConfirm: () => {
|
|
419
|
-
setIsDiscardDialogOpen(false);
|
|
420
|
-
discardAndClose();
|
|
421
|
-
},
|
|
422
|
-
children: (0, import_i18n.__)(
|
|
423
|
-
"Are you sure you want to discard your unsaved changes?"
|
|
424
|
-
)
|
|
425
|
-
}
|
|
426
|
-
)
|
|
427
|
-
]
|
|
428
|
-
}
|
|
429
|
-
),
|
|
430
|
-
(0, import_element.createPortal)(
|
|
431
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
432
|
-
import_notices.SnackbarNotices,
|
|
433
|
-
{
|
|
434
|
-
className: "media-editor-modal__snackbar",
|
|
435
|
-
context: NOTICES_CONTEXT
|
|
436
|
-
}
|
|
437
|
-
),
|
|
438
|
-
document.body
|
|
439
|
-
)
|
|
440
|
-
]
|
|
441
|
-
}
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
43
|
function MediaEditorModal({
|
|
445
44
|
fields = [],
|
|
446
45
|
aspectRatioPresets
|
|
@@ -453,41 +52,54 @@ function MediaEditorModal({
|
|
|
453
52
|
onUpdate: getOnUpdate()
|
|
454
53
|
};
|
|
455
54
|
}, []);
|
|
456
|
-
const {
|
|
457
|
-
(select) => {
|
|
458
|
-
if (!id) {
|
|
459
|
-
return { media: null, hasEdits: false };
|
|
460
|
-
}
|
|
461
|
-
const { getEditedEntityRecord, hasEditsForEntityRecord } = select(import_core_data.store);
|
|
462
|
-
return {
|
|
463
|
-
media: getEditedEntityRecord(
|
|
464
|
-
"postType",
|
|
465
|
-
"attachment",
|
|
466
|
-
id
|
|
467
|
-
),
|
|
468
|
-
hasEdits: hasEditsForEntityRecord(
|
|
469
|
-
"postType",
|
|
470
|
-
"attachment",
|
|
471
|
-
id
|
|
472
|
-
)
|
|
473
|
-
};
|
|
474
|
-
},
|
|
475
|
-
[id]
|
|
476
|
-
);
|
|
55
|
+
const { closeMediaEditorModal } = (0, import_data.useDispatch)(import_store.store);
|
|
477
56
|
if (!isModalOpen || !id) {
|
|
478
57
|
return null;
|
|
479
58
|
}
|
|
480
|
-
|
|
481
|
-
|
|
59
|
+
const portalElement = typeof document === "undefined" ? null : document.body;
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
import_media_editor.default,
|
|
482
62
|
{
|
|
483
|
-
fields,
|
|
484
63
|
id,
|
|
485
|
-
|
|
486
|
-
hasEdits,
|
|
64
|
+
fields,
|
|
487
65
|
aspectRatioPresets,
|
|
488
|
-
|
|
66
|
+
showCloseButton: true,
|
|
67
|
+
shouldCloseOnEsc: true,
|
|
68
|
+
noticesClassName: "media-editor-modal__snackbar",
|
|
69
|
+
noticesPortalElement: portalElement,
|
|
70
|
+
onClose: closeMediaEditorModal,
|
|
71
|
+
onSaved: ({ id: savedId, url }) => {
|
|
72
|
+
if (savedId && onUpdate) {
|
|
73
|
+
const update = {
|
|
74
|
+
id: savedId,
|
|
75
|
+
url
|
|
76
|
+
};
|
|
77
|
+
onUpdate(update);
|
|
78
|
+
}
|
|
79
|
+
closeMediaEditorModal();
|
|
80
|
+
},
|
|
81
|
+
renderFrame: ({
|
|
82
|
+
children,
|
|
83
|
+
headerActions,
|
|
84
|
+
onRequestClose,
|
|
85
|
+
onKeyDown,
|
|
86
|
+
shouldCloseOnClickOutside
|
|
87
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
88
|
+
import_components.Modal,
|
|
89
|
+
{
|
|
90
|
+
className: "media-editor-modal",
|
|
91
|
+
title: (0, import_i18n.__)("Edit media"),
|
|
92
|
+
size: "fill",
|
|
93
|
+
isDismissible: false,
|
|
94
|
+
shouldCloseOnClickOutside,
|
|
95
|
+
onKeyDown,
|
|
96
|
+
onRequestClose,
|
|
97
|
+
headerActions,
|
|
98
|
+
children
|
|
99
|
+
}
|
|
100
|
+
)
|
|
489
101
|
}
|
|
490
|
-
)
|
|
102
|
+
);
|
|
491
103
|
}
|
|
492
104
|
var media_editor_modal_default = MediaEditorModal;
|
|
493
105
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": ["
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAsB;AACtB,kBAAuC;AACvC,kBAAmB;AAMnB,0BAAwB;AAExB,mBAA0C;AAoEtC;AAjDG,SAAS,iBAAkB;AAAA,EACjC,SAAS,CAAC;AAAA,EACV;AACD,GAA2B;AAC1B,QAAM,EAAE,aAAa,IAAI,SAAS,QAAI,uBAAW,CAAE,WAAY;AAC9D,UAAM,EAAE,QAAQ,OAAO,YAAY,IAAI,OAAQ,aAAAA,KAAiB;AAChE,WAAO;AAAA,MACN,aAAa,OAAO;AAAA,MACpB,IAAI,MAAM;AAAA,MACV,UAAU,YAAY;AAAA,IACvB;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,EAAE,sBAAsB,QAAI,yBAAa,aAAAA,KAAiB;AAEhE,MAAK,CAAE,eAAe,CAAE,IAAK;AAC5B,WAAO;AAAA,EACR;AAEA,QAAM,gBACL,OAAO,aAAa,cAAc,OAAO,SAAS;AAEnD,SACC;AAAA,IAAC,oBAAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAe;AAAA,MACf,kBAAgB;AAAA,MAChB,kBAAiB;AAAA,MACjB,sBAAuB;AAAA,MACvB,SAAU;AAAA,MACV,SAAU,CAAE,EAAE,IAAI,SAAS,IAAI,MAAO;AACrC,YAAK,WAAW,UAAW;AAC1B,gBAAM,SAAiC;AAAA,YACtC,IAAI;AAAA,YACJ;AAAA,UACD;AACA,mBAAU,MAAO;AAAA,QAClB;AACA,8BAAsB;AAAA,MACvB;AAAA,MACA,aAAc,CAAE;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD,MACC;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV,WAAQ,gBAAI,YAAa;AAAA,UACzB,MAAK;AAAA,UACL,eAAgB;AAAA,UAChB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAEE;AAAA;AAAA,MACH;AAAA;AAAA,EAEF;AAEF;AAEA,IAAO,6BAAQ;",
|
|
6
|
+
"names": ["mediaEditorStore", "MediaEditor"]
|
|
7
7
|
}
|