@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.
- 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,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/media-editor/src/components/media-editor-toolbar/index.tsx
|
|
31
|
-
var media_editor_toolbar_exports = {};
|
|
32
|
-
__export(media_editor_toolbar_exports, {
|
|
33
|
-
default: () => MediaEditorToolbar
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(media_editor_toolbar_exports);
|
|
36
|
-
var import_components = require("@wordpress/components");
|
|
37
|
-
var import_ui = require("@wordpress/ui");
|
|
38
|
-
var import_i18n = require("@wordpress/i18n");
|
|
39
|
-
var import_keycodes = require("@wordpress/keycodes");
|
|
40
|
-
var import_icons = require("@wordpress/icons");
|
|
41
|
-
var import_state = require("../../state/index.cjs");
|
|
42
|
-
var import_use_crop_gesture_handlers = require("../../hooks/use-crop-gesture-handlers.cjs");
|
|
43
|
-
var import_constants = require("../../image-editor/core/constants.cjs");
|
|
44
|
-
var import_rotation_ruler = __toESM(require("../rotation-ruler/index.cjs"));
|
|
45
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
-
function MediaEditorToolbar({
|
|
47
|
-
onReset,
|
|
48
|
-
onPlacementControlInteraction,
|
|
49
|
-
isUndoRedoDisabled = false
|
|
50
|
-
}) {
|
|
51
|
-
const {
|
|
52
|
-
state,
|
|
53
|
-
setRotation,
|
|
54
|
-
setFlip,
|
|
55
|
-
snapRotate90,
|
|
56
|
-
reset,
|
|
57
|
-
isDirty,
|
|
58
|
-
hasUndo,
|
|
59
|
-
hasRedo,
|
|
60
|
-
undo: undoCrop,
|
|
61
|
-
redo: redoCrop,
|
|
62
|
-
beginGesture,
|
|
63
|
-
endGesture
|
|
64
|
-
} = (0, import_state.useMediaEditor)();
|
|
65
|
-
const rotationGestureHandlers = (0, import_use_crop_gesture_handlers.useCropGestureHandlers)({
|
|
66
|
-
commitOnKeyUp: false
|
|
67
|
-
});
|
|
68
|
-
const handleReset = () => {
|
|
69
|
-
beginGesture();
|
|
70
|
-
reset();
|
|
71
|
-
onReset?.();
|
|
72
|
-
endGesture();
|
|
73
|
-
};
|
|
74
|
-
const handleUndo = () => {
|
|
75
|
-
if (isUndoRedoDisabled) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
undoCrop();
|
|
79
|
-
};
|
|
80
|
-
const handleRedo = () => {
|
|
81
|
-
if (isUndoRedoDisabled) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
redoCrop();
|
|
85
|
-
};
|
|
86
|
-
const baseAngle = Math.round(state.rotation / 90) * 90;
|
|
87
|
-
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
88
|
-
const visualDir = singleFlip ? -1 : 1;
|
|
89
|
-
const fineOffset = (state.rotation - baseAngle) * visualDir;
|
|
90
|
-
const handleRotationSlider = (value) => {
|
|
91
|
-
const EPS = 0.01;
|
|
92
|
-
const clamped = Math.max(
|
|
93
|
-
-import_constants.MAX_ROTATION_OFFSET + EPS,
|
|
94
|
-
Math.min(import_constants.MAX_ROTATION_OFFSET - EPS, value)
|
|
95
|
-
);
|
|
96
|
-
onPlacementControlInteraction?.();
|
|
97
|
-
setRotation(baseAngle + clamped * visualDir);
|
|
98
|
-
};
|
|
99
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
100
|
-
import_ui.Stack,
|
|
101
|
-
{
|
|
102
|
-
className: "media-editor-toolbar",
|
|
103
|
-
direction: "row",
|
|
104
|
-
align: "center",
|
|
105
|
-
justify: "center",
|
|
106
|
-
gap: "sm",
|
|
107
|
-
wrap: "wrap",
|
|
108
|
-
children: [
|
|
109
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
110
|
-
"div",
|
|
111
|
-
{
|
|
112
|
-
role: "presentation",
|
|
113
|
-
className: "media-editor-toolbar__rotation-slider",
|
|
114
|
-
...rotationGestureHandlers,
|
|
115
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
116
|
-
import_rotation_ruler.default,
|
|
117
|
-
{
|
|
118
|
-
label: (0, import_i18n.__)("Fine rotation"),
|
|
119
|
-
min: -import_constants.MAX_ROTATION_OFFSET,
|
|
120
|
-
max: import_constants.MAX_ROTATION_OFFSET,
|
|
121
|
-
value: fineOffset,
|
|
122
|
-
onChange: handleRotationSlider
|
|
123
|
-
}
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
),
|
|
127
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-toolbar__action-cluster", children: [
|
|
128
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
129
|
-
import_components.Button,
|
|
130
|
-
{
|
|
131
|
-
size: "compact",
|
|
132
|
-
icon: import_icons.rotateLeft,
|
|
133
|
-
label: (0, import_i18n.__)("Rotate 90\xB0 counter-clockwise"),
|
|
134
|
-
showTooltip: true,
|
|
135
|
-
onClick: () => snapRotate90(-1)
|
|
136
|
-
}
|
|
137
|
-
),
|
|
138
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
139
|
-
import_components.Button,
|
|
140
|
-
{
|
|
141
|
-
size: "compact",
|
|
142
|
-
icon: import_icons.rotateRight,
|
|
143
|
-
label: (0, import_i18n.__)("Rotate 90\xB0 clockwise"),
|
|
144
|
-
showTooltip: true,
|
|
145
|
-
onClick: () => snapRotate90(1)
|
|
146
|
-
}
|
|
147
|
-
),
|
|
148
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
149
|
-
import_components.Button,
|
|
150
|
-
{
|
|
151
|
-
size: "compact",
|
|
152
|
-
icon: import_icons.flipHorizontal,
|
|
153
|
-
label: (0, import_i18n.__)("Flip horizontal"),
|
|
154
|
-
showTooltip: true,
|
|
155
|
-
isPressed: state.flip.horizontal,
|
|
156
|
-
onClick: () => setFlip({
|
|
157
|
-
horizontal: !state.flip.horizontal,
|
|
158
|
-
vertical: state.flip.vertical
|
|
159
|
-
})
|
|
160
|
-
}
|
|
161
|
-
),
|
|
162
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
163
|
-
import_components.Button,
|
|
164
|
-
{
|
|
165
|
-
size: "compact",
|
|
166
|
-
icon: import_icons.flipVertical,
|
|
167
|
-
label: (0, import_i18n.__)("Flip vertical"),
|
|
168
|
-
showTooltip: true,
|
|
169
|
-
isPressed: state.flip.vertical,
|
|
170
|
-
onClick: () => setFlip({
|
|
171
|
-
horizontal: state.flip.horizontal,
|
|
172
|
-
vertical: !state.flip.vertical
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
),
|
|
176
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
177
|
-
import_components.Button,
|
|
178
|
-
{
|
|
179
|
-
size: "compact",
|
|
180
|
-
icon: import_icons.undo,
|
|
181
|
-
label: (0, import_i18n.__)("Undo"),
|
|
182
|
-
showTooltip: true,
|
|
183
|
-
shortcut: import_keycodes.displayShortcut.primary("z"),
|
|
184
|
-
disabled: isUndoRedoDisabled || !hasUndo,
|
|
185
|
-
accessibleWhenDisabled: true,
|
|
186
|
-
onClick: handleUndo
|
|
187
|
-
}
|
|
188
|
-
),
|
|
189
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
190
|
-
import_components.Button,
|
|
191
|
-
{
|
|
192
|
-
size: "compact",
|
|
193
|
-
icon: import_icons.redo,
|
|
194
|
-
label: (0, import_i18n.__)("Redo"),
|
|
195
|
-
showTooltip: true,
|
|
196
|
-
shortcut: (0, import_keycodes.isAppleOS)() ? import_keycodes.displayShortcut.primaryShift("z") : import_keycodes.displayShortcut.primary("y"),
|
|
197
|
-
disabled: isUndoRedoDisabled || !hasRedo,
|
|
198
|
-
accessibleWhenDisabled: true,
|
|
199
|
-
onClick: handleRedo
|
|
200
|
-
}
|
|
201
|
-
),
|
|
202
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
203
|
-
import_components.Button,
|
|
204
|
-
{
|
|
205
|
-
size: "compact",
|
|
206
|
-
variant: "tertiary",
|
|
207
|
-
disabled: !isDirty,
|
|
208
|
-
accessibleWhenDisabled: true,
|
|
209
|
-
onClick: handleReset,
|
|
210
|
-
children: (0, import_i18n.__)("Reset")
|
|
211
|
-
}
|
|
212
|
-
)
|
|
213
|
-
] })
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-toolbar/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { displayShortcut, isAppleOS } from '@wordpress/keycodes';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tundo,\n\tredo,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorToolbarProps {\n\t/**\n\t * Extra work to run when the user clicks Reset \u2014 e.g. clearing\n\t * aspect-ratio / freeform state that lives outside the cropper\n\t * controller.\n\t */\n\tonReset?: () => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/** Whether undo/redo should be unavailable during an active gesture. */\n\tisUndoRedoDisabled?: boolean;\n}\n\n/**\n * Toolbar for the media editor modal. Hosts the tactile cropper verbs \u2014\n * rotate, flip, fine rotation, reset \u2014 so they stay within thumb reach\n * when the toolbar sits at the bottom of the modal. Aspect-ratio presets\n * and freeform toggle live in the Crop sidebar tab instead.\n * @param props\n * @param props.onReset\n * @param props.onPlacementControlInteraction\n * @param props.isUndoRedoDisabled\n */\nexport default function MediaEditorToolbar( {\n\tonReset,\n\tonPlacementControlInteraction,\n\tisUndoRedoDisabled = false,\n}: MediaEditorToolbarProps ) {\n\tconst {\n\t\tstate,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\tsnapRotate90,\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t\tbeginGesture,\n\t\tendGesture,\n\t} = useMediaEditor();\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\tconst handleReset = () => {\n\t\tbeginGesture();\n\t\treset();\n\t\tonReset?.();\n\t\tendGesture();\n\t};\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly \u00B1MAX lands state on a\n\t\t// 90\u00B0 midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor-toolbar\"\n\t\t\tdirection=\"row\"\n\t\t\talign=\"center\"\n\t\t\tjustify=\"center\"\n\t\t\tgap=\"sm\"\n\t\t\twrap=\"wrap\"\n\t\t>\n\t\t\t<div\n\t\t\t\trole=\"presentation\"\n\t\t\t\tclassName=\"media-editor-toolbar__rotation-slider\"\n\t\t\t\t{ ...rotationGestureHandlers }\n\t\t\t>\n\t\t\t\t<RotationRuler\n\t\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\t\tvalue={ fineOffset }\n\t\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"media-editor-toolbar__action-cluster\">\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateLeft }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateRight }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipHorizontal }\n\t\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipVertical }\n\t\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ undo }\n\t\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleUndo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ redo }\n\t\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={\n\t\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t\t}\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleRedo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! isDirty }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleReset }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t</Stack>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AACvB,gBAAsB;AACtB,kBAAmB;AACnB,sBAA2C;AAC3C,mBAOO;AAKP,mBAA+B;AAC/B,uCAAuC;AACvC,uBAAoC;AACpC,4BAA0B;AAyGtB;AAh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CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,WAAQ,gBAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,cACC,2BAAU,IACP,gCAAgB,aAAc,GAAI,IAClC,gCAAgB,QAAS,GAAI;AAAA,cAEjC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,SAAQ;AAAA,cACR,UAAW,CAAE;AAAA,cACb,wBAAsB;AAAA,cACtB,SAAU;AAAA,cAER,8BAAI,OAAQ;AAAA;AAAA,UACf;AAAA,WACD;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
-
"names": ["RotationRuler"]
|
|
7
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// packages/media-editor/src/components/media-editor-toolbar/index.tsx
|
|
2
|
-
import { Button } from "@wordpress/components";
|
|
3
|
-
import { Stack } from "@wordpress/ui";
|
|
4
|
-
import { __ } from "@wordpress/i18n";
|
|
5
|
-
import { displayShortcut, isAppleOS } from "@wordpress/keycodes";
|
|
6
|
-
import {
|
|
7
|
-
rotateLeft,
|
|
8
|
-
rotateRight,
|
|
9
|
-
flipHorizontal,
|
|
10
|
-
flipVertical,
|
|
11
|
-
undo,
|
|
12
|
-
redo
|
|
13
|
-
} from "@wordpress/icons";
|
|
14
|
-
import { useMediaEditor } from "../../state/index.mjs";
|
|
15
|
-
import { useCropGestureHandlers } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
16
|
-
import { MAX_ROTATION_OFFSET } from "../../image-editor/core/constants.mjs";
|
|
17
|
-
import RotationRuler from "../rotation-ruler/index.mjs";
|
|
18
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
-
function MediaEditorToolbar({
|
|
20
|
-
onReset,
|
|
21
|
-
onPlacementControlInteraction,
|
|
22
|
-
isUndoRedoDisabled = false
|
|
23
|
-
}) {
|
|
24
|
-
const {
|
|
25
|
-
state,
|
|
26
|
-
setRotation,
|
|
27
|
-
setFlip,
|
|
28
|
-
snapRotate90,
|
|
29
|
-
reset,
|
|
30
|
-
isDirty,
|
|
31
|
-
hasUndo,
|
|
32
|
-
hasRedo,
|
|
33
|
-
undo: undoCrop,
|
|
34
|
-
redo: redoCrop,
|
|
35
|
-
beginGesture,
|
|
36
|
-
endGesture
|
|
37
|
-
} = useMediaEditor();
|
|
38
|
-
const rotationGestureHandlers = useCropGestureHandlers({
|
|
39
|
-
commitOnKeyUp: false
|
|
40
|
-
});
|
|
41
|
-
const handleReset = () => {
|
|
42
|
-
beginGesture();
|
|
43
|
-
reset();
|
|
44
|
-
onReset?.();
|
|
45
|
-
endGesture();
|
|
46
|
-
};
|
|
47
|
-
const handleUndo = () => {
|
|
48
|
-
if (isUndoRedoDisabled) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
undoCrop();
|
|
52
|
-
};
|
|
53
|
-
const handleRedo = () => {
|
|
54
|
-
if (isUndoRedoDisabled) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
redoCrop();
|
|
58
|
-
};
|
|
59
|
-
const baseAngle = Math.round(state.rotation / 90) * 90;
|
|
60
|
-
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
61
|
-
const visualDir = singleFlip ? -1 : 1;
|
|
62
|
-
const fineOffset = (state.rotation - baseAngle) * visualDir;
|
|
63
|
-
const handleRotationSlider = (value) => {
|
|
64
|
-
const EPS = 0.01;
|
|
65
|
-
const clamped = Math.max(
|
|
66
|
-
-MAX_ROTATION_OFFSET + EPS,
|
|
67
|
-
Math.min(MAX_ROTATION_OFFSET - EPS, value)
|
|
68
|
-
);
|
|
69
|
-
onPlacementControlInteraction?.();
|
|
70
|
-
setRotation(baseAngle + clamped * visualDir);
|
|
71
|
-
};
|
|
72
|
-
return /* @__PURE__ */ jsxs(
|
|
73
|
-
Stack,
|
|
74
|
-
{
|
|
75
|
-
className: "media-editor-toolbar",
|
|
76
|
-
direction: "row",
|
|
77
|
-
align: "center",
|
|
78
|
-
justify: "center",
|
|
79
|
-
gap: "sm",
|
|
80
|
-
wrap: "wrap",
|
|
81
|
-
children: [
|
|
82
|
-
/* @__PURE__ */ jsx(
|
|
83
|
-
"div",
|
|
84
|
-
{
|
|
85
|
-
role: "presentation",
|
|
86
|
-
className: "media-editor-toolbar__rotation-slider",
|
|
87
|
-
...rotationGestureHandlers,
|
|
88
|
-
children: /* @__PURE__ */ jsx(
|
|
89
|
-
RotationRuler,
|
|
90
|
-
{
|
|
91
|
-
label: __("Fine rotation"),
|
|
92
|
-
min: -MAX_ROTATION_OFFSET,
|
|
93
|
-
max: MAX_ROTATION_OFFSET,
|
|
94
|
-
value: fineOffset,
|
|
95
|
-
onChange: handleRotationSlider
|
|
96
|
-
}
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
),
|
|
100
|
-
/* @__PURE__ */ jsxs("div", { className: "media-editor-toolbar__action-cluster", children: [
|
|
101
|
-
/* @__PURE__ */ jsx(
|
|
102
|
-
Button,
|
|
103
|
-
{
|
|
104
|
-
size: "compact",
|
|
105
|
-
icon: rotateLeft,
|
|
106
|
-
label: __("Rotate 90\xB0 counter-clockwise"),
|
|
107
|
-
showTooltip: true,
|
|
108
|
-
onClick: () => snapRotate90(-1)
|
|
109
|
-
}
|
|
110
|
-
),
|
|
111
|
-
/* @__PURE__ */ jsx(
|
|
112
|
-
Button,
|
|
113
|
-
{
|
|
114
|
-
size: "compact",
|
|
115
|
-
icon: rotateRight,
|
|
116
|
-
label: __("Rotate 90\xB0 clockwise"),
|
|
117
|
-
showTooltip: true,
|
|
118
|
-
onClick: () => snapRotate90(1)
|
|
119
|
-
}
|
|
120
|
-
),
|
|
121
|
-
/* @__PURE__ */ jsx(
|
|
122
|
-
Button,
|
|
123
|
-
{
|
|
124
|
-
size: "compact",
|
|
125
|
-
icon: flipHorizontal,
|
|
126
|
-
label: __("Flip horizontal"),
|
|
127
|
-
showTooltip: true,
|
|
128
|
-
isPressed: state.flip.horizontal,
|
|
129
|
-
onClick: () => setFlip({
|
|
130
|
-
horizontal: !state.flip.horizontal,
|
|
131
|
-
vertical: state.flip.vertical
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
),
|
|
135
|
-
/* @__PURE__ */ jsx(
|
|
136
|
-
Button,
|
|
137
|
-
{
|
|
138
|
-
size: "compact",
|
|
139
|
-
icon: flipVertical,
|
|
140
|
-
label: __("Flip vertical"),
|
|
141
|
-
showTooltip: true,
|
|
142
|
-
isPressed: state.flip.vertical,
|
|
143
|
-
onClick: () => setFlip({
|
|
144
|
-
horizontal: state.flip.horizontal,
|
|
145
|
-
vertical: !state.flip.vertical
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
),
|
|
149
|
-
/* @__PURE__ */ jsx(
|
|
150
|
-
Button,
|
|
151
|
-
{
|
|
152
|
-
size: "compact",
|
|
153
|
-
icon: undo,
|
|
154
|
-
label: __("Undo"),
|
|
155
|
-
showTooltip: true,
|
|
156
|
-
shortcut: displayShortcut.primary("z"),
|
|
157
|
-
disabled: isUndoRedoDisabled || !hasUndo,
|
|
158
|
-
accessibleWhenDisabled: true,
|
|
159
|
-
onClick: handleUndo
|
|
160
|
-
}
|
|
161
|
-
),
|
|
162
|
-
/* @__PURE__ */ jsx(
|
|
163
|
-
Button,
|
|
164
|
-
{
|
|
165
|
-
size: "compact",
|
|
166
|
-
icon: redo,
|
|
167
|
-
label: __("Redo"),
|
|
168
|
-
showTooltip: true,
|
|
169
|
-
shortcut: isAppleOS() ? displayShortcut.primaryShift("z") : displayShortcut.primary("y"),
|
|
170
|
-
disabled: isUndoRedoDisabled || !hasRedo,
|
|
171
|
-
accessibleWhenDisabled: true,
|
|
172
|
-
onClick: handleRedo
|
|
173
|
-
}
|
|
174
|
-
),
|
|
175
|
-
/* @__PURE__ */ jsx(
|
|
176
|
-
Button,
|
|
177
|
-
{
|
|
178
|
-
size: "compact",
|
|
179
|
-
variant: "tertiary",
|
|
180
|
-
disabled: !isDirty,
|
|
181
|
-
accessibleWhenDisabled: true,
|
|
182
|
-
onClick: handleReset,
|
|
183
|
-
children: __("Reset")
|
|
184
|
-
}
|
|
185
|
-
)
|
|
186
|
-
] })
|
|
187
|
-
]
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
export {
|
|
192
|
-
MediaEditorToolbar as default
|
|
193
|
-
};
|
|
194
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-toolbar/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { displayShortcut, isAppleOS } from '@wordpress/keycodes';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tundo,\n\tredo,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorToolbarProps {\n\t/**\n\t * Extra work to run when the user clicks Reset \u2014 e.g. clearing\n\t * aspect-ratio / freeform state that lives outside the cropper\n\t * controller.\n\t */\n\tonReset?: () => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/** Whether undo/redo should be unavailable during an active gesture. */\n\tisUndoRedoDisabled?: boolean;\n}\n\n/**\n * Toolbar for the media editor modal. Hosts the tactile cropper verbs \u2014\n * rotate, flip, fine rotation, reset \u2014 so they stay within thumb reach\n * when the toolbar sits at the bottom of the modal. Aspect-ratio presets\n * and freeform toggle live in the Crop sidebar tab instead.\n * @param props\n * @param props.onReset\n * @param props.onPlacementControlInteraction\n * @param props.isUndoRedoDisabled\n */\nexport default function MediaEditorToolbar( {\n\tonReset,\n\tonPlacementControlInteraction,\n\tisUndoRedoDisabled = false,\n}: MediaEditorToolbarProps ) {\n\tconst {\n\t\tstate,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\tsnapRotate90,\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t\tbeginGesture,\n\t\tendGesture,\n\t} = useMediaEditor();\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\tconst handleReset = () => {\n\t\tbeginGesture();\n\t\treset();\n\t\tonReset?.();\n\t\tendGesture();\n\t};\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly \u00B1MAX lands state on a\n\t\t// 90\u00B0 midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor-toolbar\"\n\t\t\tdirection=\"row\"\n\t\t\talign=\"center\"\n\t\t\tjustify=\"center\"\n\t\t\tgap=\"sm\"\n\t\t\twrap=\"wrap\"\n\t\t>\n\t\t\t<div\n\t\t\t\trole=\"presentation\"\n\t\t\t\tclassName=\"media-editor-toolbar__rotation-slider\"\n\t\t\t\t{ ...rotationGestureHandlers }\n\t\t\t>\n\t\t\t\t<RotationRuler\n\t\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\t\tvalue={ fineOffset }\n\t\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"media-editor-toolbar__action-cluster\">\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateLeft }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateRight }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipHorizontal }\n\t\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipVertical }\n\t\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ undo }\n\t\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleUndo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ redo }\n\t\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={\n\t\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t\t}\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleRedo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! isDirty }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleReset }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t</Stack>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,UAAU;AACnB,SAAS,iBAAiB,iBAAiB;AAC3C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,OAAO,mBAAmB;AAyGtB,cAQD,YARC;AAhFW,SAAR,mBAAqC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA,qBAAqB;AACtB,GAA6B;AAC5B,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD,IAAI,eAAe;AAInB,QAAM,0BAA0B,uBAAwB;AAAA,IACvD,eAAe;AAAA,EAChB,CAAE;AAEF,QAAM,cAAc,MAAM;AACzB,iBAAa;AACb,UAAM;AACN,cAAU;AACV,eAAW;AAAA,EACZ;AACA,QAAM,aAAa,MAAM;AACxB,QAAK,oBAAqB;AACzB;AAAA,IACD;AACA,aAAS;AAAA,EACV;AACA,QAAM,aAAa,MAAM;AACxB,QAAK,oBAAqB;AACzB;AAAA,IACD;AACA,aAAS;AAAA,EACV;AAKA,QAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACtD,QAAM,aAAa,MAAM,KAAK,eAAe,MAAM,KAAK;AACxD,QAAM,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,MAAM,KAAK;AAAA,gBACzB,UAAU,MAAM,KAAK;AAAA,cACtB,CAAE;AAAA;AAAA,UAEJ;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,OAAQ,GAAI,eAAgB;AAAA,cAC5B,aAAW;AAAA,cACX,WAAY,MAAM,KAAK;AAAA,cACvB,SAAU,MACT,QAAS;AAAA,gBACR,YAAY,MAAM,KAAK;AAAA,gBACvB,UAAU,CAAE,MAAM,KAAK;AAAA,cACxB,CAAE;AAAA;AAAA,UAEJ;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,OAAQ,GAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,UAAW,gBAAgB,QAAS,GAAI;AAAA,cACxC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,OAAQ,GAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,UACC,UAAU,IACP,gBAAgB,aAAc,GAAI,IAClC,gBAAgB,QAAS,GAAI;AAAA,cAEjC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,SAAQ;AAAA,cACR,UAAW,CAAE;AAAA,cACb,wBAAsB;AAAA,cACtB,SAAU;AAAA,cAER,aAAI,OAAQ;AAAA;AAAA,UACf;AAAA,WACD;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface MediaEditorToolbarProps {
|
|
2
|
-
/**
|
|
3
|
-
* Extra work to run when the user clicks Reset — e.g. clearing
|
|
4
|
-
* aspect-ratio / freeform state that lives outside the cropper
|
|
5
|
-
* controller.
|
|
6
|
-
*/
|
|
7
|
-
onReset?: () => void;
|
|
8
|
-
/** Signal that a placement-oriented control is being adjusted. */
|
|
9
|
-
onPlacementControlInteraction?: () => void;
|
|
10
|
-
/** Whether undo/redo should be unavailable during an active gesture. */
|
|
11
|
-
isUndoRedoDisabled?: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Toolbar for the media editor modal. Hosts the tactile cropper verbs —
|
|
15
|
-
* rotate, flip, fine rotation, reset — so they stay within thumb reach
|
|
16
|
-
* when the toolbar sits at the bottom of the modal. Aspect-ratio presets
|
|
17
|
-
* and freeform toggle live in the Crop sidebar tab instead.
|
|
18
|
-
* @param props
|
|
19
|
-
* @param props.onReset
|
|
20
|
-
* @param props.onPlacementControlInteraction
|
|
21
|
-
* @param props.isUndoRedoDisabled
|
|
22
|
-
*/
|
|
23
|
-
export default function MediaEditorToolbar({ onReset, onPlacementControlInteraction, isUndoRedoDisabled }: MediaEditorToolbarProps): import("react").JSX.Element;
|
|
24
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-editor-toolbar/index.tsx"],"names":[],"mappings":"AAwBA,MAAM,WAAW,uBAAuB;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,kEAAkE;IAClE,6BAA6B,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3C,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAE,EAC3C,OAAO,EACP,6BAA6B,EAC7B,kBAA0B,EAC1B,EAAE,uBAAuB,+BAiKzB"}
|