@wordpress/media-editor 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/build/components/media-editor/index.cjs +74 -21
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +23 -3
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +6 -11
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +17 -1
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +4 -5
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +1 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +0 -1
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +10 -4
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +32 -67
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build-module/components/media-editor/index.mjs +78 -25
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +23 -3
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +1 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +0 -1
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +10 -5
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-style/style-rtl.css +104 -57
- package/build-style/style.css +103 -57
- package/build-types/components/media-editor/index.d.ts +17 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +163 -28
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +0 -1
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +155 -240
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-save-media-editor.mjs","names":["coreStore","noticesStore"],"sources":["../../../src/components/media-editor/use-save-media-editor.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\nimport {\n\tbuildModifiers,\n\ttype Modifier,\n} from '../media-editor-modal/build-modifiers';\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tif ( ! session.hasOutputEdits ) {\n\t\treturn [];\n\t}\n\treturn buildModifiers( session.cropper );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.cropper.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,qBAAqB;CAC1B;CACA;CACA;CACA;CACA;AACD;AAGA,MAAa,+BAA+B;AAuC5C,SAAS,iBAAkB,SAA0C;CACpE,IAAK,CAAE,QAAQ,gBACd,OAAO,CAAC;CAET,OAAO,eAAgB,QAAQ,OAAQ;AACxC;AAEA,SAAS,iBACR,cACA,OAC4B;CAC5B,MAAM,gBAA2C,CAAC;CAClD,KAAM,MAAM,OAAO,oBAClB,IAAK,gBAAgB,OAAO,cAC3B,cAAe,OAAQ,aAAc;CAOvC,IAAK,EAAI,UAAU,kBAAmB,OAAO,SAAS,KAAA,GACrD,cAAc,OAAO,MAAM;CAE5B,OAAO;AACR;AAEA,SAAgB,mBAAoB,EACnC,SACA,IACA,SACA,OACA,SACA,qBACqD;CACrD,MAAM,WAAW,YAAY;CAC7B,MAAM,EACL,wBACA,sBACA,2BACG,YAAaA,KAAU;CAC3B,MAAM,EAAE,mBAAmB,qBAAqB,YAAaC,OAAa;CAC1E,MAAM,CAAE,UAAU,eAAgB,SAAU,KAAM;CAyIlD,OAAO;EAAE;EAAU,MAvIN,YAAa,YAAY;GACrC,iBAAkB,Y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ACpB;EACD,GAAG;GACF;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAEsB;CAAE;AACzB"}
|
|
1
|
+
{"version":3,"file":"use-save-media-editor.mjs","names":["coreStore","noticesStore"],"sources":["../../../src/components/media-editor/use-save-media-editor.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getImageEdit, mapImageEdit } from '@wordpress/image-editor';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant — the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * image editor's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0–100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\ntype Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tif ( ! session.hasOutputEdits ) {\n\t\treturn [];\n\t}\n\tconst edit = getImageEdit( session.imageEditor.state );\n\tif ( ! edit ) {\n\t\treturn [];\n\t}\n\n\t// Core applies modifiers in the order they arrive.\n\treturn mapImageEdit< Modifier >( edit, {\n\t\tflip: ( flip ) => ( { type: 'flip', args: { flip } } ),\n\t\trotation: ( angle ) => ( { type: 'rotate', args: { angle } } ),\n\t\tcrop: ( { x, y, width, height } ) => ( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: x * 100,\n\t\t\t\ttop: y * 100,\n\t\t\t\twidth: width * 100,\n\t\t\t\theight: height * 100,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],"mappings":";;;;;;;;AAuCA,MAAM,qBAAqB;CAC1B;CACA;CACA;CACA;CACA;AACD;AAGA,MAAa,+BAA+B;AAuC5C,SAAS,iBAAkB,SAA0C;CACpE,IAAK,CAAE,QAAQ,gBACd,OAAO,CAAC;CAET,MAAM,OAAO,aAAc,QAAQ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AAQD,KAAU,CAAC,CACnB,iCACA,YACA,cACA,QAGU,GACX,WACD;KAEA,QAAU,MAAM,SAAU;MACzB,MAAM,gBAAiB,SAAU;MACjC,QAAQ;MACR,MAAM;OACL,KAAK;OACL;OACA,GAAG;MACJ;KACD,CAAE;KAEF,IAAK,OACJ,qBACC,YACA,cACA,OACA,KAAA,GACA,IACD;IAEF,OAAO,IACN,qBACA,CAAE,SACA,OAAQA,KAAU,CAAC,CACnB,wBACA,YACA,cACA,QACD,GAID,QAAQ,kBAAkB;SAE1B,QAAU,MAAM,uBACf,YACA,cACA,UACA,EAAE,cAAc,KAAK,CACtB;IAGD,MAAM,OAAS,SAAS;IAExB,IAAK,QAAQ,KAAK,OAAO,UACxB,uBAAwB,YAAY,cAAc,QAAS;IAG5D,IAAK,QAAQ,KAAK,IAAK;KACtB,IAAK,KAAK,OAAO,IAChB,QAAQ,MAAM;KAEf,UAAW;MACV,IAAI,KAAK;MACT,KAAK,KAAK;MACV,OAAO;MACP;KACD,CAAE;IACH;GACD,SAAU,OAAQ;IACjB,MAAM,UACL,iBAAiB,QACd,MAAM,UACF,OAAiC,WACtC,GAAI,4BAA6B;IACpC,kBACC,UACG,QAEA,GAAI,0BAA2B,GAC/B,OACD,IACC,QAEA,GAAI,0BAA2B,GAC/B,OACD,GACF;KACC,MAAM;KACN,SAAS;IACV,CACD;GACD,UAAU;IACT,YAAa,KAAM;GACpB;EACD,GAAG;GACF;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAEsB;CAAE;AACzB"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import clsx from "clsx";
|
|
2
|
-
import { useCallback, useEffect,
|
|
2
|
+
import { useCallback, useEffect, useState } from "@wordpress/element";
|
|
3
3
|
import { Spinner } from "@wordpress/components";
|
|
4
4
|
import { __ } from "@wordpress/i18n";
|
|
5
|
+
import { ImageEditorCanvas } from "@wordpress/image-editor";
|
|
5
6
|
import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
|
|
6
7
|
import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { resolveAspectRatio, useMediaEditor } from "../../state/index.mjs";
|
|
8
|
+
import { useMediaEditor } from "../../state/index.mjs";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
// packages/media-editor/src/components/media-editor-canvas/index.tsx
|
|
11
11
|
/**
|
|
12
12
|
* Editing surface for image media in the media editor modal. Pulls
|
|
13
|
-
* its
|
|
13
|
+
* its image editor controller from the surrounding `<MediaEditorStateProvider>`
|
|
14
14
|
* so the bottom bar and Crop sidebar tab share the same state.
|
|
15
15
|
*
|
|
16
16
|
* Returns `null` for missing or non-image media so the modal's outer
|
|
@@ -25,11 +25,8 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
25
25
|
function MediaEditorCanvas({ isPlacementActive = false, onGestureStart, onGestureEnd, disabled = false }) {
|
|
26
26
|
const { media } = useMediaEditorContext();
|
|
27
27
|
const session = useMediaEditor();
|
|
28
|
-
const { aspectRatioValue } = session.cropOptions;
|
|
29
|
-
const cropperImage = session.cropper.state.image;
|
|
30
28
|
const { beginGesture, endGesture, setSourceImage } = session;
|
|
31
29
|
const [settled, setSettled] = useState();
|
|
32
|
-
const aspectRatio = useMemo(() => resolveAspectRatio(aspectRatioValue, cropperImage), [aspectRatioValue, cropperImage]);
|
|
33
30
|
const handleGestureStart = useCallback(() => {
|
|
34
31
|
beginGesture();
|
|
35
32
|
onGestureStart?.();
|
|
@@ -84,14 +81,12 @@ function MediaEditorCanvas({ isPlacementActive = false, onGestureStart, onGestur
|
|
|
84
81
|
className: "media-editor-canvas__spinner",
|
|
85
82
|
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
86
83
|
}), /* @__PURE__ */ jsx("div", {
|
|
87
|
-
className: clsx("media-editor-
|
|
88
|
-
children: /* @__PURE__ */ jsx(
|
|
84
|
+
className: clsx("media-editor-canvas__image-editor", { "is-loaded": status === "loaded" }),
|
|
85
|
+
children: /* @__PURE__ */ jsx(ImageEditorCanvas, {
|
|
89
86
|
src: mediaUrl,
|
|
90
|
-
controller: session.
|
|
91
|
-
aspectRatio,
|
|
87
|
+
controller: session.imageEditor,
|
|
92
88
|
freeformCrop: true,
|
|
93
|
-
showGrid: "interactive",
|
|
94
|
-
isPlacementActive,
|
|
89
|
+
showGrid: isPlacementActive ? true : "interactive",
|
|
95
90
|
onGestureStart: handleGestureStart,
|
|
96
91
|
onGestureEnd: handleGestureEnd,
|
|
97
92
|
onImageLoaded: handleImageLoaded,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-editor-canvas/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useCallback, useEffect,
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-editor-canvas/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { Spinner as WCSpinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { ImageEditorCanvas } from '@wordpress/image-editor';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { useMediaEditor } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas gesture ends. */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Disable crop interaction on the canvas. Set while the edit is saving,\n\t * so a drag cannot change the crop after the request was built.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its image editor controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n * @param props.disabled\n */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n\tdisabled = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst session = useMediaEditor();\n\tconst { beginGesture, endGesture, setSourceImage } = session;\n\n\t// Tracks whether the image pixels have actually loaded. The image editor's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\t// Stored with the URL it is for, so a new URL (restoring the original\n\t// swaps it in place) counts as loading until the image editor reports back.\n\tconst [ settled, setSettled ] = useState< {\n\t\turl: string | undefined;\n\t\tstatus: 'loaded' | 'error';\n\t} >();\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetSourceImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\tconst status =\n\t\tsettled && settled.url === mediaUrl ? settled.status : 'loading';\n\tconst handleImageLoaded = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'loaded' } );\n\t}, [ mediaUrl ] );\n\tconst handleImageError = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'error' } );\n\t}, [ mediaUrl ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The image editor stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS).\n\t\t\t *\n\t\t\t * The crop area is never focused programmatically: the modal keeps\n\t\t\t * initial focus on the dialog frame, and users reach the crop area\n\t\t\t * by tabbing to it.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__image-editor', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<ImageEditorCanvas\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ session.imageEditor }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\t// Keep the grid up while a sidebar placement control is in\n\t\t\t\t\t// use; otherwise show it only while the crop is changing.\n\t\t\t\t\tshowGrid={ isPlacementActive ? true : 'interactive' }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonG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,CAAE;CAChD,GAAG,CAAE,QAAS,CAAE;CAEhB,IAAK,CAAE,YAAY,CAAE,SACpB,OAAO;CAGR,IAAK,WAAW,SACf,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAAC,OAAD;GAAK,WAAU;GAA6B,MAAK;GAChD,UAAA,oBAAC,KAAD,EAAA,UAAK,GAAI,uBAAwB,EAAM,CAAA;EACnC,CAAA;CACD,CAAA;CAIP,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,WAAW,aACZ,oBAAC,OAAD;GAAK,WAAU;GACd,UAAA,oBAACA,SAAD,CAAY,CAAA;EACR,CAAA,GAYN,oBAAC,OAAD;GACC,WAAY,KAAM,qCAAqC,EACtD,aAAa,WAAW,SACzB,CAAE;GAEF,UAAA,oBAAC,mBAAD;IACC,KAAM;IACN,YAAa,QAAQ;IACrB,cAAA;IAGA,UAAW,oBAAoB,OAAO;IACtC,gBAAiB;IACjB,cAAe;IACf,eAAgB;IAChB,cAAe;IACJ;GACX,CAAA;EACG,CAAA,CACD;;AAEP"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SelectControl, Stack, VisuallyHidden } from "@wordpress/ui";
|
|
2
2
|
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { Icon, getAspectRatioIcon } from "@wordpress/icons";
|
|
3
4
|
import { CROP_CONTROL_ATTR } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
4
5
|
import MediaEditorImageControls from "../media-editor-image-controls/index.mjs";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -39,7 +40,22 @@ function MediaEditorCropPanel({ aspectRatioValue, onAspectRatioChange, aspectRat
|
|
|
39
40
|
if (item && item.value !== null) onAspectRatioChange(item.value);
|
|
40
41
|
},
|
|
41
42
|
disabled,
|
|
42
|
-
items
|
|
43
|
+
items,
|
|
44
|
+
trigger: /* @__PURE__ */ jsx(SelectControl.Trigger, { children: (item) => /* @__PURE__ */ jsxs("span", {
|
|
45
|
+
className: "media-editor-crop-panel__aspect-ratio-option",
|
|
46
|
+
children: [/* @__PURE__ */ jsx(Icon, { icon: getAspectRatioIcon(Number(item.value)) }), /* @__PURE__ */ jsx("span", {
|
|
47
|
+
className: "media-editor-crop-panel__aspect-ratio-label",
|
|
48
|
+
children: item.label
|
|
49
|
+
})]
|
|
50
|
+
}) }),
|
|
51
|
+
children: items.map((item) => /* @__PURE__ */ jsx(SelectControl.Item, {
|
|
52
|
+
value: item,
|
|
53
|
+
label: item.label,
|
|
54
|
+
children: /* @__PURE__ */ jsx(SelectControl.ItemLabel, { children: /* @__PURE__ */ jsxs("span", {
|
|
55
|
+
className: "media-editor-crop-panel__aspect-ratio-option",
|
|
56
|
+
children: [/* @__PURE__ */ jsx(Icon, { icon: getAspectRatioIcon(Number(item.value)) }), item.label]
|
|
57
|
+
}) })
|
|
58
|
+
}, item.value))
|
|
43
59
|
})
|
|
44
60
|
]
|
|
45
61
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-crop-panel/index.tsx"],"sourcesContent":["import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-crop-panel/index.tsx"],"sourcesContent":["import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, getAspectRatioIcon } from '@wordpress/icons';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\n\nexport interface MediaEditorCropPanelProps {\n\t/**\n\t * Selected aspect-ratio preset value as a string (so it round-trips\n\t * through `<SelectControl>`). `'0'` = free, `'-1'` = original, any\n\t * positive number = fixed ratio.\n\t */\n\taspectRatioValue: string;\n\t/** Setter for the aspect-ratio preset value. */\n\tonAspectRatioChange: ( value: string ) => void;\n\t/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n\t/** Disable every control in the panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls: rotate, flip and zoom above the\n * aspect-ratio selector. Rendered where the panel docks; below that the\n * transform controls sit under the canvas instead, placed by the editor.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.disabled\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tdisabled = false,\n}: MediaEditorCropPanelProps ) {\n\tconst items = aspectRatioOptions.map( ( preset ) => ( {\n\t\tlabel: preset.label,\n\t\tvalue: preset.value.toString(),\n\t} ) );\n\n\treturn (\n\t\t// Tag the whole panel as a crop-control region so the modal's\n\t\t// Cmd+Z handler doesn't mistake the SelectControl input for a\n\t\t// metadata field (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"xl\"\n\t\t\t{ ...{ [ CROP_CONTROL_ATTR ]: true } }\n\t\t>\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Crop options' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<MediaEditorImageControls withLabels disabled={ disabled } />\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={\n\t\t\t\t\titems.find( ( item ) => item.value === aspectRatioValue ) ??\n\t\t\t\t\tnull\n\t\t\t\t}\n\t\t\t\tonValueChange={ ( item ) => {\n\t\t\t\t\tif ( item && item.value !== null ) {\n\t\t\t\t\t\tonAspectRatioChange( item.value );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\titems={ items }\n\t\t\t\ttrigger={\n\t\t\t\t\t<SelectControl.Trigger>\n\t\t\t\t\t\t{ ( item ) => (\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-label\">\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</SelectControl.Trigger>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ items.map( ( item ) => (\n\t\t\t\t\t<SelectControl.Item\n\t\t\t\t\t\tkey={ item.value }\n\t\t\t\t\t\tvalue={ item }\n\t\t\t\t\t\tlabel={ item.label }\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectControl.ItemLabel>\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</SelectControl.ItemLabel>\n\t\t\t\t\t</SelectControl.Item>\n\t\t\t\t) ) }\n\t\t\t</SelectControl>\n\t\t</Stack>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,SAAwB,qBAAsB,EAC7C,kBACA,qBACA,oBACA,WAAW,SACmB;CAC9B,MAAM,QAAQ,mBAAmB,KAAO,YAAc;EACrD,OAAO,OAAO;EACd,OAAO,OAAO,MAAM,SAAS;CAC9B,EAAI;CAEJ,OAIC,qBAAC,OAAD;EACC,WAAU;EACV,KAAI;GACK,oBAAqB;EAH/B,UAAA;GAKC,oBAAC,gBAAD;IAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;IAC3B,UAAA,GAAI,cAAe;GACN,CAAA;GAChB,oBAAC,0BAAD;IAA0B,YAAA;IAAsB;GAAY,CAAA;GAC5D,oBAAC,eAAD;IACC,OAAQ,GAAI,cAAe;IAC3B,OACC,MAAM,MAAQ,SAAU,KAAK,UAAU,gBAAiB,KACxD;IAED,gBAAkB,SAAU;KAC3B,IAAK,QAAQ,KAAK,UAAU,MAC3B,oBAAqB,KAAK,KAAM;IAElC;IACW;IACH;IACR,SACC,oBAAC,cAAc,SAAf,EAAA,WACK,SACH,qBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACC,oBAAC,MAAD,EACC,MAAO,mBACN,OAAQ,KAAK,KAAM,CACpB,EACA,CAAA,GACD,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,KAAK;KACF,CAAA,CACD;IAEe,CAAA,EAAA,CAAA;IAGtB,UAAA,MAAM,KAAO,SACd,oBAAC,cAAc,MAAf;KAEC,OAAQ;KACR,OAAQ,KAAK;KAEb,UAAA,oBAAC,cAAc,WAAf,EAAA,UACC,qBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACC,oBAAC,MAAD,EACC,MAAO,mBACN,OAAQ,KAAK,KAAM,CACpB,EACA,CAAA,GACC,KAAK,KACF;KACkB,CAAA,EAAA,CAAA;IACN,GAdb,KAAK,KAcQ,CACnB;GACY,CAAA;EACT;;AAET"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __ } from "@wordpress/i18n";
|
|
2
2
|
import { useMediaEditor } from "../../state/index.mjs";
|
|
3
3
|
import { useCropGestureHandlers } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
4
|
-
import { MAX_ROTATION_OFFSET } from "../../image-editor/core/constants.mjs";
|
|
5
4
|
import RotationRuler from "../rotation-ruler/index.mjs";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
|
7
6
|
// packages/media-editor/src/components/media-editor-fine-rotation/index.tsx
|
|
@@ -16,14 +15,14 @@ import { jsx } from "react/jsx-runtime";
|
|
|
16
15
|
* @param props.disabled
|
|
17
16
|
*/
|
|
18
17
|
function MediaEditorFineRotation({ onPlacementControlInteraction, disabled = false }) {
|
|
19
|
-
const { state, setRotation } = useMediaEditor().
|
|
18
|
+
const { state, setRotation, maxRotationOffset } = useMediaEditor().imageEditor;
|
|
20
19
|
const rotationGestureHandlers = useCropGestureHandlers({ commitOnKeyUp: false });
|
|
21
20
|
const baseAngle = Math.round(state.rotation / 90) * 90;
|
|
22
21
|
const visualDir = state.flip.horizontal !== state.flip.vertical ? -1 : 1;
|
|
23
22
|
const fineOffset = (state.rotation - baseAngle) * visualDir;
|
|
24
23
|
const handleRotationSlider = (value) => {
|
|
25
24
|
const EPS = .01;
|
|
26
|
-
const clamped = Math.max(-
|
|
25
|
+
const clamped = Math.max(-maxRotationOffset + EPS, Math.min(maxRotationOffset - EPS, value));
|
|
27
26
|
onPlacementControlInteraction?.();
|
|
28
27
|
setRotation(baseAngle + clamped * visualDir);
|
|
29
28
|
};
|
|
@@ -33,8 +32,8 @@ function MediaEditorFineRotation({ onPlacementControlInteraction, disabled = fal
|
|
|
33
32
|
...rotationGestureHandlers,
|
|
34
33
|
children: /* @__PURE__ */ jsx(RotationRuler, {
|
|
35
34
|
label: __("Fine rotation"),
|
|
36
|
-
min: -
|
|
37
|
-
max:
|
|
35
|
+
min: -maxRotationOffset,
|
|
36
|
+
max: maxRotationOffset,
|
|
38
37
|
value: fineOffset,
|
|
39
38
|
onChange: handleRotationSlider,
|
|
40
39
|
disabled
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation, maxRotationOffset } =\n\t\tuseMediaEditor().imageEditor;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-maxRotationOffset + EPS,\n\t\t\tMath.min( maxRotationOffset - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -maxRotationOffset }\n\t\t\t\tmax={ maxRotationOffset }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAwB,wBAAyB,EAChD,+BACA,WAAW,SACsB;CACjC,MAAM,EAAE,OAAO,aAAa,sBAC3B,eAAe,CAAC,CAAC;CAIlB,MAAM,0BAA0B,uBAAwB,EACvD,eAAe,MAChB,CAAE;CAKF,MAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CAEtD,MAAM,YADa,MAAM,KAAK,eAAe,MAAM,KAAK,WACzB,KAAK;CACpC,MAAM,cAAe,MAAM,WAAW,aAAc;CAEpD,MAAM,wBAAyB,UAAmB;EAIjD,MAAM,MAAM;EACZ,MAAM,UAAU,KAAK,IACpB,CAAC,oBAAoB,KACrB,KAAK,IAAK,oBAAoB,KAAK,KAAM,CAC1C;EACA,gCAAgC;EAChC,YAAa,YAAY,UAAU,SAAU;CAC9C;CAEA,OACC,oBAAC,OAAD;EACC,MAAK;EACL,WAAU;EACV,GAAK;EAEL,UAAA,oBAAC,eAAD;GACC,OAAQ,GAAI,eAAgB;GAC5B,KAAM,CAAC;GACP,KAAM;GACN,OAAQ;GACR,UAAW;GACA;EACX,CAAA;CACG,CAAA;AAEP"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Button } from "@wordpress/components";
|
|
2
2
|
import { Menu } from "@wordpress/ui";
|
|
3
3
|
import { __ } from "@wordpress/i18n";
|
|
4
|
-
import { aspectRatio, flipHorizontal, flipVertical, lineSolid, plus, rotateLeft, rotateRight } from "@wordpress/icons";
|
|
4
|
+
import { aspectRatio, flipHorizontal, flipVertical, getAspectRatioIcon, lineSolid, plus, rotateLeft, rotateRight } from "@wordpress/icons";
|
|
5
5
|
import { useMediaEditor } from "../../state/index.mjs";
|
|
6
|
-
import { MAX_ZOOM } from "../../image-editor/core/constants.mjs";
|
|
7
|
-
import { getMinZoom } from "../../image-editor/core/containment.mjs";
|
|
8
6
|
import { useCropOptions } from "../media-editor/use-crop-options.mjs";
|
|
9
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
8
|
// packages/media-editor/src/components/media-editor-image-controls/index.tsx
|
|
@@ -30,12 +28,11 @@ const DEFAULT_ZOOM_FACTOR = 1.2;
|
|
|
30
28
|
* @param props.disabled
|
|
31
29
|
*/
|
|
32
30
|
function MediaEditorImageControls({ withLabels = false, showAspectRatioControl = false, aspectRatioPresets, zoomFactor = DEFAULT_ZOOM_FACTOR, disabled = false }) {
|
|
33
|
-
const { state, setFlip, snapRotate90, setZoom } = useMediaEditor().
|
|
31
|
+
const { state, setFlip, snapRotate90, setZoom, minZoom, maxZoom } = useMediaEditor().imageEditor;
|
|
34
32
|
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } = useCropOptions({ aspectRatioPresets });
|
|
35
33
|
const hasAspectRatioControl = !withLabels && showAspectRatioControl;
|
|
36
|
-
const minZoom = getMinZoom(state);
|
|
37
34
|
const zoomByFactor = (factor) => {
|
|
38
|
-
setZoom(Math.min(
|
|
35
|
+
setZoom(Math.min(maxZoom, Math.max(minZoom, state.zoom * factor)));
|
|
39
36
|
};
|
|
40
37
|
const rotateButtons = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
41
38
|
size: "compact",
|
|
@@ -84,7 +81,7 @@ function MediaEditorImageControls({ withLabels = false, showAspectRatioControl =
|
|
|
84
81
|
icon: plus,
|
|
85
82
|
label: __("Zoom in"),
|
|
86
83
|
showTooltip: true,
|
|
87
|
-
disabled: disabled || state.zoom >=
|
|
84
|
+
disabled: disabled || state.zoom >= maxZoom,
|
|
88
85
|
accessibleWhenDisabled: true,
|
|
89
86
|
onClick: () => zoomByFactor(zoomFactor)
|
|
90
87
|
}), /* @__PURE__ */ jsx(Button, {
|
|
@@ -118,6 +115,7 @@ function MediaEditorImageControls({ withLabels = false, showAspectRatioControl =
|
|
|
118
115
|
value: preset.value.toString(),
|
|
119
116
|
closeOnClick: true,
|
|
120
117
|
disabled,
|
|
118
|
+
prefix: /* @__PURE__ */ jsx(Menu.PrefixIcon, { icon: getAspectRatioIcon(preset.value) }),
|
|
121
119
|
children: /* @__PURE__ */ jsx(Menu.ItemLabel, { children: preset.label })
|
|
122
120
|
}, preset.value))]
|
|
123
121
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["aspectRatioIcon"],"sources":["../../../src/components/media-editor-image-controls/index.tsx"],"sourcesContent":["import { Button } from '@wordpress/components';\nimport {\n\t// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.\n\tMenu,\n} from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport {\n\taspectRatio as aspectRatioIcon,\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tlineSolid,\n\tplus,\n} from '@wordpress/icons';\nimport { useMediaEditor } from '../../state';\nimport {\n\tMAX_ZOOM,\n\ttype AspectRatioPreset,\n} from '../../image-editor/core/constants';\nimport { getMinZoom } from '../../image-editor/core/containment';\nimport { useCropOptions } from '../media-editor/use-crop-options';\n\n/**\n * Default zoom factor per +/- click. Zooming is geometric, so a fixed\n * multiplier — rather than an additive step — makes each click feel like the\n * same amount of zoom at any level (an additive `+0.1` is a 10% jump at 1× but\n * a ~1% nudge at 10×). `1.2` is ~+20% per click. Overridable via the\n * `zoomFactor` prop.\n */\nexport const DEFAULT_ZOOM_FACTOR = 1.2;\n\nexport interface MediaEditorImageControlsProps {\n\t/**\n\t * When `true`, render rotate, flip and zoom as labelled groups — the Crop\n\t * panel layout used on wide viewports. When `false` (default), render a\n\t * single flat row of icon buttons — the footer layout used at narrower\n\t * widths.\n\t */\n\twithLabels?: boolean;\n\t/**\n\t * When `true`, include an aspect-ratio dropdown in the flat toolbar.\n\t * Omitted from the labelled panel layout because the Crop panel already\n\t * renders the full aspect-ratio select control.\n\t */\n\tshowAspectRatioControl?: boolean;\n\t/** Optional caller-supplied aspect-ratio presets. */\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/**\n\t * Multiplier applied to the zoom per +/- click — zoom in multiplies by it,\n\t * zoom out divides by it. Must be greater than 1. Defaults to\n\t * `DEFAULT_ZOOM_FACTOR` (1.2).\n\t */\n\tzoomFactor?: number;\n\t/**\n\t * Disable every control. Set while the edit is saving, so the crop the\n\t * request was built from cannot change under it.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Image editing controls placed independently per viewport: on wide viewports\n * rotate/flip/zoom render inside the Crop panel (`withLabels`), and at narrower\n * widths they fall back into the footer toolbar (flat row), where the\n * aspect-ratio dropdown can also be shown.\n *\n * @param props\n * @param props.withLabels\n * @param props.showAspectRatioControl\n * @param props.aspectRatioPresets\n * @param props.zoomFactor\n * @param props.disabled\n */\nexport default function MediaEditorImageControls( {\n\twithLabels = false,\n\tshowAspectRatioControl = false,\n\taspectRatioPresets,\n\tzoomFactor = DEFAULT_ZOOM_FACTOR,\n\tdisabled = false,\n}: MediaEditorImageControlsProps ) {\n\tconst { state, setFlip, snapRotate90, setZoom } = useMediaEditor().cropper;\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst hasAspectRatioControl = ! withLabels && showAspectRatioControl;\n\tconst minZoom = getMinZoom( state );\n\tconst zoomByFactor = ( factor: number ) => {\n\t\tsetZoom(\n\t\t\tMath.min( MAX_ZOOM, Math.max( minZoom, state.zoom * factor ) )\n\t\t);\n\t};\n\n\tconst rotateButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90° counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90° clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst flipButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst zoomButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ plus }\n\t\t\t\tlabel={ __( 'Zoom in' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom >= MAX_ZOOM }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( zoomFactor ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ lineSolid }\n\t\t\t\tlabel={ __( 'Zoom out' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom <= minZoom }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( 1 / zoomFactor ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst aspectRatioDropdown = hasAspectRatioControl ? (\n\t\t<Menu.Root>\n\t\t\t<Menu.Trigger\n\t\t\t\tdisabled={ disabled }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ticon={ aspectRatioIcon }\n\t\t\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Menu.Popup\n\t\t\t\tpositioner={ <Menu.Positioner side=\"top\" align=\"center\" /> }\n\t\t\t>\n\t\t\t\t<Menu.RadioGroup\n\t\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\t\tonValueChange={ ( value ) => {\n\t\t\t\t\t\tif ( ! disabled ) {\n\t\t\t\t\t\t\tsetAspectRatioValue( value );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Menu.GroupLabel>{ __( 'Aspect ratio' ) }</Menu.GroupLabel>\n\t\t\t\t\t{ aspectRatioOptions.map( ( preset ) => (\n\t\t\t\t\t\t<Menu.RadioItem\n\t\t\t\t\t\t\tkey={ preset.value }\n\t\t\t\t\t\t\tvalue={ preset.value.toString() }\n\t\t\t\t\t\t\tcloseOnClick\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Menu.ItemLabel>{ preset.label }</Menu.ItemLabel>\n\t\t\t\t\t\t</Menu.RadioItem>\n\t\t\t\t\t) ) }\n\t\t\t\t</Menu.RadioGroup>\n\t\t\t</Menu.Popup>\n\t\t</Menu.Root>\n\t) : null;\n\n\tif ( withLabels ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-image-controls is-stacked\">\n\t\t\t\t<div className=\"media-editor-image-controls__transforms\">\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Rotate' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rotate' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ rotateButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Flip' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Flip' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ flipButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label={ __( 'Zoom' ) }\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Zoom' ) }\n\t\t\t\t\t</span>\n\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t{ zoomButtons }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-image-controls\">\n\t\t\t{ rotateButtons }\n\t\t\t{ flipButtons }\n\t\t\t{ zoomButtons }\n\t\t\t{ aspectRatioDropdown }\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,MAAa,sBAAsB;;;;;;;;;;;;;;AA4CnC,SAAwB,yBAA0B,EACjD,aAAa,OACb,yBAAyB,OACzB,oBACA,aAAa,qBACb,WAAW,SACuB;CAClC,MAAM,EAAE,OAAO,SAAS,cAAc,YAAY,eAAe,CAAC,CAAC;CACnE,MAAM,EAAE,kBAAkB,qBAAqB,uBAC9C,eAAgB,EAAE,mBAAmB,CAAE;CACxC,MAAM,wBAAwB,CAAE,cAAc;CAC9C,MAAM,UAAU,WAAY,KAAM;CAClC,MAAM,gBAAiB,WAAoB;EAC1C,QACC,KAAK,IAAK,UAAU,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CACD;GACD,CAAA,CAAA;EACL,CAAA,GAAA,qBAAC,OAAD;GACC,WAAU;GACV,MAAK;GACL,cAAa,GAAI,MAAO;GAHzB,UAAA,CAKC,oBAAC,QAAD;IACC,WAAU;IACV,eAAY;IAEV,UAAA,GAAI,MAAO;GACR,CAAA,GACN,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,CACD;EACD,CAAA,CAAA;;CAIP,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACG;GACA;GACA;GACA;EACE;;AAEP"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["aspectRatioIcon"],"sources":["../../../src/components/media-editor-image-controls/index.tsx"],"sourcesContent":["import { Button } from '@wordpress/components';\nimport {\n\t// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.\n\tMenu,\n} from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport {\n\taspectRatio as aspectRatioIcon,\n\tgetAspectRatioIcon,\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tlineSolid,\n\tplus,\n} from '@wordpress/icons';\nimport { useMediaEditor } from '../../state';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { useCropOptions } from '../media-editor/use-crop-options';\n\n/**\n * Default zoom factor per +/- click. Zooming is geometric, so a fixed\n * multiplier — rather than an additive step — makes each click feel like the\n * same amount of zoom at any level (an additive `+0.1` is a 10% jump at 1× but\n * a ~1% nudge at 10×). `1.2` is ~+20% per click. Overridable via the\n * `zoomFactor` prop.\n */\nexport const DEFAULT_ZOOM_FACTOR = 1.2;\n\nexport interface MediaEditorImageControlsProps {\n\t/**\n\t * When `true`, render rotate, flip and zoom as labelled groups — the Crop\n\t * panel layout used on wide viewports. When `false` (default), render a\n\t * single flat row of icon buttons — the footer layout used at narrower\n\t * widths.\n\t */\n\twithLabels?: boolean;\n\t/**\n\t * When `true`, include an aspect-ratio dropdown in the flat toolbar.\n\t * Omitted from the labelled panel layout because the Crop panel already\n\t * renders the full aspect-ratio select control.\n\t */\n\tshowAspectRatioControl?: boolean;\n\t/** Optional caller-supplied aspect-ratio presets. */\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/**\n\t * Multiplier applied to the zoom per +/- click — zoom in multiplies by it,\n\t * zoom out divides by it. Must be greater than 1. Defaults to\n\t * `DEFAULT_ZOOM_FACTOR` (1.2).\n\t */\n\tzoomFactor?: number;\n\t/**\n\t * Disable every control. Set while the edit is saving, so the crop the\n\t * request was built from cannot change under it.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Image editing controls placed independently per viewport: on wide viewports\n * rotate/flip/zoom render inside the Crop panel (`withLabels`), and at narrower\n * widths they fall back into the footer toolbar (flat row), where the\n * aspect-ratio dropdown can also be shown.\n *\n * @param props\n * @param props.withLabels\n * @param props.showAspectRatioControl\n * @param props.aspectRatioPresets\n * @param props.zoomFactor\n * @param props.disabled\n */\nexport default function MediaEditorImageControls( {\n\twithLabels = false,\n\tshowAspectRatioControl = false,\n\taspectRatioPresets,\n\tzoomFactor = DEFAULT_ZOOM_FACTOR,\n\tdisabled = false,\n}: MediaEditorImageControlsProps ) {\n\tconst { state, setFlip, snapRotate90, setZoom, minZoom, maxZoom } =\n\t\tuseMediaEditor().imageEditor;\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst hasAspectRatioControl = ! withLabels && showAspectRatioControl;\n\tconst zoomByFactor = ( factor: number ) => {\n\t\tsetZoom(\n\t\t\tMath.min( maxZoom, Math.max( minZoom, state.zoom * factor ) )\n\t\t);\n\t};\n\n\tconst rotateButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90° counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90° clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst flipButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst zoomButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ plus }\n\t\t\t\tlabel={ __( 'Zoom in' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom >= maxZoom }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( zoomFactor ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ lineSolid }\n\t\t\t\tlabel={ __( 'Zoom out' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ disabled || state.zoom <= minZoom }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( 1 / zoomFactor ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst aspectRatioDropdown = hasAspectRatioControl ? (\n\t\t<Menu.Root>\n\t\t\t<Menu.Trigger\n\t\t\t\tdisabled={ disabled }\n\t\t\t\trender={\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ticon={ aspectRatioIcon }\n\t\t\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Menu.Popup\n\t\t\t\tpositioner={ <Menu.Positioner side=\"top\" align=\"center\" /> }\n\t\t\t>\n\t\t\t\t<Menu.RadioGroup\n\t\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\t\tonValueChange={ ( value ) => {\n\t\t\t\t\t\tif ( ! disabled ) {\n\t\t\t\t\t\t\tsetAspectRatioValue( value );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Menu.GroupLabel>{ __( 'Aspect ratio' ) }</Menu.GroupLabel>\n\t\t\t\t\t{ aspectRatioOptions.map( ( preset ) => (\n\t\t\t\t\t\t<Menu.RadioItem\n\t\t\t\t\t\t\tkey={ preset.value }\n\t\t\t\t\t\t\tvalue={ preset.value.toString() }\n\t\t\t\t\t\t\tcloseOnClick\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\tprefix={\n\t\t\t\t\t\t\t\t<Menu.PrefixIcon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon( preset.value ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Menu.ItemLabel>{ preset.label }</Menu.ItemLabel>\n\t\t\t\t\t\t</Menu.RadioItem>\n\t\t\t\t\t) ) }\n\t\t\t\t</Menu.RadioGroup>\n\t\t\t</Menu.Popup>\n\t\t</Menu.Root>\n\t) : null;\n\n\tif ( withLabels ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-image-controls is-stacked\">\n\t\t\t\t<div className=\"media-editor-image-controls__transforms\">\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Rotate' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rotate' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ rotateButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Flip' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Flip' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ flipButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label={ __( 'Zoom' ) }\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Zoom' ) }\n\t\t\t\t\t</span>\n\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t{ zoomButtons }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-image-controls\">\n\t\t\t{ rotateButtons }\n\t\t\t{ flipButtons }\n\t\t\t{ zoomButtons }\n\t\t\t{ aspectRatioDropdown }\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAa,sBAAsB;;;;;;;;;;;;;;AA4CnC,SAAwB,yBAA0B,EACjD,aAAa,OACb,yBAAyB,OACzB,oBACA,aAAa,qBACb,WAAW,SACuB;CAClC,MAAM,EAAE,OAAO,SAAS,cAAc,SAAS,SAAS,YACvD,eAAe,CAAC,CAAC;CAClB,MAAM,EAAE,kBAAkB,qBAAqB,uBAC9C,eAAgB,EAAE,mBAAmB,CAAE;CACxC,MAAM,wBAAwB,CAAE,cAAc;CAC9C,MAAM,gBAAiB,WAAoB;EAC1C,QACC,KAAK,IAAK,SAAS,KAAK,IAAK,SAAS,MAAM,OAAO,MAAO,CAAE,CAC7D;CACD;CAEA,MAAM,gBACL,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EACC,MAAK;EACL,MAAO;EACP,OAAQ,GAAI,8BAA+B;EAC3C,aAAA;EACW;EACX,wBAAA;EACA,eAAgB,aAAc,EAAG;CACjC,CAAA,GACD,oBAAC,QAAD;EACC,MAAK;EACL,MAAO;EACP,OAAQ,GAAI,sBAAuB;EAC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AA;GACE,CAAA,CACD;EACD,CAAA,CAAA;;CAIP,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACG;GACA;GACA;GACA;EACE;;AAEP"}
|
|
@@ -86,6 +86,7 @@ function KeyCombinationDisplay({ keyCombination }) {
|
|
|
86
86
|
else label = charString;
|
|
87
87
|
return /* @__PURE__ */ jsx("kbd", {
|
|
88
88
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-term",
|
|
89
|
+
dir: "ltr",
|
|
89
90
|
"aria-label": label,
|
|
90
91
|
children: keys.map((key, index) => key === "+" && modifier ? /* @__PURE__ */ jsx(Fragment, { children: key }, index) : /* @__PURE__ */ jsx("kbd", {
|
|
91
92
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-key",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\n\ninterface KeyCombination {\n\t/** Modifier for cross-platform display (e.g. 'primary', 'primaryShift', 'shift'). */\n\tmodifier?: WPKeycodeModifier;\n\t/** The key character(s) to display. Pass an array to render each as its own key. */\n\tcharacter: string | string[];\n\t/** Optional aria-label override (used when character is a symbol). */\n\tariaLabel?: string;\n}\n\ninterface ShortcutEntry {\n\tdescription: string;\n\tkeyCombination: KeyCombination;\n}\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Arrow keys' ),\n\t\t},\n\t},\n\t{\n\t\tdescription: __( 'Zoom in' ),\n\t\tkeyCombination: { character: '+' },\n\t},\n\t{\n\t\tdescription: __( 'Zoom out' ),\n\t\tkeyCombination: { character: '-' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° clockwise' ),\n\t\tkeyCombination: { character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° counter-clockwise' ),\n\t\tkeyCombination: { modifier: 'shift', character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Flip horizontal' ),\n\t\tkeyCombination: { character: 'H' },\n\t},\n\t{\n\t\tdescription: __( 'Flip vertical' ),\n\t\tkeyCombination: { character: 'V' },\n\t},\n\t{\n\t\tdescription: __( 'Pan or resize crop (large step)' ),\n\t\tkeyCombination: {\n\t\t\tmodifier: 'shift',\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Shift + Arrow keys' ),\n\t\t},\n\t},\n];\n\nfunction KeyCombinationDisplay( {\n\tkeyCombination,\n}: {\n\tkeyCombination: KeyCombination;\n} ) {\n\tconst { modifier, character, ariaLabel } = keyCombination;\n\n\tlet keys: string[];\n\tif ( Array.isArray( character ) ) {\n\t\tif ( modifier ) {\n\t\t\t// Get the modifier prefix (e.g. ['⇧', '+']) from the first char,\n\t\t\t// then replace the last element with all the individual chars.\n\t\t\tconst sample = displayShortcutList[ modifier ]( character[ 0 ] );\n\t\t\tkeys = [ ...sample.slice( 0, -1 ), ...character ];\n\t\t} else {\n\t\t\tkeys = character;\n\t\t}\n\t} else {\n\t\tkeys = modifier\n\t\t\t? displayShortcutList[ modifier ]( character )\n\t\t\t: [ character ];\n\t}\n\n\tconst charString = Array.isArray( character )\n\t\t? character.join( '' )\n\t\t: character;\n\tlet label: string;\n\tif ( ariaLabel ) {\n\t\tlabel = ariaLabel;\n\t} else if ( modifier ) {\n\t\tlabel = shortcutAriaLabel[ modifier ]( charString );\n\t} else {\n\t\tlabel = charString;\n\t}\n\n\treturn (\n\t\t<kbd\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-term\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ keys.map( ( key, index ) =>\n\t\t\t\tkey === '+' && modifier ? (\n\t\t\t\t\t<Fragment key={ index }>{ key }</Fragment>\n\t\t\t\t) : (\n\t\t\t\t\t<kbd\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-key\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ key }\n\t\t\t\t\t</kbd>\n\t\t\t\t)\n\t\t\t) }\n\t\t</kbd>\n\t);\n}\n\ninterface MediaEditorKeyboardShortcutsModalProps {\n\tonClose: () => void;\n}\n\nexport default function MediaEditorKeyboardShortcutsModal( {\n\tonClose,\n}: MediaEditorKeyboardShortcutsModalProps ) {\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal\"\n\t\t\ttitle={ __( 'Keyboard shortcuts' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t<p className=\"media-editor-keyboard-shortcuts-modal__note\">\n\t\t\t\t{ __(\n\t\t\t\t\t'These shortcuts work when the image editor has focus.'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t{ /*\n\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t */ }\n\t\t\t{ /* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t<ul\n\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-list\"\n\t\t\t\trole=\"list\"\n\t\t\t>\n\t\t\t\t{ SHORTCUTS.map( ( { description, keyCombination }, index ) => (\n\t\t\t\t\t<li\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"media-editor-keyboard-shortcuts-modal__shortcut-description\">\n\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<KeyCombinationDisplay\n\t\t\t\t\t\t\tkeyCombination={ keyCombination }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</li>\n\t\t\t\t) ) }\n\t\t\t</ul>\n\t\t\t{ /* eslint-enable jsx-a11y/no-redundant-roles */ }\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;AAuBA,MAAM,YAA6B;CAClC;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAW,WAAW;EAAI;CACvD;CACA;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAgB,WAAW;EAAI;CAC5D;CACA;EACC,aAAa,GAAI,KAAM;EACvB,gBAAgB;GACf,WAAW;IAAE;IAAK;IAAK;IAAK;GAAI;GAChC,WAAW,GAAI,YAAa;EAC7B;CACD;CACA;EACC,aAAa,GAAI,SAAU;EAC3B,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,UAAW;EAC5B,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,sBAAuB;EACxC,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,8BAA+B;EAChD,gBAAgB;GAAE,UAAU;GAAS,WAAW;EAAI;CACrD;CACA;EACC,aAAa,GAAI,iBAAkB;EACnC,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,eAAgB;EACjC,gBAAgB,EAAE,WAAW,IAAI;CAClC;CACA;EACC,aAAa,GAAI,iCAAkC;EACnD,gBAAgB;GACf,UAAU;GACV,WAAW;IAAE;IAAK;IAAK;IAAK;GAAI;GAChC,WAAW,GAAI,oBAAqB;EACrC;CACD;AACD;AAEA,SAAS,sBAAuB,EAC/B,kBAGG;CACH,MAAM,EAAE,UAAU,WAAW,cAAc;CAE3C,IAAI;CACJ,IAAK,MAAM,QAAS,SAAU,GAAI;EACjC,IAAK,UAIJ,OAAO,CAAE,GADM,oBAAqB,SAAU,CAAE,UAAW,EAC1C,CAAC,CAAC,MAAO,GAAG,EAAG,GAAG,GAAG,SAAU;OAEhD,OAAO;CAET,OACC,OAAO,WACJ,oBAAqB,SAAU,CAAE,SAAU,IAC3C,CAAE,SAAU;CAGhB,MAAM,aAAa,MAAM,QAAS,SAAU,IACzC,UAAU,KAAM,EAAG,IACnB;CACH,IAAI;CACJ,IAAK,WACJ,QAAQ;MACF,IAAK,UACX,QAAQ,kBAAmB,SAAU,CAAE,UAAW;MAElD,QAAQ;CAGT,OACC,oBAAC,OAAD;EACC,WAAU;EACV,cAAa;EAEX,UAAA,KAAK,KAAO,KAAK,UAClB,QAAQ,OAAO,WACd,oBAAC,UAAD,EAAA,UAA0B,IAAe,GAAzB,KAAyB,IAEzC,oBAAC,OAAD;GAEC,WAAU;GAER,UAAA;EACE,GAJE,KAIF,CAEP;CACI,CAAA;AAEP;AAMA,SAAwB,kCAAmC,EAC1D,WAC2C;CAC3C,OACC,qBAAC,OAAD;EACC,WAAU;EACV,OAAQ,GAAI,oBAAqB;EACjC,gBAAiB;EAHlB,UAAA,CAKC,oBAAC,KAAD;GAAG,WAAU;GACV,UAAA,GACD,uDACD;EACE,CAAA,GAMH,oBAAC,MAAD;GACC,WAAU;GACV,MAAK;GAEH,UAAA,UAAU,KAAO,EAAE,aAAa,kBAAkB,UACnD,qBAAC,MAAD;IAEC,WAAU;IAFX,UAAA,CAIC,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA;IACG,CAAA,GACN,oBAAC,uBAAD,EACkB,eACjB,CAAA,CACE;GATG,GAAA,KASH,CACH;EACC,CAAA,CAEE;;AAET"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\n\ninterface KeyCombination {\n\t/** Modifier for cross-platform display (e.g. 'primary', 'primaryShift', 'shift'). */\n\tmodifier?: WPKeycodeModifier;\n\t/** The key character(s) to display. Pass an array to render each as its own key. */\n\tcharacter: string | string[];\n\t/** Optional aria-label override (used when character is a symbol). */\n\tariaLabel?: string;\n}\n\ninterface ShortcutEntry {\n\tdescription: string;\n\tkeyCombination: KeyCombination;\n}\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Arrow keys' ),\n\t\t},\n\t},\n\t{\n\t\tdescription: __( 'Zoom in' ),\n\t\tkeyCombination: { character: '+' },\n\t},\n\t{\n\t\tdescription: __( 'Zoom out' ),\n\t\tkeyCombination: { character: '-' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° clockwise' ),\n\t\tkeyCombination: { character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° counter-clockwise' ),\n\t\tkeyCombination: { modifier: 'shift', character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Flip horizontal' ),\n\t\tkeyCombination: { character: 'H' },\n\t},\n\t{\n\t\tdescription: __( 'Flip vertical' ),\n\t\tkeyCombination: { character: 'V' },\n\t},\n\t{\n\t\tdescription: __( 'Pan or resize crop (large step)' ),\n\t\tkeyCombination: {\n\t\t\tmodifier: 'shift',\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Shift + Arrow keys' ),\n\t\t},\n\t},\n];\n\nfunction KeyCombinationDisplay( {\n\tkeyCombination,\n}: {\n\tkeyCombination: KeyCombination;\n} ) {\n\tconst { modifier, character, ariaLabel } = keyCombination;\n\n\tlet keys: string[];\n\tif ( Array.isArray( character ) ) {\n\t\tif ( modifier ) {\n\t\t\t// Get the modifier prefix (e.g. ['⇧', '+']) from the first char,\n\t\t\t// then replace the last element with all the individual chars.\n\t\t\tconst sample = displayShortcutList[ modifier ]( character[ 0 ] );\n\t\t\tkeys = [ ...sample.slice( 0, -1 ), ...character ];\n\t\t} else {\n\t\t\tkeys = character;\n\t\t}\n\t} else {\n\t\tkeys = modifier\n\t\t\t? displayShortcutList[ modifier ]( character )\n\t\t\t: [ character ];\n\t}\n\n\tconst charString = Array.isArray( character )\n\t\t? character.join( '' )\n\t\t: character;\n\tlet label: string;\n\tif ( ariaLabel ) {\n\t\tlabel = ariaLabel;\n\t} else if ( modifier ) {\n\t\tlabel = shortcutAriaLabel[ modifier ]( charString );\n\t} else {\n\t\tlabel = charString;\n\t}\n\n\treturn (\n\t\t<kbd\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-term\"\n\t\t\tdir=\"ltr\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ keys.map( ( key, index ) =>\n\t\t\t\tkey === '+' && modifier ? (\n\t\t\t\t\t<Fragment key={ index }>{ key }</Fragment>\n\t\t\t\t) : (\n\t\t\t\t\t<kbd\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-key\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ key }\n\t\t\t\t\t</kbd>\n\t\t\t\t)\n\t\t\t) }\n\t\t</kbd>\n\t);\n}\n\ninterface MediaEditorKeyboardShortcutsModalProps {\n\tonClose: () => void;\n}\n\nexport default function MediaEditorKeyboardShortcutsModal( {\n\tonClose,\n}: MediaEditorKeyboardShortcutsModalProps ) {\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal\"\n\t\t\ttitle={ __( 'Keyboard shortcuts' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t<p className=\"media-editor-keyboard-shortcuts-modal__note\">\n\t\t\t\t{ __(\n\t\t\t\t\t'These shortcuts work when the image editor has focus.'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t{ /*\n\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t */ }\n\t\t\t{ /* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t<ul\n\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-list\"\n\t\t\t\trole=\"list\"\n\t\t\t>\n\t\t\t\t{ SHORTCUTS.map( ( { description, keyCombination }, index ) => (\n\t\t\t\t\t<li\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"media-editor-keyboard-shortcuts-modal__shortcut-description\">\n\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<KeyCombinationDisplay\n\t\t\t\t\t\t\tkeyCombination={ keyCombination }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</li>\n\t\t\t\t) ) }\n\t\t\t</ul>\n\t\t\t{ /* eslint-enable jsx-a11y/no-redundant-roles */ }\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;AAuBA,MAAM,YAA6B;CAClC;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAW,WAAW;EAAI;CACvD;CACA;EACC,aAAa,GAAI,MAAO;EACxB,gBAAgB;GAAE,UAAU;GAAgB,WAAW;EAAI;CAC5D;CACA;EACC,aAAa,GAAI,KAAM;EACvB,gBAAgB;GACf,WAAW;IAAE;I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UAA0B,IAAe,GAAzB,KAAyB,IAEzC,oBAAC,OAAD;GAEC,WAAU;GAER,UAAA;EACE,GAJE,KAIF,CAEP;CACI,CAAA;AAEP;AAMA,SAAwB,kCAAmC,EAC1D,WAC2C;CAC3C,OACC,qBAAC,OAAD;EACC,WAAU;EACV,OAAQ,GAAI,oBAAqB;EACjC,gBAAiB;EAHlB,UAAA,CAKC,oBAAC,KAAD;GAAG,WAAU;GACV,UAAA,GACD,uDACD;EACE,CAAA,GAMH,oBAAC,MAAD;GACC,WAAU;GACV,MAAK;GAEH,UAAA,UAAU,KAAO,EAAE,aAAa,kBAAkB,UACnD,qBAAC,MAAD;IAEC,WAAU;IAFX,UAAA,CAIC,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA;IACG,CAAA,GACN,oBAAC,uBAAD,EACkB,eACjB,CAAA,CACE;GATG,GAAA,KASH,CACH;EACC,CAAA,CAEE;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["mediaEditorStore","noticesStore"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["mediaEditorStore","noticesStore"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,cAAc;CACtB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ACA,cAAgB,EACf,UACA,gBACA,WACA,gCAEA,oBAAC,kBAAD;GACC,WAAU;GACV,WAAY;GAEZ,UAAA,qBAAC,OAAD;IACC,WAAU;IACV,OAAQ,GAAI,YAAa;IACzB,MAAK;IACL,eAAgB;IACY;IAChB;IACK;IACjB,eACC,oBAAC,YAAY,eAAb,EAA2B,iBAAA,KAAiB,CAAA;IAT9C,UAAA,CAYG,UACF,oBAAC,aAAD,CAAc,CAAA,CACR;;EACU,CAAA;CAEnB,CAAA;AAEH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["WCSpinner","VStack"],"sources":["../../../src/components/media-form/index.tsx"],"sourcesContent":["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t'author',\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,eAAqB;CAC1B,QAAQ,EACP,MAAM,QACP;CACA,QAAQ;EACP,GAAG;GAAE;GAAS;GAAY;GAAW;EAAc,CAAC,CAAC,KAAO,QAAU;GACrE;GACA,QAAQ;IACP,MAAM;IACN,eAAe;GAChB;EACD,EAAI;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AACD;;;;;;;;;;;;;;;AAwBA,SAAwB,UAAW,EAClC,MAAM,eACN,UACmB;CACnB,MAAM,EACL,OACA,QACA,MAAM,cACN,aACG,sBAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAACA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,qBAACC,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,oBAAC,gBAAD;KAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;KAC3B,UAAA,GAAI,eAAgB;IACP,CAAA;IACd;IACF,oBAAC,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["WCSpinner","VStack"],"sources":["../../../src/components/media-form/index.tsx"],"sourcesContent":["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t{\n\t\t\tid: 'author',\n\t\t\tlayout: {\n\t\t\t\ttype: 'panel' as const,\n\t\t\t\tshowPlaceholderIfEmpty: true,\n\t\t\t},\n\t\t},\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,eAAqB;CAC1B,QAAQ,EACP,MAAM,QACP;CACA,QAAQ;EACP,GAAG;GAAE;GAAS;GAAY;GAAW;EAAc,CAAC,CAAC,KAAO,QAAU;GACrE;GACA,QAAQ;IACP,MAAM;IACN,eAAe;GAChB;EACD,EAAI;EACJ;EACA;GACC,IAAI;GACJ,QAAQ;IACP,MAAM;IACN,wBAAwB;GACzB;EACD;EACA;EACA;EACA;EACA;EACA;CACD;AACD;;;;;;;;;;;;;;;AAwBA,SAAwB,UAAW,EAClC,MAAM,eACN,UACmB;CACnB,MAAM,EACL,OACA,QACA,MAAM,cACN,aACG,sBAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAACA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,qBAACC,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,oBAAC,gBAAD;KAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;KAC3B,UAAA,GAAI,eAAgB;IACP,CAAA;IACd;IACF,oBAAC,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import { Spinner as WCSpinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tpreviewType: string;\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tdisplayTitle,\n\tmimeType,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t<p className=\"media-editor-preview__file-name\">{ displayTitle }</p>\n\t\t\t<p className=\"media-editor-preview__mime-type\">{ mimeType }</p>\n\t\t\t{ /* eslint-disable-next-line react/jsx-no-target-blank */ }\n\t\t\t<a\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\
|
|
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\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,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,MA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mjs";
|
|
3
2
|
// packages/media-editor/src/state/aspect-ratio-presets.ts
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Sentinel value for "Original" aspect ratio — resolved at runtime
|
|
5
|
+
* to the image's natural width / height.
|
|
6
|
+
*/
|
|
7
|
+
const ORIGINAL_ASPECT_RATIO = -1;
|
|
8
|
+
/**
|
|
9
|
+
* The presets the editor offers by default. They live here rather than
|
|
10
|
+
* in the image editor package, because which ratios to offer, and what
|
|
11
|
+
* to call them, is a product choice. The package takes a plain number.
|
|
7
12
|
*/
|
|
8
13
|
const DEFAULT_ASPECT_RATIOS = [
|
|
9
14
|
{
|
|
@@ -12,7 +17,7 @@ const DEFAULT_ASPECT_RATIOS = [
|
|
|
12
17
|
},
|
|
13
18
|
{
|
|
14
19
|
label: __("Original"),
|
|
15
|
-
value:
|
|
20
|
+
value: -1
|
|
16
21
|
},
|
|
17
22
|
{
|
|
18
23
|
label: __("Square (1:1)"),
|
|
@@ -43,6 +48,6 @@ const DEFAULT_ASPECT_RATIOS = [
|
|
|
43
48
|
value: 2 / 3
|
|
44
49
|
}
|
|
45
50
|
];
|
|
46
|
-
export { DEFAULT_ASPECT_RATIOS };
|
|
51
|
+
export { DEFAULT_ASPECT_RATIOS, ORIGINAL_ASPECT_RATIO };
|
|
47
52
|
|
|
48
53
|
//# sourceMappingURL=aspect-ratio-presets.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aspect-ratio-presets.mjs","names":[],"sources":["../../src/state/aspect-ratio-presets.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\
|
|
1
|
+
{"version":3,"file":"aspect-ratio-presets.mjs","names":[],"sources":["../../src/state/aspect-ratio-presets.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/**\n\t * The aspect ratio value (width / height). 0 = free,\n\t * `ORIGINAL_ASPECT_RATIO` = the image's own ratio.\n\t */\n\tvalue: number;\n}\n\n/**\n * Sentinel value for \"Original\" aspect ratio — resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\n/**\n * The presets the editor offers by default. They live here rather than\n * in the image editor package, because which ratios to offer, and what\n * to call them, is a product choice. The package takes a plain number.\n */\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],"mappings":";;;;;;AAmBA,MAAa,wBAAwB;;;;;;AAOrC,MAAa,wBAA6C;CACzD;EAAE,OAAO,GAAI,MAAO;EAAG,OAAO;CAAE;CAChC;EAAE,OAAO,GAAI,UAAW;EAAG,OAAA;CAA6B;CACxD;EAAE,OAAO,GAAI,cAAe;EAAG,OAAO;CAAE;CACxC;EAAE,OAAO,GAAI,kBAAmB;EAAG,OAAO,KAAK;CAAE;CACjD;EAAE,OAAO,GAAI,iBAAkB;EAAG,OAAO,IAAI;CAAG;CAChD;EAAE,OAAO,GAAI,eAAgB;EAAG,OAAO,IAAI;CAAE;CAC7C;EAAE,OAAO,GAAI,wBAAyB;EAAG,OAAO,IAAI;CAAE;CACtD;EAAE,OAAO,GAAI,aAAc;EAAG,OAAO,IAAI;CAAE;CAC3C;EAAE,OAAO,GAAI,sBAAuB;EAAG,OAAO,IAAI;CAAE;AACrD"}
|