@wordpress/media-editor 0.22.0 → 0.24.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 +34 -0
- package/build/components/media-editor/index.cjs +229 -126
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +41 -11
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +15 -18
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +26 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +13 -12
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +143 -37
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +12 -6
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +41 -74
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +217 -117
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +123 -41
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +12 -7
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +122 -87
- package/build-style/style.css +121 -87
- package/build-types/components/media-editor/index.d.ts +25 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- 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 +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- 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/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +40 -54
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +27 -24
- package/src/components/media-editor/index.tsx +372 -142
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +4 -1
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +195 -37
- package/src/components/media-preview/style.scss +11 -32
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +34 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +162 -242
- package/src/style.scss +2 -1
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -4,14 +4,18 @@ import {
|
|
|
4
4
|
DropdownMenu,
|
|
5
5
|
MenuGroup,
|
|
6
6
|
MenuItem,
|
|
7
|
+
Modal,
|
|
7
8
|
Spinner as WCSpinner,
|
|
8
9
|
__experimentalConfirmDialog as ConfirmDialog,
|
|
9
10
|
__unstableAnimatePresence as AnimatePresence,
|
|
10
11
|
__unstableMotion as motion,
|
|
12
|
+
Slot,
|
|
13
|
+
SlotFillProvider,
|
|
11
14
|
} from '@wordpress/components';
|
|
12
15
|
import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
|
|
16
|
+
import { PluginArea } from '@wordpress/plugins';
|
|
13
17
|
import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
|
|
14
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
18
|
+
import { useDispatch, useRegistry, useSelect } from '@wordpress/data';
|
|
15
19
|
import { store as coreStore } from '@wordpress/core-data';
|
|
16
20
|
import { NavigableRegion } from '@wordpress/admin-ui';
|
|
17
21
|
import {
|
|
@@ -20,10 +24,11 @@ import {
|
|
|
20
24
|
useCallback,
|
|
21
25
|
useContext,
|
|
22
26
|
useEffect,
|
|
27
|
+
useMemo,
|
|
23
28
|
useRef,
|
|
24
29
|
useState,
|
|
25
30
|
} from '@wordpress/element';
|
|
26
|
-
import { __ } from '@wordpress/i18n';
|
|
31
|
+
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
27
32
|
import {
|
|
28
33
|
backup,
|
|
29
34
|
close,
|
|
@@ -37,14 +42,17 @@ import {
|
|
|
37
42
|
displayShortcut,
|
|
38
43
|
isAppleOS,
|
|
39
44
|
isKeyboardEvent,
|
|
45
|
+
withIgnoreIMEEvents,
|
|
40
46
|
} from '@wordpress/keycodes';
|
|
41
47
|
import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
|
|
42
|
-
import
|
|
48
|
+
import { inertValue } from '@wordpress/react-inert-value';
|
|
49
|
+
import type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';
|
|
43
50
|
import type {
|
|
44
51
|
KeyboardEvent as ReactKeyboardEvent,
|
|
45
52
|
ReactElement,
|
|
46
53
|
ReactNode,
|
|
47
54
|
} from 'react';
|
|
55
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
48
56
|
import { MediaEditorProvider } from '../media-editor-provider';
|
|
49
57
|
import type { Media } from '../media-editor-provider';
|
|
50
58
|
import MediaPreview from '../media-preview';
|
|
@@ -53,9 +61,15 @@ import MediaEditorFineRotation from '../media-editor-fine-rotation';
|
|
|
53
61
|
import MediaEditorCropPanel from '../media-editor-crop-panel';
|
|
54
62
|
import MediaEditorImageControls from '../media-editor-image-controls';
|
|
55
63
|
import MediaForm from '../media-form';
|
|
64
|
+
import MediaEditorPanel, {
|
|
65
|
+
MEDIA_EDITOR_PLUGIN_SCOPE,
|
|
66
|
+
MediaEditorPanelsProvider,
|
|
67
|
+
getPanelSlotName,
|
|
68
|
+
useMediaEditorPanels,
|
|
69
|
+
type MediaEditorPanelFillProps,
|
|
70
|
+
} from '../media-editor-panel';
|
|
56
71
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
57
72
|
import { MediaEditorStateProvider, useMediaEditor } from '../../state';
|
|
58
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
59
73
|
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
60
74
|
import MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';
|
|
61
75
|
import {
|
|
@@ -75,15 +89,18 @@ const ATTACHMENT_EMBED_QUERY = { _embed: 'author,wp:attached-to' } as const;
|
|
|
75
89
|
const PLACEMENT_CONTROL_IDLE_MS = 300;
|
|
76
90
|
|
|
77
91
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
92
|
+
* The Details panel's id. Every media type has this panel, so the sidebar
|
|
93
|
+
* shows it when the requested panel doesn't exist.
|
|
94
|
+
*
|
|
95
|
+
* The sidebar stores the open panel's id, so adding a panel only needs a new
|
|
96
|
+
* id and a new tab.
|
|
82
97
|
*/
|
|
83
|
-
const DETAILS_PANEL = 'details';
|
|
98
|
+
const DETAILS_PANEL = 'core/details';
|
|
84
99
|
|
|
85
100
|
/** Identifier for the crop panel. Images only; other media has nothing to crop. */
|
|
86
|
-
const CROP_PANEL = 'crop';
|
|
101
|
+
const CROP_PANEL = 'core/crop';
|
|
102
|
+
|
|
103
|
+
const CROP_MEDIA_TYPES = [ 'image' ] as const;
|
|
87
104
|
|
|
88
105
|
// Matches the editor's sidebar in `ComplementaryArea`.
|
|
89
106
|
const SIDEBAR_ANIMATION_DURATION = 0.3;
|
|
@@ -143,10 +160,20 @@ export interface MediaEditorProps {
|
|
|
143
160
|
aspectRatioPresets?: AspectRatioPreset[];
|
|
144
161
|
onClose?: () => void;
|
|
145
162
|
onSaved?: ( result: MediaEditorSaveResult ) => void;
|
|
163
|
+
/** Called with the original's id when the user chooses "Edit original". */
|
|
164
|
+
onEditOriginal?: ( originalId: number ) => void;
|
|
146
165
|
renderFrame: ( props: MediaEditorFrameProps ) => ReactElement;
|
|
147
166
|
noticesClassName?: string;
|
|
148
167
|
noticesPortalElement?: Element | null;
|
|
149
168
|
shouldCloseOnEsc?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* The id of the panel to open on, which is also shown as the first tab.
|
|
171
|
+
* Below `small`, or when no tab has this id, the sidebar opens on
|
|
172
|
+
* Details.
|
|
173
|
+
*
|
|
174
|
+
* @default 'core/details'
|
|
175
|
+
*/
|
|
176
|
+
defaultPanel?: string;
|
|
150
177
|
}
|
|
151
178
|
|
|
152
179
|
interface MediaEditorSidebarProps {
|
|
@@ -206,6 +233,10 @@ function MediaEditorSidebar( {
|
|
|
206
233
|
value={ tab.id }
|
|
207
234
|
tabIndex={ -1 }
|
|
208
235
|
className="media-editor__panel"
|
|
236
|
+
// A save reads the session once and then waits, so
|
|
237
|
+
// nothing in the panel may act on it meanwhile.
|
|
238
|
+
// `inert` covers panels that ignore `disabled`.
|
|
239
|
+
inert={ inertValue( disabled ) }
|
|
209
240
|
>
|
|
210
241
|
<Stack direction="column" gap="lg">
|
|
211
242
|
{ tab.render() }
|
|
@@ -248,11 +279,16 @@ interface MediaEditorFrameContextValue {
|
|
|
248
279
|
canRestoreOriginal: boolean;
|
|
249
280
|
/**
|
|
250
281
|
* When `true`, another attachment has replaced the edited one in the
|
|
251
|
-
*
|
|
282
|
+
* image editor this session (today, only the original), so the menu item is
|
|
252
283
|
* disabled.
|
|
253
284
|
*/
|
|
254
285
|
isSourceReplaced: boolean;
|
|
255
|
-
/**
|
|
286
|
+
/** Whether the frame opens the original itself. */
|
|
287
|
+
opensOriginal: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* Load the lineage root into the image editor, or hand it to the
|
|
290
|
+
* frame.
|
|
291
|
+
*/
|
|
256
292
|
onRestoreOriginal: () => void;
|
|
257
293
|
}
|
|
258
294
|
|
|
@@ -276,6 +312,20 @@ function useMediaEditorFrameContext(): MediaEditorFrameContextValue {
|
|
|
276
312
|
return context;
|
|
277
313
|
}
|
|
278
314
|
|
|
315
|
+
function CropPanelContent( { disabled }: MediaEditorPanelFillProps ) {
|
|
316
|
+
const { aspectRatioPresets } = useMediaEditorFrameContext();
|
|
317
|
+
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
318
|
+
useCropOptions( { aspectRatioPresets } );
|
|
319
|
+
return (
|
|
320
|
+
<MediaEditorCropPanel
|
|
321
|
+
aspectRatioValue={ aspectRatioValue }
|
|
322
|
+
onAspectRatioChange={ setAspectRatioValue }
|
|
323
|
+
aspectRatioOptions={ aspectRatioOptions }
|
|
324
|
+
disabled={ disabled }
|
|
325
|
+
/>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
279
329
|
export interface HeaderActionsProps {
|
|
280
330
|
/**
|
|
281
331
|
* Whether to include a Close button. Frames with a dismissal affordance of
|
|
@@ -307,10 +357,75 @@ function PanelToggle() {
|
|
|
307
357
|
);
|
|
308
358
|
}
|
|
309
359
|
|
|
310
|
-
function
|
|
311
|
-
|
|
360
|
+
function getActionLabel( action: Action< Media >, items: Media[] ) {
|
|
361
|
+
return typeof action.label === 'string'
|
|
362
|
+
? action.label
|
|
363
|
+
: action.label( items );
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
interface MediaActionModalProps {
|
|
367
|
+
action: ActionModal< Media >;
|
|
368
|
+
items: Media[];
|
|
369
|
+
closeModal: () => void;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't
|
|
373
|
+
// exported. It could be replaced if dataviews exports it.
|
|
374
|
+
function MediaActionModal( {
|
|
375
|
+
action,
|
|
376
|
+
items,
|
|
377
|
+
closeModal,
|
|
378
|
+
}: MediaActionModalProps ) {
|
|
379
|
+
const header =
|
|
380
|
+
typeof action.modalHeader === 'function'
|
|
381
|
+
? action.modalHeader( items )
|
|
382
|
+
: action.modalHeader;
|
|
383
|
+
return (
|
|
384
|
+
<Modal
|
|
385
|
+
title={ header || getActionLabel( action, items ) }
|
|
386
|
+
__experimentalHideHeader={ !! action.hideModalHeader }
|
|
387
|
+
onRequestClose={ closeModal }
|
|
388
|
+
focusOnMount={ action.modalFocusOnMount ?? true }
|
|
389
|
+
size={ action.modalSize || 'medium' }
|
|
390
|
+
>
|
|
391
|
+
<action.RenderModal items={ items } closeModal={ closeModal } />
|
|
392
|
+
</Modal>
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface MoreMenuProps {
|
|
397
|
+
/**
|
|
398
|
+
* Actions for the attachment, such as those from the entity actions API.
|
|
399
|
+
* Only the ones whose `isEligible` passes for `item` are shown.
|
|
400
|
+
*/
|
|
401
|
+
actions?: Action< Media >[];
|
|
402
|
+
/**
|
|
403
|
+
* The attachment the actions apply to, with anything their `isEligible`
|
|
404
|
+
* checks need, such as `permissions`. Without it no actions are shown.
|
|
405
|
+
*/
|
|
406
|
+
item?: Media;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function MoreMenu( { actions = [], item }: MoreMenuProps ) {
|
|
410
|
+
const { isImage, isSaving } = useMediaEditorFrameContext();
|
|
411
|
+
const registry = useRegistry();
|
|
312
412
|
const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
|
|
313
|
-
|
|
413
|
+
const [ activeModalAction, setActiveModalAction ] =
|
|
414
|
+
useState< ActionModal< Media > | null >( null );
|
|
415
|
+
|
|
416
|
+
const items = item ? [ item ] : [];
|
|
417
|
+
const eligibleActions = useMemo(
|
|
418
|
+
() =>
|
|
419
|
+
item
|
|
420
|
+
? actions.filter(
|
|
421
|
+
( action ) =>
|
|
422
|
+
! action.isEligible || action.isEligible( item )
|
|
423
|
+
)
|
|
424
|
+
: [],
|
|
425
|
+
[ actions, item ]
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
if ( ! isImage && ! eligibleActions.length ) {
|
|
314
429
|
return null;
|
|
315
430
|
}
|
|
316
431
|
return (
|
|
@@ -321,18 +436,63 @@ function MoreMenu() {
|
|
|
321
436
|
toggleProps={ { size: 'compact' } }
|
|
322
437
|
>
|
|
323
438
|
{ ( { onClose: closeMenu } ) => (
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
439
|
+
<>
|
|
440
|
+
{ isImage && (
|
|
441
|
+
<MenuGroup>
|
|
442
|
+
<MenuItem
|
|
443
|
+
icon={ keyboard }
|
|
444
|
+
iconPosition="left"
|
|
445
|
+
onClick={ () => {
|
|
446
|
+
setIsShortcutsModalOpen( true );
|
|
447
|
+
closeMenu();
|
|
448
|
+
} }
|
|
449
|
+
>
|
|
450
|
+
{ __( 'Keyboard shortcuts' ) }
|
|
451
|
+
</MenuItem>
|
|
452
|
+
</MenuGroup>
|
|
453
|
+
) }
|
|
454
|
+
{ !! eligibleActions.length && (
|
|
455
|
+
<MenuGroup>
|
|
456
|
+
{ eligibleActions.map( ( action ) => {
|
|
457
|
+
const label = getActionLabel(
|
|
458
|
+
action,
|
|
459
|
+
items
|
|
460
|
+
);
|
|
461
|
+
return (
|
|
462
|
+
<MenuItem
|
|
463
|
+
key={ action.id }
|
|
464
|
+
disabled={
|
|
465
|
+
isSaving || action.disabled
|
|
466
|
+
}
|
|
467
|
+
onClick={ () => {
|
|
468
|
+
closeMenu();
|
|
469
|
+
if ( 'RenderModal' in action ) {
|
|
470
|
+
setActiveModalAction(
|
|
471
|
+
action
|
|
472
|
+
);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
action.callback( items, {
|
|
476
|
+
registry,
|
|
477
|
+
} );
|
|
478
|
+
} }
|
|
479
|
+
>
|
|
480
|
+
{ 'RenderModal' in action
|
|
481
|
+
? sprintf(
|
|
482
|
+
/* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */
|
|
483
|
+
_x(
|
|
484
|
+
'%s…',
|
|
485
|
+
'menu item requiring further input'
|
|
486
|
+
),
|
|
487
|
+
label
|
|
488
|
+
)
|
|
489
|
+
: label }
|
|
490
|
+
</MenuItem>
|
|
491
|
+
);
|
|
492
|
+
} ) }
|
|
493
|
+
</MenuGroup>
|
|
494
|
+
) }
|
|
495
|
+
</>
|
|
336
496
|
) }
|
|
337
497
|
</DropdownMenu>
|
|
338
498
|
{ isShortcutsModalOpen && (
|
|
@@ -340,6 +500,13 @@ function MoreMenu() {
|
|
|
340
500
|
onClose={ () => setIsShortcutsModalOpen( false ) }
|
|
341
501
|
/>
|
|
342
502
|
) }
|
|
503
|
+
{ activeModalAction && (
|
|
504
|
+
<MediaActionModal
|
|
505
|
+
action={ activeModalAction }
|
|
506
|
+
items={ items }
|
|
507
|
+
closeModal={ () => setActiveModalAction( null ) }
|
|
508
|
+
/>
|
|
509
|
+
) }
|
|
343
510
|
</>
|
|
344
511
|
);
|
|
345
512
|
}
|
|
@@ -378,6 +545,7 @@ function HistoryActions() {
|
|
|
378
545
|
activePanel,
|
|
379
546
|
canRestoreOriginal,
|
|
380
547
|
isSourceReplaced,
|
|
548
|
+
opensOriginal,
|
|
381
549
|
onRestoreOriginal,
|
|
382
550
|
} = useMediaEditorFrameContext();
|
|
383
551
|
const {
|
|
@@ -482,7 +650,9 @@ function HistoryActions() {
|
|
|
482
650
|
closeMenu();
|
|
483
651
|
} }
|
|
484
652
|
>
|
|
485
|
-
{
|
|
653
|
+
{ opensOriginal
|
|
654
|
+
? __( 'Edit original' )
|
|
655
|
+
: __( 'Restore original' ) }
|
|
486
656
|
</MenuItem>
|
|
487
657
|
</MenuGroup>
|
|
488
658
|
) }
|
|
@@ -546,10 +716,12 @@ function MediaEditorContent( {
|
|
|
546
716
|
aspectRatioPresets,
|
|
547
717
|
onClose,
|
|
548
718
|
onSaved,
|
|
719
|
+
onEditOriginal,
|
|
549
720
|
renderFrame,
|
|
550
721
|
noticesClassName = 'media-editor__snackbar',
|
|
551
722
|
noticesPortalElement,
|
|
552
723
|
shouldCloseOnEsc = false,
|
|
724
|
+
defaultPanel = DETAILS_PANEL,
|
|
553
725
|
}: MediaEditorProps ) {
|
|
554
726
|
const session = useMediaEditor();
|
|
555
727
|
// Width decides whether the settings panel docks beside the canvas or
|
|
@@ -601,17 +773,33 @@ function MediaEditorContent( {
|
|
|
601
773
|
|
|
602
774
|
const { clearEntityRecordEdits, editEntityRecord, invalidateResolution } =
|
|
603
775
|
useDispatch( coreStore );
|
|
604
|
-
const { removeAllNotices } = useDispatch( noticesStore );
|
|
776
|
+
const { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );
|
|
777
|
+
// `PluginArea` drops a plugin whose render throws; tell the user.
|
|
778
|
+
const handlePluginError = useCallback(
|
|
779
|
+
( name: string ) => {
|
|
780
|
+
createErrorNotice(
|
|
781
|
+
sprintf(
|
|
782
|
+
/* translators: %s: plugin name */
|
|
783
|
+
__(
|
|
784
|
+
'The "%s" plugin has encountered an error and cannot be rendered.'
|
|
785
|
+
),
|
|
786
|
+
name
|
|
787
|
+
),
|
|
788
|
+
{ type: 'snackbar', context: MEDIA_EDITOR_NOTICES_CONTEXT }
|
|
789
|
+
);
|
|
790
|
+
},
|
|
791
|
+
[ createErrorNotice ]
|
|
792
|
+
);
|
|
605
793
|
|
|
606
794
|
const [ isDiscardDialogOpen, setIsDiscardDialogOpen ] = useState( false );
|
|
607
795
|
const [ isPlacementActive, setIsPlacementActive ] = useState( false );
|
|
608
796
|
const [ isCanvasGestureActive, setIsCanvasGestureActive ] =
|
|
609
797
|
useState( false );
|
|
610
|
-
// Whether another attachment has replaced `id` in the
|
|
798
|
+
// Whether another attachment has replaced `id` in the image editor this
|
|
611
799
|
// session (today, the original via "Restore original image"). Stays a
|
|
612
|
-
// distinct flag (not derived from the
|
|
800
|
+
// distinct flag (not derived from the image editor) so a bare replacement
|
|
613
801
|
// counts as a change even though swapping the source resets the
|
|
614
|
-
//
|
|
802
|
+
// image editor's own dirty baseline.
|
|
615
803
|
const [ isSourceReplaced, setIsSourceReplaced ] = useState( false );
|
|
616
804
|
const placementControlTimerRef = useRef<
|
|
617
805
|
ReturnType< typeof setTimeout > | undefined
|
|
@@ -642,7 +830,7 @@ function MediaEditorContent( {
|
|
|
642
830
|
// exposed by the server as the root-level `edit_root` id on the
|
|
643
831
|
// attachment (edit context, embeddable via the `wp:edit-root` link).
|
|
644
832
|
// Fetch the original's record for the URL and natural dimensions the
|
|
645
|
-
//
|
|
833
|
+
// image editor needs to seed itself.
|
|
646
834
|
const originalId: number | undefined = sourceMedia?.edit_root;
|
|
647
835
|
const originalRecord = useSelect(
|
|
648
836
|
( select ) =>
|
|
@@ -727,22 +915,25 @@ function MediaEditorContent( {
|
|
|
727
915
|
// Restoring discards every pending edit, as the menu item says, so
|
|
728
916
|
// nothing staged against the attachment being replaced reaches a save.
|
|
729
917
|
clearEntityRecordEdits( 'postType', 'attachment', id );
|
|
918
|
+
if ( onEditOriginal && originalId ) {
|
|
919
|
+
onEditOriginal( originalId );
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
730
922
|
setIsSourceReplaced( true );
|
|
731
|
-
}, [ clearEntityRecordEdits, id ] );
|
|
923
|
+
}, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );
|
|
732
924
|
|
|
733
|
-
// A bare replacement has no
|
|
925
|
+
// A bare replacement has no image editor change, so OR the flag in explicitly.
|
|
926
|
+
// Nothing saves named edits (`session.edits`), so `hasOutputEdits` leaves
|
|
927
|
+
// them out: counting them would enable Save for a change it then drops.
|
|
734
928
|
const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
|
|
735
929
|
|
|
736
930
|
const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
|
|
737
931
|
const isImage = !! media && mediaType === 'image';
|
|
738
932
|
|
|
739
|
-
//
|
|
740
|
-
//
|
|
741
|
-
// the
|
|
742
|
-
|
|
743
|
-
// all (see `tabs`), so it always gets Details.
|
|
744
|
-
const currentTab =
|
|
745
|
-
chosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );
|
|
933
|
+
// Below `small` the panel covers the canvas, so open on Details rather
|
|
934
|
+
// than a panel that needs the canvas in view. If no tab matches
|
|
935
|
+
// `defaultPanel`, the sidebar shows Details (see `activeTab` below).
|
|
936
|
+
const currentTab = chosenTab ?? ( isWide ? defaultPanel : DETAILS_PANEL );
|
|
746
937
|
// `null` when nothing is open, otherwise the open panel's id. Until the
|
|
747
938
|
// user opens or closes the panel, follow the breakpoint: dragging a window
|
|
748
939
|
// narrow hands the canvas the full width instead of leaving a panel
|
|
@@ -763,8 +954,6 @@ function MediaEditorContent( {
|
|
|
763
954
|
const togglePanel = useCallback( () => {
|
|
764
955
|
setChosenPanel( activePanel ? null : currentTab );
|
|
765
956
|
}, [ activePanel, currentTab ] );
|
|
766
|
-
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
767
|
-
useCropOptions( { aspectRatioPresets } );
|
|
768
957
|
const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
|
|
769
958
|
session,
|
|
770
959
|
id,
|
|
@@ -804,45 +993,47 @@ function MediaEditorContent( {
|
|
|
804
993
|
discardAndClose();
|
|
805
994
|
};
|
|
806
995
|
|
|
807
|
-
const handleKeyDown = (
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
target.tagName === '
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
996
|
+
const handleKeyDown = withIgnoreIMEEvents(
|
|
997
|
+
( event: ReactKeyboardEvent< HTMLElement > ) => {
|
|
998
|
+
const isUndoShortcut = isKeyboardEvent.primary( event, 'z' );
|
|
999
|
+
const isRedoShortcut =
|
|
1000
|
+
isKeyboardEvent.primaryShift( event, 'z' ) ||
|
|
1001
|
+
( ! isAppleOS() && isKeyboardEvent.primary( event, 'y' ) );
|
|
1002
|
+
if ( ( isUndoShortcut || isRedoShortcut ) && isImage ) {
|
|
1003
|
+
const target = event.target as HTMLElement;
|
|
1004
|
+
const isMetadataField =
|
|
1005
|
+
( target.tagName === 'INPUT' ||
|
|
1006
|
+
target.tagName === 'TEXTAREA' ||
|
|
1007
|
+
target.isContentEditable ) &&
|
|
1008
|
+
! target.closest( `[${ CROP_CONTROL_ATTR }]` );
|
|
1009
|
+
if ( ! isMetadataField ) {
|
|
1010
|
+
event.preventDefault();
|
|
1011
|
+
if ( isCropInteractionActive || isSaving ) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if ( isRedoShortcut ) {
|
|
1015
|
+
session.redo();
|
|
1016
|
+
} else {
|
|
1017
|
+
session.undo();
|
|
1018
|
+
}
|
|
828
1019
|
}
|
|
829
1020
|
}
|
|
830
|
-
}
|
|
831
1021
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1022
|
+
if ( shouldCloseOnEsc ) {
|
|
1023
|
+
if ( event.code !== 'Escape' && event.key !== 'Escape' ) {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
if ( isSaving ) {
|
|
1027
|
+
event.preventDefault();
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if ( hasChanges ) {
|
|
1031
|
+
event.preventDefault();
|
|
1032
|
+
setIsDiscardDialogOpen( true );
|
|
1033
|
+
}
|
|
843
1034
|
}
|
|
844
1035
|
}
|
|
845
|
-
|
|
1036
|
+
);
|
|
846
1037
|
|
|
847
1038
|
const snackbar = (
|
|
848
1039
|
<SnackbarNotices
|
|
@@ -865,32 +1056,31 @@ function MediaEditorContent( {
|
|
|
865
1056
|
/>
|
|
866
1057
|
) : null;
|
|
867
1058
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
];
|
|
1059
|
+
const { panels, contextValue: panelsContextValue } = useMediaEditorPanels();
|
|
1060
|
+
const availableTabs: MediaEditorTab[] = panels
|
|
1061
|
+
.filter(
|
|
1062
|
+
( panel ) =>
|
|
1063
|
+
! panel.mediaTypes || panel.mediaTypes.includes( mediaType )
|
|
1064
|
+
)
|
|
1065
|
+
.map( ( panel ) => ( {
|
|
1066
|
+
id: panel.name,
|
|
1067
|
+
title: panel.title,
|
|
1068
|
+
render: () => (
|
|
1069
|
+
<Slot
|
|
1070
|
+
bubblesVirtually
|
|
1071
|
+
name={ getPanelSlotName( panel.name ) }
|
|
1072
|
+
fillProps={ { disabled: isSaving } }
|
|
1073
|
+
/>
|
|
1074
|
+
),
|
|
1075
|
+
} ) );
|
|
1076
|
+
// Put the default panel first and keep the others in order.
|
|
1077
|
+
const defaultTab = availableTabs.find( ( tab ) => tab.id === defaultPanel );
|
|
1078
|
+
const tabs = defaultTab
|
|
1079
|
+
? [
|
|
1080
|
+
defaultTab,
|
|
1081
|
+
...availableTabs.filter( ( tab ) => tab !== defaultTab ),
|
|
1082
|
+
]
|
|
1083
|
+
: availableTabs;
|
|
894
1084
|
|
|
895
1085
|
const ruler = isImage ? (
|
|
896
1086
|
<MediaEditorFineRotation
|
|
@@ -900,23 +1090,7 @@ function MediaEditorContent( {
|
|
|
900
1090
|
) : null;
|
|
901
1091
|
|
|
902
1092
|
const children = (
|
|
903
|
-
|
|
904
|
-
value={ media ?? undefined }
|
|
905
|
-
onChange={ handleChange }
|
|
906
|
-
settings={ {
|
|
907
|
-
// Disable the fields while saving, so the guard in
|
|
908
|
-
// `handleChange` is not silently swallowing typing.
|
|
909
|
-
// `readOnly` would swap the field's layout mid-save;
|
|
910
|
-
// disabled keeps it in place and greys it out.
|
|
911
|
-
fields: isSaving
|
|
912
|
-
? fields.map( ( field ) => ( {
|
|
913
|
-
...field,
|
|
914
|
-
isDisabled: true,
|
|
915
|
-
} ) )
|
|
916
|
-
: fields,
|
|
917
|
-
form,
|
|
918
|
-
} }
|
|
919
|
-
>
|
|
1093
|
+
<>
|
|
920
1094
|
<div className="media-editor">
|
|
921
1095
|
{ ! media ? (
|
|
922
1096
|
<div className="media-editor__loading">
|
|
@@ -970,25 +1144,31 @@ function MediaEditorContent( {
|
|
|
970
1144
|
exit="closed"
|
|
971
1145
|
transition={ sidebarTransition }
|
|
972
1146
|
>
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1147
|
+
{ /* Panels announce their tabs after the
|
|
1148
|
+
first render. Waiting for them outside
|
|
1149
|
+
this container would slide it in on
|
|
1150
|
+
every open. */ }
|
|
1151
|
+
{ tabs.length > 0 && (
|
|
1152
|
+
<MediaEditorSidebar
|
|
1153
|
+
tabs={ tabs }
|
|
1154
|
+
// Swapping the edited media can drop the
|
|
1155
|
+
// Crop tab out from under an open panel —
|
|
1156
|
+
// saving a crop moves the editor to a new
|
|
1157
|
+
// id, which may resolve as non-image.
|
|
1158
|
+
// Fall back rather than hand `Tabs.Root`
|
|
1159
|
+
// a value no tab matches.
|
|
1160
|
+
activeTab={
|
|
1161
|
+
tabs.some(
|
|
1162
|
+
( tab ) =>
|
|
1163
|
+
tab.id === activePanel
|
|
1164
|
+
)
|
|
1165
|
+
? activePanel
|
|
1166
|
+
: DETAILS_PANEL
|
|
1167
|
+
}
|
|
1168
|
+
onSelectTab={ selectPanel }
|
|
1169
|
+
disabled={ isSaving }
|
|
1170
|
+
/>
|
|
1171
|
+
) }
|
|
992
1172
|
</motion.div>
|
|
993
1173
|
) }
|
|
994
1174
|
</AnimatePresence>
|
|
@@ -1012,7 +1192,7 @@ function MediaEditorContent( {
|
|
|
1012
1192
|
{ noticesPortalElement
|
|
1013
1193
|
? createPortal( snackbar, noticesPortalElement )
|
|
1014
1194
|
: snackbar }
|
|
1015
|
-
|
|
1195
|
+
</>
|
|
1016
1196
|
);
|
|
1017
1197
|
|
|
1018
1198
|
// Rebuilt each render, like the elements it replaces: consumers re-render
|
|
@@ -1034,13 +1214,63 @@ function MediaEditorContent( {
|
|
|
1034
1214
|
onSave: saveMediaEditor,
|
|
1035
1215
|
canRestoreOriginal,
|
|
1036
1216
|
isSourceReplaced,
|
|
1217
|
+
opensOriginal: !! onEditOriginal,
|
|
1037
1218
|
onRestoreOriginal: handleRestoreOriginal,
|
|
1038
1219
|
};
|
|
1039
1220
|
|
|
1040
1221
|
return (
|
|
1041
1222
|
<MediaEditorFrameContext.Provider value={ contextValue }>
|
|
1042
1223
|
{ renderFrame( {
|
|
1043
|
-
children
|
|
1224
|
+
children: (
|
|
1225
|
+
<MediaEditorProvider
|
|
1226
|
+
value={ media ?? undefined }
|
|
1227
|
+
onChange={ handleChange }
|
|
1228
|
+
settings={ {
|
|
1229
|
+
// Disable the fields while saving, so the guard in
|
|
1230
|
+
// `handleChange` is not silently swallowing typing.
|
|
1231
|
+
// `readOnly` would swap the field's layout mid-save;
|
|
1232
|
+
// disabled keeps it in place and greys it out.
|
|
1233
|
+
fields: isSaving
|
|
1234
|
+
? fields.map( ( field ) => ( {
|
|
1235
|
+
...field,
|
|
1236
|
+
isDisabled: true,
|
|
1237
|
+
} ) )
|
|
1238
|
+
: fields,
|
|
1239
|
+
form,
|
|
1240
|
+
} }
|
|
1241
|
+
>
|
|
1242
|
+
<SlotFillProvider>
|
|
1243
|
+
<MediaEditorPanelsProvider
|
|
1244
|
+
value={ panelsContextValue }
|
|
1245
|
+
>
|
|
1246
|
+
{ /* Inside the session and `MediaEditorProvider`, so
|
|
1247
|
+
panel content can read both. */ }
|
|
1248
|
+
<MediaEditorPanel
|
|
1249
|
+
name={ CROP_PANEL }
|
|
1250
|
+
title={ __( 'Crop' ) }
|
|
1251
|
+
mediaTypes={ CROP_MEDIA_TYPES }
|
|
1252
|
+
>
|
|
1253
|
+
{ ( { disabled } ) => (
|
|
1254
|
+
<CropPanelContent
|
|
1255
|
+
disabled={ disabled }
|
|
1256
|
+
/>
|
|
1257
|
+
) }
|
|
1258
|
+
</MediaEditorPanel>
|
|
1259
|
+
<MediaEditorPanel
|
|
1260
|
+
name={ DETAILS_PANEL }
|
|
1261
|
+
title={ __( 'Details' ) }
|
|
1262
|
+
>
|
|
1263
|
+
<MediaForm />
|
|
1264
|
+
</MediaEditorPanel>
|
|
1265
|
+
<PluginArea
|
|
1266
|
+
scope={ MEDIA_EDITOR_PLUGIN_SCOPE }
|
|
1267
|
+
onError={ handlePluginError }
|
|
1268
|
+
/>
|
|
1269
|
+
{ children }
|
|
1270
|
+
</MediaEditorPanelsProvider>
|
|
1271
|
+
</SlotFillProvider>
|
|
1272
|
+
</MediaEditorProvider>
|
|
1273
|
+
),
|
|
1044
1274
|
isImage,
|
|
1045
1275
|
layout,
|
|
1046
1276
|
onRequestClose: handleRequestClose,
|