-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
index.js
267 lines (255 loc) · 7.07 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
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
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import {
PostTaxonomies,
PostExcerptCheck,
PageAttributesCheck,
PostFeaturedImageCheck,
PostTypeSupportCheck,
store as editorStore,
} from '@wordpress/editor';
import {
PreferencesModal,
PreferencesModalTabs,
PreferencesModalSection,
store as interfaceStore,
} from '@wordpress/interface';
import { store as preferencesStore } from '@wordpress/preferences';
/**
* Internal dependencies
*/
import {
EnablePluginDocumentSettingPanelOption,
EnablePublishSidebarOption,
EnablePanelOption,
EnableFeature,
} from './options';
import MetaBoxesSection from './meta-boxes-section';
import { store as editPostStore } from '../../store';
import BlockManager from '../block-manager';
export const PREFERENCES_MODAL_NAME = 'edit-post/preferences';
export default function EditPostPreferencesModal() {
const isLargeViewport = useViewportMatch( 'medium' );
const { closeModal } = useDispatch( interfaceStore );
const [ isModalActive, showBlockBreadcrumbsOption ] = useSelect(
( select ) => {
const { getEditorSettings } = select( editorStore );
const { getEditorMode, isFeatureActive } = select( editPostStore );
const modalActive = select( interfaceStore ).isModalActive(
PREFERENCES_MODAL_NAME
);
const mode = getEditorMode();
const isRichEditingEnabled = getEditorSettings().richEditingEnabled;
const isDistractionFreeEnabled =
isFeatureActive( 'distractionFree' );
return [
modalActive,
! isDistractionFreeEnabled &&
isLargeViewport &&
isRichEditingEnabled &&
mode === 'visual',
isDistractionFreeEnabled,
];
},
[ isLargeViewport ]
);
const { closeGeneralSidebar, setIsListViewOpened, setIsInserterOpened } =
useDispatch( editPostStore );
const { set: setPreference } = useDispatch( preferencesStore );
const toggleDistractionFree = () => {
setPreference( 'core/edit-post', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
};
const sections = useMemo(
() => [
{
name: 'general',
tabLabel: __( 'General' ),
content: (
<>
{ isLargeViewport && (
<PreferencesModalSection
title={ __( 'Publishing' ) }
description={ __(
'Change options related to publishing.'
) }
>
<EnablePublishSidebarOption
help={ __(
'Review settings, such as visibility and tags.'
) }
label={ __(
'Include pre-publish checklist'
) }
/>
</PreferencesModalSection>
) }
<PreferencesModalSection
title={ __( 'Appearance' ) }
description={ __(
'Customize options related to the block editor interface and editing flow.'
) }
>
<EnableFeature
featureName="distractionFree"
onToggle={ toggleDistractionFree }
help={ __(
'Reduce visual distractions by hiding the toolbar and other elements to focus on writing.'
) }
label={ __( 'Distraction free' ) }
/>
<EnableFeature
featureName="focusMode"
help={ __(
'Highlights the current block and fades other content.'
) }
label={ __( 'Spotlight mode' ) }
/>
<EnableFeature
featureName="showIconLabels"
label={ __( 'Show button text labels' ) }
help={ __(
'Show text instead of icons on buttons.'
) }
/>
<EnableFeature
featureName="showListViewByDefault"
help={ __(
'Opens the block list view sidebar by default.'
) }
label={ __( 'Always open list view' ) }
/>
<EnableFeature
featureName="themeStyles"
help={ __(
'Make the editor look like your theme.'
) }
label={ __( 'Use theme styles' ) }
/>
{ showBlockBreadcrumbsOption && (
<EnableFeature
featureName="showBlockBreadcrumbs"
help={ __(
'Shows block breadcrumbs at the bottom of the editor.'
) }
label={ __( 'Display block breadcrumbs' ) }
/>
) }
</PreferencesModalSection>
</>
),
},
{
name: 'blocks',
tabLabel: __( 'Blocks' ),
content: (
<>
<PreferencesModalSection
title={ __( 'Block interactions' ) }
description={ __(
'Customize how you interact with blocks in the block library and editing canvas.'
) }
>
<EnableFeature
featureName="mostUsedBlocks"
help={ __(
'Places the most frequent blocks in the block library.'
) }
label={ __( 'Show most used blocks' ) }
/>
<EnableFeature
featureName="keepCaretInsideBlock"
help={ __(
'Aids screen readers by stopping text caret from leaving blocks.'
) }
label={ __(
'Contain text cursor inside block'
) }
/>
</PreferencesModalSection>
<PreferencesModalSection
title={ __( 'Visible blocks' ) }
description={ __(
"Disable blocks that you don't want to appear in the inserter. They can always be toggled back on later."
) }
>
<BlockManager />
</PreferencesModalSection>
</>
),
},
{
name: 'panels',
tabLabel: __( 'Panels' ),
content: (
<>
<PreferencesModalSection
title={ __( 'Document settings' ) }
description={ __(
'Choose what displays in the panel.'
) }
>
<EnablePluginDocumentSettingPanelOption.Slot />
<PostTaxonomies
taxonomyWrapper={ ( content, taxonomy ) => (
<EnablePanelOption
label={ taxonomy.labels.menu_name }
panelName={ `taxonomy-panel-${ taxonomy.slug }` }
/>
) }
/>
<PostFeaturedImageCheck>
<EnablePanelOption
label={ __( 'Featured image' ) }
panelName="featured-image"
/>
</PostFeaturedImageCheck>
<PostExcerptCheck>
<EnablePanelOption
label={ __( 'Excerpt' ) }
panelName="post-excerpt"
/>
</PostExcerptCheck>
<PostTypeSupportCheck
supportKeys={ [ 'comments', 'trackbacks' ] }
>
<EnablePanelOption
label={ __( 'Discussion' ) }
panelName="discussion-panel"
/>
</PostTypeSupportCheck>
<PageAttributesCheck>
<EnablePanelOption
label={ __( 'Page attributes' ) }
panelName="page-attributes"
/>
</PageAttributesCheck>
</PreferencesModalSection>
<MetaBoxesSection
title={ __( 'Additional' ) }
description={ __(
'Add extra areas to the editor.'
) }
/>
</>
),
},
],
[ isLargeViewport, showBlockBreadcrumbsOption ]
);
if ( ! isModalActive ) {
return null;
}
return (
<PreferencesModal closeModal={ closeModal }>
<PreferencesModalTabs sections={ sections } />
</PreferencesModal>
);
}