@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/media-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Media editor components for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -52,34 +52,33 @@
|
|
|
52
52
|
"build-module/store/index.mjs"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@wordpress/
|
|
56
|
-
"@wordpress/
|
|
57
|
-
"@wordpress/
|
|
58
|
-
"@wordpress/
|
|
59
|
-
"@wordpress/
|
|
60
|
-
"@wordpress/
|
|
61
|
-
"@wordpress/
|
|
62
|
-
"@wordpress/
|
|
63
|
-
"@wordpress/
|
|
64
|
-
"@wordpress/
|
|
65
|
-
"@wordpress/
|
|
66
|
-
"@wordpress/
|
|
67
|
-
"@wordpress/keyboard-shortcuts": "^6.
|
|
68
|
-
"@wordpress/keycodes": "^5.
|
|
69
|
-
"@wordpress/notices": "^6.
|
|
70
|
-
"@wordpress/private-apis": "^3.
|
|
71
|
-
"@wordpress/ui": "^0.
|
|
55
|
+
"@wordpress/admin-ui": "^3.2.0",
|
|
56
|
+
"@wordpress/api-fetch": "^8.2.0",
|
|
57
|
+
"@wordpress/base-styles": "^15.1.0",
|
|
58
|
+
"@wordpress/components": "^45.0.0",
|
|
59
|
+
"@wordpress/compose": "^9.2.0",
|
|
60
|
+
"@wordpress/core-data": "^9.2.0",
|
|
61
|
+
"@wordpress/data": "^11.2.0",
|
|
62
|
+
"@wordpress/dataviews": "^22.1.0",
|
|
63
|
+
"@wordpress/element": "^10.2.0",
|
|
64
|
+
"@wordpress/i18n": "^7.2.0",
|
|
65
|
+
"@wordpress/icons": "^21.0.0",
|
|
66
|
+
"@wordpress/image-editor": "^0.1.0",
|
|
67
|
+
"@wordpress/keyboard-shortcuts": "^6.2.0",
|
|
68
|
+
"@wordpress/keycodes": "^5.2.0",
|
|
69
|
+
"@wordpress/notices": "^6.2.0",
|
|
70
|
+
"@wordpress/private-apis": "^3.2.0",
|
|
71
|
+
"@wordpress/ui": "^0.27.0",
|
|
72
72
|
"clsx": "^2.1.1",
|
|
73
|
-
"fast-deep-equal": "^3.1.3"
|
|
74
|
-
"gl-matrix": "^3.4.3"
|
|
73
|
+
"fast-deep-equal": "^3.1.3"
|
|
75
74
|
},
|
|
76
75
|
"devDependencies": {
|
|
77
|
-
"@storybook/react-vite": "^10.6.
|
|
76
|
+
"@storybook/react-vite": "^10.6.6",
|
|
78
77
|
"@testing-library/dom": "^10.4.2",
|
|
79
78
|
"@testing-library/jest-dom": "^7.0.1",
|
|
80
79
|
"@testing-library/react": "^16.3.3",
|
|
81
80
|
"@testing-library/user-event": "^14.6.8",
|
|
82
|
-
"vitest": "^5.0
|
|
81
|
+
"vitest": "^5.1.0",
|
|
83
82
|
"vitest-browser-react": "^2.3.0"
|
|
84
83
|
},
|
|
85
84
|
"peerDependencies": {
|
|
@@ -99,5 +98,5 @@
|
|
|
99
98
|
"publishConfig": {
|
|
100
99
|
"access": "public"
|
|
101
100
|
},
|
|
102
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "1000cdf1dffd5b5e69f75cc4360aa76db8252264"
|
|
103
102
|
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
DropdownMenu,
|
|
5
5
|
MenuGroup,
|
|
6
6
|
MenuItem,
|
|
7
|
+
Modal,
|
|
7
8
|
Spinner as WCSpinner,
|
|
8
9
|
__experimentalConfirmDialog as ConfirmDialog,
|
|
9
10
|
__unstableAnimatePresence as AnimatePresence,
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
} from '@wordpress/components';
|
|
12
13
|
import { Stack, Tabs, VisuallyHidden } from '@wordpress/ui';
|
|
13
14
|
import { useReducedMotion, useViewportMatch } from '@wordpress/compose';
|
|
14
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
15
|
+
import { useDispatch, useRegistry, useSelect } from '@wordpress/data';
|
|
15
16
|
import { store as coreStore } from '@wordpress/core-data';
|
|
16
17
|
import { NavigableRegion } from '@wordpress/admin-ui';
|
|
17
18
|
import {
|
|
@@ -20,10 +21,11 @@ import {
|
|
|
20
21
|
useCallback,
|
|
21
22
|
useContext,
|
|
22
23
|
useEffect,
|
|
24
|
+
useMemo,
|
|
23
25
|
useRef,
|
|
24
26
|
useState,
|
|
25
27
|
} from '@wordpress/element';
|
|
26
|
-
import { __ } from '@wordpress/i18n';
|
|
28
|
+
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
27
29
|
import {
|
|
28
30
|
backup,
|
|
29
31
|
close,
|
|
@@ -39,12 +41,13 @@ import {
|
|
|
39
41
|
isKeyboardEvent,
|
|
40
42
|
} from '@wordpress/keycodes';
|
|
41
43
|
import { SnackbarNotices, store as noticesStore } from '@wordpress/notices';
|
|
42
|
-
import type { Field, Form } from '@wordpress/dataviews';
|
|
44
|
+
import type { Action, ActionModal, Field, Form } from '@wordpress/dataviews';
|
|
43
45
|
import type {
|
|
44
46
|
KeyboardEvent as ReactKeyboardEvent,
|
|
45
47
|
ReactElement,
|
|
46
48
|
ReactNode,
|
|
47
49
|
} from 'react';
|
|
50
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
48
51
|
import { MediaEditorProvider } from '../media-editor-provider';
|
|
49
52
|
import type { Media } from '../media-editor-provider';
|
|
50
53
|
import MediaPreview from '../media-preview';
|
|
@@ -55,7 +58,6 @@ import MediaEditorImageControls from '../media-editor-image-controls';
|
|
|
55
58
|
import MediaForm from '../media-form';
|
|
56
59
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
57
60
|
import { MediaEditorStateProvider, useMediaEditor } from '../../state';
|
|
58
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
59
61
|
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
60
62
|
import MediaEditorKeyboardShortcutsModal from '../media-editor-keyboard-shortcuts-modal';
|
|
61
63
|
import {
|
|
@@ -143,6 +145,8 @@ export interface MediaEditorProps {
|
|
|
143
145
|
aspectRatioPresets?: AspectRatioPreset[];
|
|
144
146
|
onClose?: () => void;
|
|
145
147
|
onSaved?: ( result: MediaEditorSaveResult ) => void;
|
|
148
|
+
/** Called with the original's id when the user chooses "Edit original". */
|
|
149
|
+
onEditOriginal?: ( originalId: number ) => void;
|
|
146
150
|
renderFrame: ( props: MediaEditorFrameProps ) => ReactElement;
|
|
147
151
|
noticesClassName?: string;
|
|
148
152
|
noticesPortalElement?: Element | null;
|
|
@@ -248,11 +252,16 @@ interface MediaEditorFrameContextValue {
|
|
|
248
252
|
canRestoreOriginal: boolean;
|
|
249
253
|
/**
|
|
250
254
|
* When `true`, another attachment has replaced the edited one in the
|
|
251
|
-
*
|
|
255
|
+
* image editor this session (today, only the original), so the menu item is
|
|
252
256
|
* disabled.
|
|
253
257
|
*/
|
|
254
258
|
isSourceReplaced: boolean;
|
|
255
|
-
/**
|
|
259
|
+
/** Whether the frame opens the original itself. */
|
|
260
|
+
opensOriginal: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Load the lineage root into the image editor, or hand it to the
|
|
263
|
+
* frame.
|
|
264
|
+
*/
|
|
256
265
|
onRestoreOriginal: () => void;
|
|
257
266
|
}
|
|
258
267
|
|
|
@@ -307,10 +316,75 @@ function PanelToggle() {
|
|
|
307
316
|
);
|
|
308
317
|
}
|
|
309
318
|
|
|
310
|
-
function
|
|
311
|
-
|
|
319
|
+
function getActionLabel( action: Action< Media >, items: Media[] ) {
|
|
320
|
+
return typeof action.label === 'string'
|
|
321
|
+
? action.label
|
|
322
|
+
: action.label( items );
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
interface MediaActionModalProps {
|
|
326
|
+
action: ActionModal< Media >;
|
|
327
|
+
items: Media[];
|
|
328
|
+
closeModal: () => void;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// A copy of the `ActionModal` in `@wordpress/dataviews`, which isn't
|
|
332
|
+
// exported. It could be replaced if dataviews exports it.
|
|
333
|
+
function MediaActionModal( {
|
|
334
|
+
action,
|
|
335
|
+
items,
|
|
336
|
+
closeModal,
|
|
337
|
+
}: MediaActionModalProps ) {
|
|
338
|
+
const header =
|
|
339
|
+
typeof action.modalHeader === 'function'
|
|
340
|
+
? action.modalHeader( items )
|
|
341
|
+
: action.modalHeader;
|
|
342
|
+
return (
|
|
343
|
+
<Modal
|
|
344
|
+
title={ header || getActionLabel( action, items ) }
|
|
345
|
+
__experimentalHideHeader={ !! action.hideModalHeader }
|
|
346
|
+
onRequestClose={ closeModal }
|
|
347
|
+
focusOnMount={ action.modalFocusOnMount ?? true }
|
|
348
|
+
size={ action.modalSize || 'medium' }
|
|
349
|
+
>
|
|
350
|
+
<action.RenderModal items={ items } closeModal={ closeModal } />
|
|
351
|
+
</Modal>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface MoreMenuProps {
|
|
356
|
+
/**
|
|
357
|
+
* Actions for the attachment, such as those from the entity actions API.
|
|
358
|
+
* Only the ones whose `isEligible` passes for `item` are shown.
|
|
359
|
+
*/
|
|
360
|
+
actions?: Action< Media >[];
|
|
361
|
+
/**
|
|
362
|
+
* The attachment the actions apply to, with anything their `isEligible`
|
|
363
|
+
* checks need, such as `permissions`. Without it no actions are shown.
|
|
364
|
+
*/
|
|
365
|
+
item?: Media;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function MoreMenu( { actions = [], item }: MoreMenuProps ) {
|
|
369
|
+
const { isImage, isSaving } = useMediaEditorFrameContext();
|
|
370
|
+
const registry = useRegistry();
|
|
312
371
|
const [ isShortcutsModalOpen, setIsShortcutsModalOpen ] = useState( false );
|
|
313
|
-
|
|
372
|
+
const [ activeModalAction, setActiveModalAction ] =
|
|
373
|
+
useState< ActionModal< Media > | null >( null );
|
|
374
|
+
|
|
375
|
+
const items = item ? [ item ] : [];
|
|
376
|
+
const eligibleActions = useMemo(
|
|
377
|
+
() =>
|
|
378
|
+
item
|
|
379
|
+
? actions.filter(
|
|
380
|
+
( action ) =>
|
|
381
|
+
! action.isEligible || action.isEligible( item )
|
|
382
|
+
)
|
|
383
|
+
: [],
|
|
384
|
+
[ actions, item ]
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
if ( ! isImage && ! eligibleActions.length ) {
|
|
314
388
|
return null;
|
|
315
389
|
}
|
|
316
390
|
return (
|
|
@@ -321,18 +395,63 @@ function MoreMenu() {
|
|
|
321
395
|
toggleProps={ { size: 'compact' } }
|
|
322
396
|
>
|
|
323
397
|
{ ( { onClose: closeMenu } ) => (
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
398
|
+
<>
|
|
399
|
+
{ isImage && (
|
|
400
|
+
<MenuGroup>
|
|
401
|
+
<MenuItem
|
|
402
|
+
icon={ keyboard }
|
|
403
|
+
iconPosition="left"
|
|
404
|
+
onClick={ () => {
|
|
405
|
+
setIsShortcutsModalOpen( true );
|
|
406
|
+
closeMenu();
|
|
407
|
+
} }
|
|
408
|
+
>
|
|
409
|
+
{ __( 'Keyboard shortcuts' ) }
|
|
410
|
+
</MenuItem>
|
|
411
|
+
</MenuGroup>
|
|
412
|
+
) }
|
|
413
|
+
{ !! eligibleActions.length && (
|
|
414
|
+
<MenuGroup>
|
|
415
|
+
{ eligibleActions.map( ( action ) => {
|
|
416
|
+
const label = getActionLabel(
|
|
417
|
+
action,
|
|
418
|
+
items
|
|
419
|
+
);
|
|
420
|
+
return (
|
|
421
|
+
<MenuItem
|
|
422
|
+
key={ action.id }
|
|
423
|
+
disabled={
|
|
424
|
+
isSaving || action.disabled
|
|
425
|
+
}
|
|
426
|
+
onClick={ () => {
|
|
427
|
+
closeMenu();
|
|
428
|
+
if ( 'RenderModal' in action ) {
|
|
429
|
+
setActiveModalAction(
|
|
430
|
+
action
|
|
431
|
+
);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
action.callback( items, {
|
|
435
|
+
registry,
|
|
436
|
+
} );
|
|
437
|
+
} }
|
|
438
|
+
>
|
|
439
|
+
{ 'RenderModal' in action
|
|
440
|
+
? sprintf(
|
|
441
|
+
/* translators: %s: Action label. Use the ellipsis and spacing appropriate for your language. */
|
|
442
|
+
_x(
|
|
443
|
+
'%s…',
|
|
444
|
+
'menu item requiring further input'
|
|
445
|
+
),
|
|
446
|
+
label
|
|
447
|
+
)
|
|
448
|
+
: label }
|
|
449
|
+
</MenuItem>
|
|
450
|
+
);
|
|
451
|
+
} ) }
|
|
452
|
+
</MenuGroup>
|
|
453
|
+
) }
|
|
454
|
+
</>
|
|
336
455
|
) }
|
|
337
456
|
</DropdownMenu>
|
|
338
457
|
{ isShortcutsModalOpen && (
|
|
@@ -340,6 +459,13 @@ function MoreMenu() {
|
|
|
340
459
|
onClose={ () => setIsShortcutsModalOpen( false ) }
|
|
341
460
|
/>
|
|
342
461
|
) }
|
|
462
|
+
{ activeModalAction && (
|
|
463
|
+
<MediaActionModal
|
|
464
|
+
action={ activeModalAction }
|
|
465
|
+
items={ items }
|
|
466
|
+
closeModal={ () => setActiveModalAction( null ) }
|
|
467
|
+
/>
|
|
468
|
+
) }
|
|
343
469
|
</>
|
|
344
470
|
);
|
|
345
471
|
}
|
|
@@ -378,6 +504,7 @@ function HistoryActions() {
|
|
|
378
504
|
activePanel,
|
|
379
505
|
canRestoreOriginal,
|
|
380
506
|
isSourceReplaced,
|
|
507
|
+
opensOriginal,
|
|
381
508
|
onRestoreOriginal,
|
|
382
509
|
} = useMediaEditorFrameContext();
|
|
383
510
|
const {
|
|
@@ -482,7 +609,9 @@ function HistoryActions() {
|
|
|
482
609
|
closeMenu();
|
|
483
610
|
} }
|
|
484
611
|
>
|
|
485
|
-
{
|
|
612
|
+
{ opensOriginal
|
|
613
|
+
? __( 'Edit original' )
|
|
614
|
+
: __( 'Restore original' ) }
|
|
486
615
|
</MenuItem>
|
|
487
616
|
</MenuGroup>
|
|
488
617
|
) }
|
|
@@ -546,6 +675,7 @@ function MediaEditorContent( {
|
|
|
546
675
|
aspectRatioPresets,
|
|
547
676
|
onClose,
|
|
548
677
|
onSaved,
|
|
678
|
+
onEditOriginal,
|
|
549
679
|
renderFrame,
|
|
550
680
|
noticesClassName = 'media-editor__snackbar',
|
|
551
681
|
noticesPortalElement,
|
|
@@ -607,11 +737,11 @@ function MediaEditorContent( {
|
|
|
607
737
|
const [ isPlacementActive, setIsPlacementActive ] = useState( false );
|
|
608
738
|
const [ isCanvasGestureActive, setIsCanvasGestureActive ] =
|
|
609
739
|
useState( false );
|
|
610
|
-
// Whether another attachment has replaced `id` in the
|
|
740
|
+
// Whether another attachment has replaced `id` in the image editor this
|
|
611
741
|
// session (today, the original via "Restore original image"). Stays a
|
|
612
|
-
// distinct flag (not derived from the
|
|
742
|
+
// distinct flag (not derived from the image editor) so a bare replacement
|
|
613
743
|
// counts as a change even though swapping the source resets the
|
|
614
|
-
//
|
|
744
|
+
// image editor's own dirty baseline.
|
|
615
745
|
const [ isSourceReplaced, setIsSourceReplaced ] = useState( false );
|
|
616
746
|
const placementControlTimerRef = useRef<
|
|
617
747
|
ReturnType< typeof setTimeout > | undefined
|
|
@@ -642,7 +772,7 @@ function MediaEditorContent( {
|
|
|
642
772
|
// exposed by the server as the root-level `edit_root` id on the
|
|
643
773
|
// attachment (edit context, embeddable via the `wp:edit-root` link).
|
|
644
774
|
// Fetch the original's record for the URL and natural dimensions the
|
|
645
|
-
//
|
|
775
|
+
// image editor needs to seed itself.
|
|
646
776
|
const originalId: number | undefined = sourceMedia?.edit_root;
|
|
647
777
|
const originalRecord = useSelect(
|
|
648
778
|
( select ) =>
|
|
@@ -727,10 +857,14 @@ function MediaEditorContent( {
|
|
|
727
857
|
// Restoring discards every pending edit, as the menu item says, so
|
|
728
858
|
// nothing staged against the attachment being replaced reaches a save.
|
|
729
859
|
clearEntityRecordEdits( 'postType', 'attachment', id );
|
|
860
|
+
if ( onEditOriginal && originalId ) {
|
|
861
|
+
onEditOriginal( originalId );
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
730
864
|
setIsSourceReplaced( true );
|
|
731
|
-
}, [ clearEntityRecordEdits, id ] );
|
|
865
|
+
}, [ clearEntityRecordEdits, id, onEditOriginal, originalId ] );
|
|
732
866
|
|
|
733
|
-
// A bare replacement has no
|
|
867
|
+
// A bare replacement has no image editor change, so OR the flag in explicitly.
|
|
734
868
|
const hasChanges = session.hasOutputEdits || hasEdits || isSourceReplaced;
|
|
735
869
|
|
|
736
870
|
const mediaType = getMediaTypeFromMimeType( media?.mime_type ).type;
|
|
@@ -1034,6 +1168,7 @@ function MediaEditorContent( {
|
|
|
1034
1168
|
onSave: saveMediaEditor,
|
|
1035
1169
|
canRestoreOriginal,
|
|
1036
1170
|
isSourceReplaced,
|
|
1171
|
+
opensOriginal: !! onEditOriginal,
|
|
1037
1172
|
onRestoreOriginal: handleRestoreOriginal,
|
|
1038
1173
|
};
|
|
1039
1174
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useMemo } from '@wordpress/element';
|
|
2
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
3
2
|
import {
|
|
4
3
|
DEFAULT_ASPECT_RATIOS,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '../../state';
|
|
4
|
+
type AspectRatioPreset,
|
|
5
|
+
} from '../../state/aspect-ratio-presets';
|
|
6
|
+
import { useMediaEditor } from '../../state';
|
|
8
7
|
|
|
9
8
|
interface UseCropOptionsArgs {
|
|
10
9
|
aspectRatioPresets?: AspectRatioPreset[];
|
|
@@ -38,8 +37,7 @@ export function getAspectRatioOptions(
|
|
|
38
37
|
/**
|
|
39
38
|
* Thin selector over the composite media-editor store for the Crop
|
|
40
39
|
* sidebar tab. Reads the cropOptions slice (preset key) and exposes
|
|
41
|
-
* the corresponding setters plus
|
|
42
|
-
* derivation.
|
|
40
|
+
* the corresponding setters plus the ratio the image editor has locked.
|
|
43
41
|
*
|
|
44
42
|
* No local React state, no refs, no synchronization effects — the
|
|
45
43
|
* composite store is the single source of truth.
|
|
@@ -52,17 +50,15 @@ export function useCropOptions( {
|
|
|
52
50
|
}: UseCropOptionsArgs = {} ): UseCropOptionsReturn {
|
|
53
51
|
const controller = useMediaEditor();
|
|
54
52
|
const { aspectRatioValue } = controller.cropOptions;
|
|
55
|
-
const cropperImage = controller.cropper.state.image;
|
|
56
53
|
|
|
57
54
|
const aspectRatioOptions = useMemo(
|
|
58
55
|
() => getAspectRatioOptions( aspectRatioPresets ),
|
|
59
56
|
[ aspectRatioPresets ]
|
|
60
57
|
);
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
);
|
|
59
|
+
// The image editor owns the locked ratio; the preset is what the
|
|
60
|
+
// dropdown shows.
|
|
61
|
+
const resolvedAspectRatio = controller.imageEditor.state.aspectRatio;
|
|
66
62
|
|
|
67
63
|
return {
|
|
68
64
|
aspectRatioValue,
|
|
@@ -4,12 +4,36 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
4
4
|
import { useCallback, useState } from '@wordpress/element';
|
|
5
5
|
import { __, sprintf } from '@wordpress/i18n';
|
|
6
6
|
import { store as noticesStore } from '@wordpress/notices';
|
|
7
|
+
import { getImageEdit, mapImageEdit } from '@wordpress/image-editor';
|
|
7
8
|
import type { Media } from '../media-editor-provider';
|
|
8
9
|
import type { MediaEditorSession } from '../../state';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A single modifier in the Core REST `/edit` payload. Order is
|
|
13
|
+
* significant — the server applies modifiers sequentially (see
|
|
14
|
+
* `WP_REST_Attachments_Controller::edit_media_item`).
|
|
15
|
+
*
|
|
16
|
+
* Shape/units:
|
|
17
|
+
* - `flip`: booleans per axis.
|
|
18
|
+
* - `rotate`: `angle` in degrees, clockwise-positive (matches the
|
|
19
|
+
* image editor's own convention; Core negates it internally for
|
|
20
|
+
* `WP_Image_Editor::rotate`, which is counterclockwise-positive).
|
|
21
|
+
* - `crop`: percentages (0–100) of the image's dimensions **at the
|
|
22
|
+
* moment the crop is applied**. Because modifiers are applied in
|
|
23
|
+
* order, after a preceding `rotate` the server's
|
|
24
|
+
* `WP_Image_Editor::get_size()` reports the full post-rotate AABB,
|
|
25
|
+
* so the percentages are of that AABB. Origin is top-left.
|
|
26
|
+
*/
|
|
27
|
+
type Modifier =
|
|
28
|
+
| {
|
|
29
|
+
type: 'flip';
|
|
30
|
+
args: { flip: { horizontal: boolean; vertical: boolean } };
|
|
31
|
+
}
|
|
32
|
+
| { type: 'rotate'; args: { angle: number } }
|
|
33
|
+
| {
|
|
34
|
+
type: 'crop';
|
|
35
|
+
args: { left: number; top: number; width: number; height: number };
|
|
36
|
+
};
|
|
13
37
|
|
|
14
38
|
// Details-tab edits are bundled into transformed `/edit` requests. Core's
|
|
15
39
|
// endpoint only accepts this whitelist.
|
|
@@ -65,7 +89,25 @@ function getCropModifiers( session: MediaEditorSession ): Modifier[] {
|
|
|
65
89
|
if ( ! session.hasOutputEdits ) {
|
|
66
90
|
return [];
|
|
67
91
|
}
|
|
68
|
-
|
|
92
|
+
const edit = getImageEdit( session.imageEditor.state );
|
|
93
|
+
if ( ! edit ) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Core applies modifiers in the order they arrive.
|
|
98
|
+
return mapImageEdit< Modifier >( edit, {
|
|
99
|
+
flip: ( flip ) => ( { type: 'flip', args: { flip } } ),
|
|
100
|
+
rotation: ( angle ) => ( { type: 'rotate', args: { angle } } ),
|
|
101
|
+
crop: ( { x, y, width, height } ) => ( {
|
|
102
|
+
type: 'crop',
|
|
103
|
+
args: {
|
|
104
|
+
left: x * 100,
|
|
105
|
+
top: y * 100,
|
|
106
|
+
width: width * 100,
|
|
107
|
+
height: height * 100,
|
|
108
|
+
},
|
|
109
|
+
} ),
|
|
110
|
+
} );
|
|
69
111
|
}
|
|
70
112
|
|
|
71
113
|
function getMetadataEdits(
|
|
@@ -190,7 +232,7 @@ export function useSaveMediaEditor( {
|
|
|
190
232
|
|
|
191
233
|
if ( next && next.id ) {
|
|
192
234
|
if ( next.id === id ) {
|
|
193
|
-
session.
|
|
235
|
+
session.reset();
|
|
194
236
|
}
|
|
195
237
|
onSaved?.( {
|
|
196
238
|
id: next.id,
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
|
-
import { useCallback, useEffect,
|
|
2
|
+
import { useCallback, useEffect, useState } from '@wordpress/element';
|
|
3
3
|
import { Spinner as WCSpinner } from '@wordpress/components';
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { ImageEditorCanvas } from '@wordpress/image-editor';
|
|
5
6
|
import { useMediaEditorContext } from '../media-editor-provider';
|
|
6
7
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
7
|
-
import {
|
|
8
|
-
import { useMediaEditor, resolveAspectRatio } from '../../state';
|
|
8
|
+
import { useMediaEditor } from '../../state';
|
|
9
9
|
|
|
10
10
|
export interface MediaEditorCanvasProps {
|
|
11
11
|
/** Whether external placement activity should reveal the grid. */
|
|
12
12
|
isPlacementActive?: boolean;
|
|
13
|
-
/** Fires when a canvas
|
|
13
|
+
/** Fires when a canvas gesture begins. */
|
|
14
14
|
onGestureStart?: () => void;
|
|
15
|
-
/** Fires when a canvas
|
|
15
|
+
/** Fires when a canvas gesture ends. */
|
|
16
16
|
onGestureEnd?: () => void;
|
|
17
17
|
/**
|
|
18
18
|
* Disable crop interaction on the canvas. Set while the edit is saving,
|
|
@@ -23,7 +23,7 @@ export interface MediaEditorCanvasProps {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Editing surface for image media in the media editor modal. Pulls
|
|
26
|
-
* its
|
|
26
|
+
* its image editor controller from the surrounding `<MediaEditorStateProvider>`
|
|
27
27
|
* so the bottom bar and Crop sidebar tab share the same state.
|
|
28
28
|
*
|
|
29
29
|
* Returns `null` for missing or non-image media so the modal's outer
|
|
@@ -43,29 +43,18 @@ export default function MediaEditorCanvas( {
|
|
|
43
43
|
}: MediaEditorCanvasProps ) {
|
|
44
44
|
const { media } = useMediaEditorContext();
|
|
45
45
|
const session = useMediaEditor();
|
|
46
|
-
const { aspectRatioValue } = session.cropOptions;
|
|
47
|
-
const cropperImage = session.cropper.state.image;
|
|
48
46
|
const { beginGesture, endGesture, setSourceImage } = session;
|
|
49
47
|
|
|
50
|
-
// Tracks whether the image pixels have actually loaded. The
|
|
48
|
+
// Tracks whether the image pixels have actually loaded. The image editor's
|
|
51
49
|
// geometry is driven by the known media dimensions, so its handles and
|
|
52
50
|
// overlays would otherwise appear before the image finishes streaming in.
|
|
53
51
|
// Stored with the URL it is for, so a new URL (restoring the original
|
|
54
|
-
// swaps it in place) counts as loading until the
|
|
52
|
+
// swaps it in place) counts as loading until the image editor reports back.
|
|
55
53
|
const [ settled, setSettled ] = useState< {
|
|
56
54
|
url: string | undefined;
|
|
57
55
|
status: 'loaded' | 'error';
|
|
58
56
|
} >();
|
|
59
57
|
|
|
60
|
-
// Resolved aspect ratio is derived from the preset key + the
|
|
61
|
-
// loaded image (for the "Original" preset). The reducer doesn't
|
|
62
|
-
// store this number — only the preset key — so it's a render-time
|
|
63
|
-
// derivation here.
|
|
64
|
-
const aspectRatio = useMemo(
|
|
65
|
-
() => resolveAspectRatio( aspectRatioValue, cropperImage ),
|
|
66
|
-
[ aspectRatioValue, cropperImage ]
|
|
67
|
-
);
|
|
68
|
-
|
|
69
58
|
const handleGestureStart = useCallback( () => {
|
|
70
59
|
beginGesture();
|
|
71
60
|
onGestureStart?.();
|
|
@@ -130,7 +119,7 @@ export default function MediaEditorCanvas( {
|
|
|
130
119
|
</div>
|
|
131
120
|
) }
|
|
132
121
|
{ /*
|
|
133
|
-
* The
|
|
122
|
+
* The image editor stays mounted while loading (hidden behind the
|
|
134
123
|
* spinner) so the image decodes off-screen and reveals in one paint
|
|
135
124
|
* instead of streaming in top-to-bottom. Until it's revealed it's
|
|
136
125
|
* non-interactive (`pointer-events: none` in CSS).
|
|
@@ -140,17 +129,17 @@ export default function MediaEditorCanvas( {
|
|
|
140
129
|
* by tabbing to it.
|
|
141
130
|
*/ }
|
|
142
131
|
<div
|
|
143
|
-
className={ clsx( 'media-editor-
|
|
132
|
+
className={ clsx( 'media-editor-canvas__image-editor', {
|
|
144
133
|
'is-loaded': status === 'loaded',
|
|
145
134
|
} ) }
|
|
146
135
|
>
|
|
147
|
-
<
|
|
136
|
+
<ImageEditorCanvas
|
|
148
137
|
src={ mediaUrl }
|
|
149
|
-
controller={ session.
|
|
150
|
-
aspectRatio={ aspectRatio }
|
|
138
|
+
controller={ session.imageEditor }
|
|
151
139
|
freeformCrop
|
|
152
|
-
|
|
153
|
-
|
|
140
|
+
// Keep the grid up while a sidebar placement control is in
|
|
141
|
+
// use; otherwise show it only while the crop is changing.
|
|
142
|
+
showGrid={ isPlacementActive ? true : 'interactive' }
|
|
154
143
|
onGestureStart={ handleGestureStart }
|
|
155
144
|
onGestureEnd={ handleGestureEnd }
|
|
156
145
|
onImageLoaded={ handleImageLoaded }
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/animations" as *;
|
|
2
2
|
@use "@wordpress/base-styles/colors" as *;
|
|
3
3
|
|
|
4
|
-
// The canvas wrapper fills the modal's canvas area so the
|
|
5
|
-
// sized parent (the
|
|
4
|
+
// The canvas wrapper fills the modal's canvas area so the image editor has a
|
|
5
|
+
// sized parent (the image editor uses 100% width/height of its container).
|
|
6
6
|
// `position: relative` establishes a stacking context for any future
|
|
7
7
|
// overlays rendered inside the canvas.
|
|
8
8
|
.media-editor-canvas {
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
width: 100%;
|
|
11
11
|
height: 100%;
|
|
12
12
|
|
|
13
|
-
// The
|
|
13
|
+
// The image editor stays mounted while loading so the image decodes behind the
|
|
14
14
|
// spinner and reveals in one paint. It's hidden and non-interactive until
|
|
15
15
|
// the image has loaded, then fades in.
|
|
16
|
-
&
|
|
16
|
+
&__image-editor {
|
|
17
17
|
width: 100%;
|
|
18
18
|
height: 100%;
|
|
19
19
|
opacity: 0;
|
|
20
20
|
pointer-events: none;
|
|
21
21
|
|
|
22
22
|
// Explicit `opacity: 1` (not just the animation's fill mode) keeps the
|
|
23
|
-
//
|
|
23
|
+
// image editor visible for reduced-motion users, since `animation__fade-in`
|
|
24
24
|
// is gated behind `@media not (prefers-reduced-motion)`.
|
|
25
25
|
&.is-loaded {
|
|
26
26
|
opacity: 1;
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
transform: translate(-50%, -50%);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// Centered fallback shown in place of the
|
|
39
|
+
// Centered fallback shown in place of the image editor when the image
|
|
40
40
|
// fails to load.
|
|
41
41
|
&__error {
|
|
42
42
|
display: flex;
|