1
- /**
2
- * External dependencies
3
- */
4
- import classnames from 'classnames' ;
5
-
6
1
/**
7
2
* WordPress dependencies
8
3
*/
9
4
import { sprintf , __ } from '@wordpress/i18n' ;
5
+ import { useDispatch } from '@wordpress/data' ;
10
6
import {
11
- __experimentalGetBlockLabel as getBlockLabel ,
12
- getBlockType ,
13
- } from '@wordpress/blocks' ;
14
- import { useSelect } from '@wordpress/data' ;
15
- import {
16
- Dropdown ,
17
7
Button ,
18
8
VisuallyHidden ,
19
9
__experimentalText as Text ,
10
+ __experimentalHStack as HStack ,
20
11
} from '@wordpress/components' ;
21
- import { chevronDown } from '@wordpress/icons' ;
22
- import { useState , useMemo } from '@wordpress/element' ;
23
- import {
24
- store as blockEditorStore ,
25
- useBlockDisplayInformation ,
26
- BlockIcon ,
27
- } from '@wordpress/block-editor' ;
28
- import { store as preferencesStore } from '@wordpress/preferences' ;
12
+ import { BlockIcon } from '@wordpress/block-editor' ;
13
+ import { privateApis as commandsPrivateApis } from '@wordpress/commands' ;
29
14
30
15
/**
31
16
* Internal dependencies
32
17
*/
33
- import TemplateDetails from '../../template-details' ;
34
18
import useEditedEntityRecord from '../../use-edited-entity-record' ;
19
+ import { unlock } from '../../../private-apis' ;
35
20
36
- function getBlockDisplayText ( block ) {
37
- if ( block ) {
38
- const blockType = getBlockType ( block . name ) ;
39
- return blockType ? getBlockLabel ( blockType , block . attributes ) : null ;
40
- }
41
- return null ;
42
- }
43
-
44
- function useSecondaryText ( ) {
45
- const { getBlock } = useSelect ( blockEditorStore ) ;
46
- const activeEntityBlockId = useSelect (
47
- ( select ) =>
48
- select (
49
- blockEditorStore
50
- ) . __experimentalGetActiveBlockIdByBlockNames ( [
51
- 'core/template-part' ,
52
- ] ) ,
53
- [ ]
54
- ) ;
55
-
56
- const blockInformation = useBlockDisplayInformation ( activeEntityBlockId ) ;
57
-
58
- if ( activeEntityBlockId ) {
59
- return {
60
- label : getBlockDisplayText ( getBlock ( activeEntityBlockId ) ) ,
61
- isActive : true ,
62
- icon : blockInformation ?. icon ,
63
- } ;
64
- }
65
-
66
- return { } ;
67
- }
21
+ const { store : commandsStore } = unlock ( commandsPrivateApis ) ;
68
22
69
23
export default function DocumentActions ( ) {
70
- const showIconLabels = useSelect (
71
- ( select ) =>
72
- select ( preferencesStore ) . get (
73
- 'core/edit-site' ,
74
- 'showIconLabels'
75
- ) ,
76
- [ ]
77
- ) ;
78
- const { isLoaded, record, getTitle } = useEditedEntityRecord ( ) ;
79
- const { label, icon } = useSecondaryText ( ) ;
80
-
81
- // Use internal state instead of a ref to make sure that the component
82
- // re-renders when the popover's anchor updates.
83
- const [ popoverAnchor , setPopoverAnchor ] = useState ( null ) ;
84
-
85
- // Memoize popoverProps to avoid returning a new object every time.
86
- const popoverProps = useMemo (
87
- ( ) => ( {
88
- // Use the title wrapper as the popover anchor so that the dropdown is
89
- // centered over the whole title area rather than just one part of it.
90
- anchor : popoverAnchor ,
91
- placement : 'bottom' ,
92
- } ) ,
93
- [ popoverAnchor ]
94
- ) ;
24
+ const { open : openCommandCenter } = useDispatch ( commandsStore ) ;
25
+ const { isLoaded, record, getTitle, icon } = useEditedEntityRecord ( ) ;
95
26
96
27
// Return a simple loading indicator until we have information to show.
97
28
if ( ! isLoaded ) {
98
- return (
99
- < div className = "edit-site-document-actions" >
100
- { __ ( 'Loading…' ) }
101
- </ div >
102
- ) ;
29
+ return null ;
103
30
}
104
31
105
32
// Return feedback that the template does not seem to exist.
106
33
if ( ! record ) {
107
34
return (
108
35
< div className = "edit-site-document-actions" >
109
- { __ ( 'Template not found' ) }
36
+ { __ ( 'Document not found' ) }
110
37
</ div >
111
38
) ;
112
39
}
@@ -116,21 +43,21 @@ export default function DocumentActions() {
116
43
? __ ( 'template part' )
117
44
: __ ( 'template' ) ;
118
45
46
+ const isMac = / M a c | i P o d | i P h o n e | i P a d / . test ( window . navigator . platform ) ;
47
+
119
48
return (
120
- < div
121
- className = { classnames ( 'edit-site-document-actions' , {
122
- 'has-secondary-label' : ! ! label ,
123
- } ) }
49
+ < Button
50
+ className = "edit-site-document-actions"
51
+ onClick = { ( ) => openCommandCenter ( ) }
124
52
>
125
- < div
126
- ref = { setPopoverAnchor }
127
- className = "edit-site-document-actions__title-wrapper"
53
+ < span className = "edit-site-document-actions__left" > </ span >
54
+ < HStack
55
+ spacing = { 1 }
56
+ justify = "center"
57
+ className = "edit-site-document-actions__title"
128
58
>
129
- < Text
130
- size = "body"
131
- className = "edit-site-document-actions__title"
132
- as = "h1"
133
- >
59
+ < BlockIcon icon = { icon } />
60
+ < Text size = "body" as = "h1" >
134
61
< VisuallyHidden as = "span" >
135
62
{ sprintf (
136
63
/* translators: %s: the entity being edited, like "template"*/
@@ -140,39 +67,10 @@ export default function DocumentActions() {
140
67
</ VisuallyHidden >
141
68
{ getTitle ( ) }
142
69
</ Text >
143
- < div className = "edit-site-document-actions__secondary-item" >
144
- < BlockIcon icon = { icon } showColors />
145
- < Text size = "body" > { label ?? '' } </ Text >
146
- </ div >
147
-
148
- < Dropdown
149
- popoverProps = { popoverProps }
150
- renderToggle = { ( { isOpen, onToggle } ) => (
151
- < Button
152
- className = "edit-site-document-actions__get-info"
153
- icon = { chevronDown }
154
- aria-expanded = { isOpen }
155
- aria-haspopup = "true"
156
- onClick = { onToggle }
157
- variant = { showIconLabels ? 'tertiary' : undefined }
158
- label = { sprintf (
159
- /* translators: %s: the entity to see details about, like "template"*/
160
- __ ( 'Show %s details' ) ,
161
- entityLabel
162
- ) }
163
- >
164
- { showIconLabels && __ ( 'Details' ) }
165
- </ Button >
166
- ) }
167
- contentClassName = "edit-site-document-actions__info-dropdown"
168
- renderContent = { ( { onClose } ) => (
169
- < TemplateDetails
170
- template = { record }
171
- onClose = { onClose }
172
- />
173
- ) }
174
- />
175
- </ div >
176
- </ div >
70
+ </ HStack >
71
+ < span className = "edit-site-document-actions__shortcut" >
72
+ { isMac ? '⌘' : 'Ctrl' } K
73
+ </ span >
74
+ </ Button >
177
75
) ;
178
76
}
0 commit comments