@bhsd/codemirror-mediawiki 3.3.0 → 3.4.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 +2 -23
- package/dist/codemirror.d.ts +1 -1
- package/dist/codemirror.js +16 -3
- package/dist/fold.d.ts +2 -1
- package/dist/fold.js +13 -1
- package/dist/hover.d.ts +2 -1
- package/dist/hover.js +40 -18
- package/dist/inlay.js +8 -0
- package/dist/linter.js +1 -1
- package/dist/lintsource.js +16 -4
- package/dist/main.min.js +29 -25
- package/dist/mediawiki.js +145 -1
- package/dist/mw.min.js +33 -29
- package/dist/ref.js +9 -0
- package/dist/statusBar.js +136 -60
- package/dist/theme.js +4 -4
- package/dist/wiki.min.js +32 -28
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +2 -4
- package/mediawiki.css +0 -6
package/README.md
CHANGED
|
@@ -15,8 +15,6 @@ Nonetheless, this repository also provides a customized version with additional
|
|
|
15
15
|
|
|
16
16
|
- [Installation](#installation)
|
|
17
17
|
- [Browser Usage](#browser-usage)
|
|
18
|
-
- [Download JavaScript](#download-javascript)
|
|
19
|
-
- [Download CSS](#download-css)
|
|
20
18
|
- [Language modes](#language-modes)
|
|
21
19
|
- [css](#css)
|
|
22
20
|
- [html](#html)
|
|
@@ -104,13 +102,11 @@ import {
|
|
|
104
102
|
|
|
105
103
|
# Browser Usage
|
|
106
104
|
|
|
107
|
-
You can download the code via CDN, for example:
|
|
108
|
-
|
|
109
|
-
## Download JavaScript
|
|
110
|
-
|
|
111
105
|
<details>
|
|
112
106
|
<summary>Expand</summary>
|
|
113
107
|
|
|
108
|
+
You can download the code via CDN, for example:
|
|
109
|
+
|
|
114
110
|
```js
|
|
115
111
|
// static import
|
|
116
112
|
import {
|
|
@@ -173,23 +169,6 @@ const {
|
|
|
173
169
|
|
|
174
170
|
</details>
|
|
175
171
|
|
|
176
|
-
## Download CSS
|
|
177
|
-
|
|
178
|
-
<details>
|
|
179
|
-
<summary>Expand</summary>
|
|
180
|
-
|
|
181
|
-
```html
|
|
182
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki/mediawiki.css">
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
or
|
|
186
|
-
|
|
187
|
-
```html
|
|
188
|
-
<link rel="stylesheet" href="https://unpkg.com/@bhsd/codemirror-mediawiki/mediawiki.css">
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
</details>
|
|
192
|
-
|
|
193
172
|
# Language modes
|
|
194
173
|
|
|
195
174
|
## css
|
package/dist/codemirror.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type statusBar from './statusBar';
|
|
|
12
12
|
export type AddonMain<T> = (config?: T, cm?: CodeMirror6) => Extension;
|
|
13
13
|
export type Addon<T> = [AddonMain<T>, Record<string, T>?];
|
|
14
14
|
export type Dialect = 'sanitized-css' | undefined;
|
|
15
|
-
|
|
15
|
+
declare interface MenuItem {
|
|
16
16
|
name: string;
|
|
17
17
|
isActionable(this: void, cm: CodeMirror6): boolean;
|
|
18
18
|
getItems(this: void, cm: CodeMirror6): HTMLDivElement[];
|
package/dist/codemirror.js
CHANGED
|
@@ -121,7 +121,18 @@ export class CodeMirror6 {
|
|
|
121
121
|
},
|
|
122
122
|
]),
|
|
123
123
|
EditorView.theme({
|
|
124
|
-
'.cm-panels': {
|
|
124
|
+
'.cm-panels': {
|
|
125
|
+
direction: document.dir,
|
|
126
|
+
},
|
|
127
|
+
'& .cm-lineNumbers .cm-gutterElement': {
|
|
128
|
+
textAlign: 'end',
|
|
129
|
+
},
|
|
130
|
+
'.cm-textfield, .cm-button, .cm-panel.cm-search label, .cm-panel.cm-gotoLine label': {
|
|
131
|
+
fontSize: 'inherit',
|
|
132
|
+
},
|
|
133
|
+
'.cm-panel [name="close"]': {
|
|
134
|
+
color: 'inherit',
|
|
135
|
+
},
|
|
125
136
|
}),
|
|
126
137
|
EditorView.updateListener.of(({ state: { doc }, startState: { doc: startDoc }, docChanged, focusChanged, }) => {
|
|
127
138
|
if (docChanged) {
|
|
@@ -143,7 +154,9 @@ export class CodeMirror6 {
|
|
|
143
154
|
EditorState.readOnly.of(true),
|
|
144
155
|
EditorState.transactionFilter.of(tr => tr.docChanged ? [] : tr),
|
|
145
156
|
EditorView.theme({
|
|
146
|
-
'input[type="color"]': {
|
|
157
|
+
'input[type="color"]': {
|
|
158
|
+
pointerEvents: 'none',
|
|
159
|
+
},
|
|
147
160
|
}),
|
|
148
161
|
]
|
|
149
162
|
: [
|
|
@@ -400,7 +413,7 @@ export class CodeMirror6 {
|
|
|
400
413
|
* @param position position
|
|
401
414
|
*/
|
|
402
415
|
getNodeAt(position) {
|
|
403
|
-
return this.#view && ensureSyntaxTree(this.#view.state, position)?.
|
|
416
|
+
return this.#view && ensureSyntaxTree(this.#view.state, position)?.resolveInner(position, 1);
|
|
404
417
|
}
|
|
405
418
|
/**
|
|
406
419
|
* Scroll to the specified position
|
package/dist/fold.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import type { Command } from '@codemirror/view';
|
|
2
3
|
import type { EditorState, Extension } from '@codemirror/state';
|
|
3
4
|
import type { SyntaxNode, Tree } from '@lezer/common';
|
|
4
5
|
export interface DocRange {
|
package/dist/fold.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { showTooltip, keymap, GutterMarker, gutter, ViewPlugin } from '@codemirror/view';
|
|
1
|
+
import { showTooltip, keymap, GutterMarker, gutter, ViewPlugin, EditorView } from '@codemirror/view';
|
|
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';
|
|
@@ -334,6 +334,7 @@ const foldCommand = (refOnly) => view => {
|
|
|
334
334
|
};
|
|
335
335
|
export const foldRef = /* @__PURE__ */ foldCommand(true);
|
|
336
336
|
export default ((e = defaultFoldExtension) => e);
|
|
337
|
+
const selector = '.cm-tooltip-fold';
|
|
337
338
|
export const mediaWikiFold = /* @__PURE__ */ (() => [
|
|
338
339
|
codeFolding({
|
|
339
340
|
placeholderDOM(view) {
|
|
@@ -446,6 +447,17 @@ export const mediaWikiFold = /* @__PURE__ */ (() => [
|
|
|
446
447
|
},
|
|
447
448
|
},
|
|
448
449
|
}),
|
|
450
|
+
EditorView.theme({
|
|
451
|
+
[selector]: {
|
|
452
|
+
cursor: 'pointer',
|
|
453
|
+
lineHeight: 1.2,
|
|
454
|
+
padding: '0 1px',
|
|
455
|
+
opacity: 0.6,
|
|
456
|
+
},
|
|
457
|
+
[`${selector}:hover`]: {
|
|
458
|
+
opacity: 1,
|
|
459
|
+
},
|
|
460
|
+
}),
|
|
449
461
|
])();
|
|
450
462
|
/**
|
|
451
463
|
* 点击提示折叠模板参数
|
package/dist/hover.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import type { TooltipView } from '@codemirror/view';
|
|
2
3
|
import type { Text, Extension } from '@codemirror/state';
|
|
3
4
|
import type { Position } from 'vscode-languageserver-types';
|
|
4
5
|
import type { CodeMirror6 } from './codemirror';
|
package/dist/hover.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hoverTooltip } from '@codemirror/view';
|
|
1
|
+
import { hoverTooltip, EditorView } from '@codemirror/view';
|
|
2
2
|
import { loadScript, getLSP } from '@bhsd/browser';
|
|
3
3
|
/**
|
|
4
4
|
* 将索引转换为位置
|
|
@@ -31,20 +31,42 @@ export const createTooltipView = (view, innerHTML) => {
|
|
|
31
31
|
inner.innerHTML = innerHTML;
|
|
32
32
|
return { dom };
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
34
|
+
const selector = '.cm-tooltip-hover';
|
|
35
|
+
export default (cm) => [
|
|
36
|
+
hoverTooltip(async (view, pos) => {
|
|
37
|
+
const { state: { doc } } = view, hover = await getLSP(view, false, cm.getWikiConfig)
|
|
38
|
+
?.provideHover(doc.toString(), indexToPos(doc, pos));
|
|
39
|
+
if (hover) {
|
|
40
|
+
await loadScript('npm/marked/lib/marked.umd.js', 'marked', true);
|
|
41
|
+
const { end } = hover.range;
|
|
42
|
+
return {
|
|
43
|
+
pos,
|
|
44
|
+
end: posToIndex(doc, end),
|
|
45
|
+
above: true,
|
|
46
|
+
create() {
|
|
47
|
+
return createTooltipView(view, marked.parse(hover.contents.value));
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}),
|
|
53
|
+
EditorView.theme({
|
|
54
|
+
[selector]: {
|
|
55
|
+
padding: '2px 5px',
|
|
56
|
+
width: 'max-content',
|
|
57
|
+
maxWidth: '60vw',
|
|
58
|
+
},
|
|
59
|
+
[`${selector} *`]: {
|
|
60
|
+
marginTop: '0!important',
|
|
61
|
+
marginBottom: '0!important',
|
|
62
|
+
},
|
|
63
|
+
[`${selector}>div`]: {
|
|
64
|
+
fontSize: '90%',
|
|
65
|
+
lineHeight: 1.4,
|
|
66
|
+
},
|
|
67
|
+
[`${selector} code`]: {
|
|
68
|
+
padding: '.1em .4em',
|
|
69
|
+
borderRadius: '.4em',
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
];
|
package/dist/inlay.js
CHANGED
package/dist/linter.js
CHANGED
|
@@ -72,7 +72,7 @@ export const getWikiLinter = async (opt, obj) => {
|
|
|
72
72
|
message,
|
|
73
73
|
};
|
|
74
74
|
if (fix) {
|
|
75
|
-
const before = lines.slice(0, i - 1).join('\n').length +
|
|
75
|
+
const before = lines.slice(0, i - 1).join('\n').length + length;
|
|
76
76
|
diagnostic.data = [
|
|
77
77
|
{
|
|
78
78
|
range: {
|
package/dist/lintsource.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { ensureSyntaxTree } from '@codemirror/language';
|
|
1
2
|
import { cssLanguage } from '@codemirror/lang-css';
|
|
2
3
|
import { javascriptLanguage } from '@codemirror/lang-javascript';
|
|
4
|
+
import { sanitizeInlineStyle } from '@bhsd/common';
|
|
3
5
|
import { getWikiLinter, getJsLinter, getCssLinter, getJsonLinter, getLuaLinter } from './linter';
|
|
4
6
|
import { posToIndex } from './hover';
|
|
5
7
|
/**
|
|
@@ -125,10 +127,20 @@ export const getCssLintSource = async (opt) => {
|
|
|
125
127
|
export const getVueLintSource = async (opt) => {
|
|
126
128
|
const styleLint = await getCssLinter(), esLint = await getJsLinter();
|
|
127
129
|
return async (state) => {
|
|
128
|
-
const { doc } = state, option = await getOpt(opt) ?? {}, js = option['js'], css = option['css'];
|
|
130
|
+
const { doc } = state, option = await getOpt(opt, true) ?? {}, js = option['js'], css = option['css'];
|
|
129
131
|
return [
|
|
130
|
-
...(await Promise.all(cssLanguage.findRegions(state)
|
|
131
|
-
|
|
132
|
+
...(await Promise.all(cssLanguage.findRegions(state).map(async ({ from, to }) => {
|
|
133
|
+
const node = ensureSyntaxTree(state, from)?.resolve(from, 1);
|
|
134
|
+
if (node?.name === 'AttributeValue') {
|
|
135
|
+
return (await cssLintSource(styleLint, `a {${sanitizeInlineStyle(state.sliceDoc(from, to))}}`, css, doc, from - 3, to + 1)).filter(({ from: f, to: t }) => f <= to && t >= from)
|
|
136
|
+
.map((diagnostic) => {
|
|
137
|
+
diagnostic.from = Math.max(diagnostic.from, from);
|
|
138
|
+
diagnostic.to = Math.min(diagnostic.to, to);
|
|
139
|
+
return diagnostic;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return node ? cssLintSource(styleLint, state.sliceDoc(from, to), css, doc, from, to) : [];
|
|
143
|
+
}))).flat(),
|
|
132
144
|
...javascriptLanguage.findRegions(state)
|
|
133
145
|
.flatMap(({ from, to }) => jsLintSource(esLint, state.sliceDoc(from, to), js, doc, from, to)),
|
|
134
146
|
];
|
|
@@ -137,7 +149,7 @@ export const getVueLintSource = async (opt) => {
|
|
|
137
149
|
export const getHTMLLintSource = async (opt, view, language) => {
|
|
138
150
|
const vueLintSource = await getVueLintSource(opt), wikiLint = await getWikiLinter({ include: false, ...await getOpt(opt) }, view);
|
|
139
151
|
return async (state) => {
|
|
140
|
-
const { doc } = state, option = await getOpt(opt) ?? {}, wiki = option['wiki'];
|
|
152
|
+
const { doc } = state, option = await getOpt(opt, true) ?? {}, wiki = option['wiki'];
|
|
141
153
|
return [
|
|
142
154
|
...await vueLintSource(state),
|
|
143
155
|
...(await Promise.all(language.findRegions(state)
|