@bhsd/codemirror-mediawiki 3.5.1 → 3.5.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/codemirror.js +14 -4
- package/dist/escape.js +3 -5
- package/dist/fold.js +8 -14
- package/dist/hover.js +2 -3
- package/dist/inlay.js +2 -4
- package/dist/lintsource.js +3 -1
- package/dist/lua.js +4 -0
- package/dist/main.min.js +23 -23
- package/dist/mediawiki.js +2 -1
- package/dist/mw.min.js +26 -26
- package/dist/mwConfig.js +22 -4
- package/dist/ref.js +2 -2
- package/dist/static.js +3 -2
- package/dist/statusBar.js +11 -27
- package/dist/token.d.ts +1 -1
- package/dist/token.js +18 -13
- package/dist/wiki.min.js +25 -25
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +4 -7
package/dist/codemirror.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type Dialect = 'sanitized-css' | undefined;
|
|
|
15
15
|
declare interface MenuItem {
|
|
16
16
|
name: string;
|
|
17
17
|
isActionable(this: void, cm: CodeMirror6): boolean;
|
|
18
|
-
getItems(this: void, cm: CodeMirror6):
|
|
18
|
+
getItems(this: void, cm: CodeMirror6): HTMLElement[];
|
|
19
19
|
}
|
|
20
20
|
declare interface OptionalFunctions {
|
|
21
21
|
statusBar: typeof statusBar;
|
package/dist/codemirror.js
CHANGED
|
@@ -4,6 +4,7 @@ import { syntaxHighlighting, defaultHighlightStyle, indentOnInput, indentUnit, e
|
|
|
4
4
|
import { defaultKeymap, historyKeymap, history, redo, indentWithTab } from '@codemirror/commands';
|
|
5
5
|
import { searchKeymap } from '@codemirror/search';
|
|
6
6
|
import { linter, lintGutter, lintKeymap } from '@codemirror/lint';
|
|
7
|
+
import elt from 'crelt';
|
|
7
8
|
import { light } from './theme';
|
|
8
9
|
export const plain = () => EditorView.contentAttributes.of({ spellcheck: 'true' });
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -229,7 +230,18 @@ export class CodeMirror6 {
|
|
|
229
230
|
const linterExtension = lintSources
|
|
230
231
|
? [
|
|
231
232
|
...lintSources.map(source => linter(async ({ state }) => {
|
|
232
|
-
const diagnostics = await source(state)
|
|
233
|
+
const diagnostics = (await source(state)).map((diagnostic) => ({
|
|
234
|
+
...diagnostic,
|
|
235
|
+
renderMessage(view) {
|
|
236
|
+
const span = elt('span', { class: 'cm-diagnosticText-clickable' }, diagnostic.message);
|
|
237
|
+
span.addEventListener('click', () => {
|
|
238
|
+
view.dispatch({
|
|
239
|
+
selection: { anchor: diagnostic.from, head: diagnostic.to },
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
return span;
|
|
243
|
+
},
|
|
244
|
+
}));
|
|
233
245
|
if (state.readOnly) {
|
|
234
246
|
for (const diagnostic of diagnostics) {
|
|
235
247
|
delete diagnostic.actions;
|
|
@@ -436,9 +448,7 @@ export class CodeMirror6 {
|
|
|
436
448
|
*/
|
|
437
449
|
setTheme(theme) {
|
|
438
450
|
if (theme in themes) {
|
|
439
|
-
this.#view?.dispatch({
|
|
440
|
-
effects: this.#theme.reconfigure(themes[theme]),
|
|
441
|
-
});
|
|
451
|
+
this.#view?.dispatch({ effects: this.#theme.reconfigure(themes[theme]) });
|
|
442
452
|
}
|
|
443
453
|
}
|
|
444
454
|
/**
|
package/dist/escape.js
CHANGED
|
@@ -2,6 +2,7 @@ import { keymap } from '@codemirror/view';
|
|
|
2
2
|
import { EditorSelection } from '@codemirror/state';
|
|
3
3
|
import { indentMore, indentLess } from '@codemirror/commands';
|
|
4
4
|
import { getLSP } from '@bhsd/browser';
|
|
5
|
+
import elt from 'crelt';
|
|
5
6
|
import { CodeMirror6, menuRegistry } from './codemirror';
|
|
6
7
|
const entity = { '"': 'quot', "'": 'apos', '<': 'lt', '>': 'gt', '&': 'amp', ' ': 'nbsp' };
|
|
7
8
|
/**
|
|
@@ -69,13 +70,11 @@ menuRegistry.push({
|
|
|
69
70
|
},
|
|
70
71
|
getItems(cm) {
|
|
71
72
|
if (!items) {
|
|
72
|
-
const view = cm.view, btnHTML =
|
|
73
|
-
btnHTML.textContent = 'HTML escape';
|
|
73
|
+
const view = cm.view, btnHTML = elt('div', 'HTML escape'), btnURI = elt('div', 'URI encode/decode');
|
|
74
74
|
btnHTML.addEventListener('click', e => {
|
|
75
75
|
CodeMirror6.replaceSelections(view, escapeHTML);
|
|
76
76
|
handlerBase(view, e);
|
|
77
77
|
});
|
|
78
|
-
btnURI.textContent = 'URI encode/decode';
|
|
79
78
|
btnURI.addEventListener('click', e => {
|
|
80
79
|
CodeMirror6.replaceSelections(view, escapeURI);
|
|
81
80
|
handlerBase(view, e);
|
|
@@ -83,8 +82,7 @@ menuRegistry.push({
|
|
|
83
82
|
items = [btnHTML, btnURI];
|
|
84
83
|
const lsp = getLSP(view, false, cm.getWikiConfig);
|
|
85
84
|
if (lsp && 'provideRefactoringAction' in lsp) {
|
|
86
|
-
const btnWiki =
|
|
87
|
-
btnWiki.textContent = 'Escape with magic words';
|
|
85
|
+
const btnWiki = elt('div', 'Escape with magic words');
|
|
88
86
|
btnWiki.addEventListener('click', e => {
|
|
89
87
|
escapeWiki(cm);
|
|
90
88
|
handlerBase(view, e);
|
package/dist/fold.js
CHANGED
|
@@ -2,6 +2,7 @@ import { showTooltip, keymap, GutterMarker, gutter, ViewPlugin, EditorView } fro
|
|
|
2
2
|
import { StateField, RangeSetBuilder, RangeSet } from '@codemirror/state';
|
|
3
3
|
import { syntaxTree, ensureSyntaxTree, foldEffect, unfoldEffect, foldedRanges, unfoldAll, codeFolding, foldGutter, foldKeymap, foldState, language, } from '@codemirror/language';
|
|
4
4
|
import { getRegex } from '@bhsd/common';
|
|
5
|
+
import elt from 'crelt';
|
|
5
6
|
import { tokens } from './config';
|
|
6
7
|
import { matchTag, getTag } from './matchTag';
|
|
7
8
|
const getExtRegex = /* @__PURE__ */ getRegex(tag => new RegExp(`mw-tag-${tag}(?![a-z])`, 'u'));
|
|
@@ -160,10 +161,7 @@ const create = (state) => {
|
|
|
160
161
|
pos: head,
|
|
161
162
|
above: true,
|
|
162
163
|
create() {
|
|
163
|
-
const dom =
|
|
164
|
-
dom.className = 'cm-tooltip-fold';
|
|
165
|
-
dom.textContent = '\uff0d';
|
|
166
|
-
dom.title = state.phrase('Fold template or extension tag');
|
|
164
|
+
const dom = elt('div', { class: 'cm-tooltip-fold', title: state.phrase('Fold template or extension tag') }, '\uff0d');
|
|
167
165
|
dom.dataset['from'] = String(from);
|
|
168
166
|
dom.dataset['to'] = String(to);
|
|
169
167
|
return { dom };
|
|
@@ -182,7 +180,10 @@ const execute = (view, effects, anchor) => {
|
|
|
182
180
|
if (effects.length > 0) {
|
|
183
181
|
view.dom.querySelector('.cm-tooltip-fold')?.remove();
|
|
184
182
|
// Fold the template(s) and update the cursor position
|
|
185
|
-
view.dispatch({
|
|
183
|
+
view.dispatch({
|
|
184
|
+
effects,
|
|
185
|
+
selection: { anchor },
|
|
186
|
+
});
|
|
186
187
|
return true;
|
|
187
188
|
}
|
|
188
189
|
return false;
|
|
@@ -228,10 +229,7 @@ class FoldMarker extends GutterMarker {
|
|
|
228
229
|
return this.open === other.open;
|
|
229
230
|
}
|
|
230
231
|
toDOM({ state }) {
|
|
231
|
-
|
|
232
|
-
span.textContent = this.open ? '⌄' : '›';
|
|
233
|
-
span.title = state.phrase(this.open ? 'Fold line' : 'Unfold line');
|
|
234
|
-
return span;
|
|
232
|
+
return elt('span', { title: state.phrase(this.open ? 'Fold line' : 'Unfold line') }, this.open ? '⌄' : '›');
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
const canFold = /* @__PURE__ */ new FoldMarker(true), canUnfold = /* @__PURE__ */ new FoldMarker(false);
|
|
@@ -338,11 +336,7 @@ const selector = '.cm-tooltip-fold';
|
|
|
338
336
|
export const mediaWikiFold = /* @__PURE__ */ (() => [
|
|
339
337
|
codeFolding({
|
|
340
338
|
placeholderDOM(view) {
|
|
341
|
-
const element =
|
|
342
|
-
element.textContent = '…';
|
|
343
|
-
element.setAttribute('aria-label', 'folded code');
|
|
344
|
-
element.title = view.state.phrase('unfold');
|
|
345
|
-
element.className = 'cm-foldPlaceholder';
|
|
339
|
+
const element = elt('span', { 'aria-label': 'folded code', title: view.state.phrase('unfold'), class: 'cm-foldPlaceholder' }, '…');
|
|
346
340
|
element.addEventListener('click', ({ target }) => {
|
|
347
341
|
const pos = view.posAtDOM(target), { state } = view, { selection } = state;
|
|
348
342
|
foldedRanges(state).between(pos, pos, (from, to) => {
|
package/dist/hover.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { hoverTooltip, EditorView } from '@codemirror/view';
|
|
2
2
|
import { loadScript, getLSP } from '@bhsd/browser';
|
|
3
|
+
import elt from 'crelt';
|
|
3
4
|
/**
|
|
4
5
|
* 将索引转换为位置
|
|
5
6
|
* @param doc Text 实例
|
|
@@ -24,9 +25,7 @@ export const posToIndex = (doc, pos) => {
|
|
|
24
25
|
* @param innerHTML 提示内容
|
|
25
26
|
*/
|
|
26
27
|
export const createTooltipView = (view, innerHTML) => {
|
|
27
|
-
const
|
|
28
|
-
dom.append(inner);
|
|
29
|
-
dom.className = 'cm-tooltip-hover';
|
|
28
|
+
const inner = elt('div'), dom = elt('div', { class: 'cm-tooltip-hover' }, inner);
|
|
30
29
|
dom.style.font = getComputedStyle(view.contentDOM).font;
|
|
31
30
|
inner.innerHTML = innerHTML;
|
|
32
31
|
return { dom };
|
package/dist/inlay.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StateField, StateEffect } from '@codemirror/state';
|
|
2
2
|
import { Decoration, EditorView, WidgetType, ViewPlugin } from '@codemirror/view';
|
|
3
3
|
import { getLSP } from '@bhsd/browser';
|
|
4
|
+
import elt from 'crelt';
|
|
4
5
|
import { posToIndex } from './hover';
|
|
5
6
|
class InlayHintWidget extends WidgetType {
|
|
6
7
|
constructor(label) {
|
|
@@ -8,10 +9,7 @@ class InlayHintWidget extends WidgetType {
|
|
|
8
9
|
this.label = label;
|
|
9
10
|
}
|
|
10
11
|
toDOM() {
|
|
11
|
-
|
|
12
|
-
element.textContent = this.label;
|
|
13
|
-
element.className = 'cm-inlay-hint';
|
|
14
|
-
return element;
|
|
12
|
+
return elt('span', { class: 'cm-inlay-hint' }, this.label);
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
const stateEffect = StateEffect.define(), field = StateField.define({
|
package/dist/lintsource.js
CHANGED
|
@@ -78,7 +78,9 @@ const jsLintSource = (esLint, code, opt, doc, f = 0, t) => esLint(code, opt)
|
|
|
78
78
|
].map(({ name, fix: { range: [from, to], text } }) => ({
|
|
79
79
|
name,
|
|
80
80
|
apply(view) {
|
|
81
|
-
view.dispatch({
|
|
81
|
+
view.dispatch({
|
|
82
|
+
changes: { from: from + f, to: to + f, insert: text },
|
|
83
|
+
});
|
|
82
84
|
},
|
|
83
85
|
}));
|
|
84
86
|
}
|
package/dist/lua.js
CHANGED
|
@@ -140,6 +140,9 @@ const map = {
|
|
|
140
140
|
interwikiMap: 2,
|
|
141
141
|
},
|
|
142
142
|
},
|
|
143
|
+
svg: {
|
|
144
|
+
new: 2,
|
|
145
|
+
},
|
|
143
146
|
text: {
|
|
144
147
|
decode: 2,
|
|
145
148
|
encode: 2,
|
|
@@ -164,6 +167,7 @@ const map = {
|
|
|
164
167
|
compare: 2,
|
|
165
168
|
getCurrentTitle: 2,
|
|
166
169
|
new: 2,
|
|
170
|
+
newBatch: 2,
|
|
167
171
|
makeTitle: 2,
|
|
168
172
|
},
|
|
169
173
|
uri: {
|