@wordpress/media-editor 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/build/components/media-editor/index.cjs +229 -126
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +41 -11
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +15 -18
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +26 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +13 -12
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +143 -37
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +12 -6
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +41 -74
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +217 -117
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +123 -41
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +12 -7
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +122 -87
- package/build-style/style.css +121 -87
- package/build-types/components/media-editor/index.d.ts +25 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +40 -54
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +27 -24
- package/src/components/media-editor/index.tsx +372 -142
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +4 -1
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +195 -37
- package/src/components/media-preview/style.scss +11 -32
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +34 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +162 -242
- package/src/style.scss +2 -1
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/animations" as *;
|
|
2
|
-
@use "@wordpress/base-styles/colors" as *;
|
|
3
2
|
@use "@wordpress/base-styles/variables" as *;
|
|
4
3
|
|
|
5
4
|
.media-editor-preview {
|
|
@@ -65,39 +64,19 @@
|
|
|
65
64
|
border-radius: $radius-small;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
text-align: center;
|
|
70
|
-
background: $gray-100;
|
|
71
|
-
padding: $grid-unit-30;
|
|
72
|
-
border-radius: 2px;
|
|
73
|
-
}
|
|
74
|
-
|
|
67
|
+
// Long filenames often have no spaces to break on.
|
|
75
68
|
&__file-name {
|
|
76
|
-
|
|
77
|
-
margin-bottom: $grid-unit-10;
|
|
69
|
+
overflow-wrap: anywhere;
|
|
78
70
|
}
|
|
79
71
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
&--error,
|
|
92
|
-
&--empty {
|
|
93
|
-
color: $gray-700;
|
|
94
|
-
text-align: center;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
&__url {
|
|
98
|
-
font-size: 0.9em;
|
|
99
|
-
color: $gray-600;
|
|
100
|
-
word-break: break-all;
|
|
101
|
-
margin-top: $grid-unit-10;
|
|
72
|
+
// EmptyState.Actions switches between a column and a row on the viewport
|
|
73
|
+
// width, and the row doesn't wrap. The canvas can be narrow on a wide
|
|
74
|
+
// viewport, e.g. with the Details panel open, so wrap a row instead. Also
|
|
75
|
+
// widen its 4px gap between buttons.
|
|
76
|
+
&__actions {
|
|
77
|
+
flex-direction: row;
|
|
78
|
+
flex-wrap: wrap;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
gap: var(--wpds-dimension-gap-sm);
|
|
102
81
|
}
|
|
103
82
|
}
|
|
@@ -18,8 +18,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
18
18
|
height: 32px;
|
|
19
19
|
padding: 0 $grid-unit-10;
|
|
20
20
|
box-sizing: border-box;
|
|
21
|
-
|
|
22
|
-
font-family: $font-family-body;
|
|
21
|
+
font-family: var(--wpds-typography-font-family-body);
|
|
23
22
|
user-select: none;
|
|
24
23
|
touch-action: none;
|
|
25
24
|
cursor: ew-resize;
|
|
@@ -89,6 +88,8 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
89
88
|
|
|
90
89
|
.rotation-ruler__ticks {
|
|
91
90
|
position: absolute;
|
|
91
|
+
// Keep SVG ticks visible when the browser forces dark colors.
|
|
92
|
+
color: CanvasText;
|
|
92
93
|
// The tick offset is applied as a JS-set inline `transform: translateX()`
|
|
93
94
|
// (see rotation-ruler/index.tsx), which rtlcss can't mirror. If rtlcss
|
|
94
95
|
// flipped this `left` to `right`, the anchor and the transform would
|
|
@@ -145,7 +146,6 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
145
146
|
font-size: 12px;
|
|
146
147
|
font-weight: var(--wpds-typography-font-weight-emphasis);
|
|
147
148
|
line-height: 14px;
|
|
148
|
-
color: $gray-900;
|
|
149
149
|
pointer-events: none;
|
|
150
150
|
|
|
151
151
|
&::before {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Media Editor Session
|
|
2
|
+
|
|
3
|
+
The media editor's session owns its undo and redo history. The image editor's state from `@wordpress/image-editor` is one slice of the session's state, next to the sidebar crop options and named edits, kept through `useImageEditor( { state, onChange } )`, so one history covers them all.
|
|
4
|
+
|
|
5
|
+
`useMediaEditorState()` creates a media editor session; `<MediaEditorStateProvider>` calls it, and `useMediaEditor()` reads the one it made. Calling `useMediaEditorState()` again inside the provider makes a second session that shares nothing with the first, so components use `useMediaEditor()`. The session owns the source image, every editing slice, the shared undo/redo history, gesture boundaries, and whether the edits change the saved image (`hasOutputEdits`). The image editor is one participant: `session.imageEditor` is a geometry-only `ImageEditorController` that an `<ImageEditorCanvas>` takes via its `controller` prop, and its `isDirty` covers geometry alone. Replacing the source image (`setSourceImage`, which the image editor's `setImage` also calls) starts a fresh session with default geometry and crop options, a clean baseline, and no history. Save code asks the session, not the image editor, whether image output needs saving.
|
|
6
|
+
|
|
7
|
+
The session also holds named edits other than crop: `session.edits`, set with `session.setEdit( name, value )` and removed by passing `undefined`. They share the crop history, so undo, redo and gestures treat them like any crop change, and a different source image clears them. Values are plain data (`EditValue`: strings, numbers, booleans, `null`, and arrays and objects of those), because the session compares them by content to tell a real change from a no-op. They are session state for the editor's own edit pipeline, not an extension API. `isDirty` counts them, so Reset clears them; `hasOutputEdits` does not, so the editor's unsaved-changes check and Save ignore them, and nothing persists them. That holds until the pipeline applies them to the output, and a panel has no reason to set one before then.
|
|
8
|
+
|
|
9
|
+
`session.reset()` puts every slice back to its starting state in one undo entry: default geometry and crop options, no edits, same image. The Reset button calls it; it does not compose per-slice resets itself.
|
|
10
|
+
|
|
11
|
+
Sidebar panels are React: a `MediaEditorPanel` rendered anywhere inside the editor announces `{ name, title, mediaTypes }` while mounted and fills a slot with its content, and the sidebar turns the mounted panels into tabs. Core's Crop and Details panels are rendered with that component, so the editor itself exercises the extension point. The editor also mounts `registerPlugin` callbacks in the `media-editor` scope through `PluginArea`, inside the session provider. This follows the post editor's `PluginSidebar`: plugin UI arrives as components through Slot/Fill, not as entries in a store.
|
|
12
|
+
|
|
13
|
+
## Use the Session With the Canvas
|
|
14
|
+
|
|
15
|
+
Use the media editor session when image editor state must share history with controls such as aspect ratio. The session owns history and gesture boundaries; pass its `imageEditor` controller to `<ImageEditorCanvas>`.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { ImageEditorCanvas } from '@wordpress/image-editor';
|
|
19
|
+
import { useMediaEditor } from '../state';
|
|
20
|
+
|
|
21
|
+
function MediaEditorCanvas( { src }: { src: string } ) {
|
|
22
|
+
const session = useMediaEditor();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<ImageEditorCanvas
|
|
26
|
+
src={ src }
|
|
27
|
+
controller={ session.imageEditor }
|
|
28
|
+
freeformCrop
|
|
29
|
+
onGestureStart={ session.beginGesture }
|
|
30
|
+
onGestureEnd={ session.endGesture }
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { __ } from '@wordpress/i18n';
|
|
2
|
-
import { ORIGINAL_ASPECT_RATIO, type AspectRatioPreset } from '../image-editor';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
4
|
+
* An aspect ratio preset with a human-readable label.
|
|
5
|
+
*/
|
|
6
|
+
export interface AspectRatioPreset {
|
|
7
|
+
/** Display label (e.g., "Square (1:1)"). */
|
|
8
|
+
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* The aspect ratio value (width / height). 0 = free,
|
|
11
|
+
* `ORIGINAL_ASPECT_RATIO` = the image's own ratio.
|
|
12
|
+
*/
|
|
13
|
+
value: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sentinel value for "Original" aspect ratio — resolved at runtime
|
|
18
|
+
* to the image's natural width / height.
|
|
19
|
+
*/
|
|
20
|
+
export const ORIGINAL_ASPECT_RATIO = -1;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The presets the editor offers by default. They live here rather than
|
|
24
|
+
* in the image editor package, because which ratios to offer, and what
|
|
25
|
+
* to call them, is a product choice. The package takes a plain number.
|
|
7
26
|
*/
|
|
8
27
|
export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
|
|
9
28
|
{ label: __( 'Free' ), value: 0 },
|
|
@@ -1,81 +1,47 @@
|
|
|
1
1
|
import fastDeepEqual from 'fast-deep-equal/es6/index.js';
|
|
2
|
-
import type { CropperState } from '../image-editor';
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
3
|
+
areImageEditorStatesEqual,
|
|
4
|
+
createImageEditorState,
|
|
5
|
+
type ImageEditorState,
|
|
6
|
+
} from '@wordpress/image-editor';
|
|
8
7
|
import {
|
|
9
8
|
DEFAULT_CROP_OPTIONS,
|
|
10
|
-
type CropOptionsSlice,
|
|
11
9
|
type MediaEditorAction,
|
|
12
10
|
type MediaEditorState,
|
|
13
11
|
} from './types';
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
|
-
* Pure
|
|
14
|
+
* Pure reducer for the media editor.
|
|
17
15
|
*
|
|
18
|
-
*
|
|
19
|
-
* `
|
|
20
|
-
*
|
|
21
|
-
* in one transaction (used by undo/redo).
|
|
16
|
+
* The image editor works out its own next state (through the controller from
|
|
17
|
+
* `@wordpress/image-editor`) and this reducer stores it. The reducer
|
|
18
|
+
* also owns the sidebar crop options and the named edits.
|
|
22
19
|
*
|
|
23
|
-
*
|
|
24
|
-
* stacks live in the `useMediaEditorState` hook that wraps it.
|
|
20
|
+
* This reducer keeps no history; `useMediaEditorState` does.
|
|
25
21
|
*
|
|
26
|
-
* @param state Current
|
|
22
|
+
* @param state Current state.
|
|
27
23
|
* @param action Action to apply.
|
|
28
|
-
* @return Next
|
|
24
|
+
* @return Next state.
|
|
29
25
|
*/
|
|
30
26
|
export function mediaEditorReducer(
|
|
31
27
|
state: MediaEditorState,
|
|
32
28
|
action: MediaEditorAction
|
|
33
29
|
): MediaEditorState {
|
|
34
30
|
switch ( action.type ) {
|
|
35
|
-
case '
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
resolved > 0 &&
|
|
50
|
-
visualSize.width > 0 &&
|
|
51
|
-
visualSize.height > 0;
|
|
52
|
-
const nextCropOptions: CropOptionsSlice = {
|
|
53
|
-
...state.cropOptions,
|
|
54
|
-
aspectRatioValue: presetKey,
|
|
55
|
-
};
|
|
56
|
-
if ( ! shouldReshape ) {
|
|
57
|
-
if ( state.cropOptions.aspectRatioValue === presetKey ) {
|
|
58
|
-
return state;
|
|
59
|
-
}
|
|
60
|
-
return { ...state, cropOptions: nextCropOptions };
|
|
61
|
-
}
|
|
62
|
-
const newCropRect = computeInscribedRect( resolved, visualSize );
|
|
63
|
-
const nextCropper = cropperReducer( state.cropper, {
|
|
64
|
-
type: 'SET_CROP_RECT',
|
|
65
|
-
payload: newCropRect,
|
|
66
|
-
} );
|
|
67
|
-
return {
|
|
68
|
-
...state,
|
|
69
|
-
cropper: nextCropper,
|
|
70
|
-
cropOptions: nextCropOptions,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
case 'RESET': {
|
|
74
|
-
const next = buildInitialMediaEditorState(
|
|
75
|
-
cropperReducer( state.cropper, { type: 'RESET' } )
|
|
76
|
-
);
|
|
77
|
-
return areMediaEditorStatesEqual( state, next ) ? state : next;
|
|
78
|
-
}
|
|
31
|
+
case 'SET_IMAGE_EDITOR':
|
|
32
|
+
return action.payload === state.imageEditor
|
|
33
|
+
? state
|
|
34
|
+
: { ...state, imageEditor: action.payload };
|
|
35
|
+
case 'SET_ASPECT_RATIO_VALUE':
|
|
36
|
+
return state.cropOptions.aspectRatioValue === action.payload
|
|
37
|
+
? state
|
|
38
|
+
: {
|
|
39
|
+
...state,
|
|
40
|
+
cropOptions: {
|
|
41
|
+
...state.cropOptions,
|
|
42
|
+
aspectRatioValue: action.payload,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
79
45
|
case 'SET_EDIT': {
|
|
80
46
|
const { name, value } = action.payload;
|
|
81
47
|
if ( value === undefined ) {
|
|
@@ -91,27 +57,23 @@ export function mediaEditorReducer(
|
|
|
91
57
|
}
|
|
92
58
|
return { ...state, edits: { ...state.edits, [ name ]: value } };
|
|
93
59
|
}
|
|
60
|
+
case 'RESET': {
|
|
61
|
+
const next = buildInitialMediaEditorState(
|
|
62
|
+
createImageEditorState( { image: state.imageEditor.image } )
|
|
63
|
+
);
|
|
64
|
+
return areMediaEditorStatesEqual( state, next ) ? state : next;
|
|
65
|
+
}
|
|
94
66
|
case 'RESTORE_SNAPSHOT':
|
|
95
67
|
return action.payload;
|
|
96
|
-
case 'VIEWPORT_ADJUST_CROP_RECT': {
|
|
97
|
-
const nextCropper = cropperReducer( state.cropper, {
|
|
98
|
-
type: 'SET_CROP_RECT',
|
|
99
|
-
payload: action.payload,
|
|
100
|
-
} );
|
|
101
|
-
if ( nextCropper === state.cropper ) {
|
|
102
|
-
return state;
|
|
103
|
-
}
|
|
104
|
-
return { ...state, cropper: nextCropper };
|
|
105
|
-
}
|
|
106
68
|
}
|
|
107
69
|
}
|
|
108
70
|
|
|
109
71
|
/**
|
|
110
|
-
* Value-equality check for two
|
|
111
|
-
*
|
|
72
|
+
* Value-equality check for two media editor states. The history uses it
|
|
73
|
+
* to skip snapshots when an action turned out to be a no-op.
|
|
112
74
|
*
|
|
113
|
-
* @param a First
|
|
114
|
-
* @param b Second
|
|
75
|
+
* @param a First state.
|
|
76
|
+
* @param b Second state.
|
|
115
77
|
* @return Whether `a` and `b` are value-equal across all slices.
|
|
116
78
|
*/
|
|
117
79
|
export function areMediaEditorStatesEqual(
|
|
@@ -122,24 +84,24 @@ export function areMediaEditorStatesEqual(
|
|
|
122
84
|
return true;
|
|
123
85
|
}
|
|
124
86
|
return (
|
|
125
|
-
|
|
87
|
+
areImageEditorStatesEqual( a.imageEditor, b.imageEditor ) &&
|
|
126
88
|
a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&
|
|
127
89
|
fastDeepEqual( a.edits, b.edits )
|
|
128
90
|
);
|
|
129
91
|
}
|
|
130
92
|
|
|
131
93
|
/**
|
|
132
|
-
* Build the
|
|
133
|
-
*
|
|
94
|
+
* Build the state a session starts from: the given image editor state,
|
|
95
|
+
* default crop options, and no edits.
|
|
134
96
|
*
|
|
135
|
-
* @param
|
|
136
|
-
* @return
|
|
97
|
+
* @param imageEditor The image editor state.
|
|
98
|
+
* @return Initial state.
|
|
137
99
|
*/
|
|
138
100
|
export function buildInitialMediaEditorState(
|
|
139
|
-
|
|
101
|
+
imageEditor: ImageEditorState
|
|
140
102
|
): MediaEditorState {
|
|
141
103
|
return {
|
|
142
|
-
|
|
104
|
+
imageEditor,
|
|
143
105
|
cropOptions: { ...DEFAULT_CROP_OPTIONS },
|
|
144
106
|
edits: {},
|
|
145
107
|
};
|
package/src/state/index.ts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
useMediaEditorState,
|
|
3
|
-
resolveAspectRatio,
|
|
4
|
-
} from './use-media-editor-state';
|
|
1
|
+
export { useMediaEditorState } from './use-media-editor-state';
|
|
5
2
|
export type { MediaEditorSession } from './use-media-editor-state';
|
|
6
3
|
export {
|
|
7
4
|
MediaEditorStateProvider,
|
|
8
5
|
useMediaEditor,
|
|
9
6
|
} from './media-editor-state-provider';
|
|
10
|
-
export {
|
|
11
|
-
mediaEditorReducer,
|
|
12
|
-
areMediaEditorStatesEqual,
|
|
13
|
-
buildInitialMediaEditorState,
|
|
14
|
-
} from './composite-reducer';
|
|
15
|
-
export { DEFAULT_CROP_OPTIONS } from './types';
|
|
16
|
-
export { DEFAULT_ASPECT_RATIOS } from './aspect-ratio-presets';
|
|
17
|
-
export type {
|
|
18
|
-
CropOptionsSlice,
|
|
19
|
-
EditsSlice,
|
|
20
|
-
EditValue,
|
|
21
|
-
MediaEditorState,
|
|
22
|
-
MediaEditorAction,
|
|
23
|
-
} from './types';
|
|
7
|
+
export type { EditsSlice, EditValue, MediaEditorState } from './types';
|
package/src/state/types.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CropperAction } from '../image-editor/core';
|
|
1
|
+
import type { ImageEditorState } from '@wordpress/image-editor';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
|
-
* Sidebar control state for the
|
|
6
|
-
*
|
|
4
|
+
* Sidebar control state for the image editor, kept in the same undo history
|
|
5
|
+
* as the crop.
|
|
7
6
|
*/
|
|
8
7
|
export interface CropOptionsSlice {
|
|
9
8
|
/**
|
|
10
9
|
* Selected aspect-ratio preset as a string (round-trippable through
|
|
11
10
|
* `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive
|
|
12
|
-
* decimal = fixed ratio.
|
|
11
|
+
* decimal = fixed ratio. The image editor holds the resolved ratio itself.
|
|
13
12
|
*/
|
|
14
13
|
aspectRatioValue: string;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
19
|
-
* used by the sidebar before the user has touched anything.
|
|
17
|
+
* The crop options a session starts from.
|
|
20
18
|
*/
|
|
21
19
|
export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
|
|
22
20
|
aspectRatioValue: '0',
|
|
@@ -46,81 +44,33 @@ export type EditValue =
|
|
|
46
44
|
export type EditsSlice = Record< string, EditValue >;
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
|
-
* The full
|
|
50
|
-
*
|
|
47
|
+
* The full state of the media editor: the image editor's state, the sidebar
|
|
48
|
+
* crop options and named edits.
|
|
51
49
|
*
|
|
52
50
|
* Every undo/redo snapshot is a full `MediaEditorState`. Slices stay
|
|
53
51
|
* referentially equal across actions that don't touch them.
|
|
54
52
|
*/
|
|
55
53
|
export interface MediaEditorState {
|
|
56
|
-
|
|
54
|
+
imageEditor: ImageEditorState;
|
|
57
55
|
cropOptions: CropOptionsSlice;
|
|
58
56
|
edits: EditsSlice;
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
/**
|
|
62
|
-
* Composite reducer action union.
|
|
63
|
-
*
|
|
64
|
-
* Cropper geometry actions are wrapped in a `CROPPER` envelope and
|
|
65
|
-
* delegated to the pure `cropperReducer`. Sidebar and history
|
|
66
|
-
* concerns are first-class actions on this reducer.
|
|
67
|
-
*/
|
|
59
|
+
/** Actions the media editor reducer handles. */
|
|
68
60
|
export type MediaEditorAction =
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
| {
|
|
75
|
-
type: 'CROPPER';
|
|
76
|
-
action: CropperAction;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Set the aspect-ratio preset. Atomically updates the preset key
|
|
80
|
-
* and the cropRect (computed from the resolved ratio and the
|
|
81
|
-
* current visualSize). One transaction = one undo entry.
|
|
82
|
-
*/
|
|
83
|
-
| {
|
|
84
|
-
type: 'SET_ASPECT_RATIO_VALUE';
|
|
85
|
-
payload: {
|
|
86
|
-
/** Preset key as it appears in the dropdown. */
|
|
87
|
-
presetKey: string;
|
|
88
|
-
/**
|
|
89
|
-
* Resolved width/height ratio. `undefined` = Free
|
|
90
|
-
* (no lock; cropRect stays where it is).
|
|
91
|
-
*/
|
|
92
|
-
resolved: number | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Rendered image size used to compute the inscribed
|
|
95
|
-
* rect. Caller supplies it because the reducer is
|
|
96
|
-
* framework-agnostic and has no DOM access.
|
|
97
|
-
*/
|
|
98
|
-
visualSize: Size;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Put every slice back to its starting state, keeping the image:
|
|
103
|
-
* default geometry, default crop options, no edits. One action,
|
|
104
|
-
* so one undo entry.
|
|
105
|
-
*/
|
|
106
|
-
| { type: 'RESET' }
|
|
61
|
+
/** Replace the image editor's state with the next one it reports. */
|
|
62
|
+
| { type: 'SET_IMAGE_EDITOR'; payload: ImageEditorState }
|
|
63
|
+
/** Set the aspect-ratio preset the dropdown shows. */
|
|
64
|
+
| { type: 'SET_ASPECT_RATIO_VALUE'; payload: string }
|
|
107
65
|
/** Set a named edit, or remove it when `value` is `undefined`. */
|
|
108
66
|
| {
|
|
109
67
|
type: 'SET_EDIT';
|
|
110
68
|
payload: { name: string; value: EditValue | undefined };
|
|
111
69
|
}
|
|
112
70
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
71
|
+
* Put every slice back to its starting state, keeping the image. One
|
|
72
|
+
* action, so one undo entry.
|
|
115
73
|
*/
|
|
116
|
-
| { type: '
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
* (e.g., window resize). Behaviorally identical to a `CROPPER
|
|
120
|
-
* SET_CROP_RECT` dispatch, but tagged so the hook layer can skip
|
|
121
|
-
* history recording — viewport reshapes aren't editor actions.
|
|
122
|
-
*/
|
|
123
|
-
| {
|
|
124
|
-
type: 'VIEWPORT_ADJUST_CROP_RECT';
|
|
125
|
-
payload: NormalizedRect;
|
|
126
|
-
};
|
|
74
|
+
| { type: 'RESET' }
|
|
75
|
+
/** Replace the whole state with a snapshot (undo/redo). */
|
|
76
|
+
| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState };
|