@bhsd/codemirror-mediawiki 2.1.2 → 2.1.4
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 +64 -16
- package/dist/codemirror.d.ts +16 -4
- package/dist/config.d.ts +1 -12
- package/dist/main.min.js +12 -12
- package/dist/mediawiki.d.ts +5 -0
- package/mw/dist/base.js +24 -15
- package/package.json +1 -1
package/dist/mediawiki.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface MwConfig {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Gets a LanguageSupport instance for the MediaWiki mode.
|
|
19
|
+
* @param config Configuration for the MediaWiki mode
|
|
19
20
|
*/
|
|
20
21
|
export declare const mediawiki: (config: MwConfig) => LanguageSupport;
|
|
22
|
+
/**
|
|
23
|
+
* Gets a LanguageSupport instance for the mixed MediaWiki-HTML mode.
|
|
24
|
+
* @param config Configuration for the MediaWiki mode
|
|
25
|
+
*/
|
|
21
26
|
export declare const html: (config: MwConfig) => LanguageSupport;
|
package/mw/dist/base.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.4/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.4/mediawiki.min.css', 'text/css');
|
|
5
5
|
const instances = new WeakMap();
|
|
6
6
|
$.valHooks['textarea'] = {
|
|
7
7
|
get(elem) {
|
|
@@ -139,7 +139,6 @@ 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;
|
|
143
142
|
instances.set(textarea, this);
|
|
144
143
|
if (mw.loader.getState('jquery.textSelection') === 'ready') {
|
|
145
144
|
$(textarea).data('jquery.textSelection', textSelection);
|
|
@@ -147,24 +146,17 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
147
146
|
mw.hook('wiki-codemirror6').fire(this);
|
|
148
147
|
}
|
|
149
148
|
toggle(show = !this.visible) {
|
|
150
|
-
|
|
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' : '';
|
|
149
|
+
super.toggle(show);
|
|
158
150
|
$(this.textarea).data('jquery.textSelection', show && textSelection);
|
|
159
151
|
}
|
|
160
|
-
async defaultLint(on) {
|
|
152
|
+
async defaultLint(on, opt) {
|
|
161
153
|
if (!on) {
|
|
162
154
|
this.lint();
|
|
163
155
|
return;
|
|
164
156
|
}
|
|
165
157
|
const { lang } = this;
|
|
166
158
|
if (!(lang in linters)) {
|
|
167
|
-
linters[lang] = await this.getLinter();
|
|
159
|
+
linters[lang] = await this.getLinter(opt);
|
|
168
160
|
if (this.lang === 'mediawiki' || this.lang === 'html') {
|
|
169
161
|
const mwConfig = await getMwConfig(), config = {
|
|
170
162
|
...await wikiparse.getConfig(),
|
|
@@ -176,6 +168,13 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
176
168
|
protocol: mwConfig.urlProtocols.replace(/\\:/gu, ':'),
|
|
177
169
|
};
|
|
178
170
|
[config.parserFunction[0]] = mwConfig.functionSynonyms;
|
|
171
|
+
if (!USING_LOCAL) {
|
|
172
|
+
for (const [key, val] of Object.entries(mwConfig.functionSynonyms[0])) {
|
|
173
|
+
if (!key.startsWith('#')) {
|
|
174
|
+
config.parserFunction[0][`#${key}`] = val;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
179
178
|
config.parserFunction[1] = [
|
|
180
179
|
...Object.keys(mwConfig.functionSynonyms[1]),
|
|
181
180
|
'=',
|
|
@@ -200,7 +199,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
document.body.addEventListener('click', e => {
|
|
203
|
-
if (e.target instanceof HTMLTextAreaElement &&
|
|
202
|
+
if (e.target instanceof HTMLTextAreaElement && e.shiftKey && !instances.has(e.target)) {
|
|
204
203
|
e.preventDefault();
|
|
205
204
|
(async () => {
|
|
206
205
|
var _a;
|
|
@@ -231,7 +230,17 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
232
|
const cm = await CodeMirror.fromTextArea(e.target, lang);
|
|
234
|
-
|
|
233
|
+
let opt;
|
|
234
|
+
if (lang === 'mediawiki' && wgNamespaceNumber === 10) {
|
|
235
|
+
opt = { include: true };
|
|
236
|
+
}
|
|
237
|
+
else if (lang === 'javascript' && (wgNamespaceNumber === 8 || wgNamespaceNumber === 2300)) {
|
|
238
|
+
opt = {
|
|
239
|
+
env: { browser: true, es6: true },
|
|
240
|
+
parserOptions: { ecmaVersion: 6 },
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
await cm.defaultLint(true, opt);
|
|
235
244
|
})();
|
|
236
245
|
}
|
|
237
246
|
});
|