@bhsd/codemirror-mediawiki 2.1.11 → 2.1.12
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 +1 -1
- package/dist/main.min.js +11 -11
- package/dist/main.min.js.map +3 -3
- package/mediawiki.css +25 -25
- package/mw/dist/base.js +11 -2
- package/package.json +10 -10
- package/src/codemirror.ts +50 -24
package/mediawiki.css
CHANGED
|
@@ -161,85 +161,85 @@
|
|
|
161
161
|
/* backgrounds */
|
|
162
162
|
.cm-mw-tag-pre,
|
|
163
163
|
.cm-mw-tag-nowiki {
|
|
164
|
-
background-color: rgba(
|
|
164
|
+
background-color: rgba(0, 0, 0, .04);
|
|
165
165
|
}
|
|
166
166
|
.cm-mw-template-ground {
|
|
167
|
-
background-color: rgba(
|
|
167
|
+
background-color: rgba(170, 17, 17, .04);
|
|
168
168
|
}
|
|
169
169
|
.cm-mw-template2-ground {
|
|
170
|
-
background-color: rgba(
|
|
170
|
+
background-color: rgba(170, 17, 17, .08);
|
|
171
171
|
}
|
|
172
172
|
.cm-mw-template3-ground {
|
|
173
|
-
background-color: rgba(
|
|
173
|
+
background-color: rgba(170, 17, 17, .12);
|
|
174
174
|
}
|
|
175
175
|
.cm-mw-template-ext-ground,
|
|
176
176
|
.cm-mw-ext-ground,
|
|
177
177
|
.cm-mw-exttag {
|
|
178
|
-
background-color: rgba(
|
|
178
|
+
background-color: rgba(119, 0, 170, .04);
|
|
179
179
|
}
|
|
180
180
|
.cm-mw-template-ext2-ground,
|
|
181
181
|
.cm-mw-ext2-ground {
|
|
182
|
-
background-color: rgba(
|
|
182
|
+
background-color: rgba(119, 0, 170, .08);
|
|
183
183
|
}
|
|
184
184
|
.cm-mw-template-ext3-ground,
|
|
185
185
|
.cm-mw-ext3-ground {
|
|
186
|
-
background-color: rgba(
|
|
186
|
+
background-color: rgba(119, 0, 170, .12);
|
|
187
187
|
}
|
|
188
188
|
.cm-mw-template-link-ground,
|
|
189
189
|
.cm-mw-ext-link-ground,
|
|
190
190
|
.cm-mw-link-ground {
|
|
191
|
-
background-color: rgba(
|
|
191
|
+
background-color: rgba(34, 17, 153, .04);
|
|
192
192
|
}
|
|
193
193
|
.cm-mw-template-ext-link-ground,
|
|
194
194
|
.cm-mw-ext2-link-ground {
|
|
195
|
-
background-color: rgba(
|
|
195
|
+
background-color: rgba(77, 9, 162, .08);
|
|
196
196
|
}
|
|
197
197
|
.cm-mw-template-ext2-link-ground,
|
|
198
198
|
.cm-mw-ext3-link-ground {
|
|
199
|
-
background-color: rgba(
|
|
199
|
+
background-color: rgba(91, 6, 164, .12);
|
|
200
200
|
}
|
|
201
201
|
.cm-mw-template-ext3-link-ground {
|
|
202
|
-
background-color: rgba(
|
|
202
|
+
background-color: rgba(98, 4, 166, .16);
|
|
203
203
|
}
|
|
204
204
|
.cm-mw-template2-ext-ground {
|
|
205
|
-
background-color: rgba(
|
|
205
|
+
background-color: rgba(145, 9, 94, .08);
|
|
206
206
|
}
|
|
207
207
|
.cm-mw-template2-ext2-ground {
|
|
208
|
-
background-color: rgba(
|
|
208
|
+
background-color: rgba(136, 6, 119, .12);
|
|
209
209
|
}
|
|
210
210
|
.cm-mw-template2-ext3-ground {
|
|
211
|
-
background-color: rgba(
|
|
211
|
+
background-color: rgba(132, 4, 132, .16);
|
|
212
212
|
}
|
|
213
213
|
.cm-mw-template2-link-ground {
|
|
214
|
-
background-color: rgba(
|
|
214
|
+
background-color: rgba(102, 17, 85, .08);
|
|
215
215
|
}
|
|
216
216
|
.cm-mw-template2-ext-link-ground {
|
|
217
|
-
background-color: rgba(
|
|
217
|
+
background-color: rgba(108, 11, 113, .12);
|
|
218
218
|
}
|
|
219
219
|
.cm-mw-template2-ext2-link-ground {
|
|
220
|
-
background-color: rgba(
|
|
220
|
+
background-color: rgba(111, 9, 128, .16);
|
|
221
221
|
}
|
|
222
222
|
.cm-mw-template2-ext3-link-ground {
|
|
223
|
-
background-color: rgba(
|
|
223
|
+
background-color: rgba(112, 7, 136, .2);
|
|
224
224
|
}
|
|
225
225
|
.cm-mw-template3-ext-ground {
|
|
226
|
-
background-color: rgba(
|
|
226
|
+
background-color: rgba(153, 11, 68, .12);
|
|
227
227
|
}
|
|
228
228
|
.cm-mw-template3-ext2-ground {
|
|
229
|
-
background-color: rgba(
|
|
229
|
+
background-color: rgba(145, 9, 94, .16);
|
|
230
230
|
}
|
|
231
231
|
.cm-mw-template3-ext3-ground {
|
|
232
|
-
background-color: rgba(
|
|
232
|
+
background-color: rgba(139, 7, 109, .2);
|
|
233
233
|
}
|
|
234
234
|
.cm-mw-template3-link-ground {
|
|
235
|
-
background-color: rgba(
|
|
235
|
+
background-color: rgba(125, 17, 62, .12);
|
|
236
236
|
}
|
|
237
237
|
.cm-mw-template3-ext-link-ground {
|
|
238
|
-
background-color: rgba(
|
|
238
|
+
background-color: rgba(123, 13, 89, .16);
|
|
239
239
|
}
|
|
240
240
|
.cm-mw-template3-ext2-link-ground {
|
|
241
|
-
background-color: rgba(
|
|
241
|
+
background-color: rgba(122, 10, 105, .2);
|
|
242
242
|
}
|
|
243
243
|
.cm-mw-template3-ext3-link-ground {
|
|
244
|
-
background-color: rgba(
|
|
244
|
+
background-color: rgba(122, 9, 116, .24);
|
|
245
245
|
}
|
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.12/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.12/mediawiki.min.css', 'text/css');
|
|
5
5
|
mw.loader.addStyleTag('.wikiEditor-ui-toolbar{z-index:7}');
|
|
6
6
|
const instances = new WeakMap();
|
|
7
7
|
const getInstance = ($ele) => instances.get($ele[0]);
|
|
@@ -180,6 +180,15 @@ import { CodeMirror6 } from 'https://testingcf.jsdelivr.net/npm/@bhsd/codemirror
|
|
|
180
180
|
opt = optOrNs;
|
|
181
181
|
}
|
|
182
182
|
if (!(lang in linters)) {
|
|
183
|
+
if (lang === 'mediawiki') {
|
|
184
|
+
const i18n = mw.config.get('wgUserLanguage');
|
|
185
|
+
if (['zh', 'zh-hans', 'zh-cn', 'zh-sg', 'zh-my'].includes(i18n)) {
|
|
186
|
+
opt = { ...opt, i18n: 'zh-hans' };
|
|
187
|
+
}
|
|
188
|
+
else if (['zh-hant', 'zh-tw', 'zh-hk', 'zh-mo'].includes(i18n)) {
|
|
189
|
+
opt = { ...opt, i18n: 'zh-hant' };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
183
192
|
await this.getLinter(opt);
|
|
184
193
|
if (lang === 'mediawiki') {
|
|
185
194
|
const mwConfig = await getMwConfig(), config = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-mediawiki",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.12",
|
|
4
4
|
"description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && eslint --cache .",
|
|
36
36
|
"lint:css": "stylelint *.css",
|
|
37
37
|
"lint": "npm run lint:ts && npm run lint:css",
|
|
38
|
-
"server": "http-server .. -c-1 --cors &",
|
|
38
|
+
"server": "npm run test:end; http-server .. -c-1 --cors &",
|
|
39
39
|
"test": "npm run build:core && npm run build:gh-page && npm run server",
|
|
40
40
|
"test:end": "pkill -x http-server"
|
|
41
41
|
},
|
|
@@ -52,24 +52,24 @@
|
|
|
52
52
|
"@codemirror/state": "^6.3.3",
|
|
53
53
|
"@codemirror/view": "^6.22.2",
|
|
54
54
|
"@lezer/highlight": "^1.2.0",
|
|
55
|
-
"@stylistic/eslint-plugin": "^1.5.
|
|
55
|
+
"@stylistic/eslint-plugin": "^1.5.4",
|
|
56
56
|
"@stylistic/stylelint-plugin": "^2.0.0",
|
|
57
57
|
"@types/jquery": "^3.5.29",
|
|
58
58
|
"@types/oojs-ui": "^0.47.6",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
60
|
-
"@typescript-eslint/parser": "^6.
|
|
61
|
-
"esbuild": "^0.19.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
60
|
+
"@typescript-eslint/parser": "^6.19.1",
|
|
61
|
+
"esbuild": "^0.19.12",
|
|
62
62
|
"eslint": "^8.56.0",
|
|
63
|
-
"eslint-plugin-es-x": "^7.
|
|
63
|
+
"eslint-plugin-es-x": "^7.5.0",
|
|
64
64
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
65
65
|
"eslint-plugin-promise": "^6.1.1",
|
|
66
|
-
"eslint-plugin-regexp": "^2.
|
|
66
|
+
"eslint-plugin-regexp": "^2.2.0",
|
|
67
67
|
"eslint-plugin-unicorn": "^50.0.1",
|
|
68
68
|
"http-server": "^14.1.0",
|
|
69
69
|
"stylelint": "^16.1.0",
|
|
70
70
|
"stylelint-config-recommended": "^14.0.0",
|
|
71
71
|
"types-mediawiki": "^1.4.0",
|
|
72
|
-
"typescript": "^5.
|
|
73
|
-
"wikilint": "^2.
|
|
72
|
+
"typescript": "^5.3.3",
|
|
73
|
+
"wikilint": "^2.4.1"
|
|
74
74
|
}
|
|
75
75
|
}
|
package/src/codemirror.ts
CHANGED
|
@@ -61,6 +61,7 @@ const avail: Record<string, [(config?: any) => Extension, Record<string, unknown
|
|
|
61
61
|
{},
|
|
62
62
|
],
|
|
63
63
|
};
|
|
64
|
+
const CDN = 'https://testingcf.jsdelivr.net';
|
|
64
65
|
|
|
65
66
|
/**
|
|
66
67
|
* 使用传统方法加载脚本
|
|
@@ -73,7 +74,7 @@ const loadScript = (src: string, target: string): Promise<void> => new Promise(r
|
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
76
|
const script = document.createElement('script');
|
|
76
|
-
script.src =
|
|
77
|
+
script.src = `${CDN}/${src}`;
|
|
77
78
|
script.onload = (): void => {
|
|
78
79
|
resolve();
|
|
79
80
|
};
|
|
@@ -96,7 +97,7 @@ export class CodeMirror6 {
|
|
|
96
97
|
readonly #indent;
|
|
97
98
|
readonly #view;
|
|
98
99
|
#lang;
|
|
99
|
-
#visible =
|
|
100
|
+
#visible = false;
|
|
100
101
|
|
|
101
102
|
get textarea(): HTMLTextAreaElement {
|
|
102
103
|
return this.#textarea;
|
|
@@ -162,25 +163,12 @@ export class CodeMirror6 {
|
|
|
162
163
|
extensions,
|
|
163
164
|
doc: textarea.value,
|
|
164
165
|
});
|
|
165
|
-
const {
|
|
166
|
-
{fontSize, lineHeight} = getComputedStyle(textarea),
|
|
167
|
-
hasFocus = document.activeElement === textarea;
|
|
166
|
+
const {fontSize, lineHeight} = getComputedStyle(textarea);
|
|
168
167
|
textarea.parentNode!.insertBefore(this.#view.dom, textarea);
|
|
169
168
|
this.#minHeight();
|
|
170
|
-
this.#refresh();
|
|
171
169
|
this.#view.dom.style.fontSize = fontSize;
|
|
172
170
|
this.#view.scrollDOM.style.lineHeight = lineHeight;
|
|
173
|
-
this
|
|
174
|
-
this.#view.dispatch({
|
|
175
|
-
selection: {anchor: selectionStart, head: selectionEnd},
|
|
176
|
-
});
|
|
177
|
-
textarea.style.display = 'none';
|
|
178
|
-
if (hasFocus) {
|
|
179
|
-
this.#view.focus();
|
|
180
|
-
}
|
|
181
|
-
requestAnimationFrame(() => {
|
|
182
|
-
this.#view.scrollDOM.scrollTop = scrollTop;
|
|
183
|
-
});
|
|
171
|
+
this.toggle(true);
|
|
184
172
|
}
|
|
185
173
|
|
|
186
174
|
/** 刷新编辑器高度 */
|
|
@@ -293,11 +281,21 @@ export class CodeMirror6 {
|
|
|
293
281
|
async getLinter(opt?: Record<string, unknown>): Promise<LintSource | undefined> {
|
|
294
282
|
switch (this.#lang) {
|
|
295
283
|
case 'mediawiki': {
|
|
296
|
-
const
|
|
297
|
-
|
|
284
|
+
const REPO = 'npm/wikiparser-node@1.4.1-b',
|
|
285
|
+
DIR = `${REPO}/extensions/dist`,
|
|
286
|
+
src = `combine/${DIR}/base.min.js,${DIR}/lint.min.js`,
|
|
287
|
+
lang = opt?.['i18n'];
|
|
298
288
|
await loadScript(src, 'wikiparse');
|
|
299
|
-
|
|
300
|
-
|
|
289
|
+
if (typeof lang === 'string') {
|
|
290
|
+
try {
|
|
291
|
+
const i18n: Record<string, string>
|
|
292
|
+
= await (await fetch(`${CDN}/${REPO}/i18n/${lang.toLowerCase()}.json`)).json();
|
|
293
|
+
wikiparse.setI18N(i18n);
|
|
294
|
+
} catch {}
|
|
295
|
+
}
|
|
296
|
+
const wikiLinter = new wikiparse.Linter(opt?.['include'] as boolean | undefined);
|
|
297
|
+
return async doc =>
|
|
298
|
+
(await wikiLinter.codemirror(doc.toString())).filter(({severity}) => severity === 'error');
|
|
301
299
|
}
|
|
302
300
|
case 'javascript': {
|
|
303
301
|
await loadScript('npm/eslint-linter-browserify', 'eslint');
|
|
@@ -434,11 +432,39 @@ export class CodeMirror6 {
|
|
|
434
432
|
*/
|
|
435
433
|
toggle(show = !this.#visible): void {
|
|
436
434
|
if (show && !this.#visible) {
|
|
437
|
-
this
|
|
435
|
+
const {value, selectionStart, selectionEnd, scrollTop} = this.#textarea,
|
|
436
|
+
hasFocus = document.activeElement === this.#textarea;
|
|
437
|
+
this.setContent(value);
|
|
438
438
|
this.#refresh();
|
|
439
|
+
this.#view.dom.style.setProperty('display', '');
|
|
440
|
+
this.#textarea.style.display = 'none';
|
|
441
|
+
this.#view.requestMeasure();
|
|
442
|
+
this.#view.dispatch({
|
|
443
|
+
selection: {anchor: selectionStart, head: selectionEnd},
|
|
444
|
+
});
|
|
445
|
+
if (hasFocus) {
|
|
446
|
+
this.#view.focus();
|
|
447
|
+
}
|
|
448
|
+
requestAnimationFrame(() => {
|
|
449
|
+
this.#view.scrollDOM.scrollTop = scrollTop;
|
|
450
|
+
});
|
|
451
|
+
} else if (!show && this.#visible) {
|
|
452
|
+
const {state: {selection: {main: {from, to}}}, hasFocus} = this.#view,
|
|
453
|
+
{scrollDOM: {scrollTop}} = this.#view;
|
|
454
|
+
this.#view.dom.style.setProperty('display', 'none', 'important');
|
|
455
|
+
this.#textarea.style.display = '';
|
|
456
|
+
this.#textarea.setSelectionRange(
|
|
457
|
+
Math.min(from, to),
|
|
458
|
+
Math.max(from, to),
|
|
459
|
+
from > to ? 'backward' : 'forward',
|
|
460
|
+
);
|
|
461
|
+
if (hasFocus) {
|
|
462
|
+
this.#textarea.focus();
|
|
463
|
+
}
|
|
464
|
+
requestAnimationFrame(() => {
|
|
465
|
+
this.#textarea.scrollTop = scrollTop;
|
|
466
|
+
});
|
|
439
467
|
}
|
|
440
468
|
this.#visible = show;
|
|
441
|
-
this.#view.dom.style.setProperty('display', show ? '' : 'none', 'important');
|
|
442
|
-
this.#textarea.style.display = show ? 'none' : '';
|
|
443
469
|
}
|
|
444
470
|
}
|