-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
111 lines (105 loc) · 2.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
getBlockType,
getUnregisteredTypeHandlerName,
} from '@wordpress/blocks';
import {
PanelBody,
__experimentalUseSlot as useSlot,
} from '@wordpress/components';
import { withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import SkipToSelectedBlock from '../skip-to-selected-block';
import BlockCard from '../block-card';
import InspectorControls from '../inspector-controls';
import InspectorAdvancedControls from '../inspector-advanced-controls';
import BlockStyles from '../block-styles';
import MultiSelectionInspector from '../multi-selection-inspector';
import DefaultStylePicker from '../default-style-picker';
const BlockInspector = ( {
blockType,
count,
hasBlockStyles,
selectedBlockClientId,
selectedBlockName,
showNoBlockSelectedMessage = true,
} ) => {
const slot = useSlot( InspectorAdvancedControls.slotName );
const hasFills = Boolean( slot.fills && slot.fills.length );
if ( count > 1 ) {
return <MultiSelectionInspector />;
}
const isSelectedBlockUnregistered =
selectedBlockName === getUnregisteredTypeHandlerName();
/*
* If the selected block is of an unregistered type, avoid showing it as an actual selection
* because we want the user to focus on the unregistered block warning, not block settings.
*/
if (
! blockType ||
! selectedBlockClientId ||
isSelectedBlockUnregistered
) {
if ( showNoBlockSelectedMessage ) {
return (
<span className="block-editor-block-inspector__no-blocks">
{ __( 'No block selected.' ) }
</span>
);
}
return null;
}
return (
<div className="block-editor-block-inspector">
<BlockCard blockType={ blockType } />
{ hasBlockStyles && (
<div>
<PanelBody title={ __( 'Styles' ) } initialOpen={ false }>
<BlockStyles clientId={ selectedBlockClientId } />
<DefaultStylePicker blockName={ blockType.name } />
</PanelBody>
</div>
) }
<InspectorControls.Slot bubblesVirtually />
<div>
{ hasFills && (
<PanelBody
className="block-editor-block-inspector__advanced"
title={ __( 'Advanced' ) }
initialOpen={ false }
>
<InspectorAdvancedControls.Slot bubblesVirtually />
</PanelBody>
) }
</div>
<SkipToSelectedBlock key="back" />
</div>
);
};
export default withSelect( ( select ) => {
const {
getSelectedBlockClientId,
getSelectedBlockCount,
getBlockName,
} = select( 'core/block-editor' );
const { getBlockStyles } = select( 'core/blocks' );
const selectedBlockClientId = getSelectedBlockClientId();
const selectedBlockName =
selectedBlockClientId && getBlockName( selectedBlockClientId );
const blockType =
selectedBlockClientId && getBlockType( selectedBlockName );
const blockStyles =
selectedBlockClientId && getBlockStyles( selectedBlockName );
return {
count: getSelectedBlockCount(),
hasBlockStyles: blockStyles && blockStyles.length > 0,
selectedBlockName,
selectedBlockClientId,
blockType,
};
} )( BlockInspector );