@wordpress/media-editor 0.19.0 → 0.21.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 +34 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +136 -63
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +2 -3
- package/build/components/media-editor/use-crop-options.cjs.map +2 -2
- package/build/components/media-editor/use-save-media-editor.cjs +36 -20
- package/build/components/media-editor/use-save-media-editor.cjs.map +2 -2
- package/build/components/media-editor-canvas/index.cjs +8 -8
- package/build/components/media-editor-canvas/index.cjs.map +3 -3
- package/build/components/media-editor-crop-panel/index.cjs +12 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
- package/build/components/media-editor-fine-rotation/index.cjs +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
- package/build/components/media-editor-image-controls/index.cjs +46 -29
- package/build/components/media-editor-image-controls/index.cjs.map +2 -2
- package/build/components/media-editor-modal/index.cjs +19 -9
- package/build/components/media-editor-modal/index.cjs.map +2 -2
- package/build/components/media-editor-provider/index.cjs +2 -1
- package/build/components/media-editor-provider/index.cjs.map +2 -2
- package/build/components/media-form/index.cjs +28 -28
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/components/media-preview/index.cjs.map +3 -3
- package/build/hooks/use-crop-gesture-handlers.cjs +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs +5 -0
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +4 -14
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +1 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +3 -1
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +1 -1
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/state/composite-reducer.cjs +35 -10
- package/build/state/composite-reducer.cjs.map +3 -3
- package/build/state/index.cjs.map +1 -1
- package/build/state/media-editor-state-provider.cjs +1 -6
- package/build/state/media-editor-state-provider.cjs.map +2 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +57 -42
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build/store/actions.cjs +2 -0
- package/build/store/actions.cjs.map +2 -2
- package/build/store/reducer.cjs +3 -1
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +5 -0
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +151 -67
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +2 -3
- package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
- package/build-module/components/media-editor/use-save-media-editor.mjs +36 -20
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +2 -2
- package/build-module/components/media-editor-canvas/index.mjs +10 -10
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +13 -9
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs +47 -36
- package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
- package/build-module/components/media-editor-modal/index.mjs +19 -9
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-provider/index.mjs +2 -1
- package/build-module/components/media-editor-provider/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs +33 -30
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/media-preview/index.mjs +2 -2
- package/build-module/components/media-preview/index.mjs.map +2 -2
- package/build-module/hooks/use-crop-gesture-handlers.mjs +1 -1
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs +5 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +4 -14
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +1 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +3 -1
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +1 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/state/composite-reducer.mjs +25 -10
- package/build-module/state/composite-reducer.mjs.map +2 -2
- package/build-module/state/index.mjs.map +1 -1
- package/build-module/state/media-editor-state-provider.mjs +1 -6
- package/build-module/state/media-editor-state-provider.mjs.map +2 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +57 -42
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-module/store/actions.mjs +2 -0
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/reducer.mjs +3 -1
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +4 -0
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +5 -5
- package/build-style/style.css +5 -5
- package/build-types/components/media-editor/index.d.ts +4 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts +15 -3
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +5 -5
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -2
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/media-editor-state-provider.d.ts +8 -16
- package/build-types/state/media-editor-state-provider.d.ts.map +1 -1
- package/build-types/state/types.d.ts +34 -5
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +53 -35
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +9 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +3 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +1 -0
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +41 -25
- package/src/components/media-editor/index.tsx +213 -79
- package/src/components/media-editor/use-crop-options.ts +1 -3
- package/src/components/media-editor/use-save-media-editor.ts +61 -20
- package/src/components/media-editor-canvas/index.tsx +9 -10
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-fine-rotation/index.tsx +1 -1
- package/src/components/media-editor-image-controls/index.tsx +41 -41
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +26 -11
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +2 -2
- package/src/hooks/use-crop-gesture-handlers.ts +3 -1
- package/src/image-editor/core/interaction-controller.ts +8 -0
- package/src/image-editor/docs/architecture.md +10 -2
- package/src/image-editor/docs/recipes.md +8 -8
- package/src/image-editor/react/components/cropper.scss +5 -5
- package/src/image-editor/react/components/cropper.tsx +9 -18
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +3 -1
- package/src/image-editor/react/hooks/use-aria-announcer.ts +3 -1
- package/src/image-editor/react/hooks/use-interaction.ts +3 -2
- package/src/state/composite-reducer.ts +29 -17
- package/src/state/index.ts +3 -1
- package/src/state/media-editor-state-provider.tsx +9 -22
- package/src/state/types.ts +37 -5
- package/src/state/use-media-editor-state.ts +124 -78
- package/src/store/actions.ts +9 -0
- package/src/store/reducer.ts +6 -1
- package/src/store/selectors.ts +4 -0
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -104
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -74
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -180
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -165
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1254
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1460
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -324
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
.container {
|
|
2
|
-
width: 100%;
|
|
3
|
-
max-width: 600px;
|
|
4
|
-
aspect-ratio: 3 / 2;
|
|
5
|
-
border: 1px solid #ccc;
|
|
6
|
-
position: relative;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.resizable {
|
|
10
|
-
width: 600px;
|
|
11
|
-
height: 400px;
|
|
12
|
-
max-width: 100%;
|
|
13
|
-
min-width: 200px;
|
|
14
|
-
min-height: 200px;
|
|
15
|
-
border: 1px solid #ccc;
|
|
16
|
-
resize: both;
|
|
17
|
-
overflow: hidden;
|
|
18
|
-
position: relative;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.toolbar {
|
|
22
|
-
display: flex;
|
|
23
|
-
flex-direction: column;
|
|
24
|
-
gap: 12px;
|
|
25
|
-
padding: 8px;
|
|
26
|
-
margin-bottom: 12px;
|
|
27
|
-
border: 1px solid #e0e0e0;
|
|
28
|
-
border-radius: 4px;
|
|
29
|
-
background: #fafafa;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.sliders {
|
|
33
|
-
display: grid;
|
|
34
|
-
grid-template-columns: 1fr 1fr;
|
|
35
|
-
gap: 16px;
|
|
36
|
-
padding: 0 4px;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.hidden-file {
|
|
40
|
-
display: none;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.state {
|
|
44
|
-
font-family: monospace;
|
|
45
|
-
font-size: 11px;
|
|
46
|
-
background: #f5f5f5;
|
|
47
|
-
padding: 8px;
|
|
48
|
-
border-radius: 4px;
|
|
49
|
-
white-space: pre-wrap;
|
|
50
|
-
max-height: 200px;
|
|
51
|
-
overflow: auto;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
.export-preview {
|
|
55
|
-
margin-bottom: 16px;
|
|
56
|
-
max-width: 200px;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.export-image {
|
|
60
|
-
display: block;
|
|
61
|
-
max-width: 100%;
|
|
62
|
-
border: 1px solid #ccc;
|
|
63
|
-
border-radius: 4px;
|
|
64
|
-
background: repeating-conic-gradient(#e0e0e0 0% 25%, transparent 0% 50%) 50% / 16px 16px;
|
|
65
|
-
}
|
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { act, renderHook } from '@testing-library/react';
|
|
3
|
-
import { useMediaEditorState } from '../use-media-editor-state';
|
|
4
|
-
|
|
5
|
-
const IMAGE = {
|
|
6
|
-
src: 'test.jpg',
|
|
7
|
-
naturalWidth: 1200,
|
|
8
|
-
naturalHeight: 600,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function setupHook( visualSize = { width: 600, height: 400 } ) {
|
|
12
|
-
const view = renderHook( () =>
|
|
13
|
-
useMediaEditorState( { cropper: { image: IMAGE } } )
|
|
14
|
-
);
|
|
15
|
-
act( () => {
|
|
16
|
-
view.result.current.setVisualSize( visualSize );
|
|
17
|
-
} );
|
|
18
|
-
return view;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe( 'useMediaEditorState', () => {
|
|
22
|
-
describe( 'initial state', () => {
|
|
23
|
-
it( 'starts with default cropOptions', () => {
|
|
24
|
-
const { result } = renderHook( () => useMediaEditorState() );
|
|
25
|
-
|
|
26
|
-
expect( result.current.cropOptions.aspectRatioValue ).toBe( '0' );
|
|
27
|
-
} );
|
|
28
|
-
|
|
29
|
-
it( 'merges initial cropper and cropOptions overrides', () => {
|
|
30
|
-
const { result } = renderHook( () =>
|
|
31
|
-
useMediaEditorState( {
|
|
32
|
-
cropper: { image: IMAGE },
|
|
33
|
-
cropOptions: { aspectRatioValue: '1' },
|
|
34
|
-
} )
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
expect( result.current.state.image ).toEqual( IMAGE );
|
|
38
|
-
expect( result.current.cropOptions ).toEqual( {
|
|
39
|
-
aspectRatioValue: '1',
|
|
40
|
-
} );
|
|
41
|
-
} );
|
|
42
|
-
|
|
43
|
-
it( 'starts with isDirty=false and no undo / redo', () => {
|
|
44
|
-
const { result } = setupHook();
|
|
45
|
-
|
|
46
|
-
expect( result.current.isDirty ).toBe( false );
|
|
47
|
-
expect( result.current.isCropperDirty ).toBe( false );
|
|
48
|
-
expect( result.current.hasUndo ).toBe( false );
|
|
49
|
-
expect( result.current.hasRedo ).toBe( false );
|
|
50
|
-
} );
|
|
51
|
-
} );
|
|
52
|
-
|
|
53
|
-
describe( 'history — undo / redo across slices', () => {
|
|
54
|
-
it( 'records the pre-state of each action and undoes it', () => {
|
|
55
|
-
const { result } = setupHook();
|
|
56
|
-
|
|
57
|
-
act( () => result.current.setRotation( 45 ) );
|
|
58
|
-
|
|
59
|
-
expect( result.current.state.rotation ).toBe( 45 );
|
|
60
|
-
expect( result.current.hasUndo ).toBe( true );
|
|
61
|
-
|
|
62
|
-
act( () => result.current.undo() );
|
|
63
|
-
|
|
64
|
-
expect( result.current.state.rotation ).toBe( 0 );
|
|
65
|
-
expect( result.current.hasUndo ).toBe( false );
|
|
66
|
-
expect( result.current.hasRedo ).toBe( true );
|
|
67
|
-
} );
|
|
68
|
-
|
|
69
|
-
it( 'redo re-applies an undone action', () => {
|
|
70
|
-
const { result } = setupHook();
|
|
71
|
-
|
|
72
|
-
act( () => result.current.setRotation( 45 ) );
|
|
73
|
-
act( () => result.current.undo() );
|
|
74
|
-
act( () => result.current.redo() );
|
|
75
|
-
|
|
76
|
-
expect( result.current.state.rotation ).toBe( 45 );
|
|
77
|
-
} );
|
|
78
|
-
|
|
79
|
-
it( 'redo stack clears on a new action after undo', () => {
|
|
80
|
-
const { result } = setupHook();
|
|
81
|
-
|
|
82
|
-
act( () => result.current.setRotation( 45 ) );
|
|
83
|
-
act( () => result.current.undo() );
|
|
84
|
-
act( () => result.current.setRotation( 90 ) );
|
|
85
|
-
|
|
86
|
-
expect( result.current.hasRedo ).toBe( false );
|
|
87
|
-
} );
|
|
88
|
-
|
|
89
|
-
it( 'no-op actions do not record history entries', () => {
|
|
90
|
-
const { result } = setupHook();
|
|
91
|
-
|
|
92
|
-
act( () => result.current.setAspectRatioValue( '0' ) );
|
|
93
|
-
|
|
94
|
-
expect( result.current.hasUndo ).toBe( false );
|
|
95
|
-
} );
|
|
96
|
-
|
|
97
|
-
it( 'a single undo restores both cropOptions and cropRect after aspect-ratio change', () => {
|
|
98
|
-
const { result } = setupHook();
|
|
99
|
-
const initialCropRect = result.current.state.cropRect;
|
|
100
|
-
const initialPreset = result.current.cropOptions.aspectRatioValue;
|
|
101
|
-
|
|
102
|
-
act( () => result.current.setAspectRatioValue( '1' ) ); // Square
|
|
103
|
-
|
|
104
|
-
// Both slices changed atomically: preset key and cropRect.
|
|
105
|
-
expect( result.current.cropOptions.aspectRatioValue ).toBe( '1' );
|
|
106
|
-
expect( result.current.state.cropRect ).not.toEqual(
|
|
107
|
-
initialCropRect
|
|
108
|
-
);
|
|
109
|
-
expect( result.current.isCropperDirty ).toBe( true );
|
|
110
|
-
// Only ONE undo entry — atomic transaction.
|
|
111
|
-
expect( result.current.hasUndo ).toBe( true );
|
|
112
|
-
|
|
113
|
-
act( () => result.current.undo() );
|
|
114
|
-
|
|
115
|
-
expect( result.current.cropOptions.aspectRatioValue ).toBe(
|
|
116
|
-
initialPreset
|
|
117
|
-
);
|
|
118
|
-
expect( result.current.state.cropRect ).toEqual( initialCropRect );
|
|
119
|
-
} );
|
|
120
|
-
} );
|
|
121
|
-
|
|
122
|
-
describe( 'gestures — coalesce many changes into one undo entry', () => {
|
|
123
|
-
it( 'coalesces all changes between beginGesture and endGesture', () => {
|
|
124
|
-
const { result } = setupHook();
|
|
125
|
-
|
|
126
|
-
act( () => result.current.beginGesture() );
|
|
127
|
-
act( () => result.current.setRotation( 10 ) );
|
|
128
|
-
act( () => result.current.setRotation( 20 ) );
|
|
129
|
-
act( () => result.current.setRotation( 30 ) );
|
|
130
|
-
act( () => result.current.endGesture() );
|
|
131
|
-
|
|
132
|
-
expect( result.current.state.rotation ).toBe( 30 );
|
|
133
|
-
expect( result.current.hasUndo ).toBe( true );
|
|
134
|
-
|
|
135
|
-
// One undo restores all the way to the pre-gesture state.
|
|
136
|
-
act( () => result.current.undo() );
|
|
137
|
-
expect( result.current.state.rotation ).toBe( 0 );
|
|
138
|
-
} );
|
|
139
|
-
|
|
140
|
-
it( 'an empty gesture (no changes) records no history', () => {
|
|
141
|
-
const { result } = setupHook();
|
|
142
|
-
|
|
143
|
-
act( () => result.current.beginGesture() );
|
|
144
|
-
act( () => result.current.endGesture() );
|
|
145
|
-
|
|
146
|
-
expect( result.current.hasUndo ).toBe( false );
|
|
147
|
-
} );
|
|
148
|
-
|
|
149
|
-
it( 'undo during an open gesture flushes the gesture first', () => {
|
|
150
|
-
const { result } = setupHook();
|
|
151
|
-
|
|
152
|
-
act( () => result.current.beginGesture() );
|
|
153
|
-
act( () => result.current.setRotation( 45 ) );
|
|
154
|
-
// Undo without endGesture should still flush the in-flight change.
|
|
155
|
-
act( () => result.current.undo() );
|
|
156
|
-
|
|
157
|
-
expect( result.current.state.rotation ).toBe( 0 );
|
|
158
|
-
expect( result.current.hasRedo ).toBe( true );
|
|
159
|
-
} );
|
|
160
|
-
|
|
161
|
-
it( 'keeps the original gesture snapshot if beginGesture is called repeatedly', () => {
|
|
162
|
-
const { result } = setupHook();
|
|
163
|
-
|
|
164
|
-
act( () => {
|
|
165
|
-
result.current.beginGesture();
|
|
166
|
-
result.current.setRotation( 10 );
|
|
167
|
-
result.current.beginGesture();
|
|
168
|
-
result.current.setRotation( 20 );
|
|
169
|
-
result.current.endGesture();
|
|
170
|
-
} );
|
|
171
|
-
|
|
172
|
-
expect( result.current.state.rotation ).toBe( 20 );
|
|
173
|
-
|
|
174
|
-
act( () => result.current.undo() );
|
|
175
|
-
|
|
176
|
-
expect( result.current.state.rotation ).toBe( 0 );
|
|
177
|
-
} );
|
|
178
|
-
|
|
179
|
-
it( 'does not record a gesture that returns to its starting state', () => {
|
|
180
|
-
const { result } = setupHook();
|
|
181
|
-
|
|
182
|
-
act( () => {
|
|
183
|
-
result.current.beginGesture();
|
|
184
|
-
result.current.setRotation( 10 );
|
|
185
|
-
result.current.setRotation( 0 );
|
|
186
|
-
result.current.endGesture();
|
|
187
|
-
} );
|
|
188
|
-
|
|
189
|
-
expect( result.current.state.rotation ).toBe( 0 );
|
|
190
|
-
expect( result.current.hasUndo ).toBe( false );
|
|
191
|
-
} );
|
|
192
|
-
} );
|
|
193
|
-
|
|
194
|
-
describe( 'SET_ASPECT_RATIO_VALUE atomicity', () => {
|
|
195
|
-
it( 'reshapes cropRect when a fixed ratio is selected with visualSize > 0', () => {
|
|
196
|
-
const { result } = setupHook( { width: 600, height: 400 } );
|
|
197
|
-
|
|
198
|
-
act( () => result.current.setAspectRatioValue( '1' ) ); // Square
|
|
199
|
-
|
|
200
|
-
// At visualSize 600x400, the inscribed square has w/h such that
|
|
201
|
-
// pixel ratio = 1. normalizedRatio = 1 * 400 / 600 = 0.666...
|
|
202
|
-
// So normalized w = 0.666..., h = 1.
|
|
203
|
-
expect( result.current.state.cropRect.width ).toBeCloseTo(
|
|
204
|
-
2 / 3,
|
|
205
|
-
5
|
|
206
|
-
);
|
|
207
|
-
expect( result.current.state.cropRect.height ).toBeCloseTo( 1, 5 );
|
|
208
|
-
} );
|
|
209
|
-
|
|
210
|
-
it( 'Free leaves the cropRect alone', () => {
|
|
211
|
-
const { result } = setupHook();
|
|
212
|
-
const original = result.current.state.cropRect;
|
|
213
|
-
|
|
214
|
-
// User-picked custom crop first.
|
|
215
|
-
act( () =>
|
|
216
|
-
result.current.setCropRect( {
|
|
217
|
-
x: 0.1,
|
|
218
|
-
y: 0.1,
|
|
219
|
-
width: 0.5,
|
|
220
|
-
height: 0.5,
|
|
221
|
-
} )
|
|
222
|
-
);
|
|
223
|
-
const beforeFree = result.current.state.cropRect;
|
|
224
|
-
|
|
225
|
-
// Switch to Free — cropRect should NOT snap back to anything.
|
|
226
|
-
act( () => result.current.setAspectRatioValue( '0' ) );
|
|
227
|
-
|
|
228
|
-
expect( result.current.state.cropRect ).toEqual( beforeFree );
|
|
229
|
-
expect( original ).not.toEqual( beforeFree );
|
|
230
|
-
} );
|
|
231
|
-
|
|
232
|
-
it( 'resolves Original from the loaded image', () => {
|
|
233
|
-
const { result } = setupHook();
|
|
234
|
-
|
|
235
|
-
act( () => result.current.setAspectRatioValue( '-1' ) ); // Original
|
|
236
|
-
|
|
237
|
-
// Image is 1200x600 = ratio 2. inscribedRect at visualSize 600x400:
|
|
238
|
-
// normalizedRatio = 2 * 400 / 600 = 1.333... > 1, so h = 1/1.333 = 0.75.
|
|
239
|
-
expect( result.current.state.cropRect.width ).toBeCloseTo( 1, 5 );
|
|
240
|
-
expect( result.current.state.cropRect.height ).toBeCloseTo(
|
|
241
|
-
0.75,
|
|
242
|
-
5
|
|
243
|
-
);
|
|
244
|
-
} );
|
|
245
|
-
|
|
246
|
-
it( 'groups cropper reset and cropOptions reset in one undo step', () => {
|
|
247
|
-
const { result } = setupHook();
|
|
248
|
-
|
|
249
|
-
act( () => result.current.setAspectRatioValue( '1' ) );
|
|
250
|
-
act( () => result.current.setRotation( 45 ) );
|
|
251
|
-
|
|
252
|
-
act( () => {
|
|
253
|
-
result.current.beginGesture();
|
|
254
|
-
result.current.reset();
|
|
255
|
-
result.current.resetCropOptions();
|
|
256
|
-
result.current.endGesture();
|
|
257
|
-
} );
|
|
258
|
-
|
|
259
|
-
expect( result.current.state.rotation ).toBe( 0 );
|
|
260
|
-
expect( result.current.cropOptions ).toEqual( {
|
|
261
|
-
aspectRatioValue: '0',
|
|
262
|
-
} );
|
|
263
|
-
|
|
264
|
-
act( () => result.current.undo() );
|
|
265
|
-
|
|
266
|
-
expect( result.current.state.rotation ).toBe( 45 );
|
|
267
|
-
expect( result.current.cropOptions ).toEqual( {
|
|
268
|
-
aspectRatioValue: '1',
|
|
269
|
-
} );
|
|
270
|
-
} );
|
|
271
|
-
} );
|
|
272
|
-
|
|
273
|
-
describe( 'viewport reshape is silent', () => {
|
|
274
|
-
it( 'adjustCropRectForViewport does NOT record an undo entry', () => {
|
|
275
|
-
const { result } = setupHook();
|
|
276
|
-
|
|
277
|
-
act( () =>
|
|
278
|
-
result.current.adjustCropRectForViewport( {
|
|
279
|
-
x: 0,
|
|
280
|
-
y: 0,
|
|
281
|
-
width: 0.5,
|
|
282
|
-
height: 0.5,
|
|
283
|
-
} )
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
expect( result.current.hasUndo ).toBe( false );
|
|
287
|
-
} );
|
|
288
|
-
} );
|
|
289
|
-
|
|
290
|
-
describe( 'setImage', () => {
|
|
291
|
-
it( 'clears history and resets isDirty', () => {
|
|
292
|
-
const { result } = setupHook();
|
|
293
|
-
|
|
294
|
-
act( () => result.current.setRotation( 45 ) );
|
|
295
|
-
expect( result.current.hasUndo ).toBe( true );
|
|
296
|
-
expect( result.current.isDirty ).toBe( true );
|
|
297
|
-
|
|
298
|
-
act( () =>
|
|
299
|
-
result.current.setImage( {
|
|
300
|
-
src: 'other.jpg',
|
|
301
|
-
naturalWidth: 800,
|
|
302
|
-
naturalHeight: 800,
|
|
303
|
-
} )
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
expect( result.current.hasUndo ).toBe( false );
|
|
307
|
-
expect( result.current.hasRedo ).toBe( false );
|
|
308
|
-
expect( result.current.isDirty ).toBe( false );
|
|
309
|
-
} );
|
|
310
|
-
|
|
311
|
-
it( 'does not clear history when the same image is reported again', () => {
|
|
312
|
-
const { result } = setupHook();
|
|
313
|
-
|
|
314
|
-
act( () => result.current.setRotation( 45 ) );
|
|
315
|
-
expect( result.current.hasUndo ).toBe( true );
|
|
316
|
-
expect( result.current.isCropperDirty ).toBe( true );
|
|
317
|
-
|
|
318
|
-
act( () => result.current.setImage( IMAGE ) );
|
|
319
|
-
|
|
320
|
-
expect( result.current.hasUndo ).toBe( true );
|
|
321
|
-
expect( result.current.isCropperDirty ).toBe( true );
|
|
322
|
-
} );
|
|
323
|
-
} );
|
|
324
|
-
} );
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import reducer, { DEFAULT_STATE } from '../reducer';
|
|
3
|
-
|
|
4
|
-
describe( 'core/media-editor reducer', () => {
|
|
5
|
-
it( 'returns the default state for an unknown action', () => {
|
|
6
|
-
const state = reducer( undefined, { type: '@@INIT' } );
|
|
7
|
-
expect( state ).toEqual( DEFAULT_STATE );
|
|
8
|
-
} );
|
|
9
|
-
|
|
10
|
-
it( 'opens the modal with id and onUpdate', () => {
|
|
11
|
-
const onUpdate = vi.fn();
|
|
12
|
-
const onClose = vi.fn();
|
|
13
|
-
const state = reducer( undefined, {
|
|
14
|
-
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
15
|
-
id: 42,
|
|
16
|
-
onUpdate,
|
|
17
|
-
onClose,
|
|
18
|
-
} );
|
|
19
|
-
expect( state ).toEqual( {
|
|
20
|
-
isOpen: true,
|
|
21
|
-
id: 42,
|
|
22
|
-
onUpdate,
|
|
23
|
-
onClose,
|
|
24
|
-
} );
|
|
25
|
-
} );
|
|
26
|
-
|
|
27
|
-
it( 'replaces state on a subsequent open (new onUpdate)', () => {
|
|
28
|
-
const firstOnUpdate = vi.fn();
|
|
29
|
-
const firstOnClose = vi.fn();
|
|
30
|
-
const secondOnUpdate = vi.fn();
|
|
31
|
-
const secondOnClose = vi.fn();
|
|
32
|
-
const first = reducer( undefined, {
|
|
33
|
-
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
34
|
-
id: 42,
|
|
35
|
-
onUpdate: firstOnUpdate,
|
|
36
|
-
onClose: firstOnClose,
|
|
37
|
-
} );
|
|
38
|
-
const second = reducer( first, {
|
|
39
|
-
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
40
|
-
id: 99,
|
|
41
|
-
onUpdate: secondOnUpdate,
|
|
42
|
-
onClose: secondOnClose,
|
|
43
|
-
} );
|
|
44
|
-
expect( second ).toEqual( {
|
|
45
|
-
isOpen: true,
|
|
46
|
-
id: 99,
|
|
47
|
-
onUpdate: secondOnUpdate,
|
|
48
|
-
onClose: secondOnClose,
|
|
49
|
-
} );
|
|
50
|
-
} );
|
|
51
|
-
|
|
52
|
-
it( 'clears state on close', () => {
|
|
53
|
-
const opened = reducer( undefined, {
|
|
54
|
-
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
55
|
-
id: 42,
|
|
56
|
-
onUpdate: vi.fn(),
|
|
57
|
-
onClose: vi.fn(),
|
|
58
|
-
} );
|
|
59
|
-
const closed = reducer( opened, {
|
|
60
|
-
type: 'CLOSE_MEDIA_EDITOR_MODAL',
|
|
61
|
-
} );
|
|
62
|
-
expect( closed ).toEqual( DEFAULT_STATE );
|
|
63
|
-
} );
|
|
64
|
-
} );
|
package/tsconfig.build.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
3
|
-
"extends": "@wordpress/monorepo-tools/tsconfig/base.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"types": [ "gutenberg-env", "style-imports" ],
|
|
6
|
-
"checkJs": false
|
|
7
|
-
},
|
|
8
|
-
"references": [
|
|
9
|
-
{ "path": "../a11y/tsconfig.build.json" },
|
|
10
|
-
{ "path": "../admin-ui/tsconfig.build.json" },
|
|
11
|
-
{ "path": "../api-fetch/tsconfig.build.json" },
|
|
12
|
-
{ "path": "../components/tsconfig.build.json" },
|
|
13
|
-
{ "path": "../compose/tsconfig.build.json" },
|
|
14
|
-
{ "path": "../core-data/tsconfig.build.json" },
|
|
15
|
-
{ "path": "../data" },
|
|
16
|
-
{ "path": "../dataviews/tsconfig.build.json" },
|
|
17
|
-
{ "path": "../element/tsconfig.build.json" },
|
|
18
|
-
{ "path": "../i18n/tsconfig.build.json" },
|
|
19
|
-
{ "path": "../icons/tsconfig.build.json" },
|
|
20
|
-
{ "path": "../keyboard-shortcuts" },
|
|
21
|
-
{ "path": "../keycodes/tsconfig.build.json" },
|
|
22
|
-
{ "path": "../notices/tsconfig.build.json" },
|
|
23
|
-
{ "path": "../private-apis" },
|
|
24
|
-
{ "path": "../ui/tsconfig.build.json" }
|
|
25
|
-
]
|
|
26
|
-
}
|