@bhsd/codemirror-mediawiki 2.7.1 → 2.7.3
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 +2 -2
- package/i18n/zh-hans.json +2 -2
- package/i18n/zh-hant.json +2 -2
- package/mediawiki.css +6 -1
- package/mw/README.md +8 -1
- package/mw/base.ts +1 -1
- package/mw/config.ts +8 -17
- package/mw/msg.ts +13 -3
- package/mw/openLinks.ts +36 -18
- package/mw/preference.ts +14 -12
- package/package.json +2 -2
package/mw/openLinks.ts
CHANGED
|
@@ -5,7 +5,6 @@ import type {CodeMirror} from './base';
|
|
|
5
5
|
declare type MouseEventListener = (e: MouseEvent) => void;
|
|
6
6
|
|
|
7
7
|
const modKey = isMac ? 'metaKey' : 'ctrlKey',
|
|
8
|
-
regex = /-template-name|-link-pagename/u,
|
|
9
8
|
handlers = new WeakMap<CodeMirror, MouseEventListener>();
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -18,6 +17,19 @@ function getName(node: SyntaxNode | null): string | undefined {
|
|
|
18
17
|
return node?.name.replace(/_+/gu, ' ').trim();
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
/**
|
|
21
|
+
* 查找连续同名节点
|
|
22
|
+
* @param node 起始节点
|
|
23
|
+
* @param dir 方向
|
|
24
|
+
* @param name 节点名称
|
|
25
|
+
*/
|
|
26
|
+
const search = (node: SyntaxNode, dir: 'prevSibling' | 'nextSibling', name = getName(node)): SyntaxNode => {
|
|
27
|
+
while (getName(node[dir]!) === name) {
|
|
28
|
+
node = node[dir]!; // eslint-disable-line no-param-reassign
|
|
29
|
+
}
|
|
30
|
+
return node;
|
|
31
|
+
};
|
|
32
|
+
|
|
21
33
|
/**
|
|
22
34
|
* 点击时在新页面打开链接、模板等
|
|
23
35
|
* @param cm
|
|
@@ -32,25 +44,31 @@ const getHandler = (cm: CodeMirror): MouseEventListener => {
|
|
|
32
44
|
return;
|
|
33
45
|
}
|
|
34
46
|
const {view} = cm,
|
|
47
|
+
{state} = view,
|
|
35
48
|
node = cm.getNodeAt(view.posAtCoords(e)!);
|
|
36
|
-
if (!node
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (!node) {
|
|
50
|
+
// pass
|
|
51
|
+
} else if (/-template-name|-link-pagename/u.test(node.name)) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
const name = getName(node);
|
|
54
|
+
let page = state.sliceDoc(
|
|
55
|
+
search(node, 'prevSibling', name).from,
|
|
56
|
+
search(node, 'nextSibling', name).to,
|
|
57
|
+
).trim();
|
|
58
|
+
if (page.startsWith('/')) {
|
|
59
|
+
page = `:${mw.config.get('wgPageName')}${page}`;
|
|
60
|
+
}
|
|
61
|
+
open(new mw.Title(page, name.includes('-template-name') ? 10 : 0).getUrl(undefined), '_blank');
|
|
62
|
+
} else if (/-extlink-protocol/u.test(node.name)) {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
open(state.sliceDoc(node.from, search(node.nextSibling!, 'nextSibling').to), '_blank');
|
|
65
|
+
} else if (/-extlink(?:_|$)/u.test(node.name)) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
const name = getName(node),
|
|
68
|
+
prev = search(node, 'prevSibling', name).prevSibling!,
|
|
69
|
+
next = search(node, 'nextSibling', name);
|
|
70
|
+
open(state.sliceDoc(prev.from, next.to), '_blank');
|
|
52
71
|
}
|
|
53
|
-
open(new mw.Title(page, name.includes('-template-name') ? 10 : 0).getUrl(undefined), '_blank');
|
|
54
72
|
};
|
|
55
73
|
handlers.set(cm, handler);
|
|
56
74
|
return handler;
|
package/mw/preference.ts
CHANGED
|
@@ -75,6 +75,16 @@ export 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 @@ export 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,
|
|
@@ -164,7 +165,7 @@ export const openPreference = async (editors: (CodeMirror | undefined)[]): Promi
|
|
|
164
165
|
$('<p>', {html: msg('feedback', 'codemirror-mediawiki')}),
|
|
165
166
|
);
|
|
166
167
|
panelWikilint.$element.append(
|
|
167
|
-
...rules.map(rule => {
|
|
168
|
+
...rules.filter(rule => rule !== 'table-layout').map(rule => {
|
|
168
169
|
const state = rule === 'no-arg' ? RuleState.off : RuleState.error,
|
|
169
170
|
dropdown = new OO.ui.DropdownInputWidget({
|
|
170
171
|
options: [
|
|
@@ -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) {
|
|
@@ -242,7 +244,7 @@ export const openPreference = async (editors: (CodeMirror | undefined)[]): Promi
|
|
|
242
244
|
}
|
|
243
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.3",
|
|
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",
|