@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
|
@@ -5,11 +5,11 @@ import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
|
|
|
5
5
|
import { store as noticesStore } from '@wordpress/notices';
|
|
6
6
|
import type { Field, Form } from '@wordpress/dataviews';
|
|
7
7
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
8
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
8
9
|
import MediaEditor from '../media-editor';
|
|
9
10
|
import type { Media } from '../media-editor-provider';
|
|
10
11
|
import { store as mediaEditorStore } from '../../store';
|
|
11
12
|
import type { MediaEditorModalUpdate } from '../../store/actions';
|
|
12
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
13
13
|
|
|
14
14
|
interface MediaEditorModalProps {
|
|
15
15
|
/**
|
|
@@ -104,6 +104,9 @@ export function MediaEditorModal( {
|
|
|
104
104
|
shouldCloseOnEsc
|
|
105
105
|
noticesClassName="media-editor-modal__snackbar"
|
|
106
106
|
noticesPortalElement={ portalElement }
|
|
107
|
+
// Rotate, flip and aspect ratio are only in the Crop panel for now.
|
|
108
|
+
// This can go once they move under the canvas (#87282).
|
|
109
|
+
defaultPanel="core/crop"
|
|
107
110
|
onClose={ handleClose }
|
|
108
111
|
onSaved={ ( { id: savedId, url, previous } ) => {
|
|
109
112
|
if ( savedId && onUpdate ) {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Component } from '@wordpress/element';
|
|
2
|
+
import { speak } from '@wordpress/a11y';
|
|
3
|
+
import { useCopyToClipboard } from '@wordpress/compose';
|
|
4
|
+
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
5
|
+
import { Notice } from '@wordpress/ui';
|
|
6
|
+
import type { ReactNode } from 'react';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
title: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface State {
|
|
14
|
+
/** Separate from `error`: a panel can throw a falsy value. */
|
|
15
|
+
hasError: boolean;
|
|
16
|
+
error: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getMessage( title: string ) {
|
|
20
|
+
return {
|
|
21
|
+
title: sprintf(
|
|
22
|
+
/* translators: %s: the panel's title. */
|
|
23
|
+
__( 'The "%s" panel could not be shown' ),
|
|
24
|
+
title
|
|
25
|
+
),
|
|
26
|
+
description: __(
|
|
27
|
+
'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'
|
|
28
|
+
),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A component, because the copy hook cannot run in the class below.
|
|
33
|
+
function CopyErrorButton( { error }: { error: unknown } ) {
|
|
34
|
+
const ref = useCopyToClipboard< HTMLButtonElement >( () => {
|
|
35
|
+
// A boundary catches whatever was thrown, which is not always an `Error`.
|
|
36
|
+
const { message, stack } = ( error ?? {} ) as {
|
|
37
|
+
message?: unknown;
|
|
38
|
+
stack?: unknown;
|
|
39
|
+
};
|
|
40
|
+
const text = [ error, message ].find(
|
|
41
|
+
( part ) => typeof part === 'string' && part
|
|
42
|
+
);
|
|
43
|
+
return [ text ?? 'An unknown error occurred.', stack ]
|
|
44
|
+
.filter( ( part ) => typeof part === 'string' && part )
|
|
45
|
+
.join( '\n\n' );
|
|
46
|
+
} );
|
|
47
|
+
return (
|
|
48
|
+
<Notice.ActionButton variant="outline" ref={ ref }>
|
|
49
|
+
{ _x( 'Copy error', 'button label' ) }
|
|
50
|
+
</Notice.ActionButton>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Keeps a panel's failure inside its tab, so the rest of the editor stays
|
|
56
|
+
* usable.
|
|
57
|
+
*/
|
|
58
|
+
export default class MediaEditorPanelErrorBoundary extends Component<
|
|
59
|
+
Props,
|
|
60
|
+
State
|
|
61
|
+
> {
|
|
62
|
+
state: State = { hasError: false, error: null };
|
|
63
|
+
|
|
64
|
+
static getDerivedStateFromError( error: unknown ): State {
|
|
65
|
+
return { hasError: true, error };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
componentDidCatch() {
|
|
69
|
+
const { title, description } = getMessage( this.props.title );
|
|
70
|
+
speak( `${ title }. ${ description }`, 'assertive' );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
render() {
|
|
74
|
+
if ( ! this.state.hasError ) {
|
|
75
|
+
return this.props.children;
|
|
76
|
+
}
|
|
77
|
+
const { title, description } = getMessage( this.props.title );
|
|
78
|
+
return (
|
|
79
|
+
<Notice.Root intent="error">
|
|
80
|
+
<Notice.Title>{ title }</Notice.Title>
|
|
81
|
+
<Notice.Description>{ description }</Notice.Description>
|
|
82
|
+
<Notice.Actions>
|
|
83
|
+
<CopyErrorButton error={ this.state.error } />
|
|
84
|
+
</Notice.Actions>
|
|
85
|
+
</Notice.Root>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import fastDeepEqual from 'fast-deep-equal/es6/index.js';
|
|
2
|
+
import { Fill } from '@wordpress/components';
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from '@wordpress/element';
|
|
12
|
+
import warning from '@wordpress/warning';
|
|
13
|
+
import type { ReactNode } from 'react';
|
|
14
|
+
import { MEDIA_TYPES, type MediaType } from '../../utils';
|
|
15
|
+
import MediaEditorPanelErrorBoundary from './error-boundary';
|
|
16
|
+
|
|
17
|
+
export interface MediaEditorPanelFillProps {
|
|
18
|
+
/** `true` while a save is running. */
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MediaEditorPanelRegistration {
|
|
23
|
+
/** Unique, namespaced name, for example `core/crop`. */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Tab label. */
|
|
26
|
+
title: string;
|
|
27
|
+
/** Omitted means every type. */
|
|
28
|
+
mediaTypes?: readonly MediaType[ 'type' ][];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface MediaEditorPanelProps extends MediaEditorPanelRegistration {
|
|
32
|
+
children:
|
|
33
|
+
ReactNode | ( ( fillProps: MediaEditorPanelFillProps ) => ReactNode );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface MediaEditorPanelsContextValue {
|
|
37
|
+
register: ( panel: MediaEditorPanelRegistration, instance: object ) => void;
|
|
38
|
+
unregister: ( name: string, instance: object ) => void;
|
|
39
|
+
/** Panel name to the mounted panel that has it. */
|
|
40
|
+
owners: Record< string, object >;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const MediaEditorPanelsContext =
|
|
44
|
+
createContext< MediaEditorPanelsContextValue | null >( null );
|
|
45
|
+
|
|
46
|
+
export const MediaEditorPanelsProvider = MediaEditorPanelsContext.Provider;
|
|
47
|
+
|
|
48
|
+
/** The `registerPlugin` scope the editor mounts. */
|
|
49
|
+
export const MEDIA_EDITOR_PLUGIN_SCOPE = 'media-editor';
|
|
50
|
+
|
|
51
|
+
/** `vendor/panel`: lowercase letters, digits and dashes, with one slash. */
|
|
52
|
+
const PANEL_NAME_PATTERN = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/;
|
|
53
|
+
|
|
54
|
+
export function getPanelSlotName( name: string ) {
|
|
55
|
+
return `MediaEditorPanel/${ name }`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The mounted panels of one editor.
|
|
60
|
+
*
|
|
61
|
+
* @return The panels, in the order they mounted, and the context value to provide to them.
|
|
62
|
+
*/
|
|
63
|
+
export function useMediaEditorPanels() {
|
|
64
|
+
const [ panels, setPanels ] = useState<
|
|
65
|
+
Record<
|
|
66
|
+
string,
|
|
67
|
+
{ registration: MediaEditorPanelRegistration; owner: object }
|
|
68
|
+
>
|
|
69
|
+
>( {} );
|
|
70
|
+
// The first panel to announce a name keeps it. A ref, so panels
|
|
71
|
+
// announcing in the same commit see each other.
|
|
72
|
+
const ownersRef = useRef( new Map< string, object >() );
|
|
73
|
+
const register = useCallback(
|
|
74
|
+
( panel: MediaEditorPanelRegistration, instance: object ) => {
|
|
75
|
+
const owner = ownersRef.current.get( panel.name );
|
|
76
|
+
if ( owner && owner !== instance ) {
|
|
77
|
+
warning(
|
|
78
|
+
`A media editor panel named "${ panel.name }" is already registered, so this one is not shown. Give each panel a unique name.`
|
|
79
|
+
);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
ownersRef.current.set( panel.name, instance );
|
|
83
|
+
setPanels( ( current ) => {
|
|
84
|
+
// Skip unchanged details: an inline `mediaTypes` array would
|
|
85
|
+
// otherwise re-render the editor and the panel in a loop.
|
|
86
|
+
const entry = current[ panel.name ];
|
|
87
|
+
if (
|
|
88
|
+
entry?.owner === instance &&
|
|
89
|
+
fastDeepEqual( entry.registration, panel )
|
|
90
|
+
) {
|
|
91
|
+
return current;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
...current,
|
|
95
|
+
[ panel.name ]: { registration: panel, owner: instance },
|
|
96
|
+
};
|
|
97
|
+
} );
|
|
98
|
+
},
|
|
99
|
+
[]
|
|
100
|
+
);
|
|
101
|
+
const unregister = useCallback( ( name: string, instance: object ) => {
|
|
102
|
+
if ( ownersRef.current.get( name ) !== instance ) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
ownersRef.current.delete( name );
|
|
106
|
+
setPanels( ( current ) => {
|
|
107
|
+
if ( ! Object.hasOwn( current, name ) ) {
|
|
108
|
+
return current;
|
|
109
|
+
}
|
|
110
|
+
const next = { ...current };
|
|
111
|
+
delete next[ name ];
|
|
112
|
+
return next;
|
|
113
|
+
} );
|
|
114
|
+
}, [] );
|
|
115
|
+
const owners = useMemo(
|
|
116
|
+
() =>
|
|
117
|
+
Object.fromEntries(
|
|
118
|
+
Object.entries( panels ).map( ( [ name, { owner } ] ) => [
|
|
119
|
+
name,
|
|
120
|
+
owner,
|
|
121
|
+
] )
|
|
122
|
+
),
|
|
123
|
+
[ panels ]
|
|
124
|
+
);
|
|
125
|
+
const contextValue = useMemo(
|
|
126
|
+
() => ( { register, unregister, owners } ),
|
|
127
|
+
[ register, unregister, owners ]
|
|
128
|
+
);
|
|
129
|
+
const registrations = useMemo(
|
|
130
|
+
() =>
|
|
131
|
+
Object.values( panels ).map( ( { registration } ) => registration ),
|
|
132
|
+
[ panels ]
|
|
133
|
+
);
|
|
134
|
+
return { panels: registrations, contextValue };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** A tab in the media editor's sidebar, filled with its children. */
|
|
138
|
+
export default function MediaEditorPanel( {
|
|
139
|
+
name,
|
|
140
|
+
title,
|
|
141
|
+
mediaTypes,
|
|
142
|
+
children,
|
|
143
|
+
}: MediaEditorPanelProps ) {
|
|
144
|
+
const context = useContext( MediaEditorPanelsContext );
|
|
145
|
+
if ( ! context ) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
'MediaEditorPanel is rendered outside the media editor.'
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const { register, unregister, owners } = context;
|
|
151
|
+
// Identifies this mounted panel.
|
|
152
|
+
const [ instance ] = useState( () => ( {} ) );
|
|
153
|
+
const owner = owners[ name ];
|
|
154
|
+
// Layout effects, so the tab exists before the sidebar paints. Two of
|
|
155
|
+
// them: details may change on any render, but the tab only goes when
|
|
156
|
+
// the panel unmounts or changes its name.
|
|
157
|
+
useLayoutEffect( () => {
|
|
158
|
+
if ( ! PANEL_NAME_PATTERN.test( name ) ) {
|
|
159
|
+
warning(
|
|
160
|
+
`The media editor panel name "${ name }" should be namespaced, like "my-plugin/my-panel": lowercase letters, digits and dashes, with one slash.`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
mediaTypes?.forEach( ( type ) => {
|
|
164
|
+
if ( ! MEDIA_TYPES.includes( type ) ) {
|
|
165
|
+
warning(
|
|
166
|
+
`The media editor panel "${ name }" lists the media type "${ type }", which the editor does not know, so the panel would never show for it. Known types: ${ MEDIA_TYPES.join( ', ' ) }.`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
} );
|
|
170
|
+
register( { name, title, mediaTypes }, instance );
|
|
171
|
+
// When two panels share a name, the second waits for the first to
|
|
172
|
+
// unmount. `owner` changes at that point, which re-runs this effect
|
|
173
|
+
// and gives the second panel the tab.
|
|
174
|
+
}, [ name, title, mediaTypes, register, owner, instance ] );
|
|
175
|
+
useLayoutEffect( () => {
|
|
176
|
+
return () => unregister( name, instance );
|
|
177
|
+
}, [ name, unregister, instance ] );
|
|
178
|
+
|
|
179
|
+
if ( owner !== instance ) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<Fill name={ getPanelSlotName( name ) }>
|
|
185
|
+
{ ( fillProps ) => (
|
|
186
|
+
<MediaEditorPanelErrorBoundary title={ title }>
|
|
187
|
+
<MediaEditorPanelContent
|
|
188
|
+
// The slot passes exactly these props; `Fill` types them loosely.
|
|
189
|
+
fillProps={ fillProps as MediaEditorPanelFillProps }
|
|
190
|
+
>
|
|
191
|
+
{ children }
|
|
192
|
+
</MediaEditorPanelContent>
|
|
193
|
+
</MediaEditorPanelErrorBoundary>
|
|
194
|
+
) }
|
|
195
|
+
</Fill>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Calls a function child inside the error boundary, so one that throws is
|
|
201
|
+
* caught there.
|
|
202
|
+
*/
|
|
203
|
+
function MediaEditorPanelContent( {
|
|
204
|
+
fillProps,
|
|
205
|
+
children,
|
|
206
|
+
}: {
|
|
207
|
+
fillProps: MediaEditorPanelFillProps;
|
|
208
|
+
children: MediaEditorPanelProps[ 'children' ];
|
|
209
|
+
} ) {
|
|
210
|
+
return typeof children === 'function' ? children( fillProps ) : children;
|
|
211
|
+
}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import { speak } from '@wordpress/a11y';
|
|
3
|
+
import { Button, Spinner as WCSpinner } 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 {
|
|
8
|
+
check,
|
|
9
|
+
copy,
|
|
10
|
+
download,
|
|
11
|
+
error as errorIcon,
|
|
12
|
+
folder,
|
|
13
|
+
} from '@wordpress/icons';
|
|
14
|
+
import { EmptyState } from '@wordpress/ui';
|
|
4
15
|
import { useMediaEditorContext } from '../media-editor-provider';
|
|
16
|
+
import type { Media } from '../media-editor-provider';
|
|
5
17
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
6
18
|
|
|
7
19
|
/**
|
|
@@ -19,37 +31,142 @@ interface MediaPreviewContentProps {
|
|
|
19
31
|
mediaUrl: string;
|
|
20
32
|
altText?: string;
|
|
21
33
|
displayTitle?: string;
|
|
22
|
-
|
|
34
|
+
fileName?: string;
|
|
35
|
+
fileDetails?: string;
|
|
23
36
|
onLoad: () => void;
|
|
24
37
|
onError: () => void;
|
|
25
38
|
loadingState: 'loading' | 'loaded' | 'error';
|
|
26
39
|
}
|
|
27
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Returns the value of one of the attachment fields for the media, or an
|
|
43
|
+
* empty string if the field isn't available.
|
|
44
|
+
*
|
|
45
|
+
* @param fields The attachment fields.
|
|
46
|
+
* @param fieldId The id of the field to read.
|
|
47
|
+
* @param media The media record.
|
|
48
|
+
*/
|
|
49
|
+
function getFieldValue(
|
|
50
|
+
fields: Array< {
|
|
51
|
+
id: string;
|
|
52
|
+
getValue?: ( args: { item: Media } ) => unknown;
|
|
53
|
+
} >,
|
|
54
|
+
fieldId: string,
|
|
55
|
+
media: Media
|
|
56
|
+
): string {
|
|
57
|
+
const field = fields.find( ( { id } ) => id === fieldId );
|
|
58
|
+
const value = field?.getValue?.( { item: media } );
|
|
59
|
+
return typeof value === 'string' ? value : '';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const COPY_FEEDBACK_TIMEOUT = 2000;
|
|
63
|
+
|
|
64
|
+
type CopyResult = 'idle' | 'copied' | 'error';
|
|
65
|
+
|
|
66
|
+
const COPY_RESULT_ICONS = {
|
|
67
|
+
idle: copy,
|
|
68
|
+
copied: check,
|
|
69
|
+
error: errorIcon,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Copies the text and shows the result on the copy button, following the
|
|
74
|
+
* Copy to Clipboard design system pattern.
|
|
75
|
+
*
|
|
76
|
+
* @param text The text to copy.
|
|
77
|
+
*/
|
|
78
|
+
function useCopyWithFeedback( text: string ) {
|
|
79
|
+
// Bump the id on every result, so a repeat of the same result restarts
|
|
80
|
+
// the time the icon stays visible.
|
|
81
|
+
const [ feedback, setFeedback ] = useState< {
|
|
82
|
+
result: CopyResult;
|
|
83
|
+
id: number;
|
|
84
|
+
} >( { result: 'idle', id: 0 } );
|
|
85
|
+
|
|
86
|
+
useEffect( () => {
|
|
87
|
+
if ( feedback.result === 'idle' ) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const timeoutId = setTimeout(
|
|
91
|
+
() => setFeedback( { result: 'idle', id: 0 } ),
|
|
92
|
+
COPY_FEEDBACK_TIMEOUT
|
|
93
|
+
);
|
|
94
|
+
return () => clearTimeout( timeoutId );
|
|
95
|
+
}, [ feedback ] );
|
|
96
|
+
|
|
97
|
+
function report( result: Exclude< CopyResult, 'idle' >, message: string ) {
|
|
98
|
+
setFeedback( ( current ) => ( { result, id: current.id + 1 } ) );
|
|
99
|
+
speak( message );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const ref = useCopyToClipboard(
|
|
103
|
+
text,
|
|
104
|
+
() => report( 'copied', __( 'Copied URL to clipboard.' ) ),
|
|
105
|
+
() => report( 'error', __( "Couldn't copy URL to clipboard." ) )
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return { result: feedback.result, ref };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function MediaPreviewFileActions( { mediaUrl }: { mediaUrl: string } ) {
|
|
112
|
+
const { result, ref } = useCopyWithFeedback( mediaUrl );
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<>
|
|
116
|
+
{ /*
|
|
117
|
+
* Browsers ignore `download` for cross-origin URLs, e.g. media
|
|
118
|
+
* offloaded to a CDN, and show the file instead. Open it in a new
|
|
119
|
+
* tab so it doesn't replace the editor.
|
|
120
|
+
*/ }
|
|
121
|
+
<Button
|
|
122
|
+
__next40pxDefaultSize
|
|
123
|
+
variant="primary"
|
|
124
|
+
href={ mediaUrl }
|
|
125
|
+
target="_blank"
|
|
126
|
+
download
|
|
127
|
+
icon={ download }
|
|
128
|
+
>
|
|
129
|
+
{ __( 'Download' ) }
|
|
130
|
+
</Button>
|
|
131
|
+
{ /* The label stays the same, and the icon shows the result. */ }
|
|
132
|
+
<Button
|
|
133
|
+
__next40pxDefaultSize
|
|
134
|
+
variant="secondary"
|
|
135
|
+
ref={ ref }
|
|
136
|
+
icon={ COPY_RESULT_ICONS[ result ] }
|
|
137
|
+
>
|
|
138
|
+
{ __( 'Copy URL' ) }
|
|
139
|
+
</Button>
|
|
140
|
+
</>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
28
144
|
interface MediaPreviewFileInfoProps {
|
|
29
145
|
mediaUrl: string;
|
|
30
|
-
|
|
31
|
-
|
|
146
|
+
fileName?: string;
|
|
147
|
+
fileDetails?: string;
|
|
32
148
|
}
|
|
33
149
|
|
|
34
150
|
function MediaPreviewFileInfo( {
|
|
35
151
|
mediaUrl,
|
|
36
|
-
|
|
37
|
-
|
|
152
|
+
fileName,
|
|
153
|
+
fileDetails,
|
|
38
154
|
}: MediaPreviewFileInfoProps ) {
|
|
39
155
|
return (
|
|
40
|
-
<
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
156
|
+
<EmptyState.Root>
|
|
157
|
+
<EmptyState.Icon icon={ folder } />
|
|
158
|
+
{ !! fileName && (
|
|
159
|
+
<EmptyState.Title className="media-editor-preview__file-name">
|
|
160
|
+
{ fileName }
|
|
161
|
+
</EmptyState.Title>
|
|
162
|
+
) }
|
|
163
|
+
{ !! fileDetails && (
|
|
164
|
+
<EmptyState.Description>{ fileDetails }</EmptyState.Description>
|
|
165
|
+
) }
|
|
166
|
+
<EmptyState.Actions className="media-editor-preview__actions">
|
|
167
|
+
<MediaPreviewFileActions mediaUrl={ mediaUrl } />
|
|
168
|
+
</EmptyState.Actions>
|
|
169
|
+
</EmptyState.Root>
|
|
53
170
|
);
|
|
54
171
|
}
|
|
55
172
|
|
|
@@ -58,7 +175,8 @@ function MediaPreviewContent( {
|
|
|
58
175
|
mediaUrl,
|
|
59
176
|
altText,
|
|
60
177
|
displayTitle,
|
|
61
|
-
|
|
178
|
+
fileName,
|
|
179
|
+
fileDetails,
|
|
62
180
|
onLoad,
|
|
63
181
|
onError,
|
|
64
182
|
loadingState,
|
|
@@ -101,8 +219,8 @@ function MediaPreviewContent( {
|
|
|
101
219
|
>
|
|
102
220
|
<MediaPreviewFileInfo
|
|
103
221
|
mediaUrl={ mediaUrl }
|
|
104
|
-
|
|
105
|
-
|
|
222
|
+
fileName={ fileName }
|
|
223
|
+
fileDetails={ fileDetails }
|
|
106
224
|
/>
|
|
107
225
|
</object>
|
|
108
226
|
);
|
|
@@ -110,8 +228,8 @@ function MediaPreviewContent( {
|
|
|
110
228
|
return (
|
|
111
229
|
<MediaPreviewFileInfo
|
|
112
230
|
mediaUrl={ mediaUrl }
|
|
113
|
-
|
|
114
|
-
|
|
231
|
+
fileName={ fileName }
|
|
232
|
+
fileDetails={ fileDetails }
|
|
115
233
|
/>
|
|
116
234
|
);
|
|
117
235
|
}
|
|
@@ -128,7 +246,7 @@ export default function MediaPreview( props: MediaPreviewProps ) {
|
|
|
128
246
|
const [ loadingState, setLoadingState ] = useState<
|
|
129
247
|
'loading' | 'loaded' | 'error'
|
|
130
248
|
>( 'loading' );
|
|
131
|
-
const { media } = useMediaEditorContext();
|
|
249
|
+
const { media, fields } = useMediaEditorContext();
|
|
132
250
|
|
|
133
251
|
const {
|
|
134
252
|
source_url: mediaUrl,
|
|
@@ -148,28 +266,67 @@ export default function MediaPreview( props: MediaPreviewProps ) {
|
|
|
148
266
|
|
|
149
267
|
if ( ! mediaUrl ) {
|
|
150
268
|
return (
|
|
151
|
-
<div className="media-editor-preview media-editor-preview--empty">
|
|
152
|
-
<
|
|
269
|
+
<div className="media-editor-preview media-editor-preview--empty is-placeholder">
|
|
270
|
+
<EmptyState.Root>
|
|
271
|
+
<EmptyState.Icon icon={ folder } />
|
|
272
|
+
<EmptyState.Title>
|
|
273
|
+
{ __( 'No media file available.' ) }
|
|
274
|
+
</EmptyState.Title>
|
|
275
|
+
</EmptyState.Root>
|
|
153
276
|
</div>
|
|
154
277
|
);
|
|
155
278
|
}
|
|
156
279
|
|
|
280
|
+
const displayTitle =
|
|
281
|
+
typeof title === 'string' ? title : title?.rendered || title?.raw;
|
|
282
|
+
|
|
283
|
+
// Read through the attachment fields, so the values match the Details
|
|
284
|
+
// panel. Without a filename field, fall back to the title.
|
|
285
|
+
const fileName =
|
|
286
|
+
( media && getFieldValue( fields, 'filename', media ) ) || displayTitle;
|
|
287
|
+
const fileSize = media ? getFieldValue( fields, 'filesize', media ) : '';
|
|
288
|
+
const fileDetails =
|
|
289
|
+
mimeType && fileSize
|
|
290
|
+
? sprintf(
|
|
291
|
+
/* translators: 1: File type, e.g. "application/zip". 2: File size, e.g. "2.4 MB". */
|
|
292
|
+
_x( '%1$s · %2$s', 'file type and size' ),
|
|
293
|
+
mimeType,
|
|
294
|
+
fileSize
|
|
295
|
+
)
|
|
296
|
+
: mimeType || fileSize;
|
|
297
|
+
|
|
157
298
|
if ( loadingState === 'error' ) {
|
|
158
299
|
return (
|
|
159
|
-
<div className="media-editor-preview media-editor-preview--error">
|
|
160
|
-
<
|
|
161
|
-
|
|
300
|
+
<div className="media-editor-preview media-editor-preview--error is-placeholder">
|
|
301
|
+
<EmptyState.Root>
|
|
302
|
+
<EmptyState.Icon icon={ folder } />
|
|
303
|
+
<EmptyState.Title>
|
|
304
|
+
{ __( 'Failed to load media file.' ) }
|
|
305
|
+
</EmptyState.Title>
|
|
306
|
+
{ !! fileName && (
|
|
307
|
+
<EmptyState.Description className="media-editor-preview__file-name">
|
|
308
|
+
{ fileName }
|
|
309
|
+
</EmptyState.Description>
|
|
310
|
+
) }
|
|
311
|
+
<EmptyState.Actions className="media-editor-preview__actions">
|
|
312
|
+
<MediaPreviewFileActions mediaUrl={ mediaUrl } />
|
|
313
|
+
</EmptyState.Actions>
|
|
314
|
+
</EmptyState.Root>
|
|
162
315
|
</div>
|
|
163
316
|
);
|
|
164
317
|
}
|
|
165
318
|
|
|
166
|
-
const displayTitle =
|
|
167
|
-
typeof title === 'string' ? title : title?.rendered || title?.raw;
|
|
168
|
-
|
|
169
319
|
return (
|
|
170
320
|
<div
|
|
171
321
|
{ ...props }
|
|
172
|
-
className={
|
|
322
|
+
className={ clsx(
|
|
323
|
+
'media-editor-preview',
|
|
324
|
+
`media-editor-preview--${ previewType }`,
|
|
325
|
+
{
|
|
326
|
+
// Media with no preview of its own shows the file info.
|
|
327
|
+
'is-placeholder': previewType === 'application',
|
|
328
|
+
}
|
|
329
|
+
) }
|
|
173
330
|
>
|
|
174
331
|
{ previewType === 'image' && loadingState === 'loading' && (
|
|
175
332
|
<div className="media-editor-preview__spinner">
|
|
@@ -181,7 +338,8 @@ export default function MediaPreview( props: MediaPreviewProps ) {
|
|
|
181
338
|
mediaUrl={ mediaUrl }
|
|
182
339
|
altText={ altText }
|
|
183
340
|
displayTitle={ displayTitle }
|
|
184
|
-
|
|
341
|
+
fileName={ fileName }
|
|
342
|
+
fileDetails={ fileDetails }
|
|
185
343
|
onLoad={ () => setLoadingState( 'loaded' ) }
|
|
186
344
|
onError={ () => setLoadingState( 'error' ) }
|
|
187
345
|
loadingState={ loadingState }
|