@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131006.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/build/components/media-editor/index.cjs +560 -0
- package/build/components/media-editor/index.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +14 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +34 -27
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +42 -430
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-toolbar/index.cjs +143 -75
- package/build/components/media-editor-toolbar/index.cjs.map +3 -3
- package/build/components/media-form/index.cjs +3 -0
- package/build/components/media-form/index.cjs.map +2 -2
- package/build/components/rotation-ruler/index.cjs +197 -0
- package/build/components/rotation-ruler/index.cjs.map +7 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
- package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
- package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +9 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +7 -13
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs +43 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +5 -1
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs.map +1 -1
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/core/viewport-state.cjs +50 -0
- package/build/image-editor/core/viewport-state.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +192 -72
- package/build/image-editor/react/components/cropper.cjs.map +3 -3
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/components/viewport-provider.cjs +51 -0
- package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
- package/build/image-editor/react/visually-hidden-style.cjs +41 -0
- package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
- package/build/private-apis.cjs +2 -0
- package/build/private-apis.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +545 -0
- package/build-module/components/media-editor/index.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +14 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +46 -455
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-toolbar/index.mjs +137 -77
- package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs +3 -0
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs +166 -0
- package/build-module/components/rotation-ruler/index.mjs.map +7 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +6 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +6 -12
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs +50 -8
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +5 -1
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/core/viewport-state.mjs +24 -0
- package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +195 -73
- package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
- package/build-module/private-apis.mjs +2 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-style/style-rtl.css +254 -29
- package/build-style/style.css +254 -29
- package/build-types/components/media-editor/index.d.ts +34 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +10 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +2 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +1 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/index.d.ts +46 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +9 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +11 -7
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +25 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/core/viewport-state.d.ts +7 -0
- package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +2 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -3
- package/build-types/store/actions.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/components/media-editor/index.tsx +709 -0
- package/src/components/media-editor/style.scss +89 -0
- package/src/components/media-editor-canvas/index.tsx +24 -0
- package/src/components/media-editor-crop-panel/index.tsx +39 -27
- package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
- package/src/components/media-editor-modal/index.tsx +49 -589
- package/src/components/media-editor-modal/style.scss +13 -112
- package/src/components/media-editor-toolbar/index.tsx +122 -63
- package/src/components/media-editor-toolbar/style.scss +39 -11
- package/src/components/media-form/index.tsx +5 -0
- package/src/components/rotation-ruler/README.md +37 -0
- package/src/components/rotation-ruler/index.tsx +266 -0
- package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
- package/src/components/rotation-ruler/style.scss +147 -0
- package/src/components/rotation-ruler/test/index.tsx +109 -0
- package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
- package/src/hooks/use-crop-gesture-handlers.ts +54 -0
- package/src/image-editor/core/constants.ts +12 -0
- package/src/image-editor/core/containment.ts +16 -28
- package/src/image-editor/core/interaction-controller.ts +66 -10
- package/src/image-editor/core/state.ts +15 -8
- package/src/image-editor/core/test/camera.ts +15 -26
- package/src/image-editor/core/test/interaction-controller.ts +158 -7
- package/src/image-editor/core/test/state.ts +21 -1
- package/src/image-editor/core/transform-style.ts +1 -1
- package/src/image-editor/core/types.ts +16 -0
- package/src/image-editor/core/viewport-state.ts +33 -0
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.scss +28 -0
- package/src/image-editor/react/components/cropper.tsx +268 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
- package/src/image-editor/react/components/test/cropper.tsx +294 -5
- package/src/image-editor/react/components/viewport-provider.tsx +39 -0
- package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
- package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
- package/src/image-editor/react/hooks/use-interaction.ts +36 -6
- package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
- package/src/image-editor/react/visually-hidden-style.ts +15 -0
- package/src/private-apis.ts +2 -0
- package/src/style.scss +3 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
+
@use "@wordpress/base-styles/mixins" as *;
|
|
3
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
4
|
+
|
|
5
|
+
.media-editor {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex: 1;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
height: 100%;
|
|
10
|
+
min-height: 0;
|
|
11
|
+
|
|
12
|
+
.media-editor__loading {
|
|
13
|
+
height: 100%;
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.interface-interface-skeleton {
|
|
20
|
+
position: relative;
|
|
21
|
+
top: auto;
|
|
22
|
+
right: auto;
|
|
23
|
+
bottom: auto;
|
|
24
|
+
left: auto;
|
|
25
|
+
height: 100%;
|
|
26
|
+
max-height: none;
|
|
27
|
+
flex: 1;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.interface-interface-skeleton__editor {
|
|
32
|
+
min-width: 0;
|
|
33
|
+
flex: 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.interface-interface-skeleton__footer {
|
|
37
|
+
position: relative;
|
|
38
|
+
display: flex;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.interface-interface-skeleton.has-footer .interface-interface-skeleton__body {
|
|
42
|
+
padding-bottom: 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.media-editor__canvas {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
background: $gray-100;
|
|
50
|
+
overflow: auto;
|
|
51
|
+
height: 100%;
|
|
52
|
+
|
|
53
|
+
.media-editor-preview {
|
|
54
|
+
height: 100%;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
img,
|
|
58
|
+
video {
|
|
59
|
+
max-width: 100%;
|
|
60
|
+
max-height: 100%;
|
|
61
|
+
object-fit: contain;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.media-editor__sidebar {
|
|
66
|
+
@include reset;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.media-editor__panel {
|
|
70
|
+
padding: $grid-unit-20;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.components-panel__header.media-editor__sidebar-header {
|
|
74
|
+
padding-left: 0;
|
|
75
|
+
padding-right: $grid-unit-10;
|
|
76
|
+
|
|
77
|
+
.components-button.has-icon {
|
|
78
|
+
padding: 0;
|
|
79
|
+
|
|
80
|
+
@include break-medium() {
|
|
81
|
+
display: flex;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.media-editor__snackbar {
|
|
88
|
+
@include snackbar-container();
|
|
89
|
+
}
|
|
@@ -10,8 +10,14 @@ export interface MediaEditorCanvasProps {
|
|
|
10
10
|
aspectRatio?: number;
|
|
11
11
|
/** Enable freeform crop mode (resize handles). */
|
|
12
12
|
freeformCrop?: boolean;
|
|
13
|
+
/** Focus the crop area when the canvas mounts. */
|
|
14
|
+
focusOnMount?: boolean;
|
|
13
15
|
/** Whether external placement activity should reveal the grid. */
|
|
14
16
|
isPlacementActive?: boolean;
|
|
17
|
+
/** Fires when a canvas cropper gesture begins. */
|
|
18
|
+
onGestureStart?: () => void;
|
|
19
|
+
/** Fires when a canvas cropper gesture ends. */
|
|
20
|
+
onGestureEnd?: () => void;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
@@ -24,12 +30,18 @@ export interface MediaEditorCanvasProps {
|
|
|
24
30
|
* @param props
|
|
25
31
|
* @param props.aspectRatio
|
|
26
32
|
* @param props.freeformCrop
|
|
33
|
+
* @param props.focusOnMount
|
|
27
34
|
* @param props.isPlacementActive
|
|
35
|
+
* @param props.onGestureStart
|
|
36
|
+
* @param props.onGestureEnd
|
|
28
37
|
*/
|
|
29
38
|
export default function MediaEditorCanvas( {
|
|
30
39
|
aspectRatio,
|
|
31
40
|
freeformCrop,
|
|
41
|
+
focusOnMount,
|
|
32
42
|
isPlacementActive = false,
|
|
43
|
+
onGestureStart,
|
|
44
|
+
onGestureEnd,
|
|
33
45
|
}: MediaEditorCanvasProps ) {
|
|
34
46
|
const { media } = useMediaEditorContext();
|
|
35
47
|
const controller = useCropper();
|
|
@@ -48,8 +60,20 @@ export default function MediaEditorCanvas( {
|
|
|
48
60
|
controller={ controller }
|
|
49
61
|
aspectRatio={ aspectRatio }
|
|
50
62
|
freeformCrop={ freeformCrop }
|
|
63
|
+
focusOnMount={ focusOnMount }
|
|
51
64
|
showGrid="interactive"
|
|
52
65
|
isPlacementActive={ isPlacementActive }
|
|
66
|
+
// Flush on gesture start so any pending sidebar interaction
|
|
67
|
+
// (e.g. zoom slider debounce) is committed as its own undo
|
|
68
|
+
// step before the canvas gesture begins.
|
|
69
|
+
onGestureStart={ () => {
|
|
70
|
+
onGestureStart?.();
|
|
71
|
+
controller.commitHistory();
|
|
72
|
+
} }
|
|
73
|
+
onGestureEnd={ () => {
|
|
74
|
+
controller.commitHistory();
|
|
75
|
+
onGestureEnd?.();
|
|
76
|
+
} }
|
|
53
77
|
/>
|
|
54
78
|
</div>
|
|
55
79
|
);
|
|
@@ -6,13 +6,14 @@ import {
|
|
|
6
6
|
SelectControl,
|
|
7
7
|
ToggleControl,
|
|
8
8
|
} from '@wordpress/components';
|
|
9
|
-
import { Stack } from '@wordpress/ui';
|
|
9
|
+
import { Stack, VisuallyHidden } from '@wordpress/ui';
|
|
10
10
|
import { __, sprintf } from '@wordpress/i18n';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
15
|
import { useCropper } from '../../image-editor';
|
|
16
|
+
import { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';
|
|
16
17
|
import {
|
|
17
18
|
DEFAULT_ASPECT_RATIOS,
|
|
18
19
|
MAX_ZOOM,
|
|
@@ -89,41 +90,30 @@ export default function MediaEditorCropPanel( {
|
|
|
89
90
|
aspectRatioPresets,
|
|
90
91
|
}: MediaEditorCropPanelProps ) {
|
|
91
92
|
const { state, setZoom } = useCropper();
|
|
93
|
+
const zoomGestureHandlers = useCropGestureHandlers();
|
|
92
94
|
const aspectRatioOptions = [
|
|
93
95
|
...DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value <= 0 ),
|
|
94
96
|
...( aspectRatioPresets ??
|
|
95
97
|
DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value > 0 ) ),
|
|
96
98
|
];
|
|
99
|
+
const handleAspectRatioChange = ( value: string ) => {
|
|
100
|
+
onAspectRatioChange( value );
|
|
101
|
+
if ( value === '0' && ! freeformCrop ) {
|
|
102
|
+
onFreeformChange( true );
|
|
103
|
+
}
|
|
104
|
+
};
|
|
97
105
|
|
|
98
106
|
return (
|
|
99
107
|
<Stack direction="column" gap="md">
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
label={ __( 'Zoom' ) }
|
|
104
|
-
min={ MIN_ZOOM }
|
|
105
|
-
max={ MAX_ZOOM }
|
|
106
|
-
step={ 0.1 }
|
|
107
|
-
value={ state.zoom }
|
|
108
|
-
onChange={ ( value ) => {
|
|
109
|
-
onPlacementControlInteraction?.();
|
|
110
|
-
setZoom( typeof value === 'number' ? value : MIN_ZOOM );
|
|
111
|
-
} }
|
|
112
|
-
renderTooltipContent={ ( value ) => {
|
|
113
|
-
const zoom = typeof value === 'number' ? value : MIN_ZOOM;
|
|
114
|
-
return sprintf(
|
|
115
|
-
/* translators: %d: zoom level as a percentage. */
|
|
116
|
-
__( '%d%%' ),
|
|
117
|
-
Math.round( zoom * 100 )
|
|
118
|
-
);
|
|
119
|
-
} }
|
|
120
|
-
/>
|
|
108
|
+
<VisuallyHidden render={ <h2 /> }>
|
|
109
|
+
{ __( 'Crop options' ) }
|
|
110
|
+
</VisuallyHidden>
|
|
121
111
|
<SelectControl
|
|
122
112
|
__next40pxDefaultSize
|
|
123
113
|
__nextHasNoMarginBottom
|
|
124
114
|
label={ __( 'Aspect ratio' ) }
|
|
125
115
|
value={ aspectRatioValue }
|
|
126
|
-
onChange={
|
|
116
|
+
onChange={ handleAspectRatioChange }
|
|
127
117
|
options={ aspectRatioOptions.map( ( preset ) => ( {
|
|
128
118
|
label: preset.label,
|
|
129
119
|
value: preset.value.toString(),
|
|
@@ -131,13 +121,35 @@ export default function MediaEditorCropPanel( {
|
|
|
131
121
|
/>
|
|
132
122
|
<ToggleControl
|
|
133
123
|
__nextHasNoMarginBottom
|
|
134
|
-
label={ __( '
|
|
135
|
-
help={ __(
|
|
136
|
-
'Drag the crop edges to resize freely. When off, the crop is fixed to the selected ratio.'
|
|
137
|
-
) }
|
|
124
|
+
label={ __( 'Resize crop area' ) }
|
|
125
|
+
help={ __( 'Show handles to adjust the crop box.' ) }
|
|
138
126
|
checked={ freeformCrop }
|
|
139
127
|
onChange={ onFreeformChange }
|
|
140
128
|
/>
|
|
129
|
+
<div role="presentation" { ...zoomGestureHandlers }>
|
|
130
|
+
<RangeControl
|
|
131
|
+
__next40pxDefaultSize
|
|
132
|
+
__nextHasNoMarginBottom
|
|
133
|
+
label={ __( 'Zoom' ) }
|
|
134
|
+
min={ MIN_ZOOM }
|
|
135
|
+
max={ MAX_ZOOM }
|
|
136
|
+
step={ 0.1 }
|
|
137
|
+
value={ state.zoom }
|
|
138
|
+
onChange={ ( value ) => {
|
|
139
|
+
onPlacementControlInteraction?.();
|
|
140
|
+
setZoom( typeof value === 'number' ? value : MIN_ZOOM );
|
|
141
|
+
} }
|
|
142
|
+
renderTooltipContent={ ( value ) => {
|
|
143
|
+
const zoom =
|
|
144
|
+
typeof value === 'number' ? value : MIN_ZOOM;
|
|
145
|
+
return sprintf(
|
|
146
|
+
/* translators: %d: zoom level as a percentage. */
|
|
147
|
+
__( '%d%%' ),
|
|
148
|
+
Math.round( zoom * 100 )
|
|
149
|
+
);
|
|
150
|
+
} }
|
|
151
|
+
/>
|
|
152
|
+
</div>
|
|
141
153
|
</Stack>
|
|
142
154
|
);
|
|
143
155
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import MediaEditorCropPanel from '..';
|
|
10
|
+
import type { MediaEditorCropPanelProps } from '..';
|
|
11
|
+
import { CropperProvider } from '../../../image-editor';
|
|
12
|
+
|
|
13
|
+
function setupCropPanel(
|
|
14
|
+
overrides: Partial< MediaEditorCropPanelProps > = {}
|
|
15
|
+
) {
|
|
16
|
+
const props: MediaEditorCropPanelProps = {
|
|
17
|
+
aspectRatioValue: '1',
|
|
18
|
+
onAspectRatioChange: jest.fn(),
|
|
19
|
+
freeformCrop: false,
|
|
20
|
+
onFreeformChange: jest.fn(),
|
|
21
|
+
...overrides,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
render(
|
|
25
|
+
<CropperProvider>
|
|
26
|
+
<MediaEditorCropPanel { ...props } />
|
|
27
|
+
</CropperProvider>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return props;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function expectElementBefore( first: HTMLElement, second: HTMLElement ) {
|
|
34
|
+
expect( first.compareDocumentPosition( second ) ).toBe(
|
|
35
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe( 'MediaEditorCropPanel', () => {
|
|
40
|
+
it( 'renders crop shape controls before zoom controls', () => {
|
|
41
|
+
setupCropPanel();
|
|
42
|
+
|
|
43
|
+
const aspectRatio = screen.getByLabelText( 'Aspect ratio' );
|
|
44
|
+
const resizeCropArea = screen.getByLabelText( 'Resize crop area' );
|
|
45
|
+
const zoom = screen.getByRole( 'slider', { name: 'Zoom' } );
|
|
46
|
+
|
|
47
|
+
expect(
|
|
48
|
+
screen.getByText( 'Show handles to adjust the crop box.' )
|
|
49
|
+
).toBeInTheDocument();
|
|
50
|
+
expectElementBefore( aspectRatio, resizeCropArea );
|
|
51
|
+
expectElementBefore( resizeCropArea, zoom );
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
it( 'turns freeform crop on when Free is selected while handles are off', () => {
|
|
55
|
+
const controls = setupCropPanel( {
|
|
56
|
+
aspectRatioValue: '1',
|
|
57
|
+
freeformCrop: false,
|
|
58
|
+
} );
|
|
59
|
+
|
|
60
|
+
fireEvent.change( screen.getByLabelText( 'Aspect ratio' ), {
|
|
61
|
+
target: { value: '0' },
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
expect( controls.onAspectRatioChange ).toHaveBeenCalledWith( '0' );
|
|
65
|
+
expect( controls.onFreeformChange ).toHaveBeenCalledWith( true );
|
|
66
|
+
} );
|
|
67
|
+
|
|
68
|
+
it( 'does not change freeform crop when a fixed ratio is selected', () => {
|
|
69
|
+
const controls = setupCropPanel( {
|
|
70
|
+
aspectRatioValue: '0',
|
|
71
|
+
freeformCrop: false,
|
|
72
|
+
} );
|
|
73
|
+
|
|
74
|
+
fireEvent.change( screen.getByLabelText( 'Aspect ratio' ), {
|
|
75
|
+
target: { value: '1' },
|
|
76
|
+
} );
|
|
77
|
+
|
|
78
|
+
expect( controls.onAspectRatioChange ).toHaveBeenCalledWith( '1' );
|
|
79
|
+
expect( controls.onFreeformChange ).not.toHaveBeenCalled();
|
|
80
|
+
} );
|
|
81
|
+
|
|
82
|
+
it( 'does not call onFreeformChange when Free is selected and handles are already on', () => {
|
|
83
|
+
const controls = setupCropPanel( {
|
|
84
|
+
aspectRatioValue: '1',
|
|
85
|
+
freeformCrop: true,
|
|
86
|
+
} );
|
|
87
|
+
|
|
88
|
+
fireEvent.change( screen.getByLabelText( 'Aspect ratio' ), {
|
|
89
|
+
target: { value: '0' },
|
|
90
|
+
} );
|
|
91
|
+
|
|
92
|
+
expect( controls.onAspectRatioChange ).toHaveBeenCalledWith( '0' );
|
|
93
|
+
expect( controls.onFreeformChange ).not.toHaveBeenCalled();
|
|
94
|
+
} );
|
|
95
|
+
|
|
96
|
+
it( 'does not call onFreeformChange when a fixed ratio is selected and handles are on', () => {
|
|
97
|
+
const controls = setupCropPanel( {
|
|
98
|
+
aspectRatioValue: '0',
|
|
99
|
+
freeformCrop: true,
|
|
100
|
+
} );
|
|
101
|
+
|
|
102
|
+
fireEvent.change( screen.getByLabelText( 'Aspect ratio' ), {
|
|
103
|
+
target: { value: '1' },
|
|
104
|
+
} );
|
|
105
|
+
|
|
106
|
+
expect( controls.onAspectRatioChange ).toHaveBeenCalledWith( '1' );
|
|
107
|
+
expect( controls.onFreeformChange ).not.toHaveBeenCalled();
|
|
108
|
+
} );
|
|
109
|
+
} );
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Modal } from '@wordpress/components';
|
|
5
|
+
import { Fragment } from '@wordpress/element';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import {
|
|
8
|
+
displayShortcutList,
|
|
9
|
+
shortcutAriaLabel,
|
|
10
|
+
type WPKeycodeModifier,
|
|
11
|
+
} from '@wordpress/keycodes';
|
|
12
|
+
|
|
13
|
+
interface KeyCombination {
|
|
14
|
+
/** Modifier for cross-platform display (e.g. 'primary', 'primaryShift', 'shift'). */
|
|
15
|
+
modifier?: WPKeycodeModifier;
|
|
16
|
+
/** The key character(s) to display. Pass an array to render each as its own key. */
|
|
17
|
+
character: string | string[];
|
|
18
|
+
/** Optional aria-label override (used when character is a symbol). */
|
|
19
|
+
ariaLabel?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ShortcutEntry {
|
|
23
|
+
description: string;
|
|
24
|
+
keyCombination: KeyCombination;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SHORTCUTS: ShortcutEntry[] = [
|
|
28
|
+
{
|
|
29
|
+
description: __( 'Undo' ),
|
|
30
|
+
keyCombination: { modifier: 'primary', character: 'z' },
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: __( 'Redo' ),
|
|
34
|
+
keyCombination: { modifier: 'primaryShift', character: 'z' },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
description: __( 'Pan' ),
|
|
38
|
+
keyCombination: {
|
|
39
|
+
character: [ '↑', '↓', '←', '→' ],
|
|
40
|
+
ariaLabel: __( 'Arrow keys' ),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
description: __( 'Zoom in' ),
|
|
45
|
+
keyCombination: { character: '+' },
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
description: __( 'Zoom out' ),
|
|
49
|
+
keyCombination: { character: '-' },
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
description: __( 'Rotate 90° clockwise' ),
|
|
53
|
+
keyCombination: { character: 'R' },
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
description: __( 'Rotate 90° counter-clockwise' ),
|
|
57
|
+
keyCombination: { modifier: 'shift', character: 'R' },
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
description: __( 'Flip horizontal' ),
|
|
61
|
+
keyCombination: { character: 'H' },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
description: __( 'Flip vertical' ),
|
|
65
|
+
keyCombination: { character: 'V' },
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
description: __( 'Pan or resize crop (large step)' ),
|
|
69
|
+
keyCombination: {
|
|
70
|
+
modifier: 'shift',
|
|
71
|
+
character: [ '↑', '↓', '←', '→' ],
|
|
72
|
+
ariaLabel: __( 'Shift + Arrow keys' ),
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
function KeyCombinationDisplay( {
|
|
78
|
+
keyCombination,
|
|
79
|
+
}: {
|
|
80
|
+
keyCombination: KeyCombination;
|
|
81
|
+
} ) {
|
|
82
|
+
const { modifier, character, ariaLabel } = keyCombination;
|
|
83
|
+
|
|
84
|
+
let keys: string[];
|
|
85
|
+
if ( Array.isArray( character ) ) {
|
|
86
|
+
if ( modifier ) {
|
|
87
|
+
// Get the modifier prefix (e.g. ['⇧', '+']) from the first char,
|
|
88
|
+
// then replace the last element with all the individual chars.
|
|
89
|
+
const sample = displayShortcutList[ modifier ]( character[ 0 ] );
|
|
90
|
+
keys = [ ...sample.slice( 0, -1 ), ...character ];
|
|
91
|
+
} else {
|
|
92
|
+
keys = character;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
keys = modifier
|
|
96
|
+
? displayShortcutList[ modifier ]( character )
|
|
97
|
+
: [ character ];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const charString = Array.isArray( character )
|
|
101
|
+
? character.join( '' )
|
|
102
|
+
: character;
|
|
103
|
+
let label: string;
|
|
104
|
+
if ( ariaLabel ) {
|
|
105
|
+
label = ariaLabel;
|
|
106
|
+
} else if ( modifier ) {
|
|
107
|
+
label = shortcutAriaLabel[ modifier ]( charString );
|
|
108
|
+
} else {
|
|
109
|
+
label = charString;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<kbd
|
|
114
|
+
className="media-editor-keyboard-shortcuts-modal__shortcut-term"
|
|
115
|
+
aria-label={ label }
|
|
116
|
+
>
|
|
117
|
+
{ keys.map( ( key, index ) =>
|
|
118
|
+
key === '+' && modifier ? (
|
|
119
|
+
<Fragment key={ index }>{ key }</Fragment>
|
|
120
|
+
) : (
|
|
121
|
+
<kbd
|
|
122
|
+
key={ index }
|
|
123
|
+
className="media-editor-keyboard-shortcuts-modal__shortcut-key"
|
|
124
|
+
>
|
|
125
|
+
{ key }
|
|
126
|
+
</kbd>
|
|
127
|
+
)
|
|
128
|
+
) }
|
|
129
|
+
</kbd>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface MediaEditorKeyboardShortcutsModalProps {
|
|
134
|
+
onClose: () => void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default function MediaEditorKeyboardShortcutsModal( {
|
|
138
|
+
onClose,
|
|
139
|
+
}: MediaEditorKeyboardShortcutsModalProps ) {
|
|
140
|
+
return (
|
|
141
|
+
<Modal
|
|
142
|
+
className="media-editor-keyboard-shortcuts-modal"
|
|
143
|
+
title={ __( 'Keyboard shortcuts' ) }
|
|
144
|
+
onRequestClose={ onClose }
|
|
145
|
+
>
|
|
146
|
+
<p className="media-editor-keyboard-shortcuts-modal__note">
|
|
147
|
+
{ __(
|
|
148
|
+
'These shortcuts work when the image editor has focus.'
|
|
149
|
+
) }
|
|
150
|
+
</p>
|
|
151
|
+
{ /*
|
|
152
|
+
* Disable reason: The `list` ARIA role is redundant but
|
|
153
|
+
* Safari+VoiceOver won't announce the list otherwise.
|
|
154
|
+
*/ }
|
|
155
|
+
{ /* eslint-disable jsx-a11y/no-redundant-roles */ }
|
|
156
|
+
<ul
|
|
157
|
+
className="media-editor-keyboard-shortcuts-modal__shortcut-list"
|
|
158
|
+
role="list"
|
|
159
|
+
>
|
|
160
|
+
{ SHORTCUTS.map( ( { description, keyCombination }, index ) => (
|
|
161
|
+
<li
|
|
162
|
+
key={ index }
|
|
163
|
+
className="media-editor-keyboard-shortcuts-modal__shortcut"
|
|
164
|
+
>
|
|
165
|
+
<span className="media-editor-keyboard-shortcuts-modal__shortcut-description">
|
|
166
|
+
{ description }
|
|
167
|
+
</span>
|
|
168
|
+
<KeyCombinationDisplay
|
|
169
|
+
keyCombination={ keyCombination }
|
|
170
|
+
/>
|
|
171
|
+
</li>
|
|
172
|
+
) ) }
|
|
173
|
+
</ul>
|
|
174
|
+
{ /* eslint-enable jsx-a11y/no-redundant-roles */ }
|
|
175
|
+
</Modal>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
3
|
+
|
|
4
|
+
.media-editor-keyboard-shortcuts-modal {
|
|
5
|
+
min-width: 280px;
|
|
6
|
+
|
|
7
|
+
.media-editor-keyboard-shortcuts-modal__note {
|
|
8
|
+
margin: 0 0 $grid-unit-20;
|
|
9
|
+
color: $gray-700;
|
|
10
|
+
font-size: 13px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.media-editor-keyboard-shortcuts-modal__shortcut-list {
|
|
14
|
+
list-style: none;
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.media-editor-keyboard-shortcuts-modal__shortcut {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: baseline;
|
|
22
|
+
padding: 0.6rem 0;
|
|
23
|
+
border-top: 1px solid $gray-300;
|
|
24
|
+
margin-bottom: 0;
|
|
25
|
+
|
|
26
|
+
&:last-child {
|
|
27
|
+
border-bottom: 1px solid $gray-300;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.media-editor-keyboard-shortcuts-modal__shortcut-description {
|
|
32
|
+
flex: 1;
|
|
33
|
+
margin: 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.media-editor-keyboard-shortcuts-modal__shortcut-term {
|
|
37
|
+
background: none;
|
|
38
|
+
font-weight: 600;
|
|
39
|
+
margin: 0 0 0 1rem;
|
|
40
|
+
padding: 0;
|
|
41
|
+
text-align: right;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.media-editor-keyboard-shortcuts-modal__shortcut-key {
|
|
45
|
+
padding: 0.25rem 0.5rem;
|
|
46
|
+
border-radius: 8%;
|
|
47
|
+
margin: 0 0.2rem 0 0.2rem;
|
|
48
|
+
|
|
49
|
+
&:last-child {
|
|
50
|
+
margin: 0 0 0 0.2rem;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|