@bhsd/codemirror-mediawiki 2.0.13 → 2.0.14
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/README.md +8 -0
- package/dist/main.min.js +1 -1
- package/mw/dist/base.js +27 -33
- package/package.json +4 -2
package/mw/dist/base.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0.
|
|
1
|
+
import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0.14/dist/main.min.js';
|
|
2
2
|
(() => {
|
|
3
3
|
var _a;
|
|
4
|
-
mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0.
|
|
4
|
+
mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.0.14/mediawiki.min.css', 'text/css');
|
|
5
5
|
const instances = new WeakMap();
|
|
6
6
|
$.valHooks['textarea'] = {
|
|
7
7
|
get(elem) {
|
|
@@ -128,22 +128,8 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
128
128
|
};
|
|
129
129
|
const linters = {};
|
|
130
130
|
class CodeMirror extends CodeMirror6 {
|
|
131
|
-
constructor(textarea, lang) {
|
|
132
|
-
|
|
133
|
-
super(textarea, lang === 'mediawiki' ? undefined : lang);
|
|
134
|
-
if (lang === 'mediawiki') {
|
|
135
|
-
(async () => {
|
|
136
|
-
const config = await getMwConfig();
|
|
137
|
-
this.setLanguage('mediawiki', config);
|
|
138
|
-
})();
|
|
139
|
-
}
|
|
140
|
-
this.view.dispatch({
|
|
141
|
-
selection: { anchor: selectionStart, head: selectionEnd }
|
|
142
|
-
});
|
|
143
|
-
this.view.scrollDOM.scrollTop = scrollTop;
|
|
144
|
-
if (hasFocus) {
|
|
145
|
-
this.view.focus();
|
|
146
|
-
}
|
|
131
|
+
constructor(textarea, lang, config) {
|
|
132
|
+
super(textarea, lang, config);
|
|
147
133
|
instances.set(textarea, this);
|
|
148
134
|
if (mw.loader.getState('jquery.textSelection') === 'ready') {
|
|
149
135
|
$(textarea).data('jquery.textSelection', textSelection);
|
|
@@ -157,30 +143,38 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
157
143
|
const { lang } = this;
|
|
158
144
|
if (!(lang in linters)) {
|
|
159
145
|
linters[lang] = await this.getLinter();
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
146
|
+
if (this.lang === 'mediawiki') {
|
|
147
|
+
const mwConfig = await getMwConfig(), config = await wikiparse.getConfig();
|
|
148
|
+
config.ext = Object.keys(mwConfig.tags);
|
|
149
|
+
config.namespaces = mw.config.get('wgFormattedNamespaces');
|
|
150
|
+
config.nsid = mw.config.get('wgNamespaceIds');
|
|
151
|
+
config.parserFunction[0] = mwConfig.functionSynonyms[0];
|
|
152
|
+
config.parserFunction[1] = [...Object.keys(mwConfig.functionSynonyms[1]), '='];
|
|
153
|
+
config.doubleUnderscore = mwConfig.doubleUnderscore.map(Object.keys);
|
|
154
|
+
config.variants = mwConfig.variants;
|
|
155
|
+
config.img = mwConfig.img;
|
|
156
|
+
for (const key of Object.keys(config.img)) {
|
|
157
|
+
config.img[key] = config.img[key].slice(4);
|
|
158
|
+
}
|
|
159
|
+
wikiparse.setConfig(config);
|
|
173
160
|
}
|
|
174
|
-
wikiparse.setConfig(config);
|
|
175
161
|
}
|
|
176
162
|
super.lint(linters[lang]);
|
|
177
163
|
}
|
|
164
|
+
static async fromTextArea(textarea, lang) {
|
|
165
|
+
const cm = new CodeMirror(textarea, lang === 'mediawiki' ? undefined : lang);
|
|
166
|
+
if (lang === 'mediawiki') {
|
|
167
|
+
const config = await getMwConfig();
|
|
168
|
+
cm.setLanguage('mediawiki', config);
|
|
169
|
+
}
|
|
170
|
+
return cm;
|
|
171
|
+
}
|
|
178
172
|
}
|
|
179
173
|
$(document.body).click(async (e) => {
|
|
180
174
|
if (e.target instanceof HTMLTextAreaElement && (e.ctrlKey || e.metaKey) && !instances.has(e.target)) {
|
|
181
175
|
e.preventDefault();
|
|
182
176
|
await mw.loader.using('oojs-ui-windows');
|
|
183
|
-
const lang = await OO.ui.prompt('Language:') || undefined, cm =
|
|
177
|
+
const lang = await OO.ui.prompt('Language:') || undefined, cm = await CodeMirror.fromTextArea(e.target, lang);
|
|
184
178
|
void cm.defaultLint(true);
|
|
185
179
|
}
|
|
186
180
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-mediawiki",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.14",
|
|
4
4
|
"description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && eslint --cache .",
|
|
32
32
|
"lint:css": "stylelint *.css",
|
|
33
33
|
"lint": "npm run lint:ts && npm run lint:css",
|
|
34
|
-
"
|
|
34
|
+
"server": "http-server -c-1 --cors &",
|
|
35
|
+
"test": "npm run server; open http://127.0.0.1:8080/index.html",
|
|
36
|
+
"test:end": "pkill -x http-server"
|
|
35
37
|
},
|
|
36
38
|
"engines": {
|
|
37
39
|
"node": "20.9.0"
|