@wordpress/block-editor 8.5.2 → 8.6.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 +2 -0
- package/build/components/block-list/block.native.js +3 -1
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-mover/button.js +4 -4
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +39 -65
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-popover/inbetween.js +183 -0
- package/build/components/block-popover/inbetween.js.map +1 -0
- package/build/components/block-popover/index.js +82 -0
- package/build/components/block-popover/index.js.map +1 -0
- package/build/components/{block-tools → block-popover}/use-popover-scroll.js +4 -1
- package/build/components/block-popover/use-popover-scroll.js.map +1 -0
- package/build/components/block-styles/index.js +1 -10
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-tools/back-compat.js +2 -2
- package/build/components/block-tools/back-compat.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +4 -2
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +5 -5
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +14 -121
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/{block-popover.js → selected-block-popover.js} +25 -108
- package/build/components/block-tools/selected-block-popover.js.map +1 -0
- package/build/components/duotone-control/index.js +5 -1
- package/build/components/duotone-control/index.js.map +1 -1
- package/build/components/inserter/index.native.js +30 -8
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/rich-text/index.js +0 -5
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +0 -4
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/use-block-display-information/index.js +3 -1
- package/build/components/use-block-display-information/index.js.map +1 -1
- package/build/hooks/border.js +468 -44
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/duotone.js +66 -16
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +8 -2
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-border-props.js +22 -32
- package/build/hooks/use-border-props.js.map +1 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/store/actions.js +14 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +0 -26
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +9 -3
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-list/block.native.js +3 -1
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-mover/button.js +5 -5
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +38 -63
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +165 -0
- package/build-module/components/block-popover/inbetween.js.map +1 -0
- package/build-module/components/block-popover/index.js +67 -0
- package/build-module/components/block-popover/index.js.map +1 -0
- package/build-module/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
- package/build-module/components/block-popover/use-popover-scroll.js.map +1 -0
- package/build-module/components/block-styles/index.js +1 -9
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-tools/back-compat.js +1 -1
- package/build-module/components/block-tools/back-compat.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +3 -2
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +3 -3
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +16 -121
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/{block-popover.js → selected-block-popover.js} +25 -105
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -0
- package/build-module/components/duotone-control/index.js +4 -1
- package/build-module/components/duotone-control/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +31 -10
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/rich-text/index.js +0 -4
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +0 -4
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/use-block-display-information/index.js +3 -1
- package/build-module/components/use-block-display-information/index.js.map +1 -1
- package/build-module/hooks/border.js +458 -44
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/duotone.js +63 -16
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +2 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-border-props.js +21 -30
- package/build-module/hooks/use-border-props.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +14 -2
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +0 -24
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +8 -3
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +111 -246
- package/build-style/style.css +111 -246
- package/package.json +28 -28
- package/src/components/block-list/block.native.js +2 -0
- package/src/components/block-mover/button.js +5 -7
- package/src/components/block-mover/index.js +37 -60
- package/src/components/block-mover/stories/index.js +110 -0
- package/src/components/block-mover/style.scss +48 -138
- package/src/components/block-popover/README.md +41 -0
- package/src/components/block-popover/inbetween.js +180 -0
- package/src/components/block-popover/index.js +73 -0
- package/src/components/block-popover/style.scss +24 -0
- package/src/components/{block-tools → block-popover}/use-popover-scroll.js +3 -1
- package/src/components/block-styles/index.js +1 -12
- package/src/components/block-switcher/style.scss +0 -4
- package/src/components/block-toolbar/style.scss +0 -12
- package/src/components/block-tools/back-compat.js +1 -1
- package/src/components/block-tools/block-selection-button.js +3 -1
- package/src/components/block-tools/index.js +6 -4
- package/src/components/block-tools/insertion-point.js +19 -152
- package/src/components/block-tools/{block-popover.js → selected-block-popover.js} +24 -116
- package/src/components/block-tools/style.scss +11 -123
- package/src/components/border-radius-control/style.scss +5 -2
- package/src/components/default-block-appender/style.scss +1 -2
- package/src/components/duotone-control/index.js +8 -1
- package/src/components/gradients/README.md +29 -0
- package/src/components/inserter/index.native.js +60 -25
- package/src/components/inserter/style.native.scss +24 -3
- package/src/components/navigable-toolbar/README.md +16 -0
- package/src/components/rich-text/index.js +0 -2
- package/src/components/rich-text/index.native.js +0 -4
- package/src/components/use-block-display-information/index.js +2 -0
- package/src/hooks/border.js +438 -72
- package/src/hooks/border.scss +48 -0
- package/src/hooks/duotone.js +98 -62
- package/src/hooks/index.js +2 -1
- package/src/hooks/use-border-props.js +15 -32
- package/src/index.js +1 -0
- package/src/store/actions.js +14 -2
- package/src/store/reducer.js +0 -21
- package/src/store/selectors.js +12 -3
- package/src/store/test/actions.js +0 -18
- package/src/store/test/reducer.js +0 -19
- package/src/store/test/selectors.js +0 -19
- package/src/style.scss +1 -1
- package/build/components/block-mobile-toolbar/index.js +0 -42
- package/build/components/block-mobile-toolbar/index.js.map +0 -1
- package/build/components/block-tools/block-popover.js.map +0 -1
- package/build/components/block-tools/use-popover-scroll.js.map +0 -1
- package/build/components/list-view/appender.js +0 -93
- package/build/components/list-view/appender.js.map +0 -1
- package/build/components/list-view/list-item.js +0 -62
- package/build/components/list-view/list-item.js.map +0 -1
- package/build/components/rich-text/use-caret-in-format.js +0 -43
- package/build/components/rich-text/use-caret-in-format.js.map +0 -1
- package/build/hooks/border-color.js +0 -302
- package/build/hooks/border-color.js.map +0 -1
- package/build/hooks/border-style.js +0 -96
- package/build/hooks/border-style.js.map +0 -1
- package/build/hooks/border-width.js +0 -162
- package/build/hooks/border-width.js.map +0 -1
- package/build-module/components/block-mobile-toolbar/index.js +0 -31
- package/build-module/components/block-mobile-toolbar/index.js.map +0 -1
- package/build-module/components/block-tools/block-popover.js.map +0 -1
- package/build-module/components/block-tools/use-popover-scroll.js.map +0 -1
- package/build-module/components/list-view/appender.js +0 -76
- package/build-module/components/list-view/appender.js.map +0 -1
- package/build-module/components/list-view/list-item.js +0 -47
- package/build-module/components/list-view/list-item.js.map +0 -1
- package/build-module/components/rich-text/use-caret-in-format.js +0 -33
- package/build-module/components/rich-text/use-caret-in-format.js.map +0 -1
- package/build-module/hooks/border-color.js +0 -276
- package/build-module/hooks/border-color.js.map +0 -1
- package/build-module/hooks/border-style.js +0 -78
- package/build-module/hooks/border-style.js.map +0 -1
- package/build-module/hooks/border-width.js +0 -143
- package/build-module/hooks/border-width.js.map +0 -1
- package/src/components/block-mobile-toolbar/index.js +0 -24
- package/src/components/block-mobile-toolbar/style.scss +0 -29
- package/src/components/list-view/appender.js +0 -82
- package/src/components/list-view/list-item.js +0 -59
- package/src/components/rich-text/use-caret-in-format.js +0 -28
- package/src/hooks/border-color.js +0 -315
- package/src/hooks/border-style.js +0 -64
- package/src/hooks/border-width.js +0 -139
|
@@ -10,9 +10,7 @@ import classnames from 'classnames';
|
|
|
10
10
|
|
|
11
11
|
import { dragHandle } from '@wordpress/icons';
|
|
12
12
|
import { ToolbarGroup, ToolbarItem, Button } from '@wordpress/components';
|
|
13
|
-
import {
|
|
14
|
-
import { useState } from '@wordpress/element';
|
|
15
|
-
import { withSelect } from '@wordpress/data';
|
|
13
|
+
import { useSelect } from '@wordpress/data';
|
|
16
14
|
import { __ } from '@wordpress/i18n';
|
|
17
15
|
|
|
18
16
|
/**
|
|
@@ -22,20 +20,35 @@ import BlockDraggable from '../block-draggable';
|
|
|
22
20
|
import { BlockMoverUpButton, BlockMoverDownButton } from './button';
|
|
23
21
|
import { store as blockEditorStore } from '../../store';
|
|
24
22
|
|
|
25
|
-
function BlockMover( {
|
|
26
|
-
isFirst,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} )
|
|
35
|
-
|
|
23
|
+
function BlockMover( { clientIds, hideDragHandle } ) {
|
|
24
|
+
const { canMove, rootClientId, isFirst, isLast, orientation } = useSelect(
|
|
25
|
+
( select ) => {
|
|
26
|
+
const {
|
|
27
|
+
getBlockIndex,
|
|
28
|
+
getBlockListSettings,
|
|
29
|
+
canMoveBlocks,
|
|
30
|
+
getBlockOrder,
|
|
31
|
+
getBlockRootClientId,
|
|
32
|
+
} = select( blockEditorStore );
|
|
33
|
+
const normalizedClientIds = castArray( clientIds );
|
|
34
|
+
const firstClientId = first( normalizedClientIds );
|
|
35
|
+
const _rootClientId = getBlockRootClientId(
|
|
36
|
+
first( normalizedClientIds )
|
|
37
|
+
);
|
|
38
|
+
const firstIndex = getBlockIndex( firstClientId );
|
|
39
|
+
const lastIndex = getBlockIndex( last( normalizedClientIds ) );
|
|
40
|
+
const blockOrder = getBlockOrder( _rootClientId );
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
return {
|
|
43
|
+
canMove: canMoveBlocks( clientIds, _rootClientId ),
|
|
44
|
+
rootClientId: _rootClientId,
|
|
45
|
+
isFirst: firstIndex === 0,
|
|
46
|
+
isLast: lastIndex === blockOrder.length - 1,
|
|
47
|
+
orientation: getBlockListSettings( _rootClientId )?.orientation,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
[ clientIds ]
|
|
51
|
+
);
|
|
39
52
|
|
|
40
53
|
if ( ! canMove || ( isFirst && isLast && ! rootClientId ) ) {
|
|
41
54
|
return null;
|
|
@@ -43,22 +56,14 @@ function BlockMover( {
|
|
|
43
56
|
|
|
44
57
|
const dragHandleLabel = __( 'Drag' );
|
|
45
58
|
|
|
46
|
-
// We emulate a disabled state because forcefully applying the `disabled`
|
|
47
|
-
// attribute on the buttons while it has focus causes the screen to change
|
|
48
|
-
// to an unfocused state (body as active element) without firing blur on,
|
|
49
|
-
// the rendering parent, leaving it unable to react to focus out.
|
|
50
59
|
return (
|
|
51
|
-
<
|
|
60
|
+
<ToolbarGroup
|
|
52
61
|
className={ classnames( 'block-editor-block-mover', {
|
|
53
|
-
'is-visible': isFocused || ! isHidden,
|
|
54
62
|
'is-horizontal': orientation === 'horizontal',
|
|
55
63
|
} ) }
|
|
56
64
|
>
|
|
57
65
|
{ ! hideDragHandle && (
|
|
58
|
-
<BlockDraggable
|
|
59
|
-
clientIds={ clientIds }
|
|
60
|
-
cloneClassname="block-editor-block-mover__drag-clone"
|
|
61
|
-
>
|
|
66
|
+
<BlockDraggable clientIds={ clientIds }>
|
|
62
67
|
{ ( draggableProps ) => (
|
|
63
68
|
<Button
|
|
64
69
|
icon={ dragHandle }
|
|
@@ -73,8 +78,8 @@ function BlockMover( {
|
|
|
73
78
|
) }
|
|
74
79
|
</BlockDraggable>
|
|
75
80
|
) }
|
|
76
|
-
<
|
|
77
|
-
<ToolbarItem
|
|
81
|
+
<div className="block-editor-block-mover__move-button-container">
|
|
82
|
+
<ToolbarItem>
|
|
78
83
|
{ ( itemProps ) => (
|
|
79
84
|
<BlockMoverUpButton
|
|
80
85
|
clientIds={ clientIds }
|
|
@@ -82,7 +87,7 @@ function BlockMover( {
|
|
|
82
87
|
/>
|
|
83
88
|
) }
|
|
84
89
|
</ToolbarItem>
|
|
85
|
-
<ToolbarItem
|
|
90
|
+
<ToolbarItem>
|
|
86
91
|
{ ( itemProps ) => (
|
|
87
92
|
<BlockMoverDownButton
|
|
88
93
|
clientIds={ clientIds }
|
|
@@ -90,40 +95,12 @@ function BlockMover( {
|
|
|
90
95
|
/>
|
|
91
96
|
) }
|
|
92
97
|
</ToolbarItem>
|
|
93
|
-
</
|
|
94
|
-
</
|
|
98
|
+
</div>
|
|
99
|
+
</ToolbarGroup>
|
|
95
100
|
);
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
/**
|
|
99
104
|
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-mover/README.md
|
|
100
105
|
*/
|
|
101
|
-
export default
|
|
102
|
-
const {
|
|
103
|
-
getBlock,
|
|
104
|
-
getBlockIndex,
|
|
105
|
-
getBlockListSettings,
|
|
106
|
-
canMoveBlocks,
|
|
107
|
-
getBlockOrder,
|
|
108
|
-
getBlockRootClientId,
|
|
109
|
-
} = select( blockEditorStore );
|
|
110
|
-
const normalizedClientIds = castArray( clientIds );
|
|
111
|
-
const firstClientId = first( normalizedClientIds );
|
|
112
|
-
const block = getBlock( firstClientId );
|
|
113
|
-
const rootClientId = getBlockRootClientId( first( normalizedClientIds ) );
|
|
114
|
-
const firstIndex = getBlockIndex( firstClientId );
|
|
115
|
-
const lastIndex = getBlockIndex( last( normalizedClientIds ) );
|
|
116
|
-
const blockOrder = getBlockOrder( rootClientId );
|
|
117
|
-
const isFirst = firstIndex === 0;
|
|
118
|
-
const isLast = lastIndex === blockOrder.length - 1;
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
blockType: block ? getBlockType( block.name ) : null,
|
|
122
|
-
canMove: canMoveBlocks( clientIds, rootClientId ),
|
|
123
|
-
rootClientId,
|
|
124
|
-
firstIndex,
|
|
125
|
-
isFirst,
|
|
126
|
-
isLast,
|
|
127
|
-
orientation: getBlockListSettings( rootClientId )?.orientation,
|
|
128
|
-
};
|
|
129
|
-
} )( BlockMover );
|
|
106
|
+
export default BlockMover;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect } from '@wordpress/element';
|
|
5
|
+
import { createBlock } from '@wordpress/blocks';
|
|
6
|
+
import { registerCoreBlocks } from '@wordpress/block-library';
|
|
7
|
+
import { useDispatch } from '@wordpress/data';
|
|
8
|
+
import { Toolbar } from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import BlockMover from '../';
|
|
14
|
+
import BlockEditorProvider from '../../provider';
|
|
15
|
+
import { store as blockEditorStore } from '../../../store';
|
|
16
|
+
|
|
17
|
+
registerCoreBlocks();
|
|
18
|
+
const blocks = [
|
|
19
|
+
// vertical
|
|
20
|
+
createBlock( 'core/group', { layout: { type: 'flex' } }, [
|
|
21
|
+
createBlock( 'core/paragraph' ),
|
|
22
|
+
createBlock( 'core/paragraph' ),
|
|
23
|
+
createBlock( 'core/paragraph' ),
|
|
24
|
+
] ),
|
|
25
|
+
// horizontal
|
|
26
|
+
createBlock( 'core/buttons', {}, [
|
|
27
|
+
createBlock( 'core/button' ),
|
|
28
|
+
createBlock( 'core/button' ),
|
|
29
|
+
createBlock( 'core/button' ),
|
|
30
|
+
] ),
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function Provider( { children } ) {
|
|
34
|
+
const wrapperStyle = { margin: '24px', position: 'relative' };
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div style={ wrapperStyle }>
|
|
38
|
+
<BlockEditorProvider value={ blocks }>
|
|
39
|
+
{ children }
|
|
40
|
+
</BlockEditorProvider>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function BlockMoverStory() {
|
|
46
|
+
const { updateBlockListSettings } = useDispatch( blockEditorStore );
|
|
47
|
+
|
|
48
|
+
useEffect( () => {
|
|
49
|
+
/**
|
|
50
|
+
* This shouldn't be needed but unfortunatley
|
|
51
|
+
* the layout orientation is not declarative, we need
|
|
52
|
+
* to render the blocks to update the block settings in the state.
|
|
53
|
+
*/
|
|
54
|
+
updateBlockListSettings( blocks[ 1 ].clientId, {
|
|
55
|
+
orientation: 'horizontal',
|
|
56
|
+
} );
|
|
57
|
+
}, [] );
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div>
|
|
61
|
+
<p>The mover by default is vertical</p>
|
|
62
|
+
<Toolbar label="Block Mover">
|
|
63
|
+
<BlockMover
|
|
64
|
+
clientIds={
|
|
65
|
+
blocks.length
|
|
66
|
+
? [ blocks[ 0 ].innerBlocks[ 1 ].clientId ]
|
|
67
|
+
: []
|
|
68
|
+
}
|
|
69
|
+
/>
|
|
70
|
+
</Toolbar>
|
|
71
|
+
|
|
72
|
+
<p style={ { marginTop: 36 } }>
|
|
73
|
+
But it can also accomodate horizontal blocks.
|
|
74
|
+
</p>
|
|
75
|
+
<Toolbar label="Block Mover">
|
|
76
|
+
<BlockMover
|
|
77
|
+
clientIds={
|
|
78
|
+
blocks.length
|
|
79
|
+
? [ blocks[ 1 ].innerBlocks[ 1 ].clientId ]
|
|
80
|
+
: []
|
|
81
|
+
}
|
|
82
|
+
/>
|
|
83
|
+
</Toolbar>
|
|
84
|
+
|
|
85
|
+
<p style={ { marginTop: 36 } }>We can also hide the drag handle.</p>
|
|
86
|
+
<Toolbar label="Block Mover">
|
|
87
|
+
<BlockMover
|
|
88
|
+
clientIds={
|
|
89
|
+
blocks.length
|
|
90
|
+
? [ blocks[ 1 ].innerBlocks[ 0 ].clientId ]
|
|
91
|
+
: []
|
|
92
|
+
}
|
|
93
|
+
hideDragHandle
|
|
94
|
+
/>
|
|
95
|
+
</Toolbar>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default {
|
|
101
|
+
title: 'BlockEditor/BlockMover',
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const _default = () => {
|
|
105
|
+
return (
|
|
106
|
+
<Provider>
|
|
107
|
+
<BlockMoverStory />
|
|
108
|
+
</Provider>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -1,159 +1,69 @@
|
|
|
1
|
-
.block-editor-block-
|
|
2
|
-
display:
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.block-editor-block-mover-button.has-icon {
|
|
1
|
+
.block-editor-block-mover__move-button-container {
|
|
2
|
+
display: flex;
|
|
6
3
|
padding: 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// Show the mover in a single button under the contextual toolbar.
|
|
10
|
-
.block-editor-block-mover {
|
|
11
|
-
display: inline-flex;
|
|
12
|
-
flex-direction: row;
|
|
13
|
-
|
|
14
|
-
.block-editor-block-mover__move-button-container,
|
|
15
|
-
.components-toolbar {
|
|
16
|
-
flex: 1;
|
|
4
|
+
border: none;
|
|
17
5
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
border-right: none !important;
|
|
21
|
-
|
|
22
|
-
@include break-small() {
|
|
6
|
+
@include break-small() {
|
|
7
|
+
.block-editor-block-mover:not(.is-horizontal) & {
|
|
23
8
|
flex-direction: column;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.block-editor-block-mover-button {
|
|
37
|
-
&.block-editor-block-mover-button {
|
|
38
|
-
padding-right: 0;
|
|
39
|
-
padding-left: 0;
|
|
40
|
-
min-width: $button-size;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@include break-small() {
|
|
44
|
-
// The !important modifier should be removed when https://github.com/WordPress/gutenberg/issues/24898 refactors the spacing grid.
|
|
45
|
-
height: $block-toolbar-height*0.5;
|
|
46
|
-
width: $block-toolbar-height - $grid-unit-15 * 0.5;
|
|
47
|
-
padding-right: $grid-unit-15 - $border-width !important;
|
|
48
|
-
padding-left: $grid-unit-15 * 0.5 !important;
|
|
49
|
-
|
|
50
|
-
// Extra specificity to override standard toolbar button styles.
|
|
51
|
-
&.block-editor-block-mover-button {
|
|
52
|
-
min-width: $block-toolbar-height - $grid-unit-15 * 0.5;
|
|
9
|
+
width: $block-toolbar-height - $grid-unit-15;
|
|
10
|
+
|
|
11
|
+
> * {
|
|
12
|
+
height: $block-toolbar-height * 0.5;
|
|
13
|
+
width: 100%;
|
|
14
|
+
min-width: 0 !important; // overrides default button width.
|
|
15
|
+
|
|
16
|
+
// Focus style.
|
|
17
|
+
&::before {
|
|
18
|
+
height: 100%;
|
|
19
|
+
width: 100%;
|
|
20
|
+
}
|
|
53
21
|
}
|
|
54
|
-
}
|
|
55
22
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
@include break-small() {
|
|
60
|
-
left: $grid-unit-10 !important;
|
|
61
|
-
right: $grid-unit-10 !important;
|
|
23
|
+
.block-editor-block-mover-button.is-up-button svg {
|
|
24
|
+
top: 5px;
|
|
25
|
+
flex-shrink: 0;
|
|
62
26
|
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
27
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// The !important modifier should be removed when https://github.com/WordPress/gutenberg/issues/24898 refactors the spacing grid.
|
|
71
|
-
min-width: $button-size-small !important;
|
|
72
|
-
padding: 0 !important;
|
|
73
|
-
|
|
74
|
-
&:focus::before {
|
|
75
|
-
left: 0 !important;
|
|
76
|
-
right: 0 !important;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Position the icons correctly.
|
|
81
|
-
@include break-small() {
|
|
82
|
-
.components-toolbar-group .block-editor-block-mover-button,
|
|
83
|
-
.components-toolbar .block-editor-block-mover-button {
|
|
84
|
-
margin: 0 auto 0 0;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Up button.
|
|
88
|
-
.components-toolbar-group .block-editor-block-mover-button.is-up-button,
|
|
89
|
-
.components-toolbar .block-editor-block-mover-button.is-up-button {
|
|
90
|
-
// Focus style.
|
|
91
|
-
&::before {
|
|
92
|
-
bottom: 0;
|
|
93
|
-
height: calc(100% - #{ $border-width });
|
|
28
|
+
.block-editor-block-mover-button.is-down-button svg {
|
|
29
|
+
bottom: 5px;
|
|
30
|
+
flex-shrink: 0;
|
|
94
31
|
}
|
|
95
32
|
}
|
|
96
33
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.components-toolbar .block-editor-block-mover-button.is-down-button {
|
|
100
|
-
// Focus style.
|
|
101
|
-
&::before {
|
|
102
|
-
top: 0;
|
|
103
|
-
height: calc(100% - #{ $border-width });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
34
|
+
.block-editor-block-mover.is-horizontal & {
|
|
35
|
+
width: $block-toolbar-height;
|
|
107
36
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
padding-left: 0;
|
|
115
|
-
padding-right: 0;
|
|
37
|
+
> * {
|
|
38
|
+
width: $block-toolbar-height * 0.5;
|
|
39
|
+
min-width: 0 !important; // overrides default button width.
|
|
40
|
+
padding-left: 0 !important;
|
|
41
|
+
padding-right: 0 !important;
|
|
42
|
+
overflow: hidden;
|
|
116
43
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
min-width: 0;
|
|
122
|
-
width: auto;
|
|
123
|
-
height: auto;
|
|
44
|
+
// Focus style.
|
|
45
|
+
&::before {
|
|
46
|
+
height: 100%;
|
|
47
|
+
}
|
|
124
48
|
}
|
|
125
|
-
}
|
|
126
49
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
svg {
|
|
130
|
-
margin-left: 0;
|
|
131
|
-
margin-right: -$grid-unit-10;
|
|
132
|
-
margin-bottom: 0;
|
|
50
|
+
.block-editor-block-mover-button.is-up-button svg {
|
|
51
|
+
left: 5px;
|
|
133
52
|
}
|
|
134
53
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
&::before {
|
|
138
|
-
left: 0 !important;
|
|
139
|
-
right: 0 !important;
|
|
54
|
+
.block-editor-block-mover-button.is-down-button svg {
|
|
55
|
+
right: 5px;
|
|
140
56
|
}
|
|
141
57
|
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
142
60
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// Focus style.
|
|
151
|
-
// Overrides .components-toolbar-group styles
|
|
152
|
-
&::before {
|
|
153
|
-
left: 0 !important;
|
|
154
|
-
right: 0 !important;
|
|
155
|
-
width: calc(100% + #{ $border-width });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
61
|
+
.block-editor-block-mover__drag-handle {
|
|
62
|
+
@include break-small() {
|
|
63
|
+
width: $block-toolbar-height * 0.5;
|
|
64
|
+
min-width: 0 !important; // overrides default button width.
|
|
65
|
+
padding-left: 0 !important;
|
|
66
|
+
padding-right: 0 !important;
|
|
67
|
+
overflow: hidden;
|
|
158
68
|
}
|
|
159
69
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# BlockPopover and BlockPopoverInbetween
|
|
2
|
+
|
|
3
|
+
These two components allow rendering editor UI by the block (in a popover) but outside the canvas. This is important to avoid messing with the style and layout of the block list.
|
|
4
|
+
|
|
5
|
+
For example, it's used to render the contextual block toolbar and the in-between block inserter.
|
|
6
|
+
|
|
7
|
+
## BlockPopover
|
|
8
|
+
|
|
9
|
+
### Props
|
|
10
|
+
|
|
11
|
+
#### clientId
|
|
12
|
+
|
|
13
|
+
The client ID of the block representing the top position of the popover.
|
|
14
|
+
|
|
15
|
+
- Type: `String`
|
|
16
|
+
- Required: Yes
|
|
17
|
+
|
|
18
|
+
#### bottomClientId
|
|
19
|
+
|
|
20
|
+
The client ID of the block representing the bottom position of the popover.
|
|
21
|
+
|
|
22
|
+
- Type: `String`
|
|
23
|
+
- Required: No
|
|
24
|
+
|
|
25
|
+
## BlockPopoverInbetween
|
|
26
|
+
|
|
27
|
+
### Props
|
|
28
|
+
|
|
29
|
+
#### previousClientId
|
|
30
|
+
|
|
31
|
+
The client ID of the block before the popover.
|
|
32
|
+
|
|
33
|
+
- Type: `String`
|
|
34
|
+
- Required: Yes
|
|
35
|
+
|
|
36
|
+
#### nextClientId
|
|
37
|
+
|
|
38
|
+
The client ID of the block after the popover.
|
|
39
|
+
|
|
40
|
+
- Type: `String`
|
|
41
|
+
- Required: Yes
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
import { useCallback, useMemo, createContext } from '@wordpress/element';
|
|
11
|
+
import { Popover } from '@wordpress/components';
|
|
12
|
+
import { isRTL } from '@wordpress/i18n';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { store as blockEditorStore } from '../../store';
|
|
18
|
+
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
|
|
19
|
+
import usePopoverScroll from './use-popover-scroll';
|
|
20
|
+
|
|
21
|
+
export const InsertionPointOpenRef = createContext();
|
|
22
|
+
|
|
23
|
+
function BlockPopoverInbetween( {
|
|
24
|
+
previousClientId,
|
|
25
|
+
nextClientId,
|
|
26
|
+
children,
|
|
27
|
+
__unstablePopoverSlot,
|
|
28
|
+
__unstableContentRef,
|
|
29
|
+
...props
|
|
30
|
+
} ) {
|
|
31
|
+
const { orientation, rootClientId } = useSelect(
|
|
32
|
+
( select ) => {
|
|
33
|
+
const { getBlockListSettings, getBlockRootClientId } = select(
|
|
34
|
+
blockEditorStore
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const _rootClientId = getBlockRootClientId( previousClientId );
|
|
38
|
+
return {
|
|
39
|
+
orientation:
|
|
40
|
+
getBlockListSettings( _rootClientId )?.orientation ||
|
|
41
|
+
'vertical',
|
|
42
|
+
rootClientId: _rootClientId,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
[ previousClientId ]
|
|
46
|
+
);
|
|
47
|
+
const previousElement = useBlockElement( previousClientId );
|
|
48
|
+
const nextElement = useBlockElement( nextClientId );
|
|
49
|
+
const isVertical = orientation === 'vertical';
|
|
50
|
+
const style = useMemo( () => {
|
|
51
|
+
if ( ! previousElement && ! nextElement ) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const previousRect = previousElement
|
|
56
|
+
? previousElement.getBoundingClientRect()
|
|
57
|
+
: null;
|
|
58
|
+
const nextRect = nextElement
|
|
59
|
+
? nextElement.getBoundingClientRect()
|
|
60
|
+
: null;
|
|
61
|
+
|
|
62
|
+
if ( isVertical ) {
|
|
63
|
+
return {
|
|
64
|
+
width: previousElement
|
|
65
|
+
? previousElement.offsetWidth
|
|
66
|
+
: nextElement.offsetWidth,
|
|
67
|
+
height:
|
|
68
|
+
nextRect && previousRect
|
|
69
|
+
? nextRect.top - previousRect.bottom
|
|
70
|
+
: 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let width = 0;
|
|
75
|
+
if ( previousRect && nextRect ) {
|
|
76
|
+
width = isRTL()
|
|
77
|
+
? previousRect.left - nextRect.right
|
|
78
|
+
: nextRect.left - previousRect.right;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
width,
|
|
83
|
+
height: previousElement
|
|
84
|
+
? previousElement.offsetHeight
|
|
85
|
+
: nextElement.offsetHeight,
|
|
86
|
+
};
|
|
87
|
+
}, [ previousElement, nextElement, isVertical ] );
|
|
88
|
+
|
|
89
|
+
const getAnchorRect = useCallback( () => {
|
|
90
|
+
if ( ! previousElement && ! nextElement ) {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { ownerDocument } = previousElement || nextElement;
|
|
95
|
+
|
|
96
|
+
const previousRect = previousElement
|
|
97
|
+
? previousElement.getBoundingClientRect()
|
|
98
|
+
: null;
|
|
99
|
+
const nextRect = nextElement
|
|
100
|
+
? nextElement.getBoundingClientRect()
|
|
101
|
+
: null;
|
|
102
|
+
|
|
103
|
+
if ( isVertical ) {
|
|
104
|
+
if ( isRTL() ) {
|
|
105
|
+
return {
|
|
106
|
+
top: previousRect ? previousRect.bottom : nextRect.top,
|
|
107
|
+
left: previousRect ? previousRect.right : nextRect.right,
|
|
108
|
+
right: previousRect ? previousRect.left : nextRect.left,
|
|
109
|
+
bottom: nextRect ? nextRect.top : previousRect.bottom,
|
|
110
|
+
ownerDocument,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
top: previousRect ? previousRect.bottom : nextRect.top,
|
|
116
|
+
left: previousRect ? previousRect.left : nextRect.left,
|
|
117
|
+
right: previousRect ? previousRect.right : nextRect.right,
|
|
118
|
+
bottom: nextRect ? nextRect.top : previousRect.bottom,
|
|
119
|
+
ownerDocument,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if ( isRTL() ) {
|
|
124
|
+
return {
|
|
125
|
+
top: previousRect ? previousRect.top : nextRect.top,
|
|
126
|
+
left: previousRect ? previousRect.left : nextRect.right,
|
|
127
|
+
right: nextRect ? nextRect.right : previousRect.left,
|
|
128
|
+
bottom: previousRect ? previousRect.bottom : nextRect.bottom,
|
|
129
|
+
ownerDocument,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
top: previousRect ? previousRect.top : nextRect.top,
|
|
135
|
+
left: previousRect ? previousRect.right : nextRect.left,
|
|
136
|
+
right: nextRect ? nextRect.left : previousRect.right,
|
|
137
|
+
bottom: previousRect ? previousRect.bottom : nextRect.bottom,
|
|
138
|
+
ownerDocument,
|
|
139
|
+
};
|
|
140
|
+
}, [ previousElement, nextElement ] );
|
|
141
|
+
|
|
142
|
+
const popoverScrollRef = usePopoverScroll( __unstableContentRef );
|
|
143
|
+
|
|
144
|
+
if ( ! previousElement || ! nextElement ) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
|
|
149
|
+
// While ideally it would be enough to capture the
|
|
150
|
+
// bubbling focus event from the Inserter, due to the
|
|
151
|
+
// characteristics of click focusing of `button`s in
|
|
152
|
+
// Firefox and Safari, it is not reliable.
|
|
153
|
+
//
|
|
154
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
|
|
155
|
+
return (
|
|
156
|
+
<Popover
|
|
157
|
+
ref={ popoverScrollRef }
|
|
158
|
+
noArrow
|
|
159
|
+
animate={ false }
|
|
160
|
+
getAnchorRect={ getAnchorRect }
|
|
161
|
+
focusOnMount={ false }
|
|
162
|
+
// Render in the old slot if needed for backward compatibility,
|
|
163
|
+
// otherwise render in place (not in the the default popover slot).
|
|
164
|
+
__unstableSlotName={ __unstablePopoverSlot || null }
|
|
165
|
+
// Forces a remount of the popover when its position changes
|
|
166
|
+
// This makes sure the popover doesn't animate from its previous position.
|
|
167
|
+
key={ nextClientId + '--' + rootClientId }
|
|
168
|
+
{ ...props }
|
|
169
|
+
className={ classnames(
|
|
170
|
+
'block-editor-block-popover',
|
|
171
|
+
props.className
|
|
172
|
+
) }
|
|
173
|
+
>
|
|
174
|
+
<div style={ style }>{ children }</div>
|
|
175
|
+
</Popover>
|
|
176
|
+
);
|
|
177
|
+
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export default BlockPopoverInbetween;
|