@wordpress/media-editor 0.10.0 → 0.10.1

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.
Files changed (140) hide show
  1. package/build/components/media-editor/index.cjs +185 -42
  2. package/build/components/media-editor/index.cjs.map +3 -3
  3. package/build/components/media-editor/use-crop-options.cjs +2 -26
  4. package/build/components/media-editor/use-crop-options.cjs.map +2 -2
  5. package/build/components/media-editor-canvas/index.cjs +2 -2
  6. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  7. package/build/components/media-editor-crop-panel/index.cjs +24 -21
  8. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  9. package/build/components/media-editor-fine-rotation/index.cjs +81 -0
  10. package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
  11. package/build/components/media-editor-modal/index.cjs +25 -7
  12. package/build/components/media-editor-modal/index.cjs.map +2 -2
  13. package/build/components/media-editor-transform-controls/index.cjs +84 -0
  14. package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
  15. package/build/hooks/use-crop-gesture-handlers.cjs +1 -1
  16. package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
  17. package/build/image-editor/react/components/cropper.cjs +1 -1
  18. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  19. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +1 -1
  20. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  21. package/build/image-editor/react/hooks/use-aria-announcer.cjs +1 -3
  22. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  23. package/build/image-editor/react/hooks/use-interaction.cjs +1 -1
  24. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  25. package/build/state/composite-reducer.cjs +2 -14
  26. package/build/state/composite-reducer.cjs.map +2 -2
  27. package/build/state/types.cjs +1 -2
  28. package/build/state/types.cjs.map +2 -2
  29. package/build/state/use-media-editor-state.cjs +0 -11
  30. package/build/state/use-media-editor-state.cjs.map +2 -2
  31. package/build/store/actions.cjs +4 -2
  32. package/build/store/actions.cjs.map +2 -2
  33. package/build/store/reducer.cjs +5 -3
  34. package/build/store/reducer.cjs.map +2 -2
  35. package/build/store/selectors.cjs +5 -0
  36. package/build/store/selectors.cjs.map +2 -2
  37. package/build-module/components/media-editor/index.mjs +191 -44
  38. package/build-module/components/media-editor/index.mjs.map +2 -2
  39. package/build-module/components/media-editor/use-crop-options.mjs +3 -27
  40. package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
  41. package/build-module/components/media-editor-canvas/index.mjs +2 -2
  42. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  43. package/build-module/components/media-editor-crop-panel/index.mjs +25 -26
  44. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  45. package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
  46. package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
  47. package/build-module/components/media-editor-modal/index.mjs +26 -8
  48. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  49. package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
  50. package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
  51. package/build-module/hooks/use-crop-gesture-handlers.mjs +1 -1
  52. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
  53. package/build-module/image-editor/react/components/cropper.mjs +1 -1
  54. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  55. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +1 -1
  56. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  57. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +1 -3
  58. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  59. package/build-module/image-editor/react/hooks/use-interaction.mjs +1 -1
  60. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  61. package/build-module/state/composite-reducer.mjs +2 -14
  62. package/build-module/state/composite-reducer.mjs.map +2 -2
  63. package/build-module/state/types.mjs +1 -2
  64. package/build-module/state/types.mjs.map +2 -2
  65. package/build-module/state/use-media-editor-state.mjs +0 -11
  66. package/build-module/state/use-media-editor-state.mjs.map +2 -2
  67. package/build-module/store/actions.mjs +4 -2
  68. package/build-module/store/actions.mjs.map +2 -2
  69. package/build-module/store/reducer.mjs +5 -3
  70. package/build-module/store/reducer.mjs.map +2 -2
  71. package/build-module/store/selectors.mjs +4 -0
  72. package/build-module/store/selectors.mjs.map +2 -2
  73. package/build-style/style-rtl.css +51 -35
  74. package/build-style/style.css +51 -35
  75. package/build-types/components/media-editor/index.d.ts +14 -2
  76. package/build-types/components/media-editor/index.d.ts.map +1 -1
  77. package/build-types/components/media-editor/use-crop-options.d.ts +3 -5
  78. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  79. package/build-types/components/media-editor-crop-panel/index.d.ts +3 -10
  80. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  81. package/build-types/components/media-editor-fine-rotation/index.d.ts +14 -0
  82. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
  83. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  84. package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
  85. package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
  86. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
  87. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  88. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  89. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  90. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  91. package/build-types/state/composite-reducer.d.ts.map +1 -1
  92. package/build-types/state/types.d.ts +3 -11
  93. package/build-types/state/types.d.ts.map +1 -1
  94. package/build-types/state/use-media-editor-state.d.ts +2 -5
  95. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  96. package/build-types/store/actions.d.ts +3 -1
  97. package/build-types/store/actions.d.ts.map +1 -1
  98. package/build-types/store/reducer.d.ts +3 -0
  99. package/build-types/store/reducer.d.ts.map +1 -1
  100. package/build-types/store/selectors.d.ts +1 -0
  101. package/build-types/store/selectors.d.ts.map +1 -1
  102. package/package.json +20 -19
  103. package/src/components/media-editor/index.tsx +226 -57
  104. package/src/components/media-editor/style.scss +0 -9
  105. package/src/components/media-editor/test/use-crop-options.tsx +1 -55
  106. package/src/components/media-editor/use-crop-options.ts +6 -42
  107. package/src/components/media-editor-canvas/index.tsx +2 -2
  108. package/src/components/media-editor-crop-panel/index.tsx +35 -33
  109. package/src/components/media-editor-crop-panel/test/index.tsx +39 -20
  110. package/src/components/media-editor-fine-rotation/index.tsx +74 -0
  111. package/src/components/media-editor-modal/index.tsx +20 -4
  112. package/src/components/media-editor-modal/style.scss +80 -0
  113. package/src/components/media-editor-modal/test/index.tsx +3 -0
  114. package/src/components/media-editor-transform-controls/index.tsx +70 -0
  115. package/src/components/media-editor-transform-controls/style.scss +8 -0
  116. package/src/hooks/use-crop-gesture-handlers.ts +1 -3
  117. package/src/image-editor/docs/recipes.md +2 -2
  118. package/src/image-editor/react/components/cropper.tsx +1 -3
  119. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +1 -3
  120. package/src/image-editor/react/hooks/use-aria-announcer.ts +1 -3
  121. package/src/image-editor/react/hooks/use-interaction.ts +2 -3
  122. package/src/state/composite-reducer.ts +2 -17
  123. package/src/state/test/use-media-editor-state.ts +3 -75
  124. package/src/state/types.ts +3 -9
  125. package/src/state/use-media-editor-state.ts +3 -19
  126. package/src/store/actions.ts +3 -0
  127. package/src/store/reducer.ts +6 -1
  128. package/src/store/selectors.ts +4 -0
  129. package/src/store/test/reducer.ts +9 -0
  130. package/src/style.scss +1 -1
  131. package/tsconfig.json +1 -0
  132. package/tsconfig.tsbuildinfo +1 -1
  133. package/build/components/media-editor-toolbar/index.cjs +0 -218
  134. package/build/components/media-editor-toolbar/index.cjs.map +0 -7
  135. package/build-module/components/media-editor-toolbar/index.mjs +0 -194
  136. package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
  137. package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
  138. package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
  139. package/src/components/media-editor-toolbar/index.tsx +0 -213
  140. 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
- }