@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,356 +1,396 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import { createElement } from "@wordpress/element";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* External dependencies
|
|
6
5
|
*/
|
|
7
|
-
import {
|
|
6
|
+
import { Pressable, useWindowDimensions, View } from 'react-native';
|
|
8
7
|
/**
|
|
9
8
|
* WordPress dependencies
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
|
-
import {
|
|
11
|
+
import { useCallback, useMemo, useRef, useState } from '@wordpress/element';
|
|
13
12
|
import { GlobalStylesContext, getMergedGlobalStyles, useMobileGlobalStylesColors, alignmentHelpers, useGlobalStyles } from '@wordpress/components';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { useSetting } from '@wordpress/block-editor';
|
|
13
|
+
import { __experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel, getBlockType, getDefaultBlockName, isUnmodifiedBlock, isUnmodifiedDefaultBlock, switchToBlockType } from '@wordpress/blocks';
|
|
14
|
+
import { useDispatch, useSelect, withDispatch, withSelect } from '@wordpress/data';
|
|
15
|
+
import { compose, ifCondition, pure } from '@wordpress/compose';
|
|
18
16
|
/**
|
|
19
17
|
* Internal dependencies
|
|
20
18
|
*/
|
|
21
19
|
|
|
22
|
-
import styles from './block.scss';
|
|
23
20
|
import BlockEdit from '../block-edit';
|
|
21
|
+
import BlockDraggable from '../block-draggable';
|
|
24
22
|
import BlockInvalidWarning from './block-invalid-warning';
|
|
25
23
|
import BlockMobileToolbar from '../block-mobile-toolbar';
|
|
24
|
+
import BlockOutline from './block-outline';
|
|
25
|
+
import styles from './block.scss';
|
|
26
26
|
import { store as blockEditorStore } from '../../store';
|
|
27
|
-
import BlockDraggable from '../block-draggable';
|
|
28
27
|
import { useLayout } from './layout';
|
|
29
|
-
|
|
28
|
+
import useSetting from '../use-setting';
|
|
29
|
+
const emptyArray = []; // Helper function to memoize the wrapperProps since getEditWrapperProps always returns a new reference.
|
|
30
|
+
|
|
31
|
+
const wrapperPropsCache = new WeakMap();
|
|
32
|
+
const emptyObj = {};
|
|
33
|
+
|
|
34
|
+
function getWrapperProps(value, getWrapperPropsFunction) {
|
|
35
|
+
if (!getWrapperPropsFunction) {
|
|
36
|
+
return emptyObj;
|
|
37
|
+
}
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
const cachedValue = wrapperPropsCache.get(value);
|
|
40
|
+
|
|
41
|
+
if (!cachedValue) {
|
|
42
|
+
const wrapperProps = getWrapperPropsFunction(value);
|
|
43
|
+
wrapperPropsCache.set(value, wrapperProps);
|
|
44
|
+
return wrapperProps;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return cachedValue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function BlockWrapper(_ref) {
|
|
32
51
|
let {
|
|
33
|
-
|
|
52
|
+
accessibilityLabel,
|
|
53
|
+
align,
|
|
54
|
+
blockWidth,
|
|
55
|
+
children,
|
|
34
56
|
clientId,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
draggingClientId,
|
|
58
|
+
draggingEnabled,
|
|
59
|
+
isDescendentBlockSelected,
|
|
60
|
+
isParentSelected,
|
|
38
61
|
isSelected,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
62
|
+
isStackedHorizontally,
|
|
63
|
+
isTouchable,
|
|
64
|
+
marginHorizontal,
|
|
65
|
+
marginVertical,
|
|
43
66
|
onDeleteBlock,
|
|
44
|
-
|
|
45
|
-
parentWidth,
|
|
46
|
-
parentBlockAlignment,
|
|
47
|
-
wrapperProps,
|
|
48
|
-
blockWidth,
|
|
49
|
-
baseGlobalStyles
|
|
67
|
+
onFocus
|
|
50
68
|
} = _ref;
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
const {
|
|
70
|
+
width: screenWidth
|
|
71
|
+
} = useWindowDimensions();
|
|
72
|
+
const anchorNodeRef = useRef();
|
|
73
|
+
const {
|
|
74
|
+
isFullWidth
|
|
75
|
+
} = alignmentHelpers;
|
|
76
|
+
const isScreenWidthEqual = blockWidth === screenWidth;
|
|
77
|
+
const isFullWidthToolbar = isFullWidth(align) || isScreenWidthEqual;
|
|
78
|
+
const blockWrapperStyles = {
|
|
79
|
+
flex: 1
|
|
80
|
+
};
|
|
81
|
+
const blockWrapperStyle = [blockWrapperStyles, {
|
|
82
|
+
marginVertical,
|
|
83
|
+
marginHorizontal
|
|
84
|
+
}];
|
|
85
|
+
const accessible = !(isSelected || isDescendentBlockSelected);
|
|
86
|
+
return createElement(Pressable, {
|
|
87
|
+
accessibilityLabel: accessibilityLabel,
|
|
88
|
+
accessibilityRole: "button",
|
|
89
|
+
accessible: accessible,
|
|
90
|
+
disabled: !isTouchable,
|
|
91
|
+
onPress: onFocus,
|
|
92
|
+
style: blockWrapperStyle
|
|
93
|
+
}, createElement(BlockOutline, {
|
|
67
94
|
isSelected: isSelected,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
onReplace: onReplace,
|
|
72
|
-
insertBlocksAfter: insertBlocksAfter,
|
|
73
|
-
mergeBlocks: onMerge // Block level styles.
|
|
74
|
-
,
|
|
75
|
-
wrapperProps: wrapperProps // Inherited styles merged with block level styles.
|
|
76
|
-
,
|
|
77
|
-
style: mergedStyle,
|
|
95
|
+
isParentSelected: isParentSelected,
|
|
96
|
+
screenWidth: screenWidth
|
|
97
|
+
}), createElement(BlockDraggable, {
|
|
78
98
|
clientId: clientId,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
draggingClientId: draggingClientId,
|
|
100
|
+
enabled: draggingEnabled,
|
|
101
|
+
testID: "draggable-trigger-content"
|
|
102
|
+
}, children), createElement(View, {
|
|
103
|
+
style: styles.neutralToolbar,
|
|
104
|
+
ref: anchorNodeRef
|
|
105
|
+
}, isSelected && createElement(BlockMobileToolbar, {
|
|
106
|
+
anchorNodeRef: anchorNodeRef.current,
|
|
82
107
|
blockWidth: blockWidth,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
108
|
+
clientId: clientId,
|
|
109
|
+
draggingClientId: draggingClientId,
|
|
110
|
+
isFullWidth: isFullWidthToolbar,
|
|
111
|
+
isStackedHorizontally: isStackedHorizontally,
|
|
112
|
+
onDelete: onDeleteBlock
|
|
113
|
+
})));
|
|
88
114
|
}
|
|
89
115
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
function BlockListBlock(_ref2) {
|
|
117
|
+
let {
|
|
118
|
+
attributes,
|
|
119
|
+
blockWidth: blockWrapperWidth,
|
|
120
|
+
canRemove,
|
|
121
|
+
clientId,
|
|
122
|
+
contentStyle,
|
|
123
|
+
isLocked,
|
|
124
|
+
isSelected,
|
|
125
|
+
isSelectionEnabled,
|
|
126
|
+
isStackedHorizontally,
|
|
127
|
+
isValid,
|
|
128
|
+
marginHorizontal,
|
|
129
|
+
marginVertical,
|
|
130
|
+
name,
|
|
131
|
+
onDeleteBlock,
|
|
132
|
+
onInsertBlocksAfter,
|
|
133
|
+
onMerge,
|
|
134
|
+
onReplace,
|
|
135
|
+
parentBlockAlignment,
|
|
136
|
+
parentWidth,
|
|
137
|
+
rootClientId,
|
|
138
|
+
setAttributes,
|
|
139
|
+
toggleSelection
|
|
140
|
+
} = _ref2;
|
|
141
|
+
const {
|
|
142
|
+
baseGlobalStyles,
|
|
143
|
+
blockType,
|
|
144
|
+
draggingClientId,
|
|
145
|
+
draggingEnabled,
|
|
146
|
+
firstToSelectId,
|
|
147
|
+
isDescendantOfParentSelected,
|
|
148
|
+
isDescendentBlockSelected,
|
|
149
|
+
isParentSelected,
|
|
150
|
+
order
|
|
151
|
+
} = useSelect(select => {
|
|
152
|
+
var _getSettings;
|
|
101
153
|
|
|
102
|
-
onFocus() {
|
|
103
154
|
const {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
155
|
+
getBlockCount,
|
|
156
|
+
getBlockHierarchyRootClientId,
|
|
157
|
+
getBlockIndex,
|
|
158
|
+
getBlockParents,
|
|
159
|
+
getLowestCommonAncestorWithSelectedBlock,
|
|
160
|
+
getSelectedBlockClientId,
|
|
161
|
+
getSettings,
|
|
162
|
+
hasSelectedInnerBlock
|
|
163
|
+
} = select(blockEditorStore);
|
|
164
|
+
const currentBlockType = getBlockType(name || 'core/missing');
|
|
165
|
+
const blockOrder = getBlockIndex(clientId);
|
|
166
|
+
const descendentBlockSelected = hasSelectedInnerBlock(clientId, true);
|
|
167
|
+
const selectedBlockClientId = getSelectedBlockClientId();
|
|
168
|
+
const parents = getBlockParents(clientId, true);
|
|
169
|
+
const parentSelected = // Set false as a default value to prevent re-render when it's changed from null to false.
|
|
170
|
+
(selectedBlockClientId || false) && selectedBlockClientId === rootClientId;
|
|
171
|
+
const selectedParents = clientId ? parents : [];
|
|
172
|
+
const descendantOfParentSelected = selectedParents.includes(rootClientId);
|
|
173
|
+
const hasInnerBlocks = getBlockCount(clientId) > 0;
|
|
174
|
+
const commonAncestor = getLowestCommonAncestorWithSelectedBlock(clientId);
|
|
175
|
+
const commonAncestorIndex = parents.indexOf(commonAncestor) - 1;
|
|
176
|
+
const firstBlockToSelectId = commonAncestor ? parents[commonAncestorIndex] : parents[parents.length - 1]; // For blocks with inner blocks, we only enable the dragging in the nested
|
|
177
|
+
// blocks if any of them are selected. This way we prevent the long-press
|
|
178
|
+
// gesture from being disabled for elements within the block UI.
|
|
179
|
+
|
|
180
|
+
const isDraggingEnabled = !hasInnerBlocks || isSelected || !descendentBlockSelected; // Dragging nested blocks is not supported yet. For this reason, the block to be dragged
|
|
181
|
+
// will be the top in the hierarchy.
|
|
182
|
+
|
|
183
|
+
const currentDraggingClientId = getBlockHierarchyRootClientId(clientId);
|
|
184
|
+
const globalStylesBaseStyles = (_getSettings = getSettings()) === null || _getSettings === void 0 ? void 0 : _getSettings.__experimentalGlobalStylesBaseStyles;
|
|
185
|
+
return {
|
|
186
|
+
baseGlobalStyles: globalStylesBaseStyles,
|
|
187
|
+
blockType: currentBlockType,
|
|
188
|
+
draggingClientId: currentDraggingClientId,
|
|
189
|
+
draggingEnabled: isDraggingEnabled,
|
|
190
|
+
firstToSelectId: firstBlockToSelectId,
|
|
191
|
+
isDescendantOfParentSelected: descendantOfParentSelected,
|
|
192
|
+
isDescendentBlockSelected: descendentBlockSelected,
|
|
193
|
+
isParentSelected: parentSelected,
|
|
194
|
+
order: blockOrder
|
|
195
|
+
};
|
|
196
|
+
}, [clientId, isSelected, name, rootClientId]);
|
|
197
|
+
const {
|
|
198
|
+
removeBlock,
|
|
199
|
+
selectBlock
|
|
200
|
+
} = useDispatch(blockEditorStore);
|
|
201
|
+
const initialBlockWidth = blockWrapperWidth - 2 * marginHorizontal;
|
|
202
|
+
const [blockWidth, setBlockWidth] = useState(initialBlockWidth);
|
|
203
|
+
const parentLayout = useLayout() || {};
|
|
204
|
+
const defaultColors = useMobileGlobalStylesColors();
|
|
205
|
+
const globalStyle = useGlobalStyles();
|
|
206
|
+
const fontSizes = useSetting('typography.fontSizes') || emptyArray;
|
|
207
|
+
const onRemove = useCallback(() => removeBlock(clientId), [clientId, removeBlock]);
|
|
208
|
+
const onFocus = useCallback(() => {
|
|
209
|
+
const blockId = firstToSelectId !== null && firstToSelectId !== void 0 ? firstToSelectId : clientId;
|
|
108
210
|
|
|
109
211
|
if (!isSelected) {
|
|
110
|
-
|
|
212
|
+
selectBlock(blockId);
|
|
111
213
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
insertBlocksAfter(blocks) {
|
|
115
|
-
this.props.onInsertBlocks(blocks, this.props.order + 1);
|
|
116
|
-
|
|
117
|
-
if (blocks[0]) {
|
|
118
|
-
// Focus on the first block inserted.
|
|
119
|
-
this.props.onSelect(blocks[0].clientId);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
getBlockWidth(_ref3) {
|
|
214
|
+
}, [selectBlock, clientId, firstToSelectId, isSelected]);
|
|
215
|
+
const onLayout = useCallback(_ref3 => {
|
|
124
216
|
let {
|
|
125
217
|
nativeEvent
|
|
126
218
|
} = _ref3;
|
|
127
|
-
const
|
|
128
|
-
layout
|
|
129
|
-
} = nativeEvent;
|
|
130
|
-
const {
|
|
131
|
-
blockWidth
|
|
132
|
-
} = this.state;
|
|
133
|
-
const layoutWidth = Math.floor(layout.width);
|
|
219
|
+
const layoutWidth = Math.floor(nativeEvent.layout.width);
|
|
134
220
|
|
|
135
221
|
if (!blockWidth || !layoutWidth) {
|
|
136
222
|
return;
|
|
137
223
|
}
|
|
138
224
|
|
|
139
225
|
if (blockWidth !== layoutWidth) {
|
|
140
|
-
|
|
141
|
-
blockWidth: layoutWidth
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
getBlockForType() {
|
|
147
|
-
const {
|
|
148
|
-
blockWidth
|
|
149
|
-
} = this.state;
|
|
150
|
-
return createElement(BlockForType, _extends({}, this.props, {
|
|
151
|
-
onBlockFocus: this.onFocus,
|
|
152
|
-
insertBlocksAfter: this.insertBlocksAfter,
|
|
153
|
-
getBlockWidth: this.getBlockWidth,
|
|
154
|
-
blockWidth: blockWidth
|
|
155
|
-
}));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
renderBlockTitle() {
|
|
159
|
-
return createElement(View, {
|
|
160
|
-
style: styles.blockTitle
|
|
161
|
-
}, createElement(Text, null, "BlockType: ", this.props.name));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
render() {
|
|
165
|
-
const {
|
|
166
|
-
attributes,
|
|
167
|
-
blockType,
|
|
168
|
-
clientId,
|
|
169
|
-
icon,
|
|
170
|
-
isSelected,
|
|
171
|
-
isValid,
|
|
172
|
-
order,
|
|
173
|
-
title,
|
|
174
|
-
isDimmed,
|
|
175
|
-
isTouchable,
|
|
176
|
-
onDeleteBlock,
|
|
177
|
-
isStackedHorizontally,
|
|
178
|
-
isParentSelected,
|
|
179
|
-
getStylesFromColorScheme,
|
|
180
|
-
marginVertical,
|
|
181
|
-
marginHorizontal,
|
|
182
|
-
isInnerBlockSelected,
|
|
183
|
-
name,
|
|
184
|
-
draggingEnabled,
|
|
185
|
-
draggingClientId
|
|
186
|
-
} = this.props;
|
|
187
|
-
|
|
188
|
-
if (!attributes || !blockType) {
|
|
189
|
-
return null;
|
|
226
|
+
setBlockWidth(layoutWidth);
|
|
190
227
|
}
|
|
228
|
+
}, [blockWidth, setBlockWidth]); // Block level styles.
|
|
191
229
|
|
|
192
|
-
|
|
193
|
-
blockWidth
|
|
194
|
-
} = this.state;
|
|
195
|
-
const {
|
|
196
|
-
align
|
|
197
|
-
} = attributes;
|
|
198
|
-
const accessibilityLabel = getAccessibleBlockLabel(blockType, attributes, order + 1);
|
|
199
|
-
const {
|
|
200
|
-
isFullWidth,
|
|
201
|
-
isContainerRelated
|
|
202
|
-
} = alignmentHelpers;
|
|
203
|
-
const accessible = !(isSelected || isInnerBlockSelected);
|
|
204
|
-
const screenWidth = Math.floor(Dimensions.get('window').width);
|
|
205
|
-
const isScreenWidthEqual = blockWidth === screenWidth;
|
|
206
|
-
const isScreenWidthWider = blockWidth < screenWidth;
|
|
207
|
-
const isFullWidthToolbar = isFullWidth(align) || isScreenWidthEqual;
|
|
208
|
-
return createElement(TouchableWithoutFeedback, {
|
|
209
|
-
onPress: this.onFocus,
|
|
210
|
-
accessible: accessible,
|
|
211
|
-
accessibilityRole: 'button'
|
|
212
|
-
}, createElement(View, {
|
|
213
|
-
style: {
|
|
214
|
-
flex: 1
|
|
215
|
-
},
|
|
216
|
-
accessibilityLabel: accessibilityLabel
|
|
217
|
-
}, createElement(View, {
|
|
218
|
-
pointerEvents: isTouchable ? 'auto' : 'box-only',
|
|
219
|
-
accessibilityLabel: accessibilityLabel,
|
|
220
|
-
style: [{
|
|
221
|
-
marginVertical,
|
|
222
|
-
marginHorizontal,
|
|
223
|
-
flex: 1
|
|
224
|
-
}, isDimmed && styles.dimmed]
|
|
225
|
-
}, isSelected && createElement(View, {
|
|
226
|
-
pointerEvents: "box-none",
|
|
227
|
-
style: [styles.solidBorder, isFullWidth(align) && isScreenWidthWider && styles.borderFullWidth, isFullWidth(align) && isContainerRelated(name) && isScreenWidthWider && styles.containerBorderFullWidth, getStylesFromColorScheme(styles.solidBorderColor, styles.solidBorderColorDark)]
|
|
228
|
-
}), isParentSelected && createElement(View, {
|
|
229
|
-
style: [styles.dashedBorder, getStylesFromColorScheme(styles.dashedBorderColor, styles.dashedBorderColorDark)]
|
|
230
|
-
}), createElement(BlockDraggable, {
|
|
231
|
-
clientId: clientId,
|
|
232
|
-
draggingClientId: draggingClientId,
|
|
233
|
-
enabled: draggingEnabled,
|
|
234
|
-
testID: "draggable-trigger-content"
|
|
235
|
-
}, () => isValid ? this.getBlockForType() : createElement(BlockInvalidWarning, {
|
|
236
|
-
blockTitle: title,
|
|
237
|
-
icon: icon,
|
|
238
|
-
clientId: clientId
|
|
239
|
-
})), createElement(View, {
|
|
240
|
-
style: styles.neutralToolbar,
|
|
241
|
-
ref: this.anchorNodeRef
|
|
242
|
-
}, isSelected && createElement(BlockMobileToolbar, {
|
|
243
|
-
clientId: clientId,
|
|
244
|
-
onDelete: onDeleteBlock,
|
|
245
|
-
isStackedHorizontally: isStackedHorizontally,
|
|
246
|
-
blockWidth: blockWidth,
|
|
247
|
-
anchorNodeRef: this.anchorNodeRef.current,
|
|
248
|
-
isFullWidth: isFullWidthToolbar,
|
|
249
|
-
draggingClientId: draggingClientId
|
|
250
|
-
})))));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
} // Helper function to memoize the wrapperProps since getEditWrapperProps always returns a new reference.
|
|
254
|
-
|
|
230
|
+
const wrapperProps = getWrapperProps(attributes, blockType.getEditWrapperProps); // Inherited styles merged with block level styles.
|
|
255
231
|
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
232
|
+
const mergedStyle = useMemo(() => {
|
|
233
|
+
return getMergedGlobalStyles(baseGlobalStyles, globalStyle, wrapperProps.style, attributes, defaultColors, name, fontSizes); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
234
|
+
}, [// It is crucial to keep the dependencies array minimal to prevent unnecessary calls that could negatively impact performance.
|
|
235
|
+
// JSON.stringify is used for the following purposes:
|
|
236
|
+
// 1. To create a single, comparable value from the globalStyle, wrapperProps.style, and attributes objects. This allows useMemo to
|
|
237
|
+
// efficiently determine if a change has occurred in any of these objects.
|
|
238
|
+
// 2. To filter the attributes object, ensuring that only the relevant attributes (included in
|
|
239
|
+
// GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES) are considered as dependencies. This reduces the likelihood of
|
|
240
|
+
// unnecessary useMemo calls when other, unrelated attributes change.
|
|
241
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
242
|
+
JSON.stringify(globalStyle), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
243
|
+
JSON.stringify(wrapperProps.style), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
244
|
+
JSON.stringify(Object.fromEntries(Object.entries(attributes !== null && attributes !== void 0 ? attributes : {}).filter(_ref4 => {
|
|
245
|
+
let [key] = _ref4;
|
|
246
|
+
return GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES.includes(key);
|
|
247
|
+
})))]);
|
|
248
|
+
const {
|
|
249
|
+
align
|
|
250
|
+
} = attributes;
|
|
251
|
+
const isFocused = isSelected || isDescendentBlockSelected;
|
|
252
|
+
const isTouchable = isSelected || isDescendantOfParentSelected || isParentSelected || !rootClientId;
|
|
253
|
+
const accessibilityLabel = getAccessibleBlockLabel(blockType, attributes, order + 1);
|
|
254
|
+
return createElement(BlockWrapper, {
|
|
255
|
+
accessibilityLabel: accessibilityLabel,
|
|
256
|
+
align: align,
|
|
257
|
+
blockWidth: blockWidth,
|
|
258
|
+
clientId: clientId,
|
|
259
|
+
draggingClientId: draggingClientId,
|
|
260
|
+
draggingEnabled: draggingEnabled,
|
|
261
|
+
isFocused: isFocused,
|
|
262
|
+
isDescendentBlockSelected: isDescendentBlockSelected,
|
|
263
|
+
isParentSelected: isParentSelected,
|
|
264
|
+
isSelected: isSelected,
|
|
265
|
+
isStackedHorizontally: isStackedHorizontally,
|
|
266
|
+
isTouchable: isTouchable,
|
|
267
|
+
marginHorizontal: marginHorizontal,
|
|
268
|
+
marginVertical: marginVertical,
|
|
269
|
+
onDeleteBlock: onDeleteBlock,
|
|
270
|
+
onFocus: onFocus
|
|
271
|
+
}, () => !isValid ? createElement(BlockInvalidWarning, {
|
|
272
|
+
clientId: clientId
|
|
273
|
+
}) : createElement(GlobalStylesContext.Provider, {
|
|
274
|
+
value: mergedStyle
|
|
275
|
+
}, createElement(BlockEdit, {
|
|
276
|
+
attributes: attributes,
|
|
277
|
+
blockWidth: blockWidth,
|
|
278
|
+
clientId: clientId,
|
|
279
|
+
contentStyle: contentStyle,
|
|
280
|
+
insertBlocksAfter: isLocked ? undefined : onInsertBlocksAfter,
|
|
281
|
+
isSelected: isSelected,
|
|
282
|
+
isSelectionEnabled: isSelectionEnabled,
|
|
283
|
+
mergeBlocks: canRemove ? onMerge : undefined,
|
|
284
|
+
name: name,
|
|
285
|
+
onFocus: onFocus,
|
|
286
|
+
onRemove: canRemove ? onRemove : undefined,
|
|
287
|
+
onReplace: canRemove ? onReplace : undefined,
|
|
288
|
+
parentBlockAlignment: parentBlockAlignment,
|
|
289
|
+
parentWidth: parentWidth,
|
|
290
|
+
setAttributes: setAttributes,
|
|
291
|
+
style: mergedStyle,
|
|
292
|
+
toggleSelection: toggleSelection,
|
|
293
|
+
__unstableParentLayout: Object.keys(parentLayout).length ? parentLayout : undefined,
|
|
294
|
+
wrapperProps: wrapperProps
|
|
295
|
+
}), createElement(View, {
|
|
296
|
+
onLayout: onLayout
|
|
297
|
+
})));
|
|
273
298
|
}
|
|
274
299
|
|
|
275
|
-
|
|
276
|
-
var _getSettings;
|
|
277
|
-
|
|
300
|
+
const applyWithSelect = withSelect((select, _ref5) => {
|
|
278
301
|
let {
|
|
279
|
-
clientId
|
|
280
|
-
|
|
302
|
+
clientId,
|
|
303
|
+
rootClientId
|
|
304
|
+
} = _ref5;
|
|
281
305
|
const {
|
|
282
|
-
getBlockIndex,
|
|
283
|
-
getBlockCount,
|
|
284
|
-
getSettings,
|
|
285
306
|
isBlockSelected,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
307
|
+
getBlockMode,
|
|
308
|
+
isSelectionEnabled,
|
|
309
|
+
getTemplateLock,
|
|
310
|
+
__unstableGetBlockWithoutInnerBlocks,
|
|
311
|
+
canRemoveBlock,
|
|
312
|
+
canMoveBlock
|
|
292
313
|
} = select(blockEditorStore);
|
|
293
|
-
|
|
314
|
+
|
|
315
|
+
const block = __unstableGetBlockWithoutInnerBlocks(clientId);
|
|
316
|
+
|
|
294
317
|
const isSelected = isBlockSelected(clientId);
|
|
295
|
-
const
|
|
296
|
-
const
|
|
318
|
+
const templateLock = getTemplateLock(rootClientId);
|
|
319
|
+
const canRemove = canRemoveBlock(clientId, rootClientId);
|
|
320
|
+
const canMove = canMoveBlock(clientId, rootClientId); // The fallback to `{}` is a temporary fix.
|
|
321
|
+
// This function should never be called when a block is not present in
|
|
322
|
+
// the state. It happens now because the order in withSelect rendering
|
|
323
|
+
// is not correct.
|
|
324
|
+
|
|
297
325
|
const {
|
|
298
326
|
name,
|
|
299
327
|
attributes,
|
|
300
328
|
isValid
|
|
301
|
-
} = block || {};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const icon = blockType === null || blockType === void 0 ? void 0 : blockType.icon;
|
|
305
|
-
const parents = getBlockParents(clientId, true);
|
|
306
|
-
const parentId = parents[0] || '';
|
|
307
|
-
const selectedBlockClientId = getSelectedBlockClientId();
|
|
308
|
-
const commonAncestor = getLowestCommonAncestorWithSelectedBlock(clientId);
|
|
309
|
-
const commonAncestorIndex = parents.indexOf(commonAncestor) - 1;
|
|
310
|
-
const firstToSelectId = commonAncestor ? parents[commonAncestorIndex] : parents[parents.length - 1];
|
|
311
|
-
const isParentSelected = // Set false as a default value to prevent re-render when it's changed from null to false.
|
|
312
|
-
(selectedBlockClientId || false) && selectedBlockClientId === parentId;
|
|
313
|
-
const selectedParents = selectedBlockClientId ? getBlockParents(selectedBlockClientId) : [];
|
|
314
|
-
const isDescendantOfParentSelected = selectedParents.includes(parentId);
|
|
315
|
-
const isTouchable = isSelected || isDescendantOfParentSelected || isParentSelected || parentId === '';
|
|
316
|
-
const baseGlobalStyles = (_getSettings = getSettings()) === null || _getSettings === void 0 ? void 0 : _getSettings.__experimentalGlobalStylesBaseStyles;
|
|
317
|
-
const hasInnerBlocks = getBlockCount(clientId) > 0; // For blocks with inner blocks, we only enable the dragging in the nested
|
|
318
|
-
// blocks if any of them are selected. This way we prevent the long-press
|
|
319
|
-
// gesture from being disabled for elements within the block UI.
|
|
320
|
-
|
|
321
|
-
const draggingEnabled = !hasInnerBlocks || isSelected || !hasSelectedInnerBlock(clientId, true); // Dragging nested blocks is not supported yet. For this reason, the block to be dragged
|
|
322
|
-
// will be the top in the hierarchy.
|
|
323
|
-
|
|
324
|
-
const draggingClientId = getBlockHierarchyRootClientId(clientId);
|
|
329
|
+
} = block || {}; // Do not add new properties here, use `useSelect` instead to avoid
|
|
330
|
+
// leaking new props to the public API (editor.BlockListBlock filter).
|
|
331
|
+
|
|
325
332
|
return {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
333
|
+
mode: getBlockMode(clientId),
|
|
334
|
+
isSelectionEnabled: isSelectionEnabled(),
|
|
335
|
+
isLocked: !!templateLock,
|
|
336
|
+
canRemove,
|
|
337
|
+
canMove,
|
|
338
|
+
// Users of the editor.BlockListBlock filter used to be able to
|
|
339
|
+
// access the block prop.
|
|
340
|
+
// Ideally these blocks would rely on the clientId prop only.
|
|
341
|
+
// This is kept for backward compatibility reasons.
|
|
342
|
+
block,
|
|
343
|
+
name,
|
|
330
344
|
attributes,
|
|
331
|
-
blockType,
|
|
332
|
-
draggingClientId,
|
|
333
|
-
draggingEnabled,
|
|
334
|
-
isSelected,
|
|
335
|
-
isInnerBlockSelected,
|
|
336
345
|
isValid,
|
|
337
|
-
|
|
338
|
-
firstToSelectId,
|
|
339
|
-
isTouchable,
|
|
340
|
-
baseGlobalStyles,
|
|
341
|
-
wrapperProps: getWrapperProps(attributes, blockType.getEditWrapperProps)
|
|
346
|
+
isSelected
|
|
342
347
|
};
|
|
343
|
-
})
|
|
348
|
+
});
|
|
349
|
+
const applyWithDispatch = withDispatch((dispatch, ownProps, registry) => {
|
|
344
350
|
const {
|
|
351
|
+
updateBlockAttributes,
|
|
345
352
|
insertBlocks,
|
|
346
353
|
mergeBlocks,
|
|
347
354
|
replaceBlocks,
|
|
348
|
-
|
|
349
|
-
|
|
355
|
+
toggleSelection,
|
|
356
|
+
__unstableMarkLastChangeAsPersistent,
|
|
350
357
|
moveBlocksToPosition,
|
|
351
358
|
removeBlock
|
|
352
|
-
} = dispatch(blockEditorStore);
|
|
359
|
+
} = dispatch(blockEditorStore); // Do not add new properties here, use `useDispatch` instead to avoid
|
|
360
|
+
// leaking new props to the public API (editor.BlockListBlock filter).
|
|
361
|
+
|
|
353
362
|
return {
|
|
363
|
+
setAttributes(newAttributes) {
|
|
364
|
+
const {
|
|
365
|
+
getMultiSelectedBlockClientIds
|
|
366
|
+
} = registry.select(blockEditorStore);
|
|
367
|
+
const multiSelectedBlockClientIds = getMultiSelectedBlockClientIds();
|
|
368
|
+
const {
|
|
369
|
+
clientId
|
|
370
|
+
} = ownProps;
|
|
371
|
+
const clientIds = multiSelectedBlockClientIds.length ? multiSelectedBlockClientIds : [clientId];
|
|
372
|
+
updateBlockAttributes(clientIds, newAttributes);
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
onInsertBlocks(blocks, index) {
|
|
376
|
+
const {
|
|
377
|
+
rootClientId
|
|
378
|
+
} = ownProps;
|
|
379
|
+
insertBlocks(blocks, index, rootClientId);
|
|
380
|
+
},
|
|
381
|
+
|
|
382
|
+
onInsertBlocksAfter(blocks) {
|
|
383
|
+
const {
|
|
384
|
+
clientId,
|
|
385
|
+
rootClientId
|
|
386
|
+
} = ownProps;
|
|
387
|
+
const {
|
|
388
|
+
getBlockIndex
|
|
389
|
+
} = registry.select(blockEditorStore);
|
|
390
|
+
const index = getBlockIndex(clientId);
|
|
391
|
+
insertBlocks(blocks, index + 1, rootClientId);
|
|
392
|
+
},
|
|
393
|
+
|
|
354
394
|
onMerge(forward) {
|
|
355
395
|
const {
|
|
356
396
|
clientId,
|
|
@@ -471,24 +511,27 @@ export default compose([withSelect((select, _ref4) => {
|
|
|
471
511
|
}
|
|
472
512
|
},
|
|
473
513
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
onSelect() {
|
|
479
|
-
let clientId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ownProps.clientId;
|
|
480
|
-
let initialPosition = arguments.length > 1 ? arguments[1] : undefined;
|
|
481
|
-
selectBlock(clientId, initialPosition);
|
|
482
|
-
},
|
|
514
|
+
onReplace(blocks, indexToSelect, initialPosition) {
|
|
515
|
+
if (blocks.length && !isUnmodifiedDefaultBlock(blocks[blocks.length - 1])) {
|
|
516
|
+
__unstableMarkLastChangeAsPersistent();
|
|
517
|
+
}
|
|
483
518
|
|
|
484
|
-
|
|
485
|
-
updateBlockAttributes(ownProps.clientId, attributes);
|
|
519
|
+
replaceBlocks([ownProps.clientId], blocks, indexToSelect, initialPosition);
|
|
486
520
|
},
|
|
487
521
|
|
|
488
|
-
|
|
489
|
-
|
|
522
|
+
toggleSelection(selectionEnabled) {
|
|
523
|
+
toggleSelection(selectionEnabled);
|
|
490
524
|
}
|
|
491
525
|
|
|
492
526
|
};
|
|
493
|
-
})
|
|
527
|
+
});
|
|
528
|
+
export default compose(pure, applyWithSelect, applyWithDispatch, // Block is sometimes not mounted at the right time, causing it be undefined
|
|
529
|
+
// see issue for more info
|
|
530
|
+
// https://github.com/WordPress/gutenberg/issues/17013
|
|
531
|
+
ifCondition(_ref6 => {
|
|
532
|
+
let {
|
|
533
|
+
block
|
|
534
|
+
} = _ref6;
|
|
535
|
+
return !!block;
|
|
536
|
+
}))(BlockListBlock);
|
|
494
537
|
//# sourceMappingURL=block.native.js.map
|