@wordpress/media-editor 0.11.0 → 0.11.2-next.v.202606191442.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/build/components/media-editor/index.cjs +41 -51
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +63 -15
- package/build/components/media-editor-canvas/index.cjs.map +3 -3
- package/build/components/media-editor-crop-panel/index.cjs +15 -45
- package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
- package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
- package/build/components/media-editor-image-controls/index.cjs +230 -0
- package/build/components/media-editor-image-controls/index.cjs.map +7 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +4 -4
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -1
- package/build/components/media-form/index.cjs +12 -23
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/components/rotation-ruler/index.cjs +1 -1
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/image-editor/core/camera.cjs +13 -0
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +15 -3
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs.map +1 -1
- package/build/image-editor/core/crop-rect.cjs.map +1 -1
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -1
- package/build/image-editor/core/interaction-controller.cjs +9 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs.map +1 -1
- package/build/image-editor/core/setter-helpers.cjs.map +1 -1
- package/build/image-editor/core/source-region.cjs +111 -2
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs.map +1 -1
- package/build/image-editor/core/stencil-math.cjs +14 -6
- package/build/image-editor/core/stencil-math.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/react/components/cropper.cjs +231 -49
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +1 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +65 -19
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -1
- package/build/index.cjs.map +1 -1
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +1 -1
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +41 -51
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +55 -17
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +8 -51
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs +221 -0
- package/build-module/components/media-editor-image-controls/index.mjs.map +7 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +4 -4
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -1
- package/build-module/components/media-form/index.mjs +12 -13
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs +1 -1
- package/build-module/components/rotation-ruler/index.mjs.map +1 -1
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -1
- package/build-module/image-editor/core/camera.mjs +12 -0
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +10 -2
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs.map +1 -1
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -1
- package/build-module/image-editor/core/interaction-controller.mjs +9 -7
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -1
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -1
- package/build-module/image-editor/core/source-region.mjs +108 -1
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs.map +1 -1
- package/build-module/image-editor/core/stencil-math.mjs +12 -5
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/react/components/cropper.mjs +242 -52
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +1 -0
- 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 +65 -19
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-style/style-rtl.css +179 -47
- package/build-style/style.css +179 -46
- package/build-types/components/media-editor/index.d.ts +6 -7
- package/build-types/components/media-editor/index.d.ts.map +1 -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 +11 -6
- 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 +4 -3
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +46 -0
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts +25 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +30 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/source-region.d.ts +23 -1
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +22 -4
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +14 -0
- package/build-types/image-editor/core/types.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/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +17 -14
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/package.json +30 -20
- package/src/components/media-editor/index.tsx +69 -77
- package/src/components/media-editor/style.scss +136 -4
- package/src/components/media-editor-canvas/index.tsx +82 -13
- package/src/components/media-editor-canvas/style.scss +41 -0
- package/src/components/media-editor-crop-panel/index.tsx +16 -62
- package/src/components/media-editor-crop-panel/test/index.tsx +25 -41
- package/src/components/media-editor-fine-rotation/index.tsx +4 -3
- package/src/components/media-editor-image-controls/index.tsx +262 -0
- package/src/components/media-editor-image-controls/style.scss +48 -0
- package/src/components/media-editor-image-controls/test/index.tsx +150 -0
- package/src/components/media-editor-modal/style.scss +32 -42
- package/src/components/media-form/index.tsx +17 -21
- package/src/components/media-form/style.scss +6 -0
- package/src/components/rotation-ruler/style.scss +10 -3
- package/src/image-editor/core/camera.ts +60 -1
- package/src/image-editor/core/constants.ts +34 -1
- package/src/image-editor/core/interaction-controller.ts +25 -11
- package/src/image-editor/core/source-region.ts +202 -1
- package/src/image-editor/core/stencil-math.ts +42 -10
- package/src/image-editor/core/test/camera.ts +272 -1
- package/src/image-editor/core/test/interaction-controller.ts +100 -0
- package/src/image-editor/core/test/stencil-math.ts +153 -0
- package/src/image-editor/core/types.ts +17 -0
- package/src/image-editor/react/components/cropper.scss +28 -17
- package/src/image-editor/react/components/cropper.tsx +362 -62
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +1 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +101 -32
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +169 -17
- package/src/image-editor/react/components/test/cropper.tsx +689 -6
- package/src/style.scss +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-transform-controls/index.cjs +0 -84
- package/build/components/media-editor-transform-controls/index.cjs.map +0 -7
- package/build/components/media-form/sidebar-datetime-view.cjs +0 -53
- package/build/components/media-form/sidebar-datetime-view.cjs.map +0 -7
- package/build-module/components/media-editor-transform-controls/index.mjs +0 -68
- package/build-module/components/media-editor-transform-controls/index.mjs.map +0 -7
- package/build-module/components/media-form/sidebar-datetime-view.mjs +0 -32
- package/build-module/components/media-form/sidebar-datetime-view.mjs.map +0 -7
- package/build-types/components/media-editor-transform-controls/index.d.ts +0 -8
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
- package/src/components/media-editor-transform-controls/index.tsx +0 -70
- package/src/components/media-editor-transform-controls/style.scss +0 -8
- package/src/components/media-form/sidebar-datetime-view.tsx +0 -47
- package/src/components/media-form/test/sidebar-datetime-view.test.tsx +0 -96
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/breakpoints" as breakpoints;
|
|
1
2
|
@use "@wordpress/base-styles/colors" as *;
|
|
2
3
|
@use "@wordpress/base-styles/mixins" as *;
|
|
3
4
|
@use "@wordpress/base-styles/variables" as *;
|
|
@@ -28,18 +29,64 @@
|
|
|
28
29
|
flex-direction: column;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
// The skeleton must always sit in the modal's flow (`top: auto`). The reset
|
|
33
|
+
// above sets that, but external rules can outrank its low specificity — e.g.
|
|
34
|
+
// the "Omnipresent Toolbar" experiment (`gutenberg-omnibar`)
|
|
35
|
+
// offsets every `.interface-interface-skeleton` below the admin bar via a
|
|
36
|
+
// `body.has-admin-bar-in-editor.is-fullscreen-mode` rule, which would push
|
|
37
|
+
// the editor (and the fine-rotation ruler under the canvas) down inside our
|
|
38
|
+
// full-screen modal that already overlays the admin bar. Re-assert `top` at a
|
|
39
|
+
// specificity that beats such rules, anchored on the modal frame
|
|
40
|
+
// (`.media-editor` only ever renders inside `.media-editor-modal`) rather
|
|
41
|
+
// than on the experiment's class, which may change if it ever graduates.
|
|
42
|
+
.media-editor-modal & .interface-interface-skeleton.interface-interface-skeleton {
|
|
43
|
+
top: auto;
|
|
44
|
+
}
|
|
45
|
+
|
|
31
46
|
.interface-interface-skeleton__editor {
|
|
32
47
|
min-width: 0;
|
|
33
48
|
flex: 1;
|
|
34
49
|
}
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
// Canvas column: image fills the available height; in panel mode the
|
|
52
|
+
// fine-rotation ruler sits directly beneath it.
|
|
53
|
+
.media-editor__content {
|
|
54
|
+
display: flex;
|
|
55
|
+
flex: 1;
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
min-height: 0;
|
|
58
|
+
// Inset the canvas + fine-rotation ruler as one rounded grey panel
|
|
59
|
+
// with a horizontal-only gutter. The ruler is always a child here
|
|
60
|
+
// (never the footer), so the two share a container and the panel is
|
|
61
|
+
// fully rounded at every viewport.
|
|
62
|
+
margin: 0 $grid-unit-30;
|
|
63
|
+
border-radius: $radius-large;
|
|
64
|
+
overflow: hidden;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.media-editor__canvas-toolbar {
|
|
68
|
+
display: flex;
|
|
69
|
+
flex-shrink: 0;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
// Share the canvas grey so the ruler strip blends into the same
|
|
72
|
+
// surface as the area around the image.
|
|
73
|
+
background: $gray-200;
|
|
74
|
+
padding: $grid-unit-10 $grid-unit-20;
|
|
75
|
+
|
|
76
|
+
.media-editor-fine-rotation {
|
|
77
|
+
flex: 0 1 360px;
|
|
78
|
+
min-width: 0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.media-editor__canvas-area {
|
|
37
83
|
display: flex;
|
|
38
84
|
align-items: center;
|
|
39
85
|
justify-content: center;
|
|
40
|
-
background: $gray-
|
|
86
|
+
background: $gray-200;
|
|
41
87
|
overflow: auto;
|
|
42
|
-
|
|
88
|
+
flex: 1;
|
|
89
|
+
min-height: 0;
|
|
43
90
|
|
|
44
91
|
.media-editor-preview {
|
|
45
92
|
height: 100%;
|
|
@@ -55,24 +102,109 @@
|
|
|
55
102
|
|
|
56
103
|
.media-editor__sidebar {
|
|
57
104
|
@include reset;
|
|
105
|
+
|
|
106
|
+
// Small left gutter so the tabs and panel content (and the zoom
|
|
107
|
+
// slider's thumb at its minimum) sit off the sidebar edge.
|
|
108
|
+
@include break-small() {
|
|
109
|
+
padding-left: 1px;
|
|
110
|
+
}
|
|
58
111
|
}
|
|
59
112
|
|
|
113
|
+
.media-editor__sidebar-panel {
|
|
114
|
+
padding-bottom: $grid-unit-30;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Borderless controls panel: clear the InterfaceSkeleton sidebar's
|
|
118
|
+
// default top border, left box-shadow, and high-contrast outline so the
|
|
119
|
+
// panel sits flush with no divider lines.
|
|
120
|
+
// NOTE: overrides @wordpress/interface internals. The sidebar region has
|
|
121
|
+
// no className prop, so this targets `interface-interface-skeleton__sidebar`
|
|
122
|
+
// directly — update here if that class is renamed upstream.
|
|
123
|
+
.interface-interface-skeleton__sidebar {
|
|
124
|
+
border-top: 0;
|
|
125
|
+
box-shadow: none;
|
|
126
|
+
outline: 1px solid transparent;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Below `small` the sidebar is a full-width overlay, so the panel carries
|
|
130
|
+
// its own all-around gutter. From `small` up it's the right-hand column and
|
|
131
|
+
// drops its left/bottom padding (the sidebar supplies the left gutter).
|
|
60
132
|
.media-editor__panel {
|
|
61
133
|
padding: $grid-unit-20;
|
|
134
|
+
|
|
135
|
+
@include break-small() {
|
|
136
|
+
padding: $grid-unit-20 $grid-unit-30 0 0;
|
|
137
|
+
}
|
|
62
138
|
}
|
|
63
139
|
|
|
140
|
+
// NOTE: overrides @wordpress/components Panel/Button internals to align
|
|
141
|
+
// the sidebar header (tabs + close button). Targets their classes
|
|
142
|
+
// directly; update here if they are renamed upstream.
|
|
64
143
|
.components-panel__header.media-editor__sidebar-header {
|
|
65
144
|
padding-left: 0;
|
|
66
145
|
padding-right: $grid-unit-10;
|
|
146
|
+
margin-right: $grid-unit-30;
|
|
147
|
+
margin-right: 0;
|
|
67
148
|
|
|
149
|
+
// When the sidebar is not a full page column, we offset the header to match the overall gutter.
|
|
150
|
+
@include break-small() {
|
|
151
|
+
margin-right: $grid-unit-30;
|
|
152
|
+
}
|
|
68
153
|
.components-button.has-icon {
|
|
69
154
|
padding: 0;
|
|
70
155
|
|
|
71
|
-
@include break-
|
|
156
|
+
@include break-small() {
|
|
72
157
|
display: flex;
|
|
73
158
|
}
|
|
74
159
|
}
|
|
75
160
|
}
|
|
161
|
+
|
|
162
|
+
// `ComplementaryArea`'s "mobile" mode is hard-coded to the `medium`
|
|
163
|
+
// breakpoint: below 782px it renders an animated fill wrapper and writes
|
|
164
|
+
// `width: 100vw` inline on both it and the inner panel. We want the sidebar
|
|
165
|
+
// to mirror InterfaceSkeleton's column/overlay collapse but shifted to
|
|
166
|
+
// `small`, so we override that inline width by breakpoint (`!important` is
|
|
167
|
+
// the only way to beat an inline style). `:has(__fill)` scopes the changes
|
|
168
|
+
// to when the panel is actually open: the skeleton sidebar wrapper is always
|
|
169
|
+
// present (empty when closed), so touching it unconditionally would paint an
|
|
170
|
+
// empty box over the canvas.
|
|
171
|
+
|
|
172
|
+
// Column (small–medium): between 600px and 782px `ComplementaryArea` is
|
|
173
|
+
// still in its mobile mode (inline `100vw`, see above) and the skeleton
|
|
174
|
+
// sidebar is absolutely positioned, so pull the open panel back in-flow at
|
|
175
|
+
// the sidebar width to sit it beside the canvas as a column.
|
|
176
|
+
//
|
|
177
|
+
// Bounded *below* the medium breakpoint on purpose. From 782px up,
|
|
178
|
+
// `InterfaceSkeleton` already makes the sidebar a `position: relative`,
|
|
179
|
+
// `width: auto` column and `ComplementaryArea` animates its width to
|
|
180
|
+
// `$sidebar-width` — exactly like the main editor. Pinning the width with
|
|
181
|
+
// `!important` there would freeze that open/close tween (the panel would
|
|
182
|
+
// sit mounted and unchanged for the animation's duration, then pop in or
|
|
183
|
+
// out), so we leave it to the skeleton. Below 782px there's nothing to
|
|
184
|
+
// freeze: `ComplementaryArea` zeroes the animation duration in mobile mode.
|
|
185
|
+
@media (min-width: #{ breakpoints.$break-small }) and (max-width: #{ (breakpoints.$break-medium - 1) }) {
|
|
186
|
+
.interface-interface-skeleton__sidebar:has(.interface-complementary-area__fill) {
|
|
187
|
+
position: relative !important;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.interface-complementary-area__fill,
|
|
191
|
+
.interface-complementary-area {
|
|
192
|
+
width: $sidebar-width !important;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Overlay (< small): the open panel fills the modal width (it would
|
|
197
|
+
// otherwise shrink-wrap, since the inline `100vw` is overridden below).
|
|
198
|
+
@media (max-width: #{ (breakpoints.$break-small - 1) }) {
|
|
199
|
+
.interface-interface-skeleton__sidebar:has(.interface-complementary-area__fill) {
|
|
200
|
+
width: 100%;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.interface-complementary-area__fill,
|
|
204
|
+
.interface-complementary-area {
|
|
205
|
+
width: 100% !important;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
76
208
|
}
|
|
77
209
|
|
|
78
210
|
.media-editor__snackbar {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
4
|
-
import { useCallback, useEffect, useMemo } from '@wordpress/element';
|
|
9
|
+
import { useCallback, useEffect, useMemo, useState } from '@wordpress/element';
|
|
10
|
+
import { Spinner } from '@wordpress/components';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* Internal dependencies
|
|
@@ -48,6 +55,13 @@ export default function MediaEditorCanvas( {
|
|
|
48
55
|
const cropperImage = controller.state.image;
|
|
49
56
|
const { beginGesture, endGesture, setImage } = controller;
|
|
50
57
|
|
|
58
|
+
// Tracks whether the image pixels have actually loaded. The cropper's
|
|
59
|
+
// geometry is driven by the known media dimensions, so its handles and
|
|
60
|
+
// overlays would otherwise appear before the image finishes streaming in.
|
|
61
|
+
const [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(
|
|
62
|
+
'loading'
|
|
63
|
+
);
|
|
64
|
+
|
|
51
65
|
// Resolved aspect ratio is derived from the preset key + the
|
|
52
66
|
// loaded image (for the "Original" preset). The reducer doesn't
|
|
53
67
|
// store this number — only the preset key — so it's a render-time
|
|
@@ -90,23 +104,78 @@ export default function MediaEditorCanvas( {
|
|
|
90
104
|
} );
|
|
91
105
|
}, [ cropperImage, mediaUrl, mediaWidth, mediaHeight, setImage ] );
|
|
92
106
|
|
|
93
|
-
|
|
107
|
+
const isImage = mediaType.type === 'image';
|
|
108
|
+
|
|
109
|
+
// Probe the image to know when its pixels have loaded (or failed),
|
|
110
|
+
// independent of the cropper. The browser shares one fetch/cache with the
|
|
111
|
+
// cropper's own `<img>`, so this adds no network cost. The cropper stays
|
|
112
|
+
// framework-pure — load/error handling lives here in the wrapper layer.
|
|
113
|
+
useEffect( () => {
|
|
114
|
+
if ( ! mediaUrl || ! isImage ) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
setStatus( 'loading' );
|
|
118
|
+
const probe = new window.Image();
|
|
119
|
+
probe.onload = () => setStatus( 'loaded' );
|
|
120
|
+
probe.onerror = () => setStatus( 'error' );
|
|
121
|
+
probe.src = mediaUrl;
|
|
122
|
+
// Cached images may already be complete before listeners attach.
|
|
123
|
+
if ( probe.complete ) {
|
|
124
|
+
setStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );
|
|
125
|
+
}
|
|
126
|
+
return () => {
|
|
127
|
+
probe.onload = null;
|
|
128
|
+
probe.onerror = null;
|
|
129
|
+
};
|
|
130
|
+
}, [ mediaUrl, isImage ] );
|
|
131
|
+
|
|
132
|
+
if ( ! mediaUrl || ! isImage ) {
|
|
94
133
|
return null;
|
|
95
134
|
}
|
|
96
135
|
|
|
136
|
+
if ( status === 'error' ) {
|
|
137
|
+
return (
|
|
138
|
+
<div className="media-editor-canvas">
|
|
139
|
+
<div className="media-editor-canvas__error" role="alert">
|
|
140
|
+
<p>{ __( 'Failed to load image.' ) }</p>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
97
146
|
return (
|
|
98
147
|
<div className="media-editor-canvas">
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
148
|
+
{ status === 'loading' && (
|
|
149
|
+
<div className="media-editor-canvas__spinner">
|
|
150
|
+
<Spinner />
|
|
151
|
+
</div>
|
|
152
|
+
) }
|
|
153
|
+
{ /*
|
|
154
|
+
* The cropper stays mounted while loading (hidden behind the
|
|
155
|
+
* spinner) so the image decodes off-screen and reveals in one paint
|
|
156
|
+
* instead of streaming in top-to-bottom. Until it's revealed it's
|
|
157
|
+
* non-interactive (`pointer-events: none` in CSS), and focus is
|
|
158
|
+
* withheld by gating `focusOnMount` on the loaded state — the
|
|
159
|
+
* cropper's focus effect keys off that prop, so focus lands on the
|
|
160
|
+
* crop area only once it's visible.
|
|
161
|
+
*/ }
|
|
162
|
+
<div
|
|
163
|
+
className={ clsx( 'media-editor-canvas__cropper', {
|
|
164
|
+
'is-loaded': status === 'loaded',
|
|
165
|
+
} ) }
|
|
166
|
+
>
|
|
167
|
+
<Cropper
|
|
168
|
+
src={ mediaUrl }
|
|
169
|
+
controller={ controller }
|
|
170
|
+
aspectRatio={ aspectRatio }
|
|
171
|
+
freeformCrop
|
|
172
|
+
focusOnMount={ focusOnMount && status === 'loaded' }
|
|
173
|
+
showGrid="interactive"
|
|
174
|
+
isPlacementActive={ isPlacementActive }
|
|
175
|
+
onGestureStart={ handleGestureStart }
|
|
176
|
+
onGestureEnd={ handleGestureEnd }
|
|
177
|
+
/>
|
|
178
|
+
</div>
|
|
110
179
|
</div>
|
|
111
180
|
);
|
|
112
181
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/animations" as *;
|
|
2
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
3
|
+
|
|
1
4
|
// The canvas wrapper fills the modal's canvas area so the cropper has a
|
|
2
5
|
// sized parent (the cropper uses 100% width/height of its container).
|
|
3
6
|
// `position: relative` establishes a stacking context for any future
|
|
@@ -6,4 +9,42 @@
|
|
|
6
9
|
position: relative;
|
|
7
10
|
width: 100%;
|
|
8
11
|
height: 100%;
|
|
12
|
+
|
|
13
|
+
// The cropper stays mounted while loading so the image decodes behind the
|
|
14
|
+
// spinner and reveals in one paint. It's hidden and non-interactive until
|
|
15
|
+
// the image has loaded, then fades in.
|
|
16
|
+
&__cropper {
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
opacity: 0;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
|
|
22
|
+
// Explicit `opacity: 1` (not just the animation's fill mode) keeps the
|
|
23
|
+
// cropper visible for reduced-motion users, since `animation__fade-in`
|
|
24
|
+
// is gated behind `@media not (prefers-reduced-motion)`.
|
|
25
|
+
&.is-loaded {
|
|
26
|
+
opacity: 1;
|
|
27
|
+
pointer-events: auto;
|
|
28
|
+
@include animation__fade-in( 0.2s );
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&__spinner {
|
|
33
|
+
position: absolute;
|
|
34
|
+
top: 50%;
|
|
35
|
+
left: 50%;
|
|
36
|
+
transform: translate(-50%, -50%);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Centered fallback shown in place of the cropper when the image
|
|
40
|
+
// fails to load.
|
|
41
|
+
&__error {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
width: 100%;
|
|
46
|
+
height: 100%;
|
|
47
|
+
color: $gray-700;
|
|
48
|
+
text-align: center;
|
|
49
|
+
}
|
|
9
50
|
}
|
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { SelectControl } from '@wordpress/components';
|
|
5
5
|
import { Stack, VisuallyHidden } from '@wordpress/ui';
|
|
6
|
-
import { __
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
useCropGestureHandlers,
|
|
14
|
-
CROP_CONTROL_ATTR,
|
|
15
|
-
} from '../../hooks/use-crop-gesture-handlers';
|
|
16
|
-
import { MAX_ZOOM } from '../../image-editor/core/constants';
|
|
17
|
-
import { getMinZoom } from '../../image-editor/core/containment';
|
|
11
|
+
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
12
|
+
import MediaEditorImageControls from '../media-editor-image-controls';
|
|
18
13
|
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
19
14
|
|
|
20
|
-
const ZOOM_PERCENTAGE_SCALE = 100;
|
|
21
|
-
const MAX_ZOOM_PERCENTAGE = MAX_ZOOM * ZOOM_PERCENTAGE_SCALE;
|
|
22
|
-
|
|
23
|
-
function getZoomPercentageForDisplay( zoom: number ): number {
|
|
24
|
-
return Math.round( zoom * ZOOM_PERCENTAGE_SCALE );
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getMinZoomPercentageForDisplay( zoom: number ): number {
|
|
28
|
-
return Math.ceil( zoom * ZOOM_PERCENTAGE_SCALE );
|
|
29
|
-
}
|
|
30
|
-
|
|
31
15
|
export interface MediaEditorCropPanelProps {
|
|
32
16
|
/**
|
|
33
17
|
* Selected aspect-ratio preset value as a string (so it round-trips
|
|
@@ -37,33 +21,32 @@ export interface MediaEditorCropPanelProps {
|
|
|
37
21
|
aspectRatioValue: string;
|
|
38
22
|
/** Setter for the aspect-ratio preset value. */
|
|
39
23
|
onAspectRatioChange: ( value: string ) => void;
|
|
40
|
-
/** Signal that a placement-oriented control is being adjusted. */
|
|
41
|
-
onPlacementControlInteraction?: () => void;
|
|
42
24
|
/** Aspect-ratio presets to display in the selector. */
|
|
43
25
|
aspectRatioOptions: AspectRatioPreset[];
|
|
26
|
+
/**
|
|
27
|
+
* When `true`, render the rotate/flip/zoom image controls at the top of
|
|
28
|
+
* the panel. Used on wide viewports where the footer no longer carries
|
|
29
|
+
* them.
|
|
30
|
+
*/
|
|
31
|
+
showTransformControls?: boolean;
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
/**
|
|
47
|
-
* Sidebar panel for crop
|
|
48
|
-
*
|
|
35
|
+
* Sidebar panel for crop controls. Renders the aspect-ratio selector, plus the
|
|
36
|
+
* rotate/flip and zoom controls on wide viewports (these move to the footer
|
|
37
|
+
* toolbar when the sidebar collapses).
|
|
49
38
|
* @param props
|
|
50
39
|
* @param props.aspectRatioValue
|
|
51
40
|
* @param props.onAspectRatioChange
|
|
52
|
-
* @param props.onPlacementControlInteraction
|
|
53
41
|
* @param props.aspectRatioOptions
|
|
42
|
+
* @param props.showTransformControls
|
|
54
43
|
*/
|
|
55
44
|
export default function MediaEditorCropPanel( {
|
|
56
45
|
aspectRatioValue,
|
|
57
46
|
onAspectRatioChange,
|
|
58
|
-
onPlacementControlInteraction,
|
|
59
47
|
aspectRatioOptions,
|
|
48
|
+
showTransformControls = false,
|
|
60
49
|
}: MediaEditorCropPanelProps ) {
|
|
61
|
-
const { state, setZoom } = useMediaEditor();
|
|
62
|
-
const zoomGestureHandlers = useCropGestureHandlers();
|
|
63
|
-
const minZoom = getMinZoom( state );
|
|
64
|
-
const zoomPercentage = getZoomPercentageForDisplay( state.zoom );
|
|
65
|
-
const minZoomPercentage = getMinZoomPercentageForDisplay( minZoom );
|
|
66
|
-
|
|
67
50
|
return (
|
|
68
51
|
// Tag the whole panel as a crop-control region so the modal's
|
|
69
52
|
// Cmd+Z handler doesn't mistake the SelectControl input for a
|
|
@@ -76,6 +59,7 @@ export default function MediaEditorCropPanel( {
|
|
|
76
59
|
<VisuallyHidden render={ <h2 /> }>
|
|
77
60
|
{ __( 'Crop options' ) }
|
|
78
61
|
</VisuallyHidden>
|
|
62
|
+
{ showTransformControls && <MediaEditorImageControls withLabels /> }
|
|
79
63
|
<SelectControl
|
|
80
64
|
__next40pxDefaultSize
|
|
81
65
|
label={ __( 'Aspect ratio' ) }
|
|
@@ -86,36 +70,6 @@ export default function MediaEditorCropPanel( {
|
|
|
86
70
|
value: preset.value.toString(),
|
|
87
71
|
} ) ) }
|
|
88
72
|
/>
|
|
89
|
-
<div role="presentation" { ...zoomGestureHandlers }>
|
|
90
|
-
<RangeControl
|
|
91
|
-
__next40pxDefaultSize
|
|
92
|
-
label={ __( 'Zoom (%)' ) }
|
|
93
|
-
min={ minZoomPercentage }
|
|
94
|
-
max={ MAX_ZOOM_PERCENTAGE }
|
|
95
|
-
step={ 1 }
|
|
96
|
-
shiftStep={ 10 }
|
|
97
|
-
value={ zoomPercentage }
|
|
98
|
-
onChange={ ( value ) => {
|
|
99
|
-
onPlacementControlInteraction?.();
|
|
100
|
-
setZoom(
|
|
101
|
-
typeof value === 'number'
|
|
102
|
-
? value / ZOOM_PERCENTAGE_SCALE
|
|
103
|
-
: minZoom
|
|
104
|
-
);
|
|
105
|
-
} }
|
|
106
|
-
renderTooltipContent={ ( value ) => {
|
|
107
|
-
const percentage =
|
|
108
|
-
typeof value === 'number'
|
|
109
|
-
? value
|
|
110
|
-
: minZoomPercentage;
|
|
111
|
-
return sprintf(
|
|
112
|
-
/* translators: %d: zoom level as a percentage. */
|
|
113
|
-
__( '%d%%' ),
|
|
114
|
-
Math.round( percentage )
|
|
115
|
-
);
|
|
116
|
-
} }
|
|
117
|
-
/>
|
|
118
|
-
</div>
|
|
119
73
|
</Stack>
|
|
120
74
|
);
|
|
121
75
|
}
|
|
@@ -8,7 +8,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
|
|
|
8
8
|
*/
|
|
9
9
|
import MediaEditorCropPanel from '..';
|
|
10
10
|
import type { MediaEditorCropPanelProps } from '..';
|
|
11
|
-
import { MediaEditorStateProvider
|
|
11
|
+
import { MediaEditorStateProvider } from '../../../state';
|
|
12
12
|
import type { CropperState } from '../../../image-editor';
|
|
13
13
|
|
|
14
14
|
function setupCropPanel(
|
|
@@ -29,31 +29,13 @@ function setupCropPanel(
|
|
|
29
29
|
render(
|
|
30
30
|
<MediaEditorStateProvider initialCropperState={ initialCropperState }>
|
|
31
31
|
<MediaEditorCropPanel { ...props } />
|
|
32
|
-
<CurrentZoomValue />
|
|
33
32
|
</MediaEditorStateProvider>
|
|
34
33
|
);
|
|
35
34
|
|
|
36
35
|
return props;
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
function CurrentZoomValue() {
|
|
40
|
-
const { state } = useMediaEditor();
|
|
41
|
-
|
|
42
|
-
return <output data-testid="current-zoom">{ state.zoom }</output>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
38
|
describe( 'MediaEditorCropPanel', () => {
|
|
46
|
-
it( 'renders crop shape controls before zoom controls', () => {
|
|
47
|
-
setupCropPanel();
|
|
48
|
-
|
|
49
|
-
const aspectRatio = screen.getByLabelText( 'Aspect ratio' );
|
|
50
|
-
const zoom = screen.getByRole( 'slider', { name: 'Zoom (%)' } );
|
|
51
|
-
|
|
52
|
-
expect( aspectRatio.compareDocumentPosition( zoom ) ).toBe(
|
|
53
|
-
Node.DOCUMENT_POSITION_FOLLOWING
|
|
54
|
-
);
|
|
55
|
-
} );
|
|
56
|
-
|
|
57
39
|
it( 'passes selected aspect ratio changes to the caller', () => {
|
|
58
40
|
const controls = setupCropPanel( {
|
|
59
41
|
aspectRatioValue: '1',
|
|
@@ -69,34 +51,36 @@ describe( 'MediaEditorCropPanel', () => {
|
|
|
69
51
|
).toBe( '0' );
|
|
70
52
|
} );
|
|
71
53
|
|
|
72
|
-
it( '
|
|
73
|
-
setupCropPanel(
|
|
54
|
+
it( 'omits the image controls by default', () => {
|
|
55
|
+
setupCropPanel();
|
|
74
56
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
expect( screen.queryByText( 'Rotate' ) ).not.toBeInTheDocument();
|
|
58
|
+
expect( screen.queryByText( 'Flip' ) ).not.toBeInTheDocument();
|
|
59
|
+
expect( screen.queryByText( 'Zoom' ) ).not.toBeInTheDocument();
|
|
60
|
+
} );
|
|
78
61
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
62
|
+
it( 'renders rotate, flip and zoom controls when showTransformControls is set', () => {
|
|
63
|
+
setupCropPanel( { showTransformControls: true } );
|
|
64
|
+
|
|
65
|
+
expect( screen.getByText( 'Rotate' ) ).toBeInTheDocument();
|
|
66
|
+
expect( screen.getByText( 'Flip' ) ).toBeInTheDocument();
|
|
67
|
+
expect( screen.getByText( 'Zoom' ) ).toBeInTheDocument();
|
|
68
|
+
expect(
|
|
69
|
+
screen.getByRole( 'button', { name: 'Rotate 90° clockwise' } )
|
|
70
|
+
).toBeInTheDocument();
|
|
71
|
+
expect(
|
|
72
|
+
screen.getByRole( 'button', { name: 'Zoom in' } )
|
|
73
|
+
).toBeInTheDocument();
|
|
83
74
|
} );
|
|
84
75
|
|
|
85
|
-
it( '
|
|
86
|
-
|
|
87
|
-
onPlacementControlInteraction: jest.fn(),
|
|
88
|
-
} );
|
|
76
|
+
it( 'renders the image controls above the aspect-ratio selector', () => {
|
|
77
|
+
setupCropPanel( { showTransformControls: true } );
|
|
89
78
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
target: { value: '250' },
|
|
94
|
-
}
|
|
95
|
-
);
|
|
79
|
+
const rotate = screen.getByText( 'Rotate' );
|
|
80
|
+
const aspectRatio = screen.getByLabelText( 'Aspect ratio' );
|
|
96
81
|
|
|
97
|
-
expect(
|
|
98
|
-
|
|
82
|
+
expect( rotate.compareDocumentPosition( aspectRatio ) ).toBe(
|
|
83
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
99
84
|
);
|
|
100
|
-
expect( controls.onPlacementControlInteraction ).toHaveBeenCalled();
|
|
101
85
|
} );
|
|
102
86
|
} );
|
|
@@ -17,9 +17,10 @@ export interface MediaEditorFineRotationProps {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Fine-rotation slider for the media
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Fine-rotation slider for the media editor. It renders under the canvas so it
|
|
21
|
+
* stays constrained to the canvas column at all viewport sizes. Lives
|
|
22
|
+
* separately from the snap-rotate / flip buttons so the two can be placed
|
|
23
|
+
* independently per viewport.
|
|
23
24
|
*
|
|
24
25
|
* @param props
|
|
25
26
|
* @param props.onPlacementControlInteraction
|