@bhsd/codemirror-mediawiki 2.7.0 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codemirror.d.ts +18 -0
- package/dist/main.min.js +11 -11
- package/dist/mw.min.js +1 -1
- package/dist/mw.min.js.map +3 -3
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/mw/README.md +7 -0
- package/mw/base.ts +5 -4
- package/mw/config.ts +8 -17
- package/mw/msg.ts +1 -1
- package/mw/preference.ts +28 -26
- package/package.json +2 -2
package/mw/preference.ts
CHANGED
|
@@ -59,7 +59,7 @@ const api = (async () => {
|
|
|
59
59
|
return undefined;
|
|
60
60
|
})();
|
|
61
61
|
|
|
62
|
-
const loadJSON = (async () => {
|
|
62
|
+
export const loadJSON = (async () => {
|
|
63
63
|
if (!user) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
@@ -75,6 +75,16 @@ const loadJSON = (async () => {
|
|
|
75
75
|
const {query: {pages: [page]}} = res as MediaWikiResponse;
|
|
76
76
|
if (page?.revisions) {
|
|
77
77
|
const json: Preferences = JSON.parse(page.revisions[0]!.content);
|
|
78
|
+
if (!json.addons?.includes('save')) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
prefs.clear();
|
|
82
|
+
for (const option of json.addons) {
|
|
83
|
+
prefs.add(option);
|
|
84
|
+
}
|
|
85
|
+
if (json.indent) {
|
|
86
|
+
localStorage.setItem(indentKey, json.indent);
|
|
87
|
+
}
|
|
78
88
|
for (const key of codeKeys) {
|
|
79
89
|
if (json[key]) {
|
|
80
90
|
codeConfigs.set(key, json[key]);
|
|
@@ -83,15 +93,6 @@ const loadJSON = (async () => {
|
|
|
83
93
|
if (json.wikilint) {
|
|
84
94
|
Object.assign(wikilintConfig, json.wikilint);
|
|
85
95
|
}
|
|
86
|
-
if (json.addons) {
|
|
87
|
-
prefs.clear();
|
|
88
|
-
for (const option of json.addons) {
|
|
89
|
-
prefs.add(option);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (json.indent) {
|
|
93
|
-
localStorage.setItem(indentKey, json.indent);
|
|
94
|
-
}
|
|
95
96
|
}
|
|
96
97
|
},
|
|
97
98
|
apiErr,
|
|
@@ -193,7 +194,8 @@ export const openPreference = async (editors: (CodeMirror | undefined)[]): Promi
|
|
|
193
194
|
}).closing as unknown as Promise<{action?: unknown} | undefined>);
|
|
194
195
|
if (typeof data === 'object' && data.action === 'accept') {
|
|
195
196
|
// 缩进
|
|
196
|
-
const oldIndent = indent
|
|
197
|
+
const oldIndent = indent,
|
|
198
|
+
save = prefs.has('save');
|
|
197
199
|
indent = indentWidget.getValue(); // eslint-disable-line require-atomic-updates
|
|
198
200
|
let changed = indent !== oldIndent;
|
|
199
201
|
if (changed) {
|
|
@@ -203,20 +205,6 @@ export const openPreference = async (editors: (CodeMirror | undefined)[]): Promi
|
|
|
203
205
|
localStorage.setItem(indentKey, indent);
|
|
204
206
|
}
|
|
205
207
|
|
|
206
|
-
// 插件
|
|
207
|
-
const value = widget.getValue() as unknown as string[];
|
|
208
|
-
if (value.length !== prefs.size || !value.every(option => prefs.has(option))) {
|
|
209
|
-
changed = true;
|
|
210
|
-
prefs.clear();
|
|
211
|
-
for (const option of value) {
|
|
212
|
-
prefs.add(option);
|
|
213
|
-
}
|
|
214
|
-
for (const cm of editors) {
|
|
215
|
-
cm?.prefer(value);
|
|
216
|
-
}
|
|
217
|
-
setObject(storageKey, value);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
208
|
// WikiLint
|
|
221
209
|
for (const [rule, dropdown] of wikilintWidgets) {
|
|
222
210
|
const val = dropdown.getValue() as RuleState;
|
|
@@ -241,8 +229,22 @@ export const openPreference = async (editors: (CodeMirror | undefined)[]): Promi
|
|
|
241
229
|
void OO.ui.alert(msg('json-error', jsonErrors.join(msg('and'))));
|
|
242
230
|
}
|
|
243
231
|
|
|
232
|
+
// 插件
|
|
233
|
+
const value = widget.getValue() as unknown as string[];
|
|
234
|
+
if (value.length !== prefs.size || !value.every(option => prefs.has(option))) {
|
|
235
|
+
changed = true;
|
|
236
|
+
prefs.clear();
|
|
237
|
+
for (const option of value) {
|
|
238
|
+
prefs.add(option);
|
|
239
|
+
}
|
|
240
|
+
for (const cm of editors) {
|
|
241
|
+
cm?.prefer(value);
|
|
242
|
+
}
|
|
243
|
+
setObject(storageKey, value);
|
|
244
|
+
}
|
|
245
|
+
|
|
244
246
|
// 保存至用户子页面
|
|
245
|
-
if (changed && user && prefs.has('save')) {
|
|
247
|
+
if (changed && user && (save || prefs.has('save'))) {
|
|
246
248
|
const params: ApiEditPageParams = {
|
|
247
249
|
action: 'edit',
|
|
248
250
|
title: userPage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-mediawiki",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@codemirror/state": "^6.4.1",
|
|
54
54
|
"@codemirror/view": "^6.24.1",
|
|
55
55
|
"@lezer/highlight": "^1.2.0",
|
|
56
|
-
"wikiparser-node": "^1.5.
|
|
56
|
+
"wikiparser-node": "^1.5.6"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@lezer/common": "^1.1.2",
|