@wordpress/media-editor 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/components/media-editor/index.cjs +533 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -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 +76 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -710
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +134 -112
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -294
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -673
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -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 +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +98 -96
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +43 -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 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -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 +68 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +106 -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/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -686
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -90
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -286
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +4 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +1 -0
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +2 -1
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/media-editor/index.tsx +215 -162
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -2
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +16 -26
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-preview/index.tsx +66 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +19 -27
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +2 -2
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +2 -6
- package/src/state/use-media-editor-state.ts +7 -5
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
|
@@ -6,9 +6,11 @@ import {
|
|
|
6
6
|
MenuItem,
|
|
7
7
|
Spinner as WCSpinner,
|
|
8
8
|
__experimentalConfirmDialog as ConfirmDialog,
|
|
9
|
+
__unstableAnimatePresence as AnimatePresence,
|
|
10
|
+
__unstableMotion as motion,
|
|
9
11
|
} from '@wordpress/components';
|
|
10
12
|
import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
|
|
11
|
-
import { useViewportMatch } from '@wordpress/compose';
|
|
13
|
+
import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
|
|
12
14
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
13
15
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
16
|
import { NavigableRegion } from '@wordpress/admin-ui';
|
|
@@ -83,6 +85,26 @@ const DETAILS_PANEL = 'details';
|
|
|
83
85
|
/** Identifier for the crop panel. Images only; other media has nothing to crop. */
|
|
84
86
|
const CROP_PANEL = 'crop';
|
|
85
87
|
|
|
88
|
+
// Matches the editor's sidebar in `ComplementaryArea`.
|
|
89
|
+
const SIDEBAR_ANIMATION_DURATION = 0.3;
|
|
90
|
+
|
|
91
|
+
type SidebarTransition = {
|
|
92
|
+
type: 'tween';
|
|
93
|
+
duration: number;
|
|
94
|
+
ease: number[];
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const sidebarVariants = {
|
|
98
|
+
// `auto` leaves the width to the sidebar's stylesheet.
|
|
99
|
+
open: { width: 'auto' },
|
|
100
|
+
// Takes the transition from `AnimatePresence`'s `custom` prop, so a
|
|
101
|
+
// sidebar that is already closing still gets the current one.
|
|
102
|
+
closed: ( transition: SidebarTransition ) => ( {
|
|
103
|
+
width: 0,
|
|
104
|
+
transition,
|
|
105
|
+
} ),
|
|
106
|
+
};
|
|
107
|
+
|
|
86
108
|
interface MediaEditorTab {
|
|
87
109
|
id: string;
|
|
88
110
|
title: string;
|
|
@@ -221,7 +243,7 @@ interface MediaEditorFrameContextValue {
|
|
|
221
243
|
onSave: () => void;
|
|
222
244
|
/**
|
|
223
245
|
* When `true`, the media has a lineage root to restore to, so the
|
|
224
|
-
* "Restore original
|
|
246
|
+
* history menu shows its "Restore original" item.
|
|
225
247
|
*/
|
|
226
248
|
canRestoreOriginal: boolean;
|
|
227
249
|
/**
|
|
@@ -264,20 +286,66 @@ export interface HeaderActionsProps {
|
|
|
264
286
|
showCloseButton?: boolean;
|
|
265
287
|
}
|
|
266
288
|
|
|
267
|
-
function
|
|
268
|
-
const {
|
|
269
|
-
isImage,
|
|
270
|
-
isSaving,
|
|
271
|
-
onCancel,
|
|
272
|
-
isWide,
|
|
273
|
-
activePanel,
|
|
274
|
-
onTogglePanel,
|
|
275
|
-
canRestoreOriginal,
|
|
276
|
-
isSourceReplaced,
|
|
277
|
-
onRestoreOriginal,
|
|
278
|
-
} = useMediaEditorFrameContext();
|
|
289
|
+
function PanelToggle() {
|
|
290
|
+
const { isWide, activePanel, onTogglePanel } = useMediaEditorFrameContext();
|
|
279
291
|
const isPanelOpen = !! activePanel;
|
|
292
|
+
// The sidebar holds more than one panel, so this opens and closes the
|
|
293
|
+
// sidebar rather than naming a panel: reopening returns to whichever tab
|
|
294
|
+
// was last showing, and the tab strip inside switches between them.
|
|
295
|
+
return (
|
|
296
|
+
<Button
|
|
297
|
+
size="compact"
|
|
298
|
+
icon={ drawerRight }
|
|
299
|
+
label={ __( 'Media settings' ) }
|
|
300
|
+
isPressed={ isPanelOpen }
|
|
301
|
+
// Only a docked column really expands beside the canvas; below
|
|
302
|
+
// that the panel replaces the view, which the pressed state
|
|
303
|
+
// already describes.
|
|
304
|
+
aria-expanded={ isWide ? isPanelOpen : undefined }
|
|
305
|
+
onClick={ onTogglePanel }
|
|
306
|
+
/>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function MoreMenu() {
|
|
311
|
+
const { isImage } = useMediaEditorFrameContext();
|
|
280
312
|
const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
|
|
313
|
+
if ( ! isImage ) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
return (
|
|
317
|
+
<>
|
|
318
|
+
<DropdownMenu
|
|
319
|
+
icon={ moreVertical }
|
|
320
|
+
label={ __( 'More options' ) }
|
|
321
|
+
toggleProps={ { size: 'compact' } }
|
|
322
|
+
>
|
|
323
|
+
{ ( { onClose: closeMenu } ) => (
|
|
324
|
+
<MenuGroup>
|
|
325
|
+
<MenuItem
|
|
326
|
+
icon={ keyboard }
|
|
327
|
+
iconPosition="left"
|
|
328
|
+
onClick={ () => {
|
|
329
|
+
setIsShortcutsModalOpen( true );
|
|
330
|
+
closeMenu();
|
|
331
|
+
} }
|
|
332
|
+
>
|
|
333
|
+
{ __( 'Keyboard shortcuts' ) }
|
|
334
|
+
</MenuItem>
|
|
335
|
+
</MenuGroup>
|
|
336
|
+
) }
|
|
337
|
+
</DropdownMenu>
|
|
338
|
+
{ isShortcutsModalOpen && (
|
|
339
|
+
<MediaEditorKeyboardShortcutsModal
|
|
340
|
+
onClose={ () => setIsShortcutsModalOpen( false ) }
|
|
341
|
+
/>
|
|
342
|
+
) }
|
|
343
|
+
</>
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
|
|
348
|
+
const { isSaving, onCancel } = useMediaEditorFrameContext();
|
|
281
349
|
return (
|
|
282
350
|
<Stack
|
|
283
351
|
className="media-editor__header-actions"
|
|
@@ -285,65 +353,8 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
|
|
|
285
353
|
align="center"
|
|
286
354
|
gap="sm"
|
|
287
355
|
>
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
returns to whichever tab was last showing, and the tab strip
|
|
291
|
-
inside switches between them. */ }
|
|
292
|
-
<Button
|
|
293
|
-
size="compact"
|
|
294
|
-
icon={ drawerRight }
|
|
295
|
-
label={ __( 'Media settings' ) }
|
|
296
|
-
isPressed={ isPanelOpen }
|
|
297
|
-
// Only a docked column really expands beside the canvas; below
|
|
298
|
-
// that the panel replaces the view, which the pressed state
|
|
299
|
-
// already describes.
|
|
300
|
-
aria-expanded={ isWide ? isPanelOpen : undefined }
|
|
301
|
-
onClick={ onTogglePanel }
|
|
302
|
-
/>
|
|
303
|
-
{ isImage && (
|
|
304
|
-
<DropdownMenu
|
|
305
|
-
icon={ moreVertical }
|
|
306
|
-
label={ __( 'More options' ) }
|
|
307
|
-
toggleProps={ { size: 'compact' } }
|
|
308
|
-
>
|
|
309
|
-
{ ( { onClose: closeMenu } ) => (
|
|
310
|
-
<>
|
|
311
|
-
{ canRestoreOriginal && (
|
|
312
|
-
<MenuGroup>
|
|
313
|
-
<MenuItem
|
|
314
|
-
icon={ backup }
|
|
315
|
-
iconPosition="left"
|
|
316
|
-
disabled={
|
|
317
|
-
isSourceReplaced || isSaving
|
|
318
|
-
}
|
|
319
|
-
info={ __(
|
|
320
|
-
'Discards unsaved changes and loads the original image.'
|
|
321
|
-
) }
|
|
322
|
-
onClick={ () => {
|
|
323
|
-
onRestoreOriginal();
|
|
324
|
-
closeMenu();
|
|
325
|
-
} }
|
|
326
|
-
>
|
|
327
|
-
{ __( 'Restore original image' ) }
|
|
328
|
-
</MenuItem>
|
|
329
|
-
</MenuGroup>
|
|
330
|
-
) }
|
|
331
|
-
<MenuGroup>
|
|
332
|
-
<MenuItem
|
|
333
|
-
icon={ keyboard }
|
|
334
|
-
iconPosition="left"
|
|
335
|
-
onClick={ () => {
|
|
336
|
-
setIsShortcutsModalOpen( true );
|
|
337
|
-
closeMenu();
|
|
338
|
-
} }
|
|
339
|
-
>
|
|
340
|
-
{ __( 'Keyboard shortcuts' ) }
|
|
341
|
-
</MenuItem>
|
|
342
|
-
</MenuGroup>
|
|
343
|
-
</>
|
|
344
|
-
) }
|
|
345
|
-
</DropdownMenu>
|
|
346
|
-
) }
|
|
356
|
+
<PanelToggle />
|
|
357
|
+
<MoreMenu />
|
|
347
358
|
{ showCloseButton && (
|
|
348
359
|
<Button
|
|
349
360
|
size="compact"
|
|
@@ -354,18 +365,21 @@ function HeaderActions( { showCloseButton = false }: HeaderActionsProps ) {
|
|
|
354
365
|
accessibleWhenDisabled
|
|
355
366
|
/>
|
|
356
367
|
) }
|
|
357
|
-
{ isShortcutsModalOpen && (
|
|
358
|
-
<MediaEditorKeyboardShortcutsModal
|
|
359
|
-
onClose={ () => setIsShortcutsModalOpen( false ) }
|
|
360
|
-
/>
|
|
361
|
-
) }
|
|
362
368
|
</Stack>
|
|
363
369
|
);
|
|
364
370
|
}
|
|
365
371
|
|
|
366
372
|
function HistoryActions() {
|
|
367
|
-
const {
|
|
368
|
-
|
|
373
|
+
const {
|
|
374
|
+
isImage,
|
|
375
|
+
isSaving,
|
|
376
|
+
isUndoRedoDisabled,
|
|
377
|
+
isWide,
|
|
378
|
+
activePanel,
|
|
379
|
+
canRestoreOriginal,
|
|
380
|
+
isSourceReplaced,
|
|
381
|
+
onRestoreOriginal,
|
|
382
|
+
} = useMediaEditorFrameContext();
|
|
369
383
|
const {
|
|
370
384
|
reset,
|
|
371
385
|
isDirty,
|
|
@@ -409,15 +423,6 @@ function HistoryActions() {
|
|
|
409
423
|
align="center"
|
|
410
424
|
gap="sm"
|
|
411
425
|
>
|
|
412
|
-
<Button
|
|
413
|
-
size="compact"
|
|
414
|
-
variant="tertiary"
|
|
415
|
-
disabled={ isUndoRedoDisabled || ! isDirty }
|
|
416
|
-
accessibleWhenDisabled
|
|
417
|
-
onClick={ handleReset }
|
|
418
|
-
>
|
|
419
|
-
{ __( 'Reset' ) }
|
|
420
|
-
</Button>
|
|
421
426
|
<Button
|
|
422
427
|
size="compact"
|
|
423
428
|
icon={ undo }
|
|
@@ -442,6 +447,48 @@ function HistoryActions() {
|
|
|
442
447
|
accessibleWhenDisabled
|
|
443
448
|
onClick={ handleRedo }
|
|
444
449
|
/>
|
|
450
|
+
<DropdownMenu
|
|
451
|
+
icon={ backup }
|
|
452
|
+
label={ __( 'History' ) }
|
|
453
|
+
popoverProps={ { placement: 'top-start' } }
|
|
454
|
+
toggleProps={ {
|
|
455
|
+
size: 'compact',
|
|
456
|
+
disabled:
|
|
457
|
+
isUndoRedoDisabled ||
|
|
458
|
+
( ! isDirty && ! canRestoreOriginal ),
|
|
459
|
+
accessibleWhenDisabled: true,
|
|
460
|
+
} }
|
|
461
|
+
>
|
|
462
|
+
{ ( { onClose: closeMenu } ) => (
|
|
463
|
+
<>
|
|
464
|
+
<MenuGroup>
|
|
465
|
+
<MenuItem
|
|
466
|
+
disabled={ isUndoRedoDisabled || ! isDirty }
|
|
467
|
+
onClick={ () => {
|
|
468
|
+
handleReset();
|
|
469
|
+
closeMenu();
|
|
470
|
+
} }
|
|
471
|
+
>
|
|
472
|
+
{ __( 'Reset image edits' ) }
|
|
473
|
+
</MenuItem>
|
|
474
|
+
</MenuGroup>
|
|
475
|
+
{ canRestoreOriginal && (
|
|
476
|
+
<MenuGroup>
|
|
477
|
+
<MenuItem
|
|
478
|
+
disabled={ isSourceReplaced || isSaving }
|
|
479
|
+
info={ __( 'Discards unsaved changes.' ) }
|
|
480
|
+
onClick={ () => {
|
|
481
|
+
onRestoreOriginal();
|
|
482
|
+
closeMenu();
|
|
483
|
+
} }
|
|
484
|
+
>
|
|
485
|
+
{ __( 'Restore original' ) }
|
|
486
|
+
</MenuItem>
|
|
487
|
+
</MenuGroup>
|
|
488
|
+
) }
|
|
489
|
+
</>
|
|
490
|
+
) }
|
|
491
|
+
</DropdownMenu>
|
|
445
492
|
</Stack>
|
|
446
493
|
);
|
|
447
494
|
}
|
|
@@ -518,36 +565,26 @@ function MediaEditorContent( {
|
|
|
518
565
|
// The choice is not carried across openings: the modal is transient, and
|
|
519
566
|
// re-opening with the panel hidden on a wide screen is how #81487 read to
|
|
520
567
|
// people in the first place. Within one opening it does hold — see
|
|
521
|
-
// `
|
|
568
|
+
// `chosenPanel` below.
|
|
522
569
|
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
|
-
}, [] );
|
|
570
|
+
// Below `small` the open panel replaces the canvas instead of sitting
|
|
571
|
+
// beside it, so there is nothing to animate.
|
|
572
|
+
const disableSidebarMotion = useReducedMotion() || ! isWide;
|
|
573
|
+
const sidebarTransition: SidebarTransition = {
|
|
574
|
+
type: 'tween',
|
|
575
|
+
duration: disableSidebarMotion ? 0 : SIDEBAR_ANIMATION_DURATION,
|
|
576
|
+
ease: [ 0.6, 0, 0.4, 1 ],
|
|
577
|
+
};
|
|
578
|
+
// Width picks the starting panel, but only until the user opens or closes
|
|
579
|
+
// it. After that their choice holds for the rest of the session: closing
|
|
580
|
+
// the panel and then resizing — or crossing the breakpoint by rotating a
|
|
581
|
+
// tablet — should not reopen something they just dismissed. `undefined`
|
|
582
|
+
// until then, otherwise `null` for closed or the open panel's id.
|
|
583
|
+
const [ chosenPanel, setChosenPanel ] = useState< string | null >();
|
|
584
|
+
// The tab the user picked, `null` until they pick one. Tracked separately
|
|
585
|
+
// from `chosenPanel` because the two answer different questions: whether
|
|
586
|
+
// the panel should be open, and which tab it should show.
|
|
587
|
+
const [ chosenTab, setChosenTab ] = useState< string | null >( null );
|
|
551
588
|
// Below `small` a frame's header cannot fit the history cluster alongside
|
|
552
589
|
// its own controls, so it moves that cluster elsewhere. The same width
|
|
553
590
|
// undocks the panel, so this is `isWide` rather than a second query.
|
|
@@ -601,12 +638,6 @@ function MediaEditorContent( {
|
|
|
601
638
|
};
|
|
602
639
|
}, [] );
|
|
603
640
|
|
|
604
|
-
useEffect( () => {
|
|
605
|
-
setIsPlacementActive( false );
|
|
606
|
-
setIsCanvasGestureActive( false );
|
|
607
|
-
setIsSourceReplaced( false );
|
|
608
|
-
}, [ id ] );
|
|
609
|
-
|
|
610
641
|
// Restore-original: the edit root the edited attachment descends from,
|
|
611
642
|
// exposed by the server as the root-level `edit_root` id on the
|
|
612
643
|
// attachment (edit context, embeddable via the `wp:edit-root` link).
|
|
@@ -705,29 +736,33 @@ function MediaEditorContent( {
|
|
|
705
736
|
const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
|
|
706
737
|
const isImage = !! media && mediaType === 'image';
|
|
707
738
|
|
|
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
739
|
// Docked, the panel opens on Crop: the canvas is still beside it and
|
|
713
740
|
// cropping is what the editor is for. Below `small` an open panel covers
|
|
714
741
|
// the canvas, and crop controls with no crop in sight are not worth
|
|
715
742
|
// 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
|
-
|
|
743
|
+
// all (see `tabs`), so it always gets Details.
|
|
744
|
+
const currentTab =
|
|
745
|
+
chosenTab ?? ( isWide && isImage ? CROP_PANEL : DETAILS_PANEL );
|
|
746
|
+
// `null` when nothing is open, otherwise the open panel's id. Until the
|
|
747
|
+
// user opens or closes the panel, follow the breakpoint: dragging a window
|
|
748
|
+
// narrow hands the canvas the full width instead of leaving a panel
|
|
749
|
+
// wedged beside it.
|
|
750
|
+
let activePanel = chosenPanel;
|
|
751
|
+
if ( activePanel === undefined ) {
|
|
752
|
+
activePanel = isWide ? currentTab : null;
|
|
753
|
+
}
|
|
754
|
+
// Switching tabs says nothing about whether the panel should be open, so
|
|
755
|
+
// it leaves `chosenPanel` unset: picking Details on a wide screen and then
|
|
756
|
+
// dragging the window narrow should still hand the canvas the full width.
|
|
757
|
+
const selectPanel = useCallback( ( panel: string ) => {
|
|
758
|
+
setChosenTab( panel );
|
|
759
|
+
setChosenPanel( ( chosen ) =>
|
|
760
|
+
chosen === undefined ? chosen : panel
|
|
761
|
+
);
|
|
762
|
+
}, [] );
|
|
763
|
+
const togglePanel = useCallback( () => {
|
|
764
|
+
setChosenPanel( activePanel ? null : currentTab );
|
|
765
|
+
}, [ activePanel, currentTab ] );
|
|
731
766
|
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
732
767
|
useCropOptions( { aspectRatioPresets } );
|
|
733
768
|
const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
|
|
@@ -922,25 +957,41 @@ function MediaEditorContent( {
|
|
|
922
957
|
</div>
|
|
923
958
|
) }
|
|
924
959
|
</NavigableRegion>
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
960
|
+
<AnimatePresence
|
|
961
|
+
initial={ false }
|
|
962
|
+
custom={ sidebarTransition }
|
|
963
|
+
>
|
|
964
|
+
{ !! activePanel && (
|
|
965
|
+
<motion.div
|
|
966
|
+
className="media-editor__sidebar-container"
|
|
967
|
+
variants={ sidebarVariants }
|
|
968
|
+
initial="closed"
|
|
969
|
+
animate="open"
|
|
970
|
+
exit="closed"
|
|
971
|
+
transition={ sidebarTransition }
|
|
972
|
+
>
|
|
973
|
+
<MediaEditorSidebar
|
|
974
|
+
tabs={ tabs }
|
|
975
|
+
// Swapping the edited media can drop the
|
|
976
|
+
// Crop tab out from under an open panel —
|
|
977
|
+
// saving a crop moves the editor to a new
|
|
978
|
+
// id, which may resolve as non-image.
|
|
979
|
+
// Fall back rather than hand `Tabs.Root`
|
|
980
|
+
// a value no tab matches.
|
|
981
|
+
activeTab={
|
|
982
|
+
tabs.some(
|
|
983
|
+
( tab ) =>
|
|
984
|
+
tab.id === activePanel
|
|
985
|
+
)
|
|
986
|
+
? activePanel
|
|
987
|
+
: DETAILS_PANEL
|
|
988
|
+
}
|
|
989
|
+
onSelectTab={ selectPanel }
|
|
990
|
+
disabled={ isSaving }
|
|
991
|
+
/>
|
|
992
|
+
</motion.div>
|
|
993
|
+
) }
|
|
994
|
+
</AnimatePresence>
|
|
944
995
|
</div>
|
|
945
996
|
) }
|
|
946
997
|
</div>
|
|
@@ -1015,6 +1066,8 @@ export function MediaEditor( props: MediaEditorProps ) {
|
|
|
1015
1066
|
// `DataViewsPicker` exposes its own sub-components. They read what they need
|
|
1016
1067
|
// from context, so a frame only chooses where they go and how they look.
|
|
1017
1068
|
MediaEditor.HeaderActions = HeaderActions;
|
|
1069
|
+
MediaEditor.PanelToggle = PanelToggle;
|
|
1070
|
+
MediaEditor.MoreMenu = MoreMenu;
|
|
1018
1071
|
MediaEditor.HistoryActions = HistoryActions;
|
|
1019
1072
|
MediaEditor.SaveActions = SaveActions;
|
|
1020
1073
|
|
|
@@ -51,8 +51,13 @@
|
|
|
51
51
|
// canvas takes whatever the 320px panel leaves — about 200px at
|
|
52
52
|
// 600px, 380px at 782px. Cramped, but a cramped preview beside
|
|
53
53
|
// reachable controls beats a panel that hides the image outright.
|
|
54
|
+
// The right gutter goes when the sidebar opens beside the canvas. It
|
|
55
|
+
// moves with the sidebar's width animation, so it uses the same
|
|
56
|
+
// duration and easing.
|
|
54
57
|
@include break-small() {
|
|
55
58
|
margin: 0 $grid-unit-30;
|
|
59
|
+
transition: margin-right 0.3s cubic-bezier(0.6, 0, 0.4, 1);
|
|
60
|
+
@include reduce-motion("transition");
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
// Promise the canvas a floor only where the body is wide enough to
|
|
@@ -123,6 +128,20 @@
|
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
|
|
131
|
+
// Animates its width when the sidebar opens or closes. The sidebar keeps
|
|
132
|
+
// its own width inside, so its contents are clipped rather than reflowed.
|
|
133
|
+
.media-editor__sidebar-container {
|
|
134
|
+
display: flex;
|
|
135
|
+
flex: 1;
|
|
136
|
+
min-width: 0;
|
|
137
|
+
min-height: 0;
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
|
|
140
|
+
@include break-small() {
|
|
141
|
+
flex: none;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
126
145
|
// Settings panel. Below `small` it takes the whole body: there is no room
|
|
127
146
|
// to put a 320px column beside a canvas worth looking at, and that is
|
|
128
147
|
// also where the transform controls fall back to a row under the canvas.
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useMemo } from '@wordpress/element';
|
|
2
|
-
import { DEFAULT_ASPECT_RATIOS } from '../../image-editor/core/constants';
|
|
3
2
|
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
4
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_ASPECT_RATIOS,
|
|
5
|
+
useMediaEditor,
|
|
6
|
+
resolveAspectRatio,
|
|
7
|
+
} from '../../state';
|
|
5
8
|
|
|
6
9
|
interface UseCropOptionsArgs {
|
|
7
10
|
aspectRatioPresets?: AspectRatioPreset[];
|
|
@@ -62,14 +62,10 @@ interface UseSaveMediaEditorReturn {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function getCropModifiers( session: MediaEditorSession ): Modifier[] {
|
|
65
|
-
|
|
66
|
-
if ( ! session.hasOutputEdits || ! state.image ) {
|
|
65
|
+
if ( ! session.hasOutputEdits ) {
|
|
67
66
|
return [];
|
|
68
67
|
}
|
|
69
|
-
return buildModifiers(
|
|
70
|
-
width: state.image.naturalWidth,
|
|
71
|
-
height: state.image.naturalHeight,
|
|
72
|
-
} );
|
|
68
|
+
return buildModifiers( session.cropper );
|
|
73
69
|
}
|
|
74
70
|
|
|
75
71
|
function getMetadataEdits(
|
|
@@ -50,9 +50,12 @@ export default function MediaEditorCanvas( {
|
|
|
50
50
|
// Tracks whether the image pixels have actually loaded. The cropper's
|
|
51
51
|
// geometry is driven by the known media dimensions, so its handles and
|
|
52
52
|
// overlays would otherwise appear before the image finishes streaming in.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
// Stored with the URL it is for, so a new URL (restoring the original
|
|
54
|
+
// swaps it in place) counts as loading until the cropper reports back.
|
|
55
|
+
const [ settled, setSettled ] = useState< {
|
|
56
|
+
url: string | undefined;
|
|
57
|
+
status: 'loaded' | 'error';
|
|
58
|
+
} >();
|
|
56
59
|
|
|
57
60
|
// Resolved aspect ratio is derived from the preset key + the
|
|
58
61
|
// loaded image (for the "Original" preset). The reducer doesn't
|
|
@@ -96,29 +99,14 @@ export default function MediaEditorCanvas( {
|
|
|
96
99
|
}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );
|
|
97
100
|
|
|
98
101
|
const isImage = mediaType.type === 'image';
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
setStatus( 'loading' );
|
|
109
|
-
const probe = new window.Image();
|
|
110
|
-
probe.onload = () => setStatus( 'loaded' );
|
|
111
|
-
probe.onerror = () => setStatus( 'error' );
|
|
112
|
-
probe.src = mediaUrl;
|
|
113
|
-
// Cached images may already be complete before listeners attach.
|
|
114
|
-
if ( probe.complete ) {
|
|
115
|
-
setStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );
|
|
116
|
-
}
|
|
117
|
-
return () => {
|
|
118
|
-
probe.onload = null;
|
|
119
|
-
probe.onerror = null;
|
|
120
|
-
};
|
|
121
|
-
}, [ mediaUrl, isImage ] );
|
|
102
|
+
const status =
|
|
103
|
+
settled && settled.url === mediaUrl ? settled.status : 'loading';
|
|
104
|
+
const handleImageLoaded = useCallback( () => {
|
|
105
|
+
setSettled( { url: mediaUrl, status: 'loaded' } );
|
|
106
|
+
}, [ mediaUrl ] );
|
|
107
|
+
const handleImageError = useCallback( () => {
|
|
108
|
+
setSettled( { url: mediaUrl, status: 'error' } );
|
|
109
|
+
}, [ mediaUrl ] );
|
|
122
110
|
|
|
123
111
|
if ( ! mediaUrl || ! isImage ) {
|
|
124
112
|
return null;
|
|
@@ -165,6 +153,8 @@ export default function MediaEditorCanvas( {
|
|
|
165
153
|
isPlacementActive={ isPlacementActive }
|
|
166
154
|
onGestureStart={ handleGestureStart }
|
|
167
155
|
onGestureEnd={ handleGestureEnd }
|
|
156
|
+
onImageLoaded={ handleImageLoaded }
|
|
157
|
+
onImageError={ handleImageError }
|
|
168
158
|
disabled={ disabled }
|
|
169
159
|
/>
|
|
170
160
|
</div>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Button } from '@wordpress/components';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.
|
|
4
|
+
Menu,
|
|
5
|
+
} from '@wordpress/ui';
|
|
4
6
|
import { __ } from '@wordpress/i18n';
|
|
5
7
|
import {
|
|
6
8
|
aspectRatio as aspectRatioIcon,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CropperController } from '../../image-editor';
|
|
2
2
|
import { getRotatedBBox } from '../../image-editor/core/camera';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -71,20 +71,26 @@ const CROP_TOLERANCE = 0.1;
|
|
|
71
71
|
* leave the sign alone because `flip_h · flip_v = -I` commutes with
|
|
72
72
|
* rotation.
|
|
73
73
|
*
|
|
74
|
-
* @param
|
|
75
|
-
*
|
|
76
|
-
* @return Ordered modifier array; empty when nothing is server-relevant
|
|
74
|
+
* @param cropper The cropper controller. The current edit and the loaded
|
|
75
|
+
* image's natural size are both read from its state.
|
|
76
|
+
* @return Ordered modifier array; empty when nothing is server-relevant or
|
|
77
|
+
* no image has loaded.
|
|
77
78
|
*/
|
|
78
79
|
export function buildModifiers(
|
|
79
|
-
|
|
80
|
-
imageSize: Size
|
|
80
|
+
cropper: Pick< CropperController, 'state' >
|
|
81
81
|
): Modifier[] {
|
|
82
82
|
const modifiers: Modifier[] = [];
|
|
83
|
+
const { state } = cropper;
|
|
84
|
+
const { image } = state;
|
|
83
85
|
|
|
84
|
-
if (
|
|
86
|
+
if ( ! image || image.naturalWidth === 0 || image.naturalHeight === 0 ) {
|
|
85
87
|
return modifiers;
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
const imageSize = {
|
|
91
|
+
width: image.naturalWidth,
|
|
92
|
+
height: image.naturalHeight,
|
|
93
|
+
};
|
|
88
94
|
const { cropRect, pan, zoom, flip } = state;
|
|
89
95
|
const hasFlipH = flip.horizontal;
|
|
90
96
|
const hasFlipV = flip.vertical;
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Active (enabled) undo/redo icon buttons take the admin accent colour so
|
|
44
|
-
// they read as live alongside the
|
|
44
|
+
// they read as live alongside the Cancel/Save actions. Disabled
|
|
45
45
|
// buttons (rendered with `aria-disabled` via `accessibleWhenDisabled`)
|
|
46
46
|
// keep the default muted icon colour.
|
|
47
47
|
// Scoped to the modal: the package ships one stylesheet, so an unscoped
|