@wordpress/block-editor 11.4.0 → 11.5.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 +6 -0
- package/build/components/block-inspector/index.js +11 -10
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js +46 -0
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build/components/block-lock/modal.js +1 -0
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +2 -1
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/child-layout-control/index.js +107 -0
- package/build/components/child-layout-control/index.js.map +1 -0
- package/build/components/date-format-picker/index.js +3 -3
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +594 -0
- package/build/components/global-styles/dimensions-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +72 -36
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +20 -6
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +25 -12
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +1 -1
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/index.native.js +23 -0
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +10 -11
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/media-tab/media-list.js +5 -108
- package/build/components/inserter/media-tab/media-list.js.map +1 -1
- package/build/components/inserter/media-tab/media-preview.js +242 -0
- package/build/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/inspector-controls/fill.js +38 -9
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +1 -1
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/link-control/settings.js +1 -0
- package/build/components/link-control/settings.js.map +1 -1
- package/build/components/list-view/block.js +17 -3
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +2 -2
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/expander.js +2 -1
- package/build/components/list-view/expander.js.map +1 -1
- package/build/components/list-view/leaf.js +10 -6
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-scroll-into-view.js +51 -0
- package/build/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build/components/off-canvas-editor/appender.js +5 -10
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/branch.js +1 -0
- package/build/components/off-canvas-editor/branch.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +7 -3
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +34 -4
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build/components/off-canvas-editor/link-ui.js +1 -0
- package/build/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build/components/responsive-block-control/index.js +1 -0
- package/build/components/responsive-block-control/index.js.map +1 -1
- package/build/components/rich-text/index.js +9 -43
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-delete.js +73 -0
- package/build/components/rich-text/use-delete.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +14 -6
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +4 -1
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/hooks/align.js +3 -1
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/dimensions.js +72 -190
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +94 -25
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/gap.js +0 -202
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/layout.js +14 -5
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/margin.js +7 -163
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +7 -163
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/typography.js +50 -65
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +75 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/flex.js +1 -0
- package/build/layouts/flex.js.map +1 -1
- package/build/store/actions.js +24 -12
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +28 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +53 -47
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +5 -1
- package/build/store/selectors.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +36 -3
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-inspector/index.js +9 -9
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js +37 -0
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build-module/components/block-lock/modal.js +1 -0
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +2 -1
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/child-layout-control/index.js +98 -0
- package/build-module/components/child-layout-control/index.js.map +1 -0
- package/build-module/components/date-format-picker/index.js +4 -4
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +574 -0
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +71 -33
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +2 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +26 -11
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/index.native.js +2 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +10 -11
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-list.js +6 -105
- package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-preview.js +222 -0
- package/build-module/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build-module/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +39 -9
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +1 -1
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/link-control/settings.js +1 -0
- package/build-module/components/link-control/settings.js.map +1 -1
- package/build-module/components/list-view/block.js +16 -3
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +2 -2
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/expander.js +2 -1
- package/build-module/components/list-view/expander.js.map +1 -1
- package/build-module/components/list-view/leaf.js +8 -4
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-scroll-into-view.js +42 -0
- package/build-module/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build-module/components/off-canvas-editor/appender.js +5 -10
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/branch.js +1 -0
- package/build-module/components/off-canvas-editor/branch.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +7 -3
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +36 -7
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build-module/components/off-canvas-editor/link-ui.js +1 -0
- package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build-module/components/responsive-block-control/index.js +1 -0
- package/build-module/components/responsive-block-control/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +9 -43
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-delete.js +62 -0
- package/build-module/components/rich-text/use-delete.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +14 -6
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +4 -1
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/hooks/align.js +3 -1
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/dimensions.js +75 -187
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +86 -24
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/gap.js +0 -183
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/layout.js +14 -5
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/margin.js +4 -143
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +4 -143
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/typography.js +52 -65
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +70 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/flex.js +1 -0
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/store/actions.js +24 -12
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +28 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +53 -45
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +5 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +36 -3
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +33 -21
- package/build-style/style.css +33 -21
- package/package.json +31 -31
- package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +24 -24
- package/src/components/block-inspector/index.js +11 -14
- package/src/components/block-inspector/useBlockInspectorAnimationSettings.js +53 -0
- package/src/components/block-lock/modal.js +1 -0
- package/src/components/block-lock/style.scss +0 -9
- package/src/components/block-mobile-toolbar/test/__snapshots__/block-actions-menu.native.js.snap +20 -20
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +15 -15
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/components/block-styles/index.js +5 -1
- package/src/components/child-layout-control/index.js +106 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/date-format-picker/index.js +6 -8
- package/src/components/date-format-picker/style.scss +0 -5
- package/src/components/global-styles/dimensions-panel.js +627 -0
- package/src/components/global-styles/hooks.js +88 -45
- package/src/components/global-styles/index.js +5 -1
- package/src/components/global-styles/typography-panel.js +33 -8
- package/src/components/global-styles/use-global-styles-output.js +4 -3
- package/src/components/global-styles/utils.js +2 -0
- package/src/components/index.native.js +5 -0
- package/src/components/inner-blocks/test/__snapshots__/index.js.snap +1 -1
- package/src/components/inserter/media-tab/hooks.js +9 -8
- package/src/components/inserter/media-tab/media-list.js +3 -122
- package/src/components/inserter/media-tab/media-preview.js +268 -0
- package/src/components/inserter/style.scss +22 -0
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +15 -15
- package/src/components/inspector-controls/block-support-tools-panel.js +0 -1
- package/src/components/inspector-controls/fill.js +32 -8
- package/src/components/link-control/settings-drawer.js +2 -1
- package/src/components/link-control/settings.js +1 -0
- package/src/components/link-control/style.scss +18 -8
- package/src/components/link-control/test/index.js +3 -3
- package/src/components/list-view/block.js +19 -1
- package/src/components/list-view/branch.js +1 -2
- package/src/components/list-view/expander.js +1 -0
- package/src/components/list-view/leaf.js +43 -29
- package/src/components/list-view/use-list-view-scroll-into-view.js +48 -0
- package/src/components/media-replace-flow/style.scss +7 -9
- package/src/components/off-canvas-editor/appender.js +13 -16
- package/src/components/off-canvas-editor/branch.js +1 -0
- package/src/components/off-canvas-editor/index.js +8 -2
- package/src/components/off-canvas-editor/leaf-more-menu.js +57 -15
- package/src/components/off-canvas-editor/link-ui.js +1 -0
- package/src/components/responsive-block-control/index.js +1 -0
- package/src/components/rich-text/index.js +8 -44
- package/src/components/rich-text/use-delete.js +59 -0
- package/src/components/rich-text/use-input-rules.js +13 -5
- package/src/components/spacing-sizes-control/style.scss +1 -1
- package/src/components/url-popover/stories/index.js +1 -0
- package/src/components/writing-flow/use-selection-observer.js +5 -1
- package/src/hooks/align.js +1 -1
- package/src/hooks/dimensions.js +85 -269
- package/src/hooks/duotone.js +100 -30
- package/src/hooks/gap.js +0 -208
- package/src/hooks/layout.js +19 -6
- package/src/hooks/margin.js +1 -164
- package/src/hooks/padding.js +1 -163
- package/src/hooks/test/__snapshots__/align.native.js.snap +24 -24
- package/src/hooks/test/duotone.js +102 -0
- package/src/hooks/typography.js +66 -88
- package/src/hooks/utils.js +90 -0
- package/src/layouts/flex.js +1 -0
- package/src/store/actions.js +12 -4
- package/src/store/defaults.js +14 -1
- package/src/store/reducer.js +68 -43
- package/src/store/selectors.js +8 -1
- package/src/store/test/actions.js +4 -2
- package/src/utils/parse-css-unit-to-px.js +35 -5
- package/src/utils/test/parse-css-unit-to-px.js +12 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/hooks/child-layout.js +0 -213
- package/build/hooks/child-layout.js.map +0 -1
- package/build/hooks/min-height.js +0 -139
- package/build/hooks/min-height.js.map +0 -1
- package/build-module/hooks/child-layout.js +0 -193
- package/build-module/hooks/child-layout.js.map +0 -1
- package/build-module/hooks/min-height.js +0 -116
- package/build-module/hooks/min-height.js.map +0 -1
- package/src/hooks/child-layout.js +0 -195
- package/src/hooks/min-height.js +0 -104
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
__unstableCompositeItem as CompositeItem,
|
|
11
|
+
Tooltip,
|
|
12
|
+
DropdownMenu,
|
|
13
|
+
MenuGroup,
|
|
14
|
+
MenuItem,
|
|
15
|
+
Spinner,
|
|
16
|
+
Modal,
|
|
17
|
+
Flex,
|
|
18
|
+
FlexItem,
|
|
19
|
+
Button,
|
|
20
|
+
__experimentalVStack as VStack,
|
|
21
|
+
} from '@wordpress/components';
|
|
22
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
23
|
+
import { useMemo, useCallback, useState } from '@wordpress/element';
|
|
24
|
+
import { cloneBlock } from '@wordpress/blocks';
|
|
25
|
+
import { moreVertical, external } from '@wordpress/icons';
|
|
26
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
27
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
28
|
+
import { isBlobURL } from '@wordpress/blob';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Internal dependencies
|
|
32
|
+
*/
|
|
33
|
+
import InserterDraggableBlocks from '../../inserter-draggable-blocks';
|
|
34
|
+
import { getBlockAndPreviewFromMedia } from './utils';
|
|
35
|
+
import { store as blockEditorStore } from '../../../store';
|
|
36
|
+
|
|
37
|
+
const ALLOWED_MEDIA_TYPES = [ 'image' ];
|
|
38
|
+
const MAXIMUM_TITLE_LENGTH = 25;
|
|
39
|
+
const MEDIA_OPTIONS_POPOVER_PROPS = {
|
|
40
|
+
position: 'bottom left',
|
|
41
|
+
className:
|
|
42
|
+
'block-editor-inserter__media-list__item-preview-options__popover',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function MediaPreviewOptions( { category, media } ) {
|
|
46
|
+
if ( ! category.getReportUrl ) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const reportUrl = category.getReportUrl( media );
|
|
50
|
+
return (
|
|
51
|
+
<DropdownMenu
|
|
52
|
+
className="block-editor-inserter__media-list__item-preview-options"
|
|
53
|
+
label={ __( 'Options' ) }
|
|
54
|
+
popoverProps={ MEDIA_OPTIONS_POPOVER_PROPS }
|
|
55
|
+
icon={ moreVertical }
|
|
56
|
+
>
|
|
57
|
+
{ () => (
|
|
58
|
+
<MenuGroup>
|
|
59
|
+
<MenuItem
|
|
60
|
+
onClick={ () =>
|
|
61
|
+
window.open( reportUrl, '_blank' ).focus()
|
|
62
|
+
}
|
|
63
|
+
icon={ external }
|
|
64
|
+
>
|
|
65
|
+
{ sprintf(
|
|
66
|
+
/* translators: %s: The media type to report e.g: "image", "video", "audio" */
|
|
67
|
+
__( 'Report %s' ),
|
|
68
|
+
category.mediaType
|
|
69
|
+
) }
|
|
70
|
+
</MenuItem>
|
|
71
|
+
</MenuGroup>
|
|
72
|
+
) }
|
|
73
|
+
</DropdownMenu>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function InsertExternalImageModal( { onClose, onSubmit } ) {
|
|
78
|
+
return (
|
|
79
|
+
<Modal
|
|
80
|
+
title={ __( 'Insert external image' ) }
|
|
81
|
+
onRequestClose={ onClose }
|
|
82
|
+
className="block-editor-inserter-media-tab-media-preview-inserter-external-image-modal"
|
|
83
|
+
>
|
|
84
|
+
<VStack spacing={ 3 }>
|
|
85
|
+
<p>
|
|
86
|
+
{ __(
|
|
87
|
+
'This image cannot be uploaded to your Media Library, but it can still be inserted as an external image.'
|
|
88
|
+
) }
|
|
89
|
+
</p>
|
|
90
|
+
<p>
|
|
91
|
+
{ __(
|
|
92
|
+
'External images can be removed by the external provider without warning and could even have legal compliance issues related to privacy legislation.'
|
|
93
|
+
) }
|
|
94
|
+
</p>
|
|
95
|
+
</VStack>
|
|
96
|
+
<Flex
|
|
97
|
+
className="block-editor-block-lock-modal__actions"
|
|
98
|
+
justify="flex-end"
|
|
99
|
+
expanded={ false }
|
|
100
|
+
>
|
|
101
|
+
<FlexItem>
|
|
102
|
+
<Button variant="tertiary" onClick={ onClose }>
|
|
103
|
+
{ __( 'Cancel' ) }
|
|
104
|
+
</Button>
|
|
105
|
+
</FlexItem>
|
|
106
|
+
<FlexItem>
|
|
107
|
+
<Button variant="primary" onClick={ onSubmit }>
|
|
108
|
+
{ __( 'Insert' ) }
|
|
109
|
+
</Button>
|
|
110
|
+
</FlexItem>
|
|
111
|
+
</Flex>
|
|
112
|
+
</Modal>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function MediaPreview( { media, onClick, composite, category } ) {
|
|
117
|
+
const [ showExternalUploadModal, setShowExternalUploadModal ] =
|
|
118
|
+
useState( false );
|
|
119
|
+
const [ isHovered, setIsHovered ] = useState( false );
|
|
120
|
+
const [ isInserting, setIsInserting ] = useState( false );
|
|
121
|
+
const [ block, preview ] = useMemo(
|
|
122
|
+
() => getBlockAndPreviewFromMedia( media, category.mediaType ),
|
|
123
|
+
[ media, category.mediaType ]
|
|
124
|
+
);
|
|
125
|
+
const { createErrorNotice, createSuccessNotice } =
|
|
126
|
+
useDispatch( noticesStore );
|
|
127
|
+
const mediaUpload = useSelect(
|
|
128
|
+
( select ) => select( blockEditorStore ).getSettings().mediaUpload,
|
|
129
|
+
[]
|
|
130
|
+
);
|
|
131
|
+
const onMediaInsert = useCallback(
|
|
132
|
+
( previewBlock ) => {
|
|
133
|
+
// Prevent multiple uploads when we're in the process of inserting.
|
|
134
|
+
if ( isInserting ) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const clonedBlock = cloneBlock( previewBlock );
|
|
138
|
+
const { id, url, caption } = clonedBlock.attributes;
|
|
139
|
+
// Media item already exists in library, so just insert it.
|
|
140
|
+
if ( !! id ) {
|
|
141
|
+
onClick( clonedBlock );
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
setIsInserting( true );
|
|
145
|
+
// Media item does not exist in library, so try to upload it.
|
|
146
|
+
// Fist fetch the image data. This may fail if the image host
|
|
147
|
+
// doesn't allow CORS with the domain.
|
|
148
|
+
// If this happens, we insert the image block using the external
|
|
149
|
+
// URL and let the user know about the possible implications.
|
|
150
|
+
window
|
|
151
|
+
.fetch( url )
|
|
152
|
+
.then( ( response ) => response.blob() )
|
|
153
|
+
.then( ( blob ) => {
|
|
154
|
+
mediaUpload( {
|
|
155
|
+
filesList: [ blob ],
|
|
156
|
+
additionalData: { caption },
|
|
157
|
+
onFileChange( [ img ] ) {
|
|
158
|
+
if ( isBlobURL( img.url ) ) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
onClick( {
|
|
162
|
+
...clonedBlock,
|
|
163
|
+
attributes: {
|
|
164
|
+
...clonedBlock.attributes,
|
|
165
|
+
id: img.id,
|
|
166
|
+
url: img.url,
|
|
167
|
+
},
|
|
168
|
+
} );
|
|
169
|
+
createSuccessNotice(
|
|
170
|
+
__( 'Image uploaded and inserted.' ),
|
|
171
|
+
{ type: 'snackbar' }
|
|
172
|
+
);
|
|
173
|
+
setIsInserting( false );
|
|
174
|
+
},
|
|
175
|
+
allowedTypes: ALLOWED_MEDIA_TYPES,
|
|
176
|
+
onError( message ) {
|
|
177
|
+
createErrorNotice( message, { type: 'snackbar' } );
|
|
178
|
+
setIsInserting( false );
|
|
179
|
+
},
|
|
180
|
+
} );
|
|
181
|
+
} )
|
|
182
|
+
.catch( () => {
|
|
183
|
+
setShowExternalUploadModal( true );
|
|
184
|
+
setIsInserting( false );
|
|
185
|
+
} );
|
|
186
|
+
},
|
|
187
|
+
[
|
|
188
|
+
isInserting,
|
|
189
|
+
onClick,
|
|
190
|
+
mediaUpload,
|
|
191
|
+
createErrorNotice,
|
|
192
|
+
createSuccessNotice,
|
|
193
|
+
]
|
|
194
|
+
);
|
|
195
|
+
const title = media.title?.rendered || media.title;
|
|
196
|
+
let truncatedTitle;
|
|
197
|
+
if ( title.length > MAXIMUM_TITLE_LENGTH ) {
|
|
198
|
+
const omission = '...';
|
|
199
|
+
truncatedTitle =
|
|
200
|
+
title.slice( 0, MAXIMUM_TITLE_LENGTH - omission.length ) + omission;
|
|
201
|
+
}
|
|
202
|
+
const onMouseEnter = useCallback( () => setIsHovered( true ), [] );
|
|
203
|
+
const onMouseLeave = useCallback( () => setIsHovered( false ), [] );
|
|
204
|
+
return (
|
|
205
|
+
<>
|
|
206
|
+
<InserterDraggableBlocks isEnabled={ true } blocks={ [ block ] }>
|
|
207
|
+
{ ( { draggable, onDragStart, onDragEnd } ) => (
|
|
208
|
+
<div
|
|
209
|
+
className={ classnames(
|
|
210
|
+
'block-editor-inserter__media-list__list-item',
|
|
211
|
+
{
|
|
212
|
+
'is-hovered': isHovered,
|
|
213
|
+
}
|
|
214
|
+
) }
|
|
215
|
+
draggable={ draggable }
|
|
216
|
+
onDragStart={ onDragStart }
|
|
217
|
+
onDragEnd={ onDragEnd }
|
|
218
|
+
>
|
|
219
|
+
<Tooltip text={ truncatedTitle || title }>
|
|
220
|
+
{ /* Adding `is-hovered` class to the wrapper element is needed
|
|
221
|
+
because the options Popover is rendered outside of this node. */ }
|
|
222
|
+
<div
|
|
223
|
+
onMouseEnter={ onMouseEnter }
|
|
224
|
+
onMouseLeave={ onMouseLeave }
|
|
225
|
+
>
|
|
226
|
+
<CompositeItem
|
|
227
|
+
role="option"
|
|
228
|
+
as="div"
|
|
229
|
+
{ ...composite }
|
|
230
|
+
className="block-editor-inserter__media-list__item"
|
|
231
|
+
onClick={ () => onMediaInsert( block ) }
|
|
232
|
+
aria-label={ title }
|
|
233
|
+
>
|
|
234
|
+
<div className="block-editor-inserter__media-list__item-preview">
|
|
235
|
+
{ preview }
|
|
236
|
+
{ isInserting && (
|
|
237
|
+
<div className="block-editor-inserter__media-list__item-preview-spinner">
|
|
238
|
+
<Spinner />
|
|
239
|
+
</div>
|
|
240
|
+
) }
|
|
241
|
+
</div>
|
|
242
|
+
</CompositeItem>
|
|
243
|
+
{ ! isInserting && (
|
|
244
|
+
<MediaPreviewOptions
|
|
245
|
+
category={ category }
|
|
246
|
+
media={ media }
|
|
247
|
+
/>
|
|
248
|
+
) }
|
|
249
|
+
</div>
|
|
250
|
+
</Tooltip>
|
|
251
|
+
</div>
|
|
252
|
+
) }
|
|
253
|
+
</InserterDraggableBlocks>
|
|
254
|
+
{ showExternalUploadModal && (
|
|
255
|
+
<InsertExternalImageModal
|
|
256
|
+
onClose={ () => setShowExternalUploadModal( false ) }
|
|
257
|
+
onSubmit={ () => {
|
|
258
|
+
onClick( cloneBlock( block ) );
|
|
259
|
+
createSuccessNotice( __( 'Image inserted.' ), {
|
|
260
|
+
type: 'snackbar',
|
|
261
|
+
} );
|
|
262
|
+
setShowExternalUploadModal( false );
|
|
263
|
+
} }
|
|
264
|
+
/>
|
|
265
|
+
) }
|
|
266
|
+
</>
|
|
267
|
+
);
|
|
268
|
+
}
|
|
@@ -660,6 +660,17 @@ $block-inserter-tabs-height: 44px;
|
|
|
660
660
|
margin: 0 auto;
|
|
661
661
|
max-width: 100%;
|
|
662
662
|
}
|
|
663
|
+
|
|
664
|
+
.block-editor-inserter__media-list__item-preview-spinner {
|
|
665
|
+
display: flex;
|
|
666
|
+
height: 100%;
|
|
667
|
+
width: 100%;
|
|
668
|
+
position: absolute;
|
|
669
|
+
justify-content: center;
|
|
670
|
+
background: rgba($white, 0.7);
|
|
671
|
+
align-items: center;
|
|
672
|
+
pointer-events: none;
|
|
673
|
+
}
|
|
663
674
|
}
|
|
664
675
|
|
|
665
676
|
&:focus .block-editor-inserter__media-list__item-preview {
|
|
@@ -686,3 +697,14 @@ $block-inserter-tabs-height: 44px;
|
|
|
686
697
|
height: 100%;
|
|
687
698
|
}
|
|
688
699
|
}
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
.block-editor-inserter-media-tab-media-preview-inserter-external-image-modal {
|
|
703
|
+
@include break-small() {
|
|
704
|
+
max-width: $break-mobile;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
p {
|
|
708
|
+
margin: 0;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Inserter can add blocks adds new block at the end of post 1`] = `
|
|
4
4
|
"<!-- wp:spacer -->
|
|
5
|
-
<div style
|
|
5
|
+
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
|
|
6
6
|
<!-- /wp:spacer -->
|
|
7
7
|
|
|
8
8
|
<!-- wp:heading -->
|
|
9
|
-
<h2 class
|
|
9
|
+
<h2 class="wp-block-heading"></h2>
|
|
10
10
|
<!-- /wp:heading -->"
|
|
11
11
|
`;
|
|
12
12
|
|
|
13
13
|
exports[`Inserter can add blocks after another block 1`] = `
|
|
14
14
|
"<!-- wp:spacer -->
|
|
15
|
-
<div style
|
|
15
|
+
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
|
|
16
16
|
<!-- /wp:spacer -->
|
|
17
17
|
|
|
18
18
|
<!-- wp:heading -->
|
|
19
|
-
<h2 class
|
|
19
|
+
<h2 class="wp-block-heading"></h2>
|
|
20
20
|
<!-- /wp:heading -->
|
|
21
21
|
|
|
22
22
|
<!-- wp:more -->
|
|
@@ -30,7 +30,7 @@ exports[`Inserter can add blocks after another block 1`] = `
|
|
|
30
30
|
|
|
31
31
|
exports[`Inserter can add blocks before another block 1`] = `
|
|
32
32
|
"<!-- wp:heading -->
|
|
33
|
-
<h2 class
|
|
33
|
+
<h2 class="wp-block-heading"></h2>
|
|
34
34
|
<!-- /wp:heading -->
|
|
35
35
|
|
|
36
36
|
<!-- wp:paragraph -->
|
|
@@ -40,11 +40,11 @@ exports[`Inserter can add blocks before another block 1`] = `
|
|
|
40
40
|
|
|
41
41
|
exports[`Inserter can add blocks creates a new Paragraph block tapping on the empty area below the last block 1`] = `
|
|
42
42
|
"<!-- wp:spacer -->
|
|
43
|
-
<div style
|
|
43
|
+
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
|
|
44
44
|
<!-- /wp:spacer -->
|
|
45
45
|
|
|
46
46
|
<!-- wp:heading -->
|
|
47
|
-
<h2 class
|
|
47
|
+
<h2 class="wp-block-heading"></h2>
|
|
48
48
|
<!-- /wp:heading -->
|
|
49
49
|
|
|
50
50
|
<!-- wp:paragraph -->
|
|
@@ -54,7 +54,7 @@ exports[`Inserter can add blocks creates a new Paragraph block tapping on the em
|
|
|
54
54
|
|
|
55
55
|
exports[`Inserter can add blocks inserts between 2 existing blocks 1`] = `
|
|
56
56
|
"<!-- wp:spacer -->
|
|
57
|
-
<div style
|
|
57
|
+
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
|
|
58
58
|
<!-- /wp:spacer -->
|
|
59
59
|
|
|
60
60
|
<!-- wp:more -->
|
|
@@ -62,17 +62,17 @@ exports[`Inserter can add blocks inserts between 2 existing blocks 1`] = `
|
|
|
62
62
|
<!-- /wp:more -->
|
|
63
63
|
|
|
64
64
|
<!-- wp:heading -->
|
|
65
|
-
<h2 class
|
|
65
|
+
<h2 class="wp-block-heading"></h2>
|
|
66
66
|
<!-- /wp:heading -->"
|
|
67
67
|
`;
|
|
68
68
|
|
|
69
69
|
exports[`Inserter can add blocks inserts block at the end of post when no block is selected 1`] = `
|
|
70
70
|
"<!-- wp:spacer -->
|
|
71
|
-
<div style
|
|
71
|
+
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
|
|
72
72
|
<!-- /wp:spacer -->
|
|
73
73
|
|
|
74
74
|
<!-- wp:heading -->
|
|
75
|
-
<h2 class
|
|
75
|
+
<h2 class="wp-block-heading"></h2>
|
|
76
76
|
<!-- /wp:heading -->
|
|
77
77
|
|
|
78
78
|
<!-- wp:more -->
|
|
@@ -86,11 +86,11 @@ exports[`Inserter can add blocks to the beginning 1`] = `
|
|
|
86
86
|
<!-- /wp:more -->
|
|
87
87
|
|
|
88
88
|
<!-- wp:spacer -->
|
|
89
|
-
<div style
|
|
89
|
+
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
|
|
90
90
|
<!-- /wp:spacer -->
|
|
91
91
|
|
|
92
92
|
<!-- wp:heading -->
|
|
93
|
-
<h2 class
|
|
93
|
+
<h2 class="wp-block-heading"></h2>
|
|
94
94
|
<!-- /wp:heading -->
|
|
95
95
|
|
|
96
96
|
<!-- wp:paragraph -->
|
|
@@ -100,11 +100,11 @@ exports[`Inserter can add blocks to the beginning 1`] = `
|
|
|
100
100
|
|
|
101
101
|
exports[`Inserter can add blocks to the end 1`] = `
|
|
102
102
|
"<!-- wp:spacer -->
|
|
103
|
-
<div style
|
|
103
|
+
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
|
|
104
104
|
<!-- /wp:spacer -->
|
|
105
105
|
|
|
106
106
|
<!-- wp:heading -->
|
|
107
|
-
<h2 class
|
|
107
|
+
<h2 class="wp-block-heading"></h2>
|
|
108
108
|
<!-- /wp:heading -->
|
|
109
109
|
|
|
110
110
|
<!-- wp:paragraph -->
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '@wordpress/components';
|
|
13
13
|
import warning from '@wordpress/warning';
|
|
14
14
|
import deprecated from '@wordpress/deprecated';
|
|
15
|
+
import { useEffect } from '@wordpress/element';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Internal dependencies
|
|
@@ -23,6 +24,7 @@ export default function InspectorControlsFill( {
|
|
|
23
24
|
children,
|
|
24
25
|
group = 'default',
|
|
25
26
|
__experimentalGroup,
|
|
27
|
+
resetAllFilter,
|
|
26
28
|
} ) {
|
|
27
29
|
if ( __experimentalGroup ) {
|
|
28
30
|
deprecated(
|
|
@@ -50,18 +52,40 @@ export default function InspectorControlsFill( {
|
|
|
50
52
|
<StyleProvider document={ document }>
|
|
51
53
|
<Fill>
|
|
52
54
|
{ ( fillProps ) => {
|
|
53
|
-
// Children passed to InspectorControlsFill will not have
|
|
54
|
-
// access to any React Context whose Provider is part of
|
|
55
|
-
// the InspectorControlsSlot tree. So we re-create the
|
|
56
|
-
// Provider in this subtree.
|
|
57
|
-
const value = ! isEmpty( fillProps ) ? fillProps : null;
|
|
58
55
|
return (
|
|
59
|
-
<
|
|
60
|
-
{
|
|
61
|
-
|
|
56
|
+
<ToolsPanelInspectorControl
|
|
57
|
+
fillProps={ fillProps }
|
|
58
|
+
children={ children }
|
|
59
|
+
resetAllFilter={ resetAllFilter }
|
|
60
|
+
/>
|
|
62
61
|
);
|
|
63
62
|
} }
|
|
64
63
|
</Fill>
|
|
65
64
|
</StyleProvider>
|
|
66
65
|
);
|
|
67
66
|
}
|
|
67
|
+
|
|
68
|
+
function ToolsPanelInspectorControl( { children, resetAllFilter, fillProps } ) {
|
|
69
|
+
const { registerResetAllFilter, deregisterResetAllFilter } = fillProps;
|
|
70
|
+
useEffect( () => {
|
|
71
|
+
if ( resetAllFilter && registerResetAllFilter ) {
|
|
72
|
+
registerResetAllFilter( resetAllFilter );
|
|
73
|
+
}
|
|
74
|
+
return () => {
|
|
75
|
+
if ( resetAllFilter && deregisterResetAllFilter ) {
|
|
76
|
+
deregisterResetAllFilter( resetAllFilter );
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}, [ resetAllFilter, registerResetAllFilter, deregisterResetAllFilter ] );
|
|
80
|
+
|
|
81
|
+
// Children passed to InspectorControlsFill will not have
|
|
82
|
+
// access to any React Context whose Provider is part of
|
|
83
|
+
// the InspectorControlsSlot tree. So we re-create the
|
|
84
|
+
// Provider in this subtree.
|
|
85
|
+
const value = ! isEmpty( fillProps ) ? fillProps : null;
|
|
86
|
+
return (
|
|
87
|
+
<ToolsPanelContext.Provider value={ value }>
|
|
88
|
+
{ children }
|
|
89
|
+
</ToolsPanelContext.Provider>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -11,6 +11,7 @@ import { settings as settingsIcon } from '@wordpress/icons';
|
|
|
11
11
|
import { useReducedMotion, useInstanceId } from '@wordpress/compose';
|
|
12
12
|
import { __ } from '@wordpress/i18n';
|
|
13
13
|
import { Fragment } from '@wordpress/element';
|
|
14
|
+
|
|
14
15
|
/**
|
|
15
16
|
* Internal dependencies
|
|
16
17
|
*/
|
|
@@ -46,7 +47,7 @@ function LinkSettingsDrawer( {
|
|
|
46
47
|
aria-expanded={ settingsOpen }
|
|
47
48
|
onClick={ () => setSettingsOpen( ! settingsOpen ) }
|
|
48
49
|
icon={ settingsIcon }
|
|
49
|
-
label={ __( '
|
|
50
|
+
label={ __( 'Link Settings' ) }
|
|
50
51
|
aria-controls={ settingsDrawerId }
|
|
51
52
|
/>
|
|
52
53
|
<MaybeAnimatePresence>
|
|
@@ -20,6 +20,7 @@ const LinkControlSettings = ( { value, onChange = noop, settings } ) => {
|
|
|
20
20
|
|
|
21
21
|
const theSettings = settings.map( ( setting ) => (
|
|
22
22
|
<ToggleControl
|
|
23
|
+
__nextHasNoMarginBottom
|
|
23
24
|
className="block-editor-link-control__setting"
|
|
24
25
|
key={ setting.id }
|
|
25
26
|
label={ setting.title }
|
|
@@ -22,6 +22,20 @@ $preview-image-height: 140px;
|
|
|
22
22
|
width: 90vw;
|
|
23
23
|
max-width: $modal-min-width;
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
.show-icon-labels & {
|
|
27
|
+
.components-button.has-icon {
|
|
28
|
+
// Hide the button icons when labels are set to display...
|
|
29
|
+
svg {
|
|
30
|
+
display: none;
|
|
31
|
+
}
|
|
32
|
+
// ... and display labels.
|
|
33
|
+
// Uses ::before as ::after is already used for active tab styling.
|
|
34
|
+
&::before {
|
|
35
|
+
content: attr(aria-label);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
// Provides positioning context for reset button. Without this then when an
|
|
@@ -72,7 +86,7 @@ $preview-image-height: 140px;
|
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
.block-editor-link-control__search-error {
|
|
75
|
-
margin: -$grid-unit-20*0.5 $grid-unit-20 $grid-unit-20; // negative margin to bring the error a bit closer to the button
|
|
89
|
+
margin: -$grid-unit-20 * 0.5 $grid-unit-20 $grid-unit-20; // negative margin to bring the error a bit closer to the button
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
.block-editor-link-control__search-actions {
|
|
@@ -103,7 +117,7 @@ $preview-image-height: 140px;
|
|
|
103
117
|
}
|
|
104
118
|
|
|
105
119
|
&::before {
|
|
106
|
-
height: $grid-unit-20*0.5;
|
|
120
|
+
height: $grid-unit-20 * 0.5;
|
|
107
121
|
top: 0;
|
|
108
122
|
bottom: auto;
|
|
109
123
|
}
|
|
@@ -123,7 +137,7 @@ $preview-image-height: 140px;
|
|
|
123
137
|
|
|
124
138
|
.block-editor-link-control__search-results {
|
|
125
139
|
margin: 0;
|
|
126
|
-
padding: $grid-unit-20*0.5 $grid-unit-20 $grid-unit-20*0.5;
|
|
140
|
+
padding: $grid-unit-20 * 0.5 $grid-unit-20 $grid-unit-20 * 0.5;
|
|
127
141
|
max-height: 200px;
|
|
128
142
|
overflow-y: auto; // allow results list to scroll
|
|
129
143
|
|
|
@@ -224,7 +238,6 @@ $preview-image-height: 140px;
|
|
|
224
238
|
max-height: 32px;
|
|
225
239
|
}
|
|
226
240
|
|
|
227
|
-
|
|
228
241
|
.block-editor-link-control__search-item-info,
|
|
229
242
|
.block-editor-link-control__search-item-title {
|
|
230
243
|
overflow: hidden;
|
|
@@ -344,16 +357,13 @@ $preview-image-height: 140px;
|
|
|
344
357
|
width: 100%;
|
|
345
358
|
}
|
|
346
359
|
|
|
347
|
-
|
|
348
360
|
.block-editor-link-control__search-item.is-fetching {
|
|
349
|
-
|
|
350
361
|
.block-editor-link-control__search-item-description {
|
|
351
362
|
&::before,
|
|
352
363
|
&::after {
|
|
353
364
|
animation: loadingpulse 1s linear infinite;
|
|
354
365
|
animation-delay: 0.5s; // avoid animating for fast network responses
|
|
355
366
|
}
|
|
356
|
-
|
|
357
367
|
}
|
|
358
368
|
|
|
359
369
|
.block-editor-link-control__search-item-image {
|
|
@@ -403,7 +413,7 @@ $preview-image-height: 140px;
|
|
|
403
413
|
&::before {
|
|
404
414
|
content: "";
|
|
405
415
|
position: absolute;
|
|
406
|
-
top: -#{$block-selected-child-margin*2};
|
|
416
|
+
top: -#{$block-selected-child-margin * 2};
|
|
407
417
|
left: 0;
|
|
408
418
|
display: block;
|
|
409
419
|
width: 100%;
|
|
@@ -1670,7 +1670,7 @@ describe( 'Addition Settings UI', () => {
|
|
|
1670
1670
|
render( <LinkControlConsumer /> );
|
|
1671
1671
|
|
|
1672
1672
|
const settingsToggle = screen.queryByRole( 'button', {
|
|
1673
|
-
name: '
|
|
1673
|
+
name: 'Link Settings',
|
|
1674
1674
|
ariaControls: 'link-settings-1',
|
|
1675
1675
|
} );
|
|
1676
1676
|
|
|
@@ -1690,7 +1690,7 @@ describe( 'Addition Settings UI', () => {
|
|
|
1690
1690
|
const user = userEvent.setup();
|
|
1691
1691
|
|
|
1692
1692
|
const settingsToggle = screen.queryByRole( 'button', {
|
|
1693
|
-
name: '
|
|
1693
|
+
name: 'Link Settings',
|
|
1694
1694
|
ariaControls: 'link-settings-1',
|
|
1695
1695
|
} );
|
|
1696
1696
|
|
|
@@ -2241,7 +2241,7 @@ describe( 'Controlling link title text', () => {
|
|
|
2241
2241
|
|
|
2242
2242
|
async function toggleSettingsDrawer( user ) {
|
|
2243
2243
|
const settingsToggle = screen.queryByRole( 'button', {
|
|
2244
|
-
name: '
|
|
2244
|
+
name: 'Link Settings',
|
|
2245
2245
|
} );
|
|
2246
2246
|
|
|
2247
2247
|
await user.click( settingsToggle );
|
|
@@ -27,6 +27,7 @@ import { sprintf, __ } from '@wordpress/i18n';
|
|
|
27
27
|
* Internal dependencies
|
|
28
28
|
*/
|
|
29
29
|
import ListViewLeaf from './leaf';
|
|
30
|
+
import useListViewScrollIntoView from './use-list-view-scroll-into-view';
|
|
30
31
|
import {
|
|
31
32
|
BlockMoverUpButton,
|
|
32
33
|
BlockMoverDownButton,
|
|
@@ -57,6 +58,7 @@ function ListViewBlock( {
|
|
|
57
58
|
isSyncedBranch,
|
|
58
59
|
} ) {
|
|
59
60
|
const cellRef = useRef( null );
|
|
61
|
+
const rowRef = useRef( null );
|
|
60
62
|
const [ isHovered, setIsHovered ] = useState( false );
|
|
61
63
|
const { clientId } = block;
|
|
62
64
|
|
|
@@ -220,6 +222,19 @@ function ListViewBlock( {
|
|
|
220
222
|
? selectedClientIds
|
|
221
223
|
: [ clientId ];
|
|
222
224
|
|
|
225
|
+
// Pass in a ref to the row, so that it can be scrolled
|
|
226
|
+
// into view when selected. For long lists, the placeholder for the
|
|
227
|
+
// selected block is also observed, within ListViewLeafPlaceholder.
|
|
228
|
+
useListViewScrollIntoView( {
|
|
229
|
+
isSelected,
|
|
230
|
+
rowItemRef: rowRef,
|
|
231
|
+
selectedClientIds,
|
|
232
|
+
} );
|
|
233
|
+
|
|
234
|
+
// Detect if there is a block in the canvas currently being edited and multi-selection is not happening.
|
|
235
|
+
const currentlyEditingBlockInCanvas =
|
|
236
|
+
isSelected && selectedClientIds.length === 1;
|
|
237
|
+
|
|
223
238
|
return (
|
|
224
239
|
<ListViewLeaf
|
|
225
240
|
className={ classes }
|
|
@@ -235,6 +250,7 @@ function ListViewBlock( {
|
|
|
235
250
|
data-block={ clientId }
|
|
236
251
|
isExpanded={ canExpand ? isExpanded : undefined }
|
|
237
252
|
aria-selected={ !! isSelected || forceSelectionContentLock }
|
|
253
|
+
ref={ rowRef }
|
|
238
254
|
>
|
|
239
255
|
<TreeGridCell
|
|
240
256
|
className="block-editor-list-view-block__contents-cell"
|
|
@@ -256,7 +272,9 @@ function ListViewBlock( {
|
|
|
256
272
|
siblingBlockCount={ siblingBlockCount }
|
|
257
273
|
level={ level }
|
|
258
274
|
ref={ ref }
|
|
259
|
-
tabIndex={
|
|
275
|
+
tabIndex={
|
|
276
|
+
currentlyEditingBlockInCanvas ? 0 : tabIndex
|
|
277
|
+
}
|
|
260
278
|
onFocus={ onFocus }
|
|
261
279
|
isExpanded={ isExpanded }
|
|
262
280
|
selectedClientIds={ selectedClientIds }
|
|
@@ -155,8 +155,6 @@ function ListViewBranch( props ) {
|
|
|
155
155
|
|
|
156
156
|
const isDragged = !! draggedClientIds?.includes( clientId );
|
|
157
157
|
|
|
158
|
-
const showBlock = isDragged || blockInView;
|
|
159
|
-
|
|
160
158
|
// Make updates to the selected or dragged blocks synchronous,
|
|
161
159
|
// but asynchronous for any other block.
|
|
162
160
|
const isSelected = isClientIdSelected(
|
|
@@ -165,6 +163,7 @@ function ListViewBranch( props ) {
|
|
|
165
163
|
);
|
|
166
164
|
const isSelectedBranch =
|
|
167
165
|
isBranchSelected || ( isSelected && hasNestedBlocks );
|
|
166
|
+
const showBlock = isDragged || blockInView || isSelected;
|
|
168
167
|
return (
|
|
169
168
|
<AsyncModeProvider key={ clientId } value={ ! isSelected }>
|
|
170
169
|
{ showBlock && (
|
|
@@ -19,6 +19,7 @@ export default function ListViewExpander( { onClick } ) {
|
|
|
19
19
|
className="block-editor-list-view__expander"
|
|
20
20
|
onClick={ ( event ) => onClick( event, { forceToggle: true } ) }
|
|
21
21
|
aria-hidden="true"
|
|
22
|
+
data-testid="list-view-expander"
|
|
22
23
|
>
|
|
23
24
|
<Icon icon={ isRTL() ? chevronLeftSmall : chevronRightSmall } />
|
|
24
25
|
</span>
|