@wordpress/media-editor 0.18.0 → 0.19.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 +7 -0
- package/README.md +7 -7
- package/build/components/media-editor/index.cjs.map +2 -2
- package/build/components/media-editor/use-save-media-editor.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/setter-helpers.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/setter-helpers.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +2 -2
- package/build-style/style-rtl.css +21 -22
- package/build-style/style.css +6 -0
- package/global.d.ts +0 -1
- package/package.json +23 -24
- package/src/components/media-editor/index.tsx +2 -2
- package/src/components/media-editor/use-save-media-editor.ts +5 -5
- package/src/components/media-editor-crop-panel/index.tsx +2 -2
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +7 -7
- package/src/components/rotation-ruler/stories/index.story.tsx +2 -2
- package/src/components/rotation-ruler/style.scss +9 -0
- package/src/image-editor/core/interaction-controller.ts +2 -2
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/react/components/cropper.scss +6 -0
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +1 -1
- package/src/image-editor/react/components/stencils/test/{rectangle-stencil.jsdom.test.tsx → rectangle-stencil.browser.test.tsx} +80 -98
- package/src/image-editor/react/components/test/{cropper.jsdom.test.tsx → cropper.browser.test.tsx} +230 -221
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +1 -1
- package/src/image-editor/stories/rectangle-crop.story.tsx +24 -23
- package/src/image-editor/stories/{style.css → style.module.css} +8 -37
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +1 -2
|
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
|
2
2
|
import { useState, useCallback, useEffect, useRef } from '@wordpress/element';
|
|
3
3
|
import {
|
|
4
4
|
Button,
|
|
5
|
-
SelectControl,
|
|
5
|
+
SelectControl as WCSelectControl,
|
|
6
6
|
RangeControl,
|
|
7
7
|
ToggleControl,
|
|
8
8
|
Flex,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
getVisibleBounds,
|
|
41
41
|
} from '../core/camera';
|
|
42
42
|
import { getSourceRegion } from '../core/source-region';
|
|
43
|
-
import './style.css';
|
|
43
|
+
import styles from './style.module.css';
|
|
44
44
|
|
|
45
45
|
const SAMPLE_IMAGE = 'image-editor-demo.jpeg';
|
|
46
46
|
|
|
@@ -118,7 +118,8 @@ function resolveAspectRatio(
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
const meta: Meta< typeof Cropper > = {
|
|
121
|
-
|
|
121
|
+
id: 'mediaeditor-imageeditor',
|
|
122
|
+
title: 'Editor/Media Editor/ImageEditor',
|
|
122
123
|
component: Cropper,
|
|
123
124
|
tags: [ 'status-experimental' ],
|
|
124
125
|
};
|
|
@@ -135,7 +136,7 @@ const DefaultComponent = () => {
|
|
|
135
136
|
|
|
136
137
|
return (
|
|
137
138
|
<div>
|
|
138
|
-
<div className=
|
|
139
|
+
<div className={ styles.container }>
|
|
139
140
|
<Cropper
|
|
140
141
|
src={ SAMPLE_IMAGE }
|
|
141
142
|
controller={ controller }
|
|
@@ -198,7 +199,7 @@ const WithControlsComponent = () => {
|
|
|
198
199
|
? getSourceRegion( state, {
|
|
199
200
|
width: state.image.naturalWidth,
|
|
200
201
|
height: state.image.naturalHeight,
|
|
201
|
-
|
|
202
|
+
} )
|
|
202
203
|
: null;
|
|
203
204
|
|
|
204
205
|
// The base cardinal angle (nearest 90° step) and the fine offset.
|
|
@@ -320,9 +321,9 @@ const WithControlsComponent = () => {
|
|
|
320
321
|
type="file"
|
|
321
322
|
accept="image/*"
|
|
322
323
|
onChange={ handleFileChange }
|
|
323
|
-
className=
|
|
324
|
+
className={ styles[ 'hidden-file' ] }
|
|
324
325
|
/>
|
|
325
|
-
<div className=
|
|
326
|
+
<div className={ styles.toolbar }>
|
|
326
327
|
<Flex align="center" gap={ 2 } wrap>
|
|
327
328
|
<FlexItem>
|
|
328
329
|
<Button
|
|
@@ -388,7 +389,7 @@ const WithControlsComponent = () => {
|
|
|
388
389
|
/>
|
|
389
390
|
</FlexItem>
|
|
390
391
|
<FlexItem>
|
|
391
|
-
<
|
|
392
|
+
<WCSelectControl
|
|
392
393
|
label="Aspect ratio"
|
|
393
394
|
hideLabelFromVision
|
|
394
395
|
value={ aspectRatioValue }
|
|
@@ -409,7 +410,7 @@ const WithControlsComponent = () => {
|
|
|
409
410
|
/>
|
|
410
411
|
</FlexItem>
|
|
411
412
|
<FlexItem>
|
|
412
|
-
<
|
|
413
|
+
<WCSelectControl
|
|
413
414
|
label="Grid"
|
|
414
415
|
hideLabelFromVision
|
|
415
416
|
value={ gridMode }
|
|
@@ -440,7 +441,7 @@ const WithControlsComponent = () => {
|
|
|
440
441
|
</Button>
|
|
441
442
|
</FlexItem>
|
|
442
443
|
</Flex>
|
|
443
|
-
<div className=
|
|
444
|
+
<div className={ styles.sliders }>
|
|
444
445
|
<RangeControl
|
|
445
446
|
label="Fine rotation"
|
|
446
447
|
min={ -MAX_ROTATION_OFFSET }
|
|
@@ -460,7 +461,7 @@ const WithControlsComponent = () => {
|
|
|
460
461
|
</div>
|
|
461
462
|
</div>
|
|
462
463
|
|
|
463
|
-
<div className=
|
|
464
|
+
<div className={ styles.resizable }>
|
|
464
465
|
<Cropper
|
|
465
466
|
src={ src }
|
|
466
467
|
controller={ controller }
|
|
@@ -491,7 +492,7 @@ const WithControlsComponent = () => {
|
|
|
491
492
|
|
|
492
493
|
<div style={ { marginTop: 16 } }>
|
|
493
494
|
<strong>Current State:</strong>
|
|
494
|
-
<pre className=
|
|
495
|
+
<pre className={ styles.state }>
|
|
495
496
|
{ JSON.stringify(
|
|
496
497
|
{
|
|
497
498
|
rotation: state.rotation,
|
|
@@ -503,7 +504,7 @@ const WithControlsComponent = () => {
|
|
|
503
504
|
naturalWidth: state.image.naturalWidth,
|
|
504
505
|
naturalHeight:
|
|
505
506
|
state.image.naturalHeight,
|
|
506
|
-
|
|
507
|
+
}
|
|
507
508
|
: null,
|
|
508
509
|
},
|
|
509
510
|
null,
|
|
@@ -615,7 +616,7 @@ const DebugComponent = () => {
|
|
|
615
616
|
: {
|
|
616
617
|
elementSize: { width: 0, height: 0 },
|
|
617
618
|
visualSize: { width: 0, height: 0 },
|
|
618
|
-
|
|
619
|
+
};
|
|
619
620
|
|
|
620
621
|
// Camera and restriction.
|
|
621
622
|
const camera = hasImage
|
|
@@ -626,7 +627,7 @@ const DebugComponent = () => {
|
|
|
626
627
|
{ ...state, pan: { x: 0, y: 0 }, zoom: 1 },
|
|
627
628
|
containerSize,
|
|
628
629
|
imageSize
|
|
629
|
-
|
|
630
|
+
)
|
|
630
631
|
: null;
|
|
631
632
|
const vb = baseCamera ? getVisibleBounds( baseCamera ) : null;
|
|
632
633
|
|
|
@@ -648,7 +649,7 @@ const DebugComponent = () => {
|
|
|
648
649
|
( state.cropRect.y + state.cropRect.height ) *
|
|
649
650
|
vb.height,
|
|
650
651
|
} ),
|
|
651
|
-
|
|
652
|
+
]
|
|
652
653
|
: null;
|
|
653
654
|
|
|
654
655
|
// Restriction result.
|
|
@@ -737,9 +738,9 @@ const DebugComponent = () => {
|
|
|
737
738
|
type="file"
|
|
738
739
|
accept="image/*"
|
|
739
740
|
onChange={ handleFileChange }
|
|
740
|
-
className=
|
|
741
|
+
className={ styles[ 'hidden-file' ] }
|
|
741
742
|
/>
|
|
742
|
-
<div className=
|
|
743
|
+
<div className={ styles.toolbar }>
|
|
743
744
|
<Flex align="center" gap={ 2 } wrap>
|
|
744
745
|
<FlexItem>
|
|
745
746
|
<Button
|
|
@@ -825,7 +826,7 @@ const DebugComponent = () => {
|
|
|
825
826
|
</Button>
|
|
826
827
|
</FlexItem>
|
|
827
828
|
<FlexItem>
|
|
828
|
-
<
|
|
829
|
+
<WCSelectControl
|
|
829
830
|
label="Format"
|
|
830
831
|
hideLabelFromVision
|
|
831
832
|
value={ exportFormat as 'image/jpeg' }
|
|
@@ -858,7 +859,7 @@ const DebugComponent = () => {
|
|
|
858
859
|
</Button>
|
|
859
860
|
</FlexItem>
|
|
860
861
|
</Flex>
|
|
861
|
-
<div className=
|
|
862
|
+
<div className={ styles.sliders }>
|
|
862
863
|
<RangeControl
|
|
863
864
|
label="Fine rotation"
|
|
864
865
|
min={ -MAX_ROTATION_OFFSET }
|
|
@@ -885,7 +886,7 @@ const DebugComponent = () => {
|
|
|
885
886
|
ref={ containerRef }
|
|
886
887
|
style={ { flex: '1 1 60%', minWidth: 0 } }
|
|
887
888
|
>
|
|
888
|
-
<div className=
|
|
889
|
+
<div className={ styles.container }>
|
|
889
890
|
<Cropper
|
|
890
891
|
src={ src }
|
|
891
892
|
controller={ controller }
|
|
@@ -907,10 +908,10 @@ const DebugComponent = () => {
|
|
|
907
908
|
maxHeight: 500,
|
|
908
909
|
} }
|
|
909
910
|
>
|
|
910
|
-
<div className=
|
|
911
|
+
<div className={ styles[ 'export-preview' ] }>
|
|
911
912
|
{ previewSrc ? (
|
|
912
913
|
<img
|
|
913
|
-
className=
|
|
914
|
+
className={ styles[ 'export-image' ] }
|
|
914
915
|
src={ previewSrc }
|
|
915
916
|
alt="Crop preview"
|
|
916
917
|
/>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.
|
|
1
|
+
.container {
|
|
2
2
|
width: 100%;
|
|
3
3
|
max-width: 600px;
|
|
4
4
|
aspect-ratio: 3 / 2;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
position: relative;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
.
|
|
9
|
+
.resizable {
|
|
10
10
|
width: 600px;
|
|
11
11
|
height: 400px;
|
|
12
12
|
max-width: 100%;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
position: relative;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
.
|
|
21
|
+
.toolbar {
|
|
22
22
|
display: flex;
|
|
23
23
|
flex-direction: column;
|
|
24
24
|
gap: 12px;
|
|
@@ -29,25 +29,18 @@
|
|
|
29
29
|
background: #fafafa;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
.
|
|
32
|
+
.sliders {
|
|
33
33
|
display: grid;
|
|
34
34
|
grid-template-columns: 1fr 1fr;
|
|
35
35
|
gap: 16px;
|
|
36
36
|
padding: 0 4px;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
.
|
|
39
|
+
.hidden-file {
|
|
40
40
|
display: none;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
.
|
|
44
|
-
width: 100%;
|
|
45
|
-
min-height: 80px;
|
|
46
|
-
font-family: monospace;
|
|
47
|
-
font-size: 12px;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.image-editor-story__state {
|
|
43
|
+
.state {
|
|
51
44
|
font-family: monospace;
|
|
52
45
|
font-size: 11px;
|
|
53
46
|
background: #f5f5f5;
|
|
@@ -58,34 +51,12 @@
|
|
|
58
51
|
overflow: auto;
|
|
59
52
|
}
|
|
60
53
|
|
|
61
|
-
.
|
|
62
|
-
font-variant-numeric: tabular-nums;
|
|
63
|
-
min-width: 120px;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.image-editor-story__instructions {
|
|
67
|
-
background: #f9f9f9;
|
|
68
|
-
border: 1px solid #e0e0e0;
|
|
69
|
-
border-radius: 4px;
|
|
70
|
-
padding: 12px;
|
|
71
|
-
font-size: 13px;
|
|
72
|
-
line-height: 1.5;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.image-editor-story__instructions p {
|
|
76
|
-
margin: 0 0 4px;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
.image-editor-story__instructions p:last-child {
|
|
80
|
-
margin-bottom: 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.image-editor-story__export-preview {
|
|
54
|
+
.export-preview {
|
|
84
55
|
margin-bottom: 16px;
|
|
85
56
|
max-width: 200px;
|
|
86
57
|
}
|
|
87
58
|
|
|
88
|
-
.
|
|
59
|
+
.export-image {
|
|
89
60
|
display: block;
|
|
90
61
|
max-width: 100%;
|
|
91
62
|
border: 1px solid #ccc;
|
package/tsconfig.build.json
CHANGED