@wordpress/media-editor 0.7.1-next.v.202604201441.0 → 0.8.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-canvas/index.cjs +54 -0
- package/build/components/media-editor-canvas/index.cjs.map +7 -0
- package/build/components/media-editor-crop-panel/index.cjs +116 -0
- package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
- package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
- package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +497 -0
- package/build/components/media-editor-modal/index.cjs.map +7 -0
- package/build/components/media-editor-toolbar/index.cjs +146 -0
- package/build/components/media-editor-toolbar/index.cjs.map +7 -0
- package/build/image-editor/core/camera.cjs +194 -0
- package/build/image-editor/core/camera.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +81 -0
- package/build/image-editor/core/constants.cjs.map +7 -0
- package/build/image-editor/core/containment.cjs +245 -0
- package/build/image-editor/core/containment.cjs.map +7 -0
- package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
- package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +50 -0
- package/build/image-editor/core/index.cjs.map +7 -0
- package/build/image-editor/core/interaction-controller.cjs +608 -0
- package/build/image-editor/core/interaction-controller.cjs.map +7 -0
- package/build/image-editor/core/math/rotation.cjs +41 -0
- package/build/image-editor/core/math/rotation.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +95 -0
- package/build/image-editor/core/source-region.cjs.map +7 -0
- package/build/image-editor/core/state.cjs +269 -0
- package/build/image-editor/core/state.cjs.map +7 -0
- package/build/image-editor/core/stencil-math.cjs +197 -0
- package/build/image-editor/core/stencil-math.cjs.map +7 -0
- package/build/image-editor/core/transform-style.cjs +46 -0
- package/build/image-editor/core/transform-style.cjs.map +7 -0
- package/build/image-editor/core/transforms/pipeline.cjs +43 -0
- package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
- package/build/image-editor/core/types.cjs +19 -0
- package/build/image-editor/core/types.cjs.map +7 -0
- package/build/image-editor/index.cjs +57 -0
- package/build/image-editor/index.cjs.map +7 -0
- package/build/image-editor/react/components/cropper-provider.cjs +50 -0
- package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +365 -0
- package/build/image-editor/react/components/cropper.cjs.map +7 -0
- package/build/image-editor/react/components/index.cjs +36 -0
- package/build/image-editor/react/components/index.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +31 -0
- package/build/image-editor/react/hooks/index.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
- package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
- package/build/index.cjs +5 -2
- package/build/index.cjs.map +2 -2
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/private-apis.cjs +38 -0
- package/build/private-apis.cjs.map +7 -0
- package/build/store/actions.cjs +45 -0
- package/build/store/actions.cjs.map +7 -0
- package/build/store/constants.cjs +31 -0
- package/build/store/constants.cjs.map +7 -0
- package/build/store/index.cjs +51 -0
- package/build/store/index.cjs.map +7 -0
- package/build/store/reducer.cjs +51 -0
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/selectors.cjs +43 -0
- package/build/store/selectors.cjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +33 -0
- package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
- package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
- package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +483 -0
- package/build-module/components/media-editor-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-toolbar/index.mjs +130 -0
- package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
- package/build-module/image-editor/core/camera.mjs +163 -0
- package/build-module/image-editor/core/camera.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +51 -0
- package/build-module/image-editor/core/constants.mjs.map +7 -0
- package/build-module/image-editor/core/containment.mjs +218 -0
- package/build-module/image-editor/core/containment.mjs.map +7 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +24 -0
- package/build-module/image-editor/core/index.mjs.map +7 -0
- package/build-module/image-editor/core/interaction-controller.mjs +583 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
- package/build-module/image-editor/core/math/rotation.mjs +15 -0
- package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +69 -0
- package/build-module/image-editor/core/source-region.mjs.map +7 -0
- package/build-module/image-editor/core/state.mjs +242 -0
- package/build-module/image-editor/core/state.mjs.map +7 -0
- package/build-module/image-editor/core/stencil-math.mjs +169 -0
- package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
- package/build-module/image-editor/core/transform-style.mjs +21 -0
- package/build-module/image-editor/core/transform-style.mjs.map +7 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
- package/build-module/image-editor/core/types.mjs +1 -0
- package/build-module/image-editor/core/types.mjs.map +7 -0
- package/build-module/image-editor/index.mjs +30 -0
- package/build-module/image-editor/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +337 -0
- package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
- package/build-module/image-editor/react/components/index.mjs +9 -0
- package/build-module/image-editor/react/components/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +6 -0
- package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
- package/build-module/index.mjs +3 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/private-apis.mjs +13 -0
- package/build-module/private-apis.mjs.map +7 -0
- package/build-module/store/actions.mjs +19 -0
- package/build-module/store/actions.mjs.map +7 -0
- package/build-module/store/constants.mjs +6 -0
- package/build-module/store/constants.mjs.map +7 -0
- package/build-module/store/index.mjs +16 -0
- package/build-module/store/index.mjs.map +7 -0
- package/build-module/store/reducer.mjs +26 -0
- package/build-module/store/reducer.mjs.map +7 -0
- package/build-module/store/selectors.mjs +16 -0
- package/build-module/store/selectors.mjs.map +7 -0
- package/build-style/style-rtl.css +315 -0
- package/build-style/style.css +315 -0
- package/build-types/components/media-editor-canvas/index.d.ts +22 -0
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +20 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/image-editor/core/camera.d.ts +107 -0
- package/build-types/image-editor/core/camera.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +46 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -0
- package/build-types/image-editor/core/containment.d.ts +61 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +8 -0
- package/build-types/image-editor/core/index.d.ts.map +1 -0
- package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
- package/build-types/image-editor/core/math/rotation.d.ts +18 -0
- package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts +75 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -0
- package/build-types/image-editor/core/state.d.ts +42 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -0
- package/build-types/image-editor/core/stencil-math.d.ts +79 -0
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
- package/build-types/image-editor/core/transform-style.d.ts +23 -0
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
- package/build-types/image-editor/core/types.d.ts +211 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -0
- package/build-types/image-editor/index.d.ts +16 -0
- package/build-types/image-editor/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper.d.ts +59 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
- package/build-types/image-editor/react/components/index.d.ts +4 -0
- package/build-types/image-editor/react/components/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +3 -0
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +27 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +2 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +4 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +23 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +8 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/package.json +21 -7
- package/src/components/media-editor-canvas/index.tsx +56 -0
- package/src/components/media-editor-canvas/style.scss +9 -0
- package/src/components/media-editor-crop-panel/index.tsx +143 -0
- package/src/components/media-editor-modal/build-modifiers.ts +164 -0
- package/src/components/media-editor-modal/index.tsx +639 -0
- package/src/components/media-editor-modal/style.scss +139 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
- package/src/components/media-editor-toolbar/index.tsx +150 -0
- package/src/components/media-editor-toolbar/style.scss +21 -0
- package/src/image-editor/README.md +162 -0
- package/src/image-editor/core/camera.ts +352 -0
- package/src/image-editor/core/constants.ts +93 -0
- package/src/image-editor/core/containment.ts +435 -0
- package/src/image-editor/core/export/canvas-renderer.ts +253 -0
- package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
- package/src/image-editor/core/index.ts +35 -0
- package/src/image-editor/core/interaction-controller.ts +889 -0
- package/src/image-editor/core/math/rotation.ts +26 -0
- package/src/image-editor/core/source-region.ts +166 -0
- package/src/image-editor/core/state.ts +428 -0
- package/src/image-editor/core/stencil-math.ts +330 -0
- package/src/image-editor/core/test/camera.ts +593 -0
- package/src/image-editor/core/test/interaction-controller.ts +996 -0
- package/src/image-editor/core/test/preview-export-parity.ts +242 -0
- package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
- package/src/image-editor/core/test/state.ts +762 -0
- package/src/image-editor/core/test/stencil-math.ts +321 -0
- package/src/image-editor/core/transform-style.ts +44 -0
- package/src/image-editor/core/transforms/pipeline.ts +43 -0
- package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
- package/src/image-editor/core/types.ts +177 -0
- package/src/image-editor/docs/architecture.md +96 -0
- package/src/image-editor/docs/recipes.md +720 -0
- package/src/image-editor/docs/roadmap.md +66 -0
- package/src/image-editor/index.ts +43 -0
- package/src/image-editor/react/components/cropper-provider.tsx +73 -0
- package/src/image-editor/react/components/cropper.scss +195 -0
- package/src/image-editor/react/components/cropper.tsx +534 -0
- package/src/image-editor/react/components/index.ts +3 -0
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
- package/src/image-editor/react/components/test/cropper.tsx +140 -0
- package/src/image-editor/react/hooks/index.ts +2 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
- package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
- package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
- package/src/image-editor/react/hooks/use-interaction.ts +223 -0
- package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
- package/src/image-editor/stories/style.css +94 -0
- package/src/image-editor/style.scss +1 -0
- package/src/index.ts +3 -0
- package/src/lock-unlock.ts +10 -0
- package/src/private-apis.ts +12 -0
- package/src/store/actions.ts +33 -0
- package/src/store/constants.ts +1 -0
- package/src/store/index.ts +20 -0
- package/src/store/reducer.ts +48 -0
- package/src/store/selectors.ts +16 -0
- package/src/store/test/reducer.ts +57 -0
- package/src/style.scss +4 -0
- package/tsconfig.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,497 @@
|
|
|
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-modal/index.tsx
|
|
31
|
+
var media_editor_modal_exports = {};
|
|
32
|
+
__export(media_editor_modal_exports, {
|
|
33
|
+
MediaEditorModal: () => MediaEditorModal,
|
|
34
|
+
default: () => media_editor_modal_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(media_editor_modal_exports);
|
|
37
|
+
var import_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_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"));
|
|
53
|
+
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
|
+
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
|
+
function MediaEditorModal({
|
|
445
|
+
fields = [],
|
|
446
|
+
aspectRatioPresets
|
|
447
|
+
}) {
|
|
448
|
+
const { isModalOpen, id, onUpdate } = (0, import_data.useSelect)((select) => {
|
|
449
|
+
const { isOpen, getId, getOnUpdate } = select(import_store.store);
|
|
450
|
+
return {
|
|
451
|
+
isModalOpen: isOpen(),
|
|
452
|
+
id: getId(),
|
|
453
|
+
onUpdate: getOnUpdate()
|
|
454
|
+
};
|
|
455
|
+
}, []);
|
|
456
|
+
const { media, hasEdits } = (0, import_data.useSelect)(
|
|
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
|
+
);
|
|
477
|
+
if (!isModalOpen || !id) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image_editor.CropperProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
481
|
+
MediaEditorModalContent,
|
|
482
|
+
{
|
|
483
|
+
fields,
|
|
484
|
+
id,
|
|
485
|
+
media,
|
|
486
|
+
hasEdits,
|
|
487
|
+
aspectRatioPresets,
|
|
488
|
+
onUpdate
|
|
489
|
+
}
|
|
490
|
+
) }, id);
|
|
491
|
+
}
|
|
492
|
+
var media_editor_modal_default = MediaEditorModal;
|
|
493
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
494
|
+
0 && (module.exports = {
|
|
495
|
+
MediaEditorModal
|
|
496
|
+
});
|
|
497
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,uBAAqB;AACrB,wBAOO;AACP,gBAAsB;AACtB,kBAAoD;AACpD,uBAAmC;AACnC,qBAQO;AACP,kBAA4B;AAC5B,mBAAmC;AACnC,qBAAuD;AAEvD,uBAMO;AAKP,mCAAoC;AAEpC,2BAAyB;AACzB,iCAA8B;AAC9B,kCAA+B;AAC/B,qCAEO;AACP,wBAAsB;AACtB,mBAA0C;AAE1C,yBAAuB;AACvB,mBAAyC;AACzC,0BAA4C;AAE5C,6BAA+B;AAoExB;AA3DP,IAAM,qBAAqB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAIA,IAAM,kBAAkB;AACxB,IAAM,4BAA4B;AAElC,IAAM,EAAE,KAAK,QAAI,2BAAQ,kBAAAA,WAAsB;AA8B/C,SAAS,w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B;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,aAAAR,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,OAAO,SAAS,QAAI;AAAA,IAC3B,CAAE,WAAY;AACb,UAAK,CAAE,IAAK;AACX,eAAO,EAAE,OAAO,MAAM,UAAU,MAAM;AAAA,MACvC;AACA,YAAM,EAAE,uBAAuB,wBAAwB,IACtD,OAAQ,iBAAAD,KAAU;AACnB,aAAO;AAAA,QACN,OAAO;AAAA,UACN;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,QACA,UAAU;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,EAAG;AAAA,EACN;AAEA,MAAK,CAAE,eAAe,CAAE,IAAK;AAC5B,WAAO;AAAA,EACR;AAUA,SACC,4CAAC,uCACA;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACD,KARsB,EASvB;AAEF;AAEA,IAAO,6BAAQ;",
|
|
6
|
+
"names": ["componentsPrivateApis", "coreStore", "mediaEditorStore", "noticesStore", "MediaForm", "MediaEditorCropPanel", "apiFetch", "MediaEditorCanvas", "MediaPreview", "MediaEditorToolbar", "ConfirmDialog"]
|
|
7
|
+
}
|