@wordpress/media-editor 0.20.0 → 0.22.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 +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- 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.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- 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/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
2
|
import { useCallback, useEffect, useMemo, useState } from '@wordpress/element';
|
|
3
|
-
import { Spinner } from '@wordpress/components';
|
|
3
|
+
import { Spinner as WCSpinner } from '@wordpress/components';
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { useMediaEditorContext } from '../media-editor-provider';
|
|
6
6
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
@@ -50,9 +50,12 @@ export default function MediaEditorCanvas( {
|
|
|
50
50
|
// Tracks whether the image pixels have actually loaded. The cropper's
|
|
51
51
|
// geometry is driven by the known media dimensions, so its handles and
|
|
52
52
|
// overlays would otherwise appear before the image finishes streaming in.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
// Stored with the URL it is for, so a new URL (restoring the original
|
|
54
|
+
// swaps it in place) counts as loading until the cropper reports back.
|
|
55
|
+
const [ settled, setSettled ] = useState< {
|
|
56
|
+
url: string | undefined;
|
|
57
|
+
status: 'loaded' | 'error';
|
|
58
|
+
} >();
|
|
56
59
|
|
|
57
60
|
// Resolved aspect ratio is derived from the preset key + the
|
|
58
61
|
// loaded image (for the "Original" preset). The reducer doesn't
|
|
@@ -96,29 +99,14 @@ export default function MediaEditorCanvas( {
|
|
|
96
99
|
}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );
|
|
97
100
|
|
|
98
101
|
const isImage = mediaType.type === 'image';
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
setStatus( 'loading' );
|
|
109
|
-
const probe = new window.Image();
|
|
110
|
-
probe.onload = () => setStatus( 'loaded' );
|
|
111
|
-
probe.onerror = () => setStatus( 'error' );
|
|
112
|
-
probe.src = mediaUrl;
|
|
113
|
-
// Cached images may already be complete before listeners attach.
|
|
114
|
-
if ( probe.complete ) {
|
|
115
|
-
setStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );
|
|
116
|
-
}
|
|
117
|
-
return () => {
|
|
118
|
-
probe.onload = null;
|
|
119
|
-
probe.onerror = null;
|
|
120
|
-
};
|
|
121
|
-
}, [ mediaUrl, isImage ] );
|
|
102
|
+
const status =
|
|
103
|
+
settled && settled.url === mediaUrl ? settled.status : 'loading';
|
|
104
|
+
const handleImageLoaded = useCallback( () => {
|
|
105
|
+
setSettled( { url: mediaUrl, status: 'loaded' } );
|
|
106
|
+
}, [ mediaUrl ] );
|
|
107
|
+
const handleImageError = useCallback( () => {
|
|
108
|
+
setSettled( { url: mediaUrl, status: 'error' } );
|
|
109
|
+
}, [ mediaUrl ] );
|
|
122
110
|
|
|
123
111
|
if ( ! mediaUrl || ! isImage ) {
|
|
124
112
|
return null;
|
|
@@ -138,7 +126,7 @@ export default function MediaEditorCanvas( {
|
|
|
138
126
|
<div className="media-editor-canvas">
|
|
139
127
|
{ status === 'loading' && (
|
|
140
128
|
<div className="media-editor-canvas__spinner">
|
|
141
|
-
<
|
|
129
|
+
<WCSpinner />
|
|
142
130
|
</div>
|
|
143
131
|
) }
|
|
144
132
|
{ /*
|
|
@@ -165,6 +153,8 @@ export default function MediaEditorCanvas( {
|
|
|
165
153
|
isPlacementActive={ isPlacementActive }
|
|
166
154
|
onGestureStart={ handleGestureStart }
|
|
167
155
|
onGestureEnd={ handleGestureEnd }
|
|
156
|
+
onImageLoaded={ handleImageLoaded }
|
|
157
|
+
onImageError={ handleImageError }
|
|
168
158
|
disabled={ disabled }
|
|
169
159
|
/>
|
|
170
160
|
</div>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SelectControl
|
|
2
|
-
import { Stack, VisuallyHidden } from '@wordpress/ui';
|
|
1
|
+
import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';
|
|
3
2
|
import { __ } from '@wordpress/i18n';
|
|
4
3
|
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
5
4
|
import MediaEditorImageControls from '../media-editor-image-controls';
|
|
@@ -36,6 +35,11 @@ export default function MediaEditorCropPanel( {
|
|
|
36
35
|
aspectRatioOptions,
|
|
37
36
|
disabled = false,
|
|
38
37
|
}: MediaEditorCropPanelProps ) {
|
|
38
|
+
const items = aspectRatioOptions.map( ( preset ) => ( {
|
|
39
|
+
label: preset.label,
|
|
40
|
+
value: preset.value.toString(),
|
|
41
|
+
} ) );
|
|
42
|
+
|
|
39
43
|
return (
|
|
40
44
|
// Tag the whole panel as a crop-control region so the modal's
|
|
41
45
|
// Cmd+Z handler doesn't mistake the SelectControl input for a
|
|
@@ -49,15 +53,19 @@ export default function MediaEditorCropPanel( {
|
|
|
49
53
|
{ __( 'Crop options' ) }
|
|
50
54
|
</VisuallyHidden>
|
|
51
55
|
<MediaEditorImageControls withLabels disabled={ disabled } />
|
|
52
|
-
<
|
|
56
|
+
<SelectControl
|
|
53
57
|
label={ __( 'Aspect ratio' ) }
|
|
54
|
-
value={
|
|
55
|
-
|
|
58
|
+
value={
|
|
59
|
+
items.find( ( item ) => item.value === aspectRatioValue ) ??
|
|
60
|
+
null
|
|
61
|
+
}
|
|
62
|
+
onValueChange={ ( item ) => {
|
|
63
|
+
if ( item && item.value !== null ) {
|
|
64
|
+
onAspectRatioChange( item.value );
|
|
65
|
+
}
|
|
66
|
+
} }
|
|
56
67
|
disabled={ disabled }
|
|
57
|
-
|
|
58
|
-
label: preset.label,
|
|
59
|
-
value: preset.value.toString(),
|
|
60
|
-
} ) ) }
|
|
68
|
+
items={ items }
|
|
61
69
|
/>
|
|
62
70
|
</Stack>
|
|
63
71
|
);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Button } from '@wordpress/components';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.
|
|
4
|
+
Menu,
|
|
5
|
+
} from '@wordpress/ui';
|
|
4
6
|
import { __ } from '@wordpress/i18n';
|
|
5
7
|
import {
|
|
6
8
|
aspectRatio as aspectRatioIcon,
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
// Match the uppercase 11px heading the panel's other controls use for
|
|
32
32
|
// their labels (Zoom, Aspect ratio) so the groups read as section
|
|
33
|
-
// headings.
|
|
33
|
+
// headings. Matches InputControl's label typography in `@wordpress/components`.
|
|
34
34
|
&__label {
|
|
35
35
|
font-size: 11px;
|
|
36
36
|
font-weight: var(--wpds-typography-font-weight-emphasis);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CropperController } from '../../image-editor';
|
|
2
2
|
import { getRotatedBBox } from '../../image-editor/core/camera';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -71,20 +71,26 @@ const CROP_TOLERANCE = 0.1;
|
|
|
71
71
|
* leave the sign alone because `flip_h · flip_v = -I` commutes with
|
|
72
72
|
* rotation.
|
|
73
73
|
*
|
|
74
|
-
* @param
|
|
75
|
-
*
|
|
76
|
-
* @return Ordered modifier array; empty when nothing is server-relevant
|
|
74
|
+
* @param cropper The cropper controller. The current edit and the loaded
|
|
75
|
+
* image's natural size are both read from its state.
|
|
76
|
+
* @return Ordered modifier array; empty when nothing is server-relevant or
|
|
77
|
+
* no image has loaded.
|
|
77
78
|
*/
|
|
78
79
|
export function buildModifiers(
|
|
79
|
-
|
|
80
|
-
imageSize: Size
|
|
80
|
+
cropper: Pick< CropperController, 'state' >
|
|
81
81
|
): Modifier[] {
|
|
82
82
|
const modifiers: Modifier[] = [];
|
|
83
|
+
const { state } = cropper;
|
|
84
|
+
const { image } = state;
|
|
83
85
|
|
|
84
|
-
if (
|
|
86
|
+
if ( ! image || image.naturalWidth === 0 || image.naturalHeight === 0 ) {
|
|
85
87
|
return modifiers;
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
const imageSize = {
|
|
91
|
+
width: image.naturalWidth,
|
|
92
|
+
height: image.naturalHeight,
|
|
93
|
+
};
|
|
88
94
|
const { cropRect, pan, zoom, flip } = state;
|
|
89
95
|
const hasFlipH = flip.horizontal;
|
|
90
96
|
const hasFlipV = flip.vertical;
|
|
@@ -3,7 +3,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
3
3
|
import { __ } from '@wordpress/i18n';
|
|
4
4
|
import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
|
|
5
5
|
import { store as noticesStore } from '@wordpress/notices';
|
|
6
|
-
import type { Field } from '@wordpress/dataviews';
|
|
6
|
+
import type { Field, Form } from '@wordpress/dataviews';
|
|
7
7
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
8
8
|
import MediaEditor from '../media-editor';
|
|
9
9
|
import type { Media } from '../media-editor-provider';
|
|
@@ -19,6 +19,11 @@ interface MediaEditorModalProps {
|
|
|
19
19
|
* since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.
|
|
20
20
|
*/
|
|
21
21
|
fields?: Field< Media >[];
|
|
22
|
+
/**
|
|
23
|
+
* Form the fields are laid out with in the Details tab. When omitted,
|
|
24
|
+
* a default layout of the core attachment fields is used.
|
|
25
|
+
*/
|
|
26
|
+
form?: Form;
|
|
22
27
|
/**
|
|
23
28
|
* Fixed aspect-ratio presets for image cropping. Free and Original are
|
|
24
29
|
* always provided by the media editor.
|
|
@@ -47,6 +52,7 @@ function ModalFooter() {
|
|
|
47
52
|
|
|
48
53
|
export function MediaEditorModal( {
|
|
49
54
|
fields = [],
|
|
55
|
+
form,
|
|
50
56
|
aspectRatioPresets,
|
|
51
57
|
}: MediaEditorModalProps ) {
|
|
52
58
|
const { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(
|
|
@@ -93,6 +99,7 @@ export function MediaEditorModal( {
|
|
|
93
99
|
<MediaEditor
|
|
94
100
|
id={ id }
|
|
95
101
|
fields={ fields }
|
|
102
|
+
form={ form }
|
|
96
103
|
aspectRatioPresets={ aspectRatioPresets }
|
|
97
104
|
shouldCloseOnEsc
|
|
98
105
|
noticesClassName="media-editor-modal__snackbar"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Active (enabled) undo/redo icon buttons take the admin accent colour so
|
|
44
|
-
// they read as live alongside the
|
|
44
|
+
// they read as live alongside the Cancel/Save actions. Disabled
|
|
45
45
|
// buttons (rendered with `aria-disabled` via `accessibleWhenDisabled`)
|
|
46
46
|
// keep the default muted icon colour.
|
|
47
47
|
// Scoped to the modal: the package ships one stylesheet, so an unscoped
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext } from '@wordpress/element';
|
|
2
|
-
import type { Field } from '@wordpress/dataviews';
|
|
2
|
+
import type { Field, Form } from '@wordpress/dataviews';
|
|
3
3
|
import type { ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -23,6 +23,7 @@ export interface MediaEditorContextValue {
|
|
|
23
23
|
media?: Media;
|
|
24
24
|
onChange?: ( updates: Partial< Media > ) => void;
|
|
25
25
|
fields: Field< Media >[];
|
|
26
|
+
form?: Form;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/**
|
|
@@ -41,6 +42,11 @@ export interface MediaEditorProviderProps {
|
|
|
41
42
|
/** Configuration settings for the media editor. */
|
|
42
43
|
settings?: {
|
|
43
44
|
fields?: Field< Media >[];
|
|
45
|
+
/**
|
|
46
|
+
* The form the fields are laid out with. When omitted, `MediaForm`
|
|
47
|
+
* uses a default layout of the core attachment fields.
|
|
48
|
+
*/
|
|
49
|
+
form?: Form;
|
|
44
50
|
};
|
|
45
51
|
/** Child components. */
|
|
46
52
|
children: ReactNode;
|
|
@@ -60,6 +66,7 @@ export function MediaEditorProvider( {
|
|
|
60
66
|
media: value,
|
|
61
67
|
onChange,
|
|
62
68
|
fields: settings.fields || [],
|
|
69
|
+
form: settings.form,
|
|
63
70
|
};
|
|
64
71
|
|
|
65
72
|
return (
|
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
import { DataForm } from '@wordpress/dataviews';
|
|
2
|
-
import type { Form
|
|
3
|
-
import {
|
|
2
|
+
import type { Form } from '@wordpress/dataviews';
|
|
3
|
+
import {
|
|
4
|
+
Spinner as WCSpinner,
|
|
5
|
+
__experimentalVStack as VStack,
|
|
6
|
+
} from '@wordpress/components';
|
|
4
7
|
import { VisuallyHidden } from '@wordpress/ui';
|
|
5
8
|
import { __ } from '@wordpress/i18n';
|
|
6
9
|
import type { ReactNode } from 'react';
|
|
7
10
|
import { useMediaEditorContext } from '../media-editor-provider';
|
|
8
|
-
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* The form used when neither the component nor the provider settings have
|
|
14
|
+
* one, mirroring the `form` of the `attachment` view configuration on the
|
|
15
|
+
* server. It lists the core attachment fields in a fixed order, so the layout
|
|
16
|
+
* does not depend on the order the fields are passed in: the editable fields
|
|
17
|
+
* first, in a regular layout, then the metadata and the file information, in
|
|
18
|
+
* panels. A field it lists that is not passed renders nothing.
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_FORM: Form = {
|
|
21
|
+
layout: {
|
|
22
|
+
type: 'panel',
|
|
23
|
+
},
|
|
24
|
+
fields: [
|
|
25
|
+
...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {
|
|
26
|
+
id,
|
|
27
|
+
layout: {
|
|
28
|
+
type: 'regular' as const,
|
|
29
|
+
labelPosition: 'top' as const,
|
|
30
|
+
},
|
|
31
|
+
} ) ),
|
|
32
|
+
'date',
|
|
33
|
+
'author',
|
|
34
|
+
'filename',
|
|
35
|
+
'mime_type',
|
|
36
|
+
'filesize',
|
|
37
|
+
'media_dimensions',
|
|
38
|
+
'attached_to',
|
|
39
|
+
],
|
|
40
|
+
};
|
|
9
41
|
|
|
10
42
|
/**
|
|
11
43
|
* Props for MediaForm component.
|
|
@@ -19,10 +51,13 @@ export interface MediaFormProps {
|
|
|
19
51
|
* MediaForm component for editing media metadata.
|
|
20
52
|
*
|
|
21
53
|
* Renders a DataForm with fields for editing media properties like
|
|
22
|
-
* title, alt text, caption, description, etc.
|
|
54
|
+
* title, alt text, caption, description, etc. The fields are laid out with
|
|
55
|
+
* the `form` prop, else the form of the provider settings, else a default
|
|
56
|
+
* form of the core attachment fields.
|
|
23
57
|
*
|
|
24
58
|
* @param props - Component props.
|
|
25
|
-
* @param props.form - Optional form configuration
|
|
59
|
+
* @param props.form - Optional form configuration, which takes precedence
|
|
60
|
+
* over the form of the provider settings.
|
|
26
61
|
* @param props.header - Optional header content to display above the form.
|
|
27
62
|
* @return The MediaForm component.
|
|
28
63
|
*/
|
|
@@ -30,51 +65,22 @@ export default function MediaForm( {
|
|
|
30
65
|
form: formOverrides,
|
|
31
66
|
header,
|
|
32
67
|
}: MediaFormProps ) {
|
|
33
|
-
const {
|
|
68
|
+
const {
|
|
69
|
+
media,
|
|
70
|
+
fields,
|
|
71
|
+
form: settingsForm,
|
|
72
|
+
onChange,
|
|
73
|
+
} = useMediaEditorContext();
|
|
34
74
|
|
|
35
75
|
if ( ! media || ! onChange ) {
|
|
36
76
|
return (
|
|
37
77
|
<div className="media-editor-form media-editor-form--loading">
|
|
38
|
-
<
|
|
78
|
+
<WCSpinner />
|
|
39
79
|
</div>
|
|
40
80
|
);
|
|
41
81
|
}
|
|
42
82
|
|
|
43
|
-
|
|
44
|
-
const regularFieldIds = [ 'title', 'alt_text', 'caption', 'description' ];
|
|
45
|
-
|
|
46
|
-
// Place the non-panel (regular layout) fields at the top of the array,
|
|
47
|
-
// with the remaining panel fields below.
|
|
48
|
-
const sortedFields = [
|
|
49
|
-
...fields.filter( ( field: Field< Media > ) =>
|
|
50
|
-
regularFieldIds.includes( field.id )
|
|
51
|
-
),
|
|
52
|
-
...fields.filter(
|
|
53
|
-
( field: Field< Media > ) => ! regularFieldIds.includes( field.id )
|
|
54
|
-
),
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
// Default form structure with panel layout
|
|
58
|
-
const defaultForm: Form = {
|
|
59
|
-
layout: {
|
|
60
|
-
type: 'panel',
|
|
61
|
-
},
|
|
62
|
-
fields: sortedFields.map( ( field: Field< Media > ) => {
|
|
63
|
-
// Use regular layout for main editable fields
|
|
64
|
-
if ( regularFieldIds.includes( field.id ) ) {
|
|
65
|
-
return {
|
|
66
|
-
id: field.id,
|
|
67
|
-
layout: {
|
|
68
|
-
type: 'regular',
|
|
69
|
-
labelPosition: 'top',
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return field.id;
|
|
74
|
-
} ),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const form = formOverrides || defaultForm;
|
|
83
|
+
const form = formOverrides || settingsForm || DEFAULT_FORM;
|
|
78
84
|
|
|
79
85
|
return (
|
|
80
86
|
<div className="media-editor-form">
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Spinner } from '@wordpress/components';
|
|
1
|
+
import { Spinner as WCSpinner } from '@wordpress/components';
|
|
2
2
|
import { useState } from '@wordpress/element';
|
|
3
3
|
import { __ } from '@wordpress/i18n';
|
|
4
4
|
import { useMediaEditorContext } from '../media-editor-provider';
|
|
@@ -15,7 +15,7 @@ export interface MediaPreviewProps {
|
|
|
15
15
|
* Props for MediaPreviewContent component.
|
|
16
16
|
*/
|
|
17
17
|
interface MediaPreviewContentProps {
|
|
18
|
-
|
|
18
|
+
previewType: string;
|
|
19
19
|
mediaUrl: string;
|
|
20
20
|
altText?: string;
|
|
21
21
|
displayTitle?: string;
|
|
@@ -25,8 +25,36 @@ interface MediaPreviewContentProps {
|
|
|
25
25
|
loadingState: 'loading' | 'loaded' | 'error';
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
interface MediaPreviewFileInfoProps {
|
|
29
|
+
mediaUrl: string;
|
|
30
|
+
displayTitle?: string;
|
|
31
|
+
mimeType?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function MediaPreviewFileInfo( {
|
|
35
|
+
mediaUrl,
|
|
36
|
+
displayTitle,
|
|
37
|
+
mimeType,
|
|
38
|
+
}: MediaPreviewFileInfoProps ) {
|
|
39
|
+
return (
|
|
40
|
+
<div className="media-editor-preview__file-info">
|
|
41
|
+
<p className="media-editor-preview__file-name">{ displayTitle }</p>
|
|
42
|
+
<p className="media-editor-preview__mime-type">{ mimeType }</p>
|
|
43
|
+
{ /* eslint-disable-next-line react/jsx-no-target-blank */ }
|
|
44
|
+
<a
|
|
45
|
+
href={ mediaUrl }
|
|
46
|
+
target="_blank"
|
|
47
|
+
rel="noopener"
|
|
48
|
+
className="media-editor-preview__download-link"
|
|
49
|
+
>
|
|
50
|
+
{ __( 'View file' ) }
|
|
51
|
+
</a>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
28
56
|
function MediaPreviewContent( {
|
|
29
|
-
|
|
57
|
+
previewType,
|
|
30
58
|
mediaUrl,
|
|
31
59
|
altText,
|
|
32
60
|
displayTitle,
|
|
@@ -35,7 +63,7 @@ function MediaPreviewContent( {
|
|
|
35
63
|
onError,
|
|
36
64
|
loadingState,
|
|
37
65
|
}: MediaPreviewContentProps ) {
|
|
38
|
-
switch (
|
|
66
|
+
switch ( previewType ) {
|
|
39
67
|
case 'image':
|
|
40
68
|
return (
|
|
41
69
|
<img
|
|
@@ -58,25 +86,33 @@ function MediaPreviewContent( {
|
|
|
58
86
|
{ displayTitle }
|
|
59
87
|
</audio>
|
|
60
88
|
);
|
|
89
|
+
case 'pdf':
|
|
90
|
+
// The browser renders the children instead of the PDF when it
|
|
91
|
+
// can't display it, e.g. when the request fails.
|
|
92
|
+
return (
|
|
93
|
+
<object
|
|
94
|
+
className="media-editor-preview__pdf"
|
|
95
|
+
// Ask the viewer to fit the whole page rather than the
|
|
96
|
+
// width. Chrome reads `view`, Firefox reads `zoom`, and
|
|
97
|
+
// Safari ignores both.
|
|
98
|
+
data={ `${ mediaUrl }#view=Fit&zoom=page-fit` }
|
|
99
|
+
type="application/pdf"
|
|
100
|
+
aria-label={ __( 'Embed of the selected PDF file.' ) }
|
|
101
|
+
>
|
|
102
|
+
<MediaPreviewFileInfo
|
|
103
|
+
mediaUrl={ mediaUrl }
|
|
104
|
+
displayTitle={ displayTitle }
|
|
105
|
+
mimeType={ mimeType }
|
|
106
|
+
/>
|
|
107
|
+
</object>
|
|
108
|
+
);
|
|
61
109
|
default:
|
|
62
110
|
return (
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{ mimeType }
|
|
69
|
-
</p>
|
|
70
|
-
{ /* eslint-disable-next-line react/jsx-no-target-blank */ }
|
|
71
|
-
<a
|
|
72
|
-
href={ mediaUrl }
|
|
73
|
-
target="_blank"
|
|
74
|
-
rel="noopener"
|
|
75
|
-
className="media-editor-preview__download-link"
|
|
76
|
-
>
|
|
77
|
-
{ __( 'View file' ) }
|
|
78
|
-
</a>
|
|
79
|
-
</div>
|
|
111
|
+
<MediaPreviewFileInfo
|
|
112
|
+
mediaUrl={ mediaUrl }
|
|
113
|
+
displayTitle={ displayTitle }
|
|
114
|
+
mimeType={ mimeType }
|
|
115
|
+
/>
|
|
80
116
|
);
|
|
81
117
|
}
|
|
82
118
|
}
|
|
@@ -103,6 +139,13 @@ export default function MediaPreview( props: MediaPreviewProps ) {
|
|
|
103
139
|
|
|
104
140
|
const mediaType = getMediaTypeFromMimeType( mimeType );
|
|
105
141
|
|
|
142
|
+
// Without a built-in PDF viewer (e.g. on most mobile browsers), show
|
|
143
|
+
// the file info instead of an embed that can't render.
|
|
144
|
+
const previewType =
|
|
145
|
+
mimeType === 'application/pdf' && window.navigator.pdfViewerEnabled
|
|
146
|
+
? 'pdf'
|
|
147
|
+
: mediaType.type;
|
|
148
|
+
|
|
106
149
|
if ( ! mediaUrl ) {
|
|
107
150
|
return (
|
|
108
151
|
<div className="media-editor-preview media-editor-preview--empty">
|
|
@@ -126,15 +169,15 @@ export default function MediaPreview( props: MediaPreviewProps ) {
|
|
|
126
169
|
return (
|
|
127
170
|
<div
|
|
128
171
|
{ ...props }
|
|
129
|
-
className={ `media-editor-preview media-editor-preview--${
|
|
172
|
+
className={ `media-editor-preview media-editor-preview--${ previewType }` }
|
|
130
173
|
>
|
|
131
|
-
{
|
|
174
|
+
{ previewType === 'image' && loadingState === 'loading' && (
|
|
132
175
|
<div className="media-editor-preview__spinner">
|
|
133
|
-
<
|
|
176
|
+
<WCSpinner />
|
|
134
177
|
</div>
|
|
135
178
|
) }
|
|
136
179
|
<MediaPreviewContent
|
|
137
|
-
|
|
180
|
+
previewType={ previewType }
|
|
138
181
|
mediaUrl={ mediaUrl }
|
|
139
182
|
altText={ altText }
|
|
140
183
|
displayTitle={ displayTitle }
|
|
@@ -48,11 +48,25 @@
|
|
|
48
48
|
max-width: 100%;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
&--
|
|
52
|
-
|
|
51
|
+
&--pdf {
|
|
52
|
+
align-items: stretch;
|
|
53
|
+
width: 100%;
|
|
54
|
+
max-width: $wide-content-width;
|
|
55
|
+
margin-inline: auto;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&__pdf {
|
|
59
|
+
display: flex;
|
|
60
|
+
flex: 1;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
min-width: 0;
|
|
64
|
+
border: 0;
|
|
65
|
+
border-radius: $radius-small;
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
&__file-info {
|
|
69
|
+
text-align: center;
|
|
56
70
|
background: $gray-100;
|
|
57
71
|
padding: $grid-unit-30;
|
|
58
72
|
border-radius: 2px;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
+
@use "@wordpress/base-styles/mixins" as *;
|
|
2
3
|
@use "@wordpress/base-styles/variables" as *;
|
|
3
4
|
|
|
4
5
|
// Default to WordPress core's admin theme blue when the host hasn't
|
|
@@ -38,8 +39,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
&:has(.rotation-ruler__input:focus-visible) {
|
|
41
|
-
|
|
42
|
-
outline-offset: 2px;
|
|
42
|
+
@include outset-ring__focus();
|
|
43
43
|
border-radius: 4px;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -70,6 +70,10 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
70
70
|
border-radius: 1px;
|
|
71
71
|
transform: translateX(-50%);
|
|
72
72
|
pointer-events: none;
|
|
73
|
+
|
|
74
|
+
@media (forced-colors: active) {
|
|
75
|
+
background: CanvasText;
|
|
76
|
+
}
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
.rotation-ruler__strip {
|
|
@@ -94,12 +94,9 @@ export function useRulerDrag(
|
|
|
94
94
|
onPointerDownStart,
|
|
95
95
|
} = options;
|
|
96
96
|
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
// effect (not at render time) to satisfy `react-hooks/refs`; the
|
|
101
|
-
// effect flushes after commit, so by the time any pointer handler
|
|
102
|
-
// runs, the ref reflects the latest committed `value`.
|
|
97
|
+
// Per-drag state, including the last emitted value. Pointermove
|
|
98
|
+
// handlers fire far faster than React commits, so they cannot read
|
|
99
|
+
// `value` from closure. Pointerdown seeds it from the committed `value`.
|
|
103
100
|
const latestRef = useRef< {
|
|
104
101
|
value: number;
|
|
105
102
|
startX: number;
|
|
@@ -119,9 +116,6 @@ export function useRulerDrag(
|
|
|
119
116
|
capturePointerId: 0,
|
|
120
117
|
windowPointerUp: null,
|
|
121
118
|
} );
|
|
122
|
-
useEffect( () => {
|
|
123
|
-
latestRef.current.value = value;
|
|
124
|
-
}, [ value ] );
|
|
125
119
|
|
|
126
120
|
const endDrag = useCallback( () => {
|
|
127
121
|
const state = latestRef.current;
|
|
@@ -170,7 +164,8 @@ export function useRulerDrag(
|
|
|
170
164
|
state.captureElement = event.currentTarget;
|
|
171
165
|
state.capturePointerId = event.pointerId;
|
|
172
166
|
state.startX = event.clientX;
|
|
173
|
-
state.
|
|
167
|
+
state.value = value;
|
|
168
|
+
state.startValue = value;
|
|
174
169
|
state.activeStep = event.shiftKey ? step / 2 : step;
|
|
175
170
|
state.dragging = true;
|
|
176
171
|
onPointerDownStart?.();
|
|
@@ -186,7 +181,7 @@ export function useRulerDrag(
|
|
|
186
181
|
window.addEventListener( 'pointerup', onWindowUp );
|
|
187
182
|
window.addEventListener( 'pointercancel', onWindowUp );
|
|
188
183
|
},
|
|
189
|
-
[ disabled, onPointerDownStart, endDrag, step ]
|
|
184
|
+
[ disabled, onPointerDownStart, endDrag, step, value ]
|
|
190
185
|
);
|
|
191
186
|
|
|
192
187
|
const onPointerMove = useCallback(
|