@wordpress/media-editor 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -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.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,201 +1,127 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let _wordpress_api_fetch = require("@wordpress/api-fetch");
|
|
28
|
+
_wordpress_api_fetch = __toESM(_wordpress_api_fetch);
|
|
29
|
+
let _wordpress_data = require("@wordpress/data");
|
|
30
|
+
let _wordpress_core_data = require("@wordpress/core-data");
|
|
31
|
+
let _wordpress_element = require("@wordpress/element");
|
|
32
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
33
|
+
let _wordpress_notices = require("@wordpress/notices");
|
|
34
|
+
let ___media_editor_modal_build_modifiers_ts = require("../media-editor-modal/build-modifiers.cjs");
|
|
30
35
|
// packages/media-editor/src/components/media-editor/use-save-media-editor.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
38
|
-
var import_data = require("@wordpress/data");
|
|
39
|
-
var import_core_data = require("@wordpress/core-data");
|
|
40
|
-
var import_element = require("@wordpress/element");
|
|
41
|
-
var import_i18n = require("@wordpress/i18n");
|
|
42
|
-
var import_notices = require("@wordpress/notices");
|
|
43
|
-
var import_build_modifiers = require("../media-editor-modal/build-modifiers.cjs");
|
|
44
|
-
var METADATA_EDIT_KEYS = [
|
|
45
|
-
"title",
|
|
46
|
-
"caption",
|
|
47
|
-
"description",
|
|
48
|
-
"alt_text",
|
|
49
|
-
"post"
|
|
36
|
+
const METADATA_EDIT_KEYS = [
|
|
37
|
+
"title",
|
|
38
|
+
"caption",
|
|
39
|
+
"description",
|
|
40
|
+
"alt_text",
|
|
41
|
+
"post"
|
|
50
42
|
];
|
|
51
|
-
|
|
43
|
+
const MEDIA_EDITOR_NOTICES_CONTEXT = "media-editor";
|
|
52
44
|
function getCropModifiers(session) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
return (0, import_build_modifiers.buildModifiers)(state, {
|
|
58
|
-
width: state.image.naturalWidth,
|
|
59
|
-
height: state.image.naturalHeight
|
|
60
|
-
});
|
|
45
|
+
if (!session.hasOutputEdits) return [];
|
|
46
|
+
return (0, ___media_editor_modal_build_modifiers_ts.buildModifiers)(session.cropper);
|
|
61
47
|
}
|
|
62
48
|
function getMetadataEdits(pendingEdits, media) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (!("post" in metadataEdits) && media?.post !== void 0) {
|
|
70
|
-
metadataEdits.post = media.post;
|
|
71
|
-
}
|
|
72
|
-
return metadataEdits;
|
|
49
|
+
const metadataEdits = {};
|
|
50
|
+
for (const key of METADATA_EDIT_KEYS) if (pendingEdits && key in pendingEdits) metadataEdits[key] = pendingEdits[key];
|
|
51
|
+
if (!("post" in metadataEdits) && media?.post !== void 0) metadataEdits.post = media.post;
|
|
52
|
+
return metadataEdits;
|
|
73
53
|
}
|
|
74
|
-
function useSaveMediaEditor({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
const next = saved ?? targetMedia;
|
|
146
|
-
if (next && next.id !== targetId) {
|
|
147
|
-
clearEntityRecordEdits("postType", "attachment", targetId);
|
|
148
|
-
}
|
|
149
|
-
if (next && next.id) {
|
|
150
|
-
if (next.id === id) {
|
|
151
|
-
session.cropper.reset();
|
|
152
|
-
}
|
|
153
|
-
onSaved?.({
|
|
154
|
-
id: next.id,
|
|
155
|
-
url: next.source_url,
|
|
156
|
-
media: next,
|
|
157
|
-
previous
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
} catch (error) {
|
|
161
|
-
const message = error instanceof Error ? error.message : error?.message ?? (0, import_i18n.__)("An unknown error occurred.");
|
|
162
|
-
createErrorNotice(
|
|
163
|
-
isImage ? (0, import_i18n.sprintf)(
|
|
164
|
-
/* translators: %s: Error message. */
|
|
165
|
-
(0, import_i18n.__)("Could not save image. %s"),
|
|
166
|
-
message
|
|
167
|
-
) : (0, import_i18n.sprintf)(
|
|
168
|
-
/* translators: %s: Error message. */
|
|
169
|
-
(0, import_i18n.__)("Could not save media. %s"),
|
|
170
|
-
message
|
|
171
|
-
),
|
|
172
|
-
{
|
|
173
|
-
type: "snackbar",
|
|
174
|
-
context: MEDIA_EDITOR_NOTICES_CONTEXT
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
} finally {
|
|
178
|
-
setIsSaving(false);
|
|
179
|
-
}
|
|
180
|
-
}, [
|
|
181
|
-
clearEntityRecordEdits,
|
|
182
|
-
createErrorNotice,
|
|
183
|
-
id,
|
|
184
|
-
isImage,
|
|
185
|
-
media,
|
|
186
|
-
onSaved,
|
|
187
|
-
receiveEntityRecords,
|
|
188
|
-
registry,
|
|
189
|
-
removeAllNotices,
|
|
190
|
-
replacementSource,
|
|
191
|
-
saveEditedEntityRecord,
|
|
192
|
-
session
|
|
193
|
-
]);
|
|
194
|
-
return { isSaving, save };
|
|
54
|
+
function useSaveMediaEditor({ session, id, isImage, media, onSaved, replacementSource }) {
|
|
55
|
+
const registry = (0, _wordpress_data.useRegistry)();
|
|
56
|
+
const { clearEntityRecordEdits, receiveEntityRecords, saveEditedEntityRecord } = (0, _wordpress_data.useDispatch)(_wordpress_core_data.store);
|
|
57
|
+
const { createErrorNotice, removeAllNotices } = (0, _wordpress_data.useDispatch)(_wordpress_notices.store);
|
|
58
|
+
const [isSaving, setIsSaving] = (0, _wordpress_element.useState)(false);
|
|
59
|
+
return {
|
|
60
|
+
isSaving,
|
|
61
|
+
save: (0, _wordpress_element.useCallback)(async () => {
|
|
62
|
+
removeAllNotices("snackbar", MEDIA_EDITOR_NOTICES_CONTEXT);
|
|
63
|
+
setIsSaving(true);
|
|
64
|
+
try {
|
|
65
|
+
let saved;
|
|
66
|
+
const modifiers = getCropModifiers(session);
|
|
67
|
+
const targetId = replacementSource?.id ?? id;
|
|
68
|
+
const targetUrl = replacementSource?.url ?? media?.source_url;
|
|
69
|
+
const targetMedia = replacementSource?.media ?? media;
|
|
70
|
+
const previous = (modifiers.length > 0 || replacementSource) && media ? {
|
|
71
|
+
id,
|
|
72
|
+
url: media.source_url
|
|
73
|
+
} : void 0;
|
|
74
|
+
if (modifiers.length > 0) {
|
|
75
|
+
const metadataEdits = getMetadataEdits(registry.select(_wordpress_core_data.store).getEntityRecordNonTransientEdits("postType", "attachment", targetId), targetMedia);
|
|
76
|
+
saved = await (0, _wordpress_api_fetch.default)({
|
|
77
|
+
path: `/wp/v2/media/${targetId}/edit`,
|
|
78
|
+
method: "POST",
|
|
79
|
+
data: {
|
|
80
|
+
src: targetUrl,
|
|
81
|
+
modifiers,
|
|
82
|
+
...metadataEdits
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (saved) receiveEntityRecords("postType", "attachment", saved, void 0, true);
|
|
86
|
+
} else if (replacementSource && !registry.select(_wordpress_core_data.store).hasEditsForEntityRecord("postType", "attachment", targetId)) saved = replacementSource.media;
|
|
87
|
+
else saved = await saveEditedEntityRecord("postType", "attachment", targetId, { throwOnError: true });
|
|
88
|
+
const next = saved ?? targetMedia;
|
|
89
|
+
if (next && next.id !== targetId) clearEntityRecordEdits("postType", "attachment", targetId);
|
|
90
|
+
if (next && next.id) {
|
|
91
|
+
if (next.id === id) session.cropper.reset();
|
|
92
|
+
onSaved?.({
|
|
93
|
+
id: next.id,
|
|
94
|
+
url: next.source_url,
|
|
95
|
+
media: next,
|
|
96
|
+
previous
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
const message = error instanceof Error ? error.message : error?.message ?? (0, _wordpress_i18n.__)("An unknown error occurred.");
|
|
101
|
+
createErrorNotice(isImage ? (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Could not save image. %s"), message) : (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Could not save media. %s"), message), {
|
|
102
|
+
type: "snackbar",
|
|
103
|
+
context: MEDIA_EDITOR_NOTICES_CONTEXT
|
|
104
|
+
});
|
|
105
|
+
} finally {
|
|
106
|
+
setIsSaving(false);
|
|
107
|
+
}
|
|
108
|
+
}, [
|
|
109
|
+
clearEntityRecordEdits,
|
|
110
|
+
createErrorNotice,
|
|
111
|
+
id,
|
|
112
|
+
isImage,
|
|
113
|
+
media,
|
|
114
|
+
onSaved,
|
|
115
|
+
receiveEntityRecords,
|
|
116
|
+
registry,
|
|
117
|
+
removeAllNotices,
|
|
118
|
+
replacementSource,
|
|
119
|
+
saveEditedEntityRecord,
|
|
120
|
+
session
|
|
121
|
+
])
|
|
122
|
+
};
|
|
195
123
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
});
|
|
201
|
-
//# sourceMappingURL=use-save-media-editor.cjs.map
|
|
124
|
+
exports.MEDIA_EDITOR_NOTICES_CONTEXT = MEDIA_EDITOR_NOTICES_CONTEXT;
|
|
125
|
+
exports.useSaveMediaEditor = useSaveMediaEditor;
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=use-save-media-editor.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor/use-save-media-editor.ts"],
|
|
4
|
-
"sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\nimport {\n\tbuildModifiers,\n\ttype Modifier,\n} from '../media-editor-modal/build-modifiers';\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// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tconst { state } = session.cropper;\n\tif ( ! session.hasOutputEdits || ! state.image ) {\n\t\treturn [];\n\t}\n\treturn buildModifiers( state, {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t} );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\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\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\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 if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\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\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\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\tsession.cropper.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\tprevious,\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\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\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\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["coreStore", "noticesStore", "apiFetch"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"use-save-media-editor.cjs","names":["buildModifiers","useRegistry","useDispatch","coreStore","noticesStore","useState","useCallback","apiFetch","__","sprintf"],"sources":["../../../src/components/media-editor/use-save-media-editor.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\nimport {\n\tbuildModifiers,\n\ttype Modifier,\n} from '../media-editor-modal/build-modifiers';\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// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tif ( ! session.hasOutputEdits ) {\n\t\treturn [];\n\t}\n\treturn buildModifiers( session.cropper );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\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\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\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 if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\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\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\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\tsession.cropper.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\tprevious,\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\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\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\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],"mappings":"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"}
|
|
@@ -1,135 +1,133 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let clsx = require("clsx");
|
|
28
|
+
clsx = __toESM(clsx);
|
|
29
|
+
let _wordpress_element = require("@wordpress/element");
|
|
30
|
+
let _wordpress_components = require("@wordpress/components");
|
|
31
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
32
|
+
let ___media_editor_provider_index_tsx = require("../media-editor-provider/index.cjs");
|
|
33
|
+
let ______utils_index_ts = require("../../utils/index.cjs");
|
|
34
|
+
let ______image_editor_index_ts = require("../../image-editor/index.cjs");
|
|
35
|
+
let ______state_index_ts = require("../../state/index.cjs");
|
|
36
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
30
37
|
// packages/media-editor/src/components/media-editor-canvas/index.tsx
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
function MediaEditorCanvas({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
freeformCrop: true,
|
|
124
|
-
showGrid: "interactive",
|
|
125
|
-
isPlacementActive,
|
|
126
|
-
onGestureStart: handleGestureStart,
|
|
127
|
-
onGestureEnd: handleGestureEnd,
|
|
128
|
-
disabled
|
|
129
|
-
}
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
)
|
|
133
|
-
] });
|
|
38
|
+
/**
|
|
39
|
+
* Editing surface for image media in the media editor modal. Pulls
|
|
40
|
+
* its cropper controller from the surrounding `<MediaEditorStateProvider>`
|
|
41
|
+
* so the bottom bar and Crop sidebar tab share the same state.
|
|
42
|
+
*
|
|
43
|
+
* Returns `null` for missing or non-image media so the modal's outer
|
|
44
|
+
* guards can render a spinner or fall through to `<MediaPreview>`.
|
|
45
|
+
*
|
|
46
|
+
* @param props
|
|
47
|
+
* @param props.isPlacementActive
|
|
48
|
+
* @param props.onGestureStart
|
|
49
|
+
* @param props.onGestureEnd
|
|
50
|
+
* @param props.disabled
|
|
51
|
+
*/
|
|
52
|
+
function MediaEditorCanvas({ isPlacementActive = false, onGestureStart, onGestureEnd, disabled = false }) {
|
|
53
|
+
const { media } = (0, ___media_editor_provider_index_tsx.useMediaEditorContext)();
|
|
54
|
+
const session = (0, ______state_index_ts.useMediaEditor)();
|
|
55
|
+
const { aspectRatioValue } = session.cropOptions;
|
|
56
|
+
const cropperImage = session.cropper.state.image;
|
|
57
|
+
const { beginGesture, endGesture, setSourceImage } = session;
|
|
58
|
+
const [settled, setSettled] = (0, _wordpress_element.useState)();
|
|
59
|
+
const aspectRatio = (0, _wordpress_element.useMemo)(() => (0, ______state_index_ts.resolveAspectRatio)(aspectRatioValue, cropperImage), [aspectRatioValue, cropperImage]);
|
|
60
|
+
const handleGestureStart = (0, _wordpress_element.useCallback)(() => {
|
|
61
|
+
beginGesture();
|
|
62
|
+
onGestureStart?.();
|
|
63
|
+
}, [beginGesture, onGestureStart]);
|
|
64
|
+
const handleGestureEnd = (0, _wordpress_element.useCallback)(() => {
|
|
65
|
+
endGesture();
|
|
66
|
+
onGestureEnd?.();
|
|
67
|
+
}, [endGesture, onGestureEnd]);
|
|
68
|
+
const mediaUrl = media?.source_url;
|
|
69
|
+
const mediaType = (0, ______utils_index_ts.getMediaTypeFromMimeType)(media?.mime_type);
|
|
70
|
+
const mediaWidth = Number(media?.media_details?.width);
|
|
71
|
+
const mediaHeight = Number(media?.media_details?.height);
|
|
72
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
73
|
+
if (!mediaUrl || !Number.isFinite(mediaWidth) || !Number.isFinite(mediaHeight) || mediaWidth <= 0 || mediaHeight <= 0) return;
|
|
74
|
+
setSourceImage({
|
|
75
|
+
src: mediaUrl,
|
|
76
|
+
naturalWidth: mediaWidth,
|
|
77
|
+
naturalHeight: mediaHeight
|
|
78
|
+
});
|
|
79
|
+
}, [
|
|
80
|
+
mediaUrl,
|
|
81
|
+
mediaWidth,
|
|
82
|
+
mediaHeight,
|
|
83
|
+
setSourceImage
|
|
84
|
+
]);
|
|
85
|
+
const isImage = mediaType.type === "image";
|
|
86
|
+
const status = settled && settled.url === mediaUrl ? settled.status : "loading";
|
|
87
|
+
const handleImageLoaded = (0, _wordpress_element.useCallback)(() => {
|
|
88
|
+
setSettled({
|
|
89
|
+
url: mediaUrl,
|
|
90
|
+
status: "loaded"
|
|
91
|
+
});
|
|
92
|
+
}, [mediaUrl]);
|
|
93
|
+
const handleImageError = (0, _wordpress_element.useCallback)(() => {
|
|
94
|
+
setSettled({
|
|
95
|
+
url: mediaUrl,
|
|
96
|
+
status: "error"
|
|
97
|
+
});
|
|
98
|
+
}, [mediaUrl]);
|
|
99
|
+
if (!mediaUrl || !isImage) return null;
|
|
100
|
+
if (status === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
101
|
+
className: "media-editor-canvas",
|
|
102
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
103
|
+
className: "media-editor-canvas__error",
|
|
104
|
+
role: "alert",
|
|
105
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: (0, _wordpress_i18n.__)("Failed to load image.") })
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
109
|
+
className: "media-editor-canvas",
|
|
110
|
+
children: [status === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
111
|
+
className: "media-editor-canvas__spinner",
|
|
112
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Spinner, {})
|
|
113
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
114
|
+
className: (0, clsx.default)("media-editor-canvas__cropper", { "is-loaded": status === "loaded" }),
|
|
115
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(______image_editor_index_ts.Cropper, {
|
|
116
|
+
src: mediaUrl,
|
|
117
|
+
controller: session.cropper,
|
|
118
|
+
aspectRatio,
|
|
119
|
+
freeformCrop: true,
|
|
120
|
+
showGrid: "interactive",
|
|
121
|
+
isPlacementActive,
|
|
122
|
+
onGestureStart: handleGestureStart,
|
|
123
|
+
onGestureEnd: handleGestureEnd,
|
|
124
|
+
onImageLoaded: handleImageLoaded,
|
|
125
|
+
onImageError: handleImageError,
|
|
126
|
+
disabled
|
|
127
|
+
})
|
|
128
|
+
})]
|
|
129
|
+
});
|
|
134
130
|
}
|
|
135
|
-
|
|
131
|
+
exports.default = MediaEditorCanvas;
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=index.cjs.map
|