@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
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { Button } from '@wordpress/components';
|
|
5
|
-
import { Stack } from '@wordpress/ui';
|
|
6
|
-
import { __ } from '@wordpress/i18n';
|
|
7
|
-
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
|
|
8
|
-
import {
|
|
9
|
-
rotateLeft,
|
|
10
|
-
rotateRight,
|
|
11
|
-
flipHorizontal,
|
|
12
|
-
flipVertical,
|
|
13
|
-
undo,
|
|
14
|
-
redo,
|
|
15
|
-
} from '@wordpress/icons';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
import { useMediaEditor } from '../../state';
|
|
21
|
-
import { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';
|
|
22
|
-
import { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';
|
|
23
|
-
import RotationRuler from '../rotation-ruler';
|
|
24
|
-
|
|
25
|
-
export interface MediaEditorToolbarProps {
|
|
26
|
-
/**
|
|
27
|
-
* Extra work to run when the user clicks Reset — e.g. clearing
|
|
28
|
-
* aspect-ratio / freeform state that lives outside the cropper
|
|
29
|
-
* controller.
|
|
30
|
-
*/
|
|
31
|
-
onReset?: () => void;
|
|
32
|
-
/** Signal that a placement-oriented control is being adjusted. */
|
|
33
|
-
onPlacementControlInteraction?: () => void;
|
|
34
|
-
/** Whether undo/redo should be unavailable during an active gesture. */
|
|
35
|
-
isUndoRedoDisabled?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Toolbar for the media editor modal. Hosts the tactile cropper verbs —
|
|
40
|
-
* rotate, flip, fine rotation, reset — so they stay within thumb reach
|
|
41
|
-
* when the toolbar sits at the bottom of the modal. Aspect-ratio presets
|
|
42
|
-
* and freeform toggle live in the Crop sidebar tab instead.
|
|
43
|
-
* @param props
|
|
44
|
-
* @param props.onReset
|
|
45
|
-
* @param props.onPlacementControlInteraction
|
|
46
|
-
* @param props.isUndoRedoDisabled
|
|
47
|
-
*/
|
|
48
|
-
export default function MediaEditorToolbar( {
|
|
49
|
-
onReset,
|
|
50
|
-
onPlacementControlInteraction,
|
|
51
|
-
isUndoRedoDisabled = false,
|
|
52
|
-
}: MediaEditorToolbarProps ) {
|
|
53
|
-
const {
|
|
54
|
-
state,
|
|
55
|
-
setRotation,
|
|
56
|
-
setFlip,
|
|
57
|
-
snapRotate90,
|
|
58
|
-
reset,
|
|
59
|
-
isDirty,
|
|
60
|
-
hasUndo,
|
|
61
|
-
hasRedo,
|
|
62
|
-
undo: undoCrop,
|
|
63
|
-
redo: redoCrop,
|
|
64
|
-
beginGesture,
|
|
65
|
-
endGesture,
|
|
66
|
-
} = useMediaEditor();
|
|
67
|
-
// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce
|
|
68
|
-
// into one undo entry via the gesture idle window. Pointer-up still
|
|
69
|
-
// closes pointer drags immediately.
|
|
70
|
-
const rotationGestureHandlers = useCropGestureHandlers( {
|
|
71
|
-
commitOnKeyUp: false,
|
|
72
|
-
} );
|
|
73
|
-
|
|
74
|
-
const handleReset = () => {
|
|
75
|
-
beginGesture();
|
|
76
|
-
reset();
|
|
77
|
-
onReset?.();
|
|
78
|
-
endGesture();
|
|
79
|
-
};
|
|
80
|
-
const handleUndo = () => {
|
|
81
|
-
if ( isUndoRedoDisabled ) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
undoCrop();
|
|
85
|
-
};
|
|
86
|
-
const handleRedo = () => {
|
|
87
|
-
if ( isUndoRedoDisabled ) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
redoCrop();
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// `setRotation` is an absolute-angle setter. When a single flip is active
|
|
94
|
-
// the visual direction inverts, so slider input must flip sign to match
|
|
95
|
-
// what the user sees. `snapRotate90` already handles this internally.
|
|
96
|
-
const baseAngle = Math.round( state.rotation / 90 ) * 90;
|
|
97
|
-
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
98
|
-
const visualDir = singleFlip ? -1 : 1;
|
|
99
|
-
const fineOffset = ( state.rotation - baseAngle ) * visualDir;
|
|
100
|
-
|
|
101
|
-
const handleRotationSlider = ( value: number ) => {
|
|
102
|
-
// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a
|
|
103
|
-
// 90° midpoint and flips the derived baseAngle on the next render,
|
|
104
|
-
// causing subsequent events to spiral.
|
|
105
|
-
const EPS = 0.01;
|
|
106
|
-
const clamped = Math.max(
|
|
107
|
-
-MAX_ROTATION_OFFSET + EPS,
|
|
108
|
-
Math.min( MAX_ROTATION_OFFSET - EPS, value )
|
|
109
|
-
);
|
|
110
|
-
onPlacementControlInteraction?.();
|
|
111
|
-
setRotation( baseAngle + clamped * visualDir );
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<Stack
|
|
116
|
-
className="media-editor-toolbar"
|
|
117
|
-
direction="row"
|
|
118
|
-
align="center"
|
|
119
|
-
justify="center"
|
|
120
|
-
gap="sm"
|
|
121
|
-
wrap="wrap"
|
|
122
|
-
>
|
|
123
|
-
<div
|
|
124
|
-
role="presentation"
|
|
125
|
-
className="media-editor-toolbar__rotation-slider"
|
|
126
|
-
{ ...rotationGestureHandlers }
|
|
127
|
-
>
|
|
128
|
-
<RotationRuler
|
|
129
|
-
label={ __( 'Fine rotation' ) }
|
|
130
|
-
min={ -MAX_ROTATION_OFFSET }
|
|
131
|
-
max={ MAX_ROTATION_OFFSET }
|
|
132
|
-
value={ fineOffset }
|
|
133
|
-
onChange={ handleRotationSlider }
|
|
134
|
-
/>
|
|
135
|
-
</div>
|
|
136
|
-
<div className="media-editor-toolbar__action-cluster">
|
|
137
|
-
<Button
|
|
138
|
-
size="compact"
|
|
139
|
-
icon={ rotateLeft }
|
|
140
|
-
label={ __( 'Rotate 90° counter-clockwise' ) }
|
|
141
|
-
showTooltip
|
|
142
|
-
onClick={ () => snapRotate90( -1 ) }
|
|
143
|
-
/>
|
|
144
|
-
<Button
|
|
145
|
-
size="compact"
|
|
146
|
-
icon={ rotateRight }
|
|
147
|
-
label={ __( 'Rotate 90° clockwise' ) }
|
|
148
|
-
showTooltip
|
|
149
|
-
onClick={ () => snapRotate90( 1 ) }
|
|
150
|
-
/>
|
|
151
|
-
<Button
|
|
152
|
-
size="compact"
|
|
153
|
-
icon={ flipHorizontal }
|
|
154
|
-
label={ __( 'Flip horizontal' ) }
|
|
155
|
-
showTooltip
|
|
156
|
-
isPressed={ state.flip.horizontal }
|
|
157
|
-
onClick={ () =>
|
|
158
|
-
setFlip( {
|
|
159
|
-
horizontal: ! state.flip.horizontal,
|
|
160
|
-
vertical: state.flip.vertical,
|
|
161
|
-
} )
|
|
162
|
-
}
|
|
163
|
-
/>
|
|
164
|
-
<Button
|
|
165
|
-
size="compact"
|
|
166
|
-
icon={ flipVertical }
|
|
167
|
-
label={ __( 'Flip vertical' ) }
|
|
168
|
-
showTooltip
|
|
169
|
-
isPressed={ state.flip.vertical }
|
|
170
|
-
onClick={ () =>
|
|
171
|
-
setFlip( {
|
|
172
|
-
horizontal: state.flip.horizontal,
|
|
173
|
-
vertical: ! state.flip.vertical,
|
|
174
|
-
} )
|
|
175
|
-
}
|
|
176
|
-
/>
|
|
177
|
-
<Button
|
|
178
|
-
size="compact"
|
|
179
|
-
icon={ undo }
|
|
180
|
-
label={ __( 'Undo' ) }
|
|
181
|
-
showTooltip
|
|
182
|
-
shortcut={ displayShortcut.primary( 'z' ) }
|
|
183
|
-
disabled={ isUndoRedoDisabled || ! hasUndo }
|
|
184
|
-
accessibleWhenDisabled
|
|
185
|
-
onClick={ handleUndo }
|
|
186
|
-
/>
|
|
187
|
-
<Button
|
|
188
|
-
size="compact"
|
|
189
|
-
icon={ redo }
|
|
190
|
-
label={ __( 'Redo' ) }
|
|
191
|
-
showTooltip
|
|
192
|
-
shortcut={
|
|
193
|
-
isAppleOS()
|
|
194
|
-
? displayShortcut.primaryShift( 'z' )
|
|
195
|
-
: displayShortcut.primary( 'y' )
|
|
196
|
-
}
|
|
197
|
-
disabled={ isUndoRedoDisabled || ! hasRedo }
|
|
198
|
-
accessibleWhenDisabled
|
|
199
|
-
onClick={ handleRedo }
|
|
200
|
-
/>
|
|
201
|
-
<Button
|
|
202
|
-
size="compact"
|
|
203
|
-
variant="tertiary"
|
|
204
|
-
disabled={ ! isDirty }
|
|
205
|
-
accessibleWhenDisabled
|
|
206
|
-
onClick={ handleReset }
|
|
207
|
-
>
|
|
208
|
-
{ __( 'Reset' ) }
|
|
209
|
-
</Button>
|
|
210
|
-
</div>
|
|
211
|
-
</Stack>
|
|
212
|
-
);
|
|
213
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
@use "@wordpress/base-styles/breakpoints" as *;
|
|
2
|
-
@use "@wordpress/base-styles/colors" as *;
|
|
3
|
-
@use "@wordpress/base-styles/variables" as *;
|
|
4
|
-
|
|
5
|
-
.media-editor-toolbar {
|
|
6
|
-
width: 100%;
|
|
7
|
-
padding: $grid-unit-10 $grid-unit-20;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// Two flex items: the fine-rotation slider (left, grows) and the
|
|
11
|
-
// action cluster (right, fixed). At narrow widths each takes a full
|
|
12
|
-
// row with the slider on top.
|
|
13
|
-
.media-editor-toolbar__rotation-slider {
|
|
14
|
-
flex: 1 1 280px;
|
|
15
|
-
min-width: 0;
|
|
16
|
-
max-width: 360px;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.media-editor-toolbar__action-cluster {
|
|
20
|
-
display: flex;
|
|
21
|
-
flex-wrap: nowrap;
|
|
22
|
-
align-items: center;
|
|
23
|
-
gap: $grid-unit-10;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Above break-medium, when the slider and action cluster share a row,
|
|
27
|
-
// divide them with a thin rule. Below the breakpoint they stack — no
|
|
28
|
-
// divider.
|
|
29
|
-
@media (min-width: $break-medium) {
|
|
30
|
-
.media-editor-toolbar__action-cluster {
|
|
31
|
-
border-left: 1px solid $gray-300;
|
|
32
|
-
padding-left: $grid-unit-15;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Below the modal-sidebar full-page breakpoint, force a deterministic
|
|
37
|
-
// two-row layout: slider on top, action cluster beneath. Mirrors the
|
|
38
|
-
// InterfaceSkeleton's own side-by-side → stacked flip at break-medium.
|
|
39
|
-
@media (max-width: #{ $break-medium - 1 }) {
|
|
40
|
-
.media-editor-toolbar__rotation-slider {
|
|
41
|
-
flex-basis: 100%;
|
|
42
|
-
max-width: none;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.media-editor-toolbar__action-cluster {
|
|
46
|
-
flex-basis: 100%;
|
|
47
|
-
justify-content: center;
|
|
48
|
-
}
|
|
49
|
-
}
|