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