@wordpress/block-editor 14.7.1-next.082ed6819.0 → 14.8.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-toolbar/index.js +11 -4
  3. package/build/components/block-toolbar/index.js.map +1 -1
  4. package/build/components/iframe/index.js +12 -216
  5. package/build/components/iframe/index.js.map +1 -1
  6. package/build/components/iframe/use-scale-canvas.js +377 -0
  7. package/build/components/iframe/use-scale-canvas.js.map +1 -0
  8. package/build/components/image-editor/use-save-image.js +22 -3
  9. package/build/components/image-editor/use-save-image.js.map +1 -1
  10. package/build-module/components/block-toolbar/index.js +11 -4
  11. package/build-module/components/block-toolbar/index.js.map +1 -1
  12. package/build-module/components/iframe/index.js +14 -218
  13. package/build-module/components/iframe/index.js.map +1 -1
  14. package/build-module/components/iframe/use-scale-canvas.js +371 -0
  15. package/build-module/components/iframe/use-scale-canvas.js.map +1 -0
  16. package/build-module/components/image-editor/use-save-image.js +22 -3
  17. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  18. package/build-style/content-rtl.css +7 -22
  19. package/build-style/content.css +7 -22
  20. package/build-style/style-rtl.css +30 -0
  21. package/build-style/style.css +30 -0
  22. package/package.json +31 -31
  23. package/src/components/block-canvas/style.scss +2 -1
  24. package/src/components/block-toolbar/index.js +8 -0
  25. package/src/components/block-tools/style.scss +39 -0
  26. package/src/components/color-palette/test/__snapshots__/control.js.snap +2 -2
  27. package/src/components/iframe/content.scss +34 -41
  28. package/src/components/iframe/index.js +13 -313
  29. package/src/components/iframe/use-scale-canvas.js +468 -0
  30. package/src/components/image-editor/use-save-image.js +27 -2
@@ -0,0 +1,371 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEffect, useRef, useCallback } from '@wordpress/element';
5
+ import { useReducedMotion, useResizeObserver } from '@wordpress/compose';
6
+
7
+ /**
8
+ * @typedef {Object} TransitionState
9
+ * @property {number} scaleValue Scale of the canvas.
10
+ * @property {number} frameSize Size of the frame/offset around the canvas.
11
+ * @property {number} clientHeight ClientHeight of the iframe.
12
+ * @property {number} scrollTop ScrollTop of the iframe.
13
+ * @property {number} scrollHeight ScrollHeight of the iframe.
14
+ */
15
+
16
+ /**
17
+ * Calculate the scale of the canvas.
18
+ *
19
+ * @param {Object} options Object of options
20
+ * @param {number} options.frameSize Size of the frame/offset around the canvas
21
+ * @param {number} options.containerWidth Actual width of the canvas container
22
+ * @param {number} options.maxContainerWidth Maximum width of the container to use for the scale calculation. This locks the canvas to a maximum width when zooming out.
23
+ * @param {number} options.scaleContainerWidth Width the of the container wrapping the canvas container
24
+ * @return {number} Scale value between 0 and/or equal to 1
25
+ */
26
+ function calculateScale({
27
+ frameSize,
28
+ containerWidth,
29
+ maxContainerWidth,
30
+ scaleContainerWidth
31
+ }) {
32
+ return (Math.min(containerWidth, maxContainerWidth) - frameSize * 2) / scaleContainerWidth;
33
+ }
34
+
35
+ /**
36
+ * Compute the next scrollTop position after scaling the iframe content.
37
+ *
38
+ * @param {TransitionState} transitionFrom Starting point of the transition
39
+ * @param {TransitionState} transitionTo Ending state of the transition
40
+ * @return {number} Next scrollTop position after scaling the iframe content.
41
+ */
42
+ function computeScrollTopNext(transitionFrom, transitionTo) {
43
+ const {
44
+ clientHeight: prevClientHeight,
45
+ frameSize: prevFrameSize,
46
+ scaleValue: prevScale,
47
+ scrollTop,
48
+ scrollHeight
49
+ } = transitionFrom;
50
+ const {
51
+ clientHeight,
52
+ frameSize,
53
+ scaleValue
54
+ } = transitionTo;
55
+ // Step 0: Start with the current scrollTop.
56
+ let scrollTopNext = scrollTop;
57
+ // Step 1: Undo the effects of the previous scale and frame around the
58
+ // midpoint of the visible area.
59
+ scrollTopNext = (scrollTopNext + prevClientHeight / 2 - prevFrameSize) / prevScale - prevClientHeight / 2;
60
+
61
+ // Step 2: Apply the new scale and frame around the midpoint of the
62
+ // visible area.
63
+ scrollTopNext = (scrollTopNext + clientHeight / 2) * scaleValue + frameSize - clientHeight / 2;
64
+
65
+ // Step 3: Handle an edge case so that you scroll to the top of the
66
+ // iframe if the top of the iframe content is visible in the container.
67
+ // The same edge case for the bottom is skipped because changing content
68
+ // makes calculating it impossible.
69
+ scrollTopNext = scrollTop <= prevFrameSize ? 0 : scrollTopNext;
70
+
71
+ // This is the scrollTop value if you are scrolled to the bottom of the
72
+ // iframe. We can't just let the browser handle it because we need to
73
+ // animate the scaling.
74
+ const maxScrollTop = scrollHeight * (scaleValue / prevScale) + frameSize * 2 - clientHeight;
75
+
76
+ // Step 4: Clamp the scrollTopNext between the minimum and maximum
77
+ // possible scrollTop positions. Round the value to avoid subpixel
78
+ // truncation by the browser which sometimes causes a 1px error.
79
+ return Math.round(Math.min(Math.max(0, scrollTopNext), Math.max(0, maxScrollTop)));
80
+ }
81
+
82
+ /**
83
+ * Generate the keyframes to use for the zoom out animation.
84
+ *
85
+ * @param {TransitionState} transitionFrom Starting transition state.
86
+ * @param {TransitionState} transitionTo Ending transition state.
87
+ * @return {Object[]} An array of keyframes to use for the animation.
88
+ */
89
+ function getAnimationKeyframes(transitionFrom, transitionTo) {
90
+ const {
91
+ scaleValue: prevScale,
92
+ frameSize: prevFrameSize,
93
+ scrollTop
94
+ } = transitionFrom;
95
+ const {
96
+ scaleValue,
97
+ frameSize,
98
+ scrollTop: scrollTopNext
99
+ } = transitionTo;
100
+ return [{
101
+ translate: `0 0`,
102
+ scale: prevScale,
103
+ paddingTop: `${prevFrameSize / prevScale}px`,
104
+ paddingBottom: `${prevFrameSize / prevScale}px`
105
+ }, {
106
+ translate: `0 ${scrollTop - scrollTopNext}px`,
107
+ scale: scaleValue,
108
+ paddingTop: `${frameSize / scaleValue}px`,
109
+ paddingBottom: `${frameSize / scaleValue}px`
110
+ }];
111
+ }
112
+
113
+ /**
114
+ * @typedef {Object} ScaleCanvasResult
115
+ * @property {boolean} isZoomedOut A boolean indicating if the canvas is zoomed out.
116
+ * @property {number} scaleContainerWidth The width of the container used to calculate the scale.
117
+ * @property {Object} contentResizeListener A resize observer for the content.
118
+ * @property {Object} containerResizeListener A resize observer for the container.
119
+ */
120
+
121
+ /**
122
+ * Handles scaling the canvas for the zoom out mode and animating between
123
+ * the states.
124
+ *
125
+ * @param {Object} options Object of options.
126
+ * @param {number} options.frameSize Size of the frame around the content.
127
+ * @param {Document} options.iframeDocument Document of the iframe.
128
+ * @param {number} options.maxContainerWidth Max width of the canvas to use as the starting scale point. Defaults to 750.
129
+ * @param {number|string} options.scale Scale of the canvas. Can be an decimal between 0 and 1, 1, or 'auto-scaled'.
130
+ * @return {ScaleCanvasResult} Properties of the result.
131
+ */
132
+ export function useScaleCanvas({
133
+ frameSize,
134
+ iframeDocument,
135
+ maxContainerWidth = 750,
136
+ scale
137
+ }) {
138
+ const [contentResizeListener, {
139
+ height: contentHeight
140
+ }] = useResizeObserver();
141
+ const [containerResizeListener, {
142
+ width: containerWidth
143
+ }] = useResizeObserver();
144
+ const initialContainerWidthRef = useRef(0);
145
+ const isZoomedOut = scale !== 1;
146
+ const prefersReducedMotion = useReducedMotion();
147
+ const isAutoScaled = scale === 'auto-scaled';
148
+ // Track if the animation should start when the useEffect runs.
149
+ const startAnimationRef = useRef(false);
150
+ // Track the animation so we know if we have an animation running,
151
+ // and can cancel it, reverse it, call a finish event, etc.
152
+ const animationRef = useRef(null);
153
+ useEffect(() => {
154
+ if (!isZoomedOut) {
155
+ initialContainerWidthRef.current = containerWidth;
156
+ }
157
+ }, [containerWidth, isZoomedOut]);
158
+ const scaleContainerWidth = Math.max(initialContainerWidthRef.current, containerWidth);
159
+ const scaleValue = isAutoScaled ? calculateScale({
160
+ frameSize,
161
+ containerWidth,
162
+ maxContainerWidth,
163
+ scaleContainerWidth
164
+ }) : scale;
165
+
166
+ /**
167
+ * The starting transition state for the zoom out animation.
168
+ * @type {import('react').RefObject<TransitionState>}
169
+ */
170
+ const transitionFromRef = useRef({
171
+ scaleValue,
172
+ frameSize,
173
+ clientHeight: 0,
174
+ scrollTop: 0,
175
+ scrollHeight: 0
176
+ });
177
+
178
+ /**
179
+ * The ending transition state for the zoom out animation.
180
+ * @type {import('react').RefObject<TransitionState>}
181
+ */
182
+ const transitionToRef = useRef({
183
+ scaleValue,
184
+ frameSize,
185
+ clientHeight: 0,
186
+ scrollTop: 0,
187
+ scrollHeight: 0
188
+ });
189
+
190
+ /**
191
+ * Start the zoom out animation. This sets the necessary CSS variables
192
+ * for animating the canvas and returns the Animation object.
193
+ *
194
+ * @return {Animation} The animation object for the zoom out animation.
195
+ */
196
+ const startZoomOutAnimation = useCallback(() => {
197
+ const {
198
+ scrollTop
199
+ } = transitionFromRef.current;
200
+ const {
201
+ scrollTop: scrollTopNext
202
+ } = transitionToRef.current;
203
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scroll-top', `${scrollTop}px`);
204
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scroll-top-next', `${scrollTopNext}px`);
205
+ iframeDocument.documentElement.classList.add('zoom-out-animation');
206
+ return iframeDocument.documentElement.animate(getAnimationKeyframes(transitionFromRef.current, transitionToRef.current), {
207
+ easing: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)',
208
+ duration: 400
209
+ });
210
+ }, [iframeDocument]);
211
+
212
+ /**
213
+ * Callback when the zoom out animation is finished.
214
+ * - Cleans up animations refs.
215
+ * - Adds final CSS vars for scale and frame size to preserve the state.
216
+ * - Removes the 'zoom-out-animation' class (which has the fixed positioning).
217
+ * - Sets the final scroll position after the canvas is no longer in fixed position.
218
+ * - Removes CSS vars related to the animation.
219
+ * - Sets the transitionFrom to the transitionTo state to be ready for the next animation.
220
+ */
221
+ const finishZoomOutAnimation = useCallback(() => {
222
+ startAnimationRef.current = false;
223
+ animationRef.current = null;
224
+
225
+ // Add our final scale and frame size now that the animation is done.
226
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale', transitionToRef.current.scaleValue);
227
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-frame-size', `${transitionToRef.current.frameSize}px`);
228
+ iframeDocument.documentElement.classList.remove('zoom-out-animation');
229
+
230
+ // Set the final scroll position that was just animated to.
231
+ // Disable reason: Eslint isn't smart enough to know that this is a
232
+ // DOM element. https://github.com/facebook/react/issues/31483
233
+ // eslint-disable-next-line react-compiler/react-compiler
234
+ iframeDocument.documentElement.scrollTop = transitionToRef.current.scrollTop;
235
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scroll-top');
236
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scroll-top-next');
237
+
238
+ // Update previous values.
239
+ transitionFromRef.current = transitionToRef.current;
240
+ }, [iframeDocument]);
241
+
242
+ /**
243
+ * Runs when zoom out mode is toggled, and sets the startAnimation flag
244
+ * so the animation will start when the next useEffect runs. We _only_
245
+ * want to animate when the zoom out mode is toggled, not when the scale
246
+ * changes due to the container resizing.
247
+ */
248
+ useEffect(() => {
249
+ if (!iframeDocument) {
250
+ return;
251
+ }
252
+ if (isZoomedOut) {
253
+ iframeDocument.documentElement.classList.add('is-zoomed-out');
254
+ }
255
+ startAnimationRef.current = true;
256
+ return () => {
257
+ iframeDocument.documentElement.classList.remove('is-zoomed-out');
258
+ };
259
+ }, [iframeDocument, isZoomedOut]);
260
+
261
+ /**
262
+ * This handles:
263
+ * 1. Setting the correct scale and vars of the canvas when zoomed out
264
+ * 2. If zoom out mode has been toggled, runs the animation of zooming in/out
265
+ */
266
+ useEffect(() => {
267
+ if (!iframeDocument) {
268
+ return;
269
+ }
270
+
271
+ // We need to update the appropriate scale to exit from. If sidebars have been opened since setting the
272
+ // original scale, we will snap to a much smaller scale due to the scale container immediately changing sizes when exiting.
273
+ if (isAutoScaled && transitionFromRef.current.scaleValue !== 1) {
274
+ // We use containerWidth as the divisor, as scaleContainerWidth will always match the containerWidth when
275
+ // exiting.
276
+ transitionFromRef.current.scaleValue = calculateScale({
277
+ frameSize: transitionFromRef.current.frameSize,
278
+ containerWidth,
279
+ maxContainerWidth,
280
+ scaleContainerWidth: containerWidth
281
+ });
282
+ }
283
+
284
+ // If we are not going to animate the transition, set the scale and frame size directly.
285
+ // If we are animating, these values will be set when the animation is finished.
286
+ // Example: Opening sidebars that reduce the scale of the canvas, but we don't want to
287
+ // animate the transition.
288
+ if (!startAnimationRef.current) {
289
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale', scaleValue);
290
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-frame-size', `${frameSize}px`);
291
+ }
292
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-content-height', `${contentHeight}px`);
293
+ const clientHeight = iframeDocument.documentElement.clientHeight;
294
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-inner-height', `${clientHeight}px`);
295
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-container-width', `${containerWidth}px`);
296
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale-container-width', `${scaleContainerWidth}px`);
297
+
298
+ /**
299
+ * Handle the zoom out animation:
300
+ *
301
+ * - Get the current scrollTop position.
302
+ * - Calculate where the same scroll position is after scaling.
303
+ * - Apply fixed positioning to the canvas with a transform offset
304
+ * to keep the canvas centered.
305
+ * - Animate the scale and padding to the new scale and frame size.
306
+ * - After the animation is complete, remove the fixed positioning
307
+ * and set the scroll position that keeps everything centered.
308
+ */
309
+ if (startAnimationRef.current) {
310
+ // Don't allow a new transition to start again unless it was started by the zoom out mode changing.
311
+ startAnimationRef.current = false;
312
+
313
+ /**
314
+ * If we already have an animation running, reverse it.
315
+ */
316
+ if (animationRef.current) {
317
+ animationRef.current.reverse();
318
+ // Swap the transition to/from refs so that we set the correct values when
319
+ // finishZoomOutAnimation runs.
320
+ const tempTransitionFrom = transitionFromRef.current;
321
+ const tempTransitionTo = transitionToRef.current;
322
+ transitionFromRef.current = tempTransitionTo;
323
+ transitionToRef.current = tempTransitionFrom;
324
+ } else {
325
+ var _transitionFromRef$cu;
326
+ /**
327
+ * Start a new zoom animation.
328
+ */
329
+
330
+ // We can't trust the set value from contentHeight, as it was measured
331
+ // before the zoom out mode was changed. After zoom out mode is changed,
332
+ // appenders may appear or disappear, so we need to get the height from
333
+ // the iframe at this point when we're about to animate the zoom out.
334
+ // The iframe scrollTop, scrollHeight, and clientHeight will all be
335
+ // the most accurate.
336
+ transitionFromRef.current.clientHeight = (_transitionFromRef$cu = transitionFromRef.current.clientHeight) !== null && _transitionFromRef$cu !== void 0 ? _transitionFromRef$cu : clientHeight;
337
+ transitionFromRef.current.scrollTop = iframeDocument.documentElement.scrollTop;
338
+ transitionFromRef.current.scrollHeight = iframeDocument.documentElement.scrollHeight;
339
+ transitionToRef.current = {
340
+ scaleValue,
341
+ frameSize,
342
+ clientHeight
343
+ };
344
+ transitionToRef.current.scrollTop = computeScrollTopNext(transitionFromRef.current, transitionToRef.current);
345
+ animationRef.current = startZoomOutAnimation();
346
+
347
+ // If the user prefers reduced motion, finish the animation immediately and set the final state.
348
+ if (prefersReducedMotion) {
349
+ finishZoomOutAnimation();
350
+ } else {
351
+ animationRef.current.onfinish = finishZoomOutAnimation;
352
+ }
353
+ }
354
+ }
355
+ return () => {
356
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scale');
357
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-frame-size');
358
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-content-height');
359
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-inner-height');
360
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-container-width');
361
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scale-container-width');
362
+ };
363
+ }, [startZoomOutAnimation, finishZoomOutAnimation, prefersReducedMotion, isAutoScaled, scaleValue, frameSize, iframeDocument, contentHeight, containerWidth, maxContainerWidth, scaleContainerWidth]);
364
+ return {
365
+ isZoomedOut,
366
+ scaleContainerWidth,
367
+ contentResizeListener,
368
+ containerResizeListener
369
+ };
370
+ }
371
+ //# sourceMappingURL=use-scale-canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useRef","useCallback","useReducedMotion","useResizeObserver","calculateScale","frameSize","containerWidth","maxContainerWidth","scaleContainerWidth","Math","min","computeScrollTopNext","transitionFrom","transitionTo","clientHeight","prevClientHeight","prevFrameSize","scaleValue","prevScale","scrollTop","scrollHeight","scrollTopNext","maxScrollTop","round","max","getAnimationKeyframes","translate","scale","paddingTop","paddingBottom","useScaleCanvas","iframeDocument","contentResizeListener","height","contentHeight","containerResizeListener","width","initialContainerWidthRef","isZoomedOut","prefersReducedMotion","isAutoScaled","startAnimationRef","animationRef","current","transitionFromRef","transitionToRef","startZoomOutAnimation","documentElement","style","setProperty","classList","add","animate","easing","duration","finishZoomOutAnimation","remove","removeProperty","reverse","tempTransitionFrom","tempTransitionTo","_transitionFromRef$cu","onfinish"],"sources":["@wordpress/block-editor/src/components/iframe/use-scale-canvas.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef, useCallback } from '@wordpress/element';\nimport { useReducedMotion, useResizeObserver } from '@wordpress/compose';\n\n/**\n * @typedef {Object} TransitionState\n * @property {number} scaleValue Scale of the canvas.\n * @property {number} frameSize Size of the frame/offset around the canvas.\n * @property {number} clientHeight ClientHeight of the iframe.\n * @property {number} scrollTop ScrollTop of the iframe.\n * @property {number} scrollHeight ScrollHeight of the iframe.\n */\n\n/**\n * Calculate the scale of the canvas.\n *\n * @param {Object} options Object of options\n * @param {number} options.frameSize Size of the frame/offset around the canvas\n * @param {number} options.containerWidth Actual width of the canvas container\n * @param {number} options.maxContainerWidth Maximum width of the container to use for the scale calculation. This locks the canvas to a maximum width when zooming out.\n * @param {number} options.scaleContainerWidth Width the of the container wrapping the canvas container\n * @return {number} Scale value between 0 and/or equal to 1\n */\nfunction calculateScale( {\n\tframeSize,\n\tcontainerWidth,\n\tmaxContainerWidth,\n\tscaleContainerWidth,\n} ) {\n\treturn (\n\t\t( Math.min( containerWidth, maxContainerWidth ) - frameSize * 2 ) /\n\t\tscaleContainerWidth\n\t);\n}\n\n/**\n * Compute the next scrollTop position after scaling the iframe content.\n *\n * @param {TransitionState} transitionFrom Starting point of the transition\n * @param {TransitionState} transitionTo Ending state of the transition\n * @return {number} Next scrollTop position after scaling the iframe content.\n */\nfunction computeScrollTopNext( transitionFrom, transitionTo ) {\n\tconst {\n\t\tclientHeight: prevClientHeight,\n\t\tframeSize: prevFrameSize,\n\t\tscaleValue: prevScale,\n\t\tscrollTop,\n\t\tscrollHeight,\n\t} = transitionFrom;\n\tconst { clientHeight, frameSize, scaleValue } = transitionTo;\n\t// Step 0: Start with the current scrollTop.\n\tlet scrollTopNext = scrollTop;\n\t// Step 1: Undo the effects of the previous scale and frame around the\n\t// midpoint of the visible area.\n\tscrollTopNext =\n\t\t( scrollTopNext + prevClientHeight / 2 - prevFrameSize ) / prevScale -\n\t\tprevClientHeight / 2;\n\n\t// Step 2: Apply the new scale and frame around the midpoint of the\n\t// visible area.\n\tscrollTopNext =\n\t\t( scrollTopNext + clientHeight / 2 ) * scaleValue +\n\t\tframeSize -\n\t\tclientHeight / 2;\n\n\t// Step 3: Handle an edge case so that you scroll to the top of the\n\t// iframe if the top of the iframe content is visible in the container.\n\t// The same edge case for the bottom is skipped because changing content\n\t// makes calculating it impossible.\n\tscrollTopNext = scrollTop <= prevFrameSize ? 0 : scrollTopNext;\n\n\t// This is the scrollTop value if you are scrolled to the bottom of the\n\t// iframe. We can't just let the browser handle it because we need to\n\t// animate the scaling.\n\tconst maxScrollTop =\n\t\tscrollHeight * ( scaleValue / prevScale ) +\n\t\tframeSize * 2 -\n\t\tclientHeight;\n\n\t// Step 4: Clamp the scrollTopNext between the minimum and maximum\n\t// possible scrollTop positions. Round the value to avoid subpixel\n\t// truncation by the browser which sometimes causes a 1px error.\n\treturn Math.round(\n\t\tMath.min( Math.max( 0, scrollTopNext ), Math.max( 0, maxScrollTop ) )\n\t);\n}\n\n/**\n * Generate the keyframes to use for the zoom out animation.\n *\n * @param {TransitionState} transitionFrom Starting transition state.\n * @param {TransitionState} transitionTo Ending transition state.\n * @return {Object[]} An array of keyframes to use for the animation.\n */\nfunction getAnimationKeyframes( transitionFrom, transitionTo ) {\n\tconst {\n\t\tscaleValue: prevScale,\n\t\tframeSize: prevFrameSize,\n\t\tscrollTop,\n\t} = transitionFrom;\n\tconst { scaleValue, frameSize, scrollTop: scrollTopNext } = transitionTo;\n\n\treturn [\n\t\t{\n\t\t\ttranslate: `0 0`,\n\t\t\tscale: prevScale,\n\t\t\tpaddingTop: `${ prevFrameSize / prevScale }px`,\n\t\t\tpaddingBottom: `${ prevFrameSize / prevScale }px`,\n\t\t},\n\t\t{\n\t\t\ttranslate: `0 ${ scrollTop - scrollTopNext }px`,\n\t\t\tscale: scaleValue,\n\t\t\tpaddingTop: `${ frameSize / scaleValue }px`,\n\t\t\tpaddingBottom: `${ frameSize / scaleValue }px`,\n\t\t},\n\t];\n}\n\n/**\n * @typedef {Object} ScaleCanvasResult\n * @property {boolean} isZoomedOut A boolean indicating if the canvas is zoomed out.\n * @property {number} scaleContainerWidth The width of the container used to calculate the scale.\n * @property {Object} contentResizeListener A resize observer for the content.\n * @property {Object} containerResizeListener A resize observer for the container.\n */\n\n/**\n * Handles scaling the canvas for the zoom out mode and animating between\n * the states.\n *\n * @param {Object} options Object of options.\n * @param {number} options.frameSize Size of the frame around the content.\n * @param {Document} options.iframeDocument Document of the iframe.\n * @param {number} options.maxContainerWidth Max width of the canvas to use as the starting scale point. Defaults to 750.\n * @param {number|string} options.scale Scale of the canvas. Can be an decimal between 0 and 1, 1, or 'auto-scaled'.\n * @return {ScaleCanvasResult} Properties of the result.\n */\nexport function useScaleCanvas( {\n\tframeSize,\n\tiframeDocument,\n\tmaxContainerWidth = 750,\n\tscale,\n} ) {\n\tconst [ contentResizeListener, { height: contentHeight } ] =\n\t\tuseResizeObserver();\n\tconst [ containerResizeListener, { width: containerWidth } ] =\n\t\tuseResizeObserver();\n\n\tconst initialContainerWidthRef = useRef( 0 );\n\tconst isZoomedOut = scale !== 1;\n\tconst prefersReducedMotion = useReducedMotion();\n\tconst isAutoScaled = scale === 'auto-scaled';\n\t// Track if the animation should start when the useEffect runs.\n\tconst startAnimationRef = useRef( false );\n\t// Track the animation so we know if we have an animation running,\n\t// and can cancel it, reverse it, call a finish event, etc.\n\tconst animationRef = useRef( null );\n\n\tuseEffect( () => {\n\t\tif ( ! isZoomedOut ) {\n\t\t\tinitialContainerWidthRef.current = containerWidth;\n\t\t}\n\t}, [ containerWidth, isZoomedOut ] );\n\n\tconst scaleContainerWidth = Math.max(\n\t\tinitialContainerWidthRef.current,\n\t\tcontainerWidth\n\t);\n\n\tconst scaleValue = isAutoScaled\n\t\t? calculateScale( {\n\t\t\t\tframeSize,\n\t\t\t\tcontainerWidth,\n\t\t\t\tmaxContainerWidth,\n\t\t\t\tscaleContainerWidth,\n\t\t } )\n\t\t: scale;\n\n\t/**\n\t * The starting transition state for the zoom out animation.\n\t * @type {import('react').RefObject<TransitionState>}\n\t */\n\tconst transitionFromRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tclientHeight: 0,\n\t\tscrollTop: 0,\n\t\tscrollHeight: 0,\n\t} );\n\n\t/**\n\t * The ending transition state for the zoom out animation.\n\t * @type {import('react').RefObject<TransitionState>}\n\t */\n\tconst transitionToRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tclientHeight: 0,\n\t\tscrollTop: 0,\n\t\tscrollHeight: 0,\n\t} );\n\n\t/**\n\t * Start the zoom out animation. This sets the necessary CSS variables\n\t * for animating the canvas and returns the Animation object.\n\t *\n\t * @return {Animation} The animation object for the zoom out animation.\n\t */\n\tconst startZoomOutAnimation = useCallback( () => {\n\t\tconst { scrollTop } = transitionFromRef.current;\n\t\tconst { scrollTop: scrollTopNext } = transitionToRef.current;\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top',\n\t\t\t`${ scrollTop }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top-next',\n\t\t\t`${ scrollTopNext }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.classList.add( 'zoom-out-animation' );\n\n\t\treturn iframeDocument.documentElement.animate(\n\t\t\tgetAnimationKeyframes(\n\t\t\t\ttransitionFromRef.current,\n\t\t\t\ttransitionToRef.current\n\t\t\t),\n\t\t\t{\n\t\t\t\teasing: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)',\n\t\t\t\tduration: 400,\n\t\t\t}\n\t\t);\n\t}, [ iframeDocument ] );\n\n\t/**\n\t * Callback when the zoom out animation is finished.\n\t * - Cleans up animations refs.\n\t * - Adds final CSS vars for scale and frame size to preserve the state.\n\t * - Removes the 'zoom-out-animation' class (which has the fixed positioning).\n\t * - Sets the final scroll position after the canvas is no longer in fixed position.\n\t * - Removes CSS vars related to the animation.\n\t * - Sets the transitionFrom to the transitionTo state to be ready for the next animation.\n\t */\n\tconst finishZoomOutAnimation = useCallback( () => {\n\t\tstartAnimationRef.current = false;\n\t\tanimationRef.current = null;\n\n\t\t// Add our final scale and frame size now that the animation is done.\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\ttransitionToRef.current.scaleValue\n\t\t);\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t`${ transitionToRef.current.frameSize }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.classList.remove( 'zoom-out-animation' );\n\n\t\t// Set the final scroll position that was just animated to.\n\t\t// Disable reason: Eslint isn't smart enough to know that this is a\n\t\t// DOM element. https://github.com/facebook/react/issues/31483\n\t\t// eslint-disable-next-line react-compiler/react-compiler\n\t\tiframeDocument.documentElement.scrollTop =\n\t\t\ttransitionToRef.current.scrollTop;\n\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top'\n\t\t);\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top-next'\n\t\t);\n\n\t\t// Update previous values.\n\t\ttransitionFromRef.current = transitionToRef.current;\n\t}, [ iframeDocument ] );\n\n\t/**\n\t * Runs when zoom out mode is toggled, and sets the startAnimation flag\n\t * so the animation will start when the next useEffect runs. We _only_\n\t * want to animate when the zoom out mode is toggled, not when the scale\n\t * changes due to the container resizing.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! iframeDocument ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isZoomedOut ) {\n\t\t\tiframeDocument.documentElement.classList.add( 'is-zoomed-out' );\n\t\t}\n\n\t\tstartAnimationRef.current = true;\n\n\t\treturn () => {\n\t\t\tiframeDocument.documentElement.classList.remove( 'is-zoomed-out' );\n\t\t};\n\t}, [ iframeDocument, isZoomedOut ] );\n\n\t/**\n\t * This handles:\n\t * 1. Setting the correct scale and vars of the canvas when zoomed out\n\t * 2. If zoom out mode has been toggled, runs the animation of zooming in/out\n\t */\n\tuseEffect( () => {\n\t\tif ( ! iframeDocument ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We need to update the appropriate scale to exit from. If sidebars have been opened since setting the\n\t\t// original scale, we will snap to a much smaller scale due to the scale container immediately changing sizes when exiting.\n\t\tif ( isAutoScaled && transitionFromRef.current.scaleValue !== 1 ) {\n\t\t\t// We use containerWidth as the divisor, as scaleContainerWidth will always match the containerWidth when\n\t\t\t// exiting.\n\t\t\ttransitionFromRef.current.scaleValue = calculateScale( {\n\t\t\t\tframeSize: transitionFromRef.current.frameSize,\n\t\t\t\tcontainerWidth,\n\t\t\t\tmaxContainerWidth,\n\t\t\t\tscaleContainerWidth: containerWidth,\n\t\t\t} );\n\t\t}\n\n\t\t// If we are not going to animate the transition, set the scale and frame size directly.\n\t\t// If we are animating, these values will be set when the animation is finished.\n\t\t// Example: Opening sidebars that reduce the scale of the canvas, but we don't want to\n\t\t// animate the transition.\n\t\tif ( ! startAnimationRef.current ) {\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\t\tscaleValue\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t\t`${ frameSize }px`\n\t\t\t);\n\t\t}\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-content-height',\n\t\t\t`${ contentHeight }px`\n\t\t);\n\n\t\tconst clientHeight = iframeDocument.documentElement.clientHeight;\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-inner-height',\n\t\t\t`${ clientHeight }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-container-width',\n\t\t\t`${ containerWidth }px`\n\t\t);\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width',\n\t\t\t`${ scaleContainerWidth }px`\n\t\t);\n\n\t\t/**\n\t\t * Handle the zoom out animation:\n\t\t *\n\t\t * - Get the current scrollTop position.\n\t\t * - Calculate where the same scroll position is after scaling.\n\t\t * - Apply fixed positioning to the canvas with a transform offset\n\t\t * to keep the canvas centered.\n\t\t * - Animate the scale and padding to the new scale and frame size.\n\t\t * - After the animation is complete, remove the fixed positioning\n\t\t * and set the scroll position that keeps everything centered.\n\t\t */\n\t\tif ( startAnimationRef.current ) {\n\t\t\t// Don't allow a new transition to start again unless it was started by the zoom out mode changing.\n\t\t\tstartAnimationRef.current = false;\n\n\t\t\t/**\n\t\t\t * If we already have an animation running, reverse it.\n\t\t\t */\n\t\t\tif ( animationRef.current ) {\n\t\t\t\tanimationRef.current.reverse();\n\t\t\t\t// Swap the transition to/from refs so that we set the correct values when\n\t\t\t\t// finishZoomOutAnimation runs.\n\t\t\t\tconst tempTransitionFrom = transitionFromRef.current;\n\t\t\t\tconst tempTransitionTo = transitionToRef.current;\n\t\t\t\ttransitionFromRef.current = tempTransitionTo;\n\t\t\t\ttransitionToRef.current = tempTransitionFrom;\n\t\t\t} else {\n\t\t\t\t/**\n\t\t\t\t * Start a new zoom animation.\n\t\t\t\t */\n\n\t\t\t\t// We can't trust the set value from contentHeight, as it was measured\n\t\t\t\t// before the zoom out mode was changed. After zoom out mode is changed,\n\t\t\t\t// appenders may appear or disappear, so we need to get the height from\n\t\t\t\t// the iframe at this point when we're about to animate the zoom out.\n\t\t\t\t// The iframe scrollTop, scrollHeight, and clientHeight will all be\n\t\t\t\t// the most accurate.\n\t\t\t\ttransitionFromRef.current.clientHeight =\n\t\t\t\t\ttransitionFromRef.current.clientHeight ?? clientHeight;\n\t\t\t\ttransitionFromRef.current.scrollTop =\n\t\t\t\t\tiframeDocument.documentElement.scrollTop;\n\t\t\t\ttransitionFromRef.current.scrollHeight =\n\t\t\t\t\tiframeDocument.documentElement.scrollHeight;\n\n\t\t\t\ttransitionToRef.current = {\n\t\t\t\t\tscaleValue,\n\t\t\t\t\tframeSize,\n\t\t\t\t\tclientHeight,\n\t\t\t\t};\n\t\t\t\ttransitionToRef.current.scrollTop = computeScrollTopNext(\n\t\t\t\t\ttransitionFromRef.current,\n\t\t\t\t\ttransitionToRef.current\n\t\t\t\t);\n\n\t\t\t\tanimationRef.current = startZoomOutAnimation();\n\n\t\t\t\t// If the user prefers reduced motion, finish the animation immediately and set the final state.\n\t\t\t\tif ( prefersReducedMotion ) {\n\t\t\t\t\tfinishZoomOutAnimation();\n\t\t\t\t} else {\n\t\t\t\t\tanimationRef.current.onfinish = finishZoomOutAnimation;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn () => {\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-content-height'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-inner-height'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-container-width'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width'\n\t\t\t);\n\t\t};\n\t}, [\n\t\tstartZoomOutAnimation,\n\t\tfinishZoomOutAnimation,\n\t\tprefersReducedMotion,\n\t\tisAutoScaled,\n\t\tscaleValue,\n\t\tframeSize,\n\t\tiframeDocument,\n\t\tcontentHeight,\n\t\tcontainerWidth,\n\t\tmaxContainerWidth,\n\t\tscaleContainerWidth,\n\t] );\n\n\treturn {\n\t\tisZoomedOut,\n\t\tscaleContainerWidth,\n\t\tcontentResizeListener,\n\t\tcontainerResizeListener,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,EAAEC,WAAW,QAAQ,oBAAoB;AACnE,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,oBAAoB;;AAExE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAAE;EACxBC,SAAS;EACTC,cAAc;EACdC,iBAAiB;EACjBC;AACD,CAAC,EAAG;EACH,OACC,CA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EAAG;UAC3BgB,sBAAsB,CAAC,CAAC;QACzB,CAAC,MAAM;UACNb,YAAY,CAACC,OAAO,CAACmB,QAAQ,GAAGP,sBAAsB;QACvD;MACD;IACD;IAEA,OAAO,MAAM;MACZxB,cAAc,CAACgB,eAAe,CAACC,KAAK,CAACS,cAAc,CAClD,yCACD,CAAC;MACD1B,cAAc,CAACgB,eAAe,CAACC,KAAK,CAACS,cAAc,CAClD,8CACD,CAAC;MACD1B,cAAc,CAACgB,eAAe,CAACC,KAAK,CAACS,cAAc,CAClD,kDACD,CAAC;MACD1B,cAAc,CAACgB,eAAe,CAACC,KAAK,CAACS,cAAc,CAClD,gDACD,CAAC;MACD1B,cAAc,CAACgB,eAAe,CAACC,KAAK,CAACS,cAAc,CAClD,mDACD,CAAC;MACD1B,cAAc,CAACgB,eAAe,CAACC,KAAK,CAACS,cAAc,CAClD,yDACD,CAAC;IACF,CAAC;EACF,CAAC,EAAE,CACFX,qBAAqB,EACrBS,sBAAsB,EACtBhB,oBAAoB,EACpBC,YAAY,EACZvB,UAAU,EACVZ,SAAS,EACT0B,cAAc,EACdG,aAAa,EACb5B,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,CAClB,CAAC;EAEH,OAAO;IACN8B,WAAW;IACX9B,mBAAmB;IACnBwB,qBAAqB;IACrBG;EACD,CAAC;AACF","ignoreList":[]}
@@ -9,6 +9,11 @@ import { useCallback, useMemo, useState } from '@wordpress/element';
9
9
  import { __, sprintf } from '@wordpress/i18n';
10
10
  import { store as noticesStore } from '@wordpress/notices';
11
11
  import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
12
+ const messages = {
13
+ crop: __('Image cropped.'),
14
+ rotate: __('Image rotated.'),
15
+ cropAndRotate: __('Image cropped and rotated.')
16
+ };
12
17
  export default function useSaveImage({
13
18
  crop,
14
19
  rotation,
@@ -18,7 +23,8 @@ export default function useSaveImage({
18
23
  onFinishEditing
19
24
  }) {
20
25
  const {
21
- createErrorNotice
26
+ createErrorNotice,
27
+ createSuccessNotice
22
28
  } = useDispatch(noticesStore);
23
29
  const [isInProgress, setIsInProgress] = useState(false);
24
30
  const cancel = useCallback(() => {
@@ -56,6 +62,7 @@ export default function useSaveImage({
56
62
  onFinishEditing();
57
63
  return;
58
64
  }
65
+ const modifierType = modifiers.length === 1 ? modifiers[0].type : 'cropAndRotate';
59
66
  apiFetch({
60
67
  path: `/wp/v2/media/${id}/edit`,
61
68
  method: 'POST',
@@ -68,8 +75,20 @@ export default function useSaveImage({
68
75
  id: response.id,
69
76
  url: response.source_url
70
77
  });
78
+ createSuccessNotice(messages[modifierType], {
79
+ type: 'snackbar',
80
+ actions: [{
81
+ label: __('Undo'),
82
+ onClick: () => {
83
+ onSaveImage({
84
+ id,
85
+ url
86
+ });
87
+ }
88
+ }]
89
+ });
71
90
  }).catch(error => {
72
- createErrorNotice(sprintf(/* translators: 1. Error message */
91
+ createErrorNotice(sprintf(/* translators: %s: Error message. */
73
92
  __('Could not edit image. %s'), stripHTML(error.message)), {
74
93
  id: 'image-editing-error',
75
94
  type: 'snackbar'
@@ -78,7 +97,7 @@ export default function useSaveImage({
78
97
  setIsInProgress(false);
79
98
  onFinishEditing();
80
99
  });
81
- }, [crop, rotation, id, url, onSaveImage, createErrorNotice, onFinishEditing]);
100
+ }, [crop, rotation, id, url, onSaveImage, createErrorNotice, createSuccessNotice, onFinishEditing]);
82
101
  return useMemo(() => ({
83
102
  isInProgress,
84
103
  apply,
@@ -1 +1 @@
1
- {"version":3,"names":["apiFetch","useDispatch","useCallback","useMemo","useState","__","sprintf","store","noticesStore","__unstableStripHTML","stripHTML","useSaveImage","crop","rotation","url","id","onSaveImage","onFinishEditing","createErrorNotice","isInProgress","setIsInProgress","cancel","apply","modifiers","push","type","args","angle","width","height","left","x","top","y","length","path","method","data","src","then","response","source_url","catch","error","message","finally"],"sources":["@wordpress/block-editor/src/components/image-editor/use-save-image.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n// Disable Reason: Needs to be refactored.\n// eslint-disable-next-line no-restricted-imports\nimport apiFetch from '@wordpress/api-fetch';\nimport { useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\nexport default function useSaveImage( {\n\tcrop,\n\trotation,\n\turl,\n\tid,\n\tonSaveImage,\n\tonFinishEditing,\n} ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst [ isInProgress, setIsInProgress ] = useState( false );\n\n\tconst cancel = useCallback( () => {\n\t\tsetIsInProgress( false );\n\t\tonFinishEditing();\n\t}, [ onFinishEditing ] );\n\n\tconst apply = useCallback( () => {\n\t\tsetIsInProgress( true );\n\n\t\tconst modifiers = [];\n\n\t\tif ( rotation > 0 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'rotate',\n\t\t\t\targs: {\n\t\t\t\t\tangle: rotation,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The crop script may return some very small, sub-pixel values when the image was not cropped.\n\t\t// Crop only when the new size has changed by more than 0.1%.\n\t\tif ( crop.width < 99.9 || crop.height < 99.9 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'crop',\n\t\t\t\targs: {\n\t\t\t\t\tleft: crop.x,\n\t\t\t\t\ttop: crop.y,\n\t\t\t\t\twidth: crop.width,\n\t\t\t\t\theight: crop.height,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tif ( modifiers.length === 0 ) {\n\t\t\t// No changes to apply.\n\t\t\tsetIsInProgress( false );\n\t\t\tonFinishEditing();\n\t\t\treturn;\n\t\t}\n\n\t\tapiFetch( {\n\t\t\tpath: `/wp/v2/media/${ id }/edit`,\n\t\t\tmethod: 'POST',\n\t\t\tdata: { src: url, modifiers },\n\t\t} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tonSaveImage( {\n\t\t\t\t\tid: response.id,\n\t\t\t\t\turl: response.source_url,\n\t\t\t\t} );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: 1. Error message */\n\t\t\t\t\t\t__( 'Could not edit image. %s' ),\n\t\t\t\t\t\tstripHTML( error.message )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'image-editing-error',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tsetIsInProgress( false );\n\t\t\t\tonFinishEditing();\n\t\t\t} );\n\t}, [\n\t\tcrop,\n\t\trotation,\n\t\tid,\n\t\turl,\n\t\tonSaveImage,\n\t\tcreateErrorNotice,\n\t\tonFinishEditing,\n\t] );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tisInProgress,\n\t\t\tapply,\n\t\t\tcancel,\n\t\t} ),\n\t\t[ isInProgress, apply, cancel ]\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,sBAAsB;AAC3C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,mBAAmB,IAAIC,SAAS,QAAQ,gBAAgB;AAEjE,eAAe,SAASC,YAAYA,CAAE;EACrCC,IAAI;EACJC,QAAQ;EACRC,GAAG;EACHC,EAAE;EACFC,WAAW;EACXC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAkB,CAAC,GAAGjB,WAAW,CAAEO,YAAa,CAAC;EACzD,MAAM,CAAEW,YAAY,EAAEC,eAAe,CAAE,GAAGhB,QAAQ,CAAE,KAAM,CAAC;EAE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,KAAK,CAAIC,KAAK,IAAM;MACpBzB,iBAAiB,CAChBZ,OAAO,CACN;MACAD,EAAE,CAAE,0BAA2B,CAAC,EAChCK,SAAS,CAAEiC,KAAK,CAACC,OAAQ,CAC1B,CAAC,EACD;QACC7B,EAAE,EAAE,qBAAqB;QACzBU,IAAI,EAAE;MACP,CACD,CAAC;IACF,CAAE,CAAC,CACFoB,OAAO,CAAE,MAAM;MACfzB,eAAe,CAAE,KAAM,CAAC;MACxBH,eAAe,CAAC,CAAC;IAClB,CAAE,CAAC;EACL,CAAC,EAAE,CACFL,IAAI,EACJC,QAAQ,EACRE,EAAE,EACFD,GAAG,EACHE,WAAW,EACXE,iBAAiB,EACjBD,eAAe,CACd,CAAC;EAEH,OAAOd,OAAO,CACb,OAAQ;IACPgB,YAAY;IACZG,KAAK;IACLD;EACD,CAAC,CAAE,EACH,CAAEF,YAAY,EAAEG,KAAK,EAAED,MAAM,CAC9B,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["apiFetch","useDispatch","useCallback","useMemo","useState","__","sprintf","store","noticesStore","__unstableStripHTML","stripHTML","messages","crop","rotate","cropAndRotate","useSaveImage","rotation","url","id","onSaveImage","onFinishEditing","createErrorNotice","createSuccessNotice","isInProgress","setIsInProgress","cancel","apply","modifiers","push","type","args","angle","width","height","left","x","top","y","length","modifierType","path","method","data","src","then","response","source_url","actions","label","onClick","catch","error","message","finally"],"sources":["@wordpress/block-editor/src/components/image-editor/use-save-image.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n// Disable Reason: Needs to be refactored.\n// eslint-disable-next-line no-restricted-imports\nimport apiFetch from '@wordpress/api-fetch';\nimport { useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\nconst messages = {\n\tcrop: __( 'Image cropped.' ),\n\trotate: __( 'Image rotated.' ),\n\tcropAndRotate: __( 'Image cropped and rotated.' ),\n};\n\nexport default function useSaveImage( {\n\tcrop,\n\trotation,\n\turl,\n\tid,\n\tonSaveImage,\n\tonFinishEditing,\n} ) {\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst [ isInProgress, setIsInProgress ] = useState( false );\n\n\tconst cancel = useCallback( () => {\n\t\tsetIsInProgress( false );\n\t\tonFinishEditing();\n\t}, [ onFinishEditing ] );\n\n\tconst apply = useCallback( () => {\n\t\tsetIsInProgress( true );\n\n\t\tconst modifiers = [];\n\n\t\tif ( rotation > 0 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'rotate',\n\t\t\t\targs: {\n\t\t\t\t\tangle: rotation,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The crop script may return some very small, sub-pixel values when the image was not cropped.\n\t\t// Crop only when the new size has changed by more than 0.1%.\n\t\tif ( crop.width < 99.9 || crop.height < 99.9 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'crop',\n\t\t\t\targs: {\n\t\t\t\t\tleft: crop.x,\n\t\t\t\t\ttop: crop.y,\n\t\t\t\t\twidth: crop.width,\n\t\t\t\t\theight: crop.height,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tif ( modifiers.length === 0 ) {\n\t\t\t// No changes to apply.\n\t\t\tsetIsInProgress( false );\n\t\t\tonFinishEditing();\n\t\t\treturn;\n\t\t}\n\n\t\tconst modifierType =\n\t\t\tmodifiers.length === 1 ? modifiers[ 0 ].type : 'cropAndRotate';\n\n\t\tapiFetch( {\n\t\t\tpath: `/wp/v2/media/${ id }/edit`,\n\t\t\tmethod: 'POST',\n\t\t\tdata: { src: url, modifiers },\n\t\t} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tonSaveImage( {\n\t\t\t\t\tid: response.id,\n\t\t\t\t\turl: response.source_url,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( messages[ modifierType ], {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\tonSaveImage( {\n\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t} );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t__( 'Could not edit image. %s' ),\n\t\t\t\t\t\tstripHTML( error.message )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'image-editing-error',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tsetIsInProgress( false );\n\t\t\t\tonFinishEditing();\n\t\t\t} );\n\t}, [\n\t\tcrop,\n\t\trotation,\n\t\tid,\n\t\turl,\n\t\tonSaveImage,\n\t\tcreateErrorNotice,\n\t\tcreateSuccessNotice,\n\t\tonFinishEditing,\n\t] );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tisInProgress,\n\t\t\tapply,\n\t\t\tcancel,\n\t\t} ),\n\t\t[ isInProgress, apply, cancel ]\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,sBAAsB;AAC3C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,mBAAmB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,CACFR,IAAI,EACJI,QAAQ,EACRE,EAAE,EACFD,GAAG,EACHE,WAAW,EACXE,iBAAiB,EACjBC,mBAAmB,EACnBF,eAAe,CACd,CAAC;EAEH,OAAOjB,OAAO,CACb,OAAQ;IACPoB,YAAY;IACZG,KAAK;IACLD;EACD,CAAC,CAAE,EACH,CAAEF,YAAY,EAAEG,KAAK,EAAED,MAAM,CAC9B,CAAC;AACF","ignoreList":[]}
@@ -777,13 +777,7 @@ _::-webkit-full-page-media, _:future, :root [data-has-multi-selection=true] .blo
777
777
 
778
778
  .block-editor-iframe__html {
779
779
  transform-origin: top center;
780
- transition: all 400ms cubic-bezier(0.46, 0.03, 0.52, 0.96), transform 0s, scale 0s, padding 0s, translate 0s;
781
- }
782
- @media (prefers-reduced-motion: reduce) {
783
- .block-editor-iframe__html {
784
- transition-duration: 0s;
785
- transition-delay: 0s;
786
- }
780
+ transition: background-color 400ms;
787
781
  }
788
782
  .block-editor-iframe__html.zoom-out-animation {
789
783
  position: fixed;
@@ -791,27 +785,18 @@ _::-webkit-full-page-media, _:future, :root [data-has-multi-selection=true] .blo
791
785
  left: 0;
792
786
  top: calc(-1 * var(--wp-block-editor-iframe-zoom-out-scroll-top, 0));
793
787
  bottom: 0;
794
- translate: 0 calc(var(--wp-block-editor-iframe-zoom-out-scroll-top, 0) - var(--wp-block-editor-iframe-zoom-out-scroll-top-next, 0));
795
788
  overflow-y: scroll;
796
- transition: all 400ms cubic-bezier(0.46, 0.03, 0.52, 0.96), transform 0s, top 0s, bottom 0s, left 0s, right 0s;
797
789
  }
798
- @media (prefers-reduced-motion: reduce) {
799
- .block-editor-iframe__html.zoom-out-animation {
800
- transition-duration: 0s;
801
- transition-delay: 0s;
802
- }
803
- }
804
-
805
790
  .block-editor-iframe__html.is-zoomed-out {
806
- transform: translateX(calc(-1*((var(--wp-block-editor-iframe-zoom-out-scale-container-width) - var(--wp-block-editor-iframe-zoom-out-container-width, 100vw)) / 2 / var(--wp-block-editor-iframe-zoom-out-scale))));
807
- scale: var(--wp-block-editor-iframe-zoom-out-scale);
791
+ transform: translateX(calc(-1*((var(--wp-block-editor-iframe-zoom-out-scale-container-width) - var(--wp-block-editor-iframe-zoom-out-container-width, 100vw)) / 2 / var(--wp-block-editor-iframe-zoom-out-scale, 1))));
792
+ scale: var(--wp-block-editor-iframe-zoom-out-scale, 1);
808
793
  background-color: #ddd;
809
- margin-bottom: calc(-1 * calc(calc(var(--wp-block-editor-iframe-zoom-out-content-height) * (1 - var(--wp-block-editor-iframe-zoom-out-scale))) + calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale)) + 2px));
810
- padding-top: calc(var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale));
811
- padding-bottom: calc(var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale));
794
+ margin-bottom: calc(-1 * calc(calc(var(--wp-block-editor-iframe-zoom-out-content-height) * (1 - var(--wp-block-editor-iframe-zoom-out-scale, 1))) + calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1)) + 2px));
795
+ padding-top: calc(var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
796
+ padding-bottom: calc(var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
812
797
  }
813
798
  .block-editor-iframe__html.is-zoomed-out body {
814
- min-height: calc((var(--wp-block-editor-iframe-zoom-out-inner-height) - calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale))) / var(--wp-block-editor-iframe-zoom-out-scale));
799
+ min-height: calc((var(--wp-block-editor-iframe-zoom-out-inner-height) - calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1))) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
815
800
  }
816
801
  .block-editor-iframe__html.is-zoomed-out body > .is-root-container:not(.wp-block-post-content) {
817
802
  flex: 1;
@@ -777,13 +777,7 @@ _::-webkit-full-page-media, _:future, :root [data-has-multi-selection=true] .blo
777
777
 
778
778
  .block-editor-iframe__html {
779
779
  transform-origin: top center;
780
- transition: all 400ms cubic-bezier(0.46, 0.03, 0.52, 0.96), transform 0s, scale 0s, padding 0s, translate 0s;
781
- }
782
- @media (prefers-reduced-motion: reduce) {
783
- .block-editor-iframe__html {
784
- transition-duration: 0s;
785
- transition-delay: 0s;
786
- }
780
+ transition: background-color 400ms;
787
781
  }
788
782
  .block-editor-iframe__html.zoom-out-animation {
789
783
  position: fixed;
@@ -791,27 +785,18 @@ _::-webkit-full-page-media, _:future, :root [data-has-multi-selection=true] .blo
791
785
  right: 0;
792
786
  top: calc(-1 * var(--wp-block-editor-iframe-zoom-out-scroll-top, 0));
793
787
  bottom: 0;
794
- translate: 0 calc(var(--wp-block-editor-iframe-zoom-out-scroll-top, 0) - var(--wp-block-editor-iframe-zoom-out-scroll-top-next, 0));
795
788
  overflow-y: scroll;
796
- transition: all 400ms cubic-bezier(0.46, 0.03, 0.52, 0.96), transform 0s, top 0s, bottom 0s, right 0s, left 0s;
797
789
  }
798
- @media (prefers-reduced-motion: reduce) {
799
- .block-editor-iframe__html.zoom-out-animation {
800
- transition-duration: 0s;
801
- transition-delay: 0s;
802
- }
803
- }
804
-
805
790
  .block-editor-iframe__html.is-zoomed-out {
806
- transform: translateX(calc((var(--wp-block-editor-iframe-zoom-out-scale-container-width) - var(--wp-block-editor-iframe-zoom-out-container-width, 100vw)) / 2 / var(--wp-block-editor-iframe-zoom-out-scale)));
807
- scale: var(--wp-block-editor-iframe-zoom-out-scale);
791
+ transform: translateX(calc((var(--wp-block-editor-iframe-zoom-out-scale-container-width) - var(--wp-block-editor-iframe-zoom-out-container-width, 100vw)) / 2 / var(--wp-block-editor-iframe-zoom-out-scale, 1)));
792
+ scale: var(--wp-block-editor-iframe-zoom-out-scale, 1);
808
793
  background-color: #ddd;
809
- margin-bottom: calc(-1 * calc(calc(var(--wp-block-editor-iframe-zoom-out-content-height) * (1 - var(--wp-block-editor-iframe-zoom-out-scale))) + calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale)) + 2px));
810
- padding-top: calc(var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale));
811
- padding-bottom: calc(var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale));
794
+ margin-bottom: calc(-1 * calc(calc(var(--wp-block-editor-iframe-zoom-out-content-height) * (1 - var(--wp-block-editor-iframe-zoom-out-scale, 1))) + calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1)) + 2px));
795
+ padding-top: calc(var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
796
+ padding-bottom: calc(var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
812
797
  }
813
798
  .block-editor-iframe__html.is-zoomed-out body {
814
- min-height: calc((var(--wp-block-editor-iframe-zoom-out-inner-height) - calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale))) / var(--wp-block-editor-iframe-zoom-out-scale));
799
+ min-height: calc((var(--wp-block-editor-iframe-zoom-out-inner-height) - calc(2 * var(--wp-block-editor-iframe-zoom-out-frame-size, 0) / var(--wp-block-editor-iframe-zoom-out-scale, 1))) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
815
800
  }
816
801
  .block-editor-iframe__html.is-zoomed-out body > .is-root-container:not(.wp-block-post-content) {
817
802
  flex: 1;