-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
76 lines (68 loc) · 1.93 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
/**
* WordPress dependencies
*/
import { sprintf, __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import {
Button,
VisuallyHidden,
__experimentalText as Text,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { BlockIcon } from '@wordpress/block-editor';
import { privateApis as commandsPrivateApis } from '@wordpress/commands';
/**
* Internal dependencies
*/
import useEditedEntityRecord from '../../use-edited-entity-record';
import { unlock } from '../../../private-apis';
const { store: commandsStore } = unlock( commandsPrivateApis );
export default function DocumentActions() {
const { open: openCommandCenter } = useDispatch( commandsStore );
const { isLoaded, record, getTitle, icon } = useEditedEntityRecord();
// Return a simple loading indicator until we have information to show.
if ( ! isLoaded ) {
return null;
}
// Return feedback that the template does not seem to exist.
if ( ! record ) {
return (
<div className="edit-site-document-actions">
{ __( 'Document not found' ) }
</div>
);
}
const entityLabel =
record.type === 'wp_template_part'
? __( 'template part' )
: __( 'template' );
const isMac = /Mac|iPod|iPhone|iPad/.test( window.navigator.platform );
return (
<Button
className="edit-site-document-actions"
onClick={ () => openCommandCenter() }
>
<span className="edit-site-document-actions__left"></span>
<HStack
spacing={ 1 }
justify="center"
className="edit-site-document-actions__title"
>
<BlockIcon icon={ icon } />
<Text size="body" as="h1">
<VisuallyHidden as="span">
{ sprintf(
/* translators: %s: the entity being edited, like "template"*/
__( 'Editing %s: ' ),
entityLabel
) }
</VisuallyHidden>
{ getTitle() }
</Text>
</HStack>
<span className="edit-site-document-actions__shortcut">
{ isMac ? '⌘' : 'Ctrl' } K
</span>
</Button>
);
}