@wordpress/media-editor 0.10.0 → 0.11.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 +185 -42
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +2 -26
- package/build/components/media-editor/use-crop-options.cjs.map +2 -2
- package/build/components/media-editor-canvas/index.cjs +2 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +24 -21
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs +81 -0
- package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +25 -7
- package/build/components/media-editor-modal/index.cjs.map +2 -2
- package/build/components/media-editor-transform-controls/index.cjs +84 -0
- package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
- 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/react/components/cropper.cjs +1 -1
- 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 +1 -3
- 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 +2 -14
- package/build/state/composite-reducer.cjs.map +2 -2
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +2 -2
- package/build/state/use-media-editor-state.cjs +0 -11
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build/store/actions.cjs +4 -2
- package/build/store/actions.cjs.map +2 -2
- package/build/store/reducer.cjs +5 -3
- 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 +191 -44
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +3 -27
- package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
- package/build-module/components/media-editor-canvas/index.mjs +2 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +25 -26
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +26 -8
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
- package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
- 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/react/components/cropper.mjs +1 -1
- 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 +1 -3
- 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 +2 -14
- package/build-module/state/composite-reducer.mjs.map +2 -2
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +2 -2
- package/build-module/state/use-media-editor-state.mjs +0 -11
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-module/store/actions.mjs +4 -2
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/reducer.mjs +5 -3
- 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 +51 -35
- package/build-style/style.css +51 -35
- package/build-types/components/media-editor/index.d.ts +14 -2
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +3 -5
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +3 -10
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +14 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.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.map +1 -1
- package/build-types/state/types.d.ts +3 -11
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +2 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -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 +20 -19
- package/src/components/media-editor/index.tsx +226 -57
- package/src/components/media-editor/style.scss +0 -9
- package/src/components/media-editor/test/use-crop-options.tsx +1 -55
- package/src/components/media-editor/use-crop-options.ts +6 -42
- package/src/components/media-editor-canvas/index.tsx +2 -2
- package/src/components/media-editor-crop-panel/index.tsx +35 -33
- package/src/components/media-editor-crop-panel/test/index.tsx +39 -20
- package/src/components/media-editor-fine-rotation/index.tsx +74 -0
- package/src/components/media-editor-modal/index.tsx +20 -4
- package/src/components/media-editor-modal/style.scss +80 -0
- package/src/components/media-editor-modal/test/index.tsx +3 -0
- package/src/components/media-editor-transform-controls/index.tsx +70 -0
- package/src/components/media-editor-transform-controls/style.scss +8 -0
- package/src/hooks/use-crop-gesture-handlers.ts +1 -3
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.tsx +1 -3
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +1 -3
- package/src/image-editor/react/hooks/use-aria-announcer.ts +1 -3
- package/src/image-editor/react/hooks/use-interaction.ts +2 -3
- package/src/state/composite-reducer.ts +2 -17
- package/src/state/test/use-media-editor-state.ts +3 -75
- package/src/state/types.ts +3 -9
- package/src/state/use-media-editor-state.ts +3 -19
- package/src/store/actions.ts +3 -0
- package/src/store/reducer.ts +6 -1
- package/src/store/selectors.ts +4 -0
- package/src/store/test/reducer.ts +9 -0
- package/src/style.scss +1 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-toolbar/index.cjs +0 -218
- package/build/components/media-editor-toolbar/index.cjs.map +0 -7
- package/build-module/components/media-editor-toolbar/index.mjs +0 -194
- package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/src/components/media-editor-toolbar/index.tsx +0 -213
- package/src/components/media-editor-toolbar/style.scss +0 -49
|
@@ -71,24 +71,10 @@ export function mediaEditorReducer(
|
|
|
71
71
|
cropOptions: nextCropOptions,
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
case 'SET_FREEFORM_CROP': {
|
|
75
|
-
if ( state.cropOptions.freeformCrop === action.payload ) {
|
|
76
|
-
return state;
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
...state,
|
|
80
|
-
cropOptions: {
|
|
81
|
-
...state.cropOptions,
|
|
82
|
-
freeformCrop: action.payload,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
74
|
case 'RESET_CROP_OPTIONS': {
|
|
87
75
|
if (
|
|
88
76
|
state.cropOptions.aspectRatioValue ===
|
|
89
|
-
|
|
90
|
-
state.cropOptions.freeformCrop ===
|
|
91
|
-
DEFAULT_CROP_OPTIONS.freeformCrop
|
|
77
|
+
DEFAULT_CROP_OPTIONS.aspectRatioValue
|
|
92
78
|
) {
|
|
93
79
|
return state;
|
|
94
80
|
}
|
|
@@ -129,8 +115,7 @@ export function areMediaEditorStatesEqual(
|
|
|
129
115
|
}
|
|
130
116
|
return (
|
|
131
117
|
areCropperStatesEqual( a.cropper, b.cropper ) &&
|
|
132
|
-
a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue
|
|
133
|
-
a.cropOptions.freeformCrop === b.cropOptions.freeformCrop
|
|
118
|
+
a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue
|
|
134
119
|
);
|
|
135
120
|
}
|
|
136
121
|
|
|
@@ -26,25 +26,23 @@ function setupHook( visualSize = { width: 600, height: 400 } ) {
|
|
|
26
26
|
|
|
27
27
|
describe( 'useMediaEditorState', () => {
|
|
28
28
|
describe( 'initial state', () => {
|
|
29
|
-
it( 'starts with default cropOptions
|
|
29
|
+
it( 'starts with default cropOptions', () => {
|
|
30
30
|
const { result } = renderHook( () => useMediaEditorState() );
|
|
31
31
|
|
|
32
32
|
expect( result.current.cropOptions.aspectRatioValue ).toBe( '0' );
|
|
33
|
-
expect( result.current.cropOptions.freeformCrop ).toBe( true );
|
|
34
33
|
} );
|
|
35
34
|
|
|
36
35
|
it( 'merges initial cropper and cropOptions overrides', () => {
|
|
37
36
|
const { result } = renderHook( () =>
|
|
38
37
|
useMediaEditorState( {
|
|
39
38
|
cropper: { image: IMAGE },
|
|
40
|
-
cropOptions: { aspectRatioValue: '1'
|
|
39
|
+
cropOptions: { aspectRatioValue: '1' },
|
|
41
40
|
} )
|
|
42
41
|
);
|
|
43
42
|
|
|
44
43
|
expect( result.current.state.image ).toEqual( IMAGE );
|
|
45
44
|
expect( result.current.cropOptions ).toEqual( {
|
|
46
45
|
aspectRatioValue: '1',
|
|
47
|
-
freeformCrop: false,
|
|
48
46
|
} );
|
|
49
47
|
} );
|
|
50
48
|
|
|
@@ -94,23 +92,10 @@ describe( 'useMediaEditorState', () => {
|
|
|
94
92
|
expect( result.current.hasRedo ).toBe( false );
|
|
95
93
|
} );
|
|
96
94
|
|
|
97
|
-
it( 'undo restores cropOptions changes (freeform toggle)', () => {
|
|
98
|
-
const { result } = setupHook();
|
|
99
|
-
|
|
100
|
-
act( () => result.current.setFreeformCrop( false ) );
|
|
101
|
-
expect( result.current.cropOptions.freeformCrop ).toBe( false );
|
|
102
|
-
expect( result.current.isDirty ).toBe( true );
|
|
103
|
-
expect( result.current.isCropperDirty ).toBe( false );
|
|
104
|
-
|
|
105
|
-
act( () => result.current.undo() );
|
|
106
|
-
expect( result.current.cropOptions.freeformCrop ).toBe( true );
|
|
107
|
-
} );
|
|
108
|
-
|
|
109
95
|
it( 'no-op actions do not record history entries', () => {
|
|
110
96
|
const { result } = setupHook();
|
|
111
97
|
|
|
112
|
-
|
|
113
|
-
act( () => result.current.setFreeformCrop( true ) );
|
|
98
|
+
act( () => result.current.setAspectRatioValue( '0' ) );
|
|
114
99
|
|
|
115
100
|
expect( result.current.hasUndo ).toBe( false );
|
|
116
101
|
} );
|
|
@@ -210,37 +195,6 @@ describe( 'useMediaEditorState', () => {
|
|
|
210
195
|
expect( result.current.state.rotation ).toBe( 0 );
|
|
211
196
|
expect( result.current.hasUndo ).toBe( false );
|
|
212
197
|
} );
|
|
213
|
-
|
|
214
|
-
it( 'groups a Free preset change and freeform re-enable in one undo step', () => {
|
|
215
|
-
const { result } = renderHook( () =>
|
|
216
|
-
useMediaEditorState( {
|
|
217
|
-
cropper: { image: IMAGE },
|
|
218
|
-
cropOptions: {
|
|
219
|
-
aspectRatioValue: '1',
|
|
220
|
-
freeformCrop: false,
|
|
221
|
-
},
|
|
222
|
-
} )
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
act( () => {
|
|
226
|
-
result.current.beginGesture();
|
|
227
|
-
result.current.setAspectRatioValue( '0' );
|
|
228
|
-
result.current.setFreeformCrop( true );
|
|
229
|
-
result.current.endGesture();
|
|
230
|
-
} );
|
|
231
|
-
|
|
232
|
-
expect( result.current.cropOptions ).toEqual( {
|
|
233
|
-
aspectRatioValue: '0',
|
|
234
|
-
freeformCrop: true,
|
|
235
|
-
} );
|
|
236
|
-
|
|
237
|
-
act( () => result.current.undo() );
|
|
238
|
-
|
|
239
|
-
expect( result.current.cropOptions ).toEqual( {
|
|
240
|
-
aspectRatioValue: '1',
|
|
241
|
-
freeformCrop: false,
|
|
242
|
-
} );
|
|
243
|
-
} );
|
|
244
198
|
} );
|
|
245
199
|
|
|
246
200
|
describe( 'SET_ASPECT_RATIO_VALUE atomicity', () => {
|
|
@@ -295,34 +249,10 @@ describe( 'useMediaEditorState', () => {
|
|
|
295
249
|
);
|
|
296
250
|
} );
|
|
297
251
|
|
|
298
|
-
it( 'records exactly ONE history entry for an aspect-ratio change followed by a freeform toggle', () => {
|
|
299
|
-
const { result } = setupHook();
|
|
300
|
-
const original = result.current.state.cropRect;
|
|
301
|
-
const originalPreset = result.current.cropOptions.aspectRatioValue;
|
|
302
|
-
const originalFreeform = result.current.cropOptions.freeformCrop;
|
|
303
|
-
|
|
304
|
-
act( () => result.current.setAspectRatioValue( '1' ) ); // Square
|
|
305
|
-
act( () => result.current.setFreeformCrop( false ) );
|
|
306
|
-
|
|
307
|
-
// Two discrete actions → two undo entries.
|
|
308
|
-
act( () => result.current.undo() );
|
|
309
|
-
expect( result.current.cropOptions.freeformCrop ).toBe(
|
|
310
|
-
originalFreeform
|
|
311
|
-
);
|
|
312
|
-
expect( result.current.cropOptions.aspectRatioValue ).toBe( '1' );
|
|
313
|
-
|
|
314
|
-
act( () => result.current.undo() );
|
|
315
|
-
expect( result.current.cropOptions.aspectRatioValue ).toBe(
|
|
316
|
-
originalPreset
|
|
317
|
-
);
|
|
318
|
-
expect( result.current.state.cropRect ).toEqual( original );
|
|
319
|
-
} );
|
|
320
|
-
|
|
321
252
|
it( 'groups cropper reset and cropOptions reset in one undo step', () => {
|
|
322
253
|
const { result } = setupHook();
|
|
323
254
|
|
|
324
255
|
act( () => result.current.setAspectRatioValue( '1' ) );
|
|
325
|
-
act( () => result.current.setFreeformCrop( false ) );
|
|
326
256
|
act( () => result.current.setRotation( 45 ) );
|
|
327
257
|
|
|
328
258
|
act( () => {
|
|
@@ -335,7 +265,6 @@ describe( 'useMediaEditorState', () => {
|
|
|
335
265
|
expect( result.current.state.rotation ).toBe( 0 );
|
|
336
266
|
expect( result.current.cropOptions ).toEqual( {
|
|
337
267
|
aspectRatioValue: '0',
|
|
338
|
-
freeformCrop: true,
|
|
339
268
|
} );
|
|
340
269
|
|
|
341
270
|
act( () => result.current.undo() );
|
|
@@ -343,7 +272,6 @@ describe( 'useMediaEditorState', () => {
|
|
|
343
272
|
expect( result.current.state.rotation ).toBe( 45 );
|
|
344
273
|
expect( result.current.cropOptions ).toEqual( {
|
|
345
274
|
aspectRatioValue: '1',
|
|
346
|
-
freeformCrop: false,
|
|
347
275
|
} );
|
|
348
276
|
} );
|
|
349
277
|
} );
|
package/src/state/types.ts
CHANGED
|
@@ -9,9 +9,8 @@ import type {
|
|
|
9
9
|
} from '../image-editor';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Sidebar control state for the cropper
|
|
13
|
-
*
|
|
14
|
-
* participates in the same undo history as cropper geometry.
|
|
12
|
+
* Sidebar control state for the cropper. Lives in the composite store
|
|
13
|
+
* so it participates in the same undo history as cropper geometry.
|
|
15
14
|
*/
|
|
16
15
|
export interface CropOptionsSlice {
|
|
17
16
|
/**
|
|
@@ -20,8 +19,6 @@ export interface CropOptionsSlice {
|
|
|
20
19
|
* decimal = fixed ratio.
|
|
21
20
|
*/
|
|
22
21
|
aspectRatioValue: string;
|
|
23
|
-
/** Whether the cropper exposes resize handles. */
|
|
24
|
-
freeformCrop: boolean;
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
/**
|
|
@@ -30,7 +27,6 @@ export interface CropOptionsSlice {
|
|
|
30
27
|
*/
|
|
31
28
|
export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
|
|
32
29
|
aspectRatioValue: '0',
|
|
33
|
-
freeformCrop: true,
|
|
34
30
|
};
|
|
35
31
|
|
|
36
32
|
/**
|
|
@@ -86,9 +82,7 @@ export type MediaEditorAction =
|
|
|
86
82
|
visualSize: Size;
|
|
87
83
|
};
|
|
88
84
|
}
|
|
89
|
-
/**
|
|
90
|
-
| { type: 'SET_FREEFORM_CROP'; payload: boolean }
|
|
91
|
-
/** Reset both cropOptions fields to defaults. */
|
|
85
|
+
/** Reset cropOptions to defaults. */
|
|
92
86
|
| { type: 'RESET_CROP_OPTIONS' }
|
|
93
87
|
/**
|
|
94
88
|
* Replace the entire composite state with `payload`. Used by
|
|
@@ -95,17 +95,14 @@ function areCropperImagesEqual(
|
|
|
95
95
|
* setters, undo/redo, gesture boundaries, and viewport reporting.
|
|
96
96
|
*/
|
|
97
97
|
export interface MediaEditorController extends CropperController {
|
|
98
|
-
/** The cropOptions slice
|
|
98
|
+
/** The cropOptions slice. */
|
|
99
99
|
cropOptions: CropOptionsSlice;
|
|
100
100
|
/** Set the aspect-ratio preset. Atomic with the cropRect reshape. */
|
|
101
101
|
setAspectRatioValue: ( presetKey: string ) => void;
|
|
102
|
-
/**
|
|
103
|
-
setFreeformCrop: ( value: boolean ) => void;
|
|
104
|
-
/** Reset cropOptions to defaults (Free + freeform on). */
|
|
102
|
+
/** Reset cropOptions to defaults. */
|
|
105
103
|
resetCropOptions: () => void;
|
|
106
104
|
/**
|
|
107
105
|
* Whether the cropper geometry differs from the initial baseline.
|
|
108
|
-
* This excludes UI-only cropOptions such as the resize-handle toggle.
|
|
109
106
|
*/
|
|
110
107
|
isCropperDirty: boolean;
|
|
111
108
|
/** Whether there's an undoable change in history. */
|
|
@@ -224,8 +221,7 @@ export function useMediaEditorState(
|
|
|
224
221
|
|
|
225
222
|
// Core dispatch wrapper. Synchronously computes the post-state via
|
|
226
223
|
// the pure reducer so we can skip history pushes for no-op actions
|
|
227
|
-
//
|
|
228
|
-
// `stateRef` in lockstep with React's pending state.
|
|
224
|
+
// and keep `stateRef` in lockstep with React's pending state.
|
|
229
225
|
const dispatchWithHistory = useCallback(
|
|
230
226
|
( action: MediaEditorAction, recordHistory = true ) => {
|
|
231
227
|
const preState = stateRef.current;
|
|
@@ -346,16 +342,6 @@ export function useMediaEditorState(
|
|
|
346
342
|
[ dispatchWithHistory ]
|
|
347
343
|
);
|
|
348
344
|
|
|
349
|
-
const setFreeformCrop = useCallback(
|
|
350
|
-
( value: boolean ) => {
|
|
351
|
-
dispatchWithHistory( {
|
|
352
|
-
type: 'SET_FREEFORM_CROP',
|
|
353
|
-
payload: value,
|
|
354
|
-
} );
|
|
355
|
-
},
|
|
356
|
-
[ dispatchWithHistory ]
|
|
357
|
-
);
|
|
358
|
-
|
|
359
345
|
const resetCropOptions = useCallback( () => {
|
|
360
346
|
dispatchWithHistory( { type: 'RESET_CROP_OPTIONS' } );
|
|
361
347
|
}, [ dispatchWithHistory ] );
|
|
@@ -450,7 +436,6 @@ export function useMediaEditorState(
|
|
|
450
436
|
// Composite extensions
|
|
451
437
|
cropOptions: state.cropOptions,
|
|
452
438
|
setAspectRatioValue,
|
|
453
|
-
setFreeformCrop,
|
|
454
439
|
resetCropOptions,
|
|
455
440
|
isCropperDirty,
|
|
456
441
|
hasUndo,
|
|
@@ -471,7 +456,6 @@ export function useMediaEditorState(
|
|
|
471
456
|
getCroppedImage,
|
|
472
457
|
state.cropOptions,
|
|
473
458
|
setAspectRatioValue,
|
|
474
|
-
setFreeformCrop,
|
|
475
459
|
resetCropOptions,
|
|
476
460
|
isCropperDirty,
|
|
477
461
|
hasUndo,
|
package/src/store/actions.ts
CHANGED
|
@@ -15,16 +15,19 @@ export interface MediaEditorModalUpdate {
|
|
|
15
15
|
interface OpenMediaEditorModalArgs {
|
|
16
16
|
id: number;
|
|
17
17
|
onUpdate?: ( updated: MediaEditorModalUpdate ) => void;
|
|
18
|
+
onClose?: () => void;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export function openMediaEditorModal( {
|
|
21
22
|
id,
|
|
22
23
|
onUpdate,
|
|
24
|
+
onClose,
|
|
23
25
|
}: OpenMediaEditorModalArgs ) {
|
|
24
26
|
return {
|
|
25
27
|
type: 'OPEN_MEDIA_EDITOR_MODAL' as const,
|
|
26
28
|
id,
|
|
27
29
|
onUpdate: onUpdate ?? null,
|
|
30
|
+
onClose: onClose ?? null,
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
33
|
|
package/src/store/reducer.ts
CHANGED
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|
import type { MediaEditorModalUpdate } from './actions';
|
|
5
5
|
|
|
6
6
|
type OnUpdateCallback = ( updated: MediaEditorModalUpdate ) => void;
|
|
7
|
+
type OnCloseCallback = () => void;
|
|
7
8
|
|
|
8
9
|
export interface State {
|
|
9
10
|
isOpen: boolean;
|
|
10
11
|
id: number | null;
|
|
11
12
|
onUpdate: OnUpdateCallback | null;
|
|
13
|
+
onClose: OnCloseCallback | null;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export const DEFAULT_STATE: State = {
|
|
15
17
|
isOpen: false,
|
|
16
18
|
id: null,
|
|
17
19
|
onUpdate: null,
|
|
20
|
+
onClose: null,
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
type Action =
|
|
@@ -22,6 +25,7 @@ type Action =
|
|
|
22
25
|
type: 'OPEN_MEDIA_EDITOR_MODAL';
|
|
23
26
|
id: number;
|
|
24
27
|
onUpdate: OnUpdateCallback | null;
|
|
28
|
+
onClose: OnCloseCallback | null;
|
|
25
29
|
}
|
|
26
30
|
| { type: 'CLOSE_MEDIA_EDITOR_MODAL' };
|
|
27
31
|
|
|
@@ -31,7 +35,7 @@ export default function reducer(
|
|
|
31
35
|
): State {
|
|
32
36
|
switch ( action.type ) {
|
|
33
37
|
case 'OPEN_MEDIA_EDITOR_MODAL': {
|
|
34
|
-
const { id, onUpdate } = action as Extract<
|
|
38
|
+
const { id, onUpdate, onClose } = action as Extract<
|
|
35
39
|
Action,
|
|
36
40
|
{ type: 'OPEN_MEDIA_EDITOR_MODAL' }
|
|
37
41
|
>;
|
|
@@ -39,6 +43,7 @@ export default function reducer(
|
|
|
39
43
|
isOpen: true,
|
|
40
44
|
id,
|
|
41
45
|
onUpdate,
|
|
46
|
+
onClose,
|
|
42
47
|
};
|
|
43
48
|
}
|
|
44
49
|
case 'CLOSE_MEDIA_EDITOR_MODAL':
|
package/src/store/selectors.ts
CHANGED
|
@@ -11,35 +11,43 @@ describe( 'core/media-editor reducer', () => {
|
|
|
11
11
|
|
|
12
12
|
it( 'opens the modal with id and onUpdate', () => {
|
|
13
13
|
const onUpdate = jest.fn();
|
|
14
|
+
const onClose = jest.fn();
|
|
14
15
|
const state = reducer( undefined, {
|
|
15
16
|
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
16
17
|
id: 42,
|
|
17
18
|
onUpdate,
|
|
19
|
+
onClose,
|
|
18
20
|
} );
|
|
19
21
|
expect( state ).toEqual( {
|
|
20
22
|
isOpen: true,
|
|
21
23
|
id: 42,
|
|
22
24
|
onUpdate,
|
|
25
|
+
onClose,
|
|
23
26
|
} );
|
|
24
27
|
} );
|
|
25
28
|
|
|
26
29
|
it( 'replaces state on a subsequent open (new onUpdate)', () => {
|
|
27
30
|
const firstOnUpdate = jest.fn();
|
|
31
|
+
const firstOnClose = jest.fn();
|
|
28
32
|
const secondOnUpdate = jest.fn();
|
|
33
|
+
const secondOnClose = jest.fn();
|
|
29
34
|
const first = reducer( undefined, {
|
|
30
35
|
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
31
36
|
id: 42,
|
|
32
37
|
onUpdate: firstOnUpdate,
|
|
38
|
+
onClose: firstOnClose,
|
|
33
39
|
} );
|
|
34
40
|
const second = reducer( first, {
|
|
35
41
|
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
36
42
|
id: 99,
|
|
37
43
|
onUpdate: secondOnUpdate,
|
|
44
|
+
onClose: secondOnClose,
|
|
38
45
|
} );
|
|
39
46
|
expect( second ).toEqual( {
|
|
40
47
|
isOpen: true,
|
|
41
48
|
id: 99,
|
|
42
49
|
onUpdate: secondOnUpdate,
|
|
50
|
+
onClose: secondOnClose,
|
|
43
51
|
} );
|
|
44
52
|
} );
|
|
45
53
|
|
|
@@ -48,6 +56,7 @@ describe( 'core/media-editor reducer', () => {
|
|
|
48
56
|
type: 'OPEN_MEDIA_EDITOR_MODAL',
|
|
49
57
|
id: 42,
|
|
50
58
|
onUpdate: jest.fn(),
|
|
59
|
+
onClose: jest.fn(),
|
|
51
60
|
} );
|
|
52
61
|
const closed = reducer( opened, {
|
|
53
62
|
type: 'CLOSE_MEDIA_EDITOR_MODAL',
|
package/src/style.scss
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
@use "./components/media-editor/style.scss" as *;
|
|
5
5
|
@use "./components/media-editor-modal/style.scss" as *;
|
|
6
6
|
@use "./components/media-editor-canvas/style.scss" as *;
|
|
7
|
-
@use "./components/media-editor-
|
|
7
|
+
@use "./components/media-editor-transform-controls/style.scss" as *;
|
|
8
8
|
@use "./components/media-editor-keyboard-shortcuts-modal/style.scss" as *;
|
|
9
9
|
@use "./components/rotation-ruler/style.scss" as *;
|