wikiplus-highlight 3.0.8 → 3.1.0
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/main.js +85 -53
- package/package.json +2 -1
package/dist/main.js
CHANGED
|
@@ -9,19 +9,23 @@
|
|
|
9
9
|
if (wphl === null || wphl === void 0 ? void 0 : wphl.version) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const version = '3.0
|
|
13
|
-
libs.wphl = { version, cmVersion: '2.9', ...wphl }; // 开始加载
|
|
12
|
+
const version = '3.1.0';
|
|
13
|
+
libs.wphl = { version, cmVersion: '2.9', monacoVersion: '0.2.2', ...wphl }; // 开始加载
|
|
14
14
|
// 路径
|
|
15
|
-
const CDN = '//testingcf.jsdelivr.net', MW_CDN = `npm/@bhsd/codemirror-mediawiki@${libs.wphl.cmVersion || 'latest'}/dist/mw.min.js`, REPO_CDN = 'npm/wikiplus-highlight';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
const CDN = '//testingcf.jsdelivr.net', MW_CDN = `npm/@bhsd/codemirror-mediawiki@${libs.wphl.cmVersion || 'latest'}/dist/mw.min.js`, MONACO_CDN = `npm/monaco-wiki@${libs.wphl.monacoVersion || 'latest'}/dist/mw.min.js`, REPO_CDN = 'npm/wikiplus-highlight';
|
|
16
|
+
const useMonaco = wphl === null || wphl === void 0 ? void 0 : wphl.useMonaco;
|
|
17
|
+
if (useMonaco) {
|
|
18
|
+
window.MonacoWikiEditor || (window.MonacoWikiEditor = (async () => {
|
|
19
|
+
await $.ajax(`${CDN}/${MONACO_CDN}`, { dataType: 'script', scriptAttrs: { type: 'module' } });
|
|
20
|
+
return MonacoWikiEditor;
|
|
21
|
+
})());
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
window.CodeMirror6 || (window.CodeMirror6 = (async () => {
|
|
25
|
+
await $.ajax(`${CDN}/${MW_CDN}`, { dataType: 'script', scriptAttrs: { type: 'module' } });
|
|
26
|
+
return CodeMirror6;
|
|
27
|
+
})());
|
|
28
|
+
}
|
|
25
29
|
const { wgPageName: page, wgNamespaceNumber: ns, wgPageContentModel: contentmodel, } = mw.config.get();
|
|
26
30
|
const CONTENTMODELS = {
|
|
27
31
|
'sanitized-css': 'css',
|
|
@@ -89,56 +93,84 @@
|
|
|
89
93
|
}
|
|
90
94
|
return [ns === 274 ? 'html' : 'lua'];
|
|
91
95
|
};
|
|
96
|
+
const submit = /** 提交编辑 */ () => {
|
|
97
|
+
document.getElementById('Wikiplus-Quickedit-Submit').dispatchEvent(new MouseEvent('click'));
|
|
98
|
+
return true;
|
|
99
|
+
}, submitMinor = /** 提交小编辑 */ () => {
|
|
100
|
+
document.querySelector('#Wikiplus-Quickedit-MinorEdit').checked = true;
|
|
101
|
+
return submit();
|
|
102
|
+
}, escapeEdit = /** 按下Esc键退出编辑 */ () => {
|
|
103
|
+
document.getElementById('Wikiplus-Quickedit-Back').dispatchEvent(new MouseEvent('click'));
|
|
104
|
+
return true;
|
|
105
|
+
};
|
|
92
106
|
/**
|
|
93
107
|
* 渲染编辑器
|
|
94
108
|
* @param $target 目标编辑框
|
|
95
109
|
* @param setting 是否是Wikiplus设置(使用json语法)
|
|
96
110
|
*/
|
|
97
111
|
const renderEditor = async ($target, setting) => {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
const settings = getObject('Wikiplus_Settings'), escToExitQuickEdit = settings && (settings['esc_to_exit_quickedit'] || settings['escToExitQuickEdit']);
|
|
113
|
+
if (useMonaco) {
|
|
114
|
+
const lang = setting ? 'json' : (await getPageMode($target.val()))[0], { editor } = await (await MonacoWikiEditor).fromTextArea($target[0], lang);
|
|
115
|
+
editor.getDomNode().id = 'Wikiplus-CodeMirror';
|
|
116
|
+
if (!setting) { // 普通Wikiplus编辑区
|
|
117
|
+
editor.onKeyUp(e => {
|
|
118
|
+
if (e.keyCode === 49 && (e.ctrlKey || e.metaKey)) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
if (e.shiftKey) {
|
|
121
|
+
submitMinor();
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
submit();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else if (e.keyCode === 9
|
|
128
|
+
&& (escToExitQuickEdit === true || escToExitQuickEdit === 'true')) {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
escapeEdit();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
119
134
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
else {
|
|
136
|
+
const cm = await (await CodeMirror6).fromTextArea($target[0], ...setting ? ['json'] : await getPageMode($target.val()));
|
|
137
|
+
cm.view.dom.id = 'Wikiplus-CodeMirror';
|
|
138
|
+
if (!setting) { // 普通Wikiplus编辑区
|
|
139
|
+
cm.extraKeys([
|
|
140
|
+
{ key: 'Mod-S', run: submit },
|
|
141
|
+
{ key: 'Shift-Mod-S', run: submitMinor },
|
|
142
|
+
...escToExitQuickEdit === true || escToExitQuickEdit === 'true'
|
|
143
|
+
? [{ key: 'Esc', run: escapeEdit }]
|
|
144
|
+
: [],
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
/** @todo 以下过渡代码添加于2024-02-07,将于一段时间后弃用 */
|
|
148
|
+
const oldKey = 'Wikiplus-highlight-addons', oldPrefs = getObject(oldKey), mapping = {
|
|
149
|
+
activeLine: 'highlightActiveLine',
|
|
150
|
+
trailingspace: 'highlightTrailingWhitespace',
|
|
151
|
+
matchBrackets: 'bracketMatching',
|
|
152
|
+
closeBrackets: 'closeBrackets',
|
|
153
|
+
matchTags: 'tagMatching',
|
|
154
|
+
fold: 'codeFolding',
|
|
155
|
+
wikiEditor: 'wikiEditor',
|
|
156
|
+
escape: 'escape',
|
|
157
|
+
contextmenu: 'openLinks',
|
|
158
|
+
lint: 'lint',
|
|
159
|
+
};
|
|
160
|
+
localStorage.removeItem(oldKey);
|
|
161
|
+
if (oldPrefs) {
|
|
162
|
+
const obj = {};
|
|
163
|
+
for (const k of oldPrefs) {
|
|
164
|
+
if (k in mapping) {
|
|
165
|
+
obj[mapping[k]] = true;
|
|
166
|
+
}
|
|
139
167
|
}
|
|
168
|
+
cm.prefer(obj);
|
|
140
169
|
}
|
|
141
|
-
|
|
170
|
+
}
|
|
171
|
+
const jump = document.querySelector('#Wikiplus-Quickedit-Jump > a');
|
|
172
|
+
if (jump) {
|
|
173
|
+
jump.href = '#Wikiplus-CodeMirror';
|
|
142
174
|
}
|
|
143
175
|
};
|
|
144
176
|
// 监视 Wikiplus 编辑框
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiplus-highlight",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A plugin for the MediaWiki front-end add-on \"Wikiplus\"",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"eslint-plugin-promise": "^6.1.1",
|
|
45
45
|
"eslint-plugin-regexp": "^2.2.0",
|
|
46
46
|
"eslint-plugin-unicorn": "^51.0.1",
|
|
47
|
+
"monaco-wiki": "^0.2.0",
|
|
47
48
|
"stylelint": "^16.1.0",
|
|
48
49
|
"stylelint-config-recommended": "^14.0.0",
|
|
49
50
|
"types-mediawiki": "^1.4.0",
|