@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
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/media-editor/src/components/media-editor/index.tsx
|
|
31
|
+
var media_editor_exports = {};
|
|
32
|
+
__export(media_editor_exports, {
|
|
33
|
+
MediaEditor: () => MediaEditor,
|
|
34
|
+
default: () => media_editor_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(media_editor_exports);
|
|
37
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
38
|
+
var import_components = require("@wordpress/components");
|
|
39
|
+
var import_ui = require("@wordpress/ui");
|
|
40
|
+
var import_data = require("@wordpress/data");
|
|
41
|
+
var import_core_data = require("@wordpress/core-data");
|
|
42
|
+
var import_element = require("@wordpress/element");
|
|
43
|
+
var import_i18n = require("@wordpress/i18n");
|
|
44
|
+
var import_icons = require("@wordpress/icons");
|
|
45
|
+
var import_keycodes = require("@wordpress/keycodes");
|
|
46
|
+
var import_notices = require("@wordpress/notices");
|
|
47
|
+
var import_interface = require("@wordpress/interface");
|
|
48
|
+
var import_media_editor_provider = require("../media-editor-provider/index.cjs");
|
|
49
|
+
var import_media_preview = __toESM(require("../media-preview/index.cjs"));
|
|
50
|
+
var import_media_editor_canvas = __toESM(require("../media-editor-canvas/index.cjs"));
|
|
51
|
+
var import_media_editor_toolbar = __toESM(require("../media-editor-toolbar/index.cjs"));
|
|
52
|
+
var import_media_editor_crop_panel = __toESM(require("../media-editor-crop-panel/index.cjs"));
|
|
53
|
+
var import_media_form = __toESM(require("../media-form/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_use_crop_gesture_handlers = require("../../hooks/use-crop-gesture-handlers.cjs");
|
|
58
|
+
var import_build_modifiers = require("../media-editor-modal/build-modifiers.cjs");
|
|
59
|
+
var import_media_editor_keyboard_shortcuts_modal = __toESM(require("../media-editor-keyboard-shortcuts-modal/index.cjs"));
|
|
60
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
61
|
+
var METADATA_EDIT_KEYS = [
|
|
62
|
+
"title",
|
|
63
|
+
"caption",
|
|
64
|
+
"description",
|
|
65
|
+
"alt_text",
|
|
66
|
+
"post"
|
|
67
|
+
];
|
|
68
|
+
var ATTACHMENT_EMBED_QUERY = { _embed: "author,wp:attached-to" };
|
|
69
|
+
var NOTICES_CONTEXT = "media-editor";
|
|
70
|
+
var PLACEMENT_CONTROL_IDLE_MS = 300;
|
|
71
|
+
var { Tabs } = (0, import_lock_unlock.unlock)(import_components.privateApis);
|
|
72
|
+
function MediaEditorSidebar({ tabs }) {
|
|
73
|
+
const tabsContextValue = (0, import_element.useContext)(Tabs.Context);
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
75
|
+
import_interface.ComplementaryArea,
|
|
76
|
+
{
|
|
77
|
+
scope: "media-editor",
|
|
78
|
+
identifier: "media-editor/details",
|
|
79
|
+
title: (0, import_i18n.__)("Details"),
|
|
80
|
+
icon: import_icons.drawerRight,
|
|
81
|
+
isActiveByDefault: true,
|
|
82
|
+
className: "media-editor__sidebar",
|
|
83
|
+
panelClassName: "media-editor__sidebar-panel",
|
|
84
|
+
headerClassName: "media-editor__sidebar-header",
|
|
85
|
+
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)) }) }),
|
|
86
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.Context.Provider, { value: tabsContextValue, children: tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
87
|
+
Tabs.TabPanel,
|
|
88
|
+
{
|
|
89
|
+
tabId: tab.id,
|
|
90
|
+
focusable: false,
|
|
91
|
+
children: tab.panel
|
|
92
|
+
},
|
|
93
|
+
tab.id
|
|
94
|
+
)) })
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
function HeaderActions({
|
|
99
|
+
isSaving,
|
|
100
|
+
hasMedia,
|
|
101
|
+
hasChanges,
|
|
102
|
+
isImage,
|
|
103
|
+
showCloseButton = false,
|
|
104
|
+
onCancel,
|
|
105
|
+
onSave
|
|
106
|
+
}) {
|
|
107
|
+
const saveDisabled = isSaving || !hasMedia || !hasChanges;
|
|
108
|
+
const [isShortcutsModalOpen, setIsShortcutsModalOpen] = (0, import_element.useState)(false);
|
|
109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
110
|
+
import_components.Flex,
|
|
111
|
+
{
|
|
112
|
+
className: "media-editor__header-actions",
|
|
113
|
+
justify: "flex-end",
|
|
114
|
+
expanded: false,
|
|
115
|
+
gap: 2,
|
|
116
|
+
children: [
|
|
117
|
+
isImage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
118
|
+
import_components.Button,
|
|
119
|
+
{
|
|
120
|
+
size: "compact",
|
|
121
|
+
icon: import_icons.keyboard,
|
|
122
|
+
label: (0, import_i18n.__)("Keyboard shortcuts"),
|
|
123
|
+
onClick: () => setIsShortcutsModalOpen(true)
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_interface.PinnedItems.Slot, { scope: "media-editor" }),
|
|
127
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
128
|
+
import_components.Button,
|
|
129
|
+
{
|
|
130
|
+
size: "compact",
|
|
131
|
+
variant: "tertiary",
|
|
132
|
+
onClick: onCancel,
|
|
133
|
+
disabled: isSaving,
|
|
134
|
+
accessibleWhenDisabled: true,
|
|
135
|
+
children: (0, import_i18n.__)("Cancel")
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
139
|
+
import_components.Button,
|
|
140
|
+
{
|
|
141
|
+
size: "compact",
|
|
142
|
+
variant: "primary",
|
|
143
|
+
onClick: onSave,
|
|
144
|
+
isBusy: isSaving,
|
|
145
|
+
disabled: saveDisabled,
|
|
146
|
+
accessibleWhenDisabled: true,
|
|
147
|
+
children: (0, import_i18n.__)("Save")
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
151
|
+
import_components.Button,
|
|
152
|
+
{
|
|
153
|
+
size: "compact",
|
|
154
|
+
icon: import_icons.close,
|
|
155
|
+
label: (0, import_i18n.__)("Close"),
|
|
156
|
+
onClick: onCancel,
|
|
157
|
+
disabled: isSaving,
|
|
158
|
+
accessibleWhenDisabled: true
|
|
159
|
+
}
|
|
160
|
+
),
|
|
161
|
+
isShortcutsModalOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
162
|
+
import_media_editor_keyboard_shortcuts_modal.default,
|
|
163
|
+
{
|
|
164
|
+
onClose: () => setIsShortcutsModalOpen(false)
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
function MediaEditorContent({
|
|
172
|
+
fields = [],
|
|
173
|
+
id,
|
|
174
|
+
aspectRatioPresets,
|
|
175
|
+
onClose,
|
|
176
|
+
onSaved,
|
|
177
|
+
renderFrame,
|
|
178
|
+
noticesClassName = "media-editor__snackbar",
|
|
179
|
+
noticesPortalElement,
|
|
180
|
+
showCloseButton = false,
|
|
181
|
+
shouldCloseOnEsc = false
|
|
182
|
+
}) {
|
|
183
|
+
const cropper = (0, import_image_editor.useCropper)();
|
|
184
|
+
const { media, hasEdits } = (0, import_data.useSelect)(
|
|
185
|
+
(select) => {
|
|
186
|
+
const {
|
|
187
|
+
getEditedEntityRecord,
|
|
188
|
+
getEntityRecord,
|
|
189
|
+
hasEditsForEntityRecord
|
|
190
|
+
} = select(import_core_data.store);
|
|
191
|
+
getEntityRecord(
|
|
192
|
+
"postType",
|
|
193
|
+
"attachment",
|
|
194
|
+
id,
|
|
195
|
+
ATTACHMENT_EMBED_QUERY
|
|
196
|
+
);
|
|
197
|
+
return {
|
|
198
|
+
media: getEditedEntityRecord(
|
|
199
|
+
"postType",
|
|
200
|
+
"attachment",
|
|
201
|
+
id
|
|
202
|
+
),
|
|
203
|
+
hasEdits: hasEditsForEntityRecord(
|
|
204
|
+
"postType",
|
|
205
|
+
"attachment",
|
|
206
|
+
id
|
|
207
|
+
)
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
[id]
|
|
211
|
+
);
|
|
212
|
+
const hasChanges = cropper.isDirty || hasEdits;
|
|
213
|
+
const registry = (0, import_data.useRegistry)();
|
|
214
|
+
const {
|
|
215
|
+
clearEntityRecordEdits,
|
|
216
|
+
editEntityRecord,
|
|
217
|
+
invalidateResolution,
|
|
218
|
+
receiveEntityRecords,
|
|
219
|
+
saveEditedEntityRecord
|
|
220
|
+
} = (0, import_data.useDispatch)(import_core_data.store);
|
|
221
|
+
const { createErrorNotice, removeAllNotices } = (0, import_data.useDispatch)(import_notices.store);
|
|
222
|
+
const [isSaving, setIsSaving] = (0, import_element.useState)(false);
|
|
223
|
+
const [isDiscardDialogOpen, setIsDiscardDialogOpen] = (0, import_element.useState)(false);
|
|
224
|
+
const [isPlacementActive, setIsPlacementActive] = (0, import_element.useState)(false);
|
|
225
|
+
const [isCanvasGestureActive, setIsCanvasGestureActive] = (0, import_element.useState)(false);
|
|
226
|
+
const placementControlTimerRef = (0, import_element.useRef)();
|
|
227
|
+
const [aspectRatioValue, setAspectRatioValue] = (0, import_element.useState)("0");
|
|
228
|
+
const [freeformCrop, setFreeformCrop] = (0, import_element.useState)(true);
|
|
229
|
+
const signalPlacementControlInteraction = (0, import_element.useCallback)(() => {
|
|
230
|
+
setIsPlacementActive(true);
|
|
231
|
+
clearTimeout(placementControlTimerRef.current);
|
|
232
|
+
placementControlTimerRef.current = setTimeout(() => {
|
|
233
|
+
setIsPlacementActive(false);
|
|
234
|
+
}, PLACEMENT_CONTROL_IDLE_MS);
|
|
235
|
+
}, []);
|
|
236
|
+
const handleCanvasGestureStart = (0, import_element.useCallback)(() => {
|
|
237
|
+
setIsCanvasGestureActive(true);
|
|
238
|
+
}, []);
|
|
239
|
+
const handleCanvasGestureEnd = (0, import_element.useCallback)(() => {
|
|
240
|
+
setIsCanvasGestureActive(false);
|
|
241
|
+
}, []);
|
|
242
|
+
const isCropInteractionActive = isPlacementActive || isCanvasGestureActive;
|
|
243
|
+
(0, import_element.useEffect)(() => {
|
|
244
|
+
return () => {
|
|
245
|
+
clearTimeout(placementControlTimerRef.current);
|
|
246
|
+
};
|
|
247
|
+
}, []);
|
|
248
|
+
(0, import_element.useEffect)(() => {
|
|
249
|
+
setAspectRatioValue("0");
|
|
250
|
+
setFreeformCrop(true);
|
|
251
|
+
setIsPlacementActive(false);
|
|
252
|
+
setIsCanvasGestureActive(false);
|
|
253
|
+
}, [id]);
|
|
254
|
+
(0, import_element.useEffect)(() => {
|
|
255
|
+
invalidateResolution("getEntityRecord", [
|
|
256
|
+
"postType",
|
|
257
|
+
"attachment",
|
|
258
|
+
id,
|
|
259
|
+
ATTACHMENT_EMBED_QUERY
|
|
260
|
+
]);
|
|
261
|
+
}, [id, invalidateResolution]);
|
|
262
|
+
const mediaType = (0, import_utils.getMediaTypeFromMimeType)(media?.mime_type).type;
|
|
263
|
+
const isImage = !!media && mediaType === "image";
|
|
264
|
+
const imageAspectRatio = (0, import_element.useMemo)(() => {
|
|
265
|
+
if (!isImage) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
const naturalWidth = Number(media?.media_details?.width);
|
|
269
|
+
const naturalHeight = Number(media?.media_details?.height);
|
|
270
|
+
if (Number.isFinite(naturalWidth) && Number.isFinite(naturalHeight) && naturalHeight > 0) {
|
|
271
|
+
return naturalWidth / naturalHeight;
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
274
|
+
}, [isImage, media]);
|
|
275
|
+
const tabs = (0, import_element.useMemo)(() => {
|
|
276
|
+
const detailsTab = {
|
|
277
|
+
id: "details",
|
|
278
|
+
title: (0, import_i18n.__)("Details"),
|
|
279
|
+
panel: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
280
|
+
import_ui.Stack,
|
|
281
|
+
{
|
|
282
|
+
className: "media-editor__panel",
|
|
283
|
+
direction: "column",
|
|
284
|
+
gap: "lg",
|
|
285
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_form.default, {})
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
};
|
|
289
|
+
if (!isImage) {
|
|
290
|
+
return [detailsTab];
|
|
291
|
+
}
|
|
292
|
+
return [
|
|
293
|
+
{
|
|
294
|
+
id: "crop",
|
|
295
|
+
title: (0, import_i18n.__)("Crop"),
|
|
296
|
+
panel: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
297
|
+
import_ui.Stack,
|
|
298
|
+
{
|
|
299
|
+
className: "media-editor__panel",
|
|
300
|
+
direction: "column",
|
|
301
|
+
gap: "lg",
|
|
302
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
303
|
+
import_media_editor_crop_panel.default,
|
|
304
|
+
{
|
|
305
|
+
aspectRatioValue,
|
|
306
|
+
onAspectRatioChange: setAspectRatioValue,
|
|
307
|
+
freeformCrop,
|
|
308
|
+
onFreeformChange: setFreeformCrop,
|
|
309
|
+
onPlacementControlInteraction: signalPlacementControlInteraction,
|
|
310
|
+
aspectRatioPresets
|
|
311
|
+
}
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
},
|
|
316
|
+
detailsTab
|
|
317
|
+
];
|
|
318
|
+
}, [
|
|
319
|
+
isImage,
|
|
320
|
+
aspectRatioValue,
|
|
321
|
+
freeformCrop,
|
|
322
|
+
aspectRatioPresets,
|
|
323
|
+
signalPlacementControlInteraction
|
|
324
|
+
]);
|
|
325
|
+
const handleChange = (updates) => {
|
|
326
|
+
editEntityRecord("postType", "attachment", id, updates);
|
|
327
|
+
};
|
|
328
|
+
const discardAndClose = () => {
|
|
329
|
+
removeAllNotices("snackbar", NOTICES_CONTEXT);
|
|
330
|
+
clearEntityRecordEdits("postType", "attachment", id);
|
|
331
|
+
onClose?.();
|
|
332
|
+
};
|
|
333
|
+
const handleRequestClose = () => {
|
|
334
|
+
if (isSaving) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (hasChanges) {
|
|
338
|
+
setIsDiscardDialogOpen(true);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
discardAndClose();
|
|
342
|
+
};
|
|
343
|
+
const handleSave = async () => {
|
|
344
|
+
removeAllNotices("snackbar", NOTICES_CONTEXT);
|
|
345
|
+
setIsSaving(true);
|
|
346
|
+
try {
|
|
347
|
+
let saved;
|
|
348
|
+
const modifiers = cropper.isDirty && cropper.state.image ? (0, import_build_modifiers.buildModifiers)(cropper.state, {
|
|
349
|
+
width: cropper.state.image.naturalWidth,
|
|
350
|
+
height: cropper.state.image.naturalHeight
|
|
351
|
+
}) : [];
|
|
352
|
+
if (modifiers.length > 0) {
|
|
353
|
+
const pendingEdits = registry.select(import_core_data.store).getEntityRecordNonTransientEdits(
|
|
354
|
+
"postType",
|
|
355
|
+
"attachment",
|
|
356
|
+
id
|
|
357
|
+
);
|
|
358
|
+
const metadataEdits = {};
|
|
359
|
+
for (const key of METADATA_EDIT_KEYS) {
|
|
360
|
+
if (pendingEdits && key in pendingEdits) {
|
|
361
|
+
metadataEdits[key] = pendingEdits[key];
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (!("post" in metadataEdits) && media?.post !== void 0) {
|
|
365
|
+
metadataEdits.post = media.post;
|
|
366
|
+
}
|
|
367
|
+
saved = await (0, import_api_fetch.default)({
|
|
368
|
+
path: `/wp/v2/media/${id}/edit`,
|
|
369
|
+
method: "POST",
|
|
370
|
+
data: {
|
|
371
|
+
src: media?.source_url,
|
|
372
|
+
modifiers,
|
|
373
|
+
...metadataEdits
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
if (saved) {
|
|
377
|
+
receiveEntityRecords(
|
|
378
|
+
"postType",
|
|
379
|
+
"attachment",
|
|
380
|
+
saved,
|
|
381
|
+
void 0,
|
|
382
|
+
true
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
saved = await saveEditedEntityRecord(
|
|
387
|
+
"postType",
|
|
388
|
+
"attachment",
|
|
389
|
+
id
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
const next = saved ?? media;
|
|
393
|
+
if (next && next.id !== id) {
|
|
394
|
+
clearEntityRecordEdits("postType", "attachment", id);
|
|
395
|
+
}
|
|
396
|
+
if (next && next.id) {
|
|
397
|
+
if (next.id === id) {
|
|
398
|
+
cropper.reset();
|
|
399
|
+
}
|
|
400
|
+
onSaved?.({
|
|
401
|
+
id: next.id,
|
|
402
|
+
url: next.source_url,
|
|
403
|
+
media: next
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
} catch (error) {
|
|
407
|
+
const message = error instanceof Error ? error.message : error?.message ?? (0, import_i18n.__)("An unknown error occurred.");
|
|
408
|
+
createErrorNotice(
|
|
409
|
+
isImage ? (0, import_i18n.sprintf)(
|
|
410
|
+
/* translators: %s: Error message. */
|
|
411
|
+
(0, import_i18n.__)("Could not save image. %s"),
|
|
412
|
+
message
|
|
413
|
+
) : (0, import_i18n.sprintf)(
|
|
414
|
+
/* translators: %s: Error message. */
|
|
415
|
+
(0, import_i18n.__)("Could not save media. %s"),
|
|
416
|
+
message
|
|
417
|
+
),
|
|
418
|
+
{ type: "snackbar", context: NOTICES_CONTEXT }
|
|
419
|
+
);
|
|
420
|
+
} finally {
|
|
421
|
+
setIsSaving(false);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const handleKeyDown = (event) => {
|
|
425
|
+
const isUndoShortcut = import_keycodes.isKeyboardEvent.primary(event, "z");
|
|
426
|
+
const isRedoShortcut = import_keycodes.isKeyboardEvent.primaryShift(event, "z") || !(0, import_keycodes.isAppleOS)() && import_keycodes.isKeyboardEvent.primary(event, "y");
|
|
427
|
+
if ((isUndoShortcut || isRedoShortcut) && isImage) {
|
|
428
|
+
const target = event.target;
|
|
429
|
+
const isMetadataField = (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) && !target.closest(`[${import_use_crop_gesture_handlers.CROP_CONTROL_ATTR}]`);
|
|
430
|
+
if (!isMetadataField) {
|
|
431
|
+
event.preventDefault();
|
|
432
|
+
if (isCropInteractionActive) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (isRedoShortcut) {
|
|
436
|
+
cropper.redo();
|
|
437
|
+
} else {
|
|
438
|
+
cropper.undo();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (shouldCloseOnEsc) {
|
|
443
|
+
if (event.code !== "Escape" && event.key !== "Escape") {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (isSaving) {
|
|
447
|
+
event.preventDefault();
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (hasChanges) {
|
|
451
|
+
event.preventDefault();
|
|
452
|
+
setIsDiscardDialogOpen(true);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const snackbar = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
457
|
+
import_notices.SnackbarNotices,
|
|
458
|
+
{
|
|
459
|
+
className: noticesClassName,
|
|
460
|
+
context: NOTICES_CONTEXT
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
const children = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
464
|
+
import_media_editor_provider.MediaEditorProvider,
|
|
465
|
+
{
|
|
466
|
+
value: media ?? void 0,
|
|
467
|
+
onChange: handleChange,
|
|
468
|
+
settings: { fields },
|
|
469
|
+
children: [
|
|
470
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor", children: !media ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor__loading", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
471
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorSidebar, { tabs }) }),
|
|
472
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
473
|
+
import_interface.InterfaceSkeleton,
|
|
474
|
+
{
|
|
475
|
+
className: "media-editor__skeleton",
|
|
476
|
+
labels: {
|
|
477
|
+
body: isImage ? (0, import_i18n.__)("Image editor") : (0, import_i18n.__)("Media preview"),
|
|
478
|
+
sidebar: (0, import_i18n.__)("Media details"),
|
|
479
|
+
footer: (0, import_i18n.__)("Image editing tools")
|
|
480
|
+
},
|
|
481
|
+
content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor__canvas", children: isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
482
|
+
import_media_editor_canvas.default,
|
|
483
|
+
{
|
|
484
|
+
aspectRatio: (0, import_media_editor_crop_panel.resolveAspectRatio)(
|
|
485
|
+
aspectRatioValue,
|
|
486
|
+
imageAspectRatio
|
|
487
|
+
),
|
|
488
|
+
freeformCrop,
|
|
489
|
+
focusOnMount: true,
|
|
490
|
+
isPlacementActive,
|
|
491
|
+
onGestureStart: handleCanvasGestureStart,
|
|
492
|
+
onGestureEnd: handleCanvasGestureEnd
|
|
493
|
+
}
|
|
494
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_media_preview.default, {}) }),
|
|
495
|
+
footer: isImage ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
496
|
+
import_media_editor_toolbar.default,
|
|
497
|
+
{
|
|
498
|
+
onReset: () => {
|
|
499
|
+
setAspectRatioValue("0");
|
|
500
|
+
setFreeformCrop(true);
|
|
501
|
+
},
|
|
502
|
+
onPlacementControlInteraction: signalPlacementControlInteraction,
|
|
503
|
+
isUndoRedoDisabled: isCropInteractionActive
|
|
504
|
+
}
|
|
505
|
+
) : void 0,
|
|
506
|
+
sidebar: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_interface.ComplementaryArea.Slot, { scope: "media-editor" })
|
|
507
|
+
}
|
|
508
|
+
)
|
|
509
|
+
] }) }),
|
|
510
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
511
|
+
import_components.__experimentalConfirmDialog,
|
|
512
|
+
{
|
|
513
|
+
isOpen: isDiscardDialogOpen,
|
|
514
|
+
confirmButtonText: (0, import_i18n.__)("Discard"),
|
|
515
|
+
cancelButtonText: (0, import_i18n.__)("Keep editing"),
|
|
516
|
+
onCancel: () => setIsDiscardDialogOpen(false),
|
|
517
|
+
onConfirm: () => {
|
|
518
|
+
setIsDiscardDialogOpen(false);
|
|
519
|
+
discardAndClose();
|
|
520
|
+
},
|
|
521
|
+
children: (0, import_i18n.__)(
|
|
522
|
+
"Are you sure you want to discard your unsaved changes?"
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
),
|
|
526
|
+
noticesPortalElement ? (0, import_element.createPortal)(snackbar, noticesPortalElement) : snackbar
|
|
527
|
+
]
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
return renderFrame({
|
|
531
|
+
children,
|
|
532
|
+
headerActions: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
533
|
+
HeaderActions,
|
|
534
|
+
{
|
|
535
|
+
isSaving,
|
|
536
|
+
hasMedia: !!media,
|
|
537
|
+
hasChanges,
|
|
538
|
+
isImage,
|
|
539
|
+
showCloseButton,
|
|
540
|
+
onCancel: handleRequestClose,
|
|
541
|
+
onSave: handleSave
|
|
542
|
+
}
|
|
543
|
+
),
|
|
544
|
+
onRequestClose: handleRequestClose,
|
|
545
|
+
onKeyDown: handleKeyDown,
|
|
546
|
+
shouldCloseOnClickOutside: !hasChanges && !isSaving,
|
|
547
|
+
isSaving,
|
|
548
|
+
hasChanges,
|
|
549
|
+
hasMedia: !!media
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
function MediaEditor(props) {
|
|
553
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image_editor.CropperProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorContent, { ...props }) }, props.id);
|
|
554
|
+
}
|
|
555
|
+
var media_editor_default = MediaEditor;
|
|
556
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
557
|
+
0 && (module.exports = {
|
|
558
|
+
MediaEditor
|
|
559
|
+
});
|
|
560
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/media-editor/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\tButton,\n\tFlex,\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, keyboard } from '@wordpress/icons';\nimport { isAppleOS, isKeyboardEvent } from '@wordpress/keycodes';\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';\nimport type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react';\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 { unlock } from '../../lock-unlock';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { CropperProvider, useCropper } from '../../image-editor';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport { buildModifiers } from '../media-editor-modal/build-modifiers';\nimport MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\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// Embed query for the attachment's author and parent post. Shared between\n// the `getEntityRecord` read and the matching `invalidateResolution` so the\n// two stay in lockstep.\nconst ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;\n\n// Scope save-failure snackbars so they don't leak into the host editor/page.\nconst NOTICES_CONTEXT = 'media-editor';\nconst PLACEMENT_CONTROL_IDLE_MS = 300;\n\nconst { Tabs } = unlock( componentsPrivateApis );\n\ninterface EditorTab {\n\tid: string;\n\ttitle: string;\n\tpanel: JSX.Element;\n}\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n}\n\nexport interface MediaEditorFrameProps {\n\tchildren: ReactNode;\n\theaderActions: ReactNode;\n\tonRequestClose: () => void;\n\tonKeyDown: ( event: ReactKeyboardEvent< HTMLElement > ) => void;\n\tshouldCloseOnClickOutside: boolean;\n\tisSaving: boolean;\n\thasChanges: boolean;\n\thasMedia: boolean;\n}\n\nexport interface MediaEditorProps {\n\tfields?: Field< Media >[];\n\tid: number;\n\taspectRatioPresets?: AspectRatioPreset[];\n\tonClose?: () => void;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\trenderFrame: ( props: MediaEditorFrameProps ) => JSX.Element;\n\tnoticesClassName?: string;\n\tnoticesPortalElement?: Element | null;\n\tshowCloseButton?: boolean;\n\tshouldCloseOnEsc?: boolean;\n}\n\nfunction MediaEditorSidebar( { tabs }: { tabs: EditorTab[] } ) {\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__sidebar\"\n\t\t\tpanelClassName=\"media-editor__sidebar-panel\"\n\t\t\theaderClassName=\"media-editor__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\tisImage: boolean;\n\tshowCloseButton?: boolean;\n\tonCancel: () => void;\n\tonSave: () => void;\n}\n\nfunction HeaderActions( {\n\tisSaving,\n\thasMedia,\n\thasChanges,\n\tisImage,\n\tshowCloseButton = false,\n\tonCancel,\n\tonSave,\n}: HeaderActionsProps ) {\n\tconst saveDisabled = isSaving || ! hasMedia || ! hasChanges;\n\tconst [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"media-editor__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{ isImage && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ keyboard }\n\t\t\t\t\tlabel={ __( 'Keyboard shortcuts' ) }\n\t\t\t\t\tonClick={ () => setIsShortcutsModalOpen( true ) }\n\t\t\t\t/>\n\t\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{ showCloseButton && (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ close }\n\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\tonClick={ onCancel }\n\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isShortcutsModalOpen && (\n\t\t\t\t<MediaEditorKeyboardShortcutsModal\n\t\t\t\t\tonClose={ () => setIsShortcutsModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Flex>\n\t);\n}\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nfunction MediaEditorContent( {\n\tfields = [],\n\tid,\n\taspectRatioPresets,\n\tonClose,\n\tonSaved,\n\trenderFrame,\n\tnoticesClassName = 'media-editor__snackbar',\n\tnoticesPortalElement,\n\tshowCloseButton = false,\n\tshouldCloseOnEsc = false,\n}: MediaEditorProps ) {\n\tconst cropper = useCropper();\n\n\tconst { media, hasEdits } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\tgetEntityRecord,\n\t\t\t\thasEditsForEntityRecord,\n\t\t\t} = select( coreStore );\n\t\t\t// Trigger an _embed fetch so `_embedded.author` and\n\t\t\t// `_embedded['wp:attached-to']` land on the record for the Details\n\t\t\t// fields to read. `getEditedEntityRecord` doesn't formally accept a\n\t\t\t// query, so we can't embed via that selector directly.\n\t\t\tgetEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tid,\n\t\t\t\tATTACHMENT_EMBED_QUERY\n\t\t\t);\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\tconst hasChanges = cropper.isDirty || hasEdits;\n\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\teditEntityRecord,\n\t\tinvalidateResolution,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\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 [ isCanvasGestureActive, setIsCanvasGestureActive ] =\n\t\tuseState( 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\tconst handleCanvasGestureStart = useCallback( () => {\n\t\tsetIsCanvasGestureActive( true );\n\t}, [] );\n\tconst handleCanvasGestureEnd = useCallback( () => {\n\t\tsetIsCanvasGestureActive( false );\n\t}, [] );\n\tconst isCropInteractionActive = isPlacementActive || isCanvasGestureActive;\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( placementControlTimerRef.current );\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tsetAspectRatioValue( '0' );\n\t\tsetFreeformCrop( true );\n\t\tsetIsPlacementActive( false );\n\t\tsetIsCanvasGestureActive( false );\n\t}, [ id ] );\n\n\t// Bust the cached `_embed` resolution each time the editor mounts (or the\n\t// id changes) so embedded data such as the attached post's title or the\n\t// author's name reflects any edits made elsewhere since the last open.\n\tuseEffect( () => {\n\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t'postType',\n\t\t\t'attachment',\n\t\t\tid,\n\t\t\tATTACHMENT_EMBED_QUERY,\n\t\t] );\n\t}, [ id, invalidateResolution ] );\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< EditorTab[] >( () => {\n\t\tconst detailsTab: EditorTab = {\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__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__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\tonClose?.();\n\t};\n\n\tconst handleRequestClose = () => {\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\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\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 PendingMetadataEdits;\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\t\t\t\t// The `/edit` endpoint creates a new attachment for the crop\n\t\t\t\t// and doesn't inherit `post_parent` from the source (unlike\n\t\t\t\t// title/caption/etc.), so carry the existing value across when\n\t\t\t\t// the user hasn't explicitly edited it. Use a defined-check so\n\t\t\t\t// an explicit `0` (unattached) is also preserved.\n\t\t\t\tif (\n\t\t\t\t\t! ( 'post' in metadataEdits ) &&\n\t\t\t\t\tmedia?.post !== undefined\n\t\t\t\t) {\n\t\t\t\t\tmetadataEdits.post = media.post;\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\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\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 ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tcropper.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t} );\n\t\t\t}\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\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\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\tconst handleKeyDown = ( event: ReactKeyboardEvent< HTMLElement > ) => {\n\t\tconst isUndoShortcut = isKeyboardEvent.primary( event, 'z' );\n\t\tconst isRedoShortcut =\n\t\t\tisKeyboardEvent.primaryShift( event, 'z' ) ||\n\t\t\t( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );\n\t\tif ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tconst isMetadataField =\n\t\t\t\t( target.tagName === 'INPUT' ||\n\t\t\t\t\ttarget.tagName === 'TEXTAREA' ||\n\t\t\t\t\ttarget.isContentEditable ) &&\n\t\t\t\t! target.closest( `[${ CROP_CONTROL_ATTR }]` );\n\t\t\tif ( ! isMetadataField ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( isCropInteractionActive ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( isRedoShortcut ) {\n\t\t\t\t\tcropper.redo();\n\t\t\t\t} else {\n\t\t\t\t\tcropper.undo();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif ( shouldCloseOnEsc ) {\n\t\t\tif ( event.code !== 'Escape' && event.key !== 'Escape' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( isSaving ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( hasChanges ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetIsDiscardDialogOpen( true );\n\t\t\t}\n\t\t}\n\t};\n\n\tconst snackbar = (\n\t\t<SnackbarNotices\n\t\t\tclassName={ noticesClassName }\n\t\t\tcontext={ NOTICES_CONTEXT }\n\t\t/>\n\t);\n\n\tconst children = (\n\t\t<MediaEditorProvider\n\t\t\tvalue={ media ?? undefined }\n\t\t\tonChange={ handleChange }\n\t\t\tsettings={ { fields } }\n\t\t>\n\t\t\t<div className=\"media-editor\">\n\t\t\t\t{ ! media ? (\n\t\t\t\t\t<div className=\"media-editor__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<MediaEditorSidebar 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__skeleton\"\n\t\t\t\t\t\t\tlabels={ {\n\t\t\t\t\t\t\t\tbody: isImage\n\t\t\t\t\t\t\t\t\t? __( 'Image editor' )\n\t\t\t\t\t\t\t\t\t: __( 'Media preview' ),\n\t\t\t\t\t\t\t\tsidebar: __( 'Media details' ),\n\t\t\t\t\t\t\t\tfooter: __( 'Image editing tools' ),\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tcontent={\n\t\t\t\t\t\t\t\t<div className=\"media-editor__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\tfocusOnMount\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\tonGestureStart={\n\t\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureStart\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonGestureEnd={\n\t\t\t\t\t\t\t\t\t\t\t\thandleCanvasGestureEnd\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\tisUndoRedoDisabled={\n\t\t\t\t\t\t\t\t\t\t\tisCropInteractionActive\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</div>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isDiscardDialogOpen }\n\t\t\t\tconfirmButtonText={ __( 'Discard' ) }\n\t\t\t\tcancelButtonText={ __( 'Keep editing' ) }\n\t\t\t\tonCancel={ () => setIsDiscardDialogOpen( false ) }\n\t\t\t\tonConfirm={ () => {\n\t\t\t\t\tsetIsDiscardDialogOpen( false );\n\t\t\t\t\tdiscardAndClose();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __(\n\t\t\t\t\t'Are you sure you want to discard your unsaved changes?'\n\t\t\t\t) }\n\t\t\t</ConfirmDialog>\n\t\t\t{ noticesPortalElement\n\t\t\t\t? createPortal( snackbar, noticesPortalElement )\n\t\t\t\t: snackbar }\n\t\t</MediaEditorProvider>\n\t);\n\n\treturn renderFrame( {\n\t\tchildren,\n\t\theaderActions: (\n\t\t\t<HeaderActions\n\t\t\t\tisSaving={ isSaving }\n\t\t\t\thasMedia={ !! media }\n\t\t\t\thasChanges={ hasChanges }\n\t\t\t\tisImage={ isImage }\n\t\t\t\tshowCloseButton={ showCloseButton }\n\t\t\t\tonCancel={ handleRequestClose }\n\t\t\t\tonSave={ handleSave }\n\t\t\t/>\n\t\t),\n\t\tonRequestClose: handleRequestClose,\n\t\tonKeyDown: handleKeyDown,\n\t\tshouldCloseOnClickOutside: ! hasChanges && ! isSaving,\n\t\tisSaving,\n\t\thasChanges,\n\t\thasMedia: !! media,\n\t} );\n}\n\nexport function MediaEditor( props: MediaEditorProps ) {\n\treturn (\n\t\t<CropperProvider key={ props.id }>\n\t\t\t<MediaEditorContent { ...props } />\n\t\t</CropperProvider>\n\t);\n}\n\nexport default MediaEditor;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AACrB,wBAMO;AACP,gBAAsB;AACtB,kBAAoD;AACpD,uBAAmC;AACnC,qBAQO;AACP,kBAA4B;AAC5B,mBAA6C;AAC7C,sBAA2C;AAC3C,qBAAuD;AAEvD,uBAMO;AAMP,mCAAoC;AAEpC,2BAAyB;AACzB,iCAA8B;AAC9B,kCAA+B;AAC/B,qCAEO;AACP,wBAAsB;AACtB,yBAAuB;AACvB,mBAAyC;AACzC,0BAA4C;AAE5C,uCAAkC;AAClC,6BAA+B;AAC/B,mDAA8C;AA2EvC;AAvEP,IAAM,qBAAqB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;A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,KADX,MAAM,EAE7B;AAEF;AAEA,IAAO,uBAAQ;",
|
|
6
|
+
"names": ["componentsPrivateApis", "MediaEditorKeyboardShortcutsModal", "coreStore", "noticesStore", "MediaForm", "MediaEditorCropPanel", "apiFetch", "MediaEditorCanvas", "MediaPreview", "MediaEditorToolbar", "ConfirmDialog"]
|
|
7
|
+
}
|
|
@@ -30,7 +30,10 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
30
30
|
function MediaEditorCanvas({
|
|
31
31
|
aspectRatio,
|
|
32
32
|
freeformCrop,
|
|
33
|
-
|
|
33
|
+
focusOnMount,
|
|
34
|
+
isPlacementActive = false,
|
|
35
|
+
onGestureStart,
|
|
36
|
+
onGestureEnd
|
|
34
37
|
}) {
|
|
35
38
|
const { media } = (0, import_media_editor_provider.useMediaEditorContext)();
|
|
36
39
|
const controller = (0, import_image_editor.useCropper)();
|
|
@@ -46,8 +49,17 @@ function MediaEditorCanvas({
|
|
|
46
49
|
controller,
|
|
47
50
|
aspectRatio,
|
|
48
51
|
freeformCrop,
|
|
52
|
+
focusOnMount,
|
|
49
53
|
showGrid: "interactive",
|
|
50
|
-
isPlacementActive
|
|
54
|
+
isPlacementActive,
|
|
55
|
+
onGestureStart: () => {
|
|
56
|
+
onGestureStart?.();
|
|
57
|
+
controller.commitHistory();
|
|
58
|
+
},
|
|
59
|
+
onGestureEnd: () => {
|
|
60
|
+
controller.commitHistory();
|
|
61
|
+
onGestureEnd?.();
|
|
62
|
+
}
|
|
51
63
|
}
|
|
52
64
|
) });
|
|
53
65
|
}
|