@wordpress/media-editor 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/build/components/media-editor/index.cjs +74 -21
- 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 +23 -3
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +6 -11
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +17 -1
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +4 -5
- 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 +1 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- 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 +0 -1
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +10 -4
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +32 -67
- 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-module/components/media-editor/index.mjs +78 -25
- 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 +23 -3
- 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 +1 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- 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 +0 -1
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +10 -5
- 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-style/style-rtl.css +104 -57
- package/build-style/style.css +103 -57
- package/build-types/components/media-editor/index.d.ts +17 -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-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 +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +163 -28
- 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 +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +0 -1
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +32 -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 +155 -240
- package/src/style.scss +2 -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,8 +1,9 @@
|
|
|
1
1
|
import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';
|
|
2
2
|
import { __ } from '@wordpress/i18n';
|
|
3
|
+
import { Icon, getAspectRatioIcon } from '@wordpress/icons';
|
|
4
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
3
5
|
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
4
6
|
import MediaEditorImageControls from '../media-editor-image-controls';
|
|
5
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
6
7
|
|
|
7
8
|
export interface MediaEditorCropPanelProps {
|
|
8
9
|
/**
|
|
@@ -66,7 +67,42 @@ export default function MediaEditorCropPanel( {
|
|
|
66
67
|
} }
|
|
67
68
|
disabled={ disabled }
|
|
68
69
|
items={ items }
|
|
69
|
-
|
|
70
|
+
trigger={
|
|
71
|
+
<SelectControl.Trigger>
|
|
72
|
+
{ ( item ) => (
|
|
73
|
+
<span className="media-editor-crop-panel__aspect-ratio-option">
|
|
74
|
+
<Icon
|
|
75
|
+
icon={ getAspectRatioIcon(
|
|
76
|
+
Number( item.value )
|
|
77
|
+
) }
|
|
78
|
+
/>
|
|
79
|
+
<span className="media-editor-crop-panel__aspect-ratio-label">
|
|
80
|
+
{ item.label }
|
|
81
|
+
</span>
|
|
82
|
+
</span>
|
|
83
|
+
) }
|
|
84
|
+
</SelectControl.Trigger>
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
{ items.map( ( item ) => (
|
|
88
|
+
<SelectControl.Item
|
|
89
|
+
key={ item.value }
|
|
90
|
+
value={ item }
|
|
91
|
+
label={ item.label }
|
|
92
|
+
>
|
|
93
|
+
<SelectControl.ItemLabel>
|
|
94
|
+
<span className="media-editor-crop-panel__aspect-ratio-option">
|
|
95
|
+
<Icon
|
|
96
|
+
icon={ getAspectRatioIcon(
|
|
97
|
+
Number( item.value )
|
|
98
|
+
) }
|
|
99
|
+
/>
|
|
100
|
+
{ item.label }
|
|
101
|
+
</span>
|
|
102
|
+
</SelectControl.ItemLabel>
|
|
103
|
+
</SelectControl.Item>
|
|
104
|
+
) ) }
|
|
105
|
+
</SelectControl>
|
|
70
106
|
</Stack>
|
|
71
107
|
);
|
|
72
108
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
2
|
+
|
|
3
|
+
.media-editor-crop-panel__aspect-ratio-option {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: $grid-unit-10;
|
|
7
|
+
// Allow the label to shrink so that it can be truncated.
|
|
8
|
+
min-width: 0;
|
|
9
|
+
|
|
10
|
+
svg {
|
|
11
|
+
flex-shrink: 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The trigger truncates its value with an ellipsis, which doesn't apply
|
|
16
|
+
// through the flex wrapper, so truncate the label itself.
|
|
17
|
+
.media-editor-crop-panel__aspect-ratio-label {
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
text-overflow: ellipsis;
|
|
20
|
+
white-space: nowrap;
|
|
21
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __ } from '@wordpress/i18n';
|
|
2
2
|
import { useMediaEditor } from '../../state';
|
|
3
3
|
import { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';
|
|
4
|
-
import { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';
|
|
5
4
|
import RotationRuler from '../rotation-ruler';
|
|
6
5
|
|
|
7
6
|
export interface MediaEditorFineRotationProps {
|
|
@@ -28,7 +27,8 @@ export default function MediaEditorFineRotation( {
|
|
|
28
27
|
onPlacementControlInteraction,
|
|
29
28
|
disabled = false,
|
|
30
29
|
}: MediaEditorFineRotationProps ) {
|
|
31
|
-
const { state, setRotation } =
|
|
30
|
+
const { state, setRotation, maxRotationOffset } =
|
|
31
|
+
useMediaEditor().imageEditor;
|
|
32
32
|
// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce
|
|
33
33
|
// into one undo entry via the gesture idle window. Pointer-up still
|
|
34
34
|
// closes pointer drags immediately.
|
|
@@ -50,8 +50,8 @@ export default function MediaEditorFineRotation( {
|
|
|
50
50
|
// causing subsequent events to spiral.
|
|
51
51
|
const EPS = 0.01;
|
|
52
52
|
const clamped = Math.max(
|
|
53
|
-
-
|
|
54
|
-
Math.min(
|
|
53
|
+
-maxRotationOffset + EPS,
|
|
54
|
+
Math.min( maxRotationOffset - EPS, value )
|
|
55
55
|
);
|
|
56
56
|
onPlacementControlInteraction?.();
|
|
57
57
|
setRotation( baseAngle + clamped * visualDir );
|
|
@@ -65,8 +65,8 @@ export default function MediaEditorFineRotation( {
|
|
|
65
65
|
>
|
|
66
66
|
<RotationRuler
|
|
67
67
|
label={ __( 'Fine rotation' ) }
|
|
68
|
-
min={ -
|
|
69
|
-
max={
|
|
68
|
+
min={ -maxRotationOffset }
|
|
69
|
+
max={ maxRotationOffset }
|
|
70
70
|
value={ fineOffset }
|
|
71
71
|
onChange={ handleRotationSlider }
|
|
72
72
|
disabled={ disabled }
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
import {
|
|
8
8
|
aspectRatio as aspectRatioIcon,
|
|
9
|
+
getAspectRatioIcon,
|
|
9
10
|
rotateLeft,
|
|
10
11
|
rotateRight,
|
|
11
12
|
flipHorizontal,
|
|
@@ -14,11 +15,7 @@ import {
|
|
|
14
15
|
plus,
|
|
15
16
|
} from '@wordpress/icons';
|
|
16
17
|
import { useMediaEditor } from '../../state';
|
|
17
|
-
import {
|
|
18
|
-
MAX_ZOOM,
|
|
19
|
-
type AspectRatioPreset,
|
|
20
|
-
} from '../../image-editor/core/constants';
|
|
21
|
-
import { getMinZoom } from '../../image-editor/core/containment';
|
|
18
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
22
19
|
import { useCropOptions } from '../media-editor/use-crop-options';
|
|
23
20
|
|
|
24
21
|
/**
|
|
@@ -79,14 +76,14 @@ export default function MediaEditorImageControls( {
|
|
|
79
76
|
zoomFactor = DEFAULT_ZOOM_FACTOR,
|
|
80
77
|
disabled = false,
|
|
81
78
|
}: MediaEditorImageControlsProps ) {
|
|
82
|
-
const { state, setFlip, snapRotate90, setZoom } =
|
|
79
|
+
const { state, setFlip, snapRotate90, setZoom, minZoom, maxZoom } =
|
|
80
|
+
useMediaEditor().imageEditor;
|
|
83
81
|
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
84
82
|
useCropOptions( { aspectRatioPresets } );
|
|
85
83
|
const hasAspectRatioControl = ! withLabels && showAspectRatioControl;
|
|
86
|
-
const minZoom = getMinZoom( state );
|
|
87
84
|
const zoomByFactor = ( factor: number ) => {
|
|
88
85
|
setZoom(
|
|
89
|
-
Math.min(
|
|
86
|
+
Math.min( maxZoom, Math.max( minZoom, state.zoom * factor ) )
|
|
90
87
|
);
|
|
91
88
|
};
|
|
92
89
|
|
|
@@ -155,7 +152,7 @@ export default function MediaEditorImageControls( {
|
|
|
155
152
|
icon={ plus }
|
|
156
153
|
label={ __( 'Zoom in' ) }
|
|
157
154
|
showTooltip
|
|
158
|
-
disabled={ disabled || state.zoom >=
|
|
155
|
+
disabled={ disabled || state.zoom >= maxZoom }
|
|
159
156
|
accessibleWhenDisabled
|
|
160
157
|
onClick={ () => zoomByFactor( zoomFactor ) }
|
|
161
158
|
/>
|
|
@@ -202,6 +199,11 @@ export default function MediaEditorImageControls( {
|
|
|
202
199
|
value={ preset.value.toString() }
|
|
203
200
|
closeOnClick
|
|
204
201
|
disabled={ disabled }
|
|
202
|
+
prefix={
|
|
203
|
+
<Menu.PrefixIcon
|
|
204
|
+
icon={ getAspectRatioIcon( preset.value ) }
|
|
205
|
+
/>
|
|
206
|
+
}
|
|
205
207
|
>
|
|
206
208
|
<Menu.ItemLabel>{ preset.label }</Menu.ItemLabel>
|
|
207
209
|
</Menu.RadioItem>
|
|
@@ -5,11 +5,11 @@ import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
|
|
|
5
5
|
import { store as noticesStore } from '@wordpress/notices';
|
|
6
6
|
import type { Field, Form } from '@wordpress/dataviews';
|
|
7
7
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
8
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
8
9
|
import MediaEditor from '../media-editor';
|
|
9
10
|
import type { Media } from '../media-editor-provider';
|
|
10
11
|
import { store as mediaEditorStore } from '../../store';
|
|
11
12
|
import type { MediaEditorModalUpdate } from '../../store/actions';
|
|
12
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
13
13
|
|
|
14
14
|
interface MediaEditorModalProps {
|
|
15
15
|
/**
|
|
@@ -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,32 @@
|
|
|
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. Edits do not yet count towards `hasOutputEdits`; nothing saves them.
|
|
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
|
+
## Use the Session With the Canvas
|
|
12
|
+
|
|
13
|
+
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>`.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { ImageEditorCanvas } from '@wordpress/image-editor';
|
|
17
|
+
import { useMediaEditor } from '../state';
|
|
18
|
+
|
|
19
|
+
function MediaEditorCanvas( { src }: { src: string } ) {
|
|
20
|
+
const session = useMediaEditor();
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<ImageEditorCanvas
|
|
24
|
+
src={ src }
|
|
25
|
+
controller={ session.imageEditor }
|
|
26
|
+
freeformCrop
|
|
27
|
+
onGestureStart={ session.beginGesture }
|
|
28
|
+
onGestureEnd={ session.endGesture }
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
@@ -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 };
|