-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
185 lines (169 loc) · 4.72 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useReducedMotion } from '@wordpress/compose';
import { store as coreStore } from '@wordpress/core-data';
import {
__experimentalPreviewOptions as PreviewOptions,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { PinnedItems } from '@wordpress/interface';
import { __ } from '@wordpress/i18n';
import { external } from '@wordpress/icons';
import {
__unstableMotion as motion,
MenuGroup,
MenuItem,
VisuallyHidden,
} from '@wordpress/components';
import { store as preferencesStore } from '@wordpress/preferences';
/**
* Internal dependencies
*/
import MoreMenu from './more-menu';
import SaveButton from '../save-button';
import DocumentActions from './document-actions';
import DocumentTools from './document-tools';
import { store as editSiteStore } from '../../store';
import {
getEditorCanvasContainerTitle,
useHasEditorCanvasContainer,
} from '../editor-canvas-container';
import { unlock } from '../../lock-unlock';
import { FOCUSABLE_ENTITIES } from '../../utils/constants';
export default function HeaderEditMode( { setListViewToggleElement } ) {
const {
deviceType,
templateType,
isDistractionFree,
blockEditorMode,
homeUrl,
showIconLabels,
editorCanvasView,
} = useSelect( ( select ) => {
const { __experimentalGetPreviewDeviceType, getEditedPostType } =
select( editSiteStore );
const { __unstableGetEditorMode } = select( blockEditorStore );
const postType = getEditedPostType();
const {
getUnstableBase, // Site index.
} = select( coreStore );
const { get: getPreference } = select( preferencesStore );
return {
deviceType: __experimentalGetPreviewDeviceType(),
templateType: postType,
blockEditorMode: __unstableGetEditorMode(),
homeUrl: getUnstableBase()?.home,
showIconLabels: getPreference(
editSiteStore.name,
'showIconLabels'
),
editorCanvasView: unlock(
select( editSiteStore )
).getEditorCanvasContainerView(),
isDistractionFree: getPreference(
editSiteStore.name,
'distractionFree'
),
};
}, [] );
const { __experimentalSetPreviewDeviceType: setPreviewDeviceType } =
useDispatch( editSiteStore );
const disableMotion = useReducedMotion();
const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer();
const isFocusMode = FOCUSABLE_ENTITIES.includes( templateType );
const isZoomedOutView = blockEditorMode === 'zoom-out';
const toolbarVariants = {
isDistractionFree: { y: '-50px' },
isDistractionFreeHovering: { y: 0 },
view: { y: 0 },
edit: { y: 0 },
};
const toolbarTransition = {
type: 'tween',
duration: disableMotion ? 0 : 0.2,
ease: 'easeOut',
};
return (
<div
className={ classnames( 'edit-site-header-edit-mode', {
'show-icon-labels': showIconLabels,
} ) }
>
{ hasDefaultEditorCanvasView && (
<motion.div
variants={ toolbarVariants }
transition={ toolbarTransition }
>
<DocumentTools
blockEditorMode={ blockEditorMode }
isDistractionFree={ isDistractionFree }
showIconLabels={ showIconLabels }
setListViewToggleElement={ setListViewToggleElement }
/>
</motion.div>
) }
{ ! isDistractionFree && (
<div className="edit-site-header-edit-mode__center">
{ ! hasDefaultEditorCanvasView ? (
getEditorCanvasContainerTitle( editorCanvasView )
) : (
<DocumentActions />
) }
</div>
) }
<div className="edit-site-header-edit-mode__end">
<motion.div
className="edit-site-header-edit-mode__actions"
variants={ toolbarVariants }
transition={ toolbarTransition }
>
<div
className={ classnames(
'edit-site-header-edit-mode__preview-options',
{ 'is-zoomed-out': isZoomedOutView }
) }
>
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
label={ __( 'View' ) }
isEnabled={
! isFocusMode && hasDefaultEditorCanvasView
}
>
{ ( { onClose } ) => (
<MenuGroup>
<MenuItem
href={ homeUrl }
target="_blank"
icon={ external }
onClick={ onClose }
>
{ __( 'View site' ) }
<VisuallyHidden as="span">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</VisuallyHidden>
</MenuItem>
</MenuGroup>
) }
</PreviewOptions>
</div>
<SaveButton />
{ ! isDistractionFree && (
<PinnedItems.Slot scope="core/edit-site" />
) }
<MoreMenu showIconLabels={ showIconLabels } />
</motion.div>
</div>
</div>
);
}