-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
213 lines (207 loc) · 5.84 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
/**
* WordPress dependencies
*/
import {
PreferencesModal,
PreferencesModalTabs,
PreferencesModalSection,
store as interfaceStore,
} from '@wordpress/interface';
import { useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';
import {
PostTaxonomies,
PostExcerptCheck,
PageAttributesCheck,
PostFeaturedImageCheck,
PostTypeSupportCheck,
store as editorStore,
} from '@wordpress/editor';
/**
* Internal dependencies
*/
import EnableFeature from './enable-feature';
import EnablePanelOption from './enable-panel-option';
import { store as editSiteStore } from '../../store';
export const PREFERENCES_MODAL_NAME = 'edit-site/preferences';
export default function EditSitePreferencesModal() {
const isModalActive = useSelect( ( select ) =>
select( interfaceStore ).isModalActive( PREFERENCES_MODAL_NAME )
);
const { closeModal, openModal } = useDispatch( interfaceStore );
const toggleModal = () =>
isModalActive ? closeModal() : openModal( PREFERENCES_MODAL_NAME );
const registry = useRegistry();
const { closeGeneralSidebar } = useDispatch( editSiteStore );
const { setIsListViewOpened, setIsInserterOpened } =
useDispatch( editorStore );
const { set: setPreference } = useDispatch( preferencesStore );
const toggleDistractionFree = () => {
registry.batch( () => {
setPreference( 'core', 'fixedToolbar', true );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
} );
};
const turnOffDistractionFree = () => {
setPreference( 'core/edit-site', 'distractionFree', false );
};
const sections = useMemo( () => [
{
name: 'general',
tabLabel: __( 'General' ),
content: (
<>
<PreferencesModalSection title={ __( 'Interface' ) }>
<EnableFeature
scope="core"
featureName="showListViewByDefault"
help={ __(
'Opens the block list view sidebar by default.'
) }
label={ __( 'Always open list view' ) }
/>
<EnableFeature
scope="core"
featureName="showBlockBreadcrumbs"
help={ __(
'Shows block breadcrumbs at the bottom of the editor.'
) }
label={ __( 'Display block breadcrumbs' ) }
/>
<EnableFeature
scope="core"
featureName="allowRightClickOverrides"
help={ __(
'Allows contextual list view menus via right-click, overriding browser defaults.'
) }
label={ __( 'Allow right-click contextual menus' ) }
/>
</PreferencesModalSection>
<PreferencesModalSection
title={ __( 'Document settings' ) }
description={ __(
'Select what settings are shown in the document panel.'
) }
>
<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>
</>
),
},
{
name: 'appearance',
tabLabel: __( 'Appearance' ),
content: (
<PreferencesModalSection
title={ __( 'Appearance' ) }
description={ __(
'Customize the editor interface to suit your needs.'
) }
>
<EnableFeature
featureName="fixedToolbar"
onToggle={ turnOffDistractionFree }
help={ __(
'Access all block and document tools in a single place.'
) }
label={ __( 'Top toolbar' ) }
/>
<EnableFeature
featureName="distractionFree"
onToggle={ toggleDistractionFree }
help={ __(
'Reduce visual distractions by hiding the toolbar and other elements to focus on writing.'
) }
label={ __( 'Distraction free' ) }
/>
<EnableFeature
scope="core"
featureName="focusMode"
help={ __(
'Highlights the current block and fades other content.'
) }
label={ __( 'Spotlight mode' ) }
/>
</PreferencesModalSection>
),
},
{
name: 'accessibility',
tabLabel: __( 'Accessibility' ),
content: (
<>
<PreferencesModalSection
title={ __( 'Navigation' ) }
description={ __(
'Optimize the editing experience for enhanced control.'
) }
>
<EnableFeature
scope="core"
featureName="keepCaretInsideBlock"
help={ __(
'Keeps the text cursor within the block boundaries, aiding users with screen readers by preventing unintentional cursor movement outside the block.'
) }
label={ __( 'Contain text cursor inside block' ) }
/>
</PreferencesModalSection>
<PreferencesModalSection title={ __( 'Interface' ) }>
<EnableFeature
scope="core"
featureName="showIconLabels"
label={ __( 'Show button text labels' ) }
help={ __(
'Show text instead of icons on buttons across the interface.'
) }
/>
</PreferencesModalSection>
</>
),
},
] );
if ( ! isModalActive ) {
return null;
}
return (
<PreferencesModal closeModal={ toggleModal }>
<PreferencesModalTabs sections={ sections } />
</PreferencesModal>
);
}