@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131032.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 +560 -0
- package/build/components/media-editor/index.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +14 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +34 -27
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +42 -430
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-toolbar/index.cjs +143 -75
- package/build/components/media-editor-toolbar/index.cjs.map +3 -3
- package/build/components/media-form/index.cjs +3 -0
- package/build/components/media-form/index.cjs.map +2 -2
- package/build/components/rotation-ruler/index.cjs +197 -0
- package/build/components/rotation-ruler/index.cjs.map +7 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
- package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
- package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +9 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +7 -13
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs +43 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +5 -1
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs.map +1 -1
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/core/viewport-state.cjs +50 -0
- package/build/image-editor/core/viewport-state.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +192 -72
- package/build/image-editor/react/components/cropper.cjs.map +3 -3
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/components/viewport-provider.cjs +51 -0
- package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
- package/build/image-editor/react/visually-hidden-style.cjs +41 -0
- package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
- package/build/private-apis.cjs +2 -0
- package/build/private-apis.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +545 -0
- package/build-module/components/media-editor/index.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +14 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +46 -455
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-toolbar/index.mjs +137 -77
- package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs +3 -0
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs +166 -0
- package/build-module/components/rotation-ruler/index.mjs.map +7 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +6 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +6 -12
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs +50 -8
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +5 -1
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/core/viewport-state.mjs +24 -0
- package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +195 -73
- package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
- package/build-module/private-apis.mjs +2 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-style/style-rtl.css +254 -29
- package/build-style/style.css +254 -29
- package/build-types/components/media-editor/index.d.ts +34 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +10 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +2 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +1 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/index.d.ts +46 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +9 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +11 -7
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +25 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/core/viewport-state.d.ts +7 -0
- package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +2 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -3
- package/build-types/store/actions.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/components/media-editor/index.tsx +709 -0
- package/src/components/media-editor/style.scss +89 -0
- package/src/components/media-editor-canvas/index.tsx +24 -0
- package/src/components/media-editor-crop-panel/index.tsx +39 -27
- package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
- package/src/components/media-editor-modal/index.tsx +49 -589
- package/src/components/media-editor-modal/style.scss +13 -112
- package/src/components/media-editor-toolbar/index.tsx +122 -63
- package/src/components/media-editor-toolbar/style.scss +39 -11
- package/src/components/media-form/index.tsx +5 -0
- package/src/components/rotation-ruler/README.md +37 -0
- package/src/components/rotation-ruler/index.tsx +266 -0
- package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
- package/src/components/rotation-ruler/style.scss +147 -0
- package/src/components/rotation-ruler/test/index.tsx +109 -0
- package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
- package/src/hooks/use-crop-gesture-handlers.ts +54 -0
- package/src/image-editor/core/constants.ts +12 -0
- package/src/image-editor/core/containment.ts +16 -28
- package/src/image-editor/core/interaction-controller.ts +66 -10
- package/src/image-editor/core/state.ts +15 -8
- package/src/image-editor/core/test/camera.ts +15 -26
- package/src/image-editor/core/test/interaction-controller.ts +158 -7
- package/src/image-editor/core/test/state.ts +21 -1
- package/src/image-editor/core/transform-style.ts +1 -1
- package/src/image-editor/core/types.ts +16 -0
- package/src/image-editor/core/viewport-state.ts +33 -0
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.scss +28 -0
- package/src/image-editor/react/components/cropper.tsx +268 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
- package/src/image-editor/react/components/test/cropper.tsx +294 -5
- package/src/image-editor/react/components/viewport-provider.tsx +39 -0
- package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
- package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
- package/src/image-editor/react/hooks/use-interaction.ts +36 -6
- package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
- package/src/image-editor/react/visually-hidden-style.ts +15 -0
- package/src/private-apis.ts +2 -0
- package/src/style.scss +3 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -3,126 +3,27 @@
|
|
|
3
3
|
@use "@wordpress/base-styles/variables" as *;
|
|
4
4
|
@use "@wordpress/base-styles/z-index" as *;
|
|
5
5
|
|
|
6
|
-
// `className` on `<Modal>` is applied to `.components-modal__frame`, so
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// and lets the InterfaceSkeleton run edge-to-edge inside the modal.
|
|
6
|
+
// `className` on `<Modal>` is applied to `.components-modal__frame`, so this
|
|
7
|
+
// bumps specificity over the shipped full-screen modal content rule and lets
|
|
8
|
+
// the media editor run edge-to-edge inside the modal.
|
|
10
9
|
.media-editor-modal.components-modal__frame .components-modal__content {
|
|
11
10
|
padding: 0;
|
|
12
11
|
margin-bottom: 0;
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
min-height: 0;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
.media-editor-modal {
|
|
17
|
+
.media-editor-modal.components-modal__frame .components-modal__children-container {
|
|
16
18
|
display: flex;
|
|
19
|
+
flex: 1;
|
|
17
20
|
flex-direction: column;
|
|
21
|
+
min-height: 0;
|
|
22
|
+
}
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// container — `height: 100%` (rather than `flex: 1`) makes it fill
|
|
23
|
-
// the body so the inner flex can center the spinner.
|
|
24
|
-
.media-editor-modal__loading {
|
|
25
|
-
height: 100%;
|
|
26
|
-
display: flex;
|
|
27
|
-
align-items: center;
|
|
28
|
-
justify-content: center;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// InterfaceSkeleton defaults to position: fixed for full-viewport usage.
|
|
32
|
-
// Reset it so the skeleton flows inside the modal's content area. Stack
|
|
33
|
-
// children vertically (header/body/footer) since the default row layout
|
|
34
|
-
// assumes an absolutely positioned footer that overlays the bottom.
|
|
35
|
-
.interface-interface-skeleton {
|
|
36
|
-
position: relative;
|
|
37
|
-
top: auto;
|
|
38
|
-
right: auto;
|
|
39
|
-
bottom: auto;
|
|
40
|
-
left: auto;
|
|
41
|
-
height: 100%;
|
|
42
|
-
max-height: none;
|
|
43
|
-
flex: 1;
|
|
44
|
-
flex-direction: column;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.interface-interface-skeleton__editor {
|
|
48
|
-
min-width: 0;
|
|
49
|
-
flex: 1;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// The skeleton's default footer is `position: absolute; bottom: 0` with
|
|
53
|
-
// a small fixed padding-bottom on the body to compensate. Our bottom
|
|
54
|
-
// bar is taller than that default, so it would overlap the cropper's
|
|
55
|
-
// resize handles. Put the footer in flow so it claims its own row and
|
|
56
|
-
// the canvas (and sidebar) resize to fit above it. The skeleton also
|
|
57
|
-
// hides the footer below the medium breakpoint by default; force it
|
|
58
|
-
// visible so the bottom-bar controls remain accessible on narrow
|
|
59
|
-
// viewports.
|
|
60
|
-
.interface-interface-skeleton__footer {
|
|
61
|
-
position: relative;
|
|
62
|
-
display: flex;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.interface-interface-skeleton.has-footer .interface-interface-skeleton__body {
|
|
66
|
-
padding-bottom: 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.media-editor-modal__canvas {
|
|
70
|
-
display: flex;
|
|
71
|
-
align-items: center;
|
|
72
|
-
justify-content: center;
|
|
73
|
-
background: $gray-100;
|
|
74
|
-
overflow: auto;
|
|
75
|
-
height: 100%;
|
|
76
|
-
|
|
77
|
-
// MediaPreview uses `min-height: 100%` so it can grow when needed in
|
|
78
|
-
// other contexts. Inside the modal canvas we need a definite height
|
|
79
|
-
// so the image/video's `max-height: 100%` resolves and the preview
|
|
80
|
-
// is contained vertically.
|
|
81
|
-
.media-editor-preview {
|
|
82
|
-
height: 100%;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
img,
|
|
86
|
-
video {
|
|
87
|
-
max-width: 100%;
|
|
88
|
-
max-height: 100%;
|
|
89
|
-
object-fit: contain;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Matches the post editor's `.editor-sidebar` container (see
|
|
94
|
-
// `packages/editor/src/components/sidebar/style.scss`): `@include reset`
|
|
95
|
-
// sets `box-sizing: border-box` and makes all descendants inherit it.
|
|
96
|
-
// Without this, descendants (notably the active-tab underline inside
|
|
97
|
-
// `<Tabs>`) fall back to `content-box` sizing that shortens the
|
|
98
|
-
// indicator under the selected tab label.
|
|
99
|
-
.media-editor-modal__sidebar {
|
|
100
|
-
@include reset;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Mirror the editor's `PostPanelSection` padding for tab body content,
|
|
104
|
-
// so the form inside the Details tab has breathing room.
|
|
105
|
-
.media-editor-modal__panel {
|
|
106
|
-
padding: $grid-unit-20;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Match the post editor's sidebar header treatment
|
|
110
|
-
// (see `packages/editor/src/components/sidebar/style.scss`): when the tab
|
|
111
|
-
// list is rendered as `ComplementaryArea`'s header, zero the default
|
|
112
|
-
// panel-header padding so tabs sit flush to the edge and the active-tab
|
|
113
|
-
// underline can span the full tab label width.
|
|
114
|
-
.components-panel__header.media-editor-modal__sidebar-header {
|
|
115
|
-
padding-left: 0;
|
|
116
|
-
padding-right: $grid-unit-10;
|
|
117
|
-
|
|
118
|
-
.components-button.has-icon {
|
|
119
|
-
padding: 0;
|
|
120
|
-
|
|
121
|
-
@include break-medium() {
|
|
122
|
-
display: flex;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
24
|
+
.media-editor-modal {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
126
27
|
}
|
|
127
28
|
|
|
128
29
|
// `<SnackbarNotices>` renders `.components-snackbar-list` with
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { Button
|
|
4
|
+
import { Button } from '@wordpress/components';
|
|
5
5
|
import { Stack } from '@wordpress/ui';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
|
|
7
8
|
import {
|
|
8
9
|
rotateLeft,
|
|
9
10
|
rotateRight,
|
|
10
11
|
flipHorizontal,
|
|
11
12
|
flipVertical,
|
|
13
|
+
undo,
|
|
14
|
+
redo,
|
|
12
15
|
} from '@wordpress/icons';
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Internal dependencies
|
|
16
19
|
*/
|
|
17
20
|
import { useCropper } from '../../image-editor';
|
|
21
|
+
import { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';
|
|
18
22
|
import { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';
|
|
23
|
+
import RotationRuler from '../rotation-ruler';
|
|
19
24
|
|
|
20
25
|
export interface MediaEditorToolbarProps {
|
|
21
26
|
/**
|
|
@@ -26,6 +31,8 @@ export interface MediaEditorToolbarProps {
|
|
|
26
31
|
onReset?: () => void;
|
|
27
32
|
/** Signal that a placement-oriented control is being adjusted. */
|
|
28
33
|
onPlacementControlInteraction?: () => void;
|
|
34
|
+
/** Whether undo/redo should be unavailable during an active gesture. */
|
|
35
|
+
isUndoRedoDisabled?: boolean;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
/**
|
|
@@ -36,18 +43,48 @@ export interface MediaEditorToolbarProps {
|
|
|
36
43
|
* @param props
|
|
37
44
|
* @param props.onReset
|
|
38
45
|
* @param props.onPlacementControlInteraction
|
|
46
|
+
* @param props.isUndoRedoDisabled
|
|
39
47
|
*/
|
|
40
48
|
export default function MediaEditorToolbar( {
|
|
41
49
|
onReset,
|
|
42
50
|
onPlacementControlInteraction,
|
|
51
|
+
isUndoRedoDisabled = false,
|
|
43
52
|
}: MediaEditorToolbarProps ) {
|
|
44
|
-
const {
|
|
45
|
-
|
|
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
|
+
} = useCropper();
|
|
65
|
+
// `commitOnKeyUp: false` keeps rapid arrow-key adjustments coalesced
|
|
66
|
+
// into a single undo entry by the state-change debounce. Pointer-up
|
|
67
|
+
// still commits immediately so each drag is its own undo step.
|
|
68
|
+
const rotationGestureHandlers = useCropGestureHandlers( {
|
|
69
|
+
commitOnKeyUp: false,
|
|
70
|
+
} );
|
|
46
71
|
|
|
47
72
|
const handleReset = () => {
|
|
48
73
|
reset();
|
|
49
74
|
onReset?.();
|
|
50
75
|
};
|
|
76
|
+
const handleUndo = () => {
|
|
77
|
+
if ( isUndoRedoDisabled ) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
undoCrop();
|
|
81
|
+
};
|
|
82
|
+
const handleRedo = () => {
|
|
83
|
+
if ( isUndoRedoDisabled ) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
redoCrop();
|
|
87
|
+
};
|
|
51
88
|
|
|
52
89
|
// `setRotation` is an absolute-angle setter. When a single flip is active
|
|
53
90
|
// the visual direction inverts, so slider input must flip sign to match
|
|
@@ -57,10 +94,7 @@ export default function MediaEditorToolbar( {
|
|
|
57
94
|
const visualDir = singleFlip ? -1 : 1;
|
|
58
95
|
const fineOffset = ( state.rotation - baseAngle ) * visualDir;
|
|
59
96
|
|
|
60
|
-
const handleRotationSlider = ( value: number
|
|
61
|
-
if ( value === undefined ) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
97
|
+
const handleRotationSlider = ( value: number ) => {
|
|
64
98
|
// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a
|
|
65
99
|
// 90° midpoint and flips the derived baseAngle on the next render,
|
|
66
100
|
// causing subsequent events to spiral.
|
|
@@ -82,69 +116,94 @@ export default function MediaEditorToolbar( {
|
|
|
82
116
|
gap="sm"
|
|
83
117
|
wrap="wrap"
|
|
84
118
|
>
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/>
|
|
92
|
-
<Button
|
|
93
|
-
size="compact"
|
|
94
|
-
icon={ rotateRight }
|
|
95
|
-
label={ __( 'Rotate 90° clockwise' ) }
|
|
96
|
-
showTooltip
|
|
97
|
-
onClick={ () => snapRotate90( 1 ) }
|
|
98
|
-
/>
|
|
99
|
-
<Button
|
|
100
|
-
size="compact"
|
|
101
|
-
icon={ flipHorizontal }
|
|
102
|
-
label={ __( 'Flip horizontal' ) }
|
|
103
|
-
showTooltip
|
|
104
|
-
isPressed={ state.flip.horizontal }
|
|
105
|
-
onClick={ () =>
|
|
106
|
-
setFlip( {
|
|
107
|
-
horizontal: ! state.flip.horizontal,
|
|
108
|
-
vertical: state.flip.vertical,
|
|
109
|
-
} )
|
|
110
|
-
}
|
|
111
|
-
/>
|
|
112
|
-
<Button
|
|
113
|
-
size="compact"
|
|
114
|
-
icon={ flipVertical }
|
|
115
|
-
label={ __( 'Flip vertical' ) }
|
|
116
|
-
showTooltip
|
|
117
|
-
isPressed={ state.flip.vertical }
|
|
118
|
-
onClick={ () =>
|
|
119
|
-
setFlip( {
|
|
120
|
-
horizontal: state.flip.horizontal,
|
|
121
|
-
vertical: ! state.flip.vertical,
|
|
122
|
-
} )
|
|
123
|
-
}
|
|
124
|
-
/>
|
|
125
|
-
<div className="media-editor-toolbar__rotation-slider">
|
|
126
|
-
<RangeControl
|
|
127
|
-
__next40pxDefaultSize
|
|
128
|
-
__nextHasNoMarginBottom
|
|
119
|
+
<div
|
|
120
|
+
role="presentation"
|
|
121
|
+
className="media-editor-toolbar__rotation-slider"
|
|
122
|
+
{ ...rotationGestureHandlers }
|
|
123
|
+
>
|
|
124
|
+
<RotationRuler
|
|
129
125
|
label={ __( 'Fine rotation' ) }
|
|
130
|
-
hideLabelFromVision
|
|
131
126
|
min={ -MAX_ROTATION_OFFSET }
|
|
132
127
|
max={ MAX_ROTATION_OFFSET }
|
|
133
|
-
step={ 0.5 }
|
|
134
128
|
value={ fineOffset }
|
|
135
129
|
onChange={ handleRotationSlider }
|
|
136
|
-
showTooltip={ false }
|
|
137
130
|
/>
|
|
138
131
|
</div>
|
|
139
|
-
<
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
132
|
+
<div className="media-editor-toolbar__action-cluster">
|
|
133
|
+
<Button
|
|
134
|
+
size="compact"
|
|
135
|
+
icon={ rotateLeft }
|
|
136
|
+
label={ __( 'Rotate 90° counter-clockwise' ) }
|
|
137
|
+
showTooltip
|
|
138
|
+
onClick={ () => snapRotate90( -1 ) }
|
|
139
|
+
/>
|
|
140
|
+
<Button
|
|
141
|
+
size="compact"
|
|
142
|
+
icon={ rotateRight }
|
|
143
|
+
label={ __( 'Rotate 90° clockwise' ) }
|
|
144
|
+
showTooltip
|
|
145
|
+
onClick={ () => snapRotate90( 1 ) }
|
|
146
|
+
/>
|
|
147
|
+
<Button
|
|
148
|
+
size="compact"
|
|
149
|
+
icon={ flipHorizontal }
|
|
150
|
+
label={ __( 'Flip horizontal' ) }
|
|
151
|
+
showTooltip
|
|
152
|
+
isPressed={ state.flip.horizontal }
|
|
153
|
+
onClick={ () =>
|
|
154
|
+
setFlip( {
|
|
155
|
+
horizontal: ! state.flip.horizontal,
|
|
156
|
+
vertical: state.flip.vertical,
|
|
157
|
+
} )
|
|
158
|
+
}
|
|
159
|
+
/>
|
|
160
|
+
<Button
|
|
161
|
+
size="compact"
|
|
162
|
+
icon={ flipVertical }
|
|
163
|
+
label={ __( 'Flip vertical' ) }
|
|
164
|
+
showTooltip
|
|
165
|
+
isPressed={ state.flip.vertical }
|
|
166
|
+
onClick={ () =>
|
|
167
|
+
setFlip( {
|
|
168
|
+
horizontal: state.flip.horizontal,
|
|
169
|
+
vertical: ! state.flip.vertical,
|
|
170
|
+
} )
|
|
171
|
+
}
|
|
172
|
+
/>
|
|
173
|
+
<Button
|
|
174
|
+
size="compact"
|
|
175
|
+
icon={ undo }
|
|
176
|
+
label={ __( 'Undo' ) }
|
|
177
|
+
showTooltip
|
|
178
|
+
shortcut={ displayShortcut.primary( 'z' ) }
|
|
179
|
+
disabled={ isUndoRedoDisabled || ! hasUndo }
|
|
180
|
+
accessibleWhenDisabled
|
|
181
|
+
onClick={ handleUndo }
|
|
182
|
+
/>
|
|
183
|
+
<Button
|
|
184
|
+
size="compact"
|
|
185
|
+
icon={ redo }
|
|
186
|
+
label={ __( 'Redo' ) }
|
|
187
|
+
showTooltip
|
|
188
|
+
shortcut={
|
|
189
|
+
isAppleOS()
|
|
190
|
+
? displayShortcut.primaryShift( 'z' )
|
|
191
|
+
: displayShortcut.primary( 'y' )
|
|
192
|
+
}
|
|
193
|
+
disabled={ isUndoRedoDisabled || ! hasRedo }
|
|
194
|
+
accessibleWhenDisabled
|
|
195
|
+
onClick={ handleRedo }
|
|
196
|
+
/>
|
|
197
|
+
<Button
|
|
198
|
+
size="compact"
|
|
199
|
+
variant="tertiary"
|
|
200
|
+
disabled={ ! isDirty }
|
|
201
|
+
accessibleWhenDisabled
|
|
202
|
+
onClick={ handleReset }
|
|
203
|
+
>
|
|
204
|
+
{ __( 'Reset' ) }
|
|
205
|
+
</Button>
|
|
206
|
+
</div>
|
|
148
207
|
</Stack>
|
|
149
208
|
);
|
|
150
209
|
}
|
|
@@ -1,21 +1,49 @@
|
|
|
1
|
-
@use "@wordpress/base-styles/variables" as *;
|
|
2
1
|
@use "@wordpress/base-styles/breakpoints" as *;
|
|
2
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
3
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
3
4
|
|
|
4
5
|
.media-editor-toolbar {
|
|
5
6
|
width: 100%;
|
|
6
7
|
padding: $grid-unit-10 $grid-unit-20;
|
|
8
|
+
}
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 }) {
|
|
11
40
|
.media-editor-toolbar__rotation-slider {
|
|
12
|
-
flex:
|
|
13
|
-
max-width:
|
|
41
|
+
flex-basis: 100%;
|
|
42
|
+
max-width: none;
|
|
43
|
+
}
|
|
14
44
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
display: none;
|
|
19
|
-
}
|
|
45
|
+
.media-editor-toolbar__action-cluster {
|
|
46
|
+
flex-basis: 100%;
|
|
47
|
+
justify-content: center;
|
|
20
48
|
}
|
|
21
49
|
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { DataForm } from '@wordpress/dataviews';
|
|
5
5
|
import type { Form, Field } from '@wordpress/dataviews';
|
|
6
6
|
import { Spinner, __experimentalVStack as VStack } from '@wordpress/components';
|
|
7
|
+
import { VisuallyHidden } from '@wordpress/ui';
|
|
8
|
+
import { __ } from '@wordpress/i18n';
|
|
7
9
|
import type { ReactNode } from 'react';
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -74,6 +76,9 @@ export default function MediaForm( {
|
|
|
74
76
|
return (
|
|
75
77
|
<div className="media-editor-form">
|
|
76
78
|
<VStack spacing={ 4 }>
|
|
79
|
+
<VisuallyHidden render={ <h2 /> }>
|
|
80
|
+
{ __( 'Media details' ) }
|
|
81
|
+
</VisuallyHidden>
|
|
77
82
|
{ header }
|
|
78
83
|
<DataForm
|
|
79
84
|
data={ media }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# RotationRuler
|
|
2
|
+
|
|
3
|
+
Private to `@wordpress/media-editor`. A horizontal ruler-slider for
|
|
4
|
+
fine-grained numeric values (used for fine-tune rotation in the media
|
|
5
|
+
editor toolbar). Drag the ruler to scrub; the current value is shown
|
|
6
|
+
in an active label sitting over the centered pointer triangle, with
|
|
7
|
+
labelled major ticks running through the strip behind it. A visually
|
|
8
|
+
hidden `<input type="range">` underneath provides keyboard access and
|
|
9
|
+
accessibility. Drag values quantize to multiples of `step`.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
<RotationRuler
|
|
15
|
+
value={ rotation }
|
|
16
|
+
onChange={ setRotation }
|
|
17
|
+
label={ __( 'Fine rotation' ) }
|
|
18
|
+
min={ -45 }
|
|
19
|
+
max={ 45 }
|
|
20
|
+
/>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Props
|
|
24
|
+
|
|
25
|
+
See `index.tsx` for the full `RotationRulerProps` interface. The
|
|
26
|
+
component is controlled (`value` / `onChange`); callers own state and
|
|
27
|
+
clamp/transform values as they wish before passing them in.
|
|
28
|
+
|
|
29
|
+
## Keyboard
|
|
30
|
+
|
|
31
|
+
- **← / ↓** — decrement by `step`
|
|
32
|
+
- **→ / ↑** — increment by `step`
|
|
33
|
+
- **Shift + arrow** — half-step (e.g. 0.5° when `step` is 1°), for
|
|
34
|
+
keyboard precision when the integer drag-step is too coarse.
|
|
35
|
+
**Shift + drag** does the same on the pointer.
|
|
36
|
+
- **Home / End** — min / max
|
|
37
|
+
- **PageUp / PageDown** — ±10% of range (native input behaviour)
|