1 |
|
2 |
|
3 |
|
4 | import createSelector from 'rememo';
|
5 | import { get, includes, some, flatten, values } from 'lodash';
|
6 | /**
|
7 | * Returns the current editing mode.
|
8 | *
|
9 | * @param {Object} state Global application state.
|
10 | *
|
11 | * @return {string} Editing mode.
|
12 | */
|
13 |
|
14 | export function getEditorMode(state) {
|
15 | return getPreference(state, 'editorMode', 'visual');
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export function isEditorSidebarOpened(state) {
|
26 | var activeGeneralSidebar = getActiveGeneralSidebarName(state);
|
27 | return includes(['edit-post/document', 'edit-post/block'], activeGeneralSidebar);
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | export function isPluginSidebarOpened(state) {
|
37 | var activeGeneralSidebar = getActiveGeneralSidebarName(state);
|
38 | return !!activeGeneralSidebar && !isEditorSidebarOpened(state);
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | export function getActiveGeneralSidebarName(state) {
|
56 |
|
57 | var isDismissed = getPreference(state, 'isGeneralSidebarDismissed', false);
|
58 |
|
59 | if (isDismissed) {
|
60 | return null;
|
61 | }
|
62 |
|
63 | return state.activeGeneralSidebar;
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | export function getPreferences(state) {
|
74 | return state.preferences;
|
75 | }
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export function getPreference(state, preferenceKey, defaultValue) {
|
86 | var preferences = getPreferences(state);
|
87 | var value = preferences[preferenceKey];
|
88 | return value === undefined ? defaultValue : value;
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | export function isPublishSidebarOpened(state) {
|
99 | return state.publishSidebarActive;
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | export function isEditorPanelRemoved(state, panelName) {
|
112 | return includes(state.removedPanels, panelName);
|
113 | }
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | export function isEditorPanelEnabled(state, panelName) {
|
125 | var panels = getPreference(state, 'panels');
|
126 | return !isEditorPanelRemoved(state, panelName) && get(panels, [panelName, 'enabled'], true);
|
127 | }
|
128 | /**
|
129 | * Returns true if the given panel is open, or false otherwise. Panels are
|
130 | * closed by default.
|
131 | *
|
132 | * @param {Object} state Global application state.
|
133 | * @param {string} panelName A string that identifies the panel.
|
134 | *
|
135 | * @return {boolean} Whether or not the panel is open.
|
136 | */
|
137 |
|
138 | export function isEditorPanelOpened(state, panelName) {
|
139 | var panels = getPreference(state, 'panels');
|
140 | return panels[panelName] === true || get(panels, [panelName, 'opened'], false);
|
141 | }
|
142 | /**
|
143 | * Returns true if a modal is active, or false otherwise.
|
144 | *
|
145 | * @param {Object} state Global application state.
|
146 | * @param {string} modalName A string that uniquely identifies the modal.
|
147 | *
|
148 | * @return {boolean} Whether the modal is active.
|
149 | */
|
150 |
|
151 | export function isModalActive(state, modalName) {
|
152 | return state.activeModal === modalName;
|
153 | }
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | export function isFeatureActive(state, feature) {
|
164 | return !!state.preferences.features[feature];
|
165 | }
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | export function isPluginItemPinned(state, pluginName) {
|
177 | var pinnedPluginItems = getPreference(state, 'pinnedPluginItems', {});
|
178 | return get(pinnedPluginItems, [pluginName], true);
|
179 | }
|
180 | /**
|
181 | * Returns an array of active meta box locations.
|
182 | *
|
183 | * @param {Object} state Post editor state.
|
184 | *
|
185 | * @return {string[]} Active meta box locations.
|
186 | */
|
187 |
|
188 | export var getActiveMetaBoxLocations = createSelector(function (state) {
|
189 | return Object.keys(state.metaBoxes.locations).filter(function (location) {
|
190 | return isMetaBoxLocationActive(state, location);
|
191 | });
|
192 | }, function (state) {
|
193 | return [state.metaBoxes.locations];
|
194 | });
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 | export function isMetaBoxLocationVisible(state, location) {
|
205 | return isMetaBoxLocationActive(state, location) && some(getMetaBoxesPerLocation(state, location), function (_ref) {
|
206 | var id = _ref.id;
|
207 | return isEditorPanelEnabled(state, "meta-box-".concat(id));
|
208 | });
|
209 | }
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | export function isMetaBoxLocationActive(state, location) {
|
221 | var metaBoxes = getMetaBoxesPerLocation(state, location);
|
222 | return !!metaBoxes && metaBoxes.length !== 0;
|
223 | }
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 | export function getMetaBoxesPerLocation(state, location) {
|
234 | return state.metaBoxes.locations[location];
|
235 | }
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | export var getAllMetaBoxes = createSelector(function (state) {
|
245 | return flatten(values(state.metaBoxes.locations));
|
246 | }, function (state) {
|
247 | return [state.metaBoxes.locations];
|
248 | });
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 | export function hasMetaBoxes(state) {
|
258 | return getActiveMetaBoxLocations(state).length > 0;
|
259 | }
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 | export function isSavingMetaBoxes(state) {
|
269 | return state.metaBoxes.isSaving;
|
270 | }
|
271 |
|
\ | No newline at end of file |