@wordpress/media-editor 0.21.0 → 0.23.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 +30 -0
- package/build/components/media-editor/index.cjs +586 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +42 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +131 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +117 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +81 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +61 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +181 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +82 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +113 -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/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 +59 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +100 -113
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +22 -45
- 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 +11 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +227 -296
- 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 +545 -675
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +37 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +95 -98
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +171 -238
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +74 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -90
- 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/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 +53 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +80 -91
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +3 -26
- 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 +7 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +223 -288
- 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 +145 -61
- package/build-style/style.css +144 -61
- package/build-types/components/media-editor/index.d.ts +20 -2
- 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-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/state/aspect-ratio-presets.d.ts +24 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- 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 -4
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -63
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +355 -167
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +9 -10
- package/src/components/media-editor/use-save-media-editor.ts +48 -10
- package/src/components/media-editor-canvas/index.tsx +30 -51
- 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 +15 -11
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +65 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +9 -5
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +37 -0
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -17
- package/src/state/types.ts +18 -72
- package/src/state/use-media-editor-state.ts +155 -238
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
- package/build/image-editor/core/camera.cjs +0 -225
- package/build/image-editor/core/camera.cjs.map +0 -7
- package/build/image-editor/core/constants.cjs +0 -108
- package/build/image-editor/core/constants.cjs.map +0 -7
- package/build/image-editor/core/containment.cjs +0 -276
- package/build/image-editor/core/containment.cjs.map +0 -7
- package/build/image-editor/core/crop-rect.cjs +0 -48
- package/build/image-editor/core/crop-rect.cjs.map +0 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
- package/build/image-editor/core/index.cjs +0 -62
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/interaction-controller.cjs +0 -654
- package/build/image-editor/core/interaction-controller.cjs.map +0 -7
- package/build/image-editor/core/math/rotation.cjs +0 -41
- package/build/image-editor/core/math/rotation.cjs.map +0 -7
- package/build/image-editor/core/math/sanitize.cjs +0 -92
- package/build/image-editor/core/math/sanitize.cjs.map +0 -7
- package/build/image-editor/core/setter-helpers.cjs +0 -64
- package/build/image-editor/core/setter-helpers.cjs.map +0 -7
- package/build/image-editor/core/source-region.cjs +0 -206
- package/build/image-editor/core/source-region.cjs.map +0 -7
- package/build/image-editor/core/state.cjs +0 -283
- package/build/image-editor/core/state.cjs.map +0 -7
- package/build/image-editor/core/stencil-math.cjs +0 -216
- package/build/image-editor/core/stencil-math.cjs.map +0 -7
- package/build/image-editor/core/transform-style.cjs +0 -52
- package/build/image-editor/core/transform-style.cjs.map +0 -7
- package/build/image-editor/core/transforms/pipeline.cjs +0 -43
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
- package/build/image-editor/core/types.cjs +0 -19
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/core/viewport-state.cjs +0 -50
- package/build/image-editor/core/viewport-state.cjs.map +0 -7
- package/build/image-editor/index.cjs +0 -67
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/cropper-provider.cjs +0 -50
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
- package/build/image-editor/react/components/cropper.cjs +0 -722
- package/build/image-editor/react/components/cropper.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs +0 -36
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
- package/build/image-editor/react/components/viewport-provider.cjs +0 -51
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs +0 -34
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
- package/build/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.cjs +0 -213
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
- package/build/image-editor/react/visually-hidden-style.cjs +0 -41
- package/build/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.mjs +0 -66
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
- package/build-module/image-editor/core/camera.mjs +0 -198
- package/build-module/image-editor/core/camera.mjs.map +0 -7
- package/build-module/image-editor/core/constants.mjs +0 -69
- package/build-module/image-editor/core/constants.mjs.map +0 -7
- package/build-module/image-editor/core/containment.mjs +0 -253
- package/build-module/image-editor/core/containment.mjs.map +0 -7
- package/build-module/image-editor/core/crop-rect.mjs +0 -23
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
- package/build-module/image-editor/core/index.mjs +0 -36
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -635
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
- package/build-module/image-editor/core/math/rotation.mjs +0 -15
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
- package/build-module/image-editor/core/math/sanitize.mjs +0 -63
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
- package/build-module/image-editor/core/setter-helpers.mjs +0 -39
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
- package/build-module/image-editor/core/source-region.mjs +0 -178
- package/build-module/image-editor/core/source-region.mjs.map +0 -7
- package/build-module/image-editor/core/state.mjs +0 -260
- package/build-module/image-editor/core/state.mjs.map +0 -7
- package/build-module/image-editor/core/stencil-math.mjs +0 -187
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
- package/build-module/image-editor/core/transform-style.mjs +0 -27
- package/build-module/image-editor/core/transform-style.mjs.map +0 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/core/viewport-state.mjs +0 -24
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
- package/build-module/image-editor/index.mjs +0 -39
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper.mjs +0 -704
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs +0 -9
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs +0 -8
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
- package/build-module/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.mjs +0 -190
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
- package/build-module/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.d.ts +0 -80
- 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 -99
- 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 -16
- 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 -63
- 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-reducer.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-reducer.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 -161
- 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 -150
- 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 -47
- 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 -52
- 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 -1116
- 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-reducer.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,12 +4,15 @@ import {
|
|
|
4
4
|
DropdownMenu,
|
|
5
5
|
MenuGroup,
|
|
6
6
|
MenuItem,
|
|
7
|
+
Modal,
|
|
7
8
|
Spinner as WCSpinner,
|
|
8
9
|
__experimentalConfirmDialog as ConfirmDialog,
|
|
10
|
+
__unstableAnimatePresence as AnimatePresence,
|
|
11
|
+
__unstableMotion as motion,
|
|
9
12
|
} from '@wordpress/components';
|
|
10
13
|
import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
|
|
11
|
-
import { useViewportMatch } from '@wordpress/compose';
|
|
12
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
14
|
+
import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
|
|
15
|
+
import { useDispatch, useRegistry, useSelect } from '@wordpress/data';
|
|
13
16
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
17
|
import { NavigableRegion } from '@wordpress/admin-ui';
|
|
15
18
|
import {
|
|
@@ -18,10 +21,11 @@ import {
|
|
|
18
21
|
useCallback,
|
|
19
22
|
useContext,
|
|
20
23
|
useEffect,
|
|
24
|
+
useMemo,
|
|
21
25
|
useRef,
|
|
22
26
|
useState,
|
|
23
27
|
} from '@wordpress/element';
|
|
24
|
-
import { __ } from '@wordpress/i18n';
|
|
28
|
+
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
25
29
|
import {
|
|
26
30
|
backup,
|
|
27
31
|
close,
|
|
@@ -37,12 +41,13 @@ import {
|
|
|
37
41
|
isKeyboardEvent,
|
|
38
42
|
} from '@wordpress/keycodes';
|
|
39
43
|
import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
|
|
40
|
-
import type { Field, Form } from '@wordpress/dataviews';
|
|
44
|
+
import type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';
|
|
41
45
|
import type {
|
|
42
46
|
KeyboardEvent as ReactKeyboardEvent,
|
|
43
47
|
ReactElement,
|
|
44
48
|
ReactNode,
|
|
45
49
|
} from 'react';
|
|
50
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
46
51
|
import { MediaEditorProvider } from '../media-editor-provider';
|
|
47
52
|
import type { Media } from '../media-editor-provider';
|
|
48
53
|
import MediaPreview from '../media-preview';
|
|
@@ -53,7 +58,6 @@ import MediaEditorImageControls from '../media-editor-image-controls';
|
|
|
53
58
|
import MediaForm from '../media-form';
|
|
54
59
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
55
60
|
import { MediaEditorStateProvider, useMediaEditor } from '../../state';
|
|
56
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
57
61
|
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
58
62
|
import MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';
|
|
59
63
|
import {
|
|
@@ -83,6 +87,26 @@ const DETAILS_PANEL = 'details';
|
|
|
83
87
|
/** Identifier for the crop panel. Images only; other media has nothing to crop. */
|
|
84
88
|
const CROP_PANEL = 'crop';
|
|
85
89
|
|
|
90
|
+
// Matches the editor's sidebar in `ComplementaryArea`.
|
|
91
|
+
const SIDEBAR_ANIMATION_DURATION = 0.3;
|
|
92
|
+
|
|
93
|
+
type SidebarTransition = {
|
|
94
|
+
type: 'tween';
|
|
95
|
+
duration: number;
|
|
96
|
+
ease: number[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const sidebarVariants = {
|
|
100
|
+
// `auto` leaves the width to the sidebar's stylesheet.
|
|
101
|
+
open: { width: 'auto' },
|
|
102
|
+
// Takes the transition from `AnimatePresence`'s `custom` prop, so a
|
|
103
|
+
// sidebar that is already closing still gets the current one.
|
|
104
|
+
closed: ( transition: SidebarTransition ) => ( {
|
|
105
|
+
width: 0,
|
|
106
|
+
transition,
|
|
107
|
+
} ),
|
|
108
|
+
};
|
|
109
|
+
|
|
86
110
|
interface MediaEditorTab {
|
|
87
111
|
id: string;
|
|
88
112
|
title: string;
|
|
@@ -121,6 +145,8 @@ export interface MediaEditorProps {
|
|
|
121
145
|
aspectRatioPresets?: AspectRatioPreset[];
|
|
122
146
|
onClose?: () => void;
|
|
123
147
|
onSaved?: ( result: MediaEditorSaveResult ) => void;
|
|
148
|
+
/** Called with the original's id when the user chooses "Edit original". */
|
|
149
|
+
onEditOriginal?: ( originalId: number ) => void;
|
|
124
150
|
renderFrame: ( props: MediaEditorFrameProps ) => ReactElement;
|
|
125
151
|
noticesClassName?: string;
|
|
126
152
|
noticesPortalElement?: Element | null;
|
|
@@ -221,16 +247,21 @@ interface MediaEditorFrameContextValue {
|
|
|
221
247
|
onSave: () => void;
|
|
222
248
|
/**
|
|
223
249
|
* When `true`, the media has a lineage root to restore to, so the
|
|
224
|
-
* "Restore original
|
|
250
|
+
* history menu shows its "Restore original" item.
|
|
225
251
|
*/
|
|
226
252
|
canRestoreOriginal: boolean;
|
|
227
253
|
/**
|
|
228
254
|
* When `true`, another attachment has replaced the edited one in the
|
|
229
|
-
*
|
|
255
|
+
* image editor this session (today, only the original), so the menu item is
|
|
230
256
|
* disabled.
|
|
231
257
|
*/
|
|
232
258
|
isSourceReplaced: boolean;
|
|
233
|
-
/**
|
|
259
|
+
/** Whether the frame opens the original itself. */
|
|
260
|
+
opensOriginal: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Load the lineage root into the image editor, or hand it to the
|
|
263
|
+
* frame.
|
|
264
|
+
*/
|
|
234
265
|
onRestoreOriginal: () => void;
|
|
235
266
|
}
|
|
236
267
|
|
|
@@ -264,70 +295,108 @@ export interface HeaderActionsProps {
|
|
|
264
295
|
showCloseButton?: boolean;
|
|
265
296
|
}
|
|
266
297
|
|
|
267
|
-
function
|
|
268
|
-
const {
|
|
269
|
-
isImage,
|
|
270
|
-
isSaving,
|
|
271
|
-
onCancel,
|
|
272
|
-
isWide,
|
|
273
|
-
activePanel,
|
|
274
|
-
onTogglePanel,
|
|
275
|
-
canRestoreOriginal,
|
|
276
|
-
isSourceReplaced,
|
|
277
|
-
onRestoreOriginal,
|
|
278
|
-
} = useMediaEditorFrameContext();
|
|
298
|
+
function PanelToggle() {
|
|
299
|
+
const { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();
|
|
279
300
|
const isPanelOpen = !! activePanel;
|
|
280
|
-
|
|
301
|
+
// The sidebar holds more than one panel, so this opens and closes the
|
|
302
|
+
// sidebar rather than naming a panel: reopening returns to whichever tab
|
|
303
|
+
// was last showing, and the tab strip inside switches between them.
|
|
281
304
|
return (
|
|
282
|
-
<
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
305
|
+
<Button
|
|
306
|
+
size="compact"
|
|
307
|
+
icon={ drawerRight }
|
|
308
|
+
label={ __( 'Media settings' ) }
|
|
309
|
+
isPressed={ isPanelOpen }
|
|
310
|
+
// Only a docked column really expands beside the canvas; below
|
|
311
|
+
// that the panel replaces the view, which the pressed state
|
|
312
|
+
// already describes.
|
|
313
|
+
aria-expanded={ isWide ? isPanelOpen : undefined }
|
|
314
|
+
onClick={ onTogglePanel }
|
|
315
|
+
/>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function getActionLabel( action: Action< Media >, items: Media[] ) {
|
|
320
|
+
return typeof action.label === 'string'
|
|
321
|
+
? action.label
|
|
322
|
+
: action.label( items );
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
interface MediaActionModalProps {
|
|
326
|
+
action: ActionModal< Media >;
|
|
327
|
+
items: Media[];
|
|
328
|
+
closeModal: () => void;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't
|
|
332
|
+
// exported. It could be replaced if dataviews exports it.
|
|
333
|
+
function MediaActionModal( {
|
|
334
|
+
action,
|
|
335
|
+
items,
|
|
336
|
+
closeModal,
|
|
337
|
+
}: MediaActionModalProps ) {
|
|
338
|
+
const header =
|
|
339
|
+
typeof action.modalHeader === 'function'
|
|
340
|
+
? action.modalHeader( items )
|
|
341
|
+
: action.modalHeader;
|
|
342
|
+
return (
|
|
343
|
+
<Modal
|
|
344
|
+
title={ header || getActionLabel( action, items ) }
|
|
345
|
+
__experimentalHideHeader={ !! action.hideModalHeader }
|
|
346
|
+
onRequestClose={ closeModal }
|
|
347
|
+
focusOnMount={ action.modalFocusOnMount ?? true }
|
|
348
|
+
size={ action.modalSize || 'medium' }
|
|
287
349
|
>
|
|
288
|
-
{
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
350
|
+
<action.RenderModal items={ items } closeModal={ closeModal } />
|
|
351
|
+
</Modal>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface MoreMenuProps {
|
|
356
|
+
/**
|
|
357
|
+
* Actions for the attachment, such as those from the entity actions API.
|
|
358
|
+
* Only the ones whose `isEligible` passes for `item` are shown.
|
|
359
|
+
*/
|
|
360
|
+
actions?: Action< Media >[];
|
|
361
|
+
/**
|
|
362
|
+
* The attachment the actions apply to, with anything their `isEligible`
|
|
363
|
+
* checks need, such as `permissions`. Without it no actions are shown.
|
|
364
|
+
*/
|
|
365
|
+
item?: Media;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function MoreMenu( { actions = [], item }: MoreMenuProps ) {
|
|
369
|
+
const { isImage, isSaving } = useMediaEditorFrameContext();
|
|
370
|
+
const registry = useRegistry();
|
|
371
|
+
const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
|
|
372
|
+
const [ activeModalAction, setActiveModalAction ] =
|
|
373
|
+
useState< ActionModal< Media > | null >( null );
|
|
374
|
+
|
|
375
|
+
const items = item ? [ item ] : [];
|
|
376
|
+
const eligibleActions = useMemo(
|
|
377
|
+
() =>
|
|
378
|
+
item
|
|
379
|
+
? actions.filter(
|
|
380
|
+
( action ) =>
|
|
381
|
+
! action.isEligible || action.isEligible( item )
|
|
382
|
+
)
|
|
383
|
+
: [],
|
|
384
|
+
[ actions, item ]
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
if ( ! isImage && ! eligibleActions.length ) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
return (
|
|
391
|
+
<>
|
|
392
|
+
<DropdownMenu
|
|
393
|
+
icon={ moreVertical }
|
|
394
|
+
label={ __( 'More options' ) }
|
|
395
|
+
toggleProps={ { size: 'compact' } }
|
|
396
|
+
>
|
|
397
|
+
{ ( { onClose: closeMenu } ) => (
|
|
398
|
+
<>
|
|
399
|
+
{ isImage && (
|
|
331
400
|
<MenuGroup>
|
|
332
401
|
<MenuItem
|
|
333
402
|
icon={ keyboard }
|
|
@@ -340,10 +409,78 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
|
|
|
340
409
|
{ __( 'Keyboard shortcuts' ) }
|
|
341
410
|
</MenuItem>
|
|
342
411
|
</MenuGroup>
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
412
|
+
) }
|
|
413
|
+
{ !! eligibleActions.length && (
|
|
414
|
+
<MenuGroup>
|
|
415
|
+
{ eligibleActions.map( ( action ) => {
|
|
416
|
+
const label = getActionLabel(
|
|
417
|
+
action,
|
|
418
|
+
items
|
|
419
|
+
);
|
|
420
|
+
return (
|
|
421
|
+
<MenuItem
|
|
422
|
+
key={ action.id }
|
|
423
|
+
disabled={
|
|
424
|
+
isSaving || action.disabled
|
|
425
|
+
}
|
|
426
|
+
onClick={ () => {
|
|
427
|
+
closeMenu();
|
|
428
|
+
if ( 'RenderModal' in action ) {
|
|
429
|
+
setActiveModalAction(
|
|
430
|
+
action
|
|
431
|
+
);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
action.callback( items, {
|
|
435
|
+
registry,
|
|
436
|
+
} );
|
|
437
|
+
} }
|
|
438
|
+
>
|
|
439
|
+
{ 'RenderModal' in action
|
|
440
|
+
? sprintf(
|
|
441
|
+
/* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */
|
|
442
|
+
_x(
|
|
443
|
+
'%s…',
|
|
444
|
+
'menu item requiring further input'
|
|
445
|
+
),
|
|
446
|
+
label
|
|
447
|
+
)
|
|
448
|
+
: label }
|
|
449
|
+
</MenuItem>
|
|
450
|
+
);
|
|
451
|
+
} ) }
|
|
452
|
+
</MenuGroup>
|
|
453
|
+
) }
|
|
454
|
+
</>
|
|
455
|
+
) }
|
|
456
|
+
</DropdownMenu>
|
|
457
|
+
{ isShortcutsModalOpen && (
|
|
458
|
+
<MediaEditorKeyboardShortcutsModal
|
|
459
|
+
onClose={ () => setIsShortcutsModalOpen( false ) }
|
|
460
|
+
/>
|
|
461
|
+
) }
|
|
462
|
+
{ activeModalAction && (
|
|
463
|
+
<MediaActionModal
|
|
464
|
+
action={ activeModalAction }
|
|
465
|
+
items={ items }
|
|
466
|
+
closeModal={ () => setActiveModalAction( null ) }
|
|
467
|
+
/>
|
|
346
468
|
) }
|
|
469
|
+
</>
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
|
|
474
|
+
const { isSaving, onCancel } = useMediaEditorFrameContext();
|
|
475
|
+
return (
|
|
476
|
+
<Stack
|
|
477
|
+
className="media-editor__header-actions"
|
|
478
|
+
justify="flex-end"
|
|
479
|
+
align="center"
|
|
480
|
+
gap="sm"
|
|
481
|
+
>
|
|
482
|
+
<PanelToggle />
|
|
483
|
+
<MoreMenu />
|
|
347
484
|
{ showCloseButton && (
|
|
348
485
|
<Button
|
|
349
486
|
size="compact"
|
|
@@ -354,18 +491,22 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
|
|
|
354
491
|
accessibleWhenDisabled
|
|
355
492
|
/>
|
|
356
493
|
) }
|
|
357
|
-
{ isShortcutsModalOpen && (
|
|
358
|
-
<MediaEditorKeyboardShortcutsModal
|
|
359
|
-
onClose={ () => setIsShortcutsModalOpen( false ) }
|
|
360
|
-
/>
|
|
361
|
-
) }
|
|
362
494
|
</Stack>
|
|
363
495
|
);
|
|
364
496
|
}
|
|
365
497
|
|
|
366
498
|
function HistoryActions() {
|
|
367
|
-
const {
|
|
368
|
-
|
|
499
|
+
const {
|
|
500
|
+
isImage,
|
|
501
|
+
isSaving,
|
|
502
|
+
isUndoRedoDisabled,
|
|
503
|
+
isWide,
|
|
504
|
+
activePanel,
|
|
505
|
+
canRestoreOriginal,
|
|
506
|
+
isSourceReplaced,
|
|
507
|
+
opensOriginal,
|
|
508
|
+
onRestoreOriginal,
|
|
509
|
+
} = useMediaEditorFrameContext();
|
|
369
510
|
const {
|
|
370
511
|
reset,
|
|
371
512
|
isDirty,
|
|
@@ -409,15 +550,6 @@ function HistoryActions() {
|
|
|
409
550
|
align="center"
|
|
410
551
|
gap="sm"
|
|
411
552
|
>
|
|
412
|
-
<Button
|
|
413
|
-
size="compact"
|
|
414
|
-
variant="tertiary"
|
|
415
|
-
disabled={ isUndoRedoDisabled || ! isDirty }
|
|
416
|
-
accessibleWhenDisabled
|
|
417
|
-
onClick={ handleReset }
|
|
418
|
-
>
|
|
419
|
-
{ __( 'Reset' ) }
|
|
420
|
-
</Button>
|
|
421
553
|
<Button
|
|
422
554
|
size="compact"
|
|
423
555
|
icon={ undo }
|
|
@@ -442,6 +574,50 @@ function HistoryActions() {
|
|
|
442
574
|
accessibleWhenDisabled
|
|
443
575
|
onClick={ handleRedo }
|
|
444
576
|
/>
|
|
577
|
+
<DropdownMenu
|
|
578
|
+
icon={ backup }
|
|
579
|
+
label={ __( 'History' ) }
|
|
580
|
+
popoverProps={ { placement: 'top-start' } }
|
|
581
|
+
toggleProps={ {
|
|
582
|
+
size: 'compact',
|
|
583
|
+
disabled:
|
|
584
|
+
isUndoRedoDisabled ||
|
|
585
|
+
( ! isDirty && ! canRestoreOriginal ),
|
|
586
|
+
accessibleWhenDisabled: true,
|
|
587
|
+
} }
|
|
588
|
+
>
|
|
589
|
+
{ ( { onClose: closeMenu } ) => (
|
|
590
|
+
<>
|
|
591
|
+
<MenuGroup>
|
|
592
|
+
<MenuItem
|
|
593
|
+
disabled={ isUndoRedoDisabled || ! isDirty }
|
|
594
|
+
onClick={ () => {
|
|
595
|
+
handleReset();
|
|
596
|
+
closeMenu();
|
|
597
|
+
} }
|
|
598
|
+
>
|
|
599
|
+
{ __( 'Reset image edits' ) }
|
|
600
|
+
</MenuItem>
|
|
601
|
+
</MenuGroup>
|
|
602
|
+
{ canRestoreOriginal && (
|
|
603
|
+
<MenuGroup>
|
|
604
|
+
<MenuItem
|
|
605
|
+
disabled={ isSourceReplaced || isSaving }
|
|
606
|
+
info={ __( 'Discards unsaved changes.' ) }
|
|
607
|
+
onClick={ () => {
|
|
608
|
+
onRestoreOriginal();
|
|
609
|
+
closeMenu();
|
|
610
|
+
} }
|
|
611
|
+
>
|
|
612
|
+
{ opensOriginal
|
|
613
|
+
? __( 'Edit original' )
|
|
614
|
+
: __( 'Restore original' ) }
|
|
615
|
+
</MenuItem>
|
|
616
|
+
</MenuGroup>
|
|
617
|
+
) }
|
|
618
|
+
</>
|
|
619
|
+
) }
|
|
620
|
+
</DropdownMenu>
|
|
445
621
|
</Stack>
|
|
446
622
|
);
|
|
447
623
|
}
|
|
@@ -499,6 +675,7 @@ function MediaEditorContent( {
|
|
|
499
675
|
aspectRatioPresets,
|
|
500
676
|
onClose,
|
|
501
677
|
onSaved,
|
|
678
|
+
onEditOriginal,
|
|
502
679
|
renderFrame,
|
|
503
680
|
noticesClassName = 'media-editor__snackbar',
|
|
504
681
|
noticesPortalElement,
|
|
@@ -518,36 +695,26 @@ function MediaEditorContent( {
|
|
|
518
695
|
// The choice is not carried across openings: the modal is transient, and
|
|
519
696
|
// re-opening with the panel hidden on a wide screen is how #81487 read to
|
|
520
697
|
// people in the first place. Within one opening it does hold — see
|
|
521
|
-
// `
|
|
698
|
+
// `chosenPanel` below.
|
|
522
699
|
const isWide = useViewportMatch( 'small' );
|
|
523
|
-
// `
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
//
|
|
533
|
-
//
|
|
534
|
-
//
|
|
535
|
-
//
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
//
|
|
539
|
-
//
|
|
540
|
-
|
|
541
|
-
// full width.
|
|
542
|
-
const selectPanel = useCallback( ( panel: string ) => {
|
|
543
|
-
hasChosenTabRef.current = true;
|
|
544
|
-
lastPanelRef.current = panel;
|
|
545
|
-
setActivePanel( panel );
|
|
546
|
-
}, [] );
|
|
547
|
-
const togglePanel = useCallback( () => {
|
|
548
|
-
hasChosenPanelRef.current = true;
|
|
549
|
-
setActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );
|
|
550
|
-
}, [] );
|
|
700
|
+
// Below `small` the open panel replaces the canvas instead of sitting
|
|
701
|
+
// beside it, so there is nothing to animate.
|
|
702
|
+
const disableSidebarMotion = useReducedMotion() || ! isWide;
|
|
703
|
+
const sidebarTransition: SidebarTransition = {
|
|
704
|
+
type: 'tween',
|
|
705
|
+
duration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,
|
|
706
|
+
ease: [ 0.6, 0, 0.4, 1 ],
|
|
707
|
+
};
|
|
708
|
+
// Width picks the starting panel, but only until the user opens or closes
|
|
709
|
+
// it. After that their choice holds for the rest of the session: closing
|
|
710
|
+
// the panel and then resizing — or crossing the breakpoint by rotating a
|
|
711
|
+
// tablet — should not reopen something they just dismissed. `undefined`
|
|
712
|
+
// until then, otherwise `null` for closed or the open panel's id.
|
|
713
|
+
const [ chosenPanel, setChosenPanel ] = useState< string | null >();
|
|
714
|
+
// The tab the user picked, `null` until they pick one. Tracked separately
|
|
715
|
+
// from `chosenPanel` because the two answer different questions: whether
|
|
716
|
+
// the panel should be open, and which tab it should show.
|
|
717
|
+
const [ chosenTab, setChosenTab ] = useState< string | null >( null );
|
|
551
718
|
// Below `small` a frame's header cannot fit the history cluster alongside
|
|
552
719
|
// its own controls, so it moves that cluster elsewhere. The same width
|
|
553
720
|
// undocks the panel, so this is `isWide` rather than a second query.
|
|
@@ -570,11 +737,11 @@ function MediaEditorContent( {
|
|
|
570
737
|
const [ isPlacementActive, setIsPlacementActive ] = useState( false );
|
|
571
738
|
const [ isCanvasGestureActive, setIsCanvasGestureActive ] =
|
|
572
739
|
useState( false );
|
|
573
|
-
// Whether another attachment has replaced `id` in the
|
|
740
|
+
// Whether another attachment has replaced `id` in the image editor this
|
|
574
741
|
// session (today, the original via "Restore original image"). Stays a
|
|
575
|
-
// distinct flag (not derived from the
|
|
742
|
+
// distinct flag (not derived from the image editor) so a bare replacement
|
|
576
743
|
// counts as a change even though swapping the source resets the
|
|
577
|
-
//
|
|
744
|
+
// image editor's own dirty baseline.
|
|
578
745
|
const [ isSourceReplaced, setIsSourceReplaced ] = useState( false );
|
|
579
746
|
const placementControlTimerRef = useRef<
|
|
580
747
|
ReturnType< typeof setTimeout > | undefined
|
|
@@ -601,17 +768,11 @@ function MediaEditorContent( {
|
|
|
601
768
|
};
|
|
602
769
|
}, [] );
|
|
603
770
|
|
|
604
|
-
useEffect( () => {
|
|
605
|
-
setIsPlacementActive( false );
|
|
606
|
-
setIsCanvasGestureActive( false );
|
|
607
|
-
setIsSourceReplaced( false );
|
|
608
|
-
}, [ id ] );
|
|
609
|
-
|
|
610
771
|
// Restore-original: the edit root the edited attachment descends from,
|
|
611
772
|
// exposed by the server as the root-level `edit_root` id on the
|
|
612
773
|
// attachment (edit context, embeddable via the `wp:edit-root` link).
|
|
613
774
|
// Fetch the original's record for the URL and natural dimensions the
|
|
614
|
-
//
|
|
775
|
+
// image editor needs to seed itself.
|
|
615
776
|
const originalId: number | undefined = sourceMedia?.edit_root;
|
|
616
777
|
const originalRecord = useSelect(
|
|
617
778
|
( select ) =>
|
|
@@ -696,38 +857,46 @@ function MediaEditorContent( {
|
|
|
696
857
|
// Restoring discards every pending edit, as the menu item says, so
|
|
697
858
|
// nothing staged against the attachment being replaced reaches a save.
|
|
698
859
|
clearEntityRecordEdits( 'postType', 'attachment', id );
|
|
860
|
+
if ( onEditOriginal && originalId ) {
|
|
861
|
+
onEditOriginal( originalId );
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
699
864
|
setIsSourceReplaced( true );
|
|
700
|
-
}, [ clearEntityRecordEdits, id ] );
|
|
865
|
+
}, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );
|
|
701
866
|
|
|
702
|
-
// A bare replacement has no
|
|
867
|
+
// A bare replacement has no image editor change, so OR the flag in explicitly.
|
|
703
868
|
const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
|
|
704
869
|
|
|
705
870
|
const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
|
|
706
871
|
const isImage = !! media && mediaType === 'image';
|
|
707
872
|
|
|
708
|
-
// Until the user picks a panel, follow the breakpoint: dragging a window
|
|
709
|
-
// narrow hands the canvas the full width instead of leaving a panel
|
|
710
|
-
// wedged beside it.
|
|
711
|
-
//
|
|
712
873
|
// Docked, the panel opens on Crop: the canvas is still beside it and
|
|
713
874
|
// cropping is what the editor is for. Below `small` an open panel covers
|
|
714
875
|
// the canvas, and crop controls with no crop in sight are not worth
|
|
715
876
|
// opening on, so Details leads there. Non-image media has no Crop tab at
|
|
716
|
-
// all (see `tabs`), so it always gets Details.
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
877
|
+
// all (see `tabs`), so it always gets Details.
|
|
878
|
+
const currentTab =
|
|
879
|
+
chosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );
|
|
880
|
+
// `null` when nothing is open, otherwise the open panel's id. Until the
|
|
881
|
+
// user opens or closes the panel, follow the breakpoint: dragging a window
|
|
882
|
+
// narrow hands the canvas the full width instead of leaving a panel
|
|
883
|
+
// wedged beside it.
|
|
884
|
+
let activePanel = chosenPanel;
|
|
885
|
+
if ( activePanel === undefined ) {
|
|
886
|
+
activePanel = isWide ? currentTab : null;
|
|
887
|
+
}
|
|
888
|
+
// Switching tabs says nothing about whether the panel should be open, so
|
|
889
|
+
// it leaves `chosenPanel` unset: picking Details on a wide screen and then
|
|
890
|
+
// dragging the window narrow should still hand the canvas the full width.
|
|
891
|
+
const selectPanel = useCallback( ( panel: string ) => {
|
|
892
|
+
setChosenTab( panel );
|
|
893
|
+
setChosenPanel( ( chosen ) =>
|
|
894
|
+
chosen === undefined ? chosen : panel
|
|
895
|
+
);
|
|
896
|
+
}, [] );
|
|
897
|
+
const togglePanel = useCallback( () => {
|
|
898
|
+
setChosenPanel( activePanel ? null : currentTab );
|
|
899
|
+
}, [ activePanel, currentTab ] );
|
|
731
900
|
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
732
901
|
useCropOptions( { aspectRatioPresets } );
|
|
733
902
|
const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
|
|
@@ -922,25 +1091,41 @@ function MediaEditorContent( {
|
|
|
922
1091
|
</div>
|
|
923
1092
|
) }
|
|
924
1093
|
</NavigableRegion>
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1094
|
+
<AnimatePresence
|
|
1095
|
+
initial={ false }
|
|
1096
|
+
custom={ sidebarTransition }
|
|
1097
|
+
>
|
|
1098
|
+
{ !! activePanel && (
|
|
1099
|
+
<motion.div
|
|
1100
|
+
className="media-editor__sidebar-container"
|
|
1101
|
+
variants={ sidebarVariants }
|
|
1102
|
+
initial="closed"
|
|
1103
|
+
animate="open"
|
|
1104
|
+
exit="closed"
|
|
1105
|
+
transition={ sidebarTransition }
|
|
1106
|
+
>
|
|
1107
|
+
<MediaEditorSidebar
|
|
1108
|
+
tabs={ tabs }
|
|
1109
|
+
// Swapping the edited media can drop the
|
|
1110
|
+
// Crop tab out from under an open panel —
|
|
1111
|
+
// saving a crop moves the editor to a new
|
|
1112
|
+
// id, which may resolve as non-image.
|
|
1113
|
+
// Fall back rather than hand `Tabs.Root`
|
|
1114
|
+
// a value no tab matches.
|
|
1115
|
+
activeTab={
|
|
1116
|
+
tabs.some(
|
|
1117
|
+
( tab ) =>
|
|
1118
|
+
tab.id === activePanel
|
|
1119
|
+
)
|
|
1120
|
+
? activePanel
|
|
1121
|
+
: DETAILS_PANEL
|
|
1122
|
+
}
|
|
1123
|
+
onSelectTab={ selectPanel }
|
|
1124
|
+
disabled={ isSaving }
|
|
1125
|
+
/>
|
|
1126
|
+
</motion.div>
|
|
1127
|
+
) }
|
|
1128
|
+
</AnimatePresence>
|
|
944
1129
|
</div>
|
|
945
1130
|
) }
|
|
946
1131
|
</div>
|
|
@@ -983,6 +1168,7 @@ function MediaEditorContent( {
|
|
|
983
1168
|
onSave: saveMediaEditor,
|
|
984
1169
|
canRestoreOriginal,
|
|
985
1170
|
isSourceReplaced,
|
|
1171
|
+
opensOriginal: !! onEditOriginal,
|
|
986
1172
|
onRestoreOriginal: handleRestoreOriginal,
|
|
987
1173
|
};
|
|
988
1174
|
|
|
@@ -1015,6 +1201,8 @@ export function MediaEditor( props: MediaEditorProps ) {
|
|
|
1015
1201
|
// `DataViewsPicker` exposes its own sub-components. They read what they need
|
|
1016
1202
|
// from context, so a frame only chooses where they go and how they look.
|
|
1017
1203
|
MediaEditor.HeaderActions = HeaderActions;
|
|
1204
|
+
MediaEditor.PanelToggle = PanelToggle;
|
|
1205
|
+
MediaEditor.MoreMenu = MoreMenu;
|
|
1018
1206
|
MediaEditor.HistoryActions = HistoryActions;
|
|
1019
1207
|
MediaEditor.SaveActions = SaveActions;
|
|
1020
1208
|
|