@bhsd/codemirror-mediawiki 2.1.0 → 2.1.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 +1 -1
- package/dist/main.min.js +10 -10
- package/dist/plugins.d.ts +1 -1
- package/mw/dist/base.js +58 -15
- package/package.json +1 -1
package/dist/plugins.d.ts
CHANGED
package/mw/dist/base.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.
|
|
1
|
+
import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.2/dist/main.min.js';
|
|
2
2
|
(() => {
|
|
3
3
|
var _a;
|
|
4
|
-
mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.
|
|
4
|
+
mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.2/mediawiki.min.css', 'text/css');
|
|
5
5
|
const instances = new WeakMap();
|
|
6
6
|
$.valHooks['textarea'] = {
|
|
7
7
|
get(elem) {
|
|
8
8
|
const cm = instances.get(elem);
|
|
9
|
-
return cm ? cm.view.state.doc.toString() : elem.value;
|
|
9
|
+
return (cm === null || cm === void 0 ? void 0 : cm.visible) ? cm.view.state.doc.toString() : elem.value;
|
|
10
10
|
},
|
|
11
11
|
set(elem, value) {
|
|
12
12
|
const cm = instances.get(elem);
|
|
13
|
-
if (cm) {
|
|
13
|
+
if (cm === null || cm === void 0 ? void 0 : cm.visible) {
|
|
14
14
|
cm.view.dispatch({
|
|
15
15
|
changes: { from: 0, to: cm.view.state.doc.length, insert: value },
|
|
16
16
|
});
|
|
@@ -139,20 +139,33 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
139
139
|
class CodeMirror extends CodeMirror6 {
|
|
140
140
|
constructor(textarea, lang, config) {
|
|
141
141
|
super(textarea, lang, config);
|
|
142
|
+
this.visible = true;
|
|
142
143
|
instances.set(textarea, this);
|
|
143
144
|
if (mw.loader.getState('jquery.textSelection') === 'ready') {
|
|
144
145
|
$(textarea).data('jquery.textSelection', textSelection);
|
|
145
146
|
}
|
|
147
|
+
mw.hook('wiki-codemirror6').fire(this);
|
|
148
|
+
}
|
|
149
|
+
toggle(show = !this.visible) {
|
|
150
|
+
if (show && !this.visible) {
|
|
151
|
+
this.view.dispatch({
|
|
152
|
+
changes: { from: 0, to: this.view.state.doc.length, insert: this.textarea.value },
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
this.visible = show;
|
|
156
|
+
this.view.dom.style.setProperty('display', show ? '' : 'none', 'important');
|
|
157
|
+
this.textarea.style.display = show ? 'none' : '';
|
|
158
|
+
$(this.textarea).data('jquery.textSelection', show && textSelection);
|
|
146
159
|
}
|
|
147
160
|
async defaultLint(on) {
|
|
148
161
|
if (!on) {
|
|
149
|
-
|
|
162
|
+
this.lint();
|
|
150
163
|
return;
|
|
151
164
|
}
|
|
152
165
|
const { lang } = this;
|
|
153
166
|
if (!(lang in linters)) {
|
|
154
167
|
linters[lang] = await this.getLinter();
|
|
155
|
-
if (this.lang === 'mediawiki') {
|
|
168
|
+
if (this.lang === 'mediawiki' || this.lang === 'html') {
|
|
156
169
|
const mwConfig = await getMwConfig(), config = {
|
|
157
170
|
...await wikiparse.getConfig(),
|
|
158
171
|
ext: Object.keys(mwConfig.tags),
|
|
@@ -160,7 +173,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
160
173
|
nsid: mw.config.get('wgNamespaceIds'),
|
|
161
174
|
doubleUnderscore: mwConfig.doubleUnderscore.map(obj => Object.keys(obj).map(s => s.slice(2, -2))),
|
|
162
175
|
variants: mwConfig.variants,
|
|
163
|
-
protocol: mwConfig.urlProtocols,
|
|
176
|
+
protocol: mwConfig.urlProtocols.replace(/\\:/gu, ':'),
|
|
164
177
|
};
|
|
165
178
|
[config.parserFunction[0]] = mwConfig.functionSynonyms;
|
|
166
179
|
config.parserFunction[1] = [
|
|
@@ -173,23 +186,53 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
173
186
|
wikiparse.setConfig(config);
|
|
174
187
|
}
|
|
175
188
|
}
|
|
176
|
-
|
|
189
|
+
if (linters[lang]) {
|
|
190
|
+
this.lint(linters[lang]);
|
|
191
|
+
}
|
|
177
192
|
}
|
|
178
193
|
static async fromTextArea(textarea, lang) {
|
|
179
|
-
const cm = new CodeMirror(textarea,
|
|
180
|
-
if (
|
|
194
|
+
const isWiki = lang === 'mediawiki' || lang === 'html', cm = new CodeMirror(textarea, isWiki ? undefined : lang);
|
|
195
|
+
if (isWiki) {
|
|
181
196
|
const config = await getMwConfig();
|
|
182
|
-
cm.setLanguage(
|
|
197
|
+
cm.setLanguage(lang, config);
|
|
183
198
|
}
|
|
184
199
|
return cm;
|
|
185
200
|
}
|
|
186
201
|
}
|
|
187
|
-
|
|
202
|
+
document.body.addEventListener('click', e => {
|
|
188
203
|
if (e.target instanceof HTMLTextAreaElement && (e.ctrlKey || e.metaKey) && !instances.has(e.target)) {
|
|
189
204
|
e.preventDefault();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
205
|
+
(async () => {
|
|
206
|
+
var _a;
|
|
207
|
+
const { wgAction, wgNamespaceNumber, wgPageContentModel } = mw.config.get();
|
|
208
|
+
let lang;
|
|
209
|
+
if (wgAction !== 'edit' && wgAction !== 'submit') {
|
|
210
|
+
await mw.loader.using('oojs-ui-windows');
|
|
211
|
+
lang = (_a = (await OO.ui.prompt('Language:') || undefined)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
switch (wgPageContentModel) {
|
|
215
|
+
case 'css':
|
|
216
|
+
case 'sanitized-css':
|
|
217
|
+
lang = 'css';
|
|
218
|
+
break;
|
|
219
|
+
case 'javascript':
|
|
220
|
+
lang = 'javascript';
|
|
221
|
+
break;
|
|
222
|
+
case 'json':
|
|
223
|
+
lang = 'json';
|
|
224
|
+
break;
|
|
225
|
+
case 'Scribunto':
|
|
226
|
+
lang = 'lua';
|
|
227
|
+
break;
|
|
228
|
+
case 'wikitext':
|
|
229
|
+
lang = wgNamespaceNumber === 274 ? 'html' : 'mediawiki';
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const cm = await CodeMirror.fromTextArea(e.target, lang);
|
|
234
|
+
void cm.defaultLint(true);
|
|
235
|
+
})();
|
|
193
236
|
}
|
|
194
237
|
});
|
|
195
238
|
Object.assign(window, { CodeMirror });
|