-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
initState.js
73 lines (66 loc) · 2.58 KB
/
initState.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
/**
* This file is part of Feather Wiki.
*
* Feather Wiki is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Feather Wiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with Feather Wiki. If not, see https://www.gnu.org/licenses/.
*/
import { pagesView } from './views/pages';
import { settingsView } from './views/settings';
import { taggedView } from './views/tagged';
import { pageView } from './views/page';
import { missingView } from './views/missing';
export const initState = state => {
state.root = location.pathname || '/'; // path to file
state.sb = false; // show sidebar
state.sbTab = '{{translate:pagesTab}}';
state.sbx = new Set(); // expanded sidebar menu items
state.recent = [];
state.edit = false;
state.edits = null; // Edit store
state.keep = false; // Keep Editor, Prevent navigation if editing
state.src = false; // Show HTML in editor
state.notis = {}; // Notifications
state.canPut = false; // Show "Save Wiki to Server" button
state.events = {
...state.events,
HANDLE_404: '404',
CREATE_PAGE: 'cp',
START_EDIT: 'se',
CANCEL_EDIT: 'ce',
UPDATE_PAGE: 'up',
DELETE_PAGE: 'dp',
COLLECT_TAGS: 'ct',
CHECK_CHANGED: 'cc',
SAVE_WIKI: 'sw',
NOTIFY: 'n',
REMOVE_NOTI: 'rn',
PUT_SAVE_WIKI: 'psw',
DETECT_PUT_SUPPORT: 'dps',
};
state.views = {
a: pagesView,
s: settingsView,
t: taggedView,
p: pageView,
m: missingView
};
state.c = document.querySelector('style#c')?.innerHTML ?? '';
state.j = FW.parseJs(document.querySelector('script#j')?.innerHTML ?? '');
try {
state.p = FW.json.decompress(JSON.parse(document.querySelector('script#p').innerHTML));
} catch (e) {
state.p = {name:'{{translate:newWiki}}',desc:'',pages:[],img:{}};
}
state.pg = FW.getPage();
// determine last-used editor
const lastModified = state.p.pages.find(p => p.id === state.recent[0]?.p);
state.useMd = lastModified?.editor === 'md';
state.t = []; // all used tags
state.prev = FW.hash.object(state.p); // Hash of state at last save
state.now = state.prev; // Hash of current state
state.changed = false; // Changed since last save?
return state;
}