-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Expand file tree
/
Copy pathindex.js
More file actions
287 lines (274 loc) · 8.14 KB
/
Copy pathindex.js
File metadata and controls
287 lines (274 loc) · 8.14 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { InterfaceSkeleton, ComplementaryArea } from '@wordpress/interface';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import {
BlockBreadcrumb,
BlockToolbar,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useViewportMatch } from '@wordpress/compose';
import { useState, useCallback } from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';
import { InlineNotices } from '@wordpress/notices';
/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import TemplateValidationNotice from '../template-validation-notice';
import Header from '../header';
import InserterSidebar from '../inserter-sidebar';
import ListViewSidebar from '../list-view-sidebar';
import { RevisionsHeader, RevisionsCanvas } from '../post-revisions-preview';
import { CollaboratorsOverlay } from '../collaborators-overlay';
import { useCollaboratorNotifications } from '../collaborators-presence/use-collaborator-notifications';
import SavePublishPanels from '../save-publish-panels';
import TextEditor from '../text-editor';
import VisualEditor from '../visual-editor';
import StylesCanvas from '../styles-canvas';
const interfaceLabels = {
/* translators: accessibility text for the editor top bar landmark region. */
header: __( 'Editor top bar' ),
/* translators: accessibility text for the editor content landmark region. */
body: __( 'Editor content' ),
/* translators: accessibility text for the editor settings landmark region. */
sidebar: __( 'Editor settings' ),
/* translators: accessibility text for the editor publish landmark region. */
actions: __( 'Editor publish' ),
/* translators: accessibility text for the editor footer landmark region. */
footer: __( 'Editor footer' ),
};
function Notices() {
const isValidTemplate = useSelect( ( select ) => {
return select( blockEditorStore ).isValidTemplate();
}, [] );
return (
<InlineNotices
className="editor-notices"
pinnedNoticesClassName="editor-notices__pinned"
dismissibleNoticesClassName="editor-notices__dismissible"
>
{ ! isValidTemplate && <TemplateValidationNotice /> }
</InlineNotices>
);
}
export default function EditorInterface( {
className,
children,
forceIsDirty,
contentRef,
disableIframe,
autoFocus,
customSaveButton,
customSavePanel,
forceDisableBlockTools,
iframeProps,
} ) {
const {
mode,
postId,
postType,
isInserterOpened,
isListViewOpened,
isDistractionFree,
isPreviewMode,
showBlockBreadcrumbs,
postTypeLabel,
stylesPath,
showStylebook,
isRevisionsMode,
showDiff,
} = useSelect( ( select ) => {
const { get } = select( preferencesStore );
const {
getEditorSettings,
getPostTypeLabel,
getCurrentPostType,
getCurrentPostId,
} = select( editorStore );
const {
getStylesPath,
getShowStylebook,
isRevisionsMode: _isRevisionsMode,
isShowingRevisionDiff,
} = unlock( select( editorStore ) );
const editorSettings = getEditorSettings();
let _mode = select( editorStore ).getEditorMode();
if ( ! editorSettings.richEditingEnabled && _mode === 'visual' ) {
_mode = 'text';
}
if ( ! editorSettings.codeEditingEnabled && _mode === 'text' ) {
_mode = 'visual';
}
return {
mode: _mode,
postId: getCurrentPostId(),
postType: getCurrentPostType(),
isInserterOpened: select( editorStore ).isInserterOpened(),
isListViewOpened: select( editorStore ).isListViewOpened(),
isDistractionFree: get( 'core', 'distractionFree' ),
isPreviewMode: editorSettings.isPreviewMode,
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
postTypeLabel: getPostTypeLabel(),
stylesPath: getStylesPath(),
showStylebook: getShowStylebook(),
isRevisionsMode: _isRevisionsMode(),
showDiff: isShowingRevisionDiff(),
};
}, [] );
const { setShowRevisionDiff } = unlock( useDispatch( editorStore ) );
// Runs unconditionally so join/leave/save notifications are dispatched
// regardless of viewport width or whether the header centre area is visible.
useCollaboratorNotifications( postId, postType );
const isLargeViewport = useViewportMatch( 'medium' );
const secondarySidebarLabel = isListViewOpened
? __( 'Document Overview' )
: __( 'Block Library' );
const shouldShowStylesCanvas =
showStylebook || stylesPath?.startsWith( '/revisions' );
const shouldShowBlockEditor = ! shouldShowStylesCanvas;
// Local state for save panel.
// Note 'truthy' callback implies an open panel.
const [ entitiesSavedStatesCallback, setEntitiesSavedStatesCallback ] =
useState( false );
const closeEntitiesSavedStates = useCallback(
( arg ) => {
if ( typeof entitiesSavedStatesCallback === 'function' ) {
entitiesSavedStatesCallback( arg );
}
setEntitiesSavedStatesCallback( false );
},
[ entitiesSavedStatesCallback ]
);
// When in revisions mode, render the revisions interface.
if ( isRevisionsMode ) {
return (
<InterfaceSkeleton
className={ clsx( 'editor-editor-interface', className ) }
labels={ interfaceLabels }
header={
<RevisionsHeader
showDiff={ showDiff }
onToggleDiff={ () => setShowRevisionDiff( ! showDiff ) }
/>
}
content={ <RevisionsCanvas /> }
sidebar={ <ComplementaryArea.Slot scope="core" /> }
/>
);
}
return (
<InterfaceSkeleton
isDistractionFree={ isDistractionFree }
className={ clsx( 'editor-editor-interface', className, {
'is-entity-save-view-open': !! entitiesSavedStatesCallback,
'is-distraction-free': isDistractionFree && ! isPreviewMode,
} ) }
labels={ {
...interfaceLabels,
secondarySidebar: secondarySidebarLabel,
} }
header={
! isPreviewMode && (
<Header
forceIsDirty={ forceIsDirty }
setEntitiesSavedStatesCallback={
setEntitiesSavedStatesCallback
}
customSaveButton={ customSaveButton }
forceDisableBlockTools={ forceDisableBlockTools }
/>
)
}
editorNotices={ <Notices /> }
secondarySidebar={
! isPreviewMode &&
mode === 'visual' &&
( ( isInserterOpened && <InserterSidebar /> ) ||
( isListViewOpened && <ListViewSidebar /> ) )
}
sidebar={
! isPreviewMode &&
! isDistractionFree && <ComplementaryArea.Slot scope="core" />
}
content={
<>
{ ! isDistractionFree && ! isPreviewMode && <Notices /> }
{ shouldShowStylesCanvas && <StylesCanvas /> }
{ shouldShowBlockEditor && (
<>
{ ! isPreviewMode && mode === 'text' && (
<TextEditor
// We should auto-focus the canvas (title) on load.
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ autoFocus }
/>
) }
{ ! isPreviewMode &&
! isLargeViewport &&
mode === 'visual' && (
<BlockToolbar hideDragHandle />
) }
{ ( isPreviewMode || mode === 'visual' ) && (
<VisualEditor
contentRef={ contentRef }
disableIframe={ disableIframe }
// We should auto-focus the canvas (title) on load.
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ autoFocus }
iframeProps={ iframeProps }
/>
) }
{ children }
<CollaboratorsOverlay
postId={ postId }
postType={ postType }
/>
</>
) }
</>
}
footer={
! isPreviewMode &&
! isDistractionFree &&
isLargeViewport &&
showBlockBreadcrumbs &&
mode === 'visual' && (
<BlockBreadcrumb
rootLabelText={
postTypeLabel
? decodeEntities( postTypeLabel )
: undefined
}
/>
)
}
actions={
! isPreviewMode
? customSavePanel || (
<SavePublishPanels
closeEntitiesSavedStates={
closeEntitiesSavedStates
}
isEntitiesSavedStatesOpen={
entitiesSavedStatesCallback
}
setEntitiesSavedStatesCallback={
setEntitiesSavedStatesCallback
}
forceIsDirtyPublishPanel={ forceIsDirty }
/>
)
: undefined
}
/>
);
}