@wordpress/block-editor 14.7.1-next.082ed6819.0 → 14.8.1-next.cd6172eb0.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 +2 -0
- package/build/autocompleters/block.js +2 -4
- package/build/autocompleters/block.js.map +1 -1
- package/build/autocompleters/link.js +2 -4
- package/build/autocompleters/link.js.map +1 -1
- package/build/components/block-canvas/index.js +3 -6
- package/build/components/block-canvas/index.js.map +1 -1
- package/build/components/block-list/block.js +6 -5
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/index.js +0 -1
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +7 -2
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +34 -0
- package/build/components/block-list/use-block-props/use-firefox-draggable-compatibility.js.map +1 -0
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +98 -5
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build/components/block-patterns-list/index.js +13 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-popover/inbetween.js +4 -0
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +7 -4
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +1 -1
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-switcher/index.js +12 -22
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-switcher/use-transformed-patterns.js +0 -1
- package/build/components/block-switcher/use-transformed-patterns.js.map +1 -1
- package/build/components/block-switcher/utils.js +0 -1
- package/build/components/block-switcher/utils.js.map +1 -1
- package/build/components/block-toolbar/index.js +17 -9
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +0 -1
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/date-format-picker/index.js +0 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +1 -0
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/font-family/index.js +10 -0
- package/build/components/font-family/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +17 -16
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/get-global-styles-changes.js +0 -1
- package/build/components/global-styles/get-global-styles-changes.js.map +1 -1
- package/build/components/iframe/index.js +12 -216
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/iframe/use-scale-canvas.js +398 -0
- package/build/components/iframe/use-scale-canvas.js.map +1 -0
- package/build/components/image-editor/use-save-image.js +22 -3
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/index.js +0 -10
- package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build/components/inserter/menu.js +2 -1
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +19 -10
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/letter-spacing-control/index.js +10 -0
- package/build/components/letter-spacing-control/index.js.map +1 -1
- package/build/components/line-height-control/index.js +1 -0
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/media-placeholder/index.js +18 -18
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/observe-typing/index.js +0 -1
- package/build/components/observe-typing/index.js.map +1 -1
- package/build/components/recursion-provider/index.js +0 -1
- package/build/components/recursion-provider/index.js.map +1 -1
- package/build/components/rich-text/index.js +5 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/native/use-format-types.js +0 -1
- package/build/components/rich-text/native/use-format-types.js.map +1 -1
- package/build/components/rich-text/use-format-types.js +0 -1
- package/build/components/rich-text/use-format-types.js.map +1 -1
- package/build/components/spacing-sizes-control/utils.js +0 -1
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/components/typewriter/index.js +0 -1
- package/build/components/typewriter/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +11 -2
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-moving-animation/index.js +15 -2
- package/build/components/use-moving-animation/index.js.map +1 -1
- package/build/components/use-resize-canvas/index.js +1 -1
- package/build/components/use-resize-canvas/index.js.map +1 -1
- package/build/components/writing-flow/use-drag-selection.js +11 -0
- package/build/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +6 -2
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/hooks/block-bindings.js +4 -3
- package/build/hooks/block-bindings.js.map +1 -1
- package/build/hooks/gap.js +1 -1
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/generated-class-name.js +0 -1
- package/build/hooks/generated-class-name.js.map +1 -1
- package/build/store/private-selectors.js +1 -7
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +478 -2
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +12 -55
- package/build/store/selectors.js.map +1 -1
- package/build/utils/object.js +0 -1
- package/build/utils/object.js.map +1 -1
- package/build-module/autocompleters/block.js +2 -4
- package/build-module/autocompleters/block.js.map +1 -1
- package/build-module/autocompleters/link.js +2 -4
- package/build-module/autocompleters/link.js.map +1 -1
- package/build-module/components/block-canvas/index.js +3 -6
- package/build-module/components/block-canvas/index.js.map +1 -1
- package/build-module/components/block-list/block.js +8 -7
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/index.js +0 -1
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +7 -2
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +28 -0
- package/build-module/components/block-list/use-block-props/use-firefox-draggable-compatibility.js.map +1 -0
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +97 -5
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +13 -4
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +4 -0
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +7 -4
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +1 -1
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-switcher/index.js +13 -23
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-switcher/use-transformed-patterns.js +0 -1
- package/build-module/components/block-switcher/use-transformed-patterns.js.map +1 -1
- package/build-module/components/block-switcher/utils.js +0 -1
- package/build-module/components/block-switcher/utils.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +17 -9
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +0 -1
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +0 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +1 -0
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/font-family/index.js +10 -0
- package/build-module/components/font-family/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +17 -16
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/get-global-styles-changes.js +0 -1
- package/build-module/components/global-styles/get-global-styles-changes.js.map +1 -1
- package/build-module/components/iframe/index.js +14 -218
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/iframe/use-scale-canvas.js +392 -0
- package/build-module/components/iframe/use-scale-canvas.js.map +1 -0
- package/build-module/components/image-editor/use-save-image.js +22 -3
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/index.js +1 -11
- package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build-module/components/inserter/menu.js +2 -1
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +20 -11
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/letter-spacing-control/index.js +9 -0
- package/build-module/components/letter-spacing-control/index.js.map +1 -1
- package/build-module/components/line-height-control/index.js +1 -0
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +18 -18
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/observe-typing/index.js +0 -1
- package/build-module/components/observe-typing/index.js.map +1 -1
- package/build-module/components/recursion-provider/index.js +0 -1
- package/build-module/components/recursion-provider/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +5 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/native/use-format-types.js +0 -1
- package/build-module/components/rich-text/native/use-format-types.js.map +1 -1
- package/build-module/components/rich-text/use-format-types.js +0 -1
- package/build-module/components/rich-text/use-format-types.js.map +1 -1
- package/build-module/components/spacing-sizes-control/utils.js +0 -1
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/components/typewriter/index.js +0 -1
- package/build-module/components/typewriter/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +11 -2
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-moving-animation/index.js +15 -2
- package/build-module/components/use-moving-animation/index.js.map +1 -1
- package/build-module/components/use-resize-canvas/index.js +1 -1
- package/build-module/components/use-resize-canvas/index.js.map +1 -1
- package/build-module/components/writing-flow/use-drag-selection.js +11 -0
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +6 -2
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/hooks/block-bindings.js +4 -3
- package/build-module/hooks/block-bindings.js.map +1 -1
- package/build-module/hooks/gap.js +1 -1
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/generated-class-name.js +0 -1
- package/build-module/hooks/generated-class-name.js.map +1 -1
- package/build-module/store/private-selectors.js +1 -6
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +479 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +12 -55
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/object.js +0 -1
- package/build-module/utils/object.js.map +1 -1
- package/build-style/content-rtl.css +24 -26
- package/build-style/content.css +24 -26
- package/build-style/style-rtl.css +51 -16
- package/build-style/style.css +51 -16
- package/package.json +32 -32
- package/src/autocompleters/block.js +2 -4
- package/src/autocompleters/link.js +2 -4
- package/src/components/alignment-control/stories/aliginment-toolbar.story.js +47 -0
- package/src/components/alignment-control/stories/index.story.js +51 -0
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +5 -5
- package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +4 -4
- package/src/components/block-canvas/index.js +3 -5
- package/src/components/block-canvas/style.scss +2 -1
- package/src/components/block-draggable/content.scss +11 -5
- package/src/components/block-list/block.js +7 -13
- package/src/components/block-list/content.scss +6 -0
- package/src/components/block-list/use-block-props/index.js +7 -0
- package/src/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +25 -0
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +112 -8
- package/src/components/block-patterns-list/index.js +12 -1
- package/src/components/block-patterns-list/style.scss +16 -5
- package/src/components/block-popover/inbetween.js +4 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +6 -1
- package/src/components/block-settings-menu-controls/index.js +2 -1
- package/src/components/block-switcher/index.js +19 -21
- package/src/components/block-switcher/style.scss +0 -9
- package/src/components/block-title/test/index.js +2 -0
- package/src/components/block-toolbar/index.js +16 -6
- package/src/components/block-tools/style.scss +44 -0
- package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +3 -3
- package/src/components/color-palette/test/__snapshots__/control.js.snap +2 -2
- package/src/components/font-appearance-control/index.js +1 -0
- package/src/components/font-family/index.js +10 -0
- package/src/components/font-family/style.scss +5 -0
- package/src/components/global-styles/dimensions-panel.js +16 -16
- package/src/components/iframe/content.scss +40 -42
- package/src/components/iframe/index.js +13 -313
- package/src/components/iframe/use-scale-canvas.js +490 -0
- package/src/components/image-editor/use-save-image.js +27 -2
- package/src/components/inserter/block-patterns-tab/index.js +1 -17
- package/src/components/inserter/menu.js +8 -1
- package/src/components/inserter-draggable-blocks/index.js +19 -29
- package/src/components/letter-spacing-control/README.md +2 -1
- package/src/components/letter-spacing-control/index.js +17 -0
- package/src/components/line-height-control/index.js +1 -0
- package/src/components/media-placeholder/index.js +25 -28
- package/src/components/rich-text/index.js +5 -0
- package/src/components/use-block-drop-zone/index.js +18 -1
- package/src/components/use-moving-animation/index.js +15 -0
- package/src/components/use-resize-canvas/index.js +1 -1
- package/src/components/writing-flow/use-drag-selection.js +11 -0
- package/src/components/writing-flow/use-tab-nav.js +9 -6
- package/src/hooks/block-bindings.js +8 -4
- package/src/hooks/gap.js +1 -1
- package/src/store/private-selectors.js +2 -17
- package/src/store/reducer.js +639 -2
- package/src/store/selectors.js +19 -69
- package/src/store/test/private-selectors.js +1 -0
- package/src/store/test/reducer.js +849 -0
- package/src/store/test/selectors.js +4 -110
- package/src/style.scss +1 -0
|
@@ -0,0 +1,392 @@
|
|
|
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} containerHeight containerHeight 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 scrollHeight based on the transition states.
|
|
37
|
+
*
|
|
38
|
+
* @param {TransitionState} transitionFrom Starting point of the transition
|
|
39
|
+
* @param {TransitionState} transitionTo Ending state of the transition
|
|
40
|
+
* @return {number} Next scrollHeight based on scale and frame value changes.
|
|
41
|
+
*/
|
|
42
|
+
function computeScrollHeightNext(transitionFrom, transitionTo) {
|
|
43
|
+
const {
|
|
44
|
+
scaleValue: prevScale,
|
|
45
|
+
scrollHeight: prevScrollHeight
|
|
46
|
+
} = transitionFrom;
|
|
47
|
+
const {
|
|
48
|
+
frameSize,
|
|
49
|
+
scaleValue
|
|
50
|
+
} = transitionTo;
|
|
51
|
+
return prevScrollHeight * (scaleValue / prevScale) + frameSize * 2;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Compute the next scrollTop position after scaling the iframe content.
|
|
56
|
+
*
|
|
57
|
+
* @param {TransitionState} transitionFrom Starting point of the transition
|
|
58
|
+
* @param {TransitionState} transitionTo Ending state of the transition
|
|
59
|
+
* @return {number} Next scrollTop position after scaling the iframe content.
|
|
60
|
+
*/
|
|
61
|
+
function computeScrollTopNext(transitionFrom, transitionTo) {
|
|
62
|
+
const {
|
|
63
|
+
containerHeight: prevContainerHeight,
|
|
64
|
+
frameSize: prevFrameSize,
|
|
65
|
+
scaleValue: prevScale,
|
|
66
|
+
scrollTop: prevScrollTop
|
|
67
|
+
} = transitionFrom;
|
|
68
|
+
const {
|
|
69
|
+
containerHeight,
|
|
70
|
+
frameSize,
|
|
71
|
+
scaleValue,
|
|
72
|
+
scrollHeight
|
|
73
|
+
} = transitionTo;
|
|
74
|
+
// Step 0: Start with the current scrollTop.
|
|
75
|
+
let scrollTopNext = prevScrollTop;
|
|
76
|
+
// Step 1: Undo the effects of the previous scale and frame around the
|
|
77
|
+
// midpoint of the visible area.
|
|
78
|
+
scrollTopNext = (scrollTopNext + prevContainerHeight / 2 - prevFrameSize) / prevScale - prevContainerHeight / 2;
|
|
79
|
+
|
|
80
|
+
// Step 2: Apply the new scale and frame around the midpoint of the
|
|
81
|
+
// visible area.
|
|
82
|
+
scrollTopNext = (scrollTopNext + containerHeight / 2) * scaleValue + frameSize - containerHeight / 2;
|
|
83
|
+
|
|
84
|
+
// Step 3: Handle an edge case so that you scroll to the top of the
|
|
85
|
+
// iframe if the top of the iframe content is visible in the container.
|
|
86
|
+
// The same edge case for the bottom is skipped because changing content
|
|
87
|
+
// makes calculating it impossible.
|
|
88
|
+
scrollTopNext = prevScrollTop <= prevFrameSize ? 0 : scrollTopNext;
|
|
89
|
+
|
|
90
|
+
// This is the scrollTop value if you are scrolled to the bottom of the
|
|
91
|
+
// iframe. We can't just let the browser handle it because we need to
|
|
92
|
+
// animate the scaling.
|
|
93
|
+
const maxScrollTop = scrollHeight - containerHeight;
|
|
94
|
+
|
|
95
|
+
// Step 4: Clamp the scrollTopNext between the minimum and maximum
|
|
96
|
+
// possible scrollTop positions. Round the value to avoid subpixel
|
|
97
|
+
// truncation by the browser which sometimes causes a 1px error.
|
|
98
|
+
return Math.round(Math.min(Math.max(0, scrollTopNext), Math.max(0, maxScrollTop)));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Generate the keyframes to use for the zoom out animation.
|
|
103
|
+
*
|
|
104
|
+
* @param {TransitionState} transitionFrom Starting transition state.
|
|
105
|
+
* @param {TransitionState} transitionTo Ending transition state.
|
|
106
|
+
* @return {Object[]} An array of keyframes to use for the animation.
|
|
107
|
+
*/
|
|
108
|
+
function getAnimationKeyframes(transitionFrom, transitionTo) {
|
|
109
|
+
const {
|
|
110
|
+
scaleValue: prevScale,
|
|
111
|
+
frameSize: prevFrameSize,
|
|
112
|
+
scrollTop
|
|
113
|
+
} = transitionFrom;
|
|
114
|
+
const {
|
|
115
|
+
scaleValue,
|
|
116
|
+
frameSize,
|
|
117
|
+
scrollTop: scrollTopNext
|
|
118
|
+
} = transitionTo;
|
|
119
|
+
return [{
|
|
120
|
+
translate: `0 0`,
|
|
121
|
+
scale: prevScale,
|
|
122
|
+
paddingTop: `${prevFrameSize / prevScale}px`,
|
|
123
|
+
paddingBottom: `${prevFrameSize / prevScale}px`
|
|
124
|
+
}, {
|
|
125
|
+
translate: `0 ${scrollTop - scrollTopNext}px`,
|
|
126
|
+
scale: scaleValue,
|
|
127
|
+
paddingTop: `${frameSize / scaleValue}px`,
|
|
128
|
+
paddingBottom: `${frameSize / scaleValue}px`
|
|
129
|
+
}];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @typedef {Object} ScaleCanvasResult
|
|
134
|
+
* @property {boolean} isZoomedOut A boolean indicating if the canvas is zoomed out.
|
|
135
|
+
* @property {number} scaleContainerWidth The width of the container used to calculate the scale.
|
|
136
|
+
* @property {Object} contentResizeListener A resize observer for the content.
|
|
137
|
+
* @property {Object} containerResizeListener A resize observer for the container.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Handles scaling the canvas for the zoom out mode and animating between
|
|
142
|
+
* the states.
|
|
143
|
+
*
|
|
144
|
+
* @param {Object} options Object of options.
|
|
145
|
+
* @param {number} options.frameSize Size of the frame around the content.
|
|
146
|
+
* @param {Document} options.iframeDocument Document of the iframe.
|
|
147
|
+
* @param {number} options.maxContainerWidth Max width of the canvas to use as the starting scale point. Defaults to 750.
|
|
148
|
+
* @param {number|string} options.scale Scale of the canvas. Can be an decimal between 0 and 1, 1, or 'auto-scaled'.
|
|
149
|
+
* @return {ScaleCanvasResult} Properties of the result.
|
|
150
|
+
*/
|
|
151
|
+
export function useScaleCanvas({
|
|
152
|
+
frameSize,
|
|
153
|
+
iframeDocument,
|
|
154
|
+
maxContainerWidth = 750,
|
|
155
|
+
scale
|
|
156
|
+
}) {
|
|
157
|
+
const [contentResizeListener, {
|
|
158
|
+
height: contentHeight
|
|
159
|
+
}] = useResizeObserver();
|
|
160
|
+
const [containerResizeListener, {
|
|
161
|
+
width: containerWidth,
|
|
162
|
+
height: containerHeight
|
|
163
|
+
}] = useResizeObserver();
|
|
164
|
+
const initialContainerWidthRef = useRef(0);
|
|
165
|
+
const isZoomedOut = scale !== 1;
|
|
166
|
+
const prefersReducedMotion = useReducedMotion();
|
|
167
|
+
const isAutoScaled = scale === 'auto-scaled';
|
|
168
|
+
// Track if the animation should start when the useEffect runs.
|
|
169
|
+
const startAnimationRef = useRef(false);
|
|
170
|
+
// Track the animation so we know if we have an animation running,
|
|
171
|
+
// and can cancel it, reverse it, call a finish event, etc.
|
|
172
|
+
const animationRef = useRef(null);
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
if (!isZoomedOut) {
|
|
175
|
+
initialContainerWidthRef.current = containerWidth;
|
|
176
|
+
}
|
|
177
|
+
}, [containerWidth, isZoomedOut]);
|
|
178
|
+
const scaleContainerWidth = Math.max(initialContainerWidthRef.current, containerWidth);
|
|
179
|
+
const scaleValue = isAutoScaled ? calculateScale({
|
|
180
|
+
frameSize,
|
|
181
|
+
containerWidth,
|
|
182
|
+
maxContainerWidth,
|
|
183
|
+
scaleContainerWidth
|
|
184
|
+
}) : scale;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The starting transition state for the zoom out animation.
|
|
188
|
+
* @type {import('react').RefObject<TransitionState>}
|
|
189
|
+
*/
|
|
190
|
+
const transitionFromRef = useRef({
|
|
191
|
+
scaleValue,
|
|
192
|
+
frameSize,
|
|
193
|
+
containerHeight: 0,
|
|
194
|
+
scrollTop: 0,
|
|
195
|
+
scrollHeight: 0
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The ending transition state for the zoom out animation.
|
|
200
|
+
* @type {import('react').RefObject<TransitionState>}
|
|
201
|
+
*/
|
|
202
|
+
const transitionToRef = useRef({
|
|
203
|
+
scaleValue,
|
|
204
|
+
frameSize,
|
|
205
|
+
containerHeight: 0,
|
|
206
|
+
scrollTop: 0,
|
|
207
|
+
scrollHeight: 0
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Start the zoom out animation. This sets the necessary CSS variables
|
|
212
|
+
* for animating the canvas and returns the Animation object.
|
|
213
|
+
*
|
|
214
|
+
* @return {Animation} The animation object for the zoom out animation.
|
|
215
|
+
*/
|
|
216
|
+
const startZoomOutAnimation = useCallback(() => {
|
|
217
|
+
const {
|
|
218
|
+
scrollTop
|
|
219
|
+
} = transitionFromRef.current;
|
|
220
|
+
const {
|
|
221
|
+
scrollTop: scrollTopNext
|
|
222
|
+
} = transitionToRef.current;
|
|
223
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scroll-top', `${scrollTop}px`);
|
|
224
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scroll-top-next', `${scrollTopNext}px`);
|
|
225
|
+
|
|
226
|
+
// If the container has a scrolllbar, force a scrollbar to prevent the content from shifting while animating.
|
|
227
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-overflow-behavior', transitionFromRef.current.scrollHeight === transitionFromRef.current.containerHeight ? 'auto' : 'scroll');
|
|
228
|
+
iframeDocument.documentElement.classList.add('zoom-out-animation');
|
|
229
|
+
return iframeDocument.documentElement.animate(getAnimationKeyframes(transitionFromRef.current, transitionToRef.current), {
|
|
230
|
+
easing: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)',
|
|
231
|
+
duration: 400
|
|
232
|
+
});
|
|
233
|
+
}, [iframeDocument]);
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Callback when the zoom out animation is finished.
|
|
237
|
+
* - Cleans up animations refs.
|
|
238
|
+
* - Adds final CSS vars for scale and frame size to preserve the state.
|
|
239
|
+
* - Removes the 'zoom-out-animation' class (which has the fixed positioning).
|
|
240
|
+
* - Sets the final scroll position after the canvas is no longer in fixed position.
|
|
241
|
+
* - Removes CSS vars related to the animation.
|
|
242
|
+
* - Sets the transitionFrom to the transitionTo state to be ready for the next animation.
|
|
243
|
+
*/
|
|
244
|
+
const finishZoomOutAnimation = useCallback(() => {
|
|
245
|
+
startAnimationRef.current = false;
|
|
246
|
+
animationRef.current = null;
|
|
247
|
+
|
|
248
|
+
// Add our final scale and frame size now that the animation is done.
|
|
249
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale', transitionToRef.current.scaleValue);
|
|
250
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-frame-size', `${transitionToRef.current.frameSize}px`);
|
|
251
|
+
iframeDocument.documentElement.classList.remove('zoom-out-animation');
|
|
252
|
+
|
|
253
|
+
// Set the final scroll position that was just animated to.
|
|
254
|
+
// Disable reason: Eslint isn't smart enough to know that this is a
|
|
255
|
+
// DOM element. https://github.com/facebook/react/issues/31483
|
|
256
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
257
|
+
iframeDocument.documentElement.scrollTop = transitionToRef.current.scrollTop;
|
|
258
|
+
iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scroll-top');
|
|
259
|
+
iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scroll-top-next');
|
|
260
|
+
iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-overflow-behavior');
|
|
261
|
+
|
|
262
|
+
// Update previous values.
|
|
263
|
+
transitionFromRef.current = transitionToRef.current;
|
|
264
|
+
}, [iframeDocument]);
|
|
265
|
+
const previousIsZoomedOut = useRef(false);
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Runs when zoom out mode is toggled, and sets the startAnimation flag
|
|
269
|
+
* so the animation will start when the next useEffect runs. We _only_
|
|
270
|
+
* want to animate when the zoom out mode is toggled, not when the scale
|
|
271
|
+
* changes due to the container resizing.
|
|
272
|
+
*/
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
const trigger = iframeDocument && previousIsZoomedOut.current !== isZoomedOut;
|
|
275
|
+
previousIsZoomedOut.current = isZoomedOut;
|
|
276
|
+
if (!trigger) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
startAnimationRef.current = true;
|
|
280
|
+
if (!isZoomedOut) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
iframeDocument.documentElement.classList.add('is-zoomed-out');
|
|
284
|
+
return () => {
|
|
285
|
+
iframeDocument.documentElement.classList.remove('is-zoomed-out');
|
|
286
|
+
};
|
|
287
|
+
}, [iframeDocument, isZoomedOut]);
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* This handles:
|
|
291
|
+
* 1. Setting the correct scale and vars of the canvas when zoomed out
|
|
292
|
+
* 2. If zoom out mode has been toggled, runs the animation of zooming in/out
|
|
293
|
+
*/
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
if (!iframeDocument) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// We need to update the appropriate scale to exit from. If sidebars have been opened since setting the
|
|
300
|
+
// original scale, we will snap to a much smaller scale due to the scale container immediately changing sizes when exiting.
|
|
301
|
+
if (isAutoScaled && transitionFromRef.current.scaleValue !== 1) {
|
|
302
|
+
// We use containerWidth as the divisor, as scaleContainerWidth will always match the containerWidth when
|
|
303
|
+
// exiting.
|
|
304
|
+
transitionFromRef.current.scaleValue = calculateScale({
|
|
305
|
+
frameSize: transitionFromRef.current.frameSize,
|
|
306
|
+
containerWidth,
|
|
307
|
+
maxContainerWidth,
|
|
308
|
+
scaleContainerWidth: containerWidth
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if (scaleValue < 1) {
|
|
312
|
+
// If we are not going to animate the transition, set the scale and frame size directly.
|
|
313
|
+
// If we are animating, these values will be set when the animation is finished.
|
|
314
|
+
// Example: Opening sidebars that reduce the scale of the canvas, but we don't want to
|
|
315
|
+
// animate the transition.
|
|
316
|
+
if (!startAnimationRef.current) {
|
|
317
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale', scaleValue);
|
|
318
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-frame-size', `${frameSize}px`);
|
|
319
|
+
}
|
|
320
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-content-height', `${contentHeight}px`);
|
|
321
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-inner-height', `${containerHeight}px`);
|
|
322
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-container-width', `${containerWidth}px`);
|
|
323
|
+
iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale-container-width', `${scaleContainerWidth}px`);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Handle the zoom out animation:
|
|
328
|
+
*
|
|
329
|
+
* - Get the current scrollTop position.
|
|
330
|
+
* - Calculate where the same scroll position is after scaling.
|
|
331
|
+
* - Apply fixed positioning to the canvas with a transform offset
|
|
332
|
+
* to keep the canvas centered.
|
|
333
|
+
* - Animate the scale and padding to the new scale and frame size.
|
|
334
|
+
* - After the animation is complete, remove the fixed positioning
|
|
335
|
+
* and set the scroll position that keeps everything centered.
|
|
336
|
+
*/
|
|
337
|
+
if (startAnimationRef.current) {
|
|
338
|
+
// Don't allow a new transition to start again unless it was started by the zoom out mode changing.
|
|
339
|
+
startAnimationRef.current = false;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* If we already have an animation running, reverse it.
|
|
343
|
+
*/
|
|
344
|
+
if (animationRef.current) {
|
|
345
|
+
animationRef.current.reverse();
|
|
346
|
+
// Swap the transition to/from refs so that we set the correct values when
|
|
347
|
+
// finishZoomOutAnimation runs.
|
|
348
|
+
const tempTransitionFrom = transitionFromRef.current;
|
|
349
|
+
const tempTransitionTo = transitionToRef.current;
|
|
350
|
+
transitionFromRef.current = tempTransitionTo;
|
|
351
|
+
transitionToRef.current = tempTransitionFrom;
|
|
352
|
+
} else {
|
|
353
|
+
/**
|
|
354
|
+
* Start a new zoom animation.
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
// We can't trust the set value from contentHeight, as it was measured
|
|
358
|
+
// before the zoom out mode was changed. After zoom out mode is changed,
|
|
359
|
+
// appenders may appear or disappear, so we need to get the height from
|
|
360
|
+
// the iframe at this point when we're about to animate the zoom out.
|
|
361
|
+
// The iframe scrollTop, scrollHeight, and clientHeight will all be
|
|
362
|
+
// the most accurate.
|
|
363
|
+
transitionFromRef.current.scrollTop = iframeDocument.documentElement.scrollTop;
|
|
364
|
+
transitionFromRef.current.scrollHeight = iframeDocument.documentElement.scrollHeight;
|
|
365
|
+
// Use containerHeight, as it's the previous container height before the zoom out animation starts.
|
|
366
|
+
transitionFromRef.current.containerHeight = containerHeight;
|
|
367
|
+
transitionToRef.current = {
|
|
368
|
+
scaleValue,
|
|
369
|
+
frameSize,
|
|
370
|
+
containerHeight: iframeDocument.documentElement.clientHeight // use clientHeight to get the actual height of the new container after zoom state changes have rendered, as it will be the most up-to-date.
|
|
371
|
+
};
|
|
372
|
+
transitionToRef.current.scrollHeight = computeScrollHeightNext(transitionFromRef.current, transitionToRef.current);
|
|
373
|
+
transitionToRef.current.scrollTop = computeScrollTopNext(transitionFromRef.current, transitionToRef.current);
|
|
374
|
+
animationRef.current = startZoomOutAnimation();
|
|
375
|
+
|
|
376
|
+
// If the user prefers reduced motion, finish the animation immediately and set the final state.
|
|
377
|
+
if (prefersReducedMotion) {
|
|
378
|
+
finishZoomOutAnimation();
|
|
379
|
+
} else {
|
|
380
|
+
animationRef.current.onfinish = finishZoomOutAnimation;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}, [startZoomOutAnimation, finishZoomOutAnimation, prefersReducedMotion, isAutoScaled, scaleValue, frameSize, iframeDocument, contentHeight, containerWidth, containerHeight, maxContainerWidth, scaleContainerWidth]);
|
|
385
|
+
return {
|
|
386
|
+
isZoomedOut,
|
|
387
|
+
scaleContainerWidth,
|
|
388
|
+
contentResizeListener,
|
|
389
|
+
containerResizeListener
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
//# 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","computeScrollHeightNext","transitionFrom","transitionTo","scaleValue","prevScale","scrollHeight","prevScrollHeight","computeScrollTopNext","containerHeight","prevContainerHeight","prevFrameSize","scrollTop","prevScrollTop","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","previousIsZoomedOut","trigger","reverse","tempTransitionFrom","tempTransitionTo","clientHeight","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} containerHeight containerHeight 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 scrollHeight based on the transition states.\n *\n * @param {TransitionState} transitionFrom Starting point of the transition\n * @param {TransitionState} transitionTo Ending state of the transition\n * @return {number} Next scrollHeight based on scale and frame value changes.\n */\nfunction computeScrollHeightNext( transitionFrom, transitionTo ) {\n\tconst { scaleValue: prevScale, scrollHeight: prevScrollHeight } =\n\t\ttransitionFrom;\n\tconst { frameSize, scaleValue } = transitionTo;\n\n\treturn prevScrollHeight * ( scaleValue / prevScale ) + frameSize * 2;\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\tcontainerHeight: prevContainerHeight,\n\t\tframeSize: prevFrameSize,\n\t\tscaleValue: prevScale,\n\t\tscrollTop: prevScrollTop,\n\t} = transitionFrom;\n\tconst { containerHeight, frameSize, scaleValue, scrollHeight } =\n\t\ttransitionTo;\n\t// Step 0: Start with the current scrollTop.\n\tlet scrollTopNext = prevScrollTop;\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 + prevContainerHeight / 2 - prevFrameSize ) /\n\t\t\tprevScale -\n\t\tprevContainerHeight / 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 + containerHeight / 2 ) * scaleValue +\n\t\tframeSize -\n\t\tcontainerHeight / 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 = prevScrollTop <= 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 = scrollHeight - containerHeight;\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 [\n\t\tcontainerResizeListener,\n\t\t{ width: containerWidth, height: containerHeight },\n\t] = useResizeObserver();\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\tcontainerHeight: 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\tcontainerHeight: 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\t// If the container has a scrolllbar, force a scrollbar to prevent the content from shifting while animating.\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-overflow-behavior',\n\t\t\ttransitionFromRef.current.scrollHeight ===\n\t\t\t\ttransitionFromRef.current.containerHeight\n\t\t\t\t? 'auto'\n\t\t\t\t: 'scroll'\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\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-overflow-behavior'\n\t\t);\n\n\t\t// Update previous values.\n\t\ttransitionFromRef.current = transitionToRef.current;\n\t}, [ iframeDocument ] );\n\n\tconst previousIsZoomedOut = useRef( false );\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\tconst trigger =\n\t\t\tiframeDocument && previousIsZoomedOut.current !== isZoomedOut;\n\n\t\tpreviousIsZoomedOut.current = isZoomedOut;\n\n\t\tif ( ! trigger ) {\n\t\t\treturn;\n\t\t}\n\n\t\tstartAnimationRef.current = true;\n\n\t\tif ( ! isZoomedOut ) {\n\t\t\treturn;\n\t\t}\n\n\t\tiframeDocument.documentElement.classList.add( 'is-zoomed-out' );\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\tif ( scaleValue < 1 ) {\n\t\t\t// If we are not going to animate the transition, set the scale and frame size directly.\n\t\t\t// If we are animating, these values will be set when the animation is finished.\n\t\t\t// Example: Opening sidebars that reduce the scale of the canvas, but we don't want to\n\t\t\t// animate the transition.\n\t\t\tif ( ! startAnimationRef.current ) {\n\t\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\t\t\tscaleValue\n\t\t\t\t);\n\t\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t\t\t`${ frameSize }px`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-content-height',\n\t\t\t\t`${ contentHeight }px`\n\t\t\t);\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-inner-height',\n\t\t\t\t`${ containerHeight }px`\n\t\t\t);\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-container-width',\n\t\t\t\t`${ containerWidth }px`\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width',\n\t\t\t\t`${ scaleContainerWidth }px`\n\t\t\t);\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.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\t\t\t\t// Use containerHeight, as it's the previous container height before the zoom out animation starts.\n\t\t\t\ttransitionFromRef.current.containerHeight = containerHeight;\n\n\t\t\t\ttransitionToRef.current = {\n\t\t\t\t\tscaleValue,\n\t\t\t\t\tframeSize,\n\t\t\t\t\tcontainerHeight:\n\t\t\t\t\t\tiframeDocument.documentElement.clientHeight, // use clientHeight to get the actual height of the new container after zoom state changes have rendered, as it will be the most up-to-date.\n\t\t\t\t};\n\n\t\t\t\ttransitionToRef.current.scrollHeight = computeScrollHeightNext(\n\t\t\t\t\ttransitionFromRef.current,\n\t\t\t\t\ttransitionToRef.current\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\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\tcontainerHeight,\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,CAAEC,IAAI,CAACC,GAAG,CAAEJ,cAAc,EAAEC,iBAAkB,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,GAAGkB,kBAAkB;MAC7C,CAAC,MAAM;QACN;AACJ;AACA;;QAEI;QACA;QACA;QACA;QACA;QACA;QACAjB,iBAAiB,CAACD,OAAO,CAACxB,SAAS,GAClCY,cAAc,CAACgB,eAAe,CAAC5B,SAAS;QACzCyB,iBAAiB,CAACD,OAAO,CAAC9B,YAAY,GACrCkB,cAAc,CAACgB,eAAe,CAAClC,YAAY;QAC5C;QACA+B,iBAAiB,CAACD,OAAO,CAAC3B,eAAe,GAAGA,eAAe;QAE3D6B,eAAe,CAACF,OAAO,GAAG;UACzBhC,UAAU;UACVT,SAAS;UACTc,eAAe,EACde,cAAc,CAACgB,eAAe,CAACgB,YAAY,CAAE;QAC/C,CAAC;QAEDlB,eAAe,CAACF,OAAO,CAAC9B,YAAY,GAAGL,uBAAuB,CAC7DoC,iBAAiB,CAACD,OAAO,EACzBE,eAAe,CAACF,OACjB,CAAC;QACDE,eAAe,CAACF,OAAO,CAACxB,SAAS,GAAGJ,oBAAoB,CACvD6B,iBAAiB,CAACD,OAAO,EACzBE,eAAe,CAACF,OACjB,CAAC;QAEDD,YAAY,CAACC,OAAO,GAAGG,qBAAqB,CAAC,CAAC;;QAE9C;QACA,IAAKP,oBAAoB,EAAG;UAC3BgB,sBAAsB,CAAC,CAAC;QACzB,CAAC,MAAM;UACNb,YAAY,CAACC,OAAO,CAACqB,QAAQ,GAAGT,sBAAsB;QACvD;MACD;IACD;EACD,CAAC,EAAE,CACFT,qBAAqB,EACrBS,sBAAsB,EACtBhB,oBAAoB,EACpBC,YAAY,EACZ7B,UAAU,EACVT,SAAS,EACT6B,cAAc,EACdG,aAAa,EACb/B,cAAc,EACda,eAAe,EACfZ,iBAAiB,EACjBC,mBAAmB,CAClB,CAAC;EAEH,OAAO;IACNiC,WAAW;IACXjC,mBAAmB;IACnB2B,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:
|
|
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","
|
|
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,IAAIC,SAAS,QAAQ,gBAAgB;AAEjE,MAAMC,QAAQ,GAAG;EAChBC,IAAI,EAAEP,EAAE,CAAE,gB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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":[]}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useState } from '@wordpress/element';
|
|
5
5
|
import { useViewportMatch } from '@wordpress/compose';
|
|
6
|
-
import { Button
|
|
6
|
+
import { Button } from '@wordpress/components';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
|
-
import { useSelect } from '@wordpress/data';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Internal dependencies
|
|
@@ -16,8 +15,6 @@ import { PatternCategoryPreviews } from './pattern-category-previews';
|
|
|
16
15
|
import { usePatternCategories } from './use-pattern-categories';
|
|
17
16
|
import CategoryTabs from '../category-tabs';
|
|
18
17
|
import InserterNoResults from '../no-results';
|
|
19
|
-
import { store as blockEditorStore } from '../../../store';
|
|
20
|
-
import { unlock } from '../../../lock-unlock';
|
|
21
18
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
22
19
|
function BlockPatternsTab({
|
|
23
20
|
onSelectCategory,
|
|
@@ -29,13 +26,6 @@ function BlockPatternsTab({
|
|
|
29
26
|
const [showPatternsExplorer, setShowPatternsExplorer] = useState(false);
|
|
30
27
|
const categories = usePatternCategories(rootClientId);
|
|
31
28
|
const isMobile = useViewportMatch('medium', '<');
|
|
32
|
-
const isResolvingPatterns = useSelect(select => unlock(select(blockEditorStore)).isResolvingPatterns(), []);
|
|
33
|
-
if (isResolvingPatterns) {
|
|
34
|
-
return /*#__PURE__*/_jsx("div", {
|
|
35
|
-
className: "block-editor-inserter__patterns-loading",
|
|
36
|
-
children: /*#__PURE__*/_jsx(Spinner, {})
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
29
|
if (!categories.length) {
|
|
40
30
|
return /*#__PURE__*/_jsx(InserterNoResults, {});
|
|
41
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useViewportMatch","Button","
|
|
1
|
+
{"version":3,"names":["useState","useViewportMatch","Button","__","PatternsExplorerModal","MobileTabNavigation","PatternCategoryPreviews","usePatternCategories","CategoryTabs","InserterNoResults","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","BlockPatternsTab","onSelectCategory","selectedCategory","onInsert","rootClientId","children","showPatternsExplorer","setShowPatternsExplorer","categories","isMobile","length","className","__next40pxDefaultSize","onClick","variant","category","name","initialCategory","patternCategories","onModalClose"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport PatternsExplorerModal from '../block-patterns-explorer';\nimport MobileTabNavigation from '../mobile-tab-navigation';\nimport { PatternCategoryPreviews } from './pattern-category-previews';\nimport { usePatternCategories } from './use-pattern-categories';\nimport CategoryTabs from '../category-tabs';\nimport InserterNoResults from '../no-results';\n\nfunction BlockPatternsTab( {\n\tonSelectCategory,\n\tselectedCategory,\n\tonInsert,\n\trootClientId,\n\tchildren,\n} ) {\n\tconst [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );\n\n\tconst categories = usePatternCategories( rootClientId );\n\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tif ( ! categories.length ) {\n\t\treturn <InserterNoResults />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ ! isMobile && (\n\t\t\t\t<div className=\"block-editor-inserter__block-patterns-tabs-container\">\n\t\t\t\t\t<CategoryTabs\n\t\t\t\t\t\tcategories={ categories }\n\t\t\t\t\t\tselectedCategory={ selectedCategory }\n\t\t\t\t\t\tonSelectCategory={ onSelectCategory }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</CategoryTabs>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"block-editor-inserter__patterns-explore-button\"\n\t\t\t\t\t\tonClick={ () => setShowPatternsExplorer( true ) }\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Explore all patterns' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ isMobile && (\n\t\t\t\t<MobileTabNavigation categories={ categories }>\n\t\t\t\t\t{ ( category ) => (\n\t\t\t\t\t\t<div className=\"block-editor-inserter__category-panel\">\n\t\t\t\t\t\t\t<PatternCategoryPreviews\n\t\t\t\t\t\t\t\tkey={ category.name }\n\t\t\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t</MobileTabNavigation>\n\t\t\t) }\n\t\t\t{ showPatternsExplorer && (\n\t\t\t\t<PatternsExplorerModal\n\t\t\t\t\tinitialCategory={ selectedCategory || categories[ 0 ] }\n\t\t\t\t\tpatternCategories={ categories }\n\t\t\t\t\tonModalClose={ () => setShowPatternsExplorer( false ) }\n\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default BlockPatternsTab;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,OAAOC,qBAAqB,MAAM,4BAA4B;AAC9D,OAAOC,mBAAmB,MAAM,0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AAAH,QAAA,EACzCU,QAAQ,iBACXpB,IAAA;QAAKgB,SAAS,EAAC,uCAAuC;QAAAN,QAAA,eACrDV,IAAA,CAACL,uBAAuB;UAEvBa,QAAQ,EAAGA,QAAU;UACrBC,YAAY,EAAGA,YAAc;UAC7BW,QAAQ,EAAGA;QAAU,GAHfA,QAAQ,CAACC,IAIf;MAAC,CACE;IACL,CACmB,CACrB,EACCV,oBAAoB,iBACrBX,IAAA,CAACP,qBAAqB;MACrB6B,eAAe,EAAGf,gBAAgB,IAAIM,UAAU,CAAE,CAAC,CAAI;MACvDU,iBAAiB,EAAGV,UAAY;MAChCW,YAAY,EAAGA,CAAA,KAAMZ,uBAAuB,CAAE,KAAM,CAAG;MACvDH,YAAY,EAAGA;IAAc,CAC7B,CACD;EAAA,CACA,CAAC;AAEL;AAEA,eAAeJ,gBAAgB","ignoreList":[]}
|
|
@@ -45,6 +45,7 @@ function InserterMenu({
|
|
|
45
45
|
__experimentalInitialCategory
|
|
46
46
|
}, ref) {
|
|
47
47
|
const isZoomOutMode = useSelect(select => unlock(select(blockEditorStore)).isZoomOut(), []);
|
|
48
|
+
const hasSectionRootClientId = useSelect(select => !!unlock(select(blockEditorStore)).getSectionRootClientId(), []);
|
|
48
49
|
const [filterValue, setFilterValue, delayedFilterValue] = useDebouncedInput(__experimentalFilterValue);
|
|
49
50
|
const [hoveredItem, setHoveredItem] = useState(null);
|
|
50
51
|
const [selectedPatternCategory, setSelectedPatternCategory] = useState(__experimentalInitialCategory);
|
|
@@ -60,7 +61,7 @@ function InserterMenu({
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
const [selectedTab, setSelectedTab] = useState(getInitialTab());
|
|
63
|
-
const shouldUseZoomOut = selectedTab === 'patterns' || selectedTab === 'media';
|
|
64
|
+
const shouldUseZoomOut = hasSectionRootClientId && (selectedTab === 'patterns' || selectedTab === 'media');
|
|
64
65
|
useZoomOut(shouldUseZoomOut && isLargeViewport);
|
|
65
66
|
const [destinationRootClientId, onInsertBlocks, onToggleInsertionPoint] = useInsertionPoint({
|
|
66
67
|
rootClientId,
|