@bhsd/codemirror-mediawiki 2.1.1 → 2.1.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.
@@ -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/dist/plugins.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { css } from '@codemirror/legacy-modes/mode/css';
2
- export { javascript } from '@codemirror/legacy-modes/mode/javascript';
2
+ export { javascript, json } from '@codemirror/legacy-modes/mode/javascript';
3
3
  export { lua } from '@codemirror/legacy-modes/mode/lua';
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/dist/main.min.js';
1
+ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.3/dist/main.min.js';
2
2
  (() => {
3
3
  var _a;
4
- mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.1/mediawiki.min.css', 'text/css');
4
+ mw.loader.load('https://testingcf.jsdelivr.net/npm/@bhsd/codemirror-mediawiki@2.1.3/mediawiki.min.css', 'text/css');
5
5
  const instances = new WeakMap();
6
6
  $.valHooks['textarea'] = {
7
7
  get(elem) {
@@ -139,31 +139,24 @@ 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);
146
145
  }
146
+ mw.hook('wiki-codemirror6').fire(this);
147
147
  }
148
148
  toggle(show = !this.visible) {
149
- if (show && !this.visible) {
150
- this.view.dispatch({
151
- changes: { from: 0, to: this.view.state.doc.length, insert: this.textarea.value },
152
- });
153
- }
154
- this.visible = show;
155
- this.view.dom.style.setProperty('display', show ? '' : 'none', 'important');
156
- this.textarea.style.display = show ? 'none' : '';
149
+ super.toggle(show);
157
150
  $(this.textarea).data('jquery.textSelection', show && textSelection);
158
151
  }
159
- async defaultLint(on) {
152
+ async defaultLint(on, opt) {
160
153
  if (!on) {
161
154
  this.lint();
162
155
  return;
163
156
  }
164
157
  const { lang } = this;
165
158
  if (!(lang in linters)) {
166
- linters[lang] = await this.getLinter();
159
+ linters[lang] = await this.getLinter(opt);
167
160
  if (this.lang === 'mediawiki' || this.lang === 'html') {
168
161
  const mwConfig = await getMwConfig(), config = {
169
162
  ...await wikiparse.getConfig(),
@@ -185,7 +178,9 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
185
178
  wikiparse.setConfig(config);
186
179
  }
187
180
  }
188
- this.lint(linters[lang]);
181
+ if (linters[lang]) {
182
+ this.lint(linters[lang]);
183
+ }
189
184
  }
190
185
  static async fromTextArea(textarea, lang) {
191
186
  const isWiki = lang === 'mediawiki' || lang === 'html', cm = new CodeMirror(textarea, isWiki ? undefined : lang);
@@ -197,7 +192,7 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
197
192
  }
198
193
  }
199
194
  document.body.addEventListener('click', e => {
200
- if (e.target instanceof HTMLTextAreaElement && (e.ctrlKey || e.metaKey) && !instances.has(e.target)) {
195
+ if (e.target instanceof HTMLTextAreaElement && e.shiftKey && !instances.has(e.target)) {
201
196
  e.preventDefault();
202
197
  (async () => {
203
198
  var _a;
@@ -214,9 +209,11 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
214
209
  lang = 'css';
215
210
  break;
216
211
  case 'javascript':
217
- case 'json':
218
212
  lang = 'javascript';
219
213
  break;
214
+ case 'json':
215
+ lang = 'json';
216
+ break;
220
217
  case 'Scribunto':
221
218
  lang = 'lua';
222
219
  break;
@@ -226,7 +223,17 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
226
223
  }
227
224
  }
228
225
  const cm = await CodeMirror.fromTextArea(e.target, lang);
229
- void cm.defaultLint(true);
226
+ let opt;
227
+ if (lang === 'mediawiki' && wgNamespaceNumber === 10) {
228
+ opt = { include: true };
229
+ }
230
+ else if (lang === 'javascript' && (wgNamespaceNumber === 8 || wgNamespaceNumber === 2300)) {
231
+ opt = {
232
+ env: { browser: true, es6: true },
233
+ parserOptions: { ecmaVersion: 6 },
234
+ };
235
+ }
236
+ await cm.defaultLint(true, opt);
230
237
  })();
231
238
  }
232
239
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/codemirror-mediawiki",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
5
5
  "keywords": [
6
6
  "mediawiki",