@wordpress/block-editor 12.0.0 → 12.1.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 +4 -0
- package/README.md +1 -1
- package/build/components/block-controls/slot.js +12 -4
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-controls/slot.native.js +10 -1
- package/build/components/block-controls/slot.native.js.map +1 -1
- package/build/components/block-draggable/index.js +11 -7
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-draggable/use-scroll-when-dragging.js +2 -2
- package/build/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
- package/build/components/block-list/block-invalid-warning.native.js +15 -7
- package/build/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build/components/block-list/block-list-item-cell.native.js +15 -2
- package/build/components/block-list/block-list-item-cell.native.js.map +1 -1
- package/build/components/block-list/block-list-item.native.js +158 -195
- package/build/components/block-list/block-list-item.native.js.map +1 -1
- package/build/components/block-list/block-outline.native.js +57 -0
- package/build/components/block-list/block-outline.native.js.map +1 -0
- package/build/components/block-list/block.native.js +343 -299
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +202 -298
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/insertion-point.native.js +4 -2
- package/build/components/block-list/insertion-point.native.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +8 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +15 -4
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +17 -62
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +3 -8
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
- package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build/components/global-styles/advanced-panel.js +86 -0
- package/build/components/global-styles/advanced-panel.js.map +1 -0
- package/build/components/global-styles/color-panel.js +4 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +6 -6
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +1 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +24 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +1 -1
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +27 -4
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +30 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +24 -8
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +5 -0
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/inspector-controls/fill.js +1 -1
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +1 -1
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/slot.js +3 -6
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/inspector-controls/slot.native.js +1 -1
- package/build/components/inspector-controls/slot.native.js.map +1 -1
- package/build/components/line-height-control/index.js +7 -2
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/link-control/use-internal-input-value.js +9 -8
- package/build/components/link-control/use-internal-input-value.js.map +1 -1
- package/build/components/list-view/block-contents.js +7 -2
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block-select-button.js +2 -1
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +4 -4
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/index.js +32 -18
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +163 -11
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-placeholder/index.js +68 -7
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/multi-selection-inspector/index.js +2 -2
- package/build/components/multi-selection-inspector/index.js.map +1 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +3 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build/components/preview-options/index.js +6 -1
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/components/url-input/index.js +1 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/hooks/align.js +1 -1
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/border.js +1 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +1 -1
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/content-lock-ui.js +8 -12
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/duotone.js +1 -1
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.native.js +8 -0
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/layout.js +2 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/position.js +1 -1
- package/build/hooks/position.js.map +1 -1
- package/build/hooks/style.js +1 -1
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/use-editor-wrapper-styles.native.js +255 -0
- package/build/hooks/use-editor-wrapper-styles.native.js.map +1 -0
- package/build/hooks/use-typography-props.js +14 -10
- package/build/hooks/use-typography-props.js.map +1 -1
- package/build/index.native.js +31 -0
- package/build/index.native.js.map +1 -0
- package/build/utils/use-should-contextual-toolbar-show.js +16 -12
- package/build/utils/use-should-contextual-toolbar-show.js.map +1 -1
- package/build-module/components/block-controls/slot.js +11 -4
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-controls/slot.native.js +9 -1
- package/build-module/components/block-controls/slot.native.js.map +1 -1
- package/build-module/components/block-draggable/index.js +10 -6
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-draggable/use-scroll-when-dragging.js +2 -2
- package/build-module/components/block-draggable/use-scroll-when-dragging.js.map +1 -1
- package/build-module/components/block-list/block-invalid-warning.native.js +16 -8
- package/build-module/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build-module/components/block-list/block-list-item-cell.native.js +13 -2
- package/build-module/components/block-list/block-list-item-cell.native.js.map +1 -1
- package/build-module/components/block-list/block-list-item.native.js +160 -190
- package/build-module/components/block-list/block-list-item.native.js.map +1 -1
- package/build-module/components/block-list/block-outline.native.js +44 -0
- package/build-module/components/block-list/block-outline.native.js.map +1 -0
- package/build-module/components/block-list/block.native.js +341 -298
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +203 -293
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/insertion-point.native.js +4 -2
- package/build-module/components/block-list/insertion-point.native.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +8 -9
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +13 -5
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +18 -62
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +3 -7
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +3 -2
- package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
- package/build-module/components/global-styles/advanced-panel.js +74 -0
- package/build-module/components/global-styles/advanced-panel.js.map +1 -0
- package/build-module/components/global-styles/color-panel.js +5 -2
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +6 -6
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +1 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +3 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +1 -1
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +25 -4
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +25 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +24 -8
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +4 -0
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +1 -1
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +1 -1
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +4 -7
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/inspector-controls/slot.native.js +1 -1
- package/build-module/components/inspector-controls/slot.native.js.map +1 -1
- package/build-module/components/line-height-control/index.js +7 -2
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/link-control/use-internal-input-value.js +9 -8
- package/build-module/components/link-control/use-internal-input-value.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +7 -3
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +2 -1
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +4 -4
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/index.js +32 -18
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +160 -11
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +66 -7
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/multi-selection-inspector/index.js +2 -2
- package/build-module/components/multi-selection-inspector/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +3 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build-module/components/preview-options/index.js +7 -2
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/components/url-input/index.js +1 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/hooks/align.js +1 -1
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/border.js +1 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +1 -1
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +8 -11
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/duotone.js +1 -1
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -0
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/layout.js +2 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/position.js +1 -1
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/hooks/style.js +1 -1
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/use-editor-wrapper-styles.native.js +242 -0
- package/build-module/hooks/use-editor-wrapper-styles.native.js.map +1 -0
- package/build-module/hooks/use-typography-props.js +14 -10
- package/build-module/hooks/use-typography-props.js.map +1 -1
- package/build-module/index.native.js +6 -0
- package/build-module/index.native.js.map +1 -0
- package/build-module/utils/use-should-contextual-toolbar-show.js +16 -12
- package/build-module/utils/use-should-contextual-toolbar-show.js.map +1 -1
- package/build-style/content-rtl.css +0 -1
- package/build-style/content.css +0 -1
- package/build-style/style-rtl.css +37 -13
- package/build-style/style.css +37 -13
- package/package.json +31 -31
- package/src/components/block-breadcrumb/style.scss +2 -1
- package/src/components/block-controls/slot.js +8 -4
- package/src/components/block-controls/slot.native.js +6 -1
- package/src/components/block-draggable/index.js +10 -6
- package/src/components/block-draggable/use-scroll-when-dragging.js +8 -2
- package/src/components/block-list/block-invalid-warning.native.js +17 -9
- package/src/components/block-list/block-list-item-cell.native.js +10 -1
- package/src/components/block-list/block-list-item.native.js +180 -208
- package/src/components/block-list/block-outline.native.js +58 -0
- package/src/components/block-list/block.native.js +564 -523
- package/src/components/block-list/content.scss +0 -1
- package/src/components/block-list/index.native.js +229 -298
- package/src/components/block-list/insertion-point.native.js +2 -2
- package/src/components/block-list/test/block-invalid-warning.native.js +48 -0
- package/src/components/block-list/test/index.native.js +205 -0
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +3 -1
- package/src/components/block-pattern-setup/style.scss +1 -4
- package/src/components/block-patterns-list/style.scss +1 -4
- package/src/components/block-settings-menu/block-settings-dropdown.js +10 -17
- package/src/components/block-settings-menu-controls/index.js +24 -4
- package/src/components/block-styles/style.scss +4 -4
- package/src/components/block-tools/block-contextual-toolbar.js +28 -62
- package/src/components/block-tools/selected-block-popover.js +3 -5
- package/src/components/block-tools/style.scss +8 -0
- package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +16 -2
- package/src/components/global-styles/advanced-panel.js +82 -0
- package/src/components/global-styles/color-panel.js +6 -1
- package/src/components/global-styles/dimensions-panel.js +6 -6
- package/src/components/global-styles/hooks.js +1 -5
- package/src/components/global-styles/index.js +6 -1
- package/src/components/global-styles/style.scss +14 -0
- package/src/components/global-styles/test/utils.js +57 -1
- package/src/components/global-styles/typography-panel.js +1 -1
- package/src/components/global-styles/use-global-styles-output.js +21 -3
- package/src/components/global-styles/utils.js +27 -0
- package/src/components/image-editor/use-save-image.js +20 -9
- package/src/components/inserter-draggable-blocks/index.js +4 -0
- package/src/components/inspector-controls/fill.js +1 -1
- package/src/components/inspector-controls/fill.native.js +1 -1
- package/src/components/inspector-controls/slot.js +4 -9
- package/src/components/inspector-controls/slot.native.js +1 -1
- package/src/components/line-height-control/index.js +7 -2
- package/src/components/line-height-control/stories/index.js +1 -1
- package/src/components/link-control/test/index.js +42 -0
- package/src/components/link-control/use-internal-input-value.js +8 -7
- package/src/components/list-view/block-contents.js +26 -20
- package/src/components/list-view/block-select-button.js +5 -1
- package/src/components/list-view/block.js +5 -2
- package/src/components/list-view/index.js +26 -14
- package/src/components/list-view/style.scss +5 -2
- package/src/components/list-view/test/use-list-view-drop-zone.js +88 -12
- package/src/components/list-view/use-list-view-drop-zone.js +194 -11
- package/src/components/media-placeholder/index.js +74 -1
- package/src/components/multi-selection-inspector/index.js +2 -2
- package/src/components/off-canvas-editor/leaf-more-menu.js +2 -1
- package/src/components/preview-options/index.js +9 -2
- package/src/components/spacing-sizes-control/spacing-input-control.js +1 -0
- package/src/components/url-input/index.js +1 -2
- package/src/hooks/align.js +2 -1
- package/src/hooks/border.js +2 -1
- package/src/hooks/color.js +2 -1
- package/src/hooks/content-lock-ui.js +3 -15
- package/src/hooks/duotone.js +1 -0
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/layout.js +4 -2
- package/src/hooks/position.js +2 -1
- package/src/hooks/style.js +2 -1
- package/src/hooks/test/use-editor-wrapper-styles.native.js +282 -0
- package/src/hooks/test/use-typography-props.js +47 -2
- package/src/hooks/use-editor-wrapper-styles.native.js +250 -0
- package/src/hooks/use-editor-wrapper-styles.native.scss +11 -0
- package/src/hooks/use-typography-props.js +10 -11
- package/src/index.native.js +6 -0
- package/src/utils/use-should-contextual-toolbar-show.js +19 -9
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { Pressable, useWindowDimensions, View } from 'react-native';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { useCallback, useMemo, useRef, useState } from '@wordpress/element';
|
|
10
10
|
import {
|
|
11
11
|
GlobalStylesContext,
|
|
12
12
|
getMergedGlobalStyles,
|
|
@@ -14,51 +14,265 @@ import {
|
|
|
14
14
|
alignmentHelpers,
|
|
15
15
|
useGlobalStyles,
|
|
16
16
|
} from '@wordpress/components';
|
|
17
|
-
import { withDispatch, withSelect } from '@wordpress/data';
|
|
18
|
-
import { compose, withPreferredColorScheme } from '@wordpress/compose';
|
|
19
17
|
import {
|
|
20
|
-
getBlockType,
|
|
21
18
|
__experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel,
|
|
22
|
-
|
|
19
|
+
getBlockType,
|
|
23
20
|
getDefaultBlockName,
|
|
24
21
|
isUnmodifiedBlock,
|
|
22
|
+
isUnmodifiedDefaultBlock,
|
|
23
|
+
switchToBlockType,
|
|
25
24
|
} from '@wordpress/blocks';
|
|
26
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
useDispatch,
|
|
27
|
+
useSelect,
|
|
28
|
+
withDispatch,
|
|
29
|
+
withSelect,
|
|
30
|
+
} from '@wordpress/data';
|
|
31
|
+
import { compose, ifCondition, pure } from '@wordpress/compose';
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* Internal dependencies
|
|
30
35
|
*/
|
|
31
|
-
import styles from './block.scss';
|
|
32
36
|
import BlockEdit from '../block-edit';
|
|
37
|
+
import BlockDraggable from '../block-draggable';
|
|
33
38
|
import BlockInvalidWarning from './block-invalid-warning';
|
|
34
39
|
import BlockMobileToolbar from '../block-mobile-toolbar';
|
|
40
|
+
import BlockOutline from './block-outline';
|
|
41
|
+
import styles from './block.scss';
|
|
35
42
|
import { store as blockEditorStore } from '../../store';
|
|
36
|
-
import BlockDraggable from '../block-draggable';
|
|
37
43
|
import { useLayout } from './layout';
|
|
44
|
+
import useSetting from '../use-setting';
|
|
38
45
|
|
|
39
46
|
const emptyArray = [];
|
|
40
|
-
|
|
47
|
+
|
|
48
|
+
// Helper function to memoize the wrapperProps since getEditWrapperProps always returns a new reference.
|
|
49
|
+
const wrapperPropsCache = new WeakMap();
|
|
50
|
+
const emptyObj = {};
|
|
51
|
+
function getWrapperProps( value, getWrapperPropsFunction ) {
|
|
52
|
+
if ( ! getWrapperPropsFunction ) {
|
|
53
|
+
return emptyObj;
|
|
54
|
+
}
|
|
55
|
+
const cachedValue = wrapperPropsCache.get( value );
|
|
56
|
+
if ( ! cachedValue ) {
|
|
57
|
+
const wrapperProps = getWrapperPropsFunction( value );
|
|
58
|
+
wrapperPropsCache.set( value, wrapperProps );
|
|
59
|
+
return wrapperProps;
|
|
60
|
+
}
|
|
61
|
+
return cachedValue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function BlockWrapper( {
|
|
65
|
+
accessibilityLabel,
|
|
66
|
+
align,
|
|
67
|
+
blockWidth,
|
|
68
|
+
children,
|
|
69
|
+
clientId,
|
|
70
|
+
draggingClientId,
|
|
71
|
+
draggingEnabled,
|
|
72
|
+
isDescendentBlockSelected,
|
|
73
|
+
isParentSelected,
|
|
74
|
+
isSelected,
|
|
75
|
+
isStackedHorizontally,
|
|
76
|
+
isTouchable,
|
|
77
|
+
marginHorizontal,
|
|
78
|
+
marginVertical,
|
|
79
|
+
onDeleteBlock,
|
|
80
|
+
onFocus,
|
|
81
|
+
} ) {
|
|
82
|
+
const { width: screenWidth } = useWindowDimensions();
|
|
83
|
+
const anchorNodeRef = useRef();
|
|
84
|
+
const { isFullWidth } = alignmentHelpers;
|
|
85
|
+
const isScreenWidthEqual = blockWidth === screenWidth;
|
|
86
|
+
const isFullWidthToolbar = isFullWidth( align ) || isScreenWidthEqual;
|
|
87
|
+
const blockWrapperStyles = { flex: 1 };
|
|
88
|
+
const blockWrapperStyle = [
|
|
89
|
+
blockWrapperStyles,
|
|
90
|
+
{
|
|
91
|
+
marginVertical,
|
|
92
|
+
marginHorizontal,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
const accessible = ! ( isSelected || isDescendentBlockSelected );
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Pressable
|
|
99
|
+
accessibilityLabel={ accessibilityLabel }
|
|
100
|
+
accessibilityRole="button"
|
|
101
|
+
accessible={ accessible }
|
|
102
|
+
disabled={ ! isTouchable }
|
|
103
|
+
onPress={ onFocus }
|
|
104
|
+
style={ blockWrapperStyle }
|
|
105
|
+
>
|
|
106
|
+
<BlockOutline
|
|
107
|
+
isSelected={ isSelected }
|
|
108
|
+
isParentSelected={ isParentSelected }
|
|
109
|
+
screenWidth={ screenWidth }
|
|
110
|
+
/>
|
|
111
|
+
<BlockDraggable
|
|
112
|
+
clientId={ clientId }
|
|
113
|
+
draggingClientId={ draggingClientId }
|
|
114
|
+
enabled={ draggingEnabled }
|
|
115
|
+
testID="draggable-trigger-content"
|
|
116
|
+
>
|
|
117
|
+
{ children }
|
|
118
|
+
</BlockDraggable>
|
|
119
|
+
<View style={ styles.neutralToolbar } ref={ anchorNodeRef }>
|
|
120
|
+
{ isSelected && (
|
|
121
|
+
<BlockMobileToolbar
|
|
122
|
+
anchorNodeRef={ anchorNodeRef.current }
|
|
123
|
+
blockWidth={ blockWidth }
|
|
124
|
+
clientId={ clientId }
|
|
125
|
+
draggingClientId={ draggingClientId }
|
|
126
|
+
isFullWidth={ isFullWidthToolbar }
|
|
127
|
+
isStackedHorizontally={ isStackedHorizontally }
|
|
128
|
+
onDelete={ onDeleteBlock }
|
|
129
|
+
/>
|
|
130
|
+
) }
|
|
131
|
+
</View>
|
|
132
|
+
</Pressable>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function BlockListBlock( {
|
|
41
137
|
attributes,
|
|
138
|
+
blockWidth: blockWrapperWidth,
|
|
139
|
+
canRemove,
|
|
42
140
|
clientId,
|
|
43
141
|
contentStyle,
|
|
44
|
-
|
|
45
|
-
insertBlocksAfter,
|
|
142
|
+
isLocked,
|
|
46
143
|
isSelected,
|
|
47
|
-
|
|
144
|
+
isSelectionEnabled,
|
|
145
|
+
isStackedHorizontally,
|
|
146
|
+
isValid,
|
|
147
|
+
marginHorizontal,
|
|
148
|
+
marginVertical,
|
|
48
149
|
name,
|
|
49
|
-
onBlockFocus,
|
|
50
|
-
onChange,
|
|
51
150
|
onDeleteBlock,
|
|
151
|
+
onInsertBlocksAfter,
|
|
152
|
+
onMerge,
|
|
52
153
|
onReplace,
|
|
53
|
-
parentWidth,
|
|
54
154
|
parentBlockAlignment,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
155
|
+
parentWidth,
|
|
156
|
+
rootClientId,
|
|
157
|
+
setAttributes,
|
|
158
|
+
toggleSelection,
|
|
58
159
|
} ) {
|
|
160
|
+
const {
|
|
161
|
+
baseGlobalStyles,
|
|
162
|
+
blockType,
|
|
163
|
+
draggingClientId,
|
|
164
|
+
draggingEnabled,
|
|
165
|
+
firstToSelectId,
|
|
166
|
+
isDescendantOfParentSelected,
|
|
167
|
+
isDescendentBlockSelected,
|
|
168
|
+
isParentSelected,
|
|
169
|
+
order,
|
|
170
|
+
} = useSelect(
|
|
171
|
+
( select ) => {
|
|
172
|
+
const {
|
|
173
|
+
getBlockCount,
|
|
174
|
+
getBlockHierarchyRootClientId,
|
|
175
|
+
getBlockIndex,
|
|
176
|
+
getBlockParents,
|
|
177
|
+
getLowestCommonAncestorWithSelectedBlock,
|
|
178
|
+
getSelectedBlockClientId,
|
|
179
|
+
getSettings,
|
|
180
|
+
hasSelectedInnerBlock,
|
|
181
|
+
} = select( blockEditorStore );
|
|
182
|
+
const currentBlockType = getBlockType( name || 'core/missing' );
|
|
183
|
+
const blockOrder = getBlockIndex( clientId );
|
|
184
|
+
const descendentBlockSelected = hasSelectedInnerBlock(
|
|
185
|
+
clientId,
|
|
186
|
+
true
|
|
187
|
+
);
|
|
188
|
+
const selectedBlockClientId = getSelectedBlockClientId();
|
|
189
|
+
|
|
190
|
+
const parents = getBlockParents( clientId, true );
|
|
191
|
+
const parentSelected =
|
|
192
|
+
// Set false as a default value to prevent re-render when it's changed from null to false.
|
|
193
|
+
( selectedBlockClientId || false ) &&
|
|
194
|
+
selectedBlockClientId === rootClientId;
|
|
195
|
+
|
|
196
|
+
const selectedParents = clientId ? parents : [];
|
|
197
|
+
const descendantOfParentSelected =
|
|
198
|
+
selectedParents.includes( rootClientId );
|
|
199
|
+
const hasInnerBlocks = getBlockCount( clientId ) > 0;
|
|
200
|
+
|
|
201
|
+
const commonAncestor =
|
|
202
|
+
getLowestCommonAncestorWithSelectedBlock( clientId );
|
|
203
|
+
const commonAncestorIndex = parents.indexOf( commonAncestor ) - 1;
|
|
204
|
+
const firstBlockToSelectId = commonAncestor
|
|
205
|
+
? parents[ commonAncestorIndex ]
|
|
206
|
+
: parents[ parents.length - 1 ];
|
|
207
|
+
|
|
208
|
+
// For blocks with inner blocks, we only enable the dragging in the nested
|
|
209
|
+
// blocks if any of them are selected. This way we prevent the long-press
|
|
210
|
+
// gesture from being disabled for elements within the block UI.
|
|
211
|
+
const isDraggingEnabled =
|
|
212
|
+
! hasInnerBlocks || isSelected || ! descendentBlockSelected;
|
|
213
|
+
// Dragging nested blocks is not supported yet. For this reason, the block to be dragged
|
|
214
|
+
// will be the top in the hierarchy.
|
|
215
|
+
const currentDraggingClientId =
|
|
216
|
+
getBlockHierarchyRootClientId( clientId );
|
|
217
|
+
|
|
218
|
+
const globalStylesBaseStyles =
|
|
219
|
+
getSettings()?.__experimentalGlobalStylesBaseStyles;
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
baseGlobalStyles: globalStylesBaseStyles,
|
|
223
|
+
blockType: currentBlockType,
|
|
224
|
+
draggingClientId: currentDraggingClientId,
|
|
225
|
+
draggingEnabled: isDraggingEnabled,
|
|
226
|
+
firstToSelectId: firstBlockToSelectId,
|
|
227
|
+
isDescendantOfParentSelected: descendantOfParentSelected,
|
|
228
|
+
isDescendentBlockSelected: descendentBlockSelected,
|
|
229
|
+
isParentSelected: parentSelected,
|
|
230
|
+
order: blockOrder,
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
[ clientId, isSelected, name, rootClientId ]
|
|
234
|
+
);
|
|
235
|
+
const { removeBlock, selectBlock } = useDispatch( blockEditorStore );
|
|
236
|
+
const initialBlockWidth = blockWrapperWidth - 2 * marginHorizontal;
|
|
237
|
+
const [ blockWidth, setBlockWidth ] = useState( initialBlockWidth );
|
|
238
|
+
const parentLayout = useLayout() || {};
|
|
59
239
|
const defaultColors = useMobileGlobalStylesColors();
|
|
60
|
-
const fontSizes = useSetting( 'typography.fontSizes' ) || emptyArray;
|
|
61
240
|
const globalStyle = useGlobalStyles();
|
|
241
|
+
const fontSizes = useSetting( 'typography.fontSizes' ) || emptyArray;
|
|
242
|
+
|
|
243
|
+
const onRemove = useCallback(
|
|
244
|
+
() => removeBlock( clientId ),
|
|
245
|
+
[ clientId, removeBlock ]
|
|
246
|
+
);
|
|
247
|
+
const onFocus = useCallback( () => {
|
|
248
|
+
const blockId = firstToSelectId ?? clientId;
|
|
249
|
+
if ( ! isSelected ) {
|
|
250
|
+
selectBlock( blockId );
|
|
251
|
+
}
|
|
252
|
+
}, [ selectBlock, clientId, firstToSelectId, isSelected ] );
|
|
253
|
+
|
|
254
|
+
const onLayout = useCallback(
|
|
255
|
+
( { nativeEvent } ) => {
|
|
256
|
+
const layoutWidth = Math.floor( nativeEvent.layout.width );
|
|
257
|
+
|
|
258
|
+
if ( ! blockWidth || ! layoutWidth ) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if ( blockWidth !== layoutWidth ) {
|
|
263
|
+
setBlockWidth( layoutWidth );
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
[ blockWidth, setBlockWidth ]
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// Block level styles.
|
|
270
|
+
const wrapperProps = getWrapperProps(
|
|
271
|
+
attributes,
|
|
272
|
+
blockType.getEditWrapperProps
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
// Inherited styles merged with block level styles.
|
|
62
276
|
const mergedStyle = useMemo( () => {
|
|
63
277
|
return getMergedGlobalStyles(
|
|
64
278
|
baseGlobalStyles,
|
|
@@ -69,12 +283,20 @@ function BlockForType( {
|
|
|
69
283
|
name,
|
|
70
284
|
fontSizes
|
|
71
285
|
);
|
|
286
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
287
|
}, [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
//
|
|
288
|
+
// It is crucial to keep the dependencies array minimal to prevent unnecessary calls that could negatively impact performance.
|
|
289
|
+
// JSON.stringify is used for the following purposes:
|
|
290
|
+
// 1. To create a single, comparable value from the globalStyle, wrapperProps.style, and attributes objects. This allows useMemo to
|
|
291
|
+
// efficiently determine if a change has occurred in any of these objects.
|
|
292
|
+
// 2. To filter the attributes object, ensuring that only the relevant attributes (included in
|
|
293
|
+
// GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES) are considered as dependencies. This reduces the likelihood of
|
|
294
|
+
// unnecessary useMemo calls when other, unrelated attributes change.
|
|
295
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
296
|
+
JSON.stringify( globalStyle ),
|
|
297
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
298
|
JSON.stringify( wrapperProps.style ),
|
|
299
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
300
|
JSON.stringify(
|
|
79
301
|
Object.fromEntries(
|
|
80
302
|
Object.entries( attributes ?? {} ).filter( ( [ key ] ) =>
|
|
@@ -84,502 +306,251 @@ function BlockForType( {
|
|
|
84
306
|
),
|
|
85
307
|
] );
|
|
86
308
|
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
mergeBlocks={ onMerge }
|
|
100
|
-
// Block level styles.
|
|
101
|
-
wrapperProps={ wrapperProps }
|
|
102
|
-
// Inherited styles merged with block level styles.
|
|
103
|
-
style={ mergedStyle }
|
|
104
|
-
clientId={ clientId }
|
|
105
|
-
parentWidth={ parentWidth }
|
|
106
|
-
contentStyle={ contentStyle }
|
|
107
|
-
onDeleteBlock={ onDeleteBlock }
|
|
108
|
-
blockWidth={ blockWidth }
|
|
109
|
-
parentBlockAlignment={ parentBlockAlignment }
|
|
110
|
-
__unstableParentLayout={ parentLayout }
|
|
111
|
-
/>
|
|
112
|
-
<View onLayout={ getBlockWidth } />
|
|
113
|
-
</GlobalStylesContext.Provider>
|
|
309
|
+
const { align } = attributes;
|
|
310
|
+
const isFocused = isSelected || isDescendentBlockSelected;
|
|
311
|
+
const isTouchable =
|
|
312
|
+
isSelected ||
|
|
313
|
+
isDescendantOfParentSelected ||
|
|
314
|
+
isParentSelected ||
|
|
315
|
+
! rootClientId;
|
|
316
|
+
|
|
317
|
+
const accessibilityLabel = getAccessibleBlockLabel(
|
|
318
|
+
blockType,
|
|
319
|
+
attributes,
|
|
320
|
+
order + 1
|
|
114
321
|
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
class BlockListBlock extends Component {
|
|
118
|
-
constructor() {
|
|
119
|
-
super( ...arguments );
|
|
120
|
-
|
|
121
|
-
this.insertBlocksAfter = this.insertBlocksAfter.bind( this );
|
|
122
|
-
this.onFocus = this.onFocus.bind( this );
|
|
123
|
-
this.getBlockWidth = this.getBlockWidth.bind( this );
|
|
124
|
-
|
|
125
|
-
this.state = {
|
|
126
|
-
blockWidth: this.props.blockWidth - 2 * this.props.marginHorizontal,
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
this.anchorNodeRef = createRef();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
onFocus() {
|
|
133
|
-
const { firstToSelectId, isSelected, onSelect } = this.props;
|
|
134
|
-
if ( ! isSelected ) {
|
|
135
|
-
onSelect( firstToSelectId );
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
insertBlocksAfter( blocks ) {
|
|
140
|
-
this.props.onInsertBlocks( blocks, this.props.order + 1 );
|
|
141
|
-
|
|
142
|
-
if ( blocks[ 0 ] ) {
|
|
143
|
-
// Focus on the first block inserted.
|
|
144
|
-
this.props.onSelect( blocks[ 0 ].clientId );
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
getBlockWidth( { nativeEvent } ) {
|
|
149
|
-
const { layout } = nativeEvent;
|
|
150
|
-
const { blockWidth } = this.state;
|
|
151
|
-
const layoutWidth = Math.floor( layout.width );
|
|
152
|
-
|
|
153
|
-
if ( ! blockWidth || ! layoutWidth ) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if ( blockWidth !== layoutWidth ) {
|
|
158
|
-
this.setState( { blockWidth: layoutWidth } );
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
getBlockForType() {
|
|
163
|
-
const { blockWidth } = this.state;
|
|
164
|
-
return (
|
|
165
|
-
<BlockForType
|
|
166
|
-
{ ...this.props }
|
|
167
|
-
onBlockFocus={ this.onFocus }
|
|
168
|
-
insertBlocksAfter={ this.insertBlocksAfter }
|
|
169
|
-
getBlockWidth={ this.getBlockWidth }
|
|
170
|
-
blockWidth={ blockWidth }
|
|
171
|
-
/>
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
renderBlockTitle() {
|
|
176
|
-
return (
|
|
177
|
-
<View style={ styles.blockTitle }>
|
|
178
|
-
<Text>BlockType: { this.props.name }</Text>
|
|
179
|
-
</View>
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
322
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const { blockWidth } = this.state;
|
|
211
|
-
const { align } = attributes;
|
|
212
|
-
const accessibilityLabel = getAccessibleBlockLabel(
|
|
213
|
-
blockType,
|
|
214
|
-
attributes,
|
|
215
|
-
order + 1
|
|
216
|
-
);
|
|
217
|
-
const { isFullWidth, isContainerRelated } = alignmentHelpers;
|
|
218
|
-
const accessible = ! ( isSelected || isInnerBlockSelected );
|
|
219
|
-
const screenWidth = Math.floor( Dimensions.get( 'window' ).width );
|
|
220
|
-
const isScreenWidthEqual = blockWidth === screenWidth;
|
|
221
|
-
const isScreenWidthWider = blockWidth < screenWidth;
|
|
222
|
-
const isFullWidthToolbar = isFullWidth( align ) || isScreenWidthEqual;
|
|
223
|
-
|
|
224
|
-
return (
|
|
225
|
-
<TouchableWithoutFeedback
|
|
226
|
-
onPress={ this.onFocus }
|
|
227
|
-
accessible={ accessible }
|
|
228
|
-
accessibilityRole={ 'button' }
|
|
229
|
-
>
|
|
230
|
-
<View
|
|
231
|
-
style={ { flex: 1 } }
|
|
232
|
-
accessibilityLabel={ accessibilityLabel }
|
|
233
|
-
>
|
|
234
|
-
<View
|
|
235
|
-
pointerEvents={ isTouchable ? 'auto' : 'box-only' }
|
|
236
|
-
accessibilityLabel={ accessibilityLabel }
|
|
237
|
-
style={ [
|
|
238
|
-
{ marginVertical, marginHorizontal, flex: 1 },
|
|
239
|
-
isDimmed && styles.dimmed,
|
|
240
|
-
] }
|
|
241
|
-
>
|
|
242
|
-
{ isSelected && (
|
|
243
|
-
<View
|
|
244
|
-
pointerEvents="box-none"
|
|
245
|
-
style={ [
|
|
246
|
-
styles.solidBorder,
|
|
247
|
-
isFullWidth( align ) &&
|
|
248
|
-
isScreenWidthWider &&
|
|
249
|
-
styles.borderFullWidth,
|
|
250
|
-
isFullWidth( align ) &&
|
|
251
|
-
isContainerRelated( name ) &&
|
|
252
|
-
isScreenWidthWider &&
|
|
253
|
-
styles.containerBorderFullWidth,
|
|
254
|
-
getStylesFromColorScheme(
|
|
255
|
-
styles.solidBorderColor,
|
|
256
|
-
styles.solidBorderColorDark
|
|
257
|
-
),
|
|
258
|
-
] }
|
|
259
|
-
/>
|
|
260
|
-
) }
|
|
261
|
-
{ isParentSelected && (
|
|
262
|
-
<View
|
|
263
|
-
style={ [
|
|
264
|
-
styles.dashedBorder,
|
|
265
|
-
getStylesFromColorScheme(
|
|
266
|
-
styles.dashedBorderColor,
|
|
267
|
-
styles.dashedBorderColorDark
|
|
268
|
-
),
|
|
269
|
-
] }
|
|
270
|
-
/>
|
|
271
|
-
) }
|
|
272
|
-
<BlockDraggable
|
|
323
|
+
return (
|
|
324
|
+
<BlockWrapper
|
|
325
|
+
accessibilityLabel={ accessibilityLabel }
|
|
326
|
+
align={ align }
|
|
327
|
+
blockWidth={ blockWidth }
|
|
328
|
+
clientId={ clientId }
|
|
329
|
+
draggingClientId={ draggingClientId }
|
|
330
|
+
draggingEnabled={ draggingEnabled }
|
|
331
|
+
isFocused={ isFocused }
|
|
332
|
+
isDescendentBlockSelected={ isDescendentBlockSelected }
|
|
333
|
+
isParentSelected={ isParentSelected }
|
|
334
|
+
isSelected={ isSelected }
|
|
335
|
+
isStackedHorizontally={ isStackedHorizontally }
|
|
336
|
+
isTouchable={ isTouchable }
|
|
337
|
+
marginHorizontal={ marginHorizontal }
|
|
338
|
+
marginVertical={ marginVertical }
|
|
339
|
+
onDeleteBlock={ onDeleteBlock }
|
|
340
|
+
onFocus={ onFocus }
|
|
341
|
+
>
|
|
342
|
+
{ () =>
|
|
343
|
+
! isValid ? (
|
|
344
|
+
<BlockInvalidWarning clientId={ clientId } />
|
|
345
|
+
) : (
|
|
346
|
+
<GlobalStylesContext.Provider value={ mergedStyle }>
|
|
347
|
+
<BlockEdit
|
|
348
|
+
attributes={ attributes }
|
|
349
|
+
blockWidth={ blockWidth }
|
|
273
350
|
clientId={ clientId }
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
>
|
|
278
|
-
{ () =>
|
|
279
|
-
isValid ? (
|
|
280
|
-
this.getBlockForType()
|
|
281
|
-
) : (
|
|
282
|
-
<BlockInvalidWarning
|
|
283
|
-
blockTitle={ title }
|
|
284
|
-
icon={ icon }
|
|
285
|
-
clientId={ clientId }
|
|
286
|
-
/>
|
|
287
|
-
)
|
|
351
|
+
contentStyle={ contentStyle }
|
|
352
|
+
insertBlocksAfter={
|
|
353
|
+
isLocked ? undefined : onInsertBlocksAfter
|
|
288
354
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
{
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
// Helper function to memoize the wrapperProps since getEditWrapperProps always returns a new reference.
|
|
316
|
-
const wrapperPropsCache = new WeakMap();
|
|
317
|
-
const emptyObj = {};
|
|
318
|
-
function getWrapperProps( value, getWrapperPropsFunction ) {
|
|
319
|
-
if ( ! getWrapperPropsFunction ) {
|
|
320
|
-
return emptyObj;
|
|
321
|
-
}
|
|
322
|
-
const cachedValue = wrapperPropsCache.get( value );
|
|
323
|
-
if ( ! cachedValue ) {
|
|
324
|
-
const wrapperProps = getWrapperPropsFunction( value );
|
|
325
|
-
wrapperPropsCache.set( value, wrapperProps );
|
|
326
|
-
return wrapperProps;
|
|
327
|
-
}
|
|
328
|
-
return cachedValue;
|
|
355
|
+
isSelected={ isSelected }
|
|
356
|
+
isSelectionEnabled={ isSelectionEnabled }
|
|
357
|
+
mergeBlocks={ canRemove ? onMerge : undefined }
|
|
358
|
+
name={ name }
|
|
359
|
+
onFocus={ onFocus }
|
|
360
|
+
onRemove={ canRemove ? onRemove : undefined }
|
|
361
|
+
onReplace={ canRemove ? onReplace : undefined }
|
|
362
|
+
parentBlockAlignment={ parentBlockAlignment }
|
|
363
|
+
parentWidth={ parentWidth }
|
|
364
|
+
setAttributes={ setAttributes }
|
|
365
|
+
style={ mergedStyle }
|
|
366
|
+
toggleSelection={ toggleSelection }
|
|
367
|
+
__unstableParentLayout={
|
|
368
|
+
Object.keys( parentLayout ).length
|
|
369
|
+
? parentLayout
|
|
370
|
+
: undefined
|
|
371
|
+
}
|
|
372
|
+
wrapperProps={ wrapperProps }
|
|
373
|
+
/>
|
|
374
|
+
<View onLayout={ onLayout } />
|
|
375
|
+
</GlobalStylesContext.Provider>
|
|
376
|
+
)
|
|
377
|
+
}
|
|
378
|
+
</BlockWrapper>
|
|
379
|
+
);
|
|
329
380
|
}
|
|
330
381
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
} = registry.select( blockEditorStore );
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Moves the block with clientId up one level. If the block type
|
|
448
|
-
* cannot be inserted at the new location, it will be attempted to
|
|
449
|
-
* convert to the default block type.
|
|
450
|
-
*
|
|
451
|
-
* @param {string} _clientId The block to move.
|
|
452
|
-
* @param {boolean} changeSelection Whether to change the selection
|
|
453
|
-
* to the moved block.
|
|
454
|
-
*/
|
|
455
|
-
function moveFirstItemUp( _clientId, changeSelection = true ) {
|
|
456
|
-
const targetRootClientId =
|
|
457
|
-
getBlockRootClientId( _clientId );
|
|
458
|
-
const blockOrder = getBlockOrder( _clientId );
|
|
459
|
-
const [ firstClientId ] = blockOrder;
|
|
460
|
-
|
|
382
|
+
const applyWithSelect = withSelect( ( select, { clientId, rootClientId } ) => {
|
|
383
|
+
const {
|
|
384
|
+
isBlockSelected,
|
|
385
|
+
getBlockMode,
|
|
386
|
+
isSelectionEnabled,
|
|
387
|
+
getTemplateLock,
|
|
388
|
+
__unstableGetBlockWithoutInnerBlocks,
|
|
389
|
+
canRemoveBlock,
|
|
390
|
+
canMoveBlock,
|
|
391
|
+
} = select( blockEditorStore );
|
|
392
|
+
const block = __unstableGetBlockWithoutInnerBlocks( clientId );
|
|
393
|
+
const isSelected = isBlockSelected( clientId );
|
|
394
|
+
const templateLock = getTemplateLock( rootClientId );
|
|
395
|
+
const canRemove = canRemoveBlock( clientId, rootClientId );
|
|
396
|
+
const canMove = canMoveBlock( clientId, rootClientId );
|
|
397
|
+
|
|
398
|
+
// The fallback to `{}` is a temporary fix.
|
|
399
|
+
// This function should never be called when a block is not present in
|
|
400
|
+
// the state. It happens now because the order in withSelect rendering
|
|
401
|
+
// is not correct.
|
|
402
|
+
const { name, attributes, isValid } = block || {};
|
|
403
|
+
|
|
404
|
+
// Do not add new properties here, use `useSelect` instead to avoid
|
|
405
|
+
// leaking new props to the public API (editor.BlockListBlock filter).
|
|
406
|
+
return {
|
|
407
|
+
mode: getBlockMode( clientId ),
|
|
408
|
+
isSelectionEnabled: isSelectionEnabled(),
|
|
409
|
+
isLocked: !! templateLock,
|
|
410
|
+
canRemove,
|
|
411
|
+
canMove,
|
|
412
|
+
// Users of the editor.BlockListBlock filter used to be able to
|
|
413
|
+
// access the block prop.
|
|
414
|
+
// Ideally these blocks would rely on the clientId prop only.
|
|
415
|
+
// This is kept for backward compatibility reasons.
|
|
416
|
+
block,
|
|
417
|
+
name,
|
|
418
|
+
attributes,
|
|
419
|
+
isValid,
|
|
420
|
+
isSelected,
|
|
421
|
+
};
|
|
422
|
+
} );
|
|
423
|
+
|
|
424
|
+
const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
|
|
425
|
+
const {
|
|
426
|
+
updateBlockAttributes,
|
|
427
|
+
insertBlocks,
|
|
428
|
+
mergeBlocks,
|
|
429
|
+
replaceBlocks,
|
|
430
|
+
toggleSelection,
|
|
431
|
+
__unstableMarkLastChangeAsPersistent,
|
|
432
|
+
moveBlocksToPosition,
|
|
433
|
+
removeBlock,
|
|
434
|
+
} = dispatch( blockEditorStore );
|
|
435
|
+
|
|
436
|
+
// Do not add new properties here, use `useDispatch` instead to avoid
|
|
437
|
+
// leaking new props to the public API (editor.BlockListBlock filter).
|
|
438
|
+
return {
|
|
439
|
+
setAttributes( newAttributes ) {
|
|
440
|
+
const { getMultiSelectedBlockClientIds } =
|
|
441
|
+
registry.select( blockEditorStore );
|
|
442
|
+
const multiSelectedBlockClientIds =
|
|
443
|
+
getMultiSelectedBlockClientIds();
|
|
444
|
+
const { clientId } = ownProps;
|
|
445
|
+
const clientIds = multiSelectedBlockClientIds.length
|
|
446
|
+
? multiSelectedBlockClientIds
|
|
447
|
+
: [ clientId ];
|
|
448
|
+
|
|
449
|
+
updateBlockAttributes( clientIds, newAttributes );
|
|
450
|
+
},
|
|
451
|
+
onInsertBlocks( blocks, index ) {
|
|
452
|
+
const { rootClientId } = ownProps;
|
|
453
|
+
insertBlocks( blocks, index, rootClientId );
|
|
454
|
+
},
|
|
455
|
+
onInsertBlocksAfter( blocks ) {
|
|
456
|
+
const { clientId, rootClientId } = ownProps;
|
|
457
|
+
const { getBlockIndex } = registry.select( blockEditorStore );
|
|
458
|
+
const index = getBlockIndex( clientId );
|
|
459
|
+
insertBlocks( blocks, index + 1, rootClientId );
|
|
460
|
+
},
|
|
461
|
+
onMerge( forward ) {
|
|
462
|
+
const { clientId, rootClientId } = ownProps;
|
|
463
|
+
const {
|
|
464
|
+
getPreviousBlockClientId,
|
|
465
|
+
getNextBlockClientId,
|
|
466
|
+
getBlock,
|
|
467
|
+
getBlockAttributes,
|
|
468
|
+
getBlockName,
|
|
469
|
+
getBlockOrder,
|
|
470
|
+
getBlockIndex,
|
|
471
|
+
getBlockRootClientId,
|
|
472
|
+
canInsertBlockType,
|
|
473
|
+
} = registry.select( blockEditorStore );
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Moves the block with clientId up one level. If the block type
|
|
477
|
+
* cannot be inserted at the new location, it will be attempted to
|
|
478
|
+
* convert to the default block type.
|
|
479
|
+
*
|
|
480
|
+
* @param {string} _clientId The block to move.
|
|
481
|
+
* @param {boolean} changeSelection Whether to change the selection
|
|
482
|
+
* to the moved block.
|
|
483
|
+
*/
|
|
484
|
+
function moveFirstItemUp( _clientId, changeSelection = true ) {
|
|
485
|
+
const targetRootClientId = getBlockRootClientId( _clientId );
|
|
486
|
+
const blockOrder = getBlockOrder( _clientId );
|
|
487
|
+
const [ firstClientId ] = blockOrder;
|
|
488
|
+
|
|
489
|
+
if (
|
|
490
|
+
blockOrder.length === 1 &&
|
|
491
|
+
isUnmodifiedBlock( getBlock( firstClientId ) )
|
|
492
|
+
) {
|
|
493
|
+
removeBlock( _clientId );
|
|
494
|
+
} else {
|
|
461
495
|
if (
|
|
462
|
-
|
|
463
|
-
|
|
496
|
+
canInsertBlockType(
|
|
497
|
+
getBlockName( firstClientId ),
|
|
498
|
+
targetRootClientId
|
|
499
|
+
)
|
|
464
500
|
) {
|
|
465
|
-
|
|
501
|
+
moveBlocksToPosition(
|
|
502
|
+
[ firstClientId ],
|
|
503
|
+
_clientId,
|
|
504
|
+
targetRootClientId,
|
|
505
|
+
getBlockIndex( _clientId )
|
|
506
|
+
);
|
|
466
507
|
} else {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
getDefaultBlockName()
|
|
483
|
-
);
|
|
484
|
-
|
|
485
|
-
if ( replacement && replacement.length ) {
|
|
486
|
-
registry.batch( () => {
|
|
487
|
-
insertBlocks(
|
|
488
|
-
replacement,
|
|
489
|
-
getBlockIndex( _clientId ),
|
|
490
|
-
targetRootClientId,
|
|
491
|
-
changeSelection
|
|
492
|
-
);
|
|
493
|
-
removeBlock( firstClientId, false );
|
|
494
|
-
} );
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
if (
|
|
499
|
-
! getBlockOrder( _clientId ).length &&
|
|
500
|
-
isUnmodifiedBlock( getBlock( _clientId ) )
|
|
501
|
-
) {
|
|
502
|
-
removeBlock( _clientId, false );
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
// For `Delete` or forward merge, we should do the exact same thing
|
|
508
|
-
// as `Backspace`, but from the other block.
|
|
509
|
-
if ( forward ) {
|
|
510
|
-
if ( rootClientId ) {
|
|
511
|
-
const nextRootClientId =
|
|
512
|
-
getNextBlockClientId( rootClientId );
|
|
513
|
-
|
|
514
|
-
if ( nextRootClientId ) {
|
|
515
|
-
// If there is a block that follows with the same parent
|
|
516
|
-
// block name and the same attributes, merge the inner
|
|
517
|
-
// blocks.
|
|
518
|
-
if (
|
|
519
|
-
getBlockName( rootClientId ) ===
|
|
520
|
-
getBlockName( nextRootClientId )
|
|
521
|
-
) {
|
|
522
|
-
const rootAttributes =
|
|
523
|
-
getBlockAttributes( rootClientId );
|
|
524
|
-
const previousRootAttributes =
|
|
525
|
-
getBlockAttributes( nextRootClientId );
|
|
526
|
-
|
|
527
|
-
if (
|
|
528
|
-
Object.keys( rootAttributes ).every(
|
|
529
|
-
( key ) =>
|
|
530
|
-
rootAttributes[ key ] ===
|
|
531
|
-
previousRootAttributes[ key ]
|
|
532
|
-
)
|
|
533
|
-
) {
|
|
534
|
-
registry.batch( () => {
|
|
535
|
-
moveBlocksToPosition(
|
|
536
|
-
getBlockOrder( nextRootClientId ),
|
|
537
|
-
nextRootClientId,
|
|
538
|
-
rootClientId
|
|
539
|
-
);
|
|
540
|
-
removeBlock( nextRootClientId, false );
|
|
541
|
-
} );
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
} else {
|
|
545
|
-
mergeBlocks( rootClientId, nextRootClientId );
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
508
|
+
const replacement = switchToBlockType(
|
|
509
|
+
getBlock( firstClientId ),
|
|
510
|
+
getDefaultBlockName()
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
if ( replacement && replacement.length ) {
|
|
514
|
+
registry.batch( () => {
|
|
515
|
+
insertBlocks(
|
|
516
|
+
replacement,
|
|
517
|
+
getBlockIndex( _clientId ),
|
|
518
|
+
targetRootClientId,
|
|
519
|
+
changeSelection
|
|
520
|
+
);
|
|
521
|
+
removeBlock( firstClientId, false );
|
|
522
|
+
} );
|
|
548
523
|
}
|
|
549
524
|
}
|
|
550
525
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if ( getBlockOrder( nextBlockClientId ).length ) {
|
|
558
|
-
moveFirstItemUp( nextBlockClientId, false );
|
|
559
|
-
} else {
|
|
560
|
-
mergeBlocks( clientId, nextBlockClientId );
|
|
526
|
+
if (
|
|
527
|
+
! getBlockOrder( _clientId ).length &&
|
|
528
|
+
isUnmodifiedBlock( getBlock( _clientId ) )
|
|
529
|
+
) {
|
|
530
|
+
removeBlock( _clientId, false );
|
|
561
531
|
}
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
//
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// For `Delete` or forward merge, we should do the exact same thing
|
|
536
|
+
// as `Backspace`, but from the other block.
|
|
537
|
+
if ( forward ) {
|
|
538
|
+
if ( rootClientId ) {
|
|
539
|
+
const nextRootClientId =
|
|
540
|
+
getNextBlockClientId( rootClientId );
|
|
541
|
+
|
|
542
|
+
if ( nextRootClientId ) {
|
|
543
|
+
// If there is a block that follows with the same parent
|
|
544
|
+
// block name and the same attributes, merge the inner
|
|
545
|
+
// blocks.
|
|
574
546
|
if (
|
|
575
|
-
previousRootClientId &&
|
|
576
547
|
getBlockName( rootClientId ) ===
|
|
577
|
-
|
|
548
|
+
getBlockName( nextRootClientId )
|
|
578
549
|
) {
|
|
579
550
|
const rootAttributes =
|
|
580
551
|
getBlockAttributes( rootClientId );
|
|
581
552
|
const previousRootAttributes =
|
|
582
|
-
getBlockAttributes(
|
|
553
|
+
getBlockAttributes( nextRootClientId );
|
|
583
554
|
|
|
584
555
|
if (
|
|
585
556
|
Object.keys( rootAttributes ).every(
|
|
@@ -590,33 +561,103 @@ export default compose( [
|
|
|
590
561
|
) {
|
|
591
562
|
registry.batch( () => {
|
|
592
563
|
moveBlocksToPosition(
|
|
593
|
-
getBlockOrder(
|
|
594
|
-
|
|
595
|
-
|
|
564
|
+
getBlockOrder( nextRootClientId ),
|
|
565
|
+
nextRootClientId,
|
|
566
|
+
rootClientId
|
|
596
567
|
);
|
|
597
|
-
removeBlock(
|
|
568
|
+
removeBlock( nextRootClientId, false );
|
|
598
569
|
} );
|
|
599
570
|
return;
|
|
600
571
|
}
|
|
572
|
+
} else {
|
|
573
|
+
mergeBlocks( rootClientId, nextRootClientId );
|
|
574
|
+
return;
|
|
601
575
|
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const nextBlockClientId = getNextBlockClientId( clientId );
|
|
580
|
+
|
|
581
|
+
if ( ! nextBlockClientId ) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if ( getBlockOrder( nextBlockClientId ).length ) {
|
|
586
|
+
moveFirstItemUp( nextBlockClientId, false );
|
|
587
|
+
} else {
|
|
588
|
+
mergeBlocks( clientId, nextBlockClientId );
|
|
589
|
+
}
|
|
590
|
+
} else {
|
|
591
|
+
const previousBlockClientId =
|
|
592
|
+
getPreviousBlockClientId( clientId );
|
|
593
|
+
|
|
594
|
+
if ( previousBlockClientId ) {
|
|
595
|
+
mergeBlocks( previousBlockClientId, clientId );
|
|
596
|
+
} else if ( rootClientId ) {
|
|
597
|
+
const previousRootClientId =
|
|
598
|
+
getPreviousBlockClientId( rootClientId );
|
|
599
|
+
|
|
600
|
+
// If there is a preceding block with the same parent block
|
|
601
|
+
// name and the same attributes, merge the inner blocks.
|
|
602
|
+
if (
|
|
603
|
+
previousRootClientId &&
|
|
604
|
+
getBlockName( rootClientId ) ===
|
|
605
|
+
getBlockName( previousRootClientId )
|
|
606
|
+
) {
|
|
607
|
+
const rootAttributes =
|
|
608
|
+
getBlockAttributes( rootClientId );
|
|
609
|
+
const previousRootAttributes =
|
|
610
|
+
getBlockAttributes( previousRootClientId );
|
|
602
611
|
|
|
603
|
-
|
|
612
|
+
if (
|
|
613
|
+
Object.keys( rootAttributes ).every(
|
|
614
|
+
( key ) =>
|
|
615
|
+
rootAttributes[ key ] ===
|
|
616
|
+
previousRootAttributes[ key ]
|
|
617
|
+
)
|
|
618
|
+
) {
|
|
619
|
+
registry.batch( () => {
|
|
620
|
+
moveBlocksToPosition(
|
|
621
|
+
getBlockOrder( rootClientId ),
|
|
622
|
+
rootClientId,
|
|
623
|
+
previousRootClientId
|
|
624
|
+
);
|
|
625
|
+
removeBlock( rootClientId, false );
|
|
626
|
+
} );
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
604
629
|
}
|
|
630
|
+
|
|
631
|
+
moveFirstItemUp( rootClientId );
|
|
605
632
|
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
onReplace( blocks, indexToSelect, initialPosition ) {
|
|
636
|
+
if (
|
|
637
|
+
blocks.length &&
|
|
638
|
+
! isUnmodifiedDefaultBlock( blocks[ blocks.length - 1 ] )
|
|
639
|
+
) {
|
|
640
|
+
__unstableMarkLastChangeAsPersistent();
|
|
641
|
+
}
|
|
642
|
+
replaceBlocks(
|
|
643
|
+
[ ownProps.clientId ],
|
|
644
|
+
blocks,
|
|
645
|
+
indexToSelect,
|
|
646
|
+
initialPosition
|
|
647
|
+
);
|
|
648
|
+
},
|
|
649
|
+
toggleSelection( selectionEnabled ) {
|
|
650
|
+
toggleSelection( selectionEnabled );
|
|
651
|
+
},
|
|
652
|
+
};
|
|
653
|
+
} );
|
|
654
|
+
|
|
655
|
+
export default compose(
|
|
656
|
+
pure,
|
|
657
|
+
applyWithSelect,
|
|
658
|
+
applyWithDispatch,
|
|
659
|
+
// Block is sometimes not mounted at the right time, causing it be undefined
|
|
660
|
+
// see issue for more info
|
|
661
|
+
// https://github.com/WordPress/gutenberg/issues/17013
|
|
662
|
+
ifCondition( ( { block } ) => !! block )
|
|
663
|
+
)( BlockListBlock );
|