@wordpress/block-editor 14.8.0 → 14.8.1-next.a9f418477.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/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 +6 -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 +87 -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-lock/modal.js +4 -4
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-parent-selector/index.js +2 -15
- package/build/components/block-parent-selector/index.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 +7 -6
- 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/use-scale-canvas.js +68 -47
- package/build/components/iframe/use-scale-canvas.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/inspector-controls/slot.js +2 -13
- package/build/components/inspector-controls/slot.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/multi-selection-inspector/index.js +9 -25
- package/build/components/multi-selection-inspector/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/warning/index.js +2 -3
- package/build/components/warning/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/hooks/use-zoom-out.js +47 -14
- package/build/hooks/use-zoom-out.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 +6 -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 +80 -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-lock/modal.js +4 -4
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +2 -15
- package/build-module/components/block-parent-selector/index.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 +7 -6
- 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/use-scale-canvas.js +68 -47
- package/build-module/components/iframe/use-scale-canvas.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/inspector-controls/slot.js +3 -14
- package/build-module/components/inspector-controls/slot.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/multi-selection-inspector/index.js +9 -25
- package/build-module/components/multi-selection-inspector/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/warning/index.js +2 -3
- package/build-module/components/warning/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/hooks/use-zoom-out.js +48 -15
- package/build-module/hooks/use-zoom-out.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 +18 -5
- package/build-style/content.css +18 -5
- package/build-style/style-rtl.css +25 -64
- package/build-style/style.css +25 -64
- 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-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 +5 -0
- package/src/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +83 -0
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +112 -8
- package/src/components/block-lock/modal.js +4 -6
- package/src/components/block-parent-selector/index.js +1 -19
- package/src/components/block-patterns-list/index.js +12 -1
- package/src/components/block-patterns-list/stories/fixtures.js +1 -0
- 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 +9 -6
- package/src/components/block-tools/style.scss +5 -0
- package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +3 -3
- package/src/components/dimensions-tool/stories/aspect-ratio-tool.story.js +1 -1
- package/src/components/dimensions-tool/stories/index.story.js +1 -1
- package/src/components/dimensions-tool/stories/scale-tool.story.js +1 -1
- package/src/components/dimensions-tool/stories/width-height-tool.story.js +1 -1
- 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 +6 -1
- package/src/components/iframe/use-scale-canvas.js +103 -81
- 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/inspector-controls/slot.js +3 -22
- 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/multi-selection-inspector/index.js +17 -27
- package/src/components/multi-selection-inspector/style.scss +0 -12
- package/src/components/resolution-tool/stories/index.story.js +1 -1
- package/src/components/rich-text/index.js +5 -0
- package/src/components/spacing-sizes-control/style.scss +0 -29
- package/src/components/text-alignment-control/stories/index.story.js +1 -1
- 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/warning/index.js +3 -4
- package/src/components/warning/test/index.js +3 -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/hooks/use-zoom-out.js +48 -16
- 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
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -6,11 +6,11 @@ import { useReducedMotion, useResizeObserver } from '@wordpress/compose';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {Object} TransitionState
|
|
9
|
-
* @property {number} scaleValue
|
|
10
|
-
* @property {number} frameSize
|
|
11
|
-
* @property {number}
|
|
12
|
-
* @property {number} scrollTop
|
|
13
|
-
* @property {number} scrollHeight
|
|
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
14
|
*/
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -35,6 +35,21 @@ function calculateScale( {
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Compute the next scrollHeight based on the transition states.
|
|
40
|
+
*
|
|
41
|
+
* @param {TransitionState} transitionFrom Starting point of the transition
|
|
42
|
+
* @param {TransitionState} transitionTo Ending state of the transition
|
|
43
|
+
* @return {number} Next scrollHeight based on scale and frame value changes.
|
|
44
|
+
*/
|
|
45
|
+
function computeScrollHeightNext( transitionFrom, transitionTo ) {
|
|
46
|
+
const { scaleValue: prevScale, scrollHeight: prevScrollHeight } =
|
|
47
|
+
transitionFrom;
|
|
48
|
+
const { frameSize, scaleValue } = transitionTo;
|
|
49
|
+
|
|
50
|
+
return prevScrollHeight * ( scaleValue / prevScale ) + frameSize * 2;
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
/**
|
|
39
54
|
* Compute the next scrollTop position after scaling the iframe content.
|
|
40
55
|
*
|
|
@@ -44,41 +59,39 @@ function calculateScale( {
|
|
|
44
59
|
*/
|
|
45
60
|
function computeScrollTopNext( transitionFrom, transitionTo ) {
|
|
46
61
|
const {
|
|
47
|
-
|
|
62
|
+
containerHeight: prevContainerHeight,
|
|
48
63
|
frameSize: prevFrameSize,
|
|
49
64
|
scaleValue: prevScale,
|
|
50
|
-
scrollTop,
|
|
51
|
-
scrollHeight,
|
|
65
|
+
scrollTop: prevScrollTop,
|
|
52
66
|
} = transitionFrom;
|
|
53
|
-
const {
|
|
67
|
+
const { containerHeight, frameSize, scaleValue, scrollHeight } =
|
|
68
|
+
transitionTo;
|
|
54
69
|
// Step 0: Start with the current scrollTop.
|
|
55
|
-
let scrollTopNext =
|
|
70
|
+
let scrollTopNext = prevScrollTop;
|
|
56
71
|
// Step 1: Undo the effects of the previous scale and frame around the
|
|
57
72
|
// midpoint of the visible area.
|
|
58
73
|
scrollTopNext =
|
|
59
|
-
( scrollTopNext +
|
|
60
|
-
|
|
74
|
+
( scrollTopNext + prevContainerHeight / 2 - prevFrameSize ) /
|
|
75
|
+
prevScale -
|
|
76
|
+
prevContainerHeight / 2;
|
|
61
77
|
|
|
62
78
|
// Step 2: Apply the new scale and frame around the midpoint of the
|
|
63
79
|
// visible area.
|
|
64
80
|
scrollTopNext =
|
|
65
|
-
( scrollTopNext +
|
|
81
|
+
( scrollTopNext + containerHeight / 2 ) * scaleValue +
|
|
66
82
|
frameSize -
|
|
67
|
-
|
|
83
|
+
containerHeight / 2;
|
|
68
84
|
|
|
69
85
|
// Step 3: Handle an edge case so that you scroll to the top of the
|
|
70
86
|
// iframe if the top of the iframe content is visible in the container.
|
|
71
87
|
// The same edge case for the bottom is skipped because changing content
|
|
72
88
|
// makes calculating it impossible.
|
|
73
|
-
scrollTopNext =
|
|
89
|
+
scrollTopNext = prevScrollTop <= prevFrameSize ? 0 : scrollTopNext;
|
|
74
90
|
|
|
75
91
|
// This is the scrollTop value if you are scrolled to the bottom of the
|
|
76
92
|
// iframe. We can't just let the browser handle it because we need to
|
|
77
93
|
// animate the scaling.
|
|
78
|
-
const maxScrollTop =
|
|
79
|
-
scrollHeight * ( scaleValue / prevScale ) +
|
|
80
|
-
frameSize * 2 -
|
|
81
|
-
clientHeight;
|
|
94
|
+
const maxScrollTop = scrollHeight - containerHeight;
|
|
82
95
|
|
|
83
96
|
// Step 4: Clamp the scrollTopNext between the minimum and maximum
|
|
84
97
|
// possible scrollTop positions. Round the value to avoid subpixel
|
|
@@ -146,8 +159,10 @@ export function useScaleCanvas( {
|
|
|
146
159
|
} ) {
|
|
147
160
|
const [ contentResizeListener, { height: contentHeight } ] =
|
|
148
161
|
useResizeObserver();
|
|
149
|
-
const [
|
|
150
|
-
|
|
162
|
+
const [
|
|
163
|
+
containerResizeListener,
|
|
164
|
+
{ width: containerWidth, height: containerHeight },
|
|
165
|
+
] = useResizeObserver();
|
|
151
166
|
|
|
152
167
|
const initialContainerWidthRef = useRef( 0 );
|
|
153
168
|
const isZoomedOut = scale !== 1;
|
|
@@ -186,7 +201,7 @@ export function useScaleCanvas( {
|
|
|
186
201
|
const transitionFromRef = useRef( {
|
|
187
202
|
scaleValue,
|
|
188
203
|
frameSize,
|
|
189
|
-
|
|
204
|
+
containerHeight: 0,
|
|
190
205
|
scrollTop: 0,
|
|
191
206
|
scrollHeight: 0,
|
|
192
207
|
} );
|
|
@@ -198,7 +213,7 @@ export function useScaleCanvas( {
|
|
|
198
213
|
const transitionToRef = useRef( {
|
|
199
214
|
scaleValue,
|
|
200
215
|
frameSize,
|
|
201
|
-
|
|
216
|
+
containerHeight: 0,
|
|
202
217
|
scrollTop: 0,
|
|
203
218
|
scrollHeight: 0,
|
|
204
219
|
} );
|
|
@@ -223,6 +238,15 @@ export function useScaleCanvas( {
|
|
|
223
238
|
`${ scrollTopNext }px`
|
|
224
239
|
);
|
|
225
240
|
|
|
241
|
+
// If the container has a scrolllbar, force a scrollbar to prevent the content from shifting while animating.
|
|
242
|
+
iframeDocument.documentElement.style.setProperty(
|
|
243
|
+
'--wp-block-editor-iframe-zoom-out-overflow-behavior',
|
|
244
|
+
transitionFromRef.current.scrollHeight ===
|
|
245
|
+
transitionFromRef.current.containerHeight
|
|
246
|
+
? 'auto'
|
|
247
|
+
: 'scroll'
|
|
248
|
+
);
|
|
249
|
+
|
|
226
250
|
iframeDocument.documentElement.classList.add( 'zoom-out-animation' );
|
|
227
251
|
|
|
228
252
|
return iframeDocument.documentElement.animate(
|
|
@@ -275,11 +299,16 @@ export function useScaleCanvas( {
|
|
|
275
299
|
iframeDocument.documentElement.style.removeProperty(
|
|
276
300
|
'--wp-block-editor-iframe-zoom-out-scroll-top-next'
|
|
277
301
|
);
|
|
302
|
+
iframeDocument.documentElement.style.removeProperty(
|
|
303
|
+
'--wp-block-editor-iframe-zoom-out-overflow-behavior'
|
|
304
|
+
);
|
|
278
305
|
|
|
279
306
|
// Update previous values.
|
|
280
307
|
transitionFromRef.current = transitionToRef.current;
|
|
281
308
|
}, [ iframeDocument ] );
|
|
282
309
|
|
|
310
|
+
const previousIsZoomedOut = useRef( false );
|
|
311
|
+
|
|
283
312
|
/**
|
|
284
313
|
* Runs when zoom out mode is toggled, and sets the startAnimation flag
|
|
285
314
|
* so the animation will start when the next useEffect runs. We _only_
|
|
@@ -287,16 +316,22 @@ export function useScaleCanvas( {
|
|
|
287
316
|
* changes due to the container resizing.
|
|
288
317
|
*/
|
|
289
318
|
useEffect( () => {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
319
|
+
const trigger =
|
|
320
|
+
iframeDocument && previousIsZoomedOut.current !== isZoomedOut;
|
|
321
|
+
|
|
322
|
+
previousIsZoomedOut.current = isZoomedOut;
|
|
293
323
|
|
|
294
|
-
if (
|
|
295
|
-
|
|
324
|
+
if ( ! trigger ) {
|
|
325
|
+
return;
|
|
296
326
|
}
|
|
297
327
|
|
|
298
328
|
startAnimationRef.current = true;
|
|
299
329
|
|
|
330
|
+
if ( ! isZoomedOut ) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
|
|
300
335
|
return () => {
|
|
301
336
|
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
|
|
302
337
|
};
|
|
@@ -325,40 +360,41 @@ export function useScaleCanvas( {
|
|
|
325
360
|
} );
|
|
326
361
|
}
|
|
327
362
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
363
|
+
if ( scaleValue < 1 ) {
|
|
364
|
+
// If we are not going to animate the transition, set the scale and frame size directly.
|
|
365
|
+
// If we are animating, these values will be set when the animation is finished.
|
|
366
|
+
// Example: Opening sidebars that reduce the scale of the canvas, but we don't want to
|
|
367
|
+
// animate the transition.
|
|
368
|
+
if ( ! startAnimationRef.current ) {
|
|
369
|
+
iframeDocument.documentElement.style.setProperty(
|
|
370
|
+
'--wp-block-editor-iframe-zoom-out-scale',
|
|
371
|
+
scaleValue
|
|
372
|
+
);
|
|
373
|
+
iframeDocument.documentElement.style.setProperty(
|
|
374
|
+
'--wp-block-editor-iframe-zoom-out-frame-size',
|
|
375
|
+
`${ frameSize }px`
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
333
379
|
iframeDocument.documentElement.style.setProperty(
|
|
334
|
-
'--wp-block-editor-iframe-zoom-out-
|
|
335
|
-
|
|
380
|
+
'--wp-block-editor-iframe-zoom-out-content-height',
|
|
381
|
+
`${ contentHeight }px`
|
|
336
382
|
);
|
|
383
|
+
|
|
337
384
|
iframeDocument.documentElement.style.setProperty(
|
|
338
|
-
'--wp-block-editor-iframe-zoom-out-
|
|
339
|
-
`${
|
|
385
|
+
'--wp-block-editor-iframe-zoom-out-inner-height',
|
|
386
|
+
`${ containerHeight }px`
|
|
340
387
|
);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
iframeDocument.documentElement.style.setProperty(
|
|
344
|
-
'--wp-block-editor-iframe-zoom-out-content-height',
|
|
345
|
-
`${ contentHeight }px`
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
const clientHeight = iframeDocument.documentElement.clientHeight;
|
|
349
|
-
iframeDocument.documentElement.style.setProperty(
|
|
350
|
-
'--wp-block-editor-iframe-zoom-out-inner-height',
|
|
351
|
-
`${ clientHeight }px`
|
|
352
|
-
);
|
|
353
388
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
389
|
+
iframeDocument.documentElement.style.setProperty(
|
|
390
|
+
'--wp-block-editor-iframe-zoom-out-container-width',
|
|
391
|
+
`${ containerWidth }px`
|
|
392
|
+
);
|
|
393
|
+
iframeDocument.documentElement.style.setProperty(
|
|
394
|
+
'--wp-block-editor-iframe-zoom-out-scale-container-width',
|
|
395
|
+
`${ scaleContainerWidth }px`
|
|
396
|
+
);
|
|
397
|
+
}
|
|
362
398
|
|
|
363
399
|
/**
|
|
364
400
|
* Handle the zoom out animation:
|
|
@@ -397,18 +433,24 @@ export function useScaleCanvas( {
|
|
|
397
433
|
// the iframe at this point when we're about to animate the zoom out.
|
|
398
434
|
// The iframe scrollTop, scrollHeight, and clientHeight will all be
|
|
399
435
|
// the most accurate.
|
|
400
|
-
transitionFromRef.current.clientHeight =
|
|
401
|
-
transitionFromRef.current.clientHeight ?? clientHeight;
|
|
402
436
|
transitionFromRef.current.scrollTop =
|
|
403
437
|
iframeDocument.documentElement.scrollTop;
|
|
404
438
|
transitionFromRef.current.scrollHeight =
|
|
405
439
|
iframeDocument.documentElement.scrollHeight;
|
|
440
|
+
// Use containerHeight, as it's the previous container height before the zoom out animation starts.
|
|
441
|
+
transitionFromRef.current.containerHeight = containerHeight;
|
|
406
442
|
|
|
407
443
|
transitionToRef.current = {
|
|
408
444
|
scaleValue,
|
|
409
445
|
frameSize,
|
|
410
|
-
|
|
446
|
+
containerHeight:
|
|
447
|
+
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.
|
|
411
448
|
};
|
|
449
|
+
|
|
450
|
+
transitionToRef.current.scrollHeight = computeScrollHeightNext(
|
|
451
|
+
transitionFromRef.current,
|
|
452
|
+
transitionToRef.current
|
|
453
|
+
);
|
|
412
454
|
transitionToRef.current.scrollTop = computeScrollTopNext(
|
|
413
455
|
transitionFromRef.current,
|
|
414
456
|
transitionToRef.current
|
|
@@ -424,27 +466,6 @@ export function useScaleCanvas( {
|
|
|
424
466
|
}
|
|
425
467
|
}
|
|
426
468
|
}
|
|
427
|
-
|
|
428
|
-
return () => {
|
|
429
|
-
iframeDocument.documentElement.style.removeProperty(
|
|
430
|
-
'--wp-block-editor-iframe-zoom-out-scale'
|
|
431
|
-
);
|
|
432
|
-
iframeDocument.documentElement.style.removeProperty(
|
|
433
|
-
'--wp-block-editor-iframe-zoom-out-frame-size'
|
|
434
|
-
);
|
|
435
|
-
iframeDocument.documentElement.style.removeProperty(
|
|
436
|
-
'--wp-block-editor-iframe-zoom-out-content-height'
|
|
437
|
-
);
|
|
438
|
-
iframeDocument.documentElement.style.removeProperty(
|
|
439
|
-
'--wp-block-editor-iframe-zoom-out-inner-height'
|
|
440
|
-
);
|
|
441
|
-
iframeDocument.documentElement.style.removeProperty(
|
|
442
|
-
'--wp-block-editor-iframe-zoom-out-container-width'
|
|
443
|
-
);
|
|
444
|
-
iframeDocument.documentElement.style.removeProperty(
|
|
445
|
-
'--wp-block-editor-iframe-zoom-out-scale-container-width'
|
|
446
|
-
);
|
|
447
|
-
};
|
|
448
469
|
}, [
|
|
449
470
|
startZoomOutAnimation,
|
|
450
471
|
finishZoomOutAnimation,
|
|
@@ -455,6 +476,7 @@ export function useScaleCanvas( {
|
|
|
455
476
|
iframeDocument,
|
|
456
477
|
contentHeight,
|
|
457
478
|
containerWidth,
|
|
479
|
+
containerHeight,
|
|
458
480
|
maxContainerWidth,
|
|
459
481
|
scaleContainerWidth,
|
|
460
482
|
] );
|
|
@@ -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
|
|
|
22
19
|
function BlockPatternsTab( {
|
|
23
20
|
onSelectCategory,
|
|
@@ -31,19 +28,6 @@ function BlockPatternsTab( {
|
|
|
31
28
|
const categories = usePatternCategories( rootClientId );
|
|
32
29
|
|
|
33
30
|
const isMobile = useViewportMatch( 'medium', '<' );
|
|
34
|
-
const isResolvingPatterns = useSelect(
|
|
35
|
-
( select ) =>
|
|
36
|
-
unlock( select( blockEditorStore ) ).isResolvingPatterns(),
|
|
37
|
-
[]
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
if ( isResolvingPatterns ) {
|
|
41
|
-
return (
|
|
42
|
-
<div className="block-editor-inserter__patterns-loading">
|
|
43
|
-
<Spinner />
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
31
|
|
|
48
32
|
if ( ! categories.length ) {
|
|
49
33
|
return <InserterNoResults />;
|
|
@@ -58,6 +58,11 @@ function InserterMenu(
|
|
|
58
58
|
( select ) => unlock( select( blockEditorStore ) ).isZoomOut(),
|
|
59
59
|
[]
|
|
60
60
|
);
|
|
61
|
+
const hasSectionRootClientId = useSelect(
|
|
62
|
+
( select ) =>
|
|
63
|
+
!! unlock( select( blockEditorStore ) ).getSectionRootClientId(),
|
|
64
|
+
[]
|
|
65
|
+
);
|
|
61
66
|
const [ filterValue, setFilterValue, delayedFilterValue ] =
|
|
62
67
|
useDebouncedInput( __experimentalFilterValue );
|
|
63
68
|
const [ hoveredItem, setHoveredItem ] = useState( null );
|
|
@@ -81,7 +86,9 @@ function InserterMenu(
|
|
|
81
86
|
const [ selectedTab, setSelectedTab ] = useState( getInitialTab() );
|
|
82
87
|
|
|
83
88
|
const shouldUseZoomOut =
|
|
84
|
-
|
|
89
|
+
hasSectionRootClientId &&
|
|
90
|
+
( selectedTab === 'patterns' || selectedTab === 'media' );
|
|
91
|
+
|
|
85
92
|
useZoomOut( shouldUseZoomOut && isLargeViewport );
|
|
86
93
|
|
|
87
94
|
const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { Draggable } from '@wordpress/components';
|
|
5
|
-
import {
|
|
6
|
-
createBlock,
|
|
7
|
-
serialize,
|
|
8
|
-
store as blocksStore,
|
|
9
|
-
} from '@wordpress/blocks';
|
|
5
|
+
import { createBlock, store as blocksStore } from '@wordpress/blocks';
|
|
10
6
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
|
+
import { useMemo } from '@wordpress/element';
|
|
11
8
|
|
|
12
9
|
/**
|
|
13
10
|
* Internal dependencies
|
|
@@ -24,20 +21,6 @@ const InserterDraggableBlocks = ( {
|
|
|
24
21
|
children,
|
|
25
22
|
pattern,
|
|
26
23
|
} ) => {
|
|
27
|
-
const transferData = {
|
|
28
|
-
type: 'inserter',
|
|
29
|
-
blocks,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const blocksContainMedia =
|
|
33
|
-
blocks.filter(
|
|
34
|
-
( block ) =>
|
|
35
|
-
( block.name === 'core/image' ||
|
|
36
|
-
block.name === 'core/audio' ||
|
|
37
|
-
block.name === 'core/video' ) &&
|
|
38
|
-
( block.attributes.url || block.attributes.src )
|
|
39
|
-
).length > 0;
|
|
40
|
-
|
|
41
24
|
const blockTypeIcon = useSelect(
|
|
42
25
|
( select ) => {
|
|
43
26
|
const { getBlockType } = select( blocksStore );
|
|
@@ -52,6 +35,13 @@ const InserterDraggableBlocks = ( {
|
|
|
52
35
|
useDispatch( blockEditorStore )
|
|
53
36
|
);
|
|
54
37
|
|
|
38
|
+
const patternBlock = useMemo( () => {
|
|
39
|
+
return pattern?.type === INSERTER_PATTERN_TYPES.user &&
|
|
40
|
+
pattern?.syncStatus !== 'unsynced'
|
|
41
|
+
? [ createBlock( 'core/block', { ref: pattern.id } ) ]
|
|
42
|
+
: undefined;
|
|
43
|
+
}, [ pattern?.type, pattern?.syncStatus, pattern?.id ] );
|
|
44
|
+
|
|
55
45
|
if ( ! isEnabled ) {
|
|
56
46
|
return children( {
|
|
57
47
|
draggable: false,
|
|
@@ -60,21 +50,21 @@ const InserterDraggableBlocks = ( {
|
|
|
60
50
|
} );
|
|
61
51
|
}
|
|
62
52
|
|
|
53
|
+
const draggableBlocks = patternBlock ?? blocks;
|
|
63
54
|
return (
|
|
64
55
|
<Draggable
|
|
65
56
|
__experimentalTransferDataType="wp-blocks"
|
|
66
|
-
transferData={
|
|
57
|
+
transferData={ { type: 'inserter', blocks: draggableBlocks } }
|
|
67
58
|
onDragStart={ ( event ) => {
|
|
68
59
|
startDragging();
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
60
|
+
for ( const block of draggableBlocks ) {
|
|
61
|
+
const type = `wp-block:${ block.name }`;
|
|
62
|
+
// This will fill in the dataTransfer.types array so that
|
|
63
|
+
// the drop zone can check if the draggable is eligible.
|
|
64
|
+
// Unfortuantely, on drag start, we don't have access to the
|
|
65
|
+
// actual data, only the data keys/types.
|
|
66
|
+
event.dataTransfer.items.add( '', type );
|
|
67
|
+
}
|
|
78
68
|
} }
|
|
79
69
|
onDragEnd={ () => {
|
|
80
70
|
stopDragging();
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
__experimentalUseSlotFills as useSlotFills,
|
|
6
|
-
__unstableMotionContext as MotionContext,
|
|
7
|
-
} from '@wordpress/components';
|
|
8
|
-
import { useContext, useMemo } from '@wordpress/element';
|
|
4
|
+
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
|
|
9
5
|
import warning from '@wordpress/warning';
|
|
10
6
|
import deprecated from '@wordpress/deprecated';
|
|
11
7
|
|
|
@@ -37,19 +33,6 @@ export default function InspectorControlsSlot( {
|
|
|
37
33
|
const slotFill = groups[ group ];
|
|
38
34
|
const fills = useSlotFills( slotFill?.name );
|
|
39
35
|
|
|
40
|
-
const motionContextValue = useContext( MotionContext );
|
|
41
|
-
|
|
42
|
-
const computedFillProps = useMemo(
|
|
43
|
-
() => ( {
|
|
44
|
-
...fillProps,
|
|
45
|
-
forwardedContext: [
|
|
46
|
-
...( fillProps?.forwardedContext ?? [] ),
|
|
47
|
-
[ MotionContext.Provider, { value: motionContextValue } ],
|
|
48
|
-
],
|
|
49
|
-
} ),
|
|
50
|
-
[ motionContextValue, fillProps ]
|
|
51
|
-
);
|
|
52
|
-
|
|
53
36
|
if ( ! slotFill ) {
|
|
54
37
|
warning( `Unknown InspectorControls group "${ group }" provided.` );
|
|
55
38
|
return null;
|
|
@@ -66,14 +49,12 @@ export default function InspectorControlsSlot( {
|
|
|
66
49
|
<BlockSupportToolsPanel group={ group } label={ label }>
|
|
67
50
|
<BlockSupportSlotContainer
|
|
68
51
|
{ ...props }
|
|
69
|
-
fillProps={
|
|
52
|
+
fillProps={ fillProps }
|
|
70
53
|
Slot={ Slot }
|
|
71
54
|
/>
|
|
72
55
|
</BlockSupportToolsPanel>
|
|
73
56
|
);
|
|
74
57
|
}
|
|
75
58
|
|
|
76
|
-
return
|
|
77
|
-
<Slot { ...props } fillProps={ computedFillProps } bubblesVirtually />
|
|
78
|
-
);
|
|
59
|
+
return <Slot { ...props } fillProps={ fillProps } bubblesVirtually />;
|
|
79
60
|
}
|
|
@@ -12,13 +12,14 @@ This component is used for blocks that display text, commonly inside a
|
|
|
12
12
|
Renders a letter spacing control.
|
|
13
13
|
|
|
14
14
|
```jsx
|
|
15
|
-
import { LetterSpacingControl } from '@wordpress/block-editor';
|
|
15
|
+
import { __experimentalLetterSpacingControl as LetterSpacingControl } from '@wordpress/block-editor';
|
|
16
16
|
|
|
17
17
|
const MyLetterSpacingControl = () => (
|
|
18
18
|
<LetterSpacingControl
|
|
19
19
|
value={ value }
|
|
20
20
|
onChange={ onChange }
|
|
21
21
|
__unstableInputWidth="auto"
|
|
22
|
+
__next40pxDefaultSize
|
|
22
23
|
/>
|
|
23
24
|
);
|
|
24
25
|
```
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
__experimentalUnitControl as UnitControl,
|
|
6
6
|
__experimentalUseCustomUnits as useCustomUnits,
|
|
7
7
|
} from '@wordpress/components';
|
|
8
|
+
import deprecated from '@wordpress/deprecated';
|
|
8
9
|
import { __ } from '@wordpress/i18n';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -35,9 +36,25 @@ export default function LetterSpacingControl( {
|
|
|
35
36
|
availableUnits: availableUnits || [ 'px', 'em', 'rem' ],
|
|
36
37
|
defaultValues: { px: 2, em: 0.2, rem: 0.2 },
|
|
37
38
|
} );
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
! __next40pxDefaultSize &&
|
|
42
|
+
( otherProps.size === undefined || otherProps.size === 'default' )
|
|
43
|
+
) {
|
|
44
|
+
deprecated(
|
|
45
|
+
`36px default size for wp.blockEditor.__experimentalLetterSpacingControl`,
|
|
46
|
+
{
|
|
47
|
+
since: '6.8',
|
|
48
|
+
version: '7.1',
|
|
49
|
+
hint: 'Set the `__next40pxDefaultSize` prop to true to start opting into the new default size, which will become the default in a future version.',
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
38
54
|
return (
|
|
39
55
|
<UnitControl
|
|
40
56
|
__next40pxDefaultSize={ __next40pxDefaultSize }
|
|
57
|
+
__shouldNotWarnDeprecated36pxSize
|
|
41
58
|
{ ...otherProps }
|
|
42
59
|
label={ __( 'Letter spacing' ) }
|
|
43
60
|
value={ value }
|
|
@@ -93,6 +93,7 @@ const LineHeightControl = ( {
|
|
|
93
93
|
<div className="block-editor-line-height-control">
|
|
94
94
|
<NumberControl
|
|
95
95
|
{ ...otherProps }
|
|
96
|
+
__shouldNotWarnDeprecated36pxSize
|
|
96
97
|
__next40pxDefaultSize={ __next40pxDefaultSize }
|
|
97
98
|
__unstableInputWidth={ __unstableInputWidth }
|
|
98
99
|
__unstableStateReducer={ stateReducer }
|
|
@@ -19,7 +19,6 @@ import { __ } from '@wordpress/i18n';
|
|
|
19
19
|
import { useState, useEffect } from '@wordpress/element';
|
|
20
20
|
import { useSelect } from '@wordpress/data';
|
|
21
21
|
import { keyboardReturn } from '@wordpress/icons';
|
|
22
|
-
import { pasteHandler } from '@wordpress/blocks';
|
|
23
22
|
import deprecated from '@wordpress/deprecated';
|
|
24
23
|
|
|
25
24
|
/**
|
|
@@ -29,6 +28,7 @@ import MediaUpload from '../media-upload';
|
|
|
29
28
|
import MediaUploadCheck from '../media-upload/check';
|
|
30
29
|
import URLPopover from '../url-popover';
|
|
31
30
|
import { store as blockEditorStore } from '../../store';
|
|
31
|
+
import { parseDropEvent } from '../use-on-block-drop';
|
|
32
32
|
|
|
33
33
|
const noop = () => {};
|
|
34
34
|
|
|
@@ -229,30 +229,15 @@ export function MediaPlaceholder( {
|
|
|
229
229
|
} );
|
|
230
230
|
};
|
|
231
231
|
|
|
232
|
-
async function handleBlocksDrop(
|
|
233
|
-
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
232
|
+
async function handleBlocksDrop( event ) {
|
|
233
|
+
const { blocks } = parseDropEvent( event );
|
|
236
234
|
|
|
237
|
-
|
|
238
|
-
return _blocks.flatMap( ( block ) =>
|
|
239
|
-
( block.name === 'core/image' ||
|
|
240
|
-
block.name === 'core/audio' ||
|
|
241
|
-
block.name === 'core/video' ) &&
|
|
242
|
-
( block.attributes.url || block.attributes.src )
|
|
243
|
-
? [ block ]
|
|
244
|
-
: recursivelyFindMediaFromBlocks( block.innerBlocks )
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const mediaBlocks = recursivelyFindMediaFromBlocks( blocks );
|
|
249
|
-
|
|
250
|
-
if ( ! mediaBlocks.length ) {
|
|
235
|
+
if ( ! blocks?.length ) {
|
|
251
236
|
return;
|
|
252
237
|
}
|
|
253
238
|
|
|
254
239
|
const uploadedMediaList = await Promise.all(
|
|
255
|
-
|
|
240
|
+
blocks.map( ( block ) => {
|
|
256
241
|
const blockType = block.name.split( '/' )[ 1 ];
|
|
257
242
|
if ( block.attributes.id ) {
|
|
258
243
|
block.attributes.type = blockType;
|
|
@@ -292,13 +277,6 @@ export function MediaPlaceholder( {
|
|
|
292
277
|
}
|
|
293
278
|
}
|
|
294
279
|
|
|
295
|
-
async function onDrop( event ) {
|
|
296
|
-
const blocks = pasteHandler( {
|
|
297
|
-
HTML: event.dataTransfer?.getData( 'default' ),
|
|
298
|
-
} );
|
|
299
|
-
return await handleBlocksDrop( blocks );
|
|
300
|
-
}
|
|
301
|
-
|
|
302
280
|
const onUpload = ( event ) => {
|
|
303
281
|
onFilesUpload( event.target.files );
|
|
304
282
|
};
|
|
@@ -385,7 +363,26 @@ export function MediaPlaceholder( {
|
|
|
385
363
|
return null;
|
|
386
364
|
}
|
|
387
365
|
|
|
388
|
-
return
|
|
366
|
+
return (
|
|
367
|
+
<DropZone
|
|
368
|
+
onFilesDrop={ onFilesUpload }
|
|
369
|
+
onDrop={ handleBlocksDrop }
|
|
370
|
+
isEligible={ ( dataTransfer ) => {
|
|
371
|
+
const prefix = 'wp-block:core/';
|
|
372
|
+
const types = [];
|
|
373
|
+
for ( const type of dataTransfer.types ) {
|
|
374
|
+
if ( type.startsWith( prefix ) ) {
|
|
375
|
+
types.push( type.slice( prefix.length ) );
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return (
|
|
379
|
+
types.every( ( type ) =>
|
|
380
|
+
allowedTypes.includes( type )
|
|
381
|
+
) && ( multiple ? true : types.length === 1 )
|
|
382
|
+
);
|
|
383
|
+
} }
|
|
384
|
+
/>
|
|
385
|
+
);
|
|
389
386
|
};
|
|
390
387
|
|
|
391
388
|
const renderCancelLink = () => {
|