@bhsd/codemirror-mediawiki 2.31.0 → 3.0.1
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 +181 -32
- package/dist/codemirror.d.ts +72 -47
- package/dist/codemirror.js +169 -208
- package/dist/color.d.ts +1 -6
- package/dist/color.js +1 -8
- package/dist/config.js +4 -4
- package/dist/escape.js +2 -2
- package/dist/fold.d.ts +53 -6
- package/dist/fold.js +130 -133
- package/dist/indent.d.ts +5 -1
- package/dist/indent.js +2 -1
- package/dist/javascript.d.ts +1 -0
- package/dist/javascript.js +2 -4
- package/dist/keybindings.js +1 -0
- package/dist/linter.js +43 -8
- package/dist/lintsource.d.ts +14 -0
- package/dist/lintsource.js +159 -0
- package/dist/main.min.js +25 -24
- package/dist/matchBrackets.d.ts +1 -1
- package/dist/matchTag.js +2 -2
- package/dist/mw.min.js +26 -25
- package/dist/mwConfig.js +0 -3
- package/dist/statusBar.d.ts +1 -1
- package/dist/token.d.ts +1 -1
- package/dist/token.js +11 -16
- package/dist/vue.d.ts +3 -0
- package/dist/vue.js +14 -0
- package/dist/wiki.min.js +25 -24
- package/i18n/en.json +2 -3
- package/i18n/zh-hans.json +2 -3
- package/i18n/zh-hant.json +2 -3
- package/package.json +10 -7
package/dist/codemirror.js
CHANGED
|
@@ -6,17 +6,20 @@ import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
|
|
6
6
|
import { linter, lintGutter, lintKeymap } from '@codemirror/lint';
|
|
7
7
|
import { closeBrackets, autocompletion, acceptCompletion, completionKeymap, startCompletion, } from '@codemirror/autocomplete';
|
|
8
8
|
import { json } from '@codemirror/lang-json';
|
|
9
|
+
import { autoCloseTags } from '@codemirror/lang-html';
|
|
10
|
+
import { css as cssParser } from '@codemirror/legacy-modes/mode/css';
|
|
9
11
|
import { getLSP } from '@bhsd/browser';
|
|
10
|
-
import colorPicker from '
|
|
11
|
-
import {
|
|
12
|
+
import { colorPicker as cssColorPicker, colorPickerTheme, makeColorPicker } from '@bhsd/codemirror-css-color-picker';
|
|
13
|
+
import colorPicker, { discoverColors } from './color';
|
|
14
|
+
import { mediawiki, html, FullMediaWiki } from './mediawiki';
|
|
12
15
|
import escapeKeymap from './escape';
|
|
13
|
-
import codeFolding, { foldHandler } from './fold';
|
|
16
|
+
import codeFolding, { foldHandler, mediaWikiFold } from './fold';
|
|
14
17
|
import tagMatchingState from './matchTag';
|
|
15
18
|
import refHover from './ref';
|
|
16
|
-
import magicWordHover
|
|
19
|
+
import magicWordHover from './hover';
|
|
17
20
|
import signatureHelp from './signature';
|
|
18
21
|
import inlayHints from './inlay';
|
|
19
|
-
import {
|
|
22
|
+
import { getWikiLintSource, getJsLintSource, getCssLintSource, getJsonLintSource, getLuaLintSource, getVueLintSource, } from './lintsource';
|
|
20
23
|
import openLinks from './openLinks';
|
|
21
24
|
import { tagModes, getStaticMwConfig } from './static';
|
|
22
25
|
import bidiIsolation from './bidi';
|
|
@@ -28,24 +31,10 @@ import wikitextLSP from './lsp';
|
|
|
28
31
|
import javascript from './javascript';
|
|
29
32
|
import css from './css';
|
|
30
33
|
import lua from './lua';
|
|
34
|
+
import vue from './vue';
|
|
31
35
|
const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
|
|
32
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
const languages = {
|
|
34
|
-
plain,
|
|
35
|
-
mediawiki(config) {
|
|
36
|
-
return [
|
|
37
|
-
mediawiki(config),
|
|
38
|
-
plain(),
|
|
39
|
-
bidiIsolation,
|
|
40
|
-
toolKeymap,
|
|
41
|
-
];
|
|
42
|
-
},
|
|
43
|
-
html,
|
|
44
|
-
javascript,
|
|
45
|
-
css,
|
|
46
|
-
json,
|
|
47
|
-
lua,
|
|
48
|
-
};
|
|
37
|
+
const languages = { plain };
|
|
49
38
|
function mediawikiOnly(ext) {
|
|
50
39
|
return typeof ext === 'function'
|
|
51
40
|
? [(enable, cm) => enable ? ext(cm) : [], { mediawiki: true }]
|
|
@@ -53,15 +42,19 @@ function mediawikiOnly(ext) {
|
|
|
53
42
|
}
|
|
54
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
44
|
const avail = {
|
|
56
|
-
highlightSpecialChars: [highlightSpecialChars
|
|
57
|
-
highlightActiveLine: [highlightActiveLine
|
|
58
|
-
highlightWhitespace: [highlightWhitespace
|
|
59
|
-
highlightTrailingWhitespace: [highlightTrailingWhitespace
|
|
60
|
-
highlightSelectionMatches: [highlightSelectionMatches
|
|
61
|
-
bracketMatching: [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
highlightSpecialChars: [highlightSpecialChars],
|
|
46
|
+
highlightActiveLine: [highlightActiveLine],
|
|
47
|
+
highlightWhitespace: [highlightWhitespace],
|
|
48
|
+
highlightTrailingWhitespace: [highlightTrailingWhitespace],
|
|
49
|
+
highlightSelectionMatches: [highlightSelectionMatches],
|
|
50
|
+
bracketMatching: [
|
|
51
|
+
([config, e = []] = []) => [
|
|
52
|
+
bracketMatching(config),
|
|
53
|
+
e,
|
|
54
|
+
],
|
|
55
|
+
],
|
|
56
|
+
closeBrackets: [(e = []) => [closeBrackets(), e]],
|
|
57
|
+
scrollPastEnd: [scrollPastEnd],
|
|
65
58
|
allowMultipleSelections: [
|
|
66
59
|
() => [
|
|
67
60
|
EditorState.allowMultipleSelections.of(true),
|
|
@@ -69,7 +62,6 @@ const avail = {
|
|
|
69
62
|
rectangularSelection(),
|
|
70
63
|
crosshairCursor(),
|
|
71
64
|
],
|
|
72
|
-
{},
|
|
73
65
|
],
|
|
74
66
|
autocompletion: [
|
|
75
67
|
() => [
|
|
@@ -80,27 +72,104 @@ const avail = {
|
|
|
80
72
|
{ key: 'Tab', run: acceptCompletion },
|
|
81
73
|
]),
|
|
82
74
|
],
|
|
83
|
-
{},
|
|
84
75
|
],
|
|
85
76
|
codeFolding,
|
|
86
77
|
colorPicker,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
signatureHelp: mediawikiOnly(signatureHelp),
|
|
92
|
-
inlayHints: mediawikiOnly(inlayHints),
|
|
93
|
-
}, editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp']);
|
|
78
|
+
};
|
|
79
|
+
const linterRegistry = {};
|
|
80
|
+
const destroyListeners = [];
|
|
81
|
+
const editExtensions = new Set(['closeBrackets', 'autocompletion', 'signatureHelp']);
|
|
94
82
|
const linters = {};
|
|
95
83
|
const phrases = {};
|
|
96
84
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
85
|
+
* 注册特定语言的扩展
|
|
86
|
+
* @param lang 语言
|
|
87
|
+
* @param name 扩展名
|
|
88
|
+
* @param ext 扩展
|
|
89
|
+
*/
|
|
90
|
+
const registerLangExtension = (lang, name, ext) => {
|
|
91
|
+
const addon = avail[name];
|
|
92
|
+
addon[1] ??= {};
|
|
93
|
+
addon[1][lang] = ext;
|
|
94
|
+
};
|
|
95
|
+
/** Register MediaWiki language support */
|
|
96
|
+
export const registerMediaWiki = () => {
|
|
97
|
+
languages['mediawiki'] = (config) => [
|
|
98
|
+
mediawiki(config),
|
|
99
|
+
plain(),
|
|
100
|
+
bidiIsolation,
|
|
101
|
+
toolKeymap,
|
|
102
|
+
];
|
|
103
|
+
registerLangExtension('mediawiki', 'colorPicker', [
|
|
104
|
+
[makeColorPicker({ discoverColors }), colorPickerTheme],
|
|
105
|
+
{ marginLeft: '0.6ch' },
|
|
106
|
+
]);
|
|
107
|
+
registerLangExtension('mediawiki', 'bracketMatching', [
|
|
108
|
+
{ brackets: '()[]{}()【】[]{}' },
|
|
109
|
+
tagMatchingState,
|
|
110
|
+
]);
|
|
111
|
+
registerLangExtension('mediawiki', 'codeFolding', mediaWikiFold);
|
|
112
|
+
Object.assign(avail, {
|
|
113
|
+
openLinks: mediawikiOnly(openLinks),
|
|
114
|
+
escape: mediawikiOnly(keymap.of(escapeKeymap)),
|
|
115
|
+
refHover: mediawikiOnly(refHover),
|
|
116
|
+
hover: mediawikiOnly(magicWordHover),
|
|
117
|
+
signatureHelp: mediawikiOnly(signatureHelp),
|
|
118
|
+
inlayHints: mediawikiOnly(inlayHints),
|
|
119
|
+
});
|
|
120
|
+
linterRegistry['mediawiki'] = getWikiLintSource;
|
|
121
|
+
destroyListeners.push(view => getLSP(view)?.destroy());
|
|
122
|
+
};
|
|
123
|
+
/** Register mixed MediaWiki-HTML language support */
|
|
124
|
+
export const registerHTML = () => {
|
|
125
|
+
Object.assign(FullMediaWiki.prototype, {
|
|
126
|
+
css() {
|
|
127
|
+
return cssParser;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
languages['html'] = html;
|
|
131
|
+
};
|
|
132
|
+
/** Register JavaScript language support */
|
|
133
|
+
export const registerJavaScript = () => {
|
|
134
|
+
languages['javascript'] = javascript;
|
|
135
|
+
linterRegistry['javascript'] = getJsLintSource;
|
|
136
|
+
};
|
|
137
|
+
/** Register CSS language support */
|
|
138
|
+
export const registerCSS = () => {
|
|
139
|
+
languages['css'] = css;
|
|
140
|
+
registerLangExtension('css', 'colorPicker', [cssColorPicker]);
|
|
141
|
+
linterRegistry['css'] = getCssLintSource;
|
|
142
|
+
};
|
|
143
|
+
/** Register JSON language support */
|
|
144
|
+
export const registerJSON = () => {
|
|
145
|
+
languages['json'] = json;
|
|
146
|
+
linterRegistry['json'] = getJsonLintSource;
|
|
147
|
+
};
|
|
148
|
+
/** Register Lua language support */
|
|
149
|
+
export const registerLua = () => {
|
|
150
|
+
languages['lua'] = lua;
|
|
151
|
+
linterRegistry['lua'] = getLuaLintSource;
|
|
152
|
+
};
|
|
153
|
+
/** Register Vue language support */
|
|
154
|
+
export const registerVue = () => {
|
|
155
|
+
languages['vue'] = vue;
|
|
156
|
+
registerLangExtension('vue', 'closeBrackets', autoCloseTags);
|
|
157
|
+
registerLangExtension('vue', 'colorPicker', [cssColorPicker]);
|
|
158
|
+
linterRegistry['vue'] = getVueLintSource;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Register a custom language support
|
|
162
|
+
* @param name language name
|
|
163
|
+
* @param lang language support
|
|
164
|
+
* @param lintSource optional linter
|
|
101
165
|
*/
|
|
102
|
-
const
|
|
103
|
-
|
|
166
|
+
export const registerLanguage = (name, lang, lintSource) => {
|
|
167
|
+
languages[name] = lang;
|
|
168
|
+
if (lintSource) {
|
|
169
|
+
linterRegistry[name] = lintSource;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/** CodeMirror 6 editor */
|
|
104
173
|
export class CodeMirror6 {
|
|
105
174
|
#textarea;
|
|
106
175
|
#language = new Compartment();
|
|
@@ -116,23 +185,27 @@ export class CodeMirror6 {
|
|
|
116
185
|
#visible = false;
|
|
117
186
|
#preferred = new Set();
|
|
118
187
|
#indentStr = '\t';
|
|
188
|
+
/** textarea element */
|
|
119
189
|
get textarea() {
|
|
120
190
|
return this.#textarea;
|
|
121
191
|
}
|
|
192
|
+
/** EditorView instance */
|
|
122
193
|
get view() {
|
|
123
194
|
return this.#view;
|
|
124
195
|
}
|
|
196
|
+
/** language */
|
|
125
197
|
get lang() {
|
|
126
198
|
return this.#lang;
|
|
127
199
|
}
|
|
200
|
+
/** whether the editor view is visible */
|
|
128
201
|
get visible() {
|
|
129
202
|
return this.#visible && this.textarea.isConnected;
|
|
130
203
|
}
|
|
131
204
|
/**
|
|
132
|
-
* @param textarea
|
|
133
|
-
* @param lang
|
|
134
|
-
* @param config
|
|
135
|
-
* @param init
|
|
205
|
+
* @param textarea textarea element
|
|
206
|
+
* @param lang language
|
|
207
|
+
* @param config language configuration
|
|
208
|
+
* @param init whether to initialize the editor immediately
|
|
136
209
|
*/
|
|
137
210
|
constructor(textarea, lang = 'plain', config, init = true) {
|
|
138
211
|
this.#textarea = textarea;
|
|
@@ -142,8 +215,8 @@ export class CodeMirror6 {
|
|
|
142
215
|
}
|
|
143
216
|
}
|
|
144
217
|
/**
|
|
145
|
-
*
|
|
146
|
-
* @param config
|
|
218
|
+
* Initialize the editor
|
|
219
|
+
* @param config language configuration
|
|
147
220
|
*/
|
|
148
221
|
initialize(config) {
|
|
149
222
|
let timer;
|
|
@@ -246,14 +319,14 @@ export class CodeMirror6 {
|
|
|
246
319
|
return this.#linter.get(this.#view.state)[0];
|
|
247
320
|
}
|
|
248
321
|
/**
|
|
249
|
-
*
|
|
250
|
-
* @param lang
|
|
251
|
-
* @param config
|
|
322
|
+
* Set language
|
|
323
|
+
* @param lang language
|
|
324
|
+
* @param config language configuration
|
|
252
325
|
*/
|
|
253
326
|
async setLanguage(lang = 'plain', config) {
|
|
254
327
|
this.#lang = lang;
|
|
255
328
|
if (this.#view) {
|
|
256
|
-
let ext = languages[lang](config);
|
|
329
|
+
let ext = (languages[lang] ?? plain)(config);
|
|
257
330
|
ws: { // eslint-disable-line no-unused-labels
|
|
258
331
|
if (lang === 'mediawiki') {
|
|
259
332
|
ext = [ext, await wikitextLSP()];
|
|
@@ -268,15 +341,15 @@ export class CodeMirror6 {
|
|
|
268
341
|
}
|
|
269
342
|
}
|
|
270
343
|
/**
|
|
271
|
-
*
|
|
272
|
-
* @param lintSource
|
|
344
|
+
* Start syntax checking
|
|
345
|
+
* @param lintSource function for syntax checking
|
|
273
346
|
*/
|
|
274
347
|
lint(lintSource) {
|
|
275
348
|
const linterExtension = lintSource
|
|
276
349
|
? [
|
|
277
|
-
linter(async ({ state
|
|
278
|
-
const diagnostics = await lintSource(
|
|
279
|
-
if (readOnly) {
|
|
350
|
+
linter(async ({ state }) => {
|
|
351
|
+
const diagnostics = await lintSource(state);
|
|
352
|
+
if (state.readOnly) {
|
|
280
353
|
for (const diagnostic of diagnostics) {
|
|
281
354
|
delete diagnostic.actions;
|
|
282
355
|
}
|
|
@@ -299,7 +372,7 @@ export class CodeMirror6 {
|
|
|
299
372
|
this.#minHeight(Boolean(lintSource));
|
|
300
373
|
}
|
|
301
374
|
}
|
|
302
|
-
/**
|
|
375
|
+
/** Update syntax checking immediately */
|
|
303
376
|
update() {
|
|
304
377
|
if (this.#view) {
|
|
305
378
|
const extension = this.#getLintExtension();
|
|
@@ -311,16 +384,16 @@ export class CodeMirror6 {
|
|
|
311
384
|
}
|
|
312
385
|
}
|
|
313
386
|
/**
|
|
314
|
-
*
|
|
315
|
-
* @param names
|
|
387
|
+
* Add extensions
|
|
388
|
+
* @param names extension names
|
|
316
389
|
*/
|
|
317
390
|
prefer(names) {
|
|
318
391
|
if (Array.isArray(names)) {
|
|
319
|
-
this.#preferred = new Set(names.filter(name => avail
|
|
392
|
+
this.#preferred = new Set(names.filter(name => Object.prototype.hasOwnProperty.call(avail, name)));
|
|
320
393
|
}
|
|
321
394
|
else {
|
|
322
395
|
for (const [name, enable] of Object.entries(names)) {
|
|
323
|
-
if (enable && avail
|
|
396
|
+
if (enable && Object.prototype.hasOwnProperty.call(avail, name)) {
|
|
324
397
|
this.#preferred.add(name);
|
|
325
398
|
}
|
|
326
399
|
else {
|
|
@@ -331,14 +404,14 @@ export class CodeMirror6 {
|
|
|
331
404
|
if (this.#view) {
|
|
332
405
|
const { readOnly } = this.#view.state;
|
|
333
406
|
this.#effects(this.#extensions.reconfigure([...this.#preferred].filter(name => !readOnly || !editExtensions.has(name)).map(name => {
|
|
334
|
-
const [extension, configs] = avail[name];
|
|
407
|
+
const [extension, configs = {}] = avail[name];
|
|
335
408
|
return extension(configs[this.#lang], this);
|
|
336
409
|
})));
|
|
337
410
|
}
|
|
338
411
|
}
|
|
339
412
|
/**
|
|
340
|
-
*
|
|
341
|
-
* @param indent
|
|
413
|
+
* Set text indentation
|
|
414
|
+
* @param indent indentation string
|
|
342
415
|
*/
|
|
343
416
|
setIndent(indent) {
|
|
344
417
|
if (this.#view) {
|
|
@@ -349,8 +422,8 @@ export class CodeMirror6 {
|
|
|
349
422
|
}
|
|
350
423
|
}
|
|
351
424
|
/**
|
|
352
|
-
*
|
|
353
|
-
* @param wrapping
|
|
425
|
+
* Set line wrapping
|
|
426
|
+
* @param wrapping whether to enable line wrapping
|
|
354
427
|
*/
|
|
355
428
|
setLineWrapping(wrapping) {
|
|
356
429
|
if (this.#view) {
|
|
@@ -358,131 +431,16 @@ export class CodeMirror6 {
|
|
|
358
431
|
}
|
|
359
432
|
}
|
|
360
433
|
/**
|
|
361
|
-
*
|
|
362
|
-
* @param opt
|
|
434
|
+
* Get default linter
|
|
435
|
+
* @param opt linter options
|
|
363
436
|
*/
|
|
364
437
|
async getLinter(opt) {
|
|
365
|
-
|
|
366
|
-
switch (this.#lang) {
|
|
367
|
-
case 'mediawiki': {
|
|
368
|
-
const wikiLint = await getWikiLinter(await getOpt(), this.#view);
|
|
369
|
-
return async (doc) => (await wikiLint(doc.toString(), await getOpt(true)))
|
|
370
|
-
.map(({ severity, code, message, range: r, from, to, data = [], source }) => ({
|
|
371
|
-
source: source,
|
|
372
|
-
from: from ?? posToIndex(doc, r.start),
|
|
373
|
-
to: to ?? posToIndex(doc, r.end),
|
|
374
|
-
severity: severity === 2 ? 'warning' : 'error',
|
|
375
|
-
message: source === 'Stylelint' ? message : `${message} (${code})`,
|
|
376
|
-
actions: data.map(({ title, range, newText }) => ({
|
|
377
|
-
name: title,
|
|
378
|
-
apply(view) {
|
|
379
|
-
view.dispatch({
|
|
380
|
-
changes: {
|
|
381
|
-
from: posToIndex(doc, range.start),
|
|
382
|
-
to: posToIndex(doc, range.end),
|
|
383
|
-
insert: newText,
|
|
384
|
-
},
|
|
385
|
-
});
|
|
386
|
-
},
|
|
387
|
-
})),
|
|
388
|
-
}));
|
|
389
|
-
}
|
|
390
|
-
case 'javascript': {
|
|
391
|
-
const esLint = await getJsLinter();
|
|
392
|
-
const lintSource = async (doc) => esLint(doc.toString(), await getOpt())
|
|
393
|
-
.map(({ ruleId, message, severity, line, column, endLine, endColumn, fix, suggestions = [] }) => {
|
|
394
|
-
const start = pos(doc, line, column), diagnostic = {
|
|
395
|
-
source: 'ESLint',
|
|
396
|
-
message: message + (ruleId ? ` (${ruleId})` : ''),
|
|
397
|
-
severity: severity === 1 ? 'warning' : 'error',
|
|
398
|
-
from: start,
|
|
399
|
-
to: endLine === undefined ? start + 1 : pos(doc, endLine, endColumn),
|
|
400
|
-
};
|
|
401
|
-
if (fix || suggestions.length > 0) {
|
|
402
|
-
diagnostic.actions = [
|
|
403
|
-
...fix ? [{ name: 'fix', fix }] : [],
|
|
404
|
-
...suggestions.map(suggestion => ({ name: 'suggestion', fix: suggestion.fix })),
|
|
405
|
-
].map(({ name, fix: { range: [from, to], text } }) => ({
|
|
406
|
-
name,
|
|
407
|
-
apply(view) {
|
|
408
|
-
view.dispatch({ changes: { from, to, insert: text } });
|
|
409
|
-
},
|
|
410
|
-
}));
|
|
411
|
-
}
|
|
412
|
-
return diagnostic;
|
|
413
|
-
});
|
|
414
|
-
lintSource.fixer = (doc, rule) => esLint.fixer(doc.toString(), rule);
|
|
415
|
-
return lintSource;
|
|
416
|
-
}
|
|
417
|
-
case 'css': {
|
|
418
|
-
const styleLint = await getCssLinter();
|
|
419
|
-
let option = await getOpt() ?? {};
|
|
420
|
-
if (!('extends' in option || 'rules' in option)) {
|
|
421
|
-
option = { rules: option };
|
|
422
|
-
}
|
|
423
|
-
const lintSource = async (doc) => (await styleLint(doc.toString(), option))
|
|
424
|
-
.map(({ text, severity, line, column, endLine, endColumn, fix }) => {
|
|
425
|
-
const diagnostic = {
|
|
426
|
-
source: 'Stylelint',
|
|
427
|
-
message: text,
|
|
428
|
-
severity,
|
|
429
|
-
from: pos(doc, line, column),
|
|
430
|
-
to: endLine === undefined ? doc.line(line).to : pos(doc, endLine, endColumn),
|
|
431
|
-
};
|
|
432
|
-
if (fix) {
|
|
433
|
-
diagnostic.actions = [
|
|
434
|
-
{
|
|
435
|
-
name: 'fix',
|
|
436
|
-
apply(view) {
|
|
437
|
-
view.dispatch({
|
|
438
|
-
changes: { from: fix.range[0], to: fix.range[1], insert: fix.text },
|
|
439
|
-
});
|
|
440
|
-
},
|
|
441
|
-
},
|
|
442
|
-
];
|
|
443
|
-
}
|
|
444
|
-
return diagnostic;
|
|
445
|
-
});
|
|
446
|
-
lintSource.fixer = async (doc, rule) => styleLint.fixer(doc.toString(), rule);
|
|
447
|
-
return lintSource;
|
|
448
|
-
}
|
|
449
|
-
case 'lua': {
|
|
450
|
-
const luaLint = await getLuaLinter();
|
|
451
|
-
return async (doc) => (await luaLint(doc.toString()))
|
|
452
|
-
.map(({ line, column, end_column: endColumn, msg: message, severity }) => ({
|
|
453
|
-
source: 'Luacheck',
|
|
454
|
-
message,
|
|
455
|
-
severity: severity === 1 ? 'warning' : 'error',
|
|
456
|
-
from: pos(doc, line, column),
|
|
457
|
-
to: pos(doc, line, endColumn + 1),
|
|
458
|
-
}));
|
|
459
|
-
}
|
|
460
|
-
case 'json': {
|
|
461
|
-
const jsonLint = getJsonLinter();
|
|
462
|
-
return doc => {
|
|
463
|
-
const [e] = jsonLint(doc.toString());
|
|
464
|
-
if (e) {
|
|
465
|
-
const { message, severity, line, column, position } = e;
|
|
466
|
-
let from = 0;
|
|
467
|
-
if (position) {
|
|
468
|
-
from = Number(position);
|
|
469
|
-
}
|
|
470
|
-
else if (line && column) {
|
|
471
|
-
from = pos(doc, Number(line), Number(column));
|
|
472
|
-
}
|
|
473
|
-
return [{ message, severity, from, to: from }];
|
|
474
|
-
}
|
|
475
|
-
return [];
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
default:
|
|
479
|
-
return undefined;
|
|
480
|
-
}
|
|
438
|
+
return linterRegistry[this.#lang]?.(opt, this.#view);
|
|
481
439
|
}
|
|
482
440
|
/**
|
|
483
|
-
*
|
|
484
|
-
* @param insert
|
|
485
|
-
* @param force
|
|
441
|
+
* Set content
|
|
442
|
+
* @param insert new content
|
|
443
|
+
* @param force whether to forcefully replace the content
|
|
486
444
|
*/
|
|
487
445
|
setContent(insert, force) {
|
|
488
446
|
if (this.#view) {
|
|
@@ -493,8 +451,8 @@ export class CodeMirror6 {
|
|
|
493
451
|
}
|
|
494
452
|
}
|
|
495
453
|
/**
|
|
496
|
-
*
|
|
497
|
-
* @param show
|
|
454
|
+
* Switch between textarea and editor view
|
|
455
|
+
* @param show whether to show the editor view
|
|
498
456
|
*/
|
|
499
457
|
toggle(show = !this.#visible) {
|
|
500
458
|
if (!this.#view) {
|
|
@@ -531,20 +489,22 @@ export class CodeMirror6 {
|
|
|
531
489
|
}
|
|
532
490
|
this.#visible = show;
|
|
533
491
|
}
|
|
534
|
-
/**
|
|
492
|
+
/** Destroy the editor */
|
|
535
493
|
destroy() {
|
|
536
494
|
if (this.visible) {
|
|
537
495
|
this.toggle(false);
|
|
538
496
|
}
|
|
539
497
|
if (this.#view) {
|
|
540
|
-
|
|
498
|
+
for (const listener of destroyListeners) {
|
|
499
|
+
listener(this.#view);
|
|
500
|
+
}
|
|
541
501
|
this.#view.destroy();
|
|
542
502
|
}
|
|
543
503
|
Object.setPrototypeOf(this, null);
|
|
544
504
|
}
|
|
545
505
|
/**
|
|
546
|
-
*
|
|
547
|
-
* @param keys
|
|
506
|
+
* Define extra key bindings
|
|
507
|
+
* @param keys key bindings
|
|
548
508
|
*/
|
|
549
509
|
extraKeys(keys) {
|
|
550
510
|
if (this.#view) {
|
|
@@ -552,8 +512,8 @@ export class CodeMirror6 {
|
|
|
552
512
|
}
|
|
553
513
|
}
|
|
554
514
|
/**
|
|
555
|
-
*
|
|
556
|
-
* @param messages
|
|
515
|
+
* Set translation messages
|
|
516
|
+
* @param messages translation messages
|
|
557
517
|
*/
|
|
558
518
|
localize(messages) {
|
|
559
519
|
Object.assign(phrases, messages);
|
|
@@ -562,15 +522,15 @@ export class CodeMirror6 {
|
|
|
562
522
|
}
|
|
563
523
|
}
|
|
564
524
|
/**
|
|
565
|
-
*
|
|
566
|
-
* @param position
|
|
525
|
+
* Get the syntax node at the specified position
|
|
526
|
+
* @param position position
|
|
567
527
|
*/
|
|
568
528
|
getNodeAt(position) {
|
|
569
529
|
return this.#view && ensureSyntaxTree(this.#view.state, position)?.resolve(position, 1);
|
|
570
530
|
}
|
|
571
531
|
/**
|
|
572
|
-
*
|
|
573
|
-
* @param position
|
|
532
|
+
* Scroll to the specified position
|
|
533
|
+
* @param position position or selection range
|
|
574
534
|
*/
|
|
575
535
|
scrollTo(position) {
|
|
576
536
|
if (this.#view) {
|
|
@@ -582,9 +542,9 @@ export class CodeMirror6 {
|
|
|
582
542
|
}
|
|
583
543
|
}
|
|
584
544
|
/**
|
|
585
|
-
*
|
|
586
|
-
* @param view
|
|
587
|
-
* @param func
|
|
545
|
+
* Replace the current selection with the result of a function
|
|
546
|
+
* @param view EditorView instance
|
|
547
|
+
* @param func function to produce the replacement text
|
|
588
548
|
*/
|
|
589
549
|
static replaceSelections(view, func) {
|
|
590
550
|
const { state } = view;
|
|
@@ -604,8 +564,9 @@ export class CodeMirror6 {
|
|
|
604
564
|
}));
|
|
605
565
|
}
|
|
606
566
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
567
|
+
* Convert a [WikiParser-Node](https://npmjs.com/package/wikiparser-node) configuration
|
|
568
|
+
* to a CodeMirror-MediaWiki configuration
|
|
569
|
+
* @param config WikiParser-Node configuration
|
|
609
570
|
*/
|
|
610
571
|
static getMwConfig(config) {
|
|
611
572
|
return getStaticMwConfig(config, tagModes);
|
package/dist/color.d.ts
CHANGED
|
@@ -3,10 +3,5 @@ import type { Tree } from '@lezer/common';
|
|
|
3
3
|
import type { StyleSpec } from 'style-mod';
|
|
4
4
|
import type { WidgetOptions } from '@bhsd/codemirror-css-color-picker';
|
|
5
5
|
export declare const discoverColors: (_: Tree, from: number, to: number, type: string, doc: Text) => WidgetOptions[] | null;
|
|
6
|
-
declare const _default: [([e, style]?: [Extension?, StyleSpec?]) => Extension
|
|
7
|
-
css: [Extension];
|
|
8
|
-
mediawiki: [Extension[], {
|
|
9
|
-
marginLeft: string;
|
|
10
|
-
}];
|
|
11
|
-
}];
|
|
6
|
+
declare const _default: [([e, style]?: [Extension?, StyleSpec?]) => Extension];
|
|
12
7
|
export default _default;
|
package/dist/color.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { splitColors, numToHex } from '@bhsd/common';
|
|
2
2
|
import { EditorView } from '@codemirror/view';
|
|
3
|
-
import { parseCallExpression, parseColorLiteral, ColorType,
|
|
3
|
+
import { parseCallExpression, parseColorLiteral, ColorType, wrapperClassName } from '@bhsd/codemirror-css-color-picker';
|
|
4
4
|
export const discoverColors = (_, from, to, type, doc) => {
|
|
5
5
|
if (!/mw-(?:(?:ext|html)tag-attribute-value|table-definition)/u.test(type)
|
|
6
6
|
&& (!/mw-(?:template|parserfunction)(?:$|_)/u.test(type)
|
|
@@ -42,11 +42,4 @@ export default [
|
|
|
42
42
|
}),
|
|
43
43
|
]
|
|
44
44
|
: [],
|
|
45
|
-
{
|
|
46
|
-
css: [colorPicker],
|
|
47
|
-
mediawiki: [
|
|
48
|
-
[makeColorPicker({ discoverColors }), colorPickerTheme],
|
|
49
|
-
{ marginLeft: '0.6ch' },
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
45
|
];
|
package/dist/config.js
CHANGED
|
@@ -79,9 +79,9 @@ var html = [
|
|
|
79
79
|
* @license GPL-2.0-or-later
|
|
80
80
|
* @see https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
|
|
81
81
|
*/
|
|
82
|
-
var htmlTags = html.flat();
|
|
83
|
-
var voidHtmlTags = html[2];
|
|
84
|
-
var selfClosingTags = html[1];
|
|
82
|
+
var htmlTags = /* @__PURE__ */ html.flat();
|
|
83
|
+
var voidHtmlTags = /* @__PURE__ */ (() => html[2])();
|
|
84
|
+
var selfClosingTags = /* @__PURE__ */ (() => html[1])();
|
|
85
85
|
var tokens = {
|
|
86
86
|
apostrophes: "mw-apostrophes",
|
|
87
87
|
comment: "mw-comment",
|
|
@@ -149,7 +149,7 @@ var tokens = {
|
|
|
149
149
|
templateVariableDelimiter: "mw-templatevariable-delimiter",
|
|
150
150
|
templateVariableName: "mw-templatevariable-name"
|
|
151
151
|
};
|
|
152
|
-
var tokenTable = (() => {
|
|
152
|
+
var tokenTable = /* @__PURE__ */ (() => {
|
|
153
153
|
const table = {
|
|
154
154
|
variable: tags.variableName,
|
|
155
155
|
"variable-2": tags.special(tags.variableName),
|
package/dist/escape.js
CHANGED
|
@@ -29,7 +29,7 @@ export const escapeHTML = (str) => [...str].map(c => {
|
|
|
29
29
|
}
|
|
30
30
|
return encodeURIComponent(str);
|
|
31
31
|
};
|
|
32
|
-
export default [
|
|
32
|
+
export default /* @__PURE__ */ (() => [
|
|
33
33
|
{ key: 'Mod-[', run: convert(escapeHTML, indentLess) },
|
|
34
34
|
{ key: 'Mod-]', run: convert(escapeURI, indentMore) },
|
|
35
|
-
];
|
|
35
|
+
])();
|