@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
|
@@ -98,6 +98,15 @@ describe( 'RectangleStencil', () => {
|
|
|
98
98
|
] );
|
|
99
99
|
} );
|
|
100
100
|
|
|
101
|
+
it( 'describes keyboard resizing on resize handles', () => {
|
|
102
|
+
renderStencil();
|
|
103
|
+
expect(
|
|
104
|
+
screen.getByRole( 'button', { name: 'Resize top-left corner' } )
|
|
105
|
+
).toHaveAccessibleDescription(
|
|
106
|
+
'Use arrow keys to resize the crop area. Hold Shift for larger steps.'
|
|
107
|
+
);
|
|
108
|
+
} );
|
|
109
|
+
|
|
101
110
|
it( 'renders corner handles clockwise from top-left when aspect ratio is locked', () => {
|
|
102
111
|
renderStencil( { aspectRatio: 16 / 9 } );
|
|
103
112
|
const labels = screen
|
|
@@ -114,21 +123,38 @@ describe( 'RectangleStencil', () => {
|
|
|
114
123
|
} );
|
|
115
124
|
|
|
116
125
|
describe( 'keyboard — Escape', () => {
|
|
117
|
-
it( '
|
|
118
|
-
const
|
|
126
|
+
it( 'handles Escape on a handle without bubbling', () => {
|
|
127
|
+
const onKeyDown = jest.fn();
|
|
128
|
+
const onEscape = jest.fn();
|
|
129
|
+
render(
|
|
130
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
131
|
+
<div onKeyDown={ onKeyDown }>
|
|
132
|
+
<RectangleStencil
|
|
133
|
+
cropRect={ DEFAULT_CROP_RECT }
|
|
134
|
+
containerSize={ CONTAINER_SIZE }
|
|
135
|
+
imageSize={ IMAGE_SIZE }
|
|
136
|
+
onCropChange={ jest.fn() }
|
|
137
|
+
onEscape={ onEscape }
|
|
138
|
+
freeformCrop
|
|
139
|
+
cropBounds={ CROP_BOUNDS }
|
|
140
|
+
/>
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
119
143
|
const [ firstHandle ] = screen.getAllByRole( 'button' );
|
|
120
144
|
|
|
121
145
|
fireEvent.keyDown( firstHandle, { key: 'Escape' } );
|
|
122
146
|
|
|
123
147
|
expect( onEscape ).toHaveBeenCalledTimes( 1 );
|
|
148
|
+
expect( onKeyDown ).not.toHaveBeenCalled();
|
|
124
149
|
} );
|
|
125
150
|
|
|
126
151
|
it( 'does not call onCropChange when Escape is pressed', () => {
|
|
127
|
-
const { onCropChange } = renderStencil();
|
|
152
|
+
const { onCropChange, onEscape } = renderStencil();
|
|
128
153
|
const [ firstHandle ] = screen.getAllByRole( 'button' );
|
|
129
154
|
|
|
130
155
|
fireEvent.keyDown( firstHandle, { key: 'Escape' } );
|
|
131
156
|
|
|
157
|
+
expect( onEscape ).toHaveBeenCalledTimes( 1 );
|
|
132
158
|
expect( onCropChange ).not.toHaveBeenCalled();
|
|
133
159
|
} );
|
|
134
160
|
} );
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
act,
|
|
6
|
+
fireEvent,
|
|
7
|
+
render,
|
|
8
|
+
screen,
|
|
9
|
+
waitFor,
|
|
10
|
+
} from '@testing-library/react';
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* Internal dependencies
|
|
@@ -37,14 +43,37 @@ function createController(): UseCropperStateReturn {
|
|
|
37
43
|
applyOperation: jest.fn(),
|
|
38
44
|
reset: jest.fn(),
|
|
39
45
|
isDirty: false,
|
|
46
|
+
hasUndo: false,
|
|
47
|
+
hasRedo: false,
|
|
48
|
+
undo: jest.fn(),
|
|
49
|
+
redo: jest.fn(),
|
|
50
|
+
commitHistory: jest.fn(),
|
|
40
51
|
getCroppedImage: jest.fn(),
|
|
41
52
|
};
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
describe( 'Cropper
|
|
55
|
+
describe( 'Cropper', () => {
|
|
45
56
|
const originalResizeObserver = globalThis.ResizeObserver;
|
|
46
57
|
|
|
47
58
|
beforeAll( () => {
|
|
59
|
+
if ( ! HTMLElement.prototype.setPointerCapture ) {
|
|
60
|
+
HTMLElement.prototype.setPointerCapture = jest.fn();
|
|
61
|
+
}
|
|
62
|
+
if ( ! HTMLElement.prototype.releasePointerCapture ) {
|
|
63
|
+
HTMLElement.prototype.releasePointerCapture = jest.fn();
|
|
64
|
+
}
|
|
65
|
+
if ( typeof ( globalThis as any ).PointerEvent === 'undefined' ) {
|
|
66
|
+
( globalThis as any ).PointerEvent = class PointerEvent extends (
|
|
67
|
+
MouseEvent
|
|
68
|
+
) {
|
|
69
|
+
pointerId: number;
|
|
70
|
+
constructor( type: string, init: PointerEventInit = {} ) {
|
|
71
|
+
super( type, init );
|
|
72
|
+
this.pointerId = init.pointerId ?? 0;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
48
77
|
globalThis.ResizeObserver = class ResizeObserver {
|
|
49
78
|
private callback: ResizeObserverCallback;
|
|
50
79
|
|
|
@@ -98,11 +127,79 @@ describe( 'Cropper grid visibility classes', () => {
|
|
|
98
127
|
|
|
99
128
|
await screen.findByTestId( GRID_TEST_ID );
|
|
100
129
|
|
|
101
|
-
const canvas = screen.getByRole( 'group', { name: '
|
|
130
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
102
131
|
expect( canvas ).not.toHaveClass( GRID_INTERACTIVE_CLASS );
|
|
103
132
|
expect( canvas ).not.toHaveClass( SHOW_GRID_CLASS );
|
|
104
133
|
} );
|
|
105
134
|
|
|
135
|
+
it( 'describes and focuses the crop area when requested', () => {
|
|
136
|
+
render(
|
|
137
|
+
<Cropper
|
|
138
|
+
src="test.jpg"
|
|
139
|
+
controller={ createController() }
|
|
140
|
+
showDimming={ false }
|
|
141
|
+
focusOnMount
|
|
142
|
+
/>
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
146
|
+
expect( canvas ).toHaveAccessibleDescription(
|
|
147
|
+
'When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.'
|
|
148
|
+
);
|
|
149
|
+
expect( canvas ).toHaveFocus();
|
|
150
|
+
} );
|
|
151
|
+
|
|
152
|
+
it( 'does not expose crop area keyboard hints while resize handles are focused', async () => {
|
|
153
|
+
render(
|
|
154
|
+
<Cropper
|
|
155
|
+
src="test.jpg"
|
|
156
|
+
controller={ createController() }
|
|
157
|
+
showDimming={ false }
|
|
158
|
+
freeformCrop
|
|
159
|
+
focusOnMount
|
|
160
|
+
/>
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
164
|
+
const handle = await screen.findByRole( 'button', {
|
|
165
|
+
name: 'Resize top-left corner',
|
|
166
|
+
} );
|
|
167
|
+
|
|
168
|
+
fireEvent.blur( canvas, { relatedTarget: handle } );
|
|
169
|
+
fireEvent.focus( handle );
|
|
170
|
+
|
|
171
|
+
expect( canvas ).not.toHaveAccessibleDescription(
|
|
172
|
+
'When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.'
|
|
173
|
+
);
|
|
174
|
+
expect( handle ).toHaveAccessibleDescription(
|
|
175
|
+
'Use arrow keys to resize the crop area. Hold Shift for larger steps.'
|
|
176
|
+
);
|
|
177
|
+
} );
|
|
178
|
+
|
|
179
|
+
it( 'returns focus to the crop area on Escape from a resize handle', async () => {
|
|
180
|
+
render(
|
|
181
|
+
<Cropper
|
|
182
|
+
src="test.jpg"
|
|
183
|
+
controller={ createController() }
|
|
184
|
+
showDimming={ false }
|
|
185
|
+
freeformCrop
|
|
186
|
+
focusOnMount
|
|
187
|
+
/>
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
191
|
+
const handle = await screen.findByRole( 'button', {
|
|
192
|
+
name: 'Resize top-left corner',
|
|
193
|
+
} );
|
|
194
|
+
|
|
195
|
+
act( () => {
|
|
196
|
+
handle.focus();
|
|
197
|
+
} );
|
|
198
|
+
fireEvent.keyDown( handle, { key: 'Escape' } );
|
|
199
|
+
|
|
200
|
+
expect( canvas ).toHaveFocus();
|
|
201
|
+
} );
|
|
202
|
+
|
|
106
203
|
it( 'renders the grid hidden by default in interactive mode', async () => {
|
|
107
204
|
render(
|
|
108
205
|
<Cropper
|
|
@@ -115,7 +212,7 @@ describe( 'Cropper grid visibility classes', () => {
|
|
|
115
212
|
|
|
116
213
|
await screen.findByTestId( GRID_TEST_ID );
|
|
117
214
|
|
|
118
|
-
const canvas = screen.getByRole( 'group', { name: '
|
|
215
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
119
216
|
expect( canvas ).toHaveClass( GRID_INTERACTIVE_CLASS );
|
|
120
217
|
expect( canvas ).not.toHaveClass( SHOW_GRID_CLASS );
|
|
121
218
|
} );
|
|
@@ -133,8 +230,200 @@ describe( 'Cropper grid visibility classes', () => {
|
|
|
133
230
|
|
|
134
231
|
await screen.findByTestId( GRID_TEST_ID );
|
|
135
232
|
|
|
136
|
-
const canvas = screen.getByRole( 'group', { name: '
|
|
233
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
137
234
|
expect( canvas ).toHaveClass( GRID_INTERACTIVE_CLASS );
|
|
138
235
|
expect( canvas ).toHaveClass( SHOW_GRID_CLASS );
|
|
139
236
|
} );
|
|
237
|
+
|
|
238
|
+
it( 'preserves a free crop when freeform handles are toggled off', async () => {
|
|
239
|
+
const controller = createController();
|
|
240
|
+
controller.state = {
|
|
241
|
+
...controller.state,
|
|
242
|
+
cropRect: { x: 0.1, y: 0.2, width: 0.5, height: 0.4 },
|
|
243
|
+
};
|
|
244
|
+
const { rerender } = render(
|
|
245
|
+
<Cropper
|
|
246
|
+
src="test.jpg"
|
|
247
|
+
controller={ controller }
|
|
248
|
+
showDimming={ false }
|
|
249
|
+
freeformCrop
|
|
250
|
+
/>
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
await screen.findByRole( 'button', {
|
|
254
|
+
name: 'Resize top-left corner',
|
|
255
|
+
} );
|
|
256
|
+
( controller.setCropRect as jest.Mock ).mockClear();
|
|
257
|
+
|
|
258
|
+
rerender(
|
|
259
|
+
<Cropper
|
|
260
|
+
src="test.jpg"
|
|
261
|
+
controller={ controller }
|
|
262
|
+
showDimming={ false }
|
|
263
|
+
freeformCrop={ false }
|
|
264
|
+
/>
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
expect(
|
|
268
|
+
screen.queryByRole( 'button', {
|
|
269
|
+
name: 'Resize top-left corner',
|
|
270
|
+
} )
|
|
271
|
+
).not.toBeInTheDocument();
|
|
272
|
+
expect( controller.setCropRect ).not.toHaveBeenCalled();
|
|
273
|
+
} );
|
|
274
|
+
|
|
275
|
+
it( 'centers a fixed-ratio crop when freeform handles are off', async () => {
|
|
276
|
+
const controller = createController();
|
|
277
|
+
controller.state = {
|
|
278
|
+
...controller.state,
|
|
279
|
+
cropRect: { x: 0.1, y: 0.2, width: 0.5, height: 0.4 },
|
|
280
|
+
};
|
|
281
|
+
render(
|
|
282
|
+
<Cropper
|
|
283
|
+
src="test.jpg"
|
|
284
|
+
controller={ controller }
|
|
285
|
+
showDimming={ false }
|
|
286
|
+
freeformCrop={ false }
|
|
287
|
+
aspectRatio={ 1 }
|
|
288
|
+
/>
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
await waitFor( () =>
|
|
292
|
+
expect( controller.setCropRect ).toHaveBeenCalledWith( {
|
|
293
|
+
x: expect.closeTo( 1 / 6, 5 ),
|
|
294
|
+
y: 0,
|
|
295
|
+
width: expect.closeTo( 2 / 3, 5 ),
|
|
296
|
+
height: 1,
|
|
297
|
+
} )
|
|
298
|
+
);
|
|
299
|
+
} );
|
|
300
|
+
|
|
301
|
+
it( 'clears settling state when a new resize starts before the settle timer fires', async () => {
|
|
302
|
+
jest.useFakeTimers();
|
|
303
|
+
|
|
304
|
+
render(
|
|
305
|
+
<Cropper
|
|
306
|
+
src="test.jpg"
|
|
307
|
+
controller={ createController() }
|
|
308
|
+
showDimming={ false }
|
|
309
|
+
freeformCrop
|
|
310
|
+
/>
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const handle = await screen.findByRole( 'button', {
|
|
314
|
+
name: 'Resize top-left corner',
|
|
315
|
+
} );
|
|
316
|
+
// The settle transition and viewport pan live on the stage, not the
|
|
317
|
+
// canvas (which stays fixed so the root background is never exposed).
|
|
318
|
+
const stage = screen.getByTestId( 'cropper-stage' );
|
|
319
|
+
|
|
320
|
+
// Start and end a resize to trigger the settle animation.
|
|
321
|
+
fireEvent.pointerDown( handle, {
|
|
322
|
+
button: 0,
|
|
323
|
+
clientX: 100,
|
|
324
|
+
clientY: 100,
|
|
325
|
+
pointerId: 1,
|
|
326
|
+
} );
|
|
327
|
+
fireEvent.pointerUp( handle, { pointerId: 1 } );
|
|
328
|
+
|
|
329
|
+
// The settle transition should now be active on the stage.
|
|
330
|
+
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
331
|
+
|
|
332
|
+
// Start a new resize before the 200 ms settle timer fires.
|
|
333
|
+
fireEvent.pointerDown( handle, {
|
|
334
|
+
button: 0,
|
|
335
|
+
clientX: 100,
|
|
336
|
+
clientY: 100,
|
|
337
|
+
pointerId: 1,
|
|
338
|
+
} );
|
|
339
|
+
|
|
340
|
+
// Settling must be cleared — no transition on the drag.
|
|
341
|
+
expect( stage ).not.toHaveStyle(
|
|
342
|
+
'transition: transform 200ms ease-out'
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
// Advance past the old settle timer; it was cancelled so the stage
|
|
346
|
+
// should still have no transition.
|
|
347
|
+
act( () => jest.advanceTimersByTime( 200 ) );
|
|
348
|
+
expect( stage ).not.toHaveStyle(
|
|
349
|
+
'transition: transform 200ms ease-out'
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
fireEvent.pointerUp( handle, { pointerId: 1 } );
|
|
353
|
+
|
|
354
|
+
jest.useRealTimers();
|
|
355
|
+
} );
|
|
356
|
+
|
|
357
|
+
it( 'pans the canvas when a keyboard resize extends the crop past the canvas edge', async () => {
|
|
358
|
+
jest.useFakeTimers();
|
|
359
|
+
|
|
360
|
+
// zoom: 2 so the image bounds extend past [0, 1] in normalized space,
|
|
361
|
+
// allowing the crop to be resized beyond the canvas edge.
|
|
362
|
+
const controller = createController();
|
|
363
|
+
controller.state = { ...controller.state, zoom: 2 };
|
|
364
|
+
|
|
365
|
+
render(
|
|
366
|
+
<Cropper
|
|
367
|
+
src="test.jpg"
|
|
368
|
+
controller={ controller }
|
|
369
|
+
showDimming={ false }
|
|
370
|
+
freeformCrop
|
|
371
|
+
/>
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
// East handle (4th button clockwise: nw, n, ne, e).
|
|
375
|
+
const eHandle = await screen.findByRole( 'button', {
|
|
376
|
+
name: 'Resize right edge',
|
|
377
|
+
} );
|
|
378
|
+
const stage = screen.getByTestId( 'cropper-stage' );
|
|
379
|
+
|
|
380
|
+
// cropRect starts at {x:0, y:0, width:1, height:1} (right edge = 1.0).
|
|
381
|
+
// One ArrowRight step (+0.01 normalized) puts the right edge at 1.01.
|
|
382
|
+
// With canvasSize=600×400 and visualSize=600×400:
|
|
383
|
+
// rightOverflow = 1.01 * 600 − 600 = 6 → pan.x = −6
|
|
384
|
+
fireEvent.keyDown( eHandle, { key: 'ArrowRight' } );
|
|
385
|
+
|
|
386
|
+
expect( stage ).toHaveStyle( 'transform: translate(-6px, 0px)' );
|
|
387
|
+
|
|
388
|
+
jest.useRealTimers();
|
|
389
|
+
} );
|
|
390
|
+
|
|
391
|
+
it( 'ignores wheel zoom while a crop resize is active', async () => {
|
|
392
|
+
const controller = createController();
|
|
393
|
+
render(
|
|
394
|
+
<Cropper
|
|
395
|
+
src="test.jpg"
|
|
396
|
+
controller={ controller }
|
|
397
|
+
showDimming={ false }
|
|
398
|
+
freeformCrop
|
|
399
|
+
/>
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
const resizeHandle = await screen.findByRole( 'button', {
|
|
403
|
+
name: 'Resize top-left corner',
|
|
404
|
+
} );
|
|
405
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
406
|
+
|
|
407
|
+
fireEvent.pointerDown( resizeHandle, {
|
|
408
|
+
button: 0,
|
|
409
|
+
clientX: 100,
|
|
410
|
+
clientY: 100,
|
|
411
|
+
pointerId: 1,
|
|
412
|
+
} );
|
|
413
|
+
|
|
414
|
+
const wheelEvent = new WheelEvent( 'wheel', {
|
|
415
|
+
bubbles: true,
|
|
416
|
+
cancelable: true,
|
|
417
|
+
clientX: 300,
|
|
418
|
+
clientY: 200,
|
|
419
|
+
deltaY: -100,
|
|
420
|
+
} );
|
|
421
|
+
fireEvent( canvas, wheelEvent );
|
|
422
|
+
|
|
423
|
+
expect( wheelEvent.defaultPrevented ).toBe( true );
|
|
424
|
+
expect( controller.setZoom ).not.toHaveBeenCalled();
|
|
425
|
+
expect( controller.setZoomAtPoint ).not.toHaveBeenCalled();
|
|
426
|
+
|
|
427
|
+
fireEvent.pointerUp( resizeHandle, { pointerId: 1 } );
|
|
428
|
+
} );
|
|
140
429
|
} );
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createContext, useContext } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
useViewportState,
|
|
11
|
+
type UseViewportStateReturn,
|
|
12
|
+
} from '../hooks/use-viewport-state';
|
|
13
|
+
|
|
14
|
+
type ViewportContextValue = UseViewportStateReturn;
|
|
15
|
+
|
|
16
|
+
const ViewportContext = createContext< ViewportContextValue | null >( null );
|
|
17
|
+
|
|
18
|
+
export function ViewportProvider( {
|
|
19
|
+
children,
|
|
20
|
+
}: {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
} ) {
|
|
23
|
+
const viewportState = useViewportState();
|
|
24
|
+
return (
|
|
25
|
+
<ViewportContext.Provider value={ viewportState }>
|
|
26
|
+
{ children }
|
|
27
|
+
</ViewportContext.Provider>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useViewport(): UseViewportStateReturn {
|
|
32
|
+
const context = useContext( ViewportContext );
|
|
33
|
+
if ( ! context ) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
'useViewport must be used within a ViewportProvider.'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { act, renderHook } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useAriaAnnouncer } from '../use-aria-announcer';
|
|
10
|
+
import { DEFAULT_STATE } from '../../../core/constants';
|
|
11
|
+
import type { CropperState } from '../../../core/types';
|
|
12
|
+
|
|
13
|
+
function makeState( overrides: Partial< CropperState > = {} ): CropperState {
|
|
14
|
+
return {
|
|
15
|
+
...DEFAULT_STATE,
|
|
16
|
+
...overrides,
|
|
17
|
+
cropRect: {
|
|
18
|
+
...DEFAULT_STATE.cropRect,
|
|
19
|
+
...overrides.cropRect,
|
|
20
|
+
},
|
|
21
|
+
flip: {
|
|
22
|
+
...DEFAULT_STATE.flip,
|
|
23
|
+
...overrides.flip,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe( 'useAriaAnnouncer', () => {
|
|
29
|
+
beforeEach( () => {
|
|
30
|
+
jest.useFakeTimers();
|
|
31
|
+
} );
|
|
32
|
+
|
|
33
|
+
afterEach( () => {
|
|
34
|
+
jest.useRealTimers();
|
|
35
|
+
} );
|
|
36
|
+
|
|
37
|
+
it( 'announces horizontal flip changes', () => {
|
|
38
|
+
const { result, rerender } = renderHook(
|
|
39
|
+
( { state } ) => useAriaAnnouncer( state ),
|
|
40
|
+
{ initialProps: { state: makeState() } }
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
act( () => jest.advanceTimersByTime( 300 ) );
|
|
44
|
+
|
|
45
|
+
rerender( {
|
|
46
|
+
state: makeState( {
|
|
47
|
+
flip: { horizontal: true, vertical: false },
|
|
48
|
+
} ),
|
|
49
|
+
} );
|
|
50
|
+
act( () => jest.advanceTimersByTime( 300 ) );
|
|
51
|
+
|
|
52
|
+
expect( result.current ).toBe( 'Flipped horizontally' );
|
|
53
|
+
|
|
54
|
+
rerender( {
|
|
55
|
+
state: makeState( {
|
|
56
|
+
flip: { horizontal: false, vertical: false },
|
|
57
|
+
} ),
|
|
58
|
+
} );
|
|
59
|
+
act( () => jest.advanceTimersByTime( 300 ) );
|
|
60
|
+
|
|
61
|
+
expect( result.current ).toBe( 'Flip removed' );
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
it( 'announces combined flip state when both axes are active', () => {
|
|
65
|
+
const { result, rerender } = renderHook(
|
|
66
|
+
( { state } ) => useAriaAnnouncer( state ),
|
|
67
|
+
{ initialProps: { state: makeState() } }
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
act( () => jest.advanceTimersByTime( 300 ) );
|
|
71
|
+
|
|
72
|
+
rerender( {
|
|
73
|
+
state: makeState( {
|
|
74
|
+
flip: { horizontal: true, vertical: true },
|
|
75
|
+
} ),
|
|
76
|
+
} );
|
|
77
|
+
act( () => jest.advanceTimersByTime( 300 ) );
|
|
78
|
+
|
|
79
|
+
expect( result.current ).toBe( 'Flipped horizontally and vertically' );
|
|
80
|
+
} );
|
|
81
|
+
} );
|