@wordpress/block-editor 10.1.1-next.4d3b314fd5.0 → 10.3.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 +14 -0
- package/README.md +41 -0
- package/build/components/block-controls/slot.js +2 -2
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-draggable/draggable-chip.js +4 -2
- package/build/components/block-draggable/draggable-chip.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -5
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block-list-compact.native.js +1 -0
- package/build/components/block-list/block-list-compact.native.js.map +1 -1
- package/build/components/block-list/block.js +72 -14
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +79 -12
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +7 -23
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/modal.js +9 -6
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-parent-selector/index.js +5 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-patterns-list/index.js +5 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-popover/drop-zone.js +85 -0
- package/build/components/block-popover/drop-zone.js.map +1 -0
- package/build/components/block-popover/inbetween.js +3 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +22 -17
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js +2 -2
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +6 -9
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-preview/live.js +3 -7
- package/build/components/block-preview/live.js.map +1 -1
- package/build/components/block-selection-clearer/index.js +9 -1
- package/build/components/block-selection-clearer/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +22 -16
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +18 -42
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +4 -4
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -1
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +50 -20
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +15 -3
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors-gradients/control.js +1 -1
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/panel-color-gradient-settings.js +2 -2
- package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +256 -0
- package/build/components/font-sizes/fluid-utils.js.map +1 -0
- package/build/components/font-sizes/index.js +8 -0
- package/build/components/font-sizes/index.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +2 -2
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/index.js +0 -9
- package/build/components/index.js.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +151 -78
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +1 -1
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/menu.js +14 -3
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inserter/search-items.js +2 -17
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +4 -2
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inspector-controls/slot.js +2 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/preview-options/index.js +2 -3
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/rich-text/index.js +17 -0
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +10 -2
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +40 -9
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +98 -57
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +12 -12
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-on-block-drop/types.js +6 -0
- package/build/components/use-on-block-drop/types.js.map +1 -0
- package/build/hooks/align.js +1 -3
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/align.native.js +1 -7
- package/build/hooks/align.native.js.map +1 -1
- package/build/hooks/font-size.js +60 -0
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/margin.js +6 -5
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +2 -1
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/style.js +126 -4
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-typography-props.js +17 -3
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/hooks/utils.js +1 -1
- package/build/hooks/utils.js.map +1 -1
- package/build/store/actions.js +59 -45
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +3 -0
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +36 -18
- package/build/store/reducer.js.map +1 -1
- package/build/utils/math.js +14 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/pre-parse-patterns.js +19 -2
- package/build/utils/pre-parse-patterns.js.map +1 -1
- package/build-module/components/block-controls/slot.js +3 -3
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-draggable/draggable-chip.js +7 -3
- package/build-module/components/block-draggable/draggable-chip.js.map +1 -1
- package/build-module/components/block-inspector/index.js +5 -6
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block-list-compact.native.js +1 -0
- package/build-module/components/block-list/block-list-compact.native.js.map +1 -1
- package/build-module/components/block-list/block.js +72 -14
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +80 -13
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +8 -24
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/modal.js +10 -8
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +5 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +5 -4
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-popover/drop-zone.js +70 -0
- package/build-module/components/block-popover/drop-zone.js.map +1 -0
- package/build-module/components/block-popover/inbetween.js +3 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +22 -17
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +6 -9
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-preview/live.js +3 -6
- package/build-module/components/block-preview/live.js.map +1 -1
- package/build-module/components/block-selection-clearer/index.js +9 -1
- package/build-module/components/block-selection-clearer/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +25 -19
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +19 -44
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +4 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +2 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +48 -20
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +15 -3
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +2 -2
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js +3 -3
- package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +245 -0
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
- package/build-module/components/font-sizes/index.js +1 -0
- package/build-module/components/font-sizes/index.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +2 -2
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/index.js +0 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/build-module/components/inner-blocks/use-inner-block-template-sync.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +148 -81
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +3 -3
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +10 -3
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inserter/search-items.js +3 -17
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +4 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +3 -2
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -14
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/preview-options/index.js +2 -3
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +17 -0
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +10 -3
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +40 -10
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +98 -58
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +12 -12
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/types.js +2 -0
- package/build-module/components/use-on-block-drop/types.js.map +1 -0
- package/build-module/hooks/align.js +1 -2
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/align.native.js +1 -6
- package/build-module/hooks/align.native.js.map +1 -1
- package/build-module/hooks/font-size.js +59 -1
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/margin.js +6 -5
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +2 -1
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/style.js +124 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-typography-props.js +17 -4
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/hooks/utils.js +2 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/store/actions.js +55 -42
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +3 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +36 -19
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/pre-parse-patterns.js +19 -2
- package/build-module/utils/pre-parse-patterns.js.map +1 -1
- package/build-style/style-rtl.css +256 -152
- package/build-style/style.css +256 -152
- package/package.json +28 -29
- package/src/components/block-breadcrumb/test/index.js +1 -1
- package/src/components/block-controls/slot.js +3 -3
- package/src/components/block-draggable/draggable-chip.js +4 -2
- package/src/components/block-inspector/index.js +8 -11
- package/src/components/block-list/block-list-compact.native.js +1 -0
- package/src/components/block-list/block.js +111 -7
- package/src/components/block-list/block.native.js +123 -9
- package/src/components/block-list/style.scss +93 -126
- package/src/components/block-list/use-in-between-inserter.js +8 -19
- package/src/components/block-lock/modal.js +12 -7
- package/src/components/block-mover/style.scss +0 -1
- package/src/components/block-parent-selector/index.js +5 -5
- package/src/components/block-patterns-list/index.js +9 -5
- package/src/components/block-patterns-list/style.scss +7 -3
- package/src/components/block-popover/README.md +8 -0
- package/src/components/block-popover/drop-zone.js +63 -0
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +39 -22
- package/src/components/block-popover/style.scss +17 -1
- package/src/components/block-preview/auto.js +1 -1
- package/src/components/block-preview/index.js +7 -8
- package/src/components/block-preview/live.js +2 -7
- package/src/components/block-preview/test/index.js +1 -7
- package/src/components/block-selection-clearer/index.js +7 -2
- package/src/components/block-selection-clearer/test/index.js +118 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +32 -18
- package/src/components/block-settings-menu/test/block-mode-toggle.js +17 -17
- package/src/components/block-styles/index.js +26 -49
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +104 -33
- package/src/components/block-switcher/test/index.js +121 -61
- package/src/components/block-toolbar/index.js +4 -6
- package/src/components/block-toolbar/style.scss +38 -14
- package/src/components/block-tools/back-compat.js +1 -0
- package/src/components/block-tools/insertion-point.js +42 -17
- package/src/components/block-tools/selected-block-popover.js +14 -1
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +32 -52
- package/src/components/color-palette/test/control.js +11 -15
- package/src/components/colors-gradients/control.js +2 -2
- package/src/components/colors-gradients/panel-color-gradient-settings.js +3 -4
- package/src/components/colors-gradients/test/control.js +49 -77
- package/src/components/font-sizes/fluid-utils.js +296 -0
- package/src/components/font-sizes/index.js +1 -0
- package/src/components/font-sizes/test/fluid-utils.js +168 -0
- package/src/components/image-editor/use-transform-image.js +2 -2
- package/src/components/image-size-control/test/index.js +47 -60
- package/src/components/index.js +0 -1
- package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -2
- package/src/components/inserter/block-patterns-tab.js +232 -98
- package/src/components/inserter/block-types-tab.js +3 -3
- package/src/components/inserter/menu.js +15 -2
- package/src/components/inserter/search-items.js +3 -15
- package/src/components/inserter/style.scss +94 -9
- package/src/components/inserter/test/reusable-blocks-tab.js +6 -6
- package/src/components/inserter/test/search-items.js +4 -0
- package/src/components/inserter-draggable-blocks/index.js +12 -2
- package/src/components/inserter-list-item/style.scss +20 -1
- package/src/components/inspector-controls/slot.js +6 -2
- package/src/components/link-control/test/index.js +1 -1
- package/src/components/list-view/use-list-view-drop-zone.js +4 -18
- package/src/components/panel-color-settings/test/index.js +4 -4
- package/src/components/preview-options/index.js +2 -2
- package/src/components/preview-options/style.scss +1 -1
- package/src/components/provider/test/use-block-sync.js +131 -165
- package/src/components/responsive-block-control/test/index.js +77 -122
- package/src/components/rich-text/index.js +22 -0
- package/src/components/spacing-sizes-control/index.js +15 -3
- package/src/components/spacing-sizes-control/spacing-input-control.js +24 -9
- package/src/components/spacing-sizes-control/style.scss +42 -31
- package/src/components/use-block-drop-zone/index.js +136 -79
- package/src/components/use-block-drop-zone/test/index.js +333 -81
- package/src/components/use-on-block-drop/index.js +11 -12
- package/src/components/use-on-block-drop/types.ts +1 -0
- package/src/hooks/align.js +3 -2
- package/src/hooks/align.native.js +5 -8
- package/src/hooks/font-size.js +75 -0
- package/src/hooks/margin.js +5 -4
- package/src/hooks/padding.js +1 -0
- package/src/hooks/style.js +122 -3
- package/src/hooks/test/style.js +206 -1
- package/src/hooks/test/use-typography-props.js +22 -0
- package/src/hooks/use-typography-props.js +18 -3
- package/src/hooks/utils.js +6 -2
- package/src/store/actions.js +20 -12
- package/src/store/defaults.js +3 -0
- package/src/store/reducer.js +35 -28
- package/src/store/test/actions.js +0 -9
- package/src/utils/math.js +17 -0
- package/src/utils/pre-parse-patterns.js +12 -7
- package/build/components/inserter/pattern-panel.js +0 -87
- package/build/components/inserter/pattern-panel.js.map +0 -1
- package/build-module/components/inserter/pattern-panel.js +0 -74
- package/build-module/components/inserter/pattern-panel.js.map +0 -1
- package/src/components/inserter/pattern-panel.js +0 -93
|
@@ -8,15 +8,20 @@ import {
|
|
|
8
8
|
__experimentalUseDropZone as useDropZone,
|
|
9
9
|
} from '@wordpress/compose';
|
|
10
10
|
import { isRTL } from '@wordpress/i18n';
|
|
11
|
+
import { isUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock } from '@wordpress/blocks';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
14
15
|
*/
|
|
15
16
|
import useOnBlockDrop from '../use-on-block-drop';
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
getDistanceToNearestEdge,
|
|
19
|
+
isPointContainedByRect,
|
|
20
|
+
} from '../../utils/math';
|
|
17
21
|
import { store as blockEditorStore } from '../../store';
|
|
18
22
|
|
|
19
23
|
/** @typedef {import('../../utils/math').WPPoint} WPPoint */
|
|
24
|
+
/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* The orientation of a block list.
|
|
@@ -25,16 +30,31 @@ import { store as blockEditorStore } from '../../store';
|
|
|
25
30
|
*/
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
|
-
*
|
|
29
|
-
* at.
|
|
33
|
+
* The insert position when dropping a block.
|
|
30
34
|
*
|
|
31
|
-
* @
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
* @typedef {'before'|'after'} WPInsertPosition
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {Object} WPBlockData
|
|
40
|
+
* @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.
|
|
41
|
+
* @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.
|
|
42
|
+
* @property {number} blockIndex The index of the block.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get the drop target position from a given drop point and the orientation.
|
|
34
47
|
*
|
|
35
|
-
* @
|
|
48
|
+
* @param {WPBlockData[]} blocksData The block data list.
|
|
49
|
+
* @param {WPPoint} position The position of the item being dragged.
|
|
50
|
+
* @param {WPBlockListOrientation} orientation The orientation of the block list.
|
|
51
|
+
* @return {[number, WPDropOperation]} The drop target position.
|
|
36
52
|
*/
|
|
37
|
-
export function
|
|
53
|
+
export function getDropTargetPosition(
|
|
54
|
+
blocksData,
|
|
55
|
+
position,
|
|
56
|
+
orientation = 'vertical'
|
|
57
|
+
) {
|
|
38
58
|
const allowedEdges =
|
|
39
59
|
orientation === 'horizontal'
|
|
40
60
|
? [ 'left', 'right' ]
|
|
@@ -42,49 +62,67 @@ export function getNearestBlockIndex( elements, position, orientation ) {
|
|
|
42
62
|
|
|
43
63
|
const isRightToLeft = isRTL();
|
|
44
64
|
|
|
45
|
-
let
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
elements.forEach( ( element, index ) => {
|
|
49
|
-
const rect = element.getBoundingClientRect();
|
|
50
|
-
const [ distance, edge ] = getDistanceToNearestEdge(
|
|
51
|
-
position,
|
|
52
|
-
rect,
|
|
53
|
-
allowedEdges
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if ( candidateDistance === undefined || distance < candidateDistance ) {
|
|
57
|
-
// If the user is dropping to the trailing edge of the block
|
|
58
|
-
// add 1 to the index to represent dragging after.
|
|
59
|
-
// Take RTL languages into account where the left edge is
|
|
60
|
-
// the trailing edge.
|
|
61
|
-
const isTrailingEdge =
|
|
62
|
-
edge === 'bottom' ||
|
|
63
|
-
( ! isRightToLeft && edge === 'right' ) ||
|
|
64
|
-
( isRightToLeft && edge === 'left' );
|
|
65
|
-
const offset = isTrailingEdge ? 1 : 0;
|
|
66
|
-
|
|
67
|
-
// Update the currently known best candidate.
|
|
68
|
-
candidateDistance = distance;
|
|
69
|
-
candidateIndex = index + offset;
|
|
70
|
-
}
|
|
71
|
-
} );
|
|
65
|
+
let nearestIndex = 0;
|
|
66
|
+
let insertPosition = 'before';
|
|
67
|
+
let minDistance = Infinity;
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
}
|
|
69
|
+
blocksData.forEach(
|
|
70
|
+
( { isUnmodifiedDefaultBlock, getBoundingClientRect, blockIndex } ) => {
|
|
71
|
+
const rect = getBoundingClientRect();
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
let [ distance, edge ] = getDistanceToNearestEdge(
|
|
74
|
+
position,
|
|
75
|
+
rect,
|
|
76
|
+
allowedEdges
|
|
77
|
+
);
|
|
78
|
+
// Prioritize the element if the point is inside of an unmodified default block.
|
|
79
|
+
if (
|
|
80
|
+
isUnmodifiedDefaultBlock &&
|
|
81
|
+
isPointContainedByRect( position, rect )
|
|
82
|
+
) {
|
|
83
|
+
distance = 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ( distance < minDistance ) {
|
|
87
|
+
// Where the dropped block will be inserted on the nearest block.
|
|
88
|
+
insertPosition =
|
|
89
|
+
edge === 'bottom' ||
|
|
90
|
+
( ! isRightToLeft && edge === 'right' ) ||
|
|
91
|
+
( isRightToLeft && edge === 'left' )
|
|
92
|
+
? 'after'
|
|
93
|
+
: 'before';
|
|
94
|
+
|
|
95
|
+
// Update the currently known best candidate.
|
|
96
|
+
minDistance = distance;
|
|
97
|
+
nearestIndex = blockIndex;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
87
100
|
);
|
|
101
|
+
|
|
102
|
+
const adjacentIndex =
|
|
103
|
+
nearestIndex + ( insertPosition === 'after' ? 1 : -1 );
|
|
104
|
+
const isNearestBlockUnmodifiedDefaultBlock =
|
|
105
|
+
!! blocksData[ nearestIndex ]?.isUnmodifiedDefaultBlock;
|
|
106
|
+
const isAdjacentBlockUnmodifiedDefaultBlock =
|
|
107
|
+
!! blocksData[ adjacentIndex ]?.isUnmodifiedDefaultBlock;
|
|
108
|
+
|
|
109
|
+
// If both blocks are not unmodified default blocks then just insert between them.
|
|
110
|
+
if (
|
|
111
|
+
! isNearestBlockUnmodifiedDefaultBlock &&
|
|
112
|
+
! isAdjacentBlockUnmodifiedDefaultBlock
|
|
113
|
+
) {
|
|
114
|
+
// If the user is dropping to the trailing edge of the block
|
|
115
|
+
// add 1 to the index to represent dragging after.
|
|
116
|
+
const insertionIndex =
|
|
117
|
+
insertPosition === 'after' ? nearestIndex + 1 : nearestIndex;
|
|
118
|
+
return [ insertionIndex, 'insert' ];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Otherwise, replace the nearest unmodified default block.
|
|
122
|
+
return [
|
|
123
|
+
isNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex,
|
|
124
|
+
'replace',
|
|
125
|
+
];
|
|
88
126
|
}
|
|
89
127
|
|
|
90
128
|
/**
|
|
@@ -104,7 +142,10 @@ export default function useBlockDropZone( {
|
|
|
104
142
|
// an empty string to represent top-level blocks.
|
|
105
143
|
rootClientId: targetRootClientId = '',
|
|
106
144
|
} = {} ) {
|
|
107
|
-
const [
|
|
145
|
+
const [ dropTarget, setDropTarget ] = useState( {
|
|
146
|
+
index: null,
|
|
147
|
+
operation: 'insert',
|
|
148
|
+
} );
|
|
108
149
|
|
|
109
150
|
const isDisabled = useSelect(
|
|
110
151
|
( select ) => {
|
|
@@ -125,40 +166,58 @@ export default function useBlockDropZone( {
|
|
|
125
166
|
[ targetRootClientId ]
|
|
126
167
|
);
|
|
127
168
|
|
|
128
|
-
const { getBlockListSettings } =
|
|
169
|
+
const { getBlockListSettings, getBlocks, getBlockIndex } =
|
|
170
|
+
useSelect( blockEditorStore );
|
|
129
171
|
const { showInsertionPoint, hideInsertionPoint } =
|
|
130
172
|
useDispatch( blockEditorStore );
|
|
131
173
|
|
|
132
|
-
const onBlockDrop = useOnBlockDrop( targetRootClientId,
|
|
174
|
+
const onBlockDrop = useOnBlockDrop( targetRootClientId, dropTarget.index, {
|
|
175
|
+
operation: dropTarget.operation,
|
|
176
|
+
} );
|
|
133
177
|
const throttled = useThrottle(
|
|
134
|
-
useCallback(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
setTargetBlockIndex( targetIndex === undefined ? 0 : targetIndex );
|
|
146
|
-
|
|
147
|
-
if ( targetIndex !== undefined ) {
|
|
148
|
-
const nextBlock = blockElements[ targetIndex ];
|
|
149
|
-
const previousBlock = blockElements[ targetIndex - 1 ];
|
|
150
|
-
|
|
151
|
-
// Don't show the insertion point when it's near an empty paragraph block.
|
|
152
|
-
if (
|
|
153
|
-
isEmptyParagraph( nextBlock ) ||
|
|
154
|
-
isEmptyParagraph( previousBlock )
|
|
155
|
-
) {
|
|
178
|
+
useCallback(
|
|
179
|
+
( event, ownerDocument ) => {
|
|
180
|
+
const blocks = getBlocks( targetRootClientId );
|
|
181
|
+
|
|
182
|
+
// The block list is empty, don't show the insertion point but still allow dropping.
|
|
183
|
+
if ( blocks.length === 0 ) {
|
|
184
|
+
setDropTarget( {
|
|
185
|
+
index: 0,
|
|
186
|
+
operation: 'insert',
|
|
187
|
+
} );
|
|
156
188
|
return;
|
|
157
189
|
}
|
|
158
190
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
191
|
+
const blocksData = blocks.map( ( block ) => {
|
|
192
|
+
const clientId = block.clientId;
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
isUnmodifiedDefaultBlock:
|
|
196
|
+
getIsUnmodifiedDefaultBlock( block ),
|
|
197
|
+
getBoundingClientRect: () =>
|
|
198
|
+
ownerDocument
|
|
199
|
+
.getElementById( `block-${ clientId }` )
|
|
200
|
+
.getBoundingClientRect(),
|
|
201
|
+
blockIndex: getBlockIndex( clientId ),
|
|
202
|
+
};
|
|
203
|
+
} );
|
|
204
|
+
|
|
205
|
+
const [ targetIndex, operation ] = getDropTargetPosition(
|
|
206
|
+
blocksData,
|
|
207
|
+
{ x: event.clientX, y: event.clientY },
|
|
208
|
+
getBlockListSettings( targetRootClientId )?.orientation
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
setDropTarget( {
|
|
212
|
+
index: targetIndex,
|
|
213
|
+
operation,
|
|
214
|
+
} );
|
|
215
|
+
showInsertionPoint( targetRootClientId, targetIndex, {
|
|
216
|
+
operation,
|
|
217
|
+
} );
|
|
218
|
+
},
|
|
219
|
+
[ targetRootClientId ]
|
|
220
|
+
),
|
|
162
221
|
200
|
|
163
222
|
);
|
|
164
223
|
|
|
@@ -169,17 +228,15 @@ export default function useBlockDropZone( {
|
|
|
169
228
|
// `currentTarget` is only available while the event is being
|
|
170
229
|
// handled, so get it now and pass it to the thottled function.
|
|
171
230
|
// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
|
|
172
|
-
throttled( event, event.currentTarget );
|
|
231
|
+
throttled( event, event.currentTarget.ownerDocument );
|
|
173
232
|
},
|
|
174
233
|
onDragLeave() {
|
|
175
234
|
throttled.cancel();
|
|
176
235
|
hideInsertionPoint();
|
|
177
|
-
setTargetBlockIndex( null );
|
|
178
236
|
},
|
|
179
237
|
onDragEnd() {
|
|
180
238
|
throttled.cancel();
|
|
181
239
|
hideInsertionPoint();
|
|
182
|
-
setTargetBlockIndex( null );
|
|
183
240
|
},
|
|
184
241
|
} );
|
|
185
242
|
}
|