@wordpress/media-editor 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
DropdownMenu,
|
|
5
5
|
MenuGroup,
|
|
6
6
|
MenuItem,
|
|
7
|
-
Spinner,
|
|
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';
|
|
@@ -37,7 +39,7 @@ import {
|
|
|
37
39
|
isKeyboardEvent,
|
|
38
40
|
} from '@wordpress/keycodes';
|
|
39
41
|
import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
|
|
40
|
-
import type { Field } from '@wordpress/dataviews';
|
|
42
|
+
import type { Field, Form } from '@wordpress/dataviews';
|
|
41
43
|
import type {
|
|
42
44
|
KeyboardEvent as ReactKeyboardEvent,
|
|
43
45
|
ReactElement,
|
|
@@ -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;
|
|
@@ -116,6 +138,7 @@ export interface MediaEditorFrameProps {
|
|
|
116
138
|
|
|
117
139
|
export interface MediaEditorProps {
|
|
118
140
|
fields?: Field< Media >[];
|
|
141
|
+
form?: Form;
|
|
119
142
|
id: number;
|
|
120
143
|
aspectRatioPresets?: AspectRatioPreset[];
|
|
121
144
|
onClose?: () => void;
|
|
@@ -218,10 +241,9 @@ interface MediaEditorFrameContextValue {
|
|
|
218
241
|
onTogglePanel: () => void;
|
|
219
242
|
onCancel: () => void;
|
|
220
243
|
onSave: () => void;
|
|
221
|
-
onReset: () => 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,30 +365,31 @@ 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 { isImage, isUndoRedoDisabled, onReset, isWide, activePanel } =
|
|
368
|
-
useMediaEditorFrameContext();
|
|
369
373
|
const {
|
|
370
|
-
|
|
374
|
+
isImage,
|
|
375
|
+
isSaving,
|
|
376
|
+
isUndoRedoDisabled,
|
|
377
|
+
isWide,
|
|
378
|
+
activePanel,
|
|
379
|
+
canRestoreOriginal,
|
|
380
|
+
isSourceReplaced,
|
|
381
|
+
onRestoreOriginal,
|
|
382
|
+
} = useMediaEditorFrameContext();
|
|
383
|
+
const {
|
|
384
|
+
reset,
|
|
371
385
|
isDirty,
|
|
372
386
|
hasUndo,
|
|
373
387
|
hasRedo,
|
|
374
388
|
undo: undoCrop,
|
|
375
389
|
redo: redoCrop,
|
|
376
|
-
beginGesture,
|
|
377
|
-
endGesture,
|
|
378
390
|
} = useMediaEditor();
|
|
379
|
-
// Reset, undo and redo act on the
|
|
380
|
-
// canvas does. Non-image media has no edit history at all; below the dock
|
|
391
|
+
// Reset, undo and redo act on the image edits, so they only appear where
|
|
392
|
+
// the canvas does. Non-image media has no edit history at all; below the dock
|
|
381
393
|
// breakpoint an open panel replaces the canvas, and leaving these behind
|
|
382
394
|
// would put an enabled, destructive Reset next to metadata fields it does
|
|
383
395
|
// not touch — clicking it would discard a crop the user cannot see.
|
|
@@ -403,10 +415,7 @@ function HistoryActions() {
|
|
|
403
415
|
if ( isUndoRedoDisabled ) {
|
|
404
416
|
return;
|
|
405
417
|
}
|
|
406
|
-
beginGesture();
|
|
407
418
|
reset();
|
|
408
|
-
onReset();
|
|
409
|
-
endGesture();
|
|
410
419
|
};
|
|
411
420
|
return (
|
|
412
421
|
<Stack
|
|
@@ -414,15 +423,6 @@ function HistoryActions() {
|
|
|
414
423
|
align="center"
|
|
415
424
|
gap="sm"
|
|
416
425
|
>
|
|
417
|
-
<Button
|
|
418
|
-
size="compact"
|
|
419
|
-
variant="tertiary"
|
|
420
|
-
disabled={ isUndoRedoDisabled || ! isDirty }
|
|
421
|
-
accessibleWhenDisabled
|
|
422
|
-
onClick={ handleReset }
|
|
423
|
-
>
|
|
424
|
-
{ __( 'Reset' ) }
|
|
425
|
-
</Button>
|
|
426
426
|
<Button
|
|
427
427
|
size="compact"
|
|
428
428
|
icon={ undo }
|
|
@@ -447,6 +447,48 @@ function HistoryActions() {
|
|
|
447
447
|
accessibleWhenDisabled
|
|
448
448
|
onClick={ handleRedo }
|
|
449
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>
|
|
450
492
|
</Stack>
|
|
451
493
|
);
|
|
452
494
|
}
|
|
@@ -499,6 +541,7 @@ function SaveActions( { size = 'default' }: SaveActionsProps ) {
|
|
|
499
541
|
|
|
500
542
|
function MediaEditorContent( {
|
|
501
543
|
fields = [],
|
|
544
|
+
form,
|
|
502
545
|
id,
|
|
503
546
|
aspectRatioPresets,
|
|
504
547
|
onClose,
|
|
@@ -522,36 +565,26 @@ function MediaEditorContent( {
|
|
|
522
565
|
// The choice is not carried across openings: the modal is transient, and
|
|
523
566
|
// re-opening with the panel hidden on a wide screen is how #81487 read to
|
|
524
567
|
// people in the first place. Within one opening it does hold — see
|
|
525
|
-
// `
|
|
568
|
+
// `chosenPanel` below.
|
|
526
569
|
const isWide = useViewportMatch( 'small' );
|
|
527
|
-
// `
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
//
|
|
537
|
-
//
|
|
538
|
-
//
|
|
539
|
-
//
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
//
|
|
543
|
-
//
|
|
544
|
-
|
|
545
|
-
// full width.
|
|
546
|
-
const selectPanel = useCallback( ( panel: string ) => {
|
|
547
|
-
hasChosenTabRef.current = true;
|
|
548
|
-
lastPanelRef.current = panel;
|
|
549
|
-
setActivePanel( panel );
|
|
550
|
-
}, [] );
|
|
551
|
-
const togglePanel = useCallback( () => {
|
|
552
|
-
hasChosenPanelRef.current = true;
|
|
553
|
-
setActivePanel( ( open ) => ( open ? null : lastPanelRef.current ) );
|
|
554
|
-
}, [] );
|
|
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 );
|
|
555
588
|
// Below `small` a frame's header cannot fit the history cluster alongside
|
|
556
589
|
// its own controls, so it moves that cluster elsewhere. The same width
|
|
557
590
|
// undocks the panel, so this is `isWide` rather than a second query.
|
|
@@ -605,12 +638,6 @@ function MediaEditorContent( {
|
|
|
605
638
|
};
|
|
606
639
|
}, [] );
|
|
607
640
|
|
|
608
|
-
useEffect( () => {
|
|
609
|
-
setIsPlacementActive( false );
|
|
610
|
-
setIsCanvasGestureActive( false );
|
|
611
|
-
setIsSourceReplaced( false );
|
|
612
|
-
}, [ id ] );
|
|
613
|
-
|
|
614
641
|
// Restore-original: the edit root the edited attachment descends from,
|
|
615
642
|
// exposed by the server as the root-level `edit_root` id on the
|
|
616
643
|
// attachment (edit context, embeddable via the `wp:edit-root` link).
|
|
@@ -709,37 +736,35 @@ function MediaEditorContent( {
|
|
|
709
736
|
const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
|
|
710
737
|
const isImage = !! media && mediaType === 'image';
|
|
711
738
|
|
|
712
|
-
// Until the user picks a panel, follow the breakpoint: dragging a window
|
|
713
|
-
// narrow hands the canvas the full width instead of leaving a panel
|
|
714
|
-
// wedged beside it.
|
|
715
|
-
//
|
|
716
739
|
// Docked, the panel opens on Crop: the canvas is still beside it and
|
|
717
740
|
// cropping is what the editor is for. Below `small` an open panel covers
|
|
718
741
|
// the canvas, and crop controls with no crop in sight are not worth
|
|
719
742
|
// opening on, so Details leads there. Non-image media has no Crop tab at
|
|
720
|
-
// all (see `tabs`), so it always gets Details.
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
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 ] );
|
|
766
|
+
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
767
|
+
useCropOptions( { aspectRatioPresets } );
|
|
743
768
|
const { isSaving, save: saveMediaEditor } = useSaveMediaEditor( {
|
|
744
769
|
session,
|
|
745
770
|
id,
|
|
@@ -889,12 +914,13 @@ function MediaEditorContent( {
|
|
|
889
914
|
isDisabled: true,
|
|
890
915
|
} ) )
|
|
891
916
|
: fields,
|
|
917
|
+
form,
|
|
892
918
|
} }
|
|
893
919
|
>
|
|
894
920
|
<div className="media-editor">
|
|
895
921
|
{ ! media ? (
|
|
896
922
|
<div className="media-editor__loading">
|
|
897
|
-
<
|
|
923
|
+
<WCSpinner />
|
|
898
924
|
</div>
|
|
899
925
|
) : (
|
|
900
926
|
<div
|
|
@@ -931,25 +957,41 @@ function MediaEditorContent( {
|
|
|
931
957
|
</div>
|
|
932
958
|
) }
|
|
933
959
|
</NavigableRegion>
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
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>
|
|
953
995
|
</div>
|
|
954
996
|
) }
|
|
955
997
|
</div>
|
|
@@ -990,7 +1032,6 @@ function MediaEditorContent( {
|
|
|
990
1032
|
onTogglePanel: togglePanel,
|
|
991
1033
|
onCancel: handleRequestClose,
|
|
992
1034
|
onSave: saveMediaEditor,
|
|
993
|
-
onReset: resetCropOptions,
|
|
994
1035
|
canRestoreOriginal,
|
|
995
1036
|
isSourceReplaced,
|
|
996
1037
|
onRestoreOriginal: handleRestoreOriginal,
|
|
@@ -1025,6 +1066,8 @@ export function MediaEditor( props: MediaEditorProps ) {
|
|
|
1025
1066
|
// `DataViewsPicker` exposes its own sub-components. They read what they need
|
|
1026
1067
|
// from context, so a frame only chooses where they go and how they look.
|
|
1027
1068
|
MediaEditor.HeaderActions = HeaderActions;
|
|
1069
|
+
MediaEditor.PanelToggle = PanelToggle;
|
|
1070
|
+
MediaEditor.MoreMenu = MoreMenu;
|
|
1028
1071
|
MediaEditor.HistoryActions = HistoryActions;
|
|
1029
1072
|
MediaEditor.SaveActions = SaveActions;
|
|
1030
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[];
|
|
@@ -12,7 +15,6 @@ interface UseCropOptionsReturn {
|
|
|
12
15
|
setAspectRatioValue: ( value: string ) => void;
|
|
13
16
|
aspectRatioOptions: AspectRatioPreset[];
|
|
14
17
|
resolvedAspectRatio: number | undefined;
|
|
15
|
-
resetCropOptions: () => void;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -67,6 +69,5 @@ export function useCropOptions( {
|
|
|
67
69
|
setAspectRatioValue: controller.setAspectRatioValue,
|
|
68
70
|
aspectRatioOptions,
|
|
69
71
|
resolvedAspectRatio,
|
|
70
|
-
resetCropOptions: controller.resetCropOptions,
|
|
71
72
|
};
|
|
72
73
|
}
|
|
@@ -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(
|