@wordpress/media-editor 0.21.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 +12 -0
- package/build/components/media-editor/index.cjs +533 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -57
- 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 -72
- 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 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +76 -77
- 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 -710
- 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 +134 -112
- 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 -294
- 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 -673
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -32
- 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 +98 -96
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
- 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 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +68 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +106 -90
- 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 -686
- 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 -90
- 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 -286
- 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 +4 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -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-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-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 +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +1 -0
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +2 -1
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/media-editor/index.tsx +215 -162
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -2
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +16 -26
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-preview/index.tsx +66 -23
- 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 +1 -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 +19 -27
- 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 +2 -2
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +2 -6
- package/src/state/use-media-editor-state.ts +7 -5
- 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
|
@@ -1,98 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
import { Spinner as WCSpinner } from "@wordpress/components";
|
|
1
|
+
import { Spinner } from "@wordpress/components";
|
|
3
2
|
import { useState } from "@wordpress/element";
|
|
4
3
|
import { __ } from "@wordpress/i18n";
|
|
5
4
|
import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
|
|
6
5
|
import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
|
|
7
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
7
|
+
// packages/media-editor/src/components/media-preview/index.tsx
|
|
8
|
+
function MediaPreviewFileInfo({ mediaUrl, displayTitle, mimeType }) {
|
|
9
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
10
|
+
className: "media-editor-preview__file-info",
|
|
11
|
+
children: [
|
|
12
|
+
/* @__PURE__ */ jsx("p", {
|
|
13
|
+
className: "media-editor-preview__file-name",
|
|
14
|
+
children: displayTitle
|
|
15
|
+
}),
|
|
16
|
+
/* @__PURE__ */ jsx("p", {
|
|
17
|
+
className: "media-editor-preview__mime-type",
|
|
18
|
+
children: mimeType
|
|
19
|
+
}),
|
|
20
|
+
/* @__PURE__ */ jsx("a", {
|
|
21
|
+
href: mediaUrl,
|
|
22
|
+
target: "_blank",
|
|
23
|
+
rel: "noopener",
|
|
24
|
+
className: "media-editor-preview__download-link",
|
|
25
|
+
children: __("View file")
|
|
26
|
+
})
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mimeType, onLoad, onError, loadingState }) {
|
|
31
|
+
switch (previewType) {
|
|
32
|
+
case "image": return /* @__PURE__ */ jsx("img", {
|
|
33
|
+
className: loadingState === "loaded" ? "loaded" : "",
|
|
34
|
+
src: mediaUrl,
|
|
35
|
+
alt: altText || "",
|
|
36
|
+
onLoad,
|
|
37
|
+
onError
|
|
38
|
+
});
|
|
39
|
+
case "video": return /* @__PURE__ */ jsx("video", {
|
|
40
|
+
src: mediaUrl,
|
|
41
|
+
controls: true,
|
|
42
|
+
onError,
|
|
43
|
+
children: displayTitle
|
|
44
|
+
});
|
|
45
|
+
case "audio": return /* @__PURE__ */ jsx("audio", {
|
|
46
|
+
src: mediaUrl,
|
|
47
|
+
controls: true,
|
|
48
|
+
onError,
|
|
49
|
+
children: displayTitle
|
|
50
|
+
});
|
|
51
|
+
case "pdf": return /* @__PURE__ */ jsx("object", {
|
|
52
|
+
className: "media-editor-preview__pdf",
|
|
53
|
+
data: `${mediaUrl}#view=Fit&zoom=page-fit`,
|
|
54
|
+
type: "application/pdf",
|
|
55
|
+
"aria-label": __("Embed of the selected PDF file."),
|
|
56
|
+
children: /* @__PURE__ */ jsx(MediaPreviewFileInfo, {
|
|
57
|
+
mediaUrl,
|
|
58
|
+
displayTitle,
|
|
59
|
+
mimeType
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
default: return /* @__PURE__ */ jsx(MediaPreviewFileInfo, {
|
|
63
|
+
mediaUrl,
|
|
64
|
+
displayTitle,
|
|
65
|
+
mimeType
|
|
66
|
+
});
|
|
67
|
+
}
|
|
50
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* MediaPreview component displays the media file in the editor canvas.
|
|
71
|
+
* Supports images, videos, audio files, and generic file displays.
|
|
72
|
+
*
|
|
73
|
+
* @param props - Component props including click handlers and accessibility attributes.
|
|
74
|
+
* @return The MediaPreview component.
|
|
75
|
+
*/
|
|
51
76
|
function MediaPreview(props) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
onLoad: () => setLoadingState("loaded"),
|
|
87
|
-
onError: () => setLoadingState("error"),
|
|
88
|
-
loadingState
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
);
|
|
77
|
+
const [loadingState, setLoadingState] = useState("loading");
|
|
78
|
+
const { media } = useMediaEditorContext();
|
|
79
|
+
const { source_url: mediaUrl, mime_type: mimeType, alt_text: altText, title } = media || {};
|
|
80
|
+
const mediaType = getMediaTypeFromMimeType(mimeType);
|
|
81
|
+
const previewType = mimeType === "application/pdf" && window.navigator.pdfViewerEnabled ? "pdf" : mediaType.type;
|
|
82
|
+
if (!mediaUrl) return /* @__PURE__ */ jsx("div", {
|
|
83
|
+
className: "media-editor-preview media-editor-preview--empty",
|
|
84
|
+
children: /* @__PURE__ */ jsx("p", { children: __("No media file available.") })
|
|
85
|
+
});
|
|
86
|
+
if (loadingState === "error") return /* @__PURE__ */ jsxs("div", {
|
|
87
|
+
className: "media-editor-preview media-editor-preview--error",
|
|
88
|
+
children: [/* @__PURE__ */ jsx("p", { children: __("Failed to load media file.") }), /* @__PURE__ */ jsx("p", {
|
|
89
|
+
className: "media-editor-preview__url",
|
|
90
|
+
children: mediaUrl
|
|
91
|
+
})]
|
|
92
|
+
});
|
|
93
|
+
const displayTitle = typeof title === "string" ? title : title?.rendered || title?.raw;
|
|
94
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
95
|
+
...props,
|
|
96
|
+
className: `media-editor-preview media-editor-preview--${previewType}`,
|
|
97
|
+
children: [previewType === "image" && loadingState === "loading" && /* @__PURE__ */ jsx("div", {
|
|
98
|
+
className: "media-editor-preview__spinner",
|
|
99
|
+
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
100
|
+
}), /* @__PURE__ */ jsx(MediaPreviewContent, {
|
|
101
|
+
previewType,
|
|
102
|
+
mediaUrl,
|
|
103
|
+
altText,
|
|
104
|
+
displayTitle,
|
|
105
|
+
mimeType,
|
|
106
|
+
onLoad: () => setLoadingState("loaded"),
|
|
107
|
+
onError: () => setLoadingState("error"),
|
|
108
|
+
loadingState
|
|
109
|
+
})]
|
|
110
|
+
});
|
|
94
111
|
}
|
|
95
|
-
export {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//# sourceMappingURL=index.mjs.map
|
|
112
|
+
export { MediaPreview as default };
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-preview/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Spinner as WCSpinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tmediaType: { type: string };\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\nfunction MediaPreviewContent( {\n\tmediaType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tmimeType,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( mediaType.type ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t\t\t<p className=\"media-editor-preview__file-name\">\n\t\t\t\t\t\t{ displayTitle }\n\t\t\t\t\t</p>\n\t\t\t\t\t<p className=\"media-editor-preview__mime-type\">\n\t\t\t\t\t\t{ mimeType }\n\t\t\t\t\t</p>\n\t\t\t\t\t{ /* eslint-disable-next-line react/jsx-no-target-blank */ }\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={ mediaUrl }\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"noopener\"\n\t\t\t\t\t\tclassName=\"media-editor-preview__download-link\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'View file' ) }\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty\">\n\t\t\t\t<p>{ __( 'No media file available.' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error\">\n\t\t\t\t<p>{ __( 'Failed to load media file.' ) }</p>\n\t\t\t\t<p className=\"media-editor-preview__url\">{ mediaUrl }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ `media-editor-preview media-editor-preview--${ mediaType.type }` }\n\t\t>\n\t\t\t{ mediaType.type === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tmediaType={ mediaType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tmimeType={ mimeType }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,WAAW,iBAAiB;AACrC,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AAoCrC,cAsBA,YAtBA;AAbJ,SAAS,oBAAqB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA8B;AAC7B,UAAS,UAAU,MAAO;AAAA,IACzB,KAAK;AACJ,aACC;AAAA,QAAC;AAAA;AAAA,UACA,WAAY,iBAAiB,WAAW,WAAW;AAAA,UACnD,KAAM;AAAA,UACN,KAAM,WAAW;AAAA,UACjB;AAAA,UACA;AAAA;AAAA,MACD;AAAA,IAEF,KAAK;AACJ,aACC,oBAAC,WAAM,KAAM,UAAW,UAAQ,MAAC,SAC9B,wBACH;AAAA,IAEF,KAAK;AACJ,aACC,oBAAC,WAAM,KAAM,UAAW,UAAQ,MAAC,SAC9B,wBACH;AAAA,IAEF;AACC,aACC,qBAAC,SAAI,WAAU,mCACd;AAAA,4BAAC,OAAE,WAAU,mCACV,wBACH;AAAA,QACA,oBAAC,OAAE,WAAU,mCACV,oBACH;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,MAAO;AAAA,YACP,QAAO;AAAA,YACP,KAAI;AAAA,YACJ,WAAU;AAAA,YAER,aAAI,WAAY;AAAA;AAAA,QACnB;AAAA,SACD;AAAA,EAEH;AACD;AASe,SAAR,aAA+B,OAA2B;AAChE,QAAM,CAAE,cAAc,eAAgB,IAAI,SAEvC,SAAU;AACb,QAAM,EAAE,MAAM,IAAI,sBAAsB;AAExC,QAAM;AAAA,IACL,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,UAAU;AAAA,IACV;AAAA,EACD,IAAI,SAAS,CAAC;AAEd,QAAM,YAAY,yBAA0B,QAAS;AAErD,MAAK,CAAE,UAAW;AACjB,WACC,oBAAC,SAAI,WAAU,oDACd,8BAAC,OAAI,aAAI,0BAA2B,GAAG,GACxC;AAAA,EAEF;AAEA,MAAK,iBAAiB,SAAU;AAC/B,WACC,qBAAC,SAAI,WAAU,oDACd;AAAA,0BAAC,OAAI,aAAI,4BAA6B,GAAG;AAAA,MACzC,oBAAC,OAAE,WAAU,6BAA8B,oBAAU;AAAA,OACtD;AAAA,EAEF;AAEA,QAAM,eACL,OAAO,UAAU,WAAW,QAAQ,OAAO,YAAY,OAAO;AAE/D,SACC;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACL,WAAY,8CAA+C,UAAU,IAAK;AAAA,MAExE;AAAA,kBAAU,SAAS,WAAW,iBAAiB,aAChD,oBAAC,SAAI,WAAU,iCACd,8BAAC,aAAU,GACZ;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,QAAS,MAAM,gBAAiB,QAAS;AAAA,YACzC,SAAU,MAAM,gBAAiB,OAAQ;AAAA,YACzC;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import { Spinner as WCSpinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tpreviewType: string;\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tdisplayTitle,\n\tmimeType,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t<p className=\"media-editor-preview__file-name\">{ displayTitle }</p>\n\t\t\t<p className=\"media-editor-preview__mime-type\">{ mimeType }</p>\n\t\t\t{ /* eslint-disable-next-line react/jsx-no-target-blank */ }\n\t\t\t<a\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\trel=\"noopener\"\n\t\t\t\tclassName=\"media-editor-preview__download-link\"\n\t\t\t>\n\t\t\t\t{ __( 'View file' ) }\n\t\t\t</a>\n\t\t</div>\n\t);\n}\n\nfunction MediaPreviewContent( {\n\tpreviewType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tmimeType,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( previewType ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tcase 'pdf':\n\t\t\t// The browser renders the children instead of the PDF when it\n\t\t\t// can't display it, e.g. when the request fails.\n\t\t\treturn (\n\t\t\t\t<object\n\t\t\t\t\tclassName=\"media-editor-preview__pdf\"\n\t\t\t\t\t// Ask the viewer to fit the whole page rather than the\n\t\t\t\t\t// width. Chrome reads `view`, Firefox reads `zoom`, and\n\t\t\t\t\t// Safari ignores both.\n\t\t\t\t\tdata={ `${ mediaUrl }#view=Fit&zoom=page-fit` }\n\t\t\t\t\ttype=\"application/pdf\"\n\t\t\t\t\taria-label={ __( 'Embed of the selected PDF file.' ) }\n\t\t\t\t>\n\t\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t\t/>\n\t\t\t\t</object>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t/>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\t// Without a built-in PDF viewer (e.g. on most mobile browsers), show\n\t// the file info instead of an embed that can't render.\n\tconst previewType =\n\t\tmimeType === 'application/pdf' && window.navigator.pdfViewerEnabled\n\t\t\t? 'pdf'\n\t\t\t: mediaType.type;\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty\">\n\t\t\t\t<p>{ __( 'No media file available.' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error\">\n\t\t\t\t<p>{ __( 'Failed to load media file.' ) }</p>\n\t\t\t\t<p className=\"media-editor-preview__url\">{ mediaUrl }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ `media-editor-preview media-editor-preview--${ previewType }` }\n\t\t>\n\t\t\t{ previewType === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tpreviewType={ previewType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tmimeType={ mimeType }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,qBAAsB,EAC9B,UACA,cACA,YAC8B;CAC9B,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACC,oBAAC,KAAD;IAAG,WAAU;IAAoC,UAAA;GAAiB,CAAA;GAClE,oBAAC,KAAD;IAAG,WAAU;IAAoC,UAAA;GAAa,CAAA;GAE9D,oBAAC,KAAD;IACC,MAAO;IACP,QAAO;IACP,KAAI;IACJ,WAAU;IAER,UAAA,GAAI,WAAY;GAChB,CAAA;EACC;;AAEP;AAEA,SAAS,oBAAqB,EAC7B,aACA,UACA,SACA,cACA,UACA,QACA,SACA,gBAC6B;CAC7B,QAAS,aAAT;EACC,KAAK,SACJ,OACC,oBAAC,OAAD;GACC,WAAY,iBAAiB,WAAW,WAAW;GACnD,KAAM;GACN,KAAM,WAAW;GACR;GACC;EACV,CAAA;EAEH,KAAK,SACJ,OACC,oBAAC,SAAD;GAAO,KAAM;GAAW,UAAA;GAAmB;GACxC,UAAA;EACI,CAAA;EAET,KAAK,SACJ,OACC,oBAAC,SAAD;GAAO,KAAM;GAAW,UAAA;GAAmB;GACxC,UAAA;EACI,CAAA;EAET,KAAK,OAGJ,OACC,oBAAC,UAAD;GACC,WAAU;GAIV,MAAO,GAAI,SAAU;GACrB,MAAK;GACL,cAAa,GAAI,iCAAkC;GAEnD,UAAA,oBAAC,sBAAD;IACY;IACI;IACJ;GACX,CAAA;EACM,CAAA;EAEV,SACC,OACC,oBAAC,sBAAD;GACY;GACI;GACJ;EACX,CAAA;CAEJ;AACD;;;;;;;;AASA,SAAwB,aAAc,OAA2B;CAChE,MAAM,CAAE,cAAc,mBAAoB,SAEvC,SAAU;CACb,MAAM,EAAE,UAAU,sBAAsB;CAExC,MAAM,EACL,YAAY,UACZ,WAAW,UACX,UAAU,SACV,UACG,SAAS,CAAC;CAEd,MAAM,YAAY,yBAA0B,QAAS;CAIrD,MAAM,cACL,aAAa,qBAAqB,OAAO,UAAU,mBAChD,QACA,UAAU;CAEd,IAAK,CAAE,UACN,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAAC,KAAD,EAAA,UAAK,GAAI,0BAA2B,EAAM,CAAA;CACtC,CAAA;CAIP,IAAK,iBAAiB,SACrB,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACC,oBAAC,KAAD,EAAA,UAAK,GAAI,4BAA6B,EAAM,CAAA,GAC5C,oBAAC,KAAD;GAAG,WAAU;GAA8B,UAAA;EAAa,CAAA,CACpD;;CAIP,MAAM,eACL,OAAO,UAAU,WAAW,QAAQ,OAAO,YAAY,OAAO;CAE/D,OACC,qBAAC,OAAD;EACC,GAAK;EACL,WAAY,8CAA+C;EAF5D,UAAA,CAIG,gBAAgB,WAAW,iBAAiB,aAC7C,oBAAC,OAAD;GAAK,WAAU;GACd,UAAA,oBAACA,SAAD,CAAY,CAAA;EACR,CAAA,GAEN,oBAAC,qBAAD;GACe;GACH;GACD;GACK;GACJ;GACX,cAAe,gBAAiB,QAAS;GACzC,eAAgB,gBAAiB,OAAQ;GAC1B;EACf,CAAA,CACG;;AAEP"}
|
|
@@ -1,173 +1,170 @@
|
|
|
1
|
-
// packages/media-editor/src/components/rotation-ruler/index.tsx
|
|
2
1
|
import clsx from "clsx";
|
|
3
2
|
import { useId, useMemo, useRef } from "@wordpress/element";
|
|
4
|
-
import {
|
|
3
|
+
import { clampValue, useRulerDrag } from "./use-ruler-drag.mjs";
|
|
5
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
// packages/media-editor/src/components/rotation-ruler/index.tsx
|
|
6
|
+
const STRIP_HEIGHT = 32;
|
|
7
|
+
const LABEL_BASELINE_Y = 11;
|
|
8
|
+
const MAJOR_INTERVAL = 15;
|
|
9
|
+
const TICK_HEIGHT_MINOR = 4;
|
|
10
|
+
const TICK_HEIGHT_MID = 8;
|
|
11
|
+
const TICK_HEIGHT_MAJOR = 14;
|
|
12
|
+
/**
|
|
13
|
+
* Build the tick list for the ruler strip.
|
|
14
|
+
*
|
|
15
|
+
* @param min Lower bound of the ruler in value units.
|
|
16
|
+
* @param max Upper bound of the ruler in value units.
|
|
17
|
+
*/
|
|
12
18
|
function useTicks(min, max) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
return useMemo(() => {
|
|
20
|
+
const out = [];
|
|
21
|
+
for (let v = Math.ceil(min); v <= Math.floor(max); v += 1) {
|
|
22
|
+
let kind = "minor";
|
|
23
|
+
let height = TICK_HEIGHT_MINOR;
|
|
24
|
+
if (v % 15 === 0) {
|
|
25
|
+
kind = "major";
|
|
26
|
+
height = TICK_HEIGHT_MAJOR;
|
|
27
|
+
} else if (v % 5 === 0) {
|
|
28
|
+
kind = "mid";
|
|
29
|
+
height = TICK_HEIGHT_MID;
|
|
30
|
+
}
|
|
31
|
+
out.push({
|
|
32
|
+
value: v,
|
|
33
|
+
kind,
|
|
34
|
+
height
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}, [min, max]);
|
|
29
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Format a numeric ruler value for display, trimming a trailing `.0`.
|
|
42
|
+
*
|
|
43
|
+
* @param value Value to format.
|
|
44
|
+
*/
|
|
30
45
|
function formatValue(value) {
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
const rounded = Math.round(value * 10) / 10;
|
|
47
|
+
return Number.isInteger(rounded) ? rounded.toFixed(0) : rounded.toFixed(1);
|
|
33
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Horizontal "scrub-the-ruler" slider for fine-grained numeric input
|
|
51
|
+
* such as rotation in degrees.
|
|
52
|
+
*
|
|
53
|
+
* Renders a visually hidden `<input type="range">` for assistive
|
|
54
|
+
* technologies and keyboard input alongside a decorative tick strip
|
|
55
|
+
* that the user can drag with a pointer.
|
|
56
|
+
*
|
|
57
|
+
* @param props Component props. See `RotationRulerProps`.
|
|
58
|
+
*/
|
|
34
59
|
function RotationRuler(props) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
)),
|
|
143
|
-
majorTicks.map((tick) => /* @__PURE__ */ jsxs(
|
|
144
|
-
"text",
|
|
145
|
-
{
|
|
146
|
-
x: tick.value * pxPerUnit,
|
|
147
|
-
y: LABEL_BASELINE_Y,
|
|
148
|
-
textAnchor: "middle",
|
|
149
|
-
className: "rotation-ruler__label",
|
|
150
|
-
children: [
|
|
151
|
-
tick.value,
|
|
152
|
-
unit
|
|
153
|
-
]
|
|
154
|
-
},
|
|
155
|
-
tick.value
|
|
156
|
-
))
|
|
157
|
-
]
|
|
158
|
-
}
|
|
159
|
-
) }),
|
|
160
|
-
/* @__PURE__ */ jsx("div", { className: "rotation-ruler__active-label", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("span", { className: "rotation-ruler__active-label-number", children: [
|
|
161
|
-
isNegative && /* @__PURE__ */ jsx("span", { className: "rotation-ruler__active-label-sign", children: "-" }),
|
|
162
|
-
digits,
|
|
163
|
-
/* @__PURE__ */ jsx("span", { className: "rotation-ruler__active-label-unit", children: unit })
|
|
164
|
-
] }) }),
|
|
165
|
-
/* @__PURE__ */ jsx("div", { className: "rotation-ruler__pointer", "aria-hidden": "true" })
|
|
166
|
-
]
|
|
167
|
-
}
|
|
168
|
-
);
|
|
60
|
+
const { value, onChange, min = -45, max = 45, step = 1, label, unit = "°", pixelsPerStep = 6, className, id, disabled = false } = props;
|
|
61
|
+
const inputRef = useRef(null);
|
|
62
|
+
const generatedId = useId();
|
|
63
|
+
const inputId = id ?? generatedId;
|
|
64
|
+
const dragHandlers = useRulerDrag({
|
|
65
|
+
value,
|
|
66
|
+
onChange,
|
|
67
|
+
min,
|
|
68
|
+
max,
|
|
69
|
+
step,
|
|
70
|
+
pixelsPerStep,
|
|
71
|
+
disabled,
|
|
72
|
+
onPointerDownStart: () => inputRef.current?.focus()
|
|
73
|
+
});
|
|
74
|
+
const handleKeyDown = (event) => {
|
|
75
|
+
const isIncrement = event.key === "ArrowRight" || event.key === "ArrowUp";
|
|
76
|
+
const isDecrement = event.key === "ArrowLeft" || event.key === "ArrowDown";
|
|
77
|
+
if (!isIncrement && !isDecrement) return;
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
if (disabled) return;
|
|
80
|
+
const direction = isIncrement ? 1 : -1;
|
|
81
|
+
const magnitude = event.shiftKey ? step / 2 : step;
|
|
82
|
+
const next = clampValue(value + direction * magnitude, min, max);
|
|
83
|
+
if (next !== value) onChange(next);
|
|
84
|
+
};
|
|
85
|
+
const display = `${formatValue(value)}${unit}`;
|
|
86
|
+
const ticks = useTicks(min, max);
|
|
87
|
+
const pxPerUnit = pixelsPerStep / step;
|
|
88
|
+
const stripStyle = useMemo(() => {
|
|
89
|
+
return { transform: `translateX(calc(-50% + ${-value * pxPerUnit}px))` };
|
|
90
|
+
}, [value, pxPerUnit]);
|
|
91
|
+
const closestMajor = Math.round(value / MAJOR_INTERVAL) * MAJOR_INTERVAL;
|
|
92
|
+
const numberText = Math.abs(value - closestMajor) < .01 ? `${closestMajor}` : formatValue(value);
|
|
93
|
+
const isNegative = numberText.startsWith("-");
|
|
94
|
+
const digits = isNegative ? numberText.slice(1) : numberText;
|
|
95
|
+
const majorTicks = ticks.filter((tick) => tick.kind === "major");
|
|
96
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
97
|
+
className: clsx("rotation-ruler", className),
|
|
98
|
+
role: "presentation",
|
|
99
|
+
"data-testid": "rotation-ruler",
|
|
100
|
+
"data-disabled": disabled || void 0,
|
|
101
|
+
...dragHandlers,
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsx("input", {
|
|
104
|
+
ref: inputRef,
|
|
105
|
+
id: inputId,
|
|
106
|
+
type: "range",
|
|
107
|
+
className: "rotation-ruler__input",
|
|
108
|
+
min,
|
|
109
|
+
max,
|
|
110
|
+
step: "any",
|
|
111
|
+
value,
|
|
112
|
+
disabled,
|
|
113
|
+
"aria-label": label,
|
|
114
|
+
"aria-valuetext": display,
|
|
115
|
+
onChange: (event) => onChange(clampValue(event.target.valueAsNumber, min, max)),
|
|
116
|
+
onKeyDown: handleKeyDown
|
|
117
|
+
}),
|
|
118
|
+
/* @__PURE__ */ jsx("div", {
|
|
119
|
+
className: "rotation-ruler__strip",
|
|
120
|
+
"aria-hidden": "true",
|
|
121
|
+
children: /* @__PURE__ */ jsxs("svg", {
|
|
122
|
+
className: "rotation-ruler__ticks",
|
|
123
|
+
style: stripStyle,
|
|
124
|
+
width: (max - min) * pxPerUnit,
|
|
125
|
+
height: STRIP_HEIGHT,
|
|
126
|
+
viewBox: `${min * pxPerUnit} 0 ${(max - min) * pxPerUnit} ${STRIP_HEIGHT}`,
|
|
127
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
128
|
+
children: [ticks.map((tick) => /* @__PURE__ */ jsx("line", {
|
|
129
|
+
x1: tick.value * pxPerUnit,
|
|
130
|
+
x2: tick.value * pxPerUnit,
|
|
131
|
+
y1: STRIP_HEIGHT - tick.height,
|
|
132
|
+
y2: STRIP_HEIGHT,
|
|
133
|
+
className: `rotation-ruler__tick rotation-ruler__tick--${tick.kind}`
|
|
134
|
+
}, tick.value)), majorTicks.map((tick) => /* @__PURE__ */ jsxs("text", {
|
|
135
|
+
x: tick.value * pxPerUnit,
|
|
136
|
+
y: LABEL_BASELINE_Y,
|
|
137
|
+
textAnchor: "middle",
|
|
138
|
+
className: "rotation-ruler__label",
|
|
139
|
+
children: [tick.value, unit]
|
|
140
|
+
}, tick.value))]
|
|
141
|
+
})
|
|
142
|
+
}),
|
|
143
|
+
/* @__PURE__ */ jsx("div", {
|
|
144
|
+
className: "rotation-ruler__active-label",
|
|
145
|
+
"aria-hidden": "true",
|
|
146
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
147
|
+
className: "rotation-ruler__active-label-number",
|
|
148
|
+
children: [
|
|
149
|
+
isNegative && /* @__PURE__ */ jsx("span", {
|
|
150
|
+
className: "rotation-ruler__active-label-sign",
|
|
151
|
+
children: "-"
|
|
152
|
+
}),
|
|
153
|
+
digits,
|
|
154
|
+
/* @__PURE__ */ jsx("span", {
|
|
155
|
+
className: "rotation-ruler__active-label-unit",
|
|
156
|
+
children: unit
|
|
157
|
+
})
|
|
158
|
+
]
|
|
159
|
+
})
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ jsx("div", {
|
|
162
|
+
className: "rotation-ruler__pointer",
|
|
163
|
+
"aria-hidden": "true"
|
|
164
|
+
})
|
|
165
|
+
]
|
|
166
|
+
});
|
|
169
167
|
}
|
|
170
|
-
export {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//# sourceMappingURL=index.mjs.map
|
|
168
|
+
export { RotationRuler as default };
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=index.mjs.map
|