@wordpress/media-editor 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/build/components/media-editor/index.cjs +229 -126
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +41 -11
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +15 -18
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +26 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +13 -12
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +143 -37
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +12 -6
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +41 -74
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +217 -117
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +123 -41
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +12 -7
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +122 -87
- package/build-style/style.css +121 -87
- package/build-types/components/media-editor/index.d.ts +25 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +40 -54
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +27 -24
- package/src/components/media-editor/index.tsx +372 -142
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +4 -1
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +195 -37
- package/src/components/media-preview/style.scss +11 -32
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +34 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +162 -242
- package/src/style.scss +2 -1
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1,33 +1,98 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import { speak } from "@wordpress/a11y";
|
|
3
|
+
import { Button, Spinner } from "@wordpress/components";
|
|
4
|
+
import { useCopyToClipboard } from "@wordpress/compose";
|
|
5
|
+
import { useEffect, useState } from "@wordpress/element";
|
|
6
|
+
import { __, _x, sprintf } from "@wordpress/i18n";
|
|
7
|
+
import { check, copy, download, error, folder } from "@wordpress/icons";
|
|
8
|
+
import { EmptyState } from "@wordpress/ui";
|
|
4
9
|
import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
|
|
5
10
|
import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
12
|
// packages/media-editor/src/components/media-preview/index.tsx
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Returns the value of one of the attachment fields for the media, or an
|
|
15
|
+
* empty string if the field isn't available.
|
|
16
|
+
*
|
|
17
|
+
* @param fields The attachment fields.
|
|
18
|
+
* @param fieldId The id of the field to read.
|
|
19
|
+
* @param media The media record.
|
|
20
|
+
*/
|
|
21
|
+
function getFieldValue(fields, fieldId, media) {
|
|
22
|
+
const value = fields.find(({ id }) => id === fieldId)?.getValue?.({ item: media });
|
|
23
|
+
return typeof value === "string" ? value : "";
|
|
24
|
+
}
|
|
25
|
+
const COPY_FEEDBACK_TIMEOUT = 2e3;
|
|
26
|
+
const COPY_RESULT_ICONS = {
|
|
27
|
+
idle: copy,
|
|
28
|
+
copied: check,
|
|
29
|
+
error
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Copies the text and shows the result on the copy button, following the
|
|
33
|
+
* Copy to Clipboard design system pattern.
|
|
34
|
+
*
|
|
35
|
+
* @param text The text to copy.
|
|
36
|
+
*/
|
|
37
|
+
function useCopyWithFeedback(text) {
|
|
38
|
+
const [feedback, setFeedback] = useState({
|
|
39
|
+
result: "idle",
|
|
40
|
+
id: 0
|
|
28
41
|
});
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (feedback.result === "idle") return;
|
|
44
|
+
const timeoutId = setTimeout(() => setFeedback({
|
|
45
|
+
result: "idle",
|
|
46
|
+
id: 0
|
|
47
|
+
}), COPY_FEEDBACK_TIMEOUT);
|
|
48
|
+
return () => clearTimeout(timeoutId);
|
|
49
|
+
}, [feedback]);
|
|
50
|
+
function report(result, message) {
|
|
51
|
+
setFeedback((current) => ({
|
|
52
|
+
result,
|
|
53
|
+
id: current.id + 1
|
|
54
|
+
}));
|
|
55
|
+
speak(message);
|
|
56
|
+
}
|
|
57
|
+
const ref = useCopyToClipboard(text, () => report("copied", __("Copied URL to clipboard.")), () => report("error", __("Couldn't copy URL to clipboard.")));
|
|
58
|
+
return {
|
|
59
|
+
result: feedback.result,
|
|
60
|
+
ref
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function MediaPreviewFileActions({ mediaUrl }) {
|
|
64
|
+
const { result, ref } = useCopyWithFeedback(mediaUrl);
|
|
65
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
66
|
+
__next40pxDefaultSize: true,
|
|
67
|
+
variant: "primary",
|
|
68
|
+
href: mediaUrl,
|
|
69
|
+
target: "_blank",
|
|
70
|
+
download: true,
|
|
71
|
+
icon: download,
|
|
72
|
+
children: __("Download")
|
|
73
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
74
|
+
__next40pxDefaultSize: true,
|
|
75
|
+
variant: "secondary",
|
|
76
|
+
ref,
|
|
77
|
+
icon: COPY_RESULT_ICONS[result],
|
|
78
|
+
children: __("Copy URL")
|
|
79
|
+
})] });
|
|
29
80
|
}
|
|
30
|
-
function
|
|
81
|
+
function MediaPreviewFileInfo({ mediaUrl, fileName, fileDetails }) {
|
|
82
|
+
return /* @__PURE__ */ jsxs(EmptyState.Root, { children: [
|
|
83
|
+
/* @__PURE__ */ jsx(EmptyState.Icon, { icon: folder }),
|
|
84
|
+
!!fileName && /* @__PURE__ */ jsx(EmptyState.Title, {
|
|
85
|
+
className: "media-editor-preview__file-name",
|
|
86
|
+
children: fileName
|
|
87
|
+
}),
|
|
88
|
+
!!fileDetails && /* @__PURE__ */ jsx(EmptyState.Description, { children: fileDetails }),
|
|
89
|
+
/* @__PURE__ */ jsx(EmptyState.Actions, {
|
|
90
|
+
className: "media-editor-preview__actions",
|
|
91
|
+
children: /* @__PURE__ */ jsx(MediaPreviewFileActions, { mediaUrl })
|
|
92
|
+
})
|
|
93
|
+
] });
|
|
94
|
+
}
|
|
95
|
+
function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, fileName, fileDetails, onLoad, onError, loadingState }) {
|
|
31
96
|
switch (previewType) {
|
|
32
97
|
case "image": return /* @__PURE__ */ jsx("img", {
|
|
33
98
|
className: loadingState === "loaded" ? "loaded" : "",
|
|
@@ -55,14 +120,14 @@ function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mim
|
|
|
55
120
|
"aria-label": __("Embed of the selected PDF file."),
|
|
56
121
|
children: /* @__PURE__ */ jsx(MediaPreviewFileInfo, {
|
|
57
122
|
mediaUrl,
|
|
58
|
-
|
|
59
|
-
|
|
123
|
+
fileName,
|
|
124
|
+
fileDetails
|
|
60
125
|
})
|
|
61
126
|
});
|
|
62
127
|
default: return /* @__PURE__ */ jsx(MediaPreviewFileInfo, {
|
|
63
128
|
mediaUrl,
|
|
64
|
-
|
|
65
|
-
|
|
129
|
+
fileName,
|
|
130
|
+
fileDetails
|
|
66
131
|
});
|
|
67
132
|
}
|
|
68
133
|
}
|
|
@@ -75,25 +140,41 @@ function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mim
|
|
|
75
140
|
*/
|
|
76
141
|
function MediaPreview(props) {
|
|
77
142
|
const [loadingState, setLoadingState] = useState("loading");
|
|
78
|
-
const { media } = useMediaEditorContext();
|
|
143
|
+
const { media, fields } = useMediaEditorContext();
|
|
79
144
|
const { source_url: mediaUrl, mime_type: mimeType, alt_text: altText, title } = media || {};
|
|
80
145
|
const mediaType = getMediaTypeFromMimeType(mimeType);
|
|
81
146
|
const previewType = mimeType === "application/pdf" && window.navigator.pdfViewerEnabled ? "pdf" : mediaType.type;
|
|
82
147
|
if (!mediaUrl) return /* @__PURE__ */ jsx("div", {
|
|
83
|
-
className: "media-editor-preview media-editor-preview--empty",
|
|
84
|
-
children: /* @__PURE__ */ jsx(
|
|
85
|
-
});
|
|
86
|
-
if (loadingState === "error") return /* @__PURE__ */ jsxs("div", {
|
|
87
|
-
className: "media-editor-preview media-editor-preview--error",
|
|
88
|
-
children: [/* @__PURE__ */ jsx("p", { children: __("Failed to load media file.") }), /* @__PURE__ */ jsx("p", {
|
|
89
|
-
className: "media-editor-preview__url",
|
|
90
|
-
children: mediaUrl
|
|
91
|
-
})]
|
|
148
|
+
className: "media-editor-preview media-editor-preview--empty is-placeholder",
|
|
149
|
+
children: /* @__PURE__ */ jsxs(EmptyState.Root, { children: [/* @__PURE__ */ jsx(EmptyState.Icon, { icon: folder }), /* @__PURE__ */ jsx(EmptyState.Title, { children: __("No media file available.") })] })
|
|
92
150
|
});
|
|
93
151
|
const displayTitle = typeof title === "string" ? title : title?.rendered || title?.raw;
|
|
152
|
+
const fileName = media && getFieldValue(fields, "filename", media) || displayTitle;
|
|
153
|
+
const fileSize = media ? getFieldValue(fields, "filesize", media) : "";
|
|
154
|
+
const fileDetails = mimeType && fileSize ? sprintf(
|
|
155
|
+
/** translators: 1: File type, e.g. "application/zip". 2: File size, e.g. "2.4 MB". */
|
|
156
|
+
_x("%1$s · %2$s", "file type and size"),
|
|
157
|
+
mimeType,
|
|
158
|
+
fileSize
|
|
159
|
+
) : mimeType || fileSize;
|
|
160
|
+
if (loadingState === "error") return /* @__PURE__ */ jsx("div", {
|
|
161
|
+
className: "media-editor-preview media-editor-preview--error is-placeholder",
|
|
162
|
+
children: /* @__PURE__ */ jsxs(EmptyState.Root, { children: [
|
|
163
|
+
/* @__PURE__ */ jsx(EmptyState.Icon, { icon: folder }),
|
|
164
|
+
/* @__PURE__ */ jsx(EmptyState.Title, { children: __("Failed to load media file.") }),
|
|
165
|
+
!!fileName && /* @__PURE__ */ jsx(EmptyState.Description, {
|
|
166
|
+
className: "media-editor-preview__file-name",
|
|
167
|
+
children: fileName
|
|
168
|
+
}),
|
|
169
|
+
/* @__PURE__ */ jsx(EmptyState.Actions, {
|
|
170
|
+
className: "media-editor-preview__actions",
|
|
171
|
+
children: /* @__PURE__ */ jsx(MediaPreviewFileActions, { mediaUrl })
|
|
172
|
+
})
|
|
173
|
+
] })
|
|
174
|
+
});
|
|
94
175
|
return /* @__PURE__ */ jsxs("div", {
|
|
95
176
|
...props,
|
|
96
|
-
className:
|
|
177
|
+
className: clsx("media-editor-preview", `media-editor-preview--${previewType}`, { "is-placeholder": previewType === "application" }),
|
|
97
178
|
children: [previewType === "image" && loadingState === "loading" && /* @__PURE__ */ jsx("div", {
|
|
98
179
|
className: "media-editor-preview__spinner",
|
|
99
180
|
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
@@ -102,7 +183,8 @@ function MediaPreview(props) {
|
|
|
102
183
|
mediaUrl,
|
|
103
184
|
altText,
|
|
104
185
|
displayTitle,
|
|
105
|
-
|
|
186
|
+
fileName,
|
|
187
|
+
fileDetails,
|
|
106
188
|
onLoad: () => setLoadingState("loaded"),
|
|
107
189
|
onError: () => setLoadingState("error"),
|
|
108
190
|
loadingState
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import { Spinner as WCSpinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tpreviewType: string;\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tdisplayTitle,\n\tmimeType,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t<p className=\"media-editor-preview__file-name\">{ displayTitle }</p>\n\t\t\t<p className=\"media-editor-preview__mime-type\">{ mimeType }</p>\n\t\t\t{ /* eslint-disable-next-line react/jsx-no-target-blank */ }\n\t\t\t<a\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\trel=\"noopener\"\n\t\t\t\tclassName=\"media-editor-preview__download-link\"\n\t\t\t>\n\t\t\t\t{ __( 'View file' ) }\n\t\t\t</a>\n\t\t</div>\n\t);\n}\n\nfunction MediaPreviewContent( {\n\tpreviewType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tmimeType,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( previewType ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tcase 'pdf':\n\t\t\t// The browser renders the children instead of the PDF when it\n\t\t\t// can't display it, e.g. when the request fails.\n\t\t\treturn (\n\t\t\t\t<object\n\t\t\t\t\tclassName=\"media-editor-preview__pdf\"\n\t\t\t\t\t// Ask the viewer to fit the whole page rather than the\n\t\t\t\t\t// width. Chrome reads `view`, Firefox reads `zoom`, and\n\t\t\t\t\t// Safari ignores both.\n\t\t\t\t\tdata={ `${ mediaUrl }#view=Fit&zoom=page-fit` }\n\t\t\t\t\ttype=\"application/pdf\"\n\t\t\t\t\taria-label={ __( 'Embed of the selected PDF file.' ) }\n\t\t\t\t>\n\t\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t\t/>\n\t\t\t\t</object>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t/>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\t// Without a built-in PDF viewer (e.g. on most mobile browsers), show\n\t// the file info instead of an embed that can't render.\n\tconst previewType =\n\t\tmimeType === 'application/pdf' && window.navigator.pdfViewerEnabled\n\t\t\t? 'pdf'\n\t\t\t: mediaType.type;\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty\">\n\t\t\t\t<p>{ __( 'No media file available.' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error\">\n\t\t\t\t<p>{ __( 'Failed to load media file.' ) }</p>\n\t\t\t\t<p className=\"media-editor-preview__url\">{ mediaUrl }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ `media-editor-preview media-editor-preview--${ previewType }` }\n\t\t>\n\t\t\t{ previewType === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tpreviewType={ previewType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tmimeType={ mimeType }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,qBAAsB,EAC9B,UACA,cACA,YAC8B;CAC9B,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACC,oBAAC,KAAD;IAAG,WAAU;IAAoC,UAAA;GAAiB,CAAA;GAClE,oBAAC,KAAD;IAAG,WAAU;IAAoC,UAAA;GAAa,CAAA;GAE9D,oBAAC,KAAD;IACC,MAAO;IACP,QAAO;IACP,KAAI;IACJ,WAAU;IAER,UAAA,GAAI,WAAY;GAChB,CAAA;EACC;;AAEP;AAEA,SAAS,oBAAqB,EAC7B,aACA,UACA,SACA,cACA,UACA,QACA,SACA,gBAC6B;CAC7B,QAAS,aAAT;EACC,KAAK,SACJ,OACC,oBAAC,OAAD;GACC,WAAY,iBAAiB,WAAW,WAAW;GACnD,KAAM;GACN,KAAM,WAAW;GACR;GACC;EACV,CAAA;EAEH,KAAK,SACJ,OACC,oBAAC,SAAD;GAAO,KAAM;GAAW,UAAA;GAAmB;GACxC,UAAA;EACI,CAAA;EAET,KAAK,SACJ,OACC,oBAAC,SAAD;GAAO,KAAM;GAAW,UAAA;GAAmB;GACxC,UAAA;EACI,CAAA;EAET,KAAK,OAGJ,OACC,oBAAC,UAAD;GACC,WAAU;GAIV,MAAO,GAAI,SAAU;GACrB,MAAK;GACL,cAAa,GAAI,iCAAkC;GAEnD,UAAA,oBAAC,sBAAD;IACY;IACI;IACJ;GACX,CAAA;EACM,CAAA;EAEV,SACC,OACC,oBAAC,sBAAD;GACY;GACI;GACJ;EACX,CAAA;CAEJ;AACD;;;;;;;;AASA,SAAwB,aAAc,OAA2B;CAChE,MAAM,CAAE,cAAc,mBAAoB,SAEvC,SAAU;CACb,MAAM,EAAE,UAAU,sBAAsB;CAExC,MAAM,EACL,YAAY,UACZ,WAAW,UACX,UAAU,SACV,UACG,SAAS,CAAC;CAEd,MAAM,YAAY,yBAA0B,QAAS;CAIrD,MAAM,cACL,aAAa,qBAAqB,OAAO,UAAU,mBAChD,QACA,UAAU;CAEd,IAAK,CAAE,UACN,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAAC,KAAD,EAAA,UAAK,GAAI,0BAA2B,EAAM,CAAA;CACtC,CAAA;CAIP,IAAK,iBAAiB,SACrB,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACC,oBAAC,KAAD,EAAA,UAAK,GAAI,4BAA6B,EAAM,CAAA,GAC5C,oBAAC,KAAD;GAAG,WAAU;GAA8B,UAAA;EAAa,CAAA,CACpD;;CAIP,MAAM,eACL,OAAO,UAAU,WAAW,QAAQ,OAAO,YAAY,OAAO;CAE/D,OACC,qBAAC,OAAD;EACC,GAAK;EACL,WAAY,8CAA+C;EAF5D,UAAA,CAIG,gBAAgB,WAAW,iBAAiB,aAC7C,oBAAC,OAAD;GAAK,WAAU;GACd,UAAA,oBAACA,SAAD,CAAY,CAAA;EACR,CAAA,GAEN,oBAAC,qBAAD;GACe;GACH;GACD;GACK;GACJ;GACX,cAAe,gBAAiB,QAAS;GACzC,eAAgB,gBAAiB,OAAQ;GAC1B;EACf,CAAA,CACG;;AAEP"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["errorIcon","WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { speak } from '@wordpress/a11y';\nimport { Button, Spinner as WCSpinner } from '@wordpress/components';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tcopy,\n\tdownload,\n\terror as errorIcon,\n\tfolder,\n} from '@wordpress/icons';\nimport { EmptyState } from '@wordpress/ui';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tpreviewType: string;\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tfileName?: string;\n\tfileDetails?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\n/**\n * Returns the value of one of the attachment fields for the media, or an\n * empty string if the field isn't available.\n *\n * @param fields The attachment fields.\n * @param fieldId The id of the field to read.\n * @param media The media record.\n */\nfunction getFieldValue(\n\tfields: Array< {\n\t\tid: string;\n\t\tgetValue?: ( args: { item: Media } ) => unknown;\n\t} >,\n\tfieldId: string,\n\tmedia: Media\n): string {\n\tconst field = fields.find( ( { id } ) => id === fieldId );\n\tconst value = field?.getValue?.( { item: media } );\n\treturn typeof value === 'string' ? value : '';\n}\n\nconst COPY_FEEDBACK_TIMEOUT = 2000;\n\ntype CopyResult = 'idle' | 'copied' | 'error';\n\nconst COPY_RESULT_ICONS = {\n\tidle: copy,\n\tcopied: check,\n\terror: errorIcon,\n};\n\n/**\n * Copies the text and shows the result on the copy button, following the\n * Copy to Clipboard design system pattern.\n *\n * @param text The text to copy.\n */\nfunction useCopyWithFeedback( text: string ) {\n\t// Bump the id on every result, so a repeat of the same result restarts\n\t// the time the icon stays visible.\n\tconst [ feedback, setFeedback ] = useState< {\n\t\tresult: CopyResult;\n\t\tid: number;\n\t} >( { result: 'idle', id: 0 } );\n\n\tuseEffect( () => {\n\t\tif ( feedback.result === 'idle' ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeoutId = setTimeout(\n\t\t\t() => setFeedback( { result: 'idle', id: 0 } ),\n\t\t\tCOPY_FEEDBACK_TIMEOUT\n\t\t);\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ feedback ] );\n\n\tfunction report( result: Exclude< CopyResult, 'idle' >, message: string ) {\n\t\tsetFeedback( ( current ) => ( { result, id: current.id + 1 } ) );\n\t\tspeak( message );\n\t}\n\n\tconst ref = useCopyToClipboard(\n\t\ttext,\n\t\t() => report( 'copied', __( 'Copied URL to clipboard.' ) ),\n\t\t() => report( 'error', __( \"Couldn't copy URL to clipboard.\" ) )\n\t);\n\n\treturn { result: feedback.result, ref };\n}\n\nfunction MediaPreviewFileActions( { mediaUrl }: { mediaUrl: string } ) {\n\tconst { result, ref } = useCopyWithFeedback( mediaUrl );\n\n\treturn (\n\t\t<>\n\t\t\t{ /*\n\t\t\t * Browsers ignore `download` for cross-origin URLs, e.g. media\n\t\t\t * offloaded to a CDN, and show the file instead. Open it in a new\n\t\t\t * tab so it doesn't replace the editor.\n\t\t\t */ }\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvariant=\"primary\"\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\tdownload\n\t\t\t\ticon={ download }\n\t\t\t>\n\t\t\t\t{ __( 'Download' ) }\n\t\t\t</Button>\n\t\t\t{ /* The label stays the same, and the icon shows the result. */ }\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tref={ ref }\n\t\t\t\ticon={ COPY_RESULT_ICONS[ result ] }\n\t\t\t>\n\t\t\t\t{ __( 'Copy URL' ) }\n\t\t\t</Button>\n\t\t</>\n\t);\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tfileName?: string;\n\tfileDetails?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tfileName,\n\tfileDetails,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<EmptyState.Root>\n\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t{ !! fileName && (\n\t\t\t\t<EmptyState.Title className=\"media-editor-preview__file-name\">\n\t\t\t\t\t{ fileName }\n\t\t\t\t</EmptyState.Title>\n\t\t\t) }\n\t\t\t{ !! fileDetails && (\n\t\t\t\t<EmptyState.Description>{ fileDetails }</EmptyState.Description>\n\t\t\t) }\n\t\t\t<EmptyState.Actions className=\"media-editor-preview__actions\">\n\t\t\t\t<MediaPreviewFileActions mediaUrl={ mediaUrl } />\n\t\t\t</EmptyState.Actions>\n\t\t</EmptyState.Root>\n\t);\n}\n\nfunction MediaPreviewContent( {\n\tpreviewType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tfileName,\n\tfileDetails,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( previewType ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tcase 'pdf':\n\t\t\t// The browser renders the children instead of the PDF when it\n\t\t\t// can't display it, e.g. when the request fails.\n\t\t\treturn (\n\t\t\t\t<object\n\t\t\t\t\tclassName=\"media-editor-preview__pdf\"\n\t\t\t\t\t// Ask the viewer to fit the whole page rather than the\n\t\t\t\t\t// width. Chrome reads `view`, Firefox reads `zoom`, and\n\t\t\t\t\t// Safari ignores both.\n\t\t\t\t\tdata={ `${ mediaUrl }#view=Fit&zoom=page-fit` }\n\t\t\t\t\ttype=\"application/pdf\"\n\t\t\t\t\taria-label={ __( 'Embed of the selected PDF file.' ) }\n\t\t\t\t>\n\t\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\t\tfileName={ fileName }\n\t\t\t\t\t\tfileDetails={ fileDetails }\n\t\t\t\t\t/>\n\t\t\t\t</object>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\tfileName={ fileName }\n\t\t\t\t\tfileDetails={ fileDetails }\n\t\t\t\t/>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media, fields } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\t// Without a built-in PDF viewer (e.g. on most mobile browsers), show\n\t// the file info instead of an embed that can't render.\n\tconst previewType =\n\t\tmimeType === 'application/pdf' && window.navigator.pdfViewerEnabled\n\t\t\t? 'pdf'\n\t\t\t: mediaType.type;\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty is-placeholder\">\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'No media file available.' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t</EmptyState.Root>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\t// Read through the attachment fields, so the values match the Details\n\t// panel. Without a filename field, fall back to the title.\n\tconst fileName =\n\t\t( media && getFieldValue( fields, 'filename', media ) ) || displayTitle;\n\tconst fileSize = media ? getFieldValue( fields, 'filesize', media ) : '';\n\tconst fileDetails =\n\t\tmimeType && fileSize\n\t\t\t? sprintf(\n\t\t\t\t\t/* translators: 1: File type, e.g. \"application/zip\". 2: File size, e.g. \"2.4 MB\". */\n\t\t\t\t\t_x( '%1$s · %2$s', 'file type and size' ),\n\t\t\t\t\tmimeType,\n\t\t\t\t\tfileSize\n\t\t\t\t)\n\t\t\t: mimeType || fileSize;\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error is-placeholder\">\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'Failed to load media file.' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t\t{ !! fileName && (\n\t\t\t\t\t\t<EmptyState.Description className=\"media-editor-preview__file-name\">\n\t\t\t\t\t\t\t{ fileName }\n\t\t\t\t\t\t</EmptyState.Description>\n\t\t\t\t\t) }\n\t\t\t\t\t<EmptyState.Actions className=\"media-editor-preview__actions\">\n\t\t\t\t\t\t<MediaPreviewFileActions mediaUrl={ mediaUrl } />\n\t\t\t\t\t</EmptyState.Actions>\n\t\t\t\t</EmptyState.Root>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ clsx(\n\t\t\t\t'media-editor-preview',\n\t\t\t\t`media-editor-preview--${ previewType }`,\n\t\t\t\t{\n\t\t\t\t\t// Media with no preview of its own shows the file info.\n\t\t\t\t\t'is-placeholder': previewType === 'application',\n\t\t\t\t}\n\t\t\t) }\n\t\t>\n\t\t\t{ previewType === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tpreviewType={ previewType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tfileName={ fileName }\n\t\t\t\tfileDetails={ fileDetails }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":"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"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { __ } from "@wordpress/i18n";
|
|
2
|
-
import { ORIGINAL_ASPECT_RATIO } from "../image-editor/index.mjs";
|
|
3
2
|
// packages/media-editor/src/state/aspect-ratio-presets.ts
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Sentinel value for "Original" aspect ratio — resolved at runtime
|
|
5
|
+
* to the image's natural width / height.
|
|
6
|
+
*/
|
|
7
|
+
const ORIGINAL_ASPECT_RATIO = -1;
|
|
8
|
+
/**
|
|
9
|
+
* The presets the editor offers by default. They live here rather than
|
|
10
|
+
* in the image editor package, because which ratios to offer, and what
|
|
11
|
+
* to call them, is a product choice. The package takes a plain number.
|
|
7
12
|
*/
|
|
8
13
|
const DEFAULT_ASPECT_RATIOS = [
|
|
9
14
|
{
|
|
@@ -12,7 +17,7 @@ const DEFAULT_ASPECT_RATIOS = [
|
|
|
12
17
|
},
|
|
13
18
|
{
|
|
14
19
|
label: __("Original"),
|
|
15
|
-
value:
|
|
20
|
+
value: -1
|
|
16
21
|
},
|
|
17
22
|
{
|
|
18
23
|
label: __("Square (1:1)"),
|
|
@@ -32,17 +37,17 @@ const DEFAULT_ASPECT_RATIOS = [
|
|
|
32
37
|
},
|
|
33
38
|
{
|
|
34
39
|
label: __("Classic portrait (3:4)"),
|
|
35
|
-
value:
|
|
40
|
+
value: .75
|
|
36
41
|
},
|
|
37
42
|
{
|
|
38
43
|
label: __("Photo (3:2)"),
|
|
39
|
-
value:
|
|
44
|
+
value: 1.5
|
|
40
45
|
},
|
|
41
46
|
{
|
|
42
47
|
label: __("Photo portrait (2:3)"),
|
|
43
48
|
value: 2 / 3
|
|
44
49
|
}
|
|
45
50
|
];
|
|
46
|
-
export { DEFAULT_ASPECT_RATIOS };
|
|
51
|
+
export { DEFAULT_ASPECT_RATIOS, ORIGINAL_ASPECT_RATIO };
|
|
47
52
|
|
|
48
53
|
//# sourceMappingURL=aspect-ratio-presets.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aspect-ratio-presets.mjs","names":[],"sources":["../../src/state/aspect-ratio-presets.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\
|
|
1
|
+
{"version":3,"file":"aspect-ratio-presets.mjs","names":[],"sources":["../../src/state/aspect-ratio-presets.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/**\n\t * The aspect ratio value (width / height). 0 = free,\n\t * `ORIGINAL_ASPECT_RATIO` = the image's own ratio.\n\t */\n\tvalue: number;\n}\n\n/**\n * Sentinel value for \"Original\" aspect ratio — resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\n/**\n * The presets the editor offers by default. They live here rather than\n * in the image editor package, because which ratios to offer, and what\n * to call them, is a product choice. The package takes a plain number.\n */\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],"mappings":";;;;;;AAmBA,MAAa,wBAAwB;;;;;;AAOrC,MAAa,wBAA6C;CACzD;EAAE,OAAO,GAAI,MAAO;EAAG,OAAO;CAAE;CAChC;EAAE,OAAO,GAAI,UAAW;EAAG,OAAA;CAA6B;CACxD;EAAE,OAAO,GAAI,cAAe;EAAG,OAAO;CAAE;CACxC;EAAE,OAAO,GAAI,kBAAmB;EAAG,OAAO,KAAK;CAAE;CACjD;EAAE,OAAO,GAAI,iBAAkB;EAAG,OAAO,IAAI;CAAG;CAChD;EAAE,OAAO,GAAI,eAAgB;EAAG,OAAO,IAAI;CAAE;CAC7C;EAAE,OAAO,GAAI,wBAAyB;EAAG,OAAO;CAAM;CACtD;EAAE,OAAO,GAAI,aAAc;EAAG,OAAO;CAAM;CAC3C;EAAE,OAAO,GAAI,sBAAuB;EAAG,OAAO,IAAI;CAAE;AACrD"}
|
|
@@ -1,61 +1,33 @@
|
|
|
1
1
|
import fastDeepEqual from "fast-deep-equal/es6/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { areImageEditorStatesEqual, createImageEditorState } from "@wordpress/image-editor";
|
|
3
3
|
import { DEFAULT_CROP_OPTIONS } from "./types.mjs";
|
|
4
4
|
// packages/media-editor/src/state/composite-reducer.ts
|
|
5
5
|
/**
|
|
6
|
-
* Pure
|
|
6
|
+
* Pure reducer for the media editor.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
* in one transaction (used by undo/redo).
|
|
8
|
+
* The image editor works out its own next state (through the controller from
|
|
9
|
+
* `@wordpress/image-editor`) and this reducer stores it. The reducer
|
|
10
|
+
* also owns the sidebar crop options and the named edits.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
* stacks live in the `useMediaEditorState` hook that wraps it.
|
|
12
|
+
* This reducer keeps no history; `useMediaEditorState` does.
|
|
15
13
|
*
|
|
16
|
-
* @param state Current
|
|
14
|
+
* @param state Current state.
|
|
17
15
|
* @param action Action to apply.
|
|
18
|
-
* @return Next
|
|
16
|
+
* @return Next state.
|
|
19
17
|
*/
|
|
20
18
|
function mediaEditorReducer(state, action) {
|
|
21
19
|
switch (action.type) {
|
|
22
|
-
case "
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
case "SET_ASPECT_RATIO_VALUE": {
|
|
31
|
-
const { presetKey, resolved, visualSize } = action.payload;
|
|
32
|
-
const shouldReshape = resolved !== void 0 && resolved > 0 && visualSize.width > 0 && visualSize.height > 0;
|
|
33
|
-
const nextCropOptions = {
|
|
20
|
+
case "SET_IMAGE_EDITOR": return action.payload === state.imageEditor ? state : {
|
|
21
|
+
...state,
|
|
22
|
+
imageEditor: action.payload
|
|
23
|
+
};
|
|
24
|
+
case "SET_ASPECT_RATIO_VALUE": return state.cropOptions.aspectRatioValue === action.payload ? state : {
|
|
25
|
+
...state,
|
|
26
|
+
cropOptions: {
|
|
34
27
|
...state.cropOptions,
|
|
35
|
-
aspectRatioValue:
|
|
36
|
-
};
|
|
37
|
-
if (!shouldReshape) {
|
|
38
|
-
if (state.cropOptions.aspectRatioValue === presetKey) return state;
|
|
39
|
-
return {
|
|
40
|
-
...state,
|
|
41
|
-
cropOptions: nextCropOptions
|
|
42
|
-
};
|
|
28
|
+
aspectRatioValue: action.payload
|
|
43
29
|
}
|
|
44
|
-
|
|
45
|
-
const nextCropper = cropperReducer(state.cropper, {
|
|
46
|
-
type: "SET_CROP_RECT",
|
|
47
|
-
payload: newCropRect
|
|
48
|
-
});
|
|
49
|
-
return {
|
|
50
|
-
...state,
|
|
51
|
-
cropper: nextCropper,
|
|
52
|
-
cropOptions: nextCropOptions
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
case "RESET": {
|
|
56
|
-
const next = buildInitialMediaEditorState(cropperReducer(state.cropper, { type: "RESET" }));
|
|
57
|
-
return areMediaEditorStatesEqual(state, next) ? state : next;
|
|
58
|
-
}
|
|
30
|
+
};
|
|
59
31
|
case "SET_EDIT": {
|
|
60
32
|
const { name, value } = action.payload;
|
|
61
33
|
if (value === void 0) {
|
|
@@ -76,42 +48,35 @@ function mediaEditorReducer(state, action) {
|
|
|
76
48
|
}
|
|
77
49
|
};
|
|
78
50
|
}
|
|
79
|
-
case "
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
type: "SET_CROP_RECT",
|
|
83
|
-
payload: action.payload
|
|
84
|
-
});
|
|
85
|
-
if (nextCropper === state.cropper) return state;
|
|
86
|
-
return {
|
|
87
|
-
...state,
|
|
88
|
-
cropper: nextCropper
|
|
89
|
-
};
|
|
51
|
+
case "RESET": {
|
|
52
|
+
const next = buildInitialMediaEditorState(createImageEditorState({ image: state.imageEditor.image }));
|
|
53
|
+
return areMediaEditorStatesEqual(state, next) ? state : next;
|
|
90
54
|
}
|
|
55
|
+
case "RESTORE_SNAPSHOT": return action.payload;
|
|
91
56
|
}
|
|
92
57
|
}
|
|
93
58
|
/**
|
|
94
|
-
* Value-equality check for two
|
|
95
|
-
*
|
|
59
|
+
* Value-equality check for two media editor states. The history uses it
|
|
60
|
+
* to skip snapshots when an action turned out to be a no-op.
|
|
96
61
|
*
|
|
97
|
-
* @param a First
|
|
98
|
-
* @param b Second
|
|
62
|
+
* @param a First state.
|
|
63
|
+
* @param b Second state.
|
|
99
64
|
* @return Whether `a` and `b` are value-equal across all slices.
|
|
100
65
|
*/
|
|
101
66
|
function areMediaEditorStatesEqual(a, b) {
|
|
102
67
|
if (a === b) return true;
|
|
103
|
-
return
|
|
68
|
+
return areImageEditorStatesEqual(a.imageEditor, b.imageEditor) && a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue && fastDeepEqual(a.edits, b.edits);
|
|
104
69
|
}
|
|
105
70
|
/**
|
|
106
|
-
* Build the
|
|
107
|
-
*
|
|
71
|
+
* Build the state a session starts from: the given image editor state,
|
|
72
|
+
* default crop options, and no edits.
|
|
108
73
|
*
|
|
109
|
-
* @param
|
|
110
|
-
* @return
|
|
74
|
+
* @param imageEditor The image editor state.
|
|
75
|
+
* @return Initial state.
|
|
111
76
|
*/
|
|
112
|
-
function buildInitialMediaEditorState(
|
|
77
|
+
function buildInitialMediaEditorState(imageEditor) {
|
|
113
78
|
return {
|
|
114
|
-
|
|
79
|
+
imageEditor,
|
|
115
80
|
cropOptions: { ...DEFAULT_CROP_OPTIONS },
|
|
116
81
|
edits: {}
|
|
117
82
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composite-reducer.mjs","names":[],"sources":["../../src/state/composite-reducer.ts"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport
|
|
1
|
+
{"version":3,"file":"composite-reducer.mjs","names":[],"sources":["../../src/state/composite-reducer.ts"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tareImageEditorStatesEqual,\n\tcreateImageEditorState,\n\ttype ImageEditorState,\n} from '@wordpress/image-editor';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure reducer for the media editor.\n *\n * The image editor works out its own next state (through the controller from\n * `@wordpress/image-editor`) and this reducer stores it. The reducer\n * also owns the sidebar crop options and the named edits.\n *\n * This reducer keeps no history; `useMediaEditorState` does.\n *\n * @param state Current state.\n * @param action Action to apply.\n * @return Next state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IMAGE_EDITOR':\n\t\t\treturn action.payload === state.imageEditor\n\t\t\t\t? state\n\t\t\t\t: { ...state, imageEditor: action.payload };\n\t\tcase 'SET_ASPECT_RATIO_VALUE':\n\t\t\treturn state.cropOptions.aspectRatioValue === action.payload\n\t\t\t\t? state\n\t\t\t\t: {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tcropOptions: {\n\t\t\t\t\t\t\t...state.cropOptions,\n\t\t\t\t\t\t\taspectRatioValue: action.payload,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\tcase 'SET_EDIT': {\n\t\t\tconst { name, value } = action.payload;\n\t\t\tif ( value === undefined ) {\n\t\t\t\tif ( ! Object.hasOwn( state.edits, name ) ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\tconst edits = { ...state.edits };\n\t\t\t\tdelete edits[ name ];\n\t\t\t\treturn { ...state, edits };\n\t\t\t}\n\t\t\tif ( fastDeepEqual( state.edits[ name ], value ) ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, edits: { ...state.edits, [ name ]: value } };\n\t\t}\n\t\tcase 'RESET': {\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcreateImageEditorState( { image: state.imageEditor.image } )\n\t\t\t);\n\t\t\treturn areMediaEditorStatesEqual( state, next ) ? state : next;\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t}\n}\n\n/**\n * Value-equality check for two media editor states. The history uses it\n * to skip snapshots when an action turned out to be a no-op.\n *\n * @param a First state.\n * @param b Second state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareImageEditorStatesEqual( a.imageEditor, b.imageEditor ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&\n\t\tfastDeepEqual( a.edits, b.edits )\n\t);\n}\n\n/**\n * Build the state a session starts from: the given image editor state,\n * default crop options, and no edits.\n *\n * @param imageEditor The image editor state.\n * @return Initial state.\n */\nexport function buildInitialMediaEditorState(\n\timageEditor: ImageEditorState\n): MediaEditorState {\n\treturn {\n\t\timageEditor,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\tedits: {},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,SAAgB,mBACf,OACA,QACmB;CACnB,QAAS,OAAO,MAAhB;EACC,KAAK,oBACJ,OAAO,OAAO,YAAY,MAAM,cAC7B,QACA;GAAE,GAAG;GAAO,aAAa,OAAO;EAAQ;EAC5C,KAAK,0BACJ,OAAO,MAAM,YAAY,qBAAqB,OAAO,UAClD,QACA;GACA,GAAG;GACH,aAAa;IACZ,GAAG,MAAM;IACT,kBAAkB,OAAO;GAC1B;EACD;EACH,KAAK,YAAY;GAChB,MAAM,EAAE,MAAM,UAAU,OAAO;GAC/B,IAAK,UAAU,KAAA,GAAY;IAC1B,IAAK,CAAE,OAAO,OAAQ,MAAM,OAAO,IAAK,GACvC,OAAO;IAER,MAAM,QAAQ,EAAE,GAAG,MAAM,MAAM;IAC/B,OAAO,MAAO;IACd,OAAO;KAAE,GAAG;KAAO;IAAM;GAC1B;GACA,IAAK,cAAe,MAAM,MAAO,OAAQ,KAAM,GAC9C,OAAO;GAER,OAAO;IAAE,GAAG;IAAO,OAAO;KAAE,GAAG,MAAM;MAAS,OAAQ;IAAM;GAAE;EAC/D;EACA,KAAK,SAAS;GACb,MAAM,OAAO,6BACZ,uBAAwB,EAAE,OAAO,MAAM,YAAY,MAAM,CAAE,CAC5D;GACA,OAAO,0BAA2B,OAAO,IAAK,IAAI,QAAQ;EAC3D;EACA,KAAK,oBACJ,OAAO,OAAO;CAChB;AACD;;;;;;;;;AAUA,SAAgB,0BACf,GACA,GACU;CACV,IAAK,MAAM,GACV,OAAO;CAER,OACC,0BAA2B,EAAE,aAAa,EAAE,WAAY,KACxD,EAAE,YAAY,qBAAqB,EAAE,YAAY,oBACjD,cAAe,EAAE,OAAO,EAAE,KAAM;AAElC;;;;;;;;AASA,SAAgB,6BACf,aACmB;CACnB,OAAO;EACN;EACA,aAAa,EAAE,GAAG,qBAAqB;EACvC,OAAO,CAAC;CACT;AACD"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMediaEditorState } from "./use-media-editor-state.mjs";
|
|
2
2
|
import { MediaEditorStateProvider, useMediaEditor } from "./media-editor-state-provider.mjs";
|
|
3
|
-
|
|
4
|
-
import { DEFAULT_CROP_OPTIONS } from "./types.mjs";
|
|
5
|
-
import { DEFAULT_ASPECT_RATIOS } from "./aspect-ratio-presets.mjs";
|
|
6
|
-
export { DEFAULT_ASPECT_RATIOS, DEFAULT_CROP_OPTIONS, MediaEditorStateProvider, areMediaEditorStatesEqual, buildInitialMediaEditorState, mediaEditorReducer, resolveAspectRatio, useMediaEditor, useMediaEditorState };
|
|
3
|
+
export { MediaEditorStateProvider, useMediaEditor, useMediaEditorState };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// packages/media-editor/src/state/types.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* used by the sidebar before the user has touched anything.
|
|
3
|
+
* The crop options a session starts from.
|
|
5
4
|
*/
|
|
6
5
|
const DEFAULT_CROP_OPTIONS = { aspectRatioValue: "0" };
|
|
7
6
|
export { DEFAULT_CROP_OPTIONS };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/state/types.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/state/types.ts"],"sourcesContent":["import type { ImageEditorState } from '@wordpress/image-editor';\n\n/**\n * Sidebar control state for the image editor, kept in the same undo history\n * as the crop.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio. The image editor holds the resolved ratio itself.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * The crop options a session starts from.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * A value an edit can hold: plain data only, because the session\n * compares values by content to tell a real change from a no-op.\n * Anything else, such as a `Blob`, would compare equal to any other\n * and the change would be dropped — keep bytes behind a URL instead.\n *\n * Objects must satisfy the index signature, so type a value with a\n * `type` alias rather than an `interface`.\n */\nexport type EditValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| EditValue[]\n\t| { [ key: string ]: EditValue };\n\n/**\n * Named edits other than crop, keyed by edit name (for example\n * `my-plugin/vignette`). An edit that is not present means \"no edit\".\n */\nexport type EditsSlice = Record< string, EditValue >;\n\n/**\n * The full state of the media editor: the image editor's state, the sidebar\n * crop options and named edits.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\timageEditor: ImageEditorState;\n\tcropOptions: CropOptionsSlice;\n\tedits: EditsSlice;\n}\n\n/** Actions the media editor reducer handles. */\nexport type MediaEditorAction =\n\t/** Replace the image editor's state with the next one it reports. */\n\t| { type: 'SET_IMAGE_EDITOR'; payload: ImageEditorState }\n\t/** Set the aspect-ratio preset the dropdown shows. */\n\t| { type: 'SET_ASPECT_RATIO_VALUE'; payload: string }\n\t/** Set a named edit, or remove it when `value` is `undefined`. */\n\t| {\n\t\t\ttype: 'SET_EDIT';\n\t\t\tpayload: { name: string; value: EditValue | undefined };\n\t }\n\t/**\n\t * Put every slice back to its starting state, keeping the image. One\n\t * action, so one undo entry.\n\t */\n\t| { type: 'RESET' }\n\t/** Replace the whole state with a snapshot (undo/redo). */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState };\n"],"mappings":";;;;AAkBA,MAAa,uBAAyC,EACrD,kBAAkB,IACnB"}
|